feat: token optimization layer — doc-converter, CCR, and compression pipeline
Problem
gitagent currently cannot read PDF, DOCX, XLSX, or PPTX files. Clients whose users upload documents get a [Binary file] response — the agent is blind to those files entirely.
Additionally, when agents work with large documents across multiple turns, the full document content accumulates in context on every turn, compounding API costs with each message.
Proposed Solution
A multi-layer token optimization pipeline built into the read tool:
1. Doc-converter — binary → readable
Convert PDF, DOCX, XLSX, PPTX to clean markdown automatically when read() is called. No manual pre-processing needed by the client.
2. CCR (Chunked Reversible Retrieval) — large doc efficiency
For documents exceeding a token threshold, return a lightweight outline on first read. The agent fetches only the sections it needs via read_doc_section. Prevents large documents from flooding context on every turn in multi-turn sessions.
3. SmartCrusher — JSON compression
Strip nulls, deduplicate arrays, truncate padding from JSON tool outputs.
4. CodeCompressor — source file compression
Remove comments and blank lines from source files before returning to agent.
5. CacheAligner — system prompt KV cache
Reorder system prompt so static content comes first, maximising provider-side KV cache hits across sessions.
Scope
src/tools/read.ts— pipeline wired insrc/tools/doc-converter.ts— newsrc/tools/doc-store.ts— new (CCR +read_doc_sectiontool)src/compression/— new (SmartCrusher, CodeCompressor, CacheAligner)
Benchmark methodology (proposed)
Compare two successful agent runs on the same document:
- Baseline — doc-converter converts PDF, full markdown injected into prompt
- With CCR — agent receives outline, fetches only relevant sections on demand
This gives a fair apples-to-apples token comparison where both runs complete the task.
Closed as New Issue is issued