samagotchi 0.169.0 → 0.171.0

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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -1
  3. data/docs/architecture.md +2 -2
  4. data/docs/cli.md +37 -23
  5. data/docs/configuration.md +1 -1
  6. data/docs/internals/block-renderers.md +2 -2
  7. data/docs/internals/bridge.md +9 -5
  8. data/docs/internals/context-telemetry.md +13 -1
  9. data/docs/internals/engine.md +4 -4
  10. data/docs/internals/inline-widgets.md +1 -1
  11. data/docs/internals/objectives.md +1 -1
  12. data/docs/internals/participants.md +235 -119
  13. data/docs/internals/web-frontend.md +173 -39
  14. data/docs/internals/working-set.md +71 -6
  15. data/docs/releasing.md +5 -2
  16. data/docs/sessions.md +6 -3
  17. data/docs/testing.md +10 -5
  18. data/lib/samagotchi/bridge/turn_accumulator.rb +8 -4
  19. data/lib/samagotchi/bridge.rb +53 -13
  20. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  21. data/lib/samagotchi/delivery.rb +13 -0
  22. data/lib/samagotchi/engine/events.rb +9 -0
  23. data/lib/samagotchi/engine.rb +6 -2
  24. data/lib/samagotchi/event_fanout.rb +25 -7
  25. data/lib/samagotchi/grants.rb +5 -0
  26. data/lib/samagotchi/guardrails/review_paths.rb +2 -2
  27. data/lib/samagotchi/image_store.rb +51 -12
  28. data/lib/samagotchi/kernel_loop.rb +7 -1
  29. data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
  30. data/lib/samagotchi/llm_context_stale.rb +4 -1
  31. data/lib/samagotchi/participant_messages.rb +39 -0
  32. data/lib/samagotchi/participant_revise.rb +61 -0
  33. data/lib/samagotchi/participant_uploads.rb +98 -0
  34. data/lib/samagotchi/reply_wait/poll.rb +5 -1
  35. data/lib/samagotchi/revise_anchor.rb +9 -0
  36. data/lib/samagotchi/send_command.rb +5 -0
  37. data/lib/samagotchi/session_inbox.rb +20 -12
  38. data/lib/samagotchi/session_manager/delivery.rb +7 -0
  39. data/lib/samagotchi/session_stores.rb +2 -0
  40. data/lib/samagotchi/tool_runner.rb +39 -5
  41. data/lib/samagotchi/tools/memory.rb +26 -7
  42. data/lib/samagotchi/turn_anchors.rb +0 -3
  43. data/lib/samagotchi/turn_stages/verify_anchors.rb +13 -1
  44. data/lib/samagotchi/verify_anchor.rb +6 -0
  45. data/lib/samagotchi/version.rb +1 -1
  46. data/lib/samagotchi/web/app.rb +42 -62
  47. data/lib/samagotchi/web/participant_access.rb +129 -26
  48. data/lib/samagotchi/web/participant_images.rb +185 -0
  49. data/lib/samagotchi/web/participant_review.rb +19 -138
  50. data/lib/samagotchi/web/participant_show.rb +240 -0
  51. data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
  52. data/lib/samagotchi/web/participant_view.rb +331 -24
  53. data/lib/samagotchi/web/public/annotate_bar.css +1 -2
  54. data/lib/samagotchi/web/public/annotate_bar.js +1 -2
  55. data/lib/samagotchi/web/public/app.js +125 -88
  56. data/lib/samagotchi/web/public/block_host.js +7 -4
  57. data/lib/samagotchi/web/public/bubbles.js +9 -1
  58. data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
  59. data/lib/samagotchi/web/public/chip_popover.js +5 -4
  60. data/lib/samagotchi/web/public/claim_link.js +4 -4
  61. data/lib/samagotchi/web/public/composer.css +4 -6
  62. data/lib/samagotchi/web/public/composer_mode.js +11 -6
  63. data/lib/samagotchi/web/public/composer_mount.js +4 -4
  64. data/lib/samagotchi/web/public/ctx.js +12 -3
  65. data/lib/samagotchi/web/public/delivery_line.js +34 -5
  66. data/lib/samagotchi/web/public/history_shape.js +5 -1
  67. data/lib/samagotchi/web/public/images.js +7 -1
  68. data/lib/samagotchi/web/public/index.html +49 -4
  69. data/lib/samagotchi/web/public/info_bar_model.js +2 -1
  70. data/lib/samagotchi/web/public/live_timing.js +5 -3
  71. data/lib/samagotchi/web/public/markdown_place.js +5 -4
  72. data/lib/samagotchi/web/public/owner_claim.js +3 -3
  73. data/lib/samagotchi/web/public/owner_verify.js +0 -2
  74. data/lib/samagotchi/web/public/participant_bar.js +108 -0
  75. data/lib/samagotchi/web/public/participant_main.js +289 -0
  76. data/lib/samagotchi/web/public/participant_model.js +5 -292
  77. data/lib/samagotchi/web/public/participant_names.js +6 -1
  78. data/lib/samagotchi/web/public/participant_revise.js +66 -0
  79. data/lib/samagotchi/web/public/participants_panel.js +3 -12
  80. data/lib/samagotchi/web/public/question_cards.js +24 -4
  81. data/lib/samagotchi/web/public/refs.js +53 -36
  82. data/lib/samagotchi/web/public/reload_check.js +68 -11
  83. data/lib/samagotchi/web/public/revise_stack.js +21 -10
  84. data/lib/samagotchi/web/public/send_turn.js +24 -6
  85. data/lib/samagotchi/web/public/session_fields.js +1 -1
  86. data/lib/samagotchi/web/public/session_state.js +12 -4
  87. data/lib/samagotchi/web/public/session_sync.js +9 -2
  88. data/lib/samagotchi/web/public/session_view.js +17 -7
  89. data/lib/samagotchi/web/public/stage_asking.js +6 -4
  90. data/lib/samagotchi/web/public/stage_frame.js +3 -3
  91. data/lib/samagotchi/web/public/stage_model.js +12 -5
  92. data/lib/samagotchi/web/public/stage_opened.js +8 -5
  93. data/lib/samagotchi/web/public/stage_owner_wait.js +35 -0
  94. data/lib/samagotchi/web/public/stage_view.js +54 -17
  95. data/lib/samagotchi/web/public/stage_waiting.js +74 -6
  96. data/lib/samagotchi/web/public/storage.js +22 -0
  97. data/lib/samagotchi/web/public/stream_handlers.js +2 -1
  98. data/lib/samagotchi/web/public/tokens.css +1 -1
  99. data/lib/samagotchi/web/public/turn_block.js +3 -2
  100. data/lib/samagotchi/web/public/turn_events.js +15 -6
  101. data/lib/samagotchi/web/public/turn_html.js +9 -2
  102. data/lib/samagotchi/web/public/turn_range.js +1 -2
  103. data/lib/samagotchi/web/public/verify_target.js +2 -4
  104. data/lib/samagotchi/web/public/viewer.js +59 -0
  105. data/lib/samagotchi/web/public/viewer_self.js +53 -0
  106. data/lib/samagotchi/web/public/working_set.js +11 -5
  107. data/lib/samagotchi/web/public/working_set_view.js +53 -8
  108. data/lib/samagotchi/web/public/ws_cards.js +89 -0
  109. data/lib/samagotchi/web/public/ws_peek.js +106 -0
  110. data/lib/samagotchi/web/public/ws_preview.css +126 -0
  111. data/lib/samagotchi/web/public/ws_reader.js +319 -0
  112. data/lib/samagotchi/web/public/ws_timeline.js +200 -0
  113. data/lib/samagotchi/web/public/ws_way_in.js +25 -0
  114. data/lib/samagotchi/web/session_control.rb +42 -15
  115. data/lib/samagotchi/web/session_create.rb +1 -1
  116. data/lib/samagotchi/web/session_hub.rb +16 -0
  117. data/lib/samagotchi/web/session_show.rb +75 -28
  118. data/lib/samagotchi/web/viewer.rb +70 -0
  119. data/lib/samagotchi/web/working_set_routes.rb +132 -0
  120. data/lib/samagotchi/worker.rb +19 -14
  121. data/lib/samagotchi/working_set.rb +260 -8
  122. metadata +20 -6
  123. data/lib/samagotchi/web/public/participant.html +0 -218
  124. data/lib/samagotchi/web/public/participant.js +0 -719
  125. data/lib/samagotchi/web/public/participant_annotate.js +0 -76
  126. data/lib/samagotchi/web/public/review_history.js +0 -72
  127. data/lib/samagotchi/web/public/tools_overview.js +0 -42
