samagotchi 0.84.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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +80 -1
  3. data/docs/architecture.md +44 -6
  4. data/docs/bundle-authoring.md +125 -0
  5. data/docs/cli.md +54 -4
  6. data/docs/configuration.md +8 -5
  7. data/docs/guardrails.md +63 -35
  8. data/docs/hooks.md +20 -4
  9. data/docs/internals/anthropic.md +2 -2
  10. data/docs/internals/bundles.md +11 -2
  11. data/docs/internals/context-telemetry.md +19 -1
  12. data/docs/internals/engine.md +4 -3
  13. data/docs/memory.md +1 -1
  14. data/docs/plugins.md +59 -2
  15. data/docs/releasing.md +1 -1
  16. data/docs/sessions.md +8 -6
  17. data/docs/sub-agent.md +35 -24
  18. data/docs/testing.md +7 -2
  19. data/lib/samagotchi/answer_command.rb +21 -25
  20. data/lib/samagotchi/bridge/client_event.rb +50 -0
  21. data/lib/samagotchi/bridge/sse_writer.rb +6 -2
  22. data/lib/samagotchi/bridge/turn_accumulator.rb +3 -0
  23. data/lib/samagotchi/bridge.rb +76 -12
  24. data/lib/samagotchi/bridge_client.rb +14 -2
  25. data/lib/samagotchi/bundle_command/check.rb +348 -0
  26. data/lib/samagotchi/bundle_command/scaffold.rb +135 -0
  27. data/lib/samagotchi/bundle_command/test_run.rb +89 -0
  28. data/lib/samagotchi/bundle_command.rb +125 -2
  29. data/lib/samagotchi/bundles/core/manifest.yml +2 -2
  30. data/lib/samagotchi/bundles/cost-cap/manifest.yml +4 -4
  31. data/lib/samagotchi/bundles/cost-cap/plugin.rb +4 -1
  32. data/lib/samagotchi/bundles/dev/manifest.yml +2 -1
  33. data/lib/samagotchi/bundles/guardrails/guardrails/rules.yml +4 -2
  34. data/lib/samagotchi/bundles/guardrails/manifest.yml +1 -1
  35. data/lib/samagotchi/bundles/ruby/manifest.yml +11 -0
  36. data/lib/samagotchi/bundles/ruby/plugin.rb +74 -0
  37. data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
  38. data/lib/samagotchi/bundles/system/manifest.yml +3 -3
  39. data/lib/samagotchi/bundles/system/self_map.md +2 -1
  40. data/lib/samagotchi/client_id.rb +1 -1
  41. data/lib/samagotchi/config.rb +195 -115
  42. data/lib/samagotchi/context_status.rb +1 -1
  43. data/lib/samagotchi/continue_offer.rb +2 -1
  44. data/lib/samagotchi/engine.rb +5 -5
  45. data/lib/samagotchi/guardrail_wiring.rb +4 -0
  46. data/lib/samagotchi/guardrails/approval.rb +12 -2
  47. data/lib/samagotchi/guardrails/load_failures.rb +17 -3
  48. data/lib/samagotchi/guardrails/parent_approvals.rb +14 -70
  49. data/lib/samagotchi/guardrails/parent_policy.rb +258 -0
  50. data/lib/samagotchi/guardrails/verdict.rb +6 -3
  51. data/lib/samagotchi/hook_routes.rb +5 -3
  52. data/lib/samagotchi/hooks/bundle_loader.rb +3 -1
  53. data/lib/samagotchi/hooks/registry.rb +13 -6
  54. data/lib/samagotchi/hooks.rb +5 -0
  55. data/lib/samagotchi/kernel_loop.rb +10 -3
  56. data/lib/samagotchi/llm/anthropic_assembly.rb +1 -1
  57. data/lib/samagotchi/llm/chat_loop.rb +5 -1
  58. data/lib/samagotchi/log_subscriber.rb +1 -0
  59. data/lib/samagotchi/memory_bundle/shas.rb +127 -0
  60. data/lib/samagotchi/memory_bundle.rb +1 -0
  61. data/lib/samagotchi/parent_report.rb +92 -16
  62. data/lib/samagotchi/pending_question.rb +8 -4
  63. data/lib/samagotchi/plugin/api.rb +16 -0
  64. data/lib/samagotchi/plugin/context.rb +22 -12
  65. data/lib/samagotchi/plugin/loader.rb +5 -3
  66. data/lib/samagotchi/question_desk.rb +37 -24
  67. data/lib/samagotchi/queued_command.rb +5 -4
  68. data/lib/samagotchi/relay.rb +5 -1
  69. data/lib/samagotchi/relay_verifier.rb +4 -5
  70. data/lib/samagotchi/reply_wait.rb +22 -6
  71. data/lib/samagotchi/send_command.rb +34 -8
  72. data/lib/samagotchi/session_commands.rb +21 -7
  73. data/lib/samagotchi/session_inbox.rb +68 -0
  74. data/lib/samagotchi/terminal_ui/attach_launcher.rb +1 -1
  75. data/lib/samagotchi/terminal_ui/attached_loop.rb +102 -12
  76. data/lib/samagotchi/terminal_ui/thinking_line.rb +5 -9
  77. data/lib/samagotchi/terminal_ui.rb +15 -9
  78. data/lib/samagotchi/testing/boundary.rb +0 -3
  79. data/lib/samagotchi/testing/bundle.rb +7 -0
  80. data/lib/samagotchi/testing/host.rb +6 -4
  81. data/lib/samagotchi/testing/install.rb +119 -0
  82. data/lib/samagotchi/testing/recorder.rb +13 -4
  83. data/lib/samagotchi/testing.rb +1 -0
  84. data/lib/samagotchi/tools/builtins.rb +2 -1
  85. data/lib/samagotchi/tools/delegate_wait.rb +6 -1
  86. data/lib/samagotchi/tools/task_runtime.rb +5 -3
  87. data/lib/samagotchi/turn_checkpoint.rb +64 -2
  88. data/lib/samagotchi/turn_flow.rb +10 -0
  89. data/lib/samagotchi/version.rb +1 -1
  90. data/lib/samagotchi/web/app.rb +76 -10
  91. data/lib/samagotchi/web/public/app.js +17 -0
  92. data/lib/samagotchi/web/public/bubbles.js +9 -0
  93. data/lib/samagotchi/web/public/chunk_router.js +8 -19
  94. data/lib/samagotchi/web/public/commands.js +1 -0
  95. data/lib/samagotchi/web/public/ctx.js +12 -26
  96. data/lib/samagotchi/web/public/data.js +11 -0
  97. data/lib/samagotchi/web/public/index.html +9 -0
  98. data/lib/samagotchi/web/public/stage_view.js +6 -0
  99. data/lib/samagotchi/web/public/stream_handlers.js +4 -1
  100. data/lib/samagotchi/web/public/turn_events.js +4 -0
  101. data/lib/samagotchi/web/public/turn_html.js +9 -1
  102. data/lib/samagotchi/web/public/unqueue.js +56 -0
  103. data/lib/samagotchi/web/server.rb +4 -0
  104. data/lib/samagotchi/worker.rb +19 -5
  105. data/lib/samagotchi/worker_inbound.rb +4 -4
  106. metadata +12 -2
  107. data/lib/samagotchi/guardrails/parent_continue.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5e180d3ef3bc5dd32bd646d471b1ef88e11083aba16f6908a8c4588b0173b4c
