samagotchi 0.170.0 → 0.172.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 (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -1
  3. data/bin/chi +6 -4
  4. data/docs/architecture.md +26 -9
  5. data/docs/bundles.md +4 -21
  6. data/docs/cli.md +81 -97
  7. data/docs/configuration.md +12 -14
  8. data/docs/context.md +5 -6
  9. data/docs/guardrails.md +57 -96
  10. data/docs/hooks.md +3 -4
  11. data/docs/internals/attached-context.md +6 -7
  12. data/docs/internals/background-tasks.md +4 -3
  13. data/docs/internals/block-renderers.md +2 -2
  14. data/docs/internals/bridge.md +34 -7
  15. data/docs/internals/context-telemetry.md +13 -1
  16. data/docs/internals/engine.md +25 -13
  17. data/docs/internals/inline-widgets.md +1 -1
  18. data/docs/internals/objectives.md +4 -6
  19. data/docs/internals/participants.md +340 -249
  20. data/docs/internals/prompt-caching.md +4 -5
  21. data/docs/internals/web-frontend.md +185 -35
  22. data/docs/internals/working-set.md +71 -5
  23. data/docs/memory.md +1 -1
  24. data/docs/plugins.md +2 -16
  25. data/docs/releasing.md +2 -1
  26. data/docs/scheduling.md +1 -1
  27. data/docs/sessions.md +17 -48
  28. data/docs/sub-agent.md +2 -2
  29. data/docs/system-one.md +2 -2
  30. data/docs/testing.md +56 -7
  31. data/lib/samagotchi/bridge/card_store.rb +1 -0
  32. data/lib/samagotchi/bridge/sse_writer.rb +1 -0
  33. data/lib/samagotchi/bridge/turn_accumulator.rb +8 -5
  34. data/lib/samagotchi/bridge.rb +64 -20
  35. data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
  36. data/lib/samagotchi/bundle_command/test_run.rb +1 -0
  37. data/lib/samagotchi/bundle_command/try/run.rb +1 -0
  38. data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
  39. data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
  40. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
  41. data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
  42. data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
  43. data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
  44. data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
  45. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  46. data/lib/samagotchi/client_id.rb +126 -67
  47. data/lib/samagotchi/command_intake.rb +15 -3
  48. data/lib/samagotchi/compat.rb +6 -1
  49. data/lib/samagotchi/context_candidate_choice.rb +1 -3
  50. data/lib/samagotchi/context_candidates.rb +3 -4
  51. data/lib/samagotchi/continue_offer.rb +9 -2
  52. data/lib/samagotchi/delivery.rb +36 -12
  53. data/lib/samagotchi/empty_answer_error.rb +5 -0
  54. data/lib/samagotchi/engine/cards.rb +3 -0
  55. data/lib/samagotchi/engine/context_judge.rb +5 -3
  56. data/lib/samagotchi/engine/events.rb +4 -0
  57. data/lib/samagotchi/engine/hooks.rb +3 -0
  58. data/lib/samagotchi/engine/messages.rb +5 -0
  59. data/lib/samagotchi/engine/model_settings.rb +2 -0
  60. data/lib/samagotchi/engine/models.rb +10 -0
  61. data/lib/samagotchi/engine/objectives.rb +6 -0
  62. data/lib/samagotchi/engine/participants.rb +18 -14
  63. data/lib/samagotchi/engine/plugins.rb +8 -0
  64. data/lib/samagotchi/engine/questions.rb +3 -0
  65. data/lib/samagotchi/engine/recap.rb +1 -0
  66. data/lib/samagotchi/engine/session.rb +4 -0
  67. data/lib/samagotchi/engine/side_requests.rb +9 -0
  68. data/lib/samagotchi/engine/steering.rb +2 -0
  69. data/lib/samagotchi/engine/toolkit.rb +5 -0
  70. data/lib/samagotchi/engine/turn_end.rb +7 -0
  71. data/lib/samagotchi/engine/turn_helpers.rb +8 -0
  72. data/lib/samagotchi/engine/verify.rb +2 -0
  73. data/lib/samagotchi/engine.rb +8 -3
  74. data/lib/samagotchi/event_fanout.rb +22 -1
  75. data/lib/samagotchi/grants.rb +33 -22
  76. data/lib/samagotchi/guardrail_wiring.rb +23 -18
  77. data/lib/samagotchi/guardrails/approval_use.rb +59 -0
  78. data/lib/samagotchi/guardrails/approvals.rb +9 -11
  79. data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
  80. data/lib/samagotchi/guardrails/gate.rb +10 -5
  81. data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
  82. data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
  83. data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
  84. data/lib/samagotchi/guardrails/review_paths.rb +2 -3
  85. data/lib/samagotchi/guardrails.rb +1 -1
  86. data/lib/samagotchi/image_store.rb +51 -12
  87. data/lib/samagotchi/kernel_loop.rb +7 -1
  88. data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
  89. data/lib/samagotchi/llm_context_stale.rb +4 -1
  90. data/lib/samagotchi/llm_context_strategy.rb +2 -0
  91. data/lib/samagotchi/objectives.rb +1 -4
  92. data/lib/samagotchi/objectives_audit.rb +1 -1
  93. data/lib/samagotchi/objectives_track.rb +1 -1
  94. data/lib/samagotchi/owner_prompt.rb +3 -6
  95. data/lib/samagotchi/parent_report.rb +1 -0
  96. data/lib/samagotchi/participant_messages.rb +48 -4
  97. data/lib/samagotchi/participant_revise.rb +61 -0
  98. data/lib/samagotchi/participant_turn_mode.rb +50 -0
  99. data/lib/samagotchi/participant_uploads.rb +98 -0
  100. data/lib/samagotchi/participants.rb +21 -12
  101. data/lib/samagotchi/participants_watch.rb +2 -2
  102. data/lib/samagotchi/plugin/api.rb +2 -2
  103. data/lib/samagotchi/plugin/attached_context.rb +1 -1
  104. data/lib/samagotchi/plugin/context.rb +0 -4
  105. data/lib/samagotchi/plugin/sessions.rb +1 -25
  106. data/lib/samagotchi/reply_wait/poll.rb +5 -1
  107. data/lib/samagotchi/revise_anchor.rb +9 -0
  108. data/lib/samagotchi/run_options.rb +2 -3
  109. data/lib/samagotchi/send_command.rb +15 -10
  110. data/lib/samagotchi/session.rb +0 -3
  111. data/lib/samagotchi/session_access/contract.rb +1 -10
  112. data/lib/samagotchi/session_access/local.rb +10 -23
  113. data/lib/samagotchi/session_access/remote.rb +9 -20
  114. data/lib/samagotchi/session_access.rb +12 -16
  115. data/lib/samagotchi/session_chain.rb +4 -6
  116. data/lib/samagotchi/session_commands.rb +6 -3
  117. data/lib/samagotchi/session_continue.rb +1 -2
  118. data/lib/samagotchi/session_inbox.rb +20 -12
  119. data/lib/samagotchi/session_manager/delivery.rb +32 -5
  120. data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
  121. data/lib/samagotchi/session_manager/listing.rb +5 -0
  122. data/lib/samagotchi/session_manager/spawn.rb +2 -2
  123. data/lib/samagotchi/session_manager/worker_command.rb +9 -0
  124. data/lib/samagotchi/session_participants.rb +12 -8
  125. data/lib/samagotchi/session_review.rb +5 -7
  126. data/lib/samagotchi/session_stores.rb +3 -1
  127. data/lib/samagotchi/share_command.rb +10 -12
  128. data/lib/samagotchi/share_terms.rb +41 -0
  129. data/lib/samagotchi/steer.rb +8 -14
  130. data/lib/samagotchi/system_prompt.rb +16 -25
  131. data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
  132. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
  133. data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
  134. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
  135. data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
  136. data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
  137. data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
  138. data/lib/samagotchi/terminal_ui.rb +1 -2
  139. data/lib/samagotchi/testing/sessions.rb +2 -10
  140. data/lib/samagotchi/tool_runner.rb +42 -9
  141. data/lib/samagotchi/toolkit.rb +4 -22
  142. data/lib/samagotchi/toolkit_suggest.rb +3 -3
  143. data/lib/samagotchi/tools/deferred_tools.rb +1 -0
  144. data/lib/samagotchi/tools/execute.rb +11 -45
  145. data/lib/samagotchi/tools/leftovers.rb +122 -0
  146. data/lib/samagotchi/tools/memory.rb +88 -25
  147. data/lib/samagotchi/tools/task_get.rb +1 -0
  148. data/lib/samagotchi/tools/task_list.rb +3 -2
  149. data/lib/samagotchi/tools/task_record.rb +6 -4
  150. data/lib/samagotchi/tools/task_runtime.rb +199 -20
  151. data/lib/samagotchi/tools/task_wait.rb +4 -3
  152. data/lib/samagotchi/turn_anchors.rb +0 -3
  153. data/lib/samagotchi/turn_context.rb +1 -1
  154. data/lib/samagotchi/turn_origin.rb +1 -1
  155. data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
  156. data/lib/samagotchi/turn_stages/objectives.rb +2 -2
  157. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
  158. data/lib/samagotchi/turn_stages/verify_anchors.rb +13 -1
  159. data/lib/samagotchi/update_hint.rb +3 -1
  160. data/lib/samagotchi/verify_anchor.rb +6 -0
  161. data/lib/samagotchi/verify_fresh.rb +1 -1
  162. data/lib/samagotchi/verify_fresh_origin.rb +13 -11
  163. data/lib/samagotchi/version.rb +1 -1
  164. data/lib/samagotchi/web/app.rb +45 -82
  165. data/lib/samagotchi/web/participant_access.rb +139 -40
  166. data/lib/samagotchi/web/participant_images.rb +185 -0
  167. data/lib/samagotchi/web/participant_review.rb +22 -142
  168. data/lib/samagotchi/web/participant_show.rb +241 -0
  169. data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
  170. data/lib/samagotchi/web/participant_view.rb +334 -27
  171. data/lib/samagotchi/web/participants_admin.rb +21 -40
  172. data/lib/samagotchi/web/public/annotate_bar.css +1 -2
  173. data/lib/samagotchi/web/public/annotate_bar.js +1 -2
  174. data/lib/samagotchi/web/public/app.js +126 -132
  175. data/lib/samagotchi/web/public/block_host.js +7 -4
  176. data/lib/samagotchi/web/public/bubbles.js +9 -1
  177. data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
  178. data/lib/samagotchi/web/public/chip_popover.js +5 -4
  179. data/lib/samagotchi/web/public/claim_link.js +4 -4
  180. data/lib/samagotchi/web/public/composer.css +4 -6
  181. data/lib/samagotchi/web/public/composer_mode.js +11 -6
  182. data/lib/samagotchi/web/public/composer_mount.js +4 -4
  183. data/lib/samagotchi/web/public/ctx.js +12 -3
  184. data/lib/samagotchi/web/public/data.js +2 -10
  185. data/lib/samagotchi/web/public/delivery_line.js +49 -63
  186. data/lib/samagotchi/web/public/history_shape.js +5 -1
  187. data/lib/samagotchi/web/public/images.js +7 -1
  188. data/lib/samagotchi/web/public/index.html +50 -34
  189. data/lib/samagotchi/web/public/info_bar_model.js +2 -1
  190. data/lib/samagotchi/web/public/live_turn.js +1 -1
  191. data/lib/samagotchi/web/public/markdown_place.js +5 -4
  192. data/lib/samagotchi/web/public/owner_claim.js +5 -5
  193. data/lib/samagotchi/web/public/owner_verify.js +0 -2
  194. data/lib/samagotchi/web/public/participant_bar.js +107 -0
  195. data/lib/samagotchi/web/public/participant_main.js +289 -0
  196. data/lib/samagotchi/web/public/participant_model.js +5 -292
  197. data/lib/samagotchi/web/public/participant_names.js +17 -8
  198. data/lib/samagotchi/web/public/participant_revise.js +66 -0
  199. data/lib/samagotchi/web/public/participants_panel.js +32 -74
  200. data/lib/samagotchi/web/public/question_cards.js +14 -3
  201. data/lib/samagotchi/web/public/refs.js +53 -36
  202. data/lib/samagotchi/web/public/reload_check.js +70 -14
  203. data/lib/samagotchi/web/public/revise_stack.js +21 -10
  204. data/lib/samagotchi/web/public/send_turn.js +28 -29
  205. data/lib/samagotchi/web/public/session_actions.js +4 -45
  206. data/lib/samagotchi/web/public/session_fields.js +1 -2
  207. data/lib/samagotchi/web/public/session_state.js +12 -7
  208. data/lib/samagotchi/web/public/session_sync.js +9 -2
  209. data/lib/samagotchi/web/public/session_view.js +14 -5
  210. data/lib/samagotchi/web/public/settings_panel.js +4 -18
  211. data/lib/samagotchi/web/public/stage_answer.js +56 -0
  212. data/lib/samagotchi/web/public/stage_asking.js +7 -5
  213. data/lib/samagotchi/web/public/stage_cloud.js +93 -0
  214. data/lib/samagotchi/web/public/stage_dom.js +100 -0
  215. data/lib/samagotchi/web/public/stage_handoff.js +154 -0
  216. data/lib/samagotchi/web/public/stage_owner_wait.js +35 -0
  217. data/lib/samagotchi/web/public/stage_pager.js +59 -0
  218. data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
  219. data/lib/samagotchi/web/public/stage_view.js +103 -410
  220. data/lib/samagotchi/web/public/stage_waiting.js +74 -6
  221. data/lib/samagotchi/web/public/start_page.js +12 -33
  222. data/lib/samagotchi/web/public/start_settings.js +24 -78
  223. data/lib/samagotchi/web/public/start_toolkit.js +6 -10
  224. data/lib/samagotchi/web/public/storage.js +22 -0
  225. data/lib/samagotchi/web/public/stream_handlers.js +3 -10
  226. data/lib/samagotchi/web/public/tokens.css +1 -1
  227. data/lib/samagotchi/web/public/turn_block.js +2 -5
  228. data/lib/samagotchi/web/public/turn_events.js +30 -12
  229. data/lib/samagotchi/web/public/turn_html.js +9 -2
  230. data/lib/samagotchi/web/public/turn_pieces.js +3 -4
  231. data/lib/samagotchi/web/public/turn_range.js +1 -2
  232. data/lib/samagotchi/web/public/verify_target.js +2 -4
  233. data/lib/samagotchi/web/public/viewer.js +59 -0
  234. data/lib/samagotchi/web/public/viewer_self.js +59 -0
  235. data/lib/samagotchi/web/public/working_set.js +11 -5
  236. data/lib/samagotchi/web/public/working_set_view.js +53 -8
  237. data/lib/samagotchi/web/public/ws_cards.js +89 -0
  238. data/lib/samagotchi/web/public/ws_peek.js +106 -0
  239. data/lib/samagotchi/web/public/ws_preview.css +126 -0
  240. data/lib/samagotchi/web/public/ws_reader.js +319 -0
  241. data/lib/samagotchi/web/public/ws_timeline.js +200 -0
  242. data/lib/samagotchi/web/public/ws_way_in.js +25 -0
  243. data/lib/samagotchi/web/qr.rb +1 -1
  244. data/lib/samagotchi/web/session_control.rb +42 -15
  245. data/lib/samagotchi/web/session_create.rb +6 -72
  246. data/lib/samagotchi/web/session_show.rb +75 -28
  247. data/lib/samagotchi/web/session_summary.rb +1 -4
  248. data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
  249. data/lib/samagotchi/web/viewer.rb +70 -0
  250. data/lib/samagotchi/web/working_set_routes.rb +132 -0
  251. data/lib/samagotchi/worker.rb +35 -28
  252. data/lib/samagotchi/worker_inbound.rb +4 -3
  253. data/lib/samagotchi/worker_link.rb +17 -0
  254. data/lib/samagotchi/working_set.rb +322 -11
  255. metadata +32 -13
  256. data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
  257. data/lib/samagotchi/participant_mode.rb +0 -86
  258. data/lib/samagotchi/review_apply.rb +0 -131
  259. data/lib/samagotchi/review_command.rb +0 -123
  260. data/lib/samagotchi/review_start.rb +0 -196
  261. data/lib/samagotchi/web/public/participant.html +0 -218
  262. data/lib/samagotchi/web/public/participant.js +0 -719
  263. data/lib/samagotchi/web/public/participant_annotate.js +0 -76
  264. data/lib/samagotchi/web/public/review_apply.js +0 -34
  265. data/lib/samagotchi/web/public/review_history.js +0 -72
  266. data/lib/samagotchi/web/public/review_start.js +0 -55
  267. data/lib/samagotchi/web/public/tools_overview.js +0 -42
data/docs/sessions.md CHANGED
@@ -6,9 +6,9 @@ Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/s
6
6
 
7
7
  **Verify verdicts:** a web Verify turn stamps its opening user message with `verify: {turn_id, quote}` (the selected source turn and quote; metadata only, never added to the prompt). When that turn completes and the final assistant reply's last non-empty line is a valid `Verdict: confirmed|refuted|unclear — <reason>`, the session file appends `{anchor: {turn_id, quote}, verdict, reason, by, check_turn_id, at}` to its optional `verdicts` array. `by` is the turn's author (nil for the owner), `check_turn_id` names the Verify turn, and `at` is its timestamp. The array is append-only; older files without it have no saved verdicts. An `unclear` verdict can be checked again by **Verify fresh** (a delegate child that gets only the claim; see *Delegating*): its verdict is appended to the parent's `verdicts` with `fresh: true`, `of` (the verdict it checked again) and `child_id`, from the parent's `fresh_verdicts/` dir, which its worker takes between turns. Verdicts are display state: none enters a prompt.
8
8
 
9
- **Revise stacks:** a web Revise turn (POST /turn `revises: {turn_id}`, the answer it rewrites) stamps its opening message (its prompt) with `revises: {turn_id}` at the turn's end, only when the turn completed with an answer (`AnswerTail`): a failed, canceled or empty turn revised nothing (`TurnStages::VerifyAnchors#stamp_opening`). A draft no prompt carries (a stale page, a rolled-back turn) is no target: no stamp. A draft a stamped turn already revised is re-targeted to its stack's top, the newest version, so a stack is a chain `v1 ← v2 ← v3`. Like `verify`, it is metadata only, never added to the prompt (no change to a request's bytes); chi web's history passes it on the opening message (and on a wake turn's note), and `:turn_completed` carries the stamped `revises` (the participant view's too). The history also marks a Verify turn's opening `verify: true`, and so does its live end event (`:turn_completed`'s `verify: true`, with its `turn_id`): the page offers no Revise on its answer. The web page draws the stacks from these stamps (docs/cli.md, Revise). Like a Verify turn's, a Revise message waits for the running turn's end (`SessionInbox.turn_end_data?`; the Bridge takes either as `delivery: queue`, so it never cuts and its ack and `:turn_enqueued` say it queues), is sent only to a worker whose `bridge.json` names the `revise` feature (else 409 `revise_unavailable`), and a failed turn gives it back (`:prompt_restored`'s `revises`). Participants can't Revise: chi web and the Bridge drop it from their turns. Both anchors travel as one `TurnAnchors` inside chi; on the wire and in an input file each keeps its own key (`verify`, `revises`).
9
+ **Revise stacks:** a web Revise turn (POST /turn `revises: {turn_id}`, the answer it rewrites) stamps its opening message (its prompt) with `revises: {turn_id}` at the turn's end, only when the turn completed with an answer (`AnswerTail`): a failed, canceled or empty turn revised nothing (`TurnStages::VerifyAnchors#stamp_opening`). A draft no prompt carries (a stale page, a rolled-back turn) is no target: no stamp. A draft a stamped turn already revised is re-targeted to its stack's top, the newest version, so a stack is a chain `v1 ← v2 ← v3`. Like `verify`, it is metadata only, never added to the prompt (no change to a request's bytes); chi web's history passes it on the opening message (and on a wake turn's note), and `:turn_completed` carries the stamped `revises` (the participant view's too). The history also marks a Verify turn's opening `verify: true`, and so does its live end event (`:turn_completed`'s `verify: true`, with its `turn_id`): the page offers no Revise on its answer. The web page draws the stacks from these stamps (docs/cli.md, Revise). Like a Verify turn's, a Revise message waits for the running turn's end (`SessionInbox.turn_end_data?`; the Bridge takes either as `delivery: queue`, so it never cuts and its ack and `:turn_enqueued` say it queues), is sent only to a worker whose `bridge.json` names the `revise` feature (else 409 `revise_unavailable`), and a failed turn gives it back (`:prompt_restored`'s `revises`). A participant's Revise is theirs only (`ParticipantRevise`, from the authors the server stamped): the answer to their own message (not a Verify turn's), with only their own turn openings after it (an owner's `!` line, which they never see, counts for nothing). chi web checks it at the send against the live worker's snapshot (403 `revise_not_own`, the same for a missing turn; 409 `revise_overtaken`; 409 `revise_unavailable` for a live worker without the `participant_revise` feature), and the worker checks it again at the stamp, up to the Revise turn itself. A Revise someone else's turn overtook after the send silently becomes a plain turn: it runs and answers, but nothing folds, no stack is drawn and neither they nor the owner get a notice; only a `revise_anchor_rejected` log line (reason `overtaken` or `not_own`) records it. It isn't refused at the start because a participant gets no `prompt_restored`, so their text would be lost. A delivery to a live worker without `participant_revise` is refused too (`SessionManager::Delivery`, 409 `revise_unavailable` in their words). The owner's Revise is unchanged, of anyone's answer. Both anchors travel as one `TurnAnchors` inside chi; on the wire and in an input file each keeps its own key (`verify`, `revises`).
10
10
 
11
- **Input files:** a message for a session's worker waits in `input/<timestamp>.json` (`SessionInbox.write_input`: `prompt`, `client_id`, `enqueued_id`, and `images`, `no_interrupt` and `delivery` when they apply; `delivery` is written only for `"queue"`). While a turn runs, the worker merges them at each step boundary in name order, except a queued one or one with images: those wait for the turn's end and run one turn each, in name order, and a file after them still merges (`Worker#pending_input_drain`). For each file it merges, before deleting it, the drain records which turn took it: `input/merged/<enqueued_id>` = `{"into": the turn's enqueued_id, "at"}` (`SessionInbox.mark_merged`; none for a turn without an id), so a wait for that message waits for that turn (`ReplyWait::Poll#follow_merge`). A turn nobody typed (a reminder, a wake turn: a delegate report's, an attached context change's, a finished task's) gets an `enqueued_id` its worker mints as it runs, `wake-` and 16 hex digits (`Worker#wake_origin`), for its mark, `last_turn`, reply file and settle; the reports it merges keep id-less origins. Such a file, with a prompt, from the user, `chi send` or a delegating parent, also ends a running `task_wait` or `delegate_result` and hands a running `execute` over as a task after 3 s (`SessionInbox.steer_waiting?`, a peek the worker's turn polls through `Engine#input_waiting?`; never in a participant's turn): the file stays for the drain. A queue is sent only to a worker whose `bridge.json` names the `delivery` feature; an older one would steer it, so `SessionManager.deliver_turn` refuses it (409 `delivery_unavailable`), and any other 4xx the Bridge answers is a refusal too, never a fallback file (except a 413, a body over its size limit: that one still goes in as a file, its `delivery` kept). A session command recognized in a file runs without a turn; its outcome is kept at `input/settled/<enqueued_id>` (`completed`, `failed` for a command error, `canceled` with `cancel_reason` `busy` or `dropped` for one refused mid-turn or dropped as the worker left; `origin: command`) so `chi send --wait` ends instead of waiting for a turn that will not run, its detail saying `the command failed` or `the command was refused (busy)` rather than a turn's words. **Reply files:** a turn that ends with visible text leaves its reply in `output/<timestamp>.txt`, or `output/<timestamp>-<enqueued_id>.txt` when the turn ran an input file with an id (`SessionInbox.write_output`), and the session's `last_turn` keeps that `enqueued_id`; so a wait for one queued message (`chi send --queue --wait`, `ReplyWait`'s `turn:`) finds its own turn's reply or end, never another turn's. The names still sort by time, and every reader takes `*.txt`.
11
+ **Input files:** a message for a session's worker waits in `input/<timestamp>.json` (`SessionInbox.write_input`: `prompt`, `client_id`, `enqueued_id`, and `images`, `no_interrupt` and `delivery` when they apply; `delivery` is written only for `"queue"`). While a turn runs, the worker merges them at each step boundary in name order, except a queued one, one with images or one whose author isn't the running turn's (a participant's goes only into their own turn, and a participant's turn takes nobody else's: `SessionInbox.turn_end_data?`): those wait for the turn's end and run one turn each, in name order, and a file after them still merges (`Worker#pending_input_drain`). For each file it merges, before deleting it, the drain records which turn took it: `input/merged/<enqueued_id>` = `{"into": the turn's enqueued_id, "at"}` (`SessionInbox.mark_merged`; none for a turn without an id), so a wait for that message waits for that turn (`ReplyWait::Poll#follow_merge`). A turn nobody typed (a reminder, a wake turn: a delegate report's, an attached context change's, a finished task's) gets an `enqueued_id` its worker mints as it runs, `wake-` and 16 hex digits (`Worker#wake_origin`), for its mark, `last_turn`, reply file and settle; the reports it merges keep id-less origins. Such a file, with a prompt, from the user, `chi send` or a delegating parent, also ends a running `task_wait` or `delegate_result` and hands a running `execute` over as a task after 3 s (`SessionInbox.steer_waiting?`, a peek the worker's turn polls through `Engine#input_waiting?`; in a participant's turn only their own line): the file stays for the drain. A queue is sent only to a worker whose `bridge.json` names the `delivery` feature; an older one would steer it, so `SessionManager.deliver_turn` refuses it (409 `delivery_unavailable`), and any other 4xx the Bridge answers is a refusal too, never a fallback file (except a 413, a body over its size limit: that one still goes in as a file, its `delivery` kept). A session command recognized in a file runs without a turn; its outcome is kept at `input/settled/<enqueued_id>` (`completed`, `failed` for a command error, `canceled` with `cancel_reason` `busy` or `dropped` for one refused mid-turn or dropped as the worker left; `origin: command`) so `chi send --wait` ends instead of waiting for a turn that will not run, its detail saying `the command failed` or `the command was refused (busy)` rather than a turn's words. **Reply files:** a turn that ends with visible text leaves its reply in `output/<timestamp>.txt`, or `output/<timestamp>-<enqueued_id>.txt` when the turn ran an input file with an id (`SessionInbox.write_output`), and the session's `last_turn` keeps that `enqueued_id`; so a wait for one queued message (`chi send --queue --wait`, `ReplyWait`'s `turn:`) finds its own turn's reply or end, never another turn's. The names still sort by time, and every reader takes `*.txt`.
12
12
 
13
13
  **Removing a queued message:** a message queued for after the running turn (`chi send --queue`, the web's Alt+Enter, `/queue TEXT` in a terminal), or one with images (it waits for the turn's end too), can be taken back while it still waits: the worker's Bridge (`POST /session/:id/turn/dequeue {enqueued_id}`, the `unqueue` feature) deletes its input file and every UI drops it (`:turn_dequeued`). It is a race with the turn's end, decided by the same rename the worker uses to take the file: once a turn took it the answer is `409 already_started` (it runs), and an id the worker no longer knows is `404 unknown_enqueued_id`. A plain message sent without `--queue` is not removable (`409 not_queued`): a running turn's next step may take it at any moment. A wait for its turn (`chi send --queue --wait`, a delegate follow-up's wait) ends at once with `removed` (the tombstone `input/removed/<enqueued_id>` says so), and a `chi -p` run whose queued prompt went ends with exit 1. The `200` carries the removed `prompt`: the web and the attached terminal put it back into the composer to edit (not its images). The images a removed message named stay in the session's `images/`. Not removable: a queued session command (`/queue /model x`: it waits in the worker, not in `input/`), and a message in a stopped worker's inbox (the next worker runs it).
14
14
 
@@ -27,7 +27,7 @@ A session is deleted if **expired by age OR overflow by count** (unless `keep_st
27
27
 
28
28
  **Empty sessions:** a session nothing happened in is deleted when it is left, so `chi` → `/exit` leaves no trace. Empty means: no messages, no turn tried (a failed turn leaves a `last_prompt` and keeps it), no memory used, no pending question, nothing in `input/`, `notes/` or `images/`, nothing in its dir beyond the worker's skeleton, mode `assist`, and the default model. A session on another model (`/model`, `--model`) counts as prepared and stays (`SessionManager.discardable?`). The worker checks as it idle-exits or leaves on a client's request and deletes it once its lock is free, checking again first. The attached `/exit` then says `Detached; the session is empty: it will be discarded if nothing arrives before its worker stops.` (a note or prompt landing first keeps it). The retention sweep catches those killed first: empty sessions over an hour old with no live owner, whatever `DAYS`/`MAX`, and skeleton-only dirs with no `*.json` (removed as a delete removes, every session store, under the session's lock: a worker or a start that took the session since the check keeps it, and so does one whose file or content was written meanwhile, read again under that lock). `session.keep_empty: true` (env `SAMAGOTCHI_SESSION_KEEP_EMPTY`) turns all of it off.
29
29
 
30
- **Participants:** a session its owner invited participants to review (`chi share`, see [CLI: Participants](cli.md#participants)) has two more files in its dir, neither in the session JSON: `participants.json` (0600), who is or was invited (`{participants: [{id, kind, name, role, added_at, expires_at, removed_at}]}`, never a token), which chi web and `chi share` write and the worker reads (`Participants.read`); and `participants.jsonl` (0600, append-only), the audit trail (grants issued, revoked and expired, each new peer, refused routes). A session nobody was invited to has neither. A continue, a fork or a delegate starts with no participants. Archiving or deleting the session revokes its links. See [internals/participants.md](internals/participants.md).
30
+ **Participants:** a session its owner invited participants into (`chi share`, see [CLI: Participants](cli.md#participants)) has two more files in its dir, neither in the session JSON: `participants.json` (0600), who is or was invited (`{participants: [{id, kind, name, role, added_at, expires_at, removed_at}]}`, never a token), which chi web and `chi share` write and the worker reads (`Participants.read`); and `participants.jsonl` (0600, append-only), the audit trail (grants issued, revoked and expired, each new peer, refused routes). A session nobody was invited to has neither. A continue, a fork or a delegate starts with no participants. Archiving or deleting the session revokes its links. See [internals/participants.md](internals/participants.md).
31
31
 
32
32
  **Always attached:** every interactive `chi` (plain, `-p`, `--resume ID`, `--attach ID`, `chi scratch`) runs its session in a background worker and attaches to it; there is no setting for it. The worker runs in the session's `working_directory`, so `!commands` and tools see the directory the session was started in. Only `chi -p TEXT --non-interactive` runs its one turn in this process; while it does, the session can't be attached ("in use by a one-turn chi --non-interactive run or an older chi's terminal"). See [CLI: Sharing a session](cli.md#sharing-a-session).
33
33
 
@@ -45,7 +45,7 @@ A new session field is one `Session::FIELDS` row, plus a `SessionSetup` member w
45
45
 
46
46
  **Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped}`; 409 `owned_by_tui` or `still_stopping`; 404).
47
47
 
48
- <a id="archiving-a-session"></a>**Archiving a session:** `chi sessions archive ID...`, `/archive` in a terminal and the Web UI's `archive` go through `SessionManager.archive_session`: it writes `<id>/archived` (`{"archived_at": …}`; not a session.json field, which every save rewrites) for the session and its delegated children. `Session.list` leaves archived sessions out unless `include_archived:`, and everything built on it follows: `chi sessions list` (`--archived` shows them, `[archived]`), the summaries (`--live`, json/tsv, the desktop panel, the agent's `list_sessions`) and the retention prune, which neither deletes nor counts them against `max_count`. `children_of` (max_children, `delegate_result`) still sees them, and `--resume`/`--attach ID`, `chi send`/`chi note ID` reach them as before, except that `chi send` and `chi note` to a link that was continued go to its chain's newest link (*Session chains*). Refused: a turn running in the session or in one of its children (naming the child; 409 `busy` on the web), a prompt queued in `input/` (it would run on the next resume) or a live worker's step-limit question still open, in it or a child (409 `busy` too), a one-turn `chi --non-interactive` run owning it (`owned_by_tui`), a `chi scratch` session (`scratch`). A live idle worker is stopped first, and the marker is written even if it is still shutting down. Input a human typed brings a session back (`{"unarchived_at": …}`): a prompt from the web, an attached terminal or `chi send` (origin `web:*`, `tui:*`, `cli:send`, none), steering merged into a running turn, a `/continue` answer or a question answered (the step-limit question too); a delegate's follow-up, a plugin's turn, a reminder, the idle recap, a note and just opening it don't. A child's input brings only the child back. The retention sweep ages an unarchived session from when it was unarchived, so unarchiving an old session doesn't let the next sweep take it. `/archive` leaves the session first, as `/exit` does, then archives it: in an attached terminal the worker is asked to exit (one that stays up for another UI is stopped by the archive; a running turn, a queued prompt or an open step-limit question refuses it), and an empty session is discarded instead; `chi scratch` refuses it. Typed while a turn runs, `/archive` waits for the turn's end (an attached terminal for the commands queued behind it too) and then archives. `chi sessions unarchive ID...` and the web's `unarchive` bring back the whole family. Web routes: `POST /api/sessions/:id/archive` (200 `{status, session_id, archived, stopped, discarded}`, ids) and `POST /api/sessions/:id/unarchive` (200 `{status, session_id, unarchived}`). The session hub and `GET /api/sessions` keep archived sessions, `archived: true` in their summaries: the page leaves them out of the strip, its count and the list at render, and the `archived` toggle beside the all-sessions search shows them, dimmed with an `archived` badge. The info bar marks a session whose live worker runs an older chi than the newest installed (`worker_version` in its summary): `chi 0.18.1 · Restart`, which asks to confirm and calls `POST /api/sessions/:id/restart` (a refusal's reason shows in a toast); a worker from before restarts shows `chi sessions stop ID` instead. The info bar reads `continue → · archive · stop · delete` (`unarchive` on an archived one; no `continue →` on a link continued already, see *Session chains*; `continue →` is a plain button like `archive`, in the accent on an archived session, where it is the thing to do); archiving the open session stays on it, with an Undo toast.
48
+ <a id="archiving-a-session"></a>**Archiving a session:** `chi sessions archive ID...`, `/archive` in a terminal and the Web UI's `archive` go through `SessionManager.archive_session`: it writes `<id>/archived` (`{"archived_at": …}`; not a session.json field, which every save rewrites) for the session and its delegated children. `Session.list` leaves archived sessions out unless `include_archived:`, and everything built on it follows: `chi sessions list` (`--archived` shows them, `[archived]`), the summaries (`--live`, json/tsv, the desktop panel, the agent's `list_sessions`) and the retention prune, which neither deletes nor counts them against `max_count`. `children_of` (max_children, `delegate_result`) still sees them, and `--resume`/`--attach ID`, `chi send`/`chi note ID` reach them as before, except that `chi send` and `chi note` to a link that was continued go to its chain's newest link (*Session chains*). Refused: a turn running in the session or in one of its children (naming the child; 409 `busy` on the web), a prompt queued in `input/` (it would run on the next resume) or a live worker's step-limit question still open, in it or a child (409 `busy` too), a one-turn `chi --non-interactive` run owning it (`owned_by_tui`), a `chi scratch` session (`scratch`). A live idle worker is stopped first, and the marker is written even if it is still shutting down. Input a human typed brings a session back (`{"unarchived_at": …}`): a prompt from the web, an attached terminal or `chi send` (origin `web:*`, `tui:*`, `cli:send`, its own first prompt: `spawn:first`; input naming no sender doesn't), steering merged into a running turn, a `/continue` answer or a question answered (the step-limit question too); a delegate's follow-up, a plugin's turn, a reminder, the idle recap, a note and just opening it don't. A child's input brings only the child back. The retention sweep ages an unarchived session from when it was unarchived, so unarchiving an old session doesn't let the next sweep take it. `/archive` leaves the session first, as `/exit` does, then archives it: in an attached terminal the worker is asked to exit (one that stays up for another UI is stopped by the archive; a running turn, a queued prompt or an open step-limit question refuses it), and an empty session is discarded instead; `chi scratch` refuses it. Typed while a turn runs, `/archive` waits for the turn's end (an attached terminal for the commands queued behind it too) and then archives. `chi sessions unarchive ID...` and the web's `unarchive` bring back the whole family. Web routes: `POST /api/sessions/:id/archive` (200 `{status, session_id, archived, stopped, discarded}`, ids) and `POST /api/sessions/:id/unarchive` (200 `{status, session_id, unarchived}`). The session hub and `GET /api/sessions` keep archived sessions, `archived: true` in their summaries: the page leaves them out of the strip, its count and the list at render, and the `archived` toggle beside the all-sessions search shows them, dimmed with an `archived` badge. The info bar marks a session whose live worker runs an older chi than the newest installed (`worker_version` in its summary): `chi 0.18.1 · Restart`, which asks to confirm and calls `POST /api/sessions/:id/restart` (a refusal's reason shows in a toast); a worker from before restarts shows `chi sessions stop ID` instead. The info bar reads `continue → · archive · stop · delete` (`unarchive` on an archived one; no `continue →` on a link continued already, see *Session chains*; `continue →` is a plain button like `archive`, in the accent on an archived session, where it is the thing to do); archiving the open session stays on it, with an Undo toast.
49
49
 
50
50
  **System 1's saved runs** last as long as sessions: the sweep ages them by day file, and deleting a session purges its runs ([system-one.md](system-one.md)).
51
51
 
@@ -102,9 +102,9 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
102
102
  - The web header's project chip opens a picker. The start project is the default row (including its start folder); other rows show their root, session and waiting counts. **All projects** opens every session, and choosing a project drops the open-session hash while keeping `?view=`.
103
103
 
104
104
  - `Session.list` / `SessionManager.list_sessions` / `GET /api/sessions?sort=&order=&limit=&offset=` default to `updated_at desc` (newest activity first). Also supports `created_at`, `asc`. `X-Total-Count` header when paginated.
105
- - Web UI (`chi web`): the page's scope is in its URL. Started in a project (a git repository or a `chi project init` folder), `chi web` opens `/?dir=<that folder>`: that project's sessions, and new sessions start in that folder; the header chip says `<project> · all`, and `all` opens the same place as `?scope=all` (every session; a new session there starts in chi web's start folder, shown on the start page, and cards name their folder; `← <project>` goes back to the project view it came from, or to the start folder's project). A bare `/` (the LAN link, the Home Screen app) is the start folder's project too: the folder chi web runs in, or `web.start_dir` / `chi web --start-dir DIR`; outside a project (no repository or marked folder) it shows every session. A pushed notification opens its session in that session's own project (`/?dir=<its project>#/s/<id>`; `?scope=all` outside a project). One server serves every project: a second `chi web` (from another repo) finds it through `GET /api/info` and prints (with `--open`, opens) its page for its own folder instead of starting another. The 3 latest sessions sit above the chat, and the grip on the chat's top edge — the same thin handle as the composer's, its twin — puts them away and brings them back: a drag up (or a click, or Enter/Space on it) hides them, a drag down (or a click) shows them again, and the choice is remembered. A hidden strip leaves its status in the top bar (`N sessions · ● 1 live · ● 1 waiting`, from the cards), and a click on that pill opens All sessions, without showing the strip first; there the pill shows whatever the strip's state, pressed, and a click on it goes back to the chat (as Esc does). In a window under 900 px wide, where the strip scrolls sideways, the grip stays under it, outside the scroller; a window under 700 px tall hides the strip by itself, so a question or approval card in the stage keeps room, and the grip shows it until the window is tall again. A parent and its delegates are one card there: its `▸ 2 delegates · 1 live · 1 waiting` chip (the waiting part in the attention colour, the card's border too; just `▸ 2 delegates` while the rows are open: they carry the marks then) opens their rows in a popover under it (a row per delegate at any depth, indented; a click opens that one, Esc or a click outside closes it, and the strip's order holds while it is open). A fork is a card of its own, and so is a delegate whose parent isn't listed (archived, another project), with its `↳ <parent>` chip; the pill counts cards, and every live or waiting session. "All sessions" (or `/`) opens every session at `#/sessions`; its header is the top bar's right end: a search over preview, id and status, the count, an `archived` toggle and Select (on a phone a row of its own under the bar). Esc or the pressed pill returns; where the sessions are stored is a faint line under the list. A card is its title on one line (an untitled session reads `Untitled` over its first message), a line under it (its recap, else its first message) and its meta row, with one mark per state and no status dot: a waiting card has its warn outline and its `question` (or `approval`…) chip, an errored one an `error` badge, a session a worker runs the `live` badge (not on a waiting card: waiting means a worker), and idle, completed and stopped ones are unmarked; a family's and a chain's rows the same. There a parent's card holds its delegates the same way, the chip opening their rows inside the card (each with an archive button on hover), open by itself while one of them waits on you; the count says `14 · 7 delegates` (`3 / 14` while a search narrows it), a search that matches a delegate shows its parent's card with the list open and the matching rows marked, and select mode picks cards (archiving a parent takes its delegates). The open session is in the URL (`#/s/<id>`), so a reload or a copied link opens it again; the chi logo top left goes back to the empty start for a new session. The message box grows with its text; drag its top edge to keep it taller (double-click resets). A file in a tool row (a read, edit or write's title) and its diff lines are refs: hover one and click to open the current file in your editor at that line, on this machine only (`web.editor`; the browser's "always allow" for the page's port and VS Code's "allow opening local files" are asked once; see [Opening files from chi web](configuration.md#opening-files-from-chi-web)). So are an edit or write approval card's paths (at the first line the dry run changes) and its diff lines, before you approve, and the numbered lines of a read's output: `lines 40–60` under it opens the text as read, numbered, when the output is the file as-is (not the head/tail preview of a big file, an error or an image; no numbers after a cut). A `path:line` (or `path:line-line`) in an answer or a step's text is one too once the turn has ended, and after a reload, when it names a file a row or card on the page touched: the path under the session's folder, else the one touched file it ends with (a bare `app.js:12` when only one touched file is named so; two such files make it none); a path without a line counts only when it is a touched file exactly. Code blocks, links, bare URLs and inline code with more than the ref in it are left alone, and a file the session didn't touch is never linked; a link whose text is such a ref alone (github-pr's link to the PR diff) becomes a ref too, and its plain click still goes to the PR. A plugin's refs on an answer (an `after_turn` hook's, see [Refs on the answer](hooks.md#refs-on-the-answer-display-only)) are paired with its links and text whatever the rows touched: they can link a file the session didn't touch, or an issue or a commit, and add their own actions to the ref's menu. A plugin tool's row carries the refs its `refs:` gives (see [Refs on a tool's row](plugins.md#refs-on-a-tools-row)): its title opens the first, and its `▾` menu adds the others as `<ref> · <action>` (the URL on hover); their URL actions work on a phone too. A ref with more than one target shows a small `▾` on hover: it opens a menu of them, in order **PR diff** (a link's), **Open in editor**, **Show in turn** and **Copy path**, and a plain click runs the first (a link's own, else the editor, else show in turn). **Show in turn** scrolls to the tool row that touched the file (looked for in the ref's own step, then its own turn, then the rows before it, then the nearest after it; there, the last one showing the ref's line, else the last one), opens the steps, the stage's steps and the row's diff (or the read showing the line) and flashes the row and the line; an answer's or a step's ref and an approval card's path have it, not a row's own title or lines. It needs no editor, so a viewer without one (a phone on the LAN) gets an answer's refs with **Show in turn** as their click; a row's title and diff lines stay plain text there. On a touch screen a tap opens the menu. A ref with a target is a tab stop: Enter runs its first target, ↓ opens the menu (↑/↓ move, Enter picks, Esc closes back to the ref). Diff and read lines have their click only. The info bar's id copies the full session id on click ("Session id copied"), the id every CLI command takes (`chi --attach ID`, `chi send ID`). A session whose prompt carried model notes has a `notes: deepseek` chip there (the names without `model_notes_`; the tooltip lists each with its scope and size; `session.prompt_notes` in `GET /api/sessions/:id`, the live worker's, else the session file's; see [Memory](memory.md#model-notes)). Its ⚙ chip, after the model, holds the session's thinking level, reasoning history and LLM context: `⚙` alone while the session follows the model for all three, else `⚙` and what the session set, in the accent colour (`⚙ think low · ctx stale,forget`; a phone shows ⚙ with a dot; the tooltip gives each value and its source). Its panel is the start page's ⚙ panel for this session: a Thinking row (`/thinking`), on a chat host a Reasoning row (the reasoning history, `/reasoning-history`), and a Context row with its Apply and budget fields (`/llm-context`); a tap runs that row's command at once in the worker (one reply in the conversation, as a typed one) and changes that field alone, the Context row's `default` resets the strategy, apply rule and budget (`/llm-context reset`), and a tap while a turn runs is queued for after it (the panel's note says so). `GET /api/sessions/:id`'s `session.thinking`, `session.reasoning_history` (null on a native host) and `session.llm_context` carry the values (the live worker's, else resolved from the session file), and a `command_ran` that changed them carries the new ones. After ⚙, the 🧰 chip names the session's toolkit: `🧰` alone on the configured default (`toolkit.default`, `session.toolkit_default`), `🧰 lean` on another (see [Toolkits](configuration.md#toolkits); `/toolkit` changes it). A `/thinking` or `/reasoning-history` change typed in the composer that restarts the prompt cache asks first: the reply bubble has an **Apply (restarts the cache)** button that sends its `--yes` line (the ⚙ panel sends that line itself; see [Changes that restart the prompt cache](configuration.md#changes-that-restart-the-prompt-cache)). It shows the context used (`ctx 42%`) and the last generation's decode speed (`87 tok/s`, `~64 tok/s` when estimated; see `/stats` in [cli.md](cli.md#session-commands)); hovering `ctx` there or on a session card lists the session's tokens in (summed over every request, with the cached share), out (with reasoning) and the cost when the provider reports one, for this session only (one estimated from a `hosts.<name>.models` price shows with `~`: `cost: ~$0.54 ($0.42 reported, ~$0.12 estimated)`); after a `/model` switch the info bar's tooltip adds a `per model:` row per run of turns on one model above those totals (`splash:qwen3-35b · 6 turns · 96.0k in / 9.0k out · ~$0.02`, a switch's prefill under its row: `└ switch prefill 58.0k uncached prompt ≈$0.01`; the timing's `model_segments`, replaced by each `generation_completed`'s; the session cards stay as they were), and right after the switch its ctx % is the new model's window's; and the memory indexes its prompt holds (`memory index: ~3.4k tokens in this session's prompt (system 2.0k, project 1.4k)`; see [Memory](memory.md#the-indexs-size)). The start page's model picker (bottom left of the composer, the chosen name `▾`) chooses the model a new session starts on, and a fresh chain link's (see [Session chains](#session-chains); there a pick shows as a `/model` command bubble in the link); it opens a search list over the conversation (↓ or a click; downward when the start page leaves no room above): an empty search shows the last 5 picks (Recent) and then each host's model ids A–Z under the host, the default host first (an id the host declares under `hosts.<name>.models` first, noted `config`, its tooltip `served by config (hosts.<name>.models)`; a host that failed to list its models keeps those ids, greyed and noted `host down`, still pickable; a remembered or default model stays chosen even then, greyed on the button); typed words must each match the host or the id (a substring, else for 3+ characters the letters in order, so `deepseek4.1 fla` finds `openrouter · deepseek/deepseek-v4.1-flash`), ⏎ picks, Esc/Tab close, a pick puts the focus in the message box: `GET /api/models` lists the hosts' models as chi spells them (`{default, models: [{name, host, id, configured?, unavailable?, sampling?, llm_context?}], warning?}`; `configured: true` marks an id declared under `hosts.<name>.models`, listed first under its host, `unavailable: true` one whose host failed to list its models; `sampling` is the model's configured request parameters as `/model` words them, the row's tooltip in the list; bare for the default host, `host:model` for the others, from the same cached lists as `/models`, a bounded wait, a host that is down noted in `warning`; `toolkits`: `{default, suggest, kits: [{name, description?}]}`, the start page's 🧰 list: the configured `toolkit.default`, `suggest` `on` only when a new session's first message may get a suggested kit (`toolkit.suggest.mode: on`, a System 1 host, two described kits; else `audit` or `off`), and the built-in and config kits a new session can start on, without `review`, `child`, `undecided`, a kit `groups:` refuses or one that doesn't resolve (a base that is a bundle kit), the default always listed; left out when it can't be read), and `POST /api/sessions` takes `model` (blank means the default). Beside it, ⚙ opens the new session's rarely used settings (thinking and LLM context, following each `GET /api/models` row's `thinking` and `llm_context`, and the review files; see [configuration.md](configuration.md#llm-context-a-sessions-own-strategy)), and 🧰 its toolkit: **Auto** (with `toolkit.suggest.mode: on`: the first message may get a suggested kit, else the default) or a kit from the payload's `toolkits`, sent as `POST /api/sessions`'s `toolkit` (see [configuration.md](configuration.md#toolkits)); a refused kit (`400 toolkit_refused`) is said in the list, opened again. What is set shows on the row as an accent chip (`think high`, `tools: lean`; a dot on ⚙ or 🧰 on a phone); each is for the next new session only, never remembered. The start page's first message goes as later ones do: `POST /api/sessions` with `idle: true` and `preview` (the message, which names the session until its turn is saved), then `POST /api/sessions/:id/turn`, so a failed first turn puts its prompt back in the composer too; a first line that is one of the new session's commands (`/model …`) goes to `POST /api/sessions/:id/command` instead, as later ones do. The browser remembers the last model picked; a running session's model is in the info bar and changes only with `/model`. In the composer a line is a command when it is `!…` or starts with one of the session's command names (its `commands` list; `/stats`, `/exit` and the other terminal words get the page's own reply); an unknown `/word` (`/usr/bin/env is missing`) goes to the model as a prompt, as in a terminal; a one-word `/word` no command answers (`/modle`) is not sent: the page shows `Unknown command /modle. Did you mean /model? /help lists the commands.` (the "Did you mean" part only when a name is close). A `POST /turn` (or a session's first `prompt`) that is one of the worker's commands runs as that command too (`202 {status, command_id, session_id}`), so `chi send`, `chi -p` and a page whose command list lags all get the command. ↑/↓ in the composer walk the prompt history the TUI's ↑ walks ([Persistent Prompt History](cli.md#persistent-prompt-history)): ↑ with the caret on the first line, ↓ from the last line while browsing, ↓ past the newest brings the draft back; `GET /api/history` returns `{entries: [...]}`, oldest first (the page fetches it on focus and after each send). The server records a sent line in the routes once the worker took it (`POST /turn` accepted, a `!command` through `POST /command` or as a session's first line); `"history": false` in the body keeps it out (an image-only send).
105
+ - Web UI (`chi web`): the page's scope is in its URL. Started in a project (a git repository or a `chi project init` folder), `chi web` opens `/?dir=<that folder>`: that project's sessions, and new sessions start in that folder; the header chip says `<project> · all`, and `all` opens the same place as `?scope=all` (every session; a new session there starts in chi web's start folder, shown on the start page, and cards name their folder; `← <project>` goes back to the project view it came from, or to the start folder's project). A bare `/` (the LAN link, the Home Screen app) is the start folder's project too: the folder chi web runs in, or `web.start_dir` / `chi web --start-dir DIR`; outside a project (no repository or marked folder) it shows every session. A pushed notification opens its session in that session's own project (`/?dir=<its project>#/s/<id>`; `?scope=all` outside a project). One server serves every project: a second `chi web` (from another repo) finds it through `GET /api/info` and prints (with `--open`, opens) its page for its own folder instead of starting another. The 3 latest sessions sit above the chat, and the grip on the chat's top edge — the same thin handle as the composer's, its twin — puts them away and brings them back: a drag up (or a click, or Enter/Space on it) hides them, a drag down (or a click) shows them again, and the choice is remembered. A hidden strip leaves its status in the top bar (`N sessions · ● 1 live · ● 1 waiting`, from the cards), and a click on that pill opens All sessions, without showing the strip first; there the pill shows whatever the strip's state, pressed, and a click on it goes back to the chat (as Esc does). In a window under 900 px wide, where the strip scrolls sideways, the grip stays under it, outside the scroller; a window under 700 px tall hides the strip by itself, so a question or approval card in the stage keeps room, and the grip shows it until the window is tall again. A parent and its delegates are one card there: its `▸ 2 delegates · 1 live · 1 waiting` chip (the waiting part in the attention colour, the card's border too; just `▸ 2 delegates` while the rows are open: they carry the marks then) opens their rows in a popover under it (a row per delegate at any depth, indented; a click opens that one, Esc or a click outside closes it, and the strip's order holds while it is open). A fork is a card of its own, and so is a delegate whose parent isn't listed (archived, another project), with its `↳ <parent>` chip; the pill counts cards, and every live or waiting session. "All sessions" (or `/`) opens every session at `#/sessions`; its header is the top bar's right end: a search over preview, id and status, the count, an `archived` toggle and Select (on a phone a row of its own under the bar). Esc or the pressed pill returns; where the sessions are stored is a faint line under the list. A card is its title on one line (an untitled session reads `Untitled` over its first message), a line under it (its recap, else its first message) and its meta row, with one mark per state and no status dot: a waiting card has its warn outline and its `question` (or `approval`…) chip, an errored one an `error` badge, a session a worker runs the `live` badge (not on a waiting card: waiting means a worker), and idle, completed and stopped ones are unmarked; a family's and a chain's rows the same. There a parent's card holds its delegates the same way, the chip opening their rows inside the card (each with an archive button on hover), open by itself while one of them waits on you; the count says `14 · 7 delegates` (`3 / 14` while a search narrows it), a search that matches a delegate shows its parent's card with the list open and the matching rows marked, and select mode picks cards (archiving a parent takes its delegates). The open session is in the URL (`#/s/<id>`), so a reload or a copied link opens it again; the chi logo top left goes back to the empty start for a new session. The message box grows with its text; drag its top edge to keep it taller (double-click resets). A file in a tool row (a read, edit or write's title) and its diff lines are refs: hover one and click to open the current file in your editor at that line, on this machine only (`web.editor`; the browser's "always allow" for the page's port and VS Code's "allow opening local files" are asked once; see [Opening files from chi web](configuration.md#opening-files-from-chi-web)). So are an edit or write approval card's paths (at the first line the dry run changes) and its diff lines, before you approve, and the numbered lines of a read's output: `lines 40–60` under it opens the text as read, numbered, when the output is the file as-is (not the head/tail preview of a big file, an error or an image; no numbers after a cut). A `path:line` (or `path:line-line`) in an answer or a step's text is one too once the turn has ended, and after a reload, when it names a file a row or card on the page touched: the path under the session's folder, else the one touched file it ends with (a bare `app.js:12` when only one touched file is named so; two such files make it none); a path without a line counts only when it is a touched file exactly. Code blocks, links, bare URLs and inline code with more than the ref in it are left alone, and a file the session didn't touch is never linked; a link whose text is such a ref alone (github-pr's link to the PR diff) becomes a ref too, and its plain click still goes to the PR. A plugin's refs on an answer (an `after_turn` hook's, see [Refs on the answer](hooks.md#refs-on-the-answer-display-only)) are paired with its links and text whatever the rows touched: they can link a file the session didn't touch, or an issue or a commit, and add their own actions to the ref's menu. A plugin tool's row carries the refs its `refs:` gives (see [Refs on a tool's row](plugins.md#refs-on-a-tools-row)): its title opens the first, and its `▾` menu adds the others as `<ref> · <action>` (the URL on hover); their URL actions work on a phone too. A ref with more than one target shows a small `▾` on hover: it opens a menu of them, in order **PR diff** (a link's), **Open in editor**, **Show in turn** and **Copy path**, and a plain click runs the first (a link's own, else the editor, else show in turn). **Show in turn** scrolls to the tool row that touched the file (looked for in the ref's own step, then its own turn, then the rows before it, then the nearest after it; there, the last one showing the ref's line, else the last one), opens the steps, the stage's steps and the row's diff (or the read showing the line) and flashes the row and the line; an answer's or a step's ref and an approval card's path have it, not a row's own title or lines. It needs no editor, so a viewer without one (a phone on the LAN) gets an answer's refs with **Show in turn** as their click; a row's title and diff lines stay plain text there. On a touch screen a tap opens the menu. A ref with a target is a tab stop: Enter runs its first target, ↓ opens the menu (↑/↓ move, Enter picks, Esc closes back to the ref). Diff and read lines have their click only. The info bar's id copies the full session id on click ("Session id copied"), the id every CLI command takes (`chi --attach ID`, `chi send ID`). A session whose prompt carried model notes has a `notes: deepseek` chip there (the names without `model_notes_`; the tooltip lists each with its scope and size; `session.prompt_notes` in `GET /api/sessions/:id`, the live worker's, else the session file's; see [Memory](memory.md#model-notes)). Its ⚙ chip, after the model, holds the session's thinking level, reasoning history and LLM context: `⚙` alone while the session follows the model for all three, else `⚙` and what the session set, in the accent colour (`⚙ think low · ctx stale,forget`; a phone shows ⚙ with a dot; the tooltip gives each value and its source). Its panel is the start page's ⚙ panel for this session: a Thinking row (`/thinking`), on a chat host a Reasoning row (the reasoning history, `/reasoning-history`), and a Context row with its Apply and budget fields (`/llm-context`); a tap runs that row's command at once in the worker (one reply in the conversation, as a typed one) and changes that field alone, the Context row's `default` resets the strategy, apply rule and budget (`/llm-context reset`), and a tap while a turn runs is queued for after it (the panel's note says so). `GET /api/sessions/:id`'s `session.thinking`, `session.reasoning_history` (null on a native host) and `session.llm_context` carry the values (the live worker's, else resolved from the session file), and a `command_ran` that changed them carries the new ones. After ⚙, the 🧰 chip names the session's toolkit: `🧰` alone on the configured default (`toolkit.default`, `session.toolkit_default`), `🧰 lean` on another (see [Toolkits](configuration.md#toolkits); `/toolkit` changes it). A `/thinking` or `/reasoning-history` change typed in the composer that restarts the prompt cache asks first: the reply bubble has an **Apply (restarts the cache)** button that sends its `--yes` line (the ⚙ panel sends that line itself; see [Changes that restart the prompt cache](configuration.md#changes-that-restart-the-prompt-cache)). It shows the context used (`ctx 42%`) and the last generation's decode speed (`87 tok/s`, `~64 tok/s` when estimated; see `/stats` in [cli.md](cli.md#session-commands)); hovering `ctx` there or on a session card lists the session's tokens in (summed over every request, with the cached share), out (with reasoning) and the cost when the provider reports one, for this session only (one estimated from a `hosts.<name>.models` price shows with `~`: `cost: ~$0.54 ($0.42 reported, ~$0.12 estimated)`); after a `/model` switch the info bar's tooltip adds a `per model:` row per run of turns on one model above those totals (`splash:qwen3-35b · 6 turns · 96.0k in / 9.0k out · ~$0.02`, a switch's prefill under its row: `└ switch prefill 58.0k uncached prompt ≈$0.01`; the timing's `model_segments`, replaced by each `generation_completed`'s; the session cards stay as they were), and right after the switch its ctx % is the new model's window's; and the memory indexes its prompt holds (`memory index: ~3.4k tokens in this session's prompt (system 2.0k, project 1.4k)`; see [Memory](memory.md#the-indexs-size)). The start page's model picker (bottom left of the composer, the chosen name `▾`) chooses the model a new session starts on, and a fresh chain link's (see [Session chains](#session-chains); there a pick shows as a `/model` command bubble in the link); it opens a search list over the conversation (↓ or a click; downward when the start page leaves no room above): an empty search shows the last 5 picks (Recent) and then each host's model ids A–Z under the host, the default host first (an id the host declares under `hosts.<name>.models` first, noted `config`, its tooltip `served by config (hosts.<name>.models)`; a host that failed to list its models keeps those ids, greyed and noted `host down`, still pickable; a remembered or default model stays chosen even then, greyed on the button); typed words must each match the host or the id (a substring, else for 3+ characters the letters in order, so `deepseek4.1 fla` finds `openrouter · deepseek/deepseek-v4.1-flash`), ⏎ picks, Esc/Tab close, a pick puts the focus in the message box: `GET /api/models` lists the hosts' models as chi spells them (`{default, models: [{name, host, id, configured?, unavailable?, sampling?, llm_context?}], warning?}`; `configured: true` marks an id declared under `hosts.<name>.models`, listed first under its host, `unavailable: true` one whose host failed to list its models; `sampling` is the model's configured request parameters as `/model` words them, the row's tooltip in the list; bare for the default host, `host:model` for the others, from the same cached lists as `/models`, a bounded wait, a host that is down noted in `warning`; `toolkits`: `{default, suggest, kits: [{name, description?}]}`, the start page's 🧰 list: the configured `toolkit.default`, `suggest` `on` only when a new session's first message may get a suggested kit (`toolkit.suggest.mode: on`, a System 1 host, two described kits; else `audit` or `off`), and the built-in and config kits a new session can start on, without `child` or `undecided`, a kit `groups:` refuses or one that doesn't resolve (a base that is a bundle kit), the default always listed; left out when it can't be read), and `POST /api/sessions` takes `model` (blank means the default). Beside it, ⚙ opens the new session's rarely used settings (thinking and LLM context, following each `GET /api/models` row's `thinking` and `llm_context`, ; see [configuration.md](configuration.md#llm-context-a-sessions-own-strategy)), and 🧰 its toolkit: **Auto** (with `toolkit.suggest.mode: on`: the first message may get a suggested kit, else the default) or a kit from the payload's `toolkits`, sent as `POST /api/sessions`'s `toolkit` (see [configuration.md](configuration.md#toolkits)); a refused kit (`400 toolkit_refused`) is said in the list, opened again. What is set shows on the row as an accent chip (`think high`, `tools: lean`; a dot on ⚙ or 🧰 on a phone); each is for the next new session only, never remembered. The start page's first message goes as later ones do: `POST /api/sessions` with `idle: true` and `preview` (the message, which names the session until its turn is saved), then `POST /api/sessions/:id/turn`, so a failed first turn puts its prompt back in the composer too; a first line that is one of the new session's commands (`/model …`) goes to `POST /api/sessions/:id/command` instead, as later ones do. The browser remembers the last model picked; a running session's model is in the info bar and changes only with `/model`. In the composer a line is a command when it is `!…` or starts with one of the session's command names (its `commands` list; `/stats`, `/exit` and the other terminal words get the page's own reply); an unknown `/word` (`/usr/bin/env is missing`) goes to the model as a prompt, as in a terminal; a one-word `/word` no command answers (`/modle`) is not sent: the page shows `Unknown command /modle. Did you mean /model? /help lists the commands.` (the "Did you mean" part only when a name is close). A `POST /turn` (or a session's first `prompt`) that is one of the worker's commands runs as that command too (`202 {status, command_id, session_id}`), so `chi send`, `chi -p` and a page whose command list lags all get the command. ↑/↓ in the composer walk the prompt history the TUI's ↑ walks ([Persistent Prompt History](cli.md#persistent-prompt-history)): ↑ with the caret on the first line, ↓ from the last line while browsing, ↓ past the newest brings the draft back; `GET /api/history` returns `{entries: [...]}`, oldest first (the page fetches it on focus and after each send). The server records a sent line in the routes once the worker took it (`POST /turn` accepted, a `!command` through `POST /command` or as a session's first line); `"history": false` in the body keeps it out (an image-only send).
106
106
  - Web notifications: when a session needs you while the tab is hidden or behind another window (a question or a guardrail approval, a plugin card with buttons during a turn such as check-in's, a failed turn, a turn done after 10 s or more; a delegated session only for its questions, a canceled turn never), the page title counts it, `(N) Chi`, until you come back to the tab. The bell at the right of the top bar also turns on OS notifications ("needs an answer", "needs approval", "needs you", "turn failed", "done in 42 s", under the session's first message; a click opens the session): its first click asks the browser for the permission, and the choice is kept per browser. Any session of the page's scope counts, not only the open one. What was already so when the page loaded never counts, and several chi tabs show one notification per event. A chi tab in front tells the others (a `BroadcastChannel`), so while you look at one, the ones behind neither notify nor count what it shows; coming back to a tab clears those events in the other tabs' titles too. The hub's `session` frames carry what this needs: `pending_question` (`{id, kind}`, kind `question` or `approval`), `pending_card` (`{id, bundle}`: the running turn's card with actions, from `pending_card.json` that the worker keeps in the session's folder while one is open; a card without actions, such as loop-guard's, never counts) and `last_turn` (`{outcome, ended_at, seconds, origin}`, saved in the session's JSON as the engine ends each turn).
107
- - The web frontend is a zero-build ES-module stack in `lib/samagotchi/web/public/`: `data.js` (retrieval, typed SSE `openStream` for a session and `openEvents` for the session list), `sessions_list.js` (the list as a pure reducer over `GET /api/events`: a snapshot replaces it, an upsert keeps a known card in place, a removal drops it; `families()` groups delegates under their parent), `families_view.js` (a parent's family chip, its rows and the strip's popover; the chip and rows as lit-html templates), `keep_focus.js` (lit reuses a list's nodes by position: a redraw keeps the focus on the same item by its `data-id` / `data-name`), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `#N` chip and rows as lit-html templates, the info bar's ← → links, a refused continue, and the fresh-link rule), `notify.js` (which of those events needs the user, for the notifications), `app.js` (presentation/state; a session with no live stream gets one when its `session` event says `bridge_up`, after one re-read: `event_seq` starts over in each worker, so a dropped stream is never resumed with its old cursor), `bubbles.js` (the history's bubbles between the turns' rows: output chunks, end lines, every client's prompt bubbles by `enqueued_id` with their queued/steered badges, the idle recap, guardrail warnings, hooks' notices, plugins' steers, command and note bubbles; lit-html templates, put in the history with the sticky follow by `createBubbles`), `cards_place.js` (where plugin cards and a snapshot's notices go in the history: a card added or updated in place by its id, a running turn's into its step, a snapshot's each above the first turn after it, a finished turn's notice in its step's rows and its question resolved where it was asked; a card's action buttons), `format.js` (pure formatters such as `previewOf`), `plain_line.js` (markdown out of the plain one-line places: the stage headline, a closed step's title, an answered question card's kept-reply line), `prompt_history.js` (the composer's ↑/↓ over the shared prompt history), `commands.js` (session commands: which composer lines are commands, the page's own replies, a `command_ran`'s bubble, the page's command bubbles kept across a re-read), `composer.js` (where a composer line goes, `routeComposerLine`: /cut and /queue, the start page's own replies, a session command or `!cmd`, a typo hint, else a turn; and a session command sent from the composer or a chip), `delivery_line.js` (the composer's row above the text field in a session, always there so the composer keeps its height (on a phone no row: the line lies over the session bar's left while a turn runs and you type or have a choice armed): the key hint while idle, and the delivery line while a turn runs: where a message typed now goes in, from the step's phase, clock and size, whether "cut in now" can land, and the queue link for a worker with the `delivery` feature, as a pure `deliveryLine`, its lit-html template and `createDeliveryControl`, which ticks it and keeps a choice armed from a link; see docs/cli.md, "Typing during a turn"), `restore.js` (a failed turn's prompt handed back into this tab's composer, before or after its `/turn` ack), `lists_view.js` (the session lists: the strip and its pill, all sessions with its search, count and select mode, their cards, the family and chain popovers; the cards, tile and pill as lit-html templates, drawn as new nodes each time, and the lists' orders as pure functions), `stream_handlers.js` (the open session's stream event handlers, by event type, over the page's views and hooks; a snapshot replays through them too), `stage_view.js` (the stage view: the running turn pinned above the composer, with Stop turn in its status row while it runs, then handed off into the history; its pure rules and texts in `stage_model.js`, its live slots (headline, now row, trail, ticks) in `stage_slots.js`, its cap and held height in `stage_frame.js`, the in-use watch that times the hand-off in `stage_watch.js`), `info_bar.js` (the session bar's info line as a lit-html template over a plain model, three groups with hairlines between them, on one line above a phone's width (the folder gives way first): the setup (id, status, model, the ⚙ and 🧰 chips, notes, the memory or working-set chip), the relations (chain links, the parent as `↑ <id>`, delegates, participants; only when there is one) and the telemetry (folder, ctx, speed, the session's time, worker badge)), `settings_chip.js` (the session bar's ⚙ chip and its panel over `settings_panel.js`: a tap runs that row's command, one field), `toolkit_chip.js` (the session bar's 🧰 chip: the kit against `toolkit.default`), `info_bar_model.js` (that model and the bar's buttons' states, built from the page's session state, its list and its in-flight continues and restarts (the restarting set is `version_notices.js`'s) as pure functions; `app.js`'s `updateInfoBar` applies them every second while a turn runs), `session_state.js` (what the page knows about the open session: its empty state, and `sessionStateFrom`, the fields a `GET /sessions/:id` payload sets), `refs.js` (refs: a kind and a target on the element, a plugin's ref data (label, http(s) URL actions) bound in a WeakMap by `bindRef`, the targets per kind, show in turn, one delegated set of click, key and hover listeners), `ref_menu.js` (a ref's `▾` and its menu), `ref_scan.js` (the `path:line` refs in an answer's or a step's text that name a file the session's rows touched), `answer_refs.js` (the refs a plugin attached to an answer, its `display_refs`: bound to the answer's bubble, paired with its links and text, bound with `bindRef`), `markdown_place.js` (where rendered markdown and its refs go: a text as markdown HTML, its `path:line` refs, a final answer's rendering), `images.js` (image chips in the composer: paste, drop and the image button, the upload before a turn, the thumbnails and the lightbox), `composer_grip.js` (the composer's grip and fold: the drag, tap and keys, the fold per visit), `composer_mount.js` (the composer mounted on a page's markup: the message box and its height, the image chips from a paste, a drop or the image button, the grip and fold, ↑/↓ over the prompt history and the keys; the page's own parts come in as hooks: what Enter and Send do, keys taken first, Esc, where the history comes from, the info bar's drop while folded, typing anywhere to open it; its styles, the card it sits in (`.composer-card`, its footer and its line above the text field) included, are the shared `composer.css`, linked after `tokens.css` by `index.html` and `participant.html`), `strip_grip.js` (the latest-sessions strip's grip, the composer grip's twin: hides and shows the strip), `strip_hidden.js` (the strip hidden or shown: the saved choice, the short window's own hide, the grip and the body's class), `review_history.js` (a participant's ↑/↓ list on the participant page: their own comments, in localStorage per grant, never the owner's `/api/history`; `participant.js` mounts `composer_mount.js` with it, no `/` list, no delivery choices, images off), `storage.js` (the page's per-browser choices in localStorage, guarded: a choice that can't be read or written is not remembered), `unqueue.js` (the × on a message queued for after the turn: takes it back, its text into an empty composer or a toast), `toasts.js` (the page's toast stack: a timer each, sticky ones until acted on, the same text reusing its item), `toast_place.js` (where the toast sits: above the composer card, the stage and an open model panel), `dock_reserve.js` (what floats over the history: the history's bottom reserve (`--dock-h`) at the composer card's and the showing stage's height, a reader at the end kept there, and the toast's place measured for `toast_place.js`), `notice_links.js` (a hook notice line's http(s) URLs as links), `start_page.js` (the start page's model picker, its ⚙ panel's and 🧰 list's choices for the next new session only and their override chips; a fresh chain link's picker and its `/model`), `start_settings.js` (the start page's ⚙ panel: thinking and LLM context as rows of segments, applied at once, the Apply and budget disclosure, the review files' view; the override chips' words and ⚙'s dot), `settings_panel.js` (the panel's rows as lit-html templates, shared: the segments, the disclosure, a hidden row's sent-anyway line, the review line; the caller passes its rows and applies the picks), `start_toolkit.js` (the start page's 🧰 list: Auto with suggest on, the kits, the default marked; a pick closes it; its override chip and dot), `session_actions.js` (Continue, Archive and its Undo, Delete and Stop, and the start page when the open session is gone), `send_turn.js` (the composer's send: a new session first on the start page, the route, the echo, the image upload, the `/turn` ack, a fast failure's restore and each error's place). Unit-tested via `npm test` (`spec/web/public/*.test.js`).
107
+ - The web frontend is a zero-build ES-module stack in `lib/samagotchi/web/public/`: `data.js` (retrieval, typed SSE `openStream` for a session and `openEvents` for the session list), `sessions_list.js` (the list as a pure reducer over `GET /api/events`: a snapshot replaces it, an upsert keeps a known card in place, a removal drops it; `families()` groups delegates under their parent), `families_view.js` (a parent's family chip, its rows and the strip's popover; the chip and rows as lit-html templates), `keep_focus.js` (lit reuses a list's nodes by position: a redraw keeps the focus on the same item by its `data-id` / `data-name`), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `#N` chip and rows as lit-html templates, the info bar's ← → links, a refused continue, and the fresh-link rule), `notify.js` (which of those events needs the user, for the notifications), `app.js` (presentation/state; a session with no live stream gets one when its `session` event says `bridge_up`, after one re-read: `event_seq` starts over in each worker, so a dropped stream is never resumed with its old cursor), `bubbles.js` (the history's bubbles between the turns' rows: output chunks, end lines, every client's prompt bubbles by `enqueued_id` with their queued/steered badges, the idle recap, guardrail warnings, hooks' notices, plugins' steers, command and note bubbles; lit-html templates, put in the history with the sticky follow by `createBubbles`), `cards_place.js` (where plugin cards and a snapshot's notices go in the history: a card added or updated in place by its id, a running turn's into its step, a snapshot's each above the first turn after it, a finished turn's notice in its step's rows and its question resolved where it was asked; a card's action buttons), `format.js` (pure formatters such as `previewOf`), `plain_line.js` (markdown out of the plain one-line places: the stage headline, a closed step's title, an answered question card's kept-reply line), `prompt_history.js` (the composer's ↑/↓ over the shared prompt history), `commands.js` (session commands: which composer lines are commands, the page's own replies, a `command_ran`'s bubble, the page's command bubbles kept across a re-read), `composer.js` (where a composer line goes, `routeComposerLine`: /cut and /queue, the start page's own replies, a session command or `!cmd`, a typo hint, else a turn; and a session command sent from the composer or a chip), `delivery_line.js` (the composer's row above the text field in a session, always there so the composer keeps its height (on a phone no row: the line lies over the session bar's left while a turn runs and you type or have a choice armed): the key hint while idle, and the delivery line while a turn runs: where a message typed now goes in, from the step's phase, clock and size, whether "cut in now" can land, and the queue link for a worker with the `delivery` feature, as a pure `deliveryLine`, its lit-html template and `createDeliveryControl`, which ticks it and keeps a choice armed from a link; see docs/cli.md, "Typing during a turn"), `restore.js` (a failed turn's prompt handed back into this tab's composer, before or after its `/turn` ack), `lists_view.js` (the session lists: the strip and its pill, all sessions with its search, count and select mode, their cards, the family and chain popovers; the cards, tile and pill as lit-html templates, drawn as new nodes each time, and the lists' orders as pure functions), `stream_handlers.js` (the open session's stream event handlers, by event type, over the page's views and hooks; a snapshot replays through them too), `stage_view.js` (the stage view: the running turn pinned above the composer, with Stop turn in its status row while it runs, then handed off into the history; its pure rules and texts in `stage_model.js`, its live slots (headline, now row, trail, ticks) in `stage_slots.js`, its cap and held height in `stage_frame.js`, the in-use watch that times the hand-off in `stage_watch.js`), `info_bar.js` (the session bar's info line as a lit-html template over a plain model, three groups with hairlines between them, on one line above a phone's width (the folder gives way first): the setup (id, status, model, the ⚙ and 🧰 chips, notes, the memory or working-set chip), the relations (chain links, the parent as `↑ <id>`, delegates, participants; only when there is one) and the telemetry (folder, ctx, speed, the session's time, worker badge)), `settings_chip.js` (the session bar's ⚙ chip and its panel over `settings_panel.js`: a tap runs that row's command, one field), `toolkit_chip.js` (the session bar's 🧰 chip: the kit against `toolkit.default`), `info_bar_model.js` (that model and the bar's buttons' states, built from the page's session state, its list and its in-flight continues and restarts (the restarting set is `version_notices.js`'s) as pure functions; `app.js`'s `updateInfoBar` applies them every second while a turn runs), `session_state.js` (what the page knows about the open session: its empty state, and `sessionStateFrom`, the fields a `GET /sessions/:id` payload sets), `refs.js` (refs: a kind and a target on the element, a plugin's ref data (label, http(s) URL actions) bound in a WeakMap by `bindRef`, the targets per kind, show in turn, one delegated set of click, key and hover listeners), `ref_menu.js` (a ref's `▾` and its menu), `ref_scan.js` (the `path:line` refs in an answer's or a step's text that name a file the session's rows touched), `answer_refs.js` (the refs a plugin attached to an answer, its `display_refs`: bound to the answer's bubble, paired with its links and text, bound with `bindRef`), `markdown_place.js` (where rendered markdown and its refs go: a text as markdown HTML, its `path:line` refs, a final answer's rendering), `images.js` (image chips in the composer: paste, drop and the image button, the upload before a turn, the thumbnails and the lightbox), `composer_grip.js` (the composer's grip and fold: the drag, tap and keys, the fold per visit), `composer_mount.js` (the composer mounted on a page's markup: the message box and its height, the image chips from a paste, a drop or the image button, the grip and fold, ↑/↓ over the prompt history and the keys; the page's own parts come in as hooks: what Enter and Send do, keys taken first, Esc, where the history comes from, the info bar's drop while folded, typing anywhere to open it; its styles, the card it sits in (`.composer-card`, its footer and its line above the text field) included, are the shared `composer.css`, linked after `tokens.css` by `index.html`), `strip_grip.js` (the latest-sessions strip's grip, the composer grip's twin: hides and shows the strip), `strip_hidden.js` (the strip hidden or shown: the saved choice, the short window's own hide, the grip and the body's class), `storage.js` (the page's per-browser choices in localStorage, guarded: a choice that can't be read or written is not remembered), `unqueue.js` (the × on a message queued for after the turn: takes it back, its text into an empty composer or a toast), `toasts.js` (the page's toast stack: a timer each, sticky ones until acted on, the same text reusing its item), `toast_place.js` (where the toast sits: above the composer card, the stage and an open model panel), `dock_reserve.js` (what floats over the history: the history's bottom reserve (`--dock-h`) at the composer card's and the showing stage's height, a reader at the end kept there, and the toast's place measured for `toast_place.js`), `notice_links.js` (a hook notice line's http(s) URLs as links), `start_page.js` (the start page's model picker, its ⚙ panel's and 🧰 list's choices for the next new session only and their override chips; a fresh chain link's picker and its `/model`), `start_settings.js` (the start page's ⚙ panel: thinking and LLM context as rows of segments, applied at once, the Apply and budget disclosure; the override chips' words and ⚙'s dot), `settings_panel.js` (the panel's rows as lit-html templates, shared: the segments, the disclosure, a hidden row's sent-anyway line; the caller passes its rows and applies the picks), `start_toolkit.js` (the start page's 🧰 list: Auto with suggest on, the kits, the default marked; a pick closes it; its override chip and dot), `session_actions.js` (Continue, Archive and its Undo, Delete and Stop, and the start page when the open session is gone), `send_turn.js` (the composer's send: a new session first on the start page, the route, the echo, the image upload, the `/turn` ack, a fast failure's restore and each error's place). Unit-tested via `npm test` (`spec/web/public/*.test.js`).
108
108
  - Selecting a session in the web UI is read-only: `GET /api/sessions/:id` never spawns a worker (it reads a live worker's snapshot when one runs, else the session file). A prompt (`POST /turn`) or a command (`POST /command`) wakes the worker, and `/stream` briefly waits for a freshly-spawned bridge before answering. A caught-up SSE reconnect holds the stream open; `reset` markers are only sent for reconnects behind the ring window, or with a cursor from another worker (event ids are `<event_seq>-<epoch>`, one epoch per worker).
109
109
  - The web session page's message box folds away for room to read. Drag the grip on its top edge (the pill that shows on hover; always on a phone) down, past the box by 32 px: the pill turns accent while releasing would hide it, and on release the box folds and the info bar stays as the page's bottom edge. The grip stays as a handle on the info bar's top edge, drawn always: pull it up (8 px opens it, and the box follows the pointer in the same gesture), click or tap it (opens it and focuses the box), or just type on the page (the key lands in the box) to bring it back; Enter or Space on the focused grip folds or opens too. A draft (text or images, which folding never clears) colours the handle with the accent, a session waiting on you with the attention colour; its tooltip says so. Stop turn isn't the message box's: it sits in the running turn's stage, at the right edge of its status row beside the fold caret (collapsed stage or not), while the turn runs, and goes when the turn ends A turn the page knows runs but has nothing of to draw (a reload whose session payload carries no current turn) shows that status row alone, `running` and Stop turn. The fold is remembered per browser (`chi_composer_collapsed`), an archived session opens folded for the visit, and opening it there, like the page opening it itself (a restored line, a quote, continue →'s opener), is for that visit only. The fold keeps the height the grip set (`chi_composer_floor`): the box opens again at the height it had, and only a double-click on the grip forgets it. That height never takes more than half of the window the box is drawn in: a floor saved in a bigger window is held to that half in a smaller one (a rotated phone, a resized window, another device on the same origin), and the saved floor itself stays, so the height comes back when the room does. A click on the expanded grip hides the box as well: it folds 250 ms after the press, so a second click inside that window is read as a double-click and resets the height instead (a drag, Enter or Space act at once, and a drag after a click takes the wait back). The start page's grip only resizes.
110
110
 
@@ -157,7 +157,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
157
157
  | `interrupted_turn` | The mark of a turn a worker checkpointed and never finished (`InterruptedTurn`); the next worker settles it and sets it to `null`. | the worker |
158
158
  | `parent_answers` | Its own `guardrails.parent_answers` (it may only tighten config.yml's). | creation (`--parent-answers`), `/parent-answers` |
159
159
  | `working_set_pins` | The working-set items the user pinned (`/working-set pin`); kept by a respawn, a continue and a fork. | the Engine's command |
160
- | `review` | A review session's subjects and source (`SessionReview`), see [Review sessions](#review-sessions). | `ReviewStart` |
160
+ | `review` | An older chi's review session's subjects and source (`SessionReview`), kept as written, never read: see [Older review sessions](#older-review-sessions). | an older chi |
161
161
  | `first_turn_id` | The id the creating prompt's turn gets, so a wait can name it (`chi send --new --wait`, `--wait --turn T ID`); `null` for a session created idle. | `SessionManager.spawn_session` |
162
162
  | `first_turn_client_id` | Who sent the creating prompt when no person did (`delegate:<parent8>` for a delegate's task, `system:schedule:<id>` for a chain schedule's link): that first turn's origin, so its line is no command of the owner's (docs/guardrails.md, Who may run a session command) and `last_turn` names the sender. Written only when set; not carried by a fork, a continue or a delegate. An older chi keeps it but runs the first prompt as a person's. | `SessionManager.spawn_session` (its `client_id:`) |
163
163
  | `verify_fresh` | A Verify fresh child's requester, rules and claim (`VerifyFreshOrigin`). | `VerifyFresh.start`, once |
@@ -208,7 +208,7 @@ optionally a done-when hint, which nothing enforces.
208
208
 
209
209
  An edit waits for a moment between turns: it lands within seconds in an idle session, and at the turn's end during one.
210
210
  Several edits made during a turn go in as one list. A continue copies the list to the next link, as a second note after
211
- the carry note; a review link doesn't. `!rollback` keeps it. A session a one-turn `chi --non-interactive` run has refuses an edit, as it
211
+ the carry note. `!rollback` keeps it. A session a one-turn `chi --non-interactive` run has refuses an edit, as it
212
212
  refuses a note. See [cli.md](cli.md#session-objectives) for the commands and
213
213
  [internals/objectives.md](internals/objectives.md) for the mechanism.
214
214
 
@@ -372,7 +372,7 @@ A session can **continue** an earlier one: "the next run of the same routine" (a
372
372
  `SessionContinue.run` makes the next link:
373
373
 
374
374
  - **What it copies:** the previous link's folder, its model (the name it was typed as, so an alias holds) unless the continue names one (`--model`, the web's `model`), its own LLM context values, and its `--memory` and `--mute` lists. It does not carry the reserved `system/delegated` memory when the previous link is a delegate child: a continuation has no parent and is no longer a delegate. A model given is checked like a new session's (a host config.yml doesn't have refuses the continue, nothing archived). An inherited model whose host can't run it any more (gone from config.yml, `enabled: false`, an alias naming another host) **falls back to the default model** with a warning, `gone:org/model can't run (unknown host 'gone' in model …); started on <default>`, decided before the archive; with no default model configured the continue is refused. The carry note doesn't mention the model. The new link carries no transcript beyond the note's last answer, so a different model, or another provider, starts clean there. Its preview is the previous link's (until its first message is saved), unless it starts with a message. Its title (`/title`) is the previous link's, with or without a first message.
375
- - **The carry note:** the new link starts with a context note from `session chain` (shown in its transcript as `note from session chain`), queued before its worker spawns, so its first turn sees it: `This session continues 3fa2c1d0 (2026-10-08 09:12), the previous link of its chain. Its recap, as of 2026-10-08 18:02:` and the previous link's recap (`recap.json`; cut at 8000 characters). No recap (fewer user turns than a recap needs, recaps off, none written in time): `… It left no recap.` Then `Its last answer:` and the previous link's last answer, read after the recap wait, so its exact shas, paths and next steps survive: a longer one keeps its last 4000 characters, after a `…` (a wrap-up closes on what comes next). There is none when the newest bubble was a step that asked for tools, when a later turn failed or was cut before it answered, and on a review link (a continue doesn't copy the grants, so the next link's participants could differ); `session.carry_last_answer: false` leaves it out of every note. No other transcript. The note never makes a continue fail: it stays within the 16 KiB a note may hold, the answer taking what the head and recap leave, and a session file that can't be read gives no answer. An idle new link holding only the note is kept, not discarded as empty.
375
+ - **The carry note:** the new link starts with a context note from `session chain` (shown in its transcript as `note from session chain`), queued before its worker spawns, so its first turn sees it: `This session continues 3fa2c1d0 (2026-10-08 09:12), the previous link of its chain. Its recap, as of 2026-10-08 18:02:` and the previous link's recap (`recap.json`; cut at 8000 characters). No recap (fewer user turns than a recap needs, recaps off, none written in time): `… It left no recap.` Then `Its last answer:` and the previous link's last answer, read after the recap wait, so its exact shas, paths and next steps survive: a longer one keeps its last 4000 characters, after a `…` (a wrap-up closes on what comes next). There is none when the newest bubble was a step that asked for tools, when a later turn failed or was cut before it answered; `session.carry_last_answer: false` leaves it out of every note. No other transcript. The note never makes a continue fail: it stays within the 16 KiB a note may hold, the answer taking what the head and recap leave, and a session file that can't be read gives no answer. An idle new link holding only the note is kept, not discarded as empty.
376
376
  - **Its attached context:** the previous link's movable sources (a command source by default; a pushed one stays) are copied to the new link before its worker starts, with their last text and the removed and muted markers, and a second note (`attached context`, after the carry note) names what moved and what stayed. A push into the archived link is then refused with the new link's id. See [Movable context](context.md#movable-context).
377
377
  - **Its waiting notes:** the previous link's unabsorbed context notes move to the new link (`NoteMove.move`, the continue's last step before the worker starts, after the objectives' carry, which reads a pending `/objectives` edit from them first), file names kept, so they keep their ids and order and come ahead of the carry note. An `/objectives` note stays (the carry took its list), and so do the notes an earlier continue wrote into the previous link itself (a link continued before it ever started: its own carry note is replaced by the new one). A note an old worker had claimed and not deleted (`*.json.processing`) moves too, un-claimed (logged `notes_moved_claimed`): the previous link is archived, so left there it would be lost; if that worker had already added it to its conversation, the new link sees it once more, a rare duplicate rather than a loss. A note sent to the previous link after that goes to the new one (*Context notes*). One that still lands in an earlier link (sent just as the continue saved the new link, or by an older chi that knows no chain) is adopted by the new link's worker on its next pass: it looks back along the chain, one listing at its start, through up to 8 archived links, each one whose next link is the one after it, stopping at a link back in the lists or gone, and takes from each only the notes from the creation of the link that continued it on, never an `/objectives` note; older ones (left by a continue before notes moved) stay with the archived link, logged once (`notes_left_old`). An earlier link that is brought back (input un-archives it) keeps its notes while it is back; archived again, the newest link's running worker adopts from it again, so a note it got meanwhile and never absorbed comes to the newest link.
378
378
  - **The recap first:** a previous link with a live worker is asked for a recap (the Bridge's `POST /recap`) and given up to 30 s to write it; one with none wrote its recap when its worker left.
@@ -409,45 +409,14 @@ running. A schedule turn carries `client_id: "system:schedule:<id>`, so both UIs
409
409
  label it `schedule`. Full details, the busy check and the DST caveat:
410
410
  [Scheduling](scheduling.md).
411
411
 
412
- ## Review sessions
413
-
414
- A **review session** is one made to be shared with participants (the shared-sessions plan's D2: a review is its own
415
- session, so a participant's review turn can't quote a working session's tool outputs, and only reads). Sharing a
416
- working session itself is pairing: a participant's turns there act with its tools under the owner's guardrails
417
- ([CLI: Participants](cli.md#participants), [guardrails](guardrails.md#a-participants-pair-boundary)). `chi review FILE…` starts one
418
- in a project, `chi review --from ID` as a review fork of a working session (see [CLI: Review
419
- sessions](cli.md#review-sessions)); both start idle and print the `chi share` line to invite someone.
420
-
421
- - **The field:** `review: {subjects: ["docs/plan.md", …], from: "<id>"}` in the session JSON: the subjects relative
422
- to the project root (the work tree top of its folder, its folder outside git), and for a fork the session it
423
- started from. A session without one has no `review` key at all, so other session files save as they were. A
424
- continue keeps it; a fork (`ctx.sessions.fork`) and a delegate child don't.
425
- - **The subjects** are checked where the session starts (`ReviewStart.check_subjects`), by the same check a review
426
- turn's `read` goes through (`Guardrails::ReviewPaths`): an existing file under the project root, as given and as it
427
- resolves, never a secret file or chi's own. They are what participants read beside the thread, and may quote into
428
- a comment (Annotate: [participants.md](internals/participants.md#what-a-participant-sees)).
429
- - **The note:** it starts with a context note from `review` naming the subjects and what a review turn does; a fork's
430
- starts with `This review session starts from 3f9a1c2e (2026-10-23 09:12), a working session: it brings that
431
- session's recap, not its transcript.` and the recap (as a continue's carry note), so nothing of the source's
432
- history comes along. Its preview is `review: docs/plan.md`, or a fork's `review of <the source's title>`.
433
- - **A fork isn't a continue:** the source is neither archived nor continued (no `continues`), and its delegates stay
434
- its own; a coordinator can open a review of its own session and keep working (`/coordinate review`).
435
- - **Its setup:** a review fork carries the source's `--mute` list, but not its `--memory` preloads.
436
- - **Web:** `POST /api/sessions` takes `review: {subjects: [...], from: "<id>"}` instead of a `prompt` (a review
437
- session starts idle: `prompt`, `preview`, `idle` and `continues` beside it are 400 `invalid_review`). Without
438
- `from`, the subjects are relative to `dir` and the setup fields work as for any create; with `from`, the source's
439
- folder and setup are taken (`dir` and the setup fields beside it are 400 `invalid_review`) and `model` is the
440
- only choice. A subject refused, or the source's folder gone, is 400 `invalid_review` with the one message; an
441
- unknown source 404 `not_found`.
442
- - **The page:** the start page's ⚙ panel, **Review files…**, takes the files (comma- or
443
- space-separated, relative to the page's folder; a path with a space in double quotes, `"docs/my plan.md"`): the
444
- row then shows a `review: plan.md +1` chip, and Start makes a review session (the message typed, if any, is its first
445
- turn; with none it starts idle). A refused file shows the server's one message in the panel's review view, opened again. On a session that isn't a review session the participants panel (the session bar's
446
- participants chip) says so before its Invite, with the share warning (that a participant's turns act there, writes
447
- included and asks to the owner, or only read while an older worker holds it; how many tool outputs its history holds)
448
- and **Start a review of it**: a review fork of it, opened, with a toast (`Review 4b7e9a01 started from 3f9a1c2e's
449
- recap; 3f9a1c2e keeps running.`) whose **Invite** opens the new session's panel. Every summary carries `review`
450
- (null for other sessions).
412
+ ## Older review sessions
413
+
414
+ An older chi could start a **review session** (`chi review`, the web's Start review), shared with participants
415
+ whose turns only read. This chi starts none and runs no read-only turn: such a session is an ordinary one. Its
416
+ `review: {subjects, from}` key loads and is written back as it was (a continue copies it), and nothing reads it:
417
+ its participants' turns act under the owner's guardrails like anyone's, a continue carries its last answer and
418
+ objectives, and context candidates are proposed in it. Its old read-only invites have ended ("this link is from an
419
+ older chi"); invite them again ([CLI: Participants](cli.md#participants)).
451
420
 
452
421
  ## Toolkits
453
422
 
data/docs/sub-agent.md CHANGED
@@ -69,9 +69,9 @@ Exit codes, both commands:
69
69
  | 0 | `command` | (`chi send`) the message was a session command (`/model x`): it ran as one, no reply comes |
70
70
  | 0 | `not_continued` | (`chi answer`) a Stop answered the step-limit question; the turn's work so far stays |
71
71
  | 3 | `question` | chi waits for an answer: `question`, `answer_with` |
72
- | 3 | `waiting_for_owner` | (a participant's wait, `chi --remote NAME send --wait` with their link's token) their review turn waits on the session's owner: a question or an approval it raised, or the owner's step-limit Continue; wait again |
72
+ | 3 | `waiting_for_owner` | (a participant's wait, `chi --remote NAME send --wait` with their link's token) their turn waits on the session's owner: a question or an approval it raised, or the owner's step-limit Continue; wait again |
73
73
  | 4 | `running` | `--timeout` passed; the turn goes on, wait again |
74
- | 1 | `refused` | (a participant's wait) their queued review turn was refused before it ran: `cancel_reason` `revoked` (their link was revoked or expired) or `cap_reached` (they spent their cap); no turn ran for it |
74
+ | 1 | `refused` | (a participant's wait) their queued turn was refused before it ran: `cancel_reason` `revoked` (their link was revoked or expired), `outdated` (their link is an older chi's read-only one) or `cap_reached` (they spent their cap); no turn ran for it |
75
75
  | 1 | `failed`, `canceled`, `limit`, `removed`, `no_answer`, `error`, `worker_gone`, `stopped` | `detail` says what happened (`limit`: the turn ran out of steps and nobody can be asked, e.g. an older worker; `chi send ID -m '/continue yes'` continues it, except under `guardrails.parent_answers: hard`, where a parent's `/continue yes` is refused as its `chi answer --option Continue` is; `removed`: the `--queue` message waited for was taken back before it ran, no turn ran for it). `failed` adds `error_kind` (the provider error's kind: `credits`, `credits_held`, `rate_limited`, `server`, `auth`, `connection`, …) and `retryable` when known; `canceled` adds `cancel_reason` (`user`: a Stop in the web; `session_stopped`: a session stop, `chi sessions stop` or the web's; `worker_stopped`: the turn waited for (a `--queue` message's, a message's to an idle session, the running turn a message merged into or a plain `--wait` saw running) died with its worker (detail "its worker exited mid-turn"), settled by the next one; `hook`; `ctrl_c`; `manual`) and `stopped_by` (the hook that stopped it, e.g. `loop-guard`) when known |
76
76
  | 2 | (no JSON) | usage error, or an option the question doesn't offer |
77
77
  | 130 | `running` | Ctrl-C; the turn goes on |
data/docs/system-one.md CHANGED
@@ -26,7 +26,7 @@ one warn and never changes the answer. A use that needs the run's id at once pas
26
26
 
27
27
  Not saved: a toolkit warm-up (it goes straight to the backend), `chi guardrails replay`,
28
28
  chi web's availability check, a scratch session's asks or anything about them, and a participant's turn (never judged by core; a bundle's ask there still goes, unsaved).
29
- An owner's turn in a review session is judged, so it is saved. Test runs are saved with `test_run: true`.
29
+ Test runs are saved with `test_run: true`.
30
30
 
31
31
  ## Bundles' judgments
32
32
 
@@ -54,7 +54,7 @@ per-message judge on an objective didn't work as a gate on the pod (AUC about .5
54
54
  into the conversation (not the list's own, nor a continue's carry note: `Objectives.outside_note?`). A steer isn't asked about.
55
55
  - `objectives.outgoing`: a finished answer of the owner's turn of 400 characters or more, not a cancelled or exhausted one.
56
56
  - The state: `objective` (its text and done-when, no id or status) and `message` (2000 characters: a message's head, an answer's tail).
57
- **That text goes to the System 1 host**, a hosted one too, and into the run. A participant's turn, a review session and a scratch session are never asked about.
57
+ **That text goes to the System 1 host**, a hosted one too, and into the run. A participant's turn and a scratch session are never asked about.
58
58
  - At most 6 objectives per message. Each direction has one ask running: what comes meanwhile is a run with `asked: false`, `skipped: busy`.
59
59
  - The asks run on `SideJudgments`' threads beside the turn, so a turn doesn't wait; on a one-slot server shared with the session's model, a request can still queue behind or ahead of them. They share `/v1/systemone` with approvals: on a slow one-slot host an approval can wait behind up to 2 in-flight asks and time out to the user. A failed ask is a run with its `failure` and one log line (`system_one_failed`).
60
60
 
data/docs/testing.md CHANGED
@@ -8,7 +8,7 @@ npm test # web frontend specs
8
8
  npm run lint # web frontend: undefined names and unused imports (ESLint; CI runs it)
9
9
  npm run e2e # web UI happy paths in Chromium, fake model (once: npx playwright install chromium)
10
10
  npx playwright test spec/e2e/stage.spec.js # one e2e file (the root playwright.config.js is the suite's)
11
- bundle exec rake lint # RuboCop: no offenses (CI runs it)
11
+ bundle exec rake lint # RuboCop and script/load-check --strict: no offenses, no findings (CI runs it)
12
12
  ```
13
13
 
14
14
  Run `bundle exec rubocop -a` on the files you changed before committing: every enabled style cop follows the
@@ -20,7 +20,7 @@ bug) or a broken spec: fix it, or disable that line with the reason (`# rubocop:
20
20
  with two rules only, `no-undef` (a name used but never imported or declared: a dropped import) and `no-unused-vars`
21
21
  (an import or variable left over), over the browser's globals (`eslint.config.js`). It is a missing-name guard, not a
22
22
  style pass: add a rule only for a bug class it would have caught. It runs in about 2 s, in CI's `npm test` job and in
23
- `rake release:check`; `rake lint` stays RuboCop alone (CI's rubocop job has no node). A name that is also a browser
23
+ `rake release:check`; `rake lint` stays Ruby only (RuboCop and the load check: CI's rubocop job has no node). A name that is also a browser
24
24
  global (`name`, `status`, `open`…) passes even when its import is gone: give an export such a name only with care.
25
25
  It also caps every web module's size and `app.js`'s own, lower (`max-lines`; see docs/internals/web-frontend.md).
26
26
  It also checks `spec/e2e/` for two things: `no-unused-vars`, and the Playwright twin of `Samagotchi/SpecSleep`: no `page.waitForTimeout`.
@@ -64,8 +64,8 @@ The whole-turn goldens (`spec/engine_turn_golden_spec.rb`, `spec/fixtures/turn_g
64
64
  `Engine#run_turn` (its own KernelLoop, ChatLoop, ToolRunner, Gate and GuardrailWiring) over `FakeProviderServer` on
65
65
  the native (llama.cpp `/completion`, Qwen tool calls), `api: openai` and `api: anthropic` wires: a turn of two tool
66
66
  iterations (a muted `memory_read` and a `read`, then a `write` a config rule asks about, allowed through the question
67
- flow), a `before_turn` hook switching the model (the request names the new model with the old one's sampling), and a
68
- review participant's turn whose `write` the review boundary refuses. Each golden pins every request (the chi-set
67
+ flow), a `before_turn` hook switching the model (the request names the new model with the old one's sampling), and an
68
+ older chi's read-only participant's turn whose `read` and `write` the participant seat refuses (`ParticipantRefusal`). Each golden pins every request (the chi-set
69
69
  headers, the body in its key order, the native prompt as text), the turn's events (keys sorted; the context-status
70
70
  estimates and clock values masked), each `before_tool_call` payload, the approval asked and the session's messages.
71
71
  System 1, the toolkit suggestion, the context judge, the recap and the warm-up are off by config, so the order is the
@@ -84,11 +84,16 @@ next round folds the first three into one wiring example each in `effective_mode
84
84
  `session_model_settings_spec.rb` and `session_setting_spec.rb`, and the ladders the round after into the setting
85
85
  modules' and `model_lookup_spec.rb`.
86
86
 
87
+ The sender rows (`ClientId::ROWS`) have three pins: `spec/client_id_characterization_spec.rb` (what every id chi
88
+ makes, a sample per prefix, nil, "" and unknown ids get from `human?`, `owner?`, `interactive?`, `wake_kind`, `origin`
89
+ and `Steer.source_for_client`: a row change shows up there), `spec/client_id_spec.rb` (every String constant of
90
+ `ClientId` has a row) and `spec/shared/labels_matrix.json` (a client case per row, both UIs' labels).
91
+
87
92
  The session file goldens (`spec/session_file_goldens_spec.rb`, `spec/fixtures/session_goldens/`) pin the bytes `Session#save`
88
93
  writes: every field away from its default, a new session, a newer chi's file, an old chi's file in a git repo, every key
89
94
  present as `null`, the plain writers' raw values, a running turn's checkpoint and the scrub (the `*_in.json` files are
90
95
  hand-written inputs, never regenerated); and the file each path that makes or rewrites a session writes (a fork, a
91
- continue, a delegate child, a plain spawn, a review, a Verify fresh child, a respawn; a resume and an archive leave the bytes as they were), with
96
+ continue, a delegate child, a plain spawn, a Verify fresh child, a respawn; a resume and an archive leave the bytes as they were), with
92
97
  `carry_matrix.json`, what each keeps of its source. They are pinned before Session's fields became one table and are kept
93
98
  as the file format's pins, not retired: a diff is a change to every session file on disk, so only a commit that means to
94
99
  change the format regenerates them (`UPDATE_GOLDENS=1 bundle exec rspec spec/session_file_goldens_spec.rb`).
@@ -190,7 +195,9 @@ registered in `Compat::SHIMS` (`lib/samagotchi/compat.rb`): an id, the release
190
195
  that added it, `remove_after` (nil: the owner hasn't dated it) and its files,
191
196
  each Ruby one naming it in a comment (`compat shim <id>`). `spec/compat_spec.rb`
192
197
  fails once `Samagotchi::VERSION` passes a shim's `remove_after`, naming it:
193
- remove the shim, or move its date with the owner's OK. A new shim gets a row.
198
+ remove the shim, or move its date with the owner's OK. A new shim gets a row
199
+ (`review_client_id`: a participant's `review:<id>` from 0.171 and before, until 0.173; its old-shape samples are
200
+ hand-made in `spec/fixtures/compat_review_client_id/`, as no corpus recorded one).
194
201
 
195
202
  ## Levels
196
203
 
@@ -242,7 +249,7 @@ Each level owns its own share; a detail is asserted once, at the lowest level th
242
249
  its items into turns and gives each a minimal drawing (not the synthesizer: what a real drawing holds is the
243
250
  fixtures'). The
244
251
  `lan` project's chi web is on the LAN only
245
- when the machine has a private IPv4: without one its LAN tests skip and the participant review journey runs on
252
+ when the machine has a private IPv4: without one its LAN tests skip and the participant journey runs on
246
253
  loopback.
247
254
 
248
255
  ## Waiting and time
@@ -588,3 +595,45 @@ The code is `script/deps/deps_check.rb`; its spec stubs every request and comman
588
595
  names (Prism; `be_foo`/`have_foo` count for `foo?`/`has_foo?`), as `path:line name [notes]` with a count; a note says
589
596
  what may explain a row (a doc, a name built at run time, a framework hook). Advisory: it always exits 0, CI doesn't
590
597
  run it. Its spec is `spec/script/dead_code_spec.rb`.
598
+
599
+ ## The load check
600
+
601
+ `script/load-check` reads every file under `lib/samagotchi/` (the shipped bundles under
602
+ `lib/samagotchi/bundles/` apart) and `bin/chi` with Prism and **never loads them**, then checks three rules:
603
+
604
+ 1. **call-time reference** — a constant a method body names is defined in the file or reached by its
605
+ `require`/`require_relative`/`autoload` lines, transitively (a `require` inside a method counts here only);
606
+ 2. **load-time reference** — a constant evaluated while the file loads (a superclass, `include`/`extend`/
607
+ `prepend`, a class body) comes from a file required above that line, and a require cycle does not
608
+ guarantee it;
609
+ 3. **autoload** — an `autoload` may name a constant defined in one file; one that names a namespace
610
+ reopened in several files is a finding. A dynamically named autoload is reported unread, since its name
611
+ cannot be checked.
612
+
613
+ A name that resolves to nothing of chi's (a stdlib or gem constant) is out of scope, and lexical scope is
614
+ mimicked: a bare `Log` inside `module Samagotchi` is `Samagotchi::Log`. Each line is
615
+ `RULE file:line Constant — why`; the summary counts findings per rule, per `lib/samagotchi/<dir or file>`,
616
+ and the files scanned. Report mode exits 0; `--strict` exits 1 when findings remain, and `rake lint` (so
617
+ CI) runs `--strict`: the tree reports none. Its spec is `spec/script/load_check_spec.rb`.
618
+
619
+ **Reading a finding.** `1 lib/samagotchi/engine/models.rb:63 Samagotchi::Log — no require or autoload here
620
+ reaches lib/samagotchi/log.rb, which defines it` says that a method in `models.rb` names `Log` and that the
621
+ file works today only because someone else required `log.rb` first. The fix is the require the line names,
622
+ at the top of the file (`require_relative "../log"`): a require only adds what the file already gets through
623
+ its loaders, so the processes' loaded files don't change (`spec/require_cycle_spec.rb`'s budgets say if they
624
+ do). Prefer an existing door when there is one: `LLM::ChatLoop` is `llm/backend.rb`'s autoload, so a file
625
+ naming it requires `llm/backend`. When the file is needed only on one path a thin process never takes,
626
+ require it inside that method (a method-body require satisfies rule 1). When the require would close a cycle
627
+ (the defining file requires this one: a part naming its host's constants), the finding goes in the
628
+ allow-list. A rule 2 finding is a load-order bug and is fixed, not allow-listed. A rule 3 finding is fixed
629
+ by pointing the autoload at the namespace's base file, or allow-listed when that file requires every file
630
+ that reopens the namespace and nothing else does (then firing the autoload loads it whole).
631
+
632
+ **The allow-list.** `script/load_check/allow.yml` (`--allow FILE` reads another): each entry matches on
633
+ `rule`, `file` and `constant`, with `*` and `[A-Z]` globs, and says why in `reason`. Its entries are of
634
+ four kinds: a part naming its host's value constants (`Samagotchi::Engine::[A-Z][A-Z_]*` in
635
+ `engine/*.rb`: the host requires the part, so a require back is a cycle; the glob leaves classes a part
636
+ names from elsewhere checked), one-off host pairs (`ToolRun` in `tool_response.rb`), the namespace
637
+ autoloads that load whole (`SessionManager`, `Objectives`, `Config`), and `Plugin::Http`'s (its base file
638
+ loads the reopening file only inside a method, and that file requires the base file first). The summary counts the entries that
639
+ matched and those that match nothing: delete a stale one.
@@ -7,6 +7,7 @@ require_relative "../events"
7
7
  require_relative "../state_format"
8
8
  require_relative "card_places"
9
9
  require_relative "turn_notice"
10
+ require_relative "../log"
10
11
 
11
12
  module Samagotchi
12
13
  class Bridge
@@ -5,6 +5,7 @@ require "json"
5
5
  require_relative "client_event"
6
6
  require_relative "event_id"
7
7
  require_relative "../llm/utf8_scrub"
8
+ require_relative "bounded_queue"
8
9
 
9
10
  module Samagotchi
10
11
  class Bridge
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../events"
4
- require_relative "../kernel_loop"
5
4
  require_relative "../log"
6
5
  require_relative "../steer"
7
6
  require_relative "../tool_output_cut"
@@ -83,10 +82,14 @@ module Samagotchi
83
82
  end
84
83
  end
85
84
 
86
- # Whether the turn in progress is a participant's review turn (its
87
- # author): the owner's input queues behind it then (Bridge's POST /turn).
88
- def participant_turn?
89
- @mutex.synchronize { !@turn.nil? && Steer.participant_author?(@turn[:author] || TurnOrigin.from(@turn[:origin])&.author) }
85
+ # Whether the turn in progress is a participant's turn (its author):
86
+ # anyone else's input queues behind it then (Bridge's POST /turn).
87
+ def participant_turn? = !participant_author.nil?
88
+
89
+ # The turn in progress's participant author ("p:<id>"), nil for the
90
+ # owner's or none.
91
+ def participant_author
92
+ @mutex.synchronize { @turn && Steer.sender_author(@turn[:author] || TurnOrigin.from(@turn[:origin])&.author) }
90
93
  end
91
94
 
92
95
  # The turn in progress as conversation messages, for a plugin's