feat: leveled response views + --level knob with snapshot digest — Phase 4#942
feat: leveled response views + --level knob with snapshot digest — Phase 4#942thymikee wants to merge 2 commits into
Conversation
… Phase 4
Add the agent-cost leveled-response system: a responseLevel knob
(digest | default | full) plumbed end to end behind a global --level flag
(mirroring --cost), and a per-command ResponseView registry applied in the
router on the success path.
- contracts: RESPONSE_LEVELS/ResponseLevel + meta.responseLevel + boundary
schema whitelist. Plumbing mirrors --cost: cli-flags FlagDefinition +
GLOBAL_FLAG_KEYS, AgentDeviceClientConfig + overrides, buildClientConfig,
buildMeta. ResponseLevel exported from the public root.
- src/daemon/response-views.ts: the ResponseView registry. Seeds the snapshot
digest — the full node tree (the dominant token sink) collapses to
{ nodeCount, refs: first 12 hittable/non-occluded refs with labels } plus the
cheap top-level signals (truncated/visibility/snapshotQuality). full returns
today's shape (nothing richer is computed yet).
- router graft (applyResponseLevelView + applyAgentCostGrafts): composes with
the existing cost block. With responseLevel default (or unset) AND no
registered view AND no --cost, the original response is returned UNCHANGED —
byte-identical to today (Maestro .ad recompare safe). cost.nodeCount reads the
original node tree so it stays accurate even after a digest.
Tests: snapshot view unit test (digest filters hittable/occluded, drops the
tree, keeps cheap signals; default/full passthrough); router graft test via an
injected view (default identity byte-identical, digest applies, full passthrough,
digest+cost composition, unregistered-command passthrough, boundary parse).
Verified: tsc, oxfmt + oxlint --deny-warnings, fallow audit clean, rslib build,
Layering Guard empty, 1106 daemon/contracts/client tests pass (incl. the
existing cost/typed-error grafts after the restructure).
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
|
Current head Please add |
The new --level/responseLevel flag (#942) is a diagnostics/output flag (not device-observable), so it belongs in the exclusion bucket alongside --cost. Unblocks the Provider-backed integration progress check.
|
Reviewed current head
That means the advertised token-cheap |
What
The core of Phase 4's token win: a leveled response system. A
responseLevelknob —digest | default | full— behind a global--levelflag (mirroring--cost), with a per-commandResponseViewregistry applied in the router on the success path.The headline view: snapshot digest collapses the full node tree (the dominant token sink for agents) to
{ nodeCount, refs: first 12 hittable/non-occluded refs with labels }plus the cheap top-level signals.Invariant (Maestro-safe)
With
responseLeveldefault(or unset) AND no registered view AND no--cost, the router returns the originalresponseobject untouched — byte-identical to today, so the Maestro.adrecompare path is unaffected. Views and cost are purely additive and compose (cost computed from the original node tree, socost.nodeCountstays accurate even after a digest).Changes
src/contracts.ts:RESPONSE_LEVELS/ResponseLevel,meta.responseLevel, boundary-schema whitelist. Plumbing mirrors--costend to end (cli-flags FlagDefinition +GLOBAL_FLAG_KEYS,AgentDeviceClientConfig+ overrides,buildClientConfig,buildMeta).ResponseLevelexported from the public root.src/daemon/response-views.ts(new): theResponseViewregistry, seeding the snapshot digest.fullreturns today's shape (nothing richer is computed yet).src/daemon/request-router.ts:applyResponseLevelView+applyAgentCostGraftson the success path — composes cleanly with the existing cost block.Tests
response-views.test.ts: the snapshot view — digest filters tohittable === true && interactionBlocked !== 'covered', drops the tree, keepstruncated/visibility/snapshotQuality;default/fullare reference-identical passthroughs.request-router-response-level.test.ts: the router graft via an injected test view — (a) default identity isJSON.stringify-identical to no-meta, (b) digest applies, (c) full passthrough, (d) digest +--costcomposition, (e) unregistered command + digest is byte-identical, (f)responseLevelsurvives boundary parse.Verification
tsc --noEmit0;oxfmt+oxlint --deny-warningsclean;fallow audit --base origin/mainclean;rslib build0; Layering Guard emptyvitestdaemon/contracts/client → 111 files / 1106 tests pass (incl. the existing cost/typed-error grafts after the router restructure)Scope / follow-ups (Phase 4 workstreams)
outputSchema(independent).overlayRefs, the single-nodefind/getfamily); the typed batch-step digest (WS4, rides on this); MCPresponseLevelexposure (held back to avoid colliding with feat: per-command MCP outputSchema — Phase 4 #941'scommand-tools.tsedits); and the zero-load fast-path generalization (sensitive routing — better as a focused follow-up).