Skip to content

feat(runtime): route large tool outputs through workshop to protect parent context (closes #548)#658

Merged
Hmbown merged 3 commits into
Hmbown:mainfrom
merchloubna70-dot:feat/large-tool-output-548
May 5, 2026
Merged

feat(runtime): route large tool outputs through workshop to protect parent context (closes #548)#658
Hmbown merged 3 commits into
Hmbown:mainfrom
merchloubna70-dot:feat/large-tool-output-548

Conversation

@merchloubna70-dot

Copy link
Copy Markdown

Summary

  • Introduces LargeOutputRouter that intercepts tool results exceeding a token threshold (default 4 096 tokens) before they enter the parent context
  • A structured synthesis header replaces the raw blob in the parent; the full raw content is stored in the workshop variable last_tool_result for later promote_to_context retrieval
  • Individual tool calls can pass raw = true to bypass routing for that invocation
  • Per-tool threshold overrides are supported via [workshop.per_tool_thresholds] in config.toml

Changes

File Change
crates/tui/src/tools/large_output_router.rs New module: LargeOutputRouter, WorkshopConfig, WorkshopVariables, RouteDecision, token estimator, synthesis-prompt builder, 14 unit tests
crates/tui/src/tools/spec.rs ToolContext gains large_output_router + workshop_vars fields and with_large_output_router builder
crates/tui/src/tools/registry.rs execute_full_with_context applies routing after every tool call
crates/tui/src/core/engine.rs EngineConfig.workshop, Engine.workshop_vars, wired in build_tool_context
crates/tui/src/config.rs Config.workshop deserialization + merge_config propagation
crates/tui/src/main.rs, runtime_threads.rs, tui/ui.rs Pass workshop field through EngineConfig initializers
config.example.toml Documents [workshop] table with threshold and per-tool override examples

Design notes

  • ToolContext.large_output_router = None by default: sub-agents and test contexts see no routing (prevents recursive synthesis calls)
  • Token count uses a conservative 3 chars/token heuristic — the real tokeniser is not a dependency at this layer
  • The synthesis currently produces a structured preview + provenance header; the live V4-Flash API call is deferred to a follow-up once async is safe from the registry layer
  • WorkshopVariables is an Arc<Mutex<…>> shared across all tool calls in the session so last_tool_result persists until explicitly consumed

Test plan

  • cargo check — zero errors, zero warnings (verified in CI pre-push)
  • [workshop] large_output_threshold_tokens = 512 in local config → small grep results pass through, large file reads get the synthesis header
  • read_file path="bigfile.rs" raw=true → bypass confirmed, full content returned
  • [workshop.per_tool_thresholds] exec_shell = 256 → shell output synthesised at tighter limit while other tools use the global threshold
  • Sub-agent spawned via spawn_agent inherits no router → no recursive synthesis

🤖 Generated with Claude Code

macworkers and others added 3 commits May 4, 2026 12:39
All system prompts were English-only, causing DeepSeek V4 to reason
and respond in English even when users wrote in Chinese or other
languages.

Add a Language Mirror section to base.md and base.txt that instructs
the model to detect the user's primary language and use it for both
reasoning (thinking tokens) and the final reply.
base.txt is not referenced via include_str! in prompts.rs.
Only base.md is loaded (BASE_PROMPT). Remove the redundant change
to base.txt as noted by Gemini Code Assist review.
…arent context (closes Hmbown#548)

Tool outputs (read_file, grep_files, exec_shell, fetch_url, web_search) that
exceed a configurable token threshold are now intercepted before they reach
the parent context. A structured synthesis header replaces the raw blob; the
full content is stored in the workshop variable `last_tool_result` for later
`promote_to_context` retrieval.

Key changes:
- New `crates/tui/src/tools/large_output_router.rs`: `LargeOutputRouter`,
  `WorkshopConfig`, `WorkshopVariables`, `RouteDecision`, token estimator,
  synthesis-prompt builder, and wrap_synthesis helper. Full unit-test suite.
- `ToolContext` gains `large_output_router` and `workshop_vars` fields plus
  the `with_large_output_router` builder; constructor defaults are `None` so
  sub-agents and test contexts are unaffected.
- `ToolRegistry::execute_full_with_context` applies routing after every tool
  call; `raw=true` in the tool input bypasses routing for that invocation.
- `EngineConfig` gains a `workshop` field; `Engine::new` creates the shared
  `WorkshopVariables` Arc when the field is present and wires it into every
  `build_tool_context` call.
- `Config` gains `[workshop]` table deserialization; `merge_config` propagates
  it like other optional tables.
- `config.example.toml` documents `[workshop]`, `large_output_threshold_tokens`
  (default 4096), and per-tool threshold overrides.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@ILoveScratch2

Copy link
Copy Markdown

谁家PR机器人

Hmbown added a commit that referenced this pull request May 5, 2026
47 fmt drifts had accumulated from the squash-merged community PRs on
this branch (#653, #654, #655, #645, #658, #668, #659, #661, #660,
#667, #656). Pure formatting — no behavioural changes — applied via
`cargo fmt --all` to satisfy CI's `cargo fmt --all -- --check` gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Hmbown Hmbown merged commit 937f5f3 into Hmbown:main May 5, 2026
1 check passed
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
47 fmt drifts had accumulated from the squash-merged community PRs on
this branch (Hmbown#653, Hmbown#654, Hmbown#655, Hmbown#645, Hmbown#658, Hmbown#668, Hmbown#659, Hmbown#661, Hmbown#660,
Hmbown#667, Hmbown#656). Pure formatting — no behavioural changes — applied via
`cargo fmt --all` to satisfy CI's `cargo fmt --all -- --check` gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants