@vibefield/rosetta-room 0.1.11 → 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 (87) hide show
  1. package/README.md +64 -2
  2. package/dist/components/Transcript.js +6 -2
  3. package/dist/components/file-viewer/kinds.d.ts +22 -0
  4. package/dist/components/file-viewer/kinds.js +57 -0
  5. package/dist/components/file-viewer/markdown/render.d.ts +7 -1
  6. package/dist/components/file-viewer/markdown/render.js +16 -12
  7. package/dist/components/file-viewer/registry.d.ts +2 -2
  8. package/dist/components/file-viewer/registry.js +20 -59
  9. package/dist/components/transcript/Activity.d.ts +10 -4
  10. package/dist/components/transcript/Activity.js +36 -11
  11. package/dist/components/transcript/Compaction.d.ts +9 -0
  12. package/dist/components/transcript/Compaction.js +8 -4
  13. package/dist/components/transcript/Document.js +150 -208
  14. package/dist/components/transcript/PromptJump.js +28 -8
  15. package/dist/components/transcript/Prose.d.ts +5 -1
  16. package/dist/components/transcript/Prose.js +3 -3
  17. package/dist/components/transcript/ReadingBlocks.d.ts +71 -0
  18. package/dist/components/transcript/ReadingBlocks.js +279 -0
  19. package/dist/components/transcript/activity-plan.d.ts +38 -7
  20. package/dist/components/transcript/activity-plan.js +198 -28
  21. package/dist/components/transcript/attachment-file-source.d.ts +1 -2
  22. package/dist/components/transcript/attachment-file-source.js +7 -5
  23. package/dist/components/transcript/disclosure-state.d.ts +2 -0
  24. package/dist/components/transcript/disclosure-state.js +6 -2
  25. package/dist/components/transcript/document-model.js +53 -9
  26. package/dist/components/transcript/document-plan.js +263 -98
  27. package/dist/components/transcript/reading-identity.d.ts +14 -1
  28. package/dist/components/transcript/reading-identity.js +126 -10
  29. package/dist/conversation/ConversationGallery.d.ts +11 -0
  30. package/dist/conversation/ConversationGallery.js +14 -0
  31. package/dist/conversation/ConversationMedia.d.ts +44 -0
  32. package/dist/conversation/ConversationMedia.js +210 -0
  33. package/dist/conversation/ConversationProse.d.ts +13 -0
  34. package/dist/conversation/ConversationProse.js +6 -0
  35. package/dist/conversation/ConversationRunRows.d.ts +57 -0
  36. package/dist/conversation/ConversationRunRows.js +84 -0
  37. package/dist/conversation/ConversationTurnView.d.ts +64 -0
  38. package/dist/conversation/ConversationTurnView.js +169 -0
  39. package/dist/conversation/ConversationView.d.ts +3 -0
  40. package/dist/conversation/ConversationView.js +257 -0
  41. package/dist/conversation/feed-reads.d.ts +36 -0
  42. package/dist/conversation/feed-reads.js +155 -0
  43. package/dist/conversation/feed.d.ts +106 -0
  44. package/dist/conversation/feed.js +884 -0
  45. package/dist/conversation/index.d.ts +11 -0
  46. package/dist/conversation/index.js +25 -0
  47. package/dist/conversation/model.d.ts +108 -0
  48. package/dist/conversation/model.js +257 -0
  49. package/dist/conversation/ports.d.ts +194 -0
  50. package/dist/conversation/ports.js +9 -0
  51. package/dist/conversation/rosetta-client.d.ts +8 -0
  52. package/dist/conversation/rosetta-client.js +1 -0
  53. package/dist/conversation/use-conversation-feed.d.ts +16 -0
  54. package/dist/conversation/use-conversation-feed.js +41 -0
  55. package/dist/conversation/use-conversation-window.d.ts +50 -0
  56. package/dist/conversation/use-conversation-window.js +336 -0
  57. package/dist/conversation/words.d.ts +51 -0
  58. package/dist/conversation/words.js +79 -0
  59. package/dist/fixtures/conversation.d.ts +34 -0
  60. package/dist/fixtures/conversation.js +723 -0
  61. package/dist/fixtures/index.d.ts +2 -0
  62. package/dist/fixtures/index.js +1 -0
  63. package/dist/lib/session-leases.d.ts +11 -8
  64. package/dist/lib/transcript/collaboration.js +53 -19
  65. package/dist/lib/transcript/head-of-document.js +9 -3
  66. package/dist/lib/transcript/index.d.ts +1 -1
  67. package/dist/lib/transcript/index.js +1 -1
  68. package/dist/lib/transcript/prompt-jump.d.ts +2 -0
  69. package/dist/lib/transcript/prompt-jump.js +5 -1
  70. package/dist/lib/transcript/sittings.d.ts +2 -1
  71. package/dist/lib/transcript/sittings.js +72 -10
  72. package/dist/lib/transcript/tail-state.d.ts +9 -0
  73. package/dist/lib/transcript/tail-state.js +25 -1
  74. package/dist/lib/transcript/turns.d.ts +5 -0
  75. package/dist/lib/transcript/turns.js +221 -57
  76. package/dist/lib/transcript/use-transcript-tail.js +17 -3
  77. package/dist/lib/transcript/vocabulary.d.ts +2 -1
  78. package/dist/lib/transcript/vocabulary.js +11 -1
  79. package/dist/parts-context.d.ts +25 -0
  80. package/dist/parts-context.js +32 -0
  81. package/dist/ports.d.ts +3 -0
  82. package/dist/room-context.d.ts +1 -7
  83. package/dist/room-context.js +12 -18
  84. package/dist/styles/conversation-turn.css +147 -0
  85. package/dist/styles/conversation.css +45 -0
  86. package/dist/styles/transcript.css +11 -2
  87. package/package.json +9 -4
