samagotchi 0.193.0 → 0.195.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 (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +116 -1
  3. data/docs/bundle-authoring.md +2 -2
  4. data/docs/bundles.md +223 -12
  5. data/docs/cli.md +27 -11
  6. data/docs/configuration.md +93 -6
  7. data/docs/desktop.md +3 -0
  8. data/docs/guardrails.md +11 -1
  9. data/docs/hooks.md +1 -0
  10. data/docs/internals/attached-context.md +2 -0
  11. data/docs/internals/bridge.md +4 -0
  12. data/docs/internals/engine.md +59 -4
  13. data/docs/internals/knowledge.md +205 -0
  14. data/docs/internals/pages.md +17 -9
  15. data/docs/internals/panes.md +104 -0
  16. data/docs/internals/peers.md +102 -5
  17. data/docs/internals/prompt-caching.md +4 -0
  18. data/docs/internals/session-lifecycle.md +9 -2
  19. data/docs/internals/web-frontend.md +16 -4
  20. data/docs/memory.md +4 -2
  21. data/docs/pages.md +72 -1
  22. data/docs/peers.md +90 -5
  23. data/docs/plugins.md +100 -6
  24. data/docs/releasing.md +1 -1
  25. data/docs/scheduling.md +4 -0
  26. data/docs/sessions.md +23 -7
  27. data/docs/sub-agent.md +6 -4
  28. data/docs/system-one.md +4 -0
  29. data/docs/testing.md +5 -0
  30. data/lib/samagotchi/bridge/card_store.rb +1 -1
  31. data/lib/samagotchi/broadcast/triage_model.rb +17 -0
  32. data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -5
  33. data/lib/samagotchi/bundles/claude-peer/plugin.rb +24 -5
  34. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +28 -7
  35. data/lib/samagotchi/bundles/claude-peer/scripts/pair +31 -8
  36. data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -5
  37. data/lib/samagotchi/bundles/codex-peer/plugin.rb +62 -6
  38. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +23 -2
  39. data/lib/samagotchi/bundles/codex-peer/scripts/pair +28 -7
  40. data/lib/samagotchi/bundles/coordinator/manifest.yml +7 -4
  41. data/lib/samagotchi/bundles/coordinator/plugin.rb +15 -5
  42. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +10 -0
  43. data/lib/samagotchi/bundles/dev/manifest.yml +3 -2
  44. data/lib/samagotchi/bundles/knowledge/adapters.rb +205 -0
  45. data/lib/samagotchi/bundles/knowledge/catalog.rb +151 -0
  46. data/lib/samagotchi/bundles/knowledge/chi_adapters.rb +160 -0
  47. data/lib/samagotchi/bundles/knowledge/chunker.rb +55 -0
  48. data/lib/samagotchi/bundles/knowledge/github.rb +246 -0
  49. data/lib/samagotchi/bundles/knowledge/manifest.yml +25 -0
  50. data/lib/samagotchi/bundles/knowledge/plugin.rb +788 -0
  51. data/lib/samagotchi/bundles/knowledge/query.rb +30 -0
  52. data/lib/samagotchi/bundles/knowledge/query_log.rb +55 -0
  53. data/lib/samagotchi/bundles/knowledge/refresh.rb +133 -0
  54. data/lib/samagotchi/bundles/knowledge/store.rb +264 -0
  55. data/lib/samagotchi/bundles/reflect/manifest.yml +17 -0
  56. data/lib/samagotchi/bundles/reflect/scripts/reflect.rb +439 -0
  57. data/lib/samagotchi/bundles/reflect/skill_reflect.md +100 -0
  58. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  59. data/lib/samagotchi/chi_invocation.rb +7 -0
  60. data/lib/samagotchi/client.rb +18 -0
  61. data/lib/samagotchi/codex_rollout.rb +93 -0
  62. data/lib/samagotchi/config.rb +15 -6
  63. data/lib/samagotchi/effective_model.rb +28 -2
  64. data/lib/samagotchi/engine/cards.rb +9 -4
  65. data/lib/samagotchi/engine/hooks.rb +8 -0
  66. data/lib/samagotchi/engine/models.rb +180 -7
  67. data/lib/samagotchi/engine/side_requests.rb +72 -13
  68. data/lib/samagotchi/engine/toolkit.rb +1 -1
  69. data/lib/samagotchi/engine/turn_helpers.rb +1 -1
  70. data/lib/samagotchi/engine.rb +11 -8
  71. data/lib/samagotchi/engine_snapshots.rb +16 -3
  72. data/lib/samagotchi/events.rb +1 -0
  73. data/lib/samagotchi/guardrails/review_paths.rb +13 -3
  74. data/lib/samagotchi/guardrails_command.rb +3 -9
  75. data/lib/samagotchi/hook_label.rb +19 -0
  76. data/lib/samagotchi/hook_routes.rb +3 -2
  77. data/lib/samagotchi/hooks.rb +3 -1
  78. data/lib/samagotchi/host_registry.rb +146 -16
  79. data/lib/samagotchi/idle_client.rb +13 -2
  80. data/lib/samagotchi/idle_recap.rb +33 -3
  81. data/lib/samagotchi/idle_target.rb +27 -7
  82. data/lib/samagotchi/llm/adapter_common.rb +4 -2
  83. data/lib/samagotchi/llm/anthropic_messages.rb +3 -2
  84. data/lib/samagotchi/llm/errors.rb +35 -4
  85. data/lib/samagotchi/llm/model_listing.rb +19 -0
  86. data/lib/samagotchi/llm/openai_chat.rb +3 -2
  87. data/lib/samagotchi/model_binding.rb +46 -4
  88. data/lib/samagotchi/model_catalog.rb +68 -8
  89. data/lib/samagotchi/model_profile.rb +35 -0
  90. data/lib/samagotchi/models_command.rb +8 -4
  91. data/lib/samagotchi/page_command.rb +90 -6
  92. data/lib/samagotchi/pages/launch.rb +16 -8
  93. data/lib/samagotchi/pages/runner.rb +7 -2
  94. data/lib/samagotchi/pages/runtime.rb +62 -2
  95. data/lib/samagotchi/pages.rb +4 -0
  96. data/lib/samagotchi/panes/kitty.rb +137 -0
  97. data/lib/samagotchi/panes.rb +254 -0
  98. data/lib/samagotchi/peer_announce.rb +245 -0
  99. data/lib/samagotchi/peer_command.rb +97 -11
  100. data/lib/samagotchi/peer_continue.rb +10 -0
  101. data/lib/samagotchi/peer_mailbox.rb +30 -7
  102. data/lib/samagotchi/peer_pair_here.rb +149 -0
  103. data/lib/samagotchi/peer_presence.rb +434 -0
  104. data/lib/samagotchi/peer_say.rb +17 -10
  105. data/lib/samagotchi/peer_wait_expiry.rb +47 -0
  106. data/lib/samagotchi/plugin/api.rb +18 -1
  107. data/lib/samagotchi/plugin/attached_context.rb +46 -1
  108. data/lib/samagotchi/plugin/card.rb +68 -11
  109. data/lib/samagotchi/plugin/context.rb +42 -6
  110. data/lib/samagotchi/plugin/panes.rb +97 -0
  111. data/lib/samagotchi/plugin/peer.rb +52 -10
  112. data/lib/samagotchi/plugin/peer_pairing.rb +290 -0
  113. data/lib/samagotchi/plugin/peer_start.rb +326 -0
  114. data/lib/samagotchi/plugin/peer_start_hook.rb +207 -0
  115. data/lib/samagotchi/plugin/peers.rb +76 -3
  116. data/lib/samagotchi/plugin/project.rb +63 -0
  117. data/lib/samagotchi/plugin/sessions.rb +36 -1
  118. data/lib/samagotchi/plugin/tool_spec.rb +16 -7
  119. data/lib/samagotchi/recap_setup.rb +40 -3
  120. data/lib/samagotchi/self_report.rb +25 -6
  121. data/lib/samagotchi/send_command.rb +6 -6
  122. data/lib/samagotchi/served_lookup.rb +225 -0
  123. data/lib/samagotchi/served_ref.rb +41 -0
  124. data/lib/samagotchi/session.rb +22 -9
  125. data/lib/samagotchi/session_access/contract.rb +6 -0
  126. data/lib/samagotchi/session_access/local.rb +54 -6
  127. data/lib/samagotchi/session_access/remote.rb +4 -4
  128. data/lib/samagotchi/session_access/remote_peers.rb +7 -4
  129. data/lib/samagotchi/session_commands.rb +40 -8
  130. data/lib/samagotchi/session_continue.rb +6 -2
  131. data/lib/samagotchi/session_lifecycle/allowed.rb +4 -2
  132. data/lib/samagotchi/session_manager/delivery.rb +5 -0
  133. data/lib/samagotchi/session_manager/lifecycle.rb +58 -7
  134. data/lib/samagotchi/session_manager/removal.rb +3 -0
  135. data/lib/samagotchi/session_model_settings.rb +7 -3
  136. data/lib/samagotchi/session_stats.rb +436 -0
  137. data/lib/samagotchi/session_stores.rb +9 -0
  138. data/lib/samagotchi/session_window.rb +30 -0
  139. data/lib/samagotchi/sessions_command.rb +16 -3
  140. data/lib/samagotchi/system_one/approval_choice.rb +22 -0
  141. data/lib/samagotchi/system_one/approval_label.rb +4 -6
  142. data/lib/samagotchi/system_one/http_backend.rb +111 -10
  143. data/lib/samagotchi/system_prompt.rb +14 -5
  144. data/lib/samagotchi/terminal_ui/attach_launcher.rb +30 -0
  145. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -1
  146. data/lib/samagotchi/terminal_ui/formatting.rb +26 -12
  147. data/lib/samagotchi/terminal_ui/status_row.rb +20 -3
  148. data/lib/samagotchi/terminal_ui.rb +1 -1
  149. data/lib/samagotchi/testing/boundary.rb +17 -4
  150. data/lib/samagotchi/testing/bundle.rb +6 -2
  151. data/lib/samagotchi/testing/sessions.rb +11 -3
  152. data/lib/samagotchi/toolkit.rb +11 -4
  153. data/lib/samagotchi/toolkit_report_command.rb +14 -18
  154. data/lib/samagotchi/toolkit_suggest.rb +9 -2
  155. data/lib/samagotchi/tools/registry.rb +43 -18
  156. data/lib/samagotchi/tools/tool_index.rb +6 -2
  157. data/lib/samagotchi/turn_endings.rb +6 -2
  158. data/lib/samagotchi/turn_excerpts.rb +298 -0
  159. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +9 -0
  160. data/lib/samagotchi/user_typed.rb +29 -0
  161. data/lib/samagotchi/version.rb +1 -1
  162. data/lib/samagotchi/web/app.rb +8 -20
  163. data/lib/samagotchi/web/participant_review.rb +1 -1
  164. data/lib/samagotchi/web/participant_view.rb +1 -1
  165. data/lib/samagotchi/web/peer_routes.rb +33 -13
  166. data/lib/samagotchi/web/public/app.js +1 -1
  167. data/lib/samagotchi/web/public/card.js +26 -10
  168. data/lib/samagotchi/web/public/context_chips.js +24 -2
  169. data/lib/samagotchi/web/public/copy.js +8 -2
  170. data/lib/samagotchi/web/public/data.js +2 -1
  171. data/lib/samagotchi/web/public/format.js +9 -1
  172. data/lib/samagotchi/web/public/index.html +18 -0
  173. data/lib/samagotchi/web/public/info_bar_model.js +1 -1
  174. data/lib/samagotchi/web/public/model_pick.js +18 -5
  175. data/lib/samagotchi/web/public/model_picker.js +1 -1
  176. data/lib/samagotchi/web/public/peer_chip.js +15 -5
  177. data/lib/samagotchi/web/public/peer_data.js +4 -2
  178. data/lib/samagotchi/web/public/peer_wait.js +36 -0
  179. data/lib/samagotchi/web/public/served_ref.js +9 -0
  180. data/lib/samagotchi/web/public/session_fields.js +1 -0
  181. data/lib/samagotchi/web/public/session_state.js +4 -0
  182. data/lib/samagotchi/web/public/stage_missing.js +23 -6
  183. data/lib/samagotchi/web/public/stream_handlers.js +16 -0
  184. data/lib/samagotchi/web/public/version_notices.js +7 -1
  185. data/lib/samagotchi/web/session_control.rb +19 -10
  186. data/lib/samagotchi/web/session_show.rb +20 -0
  187. data/lib/samagotchi/web/update_ops.rb +2 -2
  188. data/lib/samagotchi/worker/command_queue.rb +3 -0
  189. data/lib/samagotchi/worker/mail.rb +14 -1
  190. data/lib/samagotchi/worker.rb +1 -0
  191. metadata +39 -1
@@ -182,7 +182,8 @@ or `chi web` restart.
182
182
  | `broadcast.*` | Next `chi broadcast` | Each broadcast invocation reads its targeting and triage settings. |
183
183
  | `update.gem`, `update.bundles`, `update.desktop` | Next `chi update` | The command reads which components to update when it runs. |
184
184
  | `update.notify`, `update.check_hours`, `update.min_age_hours`, `update.auto`, `update.restart` | `chi web` start | The update checker starts with chi web; restart it to apply changes. |
185
- | `kitty.*`, `tmux.*` | `chi desktop upgrade` or desktop update | These settings are copied into the desktop helper's launch file. |
185
+ | `kitty.listen_on`, `kitty.binary` | Next pane lookup; `chi desktop upgrade` or desktop update for the helper | Read live by the worker each time it looks for a pane (`/claude pair`'s list, `/claude show`, `/claude start`'s window: [Panes](internals/panes.md)); copied by `chi desktop upgrade` into the desktop helper's launch file. |
186
+ | `kitty.agents`, `tmux.*` | `chi desktop upgrade` or desktop update | These settings are copied into the desktop helper's launch file. |
186
187
  | `model.profile`, `reasoning_history` | Not from config.yml | These are CLI/environment settings; `models:` and `hosts:` provide their model- and host-specific forms. |
187
188
 
188
189
  ### Per-session settings
@@ -238,7 +239,9 @@ A few environment variables are not settings (no config.yml key, no flag):
238
239
  A model's settings come in layers, and the first one set wins. Every surface reads them the same way: a turn,
239
240
  `/model` and `/stats`, `chi self`, the web's chips and the start page's ⚙ panel, and a session list's ctx %. A
240
241
  `models:` entry is looked up under each name the model goes by, the most specific first: the name as typed (an
241
- alias), the alias's target (`host:id`), the part after a host prefix, then the id the host is asked for.
242
+ alias), the alias's target (`host:id`), the part after a host prefix, then the id the host is asked for. A `served` model
243
+ (`main:served`, below) is looked up under the id its host serves now: key per-family settings by that id, not by
244
+ `served` or an alias of it (an alias's entry would apply to every model the host loads).
242
245
 
243
246
  | Setting | Order, first set wins |
244
247
  |---|---|
@@ -1039,6 +1042,66 @@ alias, `/model`, `chi send --new --model`, the web's new-session model and a
1039
1042
  delegate's model. Any other unknown prefix (`nosuch:x`) is sent to the default
1040
1043
  host as the model id.
1041
1044
 
1045
+ ### The model a host serves now (`served`)
1046
+
1047
+ A local server that serves one model at a time (Splash, a single-model llama-server or vLLM) can be named by
1048
+ what it serves now instead of by an id: `host:served` (`main:served`; a bare `served` is the default host's). Then
1049
+ a model swap on the server needs no config edit, and the sessions (and their schedules) follow it.
1050
+
1051
+ ```yaml
1052
+ default:
1053
+ model: main:served
1054
+ model_aliases:
1055
+ splash: main:served
1056
+ ```
1057
+
1058
+ - **What it resolves to:** the one id the host's own `/v1/models` lists now. The declared ids
1059
+ (`hosts.<name>.models`, below) never count. A host that lists none or several (OpenRouter, a gateway,
1060
+ api.anthropic.com) refuses it: the turn fails with `host main lists 3 models (a, b, c); served needs exactly one:
1061
+ pick one with /model`.
1062
+ - **Saved as written:** a session saves `main:served`, never the id, so a resumed, continued, forked or scheduled
1063
+ session resolves again. Each turn records the model it ran on (`/stats` has a segment per id).
1064
+ - **Checked at each turn's start:** one short `GET /v1/models` before the turn's prompt is built (a few ms on a
1065
+ local host; never on a page or Bridge read, which show the id last listed). A change works like a `/model` nobody
1066
+ typed: the prompt is rebuilt, the overlays, notes and profile follow, and the turn shows `host main now serves Y
1067
+ (was X)`. A `--profile` given at start stays.
1068
+ - **A swap mid-turn:** the host refuses the next request, and the turn fails with `host main no longer serves X (it
1069
+ serves Y now): send again to continue on Y`. The next turn follows.
1070
+ - **A host that is down** keeps the id last known (the turn then fails as before, `can't reach host main …`).
1071
+ - **Settings key by the id it runs** (sampling, thinking, window, profile, prices, model notes, overlays,
1072
+ `guardrails.small_models`), as if you had typed that id.
1073
+ - **The system prompt** names both: "this session runs on main:q8 (main:served: whatever host main serves; …)".
1074
+ - **Thinking replay on `api: anthropic`** (the `splash-msg` host above, where `reasoning_history` defaults to `all`):
1075
+ a served change replays the earlier turns' thinking to the new model as `/model` does.
1076
+ - **The word is reserved:** an alias named `served` is ignored with a warning at start.
1077
+ - **Sessions pinned to an explicit id don't follow**: a turn the host refuses as not served fails as before, and
1078
+ when the host lists one other model now the line ends `; host main serves Y now: /model main:served follows it`
1079
+ (one short listing; nothing switches). `/model main:served` moves the session.
1080
+ - **Side requests follow too:** System 1 (`system_one.model: served`), `recap.model`, `broadcast.triage_model`,
1081
+ `ctx.ask_model(model:)` (btw, a block fix, the objectives' check) take `served` like a session's model. They
1082
+ list the host at most every 30 s (a broadcast lists once, in its own process, and a recap asks the id last
1083
+ listed), and a host that refuses the id as not served is listed again and asked once more with the new one
1084
+ (not a broadcast's), within what is left of the first ask's time. A host that is down fails these fast for 30 s
1085
+ after a failed listing (a turn's start always lists). A `base_url:` recap or triage names no host, so
1086
+ `served` means nothing there.
1087
+ - **Where you see it:** chi web's model picker, `chi models` and `/models` offer `host:served` for a host whose own
1088
+ listing names exactly one model, as its host's first row: the picker shows `served` with `now <id>` (its tooltip
1089
+ says the id is as of the hosts' last listing, up to 60 s old), `chi models` prints `main:served → <id>`,
1090
+ `/models` prints `served → <id>` under the host, with any alias of it (`--format json` marks the row
1091
+ `served: true`). A host listing none or several gets no such row. A served session's info bar shows
1092
+ `served · <id>` (its tooltip `main:served → <id>`), the status row `model=main:served·<id>`, `/model`
1093
+ `runtime model: main:served → <id>`, `/stats` a `model:` line `main:served (now <id>)`, and `chi self`
1094
+ `main:served → <id>` (or why it can't run). The id is what the session ran on last (a session no worker runs:
1095
+ its last turn's), and changes at the next generation after a swap.
1096
+ - **Aliases of one model count as several:** Splash's `--served-model-name` names are listed as more
1097
+ `/v1/models` entries (each with `root:` the loaded id), and such a host is refused like any other listing
1098
+ several. Pick one id with `/model`, or drop the extra names.
1099
+
1100
+ Upgrade every chi that reads this config.yml before writing `served` into it: an older chi sends `served` as the
1101
+ model id, and its turns fail.
1102
+
1103
+ This is not the `served:` key of a declared model (next section), which lists the ids a gateway may answer with.
1104
+
1042
1105
  ### Models a host serves but doesn't list
1043
1106
 
1044
1107
  A gateway can serve ids its `/v1/models` never lists (round-robin aliases such
@@ -1391,6 +1454,20 @@ The desktop helper (`chi desktop`) can also paste into agent CLIs (claude,
1391
1454
  codex, …) running in [kitty](https://sw.kovidgoyal.net/kitty/) windows or
1392
1455
  tmux panes. It lists kitty's only with `kitty.listen_on` set: copy the value of `listen_on` from
1393
1456
  your `kitty.conf` as it is (kitty must also have `allow_remote_control` on).
1457
+ The same two settings let a session's worker find a Claude's window (claude-peer's Show) and open one
1458
+ (`/claude start`, `/codex start`; the command it runs is the bundle setting `bundles: claude-peer: start_command:`, a
1459
+ shell line, default `claude`): see [peers.md](peers.md#pairing). Where it opens is the bundle setting `open_in`:
1460
+
1461
+ ```yaml
1462
+ bundles:
1463
+ claude-peer:
1464
+ open_in: pane # the default: a pane next to this session's chi terminal in kitty, else a background tab
1465
+ codex-peer:
1466
+ open_in: tab # always a background tab
1467
+ ```
1468
+
1469
+ A chi terminal in kitty marks its own window for this (the kitty user var `chi_session`, set while it is attached;
1470
+ nothing to configure). Inside tmux it can't, so a start there opens a tab.
1394
1471
 
1395
1472
  ```yaml
1396
1473
  kitty:
@@ -1565,7 +1642,7 @@ toolkit:
1565
1642
  | `full` | every built-in and every plugin tool (a bundle's `chi.tool`, such as `web_search`); the default |
1566
1643
  | `lean` | `execute`, `read`, `write`, `edit`, `memory_read`, `memory_write`, `task_create`, `task_wait`, `task_get`, `task_list`, `task_stop`, `ask_user_question`, `web_fetch`, `context_read` |
1567
1644
  | `child` | `lean` plus `send_note`, without `memory_write`, `delegate`, `delegate_result` |
1568
- | `coordinator` | `lean` plus `delegate`, `delegate_result`, `list_sessions`, `objectives` (declared by the coordinator bundle) |
1645
+ | `coordinator` | `lean` plus `delegate`, `delegate_result`, `list_sessions`, `objectives`, and the knowledge bundle's `knowledge_add`, `knowledge_list`, `knowledge_remove` (declared by the coordinator bundle) |
1569
1646
  | `coding` | `child`, with the prompt text `- Be concise in your responses` / `- Show file paths clearly when working with files` (declared by the coordinator bundle, for build and fix children) |
1570
1647
 
1571
1648
  - **Plugin tools** (a bundle's `chi.tool`, such as web-search's `web_search`) follow a kit's list as built-ins do:
@@ -1576,6 +1653,16 @@ toolkit:
1576
1653
  (`full`, `lean`, `child`; `review` is an ordinary name since there is no review kit). A bundle declares its own with `chi.toolkit`
1577
1654
  ([plugins](plugins.md#chitoolkitname-base-add--remove--prompt-nil-groups-nil-description-nil)).
1578
1655
  `description:` is optional classifier input, up to 300 characters; it is not included in the session prompt.
1656
+ - **`:always` and `:kit` plugin tools.** A bundle may give a tool its own rule (`chi.tool(…, declare:)`,
1657
+ [plugins](plugins.md#declare-which-kits-declare-it)). `declare: :always` is declared by **every** kit, `lean`,
1658
+ `child` and your `kits:` ones included, unless the kit (or the session: `--no-tool`, `/toolkit remove`) removes it:
1659
+ the knowledge bundle's `knowledge_search`. `declare: :kit` is declared only where it is added (a kit's `add:`,
1660
+ `--tool`, `/toolkit add`), never by `full` alone: the knowledge bundle's catalog tools, which the `coordinator`
1661
+ kit adds. Such a tool isn't "left out" of a kit that doesn't add it: no prompt names it (the not-loaded line,
1662
+ `find_tools`' description), so a kit's prompt and declared tools stay as they were; `find_tools` finds it and
1663
+ `call_tool` reaches it as `chi/<name>` where the tool index is up (an MCP server, a kit leaving built-ins out), and
1664
+ it never brings `find_tools`/`call_tool` into a session that had none. `full` with an add stays its own toolkit
1665
+ (`full +knowledge_add`), which declares the add.
1579
1666
  - **Memory kits.** A memory named `toolkit_<name>.md` defines kit `<name>` with one fenced YAML block containing
1580
1667
  optional `base:`, `add:`, `remove:` and `groups:`, plus a required `description:` (up to 300 characters).
1581
1668
  `prompt:` is refused. A memory kit may use a config or bundle kit as its base. Built-ins cannot be redefined.
@@ -2281,7 +2368,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
2281
2368
 
2282
2369
  | Setting | Default | CLI | What it does |
2283
2370
  |---|---|---|---|
2284
- | `default.model` | (required) | `--model` | The model a new session starts with; `host:model` pins a host. |
2371
+ | `default.model` | (required) | `--model` | The model a new session starts with; `host:model` pins a host; `host:served` is whatever that host serves now (The model a host serves now). |
2285
2372
  | `default.input` | none | | Text pre-filled at the first prompt (a trailing space is kept); `--no-default-input` skips it. See [CLI](cli.md). |
2286
2373
  | `default.max_tokens` | server's | yes | Most tokens one generation may produce (`n_predict` on a native llama.cpp host; OpenRouter: 32768 when unset). |
2287
2374
  | `model.profile` | none | `--profile` | Prompt profile for every model (`qwen36`, `gemma4`); env and CLI only. See "Prompt profile". |
@@ -2292,7 +2379,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
2292
2379
  | `server.first_token_timeout` | 120 remote, off local | | Seconds to the first token; `0` = off. `hosts.<name>.first_token_timeout` wins. |
2293
2380
  | `server.stream_idle_timeout` | 120 remote, off local | | Seconds a stream that showed something may go without more; `0` = off. `hosts.<name>.stream_idle_timeout` wins. |
2294
2381
  | `recap.enabled` | on | | `false` (or `recap: false`) turns the idle recap off. Per session too: `--set recap.enabled=false`, or `/recap off` in the session (see "Per-session settings"). |
2295
- | `recap.model` | session's | yes | Model that writes the recap: an id, alias or `host:model` (the host then picks where to ask; a bare id goes where a bare `--model` goes). |
2382
+ | `recap.model` | session's | yes | Model that writes the recap: an id, alias or `host:model` (the host then picks where to ask; a bare id goes where a bare `--model` goes). `main:served` (or `served` with `recap.host_ref`) asks what the host serves now (the id last listed; a not-served refusal lists and asks once more). |
2296
2383
  | `recap.host_ref` | session's | yes | A `hosts:` name to ask (`host:` is accepted too, also a host name, not a model ref). |
2297
2384
  | `recap.base_url` | none | yes | An OpenAI API base to ask instead (`http://h:8081/v1`). |
2298
2385
  | `recap.inactivity` | `180` | yes | Idle seconds before a recap. |
@@ -2341,7 +2428,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
2341
2428
  | `guardrails.system_one.threshold` | `0.8` | | The probability an auto-allow needs. config.yml only. |
2342
2429
  | `guardrails.system_one.min_record` | `5` | | How many clean records a rule needs before System 1 is trusted for it: labelled asks of that rule at the threshold the user allowed. config.yml only. |
2343
2430
  | `system_one.host` | none | | The `hosts:` entry serving `/v1/systemone` (a local Splash, or the hosted Jev API); unset: no judgment, by any use of System 1, so nothing auto-allows and every ask goes to the user. Moved from `guardrails.system_one.host`: while any of host, model and timeout_ms is still under `guardrails.system_one`, chi warns and nothing is judged. config.yml only. |
2344
- | `system_one.model` | none | | The judgment model; unset uses the host's first model, and a host that names none has no judgment. Moved from `guardrails.system_one.model`. config.yml only. |
2431
+ | `system_one.model` | none | | The judgment model; `served` is the one model `system_one.host` lists now (re-listed at most every 30 s; a not-served 422 is asked again once with the new id); unset uses the host's first model, and a host that names none has no judgment. Moved from `guardrails.system_one.model`. config.yml only. |
2345
2432
  | `system_one.timeout_ms` | `2000` | | Milliseconds one judgment may take; a slower one is no judgment and the ask goes to the user. Moved from `guardrails.system_one.timeout_ms`. config.yml only. |
2346
2433
  | `system_one.runs` | `on` | | Save each System 1 ask and what came of it, under the state dir, as long as sessions last (see [System 1's saved runs](system-one.md)); `off` stops saving. config.yml only. |
2347
2434
  | `log.file` | state dir | yes | See "Debug Log File". |
data/docs/desktop.md CHANGED
@@ -150,6 +150,9 @@ and it lands in a session running there.
150
150
 
151
151
  ## Agents in kitty and tmux
152
152
 
153
+ The helper keeps its own list of kitty windows; chi's worker reads kitty itself for claude-peer's Show
154
+ ([internals/panes.md](internals/panes.md): the same `kitty.listen_on` and `kitty.binary`, read live there).
155
+
153
156
  The panel can also send to agent CLIs (claude, codex, gemini, aider, …) running in
154
157
  [kitty](https://sw.kovidgoyal.net/kitty/) windows or [tmux](https://github.com/tmux/tmux) panes, next to chi
155
158
  sessions. Each is off until you set it up; both can be on.
data/docs/guardrails.md CHANGED
@@ -1119,7 +1119,7 @@ local Splash server, or the hosted Jev API — and its key is that host's own
1119
1119
  ```yaml
1120
1120
  system_one: # what every use of System 1 shares
1121
1121
  host: splash # the hosts: entry serving /v1/systemone
1122
- model: Qwen3.8-Flash-Next-GSQ-RCO-GGUF:Q2_0 # else the host's first model
1122
+ model: Qwen3.8-Flash-Next-GSQ-RCO-GGUF:Q2_0 # or served (what the host serves now); else the host's first model
1123
1123
  timeout_ms: 2000 # a slower judgment is no judgment
1124
1124
  guardrails:
1125
1125
  system_one: # approvals' own
@@ -1130,6 +1130,16 @@ guardrails:
1130
1130
  min_record: 5 # clean records a rule needs before it is trusted
1131
1131
  ```
1132
1132
 
1133
+ `system_one.model: served` judges with whatever `system_one.host` serves now (the one id its `/v1/models` lists,
1134
+ as `host:served` does for a session: [configuration.md](configuration.md#the-model-a-host-serves-now-served)).
1135
+ `HttpBackend#target` and `/guardrails` read the id last listed, with no request; an ask lists again when that is
1136
+ older than 30 s, within `timeout_ms`. A host that swapped models answers the ask `422 model X is not served by
1137
+ this endpoint`: the ask re-lists and is asked again once with the new id while 300 ms of `timeout_ms` are left.
1138
+ A host listing none or several models is no judgment, and `/guardrails` says why. The clean record stays
1139
+ model-blind (as a hand edit of `system_one.model` keeps it): each change of the judge logs
1140
+ `system_one_model_changed` (warn, once per change per process), and each saved run names the id that answered.
1141
+ Unset still means the host's first declared model.
1142
+
1133
1143
  `SystemOne::Client.from_config(host_registry:, mode:)` reads these on every
1134
1144
  call, so a config.yml change takes effect on the next ask. `mode: off` (the
1135
1145
  default) or no `system_one.host` means there is no client at all. Anything else is no
data/docs/hooks.md CHANGED
@@ -64,6 +64,7 @@ The plugin class must respond to `#call(event)` — duck-typed, no base class re
64
64
  | `:question_asked` | A question of the model's own (`ask_user_question`) or an approval of its tool call is about to open, on the turn's thread (not a hook's or plugin's `ask_user`, a relayed delegate approval, the step-limit question, a `--non-interactive` run or a stored approval: none of those fire it) | `{ type: :question_asked, kind: "question" \| "approval", text: "..." (the reply that asks, as the lead-in bubble shows it: no thoughts, no tool-call markup), question: {...} (the question's fields, frozen: question/options/header…, an approval's approval: facts too; no id yet), refs: (see [Refs on a question](#refs-on-a-question-display-only)) }` |
65
65
  | `:after_tool_call` | After tool execution | `{ type: :after_tool_call, iteration: N, tool: "read", output: "..." (the text the model gets: capped at max_tool_output_chars (a memory_read's cap is memory.read_max_chars, 0: none); a cut one has a [cut: …] line, at its end, or for an execute result between its head and its tail, the whole output saved in the session's tool_output/ folder), status: "ok" \| "error" \| "blocked" \| "stopped", call: {...} (the call that ran, as the gate left it), elapsed_ms: N (the tool's own run, without an approval wait; nil for a denied call), result: "..." (the tool's own text: no "[read]" lead, no "ran as:" line, never cut) }`; `stopped` is a `task_wait` the turn's Stop ended (the task runs on) or whose task was stopped. Match on `result:`, not `output:`: it is what the tool said (`Error: command timed out after 120s` for an execute killed at its limit in kill mode, `Samagotchi::Tools::Execute::TIMEOUT_PREFIX`; `Still running at the 120s limit: …` for one handed over as a task, `Samagotchi::Tools::Execute::HANDED_OVER`) |
66
66
  | `:session_end` | After each turn `:after_turn` fires for, after it (turn-level lifecycle) | `{ type: :session_end, session_id: "..." }` |
67
+ | `:peer_wait_ended` | Between turns, in a session's worker: its `/<peer> pair` wait ran out with no peer (`PeerWaitExpiry`; the peer bundles say so with `ctx.notify`) | `{ type: :peer_wait_ended, peer: "claude", session_id: "...", minutes: 10 }` |
67
68
 
68
69
  Every event also carries the hook runtime (next section): `hook:` (the label
69
70
  of the hook about to run) and the callables `notify:`, `ask_user:`,
@@ -70,6 +70,8 @@ comment is the file map and [../context.md](../context.md#storage) lists it for
70
70
  `SessionAccess::Remote#context_push`'s body (an older chi web drops it: the answer arrives unlinked). `ContextProviders` resolves a URL to a command source from an installed bundle's
71
71
  manifest `context_providers:` (read from its provenance, so the CLI and chi web resolve without loading plugins);
72
72
  `{url}` is filled at attach, `{bundle_dir}` and `{ruby}` when the command runs.
73
+ - **Read by plugins.** `ctx.context.snapshots` (`Plugin::AttachedContext#snapshots`, the knowledge bundle's context
74
+ source) reads the project location's and this project's sessions' own snapshots' texts, read-only (never a fetch).
73
75
  - **Protected.** The root is a `ProtectedPaths` entry: the file tools cannot write it, because a source's command
74
76
  runs later outside the guardrails gate with the worker's environment ([../context.md](../context.md#safety)).
75
77
 
@@ -256,6 +256,10 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
256
256
  turn no longer runs), while a between-turns card keeps its buttons.
257
257
  - **Version 1.** A file from before the log (top-level `turns`, each entry its own, maybe `running`) is no longer read, so its
258
258
  earlier cards do not show. `SessionManager.cards_empty?` still reads both versions to decide whether a session is empty.
259
+ - **Other readers.** Besides the web and `chi guardrails replay`, `SessionStats` (a page's `runtime.sessions`) reads
260
+ `cards.json` raw, read-only: version 2 only, its approvals and hook notices by turn id, and the caps by
261
+ `CAPACITY`, `NOTICE_TYPES` and `LLM_CONTEXT_TYPES` (the rule `cap_class` keeps private). A change to the entries'
262
+ shape or to those constants must keep it working (`spec/session_stats_spec.rb`).
259
263
  - **An older chi on a version 2 file.** Its `seed` wants an integer `turns`, finds none, and starts with no entries. A chi web not
260
264
  yet restarted only reads: it lists no cards for that session until restarted, and the file stays whole. An older **writer** does
261
265
  damage: at its first saved event, `:turn_started`, it writes `{"version":1,"turns":0,"running":true,"entries":[]}` over the file
@@ -36,9 +36,9 @@ Engine#run_turn(session, prompt, on_event:, …, origin:, continue:, resumed:, r
36
36
  | Step | Where | What it owns |
37
37
  |---|---|---|
38
38
  | `begin_turn` | `engine.rb` | A Verify turn's claim checked (`@verify_anchors.verified`, the sessions dir given); `session.status = RUNNING`; used memories absorbed; the `TurnContext` built **whole** (`new_turn_context`: `GuardrailWiring#begin_turn` gives git, participant and mode; `id:` the caller's or a new uuid; `settings` nil until `generate`), then `TurnState#begin!` publishes it with the controller (a new `CancellationController` when none is given), sink and `input_waiting:` peek in one step; a recap in flight invalidated. `run_turn` sets `turn.resumed` / `turn.resume_from` only on a continue. |
39
- | `prepare_turn` | `engine.rb` | `:turn_started` (an image error raised after it); the toolkit suggestion's `start`; `refresh_profile!`; `turn.prepared_settings = turn_settings(session)` and `refuse_images!`; **STOP CHECK A** (abandons the suggestion `:canceled`); `announce_guardrail_failures`, `start_init_tasks!` / `await_init_tasks`, `apply_staged_tools!`; the suggestion's `settle`, the judge's `start`, the objectives' `incoming`; `apply_toolkit!` (`Registry#toolkit`, `ToolIndex#refresh!`, a prompt rebuild when it changed, a warn per stranded plugin tool); `refresh_participants!`; **STOP CHECK B** (before the hooks run or a reminder is used up); `:session_start` (first turn) and `:before_turn` hooks; `turn_messages`. Its ensure abandons the suggestion `:failed` (nothing once settled) and calls `finish`. |
39
+ | `prepare_turn` | `engine.rb` | `served_turn_start` → `follow_served!` (`engine/models.rb`, a `served` model only: `HostRegistry#refresh_served!` max_age 0, one bounded `GET /v1/models`; a change since `ModelBinding#served_id` pins the new id and resets as `/model` does; before the emit, so `cut_after` is the new model's); `:turn_started` (an image error raised after it, then the served refusal or listing error, else the `host main now serves Y (was X)` notice); the toolkit suggestion's `start`; `refresh_profile!`; `turn.prepared_settings = turn_settings(session)` and `refuse_images!`; **STOP CHECK A** (abandons the suggestion `:canceled`); `announce_guardrail_failures`, `start_init_tasks!` / `await_init_tasks`, `apply_staged_tools!`; the suggestion's `settle`, the judge's `start`, the objectives' `incoming`; `apply_toolkit!` (`Registry#toolkit`, `ToolIndex#refresh!`, a prompt rebuild when it changed, a warn per stranded plugin tool); `refresh_participants!`; **STOP CHECK B** (before the hooks run or a reminder is used up); `:session_start` (first turn) and `:before_turn` hooks; `turn_messages`. Its ensure abandons the suggestion `:failed` (nothing once settled) and calls `finish`. |
40
40
  | `turn_messages` | `engine.rb` | System head + history + due reminders (`:reminder_injected`; none in a participant's turn) + the user message (not on a continue) + the plugins' staged tool loads (`append_tool_loads`, `engine/toolkit.rb`). `turn.messages` is set first and grown in place, so a failure meanwhile keeps what is there. |
41
- | `generate` | `engine.rb` | One `EffectiveModel` **after the hooks** (which may switch the model): `sync_kernel_client!`, the settings completed (`model_name`, `window_setting`, `llm_context`, `price`, `loads_tools`), the turn's `ToolSurface` built, `turn.context.with(…)` published by `TurnState#replace_context`; `turn.limit` (`IterationLimit.for`); `backend(model).complete(…, pending_input: turn_drain(pending_input), reasoning_since:, context:)`. |
41
+ | `generate` | `engine.rb` | One `EffectiveModel` **after the hooks** (which may switch the model; `generate_model`: a served model with no pin yet is listed, max_age 30, and pinned): `sync_kernel_client!`, the settings completed (`model_name`, `window_setting`, `llm_context`, `price`, `loads_tools`), the turn's `ToolSurface` built, `turn.context.with(…)` published by `TurnState#replace_context`; `turn.limit` (`IterationLimit.for`); `backend(model).complete(…, pending_input: turn_drain(pending_input), reasoning_since:, context:)`. |
42
42
  | `complete_turn` / `end_turn` | `engine/turn_end.rb`, `engine.rb` | See "Turn ends" below. |
43
43
  | `@turn_warmup.after` | `TurnStages::Warmup` | Local llama.cpp, native loop only: prefills the next turn's prompt (prompt-caching.md, "The turn-end warm-up"). Never fails the turn. |
44
44
  | `release_turn` | `engine/turn_end.rb` | `TurnState#finish!`, `SteerCut#finished!`, probe cancel swapped back, the context window cache dropped (the next turn asks the server again), steers left logged as dropped, activity recorded, turn-scoped hooks cleared. Then, after the flag is released, the judge's cards and `show_objective_proposals` (the objectives' `finally`: a completed turn's proposal cards shown, any other's dropped). |
@@ -339,6 +339,18 @@ only input (`entries`, `reachable_names`, `left_out_names`, `removed_names`, `st
339
339
  per build before `generate` knows `loads_tools`, `SystemPrompt::Built#surface`; `#warn_stranded`; the
340
340
  suggestion's lists; the index's `#declare` / `#refresh!`). Off the turn thread, from `ToolkitBinding#published`
341
341
  only (`#explained` for `/toolkit` and the snapshot, `ctx.load_tools`).
342
+ - **A plugin tool's `declare:`** (`chi.tool(declare: :kit | :always)`, `Registry::Entry#declare`) has three seats.
343
+ (1) `Registry#declared?`'s nil branch (full) leaves a `:kit` tool out, and `Toolkit::Resolved#declares?` reads it
344
+ (`:always` unless removed; `:kit` only when added); `Resolved#everything?` needs no adds, so `full` + an add is a
345
+ `Resolved` (`ToolkitBinding` maps only an everything-kit to nil). (2) `Registry#reachable?` (what `call_tool`
346
+ reaches: `reachable_names`, so `index_only` and `DeferredTools`; `stranded_names`) takes a `:kit` tool on full
347
+ too, while `#counts_for_index?` (`index_reaches?`) never counts one, so a `:kit` tool never brings the index's
348
+ tools in; `#left_out?` names a `:kit` tool only when removed, and neither `SystemPrompt#not_loaded_line` nor
349
+ `find_tools`' description (`ToolIndex#registry_groups(described: true)`) counts one, so no kit's prompt or
350
+ declared tools change (a kit's chip lists it as reachable; a host that loads tools defers it). (3) The
351
+ toolkit suggestion logs `always_tools` and `kit_tools` apart from `plugin_tools`, and `ToolkitReportCommand#covers?`
352
+ grades a `:kit` one by a kit's adds only. `full`'s request bytes with a `:kit` tool registered are pinned by
353
+ `spec/engine_toolkit_spec.rb`.
342
354
 
343
355
  ## State management
344
356
 
@@ -395,7 +407,50 @@ a bare id to another host, and another process's saved model lists change what a
395
407
  the hooks) and one in `generate` (after them); `system_prompt`, `steer_cut_after` and the warm-up take their own;
396
408
  `stats_snapshot` and `session_state_snapshot` (`EngineSnapshots`, `engine_snapshots.rb`) one each.
397
409
  - Never resolved (they hold on a broken resolve): `effective_model_ref`, `bare_model_name`, `guardrail_model_name`,
398
- `sync_model_key!`, `served_model(probe: false)`.
410
+ `sync_model_key!`, `served_model(probe: false)`, `model_switched_since_last_turn?`.
411
+ - **The id a host is sent has one source**: `HostRegistry#sent_model_id(raw)` (`#bare_name` is its alias), read
412
+ from the parsed ref only (the alias applied, a known host prefix off; no resolve, no model index or saved list,
413
+ no request), and equal to `resolve(raw).bare_model`. Readers that hold an `EffectiveModel` take `#bare` (the
414
+ wire in `generate`, `append_tool_loads`' `tool_changes?`, `served_model_for` with a model); the never-resolving
415
+ ones take `sent_model_id` (`bare_model_name`, so `guardrail_model_name` and `ModelBinding#sync_model_key!`;
416
+ `served_model_for` without a model, `Web::App#saved_served_model`, `Web::ParticipantReview`, `SelfReport`'s
417
+ overlay key and notes, and `IdleTarget.resolve` for a recap or triage setting that names a host). A turn's
418
+ generations are counted under `EffectiveModel#turn_ref` (`generation_model_ref`), and the switch check compares
419
+ `HostRegistry#turn_ref` without a resolve; both are the stored ref (`ModelRef#ref`), except for a served ref.
420
+ - **A served ref** (`main:served`, `ServedRef`; configuration.md, "The model a host serves now"): the id is the one
421
+ the host's own listing has (`ServedLookup`, one per `HostRegistry`). Every reader above stays request-free and
422
+ never raises: `sent_model_id`, `resolve` and `turn_ref` read `ServedLookup#cached` (the last listing, the
423
+ adapter's fresh list, the saved `model_lists.json` with exactly one id), else the word `served`. Only a turn's
424
+ start lists (`HostRegistry#refresh_served!`). **The turn pins its id**: `ModelBinding#served_id` (seeded at
425
+ build and by `switch_model!` with the cached id, moved by `#follow!`), passed by `SessionModelSettings` and
426
+ `ModelBinding#resolve_profile` to `EffectiveModel.of(…, served_id:)` and by `bare_model_name` (so
427
+ `guardrail_model_name`, the notes, the overlay key) to `sent_model_id(…, served_id:)`; a side ask's re-list moves
428
+ the lookup only. `turn_ref` is `host:<id>`, so `/stats` segments per id; `lookup_names` leaves `served` and
429
+ `main:served` out (an alias of it stays). A turn the host refuses as not served (`BadRequest#model_not_served?`)
430
+ fails with `ModelsPart#served_failure_line` (a forced re-list names the new id, once per error: the turn's note
431
+ via `TurnEndings`' `served_line:`, its end event and the one-shot share it). A hook that switches to a served
432
+ model after the start gets its own listing in `generate_model` (the start's choice is `@served_start_choice`).
433
+ An explicit id's not-served turn keeps `failure_summary`'s line and adds `ModelsPart#explicit_served_hint` (one
434
+ bounded listing of that host, kept per error; none when it lists the refused id or several).
435
+ The listing is bounded (1 s open, 2 s read, no retry) and a Stop cuts it (`Client.probe_cancel`).
436
+ Side asks list too, at most every 30 s, and retry once on a not-served refusal when a forced re-list names
437
+ another id (`IdleClient.not_served?`, the `SummarizeError`'s cause): `SideRequestsPart#ask_side_model` (and
438
+ `session_model_recap_target`, the recap's default), `RecapSetup`'s `served_target` with `IdleRecap`'s
439
+ `retarget:` (`IdleTarget.host_named?` is false for a served model, so it is resolved per attempt; an attempt
440
+ reads the id last listed and never lists, since it runs on the idle scheduler's thread; the retry lists on the
441
+ summarize thread), `Broadcast::TriageModel` (one listing, max_age 0, no retry), and System 1's `HttpBackend`
442
+ (its listing capped by what is left of `timeout_ms` and cut by the judgment's Stop; `ServedLookup#cached_refusal`
443
+ lets `#target` refuse with no request). A retry gets what is left of the first ask's timeout. `ServedLookup`
444
+ remembers a failed listing for 30 s (`FAILED_TTL`) for callers with `max_age` > 0, so a down host fails them
445
+ fast; a turn's start (max_age 0) always lists.
446
+ The UIs read the id with no request: `EffectiveModel#served_id` (the pin, else the lookup), as the session
447
+ state's `model_served` (`EngineSnapshots`), `/stats`' `served_ref`/`model_served`, `Engine#served_model_id`
448
+ (`/model`'s `main:served → <id>`, a `:command_ran`'s `model_served`); after that they follow each
449
+ `:generation_completed`'s `requested_model` (the sent id) while the model is served: an id came with it
450
+ (`model_served`; an alias of main:served too, whose `:command_ran` `model_name` is the alias typed) or it is a
451
+ served ref (`ServedRef.stored?`, `served_ref.js isServedRef`). The info bar's `served · <id>` needs only the id. chi web without a worker takes the last turn record's `model_ref`
452
+ (`SessionShow#saved_model_served`). The pickers' row is `ModelCatalog`'s (`served_row`: a `HostListing` whose
453
+ own ids are exactly one, `ServedLookup.one_id`; `web_models` names a served default by it).
399
454
  - Readers on other threads: the Bridge (`/state`, `/stats`, the SSE reset, a steer's cut wait), the worker's
400
455
  command thread, the recap thread, plugin threads.
401
456
  - `ModelChoice` (`ModelBinding#choice`) holds the name and the typed name as **one value**, so a reader never pairs
@@ -626,7 +681,7 @@ edit must keep:
626
681
  `Tools::Builtins.registry`, `ToolkitBinding`, `Tools::ToolIndex`, `PeerRegistry`, then the plugins; each plugin's
627
682
  `ctx` is a `Plugin::Context` over `plugin_host`). After the plugins (or none), `@tool_index.declare(@tools)`
628
683
  registers `find_tools` + `call_tool` (source "index", not core), declared per toolkit by `Registry#declared?`
629
- (`Toolkit::Resolved#declares?` treats built-ins and plugin tools alike).
684
+ (`Toolkit::Resolved#declares?` treats built-ins and plugin tools alike, but for a plugin tool's `declare:`).
630
685
  - `wire_kernel` gives the kernel one `KernelLoop::Services` (Engine-lifetime: hooks, tools, reminder store, mutes,
631
686
  question handler, peers, gate, warm-up, generation guard); the client is no service (a model switch swaps it,
632
687
  `sync_kernel_client!`).
@@ -0,0 +1,205 @@
1
+ # The knowledge bundle: store, catalogs, refresh, adapters
2
+
3
+ The user side is [bundles.md](../bundles.md#the-knowledge-bundle). The code is `lib/samagotchi/bundles/knowledge/`:
4
+ `plugin.rb` (the tools, `/knowledge`, the hooks) and its parts, loaded first in this order: `store.rb` (`Store`),
5
+ `query.rb` (`Query`), `chunker.rb` (`Chunker`), `adapters.rb` (`FolderAdapter`, `MemoriesAdapter`),
6
+ `chi_adapters.rb` (`SessionsAdapter`, `ContextAdapter`), `github.rb` (`GithubAdapter`), `catalog.rb` (`Catalog`),
7
+ `refresh.rb` (`Refresh`), `query_log.rb` (`QueryLog`). It is written only against the plugin API: the core seams it
8
+ needs are `chi.tool(declare:)` ([plugins.md](../plugins.md#declare-which-kits-declare-it); the three seats are in
9
+ [engine.md](engine.md#toolsurface)), `ctx.project`, `ctx.sessions.list` / `present_ids` (`SessionStats.summaries`,
10
+ the listing reflect's counts read too) and `ctx.context.snapshots`.
11
+
12
+ ## The store: the sqlite3 CLI
13
+
14
+ One SQLite file per catalog, `index.db`, through the system `sqlite3` CLI (no gem: nothing to build on a user's
15
+ machine or a pod). Every run is
16
+
17
+ ```
18
+ Open3.capture3(SQLITE, "-init", "/dev/null", "-safe", "-bail", "-nofollow", ["-json",] db, stdin_data: sql)
19
+ ```
20
+
21
+ - **`-init /dev/null`**: with piped stdin the CLI still reads `$XDG_CONFIG_HOME/sqlite3/sqliterc` (and
22
+ `~/.sqliterc`); a user's `.headers on` / `.mode box` would break the `-json` parse.
23
+ - **`-safe`** refuses `.shell`, `.system`, `.output`, `.once`, `.read`, `.import`, `.open`, `ATTACH`, `writefile()`,
24
+ `readfile()`, `edit()`, `.save`, `.backup`, `.cd`. So one catalog per call: no cross-file query.
25
+ - **Values are hex.** The SQL text is constant per operation and goes on stdin, never argv. Every value goes in as
26
+ `cast(x'<hex>' as text)`: a batch is one hex-literal JSON array read with `json_each`, and the FTS5 MATCH string
27
+ (which the bundle builds, `Query`) is hex too. A title like `x'; drop table items; --\n.shell echo PWNED` is stored
28
+ as text. Numbers (`since`, `limit`) are `Integer()`s.
29
+ - **`-nofollow`** refuses a db reached through a symlinked path and can't create one. So the catalog folder is
30
+ `File.realpath`ed (and `ctx.data_dir` once), and the db is made in Ruby first with `CREAT | EXCL | NOFOLLOW`,
31
+ mode 0600 (`-wal` / `-shm` inherit it); folders are 0700. It is made as `index.db.new`, given its schema (WAL,
32
+ checkpointed, its `-wal`/`-shm` removed) and renamed to `index.db`: a search finds no db or a whole one, never an
33
+ empty file (`no such table`) or one switching to WAL.
34
+ - **Searches read-write under `pragma query_only=1`**, not `-readonly`: Apple's `-readonly` fails on a WAL db whose
35
+ `-wal`/`-shm` are gone (another binary, a restore, deleted them). A search never waits on a write transaction
36
+ (WAL). `-json` prints nothing (not `[]`) for no rows.
37
+ - **Every run starts `.timeout 2000`** (`Store::BUSY_MS`; the dot-command, since `pragma busy_timeout` prints a row
38
+ into `-json`). Each run is its own process, so each is often the db's sole connection, and a sole connection takes
39
+ an exclusive lock when it opens (WAL recovery) and closes (the checkpoint) the db. With no busy timeout a search
40
+ meeting that lock answered `database is locked` (CI saw it; a stress loop of searches beside a writer, ~1 in 4).
41
+ The lock lasts a few ms; the timeout waits it out (and a writer, for another's transaction).
42
+ - **The load probe** (`Plugin#probe`, once per worker at plugin load, a few ms) runs the real shapes in `:memory:`:
43
+ an FTS5 table, a hex `json_each` insert, a `snippet()`/`bm25()` select with a hex MATCH. A CLI that fails it gets no
44
+ tools (no dead `:always` tool in every session), one `Log.warn`, and `/knowledge` says why. `needs: [sqlite3]` is
45
+ advisory.
46
+
47
+ ```sql
48
+ create table items(id integer primary key, source text, key text, title text, ptr text, url text, path text,
49
+ updated_at integer, sig text, unique(source, key));
50
+ create table chunk_map(chunk integer primary key, item integer, line integer);
51
+ create virtual table chunks using fts5(title, body, tokenize='porter unicode61'); -- no prefix= (+33 % size)
52
+ create table meta(k text primary key, v text); -- the schema version
53
+ ```
54
+
55
+ A schema version other than `Store::SCHEMA_VERSION` drops the file and builds it again (re-creatable data). Writes
56
+ are `begin immediate` transactions of at most 1.5 MB of JSON each (the 2 s busy timeout), under the catalog's
57
+ `index.lock`.
58
+
59
+ **The query** (`Query`): words with no letter or digit are dropped (`"login" AND "--"` finds nothing; an empty MATCH
60
+ is a syntax error: an empty query is refused), each kept word quoted, the last also a prefix (`"sqli"*`), joined by
61
+ AND; under 3 hits an OR pass fills up, ranked after. Ranking is `bm25(chunks, 5.0, 1.0)` (title, body), ties by the
62
+ newer item; one hit per item.
63
+
64
+ **The chunker** (`Chunker`): at most 1,500 chars on line boundaries, a markdown heading starts a chunk, its title is
65
+ the file's name and the nearest heading; text is scrubbed to valid UTF-8; a NUL in the first 8 KB is binary, skipped.
66
+
67
+ ## Catalogs
68
+
69
+ ```
70
+ $XDG_STATE_HOME/samagotchi/plugins/knowledge/ (ctx.data_dir, realpath'd once; dirs 0700, files 0600)
71
+ projects/<project key>/ catalog.json index.db (+ -wal, -shm) queries.jsonl index.lock sources/<name>.lock
72
+ clones/<owner>__<repo>__<digest>/ (a github source's shallow clone)
73
+ system/ the same, for sessions in no project
74
+ catalogs/<name>/ the same, for named catalogs
75
+ ```
76
+
77
+ - `Catalog.locate`: `catalog: NAME` (`[a-z0-9][a-z0-9-]{0,31}`, not `system` or `projects`) → `catalogs/NAME`; else
78
+ `ctx.project.key` → `projects/<key>` (a key that isn't a safe path segment becomes `p_<sha256 prefix>`); else
79
+ `system/`.
80
+ - `catalog.json` holds the sources (name, kind, location, max_age, why, globs, refreshed_at, last_error, items,
81
+ chunks, skipped counts; a github source's `clone`, a sessions or context source's `project_root`, `listed_at`),
82
+ `removed_defaults`, `seeded` and notes. It is read without a lock and written
83
+ (`AtomicFile.write`, 0600) only under `index.lock`, which every index write takes too.
84
+ - **Defaults**, seeded once at a project or system catalog's first use: `project-docs` (kind folder, the project
85
+ root, `FolderAdapter::DOCS_INCLUDE`, tracked only; only when the root is in a git work tree, else a note) and
86
+ `chi-memories` (the project's and the system memories dirs; the system catalog the system dir only). A named
87
+ catalog has none. A removed default stays removed.
88
+
89
+ ## Refresh: at search time only
90
+
91
+ - **When:** only when `knowledge_search` (or `knowledge_add`, for its source) runs. The stale check reads
92
+ `catalog.json` only (`now - refreshed_at > max_age`): a fresh source costs no walk and no `stat`.
93
+ - **Budget:** the selected stale sources refresh on a thread the search waits for at most `refresh_budget_ms` (1500;
94
+ `knowledge_add` 10 s for its own source), sessions sources last (a first listing reads every session file). A
95
+ `github` source refreshes on a thread of its own the search never waits for (`Refresh.new(background:)`), unless
96
+ it is its own `knowledge_add`. A named catalog's sessions or context source refreshes only from a session in the
97
+ project recorded at its add (`project_root`): `ctx.sessions` / `ctx.context` read the calling session's project. Past it the answer is read from the index as it is, the age line says
98
+ `refreshing now`, and the thread finishes. It is handed `ctx.cancel_controller` (a cancelled turn stops it between
99
+ groups of 200 items) and is **not joined at worker exit**: a killed `sqlite3` child is safe under WAL, and the next
100
+ refresh redoes that batch.
101
+ - **Locks:** `sources/<name>.lock`, `flock` without waiting, per refresh: one held elsewhere (another worker) is
102
+ skipped (`refreshing elsewhere`). `index.lock` exclusive around each write transaction and `catalog.json` write.
103
+ Readers take none.
104
+ - **Diff:** an adapter lists items with a `sig` (a file's `mtime:size`, a blob sha, a session's `updated_at`, a
105
+ snapshot's revision); only items whose sig changed are read and re-chunked, the gone ones deleted by `chunk_map`.
106
+ An adapter with `#gone(old_keys)` lists only what changed (the sessions one, since the source's `listed_at`, the
107
+ start of its last good refresh, less 2 s; dropped when the source is added again, and ignored when the index holds
108
+ no rows for it, so a rebuilt or deleted index lists in full) and says itself which old keys are gone. An adapter with `#chunks(item)`
109
+ makes its own chunks (a session's: `line` = the message index).
110
+ - **Failures** stay on the source (`last_error`, its time) and show in the age line; old rows stay searchable.
111
+ - A participant's search refreshes only the sources it selected (never a chi one).
112
+
113
+ ## Adapters
114
+
115
+ `items → [Item(key, sig, title, ptr, url, path, updated_at)]`, `text(item) → String | nil`, `skipped → counts`.
116
+
117
+ - **`FolderAdapter`**: inside a git work tree its tracked files only (`git -C DIR ls-files -z`, env
118
+ `GitEnv::UNSET`), else a `Find` walk skipping dot folders, `node_modules`, `vendor`, `tmp`. Each file through
119
+ `File.lstat`: a symlink is never followed, a file whose realpath leaves the root is skipped, so is one
120
+ `ctx.project.secret_name?` names (on its path relative to the root: the denylist's name half, `ReviewPaths
121
+ .secret_name?`), one over 1 MiB, past `max_files` (20,000). `knowledge_list` shows the counts, never names. Root
122
+ refusals (`FolderAdapter.refusal`): `/`, the home folder or above, anything under (or holding) `ctx.project.chi_dirs`
123
+ or the memories dirs (chi data goes through kind `chi`, so the participant rule holds), and a root
124
+ `ctx.project.secret_root?` matches (`~/.ssh`). The guardrail votes first through the tool's `targets:` (a folder's
125
+ `{ paths: [location] }`, a read); the adapter re-checks.
126
+ - **`MemoriesAdapter`**: the top-level `.md` files of `ctx.project.memories_dir` and `system_memories_dir` (not
127
+ `index.md`, not `.trash` or other folders), an overlay (`name.<model-key>.md`) under its memory's name. Pointer
128
+ `memory_read NAME scope`.
129
+ - **`GithubAdapter`** (`github.rb`): `GithubAdapter.parse` is the location's only door (D1): `OWNER/REPO[@REF][:SUBPATH]`
130
+ or `https://github.com/OWNER/REPO[/tree/REF[/SUBPATH]]`; `OWNER` `[A-Za-z0-9][A-Za-z0-9-]{0,38}`, `REPO`
131
+ `[A-Za-z0-9._-]{1,100}` and not `.`/`..`, no part starting with `-`, `REF` with no `..`, whitespace or control
132
+ characters and `git check-ref-format --allow-onelevel REF` (argv) passing, `SUBPATH` relative with no `..` segment.
133
+ `REF` is a branch or a tag: it goes to `clone --branch`, which takes no commit sha. The URL form's `/tree/REF/PATH`
134
+ can't tell a branch with a `/` from its path (`feature/x` reads as branch `feature`, path `x`): that one is
135
+ `OWNER/REPO@feature/x:docs`.
136
+ The clone is `clones/<owner>__<repo>__<digest of the location>/` (two refs of one repo, a case-insensitive disk):
137
+ `gh repo clone --no-upstream OWNER/REPO DIR.partial -- --depth 1 --single-branch --no-tags --config <SAFE>…
138
+ [--branch REF]` (gh's parser takes no `--` before its positionals: the validated name and the bundle's folder are
139
+ its only ones), renamed into place. `SAFE` (`GithubAdapter::SAFE`, a `--config` each on the clone, a `-c` each on
140
+ every other git spawn): `core.hooksPath=/dev/null`, `core.fsmonitor=false`, `protocol.allow=never`,
141
+ `protocol.https.allow=always`, `protocol.ssh.allow=always`, `submodule.recurse=false` (no `file://`, `ext::` or
142
+ other transport a repo's config could name; the spec's git wrapper alone adds `protocol.file.allow=always` for
143
+ its `file://` origin). A pull: `git <SAFE> -C DIR -c credential.helper= -c 'credential.helper=!gh auth
144
+ git-credential' fetch --depth 1 --no-tags origin -- REF|HEAD`, then `reset --hard FETCH_HEAD`; a failing one
145
+ clones again. Every spawn: no shell,
146
+ env `GitEnv::UNSET` + `GIT_TERMINAL_PROMPT=0` + `GIT_LFS_SKIP_SMUDGE=1`, its own process group killed after 120 s.
147
+ The listing is `git ls-tree -r -z --full-tree HEAD` (blob shas are the sigs): symlinks (120000) and submodules
148
+ (160000) skipped, then the folder rules on the clone-relative path. Pointer `OWNER/REPO:path:line`, URL
149
+ `https://github.com/OWNER/REPO/blob/<commit>/<path>#L<line>` (a participant's `read` of the clone, under chi's
150
+ state dir, is denied; the URL isn't). `updated_at` is the HEAD commit's time. `knowledge_remove` deletes the clone.
151
+ - **`SessionsAdapter`** (`chi_adapters.rb`): `ctx.sessions.list(changed_since:)` (`SessionStats.summaries` of the
152
+ session's project, or of no project: no test_run or scratch session, archived ones kept), each changed session read
153
+ with `ctx.sessions.read` (the saved file, or a live worker's snapshot): user messages with no kind or `input` and no
154
+ `source`, model messages with no kind; never `tool_response`, a steer, a system note or `thinking`, nor the user
155
+ messages chi writes: a `!cmd` line (`"!(cmd)\n<output>"`, no `turn_id`: `Steer.shell_line?`'s shape, checked in
156
+ the bundle) and `/continue no`'s reason line (an `opening_id`, no `turn_id`). Every message's text and the
157
+ session's title go through `Redact.text(text, Redact::Viewer.new(cwd: nil))` before they are chunked, as
158
+ `TurnExcerpts` and `ObjectivesRecord` do: a key by shape (`sk-…`, `ghp_…`, …) or by name (`token=…`) is stored
159
+ as `[redacted]`, and home as `~`. Chunks of
160
+ ≤ 1,500 chars, `line` = the index of the message a chunk starts at. Pointer `s:<id>`, rendered `knowledge_search
161
+ open: s:<id>#<line>`. `#gone` = the old keys not in `ctx.sessions.present_ids`. A session that can't be read
162
+ (`ctx.sessions.read` raising) keeps the source's `listed_at` at its `updated_at` (`Refresh`: the min of the
163
+ listing's start and each unread item's), so the next listing reads it again. A named catalog's source added again
164
+ from another project (its `project_root` changes) drops its rows first: they are the old project's, which no id
165
+ sweep removes (`present_ids` is every saved session, not one project's). **The id sweep:** every search that
166
+ selects a sessions source deletes the rows of ids no longer in `present_ids` (~2 ms) before the query, and the
167
+ searching session's own rows are excluded in the query (`Store#search(skip:)`: a project catalog is shared, so
168
+ another session indexes yours). Measured here: listing 407 session files 0.2 s; `Session.load` of this project's 171
169
+ sessions 0.3 s (15,556 user/model messages, 1.4 M chars; `ctx.sessions.read` also asks a running worker for its
170
+ snapshot, not measured): a source's first, full listing costs about 0.5 s before the chunking and the index
171
+ writes, which is why sessions refresh last and past the budget finish in the background.
172
+ - **`ContextAdapter`**: `ctx.context.snapshots` (this project's sources and its sessions' own; read-only, never a
173
+ command), one item per source with a text, key `project/<name>` or `session:<id>/<name>`, sig its revision. A hit
174
+ reads `context_read NAME` when this session has that source attached at that scope (`ctx.context.list`), else
175
+ `knowledge_search open: c:<key>#<line>`. Not redacted: it is a fetched outside text, like a folder's or a
176
+ repository's file (secret-named files are skipped, contents kept), and a redaction that joins a private key's
177
+ lines would move the `c:<key>#<line>` pointers off `context_read`'s lines.
178
+ - **`open:`** reads `Store#chunks_of(key, sources:)` (the chunks of that item in the catalog's chi sessions or
179
+ context sources). A long message's pieces share its line, so a pointer past a line's first chunk is
180
+ `#<line>.<part>` (`Store#search` returns each row's `part`); `open:` shows the chunk at the pointer (else the last
181
+ one before it) and the rest of its line's while they fit 4 KB, with the pointers of the chunks before and after. From the index only; an `s:` pointer at a session no longer in `ctx.sessions.present_ids` is refused before its
182
+ rows are read (a session deleted since the last search's sweep). It writes no query-log line (it is logged as a
183
+ follow-up of the search before it).
184
+
185
+ ## Participants
186
+
187
+ `ctx.turn_author` set: `knowledge_search` drops the `chi` sources before the query (a `sources:` of only chi ones is
188
+ refused; the age line says they were left out) and refuses `catalog:` (a named catalog spans projects; the participant
189
+ was invited to one session). `open:` refuses (every pointer it reads is chi data). `knowledge_add` /
190
+ `knowledge_list` / `knowledge_remove` refuse. A participant's `/` line
191
+ is a 403 already, so `/knowledge` is the owner's.
192
+
193
+ ## The query log and the embeddings gate
194
+
195
+ `queries.jsonl` beside the index, 0600, one line per search: `at, session_id, toolkit, model, catalog, query, words,
196
+ sources, since, hits, top (pointers), stale (names), ms, author (owner|participant)`. An `after_tool_call` hook
197
+ appends the **next 3 tool calls of the same turn** after a search, raw: `{after: <the search's at>, tool, arg}`
198
+ (`arg`, at most 200 chars: a plugin tool's `path` / `name` / `url` / `open` / `query` argument; a built-in's
199
+ target, the flattened call's (`Tools::BuiltinCalls.build`) `path`, else its main argument in `content` (`read`'s
200
+ path, `execute`'s command; a `write` logs its file, never its body), never the tool's name; a `knowledge_search
201
+ open:` is a follow-up, a new search is not); a `before_turn` ends the count. At 5 MB the
202
+ file moves to `queries.1.jsonl` (one kept). Nothing is classified in the bundle: an offline script reads it when the
203
+ Build 3 gate (embeddings) is checked: after ≥ 4 weeks and ≥ 100 owner searches, embeddings are planned only if ≥ 10 %
204
+ of searches are re-searched where the second query hit what the first missed, and a hand check finds most of those
205
+ are meaning misses.
@@ -10,9 +10,11 @@ The user side is [pages.md](../pages.md). This is how a run happens and what it
10
10
  | `pages/builder.rb` | `Builder` (the script's `ui`: `text`, `table`, `walk`) and `TableBlock` (columns, formats, key columns, cells, the total) |
11
11
  | `pages/store.rb` | `Store`: read, list, `record_run`, `record_failure`, `locked`, `remove`, `file_id`, `remove_temporary_outputs` |
12
12
  | `pages/runner.rb` | `Runner.run(argv)`: the runner process's whole job |
13
- | `pages/runtime.rb` | `Runtime`, a script's `runtime`: `#schedules` (`ScheduleList`, `Schedule`, `Run`, `Unreadable`) |
13
+ | `pages/runtime.rb` | `Runtime`, a script's `runtime` (`Runtime.new(page:)`, the run's page from `Runner::Collector.new(name)`): `#schedules` (`ScheduleList`, `Schedule`, `Run`, `Unreadable`), `#sessions` (`SessionStats.read`), `#turn_excerpts` (`TurnExcerpts.read`), `#launch_dir` (`Pages::LAUNCH_DIR_KEY`), `#settings` (the bundle's `settings:` keys of `ConfigFile.bundle_settings`) |
14
+ | `session_stats.rb` (core) | `SessionStats.window` (the one listing seat: window, filters, project pick, cap) and `.read` (its counts: `Listing`, `Project`, `SessionCounts`, `TurnCounts`, `FAILURE_KINDS`) |
15
+ | `turn_excerpts.rb` (core) | `TurnExcerpts.read`: given turns' failing calls (`Result`, `Excerpt`, `Call`), redacted and cut, the one text reader |
14
16
  | `pages/bundled.rb` | `Bundled`: the pages installed bundles ship (a manifest's `pages:`), `Page#refusal` |
15
- | `pages/launch.rb` | `Launch.run(name, timeout:, cancelled:)`: the one launch path |
17
+ | `pages/launch.rb` | `Launch.run(name, timeout:, cancelled:, launch_dir:)`: the one launch path; sets `CHI_PAGE_LAUNCH_DIR` (`Pages::LAUNCH_DIR_KEY`, defined in `pages.rb` so the runner never loads this file) |
16
18
  | `page_command.rb` | `chi page run | list | rm` |
17
19
 
18
20
  `pages.rb` requires json, digest, time, `inline_widgets`, `paths` and `atomic_file`, and autoloads its parts. Nothing
@@ -20,9 +22,13 @@ it reaches at load requires the engine, the config, the web, the plugins, `Child
20
22
  loads it alone. `launch.rb` is the only file that needs `ChildEnv` and `ProcessGroup`, and nothing in `pages.rb`
21
23
  requires it. Two parts load more, and only when used: `Runtime#schedules` requires `schedules.rb` (which reaches the
22
24
  config, `SessionManager` and `ProcessGroup`; about 70 ms) when a script calls it, and `Bundled` requires
23
- `installed_bundles.rb` (the config) when a name has no script of the user's. `spec/pages_runtime_spec.rb` pins it: a
24
- real runner process running a user's page that never calls `runtime` has loaded no `runtime.rb`, `schedules.rb` or
25
- `config.rb`.
25
+ `installed_bundles.rb` (the config) when a name has no script of the user's. `Runtime#sessions` requires
26
+ `session_stats.rb` (the session file, analytics, `CardStore`'s constants, `SessionWindow` and so the config: 75
27
+ files, about 20 ms on the Studio) and `Runtime#turn_excerpts` `turn_excerpts.rb` (`SessionPaths`, `AnalyticsFile`,
28
+ `Redact`: about 1 ms). `#launch_dir` loads nothing, and `#settings` loads the config only for a bundle's page (whose
29
+ run has loaded it already through `Bundled`). `spec/pages_runtime_spec.rb` pins it: a real runner process running a
30
+ user's page that never calls `runtime` has loaded no `runtime.rb`, `schedules.rb`, `config.rb`, `session_stats.rb`,
31
+ `turn_excerpts.rb` or `launch.rb`, and one calling `runtime.settings` or `runtime.launch_dir` no `config.rb`.
26
32
 
27
33
  **The resolver.** `Pages.script_path(name)` is the script a name runs: the user's `NAME.rb` when it exists, else the
28
34
  page of that name an installed bundle ships (`Bundled.find`), else the user's path (no such page). Every read and run
@@ -62,8 +68,9 @@ script 152 against 73 preloaded libraries and a stale `PWD`). It costs about 70
62
68
  `ChildEnv.unbundled` (an installed gem's Bundler changes undone),
63
69
  `ChildEnv.unset` (the spawner's guardrails settings and session markers), `Launch.cleared_keys` unset
64
70
  (`CHI_REMOTE`, every `SAMAGOTCHI_WORKER_*` key and the vendor agent markers `AgentCaller::VENDOR_MARKERS`:
65
- `CLAUDECODE`, `CODEX_THREAD_ID`, `AI_AGENT`, read from those constants), `Paths.absolute_xdg`, and `PWD` set to the
66
- pages folder (spawn's `chdir:` doesn't change it). So a run never goes remote, never looks like a worker's child,
71
+ `CLAUDECODE`, `CODEX_THREAD_ID`, `AI_AGENT`, read from those constants, and `CHI_PAGE_LAUNCH_DIR`), then
72
+ `CHI_PAGE_LAUNCH_DIR` set to the caller's `launch_dir:` (`chi page run`'s `Dir.pwd`; a Refresh passes none, so it
73
+ stays unset), `Paths.absolute_xdg`, and `PWD` set to the pages folder (spawn's `chdir:` doesn't change it). So a run never goes remote, never looks like a worker's child,
67
74
  and a script's `chi send` is the owner's even from a chi web started in an agent's pane. "This chi's lib" is
68
75
  `File.expand_path("../..", __dir__)` from `pages/launch.rb`: a checkout and an installed gem alike.
69
76
  3. stdout and stderr are each read by a `ProcessGroup::PipeReader` (64 KB, the tail kept).
@@ -216,7 +223,8 @@ owner's `~/.claude/plans/evals/0016-pages-skill/`.
216
223
 
217
224
  ## Later builds
218
225
 
219
- - `runtime` has one method, `schedules`, with its first page (the schedules bundle). A method comes with its first
220
- caller: sessions, a session's stats, a config value are the candidates.
226
+ - `runtime` has `schedules` (its first page: the schedules bundle), and, experimental, `sessions`, `turn_excerpts`,
227
+ `launch_dir` and `settings` (their first page: the reflect bundle). A method comes with its first caller.
228
+ `launch_dir` is not a page parameter: it is only where the run was typed.
221
229
  - Not planned yet: picks on a page, parameters, a live install (the hub watches the pages folder only, so a bundle's
222
230
  page shows on the next list read).