feat: add token observability with per-entity lifecycle attribution#194
Open
ChenNima wants to merge 2 commits into
Open
feat: add token observability with per-entity lifecycle attribution#194ChenNima wants to merge 2 commits into
ChenNima wants to merge 2 commits into
Conversation
…le tracking Track AI agent token consumption across the full AI-DLC lifecycle (elaboration → proposal → review → execution → verify). Key design: - Shell hooks extract per-API-call usage from CC transcripts with streaming dedup and delta cache_read computation - Sub-agents use last-turn snapshot (matches CC's total_tokens); main agent uses per-turn delta with user-boundary round filtering to prevent non-chorus conversation leakage - Primary entity model for sub-agents (task > proposal > idea > document priority) - Carry-forward attribution for main agent with user message boundaries as reset points - isReviewer flag distinguishes task-reviewer (verify phase) from dev (execution phase) - Delete-then-insert upsert on sourceSessionId for idempotent uploads - Frontend tokensSum includes all 4 Claude API fields (input + output + cache_create + cache_read) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…sage Brings observability.service.ts statement coverage above the 95% CI threshold. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
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.
Summary
isReviewerfield distinguishes task-reviewer (verify) from dev (execution)tokensSumincludes all 4 Claude API fields (input + output + cache_create + cache_read)Changed files
prisma/schema.prisma, 3 migrationsToolUsageEvent,TokenUsageRecordmodels,isReviewerfieldon-stop.sh,on-subagent-stop.sh,on-session-end.sh,on-post-tool-log.shagent-report/token-usage,agent-report/tool-usage,observability/*observability.service.tstokens-view.tsx,agent-observability.tsx,token-usage-card.tsx,task-tokens-view.tsxmessages/en.json,messages/zh.jsontoken-attribution.test.ts,observability.service.test.ts,format-tokens.test.tsTest plan
npx tsc --noEmitpassespnpm test— 1363 tests passbash public/chorus-plugin/bin/test-syntax.sh— 16/16 pass🤖 Generated with Claude Code