samagotchi 0.164.0 → 0.165.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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -1
  3. data/docs/architecture.md +7 -5
  4. data/docs/cli.md +20 -13
  5. data/docs/configuration.md +5 -1
  6. data/docs/guardrails.md +13 -16
  7. data/docs/internals/block-renderers.md +1 -1
  8. data/docs/internals/bridge.md +4 -3
  9. data/docs/internals/bundles.md +4 -2
  10. data/docs/internals/inline-widgets.md +8 -1
  11. data/docs/internals/web-frontend.md +36 -9
  12. data/docs/memory.md +12 -7
  13. data/docs/plugins.md +6 -4
  14. data/docs/releasing.md +6 -2
  15. data/docs/scheduling.md +25 -3
  16. data/docs/sessions.md +8 -6
  17. data/docs/testing.md +28 -4
  18. data/lib/samagotchi/block_renderers.rb +3 -6
  19. data/lib/samagotchi/bridge/card_store.rb +2 -1
  20. data/lib/samagotchi/bridge/turn_accumulator.rb +7 -8
  21. data/lib/samagotchi/bridge.rb +45 -3
  22. data/lib/samagotchi/bundle_command/installed_check.rb +2 -1
  23. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  24. data/lib/samagotchi/chi_home.rb +44 -2
  25. data/lib/samagotchi/client_id.rb +34 -3
  26. data/lib/samagotchi/compat.rb +36 -0
  27. data/lib/samagotchi/context_command.rb +3 -0
  28. data/lib/samagotchi/context_providers.rb +5 -6
  29. data/lib/samagotchi/context_sources.rb +2 -2
  30. data/lib/samagotchi/continue_intent.rb +50 -5
  31. data/lib/samagotchi/events.rb +4 -4
  32. data/lib/samagotchi/extension_load.rb +2 -1
  33. data/lib/samagotchi/guardrails/child_boundary.rb +7 -27
  34. data/lib/samagotchi/guardrails/rules.rb +11 -9
  35. data/lib/samagotchi/guardrails/targets.rb +3 -4
  36. data/lib/samagotchi/inline_widgets.rb +16 -1
  37. data/lib/samagotchi/memory_bundle/provenance.rb +46 -4
  38. data/lib/samagotchi/memory_bundle/status.rb +2 -1
  39. data/lib/samagotchi/memory_command.rb +3 -0
  40. data/lib/samagotchi/memory_orphans.rb +4 -7
  41. data/lib/samagotchi/memory_paths.rb +64 -7
  42. data/lib/samagotchi/memory_usage.rb +1 -1
  43. data/lib/samagotchi/plugin/sessions.rb +4 -2
  44. data/lib/samagotchi/project_command.rb +4 -1
  45. data/lib/samagotchi/project_id_clash.rb +37 -26
  46. data/lib/samagotchi/project_init.rb +24 -7
  47. data/lib/samagotchi/reply_wait/poll.rb +2 -1
  48. data/lib/samagotchi/schedules.rb +124 -106
  49. data/lib/samagotchi/send_command.rb +71 -18
  50. data/lib/samagotchi/session.rb +3 -2
  51. data/lib/samagotchi/session_access/local.rb +19 -2
  52. data/lib/samagotchi/session_access/remote.rb +15 -4
  53. data/lib/samagotchi/session_chain/links.rb +109 -0
  54. data/lib/samagotchi/session_chain.rb +7 -19
  55. data/lib/samagotchi/session_continue.rb +138 -54
  56. data/lib/samagotchi/session_inbox_delivery.rb +57 -38
  57. data/lib/samagotchi/session_manager/delivery.rb +104 -18
  58. data/lib/samagotchi/session_manager/removal.rb +13 -7
  59. data/lib/samagotchi/session_manager.rb +1 -0
  60. data/lib/samagotchi/session_retention.rb +20 -10
  61. data/lib/samagotchi/session_setup.rb +31 -1
  62. data/lib/samagotchi/state_format.rb +12 -8
  63. data/lib/samagotchi/terminal_ui/attach_launcher.rb +6 -7
  64. data/lib/samagotchi/terminal_ui.rb +20 -9
  65. data/lib/samagotchi/tools/delegate.rb +2 -1
  66. data/lib/samagotchi/verify_fresh.rb +4 -1
  67. data/lib/samagotchi/version.rb +1 -1
  68. data/lib/samagotchi/web/public/activity.js +2 -2
  69. data/lib/samagotchi/web/public/app.js +13 -13
  70. data/lib/samagotchi/web/public/bar_fold.js +293 -0
  71. data/lib/samagotchi/web/public/card.js +1 -1
  72. data/lib/samagotchi/web/public/composer_mode.js +5 -7
  73. data/lib/samagotchi/web/public/index.html +132 -65
  74. data/lib/samagotchi/web/public/info_bar.js +28 -16
  75. data/lib/samagotchi/web/public/info_bar_model.js +70 -1
  76. data/lib/samagotchi/web/public/more_sheet.js +98 -40
  77. data/lib/samagotchi/web/public/stage_view.js +3 -1
  78. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  79. data/lib/samagotchi/web/public/turn_events.js +0 -122
  80. data/lib/samagotchi/web/public/turn_model.js +1 -1
  81. data/lib/samagotchi/web/public/widget_picks.js +18 -3
  82. data/lib/samagotchi/web/session_control.rb +15 -2
  83. data/lib/samagotchi/web/session_create.rb +4 -2
  84. data/lib/samagotchi/web/update_check.rb +27 -8
  85. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d42e49a40293f88111644ce49d52c31c8d89d91e80ccee15e152725f174e010c
4
- data.tar.gz: d4d795969b1c26ea0322607c990e554561e664d77ba6e25ddff9acae164fbb03
3
+ metadata.gz: 19bcc79b84235269c1a5b70df00874349dfd3e921f4876651c10501f5b5cc028
4
+ data.tar.gz: f444020ead2aecdf956789f91e6023dccc70c228a9e9e4b44f295407cbf77e82
5
5
  SHA512:
6
- metadata.gz: d6751aa682714571296f5aba3b6f2878a8138796d9f6df35bb1bbdc54fff10497a50727ac7d1eeee05e89dc43abd27b3c5b005c0db4d2e417da0b9af53cc1d13
7
- data.tar.gz: 57b54bf2f8e02e08248da5742c584fd922e30ad3aedbb8e53fa7b45c84e95e818d73e388b479922c611daf19cab9cd217402c4a72ac11c3ef223ad83ceae2047
6
+ metadata.gz: ca8fba36e7e40ed78f95d26eb3395488f965de7ed2804729856ce885ea64f532c387ef13603db4c85e60a8e91e847751b1a0bb334ac21c2defbfcec332517f72
7
+ data.tar.gz: 5bc94f69e9c5deae6cae9309592f3d72e3fe8402c4340f86358df83be31d51be4a3532bb44bd86212d35e5c3dc8a7321fcbc4c0a5700b9b20828b4de93a5459d
data/CHANGELOG.md CHANGED
@@ -8,6 +8,56 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.165.0] - 2026-11-11
12
+
13
+ ### Changed
14
+
15
+ - Guardrails: `tool: shell` rules and child boundaries also match plugin tools whose `targets:` declare a command,
16
+ so a plugin's read-only command in another checkout no longer asks.
17
+ - web: the session bar is one row at every window width. What doesn't fit folds into `⋯` by priority, lowest first
18
+ (the folder and 🧰 first, then the notes, set and participants, the model, the clock…); `⋯` is on the row everywhere,
19
+ with a count of what it holds on a desktop and its dot when a folded item asks for a look. Archive and delete live in
20
+ `⋯` alone. A chain whose earlier links a schedule pruned now says so on the bar (`↩ earlier links pruned`).
21
+ - A session you stopped or archived stays that way for senders other than you: a schedule's firing, a plugin's
22
+ `sessions.send`, a `delegate` follow-up and a participant's turn start an idle session as before, but no longer
23
+ un-stop or un-archive one (`the session is stopped; only its owner's message starts it again`). `chi send`, a web tab
24
+ and a terminal still do.
25
+ - chi web on a phone: a session's panel runs edge to edge, tap targets are about 40px, the brand in a session is a
26
+ round `+` (new session), and an answer's copy button floats so the first line wraps short of it. Inline code's side
27
+ padding is 3px at every width.
28
+
29
+ ### Fixed
30
+
31
+ - chi web on touch: Revise no longer looks disabled.
32
+ - chi web: an answered card that ends exactly at its line's edge brings the line back.
33
+ - chi web: a `/command` from a client that names no sender is recorded as `web:unnamed` instead of as you.
34
+ - The retention sweep's skeleton-folder prune reads the folder again under the session's lock, so a session file
35
+ or content written between its check and its removal is kept instead of deleted.
36
+ - A worker's `GET /session/:id/state` reply is read under the event lock, so its `event_id` always matches its state.
37
+ - A Verify fresh child now keeps its session's own `parent_answers` (`--parent-answers`, `/parent-answers`), as a
38
+ `delegate` child does, instead of falling back to config.yml's.
39
+ - A schedule no longer restarts a session you stopped: it skips it (`the session is stopped; …`), in both modes, and a
40
+ stop that lands just before a firing counts as a skip, not a failure.
41
+ - Project marker ids no longer reuse another project's memory folder; `chi project init --new-id` gives it a safe id.
42
+ - A schedule that comes due while you are continuing its session (`chi send --new --continues`, web `continue →`) is
43
+ skipped for that tick (`being continued as 7b2d41aa; retry at the next tick`) instead of failing as `archived`, so
44
+ the race no longer counts toward `max_failures`. A chain you archived yourself still fails its schedules.
45
+ - A context source from a bundle whose script is gone, or that its install record has no sha256 for, now says so
46
+ (`scripts/pr.rb is missing (reinstall the bundle)`) instead of claiming the script "differs from the installed one".
47
+ - A chain schedule whose session was archived between the tick's check and its firing now fails as `archived`, as the
48
+ check says, instead of `the chain is gone`.
49
+ - web: a ```` ```chi-ui ```` picks row whose id starts with `!` or `/` no longer makes **Fill reply** start a shell
50
+ line or a session command: the leading `!` and `/` are dropped from the id (`!touch x` reads `touch x: …`), and an id
51
+ of nothing else refuses the block.
52
+ - `chi send` to a continued session no longer brings the old link back beside the new one when the continue finishes
53
+ just as the send goes in: it resends to the new link (or says `refused: being continued; send again in a moment`
54
+ after 10 s), and a same-mode schedule firing at that moment queues its turn in the new link instead of failing as
55
+ `archived`. With `--remote`, the other machine's chi web needs this release for the send half.
56
+ - `chi send OLD NEW` no longer sends twice when a continue makes NEW out of OLD just as the send goes in, and a send
57
+ with `--image` that resends that way no longer leaves its images copied into the old link (on this machine).
58
+
59
+ Update with `chi update`, then restart chi web and running sessions (`chi sessions restart`).
60
+
11
61
  ## [0.164.0] - 2026-11-10
12
62
 
13
63
  ### Changed
@@ -6068,7 +6118,8 @@ and long-lived sessions.
6068
6118
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
6069
6119
  hotkey panel that send selected text or the clipboard to your sessions.
6070
6120
 
6071
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.164.0...HEAD
6121
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.165.0...HEAD
6122
+ [0.165.0]: https://github.com/dm1try/samagotchi/compare/v0.164.0...v0.165.0
6072
6123
  [0.164.0]: https://github.com/dm1try/samagotchi/compare/v0.163.0...v0.164.0
6073
6124
  [0.163.0]: https://github.com/dm1try/samagotchi/compare/v0.162.0...v0.163.0
6074
6125
  [0.162.0]: https://github.com/dm1try/samagotchi/compare/v0.161.0...v0.162.0
data/docs/architecture.md CHANGED
@@ -199,7 +199,7 @@ log's last 4 MB). Rows: [configuration.md](configuration.md#checking-it-chi-home
199
199
  - **Starting:** every spawn marks the session starting (`<uuid>/starting`, `{pid, at}`, `StartingMarker`) until its worker holds the lock: `spawn_worker_for_session` writes it with its own pid before `Process.spawn` and the starter's after (the starter lives until the worker holds the lock, at most `WORKER_START_GRACE`; a spawn that raises or whose starter is gone leaves none), `spawn_session` before the new file is saved, and `Worker#start` removes it. It holds for 60 s at most, and only while the pid it names runs. A resume claims it (`StartingMarker.claim`, a link(2): of resumes racing from any processes one wins), then reads the owner again. A stop marker cancels the hold-off (`start_pending?` = starting and not stop-marked) for a start marked before the stop only: of two sends after a stop, the claim lets one spawn. The stop marker carries its own `at` (`{"at"}`, on the starting marker's clock; `Session.stopped_at`), an older chi's empty one its mtime. The sweep, archive (`:starting`) and delete (refused as an owned session) honour it. N-1: an older spawner writes none for a resume (the owner checks stay); an older worker never leaves one it was given (every worker clears it at start); a leftover one is stale by age or pid (a claim's temp files a kill left, `starting.*`, count as skeleton); a 0.160 spawner or chi web still holds off on a fresh marker under a stop (it reads `starting?` before the stop), until the start ends or 60 s. `SessionManager` keeps only its starters' pids, for chi web's restart to adopt (`live_spawn_pids`), and decides nothing from them.
200
200
  - **Deleting:** `delete_session`, the retention sweep and a failed continue's cleanup use `remove_files` for the session JSON, sidecar dir, plugin state, attached context, participant grants, System 1 runs and context-candidate records. The JSON and dir go through `remove_session_files`, holding the owner lock (kind `deleting`, which `stop_session` never signals; not waited for: a worker that took it since the check keeps the session) and reading the starting marker again under it (a resume that claimed the start just before keeps the session; one after it sees the lock held). N-1: an older chi's stop reading the owner then would TERM the deleter (chi web, the CLI) in that moment; an older reader shows the kind as unknown. `Session#save` of a session read from its file (or saved once) skips a file that is gone (log `save_skipped_deleted`) rather than recreate it; only a new session's first save creates one.
201
201
  - **Worker presence:** whether a worker is up, coming or held off is read once per decision as a `WorkerPresence` (`worker_presence.rb`, a `Data.define`), the deciders' one reader of those facts (display and list rows still read `session_owner` / `WorkerLink` themselves): the owner lock's holder, the stop marker (`stop_marked?`: the only "stopped" a decider reads, never the session file's status), the `starting` marker (`StartingMarker`, `starting?`, `start_pending?`: every spawn writes it, see Starting), the archive marker, the session file's existence, and the `WorkerLink` outcome when asked (never the file itself: a scratch session's flag is read by `WakePolicy`, last). The deciders read it: `resume_session` (tui, owned, `resume_held_off?`), the session inbox's `WakePolicy` (a ring, a push's wake, a note, a fresh verdict, `wake_for_report`, `deliver_turn`'s two liveness checks, `WorkerBoot`'s leave: below), `Local#wake`/`#worker`, `AttachLauncher`, `Schedules#busy_reason`, archive, delete and the retention sweep. Each keeps its own subset of the facts and their order.
202
- - **Session inbox:** a delivery into a session (`SessionInbox.deliver(kind, id) { |at| write }`, `session_inbox_delivery.rb`) runs one path: resolve the link (`SessionInbox::Head.resolve`: push and a fresh verdict are pinned to the id named; a send and a note go to the chain's newest link, and for a send (a kind that starts an archived link) a continue of the reached link in flight (`ContinueIntent.in_flight`: `continue.json` written, `continue.lock` held, the successor not saved yet) gives `:continuing` with the successor's id, which chi send asks again for a moment and then refuses; a note needs no such check (`NoteMove` moves or adopts it); a ring's file stays with the parent `parent.json` names and its wake goes one hop, to the link whose `ChildReports` reads that file; only an archived id is walked, with one `Session.list`), refuse before any write (a gone session; a one-turn run's or a scratch session for send and a note), write with the kind's own writer (formats unchanged), read `WorkerPresence` once, and apply the kind's `WakePolicy` row. `decide` reads in one order for every kind: gone, one-turn run (`:owned`), owned (`:live`), the stop marker (`:stopped`: the only "stopped", the file's status never decides; send un-stops), archived (send alone starts one), starting (`:starting`, never a second spawn), the kind never starts (`:none`: a note, a fresh verdict) or wasn't asked to (`:off`), scratch (the session file is read only here), else `:start` through `SessionManager.start_for_inbox` (`resume_session`, its claim on the starting marker; it answers `:woken` only when it spawned the worker, `:starting` when another start won the claim, `:live` when a worker took the lock since). N-1 gap: a session file that says `stopped` with no stop marker (stopped before the marker existed, or a resume whose spawn failed after it cleared the marker) is woken, and an older worker, which has no `Worker#settle_stale_status`, exits on its first pass; the wake still reads `:woken`, and each later ring or push spawns another such worker (bounded by the rings and pushes). Restarting chi on the new version (`chi web`, the workers) closes it. `SessionInbox.wake` is the wake half alone (`wake_for_report`, a failed continue's rings). On it: `ChildRing.ring` (its start on a thread), `Local#context_push`'s wake (its outcome is `ContextPush#wake`, the push line's ending), `NoteDelivery.deliver` (every note writer a person or another session drives: `chi note`, `send_note`, `chi broadcast`, chi web's notes route; `NoteDelivery::Result#id` is the link that has it, `#asked` the one named; `/objectives` passes `pin: true`: its list is its own session's) and `VerifyFresh.forward` (`:fresh_verdict`: the child's parent, pinned, no worker). Send keeps its Bridge/file flow in `SessionManager.deliver_turn`, which resolves nothing (it acts on the id it is given: an archived link gets the message and comes back); chi send resolves the head first (`SessionAccess#head`, remotely `GET /api/sessions/resolve?head=1`), while the web composer, a participant's turn, `delegate` follow-ups, `Plugin::Sessions` and `Schedules` stay on the id they name; its two liveness checks (before the post, after a file's write) read the `:send` row and leave the refusals to `resume_session`'s wording. One row is not a delivery: `:leave`, `WorkerBoot.run_session_loop`'s successor as a worker leaves (input left after a signal, an idle exit's or `/exit`'s input or rings, a restart), read on a fresh presence once the lock is free: a stop that landed as it left starts none for any way out (`resume_session` would clear the stop; logged `respawn_dropped`, `restart_dropped` for a restart, whose reminders go with it), the input and rings stay for the next start. The notes a spawn writes into the session it starts stay direct `SessionInbox.write_note` calls, pinned by construction: spawn_session's chain note, `ContextMove`'s notes, `Objectives.carry`, `ChildMove`'s note to a moved child. A continue moves the previous link's waiting notes to the new link last in its `before_spawn` (`NoteMove.move`), a failed one gives them back before the link goes (`NoteMove.give_back`), and the new link's worker adopts what the archived links before it get after their continue (`NoteMove.adoption`, from `WorkerInbound#absorb_notes` and `Worker#start`: back along the chain through up to 8 archived links, from each only notes from the creation of the link that continued it, never an objectives list). `write_note` refuses a session with no file and no folder (`Session::NotFound`), so a late writer can't bring back a deleted link's folder.
202
+ - **Session inbox:** a delivery into a session (`SessionInbox.deliver(kind, id) { |at| write }`, `session_inbox_delivery.rb`) runs one path: resolve the link (`SessionInbox::Head.resolve`: push and a fresh verdict are pinned to the id named; a send and a note go to the chain's newest link, and for a send (a kind that starts an archived link) a continue of the reached link in flight (`ContinueIntent.in_flight`: `continue.json` written, `continue.lock` held, the successor not saved yet) gives `:continuing` with the successor's id, which chi send asks again for a moment and then refuses; a note needs no such check (`NoteMove` moves or adopts it); a ring's file stays with the parent `parent.json` names and its wake goes one hop, to the link whose `ChildReports` reads that file; only an archived id is walked, with one `Session.list`: `SessionChain::Links#first_live`), refuse before any write (a gone session; a one-turn run's or a scratch session for send and a note), write with the kind's own writer (formats unchanged), read `WorkerPresence` once, and apply the kind's `WakePolicy` row. `decide` reads in one order for every kind: gone, one-turn run (`:owned`), owned (`:live`), the stop marker (`:stopped`: the only "stopped", the file's status never decides; send un-stops), archived (send alone starts one), starting (`:starting`, never a second spawn), the kind never starts (`:none`: a note, a fresh verdict) or wasn't asked to (`:off`), scratch (the session file is read only here), else `:start` through `SessionManager.start_for_inbox` (`resume_session`, its claim on the starting marker; it answers `:woken` only when it spawned the worker, `:starting` when another start won the claim, `:live` when a worker took the lock since). N-1 gap: a session file that says `stopped` with no stop marker (stopped before the marker existed, or a resume whose spawn failed after it cleared the marker) is woken, and an older worker, which has no `Worker#settle_stale_status`, exits on its first pass; the wake still reads `:woken`, and each later ring or push spawns another such worker (bounded by the rings and pushes). Restarting chi on the new version (`chi web`, the workers) closes it. `SessionInbox.wake` is the wake half alone (`wake_for_report`, a failed continue's rings). On it: `ChildRing.ring` (its start on a thread), `Local#context_push`'s wake (its outcome is `ContextPush#wake`, the push line's ending), `NoteDelivery.deliver` (every note writer a person or another session drives: `chi note`, `send_note`, `chi broadcast`, chi web's notes route; `NoteDelivery::Result#id` is the link that has it, `#asked` the one named; `/objectives` passes `pin: true`: its list is its own session's) and `VerifyFresh.forward` (`:fresh_verdict`: the child's parent, pinned, no worker). Send keeps its Bridge/file flow in `SessionManager.deliver_turn`, which resolves nothing (it acts on the id it is given: an archived link gets the message and comes back); chi send resolves the head first (`SessionAccess#head`, remotely `GET /api/sessions/resolve?head=1`), while the web composer, a participant's turn, `delegate` follow-ups, `Plugin::Sessions` and `Schedules` stay on the id they name; its two liveness checks (before the post, after a file's write) read the sender's row (`WakePolicy.for_sender(client_id)`, `ClientId.wake_kind`: a person's — chi send, a web tab, a TUI — is `:send`; a schedule, a plugin, a delegate follow-up and a participant have rows of their own, any other id `:automatic`, which start an idle session but neither un-stop nor start an archived link: refused before the write, `DeliverResult::STOPPED` / `ARCHIVED`) and leave the other refusals to `resume_session`'s wording. One row is not a delivery: `:leave`, `WorkerBoot.run_session_loop`'s successor as a worker leaves (input left after a signal, an idle exit's or `/exit`'s input or rings, a restart), read on a fresh presence once the lock is free: a stop that landed as it left starts none for any way out (`resume_session` would clear the stop; logged `respawn_dropped`, `restart_dropped` for a restart, whose reminders go with it), the input and rings stay for the next start. The notes a spawn writes into the session it starts stay direct `SessionInbox.write_note` calls, pinned by construction: spawn_session's chain note, `ContextMove`'s notes, `Objectives.carry`, `ChildMove`'s note to a moved child. A continue moves the previous link's waiting notes to the new link last in its `before_spawn` (`NoteMove.move`), a failed one gives them back before the link goes (`NoteMove.give_back`), and the new link's worker adopts what the archived links before it get after their continue (`NoteMove.adoption`, from `WorkerInbound#absorb_notes` and `Worker#start`: back along the chain through up to 8 archived links, from each only notes from the creation of the link that continued it, never an objectives list). `write_note` refuses a session with no file and no folder (`Session::NotFound`), so a late writer can't bring back a deleted link's folder.
203
203
  - **Retention:** 14 days / 500 cap (env `SAMAGOTCHI_SESSION_RETENTION_DAYS`/`MAX_COUNT`, optional `KEEP_STATUS`), live-owner and starting guard (looked at again right before a session's files go), only when `*.json` present; lazy sweep at most once per `session.sweep_interval_hours` (default 24) from the session hub's full-probe tick (and on `GET /api/sessions`, which the page no longer calls), manual via `bin/chi sessions prune --dry-run`.
204
204
  - **Ordering:** `Session.list(sort:,order:,limit:,offset:)` and `GET /api/sessions?sort=&order=&limit=&offset=` default `updated_at desc`; Web UI sort/filter/pagination.
205
205
  - **Test hygiene:** `test_run` flag when `SAMAGOTCHI_ENV=test`/`RACK_ENV=test`/`CI`, targetable via `prune --test-only` / `clean`.
@@ -351,7 +351,9 @@ first RubyGems check is about 30 seconds after chi web starts, then it checks at
351
351
  intervals. A stable release is available only after `update.min_age_hours` and when newer than both
352
352
  the running and newest installed chi. Its atomic, mode-0600
353
353
  `$XDG_STATE_HOME/samagotchi/update_check.json` keeps the check cooldown and versions already
354
- announced across restarts, and AutoUpdate's record (`auto`, `auto_failed`; `save_auto`). `update.notify: off`
354
+ announced across restarts, and AutoUpdate's record (`auto`, `auto_failed`; `save_auto`); its `version` is its
355
+ `StateFormat` (`UpdateCheck::STATE_FORMAT`: a file without one is an older chi's, a newer chi's keeps its version and
356
+ unknown keys through a write). `update.notify: off`
355
357
  with `update.auto: off` starts no checker thread and makes no network request. `update_blocked` names why the local gem cannot be updated in place (checkout, Bundler, or
356
358
  an unwritable gem directory). The page tells the owner to run `chi update`; a newer `installed`
357
359
  version than the server itself still means restart chi web (its workers already run the newest chi,
@@ -624,7 +626,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
624
626
  | 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. |
625
627
  | 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). |
626
628
  | Bundle authoring | `bundle_command.rb` (`BundleCommand`), `bundle_command/{scaffold,check,test_run}.rb`, `bundle_command/try/{run,sandbox,trace}.rb`, `testing.rb` + `testing/` (the test kit) | `chi bundle new`, `check`, `test` and `try`, and the kit a bundle's tests load it with ([bundle-authoring.md](bundle-authoring.md), [internals/bundles.md](internals/bundles.md)). |
627
- | Session file | `session.rb` (`Session`, `Session::FIELDS`), `session_field.rb` (`SessionField`), `session_paths.rb` (`SessionPaths`), `session_setup.rb` (`SessionSetup`) | A session's `<uuid>.json`: one `SessionField` row per key (default, cast, what the file gets; the codec on its type), from which `Session.new`, `.from_h` and `#to_h` are built; `SessionPaths` is where the file and the session's dir are and the id rule, a leaf `Session` extends (so `ArchiveStore`, `ContextSources` and `ParticipantMode` name no `Session` constant; the first two still require session.rb at load, `ParticipantMode` lazily); `SessionSetup` the settings a fork and a continue carry, applied by member name. See [sessions.md](sessions.md#session-file). |
629
+ | Session file | `session.rb` (`Session`, `Session::FIELDS`), `session_field.rb` (`SessionField`), `session_paths.rb` (`SessionPaths`), `session_setup.rb` (`SessionSetup`) | A session's `<uuid>.json`: one `SessionField` row per key (default, cast, what the file gets; the codec on its type), from which `Session.new`, `.from_h` and `#to_h` are built; `SessionPaths` is where the file and the session's dir are and the id rule, a leaf `Session` extends (so `ArchiveStore`, `ContextSources` and `ParticipantMode` name no `Session` constant; the first two still require session.rb at load, `ParticipantMode` lazily); `SessionSetup` the settings a fork and a continue carry (`.of`), applied by member name; every new-session request (chi's run flags, the one-shot, `chi send --new`, chi web's create) builds its setup with `SessionSetup.from_request`, and `spec/session_setup_entrypoints_spec.rb` holds each entrypoint's cell for each member. See [sessions.md](sessions.md#session-file). |
628
630
  | Session config (`--set`) | `session_config.rb` (`SessionConfig`, `SessionConfig::Settings`) | A session's own settings as one value (`Session#settings`, `SessionSetup#settings`): `core`, the `--set KEY=VALUE` values of the core keys marked `session: true` (`Config::Entry`), typed by `Config.coerce!` and read first through `Config.get(key, session:)` (`RecapSetup`; `Engine#session=` rebuilds the recap job, `IdleScheduler#replace_job`), file key `config_settings`; `bundles`, the `--set BUNDLE.KEY=VALUE` values, checked against the manifest's `session_settings:`, laid over `bundles: <name>:` in `ctx.settings` ([plugins.md](plugins.md)), file key `bundle_settings`. `SessionConfig.clash` refuses a bundle setting named like a core one (install, `chi bundle check`). See [configuration.md](configuration.md#per-session-settings). |
629
631
  | Plugin API | `plugin/api.rb` (`Plugin::Api`), `plugin/tool_spec.rb` (`Plugin::ToolSpec`: a checked tool declaration, how it is registered), `plugin/loader.rb`, `plugin/context.rb` (`ctx`), `plugin/http.rb` + `plugin/http_transport.rb` (`ctx.http`), `plugin/card.rb` (`Plugin::Card`) | What a bundle's plugin registers: tools, commands, annotation actions, hooks, services, toolkits, peer sources; what its handlers get as `ctx` ([plugins.md](plugins.md)). |
630
632
  | Peer bundles' base | `plugin/peer.rb` (`Plugin::Peer`) | What claude-peer and codex-peer share (the send tool, the command, the cards, payloads); each bundle's subclass sets its strings and transport ([bundles.md](bundles.md#the-claude-peer-bundle)). |
@@ -639,7 +641,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
639
641
  | Idle work | `idle_scheduler.rb` (`IdleScheduler`), `idle_recap.rb` (`IdleRecap`), `idle_reminders.rb` | One poller for an idle session's recap and reminders. |
640
642
  | 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)). |
641
643
  | 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)). |
642
- | Session chains | `session_continue.rb` (`SessionContinue`), `session_chain.rb` (`SessionChain`) | A session that continues an earlier one. `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)). |
644
+ | 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)). |
643
645
  | Review sessions | `review_start.rb` (`ReviewStart`), `session_review.rb` (`SessionReview`, the session's `review` field), `review_command.rb` (`ReviewCommand`, `chi review`), `review_apply.rb` (`ReviewApply`) | A session made to be shared: idle, its subjects project files checked by `Guardrails::ReviewPaths`, a fork of a working session from its recap (`--from`); Apply quotes a participant's review turn into the owner's composer ([sessions.md](sessions.md#review-sessions), [internals/participants.md](internals/participants.md)). |
644
646
  | 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 review'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, a review fork), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `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. |
645
647
  | 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). |
@@ -658,7 +660,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
658
660
  | Dialects | `llm/dialect.rb` (`LLM::Dialect`) | What an `api: anthropic` provider's `/v1/messages` does differently (`dialect: fireworks`) ([internals/anthropic.md](internals/anthropic.md)). |
659
661
  | Logging | `log.rb` (`Log`), `log_subscriber.rb` (`LogSubscriber`), `log_path.rb` (`LogPath`), `log_line.rb` | The debug log: tagged records, a session's event trail, where the file goes ([configuration.md](configuration.md#debug-log-file)). |
660
662
  | Stores | `reminder_store.rb` (`ReminderStore`), `recap_store.rb` (`RecapStore`) | A session's reminders, and its idle recap (`recap.json`). |
661
- | Schedules | `schedules.rb` (`Schedules`, its `Entry`, `Tick`, `Index`), `schedule_command.rb` (`ScheduleCommand`) | Durable schedules that outlive every worker: versioned `<state dir>/schedules.json` and its `schedules.lock`; rewrites preserve unknown keys and entries missing required members. The tick's busy check (a live worker asked over the Bridge's `GET /activity`, the files when there is none), the chain prune. `chi schedule` is this machine only. See [Scheduling](scheduling.md). |
663
+ | Schedules | `schedules.rb` (`Schedules`, its `Entry`, `Tick`; the tick walks chains over one `SessionChain::Links`), `schedule_command.rb` (`ScheduleCommand`) | Durable schedules that outlive every worker: versioned `<state dir>/schedules.json` and its `schedules.lock`; rewrites preserve unknown keys and entries missing required members. The tick's busy check (a live worker asked over the Bridge's `GET /activity`, the files when there is none), the chain prune. `chi schedule` is this machine only. See [Scheduling](scheduling.md). |
662
664
  | Reply waits | `reply_wait.rb` (`ReplyWait`, `GONE_AFTER`: the one dead-worker rule), `reply_wait/poll.rb` (`ReplyWait::Poll`, one look per poll), `reply_wait/target.rb` (`ReplyWait::Target`: which turn a wait binds, cursor, baseline, `owner_grace`; `first_message`, `message`, `wait_only`, `answer`, `participant`, `from_cursor`), `reply_wait/liveness.rb` (`ReplyWait::Liveness`: one owner and link read per look; `#owner?` for gone, `#worker_owned?` for an open question) | `chi send --wait`, `chi answer`, a participant's wait, the delegate tools and delegate reports wait through `ReplyWait.call(id, **target.to_h, …)` ([sub-agent.md](sub-agent.md)). |
663
665
  | Session rows | `session_row.rb` (`SessionRow`) | A session as the lists see it: scalar facts only, built by `SessionManager.session_rows` (one owner, link, recap and analytics read each), `#to_summary_h` the summaries route's body and `.from_summary_h` a remote's rows read back, `#cli_line` the one `chi sessions list` line, `.running_or_starting?` the delegates' and Verify fresh's "running" (a 15 s grace for a worker on its way). A leaf: never session_manager or web. |
664
666
  | Setup and update | `bootstrap_command.rb`, `bootstrap/`, `update_command.rb`, `gem_update.rb` | `chi bootstrap` (first config.yml, system bundle, core profile) and `chi update` (the gem, shipped bundles, the macOS helper). |
data/docs/cli.md CHANGED
@@ -1534,19 +1534,26 @@ access token", paste the token there (the part of the link after
1534
1534
  phone. The same sheet lists the other devices (a long-turns-done switch each, Remove), and `chi web push ls|rm|test`
1535
1535
  does it from the Mac (see [Phone notifications](configuration.md#phone-notifications-web-push)).
1536
1536
 
1537
- #### The session bar on a phone
1538
-
1539
- At a phone's width (600 px or less) the session bar is one row with no swiping: the id (a tap copies it), the status, the model
1540
- (cut short first), ⚙ and ⋯. ⋯ opens a bottom sheet with the rest:
1541
-
1542
- - a row for what the row has no room for, each opening what its chip opens on a wider screen: the model and the 🧰 toolkit (a tap
1543
- shows the full text a tooltip gives elsewhere), the working set (or the memories with `web.working_set` off), and, when the
1544
- session has them, participants, chain links, the parent, delegates, model notes and an older worker's Restart;
1545
- - one line with ctx, speed, the clock and the folder;
1546
- - Continue, Archive (or Unarchive), Stop and Delete, under the same rules and confirmations as the wider screen's buttons.
1547
-
1548
- A dot on ⋯ says something behind it needs a look: the accent when the working set changed or a participant is here, the warning
1549
- colour when a delegate waits or the worker runs an older chi. The attached context's chips keep their own second line under the row.
1537
+ #### The session bar
1538
+
1539
+ The session bar is one row at every window width, with no swiping and no second line. What doesn't fit folds into ⋯ by
1540
+ priority, the least needed first: the folder and the 🧰 toolkit, then model notes, the working set (or memories),
1541
+ participants and delegates, the model, the chain links, stop session, the speed, ⚙ (first down to its icon), continue →
1542
+ and the id. The status, ctx and ⋯ always stay. On a phone (600 px or less) the row is the status, ctx, the speed, ⚙ (its
1543
+ icon, a dot when the session set its own) and ⋯.
1544
+
1545
+ ⋯ opens a popover (a bottom sheet on a phone) with what the row folded away:
1546
+
1547
+ - a row for each folded chip, each opening what its chip opens: the id (a tap copies it), the model and the 🧰 toolkit (a
1548
+ tap shows the full text a tooltip gives elsewhere), ⚙, the working set (or the memories with `web.working_set` off),
1549
+ participants, chain links, the parent, delegates, model notes and an older worker's Restart;
1550
+ - one line with the folded ones of the speed, the clock and the folder;
1551
+ - Archive (or Unarchive) and Delete always, Continue and Stop when folded, under the same rules and confirmations as the
1552
+ buttons on the row.
1553
+
1554
+ On a wider screen ⋯ shows how many things it holds. A dot on ⋯ says something folded behind it needs a look: the accent when
1555
+ the working set changed or a participant is here, the warning colour when a delegate waits or the worker runs an older chi.
1556
+ The attached context's chips keep their own second line under the row.
1550
1557
 
1551
1558
  ### Remote sessions
1552
1559
 
@@ -1408,10 +1408,14 @@ launches it. It is recorded in `~/.config/samagotchi/home.json` (`$XDG_CONFIG_HO
1408
1408
  "gem_path": "/Users/me/.gem/ruby/4.0.0:/Users/me/.local/share/mise/installs/ruby/4.0.7/lib/ruby/gems/4.0.0",
1409
1409
  "mise": "/opt/homebrew/bin/mise",
1410
1410
  "set_at": "2026-10-29T21:00:00Z",
1411
- "set_by_version": "0.132.0"
1411
+ "set_by_version": "0.132.0",
1412
+ "version": 1
1412
1413
  }
1413
1414
  ```
1414
1415
 
1416
+ (`version` is the file's format, `ChiHome::STATE_FORMAT`: a home.json without one is an older chi's, and a newer chi's
1417
+ keeps its version and the keys this chi doesn't know when the same home is set again.)
1418
+
1415
1419
  - **Setting it.** `chi home set` records the Ruby your `chi` runs on and its gem path (a chruby shell's
1416
1420
  `GEM_HOME`/`GEM_PATH` are part of it: that is where its chi lives); `chi home set --ruby PATH` records another
1417
1421
  Ruby with its own gem dirs. Either needs samagotchi installed there (`gem install samagotchi` with that Ruby
data/docs/guardrails.md CHANGED
@@ -339,21 +339,18 @@ else the parent's checkout). Rule `child-boundary`, source `core`; it asks when
339
339
  - a call whose [targets](plugins.md#guardrails) say it writes its paths —
340
340
  `write`, `edit`, and a plugin tool's `targets:` with `writes: true` —
341
341
  names a path outside it (tmp dirs and memory files don't count);
342
- - `execute` or `task_create` runs mutating git in another dir (`git -C`, `cd`,
343
- `GIT_DIR`: what `git: outside_repo` matches), or a command that isn't
344
- read-only starts outside it (its `cwd:`) or names a path in the repository's
345
- other checkouts (the main one and sibling worktrees, read from
346
- `<common git dir>/worktrees/*/gitdir`) or in its common git dir;
347
- - `execute` or `task_create` runs git that changes what every checkout shares,
348
- even from its own worktree: a `git config` write (not `--get`, `--list`,
349
- `--worktree`), `update-ref`, `worktree add|remove|move|prune`, `stash
350
- drop|clear|pop`, creating or deleting a tag, and deleting, forcing or
351
- overwriting a branch other than its own;
352
- - any call whose `targets:` carry a `command:` (a plugin tool's) is checked
353
- for git that changes what every checkout shares, and for a `cwd:` outside
354
- the child's folder. Its command's text may not be shell, so the reads a
355
- shell call gets (its `git -C`/`cd` dirs, its redirects, its read-only test)
356
- are left out.
342
+ - a shell call runs mutating git in another dir (`git -C`, `cd`, `GIT_DIR`:
343
+ what `git: outside_repo` matches), or a command that isn't read-only starts
344
+ outside it (its `cwd:`) or names a path in the repository's other checkouts
345
+ (the main one and sibling worktrees, read from
346
+ `<common git dir>/worktrees/*/gitdir`) or in its common git dir. A shell
347
+ call is `execute`, `task_create`, or a plugin call whose `targets:` carry a
348
+ `command:`;
349
+ - a shell call runs git that changes what every checkout shares, even from its
350
+ own worktree: a `git config` write (not `--get`, `--list`, `--worktree`),
351
+ `update-ref`, `worktree add|remove|move|prune`, `stash drop|clear|pop`,
352
+ creating or deleting a tag, and deleting, forcing or overwriting a branch
353
+ other than its own;
357
354
 
358
355
  Read-only commands (`git -C ../app log`, `cat ../app/x`) and paths elsewhere
359
356
  (`/usr/bin`, `~/.gem`) never ask, nor does a read-only command that writes only
@@ -738,7 +735,7 @@ guardrails:
738
735
  mode: auto # or strict: also the rules tagged modes: [strict]; config.yml only
739
736
  rules:
740
737
  - id: git-push
741
- tool: shell # execute + task_create; or a tool name, a glob, or a list
738
+ tool: shell # shell calls, including plugin targets with command:; or a name, glob or list
742
739
  command: '\bgit\s+push\b' # Ruby regex on the command (data heredoc bodies left out)
743
740
  verdict: ask # ask | deny
744
741
  reason: git push publishes commits
@@ -15,7 +15,7 @@ model. The TUI is untouched: it shows a fence as source.
15
15
  didn't know the key draws once a kept manifest is there) lists
16
16
  who draws what: `GET /api/block_renderers`, `:owner`. `GET /api/block_renderers/:bundle/:file` serves a file, `:owner`:
17
17
  the URL's names go through `BlockRenderers.script_path` (membership in a listed renderer's `load` before any path is
18
- made), then `Provenance.sha_matches?`; a file with no recorded sha, a missing one or a changed one is 409
18
+ made), then `Provenance#script_failure` (the check a context provider's scripts get too); a file with no recorded sha, a missing one or a changed one is 409
19
19
  `renderer_changed`, each with its own reason. ETag + `no-cache`, as static files. A `block_renderers:` list that
20
20
  doesn't parse is logged once per bundle and problem (each list request and file fetch reads it).
21
21
  3. `block_watch.js` (`createBlockWatch`, made by `block_host.js`'s `createBlockHost`, wired in `app.js`; `participant.js`
@@ -5,6 +5,8 @@ localhost HTTP server in the worker's process, next to the `Engine` it reads and
5
5
  terminal are its clients; no browser reaches it. [architecture.md](../architecture.md) places it among the layers;
6
6
  this page is the surface: what it keeps, how a client joins and catches up, and every route.
7
7
 
8
+ Bridge Engine calls are listed with their reasons in `Bridge::ENGINE_CALLS`; add each new Engine call there.
9
+
8
10
  ## What a Bridge keeps
9
11
 
10
12
  `Bridge#start` binds a port (OS-assigned, `127.0.0.1`), then subscribes four persistent observers to the Engine
@@ -52,8 +54,7 @@ Three other users: `replay_events(turn)` turns a `current_turn` back into the li
52
54
  `turn_started` also carries `at`, `cut_after` and every author key, then a `turn_enqueued` per queued prompt and a
53
55
  `command_queued` per waiting command), which chi web's `GET /api/sessions/:id` sends as `replay` from the worker's
54
56
  snapshot (`from_wire` symbolizes it), so any worker's snapshot gives the page the same events
55
- (`spec/shared/turn_snapshot.json` pins it against turn_events.js `snapshotEvents`, the page's own fallback for one
56
- release); `messages_of` gives a
57
+ (`spec/shared/turn_snapshot.json` pins it); `messages_of` gives a
57
58
  plugin's `ctx.messages` the turn so far (`Engine#running_turn_messages`); `participant_turn?` tells `POST /turn` that
58
59
  a participant's review turn runs, so the owner's input queues behind it.
59
60
 
@@ -448,7 +449,7 @@ The Bridge exposes:
448
449
  `leaving_exit` / `leaving_delete` / `leaving_restart` when another client's exit of another kind is already taken
449
450
  (`Worker#claim_exit`, claimed before a stop-all; the words are `WorkerIdleExit::LEAVING_WORDS`). A second exit of
450
451
  the kind already taken is answered `200` as that one.
451
- - `GET /session/:id/state` — `session_state_snapshot` (JSON).
452
+ - `GET /session/:id/state` — `session_state_snapshot` (JSON), read under the event lock so its `event_seq`/`event_id` match the state.
452
453
  - `GET /session/:id/stats` — `Engine#stats_snapshot` for attached `/stats`: the metrics, with the context window and prompt profile asked from the server before the first turn.
453
454
  - `GET /session/:id/activity` — `Worker#activity_snapshot`: `{session_id, turn_running, input_pending, awaiting_continue, open_streams, reminders, tasks_holding}` — what a `chi schedule tick` asks a live worker before it fires (the tick runs out of process and cannot read a worker's memory). Read-only and small (under 300 bytes). `501 activity_unavailable` when this Bridge was built without an `on_activity:` step; the worker advertises it in `Bridge::FEATURES` (`activity`). See [scheduling.md](../scheduling.md).
454
455
  - `GET /session/:id/snapshot` — the snapshot frame's content as one request (the web server renders
@@ -179,8 +179,10 @@ its removal, so no edit is lost, and the record isn't written, so a retry is the
179
179
  failed run already placed stay, and the intent journal says they are the bundle's.
180
180
 
181
181
  **The intent journal.** After `check_named_files` and before the first write, a real run with a manifest writes
182
- `.bundles/<name>/pending.json` (`Provenance#write_pending`, atomically like the record): `{"version": "2.0.0",
183
- "scope": "project", "target_dir": "/path/to/project-memories", "files": {"a.md": ["<sha256>"]}}`: the target
182
+ `.bundles/<name>/pending.json` (`Provenance#write_pending`, atomically like the record): `{"pending_format": 1,
183
+ "version": "2.0.0", "scope": "project", "target_dir": "/path/to/project-memories", "files": {"a.md": ["<sha256>"]}}`
184
+ (`pending_format` is its `StateFormat`, `PENDING_FORMAT`: a journal without it is an older chi's, the same members; a
185
+ newer chi's keeps its format and unknown keys through a retry's write, and the release corpus records one): the target
184
186
  `version` is the latest run's target version, while `files` holds the union of incoming shas recorded by interrupted
185
187
  runs for that scope/target directory. A retry of another version in the same target adds its incoming shas; a journal
186
188
  for another scope directory is ignored. `Provenance#write` removes it with the record write; an uninstall's `rm_rf`
@@ -57,6 +57,10 @@ Pure Ruby, no web, no Engine. `parse(source)` returns a `Result`: `ok?`, `type`,
57
57
  `next` or a `goto` goes. This is a mend, not a second lenient pass (`Tree#folds`, `Schema#text`).
58
58
  - **Normalised.** Ids are strings, unknown keys are dropped, a repeated key is last-wins (`Tree#mapping`), optional values are absent rather than null, and text is
59
59
  stripped. The page never sees model junk.
60
+ - **A row id never starts a command.** Fill reply puts a picks row's id first in the composer, so a leading `!` (a
61
+ shell line) or `/` (a session command), with the spaces between them, is dropped from it (`Schema#row_id`,
62
+ `COMMAND_LEAD`): `!touch x` is the id `touch x`, the Result `lenient?`, a mend like a fold. An id of nothing else is
63
+ refused, and the uniqueness check sees the mended ids. A walk's ids never reach the composer and stay as written.
60
64
 
61
65
  ### The schemas
62
66
 
@@ -125,7 +129,10 @@ session switch, a turn's end, Revise's clones, the stage's hand-off to `#history
125
129
 
126
130
  **The only way out is composer text.** Fill reply builds `id: option (note) · …` from the picked rows (a row with no
127
131
  pick is left out) and hands it to app.js's `fillComposer`, after a typed draft on a new line (`withDraft`; the draft
128
- is kept). It never sends: the owner reads the text and sends it or not. A walk has no way out at all. The model's
132
+ is kept). It never sends: the owner reads the text and sends it or not. `replyText` drops a leading `!` or `/` from
133
+ an id too (an id of only those is its row's number), so the filled text never starts a shell line or a session command
134
+ even from data the normaliser didn't mend; the draft before it is the owner's own. The row's `wp-id` chip shows that
135
+ same cleaned id (`rowId`, one rule for both), so what is drawn is what fills. A walk has no way out at all. The model's
129
136
  strings reach the page through `textContent` and attributes only, never `innerHTML`, so a step reading
130
137
  `<img src=x onerror=…>` shows as those characters.
131
138
 
@@ -218,15 +218,42 @@ createFamilyPop`) still place their own. Every popover behaves the same (`popove
218
218
  none behind. `model_picker.js`, `command_list.js` (listboxes: the focus stays in the input), `ref_menu.js` (a menu)
219
219
  and `update_sheet.js` (a native modal `<dialog>`) aren't popovers in that sense.
220
220
 
221
- **A phone's session bar** (`more_sheet.js`): CSS alone folds the chips and the bar's buttons away at 600 px or less
222
- (`display:none`, so the same `.meta` draws both layouts and `info_bar.js` knows nothing of it); they stay in the DOM.
223
- ⋯'s sheet (`#infoMoreBtn`) draws its rows from the bar's model, and a row or an action clicks the real chip or button, so
224
- each keeps one set of handlers, confirmations and in-flight rules. A chip the sheet opens has no box to be placed at, so
225
- `chip_popover.js` places it, marks `aria-expanded` and gives focus back at the page's `[data-anchor-stand-in]` (⋯); that
226
- matters at exactly 600 px, where the CSS is a phone's but the shell (`SHEET_MAX`, `<`) still draws a popover, not a sheet.
227
- A new chip on the bar needs its place in that CSS's hidden list and a row in `moreRows`, and its attention state in the row, or
228
- it is lost on a phone. `app.js`'s `updateInfoBar` feeds the sheet (`update`) on every redraw; its rows and actions draw into
229
- fixed slots, so a row that joins keeps the focus where it was. `composer_mode.js`'s phone-width listener closes the sheet when the window grows.
221
+ **The session bar: one row** (`bar_fold.js`, `more_sheet.js`): `#infoBar` is one row at every width, and what doesn't
222
+ fit folds into ⋯. Every chip and button is an **item** of `info_bar_model.js` `BAR_ITEMS`: `{key, selector, group,
223
+ rank, phone, compact, menuOrder}`. `rank` is the desktop fold order (higher stays longer; `pinned` never folds: status,
224
+ ctx, ⋯; `menu` is never on the row: archive, delete); `phone: row` items are the only row candidates at 600 px or less
225
+ (status, ctx, speed, ⚙, ⋯); ⚙ alone has a `compact` form (its icon, the dot when the session set its own), tried before
226
+ it folds, and the phone's from the start. `info_bar.js` draws the `.meta` as four groups (identity: id, status, ctx,
227
+ speed, clock | setup: ⚙, model, 🧰, notes, set/mem | relations | trail: folder, worker badge), each `.bar-sep` classed
228
+ by the group it precedes; `#infoActions` (continue →, stop session) and ⋯ follow, right-aligned.
229
+
230
+ The **fold** is `foldPlan` (pure): every candidate full, then while the row is wider than the bar the lowest rank on it
231
+ (all items of that rank together) goes compact, else folds; pinned items never fold (the row clips). Its widths are
232
+ measured, never read from a squeezed box: the row's children are `flex:none` and the caps (model 40ch, folder 48ch)
233
+ hold always, so a drawn chip's width is its natural one. `createBarFold` caches them per key + text; a folded item has
234
+ no box, so a text first seen while folded is measured by dropping the fold's attributes for one synchronous pass
235
+ (before paint). ⋯'s count joins the row's width once something it counts folds. The live chips (ctx, speed, clock) are
236
+ cached per key as a budget (their CSS reserve is their `min-width`): a tick within it costs a width read, no refold.
237
+ A recompute runs only when an input changes: `foldSignature(bar, buttons)` (the items present and every non-live
238
+ text: a status, `set 9 → set 10`, a delegate starting to wait), the bar's width (`ResizeObserver` on `#infoBar`), the
239
+ phone profile, a live chip past its budget, the fonts ready or a zoom (those clear the cache). A recompute it starts by
240
+ itself calls `onChange` (app.js touches `infoBar`) so ⋯ follows. Call order in `app.js updateInfoBar`: `renderInfoBar`
241
+ → `barFold.update` → `moreSheet.update({bar, buttons, folded})`, in one task. The plan is three attributes on
242
+ `#infoBar` (lit renders into `#infoText` inside it, so they survive the redraws): `data-folded="notes toolkit dir"`,
243
+ `data-compact="settings"`, `data-empty-groups="relations"`; index.html has one `display:none` selector per key and
244
+ hides an empty group with its hairline. **A new chip needs a `BAR_ITEMS` entry and its `data-folded` selector**
245
+ (`bar_fold.test.js` checks every foldable key has one), or it can't fold.
246
+
247
+ ⋯'s menu (`more_sheet.js`) is a popover above 600 px and a bottom sheet under it (`chip_popover.js`, `SHEET_MAX`; its
248
+ own resize handling switches them, so a width change doesn't close it). It holds a row only for a folded item (the id,
249
+ ⚙ when folded and not compact, "earlier links pruned" included), the folded ones of speed, clock and folder on its
250
+ telemetry line (none: no line), archive and delete always, continue and stop when folded. Its dot (`moreAttention`)
251
+ and its count (`moreCount`, a desktop's, none at 0; archive and delete don't count) are from folded items alone: a chip
252
+ on the row shows its own state. Folded items stay in the DOM, display:none: a row or an action clicks the real chip or
253
+ button, so each keeps one set of handlers, confirmations and in-flight rules, and what a chip opens has no box to be
254
+ placed at, so `chip_popover.js` places it, marks `aria-expanded` and gives focus back at the page's
255
+ `[data-anchor-stand-in]` (⋯). Rows and actions draw into fixed slots, so a row that joins keeps the focus where it was.
256
+ The e2e reach an item wherever it is with `spec/e2e/support/layout.js` `clickBarItem` (the row, else ⋯'s `[data-row]`).
230
257
 
231
258
 
232
259
  ## The stage's height
data/docs/memory.md CHANGED
@@ -32,8 +32,13 @@ the folder is left as is: it is created when missing, nothing is marked).
32
32
  (`chi context --project`) are named by the marker's `id:` (`<folder name>-<8 random hex>`), not
33
33
  by its path, so moving or renaming the folder keeps them: a session started there after the move
34
34
  finds them, and one saved before it (its file stores `project_id`) keys its context sources by the
35
- id too. A folder chi already ran in at its top keeps its memories after `init`: they move to the
36
- id. A later `git init` in the folder makes it a repository, keyed by its path again (git wins): its
35
+ id too. An existing id folder is used only when its `.root` claims this project, or when its
36
+ previous claimant or a saved session's root no longer has this id after a move; otherwise chi
37
+ refuses and says to run `chi project init --new-id`. An id folder with no `.root` is taken when its
38
+ name has a path key's shape (`<name>_<8 hex>`: another project's folder); one of any other name (an
39
+ older chi's id folder) is used and claimed at session start. A folder chi
40
+ already ran in at its top keeps its memories after `init`: they move to the id. A later `git init`
41
+ in the folder makes it a repository, keyed by its path again (git wins): its
37
42
  memories stay in the id folder until you move them, and chi names the id folder at session start
38
43
  (and under a `memory_read` miss) while the repository's own folder holds no memories. Memories saved from a *subfolder* before
39
44
  `init` stay in that subfolder's own folder (keyed by its path); `chi project init` and `chi project`
@@ -59,11 +64,11 @@ the folder is left as is: it is created when missing, nothing is marked).
59
64
  but never moves folders: a folder it marks that already has path-keyed memories gets no id until
60
65
  `chi project init`.
61
66
  - **A copy shares memories.** A copied marked folder (`cp -R`) keeps the id, so the two share one
62
- memories folder; at session start in the copy chi says so (a `memory>` load warning: "… share chi
63
- project id … (a copied folder?)"; the id folder's `.root` names the folder that started a session
64
- with it last, the original keeps it). `chi project init --new-id` in the copy gives it a fresh id,
65
- with a copy of the memories and project context sources it had: each folder goes its own way.
66
- After a move, the new path just takes `.root` over, with no warning.
67
+ id folder. At session start chi claims a new id folder in `.root`; if another marked folder still
68
+ has that id, chi warns and refuses to use the folder's memories or project context sources.
69
+ `chi project init --new-id` in the copy gives it a fresh id, but does not copy an id folder claimed
70
+ by another project. After a move, the new path takes `.root` over when the old path no longer has
71
+ that id, with no warning.
67
72
  - **Restart what runs there.** A session running in the folder when it is marked keeps the old memories
68
73
  folder and AGENTS.md chain in its prompt until `chi sessions restart ID` (init names them); a running
69
74
  `chi web` groups the folder's older sessions under the project after its restart.
data/docs/plugins.md CHANGED
@@ -341,9 +341,9 @@ is what `targets:` says:
341
341
  it when the call writes, never when it only reads (a read's paths are
342
342
  `path:` rule material, not a write); a tool without it is judged as
343
343
  today.
344
- - `command:`: a shell command the call runs; `command:` rules match it, and
345
- a delegate child's boundary checks where it runs and whether it changes
346
- what every checkout shares (as for `execute`).
344
+ - `command:`: a shell command the call runs; `tool: shell` and `command:`
345
+ rules match it, and a delegate child's boundary checks it as it does
346
+ `execute` and `task_create`.
347
347
  - `cwd:`: where it runs, for the repo root and relative paths.
348
348
  - `acts_as:`: the tool a call stands for, when the tool runs other tools
349
349
  (chi's `call_tool`, which calls a tool a [source](#chitool_sourcecall-acts_as-label-wait-prefix) published). Rules keyed by that tool's name match the
@@ -1260,7 +1260,9 @@ ctx.sessions.review(subjects: ["docs/plan.md"], seed: handoff) # => a review se
1260
1260
  review session's id. The test kit's `bundle.sessions` answers `review-1`,
1261
1261
  `review-2`…
1262
1262
  - `send(id, text)` sends a user message to a session (an id or a unique
1263
- prefix); it runs as a turn, and a stopped session is woken. It waits up to
1263
+ prefix); it runs as a turn, and an idle session is woken. A session its
1264
+ owner stopped or archived is not: `Error` (`session_stopped` /
1265
+ `session_archived`), nothing sent. It waits up to
1264
1266
  5 s for the session's worker, so call it from an anytime command or a
1265
1267
  thread of your own, never from a tool or hook of a running turn. A
1266
1268
  session a `--non-interactive` one-shot has can't take it.
data/docs/releasing.md CHANGED
@@ -98,9 +98,13 @@ The agent does each step and stops where the user has to say yes.
98
98
  each one's version, none for a profile already bumped since the last tag),
99
99
  which it names in the CHANGELOG's "Update with `chi update`" line, and the
100
100
  SINCE entries it moved out of their `# Unreleased` comments. It also records
101
- the release's session, bridge, cards, schedules and bundle state under
101
+ the release's session, bridge, cards, schedules and bundle state, and a
102
+ session's input file, note, continue intent and stop marker and a bundle's
103
+ install journal, under
102
104
  `spec/compat/X.Y.Z/`; commit those samples with the release so the next
103
- release's reader spec checks them as N-1 data.
105
+ release's reader spec checks them as N-1 data. The new VERSION may pass a
106
+ compat shim's `remove_after` (`Compat::SHIMS`): `spec/compat_spec.rb` then
107
+ names it, and the shim goes (or its date moves) before the release.
104
108
  5. **Check.** Add all release files, including the new compatibility corpus, then run it:
105
109
  `git add -A && git commit -m "Release X.Y.Z"` and `bundle exec rake release:check`.
106
110
  Fix anything it finds in new commits and run it again.
data/docs/scheduling.md CHANGED
@@ -62,6 +62,10 @@ a participant's review or pair turn is denied them ([guardrails.md](guardrails.m
62
62
  `head` through the chain: once the session is continued — by a chain schedule or
63
63
  by a `chi send --continues` — the turn goes to the new link, not to the archived
64
64
  anchor the schedule was made against.
65
+ Both modes resolve the **chain's end** (`SessionChain::Links#latest`), not the
66
+ first live link a `chi send` takes: a chain firing can only continue the end, and
67
+ an archived end (a chain you retired) fails the firing instead of being brought
68
+ back as a send would.
65
69
 
66
70
  A `scratch` session is refused at `add`: it is deleted when its terminal leaves.
67
71
  A prompt is checked at `add` too — non-empty and at most 16 KiB
@@ -103,6 +107,13 @@ time zones.
103
107
 
104
108
  A cron tick cannot read a worker's memory, so the tick has two paths.
105
109
 
110
+ **Stopped by its owner** (`chi sessions stop`, the web's Stop: the stop marker,
111
+ `WorkerPresence#stop_marked?`) comes first, in both modes: a skip ("the session is
112
+ stopped; only its owner's message starts it again"), never a restart. A stop that
113
+ lands between the check and a same-mode firing is the same skip: `deliver_turn`
114
+ refuses a schedule's wake of a stopped session (a schedule is no person,
115
+ `ClientId.wake_kind`).
116
+
106
117
  **No live worker** (the usual case for a weekly schedule): the files say what can
107
118
  be known — the saved status is not `running` (and not inside the starting grace),
108
119
  `input/` is empty, no step-limit question is open, and, for chain mode, no worker
@@ -150,9 +161,20 @@ are the refusals that mean "not this moment": `ArchiveRefused` with `busy`, `que
150
161
  or `offer`, or `busy_child`/`queued_child`/`offer_child` (a chain's own running
151
162
  delegate refuses the archive, since `archivable!` walks the whole descendant tree),
152
163
  `SessionContinue::Refused(:continued)` (a human continued it while we were
153
- resolving) and `:open_children`.
154
-
155
- Anything else is a **failure** (`failures += 1`): a gone or archived target,
164
+ resolving) and `:open_children`. So is an archived target that a continue is still
165
+ making the next link of (`being continued as 7b2d41aa; retry at the next tick`): a
166
+ person's `chi send --new --continues` or web `continue →` archives the link before
167
+ its successor is saved, and a tick in that moment sees an archived end
168
+ (`ContinueIntent.in_flight`: the intent written, its lock held). It is checked before
169
+ the busy check, in both modes, and again by a same-mode firing's own look at the
170
+ files; the next tick's walk reaches the new link. A continue that ended between the
171
+ tick's listing and that look (its successor saved, its intent gone) is no failure
172
+ either: the firing walks again on a fresh listing, checks the new link as the tick
173
+ would, and queues its turn there. A stale intent (no continue holds
174
+ its lock: a crash, repaired by the next continue or list) is not in flight, so that
175
+ target still fails `archived`.
176
+
177
+ Anything else is a **failure** (`failures += 1`): a gone or archived target (an archived end of the chain: you retired it, and a schedule never brings it back),
156
178
  `SessionContinue::Refused(:folder_gone)`, `SessionManager::DeleteRefused`,
157
179
  `ModelProfile::MissingModel`, `OwnedByTUI`, `Session::NotFound`, and anything a
158
180
  spawn throws (`Errno::ENOSPC` included — `run_locked` re-raises it after undoing