Repository navigation
feat(tools): one bounding boundary, ToolOutput split, masking, per-turn budget (T1) - #31
Merged
Merged
Conversation
…imitives T1 of docs/plans/tool-layer.md. New `tools/output.rs` with `Bounds` (ceilings 128 KiB / 4000 lines / 2000-byte lines), `bound_text` head+tail line-boundary bounding with one lossless-accounting marker, the header grammar helper, allocation-free secret masking, and the 96 KiB per-turn output budget. Not yet wired into dispatch.
T1: `ToolExecutionResult` becomes `ToolOutput { model_text, ui_payload,
file_state }`. Constructors mask secrets then apply `Bounds` once; the
per-tool truncation in read/list/search and the 256 KiB tail-cut are gone.
Edit/write diffs move to `ui_payload` inside dispatch. Shell gets a
`shell exit= elapsed= bytes=` header and a 16 KiB head+tail model bound
while the 128 KiB capture and live stream cap stay. The turn loop applies
the 96 KiB per-turn output budget to what enters context; persisted rows
keep each call's own bounded text. Pruning stubs keep a header line.
Adds the `tool_output` bench (fits no-op, 16 KiB shell from 128 KiB, 128 KiB from 1 MiB, one huge line, masking over x-filled and source-like text). Escape sizing is a 256-entry table, `exceeds` short-circuits on length, line counting uses the vectorized `matches`, and the mask scan skips to trigger bytes with `position`. TUI reads the shell verdict from the header and treats `…[qq: ` lines as markers; the R4 shell fixture asserts the new contract.
Design: § Output Bounding (ToolOutput split, Bounds, marker grammar, headers, masking, per-turn budget); built-in and shell sections updated. Ledger: T1 to In review with the receipt.
Merged
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.
T1: one bounding boundary,
ToolOutputsplit, masking, per-turn budgetSpec: docs/plans/tool-layer.md#d1--cross-cutting-primitives-t1 Linear: ENG-771
What changed
User-visible
shell exit=<code> elapsed=<s> bytes=<n>and the model sees a 16 KiB head+tail (was 128 KiB tail-cut). The 128 KiB capture and liveToolCallOutputDeltastream are unchanged. On acatof a 1 MiB file the model-facing text drops ~8×.…[qq: 41,207 bytes / 1,142 lines omitted; not stored]…. Lines over 2000 bytes are clipped with…+N. Head and tail are cut at line boundaries so no partial line ever reaches the model.sk-/xox/Bearer,KEY=valuecredentials,user:pass@host) are masked as[masked:<kind>]in model text. File hashes are unaffected.turn budget reachedin its marker. Persisted rows keep each call's own bounded text.ToolCallDisplay::Diff), never sent back to the model. Pruning stubs keep a result's header line.…[qq:prefix check.Design
crates/qq-core/src/tools/output.rs(new):Boundswith named ceilings (128 KiB / 4000 lines / 2000-byte lines / 4 KiB floor),bound_text,Header,mask_secrets,TurnOutputBudget,MARKER_PREFIX.ToolExecutionResult→ToolOutput { model_text, is_error, ui_payload, file_state }. Constructors mask then bound once;verbatim_errorfor constant runtime messages. Per-tool truncation removed fromread/list/search;truncate_resultand its 256 KiB tail cut are gone.regexdependency, no root request. Clean text returns without allocation.exceedsshort-circuits on length; omitted-line counting uses the vectorizedmatches.How verified
cargo test --workspace: 1283 passed / 0 failed (qq-core 481, qq-tui 234, qq 109, …). Twoheadlesstests with 1–2 s wall-clock timeouts flake only under full-workspace CPU contention and pass alone and incargo test -p qq.cargo fmt --all -- --check✓,cargo clippy --workspace --all-targets --all-features -- -D warnings✓,cargo build --workspace✓.qq-provideruntouched.tools::output::*(21: ceilings/floors, head+tail at line boundaries, single marker, thousands grouping, note, line-count bound,…+Nclipping incl. char boundaries and escape-dense lines, multibyte tail, determinism, header grammar, each masking kind, masking exemptions, no-alloc on clean text, turn budget floor, 1 MiB one-line shell capture),edits_carry_their_diff_as_a_ui_payload_never_as_model_text,secrets_in_results_are_masked_at_the_boundary,a_turns_tool_output_is_capped_and_persisted_results_stay_whole,pruning_stubs_keep_a_result_header_line, TUIcollapsed_summaries_curate_known_tools(shell header case).cargo run --release -p xtask -- perf r4-worker --case shellpasses on the new contract (completion 93 ms, 16 payload txns).Measurements
tool_dispatchread_tool_loop (A/B, 15 interleaved pairs, median)tool_outputfits_no_op_8ktool_outputshell_16k_from_128ktool_outputdefault_128k_from_1mtool_outputmask_source_128k / x_filled worst caseLoaded host; A/B delta is inside the A/A spread. Evidence:
target/qq-perf/t1-2026-09-11/(untracked).Docs
docs/design/tools.md: § Output Bounding (new), § Built-In Tools, § Shell Execution, § Context Budget.docs/plans/progress/tool-layer.md: T1 → In review, receipt appended.Compatibility
ui_payloadreuses the existingToolCallSnapshot.display/display_json. Marker and shell header text changed; nothing parses the old...[truncated by qq]orexit code: Noutside the TUI and the xtask fixture, both updated.exit code:trailer). Transcripts persisted before this change replay as-is.Follow-ups / decisions needed
not storedwith a spill handle;ToolOutputhas nospillfield until then.AGENTS.mdnames Linear teamDEV; the workspace's team isENG. Issue filed under ENG / projectqq.list_dir/searchTUI metrics still count body lines until T2 gives them headers.