samagotchi 0.182.0 → 0.184.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 (197) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +107 -1
  3. data/bin/chi +3 -1
  4. data/docs/architecture.md +22 -11
  5. data/docs/bundle-authoring.md +1 -1
  6. data/docs/bundles.md +103 -4
  7. data/docs/cli.md +28 -6
  8. data/docs/configuration.md +4 -2
  9. data/docs/guardrails.md +16 -1
  10. data/docs/internals/block-renderers.md +58 -3
  11. data/docs/internals/bridge.md +14 -6
  12. data/docs/internals/bundles.md +26 -5
  13. data/docs/internals/engine.md +20 -9
  14. data/docs/internals/participants.md +1 -1
  15. data/docs/internals/prompt-caching.md +8 -1
  16. data/docs/internals/remote-sessions.md +40 -5
  17. data/docs/internals/web-frontend.md +96 -31
  18. data/docs/internals/web-push.md +11 -0
  19. data/docs/internals/working-set.md +239 -7
  20. data/docs/mcp-server.md +84 -0
  21. data/docs/memory.md +2 -1
  22. data/docs/plugins.md +309 -22
  23. data/docs/scheduling.md +14 -0
  24. data/docs/sessions.md +4 -4
  25. data/docs/sub-agent.md +9 -0
  26. data/docs/testing.md +3 -1
  27. data/docs/thin-clients.md +165 -0
  28. data/lib/samagotchi/bridge/pending_card.rb +4 -3
  29. data/lib/samagotchi/bridge/sse_writer.rb +16 -15
  30. data/lib/samagotchi/bridge.rb +59 -68
  31. data/lib/samagotchi/bridge_client.rb +12 -4
  32. data/lib/samagotchi/bundle_command/api_calls.rb +1 -1
  33. data/lib/samagotchi/bundle_command/check.rb +55 -20
  34. data/lib/samagotchi/bundle_command.rb +50 -21
  35. data/lib/samagotchi/bundle_manifest.rb +105 -4
  36. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  37. data/lib/samagotchi/bundles/mcp/client.rb +260 -0
  38. data/lib/samagotchi/bundles/mcp/content.rb +107 -0
  39. data/lib/samagotchi/bundles/mcp/http_client.rb +432 -0
  40. data/lib/samagotchi/bundles/mcp/manifest.yml +13 -5
  41. data/lib/samagotchi/bundles/mcp/oauth.rb +814 -0
  42. data/lib/samagotchi/bundles/mcp/plugin.rb +556 -574
  43. data/lib/samagotchi/bundles/mcp/tools.rb +232 -0
  44. data/lib/samagotchi/bundles/system/config_modification_protocol.md +10 -2
  45. data/lib/samagotchi/bundles/system/manifest.yml +3 -3
  46. data/lib/samagotchi/bundles/system/self_map.md +7 -2
  47. data/lib/samagotchi/cli/parent_wait.rb +5 -3
  48. data/lib/samagotchi/command_intake.rb +7 -0
  49. data/lib/samagotchi/commands/registry.rb +8 -3
  50. data/lib/samagotchi/continue_offer.rb +24 -15
  51. data/lib/samagotchi/engine/block_fix.rb +4 -4
  52. data/lib/samagotchi/engine/cards.rb +14 -5
  53. data/lib/samagotchi/engine/events.rb +10 -15
  54. data/lib/samagotchi/engine/models.rb +1 -1
  55. data/lib/samagotchi/engine/plugins.rb +3 -0
  56. data/lib/samagotchi/engine/recap.rb +1 -1
  57. data/lib/samagotchi/engine/session.rb +14 -6
  58. data/lib/samagotchi/engine/side_requests.rb +1 -1
  59. data/lib/samagotchi/engine/sign_in.rb +142 -0
  60. data/lib/samagotchi/engine/turn_end.rb +3 -3
  61. data/lib/samagotchi/engine/turn_helpers.rb +4 -3
  62. data/lib/samagotchi/engine.rb +43 -27
  63. data/lib/samagotchi/engine_snapshots.rb +1 -1
  64. data/lib/samagotchi/guardrail_wiring.rb +3 -1
  65. data/lib/samagotchi/guardrails/protected_paths.rb +51 -2
  66. data/lib/samagotchi/guardrails/verdict.rb +3 -2
  67. data/lib/samagotchi/hold_stop.rb +4 -4
  68. data/lib/samagotchi/idle_recap.rb +19 -11
  69. data/lib/samagotchi/idle_reminders.rb +7 -5
  70. data/lib/samagotchi/idle_scheduler.rb +7 -10
  71. data/lib/samagotchi/installed_bundles/dir.rb +37 -0
  72. data/lib/samagotchi/installed_bundles/manifest.rb +7 -1
  73. data/lib/samagotchi/installed_bundles/plugin_ref.rb +9 -5
  74. data/lib/samagotchi/installed_bundles/record.rb +3 -2
  75. data/lib/samagotchi/installed_bundles/standing.rb +3 -1
  76. data/lib/samagotchi/llm/http.rb +96 -5
  77. data/lib/samagotchi/mcp_command.rb +110 -0
  78. data/lib/samagotchi/mcp_server/http.rb +112 -0
  79. data/lib/samagotchi/mcp_server/protocol.rb +263 -0
  80. data/lib/samagotchi/mcp_server/stdio.rb +93 -0
  81. data/lib/samagotchi/mcp_server/text.rb +155 -0
  82. data/lib/samagotchi/mcp_server/tools.rb +246 -0
  83. data/lib/samagotchi/memory_bundle/asset_installer.rb +40 -12
  84. data/lib/samagotchi/memory_bundle/builder.rb +20 -2
  85. data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
  86. data/lib/samagotchi/memory_bundle/installer.rb +16 -3
  87. data/lib/samagotchi/memory_bundle/provenance.rb +18 -1
  88. data/lib/samagotchi/memory_bundle/shas.rb +6 -4
  89. data/lib/samagotchi/memory_bundle/shipped_update.rb +7 -3
  90. data/lib/samagotchi/memory_bundle/status.rb +15 -6
  91. data/lib/samagotchi/memory_bundle/uninstaller.rb +9 -4
  92. data/lib/samagotchi/model_notes.rb +34 -12
  93. data/lib/samagotchi/plugin/api.rb +6 -1
  94. data/lib/samagotchi/plugin/card.rb +36 -11
  95. data/lib/samagotchi/plugin/context.rb +63 -6
  96. data/lib/samagotchi/plugin/http.rb +40 -15
  97. data/lib/samagotchi/plugin/http_errors.rb +15 -0
  98. data/lib/samagotchi/plugin/http_stream.rb +86 -0
  99. data/lib/samagotchi/plugin/http_transport.rb +58 -16
  100. data/lib/samagotchi/plugin/loader.rb +18 -11
  101. data/lib/samagotchi/plugin/secrets.rb +266 -0
  102. data/lib/samagotchi/plugin/sign_in.rb +392 -0
  103. data/lib/samagotchi/plugin/sse_reader.rb +103 -0
  104. data/lib/samagotchi/prompt_files.rb +11 -4
  105. data/lib/samagotchi/prompt_layout.rb +88 -0
  106. data/lib/samagotchi/prompt_part.rb +82 -20
  107. data/lib/samagotchi/queued_command.rb +28 -4
  108. data/lib/samagotchi/recap_setup.rb +13 -4
  109. data/lib/samagotchi/ref.rb +3 -2
  110. data/lib/samagotchi/relay_verifier.rb +8 -7
  111. data/lib/samagotchi/relay_watcher.rb +4 -4
  112. data/lib/samagotchi/reply_wait.rb +6 -3
  113. data/lib/samagotchi/run_options.rb +2 -1
  114. data/lib/samagotchi/schedule_command.rb +18 -4
  115. data/lib/samagotchi/schedules.rb +40 -8
  116. data/lib/samagotchi/send_command.rb +54 -41
  117. data/lib/samagotchi/session_access/ask.rb +285 -0
  118. data/lib/samagotchi/session_access/contract.rb +5 -0
  119. data/lib/samagotchi/session_access/exchange/token.rb +101 -0
  120. data/lib/samagotchi/session_access/exchange.rb +176 -0
  121. data/lib/samagotchi/session_access/local.rb +34 -6
  122. data/lib/samagotchi/session_access/remote.rb +4 -1
  123. data/lib/samagotchi/session_command_catalog.rb +10 -0
  124. data/lib/samagotchi/session_commands.rb +17 -0
  125. data/lib/samagotchi/session_config.rb +4 -4
  126. data/lib/samagotchi/session_inbox.rb +15 -0
  127. data/lib/samagotchi/session_manager/delivery.rb +8 -4
  128. data/lib/samagotchi/session_observer.rb +27 -0
  129. data/lib/samagotchi/steer_cut.rb +4 -3
  130. data/lib/samagotchi/system_prompt.rb +196 -161
  131. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +4 -1
  132. data/lib/samagotchi/terminal_ui/formatting.rb +15 -0
  133. data/lib/samagotchi/testing/boundary.rb +4 -0
  134. data/lib/samagotchi/testing/bundle.rb +48 -2
  135. data/lib/samagotchi/testing/fake_http.rb +60 -15
  136. data/lib/samagotchi/testing/host.rb +4 -1
  137. data/lib/samagotchi/testing/recorder.rb +45 -5
  138. data/lib/samagotchi/tools/memory.rb +11 -3
  139. data/lib/samagotchi/tools/tool_index.rb +14 -3
  140. data/lib/samagotchi/turn_stages/warmup.rb +2 -2
  141. data/lib/samagotchi/version.rb +1 -1
  142. data/lib/samagotchi/web/app.rb +9 -8
  143. data/lib/samagotchi/web/ask_routes.rb +362 -0
  144. data/lib/samagotchi/web/mcp_route.rb +91 -0
  145. data/lib/samagotchi/web/public/app.js +2 -3
  146. data/lib/samagotchi/web/public/block_frame.js +72 -11
  147. data/lib/samagotchi/web/public/block_host.js +44 -8
  148. data/lib/samagotchi/web/public/block_regions.js +126 -0
  149. data/lib/samagotchi/web/public/card.js +22 -9
  150. data/lib/samagotchi/web/public/card_actions.js +21 -0
  151. data/lib/samagotchi/web/public/card_kinds.js +1 -1
  152. data/lib/samagotchi/web/public/card_registry.js +3 -2
  153. data/lib/samagotchi/web/public/data.js +15 -12
  154. data/lib/samagotchi/web/public/delete_sheet.js +231 -169
  155. data/lib/samagotchi/web/public/diagram_wiring.js +28 -0
  156. data/lib/samagotchi/web/public/format.js +3 -0
  157. data/lib/samagotchi/web/public/index.html +52 -7
  158. data/lib/samagotchi/web/public/more_sheet.js +6 -4
  159. data/lib/samagotchi/web/public/picture_regions.js +243 -0
  160. data/lib/samagotchi/web/public/picture_viewer.js +113 -12
  161. data/lib/samagotchi/web/public/refs.js +5 -3
  162. data/lib/samagotchi/web/public/region_hit.js +144 -0
  163. data/lib/samagotchi/web/public/removal_sheet_model.js +274 -0
  164. data/lib/samagotchi/web/public/running_tasks.js +3 -17
  165. data/lib/samagotchi/web/public/session_actions.js +96 -100
  166. data/lib/samagotchi/web/public/working_set_view.js +167 -21
  167. data/lib/samagotchi/web/public/ws_part_peek.js +277 -0
  168. data/lib/samagotchi/web/public/ws_peek.js +3 -1
  169. data/lib/samagotchi/web/public/ws_preview.css +30 -0
  170. data/lib/samagotchi/web/public/ws_reader.js +7 -3
  171. data/lib/samagotchi/web/public/ws_sections.js +37 -7
  172. data/lib/samagotchi/web/push/notifier.rb +33 -6
  173. data/lib/samagotchi/web/server.rb +1 -1
  174. data/lib/samagotchi/web/session_access_routes.rb +14 -11
  175. data/lib/samagotchi/web/session_control.rb +31 -9
  176. data/lib/samagotchi/web/session_create.rb +2 -2
  177. data/lib/samagotchi/web/session_hub.rb +26 -4
  178. data/lib/samagotchi/web/working_set_routes.rb +93 -5
  179. data/lib/samagotchi/worker/child_side.rb +3 -2
  180. data/lib/samagotchi/worker/command_queue.rb +13 -13
  181. data/lib/samagotchi/worker/leave.rb +3 -3
  182. data/lib/samagotchi/worker/scratch.rb +6 -6
  183. data/lib/samagotchi/worker/signal_grace.rb +6 -5
  184. data/lib/samagotchi/worker/startup.rb +3 -3
  185. data/lib/samagotchi/worker/wake_turns.rb +4 -4
  186. data/lib/samagotchi/worker.rb +32 -21
  187. data/lib/samagotchi/worker_exit_claim.rb +1 -1
  188. data/lib/samagotchi/worker_idle_exit.rb +18 -9
  189. data/lib/samagotchi/worker_inbound.rb +12 -7
  190. data/lib/samagotchi/worker_link.rb +2 -2
  191. data/lib/samagotchi/worker_participant_gate.rb +9 -7
  192. data/lib/samagotchi/worker_task_wakes.rb +7 -5
  193. data/lib/samagotchi/working_set.rb +162 -90
  194. data/lib/samagotchi/working_set_locator.rb +221 -0
  195. data/lib/samagotchi/working_set_own_changes.rb +221 -0
  196. data/lib/samagotchi/working_set_part.rb +281 -0
  197. metadata +36 -1
