@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
@@ -28,29 +28,17 @@ function turnSitting(turn, indexOf) {
28
28
  const first = turn.segments[0];
29
29
  return first === undefined ? 0 : indexOf(segmentRows(first)[0]);
30
30
  }
31
- /** Adjacent setting turns that share one compact configuration group. */
32
- function clusterGroups(turns, sittingOf) {
33
- const groups = [];
34
- for (const turn of turns) {
35
- const current = groups.at(-1);
36
- const previous = current?.at(-1);
37
- const joins = current !== undefined &&
38
- previous !== undefined &&
39
- turn.clusteredWithPrevious &&
40
- turn.prompt !== null &&
41
- previous.prompt !== null &&
42
- turn.prompt.setting !== null &&
43
- previous.prompt.setting !== null &&
44
- !turn.prompt.fromParent &&
45
- !previous.prompt.fromParent &&
46
- previous.segments.length === 0 &&
47
- sittingOf(previous) === sittingOf(turn);
48
- if (joins)
49
- current.push(turn);
50
- else
51
- groups.push([turn]);
52
- }
53
- return groups;
31
+ /** Whether a setting turn joins the compact configuration group the turn before it ends. */
32
+ function joinsGroup(previous, turn, sittingOf) {
33
+ return turn.clusteredWithPrevious &&
34
+ turn.prompt !== null &&
35
+ previous.prompt !== null &&
36
+ turn.prompt.setting !== null &&
37
+ previous.prompt.setting !== null &&
38
+ !turn.prompt.fromParent &&
39
+ !previous.prompt.fromParent &&
40
+ previous.segments.length === 0 &&
41
+ sittingOf(previous) === sittingOf(turn);
54
42
  }
55
43
  /**
56
44
  * Fold turns and sittings into the sections the column draws. Sittings that
@@ -58,82 +46,12 @@ function clusterGroups(turns, sittingOf) {
58
46
  * be a cut with nothing on the far side of it.
59
47
  */
60
48
  export function documentPlan(turns, sittings) {
61
- const indexByRow = new Map();
62
- sittings.forEach((sitting, index) => {
63
- for (const row of sitting.rows)
64
- indexByRow.set(row.timeline_id, index);
65
- });
66
- const indexOf = (row) => indexByRow.get(row.timeline_id) ?? 0;
49
+ const { byRow, unique } = sittingIndexByRow(sittings);
50
+ const indexOf = (row) => byRow.get(row.timeline_id) ?? 0;
67
51
  const sittingOf = (turn) => turnSitting(turn, indexOf);
68
52
  const parts = [];
69
- for (const group of clusterGroups(turns, sittingOf)) {
70
- // Only the last turn of a cluster can carry an answer, by construction.
71
- const turn = group[group.length - 1];
72
- const prompts = group
73
- .map((member) => member.prompt)
74
- .filter((prompt) => prompt !== null);
75
- const openIndex = prompts[0] === undefined ? null : indexOf(prompts[0].row);
76
- // Cut the segments wherever the sitting changes under them.
77
- const slices = [];
78
- turn.segments.forEach((segment, at) => {
79
- const index = indexOf(segmentRows(segment)[0]);
80
- const last = slices.at(-1);
81
- if (last !== undefined && last.index === index)
82
- last.segments.push(segment);
83
- else
84
- slices.push({ index, segments: [segment], from: at });
85
- });
86
- const headSlice = turn.head === null ? -1 : slices.findIndex((slice) => turn.headIndex >= slice.from && turn.headIndex < slice.from + slice.segments.length);
87
- // A head with no segments to sit above still belongs to the reply that
88
- // reported it; it rides with the prompt rather than disappearing.
89
- const headOnOpener = turn.head !== null && headSlice === -1;
90
- if (slices.length === 0) {
91
- parts.push({
92
- key: turn.key,
93
- sittingIndex: openIndex ?? 0,
94
- turn,
95
- prompts,
96
- before: [],
97
- after: [],
98
- showHead: turn.head !== null,
99
- firstRowId: firstRowIdOf(prompts, []),
100
- at: firstStampOf(prompts, []),
101
- });
102
- continue;
103
- }
104
- slices.forEach((slice, at) => {
105
- const opensWithPrompt = at === 0 && openIndex !== null && openIndex === slice.index;
106
- const slicePrompts = at === 0 && (opensWithPrompt || openIndex === null) ? prompts : [];
107
- const cut = Math.max(0, Math.min(turn.headIndex - slice.from, slice.segments.length));
108
- const showHead = at === headSlice || (headOnOpener && at === 0);
109
- parts.push({
110
- key: `${turn.key}:${at}`,
111
- sittingIndex: slice.index,
112
- turn,
113
- prompts: slicePrompts,
114
- before: slice.segments.slice(0, cut),
115
- after: slice.segments.slice(cut),
116
- showHead,
117
- firstRowId: firstRowIdOf(slicePrompts, slice.segments),
118
- at: firstStampOf(slicePrompts, slice.segments),
119
- });
120
- });
121
- // The prompt fell in an earlier sitting than every segment: it needs its
122
- // own part so its pill and its panel are not filed under the reply's day.
123
- if (openIndex !== null && slices[0].index !== openIndex) {
124
- parts.splice(parts.length - slices.length, 0, {
125
- key: `${turn.key}:opener`,
126
- sittingIndex: openIndex,
127
- turn,
128
- prompts,
129
- before: [],
130
- after: [],
131
- showHead: false,
132
- firstRowId: firstRowIdOf(prompts, []),
133
- at: firstStampOf(prompts, []),
134
- });
135
- }
136
- }
53
+ for (const made of groupedParts(turns, sittings, unique, sittingOf, indexOf))
54
+ parts.push(...made);
137
55
  const planned = sittings.map((sitting) => ({ sitting, parts: [] }));
138
56
  for (const part of parts) {
139
57
  const target = planned[part.sittingIndex] ?? planned[0];
@@ -141,5 +59,252 @@ export function documentPlan(turns, sittings) {
141
59
  continue;
142
60
  target.parts.push(part);
143
61
  }
144
- return planned.filter((entry) => entry.parts.length > 0);
62
+ return planned.filter((entry) => entry.parts.length > 0).map(keptPlan);
63
+ }
64
+ /** The last maps of each conversation, by its first sitting's first row (2026-11-29, the reader's arrival cost). */
65
+ const sittingIndexes = new WeakMap();
66
+ /**
67
+ * Each row's sitting, by `timeline_id`; a row in two sittings is the later
68
+ * one's. Sittings that begin as the last map's sittings did, as the same
69
+ * objects at the same places, keep their rows' entries, so one arriving row
70
+ * maps the sittings it changed and not every row of the document (2026-11-29,
71
+ * the reader's arrival cost). Only a map whose ids were each in one sitting is
72
+ * carried on; any other is made again.
73
+ */
74
+ function sittingIndexByRow(sittings) {
75
+ const head = sittings[0]?.rows[0];
76
+ const known = head === undefined ? [] : (sittingIndexes.get(head) ?? []);
77
+ let held;
78
+ let kept = 0;
79
+ for (const index of known) {
80
+ if (!index.unique)
81
+ continue;
82
+ let same = 0;
83
+ while (same < sittings.length && same < index.sittings.length && sittings[same] === index.sittings[same])
84
+ same += 1;
85
+ if (same > kept) {
86
+ held = index;
87
+ kept = same;
88
+ }
89
+ }
90
+ let byRow;
91
+ let unique = true;
92
+ if (held !== undefined) {
93
+ byRow = held.byRow;
94
+ for (let index = kept; index < held.sittings.length; index += 1) {
95
+ for (const row of held.sittings[index].rows)
96
+ byRow.delete(row.timeline_id);
97
+ }
98
+ for (let index = kept; index < sittings.length && unique; index += 1) {
99
+ for (const row of sittings[index].rows) {
100
+ if (byRow.has(row.timeline_id)) {
101
+ unique = false;
102
+ break;
103
+ }
104
+ byRow.set(row.timeline_id, index);
105
+ }
106
+ }
107
+ }
108
+ if (held === undefined || !unique) {
109
+ byRow = new Map();
110
+ let rows = 0;
111
+ sittings.forEach((sitting, index) => {
112
+ rows += sitting.rows.length;
113
+ for (const row of sitting.rows)
114
+ byRow.set(row.timeline_id, index);
115
+ });
116
+ unique = byRow.size === rows;
117
+ }
118
+ if (head !== undefined) {
119
+ const made = { sittings: sittings.slice(), byRow: byRow, unique };
120
+ // Two per conversation: its column and its document may plan two chronologies that begin with the same row.
121
+ sittingIndexes.set(head, [made, ...known.filter((index) => index !== held).slice(0, 1)]);
122
+ }
123
+ return { byRow: byRow, unique };
124
+ }
125
+ /** The last groupings of each conversation, by its first turn (2026-11-29, the reader's arrival cost). */
126
+ const groupFolds = new WeakMap();
127
+ function leading(a, b) {
128
+ let at = 0;
129
+ while (at < a.length && at < b.length && a[at] === b[at])
130
+ at += 1;
131
+ return at;
132
+ }
133
+ /**
134
+ * The turns grouped, and each group's parts. A group of the last grouping is
135
+ * kept as it was when its turns are the same objects at the same places and
136
+ * every sitting it is placed by is the same object at the same place, in a
137
+ * document where each row is in one sitting: its parts are then what they
138
+ * were. The turns after the kept groups are grouped again, the first of them
139
+ * against the last kept group, so one arriving row groups the turn it joins
140
+ * and not every turn of the document (2026-11-29, the reader's arrival cost).
141
+ */
142
+ function groupedParts(turns, sittings, unique, sittingOf, indexOf) {
143
+ const head = turns[0];
144
+ const known = head === undefined ? [] : (groupFolds.get(head) ?? []);
145
+ let held;
146
+ let keep = 0;
147
+ if (unique) {
148
+ for (const fold of known) {
149
+ const sameTurns = leading(turns, fold.turns);
150
+ const sameSittings = leading(sittings, fold.sittings);
151
+ let count = 0;
152
+ while (count < fold.groups.length && fold.starts[count] + fold.groups[count].length <= sameTurns &&
153
+ fold.reach[count] < sameSittings)
154
+ count += 1;
155
+ if (count > keep) {
156
+ held = fold;
157
+ keep = count;
158
+ }
159
+ }
160
+ }
161
+ const groups = held === undefined ? [] : held.groups.slice(0, keep);
162
+ const starts = held === undefined ? [] : held.starts.slice(0, keep);
163
+ const parts = held === undefined ? [] : held.parts.slice(0, keep);
164
+ const reach = held === undefined ? [] : held.reach.slice(0, keep);
165
+ // Groups from `made` on are this call's own arrays, and their parts are made below.
166
+ let made = keep;
167
+ const from = keep === 0 ? 0 : starts[keep - 1] + groups[keep - 1].length;
168
+ for (let index = from; index < turns.length; index += 1) {
169
+ const turn = turns[index];
170
+ const last = groups.length - 1;
171
+ const current = groups[last];
172
+ const previous = current?.at(-1);
173
+ if (current !== undefined && previous !== undefined && joinsGroup(previous, turn, sittingOf)) {
174
+ if (last < made) {
175
+ groups[last] = [...current, turn];
176
+ made = last;
177
+ }
178
+ else
179
+ current.push(turn);
180
+ }
181
+ else {
182
+ groups.push([turn]);
183
+ starts.push(index);
184
+ }
185
+ }
186
+ parts.length = made;
187
+ reach.length = made;
188
+ for (let at = made; at < groups.length; at += 1) {
189
+ const kept = keptGroupParts(groups[at], indexOf);
190
+ parts.push(kept.parts);
191
+ reach.push(kept.reach);
192
+ }
193
+ if (head !== undefined) {
194
+ const fold = { turns: turns.slice(), sittings: sittings.slice(), groups, starts, parts, reach };
195
+ // Two per conversation: its column and its document may plan two chronologies that begin with the same turn.
196
+ groupFolds.set(head, [fold, ...known.filter((other) => other !== held).slice(0, 1)]);
197
+ }
198
+ return parts;
199
+ }
200
+ /** The parts one cluster of turns draws, kept by its last turn (2026-11-29, the
201
+ * reader's arrival cost): the same turns, opening and cut in the same sittings,
202
+ * give back the parts made before, as the same objects. */
203
+ const madeGroupParts = new WeakMap();
204
+ function keptGroupParts(group, indexOf) {
205
+ const turn = group[group.length - 1];
206
+ // Every sitting the parts are placed by: each prompt's, and each segment's first row's.
207
+ const indices = [];
208
+ for (const member of group)
209
+ if (member.prompt !== null)
210
+ indices.push(indexOf(member.prompt.row));
211
+ for (const segment of turn.segments)
212
+ indices.push(indexOf(segmentRows(segment)[0]));
213
+ const reach = indices.reduce((highest, index) => Math.max(highest, index), 0);
214
+ const held = madeGroupParts.get(turn);
215
+ if (held !== undefined && sameItems(held.group, group) && sameItems(held.indices, indices))
216
+ return { parts: held.parts, reach };
217
+ const parts = groupParts(group, indexOf);
218
+ madeGroupParts.set(turn, { group: [...group], indices, parts });
219
+ return { parts, reach };
220
+ }
221
+ function groupParts(group, indexOf) {
222
+ const out = [];
223
+ // Only the last turn of a cluster can carry an answer, by construction.
224
+ const turn = group[group.length - 1];
225
+ const prompts = group
226
+ .map((member) => member.prompt)
227
+ .filter((prompt) => prompt !== null);
228
+ const openIndex = prompts[0] === undefined ? null : indexOf(prompts[0].row);
229
+ // Cut the segments wherever the sitting changes under them.
230
+ const slices = [];
231
+ turn.segments.forEach((segment, at) => {
232
+ const index = indexOf(segmentRows(segment)[0]);
233
+ const last = slices.at(-1);
234
+ if (last !== undefined && last.index === index)
235
+ last.segments.push(segment);
236
+ else
237
+ slices.push({ index, segments: [segment], from: at });
238
+ });
239
+ const headSlice = turn.head === null ? -1 : slices.findIndex((slice) => turn.headIndex >= slice.from && turn.headIndex < slice.from + slice.segments.length);
240
+ // A head with no segments to sit above still belongs to the reply that
241
+ // reported it; it rides with the prompt rather than disappearing.
242
+ const headOnOpener = turn.head !== null && headSlice === -1;
243
+ if (slices.length === 0) {
244
+ out.push({
245
+ key: turn.key,
246
+ sittingIndex: openIndex ?? 0,
247
+ turn,
248
+ prompts,
249
+ before: [],
250
+ after: [],
251
+ showHead: turn.head !== null,
252
+ firstRowId: firstRowIdOf(prompts, []),
253
+ at: firstStampOf(prompts, []),
254
+ });
255
+ return out;
256
+ }
257
+ slices.forEach((slice, at) => {
258
+ const opensWithPrompt = at === 0 && openIndex !== null && openIndex === slice.index;
259
+ const slicePrompts = at === 0 && (opensWithPrompt || openIndex === null) ? prompts : [];
260
+ const cut = Math.max(0, Math.min(turn.headIndex - slice.from, slice.segments.length));
261
+ const showHead = at === headSlice || (headOnOpener && at === 0);
262
+ out.push({
263
+ key: `${turn.key}:${at}`,
264
+ sittingIndex: slice.index,
265
+ turn,
266
+ prompts: slicePrompts,
267
+ before: slice.segments.slice(0, cut),
268
+ after: slice.segments.slice(cut),
269
+ showHead,
270
+ firstRowId: firstRowIdOf(slicePrompts, slice.segments),
271
+ at: firstStampOf(slicePrompts, slice.segments),
272
+ });
273
+ });
274
+ // The prompt fell in an earlier sitting than every segment: it needs its
275
+ // own part so its pill and its panel are not filed under the reply's day.
276
+ if (openIndex !== null && slices[0].index !== openIndex) {
277
+ out.splice(out.length - slices.length, 0, {
278
+ key: `${turn.key}:opener`,
279
+ sittingIndex: openIndex,
280
+ turn,
281
+ prompts,
282
+ before: [],
283
+ after: [],
284
+ showHead: false,
285
+ firstRowId: firstRowIdOf(prompts, []),
286
+ at: firstStampOf(prompts, []),
287
+ });
288
+ }
289
+ return out;
290
+ }
291
+ /** Planned sittings kept by their sitting (2026-11-29, the reader's arrival cost): the same sitting holding parts
292
+ * equal field by field (the same turns, prompts and segments) is handed back as the same object, so the reading
293
+ * blocks drawn from it are not made again. */
294
+ const madePlans = new WeakMap();
295
+ function keptPlan(entry) {
296
+ const held = madePlans.get(entry.sitting);
297
+ if (held !== undefined && held.parts.length === entry.parts.length &&
298
+ held.parts.every((part, index) => samePart(part, entry.parts[index])))
299
+ return held;
300
+ madePlans.set(entry.sitting, entry);
301
+ return entry;
302
+ }
303
+ function samePart(a, b) {
304
+ return a === b || a.key === b.key && a.sittingIndex === b.sittingIndex && a.turn === b.turn && a.showHead === b.showHead &&
305
+ a.firstRowId === b.firstRowId && a.at === b.at && sameItems(a.prompts, b.prompts) &&
306
+ sameItems(a.before, b.before) && sameItems(a.after, b.after);
307
+ }
308
+ function sameItems(a, b) {
309
+ return a.length === b.length && a.every((item, index) => item === b[index]);
145
310
  }
@@ -1,2 +1,15 @@
1
- import type { ReadingSitting } from "./activity-plan.js";
1
+ import type { TimelineEntry } from "@vibefield/rosetta-protocol";
2
+ import type { ReadingBlock, ReadingSitting } from "./activity-plan.js";
3
+ /** Every row a reading block draws, in order. */
4
+ export declare function readingBlockRows(block: ReadingBlock): readonly TimelineEntry[];
5
+ /** Structural equality over the document's plain data: arrays, maps and sets
6
+ * in order, own keys of plain objects (whose prototype is `Object.prototype`
7
+ * or null), and identity for everything else: two dates, two patterns or two
8
+ * instances of a class are equal only when they are one object. A row that is
9
+ * the same object is equal without being read. */
10
+ export declare function sameValue(a: unknown, b: unknown, depth?: number): boolean;
11
+ /** Keys survive as before; beyond that, a block whose rows did not change is
12
+ * handed back as the PREVIOUS object, and a sitting whose blocks all came back
13
+ * is the previous sitting. A memoised view of either then skips its render, so
14
+ * one arriving row costs the blocks it changed and not the document. */
2
15
  export declare function retainReadingIdentity(previous: readonly ReadingSitting[], next: readonly ReadingSitting[]): ReadingSitting[];
@@ -1,9 +1,89 @@
1
- import { activityRowKey } from "./activity-plan.js";
1
+ import { activityRowKey, activityRows } from "./activity-plan.js";
2
+ /** Every row a reading block draws, in order. */
3
+ export function readingBlockRows(block) {
4
+ switch (block.kind) {
5
+ case "prompt": return block.prompts.flatMap(prompt => prompt.rows);
6
+ case "reply": return [block.segment.row];
7
+ case "activity": return block.rows;
8
+ case "request": return activityRows(block.item);
9
+ case "gap":
10
+ case "watermark": return [];
11
+ }
12
+ }
13
+ /** A derived value past this depth is never called equal: the document is
14
+ * plain data a few levels deep, and a cycle must not recurse forever. */
15
+ const MAX_DEPTH = 48;
16
+ /** Structural equality over the document's plain data: arrays, maps and sets
17
+ * in order, own keys of plain objects (whose prototype is `Object.prototype`
18
+ * or null), and identity for everything else: two dates, two patterns or two
19
+ * instances of a class are equal only when they are one object. A row that is
20
+ * the same object is equal without being read. */
21
+ export function sameValue(a, b, depth = 0) {
22
+ if (Object.is(a, b))
23
+ return true;
24
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null || depth > MAX_DEPTH)
25
+ return false;
26
+ if (Array.isArray(a) || Array.isArray(b)) {
27
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length)
28
+ return false;
29
+ for (let index = 0; index < a.length; index += 1)
30
+ if (!sameValue(a[index], b[index], depth + 1))
31
+ return false;
32
+ return true;
33
+ }
34
+ if (a instanceof Map || b instanceof Map) {
35
+ if (!(a instanceof Map) || !(b instanceof Map) || a.size !== b.size)
36
+ return false;
37
+ const right = b.entries();
38
+ for (const [key, value] of a) {
39
+ const next = right.next().value;
40
+ if (!Object.is(key, next[0]) || !sameValue(value, next[1], depth + 1))
41
+ return false;
42
+ }
43
+ return true;
44
+ }
45
+ if (a instanceof Set || b instanceof Set) {
46
+ if (!(a instanceof Set) || !(b instanceof Set) || a.size !== b.size)
47
+ return false;
48
+ const right = b.values();
49
+ for (const value of a)
50
+ if (!sameValue(value, right.next().value, depth + 1))
51
+ return false;
52
+ return true;
53
+ }
54
+ const prototype = Object.getPrototypeOf(a);
55
+ if (prototype !== Object.getPrototypeOf(b) || (prototype !== Object.prototype && prototype !== null))
56
+ return false;
57
+ const keys = Object.keys(a);
58
+ if (keys.length !== Object.keys(b).length)
59
+ return false;
60
+ for (const key of keys) {
61
+ if (!Object.prototype.hasOwnProperty.call(b, key))
62
+ return false;
63
+ if (!sameValue(a[key], b[key], depth + 1))
64
+ return false;
65
+ }
66
+ return true;
67
+ }
68
+ function sameRows(a, b) {
69
+ if (a.length !== b.length)
70
+ return false;
71
+ for (let index = 0; index < a.length; index += 1)
72
+ if (a[index] !== b[index])
73
+ return false;
74
+ return true;
75
+ }
76
+ /** The same rows, as the same objects in the same order, and every other
77
+ * field equal: the block draws exactly what it drew. */
78
+ function sameBlock(previous, next) {
79
+ return previous.kind === next.kind && previous.key === next.key
80
+ && sameRows(readingBlockRows(previous), readingBlockRows(next)) && sameValue(previous, next);
81
+ }
2
82
  /** Prefer the largest surviving overlap, with one owner per old key. Inserting
3
83
  * older rows must not remount an existing sitting, fold, or attachment rail.
4
84
  * Real splits/merges keep the best surviving owner; row disclosure state is
5
85
  * independently keyed by canonical identity. No historical rows are retained. */