@@ -16,12 +16,14 @@
16
16
  // liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip
17
17
  // the page's views
18
18
  // workingSet the stage view's working set (web.working_set), null when off
19
+ // wsPreview its reader and peek (ws_reader.js), null without them: reset with the session
19
20
  // gapClock the page's last activity (time_gaps.js createGapClock)
20
21
  // bubbles, cards bubbles.js, cards_place.js
21
22
  // markdown markdown_place.js (linkTextRefs, applyFinalMarkdown)
22
23
  // capabilities() the page's capabilities (card.js shownElsewhere, the history's cards)
24
+ // can(name) the viewer's (viewer.js): the history's Apply row needs apply
23
25
  // page: {setReviseAnchor(anchor), renderInitRow(), setMarkdownWarning(warning),
24
- // setCapabilities(capabilities, editorUrl), findInTurnRoots(selector), appendToHistory(el),
26
+ // setCapabilities(capabilities, editorUrl, viewer), findInTurnRoots(selector), appendToHistory(el),
25
27
  // setTurnRunning(running), mergeTurnTiming(id, timing), applySessionPayload(data, opts),
26
28
  // turnEndStatus(data), replaceSelectedCard(change)} the page's hooks
27
29
  // later: {handlers(), composer(), ownerVerify(), commandList(), initTasks(), resetTurnView()}
@@ -35,7 +37,7 @@ import { seedInitTasks } from "./init_row.js";
35
37
  import { restoreCommandBubbles } from "./commands.js";
36
38
  import { failedTurnText, normalize } from "./format.js";
37
39
  import { splitSnapshotCards } from "./card.js";
38
- import { turnGroups } from "./timing.js";
40
+ import { turnGroups, normalizeTiming } from "./timing.js";
39
41
  import { groupItems } from "./working_set_view.js";
40
42
  import { thumbsTemplate } from "./images.js";
41
43
  import { hintEl, outputBubbleTemplate } from "./bubbles.js";
