samagotchi 0.172.0 → 0.173.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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -1
  3. data/docs/architecture.md +16 -5
  4. data/docs/cli.md +2 -1
  5. data/docs/configuration.md +1 -1
  6. data/docs/internals/background-tasks.md +20 -7
  7. data/docs/internals/bridge.md +2 -2
  8. data/docs/internals/engine.md +2 -1
  9. data/docs/internals/participants.md +67 -9
  10. data/docs/internals/remote-sessions.md +1 -1
  11. data/docs/internals/web-frontend.md +44 -15
  12. data/docs/plugins.md +3 -1
  13. data/docs/sessions.md +2 -2
  14. data/docs/testing.md +43 -3
  15. data/lib/samagotchi/bridge.rb +3 -2
  16. data/lib/samagotchi/bundle_command/try/sandbox.rb +2 -2
  17. data/lib/samagotchi/bundles/core/manifest.yml +2 -2
  18. data/lib/samagotchi/bundles/slow-commands/manifest.yml +3 -3
  19. data/lib/samagotchi/bundles/slow-commands/plugin.rb +3 -3
  20. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  21. data/lib/samagotchi/engine/participants.rb +2 -2
  22. data/lib/samagotchi/engine.rb +0 -1
  23. data/lib/samagotchi/file_ref.rb +3 -5
  24. data/lib/samagotchi/guardrails/participant_refusal.rb +1 -1
  25. data/lib/samagotchi/memory_usage.rb +2 -1
  26. data/lib/samagotchi/message_parts.rb +5 -3
  27. data/lib/samagotchi/objectives_backing.rb +6 -10
  28. data/lib/samagotchi/parent_report.rb +1 -1
  29. data/lib/samagotchi/participant_prompts.rb +101 -0
  30. data/lib/samagotchi/participant_turn_mode.rb +1 -1
  31. data/lib/samagotchi/project_env.rb +7 -5
  32. data/lib/samagotchi/prompt_history.rb +2 -2
  33. data/lib/samagotchi/send_command/parent_gate.rb +2 -2
  34. data/lib/samagotchi/send_command.rb +4 -4
  35. data/lib/samagotchi/session_command_catalog.rb +210 -0
  36. data/lib/samagotchi/session_commands.rb +12 -183
  37. data/lib/samagotchi/session_manager/lifecycle.rb +5 -4
  38. data/lib/samagotchi/session_manager.rb +2 -1
  39. data/lib/samagotchi/session_stores.rb +2 -0
  40. data/lib/samagotchi/spawn_env.rb +75 -0
  41. data/lib/samagotchi/task_files.rb +51 -0
  42. data/lib/samagotchi/task_transcript.rb +67 -0
  43. data/lib/samagotchi/task_watch.rb +8 -6
  44. data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +3 -3
  45. data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -2
  46. data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
  47. data/lib/samagotchi/terminal_ui/input_support.rb +1 -1
  48. data/lib/samagotchi/testing/boundary.rb +5 -0
  49. data/lib/samagotchi/tool_activity.rb +63 -79
  50. data/lib/samagotchi/tool_names.rb +179 -0
  51. data/lib/samagotchi/tool_view.rb +3 -5
  52. data/lib/samagotchi/tools/ask_user_question.rb +2 -1
  53. data/lib/samagotchi/tools/builtins.rb +1 -1
  54. data/lib/samagotchi/tools/cancel_reminder.rb +2 -1
  55. data/lib/samagotchi/tools/cancel_schedule.rb +3 -1
  56. data/lib/samagotchi/tools/context_read.rb +2 -1
  57. data/lib/samagotchi/tools/delegate.rb +2 -1
  58. data/lib/samagotchi/tools/delegate_result.rb +2 -1
  59. data/lib/samagotchi/tools/edit.rb +2 -1
  60. data/lib/samagotchi/tools/execute.rb +22 -28
  61. data/lib/samagotchi/tools/forget_outputs.rb +2 -1
  62. data/lib/samagotchi/tools/leftovers.rb +8 -4
  63. data/lib/samagotchi/tools/list_reminders.rb +2 -1
  64. data/lib/samagotchi/tools/list_schedules.rb +3 -1
  65. data/lib/samagotchi/tools/list_sessions.rb +2 -1
  66. data/lib/samagotchi/tools/memory.rb +3 -2
  67. data/lib/samagotchi/tools/objectives_tool.rb +5 -4
  68. data/lib/samagotchi/tools/read.rb +2 -1
  69. data/lib/samagotchi/tools/register_reminder.rb +2 -1
  70. data/lib/samagotchi/tools/schedule_task.rb +3 -1
  71. data/lib/samagotchi/tools/send_note.rb +2 -1
  72. data/lib/samagotchi/tools/task_create.rb +2 -1
  73. data/lib/samagotchi/tools/task_get.rb +2 -1
  74. data/lib/samagotchi/tools/task_list.rb +2 -1
  75. data/lib/samagotchi/tools/task_runtime.rb +34 -154
  76. data/lib/samagotchi/tools/task_stop.rb +2 -1
  77. data/lib/samagotchi/tools/task_wait.rb +3 -2
  78. data/lib/samagotchi/tools/web_fetch.rb +2 -1
  79. data/lib/samagotchi/tools/write.rb +2 -1
  80. data/lib/samagotchi/turn_checkpoint.rb +1 -1
  81. data/lib/samagotchi/version.rb +1 -1
  82. data/lib/samagotchi/web/app.rb +38 -36
  83. data/lib/samagotchi/web/message_display.rb +1 -7
  84. data/lib/samagotchi/web/participant_access.rb +12 -4
  85. data/lib/samagotchi/web/participant_history.rb +68 -0
  86. data/lib/samagotchi/web/participant_images.rb +2 -1
  87. data/lib/samagotchi/web/participant_show.rb +5 -5
  88. data/lib/samagotchi/web/participants_admin.rb +1 -1
  89. data/lib/samagotchi/web/public/app.js +13 -10
  90. data/lib/samagotchi/web/public/card_kinds.js +51 -0
  91. data/lib/samagotchi/web/public/card_registry.js +248 -0
  92. data/lib/samagotchi/web/public/cards_offscreen.js +3 -3
  93. data/lib/samagotchi/web/public/cards_place.js +21 -4
  94. data/lib/samagotchi/web/public/history_shape.js +1 -2
  95. data/lib/samagotchi/web/public/participant_history.js +27 -0
  96. data/lib/samagotchi/web/public/question_cards.js +16 -15
  97. data/lib/samagotchi/web/public/reload_check.js +90 -72
  98. data/lib/samagotchi/web/public/session_sync.js +4 -2
  99. data/lib/samagotchi/web/public/session_view.js +6 -1
  100. data/lib/samagotchi/web/public/stage_asking.js +18 -13
  101. data/lib/samagotchi/web/public/stage_place.js +144 -0
  102. data/lib/samagotchi/web/public/stage_probe.js +64 -0
  103. data/lib/samagotchi/web/public/stage_view.js +52 -104
  104. data/lib/samagotchi/web/public/stage_waiting.js +28 -17
  105. data/lib/samagotchi/web/public/task_stop.js +1 -1
  106. data/lib/samagotchi/web/push_routes.rb +1 -1
  107. data/lib/samagotchi/web/reload_check_route.rb +5 -2
  108. data/lib/samagotchi/web/request_body.rb +72 -0
  109. data/lib/samagotchi/web/server.rb +70 -0
  110. data/lib/samagotchi/web/session_access_routes.rb +13 -11
  111. data/lib/samagotchi/web/session_control.rb +21 -15
  112. data/lib/samagotchi/web/session_create.rb +2 -1
  113. data/lib/samagotchi/web/session_show.rb +8 -8
  114. data/lib/samagotchi/web/viewer.rb +7 -2
  115. data/lib/samagotchi/web/working_set_routes.rb +3 -3
  116. data/lib/samagotchi/worker.rb +49 -182
  117. data/lib/samagotchi/worker_exit_claim.rb +102 -0
  118. data/lib/samagotchi/worker_participant_gate.rb +156 -0
  119. data/lib/samagotchi/worker_task_wakes.rb +2 -2
  120. metadata +16 -1
