Repository navigation
Conversation
…mpaction When agy trims or compacts replay history, its reported input and cached read tokens reflect agy's smaller internal context rather than the client's full request payload. Clients like Codex that trigger compaction from reported input/cache usage then see context shrink and fail to compact on time. Add an opt-in `report_client_context` plugin option (default false) and `AGY_BRIDGE_REPORT_CLIENT_CONTEXT` env override (env takes precedence): - Capture `clientInputEstimate` (`estimateInputTokens(body)`) per response step and pad `cache_read_input_tokens` in outgoing `message_delta.usage` up to that estimate when enabled, keeping `agy` actual > client estimate intact and preserving zero usage on intermediate `agy_same_generation` tool steps. - Keep `Turn.recordResponseUsage` unpadded so internal window calibration stays faithful to agy, and apply the option consistently across SSE and `stream: false` responses. - Document the option and env var in README.md / README.en.md and bump version to 0.1.67. Tested on macOS with temp HOME (`magpie-bun test`): - `test/usage-settlement.mjs`: 43 pass, 0 fail - `agy-cli.test.mjs`, `cloak.test.mjs`, `install.test.mjs`: 35 pass, 0 fail
|
Harm scan: clean. The only new input is One thing to say in the option's text: magpie's Usage page prices |
|
Thanks for pointing that out! I've updated the |
|
Closing this PR — we'll keep this as a local patch for our own workflow instead. Thanks for reviewing! |
Why
When
agytrims or compacts history on replay, the usage reported back byagyreflectsagy's internal trimmed context window rather than the full request sent by the client. For clients such as Codex that watch reportedinput_tokens + cache_read_input_tokens + cache_creation_input_tokensto decide when to compact history, the reported context size drops unexpectedly and client-side compaction does not trigger on time.What changed
packages/agy-cli/index.mjs):report_client_contextunderauth.options(default: false, withen/zh/zh-TW/ja/delabels and descriptions).reportClientContextEnabled(magpie)withAGY_BRIDGE_REPORT_CLIENT_CONTEXT(1/true/on/yesor0/false/off/no/disabled) taking precedence overmagpie?.option?.("agy-cli", "report_client_context").input = {}inAntigravityBridgePluginso OpenCode 1.x/2.x callers without amagpiecontext continue working unchanged.packages/agy-cli/index.mjs):clientInputEstimate(estimateInputTokens(body)) on eachTurn.registerResponsestep.clientReportedUsage(step, usage, final, enabled)to padcache_read_input_tokensup toclientInputEstimateonly on the outgoingmessage_deltapayload, while:agy_same_generationintermediate tool steps (keeping their reported usage at zero),agyalready reports more tokens thanclientInputEstimate, andusagetoturn.recordResponseUsage(...)so internal window calibration remains faithful toagy.streamResponsecall sites (tool continuation, stale-turn replay recovery, and normal turns) through a sharedrespondhelper, covering both streaming andstream: falseJSON responses.packages/agy-cli/README.mdandpackages/agy-cli/README.en.md(Featuresand environment variables table).packages/agy-cli/package.jsonfrom0.1.66to0.1.67(forscripts/bumped.mjs).pluginContextinjection inpackages/agy-cli/test/testkit.mjsand tests inpackages/agy-cli/test/usage-settlement.mjscovering replay-trim padding, internal calibration isolation, option metadata validation,agy_same_generationmulti-tool steps,stream: false, no-downward-clamp guard, env override precedence, andpluginContext: null.Verification
HOME=$(mktemp -d) bun test packages/agy-cli/test/usage-settlement.mjs— 43 pass, 0 fail (run locally viamagpie-bun)HOME=$(mktemp -d) bun testinsidepackages/agy-cli— 35 pass, 0 fail (235 assertions)packages/agy-cli/opencode2.mjsmatchesHEAD:scripts/opencode2.mjs, OpenCode 1.x/2.x plugin export/loader check withoutmagpiecontext,npm pack --dry-run(magpie-community-opencode-agy-cli-auth-0.1.67.tgz), andgit diff --check