@@ -47,8 +49,8 @@ import { stillOn } from "./latest.js";
47
49
  export function createSessionView(deps) {
48
50
  const {
49
51
  store, historyEl, getSession,
50
- liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet = null, gapClock,
51
- bubbles, cards, markdown, capabilities, page, later,
52
+ liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet = null, wsPreview = null, gapClock,
53
+ bubbles, cards, markdown, capabilities, can = () => true, page, later,
52
54
  } = deps;
53
55
  const { makeUserBubble, addEndBubble, showGuardrailWarning, showRecap } = bubbles;
54
56
  const { placeSnapshotCards, upsertCard } = cards;
@@ -84,6 +86,9 @@ export function createSessionView(deps) {
84
86
  markdownTip.show(null);
85
87
  setCapabilities(null, null);
86
88
  later.composer().newVisit();
89
+ // The reader and the peek are the session's: another one (or none, the
90
+ // start page) never finds them over #center, the composer inert under it.
91
+ if (!keepVerify) wsPreview?.reset();
87
92
  }
88
93
 
89
94
  // A session view: its messages, then the turn in progress and the queued
@@ -92,7 +97,7 @@ export function createSessionView(deps) {
92
97
  function renderSessionView(data, { kept = [] } = {}) {
93
98
  setMarkdownWarning(data.markdown_warning);
94
99
  markdownTip.show(data.markdown_tip);
95
- setCapabilities(data.capabilities, data.editor_url);
100
+ setCapabilities(data.capabilities, data.editor_url, data.viewer);
96
101
  // The saved fill (when there is one) goes in here too, so a reloaded or
97
102
  // stopped session shows it before its next turn (a running turn's replay
98
103
  // below streams over it).
@@ -195,7 +200,12 @@ export function createSessionView(deps) {
195
200
  // (its prompt has no drawing yet: a plain row, no miss).
196
201
  const historyOpts = (data = {}) => ({ thumbs: (images) => thumbsTemplate(store.selected, images), workingSet: !!workingSet,
197
202
  drawings: data.turn_drawings || null, cards: data.cards || null, capabilities: capabilities(),
198
- runningTurnId: data.current_turn?.turn_id || null });
203
+ runningTurnId: data.current_turn?.turn_id || null, apply: can("apply") });
204
+
205
+ // A read drawn the way a reload draws it: the turn blocks only, nothing
206
+ // placed after them (the opt-in reload check, reload_check.js, compares
207
+ // this with what the page has, offscreen).
208
+ const reloadRender = (data = {}) => turnHistoryNodes(data.messages || [], normalizeTiming(data.timing), historyOpts(data));
199
209
 
200
210
  function renderHistory(items, data = {}) {
201
211
  gapClock.seed(null);
@@ -275,5 +285,5 @@ export function createSessionView(deps) {
275
285
  if (questionCards.pendingQuestion()) questionCards.resolveQuestion(questionCards.pendingQuestion().id, { cancelled: true, reason: "turn ended" });
276
286
  }
277
287
 
278
- return { forgetSession, renderSessionView, historyOpts, readTurnEnd, endTurnView };
288
+ return { forgetSession, renderSessionView, historyOpts, reloadRender, readTurnEnd, endTurnView };
279
289
  }
@@ -43,10 +43,12 @@ export function createStageAsking({
43
43
  // A ref's "show in turn" opened a collapsed stage (not kept).
44
44
  let revealed = false;
45
45
  // The docked card's fold is +waiting+'s (fold, trackFold): the waiting
46
- // card the user folded, by its key. For that card only, never saved: the
47
- // next one arrives open, and when the docked card goes the stage is as the
48
- // choice and +revealed+ say. One more card waiting since the fold (an
49
- // approval, a relayed or hook question) drops it, so the stage opens on it.
46
+ // card the user folded, by its key — kept for this tab (stage_waiting.js,
47
+ // chi_asking_fold:<session>), so a reload or a resync mid-turn folds that
48
+ // card again. For that card only: the next one arrives open, and when the
49
+ // docked card goes the stage is as the choice and +revealed+ say. One more
50
+ // card waiting since the fold (an approval, a relayed or hook question)
51
+ // drops it, so the stage opens on it.
50
52
 
51
53
  // ── the docked card ──────────────────────────────────────────────────────
52
54
 
@@ -3,9 +3,9 @@
3
3
  // ~60% of the page (~80% with the cloud open, 85% from a tall approval
4
4
  // until the next step), and never above the session panel. The frame: held
5
5
  // and grow-only while the stage holds a turn (stage_model.js frameTarget),
6
- // its growth eased; it lets go in two places only (forgetContent): the
7
- // asking form (a card docked, its turn opened in the history: the card
8
- // alone, stage_view.js place) and the next step after an answered card (releaseHeldWait). The stage's state comes
6
+ // its growth eased; it lets go when a card docks (stage_view.js place), or
7
+ // after an answer leaves a card in front or at the next step
8
+ // (stage_view.js releaseHeldWait). The stage's state comes
9
9
  // in as getters (+isHolding+, +isCollapsed+, +isCloudOpen+, +isRoomCap+);
10
10
  // what the stage changes of the frame's goes through resetHeld and
11
11
  // forgetContent. +waitingCard+: the card blocking the turn, or null.
@@ -9,6 +9,7 @@ import { hookNoticeLabel } from "./turn_events.js";
9
9
  import { plainLine } from "./plain_line.js";
10
10
  import { turnPieces } from "./turn_pieces.js";
11
11
  import { waitsInStage } from "./stage_cards.js";
12
+ import { clockText } from "./delivery_line.js";
12
13
 
13
14
  const READ_LIKE = new Set(["read", "memory_read", "web_fetch", "task_get", "task_list", "list_sessions"]);
14
15
  const EDITS = new Set(["edit", "write", "memory_write"]);
@@ -146,10 +147,12 @@ export function miniToolText({ collapsed, tool }) {
146
147
  // the hover, in the UI font: +question+ true), else miniToolText's running
147
148
  // call: folded, or with +running+ (check-in docked while nothing blocks:
148
149
  // the row says what chi runs now).
149
- export function foldedRowText({ collapsed, question = "", tool = null, running = false }) {
150
+ export function foldedRowText({ collapsed, question = "", tool = null, running = false, now = Date.now() }) {
150
151
  const whole = String(question || "").trim();
151
152
  if (collapsed && whole) return { text: whole.split("\n")[0].trim(), title: whole, question: true };
152
- return { ...miniToolText({ collapsed: collapsed || running, tool }), question: false };
153
+ const row = miniToolText({ collapsed: collapsed || running, tool });
154
+ const clock = running && tool?.startedAt != null ? clockText((now - tool.startedAt) / 1000) : "";
155
+ return { ...row, ...(clock ? { clock } : {}), question: false };
153
156
  }
154
157
 
155
158
  // The status row's word while check-in's card is docked and nothing blocks
@@ -218,7 +221,10 @@ export function liveSlots(turn, { narration = "", thinking = "", pending = false
218
221
  step: ended ? gens.filter((g) => !g.answer || g.thinking || g.tools.length).length : gens.length,
219
222
  headline,
220
223
  quiet: ended ? "" : current?.text && !current.textDone ? "writing…" : "thinking…",
221
- tool: running ? withTask(withCommand({ name: toolName(running), title: rowTitle(running), kind: toolKind(running.tool) }, running), running) : null,
224
+ tool: running ? withTask(withCommand({
225
+ name: toolName(running), title: rowTitle(running), kind: toolKind(running.tool),
226
+ ...(running.startedAt != null ? { startedAt: running.startedAt } : {}),
227
+ }, running), running) : null,
222
228
  trail,
223
229
  ticks: rows.map(({ row, step }) => ({ kind: toolKind(row.tool), status: row.status, step })),
224
230
  };
@@ -226,8 +232,9 @@ export function liveSlots(turn, { narration = "", thinking = "", pending = false
226
232
 
227
233
  // The stage's frame height (px) while it holds a turn: grow-only, so a
228
234
  // content change inside it (the plain flip, an answered card, a short
229
- // answer) never moves its top edge. (Its one shrink forgets +held+: the next
230
- // step after an answered card, stage_view.js releaseHeldWait.) +natural+: its content's own height;
235
+ // answer) never moves its top edge. The answer shrink forgets +held+ when
236
+ // another docked card remains, or at the next step after an answered card
237
+ // (stage_view.js releaseHeldWait). +natural+: its content's own height;
231
238
  // +held+: the height it holds (null: none yet); +cap+: --stage-max. A lower
232
239
  // cap (a phone's keyboard) clamps it at once and the clamp is the new held
233
240
  // height: a cap that rises again doesn't bring the old one back, only new
@@ -186,14 +186,17 @@ export function createOpenedTurn({
186
186
  if (bubble && !card.querySelector(":scope > summary > .question-reason-link")) reasonLink(card, bubble);
187
187
  },
188
188
  // +card+ (its +key+) no longer waits (answered, cancelled): it goes right
189
- // under its reason, which stops saying "asking you"; another card of the
190
- // turn to the history's end. A reader at the end follows.
191
- settle(key, card) {
189
+ // under its reason, which stops saying "asking you"; if it was replaced
190
+ // and removed, only the reason is settled. A reader at the end follows.
191
+ settle(key, card = null) {
192
192
  const bubble = reasons.get(key);
193
- if (!bubble?.isConnected) return add([card]);
193
+ if (!bubble?.isConnected) {
194
+ if (card) add([card]);
195
+ return;
196
+ }
194
197
  const follow = atHistoryEnd();
195
198
  bubble.classList.remove("pending");
196
- bubble.after(card);
199
+ if (card?.isConnected) bubble.after(card);
197
200
  if (follow) scrollTo();
198
201
  },
199
202
  // The turn's steps block (or one of its steps, +el+) in the history:
@@ -0,0 +1,35 @@
1
+ // The stage's look while a participant's view of the running turn waits for
2
+ // the owner (the participant main page, scene 3): the status row says
3
+ // "waiting for the owner" and one line under the live slots names what
4
+ // kind of thing they are asked (an approval, a question, a continue
5
+ // offer), never its content; no card. chi web sends the kind alone
6
+ // (ParticipantView.waiting_kind: question_requested / continue_offered's
7
+ // `kind`, the show's current_turn and viewer.waiting_for_owner).
8
+ // stage_view.js draws it at each refresh from its +ownerWait+ hook; the
9
+ // owner's page passes none (its cards are the waiting look).
10
+
11
+ export const OWNER_WAIT_STATUS = "waiting for the owner";
12
+
13
+ // The line per kind; a kind the page doesn't know reads as a question.
14
+ export const OWNER_WAIT_TEXT = Object.freeze({
15
+ approval: "chi wants to run a command that needs the owner's approval. The turn continues when they answer.",
16
+ question: "chi asked the owner a question. The turn continues when they answer.",
17
+ continue: "chi asks the owner whether to go on. The turn continues when they answer.",
18
+ });
19
+
20
+ export const ownerWaitText = (kind) => OWNER_WAIT_TEXT[kind] || OWNER_WAIT_TEXT.question;
21
+
22
+ // +stage+ the stage's root, +line+ the line's node (stage_view.js makes it
23
+ // after the live slots), +phaseEl+ the status row's phase.
24
+ // @return draw(kind): kind null (not waiting) puts the stage back
25
+ export function createOwnerWait({ stage, line, phaseEl }) {
26
+ line.hidden = true;
27
+ return function draw(kind) {
28
+ stage.classList.toggle("owner-wait", !!kind);
29
+ line.hidden = !kind;
30
+ if (!kind) return;
31
+ phaseEl.textContent = OWNER_WAIT_STATUS;
32
+ const text = ownerWaitText(kind);
33
+ if (line.textContent !== text) line.textContent = text;
34
+ };
35
+ }
@@ -37,8 +37,9 @@ import { createOpenedTurn } from "./stage_opened.js";
37
37
  import { askingRefs } from "./turn_model.js";
38
38
  import { ASKS, PENDING } from "./stage_cards.js";
39
39
  import { createStageAsking } from "./stage_asking.js";
40
- import { createStageWaiting, isApprovalCard, isBlocking, waitingKey, waitingKind } from "./stage_waiting.js";
40
+ import { cardIn, createStageWaiting, isApprovalCard, isBlocking, waitingKey, waitingKind } from "./stage_waiting.js";
41
41
  import { stampRows } from "./working_set_view.js";
42
+ import { createOwnerWait } from "./stage_owner_wait.js";
42
43
 
43
44
  // The turn-end read (markdown, answer_display) settles within this, or the
44
45
  // hand-off stops waiting for it.
@@ -71,10 +72,14 @@ const OPENING = "[data-turn-id], [data-opening-id]";
71
72
  // The quiet signal's inputs (stage_stall.js): +clock+() the page's time,
72
73
  // +streamLive+() the session's stream is open, +timingNote+() what the turn
73
74
  // waits on (live_timing.js note), +serverGen+() a joiner's generation.
75
+ // +canCancel+() whether this turn's Stop turn shows (a participant's own
76
+ // turn only); +ownerWait+() the kind a participant's view waits for the
77
+ // owner on, or null (stage_owner_wait.js).
74
78
  export function createStageView({
75
79
  historyEl, isNearBottom: historyNearBottom, sawText, sessionId, dockEl, centerEl, taskStop = null,
76
80
  renderMarkdown, linkRefs, workingSet = null, onCancel = null, onHandedOff = null,
77
81
  clock = () => Date.now(), streamLive = () => true, timingNote = () => "", serverGen = () => null,
82
+ canCancel = () => true, ownerWait = () => null,
78
83
  }) {
79
84
  // The dock becomes a clear column: the stage's card, then the composer's
80
85
  // (its rows moved into .dock-card, which wears the glass and the focus ring).
@@ -135,6 +140,8 @@ export function createStageView({
135
140
  headline.tabIndex = 0;
136
141
  headline.setAttribute("role", "button");
137
142
  headline.title = "Show this step's reasoning";
143
+ // A participant's turn waiting for the owner: one line under the headline, no card.
144
+ const drawOwnerWait = createOwnerWait({ stage, line: node("div", "ts-owner-wait", live), phaseEl });
138
145
  const now = node("div", "ts-now", live);
139
146
  const trail = node("div", "ts-trail", live);
140
147
  // The working set's rail: out of the live slots' flow on their right (a
@@ -259,8 +266,10 @@ export function createStageView({
259
266
  });
260
267
 
261
268
  // The cards that wait in the stage, as data (stage_waiting.js): the
262
- // docked card, its fold, what blocks, the approval's cap read them.
263
- const waiting = createStageWaiting();
269
+ // docked card, its fold, what blocks, the approval's cap read them. The
270
+ // fold of the asking card is this tab's own, kept per session.
271
+ const waiting = createStageWaiting({ sessionId });
272
+ let dockedAtLastRefresh = [];
264
273
  // The asking form and the stage's fold (stage_asking.js).
265
274
  const ask = createStageAsking({
266
275
  stage, extras, tail, scroller, fold, view, opener, frame: () => frame, isOpened: () => opened, setOpened,
@@ -402,18 +411,22 @@ export function createStageView({
402
411
  const slots = liveSlots(turn, { narration, thinking, pending: blocked || asksCard(), ended: endKind, emptyAnswer });
403
412
 
404
413
  // The live slots keep their height while the turn waits and until its
405
- // next step (held-wait, set with waiting): the card under them never
406
- // moves at the answer. The waiting height is measured before the swap.
414
+ // next step, unless answering leaves another docked card to fit. The
415
+ // waiting height is measured before the swap.
407
416
  const wasWaiting = stage.classList.contains("waiting");
417
+ const docked = waiting.docked();
418
+ const answeredWithCardLeft = dockedAtLastRefresh.some((key) => !docked.includes(key)) && docked.length > 0;
419
+ dockedAtLastRefresh = docked;
408
420
  if (blocked && !wasWaiting) {
409
421
  stage.classList.add("held-wait");
410
422
  }
411
423
  if (!blocked && wasWaiting) stage.style.setProperty("--live-held", `${live.offsetHeight}px`);
412
424
  stage.classList.toggle("plain", plain);
413
425
  stage.classList.toggle("ended", !!endKind);
414
- cancel.hidden = !onCancel || !!endKind;
426
+ cancel.hidden = !onCancel || !canCancel() || !!endKind;
415
427
  stage.classList.toggle("waiting", blocked);
416
428
  if (!blocked && wasWaiting) settleAnsweredCard();
429
+ if (answeredWithCardLeft && !blocked) releaseHeldWait();
417
430
  stage.dataset.phase = slots.phase;
418
431
  mark.textContent = MARKS[slots.phase] || "";
419
432
  // check-in docked, nothing blocking: the row says what chi does now (the
@@ -422,6 +435,7 @@ export function createStageView({
422
435
  const asksFront = !!asking && !blocked && !endKind && waiting.get(waiting.front())?.kind === "asks";
423
436
  const streaming = asksFront ? liveSlots(turn).phase : "";
424
437
  phaseEl.textContent = phaseLabel({ phase: slots.phase, asksFront, streaming });
438
+ drawOwnerWait(endKind ? null : ownerWait());
425
439
  stage.classList.toggle("asks-live", asksFront);
426
440
  drawAsksText(asksFront && gen?.text && !gen.answer ? String(gen.text).trim() : "");
427
441
 
@@ -445,8 +459,16 @@ export function createStageView({
445
459
  chipLabel.textContent = chipLabelText({ steps: slots.step, calls, elapsed });
446
460
  // Folded, the row says what the docked card asks (live and after a
447
461
  // reload alike: from the card), else the running call.
448
- const mini = foldedRowText({ collapsed, question: foldedText(asking), tool: slots.tool, running: asksFront });
449
- miniTool.textContent = mini.text;
462
+ const mini = foldedRowText({ collapsed, question: foldedText(asking), tool: slots.tool, running: asksFront, now: clock() });
463
+ if (mini.clock) {
464
+ miniTool.replaceChildren();
465
+ node("span", "ts-mini-label", miniTool).textContent = mini.text;
466
+ node("span", "ts-mini-clock", miniTool).textContent = ` · ${mini.clock}`;
467
+ miniTool.classList.add("ts-mini-timed");
468
+ } else {
469
+ miniTool.classList.remove("ts-mini-timed");
470
+ miniTool.textContent = mini.text;
471
+ }
450
472
  miniTool.title = mini.title;
451
473
  miniTool.classList.toggle("ts-mini-question", mini.question);
452
474
 
@@ -488,11 +510,11 @@ export function createStageView({
488
510
  return text.length > 60 ? `${text.slice(0, 59)}\u2026` : text;
489
511
  }
490
512
 
491
- // The next step after a blocking card's answer: the one time a turn's
492
- // frame shrinks (stage_frame.js forgetContent; grow-only otherwise). What
493
- // the wait held goes together: the live slots' waiting height, a raised
494
- // cap, the tallest content seen. +held-wait+ says it is due, so a later
495
- // step, or a generation with the card still waiting, changes nothing.
513
+ // The next step after a blocking card's answer, or an answer that leaves
514
+ // another docked card in front: the frame shrinks (stage_frame.js
515
+ // forgetContent; grow-only otherwise). What the wait held goes together:
516
+ // the live slots' waiting height, a raised cap, the tallest content seen.
517
+ // +held-wait+ says it is due, so later steps change nothing.
496
518
  // A card still pending is read from the slots, not the waiting class: a
497
519
  // replay (a reload, a resync) runs its answer and the next step in one
498
520
  // task, before the refresh that drops the class.
@@ -707,6 +729,7 @@ export function createStageView({
707
729
  markOwnToggles();
708
730
  opener.reset();
709
731
  waiting.reset();
732
+ dockedAtLastRefresh = [];
710
733
  miniTool.classList.remove("ts-mini-question");
711
734
  setCloud(false);
712
735
  stage.classList.remove("plain", "ended", "waiting", "held-wait", "in-use", "asking-form", "asks-live");
@@ -806,6 +829,9 @@ export function createStageView({
806
829
  // history is as tall as it gets, room to keep the reader's rows in
807
830
  // place): each answered card's clamp says it now, as the turn reloads.
808
831
  opener.end();
832
+ // The asking card's fold is this turn's: with the turn handed off, there
833
+ // is nothing for a reload to bring back.
834
+ waiting.clearFold();
809
835
  clearStage();
810
836
  if (fold.wasAtEnd) easeScrollTo(historyEl, () => historyEl.scrollHeight - historyEl.clientHeight, { reduce: !fold.animate || reducedMotion() });
811
837
  // The turn's pieces are in the history now (the opt-in reload check,
@@ -1052,8 +1078,8 @@ export function createStageView({
1052
1078
  // A waiting card and the asking form (refresh) land in one task.
1053
1079
  if (waits) refresh();
1054
1080
  else scheduleRefresh();
1055
- // The asking form: the stage shrinks to the card (one of its two
1056
- // allowed shrinks, stage_frame.js; the other is releaseHeldWait).
1081
+ // The asking form: the stage shrinks to the card; an answer can also
1082
+ // shrink it to a remaining card, or release it at the next step.
1057
1083
  if (docked) frame.forgetContent();
1058
1084
  if (waits && el.matches?.(".bubble.question")) askedFor(el);
1059
1085
  // A card that waits for the user is brought into the stage's view: in
@@ -1086,19 +1112,30 @@ export function createStageView({
1086
1112
  stage.classList.add("bare");
1087
1113
  stage.dataset.phase = "running";
1088
1114
  phaseEl.textContent = "running";
1089
- cancel.hidden = !onCancel;
1115
+ cancel.hidden = !onCancel || !canCancel();
1090
1116
  show();
1091
1117
  },
1092
1118
  // The page's clock ticks (app.js, the live timing's 200 ms / 1 s): the
1093
1119
  // quiet signal and the running call's clock.
1094
1120
  tick(nowMs = clock()) {
1095
1121
  drawStall(nowMs);
1122
+ if (holding && asksCard() && liveSlots(view.current().turn).tool?.startedAt != null) scheduleRefresh();
1096
1123
  },
1124
+ callClockActive: () => holding && asksCard() && !!liveSlots(view.current().turn).tool,
1125
+ // An input of the hooks changed (a participant's ownerWait, canCancel).
1126
+ redraw: () => scheduleRefresh(),
1097
1127
  handOff,
1098
1128
  // A card stopped waiting (stage_waiting.js keys; +only+: when it is that
1099
1129
  // kind): question_cards.js's resolve path, cards_place.js upsertCard.
1100
1130
  // The stage's redraw comes from the card's own change.
1101
- settleWaiting: (key, opts) => waiting.settle(key, opts),
1131
+ settleWaiting: (key, opts) => {
1132
+ const settled = waiting.settle(key, opts);
1133
+ if (!settled || !opener.has(key)) return settled;
1134
+ const card = cardIn(extras, key) || cardIn(tail, key);
1135
+ card?.classList.remove("ts-behind");
1136
+ opener.settle(key, card);
1137
+ return true;
1138
+ },
1102
1139
  // The waiting cards as data (the tests' and the harness's read).
1103
1140
  waiting: { list: () => waiting.list(), front: () => waiting.front(), docked: () => waiting.docked(), folded: () => waiting.folded(), count: (o) => waiting.count(o) },
1104
1141
  root: stage,
@@ -25,8 +25,12 @@
25
25
  // a reload agree whatever order the replay brings them in. One docked card
26
26
  // shows at a time (+shown+: the one the pager is on, else the first). The
27
27
  // fold (the docked card's own, stage_asking.js) is the folded card's key and
28
- // how many cards waited when it was folded.
28
+ // how many cards waited when it was folded. That fold is this tab's own: it
29
+ // is kept in sessionStorage (one entry per session) so a reload or a resync
30
+ // mid-turn draws the card as the user left it, and it goes when the card is
31
+ // answered or cancelled, when the fold drops, and when the turn hands off.
29
32
  import { ASKS, PENDING, WARN_CARD } from "./stage_cards.js";
33
+ import { readSession, removeSession, writeSession } from "./storage.js";
30
34
 
31
35
  // The kinds: what blocks the turn (BLOCKING), a running turn's card with
32
36
  // actions (check-in: "asks"), a plugin's warning ("warn": stays in sight,
@@ -46,6 +50,20 @@ export const CONTINUE_KEY = "continue";
46
50
  export const questionKey = (qid) => (qid == null ? null : `q:${qid}`);
47
51
  export const pluginCardKey = (id) => (id == null || id === "" ? null : `c:${id}`);
48
52
 
53
+ // The asking card's fold, kept for this tab (docs/internals/web-frontend.md
54
+ // Storage keys): one entry per session, JSON {key, with}.
55
+ export const FOLD_PREFIX = "chi_asking_fold:";
56
+ export const foldKey = (sessionId) => (sessionId ? `${FOLD_PREFIX}${sessionId}` : null);
57
+
58
+ // The fold's storage: the guarded sessionStorage (storage.js); the specs
59
+ // inject their own, so one test's fold is not another's (they all use session
60
+ // s1 and the same question ids).
61
+ const tabStorage = {
62
+ read: (key) => readSession(key),
63
+ write: (key, value) => writeSession(key, value),
64
+ remove: (key) => removeSession(key),
65
+ };
66
+
49
67
  // +el+'s key, null: not a card the stage keeps.
50
68
  export function waitingKey(el) {
51
69
  if (!el?.matches) return null;
@@ -79,13 +97,19 @@ export function cardIn(root, key) {
79
97
  // +kind+'s rank in the stage's order: blocking cards before the rest.
80
98
  const rank = (kind) => (BLOCKING.has(kind) ? 0 : 1);
81
99
 
82
- export function createStageWaiting() {
100
+ // +sessionId+: the open session (a getter, as app.js and the harnesses pass
101
+ // it); +storage+: the fold's read/write/remove, guarded (the specs inject
102
+ // their own).
103
+ export function createStageWaiting({ sessionId = null, storage = tabStorage } = {}) {
83
104
  const cards = new Map();
84
105
  let seq = 0;
85
106
  let folded = null;
86
107
  let foldedWith = 0;
87
108
  // The docked card the pager is on (null: the first).
88
109
  let paged = null;
110
+ // The key this session's fold is stored under (null: no session, nothing
111
+ // to keep).
112
+ const at = () => foldKey(typeof sessionId === "function" ? sessionId() : sessionId);
89
113
 
90
114
  const entries = () => [...cards.entries()].sort((a, b) => rank(a[1].kind) - rank(b[1].kind) || a[1].order - b[1].order);
91
115
  const dockedKeys = () => entries().filter(([, e]) => e.docked).map(([key]) => key);
@@ -98,6 +122,28 @@ export function createStageWaiting() {
98
122
  return n;
99
123
  }
100
124
 
125
+ // The fold this tab kept for the open session: {key, with}, or null (no
126
+ // fold, nothing stored, or storage that can't be read).
127
+ function storedFold() {
128
+ const key = at();
129
+ if (!key) return null;
130
+ try {
131
+ const value = JSON.parse(storage.read(key) || "null");
132
+ return typeof value?.key === "string" ? { key: value.key, with: Number(value.with) || 0 } : null;
133
+ } catch (_) {
134
+ return null;
135
+ }
136
+ }
137
+
138
+ // The stored fold says what the fold is: written with the count it was
139
+ // made at, removed when there is no fold.
140
+ function keepFold() {
141
+ const key = at();
142
+ if (!key) return;
143
+ if (folded) storage.write(key, JSON.stringify({ key: folded, with: foldedWith }));
144
+ else storage.remove(key);
145
+ }
146
+
101
147
  return {
102
148
  // +key+ came to the stage (again: its kind and flags change, its place in
103
149
  // the order stays).
@@ -117,7 +163,9 @@ export function createStageWaiting() {
117
163
  cards.delete(key);
118
164
  return true;
119
165
  },
120
- // The stage let its turn go: nothing waits, nothing is folded.
166
+ // The stage let its turn go: nothing waits, nothing is folded — the
167
+ // stored fold stays: a resync replays the same turn, and the fold is the
168
+ // user's.
121
169
  reset() {
122
170
  cards.clear();
123
171
  seq = 0;
@@ -161,20 +209,40 @@ export function createStageWaiting() {
161
209
  // Every entry in the stage's order (the tests' and the harness's read).
162
210
  list: () => entries().map(([key, e]) => ({ key, ...e })),
163
211
  // The asking form's fold: +key+ folded by hand (null: unfolded), with
164
- // the blocking cards that wait now.
212
+ // the blocking cards that wait now. Kept for this tab, so the same card
213
+ // is folded again after a reload or a resync.
165
214
  fold(key) {
166
215
  folded = key ?? null;
167
216
  foldedWith = count();
217
+ keepFold();
168
218
  },
169
219
  // The fold as it stands with +asking+ (the asking form's card key) now:
170
220
  // a card answered meanwhile lowers the mark, one more waiting than at
171
- // the fold drops it, and so does another form. The folded key, or null.
221
+ // the fold drops it, and so does another form. The replay drew the card
222
+ // the tab folded: with nothing folded in memory, that fold comes back.
223
+ // The folded key, or null.
172
224
  trackFold(asking) {
173
225
  const now = count();
226
+ // Nothing folded in memory and the replay drew the card this tab
227
+ // folded (a reload, or a resync mid-turn): take that fold back.
228
+ if (!folded) {
229
+ const stored = storedFold();
230
+ if (stored?.key === asking) { folded = stored.key; foldedWith = stored.with; }
231
+ }
174
232
  foldedWith = Math.min(foldedWith, now);
175
- if (folded && (folded !== asking || now > foldedWith)) folded = null;
233
+ if (folded && (folded !== asking || now > foldedWith)) {
234
+ folded = null;
235
+ // Live unfolded it: a reload must not fold it again.
236
+ keepFold();
237
+ }
176
238
  return folded;
177
239
  },
240
+ // The folded card is done for good (answered, cancelled, the turn handed
241
+ // off): there is no fold to bring back.
242
+ clearFold() {
243
+ const key = at();
244
+ if (key) storage.remove(key);
245
+ },
178
246
  folded: () => folded,
179
247
  };
180
248
  }
@@ -4,6 +4,28 @@
4
4
  // globalThis.localStorage at each call, never at import (the specs install
5
5
  // their own).
6
6
 
7
+ // The same guards on sessionStorage: this tab only, so a reload or a resync
8
+ // of it keeps what is written, and another tab or device never sees it.
9
+ // Reads globalThis.sessionStorage at each call (the specs install their own).
10
+
11
+ // The stored string, or +fallback+ when there is none or it can't be read.
12
+ export function readSession(key, fallback = null) {
13
+ try {
14
+ const value = globalThis.sessionStorage?.getItem(key);
15
+ return value == null ? fallback : value;
16
+ } catch (_) {
17
+ return fallback;
18
+ }
19
+ }
20
+
21
+ export function writeSession(key, value) {
22
+ try { globalThis.sessionStorage?.setItem(key, value); } catch (_) {}
23
+ }
24
+
25
+ export function removeSession(key) {
26
+ try { globalThis.sessionStorage?.removeItem(key); } catch (_) {}
27
+ }
28
+
7
29
  // The stored string, or +fallback+ when there is none or it can't be read.
8
30
  export function readStored(key, fallback = null) {
9
31
  try {
@@ -19,6 +19,7 @@
19
19
  // capabilities() the page's capabilities (card.js shownElsewhere)
20
20
  // historyEl the history element (keepFollowing, the failed-turn redraw)
21
21
  // liveTurn, turnDom, shownTexts, questionCards, contextChips the page's views
22
+ // (contextChips null for a viewer without them, viewer.js)
22
23
  // workingSet the stage view's working set (web.working_set),
23
24
  // null when off
24
25
  // participantsControl the owner's participants panel (participants_panel.js),
@@ -370,7 +371,7 @@ export function createStreamHandlers(deps) {
370
371
  gapBefore(at);
371
372
  addNoteBubble({ label: data.label, content: data.text || "", at, objectives: data.objectives });
372
373
  // An attached context source's note: its chip changed.
373
- if (data.context_source) contextChips.refresh();
374
+ if (data.context_source) contextChips?.refresh();
374
375
  },
375
376
  // The session's list changed (objectives_strip.js): an edit waiting, a
376
377
  // list note in, a turn's moves.
@@ -1,4 +1,4 @@
1
- /* The web UI's colour tokens, shared by the owner's page (index.html) and the participant page (participant.html): the dark :root (the default) and the light set under prefers-color-scheme: light. Everything else reads them through var(). */
1
+ /* The web UI's colour tokens, read by the page (index.html, every viewer's): the dark :root (the default) and the light set under prefers-color-scheme: light. Everything else reads them through var(). */
2
2
  :root{color-scheme:dark;--bg:#0b0d11;--bg-top:#131d29;--bg-panel:#151821;--bg-inset:#0f1115;--bg-raised:#22262f;--bg-hover:#1b1f27;--border:#1f232b;--border-strong:#2d333f;--text:#e6e8eb;--text-bright:#f0f3f6;--text-2:#c9d1d9;--text-3:#9aa4b2;--text-muted:#8b949e;--text-faint:#6e7681;--accent:#5aa9ff;--accent-strong:#0071e3;--accent-bg:#0f2340;--accent-ring:rgba(90,169,255,.18);--primary:#0071e3;--ok:#3fb950;--ok-text:#7ee787;--ok-bg:#1a2e1a;--warn:#d29922;--warn-text:#e3b341;--warn-bright:#f2cc60;--warn-bg:#2b2108;--warn-border:#6b5416;--danger:#f85149;--danger-bg:#da3633;--danger-text:#ff7b72;--danger-bg-dim:#3d1f1f;--think:#8957e5;--think-text:#d2a8ff;--accent-border:#1a3458;--pick-border:#79c0ff;--accent-tint:color-mix(in srgb,var(--accent) 7%,transparent);--narr:color-mix(in srgb,var(--accent) 38%,var(--text-muted));
3
3
  --glass-bg:color-mix(in srgb,var(--bg-panel) 70%,transparent);--glass-border:rgba(255,255,255,.08);--glass-highlight:rgba(255,255,255,.05);--glass-shadow:0 8px 30px rgba(0,0,0,.35);
4
4
  --diff-add-bg:rgba(63,185,80,.14);--diff-add-text:#aff5b4;--diff-del-bg:rgba(248,81,73,.14);--diff-del-text:#ffc1bc;
@@ -978,8 +978,9 @@ function pairStepTexts(els, group, items) {
978
978
  // turn's footprint on its summary line.
979
979
  // +cards+ the snapshot's cards (a drawn card's body), +capabilities+ the
980
980
  // page's (a notice shown elsewhere).
981
+ // +apply+: false for a viewer without the owner's Apply (viewer.js): no Apply row.
981
982
  export function turnHistoryNodes(items, timing, { thumbs, workingSet = false, now = Date.now(), drawings = null, cards = null, capabilities = {},
982
- runningTurnId = null }) {
983
+ runningTurnId = null, apply = true }) {
983
984
  const timingTemplate = (group) => {
984
985
  const record = group.record;
985
986
  // Numbered by its place in the turn records, as live (a failed turn
@@ -1026,7 +1027,7 @@ export function turnHistoryNodes(items, timing, { thumbs, workingSet = false, no
1026
1027
  blockTurns.push(ordinal);
1027
1028
  }
1028
1029
  const lineKey = (i) => (items[i]?.source === "delegate_report" ? `${group.turnId}:input:${i - (group.user ?? i)}` : null);
1029
- const reviewer = group.answer !== null && prompt?.turn_id && prompt.participant_mode !== PAIR ? authorBadge(prompt.author, prompt.author_name) : null;
1030
+ const reviewer = apply && group.answer !== null && prompt?.turn_id && prompt.participant_mode !== PAIR ? authorBadge(prompt.author, prompt.author_name) : null;
1030
1031
  const pieces = turnPieces({
1031
1032
  prompt: prompt ? (prompt.role === "note" ? noteBubbleTemplate(prompt) : userTemplate(prompt)) : null,
1032
1033
  block: drawn.block,