samagotchi 0.173.0 → 0.174.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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/docs/architecture.md +2 -2
  4. data/docs/cli.md +9 -2
  5. data/docs/internals/background-tasks.md +0 -3
  6. data/docs/internals/participants.md +3 -1
  7. data/docs/internals/remote-sessions.md +8 -0
  8. data/docs/internals/web-frontend.md +24 -3
  9. data/docs/plugins.md +1 -3
  10. data/docs/scheduling.md +9 -3
  11. data/docs/sessions.md +3 -1
  12. data/docs/testing.md +6 -0
  13. data/lib/samagotchi/bridge.rb +1 -1
  14. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  15. data/lib/samagotchi/child_move.rb +11 -4
  16. data/lib/samagotchi/continued_from.rb +51 -0
  17. data/lib/samagotchi/engine.rb +1 -1
  18. data/lib/samagotchi/note_move.rb +11 -4
  19. data/lib/samagotchi/schedules.rb +13 -16
  20. data/lib/samagotchi/session_access/contract.rb +1 -0
  21. data/lib/samagotchi/session_access/local.rb +9 -1
  22. data/lib/samagotchi/session_access/remote.rb +26 -3
  23. data/lib/samagotchi/session_chain/delete.rb +405 -0
  24. data/lib/samagotchi/session_chain/delete_preview.rb +96 -0
  25. data/lib/samagotchi/session_chain/links.rb +38 -0
  26. data/lib/samagotchi/session_command_catalog.rb +2 -2
  27. data/lib/samagotchi/session_commands.rb +3 -13
  28. data/lib/samagotchi/session_continue.rb +51 -13
  29. data/lib/samagotchi/session_delete_command.rb +82 -17
  30. data/lib/samagotchi/session_manager/removal.rb +137 -31
  31. data/lib/samagotchi/session_stores.rb +2 -0
  32. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +2 -2
  33. data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
  34. data/lib/samagotchi/terminal_ui/exit_lines.rb +16 -0
  35. data/lib/samagotchi/terminal_ui/local_link.rb +7 -1
  36. data/lib/samagotchi/terminal_ui.rb +3 -3
  37. data/lib/samagotchi/testing/boundary.rb +0 -5
  38. data/lib/samagotchi/testing/bundle.rb +1 -1
  39. data/lib/samagotchi/tools/task_runtime.rb +0 -5
  40. data/lib/samagotchi/version.rb +1 -1
  41. data/lib/samagotchi/web/app.rb +7 -1
  42. data/lib/samagotchi/web/public/app.js +13 -3
  43. data/lib/samagotchi/web/public/chains.js +3 -3
  44. data/lib/samagotchi/web/public/data.js +12 -0
  45. data/lib/samagotchi/web/public/delete_sheet.js +344 -0
  46. data/lib/samagotchi/web/public/format.js +1 -1
  47. data/lib/samagotchi/web/public/index.html +27 -0
  48. data/lib/samagotchi/web/public/info_bar.js +3 -2
  49. data/lib/samagotchi/web/public/lists_view.js +2 -2
  50. data/lib/samagotchi/web/public/more_sheet.js +42 -5
  51. data/lib/samagotchi/web/public/session_actions.js +50 -6
  52. data/lib/samagotchi/web/server.rb +13 -13
  53. data/lib/samagotchi/web/session_control.rb +58 -5
  54. metadata +5 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 858f59d0b9696f081f3f482cb9ae4609bf9ad1793f84567be5aacfc05950cd8e
4
- data.tar.gz: 902bdba4fbd18fb2faa666402bf37cf2cbe610f6293e7d6107dc8699894ea65c
3
+ metadata.gz: 9ebb4dcd3b901ac27f433f7113beb88393c67c41aea586513c1fcbae51e5b2d0
4
+ data.tar.gz: 6d8de5adbdcb40dc3fe433cb66bee2c187173a7bc3ac737f299a91fa975c04f3
5
5
  SHA512:
6
- metadata.gz: 9e2e8ce3d8c6ce27b4844d38fea93ad8603197fe9c61b0ff3275e116a52a658d294ff22348afea3fb5b18943e857173b5ae54565162ae8df5d89c03ee2f7d964
7
- data.tar.gz: 1f9516d73eb9f34768946891583e18121aa9361f60818025d5d87b557668df6e7bee5497bb59fcc514782d830025c6eb073fc9c717c130f1e9fbccd9d63bc5ba
6
+ metadata.gz: e0e438e9eb659466bf9c96bd228ca14f64707a4204be9cb71487c08eb5e1a93a3a4b98a41b29b5217d98b93c6a0caad921d739c4f6d11baaf621f8428db55370
7
+ data.tar.gz: 14fbc691fe2a5a140f53f7985307bb95930ca4e14d9f0aba2f3a327f46e738e07cf27d53607e40ded8527708abd59911c8315cc0ed3167b40fe7ac51c63cf357
data/CHANGELOG.md CHANGED
@@ -8,6 +8,35 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.174.0] - 2026-11-15
12
+
13
+ ### Added
14
+
15
+ - `chi sessions delete --chain` deletes every link of a session chain, with their finished delegates (running ones are
16
+ left running). A schedule on the chain refuses it.
17
+ - chi web: Delete on a session of a chain asks first, in the ⋯ panel (or at a card's ✕): delete this link, or the
18
+ whole chain, each saying what comes back and what goes. A session in no chain keeps the plain confirm.
19
+
20
+ ### Changed
21
+
22
+ - Deleting a chain's newest link (CLI, web, `/exit --delete`) undoes its continue: the previous link comes back to the
23
+ lists (not started) with the delegates and notes that had moved on, and the CLI says so. Before, the earlier links
24
+ stayed archived and dropped out of every list. A delete is refused while a continue of that session is under way,
25
+ and a schedule's first or current link can't be deleted. Against an older chi web, `--remote` deletes plainly.
26
+ - chi web: a chain whose earlier links were deleted says "earlier links deleted", whoever deleted them (it said "pruned
27
+ by a schedule").
28
+
29
+ ### Removed
30
+
31
+ - Bundles: `Samagotchi::Tools::TaskRuntime::TASKS_DIR` and `::EXIT_CODE_FILENAME`, kept one release after they moved;
32
+ name `Samagotchi::TaskFiles::TASKS_DIR` and `::EXIT_CODE_FILENAME`.
33
+
34
+ ### Fixed
35
+
36
+ - chi web answers successful requests without draining large ignored bodies first, closing the connection instead.
37
+
38
+ Update with `chi update`.
39
+
11
40
  ## [0.173.0] - 2026-11-14
12
41
 
13
42
  ### Added
@@ -6388,7 +6417,8 @@ and long-lived sessions.
6388
6417
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
6389
6418
  hotkey panel that send selected text or the clipboard to your sessions.
6390
6419
 
6391
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.173.0...HEAD
6420
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.174.0...HEAD
6421
+ [0.174.0]: https://github.com/dm1try/samagotchi/compare/v0.173.0...v0.174.0
6392
6422
  [0.173.0]: https://github.com/dm1try/samagotchi/compare/v0.172.1...v0.173.0
6393
6423
  [0.172.1]: https://github.com/dm1try/samagotchi/compare/v0.172.0...v0.172.1
6394
6424
  [0.172.0]: https://github.com/dm1try/samagotchi/compare/v0.171.0...v0.172.0
data/docs/architecture.md CHANGED
@@ -219,8 +219,8 @@ read their constants from and the display code (`ToolActivity`, `ToolView`, `Fil
219
219
  directly. The session commands' names, the built-ins' registry and its class-level reads (`builtin_name`,
220
220
  `builtin_registry`, `ui_only_entry`, `ui_only_refusal`, `delete_on_exit?`, `SHELL_BANG_PREFIX`…) live in
221
221
  `SessionCommandCatalog` (`session_command_catalog.rb`), which the TUI, chi web, `chi send` and `PromptHistory`
222
- require; `SessionCommands` (the runner, worker-side: `!cmd` runs `Tools::Execute`) includes it and forwards the
223
- class methods, so `SessionCommands.x` reads the same. A new client-side read of either goes to the table or the
222
+ require, and so does every caller of its class methods; `SessionCommands` (the runner, worker-side: `!cmd` runs
223
+ `Tools::Execute`) only includes it, for its constants. A new client-side read of either goes to the table or the
224
224
  catalogue, never to the class.
225
225
 
226
226
  ## Session retention & ordering
data/docs/cli.md CHANGED
@@ -762,9 +762,16 @@ archives it (an empty session is discarded instead; `chi scratch` refuses
762
762
  it). See
763
763
  [Sessions](sessions.md#archiving-a-session).
764
764
 
765
- `chi sessions delete [--force] ID...` deletes sessions for good: the
765
+ `chi sessions delete [--force] [--chain] ID...` deletes sessions for good: the
766
766
  session file and its whole directory (notes, images, queued input). Each id
767
- (or unique prefix) gets one line: `deleted`, or `refused` with the reason. A
767
+ (or unique prefix) gets one line: `deleted`, or `refused` with the reason.
768
+ Deleting a chain's newest link undoes its continue and says so (`… deleted;
769
+ the previous link 1a2b3c4d is back in the lists`): the previous link comes
770
+ back, not started, with the delegates and notes that had moved on. `--chain`
771
+ deletes every link of the session's chain with their delegates (a running
772
+ delegate is left running), one line per link and a `chain: …` summary; a
773
+ schedule on the chain refuses it. See docs/sessions.md (Session chains →
774
+ Deleting a link). A
768
775
  session whose worker runs is refused unless `--force` stops the worker first;
769
776
  one a `--non-interactive` run has is always refused ("in use by a one-turn chi
770
777
  --non-interactive run or an older chi's terminal; let it finish first"). Exit
@@ -25,9 +25,6 @@ load the process code, and does not (`spec/require_cycle_spec.rb`, the thin clie
25
25
  | `TaskFiles` (`task_files.rb`) | where a task's files are: `TASKS_DIR`, `METADATA_FILENAME`, `OUTPUT_FILENAME`, `EXIT_CODE_FILENAME`, `TASK_ID`, `metadata_path`, `task_dir_for`, `command_of` (a record read, no refresh) | `TaskRuntime`, `execute`, `ToolActivity`, `SessionManager`, `chi bundle try`'s sandbox, the slow-commands bundle |
26
26
  | `TaskTranscript` (`task_transcript.rb`) | which tasks a conversation started, from its results' text: `created_ids_in`, `created_id`, `handed_over_id`, `RAN_AS_LINE` (matching on `ToolNames::Execute`) | `TaskRuntime.running_created_in`, `Bridge`, `TaskWatch`, `WorkerTaskWakes`, `SessionManager` |
27
27
 
28
- `TaskRuntime::TASKS_DIR` and `TaskRuntime::EXIT_CODE_FILENAME` forward to `TaskFiles` for one release (bundles named
29
- them; the boundary's stable list has both homes until they are removed).
30
-
31
28
  Behavior:
32
29
 
33
30
  - `execute`, `task_create` and the `!cmd` shell bang run the command in a non-login shell: `/bin/sh -c` on Linux; on macOS, when `/bin/zsh` is there, `/bin/zsh --emulate sh +o ignore_braces +o sh_glob -o bash_rematch +o bsd_echo -c` (macOS's `/bin/sh` is bash 3.2, which can't parse an apostrophe in a heredoc inside `"$( )"`, the usual commit message shape). That mode reads no rc files and keeps POSIX word splitting, unmatched globs left as is, `{1..3}`, `[[ … =~ (…) ]]` with `BASH_REMATCH`, arrays, `$'…'`, `&>` and echo expanding `\t`. Bash-only builtins and variables (`shopt`, `BASH_VERSION`, `${!prefix*}`, `read -p`) are not there.
@@ -177,7 +177,9 @@ Transfer-Encoding) closes the connection the same way, whichever route or the ga
177
177
  participant's 403/404, the image path's own 413 and 429): `Web::Server`'s `CloseOnConnectionClose` turns WEBrick's
178
178
  keep-alive off, so it doesn't read the rest of the body before answering, and `LingerAfterAnswer` reads and drops at
179
179
  most 4 MB (2 s) after the answer so the client reads it before the close. An unauthenticated big body holds a thread
180
- at most those 2 s. A 2xx/3xx keeps the connection alive; a hijacked stream is left alone. The image path keeps its own rescue: a participant's
180
+ at most those 2 s. A 2xx/3xx with a small body (at most 64 KB) keeps the connection alive; a larger declared body or
181
+ any chunked body closes after the answer instead of holding a thread for the upload. A hijacked stream is left alone.
182
+ The image path keeps its own rescue: a participant's
181
183
  oversized upload is audited `too_large`, not `internal_error` (`SessionControl#image_upload_bytes`).
182
184
 
183
185
  Then `#route`, for each matching `ROUTES` row:
@@ -178,6 +178,14 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
178
178
  `identity`: an older chi web drops it and issues a link anyone could open) gets a feature of its own
179
179
  (`bound_grants`, `App::BOUND_FEATURE`), and `Remote` requires it before sending the field (`require_feature!`):
180
180
  never a silent downgrade.
181
+ - **A new route.** `DELETE /api/sessions/:id/chain?force=` (`chi --remote NAME sessions delete --chain`) is
182
+ `chain_delete` (`App::CHAIN_DELETE_FEATURE`): `Remote#delete_chain` requires it first, so an older chi web gives
183
+ "update it" (`RemoteTooOld`) and deletes nothing, rather than a 404 read as "not found". The route is query-only
184
+ (`force` from `req.GET`, no body read) and declared before the plain `/api/sessions/:id` rows. The plain delete
185
+ needs no feature: an older chi web deletes the link plainly (no revive, no undo) and its 200 has no
186
+ `unarchived`/`moved_back` (read as `[]`). The delete refusals reach the CLI with their own reason and message
187
+ (`continuing`, `delegate_unmovable`, `scheduled`, `chain_scheduled`, `worker_running`, `still_stopping`:
188
+ `Remote#raise_refusal` raises `DeleteRefused` with `ids` and `schedule_id`).
181
189
 
182
190
  ## Which checks run where
183
191
 
@@ -18,7 +18,7 @@ about 10% over the largest, `turn_block.js`), so a module near it splits rather
18
18
  `session_view.js`; ratcheted down from 2000, itself down from 2250 when the versions, the owner's claim links and
19
19
  Verify, the composer's mode and the strip's hide went into modules of their own. A new feature goes into a module of
20
20
  its own, wired from `app.js` in a few lines; a refactor that shrinks `app.js` ratchets its cap down with it. Never
21
- raise either: extract instead.
21
+ raise either: extract instead. Ruby's twin is `Samagotchi/FileSize` (docs/testing.md, File size).
22
22
 
23
23
  **New exports go in new modules.** The static JS is served at unversioned URLs. Today every load revalidates
24
24
  (app.rb `serve_static` sends `Cache-Control: no-cache` with a content ETag, and `sw.js` has no fetch handler), but an
@@ -29,7 +29,7 @@ page. A factory dep a new version stops passing is the same hazard the other way
29
29
  out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
30
30
  until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
31
31
  `turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
32
- `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `cards_offscreen.js` (the reload check's old placer, which nothing imports now: kept one release for a stale `app.js` that still imports it, then deleted), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
32
+ `session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (Deleting a chained session, below), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `cards_offscreen.js` (the reload check's old placer, which nothing imports now: kept one release for a stale `app.js` that still imports it, then deleted), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
33
33
 
34
34
  ## One page, every viewer
35
35
 
@@ -356,7 +356,8 @@ hides an empty group with its hairline. **A new chip needs a `BAR_ITEMS` entry a
356
356
 
357
357
  ⋯'s menu (`more_sheet.js`) is a popover above 600 px and a bottom sheet under it (`chip_popover.js`, `SHEET_MAX`; its
358
358
  own resize handling switches them, so a width change doesn't close it). It holds a row only for a folded item (the id,
359
- ⚙ when folded and not compact, "earlier links pruned" included), the folded ones of speed, clock and folder on its
359
+ ⚙ when folded and not compact, "Earlier links deleted" included: one word for a hand delete and a schedule's prune,
360
+ the logs say who; the info bar's chip "↩ earlier links deleted" and chains.js' rows say the same), the folded ones of speed, clock and folder on its
360
361
  telemetry line (none: no line), archive and delete always, continue and stop when folded. Its dot (`moreAttention`)
361
362
  and its count (`moreCount`, a desktop's, none at 0; archive and delete don't count) are from folded items alone: a chip
362
363
  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
@@ -365,6 +366,26 @@ placed at, so `chip_popover.js` places it, marks `aria-expanded` and gives focus
365
366
  `[data-anchor-stand-in]` (⋯). Rows and actions draw into fixed slots, so a row that joins keeps the focus where it was.
366
367
  The e2e reach an item wherever it is with `spec/e2e/support/layout.js` `clickBarItem` (the row, else ⋯'s `[data-row]`).
367
368
 
369
+ **Deleting a chained session** (`delete_sheet.js`; docs/sessions.md, Session chains → Deleting a link): Delete on a
370
+ session in a chain asks "Delete this link" or "Delete the whole chain" instead of the browser's confirm, which a
371
+ session in no chain keeps (`session_actions.js confirmDelete`; `isChained` reads the page's list, which holds archived
372
+ links too). In ⋯'s menu, Delete doesn't click `#infoDeleteBtn` for a chained session: `createMoreSheet`'s `onDelete`
373
+ (`session_actions.js deleteIn`) takes the panel as a host and draws the sheet in its place (a subview; ‹ More,
374
+ `del:back`, draws the list again; a redraw keeps the subview), so no second popover opens. A card's ✕ opens it at the
375
+ card (`createDeleteSheet`, on `chip_popover.js`: a bottom sheet on a phone). Both shells keep one live host: a
376
+ `host(anchor, id)` (the card's, with the session it opened for) or a Delete in ⋯ makes a new one, and a flow whose host
377
+ is no longer the live one (a ✕ on another card while the first plan was read) draws and acts on nothing. What the sheet says comes from
378
+ `GET /api/sessions/:id/delete_plan`, fetched as it opens and only for a chained session: the server's own plan and
379
+ refusals (`SessionChain::Delete::Preview`, the code the delete runs), so the sheet and the delete can't disagree; its
380
+ cost is one session listing walk per open. `deleteChoices` (pure) turns it into the two choices, a schedule's banner
381
+ and each refusal's "Not while …"; a plan that says no chain (a link alone past a gap) falls back to the confirm. A
382
+ stale plan is fine: the delete refuses as it does, and `runDeleteFlow` shows the refusal in the sheet
383
+ (`refusalModel`: a moved delegate that can't go back offers "Stop its worker, then delete" only when the 409 says
384
+ `stoppable`; it stops each, retries only once the stop answers `released`, and says so otherwise, never looping, one
385
+ stop at a time).
386
+ After a delete, `listAfterDelete` drops the `deleted` ids and un-archives the `unarchived` ones in the store, the
387
+ selection clears when it went, and the toast (`deleteToast`) names what came back with an "Open" action.
388
+
368
389
 
369
390
  ## Safe areas
370
391
 
data/docs/plugins.md CHANGED
@@ -1458,9 +1458,7 @@ that calls it, or for a real external bundle that does. No method on the chance
1458
1458
  `Samagotchi::Tools::ToolIndex.spec_tokens` (used by the mcp bundle).
1459
1459
  4. `Samagotchi::Tools::Execute::NAME`, `TIMEOUT_PREFIX`, `HANDED_OVER` and
1460
1460
  `Samagotchi::Tools::Execute.timeout_seconds`.
1461
- 5. `Samagotchi::TaskFiles::TASKS_DIR` and `EXIT_CODE_FILENAME` (require `samagotchi/task_files`). Their old names,
1462
- `Samagotchi::Tools::TaskRuntime::TASKS_DIR` and `EXIT_CODE_FILENAME`, still work in this release and are removed
1463
- in the next.
1461
+ 5. `Samagotchi::TaskFiles::TASKS_DIR` and `EXIT_CODE_FILENAME` (require `samagotchi/task_files`).
1464
1462
  6. `Samagotchi::AtomicFile.write`, `Samagotchi::Log.warn` /
1465
1463
  `Samagotchi::Log.debug`, `Samagotchi::Config.get`,
1466
1464
  `Samagotchi::VERSION`, `Samagotchi::CancellationController` (`new`, `cancel!`: what `cancel:` takes) and
data/docs/scheduling.md CHANGED
@@ -228,9 +228,12 @@ instead of racing it.
228
228
  chain links stay behind the head. After a successful chain firing — and after the
229
229
  result is recorded under the lock, so a prune that raises midway cannot lose the
230
230
  new `head` — the walk goes backwards from `head` and every link older than the
231
- window is deleted **together with its delegated children** (`descendant_ids`): the
231
+ window is deleted **together with its delegated children** (`SessionManager.delete_tree_ids`): the
232
232
  whole subtree only when every session in it is archived and no worker owns any of
233
- it, deepest child first and the link last, oldest link first. A subtree with a live
233
+ it, deepest child first and the link last, oldest link first. The delete itself is
234
+ `SessionManager.delete_ids` (the prune keeps its own checks and log tags): each id
235
+ through `delete_session`, and System 1's saved runs and the candidate log purged once
236
+ per link's batch, not once per session. A subtree with a live
234
237
  worker or an unarchived descendant is left whole and retried at the next firing. Pruning a link alone would leave its finished
235
238
  delegates archived forever with a dangling `parent_id`: archiving a session archives
236
239
  its descendants, and archived sessions are outside the retention sweep
@@ -247,9 +250,12 @@ If a link to prune still has a worker (`DeleteRefused(:worker_running)`), prunin
247
250
  stops there for this firing and is retried at the next one.
248
251
 
249
252
  Retention keeps the stored `anchor` and `head`, as well as the resolved target,
250
- of every enabled schedule. Deleting a protected session is refused—even with
253
+ of every enabled schedule. Deleting a protected session (a schedule's target,
254
+ anchor or head: a deleted head would make the schedule fall back to an archived
255
+ link and lose the links after it) is refused—even with
251
256
  `chi sessions delete --force`—until the schedule is cancelled with
252
257
  `chi schedule cancel ID`; a disabled schedule does not protect its sessions.
258
+ Deleting a whole chain (`--chain`) is refused while any enabled schedule is on it.
253
259
 
254
260
  ## Running the tick
255
261
 
data/docs/sessions.md CHANGED
@@ -43,7 +43,7 @@ A new session field is one `Session::FIELDS` row, plus a `SessionSetup` member w
43
43
 
44
44
  **Stopping a worker:** `chi sessions stop ID` marks the session stopped (an `<id>/stopped` file holding when, `{"at"}`, not a session.json field, which a worker saving at that moment would write over; a resume removes it), sends its worker TERM, then CONT (a stopped worker, SIGSTOP or Ctrl-Z, runs its TERM handler only once continued, so it leaves at once instead of outliving the wait), and waits (up to 10 s) until the worker has let go of `owner.lock`. A running turn is canceled over the Bridge first, with reason `session_stopped` (the turn's line ends "(session stopped)", its note says `cancelled (session-stopped)`, and a command it was running says "stopped as the session was stopped"; a bare signal to the worker makes it "stopped by a signal to chi"; an older worker takes the reason as `manual`); the TERM stops whatever still runs as a Stop with reason `signal` and saves it (a spawned worker traps TERM, HUP and INT: `WorkerSignals`; a turn not ended within 3 s, 0.5 s after a stop or a second signal, is cut and the session saved as it was), and a stopped worker still saves its kept turn, since the marker, not the saved status, says stopped. Any TERM, HUP or INT does the same to a worker outside a stop: it leaves (log `worker stop reason=signal`) and the next send wakes a new one, so a `chi --resume ID` right after spawns a fresh worker. That is also how to restart a worker still running an older chi, which the attached terminal reports when a command or a question dismiss gets a 404, and the web when an answer, a dismiss, a command or a cancel does (`501 not_supported`; `BridgeClient.stale_worker_message`). A command this chi has that the older worker doesn't (`/llm-context`, the web's ⚙ panel, against a 0.39.0 worker) says the same, not `not a session command` (`SessionCommandCatalog.builtin_name`); a typo keeps its `400 unknown_command`. The web's `POST /api/sessions/:id/stop` waits the same way, for 2 s (the page's Stop shows the stop at once), or for the body's `wait` up to the same 10 s (`SessionManager::STOP_WAIT`): `chi --remote NAME sessions stop` sends it, so it waits as long as here. Before that stop, the page's `stop session` button asks what the worker still has that the user can stop: `GET /api/sessions/:id/holds` (owner-only) answers the worker's `holds` — the same list the exit ask's 409 carries — always an array, empty when there is no live worker, one from before the route, or one that did not answer. With something, a sheet (a bottom sheet on a phone, a popover at the button otherwise — `stop_sheet.js`) lists them, at most three of a kind named and `+N more`, and offers **Stop all** (`POST /api/sessions/:id/holds/stop` → `HoldStop#stop_all`, then the stop), **Stop session only** (the stop exactly as it was) or **Cancel**. Nothing to ask about is the plain confirm, one tap as before. Both buttons stay because a stop only TERMs the worker: its reminders die with it (a stop also deletes a restart's `reminders.json` no successor took yet, so a later resume doesn't bring them back), while a background task and a delegate are their own processes and keep running. A command sent during a turn that waits for its end (`/model X`, `!cmd`; see *Typing during a turn* in [cli.md](cli.md)) and hasn't run when the worker leaves (a stop, a crash) is answered `command_ran {status: "dropped"}`, so no UI keeps showing it waiting.
45
45
 
46
- **Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped}`; 409 `owned_by_tui` or `still_stopping`; 404).
46
+ **Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped, unarchived, moved_back}`; `deleted` and `left_running` too; 409 with the refusal's reason as its code; 404). A schedule's target, anchor or head is refused (`scheduled`, naming the schedule): deleting a head would make the schedule fall back to an archived link. A user's delete (these three, `revive_previous:` and `refuse_continuing:` on `delete_session`) also knows about chains (`SessionChain::Delete`, *Session chains* → Deleting a link): it is refused while a continue of the session, or of the previous link it would bring back, is under way (`continuing`), and deleting a chain's newest link undoes its continue (D2/D5 below), the ids it brought back in `unarchived` and the delegates it gave back in `moved_back`. A previous link brought back is aged for retention from then on (`unarchived_at`) and has no participants (the archive ended them, and an unarchive doesn't bring them back). The scratch cleanup, the empty-session discard, the failed-continue rollback and a schedule's prune delete plainly; the retention sweep removes files directly (`remove_files`).
47
47
 
48
48
  <a id="archiving-a-session"></a>**Archiving a session:** `chi sessions archive ID...`, `/archive` in a terminal and the Web UI's `archive` go through `SessionManager.archive_session`: it writes `<id>/archived` (`{"archived_at": …}`; not a session.json field, which every save rewrites) for the session and its delegated children. `Session.list` leaves archived sessions out unless `include_archived:`, and everything built on it follows: `chi sessions list` (`--archived` shows them, `[archived]`), the summaries (`--live`, json/tsv, the desktop panel, the agent's `list_sessions`) and the retention prune, which neither deletes nor counts them against `max_count`. `children_of` (max_children, `delegate_result`) still sees them, and `--resume`/`--attach ID`, `chi send`/`chi note ID` reach them as before, except that `chi send` and `chi note` to a link that was continued go to its chain's newest link (*Session chains*). Refused: a turn running in the session or in one of its children (naming the child; 409 `busy` on the web), a prompt queued in `input/` (it would run on the next resume) or a live worker's step-limit question still open, in it or a child (409 `busy` too), a one-turn `chi --non-interactive` run owning it (`owned_by_tui`), a `chi scratch` session (`scratch`). A live idle worker is stopped first, and the marker is written even if it is still shutting down. Input a human typed brings a session back (`{"unarchived_at": …}`): a prompt from the web, an attached terminal or `chi send` (origin `web:*`, `tui:*`, `cli:send`, its own first prompt: `spawn:first`; input naming no sender doesn't), steering merged into a running turn, a `/continue` answer or a question answered (the step-limit question too); a delegate's follow-up, a plugin's turn, a reminder, the idle recap, a note and just opening it don't. A child's input brings only the child back. The retention sweep ages an unarchived session from when it was unarchived, so unarchiving an old session doesn't let the next sweep take it. `/archive` leaves the session first, as `/exit` does, then archives it: in an attached terminal the worker is asked to exit (one that stays up for another UI is stopped by the archive; a running turn, a queued prompt or an open step-limit question refuses it), and an empty session is discarded instead; `chi scratch` refuses it. Typed while a turn runs, `/archive` waits for the turn's end (an attached terminal for the commands queued behind it too) and then archives. `chi sessions unarchive ID...` and the web's `unarchive` bring back the whole family. Web routes: `POST /api/sessions/:id/archive` (200 `{status, session_id, archived, stopped, discarded}`, ids) and `POST /api/sessions/:id/unarchive` (200 `{status, session_id, unarchived}`). The session hub and `GET /api/sessions` keep archived sessions, `archived: true` in their summaries: the page leaves them out of the strip, its count and the list at render, and the `archived` toggle beside the all-sessions search shows them, dimmed with an `archived` badge. The info bar marks a session whose live worker runs an older chi than the newest installed (`worker_version` in its summary): `chi 0.18.1 · Restart`, which asks to confirm and calls `POST /api/sessions/:id/restart` (a refusal's reason shows in a toast); a worker from before restarts shows `chi sessions stop ID` instead. The info bar reads `continue → · archive · stop · delete` (`unarchive` on an archived one; no `continue →` on a link continued already, see *Session chains*; `continue →` is a plain button like `archive`, in the accent on an archived session, where it is the thing to do); archiving the open session stays on it, with an Undo toast.
49
49
 
@@ -378,12 +378,14 @@ A session can **continue** an earlier one: "the next run of the same routine" (a
378
378
  - **The recap first:** a previous link with a live worker is asked for a recap (the Bridge's `POST /recap`) and given up to 30 s to write it; one with none wrote its recap when its worker left.
379
379
  - **The previous link is archived** before the new one starts, by the archive's own rules (see *Archiving a session*): a turn running, a prompt queued or the step-limit question refuse it, a live idle worker is stopped, a session a one-turn `chi --non-interactive` run has is refused. Its finished delegates are archived with it, as any archive does. Before archiving, the continue writes `<previous>/continue.json` with the reserved successor id. Session lists and the next continue repair an interrupted operation under `continue.lock`: if that successor's session file was not saved, they unarchive the previous link and remove the intent; if it was saved as its successor, they clear the intent and keep the archive.
380
380
  - **Its open delegates move to the new link** instead: each direct delegate that is running, waiting for an answer, has a live worker or a reply its parent wasn't given, or has such a delegate below it (checked again after the recap wait, so one delegated meanwhile moves too). It moves with its own delegates, stays unarchived, and from then on is the new link's: its card folds under the new link, its reports ring the new link (an idle one runs a wake turn for them, as for its own delegates), `delegate_result` and the `⑂` chip count it there, and what its parent was already told (`delegates.json`) and any report still waiting come along, so nothing is reported twice. A moved delegate gets a context note from `session chain`, `Your parent session is now 4b7e9a01 (…), the next link of its session chain: …`, as its system prompt keeps naming the parent it started with. The move writes `<child>/parent.json` (`{parent_id, from, at}`) beside the child's session file, never the file itself, so a live child worker saving its own copy changes nothing; every reader applies it (a later move overwrites it; it is never removed). A continue is **refused for an open delegate that can't move** (`SessionContinue::Refused`, naming it): one whose live worker runs an older chi (`older chi worker 0.46.1; restart it`: `chi sessions restart <id>`, or stop it) or that a one-turn `chi --non-interactive` run has (`in use by a one-turn chi --non-interactive run or an older chi's terminal; let it finish`). An older `chi web` or CLI still running shows a moved delegate under the archived link until it is restarted.
381
+ - **What it records:** `<new link>/continued_from.json` (`ContinuedFrom`: `{previous_id, archived_ids, moved_ids}`), written first in the new link's `before_spawn`: the ids its archive hid (the previous link and the delegates archived with it, not ones archived before) and the delegates it moved. Deleting the link reads it to undo the continue. A link from an older chi has none.
381
382
  - **If the continue fails part-way:** what a continue carries (its delegates, attached context, objectives and notes, in that order) and how each is given back is one list, `SessionContinue::CARRY` (the per-session stores it leaves behind, and why, are `SessionContinue::NOT_CARRIED`). A new link that fails to start gives its moved delegates back before it is deleted (each gets a note saying so; its worker is stopped first, if one started, and a worker that won't stop is reported, the link left), with any report one of them rang it with meanwhile, and the notes it moved with any sent to it meanwhile (never the continue's own: the carry note, the attached-context note, the objectives' list): its session file goes first, so a note sent to the previous link from then on stays there, then the notes go back, then its folder goes, and a note an older chi writes into it after that is given back too (a note for a session with no file and no folder is refused, never a stray folder); the previous link, back in the lists, is woken for reports waiting. A continue that dies in the middle leaves a `move.json` in the new link's folder: the new link's next worker finishes that move (only the delegates it names, and without a second note to one already told) as it starts. Its `continue.json` intent remains in the previous link's folder too, so a later list can restore it if the successor was never saved. Until the new link's own worker holds it, a ring from a moved delegate doesn't start another (a `starting` marker in its folder, which that worker removes; a stale one, over 60 s old or from a process that is gone, is ignored). An open delegate below an archived delegate refuses the continue (`under archived …`): unarchive that one, or archive this one.
382
383
  - **Refused too:** a link that is continued already (naming the link that continues it; continue that one, or `last:<id>`), a previous link whose folder is gone, and one whose model's host can't run it when no default model is configured to fall back to. A refusal starts nothing and archives nothing; a new link that fails to start puts back what was archived. Every refusal that can be known up front (the archive's ones included) comes before the recap wait. One continue of a session runs at a time (a lock in its folder; other chains don't wait), so a double click finds the first one's link and is refused, while a `last:<id>` continue that waited follows the chain to its new end.
383
384
  - **Web:** `POST /api/sessions` takes `continues: "<id, prefix or last:id>"`, with `idle: true` (a new link waiting for its first message, previewed by the previous link's, or `preview`) or a `prompt`, and `model` (or `model_name`) for the new link's model, but not `dir`, `llm_context`, `thinking`, `settings`, `toolkit`, `tools`, `no_tools` or `parent_answers` (400 `invalid_continues`: the previous link's are taken). 201 is the new session's summary, `continues` set, with `moved`: the ids of the delegates that moved to it (`[]` for none), and `model_warning`: the default-model fallback's warning, then any about the model id, joined by `; ` (`null` for none), and `opener`: the previous link's first typed message, in full, when that link continues one itself (`null` otherwise: a chain's first link's first message is its task), and `moved_context`: `{moved: [names], stayed: [{name, why}]}`, the attached context it took (`why` `pushed` or `not movable`); 404 `not_found`; 400 `ambiguous_id` for a prefix of several sessions, `invalid_model` for a given model whose host config.yml doesn't have (or a fallback with no default model); 409 `continued` with `next_id` (the link that continues it already, which the page opens instead), `open_children` with `ids` (open delegates that can't move), `folder_gone`, `busy`, `scratch` or `owned_by_tui`. Every session summary carries `continues`.
384
385
  - **The page:** the info bar's `continue →` continues the open session (`continues: <id>, idle: true`; it reads `continuing…` through the recap wait) and opens the new link with an opener in the composer, not sent (a draft written in this session stays instead; one carried over from another session or the start page gives way to the opener, and the toast's **Restore draft** brings it back): the previous link's own first typed message when that link continues one (the 201's `opener`; a `!shell` line isn't taken), else `Continue where we left off.`. So whatever you sent on the last link comes back on the next one, and editing it once changes it for every later link; the previous link is archived, a toast says so (`Continued 3fa2c1d0 in 4b7e9a01; 3fa2c1d0 is archived; 1 open delegate moved`), and a moved delegate's card folds under the new link. When the previous link's model's host is gone the link starts on the default model and the toast carries the server's `model_warning` too, and then stays until closed. A fresh link (one with no turn yet, however it was made: `continue →`, `chi send --new --continues`, a reload) shows the model picker in its composer with the link's model, until its first turn starts (a failed or canceled first turn ends it too); a pick runs `/model <name>` in the link (a command bubble; the info bar follows) and changes neither the start page's remembered model nor its Recent list, and a Send right after it waits for the `/model` to be taken. A link a one-turn `chi --non-interactive` run has, or one continued already, shows none. A link continued already has no `continue →`: its `→` link goes to the next link (a stale page's continue answered 409 `continued` opens `next_id`). A continue refused for open delegates that can't move shows a toast that names each one (its preview and what the server says to do: `older chi worker 0.46.1; restart it`, `in use by a one-turn chi --non-interactive run or an older chi's terminal; let it finish`), each a link to its page; any other refusal shows the server's words. The info bar of a link carries `← 2026-10-08` (the previous link's day) and, on an earlier link, `2026-10-10 →`, each a link with its id, its full start (`2026-10-10 14:32`) and its preview in the tooltip; a neighbour that started on the open link's own day shows its time instead (`← 09:12`, `14:32 →`). A link made by `continue →` inherits the previous link's preview (and its title, if it has one) when it is created, so its card keeps its chain's title whatever opener it is sent, and its top bar and browser tab show its card's title. A link with a recap of its own reads its auto title, else its recap's first sentence, instead (a link without one reads its chain's name, and a first link's recap names its chain). A link whose title is the opener and nothing else (a `chi send --new --continues` link whose first message is `Continue where we left off.`) shows its chain's first link's title instead, on its card, in the popover and in its info bar's title line, display only (its messages and data keep the opener; its own title when the first link is gone). The lists fold a chain into the card of its latest listed link, whatever the earlier links' archived state (typing in an archived link brings it back, folded there still), their delegates with them: the card's `↩ #N` chip (`#N of M` when later links aren't listed; its tooltip `Session chain: link N of M`) opens a popover of the other links, newest first (`#N`, its date, with its time (`2026-10-17 14:32`) when another link of the chain started the same day, its own title when it differs from the card's (a link inherits its chain's, so mostly it doesn't), else its recap's first sentence, else its preview, `archived`), a click opens one; the chip shows a live dot or `waiting` for a link that has a worker or waits on the user, and a waiting link puts its chain's card first. All sessions folds nothing while a search is typed or the `archived` toggle is on: every link is a card of its own then, its chip `#N of M`, with its own delegates folded in, so a search finds an earlier link and its delegates.
385
386
  - **CLI:** `chi send --new --continues (ID|PREFIX|last:ID) [--model M] [-m TEXT]` (see *Starting a session*).
386
387
  - **Which link:** an id, a unique prefix, or `last:<id or prefix>`, the latest link of the chain that session is in. It walks the links that still exist: a deleted link in the middle (`chi sessions delete`, the retention sweep of an unarchived one) ends the walk before it, so `last:` of an earlier link then names that earlier link, and continuing it starts a second line beside the links after the gap; name a link after the gap instead. A trigger names the chain this way: a person's message to an archived link that nobody continued brings it back (a human's input), it doesn't continue the chain; an unattended sender's is refused (*Who may wake a session*). That is the rule: `chi send` and a note go to the chain's newest link (*Sending a message*, *Context notes*); the web composer, a participant's turn and `delegate(session:)` go to the link they name. One walker answers every one of these (`SessionChain::Links`: one session listing, archive flags read once; the earliest created successor wins a fork a hand edit made, a loop ends where it would repeat), with two rules on it, not unified on purpose: `last:` and a schedule take the chain's **end** (`Links#latest`: a continue refuses a link continued already, and a schedule never un-archives a chain you retired), `chi send` and a note the **first link not archived** (`Links#first_live`: a person's input goes where the chain is live, and brings back an archived end). A chain pruned by a schedule keeps its `anchor`: the kept window's oldest link still names a link that is gone, so the walk simply stops there; the page's chip counts from the surviving root (pruning renumbers the links) and its popover says `earlier links pruned` where the walk stops, rather than linking to a deleted session.
388
+ - **Deleting a link** (`SessionChain::Delete`; the CLI, the web and `/exit --delete`): a link of a chain is deleted alone by default, and what follows depends on where it is. **The newest link** (nobody continues it, it isn't archived itself, the link before it is archived) undoes its continue: the delegates the continue moved go back to the previous link, finished ones too (`continued_from.json`'s `moved_ids`, still under the link; without the record, its children whose `parent.json` says they came from the previous link), each with a note saying the link was deleted; every note waiting in the link but the continue's own goes back too (`NoteMove.give_back`); then the previous link and what the continue archived with it come back to the lists (without the record, the previous link alone). The previous link is **not started**: reports a moved-back delegate left wait for its next start. What dies with the link: its turns, context sources, objectives edits, session approvals and participant grants (the previous link kept its own copies). Every refusal comes before anything goes: the link's delegates that would go are checked too (a schedule on one, a one-turn run), and they and the link are removed (and the undo runs) only under their `owner.lock`s (kind deleting, taken without waiting, so a worker that took one refuses it); a moved delegate that can't go back (`ChildMove.unmovable`: an older chi's worker, a one-turn run) refuses it (`delegate_unmovable`, naming it), as does a worker that took the link after the stop. Deleting the links one after another undoes each continue by its own record. **A middle link** splits the chain (the earlier links stay archived, the later ones go on as their own chain); nothing is undone or re-linked. A link whose chain is all archived stays archived around the gap. **The link's own delegates** (any position) follow one rule, `SessionChain::Delete::DELEGATES`: a running one (a worker owns it or is starting for it, a one-turn run; a saved `running` with no worker is a crashed run, and goes) is left running with its whole subtree, its file untouched (its parent's id names a deleted session; its reports are refused as for any gone parent); every other node under the link goes, deepest first, before the link. A session in no chain (a link alone past a gap too) is deleted as before. **The web asks first**: for a chained session, chi web's delete sheet reads `GET /api/sessions/:id/delete_plan` (`:owner`; no query or body; no-store), `SessionChain::Delete::Preview` over the same `LinkPlan`/`ChainPlan` and checks the delete runs (`check_link!`, `check_chain!`): the link's place in the chain, what comes back and goes for each choice, and each choice's refusal now (a schedule on the chain, the link or a delegate that would go, a continue under way, a one-turn run, a moved delegate that can't go back and whether the page can stop it). One session listing walk per call; the page asks only for a chained session as the sheet opens. It takes and releases each link's continue lock (shared, as the delete does), creating its empty file where there was none, and writes nothing else; an unknown id is the usual 404. The moved count is each moved delegate with its subtree (they come back with it), and a `delegate_unmovable` 409 says `stoppable` itself. A stale answer is fine: the delete makes its plan again and refuses as it does. **The whole chain** (`chi sessions delete --chain`, `DELETE /api/sessions/:id/chain`, `SessionManager.delete_chain`): every link reachable from this one on its branch, newest first, each with its delegates by the same rule. Refused before anything goes when a schedule is on the chain (`chain_scheduled`) or on a delegate that would go (`scheduled`), a link or such a delegate is in a one-turn run, a continue of a link is under way (`continuing`), without `force` a link has a worker, or a link's worker outlives the stop's wait: every link is checked and stopped before the first is deleted, and each then goes under the owner locks of it and its delegates. A chain with a gap before this link reaches only the part after the gap: the earlier links stay archived (`cut_off: true`). A link refused part-way (a worker that took it after its stop) leaves it, its delegates and the earlier part of the chain whole, its new end back in the lists, and the result lists what was left.
387
389
 
388
390
  ## Schedules
389
391
 
data/docs/testing.md CHANGED
@@ -334,6 +334,12 @@ One lib cop sits beside them: `Samagotchi/SilentRescue` (a `rescue` of StandardE
334
334
  `nil`, `[]`…: use `Degrade`, or tag a right silence `# degrade-ok: why`; docs/internals/engine.md, Degrading). The
335
335
  files that had such rescues when it came are excluded in `.rubocop.yml`: that list only shrinks.
336
336
 
337
+ ### File size
338
+
339
+ `Samagotchi/FileSize` counts lines as `wc -l` does, including blank and comment lines. Ruby files have a `Max` of
340
+ 1000; `.rubocop.yml`'s `Caps` list gives existing larger files their measured size plus 50 when the cap came. Split
341
+ instead of raising a cap, and ratchet it down when its file shrinks. Specs are not covered yet.
342
+
337
343
  ### Flakes
338
344
 
339
345
  When `parallel_rspec` fails in CI's `rspec` or `rspec-macos` job, the next step (`script/rerun_failures.rb`) reruns
@@ -1077,7 +1077,7 @@ module Samagotchi
1077
1077
  # The Engine's own commands: the built-ins and its plugins' (a card's
1078
1078
  # action is a plugin command line).
1079
1079
  unless command_registry.command?(line)
1080
- known = command_registry.entries.reject(&:local).map { |entry| SessionCommands.display_name(entry) }.sort
1080
+ known = command_registry.entries.reject(&:local).map { |entry| SessionCommandCatalog.display_name(entry) }.sort
1081
1081
  detail = "not a session command: #{line[0, 80]} (known: #{known.join(", ")}; /help lists them)"
1082
1082
  return [{ "Allow" => "POST" }, 400, { error: "unknown_command", detail: detail }]
1083
1083
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: samagotchi-system
3
- version: 0.173.0
3
+ version: 0.174.0
4
4
  scope: system
5
5
  description: Default system memories — identity, self map, config modification protocol, memory guide and the delegated-session rules
6
6
  files:
@@ -102,8 +102,10 @@ module Samagotchi
102
102
  # noted, and a run finishing it (#adopt) notes only the rest. A crash
103
103
  # between a note and its record notes that child twice (better than
104
104
  # none).
105
- # @param undo [Boolean] a failed continue moving them back: its note says so
106
- def apply(ids, from:, to:, state_dir:, undo: false)
105
+ # @param undo [Symbol, nil] why they move back, which the note says:
106
+ # :failed_continue (the continue failed) or :deleted_link (the link
107
+ # they moved to was deleted: SessionChain::Delete); nil moves them on
108
+ def apply(ids, from:, to:, state_dir:, undo: nil)
107
109
  return if ids.empty?
108
110
 
109
111
  intent = Intent.new(from: from, ids: ids)
@@ -191,10 +193,15 @@ module Samagotchi
191
193
  # The child's system prompt names the parent it started with for its
192
194
  # whole life (a prompt-cache miss each time it changed): a note tells a
193
195
  # running one where its notes and reports go now.
194
- def note_child(child_id, to:, state_dir:, undo: false)
195
- text = if undo
196
+ # @param undo [Symbol, nil] #apply's
197
+ def note_child(child_id, to:, state_dir:, undo: nil)
198
+ text = case undo
199
+ when :failed_continue
196
200
  "Your parent session is #{to[0, 8]} (#{to}) again: the continue that moved you to its next link " \
197
201
  "failed. Send notes there, and your reports reach it."
202
+ when :deleted_link
203
+ "Your parent session is #{to[0, 8]} (#{to}) again: the next link of its chain, which you had moved " \
204
+ "to, was deleted. Send notes there, and your reports reach it."
198
205
  else
199
206
  "Your parent session is now #{to[0, 8]} (#{to}), the next link of its session chain: send notes " \
200
207
  "there, and your reports reach it."
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "json"
5
+ require_relative "atomic_file"
6
+ require_relative "session"
7
+
8
+ module Samagotchi
9
+ # <link>/continued_from.json: what the continue that made this link did to
10
+ # the previous one, so deleting the link can undo it (SessionChain::Delete,
11
+ # D5): the previous link's id, the ids the continue archived (it and the
12
+ # delegates archived with it, not the ones archived before) and the
13
+ # delegates it moved here. Written in the new link's before_spawn, before
14
+ # the carry (SessionContinue.spawn_continuation), and never changed. A
15
+ # link an older chi made has none: the delete falls back to the previous
16
+ # link alone and its children whose parent.json says they came from it.
17
+ # CROSS-VERSION: another chi's delete reads this file
18
+ # (spec/compat/readers_spec.rb).
19
+ module ContinuedFrom
20
+ FILE = "continued_from.json"
21
+
22
+ Record = Data.define(:previous_id, :archived_ids, :moved_ids)
23
+
24
+ module_function
25
+
26
+ def path(id, state_dir:) = File.join(Session.session_dir(id, state_dir: state_dir), FILE)
27
+
28
+ # @param archived_ids [Array<String>]
29
+ # @param moved_ids [Array<String>]
30
+ def write(id, previous_id:, archived_ids:, moved_ids:, state_dir:)
31
+ file = path(id, state_dir: state_dir)
32
+ FileUtils.mkdir_p(File.dirname(file))
33
+ data = { previous_id: previous_id, archived_ids: archived_ids, moved_ids: moved_ids }
34
+ AtomicFile.write(file, "#{JSON.generate(data)}\n", perm: 0o600)
35
+ end
36
+
37
+ # The record, nil when there is none (an older chi's link) or it doesn't
38
+ # read as one (no valid previous id). Ids that aren't ids are dropped.
39
+ # @return [Record, nil]
40
+ def read(id, state_dir:)
41
+ data = JSON.parse(File.read(path(id, state_dir: state_dir)))
42
+ return nil unless data.is_a?(Hash) && Session.valid_id?(data["previous_id"])
43
+
44
+ Record.new(previous_id: data["previous_id"], archived_ids: ids(data["archived_ids"]), moved_ids: ids(data["moved_ids"]))
45
+ rescue JSON::ParserError, SystemCallError
46
+ nil
47
+ end
48
+
49
+ def ids(value) = Array(value).select { |id| Session.valid_id?(id) }
50
+ end
51
+ end
@@ -368,7 +368,7 @@ module Samagotchi
368
368
  task_finish_notes: task_finish_notes)
369
369
  restrict_scratch_tools! if @scratch
370
370
  # Likewise the slash commands its SessionCommands run.
371
- @command_registry = SessionCommands.register_builtins(Commands::Registry.new)
371
+ @command_registry = SessionCommandCatalog.register_builtins(Commands::Registry.new)
372
372
  # Installed bundles' plugins add commands, tools and hooks to these
373
373
  # (docs/plugins.md); one that fails is announced with the load
374
374
  # failures, and the rest still load.
@@ -57,15 +57,22 @@ module Samagotchi
57
57
  # meanwhile, never one the continue wrote itself (CONTINUE_SOURCES).
58
58
  # @return [Array<String>] the file names given back
59
59
  def give_back(from:, to:, moved:, state_dir:)
60
- files = unclaimed(notes_dir(from, state_dir)).select do |file|
60
+ rename(returnable(from: from, moved: moved, state_dir: state_dir), notes_dir(to, state_dir)).tap do |back|
61
+ Log.info(:worker, "notes_given_back", from: from[0, 8], to: to[0, 8], count: back.size) unless back.empty?
62
+ end
63
+ end
64
+
65
+ # The note files #give_back takes from +from+: those in +moved+ and
66
+ # every other unclaimed one but an objectives list and the continue's
67
+ # own (CONTINUE_SOURCES). A chain delete's plan counts them.
68
+ # @return [Array<String>] paths, oldest first
69
+ def returnable(from:, moved:, state_dir:)
70
+ unclaimed(notes_dir(from, state_dir)).select do |file|
61
71
  next true if moved.include?(File.basename(file))
62
72
 
63
73
  data = read(file)
64
74
  data && !objectives?(data) && !CONTINUE_SOURCES.include?(data["source"])
65
75
  end
66
- rename(files, notes_dir(to, state_dir)).tap do |back|
67
- Log.info(:worker, "notes_given_back", from: from[0, 8], to: to[0, 8], count: back.size) unless back.empty?
68
- end
69
76
  end
70
77
 
71
78
  # How far back along the chain a worker adopts (Adoption): the links
@@ -209,6 +209,14 @@ module Samagotchi
209
209
  entries.find { |entry| target_of(entry, links).first == session_id }
210
210
  end
211
211
 
212
+ # The enabled schedule a delete of +session_id+ would break: one whose
213
+ # target (#protecting), anchor or head it is. A head deleted would make
214
+ # the schedule fall back to its anchor (an archived link) and fail.
215
+ # @return [Entry, nil]
216
+ def protecting_link(session_id)
217
+ entries.find { |entry| entry.anchor == session_id || entry.head == session_id } || protecting(session_id)
218
+ end
219
+
212
220
  # @param id_or_name [String] an id, a unique prefix of one, or a title
213
221
  # @return [Entry, nil]
214
222
  # @raise [Usage] the prefix or the title names more than one schedule
@@ -303,17 +311,7 @@ module Samagotchi
303
311
  # chain and each link back to its root. A schedule belongs to a chain when
304
312
  # its anchor or its head is one of them.
305
313
  # @return [Array<String>]
306
- def chain_of(session_id)
307
- links = links_now
308
- head = links.latest(session_id)
309
- ids = [head]
310
- id = head
311
- while (previous = links.continues(id)) && !ids.include?(previous)
312
- ids << previous
313
- id = previous
314
- end
315
- ids
316
- end
314
+ def chain_of(session_id) = links_now.chain(session_id).reverse
317
315
 
318
316
  # The schedules of this session's chain — the ones the tools may touch
319
317
  # without `all: true`.
@@ -1230,11 +1228,12 @@ module Samagotchi
1230
1228
  next if link == entry.anchor
1231
1229
  break unless ArchiveStore.archived?(Session.session_dir(link, state_dir: @state_dir))
1232
1230
 
1233
- descendants = SessionManager.descendant_ids(link, @state_dir)
1231
+ tree = SessionManager.delete_tree_ids(link, @state_dir)
1232
+ descendants = tree[0...-1]
1234
1233
  # The whole subtree must be ready: a live worker anywhere in it, or a
1235
1234
  # link's descendant that is not archived, stops the walk here rather
1236
1235
  # than half-deleting a tree.
1237
- owned = [link, *descendants].select { |sid| SessionManager.session_owner(sid, state_dir: @state_dir) }
1236
+ owned = tree.select { |sid| SessionManager.session_owner(sid, state_dir: @state_dir) }
1238
1237
  unless owned.empty?
1239
1238
  Log.warn(:worker, "prune_waiting", sid: link, id: entry.id, owned: owned.map { |sid| sid[0, 8] })
1240
1239
  break
@@ -1250,9 +1249,7 @@ module Samagotchi
1250
1249
  # refused partway, nothing above it has gone, so the next firing
1251
1250
  # retries the same set instead of leaving children under a link that
1252
1251
  # is already deleted.
1253
- (descendants.reverse + [link]).each do |sid|
1254
- SessionManager.delete_session(sid, state_dir: @state_dir)
1255
- end
1252
+ SessionManager.delete_ids(tree, state_dir: @state_dir)
1256
1253
  Log.info(:worker, "pruned_link", sid: link, id: entry.id, links: descendants.size + 1)
1257
1254
  end
1258
1255
  rescue SessionManager::DeleteRefused => e
@@ -116,6 +116,7 @@ module Samagotchi
116
116
  "sessions unarchive" => SUPPORTED,
117
117
  "sessions delete" => SUPPORTED,
118
118
  "sessions delete --force" => SUPPORTED,
119
+ "sessions delete --chain" => SUPPORTED,
119
120
  "sessions prune" => LOCAL_ONLY,
120
121
  "sessions clean" => LOCAL_ONLY,
121
122
  "sessions stats" => LOCAL_ONLY,
@@ -293,7 +293,15 @@ module Samagotchi
293
293
 
294
294
  # @param force [Boolean] stop a live worker first (else refused)
295
295
  # @return [Hash] SessionManager.delete_session's
296
- def delete(id, force:) = SessionManager.delete_session(id, stop: force, **dir)
296
+ # A user's delete: SessionManager.delete_session's revive_previous: and
297
+ # refuse_continuing: (D2/D5), on unless told otherwise.
298
+ def delete(id, force:, revive_previous: true, refuse_continuing: true)
299
+ SessionManager.delete_session(id, stop: force, revive_previous: revive_previous,
300
+ refuse_continuing: refuse_continuing, **dir)
301
+ end
302
+
303
+ # Every link of the chain (SessionManager.delete_chain).
304
+ def delete_chain(id, force:) = SessionManager.delete_chain(id, stop: force, **dir)
297
305
 
298
306
  # --- context (a session's sources, or a project's: local only)
299
307
  #