samagotchi 0.85.0 → 0.86.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 +60 -1
- data/docs/architecture.md +34 -5
- data/docs/bundle-authoring.md +125 -0
- data/docs/cli.md +38 -3
- data/docs/configuration.md +6 -5
- data/docs/guardrails.md +63 -35
- data/docs/hooks.md +19 -3
- data/docs/internals/anthropic.md +2 -2
- data/docs/internals/bundles.md +11 -2
- data/docs/internals/context-telemetry.md +19 -1
- data/docs/internals/engine.md +1 -1
- data/docs/memory.md +1 -1
- data/docs/plugins.md +59 -2
- data/docs/releasing.md +1 -1
- data/docs/sessions.md +6 -6
- data/docs/sub-agent.md +35 -24
- data/docs/testing.md +7 -2
- data/lib/samagotchi/answer_command.rb +21 -25
- data/lib/samagotchi/bridge/client_event.rb +50 -0
- data/lib/samagotchi/bridge/sse_writer.rb +6 -2
- data/lib/samagotchi/bridge.rb +22 -11
- data/lib/samagotchi/bridge_client.rb +2 -2
- data/lib/samagotchi/bundle_command/check.rb +348 -0
- data/lib/samagotchi/bundle_command/scaffold.rb +135 -0
- data/lib/samagotchi/bundle_command/test_run.rb +89 -0
- data/lib/samagotchi/bundle_command.rb +125 -2
- data/lib/samagotchi/bundles/core/manifest.yml +2 -2
- data/lib/samagotchi/bundles/cost-cap/manifest.yml +4 -4
- data/lib/samagotchi/bundles/cost-cap/plugin.rb +4 -1
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -1
- data/lib/samagotchi/bundles/guardrails/guardrails/rules.yml +4 -2
- data/lib/samagotchi/bundles/guardrails/manifest.yml +1 -1
- data/lib/samagotchi/bundles/ruby/manifest.yml +11 -0
- data/lib/samagotchi/bundles/ruby/plugin.rb +74 -0
- data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +2 -1
- data/lib/samagotchi/client_id.rb +1 -1
- data/lib/samagotchi/config.rb +195 -115
- data/lib/samagotchi/context_status.rb +1 -1
- data/lib/samagotchi/continue_offer.rb +2 -1
- data/lib/samagotchi/engine.rb +4 -4
- data/lib/samagotchi/guardrail_wiring.rb +4 -0
- data/lib/samagotchi/guardrails/approval.rb +12 -2
- data/lib/samagotchi/guardrails/load_failures.rb +17 -3
- data/lib/samagotchi/guardrails/parent_approvals.rb +14 -70
- data/lib/samagotchi/guardrails/parent_policy.rb +258 -0
- data/lib/samagotchi/guardrails/verdict.rb +6 -3
- data/lib/samagotchi/hook_routes.rb +5 -3
- data/lib/samagotchi/hooks/bundle_loader.rb +3 -1
- data/lib/samagotchi/hooks/registry.rb +13 -6
- data/lib/samagotchi/hooks.rb +5 -0
- data/lib/samagotchi/kernel_loop.rb +5 -2
- data/lib/samagotchi/llm/anthropic_assembly.rb +1 -1
- data/lib/samagotchi/memory_bundle/shas.rb +127 -0
- data/lib/samagotchi/memory_bundle.rb +1 -0
- data/lib/samagotchi/parent_report.rb +87 -14
- data/lib/samagotchi/pending_question.rb +8 -4
- data/lib/samagotchi/plugin/api.rb +16 -0
- data/lib/samagotchi/plugin/context.rb +11 -5
- data/lib/samagotchi/plugin/loader.rb +5 -3
- data/lib/samagotchi/question_desk.rb +37 -24
- data/lib/samagotchi/queued_command.rb +5 -4
- data/lib/samagotchi/relay.rb +5 -1
- data/lib/samagotchi/relay_verifier.rb +4 -5
- data/lib/samagotchi/reply_wait.rb +14 -5
- data/lib/samagotchi/send_command.rb +34 -8
- data/lib/samagotchi/session_commands.rb +14 -3
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +13 -11
- data/lib/samagotchi/terminal_ui/thinking_line.rb +5 -9
- data/lib/samagotchi/terminal_ui.rb +12 -9
- data/lib/samagotchi/testing/boundary.rb +0 -3
- data/lib/samagotchi/testing/bundle.rb +7 -0
- data/lib/samagotchi/testing/host.rb +6 -4
- data/lib/samagotchi/testing/install.rb +119 -0
- data/lib/samagotchi/testing/recorder.rb +13 -4
- data/lib/samagotchi/testing.rb +1 -0
- data/lib/samagotchi/tools/builtins.rb +2 -1
- data/lib/samagotchi/tools/delegate_wait.rb +6 -1
- data/lib/samagotchi/tools/task_runtime.rb +5 -3
- data/lib/samagotchi/turn_checkpoint.rb +64 -2
- data/lib/samagotchi/turn_flow.rb +10 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +48 -10
- data/lib/samagotchi/web/public/chunk_router.js +8 -19
- data/lib/samagotchi/web/public/ctx.js +12 -26
- data/lib/samagotchi/web/public/stream_handlers.js +1 -1
- data/lib/samagotchi/web/server.rb +4 -0
- data/lib/samagotchi/worker.rb +19 -5
- data/lib/samagotchi/worker_inbound.rb +4 -4
- metadata +11 -2
- data/lib/samagotchi/guardrails/parent_continue.rb +0 -43
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9bd5a2287b8113de9eb91acc1a735e6e132f339dd1569567e7cec6e1bea6637a
|
|
4
|
+
data.tar.gz: 2cfb2f0a9cc14bb226e227fcced1ce2efb16268707953423bd1db991070e36d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d5c8b88e0d4ab6fbebdb80d1705ae2904d6b5ac59b463099c9101f22161a912cbe56fe93da7cdcef672f62cc4162d212325c884f66a49aa27385a9aa71ba160
|
|
7
|
+
data.tar.gz: 3a54cc7c7629d902d1857e85b2f6fa43d2fb36805bf85ac733bfa4fba614c7a9488080dd40633c40e94ccae0749fdcce4f05c3fc7888b6e65931cd5cd492477d
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,64 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.86.0] - 2026-10-18
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `chi bundle new NAME`, `chi bundle check [PATH] [--fix]` and `chi bundle test [PATH]` for writing a bundle: a
|
|
16
|
+
scaffold that checks clean and passes its test; a check that installs and loads the bundle in a sandbox and prints
|
|
17
|
+
one finding per line with a fix hint (manifest, sha256 lines, load errors with file:line, `requires_chi` floor,
|
|
18
|
+
trust, what it registers), `--fix` filling the sha lines; its tests run on chi's own Ruby and lib. `check` and
|
|
19
|
+
`test` run the bundle's code in their process: run them on code you'd install. docs/bundle-authoring.md (shipped
|
|
20
|
+
in the gem) is the first read.
|
|
21
|
+
- chi tells you when a changed config.yml setting applies only after a restart ("server.port changed — applies after
|
|
22
|
+
a worker restart"; chi web's settings: after restarting chi web).
|
|
23
|
+
- The `ruby` bundle (`chi bundle install ruby`, or the `dev` profile): an `execute` that ran RSpec and found no
|
|
24
|
+
examples at all (`0 examples, 0 failures`: a path, a `-e`/`--tag` filter or a `.rspec --pattern` that matched
|
|
25
|
+
nothing) steers a hint into the turn instead of leaving the run looking green.
|
|
26
|
+
- A plugin's or a hook's `ask_user` takes `effects:` (option label => `:spend`, `:permit`, `:permit_wide`, `:deny`;
|
|
27
|
+
untagged = `:answer`), so a parent agent's answer is held to `guardrails.parent_answers`. The bundle test kit
|
|
28
|
+
records them (`bundle.questions.last.effects`). cost-cap 0.2.0 tags its Continue `:spend` and Stop `:deny`: under
|
|
29
|
+
`hard` a parent may only Stop it.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- **What a parent agent may answer is one setting, `guardrails.parent_answers`** (`hard`, `standard`, `soft`), by
|
|
34
|
+
each option's effect, for every question: approvals, the step-limit Continue, relayed delegate approvals and plugin
|
|
35
|
+
and hook questions. **The default `soft` lets a parent give "Allow once"** (before, a parent could only deny an
|
|
36
|
+
approval); `standard` is the old default (deny, and Continue), `hard` lets a parent only deny, Stop or answer
|
|
37
|
+
plainly. A wider scope and any allow on chi's own config stay the user's. `chi send --wait`, `chi answer` and
|
|
38
|
+
`delegate_result` list what the parent may give. An invalid value warns and is `hard`. A parent's `/continue yes`
|
|
39
|
+
(`chi send ID -m '/continue yes'`, a piped `chi --attach`) is held to it too, as chi answer's.
|
|
40
|
+
- SSE chunks carry chi's normalized `counts` instead of the provider's raw `payload` (and no `content`). An external
|
|
41
|
+
SSE client reading them moves to `counts` / `text` / `thinking`; `?raw=1` on the worker's stream shows the raw form.
|
|
42
|
+
- At the top context bucket (no forget layer) the model's `[CONTEXT: …]` line asks for a short handoff note (state,
|
|
43
|
+
next step) instead of "summarize aggressively": "context critical — write a short handoff note (state, next step),
|
|
44
|
+
avoid large outputs, delegate broad work to subagents".
|
|
45
|
+
- `guardrails.parent_approvals` and `turn.parent_continue` are removed: config.yml warns about them and names
|
|
46
|
+
`guardrails.parent_answers` (`parent_approvals: once` → `soft`; `turn.parent_continue: false` → `hard`). The old
|
|
47
|
+
pair `parent_approvals: once` with `turn.parent_continue: false` (Allow once but no Continue) has no equivalent:
|
|
48
|
+
the nearest is `hard`, which leaves both to the user.
|
|
49
|
+
- The Bridge's and the relay's 403 for a refused parent answer is `parent_answer_refused`, with its `reason`
|
|
50
|
+
(was `parent_approval_refused` / `parent_continue_refused`).
|
|
51
|
+
- The guardrails bundle's asks before answering chi's questions around `chi answer` (`chi-answer-piped`: `chi
|
|
52
|
+
--attach` or `chi -p` fed from a pipe or a file; `chi-answer-http`: `curl …/answer`) are the user's alone: a parent
|
|
53
|
+
agent's Allow is refused, as on chi's own config (guardrails bundle 0.9.2: its comment says so).
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
|
|
57
|
+
- `chi send --wait` no longer times out when a fallback input file carries a session command: the command's completion is recorded as that input's terminal outcome.
|
|
58
|
+
- An image-only prompt sent from an attached terminal is no longer echoed again as an image line when its turn starts.
|
|
59
|
+
- `chi send --queue --wait` (and a wait for a turn by its id) no longer waits until its timeout when the worker dies
|
|
60
|
+
in the middle of that turn: once the next worker settles it, the wait ends `canceled` with
|
|
61
|
+
`cancel_reason: worker_stopped` ("its worker exited mid-turn"). Another send's wait is not ended by it.
|
|
62
|
+
- `chi web`'s end-of-turn re-read of the answer could keep a plugin's file ref outside the session's folder when
|
|
63
|
+
neither the worker nor the session hub named the folder (an older worker): it now takes the folder from the session
|
|
64
|
+
file, as a reload does, and drops the answer's file refs when no folder is known.
|
|
65
|
+
|
|
66
|
+
Update with `chi update` (the system bundle 0.86.0, core 0.3.3, guardrails 0.9.2, cost-cap 0.2.0, dev 0.6.0 with the new ruby
|
|
67
|
+
bundle 0.1.0), then restart `chi web`.
|
|
68
|
+
|
|
11
69
|
## [0.85.0] - 2026-10-18
|
|
12
70
|
|
|
13
71
|
### Added
|
|
@@ -3408,7 +3466,8 @@ and long-lived sessions.
|
|
|
3408
3466
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
3409
3467
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
3410
3468
|
|
|
3411
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
3469
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.86.0...HEAD
|
|
3470
|
+
[0.86.0]: https://github.com/dm1try/samagotchi/compare/v0.85.0...v0.86.0
|
|
3412
3471
|
[0.85.0]: https://github.com/dm1try/samagotchi/compare/v0.84.0...v0.85.0
|
|
3413
3472
|
[0.84.0]: https://github.com/dm1try/samagotchi/compare/v0.83.0...v0.84.0
|
|
3414
3473
|
[0.83.0]: https://github.com/dm1try/samagotchi/compare/v0.82.0...v0.83.0
|
data/docs/architecture.md
CHANGED
|
@@ -245,10 +245,33 @@ process that already owns the `Engine`); every worker starts it, and it exposes:
|
|
|
245
245
|
too-old reconnects, and cursors from another worker's epoch, receive a `reset` marker carrying
|
|
246
246
|
`session_state_snapshot`. `?snapshot=1` joins with a snapshot frame instead of a replay;
|
|
247
247
|
`?client_id=` names whose stream it is (`Bridge#open_streams_except`, used by `POST /exit`).
|
|
248
|
+
Each event goes out as clients get it (`Bridge::ClientEvent.project`, in `SSEWriter#write_event`, live
|
|
249
|
+
and replayed alike); only a `generation_chunk` changes, to chi's own format (the chunk contract below).
|
|
250
|
+
`?raw=1` writes events as the engine emitted them, for debugging on the worker's port: `chi web`'s
|
|
251
|
+
`/api/sessions/:id/stream` never passes it on (`Web::App#stream_query`).
|
|
248
252
|
An attached terminal's stream (`EventStream` with `rediscover:`) looks for the session's live
|
|
249
253
|
worker whenever it drops: a new one (a restart) is followed from its snapshot, and the terminal
|
|
250
254
|
sends its requests there (`worker_changed`); it gives up after ~12 s, or at once when the session
|
|
251
255
|
was stopped.
|
|
256
|
+
|
|
257
|
+
The wire chunk (the contract; the engine's own event keeps the provider's `payload` and the raw `content`):
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
event: generation_chunk
|
|
261
|
+
data: {"type":"generation_chunk","iteration":2,"text":"…","thinking":"",
|
|
262
|
+
"tool_call":true, // only when set
|
|
263
|
+
"counts":{"prompt_tokens":489,"completion_tokens":12,
|
|
264
|
+
"total_tokens":501,"context_window_tokens":32768}, // only when the server reported counts
|
|
265
|
+
"event_seq":812}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`counts` is `ContextUsage.normalize` of the provider's payload without `ctx_pct` (normalize computes it
|
|
269
|
+
without the session's LLM context budget; a client counts `total_tokens` against the window or budget, as
|
|
270
|
+
`ContextStatus#generation_done` does for the TUI) and with its nil keys left out: cumulative for the
|
|
271
|
+
request, a missing key means unknown (never 0), `prompt_tokens` includes cached tokens, and
|
|
272
|
+
`context_window_tokens` is there only when the payload reported a window itself (llama.cpp's `/completion`
|
|
273
|
+
doesn't: the client uses `generation_started`'s). Unknown provider fields never cross; a field is added here
|
|
274
|
+
when a client needs it, never as a catch-all bag. Details: [internals/context-telemetry.md](internals/context-telemetry.md).
|
|
252
275
|
- `POST /session/:id/turn` — fire-and-forget turn creation; returns `202` with an `enqueued_id`
|
|
253
276
|
(delivery is at-least-once via the worker's file-IPC input path — it never calls `run_turn`
|
|
254
277
|
across the HTTP boundary). Only the bridge's own session: another id, in the path or the body's
|
|
@@ -270,8 +293,11 @@ process that already owns the `Engine`); every worker starts it, and it exposes:
|
|
|
270
293
|
arrives as `:recap_ready`. Answers mid-turn too.
|
|
271
294
|
- `POST /session/:id/answer` — answer the pending question; `200`, `409` when another client
|
|
272
295
|
answered first or it is gone, `400` for an invalid selection. With `client_id: "cli:answer"`
|
|
273
|
-
(`chi answer`, a parent agent)
|
|
274
|
-
`
|
|
296
|
+
(`chi answer`, a parent agent) the answer is checked by `Guardrails::ParentPolicy` in
|
|
297
|
+
`QuestionDesk#answer`: the question carries each option's effect (`effects`, set by its asker:
|
|
298
|
+
`Approval.payload`, `ContinueOffer`, `Relay.card`; derived for an untagged one) and `user_only`,
|
|
299
|
+
and an option beyond the worker's `guardrails.parent_answers` is `403 parent_answer_refused`
|
|
300
|
+
(with its `reason`), the question still open. `chi answer` makes the same check first.
|
|
275
301
|
- `POST /session/:id/question/dismiss` — leave the question unanswered (an approval: denied);
|
|
276
302
|
`200`, or `409` when it is no longer pending.
|
|
277
303
|
- `POST /session/:id/tasks/stop` — `{task_id}`: stop a background task as the user
|
|
@@ -295,7 +321,7 @@ process that already owns the `Engine`); every worker starts it, and it exposes:
|
|
|
295
321
|
pending question's `relayed_to` mark (`QuestionDesk#annotate`, `:question_relay`); `answered`
|
|
296
322
|
makes the child ask its parent's Bridge for the answer (`RelayVerifier`) and take it only for
|
|
297
323
|
this child and the question pending now. `200`, `409` no longer pending, `403` a parent agent's
|
|
298
|
-
|
|
324
|
+
pick beyond the child's own `guardrails.parent_answers` (`parent_answer_refused`), `422 relay_unverified` (the question
|
|
299
325
|
stays open).
|
|
300
326
|
- `POST /session/:id/relay/status` — on a parent's worker, `{relay_id}`: what its `RelayDesk`
|
|
301
327
|
(memory only) holds for that relay (`child_id`, `child_question_id`, `state`, `answer`, `by`);
|
|
@@ -369,7 +395,8 @@ The page's frequent reads of `GET /api/sessions/:id` stay light too:
|
|
|
369
395
|
The page binds an answer's `display_refs` to its bubble (`answer_refs.js`: on a reload's render and on this
|
|
370
396
|
read's re-render) and pairs them with the bubble's links and text before the `path:line` scan. A file ref outside the
|
|
371
397
|
session's folder is dropped, as a reload drops it: the folder `/tail` names, else (an older worker) the hub's
|
|
372
|
-
session list entry's
|
|
398
|
+
session list entry's, else (refs to check, no hub entry) the session file's; with no folder known at all, every
|
|
399
|
+
file ref is dropped rather than shown unchecked.
|
|
373
400
|
A plugin tool's row refs (`refs`, `RowRefs`) ride its tool events and, on a reload, its part (saved as
|
|
374
401
|
`tool_refs`); `turn_view.js` binds them to the row's title (`refs.js bindRowRefs`: the first on the title,
|
|
375
402
|
the others in its menu).
|
|
@@ -446,7 +473,9 @@ both go through `ToolRunner` (events, hooks, veto, output cap) and
|
|
|
446
473
|
chat `tool_calls`) are built by one table, `Tools::BuiltinCalls`, from the
|
|
447
474
|
parsed `{name, args}` (derived from `TOOL_SCHEMAS`), so a call looks the same to
|
|
448
475
|
hooks and tools whichever model made it. Both loops' `generation_chunk` carries
|
|
449
|
-
`thinking:`, `text:` and `
|
|
476
|
+
`thinking:`, `text:`, `content:` and the provider's `payload:` (the Bridge projects it for its
|
|
477
|
+
clients: `text`, `thinking`, `tool_call` and chi's `counts`, no `payload` or `content`; see the
|
|
478
|
+
Bridge's stream above): the chat loop's thinking is the
|
|
450
479
|
server's `reasoning_content`; the raw-prompt loop splits each generation's
|
|
451
480
|
stream with a fresh `ThoughtStreamSplitter` (Qwen's `<think>` and Gemma's
|
|
452
481
|
`<|channel>thought … <channel|>` are thinking, tool-call bodies are dropped
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Writing a bundle
|
|
2
|
+
|
|
3
|
+
Read this first when someone asks for new chi functionality "as a bundle". It is the short path: the loop, the
|
|
4
|
+
files, what a hook sees, how to test, and what goes wrong. The full references are in this same `docs/` folder:
|
|
5
|
+
[plugins.md](plugins.md) (the `chi.*` API and `ctx`) and [hooks.md](hooks.md) (every event's fields).
|
|
6
|
+
|
|
7
|
+
## The loop
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
chi bundle new my-bundle # ./my-bundle: manifest.yml, plugin.rb, test/my_bundle_test.rb, README.md
|
|
11
|
+
cd my-bundle # edit plugin.rb and the test
|
|
12
|
+
chi bundle test # the tests, on chi's own Ruby and lib (exit status: the tests')
|
|
13
|
+
chi bundle check --fix # manifest, files, shas (--fix rewrites them), requires_chi, install + load in a sandbox
|
|
14
|
+
chi bundle install . # into the user's chi; a NEW session loads it (a running one doesn't)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`check` prints one finding per line, `error|warn|info CODE file[:line]: message (fix: hint)`, and exits 1 on any
|
|
18
|
+
error. Run it after every edit: an install takes exactly what it checks. It installs into a temp sandbox, not
|
|
19
|
+
the user's config or state, but `check` and `test` run the bundle's plugin and hooks in their own process, as
|
|
20
|
+
written: run them on code you'd install.
|
|
21
|
+
|
|
22
|
+
## The files
|
|
23
|
+
|
|
24
|
+
```yaml
|
|
25
|
+
# manifest.yml
|
|
26
|
+
name: my-bundle # a plain name; chi bundle install takes it from here
|
|
27
|
+
version: 0.1.0
|
|
28
|
+
scope: system
|
|
29
|
+
description: "What it adds, in one line"
|
|
30
|
+
requires_chi: ">= 0.85.0" # the chi it needs (new writes the running one; check warns when a call needs newer)
|
|
31
|
+
plugin:
|
|
32
|
+
file: plugin.rb
|
|
33
|
+
sha256: sha256:<hex> # `chi bundle check --fix` fills it; never compute it by hand
|
|
34
|
+
# files: # memories it installs (top-level *.md); without files: every *.md but README & co.
|
|
35
|
+
# my_notes.md: sha256:<hex>
|
|
36
|
+
# hooks: # hooks/*.rb files (a plugin's chi.on is usually simpler)
|
|
37
|
+
# needs: [gh] # outside commands it relies on
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`plugin.rb` defines `class Plugin` with `register(chi)`; `initialize(settings)` (optional) gets config.yml
|
|
41
|
+
`bundles: my-bundle:` as a Hash with string keys, once, when the plugin loads. A value a session may set
|
|
42
|
+
(`chi --set my-bundle.KEY=V`, listed in the manifest's `session_settings:`) is read from `ctx.settings` at call
|
|
43
|
+
time. `chi bundle check --set KEY=VALUE` gives the sandboxed load a setting.
|
|
44
|
+
|
|
45
|
+
## What a hook sees
|
|
46
|
+
|
|
47
|
+
`chi.on(event) { |event, ctx| … }` gets a Hash. The events, in a turn's order: `session_start`, `before_turn`,
|
|
48
|
+
`before_generation`, `generation_progress`, `after_generation`, `before_tool_call`, `after_tool_call`,
|
|
49
|
+
`after_turn`, `session_end` (the fields of each: [hooks.md, Hook Events](hooks.md#hook-events)). A symbol not in
|
|
50
|
+
that list is never fired (`check` warns). The two a bundle wants most, for an `execute`:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
# before_tool_call: vote on the call before it runs
|
|
54
|
+
{ type: :before_tool_call, iteration: 1,
|
|
55
|
+
call: { name: "execute", content: "rm -rf build" }, params: "execute rm -rf build",
|
|
56
|
+
guardrail: verdict, # event[:guardrail].deny!("why") / .ask!("why"); ctx.stop_turn denies and stops the turn
|
|
57
|
+
context: { cwd: "/work", repo_root: nil, branch: nil, session_id: "…", interface: :worker, origin: nil },
|
|
58
|
+
targets: { command: "rm -rf build", paths: [], cwd: "/work", repo_root: nil, outside_repo: false, git_dirs: [] },
|
|
59
|
+
blocked: false, block_reason: nil }
|
|
60
|
+
|
|
61
|
+
# after_tool_call: what it did
|
|
62
|
+
{ type: :after_tool_call, iteration: 1, tool: "execute", status: "error", # "ok" | "error" | "blocked" | "stopped"
|
|
63
|
+
call: { name: "execute", content: "make test" }, elapsed_ms: 812,
|
|
64
|
+
result: "stdout:\nok\n\nstderr:\n1 failed\n\nexit: 1", # the tool's own text, never cut
|
|
65
|
+
output: "[execute]\nstdout:\n…" } # what the model reads: may be cut
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Match on `result:`, not `output:`. An execute's result is its `stdout:` and `stderr:` blocks (each left out when
|
|
69
|
+
empty), then `exit: N` (`exit: 0 (no output)` when both were empty); a non-zero exit makes `status:` `"error"`.
|
|
70
|
+
Act through `ctx`: `ctx.notify(text, level: :warn)`, `ctx.steer(text)` (a line the model reads before its next
|
|
71
|
+
step), `ctx.card(…)`, `ctx.stop_turn(reason)`, `ctx.ask_user(…)`, `ctx.data_dir` (the bundle's own folder),
|
|
72
|
+
`ctx.cwd`, `ctx.log`. In a test, each recorded notice, steer or stop names its hook as `"plugin.rb (bundle
|
|
73
|
+
my-bundle)"`, the plugin's label (a `hooks/x.rb` file's is `"x.rb (bundle my-bundle)"`).
|
|
74
|
+
|
|
75
|
+
## Testing it
|
|
76
|
+
|
|
77
|
+
`chi bundle new` writes a Minitest test that passes as written: copy its shape. The kit (`samagotchi/testing`)
|
|
78
|
+
loads the bundle's source through chi's own loaders, in a sandbox (temp HOME, config and state), and records what
|
|
79
|
+
it did at chi's edges:
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
bundle = load_bundle(BUNDLE, settings: { "greeting" => "hi" }) # in a Samagotchi::Testing::Case test
|
|
83
|
+
bundle.command("/my-bundle chi") # → what the command returned
|
|
84
|
+
bundle.fire(:after_tool_call, tool: "execute", status: "error", result: "exit: 1 (no output)", call: { … })
|
|
85
|
+
bundle.tool_call({ name: "execute", content: "rm -rf /" }).deny? # before_tool_call hooks, through the real gate
|
|
86
|
+
bundle.tool("my_tool", path: "a.txt") # a chi.tool, as the model calls it
|
|
87
|
+
bundle.notices, bundle.steers, bundle.cards, bundle.stops, bundle.questions # what it did
|
|
88
|
+
bundle.answer({ selected: "yes" }); bundle.model_answers << "text" # ask_user / ask_model answers
|
|
89
|
+
bundle.http.stub(:get, "https://api.example/x", json: { ok: true }) # ctx.http, never the network
|
|
90
|
+
bundle.set(cwd: dir, running: false); sandbox.config(hash); sandbox.fake_executable("gh", "echo '{}'")
|
|
91
|
+
bundle.install # installed as chi installs it: warnings, load failures
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The full list is in [plugins.md, Testing a bundle](plugins.md#testing-a-bundle-experimental). The kit is
|
|
95
|
+
experimental (it may change before chi 1.0). If a test needs a fake of chi's own (a stub of a `Samagotchi::`
|
|
96
|
+
class, a hand-built `ctx`), that is a gap in the kit: say so to the user rather than reaching into chi.
|
|
97
|
+
|
|
98
|
+
## Pitfalls
|
|
99
|
+
|
|
100
|
+
- **Shas.** Every file the manifest names has a sha256 line, and an edit makes it stale: the install then warns
|
|
101
|
+
of a checksum mismatch, and a line with no sha installs unchecked. `chi bundle check --fix` rewrites them; run it
|
|
102
|
+
after the last edit.
|
|
103
|
+
- **requires_chi.** Use the chi the user runs (`chi --version`). `check` warns when the plugin calls something
|
|
104
|
+
newer than the floor (`ctx.http` needs 0.80.0, `ctx.cost` 0.83.0).
|
|
105
|
+
- **trust_level.** Leave it out. `reviewed` / `trusted` are for someone who reviewed the bundle, not its author.
|
|
106
|
+
- **Restart.** A session loads bundles when it starts: after an install or a settings change, the user starts a
|
|
107
|
+
new session (or `chi sessions restart ID`).
|
|
108
|
+
- **chi's internals.** A bundle may use `chi.*`, `ctx` and the names
|
|
109
|
+
[plugins.md, Stable for bundles](plugins.md#stable-for-bundles) lists; any other `Samagotchi::` name may change
|
|
110
|
+
in any release (`check` warns: `boundary`).
|
|
111
|
+
- **Load errors.** A plugin that raises at load is skipped and the session goes on: `check` shows the error at its
|
|
112
|
+
`plugin.rb:LINE`.
|
|
113
|
+
|
|
114
|
+
## Verifying it live
|
|
115
|
+
|
|
116
|
+
After `chi bundle install .`, one real session shows it works with the user's chi:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
chi send --new --wait --format json --dir /tmp/try -m "/my-bundle chi" # the JSON names the session id
|
|
120
|
+
grep plugin_loaded ~/.local/state/samagotchi/samagotchi.log | tail -1 # bundle=my-bundle commands=1 hooks=1
|
|
121
|
+
chi sessions delete --force SESSION_ID # leave no test session behind
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
(`$XDG_STATE_HOME/samagotchi/samagotchi.log` when `XDG_STATE_HOME` is set.) Then tell the user what it adds,
|
|
125
|
+
how to use it, and that a new session picks it up.
|
data/docs/cli.md
CHANGED
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
- `chi note [--source NAME] [-m TEXT] (ID|PREFIX)... | --all` — add a context note (TEXT or stdin) to sessions: background the model sees on its next turn; it starts no turn (see [Sessions: Context notes](sessions.md#context-notes))
|
|
20
20
|
- `chi context <add|push|ls|show|refresh|rm|mute|unmute> …` — attach live external text to sessions (a command chi runs every so often, or text pushed in); the model gets a short note when it changes and reads it with `context_read`; `chi context add <URL>` attaches a GitHub PR with the github-pr bundle (see [Attached context](context.md))
|
|
21
21
|
- `chi send [-m TEXT] [--image PATH]... [--cut | --queue] (ID|PREFIX)...` — send a message to sessions as if typed there: a turn starts (or a running one takes it at its next step; `--cut` asks it to cut long thinking for it; `--queue` runs it as a turn of its own after the running one, and `--queue --wait` waits for that turn's own answer); piped stdin goes above `-m` as quoted context, and `--image` attaches images (see [Sessions: Sending a message](sessions.md#sending-a-message)); `--new` starts a session with it instead (`--new --continues ID|last:ID` the next link of that session's chain, see [Session chains](sessions.md#session-chains)), and `--wait` prints the answer (`--wait ID` with no message waits for the next reply without sending — to an idle session whose last turn already ended, that ended turn's reply or end comes back; `--wait --turn T ID` with no message waits for exactly turn T, whether running, queued or last ended; `--format json` includes its `turn_id` when known, for waiting again after exit 3 or 4; exit 3 a question waits, its options on stderr; exit 4 `--timeout` passed with the turn still running; see [Starting a session](sessions.md#starting-a-session))
|
|
22
|
-
- `chi answer ID --question QID (--option N|LABEL)... [--text T] [--timeout S] [--format json]` (or `--dismiss`) — answer the question a session waits on (the one `chi send --wait` exited 3 with), then wait and print what comes next as `chi send --wait` does: the reply (0), the next question (3), still running after `--timeout` (4). `--option` is 1-based or the label, repeated on a multi-select question; `--text` is free text, or a Deny's reason; `--dismiss` leaves it unanswered and the model finishes its reply. A question no longer open (the web answered first) isn't answered again: it waits for that turn's reply. An option the question doesn't offer exits 2; a worker that is gone exits 1 (`send the task again: chi send --wait -m "…" ID`).
|
|
22
|
+
- `chi answer ID --question QID (--option N|LABEL)... [--text T] [--timeout S] [--format json]` (or `--dismiss`) — answer the question a session waits on (the one `chi send --wait` exited 3 with), then wait and print what comes next as `chi send --wait` does: the reply (0), the next question (3), still running after `--timeout` (4). `--option` is 1-based or the label, repeated on a multi-select question; `--text` is free text, or a Deny's reason; `--dismiss` leaves it unanswered and the model finishes its reply. A question no longer open (the web answered first) isn't answered again: it waits for that turn's reply. An option the question doesn't offer exits 2; a worker that is gone exits 1 (`send the task again: chi send --wait -m "…" ID`). What a parent may pick follows `guardrails.parent_answers` (`soft`, the default: a deny, a plain answer, Continue and "Allow once"; `standard`: no allow; `hard`: no Continue either), never a wider scope or an allow on chi's own config; a refused pick exits 1 with what to answer instead (a convention, not a security boundary; see [Guardrails](guardrails.md#answers-from-a-parent-agent))
|
|
23
23
|
- `chi desktop install|upgrade|uninstall|status` — the macOS "Send to chi" helper: a Service and a ⌃⌥⌘N hotkey that send text or images to a session (live, stopped or new) as a message (⏎, a turn runs) or a context note (⌘⏎) (see [Desktop helper](desktop.md))
|
|
24
24
|
- `chi models [--format text|json] [--timeout S] [TEXT]` — list the models every configured host offers, as the names `--model` takes (see [Listing the models](#listing-the-models))
|
|
25
25
|
- `chi self` — print version, source dir (checkout or installed gem), config/memory/session paths, model/host and bundles. Run by a session's `execute`, the `model` row (and host, loop, profile, thinking, served model) is **that session's** model, labelled `(this session <id8>; default …)`; elsewhere it is the default, `(default)`. `model key` is the memory overlay key (`<name>.<key>.md`), and `model notes` the model notes a prompt of that model loads (`model_notes_deepseek (system, 612 chars)`, `none`; inside a session its `--mute` list is left out). `chi self --model` prints only the model a new session starts on, an alias resolved to its target (the desktop helper's hint)
|
|
26
26
|
- `chi update [--dry-run] [--no-gem] [--no-bundles] [--no-desktop]` — update an installed chi: the gem, the system bundle, the shipped bundles you installed and the desktop helper, in one table (see [Updating](#updating))
|
|
27
|
-
- `chi bundle install|upgrade|uninstall|status|diff|list|build|trash` — manage memory bundles (see [Bundle hooks](hooks.md#bundle-hooks-unified-workflow-bundle)); `list` shows the installed ones and the ones shipped with chi, which `install <name>` installs; `core` and `dev` are profiles that install a set of them (see [Bundle profiles](memory.md#bundle-profiles-core-and-dev), [Guardrails](guardrails.md), [Plugins](plugins.md#the-btw-bundle), [the mcp bundle](plugins.md#the-mcp-bundle) [the loop-guard bundle](plugins.md#the-loop-guard-bundle), [the check-in bundle](plugins.md#the-check-in-bundle) and [the skills bundle](plugins.md#the-skills-bundle)). `trash` lists and empties the bundle trash (moved files from uninstalls/upgrades). A usage error (an unknown subcommand or flag, a missing argument, a bad `build --scope`) exits 2, as for the other subcommands. Plain `chi` and `chi web` exit 1 on an unknown flag, a flag missing its value or a stray argument
|
|
27
|
+
- `chi bundle install|upgrade|uninstall|status|diff|list|build|trash|new|test|check` — manage memory bundles (see [Bundle hooks](hooks.md#bundle-hooks-unified-workflow-bundle)); `list` shows the installed ones and the ones shipped with chi, which `install <name>` installs; `core` and `dev` are profiles that install a set of them (see [Bundle profiles](memory.md#bundle-profiles-core-and-dev), [Guardrails](guardrails.md), [Plugins](plugins.md#the-btw-bundle), [the mcp bundle](plugins.md#the-mcp-bundle) [the loop-guard bundle](plugins.md#the-loop-guard-bundle), [the check-in bundle](plugins.md#the-check-in-bundle) and [the skills bundle](plugins.md#the-skills-bundle)). `trash` lists and empties the bundle trash (moved files from uninstalls/upgrades). A usage error (an unknown subcommand or flag, a missing argument, a bad `build --scope`) exits 2, as for the other subcommands. Plain `chi` and `chi web` exit 1 on an unknown flag, a flag missing its value or a stray argument. `new`, `test` and `check` are for writing one: see [Writing a bundle](#writing-a-bundle-new-test-check)
|
|
28
28
|
|
|
29
29
|
### First setup
|
|
30
30
|
|
|
@@ -87,6 +87,39 @@ chi bootstrap # try localhost 8080, 11434, 1234, 8000
|
|
|
87
87
|
A bundle that fails to install makes the exit 1. `--dry-run` says what it
|
|
88
88
|
would install.
|
|
89
89
|
|
|
90
|
+
### Writing a bundle: new, test, check
|
|
91
|
+
|
|
92
|
+
The loop for a bundle you're writing (the whole path: [bundle-authoring.md](bundle-authoring.md)):
|
|
93
|
+
|
|
94
|
+
- `chi bundle new NAME [--dir DIR]` writes `DIR/NAME/` (default `./NAME`; refused when it exists; `NAME` is
|
|
95
|
+
`a-z` first, then `a-z`, `0-9`, `-`, `_`, as a slash command): `manifest.yml` (a block-form `plugin:` entry with
|
|
96
|
+
its sha filled, `requires_chi: ">= <this chi>"`), `plugin.rb` (a `/NAME` command and an `after_tool_call` hook),
|
|
97
|
+
`test/NAME_test.rb` (Minitest on the bundle test kit, passing as written) and `README.md`, then prints the next
|
|
98
|
+
steps. Exit 1 when it refuses, 2 for usage.
|
|
99
|
+
- `chi bundle test [PATH] [-- ARGS]` runs the bundle's tests on the Ruby and the lib chi runs on, outside any
|
|
100
|
+
Bundler env: `test/**/*_test.rb` on Minitest (`-r samagotchi/testing/minitest`), or else `spec/` on RSpec with
|
|
101
|
+
the kit (`--options /dev/null -r samagotchi/testing/rspec`, as `rake bundles:specs`). `ARGS` go to the runner
|
|
102
|
+
(`-- -n /name/`). Exit status: the tests'; 1 with no tests; 2 for usage, or when minitest / rspec doesn't load on
|
|
103
|
+
chi's Ruby. The tests run the bundle's code as written, with your environment (the kit sandboxes each
|
|
104
|
+
test's HOME and XDG dirs, not the process).
|
|
105
|
+
- `chi bundle check [PATH] [--fix] [--set KEY=VALUE]` (PATH defaults to `.`) checks it as an install takes it, one
|
|
106
|
+
finding per line, `error|warn|info CODE file[:line]: message (fix: hint)`, then `ok|failed: N errors, N
|
|
107
|
+
warnings`. Exit 1 on any error, 0 otherwise, 2 for usage. It installs and loads the bundle in a temp sandbox
|
|
108
|
+
(HOME, config and state), not in yours, but in chi's own process: the plugin's and hooks' code runs as written,
|
|
109
|
+
so run it (and `test`) on code you'd install. The codes, in order: `manifest` (a parse error, verbatim; the run
|
|
110
|
+
stops), `missing-file`, `unlisted` (warn: a file an install leaves out, by `MemoryFiles`' rules, so a README
|
|
111
|
+
isn't one), `sha` (a stale or placeholder sha, or a plugin / hook / script entry with no sha line; `--fix`
|
|
112
|
+
rewrites the first two and prints `fixed sha FILE → sha256:…`), `requires-chi` (this chi doesn't satisfy it:
|
|
113
|
+
error; missing on a bundle with code: warn), `requires-chi-floor` (warn: the plugin calls an API newer than the
|
|
114
|
+
oldest chi `requires_chi` admits, from `Plugin::Api::SINCE`), `trust` (warn: `trust_level: reviewed|trusted` on a
|
|
115
|
+
bundle chi doesn't ship), `clash` (warn: a name chi ships, or one installed from elsewhere; the sandboxed install
|
|
116
|
+
then forces), `install` (each Installer warning, a `needs` one as warn, and each plugin or hook load failure at
|
|
117
|
+
the source `file:line`; skipped while a placeholder sha is unfilled), `registered` (info: each command, tool,
|
|
118
|
+
hook with its priority, init, toolkit, tool source and peer source), `hook-event` (warn: a `chi.on` event chi
|
|
119
|
+
never fires), `boundary` (warn: a `Samagotchi::` name outside "Stable for bundles"; a shipped bundle's listed
|
|
120
|
+
exceptions aside) and `tests` (info: how to run them, or "no tests"). `--set KEY=VALUE` (repeatable, typed as
|
|
121
|
+
`chi --set`) goes to `bundles: <name>:` in the sandbox's config.yml.
|
|
122
|
+
|
|
90
123
|
### Listing the models
|
|
91
124
|
|
|
92
125
|
`chi models` asks every host in `hosts:` for its models, in parallel, and prints the names `--model` (and
|
|
@@ -1153,7 +1186,9 @@ Behavior notes:
|
|
|
1153
1186
|
- Stop keeps the interrupted turn's work in the conversation, as a Ctrl-C or a new prompt does, with a note for the
|
|
1154
1187
|
model that it wasn't continued (or your reason); `!rollback` still erases it.
|
|
1155
1188
|
- `--non-interactive` (`chi -p`) has nobody to ask: the turn ends there. A `chi send --wait` on a session nobody can
|
|
1156
|
-
answer (an older worker) reports `limit` (exit 1) with how to continue it: `chi send ID -m '/continue yes'
|
|
1189
|
+
answer (an older worker) reports `limit` (exit 1) with how to continue it: `chi send ID -m '/continue yes'`
|
|
1190
|
+
(not under `guardrails.parent_answers: hard`: a parent agent's `/continue yes`, sent with `chi send` or typed into a
|
|
1191
|
+
piped `chi --attach`, is held to it as `chi answer --option Continue` is, and refused there).
|
|
1157
1192
|
- The check-in bundle's card closes as the turn ends, before the step-limit question opens, so the two never stand
|
|
1158
1193
|
together; with check-in's default `after: 50` and the limit of 300 a long turn shows check-in cards (at 50, 100, …)
|
|
1159
1194
|
well before it.
|
data/docs/configuration.md
CHANGED
|
@@ -131,7 +131,8 @@ The config reader checks the file's modification time and size whenever a
|
|
|
131
131
|
setting is read. That makes a changed value available to a live reader; it
|
|
132
132
|
does not reload every object that already holds a snapshot. "Worker start"
|
|
133
133
|
includes a worker respawn. A running turn keeps the settings it already
|
|
134
|
-
resolved.
|
|
134
|
+
resolved. chi tells you when a changed setting applies only after a worker
|
|
135
|
+
or `chi web` restart.
|
|
135
136
|
|
|
136
137
|
| Key | Applies | Note |
|
|
137
138
|
|---|---|---|
|
|
@@ -144,6 +145,7 @@ resolved.
|
|
|
144
145
|
| `models.<key>.profile` | Session start or `/model` | It is resolved when that model is selected; editing it does not switch the current model's profile by itself. |
|
|
145
146
|
| Other `models.<key>.*` settings | Next turn or model lookup | Sampling, thinking, vision, context, window, price and steer settings are resolved from the file for their next use. |
|
|
146
147
|
| `thinking.level` | Next turn start | A session's own `/thinking` level is saved in that session and takes precedence; a running turn keeps its level. |
|
|
148
|
+
| `turn.max_iterations` | Next turn start | The configured step limit is resolved when each turn begins. |
|
|
147
149
|
| `cache.*` | Next request or turn-end warm-up | Cache key and TTL are read for a request; warm-up is checked after a turn. |
|
|
148
150
|
| `retry.max`, `retry.base_delay`, `retry.max_delay` | Worker start | The client's network retry policy is built with its HTTP client. |
|
|
149
151
|
| `retry.empty_answer` | Next empty-answer retry | It is checked when a turn needs to retry an empty answer. |
|
|
@@ -154,12 +156,12 @@ resolved.
|
|
|
154
156
|
| `thinking.turn_preamble`, `skip_agents_md` | Prompt rebuild | A running engine caches its built prompt; a new worker or `/model` rebuild uses the changed value. |
|
|
155
157
|
| `context.*` except `context.every_seconds`, `llm_context.*` except `llm_context.policy`, `steer.cut_after`, `memory.index_warn_tokens`, `status.line` | Next matching turn, display, poll or write | Readers resolve these settings when they perform that operation. Session-specific LLM context and thinking values remain saved in the session. |
|
|
156
158
|
| `context.every_seconds` | Next context poll | The poller checks it for each source that has no explicit interval. |
|
|
157
|
-
| `guardrails.*` | Next tool call or approval | Guardrail rules and disable lists are reloaded when the config file changes; rule settings take effect on that evaluation. |
|
|
159
|
+
| `guardrails.*` | Next tool call or approval | Guardrail rules and disable lists are reloaded when the config file changes; rule settings take effect on that evaluation. `guardrails.parent_answers` is checked when a parent answers a question. |
|
|
158
160
|
| `hooks`, `bundles` | Worker start | Hooks, plugins and their bundle settings load with the engine. |
|
|
159
161
|
| `recap.*` | Worker start | The engine builds its recap job once. |
|
|
160
162
|
| `session.shared` | Next `chi` invocation | It selects attached-worker or in-process mode for that invocation. |
|
|
161
163
|
| `session.idle_exit_minutes`, `session.keep_empty`, `session.max_children`, `session.delegate_reports`, `session.max_wakes` | Worker start or next matching lifecycle decision | Existing workers keep their idle-exit timer; the other values are read for the next corresponding decision. |
|
|
162
|
-
| `session.retention_
|
|
164
|
+
| `session.retention_*`, `session.max_count`, `session.keep_status`, `session.sweep_interval_hours` | Next retention sweep | `chi web` sweeps on its configured schedule and on `GET /api/sessions`; `chi sessions prune` uses the values for that invocation. The sweep interval is checked on the next hub tick. |
|
|
163
165
|
| `web.*` | `chi web` start | Restart `chi web` to change its bind address, port or page settings. |
|
|
164
166
|
| `log.*` | Process start | Each process holds its configured log sink and level after first use; restart that process. |
|
|
165
167
|
| `history.file` | Next history access | The TUI and web composer resolve its path when they read or append history. |
|
|
@@ -1631,7 +1633,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
|
|
|
1631
1633
|
| `guardrails.enabled` | `true` | | `false`: no rules, and hooks' asks are dropped (a deny still applies). config.yml only: a worker unsets any `SAMAGOTCHI_GUARDRAILS_*` it inherits. See [Guardrails](guardrails.md). |
|
|
1632
1634
|
| `guardrails.mode` | `auto` | | Which rules vote: `auto` leaves out the rules tagged `modes: [strict]` (in the guardrails bundle: `git rebase`, writes and git outside the session's repo); `strict` runs them all. An unknown value warns and is `auto`. config.yml only. See [Guardrails](guardrails.md#modes). |
|
|
1633
1635
|
| `guardrails.small_models` | `auto` | | Which models get the `models: small` rules: `auto` (32B or less by the size in the name, an MoE's active size), a list of globs, or `[]`. config.yml only. See [Guardrails](guardrails.md#rules-for-some-models). |
|
|
1634
|
-
| `guardrails.
|
|
1636
|
+
| `guardrails.parent_answers` | `soft` | | Which options a parent agent (`chi answer`) may pick on a session's question, by their effect: `hard` (a deny, a Stop, a plain answer), `standard` (+ Continue and other spending options), `soft` (+ "Allow once"); never a wider scope or an allow on chi's own config. An invalid value warns and is `hard`. Replaces `guardrails.parent_approvals` and `turn.parent_continue`. config.yml only: no environment variable (a parent can still pick the config dir with `XDG_CONFIG_HOME`). A convention for an honest parent, not a security boundary. See [Guardrails](guardrails.md#answers-from-a-parent-agent). |
|
|
1635
1637
|
| `log.file` | state dir | yes | See "Debug Log File". |
|
|
1636
1638
|
| `log.disable` | `false` | yes | No file logging. |
|
|
1637
1639
|
| `log.level` | `info` | yes | `debug`, `info`, `warn`, `error`. |
|
|
@@ -1675,7 +1677,6 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
|
|
|
1675
1677
|
| `steer.cut_after` | `20` | | Seconds a generation must have streamed only thinking before a message sent as a cut (`/cut TEXT`, `chi send --cut`) cuts it; other messages go in at the next step; `0` = never. `models.<key>.steer_cut_after` and `hosts.<name>.steer_cut_after` come first; see [Messages during a running turn](#messages-during-a-running-turn-steer-and-cut). |
|
|
1676
1678
|
| `models.<key>.steer_cut_after`, `hosts.<name>.steer_cut_after` | none | | A model's or host's seconds a cut waits for its thinking: whole seconds, `0` = never (e.g. a slow local thinker). `/model` shows the resolved one. See [Messages during a running turn](#messages-during-a-running-turn-steer-and-cut). |
|
|
1677
1679
|
| `turn.max_iterations` | `300` | | A turn's step limit: model ↔ tool rounds before it stops and asks to continue (an integer ≥ 1). `--no-interrupt` turns get the larger of 1000 and this. See [CLI: Iteration Limit Behavior](cli.md#iteration-limit-behavior). |
|
|
1678
|
-
| `turn.parent_continue` | `true` | | Whether a parent agent (`chi answer`) may answer Continue to a session's step-limit question; `false`: Stop only. config.yml only: no environment variable. See [Sub-agent](sub-agent.md) and [Guardrails](guardrails.md#approvals-from-a-parent-agent). |
|
|
1679
1680
|
| `update.gem` | `true` | | `false`: `chi update` never installs a newer gem (`--no-gem` for one run). See [CLI: Updating](cli.md#updating). |
|
|
1680
1681
|
| `update.bundles` | `true` | | `false`: `chi update` leaves the shipped bundles to `chi bundle upgrade` (`--no-bundles`). |
|
|
1681
1682
|
| `update.desktop` | `true` | | `false`: `chi update` leaves the desktop helper alone (`--no-desktop`). |
|
data/docs/guardrails.md
CHANGED
|
@@ -67,8 +67,9 @@ Who answers:
|
|
|
67
67
|
answerable too, the first answer wins. The parent's model sees only the
|
|
68
68
|
outcome.
|
|
69
69
|
- A parent agent running chi as a sub-agent (`chi send --wait` exits 3 with
|
|
70
|
-
the approval): `chi answer` may deny it,
|
|
71
|
-
|
|
70
|
+
the approval): `chi answer` may deny it, give "Allow once" under
|
|
71
|
+
`guardrails.parent_answers: soft` (the default; never a wider scope), or
|
|
72
|
+
leave it for the user. See [Answers from a parent agent](#answers-from-a-parent-agent).
|
|
72
73
|
|
|
73
74
|
The model gets one line on a deny. A rule's or hook's deny reads
|
|
74
75
|
`[execute] Error: denied by guardrail (rule git-push, bundle guardrails): git push publishes commits. The user was not asked. Do not retry it or reach the same result another way; ask the user how to proceed.`
|
|
@@ -99,39 +100,64 @@ with one warning, and chi starts with no stored approvals (more asks, nothing lo
|
|
|
99
100
|
`/guardrails` lists the rules and approvals; `/guardrails revoke N` removes one.
|
|
100
101
|
The file tools can't write the store.
|
|
101
102
|
|
|
102
|
-
###
|
|
103
|
+
### Answers from a parent agent
|
|
103
104
|
|
|
104
|
-
A chi parent's `delegate` children don't need any of this
|
|
105
|
-
to the user on the parent's own card (the approval relay). This section is
|
|
106
|
-
path for other agents, and for a chi parent that can't host the relay (a
|
|
107
|
-
`--no-shared` REPL, `--non-interactive`): there the model gets the
|
|
105
|
+
A chi parent's `delegate` children don't need any of this for approvals: they
|
|
106
|
+
go to the user on the parent's own card (the approval relay). This section is
|
|
107
|
+
the path for other agents, and for a chi parent that can't host the relay (a
|
|
108
|
+
`--no-shared` REPL, `--non-interactive`): there the model gets the question
|
|
108
109
|
block and the rules below. With the relay, the same rules still hold for a
|
|
109
110
|
parent model that answers its own relay card (a piped or marked `chi --attach`
|
|
110
111
|
on the parent): that answer is a parent agent's, checked by the parent and
|
|
111
112
|
again by the child.
|
|
112
113
|
|
|
113
114
|
When another agent (Claude Code, Codex, a script) runs chi with
|
|
114
|
-
`chi send --wait`,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
`chi send --wait`, a question comes back to it as exit 3 and `chi answer`
|
|
116
|
+
answers it. Every question's options carry an **effect**, set by whoever asks:
|
|
117
|
+
|
|
118
|
+
- `answer`: a plain choice (the model's own questions, an untagged plugin or
|
|
119
|
+
hook option);
|
|
120
|
+
- `deny`: Deny on an approval, Stop on the step-limit question or a plugin's
|
|
121
|
+
stop option;
|
|
122
|
+
- `spend`: more time and tokens, no new permission (Continue on the step-limit
|
|
123
|
+
question, cost-cap's Continue);
|
|
124
|
+
- `permit`: one tool call (an approval's "Allow once");
|
|
125
|
+
- `permit_wide`: more than one call (this session, this repo or directory,
|
|
126
|
+
the rule).
|
|
127
|
+
|
|
128
|
+
One setting says which effects a parent may pick:
|
|
121
129
|
|
|
122
130
|
```yaml
|
|
123
131
|
guardrails:
|
|
124
|
-
|
|
132
|
+
parent_answers: soft # hard | standard | soft (the default)
|
|
125
133
|
```
|
|
126
134
|
|
|
127
|
-
`
|
|
128
|
-
option
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
- `hard`: `deny` and `answer` only. A parent can deny an approval
|
|
136
|
+
(`--option Deny --text "why"`, `--text` alone or `--dismiss`), Stop a
|
|
137
|
+
step-limit question and answer plain questions.
|
|
138
|
+
- `standard`: also `spend`: a parent may Continue a turn (or cost-cap's cap).
|
|
139
|
+
- `soft` (the default): also `permit`: `chi answer --option "Allow once"`
|
|
140
|
+
goes through, picked by the option's scope, not its label.
|
|
141
|
+
|
|
142
|
+
A parent never picks `permit_wide`: the wider scopes stay with the web and the
|
|
143
|
+
terminal. An approval that doesn't offer "once" can't be allowed from a
|
|
144
|
+
parent, and neither can one whose offered scopes are missing or don't fit its
|
|
145
|
+
options: then only Deny goes. A refused pick exits 1 with what to do instead
|
|
146
|
+
(`only Allow once (guardrails.parent_answers: soft) can be given here: deny it
|
|
147
|
+
(--option Deny --text WHY), and tell your user`), never how to allow it. The
|
|
148
|
+
question block chi prints says what the parent may give: under `soft` an
|
|
149
|
+
approval's block lists the Allow once command next to the deny; under
|
|
150
|
+
`standard` and `hard` it says allowing is up to the user. An invalid value
|
|
151
|
+
warns and is `hard`.
|
|
152
|
+
|
|
153
|
+
`soft` suits a capable parent model: it can let a child run one more command
|
|
154
|
+
it asked about, still with every guardrail rule in force. For a weak or
|
|
155
|
+
unknown parent model, set `standard` or `hard` (and see
|
|
156
|
+
[chi-nah](#an-external-guard-chi-nah) for a deterministic guard on the calls
|
|
157
|
+
themselves).
|
|
132
158
|
|
|
133
159
|
A child that has to work in another folder (`write-outside-repo`,
|
|
134
|
-
`git-outside-repo`)
|
|
160
|
+
`git-outside-repo`) gets at most Allow once per call this way. Start it in that folder instead
|
|
135
161
|
(`chi send --new --dir PATH`), or have your user allow "rule … in this repo"
|
|
136
162
|
once on the web (it is stored for later sessions in that repo), or switch the
|
|
137
163
|
rules off: `guardrails: {disable: [write-outside-repo, git-outside-repo]}`.
|
|
@@ -140,16 +166,17 @@ Whatever the setting, a parent can't allow a call on chi's own files: a
|
|
|
140
166
|
`write`, `edit` or `execute` on the config dir (config.yml, installed bundles'
|
|
141
167
|
rules), the hooks dir or the approval store, by its rule (`chi-config`,
|
|
142
168
|
`chi-hooks`, `shell-touches-chi`), its paths or its command. "Allow once" on a
|
|
143
|
-
config.yml rewrite would allow everything from then on, so those
|
|
144
|
-
user: `chi answer` and the worker refuse the allow
|
|
145
|
-
allow it`.
|
|
169
|
+
config.yml rewrite would allow everything from then on, so those questions are
|
|
170
|
+
the user's alone (`user_only`): `chi answer` and the worker refuse the allow
|
|
171
|
+
with `only the user can allow it`. The same holds for the guardrails bundle's
|
|
172
|
+
other user-only rules (`chi-context-cmd`, `chi-broadcast`,
|
|
173
|
+
`prompt-memory-write`, `model-overlay-write`, and `chi-answer-piped` /
|
|
174
|
+
`chi-answer-http`, which answer a grandchild's question as the user).
|
|
146
175
|
|
|
147
|
-
A
|
|
148
|
-
|
|
149
|
-
`turn.parent_continue: false` (config.yml only, like `parent_approvals`)
|
|
150
|
-
makes parents stop-only. See [chi as a sub-agent](sub-agent.md#the-step-limit).
|
|
176
|
+
A plugin's or a hook's question (`ask_user`) tags its options the same way
|
|
177
|
+
(`effects:`, see [Plugins](plugins.md)); an untagged one is a plain `answer`.
|
|
151
178
|
|
|
152
|
-
The guardrails settings (`enabled`, `mode`, `small_models`, `
|
|
179
|
+
The guardrails settings (`enabled`, `mode`, `small_models`, `parent_answers`) are
|
|
153
180
|
read from config.yml only: they have no environment variable, and a worker
|
|
154
181
|
chi starts unsets every `SAMAGOTCHI_GUARDRAILS_*` it would inherit. What a
|
|
155
182
|
parent's environment does choose is the config dir: `XDG_CONFIG_HOME` picks
|
|
@@ -159,11 +186,11 @@ points at (a relative one made absolute from the parent's directory). chi
|
|
|
159
186
|
doesn't record the config dir per session.
|
|
160
187
|
|
|
161
188
|
The worker checks it too. `chi answer` marks its answers as a parent's
|
|
162
|
-
(`client_id: "cli:answer"`), and the worker's Bridge refuses such
|
|
163
|
-
beyond what the *worker's* config.yml permits (`403
|
|
164
|
-
`chi answer` exits 1 with the
|
|
165
|
-
at that moment. Answers from the web and an attached
|
|
166
|
-
|
|
189
|
+
(`client_id: "cli:answer"`), and the worker's Bridge refuses such a pick
|
|
190
|
+
beyond what the *worker's* config.yml permits (`403 parent_answer_refused`
|
|
191
|
+
with its `reason`; `chi answer` exits 1 with the line), checked against the
|
|
192
|
+
question pending at that moment. Answers from the web and an attached
|
|
193
|
+
terminal keep every option.
|
|
167
194
|
|
|
168
195
|
A parent may also type its answer into chi itself: a piped `chi --attach ID`
|
|
169
196
|
or `printf '2\n' | chi --no-shared -p …`. So chi treats an answer as a
|
|
@@ -511,7 +538,8 @@ only by the user: these change a model's system prompt for later sessions (see
|
|
|
511
538
|
`shell-touches-chi`'s text heuristic); and answering chi's
|
|
512
539
|
questions around `chi answer`: `chi --attach` or `chi -p` with stdin from a
|
|
513
540
|
pipe, a here-string or a file, not `/dev/null` (`chi-answer-piped`), and `curl`/`wget` to a
|
|
514
|
-
session's `/answer` route (`chi-answer-http`), both once or for the session
|
|
541
|
+
session's `/answer` route (`chi-answer-http`), both once or for the session, and only by the
|
|
542
|
+
user (a parent agent allowing one would answer as the user).
|
|
515
543
|
`chi answer` itself isn't asked about. It denies writes into `.git/hooks`.
|
|
516
544
|
|
|
517
545
|
In strict mode (`guardrails: { mode: strict }`) it also asks before `git
|