Teams cost - #17
Open
Felixoid wants to merge 2 commits into
Open
Conversation
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
Adds token usage and cost tracking for child Pi processes launched by
agent_team. Eachmessage_endRPC record carries the child'sAssistantMessage.usagepayload;RpcUsageTracker(inrpc-message-end-handler.ts) accumulates it synchronously as steps run. On step completion the cost flows intoStepState, surfaces asStepSnapshot.usage(per-step) andRunSnapshot.teamUsage(run total), and appears inrun_status/step_resultmodel output.In interactive Pi, a separate footer status line (
team: $X.XXX ↑Xk ↓Xk ...) accumulates across allagent_teamruns in the session viactx.ui.setStatus. This is distinct from the parent session's own$X.XXXcost counter and is controlled by the newagent_team:footer-costboolean flag (defaulttrue).Scope
Proposal issue, if required:
Checklist
origin/main. It based on Fix gate tests fornpm --jsonoutput format change from array to object #16package.jsonversion.CHANGELOG.md.## Unreleased, if applicable.package:validatorrequires effectivebash;package:workerrequires effectiveeditorwrite.npm publish, create tags, push release branches, or create GitHub Releases.Design-gate check
This PR changes any of the following:
agent_teamactions or schemaNo design-gate boxes apply.
teamUsageandusageare additive read-only fields on existing snapshot types; no action schemas, authority gates, or persistence paths change. Here's the proposal issue #15Validation
Paste fresh command output or explain why a command is deferred.
pnpm run typecheck pnpm test pnpm run gate git diff --checkThey pass clean, but don't fit the limit.
Notes for reviewers
message_endRPC records (AssistantMessage.usage), not from aget_session_statsfetch. This avoids any async race between a stats request and natural child close. If a step produces nomessage_endrecords with usage (e.g. fake child in tests),usagestaysundefinedand no footer write occurs.RpcUsageTrackercaptures allmessage_endevents received before termination; partial cost is preserved.sessionTeamUsageandcountedRunsBySessionare in-memory maps in the extension closure, cleared onsession_shutdown. The status line is only written when a run terminates with real usage, and only cleared on shutdown if cost was ever accumulated.agent_team:footer-cost falsedisables the footer line going forward; it does not retroactively clear an already-set status.rendering.test.ts: thesetStatusguard now scanssrc/(implementation files must not touch UI) plus a positive assertion that anysetStatusinindex.tsmust useFOOTER_COST_FLAG.check-source-size.ts: two files exceeded the 18432-byte budget after additions; extractedRpcUsageTrackerintorpc-message-end-handler.tsand token/cost formatters intoresult-model-text.ts.