samagotchi 0.201.0 → 0.202.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 +57 -1
- data/docs/architecture.md +47 -7
- data/docs/cli.md +20 -1
- data/docs/configuration.md +2 -1
- data/docs/internals/bridge.md +4 -4
- data/docs/internals/engine.md +9 -6
- data/docs/internals/knowledge.md +26 -6
- data/docs/internals/objectives.md +2 -2
- data/docs/internals/pages.md +4 -2
- data/docs/internals/participants.md +1 -1
- data/docs/internals/peers.md +9 -7
- data/docs/internals/remote-sessions.md +6 -6
- data/docs/internals/session-lifecycle.md +37 -15
- data/docs/internals/web-frontend.md +18 -7
- data/docs/pages.md +6 -3
- data/docs/plugins.md +2 -2
- data/docs/scheduling.md +40 -12
- data/docs/sessions.md +48 -6
- data/docs/sub-agent.md +1 -2
- data/docs/testing.md +92 -8
- data/lib/samagotchi/answer_display.rb +3 -2
- data/lib/samagotchi/answer_tail.rb +4 -4
- data/lib/samagotchi/bridge/card_places.rb +5 -5
- data/lib/samagotchi/bridge/turn_accumulator.rb +5 -5
- data/lib/samagotchi/bridge/turn_drawings/synth.rb +5 -5
- data/lib/samagotchi/bridge/turn_drawings.rb +2 -2
- data/lib/samagotchi/bridge/turn_ranges.rb +15 -8
- data/lib/samagotchi/bridge.rb +5 -5
- data/lib/samagotchi/broadcast_command.rb +3 -3
- data/lib/samagotchi/bundle_command/try/trace.rb +18 -6
- data/lib/samagotchi/bundles/knowledge/embedder.rb +2 -0
- data/lib/samagotchi/bundles/knowledge/github.rb +19 -0
- data/lib/samagotchi/bundles/knowledge/manifest.yml +6 -6
- data/lib/samagotchi/bundles/knowledge/plugin.rb +26 -54
- data/lib/samagotchi/bundles/knowledge/refresh.rb +89 -14
- data/lib/samagotchi/bundles/knowledge/store.rb +36 -2
- data/lib/samagotchi/bundles/schedules/manifest.yml +2 -2
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +24 -3
- data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/skill_pages.md +1 -1
- data/lib/samagotchi/chi_invocation.rb +1 -1
- data/lib/samagotchi/child_move.rb +6 -3
- data/lib/samagotchi/child_reports.rb +3 -3
- data/lib/samagotchi/children_status.rb +4 -2
- data/lib/samagotchi/client_id.rb +2 -2
- data/lib/samagotchi/compat.rb +4 -6
- data/lib/samagotchi/config.rb +3 -0
- data/lib/samagotchi/context_note.rb +1 -1
- data/lib/samagotchi/continue_intent.rb +1 -1
- data/lib/samagotchi/continue_offer.rb +2 -2
- data/lib/samagotchi/continue_repair_backoff.rb +71 -0
- data/lib/samagotchi/delivery.rb +1 -4
- data/lib/samagotchi/engine/participants.rb +1 -1
- data/lib/samagotchi/engine/recap.rb +1 -1
- data/lib/samagotchi/engine/turn_end.rb +1 -1
- data/lib/samagotchi/grants.rb +2 -2
- data/lib/samagotchi/guardrail_wiring.rb +1 -1
- data/lib/samagotchi/guardrails/approval.rb +3 -3
- data/lib/samagotchi/guardrails/pair_boundary.rb +3 -3
- data/lib/samagotchi/guardrails/participant_refusal.rb +2 -2
- data/lib/samagotchi/idle_recap.rb +6 -6
- data/lib/samagotchi/kernel_loop.rb +1 -1
- data/lib/samagotchi/last_turn.rb +9 -6
- data/lib/samagotchi/llm/chat_loop.rb +5 -2
- data/lib/samagotchi/mcp_command.rb +2 -2
- data/lib/samagotchi/memory_usage.rb +7 -6
- data/lib/samagotchi/note_command.rb +1 -1
- data/lib/samagotchi/note_delivery.rb +5 -5
- data/lib/samagotchi/objectives_backing.rb +3 -3
- data/lib/samagotchi/objectives_record.rb +2 -2
- data/lib/samagotchi/objectives_track.rb +2 -2
- data/lib/samagotchi/owner_lock.rb +28 -2
- data/lib/samagotchi/owner_prompt.rb +3 -3
- data/lib/samagotchi/pages/runtime.rb +9 -4
- data/lib/samagotchi/participant_revise.rb +6 -6
- data/lib/samagotchi/peer_receipts.rb +11 -4
- data/lib/samagotchi/plugin/side_question.rb +1 -1
- data/lib/samagotchi/recap_place.rb +5 -5
- data/lib/samagotchi/reply_for.rb +3 -3
- data/lib/samagotchi/reply_wait/liveness.rb +2 -2
- data/lib/samagotchi/reply_wait/poll.rb +3 -3
- data/lib/samagotchi/schedule_command.rb +1 -1
- data/lib/samagotchi/schedule_display.rb +4 -3
- data/lib/samagotchi/schedules/busy_part.rb +29 -5
- data/lib/samagotchi/schedules/history_part.rb +47 -7
- data/lib/samagotchi/schedules/marks_part.rb +52 -29
- data/lib/samagotchi/schedules/notices_part.rb +31 -4
- data/lib/samagotchi/schedules/protection_part.rb +69 -11
- data/lib/samagotchi/schedules/prune_part.rb +3 -2
- data/lib/samagotchi/schedules.rb +37 -47
- data/lib/samagotchi/send_command.rb +12 -12
- data/lib/samagotchi/session.rb +71 -59
- data/lib/samagotchi/session_access/contract.rb +7 -0
- data/lib/samagotchi/session_access/exchange.rb +1 -1
- data/lib/samagotchi/session_access/local.rb +9 -9
- data/lib/samagotchi/session_access/remote.rb +20 -24
- data/lib/samagotchi/session_access.rb +1 -1
- data/lib/samagotchi/session_chain/delete.rb +15 -8
- data/lib/samagotchi/session_chain/delete_preview.rb +3 -3
- data/lib/samagotchi/session_chain/links.rb +18 -4
- data/lib/samagotchi/session_chain/successor.rb +1 -1
- data/lib/samagotchi/session_chain.rb +3 -3
- data/lib/samagotchi/session_continue.rb +83 -32
- data/lib/samagotchi/session_inbox.rb +6 -17
- data/lib/samagotchi/session_inbox_delivery.rb +36 -13
- data/lib/samagotchi/session_lifecycle/allowed.rb +5 -5
- data/lib/samagotchi/session_manager/delegate_rule.rb +2 -2
- data/lib/samagotchi/session_manager/delivery.rb +13 -38
- data/lib/samagotchi/session_manager/emptiness.rb +35 -15
- data/lib/samagotchi/session_manager/lifecycle.rb +3 -2
- data/lib/samagotchi/session_manager/listing.rb +35 -10
- data/lib/samagotchi/session_manager/removal.rb +16 -0
- data/lib/samagotchi/session_manager/spawn.rb +9 -6
- data/lib/samagotchi/session_manager.rb +6 -4
- data/lib/samagotchi/session_messages.rb +602 -0
- data/lib/samagotchi/session_metrics.rb +7 -4
- data/lib/samagotchi/session_participants.rb +4 -4
- data/lib/samagotchi/session_protection.rb +16 -2
- data/lib/samagotchi/session_retention.rb +26 -12
- data/lib/samagotchi/session_row.rb +1 -1
- data/lib/samagotchi/session_stats.rb +17 -8
- data/lib/samagotchi/session_stores.rb +5 -0
- data/lib/samagotchi/session_transition.rb +3 -2
- data/lib/samagotchi/sessions_command.rb +55 -3
- data/lib/samagotchi/steer.rb +16 -50
- data/lib/samagotchi/storage_migration.rb +234 -0
- data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
- data/lib/samagotchi/terminal_ui/formatting.rb +5 -5
- data/lib/samagotchi/terminal_ui/join_replay.rb +3 -3
- data/lib/samagotchi/terminal_ui/question_prompt.rb +2 -2
- data/lib/samagotchi/toolkit_report_command.rb +1 -1
- data/lib/samagotchi/tools/ask_session.rb +2 -2
- data/lib/samagotchi/tools/send_note.rb +1 -1
- data/lib/samagotchi/turn_context.rb +3 -3
- data/lib/samagotchi/turn_endings.rb +17 -0
- data/lib/samagotchi/turn_excerpts.rb +7 -4
- data/lib/samagotchi/turn_flow.rb +1 -1
- data/lib/samagotchi/turn_note.rb +30 -2
- data/lib/samagotchi/turn_origin.rb +7 -7
- data/lib/samagotchi/turn_outcome.rb +11 -0
- data/lib/samagotchi/turn_stages/verify_anchors.rb +4 -4
- data/lib/samagotchi/verify_fresh.rb +6 -6
- data/lib/samagotchi/verify_fresh_origin.rb +4 -4
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +4 -3
- data/lib/samagotchi/web/last_ask.rb +2 -2
- data/lib/samagotchi/web/message_display.rb +12 -12
- data/lib/samagotchi/web/page_routes.rb +9 -3
- data/lib/samagotchi/web/participant_view.rb +4 -4
- data/lib/samagotchi/web/participants_admin.rb +1 -1
- data/lib/samagotchi/web/public/bubbles.js +1 -1
- data/lib/samagotchi/web/public/composer_fold.js +0 -3
- data/lib/samagotchi/web/public/composer_grip.js +0 -2
- data/lib/samagotchi/web/public/page_view.js +29 -4
- data/lib/samagotchi/web/public/participant_model.js +1 -1
- data/lib/samagotchi/web/public/peer_wait.js +2 -4
- data/lib/samagotchi/web/public/schedule_marks.js +2 -5
- data/lib/samagotchi/web/public/schedule_name.js +14 -0
- data/lib/samagotchi/web/public/session_actions.js +5 -0
- data/lib/samagotchi/web/public/start_page.js +1 -1
- data/lib/samagotchi/web/public/stop_sheet.js +2 -4
- data/lib/samagotchi/web/public/working_set_rail.js +0 -3
- data/lib/samagotchi/web/push/attention.rb +1 -1
- data/lib/samagotchi/web/session_create.rb +1 -1
- data/lib/samagotchi/web/session_hub.rb +68 -20
- data/lib/samagotchi/web/session_summary.rb +18 -14
- data/lib/samagotchi/web/verify_fresh_routes.rb +4 -4
- data/lib/samagotchi/worker/turn_drain.rb +158 -0
- data/lib/samagotchi/worker.rb +8 -144
- data/lib/samagotchi/worker_boot.rb +21 -5
- data/lib/samagotchi/worker_participant_gate.rb +5 -5
- data/lib/samagotchi/worker_presence.rb +24 -1
- metadata +6 -1
data/docs/sessions.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Sessions
|
|
2
2
|
|
|
3
|
-
Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/sessions/<uuid>.json` (XDG-aware via `XDG_STATE_HOME`) plus a sidecar dir `<uuid>/` with `input/`/`notes/`/`output/`/`owner.lock`/`bridge.json` (`Session.session_dir`), `turn_drawings.jsonl` once a turn ended with a Bridge or in a one-shot run (each finished turn as live drew it, which the web's reload draws: [bridge.md](internals/bridge.md#turndrawings); a fork starts with its parent's lines for the turns its seed keeps unchanged, a continue with none: its turns, and any without a line, are drawn from their messages), and `tool_output/` once a long `execute` result was cut: its whole output, which the cut result names (`ToolOutputFiles`, the newest 50 kept; see [Tool output guardrails](internals/tool-output-limits.md#the-runners-cut-max_tool_output_chars)). Its keys are in [the Session file table](#session-file). A file from before `used_memory_names`, `preloaded_memory_names`, `muted_memory_names`, `parent_id` or `continues` reads those as empty lists, no parent and no previous link.
|
|
3
|
+
Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/sessions/<uuid>.json` (XDG-aware via `XDG_STATE_HOME`) plus a sidecar dir `<uuid>/` with `input/`/`notes/`/`output/`/`owner.lock`/`bridge.json` (`Session.session_dir`), `turn_drawings.jsonl` once a turn ended with a Bridge or in a one-shot run (each finished turn as live drew it, which the web's reload draws: [bridge.md](internals/bridge.md#turndrawings); a fork starts with its parent's lines for the turns its seed keeps unchanged, a continue with none: its turns, and any without a line, are drawn from their messages), and `tool_output/` once a long `execute` result was cut: its whole output, which the cut result names (`ToolOutputFiles`, the newest 50 kept; see [Tool output guardrails](internals/tool-output-limits.md#the-runners-cut-max_tool_output_chars)). Its keys are in [the Session file table](#session-file). With `session.split_messages` on, the conversation is in that dir too, `<uuid>/messages-<gen>.jsonl`, and `<uuid>.json` holds the rest ([Messages file](#messages-file)). A file from before `used_memory_names`, `preloaded_memory_names`, `muted_memory_names`, `parent_id` or `continues` reads those as empty lists, no parent and no previous link.
|
|
4
4
|
|
|
5
5
|
The sidecar's `peer_exchanges.jsonl` records peer sends and transport
|
|
6
6
|
failures, never their text, and `peer_receipts.json` what the worker did with
|
|
@@ -31,7 +31,7 @@ unread messages reach the new link as one note); a delete removes them. See
|
|
|
31
31
|
| `SAMAGOTCHI_SESSION_KEEP_STATUS` | (none) | CSV of statuses never auto-pruned |
|
|
32
32
|
| `SAMAGOTCHI_SESSION_SWEEP_INTERVAL_HOURS` | `24` | Throttle lazy sweep |
|
|
33
33
|
|
|
34
|
-
A session is deleted if **expired by age OR overflow by count** (unless `keep_status` or the live-owner guard: a session a worker or `chi` still has open is never pruned). A session's `status` is its turn state (`idle`/`running`), not whether a worker is alive. Orphan dirs without a `*.json` are never deleted, except skeleton-only ones (see *Empty sessions*). Deletion removes its `*.json` and sidecar dir under the deleting owner lock, along with its plugin state, attached context, participant grants, System 1 runs and context-candidate records. Explicit delete and retention use the same cleanup path. Set both `DAYS=0` and `MAX=0` to retain forever. A session whose transition lock is held when its turn comes (a continue, a delete, a send's shared hold: one try, `SessionTransition`) is kept for the next sweep. A session something protects is kept whatever its age or place: an enabled schedule's anchor, head and resolved target (`SessionProtection.protected_ids`; schedules are its one protector, *Deleting a session*). A protector that can't answer stops the sweep's deletes for that round: a `schedules.json` that is there but doesn't read (not JSON, not a schedules document, a file chi can't open, or a schedule in it that doesn't read) protects everyone until it is fixed (one `retention_skipped` line per sweep interval, the next try at the next interval; the skeleton-only dirs and saved runs are still swept), and `chi sessions prune`/`clean` exit 1 with its words; a missing one is no schedules ([scheduling.md](scheduling.md#keeping-the-chain-short): `chi schedule cancel <id>` removes one schedule that doesn't read).
|
|
34
|
+
A session is deleted if **expired by age OR overflow by count** (unless `keep_status` or the live-owner guard: a session a worker or `chi` still has open is never pruned). A session's `status` is its turn state (`idle`/`running`), not whether a worker is alive. Orphan dirs without a `*.json` are never deleted, except skeleton-only ones (see *Empty sessions*) and ones holding the skeleton and an `analytics.json` with turns (a session whose file went), once that `analytics.json` is older than `DAYS` (`SessionManager.analytics_only_dir?`; nothing reads it without the session file; `DAYS=0` keeps them). Deletion removes its `*.json` and sidecar dir under the deleting owner lock, along with its plugin state, attached context, participant grants, System 1 runs and context-candidate records. Explicit delete and retention use the same cleanup path. Set both `DAYS=0` and `MAX=0` to retain forever. A session whose transition lock is held when its turn comes (a continue, a delete, a send's shared hold: one try, `SessionTransition`) is kept for the next sweep. A session something protects is kept whatever its age or place: an enabled schedule's anchor, head and resolved target (`SessionProtection.protected_ids`; schedules are its one protector, *Deleting a session*). A protector that can't answer stops the sweep's deletes for that round: a `schedules.json` that is there but doesn't read (not JSON, not a schedules document, a file chi can't open, or a schedule in it that doesn't read) protects everyone until it is fixed (one `retention_skipped` line per sweep interval, the next try at the next interval; the skeleton-only dirs and saved runs are still swept), and `chi sessions prune`/`clean` exit 1 with its words; a missing one is no schedules ([scheduling.md](scheduling.md#keeping-the-chain-short): `chi schedule cancel <id>` removes one schedule that doesn't read).
|
|
35
35
|
|
|
36
36
|
Retention and manual prune/clean silently stop each deleted session's verified background tasks under its deleting lock, with `by: retention` (`stopped_by_retention`). Sessions are processed sequentially, their tasks in parallel. Unverified or unreadable tasks are not signalled; stops and failures are logged per task as `retention_task_stopped` / `retention_task_not_stopped`, without commands. A scratch session's own cleanup does the same with `by: scratch` and `scratch_task_stopped` / `scratch_task_not_stopped`.
|
|
37
37
|
|
|
@@ -43,7 +43,7 @@ Retention and manual prune/clean silently stop each deleted session's verified b
|
|
|
43
43
|
|
|
44
44
|
**Always attached:** every interactive `chi` (plain, `-p`, `--resume ID`, `--attach ID`, `chi scratch`) runs its session in a background worker and attaches to it; there is no setting for it. The worker runs in the session's `working_directory`, so `!commands` and tools see the directory the session was started in. Only `chi -p TEXT --non-interactive` runs its one turn in this process; while it does, the session can't be attached ("in use by a one-turn chi --non-interactive run or an older chi's terminal"). See [CLI: Sharing a session](cli.md#sharing-a-session).
|
|
45
45
|
|
|
46
|
-
**Who may wake a session:** every turn delivery names its sender (`SessionManager.deliver_turn` requires `client_id`), and the sender's kind picks what it may do to the worker (`ClientId.wake_kind`, `
|
|
46
|
+
**Who may wake a session:** every turn delivery names its sender (`SessionManager.deliver_turn` requires `client_id`), and the sender's kind picks what it may do to the worker (`ClientId.wake_kind`, `InboxDelivery::WakePolicy.for_sender`). A person — `chi send`, a web tab, an attached terminal — starts an idle session, un-stops a stopped one and brings back an archived link. Nobody's message goes into a session being deleted (409 `session_deleting`, *Deleting a session* above), nor into one a transition holds right now (a continue's critical part: 409 `link_continued` naming the new link, else `transition_busy`; chi send and an ask try again, a schedule skips; docs/internals/session-lifecycle.md, Arrivals declare their hold). A schedule's firing, a plugin's `ctx.sessions.send`, a `delegate` follow-up, a participant's turn, an agent's `chi send` (`agent:<name>`, [driver and visitor](sub-agent.md#an-agents-messages-driver-and-visitor)), another session's `ask_session` and any sender chi doesn't name start an idle session only: a session its owner stopped or archived refuses them (409 `session_stopped`, "the session is stopped; only its owner's message starts it again", or `session_archived`, "…brings it back"), nothing written. A schedule counts that as a skip (and skips a stopped session at its check, [scheduling.md](scheduling.md)); `delegate` says it as `Error: session <id8> refused: …`; a plugin gets `Error`; an agent's `chi send` adds how its user starts it again ("ask your user to start it: `chi --resume ID`, …", `ChiInvocation#start_stopped`), and `chi sessions restart` on it is refused for an agent with the same "ask your user …", while a person's restart (and the web's Restart) starts it again (*Restart fallback* below); chi web's restart after an update leaves it stopped. A peer's say to a stopped session is not refused: it is received and written, only its wake waits, and its line names `chi --resume` (`chi is stopped: it reads this when its user starts it (chi --resume <id8>)`). A turn already handed to a live worker is that worker's, as before. chi web's owner turn and command routes name a body that carries no `client_id` as `web:unnamed` (a web tab's rights).
|
|
47
47
|
|
|
48
48
|
**Which chi a worker runs:** a new or woken worker runs the newest chi installed for this Ruby (`gem 'samagotchi', '>= 0.a'`, prereleases count), whoever starts it: a `chi web` or terminal still on an older chi starts it on the newest one, so a stale process doesn't spread old code. A worker already running keeps its version until it is restarted. Should the newest install fail to load, the worker runs the starter's own version and logs `boot_fallback` (its stdio is `/dev/null`). Under `bundle exec` the worker drops Bundler's env first, so it activates the newest gem too. Two consequences: a wrapper pin (`chi _0.17.0_ web`) pins only that process, not the workers it starts; and a source checkout (`bin/chi` in a worktree, `bundle exec`) starts its workers on its own `lib/`, but a session it made that is later woken by an installed chi (`chi web`, `chi send`) runs the installed code. The names an older starter hands a newer worker (the boot line, its env keys, `input/` files, the session JSON fields and the Bridge routes sessions use on each other) are pinned in `spec/worker_contract_spec.rb`. A chi newer than 0.130.0 keeps the top-level keys it doesn't know (a newer chi's fields) when it saves a session, after its own, and doesn't act on them; `written_by` names the chi that saved the file last, and a worker woken on a file a newer chi saved logs `newer_writer`. chi 0.130.0 and older drop those keys: a session a newer chi made loses its newer fields when an older chi wakes or saves it (for example `chi --attach` from a project whose Ruby has an older chi). Keep the chi in every Ruby you run it from newer than 0.130.0.
|
|
49
49
|
|
|
@@ -55,7 +55,7 @@ A new session field is one `Session::FIELDS` row, plus a `SessionSetup` member w
|
|
|
55
55
|
|
|
56
56
|
**Stopping a worker:** `chi sessions stop ID` marks the session stopped (an `<id>/stopped` file holding when, `{"at"}`, not a session.json field, which a worker saving at that moment would write over; a resume removes it), sends its worker TERM, then CONT (a stopped worker, SIGSTOP or Ctrl-Z, runs its TERM handler only once continued, so it leaves at once instead of outliving the wait), and waits (up to 10 s) until the worker has let go of `owner.lock`. A running turn is canceled over the Bridge first, with reason `session_stopped` (the turn's line ends "(session stopped)", its note says `cancelled (session-stopped)`, and a command it was running says "stopped as the session was stopped"; a bare signal to the worker makes it "stopped by a signal to chi"; an older worker takes the reason as `manual`); the TERM stops whatever still runs as a Stop with reason `signal` and saves it (a spawned worker traps TERM, HUP and INT: `WorkerSignals`; a turn not ended within 3 s, 0.5 s after a stop or a second signal, is cut and the session saved as it was), and a stopped worker still saves its kept turn, since the marker, not the saved status, says stopped. Any TERM, HUP or INT does the same to a worker outside a stop: it leaves (log `worker stop reason=signal`) and the next send wakes a new one, so a `chi --resume ID` right after spawns a fresh worker. That is also how to restart a worker still running an older chi, which the attached terminal reports when a command or a question dismiss gets a 404, and the web when an answer, a dismiss, a command or a cancel does (`501 not_supported`; `BridgeClient.stale_worker_message`). A command this chi has that the older worker doesn't (`/llm-context`, the web's ⚙ panel, against a 0.39.0 worker) says the same, not `not a session command` (`SessionCommandCatalog.builtin_name`); a typo keeps its `400 unknown_command`. The web's `POST /api/sessions/:id/stop` waits the same way, for 2 s (the page's Stop shows the stop at once), or for the body's `wait` up to the same 10 s (`SessionManager::STOP_WAIT`): `chi --remote NAME sessions stop` sends it, so it waits as long as here. Before that stop, the page's `stop session` button asks what the worker still has that the user can stop: `GET /api/sessions/:id/holds` (owner-only) answers the worker's `holds` — the same list the exit ask's 409 carries — always an array, empty when there is no live worker, one from before the route, or one that did not answer. Beside it, `schedules` (`[{id, title}]`, `Schedules.waiting_on`) names the enabled schedules whose target this session is (a chain's newest link, a same-mode session; not an archived link before it), which every tick skips while it is stopped (docs/scheduling.md, *Stopped by its owner*): read from the files, so it is there with or without a worker, and its own key, never a `holds` entry (a page from before it ignores it; a chi web from before it sends none, and the page says nothing). With something, a sheet (a bottom sheet on a phone, a popover at the button otherwise — `stop_sheet.js`) lists them, at most three of a kind named and `+N more`, and offers **Stop all** (`POST /api/sessions/:id/holds/stop` → `HoldStop#stop_all`, then the stop), **Stop session only** (the stop exactly as it was) or **Cancel**; a waiting schedule is one line between the list and the buttons (`Schedule "reflect" runs on this session. It is skipped while the session is stopped, and turns itself off after enough skips. Your message starts it again.`), not counted among the things to stop: neither button stops a schedule. Nothing to ask about is the plain confirm, one tap as before, with that sentence under `Stop session ID?` when a schedule waits. `chi sessions stop` prints the same as one line per schedule after the stop line (docs/cli.md; `SessionAccess::Local#waiting_schedules`, or `Remote#waiting_schedules` over that route, read before the stop). A warning, never a refusal: stopping a scheduled session is a valid pause. Both buttons stay because a stop only TERMs the worker: its reminders die with it (a stop also deletes a restart's `reminders.json` no successor took yet, so a later resume doesn't bring them back), while a background task and a delegate are their own processes and keep running. A delete or an archive differs: it never leaves a task the session started running unasked (*Deleting a session*: refused, or `--stop-tasks` stops it), where Stop's "Stop session only" does. A command sent during a turn that waits for its end (`/model X`, `!cmd`; see *Typing during a turn* in [cli.md](cli.md)) and hasn't run when the worker leaves (a stop, a crash) is answered `command_ran {status: "dropped"}`, so no UI keeps showing it waiting.
|
|
57
57
|
|
|
58
|
-
**Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. While the delete holds it (kind `deleting`), every delivery is refused: a message (`chi send`, the web, a schedule, a delegate, a plugin, a participant) gets 409 `session_deleting`, "the session is being deleted", and a send that read the session before the lock and wrote after it takes its file back and says the same (unless a worker took the file meanwhile: then it is delivered); a note is refused as for a gone session, and a delegate's ring, a push and a fresh verdict are not written. The web asks in one sheet first (*Session chains* → Deleting a link, the page side in docs/internals/web-frontend.md, The delete sheet): what goes, what is stopped first and what stays, one button naming the outcome, no browser confirm. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped, unarchived, moved_back}`; `deleted` and `left_running` too; 409 with the refusal's reason as its code; 404). A schedule's target, anchor or head is refused (`scheduled`, naming the schedule): deleting a head would make the schedule fall back to an archived link. Who refuses a delete is one question, `SessionProtection` (`session_protection.rb`, beside `SessionStores`, which says what a delete removes): every protector in `PROTECTORS` is asked (`hold` for a session, `chain_hold` for a chain, `protected_ids` for retention), schedules the one there is (`Schedules::ProtectionPart`), and the first hold is the refusal (`SessionManager.refuse_protected!`, `DeleteRefused` with the hold's reason and its `schedule_id`). It fails closed: a protector that raises is logged (`protector_failed`) and the error raised, so nothing is deleted; a store that is there but doesn't read (`SessionProtection::Unreadable`) refuses every delete, `protection_unreadable`, "schedules.json is unreadable (…): fix or remove it before deleting sessions" (the delete sheet shows it as the choice's refusal). An archive asks no protector. A user's delete (these three, `revive_previous:` and `refuse_continuing:` on `delete_session`) goes through `SessionChain::Delete.link` for every session, chained or not (*Session chains* → Deleting a link): **its delegates follow one rule** (`SessionManager::DELEGATES`): the stopped ones (archived ones too) go with it, deepest first, and a running one stays with its whole subtree, its file untouched; a stopped delegate with a running child goes and leaves that child without a parent. The delegates that would go bring their own refusals: one that is a schedule's target, anchor or head refuses the delete (`scheduled`, naming the delegate), as does one in a one-turn run, one a worker took after the plan was made (`worker_running`), and their running background tasks (below); their participant grants end with them. The result lists them in `deleted` (the session last) and the running ones with their subtrees in `left_running`; the CLI's line and `/exit --delete` say how many went. It holds the transition locks (`continue.lock`, `SessionTransition`) of the session, the previous link it would bring back and the delegates that go, exclusively and from before the stop to the end: it waits up to 10 s for them (`SessionChain::Delete::LOCK_WAIT`; a send's short hold is waited out), and is refused when one is still held then, `continuing` while a continue of the session or of that previous link is under way, else `transition_held` ("session X is being deleted" or "is busy with another change; try again in a moment": the holder named). While it holds them a send, a push or a peer say to the session is refused 409 `transition_busy`, "session X is being deleted; try again in a moment" (`chi send` retries), for the stop and task-stop time too. Deleting a chain's newest link undoes its continue (D2/D5 below), the ids it brought back in `unarchived` and the delegates it gave back in `moved_back`. A previous link brought back is aged for retention from then on (`unarchived_at`) and has no participants (the archive ended them, and an unarchive doesn't bring them back). The scratch cleanup, the empty-session discard, the failed-continue rollback and a schedule's prune delete plainly (`delete_resolved`: they pass neither keyword and take no delegates); the retention sweep removes files directly (`remove_files`). **Background tasks still running:** a user's delete (these three, and `chi sessions delete`) asks first when tasks the deleted sessions started (their `task_create` tasks and the `execute` runs handed over at their limit, read from each session's transcript and `<working_directory>/tmp/tasks/<id>/task.json`: `SessionManager::RunningTasks`) still run: it is refused before anything changes (`tasks_running`), and the CLI's `--stop-tasks`, the web's `stop_tasks=true` (the delete's and the chain delete's query; with `&tasks=<id,id>`, the ones the sheet named, only those: `RunningTasks::Policy.stop(only:)`, see *Deleting a link*) stop them first (`stopped_by_user`, TERM then KILL after 3 s, all at once, about 4 s at most), under the deleting lock, after the starting-marker re-check, so no worker takes the session meanwhile; that last check refuses a task that started since the first (`worker_stopped: true` when the worker was stopped by then). One rule, fail-safe: a task whose pid still leads the group chi started at the start time it recorded is *running*; one whose record has no start time (before 2026-10-09) or whose start time reads nothing now, while its pid leads a group, is *unverified* ("may still be running"); a `task.json` that doesn't read is *unreadable*. All three refuse; a stop signals only the running ones (an unverified pid may belong to another process now) and reports the rest as not stopped, then deletes. A record left marked running whose pid is gone (a crashed worker's) isn't listed. The 409 is `{error: "tasks_running", reason, op: "delete", detail, session_id, tasks: {running, unverified, unreadable}, worker_stopped, stopped_worker, stopped_workers}` (`stopped_worker`: whose worker the delete stopped before the last check refused; `stopped_workers`: every worker the delete stopped), each task `{session_id, id, command}` (`links` too for a chain delete's other links); the 200 gains `tasks_stopped`, `tasks_not_stopped` and `tasks_ended` (empty unless stopped). A session's file gone (its folder left) has no tasks. The retention sweep and scratch cleanup stop verified tasks silently; the empty-session discard, failed-continue rollback and schedule prune leave them running.
|
|
58
|
+
**Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. While the delete holds it (kind `deleting`), every delivery is refused: a message (`chi send`, the web, a schedule, a delegate, a plugin, a participant) gets 409 `session_deleting`, "the session is being deleted", and a send that read the session before the lock and wrote after it takes its file back and says the same (unless a worker took the file meanwhile: then it is delivered); a note is refused as for a gone session, and a delegate's ring, a push and a fresh verdict are not written. The web asks in one sheet first (*Session chains* → Deleting a link, the page side in docs/internals/web-frontend.md, The delete sheet): what goes, what is stopped first and what stays, one button naming the outcome, no browser confirm. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped, unarchived, moved_back}`; `deleted` and `left_running` too; 409 with the refusal's reason as its code; 404). A schedule's target, anchor or head is refused (`scheduled`, naming the schedule): deleting a head would make the schedule fall back to an archived link. Who refuses a delete is one question, `SessionProtection` (`session_protection.rb`, beside `SessionStores`, which says what a delete removes): every protector in `PROTECTORS` is asked (`hold` for a session, `holds` for a batch, the delegates that would go with a link or a prune's subtree: one read and one session listing for all of them, checked id by id in the same order, `SessionManager.protection_check`; `chain_hold` for a chain, `protected_ids` for retention), schedules the one there is (`Schedules::ProtectionPart`), and the first hold is the refusal (`SessionManager.refuse_protected!`, `DeleteRefused` with the hold's reason and its `schedule_id`). It fails closed: a protector that raises is logged (`protector_failed`) and the error raised, so nothing is deleted; a store that is there but doesn't read (`SessionProtection::Unreadable`) refuses every delete, `protection_unreadable`, "schedules.json is unreadable (…): fix or remove it before deleting sessions" (the delete sheet shows it as the choice's refusal). An archive asks no protector. A user's delete (these three, `revive_previous:` and `refuse_continuing:` on `delete_session`) goes through `SessionChain::Delete.link` for every session, chained or not (*Session chains* → Deleting a link): **its delegates follow one rule** (`SessionManager::DELEGATES`): the stopped ones (archived ones too) go with it, deepest first, and a running one stays with its whole subtree, its file untouched; a stopped delegate with a running child goes and leaves that child without a parent. The delegates that would go bring their own refusals: one that is a schedule's target, anchor or head refuses the delete (`scheduled`, naming the delegate), as does one in a one-turn run, one a worker took after the plan was made (`worker_running`), and their running background tasks (below); their participant grants end with them. The result lists them in `deleted` (the session last) and the running ones with their subtrees in `left_running`; the CLI's line and `/exit --delete` say how many went. It holds the transition locks (`continue.lock`, `SessionTransition`) of the session, the previous link it would bring back and the delegates that go, exclusively and from before the stop to the end: it waits up to 10 s for them (`SessionChain::Delete::LOCK_WAIT`; a send's short hold is waited out), and is refused when one is still held then, `continuing` while a continue of the session or of that previous link is under way, else `transition_held` ("session X is being deleted" or "is busy with another change; try again in a moment": the holder named). While it holds them a send, a push or a peer say to the session is refused 409 `transition_busy`, "session X is being deleted; try again in a moment" (`chi send` retries), for the stop and task-stop time too. Deleting a chain's newest link undoes its continue (D2/D5 below), the ids it brought back in `unarchived` and the delegates it gave back in `moved_back`. A previous link brought back is aged for retention from then on (`unarchived_at`) and has no participants (the archive ended them, and an unarchive doesn't bring them back). The scratch cleanup, the empty-session discard, the failed-continue rollback and a schedule's prune delete plainly (`delete_resolved`: they pass neither keyword and take no delegates); the retention sweep removes files directly (`remove_files`). **Background tasks still running:** a user's delete (these three, and `chi sessions delete`) asks first when tasks the deleted sessions started (their `task_create` tasks and the `execute` runs handed over at their limit, read from each session's transcript and `<working_directory>/tmp/tasks/<id>/task.json`: `SessionManager::RunningTasks`) still run: it is refused before anything changes (`tasks_running`), and the CLI's `--stop-tasks`, the web's `stop_tasks=true` (the delete's and the chain delete's query; with `&tasks=<id,id>`, the ones the sheet named, only those: `RunningTasks::Policy.stop(only:)`, see *Deleting a link*) stop them first (`stopped_by_user`, TERM then KILL after 3 s, all at once, about 4 s at most), under the deleting lock, after the starting-marker re-check, so no worker takes the session meanwhile; that last check refuses a task that started since the first (`worker_stopped: true` when the worker was stopped by then). One rule, fail-safe: a task whose pid still leads the group chi started at the start time it recorded is *running*; one whose record has no start time (before 2026-10-09) or whose start time reads nothing now, while its pid leads a group, is *unverified* ("may still be running"); a `task.json` that doesn't read is *unreadable*. All three refuse; a stop signals only the running ones (an unverified pid may belong to another process now) and reports the rest as not stopped, then deletes. A record left marked running whose pid is gone (a crashed worker's) isn't listed. The 409 is `{error: "tasks_running", reason, op: "delete", detail, session_id, tasks: {running, unverified, unreadable}, worker_stopped, stopped_worker, stopped_workers}` (`stopped_worker`: whose worker the delete stopped before the last check refused; `stopped_workers`: every worker the delete stopped), each task `{session_id, id, command}` (`links` too for a chain delete's other links); the 200 gains `tasks_stopped`, `tasks_not_stopped` and `tasks_ended` (empty unless stopped). A session's file gone (its folder left) has no tasks. The retention sweep and scratch cleanup stop verified tasks silently; the empty-session discard, failed-continue rollback and schedule prune leave them running.
|
|
59
59
|
|
|
60
60
|
<a id="archiving-a-session"></a>**Archiving a session:** `chi sessions archive ID...`, `/archive` in a terminal and the Web UI's `archive` go through `SessionManager.archive_session`: it writes `<id>/archived` (`{"archived_at": …}`; not a session.json field, which every save rewrites) for the session and its delegated children. `Session.list` leaves archived sessions out unless `include_archived:`, and everything built on it follows: `chi sessions list` (`--archived` shows them, `[archived]`), the summaries (`--live`, json/tsv, the desktop panel, the agent's `list_sessions`) and the retention prune, which neither deletes nor counts them against `max_count`. `children_of` (max_children, `delegate_result`) still sees them, and `--resume`/`--attach ID`, `chi send`/`chi note ID` reach them as before, except that `chi send` and `chi note` to a link that was continued go to its chain's newest link (*Session chains*). Refused: a turn running in the session or in one of its children (naming the child; 409 `busy` on the web), a prompt queued in `input/` (it would run on the next resume) or a live worker's step-limit question still open, in it or a child (409 `busy` too), a one-turn `chi --non-interactive` run owning it (`owned_by_tui`), a `chi scratch` session (`scratch`). A live idle worker is stopped first, and the marker is written even if it is still shutting down. Input a human typed brings a session back (`{"unarchived_at": …}`): a prompt from the web, an attached terminal or `chi send` (origin `web:*`, `tui:*`, `cli:send`, its own first prompt: `spawn:first`; input naming no sender doesn't), steering merged into a running turn, a `/continue` answer or a question answered (the step-limit question too); a delegate's follow-up, a plugin's turn, a reminder, the idle recap, a note and just opening it don't. A child's input brings only the child back. The retention sweep ages an unarchived session from when it was unarchived, so unarchiving an old session doesn't let the next sweep take it. `/archive` leaves the session first, as `/exit` does, then archives it: in an attached terminal the worker is asked to exit (one that stays up for another UI is stopped by the archive; a running turn, a queued prompt or an open step-limit question refuses it), and an empty session is discarded instead; `chi scratch` refuses it. Typed while a turn runs, `/archive` waits for the turn's end (an attached terminal for the commands queued behind it too) and then archives. `chi sessions unarchive ID...` and the web's `unarchive` bring back the whole family. **Background tasks still running** in the session or a delegate refuse an archive as they refuse a delete (*Deleting a session*: the same rule and listing), before anything changes: 409 `tasks_running` (not `busy`, so an older client doesn't say "a turn is running"), `op: "archive"`. The web's Archive stays one tap (the toast's Undo) when nothing is in the way; its 409 opens the delete sheet in Archive's words (what is hidden, the tasks it stops first, `Stop them and archive`, which sends the tasks it named), and any other refusal is that sheet's "Can't archive … now". The 409 also says `sessions`: how many sessions the archive would hide (it and its delegates, across every project), plus `stopped_workers` (every stopped worker id). The refusal words name one stopped worker as "its worker was stopped" or "9d0e1f2a's worker was stopped", and several as "N workers were stopped: its own, 9d0e1f2a". `chi sessions archive --stop-tasks`, or the archive route's body `{"stop_tasks": true}` (with `"tasks": [ids]` only those; a running one not named refuses, `tasks_running`, nothing archived: up front before any worker is stopped, and again after the workers let go), stops them first: after the tree's live workers were stopped and let go (or the wait ran out: such a worker's own waiter then records the stop from the `stop_requested_by` flag on disk), and before the marker; the 200 gains `tasks_stopped`, `tasks_not_stopped` and `tasks_ended`. The task stop and the markers run under the sessions' transition locks (kind `archive`, after the workers' stops; a send meanwhile is refused "being archived"); another change holding one of them for longer than 10 s (a continue, a delete) refuses the archive in its words (409 `busy`, reason `transition_held`). Undo (unarchive) doesn't restart them. Web routes: `POST /api/sessions/:id/archive` (200 `{status, session_id, archived, stopped, discarded}`, ids) and `POST /api/sessions/:id/unarchive` (200 `{status, session_id, unarchived}`). The session hub and `GET /api/sessions` keep archived sessions, `archived: true` in their summaries: the page leaves them out of the strip, its count and the list at render, and the `archived` toggle beside the all-sessions search shows them, dimmed with an `archived` badge. The info bar marks a session whose live worker runs an older chi than the newest installed (`worker_version` in its summary): `chi 0.18.1 · Restart`, which asks to confirm and calls `POST /api/sessions/:id/restart` (a refusal's reason shows in a toast); a worker from before restarts shows `chi sessions stop ID` instead. The info bar reads `continue → · archive · stop · delete` (`unarchive` on an archived one; no `continue →` on a link continued already, see *Session chains*; `continue →` is a plain button like `archive`, in the accent on an archived session, where it is the thing to do); archiving the open session stays on it, with an Undo toast.
|
|
61
61
|
|
|
@@ -75,6 +75,7 @@ chi sessions delete [--force] [--dry-run] ID... # for good; --force stops
|
|
|
75
75
|
chi sessions prune [--dry-run] [--days N] [--keep N] [--keep-status running,...] [--test-only]
|
|
76
76
|
chi sessions clean [--dry-run] [--days N] [--all] # test sessions: all, or older than N days; --all: every kind, as prune
|
|
77
77
|
chi sessions stats ID [--format text|json] # cost, tokens and progress, without a model turn
|
|
78
|
+
chi sessions migrate [--dry-run] [--id ID]... [--json] # saved sessions to the split messages file (Messages file below)
|
|
78
79
|
```
|
|
79
80
|
|
|
80
81
|
`chi sessions stats ID` prints what `/stats` prints in a terminal, headed by `<id8> <status> <model>`: a live worker answers its Bridge's `GET stats` (no model call, and the command never starts a worker); without one, or when the worker does not answer in time, the same snapshot is rebuilt from the session's saved `analytics.json` (and the line says so when a worker was live). `--format json` prints one object `{session_id, status, live, metrics}` with the snapshot as `metrics` (its `turn_records` / `tool_records` are the recent ones only: a live worker's newest finished turn and any not yet saved, the disk snapshot's newest saved turn; `analytics.json` holds them all); a session with no `analytics.json` yet reports `metrics: null` (`(no metrics yet)` in text) and still exits 0. An unknown or ambiguous id exits 1 with the same wording `chi sessions stop` uses.
|
|
@@ -154,7 +155,8 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
154
155
|
| `model_name` | The resolved model ref (an alias applied; `host:id` when it names a host), so a resume keeps the model. A `served` ref is saved as written (`main:served`, never the id it resolved to): each turn resolves it again, and the turn's records name the id. Required. | creation, `/model` |
|
|
155
156
|
| `model_typed` | The name it was typed as when that differs (an alias), for the `models:` lookup after a resume; `null` otherwise. | creation, `/model` |
|
|
156
157
|
| `working_directory` | The folder the session runs in. Required. | creation |
|
|
157
|
-
| `messages` | The conversation (symbol keys in memory, strings on disk). While a turn runs, a save writes the turn's checkpoint here instead (`TurnCheckpoint`). | the Engine, per turn |
|
|
158
|
+
| `messages` | The conversation (symbol keys in memory, strings on disk). While a turn runs, a save writes the turn's checkpoint here instead (`TurnCheckpoint`). How the file holds them is `SessionMessages` (`session_messages.rb`), which the readers that parse the file themselves ask too (`SessionMessages.of_file`/`.read`); `Session.load(id, messages: false)` leaves them out (that session's save raises). Each save logs a `save_shape` record at info (`SessionMessages::SaveShape`: `new`, `same`, `append`, `head`, `rewrite at=k`, against the messages saved or read last; about 1.5 ms a save on a 2 MB session). A split session's file has no `messages`: `messages_log` names where they are ([Messages file](#messages-file)). | the Engine, per turn |
|
|
159
|
+
| `messages_log` | Only in a split session's file, in the place of `messages` (not a `FIELDS` row): `{v: 1, file: "messages-<gen8>.jsonl", count:, bytes:}`, the generation holding the conversation and its committed lines and bytes. `Session.from_h` drops it (no `newer_writer`). | `Session#save` (`SessionMessages::Store`), `chi sessions migrate` |
|
|
158
160
|
| `created_at`, `updated_at` | ISO times; `updated_at` is stamped by every save and orders the lists. Required. | `Session#save` |
|
|
159
161
|
| `status` | `idle`, `running`, `error` or `stopped` (turn state, not liveness; a stop is also the `<id>/stopped` marker). | the worker / Engine; the marker by `chi sessions stop` |
|
|
160
162
|
| `last_prompt` | The newest prompt; a session created with a first prompt holds it here until its worker takes it; after an `error` status, the reason. | `SessionManager.spawn_session`, the Engine, `Session.mark_error` |
|
|
@@ -189,6 +191,46 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
189
191
|
| `first_turn_client_id` | Who sent the creating prompt: any sender that is no human's (`delegate:<parent8>` for a delegate's task, `system:schedule:<id>` for a chain schedule's link, `agent:<name>`) and an interactive one (a web tab's `web:…`, a TUI's `tui:…`); none for `chi send --new`, an idle create, and a file from before interactive ids were kept: that first turn's origin, so its line is no command of the owner's (docs/guardrails.md, Who may run a session command) and `last_turn` names the sender. Written only when set; not carried by a fork, a continue or a delegate. An older chi keeps it but runs the first prompt as a person's. | `SessionManager.spawn_session` (its `client_id:`) |
|
|
190
192
|
| `verify_fresh` | A Verify fresh child's requester, rules and claim (`VerifyFreshOrigin`). | `VerifyFresh.start`, once |
|
|
191
193
|
|
|
194
|
+
### Messages file
|
|
195
|
+
|
|
196
|
+
With `session.split_messages` on (off by default; a session read split is saved split whatever it says), a save writes
|
|
197
|
+
the conversation into `<uuid>/messages-<gen8>.jsonl`, one `JSON.generate` per message and line, and `<uuid>.json`
|
|
198
|
+
without `messages`, naming that file in `messages_log` (its `count` lines and `bytes`). `<uuid>.json` is the one commit
|
|
199
|
+
point: what it names is the conversation, and every save still renames it (the hub and `changed_since` see each one).
|
|
200
|
+
|
|
201
|
+
- **Append or rewrite.** A save compares its messages, serialized, with the lines it committed last: only lines added
|
|
202
|
+
(and `<uuid>.json` still its own last commit) appends them to the same generation, cut to its committed bytes first;
|
|
203
|
+
anything else (an edit in place, a changed system head, another writer since) writes a new generation (`File::EXCL`,
|
|
204
|
+
never changed after) and then the metadata naming it. Each split save logs `save_shape … store=split by=append|rewrite
|
|
205
|
+
wrote=<bytes>`.
|
|
206
|
+
- **Generations.** The one a rewrite replaced, and one a crashed rewrite left (no metadata names it), is a stray, removed
|
|
207
|
+
by a later save once older than 60 s (`STRAY_GRACE`), so a reader that parsed the older `<uuid>.json` still reads its
|
|
208
|
+
committed bytes. A reader that finds its generation gone reads `<uuid>.json` again, once (`SessionMessages.parse`).
|
|
209
|
+
- **Crashes.** Bytes past the committed ones (a torn line, an append whose metadata never came) are ignored and cut by
|
|
210
|
+
the next append. A generation shorter than its committed bytes, a `count` that isn't its lines, or a line that doesn't
|
|
211
|
+
parse fails closed: "Session file corrupted", as a `<uuid>.json` that doesn't parse (the owner's next save writes its
|
|
212
|
+
own messages into a new generation). A first save that crashed before `<uuid>.json` leaves a folder with a generation
|
|
213
|
+
and no session: the retention sweep takes it as an orphan's.
|
|
214
|
+
- **Deleted meanwhile.** A save of a session deleted since it was read writes nothing (`save_skipped_deleted`), the
|
|
215
|
+
append's and the rewrite's alike (a new generation it wrote goes, with a folder it made).
|
|
216
|
+
- **Older chi.** chi 0.201.0 and older read a split session as one with no conversation (lists, the hub and the page
|
|
217
|
+
show it; its conversation is empty there), and a turn one of them runs is saved inline beside the `messages_log` it
|
|
218
|
+
keeps: this chi reads the log's messages, then those (the inline system head in the log's head's place), and its next
|
|
219
|
+
save is split again (compat shim `messages_inline_beside_log`). Nothing is lost; downgrading past the release that
|
|
220
|
+
ships the split is outside the N-1 rule.
|
|
221
|
+
- **Converting.** `chi sessions migrate` moves saved sessions to the split file (`StorageMigration`, step
|
|
222
|
+
`session-split-messages` v1): every session file, archived ones too, its other keys as they were (no save:
|
|
223
|
+
`updated_at` and `written_by` stay), its messages file synced to the disk before `<id>.json` names it
|
|
224
|
+
(`F_FULLFSYNC` on macOS, else `fsync`; a save doesn't sync), each checked after (read back, or put back as it
|
|
225
|
+
was). A session a worker owns, one being started or one a transition holds is skipped: it converts at its own next save. A conversion holds the
|
|
226
|
+
session's transition lock (kind `migrate`) and its owner lock (kind `migrating`) for the milliseconds it takes.
|
|
227
|
+
Meanwhile a send, a push, a peer's say or a schedule's turn is refused, "session X is being migrated; try again in a
|
|
228
|
+
moment"; a stop waits for the lock (up to 10 s), else is refused the same; a note, a delegate's ring, a fresh
|
|
229
|
+
verdict and a leaving worker's restart go in and wait for it (up to 5 s) before starting a worker or finding one; a
|
|
230
|
+
resume (`chi --resume`, `--attach`) starts the worker, which waits for it. Nothing signals the migrating process. It needs
|
|
231
|
+
`session.split_messages` on (exit 2 otherwise); `--dry-run` reads only and reports what it would convert. Run again,
|
|
232
|
+
it converts only what is left.
|
|
233
|
+
|
|
192
234
|
## Context notes
|
|
193
235
|
|
|
194
236
|
A context note is text pushed into a session as background: not a prompt, and it starts no turn.
|
|
@@ -360,7 +402,7 @@ pbpaste | chi send 3fa2 # the clipboard is the messa
|
|
|
360
402
|
- Fire and forget: it returns once the message is queued and never prints the answer; that shows in whatever is attached. A guardrail "ask" waits for a UI to answer it, so with nothing attached the turn stalls there until one attaches (`chi --attach ID`).
|
|
361
403
|
- `--image PATH` (repeatable, up to 20) sends images with the message, as the web composer's chips do. Each file is read once before anything is sent (bmp, tiff and heic converted to png, large ones downscaled, as for `@path`); a missing file or one that isn't an image stops the send (exit 1; with `--wait --format json`, an `error` line) and nothing is sent; more than 20 is a usage error (exit 2). Each session gets its own copy in `<session>/images/`. Text is still required (`-m` or stdin; context alone counts), also with `--wait`. The session's model must see images: one known not to (the host's model list says text-only, `vision: false` in `models:` or `hosts:`, a native llama.cpp without a vision model) is refused before anything is sent, with the reason (`<id> refused: gemma can't take images (…); send text only or switch the model (/model)`); the other sessions of the same send still get it, and the exit is 1. With `--new` nothing is started. When chi can't tell (a native host whose `/props` doesn't answer, a list that doesn't say), the message is sent as before and a text-only model fails the turn in the session. A running turn doesn't take images mid-turn: the message runs as the next turn, and the line says `(runs after the current turn)`. With `--new` the session starts idle with the message as its preview, then the message goes in as its first turn once its worker is up (`<id> started with 1 image`); if the worker doesn't come up in 5 s the session is kept, with its id on the `failed:` line.
|
|
362
404
|
- A session command runs as the command, as typed in a terminal: `chi send -m "/model qwen" 3fa2` switches the model (`sent as a session command`), and the model never sees the line. What counts is what the session's worker knows (the built-ins, `!cmd`, its bundles' commands); an unknown `/word` (`/usr/bin/env is missing`) goes in as a message. A UI-only command (`/stats`, `/exit`, `/recap`, …) is refused instead: the worker doesn't run it, so the line would reach the model as a prompt (`<id> refused: /stats is a terminal and web command; use chi sessions stats <id8>`; exit 1, and nothing is sent). With `--new` a line starting with `/` or `!` starts the session idle and goes to its worker once it is up, which decides. With `--wait` a command has no reply to wait for: exit 0 at once, `<id> sent as a session command: no reply to wait for …` on stderr (`{"status":"command",…,"detail":…}` with `--format json`); its output shows where the session is open.
|
|
363
|
-
- A session that was **continued** (archived, with a later link): the message goes to its chain's newest link, as a note does (*Context notes*), and the old link stays archived. The line names both, in `chi note`'s wording: `3f9a1c2e → 7b2d41aa (continued) sent`. Every id is resolved once, before anything is sent (`SessionAccess#head`, `
|
|
405
|
+
- A session that was **continued** (archived, with a later link): the message goes to its chain's newest link, as a note does (*Context notes*), and the old link stays archived. The line names both, in `chi note`'s wording: `3f9a1c2e → 7b2d41aa (continued) sent`. Every id is resolved once, before anything is sent (`SessionAccess#head`, `InboxDelivery::Head`'s walk for the `send` row), so the parent-answers check, images, a session command, the UI-only refusal and `--wait` all act on that newest link, and `chi send OLD NEW` sends once. `--wait` waits there: its `--format json` `session_id` is the newest link's, and `asked` the id given (only when they differ). `--wait` without a message follows too, but `--wait --turn T` of the old link (a turn from before the continue) waits on the old one. A link archived and never continued is still brought back by a send (a schedule's anchor whose successor a prune deleted counts as continued: the send goes to the schedule's head, *Session chains* → Which link). A link being continued right now (its intent written, its new link not saved yet: `SessionContinue`) is asked again for up to 10 s; still not there, it is refused and nothing is written: `3f9a1c2e refused: session 3f9a1c2e is being continued as 7b2d41aa-…; send again in a moment`. A continue that ends or starts after that resolve still never gets the old link: chi send's delivery says it follows (`deliver_turn`'s `follow:`, `follow: true` on chi web's turn route for `chi --remote`), and an archived link with a saved successor, or one a continue holds the lock of, refuses it (409 `link_continued`, nothing written; the check and the input go in under a shared hold of that lock, so no continue starts between them); chi send resolves again and sends to the new link (taking back the `--image` copies it made in the old one, on this machine; `chi send OLD NEW` still sends once), for up to 10 s, then the same refusal, or `refused: session 3f9a1c2e is busy with another change; try again in a moment` when the lock's holder names no new link (409 `transition_busy`; chi send tries that same link again after a pause, within the same 10 s). Every sender's turn takes that hold, not only a followed one: the web composer, a participant, a delegate follow-up, a plugin and a schedule (which skips the firing) are refused the same way while a transition holds the session (an older chi web ignores `follow` and sends as before). A chain's first link's id is a stable address for the whole chain. What stays on the id it names: the web composer (typing on an archived link's page brings that link back), a participant's turn (a grant is for one session), `delegate(session:)`, a plugin's turn and a schedule (its own rule, *Schedules*).
|
|
364
406
|
- One line per session: `sent`, `sent as a session command`, `sent with 2 images`, `sent (goes in at the running turn's next step)`, with `--cut` `sent (cut in now)`, `sent (cuts in once the thinking passes 20 s)` or `sent (cutting is off; goes in at the next step)`, with `--queue` `sent (queued: runs after the current turn)`, `sent (the running turn had ended: it runs now)` or `sent (nothing running: it runs now)`, `sent (started its worker)`, `refused: …` or `failed: …`. Exit 0 when all were sent, 1 when any was refused, failed or not found, 2 for a usage error. There is no `--all`.
|
|
365
407
|
|
|
366
408
|
The Automator action above works for messages too: swap its last line for `pbpaste | "$chi" send -m "what do you make of this?" $(print -r -- "$picked" | cut -f1)`.
|
data/docs/sub-agent.md
CHANGED
|
@@ -91,8 +91,7 @@ In chi web an agent's message that opens a turn (the driver's or a visitor's,
|
|
|
91
91
|
and an `ask_session` question) shows as a closed row like a delegate report's,
|
|
92
92
|
"agent codex · ‹first line› · N lines"; a tap opens it.
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
goes as `chi send`'s, today's behaviour.
|
|
94
|
+
Agent messages retain their `agent:<name>` client id when sent to workers or chi web.
|
|
96
95
|
|
|
97
96
|
## The commands
|
|
98
97
|
|
data/docs/testing.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
```sh
|
|
4
4
|
bundle exec parallel_rspec -n 8 spec lib/samagotchi/bundles/*/spec # Ruby specs, both roots, in parallel
|
|
5
|
+
script/spec-map record [-n N] # the same full suite, recording the spec map (below: When the full suite runs)
|
|
5
6
|
bundle exec rspec spec lib/samagotchi/bundles/*/spec # the same, plain
|
|
6
7
|
bundle exec rake bundles:specs # the shipped bundles' own specs, on the bundle test kit alone
|
|
7
8
|
npm test # web frontend specs, including the new-module exports ratchet
|
|
@@ -102,6 +103,9 @@ continue, a delegate child, a plain spawn, a Verify fresh child, a respawn; a re
|
|
|
102
103
|
`carry_matrix.json`, what each keeps of its source. They are pinned before Session's fields became one table and are kept
|
|
103
104
|
as the file format's pins, not retired: a diff is a change to every session file on disk, so only a commit that means to
|
|
104
105
|
change the format regenerates them (`UPDATE_GOLDENS=1 bundle exec rspec spec/session_file_goldens_spec.rb`).
|
|
106
|
+
They are written with `session.split_messages` off (its default), as is `spec/session_messages_spec.rb`'s pin: a split
|
|
107
|
+
change keeps those bytes identical. The split file's own shape (`messages_log` v1's keys and a generation's line form)
|
|
108
|
+
is pinned by `spec/session_messages_split_spec.rb` against `spec/fixtures/session_messages_log/`.
|
|
105
109
|
|
|
106
110
|
`UPDATE_GOLDENS=1` is the characterization specs' variable (the prompt and turn goldens above use `UPDATE_PROMPTS`):
|
|
107
111
|
the model-setting ones above, the session file goldens, claude-peer's goldens and the bundle-state corpus below. Regenerate only for an intended
|
|
@@ -175,6 +179,12 @@ A corpus after 0.168.0 also records every registered cross-version session store
|
|
|
175
179
|
(`SessionStores`): objective checks, tracks and proposal cards, delegates,
|
|
176
180
|
pending cards, reminders and parent overrides. The starting marker is the
|
|
177
181
|
documented stale-file exception.
|
|
182
|
+
A corpus after 0.201.0 also holds `compat-split` (`CompatSplit`): a session whose messages are in their own file
|
|
183
|
+
(`messages-c0ffee00.jsonl` beside `compat-split.json`, which names it in `messages_log`), converted with
|
|
184
|
+
`SessionMessages.split_file!` whatever the recording machine's `session.split_messages`; readers_spec loads its
|
|
185
|
+
messages, so the release after the one that ships the split reads what that one wrote (N reads N-1). The recorders
|
|
186
|
+
(`write_compat_corpus!`, `CompatWire.with_isolated_env`) clear `SAMAGOTCHI_SESSION_SPLIT_MESSAGES`, so the other
|
|
187
|
+
samples, `wire/sessions/` included, stay inline.
|
|
178
188
|
A corpus after 0.192.0 also holds System 1's record (`guardrails/judgments.jsonl`: a rule whose one deny keeps it from
|
|
179
189
|
auto-allowing), its saved runs (`system_one/runs/`) and the context candidates' record (`context_candidates.jsonl`),
|
|
180
190
|
written by `CompatMachineStores` with fixture values only: a machine path in them stops the bump.
|
|
@@ -443,6 +453,7 @@ any other file requires it, so a spec file run alone still finds its requires. E
|
|
|
443
453
|
| `recording_surface.rb` | `RecordingSurface`: a `TerminalUI::Surface` that records commits and slots instead of drawing |
|
|
444
454
|
| `remote_backend.rb` | `RemoteBackend`: `SessionAccess::Remote` against chi web's Rack app in this process (no socket, LAN token gate) |
|
|
445
455
|
| `reply_wait_looks.rb` | `ReplyWaitLooks`: counts a `ReplyWait`'s polls, so a step waits for the looks instead of a delay |
|
|
456
|
+
| `saved_messages.rb` | *helper*: `saved_messages(id, state_dir:)`, the conversation a session's file holds as chi reads it back (`SessionMessages.read`, string keys): ask it rather than parse `<id>.json` for `"messages"` |
|
|
446
457
|
| `session_hubs.rb` | `stop_session_hubs`: stops every `Web::SessionHub` the example built (joining its sweep thread) before a teardown removes the state dir; a config-level after stops any left over |
|
|
447
458
|
| `stamps.rb` | *helper*: `next_stamp`, distinct ordered times for the lib's `now:` seams; the pinned history clock |
|
|
448
459
|
| `task_dirs.rb` | `with_task_dir`: a tasks' folder of its own, every task stopped and its recorders joined after |
|
|
@@ -509,16 +520,74 @@ well formed (unique ids, known keys and labels, a rule that exists in its set).
|
|
|
509
520
|
## While you work: affected specs
|
|
510
521
|
|
|
511
522
|
```sh
|
|
512
|
-
script/affected-specs # the specs for this branch's change, best first
|
|
513
|
-
script/affected-specs --run # runs them
|
|
514
|
-
script/affected-specs --why # with the reason for each pick; --all: no cap; --
|
|
523
|
+
script/affected-specs # the specs for this branch's change, best first
|
|
524
|
+
script/affected-specs --run # runs them: the required run, while working and before committing
|
|
525
|
+
script/affected-specs --why # with the reason for each pick; --all: no cap; --cap N: at most N name picks
|
|
515
526
|
script/affected-specs A..B # another range (A...B: from their merge-base); a single REV: vs the working tree
|
|
527
|
+
script/affected-specs --audit FILE # the failing spec files FILE names: picked, beyond the cap, or missed
|
|
528
|
+
script/spec-map show SPEC # what a spec file executes, by the spec map
|
|
529
|
+
script/spec-map show FILE#name # which spec files execute a method (to read a miss)
|
|
516
530
|
```
|
|
517
531
|
|
|
518
|
-
|
|
532
|
+
`script/affected-specs` answers from two sources. The **spec map** (`tmp/spec_map.json` in the main checkout, one per
|
|
533
|
+
clone, read by every worktree, never committed) is what the last `script/spec-map record` saw: which lib, bin and
|
|
534
|
+
script methods each spec file ran, in the rspec runner and in every Ruby process it started (a recorder that
|
|
535
|
+
`record` puts in `RUBYOPT`). The **name matches** are the specs named after the changed files and the rules below.
|
|
536
|
+
|
|
537
|
+
With a map, each changed Ruby code file outside the bundles gets a verdict. Both sides of the change are judged: the
|
|
538
|
+
base's changed lines against the base's source, the new lines against the new source. A code line is one Prism's
|
|
539
|
+
lexer has a token on, comments and line ends aside, so every line of a heredoc is code.
|
|
540
|
+
- **answered**: every changed code line is inside a method the map knows. The picks are the spec files that ran
|
|
541
|
+
those methods (`executes Schedules#late? (lib/samagotchi/schedules.rb)`); a deleted method is answered by its old
|
|
542
|
+
name.
|
|
543
|
+
- **whole file**: a changed code line outside every method, a method the map lacks (a new one, the target side of a
|
|
544
|
+
move), a method that ran while the spec files loaded, a deleted file. The picks are the spec files that ran any
|
|
545
|
+
method of the file.
|
|
546
|
+
- **nothing**: only comments and blank lines changed. **unknown**: the map has no method of the file (a new file,
|
|
547
|
+
constants only, a script that is not Ruby).
|
|
548
|
+
|
|
549
|
+
The map's **floor** is the methods at least 98% of the spec files run (spec_helper's hooks: `Log.reset!`,
|
|
550
|
+
`Paths.state_home`…). They say nothing about who depends on them: a whole file leaves them out of its callers, and a
|
|
551
|
+
changed floor method picks none (`--why` says so; the full run covers it).
|
|
552
|
+
|
|
553
|
+
The list: the changed specs, the specs that execute the change (those named after a changed file first, then the
|
|
554
|
+
cheapest recorded first), the picks of the rules marked `always` (the class-cycle ratchet and the cheap specs that
|
|
555
|
+
read every lib file as text), then the name matches as without a map, the first `--cap` (16) of them. Only the name
|
|
556
|
+
matches are capped. One summary line on stderr says what the answer rests on; paste it into your report:
|
|
557
|
+
|
|
558
|
+
```
|
|
559
|
+
affected-specs: map 938e60df3 (2026-12-05, 12 behind this base): 3 files answered, 1 whole file
|
|
560
|
+
(lib/samagotchi/config.rb: code outside a method changed), 0 unknown; 31 spec files execute the change, 9 more by
|
|
561
|
+
name; about 40 s recorded
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
It says how far the map's commit is from the code (`behind`, `ahead`, or `at a commit this clone lacks`), a map
|
|
565
|
+
recorded red or on a dirty tree, a changed method whose executing specs differed between two recordings of one
|
|
566
|
+
commit (`volatile`: its users can be missed, the full run is the check), and picks above half of the suite's
|
|
567
|
+
recorded time. Without a map the output is the name matches alone; `--why` and `--run` add `no spec map
|
|
568
|
+
(script/spec-map record makes one): name matches only`. `--map FILE` reads another map, `--no-map` none (a spec that
|
|
569
|
+
runs the script passes one of them). `--run` runs the list with `bundle exec rspec`, or above 15 recorded seconds
|
|
570
|
+
with `bundle exec parallel_rspec -n 4` (`--jobs N`) and `--format progress`, which leaves
|
|
571
|
+
`tmp/parallel_runtime_rspec.log` and `tmp/parallel_failures.log` as the last full run left them.
|
|
572
|
+
|
|
573
|
+
What the map cannot see (the name matches and the rules stand beside it for these):
|
|
574
|
+
- **Bundle plugin code**: `Plugin::Loader` module_evals a bundle's files, and Coverage tracks required and loaded
|
|
575
|
+
files only. A change in a bundle picks by the bundle tier.
|
|
576
|
+
- **A child started without `RUBYOPT`** (or with `unsetenv_others`) does not record: `scaffold_spec.rb` (`chi bundle
|
|
577
|
+
new/check/test`), `spec/support/lock_holder.rb`, `shipped_history_spec.rb`, `note_command_spec.rb`,
|
|
578
|
+
`send_command_spec.rb`, `affected_specs/cli_spec.rb`. Their rows miss what the child ran.
|
|
579
|
+
- **One recording is one run order**: a method reached through a per-process cache is credited to the spec file that
|
|
580
|
+
fills it first. `volatile` names the methods where two recordings of one commit differed.
|
|
581
|
+
- **Methods only**: a file's top-level code and constants are invisible. A change outside a method gets the whole
|
|
582
|
+
file, which names the specs that called a method of it: all of a widely run file's callers (`session.rb`), few for
|
|
583
|
+
a file that is mostly top level (`bin/chi`) or constants. A spec that reads a file as text has no row for it (the
|
|
584
|
+
`always` rules).
|
|
585
|
+
|
|
586
|
+
The name matches: the specs the change touched, the specs named after the
|
|
519
587
|
files it changed (`lib/samagotchi/foo/bar.rb` → `spec/foo/bar_spec.rb`, `bar_*_spec.rb`…;
|
|
520
588
|
`lib/samagotchi/foo/bar/baz.rb` → `spec/foo/bar_baz_spec.rb`), the specs that read
|
|
521
|
-
docs or source as text (its `RULES`: add one when a full run catches what the names
|
|
589
|
+
docs or source as text (its `RULES`: add one when a full run catches what the names and the map missed; `always: true` keeps a cheap
|
|
590
|
+
one's picks past the cap) and the golden of a changed
|
|
522
591
|
file's layer (any `foo/*.rb` → `spec/foo_golden_spec.rb` when there is one; `turn_flow.rb` and `turn_note.rb`, whose
|
|
523
592
|
words the attached TUI prints, pick its `event_renderer` and `attached_loop` specs by a rule; `memory_bundle/*.rb`,
|
|
524
593
|
`bundle_command.rb`, `memory_paths.rb`, `model_overlay.rb` and the corpus's fixtures pick the bundle-state corpus). Changes to `tool_declarations.rb` and `system_prompt.rb` also pick the
|
|
@@ -541,9 +610,24 @@ changed spec adds (`git diff -U0` against the base; an untracked spec, all its l
|
|
|
541
610
|
sub-second `be < 0.x` bound ([Waiting and time](#waiting-and-time), rules 3 and 5). Nothing printed means nothing
|
|
542
611
|
matched.
|
|
543
612
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
613
|
+
## When the full suite runs
|
|
614
|
+
|
|
615
|
+
`script/spec-map record [-n N]` is the full suite (`spec` and the bundles' own specs, through `bundle exec
|
|
616
|
+
parallel_rspec`) that also writes the map; on the Studio it takes as long as a plain run. A red run still writes the
|
|
617
|
+
map, stamped with its failures; an interrupted run, or one that lost a runner, writes nothing. A second recording of
|
|
618
|
+
the same commit, both clean and green, fills `volatile`. Builders run `script/affected-specs --run`; the full run is
|
|
619
|
+
the coordinator's call:
|
|
620
|
+
- an ff merge of a branch whose `--run` was green on that tree: nothing more;
|
|
621
|
+
- after a rebase onto a moved main, or several merges: `script/affected-specs OLD_MAIN..HEAD --run` on the result
|
|
622
|
+
(the specs that execute either side's changes);
|
|
623
|
+
- a map far behind, a summary dominated by whole files of hub classes, a volatile method, a change everything
|
|
624
|
+
depends on (`Gemfile`, `Gemfile.lock`, the gemspec, `spec/spec_helper.rb`, `.rspec`, `.rspec_parallel`: a hint
|
|
625
|
+
says so), a release: `script/spec-map record`;
|
|
626
|
+
- a failure a full run or CI finds that the picks missed: `script/affected-specs RANGE --audit
|
|
627
|
+
tmp/parallel_failures.log` (or a pasted CI log), then the fix by kind: a text reader gets a rule, a recorder gap a
|
|
628
|
+
recorder fix, a stale map a recording.
|
|
629
|
+
|
|
630
|
+
CI on main is the last border; it never records.
|
|
547
631
|
|
|
548
632
|
## Worktrees
|
|
549
633
|
|
|
@@ -26,8 +26,9 @@ module Samagotchi
|
|
|
26
26
|
# The same object when it has none.
|
|
27
27
|
# An empty-answer note's marker (TurnNote::EMPTY_ANSWER) and the
|
|
28
28
|
# answer's refs (AnswerRefs::KEY, display_refs) are display only too:
|
|
29
|
-
# they go the same way, and so does a block fix's stamp (BlockFix::STAMP)
|
|
30
|
-
|
|
29
|
+
# they go the same way, and so does a block fix's stamp (BlockFix::STAMP)
|
|
30
|
+
# and a failed-turn note's marker (TurnNote::FAILED_KEY, KEPT_KEY).
|
|
31
|
+
DISPLAY_ONLY = [KEY.to_s, "empty_answer", "display_refs", BlockFix::STAMP.to_s, "failed", "kept"].freeze
|
|
31
32
|
|
|
32
33
|
def self.strip(message)
|
|
33
34
|
return message unless message.is_a?(Hash) && DISPLAY_ONLY.any? { |key| message.key?(key.to_sym) || message.key?(key) }
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "context_note"
|
|
4
4
|
require_relative "output_formatter"
|
|
5
|
-
require_relative "
|
|
5
|
+
require_relative "speaker"
|
|
6
6
|
require_relative "turn_note"
|
|
7
7
|
|
|
8
8
|
module Samagotchi
|
|
@@ -31,10 +31,10 @@ module Samagotchi
|
|
|
31
31
|
# prompt up to the next prompt (merged input and steers stay in it), or
|
|
32
32
|
# nil when no prompt carries it.
|
|
33
33
|
def turn_slice(list, turn_id)
|
|
34
|
-
start = list.rindex { |m|
|
|
34
|
+
start = list.rindex { |m| Speaker.turn_prompt?(m) && (m[:turn_id] || m["turn_id"]).to_s == turn_id }
|
|
35
35
|
return nil unless start
|
|
36
36
|
|
|
37
|
-
stop = list.each_index.find { |i| i > start &&
|
|
37
|
+
stop = list.each_index.find { |i| i > start && Speaker.turn_prompt?(list[i]) } || list.size
|
|
38
38
|
list[start...stop]
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -43,7 +43,7 @@ module Samagotchi
|
|
|
43
43
|
# wire-format markup is stripped (a tool-call-only step has none).
|
|
44
44
|
def answer?(message)
|
|
45
45
|
return false unless message.is_a?(Hash)
|
|
46
|
-
return false if ContextNote.note?(message) ||
|
|
46
|
+
return false if ContextNote.note?(message) || Speaker.steer?(message) || TurnNote.empty_answer(message)
|
|
47
47
|
return false unless %w[assistant model].include?((message[:role] || message["role"]).to_s)
|
|
48
48
|
|
|
49
49
|
!OutputFormatter.strip_markup((message[:content] || message["content"]).to_s.scrub).empty?
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../
|
|
3
|
+
require_relative "../speaker"
|
|
4
4
|
|
|
5
5
|
module Samagotchi
|
|
6
6
|
class Bridge
|
|
7
7
|
# Where a CardStore's entries sit in a session's messages: the turns the
|
|
8
8
|
# page draws after each. The messages count, with the rule the page and
|
|
9
|
-
# the recap share (
|
|
9
|
+
# the recap share (Speaker.turn_opening?); the store's turn log only orders
|
|
10
10
|
# the ids. So a turn with no opening (a reminder, a Continue, a failed or
|
|
11
11
|
# rolled-back one, a prompt stopped before the model) counts nothing, and
|
|
12
12
|
# an opening with no turn id (/continue no's reason) counts as it does on
|
|
@@ -14,7 +14,7 @@ module Samagotchi
|
|
|
14
14
|
# an entry says how many it came after (+past_idless+, #idless_after), and
|
|
15
15
|
# which one that is when it has an id (+after_opening+, #after_opening).
|
|
16
16
|
#
|
|
17
|
-
# The same place as a stamp (#opening_of,
|
|
17
|
+
# The same place as a stamp (#opening_of, Speaker.opening_stamp): the id of
|
|
18
18
|
# the opening the entry comes after (a prompt's turn_id, a line's
|
|
19
19
|
# opening_id), which the page finds by its bubble, not by counting.
|
|
20
20
|
# Pure: no Engine, no file.
|
|
@@ -23,7 +23,7 @@ module Samagotchi
|
|
|
23
23
|
# @param messages [Array<Hash>] the messages the page draws
|
|
24
24
|
def initialize(turn_log, messages)
|
|
25
25
|
positions = turn_log.each_with_index.to_h
|
|
26
|
-
openings = Array(messages).select { |message|
|
|
26
|
+
openings = Array(messages).select { |message| Speaker.turn_opening?(message) }
|
|
27
27
|
@ids = openings.map { |message| message[:turn_id] || message["turn_id"] }
|
|
28
28
|
@stamps = openings.map { |message| stamp_of(message) }
|
|
29
29
|
@openings = @ids.size
|
|
@@ -115,7 +115,7 @@ module Samagotchi
|
|
|
115
115
|
position >= 0 ? @last_at_or_before[position] : nil
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
def stamp_of(message) =
|
|
118
|
+
def stamp_of(message) = Speaker.opening_stamp(message)
|
|
119
119
|
|
|
120
120
|
def idless_run(opening)
|
|
121
121
|
@ids.drop(opening + 1).take_while(&:nil?).size
|
|
@@ -90,7 +90,7 @@ module Samagotchi
|
|
|
90
90
|
# The turn in progress's participant author ("p:<id>"), nil for the
|
|
91
91
|
# owner's or none.
|
|
92
92
|
def participant_author
|
|
93
|
-
@mutex.synchronize { @turn &&
|
|
93
|
+
@mutex.synchronize { @turn && Speaker.sender_author(@turn[:author] || TurnOrigin.from(@turn[:origin])&.author) }
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
# The turn in progress as conversation messages, for a plugin's
|
|
@@ -233,8 +233,8 @@ module Samagotchi
|
|
|
233
233
|
if (started = events.first)
|
|
234
234
|
started[:at] = current_turn[:at] if current_turn[:at].is_a?(String)
|
|
235
235
|
started[:cut_after] = current_turn[:cut_after] unless current_turn[:cut_after].nil?
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
Speaker::AUTHOR_KEYS.each { |key| started.delete(key) }
|
|
237
|
+
Speaker::AUTHOR_KEYS.each { |key| started[key] = current_turn[key] if current_turn[key] } if current_turn[:author]
|
|
238
238
|
end
|
|
239
239
|
Array(queued).each do |entry|
|
|
240
240
|
enqueued = { type: :turn_enqueued, enqueued_id: entry[:enqueued_id], client_id: entry[:client_id], prompt: entry[:prompt] }
|
|
@@ -371,7 +371,7 @@ module Samagotchi
|
|
|
371
371
|
@working_set = nil
|
|
372
372
|
@turn[:images] = event[:images] if event[:images]
|
|
373
373
|
@turn[:cut_after] = event[:cut_after] if event[:cut_after]
|
|
374
|
-
|
|
374
|
+
Speaker::AUTHOR_KEYS.each { |key| @turn[key] = event[key] if event[key] }
|
|
375
375
|
when :input_merged
|
|
376
376
|
@merged_origins = Array(event[:origins])
|
|
377
377
|
dequeue(@merged_origins)
|
|
@@ -454,7 +454,7 @@ module Samagotchi
|
|
|
454
454
|
# for the user lines' own merge.
|
|
455
455
|
unless event[:content].nil?
|
|
456
456
|
input = { kind: "input", iteration: event[:iteration], text: event[:content].to_s.dup, origins: @merged_origins }
|
|
457
|
-
|
|
457
|
+
Speaker::AUTHOR_KEYS.each { |key| input[key] = event[key] if event[key] }
|
|
458
458
|
parts << input
|
|
459
459
|
@merged_origins = []
|
|
460
460
|
end
|
|
@@ -306,7 +306,7 @@ module Samagotchi
|
|
|
306
306
|
images = prompt && fetch(prompt, :images)
|
|
307
307
|
event[:images] = images if images.is_a?(Array) && !images.empty?
|
|
308
308
|
source = prompt || (@opening if user?(@opening))
|
|
309
|
-
|
|
309
|
+
Speaker::AUTHOR_KEYS.each { |key| event[key] = fetch(source, key) if source && fetch(source, key) }
|
|
310
310
|
event
|
|
311
311
|
end
|
|
312
312
|
|
|
@@ -356,7 +356,7 @@ module Samagotchi
|
|
|
356
356
|
# The prompt the turn opened with: a user message, not a wake's
|
|
357
357
|
# report (an input: the turn's first merged line) or note.
|
|
358
358
|
def prompt_message
|
|
359
|
-
return nil unless @opening && user?(@opening) && !
|
|
359
|
+
return nil unless @opening && user?(@opening) && !Speaker.input?(@opening)
|
|
360
360
|
|
|
361
361
|
@opening
|
|
362
362
|
end
|
|
@@ -367,13 +367,13 @@ module Samagotchi
|
|
|
367
367
|
role = fetch(message, :role).to_s
|
|
368
368
|
if role == "system"
|
|
369
369
|
system_message(message)
|
|
370
|
-
elsif
|
|
370
|
+
elsif Speaker.steer?(message)
|
|
371
371
|
@events << { type: :pending_input_merged, iteration: step_of(message), count: 0, content: nil,
|
|
372
372
|
steers: [{ source: fetch(message, :source).to_s, text: fetch(message, :content).to_s }] }
|
|
373
|
-
elsif
|
|
373
|
+
elsif Speaker.input?(message)
|
|
374
374
|
input = { type: :pending_input_merged, iteration: step_of(message), count: 1, content: fetch(message, :content).to_s,
|
|
375
375
|
steers: [] }
|
|
376
|
-
|
|
376
|
+
Speaker::AUTHOR_KEYS.each { |key| input[key] = fetch(message, key) if fetch(message, key) }
|
|
377
377
|
@events << input
|
|
378
378
|
elsif %w[model assistant].include?(role)
|
|
379
379
|
model_step(message, empties)
|
|
@@ -7,7 +7,7 @@ require_relative "../log"
|
|
|
7
7
|
require_relative "../message_time"
|
|
8
8
|
require_relative "../context_note"
|
|
9
9
|
require_relative "../degrade"
|
|
10
|
-
require_relative "../
|
|
10
|
+
require_relative "../speaker"
|
|
11
11
|
|
|
12
12
|
module Samagotchi
|
|
13
13
|
class Bridge
|
|
@@ -52,7 +52,7 @@ module Samagotchi
|
|
|
52
52
|
END_KEYS = %i[type turn_id duration_ms revises verify cancellation_reason cancelled_by summary message error_class
|
|
53
53
|
kept_steps].freeze
|
|
54
54
|
# What a line keeps of the accumulator's turn.
|
|
55
|
-
DRAWING_KEYS = (%i[prompt turn_id origin continue at images parts] +
|
|
55
|
+
DRAWING_KEYS = (%i[prompt turn_id origin continue at images parts] + Speaker::AUTHOR_KEYS).uniq.freeze
|
|
56
56
|
KINDS = { "turn_completed" => "completed", "turn_canceled" => "canceled", "turn_failed" => "failed" }.freeze
|
|
57
57
|
|
|
58
58
|
# One line of the file (string-keyed drawing and end, as JSON has them).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "../context_note"
|
|
4
|
-
require_relative "../
|
|
4
|
+
require_relative "../speaker"
|
|
5
5
|
require_relative "../turn_note"
|
|
6
6
|
require_relative "turn_drawings"
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ module Samagotchi
|
|
|
14
14
|
#
|
|
15
15
|
# A turn starts at the reminder lines just before its opening (they
|
|
16
16
|
# went into it: `kept_from` sits before the due reminders), else at its
|
|
17
|
-
# opening (
|
|
17
|
+
# opening (Speaker.turn_opening?: a prompt, a wake turn's report), else at
|
|
18
18
|
# the first message after a wake turn's note (the note was there before
|
|
19
19
|
# the turn began: outside, the turn's opening by its id), else at a
|
|
20
20
|
# message no opening came before (a reminder's or a Continue's turn: no
|
|
@@ -94,11 +94,11 @@ module Samagotchi
|
|
|
94
94
|
list.each_with_index do |message, i|
|
|
95
95
|
next unless message.is_a?(Hash)
|
|
96
96
|
|
|
97
|
-
if
|
|
97
|
+
if Speaker.shell_line?(message)
|
|
98
98
|
close.call
|
|
99
99
|
pending = nil
|
|
100
100
|
elsif fetch(message, :role).to_s == "system"
|
|
101
|
-
if
|
|
101
|
+
if Speaker.turn_prompt?(message)
|
|
102
102
|
# A wake's note: the turn it opens starts after it.
|
|
103
103
|
close.call
|
|
104
104
|
pending = nil
|
|
@@ -121,9 +121,9 @@ module Samagotchi
|
|
|
121
121
|
pending = nil
|
|
122
122
|
end
|
|
123
123
|
# A context note, the system head: nobody's own.
|
|
124
|
-
elsif
|
|
124
|
+
elsif Speaker.turn_opening?(message)
|
|
125
125
|
id = fetch(message, :turn_id)
|
|
126
|
-
if turn && id && turn[:turn_id] == id &&
|
|
126
|
+
if turn && id && turn[:turn_id] == id && Speaker.input?(message)
|
|
127
127
|
# A second opening line of the turn (a wake turn's report after its note).
|
|
128
128
|
turn[:from] ||= pending || i
|
|
129
129
|
turn[:last] = i
|
|
@@ -145,9 +145,16 @@ module Samagotchi
|
|
|
145
145
|
private_class_method :cut
|
|
146
146
|
|
|
147
147
|
# The note of a failure that kept nothing (TurnNote.failed, not
|
|
148
|
-
# .failed_after): its prompt went back or its turn left no step.
|
|
148
|
+
# .failed_after): its prompt went back or its turn left no step. Its
|
|
149
|
+
# marker (TurnNote.failure: no kept steps), the words for an older
|
|
150
|
+
# chi's note.
|
|
149
151
|
def rolled_back?(message)
|
|
150
|
-
TurnNote.note?(message)
|
|
152
|
+
return false unless TurnNote.note?(message)
|
|
153
|
+
|
|
154
|
+
marked = TurnNote.failure(message)
|
|
155
|
+
return marked[:kept].nil? if marked
|
|
156
|
+
|
|
157
|
+
fetch(message, :content).to_s.start_with?(TurnNote::OPEN + TurnNote::FAILED)
|
|
151
158
|
end
|
|
152
159
|
private_class_method :rolled_back?
|
|
153
160
|
|