4
- data.tar.gz: b337e5690f3094d5f3b0e8528aacbedab734211c9be60ed5ff314f6eb4299ea7
3
+ metadata.gz: 9bd5a2287b8113de9eb91acc1a735e6e132f339dd1569567e7cec6e1bea6637a
4
+ data.tar.gz: 2cfb2f0a9cc14bb226e227fcced1ce2efb16268707953423bd1db991070e36d5
5
5
  SHA512:
6
- metadata.gz: 4ce619eccbfc69729b160a2b19c65d3b8e91d0f2b641fb6d4eb288d8fd12e9a147529745a8a3b5272270a2fabec6e597f423086c6574cb06f689816b32550568
7
- data.tar.gz: 4a9922290d92cabab3aac30f17292119cc6e778243a7e1b57bd8260423a27446b34b978346056566619f8e358da8dabbd9e80f8bc3aa9fc198dab99e9b27b38c
6
+ metadata.gz: 3d5c8b88e0d4ab6fbebdb80d1705ae2904d6b5ac59b463099c9101f22161a912cbe56fe93da7cdcef672f62cc4162d212325c884f66a49aa27385a9aa71ba160
7
+ data.tar.gz: 3a54cc7c7629d902d1857e85b2f6fa43d2fb36805bf85ac733bfa4fba614c7a9488080dd40633c40e94ccae0749fdcce4f05c3fc7888b6e65931cd5cd492477d
data/CHANGELOG.md CHANGED
@@ -8,6 +8,83 @@ 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
+
69
+ ## [0.85.0] - 2026-10-18
70
+
71
+ ### Added
72
+
73
+ - A message queued for after the running turn can be taken back before it runs: the × on its bubble in the web,
74
+ `/unqueue` in an attached terminal (its newest queued line). Its text comes back into the input to change and send
75
+ again. Every UI drops it, and a `chi send --queue --wait` on it ends with `removed` (exit 1). `/queue` is now listed
76
+ in the attached terminal's Tab and `/help` too.
77
+
78
+ ### Fixed
79
+
80
+ - On a phone, a queued message's text gets the bubble's full width, with its origin and after-turn badge above it.
81
+ - A plugin's `ctx.settings` reads a session's `--set` values again after a failed read, instead of keeping config.yml's
82
+ alone until the worker restarts.
83
+ - A `before_generation` hook now runs before the generation starts (`:generation_started`) in both loops: a question
84
+ it asks (the cost-cap's) no longer counts in the generation's time or leaves an empty generation on Stop.
85
+
86
+ Update with `chi update` (the system bundle 0.85.0), then restart `chi web`.
87
+
11
88
  ## [0.84.0] - 2026-10-18
12
89
 
13
90
  ### Added
@@ -3389,7 +3466,9 @@ and long-lived sessions.
3389
3466
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
3390
3467
  hotkey panel that send selected text or the clipboard to your sessions.
3391
3468
 
3392
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.84.0...HEAD
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
3471
+ [0.85.0]: https://github.com/dm1try/samagotchi/compare/v0.84.0...v0.85.0
3393
3472
  [0.84.0]: https://github.com/dm1try/samagotchi/compare/v0.83.0...v0.84.0
3394
3473
  [0.83.0]: https://github.com/dm1try/samagotchi/compare/v0.82.0...v0.83.0
3395
3474
  [0.82.0]: https://github.com/dm1try/samagotchi/compare/v0.81.0...v0.82.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) an allow on an approval beyond the worker's
274
- `guardrails.parent_approvals` is `403 parent_approval_refused`, the question still open.
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
@@ -281,12 +307,21 @@ process that already owns the `Engine`); every worker starts it, and it exposes:
281
307
  saved messages, or the running turn's accumulator); answers once the
