samagotchi 0.186.0 → 0.188.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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +68 -1
  3. data/bin/chi +4 -0
  4. data/docs/architecture.md +8 -4
  5. data/docs/bundles.md +124 -120
  6. data/docs/cli.md +26 -5
  7. data/docs/configuration.md +4 -4
  8. data/docs/context.md +18 -162
  9. data/docs/guardrails.md +3 -1
  10. data/docs/hooks.md +2 -1
  11. data/docs/internals/attached-context.md +19 -37
  12. data/docs/internals/bridge.md +1 -0
  13. data/docs/internals/engine.md +2 -2
  14. data/docs/internals/inline-widgets.md +18 -0
  15. data/docs/internals/llm-context-forget.md +5 -6
  16. data/docs/internals/objectives.md +1 -0
  17. data/docs/internals/pages.md +175 -0
  18. data/docs/internals/peers.md +149 -0
  19. data/docs/internals/remote-sessions.md +7 -4
  20. data/docs/internals/web-frontend.md +65 -40
  21. data/docs/internals/web-push.md +1 -1
  22. data/docs/memory.md +8 -1
  23. data/docs/pages.md +151 -0
  24. data/docs/peers.md +141 -0
  25. data/docs/plugins.md +52 -27
  26. data/docs/sessions.md +8 -4
  27. data/docs/sub-agent.md +5 -5
  28. data/lib/samagotchi/bridge.rb +3 -3
  29. data/lib/samagotchi/bundle_command/api_calls.rb +2 -1
  30. data/lib/samagotchi/bundle_command/check.rb +1 -1
  31. data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -18
  32. data/lib/samagotchi/bundles/claude-peer/plugin.rb +22 -16
  33. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +48 -39
  34. data/lib/samagotchi/bundles/claude-peer/scripts/pair +15 -73
  35. data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +16 -16
  36. data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -15
  37. data/lib/samagotchi/bundles/codex-peer/plugin.rb +35 -24
  38. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +51 -40
  39. data/lib/samagotchi/bundles/codex-peer/scripts/pair +18 -54
  40. data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +16 -16
  41. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  42. data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
  43. data/lib/samagotchi/bundles/skills/plugin.rb +14 -8
  44. data/lib/samagotchi/bundles/system/manifest.yml +5 -2
  45. data/lib/samagotchi/bundles/system/self_map.md +5 -1
  46. data/lib/samagotchi/bundles/system/skill_pages.md +93 -0
  47. data/lib/samagotchi/client_id.rb +15 -1
  48. data/lib/samagotchi/config.rb +8 -7
  49. data/lib/samagotchi/context_absorber.rb +23 -277
  50. data/lib/samagotchi/context_sources.rb +17 -69
  51. data/lib/samagotchi/engine/messages.rb +12 -1
  52. data/lib/samagotchi/engine/plugins.rb +1 -1
  53. data/lib/samagotchi/engine.rb +7 -6
  54. data/lib/samagotchi/engine_peers.rb +0 -3
  55. data/lib/samagotchi/guardrail_wiring.rb +2 -0
  56. data/lib/samagotchi/guardrails/chi_dirs.rb +4 -3
  57. data/lib/samagotchi/guardrails/parent_approvals.rb +6 -5
  58. data/lib/samagotchi/guardrails/protected_paths.rb +6 -3
  59. data/lib/samagotchi/inline_widgets.rb +73 -0
  60. data/lib/samagotchi/log_line.rb +1 -1
  61. data/lib/samagotchi/note_move.rb +3 -1
  62. data/lib/samagotchi/page_command.rb +243 -0
  63. data/lib/samagotchi/pages/builder.rb +186 -0
  64. data/lib/samagotchi/pages/launch.rb +193 -0
  65. data/lib/samagotchi/pages/runner.rb +154 -0
  66. data/lib/samagotchi/pages/store.rb +152 -0
  67. data/lib/samagotchi/pages.rb +119 -0
  68. data/lib/samagotchi/peer_command.rb +192 -0
  69. data/lib/samagotchi/peer_continue.rb +99 -0
  70. data/lib/samagotchi/peer_exchanges.rb +3 -3
  71. data/lib/samagotchi/peer_mailbox.rb +360 -0
  72. data/lib/samagotchi/peer_note.rb +208 -0
  73. data/lib/samagotchi/peer_receipts.rb +247 -0
  74. data/lib/samagotchi/peer_registry.rb +44 -0
  75. data/lib/samagotchi/peer_roster.rb +79 -0
  76. data/lib/samagotchi/peer_say.rb +168 -0
  77. data/lib/samagotchi/plugin/api.rb +29 -21
  78. data/lib/samagotchi/plugin/context.rb +7 -0
  79. data/lib/samagotchi/plugin/loader.rb +3 -3
  80. data/lib/samagotchi/plugin/peer.rb +175 -64
  81. data/lib/samagotchi/plugin/peers.rb +70 -0
  82. data/lib/samagotchi/run_options.rb +3 -1
  83. data/lib/samagotchi/schedule_command.rb +10 -3
  84. data/lib/samagotchi/schedule_display.rb +32 -0
  85. data/lib/samagotchi/session_access/contract.rb +19 -2
  86. data/lib/samagotchi/session_access/local.rb +132 -14
  87. data/lib/samagotchi/session_access/remote.rb +4 -2
  88. data/lib/samagotchi/session_access/remote_peers.rb +75 -0
  89. data/lib/samagotchi/session_continue.rb +12 -0
  90. data/lib/samagotchi/session_inbox_delivery.rb +5 -2
  91. data/lib/samagotchi/session_manager/delivery.rb +5 -3
  92. data/lib/samagotchi/session_manager/removal.rb +2 -0
  93. data/lib/samagotchi/session_manager/spawn.rb +2 -1
  94. data/lib/samagotchi/session_manager.rb +1 -0
  95. data/lib/samagotchi/session_stores.rb +17 -0
  96. data/lib/samagotchi/steer.rb +1 -1
  97. data/lib/samagotchi/system_prompt.rb +1 -1
  98. data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
  99. data/lib/samagotchi/terminal_ui/formatting.rb +4 -1
  100. data/lib/samagotchi/testing/boundary.rb +4 -13
  101. data/lib/samagotchi/testing/bundle.rb +40 -5
  102. data/lib/samagotchi/testing/install.rb +4 -4
  103. data/lib/samagotchi/testing/recording_api.rb +2 -1
  104. data/lib/samagotchi/tools/context_read.rb +0 -14
  105. data/lib/samagotchi/tools/list_schedules.rb +8 -3
  106. data/lib/samagotchi/version.rb +1 -1
  107. data/lib/samagotchi/web/app.rb +7 -18
  108. data/lib/samagotchi/web/message_display.rb +4 -2
  109. data/lib/samagotchi/web/page_routes.rb +116 -0
  110. data/lib/samagotchi/web/peer_routes.rb +133 -0
  111. data/lib/samagotchi/web/public/app.js +35 -95
  112. data/lib/samagotchi/web/public/bubbles.js +2 -2
  113. data/lib/samagotchi/web/public/cards_place.js +20 -1
  114. data/lib/samagotchi/web/public/context_chips.js +45 -46
  115. data/lib/samagotchi/web/public/history_reveal.js +4 -1
  116. data/lib/samagotchi/web/public/history_shape.js +3 -2
  117. data/lib/samagotchi/web/public/index.html +16 -0
  118. data/lib/samagotchi/web/public/notify.js +1 -1
  119. data/lib/samagotchi/web/public/page_blocks.js +58 -0
  120. data/lib/samagotchi/web/public/page_links.js +33 -0
  121. data/lib/samagotchi/web/public/page_model.js +68 -0
  122. data/lib/samagotchi/web/public/page_route.js +24 -0
  123. data/lib/samagotchi/web/public/page_table.js +74 -0
  124. data/lib/samagotchi/web/public/page_table_model.js +76 -0
  125. data/lib/samagotchi/web/public/page_view.js +219 -0
  126. data/lib/samagotchi/web/public/pages.css +77 -0
  127. data/lib/samagotchi/web/public/pages_group.js +65 -0
  128. data/lib/samagotchi/web/public/peer_chip.js +60 -74
  129. data/lib/samagotchi/web/public/peer_data.js +13 -11
  130. data/lib/samagotchi/web/public/peer_links.js +12 -7
  131. data/lib/samagotchi/web/public/peer_mailbox_api.js +20 -0
  132. data/lib/samagotchi/web/public/peer_note.js +7 -3
  133. data/lib/samagotchi/web/public/peer_text.js +4 -4
  134. data/lib/samagotchi/web/public/quiet_notes.js +199 -0
  135. data/lib/samagotchi/web/public/revise_stack.js +4 -3
  136. data/lib/samagotchi/web/public/session_view.js +2 -2
  137. data/lib/samagotchi/web/public/stream_handlers.js +3 -2
  138. data/lib/samagotchi/web/public/turn_block.js +7 -3
  139. data/lib/samagotchi/web/public/turn_events.js +6 -0
  140. data/lib/samagotchi/web/public/views.js +161 -0
  141. data/lib/samagotchi/web/push/attention.rb +3 -2
  142. data/lib/samagotchi/web/session_access_routes.rb +3 -20
  143. data/lib/samagotchi/web/viewer.rb +1 -1
  144. data/lib/samagotchi/worker/leave.rb +3 -0
  145. data/lib/samagotchi/worker/mail.rb +73 -0
  146. data/lib/samagotchi/worker/startup.rb +3 -0
  147. data/lib/samagotchi/worker/wake_turns.rb +20 -5
  148. data/lib/samagotchi/worker.rb +12 -6
  149. data/lib/samagotchi/worker_inbound/mail.rb +214 -0
  150. data/lib/samagotchi/worker_inbound.rb +43 -46
  151. data/lib/samagotchi/worker_wakes.rb +26 -21
  152. metadata +39 -2
  153. data/lib/samagotchi/peer_sources.rb +0 -58
