samagotchi 0.177.0 → 0.178.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 +44 -1
- data/docs/architecture.md +5 -4
- data/docs/cli.md +31 -6
- data/docs/guardrails.md +1 -1
- data/docs/internals/background-tasks.md +23 -2
- data/docs/internals/bridge.md +17 -6
- data/docs/internals/bundles.md +4 -3
- data/docs/internals/participants.md +8 -5
- data/docs/internals/remote-sessions.md +6 -1
- data/docs/internals/session-lifecycle.md +176 -0
- data/docs/internals/web-frontend.md +14 -6
- data/docs/internals/working-set.md +33 -6
- data/docs/plugins.md +1 -1
- data/docs/releasing.md +3 -2
- data/docs/scheduling.md +8 -1
- data/docs/sessions.md +15 -9
- data/docs/testing.md +4 -2
- data/lib/samagotchi/bridge/card_store.rb +2 -19
- data/lib/samagotchi/bridge.rb +38 -6
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/compat.rb +0 -7
- data/lib/samagotchi/engine/events.rb +43 -0
- data/lib/samagotchi/engine/session.rb +7 -0
- data/lib/samagotchi/engine.rb +9 -3
- data/lib/samagotchi/event_fanout.rb +56 -0
- data/lib/samagotchi/guardrails/approvals.rb +0 -4
- data/lib/samagotchi/memory_bundle/shipped_update.rb +1 -1
- data/lib/samagotchi/note_delivery.rb +9 -4
- data/lib/samagotchi/plugin/sessions.rb +2 -1
- data/lib/samagotchi/revise_anchor.rb +2 -0
- data/lib/samagotchi/schedules.rb +12 -5
- data/lib/samagotchi/session_access/contract.rb +4 -0
- data/lib/samagotchi/session_access/local.rb +16 -4
- data/lib/samagotchi/session_access/remote.rb +42 -9
- data/lib/samagotchi/session_archive_command.rb +38 -10
- data/lib/samagotchi/session_chain/delete.rb +98 -25
- data/lib/samagotchi/session_chain/delete_preview.rb +2 -2
- data/lib/samagotchi/session_delete_command.rb +33 -10
- data/lib/samagotchi/session_inbox.rb +29 -0
- data/lib/samagotchi/session_inbox_delivery.rb +13 -5
- data/lib/samagotchi/session_lifecycle/allowed.rb +69 -0
- data/lib/samagotchi/session_lifecycle/canonical.rb +49 -0
- data/lib/samagotchi/session_lifecycle/reading.rb +65 -0
- data/lib/samagotchi/session_lifecycle.rb +59 -0
- data/lib/samagotchi/session_manager/delivery.rb +29 -6
- data/lib/samagotchi/session_manager/lifecycle.rb +33 -39
- data/lib/samagotchi/session_manager/removal.rb +117 -25
- data/lib/samagotchi/session_manager/running_tasks.rb +334 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +22 -2
- data/lib/samagotchi/task_files.rb +37 -4
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +7 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
- data/lib/samagotchi/terminal_ui/local_link.rb +11 -3
- data/lib/samagotchi/tool_names.rb +1 -1
- data/lib/samagotchi/tools/memory.rb +29 -0
- data/lib/samagotchi/tools/task_runtime.rb +25 -6
- data/lib/samagotchi/turn_anchors.rb +5 -0
- data/lib/samagotchi/verify_anchor.rb +2 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +5 -1
- data/lib/samagotchi/web/participant_show.rb +3 -4
- data/lib/samagotchi/web/participant_view.rb +4 -6
- data/lib/samagotchi/web/public/data.js +19 -3
- data/lib/samagotchi/web/public/delete_sheet.js +67 -11
- data/lib/samagotchi/web/public/running_tasks.js +73 -0
- data/lib/samagotchi/web/public/session_actions.js +57 -8
- data/lib/samagotchi/web/public/stop_sheet.js +3 -2
- data/lib/samagotchi/web/public/working_set.js +3 -28
- data/lib/samagotchi/web/public/working_set_view.js +5 -2
- data/lib/samagotchi/web/public/ws_item_sig.js +51 -0
- data/lib/samagotchi/web/public/ws_peek.js +23 -13
- data/lib/samagotchi/web/public/ws_reader.js +22 -12
- data/lib/samagotchi/web/public/ws_sections.js +1 -0
- data/lib/samagotchi/web/public/ws_timeline.js +9 -6
- data/lib/samagotchi/web/session_control.rb +66 -16
- data/lib/samagotchi/web/session_summary.rb +7 -0
- data/lib/samagotchi/web/working_set_routes.rb +29 -8
- data/lib/samagotchi/worker_boot.rb +9 -6
- data/lib/samagotchi/worker_link.rb +9 -1
- data/lib/samagotchi/worker_presence.rb +4 -0
- data/lib/samagotchi/working_set.rb +26 -0
- data/lib/samagotchi/working_set_command.rb +10 -7
- data/lib/samagotchi/working_set_steer.rb +3 -10
- metadata +9 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 221dc2bfb6cf6d9e8d839dd49e5740b1b7e05f1f0ca77d64987418c755f2d82e
|
|
4
|
+
data.tar.gz: c26aca5d929e616c3e402b323ddd850e20d4e9193a42ebfbbe7b2f4cf9d28b8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d9caf39334981e0dbbe2417615f0db3e4c3e8a9fd8afc1e8caf63fb2de8bae2062c1ed11ef0de73145ec3aadbaee055a133e9f369eb915852fbd4d3fa9aed7d
|
|
7
|
+
data.tar.gz: 4d646ee36fbbc7880235793216ae4e5f975e5f77b794b1d39f25c7f1576eafc1388a48cc9d82fafce9386ffc45e483d4bf3c8ca73bfaac077a63f4b7dcaaf443
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,47 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.178.0] - 2026-11-20
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Deleting or archiving a session whose background tasks still run now asks first: the web names them and offers to
|
|
16
|
+
stop them and delete/archive; `chi sessions delete|archive` (and `/archive`, `/exit --delete`) refuse and name them,
|
|
17
|
+
and `--stop-tasks` stops them first. With `--remote` this needs this chi on both ends: an older chi web can't stop
|
|
18
|
+
them, an older CLI can't delete or archive such a session there.
|
|
19
|
+
- chi no longer reads a guardrail approvals.json list written by chi 0.166 and before (set aside with a warning; allow
|
|
20
|
+
again what you need), or a session's cards.json from before 0.151.0 (earlier cards don't show).
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- `chi sessions restart` no longer refuses its fallback for a background task that already ended (a record a crashed
|
|
25
|
+
worker left marked running).
|
|
26
|
+
- A background task's leftover process holding its log is stopped even when chi exits just after the task's shell
|
|
27
|
+
ends, instead of running on after a one-shot or worker exit.
|
|
28
|
+
- chi web: the working set's peek and reader show a running turn's reads while it runs, not only once the turn has
|
|
29
|
+
ended; they ask again only when the open item changed.
|
|
30
|
+
- `chi sessions restart` (and the web's restart) of a session being deleted says "the session is being deleted"
|
|
31
|
+
instead of "its worker is still starting"; a schedule's skip says the same, and for a worker on a newer chi says
|
|
32
|
+
to restart chi web or update chi, instead of "its worker is starting or leaving".
|
|
33
|
+
|
|
34
|
+
Update with `chi update`.
|
|
35
|
+
|
|
36
|
+
## [0.177.1] - 2026-11-19
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- chi web: deleting a chained session no longer deletes more than the sheet showed when something changed since it
|
|
41
|
+
opened (a delegate that finished, a schedule, a continue); the sheet shows the new plan to confirm.
|
|
42
|
+
- chi web: a participant's failed Verify turn comes back in their composer as a Verify turn, not plain text.
|
|
43
|
+
- `/working-set add system/x` is no longer refused as "already in the system prompt" when only a project memory x
|
|
44
|
+
is there (and the reverse); a bare name still matches either scope.
|
|
45
|
+
- A message sent to a session while it is being deleted is refused ("the session is being deleted") instead of being
|
|
46
|
+
reported delivered and then lost.
|
|
47
|
+
- `chi sessions restart` (and the web's restart) of a stopped session, or one being stopped, is refused at once with
|
|
48
|
+
what to do, instead of waiting for a restart that never comes.
|
|
49
|
+
|
|
50
|
+
Update with `chi update`.
|
|
51
|
+
|
|
11
52
|
## [0.177.0] - 2026-11-17
|
|
12
53
|
|
|
13
54
|
### Added
|
|
@@ -6480,7 +6521,9 @@ and long-lived sessions.
|
|
|
6480
6521
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6481
6522
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6482
6523
|
|
|
6483
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
6524
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.178.0...HEAD
|
|
6525
|
+
[0.178.0]: https://github.com/dm1try/samagotchi/compare/v0.177.1...v0.178.0
|
|
6526
|
+
[0.177.1]: https://github.com/dm1try/samagotchi/compare/v0.177.0...v0.177.1
|
|
6484
6527
|
[0.177.0]: https://github.com/dm1try/samagotchi/compare/v0.176.0...v0.177.0
|
|
6485
6528
|
[0.176.0]: https://github.com/dm1try/samagotchi/compare/v0.175.0...v0.176.0
|
|
6486
6529
|
[0.175.0]: https://github.com/dm1try/samagotchi/compare/v0.174.0...v0.175.0
|
data/docs/architecture.md
CHANGED
|
@@ -215,7 +215,7 @@ worker, and (its thin client load budgets) no turn loop, bundle updater, `tools/
|
|
|
215
215
|
|
|
216
216
|
The clients name tools and the session commands without loading them. A tool's name and the fixed texts it writes
|
|
217
217
|
into results (`Execute::HANDED_OVER`…) live in `ToolNames` (`tool_names.rb`, no requires), which the tool classes
|
|
218
|
-
read their constants from and the display code (`ToolActivity`, `ToolView`, `FileRef`, `
|
|
218
|
+
read their constants from and the display code (`ToolActivity`, `ToolView`, `FileRef`, `Objectives::Backing`) reads
|
|
219
219
|
directly. The session commands' names, the built-ins' registry and its class-level reads (`builtin_name`,
|
|
220
220
|
`builtin_registry`, `ui_only_entry`, `ui_only_refusal`, `delete_on_exit?`, `SHELL_BANG_PREFIX`…) live in
|
|
221
221
|
`SessionCommandCatalog` (`session_command_catalog.rb`), which the TUI, chi web, `chi send` and `PromptHistory`
|
|
@@ -652,6 +652,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
|
|
|
652
652
|
| Component | Main file(s) | What it is |
|
|
653
653
|
|---|---|---|
|
|
654
654
|
| Worker | `worker.rb` (`worker_boot.rb`, `worker_idle_exit.rb`, `worker_inbound.rb`, `worker_signals.rb`, `worker_wakes.rb`, `worker_task_wakes.rb`, `task_watch.rb`, `worker_participant_gate.rb`, `worker_exit_claim.rb`) | A session's background process: builds the `Engine` and `Bridge`, runs queued turns and the wake turns nobody typed (delegate reports, a background task that finished unseen: [Finish wake](internals/background-tasks.md#finish-wake), attached context), exits when idle. A spawned one traps TERM, HUP and INT (`WorkerSignals`, installed by `WorkerBoot.run_session_loop` when `SAMAGOTCHI_WORKER_PROCESS=1`): the running turn stops as a Stop with reason `signal`, is saved, and the worker leaves (`:signal`, exit 0; a new worker only for input already queued). A running turn is checkpointed at its iteration boundaries (`TurnCheckpoint`, the `interrupted_turn` mark), and the next worker settles a turn its predecessor died in (`TurnCheckpoint.settle`). The session is saved from the turn's thread, Bridge threads and a signal's thread; `Session#save` takes a per-session lock around its snapshot and write, so an older snapshot never lands over a newer one. `WorkerParticipantGate` is the one seat for "may this participant act" (a queued turn as it starts, the drain, the mid-turn stop, the Continue: [internals/participants.md](internals/participants.md)); `WorkerExitClaim` is the exit claim (`POST /exit`): one lock for the kind being taken and the exit taken. Threads: the gate is loop-thread only (a turn runs on the loop; no lock), the claim is safe from any thread (its own mutex, taken after the event lock). The concerns are `include`d parts in `lib/samagotchi/worker/` (`Worker::LeavePart`: exit and leave; `Worker::WakeTurnsPart`: the turns nobody typed; `Worker::StartupPart`: the start-up settle; `Worker::SignalGracePart`: a signal's grace; `Worker::ScratchPart`: a scratch worker whose terminal left; `Worker::ChildSidePart`: a delegate child's rings, Verify fresh verdicts; `Worker::CommandQueuePart`: session commands between turns). `worker.rb` keeps the loop, the wiring, the prompt turns and the drain. They share Worker's ivars, and each header says what it writes and reads. |
|
|
655
|
+
| Session lifecycle | `session_manager/`, `worker_boot.rb`, the session sidecar files | Marker writers, derived states, lock order, crash repair and the known open windows are mapped in [Session lifecycle](internals/session-lifecycle.md). |
|
|
655
656
|
| Config | `config.rb`, `config/restart_watch.rb` | Every setting as an `Entry`: env, config.yml and CLI layers ([configuration.md](configuration.md)); the notice a worker or chi web gets when config.yml changes a setting it reads only at its start. With `log.rb` it is the bottom layer: nothing it references reaches back to it, so `hosts:` and `models:` entries parse next to their types (`HostConfig.all`, `ModelSettings.all`). |
|
|
656
657
|
| Paths | `paths.rb` (`Paths`) | The XDG base dirs chi's files live under, read from the env on every call: `Paths.state_home` (`$XDG_STATE_HOME`, else `~/.local/state`) and `Paths.config_home` (`$XDG_CONFIG_HOME`, else `~/.config`), both defaults under `Dir.home`; a blank variable counts as unset, a relative one is made absolute from the current directory. `Paths.tilde` shows a path with `~` for the home folder. `SessionManager` hands a spawned worker the spawner's `XDG_STATE_HOME` / `XDG_CONFIG_HOME`, when set, made absolute, so a relative one isn't read from the session's folder. |
|
|
657
658
|
| MemoryBundle | `memory_bundle.rb`, `memory_bundle/{installer,builder,installed_bundle,plugin_ref,bundle_hook}.rb` (`Installer`, `Builder`, `InstalledBundle`, `PluginRef`, `BundleHook`) | Installing, building and reading bundles of memories, rules, plugins and scripts (`BundleHook`: an older record's retired class-file hook). |
|
|
@@ -671,12 +672,12 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
|
|
|
671
672
|
| Idle work | `idle_scheduler.rb` (`IdleScheduler`), `idle_recap.rb` (`IdleRecap`), `idle_reminders.rb` | One poller for an idle session's recap and reminders. |
|
|
672
673
|
| Attached context | `context_sources.rb` (`ContextSources`), `context_poller.rb`, `context_absorber.rb`, `context_candidates.rb` (`ContextCandidates`: proposed sources, attached on the owner's mention at a turn's start, before the worker's absorb, or in a one-shot's turn; `owner_prompt.rb` decides whose words count), `peer_sources.rb` (`PeerSources`: the sources peer bundles declare) | External sources a session keeps fresh, and the peer loop's wakes ([context.md](context.md)). |
|
|
673
674
|
| LLM context strategies | `llm_context_strategy.rb`, `llm_context_view.rb`, `llm_context_stale.rb`, `llm_context_forget.rb` | What a request sends of the history (none, stale, forget) ([internals/llm-context-forget.md](internals/llm-context-forget.md)). |
|
|
674
|
-
| Session chains | `session_continue.rb` (`SessionContinue`), `session_chain.rb` (`SessionChain`), `session_chain/links.rb` (`SessionChain::Links`) | A session that continues an earlier one. `SessionChain::Links` is the one chain walker (one listing; `latest`, `first_live`, `root`, `next_of`): `SessionChain.latest`/`.next_of`, `SessionInbox::Head` and the schedule tick all ask it. `SessionChain.opener_for` gives the text web `continue →` prefills in the new link: the previous link's own first typed message when that link continues one itself, else nil (the 201's `opener`; not saved) ([sessions.md](sessions.md)). |
|
|
675
|
-
| chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, the owner show's stamped with their turns' drawings and carrying no parts (a step's ✂ marks only), the participant show's with their parts, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/verify_fresh_routes.rb` (`Web::VerifyFreshRoutes`: Verify fresh children), `web/working_set_routes.rb` (`Web::WorkingSetRoutes`: the working set routes), `web/viewer.rb` (`Web::Viewer`: page capabilities), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions, prefs, test and presence), `web/block_renderer_routes.rb` (`Web::BlockRendererRoutes`: `GET /api/block_renderers` and one renderer's file, [internals/block-renderers.md](internals/block-renderers.md)), `web/reload_check_route.rb` (`Web::ReloadCheckRoute`: `POST /api/sessions/:id/reload_check`, the opt-in `web.reload_check`'s counts from the page's `reload_check.js`, 204 and one `reload_checked` log line, with `reload_mismatch`, its `kinds`, `excused` (ACCEPTED ids) and `explained` when the turn read otherwise after a reload; the worker's version is chi web's own view, its sidecar) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. |
|
|
675
|
+
| Session chains | `session_continue.rb` (`SessionContinue`), `session_chain.rb` (`SessionChain`), `session_chain/links.rb` (`SessionChain::Links`), `session_chain/delete.rb` (`SessionChain::Delete`), `session_chain/delete_preview.rb` (`SessionChain::Delete::Preview`), `continued_from.rb` (`ContinuedFrom`) | A session that continues an earlier one. `SessionChain::Links` is the one chain walker (one listing; `latest`, `first_live`, `root`, `next_of`): `SessionChain.latest`/`.next_of`, `SessionInbox::Head` and the schedule tick all ask it. `SessionChain.opener_for` gives the text web `continue →` prefills in the new link: the previous link's own first typed message when that link continues one itself, else nil (the 201's `opener`; not saved). `SessionChain::Delete` plans and deletes a link or its chain; `Delete::Preview` supplies the web delete sheet, and `ContinuedFrom` records what a continue must undo ([sessions.md](sessions.md)). |
|
|
676
|
+
| chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/request_body.rb` (`Web::RequestBody`: bounded body reads), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, the owner show's stamped with their turns' drawings and carrying no parts (a step's ✂ marks only), the participant show's with their parts, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/session_access_routes.rb` (`Web::SessionAccessRoutes`: the session-command routes), `web/verify_fresh_routes.rb` (`Web::VerifyFreshRoutes`: Verify fresh children), `web/working_set_routes.rb` (`Web::WorkingSetRoutes`: the working set routes), `web/viewer.rb` (`Web::Viewer`: page capabilities), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions, prefs, test and presence), `web/block_renderer_routes.rb` (`Web::BlockRendererRoutes`: `GET /api/block_renderers` and one renderer's file, [internals/block-renderers.md](internals/block-renderers.md)), `web/reload_check_route.rb` (`Web::ReloadCheckRoute`: `POST /api/sessions/:id/reload_check`, the opt-in `web.reload_check`'s counts from the page's `reload_check.js`, 204 and one `reload_checked` log line, with `reload_mismatch`, its `kinds`, `excused` (ACCEPTED ids) and `explained` when the turn read otherwise after a reload; the worker's version is chi web's own view, its sidecar) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. The shared body reader caps incoming requests. |
|
|
676
677
|
| Web Push | `web/push.rb` (`Web::Push`: `Runtime`, `preflight!`, the `web.push.*` settings), `web/push/crypto.rb` (`Push::Crypto`: RFC 8291 aes128gcm, RFC 8292 VAPID), `web/push/store.rb` (`Push::Store`, `Store::Sub`: `web-push/vapid.pem`, `subscriptions.json`), `web/push/client.rb` (`Push::Client`, `Client::Result`), `web/push/attention.rb` (`Push::Attention`: notify.js's rules in Ruby, shared cases in `spec/fixtures/attention_cases.json`), `web/push/presence.rb` (`Push::Presence`: the pages' "in front" reports), `web/push/notifier.rb` (`Push::Notifier`, a hub subscriber with a sender thread), `web/push_routes.rb` (`Web::PushRoutes`), `private_files.rb` (`PrivateFiles`, shared with the grants), `public/sw.js`, `public/push.js`, `public/manifest.webmanifest` | chi web pushes what the tab notifies for (approvals, questions, step-limit questions, cards, failed turns; done turns to a device that asks) to the owner's Home Screen app over an https public URL: the Notifier turns the hub's new attentions into show pushes after a hold, unless a chi web page is in front, at most 30 an hour, with one retry and a restart catch-up (`sent.json`) (each carries the keys still open, and the badge; no close push: every push shows a notification); the bell (`notifications.js`) subscribes the device, and the service worker and the page close the answered ones. See [internals/web-push.md](internals/web-push.md). |
|
|
677
678
|
| chi web's updates | `web/update_check.rb` (`Web::UpdateCheck`), `web/update_ops.rb` (`Web::UpdateOps`), `web/auto_update.rb` (`Web::AutoUpdate`) | The RubyGems checker and its `update_check.json`; the install, worker-restart and chi-web-restart operations (one at a time) the owner's routes and AutoUpdate share; `update.auto: install`'s thread (install when no turn runs, then idle workers and chi web). See [configuration](configuration.md#unattended-updates-updateauto). |
|
|
678
679
|
| Behind an auth proxy | `web/public_url.rb` (`Web::PublicUrl`: `web.public_url`, `web.proxy.identity_header`, `web.proxy.owner`), `web/proxy_gate.rb` (`Web::ProxyGate`, mixed into App; `RawHeaderNames`, prepended to WEBrick's request by `Web::Server`), `web/link_codes.rb` (`Web::LinkCodes`: the links' one-time codes), `proxy_trace.rb` (`ProxyTrace`), `web/public/token_fragment.js`, `web/public/auth_lost.js`, `web/tunnel.rb` + `web/tunnel/tailscale.rb` (`Web::Tunnel`, `Web::Tunnel::Tailscale`: `chi web --tunnel tailscale`, Tailscale Serve set for one run and the PublicUrl it makes) | Experimental: chi web behind an auth proxy. Every request needs the token; a proxied one's owner also needs the identity header (one clean value under one name); the `__Host-` cookie, an absolute `Location` from the public URL, https links with a one-time code in the fragment; the page's lost-sign-in banner. Bridges refuse proxy traces ([configuration.md](configuration.md#behind-an-auth-proxy)). |
|
|
679
|
-
| Participants | `participants.rb` (`Participants`, the `participants.json` sidecar), `share_command.rb` (`ShareCommand`, `chi share`), `session_participants.rb`, `participants_watch.rb`, `grants.rb` (`Grants`), `participant_exposure.rb` (`ParticipantExposure`), `web/principal.rb` (`Web::Principal`), `web/participant_access.rb` (`Web::ParticipantAccess`: the participant's gate and routes), `web/participants_admin.rb` (`Web::ParticipantsAdmin`: the owner's invite, list, revoke and cap routes), `web/participant_review.rb` + `web/participant_view.rb` (`Web::ParticipantReview`, `Web::ParticipantView`), `web/participant_show.rb` (`Web::ParticipantShow`), `web/participant_images.rb` (`Web::ParticipantImages`), `participant_uploads.rb` (`ParticipantUploads`), `participant_revise.rb` (`ParticipantRevise`), `participant_messages.rb` (`ParticipantMessages`), `revise_anchor.rb` (`ReviseAnchor`), `redact.rb` (`Redact`, `Redact::Viewer`: the redaction every string a participant gets passes, also the Engine's Verify quote check), `web/participant_stream_filter.rb`, `share_terms.rb` (`ShareTerms`), `guardrails/pair_boundary.rb` + `guardrails/participant_refusal.rb` + `guardrails/review_paths.rb` | The people an owner invites into one session through chi web: their grants and gate, what they read, their turns under the owner's guardrails ([internals/participants.md](internals/participants.md), [guardrails.md](guardrails.md)). |
|
|
680
|
+
| Participants | `participants.rb` (`Participants`, the `participants.json` sidecar), `share_command.rb` (`ShareCommand`, `chi share`), `session_participants.rb`, `participants_watch.rb`, `grants.rb` (`Grants`), `participant_exposure.rb` (`ParticipantExposure`), `participant_prompts.rb` (`ParticipantPrompts`), `participant_name.rb` (`ParticipantName`), `participant_turn_mode.rb` (`ParticipantTurnMode`), `web/principal.rb` (`Web::Principal`), `web/participant_access.rb` (`Web::ParticipantAccess`: the participant's gate and routes), `web/participants_admin.rb` (`Web::ParticipantsAdmin`: the owner's invite, list, revoke and cap routes), `web/participant_review.rb` + `web/participant_view.rb` (`Web::ParticipantReview`, `Web::ParticipantView`), `web/participant_show.rb` (`Web::ParticipantShow`), `web/participant_images.rb` (`Web::ParticipantImages`), `web/participant_history.rb` (`Web::ParticipantHistory`: prompt history), `participant_uploads.rb` (`ParticipantUploads`), `participant_revise.rb` (`ParticipantRevise`), `participant_messages.rb` (`ParticipantMessages`), `revise_anchor.rb` (`ReviseAnchor`), `redact.rb` (`Redact`, `Redact::Viewer`: the redaction every string a participant gets passes, also the Engine's Verify quote check), `web/participant_stream_filter.rb`, `share_terms.rb` (`ShareTerms`), `guardrails/pair_boundary.rb` + `guardrails/participant_refusal.rb` + `guardrails/review_paths.rb` | The people an owner invites into one session through chi web: their grants and gate, what they read, their turns under the owner's guardrails. Their own prompt history, display names and turn-mode decision are kept apart from the owner's paths ([internals/participants.md](internals/participants.md), [guardrails.md](guardrails.md)). |
|
|
680
681
|
| Analytics | `analytics_file.rb` (`AnalyticsFile`), `session_metrics/totals.rb` (`SessionMetrics::Totals`), `session_metrics/model_segment.rb` (`SessionMetrics::ModelSegment`) | A session's `analytics.json` (`SessionMetrics#persist`); the sums over its turn records (`Totals`: tokens, cost, speeds, kept as running counters) and their split per model after a `/model` switch (`ModelSegment`: a run of turns on one model, the `model_segments` rows); `session_metrics/cost.rb` (`SessionMetrics::Cost`): the spend `ctx.cost` reads; `session_metrics/usage.rb` (`SessionMetrics::Usage`): the work `ctx.usage` reads. `session_metrics/side_totals.rb` (`SessionMetrics::SideTotals`) and `side_usage.rb` (`SideUsage`): the side requests' sums, apart from the turns'. |
|
|
681
682
|
| Images / vision | `image_store.rb` (`ImageStore`), `vision_support.rb`, `vision_context.rb` | Stored prompt images and whether a model takes them. |
|
|
682
683
|
| Toolkits | `toolkit.rb` (`Toolkit`), `toolkit_binding.rb` (`ToolkitBinding`, the Engine's seam), `toolkit_command.rb` (`/toolkit`), `tools/registry.rb` (`Registry#toolkit`), `tools/tool_surface.rb` (`ToolSurface#left_out`, read by the prompt and `/toolkit`), `web/public/toolkit_chip.js` | Which registered tools a session's prompts declare: saved in the session, resolved at a turn's start (`Engine#apply_toolkit!`), named in the prompt's not-loaded line, a kit's prompt text after the appended files; `chi.toolkit` and `ctx.use_toolkit` for plugins ([configuration.md](configuration.md#toolkits)). |
|
data/docs/cli.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
- `chi web --web-markdown` / `--no-web-markdown` — opt in to, or opt out of, sanitized Markdown rendering for completed assistant messages, the stage's asking text and a resolved question card's reply (`web.markdown`, off by default; `--no-web-markdown` turns a config's `web.markdown: true` off for this run)
|
|
19
19
|
- `chi web --no-web-working-set` — turns the stage view's working set off (on by default; `--web-working-set` turns a config's `web.working_set: false` back on): what each turn brought into the model's context, in the stage and under each finished turn; `?working_set=1|0` on the page URL overrides it (see [The working set](#the-working-set))
|
|
20
20
|
- `chi web --web-stage-collapsed` / `--no-web-stage-collapsed` — every session's stage starts folded to its status row, or not (`web.stage_collapsed`, off by default); a session folded or unfolded by hand keeps its own fold in that browser
|
|
21
|
-
- `chi sessions list|stop|restart|archive|unarchive|delete|prune|clean|stats` — manage persisted sessions; `list` shows this git project's, `list --scope=all` every one, a delegated session with `↳ <parent>`, `list --archived` the archived ones too (see [Sessions](sessions.md)); one line per session (`<id> <state> <ctx> <updated_at> <text> [flags] ↳ … ↪ …`) and one footer (`N session(s) (sort=… order=…)`, or the project note) for the plain list, the `--live`/`--cwd` text and `--remote`. `stats ID` prints a session's cost, tokens and progress, and its own settings (`--set`; a `settings:` line), from a live worker's `GET stats`, else its saved `analytics.json` (`--format json` one object, with `settings`), without running a model turn. A usage error (an unknown subcommand or flag, a flag missing its value, `stop`, `restart` or `delete` with no ids, a bad `list --format`, `--scope`, `--sort` or `--order`, a `--days`, `--keep` or `--limit` that isn't a whole number) exits 2; an unknown or refused session exits 1
|
|
21
|
+
- `chi sessions list|stop|restart|archive|unarchive|delete|prune|clean|stats` — manage persisted sessions; `list` shows this git project's, `list --scope=all` every one, a delegated session with `↳ <parent>`, `list --archived` the archived ones too (see [Sessions](sessions.md)); one line per session (`<id> <state> <ctx> <updated_at> <text> [flags] ↳ … ↪ …`) and one footer (`N session(s) (sort=… order=…)`, or the project note) for the plain list, the `--live`/`--cwd` text and `--remote`. `stats ID` prints a session's cost, tokens and progress, and its own settings (`--set`; a `settings:` line), from a live worker's `GET stats`, else its saved `analytics.json` (`--format json` one object, with `settings`), without running a model turn. A usage error (an unknown subcommand or flag, a flag missing its value, `stop`, `restart` or `delete` with no ids, `unarchive --stop-tasks`, a bad `list --format`, `--scope`, `--sort` or `--order`, a `--days`, `--keep` or `--limit` that isn't a whole number) exits 2; an unknown or refused session exits 1
|
|
22
22
|
- `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))
|
|
23
23
|
- `chi broadcast [-m TEXT] [--all] [--dry-run]`, `chi broadcast log [--last N] [--format json]`, `chi broadcast deliver BROADCAST_ID (ID|PREFIX)...` — share one piece of information (TEXT or stdin) with every session it may concern, as a context note from `broadcast` (see [Broadcast](broadcast.md))
|
|
24
24
|
- `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; `chi context push NAME -m TEXT` (the long form is `--message TEXT`) gives a `--push` source its new text, read from stdin when no `-m` is given (see [Attached context](context.md))
|
|
@@ -740,7 +740,10 @@ approval, queued prompt, or running background task; otherwise it says to run
|
|
|
740
740
|
`chi sessions stop ID`, then send any prompt. That fallback drops reminders,
|
|
741
741
|
and may lose a running `/btw` and other in-memory state. A session with no running worker needs no restart (its next
|
|
742
742
|
prompt starts one on the newest chi), and an older worker without restart
|
|
743
|
-
support needs `chi sessions stop ID`.
|
|
743
|
+
support needs `chi sessions stop ID`. A stopped session, or one being stopped
|
|
744
|
+
(`chi sessions stop`), is refused at once without asking its worker: "can't
|
|
745
|
+
restart: the session is stopped; only its owner's message starts it again (on
|
|
746
|
+
the newest chi)". The Web UI's
|
|
744
747
|
`POST /api/sessions/:id/restart` does the same (409 with `reason` and `detail`
|
|
745
748
|
when it can't). An attached
|
|
746
749
|
terminal says at the join, in one `chi>` line, when the worker or the terminal
|
|
@@ -760,10 +763,16 @@ a delegate's follow-up or a reminder. The web archives from the info bar
|
|
|
760
763
|
(`archive`, before `stop`); the `archived` toggle by the all-sessions search
|
|
761
764
|
finds archived sessions. `/archive` in a terminal leaves the session and
|
|
762
765
|
archives it (an empty session is discarded instead; `chi scratch` refuses
|
|
763
|
-
it).
|
|
766
|
+
it). A session whose background tasks (its `task_create` tasks, an `execute`
|
|
767
|
+
handed over at its limit, its delegates' too) still run is refused, naming
|
|
768
|
+
them (`ab12cd34 refused: background tasks it started are still running: npm
|
|
769
|
+
run dev (--stop-tasks stops them first)`, exit 1); `archive --stop-tasks`
|
|
770
|
+
stops them first (TERM, then KILL) and says so (`archived (stopped its
|
|
771
|
+
worker; stopped 1 background task)`). `/archive` says the same and names
|
|
772
|
+
`chi sessions archive --stop-tasks ID`; the web asks a second confirm. See
|
|
764
773
|
[Sessions](sessions.md#archiving-a-session).
|
|
765
774
|
|
|
766
|
-
`chi sessions delete [--force] [--chain] ID...` deletes sessions for good: the
|
|
775
|
+
`chi sessions delete [--force] [--chain] [--stop-tasks] ID...` deletes sessions for good: the
|
|
767
776
|
session file and its whole directory (notes, images, queued input). Each id
|
|
768
777
|
(or unique prefix) gets one line: `deleted`, or `refused` with the reason.
|
|
769
778
|
Deleting a chain's newest link undoes its continue and says so (`… deleted;
|
|
@@ -775,10 +784,20 @@ schedule on the chain refuses it. See docs/sessions.md (Session chains →
|
|
|
775
784
|
Deleting a link). A
|
|
776
785
|
session whose worker runs is refused unless `--force` stops the worker first;
|
|
777
786
|
one a `--non-interactive` run has is always refused ("in use by a one-turn chi
|
|
778
|
-
--non-interactive run or an older chi's terminal; let it finish first").
|
|
787
|
+
--non-interactive run or an older chi's terminal; let it finish first"). A
|
|
788
|
+
session whose background tasks still run (its own, or a delegate's or link's
|
|
789
|
+
the delete takes) is refused, naming them (`refused: background tasks it
|
|
790
|
+
started are still running: npm run dev, rspec (--stop-tasks stops them
|
|
791
|
+
first)`); `--stop-tasks` stops them first and the line says so (`deleted
|
|
792
|
+
(stopped its worker; stopped 2 background tasks)`; one chi can't verify or
|
|
793
|
+
read is never signalled: `1 not stopped: task 3f9a2c1d (may still be
|
|
794
|
+
running)`). `--stop-tasks` is not `--force`: a live worker is still refused
|
|
795
|
+
without it. `/exit --delete` refuses the same way and names `chi sessions
|
|
796
|
+
delete --stop-tasks ID`. Exit
|
|
779
797
|
status: 0 when all are gone, 1 when any was refused or unknown, 2 on a usage
|
|
780
798
|
error. The Web UI deletes too: `delete` in the info bar, or the ✕ on a card in
|
|
781
|
-
All sessions; it asks first and stops a live worker
|
|
799
|
+
All sessions; it asks first and stops a live worker, and asks again, naming
|
|
800
|
+
them, when background tasks still run (OK stops them).
|
|
782
801
|
|
|
783
802
|
`chi sessions stats ID [--format text|json]` prints a session's cost, tokens
|
|
784
803
|
and progress without running a model turn — the same text `/stats` prints in
|
|
@@ -1650,6 +1669,12 @@ CHI_REMOTE=studio chi context push claude-outbox ab12 < answer.json
|
|
|
1650
1669
|
answer ab12 --question q1 --option N`, `chi --remote studio send --wait …`),
|
|
1651
1670
|
under `CHI_REMOTE` too, an attach as well (`chi --remote studio --attach
|
|
1652
1671
|
ab12 shows it`, `sessions stop`'s `chi --remote studio --resume ab12`).
|
|
1672
|
+
- `sessions delete|archive --stop-tasks` needs a chi web there that lists the
|
|
1673
|
+
`stop_tasks` feature (`GET /api/info`); an older one is refused before
|
|
1674
|
+
anything is sent (update and restart chi web there), and without the flag
|
|
1675
|
+
an older one deletes or archives as it always did. A new chi web answers an
|
|
1676
|
+
older CLI's delete or archive of a session whose tasks run with 409
|
|
1677
|
+
`tasks_running`, which that CLI prints as a failure.
|
|
1653
1678
|
- A remote that can't be reached names itself and why (`chi send: remote
|
|
1654
1679
|
studio (http://192.168.1.29:4567): connection refused`, exit 1; with
|
|
1655
1680
|
`--format json` an `error` object).
|
data/docs/guardrails.md
CHANGED
|
@@ -121,7 +121,7 @@ looks in the store): an owner's ask uses every scope; a [participant's turn](#a-
|
|
|
121
121
|
(`Verdict#fresh_ask`) uses none.
|
|
122
122
|
The file is a versioned store (`{"version": 1, "approvals": [...]}`, `Approvals::FORMAT`); a write keeps its version,
|
|
123
123
|
the keys this chi doesn't know and an entry with no `scope`. A bare list of entries, as chi 0.166 and before wrote it,
|
|
124
|
-
is
|
|
124
|
+
is now set aside like an unreadable file. Chi 0.165 and before set a versioned store aside, so restart their sessions
|
|
125
125
|
(`chi sessions restart`); a downgrade to 0.165 or before moves the store to a recoverable `approvals.json.corrupt-*`.
|
|
126
126
|
A file that doesn't parse, or a versioned store whose `approvals` isn't a list, is moved aside to
|
|
127
127
|
`approvals.json.corrupt-<UTC time>` with one warning, and chi starts with no stored approvals (more asks, nothing lost).
|
|
@@ -20,9 +20,9 @@ load the process code, and does not (`spec/require_cycle_spec.rb`, the thin clie
|
|
|
20
20
|
|
|
21
21
|
| Module | Holds | Read by |
|
|
22
22
|
|---|---|---|
|
|
23
|
-
| `Tools::TaskRuntime` (`tools/task_runtime.rb`) | the lifecycle: `create_task`, `adopt`, the waiter (`record_exit_status`, `waiter_for`), refresh, `stop_task`, `get_record`, `list_records`, `running_created_in`, the leftovers; all process state (`@waiters`, `@settle_lock`) | the task tools, `execute`, `Bridge`, `HoldStop`, `TaskWatch`, `TurnEndings`, `Worker` |
|
|
23
|
+
| `Tools::TaskRuntime` (`tools/task_runtime.rb`) | the lifecycle: `create_task`, `adopt`, the waiter (`record_exit_status`, `waiter_for`), refresh, `stop_task`, `get_record`, `list_records`, `running_created_in`, the leftovers; all process state (`@waiters`, `@settle_lock`) | the task tools, `execute`, `Bridge`, `HoldStop`, `TaskWatch`, `TurnEndings`, `Worker`, `SessionManager::RunningTasks.stop!` (loaded at call time) |
|
|
24
24
|
| `SpawnEnv` (`spawn_env.rb`) | the env a spawned command gets: `sanitized_spawn_env`, `spawn_env_for` (task_create's `env` checks), `SANITIZED_ENV_KEYS`, `MARKER_ENV_KEYS` | `execute`, `create_task`, `ProjectEnv.spawn_env` (required at call time: `child_env` requires `project_env`) |
|
|
25
|
-
| `TaskFiles` (`task_files.rb`) | where a task's files are: `TASKS_DIR`, `METADATA_FILENAME`, `OUTPUT_FILENAME`, `EXIT_CODE_FILENAME`, `TASK_ID`, `metadata_path`, `task_dir_for`, `command_of` (a record read, no refresh) | `TaskRuntime`, `execute`, `ToolActivity`, `SessionManager`, `chi bundle try`'s sandbox, the slow-commands bundle |
|
|
25
|
+
| `TaskFiles` (`task_files.rb`) | where a task's files are: `TASKS_DIR`, `METADATA_FILENAME`, `OUTPUT_FILENAME`, `EXIT_CODE_FILENAME`, `TASK_ID`, `metadata_path`, `task_dir_for`, `tasks_dir`, `command_of` (a record read, no refresh), `with_root` (this thread's paths under another folder) | `TaskRuntime`, `execute`, `ToolActivity`, `SessionManager`, `chi bundle try`'s sandbox, the slow-commands bundle |
|
|
26
26
|
| `TaskTranscript` (`task_transcript.rb`) | which tasks a conversation started, from its results' text: `created_ids_in`, `created_id`, `handed_over_id`, `RAN_AS_LINE` (matching on `ToolNames::Execute`) | `TaskRuntime.running_created_in`, `Bridge`, `TaskWatch`, `WorkerTaskWakes`, `SessionManager` |
|
|
27
27
|
|
|
28
28
|
Behavior:
|
|
@@ -35,6 +35,27 @@ Behavior:
|
|
|
35
35
|
- `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped (the result's hint says to start a long job with `task_create` in the foreground, no `&`: a `cmd &` left behind there is stopped too); one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, which says chi can't stop it and to kill it if it shouldn't run, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
|
|
36
36
|
- The exit code: the command runs after an EXIT trap that writes the shell's status to the `exit_code` file (`TaskRuntime.wrapped_shell_command`, shared with `task_create`), so `exit N`, a `set -e` failure and a trailing `\` or `|` in the command all record what the shell exited with. The trap runs wherever the shell is when it exits (a `task_create` `cwd`, or a `cd` in the command), so `task_create`'s `exit_code_path` is absolute; its `output_path` stays relative (`tmp/tasks/<id>/output.log`, opened by chi in the worker's cwd before the spawn). A command that sets its own EXIT trap replaces it, and a shell killed by a signal skips it (zsh's sh mode, on TERM, INT and KILL): `execute` still reports the shell's status, and a `task_create` task or a handed-over execute gets its code from chi's waiter while the chi that started it runs (`TaskRuntime.record_exit_status`): the exit status, or `128 + the signal` (TERM → 143), with no new `stop_reason`. A record a refresh already finished without a code in between (`failed`, `process_ended_without_exit_code` or the not-chi's-process reason) is corrected, its `finished_at` kept; a stopped task (its stop flag on disk) is never touched. `process_ended_without_exit_code` is left only when the shell wrote nothing and the chi that started it was gone too.
|
|
37
37
|
- `task_create` applies `execute`'s leftover rule (`Tools::Leftovers`, one implementation: `held?`, the grace, the group stop, the hint wording): `create_task` holds `output.log` with a shared `flock` across the spawn, and a handed-over execute's two logs are already held. When the task's shell exits and a process it started still holds the log (`yes >/dev/null &` with no `wait`), the task stays `running` (so the finish wake's watch and `task_wait` keep waiting) while the waiter of the chi that started it (`TaskRuntime.record_exit_status`) gives it 1.5 s (`LEFTOVER_GRACE_SEC`), then stops the group (TERM, 1 s, KILL; `Leftovers.stop_group`, only while the group still has members: a pgid isn't reused while it has any) and finishes the record in one write: the shell's status and exit code (the leftovers don't make it a failure) and `leftovers: "stopped"`. A holder outside the group with the group empty (a setsid'd `cmd &`, or a backgrounded `timeout N cmd &`: GNU `timeout` without `--foreground` moves itself and its command to a group of its own) is signalled nothing: `leftovers: "detached"`, left running, and the hint says so (`task_stop` can't reach it: kill it if it shouldn't run). A process holding no log (`nohup cmd >f 2>&1 &`) is left alone. `task_get`, `task_wait` (so the finish note too) and `task_list` add the hint line (`Leftovers.task_hint`), ``(a background process kept the task's log open and was stopped; to keep one running, run it in the foreground or end the command with `wait`)`` (or `was left running`), built from the same `Leftovers.hint` as execute's. One settler per task: while that waiter thread lives (`TaskRuntime.waiter_for`, in memory, this process only), a refresh here only reads a held record. With no waiter here (the chi that started it is gone, a worker that exited mid-grace, or another process reading), the next refresh that finds the shell dead and the log held settles it itself: a second look after 0.05 s (two `held?` probes at once read each other as holders), then the stop with a 0.5 s TERM grace and 0.5 s KILL wait (only of a group that still had members at the first look; one gone by the stop with nothing holding the log records no `leftovers`), so that read blocks up to ~1 s plus a `ps`. With no later reader of that cwd's tasks the leftovers run on; records already finished (an older chi's) are never revisited, and an older chi's record (its log never `flock`'d) reads as not held and settles as before. A `task_stop` during the grace stops the group (`Leftovers.stop_group`) and the record ends `stopped` (its stop flag wins over the waiter's write; in one process the two writes share a lock). Cost: one non-blocking `flock` try per log at shell exit (~0.2 ms), the grace only when something holds the log; a refresh of a running record whose shell is dead adds one `flock` try, and one `ps` only when the log is held.
|
|
38
|
+
- On a clean exit (worker teardown or a one-shot), `Engine#shutdown` calls `TaskRuntime.settle_pending!`: this process's
|
|
39
|
+
waiters whose shells are already reaped get time to finish their leftover grace and stop before chi exits. The wait
|
|
40
|
+
shares one deadline with the anytime-command joins (the later of their 3 s and ~4 s), and logs a warning if a selected waiter
|
|
41
|
+
remains. A shell still running at the snapshot, including one that exits during the join, is not waited on; a crash
|
|
42
|
+
or SIGKILL cannot wait either. With no later reader of that cwd, such leftovers can still run on.
|
|
43
|
+
- Nothing stops a running task when its worker leaves, so a user's delete or archive asks about the tasks the session
|
|
44
|
+
(and what the op takes with it) started: `SessionManager::RunningTasks` (`session_manager/running_tasks.rb`).
|
|
45
|
+
`.of(ids, state_dir:)` reads, per session, its file's transcript (`TaskTranscript.created_ids_in`) and each
|
|
46
|
+
`<working_directory>/tmp/tasks/<id>/task.json`, writing nothing and loading no `TaskRuntime`: a `Listing` of
|
|
47
|
+
`running` (the pid leads its group at the recorded `pid_started`), `unverified` (a group leader with no start time
|
|
48
|
+
to compare: none recorded, or none readable now) and `unreadable` (log `session_task_check_failed`). `Policy`
|
|
49
|
+
(`IGNORE`, the default; `REFUSE`; `Policy.stop(by:)` with its `Tally`) is the op's `running_tasks:`; restart's
|
|
50
|
+
fallback holds on a non-empty listing too. `.stop!` signals only `running` entries, one thread each, each running
|
|
51
|
+
`TaskRuntime.stop_task(id, by:)` inside `TaskFiles.with_root(root)`, all joined against one deadline
|
|
52
|
+
(`STOP_GRACE_SEC + ProcessGroup::KILL_WAIT_SEC + 0.5`); outcomes `stopped`, `ended`, `failed`, `unconfirmed` (and
|
|
53
|
+
the never-signalled `unverified`/`unreadable`) go into the tally, no command text logged.
|
|
54
|
+
`TaskFiles.with_root` sets a thread-local root that `metadata_path`, `task_dir_for`, `tasks_dir`,
|
|
55
|
+
`ensure_tasks_dir`, `list_records`' glob and `log_paths` (a relative `output_path` joined at read, stored unchanged)
|
|
56
|
+
read, so chi web and the CLI run `stop_task` from their own cwd; without a root every path is the relative one. A
|
|
57
|
+
thread the block starts doesn't inherit it (only `create_task` starts waiters, and nothing calls it under a root).
|
|
58
|
+
See [sessions.md](../sessions.md) (Deleting a session).
|
|
38
59
|
- A stop of an `execute` (the user's Stop, the limit in kill mode) is done once the shell is reaped and nothing holds the logs: a child that ignores TERM after its shell died gets the KILL.
|
|
39
60
|
- A command still running at `execute.timeout_sec` is handed over as a task (`execute.on_timeout: task`, the default; `kill` stops it instead, and the `!cmd` bang always kills): the result starts `Still running at the 120s limit: moved to a background task, not killed.`, then `task_id: …` and the tails of both logs so far. A command is also handed over early when a person's message waits for the turn's next step (the `message_waiting:` probe, the same `Engine#input_waiting?` as `task_wait`'s): after `Execute::EARLY_HAND_OVER_FLOOR_SEC` (3 s: a short command ends first and its result is the better answer), in the next 0.2 s slice. The first line then reads `Still running at the 4s mark: a message from the user is waiting, so the command moved to a background task, not killed.` (the seconds it had run), and the line after `task_id:` starts `Read the message first.`; the rest is the same hand-over, and the task stays watched. Never in `kill` mode (`execute.on_timeout: kill`, a participant's pair turn, the `!cmd` bang): there the probe is not even read and the command runs to its limit and is killed. A command that can't be adopted at that moment (a record that can't be written) isn't killed early: it runs on to its limit. Everything that matches the first line builds on `Execute::HANDED_OVER` (`Still running at the`) and `Execute::HANDED_OVER_AFTER` (both defined in `ToolNames::Execute`) (`120s limit:` or `4s mark:`): `TaskTranscript.handed_over_id`, `ToolActivity::HANDED_OVER_START`, `TaskWatch` (`limit_sec` for the limit's form, `early_sec` for the mark's, which the finish note words as `handed over by execute after 4s: a message from the user was waiting`) and the web's `task_stop.js`; the slow-commands bundle reads only the limit's form, which is the only one that is a timeout. A timeout during the 1.5 s background grace is a kill (the shell is gone, nothing to hand over). If the record can't be written, the command is killed. `TaskRuntime.adopt` writes a record for the process execute already started, with `handed_over_by: "execute"`. Its logs stay where execute wrote them, so the record's paths are absolute: `output_path` (stdout), `stderr_path` (stderr, a log of its own) and `exit_code_path` (a `task_create` record's `exit_code_path` is absolute too; its `output_path` is relative). `started_at` (and `created_at`) is the spawn time, not the hand-over's; `pid_started` is read at the hand-over, while execute's detach waiter is still running. From there it is an ordinary task: `task_wait`, `task_get`, `task_list` and `task_stop` treat it as any other. Its dir gets a `task` back-pointer file holding the record's absolute path. Once per process, the first `execute` sweeps `…/execute/`: a dir whose logs no process holds is removed when it has no back-pointer and is a day old (chi died mid-command), when its record is gone, or when it is 14 days old. The records live in each project's `tmp/tasks`, which the state dir can't list: hence the back-pointer.
|
|
40
61
|
- `task_wait` and `task_get` show `stderr_path` when the record has one; `task_wait`'s output tail is followed by a `stderr_tail:` of at most 10 lines when that log isn't empty. A `task_create` task has one log (stdout and stderr together) and no `stderr_path`. A `task_wait` result longer than `max_tool_output_chars` keeps its header and the tail's end, with a gap line naming `output_path`, where the whole log already is (and `stderr_path`, when the record has one) (`ToolOutputCut`'s `:head_tail_ref`; nothing is copied; see [Tool output guardrails](tool-output-limits.md#the-runners-cut-max_tool_output_chars)).
|
data/docs/internals/bridge.md
CHANGED
|
@@ -209,8 +209,9 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
|
|
|
209
209
|
so the stamp and the count always name one place, and the page finds it by the bubble (`card_stamps.js`: `data-turn-id`, or `data-opening-id` on a wake's note or a reason line), not by counting
|
|
210
210
|
bubbles. An entry shown after reason lines also saves which one it came after (`after_opening`, beside `past_idless`): read
|
|
211
211
|
first while that line is still in the run, so a later release can drop the count. No stamp (the page counts `turns_since`) for
|
|
212
|
-
an entry before every opening
|
|
213
|
-
keeps today's rule: a rolled-back
|
|
212
|
+
an entry before every opening or after a line an older chi wrote with no id. A version 1 file is no longer read (its earlier
|
|
213
|
+
cards do not show); `base_since` remains readable in version 2 files saved since. A rollback keeps today's rule: a rolled-back
|
|
214
|
+
turn's cards name the opening before it.
|
|
214
215
|
The saved recap carries the same stamp: `saved_recap`'s `opening_id` (`RecapPlace.opening_id`, the id of the last
|
|
215
216
|
opening its `covered` messages hold, read at read time, so `recap.json` is unchanged), which the page places it after
|
|
216
217
|
(`recap_stamp.js`); an older worker's `saved_recap` has none, and the page counts `turns_since`.
|
|
@@ -237,9 +238,8 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
|
|
|
237
238
|
are the worker's own (each start announces them) and an unanswered question waits for no one: neither is saved or seeded. An
|
|
238
239
|
entry from an earlier worker lists with `earlier: true`; one shown during a turn comes back **without its actions** (their
|
|
239
240
|
turn no longer runs), while a between-turns card keeps its buttons.
|
|
240
|
-
- **Version 1.** A file from before the log (top-level `turns`, each entry its own, maybe `running`)
|
|
241
|
-
|
|
242
|
-
nothing (no id to check). The next save writes version 2 with `base_since` kept. `SessionManager.cards_empty?` reads both.
|
|
241
|
+
- **Version 1.** A file from before the log (top-level `turns`, each entry its own, maybe `running`) is no longer read, so its
|
|
242
|
+
earlier cards do not show. `SessionManager.cards_empty?` still reads both versions to decide whether a session is empty.
|
|
243
243
|
- **An older chi on a version 2 file.** Its `seed` wants an integer `turns`, finds none, and starts with no entries. A chi web not
|
|
244
244
|
yet restarted only reads: it lists no cards for that session until restarted, and the file stays whole. An older **writer** does
|
|
245
245
|
damage: at its first saved event, `:turn_started`, it writes `{"version":1,"turns":0,"running":true,"entries":[]}` over the file
|
|
@@ -488,7 +488,17 @@ The Bridge exposes:
|
|
|
488
488
|
`cards` (`CardStore#list`; a card an earlier worker showed during a turn comes back read-only, with no
|
|
489
489
|
actions: its turn no longer runs), `event_seq`, `event_id`, all taken in one event-log hold; no message
|
|
490
490
|
list, so it costs the same however long the session is. `?turn_id=` answers that turn's answer
|
|
491
|
-
(an unknown or missing id: the newest)
|
|
491
|
+
(an unknown or missing id: the newest). A handler in `Bridge::QUERY_HANDLERS` gets the query string; no other one does.
|
|
492
|
+
- `GET /session/:id/working_set/item?kind=&key=[&now=1][&latest=1]` — what the model has of one working-set item
|
|
493
|
+
(`Engine#working_set_item`: `WorkingSet.timeline_of`'s `{kind, key, events}`, `now:` for a memory with `now=1`;
|
|
494
|
+
with `latest=1` only the peek's events and `counts`, `WorkingSet::Timeline#peek_h`), plus
|
|
495
|
+
`at` (the conversation's size it was built from) and `running`. While a turn runs it reads the turn's view
|
|
496
|
+
(`EventFanout#turn_view`: a shallow copy of the running turn's conversation taken at each `:generation_started`,
|
|
497
|
+
used only while that turn's id is the running one, dropped at the turn's end under the event lock), else a copy of
|
|
498
|
+
the session's messages. `400 invalid_item`
|
|
499
|
+
(`WorkingSet::INVALID_ITEM`, chi web's words) for a kind it doesn't know or a blank key. Owner-only is chi web's
|
|
500
|
+
(its route is `:owner`); the Bridge's gate is its secret. Advertised as `working_set_item`
|
|
501
|
+
([working-set.md](working-set.md#delivery)).
|
|
492
502
|
- No browser: only chi's own clients talk to a Bridge. A request with an `Origin` header, a `Sec-Fetch-Site`
|
|
493
503
|
other than `none`, or a `Host` that isn't loopback (a DNS-rebound page) is `403 cross_origin`
|
|
494
504
|
(`Bridge#browser_request?`, before any route); there is no CORS and no `OPTIONS` route. The browser reaches a
|
|
@@ -647,6 +657,7 @@ compatibility from its version. `Bridge::FEATURES` advertises:
|
|
|
647
657
|
| `cancel_turn_id` | `POST /session/:id/cancel` can stop only the named turn. |
|
|
648
658
|
| `participant_revise` | chi web can pass a participant's Revise draft for worker-side validation. |
|
|
649
659
|
| `participant_client_id` | chi web can identify a participant as `participant:<id>` instead of using the legacy `review:<id>`. |
|
|
660
|
+
| `working_set_item` | `GET /session/:id/working_set/item` answers one item's timeline (the running turn's mid-turn), so chi web asks for it instead of the whole snapshot. |
|
|
650
661
|
|
|
651
662
|
`chi web`'s `GET /api/sessions/:id/stream` proxies this bridge
|
|
652
663
|
(503 `not_live` for no worker, a leaving or stuck worker, or an unreachable Bridge; 502 `worker_newer` for skew and
|
data/docs/internals/bundles.md
CHANGED
|
@@ -108,9 +108,10 @@ back to the source dir.
|
|
|
108
108
|
Class-file hooks (retired). A record an older chi installed may still have a `hooks` map and `hooks/*.rb`
|
|
109
109
|
(`InstalledBundle#hooks`). Nothing loads them, and nothing announces them any more (the first turn, `chi bundle
|
|
110
110
|
status` and `chi update` did from 0.158 to 0.166). A source with
|
|
111
|
-
hooks is refused before its manifest is read (`
|
|
112
|
-
run too; `ShippedUpdate`'s plan skips one the same way. Over such a record,
|
|
113
|
-
plugin and scripts
|
|
111
|
+
hooks is refused before its manifest is read (`Manifest::HooksRetired.refuse_source_files`, then `Manifest.read`),
|
|
112
|
+
strict or not, a dry run too; `ShippedUpdate`'s plan skips one the same way. Over such a record,
|
|
113
|
+
after the plugin and scripts (so a refused install leaves them), `AssetInstaller#retire_hooks` copies every edited or
|
|
114
|
+
unknown file under `hooks/` to the trash
|
|
114
115
|
(`Trash#copy_edits` with the recorded shas; a dev link never), removes the dir and records each as `:removed` (a dry
|
|
115
116
|
run's `:would_remove`) with the `AssetInstaller::RETIRED` note, which `#summary` lists on a line of
|
|
116
117
|
its own; `ShippedUpdate#trash_bound` names the same files (`Trash.edits` over `hooks/`). `Provenance#write` records
|
|
@@ -463,8 +463,8 @@ headers alike. A revoked or expired grant is refused by the gate (401) as on eve
|
|
|
463
463
|
|
|
464
464
|
**Their turn** takes only refs they uploaded ([Turns](#turns)); **what they see** is their own images as thumbnails
|
|
465
465
|
and anyone else's as "N images" ([What a participant sees](#what-a-participant-sees)). A corrupt or unreadable
|
|
466
|
-
record fails closed (every grant at quota, owning nothing, `Log.warn`
|
|
467
|
-
of theirs gives the text back with its chips (`prompt_restored`, below).
|
|
466
|
+
record fails closed (every grant at quota, owning nothing, `Log.warn` once per `(path, size, mtime)` state); the
|
|
467
|
+
owner can delete the file. A failed turn of theirs gives the text back with its chips (`prompt_restored`, below).
|
|
468
468
|
|
|
469
469
|
## What a participant sees
|
|
470
470
|
|
|
@@ -493,8 +493,9 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
493
493
|
`ParticipantAccess#own_turn?`; `input_merged`: the count and origins of their own lines only), anyone else's bare;
|
|
494
494
|
`prompt_restored` (a failed turn's prompt handed back, **their own turn only**: the origin's server-stamped author
|
|
495
495
|
is theirs; another person's, the owner's and an author-less one's give nothing; carries `prompt`, `images` as their
|
|
496
|
-
own refs (`.image_refs`), `revises: {turn_id}
|
|
497
|
-
|
|
496
|
+
own refs (`.image_refs`), `revises: {turn_id}`, `origin: {client_id, enqueued_id, author}` and a parsed Verify
|
|
497
|
+
claim as `verify: {turn_id, quote}`; malformed or boolean claims are omitted. Never `source`, the error or any
|
|
498
|
+
other field; the page refills its composer as the owner's, `restore.js`);
|
|
498
499
|
`question_requested` and `continue_offered` with one derived `kind` (`.waiting_kind`: `approval` for a guardrail's
|
|
499
500
|
approval or a relayed one, `continue` for the step-limit question and every offer, `question` else); the main
|
|
500
501
|
page's numbers (`context_status`: usage's `estimated_pct` and token counts, `bucket`, a switch's
|
|
@@ -620,7 +621,9 @@ owner's machine (`home`, the folders, `project-*`, `back-*`).
|
|
|
620
621
|
- **Verify verdict cards** (`verdict_card.js`). The built-in Verify preset carries the selected source turn id and quote
|
|
621
622
|
with the submitted turn, without changing its prompt text. A Verify turn that fails fast and is rolled back hands
|
|
622
623
|
the claim back with its prompt (`prompt_restored`'s `verify`), so the owner's resend from the composer is a Verify
|
|
623
|
-
turn again.
|
|
624
|
+
turn again. A participant's own failed turn also gets its parsed `verify` claim in `prompt_restored` (see
|
|
625
|
+
[What a participant sees](#what-a-participant-sees)). Before the Engine stamps the anchor or records a verdict,
|
|
626
|
+
it checks that the source turn exists and
|
|
624
627
|
its final assistant reply (`AnswerTail`: the turn's last assistant message with text) contains the quote. Matching is case-sensitive, collapses whitespace, and strips common
|
|
625
628
|
Markdown presentation (links, headings, list/blockquote prefixes, emphasis and code delimiters) from both sides;
|
|
626
629
|
this matches the rendered text the page selects without treating different casing as the same claim. The quote may
|
|
@@ -133,7 +133,12 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
|
|
|
133
133
|
`ArgumentError` for another `not_found`, `Session::AmbiguousId`,
|
|
134
134
|
`SessionManager::OwnedByTUI` / `DeleteRefused` / `ArchiveRefused` / `RestartRefused`, `SessionContinue::Refused`,
|
|
135
135
|
and `ModelProfile::MissingModel` for `invalid_model` (no model there, or `--model`'s host unknown there: "could not
|
|
136
|
-
start a session: …", exit 1, as here).
|
|
136
|
+
start a session: …", exit 1, as here). A delete's or archive's `409 tasks_running` carries `op` (`delete` or
|
|
137
|
+
`archive`), `tasks` (`{running, unverified, unreadable}`), `worker_stopped`, `stopped_worker` (whose; an older chi web sends only the Boolean) and a chain's `links`: `raise_refusal`
|
|
138
|
+
rebuilds `DeleteRefused` or `ArchiveRefused` by `op`, with the `RunningTasks::Listing`, and makes the words here
|
|
139
|
+
(`RunningTasks.words`), not from chi web's `message`. Its own code, not archive's `busy`: an older client prints
|
|
140
|
+
`RemoteFailed "… answered 409 tasks_running: …"` rather than "a turn is running". `--stop-tasks` asks for the
|
|
141
|
+
`stop_tasks` feature first (`RemoteTooOld` without it).
|
|
137
142
|
Checks the client would make locally come back as `SessionAccess::Refused` (`parent_answers_refused`,
|
|
138
143
|
`parent_continue_refused`, `no_vision`, exit 1) or `BadRequest` (the other `invalid_*`, `missing_fields`, `bad_images`,
|
|
139
144
|
exit 2, the usage-error path). That is for the routes `raise_refusal` reads (create, uploads, …). `POST …/turn` is
|