282
308
  task is gone: `200 {status, stop_reason, task_id}`, `404 task_not_found`, `409 not_running`.
283
309
  The worker names it in its sidecar features (`task_stop`).
310
+ - `POST /session/:id/turn/dequeue` — `{enqueued_id, client_id?}`: take back a queued message
311
+ (one that waits for the running turn's end: `--queue`, Alt+Enter, `/queue TEXT`, or a message
312
+ with images) before a turn takes it (web route `POST /api/sessions/:id/turn/:enqueued_id/dequeue`,
313
+ the × on a queued bubble; `/unqueue` in the attached TUI). Under the event log, like its enqueue:
314
+ `SessionInbox.take_queued_input` claims the file as the drain does (one rename wins), deletes it,
315
+ leaves a tombstone (`input/removed/<enqueued_id>`, for `ReplyWait`'s `turn:`), and the Bridge
316
+ announces `:turn_dequeued`. `200 {status: "removed", enqueued_id, prompt}`, `409 already_started`
317
+ (a turn took it), `409 not_queued` (a next-step message: a drain may merge it any moment), `404
318
+ unknown_enqueued_id`. It never wakes the worker. The worker names it in its sidecar features (`unqueue`).
284
319
  - `POST /session/:id/relay` — the approval relay, on a delegated child's worker
285
320
  (`{action, relay_id, question_id}`): `opened` / `closed` (with a `reason`) set or clear the
286
321
  pending question's `relayed_to` mark (`QuestionDesk#annotate`, `:question_relay`); `answered`
287
322
  makes the child ask its parent's Bridge for the answer (`RelayVerifier`) and take it only for
288
323
  this child and the question pending now. `200`, `409` no longer pending, `403` a parent agent's
289
- allow beyond the child's `guardrails.parent_approvals`, `422 relay_unverified` (the question
324
+ pick beyond the child's own `guardrails.parent_answers` (`parent_answer_refused`), `422 relay_unverified` (the question
290
325
  stays open).
