samagotchi 0.172.1 → 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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -1
  3. data/docs/architecture.md +16 -5
  4. data/docs/cli.md +11 -3
  5. data/docs/configuration.md +1 -1
  6. data/docs/internals/background-tasks.md +16 -6
  7. data/docs/internals/bridge.md +2 -2
  8. data/docs/internals/engine.md +2 -1
  9. data/docs/internals/participants.md +69 -9
  10. data/docs/internals/remote-sessions.md +9 -1
  11. data/docs/internals/web-frontend.md +34 -8
  12. data/docs/plugins.md +1 -1
  13. data/docs/scheduling.md +9 -3
  14. data/docs/sessions.md +5 -3
  15. data/docs/testing.md +32 -10
  16. data/lib/samagotchi/bridge.rb +4 -3
  17. data/lib/samagotchi/bundle_command/try/sandbox.rb +2 -2
  18. data/lib/samagotchi/bundles/core/manifest.yml +2 -2
  19. data/lib/samagotchi/bundles/slow-commands/manifest.yml +3 -3
  20. data/lib/samagotchi/bundles/slow-commands/plugin.rb +3 -3
  21. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  22. data/lib/samagotchi/child_move.rb +11 -4
  23. data/lib/samagotchi/continued_from.rb +51 -0
  24. data/lib/samagotchi/engine/participants.rb +2 -2
  25. data/lib/samagotchi/engine.rb +1 -2
  26. data/lib/samagotchi/file_ref.rb +3 -5
  27. data/lib/samagotchi/guardrails/participant_refusal.rb +1 -1
  28. data/lib/samagotchi/memory_usage.rb +2 -1
  29. data/lib/samagotchi/message_parts.rb +5 -3
  30. data/lib/samagotchi/note_move.rb +11 -4
  31. data/lib/samagotchi/objectives_backing.rb +6 -10
  32. data/lib/samagotchi/parent_report.rb +1 -1
  33. data/lib/samagotchi/participant_prompts.rb +101 -0
  34. data/lib/samagotchi/participant_turn_mode.rb +1 -1
  35. data/lib/samagotchi/project_env.rb +7 -5
  36. data/lib/samagotchi/prompt_history.rb +2 -2
  37. data/lib/samagotchi/schedules.rb +13 -16
  38. data/lib/samagotchi/send_command/parent_gate.rb +2 -2
  39. data/lib/samagotchi/send_command.rb +4 -4
  40. data/lib/samagotchi/session_access/contract.rb +1 -0
  41. data/lib/samagotchi/session_access/local.rb +9 -1
  42. data/lib/samagotchi/session_access/remote.rb +26 -3
  43. data/lib/samagotchi/session_chain/delete.rb +405 -0
  44. data/lib/samagotchi/session_chain/delete_preview.rb +96 -0
  45. data/lib/samagotchi/session_chain/links.rb +38 -0
  46. data/lib/samagotchi/session_command_catalog.rb +210 -0
  47. data/lib/samagotchi/session_commands.rb +6 -187
  48. data/lib/samagotchi/session_continue.rb +51 -13
  49. data/lib/samagotchi/session_delete_command.rb +82 -17
  50. data/lib/samagotchi/session_manager/lifecycle.rb +5 -4
  51. data/lib/samagotchi/session_manager/removal.rb +137 -31
  52. data/lib/samagotchi/session_manager.rb +2 -1
  53. data/lib/samagotchi/session_stores.rb +4 -0
  54. data/lib/samagotchi/spawn_env.rb +75 -0
  55. data/lib/samagotchi/task_files.rb +51 -0
  56. data/lib/samagotchi/task_transcript.rb +67 -0
  57. data/lib/samagotchi/task_watch.rb +8 -6
  58. data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +3 -3
  59. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +2 -2
  60. data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -2
  61. data/lib/samagotchi/terminal_ui/attached_loop.rb +4 -4
  62. data/lib/samagotchi/terminal_ui/exit_lines.rb +16 -0
  63. data/lib/samagotchi/terminal_ui/input_support.rb +1 -1
  64. data/lib/samagotchi/terminal_ui/local_link.rb +7 -1
  65. data/lib/samagotchi/terminal_ui.rb +3 -3
  66. data/lib/samagotchi/testing/boundary.rb +2 -2
  67. data/lib/samagotchi/testing/bundle.rb +1 -1
  68. data/lib/samagotchi/tool_activity.rb +63 -79
  69. data/lib/samagotchi/tool_names.rb +179 -0
  70. data/lib/samagotchi/tool_view.rb +3 -5
  71. data/lib/samagotchi/tools/ask_user_question.rb +2 -1
  72. data/lib/samagotchi/tools/builtins.rb +1 -1
  73. data/lib/samagotchi/tools/cancel_reminder.rb +2 -1
  74. data/lib/samagotchi/tools/cancel_schedule.rb +3 -1
  75. data/lib/samagotchi/tools/context_read.rb +2 -1
  76. data/lib/samagotchi/tools/delegate.rb +2 -1
  77. data/lib/samagotchi/tools/delegate_result.rb +2 -1
  78. data/lib/samagotchi/tools/edit.rb +2 -1
  79. data/lib/samagotchi/tools/execute.rb +22 -28
  80. data/lib/samagotchi/tools/forget_outputs.rb +2 -1
  81. data/lib/samagotchi/tools/list_reminders.rb +2 -1
  82. data/lib/samagotchi/tools/list_schedules.rb +3 -1
  83. data/lib/samagotchi/tools/list_sessions.rb +2 -1
  84. data/lib/samagotchi/tools/memory.rb +3 -2
  85. data/lib/samagotchi/tools/objectives_tool.rb +5 -4
  86. data/lib/samagotchi/tools/read.rb +2 -1
  87. data/lib/samagotchi/tools/register_reminder.rb +2 -1
  88. data/lib/samagotchi/tools/schedule_task.rb +3 -1
  89. data/lib/samagotchi/tools/send_note.rb +2 -1
  90. data/lib/samagotchi/tools/task_create.rb +2 -1
  91. data/lib/samagotchi/tools/task_get.rb +2 -1
  92. data/lib/samagotchi/tools/task_list.rb +2 -1
  93. data/lib/samagotchi/tools/task_runtime.rb +29 -154
  94. data/lib/samagotchi/tools/task_stop.rb +2 -1
  95. data/lib/samagotchi/tools/task_wait.rb +3 -2
  96. data/lib/samagotchi/tools/web_fetch.rb +2 -1
  97. data/lib/samagotchi/tools/write.rb +2 -1
  98. data/lib/samagotchi/turn_checkpoint.rb +1 -1
  99. data/lib/samagotchi/version.rb +1 -1
  100. data/lib/samagotchi/web/app.rb +45 -37
  101. data/lib/samagotchi/web/message_display.rb +1 -7
  102. data/lib/samagotchi/web/participant_access.rb +12 -4
  103. data/lib/samagotchi/web/participant_history.rb +68 -0
  104. data/lib/samagotchi/web/participant_images.rb +2 -1
  105. data/lib/samagotchi/web/participant_show.rb +5 -5
  106. data/lib/samagotchi/web/participants_admin.rb +1 -1
  107. data/lib/samagotchi/web/public/app.js +24 -12
  108. data/lib/samagotchi/web/public/card_registry.js +248 -0
  109. data/lib/samagotchi/web/public/cards_offscreen.js +3 -3
  110. data/lib/samagotchi/web/public/cards_place.js +8 -2
  111. data/lib/samagotchi/web/public/chains.js +3 -3
  112. data/lib/samagotchi/web/public/data.js +12 -0
  113. data/lib/samagotchi/web/public/delete_sheet.js +344 -0
  114. data/lib/samagotchi/web/public/format.js +1 -1
  115. data/lib/samagotchi/web/public/history_shape.js +1 -2
  116. data/lib/samagotchi/web/public/index.html +27 -0
  117. data/lib/samagotchi/web/public/info_bar.js +3 -2
  118. data/lib/samagotchi/web/public/lists_view.js +2 -2
  119. data/lib/samagotchi/web/public/more_sheet.js +42 -5
  120. data/lib/samagotchi/web/public/participant_history.js +27 -0
  121. data/lib/samagotchi/web/public/question_cards.js +1 -15
  122. data/lib/samagotchi/web/public/reload_check.js +90 -72
  123. data/lib/samagotchi/web/public/session_actions.js +50 -6
  124. data/lib/samagotchi/web/public/session_view.js +6 -1
  125. data/lib/samagotchi/web/public/stage_asking.js +6 -20
  126. data/lib/samagotchi/web/public/stage_view.js +2 -2
  127. data/lib/samagotchi/web/public/stage_waiting.js +4 -10
  128. data/lib/samagotchi/web/public/task_stop.js +1 -1
  129. data/lib/samagotchi/web/push_routes.rb +1 -1
  130. data/lib/samagotchi/web/reload_check_route.rb +5 -2
  131. data/lib/samagotchi/web/request_body.rb +72 -0
  132. data/lib/samagotchi/web/server.rb +70 -0
  133. data/lib/samagotchi/web/session_access_routes.rb +13 -11
  134. data/lib/samagotchi/web/session_control.rb +79 -20
  135. data/lib/samagotchi/web/session_create.rb +2 -1
  136. data/lib/samagotchi/web/session_show.rb +8 -8
  137. data/lib/samagotchi/web/viewer.rb +7 -2
  138. data/lib/samagotchi/web/working_set_routes.rb +3 -3
  139. data/lib/samagotchi/worker.rb +49 -182
  140. data/lib/samagotchi/worker_exit_claim.rb +102 -0
  141. data/lib/samagotchi/worker_participant_gate.rb +156 -0
  142. data/lib/samagotchi/worker_task_wakes.rb +2 -2
  143. metadata +17 -1
@@ -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; it compares the turn's own cards and questions, dropping every entry CardStore attributes to another turn), `cards_offscreen.js` (the reload check's placer: `createCardsPlace`, `createBubbles` and `createQuestionCards` over a detached holder, every page hook inert - no stage, no scroll, no session id, no api, no storage - so a snapshot's cards land where a reload would put them without touching the page), `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), `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`, `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
 
@@ -54,6 +54,7 @@ their viewer (The viewer, below), their show and stream are filtered (`Web::Part
54
54
  | **Factory closures**: the `create*` factories (popovers, panels, views) | each component's own state: open-for, busy, error, its own fetched list | the factory | an `onChange` hook back into app.js, or a getter the factory reads at draw time |
55
55
  | **The history DOM** | the conversation as drawn (a running turn's reason bubble, `.bubble.said`, is live only: see A turn opened in the history): which turn a bubble belongs to (`data-turn-id`, `data-answer-turn`), what opens a turn (`TURN_PROMPT`, `bubbles.js`: a prompt or a wake's note, the same turns `Steer.turn_opening?` counts for a card's `turns_since`), an opening's id for a card's and the saved recap's stamp (`data-turn-id` on a prompt, `data-opening-id` on a wake's note or `/continue no`'s reason line; `card_stamps.js` places a snapshot's card after the stamped opening, `recap_stamp.js` the saved recap after the last turn it covers, each by its count (`turns_since`) only without one), kept command bubbles, which texts were shown, unnamed badges, folded answers and long prompts (`.folded`), Revise stamps (`data-revises` on a prompt; a Verify turn's `data-verify`) and the stacks' folded versions (`.stack-hidden`, `.stack-stub.open`); the switcher's version on view is `revise_stack.js`'s own (a copy `.stack-view` before the top answer, the top `.stack-swapped`; never stored) | `bubbles.js`, `cards_place.js`, `question_cards.js`, `turn_block.js`/`stage_view.js`, `answer_fold.js`, `revise_stack.js`, `stream_handlers.js` (a live `turn_completed`'s `revises` and `verify` onto its prompt) | read back as state: `turn_range.js turnElements` (one walker for a turn's elements), `keptCommandBubbles`, `seedSeenFromDom`, `nameUnnamedBadges`/`nameVerdictCards`, `answer_fold.js` and `revise_stack.js` (their observers decorate every path that fills `#history`; the stacks are `stacks()` of the stamps, read again on each change, never a store field), `history_reveal.js revealInHistory` (the one way a jump unfolds what hides its target) |
56
56
  | **A drawn turn** (`turn_drawings` of the full read) | every finished turn, as live drew it: `turnGroups` groups by the stamps only, a turn's stamped items (`drawn: <turn_id>`) one group, and `turnHistoryNodes` draws it by feeding its drawing's events to a live turn block offscreen (`turn_block.js drawnTurnNodes`: the block's own handlers, as the stage's), the stage's extras (a reminder, merged lines, a card that asks or warns) and end as live, then the answer, the merged lines and the steps' texts from their saved items (markdown, refs). Each of its top-level elements carries `data-drawn`: `cards_place.js` leaves that turn's in-turn CardStore entries (`of_turn`) to it, and a kept reminder bubble of that turn (`data-turn-id`) stays out after a resync. chi web sends a drawing for every finished turn (one made from its messages where live wrote none): `drawnGroup` pairs the record the end names (`end.record_id`, by place for a turn saved before turn ids), else by the turn's id, and the answer's `data-answer-turn` is the end's own `turn_id` only (a made-up id, `m…` or `…~N`, keys none: no Revise). Nothing is rebuilt from messages: an item that comes unstamped is a `plain` group drawn as a plain row of its text (its prompt or answer bubble, no steps), the running turn's as expected (`runningTurnId`, the show's `current_turn`: it has no line yet), any other a miss, marked `data-undrawn`, logged once per render (`console.warn`) and counted by the reload check (`undrawn`), never a throw; a drawing with no parts (a minimal line) draws its prompt, answer and end | chi web (the show) | `renderHistory`, the reload check's render |
57
+ | **The cards as data** (`card_registry.js`; app.js `cardRegistry`) | every question, continue offer and plugin card of the open session, keyed as `stage_waiting.js` keys them (`q:<id>`, `c:<id>`, `continue`): its kind and folded text (`card_kinds.js`), status (pending, answered, cancelled; resolved or dropped for the continue offer; asks or shown for a plugin card), `of_turn`, `opening_id`, step, `relayed_to` | `observeCards` around the stream handlers (outside the participant wrap: the page's handler first, then `apply`), so a read's replay feeds it too; `session_view.js renderSessionView` seeds it from the read right before the replay (`seed`: CardStore's listing, the pending question, the continue offer; it replaces), `forgetSession` resets it. Idempotent: a merge per key, a final status never back to pending, the first `of_turn`/`opening_id`/step kept, so seed then replay is what live holds. A question still pending at its turn's end is cancelled (the page cancels the card, no event comes) | an observer: nothing on the page draws from it; its one reader is the opt-in reload check (`reload_check.js`: this turn's entries against a registry seeded from a fresh read). `stage_cuts_parity.test.js` checks it against the stage's waiting cards at each cut, `card_registry.test.js` the events against each cut's seed and replay |
57
58
  | **localStorage** (`storage.js` `readStored`/`writeStored`, guarded) | per-browser choices only | the module that owns the choice | read at start (see Storage keys) |
58
59
  | **SSE** | see Streams | the server | events go into the DOM directly (a participant's through `participant_main.js wrapHandlers` first) |
59
60
 
@@ -246,7 +247,10 @@ gates are boot-time: a show's narrower `viewer` changes what `viewer.can` answer
246
247
  A participant's `can` (`Viewer::PARTICIPANT_CAPABILITIES`, in their show's `viewer` and on `<body>`) names
247
248
  capabilities of their own, not the owner's: `send` (the composer), `stop_own_turn` (Stop turn on a turn they
248
249
  started, `POST …/cancel` with its `turn_id`), `steer_own_turn` (a message during their own turn goes in at its next
249
- step, on a worker with `participant_steer`), `revise_own_turn` (Revise on the answer to their own message); and of the owner's only `working_set` and `images`, which their routes
250
+ step, on a worker with `participant_steer`), `revise_own_turn` (Revise on the answer to their own message),
251
+ `own_prompt_history` (↑/↓ over their own messages in this session, redacted: `GET …/prompt_history` through
252
+ `participant_history.js historyLoader`, never the owner's `/api/history`; the delivery line's "↑ history" hint takes
253
+ either); and of the owner's only `working_set` and `images`, which their routes
250
254
  serve filtered: the working set's project files ([participants.md](participants.md#the-main-pages-show)); their own
251
255
  uploads within their cap and quota, read back only by them ([participants.md](participants.md#participant-images)).
252
256
  Their messages carry their own images as refs (thumbnails) and anyone else's as a count, which `images.js
@@ -352,7 +356,8 @@ hides an empty group with its hairline. **A new chip needs a `BAR_ITEMS` entry a
352
356
 
353
357
  ⋯'s menu (`more_sheet.js`) is a popover above 600 px and a bottom sheet under it (`chip_popover.js`, `SHEET_MAX`; its
354
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,
355
- ⚙ 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
356
361
  telemetry line (none: no line), archive and delete always, continue and stop when folded. Its dot (`moreAttention`)
357
362
  and its count (`moreCount`, a desktop's, none at 0; archive and delete don't count) are from folded items alone: a chip
358
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
@@ -361,6 +366,26 @@ placed at, so `chip_popover.js` places it, marks `aria-expanded` and gives focus
361
366
  `[data-anchor-stand-in]` (⋯). Rows and actions draw into fixed slots, so a row that joins keeps the focus where it was.
362
367
  The e2e reach an item wherever it is with `spec/e2e/support/layout.js` `clickBarItem` (the row, else ⋯'s `[data-row]`).
363
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
+
364
389
 
365
390
  ## Safe areas
366
391
 
@@ -496,10 +521,11 @@ place that still waits (check-in's new title) patches its entry after those sett
496
521
  and summary, its order and docking kept; arrived again, not docked, as a warning or when its actions came back; with
497
522
  an older `stage_waiting.js` that has no `update`, an arrive in place), `turnEnded` the warn cards
498
523
  that leave, `session_view.js endTurnView`'s cancel of a question still pending goes through `onSettled`, and
499
- `emptySlots` resets it (a resync's and `workerGone`'s reset too). `stage_asking.js reconcileWaiting` settles nothing:
500
- a debug check at the end of `refresh`, on only with the perf probe or `<body data-stage-check="1">` (the e2e and the
501
- node tests), that warns "stage: waiting drift" for an entry whose card is gone or waits no more, or a waiting card
502
- with no entry.
524
+ `emptySlots` resets it (a resync's and `workerGone`'s reset too). Nothing on the page reads the slots back against
525
+ it: the tests do (`stage_cuts_parity.test.js`, after every event and at each cut: no entry without its waiting card in
526
+ the extras or the tail, no waiting card there without its entry; the e2e's stage check at each test's end, reading the
527
+ registry off the stage's node, `#turnStage.chiWaiting()`). `stage_asking.js reconcileWaiting` is a no-op kept one
528
+ release for a stale `stage_view.js` that still calls it.
503
529
  The registry's order is the stage's: blocking cards before the asking ones, arrival order within each, and `place`
504
530
  puts a blocking card before check-in's in the slot, so a live page and a reload agree whatever the replay's order. The
505
531
  asking form's card is the shown docked entry, the fold is the folded key (`stageCollapsed` compares keys); `opener`'s
data/docs/plugins.md CHANGED
@@ -1458,7 +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::Tools::TaskRuntime::TASKS_DIR` and `EXIT_CODE_FILENAME`.
1461
+ 5. `Samagotchi::TaskFiles::TASKS_DIR` and `EXIT_CODE_FILENAME` (require `samagotchi/task_files`).
1462
1462
  6. `Samagotchi::AtomicFile.write`, `Samagotchi::Log.warn` /
1463
1463
  `Samagotchi::Log.debug`, `Samagotchi::Config.get`,
1464
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
@@ -41,9 +41,9 @@ A new session field is one `Session::FIELDS` row, plus a `SessionSetup` member w
41
41
 
42
42
  **A worker killed mid-turn:** while a turn runs, its worker keeps it on disk (`TurnCheckpoint`): the session file has the turn so far (the prompt from the turn's start, then the finished tool steps and lines merged into it) and `interrupted_turn: {id, started_at, at, iteration, enqueued_id}` (`enqueued_id`: the input the turn runs, so any process can tell which turn is running; a continue turn carries its offer turn's), written as the turn starts, at the loop's first iteration boundary and then at most every 10 s (`updated_at` moves with it). The turn's end saves the real messages without the mark. A worker that died without ending its turn (SIGKILL, a crash of the process) leaves the mark, and loses what came after its last written boundary: at most the last 10 s of steps, plus the step in flight. Each checkpoint write also saves the turn's metrics so far to `analytics.json` (tokens, speeds, timings, its finished tool calls), as the record a killed turn leaves: canceled, `cancellation_reason: worker_stopped`; the turn's own end writes over it. The next worker to start for the session (a `chi send`, `--resume`, `--attach`, the web), or a `chi --resume ID -p TEXT --non-interactive` run, settles the turn before anything else (`TurnCheckpoint.settle`, log `interrupted_turn_settled`): a note `the previous turn was cancelled (worker-stopped) after Ns` goes at the tail, the status goes idle and the mark goes; `last_turn` stays the previous turn's (a new one saved before the turn a `chi send --wait` woke the worker for would end that wait at once); the dead turn's end is recorded under its `enqueued_id` instead, in `<id>/input/settled/<enqueued_id>` (a `last_turn` record: canceled, `cancel_reason: worker_stopped`), which only a wait for that very turn reads (`chi send --queue --wait`, a `chi send --wait -m` to an idle session or `--new`, `chi send --wait ID --turn`, a continue's wait): it ends `canceled` with `cancel_reason: worker_stopped`, detail "its worker exited mid-turn", instead of timing out. A wake or reminder turn's settle is recorded under its worker-minted `wake-…` id the same way, and a message merged into a turn as a steer follows that turn's id (`input/merged/`). A wait with no turn id that saw the turn running ends the same way when the settle comes (`chi send --wait ID` with no message on a turn with no id, such as a 0.156 worker's reminder turn), unless an input still waits or was claimed since: an unmerged message runs as its own turn next, and that turn's end is the answer. A reply the turn wrote before its worker died is still its answer. The session shows the turn's prompt and steps with that note; the dead turn is not run again, and the model reads on its next turn that it was cut.
43
43
 
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` (`SessionCommands.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.
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
 
@@ -493,7 +495,7 @@ mise.toml pins Ruby 3.4 gets that `ruby`, `gem` and `bundle` in its tools while
493
495
  `.config/mise/`, `mise/`, `.mise/`) are secrets to them, as `.env` is.
494
496
  - **What tools still drop**: every `execute`, task, `!cmd`, context source and MCP server takes no `RUBYOPT`, `RUBYLIB`, or what `bundle exec` sets
495
497
  (`BUNDLE_GEMFILE`, `BUNDLE_LOCKFILE`, `BUNDLE_BIN_PATH`, `BUNDLER_VERSION`, `BUNDLER_SETUP`: `BundlerEnv`) from the project's mise env: it runs without `RUBYLIB` and Bundler's
496
- variables, and with the worker's own `RUBYOPT`, Bundler's part removed (`TaskRuntime`).
498
+ variables, and with the worker's own `RUBYOPT`, Bundler's part removed (`SpawnEnv`).
497
499
  - **`chi` in a tool** stays the home's: with a chi home the tools' PATH starts with `$XDG_STATE_HOME/samagotchi/bin`,
498
500
  a dir holding only a `chi` script that boots the home (rewritten at each worker start when the home changed; it
499
501
  unsets `RUBYOPT`, `RUBYLIB`, `RUBYGEMS_GEMDEPS`, `GEMRC` and `BUNDLE*` before it runs, so a `bundle exec` around it
data/docs/testing.md CHANGED
@@ -231,16 +231,21 @@ Each level owns its own share; a detail is asserted once, at the lowest level th
231
231
  A turn cut mid-way while a card waits is `stage_cuts_parity.test.js`'s: the scenarios in `spec/shared/stage_cuts/`
232
232
  (written from `spec/support/stage_cut_scenarios.rb` by `spec/web/session_show_cuts_spec.rb`, which folds the events
233
233
  to each cut into a worker's snapshot and sends it through `Web::SessionShow`; `UPDATE_STAGE_CUTS=1` rewrites them)
234
- are drawn live to the cut (question cards included) and reloaded from the cut's show, and the stage (`stageShape`:
234
+ are drawn live to the cut (question cards included; a turn-end cut, which each scenario has, after the stage's
235
+ hand-off: where a finished turn's questions land and the reply they keep) and reloaded from the cut's show, and the stage (`stageShape`:
235
236
  its cards, the docked ones, the lead-in bubbles, the card in front, the one that shows and the pager, the fold) and
236
237
  the history compared; a known difference is listed in its `EXPECTED`, by scenario, cut and field (one gone fails
237
- too; none today), and on both pages `stage_waiting.js`'s cards agree with the slots, one docked card showing. `STAGE_CUTS_DEBUG=1` prints each cut's differences. Both
238
- harnesses build their page with `spec/web/public/live_page.js`. The stage's drift check (`<body
239
- data-stage-check="1">`, `stage_asking.js reconcileWaiting`) and the data-vs-node cross-check (`card_kinds.js
240
- warnDiffers`) warn "stage: waiting …": `spec/web/public/waiting_warnings.js` (`failOnWaitingWarnings`, called by
241
- `stage_view.test.js` and `stage_cuts_parity.test.js`; under `npm test`'s one process it covers the files loaded
242
- after them too) turns the check on and fails a test that warned, and `stage.spec.js` does the same in the browser
243
- (`test.use({ stageCheck: true })`, a fixture in `spec/e2e/support/fixtures.js`).
238
+ too; one today: `checkin_approval/turn end`, where a reload can't tell when a card stopped asking), and on both pages `stage_waiting.js`'s cards agree with the slots, one docked card showing. `STAGE_CUTS_DEBUG=1` prints each cut's differences. The cuts also
239
+ feed `card_registry.test.js` (every cut: its events against its show seeded and replayed) and
240
+ `reload_check.test.js` (the turn-end cuts: the opt-in reload check, live against the read, says same). Both
241
+ harnesses build their page with `spec/web/public/live_page.js`. The stage's drift check (the
242
+ registry against the slots: no entry without its waiting card, no waiting card without its entry) is the tests' own:
243
+ `stage_cuts_parity.test.js` runs it after every live event and at each cut, and `stage.spec.js` at each test's end
244
+ (`test.use({ stageCheck: true })`, a fixture in `spec/e2e/support/fixtures.js`, reading the registry off
245
+ `#turnStage.chiWaiting()`). The data-vs-node cross-check (`card_kinds.js warnDiffers`) warns "stage: waiting …":
246
+ `spec/web/public/waiting_warnings.js` (`failOnWaitingWarnings`, called by `stage_view.test.js` and
247
+ `stage_cuts_parity.test.js`; under `npm test`'s one process it covers the files loaded after them too) fails a test
248
+ that warned, and the e2e's stage check fails on such a console warning too.
244
249
  `spec/shared/turn_ranges.json` (`UPDATE_TURN_RANGES=1 bundle exec rspec spec/bridge/turn_ranges_spec.rb`) pins
245
250
  `Bridge::TurnRanges`' turns, their record pairing, the items as the show stamps them and each turn's drawing end;
246
251
  timing.test.js checks `turnGroups` (stamps only) against it. Each scenario's
@@ -329,6 +334,12 @@ One lib cop sits beside them: `Samagotchi/SilentRescue` (a `rescue` of StandardE
329
334
  `nil`, `[]`…: use `Degrade`, or tag a right silence `# degrade-ok: why`; docs/internals/engine.md, Degrading). The
330
335
  files that had such rescues when it came are excluded in `.rubocop.yml`: that list only shrinks.
331
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
+
332
343
  ### Flakes
333
344
 
334
345
  When `parallel_rspec` fails in CI's `rspec` or `rspec-macos` job, the next step (`script/rerun_failures.rb`) reruns
@@ -553,14 +564,17 @@ real tasks under each strategy (needs a model; costs tokens): [internals/llm-con
553
564
  ## The stage perf probe
554
565
 
555
566
  `script/stage-perf-probe` (`PROBE_MACHINE=<label>` names the machine; `--keep` leaves its folder, `--headed` shows
556
- the browser) times the web page's stage on a big session: `script/stage_perf_probe/session.rb` writes 300 finished
567
+ the browser, `--reload-check` turns `web.reload_check` on: `reload:compare` times the check's compare, `reload:posted`
568
+ the hand-off to its post, and the posted counts are printed) times the web page's stage on a big session: `script/stage_perf_probe/session.rb` writes 300 finished
557
569
  turns with 60 plugin cards and 40 answered questions through chi's own writers (TurnAccumulator's drawings, CardStore,
558
570
  `Session#save`; CardStore keeps its cap of 20, the rest are in the drawings), then `probe.js` opens it in chi web
559
571
  (the e2e fake model, isolated `HOME` and `XDG_*` under `tmp/stage-probe-*`) at `/?stage_probe=1` (`stage_probe.js`:
560
572
  the flag is kept for the tab in sessionStorage, `chi_stage_probe`, so a reload or a hash jump keeps it;
561
573
  `?stage_probe=0` drops it; `<body data-stage-probe="1">` works too, for that page only), runs one turn that asks a question and an approval, reloads while the question waits and answers
562
574
  both. It prints JSON: `stage:refresh` n/p50/p95/max (ms), the session's open (the hash to the last answer drawn),
563
- tap→settled per card, reload→card drawn and the JS heap after a GC before the open, after it and after the turn. Its
575
+ tap→settled per card, reload→card drawn, the JS heap after a GC before the open, after it and after the turn, and the
576
+ cards as data (`card_registry.js`): `cards:apply` per card event, `cards:seed` per read, and the registry's entries and
577
+ JSON bytes after the open and after the turn (`globalThis.chiCardRegistry`, only while probing). Its
564
578
  `session.drawn` counts what the open drew: all 300 answers and 60 cards, but only the answered questions CardStore
565
579
  still lists (8: its cap keeps the newest 20 cards and questions together, and a finished turn's question is drawn from
566
580
  that list alone). Bounded:
@@ -661,3 +675,11 @@ names from elsewhere checked), one-off host pairs (`ToolRun` in `tool_response.r
661
675
  autoloads that load whole (`SessionManager`, `Objectives`, `Config`), and `Plugin::Http`'s (its base file
662
676
  loads the reopening file only inside a method, and that file requires the base file first). The summary counts the entries that
663
677
  matched and those that match nothing: delete a stale one.
678
+
679
+ **The thin client load budgets.** `spec/require_cycle_spec.rb` loads the attached TUI's files
680
+ (`terminal_ui/attach_launcher`, `attached_loop`) and chi web's (`web/app`) in a fresh ruby and fails when either
681
+ loads the turn loop (`kernel_loop`), the bundle updater (`memory_bundle/shipped_update`), or a tool that runs:
682
+ `tools/execute`, `tools/builtins`, `tools/task_runtime`. A client that needs a tool's name or result text reads
683
+ `ToolNames`; one that needs a session command's name or the built-ins' registry reads `SessionCommandCatalog`;
684
+ task files and transcripts are `TaskFiles` and `TaskTranscript`. A require that breaks a budget is a sign the
685
+ reader wants one of those, not the class.
@@ -42,6 +42,7 @@ require_relative "worker_link"
42
42
  require_relative "relay_verifier"
43
43
  require_relative "relay_watcher"
44
44
  require_relative "reply_wait"
45
+ require_relative "task_transcript"
45
46
  require_relative "tools/task_runtime"
46
47
 
47
48
  module Samagotchi
@@ -929,9 +930,9 @@ module Samagotchi
929
930
  # "task_id:" line of its own).
930
931
  def own_task_ids
931
932
  running = Array(@accumulator.current_turn&.dig(:parts)).filter_map do |part|
932
- Tools::TaskRuntime.created_id(part[:tool], part[:output]) if part[:kind] == "tool"
933
+ TaskTranscript.created_id(part[:tool], part[:output]) if part[:kind] == "tool"
933
934
  end
934
- Tools::TaskRuntime.created_ids_in(@engine.messages_checkpoint) | running
935
+ TaskTranscript.created_ids_in(@engine.messages_checkpoint) | running
935
936
  end
936
937
 
937
938
  # Answer the pending question. A past +deadline+ (see #handle_post_turn):
@@ -1076,7 +1077,7 @@ module Samagotchi
1076
1077
  # The Engine's own commands: the built-ins and its plugins' (a card's
1077
1078
  # action is a plugin command line).
1078
1079
  unless command_registry.command?(line)
1079
- 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
1080
1081
  detail = "not a session command: #{line[0, 80]} (known: #{known.join(", ")}; /help lists them)"
1081
1082
  return [{ "Allow" => "POST" }, 400, { error: "unknown_command", detail: detail }]
1082
1083
  end
@@ -17,7 +17,7 @@ require_relative "../../sandbox_layout"
17
17
  require_relative "../../session"
18
18
  require_relative "../../session_manager"
19
19
  require_relative "../../tools/task_record"
20
- require_relative "../../tools/task_runtime"
20
+ require_relative "../../task_files"
21
21
 
22
22
  module Samagotchi
23
23
  class BundleCommand
@@ -194,7 +194,7 @@ module Samagotchi
194
194
  end
195
195
 
196
196
  def leftover_tasks
197
- pattern = File.join(work_dir, Tools::TaskRuntime::TASKS_DIR, "*", Tools::TaskRuntime::METADATA_FILENAME)
197
+ pattern = File.join(work_dir, TaskFiles::TASKS_DIR, "*", TaskFiles::METADATA_FILENAME)
198
198
  Dir.glob(pattern).filter_map do |file|
199
199
  record = Tools::TaskRecord.from_file(JSON.parse(File.read(file)))
200
200
  record.pid if record&.running? && same_process?(record)
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: core
3
- version: 0.4.3
3
+ version: 0.4.4
4
4
  scope: system
5
5
  description: "Recommended safety set"
6
6
  trust_level: reviewed
7
7
  # Its members' highest floor (work-cap's: ctx.usage, raised at the release)
8
- requires_chi: ">= 0.144.0"
8
+ requires_chi: ">= 0.173.0"
9
9
  includes:
10
10
  - loop-guard
11
11
  - check-in
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  name: slow-commands
3
- version: 0.2.5
3
+ version: 0.2.6
4
4
  scope: system
5
5
  description: "Remembers commands that ran past the execute limit in a project; the next identical execute is denied once a turn with advice to run it with task_create and task_wait; /slow-commands lists and forgets them"
6
6
  trust_level: reviewed
7
7
  plugin:
8
8
  file: plugin.rb
9
- sha256: sha256:e51c099c1552bd0cd1fe46e4fd235a3fe8340693e6ca338eb7ed09d8398a6f0f
9
+ sha256: sha256:255bd833b7012f5e6d4597b97e9510f91da61eef13539ba4de2c0baece44964e
10
10
  # Execute::HANDED_OVER, read when the plugin loads (0.59.0); after_tool_call's
11
11
  # call:, elapsed_ms: and result: (0.57.0)
12
- requires_chi: ">= 0.143.0"
12
+ requires_chi: ">= 0.173.0"
13
13
  # config.yml bundles: slow-commands: (another key warns; an older chi ignores this)
14
14
  settings: [mode, warn_ratio, ttl_days]
@@ -67,7 +67,7 @@ require "samagotchi/atomic_file"
67
67
  require "samagotchi/config"
68
68
  require "samagotchi/guardrails/shell_lex"
69
69
  require "samagotchi/tools/execute"
70
- require "samagotchi/tools/task_runtime"
70
+ require "samagotchi/task_files"
71
71
 
72
72
  class Plugin
73
73
  SOURCE = "bundle slow-commands"
@@ -406,7 +406,7 @@ class Plugin
406
406
  def task_duration(ctx, key)
407
407
  roots = [ctx.cwd, project_of(ctx)].uniq
408
408
  records = roots.flat_map do |root|
409
- Dir.glob(File.join(root, Samagotchi::Tools::TaskRuntime::TASKS_DIR, "*", "task.json"))
409
+ Dir.glob(File.join(root, Samagotchi::TaskFiles::TASKS_DIR, "*", "task.json"))
410
410
  end.uniq
411
411
  found = records.filter_map { |path| finished_task(path, ctx, key) }
412
412
  found.max_by(&:first)&.last
@@ -416,7 +416,7 @@ class Plugin
416
416
  def finished_task(path, ctx, key)
417
417
  record = JSON.parse(File.read(path))
418
418
  exit_code = record["exit_code_path"].to_s
419
- exit_code = File.join(File.dirname(path), Samagotchi::Tools::TaskRuntime::EXIT_CODE_FILENAME) unless File.absolute_path?(exit_code)
419
+ exit_code = File.join(File.dirname(path), Samagotchi::TaskFiles::EXIT_CODE_FILENAME) unless File.absolute_path?(exit_code)
420
420
  return nil unless File.file?(exit_code) && File.read(exit_code).strip == "0"
421
421
 
422
422
  command = self.class.normalize(record["command"], cwd: record["cwd"], project: key[0], base: ctx.cwd)
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: samagotchi-system
3
- version: 0.172.1
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
@@ -23,7 +23,7 @@ module Samagotchi
23
23
  # Whether a participant's pair turn must stop, read before each of its
24
24
  # generations (#guard_participant_spend): author ("p:<id>") → why (their
25
25
  # link ended, or they passed their cap), nil while it may go on. The
26
- # Worker sets it (Worker#participant_turn_stop); without one (a one-shot)
26
+ # Worker sets it (WorkerParticipantGate#turn_stop); without one (a one-shot)
27
27
  # nothing is checked mid-turn.
28
28
  attr_writer :participant_stop
29
29
 
@@ -34,7 +34,7 @@ module Samagotchi
34
34
  # plugins' stop path (cost-cap's, work-cap's), with its notice. A
35
35
  # generation's own cost is known only once it ends, so a turn can pass
36
36
  # the cap by its last generation. The turn-start check is the Worker's
37
- # (Worker#participant_refusal).
37
+ # (WorkerParticipantGate#refusal).
38
38
  # @param context [TurnContext] the running turn's (the loop's)
39
39
  def guard_participant_spend(context)
40
40
  author = context&.author
@@ -29,7 +29,6 @@ require_relative "context_window"
29
29
  require_relative "kernel_loop"
30
30
  require_relative "reprefill_meter"
31
31
  require_relative "tools/builtins"
32
- require_relative "tools/task_runtime"
33
32
  require_relative "tools/tool_index"
34
33
  require_relative "tools/tool_surface"
35
34
  require_relative "peer_sources"
@@ -369,7 +368,7 @@ module Samagotchi
369
368
  task_finish_notes: task_finish_notes)
370
369
  restrict_scratch_tools! if @scratch
371
370
  # Likewise the slash commands its SessionCommands run.
372
- @command_registry = SessionCommands.register_builtins(Commands::Registry.new)
371
+ @command_registry = SessionCommandCatalog.register_builtins(Commands::Registry.new)
373
372
  # Installed bundles' plugins add commands, tools and hooks to these
374
373
  # (docs/plugins.md); one that fails is announced with the load
375
374
  # failures, and the rest still load.