samagotchi 0.194.0 → 0.196.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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +80 -1
  3. data/docs/architecture.md +2 -1
  4. data/docs/bundle-authoring.md +23 -23
  5. data/docs/bundles.md +201 -7
  6. data/docs/cli.md +5 -1
  7. data/docs/configuration.md +25 -4
  8. data/docs/context.md +13 -3
  9. data/docs/guardrails.md +6 -4
  10. data/docs/hooks.md +3 -1
  11. data/docs/internals/attached-context.md +2 -0
  12. data/docs/internals/block-renderers.md +4 -1
  13. data/docs/internals/bridge.md +4 -0
  14. data/docs/internals/engine.md +15 -2
  15. data/docs/internals/knowledge.md +215 -0
  16. data/docs/internals/pages.md +17 -9
  17. data/docs/internals/panes.md +51 -13
  18. data/docs/internals/participants.md +15 -3
  19. data/docs/internals/peers.md +14 -9
  20. data/docs/internals/session-lifecycle.md +26 -12
  21. data/docs/internals/web-frontend.md +64 -27
  22. data/docs/memory.md +4 -2
  23. data/docs/pages.md +72 -1
  24. data/docs/peers.md +25 -14
  25. data/docs/plugins.md +132 -6
  26. data/docs/releasing.md +1 -1
  27. data/docs/scheduling.md +4 -0
  28. data/docs/sessions.md +9 -2
  29. data/docs/system-one.md +3 -1
  30. data/docs/testing.md +3 -1
  31. data/lib/samagotchi/bundle_manifest.rb +30 -5
  32. data/lib/samagotchi/bundles/claude-peer/manifest.yml +8 -5
  33. data/lib/samagotchi/bundles/claude-peer/plugin.rb +2 -2
  34. data/lib/samagotchi/bundles/codex-peer/manifest.yml +8 -5
  35. data/lib/samagotchi/bundles/codex-peer/plugin.rb +3 -3
  36. data/lib/samagotchi/bundles/coordinator/manifest.yml +7 -4
  37. data/lib/samagotchi/bundles/coordinator/plugin.rb +15 -5
  38. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +10 -0
  39. data/lib/samagotchi/bundles/core/manifest.yml +2 -2
  40. data/lib/samagotchi/bundles/cost-cap/manifest.yml +4 -4
  41. data/lib/samagotchi/bundles/cost-cap/plugin.rb +54 -3
  42. data/lib/samagotchi/bundles/dev/manifest.yml +3 -2
  43. data/lib/samagotchi/bundles/github-pr/manifest.yml +4 -2
  44. data/lib/samagotchi/bundles/knowledge/adapters.rb +205 -0
  45. data/lib/samagotchi/bundles/knowledge/catalog.rb +151 -0
  46. data/lib/samagotchi/bundles/knowledge/chi_adapters.rb +178 -0
  47. data/lib/samagotchi/bundles/knowledge/chunker.rb +55 -0
  48. data/lib/samagotchi/bundles/knowledge/github.rb +246 -0
  49. data/lib/samagotchi/bundles/knowledge/manifest.yml +27 -0
  50. data/lib/samagotchi/bundles/knowledge/plugin.rb +807 -0
  51. data/lib/samagotchi/bundles/knowledge/query.rb +30 -0
  52. data/lib/samagotchi/bundles/knowledge/query_log.rb +55 -0
  53. data/lib/samagotchi/bundles/knowledge/refresh.rb +133 -0
  54. data/lib/samagotchi/bundles/knowledge/store.rb +264 -0
  55. data/lib/samagotchi/bundles/reflect/manifest.yml +17 -0
  56. data/lib/samagotchi/bundles/reflect/scripts/reflect.rb +439 -0
  57. data/lib/samagotchi/bundles/reflect/skill_reflect.md +100 -0
  58. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  59. data/lib/samagotchi/context_change.rb +44 -0
  60. data/lib/samagotchi/context_note.rb +1 -1
  61. data/lib/samagotchi/context_providers.rb +14 -0
  62. data/lib/samagotchi/context_sources.rb +3 -25
  63. data/lib/samagotchi/engine/plugins.rb +21 -0
  64. data/lib/samagotchi/events.rb +1 -0
  65. data/lib/samagotchi/guardrails/pair_boundary.rb +12 -4
  66. data/lib/samagotchi/guardrails/review_paths.rb +13 -3
  67. data/lib/samagotchi/guardrails/targets.rb +24 -2
  68. data/lib/samagotchi/guardrails_command.rb +3 -9
  69. data/lib/samagotchi/hook_label.rb +19 -0
  70. data/lib/samagotchi/hook_routes.rb +3 -2
  71. data/lib/samagotchi/installed_bundles/manifest.rb +7 -1
  72. data/lib/samagotchi/memory_bundle/builder.rb +2 -1
  73. data/lib/samagotchi/memory_bundle/installed_copy.rb +2 -1
  74. data/lib/samagotchi/page_command.rb +90 -6
  75. data/lib/samagotchi/pages/launch.rb +16 -8
  76. data/lib/samagotchi/pages/runner.rb +7 -2
  77. data/lib/samagotchi/pages/runtime.rb +62 -2
  78. data/lib/samagotchi/pages.rb +4 -0
  79. data/lib/samagotchi/panes/kitty.rb +20 -5
  80. data/lib/samagotchi/panes.rb +81 -12
  81. data/lib/samagotchi/participants.rb +17 -6
  82. data/lib/samagotchi/peer_exchanges.rb +1 -2
  83. data/lib/samagotchi/peer_note.rb +38 -5
  84. data/lib/samagotchi/peer_presence.rb +20 -7
  85. data/lib/samagotchi/plugin/api.rb +11 -1
  86. data/lib/samagotchi/plugin/attached_context.rb +46 -1
  87. data/lib/samagotchi/plugin/chips.rb +125 -0
  88. data/lib/samagotchi/plugin/context.rb +43 -8
  89. data/lib/samagotchi/plugin/panes.rb +52 -9
  90. data/lib/samagotchi/plugin/peer_pairing.rb +2 -2
  91. data/lib/samagotchi/plugin/peer_start.rb +61 -36
  92. data/lib/samagotchi/plugin/peers.rb +6 -3
  93. data/lib/samagotchi/plugin/project.rb +63 -0
  94. data/lib/samagotchi/plugin/sessions.rb +36 -1
  95. data/lib/samagotchi/plugin/tool_spec.rb +28 -9
  96. data/lib/samagotchi/schedules.rb +8 -2
  97. data/lib/samagotchi/session.rb +22 -9
  98. data/lib/samagotchi/session_access/local.rb +34 -33
  99. data/lib/samagotchi/session_chain/sharing.rb +79 -0
  100. data/lib/samagotchi/session_chain/successor.rb +4 -2
  101. data/lib/samagotchi/session_chips.rb +133 -0
  102. data/lib/samagotchi/session_inbox_delivery.rb +11 -11
  103. data/lib/samagotchi/session_manager/emptiness.rb +4 -1
  104. data/lib/samagotchi/session_observer.rb +1 -1
  105. data/lib/samagotchi/session_stats.rb +437 -0
  106. data/lib/samagotchi/session_stores.rb +3 -0
  107. data/lib/samagotchi/session_window.rb +30 -0
  108. data/lib/samagotchi/speaker.rb +228 -0
  109. data/lib/samagotchi/steer.rb +36 -132
  110. data/lib/samagotchi/system_one/approval_choice.rb +22 -0
  111. data/lib/samagotchi/system_one/approval_label.rb +4 -6
  112. data/lib/samagotchi/system_prompt.rb +3 -1
  113. data/lib/samagotchi/terminal_ui/attach_launcher.rb +30 -0
  114. data/lib/samagotchi/testing/boundary.rb +17 -4
  115. data/lib/samagotchi/testing/bundle.rb +5 -0
  116. data/lib/samagotchi/testing/host.rb +1 -0
  117. data/lib/samagotchi/testing/recorder.rb +10 -0
  118. data/lib/samagotchi/testing/sessions.rb +11 -3
  119. data/lib/samagotchi/toolkit.rb +11 -4
  120. data/lib/samagotchi/toolkit_report_command.rb +14 -18
  121. data/lib/samagotchi/toolkit_suggest.rb +9 -2
  122. data/lib/samagotchi/tools/registry.rb +48 -18
  123. data/lib/samagotchi/tools/tool_index.rb +6 -2
  124. data/lib/samagotchi/turn_excerpts.rb +302 -0
  125. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +9 -0
  126. data/lib/samagotchi/version.rb +1 -1
  127. data/lib/samagotchi/web/app.rb +21 -10
  128. data/lib/samagotchi/web/participant_view.rb +1 -1
  129. data/lib/samagotchi/web/peer_routes.rb +5 -2
  130. data/lib/samagotchi/web/plugin_chip_rows.rb +39 -0
  131. data/lib/samagotchi/web/public/agent_rows.js +1 -0
  132. data/lib/samagotchi/web/public/app.js +17 -25
  133. data/lib/samagotchi/web/public/chains.js +0 -26
  134. data/lib/samagotchi/web/public/command_list.js +2 -3
  135. data/lib/samagotchi/web/public/composer.js +2 -3
  136. data/lib/samagotchi/web/public/composer_mount.js +3 -6
  137. data/lib/samagotchi/web/public/context_chips.js +240 -93
  138. data/lib/samagotchi/web/public/context_groups.js +84 -0
  139. data/lib/samagotchi/web/public/draft_follow.js +33 -0
  140. data/lib/samagotchi/web/public/drafts.js +26 -22
  141. data/lib/samagotchi/web/public/index.html +32 -0
  142. data/lib/samagotchi/web/public/peer_chip_kind.js +49 -0
  143. data/lib/samagotchi/web/public/peer_note.js +2 -2
  144. data/lib/samagotchi/web/public/peer_row.js +10 -5
  145. data/lib/samagotchi/web/public/peer_wait.js +4 -2
  146. data/lib/samagotchi/web/public/plugin_chip.js +55 -0
  147. data/lib/samagotchi/web/public/plugin_chip_kind.js +48 -0
  148. data/lib/samagotchi/web/public/send_turn.js +8 -21
  149. data/lib/samagotchi/web/public/session_actions.js +10 -23
  150. data/lib/samagotchi/web/public/session_view.js +7 -3
  151. data/lib/samagotchi/web/public/stream_handlers.js +2 -0
  152. metadata +33 -1