@@ -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` (the stage's features: below, The stage's modules), `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`, `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
@@ -398,6 +402,12 @@ from `emptySlots`.** `npm run lint` holds it (`samagotchi/stage-size`: every `st
398
402
  `stage_view.js` re-exports for `dock_reserve.js`) and `OPENING`, what opens a turn in the history (`reload_check.js`
399
403
  reads it). Its state, the turn sliding away, outlives `emptySlots` on purpose: the fold runs after the turn's release
400
404
  and ends by clearing the stage; the view's `reset` drops it.
405
+ - `stage_place.js`: where a row or a card goes while the stage holds a turn (`place`: the hand-off settled first, the
406
+ late recap above an opened turn, the queued slot, an opened turn's row, the docking, the lead-in, the slot order, the
407
+ step limit's hand-off); `stage_view.js`'s event API delegates to it.
408
+ - `stage_probe.js`: the perf probe (`?stage_probe=1`, kept for the tab, or `<body data-stage-probe="1">`: `measured`,
409
+ `chiStageProbe.report()`), around
410
+ `refresh`; `script/stage-perf-probe` drives it ([testing.md](../testing.md)).
401
411
 
402
412
  ## The stage's height
403
413
 
@@ -423,15 +433,17 @@ frame (`frameTarget` returns null) and an unfold refits to what shows. Three thi
423
433
  another tab's write doesn't apply live), **revealed** (a ref's "show in turn" opened it for this turn; the choice stays)
424
434
  and **the docked card's fold** (the waiting card the user folded, by its key, held in `chi_asking_fold:<session>`
425
435
  in sessionStorage: this tab's own, so a reload or a resync mid-turn draws it folded as it was — `stage_waiting.js`
426
- writes it on the fold and reads it back in `trackFold` once the replay has drawn the card; it goes when the card is
427
- answered or cancelled (`question_cards.js`), when the fold drops, when the turn hands off, and when the page opens
428
- another session (`session_sync.js`); `reset` clears the memory only, so the replay can take the fold back). In the
436
+ writes it on the fold and reads it back in `trackFold` once the replay has drawn the card; it goes when that card is
437
+ answered, cancelled or resolved (`stage_waiting.js settle` with `done`, from `question_cards.js onSettled`: only the
438
+ fold that names that card, so a replay or a history question answering another card leaves it), when the fold drops,
439
+ when the turn hands off (`clearFold`), and when the page opens another session (`session_sync.js select`, only when a
440
+ session was open); `reset` clears the memory only, so the replay can take the fold back). In the
429
441
  asking form only that fold counts: the ▾ and a tap on the folded row set or clear it and write nothing to
430
442
  `chi_stage_collapsed` (another blocking card that comes to wait meanwhile
431
443
  drops it, so the stage opens on the front card), so a card always arrives open (in the card's task, before
432
444
  `question_cards.js focusWhenIdle` focuses it) and a new one never matches an old fold; the same card drawn again with its
433
- id keeps it. The fold reads the registry checked against the slots first (`reconcileWaiting`), so a card answered in
434
- the same task no longer holds a click. When the form ends (an answer, a dismiss, a cancel; `emptySlots` for a reset, a
445
+ id keeps it. The fold reads the registry, which every answer settles in its own task, so a card answered in the same
446
+ task no longer holds a click. When the form ends (an answer, a dismiss, a cancel; `emptySlots` for a reset, a
435
447
  session switch, the next turn) the stage is as the choice and revealed say. `refresh` applies it (`drawCollapsed`: only
436
448
  when it changed, no refresh of its own). Folded, the status row's `.ts-mini` says what the shown card asks
437
449
  (`stage_asking.js foldedText`: a question's `.question-text`, an approval's summary and its command's first line, a
@@ -473,12 +485,26 @@ included (`wholeTurn`).
473
485
 
474
486
  **Where the waiting-card state lives:** `stage_waiting.js`, one registry per stage keyed by a card's id (`q:<qid>`,
475
487
  `c:<card id>`, `continue` for the old continue card), never by its node (`card.js drawCard` may swap a plugin card's
476
- DIV for a DETAILS; a resync draws a question card anew). `place` adds (`arrive`: the kind, docked, approval);
477
- `question_cards.js` settles through its `onSettled` hook (answered, cancelled, replaced, removed, the
478
- continue card resolved or dropped), `cards_place.js upsertCard` settles a plugin card redrawn without its actions,
479
- `turnEnded` the warn cards that leave, and `emptySlots` resets it. A second feed only settles: at each refresh
480
- `stage_asking.js reconcileWaiting` drops an entry whose card is gone from the slots or waits no more (a card answered
481
- outside `question_cards.js`, as the stage's unit tests do), and again before the fold, `pendingCard` and an opened row.
488
+ DIV for a DETAILS; a resync draws a question card anew). **Fed from data:** `place` (`stage_place.js`) adds
489
+ (`arrive`: the kind, docked, approval and the folded row's `summary`), taking them from what the card's maker said
490
+ right before placing it: `question_cards.js onArrive` (app.js passes it to `turnDom.expectWaiting`) and
491
+ `cards_place.js upsertCard`'s `expectWaiting`, both from `card_kinds.js` (`questionWait`, `continueWait`, `cardWait`:
492
+ the same rules and text functions the cards are drawn by). The card's node is read too (`waitingKind`,
493
+ `isApprovalCard`, `stage_asking.js foldedText`'s DOM read): a cross-check that warns once per key ("stage: waiting
494
+ kind differs", "… summary differs"), and the fallback for a card that came without data (an older `question_cards.js`
495
+ in a mixed cache, a test's bare card). **Settle is the one way out:** `question_cards.js` settles through its
496
+ `onSettled` hook (answered, cancelled, replaced, removed, the continue card resolved or dropped; `{done: true}` for an
497
+ answer, a cancel or a resolve, which also removes that card's kept fold), `cards_place.js upsertCard` settles a plugin
498
+ card redrawn without its actions (`only: "asks"`) or neither asking nor a warning (`only: "warn"`); one redrawn in
499
+ place that still waits (check-in's new title) patches its entry after those settles (`turnDom.updateWaiting`: kind
500
+ and summary, its order and docking kept; arrived again, not docked, as a warning or when its actions came back; with
501
+ an older `stage_waiting.js` that has no `update`, an arrive in place), `turnEnded` the warn cards
502
+ that leave, `session_view.js endTurnView`'s cancel of a question still pending goes through `onSettled`, and
503
+ `emptySlots` resets it (a resync's and `workerGone`'s reset too). Nothing on the page reads the slots back against
504
+ it: the tests do (`stage_cuts_parity.test.js`, after every event and at each cut: no entry without its waiting card in
505
+ the extras or the tail, no waiting card there without its entry; the e2e's stage check at each test's end, reading the
506
+ registry off the stage's node, `#turnStage.chiWaiting()`). `stage_asking.js reconcileWaiting` is a no-op kept one
507
+ release for a stale `stage_view.js` that still calls it.
482
508
  The registry's order is the stage's: blocking cards before the asking ones, arrival order within each, and `place`
483
509
  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
484
510
  asking form's card is the shown docked entry, the fold is the folded key (`stageCollapsed` compares keys); `opener`'s
@@ -632,5 +658,8 @@ reach another device or the server.
632
658
  sessionStorage (this tab only, `storage.js` `readSession`/`writeSession`/`removeSession`, guarded the same way):
633
659
  `chi_client_id` (`turn_events.js`: this tab's client id, kept over a reload mid-turn),
634
660
  `chi_asking_fold:<session>` (`stage_waiting.js`: the docked card the user folded and how many cards waited at the
635
- fold, so a reload or a resync mid-turn draws the asking form as they left it), and
636
- `chi.authReloadAt` (`auth_lost.js`: one automatic reload a minute).
661
+ fold, so a reload or a resync mid-turn draws the asking form as they left it; removed by `stage_waiting.js` alone:
662
+ `settle` with `done` for that card, the fold dropping, the hand-off's `clearFold`, and `session_sync.js select` leaving
663
+ the session),
664
+ `chi.authReloadAt` (`auth_lost.js`: one automatic reload a minute), and `chi_stage_probe` (`stage_probe.js`: the
665
+ perf probe on for this tab, from `?stage_probe=1`).
data/docs/plugins.md CHANGED
@@ -1458,7 +1458,9 @@ 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`). 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.
1462
1464
  6. `Samagotchi::AtomicFile.write`, `Samagotchi::Log.warn` /
1463
1465
  `Samagotchi::Log.debug`, `Samagotchi::Config.get`,
1464
1466
  `Samagotchi::VERSION`, `Samagotchi::CancellationController` (`new`, `cancel!`: what `cancel:` takes) and
data/docs/sessions.md CHANGED
@@ -41,7 +41,7 @@ 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
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).
47
47
 
@@ -493,7 +493,7 @@ mise.toml pins Ruby 3.4 gets that `ruby`, `gem` and `bundle` in its tools while
493
493
  `.config/mise/`, `mise/`, `.mise/`) are secrets to them, as `.env` is.
494
494
  - **What tools still drop**: every `execute`, task, `!cmd`, context source and MCP server takes no `RUBYOPT`, `RUBYLIB`, or what `bundle exec` sets
495
495
  (`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`).
496
+ variables, and with the worker's own `RUBYOPT`, Bundler's part removed (`SpawnEnv`).
497
497
  - **`chi` in a tool** stays the home's: with a chi home the tools' PATH starts with `$XDG_STATE_HOME/samagotchi/bin`,
498
498
  a dir holding only a `chi` script that boots the home (rewritten at each worker start when the home changed; it
499
499
  unsets `RUBYOPT`, `RUBYLIB`, `RUBYGEMS_GEMDEPS`, `GEMRC` and `BUNDLE*` before it runs, so a `bundle exec` around it
data/docs/testing.md CHANGED
@@ -231,11 +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`.
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.
239
249
  `spec/shared/turn_ranges.json` (`UPDATE_TURN_RANGES=1 bundle exec rspec spec/bridge/turn_ranges_spec.rb`) pins
240
250
  `Bridge::TurnRanges`' turns, their record pairing, the items as the show stamps them and each turn's drawing end;
241
251
  timing.test.js checks `turnGroups` (stamps only) against it. Each scenario's
@@ -545,6 +555,28 @@ runs its code only on small synthetic sessions, never on yours. See
545
555
  [internals/llm-context-bench.md](internals/llm-context-bench.md). `script/llm_context_live.rb` runs chi itself on
546
556
  real tasks under each strategy (needs a model; costs tokens): [internals/llm-context-live.md](internals/llm-context-live.md).
547
557
 
558
+ ## The stage perf probe
559
+
560
+ `script/stage-perf-probe` (`PROBE_MACHINE=<label>` names the machine; `--keep` leaves its folder, `--headed` shows
561
+ the browser, `--reload-check` turns `web.reload_check` on: `reload:compare` times the check's compare, `reload:posted`
562
+ 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
563
+ turns with 60 plugin cards and 40 answered questions through chi's own writers (TurnAccumulator's drawings, CardStore,
564
+ `Session#save`; CardStore keeps its cap of 20, the rest are in the drawings), then `probe.js` opens it in chi web
565
+ (the e2e fake model, isolated `HOME` and `XDG_*` under `tmp/stage-probe-*`) at `/?stage_probe=1` (`stage_probe.js`:
566
+ the flag is kept for the tab in sessionStorage, `chi_stage_probe`, so a reload or a hash jump keeps it;
567
+ `?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
568
+ both. It prints JSON: `stage:refresh` n/p50/p95/max (ms), the session's open (the hash to the last answer drawn),
569
+ tap→settled per card, reload→card drawn, the JS heap after a GC before the open, after it and after the turn, and the
570
+ cards as data (`card_registry.js`): `cards:apply` per card event, `cards:seed` per read, and the registry's entries and
571
+ JSON bytes after the open and after the turn (`globalThis.chiCardRegistry`, only while probing). Its
572
+ `session.drawn` counts what the open drew: all 300 answers and 60 cards, but only the answered questions CardStore
573
+ still lists (8: its cap keeps the newest 20 cards and questions together, and a finished turn's question is drawn from
574
+ that list alone). Bounded:
575
+ the session within 60 s, the browser run within 180 s, cut at 300 s; it stops only what it started (chi web and the
576
+ fake by their handles, the worker through chi web's stop route) and says when anything still names its folder. Not
577
+ part of any suite. On an iPhone: open the page once with `?stage_probe=1` (the Home Screen app: in Safari Web
578
+ Inspector's console, `location.search = "?stage_probe=1"`), run a turn, then `chiStageProbe.report()` there.
579
+
548
580
  ## The model notes report
549
581
 
550
582
  `ruby script/model_notes_report.rb` reads a sessions folder (`--sessions DIR`, else chi's own) and groups the
@@ -637,3 +669,11 @@ names from elsewhere checked), one-off host pairs (`ToolRun` in `tool_response.r
637
669
  autoloads that load whole (`SessionManager`, `Objectives`, `Config`), and `Plugin::Http`'s (its base file
638
670
  loads the reopening file only inside a method, and that file requires the base file first). The summary counts the entries that
639
671
  matched and those that match nothing: delete a stale one.
672
+
673
+ **The thin client load budgets.** `spec/require_cycle_spec.rb` loads the attached TUI's files
674
+ (`terminal_ui/attach_launcher`, `attached_loop`) and chi web's (`web/app`) in a fresh ruby and fails when either
675
+ loads the turn loop (`kernel_loop`), the bundle updater (`memory_bundle/shipped_update`), or a tool that runs:
676
+ `tools/execute`, `tools/builtins`, `tools/task_runtime`. A client that needs a tool's name or result text reads
677
+ `ToolNames`; one that needs a session command's name or the built-ins' registry reads `SessionCommandCatalog`;
678
+ task files and transcripts are `TaskFiles` and `TaskTranscript`. A require that breaks a budget is a sign the
679
+ 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):
@@ -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.0
3
+ version: 0.173.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:
@@ -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"
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "tools/read"
4
- require_relative "tools/write"
5
- require_relative "tools/edit"
3
+ require_relative "tool_names"
6
4
 
