samagotchi 0.199.0 → 0.200.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/docs/bundles.md +3 -2
  4. data/docs/cli.md +18 -3
  5. data/docs/configuration.md +12 -7
  6. data/docs/internals/bridge.md +9 -4
  7. data/docs/internals/knowledge.md +8 -5
  8. data/docs/internals/participants.md +2 -1
  9. data/docs/internals/prompt-caching.md +9 -4
  10. data/docs/internals/web-frontend.md +27 -2
  11. data/docs/plugins.md +4 -2
  12. data/docs/sessions.md +8 -1
  13. data/docs/testing.md +1 -1
  14. data/lib/samagotchi/bridge/card_store.rb +19 -10
  15. data/lib/samagotchi/bridge.rb +1 -1
  16. data/lib/samagotchi/bundles/knowledge/github.rb +28 -10
  17. data/lib/samagotchi/bundles/knowledge/manifest.yml +4 -4
  18. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  19. data/lib/samagotchi/cache_confirm.rb +54 -18
  20. data/lib/samagotchi/engine/models.rb +10 -0
  21. data/lib/samagotchi/guardrail_wiring.rb +1 -1
  22. data/lib/samagotchi/inline_widgets.rb +14 -2
  23. data/lib/samagotchi/level_setting_command.rb +2 -3
  24. data/lib/samagotchi/llm_context_command.rb +2 -2
  25. data/lib/samagotchi/model_switch_mark.rb +49 -0
  26. data/lib/samagotchi/paths.rb +8 -1
  27. data/lib/samagotchi/plugin/secrets.rb +1 -1
  28. data/lib/samagotchi/plugin_session_state.rb +1 -1
  29. data/lib/samagotchi/session_commands.rb +11 -4
  30. data/lib/samagotchi/session_stats.rb +11 -6
  31. data/lib/samagotchi/toolkit_command.rb +1 -1
  32. data/lib/samagotchi/version.rb +1 -1
  33. data/lib/samagotchi/web/public/app.js +3 -1
  34. data/lib/samagotchi/web/public/bar_fold.js +1 -1
  35. data/lib/samagotchi/web/public/bubbles.js +7 -2
  36. data/lib/samagotchi/web/public/cache_cost_text.js +15 -0
  37. data/lib/samagotchi/web/public/commands.js +11 -2
  38. data/lib/samagotchi/web/public/confirm_block.js +59 -0
  39. data/lib/samagotchi/web/public/index.html +26 -1
  40. data/lib/samagotchi/web/public/info_bar.js +12 -1
  41. data/lib/samagotchi/web/public/info_bar_model.js +11 -1
  42. data/lib/samagotchi/web/public/model_mark.js +18 -0
  43. data/lib/samagotchi/web/public/model_picker.js +23 -6
  44. data/lib/samagotchi/web/public/model_switch.js +101 -0
  45. data/lib/samagotchi/web/public/more_sheet.js +11 -4
  46. data/lib/samagotchi/web/public/quiet_notes.js +1 -1
  47. data/lib/samagotchi/web/public/reasoning_history_chip.js +2 -1
  48. data/lib/samagotchi/web/public/settings_chip.js +2 -1
  49. data/lib/samagotchi/web/public/start_page.js +41 -8
  50. data/lib/samagotchi/web/public/stream_handlers.js +13 -2
  51. data/lib/samagotchi/web/public/thinking_chip.js +2 -1
  52. data/lib/samagotchi/web/public/tokens.css +2 -2
  53. metadata +6 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 705b7565d3ca1bb69719bf2b57a75fad13e8670aed3d210a7adf35976c83ef5b
4
- data.tar.gz: 0f70af7c8aeafc3ed28e1a5879ce4c73daaf41086c219fb33ce64261463fbe42
3
+ metadata.gz: e8362b1b22a543f1abea8c7358416f1c840f10c702de8f4bc56a5dfa9ce390a6
4
+ data.tar.gz: c196d6678163b2ef0358ae473d07d08ed3b9de965307a83ae5f2d5c2a95c26a9
5
5
  SHA512:
6
- metadata.gz: ea3997083b1e8b862ce6bacbaaafec9ccac62f9416ef8af5ca9f5760a7b87f881ab725e43c382ee917dd9f0b4671c1d03e3f55de5ed06eed1137e1d0ad33e0e0
7
- data.tar.gz: a2fd5266bd475c128e5983b6c25e1099964bf3ba4b2fc785f77debed70d973dbbde88873fdd525b4f07f6f110cd15f47ab00a941cce910c6a0f1d97796b6274a
6
+ metadata.gz: c84c8d9b089540121868631c4d3da6de9e2e0e84f5b7df7ae264781b633a7d7894f6671d7623df71704d8ebfc836f567c90c01e4426188a13a73dc94db73a3bb
7
+ data.tar.gz: e4017132b7963df7b37bb1cb75be29ecd4236f1f735c88ba3402a6161f8e0ae9838a89dd4f56c3d334fefec2bd589b541a7a648e2b433544aac6d8b07a66f841
data/CHANGELOG.md CHANGED
@@ -8,6 +8,35 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.200.0] - 2026-12-03
12
+
13
+ ### Added
14
+
15
+ - A `/model` switch leaves a line where it happened: `model: gemma-4 → qwen-3.5 · Dec 3, 09:31`, a quiet divider in
16
+ chi web's conversation (kept after a reload and on an archived link) and `model> …` in the attached terminal. The model
17
+ never reads it; a participant never sees it. A switch before the first reply leaves none.
18
+ - chi web: the info bar's model name is a button: a click (on a phone, ⋯ → Model) opens the searchable model list for
19
+ the session; a pick asks first when it restarts the prompt cache, and once applied only the line above shows. Plain
20
+ text while a turn runs, for a terminal's session, an archived or continued link, and for participants.
21
+
22
+ ### Changed
23
+
24
+ - Every prompt-cache confirm (`/model`, `/thinking`, `/reasoning-history`, `/llm-context`, `/toolkit`, a plugin's
25
+ `ctx.cache_confirm`) says the next turn pays: "The next turn starts without a prompt cache: X reads the whole
26
+ conversation again (about N tokens). Nothing has changed yet." In chi web it is a yellow warning block with one button
27
+ (`Switch model`, …) instead of the plain bubble's Apply; the ⚙ panel's note uses the same words.
28
+
29
+ ### Fixed
30
+
31
+ - **knowledge** 0.3.1: a github source failed to clone with gh older than 2.90 (`gh repo clone` has no `--no-upstream`
32
+ there); the bundle now clones with git, your `gh` login as its credentials.
33
+ - **knowledge** 0.3.1: a git timeout names the git command and its subcommand (`git clone`, `git fetch`, …),
34
+ not the `-c` flag it can't tell apart.
35
+ - A `chi-ui` block that nests too deep is refused with "the block nests too deep", whichever libyaml reports the
36
+ limit: on the one that carries its own nesting-depth cap it was "not YAML: exceeded maximum nesting depth".
37
+
38
+ Update with `chi update` (knowledge 0.3.1).
39
+
11
40
  ## [0.199.0] - 2026-12-02
12
41
 
13
42
  ### Added
@@ -7293,7 +7322,8 @@ and long-lived sessions.
7293
7322
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
7294
7323
  hotkey panel that send selected text or the clipboard to your sessions.
7295
7324
 
7296
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.199.0...HEAD
7325
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.200.0...HEAD
7326
+ [0.200.0]: https://github.com/dm1try/samagotchi/compare/v0.199.0...v0.200.0
7297
7327
  [0.199.0]: https://github.com/dm1try/samagotchi/compare/v0.198.0...v0.199.0
7298
7328
  [0.198.0]: https://github.com/dm1try/samagotchi/compare/v0.197.0...v0.198.0
7299
7329
  [0.197.0]: https://github.com/dm1try/samagotchi/compare/v0.196.0...v0.197.0
data/docs/bundles.md CHANGED
@@ -1758,7 +1758,7 @@ indexed locally, in one SQLite FTS5 file per catalog, through the system `sqlite
1758
1758
  - **GitHub repositories** (`kind: github`, github.com only): `location` is `OWNER/REPO[@REF][:PATH]` or
1759
1759
  `https://github.com/OWNER/REPO[/tree/REF[/PATH]]`, nothing else (no leading `-`, no `..`, a ref `git check-ref-format`
1760
1760
  takes). `REF` is a branch or a tag (not a commit); a branch with a `/` takes the first form
1761
- (`acme/vendor@feature/x:docs`). The bundle keeps a shallow clone of its own (`gh repo clone`, your `gh` login: no token in chi) and pulls
1761
+ (`acme/vendor@feature/x:docs`). The bundle keeps a shallow clone of its own (`git clone` with your `gh` login as its credentials: no token in chi) and pulls
1762
1762
  it when a search finds it stale, **in the background** (a search never waits for GitHub; the age line says
1763
1763
  `refreshing now`); a failing pull clones again. Its tracked text files follow the folder rules (no symlinks,
1764
1764
  submodules or secret-named files). It needs `gh` and `git` on PATH.
