Skip to main content

Module handoff

Module handoff 

Source
Expand description

TR-9 (T24): /handoff as extreme projection — “Amp retired summarization-compaction for /handoff: spawn a new thread seeded with a drafted objective + curated relevant artifacts, old thread untouched.” (TOKEN-REDUCTION-TECHNIQUES.md@ad3f2a4 §T24). In supercode a handoff is NOT a new session lineage — it is a named ReductionLog snapshot over the SAME sidecar: the projected view collapses to (1) a handoff banner, (2) an objective paragraph, and (3) a curated keep-set, with EVERY OTHER turn covered by one ReductionKind::TurnsCleared span per contiguous gap between kept turns.

§Design: reusing TurnsCleared, not inventing a new kind

A handoff keep-set is generally scattered (system prompt + some user-named early turns + the last K turns), so the “everything else” complement is generally MULTIPLE disjoint ranges, not one. Rather than a dedicated HandoffCleared reduction kind, this reuses ReductionKind::TurnsCleared verbatim — one record per gap — which required exactly one change to super::project_messages itself: its reapplication path used to assume “at most one TurnsCleared reduction, ever” (true for the auto-compactor, Agent::maybe_compact); it now reapplies EVERY existing TurnsCleared record it finds, which is a strict, backward-compatible generalization (a log with zero or one such record behaves identically to before). invert/verify_log/ expand_reduction/sidecar_search already treated log.reductions as an unordered bag keyed by id/address — those needed NO changes at all.

§Banner/objective are view-only, never in the sidecar

The banner+objective text is never a Reduction and never recorded in the ReductionLog — it is folded into the projected VIEW’s leading system-role message only (merged into an existing leading system message if the canonical session has one, else inserted as a new one), exactly like TR-7’s super::SpanSummary audit metadata: view-layer only, invert/verify_log never look at it, and it structurally cannot reach supercode-core’s session export adapters (which rebuild only from the sidecar, never from a projected view).

§Fresh projection, not an incremental one

build_handoff deliberately builds its handoff view from a FRESH projection (ReductionLog::default()) over the canonical session rather than reapplying whatever reduction log the session already had — a handoff is “one projection event” (SPEC.md C7’s own framing), so kept turns show their full, untouched content (never stacked on top of whatever had been truncated/deduped/superseded before), and the emitted ReductionLog is exactly the set of reductions the handoff itself establishes: the standard lossless per-message passes (A7-A9, TR-2, TR-4, TR-6, TR-10) plus one TurnsCleared per non-kept gap.

Structs§

HandoffResult
The complete output of build_handoff.

Enums§

ObjectiveSource
Where the objective paragraph came from — build_handoff’s dev/05 contract: user text always wins when given; otherwise, drafting is attempted only when draft_objective is on AND a summarizer is injected, and any failure (no summarizer, an Err, or a blank result) falls back to the plain banner with no objective line at all.

Functions§

build_handoff
Build a handoff projection over msgs (the canonical, full-fidelity session messages — e.g. sidecar.messages). SPEC.md TR-9: produces a new PROJECTED continuation — banner + objective + curated keep-set, with every other turn covered by one TurnsCleared span per gap between kept turns — over the SAME sidecar (this function never touches a sidecar or disk at all; persisting HandoffResult::log/view is the caller’s job, e.g. supercode handoff’s CLI handler).
resolve_keep_indices
Resolve the full keep-set (SPEC.md TR-9 dev/01/dev/03): user-named addresses/paths (tokens) PLUS the deterministic always-keeps — the leading system prompt (if any) and the last keep_last messages — closed under tool-call/tool-result pairing so a kept call never dangles without its result (or vice versa). Pure function of msgs alone; canonical (sidecar) indices throughout.