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
@@ -0,0 +1,104 @@
1
+ # Panes: the windows agents run in
2
+
3
+ A pane is where an agent's own UI runs and where the human can walk in: today a kitty window. It carries no peer
4
+ message (that is the mailbox, [peers.md](peers.md)). `list`, `find`, `find_var` and `show` find and raise a window;
5
+ `open`, `alive?` and `paste` open a window (a background tab, or one next to the session's chi terminal) and type
6
+ into it (claude-peer's and codex-peer's `/<peer> start`, `Plugin::PeerStart`).
7
+
8
+ `Samagotchi::Panes` (`lib/samagotchi/panes.rb`), the pure parts in `Panes::Kitty` (`panes/kitty.rb`), ported from the
9
+ desktop helper's `Kitty.swift` as they are:
10
+
11
+ - **The sockets:** `kitty.listen_on`'s `unix:` path with `~`, `$VAR` and `${VAR}` expanded from the env, an unknown
12
+ one kept literal (kitty.conf's `${KITTY_PID}` is a literal file name); the files of its folder named the base,
13
+ the base `-<digits>`, or the base with `{kitty_pid}` filled, sockets only. A plain directory listing, never a glob
14
+ (its braces would read `${KITTY_PID}` as alternation). A lookup asks every socket.
15
+ - **The env:** kitty runs with `KITTY_*` removed (as the helper's `KittyRunner#kittyEnv`), so a worker started from a
16
+ kitty window never talks to that one by its variables. The literal socket name and the absolute `kitty.binary`
17
+ work from a process with no `KITTY_*` (the spike checked it from a stripped env).
18
+ - **Finding a window:** the one whose `foreground_processes[].pid` contains the pid (membership: never
19
+ `windows[].pid`, which is the login wrapper or a launcher's sh). Its title is `windows[].title` (never the tab's:
20
+ a tab holds several windows), cleaned as the helper's `AgentText.cleanTitle` (the status glyph dropped).
21
+ - **What `ls` gives a `Pane`:** besides the key, title, cwd and pids, the window's `user_vars` (`vars`) and its tab's
22
+ `layout` (`tab_layout`: `fat`, `splits`, `stack`…; "" when `ls` has none) and `is_focused` (`tab_focused`: the
23
+ active tab of the focused OS window). kitty 0.49.2's `ls` has all of them (`Window.as_dict`, `TabManager.list_tabs`).
24
+ - **The session's terminal (the mark):** the attached TUI (`TerminalUI::AttachLauncher#mark_window`) sets the user var
25
+ `chi_session` (`Panes::SESSION_VAR`) on its own window to `<session id>:<its pid>` (`Panes.session_mark`) with the
26
+ OSC 1337 `SetUserVar` escape (`Kitty.user_var`: the value base64, as kitty requires), written before the live
27
+ region opens and unset (the no-`=` form; an empty value would leave `""`) after it closes, in `run`'s outer
28
+ `ensure`, so every way out but kill -9 clears it. Only with `KITTY_WINDOW_ID` set and stdout a tty (a piped
29
+ `chi -p … | tee` never gets it), never for a `--remote` attach. No socket is needed (an escape, not
30
+ `kitty @ set-user-vars`). Inside tmux the escape is dropped unless tmux passes it through: no mark, so a start
31
+ opens a tab. `spec_helper` drops `KITTY_WINDOW_ID`, so a suite run in kitty marks nothing.
32
+ - **Finding the mark:** `find_var(name, id)` is the window whose var `name` matches `\A<id>:(\d+)\z` (the id
33
+ escaped) while that pid is among its foreground pids: a TUI killed hard leaves its mark on a window that may run a
34
+ shell now, and that one never matches. Several (two attached terminals of one session): the focused tab's first,
35
+ else the first in `ls` order. on its socket: it brings a background tab forward, and a background OS
36
+ window (checked with `kitty @ ls`'s `is_focused` while the screen was unlocked).
37
+ - **Open:** `open(command:, cwd:, title:)` runs `launch --type=tab --keep-focus --cwd DIR --tab-title TITLE ARGV…`
38
+ on the kitty whose OS window is focused (`ls`'s `is_focused`), else the live socket file with the newest mtime (the
39
+ kitty started last), and returns `PaneRef(driver, key)`, the key `<socket>#<window id>` from the id `launch`
40
+ prints. A tab only: `--type=os-window --keep-focus` doesn't keep the focus (the step-0 spike). `launch` has its own
41
+ 15 s limit (`LAUNCH_SECONDS`; `ls` 2 s, the rest 5 s): one killed early may still open a tab no ref names. No socket answering
42
+ raises `Panes::Unavailable`, the one message "kitty isn't running or `kitty.listen_on` isn't set"; a launch that
43
+ fails or prints no id raises `Panes::Error`.
44
+ - **Open next to a window:** `open(…, next_to: pane)` runs, on **that pane's own socket** (checked as any ref is),
45
+ `launch --type=window --match window_id:N --next-to id:N --location=LOC --keep-focus --cwd DIR ARGV…`. The
46
+ `--match window_id:N` picks the pane's tab: over remote control kitty ignores `--next-to` unless the matched window
47
+ is in the target tab, the active one by default, so without it the window would land in whatever tab the user is
48
+ in (`window_id:`, not `id:`, which for `launch` first looks for a tab id). `LOC` is `split` in the `splits` layout,
49
+ else `neighbor` (the slot after it: in `fat`, the default layout, a strip under chi). No `--title` (it would freeze
50
+ the title the command sets, which Show's lists read). A non-zero exit (the window gone since the `ls`, a kitty that
51
+ refuses `--next-to`, anything: stderr isn't read) raises `Panes::SplitFailed`; a timeout raises `Panes::Error`,
52
+ never `SplitFailed`, since a slow launch may still open its window (`run` tells `:timeout` from `:failed`).
53
+ - **Alive and paste:** `alive?(ref)` is `ls --match id:N` on the ref's socket. `paste(ref, text, enter:)` is the
54
+ helper's `KittyRunner#send`: `alive?` first (send-text reports nothing for a gone window), then
55
+ `send-text --match id:N --bracketed-paste=disable --stdin` with the text wrapped in `ESC[200~ … ESC[201~` (its own
56
+ markers taken out, as `AgentText.text`), then `send-key --match id:N enter` when `enter`. No in-tree caller pastes
57
+ yet: `/codex start` passes its first prompt as Codex's own argument (`codex [PROMPT]`), which doesn't race the
58
+ TUI's start as a paste would.
59
+ - **Config:** `kitty.listen_on` and `kitty.binary` are read at each call (`Panes.from_config`, `Config.get`); their
60
+ lifecycle is `next_pane_lookup` (the desktop helper still copies them into its launch file).
61
+ - **No kitty** (unset, not running, the pid in no window, the binary missing): nothing found, no error; a row then
62
+ has no Show.
63
+
64
+ `ctx.panes` (`Plugin::Panes`, [plugins.md](../plugins.md)) is the plugin's view, built with its session's id:
65
+ `find(pid:)`, `alive?(ref)`, and `show`, `open` and `paste`, which raise `Plugin::Panes::NotTyped` unless the command was typed or tapped by a person
66
+ (`ctx.user_typed?`, `UserTyped`): they act as the user on their screen, so no tool call, `chi send`, agent, participant, schedule, delegate or plugin path reaches them. The seam trusts the request's client id, so it is an accident guard as the guardrails are ([guardrails.md](../guardrails.md#protected-paths)), not a sandbox: a model's shell holding the Bridge's secret could still post as a UI, as it can a `!` line. Nothing derived from `.here` is used to open or
67
+ paste: `/<peer> start` keeps its `PaneRef` in the bundle's own session state (`state.json` under `ctx.session_dir`, a
68
+ `SessionStores` row removed with the session), never in the mailbox. That file is not protected (chi's own tools can
69
+ write it), so a ref is checked on every use instead: `alive?`, `show` and `paste` take a ref only when its socket is
70
+ one of `kitty.listen_on`'s own (`Kitty.sockets`), else they answer as for a closed tab and run no `kitty @`; a paired
71
+ session's `/<peer> show` also needs the paired peer's pid in that window. A continue doesn't carry that state (the
72
+ pairing it does).
73
+
74
+ `Plugin::Panes#open(command:, cwd:, title:, in: :tab)` (another `in:`, a string too, is an `ArgumentError`): `:tab` is the background tab; `:pane` is `find_var` of this
75
+ session's mark, then a window next to it, else a tab: no mark, the mark's tab in the `stack` layout (the window
76
+ would open hidden behind chi, `--keep-focus`), or a `SplitFailed` (one tab launch then; a timeout gets none and
77
+ raises as any open error). A block gets a `Plugin::Panes::Placed(kind, why)`: `:pane`, or `:tab` with the reason
78
+ (`NO_TERMINAL`, `STACKED`, `SPLIT_FAILED`) when a pane was asked for. Either way it returns the `PaneRef`, so
79
+ `alive?`, `show`, `paste` and the saved record work the same for a pane and a tab (all per window). A start tapped
80
+ in chi web or on the phone opens next to the session's attached TUI too when there is one: the rule names the
81
+ session's terminal, not where the tap came from. One extra `ls` per start (`find_var`; the tab path has its own).
82
+
83
+ `/<peer> start` (`Plugin::PeerStart`): the checks (typed, no live pairing, claude-peer's start hook current), then
84
+ the wait (`ctx.peers.wait`), then `open` with `[$SHELL, -l, -c, "exec <start_command>"]` (the account's shell when
85
+ `$SHELL` is unset) and `in:` from the bundle setting `open_in` (`pane`, the default, or `tab`; another value means
86
+ `pane`, and the start line names it: no setting checks values, only keys and types). The start line says what
87
+ opened ("opened a pane next to this chi", or "opened a background tab "<title>" (why)"); every later line says
88
+ "kitty window" for both, so the saved record needs no kind. An open wait (`/<peer> pair`'s) is kept, not rewritten; a pane error takes back only the wait
89
+ this start wrote (`ctx.peers.stop_waiting(name, mark)`, `PeerPresence.drop_wait`: never another wait nor an announce's
90
+ claimed file), so a refusal leaves no mark of its own. A second start while the wait is open and its window `alive?` (a
91
+ double tap) is refused, "already starting claude · chi <id8> in kitty …" (chi's label, the saved `title`: a
92
+ pane carries no title of chi's); two at the same moment take turns on a flock
93
+ (`start.lock` in `ctx.session_dir`, held across the checks, the wait and the open: commands run in parallel). The window
94
+ is checked once more 1.5 s after the launch (`PeerStart.settle_seconds`): gone already (its command not found), the
95
+ start's wait is taken back and the reply names `start_command`. The
96
+ status card's started row (scene 5) shows while the ref is `alive?` and the paired Claude's pid (its `PeerHere`) runs
97
+ in that window, and "its kitty window is closed" once the ref is gone and so is the pairing's socket.
98
+
99
+ Specs: `spec/panes_spec.rb` (on `spec/fixtures/desktop/fake_kitty`, which answers `ls`, `launch`, `focus-window`,
100
+ `send-text` and `send-key`, and logs the argv, stdin and `KITTY_*` env it got; its canned windows carry pids and
101
+ `user_vars`, its tabs `layout` and `is_focused`, its OS windows `is_focused`; `launch --match window_id:N` adds the
102
+ window to N's tab or exits 1, and `$FAKE_KITTY_SPLIT_FAILS` / `$FAKE_KITTY_LAUNCH_SLEEP` play a kitty that refuses
103
+ `--next-to` and a slow launch), `spec/terminal_ui/attach_launcher_spec.rb` (the mark) and `spec/samagotchi/bundles/claude_peer_start_spec.rb`. No spec reaches a running kitty
104
+ ([testing.md](../testing.md)).
@@ -10,8 +10,10 @@ and `RE_RE` (a send ref).
10
10
  **The peer's side, `<state>/samagotchi/mailbox/<session id>/<peer>/`** (`PeerMailbox`): the only folder a
11
11
  sandboxed peer writes, beside the sessions folder and apart from it.
12
12
 
13
- - `link.json`: `PeerLink(peer, address, paired_at, from)`; `address` nil: answers only. `chi peer pair` writes it
14
- whole; `unpair` removes only it.
13
+ - `link.json`: `PeerLink(peer, address, paired_at, from, peer_session)`; `address` nil: answers only;
14
+ `peer_session` (written only when set, read by `from_h`, so a continue's copy keeps it) the peer's own session id.
15
+ `chi peer pair` writes it whole; `unpair` removes only it (and, `Local#peer_unpair`, the session's wait and
16
+ pairing files below). An older chi drops `peer_session` on its continue and its re-pair.
15
17
  - `in/<serial>.json`: `PeerMessage(serial, text, summary, wake, re, at)`, one file per message, written whole
16
18
  (`AtomicFile`; its temp name never matches `FILE_RE`).
17
19
  - `lock`: the say's, while it picks a serial and writes (`flock`, opened `NOFOLLOW`).
@@ -38,6 +40,99 @@ newest serial it took. The CLI and chi web only read it.
38
40
  mailbox folder) and `peer_receipts.json` (`:session_files`); a continue copies `link.json` to the new link and
39
41
  leaves the rest with the previous one (below).
40
42
 
43
+ ## Who is here: `PeerPresence`
44
+
45
+ `<state>/samagotchi/mailbox/.here/<peer>/`, inside the mailbox root on purpose (the one folder a sandboxed peer may
46
+ write; the `chi-mailbox` guardrail denies chi's own tools any write there; `SessionPaths.valid_id?` rejects `.here`,
47
+ so nothing reads it as a session):
48
+
49
+ - `<peer session>.json`: `PeerHere(peer, session, address, cwd, project, pid, at)`, written whole by `chi peer
50
+ announce` only. `project` is `MemoryPaths.project_key` of the cwd, computed once; `pid` is `CLAUDE_PID` (the
51
+ socket's file-name number as fallback). Live: the pid alive and the address a socket, and a socket named
52
+ `<n>.sock` (Claude Code's) `n == pid` (a forged entry can't borrow a real Claude's pid, its title and its Show).
53
+ A dead one is removed by whoever reads the folder. A live one on the same address under another session id is superseded by the announce
54
+ (a `/clear` gives Claude a new session id on the same socket): removed, its pairing files moved, its links'
55
+ `peer_session` renamed (`Local#peer_retag`).
56
+ - `waiting/<chi session>.json`: `PeerWaiting(session, project, at)`, a 10-minute wait (`WAIT_SECONDS`); an `at` in
57
+ the future or unparsable is stale, and `marks` (what an announce and `--here` pair against) skips an archived
58
+ session's (stale on read: archiving leaves the file). **A stale wait is removed only by its session's worker** (`PeerWaitExpiry`, from
59
+ `Worker::MailPart#expire_peer_waits` in `idle_pass`: removed, and once per wait `:peer_wait_ended`, the bundle's
60
+ `ctx.notify` line; a session paired meanwhile, or a peer no bundle declares, gets no line), its unpair and its
61
+ delete; every other reader treats it as absent, so the line isn't lost. A continue moves it to the new link
62
+ (`PeerContinue#carry_waits`, keeping `at`).
63
+ - `paired/<peer session>/<chi session>`: one empty file per pairing made with a `peer_session`
64
+ (`Local#pair_on`), never rewritten, removed by unpair and delete (the peer session's folder too once it is
65
+ empty: `rmdir`, so a pairing written meanwhile keeps it). A resume's announce lists it and re-pairs each
66
+ through `Local#peer_refresh` (its busy, continue and worker-age rules), only while the chain's live link is still
67
+ that peer session's; else the file is dropped (an unpair, another Claude paired since).
68
+ - **`claim`**: an atomic rename of the wait's file (`<id>.json.claimed-<hex>`). The announce, `--here` and a row's
69
+ Pair claim before they pair; anything but `:paired` renames it back; a pairing that paired ends the link's wait
70
+ (and any claimed leftover of a crash). While a claim is held the mark is only its claimed file, which `waiting`
71
+ and `marks` don't read: `claimed?` (a claimed file with a fresh `at`) is what the other paths ask, and they write
72
+ nothing while it is true (`/claude pair`, a row's Pair, `--here`).
73
+
74
+ `SessionStores` rows: `waiting/<id>.json` (`continue: :peers`) and `paired/<peer session>/<id>`, both removal
75
+ `:peer_presence` (`RemovalPart#remove_files`), not cross-version.
76
+
77
+ **`chi peer announce NAME`** (`PeerAnnounce`): Claude Code's `SessionStart` hook. Nothing unless
78
+ `CLAUDE_CODE_SESSION_ATTENDED` is 1 (a headless or nested `claude -p` is 0; subagents fire no `SessionStart`).
79
+ It writes the `PeerHere` (superseding), refreshes its pairings (`chi <id8>: pairing refreshed`), and when it has
80
+ none takes the one fresh wait of its project (`paired with chi <id8> (<title>): …`; two or more: names them, pairs
81
+ none). Its stdout enters Claude's start context; any failure prints nothing and exits 0. Measured 0.13 s on the
82
+ Studio. Who the peer is comes from a reader returning one `PeerAnnounce::Announcer` (session, address, cwd, project,
83
+ pid, `lists_itself`, `from`, `app`): Claude's above, and Codex's for `announce codex`:
84
+
85
+ - **Codex's** (codex-peer's start hook, appended to `$CODEX_HOME/hooks.json`): stdin only. It needs
86
+ `hook_event_name: SessionStart`, `source: startup` (never `resume`, `clear`, `compact`, `fork`), a `session_id`
87
+ `PeerPresence.peer_session?` takes and an absolute `cwd`; then `CodexRollout.interactive_start?` on
88
+ `transcript_path`. The address and the peer session are the thread id; it writes no `PeerHere` (no pid, no socket:
89
+ `PeerPresence.live?` can't hold, and the TUI's hook runs in Codex's app-server daemon, which outlives every window),
90
+ so a thread with a pairing (`paired_sessions` + `peer_refresh` `:same`) takes nothing, else the mark as above
91
+ (`from: "Codex in <cwd>"`). Under the daemon's `CHI_REMOTE` bin/chi exits 2 first; the line's `|| true` hides it.
92
+ An older chi with this line exits at the `CLAUDE_CODE_SESSION_ATTENDED` gate (silent).
93
+ - **`CodexRollout`** (checked on Codex 0.172.0, undocumented): line 1 of the rollout (`type: session_meta`) passes
94
+ only with `payload.originator == "codex-tui"`, `payload.thread_source == "user"`, a string `payload.source` and
95
+ `payload.id == session_id` (an allowlist: `codex_exec`, a subagent, anything missing fail closed). The file is
96
+ lstat'ed (a regular file, no link followed, opened `NOFOLLOW`) and its real path must be under the real
97
+ `<codex home>/sessions`, the codex home being the hook env's `CODEX_HOME` (the daemon's), else `~/.codex`. Line 1
98
+ is ~19 KB (`base_instructions`), so it is read to the first newline within `LINE_MAX_BYTES` (1 MiB), never
99
+ `PeerPresence::FILE_MAX_BYTES`. The hook fires 1–2 s after the file is born, so a missing file, a 0-byte one or a
100
+ line with no newline yet is tried `TRIES` (10) × `TRY_SECONDS` (0.1 s), then given up silently. A headless `exec`
101
+ boots chi and exits at this gate (~0.4 s wall, 0.16 s CPU, on the Studio).
102
+
103
+ **`chi peer pair NAME --here`** (`PeerPairHere`): the fresh wait of this folder's project (claimed), else the one
104
+ session of that project (by `project_key`, not a path prefix) a worker runs now, else exit 1 with the candidates.
105
+ A mark or live session another pairing holds (`claimed?`, or the one mark's claim lost) exits 1 rather than falling
106
+ back; a chosen session whose chain's live link is paired with another peer (another address, and another peer
107
+ session when both are named: the same socket after a `/clear` is the same Claude) exits 1 too, "unpair there
108
+ first" (owner: `--here` never replaces a live one; a pair with an id does). One whose peer is gone
109
+ (`PeerLink#socket_gone?`: an absolute socket path that is no socket now; claude-peer's `link_gone?` is the same
110
+ rule) is replaced, as `/claude pair` ends it: its pairing file dropped and a stderr line (the pair script reads
111
+ stdout's first word). A Codex thread id is never gone, so Codex keeps the refusal.
112
+ Before the live fallback (a fresh mark still pairs first), a live session of the project whose chain's link is
113
+ paired with this peer already, by this peer session or at this address (codex-peer's start hook paired it; an older
114
+ pair script passes no `--peer-session`), wins: `PeerPairHere::Found#same`, and `PeerCommand` says it paired
115
+ (`PeerPaired` `:same`, nothing written) or, when the address or peer session changed, pairs it again (keeping its
116
+ peer session when none was given). A stopped session's pairing never wins (a resumed Codex keeps its thread).
117
+ The pair scripts run it with no id (refused over a remote by the script itself); codex-peer's passes
118
+ `--peer-session "$thread"`.
119
+
120
+ **From chi's side** (`Plugin::PeerPairing`, `ctx.peers.here/pair/wait/claim`): `/claude pair` (one here: pairs;
121
+ none: waits; several: waits and draws the card, rows by `ctx.card(rows:)`), a row's `pair <id8>` (claims first:
122
+ a pairing made meanwhile is named, nothing written; a wait that ended pairs anyway), `show <id8>` (the window found
123
+ live by its pid, `ctx.panes`, only under `ctx.user_typed?`), `unpair`. A bundle whose peer doesn't announce
124
+ (`announces?` false: codex-peer) only waits. The start hook (`Plugin::PeerStartHook`, `/<peer> install-hook
125
+ [--yes]`) is merged only under `ctx.user_typed?`: claude-peer's into Claude Code's settings.json, codex-peer's into
126
+ Codex's hooks.json (the bundle's `#hook_file`, `#start_hook_line`, `#hook_paragraph`, `#hook_written_line`,
127
+ `#hook_stale_tail`); `#with_hook` replaces an announce line in place, else appends a group, never reorders (Codex's
128
+ trust is `[hooks.state."<file>:session_start:<group>:<hook>"]` in config.toml, index-keyed, which chi never writes). `/<peer> start`
129
+ (`Plugin::PeerStart`) writes the wait and opens a kitty window running the peer (a pane next to the session's chi terminal, or a
130
+ background tab: the bundle setting `open_in`, [panes.md](panes.md)): it has no path of its own to pair (the
131
+ started Claude's announce takes the wait; codex-peer's first prompt runs the skill's `--here`, or its start hook
132
+ takes the wait at that prompt; `#start_needs_hook?`: claude true, codex false, and codex's opened line adds
133
+ `#start_review_hint` while its hook is current); its `PaneRef` lives
134
+ in the bundle's `state.json`, never here ([panes.md](panes.md)).
135
+
41
136
  ## Who is a peer
42
137
 
43
138
  - **The worker:** `PeerRegistry`, filled by `chi.peer NAME` (`Plugin::Api#peer`, staged until the plugin's
@@ -204,11 +299,13 @@ starts empty).
204
299
 
205
300
  `Web::PeerRoutes` (all `:owner`, a participant gets 403):
206
301
 
207
- - `GET …/peers` → `{peers: [{name, label, paired_at, from, address, can_send, messages, exchanges}]}`: one row per
208
- mailbox folder (`PeerRoster`), its newest 20 messages with their receipts and `words`
302
+ - `GET …/peers` → `{peers: [{name, label, paired_at, from, address, can_send, messages, exchanges, waiting}]}`: one
303
+ row per mailbox folder (`PeerRoster`), and one per peer this session waits for, with `waiting: {until}` (a fresh
304
+ wait only: `#waiting_rows`; the page's waiting chip, `peer_wait.js`), its newest 20 messages with their receipts and `words`
209
305
  (`PeerRoster.state_words`), and `exchanges` (`PeerExchanges.joined` over chi's sends and the messages as answer
210
306
  lines). No text.
211
- - `GET …/peers/NAME/messages/SERIAL` (the text and its receipt); `DELETE …/peers/NAME` (Unpair); `POST
307
+ - `GET …/peers/NAME/messages/SERIAL` (the text and its receipt); `DELETE …/peers/NAME` (Unpair, and the waiting
308
+ chip's Cancel: `Local#peer_unpair` ends the wait too; `waited: true` says one ended); `POST
212
309
  …/peers/NAME/pair` and `…/say` (the remote's; the say waits here).
213
310
 
214
311
  The page's peer chip is fed by `GET …/peers` alone ([web-frontend.md](web-frontend.md), The peer exchange).
@@ -310,6 +310,10 @@ is prefilled once. The native and the chat loop use the same plan.
310
310
  send their line with `--yes`: typing the flag, or the Set, is the choice. A plugin command asks
311
311
  through `ctx.cache_confirm(line, changed:)` (cost `:full`: its prompt section is in the stable part), with the
312
312
  sender's flag `SessionCommands#run` gives it (`CacheConfirm.asking`), and returns `[text, confirm]`.
313
+ A `served` model (`main:served`) whose host now serves another model restarts the prompt as a `/model` does
314
+ (`Engine#follow_served!` at the turn's start: the system prompt rebuilt), without asking: nobody chose it, and
315
+ the server's KV cache is the old model's anyway. Its per-turn check is one `GET /v1/models` before the prompt is
316
+ built; an unchanged answer changes no byte.
313
317
  7. **No wall-clock time rendered at wire time.** A history entry's `at` (`MessageTime::KEY`, when it happened) is
314
318
  display-only: no wire format reads it, and a guard spec checks that `ChatLoop#wire_messages` and
315
319
  `Prompt.format_with_images` give the same bytes with and without it (`spec/message_time_history_spec.rb`). A
@@ -96,7 +96,8 @@ state. A cell is `:go`, `:wait` or the decider's own refusal reason; `SessionLif
96
96
  write, a `:none` row, still goes in). The other literal operations read none (archive's column is `archivable!`,
97
97
  its checks; `archive_session` takes the lock after them).
98
98
  - **Literal columns** (`LITERAL`): resume (`resume_session`), restart (`restart_session`: `stop_marked` in every
99
- state with the stop marked: stopping, stopped, stopped_starting), stop (`stop_session`),
99
+ state with the stop marked: stopping, stopped, stopped_starting; refused for an agent's restart and an update's,
100
+ started again for a person's, the op-local `start_stopped:` branch below), stop (`stop_session`),
100
101
  archive (`archivable!`), delete (`release_for_delete!`, without a stop), sched_chain and sched_same
101
102
  (`Schedules#busy_reason`; `worker_busy` is "its worker is starting or leaving", `deleting` the delivery's "the
102
103
  session is being deleted", `worker_newer` `WorkerLink::Skew#short_message`) and attach
@@ -115,7 +116,13 @@ owner read through `session_owner`) and `ALLOWED[:restart]`: `owned_by_tui` rais
115
116
  raises `RestartRefused` with it as the reason (`starting`, `not_running`, `stop_marked`, `deleting`), `fallback` goes to
116
117
  `restart_fallback` (skew, a stuck start) and `go` asks the live worker. Its op-local checks stay where they were: the
117
118
  SIGSTOP check (`:stopped`, the worker's pid: a different condition with its own words, before the table's refusal),
118
- the worker's `restart` feature, the Bridge's reply and the fallback's holds. The matrix still drives it, so its
119
+ the worker's `restart` feature, the Bridge's reply and the fallback's holds. The `start_stopped:` branch is op-local
120
+ too (the table's `stop_marked` cell names the state; the caller picks the answer): a person's restart (the CLI when
121
+ `AgentCaller` finds no agent, the web's `POST …/restart` unless its body says `"start_stopped": false`) on a
122
+ `stop_marked` cell, after the SIGSTOP check, calls `resume_session` (the stop cleared, a worker spawned) and awaits
123
+ any live Bridge (`Restarted#was_stopped`); a stopping one first waits `wait_for_owner_release` (`STOP_WAIT`), else
124
+ `RestartRefused :still_stopping`. A scratch session keeps the refusal; `Web::UpdateOps#restart_one` passes none (an
125
+ update never undoes a stop). The matrix still drives it, so its
119
126
  column is pinned against the precheck and the op-local paths together.
120
127
 
121
128
  A schedule's busy check (`Schedules#busy_reason`, `schedules/busy_part.rb`) is the second: it reads `WorkerPresence`
@@ -41,7 +41,10 @@ uses at its top level, `agent_rows.test.js` loads both orders), `agent_runs.js`
41
41
  answers and notes: The notes rows and the run line, below; it imports only names the last release's `answer_fold.js`
42
42
  and `quiet_notes.js` exported, and `quiet_notes.js installQuietNotes` stays for an older cached `app.js`), `details_motion.js`,
43
43
  `turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
44
- `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `views.js` (the views by hash, in one place: All sessions at `#/sessions` opened, closed and left; a page at `#/p/NAME`, read before the session intent, `hashIntent` calling it `keep`: `body.page-view`, Back to where it was opened from (kept in the history entry's `history.state.from`, so Back and Forward keep it), the session's hash not written while a view owns the URL (`keepSessionHash`), a session picked leaving it; the Pages list at `#/pages` the same way, `body.pages-list`, and the pages pill pressed on either; the session's `#/s/<id>` written; a hash change applied and selected; app.js makes it after the lists and hands its functions lazily to what it made before), the page's modules `page_route.js`, `page_view.js`, `page_model.js`, `page_blocks.js`, `page_table.js`, `page_table_model.js`, `pages_model.js` (the page's one list of pages), `pages_list.js` (the Pages list at `#/pages`, read by `views.js` beside a page's hash), `pages_wiring.js` (`wirePages`: the pill, the list, the view and the links, one call in app.js) and `page_links.js` (a page in chi web: [pages.md](pages.md#chi-web)), `worker_features.js`, `version_notices.js`, `owner_claim.js` (its `showPending` calls the injected `keepSessionHash`, following `views.js`'s rule not to write the session hash while a view owns the URL), `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js`, `peer_text.js`, `peer_row.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `peer_mailbox_api.js` (the chip's message and Unpair calls), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them), `drafts.js` (the composer's drafts: The drafts, below), `draft_keys.js` (their storage keys, so `session_prefs.js` sweeps them without a new export), `answer_write.js` (the answer's live write onto its bubble, kept in its own module so a new `markdown_place.js` or `block_fix.js` importing it never waits on an old `answer_refs.js`) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
44
+ `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `views.js` (the views by hash, in one place: All sessions at `#/sessions` opened, closed and left; a page at `#/p/NAME`, read before the session intent, `hashIntent` calling it `keep`: `body.page-view`, Back to where it was opened from (kept in the history entry's `history.state.from`, so Back and Forward keep it), the session's hash not written while a view owns the URL (`keepSessionHash`), a session picked leaving it; the Pages list at `#/pages` the same way, `body.pages-list`, and the pages pill pressed on either; the session's `#/s/<id>` written; a hash change applied and selected; app.js makes it after the lists and hands its functions lazily to what it made before), the page's modules `page_route.js`, `page_view.js`, `page_model.js`, `page_blocks.js`, `page_table.js`, `page_table_model.js`, `pages_model.js` (the page's one list of pages), `pages_list.js` (the Pages list at `#/pages`, read by `views.js` beside a page's hash), `pages_wiring.js` (`wirePages`: the pill, the list, the view and the links, one call in app.js) and `page_links.js` (a page in chi web: [pages.md](pages.md#chi-web)), `worker_features.js`, `version_notices.js`, `owner_claim.js` (its `showPending` calls the injected `keepSessionHash`, following `views.js`'s rule not to write the session hash while a view owns the URL), `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js`, `peer_text.js`, `peer_row.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `peer_wait.js` (the chip of a peer
45
+ the session waits for, its popover and Cancel: The peer exchange), `peer_mailbox_api.js` (the chip's message and Unpair calls), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them), `drafts.js` (the composer's drafts: The drafts, below), `draft_keys.js` (their storage keys, so `session_prefs.js` sweeps them without a new export), `served_ref.js`
46
+ (`isServedRef`, which the stream's `generation_completed` reads, beside a `modelServed` already set, for a served
47
+ model's `modelServed`), `answer_write.js` (the answer's live write onto its bubble, kept in its own module so a new `markdown_place.js` or `block_fix.js` importing it never waits on an old `answer_refs.js`) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
45
48
 
46
49
  ## One page, every viewer
47
50
 
@@ -681,7 +684,9 @@ row. It also marks the stage `data-stage-missing`: `"1"` when it holds no turn,
681
684
  its status row's rect is off the window or below the composer card's top edge (the user's own tall or folded
682
685
  composer: reported, not fixed), and warns once per visit with counts only — `live_read`, whether `current_turn`
683
686
  came, the replay's event types with their counts, the last replayed end event's turn id beside the running turn's,
684
- the stage's and the composer's rects and the composer's saved floor and fold. The show's `live_read`
687
+ the stage's and the composer's rects and the composer's saved floor and fold. The line waits for the task's own work
688
+ (a microtask): a re-read resets the turn view and draws its read in one task (`session_sync.js resync`), so the
689
+ reset's check sees the stage before the read filled it, and the render's check clears that mark before any line. The show's `live_read`
685
690
  (`SessionShow#live_snapshot`: "ok", "none", "failed") says whether the snapshot read that fills the page came from
686
691
  a live worker; chi web logs the why and the elapsed ms when it did not (bridge.md, The show). The e2e stage check
687
692
  (`spec/e2e/support/fixtures.js`) reads the mark.
@@ -934,10 +939,16 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
934
939
  is the peer chip's only feed, so the page reads it for every session it opens (`hasPeer: () => true`).
935
940
  Read again on: the session drawn (`session_view.js renderSessionView`, through `peerLinks.drawn()`), a
936
941
  `context_added` with `peer`, a `tool_call_completed` with a peer ref, `command_ran` (a `/claude validate`), window
937
- focus, and a 60 s tick while an exchange waits; a `turn_completed` redraws without a fetch (`touch()`) (one interval, cleared with the session: `forgetSession` →
942
+ focus, a peer bundle's `card` (`source` claude-peer or codex-peer) or `hook_notice` (its hook `… (bundle
943
+ claude-peer)`: a wait that ran out), and a 60 s tick while an exchange waits or the session waits for a peer
944
+ (`waiting` on its row: the chip turns paired, or goes, on a phone with no focus event); a `turn_completed` redraws without a fetch (`touch()`) (one interval, cleared with the session: `forgetSession` →
938
945
  `peerLinks.reset()`). The peer chips read the same model: its `onChange` also calls `contextChips.peersChanged()`, and
939
946
  the chips' own load (a session opened) calls `peers.refresh({ reuse: true })`. A pairing made from the peer's side
940
947
  sends the page nothing: the chip appears at the next read (a focus, a peer note, a send).
948
+ - `peer_wait.js` (pure): `waitingChipModel` ("Claude · waiting 8 min", state `awaiting`, apart from a send's
949
+ `waiting`), `waitingPopoverTemplate` (the wait, the minutes left, Cancel: `context_chips.js cancelWait`, the
950
+ Unpair route with no confirm), `waitMinutesLeft`. `peer_chip.js peerGroups` admits a row with `paired_at` or
951
+ `waiting`; a waited-for one is drawn by these.
941
952
  - `peer_mailbox_api.js` (state): `getPeerMessage(id, name, serial)` (a message's text: View latest answer, a
942
953
  mailbox note's "Read the full answer") and `unpairPeer(id, name)` (`DELETE …/peers/NAME`).
943
954
  - `peer_exchange.js` (pure): `peerRef(row)`, `stateText` (long and the phone's short words, both drawn; CSS picks),
@@ -998,7 +1009,8 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
998
1009
  document would close it).
999
1010
  - `peer_chip.js` (pure): a paired peer in the session bar. `peerGroups(peers)` gives one group per peer of the
1000
1011
  model that is paired (`paired_at`; an unpaired one keeps its messages but has no chip): `{key: "peer:<name>", name,
1001
- label, peer}`. `peerChipModel` is the chip, the first state that applies: answers only (`can_send` false: a pairing
1012
+ label, peer}`. `peerChipModel` is the chip, the first state that applies: ended (the server's `ended`: a paired peer's inbox socket
1013
+ is gone, `PeerMailbox.socket_gone?`, and `can_send` false with it; no kitty call and no bundle state read in chi web), answers only (`can_send` false: a pairing
1002
1014
  with no address), can't send (the newest send `failed` and the pairing not renewed since, `paired_at` past the failed
1003
1015
  send's time ends it, `cantSend`), waiting (the newest validate/question `waiting`, its age the send's), answered
1004
1016
  (its newest message unread: no receipt, `held` or `noted`; with the dot), paired. A peer the read doesn't name, an
data/docs/memory.md CHANGED
@@ -446,7 +446,9 @@ chi ships one skill itself: `skill_pages` in the system bundle
446
446
  page ([docs/pages.md](pages.md#asking-chi-for-a-page)). Its index line is in
447
447
  every prompt; its text is read only when a page is asked for. It tells chi not
448
448
  to edit it (a shipped file: a local edit would have to be merged at the next
449
- upgrade) but to say what differed.
449
+ upgrade) but to say what differed. The opt-in reflect bundle ships a second,
450
+ `skill_reflect`: a nightly reflect session's steps, which suggest changes and
451
+ never apply them ([docs/bundles.md](bundles.md#a-nightly-reflect-session)).
450
452
 
451
453
  ## Toolkit memories
452
454
 
@@ -666,7 +668,7 @@ profiles, meta bundles that install a set of them:
666
668
  | profile | bundles |
667
669
  |---|---|
668
670
  | `core` | loop-guard, check-in, guardrails, slow-commands, agents-md, cost-cap, work-cap: the recommended safety set |
669
- | `dev` | known-names, mcp, btw, skills, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes |
671
+ | `dev` | known-names, mcp, btw, skills, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes, decision-card, inline-widgets, knowledge |
670
672
 
671
673
  `chi bootstrap` installs `core` and, on a terminal, offers `dev`. An existing
672
674
  install gets neither by itself: `chi bundle install core` (or `dev`).
data/docs/pages.md CHANGED
@@ -99,7 +99,68 @@ it. On an older chi `runtime` is a `NameError`, and the run fails with it (the l
99
99
  remove it before changing schedules`). The read takes no lock and writes nothing, though chi's debug log may get a
100
100
  line for an entry that doesn't read.
101
101
 
102
- `runtime`, like the rest of the page script DSL, is stable for bundles ([plugins.md](plugins.md#stable-for-bundles)).
102
+ The next four are **experimental** (from the chi after 0.194.0): their members may change while the first page that
103
+ uses them (the reflect bundle's) settles.
104
+
105
+ - **`runtime.sessions(project: nil)`**: one project's sessions over the last 14 days, as counts (a
106
+ `SessionStats::Listing`). Read-only and local: it reads the session files, `analytics.json` and `cards.json`, takes
107
+ no lock and starts no worker.
108
+ - **Which project.** `project:` is a folder: its project is read (a worktree gives its repository, a
109
+ `chi project init` folder its marked folder), even with no session in the window (then `session_count` 0 and no
110
+ sessions). nil, or a folder in no project: the project of the newest session **you started** (not a delegate,
111
+ and started by no agent, schedule or participant; a web tab's, a TUI's, `chi send`'s and a continued link's
112
+ count as yours), else the newest session's. `runtime.sessions(project: runtime.launch_dir)` reads the project
113
+ `chi page run` was typed in.
114
+ - **The listing.** `project` (`name`, `path` with `~` for your home, `session_count`; nil only when no project is
115
+ picked: no `project:` folder in a project and no session in the window), `picked_by` (`"folder"` or `"newest"`),
116
+ `projects` (every other project in the window, most sessions first), `sessions` (newest updated first), `since` (the
117
+ window's start, ISO 8601 UTC), `sessions_capped` (true when more than 500 of the project's sessions matched: the cap
118
+ counts after the project filter, and is lower when `session.max_count` is), `unreadable` (files that didn't read;
119
+ their counts are 0). The 14 days are capped by `session.retention_days`. `test_run` and `scratch` sessions are left
120
+ out; archived ones and delegates count.
121
+ - **A session** (`SessionCounts`): `id`, `created_at`, `updated_at`, `model_name`, `delegate`, `chain_link`,
122
+ `turns`, `tool_calls_by_tool` and `tool_errors_by_tool` (tool → n), `blocked` (every guardrail deny: a rule, a
123
+ hook, you or a parent declining, a tool not in the toolkit), `auto_allowed` (System 1's), `mid_turn_lines` (your
124
+ own lines into a running turn), `steers_by_source` (plugins' steers), `approvals_by_rule` (rule →
125
+ `{"asked", "once", "wide", "denied", "unanswered", "by_parent"}`; a question with no rule under `(no rule)`),
126
+ `cards_at_cap` and `hook_notices_by_bundle` / `notices_at_cap` (see "at least" below), `context_window`,
127
+ `side_cost` (recaps, `/btw`, `ask_model`: a session total, not windowed) and `schedule_id` (the schedule whose
128
+ chain link it is, else nil).
129
+ - **A turn** (`TurnCounts`): `id`, `started_at`, `status` (`completed`, `failed`, `canceled`), `cancel` (`you`: your
130
+ Stop or Ctrl-C, a participant's cancel included; `hook`; `interrupted`: the worker went mid-turn, never a
131
+ cancel; `other`; nil when not cancelled), `cancel_bundle` (the hook's bundle), `automatic` (started by no
132
+ person: a schedule, a delegate report, a reminder), `model` (for a failed turn, its model ref without the host),
133
+ `cost` (reported plus estimated), `tool_calls`, `tool_errors`, `tool_calls_by_tool`, `tool_errors_by_tool`,
134
+ `failure_kind` (one of `host_model_not_found`, `host_rejected`, `host_error`, `timeout`, `host_unreachable`,
135
+ `context_overflow`, `empty_answer`, `other`, `none`; nil unless failed) and `context_used_tokens`.
136
+ - **The window.** Turns count by when they started; tool records, approvals and notices by their turn; your lines
137
+ and steers by their own time; a question with no turn id by when it was asked. Anything with neither is left out.
138
+ - **No text.** Counts, ids, times, model names, the project's name and path, and the names the Hashes are keyed by
139
+ (tools, rules, bundles, steer sources): never a message, a title, a tool's output or command, or a failure's
140
+ words (only its kind).
141
+ - **"At least".** `cards.json` keeps the last 20 questions and cards, and the last 20 notices: `cards_at_cap` /
142
+ `notices_at_cap` say a session's approvals / hook notices may be more. An approval a participant's turn asked
143
+ counts with yours.
144
+ - A running turn reads as its last save: missing, or `interrupted` after a checkpoint.
145
+ - **`runtime.turn_excerpts(turns, include_text: false)`**: for each `[session_id, turn_id]` (worst first, as
146
+ `runtime.sessions` gives them), the turn's failing tool calls with their error results: **text from your
147
+ sessions**, which reaches whatever reads the page. A `TurnExcerpts::Result`: `excerpts`, `left_out` (calls the cap
148
+ dropped), `unpaired`, `unreadable`. An excerpt has `session_id`, `turn_id`, `started_at`, `status`, `failure` (a
149
+ failed turn's line), `calls` (at most 8: `tool`, `target` for a `call_tool`'s `<server>/<tool>`, `status` `error`
150
+ or `blocked`, `args` cut at 200 characters, `result` cut at 300), `paired`, and `prompt` / `answer` (the turn's
151
+ opening message and last answer, cut at 300; nil unless `include_text: true`). Every field has key shapes
152
+ redacted and your home as `~`, and all of them together stay within about 4k tokens (14,000 characters), filled
153
+ in the order given. A turn whose calls can't be matched to its messages exactly (a continue turn, a raw-prompt
154
+ batch) is `paired: false`: its calls with tool and status only, never a guess.
155
+ - **`runtime.launch_dir`**: the folder `chi page run` was typed in, an absolute path; nil when chi web's Refresh ran
156
+ the page, or when the folder is gone. The run itself still happens in the pages folder
157
+ ([Where a run happens](#where-a-run-happens)).
158
+ - **`runtime.settings`**: a bundle page's own settings: the keys its manifest lists in `settings:`, from config.yml
159
+ `bundles: <bundle>:`, as written (the page checks their types). `{}` for your own page, for a bundle with no
160
+ `settings:`, and when config.yml has none.
161
+
162
+ `runtime`, like the rest of the page script DSL, is stable for bundles (except the experimental ones above;
163
+ [plugins.md](plugins.md#stable-for-bundles)).
103
164
 
104
165
  ## Pages from a bundle
105
166
 
@@ -126,6 +187,14 @@ A bundle can ship pages: its manifest's `pages:` names scripts in its `scripts/`
126
187
 
127
188
  - `chi page run NAME` runs the script in a Ruby process of its own and prints a summary of each block: a text's first
128
189
  lines, a table's labels, first rows and total, a walk's step count. `--format json` prints the stored page.
190
+ `--format lines` prints the stored page in full, uncut: the name and title, `ran_at:` (and `error:` after a failed
191
+ run, which exits 1 as json does, followed by the last lines of the script's stderr, indented), then `== block N:
192
+ TYPE` before each block, a text's lines as they are, a table's labels and one row a line (cells formatted as in the
193
+ summary, `|` between, a newline in a cell as a space) and its total, a walk's title and one step a line. In a cell a
194
+ `\` prints as `\\` and a `|` as `\|` (`grep x | head` is `grep x \| head`), so a cell never reads as two; a block's
195
+ line that starts with `== block ` gets a `\` before it, so no block forges another's header. It is the form a model
196
+ reads in parts: one JSON line is cut at a tool result's limit, while `execute` saves long output whole and names the
197
+ file to `read` by `start_line`.
129
198
  - A run that fails (the script raised, has a syntax error, called `exit`, broke a limit, or printed more than 256 KB of
130
199
  blocks) prints `error: line 9: undefined method 'fetch' for nil`, the last lines of what the script wrote to stderr,
131
200
  and exits 1. **The result of the last good run is kept**: a bad edit never blanks the page.
@@ -184,6 +253,8 @@ that breaks the rule). See [the CLI](cli.md#commands).
184
253
  - **The working folder is the pages folder.** A chi command a script runs sees that folder's project: if
185
254
  `~/.config` sits in a git repository, that repository. Pass `--scope=all` to the session commands
186
255
  (`chi sessions list --scope=all --format json`) for every project.
256
+ The folder `chi page run` was typed in reaches the script only as `runtime.launch_dir` (`CHI_PAGE_LAUNCH_DIR`;
257
+ never set from a Refresh, nor inherited).
187
258
  - **The environment is yours**, as a session's worker gets it: the XDG folders absolute, chi's own session markers and
188
259
  guardrails settings left out, and `PWD` the pages folder; chi web's Refresh runs chi web's own chi. `CHI_REMOTE`, a worker's `SAMAGOTCHI_WORKER_*` keys and
189
260
  the agent markers (`CLAUDECODE`, `CODEX_THREAD_ID`, `AI_AGENT`) are left out too: a run is always on this machine,
data/docs/peers.md CHANGED
@@ -8,16 +8,101 @@ peer chip. How it is built: [internals/peers.md](internals/peers.md).
8
8
 
9
9
  ## Pairing
10
10
 
11
- The peer pairs from its side, with its `chi-peer` skill (`/claude install-skill` or `/codex install-skill`
12
- installs it). Its pair script runs one command:
11
+ There are two ways in, and neither needs a session id copied by hand:
12
+
13
+ - **In chi: `/claude pair`.** With exactly one Claude Code session open in this project it pairs at once. With
14
+ none, the session waits 10 minutes: the next Claude you start in the project pairs on its own, and its start
15
+ context says `paired with chi 3f2a9c1e (<title>)`. With several, the session waits and a card lists them, a row
16
+ each (its kitty window's title, folder and age) with **Show** (brings that window to the front) and **Pair**.
17
+ `/claude` alone shows the same list, or that none is open, or the wait. `/claude unpair` (or the chip's Unpair,
18
+ or the waiting chip's Cancel) ends the pairing or the wait. When a wait runs out, one line says so: "No Claude
19
+ Code session came in 10 min; /claude pair to wait again." On a session already paired, `/claude pair` refuses
20
+ ("unpair first"), unless that Claude is gone (its inbox socket missing): then the pairing ends, the reply says so,
21
+ and it pairs or waits as above. `/codex pair` only waits: Codex doesn't list itself, and its pairing is never gone.
22
+ - **In the peer: "pair with chi".** Its `chi-peer` skill (`/claude install-skill` or `/codex install-skill`
23
+ installs it) runs its pair script with no id, `chi peer pair claude --here …`: it pairs with the session that
24
+ waits in this project, else the chi session of this project that runs now and is paired with this peer already
25
+ (it says paired: codex-peer's start hook paired it), else the one chi session of this project that runs now, else
26
+ it lists them and the peer asks you which. A session paired with another Claude already is refused ("/claude unpair there first"), never
27
+ replaced, unless that Claude is gone (its inbox socket missing): then the pairing ends, as `/claude pair` ends it,
28
+ and it says so; one another pairing is taking right now is refused too ("try again"). With an id it pairs that session
29
+ (replacing its pairing):
13
30
 
14
31
  ```sh
15
- chi peer pair claude <session id> --address <where chi sends> --from "<who paired>"
32
+ chi peer pair claude <session id> --address <where chi sends> --from "<who paired>" [--peer-session <its id>]
16
33
  ```
17
34
 
18
35
  - `--address` is where chi's sends go: Claude Code's inbox socket, Codex's thread id. A pairing without one
19
36
  answers only: the peer can say, chi can't send to it (a peer on another machine with no forwarded socket).
20
- - Pairing again only replaces the address (a Claude Code restart gives it a new socket).
37
+ - Pairing again with an id replaces the pairing whole: its address, who paired (`--from`) and its peer session
38
+ (dropped when not passed). `--peer-session` names the peer's own session (Claude's pair script
39
+ passes `CLAUDE_CODE_SESSION_ID`): it is how a restart finds its pairing.
40
+
41
+ **Claude's start hook.** A Claude Code session lists itself here only with claude-peer's start hook: the
42
+ `/claude install-skill` card's **Add the start hook…** shows the exact line and the merged settings as a diff,
43
+ and that card's **Add the start hook** merges it into Claude Code's settings.json, on your tap only. It runs `chi peer announce claude` when an interactive Claude starts (never a
44
+ headless `claude -p`; subagents start no session). With it a Claude restart (`claude --resume`) keeps its pairing
45
+ (its start context says `chi <id8>: pairing refreshed`), and a `/clear` keeps it too. Without it, `/claude pair`
46
+ finds no Claude, and the peer pairs again with "pair with chi" after a restart. The line names the chi of your chi
47
+ home (`ChiShim.path`): run without one (a checkout's `bin/chi`, a state with no chi home) it can point at a chi that
48
+ isn't there, and its `2>/dev/null || true` (a failing hook would show "hook failed" in Claude) hides that; the status
49
+ card says when the line points at a chi that is gone.
50
+
51
+ **Codex's start hook.** codex-peer has one too: the `/codex install-skill` card's **Add the start hook…** shows the
52
+ exact line (`<chi> peer announce codex 2>/dev/null || true`) and the merged `$CODEX_HOME/hooks.json` (else
53
+ `~/.codex/hooks.json`) as a diff, and its card's **Add the start hook** appends it there on your tap: the one file it
54
+ writes, never `config.toml`, every other hook kept in its place (Codex keys a hook's trust by its place). With it, a
55
+ new Codex in this project pairs with a session that waits (`/codex pair`, `/codex start`) at its **first message**,
56
+ whatever it says ("look at the failing spec"), so no turn goes to "pair with chi"; its start context says `paired with
57
+ chi <id8> (<title>): …`. Codex fires the hook with the first message, never while it sits idle, so a Codex already open
58
+ still pairs with "pair with chi". A `codex exec` (a Codex builder, a review run), an `exec resume` and a `codex resume`
59
+ never take the wait: chi reads the first line of the session's rollout file and pairs only a fresh interactive Codex
60
+ (checked on Codex 0.172.0). A Codex subagent should not take it either (untested: the check fails closed unless its
61
+ `thread_source` and `originator` match an interactive Codex's). A `/new` in a Codex window starts a new thread, which
62
+ likely takes the wait, as a new window does. There is no list of Codex sessions in `/codex pair` (a Codex can't be told alive, nor
63
+ shown).
64
+ - **Review it in Codex.** Codex asks you to review a new or changed hook the next time it starts ("Hooks need
65
+ review": choose Review hooks, or `/hooks` later, and trust it); until then it skips the hook, silently. chi never
66
+ writes Codex's trust and never passes a trust-bypass flag. A Codex started by `/codex start` stops on that screen
67
+ in its kitty window the first time: its opened line says so; Show the window and answer it.
68
+ - A line pointing at a chi that is gone (a moved chi home) shows on the status card; adding it again changes the hook,
69
+ so Codex asks for the review again.
70
+ - Codex runs an interactive session's hooks in its app-server daemon, with the env of the Codex that started the
71
+ daemon: a `CHI_REMOTE` there makes chi exit before the announce, and `2>/dev/null || true` hides it (nothing pairs,
72
+ nothing shows). The card reads only `$CODEX_HOME/hooks.json`: an announce line you put in `config.toml`'s `[hooks]`
73
+ or a project's `.codex/hooks.json` isn't seen (the card offers to add it).
74
+
75
+ **Start one in kitty: `/claude start`.** chi makes the session wait, then opens a kitty window in the session's
76
+ folder, running `claude` through your login shell (the setting `bundles: claude-peer: start_command:` replaces it, a
77
+ shell line, so you can add flags; read when the session's worker starts, as every bundle setting is, so restart the
78
+ session after changing it); the Claude there pairs on its own when it starts, through the start hook. Where it opens:
79
+
80
+ - **A pane next to this chi** (the default): when this session's chi terminal runs in kitty, Claude opens in that
81
+ terminal's tab, beside it, whichever tab you are in now: a split in kitty's `splits` layout, the layout's next slot
82
+ in the others (in `fat`, kitty's default, a strip under chi). The start line says "opened a pane next to this chi".
83
+ The same from chi web or the phone, while the session's terminal is attached.
84
+ - **A background tab** titled `claude · chi <id8>` otherwise, and the start line says why: no chi terminal of this
85
+ session in kitty (a start from chi web with no terminal attached, a chi terminal in another app or inside tmux), its
86
+ tab in the `stack` layout (the pane would hide behind chi), or kitty refusing the pane. The tab opens in the kitty
87
+ whose window has the focus, else the one started last. `bundles: claude-peer: open_in: tab` always opens the tab
88
+ (`open_in: pane` is the default; another value is taken as `pane`, and the start line says so).
89
+
90
+ Neither takes the focus. With two chi terminals of the session in kitty, the one in the focused tab wins. `/claude`
91
+ then says **Paired · started by chi** with chi's label for it, `claude · chi <id8>` (a pane carries no title of
92
+ chi's; only the tab is titled so), and **Show** (`/claude show`, which brings the window to
93
+ the front); once the window is closed it says so, with **Start one in kitty**. It needs kitty with remote control (`kitty.listen_on`, [configuration.md](configuration.md#desktop-helper-agents-in-kitty-and-tmux)):
94
+ without it, "kitty isn't running or `kitty.listen_on` isn't set", and nothing waits. It refuses on a session already
95
+ paired, and without the start hook ("install the start hook first"). From the phone it works the same while kitty runs
96
+ on the working machine. `/codex start` opens Codex the same way (`bundles: codex-peer: start_command:`, default
97
+ `codex`, and `open_in`) with the first prompt "pair with chi", which runs the skill's pair and so spends one Codex turn; it needs no
98
+ hook (with Codex's start hook, the hook pairs at that first message and the skill's pair says paired). Start, Show and pasting into a window run only from your typing or tap: no tool call, `chi send`, agent, participant,
99
+ schedule or delegate reaches them. A second Start while the first window is still starting is refused, two at the same
100
+ moment included (they take turns). A window that closes at once (its command isn't found in the login shell's PATH: it
101
+ runs as `$SHELL -l -c "exec <start_command>"`) is said so, and leaves no wait; after its Claude ended, the status card's
102
+ title reads `claude-peer: ended` and the chip `Claude · ended`.
103
+
104
+ Who is here is a folder any local process can write (it sits in the mailbox root): a row shows nothing a forger
105
+ can't set, and your Pair is what trusts it, as the pair and say commands are unauthenticated already.
21
106
  - `chi peer unpair claude <id>` ends the pairing. Its messages stay, and chi still reads those it hasn't. The
22
107
  peer chip's **Unpair** does the same.
23
108
  - `chi peer pair` refuses a session whose live worker is older than the mailbox ("restart the session"). Pairing a
@@ -51,7 +136,7 @@ It prints one line, which the skills tell the agent to quote to its user:
51
136
  | started a turn | `#12 received · woke chi` |
52
137
  | held it | `#12 received · held: 3 peer turns in a row (peer.turns) · waits for the user's next message`, `held: chi's cache is cold · waits for the user's next message` |
53
138
  | took it as background | `#12 received · noted` |
54
- | can't say yet | `#12 received · chi is in a turn: it reads this when the turn ends`, `chi is stopped: …`, `this session is archived: …`, `chi's worker isn't running and couldn't be started from here: …` |
139
+ | can't say yet | `#12 received · chi is in a turn: it reads this when the turn ends`, `chi is stopped: it reads this when its user starts it (chi --resume 1a2b3c4d)` (a peer's say never starts a stopped session), `this session is archived: …`, `chi's worker isn't running and couldn't be started from here: …` |
55
140
  | nothing within the wait | `#12 received · no answer from chi yet` |
56
141
  | refused | `refused: no bundle in that session declares peer claude` (exit 1) |
57
142