samagotchi 0.156.0 → 0.157.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 (161) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -1
  3. data/bin/chi +1 -0
  4. data/docs/architecture.md +12 -7
  5. data/docs/bundles.md +3 -1
  6. data/docs/cli.md +9 -8
  7. data/docs/configuration.md +36 -4
  8. data/docs/guardrails.md +9 -5
  9. data/docs/hooks.md +11 -5
  10. data/docs/internals/bridge.md +83 -6
  11. data/docs/internals/bundles.md +28 -18
  12. data/docs/internals/context-telemetry.md +4 -3
  13. data/docs/internals/engine.md +16 -2
  14. data/docs/internals/participants.md +3 -2
  15. data/docs/internals/remote-sessions.md +5 -2
  16. data/docs/internals/web-frontend.md +3 -2
  17. data/docs/internals/working-set.md +1 -1
  18. data/docs/memory.md +13 -2
  19. data/docs/plugins.md +35 -2
  20. data/docs/sessions.md +9 -9
  21. data/docs/sub-agent.md +17 -2
  22. data/docs/testing.md +53 -2
  23. data/lib/samagotchi/answer_command.rb +2 -1
  24. data/lib/samagotchi/archive_store.rb +4 -3
  25. data/lib/samagotchi/bootstrap_command.rb +3 -2
  26. data/lib/samagotchi/bridge/card_places.rb +10 -4
  27. data/lib/samagotchi/bridge/card_store.rb +3 -0
  28. data/lib/samagotchi/bridge/turn_accumulator.rb +109 -9
  29. data/lib/samagotchi/bridge/turn_drawings.rb +265 -0
  30. data/lib/samagotchi/bridge.rb +31 -6
  31. data/lib/samagotchi/broadcast/recipients.rb +8 -8
  32. data/lib/samagotchi/broadcast/triage_model.rb +1 -1
  33. data/lib/samagotchi/bundle_command/check.rb +18 -0
  34. data/lib/samagotchi/bundle_command/try/sandbox.rb +1 -1
  35. data/lib/samagotchi/bundle_command/try/trace.rb +1 -1
  36. data/lib/samagotchi/bundle_command.rb +5 -2
  37. data/lib/samagotchi/bundles/known-names/manifest.yml +4 -7
  38. data/lib/samagotchi/bundles/known-names/{hooks/known_names.rb → plugin.rb} +17 -0
  39. data/lib/samagotchi/bundles/source-links/manifest.yml +4 -7
  40. data/lib/samagotchi/bundles/source-links/{hooks/source_links.rb → plugin.rb} +23 -4
  41. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  42. data/lib/samagotchi/bundles/system/memory_guide.md +1 -1
  43. data/lib/samagotchi/child_move.rb +6 -6
  44. data/lib/samagotchi/child_reports.rb +2 -2
  45. data/lib/samagotchi/children_status.rb +15 -21
  46. data/lib/samagotchi/cli/parent_wait.rb +8 -22
  47. data/lib/samagotchi/config.rb +3 -0
  48. data/lib/samagotchi/context_sources.rb +5 -4
  49. data/lib/samagotchi/context_window.rb +9 -12
  50. data/lib/samagotchi/effective_model.rb +57 -22
  51. data/lib/samagotchi/engine/plugins.rb +1 -1
  52. data/lib/samagotchi/engine/recap.rb +8 -4
  53. data/lib/samagotchi/engine.rb +29 -3
  54. data/lib/samagotchi/events.rb +3 -2
  55. data/lib/samagotchi/extension_load.rb +6 -3
  56. data/lib/samagotchi/guardrails_command.rb +1 -1
  57. data/lib/samagotchi/host_address.rb +52 -0
  58. data/lib/samagotchi/host_registry.rb +57 -45
  59. data/lib/samagotchi/kernel_loop.rb +7 -3
  60. data/lib/samagotchi/llm/chat_loop.rb +6 -3
  61. data/lib/samagotchi/llm_context_strategy.rb +27 -63
  62. data/lib/samagotchi/memory_bundle/asset_installer.rb +71 -76
  63. data/lib/samagotchi/memory_bundle/builder.rb +2 -1
  64. data/lib/samagotchi/memory_bundle/file_actions.rb +193 -0
  65. data/lib/samagotchi/memory_bundle/file_digest.rb +13 -0
  66. data/lib/samagotchi/memory_bundle/file_state.rb +152 -0
  67. data/lib/samagotchi/memory_bundle/installed_copy.rb +2 -1
  68. data/lib/samagotchi/memory_bundle/installed_manifest.rb +8 -1
  69. data/lib/samagotchi/memory_bundle/installer.rb +185 -169
  70. data/lib/samagotchi/memory_bundle/manifest.rb +14 -4
  71. data/lib/samagotchi/memory_bundle/merger.rb +69 -65
  72. data/lib/samagotchi/memory_bundle/plugin_ref.rb +6 -5
  73. data/lib/samagotchi/memory_bundle/profile.rb +5 -5
  74. data/lib/samagotchi/memory_bundle/provenance.rb +15 -1
  75. data/lib/samagotchi/memory_bundle/remerge.rb +25 -12
  76. data/lib/samagotchi/memory_bundle/shipped_update.rb +51 -6
  77. data/lib/samagotchi/memory_bundle/status.rb +14 -20
  78. data/lib/samagotchi/memory_bundle/system_bundle.rb +24 -6
  79. data/lib/samagotchi/memory_bundle/trash.rb +23 -8
  80. data/lib/samagotchi/memory_bundle/uninstaller.rb +16 -11
  81. data/lib/samagotchi/memory_usage.rb +1 -1
  82. data/lib/samagotchi/model_lookup.rb +75 -0
  83. data/lib/samagotchi/model_profile.rb +1 -0
  84. data/lib/samagotchi/models_command.rb +1 -1
  85. data/lib/samagotchi/note_command.rb +1 -1
  86. data/lib/samagotchi/participant_mode.rb +2 -1
  87. data/lib/samagotchi/plugin/api.rb +41 -6
  88. data/lib/samagotchi/plugin/loader.rb +33 -10
  89. data/lib/samagotchi/plugin/sessions.rb +1 -1
  90. data/lib/samagotchi/reasoning_history.rb +14 -20
  91. data/lib/samagotchi/recap_place.rb +27 -0
  92. data/lib/samagotchi/reply_wait/liveness.rb +38 -0
  93. data/lib/samagotchi/reply_wait/poll.rb +44 -15
  94. data/lib/samagotchi/reply_wait/target.rb +113 -0
  95. data/lib/samagotchi/reply_wait.rb +22 -2
  96. data/lib/samagotchi/sampling_settings.rb +9 -16
  97. data/lib/samagotchi/self_report.rb +34 -35
  98. data/lib/samagotchi/send_command.rb +17 -23
  99. data/lib/samagotchi/session.rb +321 -439
  100. data/lib/samagotchi/session_access/local.rb +5 -6
  101. data/lib/samagotchi/session_access/remote.rb +5 -3
  102. data/lib/samagotchi/session_field.rb +133 -0
  103. data/lib/samagotchi/session_inbox.rb +49 -1
  104. data/lib/samagotchi/session_manager/emptiness.rb +2 -1
  105. data/lib/samagotchi/session_manager/listing.rb +29 -100
  106. data/lib/samagotchi/session_manager.rb +2 -1
  107. data/lib/samagotchi/session_metrics.rb +7 -4
  108. data/lib/samagotchi/session_paths.rb +57 -0
  109. data/lib/samagotchi/session_retention.rb +2 -2
  110. data/lib/samagotchi/session_row.rb +200 -0
  111. data/lib/samagotchi/session_setup.rb +15 -12
  112. data/lib/samagotchi/sessions_command.rb +11 -129
  113. data/lib/samagotchi/steer_cut_after.rb +7 -14
  114. data/lib/samagotchi/terminal_ui/attached_loop.rb +6 -26
  115. data/lib/samagotchi/terminal_ui/join_replay.rb +86 -8
  116. data/lib/samagotchi/terminal_ui/local_link.rb +2 -2
  117. data/lib/samagotchi/terminal_ui.rb +3 -1
  118. data/lib/samagotchi/testing/install.rb +2 -1
  119. data/lib/samagotchi/thinking.rb +16 -21
  120. data/lib/samagotchi/tool_response.rb +5 -3
  121. data/lib/samagotchi/tool_runner.rb +18 -1
  122. data/lib/samagotchi/tools/delegate.rb +48 -43
  123. data/lib/samagotchi/tools/delegate_relay.rb +5 -5
  124. data/lib/samagotchi/tools/delegate_result.rb +1 -1
  125. data/lib/samagotchi/tools/delegate_wait.rb +41 -17
  126. data/lib/samagotchi/tools/list_sessions.rb +7 -7
  127. data/lib/samagotchi/update_command.rb +11 -7
  128. data/lib/samagotchi/verify_fresh.rb +7 -11
  129. data/lib/samagotchi/version.rb +1 -1
  130. data/lib/samagotchi/vision_support.rb +11 -14
  131. data/lib/samagotchi/web/app.rb +31 -21
  132. data/lib/samagotchi/web/message_display.rb +57 -7
  133. data/lib/samagotchi/web/participant_access.rb +1 -1
  134. data/lib/samagotchi/web/public/activity.js +16 -7
  135. data/lib/samagotchi/web/public/app.js +29 -8
  136. data/lib/samagotchi/web/public/bubbles.js +8 -3
  137. data/lib/samagotchi/web/public/cards_place.js +15 -0
  138. data/lib/samagotchi/web/public/commands.js +5 -1
  139. data/lib/samagotchi/web/public/data.js +4 -2
  140. data/lib/samagotchi/web/public/history_shape.js +220 -0
  141. data/lib/samagotchi/web/public/recap_stamp.js +17 -0
  142. data/lib/samagotchi/web/public/reload_check.js +71 -0
  143. data/lib/samagotchi/web/public/stage_model.js +7 -5
  144. data/lib/samagotchi/web/public/stage_view.js +7 -3
  145. data/lib/samagotchi/web/public/stream_handlers.js +8 -2
  146. data/lib/samagotchi/web/public/timing.js +43 -2
  147. data/lib/samagotchi/web/public/turn_block.js +215 -30
  148. data/lib/samagotchi/web/public/turn_drawing.js +43 -0
  149. data/lib/samagotchi/web/public/turn_events.js +10 -1
  150. data/lib/samagotchi/web/public/turn_pieces.js +29 -0
  151. data/lib/samagotchi/web/reload_check_route.rb +95 -0
  152. data/lib/samagotchi/web/server.rb +4 -2
  153. data/lib/samagotchi/web/session_access_routes.rb +3 -3
  154. data/lib/samagotchi/web/session_control.rb +1 -1
  155. data/lib/samagotchi/web/session_hub.rb +9 -17
  156. data/lib/samagotchi/web/session_show.rb +64 -2
  157. data/lib/samagotchi/web/session_summary.rb +36 -24
  158. data/lib/samagotchi/worker.rb +28 -5
  159. data/lib/samagotchi/worker_link.rb +3 -0
  160. metadata +20 -4
  161. data/lib/samagotchi/send_command/wait_target.rb +0 -85
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e545b9da4004e996e2cdee4f53d2cf0a181a47b695fbcb18ca1037e77da6b1cb
4
- data.tar.gz: 10cb3b94093ab0f0e7d285a2f405577be8fc61f26029a005754a078875d8ebdc
3
+ metadata.gz: e6e6add2f9511492180ba39e11ebbcd9da6a703e5325facfc9ddc24bd22bc2eb
4
+ data.tar.gz: e426d754c3306c361fe54d1fde2475502e3121b2ab1a5caecad92712165056e1
5
5
  SHA512:
