samagotchi 0.166.0 → 0.168.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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -1
  3. data/docs/architecture.md +1 -0
  4. data/docs/cli.md +24 -15
  5. data/docs/configuration.md +1 -0
  6. data/docs/guardrails.md +5 -5
  7. data/docs/hooks.md +4 -6
  8. data/docs/internals/bundles.md +2 -4
  9. data/docs/internals/engine.md +4 -5
  10. data/docs/internals/objectives.md +141 -9
  11. data/docs/internals/remote-sessions.md +5 -6
  12. data/docs/internals/web-frontend.md +85 -40
  13. data/docs/memory.md +1 -2
  14. data/docs/sessions.md +20 -2
  15. data/docs/testing.md +3 -3
  16. data/lib/samagotchi/bridge.rb +1 -1
  17. data/lib/samagotchi/bundle_command/installed_check.rb +2 -14
  18. data/lib/samagotchi/bundle_command.rb +35 -12
  19. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  20. data/lib/samagotchi/cli/command.rb +10 -0
  21. data/lib/samagotchi/compat.rb +1 -13
  22. data/lib/samagotchi/config.rb +3 -0
  23. data/lib/samagotchi/context_command.rb +2 -1
  24. data/lib/samagotchi/engine/objectives.rb +20 -1
  25. data/lib/samagotchi/engine/side_requests.rb +3 -2
  26. data/lib/samagotchi/engine/turn_end.rb +4 -1
  27. data/lib/samagotchi/engine.rb +3 -0
  28. data/lib/samagotchi/extension_load.rb +2 -26
  29. data/lib/samagotchi/guardrails/approvals.rb +15 -16
  30. data/lib/samagotchi/jsonl_store.rb +61 -0
  31. data/lib/samagotchi/memory_bundle/status.rb +3 -15
  32. data/lib/samagotchi/memory_bundle/system_bundle.rb +16 -10
  33. data/lib/samagotchi/memory_command.rb +4 -2
  34. data/lib/samagotchi/objectives.rb +43 -14
  35. data/lib/samagotchi/objectives_backing.rb +124 -0
  36. data/lib/samagotchi/objectives_check.rb +19 -126
  37. data/lib/samagotchi/objectives_command.rb +14 -7
  38. data/lib/samagotchi/objectives_record.rb +104 -0
  39. data/lib/samagotchi/objectives_track.rb +353 -0
  40. data/lib/samagotchi/push_command.rb +2 -1
  41. data/lib/samagotchi/remote_command.rb +2 -1
  42. data/lib/samagotchi/reply_wait/poll.rb +6 -6
  43. data/lib/samagotchi/reply_wait.rb +4 -24
  44. data/lib/samagotchi/schedule_command.rb +6 -0
  45. data/lib/samagotchi/schedules.rb +1 -1
  46. data/lib/samagotchi/session_access/remote.rb +3 -5
  47. data/lib/samagotchi/session_commands.rb +1 -1
  48. data/lib/samagotchi/sessions_command.rb +12 -6
  49. data/lib/samagotchi/share_command.rb +2 -1
  50. data/lib/samagotchi/tool_activity.rb +11 -1
  51. data/lib/samagotchi/tool_declarations.rb +5 -1
  52. data/lib/samagotchi/tools/objectives_tool.rb +19 -2
  53. data/lib/samagotchi/turn_stages/objectives.rb +46 -3
  54. data/lib/samagotchi/version.rb +1 -1
  55. data/lib/samagotchi/web/participant_access.rb +1 -1
  56. data/lib/samagotchi/web/public/app.js +52 -424
  57. data/lib/samagotchi/web/public/copy.js +2 -1
  58. data/lib/samagotchi/web/public/dock_reserve.js +12 -2
  59. data/lib/samagotchi/web/public/history_end.js +16 -0
  60. data/lib/samagotchi/web/public/index.html +74 -22
  61. data/lib/samagotchi/web/public/info_bar_model.js +3 -1
  62. data/lib/samagotchi/web/public/no_contact_fill.js +29 -0
  63. data/lib/samagotchi/web/public/objectives.css +14 -0
  64. data/lib/samagotchi/web/public/objectives_moves.js +82 -9
  65. data/lib/samagotchi/web/public/objectives_state.js +42 -0
  66. data/lib/samagotchi/web/public/objectives_strip.js +33 -9
  67. data/lib/samagotchi/web/public/objectives_track.js +52 -0
  68. data/lib/samagotchi/web/public/objectives_wiring.js +16 -1
  69. data/lib/samagotchi/web/public/participant.html +1 -1
  70. data/lib/samagotchi/web/public/participants_panel.js +14 -7
  71. data/lib/samagotchi/web/public/question_cards.js +8 -13
  72. data/lib/samagotchi/web/public/refs.js +4 -1
  73. data/lib/samagotchi/web/public/reload_check.js +5 -4
  74. data/lib/samagotchi/web/public/resync_reach.js +10 -6
  75. data/lib/samagotchi/web/public/scope.js +3 -3
  76. data/lib/samagotchi/web/public/session_rename.js +6 -2
  77. data/lib/samagotchi/web/public/session_state.js +1 -1
  78. data/lib/samagotchi/web/public/session_sync.js +249 -0
  79. data/lib/samagotchi/web/public/session_view.js +279 -0
  80. data/lib/samagotchi/web/public/stage_cards.js +20 -0
  81. data/lib/samagotchi/web/public/stage_frame.js +14 -16
  82. data/lib/samagotchi/web/public/stage_model.js +11 -4
  83. data/lib/samagotchi/web/public/stage_opened.js +229 -0
  84. data/lib/samagotchi/web/public/stage_slots.js +2 -3
  85. data/lib/samagotchi/web/public/stage_view.js +219 -147
  86. data/lib/samagotchi/web/public/stage_watch.js +8 -4
  87. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  88. data/lib/samagotchi/web/public/tokens.css +2 -2
  89. data/lib/samagotchi/web/public/turn_block.js +22 -2
  90. data/lib/samagotchi/web/public/turn_html.js +1 -1
  91. data/lib/samagotchi/web/public/widget_picks.js +3 -0
  92. data/lib/samagotchi/web/public/working_set_view.js +1 -1
  93. data/lib/samagotchi/web/session_access_routes.rb +4 -15
  94. metadata +13 -1