@@ -1,84 +1,75 @@
1
- // Deleting a link of a session chain (docs/sessions.md, Session chains →
2
- // Deleting a link): Delete on a chained session asks which, instead of the
3
- // browser's confirm. "Delete this link" (first, the default) undoes the
4
- // newest link's continue or splits the chain at a middle one; "Delete the
5
- // whole chain" takes every link. Each says what it leaves behind.
1
+ // The delete sheet (docs/sessions.md, Deleting a session; Session chains →
2
+ // Deleting a link): Delete on any session says, before anything happens,
3
+ // what goes, what is stopped first and what stays, with one button that
4
+ // names the outcome (removal_sheet_model.js has the words). A chained
5
+ // session keeps its two choices: "Delete this link" (first, the default)
6
+ // undoes the newest link's continue or splits the chain at a middle one;
7
+ // "Delete the whole chain" takes every link; each carries its own rows and
8
+ // button words. Archive asks in the same sheet when its 409 says background
9
+ // tasks still run, or why it can't happen now.
6
10
  //
7
11
  // The sheet's words come from GET /api/sessions/:id/delete_plan, the plan
8
12
  // and refusals the server's delete itself runs (SessionChain::Delete::
9
- // Preview), fetched as the sheet opens and only for a chained session: a
10
- // session in no chain keeps today's confirm (session_actions.js). The
11
- // confirmed digest is checked by the delete; a changed plan is re-read and
12
- // shown for a fresh confirmation.
13
+ // Preview), fetched as the sheet opens. The tap sends the shown choice's
14
+ // digest (expect) and, when the choice lists any task, stop_tasks with the
15
+ // running ones' ids: the server stops only those. A changed plan (409
16
+ // plan_changed) or a task that started since (409 tasks_running) is re-read
17
+ // and shown for a fresh tap.
13
18
  //