6
- function retainedKeys(previous, next) {
86
+ function retainedKeys(previous, next, taken = new Set()) {
7
87
  const owner = new Map();
8
88
  for (const group of previous)
9
89
  for (const row of group.rows)
@@ -18,7 +98,7 @@ function retainedKeys(previous, next) {
18
98
  return [...counts].map(([key, count]) => ({ index, key, count }));
19
99
  }).sort((a, b) => b.count - a.count || a.index - b.index);
20
100
  const assigned = new Map();
21
- const used = new Set();
101
+ const used = new Set(taken);
22
102
  for (const match of matches) {
23
103
  if (assigned.has(match.index) || used.has(match.key))
24
104
  continue;
@@ -36,17 +116,53 @@ function retainedKeys(previous, next) {
36
116
  return key;
37
117
  });
38
118
  }
119
+ /** Keys survive as before; beyond that, a block whose rows did not change is
120
+ * handed back as the PREVIOUS object, and a sitting whose blocks all came back
121
+ * is the previous sitting. A memoised view of either then skips its render, so
122
+ * one arriving row costs the blocks it changed and not the document. */
39
123
  export function retainReadingIdentity(previous, next) {
40
- const sittingKeys = retainedKeys(previous.map(x => ({ ...x.sitting, key: x.renderKey ?? x.sitting.key })), next.map(x => x.sitting));
124
+ // The leading sittings the plan handed back as the objects it made last time
125
+ // keep what they were retained as: retaining a sitting again against its own
126
+ // result gives that result, so they are neither read nor compared, and one
127
+ // arriving row compares the sittings it changed (2026-11-29, the reader's
128
+ // arrival cost). Their keys stay taken for the sittings after them.
129
+ let kept = 0;
130
+ while (kept < next.length && kept < previous.length && retainedFrom.get(next[kept]) === previous[kept])
131
+ kept += 1;
132
+ const head = previous.slice(0, kept);
133
+ const result = [...head, ...retainSittings(previous.slice(kept), next.slice(kept), new Set(head.map(renderKeyOf)))];
134
+ next.forEach((entry, index) => retainedFrom.set(entry, result[index]));
135
+ return result;
136
+ }
137
+ /** What each sitting the plan made was retained as. */
138
+ const retainedFrom = new WeakMap();
139
+ const renderKeyOf = (entry) => entry.renderKey ?? entry.sitting.key;
140
+ function retainSittings(previous, next, taken) {
141
+ const previousByKey = new Map(previous.map(entry => [renderKeyOf(entry), entry]));
142
+ const sittingKeys = retainedKeys(previous.map(entry => ({ key: renderKeyOf(entry), rows: entry.sitting.rows })), next.map(entry => entry.sitting), taken);
41
143
  return next.map(({ sitting, blocks }, index) => {
42
- const old = previous.find(x => (x.renderKey ?? x.sitting.key) === sittingKeys[index]);
144
+ const renderKey = sittingKeys[index];
145
+ const old = previousByKey.get(renderKey);
43
146
  const groups = blocks.filter(block => block.kind === "activity");
44
147
  const keys = retainedKeys(old?.blocks.filter(block => block.kind === "activity") ?? [], groups);
148
+ const oldByKey = new Map((old?.blocks ?? []).map(block => [block.key, block]));
45
149
  let groupIndex = 0;
46
- return {
47
- sitting,
48
- renderKey: sittingKeys[index],
49
- blocks: blocks.map(block => block.kind === "activity" ? { ...block, key: keys[groupIndex++] } : block),
50
- };
150
+ let unchanged = old !== undefined && old.renderKey === renderKey && old.blocks.length === blocks.length;
151
+ const kept = blocks.map((block, at) => {
152
+ let keyed = block;
153
+ if (block.kind === "activity") {
154
+ const key = keys[groupIndex++];
155
+ if (key !== block.key)
156
+ keyed = { ...block, key };
157
+ }
158
+ const prior = oldByKey.get(keyed.key);
159
+ const result = prior !== undefined && sameBlock(prior, keyed) ? prior : keyed;
160
+ if (unchanged && old.blocks[at] !== result)
161
+ unchanged = false;
162
+ return result;
163
+ });
164
+ if (unchanged && sameValue(old.sitting, sitting))
165
+ return old;
166
+ return { sitting, renderKey, blocks: kept };
51
167
  });
52
168
  }
