…counting (#1766)
- Split chat-prompt-budget-diagnostics.ts under the 400-LOC cap by extracting
the token-summary helpers into chat-prompt-budget-token-summary.ts.
- Document the deliberate lane attribution: the compaction summary's tokens are
charged to the history-summary lane (which owns the +1 summary item), while
system-contract reports only the bare canonical system prompt.
- Pin the compacted-path lane split with a mutation-robust test.
- Reject stray scaleMilli/offsetTokens under source "fallback-estimated".
- Document the defensive clamp in calibratedTokenCount; add redactTokenAccounting
and validator-rejection test coverage.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
Adds governed per-model calibrated token accounting for context budgeting and prompt assembly, while preserving the existing conservative fallback estimator and reporting the active accounting source in diagnostics.
Resolves #1766
Scope
Reuse And No-Duplication
Delivery Board
Keiko Product Deliveryproject.Parent Epic: #1720unless this PR updates an epic container directly.Classification: Epic,Status: Open Epics, and priority/order set for top-to-bottom implementation sequencing.Classification: Task,Status: In Progresswhile active, inherited or explicitPriority, andHuman Review Required: Yes.StatusisIn Progresswhile work is active, orDoneonly after merge and closure evidence.Workflow StateisPR OpenorReady for Human Review.Owner / Agent,Branch,Pull Request, andHuman Review Requiredare filled.status: in progress,status: ready for human review, orstatus: doneafter merge.dev, enable auto-merge, close the issue, or bypass human review unless explicitly authorized by the human maintainer.Product Impact
Update Impact
improvements.high.dev.Verification
Required:
Local verification:
Reuse / gap rationale:
Select only what applies:
npm run check:release-impactor an explicit rationale.Not applicable rationale:
Review And Closure
Resolves #1766only when this PR should close the issue.Risk Notes
tokenAccounting.counterIdis content-free metadata, is trimmed/validated at config boundaries, and is redacted from persisted evidence.v24.14.0because the machine default Nodev25.9.0is rejected by dependency-cruiser; no repo code was changed for this environment issue.