feat(spec-6-1): cost-aware tiers + cost accounting + context% + Tiers view (v0.10.0) - #15
Merged
Conversation
…textFloor filter)
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.
…at (hide runId, agent-if-named)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
/fleetTiers view. v0.10.0 (minor).Surfaces
Tier({ name, models[], costCap?, contextFloor? }) +TierRegistry(builtins < global < projecttiers.json) +resolveAgentModel(precedence:opts.model>agent.tier>agent.model> parent;contextFloor+ catalog filter; fallback retry oncreate()rejection).AgentDef.tier?frontmatter.RunRecord.costTotal(live, fromusage.cost.total) +RunLogwidening. Per-runcostCapabort (budget_exceeded).RunRecord.contextTokens(calcContextTokens) +ctx%in the above-editor widget + Runs tab (denominator =modelRegistry.find(...).contextWindow)./fleetTiers tab — tier list + per-tier spend + inline edit actions (Set models/costCap/contextFloor, Add/Delete, scope toggle) writingtiers.json.Key discovery
pi-ai's
Usageevent already carriescost.total($) +totalTokens(context) — no pricing engine needed.pi.modelRegistry.find(provider, id).contextWindowis 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).