feat: rule-based tool input compaction for auto-capture (~10x storage reduction)#2874
feat: rule-based tool input compaction for auto-capture (~10x storage reduction)#2874lg320531124 wants to merge 3 commits into
Conversation
|
Nice implementation! Rule-based tool input compaction without LLM involvement is a smart approach — reduces cost and latency for auto-capture. The inline test functions avoid coupling to the full module. Tool input policies (full vs summary) are well-designed. |
Add compactToolInput() to reduce Write/Edit/Bash/TaskCreate/TaskUpdate tool inputs to structural summaries (file path + line count + preview) instead of full file contents. This reduces session storage ~5x-10x, improves vector signal-to-noise ratio for VikingDB embeddings, and makes VLM memory extraction more likely to succeed. Changes: - auto-capture.mjs: add compactToolInput() with per-tool-type policies (full preservation for Read/Glob/Grep/LSP/WebFetch/WebSearch/Skill; summary mode for Write/Edit/Bash/TaskCreate/TaskUpdate) - auto-capture.mjs: harvestContent() now uses compactToolInput when toolInputCompaction is enabled (default) - config.mjs: add toolInputCompaction (default true) and toolInputMaxChars (default 2000) config options - __tests__/auto-capture-compaction.test.mjs: 21 regression tests covering all tool types, truncation, edge cases, and compression ratio Backward compatible: OPENVIKING_TOOL_INPUT_COMPACTION=false restores the old verbatim behavior.
4d80943 to
d4e525e
Compare
|
The I posted the full diagnosis on sibling PR #2900 (rebased onto latest This PR ( I don't have admin rights to rerun from a fork — could someone with access rerun the |
buildParts() (structured tool parts sent to OV as tool_input) bypassed compactToolInput, sending raw block.input objects while the prose extractAllTurns path already compacted Write/Edit/Bash/Task* to structural summaries. The ~10x storage reduction from volcengine#2874 only covered the inlined-text path; structured parts carried full Write content verbatim. Mirror the prose path: apply compactToolInput when cfg.toolInputCompaction !== false, fall back to formatToolInput otherwise. Non-summary tools (Read/Glob/Grep) keep full input. tool_input now a string (consistent with tool_output). Adds 6 buildParts regression tests asserting parity with the prose path for Write/Edit/Bash/Read, compaction=off fallback, and non-object input handling.
Summary
Add rule-based tool input compaction to the Claude Code auto-capture pipeline.
compactToolInput()reduces Write/Edit/Bash/TaskCreate/TaskUpdate tool inputs to structural summaries instead of full file contents.Problem
Sampling 16 CC sessions shows 79% of session storage volume is full code content from Write (avg 11,575 chars) and Edit (avg 2,525 chars) tool inputs. This causes:
bge-large-zh-v1.5embeddings are dominated by code tokens instead of semantic contentSolution
No LLM involved — purely rule-based compaction:
Measured: 10.6x compression on realistic mixed session data.
Changes
auto-capture.mjs: AddcompactToolInput()with per-tool-type policies (TOOL_INPUT_POLICIES); modifyharvestContent()to use compaction when enabledconfig.mjs: AddtoolInputCompaction(default: true) andtoolInputMaxChars(default: 2000) config options with env var overrides__tests__/auto-capture-compaction.test.mjs: 21 regression tests covering all tool types, truncation, edge cases, and compression ratioConfiguration
OPENVIKING_TOOL_INPUT_COMPACTIONtrueOPENVIKING_TOOL_INPUT_MAX_CHARS2000Set
OPENVIKING_TOOL_INPUT_COMPACTION=falseto restore the old verbatim behavior.Test Plan
Closes #2875