samagotchi 0.182.0 → 0.184.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +107 -1
- data/bin/chi +3 -1
- data/docs/architecture.md +22 -11
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +103 -4
- data/docs/cli.md +28 -6
- data/docs/configuration.md +4 -2
- data/docs/guardrails.md +16 -1
- data/docs/internals/block-renderers.md +58 -3
- data/docs/internals/bridge.md +14 -6
- data/docs/internals/bundles.md +26 -5
- data/docs/internals/engine.md +20 -9
- data/docs/internals/participants.md +1 -1
- data/docs/internals/prompt-caching.md +8 -1
- data/docs/internals/remote-sessions.md +40 -5
- data/docs/internals/web-frontend.md +96 -31
- data/docs/internals/web-push.md +11 -0
- data/docs/internals/working-set.md +239 -7
- data/docs/mcp-server.md +84 -0
- data/docs/memory.md +2 -1
- data/docs/plugins.md +309 -22
- data/docs/scheduling.md +14 -0
- data/docs/sessions.md +4 -4
- data/docs/sub-agent.md +9 -0
- data/docs/testing.md +3 -1
- data/docs/thin-clients.md +165 -0
- data/lib/samagotchi/bridge/pending_card.rb +4 -3
- data/lib/samagotchi/bridge/sse_writer.rb +16 -15
- data/lib/samagotchi/bridge.rb +59 -68
- data/lib/samagotchi/bridge_client.rb +12 -4
- data/lib/samagotchi/bundle_command/api_calls.rb +1 -1
- data/lib/samagotchi/bundle_command/check.rb +55 -20
- data/lib/samagotchi/bundle_command.rb +50 -21
- data/lib/samagotchi/bundle_manifest.rb +105 -4
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/mcp/client.rb +260 -0
- data/lib/samagotchi/bundles/mcp/content.rb +107 -0
- data/lib/samagotchi/bundles/mcp/http_client.rb +432 -0
- data/lib/samagotchi/bundles/mcp/manifest.yml +13 -5
- data/lib/samagotchi/bundles/mcp/oauth.rb +814 -0
- data/lib/samagotchi/bundles/mcp/plugin.rb +556 -574
- data/lib/samagotchi/bundles/mcp/tools.rb +232 -0
- data/lib/samagotchi/bundles/system/config_modification_protocol.md +10 -2
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +7 -2
- data/lib/samagotchi/cli/parent_wait.rb +5 -3
- data/lib/samagotchi/command_intake.rb +7 -0
- data/lib/samagotchi/commands/registry.rb +8 -3
- data/lib/samagotchi/continue_offer.rb +24 -15
- data/lib/samagotchi/engine/block_fix.rb +4 -4
- data/lib/samagotchi/engine/cards.rb +14 -5
- data/lib/samagotchi/engine/events.rb +10 -15
- data/lib/samagotchi/engine/models.rb +1 -1
- data/lib/samagotchi/engine/plugins.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -1
- data/lib/samagotchi/engine/session.rb +14 -6
- data/lib/samagotchi/engine/side_requests.rb +1 -1
- data/lib/samagotchi/engine/sign_in.rb +142 -0
- data/lib/samagotchi/engine/turn_end.rb +3 -3
- data/lib/samagotchi/engine/turn_helpers.rb +4 -3
- data/lib/samagotchi/engine.rb +43 -27
- data/lib/samagotchi/engine_snapshots.rb +1 -1
- data/lib/samagotchi/guardrail_wiring.rb +3 -1
- data/lib/samagotchi/guardrails/protected_paths.rb +51 -2
- data/lib/samagotchi/guardrails/verdict.rb +3 -2
- data/lib/samagotchi/hold_stop.rb +4 -4
- data/lib/samagotchi/idle_recap.rb +19 -11
- data/lib/samagotchi/idle_reminders.rb +7 -5
- data/lib/samagotchi/idle_scheduler.rb +7 -10
- data/lib/samagotchi/installed_bundles/dir.rb +37 -0
- data/lib/samagotchi/installed_bundles/manifest.rb +7 -1
- data/lib/samagotchi/installed_bundles/plugin_ref.rb +9 -5
- data/lib/samagotchi/installed_bundles/record.rb +3 -2
- data/lib/samagotchi/installed_bundles/standing.rb +3 -1
- data/lib/samagotchi/llm/http.rb +96 -5
- data/lib/samagotchi/mcp_command.rb +110 -0
- data/lib/samagotchi/mcp_server/http.rb +112 -0
- data/lib/samagotchi/mcp_server/protocol.rb +263 -0
- data/lib/samagotchi/mcp_server/stdio.rb +93 -0
- data/lib/samagotchi/mcp_server/text.rb +155 -0
- data/lib/samagotchi/mcp_server/tools.rb +246 -0
- data/lib/samagotchi/memory_bundle/asset_installer.rb +40 -12
- data/lib/samagotchi/memory_bundle/builder.rb +20 -2
- data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
- data/lib/samagotchi/memory_bundle/installer.rb +16 -3
- data/lib/samagotchi/memory_bundle/provenance.rb +18 -1
- data/lib/samagotchi/memory_bundle/shas.rb +6 -4
- data/lib/samagotchi/memory_bundle/shipped_update.rb +7 -3
- data/lib/samagotchi/memory_bundle/status.rb +15 -6
- data/lib/samagotchi/memory_bundle/uninstaller.rb +9 -4
- data/lib/samagotchi/model_notes.rb +34 -12
- data/lib/samagotchi/plugin/api.rb +6 -1
- data/lib/samagotchi/plugin/card.rb +36 -11
- data/lib/samagotchi/plugin/context.rb +63 -6
- data/lib/samagotchi/plugin/http.rb +40 -15
- data/lib/samagotchi/plugin/http_errors.rb +15 -0
- data/lib/samagotchi/plugin/http_stream.rb +86 -0
- data/lib/samagotchi/plugin/http_transport.rb +58 -16
- data/lib/samagotchi/plugin/loader.rb +18 -11
- data/lib/samagotchi/plugin/secrets.rb +266 -0
- data/lib/samagotchi/plugin/sign_in.rb +392 -0
- data/lib/samagotchi/plugin/sse_reader.rb +103 -0
- data/lib/samagotchi/prompt_files.rb +11 -4
- data/lib/samagotchi/prompt_layout.rb +88 -0
- data/lib/samagotchi/prompt_part.rb +82 -20
- data/lib/samagotchi/queued_command.rb +28 -4
- data/lib/samagotchi/recap_setup.rb +13 -4
- data/lib/samagotchi/ref.rb +3 -2
- data/lib/samagotchi/relay_verifier.rb +8 -7
- data/lib/samagotchi/relay_watcher.rb +4 -4
- data/lib/samagotchi/reply_wait.rb +6 -3
- data/lib/samagotchi/run_options.rb +2 -1
- data/lib/samagotchi/schedule_command.rb +18 -4
- data/lib/samagotchi/schedules.rb +40 -8
- data/lib/samagotchi/send_command.rb +54 -41
- data/lib/samagotchi/session_access/ask.rb +285 -0
- data/lib/samagotchi/session_access/contract.rb +5 -0
- data/lib/samagotchi/session_access/exchange/token.rb +101 -0
- data/lib/samagotchi/session_access/exchange.rb +176 -0
- data/lib/samagotchi/session_access/local.rb +34 -6
- data/lib/samagotchi/session_access/remote.rb +4 -1
- data/lib/samagotchi/session_command_catalog.rb +10 -0
- data/lib/samagotchi/session_commands.rb +17 -0
- data/lib/samagotchi/session_config.rb +4 -4
- data/lib/samagotchi/session_inbox.rb +15 -0
- data/lib/samagotchi/session_manager/delivery.rb +8 -4
- data/lib/samagotchi/session_observer.rb +27 -0
- data/lib/samagotchi/steer_cut.rb +4 -3
- data/lib/samagotchi/system_prompt.rb +196 -161
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +4 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -0
- data/lib/samagotchi/testing/boundary.rb +4 -0
- data/lib/samagotchi/testing/bundle.rb +48 -2
- data/lib/samagotchi/testing/fake_http.rb +60 -15
- data/lib/samagotchi/testing/host.rb +4 -1
- data/lib/samagotchi/testing/recorder.rb +45 -5
- data/lib/samagotchi/tools/memory.rb +11 -3
- data/lib/samagotchi/tools/tool_index.rb +14 -3
- data/lib/samagotchi/turn_stages/warmup.rb +2 -2
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +9 -8
- data/lib/samagotchi/web/ask_routes.rb +362 -0
- data/lib/samagotchi/web/mcp_route.rb +91 -0
- data/lib/samagotchi/web/public/app.js +2 -3
- data/lib/samagotchi/web/public/block_frame.js +72 -11
- data/lib/samagotchi/web/public/block_host.js +44 -8
- data/lib/samagotchi/web/public/block_regions.js +126 -0
- data/lib/samagotchi/web/public/card.js +22 -9
- data/lib/samagotchi/web/public/card_actions.js +21 -0
- data/lib/samagotchi/web/public/card_kinds.js +1 -1
- data/lib/samagotchi/web/public/card_registry.js +3 -2
- data/lib/samagotchi/web/public/data.js +15 -12
- data/lib/samagotchi/web/public/delete_sheet.js +231 -169
- data/lib/samagotchi/web/public/diagram_wiring.js +28 -0
- data/lib/samagotchi/web/public/format.js +3 -0
- data/lib/samagotchi/web/public/index.html +52 -7
- data/lib/samagotchi/web/public/more_sheet.js +6 -4
- data/lib/samagotchi/web/public/picture_regions.js +243 -0
- data/lib/samagotchi/web/public/picture_viewer.js +113 -12
- data/lib/samagotchi/web/public/refs.js +5 -3
- data/lib/samagotchi/web/public/region_hit.js +144 -0
- data/lib/samagotchi/web/public/removal_sheet_model.js +274 -0
- data/lib/samagotchi/web/public/running_tasks.js +3 -17
- data/lib/samagotchi/web/public/session_actions.js +96 -100
- data/lib/samagotchi/web/public/working_set_view.js +167 -21
- data/lib/samagotchi/web/public/ws_part_peek.js +277 -0
- data/lib/samagotchi/web/public/ws_peek.js +3 -1
- data/lib/samagotchi/web/public/ws_preview.css +30 -0
- data/lib/samagotchi/web/public/ws_reader.js +7 -3
- data/lib/samagotchi/web/public/ws_sections.js +37 -7
- data/lib/samagotchi/web/push/notifier.rb +33 -6
- data/lib/samagotchi/web/server.rb +1 -1
- data/lib/samagotchi/web/session_access_routes.rb +14 -11
- data/lib/samagotchi/web/session_control.rb +31 -9
- data/lib/samagotchi/web/session_create.rb +2 -2
- data/lib/samagotchi/web/session_hub.rb +26 -4
- data/lib/samagotchi/web/working_set_routes.rb +93 -5
- data/lib/samagotchi/worker/child_side.rb +3 -2
- data/lib/samagotchi/worker/command_queue.rb +13 -13
- data/lib/samagotchi/worker/leave.rb +3 -3
- data/lib/samagotchi/worker/scratch.rb +6 -6
- data/lib/samagotchi/worker/signal_grace.rb +6 -5
- data/lib/samagotchi/worker/startup.rb +3 -3
- data/lib/samagotchi/worker/wake_turns.rb +4 -4
- data/lib/samagotchi/worker.rb +32 -21
- data/lib/samagotchi/worker_exit_claim.rb +1 -1
- data/lib/samagotchi/worker_idle_exit.rb +18 -9
- data/lib/samagotchi/worker_inbound.rb +12 -7
- data/lib/samagotchi/worker_link.rb +2 -2
- data/lib/samagotchi/worker_participant_gate.rb +9 -7
- data/lib/samagotchi/worker_task_wakes.rb +7 -5
- data/lib/samagotchi/working_set.rb +162 -90
- data/lib/samagotchi/working_set_locator.rb +221 -0
- data/lib/samagotchi/working_set_own_changes.rb +221 -0
- data/lib/samagotchi/working_set_part.rb +281 -0
- metadata +36 -1
|
@@ -14,7 +14,8 @@ by `npm run e2e` (`spec/e2e/`). `app.js` has no unit spec of its own; `viewer_bo
|
|
|
14
14
|
**Every module has a size cap, `app.js` its own**: `npm run lint` fails past `max-lines` in `eslint.config.js`
|
|
15
15
|
(counted as `wc -l` counts, comments and blank lines too). Every `public/*.js` module: 1200 (`samagotchi/module-size`,
|
|
16
16
|
about 10% over the largest, `turn_block.js`), so a module near it splits rather than becoming the next `app.js`.
|
|
17
|
-
`app.js` (`samagotchi/app-size`):
|
|
17
|
+
`app.js` (`samagotchi/app-size`): 1637, its size once the diagrams' wiring went into `diagram_wiring.js`; down from 1638,
|
|
18
|
+
its size once the lightbox went into `picture_viewer.js`, itself down from 1649, its
|
|
18
19
|
size plus 50 once the session-open flow went into `session_sync.js` and `session_view.js`, itself ratcheted down from 2000, itself down from 2250 when the versions, the owner's claim links and
|
|
19
20
|
Verify, the composer's mode and the strip's hide went into modules of their own. A new feature goes into a module of
|
|
20
21
|
its own, wired from `app.js` in a few lines; a refactor that shrinks `app.js` ratchets its cap down with it. Never
|
|
@@ -29,9 +30,14 @@ on an existing module, imported by a new version of another, then finds the old
|
|
|
29
30
|
page. A factory dep a new version stops passing is the same hazard the other way round: the store's redraws took
|
|
30
31
|
`updateInfoBar` and the chip controls out of `stream_handlers.js`'s deps (and `updateInfoBar`/`updateComposerMode`
|
|
31
32
|
out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
|
|
32
|
-
until a reload, so the risk is a mixed cache, not an open tab.
|
|
33
|
+
until a reload, so the risk is a mixed cache, not an open tab. An export a new version stops importing stays until
|
|
34
|
+
the next release (its baseline refresh) for the same reason, marked as kept for an older cached module (the delete
|
|
35
|
+
sheet still keeps `isChained` and `format.js deleteConfirmText` that way; and `ws_peek.js`'s `PEEK_WIDTH`, which 0.183.0's
|
|
36
|
+
`working_set_view.js` imports though the view is 520 wide always now: `ws_part_peek_mixed_cache.test.js` loads this view
|
|
37
|
+
with 0.183.0's `ws_reader.js` and `ws_peek.js`, and 0.183.0's view with this `ws_reader.js`, from
|
|
38
|
+
`spec/web/public/fixtures/v0.183.0/`). `answer_fold.js`, `details_motion.js`,
|
|
33
39
|
`turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
|
|
34
|
-
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (
|
|
40
|
+
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `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), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) 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).
|
|
35
41
|
|
|
36
42
|
## One page, every viewer
|
|
37
43
|
|
|
@@ -380,30 +386,58 @@ placed at, so `chip_popover.js` places it, marks `aria-expanded` and gives focus
|
|
|
380
386
|
`[data-anchor-stand-in]` (⋯). Rows and actions draw into fixed slots, so a row that joins keeps the focus where it was.
|
|
381
387
|
The e2e reach an item wherever it is with `spec/e2e/support/layout.js` `clickBarItem` (the row, else ⋯'s `[data-row]`).
|
|
382
388
|
|
|
383
|
-
**
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
`
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
`
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
(
|
|
402
|
-
|
|
403
|
-
|
|
389
|
+
**The delete sheet** (`delete_sheet.js`, its words `removal_sheet_model.js`; docs/sessions.md, Deleting a session and
|
|
390
|
+
Session chains → Deleting a link; the design: https://claude.ai/artifact/1A3TL2kkz8a2Pv8obi4jsj): every Delete, and an
|
|
391
|
+
Archive the server refuses, asks in one sheet instead of the browser's `confirm()` / `alert()`. Before anything happens
|
|
392
|
+
it says what goes, what is stopped first and what stays, with one button that names the outcome.
|
|
393
|
+
- **Where.** In ⋯'s menu, Delete always takes the panel as the sheet's host (`createMoreSheet`'s `onDelete` →
|
|
394
|
+
`session_actions.js deleteIn`, which answers true for any session): the panel draws the sheet in its place (a
|
|
395
|
+
subview; ‹ More, `del:back`, draws the list again; a redraw keeps the subview), so no second popover opens inside
|
|
396
|
+
More's click (a popover opened there would see that click as outside and close). A card's ✕ opens it at the card
|
|
397
|
+
(`createDeleteSheet`, on `chip_popover.js` with `SHEET_TALL`: a bottom sheet on a phone, its buttons full width).
|
|
398
|
+
Both shells keep one live host: a `host(anchor, id)` or a Delete in ⋯ makes a new one, and a flow whose host is no
|
|
399
|
+
longer the live one (a ✕ on another card while the first plan was read) draws and acts on nothing.
|
|
400
|
+
- **What it says** comes from `GET /api/sessions/:id/delete_plan`, fetched as it opens, for every session: the
|
|
401
|
+
server's own plan and refusals (`SessionChain::Delete::Preview`, the code the delete runs), so the sheet and the
|
|
402
|
+
delete can't disagree. `deleteChoices(session, plan, sessions)` is the model. A session in no chain:
|
|
403
|
+
`removal_sheet_model.js sessionSheetModel` → `{title, groups, button, stops, foot, tasks}`, its rows from
|
|
404
|
+
`sheetGroups(link)`: **Goes** (its history; the stopped delegates of `delegates.delete`, named from the page's list
|
|
405
|
+
by `format.js cardName`, else the short id; three, then `+N more`), **Stopped first** (`worker`: "Its worker (idle)"
|
|
406
|
+
or "Its running turn"; the `running` tasks through `running_tasks.js tasksLine`, a delegate's with its id in front),
|
|
407
|
+
**Stays** (the running delegates of `delegates.leave`, with the stopped ones under them; the tasks chi can't verify or
|
|
408
|
+
read, never signalled). A chained one keeps its two choices ("this link", "the whole chain"), each with its first
|
|
409
|
+
lines, then its own Stopped first / Stays lines (`choiceTail`). A refusal the plan carries (a one-turn run, a
|
|
410
|
+
schedule, a continue under way) is the "Can't delete … now" view with only Close (`cantModel`); a plan that can't be
|
|
411
|
+
read is the same view.
|
|
412
|
+
- **The button's words** (`buttonWords`): it names the running work it ends: `Stop them and delete` (`Stop it …` for
|
|
413
|
+
one task), `Stop the turn and delete`; an idle worker is only a row and the button stays `Delete`; ` · N sessions`
|
|
414
|
+
when the tap takes more than one session: every session it deletes, the stopped delegates too (`Delete this link · 2
|
|
415
|
+
sessions` with one; the whole chain counts its links and theirs, a step past the mock-up's case 8, by the owner's word); a chain's choices say `Stop 2 tasks
|
|
416
|
+
and delete this link`. While the tap runs it says `Stopping…` (tasks or a turn) or `Deleting…`.
|
|
417
|
+
The sheet opens with focus on Cancel (× or ‹ More while there is none), so a stray Enter never deletes or archives.
|
|
418
|
+
Closed while the tap runs, a refusal that comes after is a sticky toast (`failed` on a host no longer live).
|
|
419
|
+
- **The tap** sends the choice's `digest` (`expect=`) and, whenever the choice's task listing isn't empty, `stopTasks`
|
|
420
|
+
with the ids of its `running` tasks (`stopTasksOptions`; `data.js` sends `stop_tasks=true&tasks=<id,id>`, `tasks=`
|
|
421
|
+
when it lists only records chi can't verify, so such a session can still be deleted and nothing unnamed is stopped).
|
|
422
|
+
A `409 plan_changed` and a `409 tasks_running` (a task that started since) both re-read the plan and show it with
|
|
423
|
+
"What this deletes changed; check again." Any other refusal `runDeleteFlow` shows in the sheet (`refusalModel`: a
|
|
424
|
+
moved delegate that can't go back offers "Stop its worker, then delete" only when the 409 says `stoppable`; it stops
|
|
425
|
+
each, retries only once the stop answers `released`, and says so otherwise, never looping, one stop at a time). While
|
|
426
|
+
it stops, the refusal view says `Stopping…` with the stop choice and Cancel off; if the sheet closes meanwhile, it
|
|
427
|
+
goes on with the delete and puts the delete toast or a sticky `failed` refusal in a toast.
|
|
428
|
+
- **Archive** stays one tap and the Undo toast when nothing is in the way. Its 409 opens the same sheet
|
|
429
|
+
(`session_actions.js setArchived` → `runDeleteFlow` with `archive: {refusal}`): `tasks_running` is
|
|
430
|
+
`archiveSheetModel` (Hidden: it and the 409's `sessions` − 1 delegates; Stopped first: the tasks; `Stop them and
|
|
431
|
+
archive`, its button sending the named ids the same way); a task that started since re-shows it with "What this
|
|
432
|
+
archives changed; check again."; any other refusal is "Can't archive … now". The sheet is at the control tapped:
|
|
433
|
+
⋯ for the open session's (`toggleArchiveSelected` passes it), else the card's archive button with a box, found by
|
|
434
|
+
`[data-arch="<id>"]` (app.js's wrapper passes no anchor). A 409 that comes once the shell shows another session's
|
|
435
|
+
sheet (opened while the archive was out) leaves that sheet and is a sticky toast (`latest.js stillOn` on the shell's
|
|
436
|
+
`openFor`). An unarchive that fails is a sticky toast. A batch archive
|
|
437
|
+
is untouched (`archiveOne` passes nothing, and skips a session with running tasks).
|
|
404
438
|
After a delete, `listAfterDelete` drops the `deleted` ids and un-archives the `unarchived` ones in the store, the
|
|
405
|
-
selection clears when it went, and the toast (`deleteToast`)
|
|
406
|
-
|
|
439
|
+
selection clears when it went, and the toast (`deleteToast`) says what went, what was stopped and what stays, with
|
|
440
|
+
"Open" for the link that came back or a delegate left running.
|
|
407
441
|
|
|
408
442
|
## Safe areas
|
|
409
443
|
|
|
@@ -442,7 +476,8 @@ kept: every open starts fitted.
|
|
|
442
476
|
moves, Ctrl/Cmd + wheel zooms at the cursor (a Chromium trackpad pinch is a ctrl + wheel), by `exp(-deltaY ×
|
|
443
477
|
0.01)`, not fixed steps. Safari's `gesturestart`/`change`/`end` are always prevented (they would zoom the page) and
|
|
444
478
|
applied only while no touch pointer is down: that is a Mac trackpad; iOS fires them beside the pointers for a
|
|
445
|
-
finger pinch, and applying both would double it. A double tap or click (two ups
|
|
479
|
+
finger pinch, and applying both would double it. A double tap or click (two ups within 300 ms, neither a move: past 4 px for a mouse, 10 for a finger,
|
|
480
|
+
as |dx| + |dy|)
|
|
446
481
|
goes to max(2.5 × fit, natural) at that point, or back to fit when closer than fit. The `<img>` is never
|
|
447
482
|
dragged natively (`draggable=false`, `dragstart` prevented, `-webkit-user-drag:none`, `pointer-events:none`) and
|
|
448
483
|
has no iOS long-press sheet (`-webkit-touch-callout:none`).
|
|
@@ -455,7 +490,7 @@ kept: every open starts fitted.
|
|
|
455
490
|
so after one it is the page's. A window `resize` (an orientation change) refits a fitted view, else re-clamps; it
|
|
456
491
|
is listened to only while open.
|
|
457
492
|
- **It closes by itself**, whatever it shows, on a system theme change (the diagram behind is redrawn; the viewer
|
|
458
|
-
holds the old picture;
|
|
493
|
+
holds the old picture; `diagram_wiring.js`), on a switch to another session or the start page (`session_view.js
|
|
459
494
|
forgetSession`, given `pictures`; the same session again keeps it) and when the all-sessions view opens (it hides
|
|
460
495
|
`#center`, the viewer's parent; app.js `applyView`). A bubble rewritten or cloned while it is open leaves it as it
|
|
461
496
|
is: it holds its own copy of the URL. The toast may show over it (both z-index 50, the toast later); it is modal by
|
|
@@ -464,6 +499,32 @@ kept: every open starts fitted.
|
|
|
464
499
|
viewer adopts it (or adds one) and draws ✕ and the bar with lit at the first open. ✕ and the bar are glass cards
|
|
465
500
|
(solid `--bg-panel` under `body.no-glass` and reduced transparency), by `--safe-*`, and the standalone phone
|
|
466
501
|
app's ✕ is 12px lower, below iOS 26's band under the clock.
|
|
502
|
+
- **A diagram's regions** (a renderer that reports them: [block-renderers.md](block-renderers.md#regions)): the
|
|
503
|
+
viewer's layer, `picture_regions.js createRegionLayer`, made by `diagram_wiring.js` and given by
|
|
504
|
+
`pictures.useLayer?.(layer)` (an older cached `picture_viewer.js` has none: the viewer as before; one with
|
|
505
|
+
`useLayer` but no `bind`, which never shows the card, leaves the layer undrawn and keeps no card's room). The layer
|
|
506
|
+
adds its own `.pv-marks` child to `.pv-pic` (the box marks by percent, the page's own `<svg viewBox="0 0 1 1">`
|
|
507
|
+
with at most two `<polyline>`s, the hovered and the selected arrow's, and a `role="group"` of buttons), and its card
|
|
508
|
+
(`.pv-sel`, `role="region"` "Selected") and visually hidden `aria-live` line join `#lightbox` after the bar.
|
|
509
|
+
**The pointer path is maths** (`region_hit.js`): the surface keeps its pointer capture, so a drag, a pinch and a
|
|
510
|
+
double tap are as before. A tap that isn't a move (4 px for a mouse, 10 for a finger) goes to `layer.tap` before
|
|
511
|
+
the double-tap bookkeeping: the nearest node or note within 3 px, else an arrow's line (7 px at least) or its
|
|
512
|
+
label's box, else the innermost group; nothing → it clears. A finger (18 px) takes a node first only on its box:
|
|
513
|
+
an arrow's line or label within 7 px beats a node only within the finger's margin (two nodes 30 px apart at a
|
|
514
|
+
phone's fit leave the label between them tappable), then the nearest node within 18 px, then an arrow. One region at a time; two with one kind
|
|
515
|
+
and id select together. The mouse with no button down is `layer.hover` at most once per frame (`#lightbox.over`:
|
|
516
|
+
the hand). **The card's room** (`CARD_ROOM` 64 px, 80 on a coarse pointer, beside the bar's 56) is kept in the fit
|
|
517
|
+
of a picture with regions, selected or not, so selecting never moves a fitted picture and no fitted node is under
|
|
518
|
+
the card; zoomed in, a selected node under the card slides up (`revealOffset`), `TAP_MS` after its tap and only if
|
|
519
|
+
no second tap came (a double tap zooms at the point it hit), a keyboard's selection at once. **Keys**: the nodes'
|
|
520
|
+
buttons (`.pv-node`, a full reset of the page's `button` style, `pointer-events: none`; the reset is in each
|
|
521
|
+
button's inline `style` too, so with a stale index.html they are still see-through and take no pointer) are one Tab
|
|
522
|
+
stop (roving `tabindex`, following the selection); the arrows move the focus to the nearest button that way (along +
|
|
523
|
+
2 × across; a group only when nothing else is that way), Enter or Space is the button's click, which selects; Esc
|
|
524
|
+
clears a selection first and closes second; the card's ✕ clears. When the card goes with the focus in it, the focus
|
|
525
|
+
goes to the cleared region's button, else to the viewer (never `<body>`, where the next Esc wouldn't reach the
|
|
526
|
+
viewer). A focused button never scrolls the surface (its `scroll` is reset). The card's actions row is the layer's
|
|
527
|
+
`actions(region)` (empty for now: the card is the name alone).
|
|
467
528
|
|
|
468
529
|
## A failed block asked for again
|
|
469
530
|
|
|
@@ -733,9 +794,13 @@ What chi has of one working-set item ([working-set.md](working-set.md#timeline-w
|
|
|
733
794
|
`ws_timeline.js` is the pure part (the server's events into cards newest first, reads merged by state, and between the same edits, into line
|
|
734
795
|
slices, the file strip, the peek's pick, the step tags from the item's `runs`: working_set.js `itemsOfTurn` keeps each
|
|
735
796
|
row's `tool_id` with its place), `ws_cards.js` the cards' templates (`diff_view.js` for diffs, `.read-line` for lines),
|
|
736
|
-
`ws_peek.js` the popover's peek (one row at a time; working_set_view.js draws it under the row
|
|
737
|
-
|
|
738
|
-
placing), `
|
|
797
|
+
`ws_peek.js` the popover's peek (one row at a time; working_set_view.js draws it under the row; the popover is 520 wide
|
|
798
|
+
open or closed, so no row moves sideways, and a peek grows a phone's sheet to `SHEET_TALL`: `chip_popover.js` reads
|
|
799
|
+
`width`/`sheetShare` as functions per placing), `ws_part_peek.js` the "From the start" rows' prompt peek (the part
|
|
800
|
+
route's text as sent, the tools' names and sizes, a tab per hold with the item peek as a read's tab; one peek open at a
|
|
801
|
+
time across both; [working-set.md](working-set.md#prompt-parts-as-sent)), `ws_reader.js` the reader and the wiring
|
|
802
|
+
(`createWorkingSetPreview`: the peek, with the prompt peek as its `part` (no new export: a view without it, an older
|
|
803
|
+
cached one, draws today's rows), the reader, `attach(workingSet)`
|
|
739
804
|
for the set, its jumps and its list, and `whatChiHas` for refs.js), `ws_way_in.js` a tool row's `timeline` button (a
|
|
740
805
|
flag turn_html.js reads; on only once the reader is attached). State: the reader's own closure (the open item, its
|
|
741
806
|
answer, the tab), never `store.current`. The reader is a `section` in `#center` over the history and the composer
|
data/docs/internals/web-push.md
CHANGED
|
@@ -186,6 +186,17 @@ from saying it twice across restarts). The key's `chi:` prefix keeps sw.js from
|
|
|
186
186
|
| `updated` | `chi:updated:<X>` | "chi updated to X" / "chi web and 3 sessions restarted; 1 restarts when idle." + the edited files |
|
|
187
187
|
| `restart_failed` | `chi:restart_failed:<X>` | "chi X is installed; chi web didn't restart" / why (a failed `--version` preflight, no wrapper), "Restart chi web in its terminal." |
|
|
188
188
|
|
|
189
|
+
**A disabled schedule's show.** `SessionHub#run_schedule_tick` emits one `schedule_disabled` hub event per
|
|
190
|
+
`Schedules::Outcome#disabled` of its tick (`#publish_disabled`, under `@monitor` like `publish_notice`): `{id, title,
|
|
191
|
+
kind: skipped|failed, count, reason, session_id, at}`, `session_id` being `Schedules#session_of` (the resolved
|
|
192
|
+
target, else the head) and `at` the tick's wall time. The page's event stream passes it to the tabs, which have no
|
|
193
|
+
listener. The Notifier shows it with reason `schedule`, key and tag `chi:schedule_disabled:<id>:<at>` (`chi:`: not
|
|
194
|
+
a waiting key; `<at>`: a later disable shows again; the same event twice shows once, `@updates_seen`), title
|
|
195
|
+
"Schedule disabled: <title or the id's first 8>", body "skipped 12 times: <reason>" + a line `chi schedule enable
|
|
196
|
+
<short id>`, url `Notifier.session_url` of the session's summary, `/` when it has none. Two exceptions to the rules
|
|
197
|
+
above: it is pushed with a page in front (`UNSEEN_ON_PAGE`: the page has no schedules view), and it gets
|
|
198
|
+
`UPDATE_TTL` (24 h) like an update. A cron tick or `chi schedule run-now` emits nothing (no hub).
|
|
199
|
+
|
|
189
200
|
`updated` is sent by the **restarted** chi web (its AutoUpdate finds the run at `phase: web`): the exec ends the
|
|
190
201
|
old process, and `Notifier#stop` does not flush the shows still in their hold, so a push queued just before it would
|
|
191
202
|
be lost. Sending from the new process also proves it came up. The workers left then restart without another show.
|
|
@@ -43,6 +43,23 @@ else that changes it does: a later `execute` (`sed`, `git checkout`), the user's
|
|
|
43
43
|
edit that changed the file anyway leaves the earlier stamp, so the file shows stale. On a filesystem with 1 s mtimes a
|
|
44
44
|
same-size edit in the same second goes unseen (APFS keeps nanoseconds).
|
|
45
45
|
|
|
46
|
+
A memory item follows chi's own changes too (`WorkingSet.build` passes the runs it already walked to
|
|
47
|
+
`WorkingSet::OwnChanges.from_runs`: no second walk; built only when a memory item needs it). A memory whose latest run
|
|
48
|
+
is a `memory_read` and whose stamped files differ stays `live` when every file that differs (the entry, its overlay)
|
|
49
|
+
holds chi's own later change: an `edit` or `write` of the file (its stamp), or a `memory_write` (by content, since
|
|
50
|
+
`memory_write` leaves no stamp). That is the heartbeat case, a memory read once and then edited all session. It runs
|
|
51
|
+
only after `memory_differs`' early answers: a name that now resolves to another file or overlay (a project `x` chi
|
|
52
|
+
wrote now shadowing the read's system `x`) or is gone stays `stale`, conservative. A memory whose latest run is a
|
|
53
|
+
`memory_write` is `stale` when the file it wrote (`<scope dir>/<name>.md`: system from `root`, project from the item's
|
|
54
|
+
read stamp's `project_dir`; a project memory only written has none and stays `live`) no longer holds chi's latest own
|
|
55
|
+
change of it (the write's content, or a later `edit`/`write` of the file by its stamp): one you edit after chi's write. A remove, an overlay write or a description-only write keeps today's `live`. Only a path
|
|
56
|
+
`MemoryGuard.memory_paths?` lets through is read: a stamp's file outside the memories folder counts as no own change
|
|
57
|
+
(stale, as before), never read. Cost in the worker: once any memory item's latest run is a `memory_write` (so every step
|
|
58
|
+
after a session's first one) or a memory item is found stale, one pass over the runs already in memory, testing the tool
|
|
59
|
+
name before anything else (about 0.1 ms at 350 runs on the Studio; testing `failed?` first, which copies each output,
|
|
60
|
+
cost about 1.5 ms); a stat per memory item already found stale, a `File.binread` per memory item whose latest run is a
|
|
61
|
+
`memory_write`.
|
|
62
|
+
|
|
46
63
|
## The projection: `WorkingSet.build`
|
|
47
64
|
|
|
48
65
|
`Samagotchi::WorkingSet.build(conversation, cwd:, strategy:, stat: File.method(:stat), pins: [])` (`lib/samagotchi/working_set.rb`)
|
|
@@ -130,7 +147,7 @@ pending: [Steering: add and unadd](#steering-add-and-unadd)) (`Engine#emit_worki
|
|
|
130
147
|
turn-end apply has run by then);
|
|
131
148
|
- between turns, from `Engine#announce_working_set` (the session's messages, under the event lock; after a
|
|
132
149
|
`/working-set` op, after a `rollback_to`, and after an `/llm-context` change: the states are the next turn's strategy's): announced
|
|
133
|
-
(`working_set_updated` is in `ANNOUNCEABLE_EVENTS`; held after a command's `command_ran` inside
|
|
150
|
+
(`working_set_updated` is in `SessionObserver::ANNOUNCEABLE_EVENTS`; held after a command's `command_ran` inside
|
|
134
151
|
`holding_announcements`), under the *next* turn's strategy (`SessionModelSettings#turn_llm_context`, as the
|
|
135
152
|
turn-end warm-up reads it; `TurnSettings` keeps the last turn's, stale after `/llm-context` or `/model`). While a
|
|
136
153
|
turn runs, the strategy is always the turn's.
|
|
@@ -246,7 +263,8 @@ projection), on both loops. It costs one model step; a model may skip it (the no
|
|
|
246
263
|
directory; a memory name `memory_read` rejects or that neither scope holds), an item holding the user's drop
|
|
247
264
|
(`undrop_first`: undrop brings it back without a step), one already in the system prompt and with no working-set
|
|
248
265
|
output (`in_prompt`: nothing to add; matched by name and scope, `Tools::MemoryRead.prompt_memory?` over
|
|
249
|
-
`Engine#prompt_memories`, a bare name or an unscoped prompt entry by name only), and one the model has whole (`already_sent`: live, a read of it sent
|
|
266
|
+
`Engine#prompt_memories`, a bare name or an unscoped prompt entry by name only), and one the model has whole (`already_sent`: live, a read of it sent; a memory chi read and then changed itself
|
|
267
|
+
is live, so its add is refused as a file chi edited is). The
|
|
250
268
|
prompt-only refusal doesn't apply when the set holds a read of that memory: a stale or forgotten item may still be
|
|
251
269
|
added as the web row's `refresh`. **`unadd`** takes a pending add back (free); without one it is refused
|
|
252
270
|
(`not_added`).
|
|
@@ -297,7 +315,9 @@ now (`WorkingSet::Now`: `text`, `diff`, `gone`): each name that read read, from
|
|
|
297
315
|
overlay stamped with it appended as `Tools::MemoryRead.call` appends it (`Model-specific guidance (<key>):`, the key
|
|
298
316
|
off the overlay's file name), and a missing name's `Error:` tail kept; `diff` is `TextDiff.unified` of what the read
|
|
299
317
|
sent against that (`EditPreview`'s shape, so `diff_view.js` draws it; an empty `text` is "no change"). `gone` when a
|
|
300
|
-
file is; nil without a stamp.
|
|
318
|
+
file is; nil without a stamp. Each name is a `WorkingSet::Locator` of origin `:run` ([Prompt parts as sent](#prompt-parts-as-sent), The locator):
|
|
319
|
+
every name is resolved first (refused: nil; no entry answers: gone), then read, and `memory_now` keeps the join and
|
|
320
|
+
the diff.
|
|
301
321
|
|
|
302
322
|
**The route.** `GET /api/sessions/:id/working_set/item?kind=&key=` (`WorkingSetRoutes#handle_working_set_item`,
|
|
303
323
|
`:owner, :session`: a participant gets 403 from `not_permitted_for`) answers `timeline.to_h`, and with `&now=1` for a
|
|
@@ -388,13 +408,14 @@ chi's head, in three sections, drawn as Read, Conversation, From the start (ever
|
|
|
388
408
|
server, `overlay`); a scope either side lacks (an older worker's part or item, an item the server hasn't stamped)
|
|
389
409
|
matches by name alone, as before scopes. So a project `x` read beside a system `x` in the prompt is two rows: the
|
|
390
410
|
read stays in Read as a plain read (not "prompt", never held twice), and the part's own row gets the key `x@system`
|
|
391
|
-
(no collision with the read's `x`), its words its scope ("preloaded · system") and, like identity's, no actions
|
|
392
|
-
peek. A note and a preload of one name and scope stay one row with both sizes; of two scopes, two rows. The start
|
|
411
|
+
(no collision with the read's `x`), its words its scope ("preloaded · system") and, like identity's, no actions;
|
|
412
|
+
its ▸ is the prompt peek ([Prompt parts as sent](#prompt-parts-as-sent)). A note and a preload of one name and scope stay one row with both sizes; of two scopes, two rows. The start
|
|
393
413
|
section tracks the items it shows by identity, not by key. It keeps the memory row's peek, state and the drop/pin rules of a preloaded memory (not
|
|
394
414
|
droppable or pinnable until read). Its tokens are the part's, plus `+X` for the read's (the item's server tokens: a
|
|
395
415
|
preloaded row carries none of its own, so the two never double-count). Other parts are read-only `part` rows: a
|
|
396
|
-
label, a sub (the tools part's "N declared"; dropped on a phone), `~tokens`, no actions,
|
|
397
|
-
them.
|
|
416
|
+
label, a sub (the tools part's "N declared"; dropped on a phone), `~tokens`, no actions, and a ▸ that opens what chi
|
|
417
|
+
was sent ([Prompt parts as sent](#prompt-parts-as-sent)); a turn lens dims them. Each start row carries the keys of
|
|
418
|
+
the parts it stands for (`partKeys`, `partSizes`: a note also preloaded has two).
|
|
398
419
|
- **Read in this session** (`read`): today's files / memories / urls folds (`bodySections`), minus the memories the
|
|
399
420
|
start section shows. Its meta: held (not struck) and out (forgotten or dropped); its tokens the held items'.
|
|
400
421
|
- **Conversation** (`talk`): one row at section level, "Conversation · N turns ~X" (`headSections` still returns the
|
|
@@ -484,3 +505,214 @@ The secondary text and the rail's rule read through their own tokens, a step bri
|
|
|
484
505
|
base tokens on the light one: `--ws-faint` (the counts, the ops text, step tags; `--text-muted` on dark, `--text-faint`
|
|
485
506
|
on light), `--ws-muted` (the rail's head, the list's `files · n` rows, the drop/pin buttons; `--text-3` / `--text-muted`),
|
|
486
507
|
`--ws-rule` (the rail's left rule; `--border-strong` / `--border`) and `--ws-act-border` (the buttons' border).
|
|
508
|
+
|
|
509
|
+
## Prompt parts as sent
|
|
510
|
+
|
|
511
|
+
Every "From the start" row opens what chi was sent for its part: a slice of the prompt the session already keeps,
|
|
512
|
+
never a copy.
|
|
513
|
+
|
|
514
|
+
**The head and the places.** `Engine#turn_messages` puts the built prompt at `messages[0]`
|
|
515
|
+
(`ContextNote.with_system_head`: `{role: "system", content:}` with no `kind`, `ContextNote.system_head?`) and
|
|
516
|
+
`end_turn` saves it with the turn. Each `prompt_parts` entry says where it sits in that prompt (`PromptPart`, built by
|
|
517
|
+
`PromptLayout` beside the build): `at` (where its lead starts), `len` (lead included), `lead` (the length of what chi
|
|
518
|
+
adds before the item's own text: the identity line, a note's `## name`, the first note of a scope its heading, a
|
|
519
|
+
preload's "this memory is required … memory name: x" line, a file's header, a plugin's `From b (n):`, an index's
|
|
520
|
+
`Project memories:`; none for base, the kit and the volatile lines), so the slice is `head[at, len]` and the item's
|
|
521
|
+
own text `head[at + lead, len - lead]`. Joins between items fall in no span. `chars` is not `len`: a section's first
|
|
522
|
+
part is charged its joins. `digest` is 12 hex of SHA-256 over the item's own text, `head` 16 hex of the whole prompt
|
|
523
|
+
(the same on every part of a build). The tools part has a place only where the declarations are in the prompt: inside
|
|
524
|
+
the base text on a native non-Gemma profile (base's slice leaves them out, and so does its digest), after the
|
|
525
|
+
rstripped prompt on Gemma (an item running into the rstrip is cut at it); on a chat host they are a request field and
|
|
526
|
+
the part has none. `params` say how to fetch an item again: a memory's `requested_scope` (nil for a bare name),
|
|
527
|
+
`model_key`, `fallback_model_key`, `project_dir`, `system_dir` as the build read them; a file's `path`; the tools'
|
|
528
|
+
`[{name, chars}]` (chat: each schema's JSON; native Gemma declarations: each one's text; Qwen's one JSON list gives no
|
|
529
|
+
per-tool length, so names only). The items are recorded where the builders render them
|
|
530
|
+
(`SystemPrompt::Section#items`), so a place can't drift from the bytes. Cost: about 80 bytes a part plus 100–200 for
|
|
531
|
+
a fetchable part's params, 2–3 KB a session, in the file, every snapshot, reset frame and owner show; one SHA-256 of
|
|
532
|
+
the prompt and one per item per changed build.
|
|
533
|
+
|
|
534
|
+
**The key.** A part is named from the parts list alone: `PromptPart.keys` (`kind:ref`, the label without a ref,
|
|
535
|
+
`@scope` when it has one, `#n` for the nth repeat: a duplicate preload is `preloads:x#2`); `ws_sections.js startRows`
|
|
536
|
+
has the twin, both held to `spec/shared/prompt_part_keys.json`.
|
|
537
|
+
|
|
538
|
+
**The route.** `GET /api/sessions/:id/working_set/part?key=` (`WorkingSetRoutes#handle_working_set_part`, `:owner,
|
|
539
|
+
:session`: a participant gets 403, and `Web::ParticipantShow` sends no parts) reads the parts and `messages[0]` from
|
|
540
|
+
one source: a live worker's snapshot frame (`session_state_snapshot.prompt_parts`, `snapshot.messages`), else the
|
|
541
|
+
session file. No Bridge route, no worker feature: one session-file parse. `WorkingSetPart.answer` then: tools always
|
|
542
|
+
answer `{part, tools}` (names and sizes, saved with the part); otherwise case C's table, the first that holds winning,
|
|
543
|
+
its words in `WorkingSetPart::WORDS` (the page shows them as given, `note`, with a `reason`):
|
|
544
|
+
|
|
545
|
+
| # | Condition | `reason` | Source text under it? |
|
|
546
|
+
|---|---|---|---|
|
|
547
|
+
| 1 | the part has no `at`, a live worker of an older chi (its snapshot's `chi_version`; none said: older) | `older_worker` | no |
|
|
548
|
+
| 2 | the part has no `at`, no live worker or one of this chi (a fresh worker keeps the file's parts until a turn) | `older_chi` | no |
|
|
549
|
+
| 3 | `messages[0]` is not a system head | `no_prompt` | no |
|
|
550
|
+
| 4 | the head's digest differs from the part's `head`, a turn runs | `running` (`changed`) | yes, a fetchable part |
|
|
551
|
+
| 5 | the head's digest differs, idle (`!rollback`, a failed turn's old head, an older chi's run) | `idle` (`changed`) | yes, a fetchable part |
|
|
552
|
+
|
|
553
|
+
Else `{part, sent: {text, lead}}`. Mid-turn the snapshot's messages lag the turn, but parts are recorded at its start,
|
|
554
|
+
so the slice is exact unless the prompt was rebuilt (4). A memory file with invalid UTF-8 is scrubbed in the saved
|
|
555
|
+
head, so its session stays in 5: accepted.
|
|
556
|
+
|
|
557
|
+
**The locator.** Every "now" the working set shows is fetched by one resolver, `WorkingSet::Locator`
|
|
558
|
+
(`working_set_locator.rb`, `Data.define(:origin, :kind, :ref, :scope, :params)`; loaded only when a fetch runs, for the
|
|
559
|
+
testing kit's file budget): "where a held text came from and how to fetch it again". `#fetch` has three outcomes: nil
|
|
560
|
+
(refused, or nothing to fetch), a `WorkingSet::Now` with `gone`, a `Now` with its text (diff nil). `#composed` is the
|
|
561
|
+
same fetch with the files it read (`Locator::Composed`: `now`, `files` of `Locator::Source` `{path, role: :base |
|
|
562
|
+
:overlay, key}`, at most two); a gone prompt memory names the base it was sent from (identity's saved `system_dir`, a
|
|
563
|
+
preload's built `scope`'s folder, a note's `requested_scope`'s). A note's overlay is found by
|
|
564
|
+
`ModelNotes.overlay_path`, the build's own lookup (its label keeps the key as given). Its guard follows
|
|
565
|
+
`origin`, and the two stay apart:
|
|
566
|
+
|
|
567
|
+
- `:run`, a `memory_read` stamp's entry (`WorkingSet.memory_now`): resolved with chi web's own `MemoryPaths.system_dir`,
|
|
568
|
+
any saved folder ignored; a path-only stamp (or one whose project folder is outside the root) reads its stamped
|
|
569
|
+
paths; a `read:` stand-in reads the files.
|
|
570
|
+
- `:prompt`, a prompt part's `params` (cases 4 and 5, `&now=1`, the stale states): a memory resolves with the saved
|
|
571
|
+
keys, `requested_scope` and folders only when the saved `system_dir` and `project_dir` are inside chi web's own
|
|
572
|
+
`MemoryPaths.system_dir`, and every path it may look at (the files resolved; a note's file and each saved key's
|
|
573
|
+
overlay, before any is stat'd) passes `memory_paths?`; identity and preloads through `Tools::MemoryRead.resolve` and
|
|
574
|
+
`.compose`, a note through `ModelNotes.body_at` (the composers the build used, so an unchanged memory's text has the
|
|
575
|
+
build's digest). An AGENTS.md is read only when it is on the session `working_directory`'s chain
|
|
576
|
+
(`PromptFiles.agents_paths`, `PromptFiles.content`). An appended file is never fetched (as sent from the head only);
|
|
577
|
+
base, the kit, a plugin's section, an index and the session lines are chi's own text: the line alone. Nothing is
|
|
578
|
+
recomputed: no model key, no folder (a model switch rebuilds the prompt, so the saved keys describe the sent text).
|
|
579
|
+
|
|
580
|
+
The path guard both share is `WorkingSet::MemoryGuard` (in `working_set.rb`: `#build`'s stale check of a read memory
|
|
581
|
+
uses it at load). A file or URL row has no locator: its timeline is the conversation's text, and its stale check is a
|
|
582
|
+
`stat` against its stamp.
|
|
583
|
+
|
|
584
|
+
**Stale prompt parts.** `WorkingSetPart.states(parts, root:, cwd:)` names the parts whose source changed since chi
|
|
585
|
+
was sent it, `[{key, state: "stale"}]` (the stale ones only): a part whose locator fetches text with a different
|
|
586
|
+
`PromptPart.digest_of` from its saved `digest`, or finds the source gone. A digest covers exactly the text the fetch
|
|
587
|
+
returns, so it catches an edit, shadowing (a bare preload now answered by the project scope), an overlay added or
|
|
588
|
+
removed, and a file deleted (gone). It does not catch what changes which parts exist rather than a part's text: a
|
|
589
|
+
note that newly applies (or whose `models:` line no longer matches), a new AGENTS.md in the chain, a memory muted
|
|
590
|
+
after the build. Only fetchable kinds get a state (identity, preloads, notes, AGENTS.md): never an index (it changes at
|
|
591
|
+
every memory write), an appended file, chi's own text, or a part an older chi built (no digest). Cost: about 0.8 ms per
|
|
592
|
+
GET for 11 fetchable parts (the Studio, warm cache; `find_dot_git` is stat-only).
|
|
593
|
+
|
|
594
|
+
**chi's own change of a stale part (`by_chi`).** Given the same source's `messages` (and `running`),
|
|
595
|
+
`WorkingSetPart.states` adds `by_chi: {tool_id, step, op, current}` to a stale part chi changed itself; the state
|
|
596
|
+
stays `"stale"`. The own changes are `WorkingSet::OwnChanges` (`working_set_own_changes.rb`): the latest successful
|
|
597
|
+
change per file still in the stored conversation, so its text is still sent in the call's arguments (`op`
|
|
598
|
+
`memory_write`, `remove`, `write`, `edit`; `step` is `PairedRun#step`). A `memory_write` counts by its output: "saved
|
|
599
|
+
to SCOPE scope" (keyed scope + name), "Model overlay 'x' for KEY saved" (+ the key: the handler's model key, never an
|
|
600
|
+
argument), "removed from" (a remove; "its dangling index line was dropped" is none); never a description-only write
|
|
601
|
+
("(file unchanged)"), the index, or a failed, denied or interrupted run (`WorkingSet.failed?`). An `edit` or `write`
|
|
602
|
+
counts by its `FileRef` path and stamp. Each file the part was read from (`Locator#composed`, at most two) maps to its
|
|
603
|
+
latest own change: a memory's by the saved folder it sits in (`File.dirname(path) == dir`: a project's folder is
|
|
604
|
+
inside the system one), a file tool's by basename then `realpath`. A change is current while the file holds what it
|
|
605
|
+
left: a `memory_write`'s content byte for byte (`File.binread`; a model note's or an overlaid memory's text never
|
|
606
|
+
digests to its file, so the compare is per file), a remove's absence, an edit's stamp (`WorkingSet.differs?`).
|
|
607
|
+
|
|
608
|
+
`current: true` (the row's `✎ edited`) when every file holds chi's change or what was sent, and one holds chi's. "What
|
|
609
|
+
was sent" is the part's sent slice (`sent_of`, only when `messages[0]` is the head the parts were built with), split
|
|
610
|
+
with the text now at `Tools::MemoryRead.overlay_tail` (the overlay's key now, else the build's `model_key`, then
|
|
611
|
+
`fallback_model_key`): the base's text against the body, the overlay's against the tail, and no overlay now must mean
|
|
612
|
+
no tail sent (a project `x` chi wrote now answering a bare preload that was sent with a system overlay is stale). A
|
|
613
|
+
gone part is current only by chi's current remove of the base it was sent from. Otherwise, when chi changed one of the
|
|
614
|
+
files, `current: false` (it changed again after chi's change; or the head is not the build's, case C 4–5, where
|
|
615
|
+
nothing proves the other file unchanged). Rolled back (the call's entries gone, the file still chi's text), interrupted,
|
|
616
|
+
or someone else's change: no `by_chi`. A merged row (a note also preloaded) gets an answer per part.
|
|
617
|
+
|
|
618
|
+
An `edit` is checked harder than its stamp (a stricter reading of D2, the code review's M2): `edit` replaces its
|
|
619
|
+
`old_text` wherever it still matches, so it can land over a change chi never saw, and the stamp then holds. A part
|
|
620
|
+
whose current change of a file is an `edit` is current only when undoing chi's edits of that file, newest first
|
|
621
|
+
(`OwnChanges.undoes_to?`: each `new_text` found exactly once and put back to its `old_text`), reaches the sent side
|
|
622
|
+
exactly (stripped, as a prompt file is), or chi's own `memory_write` of it before those edits. Otherwise there is no
|
|
623
|
+
`by_chi`, so the row stays plain `stale` and the now tab shows the diff. A range edit (`start_line`), an empty
|
|
624
|
+
`new_text` or a `write` among them can't be undone: plain `stale` too. An `edit` or `write` with no stamp (an older
|
|
625
|
+
session's) gives no `by_chi`, never `current: false`. Read rows and file rows keep the stamp rule (D1, as file rows
|
|
626
|
+
always had).
|
|
627
|
+
|
|
628
|
+
Known limit: own changes have no build point. A write from before the prompt's build counts when the file comes back to
|
|
629
|
+
its text (chi writes A; someone writes B; a restart builds the prompt with B; someone writes A back): the row reads
|
|
630
|
+
`✎ edited` though the newer prompt says B. Rare; a session that recorded the message index of the head's build could
|
|
631
|
+
ignore earlier changes.
|
|
632
|
+
|
|
633
|
+
While a turn runs (`running`), only a `current: true` goes out: the GET's messages may lag the turn, so chi's newest
|
|
634
|
+
write may not be in them, and "changed again" could name chi's own change. A row chi changes in the running turn reads
|
|
635
|
+
`stale` until a GET's messages hold the write (D5); in the browser check (2026-11-22, the fake model) the row already
|
|
636
|
+
read `✎ edited` in a later step of the same turn, so the lag seems to be the writing step only (inferred, not traced in
|
|
637
|
+
the worker), and the hand-off's GET settles it either way. Guard: only the Locator's files are read (`binread`, `stat`); no path a call
|
|
638
|
+
or an output names is read, and an overlay key is `[a-z0-9-]+`. Cost: nothing new for a GET with no stale part; with one,
|
|
639
|
+
one `paired_runs` walk (about 3 ms at 600–750 messages on the Studio, about twice on the laptop), the messages'
|
|
640
|
+
top-level keys symbolized (`WorkingSetPart.symbolized`, shared with `working_set_source`), and at most two reads or
|
|
641
|
+
stats per stale part. A stale part stays stale for the worker's life, so each GET of such a session pays it.
|
|
642
|
+
|
|
643
|
+
The carrier is chi web's `GET …/working_set` alone: `handle_working_set` adds `parts:` for the owner whichever of its
|
|
644
|
+
three sources answered (the running turn's set, an idle worker's, a build from the file), from the parts the part
|
|
645
|
+
route reads (`#prompt_source`: the live snapshot frame's, else the file's), so a stopped session, a live idle worker
|
|
646
|
+
and an older (0.183.0) worker all get them. No field means none stale. No event field, no worker change; a
|
|
647
|
+
participant's answer never has it (`ParticipantView.working_set` rebuilds `{items, at}`). The page asks the GET each
|
|
648
|
+
time the list opens. A `:working_set_updated` event carries no parts: the page keeps the session's last GET's states on
|
|
649
|
+
the event's set (`working_set_view.js takeServer`), and a GET an event overtook still gives its parts. The page asks
|
|
650
|
+
the GET again when the session's parts are rebuilt (their heads or digests change, `sessionChanged`) and at a turn's
|
|
651
|
+
hand-off when it holds states or the list is open, so a rebuilt prompt's states go.
|
|
652
|
+
|
|
653
|
+
Stale lasts in a live worker until chi rebuilds its prompt: `SystemPrompt#built_for` caches the build until
|
|
654
|
+
`#reset!` (a model switch, a participants change, a plugin's `prompt_changed!`, a toolkit change). An outside edit,
|
|
655
|
+
and chi's own `memory_write` of a preloaded memory, do not reset it, so the worker keeps sending the old text across
|
|
656
|
+
turns until one of those or a restart. Someone else's change reads `stale`; chi's own (a current `by_chi`) reads
|
|
657
|
+
`✎ edited`, since the new text is in chi's conversation; while the turn that made it still runs it may read `stale`
|
|
658
|
+
until a GET's messages hold the write (see `by_chi` above).
|
|
659
|
+
|
|
660
|
+
**The source now.** `GET …/working_set/part?key=&now=1` adds, beside the sent slice, `now: {text, diff, gone}`: the
|
|
661
|
+
locator's text (scrubbed to valid UTF-8 before JSON) and `TextDiff.unified` of the sent text against it (nil when
|
|
662
|
+
gone), and `rebuild`: when chi's prompt gets the source now, `restart` with a live worker (it keeps its prompt until it
|
|
663
|
+
is next built) or `next_turn` without one (the next turn builds it). Under cases 4 and 5 the answer stays as above (the
|
|
664
|
+
source now, no diff: nothing sent to diff against; no `rebuild`, their words say when). Parts without a locator have no
|
|
665
|
+
`now`. An older chi web sends no `rebuild`, and the page leaves its line out.
|
|
666
|
+
|
|
667
|
+
**The page.** `ws_part_peek.js` (made by `ws_reader.js` with the reader's markdown cache, handed to the view as
|
|
668
|
+
`peek.part`): the peek's head "in the prompt · sent with every request", the text (a memory's and an `.md` file's
|
|
669
|
+
rendered), chi's lead folded under "chi adds a line before it", no foot buttons; tools as names and sizes; case C's
|
|
670
|
+
line with the source now under it. A row of several holds gets one tab per hold, its kind and size (`note · ~0.9k`,
|
|
671
|
+
`preload · ~1.2k`, `in the prompt · ~1.4k`), and `read · t1·s1` for an item that was read: the item peek, first. One
|
|
672
|
+
peek open at a time. The popover is 520 wide open or closed.
|
|
673
|
+
|
|
674
|
+
The GET's `parts` reach the start rows as `headSections`' `states` option (`startRows`: `partStates` beside
|
|
675
|
+
`partKeys`, `partStale` when one is). A stale row says `stale` in `--warn-text` (`.ws-pstale`) in place of its words,
|
|
676
|
+
which move to its title ("model note · changed after chi's prompt was built"); a memory row whose read is stale too
|
|
677
|
+
still says one `stale`, its title and its now tab naming both ("read changed · prompt text changed"). Its peek gets a `now · changed` tab right after the stale hold (`warn`):
|
|
678
|
+
the `&now=1` answer, drawn as "<label> changed after chi's prompt was built" with the diff's `+a −d` and
|
|
679
|
+
`diff_view.js`'s diff ("no change" once it was edited back), or "Its source is gone now." It opens first unless the row
|
|
680
|
+
has a read. No new export: an older `ws_sections.js` ignores `states`, and the 0.183.0 page ignores the field.
|
|
681
|
+
|
|
682
|
+
**chi's own change on the page.** The view reads the GET's `by_chi` itself, off `server.parts` (`working_set_view.js
|
|
683
|
+
ownRow`: an older cached `ws_sections.js` has no `partKeys`, build 2's maps states to `"stale"` or none): a stale part
|
|
684
|
+
whose `by_chi.current` is true becomes `"edited"` in the row's `partStates`, and a row none of whose parts is still
|
|
685
|
+
stale is edited. It reads `✎` (the file rows' `.e`), then `<span class="st ws-pedited"><span class="ws-pwords">preloaded
|
|
686
|
+
· </span>edited</span>` (`removed` for a remove) in `--text-2`, not the warn colour; for AGENTS.md `project instructions ·
|
|
687
|
+
edited`. Its title: "preloaded · chi edited it at turn 3, step 2: the new text is in its conversation; its prompt
|
|
688
|
+
still sends the old text until it is next built" (a remove: "… chi removed it at turn 3, step 2: its prompt still sends
|
|
689
|
+
it until it is next built"). Its tag after the tokens is the call's place, found by `tool_id` over every turn's items
|
|
690
|
+
(`ws_timeline.js placeOf`), drawn as the read rows' jump (`.ws-step.ws-own`, `data-ws="jump"`); without a place, a
|
|
691
|
+
plain `step N` (the server's step). A memory row whose read is stale says the read's `stale` as before; the
|
|
692
|
+
both-causes words ("read changed · prompt text changed") need a read op, so a memory chi only wrote and someone changed
|
|
693
|
+
after reads "changed after chi's prompt was built" (its item is stale by D1, faded). A row whose part carries `by_chi`
|
|
694
|
+
and whose item has no read gets no `read` tab (the item peek of chi's write): its edited tab, or its now tab with the
|
|
695
|
+
"chi edited it at …" line, opens first. In a turn lens the call's tag replaces the lit row's step tag. A merged row
|
|
696
|
+
(a note also preloaded) stays `stale` while any part is stale without a current change; each part gets its own tab.
|
|
697
|
+
On a phone's sheet the part words go (`.ws-popover.sheet .ws-pwords{display:none}`, D7): `✎ edited` alone, the name
|
|
698
|
+
keeps its room; a part row keeps `edited` where it drops its sub text, and the tabs wrap.
|
|
699
|
+
|
|
700
|
+
The peek (`ws_part_peek.js`) gives an edited part the tab `edited · t3·s2` (`removed · t3·s2`) right after its hold, in
|
|
701
|
+
place of the now tab; it opens first unless the row has a read. Its body is the `&now=1` answer: the head "chi edited
|
|
702
|
+
`<label>` at t3·s2" with the diff's `+a −d`, the diff sent → now, and one line, "Its prompt still sends the old text with
|
|
703
|
+
every request; chi has the new text from its edit.", followed by "The prompt gets it when it is next built (a restart,
|
|
704
|
+
a model switch)." (`rebuild: "restart"`) or "The prompt gets it when it is next built (at its next turn)."
|
|
705
|
+
(`"next_turn"`); none without `rebuild`. A remove's tab: "chi removed it at t3·s2; its prompt still sends it until it
|
|
706
|
+
is next built." A stale now tab gets the rebuild line under the diff: "chi gets the new text when its prompt is next
|
|
707
|
+
built (a restart, a model switch)." or "chi gets the new text at its next turn."; with `by_chi.current === false`,
|
|
708
|
+
above it (warn) "chi edited it at t3·s2; it changed again after that.". The words are constants beside `BOTH_CHANGED`
|
|
709
|
+
(`REBUILD_LIVE`, `REBUILD_NEXT`, `STILL_SENT`, `PROMPT_GETS`). No new export: an older cached peek given `"edited"`
|
|
710
|
+
sees no stale and shows the sent text only (`v0.183.0` has no `ws_part_peek.js`, so that pairing gets a fixture once
|
|
711
|
+
0.184.0 is tagged); the 0.183.0 page and view ignore `by_chi`; a new page against an older chi web (no `by_chi`, no
|
|
712
|
+
`rebuild`) draws build 2's stale with no rebuild line.
|
|
713
|
+
|
|
714
|
+
**Compat.** An older page ignores the fields and the route; a build-2 page maps any state but `"stale"` to none, so
|
|
715
|
+
`by_chi` rides beside `state: "stale"` (no new state value) and such a page draws today's `stale`; an older chi reading a newer file drops the fields
|
|
716
|
+
(`PromptPart.from_h`), and its own save drops them (cases 1–2). The corpus's `compat-prompt` session has a head and
|
|
717
|
+
placed parts (`ReleaseTools.write_compat_corpus!`, read in `spec/compat/readers_spec.rb`); in the wire samples the head
|
|
718
|
+
is `CompatWire::SYSTEM_PROMPT`, so the digest never matches and a wire reader asserts the fallback.
|