samagotchi 0.172.1 → 0.173.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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/docs/architecture.md +16 -5
  4. data/docs/cli.md +2 -1
  5. data/docs/configuration.md +1 -1
  6. data/docs/internals/background-tasks.md +19 -6
  7. data/docs/internals/bridge.md +2 -2
  8. data/docs/internals/engine.md +2 -1
  9. data/docs/internals/participants.md +67 -9
  10. data/docs/internals/remote-sessions.md +1 -1
  11. data/docs/internals/web-frontend.md +11 -6
  12. data/docs/plugins.md +3 -1
  13. data/docs/sessions.md +2 -2
  14. data/docs/testing.md +26 -10
  15. data/lib/samagotchi/bridge.rb +3 -2
  16. data/lib/samagotchi/bundle_command/try/sandbox.rb +2 -2
  17. data/lib/samagotchi/bundles/core/manifest.yml +2 -2
  18. data/lib/samagotchi/bundles/slow-commands/manifest.yml +3 -3
  19. data/lib/samagotchi/bundles/slow-commands/plugin.rb +3 -3
  20. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  21. data/lib/samagotchi/engine/participants.rb +2 -2
  22. data/lib/samagotchi/engine.rb +0 -1
  23. data/lib/samagotchi/file_ref.rb +3 -5
  24. data/lib/samagotchi/guardrails/participant_refusal.rb +1 -1
  25. data/lib/samagotchi/memory_usage.rb +2 -1
  26. data/lib/samagotchi/message_parts.rb +5 -3
  27. data/lib/samagotchi/objectives_backing.rb +6 -10
  28. data/lib/samagotchi/parent_report.rb +1 -1
  29. data/lib/samagotchi/participant_prompts.rb +101 -0
  30. data/lib/samagotchi/participant_turn_mode.rb +1 -1
  31. data/lib/samagotchi/project_env.rb +7 -5
  32. data/lib/samagotchi/prompt_history.rb +2 -2
  33. data/lib/samagotchi/send_command/parent_gate.rb +2 -2
  34. data/lib/samagotchi/send_command.rb +4 -4
  35. data/lib/samagotchi/session_command_catalog.rb +210 -0
  36. data/lib/samagotchi/session_commands.rb +12 -183
  37. data/lib/samagotchi/session_manager/lifecycle.rb +5 -4
  38. data/lib/samagotchi/session_manager.rb +2 -1
  39. data/lib/samagotchi/session_stores.rb +2 -0
  40. data/lib/samagotchi/spawn_env.rb +75 -0
  41. data/lib/samagotchi/task_files.rb +51 -0
  42. data/lib/samagotchi/task_transcript.rb +67 -0
  43. data/lib/samagotchi/task_watch.rb +8 -6
  44. data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +3 -3
  45. data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -2
  46. data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
  47. data/lib/samagotchi/terminal_ui/input_support.rb +1 -1
  48. data/lib/samagotchi/testing/boundary.rb +5 -0
  49. data/lib/samagotchi/tool_activity.rb +63 -79
  50. data/lib/samagotchi/tool_names.rb +179 -0
  51. data/lib/samagotchi/tool_view.rb +3 -5
  52. data/lib/samagotchi/tools/ask_user_question.rb +2 -1
  53. data/lib/samagotchi/tools/builtins.rb +1 -1
  54. data/lib/samagotchi/tools/cancel_reminder.rb +2 -1
  55. data/lib/samagotchi/tools/cancel_schedule.rb +3 -1
  56. data/lib/samagotchi/tools/context_read.rb +2 -1
  57. data/lib/samagotchi/tools/delegate.rb +2 -1
  58. data/lib/samagotchi/tools/delegate_result.rb +2 -1
  59. data/lib/samagotchi/tools/edit.rb +2 -1
  60. data/lib/samagotchi/tools/execute.rb +22 -28
  61. data/lib/samagotchi/tools/forget_outputs.rb +2 -1
  62. data/lib/samagotchi/tools/list_reminders.rb +2 -1
  63. data/lib/samagotchi/tools/list_schedules.rb +3 -1
  64. data/lib/samagotchi/tools/list_sessions.rb +2 -1
  65. data/lib/samagotchi/tools/memory.rb +3 -2
  66. data/lib/samagotchi/tools/objectives_tool.rb +5 -4
  67. data/lib/samagotchi/tools/read.rb +2 -1
  68. data/lib/samagotchi/tools/register_reminder.rb +2 -1
  69. data/lib/samagotchi/tools/schedule_task.rb +3 -1
  70. data/lib/samagotchi/tools/send_note.rb +2 -1
  71. data/lib/samagotchi/tools/task_create.rb +2 -1
  72. data/lib/samagotchi/tools/task_get.rb +2 -1
  73. data/lib/samagotchi/tools/task_list.rb +2 -1
  74. data/lib/samagotchi/tools/task_runtime.rb +34 -154
  75. data/lib/samagotchi/tools/task_stop.rb +2 -1
  76. data/lib/samagotchi/tools/task_wait.rb +3 -2
  77. data/lib/samagotchi/tools/web_fetch.rb +2 -1
  78. data/lib/samagotchi/tools/write.rb +2 -1
  79. data/lib/samagotchi/turn_checkpoint.rb +1 -1
  80. data/lib/samagotchi/version.rb +1 -1
  81. data/lib/samagotchi/web/app.rb +38 -36
  82. data/lib/samagotchi/web/message_display.rb +1 -7
  83. data/lib/samagotchi/web/participant_access.rb +12 -4
  84. data/lib/samagotchi/web/participant_history.rb +68 -0
  85. data/lib/samagotchi/web/participant_images.rb +2 -1
  86. data/lib/samagotchi/web/participant_show.rb +5 -5
  87. data/lib/samagotchi/web/participants_admin.rb +1 -1
  88. data/lib/samagotchi/web/public/app.js +11 -9
  89. data/lib/samagotchi/web/public/card_registry.js +248 -0
  90. data/lib/samagotchi/web/public/cards_offscreen.js +3 -3
  91. data/lib/samagotchi/web/public/cards_place.js +8 -2
  92. data/lib/samagotchi/web/public/history_shape.js +1 -2
  93. data/lib/samagotchi/web/public/participant_history.js +27 -0
  94. data/lib/samagotchi/web/public/question_cards.js +1 -15
  95. data/lib/samagotchi/web/public/reload_check.js +90 -72
  96. data/lib/samagotchi/web/public/session_view.js +6 -1
  97. data/lib/samagotchi/web/public/stage_asking.js +6 -20
  98. data/lib/samagotchi/web/public/stage_view.js +2 -2
  99. data/lib/samagotchi/web/public/stage_waiting.js +4 -10
  100. data/lib/samagotchi/web/public/task_stop.js +1 -1
  101. data/lib/samagotchi/web/push_routes.rb +1 -1
  102. data/lib/samagotchi/web/reload_check_route.rb +5 -2
  103. data/lib/samagotchi/web/request_body.rb +72 -0
  104. data/lib/samagotchi/web/server.rb +70 -0
  105. data/lib/samagotchi/web/session_access_routes.rb +13 -11
  106. data/lib/samagotchi/web/session_control.rb +21 -15
  107. data/lib/samagotchi/web/session_create.rb +2 -1
  108. data/lib/samagotchi/web/session_show.rb +8 -8
  109. data/lib/samagotchi/web/viewer.rb +7 -2
  110. data/lib/samagotchi/web/working_set_routes.rb +3 -3
  111. data/lib/samagotchi/worker.rb +49 -182
  112. data/lib/samagotchi/worker_exit_claim.rb +102 -0
  113. data/lib/samagotchi/worker_participant_gate.rb +156 -0
  114. data/lib/samagotchi/worker_task_wakes.rb +2 -2
  115. metadata +13 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 373feecab32762e6d14c5740f3989bc31d93722133f1f956783e4203a977a44b
4
- data.tar.gz: b7bb34bbfa66dcb9ea47f464856d4eb7cbf9ed696bf3ab59f72cc34bee69bcc9
3
+ metadata.gz: 858f59d0b9696f081f3f482cb9ae4609bf9ad1793f84567be5aacfc05950cd8e
4
+ data.tar.gz: 902bdba4fbd18fb2faa666402bf37cf2cbe610f6293e7d6107dc8699894ea65c
5
5
  SHA512:
