#47 (SLICE-2, review): per-block document proposals + word-precise accept #50

Merged
benstull merged 1 commits from f12-slice2-block-proposals into main 2026-06-13 15:01:56 +00:00
Owner

SLICE-2 — #47 (review, P1) of the document-edit flow (specs/coauthoring-document-edit-flow.md §7.2, INV-39/40/41) — the sharpest pain ("too much to review").

A whole-document rewrite now proposes one F4 proposal per changed block (the unit a human reviews), but accepting a block reconciles attribution at word granularity (the unit F3 records). Block = decision unit; word = attribution unit. INV-39 supersedes INV-37's per-word cut for document edits; selection edits unchanged.

Changes

  • trackChangesModel.ts — new pure diffToBlockHunks(current, rewritten): block-key alignment (reusing diffArrays/diffBlocks keying). An isolated changed block → one block-aligned hunk → the rewritten block raw (a code/mermaid fence → one atomic whole-fence hunk, INV-23); insert/delete runs → one gap-span hunk over the inter-anchor region so reconstruction stays exact; a zero-width gap-span is anchored (INV-41). Also split diffToHunks into the raw, un-anchored wordEditHunks + the anchoring wrapper — anchoring could grow an insertion to overlap an adjacent hunk (a latent bug that only surfaces under batch application).
  • trackChangesPreview.ts — document branch uses diffToBlockHunks, tags granularity:"block".
  • model.ts / proposalModel.ts — additive optional Proposal.granularity ("block"|"single"; absent ⇒ single; no migration).
  • proposalController.ts — block accept runs an intra-block word sub-diff (wordEditHunks, disjoint) and applies one applyAgentEdit per changed run, descending offset — only Claude's actual changes land Claude-attributed; unchanged spans keep prior authorship (INV-40).

Tests

214 unit + 69/5 host E2E green. New: diffToBlockHunks unit (reconstruction, fence atomic, add/remove); f12Review E2E (M blocks→M proposals, unchanged→none, fence atomic, INV-40 attribution, INV-41 insertion accept). Updated the f11 document-path E2E to per-block (INV-39 supersedes INV-37).

Deferred decision (for review)

Undo granularity. Spec §6.2/§6.7 want a block accept to be "one undo-grouped WorkspaceEdit", but the F3 seam's pendingEdits.matchEvent matches exactly ONE registration per change event — a single multi-replace WorkspaceEdit can't carry per-run attribution. So INV-40 is implemented as sequential per-run applyAgentEdit calls (descending offset) — correct word-precise attribution, zero attribution-core risk, but a block accept is N undo steps. Single-undo-step would require extending matchEvent/onDidChange to consume multiple registrations per event (riskier) — possible follow-up.

Session 0044. Next: SLICE-3 #46 (accept-all, INV-42).

🤖 Generated with Claude Code