@@ -53,7 +53,10 @@ so nothing reads it as a session):
53
53
  A dead one is removed by whoever reads the folder. A live one on the same address under another session id is superseded by the announce
54
54
  (a `/clear` gives Claude a new session id on the same socket): removed, its pairing files moved, its links'
55
55
  `peer_session` renamed (`Local#peer_retag`).
56
- - `waiting/<chi session>.json`: `PeerWaiting(session, project, at)`, a 10-minute wait (`WAIT_SECONDS`); an `at` in
56
+ - `waiting/<chi session>.json`: `PeerWaiting(session, project, at, app)`, a 10-minute wait (`WAIT_SECONDS`); `app`
57
+ is the peer's product name as its bundle words it (`peer::APP`, "Claude Code": chi web's waiting chip, which loads
58
+ no plugins), written only when given, read only as a String of at most `APP_CHARS` (60), else none (an older
59
+ worker's mark has none); an `at` in
57
60
  the future or unparsable is stale, and `marks` (what an announce and `--here` pair against) skips an archived
58
61
  session's (stale on read: archiving leaves the file). **A stale wait is removed only by its session's worker** (`PeerWaitExpiry`, from
59
62
  `Worker::MailPart#expire_peer_waits` in `idle_pass`: removed, and once per wait `:peer_wait_ended`, the bundle's
@@ -126,7 +129,8 @@ live by its pid, `ctx.panes`, only under `ctx.user_typed?`), `unpair`. A bundle
126
129
  Codex's hooks.json (the bundle's `#hook_file`, `#start_hook_line`, `#hook_paragraph`, `#hook_written_line`,
127
130
  `#hook_stale_tail`); `#with_hook` replaces an announce line in place, else appends a group, never reorders (Codex's
128
131
  trust is `[hooks.state."<file>:session_start:<group>:<hook>"]` in config.toml, index-keyed, which chi never writes). `/<peer> start`
129
- (`Plugin::PeerStart`) writes the wait and opens a kitty tab running the peer: it has no path of its own to pair (the
132
+ (`Plugin::PeerStart`) writes the wait and opens a kitty window running the peer (a pane next to the session's chi terminal, or a
133
+ background tab: the bundle setting `open_in`, [panes.md](panes.md)): it has no path of its own to pair (the
130
134
  started Claude's announce takes the wait; codex-peer's first prompt runs the skill's `--here`, or its start hook
131
135
  takes the wait at that prompt; `#start_needs_hook?`: claude true, codex false, and codex's opened line adds
132
136
  `#start_review_hint` while its hook is current); its `PaneRef` lives
@@ -164,11 +168,11 @@ which posts `…/peers/NAME/say` with its `wait`: chi web waits, and its read ti
164
168
  reached from a continued id: `:continued` naming that link, the words the 0.192.0 skills pair again on), a live
165
169
  worker without the `peer_mail` Bridge feature (`WorkerLink.live_features`, read only), `UNTAKEN_MAX` (200)
166
170
  untaken messages or noted receipts.
167
- 2. Under a shared hold of the session's transition lock (`SessionTransition.shared`, `Local#moved_on`), the
171
+ 2. Under a shared hold of the session's transition lock (`SessionChain::Sharing.under`, `Local#moved_on`), the
168
172
  continued check again, then the delivery (step 3): a continue holding the lock (from after its recap through
169
- `PeerContinue`'s carry) refuses the say `:continued` naming its new link (`SessionChain::Successor.of` with
170
- `in_flight: true`; the line `this session is being continued as <id>: say it again in a moment`, `in_flight`
171
- on the wire), or `:busy` (`SessionTransition::Busy`'s words) when the holder names none. So a say never lands
173
+ `PeerContinue`'s carry) refuses the say `:continued` naming its new link (the line `this session is being
174
+ continued as <id>: say it again in a moment`, `in_flight` on the wire, saved or not), any other holder names a
175
+ saved successor, or `:busy` (`SessionTransition::Busy`'s words) when there is none. So a say never lands
172
176
  in a mailbox the carry already read (N1). The pairing is read again inside the hold: a continue saves its new
173
177
  link, then copies the pairing in its `before_spawn` holding the link's lock, so a say meanwhile is busy, never a
174
178
  refusal that sends the peer to pair again. The feature probe before and the receipt wait after stay outside the
@@ -198,7 +202,8 @@ why a wake can't run: `:queued`, `:exit`, `:leaving`, `:before_turn` (nil: it ma
198
202
  - **Which folders:** every `<peer>/in`, whatever its `link.json` (the link gates the say only).
199
203
  - **Order:** by `at`, then peer name, then serial. One note each: id `peer-<name>-<box>-<serial>` (the box keeps
200
204
  a fork's seed notes from hiding its own third message), source `peer <Label>`, the `peer` hash (`PeerNote.payload`
201
- plus `box`), its text by `PeerNote.body` (a wake note up to the tool output cap, a plain one up to
205
+ plus `box`; its `verdict` is `PeerNote.verdict_of`, the one parser `…/peers` answer rows use too, and with a verdict
206
+ `said`, the summary without it, `PeerNote.said`, for the web's peer row), its text by `PeerNote.body` (a wake note up to the tool output cap, a plain one up to
202
207
  `PeerNote::HELD_CHARS`; over it, `PeerNote.message_text` points at `<peer>_read(serial: N)`).
203
208
  - **Wake:** the batch wakes when a message in it asked, `peer.turns` is above 0 (else `held: off`), the caller
204
209
  gave no `hold:`, the cache isn't cold (else `held: cold`, below) and `WorkerWakes#wake_hold(peer: !agreed)` is nil. The turn starts at the batch's last note;
@@ -299,8 +304,8 @@ starts empty).
299
304
  `Web::PeerRoutes` (all `:owner`, a participant gets 403):
300
305
 
301
306
  - `GET …/peers` → `{peers: [{name, label, paired_at, from, address, can_send, messages, exchanges, waiting}]}`: one
302
- row per mailbox folder (`PeerRoster`), and one per peer this session waits for, with `waiting: {until}` (a fresh
303
- wait only: `#waiting_rows`; the page's waiting chip, `peer_wait.js`), its newest 20 messages with their receipts and `words`
307
+ row per mailbox folder (`PeerRoster`), and one per peer this session waits for, with `waiting: {until}` and, when its mark
308
+ names one, `app` (a fresh wait only: `#waiting_rows`; the page's waiting chip, `peer_wait.js`), its newest 20 messages with their receipts and `words`
304
309
  (`PeerRoster.state_words`), and `exchanges` (`PeerExchanges.joined` over chi's sends and the messages as answer
305
310
  lines). No text.
306
311
  - `GET …/peers/NAME/messages/SERIAL` (the text and its receipt); `DELETE …/peers/NAME` (Unpair, and the waiting
@@ -205,9 +205,9 @@ continue, followed send and delete honour it.
205
205
  moment"). A stop is "being stopped" and an archive "being archived", said as a delete is: a non-continue holder
206
206
  (`other_than_continue?`) names no new link, and `in_flight` reads no continue under it, whatever intent a crashed
207
207
  continue left. `exclusive`'s own Busy, the seats' busy refusal (`deliver_turn`), the continue's `transition_busy`
208
- (its detail, which `--remote` reads back), `ContextSources.changing`, `Participants.invite`, the delete's refusal
209
- (`DeleteRefused.held`) and the delete preview take their words from it; a delete holding the lock makes the seats
210
- name no successor (`Hold.under`). The peer say/pair and the context push answer a status, `:busy`, whose words
208
+ (its detail, which `--remote` reads back), `ContextChange.under`, `Participants.invite`, the delete's refusal
209
+ (`DeleteRefused.held`), the delete preview and `SessionChain::Sharing` (below) take their words from it; a delete
210
+ holding the lock makes the seats name no successor (`Hold.under`). The peer say/pair and the context push answer a status, `:busy`, whose words
211
211
  are the plain ones. Those are `Busy#retry_message`, `#message` for every taker but a stop: a stop's Busy
212
212
  (`taker: :stop`) that met a transition says what to do instead ("session ab12cd34 is being deleted", "… being
213
213
  archived", "… being continued as <new id>: stop that one"). `DeleteRefused.held` and `ArchiveRefused.held` keep
@@ -218,10 +218,21 @@ continue, followed send and delete honour it.
218
218
  folder only for a session whose file is there: a deleted session's folder is never made again, nothing is held and
219
219
  the caller's own gone refusal follows; a lock file it made for a session gone by the block's end is taken back),
220
220
  around every arrival's check and write (the seats, below), a peer say's, a peer pair's and a context push's
221
- continued check and write (`SessionAccess::Local#moved_on`), a context add or remove (`ContextSources.changing`),
221
+ continued check and write (`SessionAccess::Local#moved_on`), a context add or remove (`ContextChange.under`),
222
222
  and an invite (`Participants.invite`). A caller that can't write the session folder
223
223
  (a peer's chi behind the mailbox door) holds an existing lock file read-only, and holds nothing when there is none
224
224
  (no transition holds a file that isn't there; one starting after it is not held off).
225
+ - `SessionChain::Sharing.under(id, state_dir:)` (`session_chain/sharing.rb`) is `shared` with the one answer for a
226
+ hold that failed: nil when the hold was taken (this thread's own exclusive hold too; an id that is no session id
227
+ fails closed, `Held` with Busy's plain words, as `shared` yields false), else, from one `Busy.held` read, a continue's new link in flight
228
+ (`Moved`, kind `:continue`: never under a delete, a stop or an archive, whatever a crashed continue left), else a
229
+ saved successor under any kind (`Moved` with the holder's kind; `Successor.of` without the anchor: one
230
+ `Session.list`, only on that refusal), else `Held` with the holder's kind. Both carry the holder's `Busy`
231
+ (`Held#refusal` is it; `Moved#refusal` is `SessionChain::Continued`); callers add their tail and decide whether to
232
+ name a non-continue `Moved`: the seats (`Hold.under`) and a context add or remove (`ContextChange.under`: "; try
233
+ again in a moment" for a new link in flight, ": change it there" for a saved one) name nobody under a delete, a
234
+ stop or an archive, on purpose, the peer say/pair, the context push and an invite (`Participants.invite`: ": invite
235
+ there", "in a moment" in flight) name the saved successor. Every site that takes the lock shared across a check and a write uses it.
225
236
  - `held?(id, state_dir:)` is a kernel probe (`in_flight`, `DeletePreview`, `holder`): it creates nothing and ignores the
226
237
  registry, so it answers the same inside this thread's own hold.
227
238
  - `forget(id, state_dir:)` takes back the lock file `exclusive` left for a session with no session file (one try
@@ -254,8 +265,9 @@ refused `:transition_busy` (`SessionTransition::Busy.held`'s words naming the ho
254
265
  web; a schedule's chain firing counts it a skip, `Schedules::SKIP_REASONS`); a `last:<id>` continue with tries left
255
266
  resolves again and waits again, so a second firing of the same chain follows the first one's new link. Any sender's turn
256
267
  that meets the hold is refused naming the successor from the intent (`follow_guard`, "Arrivals declare their hold"
257
- below: `SessionChain::Successor.in_flight`), else `transition_busy`; so are a peer say, a peer pair and a context push into the link's own source
258
- (`:continued` with `in_flight`), or `:busy` in `SessionTransition::Busy`'s words when the holder names none. Who
268
+ below: `SessionChain::Sharing`), else `transition_busy`; so are a peer say, a peer pair, a context push into the
269
+ link's own source (`:continued` with `in_flight`, its new link saved or not), a context add or remove and an invite,
270
+ or `:busy` in `SessionTransition::Busy`'s words when the holder names none. Who
259
271
  continues a link is one answer, `SessionChain::Successor.of(id, state_dir:, in_flight:)` (`via` `:next`, `:anchor`
260
272
  or `:in_flight`), and the refusal one wording, `SessionChain::Continued` ("session X was continued as Y", "is being
261
273
  continued as" in flight), each site adding only what to do next. The new link's worker starts inside the hold, in its own process: its boot writes into its
@@ -335,8 +347,9 @@ by `spec/session_lifecycle/allowed_spec.rb`. The hold is taken once, in the thre
335
347
  `Dispatch.deliver` (around the refusal check, the write and the wake), `Dispatch.wake` (around the wake) and
336
348
  `SessionManager.deliver_turn` (`follow_guard`, around all of the delivery: the resume, the Bridge's wait and post, the
337
349
  file and the second liveness check). Not in `resume_session` / `start_for_inbox`: a continue's undo reaches them on its
338
- own token. A seat met by a held lock refuses, nothing written: a continue naming its new link (`Successor.in_flight`,
339
- else a saved one) → `:continued` / 409 `link_continued` with `successor_id`; else `:busy` / 409 `transition_busy`
350
+ own token. A seat met by a held lock refuses, nothing written: a continue naming its new link, else a saved successor
351
+ (`SessionChain::Sharing`'s `Moved`, but never under a delete, a stop or an archive) → `:continued` / 409
352
+ `link_continued` with `successor_id`; else `:busy` / 409 `transition_busy`
340
353
  (`DeliverResult::BUSY`, `SessionTransition::Busy`'s words). chi send, an ask and the Exchange under them retry busy as
341
354
  they follow a continue (`Exchange#relocate busy:`: the same link again, within `CONTINUING_WAIT`); a same-mode schedule
342
355
  firing counts it a skip; the web composer, a delegate follow-up, a plugin's send and a participant's turn report it.
@@ -348,9 +361,9 @@ firing counts it a skip; the web composer, a delegate follow-up, a plugin's send
348
361
  | ring | `:none` | `ChildReports` rings once, no retry; `ChildMove` moves rings (`return_rings` gives them back); a continue's undo wakes for them on its own token. |
349
362
  | fresh_verdict | `:none` | `VerifyFresh.forward` writes once, no retry; the verdict is for the card in the parent it names, continued or not; it starts no worker. |
350
363
  | leave (respawn) | `:none` | After the worker's own release, spanning two processes (outside the lock); a refusal would drop a restart or queued input's start with no retry; a continue stops the worker first and the stop wins. |
351
- | context add / remove (`Local#context_add`/`#context_remove`, chi web's URL add and detach) | shared | `ContextSources.changing`: a continue copies the session's own sources. Refused `ContextSources::Held` (423 `context_busy`). |
352
- | context push, peer say, peer pair | shared | Phase 1 (`Local#moved_on`); the say's delivery seat holds again (shared beside shared). |
353
- | invite (`Participants.invite`) | shared | A continue archives the link and ends its grants; refused `Grants::Invalid` with Busy's words. |
364
+ | context add / remove (`Local#context_add`/`#context_remove`, chi web's URL add and detach) | shared | `ContextChange.under` (`SessionChain::Sharing`): a continue copies the session's own sources. Refused `ContextSources::Held` (423 `context_busy`), naming who continues the session as the seats do, else Busy's words. |
365
+ | context push, peer say, peer pair | shared | `SessionChain::Sharing.under` (`Local#moved_on`): `:continued` naming a continue's new link in flight, else a saved successor whatever the holder; else `:busy`. The say's delivery seat holds again (shared beside shared). |
366
+ | invite (`Participants.invite`) | shared | `SessionChain::Sharing.under`: a continue archives the link and ends its grants; refused `Grants::Invalid` naming who continues the session (any holder), else Busy's words. |
354
367
  | revoke, peer unpair | none | Removals: a continue ends every grant at the archive, and an unpair of a continued id ends the live link's pairing too (`Local#peer_unpair`); refusing them would only make the owner retry. |
355
368
  | `Local#answer` / `#dismiss`, cancel (cut), the attached TUI's `post_turn`, `Bridge#enqueue_turn` (the input fallback) | worker-side | Bridge-only: the live worker's own session (a continue's archive stops that worker and `archivable!` refuses it busy or queued). Over `--remote` the TUI's turn is chi web's turn route, `deliver_turn`'s seat. |
356
369
  | The new link's boot (`ChildMove.adopt`, `NoteMove.adoption`, its objectives notes) | worker-side, none | Runs inside its creator's exclusive hold of the new link: a hold there would be refused until the continue ends. |
@@ -398,7 +411,8 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
398
411
  5. A new arrival (a `WakePolicy` row, a delivery outside the seats) declares its hold: `hold: :shared` (the seat
399
412
  takes it) or `hold: :none` with its reason; a raw `SessionInbox.write_*` site is listed with its hold in
400
413
  `spec/session_lifecycle_writers_spec.rb`; one outside the inbox that changes what a transition carries takes
401
- `SessionTransition.shared` around its check and write (see "Arrivals declare their hold").
414
+ `SessionChain::Sharing.under` around its check and write (see "Arrivals declare their hold"), which answers who
415
+ continues the session when a transition holds it.
402
416
  6. If the fact changes a state, update `SessionLifecycle::STATES`/`Reading.derive` and `CANONICAL`, then the
403
417
  `ALLOWED` cells (the literal ones by hand; the delivery ones follow `WakePolicy::ROWS`) and the matrix's rows; a
404
418
  decider that answers otherwise is a `KNOWN_DIFFERENCES` entry with its reason, never a silent cell change.
@@ -14,7 +14,7 @@ by `npm run e2e` (`spec/e2e/`). `app.js` has no unit spec of its own; `viewer_bo
14
14
  **Every module has a size cap, `app.js` its own**: `npm run lint` fails past `max-lines` in `eslint.config.js`
15
15
  (counted as `wc -l` counts, comments and blank lines too). Every `public/*.js` module: 1200 (`samagotchi/module-size`,
16
16
  about 10% over the largest, `turn_block.js`), so a module near it splits rather than becoming the next `app.js`.
17
- `app.js` (`samagotchi/app-size`): 1547, its size once the composer's writes went into `drafts.js` and continue →'s draft guess went; down from 1577, its size once the views by hash went into `views.js` and the pages' wiring landed; itself down from 1637, its size once the diagrams' wiring went into `diagram_wiring.js`, itself down from 1638,
17
+ `app.js` (`samagotchi/app-size`): 1540, its size once the composer-drafts shims for an older cached `session_actions.js` went; down from 1547, its size once the composer's writes went into `drafts.js` and continue →'s draft guess went; down from 1577, its size once the views by hash went into `views.js` and the pages' wiring landed; itself down from 1637, its size once the diagrams' wiring went into `diagram_wiring.js`, itself down from 1638,
18
18
  its size once the lightbox went into `picture_viewer.js`, itself down from 1649, its
19
19
  size plus 50 once the session-open flow went into `session_sync.js` and `session_view.js`, itself ratcheted down from 2000, itself down from 2250 when the versions, the owner's claim links and
20
20
  Verify, the composer's mode and the strip's hide went into modules of their own. A new feature goes into a module of
@@ -42,7 +42,7 @@ answers and notes: The notes rows and the run line, below; it imports only names
42
42
  and `quiet_notes.js` exported, and `quiet_notes.js installQuietNotes` stays for an older cached `app.js`), `details_motion.js`,
43
43
  `turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
44
44
  `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
45
- the session waits for, its popover and Cancel: The peer exchange), `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_keys.js` (their storage keys, so `session_prefs.js` sweeps them without a new export), `served_ref.js`
45
+ 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`
46
46
  (`isServedRef`, which the stream's `generation_completed` reads, beside a `modelServed` already set, for a served
47
47
  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).
48
48
 
@@ -946,7 +946,8 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
946
946
  the chips' own load (a session opened) calls `peers.refresh({ reuse: true })`. A pairing made from the peer's side
947
947
  sends the page nothing: the chip appears at the next read (a focus, a peer note, a send).
948
948
  - `peer_wait.js` (pure): `waitingChipModel` ("Claude · waiting 8 min", state `awaiting`, apart from a send's
949
- `waiting`), `waitingPopoverTemplate` (the wait, the minutes left, Cancel: `context_chips.js cancelWait`, the
949
+ `waiting`; the app it names is the row's `app`, the wait mark's, else `APPS`, the fallback for an older worker's
950
+ wait, gone in the release after next, else the label), `waitingPopoverTemplate` (the wait, the minutes left, Cancel: `context_chips.js cancelWait`, the
950
951
  Unpair route with no confirm), `waitMinutesLeft`. `peer_chip.js peerGroups` admits a row with `paired_at` or
951
952
  `waiting`; a waited-for one is drawn by these.
952
953
  - `peer_mailbox_api.js` (state): `getPeerMessage(id, name, serial)` (a message's text: View latest answer, a
@@ -968,8 +969,10 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
968
969
  in `#history`, short too, starts closed as one row before its bubble, `<name> <verdict> <summary> N lines` in a plain
969
970
  panel box with no chevron (`.answer-fold.peer`; the verdict in the text colour whatever it says). `peer_row.js`
970
971
  (pure) gives the words: the verdict as `verdictWord`'s lower-case word, none without one; the summary the peer sent
971
- without the verdict mark it wrote into it (`summaryWithoutVerdict`: the last `VERDICT X` when X is the server's
972
- verdict, the punctuation it leaves tidied), else (`.note-text` marked `data-fallback` by `peer_note.js`) the first
972
+ without the verdict mark it wrote into it: the server's (`PeerNote.said`, the payload's `said`, on the bubble as
973
+ `data-peer-said`), else, for a note saved before `said` or an older worker's, `summaryWithoutVerdict` (its port's
974
+ twin: the last `VERDICT X` when X is the server's verdict, the punctuation it leaves tidied; both run
975
+ `spec/fixtures/peer_said_cases.json`; it goes two releases on), else (`.note-text` marked `data-fallback` by `peer_note.js`) the first
973
976
  line of the peer's text; N the lines of the peer's own text (`.peer-text`'s `data-peer-md`), never the bubble's copy
974
977
  text, and no length without a body. A tap opens the bubble under the same line (the box's top edge; the bubble's
975
978
  `.under-row` class drops its own head, verdict and summary, which the row says, keeping the ↑ to the send), a
@@ -1005,7 +1008,7 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
1005
1008
  `refs.js showRow` on the last row of that id before the answer (its `ref:reveal` opens a folded step or the stage's
1006
1009
  cloud); focus moves to the target (`tabindex="-1"`). "Read the full answer" calls `context_chips.js
1007
1010
  showMessage(name, serial)` for a mailbox message (its peer chip's popover on that message's text) or
1008
- `showText(source)` for an older answer (that source's own chip), in a task of its own (the click's way to the
1011
+ `showText(source)` for an older answer (that source's own chip, or its group's chip on it), in a task of its own (the click's way to the
1009
1012
  document would close it).
1010
1013
  - `peer_chip.js` (pure): a paired peer in the session bar. `peerGroups(peers)` gives one group per peer of the
1011
1014
  model that is paired (`paired_at`; an unpaired one keeps its messages but has no chip): `{key: "peer:<name>", name,
@@ -1018,14 +1021,53 @@ mailbox message, and `inline` when the note's content holds the peer's text). Th
1018
1021
  is its popover (scene 2 of the design): where chi sends (the address), how it answers, the last 8 exchanges (sends,
1019
1022
  and messages no send claims as `#N · summary`) with `exchangeState`'s words and the answer's receipt words, View
1020
1023
  latest answer, Status card (`peerStatusCommand`: `/<name>` when the session lists it) and Unpair.
1021
- `context_chips.js` draws it: its chips are keyed (`data-name`: a source's name, a peer's `peer:<name>`), peer chips
1022
- first; context rows are never grouped (a `claude-outbox` source is an ordinary chip); an open popover stays while its
1024
+ `context_chips.js` draws it: its chips are keyed (`data-name`: a source's name, a group's `group:<provider>`, a
1025
+ peer's `peer:<name>`), peer chips first. The controller asks its **chip kinds** and never branches on peer or source:
1026
+ a kind gives its chips (the strip is the kinds' chips joined end to end: peer, source, then plugin), `owns(key)`, its
1027
+ `popover(key, {text, now, member})`, `label(key, {member})` (the popover's `aria-label`), `shape` (`{width, sheet,
1028
+ className}`: 440, a bottom sheet under `SHEET_MAX` and `peer-pop` for a peer; 380 for a source), `readText(key,
1029
+ {serial, box, member})` (what "view text" reads and a failure toast's name), `onLoad` (a session's open: the peers
1030
+ read with `reuse`), `ticks` (whether the minute's tick redraws: the source kind while it has rows, the peer kind
1031
+ while it has chips, so a waiting peer counts down with no source) and `keyFor` (the key `showText`/`showMessage`
1032
+ open), and may give `hasMember(key, name)` and `standsFor(key)` (below); a model that changed calls the
1033
+ controller's `changed(kind)` (`peersChanged`). The source kind is in `context_chips.js` (unexported); the peer kind
1034
+ is `peer_chip_kind.js` (`createPeerChipKind`, a wrapper over `peer_chip.js` and `peer_wait.js`, with `peerOf(key)`
1035
+ for Unpair, Cancel and Status card). **The source kind's groups** (`context_groups.js`, inside the source kind, so a
1036
+ group sits at its first source's place among the lone ones; kinds are only joined end to end): two or more unmuted
1037
+ rows of one `provider` whose bundle has a label (the row's `group`, its manifest's `context_group:`) are one chip,
1038
+ `groupChipModel` ("PRs 3 · 2m": the count in `.ctx-count`, the newest fetch's age, the worst state, the dot when any
1039
+ is unread); a lone source, or one with no bundle or label, keeps its chip. The controller holds the open
1040
+ **member** (`openMember`, null: the group's list, `groupListTemplate`): a row (`data-act="member"`) shows that
1041
+ source's `popoverTemplate` with `back` (`data-act="back"`), focus on back or on the member's row again; view text
1042
+ and detach act on the member (`rowAt(key, member)`); `follow` puts a member that left back on the list, and a group
1043
+ that fell under two closes as any chip that went. `standsFor` maps a key no longer drawn to the chip that stands for
1044
+ it (a lone source that joined a group: the group; a group down to one: that source), so the focus follows it on a
1045
+ redraw and on close. A popover click that redraws its own target (`ownClick`, as `chip_popover.js` has it) isn't a
1046
+ click outside. The group has no action of its own. The actions stay in the controller; a source is grouped only by
1047
+ its bundle's label (a `claude-outbox` source is an ordinary chip); an open popover stays while its
1023
1048
  key is among the drawn chips; View latest answer reads the newest message (`api.message`), Unpair confirms once,
1024
1049
  `DELETE`s the pairing and reads the peers again (the chip goes; a failure names itself in a toast); after a detach
1025
1050
  or Unpair that took the focused chip, focus goes to the strip's first chip, else the composer (`focusAway`); an
1026
1051
  exchange row is a button only when its send's row is drawn (`peerLinks.hasSend`) and jumps there
1027
1052
  (`peerLinks.showSend`) after closing the popover. Under 600 px the peer popover is a bottom sheet (`sheetPlace`);
1028
1053
  ordinary chips' popovers stay at their chip.
1054
+ - **The plugin chips** (a bundle's own, `ctx.chips`): the third kind, after the peer and source kinds,
1055
+ `plugin_chip_kind.js` (`createPluginChipKind`) over the pure `plugin_chip.js` (`pluginChipModel`,
1056
+ `pluginPopoverTemplate`, `pluginChipOpens`). Every kind gets the `GET …/context` read through `onRead(data)`
1057
+ (the source kind keeps `data.sources`, the plugin kind `data.chips`; an older chi web's answer has none) and
1058
+ `reset()` on a session's open or close and a failed read: the controller holds no rows of its own. A chip is keyed
1059
+ `chip:<bundle>/<name>`, drawn with core's `ok`/`warn`/`error` class (`.ctx-chip.warn`, kept when open) and the
1060
+ dot; with an `at` its label ends ` · 3m` and the kind `ticks`. A chip with no `body_html` and no actions has
1061
+ `opens: false`: `chipsTemplate` gives it no `aria-haspopup`, and a tap only closes another popover. Its card is
1062
+ the name, the bundle, the server's `body_html` (`unsafeHTML`, as `card.js` does a card's; the first paragraph in the
1063
+ text colour, the rest muted) and the actions through `card_actions.js` (`cardActions`, `cardActionUrl`; own class
1064
+ names `.ctx-plugin-*`, never `.card-action`). A kind may take its own `data-act`s (`act(name, target, {close})`,
1065
+ asked before the controller's): a command button (`plugin-command`) closes the card and calls `api.command(id,
1066
+ line)`, app.js's `sendCommand(id, line, {clientId, card: true})` then `followWokenWorker`, as `cards_place.js
1067
+ onCardAction` sends a card's (so the reply shows as a bubble, the line isn't echoed as typed, and no cache-confirm
1068
+ asks); a failure is a toast. The stream's `chips_updated` calls `contextChips.refresh()`: one `GET …/context` per
1069
+ change per open tab, and an open card follows its chip in place. A lost event (a stream `reset`) leaves the strip
1070
+ as it was until the next event or the window's focus.
1029
1071
 
1030
1072
  ## The drafts
1031
1073
 
@@ -1049,9 +1091,7 @@ one painted (`setChips(list, {revoke: false})`, `fit()`, the ↑/↓ browsing re
1049
1091
  (the grip's draft class and the fit see the new text), so `select` and `clearSelection` (+ new) both swap; app.js
1050
1092
  calls it once at boot, before `selectFromHash()`, which always paints (over a value the browser may have restored) and
1051
1093
  covers a page opened at `/` (the Home Screen app's start URL), where nothing selects. A chip's preview URL is freed on
1052
- its ×, at its send (`chipsAfterSend`) or when its draft is dropped, never on a swap. An older cached `session_view.js`
1053
- calls no `show`: the drafts see the shown key differ from the painted one and take the box as that window's draft
1054
- (today's one box), painting a kept draft only over an empty box.
1094
+ its ×, at its send (`chipsAfterSend`) or when its draft is dropped, never on a swap.
1055
1095
 
1056
1096
  **Saved in this browser**: the text, on every write and every input event (`syncFromView`, the box's input listener;
1057
1097
  no save on leave, nor on `pagehide`: `store.selected` is already the next id by `forgetSession`, and iOS gives no
@@ -1079,8 +1119,19 @@ which session is open, `handOverDraft(id, next, created)` = `drafts.handOver(A,
1079
1119
  with text or chips moves whole to the new link (A's saved copy gone), an empty one leaves the link the opener. On
1080
1120
  another session at the answer: the toast's Open, that session's draft untouched; still on A (or back on it): `await
1081
1121
  select(next)`, then `revealDraft()` (the composer opens, the box takes the focus, the caret at the end). There is no
1082
- Restore draft and no guess of where a draft came from (the old `draftFrom`/`noteDraft` and `chains.js openerFill`'s
1083
- rule). A 409 `continued` hands the draft to the link that continues it only into an empty draft of its own, no opener.
1122
+ Restore draft or guess of where a draft came from (the old source and opener-fill rule, gone).
1123
+ A 409 `continued` hands the draft to the link that continues it only into an empty draft of its own, no opener.
1124
+ A continue made elsewhere (a terminal `/continue`, a chain schedule, `chi send --new --continues`, another tab; a send
1125
+ has no `continued` path) hands the draft over the same way, without an opener: app.js `followContinuedDrafts` at the
1126
+ end of the hub's `snapshot` and `session` handlers and at a leave (`session_view.js forgetSession`, after the swap),
1127
+ `draft_follow.js continuedDrafts` naming each continued session with a draft and its chain's newest listed link; never
1128
+ the session on view (its box is not emptied under the user) nor one this tab's Continue → is taking (`continuing`).
1129
+ It hands over through `drafts.follow`, which first reads the session's text from storage again when this tab hasn't
1130
+ changed it since it last read it (a background tab holds the text as it was when it saw it; another tab may have typed
1131
+ on, or moved it already: storage empty, nothing moves). Several tabs may each run it: the first moves the stored text,
1132
+ the others find nothing stored, or the next link's draft, and stop. Images live only in the tab that added them: a
1133
+ hand-over into a link that already holds the session's very text (another tab moved it first, also before this tab's
1134
+ own Continue → lands) moves this tab's images there too and empties the session's draft (`drafts.handOver`).
1084
1135
  Chips moved from A go up again to A' at its send (`images.js uploadChips`, by `chip.session`).
1085
1136
 
1086
1137
  **Swept** with the view settings (`COMPOSER_DRAFT` is in `PREF_KEYS`): only an unscoped list, ids missing from it,
@@ -1098,20 +1149,6 @@ The sweep now deletes draft **text**, not only view settings: another chi web on
1098
1149
  port with another state dir, a smoke run on 4567) lists other sessions, and its page's first load sweeps this
1099
1150
  browser's drafts of the sessions it doesn't know.
1100
1151
 
1101
- **A mixed cache**: `send_turn.js` and `composer.js` take an older app.js's bag (`el`, `chips()`, `setChips(list)`,
1102
- `clear()`: the one box) as well as this one's, and app.js still passes those members for an older cached
1103
- `send_turn.js` (`drafts_mixed_cache.test.js` loads 0.191.0's from `spec/web/public/fixtures/v0.191.0/`); its `select`
1104
- dep moves the start page's draft to a created session too (an older `send_turn.js` doesn't). The mount's `onWrite`, a
1105
- no-argument `afterPick` and send_turn's `noteDraft` are an older module's way to say it wrote the box itself: app.js
1106
- wires them to `syncFromView`. Beside an older app.js, this mount gets no `setText` (↑/↓ recall nothing until a reload),
1107
- this command list's `afterPick` writes nothing (a Tab pick does nothing), and `unqueue.js` gets no `putBackTo` (today's
1108
- toasts). An older cached `composer_mount.js` ignores `{revoke: false}`: a swap frees the chips' previews (broken
1109
- thumbnails until a reload; the upload still works). An older `session_prefs.js` doesn't sweep the drafts until a
1110
- reload. app.js still passes `fillOpener` (a shim: the hand-over and the reveal, returning no displaced draft) and a
1111
- no-op `restoreDraft` for an older cached `session_actions.js`, which calls `fillOpener` after its select (without it
1112
- its continue would toast "Can't continue" though it succeeded); `chains.js openerFill` and `restoredComposer` stay
1113
- exported, unused, until after the next release.
1114
-
1115
1152
  ## Stale answers
1116
1153
 
1117
1154
  The page switches sessions, reopens a popover or asks again while a fetch is out. An answer for the old ask must be
data/docs/memory.md CHANGED
@@ -446,7 +446,9 @@ chi ships one skill itself: `skill_pages` in the system bundle
446
446
  page ([docs/pages.md](pages.md#asking-chi-for-a-page)). Its index line is in
447
447
  every prompt; its text is read only when a page is asked for. It tells chi not
448
448
  to edit it (a shipped file: a local edit would have to be merged at the next
449
- upgrade) but to say what differed.
449
+ upgrade) but to say what differed. The opt-in reflect bundle ships a second,
450
+ `skill_reflect`: a nightly reflect session's steps, which suggest changes and
451
+ never apply them ([docs/bundles.md](bundles.md#a-nightly-reflect-session)).
450
452
 
451
453
  ## Toolkit memories
452
454
 
@@ -666,7 +668,7 @@ profiles, meta bundles that install a set of them:
666
668
  | profile | bundles |
667
669
  |---|---|
668
670
  | `core` | loop-guard, check-in, guardrails, slow-commands, agents-md, cost-cap, work-cap: the recommended safety set |
669
- | `dev` | known-names, mcp, btw, skills, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes |
671
+ | `dev` | known-names, mcp, btw, skills, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes, decision-card, inline-widgets, knowledge |
670
672
 
671
673
  `chi bootstrap` installs `core` and, on a terminal, offers `dev`. An existing
672
674
  install gets neither by itself: `chi bundle install core` (or `dev`).
data/docs/pages.md CHANGED
@@ -99,7 +99,68 @@ it. On an older chi `runtime` is a `NameError`, and the run fails with it (the l
99
99
  remove it before changing schedules`). The read takes no lock and writes nothing, though chi's debug log may get a
100
100
  line for an entry that doesn't read.
101
101
 
102
- `runtime`, like the rest of the page script DSL, is stable for bundles ([plugins.md](plugins.md#stable-for-bundles)).
102
+ The next four are **experimental** (from the chi after 0.194.0): their members may change while the first page that
103
+ uses them (the reflect bundle's) settles.
104
+
105
+ - **`runtime.sessions(project: nil)`**: one project's sessions over the last 14 days, as counts (a
106
+ `SessionStats::Listing`). Read-only and local: it reads the session files, `analytics.json` and `cards.json`, takes
107
+ no lock and starts no worker.
108
+ - **Which project.** `project:` is a folder: its project is read (a worktree gives its repository, a
109
+ `chi project init` folder its marked folder), even with no session in the window (then `session_count` 0 and no
110
+ sessions). nil, or a folder in no project: the project of the newest session **you started** (not a delegate,
111
+ and started by no agent, schedule or participant; a web tab's, a TUI's, `chi send`'s and a continued link's
112
+ count as yours), else the newest session's. `runtime.sessions(project: runtime.launch_dir)` reads the project
113
+ `chi page run` was typed in.
114
+ - **The listing.** `project` (`name`, `path` with `~` for your home, `session_count`; nil only when no project is
115
+ picked: no `project:` folder in a project and no session in the window), `picked_by` (`"folder"` or `"newest"`),
116
+ `projects` (every other project in the window, most sessions first), `sessions` (newest updated first), `since` (the
117
+ window's start, ISO 8601 UTC), `sessions_capped` (true when more than 500 of the project's sessions matched: the cap
118
+ counts after the project filter, and is lower when `session.max_count` is), `unreadable` (files that didn't read;
119
+ their counts are 0). The 14 days are capped by `session.retention_days`. `test_run` and `scratch` sessions are left
120
+ out; archived ones and delegates count.
121
+ - **A session** (`SessionCounts`): `id`, `created_at`, `updated_at`, `model_name`, `delegate`, `chain_link`,
122
+ `turns`, `tool_calls_by_tool` and `tool_errors_by_tool` (tool → n), `blocked` (every guardrail deny: a rule, a
123
+ hook, you or a parent declining, a tool not in the toolkit), `auto_allowed` (System 1's), `mid_turn_lines` (your
124
+ own lines into a running turn), `steers_by_source` (plugins' steers), `approvals_by_rule` (rule →
125
+ `{"asked", "once", "wide", "denied", "unanswered", "by_parent"}`; a question with no rule under `(no rule)`),
126
+ `cards_at_cap` and `hook_notices_by_bundle` / `notices_at_cap` (see "at least" below), `context_window`,
127
+ `side_cost` (recaps, `/btw`, `ask_model`: a session total, not windowed) and `schedule_id` (the schedule whose
128
+ chain link it is, else nil).
129
+ - **A turn** (`TurnCounts`): `id`, `started_at`, `status` (`completed`, `failed`, `canceled`), `cancel` (`you`: your
130
+ Stop or Ctrl-C, a participant's cancel included; `hook`; `interrupted`: the worker went mid-turn, never a
131
+ cancel; `other`; nil when not cancelled), `cancel_bundle` (the hook's bundle), `automatic` (started by no
132
+ person: a schedule, a delegate report, a reminder), `model` (for a failed turn, its model ref without the host),
133
+ `cost` (reported plus estimated), `tool_calls`, `tool_errors`, `tool_calls_by_tool`, `tool_errors_by_tool`,
134
+ `failure_kind` (one of `host_model_not_found`, `host_rejected`, `host_error`, `timeout`, `host_unreachable`,
135
+ `context_overflow`, `empty_answer`, `other`, `none`; nil unless failed) and `context_used_tokens`.
136
+ - **The window.** Turns count by when they started; tool records, approvals and notices by their turn; your lines
137
+ and steers by their own time; a question with no turn id by when it was asked. Anything with neither is left out.
138
+ - **No text.** Counts, ids, times, model names, the project's name and path, and the names the Hashes are keyed by
139
+ (tools, rules, bundles, steer sources): never a message, a title, a tool's output or command, or a failure's
140
+ words (only its kind).
141
+ - **"At least".** `cards.json` keeps the last 20 questions and cards, and the last 20 notices: `cards_at_cap` /
142
+ `notices_at_cap` say a session's approvals / hook notices may be more. An approval a participant's turn asked
143
+ counts with yours.
144
+ - A running turn reads as its last save: missing, or `interrupted` after a checkpoint.
145
+ - **`runtime.turn_excerpts(turns, include_text: false)`**: for each `[session_id, turn_id]` (worst first, as
146
+ `runtime.sessions` gives them), the turn's failing tool calls with their error results: **text from your
147
+ sessions**, which reaches whatever reads the page. A `TurnExcerpts::Result`: `excerpts`, `left_out` (calls the cap
148
+ dropped), `unpaired`, `unreadable`. An excerpt has `session_id`, `turn_id`, `started_at`, `status`, `failure` (a
149
+ failed turn's line), `calls` (at most 8: `tool`, `target` for a `call_tool`'s `<server>/<tool>`, `status` `error`
150
+ or `blocked`, `args` cut at 200 characters, `result` cut at 300), `paired`, and `prompt` / `answer` (the turn's
151
+ opening message and last answer, cut at 300; nil unless `include_text: true`; a participant's turn has neither, and no `calls`). Every field has key shapes
152
+ redacted and your home as `~`, and all of them together stay within about 4k tokens (14,000 characters), filled
153
+ in the order given. A turn whose calls can't be matched to its messages exactly (a continue turn, a raw-prompt
154
+ batch) is `paired: false`: its calls with tool and status only, never a guess.
155
+ - **`runtime.launch_dir`**: the folder `chi page run` was typed in, an absolute path; nil when chi web's Refresh ran
156
+ the page, or when the folder is gone. The run itself still happens in the pages folder
157
+ ([Where a run happens](#where-a-run-happens)).
158
+ - **`runtime.settings`**: a bundle page's own settings: the keys its manifest lists in `settings:`, from config.yml
159
+ `bundles: <bundle>:`, as written (the page checks their types). `{}` for your own page, for a bundle with no
160
+ `settings:`, and when config.yml has none.
161
+
162
+ `runtime`, like the rest of the page script DSL, is stable for bundles (except the experimental ones above;
163
+ [plugins.md](plugins.md#stable-for-bundles)).
103
164
 
104
165
  ## Pages from a bundle
105
166
 
@@ -126,6 +187,14 @@ A bundle can ship pages: its manifest's `pages:` names scripts in its `scripts/`
126
187
 
127
188
  - `chi page run NAME` runs the script in a Ruby process of its own and prints a summary of each block: a text's first
128
189
  lines, a table's labels, first rows and total, a walk's step count. `--format json` prints the stored page.
190
+ `--format lines` prints the stored page in full, uncut: the name and title, `ran_at:` (and `error:` after a failed
191
+ run, which exits 1 as json does, followed by the last lines of the script's stderr, indented), then `== block N:
192
+ TYPE` before each block, a text's lines as they are, a table's labels and one row a line (cells formatted as in the
193
+ summary, `|` between, a newline in a cell as a space) and its total, a walk's title and one step a line. In a cell a
194
+ `\` prints as `\\` and a `|` as `\|` (`grep x | head` is `grep x \| head`), so a cell never reads as two; a block's
195
+ line that starts with `== block ` gets a `\` before it, so no block forges another's header. It is the form a model
196
+ reads in parts: one JSON line is cut at a tool result's limit, while `execute` saves long output whole and names the
197
+ file to `read` by `start_line`.
129
198
  - A run that fails (the script raised, has a syntax error, called `exit`, broke a limit, or printed more than 256 KB of
130
199
  blocks) prints `error: line 9: undefined method 'fetch' for nil`, the last lines of what the script wrote to stderr,
131
200
  and exits 1. **The result of the last good run is kept**: a bad edit never blanks the page.
@@ -184,6 +253,8 @@ that breaks the rule). See [the CLI](cli.md#commands).
184
253
  - **The working folder is the pages folder.** A chi command a script runs sees that folder's project: if
185
254
  `~/.config` sits in a git repository, that repository. Pass `--scope=all` to the session commands
186
255
  (`chi sessions list --scope=all --format json`) for every project.
256
+ The folder `chi page run` was typed in reaches the script only as `runtime.launch_dir` (`CHI_PAGE_LAUNCH_DIR`;
257
+ never set from a Refresh, nor inherited).
187
258
  - **The environment is yours**, as a session's worker gets it: the XDG folders absolute, chi's own session markers and
188
259
  guardrails settings left out, and `PWD` the pages folder; chi web's Refresh runs chi web's own chi. `CHI_REMOTE`, a worker's `SAMAGOTCHI_WORKER_*` keys and
189
260
  the agent markers (`CLAUDECODE`, `CODEX_THREAD_ID`, `AI_AGENT`) are left out too: a run is always on this machine,
data/docs/peers.md CHANGED
@@ -64,7 +64,7 @@ shown).
64
64
  - **Review it in Codex.** Codex asks you to review a new or changed hook the next time it starts ("Hooks need
65
65
  review": choose Review hooks, or `/hooks` later, and trust it); until then it skips the hook, silently. chi never
66
66
  writes Codex's trust and never passes a trust-bypass flag. A Codex started by `/codex start` stops on that screen
67
- in its background tab the first time: its opened line says so; Show the tab and answer it.
67
+ in its kitty window the first time: its opened line says so; Show the window and answer it.
68
68
  - A line pointing at a chi that is gone (a moved chi home) shows on the status card; adding it again changes the hook,
69
69
  so Codex asks for the review again.
70
70
  - Codex runs an interactive session's hooks in its app-server daemon, with the env of the Codex that started the
@@ -72,21 +72,32 @@ shown).
72
72
  nothing shows). The card reads only `$CODEX_HOME/hooks.json`: an announce line you put in `config.toml`'s `[hooks]`
73
73
  or a project's `.codex/hooks.json` isn't seen (the card offers to add it).
74
74
 
75
- **Start one in kitty: `/claude start`.** chi makes the session wait, then opens a background kitty tab titled
76
- `claude · chi <id8>` in the session's folder, running `claude` through your login shell (the setting
77
- `bundles: claude-peer: start_command:` replaces it, a shell line, so you can add flags; read when the session's worker
78
- starts, as every bundle setting is, so restart the session after changing it); the Claude there pairs on its
79
- own when it starts, through the start hook. The tab opens in the kitty whose window has the focus, else the one
80
- started last, and never takes the focus. `/claude` then says **Paired · started by chi** with the tab's title and
81
- **Show** (`/claude show`, which brings the tab to the front); once the tab is closed it says so, with **Start one in
82
- kitty**. It needs kitty with remote control (`kitty.listen_on`, [configuration.md](configuration.md#desktop-helper-agents-in-kitty-and-tmux)):
75
+ **Start one in kitty: `/claude start`.** chi makes the session wait, then opens a kitty window in the session's
76
+ folder, running `claude` through your login shell (the setting `bundles: claude-peer: start_command:` replaces it, a
77
+ shell line, so you can add flags; read when the session's worker starts, as every bundle setting is, so restart the
78
+ session after changing it); the Claude there pairs on its own when it starts, through the start hook. Where it opens:
79
+
80
+ - **A pane next to this chi** (the default): when this session's chi terminal runs in kitty, Claude opens in that
81
+ terminal's tab, beside it, whichever tab you are in now: a split in kitty's `splits` layout, the layout's next slot
82
+ in the others (in `fat`, kitty's default, a strip under chi). The start line says "opened a pane next to this chi".
83
+ The same from chi web or the phone, while the session's terminal is attached.
84
+ - **A background tab** titled `claude · chi <id8>` otherwise, and the start line says why: no chi terminal of this
85
+ session in kitty (a start from chi web with no terminal attached, a chi terminal in another app or inside tmux), its
86
+ tab in the `stack` layout (the pane would hide behind chi), or kitty refusing the pane. The tab opens in the kitty
87
+ whose window has the focus, else the one started last. `bundles: claude-peer: open_in: tab` always opens the tab
88
+ (`open_in: pane` is the default; another value is taken as `pane`, and the start line says so).
89
+
90
+ Neither takes the focus. With two chi terminals of the session in kitty, the one in the focused tab wins. `/claude`
91
+ then says **Paired · started by chi** with chi's label for it, `claude · chi <id8>` (a pane carries no title of
92
+ chi's; only the tab is titled so), and **Show** (`/claude show`, which brings the window to
93
+ the front); once the window is closed it says so, with **Start one in kitty**. It needs kitty with remote control (`kitty.listen_on`, [configuration.md](configuration.md#desktop-helper-agents-in-kitty-and-tmux)):
83
94
  without it, "kitty isn't running or `kitty.listen_on` isn't set", and nothing waits. It refuses on a session already
84
95
  paired, and without the start hook ("install the start hook first"). From the phone it works the same while kitty runs
85
96
  on the working machine. `/codex start` opens Codex the same way (`bundles: codex-peer: start_command:`, default
86
- `codex`) with the first prompt "pair with chi", which runs the skill's pair and so spends one Codex turn; it needs no
87
- hook (with Codex's start hook, the hook pairs at that first message and the skill's pair says paired). Start, Show and pasting into a tab run only from your typing or tap: no tool call, `chi send`, agent, participant,
88
- schedule or delegate reaches them. A second Start while the first tab is still starting is refused, two at the same
89
- moment included (they take turns). A tab that closes at once (its command isn't found in the login shell's PATH: it
97
+ `codex`, and `open_in`) with the first prompt "pair with chi", which runs the skill's pair and so spends one Codex turn; it needs no
98
+ hook (with Codex's start hook, the hook pairs at that first message and the skill's pair says paired). Start, Show and pasting into a window run only from your typing or tap: no tool call, `chi send`, agent, participant,
99
+ schedule or delegate reaches them. A second Start while the first window is still starting is refused, two at the same
100
+ moment included (they take turns). A window that closes at once (its command isn't found in the login shell's PATH: it
90
101
  runs as `$SHELL -l -c "exec <start_command>"`) is said so, and leaves no wait; after its Claude ended, the status card's
91
102
  title reads `claude-peer: ended` and the chip `Claude · ended`.
92
103
 
@@ -137,7 +148,7 @@ lost: it is a note, and the user's next message lets chi read it. The skills say
137
148
  A say is refused, with nothing written, for: no such session; a session being deleted; a continued one whose live
138
149
  link isn't paired (a chain an older chi continued: `this session was continued as <id>: say it there`, naming that
139
150
  link); one being continued right now (`this session is being continued as
140
- <id>: say it again in a moment`: its new link is not saved yet); one busy with another change (`this session is busy
151
+ <id>: say it again in a moment`: its new link saved or not); one busy with another change (`this session is busy
141
152
  with another change; try again in a moment`); not paired (`not paired: run the pair script`); an older worker
142
153
  (`restart the session`); 200 messages chi hasn't read yet.
143
154