@@ -10,10 +10,14 @@ only library. Pure modules (`*_model.js`, `session_state.js`, `sessions_list.js`
10
10
  and have `node --test` specs under `spec/web/public/` (happy-dom for the DOM ones); the pages as a whole are covered
11
11
  by `npm run e2e` (`spec/e2e/`). `app.js` has no unit spec.
12
12
 
13
- **`app.js` has a size cap**: `npm run lint` fails past `max-lines` in `eslint.config.js` (counted as `wc -l` counts:
14
- 2000, ratcheted down from 2250 when the versions, the owner's claim links and Verify, the composer's mode and the
15
- strip's hide went into modules of their own, which left room for a few features' wiring). A new feature goes into a module of its own, wired from `app.js` in a few lines; a
16
- refactor that shrinks `app.js` ratchets the cap down with it. Never raise it: extract instead.
13
+ **Every module has a size cap, `app.js` its own**: `npm run lint` fails past `max-lines` in `eslint.config.js`
14
+ (counted as `wc -l` counts, comments and blank lines too). Every `public/*.js` module: 1200 (`samagotchi/module-size`,
15
+ about 10% over the largest, `turn_block.js`), so a module near it splits rather than becoming the next `app.js`.
16
+ `app.js` (`samagotchi/app-size`): 1649, its size plus 50 once the session-open flow went into `session_sync.js` and
17
+ `session_view.js`; ratcheted down from 2000, itself down from 2250 when the versions, the owner's claim links and
18
+ Verify, the composer's mode and the strip's hide went into modules of their own. A new feature goes into a module of
19
+ its own, wired from `app.js` in a few lines; a refactor that shrinks `app.js` ratchets its cap down with it. Never
20
+ raise either: extract instead.
17
21
 
18
22
  **New exports go in new modules.** The static JS is served at unversioned URLs. Today every load revalidates
19
23
  (app.rb `serve_static` sends `Cache-Control: no-cache` with a content ETag, and `sw.js` has no fetch handler), but an
@@ -24,13 +28,13 @@ page. A factory dep a new version stops passing is the same hazard the other way
24
28
  out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
25
29
  until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
26
30
  `turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
27
- `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), `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), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says reconnecting / can't reach chi web) 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).
31
+ `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), `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), `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 the model's own question waits: the reason bubble, the moves, the end fold), `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), `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).
28
32
 
29
33
  ## Two pages, two models
30
34
 
31
35
  | Page | Entry | Model |
32
36
  |---|---|---|
33
- | **Owner page**: the start page and a session page | `index.html` → `app.js` | **Render once, then patch.** A session's open (`select` → `resync` → `renderSessionView`) draws the history from `GET /api/sessions/:id`; from then on each stream event changes the DOM in place (`stream_handlers.js`). The DOM *is* the log. The start page is the same app with `store.selected` null. |
37
+ | **Owner page**: the start page and a session page | `index.html` → `app.js` | **Render once, then patch.** A session's open (`session_sync.js` `select` → `resync` → `session_view.js` `renderSessionView`) draws the history from `GET /api/sessions/:id`; from then on each stream event changes the DOM in place (`stream_handlers.js`). The DOM *is* the log. The start page is the same app with `store.selected` null. |
34
38
  | **Participant page**: a review or pair link | `participant.html` → `participant.js` | **Re-read at a turn boundary, then a keyed redraw.** It reads `GET …/review`, draws it, and streams; an event that ends or changes a turn (`reloads`) marks the data stale and the page reads it again. `drawnMessages` keeps a message's node while its signature is unchanged; a small `live` overlay (`participant_model.js applyLive`) draws the running turn on top. |
35
39
 
36
40
  The participant page is **deliberately separate**: it shares leaf modules with the owner page (the annotate bar,
@@ -47,11 +51,11 @@ change.
47
51
  | Holder | What | Who writes | How a change reaches the screen |
48
52
  |---|---|---|---|
49
53
  | **The session store** (`session_store.js`; app.js `store`) | `store.selected` (the open session's id), `store.current` and `store.sessions` (below) | through the store only (see The session store); other modules get getters (`selected: () => store.selected`, `state: () => store.current`) or the store itself (`stream_handlers.js`, `send_turn.js`, `session_actions.js`) | the store runs the redraws that read what changed (below); nobody calls them by hand |
50
- | **app.js module scope**: about 20 top-level `let`s (`streamControl`, `eventsControl`, `pageCapabilities`/`pageEditorUrl`, `resyncsInFlight`/`resyncAgain`, `resyncAttempts`, `scopeError`…) | the page's mode and its streams | app.js only; other modules get getters and hooks | the writer touches the redraw that reads it (`store.touch("infoBar")`: the stream; `version_notices.js` does it for the versions and its `restarting` set), or calls a redraw only it feeds |
51
- | **`store.current`** (`session_state.js`: `emptySessionState` / `sessionStateFrom`; per field: `session_fields.js FIELDS`) | the open session's fields, about 40 (info bar, chips, verdicts, timing, worker, stream cursor) | `store.update` / `setStatus` from app.js, `stream_handlers.js`, `send_turn.js` (`firstPreview`, `owner`), `session_actions.js` (`status`), `owner_verify.js` (`verdicts`, `verifyFresh`); `forgetSession`'s `replaceCurrent`. Two writers in place, on purpose (D8 in `FIELDS`): live_timing.js's `activeTurn`, verdict_fresh.js's running list | the store runs the field's redraws (`FIELDS[key].redraws`) |
54
+ | **app.js module scope**: about a dozen top-level `let`s (`eventsControl`, `pageCapabilities`/`pageEditorUrl`, `scopeError`…); the open session's stream handle and re-read bookkeeping (`streamControl`, `resyncsInFlight`/`resyncAgain`, `resyncAttempts`) are `session_sync.js`'s, in its closure | the page's mode and its streams | their module only; other modules get getters and hooks (`sessionSync.hasStream()`: a stream object, also while it connects, the bar's streaming; `streamLive()`: it delivers) | the writer touches the redraw that reads it (`store.touch("infoBar")`: the stream; `version_notices.js` does it for the versions and its `restarting` set), or calls a redraw only it feeds |
55
+ | **`store.current`** (`session_state.js`: `emptySessionState` / `sessionStateFrom`; per field: `session_fields.js FIELDS`) | the open session's fields, about 40 (info bar, chips, verdicts, timing, worker, stream cursor) | `store.update` / `setStatus` from app.js, `stream_handlers.js`, `session_sync.js`, `session_view.js`, `send_turn.js` (`firstPreview`, `owner`), `session_actions.js` (`status`), `owner_verify.js` (`verdicts`, `verifyFresh`); `forgetSession`'s `replaceCurrent` (`session_view.js`). Two writers in place, on purpose (D8 in `FIELDS`): live_timing.js's `activeTurn`, verdict_fresh.js's running list | the store runs the field's redraws (`FIELDS[key].redraws`) |
52
56
  | **`store.sessions`** (the hub's projection) | every card | `store.update({sessions})` from app.js: `openSessionEvents` (`applySessionEvent`), `refresh` (the list fallback), `addCreatedSession`, `applyView` (re-sorted), `replaceSelectedCard` (`setLiveStatus` through `setStatus`, `readTurnEnd`, `setUsedMemories`), the stream's close (`withoutWorker`); `session_actions.js` (`setSessions`) | the store: `lists` and `infoBar`. **Always a new array**; an entry is replaced, never changed in place. `followSelectedSession` copies the open one's owner and worker (`fieldsFromCard`) and, when not streaming, its status (`setStatus(…, "hub")`) into `store.current` |
53
57
  | **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 |
54
- | **The history DOM** | the conversation as drawn: 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) |
58
+ | **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) |
55
59
  | **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 |
56
60
  | **localStorage** (`storage.js` `readStored`/`writeStored`, guarded) | per-browser choices only | the module that owns the choice | read at start (see Storage keys) |
57
61
  | **SSE** | see Streams | the server | owner page: events go into the DOM directly; participant page: an event marks the data stale |
@@ -75,16 +79,16 @@ through the store**, never `current.X = …`:
75
79
  old one writes there alone.
76
80
  - `store.batch(fn)`, `store.touch(name)`, `store.on(name, fn)`: the redraws (below).
77
81
 
78
- The ESLint block `samagotchi/session-writes` (eslint.config.js) enforces it in the seven modules that hold the state
82
+ The ESLint block `samagotchi/session-writes` (eslint.config.js) enforces it in the nine modules that hold the state
79
83
  (app.js, `stream_handlers.js`, `send_turn.js`, `session_actions.js`, `start_page.js`, `working_set_view.js`,
80
- `owner_verify.js`): an
84
+ `owner_verify.js`, `session_sync.js`, `session_view.js`): an
81
85
  assignment, `++`, `delete` or `Object.assign` into `current`, `store.current` or `state()` is an error
82
86
  (`spec/web/public/lint_session_writes.test.js` runs it on a sample). An alias (`const st = state(); st.x = …`) isn't
83
87
  caught: don't write through one.
84
88
 
85
89
  **Read `store.current` fresh after every await.** A `const cur = store.current` held across an await pins the object
86
- from before it, which a session switch (`forgetSession`) may have replaced: app.js's `readTurnEnd`,
87
- `mergeTurnTiming`, `resync` and `refreshTimingFromSession` read it again after each await. Keep `store.sessions`
90
+ from before it, which a session switch (`forgetSession`) may have replaced: app.js's `mergeTurnTiming` and
91
+ `refreshTimingFromSession`, `session_view.js`'s `readTurnEnd` and `session_sync.js`'s `resync` read it again after each await. Keep `store.sessions`
88
92
  reads fresh too.
89
93
 
90
94
  ### Fields and their redraws
