@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
@@ -25,3 +25,5 @@ export declare function demoProjectViewModels(demo?: RoomDemo): ProjectViewModel
25
25
  export declare function demoActivityOrder(demo?: RoomDemo): ActivityOrder;
26
26
  export { createColdImport } from "./cold-import.js";
27
27
  export type { ColdCorpus, ColdCorpusOptions, ColdImport, ColdImportController, ColdImportLog, ColdImportOptions, ColdPhase, ColdTrailEntry, ColdTree, FlipBatch, FlipKind, ResyncMode, RuntimeTimes, SessionKind, } from "./cold-import.js";
28
+ export { createConversationDemo } from "./conversation.js";
29
+ export type { ConversationDemo, ConversationDemoOptions } from "./conversation.js";
@@ -358,3 +358,4 @@ export function demoActivityOrder(demo = createRoomDemo()) {
358
358
  // archive and a controller a harness steps through simulated time
359
359
  // (`cold-import.ts`). clients/app's cold-import characterization drives it.
360
360
  export { createColdImport } from "./cold-import.js";
361
+ export { createConversationDemo } from "./conversation.js";
@@ -1,15 +1,18 @@
1
- import type { SessionClient, SessionPort } from "../ports.js";
2
- export interface SessionLease {
1
+ import type { SessionClient } from "../ports.js";
2
+ export interface SessionLease<C = SessionClient> {
3
3
  /** The client, once the port has answered; null while it opens. */
4
- readonly client: SessionClient | null;
4
+ readonly client: C | null;
5
5
  /** Settles with the client, or rejects with the port's refusal. */
6
- readonly ready: Promise<SessionClient>;
6
+ readonly ready: Promise<C>;
7
7
  /** Give the session back. Idempotent; the last holder's release closes it. */
8
8
  release(): void;
9
9
  }
10
- export interface SessionLeases {
11
- acquire(sessionId: string): SessionLease;
10
+ export interface SessionLeases<C = SessionClient> {
11
+ acquire(sessionId: string): SessionLease<C>;
12
12
  /** One read through a session's client, held only for the read. */
13
- run<T>(sessionId: string, read: (client: SessionClient) => Promise<T>): Promise<T>;
13
+ run<T>(sessionId: string, read: (client: C) => Promise<T>): Promise<T>;
14
14
  }
15
- export declare function createSessionLeases(port: SessionPort): SessionLeases;
15
+ export declare function createSessionLeases<C>(port: {
16
+ open(sessionId: string): C | PromiseLike<C>;
17
+ close(sessionId: string): void;
18
+ }): SessionLeases<C>;
@@ -89,6 +89,10 @@ export function teamSessionIds(parentSessionId, directChildren, parentRows) {
89
89
  const direct = new Map(directChildren
90
90
  .filter((child) => child.parent_session_id === parentSessionId)
91
91
  .map((child) => [child.id, child]));
92
+ // A row names a team member only among the direct children: with none, no
93
+ // row is read (2026-11-29, the reader's arrival cost).
94
+ if (direct.size === 0)
95
+ return [];
92
96
  const ids = new Set(directChildren
93
97
  .filter((child) => child.parent_session_id === parentSessionId &&
94
98
  (child.role === "team" || child.delegation?.team != null))
@@ -235,6 +239,14 @@ export function collaborationStamp(row) {
235
239
  * canonical, while child events enter the gap selected by native authored
236
240
  * time, or their explicitly labelled observed-arrival fallback. */
237
241
  export function teamChronology(parentRows, rowsBySession, coverage) {
242
+ // No team row to merge and no delivered boundary among the parent's own rows:
243
+ // nothing below is merged or counted twice, so the rows are the parent's as
244
+ // they are, and one arriving row reads every row once, not into three maps
245
+ // (2026-11-29, the reader's arrival cost).
246
+ if (![...rowsBySession.values()].some((rows) => rows.length > 0) &&
247
+ !parentRows.some((row) => row.body.type === "collaboration" && row.body.event.delivery_id !== null)) {
248
+ return { rows: parentRows, duplicateRepresentatives: new Map() };
249
+ }
238
250
  const seenTimelineIds = new Set(parentRows.map((row) => row.timeline_id));
239
251
  const duplicateRepresentatives = new Map();
240
252
  const candidates = [];
@@ -346,29 +358,12 @@ export function workerThreadLinks(lines, parentSessionId, sessions, excludedSess
346
358
  const anchorRowByChild = new Map();
347
359
  const childrenByRow = new Map();
348
360
  const referencedChildIdsByRow = new Map();
361
+ const candidates = childCandidates(parentSessionId, sessions, excludedSessionIds);
349
362
  for (const line of lines) {
350
363
  const rowId = line.rows[0]?.timeline_id;
351
364
  if (rowId === undefined)
352
365
  continue;
353
- const childIds = new Set(line.rows.flatMap((row) => linkedChildSessionIds(row)));
354
- const nativeToolIds = new Set(line.rows.flatMap((row) => row.body.type === "tool_use"
355
- ? [row.body.tool.correlation.key, row.body.tool.native.id].filter((value) => value !== null)
356
- : []));
357
- for (const child of sessions.values()) {
358
- if (child.parent_session_id === parentSessionId &&
359
- !excludedSessionIds.has(child.id) &&
360
- child.delegation?.parent_tool_native_id != null &&
361
- nativeToolIds.has(child.delegation.parent_tool_native_id)) {
362
- childIds.add(child.id);
363
- }
364
- }
365
- for (const childId of childIds) {
366
- const child = sessions.get(childId);
367
- if (child === undefined ||
368
- child.parent_session_id !== parentSessionId ||
369
- excludedSessionIds.has(child.id)) {
370
- continue;
371
- }
366
+ for (const child of lineChildren(line, candidates)) {
372
367
  const anchor = anchorRowByChild.get(child.id);
373
368
  if (anchor === undefined) {
374
369
  anchorRowByChild.set(child.id, rowId);
@@ -389,6 +384,45 @@ export function workerThreadLinks(lines, parentSessionId, sessions, excludedSess
389
384
  }
390
385
  return { anchorRowByChild, childrenByRow, referencedChildIdsByRow };
391
386
  }
387
+ let lastCandidates = { list: [], byId: new Map() };
388
+ function childCandidates(parentSessionId, sessions, excludedSessionIds) {
389
+ const list = [];
390
+ for (const child of sessions.values()) {
391
+ if (child.parent_session_id === parentSessionId && !excludedSessionIds.has(child.id))
392
+ list.push(child);
393
+ }
394
+ const held = lastCandidates;
395
+ if (held.list.length === list.length && held.list.every((child, index) => child === list[index]))
396
+ return held;
397
+ lastCandidates = { list, byId: new Map(list.map((child) => [child.id, child])) };
398
+ return lastCandidates;
399
+ }
400
+ /** The children one line links, kept by the line for as long as the candidates are the same object: one arriving
401
+ * row reads the lines it changed, not every line's rows against every session. */
402
+ const linkedByLine = new WeakMap();
403
+ function lineChildren(line, candidates) {
404
+ const held = linkedByLine.get(line);
405
+ if (held !== undefined && held.candidates === candidates)
406
+ return held.children;
407
+ const childIds = new Set(line.rows.flatMap((row) => linkedChildSessionIds(row)));
408
+ const nativeToolIds = new Set(line.rows.flatMap((row) => row.body.type === "tool_use"
409
+ ? [row.body.tool.correlation.key, row.body.tool.native.id].filter((value) => value !== null)
410
+ : []));
411
+ for (const child of candidates.list) {
412
+ if (child.delegation?.parent_tool_native_id != null && nativeToolIds.has(child.delegation.parent_tool_native_id)) {
413
+ childIds.add(child.id);
414
+ }
415
+ }
416
+ // A linked id names a child of this document only when it is one of the candidates.
417
+ const children = [];
418
+ for (const childId of childIds) {
419
+ const child = candidates.byId.get(childId);
420
+ if (child !== undefined)
421
+ children.push(child);
422
+ }
423
+ linkedByLine.set(line, { candidates, children });
424
+ return children;
425
+ }
392
426
  /** Recover report work only when canonical evidence names the exact source
393
427
  * session and inclusive timeline bounds. A shared task id alone is not a
394
428
  * safe range: teammates can overlap work on the same task. */
@@ -101,11 +101,17 @@ export function useHeadOfDocument(scrollerRef, feed, options = {}) {
101
101
  scroller.scrollTop += delta;
102
102
  anchorRef.current = measureAnchor(scroller);
103
103
  }, [landSeq, scrollerRef]);
104
- // Keep the anchor fresh: every commit, and every scroll frame below.
104
+ // Keep the anchor fresh: every commit, and every scroll frame below. Only a
105
+ // page landing above reads it, and with the conversation's start loaded
106
+ // (`none`) no page is left to land, so a commit measures nothing: a reader at
107
+ // the foot of a long document would read the box of every row on every
108
+ // arrival (2026-11-29, the reader's arrival cost). A page lands only from a
109
+ // held one, so the commit before any landing measured.
105
110
  useLayoutEffect(() => {
106
111
  const scroller = scrollerRef.current;
107
- if (scroller !== null)
108
- anchorRef.current = measureAnchor(scroller);
112
+ if (scroller === null)
113
+ return;
114
+ anchorRef.current = feedRef.current.earlier.kind === "none" ? null : measureAnchor(scroller);
109
115
  });
110
116
  // ── the receipt ───────────────────────────────────────────────────────────
111
117
  const landed = feed.landed;
@@ -14,4 +14,4 @@ export type { WorkflowAttemptFact, WorkflowAttemptIndex, WorkflowRuntimeFact, }
14
14
  export { workflowAttemptIndex, workflowAttemptsFor, workflowRuntime, workflowWorkerState, } from "./workflow.js";
15
15
  export { collaborationStamp, interleaveTeamCollaboration, participantPresentation, runtimeProfile, teamMemberPresentations, teamChronology, teamParticipants, taskBoundedReportWork, teamSessionIds, workerThreadLinks, } from "./collaboration.js";
16
16
  export type { PromptJumpPlan } from "./prompt-jump.js";
17
- export { PROMPT_JUMP_EASE_MS, PROMPT_JUMP_LANDING_PX, jumpMotion, jumpScrollTop, previousMessageTarget, promptJumpPlan, promptJumpShown, settleEase, } from "./prompt-jump.js";
17
+ export { PROMPT_JUMP_EASE_MS, PROMPT_JUMP_LANDING_PX, beginsAbove, jumpMotion, jumpScrollTop, previousMessageTarget, promptJumpPlan, promptJumpShown, settleEase, } from "./prompt-jump.js";
@@ -6,4 +6,4 @@ export { PROMPT_CLUSTER_MS, SITTING_PAUSE_MS, calendarDayKey, clockPillLead, day
6
6
  export { isWorkflowOwnedSession, standaloneWorkerSessions, } from "./collaboration.js";
7
7
  export { workflowAttemptIndex, workflowAttemptsFor, workflowRuntime, workflowWorkerState, } from "./workflow.js";
8
8
  export { collaborationStamp, interleaveTeamCollaboration, participantPresentation, runtimeProfile, teamMemberPresentations, teamChronology, teamParticipants, taskBoundedReportWork, teamSessionIds, workerThreadLinks, } from "./collaboration.js";
9
- export { PROMPT_JUMP_EASE_MS, PROMPT_JUMP_LANDING_PX, jumpMotion, jumpScrollTop, previousMessageTarget, promptJumpPlan, promptJumpShown, settleEase, } from "./prompt-jump.js";
9
+ export { PROMPT_JUMP_EASE_MS, PROMPT_JUMP_LANDING_PX, beginsAbove, jumpMotion, jumpScrollTop, previousMessageTarget, promptJumpPlan, promptJumpShown, settleEase, } from "./prompt-jump.js";
@@ -8,6 +8,8 @@ export declare const PROMPT_JUMP_EASE_MS = 300;
8
8
  * null. `tops` are in document order; of two at one top, the earlier.
9
9
  */
10
10
  export declare function previousMessageTarget(tops: readonly number[], viewTop: number): number | null;
11
+ /** A message whose top is this begins above the view: the press has somewhere to go. */
12
+ export declare function beginsAbove(top: number, viewTop: number): boolean;
11
13
  /** The scroll offset that stands a message's top 12 under the head, never above the document's top. */
12
14
  export declare function jumpScrollTop(scrollTop: number, messageTop: number, viewTop: number): number;
13
15
  /** At once when more than a screen away or under Reduce Motion; else the 300 ms ease. */
@@ -12,13 +12,17 @@ export function previousMessageTarget(tops, viewTop) {
12
12
  let target = null;
13
13
  for (let index = 0; index < tops.length; index += 1) {
14
14
  const top = tops[index];
15
- if (top >= viewTop - AT_THE_TOP_PX)
15
+ if (!beginsAbove(top, viewTop))
16
16
  continue;
17
17
  if (target === null || top > tops[target])
18
18
  target = index;
19
19
  }
20
20
  return target;
21
21
  }
22
+ /** A message whose top is this begins above the view: the press has somewhere to go. */
23
+ export function beginsAbove(top, viewTop) {
24
+ return top < viewTop - AT_THE_TOP_PX;
25
+ }
22
26
  /** The scroll offset that stands a message's top 12 under the head, never above the document's top. */
23
27
  export function jumpScrollTop(scrollTop, messageTop, viewTop) {
24
28
  return Math.max(0, scrollTop + messageTop - viewTop - PROMPT_JUMP_LANDING_PX);
@@ -93,7 +93,8 @@ export interface DayEntry {
93
93
  * not name its day is left out rather than filed under a guess.
94
94
  */
95
95
  export declare function dayList(list: readonly Sitting[]): DayEntry[];
96
- /** `3 sittings` on the session row — the same count, from the same threshold. */
96
+ /** `3 sittings` on the session row — the same count, from the same threshold,
97
+ * over the same rows the document cuts: those the reader draws. */
97
98
  export declare function sittingCount(rows: readonly TimelineEntry[], now?: number): number;
98
99
  /**
99
100
  * The time half of the setting-group rule. Whether both rows are successful
@@ -1,4 +1,5 @@
1
1
  import { clockShort, dayLabel } from "../format.js";
2
+ import { drawsNoMarker } from "./turns.js";
2
3
  /** A silence this long or longer means the reader left and came back. */
3
4
  export const SITTING_PAUSE_MS = 15 * 60_000;
4
5
  /** Adjacent successful setting commands inside this window may share one
@@ -99,9 +100,24 @@ export function msToNextViewerDay(now) {
99
100
  * caused it), and a negative gap is a record artefact, not a silence.
100
101
  */
101
102
  export function sittings(rows, now = Date.now()) {
102
- const open = [];
103
+ let open = [];
103
104
  let previousAt = null;
104
- for (const row of rows) {
105
+ // The previous stamp's day, read once per stamp rather than twice.
106
+ let previousDay = null;
107
+ // The fold reads the rows in order and nothing else, so rows that extend the
108
+ // last ones it read resume it where it ended: an arriving row is folded
109
+ // alone. The last sitting is copied before it can grow.
110
+ let start = 0;
111
+ const head = rows[0];
112
+ const last = head === undefined ? undefined : lastFolds.get(head);
113
+ if (last !== undefined && extendsRows(last.rows, rows)) {
114
+ open = last.open.map((sitting, index) => index === last.open.length - 1 ? { ...sitting, rows: [...sitting.rows] } : sitting);
115
+ start = last.rows.length;
116
+ previousAt = last.previousAt;
117
+ previousDay = last.previousDay;
118
+ }
119
+ for (let index = start; index < rows.length; index += 1) {
120
+ const row = rows[index];
105
121
  const at = row.at;
106
122
  const current = open.at(-1);
107
123
  if (current === undefined) {
@@ -116,7 +132,10 @@ export function sittings(rows, now = Date.now()) {
116
132
  }
117
133
  const gap = at - previousAt;
118
134
  const pauseMs = gap >= SITTING_PAUSE_MS ? gap : null;
119
- const dayChanged = calendarDayKey(at) !== calendarDayKey(previousAt);
135
+ previousDay ??= calendarDayKey(previousAt);
136
+ const day = at === previousAt ? previousDay : calendarDayKey(at);
137
+ const dayChanged = day !== previousDay;
138
+ previousDay = day;
120
139
  if (pauseMs === null && !dayChanged) {
121
140
  current.rows.push(row);
122
141
  previousAt = at;
@@ -132,18 +151,34 @@ export function sittings(rows, now = Date.now()) {
132
151
  });
133
152
  previousAt = at;
134
153
  }
154
+ // A copy: a caller may grow its own array after this call.
155
+ if (head !== undefined)
156
+ lastFolds.set(head, { rows: rows.slice(), open, previousAt, previousDay });
135
157
  return open.map((sitting, index) => {
158
+ const first = sitting.rows[0];
159
+ const held = madeSittings.get(first);
160
+ if (held !== undefined && held.now === now && held.sitting.isFirst === (index === 0) &&
161
+ held.sitting.resumedAt === sitting.resumedAt && held.sitting.pauseMs === sitting.pauseMs &&
162
+ held.sitting.dayChanged === sitting.dayChanged && sameRows(held.sitting.rows, sitting.rows)) {
163
+ return held.sitting;
164
+ }
136
165
  const stamps = sitting.rows
137
166
  .map((row) => row.at)
138
167
  .filter((value) => value !== null);
139
168
  const startedAt = stamps.length === 0 ? null : Math.min(...stamps);
140
169
  const endedAt = stamps.length === 0 ? null : Math.max(...stamps);
141
- return {
142
- key: sitting.rows[0].timeline_id,
143
- dayKey: startedAt === null ? null : calendarDayKey(startedAt),
144
- dayLabel: startedAt === null ? null : sittingDayLabel(startedAt, now),
170
+ // A sitting made again for a row it gained keeps its pill's words when the
171
+ // times they are read from are the same (2026-11-29, the reader's arrival cost).
172
+ const words = held !== undefined && held.now === now ? held.sitting : null;
173
+ const made = {
174
+ key: first.timeline_id,
175
+ dayKey: startedAt === null ? null
176
+ : words !== null && words.startedAt === startedAt ? words.dayKey : calendarDayKey(startedAt),
177
+ dayLabel: startedAt === null ? null
178
+ : words !== null && words.startedAt === startedAt ? words.dayLabel : sittingDayLabel(startedAt, now),
145
179
  resumedAt: sitting.resumedAt,
146
- clockLabel: sitting.resumedAt === null ? null : clockPillLead(sitting.resumedAt, now),
180
+ clockLabel: sitting.resumedAt === null ? null
181
+ : words !== null && words.resumedAt === sitting.resumedAt ? words.clockLabel : clockPillLead(sitting.resumedAt, now),
147
182
  pauseMs: sitting.pauseMs,
148
183
  dayChanged: sitting.dayChanged,
149
184
  isFirst: index === 0,
@@ -151,8 +186,34 @@ export function sittings(rows, now = Date.now()) {
151
186
  endedAt,
152
187
  rows: sitting.rows,
153
188
  };
189
+ madeSittings.set(first, { now, sitting: made });
190
+ return made;
154
191
  });
155
192
  }
193
+ /** Sittings kept by their first row (2026-11-29, the reader's arrival cost): a
194
+ * sitting of the same rows, cut the same way, read at the same `now`, is handed
195
+ * back as the same object, so one arriving row makes the last sitting again
196
+ * and not every pill's words. Rows are replaced, never changed in place. */
197
+ const madeSittings = new WeakMap();
198
+ /** The last fold of each conversation, by its first row: the rows it read and the state it ended in. */
199
+ const lastFolds = new WeakMap();
200
+ /** `next` begins with every row of `last`, as the same objects in the same order. */
201
+ function extendsRows(last, next) {
202
+ if (last.length > next.length)
203
+ return false;
204
+ for (let index = 0; index < last.length; index += 1)
205
+ if (last[index] !== next[index])
206
+ return false;
207
+ return true;
208
+ }
209
+ function sameRows(a, b) {
210
+ if (a.length !== b.length)
211
+ return false;
212
+ for (let index = 0; index < a.length; index += 1)
213
+ if (a[index] !== b[index])
214
+ return false;
215
+ return true;
216
+ }
156
217
  /**
157
218
  * The day list the pill opens into, in document order. A sitting that could
158
219
  * not name its day is left out rather than filed under a guess.
@@ -180,9 +241,10 @@ export function dayList(list) {
180
241
  }
181
242
  return days;
182
243
  }
183
- /** `3 sittings` on the session row — the same count, from the same threshold. */
244
+ /** `3 sittings` on the session row — the same count, from the same threshold,
245
+ * over the same rows the document cuts: those the reader draws. */
184
246
  export function sittingCount(rows, now = Date.now()) {
185
- return sittings(rows, now).length;
247
+ return sittings(rows.filter((row) => !drawsNoMarker(row)), now).length;
186
248
  }
187
249
  /**
188
250
  * The time half of the setting-group rule. Whether both rows are successful
@@ -1,3 +1,4 @@
1
+ import type { TimelineEntry } from "@vibefield/rosetta-protocol";
1
2
  /** Ordinals belong to sessions, not the merged team chronology. New sources
2
3
  * start with a baseline; history, patches and replay cannot inflate the count. */
3
4
  export interface TailRow {
@@ -7,11 +8,19 @@ export interface TailRow {
7
8
  }
8
9
  export declare class TailArrivals {
9
10
  private maxima;
11
+ /** The rows the last update read (2026-11-29, the reader's arrival cost).
12
+ * Each of them set its session's maximum, so none of them is fresh again: rows
13
+ * that begin with them, as the same objects in order, are read from where
14
+ * they end, and one arriving row reads one row. */
15
+ private seen;
10
16
  update<T extends TailRow>(rows: readonly T[]): T[];
11
17
  /** Even an empty initial snapshot establishes this session's live tail. */
12
18
  prime(sessionId: string): void;
13
19
  reset(): void;
14
20
  }
21
+ /** The arrivals the reader is told of ("N new messages"): rows the document
22
+ * shows, less a turn that finished, which it draws as nothing. */
23
+ export declare function countedArrivals<T extends TimelineEntry>(fresh: readonly T[], displayed: ReadonlySet<string>): T[];
15
24
  /** Time-based easing stays equally smooth on 60 Hz and 120 Hz displays.
16
25
  * Retargeting never restarts a browser smooth-scroll on each streamed token. */
17
26
  export declare function tailStep(current: number, target: number, elapsed: number): number;
@@ -1,15 +1,33 @@
1
+ import { drawsNoMarker } from "./turns.js";
1
2
  export class TailArrivals {
2
3
  maxima = new Map();
4
+ /** The rows the last update read (2026-11-29, the reader's arrival cost).
5
+ * Each of them set its session's maximum, so none of them is fresh again: rows
6
+ * that begin with them, as the same objects in order, are read from where
7
+ * they end, and one arriving row reads one row. */
8
+ seen = [];
3
9
  update(rows) {
4
10
  const fresh = [];
5
11
  const next = new Map(this.maxima);
6
- for (const row of rows) {
12
+ let start = 0;
13
+ if (this.seen.length <= rows.length) {
14
+ start = this.seen.length;
15
+ for (let index = 0; index < this.seen.length; index += 1) {
16
+ if (this.seen[index] !== rows[index]) {
17
+ start = 0;
18
+ break;
19
+ }
20
+ }
21
+ }
22
+ for (let index = start; index < rows.length; index += 1) {
23
+ const row = rows[index];
7
24
  const previous = this.maxima.get(row.session_id);
8
25
  if (previous !== undefined && row.ordinal > previous)
9
26
  fresh.push(row);
10
27
  next.set(row.session_id, Math.max(next.get(row.session_id) ?? -1, row.ordinal));
11
28
  }
12
29
  this.maxima = next;
30
+ this.seen = rows.slice();
13
31
  return fresh;
14
32
  }
15
33
  /** Even an empty initial snapshot establishes this session's live tail. */
@@ -19,8 +37,14 @@ export class TailArrivals {
19
37
  }
20
38
  reset() {
21
39
  this.maxima.clear();
40
+ this.seen = [];
22
41
  }
23
42
  }
43
+ /** The arrivals the reader is told of ("N new messages"): rows the document
44
+ * shows, less a turn that finished, which it draws as nothing. */
45
+ export function countedArrivals(fresh, displayed) {
46
+ return fresh.filter(row => displayed.has(row.timeline_id) && !drawsNoMarker(row));
47
+ }
24
48
  /** Time-based easing stays equally smooth on 60 Hz and 120 Hz displays.
25
49
  * Retargeting never restarts a browser smooth-scroll on each streamed token. */
26
50
  export function tailStep(current, target, elapsed) {
@@ -183,6 +183,11 @@ export interface DocumentOptions {
183
183
  * is cut before each of these; `document-model.ts` supplies them. */
184
184
  readonly cutBefore?: ReadonlySet<string>;
185
185
  }
186
+ /** A row the fold draws nothing for: a turn's end whose outcome is finished.
187
+ * Whoever anchors a line or a count on a row asks this first (`activityCuts`,
188
+ * the tail's arrivals, the sittings), so no line or count is anchored on a
189
+ * finished end. */
190
+ export declare function drawsNoMarker(row: TimelineEntry): boolean;
186
191
  /**
187
192
  * Fold an ordered timeline into turns. Pure: no clock, no IO. The rows behind
188
193
  * every prompt, segment and ledger line stay reachable, so the anchors, the