14
19
  // Where it is drawn (a host): the ⋯ More panel turns into it, with ‹ More to
15
- // go back (more_sheet.js' subview); a card's ✕ opens it at the card, on
16
- // chip_popover.js' shell (createDeleteSheet): a bottom sheet on a phone, a
17
- // popover on a wider window. Pure model and templates plus createDeleteSheet
18
- // and runDeleteFlow, so the specs run them under node --test.
20
+ // go back (more_sheet.js' subview); a card's ✕ (or archive) opens it at the
21
+ // card, on chip_popover.js' shell (createDeleteSheet): a bottom sheet on a
22
+ // phone, a popover on a wider window. Templates plus createDeleteSheet and
23
+ // runDeleteFlow, so the specs run them under node --test.
19
24
 
20
25
  import { html, nothing, render } from "./vendor/lit-html.js";
21
- import { createChipPopover } from "./chip_popover.js";
22
- import { cardName, clip, normalize } from "./format.js";
23
- import { tasksCount, tasksLine } from "./running_tasks.js";
26
+ import { createChipPopover, SHEET_TALL } from "./chip_popover.js";
27
+ import { archiveSheetModel, buttonWords, cantModel, choiceTail, sessionSheetModel, sheetTitle,
28
+ stopTasksOptions, stopsFirst } from "./removal_sheet_model.js";
24
29
 
25
30
  const short = (id) => String(id ?? "").slice(0, 8);
26
31
  const count = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
27
32
 
28
33
  // A session is in a chain when it continues a link, or a listed one
29
- // continues it (the page's list holds archived links too).
34
+ // continues it (the page's list holds archived links too). Unused since every
35
+ // delete reads its plan; kept while an older cached session_actions.js may
36
+ // import it (web-frontend.md, removing an export).
30
37
  export function isChained(session, list = []) {
31
38
  if (!session) return false;
32
39
  if (session.continues) return true;
33
40
  return list.some((s) => s.continues === session.id);
34
41
  }
35
42
 
