Skip to content

feat(spec-6-1): cost-aware tiers + cost accounting + context% + Tiers view (v0.10.0) - #15

Merged
rz1989s merged 13 commits into
mainfrom
feat/spec-6-1-cost-tiers
Jul 28, 2026
Merged

feat(spec-6-1): cost-aware tiers + cost accounting + context% + Tiers view (v0.10.0)#15
rz1989s merged 13 commits into
mainfrom
feat/spec-6-1-cost-tiers

Conversation

@rz1989s

@rz1989s rz1989s commented Jul 28, 2026

Copy link
Copy Markdown
Member

SPEC-6-1 — Cost-aware model tiers + cost accounting + context% + Tiers view

The first sub-SPEC of SPEC-6 (Power-user tier → v1.0). Adds a cost-aware model-tier routing layer + live $/run cost accounting + context% in the widget/Runs tab + a /fleet Tiers view. v0.10.0 (minor).

Surfaces

  • A — Tier routing: Tier ({ name, models[], costCap?, contextFloor? }) + TierRegistry (builtins < global < project tiers.json) + resolveAgentModel (precedence: opts.model > agent.tier > agent.model > parent; contextFloor + catalog filter; fallback retry on create() rejection). AgentDef.tier? frontmatter.
  • B — Cost $: RunRecord.costTotal (live, from usage.cost.total) + RunLog widening. Per-run costCap abort (budget_exceeded).
  • C — Context%: RunRecord.contextTokens (calcContextTokens) + ctx% in the above-editor widget + Runs tab (denominator = modelRegistry.find(...).contextWindow).
  • D — Tiers view: /fleet Tiers tab — tier list + per-tier spend + inline edit actions (Set models/costCap/contextFloor, Add/Delete, scope toggle) writing tiers.json.

Key discovery

pi-ai's Usage event already carries cost.total ($) + totalTokens (context) — no pricing engine needed. pi.modelRegistry.find(provider, id).contextWindow is the max-context denominator. Surfaces B + C are data-ready; the new work is A + D.

Builtins (Q10)

economy → Ollama/minimax-m3:cloud · standard → Ollama/glm-5.2:cloud + fallback · frontier → anthropic/claude-sonnet-4 + fallback, costCap $5, contextFloor 200k.

Tests

365 (was 347; +18 tiers-items + tier-registry/resolve-model/spawn-subagent-tier/widget/runs-rows/tiers-rows/tier-store/frontmatter). typecheck clean.

Pipeline

PRD ✅ · research ✅ · SPEC-1..5b-4 ✅ (v0.9.1; +v0.9.2/3/4 patches) · SPEC-6-1 (this PR) · 6-2/6-3/6-4 → v1.0.

Spec: docs/superpowers/specs/2026-07-27-spec-6-1-design.md. Plan: docs/superpowers/plans/2026-07-27-spec-6-1.md (12 TDD tasks, all done).

rz1989s added 13 commits July 27, 2026 13:53
UX: token counts in the live widget + Runs tab + conversation overlay now render
compact (<1K as-is, >=1K with K suffix). 2027001 tok → 2027K tok; 265055 tok →
265K tok; 142 tok → 142 tok (unchanged). fmtTokens(n) helper in rows.ts alongside
fmtDuration.
…xt + cap abort

Wires the tier layer into the engine:
- resolveAgentModel (Q4 precedence: opts.model > agent.tier > agent.model > parent)
  + Q5 fallback: walk tier.models[], skip not-in-catalog OR contextWindow < contextFloor,
  retry backend.factory.create() on rejection with the next candidate.
- On message_end: accumulate costTotal (usage.cost.total) + contextTokens
  (calcContextTokens) into RunRecord (live) + RunLog message.usage.cost.
- Cap abort: if tier.costCap && costTotal > costCap -> abort + finishRun reports
  'aborted' + 'budget_exceeded (cost $X > cap $Y)'.
- finishRun threads costTotal/contextTokens into the terminal RunRecord + run:ended
  event + SpawnResult.
- SpawnOptions.tierRegistry?/modelRegistry? optional (existing tests unaffected).

4 new tests: tier cost/context accumulation, fallback retry, cap abort, no-tier
no-cap. 334/334 passing, typecheck clean.
@rz1989s
rz1989s merged commit c3998ad into main Jul 28, 2026
1 check passed
@rz1989s
rz1989s deleted the feat/spec-6-1-cost-tiers branch July 28, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant