samagotchi 0.176.0 → 0.177.1
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 +47 -1
- data/docs/architecture.md +5 -4
- data/docs/cli.md +12 -5
- data/docs/internals/bundles.md +4 -3
- data/docs/internals/participants.md +10 -6
- data/docs/internals/prompt-caching.md +3 -0
- data/docs/internals/session-lifecycle.md +167 -0
- data/docs/internals/web-frontend.md +25 -8
- data/docs/internals/working-set.md +78 -6
- data/docs/plugins.md +1 -1
- data/docs/releasing.md +3 -2
- data/docs/sessions.md +8 -5
- data/docs/testing.md +4 -2
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/compat.rb +1 -1
- data/lib/samagotchi/engine/models.rb +11 -0
- data/lib/samagotchi/engine/session.rb +16 -0
- data/lib/samagotchi/engine.rb +1 -0
- data/lib/samagotchi/engine_snapshots.rb +3 -0
- 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/prompt_part.rb +66 -0
- data/lib/samagotchi/revise_anchor.rb +2 -0
- data/lib/samagotchi/schedules.rb +3 -1
- data/lib/samagotchi/session.rb +10 -1
- data/lib/samagotchi/session_chain/delete.rb +28 -5
- data/lib/samagotchi/session_chain/delete_preview.rb +2 -2
- data/lib/samagotchi/session_inbox.rb +29 -0
- data/lib/samagotchi/session_inbox_delivery.rb +13 -5
- data/lib/samagotchi/session_lifecycle/allowed.rb +66 -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 +22 -14
- data/lib/samagotchi/session_manager/removal.rb +16 -8
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +211 -12
- data/lib/samagotchi/tool_names.rb +1 -1
- data/lib/samagotchi/tools/memory.rb +29 -0
- 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/participant_show.rb +4 -5
- data/lib/samagotchi/web/participant_view.rb +4 -6
- data/lib/samagotchi/web/public/app.js +3 -0
- data/lib/samagotchi/web/public/ctx_tokens.js +33 -0
- data/lib/samagotchi/web/public/data.js +6 -2
- data/lib/samagotchi/web/public/delete_sheet.js +42 -5
- data/lib/samagotchi/web/public/index.html +43 -9
- data/lib/samagotchi/web/public/session_fields.js +10 -4
- data/lib/samagotchi/web/public/session_prefs.js +5 -2
- data/lib/samagotchi/web/public/session_state.js +14 -1
- data/lib/samagotchi/web/public/session_store.js +1 -1
- data/lib/samagotchi/web/public/session_view.js +1 -1
- data/lib/samagotchi/web/public/stream_handlers.js +7 -3
- data/lib/samagotchi/web/public/tokens.css +2 -2
- data/lib/samagotchi/web/public/working_set.js +51 -7
- data/lib/samagotchi/web/public/working_set_view.js +188 -58
- data/lib/samagotchi/web/public/ws_sections.js +252 -0
- data/lib/samagotchi/web/session_control.rb +4 -3
- data/lib/samagotchi/web/session_show.rb +13 -2
- data/lib/samagotchi/web/session_summary.rb +7 -0
- data/lib/samagotchi/worker/command_queue.rb +5 -1
- data/lib/samagotchi/worker/startup.rb +1 -1
- data/lib/samagotchi/worker.rb +1 -0
- data/lib/samagotchi/worker_boot.rb +9 -6
- data/lib/samagotchi/worker_presence.rb +4 -0
- data/lib/samagotchi/working_set.rb +32 -4
- data/lib/samagotchi/working_set_command.rb +3 -2
- data/lib/samagotchi/working_set_steer.rb +14 -3
- 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: 4a5b330c47fac34a4e9fd4c2d602e4cbc0241fe42a953bba227b6526ef619e7b
|
|
4
|
+
data.tar.gz: 4c9ae4e9df6279202aa9540984c70148ef1ea6d2e9898542cb219ab1980b6f14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc2236c6ee5a909b4cfef2b66ab813b1546b9c8fe432734aec2909f84703cbe3dba48491a0e1a02f115650c9252ce9d087ea9e1b8dba327b61e5b483a9541d47
|
|
7
|
+
data.tar.gz: a5b1653706fd962459dd639a4487d45bb28e96cdf3e022148d3fe4ce19967c84dd5a911d2f9014ad778c75945dfb0194b5c682549dd5fb39ec0c4886b3c0f65d
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,50 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.177.1] - 2026-11-19
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- chi web: deleting a chained session no longer deletes more than the sheet showed when something changed since it
|
|
16
|
+
opened (a delegate that finished, a schedule, a continue); the sheet shows the new plan to confirm.
|
|
17
|
+
- chi web: a participant's failed Verify turn comes back in their composer as a Verify turn, not plain text.
|
|
18
|
+
- `/working-set add system/x` is no longer refused as "already in the system prompt" when only a project memory x
|
|
19
|
+
is there (and the reverse); a bare name still matches either scope.
|
|
20
|
+
- A message sent to a session while it is being deleted is refused ("the session is being deleted") instead of being
|
|
21
|
+
reported delivered and then lost.
|
|
22
|
+
- `chi sessions restart` (and the web's restart) of a stopped session, or one being stopped, is refused at once with
|
|
23
|
+
what to do, instead of waiting for a restart that never comes.
|
|
24
|
+
|
|
25
|
+
Update with `chi update`.
|
|
26
|
+
|
|
27
|
+
## [0.177.0] - 2026-11-17
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- chi web: the working-set list is now a view of what is in chi's head, in three groups: **From the start** (every
|
|
32
|
+
part of the system prompt, with its size: tools, the base prompt, the identity memory, model notes, preloaded
|
|
33
|
+
memories, AGENTS.md, plugin sections, the memory indexes), **Read in this session** (files, memories and URLs) and
|
|
34
|
+
**Conversation** (the rest of the context). The line under the header says how much is in chi's head now. Each
|
|
35
|
+
group folds, and the fold is kept per session.
|
|
36
|
+
- chi web: the list's turn picker is a lens. Picking a turn (the arrows, a footprint, the rail) keeps the whole list
|
|
37
|
+
and lights the rows that turn touched with its step tags; the rest dim. The line under the header says what the
|
|
38
|
+
turn touched and how many items were new.
|
|
39
|
+
- chi web: a memory that is in the system prompt and was also read again shows "held twice", with the extra size.
|
|
40
|
+
- Sessions record the sizes of their system prompt's parts (`prompt_parts`), which the list above reads.
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
- chi web: the working-set list's header no longer shows "N items · ctx %"; the line under it does. On the phone the
|
|
45
|
+
header fits on one line, and the list's rows and buttons are 44 px tall.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- chi web: the working-set list includes model notes in the system prompt and redraws an open list when notes change.
|
|
50
|
+
- /working-set add: refuse to re-read a memory already in the system prompt unless its output is in the working set.
|
|
51
|
+
- chi web: a project memory and a system memory with the same name are no longer shown as one row.
|
|
52
|
+
|
|
53
|
+
Update with `chi update`.
|
|
54
|
+
|
|
11
55
|
## [0.176.0] - 2026-11-16
|
|
12
56
|
|
|
13
57
|
### Added
|
|
@@ -6452,7 +6496,9 @@ and long-lived sessions.
|
|
|
6452
6496
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6453
6497
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6454
6498
|
|
|
6455
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
6499
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.177.1...HEAD
|
|
6500
|
+
[0.177.1]: https://github.com/dm1try/samagotchi/compare/v0.177.0...v0.177.1
|
|
6501
|
+
[0.177.0]: https://github.com/dm1try/samagotchi/compare/v0.176.0...v0.177.0
|
|
6456
6502
|
[0.176.0]: https://github.com/dm1try/samagotchi/compare/v0.175.0...v0.176.0
|
|
6457
6503
|
[0.175.0]: https://github.com/dm1try/samagotchi/compare/v0.174.0...v0.175.0
|
|
6458
6504
|
[0.174.0]: https://github.com/dm1try/samagotchi/compare/v0.173.0...v0.174.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
|
@@ -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
|
|
@@ -1387,11 +1390,15 @@ session bar shows the `mem N` chip again.
|
|
|
1387
1390
|
tooltip goes too): the session's whole set, preloaded (`--memory`) and muted
|
|
1388
1391
|
(`--mute`) memories included; its dot lights when the set changed since you
|
|
1389
1392
|
last opened it.
|
|
1390
|
-
- **The list** the three open (a bottom sheet on a phone):
|
|
1391
|
-
|
|
1393
|
+
- **The list** the three open (a bottom sheet on a phone): always the whole
|
|
1394
|
+
session's set, files grouped by folder (a group opens in place), memories
|
|
1392
1395
|
(used, preloaded, muted) and URLs, each with what was done to it (`read ×2`,
|
|
1393
|
-
`read, edited`, `preloaded`) and a step tag (`s3`, `
|
|
1394
|
-
|
|
1396
|
+
`read, edited`, `preloaded`) and a step tag (`t2·s3`, `prompt` for a preloaded
|
|
1397
|
+
memory) that goes to the call. The header's `session | ‹ turn N ›` is a lens:
|
|
1398
|
+
the chip opens the session, a footprint or the rail opens a turn, and `‹` `›`
|
|
1399
|
+
step through the turns. In a turn's lens the rows that turn touched are lit,
|
|
1400
|
+
with that turn's words and step tag (`s3`), the others dimmed; the line under
|
|
1401
|
+
the header says `turn 2 touched 3 · 1 new`; a folded group still shows its lit rows. A file opens
|
|
1395
1402
|
as its row's title does, a URL in a new tab. A row (on hover or keyboard
|
|
1396
1403
|
focus) and a folded group offer `drop`, which runs `/working-set drop` (see
|
|
1397
1404
|
`/working-set` above); a dropped row offers `undrop`, and so does one whose
|
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
|
|
@@ -537,7 +538,8 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
537
538
|
- **The queue.** Their own queued turns (enqueued id and text, for Take back) and how many others wait.
|
|
538
539
|
- **The working set** (`.working_set`: the event and `GET …/working_set`): the file items inside the project, the
|
|
539
540
|
key made relative, with `state`, `tokens`, `ops`, `count`, `pinned`, and the set's `at`. Never a memory or URL
|
|
540
|
-
item, a path outside the project, `first_id`, `has_drop` or the pending `adds`.
|
|
541
|
+
item, a path outside the project, `first_id`, `has_drop` or the pending `adds`. A memory item's `scope` and the
|
|
542
|
+
prompt parts' `scope` reach no participant either: memory items are dropped and their `prompt_parts` is `[]`.
|
|
541
543
|
|
|
542
544
|
### The main page's show
|
|
543
545
|
|
|
@@ -619,7 +621,9 @@ owner's machine (`home`, the folders, `project-*`, `back-*`).
|
|
|
619
621
|
- **Verify verdict cards** (`verdict_card.js`). The built-in Verify preset carries the selected source turn id and quote
|
|
620
622
|
with the submitted turn, without changing its prompt text. A Verify turn that fails fast and is rolled back hands
|
|
621
623
|
the claim back with its prompt (`prompt_restored`'s `verify`), so the owner's resend from the composer is a Verify
|
|
622
|
-
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
|
|
623
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
|
|
624
628
|
Markdown presentation (links, headings, list/blockquote prefixes, emphasis and code delimiters) from both sides;
|
|
625
629
|
this matches the rendered text the page selects without treating different casing as the same claim. The quote may
|
|
@@ -63,6 +63,9 @@ right-hand column happens.
|
|
|
63
63
|
└──────────────────────────────────────────────────────────────────────────┘
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
- The sections above are recorded as `prompt_parts` (`SystemPrompt#prompt_parts`, `PromptPart`: kind, label, chars,
|
|
67
|
+
tokens at `TokenUsage::CHARS_PER_TOKEN`, ref, a memory part's scope; one per memory, file and plugin section, plus a
|
|
68
|
+
`tools` part): sizes only, worked out once with the build and saved on the session; the prompt's text is unchanged.
|
|
66
69
|
- The system prompt is built **once per key** and kept (`SystemPrompt#build`, keyed by `[chat, thinking, layers]`:
|
|
67
70
|
the loop, the thinking level, the turn's LLM context layers; a `/thinking` change builds under another key). All
|
|
68
71
|
of them are dropped only on `@prompt_builder.reset!`: a model switch (`Engine#switch_model!`), a plugin's
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Session lifecycle
|
|
2
|
+
|
|
3
|
+
There is no persisted lifecycle enum. A state is derived from the session file, sidecar files, locks, and the worker
|
|
4
|
+
link: `SessionLifecycle.read(id)` (`session_lifecycle.rb`) reads them once (`WorkerPresence` with its link looked at,
|
|
5
|
+
never unlinked, and `ContinueIntent.in_flight`) and names the first of its 15 states whose facts hold (Derived states).
|
|
6
|
+
The same session can satisfy more than one fact (archived while its worker is leaving); the precedence picks one. One
|
|
7
|
+
decider reads `SessionLifecycle`: `restart_session`'s precheck (Allowed operations). The others still read their own
|
|
8
|
+
subset of the facts in their own order, and what each answers per state is `ALLOWED` (Allowed operations), pinned by
|
|
9
|
+
the characterization matrix. The session file layout and user-facing session behavior are in [Sessions](../sessions.md); the Worker and
|
|
10
|
+
SessionManager boundaries are in [Architecture](../architecture.md) and [Engine internals](engine.md).
|
|
11
|
+
|
|
12
|
+
## Facts and markers
|
|
13
|
+
|
|
14
|
+
| Fact | Writer and removal | Cross-process readers and how they see change |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| `<id>.json` `status` | `Session#save` writes the session snapshot; the owner is the normal writer. `Session#load` overlays `stopped` as `stopped` without rewriting the file. | `SessionRow` and `SessionAccess::Local` read saved turn status; stop cancellation, restart fallback, and archive refusal also use it as a busy hint. Readers reload the file; the hub refreshes rows on its tick. It is turn state, not proof of liveness. |
|
|
17
|
+
| `starting` (`{pid, at}`) | `SpawnPart#spawn_session` marks before the first session file; `#spawn_worker_for_session` marks around `Process.spawn`; `#claim_start` claims with `StartingMarker.claim`. Failures clear it; `Worker#start` clears it after acquiring `owner.lock`. A stale/dead marker is taken over after 60 seconds or when its pid is gone. | `WorkerPresence`, resume, archive, delete, and retention read it directly; `WorkerPresence` checks age and pid. The session hub also refreshes presence. The atomic hard-link claim arbitrates competing starters; there is no event notification. |
|
|
18
|
+
| `owner.lock` and `leaving_at` | `OwnerLock.acquire` creates the file, takes its exclusive flock, and writes `{pid, kind, started_at}`; `OwnerLock#mark_leaving` adds `leaving_at` and `leave_wait`; `#release` unlocks and closes but leaves the file. Deletion removes it with the session directory. | `OwnerLock.owner` probes the kernel flock, then reads the record. The kernel releases the lock on process death; the record alone does not establish ownership. Presence and `WorkerLink` decisions probe it; hub presence refreshes poll it. `leaving_at` marks a worker that closed its Bridge but still holds the lock for leave work. |
|
|
19
|
+
| `bridge.json` | `Bridge#write_sidecar` publishes the worker endpoint; `Bridge#remove_sidecar` removes its own sidecar when stopping. A crash can leave it behind. | `WorkerLink.resolve` combines the sidecar with `owner.lock` and pid; a sidecar alone is stale. Readers waiting for a worker poll `WorkerLink.resolve`; a stale unlink rechecks the owner and removes only the unchanged file. Live clients see worker events over Bridge SSE. |
|
|
20
|
+
| In-memory exit claim | `Worker#exit_request` uses `WorkerExitClaim#claim`, `#accept`, `#release` and `#forget`; `#stopped!` records the last stop-all. It dies with that Worker. | Only that worker's threads read it; the Bridge's `/exit` and the loop coordinate through the Engine event lock, not a cross-process file. |
|
|
21
|
+
| `stopped` | `SessionManager#stop_session` calls `Session.mark_stopped`; `SpawnPart#resume` and delivery's `#start_for_send` clear it with `Session.clear_stopped` when starting for a person. Session-directory deletion removes it. | `WorkerPresence`, the worker startup/signal paths, and `Session#load` check the marker. It is read from disk on a decision (and on the hub refresh); no worker event is required. Its timestamp is compared with `starting.at` so a stop cancels an older start, not a later resume. |
|
|
22
|
+
| `archived` | `ArchiveStore.archive` is called by `SessionManager#archive_session`; `ArchiveStore.unarchive` is called by `#unarchive_session`, `SessionContinue#undo_failed_continue`, and the chain-delete undo/revival paths. Session-directory deletion removes it. | Lists, chain resolution, delivery, schedules, retention, and `WorkerPresence` call `ArchiveStore.archived?` against the file; changes are seen by the next read or list refresh. |
|
|
23
|
+
| `continue.lock` and `continue.json` | `SessionContinue#with_lock` takes the exclusive lock for a continue; `ContinueIntent#hold` takes a nonblocking shared lock for readers that must exclude a continue. `ContinueIntent#write` records the successor before archive and updates the archived ids after; failed-continue cleanup removes the intent. The lock file remains until session-directory deletion. | Followed sends, schedules, chain deletion, and `ContinueIntent.in_flight` inspect the lock and intent. flock coordinates the live transition; readers reload the JSON. An intent without a held lock is a crashed continue, not an active one. |
|
|
24
|
+
| `parent.json` | `Session#reparent` writes the override when `ChildMove` moves a child. Session-directory deletion removes it. | `ChildReports` resolves the current parent when routing a ring; the worker reads the override when loading its parent. Readers reload the file; it is not an event stream. |
|
|
25
|
+
| `reminders.json` | `Worker::LeavePart#carry_reminders` writes it for an asked restart, or removes it when stopped/no successor; stop, archive, and a stopped restart also remove it. `ReminderCarry#take` reads and removes it at worker start. | Only the next worker restores it into its Engine. It is a one-shot hand-off, not polled state; the session id, 120-second window, and stop marker are checked before restore. |
|
|
26
|
+
| Pending `input/`, `children/`, and `notes/` | `SessionInbox.write_input`, `#write_ring`, and `#write_note` write the files. A worker claims input and notes by atomic rename to `.processing`, then removes or settles them; rings are consumed by `ChildReports`. Session-directory deletion removes all three. | The worker checks input around turns and on its idle loop; rings and notes are checked by worker wake/absorption paths. The file is the durable queue; Bridge SSE can announce a live turn, but the worker's file scan is the fallback and recovery path. |
|
|
27
|
+
| Turn checkpoint and pending question | `TurnCheckpoint` writes the running turn overlay at iteration boundaries and clears it at settlement/end; `QuestionDesk` updates `Session#pending_question`, persisted by `Session#save` and cleared on answer/settlement. | The next worker settles a checkpoint on startup instead of replaying the dead turn. Session readers and Bridge snapshots read the pending question; answers go through the live Bridge when present. These are session data, not liveness locks. |
|
|
28
|
+
| `scratch` | `SpawnPart#spawn_session` saves the flag in the session file. There is no separate marker; terminal/worker cleanup deletes the scratch session. | Inbox wake policy and worker boot read the session field. Scratch sessions are not resumed by ordinary delivery; their worker is removed when its terminal leaves. |
|
|
29
|
+
|
|
30
|
+
`SessionStores` registers cross-version sidecar ownership and removal with the session directory. The lists above focus on
|
|
31
|
+
the lifecycle facts; deletion takes the session's `owner.lock` as `deleting`, rechecks `starting`, then removes the JSON
|
|
32
|
+
and entire sidecar directory.
|
|
33
|
+
|
|
34
|
+
## Derived states
|
|
35
|
+
|
|
36
|
+
`SessionLifecycle::STATES`, in precedence order (the first whose facts hold wins), as `Reading.derive` names them from a
|
|
37
|
+
`WorkerPresence` read with its link (`SessionLifecycle::Reading`: `state`, `presence` (also `facts`), `continuing`).
|
|
38
|
+
These are reader labels, not stored values:
|
|
39
|
+
|
|
40
|
+
| State | Facts that produce it |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `absent` | No session file; a leftover sidecar directory may still exist (its facts are ignored). |
|
|
43
|
+
| `tui_owned` | `owner.lock` held with kind `tui` (a one-shot `chi -p --non-interactive` owns it): an in-process one-turn host, not a worker. Wins over a stop, a start, an archive. |
|
|
44
|
+
| `deleting` | `owner.lock` held with kind `deleting` while the session's files go (`WorkerLink` reads it as `Starting`). Every delivery is refused (`WakePolicy`'s `:deleting`). |
|
|
45
|
+
| `stopping` | A worker holds the lock and the `stopped` marker exists, whatever its link. |
|
|
46
|
+
| `skew` | A worker holds the lock and its sidecar speaks a newer protocol (`WorkerLink::Skew`). |
|
|
47
|
+
| `leaving` | The worker closed its Bridge and still holds the lock (`leaving_at`, `WorkerLink::Leaving`). |
|
|
48
|
+
| `booting_stuck` | A worker has held the lock past `WorkerLink::START_LIMIT` without its sidecar (`Starting`, stuck). |
|
|
49
|
+
| `booting` | A worker holds the lock without its matching sidecar yet (`Starting`); also an owner of unknown kind (a lock record still blank after `OWNER_READ_ATTEMPTS`). |
|
|
50
|
+
| `live` | A worker holds the lock and its sidecar matches it (`WorkerLink::Live`). |
|
|
51
|
+
| `stopped_starting` | No owner; the `stopped` marker and a fresh `starting` marker (archived or not). |
|
|
52
|
+
| `stopped` | No owner; the `stopped` marker (archived or not). |
|
|
53
|
+
| `archived_starting` | No owner, no stop; `archived` and a fresh `starting` marker. |
|
|
54
|
+
| `starting` | No owner, no stop, not archived; a fresh `starting` marker names a live starter. |
|
|
55
|
+
| `archived` | No owner, no stop, no start; `archived` has `archived_at`. |
|
|
56
|
+
| `idle` | The session exists with none of the above. |
|
|
57
|
+
|
|
58
|
+
The compound states exist because the deciders disagree on precedence: owner first (WakePolicy, resume, archive,
|
|
59
|
+
delete) or stop first (a schedule's busy check, a terminal's attach); WakePolicy reads archived before starting. Facts
|
|
60
|
+
that are not states: `continuing` (`continue.json` names a successor and `continue.lock` is held: only a send's and a
|
|
61
|
+
schedule's link resolution reads it), a stale sidecar (`WorkerLink::Stale`: a crashed worker's leftover, reads as
|
|
62
|
+
the no-owner state), and the other crashed leftovers (a checkpoint, a `.processing` file, an unlocked continue intent).
|
|
63
|
+
`SessionLifecycle::CANONICAL` holds the fewest facts per state, each deriving back to it; `stopping` is a worker whose
|
|
64
|
+
Bridge answers, with a stop, and `stopped_starting` a start marked before the stop.
|
|
65
|
+
|
|
66
|
+
A read costs what `WorkerPresence.read(link: :look)` costs plus a `continue.json` stat: idle about 8 probes and one
|
|
67
|
+
flock, no JSON (~20–50 µs); a live worker adds the owner record and `bridge.json` (~0.1–0.2 ms); a continue in flight a
|
|
68
|
+
lock probe and its JSON. The worst case is `OwnerLock.owner`'s blank-record retry (0.1 s).
|
|
69
|
+
|
|
70
|
+
## Allowed operations
|
|
71
|
+
|
|
72
|
+
`SessionLifecycle::ALLOWED` (`session_lifecycle/allowed.rb`) is `{op => {state => cell}}`: every operation in every
|
|
73
|
+
state. A cell is `:go`, `:wait` or the decider's own refusal reason; `SessionLifecycle.verdict(op, cell)` reads it as
|
|
74
|
+
`:go`, `:wait` or `:refused` (resume's `live` and `starting` wait, restart's `fallback` goes).
|
|
75
|
+
|
|
76
|
+
- **Delivery columns** (send, note, push, ring, fresh_verdict, leave, schedule, plugin, delegate, participant,
|
|
77
|
+
automatic) are generated at load from `SessionInbox::WakePolicy::ROWS`, unchanged: each row's `decide` on
|
|
78
|
+
`CANONICAL[state]` (a worker asked for, no scratch file), `:start`/`:live` as go, `:starting`/`:stopped`/
|
|
79
|
+
`:archived`/`:none` as wait, `:gone`/`:owned`/`:deleting` as themselves. `:off` and `:scratch` are op-local.
|
|
80
|
+
`deleting` refuses every kind: `WakePolicy#refusal` before the write (nothing written), `#decide` after it (a
|
|
81
|
+
delete that took the lock between the two). What each kind does then: a turn delivery (`deliver_turn`, any sender)
|
|
82
|
+
answers 409 `DeliverResult::DELETING` ("the session is being deleted") and after its write takes its file back
|
|
83
|
+
(`SessionInbox.withdraw`; a file a worker claimed meanwhile stays delivered), also when the session went while it
|
|
84
|
+
wrote (and a folder the write made again goes); a note is a gone session's (`Session::NotFound`, its note taken
|
|
85
|
+
back); a ring, a push and a fresh verdict are refused before their write as for a gone parent (a push records to
|
|
86
|
+
its source's folder as for a gone session), and `wake_for_report` answers `:deleting`; a leave's respawn drops
|
|
87
|
+
(`why: deleting`).
|
|
88
|
+
- **Literal columns** (`LITERAL`): resume (`resume_session`), restart (`restart_session`: `stop_marked` in every
|
|
89
|
+
state with the stop marked: stopping, stopped, stopped_starting), stop (`stop_session`),
|
|
90
|
+
archive (`archivable!`), delete (`release_for_delete!`, without a stop), sched_chain and sched_same
|
|
91
|
+
(`Schedules#busy_reason`; `worker_busy` is "its worker is starting or leaving") and attach
|
|
92
|
+
(`TerminalUI::LocalLink#live_worker`: `gone_stopped`, `gone_worker_newer`). They assume neutral op-local facts: not
|
|
93
|
+
scratch, saved status idle, no `input/`, no question or offer, not SIGSTOPped, features restart and activity, an idle
|
|
94
|
+
worker with no streams. Absent's delete and schedule cells are unreachable (a gone session is refused first).
|
|
95
|
+
|
|
96
|
+
Link resolution (`SessionInbox::Head.resolve`, `Schedules#target_of`) stays outside: the cells are the link's own.
|
|
97
|
+
|
|
98
|
+
`restart_session` is the first decider migrated to the table: its lifecycle precheck is `SessionLifecycle.read` (the
|
|
99
|
+
owner read through `session_owner`) and `ALLOWED[:restart]`: `owned_by_tui` raises `OwnedByTUI`, a refusal cell
|
|
100
|
+
raises `RestartRefused` with it as the reason (`starting`, `not_running`, `stop_marked`), `fallback` goes to
|
|
101
|
+
`restart_fallback` (skew, a stuck start) and `go` asks the live worker. Its op-local checks stay where they were: the
|
|
102
|
+
SIGSTOP check (`:stopped`, the worker's pid: a different condition with its own words, before the table's refusal),
|
|
103
|
+
the worker's `restart` feature, the Bridge's reply and the fallback's holds. The matrix still drives it, so its
|
|
104
|
+
column is pinned against the precheck and the op-local paths together. The other deciders don't read `ALLOWED` yet.
|
|
105
|
+
|
|
106
|
+
## Characterization matrix
|
|
107
|
+
|
|
108
|
+
`spec/session_lifecycle/matrix_spec.rb` (rows, files and drivers in `spec/support/lifecycle_matrix.rb`) writes every
|
|
109
|
+
combination as real files: owner/link pairs (none, stale sidecar, tui, tui with a stale sidecar, deleting, a worker
|
|
110
|
+
Live, Starting, stuck, Leaving, Skew, an owner of unknown kind) × stop × starting × archived, one absent session, a
|
|
111
|
+
continue in flight on each archived no-owner row, and a start marked after the stop on each no-owner row with both
|
|
112
|
+
(the order is a row fact: `StartingMarker.claim` takes over only a start at or before `stopped_at`). The owner lock's
|
|
113
|
+
holder, `ContinueIntent.in_flight`, `Process.spawn`, TERM/CONT, the Bridge and the restart fallback are stubbed; no
|
|
114
|
+
process starts. Each row checks that `SessionLifecycle.read` names the state its facts derive, then drives every
|
|
115
|
+
operation (one driver each, every private reach in that one file) and projects its answer into a cell. A row the
|
|
116
|
+
code can't make (a one-turn run's lock with a stop) is marked `reachable: false` with its note and still asserted.
|
|
117
|
+
|
|
118
|
+
Every answer must equal `ALLOWED[op][state]` (for the session hub, `SHOWN[state]`: `Web::SessionSummary.build`'s
|
|
119
|
+
status and bridge_up, its `SessionRow`'s live), or be named by exactly one `KNOWN_DIFFERENCES` entry (op, a `when`
|
|
120
|
+
over the row, a plain reason); an entry that names no mismatch fails as stale. The entries are the findings for the
|
|
121
|
+
owner, not fixed: stop-first schedule and attach checks under a one-turn run's, a deleter's or an unknown owner's lock;
|
|
122
|
+
chain mode's starting check before any one-turn-run check; a start marked after the stop holding a resume off;
|
|
123
|
+
`wake_for_report` reporting a worker's `:live` as `:owned`; the hub's bridge_up, live and status overlay. (Restart
|
|
124
|
+
never reading the stop and `busy_reason`'s live branch falling through to the starting check were fixed: their
|
|
125
|
+
entries went stale and were removed.) The delivery columns are
|
|
126
|
+
generated from `WakePolicy::ROWS`, so for deliveries the matrix proves the states are drawn right (decide is a function
|
|
127
|
+
of the state), not what WakePolicy does; the literal columns and `SHOWN` are goldens.
|
|
128
|
+
|
|
129
|
+
## Locks and crash repair
|
|
130
|
+
|
|
131
|
+
`owner.lock` is the single-owner boundary for an Engine; its flock is released by process death. A starting claim uses
|
|
132
|
+
an atomic link rather than a long-held lock. A continue holds its exclusive `continue.lock` across the transition;
|
|
133
|
+
shared holds protect followed sends and chain operations. When chain deletion nests locks, it takes the continue hold
|
|
134
|
+
before the `owner.lock` deletion locks. Inside a worker, the lock order is Engine event lock, then
|
|
135
|
+
`WorkerExitClaim`'s mutex. Session saves serialize through their per-session save lock. These locks protect separate
|
|
136
|
+
facts; there is no global lifecycle lock or atomic snapshot across all markers.
|
|
137
|
+
|
|
138
|
+
A worker that crashes exits 1 and is not respawned just because input is queued. A later delivery may start a new
|
|
139
|
+
worker; under its owner lock, startup settles a turn checkpoint and stale running status rather than replaying the
|
|
140
|
+
dead turn. Interrupted continue intents are repaired separately by session listing/the web hub or before another
|
|
141
|
+
continue (`SessionContinue.repair_interrupted`), not by worker startup.
|
|
142
|
+
|
|
143
|
+
## Open windows
|
|
144
|
+
|
|
145
|
+
These are documented race boundaries, not promises of an atomic lifecycle transition:
|
|
146
|
+
|
|
147
|
+
| Window | Code comment / current behavior | Pin |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| A ring wake decides to start, then a stop lands before resume. | `SpawnPart#wake_for_report` (`session_manager/spawn.rb`): `resume_session` can clear that stop and start; the check and resume are not one transaction. | Unit spec: stop in the start callback and assert the worker is started and the marker cleared. |
|
|
150
|
+
| Empty-session discard races a delivery (closed for turns and notes). | `WorkerBoot#discard_left_session` (`worker_boot.rb`) checks emptiness after releasing the worker lock and again under the deletion lock (`delete_session`'s `still:`): a send or note that went in before the lock keeps the session. One that reads the session during the lock is refused (`DeliverResult::DELETING`, a note as gone); one that read it before the lock and wrote after it reads it again after its write and takes its file back (`SessionInbox.withdraw`), so no turn or note is reported delivered and then removed. No new lock: the write-then-reread and the recheck under the existing deletion lock close it. What remains: a ring or fresh verdict that read the session before the lock and wrote after it is not taken back: it goes with the directory, or stays for the next worker if the delete gives up; neither is reported to a person. | `run_session_loop_spec.rb`: a send at deletion-lock acquisition is refused; one just before the lock keeps the session. `delivery_spec.rb` / `note_delivery_spec.rb`: the lock (or the removal) between the check and the write, deterministic through the bridge / writer seam. |
|
|
151
|
+
| Stop reads an owner pid, then sends TERM. | `LifecyclePart#stop_session` (`session_manager/lifecycle.rb`): the pid can be reused between the owner read and `Process.kill`; protecting that requires a real pid-reuse scenario. | No unit pin: pid reuse/process signaling is not reliably representable without real processes. |
|
|
152
|
+
| Saved `status` is used as a lifecycle hint. | `LifecyclePart#restart_fallback_holds` and `RemovalPart#archive_refusal` (`session_manager/lifecycle.rb`, `session_manager/removal.rb`) use saved `running` status as a busy hint; status is not a lock or proof that a worker is alive. | Unit spec: pin fallback refusal from saved status without a live Bridge. |
|
|
153
|
+
| Stop/start ordering depends on wall-clock `at`. | `SpawnPart#claim_start` and `StartingMarker#claim` (`session_manager/spawn.rb`, `starting_marker.rb`) compare `starting.at` with `Session.stopped_at`; same-time starts are treated as before the stop. Clock adjustments across processes are not serialized. | Unit spec: pin the inclusive `at <= over_before` takeover boundary. |
|
|
154
|
+
| Several methods write or remove the same marker. | The definitions/callers in `session.rb`, `starting_marker.rb`, `archive_store.rb`, `bridge.rb`, and `reminder_carry.rb` are the source of truth; these APIs have multiple call sites. | `spec/session_lifecycle_writers_spec.rb` pins the call-site allow-lists; it does not claim their operations are one transaction. |
|
|
155
|
+
|
|
156
|
+
## Adding a transition
|
|
157
|
+
|
|
158
|
+
1. Name the fact being changed and its on-disk format; add cross-version handling to `SessionStores` when applicable.
|
|
159
|
+
2. Put the write/removal in its owning module and add the call site, with its reason, to
|
|
160
|
+
`spec/session_lifecycle_writers_spec.rb`.
|
|
161
|
+
3. Identify every decider that reads the fact and how it observes the change (lock probe, direct read, poll, or SSE).
|
|
162
|
+
4. If the change touches an open window above, extend its pin in the corresponding unit spec; don't hide a race with a
|
|
163
|
+
sleep or a process-wide integration test.
|
|
164
|
+
5. If the fact changes a state, update `SessionLifecycle::STATES`/`Reading.derive` and `CANONICAL`, then the
|
|
165
|
+
`ALLOWED` cells (the literal ones by hand; the delivery ones follow `WakePolicy::ROWS`) and the matrix's rows; a
|
|
166
|
+
decider that answers otherwise is a `KNOWN_DIFFERENCES` entry with its reason, never a silent cell change.
|
|
167
|
+
6. Recheck lock order, crash cleanup, and the existing file-format/compatibility specs before changing runtime behavior.
|
|
@@ -20,7 +20,9 @@ Verify, the composer's mode and the strip's hide went into modules of their own.
|
|
|
20
20
|
its own, wired from `app.js` in a few lines; a refactor that shrinks `app.js` ratchets its cap down with it. Never
|
|
21
21
|
raise either: extract instead. Ruby's twin is `Samagotchi/FileSize` (docs/testing.md, File size).
|
|
22
22
|
|
|
23
|
-
**New exports go in new modules.**
|
|
23
|
+
**New exports go in new modules.** An `npm test` ratchet parses every public module and compares existing modules'
|
|
24
|
+
exports with `spec/web/public/exports_baseline.json`; `release:bump` refreshes the baseline. Its `ALLOWED` entries
|
|
25
|
+
name the file and export and carry a one-line reason. The static JS is served at unversioned URLs. Today every load revalidates
|
|
24
26
|
(app.rb `serve_static` sends `Cache-Control: no-cache` with a content ETag, and `sw.js` has no fetch handler), but an
|
|
25
27
|
open tab still holds the modules it loaded, and a proxy that ignores `no-cache` can serve an old one: a new export
|
|
26
28
|
on an existing module, imported by a new version of another, then finds the old module without it and blanks the
|
|
@@ -29,7 +31,7 @@ page. A factory dep a new version stops passing is the same hazard the other way
|
|
|
29
31
|
out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
|
|
30
32
|
until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
|
|
31
33
|
`turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
|
|
32
|
-
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (Deleting a chained session, below), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
34
|
+
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (Deleting a chained session, below), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
33
35
|
|
|
34
36
|
## One page, every viewer
|
|
35
37
|
|
|
@@ -97,12 +99,22 @@ field only when the payload carries it: `session_payload.js` reads its sources f
|
|
|
97
99
|
(`fieldsFromCard`: owner, workerVersion, workerFeatures, bridgeUp; never status), its redraws (store `ORDER` names)
|
|
98
100
|
and its writers. A new field starts in `emptySessionState` and gets an entry (its spec checks both).
|
|
99
101
|
|
|
102
|
+
A source's `undefined` means "this payload doesn't say", never "none": `promptParts` (the show's `prompt_parts`)
|
|
103
|
+
is the case to copy. A turn end's `?tail=1` re-read from an older live worker leaves the key out, so the page keeps
|
|
104
|
+
the parts it has; only a list (`[]` too) replaces them. `ctxTokens` is the context's token count next to `ctxPct`
|
|
105
|
+
(the working set's "in chi's head now · ~X of Y" and its Conversation row): from the same data (`ctx_tokens.js
|
|
106
|
+
ctxTokensOf`: a `context_status`'s `usage.estimated_used_tokens`, a chunk's `counts.total_tokens`), cleared where
|
|
107
|
+
`ctxPct` is (`usage: null`); on load `loadedCtxTokens` turns the live worker's % back into tokens (against the
|
|
108
|
+
window, or the smaller budget), else the saved `timing.context.used_tokens`. It changes with almost every chunk, so it
|
|
109
|
+
has a redraw of its own, `workingSetTokens` (with `ctxWindow`, the line's "of Y"): `workingSet.tokensChanged()` draws
|
|
110
|
+
the open list only when the text it shows of them changes (the head line, the Conversation row's tokens).
|
|
111
|
+
|
|
100
112
|
A changed value (`!==`) marks its field's redraws; `sessions` marks `lists` and `infoBar` (the bar reads the list:
|
|
101
113
|
the chain's ← → links, the children chip, the archived button, the card's title, the fresh link's picker); `selected`
|
|
102
114
|
marks `paintActive`, `composer` and `infoBar`; `touch(name)` marks one redraw for an input the store doesn't hold
|
|
103
115
|
(the clock, versions, the stream, `liveTurn.running`). They run synchronously, once each, at the end of the outermost
|
|
104
116
|
`batch()` (at once for a bare write), in one `ORDER`: `lists`, `paintActive`, the open panels (`settingsPanel`,
|
|
105
|
-
`workingSetStrategy`), `featureGates`, `composer`, `infoBar`. `lists` comes before
|
|
117
|
+
`workingSetStrategy`, `workingSet`, `workingSetTokens`), `featureGates`, `composer`, `infoBar`. `lists` comes before
|
|
106
118
|
the bar because `updateSessionTitle` reads the strip's active card; `composer` before the bar as `setTurnRunning`
|
|
107
119
|
runs them. Not a rAF (a background tab runs none, and the title badge tests run there; the e2e per-frame checks would
|
|
108
120
|
see the composer move a frame late) and not a microtask (code that reads the page right after a write would see it
|
|
@@ -110,7 +122,8 @@ stale).
|
|
|
110
122
|
|
|
111
123
|
**The redraws are registered, not called.** app.js registers each name once (`store.on`, at the bottom, once every
|
|
112
124
|
piece a redraw calls exists): `lists` → `lists.render()`, `paintActive` → `lists.paintActive()`, `settingsPanel` →
|
|
113
|
-
`settingsControl.refresh()`, `workingSetStrategy` → `workingSet.strategyChanged()`, `
|
|
125
|
+
`settingsControl.refresh()`, `workingSetStrategy` → `workingSet.strategyChanged()`, `workingSet` →
|
|
126
|
+
`workingSet.sessionChanged()`, `workingSetTokens` → `workingSet.tokensChanged()`, `featureGates` (below), `composer` →
|
|
114
127
|
`composerMode.update()` (`composer_mode.js`), `infoBar` → `updateInfoBar()`. A writer writes and stops there: no `updateInfoBar()` after
|
|
115
128
|
a store write. A value written unchanged redraws nothing (a chunk with the same ctx %).
|
|
116
129
|
|
|
@@ -379,8 +392,10 @@ is no longer the live one (a ✕ on another card while the first plan was read)
|
|
|
379
392
|
`GET /api/sessions/:id/delete_plan`, fetched as it opens and only for a chained session: the server's own plan and
|
|
380
393
|
refusals (`SessionChain::Delete::Preview`, the code the delete runs), so the sheet and the delete can't disagree; its
|
|
381
394
|
cost is one session listing walk per open. `deleteChoices` (pure) turns it into the two choices, a schedule's banner
|
|
382
|
-
and each refusal's "Not while …"; a plan that says no chain (a link alone past a gap) falls back to the confirm.
|
|
383
|
-
|
|
395
|
+
and each refusal's "Not while …"; a plan that says no chain (a link alone past a gap) falls back to the confirm. The
|
|
396
|
+
confirm sends the shown choice's `digest` (`expect=`, `data.js deleteSession`/`deleteChain` keep it out of `fetch`);
|
|
397
|
+
a `409 plan_changed` re-reads the plan and redraws the sheet with "What this deletes changed; check again" (a link no
|
|
398
|
+
longer chained gets the plain confirm). Any other refusal `runDeleteFlow` shows in the sheet
|
|
384
399
|
(`refusalModel`: a moved delegate that can't go back offers "Stop its worker, then delete" only when the 409 says
|
|
385
400
|
`stoppable`; it stops each, retries only once the stop answers `released`, and says so otherwise, never looping, one
|
|
386
401
|
stop at a time).
|
|
@@ -693,18 +708,20 @@ reach another device or the server.
|
|
|
693
708
|
| `chi_strip_hidden` (`chi_zen`: the old name, read once) | `strip_hidden.js` | the session strip hidden |
|
|
694
709
|
| `chi_stage_collapsed:<session>` | `stage_asking.js` (through `session_prefs.js`) | the session's stage collapsed or opened by hand (not written from the asking form, whose fold is that question's only); none: the page's default, `<body data-stage-collapsed="1">` (`web.stage_collapsed`), else open |
|
|
695
710
|
| `chi_working_set_collapsed:<session>` | `working_set_rail.js` (through `session_prefs.js`) | the session's working set rail collapsed |
|
|
711
|
+
| `chi_ws_sections_folded:<session>` | `working_set_view.js` (through `session_prefs.js`; the key is `ws_sections.js WS_SECTION_FOLD`) | the working-set list's sections folded by hand, a JSON list of keys (`start`, `read`, `talk`); none: all open |
|
|
696
712
|
| `chi_markdown_tip_dismissed` | `markdown_tip.js` | the markdown tip dismissed |
|
|
697
713
|
| `chi_update_available_shown` | `version_notices.js` | update notices already shown |
|
|
698
714
|
| `chi_notify`, `chi_push_device` | `notifications.js` (an injected storage) | the bell's state, this device's push id |
|
|
699
715
|
| `chi_answer_fold:<session>` | `answer_fold.js`, `revise_stack.js` | the answers and long prompts (`<turn id>:prompt`) folded by hand, and the Revise stubs unfolded by hand (`stub:<turn id>`) (swept with the session list) |
|
|
700
716
|
|
|
701
|
-
**A session's view settings** (`session_prefs.js`): the
|
|
717
|
+
**A session's view settings** (`session_prefs.js`): the five `<key>:<session>` keys above (the fifth's name is
|
|
718
|
+
defined in `ws_sections.js`, a new module, so `session_prefs.js` exports nothing new: the mixed-cache rule). `read(key, session)` is the
|
|
702
719
|
session's own value, else the page's default (only the stage fold has one: `web.stage_collapsed` on `<body>`), else
|
|
703
720
|
the module's; `write(key, session, value)` writes the session's key only; with no session (the start page) the value
|
|
704
721
|
stays in memory until a reload. Each module reads its value again when a session's view is drawn (`session_view.js
|
|
705
722
|
applyPrefs`: at the end of `forgetSession`, so on a select once the new session is set, and at the start of each
|
|
706
723
|
`renderSessionView`): `stage_view.js applyPrefs` (the stage's fold, `stage_asking.js reloadChoice`, and the rail's),
|
|
707
|
-
`composer_mount.js applyPrefs` (the floor; the fold is read at each call). One sweep for the
|
|
724
|
+
`composer_mount.js applyPrefs` (the floor; the fold is read at each call). The list's section folds are read at each draw. One sweep for the five
|
|
708
725
|
(`sweepSessionPrefs`, app.js `sweepFoldsOnce`, next to `sweepAnswerFolds`): only on an unscoped list, since these keys
|
|
709
726
|
hold no project root. The old page-wide keys (`chi_stage_collapsed`, `chi_composer_floor`, `chi_composer_collapsed`,
|
|
710
727
|
`chi_working_set_collapsed`, no `:<session>`) are no longer read or written, and left in storage as they were.
|