7
5
  module Samagotchi
8
6
  # A ref to the file a read/write/edit call touched, for a UI to trace it
@@ -20,7 +18,7 @@ module Samagotchi
20
18
  class FileRef
21
19
  KIND = "file"
22
20
 
23
- TOOLS = [Tools::Read::NAME, Tools::Write::NAME, Tools::Edit::NAME].freeze
21
+ TOOLS = [ToolNames::Read::NAME, ToolNames::Write::NAME, ToolNames::Edit::NAME].freeze
24
22
 
25
23
  # @param cwd [String, nil] the session's working directory; without one
26
24
  # a relative path gets no ref (an absolute or ~ path still does)
@@ -30,7 +28,7 @@ module Samagotchi
30
28
  def self.for(tool_name, call, cwd:)
31
29
  return nil unless TOOLS.include?(tool_name) && call.is_a?(Hash)
32
30
 
33
- path = absolute((tool_name == Tools::Read::NAME ? call[:content] : call[:path]).to_s.strip, cwd)
31
+ path = absolute((tool_name == ToolNames::Read::NAME ? call[:content] : call[:path]).to_s.strip, cwd)
34
32
  return nil unless path
35
33
 
36
34
  line = positive(call[:start_line])
@@ -8,7 +8,7 @@ module Samagotchi
8
8
  # participant's turn this chi doesn't run under the owner's rules: no