6
- metadata.gz: 20c1e7acc7574a0cd8c216a76faacc12de4466ce8728900374b459bc99ea7875093c51a8f56cf2ca685d7463937cc378a7f868e0502f80025fd0ec98d39d0e91
7
- data.tar.gz: b63932bda384afa0d83f966e988f18945728b62a1af362452c3fcb4d2f5d6d89cda359ec1c74624b5b3119242de3a62f99100bd7d4a0f7c654d9d2f56d4d5374
6
+ metadata.gz: 9e2e8ce3d8c6ce27b4844d38fea93ad8603197fe9c61b0ff3275e116a52a658d294ff22348afea3fb5b18943e857173b5ae54565162ae8df5d89c03ee2f7d964
7
+ data.tar.gz: 1f9516d73eb9f34768946891583e18121aa9361f60818025d5d87b557668df6e7bee5497bb59fcc514782d830025c6eb073fc9c717c130f1e9fbccd9d63bc5ba
data/CHANGELOG.md CHANGED
@@ -8,6 +8,35 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.173.0] - 2026-11-14
12
+
13
+ ### Added
14
+
15
+ - chi web: a participant's ↑ in the composer recalls their own earlier messages in that session (never the owner's or
16
+ another participant's). Messages they sent before this update aren't recalled, and a new invite starts empty.
17
+
18
+ ### Changed
19
+
20
+ - The terminal and chi web start a little faster and use a little less memory: they no longer load the code that runs
21
+ tools (about 40 fewer files).
22
+
23
+ ### Fixed
24
+
25
+ - Web: after a reload, a second question or approval from the same step of a finished turn no longer repeats the step's
26
+ reply above it, as live.
27
+ - Web: `/api/update`'s answer to a body over 16 KB is `413 too_large`, as every other route's, and a stop whose body
28
+ is over 4 KB is refused instead of using the default wait.
29
+
30
+ ### Security
31
+
32
+ - chi web no longer reads a form or file body sent with the page's `?token=` link before checking the token: a large
33
+ one sent to the login page was read into memory or temp files by anyone who could reach chi web.
34
+ - chi web caps every request body: 64 KB unless a route needs more (a turn, an image, a context push). A bigger one
35
+ gets `413 too_large` and the connection is closed, instead of being read whole, so a participant can't fill chi
36
+ web's memory with one request.
37
+
38
+ Update with `chi update` (slow-commands 0.2.6, the core profile 0.4.4).
39
+
11
40
  ## [0.172.1] - 2026-11-14
12
41
 
13
42
  ### Fixed
@@ -6359,7 +6388,8 @@ and long-lived sessions.
6359
6388
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
6360
6389
  hotkey panel that send selected text or the clipboard to your sessions.
6361
6390
 
6362
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.172.1...HEAD
6391
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.173.0...HEAD
6392
+ [0.173.0]: https://github.com/dm1try/samagotchi/compare/v0.172.1...v0.173.0
6363
6393
  [0.172.1]: https://github.com/dm1try/samagotchi/compare/v0.172.0...v0.172.1
6364
6394
  [0.172.0]: https://github.com/dm1try/samagotchi/compare/v0.171.0...v0.172.0
6365
6395
  [0.171.0]: https://github.com/dm1try/samagotchi/compare/v0.170.0...v0.171.0
data/docs/architecture.md CHANGED
@@ -176,7 +176,7 @@ unless mise sets them; never `HOME`, `XDG_*`, `SAMAGOTCHI_*`, `CHI_REMOTE`, `RAC
176
176
  (`$XDG_STATE_HOME/samagotchi/bin`, only a `chi` that execs `Record#boot_argv(run: CHI_BOOT)`) first on PATH when there
177
177
  is a home, `SAMAGOTCHI_PROJECT_ENV` (`mise:<ruby>` or `none:<reason>`, for `chi self`) and