@@ -1771,7 +1771,8 @@ indexed locally, in one SQLite FTS5 file per catalog, through the system `sqlite
1771
1771
  - **Attached context** (`kind: chi, location: context`, opt-in): the latest texts of this project's attached context
1772
1772
  (`chi context`) and its sessions' own sources, as last fetched (the bundle never runs a source's command).
1773
1773
  - In a named catalog, a sessions or context source refreshes only from a session of the project it was added in;
1774
- elsewhere it answers from its index.- **Catalogs:** a session in a project (a git repository, its worktrees sharing it, or a `chi project init` folder)
1774
+ elsewhere it answers from its index.
1775
+ - **Catalogs:** a session in a project (a git repository, its worktrees sharing it, or a `chi project init` folder)
1775
1776
  reads the project's; one in no project the `system` one; `catalog: NAME` (`daily-review`) any of the four tools
1776
1777
  reads a **named** catalog instead, shared across projects, made at its first `knowledge_add`, with no default
1777
1778
  sources. One catalog per call.
data/docs/cli.md CHANGED
@@ -1140,10 +1140,11 @@ events, the logs, the shared prompt history); your own terminal's ↑ still has
1140
1140
  can a parent agent's `chi answer`.
1141
1141
 
1142
1142
  A `/model`, `/llm-context`, `/thinking`, `/reasoning-history` or `/toolkit` change that restarts the prompt cache
1143
- asks first: the reply says what it costs, changes nothing, and names the line
1143
+ asks first: the reply says the next turn pays it (`The next turn starts without a prompt cache: qwen reads the whole
1144
+ conversation again (about 41k tokens).`), changes nothing, and names the line
1144
1145
  that applies it (`/thinking low --yes`, `/model qwen --default --yes`). `--yes` (or `-y`) applies it at once.
1145
- The terminal puts that line in the next input (Enter applies it); the web's
1146
- reply has an Apply button. `chi send ID "/thinking low"`,
1146
+ The terminal puts that line in the next input (Enter applies it); the web shows a warning block whose button
1147
+ (`Switch model`, …) sends it. `chi send ID "/thinking low"`,
1147
1148
  and `chi -p "/thinking low" --non-interactive` apply without asking. See "Changes that
1148
1149
  restart the prompt cache" in [configuration.md](configuration.md).
1149
1150
 
@@ -2047,6 +2048,20 @@ In interactive assist mode, you can switch the request model without restarting:
2047
2048
  has no cache of the conversation): the reply names the line with `--yes` that applies it, flags and all
2048
2049
  (`/model qwen --alias q --yes`); `--yes` (or `-y`) applies at once. A typo (an unknown host, a bad alias) is an
2049
2050
  error before any question. See "Changes that restart the prompt cache" in [configuration.md](configuration.md).
2051
+ - A switch that changed the model (by its resolved ref) in a session with a model reply leaves a line where it
2052
+ happened: `model: gemma-4 → qwen-3.5 · Dec 3, 09:31` (the names as the info bar shows them: an alias as typed,
2053
+ else `host:id`; the worker's clock). The web draws it as a quiet divider in the conversation, kept after a reload
2054
+ and on an archived link; the attached terminal prints `model> gemma-4 → qwen-3.5 · Dec 3, 09:31` (again when it
2055
+ joins, if no turn came since). The model never reads it, and a participant never sees it. Every way a switch
2056
+ comes in leaves it: typed, picked in the web, `--default`, `--alias`, `clear`, `chi send -m "/model x"`, a
2057
+ schedule's `/model` line, and `chi --model X --attach` / `--resume` (sent as `/model X --yes`). A switch before the
2058
+ first model reply (a fresh chain link) leaves none: the link simply starts on that model.
2059
+ - In the web, the info bar's model name is a button (its small chevron) while the session may switch: a click opens
2060
+ the start page's searchable model list above the composer, the session's model chosen; a pick sends `/model
2061
+ <name>` as typed (its question is the warning block; **Switch model** applies it, and then only the line above
2062
+ shows, no command lines). On a phone, ⋯'s **Model** row opens it. While a turn runs, in a session a terminal owns,
2063
+ on an archived or continued link, and for a participant, the name is plain text (`/model` typed mid-turn still
2064
+ waits for the turn's end).
2050
2065
  - `/guardrails`: the guardrail rules (by source), what failed to load, your stored approvals, and System 1's
2051
2066
  recent auto-allows; `/guardrails revoke N` removes approval N and `/guardrails wrong [N]` flags an auto-allow
2052
2067
  this session should have been asked about (see [Guardrails](guardrails.md)).
@@ -876,15 +876,20 @@ every request ("Toolkits"). They ask only when what the next turn runs under rea
876
876
  it already runs, by its resolved ref, doesn't ask) and the session has a model reply. A `/model` name is checked
877
877
  first: an unknown host or a bad alias is an error at once, not a question.
878
878
 
879
- - The reply says what it costs and changes nothing yet. When known, it estimates the reread size: the whole
880
- conversation for full-prefix changes, or from the first changed reply for reasoning history. On `api: anthropic`,
881
- a full-prefix change also says preserved thinking in replies is dropped from then on.
882
- - `Nothing changed yet: send /thinking low --yes to apply.` names the line that applies it.
879
+ - The reply says when the cost lands and changes nothing yet: the change itself costs nothing, the next turn pays
880
+ (`The next turn starts without a prompt cache: qwen-3.5 reads the whole conversation again (about 41k tokens).`;
881
+ for reasoning history, `The next turn reads the conversation again from the first changed reply`). The size is an
882
+ estimate, left out when unknown. On `api: anthropic`, a full-prefix change also says preserved thinking in replies
883
+ is dropped from then on.
884
+ - `Nothing has changed yet: send /thinking low --yes to apply.` names the line that applies it.
883
885
  - `--yes` (or `-y`, anywhere after the command) applies it at once.
884
886
  - The attached terminal puts the `--yes` line in the next input: Enter applies it.
885
- - The web's reply bubble has an **Apply (restarts the cache)** button. The session bar's ⚙ panel is already an
886
- explicit choice: a tap sends the `--yes` line, and its note says what a change costs. Command bubbles are page-only, so
887
- the button is gone after a reload.
887
+ - The web shows the question as a yellow warning block: its title (`Switch to qwen-3.5?`, `Switch thinking to low?`,
888
+ `Change the LLM context?`, `Change the toolkit?`), the same cost sentence ending `Nothing has changed yet.`, and one
889
+ solid button that sends the `--yes` line (`Switch model`, `Switch thinking`, …). Another tab, and an older worker's
890
+ question, show the reply as a plain bubble with **Apply (restarts the cache)**. The session bar's ⚙ panel is already
891
+ an explicit choice: a tap sends the `--yes` line, and its note says what a change costs, in the same words. Command
892
+ bubbles are page-only, so the block is gone after a reload.
888
893
  - Only a person at a web tab or a chi TUI is asked. `chi send ID "/thinking low"`,
889
894
  `chi -p "/thinking low" --non-interactive`, a delegate, a plugin and a card's action
890
895
  apply directly, since nobody would see the question; so do the start flags (`chi --thinking`, `--model` and
@@ -241,8 +241,11 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
241
241
  - **A command's card.** `SessionCommands#run` wraps its dispatch in `Engine#running_command`, so a card shown on that thread
242
242
  carries `command:` (the event's field, `show_card` adds it). The store keeps the first show's (a replacement keeps it, even
243
243
  none) and lists `label: "from /short"`, never `command`. The page draws it after a reload, where the command's line is gone.
244
- - **Caps.** `CAPACITY` (20) each for notices, ✂ rows (`LLM_CONTEXT_TYPES`) and cards, so one burst cannot push out
245
- another kind. An open question (an approval too) is never pushed out.
244
+ - **Caps.** `CAPACITY` (20) each for notices, ✂ rows (`LLM_CONTEXT_TYPES`), a `/model` switch's marks and cards
245
+ (`CardStore.cap_class`: `:notice`, `:llm_context`, `:model`, `:card`), so one burst cannot push out another kind. A
246
+ mark is a between-turns hook notice of hook `model` (`ModelSwitchMark.mark?`: hook `model`, `in_turn: false`; a served
247
+ follow's `model:` row is a turn's own and counts as a notice). An older chi reading the file counts a mark as a notice.
248
+ An open question (an approval too) is never pushed out.
246
249
  - **Saved.** With a `path` (`cards.json` in the session's folder) the store rewrites the file after each event in
247
250
  `SAVED_ON`, and a later worker's store starts from it, so a turn's cards outlive the worker; `CardStore.saved(dir, messages:)`
248
251
  is what chi web reads for a session no worker runs. The file is `{version: 2, turn_log:, entries:}`. The log is pruned at
@@ -257,8 +260,9 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
257
260
  - **Version 1.** A file from before the log (top-level `turns`, each entry its own, maybe `running`) is no longer read, so its
258
261
  earlier cards do not show. `SessionManager.cards_empty?` still reads both versions to decide whether a session is empty.
259
262
  - **Other readers.** Besides the web and `chi guardrails replay`, `SessionStats` (a page's `runtime.sessions`) reads
260
- `cards.json` raw, read-only: version 2 only, its approvals and hook notices by turn id, and the caps by
261
- `CAPACITY`, `NOTICE_TYPES` and `LLM_CONTEXT_TYPES` (the rule `cap_class` keeps private). A change to the entries'
263
+ `cards.json` raw, read-only: version 2 only, its approvals and hook notices by turn id (chi's own `model` and
264
+ `thinking` notices left out), and the caps by `CAPACITY` and `CardStore.cap_class` (public: it reads a saved
265
+ entry's string keys too). A change to the entries'
262
266
  shape or to those constants must keep it working (`spec/session_stats_spec.rb`).
263
267
  - **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
264
268
  yet restarted only reads: it lists no cards for that session until restarted, and the file stays whole. An older **writer** does
@@ -695,6 +699,7 @@ compatibility from its version. `Bridge::FEATURES` advertises:
695
699
  | `block_fix` | `POST /session/:id/blocks/fix` asks again for a block the page couldn't draw; the owner's page without it says "restart this session to fix". |
696
700
  | `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. |
697
701
  | `peer_mail` | The worker takes a peer's messages from the mailbox (`WorkerInbound#absorb_mail`, [peers.md](peers.md)); `chi peer pair` and `say` refuse a live worker without it ("restart the session"), read through `WorkerLink.live_features`. |
702
+ | `model_mark` | A `/model` switch leaves its line (`ModelSwitchMark`, a between-turns hook notice of hook `model`). The page leaves a picked switch's command lines out only then (`model_switch.js workerMarks`); an older worker keeps them, and draws no mark. |
698
703
  | `agent_sender` | The worker reads an agent's id (`agent:<name>`: a driver's or a visitor's turn, `Visitor`). Without it `SessionManager#deliver_turn_now` sends `cli:send` instead (compat shim agent_client_id), also on the file path while a worker holds the session; chi web lists it in `/api/info` too, for `SessionAccess::Remote#sent_id`. |
699
704
  | `ask_session` | The worker runs another session's question (`session:<id8>`) as a visitor's turn. Without it the question is refused (409 `ask_unavailable`), and its file is not written while a worker may hold the session. |
700
705
 
@@ -134,13 +134,16 @@ $XDG_STATE_HOME/samagotchi/plugins/knowledge/ (ctx.data_dir, realpath'd onc
134
134
  can't tell a branch with a `/` from its path (`feature/x` reads as branch `feature`, path `x`): that one is
135
135
  `OWNER/REPO@feature/x:docs`.
136
136
  The clone is `clones/<owner>__<repo>__<digest of the location>/` (two refs of one repo, a case-insensitive disk):
137
- `gh repo clone --no-upstream OWNER/REPO DIR.partial -- --depth 1 --single-branch --no-tags --config <SAFE>…
138
- [--branch REF]` (gh's parser takes no `--` before its positionals: the validated name and the bundle's folder are
139
- its only ones), renamed into place. `SAFE` (`GithubAdapter::SAFE`, a `--config` each on the clone, a `-c` each on
140
- every other git spawn): `core.hooksPath=/dev/null`, `core.fsmonitor=false`, `protocol.allow=never`,
137
+ `git <SAFE> -c credential.helper= -c 'credential.helper=!gh auth git-credential' clone --depth 1 --single-branch
138
+ --no-tags [--branch REF] -- https://github.com/OWNER/REPO.git DIR.partial`, renamed into place (plain git, gh only
139
+ as the credential helper: no gh subcommand whose flags differ between gh versions, `gh repo clone --no-upstream`
140
+ being 2.90+; a public repo clones without a gh login, a private one fails with git's first `fatal:` line). Origin
141
+ is the https URL the pull fetches; a clone an older bundle made through `gh repo clone` keeps its own origin and
142
+ pulls as before. `SAFE` (`GithubAdapter::SAFE`, a `-c` each on every git spawn, the clone's included; a `-c` isn't
143
+ saved in the clone's config, so each later spawn passes them again): `core.hooksPath=/dev/null`, `core.fsmonitor=false`, `protocol.allow=never`,
141
144
  `protocol.https.allow=always`, `protocol.ssh.allow=always`, `submodule.recurse=false` (no `file://`, `ext::` or
142
145
  other transport a repo's config could name; the spec's git wrapper alone adds `protocol.file.allow=always` for
143
- its `file://` origin). A pull: `git <SAFE> -C DIR -c credential.helper= -c 'credential.helper=!gh auth
146
+ its `file://` origin, and an `insteadOf` reading the GitHub URL as it). A pull: `git <SAFE> -C DIR -c credential.helper= -c 'credential.helper=!gh auth
144
147
  git-credential' fetch --depth 1 --no-tags origin -- REF|HEAD`, then `reset --hard FETCH_HEAD`; a failing one
145
148
  clones again. Every spawn: no shell,
146
149
  env `GitEnv::UNSET` + `GIT_TERMINAL_PROMPT=0` + `GIT_LFS_SKIP_SMUDGE=1`, its own process group killed after 120 s.
@@ -511,7 +511,8 @@ fields: a field added to an event later reaches nobody until it is named there.
511
511
  `working_set_updated`: `.working_set`, below); and bare markers (the type alone) for the answers to a question or
512
512
  offer, and `snapshot` / `reset` (the page re-reads the session at a `reset`, as the owner's). Every other type,
513
513
  known (`DROPPED`) or new, is dropped (`chips_updated` among them: a bundle's chips are the owner's session bar, and
514
- `GET …/context` is owner-only). `spec/web/participant_view_spec.rb` scans every `type: :name` chi emits and
514
+ `GET …/context` is owner-only; `hook_notice` too, so a `/model` switch's line, `ModelSwitchMark`, never reaches them,
515
+ live or, with `cards: []`, on a reload: a participant sees no model). `spec/web/participant_view_spec.rb` scans every `type: :name` chi emits and
515
516
  every handler of the web's stream, and fails until a new one is named in `EVENTS` or `DROPPED`.
516
517
  - **The frames** (`Web::ParticipantStreamFilter`). The Bridge's chunks are cut into frames (`\r?\n\r?\n`, a partial
517
518
  one kept for the next chunk, one over 1 MiB dropped to its end); each frame's JSON goes through `.event` and is
@@ -304,10 +304,15 @@ is prefilled once. The native and the chat loop use the same plan.
304
304
  the session has a model reply. The confirmation estimates the reread size from the latest known context count:
305
305
  the whole conversation for `:full` / `:provider`, or up to the first changed reply for `:history`; it omits the
306
306
  estimate when no count is known. On `api: anthropic`, a `:full` / `:provider` change also warns that preserved
307
- thinking in replies is dropped from then on. A new setting with a cost adds its classifier and goes through
308
- the same step. A launch flag (`chi --model`, `--llm-context`, `--thinking` on an attached or resumed session,
309
- `LLMContextOverride.command_line`) and the session bar's ⚙ panel, whose note states the cost (`settings_chip.js`)
310
- send their line with `--yes`: typing the flag, or the Set, is the choice. A plugin command asks
307
+ thinking in replies is dropped from then on. The words say when the cost lands: the change costs nothing, the next
308
+ turn pays ("The next turn starts without a prompt cache: X reads the whole conversation again (about N tokens).
309
+ Nothing has changed yet."); `CacheConfirm` owns every sentence (`Confirm#title`, `#body`, `#button` per kind,
310
+ for the web's warning block; `#text` with the line to send, for the TUI). A new setting with a cost adds its
311
+ classifier and goes through the same step. A launch flag (`chi --model`, `--llm-context`, `--thinking` on an
312
+ attached or resumed session, `LLMContextOverride.command_line`) and the session bar's ⚙ panel, whose note states
313
+ the cost in the same words (`cache_cost_text.js`, read by `settings_chip.js`), send their line with `--yes`:
314
+ typing the flag, or the Set, is the choice. The info bar's model picker (`model_switch.js`) sends no `--yes`: a
315
+ pick is not the choice to pay, so it asks as a typed `/model` does. A plugin command asks
311
316
  through `ctx.cache_confirm(line, changed:)` (cost `:full`: its prompt section is in the stable part), with the
312
317
  sender's flag `SessionCommands#run` gives it (`CacheConfirm.asking`), and returns `[text, confirm]`.
313
318
  A `served` model (`main:served`) whose host now serves another model restarts the prompt as a `/model` does
@@ -39,7 +39,9 @@ reports and peer answers (The notes rows and the run line, below). `details_moti
39
39
  `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` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `views.js` (the views by hash, in one place: All sessions at `#/sessions` opened, closed and left; a page at `#/p/NAME`, read before the session intent, `hashIntent` calling it `keep`: `body.page-view`, Back to where it was opened from (kept in the history entry's `history.state.from`, so Back and Forward keep it), the session's hash not written while a view owns the URL (`keepSessionHash`), a session picked leaving it; the Pages list at `#/pages` the same way, `body.pages-list`, and the pages pill pressed on either; the session's `#/s/<id>` written; a hash change applied and selected; app.js makes it after the lists and hands its functions lazily to what it made before), the page's modules `page_route.js`, `page_view.js`, `page_model.js`, `page_blocks.js`, `page_table.js`, `page_table_model.js`, `pages_model.js` (the page's one list of pages), `pages_list.js` (the Pages list at `#/pages`, read by `views.js` beside a page's hash), `pages_wiring.js` (`wirePages`: the pill, the list, the view and the links, one call in app.js) and `page_links.js` (a page in chi web: [pages.md](pages.md#chi-web)), `worker_features.js`, `version_notices.js`, `owner_claim.js` (its `showPending` calls the injected `keepSessionHash`, following `views.js`'s rule not to write the session hash while a view owns the URL), `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_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.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), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `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), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js`, `peer_text.js`, `peer_row.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `peer_wait.js` (the chip of a peer
40
40
  the session waits for, its popover and Cancel: The peer exchange), `peer_chip_kind.js` (the peer chips as a kind of the context chips: The peer exchange), `plugin_chip.js` and `plugin_chip_kind.js` (a bundle's own chip, its card and buttons, and its kind: The peer exchange, the plugin chips), `context_groups.js` (a bundle's sources folded into one chip: its rows, chip and list, pure: The peer exchange, the source kind), `peer_mailbox_api.js` (the chip's message and Unpair calls), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `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), `drafts.js` (the composer's drafts: The drafts, below), `draft_follow.js` (a continue made elsewhere: the drafts to hand over, pure), `draft_keys.js` (their storage keys, so `session_prefs.js` sweeps them without a new export), `served_ref.js`
41
41
  (`isServedRef`, which the stream's `generation_completed` reads, beside a `modelServed` already set, for a served
42
- model's `modelServed`), `answer_write.js` (the answer's live write onto its bubble, kept in its own module so a new `markdown_place.js` or `block_fix.js` importing it never waits on an old `answer_refs.js`) 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).
42
+ model's `modelServed`), `answer_write.js` (the answer's live write onto its bubble, kept in its own module so a new `markdown_place.js` or `block_fix.js` importing it never waits on an old `answer_refs.js`) and the `objectives_*.js` modules are new modules for that reason, and so are `model_switch.js` (the "may /model run here"
43
+ rule, the bar's name wiring, a pick's registered lines), `model_mark.js` (a `/model` switch's mark), `confirm_block.js`
44
+ (a cache confirm's warning block) and `cache_cost_text.js` (the ⚙ panel's cost sentences). 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).
43
45
 
44
46
  ## One page, every viewer
45
47
 
@@ -151,6 +153,28 @@ The objectives' strip keeps the list in its own closure (`objectives_strip.js`,
151
153
  The start page's own choices (the model, the ⚙ panel, the 🧰 list) live in `start_page.js`'s closure, never in
152
154
  `store.current`. A fresh chain link's picker reads both.
153
155
 
156
+ **The model picker's three uses** (`model_picker.js`, one instance in `start_page.js`): the start page's (`#modelPick`,
157
+ the new session's model), a fresh chain link's (`#modelPick` in the session, `model_switch.js freshLinkPick`), and any
158
+ session's from the info bar's model name (`openForSession`: the list opens above the composer, its opener the name,
159
+ held by selector since lit redraws it; `body.model-switch` shows the panel in a session that isn't a fresh link, and the
160
+ picker's close clears it). One rule says where a control may run `/model` (`model_switch.js modelSwitchable`: not
161
+ while a turn runs, not a terminal's, not archived, not a continued link, the list in); `info_bar_model.js sessionBar`
162
+ reads it into `bar.model.switchable` (the name is then a `<button data-model-switch>`, the same class and place, an
163
+ inset ring so the row's box holds; `bar_fold.js foldSignature` counts it), and `syncModelPick` closes a list opened
164
+ from the bar once it turns false. ⋯'s Model row is then the action (`more_sheet.js` `go: "model"`). A pick in a session
165
+ registers its line first (`model_switch.js registerPick`), so this tab's `command_ran` of its applied `--yes` draws no
166
+ bubble and removes the warning block (D9 B of the plan: the `/model` mark, `model_mark.js`, is the trace); only with a
167
+ worker that has `model_mark`. A typed `/model` is never registered. The mark is a `.bubble.hook-notice.model-mark` (a
168
+ quiet centred divider, `bubbles.js hookNoticeTemplate`), the same live and after a reload, never a quiet item
169
+ (`quiet_notes.js QUIET` leaves it out).
170
+
171
+ **A cache confirm's warning block** (`confirm_block.js`): this tab's own `command_ran` with a `confirm` that has the
172
+ worker's `title`/`body`/`button` is drawn by `commands.js drawCommandBubble` as a `.bubble.command.cache-confirm`, so the
173
+ kept-bubble walkers (`keptCommandBubbles`, `restoreCommandBubbles`, `historyAnchors`) find it as any command bubble;
174
+ its one button keeps `data-confirm-line`, so app.js's delegated Apply sends it. Colours: `--warn-bg`/`--warn-border`,
175
+ the title `--warn-bright`, the body `--warn-text`, the button `--warn-solid` on `--on-warn-solid` (9.99:1 dark,
176
+ 8.21:1 light) with a `--warn-solid-edge` ring.
177
+
154
178
  ## The session store
155
179
 
156
180
  `session_store.js` holds the open session's state; `session_fields.js` says what each field is. **Every write goes
@@ -278,7 +302,8 @@ has it. A new action that needs a worker feature is one more entry.
278
302
  clock; `mergeTurnTiming` keeps it), and verdict_fresh.js `startFresh` pushes onto `fresh.running`, which is
279
303
  `store.current.verifyFresh`.
280
304
  - **Events, not state (D9)**: these stay direct calls next to their write: a `/model`'s picker sync
281
- (`syncModelPick`), the working set's `commandRan`, the context chips on a note, the participants reload, a
305
+ (`syncModelPick`), a picked switch's lines (`model_switch.js pickReply`, in the `command_ran` and `command_queued`
306
+ handlers), the working set's `commandRan`, the context chips on a note, the participants reload, a
282
307
  verdict's own `renderFresh`. (The working set's `strategyChanged` and the Verify gate's `redrawFresh` follow
283
308
  fields: they are registered redraws.)
284
309
 
data/docs/plugins.md CHANGED
@@ -198,8 +198,10 @@ A command whose change restarts the model server's prompt cache (one that change
198
198
  text, `[text, confirm]`, changing nothing. `line` is the command line that applies it (without `--yes`), `changed:`
199
199
  whether your text would change. chi decides the rest: it asks only a person at a web tab or a TUI (never `chi send`,
200
200
  a delegate or `chi -p`), only once the session has a model reply, never for a line with `--yes` (or `-y`), and
201
- writes the confirm's text (the conversation's size to read again; on an `api: anthropic` host, that preserved
202
- thinking is dropped). The TUI prefills `line --yes`, the web shows an Apply button that sends it, and the command
201
+ writes the confirm's text (that the next turn reads the conversation again, and its size; on an `api: anthropic` host,
202
+ that preserved thinking is dropped; then `Nothing has changed yet: send … --yes to apply.`). The TUI prefills
203
+ `line --yes`; the web shows a warning block titled `Apply change?` with that cost sentence and an **Apply** button that
204
+ sends it (the confirm's `title`, `body` and `button`: chi's own commands name their change there), and the command
203
205
  then runs again with `--yes` in `args` (drop it from your words). Outside a command (a hook, an init task, your
204
206
  own thread) it is always nil. A plain String or nil return is unchanged.
205
207
 
data/docs/sessions.md CHANGED
@@ -96,6 +96,13 @@ sessions source (`ctx.sessions.list`) read; `Session.list(changed_since:)` skips
96
96
 
97
97
  Each turn record in `analytics.json` names the model the turn ran on as `model_ref` (the asked `host:model`, from its first generation; `model` stays the name the server says it served); a turn stopped before it asked a model has none. The first turn after a `/model` switch (or a hook's) to another model also records what its first generation prefilled on the new model: `switch_prefill_tokens` (the prompt less the cached reads; none under 128 tokens, or for a generation with estimated counts) and `switch_prefill_cost_estimate` (from the new model's configured price, no completion; none without a price). A session saved before this has no `model_ref` on its records.
98
98
 
99
+ What a `/model` switch leaves: the session file's `model_name` (and `model_typed`), and, for a switch to another model
100
+ once the session has a model reply, its line in `cards.json` (the Bridge's CardStore, never `messages`): a between-turns
101
+ hook notice, hook `model`, text `gemma-4 → qwen-3.5 · Dec 3, 09:31` (`ModelSwitchMark`), placed after the turn it
102
+ followed and kept in a class of its own (the last 20 marks). The web and the attached terminal show it; the model never
103
+ reads it; a continue copies no cards, so it stays on the link where the switch happened. The turn records'
104
+ `model_ref` still says which model each turn ran on (a switch no turn followed has only the line).
105
+
99
106
  A session whose worker waits for an answer (a question, a hook's question, a guardrail approval, or the step-limit question of a turn that ran out of steps, which waits between turns) reads `waiting` in the status column, and json has `waiting: "question"|"approval"|"hook"|"continue"` and `waiting_id`, the question's id for `chi answer --question` (both null otherwise). A delegate's approval its parent relayed to its own card (see *Delegating*) reads `waiting (in parent ab12)`, json `relayed_to: "ab12…"` (the parent's short id, else null). Only while a worker runs it: a question a dead worker left in the file shows the saved status. Answer it with `chi answer`, the web or `chi --attach ID`; `chi sessions stop ID` frees the worker instead.
100
107
 
101
108
  Examples:
@@ -121,7 +128,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
121
128
  - The web header's project chip opens a picker. The start project is the default row (including its start folder); other rows show their root, session and waiting counts. **All projects** opens every session, and choosing a project drops the open-session hash while keeping `?view=`.
122
129
 
123
130
  - `Session.list` / `SessionManager.list_sessions` / `GET /api/sessions?sort=&order=&limit=&offset=` default to `updated_at desc` (newest activity first). Also supports `created_at`, `asc`. `X-Total-Count` header when paginated.
124
- - Web UI (`chi web`): the page's scope is in its URL. Started in a project (a git repository or a `chi project init` folder), `chi web` opens `/?dir=<that folder>`: that project's sessions, and new sessions start in that folder; the header chip says `<project> · all`, and `all` opens the same place as `?scope=all` (every session; a new session there starts in chi web's start folder, shown on the start page, and cards name their folder; `← <project>` goes back to the project view it came from, or to the start folder's project). A bare `/` (the LAN link, the Home Screen app) is the start folder's project too: the folder chi web runs in, or `web.start_dir` / `chi web --start-dir DIR`; outside a project (no repository or marked folder) it shows every session. A pushed notification opens its session in that session's own project (`/?dir=<its project>#/s/<id>`; `?scope=all` outside a project). One server serves every project: a second `chi web` (from another repo) finds it through `GET /api/info` and prints (with `--open`, opens) its page for its own folder instead of starting another. The 3 latest sessions sit above the chat, and the grip on the chat's top edge — the same thin handle as the composer's, its twin — puts them away and brings them back: a drag up (or a click, or Enter/Space on it) hides them, a drag down (or a click) shows them again, and the choice is remembered. A hidden strip leaves its status in the top bar (`N sessions · ● 1 live · ● 1 waiting`, from the cards), and a click on that pill opens All sessions, without showing the strip first; there the pill shows whatever the strip's state, pressed, and a click on it goes back to the chat (as Esc does). In a window under 900 px wide, where the strip scrolls sideways, the grip stays under it, outside the scroller; a window under 700 px tall hides the strip by itself, so a question or approval card in the stage keeps room, and the grip shows it until the window is tall again. A parent and its delegates are one card there: its `▸ 2 delegates · 1 live · 1 waiting` chip (the waiting part in the attention colour, the card's border too; just `▸ 2 delegates` while the rows are open: they carry the marks then) opens their rows in a popover under it (a row per delegate at any depth, indented; a click opens that one, Esc or a click outside closes it, and the strip's order holds while it is open). A fork is a card of its own, and so is a delegate whose parent isn't listed (archived, another project), with its `↳ <parent>` chip; the pill counts cards, and every live or waiting session. "All sessions" (or `/`) opens every session at `#/sessions`; its header is the top bar's right end: a search over preview, id and status, the count, an `archived` toggle and Select (on a phone a row of its own under the bar). Esc or the pressed pill returns; where the sessions are stored is a faint line under the list. A card is its title on one line (an untitled session reads `Untitled` over its first message), a line under it (its recap, else its first message) and its meta row, with one mark per state and no status dot: a waiting card has its warn outline and its `question` (or `approval`…) chip, an errored one an `error` badge, a session a worker runs the `live` badge (not on a waiting card: waiting means a worker), and idle, completed and stopped ones are unmarked; a family's and a chain's rows the same. There a parent's card holds its delegates the same way, the chip opening their rows inside the card (each with an archive button on hover), open by itself while one of them waits on you; the count says `14 · 7 delegates` (`3 / 14` while a search narrows it), a search that matches a delegate shows its parent's card with the list open and the matching rows marked, and select mode picks cards (archiving a parent takes its delegates). The open session is in the URL (`#/s/<id>`), so a reload or a copied link opens it again; the chi logo top left goes back to the empty start for a new session. The message box grows with its text; drag its top edge to keep it taller (double-click resets). Each session keeps its own draft in this browser (what you type in one never shows in another, and a pick or a quote goes into the open session's); the start page (+ new) has its own, which a new session takes when it is made (a failed create keeps it); a draft's text survives a reload, and a session gone while open leaves its draft on the start page (a delete drops it); images in a draft are lost on a reload. A file in a tool row (a read, edit or write's title) and its diff lines are refs: hover one and click to open the current file in your editor at that line, on this machine only (`web.editor`; the browser's "always allow" for the page's port and VS Code's "allow opening local files" are asked once; see [Opening files from chi web](configuration.md#opening-files-from-chi-web)). So are an edit or write approval card's paths (at the first line the dry run changes) and its diff lines, before you approve, and the numbered lines of a read's output: `lines 40–60` under it opens the text as read, numbered, when the output is the file as-is (not the head/tail preview of a big file, an error or an image; no numbers after a cut). A `path:line` (or `path:line-line`) in an answer or a step's text is one too once the turn has ended, and after a reload, when it names a file a row or card on the page touched: the path under the session's folder, else the one touched file it ends with (a bare `app.js:12` when only one touched file is named so; two such files make it none); a path without a line counts only when it is a touched file exactly. Code blocks, links, bare URLs and inline code with more than the ref in it are left alone, and a file the session didn't touch is never linked; a link whose text is such a ref alone (github-pr's link to the PR diff) becomes a ref too, and its plain click still goes to the PR. A plugin's refs on an answer (an `after_turn` hook's, see [Refs on the answer](hooks.md#refs-on-the-answer-display-only)) are paired with its links and text whatever the rows touched: they can link a file the session didn't touch, or an issue or a commit, and add their own actions to the ref's menu. A plugin tool's row carries the refs its `refs:` gives (see [Refs on a tool's row](plugins.md#refs-on-a-tools-row)): its title opens the first, and its `▾` menu adds the others as `<ref> · <action>` (the URL on hover); their URL actions work on a phone too. A ref with more than one target shows a small `▾` on hover: it opens a menu of them, in order **PR diff** (a link's), **Open in editor**, **Show in turn** and **Copy path**, and a plain click runs the first (a link's own, else the editor, else show in turn). **Show in turn** scrolls to the tool row that touched the file (looked for in the ref's own step, then its own turn, then the rows before it, then the nearest after it; there, the last one showing the ref's line, else the last one), opens the steps, the stage's steps and the row's diff (or the read showing the line) and flashes the row and the line; an answer's or a step's ref and an approval card's path have it, not a row's own title or lines. It needs no editor, so a viewer without one (a phone on the LAN) gets an answer's refs with **Show in turn** as their click; a row's title and diff lines stay plain text there. On a touch screen a tap opens the menu. A ref with a target is a tab stop: Enter runs its first target, ↓ opens the menu (↑/↓ move, Enter picks, Esc closes back to the ref). Diff and read lines have their click only. The info bar's id copies the full session id on click ("Session id copied"), the id every CLI command takes (`chi --attach ID`, `chi send ID`). A session whose prompt carried model notes has a `notes: deepseek` chip there (the names without `model_notes_`; the tooltip lists each with its scope and size; `session.prompt_notes` in `GET /api/sessions/:id`, the live worker's, else the session file's; see [Memory](memory.md#model-notes)). Its ⚙ chip, after the model, holds the session's thinking level, reasoning history and LLM context: `⚙` alone while the session follows the model for all three, else `⚙` and what the session set, in the accent colour (`⚙ think low · ctx stale,forget`; a phone shows ⚙ with a dot; the tooltip gives each value and its source). Its panel is the start page's ⚙ panel for this session: a Thinking row (`/thinking`), on a chat host a Reasoning row (the reasoning history, `/reasoning-history`), and a Context row with its Apply and budget fields (`/llm-context`); a tap runs that row's command at once in the worker (one reply in the conversation, as a typed one) and changes that field alone, the Context row's `default` resets the strategy, apply rule and budget (`/llm-context reset`), and a tap while a turn runs is queued for after it (the panel's note says so). `GET /api/sessions/:id`'s `session.thinking`, `session.reasoning_history` (null on a native host) and `session.llm_context` carry the values (the live worker's, else resolved from the session file), and a `command_ran` that changed them carries the new ones. After ⚙, the 🧰 chip names the session's toolkit: `🧰` alone on the configured default (`toolkit.default`, `session.toolkit_default`), `🧰 lean` on another (see [Toolkits](configuration.md#toolkits); `/toolkit` changes it). A `/thinking` or `/reasoning-history` change typed in the composer that restarts the prompt cache asks first: the reply bubble has an **Apply (restarts the cache)** button that sends its `--yes` line (the ⚙ panel sends that line itself; see [Changes that restart the prompt cache](configuration.md#changes-that-restart-the-prompt-cache)). It shows the context used (`ctx 42%`) and the last generation's decode speed (`87 tok/s`, `~64 tok/s` when estimated; see `/stats` in [cli.md](cli.md#session-commands)); hovering `ctx` there or on a session card lists the session's tokens in (summed over every request, with the cached share), out (with reasoning) and the cost when the provider reports one, for this session only (one estimated from a `hosts.<name>.models` price shows with `~`: `cost: ~$0.54 ($0.42 reported, ~$0.12 estimated)`); after a `/model` switch the info bar's tooltip adds a `per model:` row per run of turns on one model above those totals (`splash:qwen3-35b · 6 turns · 96.0k in / 9.0k out · ~$0.02`, a switch's prefill under its row: `└ switch prefill 58.0k uncached prompt ≈$0.01`; the timing's `model_segments`, replaced by each `generation_completed`'s; the session cards stay as they were), and right after the switch its ctx % is the new model's window's; and the memory indexes its prompt holds (`memory index: ~3.4k tokens in this session's prompt (system 2.0k, project 1.4k)`; see [Memory](memory.md#the-indexs-size)). The start page's model picker (bottom left of the composer, the chosen name `▾`) chooses the model a new session starts on, and a fresh chain link's (see [Session chains](#session-chains); there a pick shows as a `/model` command bubble in the link); it opens a search list over the conversation (↓ or a click; downward when the start page leaves no room above): an empty search shows the last 5 picks (Recent) and then each host's model ids A–Z under the host, the default host first (an id the host declares under `hosts.<name>.models` first, noted `config`, its tooltip `served by config (hosts.<name>.models)`; a host that failed to list its models keeps those ids, greyed and noted `host down`, still pickable; a remembered or default model stays chosen even then, greyed on the button); typed words must each match the host or the id (a substring, else for 3+ characters the letters in order, so `deepseek4.1 fla` finds `openrouter · deepseek/deepseek-v4.1-flash`), ⏎ picks, Esc/Tab close, a pick puts the focus in the message box: `GET /api/models` lists the hosts' models as chi spells them (`{default, models: [{name, host, id, configured?, unavailable?, sampling?, llm_context?}], warning?}`; `configured: true` marks an id declared under `hosts.<name>.models`, listed first under its host, `unavailable: true` one whose host failed to list its models; `sampling` is the model's configured request parameters as `/model` words them, the row's tooltip in the list; bare for the default host, `host:model` for the others, from the same cached lists as `/models`, a bounded wait, a host that is down noted in `warning`; `toolkits`: `{default, suggest, kits: [{name, description?}]}`, the start page's 🧰 list: the configured `toolkit.default`, `suggest` `on` only when a new session's first message may get a suggested kit (`toolkit.suggest.mode: on`, a System 1 host, two described kits; else `audit` or `off`), and the built-in and config kits a new session can start on, without `child` or `undecided`, a kit `groups:` refuses or one that doesn't resolve (a base that is a bundle kit), the default always listed; left out when it can't be read), and `POST /api/sessions` takes `model` (blank means the default). Beside it, ⚙ opens the new session's rarely used settings (thinking and LLM context, following each `GET /api/models` row's `thinking` and `llm_context`, ; see [configuration.md](configuration.md#llm-context-a-sessions-own-strategy)), and 🧰 its toolkit: **Auto** (with `toolkit.suggest.mode: on`: the first message may get a suggested kit, else the default) or a kit from the payload's `toolkits`, sent as `POST /api/sessions`'s `toolkit` (see [configuration.md](configuration.md#toolkits)); a refused kit (`400 toolkit_refused`) is said in the list, opened again. What is set shows on the row as an accent chip (`think high`, `tools: lean`; a dot on ⚙ or 🧰 on a phone); each is for the next new session only, never remembered. The start page's first message goes as later ones do: `POST /api/sessions` with `idle: true` and `preview` (the message, which names the session until its turn is saved), then `POST /api/sessions/:id/turn`, so a failed first turn puts its prompt back in the composer too; a first line that is one of the new session's commands (`/model …`) goes to `POST /api/sessions/:id/command` instead, as later ones do. The browser remembers the last model picked; a running session's model is in the info bar and changes only with `/model`. In the composer a line is a command when it is `!…` or starts with one of the session's command names (its `commands` list; `/stats`, `/exit` and the other terminal words get the page's own reply); an unknown `/word` (`/usr/bin/env is missing`) goes to the model as a prompt, as in a terminal; a one-word `/word` no command answers (`/modle`) is not sent: the page shows `Unknown command /modle. Did you mean /model? /help lists the commands.` (the "Did you mean" part only when a name is close). A `POST /turn` (or a session's first `prompt`) that is one of the worker's commands runs as that command too (`202 {status, command_id, session_id}`), so `chi send`, `chi -p` and a page whose command list lags all get the command. ↑/↓ in the composer walk the prompt history the TUI's ↑ walks ([Persistent Prompt History](cli.md#persistent-prompt-history)): ↑ with the caret on the first line, ↓ from the last line while browsing, ↓ past the newest brings the draft back; `GET /api/history` returns `{entries: [...]}`, oldest first (the page fetches it on focus and after each send). The server records a sent line in the routes once the worker took it (`POST /turn` accepted, a `!command` through `POST /command` or as a session's first line); `"history": false` in the body keeps it out (an image-only send).
131
+ - Web UI (`chi web`): the page's scope is in its URL. Started in a project (a git repository or a `chi project init` folder), `chi web` opens `/?dir=<that folder>`: that project's sessions, and new sessions start in that folder; the header chip says `<project> · all`, and `all` opens the same place as `?scope=all` (every session; a new session there starts in chi web's start folder, shown on the start page, and cards name their folder; `← <project>` goes back to the project view it came from, or to the start folder's project). A bare `/` (the LAN link, the Home Screen app) is the start folder's project too: the folder chi web runs in, or `web.start_dir` / `chi web --start-dir DIR`; outside a project (no repository or marked folder) it shows every session. A pushed notification opens its session in that session's own project (`/?dir=<its project>#/s/<id>`; `?scope=all` outside a project). One server serves every project: a second `chi web` (from another repo) finds it through `GET /api/info` and prints (with `--open`, opens) its page for its own folder instead of starting another. The 3 latest sessions sit above the chat, and the grip on the chat's top edge — the same thin handle as the composer's, its twin — puts them away and brings them back: a drag up (or a click, or Enter/Space on it) hides them, a drag down (or a click) shows them again, and the choice is remembered. A hidden strip leaves its status in the top bar (`N sessions · ● 1 live · ● 1 waiting`, from the cards), and a click on that pill opens All sessions, without showing the strip first; there the pill shows whatever the strip's state, pressed, and a click on it goes back to the chat (as Esc does). In a window under 900 px wide, where the strip scrolls sideways, the grip stays under it, outside the scroller; a window under 700 px tall hides the strip by itself, so a question or approval card in the stage keeps room, and the grip shows it until the window is tall again. A parent and its delegates are one card there: its `▸ 2 delegates · 1 live · 1 waiting` chip (the waiting part in the attention colour, the card's border too; just `▸ 2 delegates` while the rows are open: they carry the marks then) opens their rows in a popover under it (a row per delegate at any depth, indented; a click opens that one, Esc or a click outside closes it, and the strip's order holds while it is open). A fork is a card of its own, and so is a delegate whose parent isn't listed (archived, another project), with its `↳ <parent>` chip; the pill counts cards, and every live or waiting session. "All sessions" (or `/`) opens every session at `#/sessions`; its header is the top bar's right end: a search over preview, id and status, the count, an `archived` toggle and Select (on a phone a row of its own under the bar). Esc or the pressed pill returns; where the sessions are stored is a faint line under the list. A card is its title on one line (an untitled session reads `Untitled` over its first message), a line under it (its recap, else its first message) and its meta row, with one mark per state and no status dot: a waiting card has its warn outline and its `question` (or `approval`…) chip, an errored one an `error` badge, a session a worker runs the `live` badge (not on a waiting card: waiting means a worker), and idle, completed and stopped ones are unmarked; a family's and a chain's rows the same. There a parent's card holds its delegates the same way, the chip opening their rows inside the card (each with an archive button on hover), open by itself while one of them waits on you; the count says `14 · 7 delegates` (`3 / 14` while a search narrows it), a search that matches a delegate shows its parent's card with the list open and the matching rows marked, and select mode picks cards (archiving a parent takes its delegates). The open session is in the URL (`#/s/<id>`), so a reload or a copied link opens it again; the chi logo top left goes back to the empty start for a new session. The message box grows with its text; drag its top edge to keep it taller (double-click resets). Each session keeps its own draft in this browser (what you type in one never shows in another, and a pick or a quote goes into the open session's); the start page (+ new) has its own, which a new session takes when it is made (a failed create keeps it); a draft's text survives a reload, and a session gone while open leaves its draft on the start page (a delete drops it); images in a draft are lost on a reload. A file in a tool row (a read, edit or write's title) and its diff lines are refs: hover one and click to open the current file in your editor at that line, on this machine only (`web.editor`; the browser's "always allow" for the page's port and VS Code's "allow opening local files" are asked once; see [Opening files from chi web](configuration.md#opening-files-from-chi-web)). So are an edit or write approval card's paths (at the first line the dry run changes) and its diff lines, before you approve, and the numbered lines of a read's output: `lines 40–60` under it opens the text as read, numbered, when the output is the file as-is (not the head/tail preview of a big file, an error or an image; no numbers after a cut). A `path:line` (or `path:line-line`) in an answer or a step's text is one too once the turn has ended, and after a reload, when it names a file a row or card on the page touched: the path under the session's folder, else the one touched file it ends with (a bare `app.js:12` when only one touched file is named so; two such files make it none); a path without a line counts only when it is a touched file exactly. Code blocks, links, bare URLs and inline code with more than the ref in it are left alone, and a file the session didn't touch is never linked; a link whose text is such a ref alone (github-pr's link to the PR diff) becomes a ref too, and its plain click still goes to the PR. A plugin's refs on an answer (an `after_turn` hook's, see [Refs on the answer](hooks.md#refs-on-the-answer-display-only)) are paired with its links and text whatever the rows touched: they can link a file the session didn't touch, or an issue or a commit, and add their own actions to the ref's menu. A plugin tool's row carries the refs its `refs:` gives (see [Refs on a tool's row](plugins.md#refs-on-a-tools-row)): its title opens the first, and its `▾` menu adds the others as `<ref> · <action>` (the URL on hover); their URL actions work on a phone too. A ref with more than one target shows a small `▾` on hover: it opens a menu of them, in order **PR diff** (a link's), **Open in editor**, **Show in turn** and **Copy path**, and a plain click runs the first (a link's own, else the editor, else show in turn). **Show in turn** scrolls to the tool row that touched the file (looked for in the ref's own step, then its own turn, then the rows before it, then the nearest after it; there, the last one showing the ref's line, else the last one), opens the steps, the stage's steps and the row's diff (or the read showing the line) and flashes the row and the line; an answer's or a step's ref and an approval card's path have it, not a row's own title or lines. It needs no editor, so a viewer without one (a phone on the LAN) gets an answer's refs with **Show in turn** as their click; a row's title and diff lines stay plain text there. On a touch screen a tap opens the menu. A ref with a target is a tab stop: Enter runs its first target, ↓ opens the menu (↑/↓ move, Enter picks, Esc closes back to the ref). Diff and read lines have their click only. The info bar's id copies the full session id on click ("Session id copied"), the id every CLI command takes (`chi --attach ID`, `chi send ID`). A session whose prompt carried model notes has a `notes: deepseek` chip there (the names without `model_notes_`; the tooltip lists each with its scope and size; `session.prompt_notes` in `GET /api/sessions/:id`, the live worker's, else the session file's; see [Memory](memory.md#model-notes)). Its ⚙ chip, after the model, holds the session's thinking level, reasoning history and LLM context: `⚙` alone while the session follows the model for all three, else `⚙` and what the session set, in the accent colour (`⚙ think low · ctx stale,forget`; a phone shows ⚙ with a dot; the tooltip gives each value and its source). Its panel is the start page's ⚙ panel for this session: a Thinking row (`/thinking`), on a chat host a Reasoning row (the reasoning history, `/reasoning-history`), and a Context row with its Apply and budget fields (`/llm-context`); a tap runs that row's command at once in the worker (one reply in the conversation, as a typed one) and changes that field alone, the Context row's `default` resets the strategy, apply rule and budget (`/llm-context reset`), and a tap while a turn runs is queued for after it (the panel's note says so). `GET /api/sessions/:id`'s `session.thinking`, `session.reasoning_history` (null on a native host) and `session.llm_context` carry the values (the live worker's, else resolved from the session file), and a `command_ran` that changed them carries the new ones. After ⚙, the 🧰 chip names the session's toolkit: `🧰` alone on the configured default (`toolkit.default`, `session.toolkit_default`), `🧰 lean` on another (see [Toolkits](configuration.md#toolkits); `/toolkit` changes it). A `/thinking` or `/reasoning-history` change typed in the composer that restarts the prompt cache asks first: the reply is a warning block (what the next turn pays, "Nothing has changed yet.") whose button sends its `--yes` line (the ⚙ panel sends that line itself; see [Changes that restart the prompt cache](configuration.md#changes-that-restart-the-prompt-cache)). It shows the context used (`ctx 42%`) and the last generation's decode speed (`87 tok/s`, `~64 tok/s` when estimated; see `/stats` in [cli.md](cli.md#session-commands)); hovering `ctx` there or on a session card lists the session's tokens in (summed over every request, with the cached share), out (with reasoning) and the cost when the provider reports one, for this session only (one estimated from a `hosts.<name>.models` price shows with `~`: `cost: ~$0.54 ($0.42 reported, ~$0.12 estimated)`); after a `/model` switch the info bar's tooltip adds a `per model:` row per run of turns on one model above those totals (`splash:qwen3-35b · 6 turns · 96.0k in / 9.0k out · ~$0.02`, a switch's prefill under its row: `└ switch prefill 58.0k uncached prompt ≈$0.01`; the timing's `model_segments`, replaced by each `generation_completed`'s; the session cards stay as they were), and right after the switch its ctx % is the new model's window's; and the memory indexes its prompt holds (`memory index: ~3.4k tokens in this session's prompt (system 2.0k, project 1.4k)`; see [Memory](memory.md#the-indexs-size)). The start page's model picker (bottom left of the composer, the chosen name `▾`) chooses the model a new session starts on, and a fresh chain link's (see [Session chains](#session-chains); there a pick shows as a `/model` command bubble in the link); it opens a search list over the conversation (↓ or a click; downward when the start page leaves no room above): an empty search shows the last 5 picks (Recent) and then each host's model ids A–Z under the host, the default host first (an id the host declares under `hosts.<name>.models` first, noted `config`, its tooltip `served by config (hosts.<name>.models)`; a host that failed to list its models keeps those ids, greyed and noted `host down`, still pickable; a remembered or default model stays chosen even then, greyed on the button); typed words must each match the host or the id (a substring, else for 3+ characters the letters in order, so `deepseek4.1 fla` finds `openrouter · deepseek/deepseek-v4.1-flash`), ⏎ picks, Esc/Tab close, a pick puts the focus in the message box: `GET /api/models` lists the hosts' models as chi spells them (`{default, models: [{name, host, id, configured?, unavailable?, sampling?, llm_context?}], warning?}`; `configured: true` marks an id declared under `hosts.<name>.models`, listed first under its host, `unavailable: true` one whose host failed to list its models; `sampling` is the model's configured request parameters as `/model` words them, the row's tooltip in the list; bare for the default host, `host:model` for the others, from the same cached lists as `/models`, a bounded wait, a host that is down noted in `warning`; `toolkits`: `{default, suggest, kits: [{name, description?}]}`, the start page's 🧰 list: the configured `toolkit.default`, `suggest` `on` only when a new session's first message may get a suggested kit (`toolkit.suggest.mode: on`, a System 1 host, two described kits; else `audit` or `off`), and the built-in and config kits a new session can start on, without `child` or `undecided`, a kit `groups:` refuses or one that doesn't resolve (a base that is a bundle kit), the default always listed; left out when it can't be read), and `POST /api/sessions` takes `model` (blank means the default). Beside it, ⚙ opens the new session's rarely used settings (thinking and LLM context, following each `GET /api/models` row's `thinking` and `llm_context`, ; see [configuration.md](configuration.md#llm-context-a-sessions-own-strategy)), and 🧰 its toolkit: **Auto** (with `toolkit.suggest.mode: on`: the first message may get a suggested kit, else the default) or a kit from the payload's `toolkits`, sent as `POST /api/sessions`'s `toolkit` (see [configuration.md](configuration.md#toolkits)); a refused kit (`400 toolkit_refused`) is said in the list, opened again. What is set shows on the row as an accent chip (`think high`, `tools: lean`; a dot on ⚙ or 🧰 on a phone); each is for the next new session only, never remembered. The start page's first message goes as later ones do: `POST /api/sessions` with `idle: true` and `preview` (the message, which names the session until its turn is saved), then `POST /api/sessions/:id/turn`, so a failed first turn puts its prompt back in the composer too; a first line that is one of the new session's commands (`/model …`) goes to `POST /api/sessions/:id/command` instead, as later ones do. The browser remembers the last model picked; a running session's model is in the info bar and changes only with `/model`, typed or picked: the bar's model name is a button that opens this list for the session ([cli.md](cli.md#runtime-model-switch-assist-mode)). In the composer a line is a command when it is `!…` or starts with one of the session's command names (its `commands` list; `/stats`, `/exit` and the other terminal words get the page's own reply); an unknown `/word` (`/usr/bin/env is missing`) goes to the model as a prompt, as in a terminal; a one-word `/word` no command answers (`/modle`) is not sent: the page shows `Unknown command /modle. Did you mean /model? /help lists the commands.` (the "Did you mean" part only when a name is close). A `POST /turn` (or a session's first `prompt`) that is one of the worker's commands runs as that command too (`202 {status, command_id, session_id}`), so `chi send`, `chi -p` and a page whose command list lags all get the command. ↑/↓ in the composer walk the prompt history the TUI's ↑ walks ([Persistent Prompt History](cli.md#persistent-prompt-history)): ↑ with the caret on the first line, ↓ from the last line while browsing, ↓ past the newest brings the draft back; `GET /api/history` returns `{entries: [...]}`, oldest first (the page fetches it on focus and after each send). The server records a sent line in the routes once the worker took it (`POST /turn` accepted, a `!command` through `POST /command` or as a session's first line); `"history": false` in the body keeps it out (an image-only send).
125
132
  - Web notifications: when a session needs you while the tab is hidden or behind another window (a question or a guardrail approval, a plugin card with buttons during a turn such as check-in's, a failed turn, a turn done after 10 s or more; a delegated session only for its questions, a canceled turn never), the page title counts it, `(N) Chi`, until you come back to the tab. The bell at the right of the top bar also turns on OS notifications ("needs an answer", "needs approval", "needs you", "turn failed", "done in 42 s", under the session's first message; a click opens the session): its first click asks the browser for the permission, and the choice is kept per browser. Any session of the page's scope counts, not only the open one. What was already so when the page loaded never counts, and several chi tabs show one notification per event. A chi tab in front tells the others (a `BroadcastChannel`), so while you look at one, the ones behind neither notify nor count what it shows; coming back to a tab clears those events in the other tabs' titles too. The hub's `session` frames carry what this needs: `pending_question` (`{id, kind}`, kind `question` or `approval`), `pending_card` (`{id, bundle}`: the running turn's card with actions, from `pending_card.json` that the worker keeps in the session's folder while one is open; a card without actions, such as loop-guard's, never counts) and `last_turn` (`{outcome, ended_at, seconds, origin}`, saved in the session's JSON as the engine ends each turn).
126
133
  - The web frontend is a zero-build ES-module stack in `lib/samagotchi/web/public/`: `data.js` (retrieval, typed SSE `openStream` for a session and `openEvents` for the session list), `sessions_list.js` (the list as a pure reducer over `GET /api/events`: a snapshot replaces it, an upsert keeps a known card in place, a removal drops it; `families()` groups delegates under their parent), `families_view.js` (a parent's family chip, its rows and the strip's popover; the chip and rows as lit-html templates), `keep_focus.js` (lit reuses a list's nodes by position: a redraw keeps the focus on the same item by its `data-id` / `data-name`), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `#N` chip and rows as lit-html templates, the info bar's ← → links, a refused continue, and the fresh-link rule), `notify.js` (which of those events needs the user, for the notifications), `app.js` (presentation/state; a session with no live stream gets one when its `session` event says `bridge_up`, after one re-read: `event_seq` starts over in each worker, so a dropped stream is never resumed with its old cursor), `bubbles.js` (the history's bubbles between the turns' rows: output chunks, end lines, every client's prompt bubbles by `enqueued_id` with their queued/steered badges, the idle recap, guardrail warnings, hooks' notices, plugins' steers, command and note bubbles; lit-html templates, put in the history with the sticky follow by `createBubbles`), `cards_place.js` (where plugin cards and a snapshot's notices go in the history: a card added or updated in place by its id, a running turn's into its step, a snapshot's each above the first turn after it, a finished turn's notice in its step's rows and its question resolved where it was asked; a card's action buttons), `format.js` (pure formatters such as `previewOf`), `plain_line.js` (markdown out of the plain one-line places: the stage headline, a closed step's title, an answered question card's kept-reply line), `prompt_history.js` (the composer's ↑/↓ over the shared prompt history), `commands.js` (session commands: which composer lines are commands, the page's own replies, a `command_ran`'s bubble, the page's command bubbles kept across a re-read), `composer.js` (where a composer line goes, `routeComposerLine`: /cut and /queue, the start page's own replies, a session command or `!cmd`, a typo hint, else a turn; and a session command sent from the composer or a chip), `delivery_line.js` (the composer's row above the text field in a session, always there so the composer keeps its height (on a phone no row: the line lies over the session bar's left while a turn runs and you type or have a choice armed): the key hint while idle, and the delivery line while a turn runs: where a message typed now goes in, from the step's phase, clock and size, whether "cut in now" can land, and the queue link for a worker with the `delivery` feature, as a pure `deliveryLine`, its lit-html template and `createDeliveryControl`, which ticks it and keeps a choice armed from a link; see docs/cli.md, "Typing during a turn"), `restore.js` (a failed turn's prompt handed back into this tab's composer, before or after its `/turn` ack), `lists_view.js` (the session lists: the strip and its pill, all sessions with its search, count and select mode, their cards, the family and chain popovers; the cards, tile and pill as lit-html templates, drawn as new nodes each time, and the lists' orders as pure functions), `stream_handlers.js` (the open session's stream event handlers, by event type, over the page's views and hooks; a snapshot replays through them too), `stage_view.js` (the stage view: the running turn pinned above the composer, with Stop turn in its status row while it runs, then handed off into the history; its pure rules and texts in `stage_model.js`, its live slots (headline, now row, trail, ticks) in `stage_slots.js`, its cap and held height in `stage_frame.js`, the in-use watch that times the hand-off in `stage_watch.js`), `info_bar.js` (the session bar's info line as a lit-html template over a plain model, three groups with hairlines between them, on one line above a phone's width (the folder gives way first): the setup (id, status, model, the ⚙ and 🧰 chips, notes, the memory or working-set chip), the relations (chain links, the parent as `↑ <id>`, delegates, participants; only when there is one) and the telemetry (folder, ctx, speed, the session's time, worker badge)), `settings_chip.js` (the session bar's ⚙ chip and its panel over `settings_panel.js`: a tap runs that row's command, one field), `toolkit_chip.js` (the session bar's 🧰 chip: the kit against `toolkit.default`), `info_bar_model.js` (that model and the bar's buttons' states, built from the page's session state, its list and its in-flight continues and restarts (the restarting set is `version_notices.js`'s) as pure functions; `app.js`'s `updateInfoBar` applies them every second while a turn runs), `session_state.js` (what the page knows about the open session: its empty state, and `sessionStateFrom`, the fields a `GET /sessions/:id` payload sets), `refs.js` (refs: a kind and a target on the element, a plugin's ref data (label, http(s) URL actions) bound in a WeakMap by `bindRef`, the targets per kind, show in turn, one delegated set of click, key and hover listeners), `ref_menu.js` (a ref's `▾` and its menu), `ref_scan.js` (the `path:line` refs in an answer's or a step's text that name a file the session's rows touched), `answer_refs.js` (the refs a plugin attached to an answer, its `display_refs`: bound to the answer's bubble, paired with its links and text, bound with `bindRef`), `markdown_place.js` (where rendered markdown and its refs go: a text as markdown HTML, its `path:line` refs, a final answer's rendering), `images.js` (image chips in the composer: paste, drop and the image button, the upload before a turn, the thumbnails; a click on one opens it in `picture_viewer.js`), `composer_grip.js` (the composer's grip and fold: the drag, tap and keys, the fold per visit), `composer_mount.js` (the composer mounted on a page's markup: the message box and its height, the image chips from a paste, a drop or the image button, the grip and fold, ↑/↓ over the prompt history and the keys; the page's own parts come in as hooks: what Enter and Send do, keys taken first, Esc, where the history comes from, the info bar's drop while folded, typing anywhere to open it; its styles, the card it sits in (`.composer-card`, its footer and its line above the text field) included, are the shared `composer.css`, linked after `tokens.css` by `index.html`), `strip_grip.js` (the latest-sessions strip's grip, the composer grip's twin: hides and shows the strip), `strip_hidden.js` (the strip hidden or shown: the saved choice, the short window's own hide, the grip and the body's class), `storage.js` (the page's per-browser choices in localStorage, guarded: a choice that can't be read or written is not remembered), `unqueue.js` (the × on a message queued for after the turn: takes it back, its text into an empty composer or a toast), `toasts.js` (the page's toast stack: a timer each, sticky ones until acted on, the same text reusing its item), `toast_place.js` (where the toast sits: above the composer card, the stage and an open model panel), `dock_reserve.js` (what floats over the history: the history's bottom reserve (`--dock-h`) at the composer card's and the showing stage's height, a reader at the end kept there, and the toast's place measured for `toast_place.js`), `notice_links.js` (a hook notice line's http(s) URLs as links), `start_page.js` (the start page's model picker, its ⚙ panel's and 🧰 list's choices for the next new session only and their override chips; a fresh chain link's picker and its `/model`), `start_settings.js` (the start page's ⚙ panel: thinking and LLM context as rows of segments, applied at once, the Apply and budget disclosure; the override chips' words and ⚙'s dot), `settings_panel.js` (the panel's rows as lit-html templates, shared: the segments, the disclosure, a hidden row's sent-anyway line; the caller passes its rows and applies the picks), `start_toolkit.js` (the start page's 🧰 list: Auto with suggest on, the kits, the default marked; a pick closes it; its override chip and dot), `session_actions.js` (Continue, Archive and its Undo, Delete and Stop, and the start page when the open session is gone), `send_turn.js` (the composer's send: a new session first on the start page, the route, the echo, the image upload, the `/turn` ack, a fast failure's restore and each error's place). Unit-tested via `npm test` (`spec/web/public/*.test.js`).
127
134
  - Selecting a session in the web UI is read-only: `GET /api/sessions/:id` never spawns a worker (it reads a live worker's snapshot when one runs, else the session file). A prompt (`POST /turn`) or a command (`POST /command`) wakes the worker, and `/stream` briefly waits for a freshly-spawned bridge before answering. A caught-up SSE reconnect holds the stream open; `reset` markers are only sent for reconnects behind the ring window, or with a cursor from another worker (event ids are `<event_seq>-<epoch>`, one epoch per worker).
data/docs/testing.md CHANGED
@@ -129,7 +129,7 @@ its case.
129
129
  The web specs run in plain node. One that loads lit-html, itself or through a module it imports (`turn_block.js`,
130
130
  `turn_html.js`, `card.js`, `copy.js`, `images.js`, `scope.js`, `command_view.js`, `diff_view.js`, `read_view.js`,
131
131
  `question_cards.js`, `stream_handlers.js`, `stage_view.js`, `bubbles.js`, `cards_place.js`, the chips, `info_bar.js`, `info_bar_model.js`, `lists_view.js`, `context_chips.js`, `families_view.js`,
132
- `chains.js`, `working_set_view.js`, `working_set_rail.js`, `ws_markdown.js`, `unqueue.js`, `toasts.js`, `notice_links.js`, `start_page.js`, `start_settings.js`, `settings_panel.js`, `start_toolkit.js`, `session_actions.js`, `send_turn.js`, `composer_mount.js`, `dock_reserve.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`,
132
+ `chains.js`, `model_switch.js` (it imports chains.js), `working_set_view.js`, `working_set_rail.js`, `ws_markdown.js`, `unqueue.js`, `toasts.js`, `notice_links.js`, `start_page.js`, `start_settings.js`, `settings_panel.js`, `start_toolkit.js`, `session_actions.js`, `send_turn.js`, `composer_mount.js`, `dock_reserve.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`,
133
133
  `vendor/lit-html.js`) needs a DOM: `import "./dom_shim.js";` as its first import (happy-dom, a devDependency only,
134
134
  never shipped; lit reads `document` as it loads). The shim's `markupOf(template)`,
135
135
  `htmlOf(nodes)` and `canon(html)` compare markup without lit's marker comments; the DOM writes text with only `&`, `<`, `>`
@@ -8,6 +8,7 @@ require_relative "../state_format"
8
8
  require_relative "card_places"
9
9
  require_relative "turn_notice"
10
10
  require_relative "../log"
11
+ require_relative "../model_switch_mark"
11
12
 
12
13
  module Samagotchi
13
14
  class Bridge
@@ -41,10 +42,10 @@ module Samagotchi
41
42
  # kept Continue or reminder turn never has an opening: its entries are
42
43
  # +continued+ and stay rows.
43
44
  #
44
- # Notices (hook notices, load warnings, "asking again" rows), ✂ rows
45
- # and cards (with questions) are capped apart, +capacity+ each, so a
46
- # burst of notices can't push out a card, nor a long turn's ✂ rows a
47
- # hook's notice. An open question (an approval too) is
45
+ # Notices (hook notices, load warnings, "asking again" rows), ✂ rows,
46
+ # model switch marks (ModelSwitchMark) and cards (with questions) are
47
+ # capped apart, +capacity+ each (.cap_class), so a burst of notices can't
48
+ # push out a card or a mark, nor a long turn's ✂ rows a hook's notice. An open question (an approval too) is
48
49
  # never pushed out: the oldest other card or answered question goes.
49
50
  #
50
51
  # With a +path+ (the Bridge's: FILE in the session's folder) the store
@@ -85,6 +86,19 @@ module Samagotchi
85
86
  # What only the store reads: never listed.
86
87
  INTERNAL_FIELDS = %i[turn_id continued base_since past_idless after_opening during after_failed command].freeze
87
88
 
89
+ # Which cap +entry+ counts against: :notice, :llm_context, :model (a
90
+ # model switch's mark) or :card. A saved file's entry too (string keys
91
+ # and type): SessionStats reads the file.
92
+ # @return [Symbol]
93
+ def self.cap_class(entry)
94
+ return :model if ModelSwitchMark.mark?(entry)
95
+
96
+ type = (entry[:type] || entry["type"]).to_s.to_sym
97
+ return :llm_context if LLM_CONTEXT_TYPES.include?(type)
98
+
99
+ NOTICE_TYPES.include?(type) ? :notice : :card
100
+ end
101
+
88
102
  # What a session's saved file lists, as a store started from it lists
89
103
  # (no turn running): the web's cards for a session no worker runs.
90
104
  # @param session_dir [String]
@@ -438,12 +452,7 @@ module Samagotchi
438
452
  entry[:after_opening] = after if after
439
453
  end
440
454
 
441
- # Which cap +entry+ counts against: :notice, :llm_context or :card.
442
- def cap_class(entry)
443
- return :llm_context if LLM_CONTEXT_TYPES.include?(entry[:type])
444
-
445
- NOTICE_TYPES.include?(entry[:type]) ? :notice : :card
446
- end
455
+ def cap_class(entry) = self.class.cap_class(entry)
447
456
 
448
457
  def open_question?(entry)
449
458
  entry[:type] == :question && !entry.key?(:answer) && !entry[:cancelled]
@@ -809,7 +809,7 @@ module Samagotchi
809
809
  WorkerLink::ACTIVITY_FEATURE, ObjectivesTrack::FEATURE, Delivery::OWN_TURN_STEER_FEATURE,
810
810
  Delivery::CANCEL_TURN_ID_FEATURE, ReviseAnchor::PARTICIPANT_FEATURE, Delivery::PARTICIPANT_ID_FEATURE,
811
811
  WorkingSet::ITEM_FEATURE, BlockFix::FEATURE, Delivery::AGENT_FEATURE,
812
- Delivery::ASK_FEATURE, ReplyFor::FEATURE, PeerMailbox::FEATURE].freeze
812
+ Delivery::ASK_FEATURE, ReplyFor::FEATURE, PeerMailbox::FEATURE, ModelSwitchMark::FEATURE].freeze
813
813
 
814
814
  # The routes, by method and what follows /session/:id/: a handler takes
815
815
  # the session id and the request body and returns [headers, status, body].