@vibefield/rosetta-room 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +65 -3
  2. package/dist/components/Transcript.js +6 -2
  3. package/dist/components/file-viewer/FileViewerDialog.js +3 -2
  4. package/dist/components/file-viewer/diff/parse.js +7 -0
  5. package/dist/components/file-viewer/kinds.d.ts +22 -0
  6. package/dist/components/file-viewer/kinds.js +57 -0
  7. package/dist/components/file-viewer/markdown/render.d.ts +7 -1
  8. package/dist/components/file-viewer/markdown/render.js +16 -12
  9. package/dist/components/file-viewer/registry.d.ts +2 -2
  10. package/dist/components/file-viewer/registry.js +20 -59
  11. package/dist/components/file-viewer/views/DiffBody.js +7 -2
  12. package/dist/components/git/CommitViewer.js +3 -2
  13. package/dist/components/transcript/Activity.d.ts +10 -4
  14. package/dist/components/transcript/Activity.js +36 -11
  15. package/dist/components/transcript/Anchor.js +3 -2
  16. package/dist/components/transcript/Compaction.d.ts +9 -0
  17. package/dist/components/transcript/Compaction.js +10 -5
  18. package/dist/components/transcript/Document.js +150 -208
  19. package/dist/components/transcript/PromptJump.js +28 -8
  20. package/dist/components/transcript/Prose.d.ts +5 -1
  21. package/dist/components/transcript/Prose.js +7 -6
  22. package/dist/components/transcript/ReadingBlocks.d.ts +71 -0
  23. package/dist/components/transcript/ReadingBlocks.js +279 -0
  24. package/dist/components/transcript/activity-plan.d.ts +38 -7
  25. package/dist/components/transcript/activity-plan.js +198 -28
  26. package/dist/components/transcript/attachment-file-source.d.ts +1 -2
  27. package/dist/components/transcript/attachment-file-source.js +7 -5
  28. package/dist/components/transcript/disclosure-state.d.ts +2 -0
  29. package/dist/components/transcript/disclosure-state.js +6 -2
  30. package/dist/components/transcript/document-model.js +53 -9
  31. package/dist/components/transcript/document-plan.js +263 -98
  32. package/dist/components/transcript/reading-identity.d.ts +14 -1
  33. package/dist/components/transcript/reading-identity.js +126 -10
  34. package/dist/components/worktree/WorktreeColumn.js +12 -1
  35. package/dist/components/worktree/WorktreeList.d.ts +8 -2
  36. package/dist/components/worktree/WorktreeList.js +200 -5
  37. package/dist/components/worktree/worktree-ledger.d.ts +40 -0
  38. package/dist/components/worktree/worktree-ledger.js +68 -0
  39. package/dist/conversation/ConversationGallery.d.ts +11 -0
  40. package/dist/conversation/ConversationGallery.js +14 -0
  41. package/dist/conversation/ConversationMedia.d.ts +44 -0
  42. package/dist/conversation/ConversationMedia.js +210 -0
  43. package/dist/conversation/ConversationProse.d.ts +13 -0
  44. package/dist/conversation/ConversationProse.js +6 -0
  45. package/dist/conversation/ConversationRunRows.d.ts +57 -0
  46. package/dist/conversation/ConversationRunRows.js +84 -0
  47. package/dist/conversation/ConversationTurnView.d.ts +64 -0
  48. package/dist/conversation/ConversationTurnView.js +169 -0
  49. package/dist/conversation/ConversationView.d.ts +3 -0
  50. package/dist/conversation/ConversationView.js +257 -0
  51. package/dist/conversation/feed-reads.d.ts +36 -0
  52. package/dist/conversation/feed-reads.js +155 -0
  53. package/dist/conversation/feed.d.ts +106 -0
  54. package/dist/conversation/feed.js +884 -0
  55. package/dist/conversation/index.d.ts +11 -0
  56. package/dist/conversation/index.js +25 -0
  57. package/dist/conversation/model.d.ts +108 -0
  58. package/dist/conversation/model.js +257 -0
  59. package/dist/conversation/ports.d.ts +194 -0
  60. package/dist/conversation/ports.js +9 -0
  61. package/dist/conversation/rosetta-client.d.ts +8 -0
  62. package/dist/conversation/rosetta-client.js +1 -0
  63. package/dist/conversation/use-conversation-feed.d.ts +16 -0
  64. package/dist/conversation/use-conversation-feed.js +41 -0
  65. package/dist/conversation/use-conversation-window.d.ts +50 -0
  66. package/dist/conversation/use-conversation-window.js +336 -0
  67. package/dist/conversation/words.d.ts +51 -0
  68. package/dist/conversation/words.js +79 -0
  69. package/dist/fixtures/conversation.d.ts +34 -0
  70. package/dist/fixtures/conversation.js +723 -0
  71. package/dist/fixtures/index.d.ts +2 -0
  72. package/dist/fixtures/index.js +1 -0
  73. package/dist/index.d.ts +1 -1
  74. package/dist/lib/hooks.js +6 -1
  75. package/dist/lib/session-leases.d.ts +11 -8
  76. package/dist/lib/transcript/collaboration.js +53 -19
  77. package/dist/lib/transcript/head-of-document.js +9 -3
  78. package/dist/lib/transcript/index.d.ts +1 -1
  79. package/dist/lib/transcript/index.js +1 -1
  80. package/dist/lib/transcript/prompt-jump.d.ts +2 -0
  81. package/dist/lib/transcript/prompt-jump.js +5 -1
  82. package/dist/lib/transcript/sittings.d.ts +2 -1
  83. package/dist/lib/transcript/sittings.js +72 -10
  84. package/dist/lib/transcript/tail-state.d.ts +9 -0
  85. package/dist/lib/transcript/tail-state.js +25 -1
  86. package/dist/lib/transcript/turns.d.ts +5 -0
  87. package/dist/lib/transcript/turns.js +221 -57
  88. package/dist/lib/transcript/use-transcript-tail.js +17 -3
  89. package/dist/lib/transcript/vocabulary.d.ts +2 -1
  90. package/dist/lib/transcript/vocabulary.js +11 -1
  91. package/dist/parts-context.d.ts +25 -0
  92. package/dist/parts-context.js +32 -0
  93. package/dist/ports.d.ts +36 -0
  94. package/dist/room-context.d.ts +1 -2
  95. package/dist/room-context.js +11 -9
  96. package/dist/styles/conversation-turn.css +147 -0
  97. package/dist/styles/conversation.css +45 -0
  98. package/dist/styles/room.css +102 -12
  99. package/dist/styles/transcript.css +11 -2
  100. package/package.json +9 -4