291
326
  - `POST /session/:id/relay/status` — on a parent's worker, `{relay_id}`: what its `RelayDesk`
292
327
  (memory only) holds for that relay (`child_id`, `child_question_id`, `state`, `answer`, `by`);
@@ -360,7 +395,8 @@ The page's frequent reads of `GET /api/sessions/:id` stay light too:
360
395
  The page binds an answer's `display_refs` to its bubble (`answer_refs.js`: on a reload's render and on this
361
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
362
397
  session's folder is dropped, as a reload drops it: the folder `/tail` names, else (an older worker) the hub's
363
- 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.
364
400
  A plugin tool's row refs (`refs`, `RowRefs`) ride its tool events and, on a reload, its part (saved as
365
401
  `tool_refs`); `turn_view.js` binds them to the row's title (`refs.js bindRowRefs`: the first on the title,
366
402
  the others in its menu).
@@ -404,7 +440,7 @@ session every 10 s, so a `kill -9` shows within a second. The summary (`Web::Ses
404
440
  shared with `/api/sessions` and the session view) carries `owner`, `project_root` and
405
441
  `bridge_up` (the sidecar is there *and* the lock is held: the page attaches its stream on it), and
406
442
  from that sidecar `worker_version` (the chi the worker runs) and `worker_features`
407
- (`Bridge::FEATURES`, what a client may ask of it beyond the routes: `restart`, `task_stop`, `reparent`,
443
+ (`Bridge::FEATURES`, what a client may ask of it beyond the routes: `restart`, `task_stop`, `reparent`, `unqueue`,
408
444
  `delivery`, a worker that queues a message for after the turn; `SessionManager.deliver_turn` and
409
445
  the attached TUI refuse a queue to a worker without it, which would steer; `turn_ids`, a worker whose running
410
446
  turn's mark, continue turn and Stop carry the turn's `enqueued_id`, which `chi answer`, `chi send --wait` with no
@@ -437,7 +473,9 @@ both go through `ToolRunner` (events, hooks, veto, output cap) and
437
473
  chat `tool_calls`) are built by one table, `Tools::BuiltinCalls`, from the
438
474
  parsed `{name, args}` (derived from `TOOL_SCHEMAS`), so a call looks the same to
439
475
  hooks and tools whichever model made it. Both loops' `generation_chunk` carries
440
- `thinking:`, `text:` and `content:` (both): the chat loop's thinking is the
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
441
479
  server's `reasoning_content`; the raw-prompt loop splits each generation's
442
480
  stream with a fresh `ThoughtStreamSplitter` (Qwen's `<think>` and Gemma's
443
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`). An approval can be denied, not allowed, unless `guardrails.parent_approvals: once` (a convention, not a security boundary; see [Guardrails](guardrails.md#approvals-from-a-parent-agent))
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
@@ -607,6 +640,17 @@ REPL alike:
607
640
  sent after it still go in at the next step.
608
641
  At the open prompt (no turn running) `/cut TEXT` and `/queue TEXT` run TEXT
609
642
  as a normal prompt.
643
+ - `/unqueue` (attached terminal) takes back the newest line this terminal
644
+ queued that hasn't started: `removed: <its first 60 characters>`, and its text
645
+ goes back into the input to change and send again (not over typed text: then
646
+ it is in the input history, ↑; not with input from a pipe; its images don't
647
+ come back), then the one before it on the next `/unqueue`; `(nothing queued: …)` when none waits,
648
+ `(not removed: it already started)` when its turn won the race, `(not removed:
649
+ it is already gone)` when another client removed it. Other terminals that
650
+ showed it say `(a queued message was removed)`; the web drops its bubble. A
651
+ worker older than it is not asked: `(/unqueue needs a newer worker: …)`. In
652
+ the plain REPL it answers with a note (its own queue is not touched), and the
653
+ web's composer points at the × on the bubble.
610
654
  - **The web composer** has a row above the text field in a session (always
611
655
  there, so the composer never changes height): the keys while idle, and while
612
656
  the turn runs the delivery line, where a message sent now goes in (`↳ goes in after this
@@ -616,7 +660,11 @@ REPL alike:
616
660
  **Alt+Enter** (Option+Enter) or `queue for after the turn` queues it, like
617
661
  `/queue TEXT`, and the bubble is dashed (`after this turn`), below the
618
662
  running turn's card with the commands queued for its end, until its turn
619
- starts; `cut in now` cuts, like `/cut TEXT` (by click only: it throws the
663
+ starts; its **×** (`Remove from queue`, once the worker acked it) takes it
664
+ back before it runs, in every tab (a toast says why when it can't: it
665
+ already started, it is gone, no live worker), and puts its text back into an
666
+ empty composer to change and send again (a draft stays: the text is then in
667
+ the toast; images don't come back); `cut in now` cuts, like `/cut TEXT` (by click only: it throws the
620
668
  thinking away). Cut is enabled only while the step has streamed nothing but
621
669
  thinking and cutting is on for the model (the line says `cuts at about 0:25
622
670
  if you choose cut in now` until the thinking passes `steer_cut_after`, and
@@ -1138,7 +1186,9 @@ Behavior notes:
1138
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
1139
1187
  model that it wasn't continued (or your reason); `!rollback` still erases it.
1140
1188
  - `--non-interactive` (`chi -p`) has nobody to ask: the turn ends there. A `chi send --wait` on a session nobody can
1141
- 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).
1142
1192
  - The check-in bundle's card closes as the turn ends, before the step-limit question opens, so the two never stand
1143
1193
  together; with check-in's default `after: 50` and the limit of 300 a long turn shows check-in cards (at 50, 100, …)
1144
1194
  well before it.
@@ -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_*` | Next retention sweep | `chi web` sweeps on its configured schedule and on `GET /api/sessions`; `chi sessions prune` uses the values for that invocation. |
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. |
@@ -1145,6 +1147,8 @@ Bridge acks `delivery: "queue"` while a turn runs (to an idle session the messag
1145
1147
  `next_step`). A worker whose sidecar doesn't name the `delivery` feature (older than queueing) would steer it, so the
1146
1148
  sender refuses it (`409 delivery_unavailable`, "restart it"), and so does a worker that answers the request with a
1147
1149
  400 `delivery_unavailable`.
1150
+ Until its turn starts, a queued message can be taken back: `/unqueue` in an attached terminal, the × on its bubble
1151
+ in the web ([sessions.md](sessions.md), *Removing a queued message*).
1148
1152
 
1149
1153
  ## Server errors
1150
1154
 
@@ -1629,7 +1633,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
1629
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). |
1630
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). |
1631
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). |
1632
- | `guardrails.parent_approvals` | `off` | | What `chi answer` lets a parent agent allow on an approval: `off` (deny only) or `once` ("Allow once", never a wider scope). 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#approvals-from-a-parent-agent). |
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). |
1633
1637
  | `log.file` | state dir | yes | See "Debug Log File". |
1634
1638
  | `log.disable` | `false` | yes | No file logging. |
1635
1639
  | `log.level` | `info` | yes | `debug`, `info`, `warn`, `error`. |
@@ -1673,7 +1677,6 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
1673
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). |
1674
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). |
1675
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). |
1676
- | `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). |
1677
1680
  | `update.gem` | `true` | | `false`: `chi update` never installs a newer gem (`--no-gem` for one run). See [CLI: Updating](cli.md#updating). |
1678
1681
  | `update.bundles` | `true` | | `false`: `chi update` leaves the shipped bundles to `chi bundle upgrade` (`--no-bundles`). |
1679
1682
  | `update.desktop` | `true` | | `false`: `chi update` leaves the desktop helper alone (`--no-desktop`). |