@@ -0,0 +1,279 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // The reading blocks of History's document, each drawn on its own: a block,
3
+ // a sitting, and the drawing they alone use (a report's recorded work
4
+ // included). Moved out of `Document.tsx`, which keeps the document's own
5
+ // state and hands each sitting its scoped props.
6
+ import { Fragment, memo, useEffect, useMemo, useState } from "react";
7
+ import { collaborationStamp, linkedChildSessionIds, participantPresentation, runtimeProfile, runSummary, taskBoundedReportWork, workflowAttemptsFor, } from "../../lib/transcript/index.js";
8
+ import { useRoom } from "../../room-context.js";
9
+ import { useViewerDay } from "./viewer-day.js";
10
+ import { Anchor } from "./Anchor.js";
11
+ import { DayPill, Sitting } from "./DayPill.js";
12
+ import { transcriptModel } from "./document-model.js";
13
+ import { readingBlockRows } from "./reading-identity.js";
14
+ import { ActivityGroup, ContextEvent } from "./Activity.js";
15
+ import { messageAttachments } from "../../lib/transcript/images.js";
16
+ import { Ledger } from "./Ledger.js";
17
+ import { GapMarker, Marker, Watermark } from "./Marker.js";
18
+ import { Compaction } from "./Compaction.js";
19
+ import { Prompt } from "./Prompt.js";
20
+ import { SegmentActs } from "./Prose.js";
21
+ import { AuthoredMessage } from "./AuthoredMessage.js";
22
+ import { ResponseHead } from "./ResponseHead.js";
23
+ import { Subthread } from "./Subthread.js";
24
+ import { sessionContains } from "./thread-index.js";
25
+ import { ThoughtLine } from "./Thinking.js";
26
+ import { TeamEvent, TeamWorkthread } from "./Team.js";
27
+ import { TranscriptDocument } from "./Document.js";
28
+ /** Mounted only by an open work disclosure; ordinary team traffic carries no private work. */
29
+ function LazyReportWork({ report, ...props }) {
30
+ const [rows, setRows] = useState(null);
31
+ const [error, setError] = useState(null);
32
+ const { sessions } = useRoom();
33
+ useEffect(() => {
34
+ const controller = new AbortController();
35
+ setRows(null);
36
+ setError(null);
37
+ void sessions.run(report.session_id, (client) => client.reportWork(report.session_id, report.timeline_id, controller.signal)).then((rows) => { if (!controller.signal.aborted)
38
+ setRows(rows); }, (error) => { if (!controller.signal.aborted)
39
+ setError(error instanceof Error ? error.message : "The recorded work is unavailable"); });
40
+ return () => controller.abort();
41
+ }, [report, sessions]);
42
+ if (error !== null)
43
+ return _jsx("p", { className: "tr-quiet", children: error });
44
+ if (rows === null)
45
+ return _jsx("p", { className: "tr-quiet", children: "Loading recorded work\u2026" });
46
+ const work = taskBoundedReportWork(report, rows);
47
+ if (work === null)
48
+ return _jsx("p", { className: "tr-quiet", children: "The recorded work is no longer available." });
49
+ return (_jsxs(_Fragment, { children: [_jsxs("p", { className: "tr-quiet", children: [work.actionCount, " ", work.actionCount === 1 ? "action" : "actions"] }), _jsx(ReportWorkDocument, { ...props, rows: work.rows, startedAt: work.startedAt, endedAt: work.endedAt })] }));
50
+ }
51
+ function staticTimelineFeed(rows) {
52
+ const nothing = () => undefined;
53
+ return {
54
+ rows: [...rows],
55
+ snapshotReady: true,
56
+ error: null,
57
+ retry: nothing,
58
+ timelineMeta: null,
59
+ status: "live",
60
+ watermark: null,
61
+ earlier: { kind: "none" },
62
+ earlierNotice: null,
63
+ earlierAbove: 0,
64
+ landed: null,
65
+ holdEarlier: nothing,
66
+ revealEarlier: nothing,
67
+ retryEarlier: nothing,
68
+ dismissEarlierNotice: nothing,
69
+ canLoadEarlier: false,
70
+ loadEarlier: nothing,
71
+ loadAnchor: async () => false,
72
+ };
73
+ }
74
+ function ReportWorkDocument({ session, rows, name, color, runtime, startedAt, endedAt, index, onReceipt, onOpenAttachment, onOpenPath, getRuntimeKind, homeDirectory, }) {
75
+ const boundedSession = useMemo(() => ({ ...session, stream_state: "indexed" }), [session]);
76
+ const feed = useMemo(() => staticTimelineFeed(rows), [rows]);
77
+ // A pill's words are the drawing's: the model is re-derived when the viewer's day turns.
78
+ const viewerDay = useViewerDay();
79
+ const model = useMemo(() => transcriptModel(rows, boundedSession, homeDirectory, viewerDay.now), [rows, boundedSession, homeDirectory, viewerDay.now]);
80
+ const scopedIndex = useMemo(() => {
81
+ const linked = new Set(rows.flatMap((row) => linkedChildSessionIds(row)));
82
+ const childrenByParent = new Map(index.childrenByParent);
83
+ childrenByParent.set(session.id, (index.childrenByParent.get(session.id) ?? []).filter((child) => linked.has(child.id)));
84
+ return { byId: index.byId, childrenByParent };
85
+ }, [rows, session.id, index]);
86
+ return (_jsx(TeamWorkthread, { name: name, color: color, runtime: runtime, startedAt: startedAt, endedAt: endedAt, children: _jsx(TranscriptDocument, { session: boundedSession, model: model, feed: feed, duringBackfill: false, index: scopedIndex, focus: null, highlightedTimelineId: null, onFocusConsumed: () => undefined, onReceipt: onReceipt, onOpenAttachment: onOpenAttachment, onOpenPath: onOpenPath, getRuntimeKind: getRuntimeKind, homeDirectory: homeDirectory, onPillPress: null, nested: true }) }));
87
+ }
88
+ const EMPTY_SCOPE = {
89
+ index: { byId: new Map(), childrenByParent: new Map() },
90
+ focus: null,
91
+ revealedChildId: null,
92
+ revealRequest: 0,
93
+ duringBackfill: false,
94
+ homeDirectory: null,
95
+ workerLinks: { anchorRowByChild: new Map(), childrenByRow: new Map(), referencedChildIdsByRow: new Map() },
96
+ workflowAttempts: { byRunId: new Map(), byTimelineId: new Map() },
97
+ teamMembers: new Map(),
98
+ participants: new Map(),
99
+ teamIdSet: new Set(),
100
+ responseRuntimesBySession: new Map(),
101
+ };
102
+ /** Whether a row draws from the scope: team traffic, a workflow run, a team
103
+ * member's start, or a line that owns or names a worker's thread. */
104
+ function drawsFromScope(row, scope) {
105
+ return row.body.type === "collaboration"
106
+ || (row.body.type === "tool_use" && row.body.tool.action.type === "workflow")
107
+ || scope.teamMembers.has(row.timeline_id)
108
+ || scope.workerLinks.childrenByRow.has(row.timeline_id)
109
+ || scope.workerLinks.referencedChildIdsByRow.has(row.timeline_id);
110
+ }
111
+ function aliveIn(d, row) {
112
+ return d.aliveAfter !== null && row.session_id === d.actions.sessionId && row.ordinal > d.aliveAfter;
113
+ }
114
+ function drawChild(scope, actions, child, anchored) {
115
+ return (_jsx(Subthread, { session: child, anchored: anchored, duringBackfill: scope.duringBackfill, index: scope.index, focus: scope.focus, onFocusConsumed: actions.onFocusConsumed, onReceipt: actions.onReceipt, onOpenAttachment: actions.onOpenAttachment, onOpenPath: actions.onOpenPath, getRuntimeKind: actions.getRuntimeKind, homeDirectory: scope.homeDirectory }, child.id));
116
+ }
117
+ function childrenOf(scope, line) {
118
+ return scope.workerLinks.childrenByRow.get(line.rows[0].timeline_id) ?? [];
119
+ }
120
+ /** A search hit landed inside a worker this line owns, or the reader asked for it. */
121
+ function childFocused(scope, line) {
122
+ const focus = scope.focus;
123
+ return childrenOf(scope, line).some((child) => (focus !== null && sessionContains(child.id, focus.sessionId, scope.index.byId))
124
+ || child.id === scope.revealedChildId);
125
+ }
126
+ /** The same two forces, each named, so that a run can tell a new one from the
127
+ * one it was pressed under: a search hit inside a worker is named by its row,
128
+ * and a reveal by its request, so revealing a worker again is a new force. */
129
+ function childForces(scope, line) {
130
+ const focus = scope.focus;
131
+ return childrenOf(scope, line).flatMap((child) => [
132
+ ...(focus !== null && sessionContains(child.id, focus.sessionId, scope.index.byId)
133
+ ? [`focus:${focus.sessionId}:${focus.timelineId}`] : []),
134
+ ...(child.id === scope.revealedChildId ? [`worker:${child.id}:${scope.revealRequest}`] : []),
135
+ ]);
136
+ }
137
+ function reportWorkFor(d, row) {
138
+ if (row.body.type !== "collaboration")
139
+ return null;
140
+ const event = row.body.event;
141
+ if (event.kind !== "report" || event.source_session_id === null || event.source_response_id === null
142
+ || event.work_start_timeline_id === null || event.work_end_timeline_id === null)
143
+ return null;
144
+ const { scope, actions } = d;
145
+ const memberSession = scope.index.byId.get(event.source_session_id);
146
+ if (memberSession === undefined || !scope.teamIdSet.has(memberSession.id))
147
+ return null;
148
+ const participant = participantPresentation(scope.participants, event.sender, event.team);
149
+ return {
150
+ actionCount: null,
151
+ startedAt: null,
152
+ endedAt: null,
153
+ content: _jsx(LazyReportWork, { report: row, session: memberSession, name: event.sender, color: event.color ?? participant?.color ?? null, runtime: participant?.runtime ?? runtimeProfile([], memberSession.delegation?.configured_model ?? null, scope.responseRuntimesBySession.get(memberSession.id) ?? []), index: scope.index, onReceipt: actions.onReceipt, onOpenAttachment: actions.onOpenAttachment, onOpenPath: actions.onOpenPath, getRuntimeKind: actions.getRuntimeKind, homeDirectory: scope.homeDirectory }, `${row.session_id}:${row.timeline_id}`),
154
+ };
155
+ }
156
+ function drawSegment(d, segment, embedded = false) {
157
+ const { scope, actions } = d;
158
+ const rowId = segment.kind === "ledger" ? segment.rows[0].timeline_id : segment.row.timeline_id;
159
+ const hit = d.hit === rowId;
160
+ switch (segment.kind) {
161
+ case "ledger":
162
+ return (_jsx(Ledger, { embedded: embedded, members: segment.members, summary: segment.summary, anchor: !embedded && segment.summary.closedByDefault ? (_jsx(Anchor, { at: segment.at, sessionId: segment.rows[0].session_id, timelineId: rowId, onReceipt: actions.onReceipt })) : null, domIdOf: actions.domIdOf, highlightedTimelineId: d.hit, focusTimelineId: d.focusId, alive: (line) => aliveIn(d, line.rows[0]), hasChildren: (line) => childrenOf(scope, line).length > 0, childFocused: (line) => childFocused(scope, line), subthreadsFor: (line) => childrenOf(scope, line).map((child) => ({ childSessionId: child.id, node: drawChild(scope, actions, child, true) })), workflowAttemptsFor: (line) => workflowAttemptsFor(scope.workflowAttempts, line.rows[0]), linkedChildId: (line) => scope.workerLinks.referencedChildIdsByRow.get(line.rows[0].timeline_id)?.[0] ?? null, onOpenLinkedChild: actions.onOpenLinkedChild, teamMemberFor: (line) => line.rows
163
+ .map((row) => scope.teamMembers.get(row.timeline_id) ?? null)
164
+ .find((member) => member !== null) ?? null, onOpenPath: actions.onOpenPath, onOpenAttachment: actions.onOpenAttachment }, segment.key));
165
+ case "thinking":
166
+ // A thought alone is a run of one, drawn as its line (Q10 A).
167
+ return (_jsx(ThoughtLine, { text: segment.text, embedded: embedded, spanMs: segment.spanMs, domId: actions.domIdOf(rowId), timelineId: rowId, hit: hit, forceOpen: d.focusId === rowId, anchor: _jsx(Anchor, { at: segment.at, sessionId: segment.row.session_id, timelineId: rowId, onReceipt: actions.onReceipt }) }, segment.key));
168
+ case "marker":
169
+ if (segment.notice.type === "permission_requested")
170
+ return _jsx(Marker, { text: segment.text, tone: segment.tone, domId: actions.domIdOf(rowId), timelineId: rowId, hit: hit }, segment.key);
171
+ return _jsx(ContextEvent, { segment: segment, domId: actions.domIdOf(rowId), hit: hit, forceOpen: d.focusId === rowId, onReceipt: actions.onReceipt }, segment.key);
172
+ case "summary":
173
+ return _jsx(ContextEvent, { segment: segment, domId: actions.domIdOf(rowId), hit: hit, forceOpen: d.focusId === rowId, onReceipt: actions.onReceipt }, segment.key);
174
+ case "compaction":
175
+ return (_jsx(Compaction, { text: segment.text, domId: actions.domIdOf(rowId), timelineId: rowId, hit: segment.rows.some((row) => row.timeline_id === d.hit), forceOpen: segment.rows.some((row) => row.timeline_id === d.focusId), onReceipt: actions.onReceipt }, segment.key));
176
+ case "prose":
177
+ return (_jsxs("div", { className: "tr-seg tr-prose ah-syntax", id: actions.domIdOf(rowId), "data-timeline-id": rowId, "data-hit": hit || undefined, children: [_jsx(Anchor, { at: segment.at, sessionId: segment.row.session_id, timelineId: rowId, onReceipt: actions.onReceipt }), _jsx(AuthoredMessage, { text: segment.text, attachments: segment.attachments, recordedText: segment.row.body.type === "agent" ? segment.row.body.text : null, messageKey: `${segment.row.session_id}:${rowId}`, role: "agent", onReceipt: actions.onReceipt, onOpenAttachment: actions.onOpenAttachment }), segment.citationLabels.length > 0 && (_jsx("p", { className: "tr-cites", children: segment.citationLabels.map((label, at) => (_jsx("span", { children: label }, at))) })), _jsx(SegmentActs, { text: segment.text ?? "", onReceipt: actions.onReceipt })] }, segment.key));
178
+ case "collaboration": {
179
+ const sourceMember = scope.teamIdSet.has(segment.row.session_id)
180
+ ? scope.index.byId.get(segment.row.session_id)
181
+ : undefined;
182
+ const inferredRecipient = segment.event.channel === "coordinator" && segment.event.recipient === null
183
+ ? (sourceMember?.title ?? sourceMember?.native_session_id ?? null)
184
+ : segment.event.recipient;
185
+ const event = inferredRecipient === segment.event.recipient
186
+ ? segment.event
187
+ : { ...segment.event, recipient: inferredRecipient };
188
+ const participant = participantPresentation(scope.participants, event.sender, event.team);
189
+ const recipientParticipant = participantPresentation(scope.participants, event.recipient, event.team);
190
+ const stamp = collaborationStamp(segment.row);
191
+ return (_jsx(TeamEvent, { event: event, attachments: messageAttachments(segment.row), onOpenAttachment: actions.onOpenAttachment, at: stamp.at, timeBasis: stamp.basis, domId: actions.domIdOf(rowId), timelineId: rowId, participant: participant, recipientParticipant: recipientParticipant, hit: hit, forceOpen: d.focusId === rowId, reportWork: reportWorkFor(d, segment.row), onReceipt: actions.onReceipt }, segment.key));
192
+ }
193
+ }
194
+ }
195
+ function drawTools(d, items, embedded) {
196
+ const lines = items.map(item => item.line);
197
+ const rows = lines.flatMap(line => line.rows);
198
+ return drawSegment(d, { kind: "ledger", key: items[0].key, at: rows[0].at, rows, lines,
199
+ members: lines.map(line => ({ kind: "line", key: line.key, line })), summary: runSummary(lines) }, embedded);
200
+ }
201
+ function drawItem(d, item) {
202
+ if (item.kind === "tool")
203
+ return drawTools(d, [item], false);
204
+ if (item.kind !== "prompt")
205
+ return drawSegment(d, item, true);
206
+ const row = item.prompt.row;
207
+ if (row.body.type === "collaboration")
208
+ return drawSegment(d, { kind: "collaboration", key: item.key,
209
+ row, at: row.at, event: row.body.event }, true);
210
+ return _jsx(Prompt, { prompts: [item.prompt], domIdOf: d.actions.domIdOf, landedTimelineId: d.hit, focusTimelineId: d.focusId, onReceipt: d.actions.onReceipt, onOpenAttachment: d.actions.onOpenAttachment }, item.key);
211
+ }
212
+ function drawItems(d, items) {
213
+ const nodes = [];
214
+ let tools = [];
215
+ const flush = () => { if (tools.length > 0)
216
+ nodes.push(drawTools(d, tools, true)); tools = []; };
217
+ for (const item of items) {
218
+ if (item.kind === "tool")
219
+ tools.push(item);
220
+ else {
221
+ flush();
222
+ nodes.push(drawItem(d, item));
223
+ }
224
+ }
225
+ flush();
226
+ return nodes;
227
+ }
228
+ const ReadingBlockView = memo(function ReadingBlockView({ block, hit, focusId, force, aliveAfter, headOpen, runtimeKind, earlier, teamLoading, teamError, scope, actions, }) {
229
+ const d = { hit, focusId, aliveAfter, scope: scope ?? EMPTY_SCOPE, actions };
230
+ switch (block.kind) {
231
+ case "gap": return _jsx(GapMarker, { count: block.count, onPress: () => actions.onReceipt(`${block.count} ${block.count === 1 ? "message is" : "messages are"} in the session but not in this page`) });
232
+ case "watermark": return _jsx(Watermark, { text: "received since opening" });
233
+ case "prompt": return _jsx("div", { className: "tr-turn tr-reading-prompt", children: _jsx(Prompt, { prompts: block.prompts, domIdOf: actions.domIdOf, landedTimelineId: hit, onReceipt: actions.onReceipt, onOpenAttachment: actions.onOpenAttachment }) });
234
+ case "reply": return _jsxs("div", { className: block.head === null ? "tr-reading-reply" : "tr-resp tr-reading-reply", children: [block.head !== null && _jsx(ResponseHead, { head: block.head, runtimeKind: runtimeKind, open: headOpen }), drawSegment(d, block.segment)] });
235
+ case "request": return drawItem(d, block.item);
236
+ case "activity":
237
+ return _jsx(ActivityGroup, { items: block.items, rows: block.rows, partial: block.partial, force: force, earlier: earlier, onLoadEarlier: actions.onLoadEarlier, teamLoading: teamLoading, teamError: teamError, onRetryTeam: actions.onRetryTeam, onOpenAttachment: actions.onOpenAttachment, onReceipt: actions.onReceipt, highlightedId: hit, alive: row => aliveIn(d, row), children: () => drawItems(d, block.items) });
238
+ }
239
+ });
240
+ /** The block's element, with every prop scoped to what that block holds. */
241
+ function readingBlock(block, view, scope, actions) {
242
+ const rows = readingBlockRows(block);
243
+ const holds = (id) => id !== null && rows.some((row) => row.timeline_id === id);
244
+ const blockScope = scope !== null && rows.some((row) => drawsFromScope(row, scope)) ? scope : null;
245
+ const focusId = holds(view.focusTimelineId) ? view.focusTimelineId : null;
246
+ const activity = block.kind === "activity";
247
+ const forces = !activity ? [] : [
248
+ ...(focusId === null ? [] : [`focus:${focusId}`]),
249
+ ...(blockScope === null ? [] : block.items.flatMap((item) => item.kind === "tool" ? childForces(blockScope, item.line) : [])),
250
+ ];
251
+ const watermark = view.watermark;
252
+ const aliveAfter = (activity || block.kind === "request") && view.recentActivity && watermark !== null
253
+ && rows.some((row) => row.session_id === view.sessionId && row.ordinal > watermark) ? watermark : null;
254
+ const head = block.kind === "reply" ? block.head : null;
255
+ return _jsx(ReadingBlockView, { block: block, hit: holds(view.highlightedTimelineId) ? view.highlightedTimelineId : null, focusId: focusId, force: forces.length === 0 ? null : forces.join(" "), aliveAfter: aliveAfter, headOpen: head !== null && view.recentActivity && head.endedAt === null, runtimeKind: head !== null ? view.runtimeKind : "", earlier: activity && block.partial ? view.earlier : "none", teamLoading: activity && view.teamLoading, teamError: activity ? view.teamError : null, scope: blockScope, actions: actions });
256
+ }
257
+ const ReadingSittingView = memo(function ReadingSittingView({ entry, showPills, view, scope, floating, actions }) {
258
+ const { sitting, blocks } = entry;
259
+ // A block drawn from the same view, scope and actions, with no worker placed
260
+ // before it, is handed the element it was drawn as before: React passes over
261
+ // it unread, so a sitting drawn again for one arriving row makes the
262
+ // elements of the blocks that row changed and not of every block in it
263
+ // (2026-11-29, the reader's arrival cost).
264
+ const [drawn] = useState(() => new WeakMap());
265
+ const drawBlock = (block) => {
266
+ const placed = floating?.get(block.key);
267
+ if (placed !== undefined) {
268
+ return _jsxs(Fragment, { children: [placed.map((child) => drawChild(scope ?? EMPTY_SCOPE, actions, child, false)), readingBlock(block, view, scope, actions)] }, block.key);
269
+ }
270
+ const held = drawn.get(block);
271
+ if (held !== undefined && held.view === view && held.scope === scope && held.actions === actions)
272
+ return held.element;
273
+ const element = _jsx(Fragment, { children: readingBlock(block, view, scope, actions) }, block.key);
274
+ drawn.set(block, { view, scope, actions, element });
275
+ return element;
276
+ };
277
+ return (_jsxs(Sitting, { sitting: sitting, children: [showPills && (_jsx(DayPill, { sitting: sitting, onPress: (event) => actions.onPillPress(event.currentTarget, sitting.dayKey) })), blocks.map(drawBlock)] }));
278
+ });
279
+ export { drawChild, drawsFromScope, ReadingSittingView };
@@ -56,17 +56,48 @@ export interface ReadingSitting {
56
56
  }
