samagotchi 0.195.0 → 0.196.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -1
  3. data/docs/architecture.md +2 -1
  4. data/docs/bundle-authoring.md +23 -23
  5. data/docs/bundles.md +11 -3
  6. data/docs/cli.md +4 -0
  7. data/docs/context.md +13 -3
  8. data/docs/guardrails.md +6 -4
  9. data/docs/hooks.md +3 -1
  10. data/docs/internals/block-renderers.md +4 -1
  11. data/docs/internals/engine.md +2 -1
  12. data/docs/internals/knowledge.md +15 -5
  13. data/docs/internals/participants.md +15 -3
  14. data/docs/internals/peers.md +12 -8
  15. data/docs/internals/session-lifecycle.md +26 -12
  16. data/docs/internals/web-frontend.md +64 -27
  17. data/docs/pages.md +1 -1
  18. data/docs/peers.md +1 -1
  19. data/docs/plugins.md +73 -3
  20. data/docs/sessions.md +1 -1
  21. data/docs/system-one.md +3 -1
  22. data/lib/samagotchi/bundle_manifest.rb +30 -5
  23. data/lib/samagotchi/bundles/core/manifest.yml +2 -2
  24. data/lib/samagotchi/bundles/cost-cap/manifest.yml +4 -4
  25. data/lib/samagotchi/bundles/cost-cap/plugin.rb +54 -3
  26. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  27. data/lib/samagotchi/bundles/github-pr/manifest.yml +4 -2
  28. data/lib/samagotchi/bundles/knowledge/chi_adapters.rb +43 -25
  29. data/lib/samagotchi/bundles/knowledge/manifest.yml +6 -4
  30. data/lib/samagotchi/bundles/knowledge/plugin.rb +37 -18
  31. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  32. data/lib/samagotchi/context_change.rb +44 -0
  33. data/lib/samagotchi/context_note.rb +1 -1
  34. data/lib/samagotchi/context_providers.rb +14 -0
  35. data/lib/samagotchi/context_sources.rb +3 -25
  36. data/lib/samagotchi/engine/plugins.rb +21 -0
  37. data/lib/samagotchi/events.rb +1 -0
  38. data/lib/samagotchi/guardrails/pair_boundary.rb +12 -4
  39. data/lib/samagotchi/guardrails/targets.rb +24 -2
  40. data/lib/samagotchi/installed_bundles/manifest.rb +7 -1
  41. data/lib/samagotchi/memory_bundle/builder.rb +2 -1
  42. data/lib/samagotchi/memory_bundle/installed_copy.rb +2 -1
  43. data/lib/samagotchi/participants.rb +17 -6
  44. data/lib/samagotchi/peer_exchanges.rb +1 -2
  45. data/lib/samagotchi/peer_note.rb +38 -5
  46. data/lib/samagotchi/peer_presence.rb +20 -7
  47. data/lib/samagotchi/plugin/api.rb +5 -1
  48. data/lib/samagotchi/plugin/chips.rb +125 -0
  49. data/lib/samagotchi/plugin/context.rb +19 -1
  50. data/lib/samagotchi/plugin/peer_pairing.rb +2 -2
  51. data/lib/samagotchi/plugin/peer_start.rb +1 -1
  52. data/lib/samagotchi/plugin/peers.rb +5 -2
  53. data/lib/samagotchi/plugin/tool_spec.rb +19 -9
  54. data/lib/samagotchi/schedules.rb +8 -2
  55. data/lib/samagotchi/session_access/local.rb +34 -33
  56. data/lib/samagotchi/session_chain/sharing.rb +79 -0
  57. data/lib/samagotchi/session_chain/successor.rb +4 -2
  58. data/lib/samagotchi/session_chips.rb +133 -0
  59. data/lib/samagotchi/session_inbox_delivery.rb +11 -11
  60. data/lib/samagotchi/session_manager/emptiness.rb +4 -1
  61. data/lib/samagotchi/session_observer.rb +1 -1
  62. data/lib/samagotchi/session_stats.rb +5 -4
  63. data/lib/samagotchi/session_stores.rb +3 -0
  64. data/lib/samagotchi/speaker.rb +228 -0
  65. data/lib/samagotchi/steer.rb +36 -132
  66. data/lib/samagotchi/testing/bundle.rb +5 -0
  67. data/lib/samagotchi/testing/host.rb +1 -0
  68. data/lib/samagotchi/testing/recorder.rb +10 -0
  69. data/lib/samagotchi/tools/registry.rb +8 -3
  70. data/lib/samagotchi/turn_excerpts.rb +8 -4
  71. data/lib/samagotchi/version.rb +1 -1
  72. data/lib/samagotchi/web/app.rb +21 -10
  73. data/lib/samagotchi/web/participant_view.rb +1 -1
  74. data/lib/samagotchi/web/peer_routes.rb +5 -2
  75. data/lib/samagotchi/web/plugin_chip_rows.rb +39 -0
  76. data/lib/samagotchi/web/public/agent_rows.js +1 -0
  77. data/lib/samagotchi/web/public/app.js +17 -25
  78. data/lib/samagotchi/web/public/chains.js +0 -26
  79. data/lib/samagotchi/web/public/command_list.js +2 -3
  80. data/lib/samagotchi/web/public/composer.js +2 -3
  81. data/lib/samagotchi/web/public/composer_mount.js +3 -6
  82. data/lib/samagotchi/web/public/context_chips.js +240 -93
  83. data/lib/samagotchi/web/public/context_groups.js +84 -0
  84. data/lib/samagotchi/web/public/draft_follow.js +33 -0
  85. data/lib/samagotchi/web/public/drafts.js +26 -22
  86. data/lib/samagotchi/web/public/index.html +32 -0
  87. data/lib/samagotchi/web/public/peer_chip_kind.js +49 -0
  88. data/lib/samagotchi/web/public/peer_note.js +2 -2
  89. data/lib/samagotchi/web/public/peer_row.js +10 -5
  90. data/lib/samagotchi/web/public/peer_wait.js +4 -2
  91. data/lib/samagotchi/web/public/plugin_chip.js +55 -0
  92. data/lib/samagotchi/web/public/plugin_chip_kind.js +48 -0
  93. data/lib/samagotchi/web/public/send_turn.js +8 -21
  94. data/lib/samagotchi/web/public/session_actions.js +10 -23
  95. data/lib/samagotchi/web/public/session_view.js +7 -3
  96. data/lib/samagotchi/web/public/stream_handlers.js +2 -0
  97. metadata +12 -1
@@ -0,0 +1,33 @@
1
+ // A draft follows a continue made anywhere: the terminal's /continue, a
2
+ // chain schedule, chi send --continues, another tab. This tab's own
3
+ // Continue → hands its draft over itself (session_actions.js, with the
4
+ // opener); a continue made elsewhere shows up here only as the next link's
5
+ // card in the hub's list (its `continues`), so app.js asks, on each hub
6
+ // snapshot and session event and when a session is left (session_view.js
7
+ // forgetSession), which drafts to hand over: drafts.follow(from, to), no
8
+ // opener (a next link with a draft of its own keeps it).
9
+ //
10
+ // A module of its own: new exports go in new modules (web-frontend.md).
11
+ import { chainLinks } from "./chains.js";
12
+
13
+ // The [from, to] pairs to hand over: for each listed session that continues
14
+ // +from+, the newest listed link of +from+'s chain (chains.js chainLinks, the
15
+ // first-created rule), so A → A' → A'' takes A's draft to A'' in one pass.
16
+ // +skip(id)+: a session whose draft stays where it is (the one on view: its
17
+ // box is never emptied under the user; this tab's in-flight Continue →).
18
+ // +has(id)+: whether the session's draft holds anything. Each +from+ once.
19
+ export function continuedDrafts(sessions, { skip = () => false, has = () => false } = {}) {
20
+ const pairs = [];
21
+ const seen = new Set();
22
+ const byId = new Map(sessions.map((s) => [s.id, s]));
23
+ for (const s of sessions) {
24
+ const from = s.continues;
25
+ if (!from || from === s.id || seen.has(from)) continue;
26
+ seen.add(from);
27
+ if (skip(from) || !has(from)) continue;
28
+ // A link the list doesn't hold (deleted: its draft is dropped, or swept) is none.
29
+ const to = chainLinks(sessions, from, undefined, byId).at(-1)?.id;
30
+ if (to && to !== from) pairs.push([from, to]);
31
+ }
32
+ return pairs;
33
+ }
@@ -30,7 +30,7 @@
30
30
  //
31
31
  // @return {text(key), chips(key), has(key), setText(key, text, opts),
32
32
  // putBack(key, text), clear(key), putChips(key, list), move(from, to),
33
- // handOver(from, to, opener), drop(key), show(key),
33
+ // handOver(from, to, opener), follow(from, to), drop(key), show(key),
34
34
  // syncFromView(), sending(key, line), settle(key, line)}
35
35
  // A module of its own: new exports go in new modules (web-frontend.md).
36
36
  import { COMPOSER_DRAFT, START_DRAFT } from "./draft_keys.js";
@@ -65,17 +65,6 @@ export function createDrafts({
65
65
  return e;
66
66
  }
67
67
 
68
- // An older cached session_view.js never calls show(): the box stays the one
69
- // for every window, as before, and is the draft of the window on view (an
70
- // empty box over a draft kept for it paints that draft).
71
- function heal() {
72
- const key = shownKey();
73
- if (painted === null || key === painted) return;
74
- painted = key;
75
- if (!promptEl.value.trim() && !view.chips().length && hasKept(entry(key))) paint(key);
76
- }
77
- const hasKept = (e) => !!(e.text.trim() || e.chips.length);
78
-
79
68
  function paint(key) {
80
69
  const e = entry(key);
81
70
  promptEl.value = e.text;
@@ -116,12 +105,10 @@ export function createDrafts({
116
105
  }
117
106
 
118
107
  function text(key = shownKey()) {
119
- heal();
120
108
  return key === painted ? promptEl.value : entry(key).text;
121
109
  }
122
110
 
123
111
  function chips(key = shownKey()) {
124
- heal();
125
112
  return key === painted ? view.chips() : entry(key).chips;
126
113
  }
127
114
 
@@ -134,7 +121,6 @@ export function createDrafts({
134
121
  // composer for this visit first, +focus+ gives the box the focus,
135
122
  // +caretEnd+ puts the caret at the end.
136
123
  function setText(key, value, { reveal: open = false, focus = false, caretEnd = false } = {}) {
137
- heal();
138
124
  const next = String(value ?? "");
139
125
  if (key === painted) {
140
126
  if (open) reveal.openForVisit?.();
@@ -164,7 +150,6 @@ export function createDrafts({
164
150
 
165
151
  // +key+'s chips become +list+ (a chip left out frees its preview).
166
152
  function putChips(key, list) {
167
- heal();
168
153
  if (key === painted) {
169
154
  view.setChips(list);
170
155
  return;
@@ -193,7 +178,6 @@ export function createDrafts({
193
178
  // under +to+'s and its chips after them. +from+ is emptied, its saved copy
194
179
  // gone.
195
180
  function move(from, to) {
196
- heal();
197
181
  if (from === to) return;
198
182
  const movedText = text(from);
199
183
  const movedChips = chips(from).slice();
@@ -219,17 +203,38 @@ export function createDrafts({
219
203
  // Continue →: +from+'s draft goes to the next link +to+ (text or chips:
220
204
  // the whole draft, from emptied); an empty one leaves +to+ the +opener+
221
205
  // (none: nothing). A link with a draft of its own (one continued already)
222
- // keeps it.
206
+ // keeps it; one that holds +from+'s very text (another tab's follow moved
207
+ // it first: images stay in the tab that added them) takes +from+'s chips
208
+ // too, and +from+ empties.
223
209
  function handOver(from, to, opener = null) {
224
- if (has(to)) return;
210
+ if (has(to)) {
211
+ const moved = text(from).trim();
212
+ if (moved && text(to).trim() === moved) {
213
+ if (chips(from).length) putChips(to, chips(to).concat(chips(from)));
214
+ empty(from);
215
+ }
216
+ return;
217
+ }
225
218
  if (has(from)) move(from, to);
226
219
  else if (opener) setText(to, opener);
227
220
  }
228
221
 
222
+ // A continue made elsewhere (draft_follow.js): +from+'s draft to +to+ as
223
+ // handOver, no opener, +from+'s text first read again from storage when
224
+ // this tab hasn't changed it since it last read it: another tab may have
225
+ // typed on (or moved it: then nothing moves from here).
226
+ function follow(from, to) {
227
+ const e = kept.get(from);
228
+ if (from !== painted && e && !e.sent && e.text === e.base) {
229
+ e.text = stored(from);
230
+ e.base = e.text;
231
+ }
232
+ handOver(from, to, null);
233
+ }
234
+
229
235
  // +key+'s draft forgotten, here and in storage (its session was deleted):
230
236
  // its previews freed.
231
237
  function drop(key) {
232
- heal();
233
238
  freePreviews(chips(key));
234
239
  if (key === painted) {
235
240
  promptEl.value = "";
@@ -256,7 +261,6 @@ export function createDrafts({
256
261
 
257
262
  // The box's input: saved as the draft on view.
258
263
  function syncFromView() {
259
- heal();
260
264
  if (painted !== null) save(painted);
261
265
  }
262
266
 
@@ -274,5 +278,5 @@ export function createDrafts({
274
278
  save(key);
275
279
  }
276
280
 
277
- return { text, chips, has, setText, putBack, clear, putChips, move, handOver, drop, show, syncFromView, sending, settle };
281
+ return { text, chips, has, setText, putBack, clear, putChips, move, handOver, follow, drop, show, syncFromView, sending, settle };
278
282
  }
@@ -1525,7 +1525,13 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1525
1525
  #infoBar .ctx-chip.open{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}@media(hover:hover){#infoBar .ctx-chip:hover{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}}
1526
1526
  #infoBar .ctx-chip.empty{color:var(--text-faint);border-style:dashed}
1527
1527
  #infoBar .ctx-chip.error{color:var(--danger-text);border-color:color-mix(in srgb,var(--danger) 55%,transparent);background:var(--danger-bg-dim)}
1528
+ /* A bundle's own chip (plugin_chip.js) asking for attention: core's warn look, kept when it is open or hovered. */
1529
+ #infoBar .ctx-chip.warn,#infoBar .ctx-chip.warn.open{color:var(--warn-text);background:var(--warn-bg);border-color:var(--warn-border)}
1530
+ @media(hover:hover){#infoBar .ctx-chip.warn:hover{color:var(--warn-text);background:var(--warn-bg);border-color:var(--warn-border)}}
1528
1531
  .ctx-dot{width:7px;height:7px;border-radius:50%;background:var(--accent);box-shadow:0 0 0 2px var(--accent-ring)}
1532
+ /* A group's chip (context_groups.js): "PRs 3 · 2m", its count brighter; in a red chip the chip's own colour. */
1533
+ #infoBar .ctx-chip .ctx-count{color:var(--text);font-weight:700}
1534
+ #infoBar .ctx-chip.error .ctx-count{color:inherit}
1529
1535
  /* A paired peer's one chip (peer_chip.js): waiting in the accent, can't send in warn, answers only dashed. */
1530
1536
  #infoBar .ctx-chip.peer.waiting{color:var(--text);background:var(--accent-bg);border-color:var(--accent-border)}
1531
1537
  #infoBar .ctx-chip.peer.cant-send{color:var(--warn-text);background:var(--warn-bg);border-color:var(--warn-border)}
@@ -1771,6 +1777,32 @@ button.peer-pop-x{cursor:pointer}@media(hover:hover){button.peer-pop-x:hover .pp
1771
1777
  @media(hover:hover){.ctx-pop-actions button:hover{color:var(--text-hover)}}
1772
1778
  .ctx-pop-actions .ctx-pop-detach{color:var(--text-muted);background:transparent}
1773
1779
  @media(hover:hover){.ctx-pop-actions .ctx-pop-detach:hover{color:var(--danger-text);border-color:color-mix(in srgb,var(--danger) 55%,transparent)}}
1780
+ /* A group's list (context_groups.js): a button per source (name, one-line summary or failure, age and dot), and its
1781
+ member's way back. Own class names: .ctx-pop-* is shared with the working set's and the settings' popovers. */
1782
+ .ctx-group-rows{display:flex;flex-direction:column;margin:2px -6px 0}
1783
+ .ctx-group-row{display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:8px;align-items:center;width:100%;padding:8px 6px;border:none;border-top:1px solid var(--border);border-radius:8px;background:transparent;color:var(--text-2);font:inherit;text-align:left;cursor:pointer}
1784
+ .ctx-group-row:first-child{border-top:none}
1785
+ @media(hover:hover){.ctx-group-row:hover{background:var(--bg-hover)}}
1786
+ .ctx-group-name{font:600 12px/1.4 ui-monospace,monospace;color:var(--text)}
1787
+ .ctx-group-sum{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;color:var(--text-3)}
1788
+ .ctx-group-age{display:inline-flex;align-items:center;gap:6px;font:11px/1.4 ui-monospace,monospace;color:var(--text-muted)}
1789
+ .ctx-group-row.error .ctx-group-name,.ctx-group-row.error .ctx-group-age{color:var(--danger-text)}
1790
+ .ctx-back{flex:none;align-self:center;padding:2px 8px 2px 4px;border:1px solid var(--accent-border);border-radius:6px;background:var(--accent-bg);color:var(--accent);font-size:12px;font-weight:600;line-height:1.5}
1791
+ @media(pointer:coarse){.ctx-group-row{min-height:44px}.ctx-back{min-height:36px}}
1792
+ /* A bundle chip's card (plugin_chip.js): its text (the first paragraph in the text colour, the rest muted, as scene 9
1793
+ has it), up to four buttons in a card's shape (the primary one solid), the hosts its links open. Own class names. */
1794
+ .ctx-plugin-body{display:flex;flex-direction:column;gap:6px;color:var(--text-2);overflow-wrap:anywhere}
1795
+ .ctx-plugin-body>*{margin:0}
1796
+ .ctx-plugin-body>p:first-child{color:var(--text)}
1797
+ .ctx-plugin-body>p+p{font-size:12px;color:var(--text-muted)}
1798
+ .ctx-plugin-body strong{color:var(--text-bright)}
1799
+ .ctx-plugin-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:4px}
1800
+ .ctx-plugin-btn{display:inline-flex;align-items:center;padding:5px 11px;border-radius:7px;border:1px solid var(--border-strong);background:transparent;color:var(--text-2);font-family:inherit;font-size:12px;font-weight:600;line-height:1.4;text-decoration:none;cursor:pointer}
1801
+ .ctx-plugin-btn.primary{background:var(--accent);border-color:var(--accent);color:var(--bg)}
1802
+ @media(hover:hover){.ctx-plugin-btn:hover{color:var(--text-hover);border-color:var(--accent-border)}.ctx-plugin-btn.primary:hover{color:var(--bg);filter:brightness(1.08)}}
1803
+ .ctx-plugin-btn:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
1804
+ .ctx-plugin-opens{font-size:11px;color:var(--text-faint)}
1805
+ @media(pointer:coarse){.ctx-plugin-btn{min-height:44px;padding:10px 12px;border-radius:8px}}
1774
1806
  /* ⋯ (more_sheet.js): on the row at every width, pinned at its end; on a desktop the count of what it holds for the
1775
1807
  row (none at 0), its dot when something folded asks for a look. */
1776
1808
  #infoBar #infoMoreBtn{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:5px;flex:none;min-height:24px;padding:0 8px;font-size:14px;line-height:1;letter-spacing:1px;color:var(--text-3);background:var(--bg-raised);border:1px solid var(--border-strong)}
@@ -0,0 +1,49 @@
1
+ // The peer chips as a kind of the session bar's context chips (context_chips.js asks its kinds instead of
2
+ // branching on peer or source): one chip per peer the peers model (peer_data.js, GET …/peers) names as paired
3
+ // (peer_chip.js) or waited for (peer_wait.js), their popovers, and a message's read. A wrapper: the chips, their
4
+ // popovers and their words stay in those two modules. docs/internals/web-frontend.md, The peer exchange. Its own
5
+ // module: new exports go in new modules.
6
+
7
+ import { peerChipModel, peerGroups, peerKey, peerPopoverTemplate } from "./peer_chip.js";
8
+ import { waitingChipModel, waitingPopoverTemplate } from "./peer_wait.js";
9
+
10
+ // Wider than a source's (its actions on one line), and a bottom sheet in a phone's window (scene 2).
11
+ const SHAPE = Object.freeze({ width: 440, sheet: true, className: "peer-pop" });
12
+
13
+ // The peer kind. +peers+(): the peers model (null: none, no peer chips); +peerActions+: {status(name), drawn(id)}
14
+ // (context_chips.js createContextChips); +api+: {message(id, name, serial, box)}; +sessionId+(): the open session.
15
+ // @return a chip kind (context_chips.js), with peerOf(key): the peer of a chip's key, or null
16
+ export function createPeerChipKind({ peers = () => null, peerActions = {}, api, sessionId }) {
17
+ const peerList = () => peerGroups(peers()?.peers?.() || []);
18
+ const peerOf = (key) => peerList().find((peer) => peer.key === key) || null;
19
+ const exchangesOf = (name) => peers()?.peer?.(name)?.exchanges || [];
20
+
21
+ return {
22
+ // A peer waited for and not paired yet: the waiting chip.
23
+ chips: (now) => peerList().map((peer) => (peer.peer.paired_at ? peerChipModel(peer, exchangesOf(peer.name), now)
24
+ : waitingChipModel(peer, now))),
25
+ owns: (key) => !!peerOf(key),
26
+ popover(key, { text, now }) {
27
+ const peer = peerOf(key);
28
+ if (!peer.peer.paired_at) return waitingPopoverTemplate(peer, now);
29
+ return peerPopoverTemplate(peer, exchangesOf(peer.name), {
30
+ text, now, status: peerActions.status?.(peer.name) || null, drawn: (id) => !!peerActions.drawn?.(id),
31
+ });
32
+ },
33
+ label: (key) => peerOf(key).label,
34
+ shape: SHAPE,
35
+ // A message's text: +serial+, default the newest; none without a message.
36
+ readText(key, { serial = null, box = null } = {}) {
37
+ const peer = peerOf(key);
38
+ const number = serial ?? peer?.peer.messages?.[0]?.serial;
39
+ if (!peer || number === null || number === undefined) return null;
40
+ return { name: `${peer.label}'s message #${number}`, read: () => api.message(sessionId(), peer.name, number, box) };
41
+ },
42
+ // At a session's open: the peers read (reusing the conversation's read if loaded or in flight).
43
+ onLoad: () => { peers()?.refresh?.({ reuse: true }); },
44
+ // Its chips count down or age ("waiting 8 min", "waiting 2m"): the minute's tick redraws them, sources or not.
45
+ ticks: () => peerList().length > 0,
46
+ keyFor: peerKey,
47
+ peerOf,
48
+ };
49
+ }
@@ -50,7 +50,7 @@ export function peerSummaryText(note) {
50
50
  }
51
51
 
52
52
  // The bubble for +note+ (a context note with `peer`: {peer, label, re,
53
- // summary, serial, verdict, agreed, inline}).
53
+ // summary, serial, verdict, said, agreed, inline}).
54
54
  export function peerNoteTemplate(note) {
55
55
  const peer = note.peer || {};
56
56
  const name = peer.label || peer.peer || "Your peer";
@@ -67,5 +67,5 @@ export function peerNoteTemplate(note) {
67
67
  : rendered ? html`<div class="peer-text markdown md-compact" data-peer-md=${block.text}>${unsafeHTML(rendered)}</div>`
68
68
  : html`<div class="peer-text" data-peer-md=${block.text}>${block.text}</div>`;
69
69
  const told = block ? block.rest : (note.content ?? "");
70
- return html`<div class=${cls} title=${fullTime(note.at) || nothing} data-opening-id=${opening} data-peer-source=${attr(source)} data-peer-name=${attr(peer.peer)} data-peer-re=${attr(peer.re)} data-peer-serial=${attr(peer.serial)} data-peer-box=${attr(peer.box)} data-peer-inline=${block ? "1" : nothing}><div class="peer-head"><span class="peer-who">${name} answered</span><span class="peer-up-slot" data-peer-slot="up"></span>${verdictTemplate(peer)}</div><div class="note-text" data-fallback=${String(peer.summary ?? "").trim() ? nothing : "1"}>${peerSummaryText(note)}</div>${body}<div class="peer-foot"><span class="peer-full-slot" data-peer-slot="full"></span><details class="peer-told"><summary>what chi told the agent</summary><div class="peer-told-text">${told}</div></details></div></div>`;
70
+ return html`<div class=${cls} title=${fullTime(note.at) || nothing} data-opening-id=${opening} data-peer-source=${attr(source)} data-peer-name=${attr(peer.peer)} data-peer-re=${attr(peer.re)} data-peer-serial=${attr(peer.serial)} data-peer-box=${attr(peer.box)} data-peer-said=${attr(peer.said)} data-peer-inline=${block ? "1" : nothing}><div class="peer-head"><span class="peer-who">${name} answered</span><span class="peer-up-slot" data-peer-slot="up"></span>${verdictTemplate(peer)}</div><div class="note-text" data-fallback=${String(peer.summary ?? "").trim() ? nothing : "1"}>${peerSummaryText(note)}</div>${body}<div class="peer-foot"><span class="peer-full-slot" data-peer-slot="full"></span><details class="peer-told"><summary>what chi told the agent</summary><div class="peer-told-text">${told}</div></details></div></div>`;
71
71
  }
@@ -9,7 +9,10 @@
9
9
  import { verdictWord } from "./peer_exchange.js";
10
10
 
11
11
  // PeerNote::VERDICT, the Ruby side's: `VERDICT CHANGES`, `VERDICT: OK`; a
12
- // copied template's `VERDICT OK|CHANGES` is none.
12
+ // copied template's `VERDICT OK|CHANGES` is none. It and summaryWithoutVerdict
13
+ // stay for notes saved before the payload carried `said` and an older
14
+ // worker's live notes: remove two releases on (a pre-said note's row then says
15
+ // its verdict twice, cosmetic). spec/fixtures/peer_said_cases.json pins both sides.
13
16
  const VERDICT = /\bVERDICT:?\s*([A-Z]+)(?![A-Za-z|])/g;
14
17
 
15
18
  const squash = (s) => s.replace(/\s+/g, " ").trim();
@@ -28,10 +31,12 @@ export function summaryWithoutVerdict(summary, verdict) {
28
31
 
29
32
  // The row's words: {name, verdict, summary, size}. +verdict+: the server's
30
33
  // word (OK, CHANGES, UNSURE) or none; +summary+: the summary the peer sent,
31
- // or none; +first+: the first line of the peer's text (no summary);
32
- // +lines+: the peer's text's lines, null with no text.
33
- export function peerRowWords({ name = "", verdict = null, summary = "", first = "", lines = null } = {}) {
34
- const said = summaryWithoutVerdict(summary, verdict);
34
+ // or none; +said+: the server's summary without its verdict (PeerNote.said,
35
+ // the payload's `said`), else made here from +summary+; +first+: the first
36
+ // line of the peer's text (no summary); +lines+: the peer's text's lines,
37
+ // null with no text.
38
+ export function peerRowWords({ name = "", verdict = null, summary = "", said: given, first = "", lines = null } = {}) {
39
+ const said = typeof given === "string" ? given : summaryWithoutVerdict(summary, verdict);
35
40
  const size = lines === null || lines === undefined ? "" : `${lines} line${lines === 1 ? "" : "s"}`;
36
41
  return { name: squash(String(name ?? "")), verdict: verdictWord(verdict), summary: said || squash(String(first ?? "")), size };
37
42
  }
@@ -5,9 +5,11 @@
5
5
 
6
6
  import { html } from "./vendor/lit-html.js";
7
7
 
8
- // The peer's app as its bundle words it (chi web loads no plugins); else its label.
8
+ // The peer's app as its bundle words it: the waiting row's `app` (the wait mark's, PeerWaiting; chi web loads no
9
+ // plugins); else its label. APPS: the N-1 fallback for a wait an older worker wrote (it lives 10 minutes), remove in
10
+ // the release after next.
9
11
  const APPS = { claude: "Claude Code" };
10
- const appOf = (group) => APPS[group?.name] || group?.label || group?.name || "peer";
12
+ const appOf = (group) => group?.peer?.app || APPS[group?.name] || group?.label || group?.name || "peer";
11
13
 
12
14
  // The whole minutes left until +until+ (rounded up, at least 1 while it waits); 0 past it or unparsable.
13
15
  export function waitMinutesLeft(until, now = Date.now()) {
@@ -0,0 +1,55 @@
1
+ // A bundle's own chip in the session bar (ctx.chips, docs/plugins.md, Chips): GET …/context's `chips`, each a label
2
+ // (with an age that ticks when the bundle gave a time), one of core's three looks (ok, warn, error), an optional dot,
3
+ // and a small card a tap opens: the chip's name and bundle, the bundle's text (its body_html, rendered and sanitised
4
+ // by the server as a card's) and up to four buttons, each a session command or an http(s) link whose host is named
5
+ // under them. A chip with no text and no buttons opens nothing. Pure: a chip in, a model or a template out; the kind
6
+ // that holds them is plugin_chip_kind.js. docs/internals/web-frontend.md, The plugin chips.
7
+ //
8
+ // It reuses the chips' ageText: an import cycle, safe since it is called only at call time (as context_groups.js).
9
+
10
+ import { html, nothing } from "./vendor/lit-html.js";
11
+ import { unsafeHTML } from "./vendor/directives/unsafe-html.js";
12
+ import { ageText } from "./context_chips.js";
13
+ import { cardActions, cardActionUrl } from "./card_actions.js";
14
+
15
+ const STATES = new Set(["ok", "warn", "error"]);
16
+
17
+ // Whether a chip opens a card: it has text or a button.
18
+ export function pluginChipOpens(chip) {
19
+ return !!chip && (!!String(chip.body_html ?? "").trim() || cardActions(chip).length > 0);
20
+ }
21
+
22
+ // A chip as the strip draws it (chipsTemplate's shape, keyed by its "chip:<bundle>/<name>"): its label, " · 3m"
23
+ // after it when it has a time, its look (an unknown one is plain), its dot, and whether it opens.
24
+ export function pluginChipModel(chip, now = Date.now()) {
25
+ const age = chip.at ? ageText(chip.at, now) : "";
26
+ const label = age ? `${chip.label} · ${age}` : String(chip.label ?? "");
27
+ return { name: chip.key, label, state: STATES.has(chip.state) ? chip.state : "ok", dot: chip.dot === true,
28
+ title: chip.title || label, opens: pluginChipOpens(chip) };
29
+ }
30
+
31
+ // The card a tap opens: the chip's name, its bundle (and how long ago its time was), × ; its text; its buttons (a
32
+ // command one carries its line, data-act "plugin-command"; a url one is a link to a new tab, its host as the
33
+ // tooltip), and a line naming each host the links open, so a label can't hide where it leads.
34
+ export function pluginPopoverTemplate(chip, now = Date.now()) {
35
+ const age = chip.at ? ageText(chip.at, now) : "";
36
+ const kind = age ? `${chip.bundle} · ${age === "now" ? "just now" : `${age} ago`}` : chip.bundle;
37
+ const hosts = [];
38
+ const button = (action) => {
39
+ if (action.command) {
40
+ return html`<button type="button" class=${action.primary ? "ctx-plugin-btn primary" : "ctx-plugin-btn"}
41
+ data-act="plugin-command" data-command=${action.command} title=${action.command}>${action.label || action.command}</button>`;
42
+ }
43
+ const url = cardActionUrl(action);
44
+ const host = new URL(url).host;
45
+ if (!hosts.includes(host)) hosts.push(host);
46
+ return html`<a class="ctx-plugin-btn" href=${url} target="_blank" rel="noopener noreferrer" title=${host}>${action.label}</a>`;
47
+ };
48
+ const actions = cardActions(chip);
49
+ const body = String(chip.body_html ?? "").trim();
50
+ return html`<div class="ctx-pop-head"><strong>${chip.name}</strong><span class="ctx-pop-kind">${kind}</span
51
+ ><button type="button" class="ctx-pop-close" data-act="close" aria-label="Close">×</button></div
52
+ >${body ? html`<div class="ctx-plugin-body">${unsafeHTML(chip.body_html)}</div>` : nothing
53
+ }${actions.length ? html`<div class="ctx-plugin-actions">${actions.map(button)}</div>` : nothing
54
+ }${hosts.length ? html`<div class="ctx-plugin-opens">opens ${hosts.join(", ")}</div>` : nothing}`;
55
+ }
@@ -0,0 +1,48 @@
1
+ // The bundles' own chips as a kind of the session bar's context chips (context_chips.js asks its kinds): the chips
2
+ // GET …/context's read brought (`chips`, drawn after the peer chips and the sources), their cards, and a button's
3
+ // command, sent as a card's button sends (POST …/command with card: true: its reply shows as a bubble, the typed line
4
+ // doesn't; no cache-confirm ask). A wrapper: the model and the card are plugin_chip.js. Its own module: new exports
5
+ // go in new modules. docs/internals/web-frontend.md, The plugin chips.
6
+
7
+ import { pluginChipModel, pluginChipOpens, pluginPopoverTemplate } from "./plugin_chip.js";
8
+ import { cantText } from "./format.js";
9
+
10
+ const SHAPE = Object.freeze({ width: 380, sheet: false, className: null });
11
+
12
+ // The plugin kind. +api+: {command(id, line)} (app.js: sendCommand with card: true, then the woken worker's stream
13
+ // followed); +sessionId+(): the open session; +toast+(text): a failed send.
14
+ // @return a chip kind (context_chips.js), with opens(key), onRead(data), reset() and act(name, target, {close})
15
+ export function createPluginChipKind({ api, sessionId, toast = () => {} }) {
16
+ let chips = [];
17
+ const chipOf = (key) => chips.find((chip) => chip.key === key) || null;
18
+
19
+ return {
20
+ chips: (now) => chips.map((chip) => pluginChipModel(chip, now)),
21
+ owns: (key) => !!chipOf(key),
22
+ // A label-only chip opens nothing.
23
+ opens: (key) => pluginChipOpens(chipOf(key)),
24
+ popover: (key, { now }) => pluginPopoverTemplate(chipOf(key), now),
25
+ label: (key) => chipOf(key)?.name || key,
26
+ shape: SHAPE,
27
+ readText: () => null,
28
+ onLoad() {},
29
+ // A chip with a time ages.
30
+ ticks: () => chips.some((chip) => chip.at),
31
+ keyFor: (key) => key,
32
+ // GET …/context's answer: its chips (none from an older chi web).
33
+ onRead(data) {
34
+ chips = (Array.isArray(data?.chips) ? data.chips : []).filter((chip) => chip && chip.key && chip.label);
35
+ },
36
+ reset() { chips = []; },
37
+ // A button's command: the card closes, the session runs the line; a failure is a toast.
38
+ act(name, target, { close }) {
39
+ if (name !== "plugin-command") return false;
40
+ const line = target.dataset.command;
41
+ const id = sessionId();
42
+ close();
43
+ if (!line || !id || !api.command) return true;
44
+ Promise.resolve().then(() => api.command(id, line)).catch((e) => toast(cantText(`run ${line}`, e)));
45
+ return true;
46
+ },
47
+ };
48
+ }
@@ -24,8 +24,6 @@ import { composerAfterAck, dropEarlyRestores, restoreOnAck } from "./restore.js"
24
24
  // list), clear(key), move(from, to), sending(key, line) and settle(key,
25
25
  // line) (the line in flight, left out of the draft's saved copy until the
26
26
  // send is over)}, and button (Send/Start), fit(), openForVisit(), focus().
27
- // An older cached app.js passes the one box instead: {el (the text box),
28
- // chips(), setChips(list), clear()}; read and written as it is then.
29
27
  // +historyEl+,
30
28
  // +turnDom+; +makeUserBubble(prompt, opts)+, +bubbleById(id)+,
31
29
  // +addCommandBubble(view)+; +addCreatedSession(created)+, +select(id)+,
@@ -49,19 +47,8 @@ export function createSendTurn({
49
47
  leaveGoneSession, runCommand, toast, closesOn = null, alert = (text) => globalThis.alert(text),
50
48
  }) {
51
49
  const actionBtn = composer.button;
52
- // The draft of +key+, read and written by that key (drafts.js); an older
53
- // cached app.js's one box (no text()) for every key.
54
- const drafted = typeof composer.text === "function";
55
- const textOf = (key) => (drafted ? composer.text(key) : composer.el.value);
50
+ const textOf = (key) => composer.text(key);
56
51
  const chipsOf = (key) => composer.chips(key);
57
- function setTextOf(key, text) {
58
- if (drafted) composer.setText(key, text);
59
- else composer.el.value = text; // eslint-disable-line no-restricted-syntax -- an older cached app.js: its one box, no drafts to write through
60
- }
61
- function putChipsOf(key, list) {
62
- if (drafted) composer.putChips(key, list);
63
- else composer.setChips(list);
64
- }
65
52
 
66
53
  // A create's refusal: a picked kit's in the 🧰 list, else an alert.
67
54
  function refused(e) {
@@ -108,7 +95,7 @@ export function createSendTurn({
108
95
  addCreatedSession(s);
109
96
  // The start page's draft is the new session's now, before the page
110
97
  // opens it (a failed create moves nothing).
111
- composer.move?.("", s.id);
98
+ composer.move("", s.id);
112
99
  key = s.id;
113
100
  await select(s.id);
114
101
  } catch (e) {
@@ -157,7 +144,7 @@ export function createSendTurn({
157
144
  inFlight = flight;
158
145
  // Until the ack, the draft's saved copy leaves the line out: a reload
159
146
  // (or an iOS kill) right after Send doesn't bring it back to send again.
160
- composer.sending?.(sentTo, line);
147
+ composer.sending(sentTo, line);
161
148
  try {
162
149
  await uploadChips(sending, sentTo, { upload: api.uploadImage });
163
150
  const verifyAnchor = verify();
@@ -199,11 +186,11 @@ export function createSendTurn({
199
186
  if (restored?.refill && restored.revises && sentTo === session()) restoreRevise(restored.revises);
200
187
  const before = textOf(sentTo);
201
188
  const after = composerAfterAck({ sent: line, current: before, refill: restored?.refill || "" });
202
- setTextOf(sentTo, after);
189
+ composer.setText(sentTo, after);
203
190
  composer.fit();
204
191
  // Only the sent chips go: images added since stay (they go up at their own send).
205
192
  const kept = chipsAfterSend(chipsOf(sentTo), sending);
206
- putChipsOf(sentTo, restored?.images?.length ? kept.concat(restoredChips(sentTo, restored.images)) : kept);
193
+ composer.putChips(sentTo, restored?.images?.length ? kept.concat(restoredChips(sentTo, restored.images)) : kept);
207
194
  // Its turn_enqueued usually tagged the echo already; the ack covers a
208
195
  // worker that wasn't live (no turn_enqueued then).
209
196
  if (ack?.enqueued_id && !echo.dataset.enqueuedId && !bubbleById(ack.enqueued_id)) {
@@ -217,7 +204,7 @@ export function createSendTurn({
217
204
  } catch (e) {
218
205
  // The line is the draft's again, saved as it is (before a gone
219
206
  // session's draft moves to the start page's).
220
- composer.settle?.(sentTo, line);
207
+ composer.settle(sentTo, line);
221
208
  echo.remove();
222
209
  // The turn never reached the worker's queue: an early restore waiting
223
210
  // for its ack is never taken back (4.13), so drop it here. The prompt
@@ -236,7 +223,7 @@ export function createSendTurn({
236
223
  // start-page draft and say where it went.
237
224
  if (e.code === "not_found") {
238
225
  if (sentTo !== session()) {
239
- composer.move?.(sentTo, "");
226
+ composer.move(sentTo, "");
240
227
  toast(`Session ${sentTo.slice(0, 8)} is gone; your message is in the new-session draft`, null, { sticky: true });
241
228
  return;
242
229
  }
@@ -251,7 +238,7 @@ export function createSendTurn({
251
238
  if (REVISE_REFUSALS.includes(e.code) && sentTo === session()) return addCommandBubble({ label: null, line, text: e.body?.detail || e.message, failed: true });
252
239
  toast(cantText("send", e), null, { sticky: true });
253
240
  } finally {
254
- composer.settle?.(sentTo, line);
241
+ composer.settle(sentTo, line);
255
242
  if (inFlight === flight) inFlight = null;
256
243
  actionBtn.disabled = store.current.owner === "tui";
257
244
  composer.focus();
@@ -1,4 +1,4 @@
1
- import { continueRefusal, continuedText, openChildrenTemplate, openerText } from "./chains.js";
1
+ import { continueRefusal, continuedText, openChildrenTemplate } from "./chains.js";
2
2
  import { cantText, goneSessionNotice } from "./format.js";
3
3
  import { tasksStoppedSuffix } from "./running_tasks.js";
4
4
  import { sessionHash } from "./route.js";
@@ -26,19 +26,14 @@ import { deleteToast } from "./removal_sheet_model.js";
26
26
  // +handOverDraft(from, to, created)+ (continue →: the session's draft to the
27
27
  // new link, else the link's opener: drafts.js handOver), +revealDraft()+ (the
28
28
  // open session's draft seen: the composer opens, the box takes the focus,
29
- // the caret at the end); an older cached app.js passes +fillOpener(created,
30
- // continuedId)+ instead (the new link's composer, after its select; returns
31
- // a displaced draft, or null) and +restoreDraft(draft, opener)+ (that draft
32
- // back), kept for it; +closeLiveStream()+ (the live
33
- // stream's close, the stream left as it is) and +workerGone(id)+ the page's;
34
- // +moveDraft(from, to)+ / +dropDraft(id)+ the composer's drafts (drafts.js:
35
- // a gone session's goes to the start page's, a deleted one's is forgotten;
36
- // none passed, an older cached app.js: left as they are).
29
+ // the caret at the end); +closeLiveStream()+ (the live stream's close, the
30
+ // stream left as it is), +workerGone(id)+ the page's, +moveDraft(from, to)+
31
+ // and +dropDraft(id)+ the composer's drafts (drafts.js).
37
32
  // +confirm+: the browser's (Stop's, when nothing else runs).
38
33
  export function createSessionActions({
39
34
  selected, store, sessions, setSessions, api, eventsLive, refresh,
40
- select, clearSelection, showNotice, toast, addCreatedSession, fillOpener, restoreDraft, closeLiveStream, workerGone,
41
- moveDraft = null, dropDraft = null, handOverDraft = null, revealDraft = () => {},
35
+ select, clearSelection, showNotice, toast, addCreatedSession, closeLiveStream, workerGone,
36
+ moveDraft, dropDraft, handOverDraft, revealDraft = () => {},
42
37
  confirm = (text) => globalThis.confirm(text),
43
38
  // The Stop sheet (stop_sheet.js): +open(id, holds)+ shows it and answers
44
39
  // true; nothing to stop (or no sheet wired) is false, and Stop is the
@@ -131,7 +126,7 @@ export function createSessionActions({
131
126
  const gone = new Set(result.deleted || [id]);
132
127
  if (gone.has(selected())) clearSelection();
133
128
  // After the start page opened: the swap saved the deleted one's draft last.
134
- gone.forEach((x) => dropDraft?.(x));
129
+ gone.forEach((x) => dropDraft(x));
135
130
  if (!eventsLive()) refresh();
136
131
  const { text, back, sticky = false } = deleteToast(which, result, plan, id);
137
132
  toast(text, back ? { label: `Open ${back.slice(0, 8)}`, run: () => select(back) } : null, { sticky });
@@ -142,7 +137,7 @@ export function createSessionActions({
142
137
  if (selected() !== id) return;
143
138
  // Its draft isn't lost with it: it goes to the start page's (under what
144
139
  // is there). A delete from this tab drops it instead (afterDelete).
145
- if (!deleting.has(id)) moveDraft?.(id, "");
140
+ if (!deleting.has(id)) moveDraft(id, "");
146
141
  clearSelection();
147
142
  showNotice(goneSessionNotice(id, why));
148
143
  }
@@ -241,7 +236,7 @@ export function createSessionActions({
241
236
  markArchived([id], true);
242
237
  addCreatedSession(created);
243
238
  const next = created.id;
244
- handOverDraft?.(id, next, created);
239
+ handOverDraft(id, next, created);
245
240
  // A model fallback's warning stays until closed.
246
241
  const sticky = !!created.model_warning;
247
242
  if (selected() !== id) {
@@ -249,14 +244,13 @@ export function createSessionActions({
249
244
  return;
250
245
  }
251
246
  await select(next);
252
- if (!handOverDraft) return oldOpener(created, id, sticky, selected() === next);
253
247
  if (selected() === next) revealDraft();
254
248
  toast(continuedText(id, created), null, { sticky });
255
249
  } catch (e) {
256
250
  const refusal = continueRefusal(e, sessions());
257
251
  if (refusal.kind === "open") {
258
252
  // The link that continues it takes the draft only into an empty draft of its own.
259
- handOverDraft?.(id, refusal.id, null);
253
+ handOverDraft(id, refusal.id, null);
260
254
  if (selected() === id) await select(refusal.id);
261
255
  toast(`${short} is continued already: ${selected() === refusal.id ? "opened" : "see"} ${refusal.id.slice(0, 8)}`);
262
256
  } else if (refusal.kind === "children") {
@@ -270,13 +264,6 @@ export function createSessionActions({
270
264
  }
271
265
  }
272
266
 
273
- // An older cached app.js's continue: its fillOpener's guess and Restore draft.
274
- function oldOpener(created, id, sticky, opened) {
275
- const displaced = opened ? fillOpener(created, id) : null;
276
- const restore = displaced ? { label: "Restore draft", run: () => restoreDraft(displaced, openerText(created)) } : null;
277
- toast(continuedText(id, created), restore, { sticky: sticky || !!displaced });
278
- }
279
-
280
267
  // ── Archive ───────────────────────────────────────────────────────────────
281
268
  // Archive hides a session (and its delegates) from the strip and the list,
282
269
  // kept for good; "include archived" in all sessions finds it. No confirm:
@@ -32,9 +32,10 @@
32
32
  // setCapabilities(capabilities, editorUrl, viewer), findInTurnRoots(selector), appendToHistory(el),
33
33
  // setTurnRunning(running), mergeTurnTiming(id, timing), applySessionPayload(data, opts),
34
34
  // turnEndStatus(data), replaceSelectedCard(change)} the page's hooks
35
- // later: {handlers(), composer(), ownerVerify(), commandList(), initTasks(), resetTurnView(), drafts()}
36
- // the views made after this one, and session_sync.js's resetTurnView;
37
- // drafts(): the composer's drafts (drafts.js), swapped with the session
35
+ // later: {handlers(), composer(), ownerVerify(), commandList(), initTasks(), resetTurnView(), drafts(),
36
+ // followContinuedDrafts()} the views made after this one, and session_sync.js's resetTurnView;
37
+ // drafts(): the composer's drafts (drafts.js), swapped with the session;
38
+ // followContinuedDrafts(): a continue made elsewhere takes the left one's draft
38
39
  //
39
40
  // @return {forgetSession, renderSessionView, historyOpts, readTurnEnd, endTurnView, leaveSession}
40
41
  // leaveSession(): what the user opened of the open session's running turn,
@@ -114,6 +115,9 @@ export function createSessionView(deps) {
114
115
  // the visit and the prefs (the grip's draft class and the fit see it).
115
116
  // ?.: an older cached app.js passes no drafts.
116
117
  later.drafts?.()?.show(store.selected ?? "");
118
+ // The session left, continued elsewhere while on view: its draft to the
119
+ // newest link now (draft_follow.js). ?.: an older cached app.js passes none.
120
+ later.followContinuedDrafts?.();
117
121
  later.composer().newVisit();
118
122
  // The reader and the peek are the session's: another one (or none, the
119
123
  // start page) never finds them over #center, the composer inert under it.
@@ -402,6 +402,8 @@ export function createStreamHandlers(deps) {
402
402
  // The session's list changed (objectives_strip.js): an edit waiting, a
403
403
  // list note in, a turn's moves.
404
404
  objectives_updated: (data) => deps.objectivesUpdated?.(data),
405
+ // A bundle's chips changed (ctx.chips): the strip reads GET …/context again.
406
+ chips_updated: () => contextChips?.refresh(),
405
407
  // Someone joined, left or was revoked (the worker's ParticipantsWatch):
406
408
  // the owner's chip and panel read the list again.
407
409
  participants_changed: () => participantsControl?.reload(),