@@ -112,13 +116,13 @@ piece a redraw calls exists): `lists` → `lists.render()`, `paintActive` → `l
112
116
  a store write. A value written unchanged redraws nothing (a chunk with the same ctx %).
113
117
 
114
118
  An input the store doesn't hold calls `store.touch(name)` where it changes: `infoBar` for the clock (liveTurn's
115
- `onTick`), the versions and the sessions restarting (`version_notices.js` `notice`, `restart`), the stream (`startStream`, `workerGone`), the working
119
+ `onTick`), the versions and the sessions restarting (`version_notices.js` `notice`, `restart`), the stream (`session_sync.js` `startStream`, `workerGone`), the working
116
120
  set's and the participants' `onChange`, the continue and review in-flight sets
117
121
  (`session_actions.js`); `composer` and `infoBar` for `liveTurn.running` (`setTurnRunning`, with `settingsPanel`:
118
122
  the open ⚙ panel's running-turn note) and at the end of `renderSessionView` (a whole view drawn). Left as they are,
119
123
  on purpose: `composer_mode.js`'s phone-width listener calls its `update()` (the bar doesn't read it),
120
- `strip_hidden.js`'s apply and `applyView` call `updateSessionTitle()`, and `closeStream`/`stream.restart` set
121
- `streamControl = null` without a redraw (a resync or a workerGone follows).
124
+ `strip_hidden.js`'s apply and `applyView` call `updateSessionTitle()`, and `session_sync.js`'s `closeStream`/`restart`
125
+ (the stream handlers' `stream.restart`) drop the stream handle without a redraw (a resync or a workerGone follows).
122
126
 
123
127
  A function that writes more than once batches its synchronous part, so each redraw runs once: `select` (before its
124
128
  `await resync()`), `clearSelection`, the hub's `snapshot` and `session` events, `workerGone`, `setTurnRunning`,
@@ -156,9 +160,10 @@ A page action the open session's worker must support (its sidecar features and a
156
160
  when a field it reads changes (`workerFeatures`, `bridgeUp`), and a gate's `redraw` only when its answer flipped: a
157
161
  restart's hub event that brings the feature enables it, the worker going (`workerGone`'s `bridgeUp = false`) says
158
162
  it's unavailable. `forgetSession` and `renderSessionView` draw the history with the answer already, so they `prime()`
159
- the gates in the batch of their write, and nothing fires. Today two gates: `verify` (Verify fresh on a verdict's
160
- card, `redrawFresh`) and `revise` (the answers' Revise buttons and the composer's Revising chip, `redrawRevise`).
161
- Both refuse only a live worker without the feature — `workerPredates(features, up, feature)` in
163
+ the gates in the batch of their write, and nothing fires. Today three gates: `verify` (Verify fresh on a verdict's
164
+ card, `redrawFresh`), `revise` (the answers' Revise buttons and the composer's Revising chip, `redrawRevise`) and
165
+ `objectivesTrack` (the objectives' Where are we?, in the list and on the no-move line, `objectives.redraw`).
166
+ All refuse only a live worker without the feature — `workerPredates(features, up, feature)` in
162
167
  `worker_features.js`, the rule both gates share: a worker that isn't up is woken by the send as a new one, which
163
168
  has it. A new action that needs a worker feature is one more entry.
164
169
 
@@ -190,7 +195,7 @@ The redraws, by their store names:
190
195
  `store.sessions`.
191
196
  - `featureGates`: the gates above.
192
197
 
193
- `forgetSession()` is the one reset: `select` and `clearSelection` both call it, so anything per-session that isn't
198
+ `forgetSession()` (`session_view.js`) is the one reset: `select` and `clearSelection` both call it, so anything per-session that isn't
194
199
  in `store.current` (capabilities, the markdown warning and tip, the init row, the Verify claim, the armed Revise,
195
200
  the running turn's DOM) is cleared there, and the feature gates are primed for the empty session. A new per-session holder
196
201
  (an armed composer anchor like the Verify claim or the Revise) goes into it. The armed Verify claim is
@@ -268,24 +273,64 @@ sheet's offset (`chip_popover.js place`: 8px above the indicator, or a keyboard'
268
273
  toast's fallback place (in a session `--toast-bottom` already sits it above the card), the lightbox's padding and the
269
274
  signed-out banner (`auth_lost.js`, `env()` itself: the participant page has no `--safe-*`). A new fixed or bottom-anchored
270
275
  piece reads `--safe-*`, never `env()`: the e2e set the names by hand (`web.spec.js`, a portrait phone and a landscape one),
271
- as Chromium has no insets. The theme-color metas are tokens.css's `--bg` per theme (`theme.test.js` pins them).
276
+ as Chromium has no insets. The theme-color metas are tokens.css's `--bg-top` per theme up to 600px wide (a phone's page starts from that colour at its top edge, so the status bar meets the top bar with no seam), else its `--bg` (`theme.test.js` pins them). An iOS 26 Home Screen app ignores them for the status bar strip: it paints the strip in the body's `background-color`, so a phone's body gradient keeps a `--bg-top` colour layer under it (black strip without one).
272
277
 
273
278
  ## The stage's height
274
279
 
275
- `stage_frame.js` is the one writer. The cap is a ceiling: 60% of the page, 80% with the cloud open, 85% while a card has
276
- the room, and never above the session panel (less the card, its offset from the panel's bottom as computed: index.html
277
- `--dock-bottom`, and 16px). The frame is grow-only while a turn runs, so a change inside the stage
278
- never moves its top edge, with one exception: **the next step after a blocking card's answer lets the frame go, once**
279
- (`stage_view.js releaseHeldWait`, from `generationStarted`). The `held-wait` class says it is due: set with `waiting`,
280
- cleared there, so a later step, which calls it again, does nothing. What goes together: the live slots' waiting height, a
281
- raised cap, the tallest content seen (`forgetContent`). At the tap nothing moves: the card collapses to its line inside
282
- the held frame and the stage's scroll stays, unless the line would be above the view (a reader who scrolled down a card
283
- taller than the stage), when it comes back to the view's top (`settleAnsweredCard`).
284
-
285
- Two cards raise the cap: a model's own question whose reply overflows its slot (`drawRoom`, the question room, read from
286
- the reply's start with a pill to the card) and a blocking approval too tall for the stage's view, a delegate's relayed
287
- one too (`raiseForApproval`, `stage_frame.js fitsCap`). An approval gets the cap only: no room class and no pill, as it
288
- opens at its question and command (`revealTop`).
280
+ `stage_frame.js` is the one writer. The cap is a ceiling: 60% of the page, 80% with the cloud open, 85% with a raised
281
+ cap, and never above the session panel (less the card, its offset from the panel's bottom as computed: index.html
282
+ `--dock-bottom`, and 16px). The frame is grow-only while a turn runs, so a change inside the stage never moves its top
283
+ edge, with **two allowed shrinks, once per question and once per answer** (`forgetContent`):
284
+ - **the asking form**: each model's own question that opens (or, the second one on, finds opened) the turn in the history
285
+ (below): the stage shows that card alone (`stage_view.js place`, in the card's task);
286
+ - **the next step after a blocking card's answer** (`stage_view.js releaseHeldWait`, from `generationStarted`). The
287
+ `held-wait` class says it is due: set with `waiting`, cleared there, so a later step, which calls it again, does
288
+ nothing. What goes together: the live slots' waiting height, a raised cap, the tallest content seen. At the tap nothing
289
+ moves: the card collapses to its line inside the held frame and the stage's scroll stays, unless the line would be above
290
+ the view (a reader who scrolled down a card taller than the stage), when it comes back to the view's top
291
+ (`settleAnsweredCard`).
292
+
293
+ One card raises the cap: a blocking approval too tall for the stage's view, a delegate's relayed one too
294
+ (`raiseForApproval`, `stage_frame.js fitsCap`). It opens at its question and command (`revealTop`). A model's own
295
+ question gets no room and no pill: its reply is in the history.
296
+
297
+ ## A turn opened in the history
298
+
299
+ When the model's own question blocks the turn after a reply (`ASK_CARD`: `data-kind="question"`, not relayed, placed in
300
+ the extras before the turn's end, with a reply from `stage_view.js askingGen`: live, the step whose call runs; in a
301
+ replay, below), the stage opens the turn in the history
302
+ (`stage_view.js openTurn`, `stage_opened.js`). Approvals, relayed and hook questions, a question with no reply, plugin
303
+ asking cards and the step limit keep the stage as it was (the asking slot, `drawAsking`).
304
+
305
+ | Piece | Where, from the opening to the turn's end |
306
+ |---|---|
307
+ | The prompt, the steps block (closed; its steps in order from now on, `turn_block.js inOrder`) and the rows the extras held | the history's end, in `handOffOrder`'s order (`history_end.js moveToHistoryEnd`) |
308
+ | The reply that asked: `.bubble.said` (`data-question-id`, `data-said-turn`, never `data-turn-id`: that marks an opening) | the history's end, in the card's task; raw, then its markdown; `.pending` ("asking you", the amber edge) while its card waits |
309
+ | Rows that arrive (`placeFor` `"opened"`: notes, steered prompts, commands, a card that stopped waiting) | the history's end, in arrival order |
310
+ | A card that waits (`stage_cards.js waitsInStage`: `PENDING`, `ASKS`, a warning) | the stage, as before; a promoted one shows the asking form (`.asking-form`: the status row and the card; the prompt, the live slots with the working set and the chip hidden) and a "↑ its reason" link in its summary |
311
+ | A promoted card answered or cancelled | right under its reason (`settle`), also after the turn's end; its own clamp is hidden while the reason is there (CSS) |
312
+ | Live slots, the streaming answer, the end line, the queued slot | the stage, as before; the hand-off appends what it still holds |
313
+
314
+ A turn released without its end (a lost `turn_completed`, the next turn's start) drops its reasons (`stage_opened.js
315
+ drop`) and leaves the rest; a late recap goes above an opened turn (`place`). The reload check's turn starts at its
316
+ opening: its prompt, else a wake's note (`data-opening-id`) right before it, notes that reached the history mid-turn
317
+ included (`wholeTurn`).
318
+
319
+ The stage says where the block is (`blockPlace`: cloud, answer, history; `data-block="history"` on the stage for
320
+ `refs.js turnBlockOf`); the chip and a tick reveal the block or a step in the history. **Follow:** every row that reaches
321
+ the history follows a reader who was at its end (`atHistoryEnd`, read before the change); a reason is read from its first
322
+ line instead, and the history is marked `data-reading` until that scroll ends so the bottom reserve's own follow
323
+ (`dock_reserve.js`) doesn't take the end back. A reader scrolled up is never moved. **The end fold** (`finishFold`, after
324
+ the pieces, in their task): the reasons go and each answered card's two-line clamp says it, as the turn reloads; the first
325
+ row in view after a reason keeps its place when the history has room to scroll. The hand-off also waits while the pointer
326
+ or a selection is in a reason (`stage_watch.js alsoWatched`). The reload check gets the turn from its opening (`wholeTurn`).
327
+ **A reload or a resync** draws the same picture: `renderSessionView` replays the running turn (`data.replay`), in which
328
+ the asking call has completed when its `question_requested` comes (`TurnAccumulator.join_events`), so the asking step is
329
+ the last one whose last call is `ask_user_question` and whose reply no question card of this page took yet
330
+ (`stage_view.js askingGen`, `asked`: a later card of that step never reuses it; live, the step whose call runs). The
331
+ replayed card opens the turn as live; a question answered earlier in the turn settles under its reason with the
332
+ replayed `question_answered`, and `releaseHeldWait` reads a pending card, not the `waiting` class the replay's one task
333
+ hasn't refreshed yet.
289
334
 
290
335
  ## Frames
291
336
 
@@ -328,7 +373,7 @@ generation age, `delivery_line.js genAge`) reads "thinking quietly 0:50 · no to
328
373
  A phone shows the short text. Nothing is said while a tool runs (its own clock, `.ts-tool-clock`, from 10 s instead),
329
374
  a blocking card waits, the live timing line has a note (a retry, plugins' setup: `live_timing.js note`), the turn has
330
375
  ended, or for 5 s after the page shows again (`visibilitychange`). The open session's stream not live for a second
331
- (`streamControl` gone: `workerGone` until the resync streams again) reads "reconnecting… · events paused" and wins.
376
+ (`session_sync.js`'s stream handle gone: `workerGone` until the resync streams again) reads "reconnecting… · events paused" and wins.
332
377
  It ticks on the live timing line's clock (app.js `createLiveTurn`'s `onTick` → `turnDom.tick`; 200 ms, then 1 s) and
333
378
  writes only when its text changes. Expanded, it is a right-aligned span in the now row, its tint by level
334
379
  (`.ts-now[data-stall]`); where the now row doesn't show (a collapsed stage, a plain turn's), its short text follows
@@ -346,9 +391,9 @@ dropped. **`latest.js`** is the guard:
346
391
  ask out stale (a close, a reset). For a list that is re-read.
347
392
 
348
393
  On it: `context_chips.js`, `project_picker.js`, `participants_panel.js` (`load`), `cards_place.js`
349
- (`refreshCardBodies`), `stream_handlers.js` (`answer_display`), `working_set_view.js` (`fetchServer`) and app.js's
350
- turn-end re-reads (`readTurnEnd`, `refreshTimingFromSession`, `mergeTurnTiming`) and init-row timers. Still by hand
351
- (the id decides more than "drop it"): app.js `resync`/`retryResync` (the re-read budget, `resyncAgain`), the stream's
394
+ (`refreshCardBodies`), `stream_handlers.js` (`answer_display`), `working_set_view.js` (`fetchServer`), the
395
+ turn-end re-reads (`session_view.js` `readTurnEnd`, app.js's `refreshTimingFromSession`, `mergeTurnTiming`) and app.js's init-row timers. Still by hand
396
+ (the id decides more than "drop it"): `session_sync.js` `resync`/`retryResync` (the re-read budget, `resyncAgain`), the stream's
352
397
  close, `session_actions.js` (continue/review open another session on purpose), `send_turn.js` (a failure for another
353
398
  session becomes a toast), and `participant.js` (its own `loadSeq`, the separate page). A new await in a component
354
399
  uses `latest.js`.
@@ -368,7 +413,7 @@ uses `latest.js`.
368
413
  |---|---|---|
369
414
  | The hub, `GET /api/events` (`data.js openEvents`) | app.js `openSessionEvents` (scoped by `?dir`) | `snapshot` then `session` / `session_gone` → `applySessionEvent` → `allSessions`; EventSource reconnects itself (a fresh snapshot); `onClosed` (a proxy sign-in on reconnect): probe, reopen after `EVENTS_REOPEN_MS` |
370
415
  | A second hub stream, unscoped | `notifications.js` (`allEvents`) on a project's page | the Home Screen app's device tidy-up across projects |
371
- | The open session, `GET /api/sessions/:id/stream?from_seq=` (`data.js openStream`) | app.js `startStream` from `store.current.streamSeq` | events → `stream_handlers.js`. It closes itself on an error; the page resyncs (`resync`: a fresh render and a new stream from its cursor), once at once when it had opened, else after `STREAM_RETRY_MS`. Meanwhile a turn the stage holds reads "reconnecting…" (Quiet, under Frames), and the Bridge's `: ping` is invisible to the page. A re-read that can't reach chi web keeps the history it drew (`resync_reach.js`): the session bar's status chip says "reconnecting…" while `retryResync` tries, "can't reach chi web" once the tries ran out (`store.current.reach`), and any hub event for the session then re-reads it (`followSelectedSession`); the next drawn re-read clears it. Only a first load (select's "Loading…") shows the error in the history |
416
+ | The open session, `GET /api/sessions/:id/stream?from_seq=` (`data.js openStream`) | `session_sync.js` `startStream` from `store.current.streamSeq` | events → `stream_handlers.js`. It closes itself on an error; the page resyncs (`resync`: a fresh render and a new stream from its cursor), once at once when it had opened, else after `STREAM_RETRY_MS`. Meanwhile a turn the stage holds reads "reconnecting…" (Quiet, under Frames), and the Bridge's `: ping` is invisible to the page. A re-read that can't reach chi web keeps the history it drew (`resync_reach.js`): the session bar's status chip says "retrying" while `retryResync` tries, "offline" once the tries ran out (`store.current.reach`; short words that fit the chip's reserved width, the full words in its tooltip), but only while no turn runs: during a turn the stage's "reconnecting…" is the one signal (on a phone the bar can hide its status) and the chip keeps the turn's word, and any hub event for the session then re-reads it (`followSelectedSession`); the next drawn re-read clears it. Only a first load (select's "Loading…") shows the error in the history |
372
417
  | The participant stream | `participant.js connect` | listens for `STREAM_EVENTS`, which is `Web::ParticipantView::EVENTS` (checked by `spec/web/participant_view_spec.rb`); reopened from fresh data when CLOSED |
373
418
 
374
419
  A new event type for the owner page is a handler in `stream_handlers.js` (the participant view spec makes it decide
data/docs/memory.md CHANGED
@@ -631,8 +631,7 @@ memory still marked as behind an earlier upgrade keeps its mark either way.
631
631
  - **`chi bundle status`** says per file what is `modified` (the uninstall's
632
632
  rule above: edited, or with nothing recorded to tell), `missing` or
633
633
  `unreadable`, and that a file stays behind and why. Its `issues=` counts files
634
- behind, missing or unreadable (and a plugin that won't load, or class-file hooks an older chi installed, which no
635
- longer load: `Hooks (N): not loaded`), not edits. `chi bundle status NAME`
634
+ behind, missing or unreadable (and a plugin that won't load), not edits. `chi bundle status NAME`
636
635
  lists the bundle's guardrail rules and scripts too (`Rules (N):`, `Scripts (N):`),
637
636
  each `[ok]`, `[missing]` or `[modified]`: edited, so the next install or upgrade
638
637
  replaces it, its copy kept in the trash. An edited or missing rule doesn't load
data/docs/sessions.md CHANGED
@@ -213,7 +213,11 @@ refuses a note. See [cli.md](cli.md#session-objectives) for the commands and
213
213
  [internals/objectives.md](internals/objectives.md) for the mechanism.
214
214
 
215
215
  The model can record a **move** with the `objectives` tool: a line on what it did or found for an objective, with
216
- optional evidence. A move shows as the tool's row in the turn, and `/objectives` shows each objective's latest one under
216
+ optional evidence and a state: `progress` (the default), `blocked` or `done`. `done` is the agent's claim, not a status:
217
+ the page and `/objectives` say "claims done" (or "blocked") beside the move, and you still mark it done yourself. chi
218
+ reads what the move's own turn ran before it: a done move whose last command failed, or that edited files again after a
219
+ command checked its edits, is marked `not backed: …` (muted, information only). A turn with no command marks nothing. A move
220
+ shows as the tool's row in the turn, and `/objectives` shows each objective's latest one under
217
221
  it. It is information only: only you change the list or a status, and it never approves anything. A move costs one
218
222
  generation when it's the step's only call. On a kit that doesn't declare the tool, `/toolkit add objectives` declares it
219
223
  (the model can also reach it with `call_tool`). A participant's turn is denied it.
@@ -232,13 +236,27 @@ A second tap while one runs asks nothing. Its cost is in the session's side line
232
236
  local server it answers after the running request. A participant can't reach it. See
233
237
  [internals/objectives.md](internals/objectives.md#check-this).
234
238
 
239
+ **The tracker** (`/objectives track`, or **Where are we?** in the web) is Check this for the whole list: one side request
240
+ reads the same record and answers one line per active objective, `done`, `progress`, `blocked` or `no sign`, with what in
241
+ the record shows it. It reads at most 8 active objectives (it says how many it left out), on the same model as Check
242
+ this. The lines come as a card and as `track: …` under each objective, beside the agent's own moves: where they disagree
243
+ (the agent claims done, the tracker sees no sign) is the thing to look at. A reading goes stale once the objective is
244
+ reworded or the conversation moves on. With `objectives.tracker: on` it also runs by itself after a turn of yours (a
245
+ prompt or a wake, not a participant's, not a `--non-interactive` run) that edited, wrote or ran a command and recorded no
246
+ move, while an objective is active; your next turn cancels a read still out. **With a hosted `objectives.check_model`
247
+ that sends up to 24,000 characters of the session's record off the machine after such a turn, without a tap.** It is
248
+ information only, as Check this is, can't open a file or run anything, and is refused during a participant's turn. See
249
+ [internals/objectives.md](internals/objectives.md#the-tracker).
250
+
235
251
  **In the web** a session with a list has a strip above the conversation: its objectives and how many are done (a phone
236
252
  shows one line, the one being worked on). A tap opens the list, where you add, mark done, drop, undo and tap a text to
237
253
  reword it, with no message and no turn. Mid-turn the strip has the change and says it applies after this turn. Each list
238
254
  in the conversation shows as pills, or as one line of what you changed. A turn's moves show as chips above its answer;
239
255
  Not yet on one (or in the list, for an objective with a move) sends `Not yet on O2 (…).` as a normal message. With the
240
256
  [decision-card](bundles.md#the-decision-card-bundle) bundle, the newest long answer offers its Short version in a card,
241
- which enters no history. A session with no list shows none of this. A participant doesn't see the list.
257
+ which enters no history. The newest turn that edited, wrote or ran a command and recorded no move says `no move
258
+ recorded` under its steps while an objective is active (information only; nothing asks the model for one). A session
259
+ with no list shows none of this. A participant doesn't see the list.
242
260
 
243
261
  ## Notes a turn leaves for the model
244
262
 
data/docs/testing.md CHANGED
@@ -22,7 +22,7 @@ with two rules only, `no-undef` (a name used but never imported or declared: a d
22
22
  style pass: add a rule only for a bug class it would have caught. It runs in about 2 s, in CI's `npm test` job and in
23
23
  `rake release:check`; `rake lint` stays RuboCop alone (CI's rubocop job has no node). A name that is also a browser
24
24
  global (`name`, `status`, `open`…) passes even when its import is gone: give an export such a name only with care.
25
- It also caps `app.js`'s size (`max-lines`; see docs/internals/web-frontend.md).
25
+ It also caps every web module's size and `app.js`'s own, lower (`max-lines`; see docs/internals/web-frontend.md).
26
26
  It also checks `spec/e2e/` for two things: `no-unused-vars`, and the Playwright twin of `Samagotchi/SpecSleep`: no `page.waitForTimeout`.
27
27
  Wait for the state (a locator's `expect`, `data-phase`, an animation's end through `waitForFunction`); time the page
28
28
  keeps (a pointer's dwell, a hold) runs on Playwright's `page.clock` (`install`, then `pauseAt` and `runFor`: the
@@ -158,8 +158,8 @@ continue's `context/sessions/<id>/left.json`, stored approvals
158
158
  (`guardrails/approvals.json`), and a participant's grant
159
159
  (`web-grants/grants.json`) with its `participants.json` sidecar, and the chi
160
160
  home (`home.json`). A corpus from
161
- 0.164.0 or before has none of those and skips them; a later one must hold them. 0.165.0's approvals (a list) are
162
- also read as recorded and wrapped in a versioned store, the shape a later chi writes.
161
+ 0.164.0 or before has none of those and skips them; a later one must hold them. 0.165.0's and 0.166.0's approvals are a list, which chi no longer reads: the main read skips them and a spec there
162
+ checks that the file is set aside. The corpus is always read from a copy, since a reader may rewrite or move what it reads.
163
163
  A corpus recorded after 0.165.0 also holds `wire/`: a worker's replies to `GET state`, `snapshot` (after a turn, and
164
164
  mid-turn with a prompt queued behind it) and `tail`, each `{route, status, body}`, and the session file it saved,
165
165
  recorded from a real Engine and Bridge (`script/release/compat_wire.rb`, `CompatWire`: a scripted kernel, read over the
@@ -761,7 +761,7 @@ module Samagotchi
761
761
  FEATURES = ["restart", "task_stop", "reparent", Delivery::QUEUE_FEATURE, ReplyWait::TURN_IDS_FEATURE,
762
762
  VerifyAnchor::FEATURE, ReviseAnchor::FEATURE,
763
763
  SessionInbox::UNQUEUE_FEATURE, Delivery::REVIEW_FEATURE, Delivery::PAIR_FEATURE, TurnDrawings::FEATURE,
764
- WorkerLink::ACTIVITY_FEATURE].freeze
764
+ WorkerLink::ACTIVITY_FEATURE, ObjectivesTrack::FEATURE].freeze
765
765
 
766
766
  # The routes, by method and what follows /session/:id/: a handler takes
767
767
  # the session id and the request body and returns [headers, status, body].
@@ -59,9 +59,8 @@ module Samagotchi
59
59
 
60
60
  # What the child sends: an edited file, which the copy's own shas can't
61
61
  # tell, a manifest key that doesn't parse (the copy holds the mirror's
62
- # value or none: InstalledManifest#key_problems), the class-file hooks
63
- # the record still has (they don't load), and Check's warnings and
64
- # errors, naming the installed bundle's folder rather than the copy's.
62
+ # value or none: InstalledManifest#key_problems), and Check's warnings
63
+ # and errors, naming the installed bundle's folder rather than the copy's.
65
64
  def answer_of(bundle)
66
65
  edited = MemoryBundle::ShippedUpdate.edited_executables(bundle.name, bundle).map do |file|
67
66
  Check::Finding.new(level: :warn, code: :edited, file: file, line: nil, fix: "chi bundle upgrade #{bundle.name}, or reinstall it",
@@ -70,7 +69,6 @@ module Samagotchi
70
69
  edited += bundle.manifest.key_problems.values.map do |message|
71
70
  Check::Finding.new(level: :error, code: :manifest, file: "manifest.yml", line: nil, message: message, fix: nil)
72
71
  end
73
- edited << retired_hooks(bundle) unless bundle.hooks.empty?
74
72
  edited = edited.map { |finding| { level: finding.level, text: finding.to_s } }
75
73
  installed_dir = MemoryBundle::Provenance.new(name: bundle.name).bundle_dir
76
74
  edited + MemoryBundle::InstalledCopy.with(bundle) do |dir|
@@ -82,16 +80,6 @@ module Samagotchi
82
80
  end
83
81
  private_class_method :answer_of
84
82
 
85
- # A 0.157 record's class-file hooks: they no longer load, and only an
86
- # upgrade from a source that has moved them (or an uninstall) clears it
87
- # (compat shim retired_class_file_hooks: Compat::SHIMS).
88
- def retired_hooks(bundle)
89
- Check::Finding.new(level: :warn, code: :"hooks-retired", file: "hooks/", line: nil,
90
- message: MemoryBundle::Manifest::HooksRetired::WORDS,
91
- fix: "chi bundle upgrade #{bundle.name} once its source hooks from plugin.rb, or chi bundle uninstall #{bundle.name}")
92
- end
93
- private_class_method :retired_hooks
94
-
95
83
  def died(why, prefix: true) = Found.new(level: "error", text: check_line(prefix ? "the check died: #{why}" : why))
96
84
  private_class_method :died
97
85
 
@@ -106,6 +106,9 @@ module Samagotchi
106
106
  chi bundle build --scope system --out ./my-bundle/ identity.md work.md
107
107
  TEXT
108
108
  TRASH_HELP = "Usage: chi bundle trash [--empty] [--dry-run] [--older-than DAYS]"
109
+ STATUS_HELP = "Usage: chi bundle status [<bundle>]"
110
+ DIFF_HELP = "Usage: chi bundle diff <bundle> [file]"
111
+ LIST_HELP = "Usage: chi bundle list"
109
112
 
110
113
  # The subcommands' flags: --help only; a word not starting with -- is
111
114
  # a positional (install's source, -h included). --scope takes whatever
@@ -134,6 +137,8 @@ module Samagotchi
134
137
  f.switch "--dry-run"
135
138
  f.value "--older-than"
136
139
  end
140
+ # status, diff and list take no flag: --help, else an unknown one.
141
+ NO_FLAGS = CLI::Flags.new(help: %w[--help], flag_pattern: /\A--/)
137
142
 
138
143
  # @param argv [Array<String>] the arguments after "bundle"
139
144
  def initialize(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr)
@@ -157,7 +162,7 @@ module Samagotchi
157
162
  when "uninstall" then uninstall(@argv[1..])
158
163
  when "status" then status(@argv[1..])
159
164
  when "diff" then diff(@argv[1..])
160
- when "list" then list
165
+ when "list" then list(@argv[1..])
161
166
  when "build" then build(@argv[1..])
162
167
  when "trash" then trash(@argv[1..])
163
168
  when "new" then new_bundle(@argv[1..])
@@ -536,7 +541,10 @@ module Samagotchi
536
541
  end
537
542
 
538
543
  def status(rest)
539
- name = rest.find { |a| !a.start_with?("--") }
544
+ parsed = parse_flags(NO_FLAGS, rest, "status", help: STATUS_HELP, max_positionals: 1, noun: "bundle")
545
+ return parsed if parsed.is_a?(Integer)
546
+
547
+ name = parsed.args.first
540
548
  require "json"
541
549
  if name
542
550
  st = Samagotchi::MemoryBundle::Status.bundle_status(name)
@@ -573,10 +581,6 @@ module Samagotchi
573
581
  commit = st.provenance.source_commit
574
582
  @stdout.puts " trust_level: #{trust}"
575
583
  @stdout.puts " source_commit: #{commit}" if commit
576
- unless st.retired_hooks.empty?
577
- @stdout.puts " Hooks (#{st.retired_hooks.size}): not loaded: #{Samagotchi::MemoryBundle::Manifest::HooksRetired::WORDS}"
578
- st.retired_hooks.each { |file, state| @stdout.puts " #{file} [#{state}]" }
579
- end
580
584
  print_assets("Rules", st.rules, " (edited after install: not loaded; reinstall the bundle)")
581
585
  print_assets("Scripts", st.scripts, " (edited after install: the next install replaces it, a copy kept in the trash)")
582
586
  if (plugin = st.plugin)
@@ -598,17 +602,15 @@ module Samagotchi
598
602
 
599
603
  st = Samagotchi::MemoryBundle::Status.bundle_status(bname)
600
604
  mods = st.files.values.count { |v| v[:behind] || v[:missing] || v[:unreadable] }
601
- hook_info = st.retired_hooks.empty? ? "" : " hooks=#{st.retired_hooks.size}"
602
605
  plugin = st.plugin
603
606
  mods += 1 if plugin && (plugin[:state] != "ok" || plugin[:requires_failure])
604
- mods += 1 unless st.retired_hooks.empty?
605
607
  # A rule that is missing or edited doesn't load; a script runs edited.
606
608
  mods += st.rules.values.count { |state| state != "ok" } + st.scripts.values.count("missing")
607
609
  mods += 1 if st.scope_error
608
610
  plugin_info = plugin ? " plugin=#{plugin[:file]}" : ""
609
611
  includes = st.provenance.includes
610
612
  includes_info = includes ? " includes=#{includes.join(",")}" : ""
611
- @stdout.puts " #{bname} v#{st.provenance.version}#{dev_label(st.provenance)} scope=#{status_scope(st)} files=#{st.files.size}#{hook_info}#{plugin_info}#{includes_info} issues=#{mods}"
613
+ @stdout.puts " #{bname} v#{st.provenance.version}#{dev_label(st.provenance)} scope=#{status_scope(st)} files=#{st.files.size}#{plugin_info}#{includes_info} issues=#{mods}"
612
614
  end
613
615
  end
614
616
  0
@@ -642,7 +644,10 @@ module Samagotchi
642
644
  def status_scope(st) = st.scope_error ? "#{st.scope} (unknown)" : st.scope
643
645
 
644
646
  def diff(rest)
645
- args = rest.reject { |a| a.start_with?("--") }
647
+ parsed = parse_flags(NO_FLAGS, rest, "diff", help: DIFF_HELP, max_positionals: 2)
648
+ return parsed if parsed.is_a?(Integer)
649
+
650
+ args = parsed.args
646
651
  bname = args[0]
647
652
  file_arg = args[1]
648
653
  if bname.nil? || bname.empty?
@@ -750,7 +755,10 @@ module Samagotchi
750
755
  @stdout.puts File.exist?(current) ? File.read(current) : "(missing)"
751
756
  end
752
757
 
753
- def list
758
+ def list(rest)
759
+ parsed = parse_flags(NO_FLAGS, rest, "list", help: LIST_HELP, max_positionals: 0)
760
+ return parsed if parsed.is_a?(Integer)
761
+
754
762
  listing = Samagotchi::MemoryBundle::Listing
755
763
  shipped = listing.shipped
756
764
  installed = listing.installed(shipped: shipped)
@@ -1018,7 +1026,7 @@ module Samagotchi
1018
1026
  # @return [CLI::Flags::Result, Integer] the result, or the exit status
1019
1027
  # after the help or an unknown flag (a value flag without its value
1020
1028
  # reads as one)
1021
- def parse_flags(flags, rest, sub, help:)
1029
+ def parse_flags(flags, rest, sub, help:, max_positionals: nil, noun: "argument")
1022
1030
  parsed = flags.parse(rest)
1023
1031
  if parsed.help
1024
1032
  @stdout.puts help
@@ -1028,6 +1036,21 @@ module Samagotchi
1028
1036
  @stderr.puts "Unknown bundle #{sub} flag: #{parsed.error.arg}"
1029
1037
  return CLI::Exit::USAGE
1030
1038
  end
1039
+ if max_positionals && parsed.args.size > max_positionals
1040
+ extra = parsed.args[max_positionals..]
1041
+ count = if max_positionals == 1
1042
+ "one"
1043
+ else
1044
+ max_positionals == 2 ? "two" : max_positionals.to_s
1045
+ end
1046
+ allowed = if max_positionals.zero?
1047
+ "no #{noun}s"
1048
+ else
1049
+ "at most #{count} #{max_positionals == 1 ? noun : "#{noun}s"}"
1050
+ end
1051
+ @stderr.puts "chi bundle #{sub} takes #{allowed} (unexpected #{extra.join(", ")})"
1052
+ return CLI::Exit::USAGE
1053
+ end
1031
1054
  parsed
1032
1055
  end
1033
1056
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: samagotchi-system
3
- version: 0.166.0
3
+ version: 0.168.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:
@@ -35,6 +35,16 @@ module Samagotchi
35
35
  Exit::USAGE
36
36
  end
37
37
 
38
+ # The one refusal of a --format value the command doesn't print
39
+ # (nil, no --format, is the text). The caller returns what it gives.
40
+ # @param formats [Array<String>] the values the command takes
41
+ # @return [Integer, nil] the usage exit status, or nil for a format it takes
42
+ def format_refusal(format, formats = %w[text json])
43
+ return nil if format.nil? || formats.include?(format)
44
+
45
+ usage_error("unknown format #{format.inspect}: use --format #{formats.join("|")}")
46
+ end
47
+
38
48
  # +argv+ through +flags+ (a Flags), help and usage errors done.
39
49
  # @return [Flags::Result, Integer] the result, or the exit status
40
50
  # after the help (0) or a usage error (2)
@@ -18,19 +18,7 @@ module Samagotchi
18
18
  Shim.new(id: :cards_v1_seed, added_in: "0.151.0", remove_after: "0.170.0",
19
19
  files: ["lib/samagotchi/bridge/card_store.rb"],
20
20
  what: "CardStore#seed_v1 reads a cards.json from before the turn log; its comment says a retention " \
21
- "period after the release that wrote version 2 (0.151.0, 2026-11-05)"),
22
- Shim.new(id: :retired_class_file_hooks, added_in: "0.158.0", remove_after: "0.166.0",
23
- files: ["lib/samagotchi/extension_load.rb", "lib/samagotchi/memory_bundle/status.rb",
24
- "lib/samagotchi/bundle_command/installed_check.rb"],
25
- what: "a 0.157 install record's class-file hooks: announced as not loading, shown and checked until " \
26
- "an upgrade or uninstall clears them (installed state, not protocol)"),
27
- Shim.new(id: :approvals_array_read, added_in: "0.166.0", remove_after: nil,
28
- files: ["lib/samagotchi/guardrails/approvals.rb"],
29
- what: "Approvals#parse reads approvals.json as the list 0.165 and before write, beside the versioned store"),
30
- Shim.new(id: :approvals_array_write, added_in: "0.166.0", remove_after: "0.166.0",
31
- files: ["lib/samagotchi/guardrails/approvals.rb"],
32
- what: "Approvals#update writes a list (or no file) back as a list, since a 0.165 reader sets a " \
33
- "versioned store aside; from 0.167 a write is versioned (and the corpus records that)")
21
+ "period after the release that wrote version 2 (0.151.0, 2026-11-05)")
34
22
  ].freeze
35
23
 
36
24
  module_function
@@ -262,6 +262,9 @@ module Samagotchi
262
262
 
263
263
  # Check this (ObjectivesCheck): a cheap configured model for its one side request; nil is the session's.
264
264
  Entry.new(key: "objectives.check_model", yaml_path: %w[objectives check_model], type: :string, default: nil, expose: %i[config], lifecycle: :next_matching_turn_display_poll_write),
265
+ # The tracker (ObjectivesTrack): on, it also reads the list by itself after an owner's turn that did work and
266
+ # recorded no move (on objectives.check_model); off, only /objectives track and Where are we? do.
267
+ Entry.new(key: "objectives.tracker", yaml_path: %w[objectives tracker], type: :enum, default: "off", expose: %i[config], enum_values: %w[off on], lifecycle: :next_matching_turn_display_poll_write),
265
268
  # System 1 on the objectives (ObjectivesAudit): audit saves a yes/no per active objective on what comes in and goes
266
269
  # out, acted on by nothing; off (no conversation text goes to a System 1 host for it). Host and model: system_one.*.
267
270
  Entry.new(key: "objectives.system_one", yaml_path: %w[objectives system_one], type: :enum, default: "off", expose: %i[config], enum_values: %w[off audit], lifecycle: :next_matching_turn_display_poll_write),
@@ -249,7 +249,8 @@ module Samagotchi
249
249
 
250
250
  def run_ls(options, args)
251
251
  format = options[:format]
252
- return usage_error("unknown format #{format.inspect}: use --format text|json") unless [nil, "text", "json"].include?(format)
252
+ refused = format_refusal(format)
253
+ return refused if refused
253
254
 
254
255
  targets = targets(options, args) or return CLI::Exit::FAILED
255
256
  rows = targets.flat_map { |target| @access.context_entries(target).map { |entry| row(target, entry) } }