36
- // The session's name as today's confirm says it (format.js cardName).
37
- function sessionName(session) {
38
- const name = normalize(session ? cardName(session) : "");
39
- return clip(name, 41);
40
- }
41
-
42
- // What this link's own delegates do (D7): stopped ones go, running ones stay.
43
- function delegatesWords(deletes, running, { lead }) {
44
- const parts = [];
45
- if (deletes) parts.push(`${lead}${count(deletes, "stopped delegate")}`);
46
- const goes = parts.length ? `${parts.join("")}` : "";
47
- const stays = running ? `${count(running, "running delegate")} ${running === 1 ? "keeps" : "keep"} running on ${running === 1 ? "its" : "their"} own` : "";
48
- return { goes, stays };
49
- }
50
-
51
- function thisLinkLines(link) {
52
- const { goes, stays } = delegatesWords(link.deletes, link.left_running, { lead: "its " });
43
+ // The link's own first lines (what comes back, how the chain splits, what
44
+ // goes), then what is stopped first and what stays (choiceTail).
45
+ function thisLinkLines(link, id) {
46
+ const goes = { cls: "dim", text: `Goes: its turns${link.deletes ? ` and its ${count(link.deletes, "stopped delegate")}` : ""}.` };
47
+ let main;
53
48
  if (link.previous_id) {
54
49
  const took = [link.moved && count(link.moved, "delegate"), link.notes && count(link.notes, "unread note")].filter(Boolean);
55
- const main = `Undoes the continue: ${short(link.previous_id)} comes back to the lists (not started)` +
56
- (took.length ? `, with what this link took over from it — its ${took.join(" and ")}.` : ".");
57
- const own = [goes ? `its turns and ${goes}` : "its turns"].join("");
58
- return [main, `What this link did itself goes: ${own}.${stays ? ` Its ${stays}.` : ""}`];
59
- }
60
- let main;
61
- if (link.next_id) {
50
+ main = `Undoes the continue: ${short(link.previous_id)} comes back to the lists (not started)` +
51
+ (took.length ? `, with its ${took.join(" and ")}.` : ".");
52
+ } else if (link.next_id) {
62
53
  const earlier = link.earlier ? `${count(link.earlier, "earlier link")} ${link.earlier === 1 ? "stays" : "stay"} archived, and ` : "";
63
- main = `The chain splits: ${earlier}${short(link.next_id)} goes on as a chain of its own.`;
54
+ main = `The chain splits: ${earlier}${short(link.next_id)} goes on as a chain of its own. Nothing is undone.`;
64
55
  } else {
65
- main = "The earlier links stay as they are.";
56
+ main = "The earlier links stay as they are. Nothing is undone.";
66
57
  }
67
- const rest = [goes && `${goes.charAt(0).toUpperCase()}${goes.slice(1)} ${link.deletes === 1 ? "goes" : "go"} with it.`,
68
- stays && `${stays.charAt(0).toUpperCase()}${stays.slice(1)}.`].filter(Boolean).join(" ");
69
- return [main, `Nothing is undone.${rest ? ` ${rest}` : ""}`];
58
+ return [{ cls: "", text: main }, goes, ...choiceTail(link, id)];
70
59
  }
71
60
 
72
- function chainLines(plan) {
61
+ function chainLines(plan, id) {
73
62
  const { chain } = plan;
74
63
  const delegates = chain.deletes ? ` and their ${count(chain.deletes, "stopped delegate")}` : "";
75
- const running = chain.left_running
76
- ? ` ${count(chain.left_running, "running delegate")} ${chain.left_running === 1 ? "keeps" : "keep"} running on ${chain.left_running === 1 ? "its" : "their"} own.`
77
- : "";
78
- const lines = [plan.cut_off
79
- ? `These ${count(chain.links, "link")}${delegates ? `, ${delegates.trim()}` : ""}.${running}`
80
- : `All ${count(chain.links, "link")}${delegates}.${running}`];
81
- return lines;
64
+ const text = plan.cut_off ? `Goes: these ${count(chain.links, "link")}${delegates}.` : `Goes: all ${count(chain.links, "link")}${delegates}.`;
65
+ return [{ cls: "dim", text }, ...choiceTail(chain, id)];
66
+ }
67
+
68
+ // The stopped delegates a choice deletes with it (its ids; an older plan's
69
+ // count): its button counts them (case 2's rule, every session the tap takes).
70
+ function stoppedDelegates(choice) {
71
+ const ids = choice?.delegates?.delete;
72
+ return Array.isArray(ids) ? ids.length : choice?.deletes || 0;
82
73
  }
83
74
 
84
75
  // Why a choice can't be taken now, in the sheet's words; a schedule says it
@@ -89,41 +80,38 @@ function refusedWhy(refusal) {
89
80
  return refusal.message || "Not now.";
90
81
  }
91
82
 
92
- // The sheet's model for +session+ from its delete plan (the route's JSON).
93
- // @return {title, sub, banner, choices: [{act, label, lines, warn, disabled, why, primary}], foot}
94
- export function deleteChoices(session, plan) {
83
+ // The sheet's model for +session+ from its delete plan (the route's JSON);
84
+ // +sessions+ the page's list (it names the delegates).
85
+ // A session in no chain: removal_sheet_model.js sessionSheetModel ({title,
86
+ // groups, button, stops, foot, tasks}, or the Can't delete view {title, sub,
87
+ // close}). A chained one: {title, sub, banner, choices: [{act, label, lines,
88
+ // warn, disabled, why, primary, stops, tasks}], foot}.
89
+ export function deleteChoices(session, plan, sessions = []) {
95
90
  const id = session?.id ?? plan.session_id;
96
- const name = sessionName(session);
91
+ if (!plan.chained) return sessionSheetModel(session ?? { id }, plan, sessions);
97
92
  const link = plan.link || {};
98
93
  const chain = plan.chain || {};
99
94
  // The chain's words first: they say the schedule runs this chain.
100
95
  const scheduled = [chain.refusal, link.refusal].find((r) => r && /scheduled$/.test(r.reason));
101
96
  return {
102
- title: `Delete ${short(id)}${name ? ` — "${name}"` : ""}?`,
97
+ title: sheetTitle("Delete", id, session),
103
98
  sub: `It is link ${plan.position} of ${plan.size} of its chain. This can't be undone.`,
104
99
  banner: scheduled ? `${scheduled.message.charAt(0).toUpperCase()}${scheduled.message.slice(1)}.` : null,
105
100
  choices: [
106
- { act: "this", label: "Delete this link", lines: thisLinkLines(link), primary: true,
107
- disabled: !!link.refusal && link.refusal.reason !== "delegate_unmovable", why: refusedWhy(link.refusal) },
108
- { act: "chain", label: `Delete the whole chain · ${count(chain.links, "session")}`, lines: chainLines(plan),
101
+ { act: "this", label: buttonWords(link, { object: "this link", sessions: 1 + stoppedDelegates(link) }), lines: thisLinkLines(link, id), primary: true,
102
+ disabled: !!link.refusal && link.refusal.reason !== "delegate_unmovable", why: refusedWhy(link.refusal),
103
+ stops: stopsFirst(link), tasks: link.tasks || null },
104
+ { act: "chain", label: buttonWords(chain, { object: "the whole chain", sessions: (chain.links || 0) + stoppedDelegates(chain) }), lines: chainLines(plan, id),
109
105
  warn: plan.cut_off ? "Earlier links, cut off by a deleted link, are kept (archived)." : null,
110
- disabled: !!chain.refusal, why: refusedWhy(chain.refusal) },
106
+ disabled: !!chain.refusal, why: refusedWhy(chain.refusal), stops: stopsFirst(chain), tasks: chain.tasks || null },
111
107
  ],
112
108
  foot: "Running workers are stopped first.",
113
109
  };
114
110
  }
115
111
 
116
- function unchainedChoices(session, plan) {
117
- const id = session?.id ?? plan?.session_id;
118
- const name = sessionName(session);
119
- return {
120
- title: `Delete ${short(id)}${name ? ` — "${name}"` : ""}?`,
121
- sub: "This session is no longer in a chain. This can't be undone.",
122
- banner: null,
123
- choices: [{ act: "this", label: "Delete this session", lines: ["Its turns and session data will be permanently deleted."],
124
- primary: true }],
125
- foot: "This can't be undone.",
126
- };
112
+ function lineTemplate(line, i) {
113
+ if (typeof line === "string") return html`<span class=${i ? "ds-line dim" : "ds-line"}>${line}</span>`;
114
+ return html`<span class=${line.cls ? `ds-line ${line.cls}` : "ds-line"}>${line.text}</span>`;
127
115
  }
128
116
 
129
117
  function choiceTemplate(choice) {
@@ -133,7 +121,7 @@ function choiceTemplate(choice) {
133
121
  ><span class="ds-label">${choice.label}</span><span class="ds-line">${choice.why}</span></button>`;
134
122
  }
135
123
  return html`<button type="button" class=${cls} data-act=${`del:${choice.act}`}
136
- ><span class="ds-label">${choice.label}</span>${choice.lines.map((line, i) => html`<span class=${i ? "ds-line dim" : "ds-line"}>${line}</span>`)
124
+ ><span class="ds-label">${choice.label}</span>${choice.lines.map(lineTemplate)
137
125
  }${choice.warn ? html`<span class="ds-line warn">${choice.warn}</span>` : nothing}</button>`;
138
126
  }
139
127
 
@@ -145,9 +133,42 @@ function headTemplate(back) {
145
133
  : html`<div class="ds-head"><span></span><button type="button" class="ctx-pop-close" data-act="del:cancel" aria-label="Close">×</button></div>`;
146
134
  }
147
135
 
148
- // The choices (a lit-html template). +busy+: a delete under way (every
149
- // button off); +back+: drawn in the More panel.
150
- export function deleteSheetTemplate(model, { back = false, busy = false, notice = null } = {}) {
136
+ // A row's line: its parts (a string, {b} bold, {dim}).
137
+ function partsTemplate(parts) {
138
+ return parts.map((part) => {
139
+ if (typeof part === "string") return part;
140
+ if (part.b) return html`<b>${part.b}</b>`;
141
+ return html`<span class="dim">${part.dim}</span>`;
142
+ });
143
+ }
144
+
145
+ function groupsTemplate(groups) {
146
+ return html`<ul class="ds-groups">${groups.map((g) => html`<li class="ds-group" data-group=${g.key}
147
+ ><span class=${`ds-k ${g.key}`}>${g.label}</span><span class="ds-v">${g.lines.map((line, i) => html`${i ? html`<br>` : nothing}${partsTemplate(line)}`)}</span></li>`)}</ul>`;
148
+ }
149
+
150
+ // One session's sheet (a session in no chain, archive's ask) or the Can't …
151
+ // view. +busy+: the tap under way (its button says Stopping… / Deleting…).
152
+ function singleTemplate(model, { back, busy, notice, act }) {
153
+ const going = model.warn ? "Archiving…" : "Deleting…";
154
+ return html`<div class=${`delete-sheet${busy ? " busy" : ""}`}>${headTemplate(back)}
155
+ <div class="ds-title">${model.title}</div>
156
+ ${model.sub ? html`<div class="ds-sub">${model.sub}</div>` : nothing}
157
+ ${notice ? html`<div class="ds-banner">${notice}</div>` : nothing}
158
+ ${model.groups ? groupsTemplate(model.groups) : nothing}
159
+ <div class="ds-acts">${model.close ? nothing : html`<button type="button" class=${`ds-go ${model.warn ? "warn" : "danger"}`}
160
+ data-act=${`del:${act}`} ?disabled=${busy}>${busy ? (model.stops ? "Stopping…" : going) : model.button}</button>`
161
+ }<button type="button" class="ds-cancel" data-act="del:cancel" ?disabled=${busy}>${model.close ? "Close" : "Cancel"}</button></div>
162
+ ${model.foot ? html`<div class="ds-foot"><span class="ds-note">${model.foot}</span></div>` : nothing}
163
+ </div>`;
164
+ }
165
+
166
+ // The sheet (a lit-html template) for deleteChoices' model, or archive's.
167
+ // +busy+: a delete under way (every button off); +back+: drawn in the More
168
+ // panel; +notice+: a banner above (the plan changed); +act+: the one
169
+ // button's data-act name ("this"; "archive" for archive's).
170
+ export function deleteSheetTemplate(model, { back = false, busy = false, notice = null, act = "this", stopping = false } = {}) {
171
+ if (!model.choices) return singleTemplate(model, { back, busy, notice, act });
151
172
  const allOff = model.choices.every((c) => c.disabled);
152
173
  return html`<div class=${`delete-sheet${busy ? " busy" : ""}`}>${headTemplate(back)}
153
174
  <div class="ds-title">${model.title}</div>
@@ -155,8 +176,8 @@ export function deleteSheetTemplate(model, { back = false, busy = false, notice
155
176
  ${notice ? html`<div class="ds-banner">${notice}</div>` : nothing}
156
177
  ${model.banner ? html`<div class="ds-banner">${model.banner}</div>` : nothing}
157
178
  <div class="ds-choices" ?inert=${busy}>${model.choices.map(choiceTemplate)}</div>
158
- <div class="ds-foot">${allOff ? html`<span></span>` : html`<span class="ds-note">${busy ? "Deleting…" : model.foot}</span>`}
159
- <button type="button" class="ds-cancel" data-act="del:cancel" ?disabled=${busy}>${allOff ? "Close" : "Cancel"}</button></div>
179
+ <div class="ds-acts"><button type="button" class="ds-cancel" data-act="del:cancel" ?disabled=${busy}>${allOff ? "Close" : "Cancel"}</button></div>
180
+ ${allOff ? nothing : html`<div class="ds-foot"><span class="ds-note">${busy ? (stopping ? "Stopping…" : "Deleting…") : model.foot}</span></div>`}
160
181
  </div>`;
161
182
  }
162
183
 
@@ -167,22 +188,10 @@ export function loadingTemplate({ back = false } = {}) {
167
188
 
168
189
  // A refused delete, in the sheet: a moved delegate that can't go back
169
190
  // (delegate_unmovable: "Stop its worker, then delete" only when the page
170
- // can stop it, not a one-turn run's), background tasks the delete takes
171
- // still running (tasks_running: "Stop them and delete"), or any other
172
- // refusal's own words.
173
- // @param refusal {reason, message, ids, stoppable, tasks, sessionId}
191
+ // can stop it, not a one-turn run's), or any other refusal's own words.
192
+ // @param refusal {reason, message, ids, stoppable, sessionId}
174
193
  // @param previousId the link the delegate would go back to
175
194
  export function refusalModel(refusal, previousId = null) {
176
- if (refusal?.reason === "tasks_running") {
177
- const n = tasksCount(refusal.tasks);
178
- return {
179
- title: "Background tasks still running",
180
- text: `${count(n, "background task")} this delete takes ${n === 1 ? "is" : "are"} still running: ` +
181
- `${tasksLine(refusal.tasks, refusal.sessionId)}. Nothing was deleted.`,
182
- stop: { label: n === 1 ? "Stop it and delete" : "Stop them and delete",
183
- line: `${n === 1 ? "It is" : "They are"} stopped (TERM, then KILL after 3 s), then the session goes.` },
184
- };
185
- }
186
195
  if (refusal?.reason === "delegate_unmovable") {
187
196
  const id = (refusal.ids || [])[0];
188
197
  const back = previousId ? short(previousId) : "the previous link";
@@ -201,39 +210,16 @@ export function refusalModel(refusal, previousId = null) {
201
210
  return { title: "Not deleted", text: refusal?.message || "The delete was refused.", stop: null };
202
211
  }
203
212
 
204
- export function refusalTemplate(model, { back = false } = {}) {
213
+ export function refusalTemplate(model, { back = false, busy = false } = {}) {
205
214
  return html`<div class="delete-sheet">${headTemplate(back)}
206
215
  <div class="ds-title">${model.title}</div>
207
216
  <div class="ds-sub">${model.text}</div>
208
217
  ${model.stop ? html`<div class="ds-choices"><button type="button" class="ds-choice primary" data-act="del:stop"
209
- ><span class="ds-label">${model.stop.label}</span><span class="ds-line dim">${model.stop.line}</span></button></div>` : nothing}
210
- <div class="ds-foot"><span></span><button type="button" class="ds-cancel" data-act="del:cancel">${model.stop ? "Cancel" : "Close"}</button></div>
218
+ ?disabled=${busy}><span class="ds-label">${busy ? "Stopping…" : model.stop.label}</span><span class="ds-line dim">${model.stop.line}</span></button></div>` : nothing}
219
+ <div class="ds-acts"><button type="button" class="ds-cancel" data-act="del:cancel" ?disabled=${busy}>${model.stop ? "Cancel" : "Close"}</button></div>
211
220
  </div>`;
212
221
  }
213
222
 
214
- // The toast after a delete (D1/D5's words). +which+: "this" or "chain";
215
- // +result+: the route's 200; +plan+: the sheet's.
216
- // @return {text, back} (back: the link to offer opening, or null)
217
- export function deleteToast(which, result, plan, id) {
218
- if (which === "chain") {
219
- const left = (result.left || []).length;
220
- const links = Math.max(0, (plan.chain?.links ?? 0) - left);
221
- const delegates = Math.max(0, (result.deleted || []).length - links);
222
- let text = `Deleted the chain: ${count(links, "session")}${delegates ? ` and ${count(delegates, "delegate")}` : ""}.`;
223
- const running = (result.left_running || []).length;
224
- if (running) text += ` ${count(running, "running delegate")} ${running === 1 ? "was" : "were"} left on ${running === 1 ? "its" : "their"} own.`;
225
- if (left) text += ` ${count(left, "link")} kept: ${result.refusal}`;
226
- return { text, back: null };
227
- }
228
- const back = (result.unarchived || [])[0] || null;
229
- if (!back) return { text: `Deleted ${short(id)}.`, back: null };
230
- // The sheet's count (each moved delegate with its subtree) when it had one.
231
- const moved = (result.moved_back || []).length ? (plan.link?.moved || result.moved_back.length) : 0;
232
- const took = [moved && count(moved, "delegate"),
233
- plan.link?.notes && count(plan.link.notes, "note")].filter(Boolean);
234
- return { text: `Deleted ${short(id)}. ${short(back)} is back${took.length ? `, with ${took.join(" and ")}` : ""}.`, back };
235
- }
236
-
237
223
  // The list after a delete: the deleted ids gone, the ones back in the lists
238
224
  // not archived (session_actions.js' markArchived's flip).
239
225
  export function listAfterDelete(list, result) {
@@ -242,82 +228,143 @@ export function listAfterDelete(list, result) {
242
228
  return list.filter((s) => !gone.has(s.id)).map((s) => (back.has(s.id) ? { ...s, archived: false } : s));
243
229
  }
244
230
 
231
+ const CHANGED = { delete: "What this deletes changed; check again.", archive: "What this archives changed; check again." };
232
+
245
233
  // The flow in a +host+ ({show(template), close(), back: whether it is the
246
- // More panel}): reads the plan, shows the choices, runs the one chosen, and
234
+ // More panel}): reads the plan, shows the sheet, runs the choice tapped, and
247
235
  // shows a refusal in place. +act+ is wired by the host to the returned
248
- // handler. Hooks: api {deletePlan, deleteSession, deleteChain, stopSession};
249
- // done(which, result, plan) after a delete; plain() when the plan says no
250
- // chain (today's confirm); failed(error) when the plan can't be read.
236
+ // handler. Hooks: api {deletePlan, deleteSession, deleteChain, stopSession;
237
+ // archive(id, opts) for +archive+}; done(which, result, plan) after a
238
+ // delete (which: "this", "chain", "archive"); +sessions+ the page's list
239
+ // (names). +archive+: archive's ask from its first 409 (+archive.refusal+):
240
+ // no plan is read, the button archives stopping the named tasks.
241
+ // failed(error): a plan that can't be read, said in the sheet too; or a tap
242
+ // refused after its sheet was closed, drawn nowhere.
251
243
  // @return {act(name)} the host's handler for its data-act="del:*"
252
- export function runDeleteFlow({ id, session, host, api, done, plain, failed }) {
244
+ export function runDeleteFlow({ id, session, host, api, done, failed = () => {}, sessions = [], archive = null }) {
253
245
  let plan = null;
254
246
  let model = null;
255
247
  let notice = null;
256
248
  let refusal = null;
257
249
  let busy = false;
250
+ let stopping = false;
258
251
  const back = !!host.back;
252
+ const op = archive ? "archive" : "delete";
259
253
  // Whether +host+ still shows this flow: another session's sheet opened in
260
254
  // the same shell since (a second card's ✕, the More panel on another
261
255
  // session) takes it, and this flow then draws and acts on nothing.
262
256
  const live = () => (host.live ? host.live() : true);
263
257
  const show = (tpl) => { if (live()) host.show(tpl); };
264
258
 
265
- const showChoices = () => show(deleteSheetTemplate(model, { back, busy, notice }));
266
- const showRefusal = () => show(refusalTemplate(refusalModel(refusal, plan?.link?.previous_id), { back }));
259
+ const list = () => (typeof sessions === "function" ? sessions() : sessions);
260
+ const showSheet = () => show(deleteSheetTemplate(model, { back, busy, notice, stopping, act: archive ? "archive" : "this" }));
261
+ const showRefusal = (busyRefusal = false) =>
262
+ show(refusalTemplate(refusalModel(refusal, plan?.link?.previous_id), { back, busy: busyRefusal }));
263
+ // A plan that can't be read: why, in the sheet, and only Close.
264
+ const cant = (error) => {
265
+ busy = false;
266
+ model = cantModel(op, id, error);
267
+ notice = null;
268
+ showSheet();
269
+ failed(error);
270
+ };
267
271
 
268
- show(loadingTemplate({ back }));
269
- api.deletePlan(id).then((read) => {
270
- if (!live()) return;
271
- if (!read?.chained) { host.close(); plain(); return; }
272
- plan = read;
273
- model = deleteChoices(session, plan);
274
- showChoices();
275
- }, (error) => { if (live()) { host.close(); failed(error); } });
272
+ if (archive) {
273
+ model = archiveSheetModel(session ?? { id }, archive.refusal, list());
274
+ showSheet();
275
+ } else {
276
+ show(loadingTemplate({ back }));
277
+ api.deletePlan(id).then((read) => {
278
+ if (!live()) return;
279
+ plan = read;
280
+ model = deleteChoices(session, plan, list());
281
+ showSheet();
282
+ }, (error) => { if (live()) cant(error); });
283
+ }
276
284
 
277
285
  // The refusal as the delete's 409 says it; whether the page can stop a
278
286
  // moved delegate's worker is its +stoppable+, as the delete saw it.
279
- // A tasks_running refusal keeps its tasks and the choice it refused
280
- // (+which+), so "Stop them and delete" sends that choice again.
281
- function refused(error, which) {
287
+ function refused(error) {
282
288
  refusal = { reason: error.code, message: error.message, ids: error.body?.ids || [], stoppable: error.body?.stoppable === true,
283
- tasks: error.body?.tasks || null, sessionId: id, which };
289
+ sessionId: id };
284
290
  busy = false;
285
291
  showRefusal();
286
292
  }
287
293
 
288
- // +stopTasks+: the same choice and digest, the tasks stopped first.
289
- async function run(which, { stopTasks = false } = {}) {
290
- if (busy || !live()) return;
294
+ // The choice tapped (+which+), what it shows: its digest and its tasks.
295
+ function chosen(which) {
296
+ if (!model) return null;
297
+ if (!model.choices) return model.close ? null : { tasks: model.tasks, stops: model.stops, digest: plan?.link?.digest };
298
+ const choice = model.choices.find((c) => c.act === which);
299
+ if (!choice || choice.disabled) return null;
300
+ return { tasks: choice.tasks, stops: choice.stops, digest: which === "chain" ? plan?.chain?.digest : plan?.link?.digest };
301
+ }
302
+
303
+ async function sendDelete(which) {
304
+ const choice = chosen(which);
305
+ if (!choice) return;
291
306
  busy = true;
292
- showChoices();
307
+ stopping = !!choice.stops;
308
+ showSheet();
309
+ const tasks = stopTasksOptions(choice.tasks);
293
310
  try {
294
- const digest = which === "chain" ? plan?.chain?.digest : plan?.link?.digest;
295
- const opts = stopTasks ? { expect: digest, stopTasks: true } : { expect: digest };
296
- const result = which === "chain" ? await api.deleteChain(id, opts) : await api.deleteSession(id, opts);
311
+ let result;
312
+ if (archive) result = await api.archive(id, tasks);
313
+ else {
314
+ const opts = { expect: choice.digest, ...tasks };
315
+ result = which === "chain" ? await api.deleteChain(id, opts) : await api.deleteSession(id, opts);
316
+ }
297
317
  if (live()) host.close();
298
318
  done(which, result, plan);
299
319
  } catch (error) {
300
- if (error.code === "plan_changed") {
301
- await refreshPlan();
320
+ // The sheet was closed while the tap ran (×, ‹ More, Esc): nothing
321
+ // happened, and the caller says why (session_actions.js: a sticky toast).
322
+ if (!live()) {
323
+ busy = false;
324
+ failed(error);
302
325
  return;
303
326
  }
304
- refused(error, which);
327
+ if (error.code === "plan_changed" || error.code === "tasks_running") {
328
+ await refreshPlan(error);
329
+ return;
330
+ }
331
+ if (archive) {
332
+ busy = false;
333
+ model = archiveSheetModel(session ?? { id }, error, list());
334
+ notice = null;
335
+ showSheet();
336
+ return;
337
+ }
338
+ refused(error);
305
339
  }
306
340
  }
307
341
 
308
- async function refreshPlan() {
342
+ async function run(which) {
343
+ if (busy || !live()) return;
344
+ await sendDelete(which);
345
+ }
346
+
347
+ // The sheet as it is now, with "changed; check again" on top: the plan
348
+ // read again (a delete), or the 409's own tasks (an archive's).
349
+ async function refreshPlan(error) {
350
+ if (archive) {
351
+ busy = false;
352
+ model = archiveSheetModel(session ?? { id }, error, list());
353
+ notice = CHANGED.archive;
354
+ showSheet();
355
+ return;
356
+ }
309
357
  show(loadingTemplate({ back }));
310
358
  try {
311
359
  const read = await api.deletePlan(id);
312
360
  if (!live()) return;
313
361
  plan = read;
314
- model = read?.chained ? deleteChoices(session, plan) : unchainedChoices(session, plan);
315
- notice = "What this deletes changed; check again";
316
- busy = false;
317
- showChoices();
318
- } catch (error) {
362
+ model = deleteChoices(session, plan, list());
363
+ notice = CHANGED.delete;
319
364
  busy = false;
320
- if (live()) { host.close(); failed(error); }
365
+ showSheet();
366
+ } catch (readError) {
367
+ if (live()) cant(readError);
321
368
  }
322
369
  }
323
370
 
@@ -328,35 +375,39 @@ export function runDeleteFlow({ id, session, host, api, done, plain, failed }) {
328
375
  if (busy || !live()) return;
329
376
  const ids = refusal?.ids || [];
330
377
  busy = true;
378
+ showRefusal(true);
331
379
  for (const child of ids) {
332
380
  let released = false;
333
381
  try {
334
382
  released = (await api.stopSession(child))?.released === true;
335
383
  } catch (_) { released = false; }
336
384
  if (!released) {
337
- refusal = { reason: "still_stopping", message: `${short(child)}'s worker is still running; try again in a moment.`, ids };
338
385
  busy = false;
386
+ const message = `${short(child)}'s worker is still running; try again in a moment.`;
387
+ if (!live()) {
388
+ failed(Object.assign(new Error(message), { code: "still_stopping", body: { ids } }));
389
+ return;
390
+ }
391
+ refusal = { reason: "still_stopping", message, ids };
339
392
  showRefusal();
340
393
  return;
341
394
  }
342
395
  }
343
- busy = false;
344
- run("this");
396
+ await sendDelete("this");
345
397
  }
346
398
 
347
399
  return {
348
400
  act(name) {
349
401
  if (!live()) return;
350
402
  if (name === "cancel") host.close();
351
- else if (name === "this" || name === "chain") run(name);
352
- else if (name === "stop" && refusal?.reason === "tasks_running") run(refusal.which, { stopTasks: true });
403
+ else if (name === "this" || name === "chain" || name === "archive") run(name);
353
404
  else if (name === "stop") stopThenDelete();
354
405
  },
355
406
  };
356
407
  }
357
408
 
358
- // A card's ✕: the flow on a popover of its own at the card (a bottom sheet
359
- // on a phone). One shell for every card: +openFor+ is the session it shows,
409
+ // A card's ✕ (or its archive): the flow on a popover of its own at the
410
+ // card (a bottom sheet on a phone); ⋯ when the open session's. One shell for every card: +openFor+ is the session it shows,
360
411
  // and only the newest host is live (a ✕ on another card while one's plan is
361
412
  // read takes the shell; the first flow's late answer draws nothing).
362
413
  // @return {host(anchorEl, id): a host for runDeleteFlow, close, isOpen, pop}
@@ -365,12 +416,21 @@ export function createDeleteSheet({ doc = globalThis.document, win = globalThis.
365
416
  let handler = null;
366
417
  let current = null;
367
418
  let openFor = null;
419
+ // Focus on the way out, so a stray Enter never deletes or archives: the ×
420
+ // while the plan is read, then Cancel once it shows (once per open).
421
+ let toCancel = false;
422
+ const settleFocus = () => {
423
+ if (!toCancel) return;
424
+ const cancel = shell.pop.querySelector(".ds-cancel:not([disabled])");
425
+ if (cancel) toCancel = false;
426
+ (cancel || shell.pop.querySelector(".ctx-pop-close"))?.focus();
427
+ };
368
428
  const shell = createChipPopover({
369
- id: "deleteSheet", className: "ctx-popover delete-pop", width: 420, el, anchor: "[data-del]", openers: "[data-del]",
370
- summary: () => view, sheet: true, label: "Delete the session?", doc, win,
429
+ id: "deleteSheet", className: "ctx-popover delete-pop", width: 420, el, anchor: "[data-del]", openers: "[data-del], #infoDeleteBtn",
430
+ summary: () => view, sheet: true, sheetShare: SHEET_TALL, label: "Delete or archive the session", doc, win,
371
431
  show: (tpl) => render(tpl, shell.pop),
372
- onOpen: () => shell.pop.querySelector(".ds-choice:not([disabled]), .ds-cancel")?.focus(),
373
- onClose: () => { view = null; handler = null; current = null; openFor = null; },
432
+ onOpen: () => { toCancel = true; settleFocus(); },
433
+ onClose: () => { view = null; handler = null; current = null; openFor = null; toCancel = false; },
374
434
  onAct: (act) => {
375
435
  const [what, name] = act.split(":");
376
436
  if (what === "del") handler?.act(name);
@@ -385,8 +445,10 @@ export function createDeleteSheet({ doc = globalThis.document, win = globalThis.
385
445
  show(tpl) {
386
446
  if (current !== me) return;
387
447
  view = tpl;
388
- if (shell.isOpen()) render(tpl, shell.pop);
389
- else shell.open(anchorEl);
448
+ if (shell.isOpen()) {
449
+ render(tpl, shell.pop);
450
+ settleFocus();
451
+ } else shell.open(anchorEl);
390
452
  },
391
453
  close() { if (current === me) shell.close(); },
392
454
  wire(next) { if (current === me) handler = next; },
@@ -0,0 +1,28 @@
1
+ // The drawn diagrams' wiring, so app.js holds one line of it (its size cap):
2
+ // the block host (block_host.js) with the picture viewer as its openPicture, and
3
+ // the viewer closed on a system theme change (the diagram behind is redrawn; the
4
+ // viewer holds the old picture). docs/internals/block-renderers.md.
5
+ //
6
+ // The viewer is made by app.js, not here: createSessionView reads it at once,
7
+ // before this runs (boot order). Its regions' layer (picture_regions.js) is made
8
+ // here and given to it; an older cached picture_viewer.js has no useLayer and
9
+ // shows pictures as before.
10
+ //
11
+ // A module of its own: static JS is cached at unversioned URLs.
12
+
13
+ import { createBlockHost } from "./block_host.js";
14
+ import { createRegionLayer } from "./picture_regions.js";
15
+
16
+ // @param roots the turn roots
17
+ // @param sessionId () => the open session's id
18
+ // @param drawers the core drawers (inline_widgets.js), asked before the bundles'
19
+ // @param renderers false for a page without the bundles' renderers (a participant's)
20
+ // @param pictures the picture viewer (picture_viewer.js createPictureViewer)
21
+ // @return {host, layer} the block host and the regions' layer
22
+ export function wireDiagrams({ roots, sessionId, drawers = [], renderers = true, pictures, win = window, doc = document, ...hostOpts }) {
23
+ const host = createBlockHost({ roots, sessionId, drawers, renderers, win, openPicture: (p, o) => pictures.open(p, o), ...hostOpts });
24
+ win.matchMedia?.("(prefers-color-scheme: dark)").addEventListener?.("change", () => pictures.close());
25
+ const layer = createRegionLayer({ doc, win });
26
+ pictures.useLayer?.(layer);
27
+ return { host, layer };
28
+ }
@@ -84,6 +84,9 @@ const DELETE_PREVIEW_CHARS = 40;
84
84
  // The confirm before deleting a session (the info bar's and a card's). The
85
85
  // list's owner can be stale (a worker idle-exits), so a worker is only
86
86
  // "stopped if it's still running", never promised.
87
+ // Unused since the delete sheet (delete_sheet.js); kept while an older
88
+ // cached session_actions.js may import it (web-frontend.md); goes at the
89
+ // next release.
87
90
  export function deleteConfirmText(session) {
88
91
  const n = normalize(cardName(session));
89
92
  const preview = clip(n, DELETE_PREVIEW_CHARS + 1);