178
178
  `SAMAGOTCHI_PROJECT_ENV_ORIG` (the worker's own value of each key it changes). It is merged into: `execute` and
179
- `task_create` for the owner's turns (`Builtins.project_env`, less `TaskRuntime::SANITIZED_ENV_KEYS`; never a
179
+ `task_create` for the owner's turns (`Builtins.project_env`, less `SpawnEnv::SANITIZED_ENV_KEYS`; never a
180
180
  participant's turn), `!cmd` (`SessionCommands#shell`), context sources (`ContextFetch`) and MCP servers (the mcp
181
181
  bundle's `server_env`). A worker started from the worker inherits its clean ENV. A `chi` a tool runs (through the shim or not, a fresh
182
182
  process with the tools' env) takes the worker's values back from the record in `bin/chi`, before anything reads
@@ -200,8 +200,8 @@ Each entry point requires what it uses, so a process loads its own part of chi a
200
200
  |---|---|---|
201
201
  | a worker | the boot string's `samagotchi/worker_boot` | the boot, then the Worker, its Engine and Bridge; no TerminalUI, no Reline |
202
202
  | `chi <subcommand>`, `chi self`, `chi web push` | `bin/chi`, then the subcommand's file | that command's closure; no `engine.rb`, no Reline (`chi --version` 27 of chi's files, `chi sessions list` about 270) |
203
- | the attached TUI | `bin/chi` → `terminal_ui/attach_launcher` | the TUI, Reline and its Bridge client; no `engine.rb` |
204
- | chi web | `bin/chi` → `web/server` | the control plane; no `engine.rb` |
203
+ | the attached TUI | `bin/chi` → `terminal_ui/attach_launcher` | the TUI, Reline and its Bridge client; no `engine.rb`, no tool that runs (`tools/execute`, `tools/builtins`, `tools/task_runtime`) |
204
+ | chi web | `bin/chi` → `web/server` | the control plane; no `engine.rb`, no tool that runs (as the TUI) |
205
205
  | the one-shot (`-p X --non-interactive`) | `bin/chi` → `terminal_ui` | TerminalUI and an Engine of its own |
206
206
  | outside callers (a script, `chi bundle try`'s sandbox, the suite's `fork_chi` preload) | `samagotchi` (`lib/samagotchi.rb`) | eager: everything a turn needs |
207
207
 
@@ -210,7 +210,18 @@ the `--resume`/`--attach` id check, `samagotchi/terminal_ui` before the one-shot
210
210
  names**; `autoload` only for a constant defined in one file, never for a namespace other files reopen (that fires
211
211
  the autoload from inside the reopening file and ends in a `NameError`). `spec/require_cycle_spec.rb` pins it: no
212
212
  `engine.rb` or Reline for `chi --version`, `home`, `sessions list` and `schedule list`, no TerminalUI or Reline in a
213
- worker.
213
+ worker, and (its thin client load budgets) no turn loop, bundle updater, `tools/execute`, `tools/builtins` or
214
+ `tools/task_runtime` for the attached TUI and chi web.
215
+
216
+ The clients name tools and the session commands without loading them. A tool's name and the fixed texts it writes
217
+ into results (`Execute::HANDED_OVER`…) live in `ToolNames` (`tool_names.rb`, no requires), which the tool classes
218
+ read their constants from and the display code (`ToolActivity`, `ToolView`, `FileRef`, `ObjectivesBacking`) reads
219
+ directly. The session commands' names, the built-ins' registry and its class-level reads (`builtin_name`,
220
+ `builtin_registry`, `ui_only_entry`, `ui_only_refusal`, `delete_on_exit?`, `SHELL_BANG_PREFIX`…) live in
221
+ `SessionCommandCatalog` (`session_command_catalog.rb`), which the TUI, chi web, `chi send` and `PromptHistory`
222
+ require; `SessionCommands` (the runner, worker-side: `!cmd` runs `Tools::Execute`) includes it and forwards the
223
+ class methods, so `SessionCommands.x` reads the same. A new client-side read of either goes to the table or the
224
+ catalogue, never to the class.
214
225
 
215
226
  ## Session retention & ordering
216
227
 
@@ -640,7 +651,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
640
651
 
641
652
  | Component | Main file(s) | What it is |
642
653
  |---|---|---|
643
- | Worker | `worker.rb` (`worker_boot.rb`, `worker_idle_exit.rb`, `worker_inbound.rb`, `worker_signals.rb`, `worker_wakes.rb`, `worker_task_wakes.rb`, `task_watch.rb`) | A session's background process: builds the `Engine` and `Bridge`, runs queued turns and the wake turns nobody typed (delegate reports, a background task that finished unseen: [Finish wake](internals/background-tasks.md#finish-wake), attached context), exits when idle. A spawned one traps TERM, HUP and INT (`WorkerSignals`, installed by `WorkerBoot.run_session_loop` when `SAMAGOTCHI_WORKER_PROCESS=1`): the running turn stops as a Stop with reason `signal`, is saved, and the worker leaves (`:signal`, exit 0; a new worker only for input already queued). A running turn is checkpointed at its iteration boundaries (`TurnCheckpoint`, the `interrupted_turn` mark), and the next worker settles a turn its predecessor died in (`TurnCheckpoint.settle`). The session is saved from the turn's thread, Bridge threads and a signal's thread; `Session#save` takes a per-session lock around its snapshot and write, so an older snapshot never lands over a newer one. |
654
+ | Worker | `worker.rb` (`worker_boot.rb`, `worker_idle_exit.rb`, `worker_inbound.rb`, `worker_signals.rb`, `worker_wakes.rb`, `worker_task_wakes.rb`, `task_watch.rb`, `worker_participant_gate.rb`, `worker_exit_claim.rb`) | A session's background process: builds the `Engine` and `Bridge`, runs queued turns and the wake turns nobody typed (delegate reports, a background task that finished unseen: [Finish wake](internals/background-tasks.md#finish-wake), attached context), exits when idle. A spawned one traps TERM, HUP and INT (`WorkerSignals`, installed by `WorkerBoot.run_session_loop` when `SAMAGOTCHI_WORKER_PROCESS=1`): the running turn stops as a Stop with reason `signal`, is saved, and the worker leaves (`:signal`, exit 0; a new worker only for input already queued). A running turn is checkpointed at its iteration boundaries (`TurnCheckpoint`, the `interrupted_turn` mark), and the next worker settles a turn its predecessor died in (`TurnCheckpoint.settle`). The session is saved from the turn's thread, Bridge threads and a signal's thread; `Session#save` takes a per-session lock around its snapshot and write, so an older snapshot never lands over a newer one. `WorkerParticipantGate` is the one seat for "may this participant act" (a queued turn as it starts, the drain, the mid-turn stop, the Continue: [internals/participants.md](internals/participants.md)); `WorkerExitClaim` is the exit claim (`POST /exit`): one lock for the kind being taken and the exit taken. Threads: the gate is loop-thread only (a turn runs on the loop; no lock), the claim is safe from any thread (its own mutex, taken after the event lock). |
644
655
  | Config | `config.rb`, `config/restart_watch.rb` | Every setting as an `Entry`: env, config.yml and CLI layers ([configuration.md](configuration.md)); the notice a worker or chi web gets when config.yml changes a setting it reads only at its start. With `log.rb` it is the bottom layer: nothing it references reaches back to it, so `hosts:` and `models:` entries parse next to their types (`HostConfig.all`, `ModelSettings.all`). |
645
656
  | Paths | `paths.rb` (`Paths`) | The XDG base dirs chi's files live under, read from the env on every call: `Paths.state_home` (`$XDG_STATE_HOME`, else `~/.local/state`) and `Paths.config_home` (`$XDG_CONFIG_HOME`, else `~/.config`), both defaults under `Dir.home`; a blank variable counts as unset, a relative one is made absolute from the current directory. `Paths.tilde` shows a path with `~` for the home folder. `SessionManager` hands a spawned worker the spawner's `XDG_STATE_HOME` / `XDG_CONFIG_HOME`, when set, made absolute, so a relative one isn't read from the session's folder. |
646
657
  | MemoryBundle | `memory_bundle.rb`, `memory_bundle/{installer,builder,installed_bundle,plugin_ref,bundle_hook}.rb` (`Installer`, `Builder`, `InstalledBundle`, `PluginRef`, `BundleHook`) | Installing, building and reading bundles of memories, rules, plugins and scripts (`BundleHook`: an older record's retired class-file hook). |
data/docs/cli.md CHANGED
@@ -1781,7 +1781,8 @@ chi share revoke --all # every link to every session
1781
1781
  While their own turn runs they can **Stop turn**, and a message goes in at its next step (Alt+Enter keeps it for
1782
1782
  after the turn); while yours or another participant's runs, it goes in as their own turn afterwards. When their
1783
1783
  turn waits for you (an approval, a question, your Continue) they see that it waits and for what kind of thing,
1784
- never its content. At their cap, in a stopped session, or once their link ended the composer gives way to one line
1784
+ never its content. ↑ in their composer recalls their own earlier messages in that session (as the conversation
1785
+ shows them; never yours or another participant's). At their cap, in a stopped session, or once their link ended the composer gives way to one line
1785
1786
  and the conversation stays readable. They get none of your controls: no new session, list, rename, model, images
1786
1787
  (yet), session menu, participants panel, cards or approvals, and no file panel (they ask chi to quote what they
1787
1788
  need). They never see tool output or arguments, thinking, approvals or questions, memories, context notes,
@@ -2383,7 +2383,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
2383
2383
  | `web.host` | `127.0.0.1` | yes | `127.0.0.1`, `::1` or `localhost`; `lan` (this machine's private IPv4 address) or one of its IPv4 addresses also opens `chi web` to the network, with an access token, asked of this machine's 127.0.0.1 too (its `Local:` link carries a one-time code; `chi web --new-token` replaces the token; it is chi web's one access token, also used by `--tunnel` and `web.public_url`/a proxy). Anything else binds `127.0.0.1` with a warning. See [CLI: chi web on your phone](cli.md#chi-web-on-your-phone). |
2384
2384
  | `web.markdown` | `false` | yes | Render answers as Markdown in `chi web`. |
2385
2385
  | `web.working_set` | `true` | yes | The stage view's working set: the files, memories and URLs a turn brought into the model's context, in a rail in the stage, a footprint as each finished turn's block summary and a `set N` chip in place of the mem chip; `false` brings the mem chip back. `?working_set=1` or `?working_set=0` on the page URL overrides it for that page load. See [CLI: the working set](cli.md#the-working-set). |
2386
- | `web.reload_check` | `false` | yes | Opt-in: once each finished turn has moved into the history, the page reads the session again (one full read per turn end), draws that turn as a reload would and compares the two, strictly: a known divergence counts as a mismatch too. `chi web` logs one `reload_checked` line per check and a `reload_mismatch` line naming the kinds that differed, `excused` (the known divergences, `history_shape.js` `ACCEPTED`, that would explain them) and `explained` (all of them had one), with `turn_id`, `drawn` (the turn came back from its drawing, so a mismatch with `drawn: true` is a drawing bug), `undrawn` (how many of the reload's rows came without their turn's drawing, the page's plain fallback: 0 unless chi web missed a turn) and the worker's version: counts only, never content. The count is `grep -c reload_mismatch` over `grep -c reload_checked` in chi web's log, split by `excused`. The turn's own cards and answered questions are compared too: a drawn turn already renders its plugin cards, and the snapshot's questions (and an undrawn turn's entries) are placed into the offscreen render by the page's own placer with inert hooks (`cards_offscreen.js`). A card counts as the same when it has the same id and title in the same place, a question when its summary line and the kept reply's plain line do; bodies, buttons, folds and the tag a card is drawn in are ignored. Only entries CardStore attributes to this turn (`of_turn`) are compared: a card of another turn or between turns is dropped by id, and a question the read gives no turn and no opening stamp for (an older worker) is left out on both sides. Between-turn cards and notices stay with the e2e reload checks. Every open owner tab runs the check; `chi web` logs a turn's first report only, and starts over when it restarts. |
2386
+ | `web.reload_check` | `false` | yes | Opt-in: once each finished turn has moved into the history, the page reads the session again (one full read per turn end), draws that turn as a reload would and compares the two, strictly: a known divergence counts as a mismatch too. `chi web` logs one `reload_checked` line per check and a `reload_mismatch` line naming the kinds that differed, `excused` (the known divergences, `history_shape.js` `ACCEPTED`, that would explain them) and `explained` (all of them had one), with `turn_id`, `drawn` (the turn came back from its drawing, so a mismatch with `drawn: true` is a drawing bug), `undrawn` (how many of the reload's rows came without their turn's drawing, the page's plain fallback: 0 unless chi web missed a turn) and the worker's version: counts only, never content. The count is `grep -c reload_mismatch` over `grep -c reload_checked` in chi web's log, split by `excused`. The turn's own cards and questions are compared as data, apart from the history: what the page's stream said (`card_registry.js`) against what the read lists (CardStore), each card or question of this turn (`of_turn`) by its id, its kind, its status (answered, cancelled, still asking) and its summary line (a card's title); a difference counts as `card` or `question`. Bodies, buttons, folds, the tag a card is drawn in and where it sits are ignored (the history's compare leaves cards and questions out on both sides; their place is the specs'). A read that lists CardStore's cap of cards and questions may have lost an older one: a card the page has and such a read doesn't is no difference. A question the read gives no turn and no opening stamp for (an older worker) leaves the questions out. A page whose `app.js` is older than its `reload_check.js` (a mixed cache) compares no cards: its `reload_checked` line says `cards_compared: false`. Between-turn cards and notices stay with the e2e reload checks. Every open owner tab runs the check; `chi web` logs a turn's first report only, and starts over when it restarts. |
2387
2387
  | `web.annotate_presets` | `Agreed\|Could you please elaborate?` | yes | Quick replies next to Annotate in `chi web`, `\|`-separated (a YAML list works too); `""` in the file or on the CLI leaves only Annotate (an empty env value means the default). See [CLI](cli.md#web-annotate-presets). |
2388
2388
  | `web.editor` | `vscode` | yes | What a file ref in `chi web` (a file tool row's title, a diff line) opens, for a viewer on this machine: a preset (`vscode`, `vscode-insiders`, `cursor`, `zed`) or a URL template with `{path}` and an optional `{line}`; `none` turns refs off. See [Opening files from chi web](#opening-files-from-chi-web). |
2389
2389
  | `web.start_dir` | the folder `chi web` runs in | | The folder `chi web` starts in (`chi web --start-dir DIR` for one run): its page (the printed link, a bare `/`, the LAN link and QR code, the Home Screen app) opens on that folder's project, outside a project (no repository or marked folder) on every session, and a new session from the all view starts there; the header's project picker switches projects. `~` and a relative path (resolved from your home folder) work; one that isn't a folder stops `chi web` from starting. `chi web` never changes its own folder. See [CLI](cli.md). |
@@ -15,6 +15,19 @@ Recommended workflow:
15
15
  3. For commands with a reliable completion marker, pass `done_pattern` to return when the recent log tail matches it.
16
16
  4. Use `task_get` or `task_list` for nonblocking status checks, and `task_stop` if needed.
17
17
 
18
+ The code is split by who uses it, so a client that only reads (the attached TUI, chi web, `sessions list`) need not
19
+ load the process code, and does not (`spec/require_cycle_spec.rb`, the thin client load budgets):
20
+
21
+ | Module | Holds | Read by |
22
+ |---|---|---|
23
+ | `Tools::TaskRuntime` (`tools/task_runtime.rb`) | the lifecycle: `create_task`, `adopt`, the waiter (`record_exit_status`, `waiter_for`), refresh, `stop_task`, `get_record`, `list_records`, `running_created_in`, the leftovers; all process state (`@waiters`, `@settle_lock`) | the task tools, `execute`, `Bridge`, `HoldStop`, `TaskWatch`, `TurnEndings`, `Worker` |
24
+ | `SpawnEnv` (`spawn_env.rb`) | the env a spawned command gets: `sanitized_spawn_env`, `spawn_env_for` (task_create's `env` checks), `SANITIZED_ENV_KEYS`, `MARKER_ENV_KEYS` | `execute`, `create_task`, `ProjectEnv.spawn_env` (required at call time: `child_env` requires `project_env`) |
25
+ | `TaskFiles` (`task_files.rb`) | where a task's files are: `TASKS_DIR`, `METADATA_FILENAME`, `OUTPUT_FILENAME`, `EXIT_CODE_FILENAME`, `TASK_ID`, `metadata_path`, `task_dir_for`, `command_of` (a record read, no refresh) | `TaskRuntime`, `execute`, `ToolActivity`, `SessionManager`, `chi bundle try`'s sandbox, the slow-commands bundle |
26
+ | `TaskTranscript` (`task_transcript.rb`) | which tasks a conversation started, from its results' text: `created_ids_in`, `created_id`, `handed_over_id`, `RAN_AS_LINE` (matching on `ToolNames::Execute`) | `TaskRuntime.running_created_in`, `Bridge`, `TaskWatch`, `WorkerTaskWakes`, `SessionManager` |
27
+
28
+ `TaskRuntime::TASKS_DIR` and `TaskRuntime::EXIT_CODE_FILENAME` forward to `TaskFiles` for one release (bundles named
29
+ them; the boundary's stable list has both homes until they are removed).
30
+
18
31
  Behavior:
19
32
 
20
33
  - `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.
@@ -26,9 +39,9 @@ Behavior:
26
39
  - 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
40
  - `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.
28
41
  - 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.
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.
42
+ - 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` (both defined in `ToolNames::Execute`) (`120s limit:` or `4s mark:`): `TaskTranscript.handed_over_id`, `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.
30
43
  - `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)).
31
- - Which tasks are a session's own (a cancelled turn's note, a worker's restart hold, the finish wake below, the web's stop-task button): the ids its `task_create` results and its handed-over executes name (`TaskRuntime.created_ids_in`, `created_id`). An execute's id is read only after its first line (`Execute::HANDED_OVER`, through `TaskRuntime.handed_over_id`; the web has a JS twin in `task_stop.js`), not from a `task_id:` line inside a run, which the command can print. (A command that prints the `---` separator chi joins a turn's results with, then a hand-over line, still fakes one: a known gap.) Either result may start with the `ran as: …` line of a gate-corrected call.
44
+ - Which tasks are a session's own (a cancelled turn's note, a worker's restart hold, the finish wake below, the web's stop-task button): the ids its `task_create` results and its handed-over executes name (`TaskTranscript.created_ids_in`, `created_id`). An execute's id is read only after its first line (`Execute::HANDED_OVER`, through `TaskTranscript.handed_over_id`; the web has a JS twin in `task_stop.js`), not from a `task_id:` line inside a run, which the command can print. (A command that prints the `---` separator chi joins a turn's results with, then a hand-over line, still fakes one: a known gap.) Either result may start with the `ran as: …` line of a gate-corrected call.
32
45
  - `task_get` returns metadata and `output_path`; use `read` for output contents.
33
46
  - `task_wait` accepts `timeout`, `tail_lines` (maximum 100), and `done_pattern` (a regular expression string).
34
47
  - `task_wait`'s results: a finished task's status and tail (no `wait_result`), or one still running with
@@ -42,8 +55,8 @@ Behavior:
42
55
  again or stop it (`TaskWait::MESSAGE_WAITING_NOTE`), and `waited: Ns`; the task keeps running and stays watched
43
56
  (below). A task that finished meanwhile gives its finished result, as after a Stop. A `chi -p` turn has no probe. The same probe ends a blocking `delegate_result` (and `delegate`'s wait) early; see [Sessions: Delegating](../sessions.md).
44
57
  - `task_create` accepts `env` as a JSON object string for deterministic overrides such as `PATH`; use an absolute interpreter path when that is simpler. Ruby/Bundler isolation variables remain protected.
45
- - `execute` and `task_create` both spawn with chi's own Ruby/Bundler setup scrubbed (`TaskRuntime.sanitized_spawn_env`): `RUBYOPT` loses its `-r…bundler/setup` flags (others stay) and `RUBYLIB` and what `bundle exec` sets (`BundlerEnv::VARS`: `BUNDLE_GEMFILE`, `BUNDLE_LOCKFILE`, `BUNDLE_BIN_PATH`, `BUNDLER_VERSION`, `BUNDLER_SETUP`) are unset, so a project's `ruby -e` or `bundle exec` uses its own Gemfile, or none, when chi runs under `bundle exec`. RubyGems requires what `BUNDLER_SETUP` names at boot, whatever `RUBYOPT` says. A project's own settings (`BUNDLE_PATH`, `BUNDLE_WITHOUT`) stay. `task_create` refuses those keys in the model's `env`, its error saying to write `KEY=value cmd` in the command instead; `execute`'s `env` comes from chi's callers (`Builtins`, `!cmd`), not the model, and is set over the scrub. An `execute` handed over at its limit keeps the process it spawned, so the task runs with the same env.
46
- - `execute` and `task_create` export chi's own markers into the command, set over the model's `env` (which can't set them: `Error: env key is reserved`): `SAMAGOTCHI_PARENT_SESSION` (the session's id, `chi` without one; a chi started there answers as a parent agent), `SAMAGOTCHI_SESSION_MODEL` (the resolved ref the session runs on, read at each call so it follows `/model`; unset when unknown) `SAMAGOTCHI_SESSION_THINKING` (the session's own thinking level; unset when it has none) and `SAMAGOTCHI_SESSION_REASONING_HISTORY` (its own reasoning_history level, the same way). `chi self` reads the last three for its model, thinking level and reasoning history. The four are `ChildEnv::SESSION_MARKERS` (`TaskRuntime::MARKER_ENV_KEYS`), which a spawned worker unsets (`ChildEnv.unset`, merged into its spawn env). A session's worker never inherits them from whoever started it (a `chi send` run by another session's `execute`): its other commands (a user's `!cmd`, an MCP server, a context command) have none.
58
+ - `execute` and `task_create` both spawn with chi's own Ruby/Bundler setup scrubbed (`SpawnEnv.sanitized_spawn_env`): `RUBYOPT` loses its `-r…bundler/setup` flags (others stay) and `RUBYLIB` and what `bundle exec` sets (`BundlerEnv::VARS`: `BUNDLE_GEMFILE`, `BUNDLE_LOCKFILE`, `BUNDLE_BIN_PATH`, `BUNDLER_VERSION`, `BUNDLER_SETUP`) are unset, so a project's `ruby -e` or `bundle exec` uses its own Gemfile, or none, when chi runs under `bundle exec`. RubyGems requires what `BUNDLER_SETUP` names at boot, whatever `RUBYOPT` says. A project's own settings (`BUNDLE_PATH`, `BUNDLE_WITHOUT`) stay. `task_create` refuses those keys in the model's `env`, its error saying to write `KEY=value cmd` in the command instead; `execute`'s `env` comes from chi's callers (`Builtins`, `!cmd`), not the model, and is set over the scrub. An `execute` handed over at its limit keeps the process it spawned, so the task runs with the same env.
59
+ - `execute` and `task_create` export chi's own markers into the command, set over the model's `env` (which can't set them: `Error: env key is reserved`): `SAMAGOTCHI_PARENT_SESSION` (the session's id, `chi` without one; a chi started there answers as a parent agent), `SAMAGOTCHI_SESSION_MODEL` (the resolved ref the session runs on, read at each call so it follows `/model`; unset when unknown) `SAMAGOTCHI_SESSION_THINKING` (the session's own thinking level; unset when it has none) and `SAMAGOTCHI_SESSION_REASONING_HISTORY` (its own reasoning_history level, the same way). `chi self` reads the last three for its model, thinking level and reasoning history. The four are `ChildEnv::SESSION_MARKERS` (`SpawnEnv::MARKER_ENV_KEYS`), which a spawned worker unsets (`ChildEnv.unset`, merged into its spawn env). A session's worker never inherits them from whoever started it (a `chi send` run by another session's `execute`): its other commands (a user's `!cmd`, an MCP server, a context command) have none.
47
60
  - They also pass on a set `XDG_STATE_HOME` / `XDG_CONFIG_HOME` made absolute (`Builtins.xdg_absolute`, via `Paths`), so a chi the command runs in another `cwd` (`chi send`) reads this chi's state and config. These aren't reserved: an XDG dir the model sets in `task_create`'s `env` stays its own.
48
61
  - Every runner starts from the session's project env, `ProjectEnv.tools_env`: the overlay a spawned worker computed once at boot (`WorkerBoot.apply_project_env` → `ProjectEnv.compute` → `ProjectEnv.install!`; its folder's `mise env`, and the chi shim's dir first on PATH so `chi` is the chi home's), less `ProjectEnv::TOOLS_DROP` (`RUBYOPT`, `RUBYLIB`, Bundler's: the scrub above sets those). Outside a worker (`ProjectEnv::NONE`) it is `{}`. The sites: `execute` and `task_create` (`Tools::Builtins#project_env`, under the markers and the model's `env`; a participant's turn gets `{}`), the user's `!cmd` (`SessionCommands#shell`), and through `ProjectEnv.spawn_env` (the scrub above, then `tools_env`: what `execute` spawns with, for the runners that don't go through it) a context source's command (`ContextFetch#env_for`) and an MCP server, under the server's own keys (`bundles/mcp/plugin.rb` `server_env`, from mcp 0.7.4; no participant rule: the server is the session's). chi's own process env is never changed, and the project env never enters the prompt. User docs: [Project env](../sessions.md#project-env); the launch side: [How chi launches itself](../architecture.md#how-chi-launches-itself).
49
62
 
@@ -51,8 +64,8 @@ Behavior:
51
64
 
52
65
  A task the model leaves running (it ends its turn: "I'll check when it's finished") is reported when it ends, so the result doesn't wait for the user's next message. `session.task_wakes` (env `SAMAGOTCHI_SESSION_TASK_WAKES`): `wake` (default), `queue` or `off` (no watch, as before).
53
66
 
54
- - **The watch** (`TaskWatch`, `task_watch.rb`) is the Worker's (`WorkerTaskWakes`, `worker_task_wakes.rb`, which writes the notes; the Worker runs the wake turn), in memory: a `--non-interactive` one-shot has none, and a crash loses it (those tasks behave as before). The Worker's Engine observer feeds it the raw `:tool_call_completed` events, the input `Bridge#own_task_ids` reads too. A `task_create` result and an `execute` hand-over add the task (`TaskRuntime.created_id`: a `task_id:` the command printed doesn't count), the hand-over's limit kept for the note. What shows the model the end removes it: a `task_wait` with a final status, or with `wait_result: pattern_matched` (the model chose its own "done" marker); a `task_get` with a final status; any `task_stop`. `task_list` and a `read` of `output.log` don't: a model that read the log still gets the wake once. Tasks a tool starts inside an anytime command (`/btw` and the like) reach the same observer, so they are watched too.
55
- - **The idle tick**: with something watched, each idle pass (after delegate reports, before due reminders) refreshes the watched records (`TaskRuntime.get_record`, one `ps` per running task) and takes the finished ones, keeping only the ids the conversation still holds (`TaskRuntime.created_ids_in`: a `!rollback` or a restored turn may have dropped the result that started one; an LLM context strategy can't, since its stale and forget stubs are drawn in the request, never written over the saved result). A note that can't be written puts its task back for the next pass. An empty watch costs nothing. A task that finishes during a turn and is still unseen when the turn ends wakes on the next idle pass. One the user stopped with the web's stop-task button is dropped without a note.
67
+ - **The watch** (`TaskWatch`, `task_watch.rb`) is the Worker's (`WorkerTaskWakes`, `worker_task_wakes.rb`, which writes the notes; the Worker runs the wake turn), in memory: a `--non-interactive` one-shot has none, and a crash loses it (those tasks behave as before). The Worker's Engine observer feeds it the raw `:tool_call_completed` events, the input `Bridge#own_task_ids` reads too. A `task_create` result and an `execute` hand-over add the task (`TaskTranscript.created_id`: a `task_id:` the command printed doesn't count), the hand-over's limit kept for the note. What shows the model the end removes it: a `task_wait` with a final status, or with `wait_result: pattern_matched` (the model chose its own "done" marker); a `task_get` with a final status; any `task_stop`. `task_list` and a `read` of `output.log` don't: a model that read the log still gets the wake once. Tasks a tool starts inside an anytime command (`/btw` and the like) reach the same observer, so they are watched too.
68
+ - **The idle tick**: with something watched, each idle pass (after delegate reports, before due reminders) refreshes the watched records (`TaskRuntime.get_record`, one `ps` per running task) and takes the finished ones, keeping only the ids the conversation still holds (`TaskTranscript.created_ids_in`: a `!rollback` or a restored turn may have dropped the result that started one; an LLM context strategy can't, since its stale and forget stubs are drawn in the request, never written over the saved result). A note that can't be written puts its task back for the next pass. An empty watch costs nothing. A task that finishes during a turn and is still unseen when the turn ends wakes on the next idle pass. One the user stopped with the web's stop-task button is dropped without a note.
56
69
  - **The note** is a context note under its own header (`ContextNote::TASK_HEADER`; `TaskFinishNote`), `note_id: task-<id>`, `source: task <id8>`:
57
70
 
58
71
  ```
@@ -415,7 +415,7 @@ The Bridge exposes:
415
415
  - `POST /session/:id/tasks/stop` — `{task_id}`: stop a background task as the user
416
416
  (`TaskRuntime.stop_task by: "user"`, the web's stop-task button on a running `task_wait`;
417
417
  web route `POST /api/sessions/:id/tasks/:task_id/stop`). Only a task this conversation's
418
- `task_create` started, or an `execute` handed over as a task at its limit (`TaskRuntime.created_ids_in` on the
418
+ `task_create` started, or an `execute` handed over as a task at its limit (`TaskTranscript.created_ids_in` on the
419
419
  saved messages, or the running turn's accumulator); answers once the
420
420
  task is gone: `200 {status, stop_reason, task_id}`, `404 task_not_found`, `409 not_running`.
421
421
  The worker names it in its sidecar features (`task_stop`).
@@ -461,7 +461,7 @@ The Bridge exposes:
461
461
  `continue_offered`, `client_connected` (a stream not named by the asker), `reminders`,
462
462
  `background_tasks` (with `tasks: [{id, command}]`: the running tasks a finish wake watches), `starting`, or
463
463
  `leaving_exit` / `leaving_delete` / `leaving_restart` when another client's exit of another kind is already taken
464
- (`Worker#claim_exit`, claimed before a stop-all; the words are `WorkerIdleExit::LEAVING_WORDS`). A second exit of
464
+ (`WorkerExitClaim#claim`, claimed before a stop-all; the words are `WorkerIdleExit::LEAVING_WORDS`). A second exit of
465
465
  the kind already taken is answered `200` as that one.
466
466
  - `GET /session/:id/state` — `session_state_snapshot` (JSON), read under the event lock so its `event_seq`/`event_id` match the state.
467
467
  - `GET /session/:id/stats` — `Engine#stats_snapshot` for attached `/stats`: the metrics, with the context window and prompt profile asked from the server before the first turn.
@@ -558,7 +558,7 @@ Where a participant's author (`"p:<id>"`; `Steer.participant_author?`) goes (the
558
558
  `ClientId::UNKNOWN`: automatic.
559
559
  - **Delivery**: a participant's input always waits for a turn of its own (`SessionInbox.waits_for_turn_end?`), so
560
560
  the drain never merges it; their turns count against chi web's `pending_limit` (429 `too_many_turns`).
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.
561
+ `Worker#run_prompt` checks their link (`ParticipantTurnMode`: an older chi's read-only one is `outdated`) and cap (`WorkerParticipantGate#refusal`) before the turn and after it.
562
562
  - **The gate**: `GuardrailWiring#participant_boundary` picks `Guardrails::PairBoundary` for a pair turn, else
563
563
  `Guardrails::ParticipantRefusal` (every call denied), by `TurnContext#participant_mode` (guardrails.md). Both are
564
564
  no-ops for the owner.
@@ -794,6 +794,7 @@ are in [architecture.md](../architecture.md)'s file table.
794
794
  | `tool_runner.rb`, `tool_response.rb`, `tool_row_fields.rb`, `row_refs.rb` | Per call; per batch; row fields; plugin row refs |
795
795
  | `tool_output_cut.rb`, `tool_output_files.rb` | The output cap's policies; an execute's saved whole output ([tool-output-limits.md](tool-output-limits.md)) |
796
796
  | `tools/tool_surface.rb`, `tools/registry.rb`, `tools/tool_index.rb`, `plugin/tool_spec.rb` | The turn's surface; the Registry; `find_tools` / `call_tool`; a checked plugin tool declaration |
797
+ | `tool_names.rb`, `session_command_catalog.rb`, `session_commands.rb` | Each builtin tool's name and result texts (`ToolNames`, no requires: the tool classes and the display read it); the session commands' names, built-ins' registry and class-level reads the clients require (`SessionCommandCatalog`, no tool); the runner a worker dispatches a command line to (`SessionCommands#run`, which includes the catalogue) |
797
798
  | `toolkit.rb`, `toolkit_command.rb`, `toolkit_binding.rb` | Toolkits; `/toolkit`; the Engine's toolkit seam (`#published`, `#apply!`) |
798
799
  | `empty_answer_retry.rb`, `prompt_warmup.rb` | The empty-answer and cut retry budget; the turn-end warm-up |
799
800
  | `system_prompt.rb`, `prompt_files.rb`, `model_notes.rb` | The system prompt; AGENTS.md and appended files; model notes |
@@ -163,6 +163,23 @@ the gate asks for it (on the LAN, this machine's loopback too). On a chi web the
163
163
  401 for a grant's cookie that no longer works clears the cookie, so that browser is the owner's again at its next
164
164
  request; on the LAN that browser gets the ended page and opens the owner's link again.
165
165
 
166
+ The gate reads one body, `POST /api/token`'s, through `traded_token`, under `TRADE_BODY_LIMIT` (a body of 4096
167
+ bytes or more is no token, 401). The page's `?token=` trade reads the query only (`req.GET`): Rack's `req.params`
168
+ would parse a urlencoded body into memory and a multipart one into temp files, before any check, so chi web reads
169
+ every query through `req.GET` (`spec/web/no_body_params_spec.rb` fails on a new `req.params` or `req.POST`). Past
170
+ the gate, every handler reads its body through `Web::RequestBody#request_body`, capped: 64 KB by default; a
171
+ participant's turn and an answer 1 MB (what the Bridge takes, `BRIDGE_BODY_LIMIT`); the owner's turn and new session
172
+ (`OWNER_TURN_BODY_LIMIT`) and a context push 16 MB; an image 20 MB, a text to render 64 KB, `/api/update` 16 KB,
173
+ push 8 KB, a stop's wait and the reload check 4 KB. Over its cap, by its Content-Length (nothing read) or by what
174
+ came (a chunked body: the cap + 1 read), the request gets `#route`'s one **413 `too_large`** ("a request body may be
175
+ up to 64 KB"), with `Connection: close`. Every 4xx (or 5xx) to a request that declared a body (Content-Length > 0 or
176
+ Transfer-Encoding) closes the connection the same way, whichever route or the gate answered it (the gate's 401, a
177
+ participant's 403/404, the image path's own 413 and 429): `Web::Server`'s `CloseOnConnectionClose` turns WEBrick's
178
+ keep-alive off, so it doesn't read the rest of the body before answering, and `LingerAfterAnswer` reads and drops at
179
+ most 4 MB (2 s) after the answer so the client reads it before the close. An unauthenticated big body holds a thread
180
+ at most those 2 s. A 2xx/3xx keeps the connection alive; a hijacked stream is left alone. The image path keeps its own rescue: a participant's
181
+ oversized upload is audited `too_large`, not `internal_error` (`SessionControl#image_upload_bytes`).
182
+
166
183
  Then `#route`, for each matching `ROUTES` row:
167
184
 
168
185
  1. A participant on a `/api/sessions/:id…` route whose id isn't their grant's session gets **404 `not_found`**, the
@@ -186,6 +203,7 @@ row answers another session's id 404, so a new route is covered without a new ex
186
203
  | `GET /` | participant | the main page (`index.html`) stamped for them (`App#participant_index_data`: their viewer, the grant's session and its title; [web-frontend.md](web-frontend.md#the-participants-page)); the page reads the rest through the show and the stream below |
187
204
  | `POST /api/token` | participant | trade a link's one-time code or a pasted token for the `chi_token` cookie (the token is not left in the page URL) |
188
205
  | `GET /api/sessions/:id/stream` | participant | the session's stream through `ParticipantStreamFilter` (only `from_seq` and `snapshot` reach the Bridge); it ends within a poll of a revoke or the expiry |
206
+ | `GET /api/sessions/:id/prompt_history` | participant | their own accepted messages in this session for ↑/↓, oldest first, redacted, `{entries}` ([A participant's prompt history](#a-participants-prompt-history)); the owner calling it: a plain 403 (their list is `GET /api/history`, `:owner`) |
189
207
  | `GET /api/sessions/:id/working_set` | participant | the working set's project files only (`ParticipantView.working_set`), with `running` |
190
208
  | `POST /api/sessions/:id/images` | participant | their upload ([Participant images](#participant-images)): refused at their cap, past their attempts or quota, a bmp/tiff/heic; the reply `{file, name, width, height}` |
191
209
  | `GET /api/sessions/:id/images/<name>` | participant | only an image they uploaded, `Cache-Control: no-store`; any other the 404 a missing file gets |
@@ -211,11 +229,11 @@ ran read-only may run with tool rights here. Whether a participant's turn runs i
211
229
  `ParticipantTurnMode.of(entry:, session:, now:)`: `:pair` (it runs), `:revoked` (no current entry: none, revoked,
212
230
  expired, or anything that isn't an entry), `:outdated` (an older chi's read-only invite, or a participant's Verify fresh
213
231
  child saved read-only) or `:not_invited` (no session, or the owner's own Verify fresh child). The worker
214
- (`#participant_refusal`: `:outdated` → `outdated`, the other two → `revoked`, no new reason on the wire) and the
232
+ (`WorkerParticipantGate#refusal`: `:outdated` → `outdated`, the other two → `revoked`, no new reason on the wire) and the
215
233
  guardrails (`GuardrailWiring#participant_turn_mode`: `:pair` → `PAIR`, else `REFUSED`) both read it; `Grant#state`
216
234
  and `Entry#outdated?` use its `invite_mode?`.
217
235
  - A grant without it (an older chi's read-only invite) is ended at the gate (`token_outdated`, above), and its
218
- `participants.json` entry is not active (`Participants::Entry#outdated?`): the worker's `#participant_refusal`
236
+ `participants.json` entry is not active (`Participants::Entry#outdated?`): the worker's `WorkerParticipantGate#refusal`
219
237
  refuses its turns with `outdated` (every Bridge and inbox-file turn, and every line the own-turn drain would merge,
220
238
  passes there: an older chi web still running and files queued before the upgrade are covered), and the system
221
239
  prompt's line and the terminal's count leave it out.
@@ -281,7 +299,8 @@ Refused before delivery, each audited:
281
299
  `deliver_turn` as `images:`; the turn's audit line counts them (`images`), accepted or refused by the worker.
282
300
 
283
301
  It goes out with that delivery and `pending_limit` = the grant's queue limit + 1 (the running one), never
284
- into the owner's prompt history. The Bridge counts the author's running and queued turns under its event lock and
302
+ into the owner's prompt history: an accepted one goes into their own ([A participant's prompt
303
+ history](#a-participants-prompt-history)). The Bridge counts the author's running and queued turns under its event lock and
285
304
  answers 429 `too_many_turns` past it; with no worker, their waiting input files are counted, and the new one
286
305
  written, under the session dir's `participants.lock` (`SessionManager.deliver_turn`), so two at once can't both
287
306
  pass. The ack is 202 with the worker's
@@ -305,6 +324,11 @@ worker checks their link (`participants.json`: revoked, expired, an older chi's)
305
324
  turn is dequeued (`:turn_dequeued`) and audited (`revoked`, `outdated`, `cap_reached`) instead of run, so a revoke also stops what they
306
325
  had queued; its settled record (`TurnCheckpoint.record_refused`: canceled, `cancel_reason` the reason) ends their
307
326
  wait on it at once, which `ParentReport` reads as status `refused`, exit 1.
327
+ Every one of these asks is one seat, `WorkerParticipantGate` (`worker_participant_gate.rb`, built in `Worker#start`):
328
+ `#refusal` for a queued turn as it starts, a line the drain would merge and the owner's Continue on a participant's
329
+ offer (`ContinueOffer`'s `participant_refused:`), `#turn_stop` for a running pair turn (`Engine#participant_stop`),
330
+ `#refuse` for the dequeue and audit, `#watch` for `:participants_changed`. It runs on the worker's loop thread only
331
+ (a turn runs there too) and takes no lock; `Worker#held_for_offer?` (read from Bridge threads too) is not in it.
308
332
 
309
333
  **The Verify gate.** A worker names `verify` (`VerifyAnchor::FEATURE`, in the Bridge's `FEATURES`) when it understands a
310
334
  Verify turn's anchor (`VerifyAnchor`, `{turn_id, quote}`: a UUID and a quote of 1 to 200 characters). A turn carrying an
@@ -388,12 +412,12 @@ and `ctx.turn_author` names it ([hooks](../hooks.md#participants-turns)).
388
412
  their $2.00 cap: their turns stop and are refused until you raise it (chi share cap ID p_… AMOUNT)." A turn stops
389
413
  mid-turn: before each
390
414
  generation (`KernelLoop::Services#generation_guard`, both loops) `Engine#guard_participant_spend` asks the worker's check
391
- (`Worker#participant_turn_stop`: `metrics.spend(author)` counts the running turn's finished generations) and, past
415
+ (`WorkerParticipantGate#turn_stop`: `metrics.spend(author)` counts the running turn's finished generations) and, past
392
416
  the cap, stops the turn on the plugins' stop path (`HookRoutes#stop_turn`: "stopped the turn: Alex reached their
393
417
  $2.00 cap"), with the owner's notice once per cap. A generation's cost is known only when it ends, so a pair turn
394
418
  can overshoot the cap by its last generation (and the side requests it caused); there is no projection of the
395
419
  next one. The same check stops a pair turn whose link ended mid-turn (revoked, expired, the session archived):
396
- "stopped the turn: Alex's link was revoked or expired" (`Worker::REVOKED_STOP`). The session-wide `cost-cap` bundle still applies, and its
420
+ "stopped the turn: Alex's link was revoked or expired" (`WorkerParticipantGate::REVOKED_STOP`). The session-wide `cost-cap` bundle still applies, and its
397
421
  question in a participant's turn goes to the owner.
398
422
 
399
423
  **Streams.** A participant's stream is filtered ([below](#what-a-participant-sees)), and it ends with their link:
@@ -447,7 +471,8 @@ context's fill, the speed, each turn's time and the working set's file names.
447
471
  Not tool output or arguments, thinking, approvals' and questions' content, memories (text or names), context notes,
448
472
  plugin steers, automatic and delegate input, cards, command output, the working set's memories and URLs, cost
449
473
  (but their own usage, as their grant's exposure shows it), tokens and cost per model, guardrail judgments,
450
- host paths or the owner's prompt history. Every read a participant reaches goes through one module,
474
+ host paths or the owner's prompt history (their own messages for ↑ come from their own list, redacted:
475
+ [A participant's prompt history](#a-participants-prompt-history)). Every read a participant reaches goes through one module,
451
476
  `Web::ParticipantView` (`lib/samagotchi/web/participant_view.rb`), whose every answer is a new hash built from named
452
477
  fields: a field added to an event later reaches nobody until it is named there.
453
478
 
@@ -627,7 +652,7 @@ owner's machine (`home`, the folders, `project-*`, `back-*`).
627
652
  - **The child is its requester's.** Its session file carries `verify_fresh: {author, mode, of, anchor}`
628
653
  (`VerifyFreshOrigin`), saved before its worker starts. `author` is the participant's (`p:<id>`), none for the
629
654
  owner. `mode` is `pair` (`Grants::PAIR_MODE`: every live grant's); a child an older chi saved with `review` is refused,
630
- never run (`VerifyFreshOrigin#pair?`, `Worker#participant_refusal` `outdated`). Every
655
+ never run (`VerifyFreshOrigin#pair?`, `WorkerParticipantGate#refusal` `outdated`). Every
631
656
  turn of a participant's child is theirs, whoever starts it (the owner typing into it, a continue, a reminder):
632
657
  `VerifyFreshOrigin#origin_for` sets the author in `Engine#begin_turn` and in the worker, so their boundary
633
658
  (`GuardrailWiring#begin_turn` reads the saved mode, never a lookup), their System 1 skip, their once-only asks to
@@ -646,7 +671,7 @@ owner's machine (`home`, the folders, `project-*`, `back-*`).
646
671
  card: fails closed.
647
672
  - **Spend.** The parent's `verify_fresh.jsonl` (one line per child: `child_id`, `of`, `author`, `at`) is the
648
673
  rollup's index: a participant's cap check in chi web (`#participant_saved_spend`), their usage line, and the
649
- worker's (`Worker#participant_spend`) add their fresh children's saved spend (`VerifyFresh.children_spend`); a
674
+ worker's cap check (`WorkerParticipantGate#refusal`, its spend) add their fresh children's saved spend (`VerifyFresh.children_spend`); a
650
675
  child's worker adds the parent's saved spend and its siblings'. A child's spend counts from its turns' ends, as
651
676
  a turn's does.
652
677
  - **The verdict lands on the card**, never in the parent's conversation: the child's worker writes each verdict
@@ -661,7 +686,8 @@ owner's machine (`home`, the folders, `project-*`, `back-*`).
661
686
  participant can't open it). No push
662
687
  for a fresh verdict yet (`Attention` pushes a verdict at a turn's end).
663
688
  - **The composer** is the owner's, with what is theirs (`participant_main.js`; [web-frontend.md](web-frontend.md#the-participants-page)):
664
- no `/` list or plugin pills, no ↑/↓ prompt history (the owner's `GET /api/history`), no model picker. Images go
689
+ no `/` list or plugin pills, no model picker; ↑/↓ walks their own messages in this session, never the owner's
690
+ `GET /api/history` ([A participant's prompt history](#a-participants-prompt-history)). Images go
665
691
  in as the owner's do (paste, drop, the image button), within their quota ([Participant images](#participant-images));
666
692
  a refused upload or send keeps the chips and toasts the server's words. While their own turn runs, a message goes in at its next step on a
667
693
  worker with `participant_steer` (Alt+Enter queues it); while anyone else's runs, it goes in as their own turn after
@@ -718,6 +744,31 @@ the token or its digest.
718
744
  the local chi web's LAN address when one runs (its `GET /api/info`), else `127.0.0.1` with a line saying it opens on
719
745
  this machine only.
720
746
 
747
+ ## A participant's prompt history
748
+
749
+ A participant's ↑/↓ in the composer walks their own messages in this session, as the owner's walks the owner's.
750
+
751
+ - **Recorded at accept.** `ParticipantAccess#participant_turn_result`'s accepted branch (beside its audit line) calls
752
+ `Web::ParticipantHistory#record_participant_prompt`: `ParticipantPrompts.append` under the principal's grant id
753
+ (never a body field: `author` and `client_id` are ignored, `history` counts only as the boolean `false`, an
754
+ image-only send), with the session's grants `Grants` still knows as the live ones. A send chi web refuses (a `!`/`/`
755
+ line, a cut, the cap, too many turns, bad images, a Revise of another's turn), times out on or fails to enqueue
756
+ records nothing. Recorded by design, because chi web accepted them (202), as the owner's `record_history`: a queued
757
+ turn the worker refuses at its start (the cap re-check, an outdated invite), a Revise overtaken at the stamp and a
758
+ queued turn they take back. A failed write never fails the send (`Log.warn`). The owner's `PromptHistory` is never
759
+ read or written for a participant.
760
+ - **Served to its grant only.** `GET /api/sessions/:id/prompt_history` (`:participant`, `:session`: another
761
+ session's id is the router's unknown session first) answers `{entries}` with `Cache-Control: no-store`:
762
+ `ParticipantPrompts.entries` for `principal(req).grant.id`, each through `Redact.text` with their viewer (the
763
+ grant's author, the session folder from `SessionHub#working_directory`, else the saved session's, and
764
+ `owner_secrets`), so a recalled message reads as their conversation shows it (`[redacted]`, a relative path,
765
+ `~`). No query or body is read; entries only (no grant id, name or time). The owner gets a plain 403
766
+ `not_permitted` with no audit line. The page asks for it with `own_prompt_history`
767
+ (`participant_history.js`; [web-frontend.md](web-frontend.md#the-viewer)).
768
+ - **Per invite, from now.** Lists are per grant: a new invite for the same person starts empty, and messages sent
769
+ before this landed aren't in it (no backfill). A swept grant's id reissued in the same session (about 1 in 2³²)
770
+ could inherit a list no append has pruned yet, as `participant_images.json` and `participants.json` today.
771
+
721
772
  ## Files in the session dir
722
773
 
723
774
  None is in the session JSON (chi web never saves that, and a worker would overwrite a field it added), and
@@ -747,6 +798,11 @@ invited to has none: its files stay byte for byte as they were.
747
798
  `images/`: no route serves it): `{images: [{file, grant_id, at}], attempts: {<grant id>: n}}`, which image files
748
799
  each grant uploaded and how many uploads each tried. Written whole (`AtomicFile`) under chi web's
749
800
  `@participant_images_mutex`. It goes with the session.
801
+ - **`participant_prompts.json`** (0600, `ParticipantPrompts`, chi web only, beside `participants.json`; served only
802
+ through `GET …/prompt_history`, to its grant, redacted): `{prompts: {<grant id>: [text, …]}}`, each grant's accepted
803
+ messages, oldest first, at most 100 of at most 16 KB each (a longer one isn't recorded); the lists of grants the
804
+ grants store no longer knows are pruned on an append; a file that doesn't read is never written over and reads as
805
+ none. Written whole (`AtomicFile`) under chi web's `@participant_prompts_mutex`. It goes with the session.
750
806
  - **`participants.lock`** (0600, empty): the lock a participant's turn file is counted and written under when no
751
807
  worker runs ([Turns](#turns)).
752
808
 
@@ -863,6 +919,8 @@ participant TUI in v1.
863
919
  older chi's unstamped or read-only message), and never merged into the owner's message.
864
920
  - The owner's input is never merged into a participant's running turn (the Bridge queues it, the drain takes only
865
921
  the participant's own lines): it runs as the owner's own turn after it.
922
+ - A participant's ↑ list is built from their grant's accepted sends only, keyed by the principal, and served only
923
+ to that grant, redacted; never the owner's prompt history or another participant's messages.
866
924
  - A participant stops only a turn they started, named by its id, which the worker compares under its lock.
867
925
  - A participant revises only their own answer with only their own turns after it, checked by chi web at the send and
868
926
  by the worker at the stamp (`ParticipantRevise`); their Revise never folds anyone else's turn.
@@ -199,7 +199,7 @@ with a "Machine-local" comment; the rest branch on `@access.remote?` (`SendComma
199
199
  | `sessions list`'s default project (`ProjectScope.root_for(Dir.pwd)`) | client | every project's; `--scope=project` needs `--cwd` (a folder there) |
200
200
  | `context`'s default session (`SAMAGOTCHI_PARENT_SESSION`, `ContextCommand#inside_session`) | client | no default: ids are required (`added_by` still reads it) |
201
201
  | A context URL's provider (`ContextProviders.resolve`) | client's bundles | server's bundles (`Remote#context_add_url`) |
202
- | UI-only slash commands (`SessionCommands.ui_only_entry`), `--image` ingest, note text (`SessionInbox.checked_text`), push text (`ContextSources.parse_output`) | client | client too (the server checks note and push text again) |
202
+ | UI-only slash commands (`SessionCommandCatalog.ui_only_entry`), `--image` ingest, note text (`SessionInbox.checked_text`), push text (`ContextSources.parse_output`) | client | client too (the server checks note and push text again) |
203
203
  | A remote attach's `--attach`/`--resume` id (`Session.resolve_id`), the leftover scratch check, the one-turn run's refusal (`OwnerLock::TUI_BUSY`) | client (bin/chi, `AttachLauncher.connect`) | server: `Remote#resolve`, then `POST …/wake`'s 409s |
204
204
  | A new attached session's `--toolkit`, `--set`, `--thinking`, `--llm-context*`, `--parent-answers`, `--model` | client (bin/chi) | server: `POST /api/sessions` with `idle: true` and `SetupWords`; its warnings printed as `send --new` prints them |
205
205
  | The status row's default model, the newest chi for the version line, what a parent may pick (exit 3) | client | server: the wake's `default_model`, `installed`, `parent_strategy` (the last read again from `GET …/worker` at report time) |
@@ -29,7 +29,7 @@ page. A factory dep a new version stops passing is the same hazard the other way
29
29
  out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
30
30
  until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
31
31
  `turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
32
- `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; it compares the turn's own cards and questions, dropping every entry CardStore attributes to another turn), `cards_offscreen.js` (the reload check's placer: `createCardsPlace`, `createBubbles` and `createQuestionCards` over a detached holder, every page hook inert - no stage, no scroll, no session id, no api, no storage - so a snapshot's cards land where a reload would put them without touching the page), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
32
+ `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `cards_offscreen.js` (the reload check's old placer, which nothing imports now: kept one release for a stale `app.js` that still imports it, then deleted), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
33
33
 
34
34
  ## One page, every viewer
35
35
 
@@ -54,6 +54,7 @@ their viewer (The viewer, below), their show and stream are filtered (`Web::Part
54
54
  | **Factory closures**: the `create*` factories (popovers, panels, views) | each component's own state: open-for, busy, error, its own fetched list | the factory | an `onChange` hook back into app.js, or a getter the factory reads at draw time |
55
55
  | **The history DOM** | the conversation as drawn (a running turn's reason bubble, `.bubble.said`, is live only: see A turn opened in the history): which turn a bubble belongs to (`data-turn-id`, `data-answer-turn`), what opens a turn (`TURN_PROMPT`, `bubbles.js`: a prompt or a wake's note, the same turns `Steer.turn_opening?` counts for a card's `turns_since`), an opening's id for a card's and the saved recap's stamp (`data-turn-id` on a prompt, `data-opening-id` on a wake's note or `/continue no`'s reason line; `card_stamps.js` places a snapshot's card after the stamped opening, `recap_stamp.js` the saved recap after the last turn it covers, each by its count (`turns_since`) only without one), kept command bubbles, which texts were shown, unnamed badges, folded answers and long prompts (`.folded`), Revise stamps (`data-revises` on a prompt; a Verify turn's `data-verify`) and the stacks' folded versions (`.stack-hidden`, `.stack-stub.open`); the switcher's version on view is `revise_stack.js`'s own (a copy `.stack-view` before the top answer, the top `.stack-swapped`; never stored) | `bubbles.js`, `cards_place.js`, `question_cards.js`, `turn_block.js`/`stage_view.js`, `answer_fold.js`, `revise_stack.js`, `stream_handlers.js` (a live `turn_completed`'s `revises` and `verify` onto its prompt) | read back as state: `turn_range.js turnElements` (one walker for a turn's elements), `keptCommandBubbles`, `seedSeenFromDom`, `nameUnnamedBadges`/`nameVerdictCards`, `answer_fold.js` and `revise_stack.js` (their observers decorate every path that fills `#history`; the stacks are `stacks()` of the stamps, read again on each change, never a store field), `history_reveal.js revealInHistory` (the one way a jump unfolds what hides its target) |
56
56
  | **A drawn turn** (`turn_drawings` of the full read) | every finished turn, as live drew it: `turnGroups` groups by the stamps only, a turn's stamped items (`drawn: <turn_id>`) one group, and `turnHistoryNodes` draws it by feeding its drawing's events to a live turn block offscreen (`turn_block.js drawnTurnNodes`: the block's own handlers, as the stage's), the stage's extras (a reminder, merged lines, a card that asks or warns) and end as live, then the answer, the merged lines and the steps' texts from their saved items (markdown, refs). Each of its top-level elements carries `data-drawn`: `cards_place.js` leaves that turn's in-turn CardStore entries (`of_turn`) to it, and a kept reminder bubble of that turn (`data-turn-id`) stays out after a resync. chi web sends a drawing for every finished turn (one made from its messages where live wrote none): `drawnGroup` pairs the record the end names (`end.record_id`, by place for a turn saved before turn ids), else by the turn's id, and the answer's `data-answer-turn` is the end's own `turn_id` only (a made-up id, `m…` or `…~N`, keys none: no Revise). Nothing is rebuilt from messages: an item that comes unstamped is a `plain` group drawn as a plain row of its text (its prompt or answer bubble, no steps), the running turn's as expected (`runningTurnId`, the show's `current_turn`: it has no line yet), any other a miss, marked `data-undrawn`, logged once per render (`console.warn`) and counted by the reload check (`undrawn`), never a throw; a drawing with no parts (a minimal line) draws its prompt, answer and end | chi web (the show) | `renderHistory`, the reload check's render |
57
+ | **The cards as data** (`card_registry.js`; app.js `cardRegistry`) | every question, continue offer and plugin card of the open session, keyed as `stage_waiting.js` keys them (`q:<id>`, `c:<id>`, `continue`): its kind and folded text (`card_kinds.js`), status (pending, answered, cancelled; resolved or dropped for the continue offer; asks or shown for a plugin card), `of_turn`, `opening_id`, step, `relayed_to` | `observeCards` around the stream handlers (outside the participant wrap: the page's handler first, then `apply`), so a read's replay feeds it too; `session_view.js renderSessionView` seeds it from the read right before the replay (`seed`: CardStore's listing, the pending question, the continue offer; it replaces), `forgetSession` resets it. Idempotent: a merge per key, a final status never back to pending, the first `of_turn`/`opening_id`/step kept, so seed then replay is what live holds. A question still pending at its turn's end is cancelled (the page cancels the card, no event comes) | an observer: nothing on the page draws from it; its one reader is the opt-in reload check (`reload_check.js`: this turn's entries against a registry seeded from a fresh read). `stage_cuts_parity.test.js` checks it against the stage's waiting cards at each cut, `card_registry.test.js` the events against each cut's seed and replay |
57
58
  | **localStorage** (`storage.js` `readStored`/`writeStored`, guarded) | per-browser choices only | the module that owns the choice | read at start (see Storage keys) |
58
59
  | **SSE** | see Streams | the server | events go into the DOM directly (a participant's through `participant_main.js wrapHandlers` first) |
59
60
 
@@ -246,7 +247,10 @@ gates are boot-time: a show's narrower `viewer` changes what `viewer.can` answer
246
247
  A participant's `can` (`Viewer::PARTICIPANT_CAPABILITIES`, in their show's `viewer` and on `<body>`) names
247
248
  capabilities of their own, not the owner's: `send` (the composer), `stop_own_turn` (Stop turn on a turn they
248
249
  started, `POST …/cancel` with its `turn_id`), `steer_own_turn` (a message during their own turn goes in at its next
249
- step, on a worker with `participant_steer`), `revise_own_turn` (Revise on the answer to their own message); and of the owner's only `working_set` and `images`, which their routes
250
+ step, on a worker with `participant_steer`), `revise_own_turn` (Revise on the answer to their own message),
251
+ `own_prompt_history` (↑/↓ over their own messages in this session, redacted: `GET …/prompt_history` through
252
+ `participant_history.js historyLoader`, never the owner's `/api/history`; the delivery line's "↑ history" hint takes
253
+ either); and of the owner's only `working_set` and `images`, which their routes
250
254
  serve filtered: the working set's project files ([participants.md](participants.md#the-main-pages-show)); their own
251
255
  uploads within their cap and quota, read back only by them ([participants.md](participants.md#participant-images)).
252
256
  Their messages carry their own images as refs (thumbnails) and anyone else's as a count, which `images.js
@@ -496,10 +500,11 @@ place that still waits (check-in's new title) patches its entry after those sett
496
500
  and summary, its order and docking kept; arrived again, not docked, as a warning or when its actions came back; with
497
501
  an older `stage_waiting.js` that has no `update`, an arrive in place), `turnEnded` the warn cards
498
502
  that leave, `session_view.js endTurnView`'s cancel of a question still pending goes through `onSettled`, and
499
- `emptySlots` resets it (a resync's and `workerGone`'s reset too). `stage_asking.js reconcileWaiting` settles nothing:
500
- a debug check at the end of `refresh`, on only with the perf probe or `<body data-stage-check="1">` (the e2e and the
501
- node tests), that warns "stage: waiting drift" for an entry whose card is gone or waits no more, or a waiting card
502
- with no entry.
503
+ `emptySlots` resets it (a resync's and `workerGone`'s reset too). Nothing on the page reads the slots back against
504
+ it: the tests do (`stage_cuts_parity.test.js`, after every event and at each cut: no entry without its waiting card in
505
+ the extras or the tail, no waiting card there without its entry; the e2e's stage check at each test's end, reading the
506
+ registry off the stage's node, `#turnStage.chiWaiting()`). `stage_asking.js reconcileWaiting` is a no-op kept one
507
+ release for a stale `stage_view.js` that still calls it.
503
508
  The registry's order is the stage's: blocking cards before the asking ones, arrival order within each, and `place`
504
509
  puts a blocking card before check-in's in the slot, so a live page and a reload agree whatever the replay's order. The
505
510
  asking form's card is the shown docked entry, the fold is the folded key (`stageCollapsed` compares keys); `opener`'s
data/docs/plugins.md CHANGED
@@ -1458,7 +1458,9 @@ that calls it, or for a real external bundle that does. No method on the chance
1458
1458
  `Samagotchi::Tools::ToolIndex.spec_tokens` (used by the mcp bundle).
1459
1459
  4. `Samagotchi::Tools::Execute::NAME`, `TIMEOUT_PREFIX`, `HANDED_OVER` and
1460
1460
  `Samagotchi::Tools::Execute.timeout_seconds`.
1461
- 5. `Samagotchi::Tools::TaskRuntime::TASKS_DIR` and `EXIT_CODE_FILENAME`.
1461
+ 5. `Samagotchi::TaskFiles::TASKS_DIR` and `EXIT_CODE_FILENAME` (require `samagotchi/task_files`). Their old names,
1462
+ `Samagotchi::Tools::TaskRuntime::TASKS_DIR` and `EXIT_CODE_FILENAME`, still work in this release and are removed
1463
+ in the next.
1462
1464
  6. `Samagotchi::AtomicFile.write`, `Samagotchi::Log.warn` /
1463
1465
  `Samagotchi::Log.debug`, `Samagotchi::Config.get`,
1464
1466
  `Samagotchi::VERSION`, `Samagotchi::CancellationController` (`new`, `cancel!`: what `cancel:` takes) and