9
9
  # current invite (an older chi's read-only one, no grant at all), a
10
10
  # Verify fresh child saved for a read-only turn, or no session. The
11
- # worker refuses such a turn before it starts (Worker#participant_refusal);
11
+ # worker refuses such a turn before it starts (WorkerParticipantGate#refusal);
12
12
  # this is the fail-closed fallback should one start anyway: every call is
13
13
  # denied, nobody is asked. A no-op for the owner's turns.
14
14
  class ParticipantRefusal
@@ -11,6 +11,7 @@ require_relative "working_set"
11
11
  require_relative "file_ref"
12
12
  require_relative "tool_response"
13
13
  require_relative "tool_output_cut"
14
+ require_relative "tool_names"
14
15
  require_relative "model_overlay"
15
16
  require_relative "tools/memory"
16
17
 
@@ -38,7 +39,7 @@ module Samagotchi
38
39
  # The memory scopes, project first, as `chi memory ls` reports them.
39
40
  SCOPES = Tools::VALID_SCOPES
40
41
  MEMORY_READ = Tools::MemoryRead::NAME
41
- FILE_READ = Tools::Read::NAME
42
+ FILE_READ = ToolNames::Read::NAME
42
43
 
43
44
  # One memory read at least once in the sessions counted: its tokens (the