@@ -59,6 +59,17 @@ export function WorktreeColumn({ projectRoot, tint, homeDirectory, sessionPaths,
59
59
  ? null
60
60
  : commits.filter((commit) => commit.pushed === false).length, [commits]);
61
61
  const host = useRoom().host;
62
+ // The ledger's figures: asked of the host for the rows on screen, for this
63
+ // exact root and generation. A new root is a new asker, and the list starts
64
+ // its answers over.
65
+ const measureRoot = live?.root ?? null;
66
+ const measureGeneration = live?.generation ?? null;
67
+ const measure = useMemo(() => {
68
+ const worktree = host?.worktree;
69
+ if (worktree?.worktreeSizes === undefined || measureRoot === null || measureGeneration === null)
70
+ return undefined;
71
+ return (paths) => worktree.worktreeSizes?.(measureRoot, measureGeneration, paths) ?? Promise.resolve([]);
72
+ }, [host, measureRoot, measureGeneration]);
62
73
  const hasShell = host?.worktree !== undefined;
63
74
  const listBrowsers = useMemo(() => host?.browsers?.bind(host), [host]);
64
75
  const openInBrowser = useMemo(() => (host === null ? null : (name, bytes, browserId) => host.openInBrowser(name, bytes, browserId)), [host]);
@@ -146,7 +157,7 @@ export function WorktreeColumn({ projectRoot, tint, homeDirectory, sessionPaths,
146
157
  // with no children, which an empty directory also is.
147
158
  if (isOpenable(entry))
148
159
  setOpen({ handle: handleFor(engine, entry), diff: false });
149
- } }), hasSiblingWorktrees && (_jsx(WorktreeList, { facts: facts, openRoot: shownRoot, homeDirectory: homeDirectory }))] }))) : connection === null ? (_jsx(EmptyState, { title: "Reading the repository", description: "Asking git for its status." })) : tab === "changes" ? (_jsx(GitChanges, { entries: entries, sessionPaths: sessionPaths, selection: selection, onSelect: showDiff, onStage: client === null ? null : (paths) => act("Staged", paths, client.stage), onUnstage: client === null ? null : (paths) => act("Unstaged", paths, client.unstage), onDiscard: client === null ? null : setPendingDiscard })) : (_jsx(GitHistory, { commits: commits, selectedSha: openCommit, onSelect: showCommit, currentTimestamp: currentTimestamp })), openCommit !== null && (_jsx(CommitViewer, { commit: openCommit, files: commitFiles, client: client, sessionPaths: sessionPaths, currentTimestamp: currentTimestamp, onReceipt: onReceipt, onClose: () => {
160
+ } }), hasSiblingWorktrees && (_jsx(WorktreeList, { facts: facts, openRoot: shownRoot, homeDirectory: homeDirectory, onReceipt: onReceipt, measure: measure }))] }))) : connection === null ? (_jsx(EmptyState, { title: "Reading the repository", description: "Asking git for its status." })) : tab === "changes" ? (_jsx(GitChanges, { entries: entries, sessionPaths: sessionPaths, selection: selection, onSelect: showDiff, onStage: client === null ? null : (paths) => act("Staged", paths, client.stage), onUnstage: client === null ? null : (paths) => act("Unstaged", paths, client.unstage), onDiscard: client === null ? null : setPendingDiscard })) : (_jsx(GitHistory, { commits: commits, selectedSha: openCommit, onSelect: showCommit, currentTimestamp: currentTimestamp })), openCommit !== null && (_jsx(CommitViewer, { commit: openCommit, files: commitFiles, client: client, sessionPaths: sessionPaths, currentTimestamp: currentTimestamp, onReceipt: onReceipt, onClose: () => {
150
161
  setOpenCommit(null);
151
162
  setCommitFiles(null);
152
163
  } })), _jsx(ConfirmDialog, { question: pendingDiscard === null
@@ -1,8 +1,14 @@
1
- import type { GitFacts } from "../../ports.js";
1
+ import type { GitFacts, WorktreeSize } from "../../ports.js";
2
2
  export interface WorktreeListProps {
3
3
  readonly facts: GitFacts;
4
4
  /** The root the tree is showing, which earns the dirty count. */
5
5
  readonly openRoot: string | null;
6
6
  readonly homeDirectory: string | null;
7
+ /** The room's receipt line, so a copy is never silent. */
8
+ readonly onReceipt: (text: string) => void;
9
+ /** Ask the host what these worktrees hold on disk. Its identity is the
10
+ * open root's: a new one starts the list's answers over. Absent: the host
11
+ * measures nothing, and the list draws only the figures git facts carried. */
12
+ readonly measure?: ((paths: readonly string[]) => Promise<readonly WorktreeSize[]>) | undefined;
7
13
  }
8
- export declare function WorktreeList({ facts, openRoot, homeDirectory }: WorktreeListProps): import("react").JSX.Element;
14
+ export declare function WorktreeList({ facts, openRoot, homeDirectory, onReceipt, measure, }: WorktreeListProps): import("react").JSX.Element;