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/guardrails.md CHANGED
@@ -13,8 +13,8 @@ Who votes, in order:
13
13
 
14
14
  1. `before_tool_call` hooks (Ruby; see [Hooks](hooks.md#guardrails-from-a-hook)).
15
15
  2. Core checks (`GuardrailWiring#checks`): a required guardrail that failed to load, then (a participant's turn only)
16
- [the review boundary](#a-participants-review-boundary) or, for a pair turn,
17
- [the pair boundary](#a-participants-pair-boundary), then protected paths, then (a `chi scratch` session only)
16
+ [the pair boundary](#a-participants-pair-boundary) (or, for a turn this chi doesn't run under the owner's rules,
17
+ [the refusal seat](#a-participants-turn-without-a-current-invite)), then protected paths, then (a `chi scratch` session only)
18
18
  writes to the memories folder (rule `scratch-session`), then (a delegate child only)
19
19
  [the child boundary](#a-delegate-childs-boundary).
20
20
  3. YAML rules: `config.yml`'s `guardrails:` section, then installed bundles' rule files (by bundle name).
@@ -114,6 +114,11 @@ answers it, since it is keyed on the whole command you saw: `git branch -D x &&
114
114
  once, session and repo, while `git merge y && git push` offers once, as `git-merge` offers only once and its rule.
115
115
  Two rules with one id (a config.yml copy of a bundle's rule) are one rule; a core ask followed by a rule's (the
116
116
  [child boundary's](#a-delegate-childs-boundary)) keeps its own scopes.
117
+
118
+ Which stored approvals an ask may use is decided in one place, `Guardrails::ApprovalUse` (before `Gate#settle_ask`
119
+ looks in the store): an owner's ask uses every scope; a [participant's turn](#a-participants-pair-boundary) and a
120
+ [delegate child's boundary](#a-delegate-childs-boundary) use only this session's own `session` entries; a fresh ask
121
+ (`Verdict#fresh_ask`) uses none.
117
122
  The file is a versioned store (`{"version": 1, "approvals": [...]}`, `Approvals::FORMAT`); a write keeps its version,
118
123
  the keys this chi doesn't know and an entry with no `scope`. A bare list of entries, as chi 0.166 and before wrote it,
119
124
  is read and converted to a versioned store on the next write. Chi 0.165 and before set a versioned store aside, so restart their sessions
@@ -305,16 +310,20 @@ sub-agent](sub-agent.md)) tell them to use `chi answer` only.
305
310
 
306
311
  A message that is a session command (`/model x`, `!cmd`, `!rollback`) runs as the command only when a person sends
307
312
  it: a web tab, an attached chi TUI, `chi send` (yours, or one a model runs from `execute`: the trust model above), a
308
- message with no sender named, and `chi answer`'s lines (`cli:answer`: a parent agent's `/continue yes` and
313
+ session's own first prompt, and `chi answer`'s lines (`cli:answer`: a parent agent's `/continue yes` and
309
314
  `/parent-answers`), which may send any session command, with the same trust as `chi send`.
310
315
  `!cmd` runs its shell line with no rule or ask (it is yours), so from anyone else it is refused: a delegating parent's
311
316
  task or follow-up, a schedule's firing (both modes), a plugin's message, a context or task wake. Chi web's Bridge answers
312
317
  `403 command_not_permitted` with one message, an input file's line shows as the command's error, and nothing runs.
313
318
  Their `/word` line is plain text: the model reads it. `delegate`, `schedule_task` and `chi schedule add` refuse a task
314
319
  or prompt that starts with `!` with the same message, so the model can rewrite it. A participant's command is refused
315
- as before ([their review boundary](#a-participants-review-boundary)). The rule is `CommandIntake`
316
- (`lib/samagotchi/command_intake.rb`), asked by `Bridge#handle_post_turn` and `WorkerInbound#queue_as_command`;
317
- `POST /command` (a UI's or a card's explicit command line) is not a message and is not covered.
320
+ as before ([their boundary](#a-participants-pair-boundary)). A message that names no sender (an input file from an
321
+ older chi, a Bridge `POST /turn` without `client_id`) is nobody's: its `/word` line is text, its `!` line refused
322
+ (`ClientId::NONE` is never the owner's). The rule is `CommandIntake` (`lib/samagotchi/command_intake.rb`, on
323
+ `ClientId.owner?`), asked by `Bridge#handle_post_turn`, `WorkerInbound#queue_as_command` and `Bridge#handle_command`
324
+ (`POST /command`, a UI's or a card's explicit command line): that route must name its sender (without `client_id` 400
325
+ `missing_client_id`), and from any other sender (a participant, a delegate, a plugin, an unknown id) it answers 403
326
+ `command_not_permitted` (`CommandIntake::COMMAND_REFUSED`; a `!` line's is `REFUSED`) and runs nothing.
318
327
 
319
328
  ## Protected paths
320
329
 
@@ -373,83 +382,42 @@ under its own `env:` (its `$TMPDIR`, `$HOME`, `GIT_DIR`, …): either one naming
373
382
  redefines the shell (`BASH_ENV`, `BASH_FUNC_cat%%`, `CDPATH`, …, as under `skip_read_only` below) always asks, even
374
383
  for `cat a.txt` in the child's own folder: what it runs is in no word of the command. The answer is once or for the child's
375
384
  session only: a repo or rule answer would hold in every worktree, for every
376
- child, so a stored repo or rule approval doesn't let it through either. Its
385
+ child, so a stored repo or rule approval doesn't let it through either (`ApprovalUse::SESSION_ONLY_RULES`). Its
377
386
  ask goes before the rules, so with the guardrails bundle in strict mode the
378
387
  card still names `child-boundary`. The parent (never a delegate), forks and
379
388
  ordinary sessions don't get it. Like the rules it reads command text: a
380
389
  `sh -c` body, a script or `$(…)` isn't looked into.
381
390
 
382
- ## A participant's review boundary
383
-
384
- Built in, for a [participant's](internals/participants.md#turns) turns in a
385
- **review session** only (a turn whose author is `p:<id>`, in a session with a
386
- `review:` key: `ParticipantMode.of` is `:review`; a working session's
387
- participant turns get the [pair boundary](#a-participants-pair-boundary)
388
- instead), in every mode (also with
389
- `guardrails.enabled: false`) and without the guardrails bundle:
390
- `Guardrails::ReviewBoundary`, rule `review-boundary`, source `core`. It comes
391
- right after the load-failure check (rules that don't load deny every call) and before the hooks' asks, the
392
- protected paths and the rules (`GuardrailWiring#checks`; a deny is sticky, so no later vote turns it into a
393
- question), and it
394
- **denies, never asks**: nobody on the participant's side may approve, and the
395
- owner's approval would give the participant's text the owner's tools. A
396
- participant's turn may call only the `review` kit's tools:
397
-
398
- - `read`, under the session's project root (the work tree top of its folder)
399
- and never a secret: chi's state and config dirs (sessions, the grants, the
400
- web token, memories and their `.bundles`, `config.yml`, hooks, and a
401
- `hooks.hooks_dir` configured outside the config dir), `~/.ssh`,
402
- `~/.gnupg`, `~/.aws`, and the project's `.env*`, `.netrc`, `*.pem`, `*.key`,
403
- `*.p12`, anything named `credentials` (`.git-credentials` too), `.npmrc`,
404
- `.pypirc`, ssh keys (`id_rsa`, `id_ed25519`, …), `*.tfstate`,
405
- `secrets.yml`/`.json`, `.docker/config.json`, `.kube/config` and any config
406
- under `.git` (a submodule's too). The path is checked as given and as it
407
- resolves, so a symlink in the project to `~/.ssh` is `~/.ssh`, and
408
- `node_modules/foo/../../.config/gh/hosts.yml` with `foo` a link to `~/src/foo`
409
- is `~/.config/gh/hosts.yml` ([How paths resolve](#how-paths-resolve)). A session
410
- whose folder is the home folder or above it reads nothing.
411
- - `memory_read` with `scope: project` (a read without a scope would fall back
412
- to the system memories). The prompt's preloaded memories and the memory
413
- index are in the system prompt anyway: a review session should start
414
- without personal ones.
415
-
416
- Everything else is denied with "a participant's review turn may only read …",
417
- and the model is told to propose the change as text or a diff for the owner
418
- to apply: `write`, `edit`, `memory_write`, `execute`, the task tools,
419
- `delegate`, `send_note`, `list_sessions`, `register_reminder` (it would fire
420
- an owner turn later), `web_fetch`, `context_read`, `ask_user_question`,
421
- `forget_outputs` (it would replace the owner's earlier tool outputs with the
422
- participant's note, which later owner turns would read as their own), and
423
- every plugin or MCP tool, including through `call_tool` (a built-in reached
424
- through `call_tool` is checked as that built-in). The session's declared tools
425
- stay its own (no prompt rebuild per author), so the model may still try a
426
- write; the turn's header ("This turn may only read") keeps that rare.
427
-
428
- The kit is `Toolkit::REVIEW`, a frozen built-in: config's `toolkit.kits.review`
429
- is refused with one message ([configuration](configuration.md#toolkits)), so
430
- config can't widen the boundary. Hooks still run on a participant's turn, with
431
- the owner's power ([hooks](hooks.md#participants-turns)); a hook that rewrites a
432
- call is checked on the call it leaves.
391
+ ## A participant's turn without a current invite
392
+
393
+ chi runs no read-only turn: no turn an older chi ran read-only may run with tool rights here. The worker refuses a
394
+ participant's turn whose invite is an older chi's (a grant or `participants.json` entry without `mode: pair`), a Verify
395
+ fresh child saved for a read-only turn, a participant with no invite at all, and a participant's turn in the owner's
396
+ own Verify fresh child (the parent's participants are the parent's), before it starts; one function decides it for the
397
+ worker and the guardrails alike (`ParticipantTurnMode`)
398
+ ([participants](internals/participants.md#turns)). Should such a turn start anyway, its seat in
399
+ `GuardrailWiring#checks` is `Guardrails::ParticipantRefusal` (rule `participant-refused`, source `core`): every call
400
+ is denied, nobody is asked, in every mode and with `guardrails.enabled: false`.
433
401
 
434
402
  ## A participant's pair boundary
435
403
 
436
- A participant's turn in a **working session** acts with the session's tools
437
- under the owner's guardrails, as the owner's own turns do: the rules, the
438
- protected paths and every approval the owner already granted apply, and an ask
439
- goes to the owner. It is a pair turn only when all three hold
440
- (`ParticipantMode.for_turn`, decided once at the turn's start:
441
- `GuardrailWiring#begin_turn`, into the turn's `TurnContext#participant_mode`): the session has no `review:` key, its worker
442
- names the `pair_turns` feature, and the participant's grant was issued with
443
- `mode: pair`, which chi share and the web's Invite stamp only when the warning
444
- they showed said their turns act. A grant from before, or one issued while an
445
- older worker held the session, keeps review turns until it is invited again.
404
+ A participant's turn acts with the session's tools under the owner's
405
+ guardrails, as the owner's own turns do: the rules and the protected paths
406
+ apply, and an ask goes to the owner. Of the owner's stored approvals only this
407
+ session's own ("Allow … for the session") answer its asks
408
+ (`Guardrails::ApprovalUse`): a call the owner allowed in this repo or for a
409
+ rule asks the owner again, on a card.
410
+ Every invite is stamped `mode: pair`; the turn's mode is decided once at its
411
+ start (`ParticipantTurnMode` via `GuardrailWiring#participant_turn_mode`, into the turn's
412
+ `TurnContext#participant_mode`), and it runs only on a worker that names the
413
+ `pair_turns` feature.
446
414
 
447
415
  `Guardrails::PairBoundary` (rule `pair-boundary`, source `core`) sits in the
448
- review boundary's seat in `GuardrailWiring#checks`, in every mode (also with
416
+ participant boundary's seat in `GuardrailWiring#checks`, in every mode (also with
449
417
  `guardrails.enabled: false`), and **denies, never asks**, each with its own
450
418
  message:
451
419
 
452
- - secrets, read or written: the review boundary's denylist (chi's state and
420
+ - secrets, read or written: `ReviewPaths`' denylist (chi's state and
453
421
  config dirs, so `grants.json`, the web token and every `participants.json`;
454
422
  `~/.ssh`, `~/.gnupg`, `~/.aws`, `~/.config/gh`, `~/.config/fish`,
455
423
  `~/.config/git`, `~/Library/LaunchAgents`, `~/.local/bin`; the home's shell
@@ -685,7 +653,7 @@ A command that makes a link asks too, wherever it points (`ln`, `link`, `cp
685
653
  a link the same command makes is judged before the link exists, so `ln -s ..
686
654
  up && cat up/…` can't be read for what it reaches.
687
655
  A session whose folder is the home folder or above it has no project to
688
- keep the turn in (`ReviewPaths.home_root?`, the review boundary's test): every
656
+ keep the turn in (`ReviewPaths.home_root?`): every
689
657
  write there asks.
690
658
 
691
659
  A participant's ask names them on the owner's card ("Sam's turn asks: approve
@@ -699,7 +667,7 @@ cap or their link was revoked or expired
699
667
 
700
668
  The trust model is a team's (everyone invited is trusted): the boundary is an
701
669
  **accident guard** for secrets and the owner's voice, not containment of a
702
- hostile participant; a review session is. A pair turn can still reach, through
670
+ hostile participant. A participant's turn can still reach, through
703
671
  the owner's rules: `web_fetch` (an open egress path: what the turn can read it
704
672
  can send out in a URL), plugin and MCP tools, `memory_read` and `context_read`,
705
673
  `list_sessions` (the owner's other sessions' titles), chi web by a name the
@@ -716,17 +684,16 @@ delegate child chi web starts for an unclear verdict) runs a participant's
716
684
  check under **the boundary that participant has in the parent**. A verdict a
717
685
  participant recorded is always checked again as them, even when the owner
718
686
  clicks (the claim is their text; their link must still be live), so it never
719
- runs with the owner's rules or System 1's auto-allows. The mode is decided once,
720
- at the start, from their grant's mode there (`ParticipantMode.live_for`) and
721
- saved on the child (`verify_fresh.mode`): `review` keeps every turn of it
722
- inside `ReviewBoundary` (read only), `pair` inside `PairBoundary`.
687
+ runs with the owner's rules or System 1's auto-allows. The mode is saved on the
688
+ child at its start (`verify_fresh.mode`: `pair`, every live grant's); a child an
689
+ older chi saved `review` is refused, never run.
723
690
  `GuardrailWiring#begin_turn` reads the saved mode and never looks it up again,
724
691
  and every turn of the child carries the participant as its author, whoever
725
692
  started it, so the boundary can't fall away for a turn the owner typed into it
726
693
  or for an author lookup that finds nobody (the child has no
727
694
  `participants.json`; revoke and cap read the parent's). It fails closed: a
728
- `verify_fresh` field that doesn't read is a participant nobody has, under
729
- review, whose turns are refused. `ChildBoundary` applies on top, as for every
695
+ `verify_fresh` field that doesn't read is a participant nobody has, whose turns
696
+ are refused. `ChildBoundary` applies on top, as for every
730
697
  delegate child, and its asks go to the owner (once only, as a participant's
731
698
  do; System 1 skips them). The owner's own fresh child is an ordinary delegate
732
699
  child: the owner's turns, `ChildBoundary`.
@@ -931,7 +898,7 @@ name too) is always outside, in the repo or a tmp folder alike
931
898
  #### How paths resolve
932
899
 
933
900
  Every path check (protected paths, `outside_repo`, `touches`, `rm`, `memory:
934
- prompt`, the child, review and pair boundaries, System 1's own-files test)
901
+ prompt`, the child and pair boundaries, System 1's own-files test)
935
902
  resolves paths with `Guardrails::PathResolve` (the map below):
936
903
 
937
904
  - `..` is taken the kernel's way (`.expand`): after a symlinked folder it
@@ -1168,7 +1135,7 @@ user's **earlier asks they answered** (`SystemOne::Similar`) — this rule in
1168
1135
  this repository first, then this rule anywhere, then any answered ask, ranked
1169
1136
  by how many words the logged call shares with this one, ties going to the
1170
1137
  newest. Reading the log is best-effort, so a log that cannot be read simply
1171
- offers no examples. A participant's turn (review or pair) is never judged:
1138
+ offers no examples. A participant's turn is never judged:
1172
1139
  there is no user there to ask, and its asks go to the owner. The judgment runs before the card appears, so an ask is
1173
1140
  slower by up to `timeout_ms` (2000 ms by default).
1174
1141
 
@@ -1494,7 +1461,7 @@ else goes to chi's own rules. It needs nah installed; see its README for the set
1494
1461
 
1495
1462
  ## Participants' text in later turns
1496
1463
 
1497
- A participant's message (a review contribution, see
1464
+ A participant's message (see
1498
1465
  [internals/participants.md](internals/participants.md#attribution)) stays in
1499
1466
  the history, so later **owner** turns read it. chi marks it: the wire header
1500
1467
  above it says it is a participant's and not the owner's instruction, and the
@@ -1502,21 +1469,15 @@ system prompt says the same while the session has participants. Owner turns
1502
1469
  keep every guardrail. But an owner turn that says "do what Alex said" hands
1503
1470
  Alex's text the owner's tools: the model will act on it as the owner asked.
1504
1471
  That is the residual risk, documented rather than engineered away: on a
1505
- session with sensitive tools, quote the proposal you want applied in your own
1506
- turn instead: the web's **Apply** under a review turn does that (it puts your
1507
- line and the reply quoted line by line in your composer, for you to read and
1508
- send; [internals/participants.md](internals/participants.md#apply)). A quote
1509
- lowers the risk, it doesn't remove it: your line still asks the model to act
1510
- on what it quotes, with your tools, so read the quote before you send it.
1511
-
1512
- Within its own turn in a review session a participant's text can't act: the
1513
- review boundary leaves it reads of the project only, and an injection that
1514
- convinces the model still meets the boundary (containment over detection). In
1515
- a working session it acts, by design ([the pair boundary](#a-participants-pair-boundary)):
1516
- invite only people you would let type in your session, under your guardrails. What it can do
1517
- is make the model *say* what the history holds: a review turn's model sees the
1518
- whole conversation, earlier tool outputs included, so start a review in a
1519
- fresh session (or a continue), not on a working session full of outputs. A
1472
+ session with sensitive tools, quote what you want done in your own turn
1473
+ instead. A quote lowers the risk, it doesn't remove it: your line still asks
1474
+ the model to act on what it quotes, with your tools, so read it before you send
1475
+ it.
1476
+
1477
+ Within its own turn a participant's text acts, by design ([the pair boundary](#a-participants-pair-boundary)):
1478
+ invite only people you would let type in your session, under your guardrails. It can also make the model *say*
1479
+ what the history holds: a participant's turn sees the whole conversation, earlier tool outputs included, so invite
1480
+ them to a fresh session (or a continue) when the history holds what they shouldn't read. A
1520
1481
  line of a participant's text that looks like one of chi's own headers goes
1521
1482
  out quoted (`(quoted) [Steer from the user, …]`), under the real one, in any
1522
1483
  case and after any spaces (chi's context-note and task frames too). The owner's
data/docs/hooks.md CHANGED
@@ -76,13 +76,12 @@ cheap).
76
76
 
77
77
  ## Participants' turns
78
78
 
79
- A [participant's](internals/participants.md#turns) turn — a review turn or a pair turn — fires the same hooks, and
79
+ A [participant's](internals/participants.md#turns) turn fires the same hooks, and
80
80
  every event of it carries `author: "p:<id>"` (the owner's carry no `author:` key, as before); a plugin reads the
81
- same as `ctx.turn_author` (nil for the owner's turns and between turns). The mode does not change that: `author:`
82
- comes from who wrote the turn, not from `ParticipantMode`. **A hook runs with the owner's power whatever the
81
+ same as `ctx.turn_author` (nil for the owner's turns and between turns). `author:` comes from who wrote the turn. **A hook runs with the owner's power whatever the
83
82
  author**: it may read, write and run what the owner's chi may, and `notify`, `ask_user` and `steer` reach the
84
83
  owner. A bundle that acts on a turn's text (a prompt rewrite, a fetch of what it names) should check `author:`
85
- first: the text may be a participant's. The participant's boundary (the review or pair one) checks a tool call
84
+ first: the text may be a participant's. The participant's boundary (the pair one) checks a tool call
86
85
  after the hooks, on the call they leave.
87
86
 
88
87
  ## What a hook can do: the runtime
@@ -125,8 +125,7 @@ name (or whose hint is its URL) is attached, *declined* while the declined marke
125
125
 
126
126
  - **Mention.** `mention_in` / `pattern_for` implement the user-facing rules (whole tokens, `#N` ≥ 10 or after
127
127
  "PR", branch names ≥ 6 chars with `/ - _`, exact URLs, fenced code blanked). Only `OwnerPrompt` texts count
128
- (`owner_texts`), so a participant's message, a steer, a note or a reminder never attaches anything; a review
129
- session skips all of it.
128
+ (`owner_texts`), so a participant's message, a steer, a note or a reminder never attaches anything.
130
129
  - **Where it runs.** `before_turn` (from `Worker#run_prompt` before the absorb, and a `--non-interactive` one-shot's turn start, `TerminalUI`): attach
131
130
  each proposed candidate the owner's prompts so far mention (`attach` writes a session `Source` through
132
131
  `source_for`: a URL resolves through `ContextProviders`, else the candidate's own `cmd`), then `first_fetch` them
@@ -148,9 +147,9 @@ nothing, so the next owner prompt asks again.
148
147
 
149
148
  The driver is the turn stage `TurnStages::ContextJudge` (`turn_stages/context_judge.rb`), not the judge:
150
149
  `Engine#prepare_turn` calls its `start(turn, recorder:)` after the toolkit suggestion settled and before `apply_toolkit!` (an owner
151
- turn's start; skipped for participants, review sessions and a Continue), and `Engine#judge_late_candidates` (a proposal
150
+ turn's start; skipped for participants and a Continue), and `Engine#judge_late_candidates` (a proposal
152
151
  after the prompts) gives its `late_candidates` the session, the owner's messages, the recorder and the sessions dir
153
- (none of it read with no session or in a review session); both make one pass (docs/internals/engine.md, "Turn stages").
152
+ (none of it read with no session); both make one pass (docs/internals/engine.md, "Turn stages").
154
153
  It first logs status changes (`ContextCandidatesLog.look`), returns at `mode: off`, builds the due `Job`s, and hands
155
154
  them to `SideJudgments` (`:context` kind: one thread, one batch per session at a time), asked at once on any host,
156
155
  the model's own server too.
@@ -161,7 +160,7 @@ session source with `JUDGE_WHY`, no probability in the model-visible why), *offe
161
160
  is still proposed, since the user may have chosen while it was asked. Cards are shown through the stage's choice
162
161
  lambda, which holds them while a turn runs; `run_turn`'s ensure shows them after `release_turn`
163
162
  (`show_cards_after_turn`). `choose` is the `/context attach|decline` command's body (`SessionCommands`), shared by the
164
- card's buttons; it refuses in a review session. An attach only writes the session folder: its note comes with the next between-turn delivery, never into a
163
+ card's buttons. An attach only writes the session folder: its note comes with the next between-turn delivery, never into a
165
164
  running turn.
166
165
 
167
166
  `ContextCandidatesLog` is `context_candidates.jsonl` beside the sessions folder (a `SideJudgments.log`: 0600, one
@@ -209,8 +208,8 @@ The refusal side: a push into a session that has been continued is refused with
209
208
  |---|---|
210
209
  | Absorb at all | the conversation has started (`conversation_started?`), or `before_turn: true`; the session isn't stopped on disk |
211
210
  | A wake turn | `context.wake`; `WorkerWakes#context_open?`; `CONTEXT_WAKE_WINDOW`; nothing queued and no exit requested; peer: `context.peer_turns`, `peer_open?` |
212
- | Mention attach | `OwnerPrompt.turn?` (owner author, not a review session) |
213
- | Judge | `context.candidates.mode` `audit`/`on` (default `off`); a System 1 client configured; not a participant's turn, review session, scratch session or Continue |
211
+ | Mention attach | `OwnerPrompt.turn?` (owner author) |
212
+ | Judge | `context.candidates.mode` `audit`/`on` (default `off`); a System 1 client configured; not a participant's turn, scratch session or Continue |
214
213
  | Command source defined by the agent | `chi-context-cmd` guardrails rule asks, always; a parent agent can't approve it for a child |
215
214
  | Writes to the store | `ProtectedPaths` denies the file tools |
216
215
 
@@ -18,12 +18,13 @@ Recommended workflow:
18
18
  Behavior:
19
19
 
20
20
  - `execute`, `task_create` and the `!cmd` shell bang run the command in a non-login shell: `/bin/sh -c` on Linux; on macOS, when `/bin/zsh` is there, `/bin/zsh --emulate sh +o ignore_braces +o sh_glob -o bash_rematch +o bsd_echo -c` (macOS's `/bin/sh` is bash 3.2, which can't parse an apostrophe in a heredoc inside `"$( )"`, the usual commit message shape). That mode reads no rc files and keeps POSIX word splitting, unmatched globs left as is, `{1..3}`, `[[ … =~ (…) ]]` with `BASH_REMATCH`, arrays, `$'…'`, `&>` and echo expanding `\t`. Bash-only builtins and variables (`shopt`, `BASH_VERSION`, `${!prefix*}`, `read -p`) are not there.
21
- - Task metadata and output are persisted under `tmp/tasks/`: each task's `tmp/tasks/<id>/task.json` is a `TaskRecord` (`lib/samagotchi/tools/task_record.rb`, a value object: `.from_file` reads it, `#to_file` is the JSON object written, an update is a `#with`). Its keys keep their order; `stderr_path` and `handed_over_by` (a handed-over execute) and `stop_requested_by` (a stop under way or done) are left out until set. `bundles/slow-commands` reads these files on its own, so the shape is a contract.
21
+ - Task metadata and output are persisted under `tmp/tasks/`: each task's `tmp/tasks/<id>/task.json` is a `TaskRecord` (`lib/samagotchi/tools/task_record.rb`, a value object: `.from_file` reads it, `#to_file` is the JSON object written, an update is a `#with`). Its keys keep their order; `stderr_path` and `handed_over_by` (a handed-over execute), `stop_requested_by` (a stop under way or done) and `leftovers` (`stopped` or `detached`: what the shell left holding the log, below) are left out until set. `bundles/slow-commands` reads these files on its own, so the shape is a contract.
22
22
  - A task record keeps its process's pid and start time (`pid_started`). Before `task_stop` signals, the pid must still lead its own process group and must not have started at another time; otherwise the pid was reused by another process, nothing is signalled and the task ends as failed. A start time that can't be read at that moment (a failed `ps`) falls back to the group check, as does a record without `pid_started` (from an older chi). `task_get`, `task_list`, `task_wait`'s polls and the running-task lists (a cancelled turn's note, a worker's restart hold, the finish wake's watch) make the same check, so a task whose pid was reused reads as exited (failed) at once, not as running until a `task_stop`; on macOS that is one `ps` per running task per check (~5 ms).
23
- - A stop (`task_stop`, the user's Stop of an `execute`, the execute limit in kill mode) TERMs the task's process group, then KILLs it after a grace. The groups its processes started are stopped too: a GNU `timeout N cmd` (without `--foreground`) moves itself and its command to a group of its own. `ProcessGroup.stop` finds them with one `ps -A -o pid=,ppid=,pgid=` (~40 ms on macOS) before the TERM and again before the KILL, walking down from the group's members. A process whose parent already exited (reparented to init, e.g. a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` after its shell exited) is not found and runs on.
23
+ - A stop (`task_stop`, the user's Stop of an `execute`, the execute limit in kill mode) TERMs the task's process group, then KILLs it after a grace. The groups its processes started are stopped too: a GNU `timeout N cmd` (without `--foreground`) moves itself and its command to a group of its own. `ProcessGroup.stop` finds them with one `ps -A -o pid=,ppid=,pgid=` (~40 ms on macOS) before the TERM and again before the KILL, walking down from the group's members. A process whose parent already exited (reparented to init, e.g. a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` after its shell exited) is not found by that walk; one still in the task's group is stopped by the leftover rule below, so only one outside the group runs on: a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` (GNU `timeout` moves to a group of its own). Holding the task's log, it is reported detached.
24
24
  - Task listing is workspace-scoped (current project only).
25
- - `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped; one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
25
+ - `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped (the result's hint says to start a long job with `task_create` in the foreground, no `&`: a `cmd &` left behind there is stopped too); one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
26
26
  - The exit code: the command runs after an EXIT trap that writes the shell's status to the `exit_code` file (`TaskRuntime.wrapped_shell_command`, shared with `task_create`), so `exit N`, a `set -e` failure and a trailing `\` or `|` in the command all record what the shell exited with. The trap runs wherever the shell is when it exits (a `task_create` `cwd`, or a `cd` in the command), so `task_create`'s `exit_code_path` is absolute; its `output_path` stays relative (`tmp/tasks/<id>/output.log`, opened by chi in the worker's cwd before the spawn). A command that sets its own EXIT trap replaces it, and a shell killed by a signal skips it (zsh's sh mode, on TERM, INT and KILL): `execute` still reports the shell's status, and a `task_create` task or a handed-over execute gets its code from chi's waiter while the chi that started it runs (`TaskRuntime.record_exit_status`): the exit status, or `128 + the signal` (TERM → 143), with no new `stop_reason`. A record a refresh already finished without a code in between (`failed`, `process_ended_without_exit_code` or the not-chi's-process reason) is corrected, its `finished_at` kept; a stopped task (its stop flag on disk) is never touched. `process_ended_without_exit_code` is left only when the shell wrote nothing and the chi that started it was gone too.
27
+ - `task_create` applies `execute`'s leftover rule (`Tools::Leftovers`, one implementation: `held?`, the grace, the group stop, the hint wording): `create_task` holds `output.log` with a shared `flock` across the spawn, and a handed-over execute's two logs are already held. When the task's shell exits and a process it started still holds the log (`yes >/dev/null &` with no `wait`), the task stays `running` (so the finish wake's watch and `task_wait` keep waiting) while the waiter of the chi that started it (`TaskRuntime.record_exit_status`) gives it 1.5 s (`LEFTOVER_GRACE_SEC`), then stops the group (TERM, 1 s, KILL; `Leftovers.stop_group`, only while the group still has members: a pgid isn't reused while it has any) and finishes the record in one write: the shell's status and exit code (the leftovers don't make it a failure) and `leftovers: "stopped"`. A holder outside the group with the group empty (a setsid'd `cmd &`, or a backgrounded `timeout N cmd &`: GNU `timeout` without `--foreground` moves itself and its command to a group of its own) is signalled nothing: `leftovers: "detached"`, left running, and the hint says so (`task_stop` can't reach it: kill it if it shouldn't run). A process holding no log (`nohup cmd >f 2>&1 &`) is left alone. `task_get`, `task_wait` (so the finish note too) and `task_list` add the hint line (`Leftovers.task_hint`), ``(a background process kept the task's log open and was stopped; to keep one running, run it in the foreground or end the command with `wait`)`` (or `was left running`), built from the same `Leftovers.hint` as execute's. One settler per task: while that waiter thread lives (`TaskRuntime.waiter_for`, in memory, this process only), a refresh here only reads a held record. With no waiter here (the chi that started it is gone, a worker that exited mid-grace, or another process reading), the next refresh that finds the shell dead and the log held settles it itself: a second look after 0.05 s (two `held?` probes at once read each other as holders), then the stop with a 0.5 s TERM grace and 0.5 s KILL wait (only of a group that still had members at the first look; one gone by the stop with nothing holding the log records no `leftovers`), so that read blocks up to ~1 s plus a `ps`. With no later reader of that cwd's tasks the leftovers run on; records already finished (an older chi's) are never revisited, and an older chi's record (its log never `flock`'d) reads as not held and settles as before. A `task_stop` during the grace stops the group (`Leftovers.stop_group`) and the record ends `stopped` (its stop flag wins over the waiter's write; in one process the two writes share a lock). Cost: one non-blocking `flock` try per log at shell exit (~0.2 ms), the grace only when something holds the log; a refresh of a running record whose shell is dead adds one `flock` try, and one `ps` only when the log is held.
27
28
  - A stop of an `execute` (the user's Stop, the limit in kill mode) is done once the shell is reaped and nothing holds the logs: a child that ignores TERM after its shell died gets the KILL.
28
29
  - A command still running at `execute.timeout_sec` is handed over as a task (`execute.on_timeout: task`, the default; `kill` stops it instead, and the `!cmd` bang always kills): the result starts `Still running at the 120s limit: moved to a background task, not killed.`, then `task_id: …` and the tails of both logs so far. A command is also handed over early when a person's message waits for the turn's next step (the `message_waiting:` probe, the same `Engine#input_waiting?` as `task_wait`'s): after `Execute::EARLY_HAND_OVER_FLOOR_SEC` (3 s: a short command ends first and its result is the better answer), in the next 0.2 s slice. The first line then reads `Still running at the 4s mark: a message from the user is waiting, so the command moved to a background task, not killed.` (the seconds it had run), and the line after `task_id:` starts `Read the message first.`; the rest is the same hand-over, and the task stays watched. Never in `kill` mode (`execute.on_timeout: kill`, a participant's pair turn, the `!cmd` bang): there the probe is not even read and the command runs to its limit and is killed. A command that can't be adopted at that moment (a record that can't be written) isn't killed early: it runs on to its limit. Everything that matches the first line builds on `Execute::HANDED_OVER` (`Still running at the`) and `Execute::HANDED_OVER_AFTER` (`120s limit:` or `4s mark:`): `TaskRuntime.handed_over_pattern`, `ToolActivity::HANDED_OVER_START`, `TaskWatch` (`limit_sec` for the limit's form, `early_sec` for the mark's, which the finish note words as `handed over by execute after 4s: a message from the user was waiting`) and the web's `task_stop.js`; the slow-commands bundle reads only the limit's form, which is the only one that is a timeout. A timeout during the 1.5 s background grace is a kill (the shell is gone, nothing to hand over). If the record can't be written, the command is killed. `TaskRuntime.adopt` writes a record for the process execute already started, with `handed_over_by: "execute"`. Its logs stay where execute wrote them, so the record's paths are absolute: `output_path` (stdout), `stderr_path` (stderr, a log of its own) and `exit_code_path` (a `task_create` record's `exit_code_path` is absolute too; its `output_path` is relative). `started_at` (and `created_at`) is the spawn time, not the hand-over's; `pid_started` is read at the hand-over, while execute's detach waiter is still running. From there it is an ordinary task: `task_wait`, `task_get`, `task_list` and `task_stop` treat it as any other. Its dir gets a `task` back-pointer file holding the record's absolute path. Once per process, the first `execute` sweeps `…/execute/`: a dir whose logs no process holds is removed when it has no back-pointer and is a day old (chi died mid-command), when its record is gone, or when it is 14 days old. The records live in each project's `tmp/tasks`, which the state dir can't list: hence the back-pointer.
29
30
  - `task_wait` and `task_get` show `stderr_path` when the record has one; `task_wait`'s output tail is followed by a `stderr_tail:` of at most 10 lines when that log isn't empty. A `task_create` task has one log (stdout and stderr together) and no `stderr_path`. A `task_wait` result longer than `max_tool_output_chars` keeps its header and the tail's end, with a gap line naming `output_path`, where the whole log already is (and `stderr_path`, when the record has one) (`ToolOutputCut`'s `:head_tail_ref`; nothing is copied; see [Tool output guardrails](tool-output-limits.md#the-runners-cut-max_tool_output_chars)).
@@ -18,8 +18,8 @@ model. The TUI is untouched: it shows a fence as source.
18
18
  made), then `Provenance#script_failure` (the check a context provider's scripts get too); a file with no recorded sha, a missing one or a changed one is 409
19
19
  `renderer_changed`, each with its own reason. ETag + `no-cache`, as static files. A `block_renderers:` list that
20
20
  doesn't parse is logged once per bundle and problem (each list request and file fetch reads it).
21
- 3. `block_watch.js` (`createBlockWatch`, made by `block_host.js`'s `createBlockHost`, wired in `app.js`; `participant.js`
22
- isn't) finds and watches the blocks; `block_host.js` is its frame drawer (`createFrameDrawer`). The watcher asks an
21
+ 3. `block_watch.js` (`createBlockWatch`, made by `block_host.js`'s `createBlockHost`, wired in `app.js`; a participant's page
22
+ gets the core drawers only, no bundle's renderers: `block_renderers`) finds and watches the blocks; `block_host.js` is its frame drawer (`createFrameDrawer`). The watcher asks an
23
23
  ordered list of drawers, core ones first (`inline_widgets.js` for `chi-ui`: [inline-widgets.md](inline-widgets.md)), then the frame drawer, which waits for `/api/block_renderers`;
24
24
  the first that `claims` the block's language draws it, and a language none claims is left alone. The contract
25
25
  (`claims`, `needsDraw`, `draw`, its `reconsider`, `sessionChanged`) is in the module's header. The shared DOM
@@ -57,8 +57,10 @@ Three other users: `replay_events(turn)` turns a `current_turn` back into the li
57
57
  `command_queued` per waiting command), which chi web's `GET /api/sessions/:id` sends as `replay` from the worker's
58
58
  snapshot (`from_wire` symbolizes it), so any worker's snapshot gives the page the same events
59
59
  (`spec/shared/turn_snapshot.json` pins it); `messages_of` gives a
60
- plugin's `ctx.messages` the turn so far (`Engine#running_turn_messages`); `participant_turn?` tells `POST /turn` that
61
- a participant's review turn runs, so the owner's input queues behind it.
60
+ plugin's `ctx.messages` the turn so far (`Engine#running_turn_messages`); `participant_author` (and
61
+ `participant_turn?`) tell `POST /turn` whose turn runs: input goes into it only from its own author
62
+ (`Bridge#same_author_steer?`), so the owner's input queues behind a participant's turn, and a participant's goes in at
63
+ the next step of their own turn only.
62
64
 
63
65
  ## TurnDrawings
64
66
 
@@ -155,7 +157,7 @@ no line for (an older worker's, one from before drawings, a dropped one) gets on
155
157
  is memoized per range (`Synth.memoized`), so a show after a turn end makes no old turn again. What each step did
156
158
  as message parts (`MessageParts`, `parts: true`) is the participant review's only (`ParticipantReview`, frozen on
157
159
  its message model).
158
- - **Compat.** An older worker writes nothing, a continue (a note, no turns) and a review fork copy no drawings, and
160
+ - **Compat.** An older worker writes nothing, a continue (a note, no turns) copies no drawings, and
159
161
  an older chi's fork or one-shot wrote none: their turns are made from their messages. A `/btw keep` child forked
160
162
  before its first turn (saved without its system head) draws its turns made from its messages, without CardStore
161
163
  rows, until that turn puts the head back and its carried lines hold (`Synth::LOSSES` `fork_before_first_turn`;
@@ -442,8 +444,11 @@ The Bridge exposes:
442
444
  (memory only) holds for that relay (`child_id`, `child_question_id`, `state`, `answer`, `by`);
443
445
  `404` for an unknown id. A POST with a body because routes match exact paths.
444
446
  - `POST /session/:id/command` — a session command (`/model`, `/models`, `!rollback`, `!cmd`,
445
- `/continue`) for the worker loop; `202` with a `command_id` its `:command_ran` names, `400` when
446
- the line isn't one. A `:command_ran`'s `output` is the command's, up to `Worker::COMMAND_OUTPUT_LIMIT` (64 KiB of chars; past it
447
+ `/continue`) for the worker loop (`{line, client_id, card?, deadline?}`); `202` with a `command_id` its
448
+ `:command_ran` names, `400` when the line isn't one. `client_id` is required: without one (or a blank one) `400
449
+ missing_client_id` (`Bridge::UNNAMED_COMMAND`); from a sender that may not send commands (`CommandIntake.allowed?`:
450
+ only the owner's senders, `web:`, `tui:`, `cli:send`, and chi answer's `cli:answer`) `403 command_not_permitted`, its
451
+ detail `CommandIntake::COMMAND_REFUSED` (`CommandIntake::REFUSED` for a `!` line), nothing queued. A `:command_ran`'s `output` is the command's, up to `Worker::COMMAND_OUTPUT_LIMIT` (64 KiB of chars; past it
447
452
  the text ends with a `[cut: N of M chars: …]` line, which the UIs print as they print the rest). It carries `thinking`, `reasoning_history` and `llm_context`
448
453
  (the summaries the next turn runs under) when the command changed them or the model, and
449
454
  `confirm: {line, text}` when a `/thinking` or `/reasoning-history` change from a `web:` or `tui:`
@@ -613,13 +618,35 @@ the Live's client or nil; `WorkerLink.await` polls for a new worker's Live (an `
613
618
  successor from the old worker); chi web's `App#worker_link` / `#await_worker_link` wrap them. The Bridge writes
614
619
  `pid` and `protocol` with its port and removes its sidecar on stop only when the file still carries its epoch.
615
620
 
621
+ The sidecar's `features` array is the worker's capability handshake: clients check a name rather than infer
622
+ compatibility from its version. `Bridge::FEATURES` advertises:
623
+
624
+ | Feature | What a client gains |
625
+ |---|---|
626
+ | `restart` | `POST /session/:id/exit` can hand the session to a worker running the newest chi (`chi sessions restart`). |
627
+ | `task_stop` | The web can stop a running background task with `POST /session/:id/tasks/stop`. |
628
+ | `reparent` | A continued chain can move a live delegate worker with its parent. |
629
+ | `delivery` | The worker understands all delivery modes, including queueing a turn until the current turn ends. |
630
+ | `turn_ids` | A client can wait for a particular enqueued turn across running, continued and stopped turns. |
631
+ | `verify` | The worker accepts and validates Verify anchors on turns. |
632
+ | `revise` | The worker accepts and validates Revise anchors on turns. |
633
+ | `unqueue` | A client can take back a queued turn before it starts (`POST /session/:id/turn/dequeue`). |
634
+ | `review_turns` | An older chi web checks this before sending legacy participant turns; it is not a read-only mode on current workers. |
635
+ | `pair_turns` | The worker runs participant turns under the owner's guardrails, so chi web may invite participants. |
636
+ | `turn_drawings` | chi web can render completed turns from their saved drawings instead of reconstructing them. |
637
+ | `activity` | `GET /activity` tells `chi schedule tick` what the live worker is doing. |
638
+ | `objectives_track` | chi web can show the worker's progress tracking for active objectives. |
639
+ | `participant_steer` | A participant's message during their own turn can go in at its next step. |
640
+ | `cancel_turn_id` | `POST /session/:id/cancel` can stop only the named turn. |
641
+ | `participant_revise` | chi web can pass a participant's Revise draft for worker-side validation. |
642
+ | `participant_client_id` | chi web can identify a participant as `participant:<id>` instead of using the legacy `review:<id>`. |
643
+
616
644
  `chi web`'s `GET /api/sessions/:id/stream` proxies this bridge
617
645
  (503 `not_live` for no worker, a leaving or stuck worker, or an unreachable Bridge; 502 `worker_newer` for skew and
618
646
  `bridge_error` / `bridge_secret` for a refused Bridge; 200 only after the Bridge answers; full history of any session
619
647
  is served by `GET /api/sessions/:id/output`). It opens the Bridge before answering and gives the one opened socket to
620
648
  `App#proxy_stream_body` / `ProxyStreamBody`, which closes it when the body or hijacked client ends. The owner's stream
621
- is a byte pipe; the body gives it the request's frame filter (`App#stream_filter`: nil for the owner; for a participant, and the owner's participant view
622
- `?as=participant`, a `Web::ParticipantStreamFilter`, which cuts the Bridge's chunks into frames and writes each again
649
+ is a byte pipe; the body gives it the request's frame filter (`App#stream_filter`: nil for the owner; for a participant, a `Web::ParticipantStreamFilter`, which cuts the Bridge's chunks into frames and writes each again
623
650
  from `Web::ParticipantView.event`'s allowlist, dropping every other event; only `from_seq` and `snapshot` reach the
624
651
  Bridge; [internals/participants.md](participants.md#what-a-participant-sees)). Resume/ring-buffer state is **in-memory**, per worker: a cursor from
625
652
  an earlier worker gets the `reset` snapshot, not a replay.
@@ -24,7 +24,10 @@ next turn's estimate before its first count uses it instead of
24
24
  Emission behavior:
25
25
 
26
26
  - The estimate is emitted on every request (both loops, before each request),
27
- so the web and the attached TUI get a fresh number each time.
27
+ so the web and the attached TUI get a fresh number each time; the Engine also
28
+ keeps the last one it saw (`@last_context_status`, from the stream handler),
29
+ so a page or TUI that joins while a turn runs reads it from
30
+ `session_state_snapshot` at once instead of waiting for the turn to end.
28
31
  - The model's own `[CONTEXT: …]` line is still gated: it is left only on a rise
29
32
  into a guidance bucket (from the second threshold up), never on a fall, and
30
33
  not again for a bucket a resumed session's line already names.
@@ -54,6 +57,15 @@ plain `Context window unknown` after it, and for a session whose window lookup f
54
57
  session's first counted turn. A
55
58
  hook's switch (`before_turn`) sends nothing: its turn's first request counts on the new model anyway.
56
59
 
60
+ The owner's show (`Web::SessionShow#shown_session_json`) passes the snapshot's
61
+ `context_status` to the page as `session.context_status`, which
62
+ `session_state.js#sessionStateFrom` reads as the ctx percent before any stream
63
+ event (it wins over the saved fill). With a window known and no percent yet,
64
+ `ctxBarTip` says `No context count yet: the next request counts it`; while the
65
+ session's turn runs (`window.running`, the info bar's own flag) the tooltip's
66
+ title is `Context in use (this turn so far)` rather than `Context used after
67
+ the last turn`.
68
+
57
69
  A process that loads the session on another model than its last turn ran on (`Engine#session=`:
58
70
  `SessionMetrics#last_model_ref` differs from `effective_model_ref`; a `--resume`'d one-shot with `--model`, a worker woken
59
71
  after a `/model` with no turn since) drops the old window (`forget_model_reports!`) and calls
@@ -84,7 +84,7 @@ hook's model switch names the new model and `incoming` the old one. Building one
84
84
  | Stage | Built with | Called with | Called | State |
85
85
  |---|---|---|---|---|
86
86
  | `TurnStages::ToolkitSuggestion` (ToolkitSuggest's ask; configuration.md (Toolkits), guardrails.md (System 1)) | side judgments, host registry, toolkit binding, tools | `start(turn, recorder:)`; `settle`, `abandon(turn, why)`, `finish` (the turn); `warm!(session)` | `start` before `refresh_profile!`; `settle` after `apply_staged_tools!` (on mode: waits up to System 1's timeout or a Stop, which wins over an answer already in; a pick ≥ threshold → `ToolkitBinding#suggest`); `abandon` at STOP CHECK A and in the ensure, then `finish`; `warm!` / `stop_warmup` (Worker start, `shutdown`) | the turn's `ToolkitSuggest::Pending` (turn thread only; another turn's is never touched; dropped at `finish`), the warm-up thread |
87
- | `TurnStages::ContextJudge` ([attached-context.md](attached-context.md), [context.md](../context.md) "The judge") | side judgments, host registry, `TurnState`, `show_card:`, `current_session:` | `start(turn, recorder:)`; `late_candidates(session, messages:, recorder:, state_dir:)`; `show_cards_after_turn` | `start` after `settle`, before `apply_toolkit!` (owner turns only); `late_candidates` from `judge_late_candidates` (which returns on no session or a review session first, before reading anything else); `show_cards_after_turn` after `release_turn` | the cards an answer brought while a turn ran, under their mutex |
87
+ | `TurnStages::ContextJudge` ([attached-context.md](attached-context.md), [context.md](../context.md) "The judge") | side judgments, host registry, `TurnState`, `show_card:`, `current_session:` | `start(turn, recorder:)`; `late_candidates(session, messages:, recorder:, state_dir:)`; `show_cards_after_turn` | `start` after `settle`, before `apply_toolkit!` (owner turns only); `late_candidates` from `judge_late_candidates` (which returns on no session first, before reading anything else); `show_cards_after_turn` after `release_turn` | the cards an answer brought while a turn ran, under their mutex |
88
88
  | `TurnStages::Objectives` ([objectives.md](objectives.md)) | side judgments, host registry | `incoming(turn, recorder:)`, `outgoing(turn, result, recorder:)`, `note(session, note, recorder:, state_dir:)`, `announce(session, state_dir:, running:)` → the event or nil, `propose(proposal)`, `finally(turn)` → the cards, `track(turn, engine:)` → the tracker's thread or nil, `cancel_track` | `cancel_track` first thing in `begin_turn` (any turn, a wake's too); `incoming` after the judge's `start` (owner and human prompts only); `announce` from `announce_objectives` (inside `end_turn`'s step, and between turns from any thread); `outgoing` in `complete_turn` before `:after_turn`, `track` right after it (`Engine#track_objectives_after`); `note` in `add_context_note`; `propose`; `finally` from `show_objective_proposals` in the ensure | the turn's proposals under their mutex (drained at `finally`), the last view announced (touched only under the event lock), the tracker's automatic read's cancel under its own mutex; the `ObjectivesAudit` is built per call |
89
89
  | `TurnStages::Warmup` (PromptWarmup) | `PromptWarmup`, kernel, `TurnState`, model settings, reminder queue, `system_prompt` | `after(turn, result, next_turn_waiting:)` | after `complete_turn` (reads `turn.context.settings`) | none (PromptWarmup keeps its pin and thread) |
90
90
  | `TurnStages::VerifyAnchors` | nothing | `verified(session, anchor, state_dir:)`; `stamp_opening`, `record_verdict` | `verified` in `begin_turn` (before any `TurnContext`); `stamp_opening`, `record_verdict` inside `end_turn`'s step | none |
@@ -533,23 +533,35 @@ Where a participant's author (`"p:<id>"`; `Steer.participant_author?`) goes (the
533
533
  grouped by sender and author so a participant's lines never share the owner's message (`Steer::Line#author`).
534
534
  Assistant and tool messages carry none: `Steer.author_at(messages, index)` resolves by position. `ChatLoop#plain`
535
535
  keeps the keys (`Steer::AUTHOR_KEYS`).
536
- - **The wire**: such a message goes out under the review-contribution header (`Steer.wire_text`; prompt-caching.md).
536
+ - **The wire**: such a message goes out under its participant header (`Steer.wire_text`: the pair one, or the review one for an older chi's; prompt-caching.md).
537
537
  Saved raw.
538
538
  - **`Session#last_turn.author`** and the analytics record's `author` (`SessionMetrics`); a Continue keeps the offer
539
539
  turn's author (`ContinueOffer#run_continue_turn`).
540
540
  - **Never a command**: a participant's `/word` or `!line` is refused (`Bridge#handle_post_turn` 403,
541
541
  `WorkerInbound#queue_as_command` drops it). The same two intakes ask `CommandIntake.allowed?` for every other
542
- sender: only a person's (`ClientId.human?`, not `review:`) and `cli:answer`'s line is a command; from a delegate, a
543
- schedule, a plugin or a wake a `/word` line is a prompt and a `!` line is refused (the Bridge's 403
542
+ sender: only the owner's (`ClientId.owner?`) and `cli:answer`'s line is a command; from a delegate, a schedule, a
543
+ plugin, a wake or a sender that names none a `/word` line is a prompt and a `!` line is refused (the Bridge's 403
544
544
  `command_not_permitted`; an input file's or a first prompt's is queued and `Worker#run_command_line` answers it with
545
545
  the error `command_ran`). A session's first prompt carries its sender too: `WorkerInbound#initial_origin` reads
546
- `Session#first_turn_client_id` (a delegate child without it: `ClientId.delegate` of its parent) and `first_turn_id`,
547
- for `#initial_command?` and `Worker#run_initial_prompt`.
546
+ `Session#first_turn_client_id` (a delegate child without it: `ClientId.delegate` of its parent), else the owner's
547
+ `ClientId::FIRST_PROMPT` (`spawn:first`: a person's session saves none), and `first_turn_id`, for `#initial_command?`
548
+ and `Worker#run_initial_prompt`.
549
+ - **Who sent it**: `client_id.rb`'s `ClientId::ROWS`, one `ClientId::Sender` row per id chi makes (the whole id, or a
550
+ prefix ending in `:`; the longest wins): `human`, `owner`, `interactive`, `wake`, `origin`, the merged line's `source`
551
+ and the UIs' `label`. `ClientId.human?`, `.owner?`, `.interactive?`, `.wake_kind`, `.origin`,
552
+ `Steer.source_for_client` and the TUI's labels read it; `turn_events.js CLIENT_LABELS` keeps the same labels
553
+ (`spec/shared/labels_matrix.json` has a case per row). No client id is `ClientId::NONE`: a human's (a delegate
554
+ child's report, the metrics) but **never the owner's**: no session command, no un-archive. Every sender names itself:
555
+ the Bridge's `POST /command` answers 400 `missing_client_id` (`Bridge::UNNAMED_COMMAND`) without one, and a person's
556
+ card answer, which names none (a TUI's, the web's), is stamped `ClientId::CARD_ANSWER` by `ContinueOffer#answered`
557
+ so their Continue / Stop un-archives and resets the wakes (`Worker#user_input`). An id chi doesn't know is
558
+ `ClientId::UNKNOWN`: automatic.
548
559
  - **Delivery**: a participant's input always waits for a turn of its own (`SessionInbox.waits_for_turn_end?`), so
549
560
  the drain never merges it; their turns count against chi web's `pending_limit` (429 `too_many_turns`).
550
- `Worker#run_prompt` checks their link and cap (`participant_refusal`) before the turn and after it.
551
- - **The gate**: `GuardrailWiring#participant_boundary` picks `Guardrails::PairBoundary` or
552
- `Guardrails::ReviewBoundary` by `TurnContext#participant_mode` (guardrails.md). Both are no-ops for the owner.
561
+ `Worker#run_prompt` checks their link (`ParticipantTurnMode`: an older chi's read-only one is `outdated`) and cap (`participant_refusal`) before the turn and after it.
562
+ - **The gate**: `GuardrailWiring#participant_boundary` picks `Guardrails::PairBoundary` for a pair turn, else
563
+ `Guardrails::ParticipantRefusal` (every call denied), by `TurnContext#participant_mode` (guardrails.md). Both are
564
+ no-ops for the owner.
553
565
  The declared tools stay the session's (no rebuild per author).
554
566
  - **Hooks and plugins**: `Engine#turn_author` (the published `TurnContext#author`, so any thread reads it from the
555
567
  turn's first moment) is the hook runtime's (`author:` on every event of such a turn) and `ctx.turn_author`.
@@ -688,10 +700,10 @@ announced at once, marked `anytime: true`, **never as the running turn's events*
688
700
  Both loops, unless marked:
689
701
 
690
702
  - <a id="a-reply-that-is-only-a-tool-call"></a>**A reply that is only a tool call** (`LLM::StrayToolCall`, chat loop
691
- only): a reply with no tool calls whose whole text is one tool-call block closed by the tag that opened it
692
- (`<function=` by `</function>`, `<parameter=` by `</parameter>` or `</function>`, `<tool_call>` by
693
- `</tool_call>`; inner tags not needed) isn't an answer. Prose or a fence before it, or anything after the close,
694
- keeps it an answer. Nothing is guessed from the block and it never enters the history (`:generation_completed` and
703
+ only): a reply with no tool calls whose whole text is one tool-call block closed by the tag that opened it, or by
704
+ the wrapper's `</tool_call>` (`<function=` by `</function>` or `</tool_call>`, `<parameter=` by `</parameter>`, `</function>`
705
+ or `</tool_call>`, `<tool_call>` by `</tool_call>`; inner tags not needed) isn't an answer. Prose or a fence before it, or anything
706
+ after the close, keeps it an answer. Nothing is guessed from the block and it never enters the history (`:generation_completed` and
695
707
  `:after_generation` have already seen the text): `:generation_retrying`
696
708
  with `restarted` voids the streamed text, `:empty_answer_retry` with `malformed` goes out, and a hidden
697
709
  `TurnNote.malformed_retry` asks again at the retry temperature. Its own budget (`retry.empty_answer: 0` doesn't turn
@@ -136,7 +136,7 @@ same cleaned id (`rowId`, one rule for both), so what is drawn is what fills. A
136
136
  strings reach the page through `textContent` and attributes only, never `innerHTML`, so a step reading
137
137
  `<img src=x onerror=…>` shows as those characters.
138
138
 
139
- **What doesn't draw.** The participant page (`participant.js` wires no block host), `web.markdown` off (no
139
+ **What doesn't draw.** `web.markdown` off (no
140
140
  `data-lang`), a live answer while it streams (its YAML shows until the turn's end re-renders it as markdown), and
141
141
  anything outside `TEXTS`: cards, question replies, a lead-in bubble, delegate reports. The terminal shows the YAML.
142
142