samagotchi 0.187.0 → 0.188.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 +55 -1
- data/bin/chi +2 -0
- data/docs/architecture.md +8 -4
- data/docs/bundles.md +124 -120
- data/docs/cli.md +25 -5
- data/docs/configuration.md +4 -4
- data/docs/context.md +18 -162
- data/docs/guardrails.md +3 -1
- data/docs/hooks.md +2 -1
- data/docs/internals/attached-context.md +19 -37
- data/docs/internals/bridge.md +1 -0
- data/docs/internals/engine.md +2 -2
- data/docs/internals/llm-context-forget.md +5 -6
- data/docs/internals/objectives.md +1 -0
- data/docs/internals/pages.md +6 -3
- data/docs/internals/peers.md +149 -0
- data/docs/internals/remote-sessions.md +7 -4
- data/docs/internals/web-frontend.md +61 -37
- data/docs/internals/web-push.md +1 -1
- data/docs/memory.md +1 -1
- data/docs/pages.md +2 -1
- data/docs/peers.md +141 -0
- data/docs/plugins.md +52 -27
- data/docs/sessions.md +8 -4
- data/docs/sub-agent.md +5 -5
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundle_command/api_calls.rb +2 -1
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -18
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +22 -16
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +48 -39
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +15 -73
- data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +16 -16
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -15
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +35 -24
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +51 -40
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +18 -54
- data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +16 -16
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/plugin.rb +14 -8
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +15 -1
- data/lib/samagotchi/config.rb +8 -7
- data/lib/samagotchi/context_absorber.rb +23 -277
- data/lib/samagotchi/context_sources.rb +17 -69
- data/lib/samagotchi/engine/messages.rb +12 -1
- data/lib/samagotchi/engine/plugins.rb +1 -1
- data/lib/samagotchi/engine.rb +7 -6
- data/lib/samagotchi/engine_peers.rb +0 -3
- data/lib/samagotchi/guardrail_wiring.rb +2 -0
- data/lib/samagotchi/guardrails/chi_dirs.rb +4 -3
- data/lib/samagotchi/guardrails/parent_approvals.rb +6 -5
- data/lib/samagotchi/guardrails/protected_paths.rb +6 -3
- data/lib/samagotchi/inline_widgets.rb +11 -3
- data/lib/samagotchi/log_line.rb +1 -1
- data/lib/samagotchi/note_move.rb +3 -1
- data/lib/samagotchi/page_command.rb +18 -9
- data/lib/samagotchi/pages/builder.rb +7 -8
- data/lib/samagotchi/pages/launch.rb +8 -2
- data/lib/samagotchi/pages/store.rb +11 -2
- data/lib/samagotchi/peer_command.rb +192 -0
- data/lib/samagotchi/peer_continue.rb +99 -0
- data/lib/samagotchi/peer_exchanges.rb +3 -3
- data/lib/samagotchi/peer_mailbox.rb +360 -0
- data/lib/samagotchi/peer_note.rb +208 -0
- data/lib/samagotchi/peer_receipts.rb +247 -0
- data/lib/samagotchi/peer_registry.rb +44 -0
- data/lib/samagotchi/peer_roster.rb +79 -0
- data/lib/samagotchi/peer_say.rb +168 -0
- data/lib/samagotchi/plugin/api.rb +29 -21
- data/lib/samagotchi/plugin/context.rb +7 -0
- data/lib/samagotchi/plugin/loader.rb +3 -3
- data/lib/samagotchi/plugin/peer.rb +175 -64
- data/lib/samagotchi/plugin/peers.rb +70 -0
- data/lib/samagotchi/run_options.rb +2 -1
- data/lib/samagotchi/schedule_command.rb +10 -3
- data/lib/samagotchi/schedule_display.rb +32 -0
- data/lib/samagotchi/session_access/contract.rb +18 -1
- data/lib/samagotchi/session_access/local.rb +132 -14
- data/lib/samagotchi/session_access/remote.rb +4 -2
- data/lib/samagotchi/session_access/remote_peers.rb +75 -0
- data/lib/samagotchi/session_continue.rb +12 -0
- data/lib/samagotchi/session_inbox_delivery.rb +5 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -3
- data/lib/samagotchi/session_manager/removal.rb +2 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -1
- data/lib/samagotchi/session_manager.rb +1 -0
- data/lib/samagotchi/session_stores.rb +17 -0
- data/lib/samagotchi/steer.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +4 -1
- data/lib/samagotchi/testing/boundary.rb +4 -13
- data/lib/samagotchi/testing/bundle.rb +40 -5
- data/lib/samagotchi/testing/install.rb +4 -4
- data/lib/samagotchi/testing/recording_api.rb +2 -1
- data/lib/samagotchi/tools/context_read.rb +0 -14
- data/lib/samagotchi/tools/list_schedules.rb +8 -3
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +2 -13
- data/lib/samagotchi/web/message_display.rb +4 -2
- data/lib/samagotchi/web/peer_routes.rb +133 -0
- data/lib/samagotchi/web/public/app.js +11 -11
- data/lib/samagotchi/web/public/bubbles.js +2 -2
- data/lib/samagotchi/web/public/cards_place.js +20 -1
- data/lib/samagotchi/web/public/context_chips.js +45 -46
- data/lib/samagotchi/web/public/history_reveal.js +4 -1
- data/lib/samagotchi/web/public/history_shape.js +3 -2
- data/lib/samagotchi/web/public/index.html +13 -0
- data/lib/samagotchi/web/public/notify.js +1 -1
- data/lib/samagotchi/web/public/page_view.js +2 -1
- data/lib/samagotchi/web/public/peer_chip.js +60 -74
- data/lib/samagotchi/web/public/peer_data.js +13 -11
- data/lib/samagotchi/web/public/peer_links.js +12 -7
- data/lib/samagotchi/web/public/peer_mailbox_api.js +20 -0
- data/lib/samagotchi/web/public/peer_note.js +7 -3
- data/lib/samagotchi/web/public/peer_text.js +4 -4
- data/lib/samagotchi/web/public/quiet_notes.js +199 -0
- data/lib/samagotchi/web/public/revise_stack.js +4 -3
- data/lib/samagotchi/web/public/session_view.js +2 -2
- data/lib/samagotchi/web/public/stream_handlers.js +3 -2
- data/lib/samagotchi/web/public/turn_block.js +7 -3
- data/lib/samagotchi/web/public/turn_events.js +6 -0
- data/lib/samagotchi/web/push/attention.rb +3 -2
- data/lib/samagotchi/web/session_access_routes.rb +3 -20
- data/lib/samagotchi/worker/leave.rb +3 -0
- data/lib/samagotchi/worker/mail.rb +73 -0
- data/lib/samagotchi/worker/startup.rb +3 -0
- data/lib/samagotchi/worker/wake_turns.rb +20 -5
- data/lib/samagotchi/worker.rb +12 -6
- data/lib/samagotchi/worker_inbound/mail.rb +214 -0
- data/lib/samagotchi/worker_inbound.rb +43 -46
- data/lib/samagotchi/worker_wakes.rb +26 -21
- metadata +19 -2
- data/lib/samagotchi/peer_sources.rb +0 -58
data/docs/plugins.md
CHANGED
|
@@ -862,29 +862,33 @@ index = Samagotchi::Tools::ToolIndex
|
|
|
862
862
|
names itself (an mcp bundle before 0.7.0 has `find_mcp_tools` and
|
|
863
863
|
`mcp_call`) keeps them; with no source, `full` declares neither of chi's.
|
|
864
864
|
|
|
865
|
-
### `chi.
|
|
865
|
+
### `chi.peer(name)`
|
|
866
866
|
|
|
867
|
-
Declares a
|
|
868
|
-
`
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
sources](context.md#peer-sources-the-peer-loop)).
|
|
867
|
+
Declares a peer agent this bundle speaks for: the peer bundles' `claude` and
|
|
868
|
+
`codex`. Its messages in the session's mailbox (`chi peer say NAME`,
|
|
869
|
+
[peers.md](peers.md)) become its notes and may wake the session by the peer
|
|
870
|
+
loop's rules: up to `peer.turns` wake turns in a row, one closing wake
|
|
871
|
+
(outside that count) for a message whose verdict is `VERDICT OK`, and a wake
|
|
872
|
+
line that names the peer and keeps the turn within the user's task.
|
|
874
873
|
|
|
875
874
|
```ruby
|
|
876
|
-
chi.
|
|
875
|
+
chi.peer "codex"
|
|
877
876
|
```
|
|
878
877
|
|
|
879
|
-
- `name`: a
|
|
880
|
-
bundle's is a load error.
|
|
881
|
-
|
|
882
|
-
Codex"): a capital letter, then up to 23 letters and spaces.
|
|
878
|
+
- `name`: a lowercase letter, then lowercase letters and digits, up to 24.
|
|
879
|
+
Another bundle's is a load error. The peer's label is its name capitalised
|
|
880
|
+
("Codex").
|
|
883
881
|
|
|
884
|
-
The declaration lives in the session's process only, like a tool: a
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
882
|
+
The declaration lives in the session's process only, like a tool: a file in
|
|
883
|
+
the mailbox can't make its writer a peer, and uninstalling the bundle ends it
|
|
884
|
+
(a message from a name no loaded bundle declared is refused, and delivered
|
|
885
|
+
once one does). Subclasses of `Samagotchi::Plugin::Peer` (below) declare their
|
|
886
|
+
`PEER`. Needs the next chi (guard it with `chi.respond_to?(:peer)`).
|
|
887
|
+
|
|
888
|
+
`chi.peer_source(name, label:)` (the context-source peers of chi 0.67.0 to
|
|
889
|
+
0.187.0) is gone: it raises "chi.peer_source is gone: upgrade this bundle
|
|
890
|
+
(chi bundle install <name> --force)", so an older peer bundle fails to load
|
|
891
|
+
and chi starts without it.
|
|
888
892
|
|
|
889
893
|
### `chi.judgment(name, questions:, positive: nil, negative: nil)`
|
|
890
894
|
|
|
@@ -1567,7 +1571,7 @@ ctx.context.decline(url: "https://github.com/acme/app/pull/42") # => "pr-42"
|
|
|
1567
1571
|
ctx.context.propose(url: "https://github.com/acme/app/pull/42", title: "#42 Make the thing", mentions: ["#42", "feat/x"])
|
|
1568
1572
|
ctx.context.candidates # => [#<data Candidate name="pr-42", url="https://…", title="#42 Make the thing", …>]
|
|
1569
1573
|
ctx.context.withdraw("pr-42") # => true
|
|
1570
|
-
ctx.context.left_behind # => [#<data Left name="
|
|
1574
|
+
ctx.context.left_behind # => [#<data Left name="notes", hint="…", from="3f2a9c1e-…">]
|
|
1571
1575
|
```
|
|
1572
1576
|
|
|
1573
1577
|
[Attached context](context.md) for the session the plugin runs in: chi runs
|
|
@@ -1616,8 +1620,7 @@ gets a note when its text changes.
|
|
|
1616
1620
|
session left with the previous link ([Movable
|
|
1617
1621
|
context](context.md#movable-context)): `ContextSources::Left` values with
|
|
1618
1622
|
`name`, `hint` (the last pushed one, else the source's) and `from` (the
|
|
1619
|
-
previous link's id); `[]` for a session that isn't a continue's.
|
|
1620
|
-
bundles read it to ask their peer to pair again (below).
|
|
1623
|
+
previous link's id); `[]` for a session that isn't a continue's.
|
|
1621
1624
|
- The source is the session's (not the project's), marked
|
|
1622
1625
|
`added_by: plugin:<bundle>`. It is plugin code, so it isn't asked about as
|
|
1623
1626
|
the agent's `chi context add --cmd` is.
|
|
@@ -1634,6 +1637,23 @@ gets a note when its text changes.
|
|
|
1634
1637
|
The [github-pr bundle](bundles.md#the-github-pr-bundle) proposes the branch's PR from
|
|
1635
1638
|
a quiet `chi.init` task.
|
|
1636
1639
|
|
|
1640
|
+
## Peers: `ctx.peers`
|
|
1641
|
+
|
|
1642
|
+
```ruby
|
|
1643
|
+
ctx.peers.link("claude") # => #<data PeerLink peer="claude", address="/tmp/…sock", paired_at="…", from="…"> or nil
|
|
1644
|
+
ctx.peers.left_behind("claude") # the previous link's pairing, in a continue's new link; else nil
|
|
1645
|
+
ctx.peers.message("claude", 12) # => #<data PeerMessage serial=12, text="…", summary="…", wake=true, re="s-ab12cd", at="…"> or nil
|
|
1646
|
+
ctx.peers.last_message("claude") # the newest message still in the mailbox, or nil
|
|
1647
|
+
```
|
|
1648
|
+
|
|
1649
|
+
What a peer bundle reads of its peer's side of the session (the mailbox,
|
|
1650
|
+
[peers.md](peers.md)): the pairing (`address` nil: the peer answers only) and
|
|
1651
|
+
the peer's messages. Read only: the peer pairs and says through `chi peer`,
|
|
1652
|
+
and the worker takes the messages. A continue leaves the pairing with the
|
|
1653
|
+
previous link, so a new link's `link` is nil until the peer pairs again;
|
|
1654
|
+
`left_behind` is the one the previous link kept (`Plugin::Peer#tell_moved`
|
|
1655
|
+
tells the peer the new id there). Needs the next chi.
|
|
1656
|
+
|
|
1637
1657
|
### Context providers in the manifest
|
|
1638
1658
|
|
|
1639
1659
|
A bundle can turn URLs into sources for every process, without loading
|
|
@@ -1741,16 +1761,18 @@ that calls it, or for a real external bundle that does. No method on the chance
|
|
|
1741
1761
|
`Samagotchi::Plugin::Secrets::Busy` and `Samagotchi::Plugin::Secrets::Unavailable` (a bundle rescues them by name).
|
|
1742
1762
|
2. `Samagotchi::Plugin::Peer` as a base class. A subclass defines `post`,
|
|
1743
1763
|
`check_hint!`, `paired_lines`, `transport_line`, `peer_dir` and
|
|
1744
|
-
`setup_paragraph` (optionally `skill_substitutions`), and sets `NAME`,
|
|
1745
|
-
`APP`, `COMMAND`, `USAGE`, `
|
|
1746
|
-
read as `self.class::X`.
|
|
1764
|
+
`setup_paragraph` (optionally `skill_substitutions` and `skill_installed`), and sets `PEER`, `NAME`,
|
|
1765
|
+
`APP`, `COMMAND`, `TOOL`, `READ_TOOL`, `USAGE`, `LEGACY_INBOX`, `LEGACY_OUTBOX` and `SCRIPTS_DIRS`. These
|
|
1766
|
+
constants are read as `self.class::X`. It declares the peer (`chi.peer PEER`), the send tool and
|
|
1767
|
+
`<peer>_read` (a long message by its number, paged), and sends to the pairing's address
|
|
1768
|
+
(`ctx.peers.link`). The base names each send: `Peer.send_id(kind, title, text, salt)` (`s-` and 6 hex
|
|
1747
1769
|
of SHA-256 over the args as given and the send's salt: the tool run's `ctx.tool_id`, a random one for a
|
|
1748
1770
|
`/<peer>` command's, so each send has its own id; a nil salt gives an older chi's id, over the args alone) is the
|
|
1749
1771
|
message's second line (`ref: <id>`), the tool row's `peer` ref (display only, no actions; computed from the args
|
|
1750
1772
|
and the run's id before the call runs, a two-arg `refs:`, so a send that then fails has it too) and the last
|
|
1751
|
-
send's `id`; the peer's answer
|
|
1752
|
-
Successful sends and transport failures are recorded in the session's peer exchange log;
|
|
1753
|
-
|
|
1773
|
+
send's `id`; the peer's answer names it (`chi peer say --re`).
|
|
1774
|
+
Successful sends and transport failures are recorded in the session's peer exchange log; the answers are the
|
|
1775
|
+
mailbox's messages. The log does not enter the model's context.
|
|
1754
1776
|
See the [claude-peer](bundles.md#the-claude-peer-bundle) and
|
|
1755
1777
|
[codex-peer](bundles.md#the-codex-peer-bundle) bundles.
|
|
1756
1778
|
3. `Samagotchi::Tools::ToolIndex::Tool` and `Samagotchi::Tools::ToolIndex::Group`
|
|
@@ -1838,6 +1860,9 @@ bundle.set(usage: { tool_calls: 40, active_ms: 600_000 }) # ctx.usage: { turns:,
|
|
|
1838
1860
|
bundle.set(turn_author: "p:p_0123abcd") # a participant's turn: ctx.turn_author, and author: on every event
|
|
1839
1861
|
bundle.set(session_settings: { "cap" => 1 }) # the session's --set values (Bundle.load takes session_settings: too)
|
|
1840
1862
|
bundle.tool_loads.last.names # ctx.load_tools calls; set(load_tools_staged: [...]) limits what they stage
|
|
1863
|
+
bundle.pair_peer("claude", address: "/tmp/c.sock") # a peer's side, as chi peer pair writes it (ctx.peers.link); address: nil answers only
|
|
1864
|
+
bundle.peer_says("claude", "VERDICT OK", summary: "s") # a message in the mailbox, as chi peer say writes it (ctx.peers.message)
|
|
1865
|
+
bundle.unpair_peer("claude") # chi peer unpair; bundle.peer_registry.names: the chi.peer declarations
|
|
1841
1866
|
bundle.shutdown
|
|
1842
1867
|
```
|
|
1843
1868
|
|
|
@@ -1913,7 +1938,7 @@ docs/testing.md). **Minitest:** `require "samagotchi/testing/minitest"` and subc
|
|
|
1913
1938
|
checked: a bundle whose `requires_chi` this chi doesn't meet raises `InstallError` unless `force: true`)
|
|
1914
1939
|
and loads the installed copy with chi's own loaders. It returns `warnings` (the Installer's),
|
|
1915
1940
|
`plugin_failures` / `hook_failures` (each with the `location` in your source, `plugin.rb:12`) and `registered`
|
|
1916
|
-
(commands, tools, hooks per event, inits, toolkits, tool and
|
|
1941
|
+
(commands, tools, hooks per event, inits, toolkits, tool sources and peers). A name chi ships raises
|
|
1917
1942
|
`MemoryBundle::Installer::InstallError` unless `force: true`.
|
|
1918
1943
|
- **From the command line:** `chi bundle test [PATH]` runs a bundle's `test/**/*_test.rb` (or `spec/`) on the
|
|
1919
1944
|
Ruby and lib chi runs on, and `chi bundle check [PATH] [--fix]` runs `Install` (and the manifest, sha and
|
data/docs/sessions.md
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/sessions/<uuid>.json` (XDG-aware via `XDG_STATE_HOME`) plus a sidecar dir `<uuid>/` with `input/`/`notes/`/`output/`/`owner.lock`/`bridge.json` (`Session.session_dir`), `turn_drawings.jsonl` once a turn ended with a Bridge or in a one-shot run (each finished turn as live drew it, which the web's reload draws: [bridge.md](internals/bridge.md#turndrawings); a fork starts with its parent's lines for the turns its seed keeps unchanged, a continue with none: its turns, and any without a line, are drawn from their messages), and `tool_output/` once a long `execute` result was cut: its whole output, which the cut result names (`ToolOutputFiles`, the newest 50 kept; see [Tool output guardrails](internals/tool-output-limits.md#the-runners-cut-max_tool_output_chars)). Its keys are in [the Session file table](#session-file). A file from before `used_memory_names`, `preloaded_memory_names`, `muted_memory_names`, `parent_id` or `continues` reads those as empty lists, no parent and no previous link.
|
|
4
4
|
|
|
5
|
-
The sidecar's `peer_exchanges.jsonl` records peer sends
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
The sidecar's `peer_exchanges.jsonl` records peer sends and transport
|
|
6
|
+
failures, never their text, and `peer_receipts.json` what the worker did with
|
|
7
|
+
each peer message (its worker writes it alone); the messages themselves are in
|
|
8
|
+
the mailbox, `$XDG_STATE_HOME/samagotchi/mailbox/<uuid>/<peer>/`, apart from
|
|
9
|
+
the sessions folder. All three stay with the previous link on a continue (its
|
|
10
|
+
unread messages reach the new link as one note); a delete removes them. See
|
|
11
|
+
[peers.md](peers.md).
|
|
8
12
|
|
|
9
13
|
**Message times:** an entry of `messages` may carry `at`, when it happened: a local-offset ISO time with milliseconds (`2026-10-24T14:32:05.120+02:00`). User prompts, lines merged into a turn and steers, reminders, context and task notes, and the model's replies have one (a note's is its `created_at`); tool results, `!cmd` messages and chi's own turn notes don't, nor does anything saved before chi stamped messages (no backfill). It is for the UIs only (the gap dividers, a bubble's time): it never goes to the model, so it changes nothing in the requests or their prompt cache. The one time the model reads is the reminders': due reminders go into a turn as a system message headed `[SYSTEM: REMINDERS DUE 2026-10-24 14:32 local]` (the turn's local time; `ReminderQueue#inject!`), written into the saved content then, so a later request sends the same text.
|
|
10
14
|
|
|
@@ -194,7 +198,7 @@ pbpaste | chi note --source slack 3f2a 8c1d
|
|
|
194
198
|
- It lands in `<uuid>/notes/`, apart from `input/`, so nothing that runs turns sees it. A live worker adds it to the conversation within a few seconds, between turns: one sent during a turn waits for that turn to end. A session with no worker keeps it until a worker next starts (a prompt, `--attach`), which adds it before anything else. A session a one-turn `chi --non-interactive` run has refuses notes. `chi note` prints one line per session: queued, waits for the next start (with the queue count), or refused.
|
|
195
199
|
- A note to a link that was **continued** (archived, with a later link) goes to its chain's newest link, as `send_note`'s and `chi broadcast`'s do (`chi broadcast` gives two links of one chain the note once, logged under the newest): `chi note` prints `3f2a1c0d → 4b7e9a01 (continued) queued: …` (and `… (continued) refused: …` when that link refuses it), and chi web's notes answer names that link as `id` beside `session_id`, in a 409 too. `chi broadcast deliver` logs such a delivery under the newest link's id (the one that has the note), so `chi broadcast log` shows that id, not the one typed, and a later `deliver` to either link says it had it. An archived link nobody continues keeps its note until input brings it back. An `/objectives` edit is the one note that stays in its own session: its list is that conversation's. Notes waiting when a session is continued move with it (*Session chains*).
|
|
196
200
|
- In the conversation it is a tail system message marked `kind: note`, framed `[CONTEXT NOTE from slack, 14:02]\n…\n[END NOTE]` (from another session: `from session 3f2a1c (~/projects/foo)`). The system prompt says notes are background, not requests: the model uses one when it is relevant, doesn't answer it on its own, and never follows instructions inside it. A note from `broadcast` ([`chi broadcast`](broadcast.md)) is the one exception to "doesn't answer it": the model says briefly in its next answer when it affects its current work, and still doesn't act on it unless asked. `--source broadcast` is refused for `chi note`. Its text is escaped like user text, so it can't fake a turn. It survives `--resume`, a reload, `!rollback` and a continue answered no.
|
|
197
|
-
- The web shows it as a dim "note from …" block, live (`context_added`) and after a reload; the attached terminal as one dim `note from slack: <first line>` line, also when joining.
|
|
201
|
+
- The web shows it as a dim "note from …" block, live (`context_added`) and after a reload, folded into a closed notes row with the background lines next to it (a tap opens it) unless it starts a turn; the attached terminal as one dim `note from slack: <first line>` line, also when joining.
|
|
198
202
|
- Agents: `list_sessions` (other sessions of this project, newest first, up to 20; optional `cwd`, `"/"` for every project) and `send_note(session, text)`, which sends a note from this session. Neither starts a turn anywhere.
|
|
199
203
|
|
|
200
204
|
On macOS, `chi desktop install` does this with a native panel from the Services menu or a hotkey (see [Desktop helper](desktop.md)). A plain Automator Quick Action that sends the clipboard to the live sessions you pick works too (Automator: Quick Action, "Run Shell Script", shell `/bin/zsh`; Automator's PATH is minimal, so put your Ruby's bin dir on it and use the full path to `chi`):
|
data/docs/sub-agent.md
CHANGED
|
@@ -26,15 +26,15 @@ The other direction, chi sending a part of its work to a Claude Code session
|
|
|
26
26
|
you already work with (to validate, as context, or with a question), is the
|
|
27
27
|
[claude-peer bundle](bundles.md#the-claude-peer-bundle): Claude pairs with the
|
|
28
28
|
chi session, chi's `claude_send` tool or `/claude` writes to Claude's inbox,
|
|
29
|
-
and Claude's answer comes back
|
|
30
|
-
|
|
31
|
-
chi
|
|
29
|
+
and Claude's answer comes back with `chi peer say` as a message in the
|
|
30
|
+
session's mailbox, its whole text in a note of chi's conversation, and the
|
|
31
|
+
say prints what chi did with it (Claude can also tell chi something unasked,
|
|
32
|
+
which wakes chi under the same count). The
|
|
32
33
|
[codex-peer bundle](bundles.md#the-codex-peer-bundle) does the same with a
|
|
33
34
|
Codex CLI session (`codex_send`, `/codex`, through `codex queue`). The peer's
|
|
34
35
|
answers wake chi in a short loop (fix or disagree, send again) until it says
|
|
35
36
|
`VERDICT OK` (one closing wake: chi carries on or tells you what was agreed)
|
|
36
|
-
or after `
|
|
37
|
-
sources](context.md#peer-sources-the-peer-loop).
|
|
37
|
+
or after `peer.turns` turns: [peers.md](peers.md).
|
|
38
38
|
|
|
39
39
|
A client with no chi of its own (an iOS Shortcut, a script) can do the same
|
|
40
40
|
over HTTP: one `POST …/ask` to chi web, then a wait token until the answer
|
data/lib/samagotchi/bridge.rb
CHANGED
|
@@ -44,6 +44,7 @@ require_relative "working_set"
|
|
|
44
44
|
require_relative "relay_verifier"
|
|
45
45
|
require_relative "relay_watcher"
|
|
46
46
|
require_relative "reply_wait"
|
|
47
|
+
require_relative "peer_mailbox"
|
|
47
48
|
require_relative "task_transcript"
|
|
48
49
|
require_relative "tools/task_runtime"
|
|
49
50
|
|
|
@@ -796,8 +797,7 @@ module Samagotchi
|
|
|
796
797
|
# participant_revise: a participant's Revise draft is kept, and the
|
|
797
798
|
# Engine checks it at the stamp (ParticipantRevise): what chi web needs
|
|
798
799
|
# to pass one on (ReviseAnchor::PARTICIPANT_FEATURE).
|
|
799
|
-
# activity: GET /activity answers with Worker#activity_snapshot
|
|
800
|
-
# `chi schedule tick` can ask a live worker what it is busy with.
|
|
800
|
+
# activity: GET /activity answers with Worker#activity_snapshot (chi schedule tick asks a live worker's).
|
|
801
801
|
# participant_client_id: it reads a participant's client id as
|
|
802
802
|
# participant:<id>; chi web sends a worker without it review:<id>
|
|
803
803
|
# (Delivery::PARTICIPANT_ID_FEATURE).
|
|
@@ -810,7 +810,7 @@ module Samagotchi
|
|
|
810
810
|
WorkerLink::ACTIVITY_FEATURE, ObjectivesTrack::FEATURE, Delivery::OWN_TURN_STEER_FEATURE,
|
|
811
811
|
Delivery::CANCEL_TURN_ID_FEATURE, ReviseAnchor::PARTICIPANT_FEATURE, Delivery::PARTICIPANT_ID_FEATURE,
|
|
812
812
|
WorkingSet::ITEM_FEATURE, BlockFix::FEATURE, Delivery::AGENT_FEATURE,
|
|
813
|
-
Delivery::ASK_FEATURE, ReplyFor::FEATURE].freeze
|
|
813
|
+
Delivery::ASK_FEATURE, ReplyFor::FEATURE, PeerMailbox::FEATURE].freeze
|
|
814
814
|
|
|
815
815
|
# The routes, by method and what follows /session/:id/: a handler takes
|
|
816
816
|
# the session id and the request body and returns [headers, status, body].
|
|
@@ -24,7 +24,8 @@ module Samagotchi
|
|
|
24
24
|
# Resolved on use: Sessions alone loads ~150 files.
|
|
25
25
|
MEMBERS = {
|
|
26
26
|
"Plugin::Api" => { ctx: "Plugin::Context" },
|
|
27
|
-
"Plugin::Context" => { sessions: "Plugin::Sessions", context: "Plugin::AttachedContext",
|
|
27
|
+
"Plugin::Context" => { sessions: "Plugin::Sessions", context: "Plugin::AttachedContext", peers: "Plugin::Peers",
|
|
28
|
+
http: "Plugin::Http",
|
|
28
29
|
judgments: "Plugin::Judgments", cost: "SessionMetrics::Cost", usage: "SessionMetrics::Usage",
|
|
29
30
|
log: "Plugin::Context::Logger", secrets: "Plugin::Secrets" }
|
|
30
31
|
}.freeze
|
|
@@ -464,7 +464,7 @@ module Samagotchi
|
|
|
464
464
|
end
|
|
465
465
|
end
|
|
466
466
|
{ "init" => registered.inits, "toolkit" => registered.toolkits, "tool source" => registered.tool_sources,
|
|
467
|
-
"peer
|
|
467
|
+
"peer" => registered.peers, "prompt section" => registered.prompt_sections }.each do |what, names|
|
|
468
468
|
names.each { |name| add(:info, :registered, plugin, "#{what} #{name}") }
|
|
469
469
|
end
|
|
470
470
|
end
|
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: claude-peer
|
|
3
|
-
version: 0.
|
|
3
|
+
version: 0.7.0
|
|
4
4
|
scope: system
|
|
5
|
-
description: "Pair this session with a Claude Code session you work with: the claude_send tool and /claude send it a part of the work (a plan step, a diff, a finding) to validate or as context, and Claude's answer comes back as a
|
|
5
|
+
description: "Pair this session with a Claude Code session you work with: the claude_send tool and /claude send it a part of the work (a plan step, a diff, a finding) to validate or as context, and Claude's answer comes back as a message with its text (chi peer say); /claude install-skill installs Claude's chi-peer skill, which pairs"
|
|
6
6
|
trust_level: reviewed
|
|
7
7
|
files:
|
|
8
8
|
skill_claude_peer.md:
|
|
9
|
-
sha256: sha256:
|
|
10
|
-
description: "Send a part of the work to the paired Claude Code session (claude_send): only when the user asks, or to reply to its answer in a peer turn; validate, context or question; Claude's answer comes as a
|
|
9
|
+
sha256: sha256:d376b42d3a6ece86e53bc58afef8fd5dc0bfbaf06d0e988faed304b05ca72b45
|
|
10
|
+
description: "Send a part of the work to the paired Claude Code session (claude_send): only when the user asks, or to reply to its answer in a peer turn; validate, context or question; Claude's answer comes as a message with its text"
|
|
11
11
|
plugin:
|
|
12
12
|
file: plugin.rb
|
|
13
|
-
sha256: sha256:
|
|
13
|
+
sha256: sha256:a7fa566ff03f6e63d2889196539acbc2fa0c3615aa3a75c1282c91d062bc5e6f
|
|
14
14
|
scripts:
|
|
15
15
|
pair-remote: sha256:d7681f87a194e540b629564f84cad9f2d0a763197502c74614276ef88a8920cc
|
|
16
|
-
pair: sha256:
|
|
17
|
-
chi-peer-SKILL.md: sha256:
|
|
18
|
-
# The plugin needs Samagotchi::Plugin::Peer
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
# ignores the unknown key, and sends no `ref:` line for the skill to echo.
|
|
23
|
-
requires_chi: ">= 0.185.0"
|
|
24
|
-
# The next chi: the installed skill's __CHI_PEER_PAIR_REMOTE__ placeholder
|
|
25
|
-
# (scripts/pair-remote's path), which only its Plugin::Peer
|
|
26
|
-
# #skill_target_and_text fills; an older chi would install the skill with it
|
|
27
|
-
# left in. Also the memory and the tool's words say a peer's note holds its
|
|
28
|
-
# text (chi's ContextAbsorber peer block), which the next chi adds.
|
|
16
|
+
pair: sha256:98cddde54801f49b123cd0269f9ddc834b2566fde4ad241c07a50f3b794fedd0
|
|
17
|
+
chi-peer-SKILL.md: sha256:90132948e1198c450bd6fd3fcadbfad410c429b0d55ef4d7aede21a9f0e47b2f
|
|
18
|
+
# The plugin needs Samagotchi::Plugin::Peer on the mailbox: chi.peer and
|
|
19
|
+
# ctx.peers, and the skill's chi peer pair|say, are the next chi's (an older
|
|
20
|
+
# chi has no chi.peer: the plugin fails to load there).
|
|
21
|
+
requires_chi: ">= 0.188.0"
|
|
@@ -7,10 +7,11 @@ require "samagotchi/plugin/peer"
|
|
|
7
7
|
|
|
8
8
|
# claude-peer (docs/bundles.md, The claude-peer bundle): a live link between
|
|
9
9
|
# this chi session and a Claude Code session the user works with. Claude
|
|
10
|
-
# pairs (its chi-peer skill, scripts/pair
|
|
11
|
-
#
|
|
12
|
-
# (CLAUDE_CODE_MESSAGING_SOCKET)
|
|
13
|
-
#
|
|
10
|
+
# pairs (its chi-peer skill, scripts/pair: `chi peer pair claude <id>
|
|
11
|
+
# --address <socket>`), the pairing's address being its per-session inbox
|
|
12
|
+
# socket (CLAUDE_CODE_MESSAGING_SOCKET); its answers come back as messages
|
|
13
|
+
# in the session's mailbox (`chi peer say claude <id>`), each a note that may
|
|
14
|
+
# wake chi (docs/peers.md).
|
|
14
15
|
#
|
|
15
16
|
# The claude_send tool sends a part of the work (a plan step, a diff, a
|
|
16
17
|
# finding) to that socket as one JSON line, the format Claude Code's inbox
|
|
@@ -30,7 +31,7 @@ require "samagotchi/plugin/peer"
|
|
|
30
31
|
# /claude (anytime: it only reads files, writes one and posts to a socket)
|
|
31
32
|
# lets the user send without the model: `/claude` alone is a status card
|
|
32
33
|
# (paired or not, the socket and whether it is there, the last send, the
|
|
33
|
-
# last
|
|
34
|
+
# last message from Claude); `/claude validate|context <text>` sends the
|
|
34
35
|
# text as it is, titled by its first line; `/claude last` sends the model's
|
|
35
36
|
# last completed answer as context (mid-turn, a worker's ctx.messages holds
|
|
36
37
|
# the running turn's partial text, so the before_turn and after_turn hooks
|
|
@@ -50,13 +51,18 @@ require "samagotchi/plugin/peer"
|
|
|
50
51
|
# is Samagotchi::Plugin::Peer; this class has Claude's strings and the
|
|
51
52
|
# socket transport.
|
|
52
53
|
class Plugin < Samagotchi::Plugin::Peer
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
PEER = "claude"
|
|
55
|
+
# The context sources an older claude-peer paired through: only the
|
|
56
|
+
# status card's "paired the old way" line reads them. Remove after the
|
|
57
|
+
# next release.
|
|
58
|
+
LEGACY_INBOX = "claude-inbox"
|
|
59
|
+
LEGACY_OUTBOX = "claude-outbox"
|
|
55
60
|
BUNDLE = "claude-peer"
|
|
56
61
|
NAME = "Claude"
|
|
57
62
|
APP = "Claude Code"
|
|
58
63
|
COMMAND = "/claude"
|
|
59
64
|
TOOL = "claude_send"
|
|
65
|
+
READ_TOOL = "claude_read"
|
|
60
66
|
# The socket must take the line within this long.
|
|
61
67
|
WRITE_SECONDS = 5
|
|
62
68
|
# The Claude Code version the wire format was checked on.
|
|
@@ -71,13 +77,13 @@ class Plugin < Samagotchi::Plugin::Peer
|
|
|
71
77
|
SCRIPTS_DIRS = [File.join(__dir__, "scripts"), File.expand_path("../scripts", __dir__)].freeze
|
|
72
78
|
|
|
73
79
|
TOOL_DESCRIPTION = "Send a part of this session's work (a plan step, a diff, a finding, your " \
|
|
74
|
-
"last answer) to the Claude Code session paired with it
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
80
|
+
"last answer) to the Claude Code session paired with it, for Claude to " \
|
|
81
|
+
"validate, to take as context, or to answer a question about. Only when the " \
|
|
82
|
+
"user asks for it, or to reply to its answer in a peer turn. Needs a paired " \
|
|
83
|
+
"Claude Code session: without one it fails, and the user pairs from Claude. " \
|
|
84
|
+
"Claude's answer comes back later as a message from your peer agent Claude, " \
|
|
85
|
+
"with its text (a validate's wakes you): don't wait or poll. Never send " \
|
|
86
|
+
"secrets or the whole conversation."
|
|
81
87
|
TOOL_PARAMS = {
|
|
82
88
|
kind: { type: "string", enum: KINDS, required: true,
|
|
83
89
|
description: "validate: check this part and answer with a verdict; context: for Claude to know, no " \
|
|
@@ -94,9 +100,9 @@ class Plugin < Samagotchi::Plugin::Peer
|
|
|
94
100
|
|
|
95
101
|
private
|
|
96
102
|
|
|
97
|
-
# The paired Claude's inbox socket: the
|
|
103
|
+
# The paired Claude's inbox socket: the pairing's address.
|
|
98
104
|
def check_hint!(hint)
|
|
99
|
-
raise SendError, "
|
|
105
|
+
raise SendError, "the pairing's address isn't a socket path (#{hint}): pair again from Claude" unless hint.start_with?("/")
|
|
100
106
|
end
|
|
101
107
|
|
|
102
108
|
def paired_lines(socket)
|
|
@@ -8,9 +8,10 @@ description: Pair this Claude Code session with a running chi (Samagotchi) sessi
|
|
|
8
8
|
A live, two-way link between this Claude session and one chi session. chi
|
|
9
9
|
sends a selected part of its work (a plan step, a diff, a finding) and asks for
|
|
10
10
|
a **validate**, hands over **context**, or asks a **question**; Claude answers
|
|
11
|
-
into chi
|
|
12
|
-
web shows everything chi does, and
|
|
13
|
-
decides whether incoming messages
|
|
11
|
+
into chi with `chi peer say`, and chi says what it did with each message. The
|
|
12
|
+
user stays in the loop on both sides: chi's web shows everything chi does, and
|
|
13
|
+
Claude Code's `crossSessionInbound` setting decides whether incoming messages
|
|
14
|
+
need approval here.
|
|
14
15
|
|
|
15
16
|
The reviewer is this session, with the context it already has: not a fresh
|
|
16
17
|
headless review run.
|
|
@@ -27,11 +28,10 @@ prefix works; the URL works too). Run:
|
|
|
27
28
|
sh "__CHI_PEER_PAIR__" <chi session id or URL>
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
It
|
|
31
|
-
`$CLAUDE_CODE_MESSAGING_SOCKET`, as
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
then.
|
|
31
|
+
It pairs this session with the chi session (`chi peer pair claude <id>`, with
|
|
32
|
+
this session's inbox socket, `$CLAUDE_CODE_MESSAGING_SOCKET`, as the address
|
|
33
|
+
chi sends to). Running it again only refreshes the socket. The socket changes
|
|
34
|
+
when this Claude session restarts: pair again then.
|
|
35
35
|
|
|
36
36
|
Tell the user it's paired, and that in chi they can say "send this to Claude
|
|
37
37
|
for validation" or "give Claude this as context", or type
|
|
@@ -73,32 +73,36 @@ Tell the user in one line what came in and what you answered.
|
|
|
73
73
|
|
|
74
74
|
## Reply into chi
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
summary, and `wake` starts a chi turn only when chi is waiting on it:
|
|
76
|
+
Say the answer with `chi peer say`, one message per answer:
|
|
78
77
|
|
|
79
78
|
```sh
|
|
80
|
-
|
|
81
|
-
"validate <title>: VERDICT CHANGES, 2 issues" wake s-ab12cd <<'EOF' | chi context push claude-outbox <id>
|
|
79
|
+
chi peer say claude <id> --wake --re s-ab12cd --summary "validate <title>: VERDICT CHANGES, 2 issues" --wait 8 <<'EOF'
|
|
82
80
|
<the full answer>
|
|
83
81
|
EOF
|
|
84
82
|
```
|
|
85
83
|
|
|
86
|
-
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
-
|
|
91
|
-
|
|
84
|
+
- Always give `--wake` or `--nowake`: `--wake` for a validate or a question
|
|
85
|
+
(chi asked and is waiting), and for a message you start yourself that chi
|
|
86
|
+
should act on or know now (below); `--nowake` for a reply to context and for
|
|
87
|
+
background chi can pick up at its next turn.
|
|
88
|
+
- `--re` is the `ref:` value of the message you answer (`s-ab12cd` above), so
|
|
89
|
+
chi ties the answer to its send; leave it out when the message had no
|
|
92
90
|
`ref:` line, and for a message you start.
|
|
93
|
-
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
- Start the summary with the title you are answering, and end it with your
|
|
92
|
+
verdict (`VERDICT OK`, `VERDICT CHANGES` or `VERDICT UNSURE`): an OK wakes
|
|
93
|
+
chi once to close the round.
|
|
94
|
+
- chi keeps each message as its own note with its text (up to its tool output
|
|
95
|
+
cap, 10,000 characters by default, for a message that wakes it; up to 2,000
|
|
96
|
+
for one that doesn't; a longer one it reads on demand), so don't repeat
|
|
97
|
+
points from an earlier answer.
|
|
98
|
+
- **It prints one line: quote it to your user.** `#12 received · woke chi`,
|
|
99
|
+
or `#12 received · held: 3 peer turns in a row (peer.turns) · waits for the
|
|
100
|
+
user's next message`, or why chi can't say yet (`chi is in a turn: it reads
|
|
101
|
+
this when the turn ends`). If it says **held**, don't send again, and don't
|
|
102
|
+
use `chi send` to get past it: the user decides when chi goes on.
|
|
103
|
+
- A say that is **refused** (exit 1) says why: not paired (pair again), the
|
|
104
|
+
session was continued (below), chi's worker is older (the user restarts the
|
|
105
|
+
session).
|
|
102
106
|
- Never answer a chi message with `chi send`: it goes in as an agent's
|
|
103
107
|
message (yours, not the user's) and counts toward the session's wake
|
|
104
108
|
budget (`session.max_wakes`), outside the round's limit. Use it only when
|
|
@@ -108,13 +112,13 @@ EOF
|
|
|
108
112
|
|
|
109
113
|
When something here changes what chi is doing (you changed code or a plan it
|
|
110
114
|
depends on, the user took a decision with you that chi should follow), tell
|
|
111
|
-
chi without waiting to be asked: the same
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
user. A waking message counts toward the same limit as answers
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
chi without waiting to be asked: the same say, with no `--re`, and `--wake`
|
|
116
|
+
when chi should react now, `--nowake` when it is only background. Start the
|
|
117
|
+
summary with what it is about (`sync: <what>`). chi reads it as a message you
|
|
118
|
+
sent unasked, takes it into account within its user's task and tells its
|
|
119
|
+
user. A waking message counts toward the same limit as answers (`peer.turns`,
|
|
120
|
+
3 in a row without the user typing); past it the message waits in chi as a
|
|
121
|
+
note, and the line says so. Don't send one only to acknowledge.
|
|
118
122
|
|
|
119
123
|
## chi continued the session
|
|
120
124
|
|
|
@@ -127,8 +131,10 @@ with the old id, so pair again:
|
|
|
127
131
|
id gets its own socket and forward). From then on answer only
|
|
128
132
|
the new id; an answer you are still writing goes there too. Don't reply to
|
|
129
133
|
the message itself.
|
|
130
|
-
- **A
|
|
131
|
-
the new id the same way, then
|
|
134
|
+
- **A say refused** with `this session was continued as <new id>`: pair
|
|
135
|
+
again with the new id the same way, then say the answer again, to the new
|
|
136
|
+
id. Messages chi hadn't read yet reach the new session as one note: don't
|
|
137
|
+
send them again.
|
|
132
138
|
|
|
133
139
|
## chi on another machine over SSH
|
|
134
140
|
|
|
@@ -161,8 +167,9 @@ SSH user, in the same `/tmp`, not inside a separate container): if `/claude`
|
|
|
161
167
|
in chi shows the socket **missing** while the forward runs, that is why (or
|
|
162
168
|
the host and the remote name point at different machines).
|
|
163
169
|
|
|
164
|
-
Replies are the same
|
|
165
|
-
`CHI_REMOTE=<name> chi
|
|
170
|
+
Replies are the same say, through the remote:
|
|
171
|
+
`CHI_REMOTE=<name> chi peer say claude <id> …` (chi there waits for the
|
|
172
|
+
`--wait` and prints the line).
|
|
166
173
|
|
|
167
174
|
A path in a chi message — a `payload: <path>` file, a file or a diff to check —
|
|
168
175
|
is on `<host>`, not here: read it with `ssh <host> cat <path>` (or the repo
|
|
@@ -192,4 +199,6 @@ tell the user.
|
|
|
192
199
|
read those without being asked each time, the user can allow
|
|
193
200
|
`Read(__CHI_PEER_PAYLOADS__/**)` in Claude Code's permissions (their call).
|
|
194
201
|
- Auto mode refuses posting to this session's own socket, so test from chi.
|
|
195
|
-
- Unpair: `chi
|
|
202
|
+
- Unpair: `chi peer unpair claude <id>` (your messages stay; chi still reads
|
|
203
|
+
those it hasn't).
|
|
204
|
+
- `chi peer ls <id>` lists your messages and what chi did with each.
|