44
45
  # results' size) and reads, +cut_reads+ of them returned a cut result,
@@ -5,7 +5,8 @@ require_relative "tool_call_parser"
5
5
  require_relative "tool_activity"
6
6
  require_relative "tool_row_fields"
7
7
  require_relative "llm/native_tool_normalizer"
8
- require_relative "tools/builtins"
8
+ require_relative "tool_names"
9
+ require_relative "tools/builtin_calls"
9
10
  require_relative "image_store"
10
11
  require_relative "llm_context_edit"
11
12
  require_relative "token_usage"
@@ -65,14 +66,15 @@ module Samagotchi
65
66
 
66
67
  # @param message [Hash] a saved model message (symbol or string keys)
67
68
  # @param responses [Array<Hash>] the tool_response messages after it
68
- # @param registry [Tools::Registry] the session's tools
69
+ # @param registry [Tools::Registry, #[]] the session's tools; the
70
+ # built-ins' names alone by default (ToolNames::BuiltinRegistry)
69
71
  # @param cwd [String, nil] the session's working directory (a file
70
72
  # tool's title is relative to it)
71
73
  # @param marks [Hash{String => Hash}] the session's edit marks by
72
74
  # output id (.edit_marks)
73
75
  # @return [Hash, nil] { thinking:, tools: [{ tool:, params:, title:,
74
76
  # output:, output_truncated:, images:, tool_id:, edit: }] } with only what it found; nil for nothing
75
- def for_message(message, responses, registry: Tools::Builtins.default, cwd: nil, marks: {})
77
+ def for_message(message, responses, registry: ToolNames::BuiltinRegistry, cwd: nil, marks: {})
76
78
  return nil unless something?(message)
77
79
 
78
80
  content = field(message, :content).to_s
@@ -3,11 +3,7 @@
3
3
  require_relative "steer"
4
4
  require_relative "tool_activity"
5
5
  require_relative "tool_response"
6
- require_relative "tools/edit"
7
- require_relative "tools/execute"
8
- require_relative "tools/objectives_tool"
9
- require_relative "tools/task_wait"
10
- require_relative "tools/write"
6
+ require_relative "tool_names"
11
7
 
12
8
  module Samagotchi
13
9
  module Objectives
@@ -37,7 +33,7 @@ module Samagotchi
37
33
  class Backing
38
34
  OK = "ok"
39
35
  FAILED = "failed"
40
- CHANGES = [Tools::Edit::NAME, Tools::Write::NAME].freeze
36
+ CHANGES = [ToolNames::Edit::NAME, ToolNames::Write::NAME].freeze
41
37
 
42
38
  # +runs+ the move's turn's paired runs before it (LLMContextStale.paired_runs'),
43
39
  # in order; +state+ the move's.
@@ -58,7 +54,7 @@ module Samagotchi
58
54
  edited_after = false
59
55
  end
60
56
  end
61
- unbacked = state == Tools::ObjectivesTool::DONE && !command.nil? && (command == FAILED || edited_after)
57
+ unbacked = state == ToolNames::ObjectivesTool::DONE && !command.nil? && (command == FAILED || edited_after)
62
58
  new(edits: edits, command: command, edited_after_command: edited_after, unbacked: unbacked)
63
59
  end
64
60
 
@@ -79,7 +75,7 @@ module Samagotchi
79
75
  # an execute that finished ok (a failed, denied, stopped one isn't; one
80
76
  # handed over as a task still runs, and isn't either).
81
77
  def self.work?(run)
82
- edit?(run) || (run.call[:name].to_s == Tools::Execute::NAME && command_status(run) == OK)
78
+ edit?(run) || (run.call[:name].to_s == ToolNames::Execute::NAME && command_status(run) == OK)
83
79
  end
84
80
 
85
81
  def self.edit?(run)
@@ -95,12 +91,12 @@ module Samagotchi
95
91
  # a waiting message) or that waited on nothing (an Error:).
96
92
  def self.command_status(run)
97
93
  name = run.call[:name].to_s
98
- return nil unless [Tools::Execute::NAME, Tools::TaskWait::NAME].include?(name)
94
+ return nil unless [ToolNames::Execute::NAME, ToolNames::TaskWait::NAME].include?(name)
99
95
  return nil if ToolResponse.interrupted_text?(run.text)
100
96
 
101
97
  text = ToolActivity.saved_result_text(run.text)
102
98
  return nil if ToolActivity.guardrail_denied?(text)
103
- return task_status(text) if name == Tools::TaskWait::NAME
99
+ return task_status(text) if name == ToolNames::TaskWait::NAME
104
100
  return nil if ToolActivity.handed_over?(name, text)
105
101
 
106
102
  case ToolActivity.tool_activity_status(text, name, command: run.call[:content])
@@ -76,7 +76,7 @@ module Samagotchi
76
76
  end
77
77
 
78
78
  # The reasons a worker refuses a participant's queued turn
79
- # (Worker#participant_refusal), as its settled record's cancel_reason.
79
+ # (WorkerParticipantGate#refusal), as its settled record's cancel_reason.
80
80
  REFUSED_LINES = { "revoked" => ParticipantMessages::TOKEN_ENDED,
81
81
  "outdated" => ParticipantMessages::TOKEN_OUTDATED,
82
82
  "cap_reached" => ParticipantMessages::CAP_REACHED }.freeze