6
- metadata.gz: f20b956f443a5a04680d2a7a162e3a9d44f9b8a66d0855f2827421420a7f8a1053ad01769ff140c442fded2e6cdf58b41f0b37f6a22b7849fcb463d5fdb2b22e
7
- data.tar.gz: a08049e4ab152265163ea53327655064a1c2415b19c695e03dd21d3b01488453824cb59451fb333618ed1aefc334e97b10b4780cfdee02dd916853e37069858a
6
+ metadata.gz: a0026bf97c1ef84a78f181283c712490f1961972d49c10e2559fe29d2047d599223837c328a96b15aa382208d47f5d78a723842b575a624bfa992b71130a6082
7
+ data.tar.gz: 0f6e09c9abd81b9e218677b47373215a91788b735fb7c515d4ea72b563d9875ea836438a4b1b019ddf4d480418954363dcbe0bd01b23a545a59a864484f6f437
data/CHANGELOG.md CHANGED
@@ -8,6 +8,48 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.157.0] - 2026-11-08
12
+
13
+ ### Added
14
+
15
+ - `web.reload_check` (off by default): chi web checks each finished turn against a reload of it and logs `reload_mismatch` with the kinds that differed and the known divergences that explain them (no content).
16
+ - A bundle's plugin can guard tool calls fail-closed: `chi.on(:before_tool_call, on_error: :fail_closed)` denies the call its block raised on, and a plugin its manifest marks `required: true` (under `plugin:`) that fails to load (an edited file, an unmet `requires_chi`, a raise) makes chi deny every tool call until it is fixed, as a fail-closed bundle hook does. `chi bundle check` warns about a fail-closed hook whose plugin isn't marked required (docs/plugins.md).
17
+
18
+ ### Changed
19
+
20
+ - `/llm-context`, `/stats` and the web's LLM context chip name where a value came from as the other settings do: `session` and `hosts.NAME` (were `the session` and `hosts entry 'NAME'`).
21
+ - `chi sessions list` prints one line wherever it runs: the `--live`, `--cwd` and `--format text` listings and `chi --remote NAME sessions list` show the plain list's state (`idle`, not `live`) and description (no folder prefix), and the plain list's footer. The plain list's `ctx N%` now rounds as the picker and chi web round it (it could read 1% apart).
22
+ - A delegating parent's wait says `worker_gone` 5 s after a child's worker dies (was 15 s); a child whose worker never starts is reported `worker_gone` ("its worker did not start") after the 30 s boot limit (or the wait's timeout, if shorter: then the child shows as `running`, as for any wait that timed out).
23
+ - In chi web, a long tool output's hover shows the same cut live as after a reload (the first 2000 characters of a file read, the start and end of other output).
24
+ - A turn nobody typed (a reminder, an attached context change, a finished task, a delegate report) has an id of its own, `wake-` and 16 hex digits: `chi send --wait --format json` names it as the `turn_id`, and the `--turn` hints carry it.
25
+ - `chi send --wait -m` to a session left running by a worker that died names the message's own id as the `turn_id` in `--format json`, where it named the running turn's.
26
+ - `chi bundle install` of a bundle already installed from a source that moved on now takes the new text of each memory you never edited, as `chi bundle upgrade` would, and records the new version; a memory you edited is still kept (`--force` or `chi bundle upgrade` brings the bundle's changes).
27
+ - The known-names and source-links bundles hook through their plugin (known-names 0.2.0, source-links 0.7.0); `chi update` installs them. Nothing changes in what they do.
28
+
29
+ ### Fixed
30
+
31
+ - A `delegate` follow-up that the child's ending turn didn't take gets its own turn's reply, not the ended turn's.
32
+ - `chi send --wait` with no message on a wake turn (a reminder, a context change, a task's finish, a delegate report) names its `turn_id`, ends `canceled` (`worker_stopped`) when its worker dies in it, and `--turn` waits for it.
33
+ - A message or a delegate follow-up merged into a running turn as a steer waits for that turn's reply or end, which the worker now records, not for the session's next reply (a newer turn's could answer for it).
34
+ - `chi bundle uninstall` asks for `--force` before taking a memory you edited that has no base copy (chi compares it with the checksum its install recorded; with neither, it counts as edited), as it does for any edited file; it used to move it to the trash without asking.
35
+ - `chi bundle status` says `modified` for an edited memory that has no base copy; it said `ok` while the next upgrade left the file behind.
36
+ - `chi update`'s plan names every edited hook, rule, plugin file and script it replaces or removes, as its `Copied to the trash first` line does; it left out edited scripts and hooks installed with no recorded sha, and its row now says `a copy goes to the trash first` instead of `it wasn't loading`.
37
+ - `chi bundle install --dry-run` and `chi bundle upgrade --dry-run` report hooks, rules, the plugin and scripts as the real run does (`Would update`, `Would install`, `Up to date`); a changed hook showed as skipped, an unchanged rule or plugin as would install, and scripts not at all.
38
+ - `chi bundle install core --dry-run` (a profile's dry run) no longer names a hook it would replace as your own kept file.
39
+ - `chi bundle upgrade --dry-run` lists a memory that already has the bundle's text as up to date, as the upgrade itself does; it listed it as skipped.
40
+ - `chi bundle upgrade` (and `chi update`'s plan) leaves behind a memory that `chi bundle status` calls `modified` but whose base copy equals it, as it does any edit it can't merge; it replaced the file with the bundle's text and kept no copy.
41
+ - `chi bundle upgrade` (and `chi update`'s plan) takes the bundle's new text for a memory you never edited that has no base copy (chi compares it with the checksum its install recorded), as for any unedited memory; it left the file behind as a conflict while `chi bundle status` called it `ok`.
42
+ - A bundle memory whose bytes don't match the manifest's `files:` sha now warns `Checksum mismatch` when `chi bundle upgrade` (or a re-install from a source that moved on) brings its new text or merges it into your edit, as a first install does: a bad download warns on an upgrade too. A `--dry-run` checks the bundle's file it would write, a memory or a hook, so it warns as the real run does and no longer blames a memory you edited (`install --force --dry-run`) or the hook an upgrade would replace. `chi update` and `chi bootstrap` show these warnings on the bundle's row (a system bundle install, update or restore, and a shipped bundle's update); they dropped them.
43
+ - A system bundle memory chi puts back after you deleted it is checked against the manifest's `files:` sha too, and warns `Checksum mismatch` when its bytes differ, as an installed one does.
44
+ - A context window given with `--context-window-tokens` to a one-shot run (`-p … --non-interactive`) is named `cli`, not `config`, where its source shows: the debug log, and chi web's context tooltip for that session.
45
+ - A tool row's duration is the same live, after a reload and in the attached terminal (each timed the call with its own clock).
46
+ - chi web draws a finished turn after a reload or a reconnect exactly as it drew it live: the empty answer's "asking again" row stays in its step, a failed turn keeps its last step, a card the turn showed comes back where it was, and the reminders that went into a turn are shown. Turns from before this release, or run by a worker not yet restarted, show as before.
47
+ - `chi --attach` shows the last turn's tool rows as they ran (status, duration, retries).
48
+ - A saved recap is placed after the turn it covers, by that turn's id, where counting turns could put it a turn off (after a check-in, for one).
49
+ - In chi web, a turn that fails after its tool steps shows the same time on its timing line live as after a reload (the turn record's, as a canceled turn does).
50
+
51
+ Update with `chi update` (known-names 0.2.0, source-links 0.7.0).
52
+
11
53
  ## [0.156.0] - 2026-11-08
12
54
 
13
55
  ### Changed
@@ -5798,7 +5840,8 @@ and long-lived sessions.
5798
5840
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
5799
5841
  hotkey panel that send selected text or the clipboard to your sessions.
5800
5842
 
5801
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.156.0...HEAD
5843
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.157.0...HEAD
5844
+ [0.157.0]: https://github.com/dm1try/samagotchi/compare/v0.156.0...v0.157.0
5802
5845
  [0.156.0]: https://github.com/dm1try/samagotchi/compare/v0.155.0...v0.156.0
5803
5846
  [0.155.0]: https://github.com/dm1try/samagotchi/compare/v0.154.1...v0.155.0
5804
5847
  [0.154.1]: https://github.com/dm1try/samagotchi/compare/v0.154.0...v0.154.1
data/bin/chi CHANGED
@@ -263,6 +263,7 @@ if options[:web]
263
263
  exit Samagotchi::Web::Server.launch(port: port, scope: options[:scope] || "project", open_browser: options[:web_open],
264
264
  markdown: markdown, new_token: options[:new_token], tunnel: options[:tunnel],
265
265
  working_set: Samagotchi::Config.get("web.working_set"),
266
+ reload_check: Samagotchi::Config.get("web.reload_check"),
266
267
  annotate_presets: Samagotchi::Config.get("web.annotate_presets"),
267
268
  editor: Samagotchi::Config.get("web.editor"),
268
269
  start_dir: options[:start_dir] || Samagotchi::Config.get("web.start_dir"),
data/docs/architecture.md CHANGED
@@ -428,14 +428,15 @@ each `<id>/` folder (recap.json, bridge.json, the stopped and archived markers),
428
428
  moved through `Session.summary_from_file`. Liveness is probed, since a killed owner leaves no
429
429
  file trace: the owner lock every tick for the sessions the projection believes owned, and every
430
430
  session every 10 s, so a `kill -9` shows within a second. The summary (`Web::SessionSummary`,
431
- shared with `/api/sessions` and the session view) carries `owner`, `project_root` and
431
+ shared with `/api/sessions` and the session view; built on the session's `SessionRow`, the one row every list
432
+ reads, so the page, `chi sessions list` and `/children` agree on status, liveness and a waiting question) carries `owner`, `project_root` and
432
433
  `bridge_up` (`WorkerLink` answers Live: a worker holds the lock and its sidecar names its pid; the page attaches its stream on it), and
433
434
  from that sidecar `worker_version` (the chi the worker runs) and `worker_features`
434
435
  (`Bridge::FEATURES`, what a client may ask of it beyond the routes: `restart`, `task_stop`, `reparent`, `unqueue`,
435
436
  `delivery`, a worker that queues a message for after the turn; `SessionManager.deliver_turn` and
436
437
  the attached TUI refuse a queue to a worker without it, which would steer; `turn_ids`, a worker whose running
437
438
  turn's mark, continue turn and Stop carry the turn's `enqueued_id`, which `chi answer`, `chi send --wait` with no
438
- message and `delegate_result` rely on through `ReplyWait.own_turn`). A worker's Bridge snapshot
439
+ message and `delegate_result` rely on through `ReplyWait.own_turn` (a wake or reminder turn has one too, worker-minted `wake-…`; a steer's merge is recorded in `input/merged/`, read by `ReplyWait::Poll#follow_merge`); every wait's binding is one `ReplyWait::Target`, built by its caller's constructor). A worker's Bridge snapshot
439
440
  names its `chi_version` too.
440
441
  `POST/DELETE /api/sessions` and `/stop` rescan the session before answering (`SessionHub#touch`).
441
442
  `GET /api/sessions` is the hub's projection too (its sort, paging and total). `Server` always builds
@@ -457,7 +458,7 @@ model: [internals/remote-sessions.md](internals/remote-sessions.md).
457
458
  | Route | Permission | Body / params | Answer | Refusals |
458
459
  |---|---|---|---|---|
459
460
  | `GET /api/sessions/resolve?id=` | owner | an id or a unique prefix | 200 `{id}` | 404 `not_found`; 400 `ambiguous_id` with `ids` |
460
- | `GET /api/sessions/summaries` | owner | `dir` (a folder: its project; none: every project), `cwd`, `live=1`, `archived=1`, `tests=0`, `sort`, `order`, `limit` | 200: the rows `chi sessions list` prints (`SessionManager.session_summaries`: `status`, `live`, `busy`, `owner`, `recap`, `ctx_pct`, `waiting`, `waiting_id`, `title`, `preview`, …) | 400 `invalid_dir`, `invalid_cwd` |
461
+ | `GET /api/sessions/summaries` | owner | `dir` (a folder: its project; none: every project), `cwd`, `live=1`, `archived=1`, `tests=0`, `sort`, `order`, `limit` | 200: the rows `chi sessions list` prints (`SessionRow#to_summary_h`, 28 keys in a fixed order: `status`, `live`, `busy`, `owner`, `recap`, `ctx_pct`, `waiting`, `waiting_id`, `title`, `preview`, …) | 400 `invalid_dir`, `invalid_cwd` |
461
462
  | `GET /api/projects?dir=` | owner | optional page-scope folder | 200: project rows (`Web::ProjectList`: the hub's projects plus the start project) with counts, roots, default/current marks; no `dir`: no current project | 400 `invalid_dir`; 503 `no_hub` |
462
463
  | `POST /api/sessions` (more fields) | owner | `toolkit`, `tools`, `no_tools`, `parent_answers`; `client_id` (`cli:send`/`cli:answer`: the first line is checked as chi send checks it); `check_vision: true` (images follow) | 201 adds `model_warning`, `parent_answers_warning` (a level looser than config.yml's, capped) and `first_turn_id` (the id the prompt it starts with gets for its turn; null for an `idle` create) | 400 `invalid_toolkit`, `invalid_parent_answers`, `invalid_continues` (beside `continues`); 403 `parent_answers_refused`, `parent_continue_refused`; 422 `no_vision` |
463
464
  | `POST /api/sessions/:id/turn` (more fields) | owner | `client_id` as above; `check_vision: true` with `images` | as before | 403 `parent_answers_refused`, `parent_continue_refused`; 422 `no_vision` |
@@ -509,8 +510,9 @@ every lookup goes through `Session.resolve!` (an id or a unique prefix), and eve
509
510
 
510
511
  A model ref (`--model`, `/model`, `default.model`, an alias's target) is parsed
511
512
  by one pure resolver, `ModelRef.parse` (host prefix, alias), given the configured
512
- hosts and aliases; `HostRegistry` routes a name that names no host (its model
513
- index after `/models`) and builds the `ModelTarget`.
513
+ hosts and aliases; `HostRegistry` (one per process for commands and chi web:
514
+ `HostRegistry.current`) routes a name that names no host (its model index after
515
+ `/models`) and builds the `ModelTarget`.
514
516
 
515
517
  Engine picks the loop from the effective model's host: `EffectiveModel.of` resolves it (`HostRegistry#resolve`)
516
518
  on every read, never kept, since config.yml and a model listing can move it without a `/model`
@@ -618,6 +620,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
618
620
  | 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. |
619
621
  | 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, hooks and plugins. |
620
622
  | Bundle authoring | `bundle_command.rb` (`BundleCommand`), `bundle_command/{scaffold,check,test_run}.rb`, `bundle_command/try/{run,sandbox,trace}.rb`, `testing.rb` + `testing/` (the test kit) | `chi bundle new`, `check`, `test` and `try`, and the kit a bundle's tests load it with ([bundle-authoring.md](bundle-authoring.md), [internals/bundles.md](internals/bundles.md)). |
623
+ | Session file | `session.rb` (`Session`, `Session::FIELDS`), `session_field.rb` (`SessionField`), `session_paths.rb` (`SessionPaths`), `session_setup.rb` (`SessionSetup`) | A session's `<uuid>.json`: one `SessionField` row per key (default, cast, what the file gets; the codec on its type), from which `Session.new`, `.from_h` and `#to_h` are built; `SessionPaths` is where the file and the session's dir are and the id rule, a leaf `Session` extends (so `ArchiveStore`, `ContextSources` and `ParticipantMode` name no `Session`); `SessionSetup` the settings a fork and a continue carry, applied by member name. See [sessions.md](sessions.md#session-file). |
621
624
  | Session config (`--set`) | `session_config.rb` (`SessionConfig`, `SessionConfig::Settings`) | A session's own settings as one value (`Session#settings`, `SessionSetup#settings`): `core`, the `--set KEY=VALUE` values of the core keys marked `session: true` (`Config::Entry`), typed by `Config.coerce!` and read first through `Config.get(key, session:)` (`RecapSetup`; `Engine#session=` rebuilds the recap job, `IdleScheduler#replace_job`), file key `config_settings`; `bundles`, the `--set BUNDLE.KEY=VALUE` values, checked against the manifest's `session_settings:`, laid over `bundles: <name>:` in `ctx.settings` ([plugins.md](plugins.md)), file key `bundle_settings`. `SessionConfig.clash` refuses a bundle setting named like a core one (install, `chi bundle check`). See [configuration.md](configuration.md#per-session-settings). |
622
625
  | Plugin API | `plugin/api.rb` (`Plugin::Api`), `plugin/tool_spec.rb` (`Plugin::ToolSpec`: a checked tool declaration, how it is registered), `plugin/loader.rb`, `plugin/context.rb` (`ctx`), `plugin/http.rb` + `plugin/http_transport.rb` (`ctx.http`), `plugin/card.rb` (`Plugin::Card`) | What a bundle's plugin registers: tools, commands, annotation actions, hooks, services, toolkits, peer sources; what its handlers get as `ctx` ([plugins.md](plugins.md)). |
623
626
  | Peer bundles' base | `plugin/peer.rb` (`Plugin::Peer`) | What claude-peer and codex-peer share (the send tool, the command, the cards, payloads); each bundle's subclass sets its strings and transport ([bundles.md](bundles.md#the-claude-peer-bundle)). |
@@ -634,7 +637,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
634
637
  | LLM context strategies | `llm_context_strategy.rb`, `llm_context_view.rb`, `llm_context_stale.rb`, `llm_context_forget.rb` | What a request sends of the history (none, stale, forget) ([internals/llm-context-forget.md](internals/llm-context-forget.md)). |
635
638
  | Session chains | `session_continue.rb` (`SessionContinue`), `session_chain.rb` (`SessionChain`) | A session that continues an earlier one. `SessionChain.opener_for` gives the text web `continue →` prefills in the new link: the previous link's own first typed message when that link continues one itself, else nil (the 201's `opener`; not saved) ([sessions.md](sessions.md)). |
636
639
  | Review sessions | `review_start.rb` (`ReviewStart`), `session_review.rb` (`SessionReview`, the session's `review` field), `review_command.rb` (`ReviewCommand`, `chi review`), `review_apply.rb` (`ReviewApply`) | A session made to be shared: idle, its subjects project files checked by `Guardrails::ReviewPaths`, a fork of a working session from its recap (`--from`); Apply quotes a participant's review turn into the owner's composer ([sessions.md](sessions.md#review-sessions), [internals/participants.md](internals/participants.md)). |
637
- | chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue, a review fork), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions, prefs, test and presence), `web/block_renderer_routes.rb` (`Web::BlockRendererRoutes`: `GET /api/block_renderers` and one renderer's file, [internals/block-renderers.md](internals/block-renderers.md)) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. |
640
+ | chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue, a review fork), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions, prefs, test and presence), `web/block_renderer_routes.rb` (`Web::BlockRendererRoutes`: `GET /api/block_renderers` and one renderer's file, [internals/block-renderers.md](internals/block-renderers.md)), `web/reload_check_route.rb` (`Web::ReloadCheckRoute`: `POST /api/sessions/:id/reload_check`, the opt-in `web.reload_check`'s counts from the page's `reload_check.js`, 204 and one `reload_checked` log line, with `reload_mismatch`, its `kinds`, `excused` (ACCEPTED ids) and `explained` when the turn read otherwise after a reload; the worker's version is chi web's own view, its sidecar) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. |
638
641
  | Web Push | `web/push.rb` (`Web::Push`: `Runtime`, `preflight!`, the `web.push.*` settings), `web/push/crypto.rb` (`Push::Crypto`: RFC 8291 aes128gcm, RFC 8292 VAPID), `web/push/store.rb` (`Push::Store`, `Store::Sub`: `web-push/vapid.pem`, `subscriptions.json`), `web/push/client.rb` (`Push::Client`, `Client::Result`), `web/push/attention.rb` (`Push::Attention`: notify.js's rules in Ruby, shared cases in `spec/fixtures/attention_cases.json`), `web/push/presence.rb` (`Push::Presence`: the pages' "in front" reports), `web/push/notifier.rb` (`Push::Notifier`, a hub subscriber with a sender thread), `web/push_routes.rb` (`Web::PushRoutes`), `private_files.rb` (`PrivateFiles`, shared with the grants), `public/sw.js`, `public/push.js`, `public/manifest.webmanifest` | chi web pushes what the tab notifies for (approvals, questions, step-limit questions, cards, failed turns; done turns to a device that asks) to the owner's Home Screen app over an https public URL: the Notifier turns the hub's new attentions into show pushes after a hold, unless a chi web page is in front, at most 30 an hour, with one retry and a restart catch-up (`sent.json`) (each carries the keys still open, and the badge; no close push: every push shows a notification); the bell (`notifications.js`) subscribes the device, and the service worker and the page close the answered ones. See [internals/web-push.md](internals/web-push.md). |
639
642
  | chi web's updates | `web/update_check.rb` (`Web::UpdateCheck`), `web/update_ops.rb` (`Web::UpdateOps`), `web/auto_update.rb` (`Web::AutoUpdate`) | The RubyGems checker and its `update_check.json`; the install, worker-restart and chi-web-restart operations (one at a time) the owner's routes and AutoUpdate share; `update.auto: install`'s thread (install when no turn runs, then idle workers and chi web). See [configuration](configuration.md#unattended-updates-updateauto). |
640
643
  | Behind an auth proxy | `web/public_url.rb` (`Web::PublicUrl`: `web.public_url`, `web.proxy.identity_header`, `web.proxy.owner`), `web/proxy_gate.rb` (`Web::ProxyGate`, mixed into App; `RawHeaderNames`, prepended to WEBrick's request by `Web::Server`), `web/link_codes.rb` (`Web::LinkCodes`: the links' one-time codes), `proxy_trace.rb` (`ProxyTrace`), `web/public/token_fragment.js`, `web/public/auth_lost.js`, `web/tunnel.rb` + `web/tunnel/tailscale.rb` (`Web::Tunnel`, `Web::Tunnel::Tailscale`: `chi web --tunnel tailscale`, Tailscale Serve set for one run and the PublicUrl it makes) | Experimental: chi web behind an auth proxy. Every request needs the token; a proxied one's owner also needs the identity header (one clean value under one name); the `__Host-` cookie, an absolute `Location` from the public URL, https links with a one-time code in the fragment; the page's lost-sign-in banner. Bridges refuse proxy traces ([configuration.md](configuration.md#behind-an-auth-proxy)). |
@@ -646,11 +649,13 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
646
649
  | Tool output cut | `tool_output_cut.rb` (`ToolOutputCut`), `tool_output_files.rb` (`ToolOutputFiles`) | A tool's output over `max_tool_output_chars` (a `memory_read`'s: `memory.read_max_chars`, 0 = none, plus a guard at half a known window), cut by the tool's policy; an execute's whole output saved in the session's `tool_output/` folder ([internals/tool-output-limits.md](internals/tool-output-limits.md)). |
647
650
  | Steer delivery | `steer.rb` (`Steer`), `delivery.rb` (`Delivery`), `steer_cut.rb` (`SteerCut`), `generation_phase.rb`, `waiting_steer.rb`, `steer_cut_after.rb` (`SteerCutAfter`), `cut_policy.rb` (`CutPolicy`) | A message for a running turn: at the next boundary, cutting a thinking-only generation, or queued for the turn's end ([internals/engine.md](internals/engine.md)). |
648
651
  | Prompt files | `prompt_files.rb` (`PromptFiles`) | The AGENTS.md chain (root → cwd) and the appended files the system prompt carries. |
649
- | Model settings | `effective_model.rb` (`EffectiveModel`, `ModelChoice`), `model_profile.rb` (`ModelProfile`), `model_settings.rb`, `sampling_settings.rb`, `model_catalog.rb` (`ModelCatalog`), `model_notes.rb` (`ModelNotes`) | The effective model's settings as one snapshot per read, a model's prompt format, its `models:` entry, its request parameters, the pickable model rows (`chi models`, `/api/models`), the notes its prompt loads. |
652
+ | Model settings | `effective_model.rb` (`EffectiveModel`, `ModelChoice`), `model_lookup.rb` (`ModelLookup`: every layer's input), `model_profile.rb` (`ModelProfile`), `model_settings.rb`, `sampling_settings.rb`, `model_catalog.rb` (`ModelCatalog`), `model_notes.rb` (`ModelNotes`) | The effective model's settings as one snapshot per read, a model's prompt format, its `models:` entry, its request parameters, the pickable model rows (`chi models`, `/api/models`), the notes its prompt loads. |
650
653
  | Session settings | `session_setting.rb` (`SessionSetting`), `session_model_settings.rb` (`SessionModelSettings`), `level_setting_command.rb` (`/thinking`, `/reasoning-history`), `llm_context_command.rb`, `toolkit_command.rb`, `thinking_notices.rb` (`ThinkingNotices`) | A session's own llm_context, thinking, reasoning_history and toolkit: their chips (session state, `/stats`, `:command_ran`, the web), the commands that set them, the thinking level's notices. |
651
654
  | Dialects | `llm/dialect.rb` (`LLM::Dialect`) | What an `api: anthropic` provider's `/v1/messages` does differently (`dialect: fireworks`) ([internals/anthropic.md](internals/anthropic.md)). |
652
655
  | Logging | `log.rb` (`Log`), `log_subscriber.rb` (`LogSubscriber`), `log_path.rb` (`LogPath`), `log_line.rb` | The debug log: tagged records, a session's event trail, where the file goes ([configuration.md](configuration.md#debug-log-file)). |
653
656
  | Stores | `reminder_store.rb` (`ReminderStore`), `recap_store.rb` (`RecapStore`) | A session's reminders, and its idle recap (`recap.json`). |
657
+ | Reply waits | `reply_wait.rb` (`ReplyWait`, `GONE_AFTER`: the one dead-worker rule), `reply_wait/poll.rb` (`ReplyWait::Poll`, one look per poll), `reply_wait/target.rb` (`ReplyWait::Target`: which turn a wait binds, cursor, baseline, `owner_grace`; `first_message`, `message`, `wait_only`, `answer`, `participant`, `from_cursor`), `reply_wait/liveness.rb` (`ReplyWait::Liveness`: one owner and link read per look; `#owner?` for gone, `#worker_owned?` for an open question) | `chi send --wait`, `chi answer`, a participant's wait, the delegate tools and delegate reports wait through `ReplyWait.call(id, **target.to_h, …)` ([sub-agent.md](sub-agent.md)). |
658
+ | Session rows | `session_row.rb` (`SessionRow`) | A session as the lists see it: scalar facts only, built by `SessionManager.session_rows` (one owner, link, recap and analytics read each), `#to_summary_h` the summaries route's body and `.from_summary_h` a remote's rows read back, `#cli_line` the one `chi sessions list` line, `.running_or_starting?` the delegates' and Verify fresh's "running" (a 15 s grace for a worker on its way). A leaf: never session_manager or web. |
654
659
  | Setup and update | `bootstrap_command.rb`, `bootstrap/`, `update_command.rb`, `gem_update.rb` | `chi bootstrap` (first config.yml, system bundle, core profile) and `chi update` (the gem, shipped bundles, the macOS helper). |
655
660
  | Process groups | `process_group.rb` (`ProcessGroup`) | A command in a process group of its own, stopped as a group (TERM, grace, KILL): execute, tasks, context fetches, the mcp bundle's servers. |
656
661
  | Desktop | `desktop.rb`, `desktop/macos.rb`, `desktop_command.rb`, `desktop/macos/*.swift` | `chi desktop`, the macOS "Send to chi" helper ([desktop.md](desktop.md)). The helper's Swift side: the panel (`Panel.swift`), the chi CLI runner (`ChiRunner.swift`), the session rows and the chi calls a send makes (`Sessions.swift`: `SendPlan`; `ChiHelper --sessions` and `--send-plan` are their CLI seams), agent terminals behind `AgentTerminal` (`AgentTerminal.swift`, `Kitty.swift`, `Tmux.swift`; `ChiHelper --agents` is their CLI seam). |
data/docs/bundles.md CHANGED
@@ -4,7 +4,9 @@ What each shipped bundle does for you, its commands, settings and files. A bundl
4
4
  the plugin API ([plugins.md](plugins.md)); install, upgrade and the `chi bundle` commands are in
5
5
  [plugins.md](plugins.md#the-bundle-commands) and [cli.md](cli.md). Two shipped bundles are documented with the
6
6
  feature they belong to: **source-links** in [hooks.md](hooks.md#the-source-links-bundle) and **known-names** in
7
- [guardrails.md](guardrails.md#the-known-names-bundle).
7
+ [guardrails.md](guardrails.md#the-known-names-bundle). Both hook events from their `plugin.rb` with `chi.on`
8
+ (known-names on `before_tool_call`, priority 50; source-links on `after_turn` and `question_asked`, priority 90), as
9
+ every shipped bundle with code does; before known-names 0.2.0 and source-links 0.7.0 they shipped a `hooks/*.rb` file.
8
10
 
9
11
  ## The btw bundle
10
12
 
data/docs/cli.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - `chi web push ls [--format json]`, `chi web push rm ID`, `chi web push test [ID]` — the phones chi web pushes to (see [Phone notifications](configuration.md#phone-notifications-web-push)): list them (short id, label, origin, added, last delivery, done turns, last error; `stale` for one made on another public URL than chi web's now: never sent to), remove one, or send a test notification to ID or to every device not stale. chi web need not run; nothing printed holds a device's push address or keys. A usage error exits 2; a store others can read, a corrupt one, an unknown device or a failed test push exit 1. This machine only: `chi --remote X web push` exits 2
18
18
  - `chi web --web-markdown` / `--no-web-markdown` — opt in to, or opt out of, sanitized Markdown rendering for completed assistant messages, the stage's asking text and a resolved question card's reply (`web.markdown`, off by default; `--no-web-markdown` turns a config's `web.markdown: true` off for this run)
19
19
  - `chi web --no-web-working-set` — turns the stage view's working set off (on by default; `--web-working-set` turns a config's `web.working_set: false` back on): what each turn brought into the model's context, in the stage and under each finished turn; `?working_set=1|0` on the page URL overrides it (see [The working set](#the-working-set))
20
- - `chi sessions list|stop|restart|archive|unarchive|delete|prune|clean|stats` — manage persisted sessions; `list` shows this git project's, `list --scope=all` every one, a delegated session with `↳ <parent>`, `list --archived` the archived ones too (see [Sessions](sessions.md)). `stats ID` prints a session's cost, tokens and progress, and its own settings (`--set`; a `settings:` line), from a live worker's `GET stats`, else its saved `analytics.json` (`--format json` one object, with `settings`), without running a model turn. A usage error (an unknown subcommand or flag, a flag missing its value, `stop`, `restart` or `delete` with no ids, a bad `list --format` or `--scope`, a `--days`, `--keep` or `--limit` that isn't a whole number) exits 2; an unknown or refused session exits 1
20
+ - `chi sessions list|stop|restart|archive|unarchive|delete|prune|clean|stats` — manage persisted sessions; `list` shows this git project's, `list --scope=all` every one, a delegated session with `↳ <parent>`, `list --archived` the archived ones too (see [Sessions](sessions.md)); one line per session (`<id> <state> <ctx> <updated_at> <text> [flags] ↳ … ↪ …`) and one footer (`N session(s) (sort=… order=…)`, or the project note) for the plain list, the `--live`/`--cwd` text and `--remote`. `stats ID` prints a session's cost, tokens and progress, and its own settings (`--set`; a `settings:` line), from a live worker's `GET stats`, else its saved `analytics.json` (`--format json` one object, with `settings`), without running a model turn. A usage error (an unknown subcommand or flag, a flag missing its value, `stop`, `restart` or `delete` with no ids, a bad `list --format` or `--scope`, a `--days`, `--keep` or `--limit` that isn't a whole number) exits 2; an unknown or refused session exits 1
21
21
  - `chi note [--source NAME] [-m TEXT] (ID|PREFIX)... | --all` — add a context note (TEXT or stdin) to sessions: background the model sees on its next turn; it starts no turn (see [Sessions: Context notes](sessions.md#context-notes))
22
22
  - `chi broadcast [-m TEXT] [--all] [--dry-run]`, `chi broadcast log [--last N] [--format json]`, `chi broadcast deliver BROADCAST_ID (ID|PREFIX)...` — share one piece of information (TEXT or stdin) with every session it may concern, as a context note from `broadcast` (see [Broadcast](broadcast.md))
23
23
  - `chi context <add|push|ls|show|refresh|rm|mute|unmute> …` — attach live external text to sessions (a command chi runs every so often, or text pushed in); the model gets a short note when it changes and reads it with `context_read`; `chi context add <URL>` attaches a GitHub PR with the github-pr bundle; `chi context push NAME -m TEXT` (the long form is `--message TEXT`) gives a `--push` source its new text, read from stdin when no `-m` is given (see [Attached context](context.md))
@@ -159,7 +159,7 @@ The loop for a bundle you're writing (the whole path: [bundle-authoring.md](bund
159
159
  then forces), `install` (each Installer warning, a `needs` one as warn, and each plugin or hook load failure at
160
160
  the source `file:line`; skipped while a placeholder sha is unfilled), `registered` (info: each command, tool,
161
161
  hook with its priority, init, toolkit, tool source, peer source and prompt section), `hook-event` (warn: a `chi.on` event chi
162
- never fires), `settings` (warn: a `--set` the manifest's `settings:` rules out, as config.yml's `bundles:` is told), `api` (warn: a `ctx.*` / `chi.*` call or a keyword this chi's API lacks, read from the source with
162
+ never fires), `fail-closed` (warn: a `chi.on(..., on_error: :fail_closed)` in a plugin whose manifest `plugin:` lacks `required: true`, so a load failure would not deny tool calls; not on an installed bundle's re-check), `settings` (warn: a `--set` the manifest's `settings:` rules out, as config.yml's `bundles:` is told), `api` (warn: a `ctx.*` / `chi.*` call or a keyword this chi's API lacks, read from the source with
163
163
  Prism against the API's own classes, on a path that never runs too; written on a local `ctx` / `chi` itself, so a
164
164
  `s = ctx.sessions` variable isn't followed; a name the plugin guards with `respond_to?` is left), `boundary` (warn: a `Samagotchi::` name outside "Stable for bundles"; a shipped bundle's listed
165
165
  exceptions aside. On an installed bundle (`chi update`) only a name this chi no longer has is a row: the constant
@@ -339,8 +339,9 @@ Also shipped, not installed: dev (mcp, skills, source-links) (chi bundle install
339
339
  the merge itself, and `--force` replacing the file. A dry run and an automatic update
340
340
  (`update.auto`) show it and leave it, and so does a failed row or one with no place
341
341
  for it (a skipped system bundle). A memory that can't be read at a
342
- newer version fails that bundle's row with the file's name. Hooks, rules and the plugin are replaced; an edited one didn't
343
- load anyway (its sha no longer matched), the row says it was replaced, and
342
+ newer version fails that bundle's row with the file's name. Hooks, rules, the plugin and scripts are replaced. One
343
+ whose bytes are neither what the install recorded (nothing recorded counts as edited) nor the new version's is
344
+ edited: the row says `replaced edited hooks/x (a copy goes to the trash first)` (`would replace` in the plan), and
344
345
  a copy goes to the bundle trash first (`chi bundle trash`; `hooks/x`,
345
346
  `guardrails/x`, `plugin/x`, `scripts/x` inside the dir).
346
347
  A bundle of the same name from elsewhere (a zip, git) is skipped ("not from
@@ -801,8 +802,8 @@ also offline (from the saved records). `/recap` is in
801
802
  Switch](#runtime-model-switch-assist-mode).
802
803
 
803
804
  `/llm-context` shows the LLM context strategy, apply rule and budget the next
804
- turn runs under, each with where it came from (`the session`, `models: <key>`,
805
- `hosts entry '<name>'`, `llm_context.*`), and the session's own values.
805
+ turn runs under, each with where it came from (`session`, `models: <key>`,
806
+ `hosts.<name>`, `llm_context.*`), and the session's own values.
806
807
  `/llm-context strategy <none|stale|stale,forget> apply <payoff|next_request|turn_end>
807
808
  budget <tokens|64k|off>` sets the session's own (any of the three, in one line;
808
809
  `default` unsets one), and `/llm-context reset` unsets them all. A change is
@@ -1527,8 +1528,8 @@ CHI_REMOTE=studio chi context push claude-outbox ab12 < answer.json
1527
1528
  - `send --new` needs `--dir`, that machine's absolute path (no folder of this
1528
1529
  one is guessed); `--toolkit`, `--set` and `--parent-answers` are checked
1529
1530
  against that machine's config and bundles. `sessions list` lists every
1530
- project's sessions there (`--scope=project --cwd DIR` one project's) in the
1531
- `--live` text form. `context` takes the session ids (no default session),
1531
+ project's sessions there (`--scope=project --cwd DIR` one project's), each
1532
+ on the same line a list here prints. `context` takes the session ids (no default session),
1532
1533
  and a URL resolves through that machine's bundles.
1533
1534
  - That machine's config.yml decides what it checks for `send` and `answer`:
1534
1535
  a parent agent's `/continue yes` and options (`guardrails.parent_answers`),
@@ -105,7 +105,9 @@ Behavior:
105
105
  - A key chi doesn't read warns at start, with the closest known key:
106
106
  `config: unknown key 'default.modle' (did you mean 'default.model'?)`.
107
107
  Names you choose under the maps below (host names, model ids) don't warn.
108
- - Environment variables and CLI flags win over config-file values.
108
+ - Environment variables and CLI flags win over config-file values. A model's
109
+ own settings (`models:`, `hosts:`) layer in between: see
110
+ [Where a model setting comes from](#where-a-model-setting-comes-from).
109
111
  - An edit to the file needs no restart of `chi web`. A new worker reads the
110
112
  file when it starts; a running worker sees only settings whose readers check
111
113
  the file again (see [When a change applies](#when-a-change-applies)). The web
@@ -148,7 +150,7 @@ or `chi web` restart.
148
150
  | `default.model` | New session | Existing sessions keep their saved model; change one with `/model`. |
149
151
  | `default.input`, `no_default_input`, `no_interrupt` | Next CLI run | These set up that run's first prompt or turn limit. |
150
152
  | `default.max_tokens`, `max_tool_output_chars`, `memory.read_max_chars`, `read.*`, `execute.*` except `execute.description`, `image.*` | Next matching request or tool use | An operation already in progress keeps its resolved limits. |
151
- | `server.host`, `server.port`, `hosts.*` | Worker start | Includes host addresses, APIs, declared models and host-level settings. The web model picker refreshes `hosts:` on file change; a running worker does not. |
153
+ | `server.host`, `server.port`, `hosts.*` | Worker start | Includes host addresses, APIs, declared models and host-level settings. Commands (`chi self`, `chi models`, the session lists) and chi web (its model picker, the session cards) read `hosts:` as it is now; a running worker keeps the hosts it started with until it restarts. |
152
154
  | `server.open_timeout`, `server.read_timeout`, `server.first_token_timeout` | Worker start | The worker's clients retain the timeouts set when they were built. |
153
155
  | `model_aliases` | Next model lookup | A session keeps its resolved model unless it is explicitly switched. |
154
156
  | `models.<key>.profile` | Session start or `/model` | It is resolved when that model is selected; editing it does not switch the current model's profile by itself. |
@@ -229,6 +231,35 @@ A few environment variables are not settings (no config.yml key, no flag):
229
231
  - `SAMAGOTCHI_LOG_STRICT=1`: an unknown log tag or a malformed log event raises instead of being dropped. The spec
230
232
  suite sets it, and a bundle's tests keep it (`Samagotchi::Testing::Sandbox`).
231
233
 
234
+ ## Where a model setting comes from
235
+
236
+ A model's settings come in layers, and the first one set wins. Every surface reads them the same way: a turn,
237
+ `/model` and `/stats`, `chi self`, the web's chips and the start page's ⚙ panel, and a session list's ctx %. A
238
+ `models:` entry is looked up under each name the model goes by, the most specific first: the name as typed (an
239
+ alias), the alias's target (`host:id`), the part after a host prefix, then the id the host is asked for.
240
+
241
+ | Setting | Order, first set wins |
242
+ |---|---|
243
+ | `thinking` | the session's own (`/thinking`, `chi --thinking`) → `chi web --thinking` or `SAMAGOTCHI_THINKING_LEVEL` → `models:` → `hosts.<name>.thinking` → `thinking.level` in config.yml → `default` |
244
+ | `reasoning_history` | the session's own (`/reasoning-history`) → `SAMAGOTCHI_REASONING_HISTORY` → `models:` → `hosts.<name>` → the api's default (`all` on `api: anthropic`, else `turn`) |
245
+ | `steer_cut_after` | `SAMAGOTCHI_STEER_CUT_AFTER` → `models:` → `hosts.<name>` → `steer.cut_after` in config.yml → 20 |
246
+ | `profile` | `--profile` or `SAMAGOTCHI_MODEL_PROFILE` → `models:` (an unknown profile warns, and the next name is tried) → `hosts.<name>.profile` → the server's chat template → the name → `qwen36` |
247
+ | `sampling` | merged: `hosts.<name>.sampling`, then `models:` over it, key by key |
248
+ | `vision` | `models:` → `hosts.<name>.vision` → what the server or the host's model list says |
249
+ | `window_tokens` | the server's `n_ctx` → the host's model list → `models:` → `hosts.<name>.window_tokens` → `context.window_tokens` (`--context-window-tokens`, `SAMAGOTCHI_CONTEXT_WINDOW_TOKENS` or config.yml) → 256000 |
250
+ | `llm_context_strategy`, `llm_context_apply`, `llm_context_budget_tokens` | each on its own: the session's own (`/llm-context`, `chi --llm-context…`) → `models:` → `hosts.<name>` → `llm_context.*` (`SAMAGOTCHI_LLM_CONTEXT_…` or config.yml) → the default |
251
+
252
+ Two rules, both intended:
253
+
254
+ - For thinking, reasoning_history, steer_cut_after and the profile, a process-wide override (a flag or an
255
+ environment variable) beats the model's own setting: it runs every model one way for a while.
256
+ - For the window and the LLM context, the global key is the fallback whatever sets it: an environment variable
257
+ or a flag there doesn't beat a model's or a host's setting. (`steer.cut_after` from config.yml, too, comes after
258
+ the host's.)
259
+
260
+ Where a value came from is named as `session`, `models: KEY`, `hosts.NAME`, or the config key or environment
261
+ variable that set it.
262
+
232
263
  ## Model Server API
233
264
 
234
265
  Chi talks to a model server over HTTP in one of two ways, set by the host's `api:`:
@@ -1774,8 +1805,8 @@ its own). The first target is a long session such as a day-long coordinator, whe
1774
1805
  budget don't ask: they only decide when a batch goes in, and each batch's break comes as designed (`next_request`
1775
1806
  with staged edits pending moves a break the old rule makes by the end of the next turn anyway). The chip's Set and
1776
1807
  `--llm-context` on an attached or resumed session send `--yes`.
1777
- - **Where to see it:** `/llm-context` (each value and where it came from: `the session`, `models: <key>`,
1778
- `hosts entry '<name>'`, `llm_context.*`), `/stats` (`llm context:`), the turn log (an `llm_context` record per
1808
+ - **Where to see it:** `/llm-context` (each value and where it came from: `session`, `models: <key>`,
1809
+ `hosts.<name>`, `llm_context.*`), `/stats` (`llm context:`), the turn log (an `llm_context` record per
1779
1810
  turn that runs a layer or whose session set its strategy) and the web's chip. A woken worker's status line counts
1780
1811
  its saved context against the session's budget.
1781
1812
 
@@ -2336,6 +2367,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
2336
2367
  | `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). Anything else binds `127.0.0.1` with a warning. See [CLI: chi web on your phone](cli.md#chi-web-on-your-phone). |
2337
2368
  | `web.markdown` | `false` | yes | Render answers as Markdown in `chi web`. |
2338
2369
  | `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). |
2370
+ | `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) 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`. Cards are left out: a reload places them after the render, which the check doesn't run (the e2e reload checks compare them). Every open owner tab runs the check; `chi web` logs a turn's first report only, and starts over when it restarts. |
2339
2371
  | `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). |
2340
2372
  | `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). |
2341
2373
  | `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 repo 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). |
data/docs/guardrails.md CHANGED
@@ -1392,7 +1392,8 @@ denies every call until the bundle is reinstalled.
1392
1392
  chi bundle install known-names # or chi bundle install dev
1393
1393
  ```
1394
1394
 
1395
- installs one `before_tool_call` hook and a short memory. A local model that
1395
+ installs a plugin with one `before_tool_call` hook (`chi.on`, priority 50; a
1396
+ `hooks/known_names.rb` file before known-names 0.2.0) and a short memory. A local model that
1396
1397
  once misspells a name inside a path (`jonathandoe` → `jonathndoe`)
1397
1398
  keeps copying the wrong spelling from its context, and every call after
1398
1399
  that fails. The hook knows the right names and compares strings: the
@@ -1449,10 +1450,13 @@ else goes to chi's own rules. It needs nah installed; see its README for the set
1449
1450
 
1450
1451
  ## Failing closed
1451
1452
 
1452
- - A config hook with `required: true`, or a bundle `before_tool_call` hook with
1453
- `on_error: fail_closed`, that fails to load (missing, syntax error, or for a
1454
- bundle hook a sha256 that differs from the installed one) makes chi deny
1455
- every tool call. One that raises when called denies that call.
1453
+ - A config hook with `required: true`, a bundle `before_tool_call` hook with
1454
+ `on_error: fail_closed`, or a bundle plugin its manifest marks `required: true`
1455
+ (`plugin:` `required: true`, for a `chi.on(:before_tool_call, on_error:
1456
+ :fail_closed)` guard, chi 0.157.0 or newer, [plugins.md](plugins.md#a-guard-that-fails-closed-on_error-fail_closed)),
1457
+ that fails to load (missing, syntax error, an unmet `requires_chi`, or for a
1458
+ bundle's file a sha256 that differs from the installed one) makes chi deny
1459
+ every tool call. A fail-closed hook that raises when called denies that call.
1456
1460
  - Other hooks stay fail-open; a load failure is a warning.
1457
1461
  - Every load failure is shown once, at the start of the first turn
1458
1462
  (`guardrails> …` in the terminal, a red line on the web).
data/docs/hooks.md CHANGED
@@ -145,8 +145,9 @@ they must never spend or permit. See
145
145
  [Guardrails](guardrails.md#answers-from-a-parent-agent). `effects:` needs a
146
146
  chi newer than 0.85.0 (an older one raises on the keyword).
147
147
 
148
- `event[:hook]` is the label the notices carry: `known_names.rb (bundle
149
- known-names)` for a bundle hook, `audit.rb (config)` for a config hook,
148
+ `event[:hook]` is the label the notices carry: `plugin.rb (bundle
149
+ known-names)` for a plugin's `chi.on` hook (`<file> (bundle <name>)` for a bundle's `hooks/*.rb`),
150
+ `audit.rb (config)` for a config hook,
150
151
  `turn hook` for one registered at runtime.
151
152
 
152
153
  `event[:notify]` also takes `fallback_for:`, what the line stands in for, so
@@ -465,6 +466,10 @@ change), as for every hook.
465
466
  (missing file, syntax error), chi denies every tool call and says why; if it
466
467
  raises as a `before_tool_call` hook, that call is denied. See
467
468
  [Guardrails](guardrails.md#failing-closed).
469
+ - A plugin's `chi.on(:before_tool_call, on_error: :fail_closed)` (chi 0.157.0 or newer) is
470
+ the same for a bundle: a raise denies that call, and a plugin its manifest
471
+ marks `required: true` that fails to load denies every call. See
472
+ [plugins.md](plugins.md#a-guard-that-fails-closed-on_error-fail_closed).
468
473
 
469
474
  A hook that fails to load is reported as a `[samagotchi:hooks]` warning and
470
475
  once in the UI.
@@ -477,7 +482,7 @@ worker, on the plugins' surface, whatever its `on_error` (the same notice a
477
482
  `chi.on` handler gets):
478
483
 
479
484
  ```
480
- plugins> guardrail guardrails.rb (bundle known-names) before_tool_call hook failed (RuntimeError: boom):
485
+ plugins> guardrail guardrails.rb (bundle my-guard) before_tool_call hook failed (RuntimeError: boom):
481
486
  it denies every tool call it guards, and its next failures are in each denial's reason
482
487
  ```
483
488
 
@@ -711,7 +716,7 @@ Notes:
711
716
  - Ordering: bundle hooks fire by `(priority, bundle_name, hook_name)` (lower priority first), then plain `config.yml` hooks in registration order.
712
717
  - Settings: a hook class with `initialize(settings = {})` gets the bundle's section of `config.yml` `bundles:` (see [Settings](#settings)).
713
718
  - A bundle can also ship a `plugin.rb` whose `chi.on(event)` blocks are bundle hooks too, next to commands and tools; see [Plugins](plugins.md). There `ctx.notify`, `ctx.steer` and the other `ctx` helpers act as this page's `event[:notify]`… do for the event the block runs for.
714
- - Shipped bundles (each but web-search in a profile: `core` or `dev`, see [Bundle profiles](memory.md#bundle-profiles-core-and-dev)): `chi bundle install guardrails` (rules, see [Guardrails](guardrails.md#the-guardrails-bundle)) and `chi bundle install known-names` (a hook, see [Guardrails](guardrails.md#the-known-names-bundle)), `chi bundle install source-links` (a hook: announces source refs, see [The source-links bundle](#the-source-links-bundle)), `chi bundle install btw` (a plugin: `/btw`, see [Bundles](bundles.md#the-btw-bundle)), `chi bundle install mcp` (a plugin: tools from MCP servers, see [Bundles](bundles.md#the-mcp-bundle)) `chi bundle install loop-guard` (a plugin: breaks tool-call loops, see [Bundles](bundles.md#the-loop-guard-bundle)), `chi bundle install check-in` (a plugin: checks on a long turn, see [Bundles](bundles.md#the-check-in-bundle)), `chi bundle install slow-commands` (a plugin: commands that ran past the execute limit are run as tasks next time, see [Bundles](bundles.md#the-slow-commands-bundle)), `chi bundle install agents-md` (a plugin: a nested AGENTS.md is steered into the conversation on the first touch under its directory, see [Bundles](bundles.md#the-agents-md-bundle)), `chi bundle install cost-cap` (a plugin: a per-session $ cap, `/cap`, see [Bundles](bundles.md#the-cost-cap-bundle)), `chi bundle install work-cap` (a plugin: a per-session cap on tool calls and active minutes, `/workcap`, see [Bundles](bundles.md#the-work-cap-bundle)), `chi bundle install ruby` (a plugin: an RSpec run with no examples at all, a hint, see [Bundles](bundles.md#the-ruby-bundle)) `chi bundle install skills` (a plugin: `/skill`, versions of skills, see [Bundles](bundles.md#the-skills-bundle)), `chi bundle install github-pr` (attached context: the branch's open PR, see [Bundles](bundles.md#the-github-pr-bundle)), `chi bundle install coordinator` (a plugin: parallel work in worktrees and child sessions, see [Bundles](bundles.md#the-coordinator-bundle)), `chi bundle install claude-peer` / `codex-peer` (a plugin: talk to a Claude Code or Codex session, see [Bundles](bundles.md#the-claude-peer-bundle)), `chi bundle install model-notes` (memories: reviewed model notes, see [Bundles](bundles.md#the-model-notes-bundle)), `chi bundle install decision-card` (a plugin: a long answer's question as a card, see [Bundles](bundles.md#the-decision-card-bundle)), `chi bundle install inline-widgets` (a plugin: prompt sections that teach the `chi-ui` blocks chi web draws, see [Bundles](bundles.md#the-inline-widgets-bundle)) and `chi bundle install web-search` (a plugin: a `web_search` tool through your SearXNG, in no profile, see [Bundles](bundles.md#the-web-search-bundle)).
719
+ - Shipped bundles (each but web-search in a profile: `core` or `dev`, see [Bundle profiles](memory.md#bundle-profiles-core-and-dev)): `chi bundle install guardrails` (rules, see [Guardrails](guardrails.md#the-guardrails-bundle)) and `chi bundle install known-names` (a plugin's `before_tool_call` hook, see [Guardrails](guardrails.md#the-known-names-bundle)), `chi bundle install source-links` (a plugin's `after_turn` and `question_asked` hook: links source refs, see [The source-links bundle](#the-source-links-bundle)), `chi bundle install btw` (a plugin: `/btw`, see [Bundles](bundles.md#the-btw-bundle)), `chi bundle install mcp` (a plugin: tools from MCP servers, see [Bundles](bundles.md#the-mcp-bundle)) `chi bundle install loop-guard` (a plugin: breaks tool-call loops, see [Bundles](bundles.md#the-loop-guard-bundle)), `chi bundle install check-in` (a plugin: checks on a long turn, see [Bundles](bundles.md#the-check-in-bundle)), `chi bundle install slow-commands` (a plugin: commands that ran past the execute limit are run as tasks next time, see [Bundles](bundles.md#the-slow-commands-bundle)), `chi bundle install agents-md` (a plugin: a nested AGENTS.md is steered into the conversation on the first touch under its directory, see [Bundles](bundles.md#the-agents-md-bundle)), `chi bundle install cost-cap` (a plugin: a per-session $ cap, `/cap`, see [Bundles](bundles.md#the-cost-cap-bundle)), `chi bundle install work-cap` (a plugin: a per-session cap on tool calls and active minutes, `/workcap`, see [Bundles](bundles.md#the-work-cap-bundle)), `chi bundle install ruby` (a plugin: an RSpec run with no examples at all, a hint, see [Bundles](bundles.md#the-ruby-bundle)) `chi bundle install skills` (a plugin: `/skill`, versions of skills, see [Bundles](bundles.md#the-skills-bundle)), `chi bundle install github-pr` (attached context: the branch's open PR, see [Bundles](bundles.md#the-github-pr-bundle)), `chi bundle install coordinator` (a plugin: parallel work in worktrees and child sessions, see [Bundles](bundles.md#the-coordinator-bundle)), `chi bundle install claude-peer` / `codex-peer` (a plugin: talk to a Claude Code or Codex session, see [Bundles](bundles.md#the-claude-peer-bundle)), `chi bundle install model-notes` (memories: reviewed model notes, see [Bundles](bundles.md#the-model-notes-bundle)), `chi bundle install decision-card` (a plugin: a long answer's question as a card, see [Bundles](bundles.md#the-decision-card-bundle)), `chi bundle install inline-widgets` (a plugin: prompt sections that teach the `chi-ui` blocks chi web draws, see [Bundles](bundles.md#the-inline-widgets-bundle)) and `chi bundle install web-search` (a plugin: a `web_search` tool through your SearXNG, in no profile, see [Bundles](bundles.md#the-web-search-bundle)).
715
720
  - Installing a bundle executes its hook code at `Engine` startup. Only install bundles you trust, as you would a gem. Hooks are **not** executed at install time (copy-only); they are `module_eval`'d at `Engine.new` inside per-bundle `Samagotchi::Bundles::<name>` namespaces (no top-level `require` collisions). Keep hook files side-effect-free at load time; do work in `#call` — top-level side effects (require, IO, `at_exit`, global assignment) run once per `Engine.new` (class redefinition is idempotent).
716
721
 
717
722
  Lifecycle:
@@ -726,7 +731,8 @@ Lifecycle:
726
731
  chi bundle install source-links # or chi bundle install dev
727
732
  ```
728
733
 
729
- installs one `after_turn` hook and a short memory. When the model's answer
734
+ installs a plugin with one hook on `after_turn` and `question_asked` (`chi.on`, priority 90; a
735
+ `hooks/source_links.rb` file before source-links 0.7.0) and a short memory. When the model's answer
730
736
  mentions a known source ref — a JIRA ticket, a GitHub issue, an internal
731
737
  wiki page — the web links it in the answer (below), and every UI shows one
732
738
  line right after the message:
@@ -16,6 +16,7 @@ rescues its own errors: an observer must never break the running turn.
16
16
  | `RingBuffer` | `ring_buffer.rb` | The last `ring_capacity` (256) raw events by `event_seq`, in memory, for a reconnect's replay. The capture observer feeds it. |
17
17
  | `TurnAccumulator` | `turn_accumulator.rb` | The turn in progress, folded from events. |
18
18
  | `CardStore` | `card_store.rb` | The last cards and notices, saved in `cards.json`, each anchored to its turn. |
19
+ | `TurnDrawings` | `turn_drawings.rb` | Each finished turn as live drew it (`turn_drawings.jsonl`): written by the accumulator's `on_turn_end` hook, read by chi web's show. |
19
20
  | `CardPlaces` | `card_places.rb` | Pure: where `CardStore`'s entries sit in the messages the page draws (`turns_since`, and the `opening_id` stamp). |
20
21
  | `PendingCard` | `pending_card.rb` | `pending_card.json` `{id:, bundle:}`: the running turn's open card with actions (check-in's Nudge), written and removed with that card, so chi web's hub, which watches files and not workers, can notify. |
21
22
 
@@ -27,12 +28,19 @@ whose seq a cursor is) and its **secret**; both are published in `bridge.json` (
27
28
 
28
29
  A joining UI must draw a turn already half done, and the ring may have dropped its early events. The accumulator
29
30
  folds the event log into one hash, `current_turn`: the prompt, `turn_id`, origin, `at`, and ordered `parts`
30
- (generation, thinking, text, tool, input, steer, reminder, notice), plus `pending_question`. A tool part keeps its
31
- row fields (`ToolRowFields`), its output cut head-and-tail at `ToolOutputCut::WEB_PREVIEW_CHARS` so a joined row is the
32
- row a reload draws, and `elapsed_ms` while it runs (the accumulator times running calls itself, `clock:`). A
31
+ (generation, thinking, text, tool, input, steer, reminder, notice, card), plus `pending_question`. A tool part keeps its
32
+ row fields (`ToolRowFields`), its `tool_id`, its output cut head-and-tail at `ToolOutputCut::WEB_PREVIEW_CHARS` so a
33
+ joined row is the row a reload draws, `elapsed_ms` while it runs (the accumulator times running calls itself, `clock:`)
34
+ and, once finished, the event's `duration_ms` (its own clock only for an older worker's event that has none). A
33
35
  `notice` part holds the event of a row that is neither text nor a tool call (`TurnNotice::FIELDS`: a hook's notice,
34
36
  the "asking again" row, a steer's cut, a ✂ row, a question and its answer), so a join replays it through the handler
35
- that drew it live.
37
+ that drew it live. A `card` part is a card the turn showed in its step (`in_turn`), its latest version in its first
38
+ one's place; `replay_events` and `join_events` skip it (a running turn's join takes its cards from CardStore), and
39
+ only `replay_events(turn, cards: true)` (a finished turn's drawing) replays it as its `card` event.
40
+
41
+ At the terminal event, before clearing, the accumulator hands a deep copy of the turn and the end event to its
42
+ `on_turn_end:` hook (the Bridge's `TurnDrawings#append`). The hook runs under the accumulator's mutex and the
43
+ observer lock, so it never calls back in; an error is logged (`turn_end_hook_failed`) and the fold goes on.
36
44
 
37
45
  The turn is cleared on its terminal event (`Events::TURN_END`), the same event that brings its messages into the
38
46
  session, so a snapshot shows a turn in exactly one of the two places. Beside the turn it keeps what a snapshot also
@@ -40,10 +48,58 @@ needs and the messages lag: `queued` turns (`:turn_enqueued` until started, merg
40
48
  the idle `recap` (until a turn starts), a pending `continue_offer`, and the running turn's `working_set`.
41
49
 
42
50
  Three other users: `replay_events(turn)` turns a `current_turn` back into the live events that would have drawn it
43
- (the web's `snapshotEvents` replays them; `spec/shared/turn_snapshot.json` pins both sides); `messages_of` gives a
51
+ (the attached TUI's join); `join_events` is the page's unfold of the same turn plus the queue behind it (its
52
+ `turn_started` also carries `at`, `cut_after` and every author key, then a `turn_enqueued` per queued prompt and a
53
+ `command_queued` per waiting command), which chi web's `GET /api/sessions/:id` sends as `replay` from the worker's
54
+ snapshot (`from_wire` symbolizes it), so any worker's snapshot gives the page the same events
55
+ (`spec/shared/turn_snapshot.json` pins it against turn_events.js `snapshotEvents`, the page's own fallback for one
56
+ release); `messages_of` gives a
44
57
  plugin's `ctx.messages` the turn so far (`Engine#running_turn_messages`); `participant_turn?` tells `POST /turn` that
45
58
  a participant's review turn runs, so the owner's input queues behind it.
46
59
 
60
+ ## TurnDrawings
61
+
62
+ A reload or a reconnect draws a finished turn from what live drew, not rebuilt from its saved messages: the
63
+ accumulator's final fold of the turn (its parts in order, in-turn cards included) and the end event's display keys
64
+ (`TurnDrawings::END_KEYS`), one JSON line per turn in `<session dir>/turn_drawings.jsonl`
65
+ (`{v: 1, turn_id, kind, from, to, from_digest, to_digest, drawing, end}`, `TurnDrawings::Line`).
66
+
67
+ - **The range comes from the Engine.** The end event's `kept_from`/`kept_to` (`Engine#end_turn`) name the turn's own
68
+ messages, `kept[from...to]`. No range (an older worker, a turn that kept nothing) or an empty one writes no line,
69
+ and the turn draws as before.
70
+ - **Validity.** A line holds while the messages reach `to` and `messages[from]` and `messages[to - 1]` digest as the
71
+ line says (`TurnDrawings.digest`: role, content and time, one canonical form for the live symbol-keyed messages
72
+ and the saved, scrubbed ones). A rollback, a rolled-back failure or a prompt handed back drops it. Of overlapping
73
+ valid lines (a rollback, then a re-run that said the same) and of one turn id's lines, the newest wins
74
+ (`TurnDrawings.valid`).
75
+ - **Writing.** The accumulator calls `TurnDrawings#append` at the end event, inside the observer delivery, so the
76
+ line is on disk before a stream writer (subscribed later) gets the end frame. That departs from SessionObserver's
77
+ "enqueue-only" note, as CardStore's save does: one append per turn end. It writes `"\n"` first when the file's last
78
+ byte isn't one (a torn line from a crash), then the line in one write; a failure is logged (`turn_drawing_failed`).
79
+ A part's output is the accumulator's cut (`WEB_PREVIEW_CHARS`); a diff is the one the saved `tool_diffs` have
80
+ (`TextDiff`'s cut); images are refs.
81
+ - **Reading.** `TurnDrawings.read(dir)` skips an unknown `v`, a torn or broken line and one missing a field, and is
82
+ cached by the file's path, size and mtime. `#last` is the newest line this worker wrote or started from.
83
+ - **The snapshot.** `Bridge#snapshot` (the snapshot and reset frames, `GET /snapshot`) adds `last_turn_drawing:
84
+ {drawing, end}`, `#last` as the file has it, not unfolded, when it holds against the snapshot's messages and its `to`
85
+ is their size (the last exchange); it is absent otherwise (no turn yet, a rollback, a Continue's note after it, a line
86
+ of another version, one over the 1 MB a restart reads back: `TurnDrawings.sendable?`). An attaching TUI unfolds it (`TerminalUI::JoinReplay`, `TurnAccumulator.replay_events`) and draws
87
+ that turn's rows through its `EventRenderer`, as a running turn's join does, then the end event's cancel or failure
88
+ line, else the saved answer; without it (or for a drawing that isn't the last prompt's turn: a reminder's, a
89
+ Continue's) the rows are rebuilt from the messages as before. `chi --remote` attaches through chi web's stream proxy,
90
+ which relays an owner's frames byte for byte, the field included. A participant never gets it: its stream's snapshot
91
+ is bare (`ParticipantView`). An older TUI ignores the field; an older worker sends none.
92
+ - **The show.** chi web's full read with `?parts=1&drawings=1` (the page's) stamps each display item of a kind a
93
+ drawing draws (the opening, steps, steers, merged lines, the empty answer) in a valid range with `drawn: <turn_id>`
94
+ and drops its `parts` (its ✂ marks stay as `marks: {tool_id => edit}`), and sends `turn_drawings: {turn_id =>
95
+ {events, end}}`: `TurnAccumulator.replay_events(drawing, cards: true)`, the one unfold, in Ruby. A context note in
96
+ a range and a `!cmd`'s record are not stamped. Without `drawings=1` (an older page) the read is what it was.
97
+ CardStore lists an in-turn entry's turn as `of_turn`, so the page leaves a drawn turn's own rows and cards to its
98
+ drawing (`cards_place.js`). A live worker whose sidecar features lack `turn_drawings` (`TurnDrawings::FEATURE`:
99
+ an older one lists no `of_turn`) gets no drawings in the show: its turns all draw as before.
100
+ - **Compat.** An older worker writes nothing (its turns fall back); an older chi web never opens the file. A fork
101
+ or a continue copies no drawings: its turns fall back. A one-shot run (no Bridge) writes none.
102
+
47
103
  ## CardStore
48
104
 
49
105
  The cards a plugin or the Engine shows (`Engine#show_card`), hook notices, load warnings (`:guardrail_warning`),
@@ -77,6 +133,9 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
77
133
  first while that line is still in the run, so a later release can drop the count. No stamp (the page counts `turns_since`) for
78
134
  an entry before every opening, after a line an older chi wrote with no id, or from a version 1 file (`base_since`). A rollback
79
135
  keeps today's rule: a rolled-back turn's cards name the opening before it.
136
+ The saved recap carries the same stamp: `saved_recap`'s `opening_id` (`RecapPlace.opening_id`, the id of the last
137
+ opening its `covered` messages hold, read at read time, so `recap.json` is unchanged), which the page places it after
138
+ (`recap_stamp.js`); an older worker's `saved_recap` has none, and the page counts `turns_since`.
80
139
  - **A turn that leaves nothing** is read, not told: an in-turn entry not `current` whose turn has no opening in the messages
81
140
  (a `!rollback`, a failed turn with nothing kept, a prompt stopped before the model) lists as a between-turns entry at its
82
141
  place, a card without its actions and a hook's notice without its step; its other rows, having no step to sit in, aren't
@@ -195,6 +254,22 @@ The Bridge exposes:
195
254
  "params":"path=notes.txt","event_seq":812}
196
255
  ```
197
256
 
257
+ Both tool events carry the run's `tool_id` (`ToolIds`, the id its output is saved under in the session's
258
+ `tool_ids`, handed out before the batch runs), and `tool_call_completed` carries `duration_ms`: the call's time from
259
+ the `tool_call_started` emit to its own, less an approval's `waited_ms`, rounded first (SessionMetrics' tool record
260
+ definition). It is the one duration every UI shows: the web's live row, the tool record a reload draws, the attached
261
+ terminal's line; each keeps its own clock only for an older worker's event without it. A long output's
262
+ `tool_call_completed` also carries `preview`: `ToolOutputCut.preview` of the capped output at `WEB_PREVIEW_CHARS`
263
+ (a `read`'s head, any other tool's head and tail), the text a reload's row has from the saved output
264
+ (`MessageParts#tool_part`; spec/tool_preview_parity_spec.rb pins the two). The web row and the accumulator's part
265
+ take it; the TUI keeps `output`.
266
+
267
+ An end event (`turn_completed`, `turn_canceled`, `turn_failed`) of a turn that kept messages carries `kept_from` and
268
+ `kept_to`: the turn's own messages are `messages[kept_from...kept_to]` of the session it leaves (`Engine#end_turn`;
269
+ `kept_from` is the conversation's size under the system head the turn may have added, before its reminders and
270
+ prompt). Small integers on the event only, never on a message; no client draws them (`Bridge::TurnDrawings` reads
271
+ them). An older worker's end event has neither.
272
+
198
273
  A `turn_completed` frame omits `result`; `turn_summary.output` carries the answer:
199
274
 
200
275
  ```
@@ -256,7 +331,9 @@ The Bridge exposes:
256
331
  deletes it, and the Bridge announces `:turn_dequeued`. `200 {status: "removed", enqueued_id, prompt}`, `409 already_started`
257
332
  (a turn took it), `409 not_queued` (a next-step message: a drain may merge it any moment), `404
258
333
  unknown_enqueued_id`. It never wakes the worker. The worker names it in its sidecar features (`unqueue`).
259
- A worker's start prunes the `input/removed/` and `input/settled/` tombstones older than a week
334
+ A worker's start prunes the `input/removed/` and `input/settled/` tombstones and the drain's merge records
335
+ (`input/merged/<enqueued_id>` = `{into, at}`, written by `Worker#pending_input_drain` before it deletes a file it
336
+ merges; their own directory, which a 0.156 waiter never reads) older than a week
260
337
  (`SessionInbox::TOMBSTONE_MAX_AGE`, log `tombstones_pruned`); otherwise they go with the session dir.
261
338
  - `POST /session/:id/relay` — the approval relay, on a delegated child's worker
262
339
  (`{action, relay_id, question_id}`): `opened` / `closed` (with a `reason`) set or clear the