Conversation
Every dispatched request now logs a local prompt-size estimate in the audit log: total chars, estimated tokens (ceil(chars / 4)), a section breakdown (relay instructions, conversation, tool results, tool schemas, payload JSON), retention limits, and forwarded tool counts. Hyperagent does not report authoritative usage, so figures are labeled as local estimates everywhere. New CLI surface: - hacb cost-report [--last N]: per-request table plus totals/averages - hacb explain-prompt [--verbose]: section breakdown of the last prompt - hacb audit --cost [count]: receipts with estimated token columns Prompt excerpt capture is strictly opt-in via debugPromptExcerpts; excerpts stay bounded (240 chars) in the private 0600 state directory and never reach the sanitized audit or gateway logs.
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.
What changed
Adds local, estimate-only cost visibility before any optimisation behaviour changes. No dispatch behaviour is modified.
Prompt metrics (src/protocol.mjs)
buildRelayPromptWithMetrics()returns the unchanged relay prompt plus a breakdown:totalChars,estimatedTokens = ceil(chars / 4),estimator,usageSourcerelayInstructionChars,conversationChars,toolResultChars(inside conversation),toolSchemaChars,payloadCharslimits(maxInputChars / maxTurnChars / maxConversationTurns / maxForwardedTools), retained turns, forwarded tool countretentionLimits()helper removes duplicated clamp logic innormalizeInput/normalizeTools;buildRelayPrompt()output is byte-for-byte identical to before.Audit fields (src/bridge.mjs)
request_reservednow carries the full breakdown + limits;completedadditionally carriespromptChars/estimatedPromptTokens. Every dispatched request logs estimated prompt usage.CLI
hacb cost-report [--last N]— per-request table (chars, ~tokens, conv/schema/result chars, tools, daily budget) plus totals/averageshacb explain-prompt [--verbose]— where the last relay prompt's characters wenthacb audit --cost [count]— receipts with estimated token columnsOpt-in excerpt capture (src/config.mjs)
debugPromptExcerpts(default false). When enabled, bounded (240-char) prompt excerpts are written only to the private state dir (prompt-excerpts.jsonl, mode 0600) via an injectable writer; never to the sanitized audit or gateway logs.Why it saves credits
This PR does not change spend by itself — it makes credit burn measurable per request so PRs 2–3 (tool shortlisting, result reducer) can show measured before/after evidence instead of guesses.
Security posture preserved
usage_sourceremainsunavailable; no fabricated usage objects).Testing
New tests cover:
request_reserved/completedExample output (synthetic local data)
Note: opened from a fork because this workstation's credentials have read-only upstream access; branch name follows the handover plan.