samagotchi 0.193.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +77 -1
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +37 -12
- data/docs/cli.md +26 -10
- data/docs/configuration.md +71 -5
- data/docs/desktop.md +3 -0
- data/docs/guardrails.md +11 -1
- data/docs/hooks.md +1 -0
- data/docs/internals/engine.md +46 -3
- data/docs/internals/panes.md +66 -0
- data/docs/internals/peers.md +101 -5
- data/docs/internals/prompt-caching.md +4 -0
- data/docs/internals/session-lifecycle.md +9 -2
- data/docs/internals/web-frontend.md +16 -4
- data/docs/peers.md +79 -5
- data/docs/plugins.md +42 -4
- data/docs/sessions.md +15 -6
- data/docs/sub-agent.md +6 -4
- data/docs/system-one.md +4 -0
- data/docs/testing.md +3 -0
- data/lib/samagotchi/bridge/card_store.rb +1 -1
- data/lib/samagotchi/broadcast/triage_model.rb +17 -0
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +8 -5
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +24 -5
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +28 -7
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +31 -8
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +8 -5
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +62 -6
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +23 -2
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +28 -7
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/chi_invocation.rb +7 -0
- data/lib/samagotchi/client.rb +18 -0
- data/lib/samagotchi/codex_rollout.rb +93 -0
- data/lib/samagotchi/config.rb +15 -6
- data/lib/samagotchi/effective_model.rb +28 -2
- data/lib/samagotchi/engine/cards.rb +9 -4
- data/lib/samagotchi/engine/hooks.rb +8 -0
- data/lib/samagotchi/engine/models.rb +180 -7
- data/lib/samagotchi/engine/side_requests.rb +72 -13
- data/lib/samagotchi/engine/toolkit.rb +1 -1
- data/lib/samagotchi/engine/turn_helpers.rb +1 -1
- data/lib/samagotchi/engine.rb +11 -8
- data/lib/samagotchi/engine_snapshots.rb +16 -3
- data/lib/samagotchi/events.rb +1 -0
- data/lib/samagotchi/hooks.rb +3 -1
- data/lib/samagotchi/host_registry.rb +146 -16
- data/lib/samagotchi/idle_client.rb +13 -2
- data/lib/samagotchi/idle_recap.rb +33 -3
- data/lib/samagotchi/idle_target.rb +27 -7
- data/lib/samagotchi/llm/adapter_common.rb +4 -2
- data/lib/samagotchi/llm/anthropic_messages.rb +3 -2
- data/lib/samagotchi/llm/errors.rb +35 -4
- data/lib/samagotchi/llm/model_listing.rb +19 -0
- data/lib/samagotchi/llm/openai_chat.rb +3 -2
- data/lib/samagotchi/model_binding.rb +46 -4
- data/lib/samagotchi/model_catalog.rb +68 -8
- data/lib/samagotchi/model_profile.rb +35 -0
- data/lib/samagotchi/models_command.rb +8 -4
- data/lib/samagotchi/panes/kitty.rb +122 -0
- data/lib/samagotchi/panes.rb +185 -0
- data/lib/samagotchi/peer_announce.rb +245 -0
- data/lib/samagotchi/peer_command.rb +97 -11
- data/lib/samagotchi/peer_continue.rb +10 -0
- data/lib/samagotchi/peer_mailbox.rb +30 -7
- data/lib/samagotchi/peer_pair_here.rb +149 -0
- data/lib/samagotchi/peer_presence.rb +434 -0
- data/lib/samagotchi/peer_say.rb +17 -10
- data/lib/samagotchi/peer_wait_expiry.rb +47 -0
- data/lib/samagotchi/plugin/api.rb +12 -1
- data/lib/samagotchi/plugin/card.rb +68 -11
- data/lib/samagotchi/plugin/context.rb +20 -1
- data/lib/samagotchi/plugin/panes.rb +54 -0
- data/lib/samagotchi/plugin/peer.rb +52 -10
- data/lib/samagotchi/plugin/peer_pairing.rb +290 -0
- data/lib/samagotchi/plugin/peer_start.rb +301 -0
- data/lib/samagotchi/plugin/peer_start_hook.rb +207 -0
- data/lib/samagotchi/plugin/peers.rb +76 -3
- data/lib/samagotchi/recap_setup.rb +40 -3
- data/lib/samagotchi/self_report.rb +25 -6
- data/lib/samagotchi/send_command.rb +6 -6
- data/lib/samagotchi/served_lookup.rb +225 -0
- data/lib/samagotchi/served_ref.rb +41 -0
- data/lib/samagotchi/session_access/contract.rb +6 -0
- data/lib/samagotchi/session_access/local.rb +54 -6
- data/lib/samagotchi/session_access/remote.rb +4 -4
- data/lib/samagotchi/session_access/remote_peers.rb +7 -4
- data/lib/samagotchi/session_commands.rb +40 -8
- data/lib/samagotchi/session_continue.rb +6 -2
- data/lib/samagotchi/session_lifecycle/allowed.rb +4 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -0
- data/lib/samagotchi/session_manager/lifecycle.rb +58 -7
- data/lib/samagotchi/session_manager/removal.rb +3 -0
- data/lib/samagotchi/session_model_settings.rb +7 -3
- data/lib/samagotchi/session_stores.rb +9 -0
- data/lib/samagotchi/sessions_command.rb +16 -3
- data/lib/samagotchi/system_one/http_backend.rb +111 -10
- data/lib/samagotchi/system_prompt.rb +11 -4
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +26 -12
- data/lib/samagotchi/terminal_ui/status_row.rb +20 -3
- data/lib/samagotchi/terminal_ui.rb +1 -1
- data/lib/samagotchi/testing/bundle.rb +6 -2
- data/lib/samagotchi/turn_endings.rb +6 -2
- data/lib/samagotchi/user_typed.rb +29 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +8 -20
- data/lib/samagotchi/web/participant_review.rb +1 -1
- data/lib/samagotchi/web/participant_view.rb +1 -1
- data/lib/samagotchi/web/peer_routes.rb +33 -13
- data/lib/samagotchi/web/public/app.js +1 -1
- data/lib/samagotchi/web/public/card.js +26 -10
- data/lib/samagotchi/web/public/context_chips.js +24 -2
- data/lib/samagotchi/web/public/copy.js +8 -2
- data/lib/samagotchi/web/public/data.js +2 -1
- data/lib/samagotchi/web/public/format.js +9 -1
- data/lib/samagotchi/web/public/index.html +18 -0
- data/lib/samagotchi/web/public/info_bar_model.js +1 -1
- data/lib/samagotchi/web/public/model_pick.js +18 -5
- data/lib/samagotchi/web/public/model_picker.js +1 -1
- data/lib/samagotchi/web/public/peer_chip.js +15 -5
- data/lib/samagotchi/web/public/peer_data.js +4 -2
- data/lib/samagotchi/web/public/peer_wait.js +36 -0
- data/lib/samagotchi/web/public/served_ref.js +9 -0
- data/lib/samagotchi/web/public/session_fields.js +1 -0
- data/lib/samagotchi/web/public/session_state.js +4 -0
- data/lib/samagotchi/web/public/stage_missing.js +23 -6
- data/lib/samagotchi/web/public/stream_handlers.js +16 -0
- data/lib/samagotchi/web/public/version_notices.js +7 -1
- data/lib/samagotchi/web/session_control.rb +19 -10
- data/lib/samagotchi/web/session_show.rb +20 -0
- data/lib/samagotchi/web/update_ops.rb +2 -2
- data/lib/samagotchi/worker/command_queue.rb +3 -0
- data/lib/samagotchi/worker/mail.rb +14 -1
- data/lib/samagotchi/worker.rb +1 -0
- metadata +18 -1
|
@@ -0,0 +1,66 @@
|
|
|
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` and `show` find and raise a window; `open`,
|
|
5
|
+
`alive?` and `paste` open a background tab and type into it (claude-peer's and codex-peer's `/<peer> start`,
|
|
6
|
+
`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
|
+
- **Show:** `focus-window --match id:N` on its socket: it brings a background tab forward, and a background OS
|
|
22
|
+
window (checked with `kitty @ ls`'s `is_focused` while the screen was unlocked).
|
|
23
|
+
- **Open:** `open(command:, cwd:, title:)` runs `launch --type=tab --keep-focus --cwd DIR --tab-title TITLE ARGV…`
|
|
24
|
+
on the kitty whose OS window is focused (`ls`'s `is_focused`), else the live socket file with the newest mtime (the
|
|
25
|
+
kitty started last), and returns `PaneRef(driver, key)`, the key `<socket>#<window id>` from the id `launch`
|
|
26
|
+
prints. A tab only: `--type=os-window --keep-focus` doesn't keep the focus (the step-0 spike). `launch` has its own
|
|
27
|
+
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
|
|
28
|
+
raises `Panes::Unavailable`, the one message "kitty isn't running or `kitty.listen_on` isn't set"; a launch that
|
|
29
|
+
fails or prints no id raises `Panes::Error`.
|
|
30
|
+
- **Alive and paste:** `alive?(ref)` is `ls --match id:N` on the ref's socket. `paste(ref, text, enter:)` is the
|
|
31
|
+
helper's `KittyRunner#send`: `alive?` first (send-text reports nothing for a gone window), then
|
|
32
|
+
`send-text --match id:N --bracketed-paste=disable --stdin` with the text wrapped in `ESC[200~ … ESC[201~` (its own
|
|
33
|
+
markers taken out, as `AgentText.text`), then `send-key --match id:N enter` when `enter`. No in-tree caller pastes
|
|
34
|
+
yet: `/codex start` passes its first prompt as Codex's own argument (`codex [PROMPT]`), which doesn't race the
|
|
35
|
+
TUI's start as a paste would.
|
|
36
|
+
- **Config:** `kitty.listen_on` and `kitty.binary` are read at each call (`Panes.from_config`, `Config.get`); their
|
|
37
|
+
lifecycle is `next_pane_lookup` (the desktop helper still copies them into its launch file).
|
|
38
|
+
- **No kitty** (unset, not running, the pid in no window, the binary missing): nothing found, no error; a row then
|
|
39
|
+
has no Show.
|
|
40
|
+
|
|
41
|
+
`ctx.panes` (`Plugin::Panes`, [plugins.md](../plugins.md)) is the plugin's view: `find(pid:)`, `alive?(ref)`, and
|
|
42
|
+
`show`, `open` and `paste`, which raise `Plugin::Panes::NotTyped` unless the command was typed or tapped by a person
|
|
43
|
+
(`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
|
|
44
|
+
paste: `/<peer> start` keeps its `PaneRef` in the bundle's own session state (`state.json` under `ctx.session_dir`, a
|
|
45
|
+
`SessionStores` row removed with the session), never in the mailbox. That file is not protected (chi's own tools can
|
|
46
|
+
write it), so a ref is checked on every use instead: `alive?`, `show` and `paste` take a ref only when its socket is
|
|
47
|
+
one of `kitty.listen_on`'s own (`Kitty.sockets`), else they answer as for a closed tab and run no `kitty @`; a paired
|
|
48
|
+
session's `/<peer> show` also needs the paired peer's pid in that window. A continue doesn't carry that state (the
|
|
49
|
+
pairing it does).
|
|
50
|
+
|
|
51
|
+
`/<peer> start` (`Plugin::PeerStart`): the checks (typed, no live pairing, claude-peer's start hook current), then
|
|
52
|
+
the wait (`ctx.peers.wait`), then `open` with `[$SHELL, -l, -c, "exec <start_command>"]` (the account's shell when
|
|
53
|
+
`$SHELL` is unset). An open wait (`/<peer> pair`'s) is kept, not rewritten; a pane error takes back only the wait
|
|
54
|
+
this start wrote (`ctx.peers.stop_waiting(name, mark)`, `PeerPresence.drop_wait`: never another wait nor an announce's
|
|
55
|
+
claimed file), so a refusal leaves no mark of its own. A second start while the wait is open and its tab `alive?` (a
|
|
56
|
+
double tap) is refused, "already starting in kitty tab …"; two at the same moment take turns on a flock
|
|
57
|
+
(`start.lock` in `ctx.session_dir`, held across the checks, the wait and the open: commands run in parallel). The tab
|
|
58
|
+
is checked once more 1.5 s after the launch (`PeerStart.settle_seconds`): gone already (its command not found), the
|
|
59
|
+
start's wait is taken back and the reply names `start_command`. The
|
|
60
|
+
status card's started row (scene 5) shows while the ref is `alive?` and the paired Claude's pid (its `PeerHere`) runs
|
|
61
|
+
in that window, and "its kitty tab is closed" once the ref is gone and so is the pairing's socket.
|
|
62
|
+
|
|
63
|
+
Specs: `spec/panes_spec.rb` (on `spec/fixtures/desktop/fake_kitty`, which answers `ls`, `launch`, `focus-window`,
|
|
64
|
+
`send-text` and `send-key`, and logs the argv, stdin and `KITTY_*` env it got; its canned windows carry pids, its OS
|
|
65
|
+
windows `is_focused`) and `spec/samagotchi/bundles/claude_peer_start_spec.rb`. No spec reaches a running kitty
|
|
66
|
+
([testing.md](../testing.md)).
|
data/docs/internals/peers.md
CHANGED
|
@@ -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
|
|
14
|
-
|
|
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,98 @@ 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 tab running the peer: it has no path of its own to pair (the
|
|
130
|
+
started Claude's announce takes the wait; codex-peer's first prompt runs the skill's `--here`, or its start hook
|
|
131
|
+
takes the wait at that prompt; `#start_needs_hook?`: claude true, codex false, and codex's opened line adds
|
|
132
|
+
`#start_review_hint` while its hook is current); its `PaneRef` lives
|
|
133
|
+
in the bundle's `state.json`, never here ([panes.md](panes.md)).
|
|
134
|
+
|
|
41
135
|
## Who is a peer
|
|
42
136
|
|
|
43
137
|
- **The worker:** `PeerRegistry`, filled by `chi.peer NAME` (`Plugin::Api#peer`, staged until the plugin's
|
|
@@ -204,11 +298,13 @@ starts empty).
|
|
|
204
298
|
|
|
205
299
|
`Web::PeerRoutes` (all `:owner`, a participant gets 403):
|
|
206
300
|
|
|
207
|
-
- `GET …/peers` → `{peers: [{name, label, paired_at, from, address, can_send, messages, exchanges}]}`: one
|
|
208
|
-
mailbox folder (`PeerRoster`),
|
|
301
|
+
- `GET …/peers` → `{peers: [{name, label, paired_at, from, address, can_send, messages, exchanges, waiting}]}`: one
|
|
302
|
+
row per mailbox folder (`PeerRoster`), and one per peer this session waits for, with `waiting: {until}` (a fresh
|
|
303
|
+
wait only: `#waiting_rows`; the page's waiting chip, `peer_wait.js`), its newest 20 messages with their receipts and `words`
|
|
209
304
|
(`PeerRoster.state_words`), and `exchanges` (`PeerExchanges.joined` over chi's sends and the messages as answer
|
|
210
305
|
lines). No text.
|
|
211
|
-
- `GET …/peers/NAME/messages/SERIAL` (the text and its receipt); `DELETE …/peers/NAME` (Unpair
|
|
306
|
+
- `GET …/peers/NAME/messages/SERIAL` (the text and its receipt); `DELETE …/peers/NAME` (Unpair, and the waiting
|
|
307
|
+
chip's Cancel: `Local#peer_unpair` ends the wait too; `waited: true` says one ended); `POST
|
|
212
308
|
…/peers/NAME/pair` and `…/say` (the remote's; the say waits here).
|
|
213
309
|
|
|
214
310
|
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
|
|
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
|
|
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), `
|
|
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
|
|
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,
|
|
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:
|
|
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/peers.md
CHANGED
|
@@ -8,16 +8,90 @@ peer chip. How it is built: [internals/peers.md](internals/peers.md).
|
|
|
8
8
|
|
|
9
9
|
## Pairing
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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 background tab the first time: its opened line says so; Show the tab 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 background kitty tab titled
|
|
76
|
+
`claude · chi <id8>` in the session's folder, running `claude` through your login shell (the setting
|
|
77
|
+
`bundles: claude-peer: start_command:` replaces it, a shell line, so you can add flags; read when the session's worker
|
|
78
|
+
starts, as every bundle setting is, so restart the session after changing it); the Claude there pairs on its
|
|
79
|
+
own when it starts, through the start hook. The tab opens in the kitty whose window has the focus, else the one
|
|
80
|
+
started last, and never takes the focus. `/claude` then says **Paired · started by chi** with the tab's title and
|
|
81
|
+
**Show** (`/claude show`, which brings the tab to the front); once the tab is closed it says so, with **Start one in
|
|
82
|
+
kitty**. It needs kitty with remote control (`kitty.listen_on`, [configuration.md](configuration.md#desktop-helper-agents-in-kitty-and-tmux)):
|
|
83
|
+
without it, "kitty isn't running or `kitty.listen_on` isn't set", and nothing waits. It refuses on a session already
|
|
84
|
+
paired, and without the start hook ("install the start hook first"). From the phone it works the same while kitty runs
|
|
85
|
+
on the working machine. `/codex start` opens Codex the same way (`bundles: codex-peer: start_command:`, default
|
|
86
|
+
`codex`) with the first prompt "pair with chi", which runs the skill's pair and so spends one Codex turn; it needs no
|
|
87
|
+
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 tab run only from your typing or tap: no tool call, `chi send`, agent, participant,
|
|
88
|
+
schedule or delegate reaches them. A second Start while the first tab is still starting is refused, two at the same
|
|
89
|
+
moment included (they take turns). A tab that closes at once (its command isn't found in the login shell's PATH: it
|
|
90
|
+
runs as `$SHELL -l -c "exec <start_command>"`) is said so, and leaves no wait; after its Claude ended, the status card's
|
|
91
|
+
title reads `claude-peer: ended` and the chip `Claude · ended`.
|
|
92
|
+
|
|
93
|
+
Who is here is a folder any local process can write (it sits in the mailbox root): a row shows nothing a forger
|
|
94
|
+
can't set, and your Pair is what trusts it, as the pair and say commands are unauthenticated already.
|
|
21
95
|
- `chi peer unpair claude <id>` ends the pairing. Its messages stay, and chi still reads those it hasn't. The
|
|
22
96
|
peer chip's **Unpair** does the same.
|
|
23
97
|
- `chi peer pair` refuses a session whose live worker is older than the mailbox ("restart the session"). Pairing a
|
|
@@ -51,7 +125,7 @@ It prints one line, which the skills tell the agent to quote to its user:
|
|
|
51
125
|
| started a turn | `#12 received · woke chi` |
|
|
52
126
|
| 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
127
|
| 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:
|
|
128
|
+
| 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
129
|
| nothing within the wait | `#12 received · no answer from chi yet` |
|
|
56
130
|
| refused | `refused: no bundle in that session declares peer claude` (exit 1) |
|
|
57
131
|
|
data/docs/plugins.md
CHANGED
|
@@ -931,7 +931,7 @@ 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 |
|
|
@@ -1030,6 +1030,17 @@ ctx.card(id: id, title: "Build finished", body: "no warnings left") # replaces
|
|
|
1030
1030
|
needs chi 0.183.0: set `requires_chi: ">= 0.183.0"` in the bundle by hand
|
|
1031
1031
|
(`chi bundle check` can't see an action's keys); an older chi refuses the
|
|
1032
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
|
+
```
|
|
1033
1044
|
- `level:` is `:info` or `:warn` (the warning colour).
|
|
1034
1045
|
- An `:info` card with no actions and a body of one short line (up to 160
|
|
1035
1046
|
characters) is a notice: the web shows it as a one-line row,
|
|
@@ -1040,7 +1051,7 @@ ctx.card(id: id, title: "Build finished", body: "no warnings left") # replaces
|
|
|
1040
1051
|
web updates the card in place; the terminal prints it again, marked
|
|
1041
1052
|
`(updated)`. A card that waits for something (a model's answer) shows
|
|
1042
1053
|
first, then is replaced.
|
|
1043
|
-
- A bad card (no title, a bad level or
|
|
1054
|
+
- A bad card (no title, a bad level, action or row) raises `ArgumentError`.
|
|
1044
1055
|
|
|
1045
1056
|
Where it shows:
|
|
1046
1057
|
|
|
@@ -1647,12 +1658,39 @@ ctx.peers.left_behind("claude") # the previous link's pairing, in a continue's
|
|
|
1647
1658
|
ctx.peers.message("claude", 12) # => #<data PeerMessage serial=12, text="…", summary="…", wake=true, re="s-ab12cd", at="…"> or nil
|
|
1648
1659
|
ctx.peers.message("claude", 3, box: "1a2b3c4d") # box: the note's box, or the continued session's id8 (its mailbox)
|
|
1649
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)
|
|
1650
1674
|
```
|
|
1651
1675
|
|
|
1652
1676
|
What a peer bundle reads of its peer's side of the session (the mailbox,
|
|
1653
1677
|
[peers.md](peers.md)): the pairing (`address` nil: the peer answers only) and
|
|
1654
|
-
the peer's messages.
|
|
1655
|
-
|
|
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
|
|
1656
1694
|
link, so its `link` is the previous link's pairing as it was; `left_behind`
|
|
1657
1695
|
is the one the previous link keeps (the copy's source; an older chi left the
|
|
1658
1696
|
new link unpaired). Needs the next chi.
|
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
|
|
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 |
|
|
@@ -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)
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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 (
|
|
61
|
-
stopped; only its owner's message starts it again
|
|
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
|
|
71
|
-
|
|
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
|