samagotchi 0.192.0 → 0.194.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 (190) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +128 -1
  3. data/docs/architecture.md +3 -3
  4. data/docs/bundle-authoring.md +1 -1
  5. data/docs/bundles.md +82 -40
  6. data/docs/cli.md +47 -17
  7. data/docs/configuration.md +75 -8
  8. data/docs/context.md +8 -5
  9. data/docs/desktop.md +3 -0
  10. data/docs/guardrails.md +20 -5
  11. data/docs/hooks.md +1 -0
  12. data/docs/internals/bridge.md +3 -1
  13. data/docs/internals/bundles.md +2 -2
  14. data/docs/internals/engine.md +46 -3
  15. data/docs/internals/pages.md +4 -4
  16. data/docs/internals/panes.md +66 -0
  17. data/docs/internals/participants.md +5 -3
  18. data/docs/internals/peers.md +176 -27
  19. data/docs/internals/prompt-caching.md +6 -1
  20. data/docs/internals/remote-sessions.md +6 -0
  21. data/docs/internals/session-lifecycle.md +12 -4
  22. data/docs/internals/web-frontend.md +106 -22
  23. data/docs/internals/working-set.md +5 -1
  24. data/docs/peers.md +150 -27
  25. data/docs/plugins.md +48 -7
  26. data/docs/releasing.md +30 -2
  27. data/docs/scheduling.md +3 -2
  28. data/docs/sessions.md +16 -7
  29. data/docs/sub-agent.md +6 -4
  30. data/docs/system-one.md +4 -0
  31. data/docs/testing.md +38 -3
  32. data/docs/thin-clients.md +27 -11
  33. data/lib/samagotchi/bridge/card_store.rb +1 -1
  34. data/lib/samagotchi/broadcast/triage_model.rb +17 -0
  35. data/lib/samagotchi/bundles/claude-peer/manifest.yml +8 -5
  36. data/lib/samagotchi/bundles/claude-peer/plugin.rb +24 -5
  37. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +61 -24
  38. data/lib/samagotchi/bundles/claude-peer/scripts/pair +31 -8
  39. data/lib/samagotchi/bundles/codex-peer/manifest.yml +8 -5
  40. data/lib/samagotchi/bundles/codex-peer/plugin.rb +62 -6
  41. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +57 -19
  42. data/lib/samagotchi/bundles/codex-peer/scripts/pair +28 -7
  43. data/lib/samagotchi/bundles/coordinator/manifest.yml +2 -2
  44. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +31 -0
  45. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  46. data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
  47. data/lib/samagotchi/bundles/mcp/plugin.rb +0 -7
  48. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  49. data/lib/samagotchi/chi_invocation.rb +7 -0
  50. data/lib/samagotchi/client.rb +18 -0
  51. data/lib/samagotchi/codex_rollout.rb +93 -0
  52. data/lib/samagotchi/compat.rb +8 -1
  53. data/lib/samagotchi/config.rb +19 -6
  54. data/lib/samagotchi/continue_offer.rb +13 -1
  55. data/lib/samagotchi/delivery.rb +2 -2
  56. data/lib/samagotchi/effective_model.rb +28 -2
  57. data/lib/samagotchi/engine/cards.rb +9 -4
  58. data/lib/samagotchi/engine/hooks.rb +8 -0
  59. data/lib/samagotchi/engine/models.rb +197 -7
  60. data/lib/samagotchi/engine/plugins.rb +2 -0
  61. data/lib/samagotchi/engine/side_requests.rb +72 -13
  62. data/lib/samagotchi/engine/toolkit.rb +1 -1
  63. data/lib/samagotchi/engine/turn_helpers.rb +1 -1
  64. data/lib/samagotchi/engine.rb +11 -8
  65. data/lib/samagotchi/engine_snapshots.rb +16 -3
  66. data/lib/samagotchi/events.rb +1 -0
  67. data/lib/samagotchi/guardrails/pair_boundary.rb +49 -18
  68. data/lib/samagotchi/hooks.rb +3 -1
  69. data/lib/samagotchi/host_registry.rb +146 -16
  70. data/lib/samagotchi/idle_client.rb +13 -2
  71. data/lib/samagotchi/idle_recap.rb +33 -3
  72. data/lib/samagotchi/idle_target.rb +27 -7
  73. data/lib/samagotchi/jsonl_store.rb +13 -2
  74. data/lib/samagotchi/llm/adapter_common.rb +4 -2
  75. data/lib/samagotchi/llm/anthropic_messages.rb +14 -2
  76. data/lib/samagotchi/llm/errors.rb +35 -4
  77. data/lib/samagotchi/llm/model_listing.rb +19 -0
  78. data/lib/samagotchi/llm/openai_chat.rb +8 -2
  79. data/lib/samagotchi/llm/prompt_cache.rb +5 -0
  80. data/lib/samagotchi/model_binding.rb +46 -4
  81. data/lib/samagotchi/model_catalog.rb +68 -8
  82. data/lib/samagotchi/model_profile.rb +35 -0
  83. data/lib/samagotchi/models_command.rb +8 -4
  84. data/lib/samagotchi/pages/launch.rb +1 -1
  85. data/lib/samagotchi/panes/kitty.rb +122 -0
  86. data/lib/samagotchi/panes.rb +185 -0
  87. data/lib/samagotchi/peer_announce.rb +245 -0
  88. data/lib/samagotchi/peer_cold.rb +92 -0
  89. data/lib/samagotchi/peer_command.rb +121 -20
  90. data/lib/samagotchi/peer_continue.rb +42 -16
  91. data/lib/samagotchi/peer_exchanges.rb +7 -0
  92. data/lib/samagotchi/peer_mailbox.rb +50 -10
  93. data/lib/samagotchi/peer_pair_here.rb +149 -0
  94. data/lib/samagotchi/peer_presence.rb +434 -0
  95. data/lib/samagotchi/peer_receipts.rb +33 -6
  96. data/lib/samagotchi/peer_say.rb +46 -21
  97. data/lib/samagotchi/peer_wait_expiry.rb +47 -0
  98. data/lib/samagotchi/plugin/api.rb +13 -1
  99. data/lib/samagotchi/plugin/card.rb +68 -11
  100. data/lib/samagotchi/plugin/context.rb +33 -2
  101. data/lib/samagotchi/plugin/panes.rb +54 -0
  102. data/lib/samagotchi/plugin/peer.rb +170 -63
  103. data/lib/samagotchi/plugin/peer_pairing.rb +290 -0
  104. data/lib/samagotchi/plugin/peer_start.rb +301 -0
  105. data/lib/samagotchi/plugin/peer_start_hook.rb +207 -0
  106. data/lib/samagotchi/plugin/peers.rb +89 -9
  107. data/lib/samagotchi/recap_setup.rb +40 -3
  108. data/lib/samagotchi/self_report.rb +25 -6
  109. data/lib/samagotchi/send_command.rb +6 -6
  110. data/lib/samagotchi/served_lookup.rb +225 -0
  111. data/lib/samagotchi/served_ref.rb +41 -0
  112. data/lib/samagotchi/session_access/contract.rb +6 -0
  113. data/lib/samagotchi/session_access/local.rb +149 -40
  114. data/lib/samagotchi/session_access/remote.rb +4 -4
  115. data/lib/samagotchi/session_access/remote_peers.rb +8 -5
  116. data/lib/samagotchi/session_chain/links.rb +8 -3
  117. data/lib/samagotchi/session_commands.rb +40 -8
  118. data/lib/samagotchi/session_continue.rb +11 -6
  119. data/lib/samagotchi/session_lifecycle/allowed.rb +4 -2
  120. data/lib/samagotchi/session_manager/delivery.rb +5 -0
  121. data/lib/samagotchi/session_manager/lifecycle.rb +58 -7
  122. data/lib/samagotchi/session_manager/removal.rb +3 -0
  123. data/lib/samagotchi/session_manager/spawn.rb +6 -1
  124. data/lib/samagotchi/session_model_settings.rb +7 -3
  125. data/lib/samagotchi/session_stores.rb +25 -11
  126. data/lib/samagotchi/sessions_command.rb +16 -3
  127. data/lib/samagotchi/system_one/http_backend.rb +111 -10
  128. data/lib/samagotchi/system_one/runs.rb +5 -2
  129. data/lib/samagotchi/system_prompt.rb +11 -4
  130. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -1
  131. data/lib/samagotchi/terminal_ui/formatting.rb +26 -12
  132. data/lib/samagotchi/terminal_ui/status_row.rb +20 -3
  133. data/lib/samagotchi/terminal_ui.rb +1 -1
  134. data/lib/samagotchi/testing/boundary.rb +0 -1
  135. data/lib/samagotchi/testing/bundle.rb +6 -2
  136. data/lib/samagotchi/testing/host.rb +1 -0
  137. data/lib/samagotchi/testing/recorder.rb +3 -0
  138. data/lib/samagotchi/turn_endings.rb +6 -2
  139. data/lib/samagotchi/user_typed.rb +29 -0
  140. data/lib/samagotchi/version.rb +1 -1
  141. data/lib/samagotchi/web/app.rb +8 -20
  142. data/lib/samagotchi/web/participant_review.rb +1 -1
  143. data/lib/samagotchi/web/participant_view.rb +1 -1
  144. data/lib/samagotchi/web/peer_routes.rb +40 -15
  145. data/lib/samagotchi/web/public/agent_rows.js +206 -0
  146. data/lib/samagotchi/web/public/agent_runs.js +595 -0
  147. data/lib/samagotchi/web/public/answer_fold.js +41 -44
  148. data/lib/samagotchi/web/public/app.js +4 -4
  149. data/lib/samagotchi/web/public/block_fix.js +1 -1
  150. data/lib/samagotchi/web/public/card.js +26 -10
  151. data/lib/samagotchi/web/public/cards_place.js +6 -4
  152. data/lib/samagotchi/web/public/context_chips.js +24 -2
  153. data/lib/samagotchi/web/public/copy.js +8 -2
  154. data/lib/samagotchi/web/public/data.js +2 -1
  155. data/lib/samagotchi/web/public/format.js +9 -1
  156. data/lib/samagotchi/web/public/history_reveal.js +5 -2
  157. data/lib/samagotchi/web/public/index.html +56 -2
  158. data/lib/samagotchi/web/public/info_bar_model.js +1 -1
  159. data/lib/samagotchi/web/public/model_pick.js +18 -5
  160. data/lib/samagotchi/web/public/model_picker.js +1 -1
  161. data/lib/samagotchi/web/public/page_view.js +1 -1
  162. data/lib/samagotchi/web/public/pages.css +1 -7
  163. data/lib/samagotchi/web/public/peer_chip.js +15 -5
  164. data/lib/samagotchi/web/public/peer_data.js +4 -2
  165. data/lib/samagotchi/web/public/peer_mailbox_api.js +2 -1
  166. data/lib/samagotchi/web/public/peer_note.js +4 -2
  167. data/lib/samagotchi/web/public/peer_row.js +37 -0
  168. data/lib/samagotchi/web/public/peer_wait.js +36 -0
  169. data/lib/samagotchi/web/public/quiet_notes.js +12 -1
  170. data/lib/samagotchi/web/public/revise_stack.js +5 -2
  171. data/lib/samagotchi/web/public/send_turn.js +11 -3
  172. data/lib/samagotchi/web/public/served_ref.js +9 -0
  173. data/lib/samagotchi/web/public/session_fields.js +1 -0
  174. data/lib/samagotchi/web/public/session_state.js +4 -0
  175. data/lib/samagotchi/web/public/stage_missing.js +23 -6
  176. data/lib/samagotchi/web/public/stream_handlers.js +16 -0
  177. data/lib/samagotchi/web/public/turn_block.js +4 -0
  178. data/lib/samagotchi/web/public/version_notices.js +7 -1
  179. data/lib/samagotchi/web/session_control.rb +19 -10
  180. data/lib/samagotchi/web/session_show.rb +20 -0
  181. data/lib/samagotchi/web/update_ops.rb +2 -2
  182. data/lib/samagotchi/worker/command_queue.rb +3 -0
  183. data/lib/samagotchi/worker/mail.rb +24 -1
  184. data/lib/samagotchi/worker.rb +8 -5
  185. data/lib/samagotchi/worker_inbound/mail.rb +34 -6
  186. data/lib/samagotchi/worker_inbound.rb +11 -3
  187. data/lib/samagotchi/worker_link.rb +13 -1
  188. data/lib/samagotchi/worker_wakes.rb +33 -5
  189. metadata +22 -2
  190. data/lib/samagotchi/web/public/pages_group.js +0 -67
