samagotchi 0.193.0 → 0.195.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +116 -1
- data/docs/bundle-authoring.md +2 -2
- data/docs/bundles.md +223 -12
- data/docs/cli.md +27 -11
- data/docs/configuration.md +93 -6
- data/docs/desktop.md +3 -0
- data/docs/guardrails.md +11 -1
- data/docs/hooks.md +1 -0
- data/docs/internals/attached-context.md +2 -0
- data/docs/internals/bridge.md +4 -0
- data/docs/internals/engine.md +59 -4
- data/docs/internals/knowledge.md +205 -0
- data/docs/internals/pages.md +17 -9
- data/docs/internals/panes.md +104 -0
- data/docs/internals/peers.md +102 -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/memory.md +4 -2
- data/docs/pages.md +72 -1
- data/docs/peers.md +90 -5
- data/docs/plugins.md +100 -6
- data/docs/releasing.md +1 -1
- data/docs/scheduling.md +4 -0
- data/docs/sessions.md +23 -7
- data/docs/sub-agent.md +6 -4
- data/docs/system-one.md +4 -0
- data/docs/testing.md +5 -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 +11 -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 +11 -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/coordinator/manifest.yml +7 -4
- data/lib/samagotchi/bundles/coordinator/plugin.rb +15 -5
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +10 -0
- data/lib/samagotchi/bundles/dev/manifest.yml +3 -2
- data/lib/samagotchi/bundles/knowledge/adapters.rb +205 -0
- data/lib/samagotchi/bundles/knowledge/catalog.rb +151 -0
- data/lib/samagotchi/bundles/knowledge/chi_adapters.rb +160 -0
- data/lib/samagotchi/bundles/knowledge/chunker.rb +55 -0
- data/lib/samagotchi/bundles/knowledge/github.rb +246 -0
- data/lib/samagotchi/bundles/knowledge/manifest.yml +25 -0
- data/lib/samagotchi/bundles/knowledge/plugin.rb +788 -0
- data/lib/samagotchi/bundles/knowledge/query.rb +30 -0
- data/lib/samagotchi/bundles/knowledge/query_log.rb +55 -0
- data/lib/samagotchi/bundles/knowledge/refresh.rb +133 -0
- data/lib/samagotchi/bundles/knowledge/store.rb +264 -0
- data/lib/samagotchi/bundles/reflect/manifest.yml +17 -0
- data/lib/samagotchi/bundles/reflect/scripts/reflect.rb +439 -0
- data/lib/samagotchi/bundles/reflect/skill_reflect.md +100 -0
- 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/guardrails/review_paths.rb +13 -3
- data/lib/samagotchi/guardrails_command.rb +3 -9
- data/lib/samagotchi/hook_label.rb +19 -0
- data/lib/samagotchi/hook_routes.rb +3 -2
- 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/page_command.rb +90 -6
- data/lib/samagotchi/pages/launch.rb +16 -8
- data/lib/samagotchi/pages/runner.rb +7 -2
- data/lib/samagotchi/pages/runtime.rb +62 -2
- data/lib/samagotchi/pages.rb +4 -0
- data/lib/samagotchi/panes/kitty.rb +137 -0
- data/lib/samagotchi/panes.rb +254 -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 +18 -1
- data/lib/samagotchi/plugin/attached_context.rb +46 -1
- data/lib/samagotchi/plugin/card.rb +68 -11
- data/lib/samagotchi/plugin/context.rb +42 -6
- data/lib/samagotchi/plugin/panes.rb +97 -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 +326 -0
- data/lib/samagotchi/plugin/peer_start_hook.rb +207 -0
- data/lib/samagotchi/plugin/peers.rb +76 -3
- data/lib/samagotchi/plugin/project.rb +63 -0
- data/lib/samagotchi/plugin/sessions.rb +36 -1
- data/lib/samagotchi/plugin/tool_spec.rb +16 -7
- 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.rb +22 -9
- 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_stats.rb +436 -0
- data/lib/samagotchi/session_stores.rb +9 -0
- data/lib/samagotchi/session_window.rb +30 -0
- data/lib/samagotchi/sessions_command.rb +16 -3
- data/lib/samagotchi/system_one/approval_choice.rb +22 -0
- data/lib/samagotchi/system_one/approval_label.rb +4 -6
- data/lib/samagotchi/system_one/http_backend.rb +111 -10
- data/lib/samagotchi/system_prompt.rb +14 -5
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +30 -0
- 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/boundary.rb +17 -4
- data/lib/samagotchi/testing/bundle.rb +6 -2
- data/lib/samagotchi/testing/sessions.rb +11 -3
- data/lib/samagotchi/toolkit.rb +11 -4
- data/lib/samagotchi/toolkit_report_command.rb +14 -18
- data/lib/samagotchi/toolkit_suggest.rb +9 -2
- data/lib/samagotchi/tools/registry.rb +43 -18
- data/lib/samagotchi/tools/tool_index.rb +6 -2
- data/lib/samagotchi/turn_endings.rb +6 -2
- data/lib/samagotchi/turn_excerpts.rb +298 -0
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +9 -0
- 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 +39 -1
data/docs/plugins.md
CHANGED
|
@@ -302,11 +302,33 @@ run by `call_tool` as the tool itself ([the chi group](#chitool_sourcecall-acts_
|
|
|
302
302
|
each key optional, says what a call acts on, for [guardrails](#guardrails).
|
|
303
303
|
- `refs`: `->(args) { [{ kind:, target:, label:, actions: [] }, …] }`, what the call's row traces to in the web
|
|
304
304
|
(display only, the model never sees them). See [Refs on a tool's row](#refs-on-a-tools-row).
|
|
305
|
+
- `declare`: `:always` or `:kit`, which toolkits declare it (below); omitted, a kit's list decides, as for a built-in.
|
|
305
306
|
|
|
306
307
|
The block returns the result text. If it starts with `Error:`, it counts as
|
|
307
308
|
a failure. If it raises, the model gets `Error: <message>`. To return images
|
|
308
309
|
too, see [Returning images](#returning-images).
|
|
309
310
|
|
|
311
|
+
#### `declare:`: which kits declare it
|
|
312
|
+
|
|
313
|
+
- **`declare: :always`**: every toolkit declares it (`lean`, `child`, a config kit on `lean` that no `add:` of
|
|
314
|
+
yours reaches) unless the toolkit or the session removes it (`remove:`, `--no-tool`, `/toolkit remove`). For a
|
|
315
|
+
tool every session should have, such as the knowledge bundle's `knowledge_search`; it costs its declaration's
|
|
316
|
+
tokens in every request, so keep its description short.
|
|
317
|
+
- **`declare: :kit`**: only a toolkit that adds it declares it (a kit's `add:`, `--tool`, `/toolkit add`), never
|
|
318
|
+
`full` by itself: for tools a kind of session needs (the knowledge bundle's catalog tools, which the coordinator
|
|
319
|
+
kit adds). A kit that doesn't add it doesn't "leave it out": no prompt names it (not the not-loaded line, not
|
|
320
|
+
`find_tools`' description) and `full` shows no chip for it, so registering one leaves the system prompt and the
|
|
321
|
+
declared tools of every session that doesn't add it as they were. Where the tool index is up (an MCP server, a kit
|
|
322
|
+
leaving built-ins out) `find_tools` finds it and `call_tool` reaches it as `chi/<name>` (a kit's chip lists it as
|
|
323
|
+
reachable; on a host that loads tools it is among the deferred ones, after the cached part), but it never brings
|
|
324
|
+
`find_tools` and `call_tool` into a session that had none. Called by its own name where it isn't declared, it gets
|
|
325
|
+
the unknown-tool answer.
|
|
326
|
+
- Anything else is a load error (`tool x: declare must be :kit or :always`). A changed `declare:` in
|
|
327
|
+
`chi.replace_tools` is a change (the prompts are built again). The toolkit report (`chi toolkit report`) grades an
|
|
328
|
+
`:always` tool covered on every kit but one removing it, and a `:kit` one only by a kit's adds.
|
|
329
|
+
- `declare:` needs a chi newer than 0.194.0: an older chi refuses the keyword, a load error, so a bundle passing it
|
|
330
|
+
sets `requires_chi` past that (`chi bundle check` warns on a lower one).
|
|
331
|
+
|
|
310
332
|
#### `args`
|
|
311
333
|
|
|
312
334
|
`args` is a frozen Hash with **string keys**: the arguments the model gave,
|
|
@@ -926,12 +948,13 @@ full label, `plugin.rb (bundle my-bundle)`.
|
|
|
926
948
|
| `ctx.session_id` | the session's id (nil before there is one) |
|
|
927
949
|
| `ctx.cwd` | the session's working directory |
|
|
928
950
|
| `ctx.repo_root` | the git checkout holding `cwd`, or nil |
|
|
951
|
+
| `ctx.project` | the project `cwd` belongs to, as chi's memories find it, frozen: `kind` (`:git`, `:marker` for a `chi project init` folder, `:none`), `root` (a repository's **main checkout**, for every linked worktree too; the marked folder; nil for none), `key` (the memories key, `<name>_<hash>` or the marker's id; nil for none), `memories_dir` (where `memory_read`/`memory_write`'s project scope is for this folder: a folder in no project has its own), `system_memories_dir`, `chi_dirs` (chi's state dir, config dir and an outside hooks dir), `secret_root?(path)` (a folder a participant's turn never reads: chi's dirs, `~/.ssh` and the other home secrets, as given and as it resolves) and `secret_name?(relative_path)` (a file inside an allowed folder named like a secret: `.env*`, `credentials*`, keys, a `.git` config). Use it rather than chi's memory paths. One known gap: a session saved with a project root before its marked folder moved keeps that root in `Session#project_root`, while `ctx.project` reads the folder now. Needs a chi newer than 0.194.0 (guard it with `ctx.respond_to?(:project)`) |
|
|
929
952
|
| `ctx.scratch?` | whether the session is a `chi scratch` one (deleted when it ends) |
|
|
930
953
|
| `ctx.delegate?` | whether the session is a delegate child: a task another session handed over |
|
|
931
954
|
| `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
955
|
| `ctx.continues` | the id of the session this one continues (a [continue](sessions.md#session-chains)'s new link), else nil |
|
|
933
956
|
| `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 |
|
|
957
|
+
| `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
958
|
| `ctx.model_key` | that model's memory overlay key (`<name>.<key>.md`, what `memory_write current_model_only` writes) |
|
|
936
959
|
| `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
960
|
| `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 +1053,17 @@ ctx.card(id: id, title: "Build finished", body: "no warnings left") # replaces
|
|
|
1030
1053
|
needs chi 0.183.0: set `requires_chi: ">= 0.183.0"` in the bundle by hand
|
|
1031
1054
|
(`chi bundle check` can't see an action's keys); an older chi refuses the
|
|
1032
1055
|
card with `ArgumentError`.
|
|
1056
|
+
- `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
|
|
1057
|
+
its title, its sub line under it and its own buttons, the actions whose `row:` is its index (0-based), up to 3 a
|
|
1058
|
+
row and apart from the card's 6; the terminal prints each row, its `→` lines indented under it. An action with
|
|
1059
|
+
`primary: true` is drawn solid in the web (the others are ghost buttons). claude-peer's "Claude Code sessions
|
|
1060
|
+
here" is one: a row per Claude, Show and Pair on each. A card with rows is never a notice.
|
|
1061
|
+
|
|
1062
|
+
```ruby
|
|
1063
|
+
ctx.card(title: "Claude Code sessions here", rows: [{ title: "coordinator", sub: "~/p/s · started 3 h ago" }],
|
|
1064
|
+
actions: [{ label: "Show", command: "/claude show 1a2b3c4d", row: 0 },
|
|
1065
|
+
{ label: "Pair", command: "/claude pair 1a2b3c4d", row: 0 }])
|
|
1066
|
+
```
|
|
1033
1067
|
- `level:` is `:info` or `:warn` (the warning colour).
|
|
1034
1068
|
- An `:info` card with no actions and a body of one short line (up to 160
|
|
1035
1069
|
characters) is a notice: the web shows it as a one-line row,
|
|
@@ -1040,7 +1074,7 @@ ctx.card(id: id, title: "Build finished", body: "no warnings left") # replaces
|
|
|
1040
1074
|
web updates the card in place; the terminal prints it again, marked
|
|
1041
1075
|
`(updated)`. A card that waits for something (a model's answer) shows
|
|
1042
1076
|
first, then is replaced.
|
|
1043
|
-
- A bad card (no title, a bad level or
|
|
1077
|
+
- A bad card (no title, a bad level, action or row) raises `ArgumentError`.
|
|
1044
1078
|
|
|
1045
1079
|
Where it shows:
|
|
1046
1080
|
|
|
@@ -1509,6 +1543,8 @@ ctx.sessions.send(id, "then the docs", delivery: :queue) # after its running tu
|
|
|
1509
1543
|
ctx.sessions.read(id) # => {id:, title:, status:, parent_id:, running:, messages:} (title: its /title, else its preview)
|
|
1510
1544
|
ctx.sessions.children # => [{id:, short_id:, state:, branch:, last_reply:, reported:, ...}]
|
|
1511
1545
|
ctx.sessions.stop(id) # one of this session's own children
|
|
1546
|
+
ctx.sessions.list(changed_since: nil) # => [{id:, title:, updated_at:, archived:}] this project's saved sessions
|
|
1547
|
+
ctx.sessions.present_ids # => ["3f2a9c1e-…", …] every saved session's id
|
|
1512
1548
|
```
|
|
1513
1549
|
|
|
1514
1550
|
- `fork(messages:, title: nil, prompt: nil)` starts a child session in its
|
|
@@ -1561,6 +1597,17 @@ ctx.sessions.stop(id) # one of this session's own children
|
|
|
1561
1597
|
- `stop(id)` stops one of this session's own children, as
|
|
1562
1598
|
`chi sessions stop` does, and waits up to 2 s for its worker to let go. It
|
|
1563
1599
|
returns the child's id. Any other session raises.
|
|
1600
|
+
- `list(changed_since: nil)` lists this project's saved sessions
|
|
1601
|
+
(`ctx.project.root`'s; a session in no project lists the ones in none),
|
|
1602
|
+
newest updated first, archived ones included, never a scratch or test_run
|
|
1603
|
+
one: the listing `SessionStats.summaries` gives (reflect's counts read it
|
|
1604
|
+
too). Each file is parsed, so call it from your own thread, not every
|
|
1605
|
+
turn; `changed_since:` (a Time) parses only the files written after it.
|
|
1606
|
+
Read a row's messages with `read(id)`. `present_ids` is every saved
|
|
1607
|
+
session's id from the file names, nothing parsed (~2 ms): what an index of
|
|
1608
|
+
sessions keeps rows for (the knowledge bundle drops a deleted session's
|
|
1609
|
+
with it). Both need a chi newer than 0.194.0 (`chi bundle check` warns
|
|
1610
|
+
below that).
|
|
1564
1611
|
- Each raises `Samagotchi::Plugin::Sessions::Error` with the reason.
|
|
1565
1612
|
|
|
1566
1613
|
## Attached context: `ctx.context`
|
|
@@ -1569,6 +1616,7 @@ ctx.sessions.stop(id) # one of this session's own children
|
|
|
1569
1616
|
ctx.context.attach(url: "https://github.com/acme/app/pull/42", why: "branch feat/x has open PR #42")
|
|
1570
1617
|
ctx.context.attach(name: "ci", cmd: "bin/ci-status", why: "this branch's CI", every_seconds: 120)
|
|
1571
1618
|
ctx.context.list # => [{name:, scope:, why:, hint:, fetched_at:, error:, provider:, summary:}]
|
|
1619
|
+
ctx.context.snapshots # => [{name:, scope:, session_id:, hint:, revision:, fetched_at:, text:}]
|
|
1572
1620
|
ctx.context.decline(url: "https://github.com/acme/app/pull/42") # => "pr-42"
|
|
1573
1621
|
ctx.context.propose(url: "https://github.com/acme/app/pull/42", title: "#42 Make the thing", mentions: ["#42", "feat/x"])
|
|
1574
1622
|
ctx.context.candidates # => [#<data Candidate name="pr-42", url="https://…", title="#42 Make the thing", …>]
|
|
@@ -1630,6 +1678,13 @@ gets a note when its text changes.
|
|
|
1630
1678
|
the session has an id or its file is saved: a command before the first turn). `hint` is the
|
|
1631
1679
|
one the last text gave (else the source's), `summary` that text's summary
|
|
1632
1680
|
(nil before any text; chi 0.63.0).
|
|
1681
|
+
- `snapshots` (read-only) gives the latest texts of this project's sources
|
|
1682
|
+
and of the sources this project's sessions keep as their own (a session in
|
|
1683
|
+
no project: the sessions in none), project ones first, then by session id
|
|
1684
|
+
and name; `session_id` is nil for a project's. A source with no text yet
|
|
1685
|
+
is left out, and it never runs a command. It reads every snapshot file, so
|
|
1686
|
+
call it from your own thread (the knowledge bundle's context source does).
|
|
1687
|
+
Needs a chi newer than 0.194.0 (`chi bundle check` warns below that).
|
|
1633
1688
|
- Two attaches of one source at once (a double click) both return its
|
|
1634
1689
|
name.
|
|
1635
1690
|
- `attach`, `decline` and `propose` raise
|
|
@@ -1647,12 +1702,48 @@ ctx.peers.left_behind("claude") # the previous link's pairing, in a continue's
|
|
|
1647
1702
|
ctx.peers.message("claude", 12) # => #<data PeerMessage serial=12, text="…", summary="…", wake=true, re="s-ab12cd", at="…"> or nil
|
|
1648
1703
|
ctx.peers.message("claude", 3, box: "1a2b3c4d") # box: the note's box, or the continued session's id8 (its mailbox)
|
|
1649
1704
|
ctx.peers.last_message("claude") # the newest message still in the mailbox, or nil
|
|
1705
|
+
ctx.peers.here("claude") # the live Claude Code sessions of this project that announced themselves (PeerHere)
|
|
1706
|
+
ctx.peers.pair("claude", address: "/tmp/…sock", from: "…", peer_session: "…") # => PeerPaired (status :paired, or a refusal)
|
|
1707
|
+
ctx.peers.unpair("claude") # => PeerUnpaired (unpaired:, waited:): ends the pairing and the wait
|
|
1708
|
+
ctx.peers.wait("claude") # this session waits 10 min for one; .waiting(name): the wait (stale? until_at)
|
|
1709
|
+
ctx.peers.claim("claude") # takes the wait before pairing against it (nil: none to take); .release(claim)
|
|
1710
|
+
ctx.peers.claimed?("claude") # another pairing holds the wait right now (a pair then writes nothing)
|
|
1711
|
+
ctx.panes.find(pid: 1234) # the kitty window a pid runs in (title, cwd), or nil
|
|
1712
|
+
ctx.panes.show(pane) # brings it to the front: only when ctx.user_typed? (else raises)
|
|
1713
|
+
ctx.panes.open(command: argv, cwd: dir, title: "…") # a background kitty tab: a PaneRef; only when ctx.user_typed?
|
|
1714
|
+
ctx.panes.open(command: argv, cwd: dir, title: "…", in: :pane) { |placed| … } # next to this session's chi terminal, else a tab
|
|
1715
|
+
ctx.panes.alive?(ref) # its window is still there
|
|
1716
|
+
ctx.panes.paste(ref, text, enter: true) # one bracketed paste, then Enter: only when ctx.user_typed? (false: gone)
|
|
1717
|
+
ctx.peers.stop_waiting("claude", mark) # ends the wait #wait returned, only while it is that one
|
|
1718
|
+
ctx.user_typed? # this command was typed or tapped by a person at a UI (never chi send or a tool)
|
|
1650
1719
|
```
|
|
1651
1720
|
|
|
1652
1721
|
What a peer bundle reads of its peer's side of the session (the mailbox,
|
|
1653
1722
|
[peers.md](peers.md)): the pairing (`address` nil: the peer answers only) and
|
|
1654
|
-
the peer's messages.
|
|
1655
|
-
|
|
1723
|
+
the peer's messages. The peer says through `chi peer`, and the worker takes
|
|
1724
|
+
the messages; a pairing from chi's side goes through `pair` (the same writer
|
|
1725
|
+
as `chi peer pair`, its refusals), against the peers that announced
|
|
1726
|
+
themselves here (`here`, [internals/peers.md](internals/peers.md#who-is-here-peerpresence))
|
|
1727
|
+
and the session's wait (`wait`, `claim`). `ctx.panes`
|
|
1728
|
+
([internals/panes.md](internals/panes.md)) finds a pid's window; its `show`,
|
|
1729
|
+
`open` and `paste` act as the user on their screen, so they run only under
|
|
1730
|
+
`ctx.user_typed?` (else `Plugin::Panes::NotTyped`), which is also what gates a
|
|
1731
|
+
write to another agent's settings. `open` raises
|
|
1732
|
+
`Samagotchi::Panes::Unavailable` when no kitty answers ("kitty isn't running or
|
|
1733
|
+
`kitty.listen_on` isn't set"), its one refusal. With `in: :pane` (the next chi:
|
|
1734
|
+
on 0.194.0 the keyword is an `ArgumentError`, and so is any value but the
|
|
1735
|
+
symbols `:pane` and `:tab`, a string too) it opens a window next to this
|
|
1736
|
+
session's attached chi terminal in kitty, in that terminal's tab, and a
|
|
1737
|
+
background tab when there is none (a start from chi web with no TUI attached,
|
|
1738
|
+
a TUI outside kitty), that tab is in kitty's stack layout, or kitty refuses
|
|
1739
|
+
the launch there; the block, when given, gets a `Plugin::Panes::Placed`:
|
|
1740
|
+
`kind` `:pane` or `:tab`, and `why` a tab when a pane was asked for, in words
|
|
1741
|
+
for your reply. The return is the same `PaneRef` either way. Keep a `PaneRef` in your own
|
|
1742
|
+
session state (`ctx.session_dir`), never in the mailbox; `ctx.panes` takes a ref
|
|
1743
|
+
only on a socket `kitty.listen_on` names, and a caller checks what runs in the
|
|
1744
|
+
window before it pastes. The seam is an accident guard: no tool call, `chi send`,
|
|
1745
|
+
agent, participant, schedule, delegate or plugin path reaches it. A wait that runs out fires
|
|
1746
|
+
`:peer_wait_ended` between turns ([hooks.md](hooks.md#hook-events)). A continue copies the pairing to the new
|
|
1656
1747
|
link, so its `link` is the previous link's pairing as it was; `left_behind`
|
|
1657
1748
|
is the one the previous link keeps (the copy's source; an older chi left the
|
|
1658
1749
|
new link unpaired). Needs the next chi.
|
|
@@ -1758,7 +1849,8 @@ pages: [schedules.rb] # scripts: keys named NAME.rb: the page NAME
|
|
|
1758
1849
|
- The owner's own `NAME.rb` in the pages folder replaces a bundle's page, and a bundle's page can't be removed but
|
|
1759
1850
|
by uninstalling the bundle ([Pages from a bundle](pages.md#pages-from-a-bundle)).
|
|
1760
1851
|
- The script is a page script like any other: `page`, `ui` and `runtime` ([pages.md](pages.md)). The shipped
|
|
1761
|
-
schedules bundle is the example (`lib/samagotchi/bundles/schedules/`)
|
|
1852
|
+
schedules bundle is the example (`lib/samagotchi/bundles/schedules/`); the reflect bundle
|
|
1853
|
+
(`lib/samagotchi/bundles/reflect/`) is a second, with `settings:` its page reads through `runtime.settings`.
|
|
1762
1854
|
|
|
1763
1855
|
## Stable for bundles
|
|
1764
1856
|
|
|
@@ -1827,7 +1919,9 @@ that calls it, or for a real external bundle that does. No method on the chance
|
|
|
1827
1919
|
- `pages:` and the page script DSL a bundle's page (or anyone's) is written in: `page`, `ui.text` / `ui.table` /
|
|
1828
1920
|
`ui.walk`, and `runtime` with what it returns (`runtime.schedules`: its members, `rows`, `warning`,
|
|
1829
1921
|
`unreadable_ids`, `Pages::Runtime::Unreadable`) ([pages.md](pages.md)). A page runs in the page runner, not as a
|
|
1830
|
-
plugin, so the scan below doesn't see it either.
|
|
1922
|
+
plugin, so the scan below doesn't see it either. `runtime.sessions(project:)`, `runtime.turn_excerpts`,
|
|
1923
|
+
`runtime.launch_dir` and `runtime.settings` are **experimental**: their members may still change
|
|
1924
|
+
([pages.md](pages.md#reading-chis-data-runtime)).
|
|
1831
1925
|
|
|
1832
1926
|
`Samagotchi::Testing::Boundary::ALLOWED` is the checked copy of items 1-6,
|
|
1833
1927
|
and `Boundary::EXCEPTIONS` the per-bundle list of what each shipped bundle
|
data/docs/releasing.md
CHANGED
|
@@ -13,7 +13,7 @@ can run the whole release; the user approves the notes before the tag and the
|
|
|
13
13
|
and `rake release:check` enforce it). The system bundle upgrades itself when
|
|
14
14
|
chi starts.
|
|
15
15
|
- **Every other shipped bundle** (btw, check-in, guardrails, known-names,
|
|
16
|
-
loop-guard, mcp, skills, slow-commands, agents-md, cost-cap, work-cap, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes, decision-card, inline-widgets, web-search, schedules, and the profiles core and dev) has its own semver in its
|
|
16
|
+
loop-guard, mcp, skills, slow-commands, agents-md, cost-cap, work-cap, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes, decision-card, inline-widgets, knowledge, web-search, schedules, reflect, and the profiles core and dev) has its own semver in its
|
|
17
17
|
`manifest.yml` and, when it needs a newer chi, a `requires_chi:` line. They never upgrade by themselves: users run
|
|
18
18
|
`chi update` (all of them, with the gem) or `chi bundle upgrade NAME`. So:
|
|
19
19
|
- a change to a bundle's files bumps that bundle's `version:`
|
data/docs/scheduling.md
CHANGED
|
@@ -93,6 +93,10 @@ the fold. If a local moment does not exist (a spring-forward gap), it fires at t
|
|
|
93
93
|
next valid minute. Schedules use the machine's local clock; there are no named
|
|
94
94
|
time zones.
|
|
95
95
|
|
|
96
|
+
A daily chain, for example a project's nightly reflect ([bundles.md](bundles.md#a-nightly-reflect-session)):
|
|
97
|
+
`chi schedule add --session <ID> --every 1d --title "reflect <project>" --keep-links 14 --max-skips 288 -m "Reflect
|
|
98
|
+
on this project's last day: follow skill_reflect."`, run at the hour you want it to fire.
|
|
99
|
+
|
|
96
100
|
`catch_up` says what an overdue entry does when the tick arrives after its moment:
|
|
97
101
|
|
|
98
102
|
- `once` (default): fire once now, then reschedule normally.
|
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
|
|
|
@@ -87,6 +87,13 @@ order: `recap`, else the asking bundle's name). It has no records: the block its
|
|
|
87
87
|
by the turn's end during one) and loaded; it is never in `tokens` or `model_segments`. `chi sessions stats --format
|
|
88
88
|
json` has it in `metrics.side`; a file without it (older, or no side requests) has none.
|
|
89
89
|
|
|
90
|
+
Two read-only readers outside the worker read the session file, `analytics.json` and `cards.json` too: `SessionStats`
|
|
91
|
+
(a page's `runtime.sessions`: counts) and `TurnExcerpts` (`runtime.turn_excerpts`: a turn's failing calls), both
|
|
92
|
+
treating every field as optional ([pages.md](pages.md#reading-chis-data-runtime)). A shape change to those files must
|
|
93
|
+
keep them working (`spec/session_stats_spec.rb`, `spec/turn_excerpts_spec.rb`). `SessionStats.summaries` (archived
|
|
94
|
+
included, no test_run or scratch session, by project) is the one listing both its counts and the knowledge bundle's
|
|
95
|
+
sessions source (`ctx.sessions.list`) read; `Session.list(changed_since:)` skips an unchanged file before parsing it.
|
|
96
|
+
|
|
90
97
|
Each turn record in `analytics.json` names the model the turn ran on as `model_ref` (the asked `host:model`, from its first generation; `model` stays the name the server says it served); a turn stopped before it asked a model has none. The first turn after a `/model` switch (or a hook's) to another model also records what its first generation prefilled on the new model: `switch_prefill_tokens` (the prompt less the cached reads; none under 128 tokens, or for a generation with estimated counts) and `switch_prefill_cost_estimate` (from the new model's configured price, no completion; none without a price). A session saved before this has no `model_ref` on its records.
|
|
91
98
|
|
|
92
99
|
A session whose worker waits for an answer (a question, a hook's question, a guardrail approval, or the step-limit question of a turn that ran out of steps, which waits between turns) reads `waiting` in the status column, and json has `waiting: "question"|"approval"|"hook"|"continue"` and `waiting_id`, the question's id for `chi answer --question` (both null otherwise). A delegate's approval its parent relayed to its own card (see *Delegating*) reads `waiting (in parent ab12)`, json `relayed_to: "ab12…"` (the parent's short id, else null). Only while a worker runs it: a question a dead worker left in the file shows the saved status. Answer it with `chi answer`, the web or `chi --attach ID`; `chi sessions stop ID` frees the worker instead.
|
|
@@ -137,7 +144,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
137
144
|
| `written_by` | The chi version that saved the file last (see *Which chi a worker runs*). | `Session#save` |
|
|
138
145
|
| `id` | The uuid; also the file name. Required. | `Session.new_session` |
|
|
139
146
|
| `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` |
|
|
147
|
+
| `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
148
|
| `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
149
|
| `working_directory` | The folder the session runs in. Required. | creation |
|
|
143
150
|
| `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 |
|
|
@@ -172,7 +179,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
172
179
|
| `working_set_pins` | The working-set items the user pinned (`/working-set pin`); kept by a respawn, a continue and a fork. | the Engine's command |
|
|
173
180
|
| `review` | An older chi's review session's subjects and source (`SessionReview`), kept as written, never read: see [Older review sessions](#older-review-sessions). | an older chi |
|
|
174
181
|
| `first_turn_id` | The id the creating prompt's turn gets, so a wait can name it (`chi send --new --wait`, `--wait --turn T ID`); `null` for a session created idle. | `SessionManager.spawn_session` |
|
|
175
|
-
| `first_turn_client_id` | Who sent the creating prompt
|
|
182
|
+
| `first_turn_client_id` | Who sent the creating prompt: any sender that is no human's (`delegate:<parent8>` for a delegate's task, `system:schedule:<id>` for a chain schedule's link, `agent:<name>`) and an interactive one (a web tab's `web:…`, a TUI's `tui:…`); none for `chi send --new`, an idle create, and a file from before interactive ids were kept: that first turn's origin, so its line is no command of the owner's (docs/guardrails.md, Who may run a session command) and `last_turn` names the sender. Written only when set; not carried by a fork, a continue or a delegate. An older chi keeps it but runs the first prompt as a person's. | `SessionManager.spawn_session` (its `client_id:`) |
|
|
176
183
|
| `verify_fresh` | A Verify fresh child's requester, rules and claim (`VerifyFreshOrigin`). | `VerifyFresh.start`, once |
|
|
177
184
|
|
|
178
185
|
## Context notes
|
|
@@ -583,7 +590,16 @@ Reminders, a running `/btw`, and other in-memory worker state cannot be
|
|
|
583
590
|
checked and may be lost in this fallback. A stopped worker (SIGSTOP or
|
|
584
591
|
Ctrl-Z: `ps` state `T`) answers neither the ask nor a TERM, so a restart
|
|
585
592
|
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
|
-
|
|
593
|
+
session whose stop is marked (stopped, or its worker being stopped) has no
|
|
594
|
+
worker to hand over (no successor would come), so a person's restart starts it
|
|
595
|
+
again instead, as `chi --resume` does without a terminal: the stop cleared and a
|
|
596
|
+
worker spawned ("Started session ID again on chi X."), one being stopped once its
|
|
597
|
+
worker has left (up to `SessionManager::STOP_WAIT`, else `still_stopping`: "is
|
|
598
|
+
still stopping; restart it again in a moment"). Only this session starts: the
|
|
599
|
+
delegates its stop stopped stay stopped. An agent's restart (`AgentCaller`) is
|
|
600
|
+
refused before any of this (`stop_marked`, "… ask your user to start it: …"),
|
|
601
|
+
and so is chi web's restart after an update (`Web::UpdateOps#restart_one`): an
|
|
602
|
+
update never undoes a stop (`restart_session`'s `start_stopped:`, false by
|
|
603
|
+
default). A session being deleted is refused the same way (`deleting`).
|
|
604
|
+
The web restart route behaves the same way: a body without
|
|
605
|
+
`"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
|
data/docs/system-one.md
CHANGED
|
@@ -37,6 +37,10 @@ same `Client` and `Recording`: the API is in [plugins.md](plugins.md#judgments-c
|
|
|
37
37
|
Only bundles' judgments have settings of their own (`JudgmentSettings`). Core's take no host, model or mode here, whatever
|
|
38
38
|
`system_one.judgments` says: `Record` and `Similar` are model-blind (`Record#initialize` filters by rule, and by repository for a rule in `guardrails.system_one.repo_rules`, never by model), so a model swapped
|
|
39
39
|
for approvals alone would inherit a clean record and could auto-allow. Before any such swap, `Record` and `Similar` have to go by model.
|
|
40
|
+
`system_one.model: served` changes the judge whenever the host loads another model, under the same model-blind record (the owner's
|
|
41
|
+
choice: the speed of a hand edit, no new kind of risk); each saved run's `model` is the id that answered (after a not-served retry, the
|
|
42
|
+
retried one), and the change logs `system_one_model_changed`. A run whose listing failed or was refused (nothing was asked)
|
|
43
|
+
records `served`, the configured value, with the failure.
|
|
40
44
|
|
|
41
45
|
Core's uses keep their own threads (`ToolkitSuggest::Pending`, `ContextJudge`, the approval path) and contention; only the ask-and-save
|
|
42
46
|
seam is common. A bundle's `judge_later` runs on the Engine's `SideJudgments` under its full name as the kind, so `SideJudgments#join`
|
data/docs/testing.md
CHANGED
|
@@ -54,6 +54,11 @@ adapters load, so a run from `git rebase --exec`, `bisect run` or a hook can't r
|
|
|
54
54
|
chose spawn with `GitEnv::UNSET`, in any run.
|
|
55
55
|
`SAMAGOTCHI_TAILSCALE_CLI` points at a file that does not exist (`spec_helper.rb`), so no spec reaches a real `tailscale`; a
|
|
56
56
|
`chi web --tunnel tailscale` spec writes a fake one and sets the variable.
|
|
57
|
+
No spec reaches a running kitty either (Panes opens tabs and pastes into windows): the spec config has no
|
|
58
|
+
`kitty.listen_on` and `spec_helper.rb` drops `SAMAGOTCHI_KITTY_LISTEN_ON`; a pane spec stubs `Config.get("kitty.*")`
|
|
59
|
+
with `spec/fixtures/desktop/fake_kitty` (`ls`, `launch`, `focus-window`, `send-text`, `send-key`). It drops
|
|
60
|
+
`KITTY_WINDOW_ID` too, so an attached TUI a spec runs never marks the developer's kitty window (the `chi_session`
|
|
61
|
+
user var, [internals/panes.md](internals/panes.md)).
|
|
57
62
|
|
|
58
63
|
Goldens (`*_golden_spec.rb`, the prompt snapshots) hold no machine state, so they pass on any runner: no absolute
|
|
59
64
|
paths (replace them with placeholders), no PATH tools (the suite pins `rg` as found, `spec_helper.rb`; an example
|
|
@@ -345,7 +345,7 @@ module Samagotchi
|
|
|
345
345
|
def anchor = @running_turn || @turn_log.last
|
|
346
346
|
|
|
347
347
|
def add_card(event)
|
|
348
|
-
card = event.slice(:type, :id, :source, :title, :body, :level, :actions, :command)
|
|
348
|
+
card = event.slice(:type, :id, :source, :title, :body, :level, :actions, :rows, :command)
|
|
349
349
|
index = @entries.index { |entry| entry[:type] == :card && entry[:id] == card[:id] }
|
|
350
350
|
if index
|
|
351
351
|
# Replaced where it was: the first one's place stays, and whose it is
|
|
@@ -31,6 +31,9 @@ module Samagotchi
|
|
|
31
31
|
def resolve(host_registry: nil, get: ->(key) { Config.get(key) })
|
|
32
32
|
registry = host_registry || HostRegistry.current
|
|
33
33
|
SETTINGS.each do |model, host_ref, base_url|
|
|
34
|
+
refusal = get.call(base_url).to_s.strip.empty? && list_served(registry, get.call(model), get.call(host_ref))
|
|
35
|
+
return Choice.new(target: nil, setting: model, problem: "#{model}: #{refusal}") if refusal
|
|
36
|
+
|
|
34
37
|
target = IdleTarget.resolve(model: get.call(model), host_ref: get.call(host_ref), base_url: get.call(base_url),
|
|
35
38
|
host_registry: registry)
|
|
36
39
|
return Choice.new(target: target, setting: model, problem: nil) if target
|
|
@@ -38,11 +41,25 @@ module Samagotchi
|
|
|
38
41
|
return Choice.new(target: nil, setting: model, problem: problem(e, model, host_ref))
|
|
39
42
|
end
|
|
40
43
|
model = ModelProfile.required_model_name(get.call("default.model"))
|
|
44
|
+
refusal = list_served(registry, model, nil)
|
|
45
|
+
return Choice.new(target: nil, setting: "default.model", problem: "default.model: #{refusal}") if refusal
|
|
46
|
+
|
|
41
47
|
Choice.new(target: IdleTarget.of_model(registry, model), setting: "default.model", problem: nil)
|
|
42
48
|
rescue StandardError => e
|
|
43
49
|
Choice.new(target: nil, setting: "default.model", problem: e.message.to_s.lines.first.to_s.strip[0, 200])
|
|
44
50
|
end
|
|
45
51
|
|
|
52
|
+
# A served +model+ (main:served, a bare served on +host_ref+'s host)
|
|
53
|
+
# listed now: this CLI process knows nothing of what the host serves.
|
|
54
|
+
# One bounded listing, no retry. @return [String, nil] the refusal
|
|
55
|
+
# when the host lists none or several models
|
|
56
|
+
def list_served(registry, model, host_ref)
|
|
57
|
+
return nil if model.to_s.strip.empty?
|
|
58
|
+
|
|
59
|
+
registry.refresh_served!(model.to_s.strip, max_age: 0, host: host_ref.to_s.strip.empty? ? nil : host_ref.to_s.strip)&.refusal
|
|
60
|
+
end
|
|
61
|
+
private_class_method :list_served
|
|
62
|
+
|
|
46
63
|
def problem(error, model_key, host_ref_key)
|
|
47
64
|
case error.reason
|
|
48
65
|
when :host_ref_unknown then "#{host_ref_key} '#{error.host_ref}' is not in hosts:"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: claude-peer
|
|
3
|
-
version: 0.
|
|
3
|
+
version: 0.10.0
|
|
4
4
|
scope: system
|
|
5
5
|
description: "Pair this session with a Claude Code session you work with: the claude_send tool and /claude send it a part of the work (a plan step, a diff, a finding) to validate or as context, and Claude's answer comes back as a message with its text (chi peer say); /claude install-skill installs Claude's chi-peer skill, which pairs"
|
|
6
6
|
trust_level: reviewed
|
|
@@ -10,12 +10,18 @@ files:
|
|
|
10
10
|
description: "Send a part of the work to the paired Claude Code session (claude_send): only when the user asks, or to reply to its answer in a peer turn; validate, context or question; Claude's answer comes as a message with its text"
|
|
11
11
|
plugin:
|
|
12
12
|
file: plugin.rb
|
|
13
|
-
sha256: sha256:
|
|
13
|
+
sha256: sha256:a20b84513f78a4c46d1d396e9d8b72fd719a4ed66e48cdf628cb8f8bea492fb6
|
|
14
14
|
scripts:
|
|
15
15
|
pair-remote: sha256:d7681f87a194e540b629564f84cad9f2d0a763197502c74614276ef88a8920cc
|
|
16
|
-
pair: sha256:
|
|
17
|
-
chi-peer-SKILL.md: sha256:
|
|
16
|
+
pair: sha256:626b1c4acba6b1ab8a9d9615c709d69da6953d89d32469f370c2eaad145a8bb8
|
|
17
|
+
chi-peer-SKILL.md: sha256:e3d5bd01d221a3206e203098bf7e1e1fbbbf72b2124bae744eace1816d8eca0c
|
|
18
|
+
# config.yml bundles: <name>: start_command: the shell line /<peer> start runs in its kitty window; open_in: pane
|
|
19
|
+
# (the default: a pane next to this session's chi terminal in kitty, else a background tab) or tab (always a
|
|
20
|
+
# background tab). Another key warns.
|
|
21
|
+
settings: {start_command: string, open_in: string}
|
|
18
22
|
# The plugin needs Samagotchi::Plugin::Peer on the mailbox: chi.peer and
|
|
19
23
|
# ctx.peers, and the skill's chi peer pair|say, are the next chi's (an older
|
|
20
24
|
# chi has no chi.peer: the plugin fails to load there).
|
|
21
|
-
requires_chi: ">= 0.
|
|
25
|
+
requires_chi: ">= 0.195.0"
|
|
26
|
+
# The pair script's no-id form (chi peer pair --here), --peer-session, /<peer> pair and the start hook are the next chi's.
|
|
27
|
+
# open_in (a pane next to the session's chi terminal) is the next chi's.
|
|
@@ -38,7 +38,11 @@ require "samagotchi/plugin/peer"
|
|
|
38
38
|
# keep what was completed); `/claude install-skill` shows a card with
|
|
39
39
|
# Claude's chi-peer skill's target and an Install action (`--yes`), the card
|
|
40
40
|
# being the user's consent: the copy happens in-process, where no guardrail
|
|
41
|
-
# sees it
|
|
41
|
+
# sees it; and "Add the start hook…" (`/claude install-hook`: the merged
|
|
42
|
+
# settings as a diff), whose card's Add (`--yes`, only on the user's own
|
|
43
|
+
# tap) merges the SessionStart hook that runs `chi
|
|
44
|
+
# peer announce claude` into Claude Code's settings.json. `/claude pair`
|
|
45
|
+
# pairs with a Claude Code session here, no id copied (Plugin::PeerPairing). The skill is scripts/chi-peer-SKILL.md beside this file, with the
|
|
42
46
|
# installed scripts/pair path and the payload folder written in.
|
|
43
47
|
#
|
|
44
48
|
# In the web, selecting text offers "Confirm with Claude" (chi.annotation):
|
|
@@ -69,9 +73,12 @@ class Plugin < Samagotchi::Plugin::Peer
|
|
|
69
73
|
CHECKED_ON = "Claude Code 2.1.296"
|
|
70
74
|
STATUS_CARD = "claude"
|
|
71
75
|
SKILL_CARD = "claude-skill"
|
|
72
|
-
USAGE = "usage: /claude — whether a Claude Code session is paired; /claude
|
|
73
|
-
"
|
|
74
|
-
"
|
|
76
|
+
USAGE = "usage: /claude — whether a Claude Code session is paired (else the ones here); /claude pair — pair the one " \
|
|
77
|
+
"here, or wait for one and list them; /claude pair <id8> — pair that one; /claude show <id8> — bring its kitty " \
|
|
78
|
+
"window to the front; /claude start — open Claude Code in a kitty window, paired when it starts; /claude show — " \
|
|
79
|
+
"bring that window to the front; /claude unpair — end the pairing or the wait; /claude validate <text> | context <text> — " \
|
|
80
|
+
"send the text to it; /claude last — send the last answer as context; /claude install-skill — install Claude's " \
|
|
81
|
+
"chi-peer skill, which pairs; /claude install-hook [--yes] — Claude Code's start hook, which lists a Claude here"
|
|
75
82
|
# The shipped bundle keeps scripts/ beside plugin.rb; an installed one
|
|
76
83
|
# has plugin/plugin.rb and scripts/ beside plugin/.
|
|
77
84
|
SCRIPTS_DIRS = [File.join(__dir__, "scripts"), File.expand_path("../scripts", __dir__)].freeze
|
|
@@ -95,6 +102,18 @@ class Plugin < Samagotchi::Plugin::Peer
|
|
|
95
102
|
"functions or diff range to look at. A long text goes to a file Claude reads" }
|
|
96
103
|
}.freeze
|
|
97
104
|
|
|
105
|
+
# Claude lists itself here (its start hook, chi peer announce): /claude
|
|
106
|
+
# pair finds the sessions open in this project.
|
|
107
|
+
def announces? = true
|
|
108
|
+
|
|
109
|
+
# Its inbox socket missing: that Claude ended (a resume pairs again with a
|
|
110
|
+
# new one). No address (answers only) isn't gone.
|
|
111
|
+
def link_gone?(link) = link.socket_gone?
|
|
112
|
+
|
|
113
|
+
# Its start hook (Claude Code's SessionStart: chi peer announce claude),
|
|
114
|
+
# added to settings.json from the skill card's "Add the start hook".
|
|
115
|
+
def start_hook? = true
|
|
116
|
+
|
|
98
117
|
# The one JSON line Claude Code's inbox socket takes.
|
|
99
118
|
def line(content) = "#{JSON.generate(type: "user", message: { role: "user", content: content })}\n"
|
|
100
119
|
|
|
@@ -118,7 +137,7 @@ class Plugin < Samagotchi::Plugin::Peer
|
|
|
118
137
|
def setup_paragraph(ctx)
|
|
119
138
|
rule = "Read(#{tilde(ctx.data_dir)}/**)"
|
|
120
139
|
"So Claude isn't asked before reading a long part's file, add `#{rule}` to Claude Code's permissions " \
|
|
121
|
-
"(`permissions.allow` in its settings.json); chi
|
|
140
|
+
"(`permissions.allow` in its settings.json); chi never changes Claude's settings without your tap."
|
|
122
141
|
end
|
|
123
142
|
|
|
124
143
|
# Claude Code's config folder: CLAUDE_CONFIG_DIR, else ~/.claude.
|
|
@@ -19,19 +19,40 @@ headless review run.
|
|
|
19
19
|
<!-- Installed by chi's claude-peer bundle (/claude install-skill); a newer
|
|
20
20
|
bundle installs a newer copy. -->
|
|
21
21
|
|
|
22
|
-
## Pair (once per chi session
|
|
22
|
+
## Pair (once per chi session)
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
When the user says "pair with chi" with no id, run it bare:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
sh "__CHI_PEER_PAIR__"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
It pairs with the chi session that waits for a Claude in this project (the
|
|
31
|
+
user typed `/claude pair` there), else with the one chi session of this
|
|
32
|
+
project that runs now. When it lists several instead (exit 1), show the list
|
|
33
|
+
to the user and ask which one; then pair with that id. When that chi session is
|
|
34
|
+
paired with another Claude that is still open, it refuses (exit 1) and replaces
|
|
35
|
+
nothing: tell the user to run `/claude unpair` there first (pairing with its id
|
|
36
|
+
replaces that pairing; do that only when the user says so). One paired with a
|
|
37
|
+
Claude that has ended is replaced, and the pair says so.
|
|
38
|
+
|
|
39
|
+
With an id: the chi session id is the `<id>` in
|
|
40
|
+
`http://127.0.0.1:4567/#/s/<id>` (a unique prefix works; the URL works too):
|
|
26
41
|
|
|
27
42
|
```sh
|
|
28
43
|
sh "__CHI_PEER_PAIR__" <chi session id or URL>
|
|
29
44
|
```
|
|
30
45
|
|
|
31
|
-
It pairs this session with the chi session (`chi peer pair claude
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
It pairs this session with the chi session (`chi peer pair claude`, with this
|
|
47
|
+
session's inbox socket, `$CLAUDE_CODE_MESSAGING_SOCKET`, as the address chi
|
|
48
|
+
sends to, and this session's id). Running it again only refreshes the socket.
|
|
49
|
+
|
|
50
|
+
The socket changes when this Claude session restarts (`claude --resume`).
|
|
51
|
+
With chi's start hook installed (`/claude install-skill` in chi, "Add the
|
|
52
|
+
start hook") the pairing follows by itself: the start context says `chi <id8>:
|
|
53
|
+
pairing refreshed`. Without it, pair again after a restart. A start context
|
|
54
|
+
line `paired with chi <id8> (<title>)` means the hook paired this session with
|
|
55
|
+
a chi session that waited: there is nothing to run.
|
|
35
56
|
|
|
36
57
|
Tell the user it's paired, and that in chi they can say "send this to Claude
|
|
37
58
|
for validation" or "give Claude this as context", or type
|