feat(compaction): agent-loop planner with transcript-bound deletion tools - #1301
Conversation
Assistant-model: GPT-5.5
Review: feat(compaction): bind deletion planning to transcript toolsNice refactor — moving from "parse the final transcript text" to transcript-bound executable tools that validate each deletion as it's recorded is a real robustness win, and the new tool-call/result reconciliation cases ( Potential bugs / correctness1. Abort can still apply a partial plan. In ```ts 2. Tool Security3. ReDoS via model-supplied regex. Performance / cost4. No turn cap on the planner agent. This replaced a single 5. Redundant double validation. Code quality (minor)
Test coverageGood additions on pairing, content-block promotion, combined call IDs, and protected skipping. Gaps given the new surface area:
Overall direction is solid; #1 (abort) and #3 (ReDoS) are the two I'd treat as blocking. 🤖 Generated with Claude Code |
Assistant-model: GPT-5.5
|
PR Review — feat(compaction): replace single-shot planner with transcript-bound multi-call tool controller Thanks for this — the move from final-response parsing to executable, immediately-validated tools is a solid architectural improvement, and the test coverage is genuinely impressive (multi-call turns, grep guardrails, regex/invalid-regex, promotion, turn cap, abort). Feedback is grouped by area; nothing here is a blocker. The highest-value items are the performance note and the ReDoS note. Strengths
Performance
Potential issues / correctness
Minor / nits
Tests Overall a well-structured, well-tested change that meaningfully hardens the compaction planner. The performance bound on Reviewed against CLAUDE.md conventions (Bun-only, raw-TS, no build step) — no violations spotted in the changed files. |
Assistant-model: GPT-5.5
Review: agent-loop planner with transcript-bound deletion toolsThorough, well-tested change. The move from a single parse-the-final-response A few things worth considering before merge: 1. Performance of
|
Assistant-model: GPT-5.5
Review: agent-loop planner with transcript-bound deletion toolsThanks for this — the move from final-response parsing to executable, immediately-validated tools is a genuine improvement, and the My main concern is one architectural decision; the rest are minor. Major — the SQLite working copy looks like over-engineeringThis PR adds Concerns:
The Minor
Nice work overall — the core redesign and tests are solid; the SQLite layer is the one thing I would push back on before merge. 🤖 Generated with Claude Code |
Assistant-model: GPT-5.5
Review: agent-loop planner with transcript-bound deletion toolsThorough, well-tested change — the incremental tool-bound deletion model is a real improvement over parsing a final JSON blob, and the reconciliation/validation hardening (with six new targeted tests) is the strongest part of the PR. The ReDoS guard, scan-size caps, and 🔴 Adding
|
Rename the planner-facing deletion API to context_delete and let overflow recovery delete stale protected task-bearing context when needed. Assistant-model: GPT-5.5
Review: agent-loop planner with transcript-bound deletion toolsThorough, well-structured PR. The shift from parsing a final 🔴 Worth resolving before merge1. 2. Is a SQLite engine warranted here at all? 🟡 Should address3. "Parallel" execution safety relies on fully-synchronous tool bodies. 4. PR description is stale vs. the merged code. The description references 5. 🟢 Minor / nits
TestsStrong coverage; test names map cleanly to the guardrails (protected-skip, Overall: solid, careful work. The main asks are (1)/(2) — justify or shed the SQLite + native dependency — and (4)/(5) — sync the description and confirm the 50-turn cap. 🤖 Generated with Claude Code |
…ools (#1301) * feat(compaction): bind deletion planning to transcript tools Assistant-model: GPT-5.5 * fix(compaction): harden planner tool guardrails Assistant-model: GPT-5.5 * fix(compaction): make planner tools parallel-safe Assistant-model: GPT-5.5 * refactor(compaction): use sqlite working copy for planner state Assistant-model: GPT-5.5 * fix(compaction): pass transcript file to planner Assistant-model: GPT-5.5 * feat(compaction): add critical overflow deletion mode Rename the planner-facing deletion API to context_delete and let overflow recovery delete stale protected task-bearing context when needed. Assistant-model: GPT-5.5
Summary
Replaces the context compaction planner's single
completeSimplecall with a multi-turnAgentloop. Deletion decisions are now bound to four executable transcript tools that validate and accumulate targets incrementally, eliminating final-response parsing as a failure mode and enabling multiple independently guarded deletion calls per turn.Closes #1300.
Changes
New tools and controller
context_delete(reworked fromcontext_deletion_plan): transcript-bound tool that validates and accumulates deletion targets incrementally; routes through the same validation pipeline as grep-delete.context_grep_delete(new): bulk-deletes transcript entries or content blocks matching a literal string or regex, with embedded guardrails — protected-entry/block skipping,maxMatchessafety cap, and optionalexpectedMatchCountassertion.context_search_transcript(new): read-only search over the full transcript working copy, returning match snippets without mutating deletion state; lets the planner find candidate entry IDs before committing deletions.context_read_entry(new): reads a small slice of one transcript entry or content block by ID; keeps per-read cost bounded viamaxCharsandoffsetpagination.createContextDeletionTool(new): factory that creates all four tools plus a controller (getDeletionRequest,getValidatedResult,getLastError,getCallCount) backed by a shared SQLite working copy.CONTEXT_COMPACTION_MAX_TURNS = 50: hard turn cap on the agent loop.Planning loop
completeSimpletoAgent+streamSimplewithAbortSignalcorrectly propagated via event listener.callCount === 0.getLowestContextCompactionThinkingLevel).Validation hardening
reconcileToolDependencies(new): bounded fixpoint repair pass that auto-reconciles tool-call/tool-result pairing violations before the strictvalidateToolDependenciesassertion — handles promoted entry deletions, orphaned results, and protected-entry constraints.mergeContextDeletionTargets(new): merges incremental target lists while keeping entry-level deletions canonical over per-block targets.validateContextDeletionPlannow runsreconcileToolDependenciesbefore overlap and dependency checks, turning previously thrown errors into repaired outputs.contextCompactuses the pre-validated plan from tool execution (skips redundant post-hocvalidateContextDeletionPlancall).Planner state persistence
ContextDeletionSqliteStore: transient SQLite working copy holding transcript entries, content blocks, accumulated deletion targets, call count, and last error — enables parallel-safe tool execution and efficient grep/search scans.Transcript manifest
contextCompactionTranscriptManifest: generates a bounded manifest (protected entries + highest-token unprotected entries, up to 80) as a structured preview in the prompt, with the full JSONL file path for deeper reads.transcriptEntryFilePayload: serializes full entry text and content blocks to JSONL for the transcript file.Tests
context-compaction-deletion-tool.test.ts) to exercise multi-tool-call turns and verify tool-result pairing in continuation context.terminate: falsecontinuation on both tools, grep guardrail behavior (protected skip,maxMatches, match reporting), and thecontext_grep_deletepath through the planner agent.validateContextDeletionPlantests covering tool-call/result reconciliation, block-index promotion, combined sibling deletions, and multi-tool assistant entry promotion.Migration notes
No breaking changes to the public
contextCompact/planContextDeletionsAPI surface. InternalparseContextDeletionPlanResponseis renamed toparseContextDeletionResponse;RawContextDeletionPlanis renamed toContextDeletionRequest;ValidatedContextDeletionPlanis renamed toValidatedContextDeletionResult. Existing callers ofvalidateContextDeletionPlanreceive reconciled rather than raw targets in the returneddeletedTargets.Validation