Skip to content

Unify turns and events into ConversationView.items#144

Draft
benbaarber wants to merge 1 commit into
mainfrom
ben/items-ir
Draft

Unify turns and events into ConversationView.items#144
benbaarber wants to merge 1 commit into
mainfrom
ben/items-ir

Conversation

@benbaarber

@benbaarber benbaarber commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Extracted from #108 as its structural prerequisite — the items IR without any compaction content. #108 will restack on this branch.

  • ConversationView.turns/.events (two parallel vecs) become one ordered items: Vec<Item> (Turn | Event), preserving the source stream's exact interleaving; turns()/events() remain as iterators.
  • derive_path emits conversation.event steps for events (previously dropped — a Claude session lost its attachments and system entries on import/export), resolves duplicate step ids by content-aware renaming instead of erroring, and splices events onto the head's ancestry so they don't dangle as false dead ends. extract_conversation restores items, spliced parents, session files_changed, and synthetic-model actors.
  • Every provider's to_view builds the ordered item stream. Native compaction markers stay opaque here (a generic event, or pi's System turn) — typed boundaries are the follow-up's concern.
  • The claude projector emits events inline at their item position (real Claude interleaves attachments/system entries with turns; the trailing-pass writer regrouped them at end-of-file). wire_order_roundtrip pins the projected entry-type sequence to the captured fixture's, and the caveat entry keeps isMeta.
  • Property tests: unique derived step ids, derive → extract → derive stability, byte-identical replay dropping — over randomized interleavings with id collisions, dangling parents, and file mutations.

All 7 quality gates pass. Verified across every provider crate's full test suite.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Extracted from #108 as its structural prerequisite — the items IR
without any compaction content.

- ConversationView.turns/.events (two parallel vecs) become one ordered
  items: Vec<Item> (Turn | Event), preserving the source stream's exact
  interleaving. turns()/events() stay as iterators.
- derive_path emits conversation.event steps for events (previously
  dropped — a Claude session lost its attachments and system entries on
  import/export), resolves duplicate step ids by content-aware renaming
  instead of erroring, and splices events onto the head's ancestry so
  they don't dangle as false dead ends. extract_conversation restores
  items, spliced parents, session files_changed, and synthetic-model
  actors.
- Every provider's to_view now builds the ordered item stream. Native
  compaction markers stay opaque (a generic event, or pi's System
  turn) — typed boundaries are the follow-up's concern.
- The claude projector emits events inline at their item position;
  real Claude interleaves attachments and system entries with turns,
  and the trailing-pass writer regrouped them at the end of the file.
  wire_order_roundtrip pins the projected entry-type sequence to the
  captured fixture's, and the caveat entry keeps isMeta.
- Property tests: unique derived step ids, derive → extract → derive
  stability, and byte-identical replay dropping, over randomized
  turn/event interleavings with id collisions, dangling parents, and
  file mutations.
ben-emp pushed a commit that referenced this pull request Jul 23, 2026
…1.2.0)

Restacked onto ben/items-ir (#144) with the standalone fixes split to
#143; the pre-restack 43-commit history is preserved at
ben/compaction-pre-split.

The Compaction item + the conversation.compact step type (kind
v1.2.0): a context-compaction boundary recorded as its own step
between the turns it separates, with trigger, summary, pre_tokens, and
the anchor-based kept contract (kept_from + expand_kept; the wire
carries the expanded contiguous run). Compaction provenance is a
closed typed set — no catch-all extra; native detail richer than the
typed fields is deliberate loss.

Per-provider support, each verified against the real harness TUI by
resuming projected sessions (versions in docs/agents/tui-drift-check.md):

- claude: compact_boundary + synthetic summary → typed boundary and
  back, preservedMessages as the kept run, transcript-only + isMeta
  render flags, empty-turn thinking-block projection.
- codex: compacted marker → wholesale boundary (2026-07 payload:
  encrypted summary + prefix-keep documented as deliberate loss);
  projector emits the event_msg/context_compacted marker the TUI
  renders, with native turn_context placement.
- opencode: per-boundary summary pairing, compaction-host parent
  redirects, tailStartID → kept anchor.
- pi: compaction entries with parent-chain kept expansion;
  model_change/thinking_level_change/label as typed events with the
  chain's model context threaded into projected assistant messages.
- copilot: the observed 1.0.68 session.compaction_start/complete pair
  mapped both directions (wholesale + summary).
- gemini/cursor: documented no-boundary.

Verification: executable round-trip oracle
(testing::{check_view_invariants, assert_fixpoint}), compaction
proptests, real captured compacted sessions for claude/codex/pi/
copilot/opencode as fixtures with looped stability tests, the
cross-harness compaction matrix (kept-anchor capability flags), the
env-gated real-session matrix mode, and import-time event-type
surfacing.
@github-actions

Copy link
Copy Markdown

🔍 Preview deployed: https://4976c5f9.toolpath.pages.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant