Files
deepseek-harness/packages/compact
Hypatia May d6da8ca29a fix(compact): decide step-alignment from surface tool-pairing, fire compaction pre-step (CBR-001)
Codex round 1 CBR-001: a head-anchored compaction checkpoint was
mis-classified by the log-position step-alignment scan, so a second
auto-compaction over a checkpoint-headed surface silently failed.

Root cause: `isStepAlignedStart/End` scanned the LOG by seq, but a
`replace` op lands a checkpoint at a high log seq whose SURFACE position
is the head — its log neighbours (the open step's assistant/message) are
not its surface neighbours, so the forward scan wrongly reported mid-step.

Fix, per the agreed direction:
- Replace the two log-position predicates with one surface-anchored
  helper `isToolPairingBalanced(nodes, events, beforeSeq)` in
  `dsh-session` (renamed step-boundary.ts → tool-pairing.ts). A cut is
  balanced when no unanswered tool-call precedes it on the surface; a
  region is collapsible iff both edges are balanced cuts. The open-tail
  and free-node cases fall out of the same counter. It also throws on a
  corrupt surface (a tool/result with no matching call).
- Move compaction off the in-step seam to a new "pre-step" seam fired
  after turn/start and before step/start, so a compaction's log-only
  compact/* records and its replacement node land cleanly OUTSIDE any
  step (the honest structure crash-safety relies on). Renamed the event
  agent/pre-request → agent/pre-step and switched its dispatch from
  parallel → serial (listeners mutate the surface as a side effect;
  serial isolates them so concurrent appends can't interleave). Extended
  the catalog generator to accept @mode serial.

Regression coverage: a real-loop test driving an auto-compaction asserts
the landed checkpoint is a balanced cut on both sides; unit tests pin the
checkpoint case, the mid-step injection case, multi-call steps, and the
corrupt-surface guard. Proven red on the old log-position logic.
2026-06-26 13:51:01 +08:00
..

compact/ — compaction capability family

A three-package capability seam (see capability seams): an abstract compaction interface, a backend that summarizes, and the model-facing tool that consumes it. The interface and a first backend (compact-basic/) exist; the consumer tool is deferred. All product packages.

Package Role ctx key
compact/ Abstract compaction seam (interface + compact/* events + CompactionResult) ctx.compact
compact-basic/ A backend: char/4 estimation + token-budget retention + llm.stream() summarization (registers ctx.compact)
tool-compact/ (deferred) Model-facing /compact tool over ctx.compact (registers on ctx.tools)

The interface lives at compact/compact/, the backend at compact/compact-basic/. Unlike the bash seam, it depends on dsh-session and dsh-llm — its verbs are defined over a Session and its output is the ContentBlock vocabulary, so the contract cannot be expressed without naming them. That deviation from the "interface depends only on cordis" guidance is intentional and recorded in the compaction capability-seam RFC. A tokenizer- or template-based backend would replace compact-basic without touching the interface or the tool.