57
57
  export declare function activityRows(item: ActivityItem): readonly TimelineEntry[];
58
58
  export declare function activityRowKey(row: TimelineEntry): string;
59
+ /** A missing stretch with no drawn row after it: its rows' count, and the first
60
+ * row past the stretch (the block's key and time). */
61
+ export interface TrailingGap {
62
+ readonly count: number;
63
+ readonly row: TimelineEntry;
64
+ }
65
+ export interface ActivityCuts {
66
+ readonly gaps: ReadonlyMap<string, number>;
67
+ readonly watermarkId: string | null;
68
+ readonly cutBefore: ReadonlySet<string>;
69
+ readonly trailingGap: TrailingGap | null;
70
+ }
59
71
  /** Tool lines must already have been cut at these boundaries before coalescing. */
60
- export declare function activityCuts(rows: readonly TimelineEntry[], watermark: number | null, displayedRows?: readonly TimelineEntry[]): {
61
- gaps: Map<string, number>;
62
- watermarkId: string | null;
63
- cutBefore: Set<string>;
64
- };
65
- export declare function activityPlan(plan: readonly PlannedSitting[], options: {
72
+ export declare function activityCuts(rows: readonly TimelineEntry[], watermark: number | null, displayedRows?: readonly TimelineEntry[]): ActivityCuts;
73
+ export interface ActivityPlanOptions {
66
74
  readonly gaps: ReadonlyMap<string, number>;
67
75
  readonly watermarkId: string | null;
68
76
  readonly partial: boolean;
69
- }): ReadingSitting[];
77
+ /** Required: a caller that left it out would say nothing of a stretch missing at the end. */
78
+ readonly trailingGap: TrailingGap | null;
79
+ }
80
+ /**
81
+ * What the last plan was made from and what it made, sitting by sitting (2026-11-29, the reader's arrival cost). The
82
+ * plan carries three things from one sitting to the next: the turns whose head is drawn, the rows whose gap or live
83
+ * line is drawn, and whether the document's first content is still ahead. Each sitting records what it added and what
84
+ * it found, so a plan whose first sittings are the same objects, under the same options, hands their blocks back and
85
+ * makes only the sittings after them: one arriving row makes the last sitting, not the document.
86
+ */
87
+ export interface ActivityPlanMemo {
88
+ plan: readonly PlannedSitting[];
89
+ options: ActivityPlanOptions | null;
90
+ made: ReadingSitting[];
91
+ headed: Set<string>;
92
+ bounded: Set<string>;
93
+ /** Per sitting: the turn keys and the row ids it added, and the first-content flag it began with. */
94
+ headedBy: string[][];
95
+ boundedBy: string[][];
96
+ firstBefore: boolean[];
97
+ firstAfter: boolean;
98
+ }
99
+ export declare function activityPlanMemo(): ActivityPlanMemo;
100
+ export declare function activityPlan(plan: readonly PlannedSitting[], options: ActivityPlanOptions, memo?: ActivityPlanMemo): ReadingSitting[];
70
101
  export interface ActivitySummary {
71
102
  readonly nouns: readonly {
72
103
  readonly key: string;
@@ -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 {