@@ -1,4 +1,5 @@
1
1
  import { runSummary } from "../../lib/transcript/ledger.js";
2
+ import { drawsNoMarker } from "../../lib/transcript/turns.js";
2
3
  import { collaborationStamp } from "../../lib/transcript/collaboration.js";
3
4
  import { noticeText } from "../../lib/transcript/vocabulary.js";
4
5
  export function activityRows(item) {
@@ -14,8 +15,24 @@ export function activityRowKey(row) {
14
15
  function eventAt(row) {
15
16
  return row.body.type === "collaboration" ? collaborationStamp(row).at : row.at;
16
17
  }
18
+ /** The last cuts made over each rows array (2026-11-29, the reader's arrival
19
+ * cost): the column and its document both cut the same rows at the same
20
+ * watermark, and the second is handed the first's. */
21
+ const madeCuts = new WeakMap();
22
+ const sameEntries = (a, b) => a.length === b.length && a.every((row, index) => row === b[index]);
17
23
  /** Tool lines must already have been cut at these boundaries before coalescing. */
18
24
  export function activityCuts(rows, watermark, displayedRows = rows) {
25
+ const held = madeCuts.get(rows);
26
+ const displayed = displayedRows === rows ? null : displayedRows;
27
+ if (held !== undefined && held.watermark === watermark && sameEntries(held.rows, rows) &&
28
+ (held.displayedRows === null ? displayed === null : displayed !== null && sameEntries(held.displayedRows, displayed))) {
29
+ return held.cuts;
30
+ }
31
+ const cuts = displayed === null ? foldedCuts(rows, watermark) : cutsOf(rows, watermark, displayedRows);
32
+ madeCuts.set(rows, { watermark, rows: rows.slice(), displayedRows: displayed === null ? null : displayed.slice(), cuts });
33
+ return cuts;
34
+ }
35
+ function cutsOf(rows, watermark, displayedRows) {
19
36
  const gaps = new Map();
20
37
  const previous = new Map();
21
38
  let watermarkId = null;
@@ -27,36 +44,176 @@ export function activityCuts(rows, watermark, displayedRows = rows) {
27
44
  if (watermarkId === null && watermark !== null && row.ordinal > watermark)
28
45
  watermarkId = row.timeline_id;
29
46
  }
30
- // A delivery copy may be removed by ownership reconciliation. Keep its
31
- // paging boundary before the next surviving source event, never discard it.
32
- if (displayedRows !== rows) {
33
- const displayed = new Set(displayedRows.map(row => row.timeline_id));
34
- let next = null;
35
- // i walks rows from its last index down to 0.
36
- const rowAt = (index) => rows[index];
37
- for (let i = rows.length - 1; i >= 0; i -= 1) {
38
- const id = rowAt(i).timeline_id;
39
- if (displayed.has(id)) {
40
- next = id;
41
- continue;
47
+ // A delivery copy may be removed by ownership reconciliation, and a turn that
48
+ // finished is drawn as nothing (`drawsNoMarker`). Keep the paging boundary and
49
+ // the live line of either before the next drawn source event, never discard them.
50
+ // A gap with no drawn row after it trails the document (`activityPlan` draws it
51
+ // after the last turn); the live line waits for the next drawn row to arrive.
52
+ const displayed = displayedRows === rows ? null : new Set(displayedRows.map(row => row.timeline_id));
53
+ let next = null;
54
+ let trailingCount = 0;
55
+ let trailingRow = null;
56
+ // i walks rows from its last index down to 0.
57
+ const rowAt = (index) => rows[index];
58
+ for (let i = rows.length - 1; i >= 0; i -= 1) {
59
+ const row = rowAt(i);
60
+ const id = row.timeline_id;
61
+ if ((displayed === null || displayed.has(id)) && !drawsNoMarker(row)) {
62
+ next = id;
63
+ continue;
64
+ }
65
+ const gap = gaps.get(id);
66
+ if (gap !== undefined) {
67
+ gaps.delete(id);
68
+ if (next !== null)
69
+ gaps.set(next, (gaps.get(next) ?? 0) + gap);
70
+ else {
71
+ trailingCount += gap;
72
+ trailingRow = row;
42
73
  }
43
- const gap = gaps.get(id);
44
- if (gap !== undefined) {
45
- gaps.delete(id);
46
- if (next !== null)
47
- gaps.set(next, (gaps.get(next) ?? 0) + gap);
74
+ }
75
+ if (watermarkId === id)
76
+ watermarkId = next;
77
+ }
78
+ return {
79
+ gaps, watermarkId, trailingGap: trailingRow === null ? null : { count: trailingCount, row: trailingRow },
80
+ cutBefore: new Set([...gaps.keys(), ...(watermarkId === null ? [] : [watermarkId])]),
81
+ };
82
+ }
83
+ /** The last reading of each conversation's cuts, by its first row (2026-11-29, the reader's arrival cost). */
84
+ const cutFolds = new WeakMap();
85
+ /**
86
+ * `cutsOf` with every row drawn but a finished end, resumed. A gap and the
87
+ * live line are carried only forward, to the next drawn row, so the cuts on
88
+ * the rows up to the last one drawn are the same when rows arrive after them.
89
+ * Rows that extend the rows read before, under the same watermark, resume the
90
+ * forward pass where it ended and run the backward pass down to that last
91
+ * drawn row: one arriving row reads itself and the finished ends just before
92
+ * it, not the document (2026-11-29, the reader's arrival cost).
93
+ */
94
+ function foldedCuts(rows, watermark) {
95
+ const head = rows[0];
96
+ const held = head === undefined ? undefined : cutFolds.get(head);
97
+ const resumes = held !== undefined && held.watermark === watermark && held.rows.length <= rows.length &&
98
+ held.rows.every((row, index) => row === rows[index]);
99
+ const previous = new Map(resumes ? held.previous : []);
100
+ const missing = new Map(resumes ? held.missing : []);
101
+ let watermarkRow = resumes ? held.watermarkRow : null;
102
+ for (let index = resumes ? held.rows.length : 0; index < rows.length; index += 1) {
103
+ const row = rows[index];
104
+ const ordinal = previous.get(row.session_id);
105
+ if (ordinal !== undefined && row.ordinal > ordinal + 1)
106
+ missing.set(row.timeline_id, row.ordinal - ordinal - 1);
107
+ previous.set(row.session_id, row.ordinal);
108
+ if (watermarkRow === null && watermark !== null && row.ordinal > watermark)
109
+ watermarkRow = { id: row.timeline_id, index };
110
+ }
111
+ // The rows whose cuts are not yet known: those after the last row drawn before.
112
+ const from = resumes ? held.lastDrawn + 1 : 0;
113
+ const gaps = new Map(resumes ? held.gaps : []);
114
+ let watermarkId = resumes ? held.watermarkId : null;
115
+ const watermarkAhead = watermarkRow !== null && watermarkRow.index >= from ? watermarkRow.id : null;
116
+ const carried = new Map();
117
+ let next = null;
118
+ let trailingCount = 0;
119
+ let trailingRow = null;
120
+ let lastDrawn = from - 1;
121
+ // index walks rows from its last index down to `from`.
122
+ for (let index = rows.length - 1; index >= from; index -= 1) {
123
+ const row = rows[index];
124
+ const id = row.timeline_id;
125
+ const gap = missing.get(id);
126
+ if (!drawsNoMarker(row)) {
127
+ if (next === null)
128
+ lastDrawn = index;
129
+ if (gap !== undefined)
130
+ carried.set(id, (carried.get(id) ?? 0) + gap);
131
+ next = id;
132
+ if (watermarkAhead === id)
133
+ watermarkId = id;
134
+ continue;
135
+ }
136
+ if (gap !== undefined) {
137
+ if (next !== null)
138
+ carried.set(next, (carried.get(next) ?? 0) + gap);
139
+ else {
140
+ trailingCount += gap;
141
+ trailingRow = row;
48
142
  }
49
- if (watermarkId === id)
50
- watermarkId = next;
51
143
  }
144
+ if (watermarkAhead === id)
145
+ watermarkId = next;
146
+ }
147
+ for (const [id, gap] of [...carried].reverse())
148
+ gaps.set(id, gap);
149
+ if (head !== undefined) {
150
+ cutFolds.set(head, {
151
+ rows: rows.slice(), watermark, previous, missing, watermarkRow, lastDrawn, gaps,
152
+ watermarkId: watermarkRow !== null && watermarkRow.index <= lastDrawn ? watermarkId : null,
153
+ });
52
154
  }
53
- return { gaps, watermarkId, cutBefore: new Set([...gaps.keys(), ...(watermarkId === null ? [] : [watermarkId])]) };
155
+ return {
156
+ gaps: new Map(gaps), watermarkId,
157
+ trailingGap: trailingRow === null ? null : { count: trailingCount, row: trailingRow },
158
+ cutBefore: new Set([...gaps.keys(), ...(watermarkId === null ? [] : [watermarkId])]),
159
+ };
160
+ }
161
+ export function activityPlanMemo() {
162
+ return { plan: [], options: null, made: [], headed: new Set(), bounded: new Set(), headedBy: [], boundedBy: [],
163
+ firstBefore: [], firstAfter: true };
164
+ }
165
+ function sameGaps(a, b) {
166
+ if (a === b)
167
+ return true;
168
+ if (a.size !== b.size)
169
+ return false;
170
+ for (const [key, value] of a)
171
+ if (b.get(key) !== value)
172
+ return false;
173
+ return true;
174
+ }
175
+ function sameTrailing(a, b) {
176
+ return a === b || (a !== null && b !== null && a.count === b.count && a.row === b.row);
54
177
  }
55
- export function activityPlan(plan, options) {
56
- const headed = new Set();
57
- let firstContent = true;
58
- const bounded = new Set();
59
- return plan.map(({ sitting, parts }) => {
178
+ export function activityPlan(plan, options, memo = activityPlanMemo()) {
179
+ // The sittings handed back: the same planned sitting at the same place, under the same options, and not the last
180
+ // sitting of either plan while a stretch is missing at the end (it is drawn after the last one).
181
+ const before = memo.options;
182
+ const comparable = before !== null && before.watermarkId === options.watermarkId &&
183
+ before.partial === options.partial && sameGaps(before.gaps, options.gaps);
184
+ const trailingBefore = before?.trailingGap ?? null;
185
+ // A stretch missing at the end, now or last time, is drawn in the last sitting: that sitting is made again
186
+ // unless the stretch and the number of sittings are both as they were.
187
+ const trailingMoves = (trailingBefore !== null || options.trailingGap !== null) &&
188
+ (!sameTrailing(trailingBefore, options.trailingGap) || plan.length !== memo.plan.length);
189
+ const drawsTrailing = (index) => index === plan.length - 1 || index === memo.plan.length - 1;
190
+ let kept = 0;
191
+ if (comparable) {
192
+ while (kept < plan.length && kept < memo.plan.length && plan[kept] === memo.plan[kept] &&
193
+ !(trailingMoves && drawsTrailing(kept)))
194
+ kept += 1;
195
+ }
196
+ // What the sittings past the kept ones added is taken back, so the carried sets hold the kept sittings' alone.
197
+ const headed = kept === 0 ? new Set() : memo.headed;
198
+ const bounded = kept === 0 ? new Set() : memo.bounded;
199
+ if (kept > 0) {
200
+ for (let index = kept; index < memo.headedBy.length; index += 1) {
201
+ for (const key of memo.headedBy[index])
202
+ headed.delete(key);
203
+ for (const key of memo.boundedBy[index])
204
+ bounded.delete(key);
205
+ }
206
+ }
207
+ let firstContent = kept === 0 ? true : (memo.firstBefore[kept] ?? memo.firstAfter);
208
+ const made = memo.made.slice(0, kept);
209
+ const headedBy = memo.headedBy.slice(0, kept);
210
+ const boundedBy = memo.boundedBy.slice(0, kept);
211
+ const firstBefore = memo.firstBefore.slice(0, kept);
212
+ for (let index = kept; index < plan.length; index += 1) {
213
+ const { sitting, parts } = plan[index];
214
+ const headedHere = [];
215
+ const boundedHere = [];
216
+ firstBefore.push(firstContent);
60
217
  const blocks = [];
61
218
  let items = [];
62
219
  let partial = false;
@@ -73,6 +230,7 @@ export function activityPlan(plan, options) {
73
230
  if (bounded.has(row.timeline_id))
74
231
  continue;
75
232
  bounded.add(row.timeline_id);
233
+ boundedHere.push(row.timeline_id);
76
234
  const gap = options.gaps.get(row.timeline_id);
77
235
  if (gap !== undefined) {
78
236
  flush();
@@ -140,7 +298,10 @@ export function activityPlan(plan, options) {
140
298
  flush();
141
299
  blocks.push({ kind: "reply", key: segment.key, segment,
142
300
  head: headed.has(part.turn.key) ? null : part.turn.head, at: segment.at });
143
- headed.add(part.turn.key);
301
+ if (!headed.has(part.turn.key)) {
302
+ headed.add(part.turn.key);
303
+ headedHere.push(part.turn.key);
304
+ }
144
305
  firstContent = false;
145
306
  }
146
307
  else if (segment.kind === "ledger") {
@@ -153,8 +314,17 @@ export function activityPlan(plan, options) {
153
314
  }
154
315
  }
155
316
  flush();
156
- return { sitting, blocks };
157
- });
317
+ // A stretch missing after the last drawn row is still said, once, at the end.
318
+ const trailing = options.trailingGap;
319
+ if (trailing !== null && index === plan.length - 1) {
320
+ blocks.push({ kind: "gap", key: `gap:${activityRowKey(trailing.row)}`, count: trailing.count, at: eventAt(trailing.row) });
321
+ }
322
+ made.push({ sitting, blocks });
323
+ headedBy.push(headedHere);
324
+ boundedBy.push(boundedHere);
325
+ }
326
+ Object.assign(memo, { plan, options, made, headed, bounded, headedBy, boundedBy, firstBefore, firstAfter: firstContent });
327
+ return made.slice();
158
328
  }
159
329
  export function summarizeActivity(items) {
160
330
  const lines = items.flatMap(item => item.kind === "tool" ? [item.line] : []);
@@ -1,8 +1,7 @@
1
1
  import type { AssetRef } from "@vibefield/rosetta-protocol";
2
2
  import type { AttachmentFact } from "../../lib/transcript/index.js";
3
3
  import type { AssetSource, AssetUrl } from "../../ports.js";
4
- import type { FileHandle, FileSource } from "../file-viewer/index.js";
5
- import type { ImageResource } from "../file-viewer/types.js";
4
+ import type { FileHandle, FileSource, ImageResource } from "../file-viewer/types.js";
6
5
  /** Reads one stored member's bytes. */
7
6
  export type AssetReader = (asset: AssetRef, signal: AbortSignal) => Promise<Uint8Array>;
8
7
  export interface AttachmentReader {
@@ -5,10 +5,12 @@
5
5
  // + `FileSource` pair the worktree supplies, so thumbnails and inline image
6
6
  // markers open the established image view instead of navigating the page.
7
7
  // Addresses come from the host's asset source; bytes ride the reading
8
- // session's client.
8
+ // session's client. Both are read from the parts' own context, which the room
9
+ // provides and a view with no room around it provides alone.
9
10
  import { useMemo } from "react";
10
- import { useReadingSession, useRoom } from "../../room-context.js";
11
- import { resolveKind } from "../file-viewer/index.js";
11
+ import { useParts, useReadingSession } from "../../parts-context.js";
12
+ // The kind table alone: the viewer's index would load every view with it.
13
+ import { kindOfName } from "../file-viewer/kinds.js";
12
14
  import { isRecordedImageAsset, isRecordedVideoAsset } from "../../lib/image-media.js";
13
15
  const EXTENSION_BY_MEDIA_TYPE = new Map([
14
16
  ["image/png", "png"],
@@ -27,7 +29,7 @@ export function attachmentViewerName(fact) {
27
29
  const base = fact.name?.trim() ||
28
30
  fact.ref?.label?.trim() ||
29
31
  "Image";
30
- const kind = resolveKind(base).viewer.id;
32
+ const kind = kindOfName(base).viewer;
31
33
  if (kind === "image" || kind === "svg")
32
34
  return base;
33
35
  const mediaType = fact.mediaType ?? (source?.type === "asset" ? source.asset.media_type : null);
@@ -101,7 +103,7 @@ export function createAttachmentReader(assets, readAsset) {
101
103
  /** The attachment reader for the document being read here: the host's
102
104
  * addresses, and bytes through the reading session's client. */
103
105
  export function useAttachmentReader() {
104
- const { assets, sessions } = useRoom();
106
+ const { assets, sessions } = useParts();
105
107
  const sessionId = useReadingSession();
106
108
  return useMemo(() => createAttachmentReader(assets, (asset, signal) => {
107
109
  if (sessionId === null)
@@ -3,4 +3,6 @@ export declare function DisclosureState({ children }: {
3
3
  readonly children: ReactNode;
4
4
  }): import("react").JSX.Element;
5
5
  export declare function useRowDisclosure(key: string, initial?: boolean): [boolean, (value: boolean | ((open: boolean) => boolean)) => void];
6
+ /** A run's own override. It subscribes to that run's answer, not to the
7
+ * store's version, so one run's press re-renders that run alone. */
6
8
  export declare function useGroupDisclosure(keys: readonly string[], revision: number): [boolean | undefined, (open: boolean) => void];
@@ -25,8 +25,12 @@ export function useRowDisclosure(key, initial = false) {
25
25
  }, [store, key, fallback]);
26
26
  return [open, setOpen];
27
27
  }
28
+ /** A run's own override. It subscribes to that run's answer, not to the
29
+ * store's version, so one run's press re-renders that run alone. */
28
30
  export function useGroupDisclosure(keys, revision) {
29
31
  const store = useContext(DisclosureContext);
30
- useSyncExternalStore(store?.subscribe ?? subscribeNothing, store?.version ?? (() => 0), () => 0);
31
- return [store?.group(keys, revision), (open) => store?.setGroup(keys, open, revision)];
32
+ const read = useCallback(() => store?.group(keys, revision), [store, keys, revision]);
33
+ const open = useSyncExternalStore(store?.subscribe ?? subscribeNothing, read, read);
34
+ const setOpen = useCallback((value) => store?.setGroup(keys, value, revision), [store, keys, revision]);
35
+ return [open, setOpen];
32
36
  }
@@ -15,6 +15,7 @@
15
15
  // silently closed over.
16
16
  import { useMemo } from "react";
17
17
  import { calendarDayKey, dayList, documentTurns, sittings } from "../../lib/transcript/index.js";
18
+ import { drawsNoMarker } from "../../lib/transcript/turns.js";
18
19
  import { documentPlan } from "./document-plan.js";
19
20
  function buildRepresentatives(turns) {
20
21
  const map = new Map();
@@ -52,23 +53,42 @@ function buildRepresentatives(turns) {
52
53
  }
53
54
  return map;
54
55
  }
55
- function buildGaps(rows) {
56
- const gaps = new Map();
57
- const previousBySession = new Map();
58
- for (const row of rows) {
56
+ /** The last read of each conversation's rows, by its first row (2026-11-29, the reader's arrival cost). */
57
+ const rowsRead = new WeakMap();
58
+ /** The rows drawn and the gaps. Both are read in order and carry nothing back,
59
+ * so rows that extend the rows read last read only the rows that arrived. */
60
+ function readRows(rows) {
61
+ const head = rows[0];
62
+ const held = head === undefined ? undefined : rowsRead.get(head);
63
+ const resumes = held !== undefined && held.rows.length <= rows.length &&
64
+ held.rows.every((row, index) => row === rows[index]);
65
+ const drawn = resumes ? held.drawn.slice() : [];
66
+ const gaps = new Map(resumes ? held.gaps : []);
67
+ const previousBySession = new Map(resumes ? held.previous : []);
68
+ for (let index = resumes ? held.rows.length : 0; index < rows.length; index += 1) {
69
+ const row = rows[index];
70
+ if (!drawsNoMarker(row))
71
+ drawn.push(row);
59
72
  const previous = previousBySession.get(row.session_id);
60
73
  const missing = previous === undefined ? 0 : row.ordinal - previous - 1;
61
74
  if (missing > 0)
62
75
  gaps.set(row.timeline_id, missing);
63
76
  previousBySession.set(row.session_id, row.ordinal);
64
77
  }
65
- return gaps;
78
+ const read = { rows: rows.slice(), drawn, gaps, previous: previousBySession };
79
+ if (head !== undefined)
80
+ rowsRead.set(head, read);
81
+ return read;
66
82
  }
67
83
  export function transcriptModel(rows, session, homeDirectory, now, options = {}) {
68
84
  // Sittings first: a run never straddles a pill, so the turns are cut at
69
- // every sitting's first row (`cutBefore`) before they are folded.
70
- const list = sittings(rows, now);
71
- const gaps = buildGaps(rows);
85
+ // every sitting's first row (`cutBefore`) before they are folded. They are
86
+ // cut over the rows the reader draws: a turn that finished draws nothing,
87
+ // so it opens no sitting, is counted in none and is no day's target, and a
88
+ // pause is measured from the last row drawn before it.
89
+ const read = readRows(rows);
90
+ const list = sittings(read.drawn, now);
91
+ const gaps = new Map(read.gaps);
72
92
  const cutBefore = new Set([...(options.cutBefore ?? gaps.keys()), ...list
73
93
  .slice(1)
74
94
  .map((sitting) => sitting.rows[0]?.timeline_id)
@@ -83,10 +103,34 @@ export function transcriptModel(rows, session, homeDirectory, now, options = {})
83
103
  sittings: list,
84
104
  days: dayList(list),
85
105
  plan: documentPlan(turns, list),
86
- representatives: buildRepresentatives(turns),
106
+ representatives: new DrawnBy(() => buildRepresentatives(turns)),
87
107
  gaps,
88
108
  };
89
109
  }
110
+ /** The representative map, built the first time it is read (2026-11-29, the
111
+ * reader's arrival cost). Only a landing reads it (a search hit, a meta link, a
112
+ * team message), so an arriving row derives no map over every row of the
113
+ * document; the first landing pays for it once per document. */
114
+ class DrawnBy {
115
+ #built = null;
116
+ #build;
117
+ constructor(build) {
118
+ this.#build = build;
119
+ }
120
+ get #map() {
121
+ return (this.#built ??= this.#build());
122
+ }
123
+ get size() { return this.#map.size; }
124
+ get(key) { return this.#map.get(key); }
125
+ has(key) { return this.#map.has(key); }
126
+ forEach(each, self) {
127
+ this.#map.forEach((value, key) => each.call(self, value, key, this));
128
+ }
129
+ entries() { return this.#map.entries(); }
130
+ keys() { return this.#map.keys(); }
131
+ values() { return this.#map.values(); }
132
+ [Symbol.iterator]() { return this.#map[Symbol.iterator](); }
133
+ }
90
134
  export function useTranscriptModel(rows, session, homeDirectory, now, options = {}) {
91
135
  const cwd = session?.cwd ?? null;
92
136
  const sharedKey = [...(options.sharedCollaborationSessionIds ?? [])].sort().join("\u0000");