data/docs/plugins.md CHANGED
@@ -931,12 +931,13 @@ full label, `plugin.rb (bundle my-bundle)`.
931
931
  | `ctx.frontend` | what runs the session, read now: `:one_shot` (`-p --non-interactive`: one turn, then exit) or `:worker` (a session worker: the web, an attached TUI). There is no `:repl` any more: a bundle that checks for it never matches. Only a worker's answers reach the web while it runs; a one-shot's show there once the session is opened. Until the host sets it (while the plugins load, inside `Engine.new`) it reads `:one_shot`, so read it in hooks and init tasks, not in `register` |
932
932
  | `ctx.continues` | the id of the session this one continues (a [continue](sessions.md#session-chains)'s new link), else nil |
933
933
  | `ctx.fork?` | whether the session is a fork (`ctx.sessions.fork`): it has a parent but isn't a delegate child, and started from a conversation, so its first prompt isn't its first user message |
934
- | `ctx.model` | the model the session runs on now: its resolved ref (`host:id`), right after `/model` too |
934
+ | `ctx.model` | the model the session runs on now: its resolved ref (`host:id`), right after `/model` too. A served model is its saved ref (`main:served`), not the id it resolves to (that id is in the turn's records: `/stats`' segments, `model_ref`), so a plugin comparing it against config keeps working |
935
935
  | `ctx.model_key` | that model's memory overlay key (`<name>.<key>.md`, what `memory_write current_model_only` writes) |
936
936
  | `ctx.model_names` | the names chi's own per-model config looks that model up under (a `models:` map in config.yml): as typed (an alias), the alias's target, the resolved ref, without the host, the bare id; deduped, most specific first, frozen (`[]` when it doesn't resolve). Match a map of yours over them downcased, first hit, as chi does. Needs chi 0.132.0 |
937
937
  | `ctx.cost` | the session's spend so far, read now, as a frozen value: `total` (USD, reported + estimated, side requests included; 0.0 before any), `reported` (by providers, `usage.cost`), `estimated` (from `hosts.<name>.models` prices; a generation is one or the other, never both), `side` (recap, `/btw`, `ask_model`: their share of `total`) and `known?` (false while generations or side requests ran but none was reported or priced, so a limit on it can't be enforced; a session with some priced generations reads known, the unpriced ones counting 0). It includes the running turn's finished generations and what earlier workers of the session spent. Use its methods, not its class. Needs chi 0.83.0 |
938
938
  | `ctx.usage` | the session's work so far, read now, as a frozen value: `turns` (finished ones and the running one), `tool_calls` and `tool_calls_by_tool` (every call, running ones included; canonical names: an alias counts under its tool, a `call_tool` call under the inner tool), `steps` (the loop rounds that dispatched tools, `/stats`' iterations) and `active_ms` (`active_minutes` too): work time, the generations' time plus the finished tool calls' time, never the waits between them (a question, an approval, the user's answer to `ask_user_question`), with `tool_ms_by_tool` its tool part by tool, so a waiting tool's time (`task_wait`) can be left out. Its counts are the ones `/stats` and `chi sessions stats` show, earlier workers' included. Use its methods, not its class. Needs chi 0.100.0 (guard it with `ctx.respond_to?(:usage)`) |
939
939
  | `ctx.turn_author` | who wrote the running turn when it isn't the session's owner: a participant's `"p:<id>"` (`chi share`); nil for the owner's turns and between turns. Every hook event of such a turn carries the same as `author:`. The handler runs with the owner's power whatever the author ([hooks](hooks.md#participants-turns)): `ctx.secrets` works there, so don't start a sign-in on such a turn. Needs chi 0.105.0 (guard it with `ctx.respond_to?(:turn_author)`) |
940
+ | `ctx.turn_interactive?` | whether the running turn was sent from a screen that shows a question and can answer it now: the owner's web tab or TUI (their first prompt, and a Continue tap on such a turn, too), and a thin client's `POST …/ask` (`web:unnamed`), which can answer a question through `…/answer`. False between turns and for every other turn (`chi send`'s, a schedule's, a delegate's, a wake turn, a participant's, a one-shot run), where a `ctx.ask_user` would wait with nobody to answer it: decide without asking there. The peer bundles' dormant send asks only when it is true. Needs the next chi (guard it with `ctx.respond_to?(:turn_interactive?)`) |
940
941
  | `ctx.tool_id` | inside a tool's block, the run's own id (chi's tool id, `"t41"`), the one a two-arg `refs:` lambda got for its row ([Refs on a tool's row](#refs-on-a-tools-row)); nil anywhere else (a hook, a command, a thread the block started) and for a run with none. Needs chi 0.181.0 (guard it with `ctx.respond_to?(:tool_id)`) |
941
942
  | `ctx.settings` | the bundle's settings, frozen: config.yml's `bundles: <bundle>:` with the session's own `--set` values laid over it ([Per-session settings](#per-session-settings)); the config alone until the session is bound (in `register` and `chi.ctx`) |
942
943
  | `ctx.data_dir` | `$XDG_STATE_HOME/samagotchi/plugins/<bundle>/`, created on first use: what the bundle keeps across sessions |
@@ -1029,6 +1030,17 @@ ctx.card(id: id, title: "Build finished", body: "no warnings left") # replaces
1029
1030
  needs chi 0.183.0: set `requires_chi: ">= 0.183.0"` in the bundle by hand
1030
1031
  (`chi bundle check` can't see an action's keys); an older chi refuses the
1031
1032
  card with `ArgumentError`.
1033
+ - `rows:` (optional) is a list to pick from, up to 8 `{title:, sub:}` (one line each, control characters taken out): the web draws each row with
1034
+ its title, its sub line under it and its own buttons, the actions whose `row:` is its index (0-based), up to 3 a
1035
+ row and apart from the card's 6; the terminal prints each row, its `→` lines indented under it. An action with
1036
+ `primary: true` is drawn solid in the web (the others are ghost buttons). claude-peer's "Claude Code sessions
1037
+ here" is one: a row per Claude, Show and Pair on each. A card with rows is never a notice.
1038
+
1039
+ ```ruby
1040
+ ctx.card(title: "Claude Code sessions here", rows: [{ title: "coordinator", sub: "~/p/s · started 3 h ago" }],
1041
+ actions: [{ label: "Show", command: "/claude show 1a2b3c4d", row: 0 },
1042
+ { label: "Pair", command: "/claude pair 1a2b3c4d", row: 0 }])
1043
+ ```
1032
1044
  - `level:` is `:info` or `:warn` (the warning colour).
1033
1045
  - An `:info` card with no actions and a body of one short line (up to 160
1034
1046
  characters) is a notice: the web shows it as a one-line row,
@@ -1039,7 +1051,7 @@ ctx.card(id: id, title: "Build finished", body: "no warnings left") # replaces
1039
1051
  web updates the card in place; the terminal prints it again, marked
1040
1052
  `(updated)`. A card that waits for something (a model's answer) shows
1041
1053
  first, then is replaced.
1042
- - A bad card (no title, a bad level or action) raises `ArgumentError`.
1054
+ - A bad card (no title, a bad level, action or row) raises `ArgumentError`.
1043
1055
 
1044
1056
  Where it shows:
1045
1057
 
@@ -1644,16 +1656,44 @@ a quiet `chi.init` task.
1644
1656
  ctx.peers.link("claude") # => #<data PeerLink peer="claude", address="/tmp/…sock", paired_at="…", from="…"> or nil
1645
1657
  ctx.peers.left_behind("claude") # the previous link's pairing, in a continue's new link; else nil
1646
1658
  ctx.peers.message("claude", 12) # => #<data PeerMessage serial=12, text="…", summary="…", wake=true, re="s-ab12cd", at="…"> or nil
1659
+ ctx.peers.message("claude", 3, box: "1a2b3c4d") # box: the note's box, or the continued session's id8 (its mailbox)
1647
1660
  ctx.peers.last_message("claude") # the newest message still in the mailbox, or nil
1661
+ ctx.peers.here("claude") # the live Claude Code sessions of this project that announced themselves (PeerHere)
1662
+ ctx.peers.pair("claude", address: "/tmp/…sock", from: "…", peer_session: "…") # => PeerPaired (status :paired, or a refusal)
1663
+ ctx.peers.unpair("claude") # => PeerUnpaired (unpaired:, waited:): ends the pairing and the wait
1664
+ ctx.peers.wait("claude") # this session waits 10 min for one; .waiting(name): the wait (stale? until_at)
1665
+ ctx.peers.claim("claude") # takes the wait before pairing against it (nil: none to take); .release(claim)
1666
+ ctx.peers.claimed?("claude") # another pairing holds the wait right now (a pair then writes nothing)
1667
+ ctx.panes.find(pid: 1234) # the kitty window a pid runs in (title, cwd), or nil
1668
+ ctx.panes.show(pane) # brings it to the front: only when ctx.user_typed? (else raises)
1669
+ ctx.panes.open(command: argv, cwd: dir, title: "…") # a background kitty tab: a PaneRef; only when ctx.user_typed?
1670
+ ctx.panes.alive?(ref) # its window is still there
1671
+ ctx.panes.paste(ref, text, enter: true) # one bracketed paste, then Enter: only when ctx.user_typed? (false: gone)
1672
+ ctx.peers.stop_waiting("claude", mark) # ends the wait #wait returned, only while it is that one
1673
+ ctx.user_typed? # this command was typed or tapped by a person at a UI (never chi send or a tool)
1648
1674
  ```
1649
1675
 
1650
1676
  What a peer bundle reads of its peer's side of the session (the mailbox,
1651
1677
  [peers.md](peers.md)): the pairing (`address` nil: the peer answers only) and
1652
- the peer's messages. Read only: the peer pairs and says through `chi peer`,
1653
- and the worker takes the messages. A continue leaves the pairing with the
1654
- previous link, so a new link's `link` is nil until the peer pairs again;
1655
- `left_behind` is the one the previous link kept (`Plugin::Peer#tell_moved`
1656
- tells the peer the new id there). Needs the next chi.
1678
+ the peer's messages. The peer says through `chi peer`, and the worker takes
1679
+ the messages; a pairing from chi's side goes through `pair` (the same writer
1680
+ as `chi peer pair`, its refusals), against the peers that announced
1681
+ themselves here (`here`, [internals/peers.md](internals/peers.md#who-is-here-peerpresence))
1682
+ and the session's wait (`wait`, `claim`). `ctx.panes`
1683
+ ([internals/panes.md](internals/panes.md)) finds a pid's window; its `show`,
1684
+ `open` and `paste` act as the user on their screen, so they run only under
1685
+ `ctx.user_typed?` (else `Plugin::Panes::NotTyped`), which is also what gates a
1686
+ write to another agent's settings. `open` raises
1687
+ `Samagotchi::Panes::Unavailable` when no kitty answers ("kitty isn't running or
1688
+ `kitty.listen_on` isn't set"), its one refusal. Keep a `PaneRef` in your own
1689
+ session state (`ctx.session_dir`), never in the mailbox; `ctx.panes` takes a ref
1690
+ only on a socket `kitty.listen_on` names, and a caller checks what runs in the
1691
+ window before it pastes. The seam is an accident guard: no tool call, `chi send`,
1692
+ agent, participant, schedule, delegate or plugin path reaches it. A wait that runs out fires
1693
+ `:peer_wait_ended` between turns ([hooks.md](hooks.md#hook-events)). A continue copies the pairing to the new
1694
+ link, so its `link` is the previous link's pairing as it was; `left_behind`
1695
+ is the one the previous link keeps (the copy's source; an older chi left the
1696
+ new link unpaired). Needs the next chi.
1657
1697
 
1658
1698
  ### Context providers in the manifest
1659
1699
 
@@ -1883,6 +1923,7 @@ bundle.set(declared_tools: %w[read]) # ctx.declared_tools (d
1883
1923
  bundle.set(cost: 2.5) # ctx.cost: reported USD, or { reported:, estimated:, side:, known: }
1884
1924
  bundle.set(usage: { tool_calls: 40, active_ms: 600_000 }) # ctx.usage: { turns:, tool_calls:, tool_calls_by_tool:, steps:, active_ms:, tool_ms_by_tool: }
1885
1925
  bundle.set(turn_author: "p:p_0123abcd") # a participant's turn: ctx.turn_author, and author: on every event
1926
+ bundle.set(turn_interactive: false) # ctx.turn_interactive? (default true: the owner's turn from a screen)
1886
1927
  bundle.set(session_settings: { "cap" => 1 }) # the session's --set values (Bundle.load takes session_settings: too)
1887
1928
  bundle.tool_loads.last.names # ctx.load_tools calls; set(load_tools_staged: [...]) limits what they stage
1888
1929
  bundle.pair_peer("claude", address: "/tmp/c.sock") # a peer's side, as chi peer pair writes it (ctx.peers.link); address: nil answers only
data/docs/releasing.md CHANGED
@@ -76,7 +76,7 @@ as the GitHub release body.
76
76
  | `rake lint` / `rake lint:fix` | RuboCop over the repo (must report no offenses; CI runs it) / its safe autocorrect (`rubocop -a`). |
77
77
  | `rake gem:validate`, `gem:build`, `gem:install`, `gem:clean` | Check the gemspec; build the gem into `pkg/`; build and install it locally; remove the built gems. |
78
78
  | `rake release:draft_changelog` | A draft Unreleased section from the commit subjects since the last tag, grouped. Stdout only. |
79
- | `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG, a compatibility corpus at `spec/compat/X.Y.Z/` written through the current state writers (with `wire/`: a real Engine and Bridge's replies, recorded twice and refused if the two differ), refreshed `spec/shared/compat_wire/*.json` fixtures, `spec/web/public/exports_baseline.json` rebuilt from the public modules, and `requires_chi: ">= X.Y.Z"` for each bundle marked `requires_chi_next` (the marker dropped), then a profile left below a member's `requires_chi` raised to it, with a patch bump of its version (none when it moved since the last tag) and named in the CHANGELOG's "Update with `chi update`" line, and each entry an `# Unreleased` comment in `Plugin::Api::SINCE` or `BundleManifest::SINCE` names moved into the table at X.Y.Z (the comment dropped). No commit; commit the corpus, fixtures and baseline with the release. |
79
+ | `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG, a compatibility corpus at `spec/compat/X.Y.Z/` written through the current state writers (with `wire/`: a real Engine and Bridge's replies and, in `wire/remote/`, chi web's answers to `chi --remote`, recorded twice and refused if the two differ), refreshed `spec/shared/compat_wire/*.json` fixtures, `spec/web/public/exports_baseline.json` rebuilt from the public modules, and `requires_chi: ">= X.Y.Z"` for each bundle marked `requires_chi_next` (the marker dropped), then a profile left below a member's `requires_chi` raised to it, with a patch bump of its version (none when it moved since the last tag) and named in the CHANGELOG's "Update with `chi update`" line, and each entry an `# Unreleased` comment in `Plugin::Api::SINCE` or `BundleManifest::SINCE` names moved into the table at X.Y.Z (the comment dropped). No commit; commit the corpus, fixtures and baseline with the release. |
80
80
  | `rake release:check` | Clean tracked tree, VERSION == system bundle, a CHANGELOG section, no `requires_chi_next` left, no `# Unreleased` comment left in `Plugin::Api::SINCE` or `BundleManifest::SINCE`, `bundles:check`, `rake lint` (RuboCop) + `npm run lint` (the web frontend's ESLint), rspec (both roots: `spec` and the bundles' own `spec/`) + `rake bundles:specs` + npm test, `gem build`, then a clean install into a temp GEM_HOME that runs `chi --version`, `chi self` and `chi bundle list` with a temp HOME. Needs the network (gem dependencies). |
81
81
  | `rake release:notes[X.Y.Z]` | Prints the CHANGELOG section (default: the current VERSION). |
82
82
 
@@ -113,7 +113,18 @@ The agent does each step and stops where the user has to say yes.
113
113
  (a new time, a random id, a measured number). Pin it in
114
114
  `CompatWire.normalise` (`*_ms`, `*_ms_sum` and `age` are pinned already, as is `last_turn.seconds`;
115
115
  an id the script chooses is better pinned at its source), check `spec/release/compat_wire_spec.rb`,
116
- and run the bump again (nothing is written when it stops). The new
116
+ and run the bump again (nothing is written when it stops). `wire/remote/`
117
+ holds what chi web answers `chi --remote` (`script/release/compat_remote.rb`,
118
+ `CompatRemote`: a real `Web::App` over a fixed state folder, no worker), one
119
+ `{method, path, query, request, status, reply}` file per call; it is
120
+ recorded twice too (a remote file's difference is pinned in
121
+ `CompatRemote.pin`). A bump also stops when any wire file names the
122
+ recording's machine ("names the recording's machine (/private/)": a /private
123
+ realpath, a chi-compat- temp folder or the home folder the normaliser
124
+ missed; the temp folder is `/compat-fixture` and the chi checkout
125
+ `/compat-project` already), or when chi web would start a worker. Corpora
126
+ recorded before 0.193.0 still hold the checkout's path in their AGENTS.md
127
+ prompt part; they are left as released. The new
117
128
  VERSION may pass a compat shim's `remove_after` (`Compat::SHIMS`): once the
118
129
  shim is also at least 14 days old (`added_on`, `Compat::MIN_AGE_DAYS`),
119
130
  `spec/compat_spec.rb` names it, and the shim goes (or its date moves)
@@ -122,6 +133,9 @@ The agent does each step and stops where the user has to say yes.
122
133
  rebuilds `spec/web/public/exports_baseline.json` from every public module
123
134
  except `vendor/`; commit both with the release. If either refresh fails, the
124
135
  bump is already written; follow its rerun command before reviewing or committing.
136
+ The corpus also holds System 1's judgments log (`guardrails/judgments.jsonl`), its saved runs
137
+ (`system_one/runs/`) and the context candidates' record (`context_candidates.jsonl`), written by
138
+ `CompatMachineStores`; the bump stops when one names this machine.
125
139
  5. **Check.** Add all release files, including the new compatibility corpus, then run it:
126
140
  `git add -A && git commit -m "Release X.Y.Z"` and `bundle exec rake release:check`.
127
141
  Fix anything it finds in new commits and run it again.
@@ -154,6 +168,20 @@ If the run fails before `gem push`, fix it on main, delete the tag
154
168
  version that reached rubygems.org can never be pushed again: fix forward with
155
169
  the next patch version.
156
170
 
171
+ ## Bumping WorkerLink::PROTOCOL
172
+
173
+ `WorkerLink::PROTOCOL` (the `protocol` in a worker's `bridge.json`) is what an older chi web, terminal or schedule
174
+ tick refuses a newer worker on (`Skew`: 502 `worker_newer`, "Lost the session's worker", a skipped session), so a bump
175
+ makes every un-restarted older reader refuse every worker of the release. An additive link change (a new sidecar key,
176
+ Bridge route or `Bridge::FEATURES` name) is no bump: clients check a feature name, not a version. Bump only when an
177
+ older client would do damage driving a newer worker: a sidecar key, route or feature name removed, renamed or given a
178
+ new meaning, or the secret rule changed. Every bump needs the owner's OK and a CHANGELOG line ("older chi web and
179
+ terminals refuse workers of this release until restarted"). A worker on an older protocol is never refused (a restart
180
+ is suggested, never gated). `spec/worker_link_contract_spec.rb` holds each protocol's list (sidecar keys with their
181
+ JSON type, routes, features): it fails when an entry of the current protocol's list is missing. The fix is a bump with
182
+ a new list under the new number, the old list kept as history; removing the entry is not. The policy's one place in
183
+ code is the `PROTOCOL` comment in `lib/samagotchi/worker_link.rb`.
184
+
157
185
  ## One-time setup
158
186
 
159
187
  Done once, before the first release, in one sitting (the pending publisher
data/docs/scheduling.md CHANGED
@@ -47,8 +47,9 @@ text, and one that starts with `!` is refused by `chi schedule add` and `schedul
47
47
  An entry stored with one before that fails when it fires (toward its `max_failures`),
48
48
  before anything is started or delivered. A chi web
49
49
  (or cron tick) still running an older chi starts chain links without the origin, so
50
- restart it after updating. Like `register_reminder`, the schedule tools are owner-voiced:
51
- a participant's turn is denied them ([guardrails.md](guardrails.md)).
50
+ restart it after updating. A participant's turn is denied the schedule tools
51
+ ([guardrails.md](guardrails.md)): like `register_reminder`, `schedule_task` and
52
+ `cancel_schedule` are owner-voiced, and `list_schedules` reads the owner's schedules.
52
53
 
53
54
  ## The two modes
54
55
 
data/docs/sessions.md CHANGED
@@ -43,7 +43,7 @@ Retention and manual prune/clean silently stop each deleted session's verified b
43
43
 
44
44
  **Always attached:** every interactive `chi` (plain, `-p`, `--resume ID`, `--attach ID`, `chi scratch`) runs its session in a background worker and attaches to it; there is no setting for it. The worker runs in the session's `working_directory`, so `!commands` and tools see the directory the session was started in. Only `chi -p TEXT --non-interactive` runs its one turn in this process; while it does, the session can't be attached ("in use by a one-turn chi --non-interactive run or an older chi's terminal"). See [CLI: Sharing a session](cli.md#sharing-a-session).
45
45
 
46
- **Who may wake a session:** every turn delivery names its sender (`SessionManager.deliver_turn` requires `client_id`), and the sender's kind picks what it may do to the worker (`ClientId.wake_kind`, `SessionInbox::WakePolicy.for_sender`). A person — `chi send`, a web tab, an attached terminal — starts an idle session, un-stops a stopped one and brings back an archived link. Nobody's message goes into a session being deleted (409 `session_deleting`, *Deleting a session* above), nor into one a transition holds right now (a continue's critical part: 409 `link_continued` naming the new link, else `transition_busy`; chi send and an ask try again, a schedule skips; docs/internals/session-lifecycle.md, Arrivals declare their hold). A schedule's firing, a plugin's `ctx.sessions.send`, a `delegate` follow-up, a participant's turn, an agent's `chi send` (`agent:<name>`, [driver and visitor](sub-agent.md#an-agents-messages-driver-and-visitor)), another session's `ask_session` and any sender chi doesn't name start an idle session only: a session its owner stopped or archived refuses them (409 `session_stopped`, "the session is stopped; only its owner's message starts it again", or `session_archived`, "…brings it back"), nothing written. A schedule counts that as a skip (and skips a stopped session at its check, [scheduling.md](scheduling.md)); `delegate` says it as `Error: session <id8> refused: …`; a plugin gets `Error`. A turn already handed to a live worker is that worker's, as before. chi web's owner turn and command routes name a body that carries no `client_id` as `web:unnamed` (a web tab's rights).
46
+ **Who may wake a session:** every turn delivery names its sender (`SessionManager.deliver_turn` requires `client_id`), and the sender's kind picks what it may do to the worker (`ClientId.wake_kind`, `SessionInbox::WakePolicy.for_sender`). A person — `chi send`, a web tab, an attached terminal — starts an idle session, un-stops a stopped one and brings back an archived link. Nobody's message goes into a session being deleted (409 `session_deleting`, *Deleting a session* above), nor into one a transition holds right now (a continue's critical part: 409 `link_continued` naming the new link, else `transition_busy`; chi send and an ask try again, a schedule skips; docs/internals/session-lifecycle.md, Arrivals declare their hold). A schedule's firing, a plugin's `ctx.sessions.send`, a `delegate` follow-up, a participant's turn, an agent's `chi send` (`agent:<name>`, [driver and visitor](sub-agent.md#an-agents-messages-driver-and-visitor)), another session's `ask_session` and any sender chi doesn't name start an idle session only: a session its owner stopped or archived refuses them (409 `session_stopped`, "the session is stopped; only its owner's message starts it again", or `session_archived`, "…brings it back"), nothing written. A schedule counts that as a skip (and skips a stopped session at its check, [scheduling.md](scheduling.md)); `delegate` says it as `Error: session <id8> refused: …`; a plugin gets `Error`; an agent's `chi send` adds how its user starts it again ("ask your user to start it: `chi --resume ID`, …", `ChiInvocation#start_stopped`), and `chi sessions restart` on it is refused for an agent with the same "ask your user …", while a person's restart (and the web's Restart) starts it again (*Restart fallback* below); chi web's restart after an update leaves it stopped. A peer's say to a stopped session is not refused: it is received and written, only its wake waits, and its line names `chi --resume` (`chi is stopped: it reads this when its user starts it (chi --resume <id8>)`). A turn already handed to a live worker is that worker's, as before. chi web's owner turn and command routes name a body that carries no `client_id` as `web:unnamed` (a web tab's rights).
47
47
 
48
48
  **Which chi a worker runs:** a new or woken worker runs the newest chi installed for this Ruby (`gem 'samagotchi', '>= 0.a'`, prereleases count), whoever starts it: a `chi web` or terminal still on an older chi starts it on the newest one, so a stale process doesn't spread old code. A worker already running keeps its version until it is restarted. Should the newest install fail to load, the worker runs the starter's own version and logs `boot_fallback` (its stdio is `/dev/null`). Under `bundle exec` the worker drops Bundler's env first, so it activates the newest gem too. Two consequences: a wrapper pin (`chi _0.17.0_ web`) pins only that process, not the workers it starts; and a source checkout (`bin/chi` in a worktree, `bundle exec`) starts its workers on its own `lib/`, but a session it made that is later woken by an installed chi (`chi web`, `chi send`) runs the installed code. The names an older starter hands a newer worker (the boot line, its env keys, `input/` files, the session JSON fields and the Bridge routes sessions use on each other) are pinned in `spec/worker_contract_spec.rb`. A chi newer than 0.130.0 keeps the top-level keys it doesn't know (a newer chi's fields) when it saves a session, after its own, and doesn't act on them; `written_by` names the chi that saved the file last, and a worker woken on a file a newer chi saved logs `newer_writer`. chi 0.130.0 and older drop those keys: a session a newer chi made loses its newer fields when an older chi wakes or saves it (for example `chi --attach` from a project whose Ruby has an older chi). Keep the chi in every Ruby you run it from newer than 0.130.0.
49
49
 
@@ -137,7 +137,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
137
137
  | `written_by` | The chi version that saved the file last (see *Which chi a worker runs*). | `Session#save` |
138
138
  | `id` | The uuid; also the file name. Required. | `Session.new_session` |
139
139
  | `mode` | `assist`, the only mode. Required. | `SessionManager.spawn_session` |
140
- | `model_name` | The resolved model ref (an alias applied; `host:id` when it names a host), so a resume keeps the model. Required. | creation, `/model` |
140
+ | `model_name` | The resolved model ref (an alias applied; `host:id` when it names a host), so a resume keeps the model. A `served` ref is saved as written (`main:served`, never the id it resolved to): each turn resolves it again, and the turn's records name the id. Required. | creation, `/model` |
141
141
  | `model_typed` | The name it was typed as when that differs (an alias), for the `models:` lookup after a resume; `null` otherwise. | creation, `/model` |
142
142
  | `working_directory` | The folder the session runs in. Required. | creation |
143
143
  | `messages` | The conversation (symbol keys in memory, strings on disk). While a turn runs, a save writes the turn's checkpoint here instead (`TurnCheckpoint`). | the Engine, per turn |
@@ -198,7 +198,7 @@ pbpaste | chi note --source slack 3f2a 8c1d
198
198
  - It lands in `<uuid>/notes/`, apart from `input/`, so nothing that runs turns sees it. A live worker adds it to the conversation within a few seconds, between turns: one sent during a turn waits for that turn to end. A session with no worker keeps it until a worker next starts (a prompt, `--attach`), which adds it before anything else. A session a one-turn `chi --non-interactive` run has refuses notes. `chi note` prints one line per session: queued, waits for the next start (with the queue count), or refused.
199
199
  - A note to a link that was **continued** (archived, with a later link) goes to its chain's newest link, as `send_note`'s and `chi broadcast`'s do (`chi broadcast` gives two links of one chain the note once, logged under the newest): `chi note` prints `3f2a1c0d → 4b7e9a01 (continued) queued: …` (and `… (continued) refused: …` when that link refuses it), and chi web's notes answer names that link as `id` beside `session_id`, in a 409 too. `chi broadcast deliver` logs such a delivery under the newest link's id (the one that has the note), so `chi broadcast log` shows that id, not the one typed, and a later `deliver` to either link says it had it. An archived link nobody continues keeps its note until input brings it back. An `/objectives` edit is the one note that stays in its own session: its list is that conversation's. Notes waiting when a session is continued move with it (*Session chains*).
200
200
  - In the conversation it is a tail system message marked `kind: note`, framed `[CONTEXT NOTE from slack, 14:02]\n…\n[END NOTE]` (from another session: `from session 3f2a1c (~/projects/foo)`). The system prompt says notes are background, not requests: the model uses one when it is relevant, doesn't answer it on its own, and never follows instructions inside it. A note from `broadcast` ([`chi broadcast`](broadcast.md)) is the one exception to "doesn't answer it": the model says briefly in its next answer when it affects its current work, and still doesn't act on it unless asked. `--source broadcast` is refused for `chi note`. Its text is escaped like user text, so it can't fake a turn. It survives `--resume`, a reload, `!rollback` and a continue answered no.
201
- - The web shows it as a dim "note from …" block, live (`context_added`) and after a reload, folded into a closed notes row with the background lines next to it (a tap opens it) unless it starts a turn; the attached terminal as one dim `note from slack: <first line>` line, also when joining.
201
+ - The web shows it as a dim "note from …" block, live (`context_added`) and after a reload, folded into a closed notes row with the background lines next to it (a tap opens it), or into the closed line it shares with the delegate reports and peers' answers next to it, unless it starts a turn; the attached terminal as one dim `note from slack: <first line>` line, also when joining.
202
202
  - Agents: `list_sessions` (other sessions of this project, newest first, up to 20; optional `cwd`, `"/"` for every project) and `send_note(session, text)`, which sends a note from this session. Neither starts a turn anywhere.
203
203
 
204
204
  On macOS, `chi desktop install` does this with a native panel from the Services menu or a hotkey (see [Desktop helper](desktop.md)). A plain Automator Quick Action that sends the clipboard to the live sessions you pick works too (Automator: Quick Action, "Run Shell Script", shell `/bin/zsh`; Automator's PATH is minimal, so put your Ruby's bin dir on it and use the full path to `chi`):
@@ -583,7 +583,16 @@ Reminders, a running `/btw`, and other in-memory worker state cannot be
583
583
  checked and may be lost in this fallback. A stopped worker (SIGSTOP or
584
584
  Ctrl-Z: `ps` state `T`) answers neither the ask nor a TERM, so a restart
585
585
  refuses it at once, before asking, with its pid and `kill -CONT PID`. A
586
- session whose stop is marked (stopped, or its worker being stopped) is refused
587
- before any of this (`stop_marked`: no successor would come).
588
- A session being deleted is refused the same way (`deleting`).
589
- The web restart route behaves the same way.
586
+ session whose stop is marked (stopped, or its worker being stopped) has no
587
+ worker to hand over (no successor would come), so a person's restart starts it
588
+ again instead, as `chi --resume` does without a terminal: the stop cleared and a
589
+ worker spawned ("Started session ID again on chi X."), one being stopped once its
590
+ worker has left (up to `SessionManager::STOP_WAIT`, else `still_stopping`: "is
591
+ still stopping; restart it again in a moment"). Only this session starts: the
592
+ delegates its stop stopped stay stopped. An agent's restart (`AgentCaller`) is
593
+ refused before any of this (`stop_marked`, "… ask your user to start it: …"),
594
+ and so is chi web's restart after an update (`Web::UpdateOps#restart_one`): an
595
+ update never undoes a stop (`restart_session`'s `start_stopped:`, false by
596
+ default). A session being deleted is refused the same way (`deleting`).
597
+ The web restart route behaves the same way: a body without
598
+ `"start_stopped": false` (the page's Restart) is a person's.
data/docs/sub-agent.md CHANGED
@@ -57,8 +57,9 @@ before: a pipe alone is not a marker, so your own script or cron line stays your
57
57
  The id is self-declared, as `cli:send` is: a convention for an honest agent, not a
58
58
  security boundary. Every Claude Code session is `claude` unless it passes `--as`.
59
59
 
60
- An agent's message can't restart a stopped session (`refused: the session is
61
- stopped; only its owner's message starts it again`), bring back an archived one,
60
+ An agent's message can't restart a stopped session (``refused: the session is
61
+ stopped; only its owner's message starts it again; ask your user to start it:
62
+ `chi --resume ID`, or a message from a terminal or the web``), bring back an archived one,
62
63
  or run a `!` line (refused with the shell-line text). It may send session commands
63
64
  (`/model x`, `/thinking low`); its `/continue yes` goes in as `chi answer`'s, held to
64
65
  `guardrails.parent_answers`.
@@ -67,8 +68,9 @@ or run a `!` line (refused with the shell-line text). It may send session comman
67
68
  Code), or the one you named (`chi send --new --driver NAME`, `/driver NAME` at a
68
69
  terminal or the web), drives it: its messages are as `chi send`'s were. No extra
69
70
  line, never counted; each resets the wake budget and releases the delegate
70
- reports held back, as your message does (but never brings back an archived
71
- session). A continue keeps the chain's driver; a fork and a delegate child have
71
+ reports held back, as your message does. It is still an agent's message: it
72
+ never starts a stopped session or brings back an archived one; that takes
73
+ yours. A continue keeps the chain's driver; a fork and a delegate child have
72
74
  none. Sessions an agent started before this change have no driver: name it with
73
75
  `/driver claude` once.
74
76
  - **A visitor.** Any other agent's message, and another chi session's
data/docs/system-one.md CHANGED
@@ -37,6 +37,10 @@ same `Client` and `Recording`: the API is in [plugins.md](plugins.md#judgments-c
37
37
  Only bundles' judgments have settings of their own (`JudgmentSettings`). Core's take no host, model or mode here, whatever
38
38
  `system_one.judgments` says: `Record` and `Similar` are model-blind (`Record#initialize` filters by rule, and by repository for a rule in `guardrails.system_one.repo_rules`, never by model), so a model swapped
39
39
  for approvals alone would inherit a clean record and could auto-allow. Before any such swap, `Record` and `Similar` have to go by model.
40
+ `system_one.model: served` changes the judge whenever the host loads another model, under the same model-blind record (the owner's
41
+ choice: the speed of a hand edit, no new kind of risk); each saved run's `model` is the id that answered (after a not-served retry, the
42
+ retried one), and the change logs `system_one_model_changed`. A run whose listing failed or was refused (nothing was asked)
43
+ records `served`, the configured value, with the failure.
40
44
 
41
45
  Core's uses keep their own threads (`ToolkitSuggest::Pending`, `ContextJudge`, the approval path) and contention; only the ask-and-save
42
46
  seam is common. A bundle's `judge_later` runs on the Engine's `SideJudgments` under its full name as the kind, so `SideJudgments#join`
data/docs/testing.md CHANGED
@@ -54,6 +54,9 @@ adapters load, so a run from `git rebase --exec`, `bisect run` or a hook can't r
54
54
  chose spawn with `GitEnv::UNSET`, in any run.
55
55
  `SAMAGOTCHI_TAILSCALE_CLI` points at a file that does not exist (`spec_helper.rb`), so no spec reaches a real `tailscale`; a
56
56
  `chi web --tunnel tailscale` spec writes a fake one and sets the variable.
57
+ No spec reaches a running kitty either (Panes opens tabs and pastes into windows): the spec config has no
58
+ `kitty.listen_on` and `spec_helper.rb` drops `SAMAGOTCHI_KITTY_LISTEN_ON`; a pane spec stubs `Config.get("kitty.*")`
59
+ with `spec/fixtures/desktop/fake_kitty` (`ls`, `launch`, `focus-window`, `send-text`, `send-key`).
57
60
 
58
61
  Goldens (`*_golden_spec.rb`, the prompt snapshots) hold no machine state, so they pass on any runner: no absolute
59
62
  paths (replace them with placeholders), no PATH tools (the suite pins `rg` as found, `spec_helper.rb`; an example
@@ -151,9 +154,10 @@ override and a `note`. The Ruby side runs each row with every core command (a ne
151
154
 
152
155
  ## Compatibility corpus
153
156
 
154
- `spec/compat/readers_spec.rb` reads the newest recorded release before the
155
- current version (or the current corpus when it is the only one) through today's
156
- session, Bridge, CardStore, schedules and bundle-record readers, and the files
157
+ The compatibility readers check both the newest corpus at or below `Samagotchi::VERSION`
158
+ and the newest corpus below it, distinct and newest first, so pull requests exercise
159
+ the release users run today as well as the previous corpus. `spec/compat/readers_spec.rb`
160
+ reads those corpora through today's session, Bridge, CardStore, schedules and bundle-record readers, and the files
157
161
  other chi versions write into a live session's folder: a queued input file, a
158
162
  context note, a continue's intent (`continue.json`) and the stop marker (the
159
163
  starting marker isn't recorded: a recorded one is always stale), a bundle's
@@ -169,6 +173,9 @@ A corpus after 0.168.0 also records every registered cross-version session store
169
173
  (`SessionStores`): objective checks, tracks and proposal cards, delegates,
170
174
  pending cards, reminders and parent overrides. The starting marker is the
171
175
  documented stale-file exception.
176
+ A corpus after 0.192.0 also holds System 1's record (`guardrails/judgments.jsonl`: a rule whose one deny keeps it from
177
+ auto-allowing), its saved runs (`system_one/runs/`) and the context candidates' record (`context_candidates.jsonl`),
178
+ written by `CompatMachineStores` with fixture values only: a machine path in them stops the bump.
172
179
  A corpus recorded after 0.165.0 also holds `wire/`: a worker's replies to `GET state`, `snapshot` (after a turn, and
173
180
  mid-turn with a prompt queued behind it) and `tail`, each `{route, status, body}`, and the session file it saved,
174
181
  plus `events.json`, the page's parsed `{type, data}` SSE replay from sequence 0, recorded from a real Engine and Bridge
@@ -184,6 +191,20 @@ show. `spec/compat/wire_readers_spec.rb` serves the recorded replies to today's
184
191
  with events); `UPDATE_COMPAT_WIRE=1` rewrites them. `release:bump` runs that spec to refresh the fixtures; commit
185
192
  `spec/shared/compat_wire/*.json` with the release. `spec/release/compat_wire_spec.rb` checks the recorder (what
186
193
  `normalise` pins, and the two-recordings guard).
194
+ A corpus recorded after 0.192.0 also holds `wire/remote/`: what chi web answers `chi --remote` (`SessionAccess::Remote`),
195
+ one `{method, path, query, request, status, reply}` file per call (`/api/info`, resolve and its 400 `ambiguous_id`
196
+ and `head=1`, the brief show and its 404, summaries, wait prepare, wait and the 409 `busy`, `delete_plan`, peers,
197
+ a delete's 409 `tasks_running`), recorded by `script/release/compat_remote.rb` (`CompatRemote`: a real `Web::App`
198
+ in LAN mode over a fixed state folder `CompatRemote.with_state` writes, no worker; a worker start raises).
199
+ `spec/compat/remote_readers_spec.rb` checks both directions: today's `Remote` driven through the same calls
200
+ (`CompatRemote.drive`) on an older chi web's replies, served by request (method, path, sorted query and body; an
201
+ unrecorded one is the older chi web's 404), every value asserted so a parser's fallback fails; and each recorded
202
+ request sent to today's `Web::App`, which must answer the same status and keep every key path of the old reply with
203
+ its JSON type. Both skip while the newest previous corpus has none (0.192.0 and before); a third example runs both on a
204
+ recording made now. No golden fixture: a new answer field changes nothing. The JSON-type check sees only what the fixed state fills
205
+ in: a value that is null or an empty array there (`delete_plan`'s delegates and tasks lists, a show's or a summary
206
+ row's null fields) is not type-checked, so a field read from such a place needs a state that fills it. `CompatRemote`'s ids, times and state
207
+ are what both sides read, so change them only with a new release's corpus in mind.
187
208
  A second example reads a corpus the writer records now, so a writer change that
188
209
  today's readers can't read goes red before the release. `rake
189
210
  release:bump[X.Y.Z]` writes `spec/compat/X.Y.Z/` using the current writers
@@ -197,6 +218,20 @@ each Ruby one naming it in a comment (`compat shim <id>`). `spec/compat_spec.rb`
197
218
  fails once `Samagotchi::VERSION` passes a shim's `remove_after`, naming it:
198
219
  remove the shim, or move its date with the owner's OK. A new shim gets a row
199
220
  when compatibility code is needed for a previous release.
221
+ Every `compat shim <id>` comment in `lib/`, `script/`, `bin/` and `spec/` (Ruby files and scripts; a comment wrapped
222
+ onto its next `#` line counts) must name a `SHIMS` row: `spec/compat_spec.rb` lists the unregistered ids with their
223
+ files.
224
+
225
+ A release that changes a file format holds both directions, or it doesn't merge: N reads what N-1 writes (a reader
226
+ kept as a `Compat::SHIMS` row, at least 14 days), and N-1 reads what N writes (an additive shape only, or a new file
227
+ name). There is no unshimmed format change. No spec checks the second direction (an N-1 worker reading the new shape
228
+ N's chi web or CLI wrote); review does.
229
+
230
+ `spec/worker_link_contract_spec.rb` pins what an older client drives a newer worker on, per `WorkerLink::PROTOCOL`: a
231
+ checked-in list of the sidecar keys a real Bridge writes (with their JSON type), its `Bridge::ROUTES` and its
232
+ `Bridge::FEATURES`. It is removal-only: extras pass, and a missing or retyped entry fails naming it. That is a protocol
233
+ bump with the owner's OK, never a deleted entry (docs/releasing.md, "Bumping WorkerLink::PROTOCOL"). It runs on every
234
+ PR, from constants and a Bridge started in process, with no corpus.
200
235
 
201
236
  ## Levels
202
237
 
data/docs/thin-clients.md CHANGED
@@ -282,23 +282,35 @@ One Shortcut with a menu: a new session, your last one, or one picked from
282
282
  your recent ones. `<chi>` is your chi web's address (`https://…` through
283
283
  [Tailscale Serve](configuration.md#tailscale-serve-your-tailnet)), and every
284
284
  **Get Contents of URL** has method POST (GET for the list), the header
285
- `Authorization: Bearer <token>` and a JSON body. Set
285
+ `Authorization: Bearer <token>` and **Request Body: JSON** (Shortcuts' default
286
+ is Form, which chi answers with 400 `invalid_json`). Set
286
287
  [`web.ask_dir`](configuration.md#all-settings) so New needs no folder (or add
287
288
  `dir` to its body).
288
289
 
289
290
  1. **Choose from Menu** with New, Last and Pick.
290
291
  2. In each: **Dictate Text**, then **Format Date** (Current Date, custom
291
- format `yyyyMMddHHmmssSSS`) and **Set Variable** `key` to it.
292
+ format `yyyyMMddHHmmssSSS`) and **Set Variable** `key` to it. ISO 8601 with
293
+ Include Time also works (no spaces) but has second precision: two asks in
294
+ the same second share a key, and the second gets the first's answer. The
295
+ built-in Short, Medium and Long formats contain spaces: refused (400
296
+ `invalid_ask`).
292
297
  - New: **Get Contents of URL** `<chi>/api/sessions` with `prompt` = the
293
298
  dictated text, `reply_for` = `voice`, `request_id` = `key`.
294
299
  - Last: the same body to `<chi>/api/sessions/last/ask`.
295
- - Pick: **Get Contents of URL** (GET)
296
- `<chi>/api/sessions/summaries?limit=30&tests=0&delegates=0`, then
297
- **Repeat with Each** row: **Text** `desc · short_id` (the row's values);
298
- **Choose from List** over the texts; **Split Text** the choice by ` · `
299
- and **Get Item from List** (Last Item: `desc` has a ` · ` of its own):
300
- that is the session's short id.
301
- Then the same body to `<chi>/api/sessions/<short id>/ask`.
300
+ - Pick:
301
+ 1. **Get Contents of URL** (GET)
302
+ `<chi>/api/sessions/summaries?limit=30&tests=0&delegates=0`.
303
+ 2. **Repeat with Each** item in Contents of URL; inside it one **Text**:
304
+ Repeat Item → **Get Value for Key** `desc`, then ` · `, then Repeat
305
+ Item → `short_id`.
306
+ 3. After **End Repeat** (not inside the loop): **Choose from List** over
307
+ **Repeat Results**.
308
+ 4. **Split Text** the choice by Custom ` · ` (a space on both sides) and
309
+ **Get Item from List** Last Item (`desc` has a ` · ` of its own).
310
+ 5. **Text** with that item, then **Replace Text** `\s+` (Regular
311
+ Expression on) with nothing: the split item can carry a trailing
312
+ space or line break, which breaks the URL silently.
313
+ 6. The same body to `<chi>/api/sessions/<Updated Text>/ask`.
302
314
  **Set Variable** `answer` to the result.
303
315
  3. After the menu: **If** `answer`'s `error` is `worker_timeout` or
304
316
  `server_stopping`, send the same request once more with the same `key` (it
@@ -314,8 +326,12 @@ Judge success by `text` (and `created` for New), not by `status`: an older chi
314
326
  web's create answers a `status` of its own. Shortcuts can't catch a **Get
315
327
  Contents of URL** that fails outright (no connection): the shortcut stops
316
328
  there, so the `request_id` retry covers only an answer with an `error`; run
317
- the shortcut again with a new message. This recipe has not been checked on a
318
- device step by step.
329
+ the shortcut again with a new message. Shortcuts doesn't stop on an HTTP error
330
+ answer either: chi's `{"error", "detail"}` comes back as the result, so a
331
+ missing **Set Variable** `answer` or an error nobody speaks looks like
332
+ "nothing happened". Add a **Quick Look** of Contents of URL after **Get
333
+ Contents of URL** to see it. This recipe was checked on an iPhone (2026-11-28,
334
+ chi 0.192.0).
319
335
 
320
336
  For running chi from another agent instead (`chi send --wait`, `chi answer`),
321
337
  see [chi as a sub-agent](sub-agent.md). The routes in full are in
@@ -345,7 +345,7 @@ module Samagotchi
345
345
  def anchor = @running_turn || @turn_log.last
346
346
 
347
347
  def add_card(event)
348
- card = event.slice(:type, :id, :source, :title, :body, :level, :actions, :command)
348
+ card = event.slice(:type, :id, :source, :title, :body, :level, :actions, :rows, :command)
349
349
  index = @entries.index { |entry| entry[:type] == :card && entry[:id] == card[:id] }
350
350
  if index
351
351
  # Replaced where it was: the first one's place stays, and whose it is
@@ -31,6 +31,9 @@ module Samagotchi
31
31
  def resolve(host_registry: nil, get: ->(key) { Config.get(key) })
32
32
  registry = host_registry || HostRegistry.current
33
33
  SETTINGS.each do |model, host_ref, base_url|
34
+ refusal = get.call(base_url).to_s.strip.empty? && list_served(registry, get.call(model), get.call(host_ref))
35
+ return Choice.new(target: nil, setting: model, problem: "#{model}: #{refusal}") if refusal
36
+
34
37
  target = IdleTarget.resolve(model: get.call(model), host_ref: get.call(host_ref), base_url: get.call(base_url),
35
38
  host_registry: registry)
36
39
  return Choice.new(target: target, setting: model, problem: nil) if target
@@ -38,11 +41,25 @@ module Samagotchi
38
41
  return Choice.new(target: nil, setting: model, problem: problem(e, model, host_ref))
39
42
  end
40
43
  model = ModelProfile.required_model_name(get.call("default.model"))
44
+ refusal = list_served(registry, model, nil)
45
+ return Choice.new(target: nil, setting: "default.model", problem: "default.model: #{refusal}") if refusal
46
+
41
47
  Choice.new(target: IdleTarget.of_model(registry, model), setting: "default.model", problem: nil)
42
48
  rescue StandardError => e
43
49
  Choice.new(target: nil, setting: "default.model", problem: e.message.to_s.lines.first.to_s.strip[0, 200])
44
50
  end
45
51
 
52
+ # A served +model+ (main:served, a bare served on +host_ref+'s host)
53
+ # listed now: this CLI process knows nothing of what the host serves.
54
+ # One bounded listing, no retry. @return [String, nil] the refusal
55
+ # when the host lists none or several models
56
+ def list_served(registry, model, host_ref)
57
+ return nil if model.to_s.strip.empty?
58
+
59
+ registry.refresh_served!(model.to_s.strip, max_age: 0, host: host_ref.to_s.strip.empty? ? nil : host_ref.to_s.strip)&.refusal
60
+ end
61
+ private_class_method :list_served
62
+
46
63
  def problem(error, model_key, host_ref_key)
47
64
  case error.reason
48
65
  when :host_ref_unknown then "#{host_ref_key} '#{error.host_ref}' is not in hosts:"
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: claude-peer
3
- version: 0.7.0
3
+ version: 0.9.0
4
4
  scope: system
5
5
  description: "Pair this session with a Claude Code session you work with: the claude_send tool and /claude send it a part of the work (a plan step, a diff, a finding) to validate or as context, and Claude's answer comes back as a message with its text (chi peer say); /claude install-skill installs Claude's chi-peer skill, which pairs"
6
6
  trust_level: reviewed
@@ -10,12 +10,15 @@ files:
10
10
  description: "Send a part of the work to the paired Claude Code session (claude_send): only when the user asks, or to reply to its answer in a peer turn; validate, context or question; Claude's answer comes as a message with its text"
11
11
  plugin:
12
12
  file: plugin.rb
13
- sha256: sha256:a7fa566ff03f6e63d2889196539acbc2fa0c3615aa3a75c1282c91d062bc5e6f
13
+ sha256: sha256:14fe3e36e84dd25172fd3fb0dba54a4aa94d4b8cdb4101573431927e84551657
14
14
  scripts:
15
15
  pair-remote: sha256:d7681f87a194e540b629564f84cad9f2d0a763197502c74614276ef88a8920cc
16
- pair: sha256:98cddde54801f49b123cd0269f9ddc834b2566fde4ad241c07a50f3b794fedd0
17
- chi-peer-SKILL.md: sha256:90132948e1198c450bd6fd3fcadbfad410c429b0d55ef4d7aede21a9f0e47b2f
16
+ pair: sha256:626b1c4acba6b1ab8a9d9615c709d69da6953d89d32469f370c2eaad145a8bb8
17
+ chi-peer-SKILL.md: sha256:e3d5bd01d221a3206e203098bf7e1e1fbbbf72b2124bae744eace1816d8eca0c
18
+ # config.yml bundles: <name>: start_command: the shell line /<peer> start runs in its kitty tab (another key warns)
19
+ settings: [start_command]
18
20
  # The plugin needs Samagotchi::Plugin::Peer on the mailbox: chi.peer and
19
21
  # ctx.peers, and the skill's chi peer pair|say, are the next chi's (an older
20
22
  # chi has no chi.peer: the plugin fails to load there).
21
- requires_chi: ">= 0.188.0"
23
+ requires_chi: ">= 0.194.0"
24
+ # The pair script's no-id form (chi peer pair --here), --peer-session, /<peer> pair and the start hook are the next chi's.
@@ -38,7 +38,11 @@ require "samagotchi/plugin/peer"
38
38
  # keep what was completed); `/claude install-skill` shows a card with
39
39
  # Claude's chi-peer skill's target and an Install action (`--yes`), the card
40
40
  # being the user's consent: the copy happens in-process, where no guardrail
41
- # sees it. The skill is scripts/chi-peer-SKILL.md beside this file, with the
41
+ # sees it; and "Add the start hook…" (`/claude install-hook`: the merged
42
+ # settings as a diff), whose card's Add (`--yes`, only on the user's own
43
+ # tap) merges the SessionStart hook that runs `chi
44
+ # peer announce claude` into Claude Code's settings.json. `/claude pair`
45
+ # pairs with a Claude Code session here, no id copied (Plugin::PeerPairing). The skill is scripts/chi-peer-SKILL.md beside this file, with the
42
46
  # installed scripts/pair path and the payload folder written in.
43
47
  #
44
48
  # In the web, selecting text offers "Confirm with Claude" (chi.annotation):
@@ -69,9 +73,12 @@ class Plugin < Samagotchi::Plugin::Peer
69
73
  CHECKED_ON = "Claude Code 2.1.296"
70
74
  STATUS_CARD = "claude"
71
75
  SKILL_CARD = "claude-skill"
72
- USAGE = "usage: /claude — whether a Claude Code session is paired; /claude validate <text> | context <text> — send " \
73
- "the text to it; /claude last — send the last answer as context; /claude install-skill — install Claude's " \
74
- "chi-peer skill, which pairs"
76
+ USAGE = "usage: /claude — whether a Claude Code session is paired (else the ones here); /claude pair — pair the one " \
77
+ "here, or wait for one and list them; /claude pair <id8> — pair that one; /claude show <id8> — bring its kitty " \
78
+ "window to the front; /claude start — open Claude Code in a kitty tab, paired when it starts; /claude show — bring " \
79
+ "that tab to the front; /claude unpair — end the pairing or the wait; /claude validate <text> | context <text> — " \
80
+ "send the text to it; /claude last — send the last answer as context; /claude install-skill — install Claude's " \
81
+ "chi-peer skill, which pairs; /claude install-hook [--yes] — Claude Code's start hook, which lists a Claude here"
75
82
  # The shipped bundle keeps scripts/ beside plugin.rb; an installed one
76
83
  # has plugin/plugin.rb and scripts/ beside plugin/.
77
84
  SCRIPTS_DIRS = [File.join(__dir__, "scripts"), File.expand_path("../scripts", __dir__)].freeze
@@ -95,6 +102,18 @@ class Plugin < Samagotchi::Plugin::Peer
95
102
  "functions or diff range to look at. A long text goes to a file Claude reads" }
96
103
  }.freeze
97
104
 
105
+ # Claude lists itself here (its start hook, chi peer announce): /claude
106
+ # pair finds the sessions open in this project.
107
+ def announces? = true
108
+
109
+ # Its inbox socket missing: that Claude ended (a resume pairs again with a
110
+ # new one). No address (answers only) isn't gone.
111
+ def link_gone?(link) = link.socket_gone?
112
+
113
+ # Its start hook (Claude Code's SessionStart: chi peer announce claude),
114
+ # added to settings.json from the skill card's "Add the start hook".
115
+ def start_hook? = true
116
+
98
117
  # The one JSON line Claude Code's inbox socket takes.
99
118
  def line(content) = "#{JSON.generate(type: "user", message: { role: "user", content: content })}\n"
100
119
 
@@ -118,7 +137,7 @@ class Plugin < Samagotchi::Plugin::Peer
118
137
  def setup_paragraph(ctx)
119
138
  rule = "Read(#{tilde(ctx.data_dir)}/**)"
120
139
  "So Claude isn't asked before reading a long part's file, add `#{rule}` to Claude Code's permissions " \
121
- "(`permissions.allow` in its settings.json); chi doesn't change Claude's settings."
140
+ "(`permissions.allow` in its settings.json); chi never changes Claude's settings without your tap."
122
141
  end
123
142
 
124
143
  # Claude Code's config folder: CLAUDE_CONFIG_DIR, else ~/.claude.