**SLICE-2 — #47 (review, P1)** of the document-edit flow (`specs/coauthoring-document-edit-flow.md` §7.2, INV-39/40/41) — the sharpest pain ("too much to review"). A whole-document rewrite now proposes **one F4 proposal per changed block** (the unit a human reviews), but accepting a block reconciles attribution at **word** granularity (the unit F3 records). **Block = decision unit; word = attribution unit.** INV-39 supersedes INV-37's per-word cut for document edits; selection edits unchanged. ## Changes - **`trackChangesModel.ts`** — new pure `diffToBlockHunks(current, rewritten)`: block-key alignment (reusing `diffArrays`/`diffBlocks` keying). An isolated changed block → one block-aligned hunk → the rewritten block raw (a code/mermaid fence → one atomic whole-fence hunk, INV-23); insert/delete runs → one gap-span hunk over the inter-anchor region so reconstruction stays exact; a zero-width gap-span is anchored (INV-41). Also split `diffToHunks` into the raw, un-anchored `wordEditHunks` + the anchoring wrapper — anchoring could grow an insertion to overlap an adjacent hunk (a latent bug that only surfaces under batch application). - **`trackChangesPreview.ts`** — document branch uses `diffToBlockHunks`, tags `granularity:"block"`. - **`model.ts` / `proposalModel.ts`** — additive optional `Proposal.granularity` (`"block"|"single"`; absent ⇒ single; no migration). - **`proposalController.ts`** — block accept runs an intra-block word sub-diff (`wordEditHunks`, disjoint) and applies one `applyAgentEdit` per changed run, descending offset — only Claude's actual changes land Claude-attributed; unchanged spans keep prior authorship (INV-40). ## Tests 214 unit + 69/5 host E2E green. New: `diffToBlockHunks` unit (reconstruction, fence atomic, add/remove); `f12Review` E2E (M blocks→M proposals, unchanged→none, fence atomic, INV-40 attribution, INV-41 insertion accept). Updated the f11 document-path E2E to per-block (INV-39 supersedes INV-37). ## Deferred decision (for review) **Undo granularity.** Spec §6.2/§6.7 want a block accept to be "one undo-grouped WorkspaceEdit", but the F3 seam's `pendingEdits.matchEvent` matches exactly ONE registration per change event — a single multi-replace `WorkspaceEdit` can't carry per-run attribution. So INV-40 is implemented as **sequential per-run `applyAgentEdit` calls (descending offset)** — correct word-precise attribution, zero attribution-core risk, but a block accept is N undo steps. Single-undo-step would require extending `matchEvent`/`onDidChange` to consume multiple registrations per event (riskier) — possible follow-up. Session 0044. Next: SLICE-3 #46 (accept-all, INV-42). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
benstull added 1 commit 2026-06-13 15:01:38 +00:00
Document-edit flow SLICE-2 (specs/coauthoring-document-edit-flow.md §7.2,
INV-39/40/41 — P1 "too much to review"). A whole-document rewrite now proposes
ONE F4 proposal per CHANGED BLOCK (the unit a human reviews), but accepting a
block reconciles attribution at WORD granularity (the unit F3 records). Block =
decision unit; word = attribution unit. Supersedes INV-37's per-word cut for
document edits; selection edits unchanged.

- trackChangesModel.ts: new pure diffToBlockHunks(current, rewritten) — block-key
  alignment (reusing diffArrays/diffBlocks keying): an isolated changed block →
  one block-aligned hunk → the rewritten block raw (a code/mermaid fence is one
  atomic whole-fence hunk, INV-23); insert/delete runs → one gap-span hunk over
  the inter-anchor region (separators included) so reconstruction stays exact; a
  zero-width gap-span is anchored (INV-41). Also split diffToHunks into the raw,
  un-anchored wordEditHunks + the anchoring wrapper (the anchoring could grow an
  insertion to overlap an adjacent hunk, corrupting a batch apply — a latent bug
  that only surfaced once hunks are applied as a batch).
- trackChangesPreview.ts: runEditAndPropose document branch uses diffToBlockHunks
  and tags each proposal granularity:"block".
- model.ts / proposalModel.ts: additive optional Proposal.granularity
  ("block"|"single"; absent ⇒ single, back-compat — no migration).
- proposalController.ts: accept of a block proposal runs an intra-block word
  sub-diff (wordEditHunks, disjoint) and applies one applyAgentEdit per changed
  run, descending offset — only the words Claude changed land Claude-attributed;
  unchanged spans keep prior authorship (INV-40).
- Tests: diffToBlockHunks unit (reconstruction + fence atomic + add/remove);
  f12Review host E2E (M blocks→M proposals, unchanged→none, fence atomic, INV-40
  attribution, INV-41 insertion accept); updated the f11 document-path E2E to
  per-block (INV-39 supersedes INV-37); MANUAL-SMOKE-F12 §2.

Seam note: pendingEdits.matchEvent resolves one registration per change event, so
INV-40's per-run attribution is sequential applyAgentEdit calls (N undo steps),
not one multi-replace WorkspaceEdit — see transcript Deferred decisions.

214 unit + 69/5 host E2E green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
benstull merged commit dc38b55c57 into main 2026-06-13 15:01:56 +00:00
Sign in to join this conversation.