@@ -17,8 +17,8 @@ import { TIME_GAP_CLASS, timeGapEl } from "./time_gaps.js";
17
17
 
18
18
  // What a session's load places at a turn's prompt from the snapshot
19
19
  // (cards_place.js placeSnapshotCards): its cards, answered questions,
20
- // notices and warnings.
21
- const SNAPSHOT_PLACED = ".plugin-card, .bubble.question, .bubble.hook-notice, .bubble.guardrail-warning";
20
+ // notices and warnings; and the notes rows over its lines (quiet_notes.js).
21
+ const SNAPSHOT_PLACED = ".plugin-card, .bubble.question, .bubble.hook-notice, .bubble.guardrail-warning, .quiet-notes";
22
22
 
23
23
  export function removeQueuedBubble(bubble) {
24
24
  if (!bubble) return;
@@ -122,13 +122,32 @@ export function createCardsPlace({
122
122
  else if (entry.type === "question") placeResolvedQuestion(entry, before);
123
123
  else if (entry.type === "guardrail_warning") bubbles.showGuardrailWarning(entry.message, entry.label || "guardrails", { before });
124
124
  else if (entry.in_turn) placeTurnNotice(entry, before);
125
- else if (entry.type === "hook_notice") bubbles.showHookNotice(entry, { before });
125
+ else if (entry.type === "hook_notice") bubbles.showHookNotice(entry, { before: afterTurnEnd(before) });
126
126
  }
127
127
  // A drawn turn's question slot whose question never came (CardStore
128
128
  // dropped it, a pending one): nothing in its place.
129
129
  historyEl.querySelectorAll("[data-question-slot]").forEach((slot) => slot.remove());
130
130
  }
131
131
 
132
+ // Where a between-turn line goes, given +before+ (the next opening, or null
133
+ // for the end): right after the turn that just ended, as live (a notice
134
+ // draws no time divider of its own), so above the next opening's divider
135
+ // and the context notes that came between the turns. It walks back over
136
+ // those and their notes rows (quiet_notes.js; never over earlier lines,
137
+ // cards or questions: several lines keep their order) and returns the
138
+ // first one it walked over, else +before+.
139
+ // Assumes the line came right after a turn (an after_turn hook), not after
140
+ // a later note: an anytime command's line between turns moves above the
141
+ // notes before it too (rare; the e2e reload checks cover it).
142
+ function afterTurnEnd(before) {
143
+ let place = before;
144
+ for (let el = before ? before.previousElementSibling : historyEl.lastElementChild; el; el = el.previousElementSibling) {
145
+ if (!el.matches(".time-gap, .bubble.note:not(.turn-start), .quiet-notes")) break;
146
+ place = el;
147
+ }
148
+ return place;
149
+ }
150
+
132
151
  // An in-turn entry (not a question) of a turn the history drew from its
133
152
  // drawing (its pieces carry data-drawn; the entry's of_turn, CardStore's).
134
153
  function drawnEntry(entry) {
@@ -12,7 +12,7 @@ import { popoverPlace, SHEET_MAX, sheetPlace } from "./chip_popover.js";
12
12
  import { focusBack, modalDialog } from "./popover_modal.js";
13
13
  import { cantText } from "./format.js";
14
14
  import { createLatest } from "./latest.js";
15
- import { peerChipModel, peerGroups, peerKey, peerPopoverTemplate, peerShown } from "./peer_chip.js";
15
+ import { peerChipModel, peerGroups, peerKey, peerPopoverTemplate } from "./peer_chip.js";
16
16
 
17
17
  // "now", "3m", "2h", "4d" since an ISO time; "" for none.
18
18
  export function ageText(iso, now = Date.now()) {
@@ -90,13 +90,14 @@ export function popoverTemplate(row, { text = null, now = Date.now() } = {}) {
90
90
  // so focus stays. The
91
91
  // popover behaves as every popover does (popover_modal.js): a modal dialog, its chip's
92
92
  // aria-expanded, Esc closes it and focus goes back to the chip.
93
- // A paired peer's two sources are one chip (peer_chip.js), drawn first:
94
- // +peers+() the peers model (peer_data.js createPeers; null: none, the
95
- // chips then read no exchanges), read again when a session's chips load or
96
- // a peer appears among them, and the chips redrawn on its change
97
- // (peersChanged); +peerActions+: {status(name): the status card's command
98
- // line ("/claude") when the session has it, else null; run(line); drawn(id):
99
- // whether that send's row is in the conversation; jump(id): to it}.
93
+ // A paired peer is one chip (peer_chip.js), drawn first: +peers+() the
94
+ // peers model (peer_data.js createPeers, GET …/peers: the chip's only feed;
95
+ // null: none, no peer chips), read when a session's chips load, and the
96
+ // chips redrawn on its change (peersChanged); +peerActions+: {status(name):
97
+ // the status card's command line ("/claude") when the session has it, else
98
+ // null; run(line); drawn(id): whether that send's row is in the
99
+ // conversation; jump(id): to it}. +api+ also reads a peer's message
100
+ // (message(id, name, serial)) and ends a pairing (unpair(id, name)).
100
101
  // +focusAway+(): where focus goes when a detach or Unpair took the last chip
101
102
  // (the composer).
102
103
  export function createContextChips({ el, api, toast = () => {}, peers = () => null, peerActions = {},
@@ -108,10 +109,8 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
108
109
  let openKey = null;
109
110
  // Only the newest list read for the open session is drawn (latest.js).
110
111
  const latest = createLatest(() => sessionId);
111
- // The open popover's text once read (view text; a peer's: its outbox's).
112
+ // The open popover's text once read (view text; a peer's: a message's).
112
113
  let text = null;
113
- // The peers the last read named (a new one reads the peers model again).
114
- let peerNames = "";
115
114
  const pop = doc.createElement("div");
116
115
  pop.id = "contextPopover";
117
116
  pop.className = "ctx-popover";
@@ -119,14 +118,14 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
119
118
  doc.body.appendChild(pop);
120
119
  modalDialog(pop, { isOpen: () => openKey !== null, doc });
121
120
 
122
- const groups = () => peerGroups(rows).peers.filter(peerShown);
121
+ const groups = () => peerGroups(peers()?.peers?.() || []);
123
122
  const groupOf = (key) => groups().find((group) => group.key === key) || null;
124
123
  const exchangesOf = (name) => peers()?.peer?.(name)?.exchanges || [];
125
124
  const rowOf = (name) => rows.find((r) => r.name === name) || null;
126
125
 
127
126
  function chips(now = Date.now()) {
128
127
  const peerChips = groups().map((group) => peerChipModel(group, exchangesOf(group.name), now));
129
- return [...peerChips, ...chipModel(peerGroups(rows).rest, now)];
128
+ return [...peerChips, ...chipModel(rows, now)];
130
129
  }
131
130
 
132
131
  function drawChips() {
@@ -166,17 +165,14 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
166
165
  draw();
167
166
  // An open popover follows its row, but not while it shows the text.
168
167
  follow();
169
- // The peers' exchanges for the chips: at a session's open (reuse the
170
- // conversation's read if loaded or in flight), and when a peer comes.
171
- const names = groups().map((group) => group.name).join(" ");
172
- if (names && (loading || names !== peerNames)) peers()?.refresh?.({ reuse: loading });
173
- peerNames = names;
168
+ // The peers for their chips: at a session's open (reuse the
169
+ // conversation's read if loaded or in flight).
170
+ if (loading) peers()?.refresh?.({ reuse: true });
174
171
  }
175
172
 
176
173
  function load(id) {
177
174
  sessionId = id;
178
175
  rows = [];
179
- peerNames = "";
180
176
  close();
181
177
  return refresh({ loading: true });
182
178
  }
@@ -184,7 +180,6 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
184
180
  function clear() {
185
181
  sessionId = null;
186
182
  rows = [];
187
- peerNames = "";
188
183
  close();
189
184
  }
190
185
 
@@ -259,13 +254,17 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
259
254
  if (key !== null) back([...el.querySelectorAll(".ctx-chip[data-name]")].find((chip) => chip.dataset.name === key));
260
255
  }
261
256
 
262
- async function viewText() {
257
+ // The open popover's text: a source's, or a peer's message (+serial+;
258
+ // default its newest).
259
+ async function viewText(serial = null, box = null) {
263
260
  const key = openKey;
264
261
  if (!key) return;
265
- // A peer's text is its outbox's: the latest answer.
266
- const name = groupOf(key)?.outbox?.name || key;
262
+ const peer = groupOf(key);
263
+ const number = peer ? serial ?? peer.peer.messages?.[0]?.serial : null;
264
+ const name = peer ? `${peer.label}'s message #${number}` : key;
265
+ if (peer && (number === null || number === undefined)) return;
267
266
  try {
268
- const data = await api.show(sessionId, name);
267
+ const data = peer ? await api.message(sessionId, peer.name, number, box) : await api.show(sessionId, key);
269
268
  if (key !== openKey) return;
270
269
  const group = groupOf(key);
271
270
  const row = group ? null : rowOf(key);
@@ -295,25 +294,21 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
295
294
  }
296
295
  }
297
296
 
298
- // Unpair: one confirm, then both legs detached, the outbox first; a leg
299
- // that fails is named and stops it (the inbox stays: the chip doesn't turn
300
- // into "answers only" over a half unpair).
297
+ // Unpair: one confirm, then the pairing ends (DELETE …/peers/NAME; its
298
+ // messages stay) and the peers are read again: the chip goes.
301
299
  async function unpair() {
302
300
  const group = groupOf(openKey);
303
301
  if (!group) return;
304
- const legs = [group.outbox, group.inbox].filter(Boolean).map((leg) => leg.name);
305
- if (!win.confirm(`Unpair ${group.label}? This detaches ${legs.join(" and ")} from this session.`)) return;
302
+ if (!win.confirm(`Unpair ${group.label}? chi stops sending to it; its messages stay.`)) return;
306
303
  const id = sessionId;
307
304
  close();
308
- for (const name of legs) {
309
- try {
310
- await api.detach(id, name);
311
- } catch (e) {
312
- toast(cantText(`detach ${name}`, e));
313
- break;
314
- }
305
+ try {
306
+ await api.unpair(id, group.name);
307
+ } catch (e) {
308
+ toast(cantText(`unpair ${group.label}`, e));
315
309
  }
316
- await refresh();
310
+ await peers()?.refresh?.();
311
+ drawChips();
317
312
  focusAfterRemoval();
318
313
  }
319
314
 
@@ -367,22 +362,26 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
367
362
  // The ages move on by themselves.
368
363
  win.setInterval(() => { if (rows.length) drawChips(); }, 60_000);
369
364
 
370
- // +name+'s popover on its text (a peer answer's "Read the full answer",
371
- // peer_links.js), at its chip: a peer's leg opens its peer's chip. In a
372
- // task of its own: the click that asks would close it on its way to the
373
- // document.
374
- function showText(name) {
365
+ // The popover of chip +key+ on its text (+serial+: a peer's message), at
366
+ // its chip. In a task of its own: the click that asks would close it on
367
+ // its way to the document.
368
+ function showAt(key, serial = null, box = null) {
375
369
  setTimeout(() => {
376
- const leg = rowOf(name);
377
- const key = leg?.peer && groupOf(peerKey(leg.peer)) ? peerKey(leg.peer) : name;
378
370
  const chip = [...el.querySelectorAll(".ctx-chip[data-name]")].find((c) => c.dataset.name === key);
379
371
  if (!chip) return;
380
372
  chip.scrollIntoView?.({ block: "nearest", inline: "nearest" });
381
373
  if (openKey !== key) open(key, chip);
382
- if (openKey === key && text === null) viewText();
374
+ if (openKey === key && text === null) viewText(serial, box);
383
375
  }, 0);
384
376
  }
385
377
 
378
+ // +name+'s popover on its text: an older peer answer's "Read the full
379
+ // answer" (peer_links.js; its context source, an ordinary chip now).
380
+ const showText = (name) => showAt(name);
381
+ // Peer +name+'s chip on its message +serial+ (a mailbox note's "Read the
382
+ // full answer", peer_links.js).
383
+ const showMessage = (name, serial, box) => showAt(peerKey(name), serial, box);
384
+
386
385
  // The peers model read again: the chips and an open peer's popover follow it.
387
386
  function peersChanged() {
388
387
  if (!sessionId) return;
@@ -390,5 +389,5 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
390
389
  if (groupOf(openKey)) follow();
391
390
  }
392
391
 
393
- return { load, clear, refresh, close, showText, peersChanged, get rows() { return rows; } };
392
+ return { load, clear, refresh, close, showText, showMessage, peersChanged, get rows() { return rows; } };
394
393
  }
@@ -3,7 +3,8 @@
3
3
  // step, a diff), an answer or a delegate report folded (answer_fold.js: its row follows
4
4
  // the bubble's class; the jump's unfold isn't saved), a superseded version
5
5
  // of a Revise stack (revise_stack.js: its stub opens, not saved), a drawn
6
- // block's source (block_source.js). Every
6
+ // block's source (block_source.js), a closed notes row (quiet_notes.js: it
7
+ // opens, never stored). Every
7
8
  // jump goes through it (claim_link.js showClaim, refs.js showRow and so the
8
9
  // working set's step tags, verdict_card.js "View check"), so a new way to
9
10
  // hide history is opened in one place.
@@ -14,6 +15,7 @@
14
15
 
15
16
  import { revealBlockSource } from "./block_source.js";
16
17
  import { openStubOver } from "./revise_stack.js";
18
+ import { revealQuiet } from "./quiet_notes.js";
17
19
 
18
20
  // Opens each closed <details> that holds +el+ (not +el+ itself: a fold the
19
21
  // caller means to open it opens itself) and unfolds the folded answer that
@@ -21,6 +23,7 @@ import { openStubOver } from "./revise_stack.js";
21
23
  export function revealInHistory(el) {
22
24
  if (!el) return null;
23
25
  openStubOver(el);
26
+ revealQuiet(el);
24
27
  revealBlockSource(el);
25
28
  el.closest?.(".bubble.folded")?.classList.remove("folded");
26
29
  for (let details = el.parentElement?.closest("details"); details; details = details.parentElement?.closest("details")) {
@@ -11,7 +11,8 @@
11
11
  // notices. Kinds come from KINDS only (the server logs them, nothing else).
12
12
  // `cls` is a kind's own modifier (a row's status, a warn notice, a report
13
13
  // reply), `text` what it says, whitespace collapsed. Left out: lit's
14
- // comments, the copy button, the quiet-stretch dividers (`.time-gap`), and
14
+ // comments, the copy button, the quiet-stretch dividers (`.time-gap`), the
15
+ // notes rows (`.quiet-notes`, quiet_notes.js: their items are read), and
15
16
  // view state (folds, stacks, the motion classes): nothing a reader would
16
17
  // call a different turn.
17
18
  //
@@ -133,7 +134,7 @@ function otherItem(el) {
133
134
  // One child of #history as its items (a turn block's are several; a time
134
135
  // divider none).
135
136
  function childItems(el) {
136
- if (el.matches(".time-gap, .copy-btn")) return [];
137
+ if (el.matches(".time-gap, .copy-btn, .quiet-notes")) return [];
137
138
  if (el.matches(".turn-work")) {
138
139
  return [item("block", textOf(el.querySelector(":scope > summary .turn-steps"))),
139
140
  ...[...el.querySelectorAll(":scope > .gen")].flatMap(stepItems)];
@@ -25,6 +25,7 @@
25
25
  <link rel="stylesheet" href="/assets/objectives.css">
26
26
  <link rel="stylesheet" href="/assets/block_renderers.css">
27
27
  <link rel="stylesheet" href="/assets/ws_preview.css">
28
+ <link rel="stylesheet" href="/assets/pages.css">
28
29
  <style>
29
30
  /* Icon masks shared by the phone info bar and the all view's cards (the stroke only shapes the mask; the icon takes currentColor); the image icon is composer.css's. */
30
31
  :root{--icon-archive:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='2.75' width='12' height='3.5' rx='1'/%3E%3Cpath d='M3.25 6.25v6a1 1 0 0 0 1 1h7.5a1 1 0 0 0 1-1v-6M6.5 9h3'/%3E%3C/svg%3E");--icon-unarchive:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='2.75' width='12' height='3.5' rx='1'/%3E%3Cpath d='M3.25 6.25v6a1 1 0 0 0 1 1h7.5a1 1 0 0 0 1-1v-6M8 11.5V8.25M6.5 9.75 8 8.25l1.5 1.5'/%3E%3C/svg%3E")}
@@ -87,6 +88,18 @@ main{flex:1;display:flex;flex-direction:column;gap:16px;padding:max(16px,var(--s
87
88
  #history>.bubble.folded{display:none}
88
89
  .answer-fold{display:flex;align-items:baseline;gap:0;align-self:stretch;max-width:100%;min-width:0;margin:0;padding:12px 14px;font:inherit;font-size:13px;font-weight:600;line-height:1.5;color:var(--text-muted);text-align:left;cursor:pointer;user-select:none;background:var(--bg-panel);border:1px solid var(--border);border-left:3px solid var(--accent-strong);border-radius:12px}
89
90
  @media(hover:hover){.answer-fold:hover .answer-fold-size{color:var(--text-2)}}
91
+ /* The notes row (quiet_notes.js): a stretch of background items folded, a sibling before them. */
92
+ #history>.quiet-hidden{display:none}
93
+ .quiet-notes{display:flex;align-items:baseline;gap:6px;align-self:stretch;max-width:100%;min-width:0;min-height:32px;margin:0;padding:5px 12px;font:inherit;font-size:13px;line-height:1.5;color:var(--text-muted);text-align:left;cursor:pointer;user-select:none;background:transparent;border:0;border-left:3px solid var(--text-faint);border-radius:0 8px 8px 0}
94
+ @media(hover:hover){.quiet-notes:hover{background:var(--bg-hover);color:var(--text-2)}}
95
+ .quiet-notes:focus-visible{outline:2px solid var(--accent-ring);outline-offset:1px}
96
+ .quiet-notes::before{content:"▸";color:var(--text-faint);flex:none}
97
+ .quiet-notes.open::before{content:"▾"}
98
+ .quiet-notes.warn{border-left-color:var(--warn)}
99
+ .qn-count{flex:none;font-weight:600;white-space:nowrap}
100
+ .qn-names{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
101
+ .qn-warn{flex:none;margin-left:auto;white-space:nowrap;color:var(--warn-text)}
102
+ @media(max-width:600px){.quiet-notes{min-height:44px;align-items:center}}
90
103
  .answer-fold:focus-visible{outline:2px solid var(--accent-ring);outline-offset:1px}
91
104
  .answer-fold::before{content:"▾\00a0";color:var(--accent);flex:none}
92
105
  .answer-fold.folded::before{content:"▸\00a0"}
@@ -1477,6 +1490,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1477
1490
  .peer-pop-legs{display:flex;flex-direction:column;gap:6px}
1478
1491
  .peer-pop-legs>div{display:flex;gap:8px}
1479
1492
  .peer-pop-legs>div>span:first-child{flex:0 0 78px;color:var(--text-muted)}
1493
+ .peer-pop-legs>div>span:last-child{min-width:0;overflow-wrap:anywhere;word-break:break-word}
1480
1494
  .peer-pop-legs .warn{color:var(--warn-text)}
1481
1495
  .peer-pop-list{display:flex;flex-direction:column}
1482
1496
  .peer-pop-list-head{font-size:12px;font-weight:700;color:var(--text-muted);padding-bottom:4px}
@@ -2313,7 +2327,9 @@ body.participant-view .bubble.user:not(.by-participant)>.origin-label{color:var(
2313
2327
  </div>
2314
2328
  </div>
2315
2329
  </section>
2330
+ <section id="pageView" aria-label="Page"></section>
2316
2331
  <section id="allView" aria-label="All sessions">
2332
+ <div id="pagesGroup" hidden></div>
2317
2333
  <div id="allList"></div>
2318
2334
  <div id="allPath" hidden>Stored in <code></code></div>
2319
2335
  </section>
@@ -20,7 +20,7 @@ export function notifyState({ hasNotification, secureContext, permission, wanted
20
20
  // an attached context change (context) or a finished background task
21
21
  // (task): nobody started it, so nobody watched it.
22
22
  const DONE_MIN_SECONDS = 10;
23
- const UNWATCHED_ORIGINS = ["delegate_report", "context", "task"];
23
+ const UNWATCHED_ORIGINS = ["delegate_report", "context", "peer", "task"];
24
24
  const VERDICT_REASON_MAX = 120;
25
25
 
26
26
  // The step-limit question (kind "continue": a turn ran out of iterations
@@ -0,0 +1,58 @@
1
+ // A page's blocks as lit templates (docs/pages.md): a text block as the
2
+ // server's sanitised html (Markdown on) or as plain text with its line
3
+ // breaks, a walk in a widget host drawn by drawWalk (inline_widgets.js'
4
+ // shadow root and sheet), a table by +table+ (page_table.js), and a block of
5
+ // a type this page doesn't know (a newer chi's) as one muted line, never a
6
+ // blank or a throw. What a script wrote reaches the page as text or
7
+ // attributes only; the one markup is the server's sanitised html. A fenced
8
+ // block inside a text block stays source: no block watcher runs here.
9
+ import { html, nothing } from "./vendor/lit-html.js";
10
+ import { unsafeHTML } from "./vendor/directives/unsafe-html.js";
11
+ import { HOST, loadWidgetSheet } from "./inline_widgets.js";
12
+ import { drawWalk } from "./widget_walk.js";
13
+
14
+ // The class a walk's host carries, so drawWalks finds the hosts to fill.
15
+ export const WALK_HOST = "pg-walk";
16
+
17
+ function textBlock(block) {
18
+ if (typeof block.html === "string") return html`<div class="pg-text markdown">${unsafeHTML(block.html)}</div>`;
19
+ return html`<div class="pg-text pg-plain">${String(block.text ?? "")}</div>`;
20
+ }
21
+
22
+ // +table+: (block, index) => template (page_table.js), or null to show a
23
+ // table as an unknown block. +index+: the block's place on the page.
24
+ export function blockTemplate(block, { table = null } = {}, index = 0) {
25
+ const type = block && typeof block === "object" ? block.type : null;
26
+ if (type === "text") return textBlock(block);
27
+ if (type === "walk") return html`<div class="${HOST} ${WALK_HOST}" .pageWalk=${block.data}></div>`;
28
+ if (type === "table" && table) return table(block, index);
29
+ return html`<div class="pg-unknown">A ${String(type || "block")} block this chi web doesn't draw.</div>`;
30
+ }
31
+
32
+ export function blocksTemplate(blocks, opts = {}) {
33
+ if (!Array.isArray(blocks) || !blocks.length) return nothing;
34
+ return blocks.map((block, index) => blockTemplate(block, opts, index));
35
+ }
36
+
37
+ // Fills each walk host under +root+ whose data changed since its last draw
38
+ // (a redraw of the same page keeps the walk where the reader left it).
39
+ export async function drawWalks(root, { doc = document, win = window, sheet = () => loadWidgetSheet(win) } = {}) {
40
+ const hosts = [...root.querySelectorAll(`.${WALK_HOST}`)].filter((host) => host.pageWalk && host.drawnWalk !== host.pageWalk);
41
+ if (!hosts.length) return;
42
+ const css = await sheet();
43
+ for (const host of hosts) {
44
+ const data = host.pageWalk;
45
+ if (host.drawnWalk === data) continue;
46
+ host.drawnWalk = data;
47
+ const shadow = host.shadowRoot || host.attachShadow({ mode: "open" });
48
+ if (css) shadow.adoptedStyleSheets = [css];
49
+ try {
50
+ shadow.replaceChildren(drawWalk(data, doc));
51
+ } catch (e) {
52
+ const line = doc.createElement("div");
53
+ line.className = "pg-unknown";
54
+ line.textContent = `This walk can't be drawn: ${e?.message || e}`;
55
+ shadow.replaceChildren(line);
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,33 @@
1
+ // A #/p/NAME link (in chi's answer, or on a page) opens the page in place
2
+ // (docs/pages.md): the sanitiser gives an answer's links target=_blank, so
3
+ // without this a page link would open a new tab (and leave the iPhone's Home
4
+ // Screen app for Safari). One delegated click handler per root, for anchors
5
+ // whose href starts with #/p/: a plain left click (button 0, no modifier
6
+ // key, not a ref link) opens the view and stops the new tab; a modified or
7
+ // middle click keeps the browser's own way. Other in-page links are left as
8
+ // they are. Installed only with the pages capability (app.js).
9
+ import { pageNameFromHash } from "./page_route.js";
10
+
11
+ // The page a click on +event+ asks for, or null when it isn't one this
12
+ // handler takes.
13
+ export function pageLinkTarget(event) {
14
+ if (event.defaultPrevented || event.button !== 0) return null;
15
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return null;
16
+ const link = event.target?.closest?.("a[href]");
17
+ if (!link || link.hasAttribute("data-ref-kind")) return null;
18
+ const href = link.getAttribute("href") || "";
19
+ return href.startsWith("#/p/") ? pageNameFromHash(href) : null;
20
+ }
21
+
22
+ // +roots()+: the elements to listen on (the turn roots, the page view).
23
+ // +open(name)+: views.js openPage.
24
+ export function installPageLinks(roots, { open }) {
25
+ for (const root of roots) {
26
+ root?.addEventListener("click", (event) => {
27
+ const name = pageLinkTarget(event);
28
+ if (!name) return;
29
+ event.preventDefault();
30
+ open(name);
31
+ });
32
+ }
33
+ }
@@ -0,0 +1,68 @@
1
+ // What a page's header and state lines say, from the page's JSON
2
+ // (GET /api/pages/NAME): pure, so the words are testable without a DOM.
3
+ // page_view.js draws them. "Changed" is the server's (Pages::Stored#changed?,
4
+ // docs/internals/pages.md): the result on screen came from an older script.
5
+ import { relativeTime } from "./format.js";
6
+
7
+ const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
8
+
9
+ // A run's length: "0.8 s", "12 s", "< 0.1 s" (not "0.0 s"); "" without one.
10
+ export function durationText(ms) {
11
+ if (typeof ms !== "number" || !Number.isFinite(ms) || ms < 0) return "";
12
+ if (ms < 50) return "< 0.1 s";
13
+ return ms < 10_000 ? `${(ms / 1000).toFixed(1)} s` : `${Math.round(ms / 1000)} s`;
14
+ }
15
+
16
+ // The header's meta: "ran 2 min ago · 0.8 s", "never ran"; null for a
17
+ // failed run (its line says when the kept result is from).
18
+ export function metaText(page, now = Date.now()) {
19
+ if (page.state === "failed") return null;
20
+ if (!page.ran_at) return "never ran";
21
+ const took = durationText(page.duration_ms);
22
+ return took ? `ran ${relativeTime(page.ran_at, now)} · ${took}` : `ran ${relativeTime(page.ran_at, now)}`;
23
+ }
24
+
25
+ // "21 Nov, 14:02", in the viewer's own time zone; "" for no time.
26
+ export function resultDate(iso) {
27
+ const t = iso ? Date.parse(iso) : NaN;
28
+ if (Number.isNaN(t)) return "";
29
+ const d = new Date(t);
30
+ const pad = (n) => String(n).padStart(2, "0");
31
+ return `${d.getDate()} ${MONTHS[d.getMonth()]}, ${pad(d.getHours())}:${pad(d.getMinutes())}`;
32
+ }
33
+
34
+ // The failed-run line in three parts, the message drawn as code between
35
+ // them: {lead: "The script failed at line 9: ", message, tail: " Showing the
36
+ // result from 21 Nov, 14:02."}; the tail is "" with no earlier result.
37
+ // null when the last run didn't fail.
38
+ export function failureParts(page) {
39
+ const error = page.state === "failed" ? page.error : null;
40
+ if (!error) return null;
41
+ const lead = Number.isInteger(error.line) ? `The script failed at line ${error.line}: ` : "The script failed: ";
42
+ const tail = page.ran_at ? ` Showing the result from ${resultDate(page.ran_at)}.` : "";
43
+ return { lead, message: String(error.message ?? ""), tail };
44
+ }
45
+
46
+ // The changed line (Scene 4), or null: shown when the result came from an
47
+ // older script, unless the last run failed on the script as it is now
48
+ // (then the failure line says enough).
49
+ export function changedText(page, now = Date.now()) {
50
+ if (!page.changed || !page.ran_at) return null;
51
+ if (page.state === "failed" && !page.changed_after_failure) return null;
52
+ const when = page.script_changed_at ? ` ${relativeTime(page.script_changed_at, now)}` : "";
53
+ return `The script changed${when}. This is the result of the earlier version; Refresh runs the new one.`;
54
+ }
55
+
56
+ // What Copy the error copies: "line 9: message", then the script's last
57
+ // words when the run's answer carried them.
58
+ export function errorCopy(page, stderr = "") {
59
+ const error = page.error;
60
+ if (!error) return "";
61
+ const head = Number.isInteger(error.line) ? `line ${error.line}: ${error.message}` : String(error.message);
62
+ return stderr ? `${head}\n\n${stderr.trimEnd()}` : head;
63
+ }
64
+
65
+ // Whether the blocks on screen are a kept result under a failure (dimmed).
66
+ export function keptAfterFailure(page) {
67
+ return page.state === "failed" && !!page.ran_at;
68
+ }
@@ -0,0 +1,24 @@
1
+ // A page's place in the URL: #/p/NAME (docs/pages.md). Pure, so the hash
2
+ // rules are testable where app.js is not. hashIntent (hash_intent.js) is
3
+ // not changed: views.js reads a page hash before the session intent, and
4
+ // a page hash is "keep" to it.
5
+
6
+ const PAGE_HASH = /^#\/p\/([^/?#]+)$/;
7
+
8
+ export function pageHash(name) {
9
+ return `#/p/${name}`;
10
+ }
11
+
12
+ // The NAME in +hash+ as it is written (never decoded: a name that isn't one
13
+ // opens the view's "no such page"), or null when it isn't a page hash.
14
+ export function pageNameFromHash(hash = "") {
15
+ const m = PAGE_HASH.exec(hash || "");
16
+ return m ? m[1] : null;
17
+ }
18
+
19
+ // The page +hash+ opens for this viewer, or null: never on a participant's
20
+ // page and never without the pages capability (the null-control rule).
21
+ export function openPageName(hash, { participant = null, canPages = false } = {}) {
22
+ if (participant || !canPages) return null;
23
+ return pageNameFromHash(hash);
24
+ }
@@ -0,0 +1,74 @@
1
+ // A page's table block as a lit template (docs/pages.md; page_table_model.js
2
+ // has its rules). Desktop: a real <table> in a box that scrolls sideways
3
+ // when it must, a column header sorts by that column (aria-sort), numbers
4
+ // right-aligned in tabular figures, the total row at the bottom whatever
5
+ // the sort, "N more rows were dropped" under it. Phone (decision D2 A): each
6
+ // row shows its first column and the key columns, and a tap opens the rest
7
+ // as label and value lines; rows keep the script's order there (no sort on
8
+ // a phone); the total is the last row. The view (page_view.js) keeps the
9
+ // sort and the opened rows; a cell reaches the page as text only.
10
+ import { html, nothing } from "./vendor/lit-html.js";
11
+ import { BLANK, cellText, numericColumn, phoneColumns, sortRows } from "./page_table_model.js";
12
+
13
+ const ARIA = { asc: "ascending", desc: "descending" };
14
+ const ARROW = { asc: " ↑", desc: " ↓" };
15
+
16
+ function cell(row, index, block) {
17
+ const text = cellText(row?.[index], block.columns[index]?.format);
18
+ return text === BLANK ? html`<span class="pg-blank">${BLANK}</span>` : text;
19
+ }
20
+
21
+ function droppedLine(block) {
22
+ const n = Number(block.dropped) || 0;
23
+ if (n <= 0) return nothing;
24
+ return html`<div class="pg-note">${n === 1 ? "1 more row was dropped" : `${n} more rows were dropped`}</div>`;
25
+ }
26
+
27
+ function desktop(block, { sort, onSort }) {
28
+ const columns = block.columns || [];
29
+ const numeric = columns.map((_c, i) => numericColumn(block, i));
30
+ const rows = sortRows(block.rows || [], sort ? sort.index : null, sort?.dir);
31
+ const cls = (i) => (numeric[i] && i > 0 ? "pg-num" : "");
32
+ const line = (row, className = "") => html`<tr class=${className}>${columns.map((_c, i) => html`<td class=${cls(i)}>${cell(row, i, block)}</td>`)}</tr>`;
33
+ return html`<div class="pg-table">
34
+ <div class="pg-scroll"><table>
35
+ <thead><tr>${columns.map((column, i) => {
36
+ const on = sort && sort.index === i ? sort.dir : null;
37
+ return html`<th class=${cls(i)} aria-sort=${on ? ARIA[on] : nothing}><button type="button" class="pg-sort"
38
+ @click=${() => onSort(i, numeric[i])}>${String(column.label ?? column.key ?? "")}${on ? ARROW[on] : ""}</button></th>`;
39
+ })}</tr></thead>
40
+ <tbody>${rows.map((row) => line(row))}</tbody>
41
+ ${Array.isArray(block.total) ? html`<tfoot>${line(block.total, "pg-total")}</tfoot>` : nothing}
42
+ </table></div>
43
+ ${droppedLine(block)}
44
+ </div>`;
45
+ }
46
+
47
+ function phone(block, { opened, onToggle }) {
48
+ const columns = block.columns || [];
49
+ const { keys, rest } = phoneColumns(block);
50
+ const label = (i) => String(columns[i]?.label ?? columns[i]?.key ?? "");
51
+ const shown = (row) => html`<span class="pg-k">${cell(row, 0, block)}</span>${keys.map((i) => html`<span class="pg-kv"><span class="pg-lab">${label(i)}</span>${cell(row, i, block)}</span>`)}`;
52
+ const style = `--pg-keys:${keys.length}`;
53
+ return html`<div class="pg-table">
54
+ <div class="pg-rows" role="list">
55
+ ${(block.rows || []).map((row, r) => {
56
+ const open = opened.has(r);
57
+ if (!rest.length) return html`<div class="pg-row" role="listitem"><div class="pg-row-main" style=${style}>${shown(row)}</div></div>`;
58
+ return html`<div class="pg-row ${open ? "open" : ""}" role="listitem">
59
+ <button type="button" class="pg-row-main" style=${style} aria-expanded=${open ? "true" : "false"}
60
+ @click=${() => onToggle(r)}>${shown(row)}</button>
61
+ ${open ? html`<div class="pg-cells">${rest.map((i) => html`<span><em>${label(i)}</em>${cell(row, i, block)}</span>`)}</div>` : nothing}
62
+ </div>`;
63
+ })}
64
+ ${Array.isArray(block.total) ? html`<div class="pg-row pg-total" role="listitem"><div class="pg-row-main" style=${style}>${shown(block.total)}</div></div>` : nothing}
65
+ </div>
66
+ ${droppedLine(block)}
67
+ </div>`;
68
+ }
69
+
70
+ // +phone+: the page's phone width; +sort+ {index, dir} or null and
71
+ // +onSort(index, numeric)+; +opened+ a Set of opened rows and +onToggle(row)+.
72
+ export function tableTemplate(block, { phone: narrow = false, sort = null, onSort = () => {}, opened = new Set(), onToggle = () => {} } = {}) {
73
+ return narrow ? phone(block, { opened, onToggle }) : desktop(block, { sort, onSort });
74
+ }