samagotchi 0.181.0 → 0.183.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 (200) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +93 -1
  3. data/bin/chi +4 -1
  4. data/docs/architecture.md +17 -7
  5. data/docs/bundle-authoring.md +1 -1
  6. data/docs/bundles.md +103 -4
  7. data/docs/cli.md +58 -10
  8. data/docs/configuration.md +3 -1
  9. data/docs/guardrails.md +16 -1
  10. data/docs/internals/block-renderers.md +172 -3
  11. data/docs/internals/bridge.md +23 -5
  12. data/docs/internals/bundles.md +21 -4
  13. data/docs/internals/engine.md +29 -8
  14. data/docs/internals/inline-widgets.md +3 -1
  15. data/docs/internals/prompt-caching.md +9 -1
  16. data/docs/internals/remote-sessions.md +38 -7
  17. data/docs/internals/web-frontend.md +116 -26
  18. data/docs/internals/working-set.md +1 -1
  19. data/docs/mcp-server.md +80 -0
  20. data/docs/plugins.md +308 -21
  21. data/docs/sessions.md +7 -4
  22. data/docs/sub-agent.md +9 -0
  23. data/docs/testing.md +3 -1
  24. data/docs/thin-clients.md +146 -0
  25. data/lib/samagotchi/answer_display.rb +3 -2
  26. data/lib/samagotchi/block_fix/stamp.rb +49 -0
  27. data/lib/samagotchi/block_fix.rb +220 -0
  28. data/lib/samagotchi/bridge/block_fix_route.rb +30 -0
  29. data/lib/samagotchi/bridge/pending_card.rb +4 -3
  30. data/lib/samagotchi/bridge/sse_writer.rb +16 -15
  31. data/lib/samagotchi/bridge/turn_drawings.rb +19 -0
  32. data/lib/samagotchi/bridge.rb +69 -69
  33. data/lib/samagotchi/bridge_client.rb +9 -0
  34. data/lib/samagotchi/bundle_command/api_calls.rb +1 -1
  35. data/lib/samagotchi/bundle_command/check.rb +36 -19
  36. data/lib/samagotchi/bundle_command.rb +50 -21
  37. data/lib/samagotchi/bundle_manifest.rb +101 -4
  38. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  39. data/lib/samagotchi/bundles/mcp/client.rb +260 -0
  40. data/lib/samagotchi/bundles/mcp/content.rb +107 -0
  41. data/lib/samagotchi/bundles/mcp/http_client.rb +407 -0
  42. data/lib/samagotchi/bundles/mcp/manifest.yml +13 -5
  43. data/lib/samagotchi/bundles/mcp/oauth.rb +814 -0
  44. data/lib/samagotchi/bundles/mcp/plugin.rb +556 -574
  45. data/lib/samagotchi/bundles/mcp/tools.rb +232 -0
  46. data/lib/samagotchi/bundles/system/config_modification_protocol.md +10 -2
  47. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  48. data/lib/samagotchi/cli/parent_wait.rb +5 -3
  49. data/lib/samagotchi/command_intake.rb +7 -0
  50. data/lib/samagotchi/commands/registry.rb +8 -3
  51. data/lib/samagotchi/config.rb +3 -0
  52. data/lib/samagotchi/continue_intent.rb +8 -0
  53. data/lib/samagotchi/continue_offer.rb +24 -15
  54. data/lib/samagotchi/engine/block_fix.rb +332 -0
  55. data/lib/samagotchi/engine/cards.rb +14 -5
  56. data/lib/samagotchi/engine/events.rb +10 -15
  57. data/lib/samagotchi/engine/models.rb +1 -1
  58. data/lib/samagotchi/engine/plugins.rb +3 -0
  59. data/lib/samagotchi/engine/recap.rb +1 -1
  60. data/lib/samagotchi/engine/side_requests.rb +8 -6
  61. data/lib/samagotchi/engine/sign_in.rb +142 -0
  62. data/lib/samagotchi/engine/turn_end.rb +3 -3
  63. data/lib/samagotchi/engine.rb +47 -27
  64. data/lib/samagotchi/engine_snapshots.rb +1 -1
  65. data/lib/samagotchi/events.rb +1 -0
  66. data/lib/samagotchi/guardrail_wiring.rb +3 -1
  67. data/lib/samagotchi/guardrails/protected_paths.rb +51 -2
  68. data/lib/samagotchi/guardrails/verdict.rb +3 -2
  69. data/lib/samagotchi/hold_stop.rb +4 -4
  70. data/lib/samagotchi/idle_client.rb +10 -6
  71. data/lib/samagotchi/idle_recap.rb +19 -11
  72. data/lib/samagotchi/idle_reminders.rb +7 -5
  73. data/lib/samagotchi/idle_scheduler.rb +7 -10
  74. data/lib/samagotchi/inline_widgets.rb +12 -0
  75. data/lib/samagotchi/installed_bundles/dir.rb +37 -0
  76. data/lib/samagotchi/installed_bundles/manifest.rb +7 -1
  77. data/lib/samagotchi/installed_bundles/plugin_ref.rb +9 -5
  78. data/lib/samagotchi/installed_bundles/record.rb +3 -2
  79. data/lib/samagotchi/installed_bundles/standing.rb +3 -1
  80. data/lib/samagotchi/kernel_loop.rb +7 -5
  81. data/lib/samagotchi/llm/chat_loop.rb +2 -0
  82. data/lib/samagotchi/llm/http.rb +96 -5
  83. data/lib/samagotchi/markdown_parser.rb +28 -0
  84. data/lib/samagotchi/mcp_command.rb +110 -0
  85. data/lib/samagotchi/mcp_server/http.rb +112 -0
  86. data/lib/samagotchi/mcp_server/protocol.rb +244 -0
  87. data/lib/samagotchi/mcp_server/stdio.rb +92 -0
  88. data/lib/samagotchi/mcp_server/text.rb +155 -0
  89. data/lib/samagotchi/mcp_server/tools.rb +245 -0
  90. data/lib/samagotchi/memory_bundle/asset_installer.rb +40 -12
  91. data/lib/samagotchi/memory_bundle/builder.rb +20 -2
  92. data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
  93. data/lib/samagotchi/memory_bundle/installer.rb +16 -3
  94. data/lib/samagotchi/memory_bundle/provenance.rb +18 -1
  95. data/lib/samagotchi/memory_bundle/shas.rb +6 -4
  96. data/lib/samagotchi/memory_bundle/shipped_update.rb +7 -3
  97. data/lib/samagotchi/memory_bundle/status.rb +15 -6
  98. data/lib/samagotchi/memory_bundle/uninstaller.rb +9 -4
  99. data/lib/samagotchi/plugin/api.rb +6 -1
  100. data/lib/samagotchi/plugin/card.rb +36 -11
  101. data/lib/samagotchi/plugin/context.rb +63 -6
  102. data/lib/samagotchi/plugin/http.rb +40 -15
  103. data/lib/samagotchi/plugin/http_errors.rb +15 -0
  104. data/lib/samagotchi/plugin/http_stream.rb +86 -0
  105. data/lib/samagotchi/plugin/http_transport.rb +58 -16
  106. data/lib/samagotchi/plugin/loader.rb +18 -11
  107. data/lib/samagotchi/plugin/secrets.rb +266 -0
  108. data/lib/samagotchi/plugin/sign_in.rb +392 -0
  109. data/lib/samagotchi/plugin/sse_reader.rb +103 -0
  110. data/lib/samagotchi/queued_command.rb +28 -4
  111. data/lib/samagotchi/recap_setup.rb +13 -4
  112. data/lib/samagotchi/ref.rb +3 -2
  113. data/lib/samagotchi/relay_verifier.rb +8 -7
  114. data/lib/samagotchi/relay_watcher.rb +4 -4
  115. data/lib/samagotchi/run_options.rb +2 -1
  116. data/lib/samagotchi/send_command.rb +54 -41
  117. data/lib/samagotchi/session_access/ask.rb +244 -0
  118. data/lib/samagotchi/session_access/contract.rb +8 -0
  119. data/lib/samagotchi/session_access/delete_plan.rb +77 -0
  120. data/lib/samagotchi/session_access/exchange/token.rb +101 -0
  121. data/lib/samagotchi/session_access/exchange.rb +173 -0
  122. data/lib/samagotchi/session_access/local.rb +38 -6
  123. data/lib/samagotchi/session_access/remote.rb +23 -2
  124. data/lib/samagotchi/session_access.rb +1 -0
  125. data/lib/samagotchi/session_chain/delete.rb +39 -81
  126. data/lib/samagotchi/session_chain/delete_preview.rb +55 -19
  127. data/lib/samagotchi/session_command_catalog.rb +10 -0
  128. data/lib/samagotchi/session_commands.rb +17 -0
  129. data/lib/samagotchi/session_config.rb +4 -4
  130. data/lib/samagotchi/session_delete_command.rb +129 -3
  131. data/lib/samagotchi/session_manager/delegate_rule.rb +86 -0
  132. data/lib/samagotchi/session_manager/listing.rb +4 -4
  133. data/lib/samagotchi/session_manager/removal.rb +38 -12
  134. data/lib/samagotchi/session_manager/running_tasks.rb +50 -23
  135. data/lib/samagotchi/session_manager.rb +1 -0
  136. data/lib/samagotchi/session_observer.rb +27 -0
  137. data/lib/samagotchi/steer_cut.rb +4 -3
  138. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +4 -1
  139. data/lib/samagotchi/terminal_ui/formatting.rb +15 -0
  140. data/lib/samagotchi/testing/boundary.rb +4 -0
  141. data/lib/samagotchi/testing/bundle.rb +48 -2
  142. data/lib/samagotchi/testing/fake_http.rb +60 -15
  143. data/lib/samagotchi/testing/host.rb +4 -1
  144. data/lib/samagotchi/testing/recorder.rb +45 -5
  145. data/lib/samagotchi/tools/tool_index.rb +14 -3
  146. data/lib/samagotchi/version.rb +1 -1
  147. data/lib/samagotchi/web/app.rb +20 -6
  148. data/lib/samagotchi/web/ask_routes.rb +292 -0
  149. data/lib/samagotchi/web/block_fix_routes.rb +39 -0
  150. data/lib/samagotchi/web/markdown_renderer.rb +24 -9
  151. data/lib/samagotchi/web/mcp_route.rb +88 -0
  152. data/lib/samagotchi/web/message_display.rb +6 -1
  153. data/lib/samagotchi/web/participant_view.rb +1 -1
  154. data/lib/samagotchi/web/public/app.js +7 -8
  155. data/lib/samagotchi/web/public/block_fix.js +270 -0
  156. data/lib/samagotchi/web/public/block_fix_note.js +104 -0
  157. data/lib/samagotchi/web/public/block_frame.js +77 -13
  158. data/lib/samagotchi/web/public/block_host.js +45 -9
  159. data/lib/samagotchi/web/public/block_regions.js +126 -0
  160. data/lib/samagotchi/web/public/block_renderers.css +12 -0
  161. data/lib/samagotchi/web/public/block_watch.js +16 -2
  162. data/lib/samagotchi/web/public/card.js +22 -9
  163. data/lib/samagotchi/web/public/card_actions.js +21 -0
  164. data/lib/samagotchi/web/public/card_kinds.js +1 -1
  165. data/lib/samagotchi/web/public/card_registry.js +3 -2
  166. data/lib/samagotchi/web/public/data.js +15 -12
  167. data/lib/samagotchi/web/public/delete_sheet.js +222 -162
  168. data/lib/samagotchi/web/public/diagram_wiring.js +28 -0
  169. data/lib/samagotchi/web/public/format.js +3 -0
  170. data/lib/samagotchi/web/public/index.html +52 -7
  171. data/lib/samagotchi/web/public/inline_widgets.js +1 -1
  172. data/lib/samagotchi/web/public/more_sheet.js +6 -4
  173. data/lib/samagotchi/web/public/picture_regions.js +243 -0
  174. data/lib/samagotchi/web/public/picture_viewer.js +113 -12
  175. data/lib/samagotchi/web/public/refs.js +5 -3
  176. data/lib/samagotchi/web/public/region_hit.js +144 -0
  177. data/lib/samagotchi/web/public/removal_sheet_model.js +275 -0
  178. data/lib/samagotchi/web/public/running_tasks.js +6 -4
  179. data/lib/samagotchi/web/public/session_actions.js +105 -100
  180. data/lib/samagotchi/web/public/stream_handlers.js +5 -1
  181. data/lib/samagotchi/web/public/turn_block.js +5 -2
  182. data/lib/samagotchi/web/server.rb +6 -4
  183. data/lib/samagotchi/web/session_access_routes.rb +14 -11
  184. data/lib/samagotchi/web/session_control.rb +84 -30
  185. data/lib/samagotchi/web/session_create.rb +2 -2
  186. data/lib/samagotchi/worker/block_fixes.rb +22 -0
  187. data/lib/samagotchi/worker/child_side.rb +3 -2
  188. data/lib/samagotchi/worker/command_queue.rb +13 -13
  189. data/lib/samagotchi/worker/leave.rb +3 -3
  190. data/lib/samagotchi/worker/scratch.rb +6 -6
  191. data/lib/samagotchi/worker/signal_grace.rb +6 -5
  192. data/lib/samagotchi/worker/startup.rb +3 -3
  193. data/lib/samagotchi/worker/wake_turns.rb +4 -4
  194. data/lib/samagotchi/worker.rb +42 -24
  195. data/lib/samagotchi/worker_exit_claim.rb +1 -1
  196. data/lib/samagotchi/worker_idle_exit.rb +18 -9
  197. data/lib/samagotchi/worker_inbound.rb +12 -7
  198. data/lib/samagotchi/worker_participant_gate.rb +9 -7
  199. data/lib/samagotchi/worker_task_wakes.rb +7 -5
  200. metadata +42 -1
@@ -77,6 +77,25 @@ exist. **A new session command or flag fails that spec until you choose one.**
77
77
  registry flag (`--recap-base-url` …) is this machine's config: `LOCAL_ONLY` without being listed
78
78
  (`Contract.run_status`). The contract spec fails on a run flag in neither.
79
79
 
80
+ ## Exchange
81
+
82
+ `SessionAccess::Exchange` (`session_access/exchange.rb`) holds the stateless pieces of "send one message and bind its
83
+ wait", over either backend (it calls only their public methods): `locate` (resolve, head, the poll while a continue
84
+ is in flight: `Located` or `Unsent`), `relocate` (located again after a continue took the link), `attempt` (one
85
+ delivery: show, the caller's check, owner, images, the delivery choice, `deliver_turn`: `Attempted` or `Stopped`),
86
+ `bind` (`ReplyWait::Target.message`) and `wait` (the backend's wait, the turn id and the UTF-8 text). It prints
87
+ nothing, keeps no state between calls, never retries and lets the backend's errors raise. `SendCommand` keeps its
88
+ retry loop, rescues and lines and calls these pieces (its Exchange reads `CONTINUING_WAIT` and `pause` when built, the
89
+ specs' stubs); `CLI::ParentWait` (chi send's and chi answer's wait) calls `wait`. `SessionAccess::Ask`
90
+ (`session_access/ask.rb`) is its own short loop over the same pieces for one message and one wait slice on one
91
+ deadline (chi web's starts with the request: `locate`'s `deadline:` and `relocate`'s `bounded: true` end the continue
92
+ waits `Ask::MIN_SLICE` before it, a continue that takes the link after it gets no second delivery, and the Bridge wait
93
+ of a worker starting draws on it too; chi web stopping cuts the continue waits at the next look, `Refused :canceled`,
94
+ 503 `server_stopping`; a client that goes away is not seen (WEBrick), so its handler runs on to that deadline),
95
+ answering `Reply` (with an `Exchange::Token` on timeout), `Ran` or `Refused`: chi web's `POST …/ask`
96
+ builds one per request over a `Local` that delivers through chi web's own manager and Bridge (`Web::AskRoutes::
97
+ AskAccess`), and plan 2's MCP server reuses it without chi web. The routes: [thin-clients.md](../thin-clients.md).
98
+
80
99
  ## One request, end to end
81
100
 
82
101
  `chi --remote studio send ab12 -m "fix it" --wait`:
@@ -84,8 +103,8 @@ registry flag (`--recap-base-url` …) is this machine's config: `LOCAL_ONLY` wi
84
103
  1. **bin/chi → Dispatch.** The flag is removed. `send` and `send --message` / `--wait` are `SUPPORTED`. `Remotes.find("studio")`
85
104
  reads `$XDG_CONFIG_HOME/samagotchi/remotes.yml`. Then `SendCommand.new(argv, access: Remote.new(entry)).run`.
86
105
  2. **SendCommand.** The client-side checks (UI-only slash commands, image ingest) run. The machine-local ones are
87
- skipped (next section). Every id is resolved once up front (`SendCommand#target`): `Remote#resolve`, then
88
- `Remote#head`, where input for it goes (a continued session's chain's newest link).
106
+ skipped (next section). Every id is resolved once up front (`SendCommand#target` → `Exchange#locate`):
107
+ `Remote#resolve`, then `Remote#head`, where input for it goes (a continued session's chain's newest link).
89
108
  3. **Remote → HTTPTransport.** The first request on a `Remote` is preceded by `check_server!`, which sends
90
109
  `GET /api/info` and needs `app: "chi-web"` plus the `session_commands` feature. Next come
91
110
  `GET /api/sessions/resolve?id=ab12`, `GET /api/sessions/resolve?id=<full id>&head=1` (`{id, asked, via}`:
@@ -93,8 +112,8 @@ registry flag (`--recap-base-url` …) is this machine's config: `LOCAL_ONLY` wi
93
112
  ignores `head=1` and answers `{id}`, read as `same`, so the message goes to the id named as before; a participant's
94
113
  token never asks, and the participant branch of the route answers `{id}` alone) and
95
114
  `POST …/wait/prepare {busy: true, queue:}` (`Remote#busy`) on the id it answered, then
96
- `POST …/wait/prepare {turn, created}` for the `WaitStart`. `deliver` calls `Remote#show` and `#owner` (each
97
- `GET /api/sessions/:id?brief=1`), then
115
+ `POST …/wait/prepare {turn, created}` for the `WaitStart`. `deliver`'s pass (`Exchange#attempt`) calls
116
+ `Remote#show` and `#owner` (each `GET /api/sessions/:id?brief=1`), then
98
117
  `POST …/turn {prompt, client_id: "cli:send", history: false}`. A 202 ack becomes a `DeliverResult` with `via`
99
118
  (`bridge` or `file`).
100
119
  4. **chi web.** `Web::App#route` runs the Host check (`local_host_header?`), then `cross_site?`, then in LAN mode for a
@@ -102,7 +121,7 @@ registry flag (`--recap-base-url` …) is this machine's config: `LOCAL_ONLY` wi
102
121
  before any handler runs. A `:session` route turns an `ArgumentError` into its unknown-session 404. The handlers in
103
122
  `SessionAccessRoutes` call `session_access`, a `SessionAccess::Local` on chi web's own state dir. The page's older
104
123
  routes (`/turn`, `/answer`, `/stop`, …) call `SessionManager` and the Bridge directly, as before.
105
- 5. **The wait.** `ParentWait#wait_for_reply` → `Remote#wait_reply` loops on `POST …/wait` with
124
+ 5. **The wait.** `ParentWait#wait_for_reply` → `Exchange#wait` → `Remote#wait_reply` loops on `POST …/wait` with
106
125
  `timeout: min(time left, WAIT_SLICE)` (30 s). The server runs `ReplyWait.call` for at most `WAIT_MAX_SECONDS` (30 s)
107
126
  and returns the `ReplyWait::Result` fields plus `parent_strategy`. On a `timeout` status the client asks again until
108
127
  its own `--timeout` runs out, at which point it builds the `timeout` result itself. Each slice is a fresh `ReplyWait`
@@ -134,9 +153,12 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
134
153
  `SessionManager::OwnedByTUI` / `DeleteRefused` / `ArchiveRefused` / `RestartRefused`, `SessionContinue::Refused`,
135
154
  and `ModelProfile::MissingModel` for `invalid_model` (no model there, or `--model`'s host unknown there: "could not
136
155
  start a session: …", exit 1, as here). A delete's or archive's `409 tasks_running` carries `op` (`delete` or
137
- `archive`), `tasks` (`{running, unverified, unreadable}`), `worker_stopped`, `stopped_worker` (whose; an older chi web sends only the Boolean) and a chain's `links`: `raise_refusal`
156
+ `archive`), `tasks` (`{running, unverified, unreadable}`), `worker_stopped`, `stopped_worker` (whose; an older chi web
157
+ sends only the Boolean), `stopped_workers` (the archive tree's stopped worker ids), and `sessions` (the archive's
158
+ hidden session count), plus a chain's `links`: `raise_refusal`
138
159
  rebuilds `DeleteRefused` or `ArchiveRefused` by `op`, with the `RunningTasks::Listing`, and makes the words here
139
- (`RunningTasks.words`), not from chi web's `message`. Its own code, not archive's `busy`: an older client prints
160
+ (`RunningTasks.words`, plus `RunningTasks.worker_words`: "its worker was stopped", "9d0e1f2a's worker was stopped",
161
+ or "N workers were stopped: its own, 9d0e1f2a"), not from chi web's `message`. Its own code, not archive's `busy`: an older client prints
140
162
  `RemoteFailed "… answered 409 tasks_running: …"` rather than "a turn is running". `--stop-tasks` asks for the
141
163
  `stop_tasks` feature first (`RemoteTooOld` without it).
142
164
  Checks the client would make locally come back as `SessionAccess::Refused` (`parent_answers_refused`,
@@ -191,6 +213,15 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
191
213
  `unarchived`/`moved_back` (read as `[]`). The delete refusals reach the CLI with their own reason and message
192
214
  (`continuing`, `delegate_unmovable`, `scheduled`, `chain_scheduled`, `worker_running`, `still_stopping`:
193
215
  `Remote#raise_refusal` raises `DeleteRefused` with `ids` and `schedule_id`).
216
+ - **A route that answers more.** `GET /api/sessions/:id/delete_plan` answering for every session (`{chained: false,
217
+ session_id, link}` for one in no chain, and a file-less folder), together with a plain delete that takes the
218
+ session's stopped delegates, is `delete_plan_all` (`App::DELETE_PLAN_FEATURE`). Its first caller is the CLI's
219
+ remote `sessions delete --dry-run` (`Remote#delete_plan`; `SessionAccess::DeletePlan.read` reads its JSON and
220
+ `Local#delete_plan`'s symbol-keyed preview into the same value objects), which requires it first: an older chi web answers a session in no chain with
221
+ `{chained: false}` alone and still leaves a plain session's delegates, so its plan would be wrong. A plain remote
222
+ delete needs no feature: against an older chi web it leaves the delegates, and the CLI prints what the result
223
+ says. The deletes' `tasks=` and archive's `tasks` (the sheet's named tasks) need none either: an older chi web
224
+ ignores them and stops what runs, which is what a CLI without them asks for.
194
225
 
195
226
  ## Which checks run where
196
227
 
@@ -14,7 +14,8 @@ by `npm run e2e` (`spec/e2e/`). `app.js` has no unit spec of its own; `viewer_bo
14
14
  **Every module has a size cap, `app.js` its own**: `npm run lint` fails past `max-lines` in `eslint.config.js`
15
15
  (counted as `wc -l` counts, comments and blank lines too). Every `public/*.js` module: 1200 (`samagotchi/module-size`,
16
16
  about 10% over the largest, `turn_block.js`), so a module near it splits rather than becoming the next `app.js`.
17
- `app.js` (`samagotchi/app-size`): 1638, its size once the lightbox went into `picture_viewer.js`; down from 1649, its
17
+ `app.js` (`samagotchi/app-size`): 1637, its size once the diagrams' wiring went into `diagram_wiring.js`; down from 1638,
18
+ its size once the lightbox went into `picture_viewer.js`, itself down from 1649, its
18
19
  size plus 50 once the session-open flow went into `session_sync.js` and `session_view.js`, itself ratcheted down from 2000, itself down from 2250 when the versions, the owner's claim links and
19
20
  Verify, the composer's mode and the strip's hide went into modules of their own. A new feature goes into a module of
20
21
  its own, wired from `app.js` in a few lines; a refactor that shrinks `app.js` ratchets its cap down with it. Never
@@ -29,9 +30,15 @@ on an existing module, imported by a new version of another, then finds the old
29
30
  page. A factory dep a new version stops passing is the same hazard the other way round: the store's redraws took
30
31
  `updateInfoBar` and the chip controls out of `stream_handlers.js`'s deps (and `updateInfoBar`/`updateComposerMode`
31
32
  out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
32
- until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
33
+ until a reload, so the risk is a mixed cache, not an open tab. An export a new version stops importing stays until
34
+ the next release (its baseline refresh) for the same reason, marked as kept for an older cached module (the delete
35
+ sheet kept `isChained`, `format.js deleteConfirmText` and `running_tasks.js tasksConfirmText` that way; and, for the
36
+ same release, the hooks 0.182.0's modules still call: `session_actions.js` passes `plain` and a `failed` that toasts
37
+ when the sheet is gone, and gives archive's ask a `deletePlan` that rejects with the refusal, and `delete_sheet.js`'s
38
+ `deleteToast` leaves out the stopped tasks the old `session_actions.js` adds itself; `delete_mixed_cache.test.js` loads
39
+ each pair, the old file from `spec/web/public/fixtures/v0.182.0/`). `answer_fold.js`, `details_motion.js`,
33
40
  `turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
34
- `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (Deleting a chained session, below), `running_tasks.js` (a delete's or archive's 409 `tasks_running`: the tasks' line, the second confirm, the toast's suffix; DOM-free, so `stop_sheet.js` and `delete_sheet.js` share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
41
+ `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
35
42
 
36
43
  ## One page, every viewer
37
44
 
@@ -380,28 +387,56 @@ placed at, so `chip_popover.js` places it, marks `aria-expanded` and gives focus
380
387
  `[data-anchor-stand-in]` (⋯). Rows and actions draw into fixed slots, so a row that joins keeps the focus where it was.
381
388
  The e2e reach an item wherever it is with `spec/e2e/support/layout.js` `clickBarItem` (the row, else ⋯'s `[data-row]`).
382
389
 
383
- **Deleting a chained session** (`delete_sheet.js`; docs/sessions.md, Session chains → Deleting a link): Delete on a
384
- session in a chain asks "Delete this link" or "Delete the whole chain" instead of the browser's confirm, which a
385
- session in no chain keeps (`session_actions.js confirmDelete`; `isChained` reads the page's list, which holds archived
386
- links too). In ⋯'s menu, Delete doesn't click `#infoDeleteBtn` for a chained session: `createMoreSheet`'s `onDelete`
387
- (`session_actions.js deleteIn`) takes the panel as a host and draws the sheet in its place (a subview; ‹ More,
388
- `del:back`, draws the list again; a redraw keeps the subview), so no second popover opens. A card's ✕ opens it at the
389
- card (`createDeleteSheet`, on `chip_popover.js`: a bottom sheet on a phone). Both shells keep one live host: a
390
- `host(anchor, id)` (the card's, with the session it opened for) or a Delete in ⋯ makes a new one, and a flow whose host
391
- is no longer the live one (a ✕ on another card while the first plan was read) draws and acts on nothing. What the sheet says comes from
392
- `GET /api/sessions/:id/delete_plan`, fetched as it opens and only for a chained session: the server's own plan and
393
- refusals (`SessionChain::Delete::Preview`, the code the delete runs), so the sheet and the delete can't disagree; its
394
- cost is one session listing walk per open. `deleteChoices` (pure) turns it into the two choices, a schedule's banner
395
- and each refusal's "Not while …"; a plan that says no chain (a link alone past a gap) falls back to the confirm. The
396
- confirm sends the shown choice's `digest` (`expect=`, `data.js deleteSession`/`deleteChain` keep it out of `fetch`);
397
- a `409 plan_changed` re-reads the plan and redraws the sheet with "What this deletes changed; check again" (a link no
398
- longer chained gets the plain confirm). Any other refusal `runDeleteFlow` shows in the sheet
399
- (`refusalModel`: a moved delegate that can't go back offers "Stop its worker, then delete" only when the 409 says
400
- `stoppable`; it stops each, retries only once the stop answers `released`, and says so otherwise, never looping, one
401
- stop at a time).
390
+ **The delete sheet** (`delete_sheet.js`, its words `removal_sheet_model.js`; docs/sessions.md, Deleting a session and
391
+ Session chains → Deleting a link; the design: https://claude.ai/artifact/1A3TL2kkz8a2Pv8obi4jsj): every Delete, and an
392
+ Archive the server refuses, asks in one sheet instead of the browser's `confirm()` / `alert()`. Before anything happens
393
+ it says what goes, what is stopped first and what stays, with one button that names the outcome.
394
+ - **Where.** In ⋯'s menu, Delete always takes the panel as the sheet's host (`createMoreSheet`'s `onDelete` →
395
+ `session_actions.js deleteIn`, which answers true for any session): the panel draws the sheet in its place (a
396
+ subview; ‹ More, `del:back`, draws the list again; a redraw keeps the subview), so no second popover opens inside
397
+ More's click (a popover opened there would see that click as outside and close). A card's ✕ opens it at the card
398
+ (`createDeleteSheet`, on `chip_popover.js` with `SHEET_TALL`: a bottom sheet on a phone, its buttons full width).
399
+ Both shells keep one live host: a `host(anchor, id)` or a Delete in ⋯ makes a new one, and a flow whose host is no
400
+ longer the live one (a ✕ on another card while the first plan was read) draws and acts on nothing.
401
+ - **What it says** comes from `GET /api/sessions/:id/delete_plan`, fetched as it opens, for every session: the
402
+ server's own plan and refusals (`SessionChain::Delete::Preview`, the code the delete runs), so the sheet and the
403
+ delete can't disagree. `deleteChoices(session, plan, sessions)` is the model. A session in no chain:
404
+ `removal_sheet_model.js sessionSheetModel` → `{title, groups, button, stops, foot, tasks}`, its rows from
405
+ `sheetGroups(link)`: **Goes** (its history; the stopped delegates of `delegates.delete`, named from the page's list
406
+ by `format.js cardName`, else the short id; three, then `+N more`), **Stopped first** (`worker`: "Its worker (idle)"
407
+ or "Its running turn"; the `running` tasks through `running_tasks.js tasksLine`, a delegate's with its id in front),
408
+ **Stays** (the running delegates of `delegates.leave`, with the stopped ones under them; the tasks chi can't verify or
409
+ read, never signalled). A chained one keeps its two choices ("this link", "the whole chain"), each with its first
410
+ lines, then its own Stopped first / Stays lines (`choiceTail`). A refusal the plan carries (a one-turn run, a
411
+ schedule, a continue under way) is the "Can't delete … now" view with only Close (`cantModel`); a plan that can't be
412
+ read is the same view.
413
+ - **The button's words** (`buttonWords`): it names the running work it ends: `Stop them and delete` (`Stop it …` for
414
+ one task), `Stop the turn and delete`; an idle worker is only a row and the button stays `Delete`; ` · N sessions`
415
+ when the tap takes more than one session: every session it deletes, the stopped delegates too (`Delete this link · 2
416
+ sessions` with one; the whole chain counts its links and theirs, a step past the mock-up's case 8, by the owner's word); a chain's choices say `Stop 2 tasks
417
+ and delete this link`. While the tap runs it says `Stopping…` (tasks or a turn) or `Deleting…`.
418
+ The sheet opens with focus on Cancel (× or ‹ More while there is none), so a stray Enter never deletes or archives.
419
+ Closed while the tap runs, a refusal that comes after is a sticky toast (`failed` on a host no longer live).
420
+ - **The tap** sends the choice's `digest` (`expect=`) and, whenever the choice's task listing isn't empty, `stopTasks`
421
+ with the ids of its `running` tasks (`stopTasksOptions`; `data.js` sends `stop_tasks=true&tasks=<id,id>`, `tasks=`
422
+ when it lists only records chi can't verify, so such a session can still be deleted and nothing unnamed is stopped).
423
+ A `409 plan_changed` and a `409 tasks_running` (a task that started since) both re-read the plan and show it with
424
+ "What this deletes changed; check again." Any other refusal `runDeleteFlow` shows in the sheet (`refusalModel`: a
425
+ moved delegate that can't go back offers "Stop its worker, then delete" only when the 409 says `stoppable`; it stops
426
+ each, retries only once the stop answers `released`, and says so otherwise, never looping, one stop at a time).
427
+ - **Archive** stays one tap and the Undo toast when nothing is in the way. Its 409 opens the same sheet
428
+ (`session_actions.js setArchived` → `runDeleteFlow` with `archive: {refusal}`): `tasks_running` is
429
+ `archiveSheetModel` (Hidden: it and the 409's `sessions` − 1 delegates; Stopped first: the tasks; `Stop them and
430
+ archive`, its button sending the named ids the same way); a task that started since re-shows it with "What this
431
+ archives changed; check again."; any other refusal is "Can't archive … now". The sheet is at the control tapped:
432
+ ⋯ for the open session's (`toggleArchiveSelected` passes it), else the card's archive button with a box, found by
433
+ `[data-arch="<id>"]` (app.js's wrapper passes no anchor). A 409 that comes once the shell shows another session's
434
+ sheet (opened while the archive was out) leaves that sheet and is a sticky toast (`latest.js stillOn` on the shell's
435
+ `openFor`). An unarchive that fails is a sticky toast. A batch archive
436
+ is untouched (`archiveOne` passes nothing, and skips a session with running tasks).
402
437
  After a delete, `listAfterDelete` drops the `deleted` ids and un-archives the `unarchived` ones in the store, the
403
- selection clears when it went, and the toast (`deleteToast`) names what came back with an "Open" action.
404
-
438
+ selection clears when it went, and the toast (`deleteToast`) says what went, what was stopped and what stays, with
439
+ "Open" for the link that came back or a delegate left running.
405
440
 
406
441
  ## Safe areas
407
442
 
@@ -440,7 +475,8 @@ kept: every open starts fitted.
440
475
  moves, Ctrl/Cmd + wheel zooms at the cursor (a Chromium trackpad pinch is a ctrl + wheel), by `exp(-deltaY ×
441
476
  0.01)`, not fixed steps. Safari's `gesturestart`/`change`/`end` are always prevented (they would zoom the page) and
442
477
  applied only while no touch pointer is down: that is a Mac trackpad; iOS fires them beside the pointers for a
443
- finger pinch, and applying both would double it. A double tap or click (two ups without a move within 300 ms)
478
+ finger pinch, and applying both would double it. A double tap or click (two ups within 300 ms, neither a move: past 4 px for a mouse, 10 for a finger,
479
+ as |dx| + |dy|)
444
480
  goes to max(2.5 × fit, natural) at that point, or back to fit when closer than fit. The `<img>` is never
445
481
  dragged natively (`draggable=false`, `dragstart` prevented, `-webkit-user-drag:none`, `pointer-events:none`) and
446
482
  has no iOS long-press sheet (`-webkit-touch-callout:none`).
@@ -453,7 +489,7 @@ kept: every open starts fitted.
453
489
  so after one it is the page's. A window `resize` (an orientation change) refits a fitted view, else re-clamps; it
454
490
  is listened to only while open.
455
491
  - **It closes by itself**, whatever it shows, on a system theme change (the diagram behind is redrawn; the viewer
456
- holds the old picture; app.js), on a switch to another session or the start page (`session_view.js
492
+ holds the old picture; `diagram_wiring.js`), on a switch to another session or the start page (`session_view.js
457
493
  forgetSession`, given `pictures`; the same session again keeps it) and when the all-sessions view opens (it hides
458
494
  `#center`, the viewer's parent; app.js `applyView`). A bubble rewritten or cloned while it is open leaves it as it
459
495
  is: it holds its own copy of the URL. The toast may show over it (both z-index 50, the toast later); it is modal by
@@ -462,6 +498,60 @@ kept: every open starts fitted.
462
498
  viewer adopts it (or adds one) and draws ✕ and the bar with lit at the first open. ✕ and the bar are glass cards
463
499
  (solid `--bg-panel` under `body.no-glass` and reduced transparency), by `--safe-*`, and the standalone phone
464
500
  app's ✕ is 12px lower, below iOS 26's band under the clock.
501
+ - **A diagram's regions** (a renderer that reports them: [block-renderers.md](block-renderers.md#regions)): the
502
+ viewer's layer, `picture_regions.js createRegionLayer`, made by `diagram_wiring.js` and given by
503
+ `pictures.useLayer?.(layer)` (an older cached `picture_viewer.js` has none: the viewer as before; one with
504
+ `useLayer` but no `bind`, which never shows the card, leaves the layer undrawn and keeps no card's room). The layer
505
+ adds its own `.pv-marks` child to `.pv-pic` (the box marks by percent, the page's own `<svg viewBox="0 0 1 1">`
506
+ with at most two `<polyline>`s, the hovered and the selected arrow's, and a `role="group"` of buttons), and its card
507
+ (`.pv-sel`, `role="region"` "Selected") and visually hidden `aria-live` line join `#lightbox` after the bar.
508
+ **The pointer path is maths** (`region_hit.js`): the surface keeps its pointer capture, so a drag, a pinch and a
509
+ double tap are as before. A tap that isn't a move (4 px for a mouse, 10 for a finger) goes to `layer.tap` before
510
+ the double-tap bookkeeping: the nearest node or note within 3 px, else an arrow's line (7 px at least) or its
511
+ label's box, else the innermost group; nothing → it clears. A finger (18 px) takes a node first only on its box:
512
+ an arrow's line or label within 7 px beats a node only within the finger's margin (two nodes 30 px apart at a
513
+ phone's fit leave the label between them tappable), then the nearest node within 18 px, then an arrow. One region at a time; two with one kind
514
+ and id select together. The mouse with no button down is `layer.hover` at most once per frame (`#lightbox.over`:
515
+ the hand). **The card's room** (`CARD_ROOM` 64 px, 80 on a coarse pointer, beside the bar's 56) is kept in the fit
516
+ of a picture with regions, selected or not, so selecting never moves a fitted picture and no fitted node is under
517
+ the card; zoomed in, a selected node under the card slides up (`revealOffset`), `TAP_MS` after its tap and only if
518
+ no second tap came (a double tap zooms at the point it hit), a keyboard's selection at once. **Keys**: the nodes'
519
+ buttons (`.pv-node`, a full reset of the page's `button` style, `pointer-events: none`; the reset is in each
520
+ button's inline `style` too, so with a stale index.html they are still see-through and take no pointer) are one Tab
521
+ stop (roving `tabindex`, following the selection); the arrows move the focus to the nearest button that way (along +
522
+ 2 × across; a group only when nothing else is that way), Enter or Space is the button's click, which selects; Esc
523
+ clears a selection first and closes second; the card's ✕ clears. When the card goes with the focus in it, the focus
524
+ goes to the cleared region's button, else to the viewer (never `<body>`, where the next Esc wouldn't reach the
525
+ viewer). A focused button never scrolls the surface (its `scroll` is reset). The card's actions row is the layer's
526
+ `actions(region)` (empty for now: the card is the name alone).
527
+
528
+ ## A failed block asked for again
529
+
530
+ Two modules, owner page only ([block-renderers.md](block-renderers.md#a-failed-block-is-asked-for-again) has the
531
+ mechanism): `block_fix.js` (`wireBlockFix`, one call in app.js: the owner's page, `viewer.can("block_renderers")`,
532
+ with `<body data-block-fix="auto">`, else null; `createBlockFix`) and `block_fix_note.js` (the line's states, DOM
533
+ only). A drawer that fails a block because of the model's input marks it (`block_watch.js failBlock(..., {fixable})`,
534
+ `pre.dataset.blockFixable`, the reason kept in `pre.dataset.blockReason`, a bubbling `block-failed` event): a refused
535
+ `chi-ui` block (`inline_widgets.js`) and a renderer's own `error` (`block_frame.js` `FrameError.renderer`). `block_fix.js`
536
+ listens for that event and scans added nodes (a Revise clone arrives failed) in the turn roots, and decides from the DOM
537
+ alone: the newest answer's first 2 such blocks are posted (`POST /api/sessions/:id/blocks/fix`, `postFix`); the worker
538
+ also enforces the 2-per-answer limit and remains the authority (`fix_limit`, even if the page or a second tab posts).
539
+ A block
540
+ that is a fix (`data-block-fixed`) or whose fix failed (`data-block-fix-failed`), an older answer, a third block and a
541
+ live worker without the `block_fix` feature (`worker_features.js workerPredates`, with `bridgeUp`) get their line
542
+ instead. Nothing is kept across a re-render: a block failing again is posted again, and the worker answers it runs (or
543
+ how it went); only the redraw is counted: an answer is read again at most once per turn and block for the page's life
544
+ (the route's 200 `fixed` or the event's), and a block failing after it says a fix didn't help. The stream's `block_fix` handler
545
+ (`stream_handlers.js`, dep `blockFix`) hands the worker's word over: `fixed` re-reads that turn's answer (`getSession(id,
546
+ {tail, turnId})`) and writes the bubble as `applyFinalAnswer` writes it, which can't find it by its old text; `failed`
547
+ and `dropped` say a fix didn't help. A block is marked asked (`data-block-fix-asked`) before its POST, since the word can
548
+ come before the 202 (a quick side answer); a 202 after it starts no give-up. No word within 60 s of a 202: the line
549
+ gives up (today's words and Ask in chat);
550
+ a session switch drops the timers. The line's words are `data-text` (CSS), Ask in chat a button whose label is CSS
551
+ (`data-label`) with an `aria-label`, one delegated click listener per root; it fills the composer after the draft
552
+ (`widget_picks.js withDraft`), never sends. "Drawn after a fix" (`.block-note.fixed`) follows a `data-block-fixed`
553
+ block once its figure is placed; a click on it copies nothing (a failed block's line copies its error). A reload's drawn turn takes the saved answer when `block_fixed` is on its item (what
554
+ streamed is the block before the fix: `turn_block.js savedAnswer`).
465
555
 
466
556
  ## The stage's modules
467
557
 
@@ -130,7 +130,7 @@ pending: [Steering: add and unadd](#steering-add-and-unadd)) (`Engine#emit_worki
130
130
  turn-end apply has run by then);
131
131
  - between turns, from `Engine#announce_working_set` (the session's messages, under the event lock; after a
132
132
  `/working-set` op, after a `rollback_to`, and after an `/llm-context` change: the states are the next turn's strategy's): announced
133
- (`working_set_updated` is in `ANNOUNCEABLE_EVENTS`; held after a command's `command_ran` inside
133
+ (`working_set_updated` is in `SessionObserver::ANNOUNCEABLE_EVENTS`; held after a command's `command_ran` inside
134
134
  `holding_announcements`), under the *next* turn's strategy (`SessionModelSettings#turn_llm_context`, as the
135
135
  turn-end warm-up reads it; `TurnSettings` keeps the last turn's, stale after `/llm-context` or `/model`). While a
136
136
  turn runs, the strategy is always the turn's.
@@ -0,0 +1,80 @@
1
+ # chi as an MCP server
2
+
3
+ An MCP host (Claude Code, Codex, any client of the Model Context Protocol) can drive chi sessions as tools: list
4
+ them, send one a message and read its answer, answer the question it waits on. The sessions are ordinary ones: you
5
+ watch them in `chi web` or attach to them while the host talks to them.
6
+
7
+ This is chi as an MCP **server**. The `mcp` bundle is the other direction: chi as an MCP client, using other
8
+ servers' tools in its own sessions (see [Bundles](bundles.md)).
9
+
10
+ ## Adding it to a host
11
+
12
+ ```sh
13
+ claude mcp add chi -- chi mcp serve # this machine's sessions, stdio
14
+ claude mcp add chi-cloud -- chi --remote cloud mcp serve # another machine's, through its chi web
15
+ claude mcp add --transport http chi http://127.0.0.1:4567/api/mcp # chi web, loopback
16
+ ```
17
+
18
+ Codex, in its `config.toml`:
19
+
20
+ ```toml
21
+ [mcp_servers.chi]
22
+ command = "chi"
23
+ args = ["mcp", "serve"]
24
+ ```
25
+
26
+ - **stdio** (`chi mcp serve`): the host starts chi; JSON-RPC lines on its stdin and stdout. Under `chi --remote
27
+ NAME` (see [Remote sessions](cli.md#remote-sessions)) the tools reach that machine's sessions through its chi web.
28
+ - **HTTP** (`POST /api/mcp` on chi web): on loopback with no `web.public_url`, no token, as every owner route of
29
+ chi web. On the LAN, or a public URL chi web serves directly, send chi web's access token:
30
+ `--header "Authorization: Bearer <token>"` (a request without it gets a 401 with `WWW-Authenticate: Bearer`).
31
+ A participant's token is refused. `GET /api/info` lists `"mcp"` in its `features`; an older chi web answers 404.
32
+ - **Behind an auth proxy** (Okta, oauth2-proxy): not yet. The proxy stops an MCP host before chi sees it: use `chi
33
+ --remote NAME mcp serve` there.
34
+
35
+ Both revisions of the protocol are served: the current one (2026-07-28, stateless: Claude Code) and the earlier
36
+ `initialize` one (2025-11-25, 2025-06-18: Codex). The answers are plain JSON, never a stream. 2025-03-26 is not
37
+ offered (a client naming it is answered 2025-11-25): it allows JSON-RPC batches, and chi answers a batch with one
38
+ `-32600` error. A message that isn't JSON in UTF-8 is a `-32700` with its request's id when chi can read one, so the
39
+ host isn't left waiting on that call.
40
+
41
+ ## The tools
42
+
43
+ | Tool | Arguments | What it does |
44
+ |---|---|---|
45
+ | `chi_sessions` | `dir?`, `live?`, `limit?` | the sessions, newest first: id, title, status, whether a question waits, project |
46
+ | `chi_ask` | `session`, `prompt` | sends the prompt as its own turn (queued behind a running one) and waits for the answer |
47
+ | `chi_wait` | `token` | keeps waiting for a turn that was still running |
48
+ | `chi_answer` | `session`, `question_id`, `option?` / `options?` / `text?` | answers the question a session waits on, then waits |
49
+
50
+ A call waits at most 25 seconds (a `chi_ask` or `chi_answer` 35 in all, under Claude Code HTTP's 60 s). Then:
51
+
52
+ - the turn still runs: `Still running. Call chi_wait with this token to keep waiting.` with a `token`;
53
+ - a question waits: the question, its numbered options and `Call chi_answer with session, question_id and option
54
+ (or text).` An option is its label or its number (1-based); several only on a question that takes several.
55
+ - `chi_answer` on a question no longer open (answered elsewhere first, a newer one waits, or a stale
56
+ `question_id`): nothing is sent. The text starts `Question <id> is no longer open …; not answered here.`, then
57
+ says what came next (`answered_here: false` in `structuredContent`).
58
+
59
+ Every result is text plus the same facts, the text included, as `structuredContent` (`status`: `done`, `running`, `waiting_for_answer`,
60
+ `command`, or `error` with `detail`). A refusal, a bad argument and a turn that ended without a reply are results
61
+ with `isError: true` and chi's own words; only an unknown tool is a protocol error.
62
+
63
+ ## Who the caller is
64
+
65
+ The host is an agent driving a session, as `chi send --wait` and `chi answer` are (see [chi as a
66
+ sub-agent](sub-agent.md)): its messages go in as `chi send`'s, its answers and a `/continue yes` as `chi answer`'s.
67
+ So `guardrails.parent_answers` holds it (see [Guardrails](guardrails.md#answers-from-a-parent-agent)): what it may
68
+ pick on an approval or a step-limit question, and whether it may continue a turn that ran out of iterations. The
69
+ page shows its turns with the "chi send" label.
70
+
71
+ `chi_ask` takes a message for the model, not a command: a line starting with `!` (a shell line) or with `/` (a
72
+ session command; `/continue …` is the one exception) is refused. That is narrower than `chi send` on purpose: a
73
+ host approves an MCP tool once, not each line.
74
+
75
+ ## Not yet
76
+
77
+ Starting a session (`chi_new`), stopping, archiving or deleting one; OAuth (claude.ai and ChatGPT connectors, a chi
78
+ web behind an auth proxy); progress notifications and streamed answers; resources and prompts; images; a
79
+ participant's token. A second `chi_ask` while the first still runs queues another turn: nothing stops a model from
80
+ asking twice.