@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
@@ -230,8 +230,21 @@ function thinkingSegment(row, nextAtOf) {
230
230
  spanMs: row.at !== null && next !== null && next > row.at ? next - row.at : null,
231
231
  };
232
232
  }
233
+ /** A row the fold draws nothing for: a turn's end whose outcome is finished.
234
+ * Whoever anchors a line or a count on a row asks this first (`activityCuts`,
235
+ * the tail's arrivals, the sittings), so no line or count is anchored on a
236
+ * finished end. */
237
+ export function drawsNoMarker(row) {
238
+ return row.body.type === "notice" && row.body.notice.type === "turn_ended" &&
239
+ row.body.notice.outcome === "finished";
240
+ }
241
+ /** A notice row's hairline marker. A turn that finished draws none: its reply is
242
+ * there, so the end says nothing more. The fold skips a null segment before it
243
+ * cuts a run, so such a row adds nothing to a run and counts nothing; a cut its
244
+ * caller places on the row (`cutBefore`) still closes the run there. A failed
245
+ * end, a stopped end and an outcome this reader does not know are drawn as ever. */
233
246
  function markerSegment(row) {
234
- if (row.body.type !== "notice")
247
+ if (row.body.type !== "notice" || drawsNoMarker(row))
235
248
  return null;
236
249
  const notice = row.body.notice;
237
250
  return {
@@ -242,6 +255,7 @@ function markerSegment(row) {
242
255
  notice,
243
256
  text: noticeText(notice),
244
257
  tone: notice.type === "runtime_error" ||
258
+ (notice.type === "turn_ended" && notice.outcome === "failed") ||
245
259
  (notice.type === "async_task" && ["failed", "denied", "timed_out"].includes(notice.status))
246
260
  ? "failed"
247
261
  : "plain",
@@ -462,38 +476,68 @@ function buildSegments(rows, nextAtOf, context, cutBefore) {
462
476
  */
463
477
  export function documentTurns(rows, options = {}) {
464
478
  const context = options.context ?? {};
465
- // The next stamped row, for a reasoning segment's span.
479
+ const cutBefore = options.cutBefore ?? NO_CUTS;
480
+ // Rows that extend the last ones folded resume the fold at the last turn
481
+ // they began (2026-11-29, the reader's arrival cost): the turns before it are
482
+ // handed back as they were, so one arriving row reads the turn it joins and
483
+ // not every row of the document. `resumable` says when that is exact.
484
+ const head = rows[0];
485
+ const folds = head === undefined ? undefined : turnFolds.get(head);
486
+ const held = folds?.find((fold) => resumable(fold, rows, options, cutBefore));
487
+ const from = held?.lastStart ?? 0;
488
+ const firstIndex = held?.firstIndex ?? new Map();
489
+ let lastStamped = held?.lastStamped ?? -1;
490
+ for (let index = held?.rows.length ?? 0; index < rows.length; index += 1) {
491
+ const row = rows[index];
492
+ if (!firstIndex.has(row.timeline_id))
493
+ firstIndex.set(row.timeline_id, index);
494
+ if (row.at !== null)
495
+ lastStamped = index;
496
+ }
497
+ // The next stamped row, for a reasoning segment's span: only a reasoning
498
+ // segment reads it, so only the ids of reasoning rows are kept, each from
499
+ // the last row that carries the id (2026-11-29, the reader's arrival cost).
500
+ // A resumed fold reads the rows it folds again: no row before them carries
501
+ // one of their ids, and each row before them has a stamped row after it.
466
502
  const nextAt = new Map();
467
- // index and ahead both stay below rows.length.
468
- const rowAt = (index) => rows[index];
469
- for (let index = 0; index < rows.length; index += 1) {
470
- let found = null;
471
- for (let ahead = index + 1; ahead < rows.length; ahead += 1) {
472
- if (rowAt(ahead).at !== null) {
473
- found = rowAt(ahead).at;
474
- break;
475
- }
503
+ const thinkingIds = new Set();
504
+ for (let index = from; index < rows.length; index += 1) {
505
+ const row = rows[index];
506
+ if (row.body.type === "thinking")
507
+ thinkingIds.add(row.timeline_id);
508
+ }
509
+ if (thinkingIds.size > 0) {
510
+ let following = null;
511
+ for (let index = rows.length - 1; index >= from; index -= 1) {
512
+ const row = rows[index];
513
+ if (thinkingIds.has(row.timeline_id) && !nextAt.has(row.timeline_id))
514
+ nextAt.set(row.timeline_id, following);
515
+ if (row.at !== null)
516
+ following = row.at;
476
517
  }
477
- nextAt.set(rowAt(index).timeline_id, found);
478
518
  }
479
519
  const nextAtOf = (row) => nextAt.get(row.timeline_id) ?? null;
480
520
  // Group the rows into turns, absorbing a command prompt's `command_output`
481
521
  // notice as we go — the pair is one object, decided by adjacency and nothing
482
522
  // else, so the notice never also draws as a marker.
483
- const groups = [];
484
- for (const row of rows) {
523
+ const groups = held === undefined ? [] : held.groups.slice(0, -1);
524
+ let lastStart = held === undefined ? 0 : from;
525
+ for (let index = from; index < rows.length; index += 1) {
526
+ const row = rows[index];
485
527
  if (opensTurn(row, options)) {
486
528
  groups.push({ prompt: row, output: null, body: [] });
529
+ lastStart = index;
487
530
  continue;
488
531
  }
489
532
  const current = groups.at(-1);
490
533
  if (current === undefined) {
491
534
  groups.push({ prompt: null, output: null, body: [row] });
535
+ lastStart = index;
492
536
  continue;
493
537
  }
494
538
  const promptRow = current.prompt;
495
539
  if (promptRow !== null &&
496
- !options.cutBefore?.has(row.timeline_id) &&
540
+ !cutBefore.has(row.timeline_id) &&
497
541
  current.output === null &&
498
542
  current.body.length === 0 &&
499
543
  row.body.type === "notice" &&
@@ -506,57 +550,177 @@ export function documentTurns(rows, options = {}) {
506
550
  }
507
551
  current.body.push(row);
508
552
  }
509
- const turns = [];
510
- let previousPromptAt = null;
511
- let previousHadReply = true;
512
- let previousWasHumanSetting = false;
513
- for (const group of groups) {
514
- const promptRow = group.prompt;
515
- const outputRow = group.output;
516
- const body = group.body;
517
- const prompt = promptRow === null ? null : buildPrompt(promptRow, outputRow);
518
- const segments = buildSegments(body, nextAtOf, context, options.cutBefore ?? new Set());
519
- const agentRows = body.filter(isAgentAuthored);
520
- const head = agentRows.length === 0
521
- ? null
522
- : {
523
- model: agentRows.find((row) => row.model !== null)?.model ?? null,
524
- effort: agentRows.find((row) => row.effort !== null)?.effort ?? null,
525
- tokens: reportedTokens(agentRows),
526
- cost: reportedCost(agentRows),
527
- startedAt: firstStamp(body),
528
- endedAt: lastStamp(body),
529
- spanMs: stampSpan(body),
530
- };
531
- const headIndex = Math.max(0, segments.findIndex((segment) => segment.kind !== "marker" && segment.kind !== "compaction"));
532
- const at = promptRow?.at ?? firstStamp(body);
553
+ const turns = held === undefined ? [] : held.turns.slice(0, -1);
554
+ let state = held === undefined ? FIRST_CLUSTER_STATE : held.beforeLast;
555
+ let beforeLast = state;
556
+ for (let at = turns.length; at < groups.length; at += 1) {
557
+ beforeLast = state;
558
+ const built = builtTurn(groups[at], nextAtOf, context, cutBefore, turns.length);
559
+ const prompt = built.turn.prompt;
533
560
  const clusteredWithPrevious = prompt !== null &&
534
561
  prompt.setting !== null &&
535
562
  !prompt.fromParent &&
536
- previousWasHumanSetting &&
537
- !previousHadReply &&
538
- withinPromptCluster(previousPromptAt, prompt.at);
539
- const allRows = [
540
- ...(prompt === null ? [] : prompt.rows),
541
- ...body,
542
- ];
543
- turns.push({
544
- key: prompt?.key ?? allRows[0]?.timeline_id ?? `turn-${turns.length}`,
563
+ state.previousWasHumanSetting &&
564
+ !state.previousHadReply &&
565
+ withinPromptCluster(state.previousPromptAt, prompt.at);
566
+ if (clusteredWithPrevious)
567
+ built.clustered ??= { ...built.turn, clusteredWithPrevious: true };
568
+ turns.push(clusteredWithPrevious ? built.clustered : built.turn);
569
+ if (prompt !== null) {
570
+ state = {
571
+ previousPromptAt: prompt.at,
572
+ previousHadReply: built.replied,
573
+ previousWasHumanSetting: prompt.setting !== null && !prompt.fromParent,
574
+ };
575
+ }
576
+ }
577
+ if (head !== undefined) {
578
+ const fold = {
579
+ rows: rows.slice(),
580
+ cwd: context.cwd ?? null,
581
+ home: context.home ?? null,
582
+ shared: options.sharedCollaborationSessionIds === undefined ? null : [...options.sharedCollaborationSessionIds],
583
+ cuts: [...cutBefore],
584
+ firstIndex,
585
+ lastStamped,
586
+ lastStart,
587
+ groups,
588
+ turns: turns.slice(),
589
+ beforeLast,
590
+ };
591
+ // Two folds per conversation: its column and its document may fold two
592
+ // chronologies that begin with the same row, one after the other.
593
+ const others = (folds ?? []).filter((fold) => fold !== held).slice(0, 1);
594
+ turnFolds.set(head, [fold, ...others]);
595
+ }
596
+ return turns;
597
+ }
598
+ const NO_CUTS = new Set();
599
+ const FIRST_CLUSTER_STATE = {
600
+ previousPromptAt: null,
601
+ previousHadReply: true,
602
+ previousWasHumanSetting: false,
603
+ };
604
+ /** The last folds of each conversation, by its first row (2026-11-29, the reader's arrival cost). */
605
+ const turnFolds = new WeakMap();
606
+ /**
607
+ * Whether `rows` resume `fold` at its last turn and fold into what a fold of
608
+ * every row makes. The rows begin with every row it read, as the same objects;
609
+ * the options are the same, but for cuts placed on the rows it folds again;
610
+ * no row from its last turn on carries the id of a row before that turn; and a
611
+ * row before that turn has a stamped row after it, so no reasoning span before
612
+ * the last turn moves.
613
+ */
614
+ function resumable(fold, rows, options, cutBefore) {
615
+ const read = fold.rows;
616
+ if (fold.lastStart === 0 || read.length > rows.length || fold.lastStamped < fold.lastStart)
617
+ return false;
618
+ if ((options.context?.cwd ?? null) !== fold.cwd || (options.context?.home ?? null) !== fold.home)
619
+ return false;
620
+ const shared = options.sharedCollaborationSessionIds;
621
+ if (shared === undefined ? fold.shared !== null
622
+ : fold.shared === null || fold.shared.length !== shared.size || !fold.shared.every((id) => shared.has(id))) {
623
+ return false;
624
+ }
625
+ for (let index = read.length - 1; index >= 0; index -= 1)
626
+ if (read[index] !== rows[index])
627
+ return false;
628
+ const before = (id) => {
629
+ const first = fold.firstIndex.get(id);
630
+ return first !== undefined && first < fold.lastStart;
631
+ };
632
+ for (let index = fold.lastStart; index < read.length; index += 1) {
633
+ if (fold.firstIndex.get(read[index].timeline_id) !== index)
634
+ return false;
635
+ }
636
+ for (let index = read.length; index < rows.length; index += 1) {
637
+ if (fold.firstIndex.has(rows[index].timeline_id))
638
+ return false;
639
+ }
640
+ const was = new Set(fold.cuts);
641
+ for (const id of cutBefore)
642
+ if (!was.delete(id) && before(id))
643
+ return false;
644
+ for (const id of was)
645
+ if (before(id))
646
+ return false;
647
+ return true;
648
+ }
649
+ /** Turns kept by their first row (2026-11-29, the reader's arrival cost). A turn
650
+ * is a function of its own rows, the next stamp after each, the cuts among them
651
+ * and the paths' context; rows are replaced, never changed in place, so a turn
652
+ * whose inputs are all the same is handed back as the same object. One arriving
653
+ * row then derives the turn it joins, not the document, and every block drawn
654
+ * from an unchanged turn keeps its identity. */
655
+ const builtTurns = new WeakMap();
656
+ function builtTurn(group, nextAtOf, context, cutBefore, index) {
657
+ const { prompt: promptRow, output: outputRow, body } = group;
658
+ const first = promptRow ?? body[0];
659
+ const cwd = context.cwd ?? null;
660
+ const home = context.home ?? null;
661
+ const key = promptRow?.timeline_id ?? body[0]?.timeline_id ?? `turn-${index}`;
662
+ const held = first === undefined ? undefined : builtTurns.get(first);
663
+ if (held !== undefined && held.output === outputRow && held.key === key && held.cwd === cwd && held.home === home &&
664
+ sameInputs(held, body, nextAtOf, cutBefore)) {
665
+ return held;
666
+ }
667
+ const nextAts = body.map((row) => (row.body.type === "thinking" ? nextAtOf(row) : null));
668
+ const cuts = body.map((row) => cutBefore.has(row.timeline_id));
669
+ const prompt = promptRow === null ? null : buildPrompt(promptRow, outputRow);
670
+ const segments = buildSegments(body, nextAtOf, context, cutBefore);
671
+ const agentRows = body.filter(isAgentAuthored);
672
+ const head = agentRows.length === 0
673
+ ? null
674
+ : {
675
+ model: agentRows.find((row) => row.model !== null)?.model ?? null,
676
+ effort: agentRows.find((row) => row.effort !== null)?.effort ?? null,
677
+ tokens: reportedTokens(agentRows),
678
+ cost: reportedCost(agentRows),
679
+ startedAt: firstStamp(body),
680
+ endedAt: lastStamp(body),
681
+ spanMs: stampSpan(body),
682
+ };
683
+ const headIndex = Math.max(0, segments.findIndex((segment) => segment.kind !== "marker" && segment.kind !== "compaction"));
684
+ const allRows = [
685
+ ...(prompt === null ? [] : prompt.rows),
686
+ ...body,
687
+ ];
688
+ const built = {
689
+ output: outputRow,
690
+ body: [...body],
691
+ nextAts,
692
+ cuts,
693
+ cwd,
694
+ home,
695
+ key,
696
+ replied: agentRows.length > 0,
697
+ clustered: null,
698
+ turn: {
699
+ key: prompt?.key ?? allRows[0]?.timeline_id ?? `turn-${index}`,
545
700
  prompt,
546
701
  head,
547
702
  segments,
548
703
  headIndex,
549
704
  rows: allRows,
550
- at,
551
- clusteredWithPrevious,
552
- });
553
- if (prompt !== null) {
554
- previousPromptAt = prompt.at;
555
- previousHadReply = agentRows.length > 0;
556
- previousWasHumanSetting = prompt.setting !== null && !prompt.fromParent;
557
- }
705
+ at: promptRow?.at ?? firstStamp(body),
706
+ clusteredWithPrevious: false,
707
+ },
708
+ };
709
+ if (first !== undefined)
710
+ builtTurns.set(first, built);
711
+ return built;
712
+ }
713
+ /** The same body rows, each with the same next stamp and the same cut before it. */
714
+ function sameInputs(held, body, nextAtOf, cutBefore) {
715
+ if (held.body.length !== body.length)
716
+ return false;
717
+ for (let index = 0; index < body.length; index += 1) {
718
+ const row = body[index];
719
+ if (held.body[index] !== row || held.cuts[index] !== cutBefore.has(row.timeline_id) ||
720
+ (row.body.type === "thinking" && !Object.is(held.nextAts[index], nextAtOf(row))))
721
+ return false;
558
722
  }
559
- return turns;
723
+ return true;
560
724
  }
561
725
  function firstStamp(rows) {
562
726
  for (const row of rows)
@@ -1,8 +1,15 @@
1
1
  import { useCallback, useLayoutEffect, useRef, useState } from "react";
2
2
  import { REDUCED_MOTION_QUERY, SETTLE_EASING } from "../motion.js";
3
- import { TailArrivals } from "./tail-state.js";
3
+ import { TailArrivals, countedArrivals } from "./tail-state.js";
4
4
  import { TailScroll } from "./tail-scroll.js";
5
5
  const EMPTY = { away: false, unseen: 0 };
6
+ /** Whether a row with this id is drawn, read from the foot, where a row that just arrived is. */
7
+ function drawnFromEnd(rows, id) {
8
+ for (let index = rows.length - 1; index >= 0; index -= 1)
9
+ if (rows[index].timeline_id === id)
10
+ return true;
11
+ return false;
12
+ }
6
13
  export function useTranscriptTail(scrollerRef, sessionId, enabled, seeking, opening = false) {
7
14
  const [state, setState] = useState(EMPTY);
8
15
  const controller = useRef(null);
@@ -41,8 +48,15 @@ export function useTranscriptTail(scrollerRef, sessionId, enabled, seeking, open
41
48
  scroll.update(false, 0);
42
49
  return;
43
50
  }
44
- const displayed = new Set(next.rows.map(row => row.timeline_id));
45
- const fresh = arrivals.update(next.observedRows ?? next.rows).filter(row => displayed.has(row.timeline_id));
51
+ const arrived = arrivals.update(next.observedRows ?? next.rows);
52
+ // Only the arrived rows are looked up, so a set of every drawn row is made
53
+ // only when many arrive at once (2026-11-29, the reader's arrival cost).
54
+ const displayed = arrived.length === 0
55
+ ? new Set()
56
+ : arrived.length > 8
57
+ ? new Set(next.rows.map(row => row.timeline_id))
58
+ : new Set(arrived.filter(row => drawnFromEnd(next.rows, row.timeline_id)).map(row => row.timeline_id));
59
+ const fresh = countedArrivals(arrived, displayed);
46
60
  for (const id of next.readySessionIds)
47
61
  arrivals.prime(id);
48
62
  scroll.update(true, fresh.length, openingRef.current);
@@ -97,7 +97,8 @@ export declare function attachmentLabel(attachment: AttachmentRef): string;
97
97
  export declare function citationLabel(citation: CitationRef): string;
98
98
  /**
99
99
  * Every `Notice` is a hairline marker, never a filled alarm (§03 G). This is
100
- * its one line of text; a `runtime_error` earns red text and nothing more.
100
+ * its one line of text; a `runtime_error` or a failed turn's end earns red
101
+ * text and nothing more.
101
102
  */
102
103
  export declare function noticeText(notice: Notice): string;
103
104
  /**
@@ -206,7 +206,8 @@ export function citationLabel(citation) {
206
206
  }
207
207
  /**
208
208
  * Every `Notice` is a hairline marker, never a filled alarm (§03 G). This is
209
- * its one line of text; a `runtime_error` earns red text and nothing more.
209
+ * its one line of text; a `runtime_error` or a failed turn's end earns red
210
+ * text and nothing more.
210
211
  */
211
212
  export function noticeText(notice) {
212
213
  switch (notice.type) {
@@ -239,6 +240,15 @@ export function noticeText(notice) {
239
240
  }
240
241
  case "runtime_error":
241
242
  return `runtime error · ${notice.kind.replaceAll("_", " ")} · ${notice.summary}`;
243
+ case "turn_ended":
244
+ if (notice.outcome === "failed") {
245
+ return notice.reason ? `turn failed · ${notice.reason}` : "turn failed";
246
+ }
247
+ if (notice.outcome === "stopped")
248
+ return "stopped";
249
+ // An outcome a newer writer names and this reader does not know: say only
250
+ // that the turn ended, never that it finished.
251
+ return notice.outcome === "finished" ? "turn finished" : "turn ended";
242
252
  }
243
253
  }
244
254
  /* ── spans ───────────────────────────────────────────────────────────────── */
@@ -0,0 +1,25 @@
1
+ import type { AssetSource, HostPort, SessionClient } from "./ports.js";
2
+ import type { SessionLeases } from "./lib/session-leases.js";
3
+ import type { RoomStorage } from "./lib/room-storage.js";
4
+ /** The reads a part makes through a session: a stored member's bytes or text. */
5
+ export type PartsClient = Pick<SessionClient, "readAsset" | "readTextAsset">;
6
+ /** What a part asks of a desktop: its copy door and its home directory. */
7
+ export type PartsHost = Pick<HostPort, "copyText" | "homeDir">;
8
+ export interface PartsContext {
9
+ readonly assets: AssetSource;
10
+ /** One lease per session. Under the room, the room's own leases. */
11
+ readonly sessions: SessionLeases<PartsClient>;
12
+ /** Absent: a browser tab, which copies through the page's own clipboard. */
13
+ readonly host: PartsHost | null;
14
+ /** The host's store under the host's prefix. */
15
+ readonly storage: RoomStorage;
16
+ }
17
+ export declare const PartsContext: import("react").Context<PartsContext | null>;
18
+ export declare function useParts(): PartsContext;
19
+ /** The one way a part puts words on the system clipboard: the host's copy
20
+ * door when it has one, else the page's own clipboard. It rejects when either
21
+ * refuses, and the part that asked says so in its receipt. A part mounted
22
+ * outside any provider (a harness) writes the page's clipboard. */
23
+ export declare function useCopyText(): (text: string) => Promise<void>;
24
+ export declare const ReadingSessionProvider: import("react").Provider<string | null>;
25
+ export declare function useReadingSession(): string | null;
@@ -0,0 +1,32 @@
1
+ // What the transcript's shared parts read: the host's asset addresses, the
2
+ // stored members a session's client reads, the host's copy door and home, the
3
+ // host's store, and the session whose words are being read.
4
+ //
5
+ // The room provides it from its own ports (`RoomProvider`), so History draws
6
+ // the parts as it always has. A lighter view with no room around it provides
7
+ // it alone. A part that reads only this never needs the room above it, and
8
+ // never imports the room's own context.
9
+ import { createContext, useCallback, useContext } from "react";
10
+ export const PartsContext = createContext(null);
11
+ export function useParts() {
12
+ const parts = useContext(PartsContext);
13
+ if (parts === null) {
14
+ throw new Error("The transcript's parts read their ports from <PartsContext>, which <HistoryRoom> and <RoomProvider> provide.");
15
+ }
16
+ return parts;
17
+ }
18
+ /** The one way a part puts words on the system clipboard: the host's copy
19
+ * door when it has one, else the page's own clipboard. It rejects when either
20
+ * refuses, and the part that asked says so in its receipt. A part mounted
21
+ * outside any provider (a harness) writes the page's clipboard. */
22
+ export function useCopyText() {
23
+ const host = useContext(PartsContext)?.host ?? null;
24
+ return useCallback((text) => host?.copyText !== undefined ? host.copyText(text) : navigator.clipboard.writeText(text), [host]);
25
+ }
26
+ /** The session whose document is being read here. Reads that name no session
27
+ * of their own — a stored text member, an attachment's bytes — ride its client. */
28
+ const ReadingSessionContext = createContext(null);
29
+ export const ReadingSessionProvider = ReadingSessionContext.Provider;
30
+ export function useReadingSession() {
31
+ return useContext(ReadingSessionContext);
32
+ }
package/dist/ports.d.ts CHANGED
@@ -122,6 +122,26 @@ export interface GitWorktree {
122
122
  readonly path: string;
123
123
  /** Absent on a detached HEAD. */
124
124
  readonly branch: string | null;
125
+ /** The commit it has checked out, as git names it (a hex object id). What
126
+ * a checkout with no branch is told apart by. Absent: the host does not
127
+ * say; null: git named none (an unborn branch). */
128
+ readonly head?: string | null | undefined;
129
+ /** git still lists it, and its folder is gone (`prunable`). */
130
+ readonly gone?: boolean | undefined;
131
+ /** What the folder holds on disk, as a walk of it counts: everything under
132
+ * it, ignored files and build output included. It is NOT what removing the
133
+ * worktree would free (files cloned from a package store share their
134
+ * blocks), and a linked folder is not followed. Here it is the figure the
135
+ * host ALREADY holds (kept from an earlier walk); git facts start no walk.
136
+ * A figure the host does not hold is asked for by name, for the rows on
137
+ * screen only (`WorktreeHostPort.worktreeSizes`). */
138
+ readonly sizeBytes?: number | null | undefined;
139
+ }
140
+ /** One asked worktree's figure: bytes; null while the host is walking the
141
+ * folder (ask again shortly); absent when no figure can be had. */
142
+ export interface WorktreeSize {
143
+ readonly path: string;
144
+ readonly sizeBytes?: number | null | undefined;
125
145
  }
126
146
  /** Read-only git facts for one root. Every field is nullable because a folder
127
147
  * without a repository is a fact, not a failure: the room says less rather
@@ -177,6 +197,13 @@ export interface WorktreeHostPort {
177
197
  /** Branch · dirty count · worktrees for the open root, or null when the
178
198
  * folder is not a repository. */
179
199
  gitFacts(root: string, generation: number): Promise<GitFacts | null>;
200
+ /** What these worktrees of the open root's repository hold on disk, in the
201
+ * order asked. Asking is what makes a host walk a folder, and a walk is
202
+ * work: the room names only the rows it is showing, each ask REPLACES what
203
+ * the last one was owed, and a host keeps what it measured so that the next
204
+ * opening walks nothing. Absent: this host measures nothing, and the list
205
+ * draws no figure it was not given. */
206
+ worktreeSizes?(root: string, generation: number, paths: readonly string[]): Promise<readonly WorktreeSize[]>;
180
207
  /** Copy absolute path text or reveal one entry in the native file manager. */
181
208
  fileAction(request: WorktreeFileActionRequest): Promise<WorktreeFileActionResult>;
182
209
  /** The engine's events. A host replays what arrived before the room
@@ -205,6 +232,12 @@ export interface HostPort {
205
232
  artifactThumbnail?(html: string): Promise<string | null>;
206
233
  /** Re-read installed browsers. Absent on hosts with only a default action. */
207
234
  browsers?(): Promise<readonly InstalledBrowser[]>;
235
+ /** Put words on the system clipboard through the desktop's own copy door.
236
+ * A host whose page may not write the clipboard itself (a shell that grants
237
+ * its window no clipboard permission) gives this, and every copy the room
238
+ * makes goes through it; it rejects when the copy is refused. Absent: the
239
+ * room writes the page's clipboard, as a browser tab does. */
240
+ copyText?(text: string): Promise<void>;
208
241
  /** One site's own icon as an image URL, or null for every honest no — a
209
242
  * refused host, no icon, a timeout. The room draws the globe for all. */
210
243
  favicon(host: string): Promise<string | null>;
@@ -247,6 +280,9 @@ export interface AssetSource {
247
280
  * `attachmentAssetUrl` stays the member's identity and is never loaded.
248
281
  */
249
282
  mediaAssetUrl?(asset: AssetRef): AssetUrl;
283
+ /** True: `mediaAssetUrl` honours byte ranges and may be asked BEFORE play, to draw a video's first frame from a
284
+ * `<video preload="metadata">`. Absent or false: asked only on play, as today. */
285
+ readonly mediaFirstFrame?: boolean;
250
286
  }
251
287
  /** Everything a host hands the room. */
252
288
  export interface IngestionPort {
@@ -55,7 +55,6 @@ export declare function useRoom(): Room;
55
55
  export declare function useRoomOverlay(open: boolean): void;
56
56
  /** Whether any of the room's dialogs is open. */
57
57
  export declare function useRoomOverlayOpen(): boolean;
58
+ export { ReadingSessionProvider, useCopyText, useReadingSession } from "./parts-context.js";
58
59
  /** Where the room portals its dialogs: the host's container, or the body. */
59
60
  export declare function useRoomPortal(): HTMLElement | undefined;
60
- export declare const ReadingSessionProvider: import("react").Provider<string | null>;
61
- export declare function useReadingSession(): string | null;
@@ -1,7 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // The ports, as the room's parts read them. `HistoryRoom` provides them; a
3
- // harness that mounts one column on its own wraps it in `RoomProvider`.
3
+ // harness that mounts one column on its own wraps it in `RoomProvider`. The
4
+ // room also provides the transcript's shared parts their own context
5
+ // (`PartsContext`) from the same values, so a part that reads only that one
6
+ // draws the same here as under a view with no room around it.
4
7
  import { createContext, useContext, useEffect, useMemo, useSyncExternalStore } from "react";
8
+ import { PartsContext } from "./parts-context.js";
5
9
  import { createSessionLeases } from "./lib/session-leases.js";
6
10
  import { createFaviconStore } from "./lib/transcript/favicons.js";
7
11
  import { browserStorage, createRoomStorage, DEFAULT_STORAGE_PREFIX } from "./lib/room-storage.js";
@@ -55,7 +59,8 @@ export function RoomProvider({ ports, options = {}, children, }) {
55
59
  catalog, sessions, assets, ingestion, host, initialSummaryTab, favicons, portalContainer, overlays,
56
60
  storage, tints, fold,
57
61
  }), [catalog, sessions, assets, ingestion, host, initialSummaryTab, favicons, portalContainer, overlays, storage, tints, fold]);
58
- return _jsx(RoomContext.Provider, { value: room, children: children });
62
+ const parts = useMemo(() => ({ assets, sessions, host, storage }), [assets, sessions, host, storage]);
63
+ return (_jsx(RoomContext.Provider, { value: room, children: _jsx(PartsContext.Provider, { value: parts, children: children }) }));
59
64
  }
60
65
  export function useRoom() {
61
66
  const room = useContext(RoomContext);
@@ -75,14 +80,11 @@ export function useRoomOverlayOpen() {
75
80
  const { overlays } = useRoom();
76
81
  return useSyncExternalStore(overlays.subscribe, () => overlays.count() > 0, () => false);
77
82
  }
83
+ // The room's one way to put words on the system clipboard, and the session
84
+ // being read here, live beside the parts that read them; the room's own parts
85
+ // keep importing them from here.
86
+ export { ReadingSessionProvider, useCopyText, useReadingSession } from "./parts-context.js";
78
87
  /** Where the room portals its dialogs: the host's container, or the body. */
79
88
  export function useRoomPortal() {
80
89
  return useContext(RoomContext)?.portalContainer ?? undefined;
81
90
  }
82
- /** The session whose document is being read here. Reads that name no session
83
- * of their own — a stored text member, an attachment's bytes — ride its client. */
84
- const ReadingSessionContext = createContext(null);
85
- export const ReadingSessionProvider = ReadingSessionContext.Provider;
86
- export function useReadingSession() {
87
- return useContext(ReadingSessionContext);
88
- }