samagotchi 0.125.0 → 0.127.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 +50 -1
- data/docs/architecture.md +1 -0
- data/docs/cli.md +1 -1
- data/docs/configuration.md +2 -2
- data/docs/guardrails.md +22 -0
- data/docs/internals/participants.md +82 -8
- data/docs/internals/web-push.md +10 -6
- data/docs/sessions.md +6 -1
- data/lib/samagotchi/bridge.rb +4 -3
- data/lib/samagotchi/bridge_client.rb +8 -1
- data/lib/samagotchi/bundles/known-names/hooks/known_names.rb +25 -4
- data/lib/samagotchi/bundles/known-names/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/child_reports.rb +3 -0
- data/lib/samagotchi/children_status.rb +6 -1
- data/lib/samagotchi/engine.rb +43 -7
- data/lib/samagotchi/guardrail_wiring.rb +10 -1
- data/lib/samagotchi/llm/chat_loop.rb +1 -0
- data/lib/samagotchi/session.rb +40 -3
- data/lib/samagotchi/session_inbox.rb +14 -8
- data/lib/samagotchi/session_manager.rb +11 -4
- data/lib/samagotchi/session_participants.rb +24 -3
- data/lib/samagotchi/verdict.rb +20 -0
- data/lib/samagotchi/verify_anchor.rb +28 -0
- data/lib/samagotchi/verify_fresh.rb +275 -0
- data/lib/samagotchi/verify_fresh_origin.rb +71 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +15 -0
- data/lib/samagotchi/web/participant_access.rb +31 -5
- data/lib/samagotchi/web/participant_review.rb +7 -1
- data/lib/samagotchi/web/participant_view.rb +46 -5
- data/lib/samagotchi/web/project_list.rb +52 -0
- data/lib/samagotchi/web/public/annotate_bar.js +9 -1
- data/lib/samagotchi/web/public/app.js +77 -4
- data/lib/samagotchi/web/public/composer.css +12 -1
- data/lib/samagotchi/web/public/data.js +2 -1
- data/lib/samagotchi/web/public/index.html +36 -16
- data/lib/samagotchi/web/public/notify.js +15 -2
- data/lib/samagotchi/web/public/participant.html +33 -32
- data/lib/samagotchi/web/public/participant.js +70 -7
- data/lib/samagotchi/web/public/project_picker.js +115 -0
- data/lib/samagotchi/web/public/restore.js +7 -4
- data/lib/samagotchi/web/public/scope.js +8 -10
- data/lib/samagotchi/web/public/send_turn.js +8 -1
- data/lib/samagotchi/web/public/session_state.js +5 -0
- data/lib/samagotchi/web/public/stage_view.js +1 -1
- data/lib/samagotchi/web/public/stream_handlers.js +6 -1
- data/lib/samagotchi/web/public/verdict_card.js +65 -0
- data/lib/samagotchi/web/public/verdict_fresh.js +120 -0
- data/lib/samagotchi/web/public/verify_card.css +17 -0
- data/lib/samagotchi/web/push/attention.rb +48 -9
- data/lib/samagotchi/web/push/notifier.rb +4 -3
- data/lib/samagotchi/web/session_control.rb +2 -0
- data/lib/samagotchi/web/session_summary.rb +25 -1
- data/lib/samagotchi/web/verify_fresh_routes.rb +110 -0
- data/lib/samagotchi/worker.rb +75 -13
- data/lib/samagotchi/worker_inbound.rb +4 -4
- metadata +11 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d35df5e2cd9639c1da812c221e1c256567df7e2f9986df32c6cbc49cc9d6d431
|
|
4
|
+
data.tar.gz: 7e98badd5615015b9841a9885404c130ff46fddefd05dc70bafd051ae37f92ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f5eaf2d9dca71dd6951989506b64c67ce905396c3af824521aa6fcc8e974d7a4f7ca6843f307f9915b5b5986b3ab87e2707ca76a771e985fa095a99acf9cedf
|
|
7
|
+
data.tar.gz: 65b7f35bcd7372d6c51a438c3808937266b035e8e67ac6c48511734d00f78ac12b9de3536359c67ad8797a4dc542e16a04649ece8d0dc7e8e729e6b7f60dd0a2
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,53 @@ and commands may change between minor versions. How releases are made:
|
|
|
7
7
|
[docs/releasing.md](docs/releasing.md).
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.127.0] - 2026-10-28
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- chi web's header project chip opens a picker to switch projects without starting chi web in each one.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- A participant's comment box sits in the same glass card as the owner's composer: the key hint above the text field,
|
|
19
|
+
their usage as the card's footer and the grip on its top edge; folded, the card keeps the usage line.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- A new invite link opens in a browser that still holds an ended link's cookie (behind an auth proxy it showed
|
|
24
|
+
'revoked').
|
|
25
|
+
- A Verify verdict push names an owner's verdict "You" when its author is empty or the owner's mark, not "A
|
|
26
|
+
participant", on the phone and in the tab alike.
|
|
27
|
+
- A Verify fresh check's system prompt carries no participants line when the owner asked for it, and its
|
|
28
|
+
requester's own (review or pair) when a participant did, instead of the parent session's.
|
|
29
|
+
- A Verify turn that fails fast and comes back into chi web's composer keeps its claim, so sending it again still
|
|
30
|
+
puts a verdict card on the claim.
|
|
31
|
+
|
|
32
|
+
Update with `chi update`, then restart `chi web` and the session workers (`chi sessions restart`).
|
|
33
|
+
|
|
34
|
+
## [0.126.0] - 2026-10-27
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- chi web places each completed Verify verdict on its source claim, links to the checking turn, and sends a phone
|
|
39
|
+
notification with the verdict and a short reason (including for short turns).
|
|
40
|
+
- **Verify fresh** on an unclear verdict's card (owner or participant): a new agent checks the claim in the session's
|
|
41
|
+
folder with none of its context; its verdict lands on the same card. A participant's runs under their own access
|
|
42
|
+
and spend cap.
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- A pair participant's page header reads "<name> · pairing" instead of "<name>'s review", and its tools overview's
|
|
47
|
+
disclosure triangle matches the text's size.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- The known-names hook lets through a protected name's CamelCase form (`CoffeeAssistant` or `coffeeAssistant` for a
|
|
52
|
+
repo named `coffee_assistant`) instead of rejecting it as a misspelling; `coffee-assistant` and `coffeeassistant`
|
|
53
|
+
are still caught.
|
|
54
|
+
- The known-names hook ignores separators at a word's start or end, so `grep coffee_assistant-` or
|
|
55
|
+
`.coffee_assistant` is no longer rejected as a misspelling; `mode: correct` keeps those separators.
|
|
56
|
+
|
|
10
57
|
## [0.125.0] - 2026-10-27
|
|
11
58
|
|
|
12
59
|
### Added
|
|
@@ -4740,7 +4787,9 @@ and long-lived sessions.
|
|
|
4740
4787
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
4741
4788
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
4742
4789
|
|
|
4743
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
4790
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.127.0...HEAD
|
|
4791
|
+
[0.127.0]: https://github.com/dm1try/samagotchi/compare/v0.126.0...v0.127.0
|
|
4792
|
+
[0.126.0]: https://github.com/dm1try/samagotchi/compare/v0.125.0...v0.126.0
|
|
4744
4793
|
[0.125.0]: https://github.com/dm1try/samagotchi/compare/v0.124.0...v0.125.0
|
|
4745
4794
|
[0.124.0]: https://github.com/dm1try/samagotchi/compare/v0.123.0...v0.124.0
|
|
4746
4795
|
[0.123.0]: https://github.com/dm1try/samagotchi/compare/v0.122.0...v0.123.0
|
data/docs/architecture.md
CHANGED
|
@@ -615,6 +615,7 @@ model: [internals/remote-sessions.md](internals/remote-sessions.md).
|
|
|
615
615
|
|---|---|---|---|---|
|
|
616
616
|
| `GET /api/sessions/resolve?id=` | owner | an id or a unique prefix | 200 `{id}` | 404 `not_found`; 400 `ambiguous_id` with `ids` |
|
|
617
617
|
| `GET /api/sessions/summaries` | owner | `dir` (a folder: its project; none: every project), `cwd`, `live=1`, `archived=1`, `tests=0`, `sort`, `order`, `limit` | 200: the rows `chi sessions list` prints (`SessionManager.session_summaries`: `status`, `live`, `busy`, `owner`, `recap`, `ctx_pct`, `waiting`, `waiting_id`, `title`, `preview`, …) | 400 `invalid_dir`, `invalid_cwd` |
|
|
618
|
+
| `GET /api/projects?dir=` | owner | optional page-scope folder | 200: project rows with counts, roots, default/current marks; no `dir`: no current project | 400 `invalid_dir`; 503 `no_hub` |
|
|
618
619
|
| `POST /api/sessions` (more fields) | owner | `toolkit`, `tools`, `no_tools`, `parent_answers`; `client_id` (`cli:send`/`cli:answer`: the first line is checked as chi send checks it); `check_vision: true` (images follow) | 201 adds `model_warning`, `parent_answers_warning` (a level looser than config.yml's, capped) and `first_turn_id` (the id the prompt it starts with gets for its turn; null for an `idle` create) | 400 `invalid_toolkit`, `invalid_parent_answers`, `invalid_continues` (beside `continues`); 403 `parent_answers_refused`, `parent_continue_refused`; 422 `no_vision` |
|
|
619
620
|
| `POST /api/sessions/:id/turn` (more fields) | owner | `client_id` as above; `check_vision: true` with `images` | as before | 403 `parent_answers_refused`, `parent_continue_refused`; 422 `no_vision` |
|
|
620
621
|
| `POST /api/sessions/:id/wait/prepare` | owner | `question_id` (absent: the pending one; `null`: none), `turn`, `created`, `busy` (+ `queue`) | 200 `{session_id, cursor, baseline: {messages, question_id, last_turn}, own_turn, known_turn, running, live, settled, last_turn_id}` (`WaitStart`) | 409 `busy`, `waiting` (`SendCommand::Busy`'s words, and its fields: `question`, `parent_strategy`) |
|
data/docs/cli.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
- A session id can be shortened to any unique prefix (like git): `chi --attach 2ea8`. `--resume`, `--attach`, `sessions stop`, `sessions archive` and `sessions delete` take one; an ambiguous prefix lists the sessions it matches.
|
|
14
14
|
- `chi web [--port 4567] [--open] [--scope=all] [--start-dir DIR]` — start the Web UI (single localhost port session control plane) on this git project's sessions (`--scope=all`, or a folder in no repo: `/?scope=all`, every session); if a chi web already runs on the port, print (with `--open`, open) its page for this folder and exit. Something else on the port (an older chi web too) exits 1 with "port N is in use"
|
|
15
15
|
- `chi web --web-host lan` — the Web UI on your home network too, for your phone: a link with an access token and its QR code (see [chi web on your phone](#chi-web-on-your-phone)); `chi web --new-token` replaces the token
|
|
16
|
-
- `chi web --start-dir DIR` (config `web.start_dir`) — the folder chi web starts in, in place of the one you run it in (`~` and a relative path work; chi web never changes its own folder): its page opens on that folder's project (the printed link, a bare `/`, the LAN link and its QR code, the Home Screen app), and a new session from the all view starts there;
|
|
16
|
+
- `chi web --start-dir DIR` (config `web.start_dir`) — the folder chi web starts in, in place of the one you run it in (`~` and a relative path work; chi web never changes its own folder): its page opens on that folder's project (the printed link, a bare `/`, the LAN link and its QR code, the Home Screen app), and a new session from the all view starts there; the header's project chip switches projects. One that isn't a folder exits 1; `--start-dir` without `web` exits 2. A chi web already running in another folder keeps it (the second one says so: restart it to change it)
|
|
17
17
|
- `chi web --tunnel tailscale` — the Web UI over https on your tailnet, for your phone anywhere: Tailscale Serve (never Funnel) on this machine's `<machine>.<tailnet>.ts.net` name for this run, the owner your Tailscale login, turned off on exit (see [Tailscale Serve](configuration.md#tailscale-serve-your-tailnet)); `--tunnel` without `web` exits 2
|
|
18
18
|
- `chi web push ls [--format json]`, `chi web push rm ID`, `chi web push test [ID]` — the phones chi web pushes to (see [Phone notifications](configuration.md#phone-notifications-web-push)): list them (short id, label, origin, added, last delivery, done turns, last error; `stale` for one made on another public URL than chi web's now: never sent to), remove one, or send a test notification to ID or to every device not stale. chi web need not run; nothing printed holds a device's push address or keys. A usage error exits 2; a store others can read, a corrupt one, an unknown device or a failed test push exit 1. This machine only: `chi --remote X web push` exits 2
|
|
19
19
|
- `chi web --web-markdown` — opt in to sanitized Markdown rendering for completed assistant messages, the stage's asking text and a resolved question card's reply
|
data/docs/configuration.md
CHANGED
|
@@ -1893,7 +1893,7 @@ What it needs:
|
|
|
1893
1893
|
|
|
1894
1894
|
Turning it on, on the phone: open the `Proxied:` link in Safari → Share → **Add to Home Screen** → open the **Chi**
|
|
1895
1895
|
app → tap the **bell** at the top → turn on **This device** in the sheet → Allow. A test notification arrives at once.
|
|
1896
|
-
The app opens on the project chi web starts in (`web.start_dir`; the header's
|
|
1896
|
+
The app opens on the project chi web starts in (`web.start_dir`; the header's project picker switches projects), but its
|
|
1897
1897
|
notifications are every project's: opening it closes the ones whose question or card is no longer open and sets its
|
|
1898
1898
|
badge for every project, whichever project the page shows.
|
|
1899
1899
|
In a browser tab the bell stays the tab's own notifications (while the tab is in the background), as before.
|
|
@@ -2077,7 +2077,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
|
|
|
2077
2077
|
| `web.working_set` | `true` | yes | The stage view's working set: the files, memories and URLs a turn brought into the model's context, in a rail in the stage, a footprint line under each finished turn and a `set N` chip in place of the mem chip; `false` brings the mem chip back. `?working_set=1` or `?working_set=0` on the page URL overrides it for that page load; the turn view ignores it. See [CLI: the working set](cli.md#the-working-set). |
|
|
2078
2078
|
| `web.annotate_presets` | `Agreed\|Could you please elaborate?` | yes | Quick replies next to Annotate in `chi web`, `\|`-separated (a YAML list works too); `""` in the file or on the CLI leaves only Annotate (an empty env value means the default). See [CLI](cli.md#web-annotate-presets). |
|
|
2079
2079
|
| `web.editor` | `vscode` | yes | What a file ref in `chi web` (a file tool row's title, a diff line) opens, for a viewer on this machine: a preset (`vscode`, `vscode-insiders`, `cursor`, `zed`) or a URL template with `{path}` and an optional `{line}`; `none` turns refs off. See [Opening files from chi web](#opening-files-from-chi-web). |
|
|
2080
|
-
| `web.start_dir` | the folder `chi web` runs in | | The folder `chi web` starts in (`chi web --start-dir DIR` for one run): its page (the printed link, a bare `/`, the LAN link and QR code, the Home Screen app) opens on that folder's project, outside a repo on every session, and a new session from the all view starts there;
|
|
2080
|
+
| `web.start_dir` | the folder `chi web` runs in | | The folder `chi web` starts in (`chi web --start-dir DIR` for one run): its page (the printed link, a bare `/`, the LAN link and QR code, the Home Screen app) opens on that folder's project, outside a repo on every session, and a new session from the all view starts there; the header's project picker switches projects. `~` and a relative path (resolved from your home folder) work; one that isn't a folder stops `chi web` from starting. `chi web` never changes its own folder. See [CLI](cli.md). |
|
|
2081
2081
|
| `web.participants.expires` | `7d` | | How long a participant's link lasts unless `chi share --expires` says otherwise: `Nh` or `Nd`, 1h to 30d. See [participants](internals/participants.md). |
|
|
2082
2082
|
| `web.participants.cap` | `2.0` | | What a participant's turns, and the side calls they cause, may cost you in dollars unless `chi share --cap` says otherwise ($0 to $1000); at the cap their next comment is refused (429 `cap_reached`) and you get a notice. `chi share cap ID P DOLLARS` changes one grant's. |
|
|
2083
2083
|
| `web.participants.queue` | `3` | | How many of a participant's turns may wait behind their running one (0 to 20); one more is refused (429 `too_many_turns`). |
|
data/docs/guardrails.md
CHANGED
|
@@ -452,6 +452,28 @@ can send out in a URL), plugin and MCP tools, `memory_read` and `context_read`,
|
|
|
452
452
|
does that the command checks don't read (a script file's body, an interpreter's
|
|
453
453
|
`-e` code). Share a working session only with people you would let type in it.
|
|
454
454
|
|
|
455
|
+
## A Verify fresh child's boundary
|
|
456
|
+
|
|
457
|
+
A [Verify fresh](internals/participants.md#what-a-participant-sees) child (a
|
|
458
|
+
delegate child chi web starts for an unclear verdict) runs a participant's
|
|
459
|
+
check under **the boundary that participant has in the parent**. A verdict a
|
|
460
|
+
participant recorded is always checked again as them, even when the owner
|
|
461
|
+
clicks (the claim is their text; their link must still be live), so it never
|
|
462
|
+
runs with the owner's rules or System 1's auto-allows. The mode is decided once,
|
|
463
|
+
at the start, from their grant's mode there (`ParticipantMode.live_for`) and
|
|
464
|
+
saved on the child (`verify_fresh.mode`): `review` keeps every turn of it
|
|
465
|
+
inside `ReviewBoundary` (read only), `pair` inside `PairBoundary`.
|
|
466
|
+
`GuardrailWiring#turn_mode` reads the saved mode and never looks it up again,
|
|
467
|
+
and every turn of the child carries the participant as its author, whoever
|
|
468
|
+
started it, so the boundary can't fall away for a turn the owner typed into it
|
|
469
|
+
or for an author lookup that finds nobody (the child has no
|
|
470
|
+
`participants.json`; revoke and cap read the parent's). It fails closed: a
|
|
471
|
+
`verify_fresh` field that doesn't read is a participant nobody has, under
|
|
472
|
+
review, whose turns are refused. `ChildBoundary` applies on top, as for every
|
|
473
|
+
delegate child, and its asks go to the owner (once only, as a participant's
|
|
474
|
+
do; System 1 skips them). The owner's own fresh child is an ordinary delegate
|
|
475
|
+
child: the owner's turns, `ChildBoundary`.
|
|
476
|
+
|
|
455
477
|
## Rules in config.yml
|
|
456
478
|
|
|
457
479
|
```yaml
|
|
@@ -35,7 +35,8 @@ participant** and **one role**, until it expires or is revoked.
|
|
|
35
35
|
retention, or archived or deleted by a process that didn't revoke, is caught by the gate: a live grant whose session
|
|
36
36
|
file is gone or archived is revoked on sight (`revoked_by: gone | archive`). Unarchiving doesn't restore a grant.
|
|
37
37
|
An ended grant stays in the store for 30 days, so its token answers `token_revoked` / `token_expired` rather than a
|
|
38
|
-
bare 401; then it goes.
|
|
38
|
+
bare 401; then it goes. The ended and bound pages also trade a link's `#code=`, so a new invite opens even in a
|
|
39
|
+
browser still holding an ended grant's cookie.
|
|
39
40
|
- **Store.** `$XDG_STATE_HOME/samagotchi/web-grants/grants.json`, next to `web-token`: the file 0600, in its own 0700
|
|
40
41
|
folder, written whole (`AtomicFile`) under a lock file (`grants.lock`) since chi web and a local `chi share` both
|
|
41
42
|
write it. Its `version` is 1, and 2 once a grant is bound (never lowered); a store above `Grants::MAX_VERSION` is a
|
|
@@ -315,7 +316,8 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
315
316
|
- **Events** (`.event`, the stream). `EVENTS` names the types a participant gets, each rebuilt by its own method:
|
|
316
317
|
`turn_started` (turn id, its wall time `at`, the author and name, `mine` for their own, the prompt only when a person sent the turn:
|
|
317
318
|
`ClientId.human?`, else `automatic`; `continue`), the turn's end (`turn_completed`, `turn_canceled`, `turn_failed`:
|
|
318
|
-
type and turn id
|
|
319
|
+
type and turn id; `turn_completed` may also carry an allowlisted verdict card), `generation_chunk` (its visible
|
|
320
|
+
`text` only; a thinking-only chunk is dropped),
|
|
319
321
|
`generation_retrying` (`restarted`), `tool_call_started` (the tool's name, and for a file tool the path relative to
|
|
320
322
|
the session's folder when it is inside it; never when that folder is home or `/`), `tool_call_completed` (its status word), and bare markers (the type
|
|
321
323
|
alone) for the queue (`turn_enqueued`, `turn_dequeued`, `input_merged`), the owner's question, approval or Continue
|
|
@@ -357,10 +359,11 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
357
359
|
reads. `queued` counts their own queued turns on the worker; `model` is the session's model as its host is sent it
|
|
358
360
|
(the alias applied, no host name), live else saved, redacted. Every source reads the grant's own author: another
|
|
359
361
|
participant's spend, the owner's and the session's totals never reach them (the red-team spec checks the body). The
|
|
360
|
-
owner's participant view has none. The page draws it as one line
|
|
362
|
+
owner's participant view has none. The page draws it as one line in the comment box card's footer
|
|
363
|
+
(`.composer-card-foot`, `usageItems`): "$0.42 of
|
|
361
364
|
$2.00 cap · 1/3 queued · link: 6 d left · model", each with a title in words; warn colours from 80% of the cap, a
|
|
362
|
-
full queue and a link's last day, "over" at the cap.
|
|
363
|
-
|
|
365
|
+
full queue and a link's last day, "over" at the cap. The key hint is the line above the text field (hidden on a
|
|
366
|
+
phone). The usage is cut at the end (the model first); folded, it stays as the card's footer under the grip. It is redrawn at each re-read (a
|
|
364
367
|
turn's end, a queued or taken-back comment), not while a turn streams.
|
|
365
368
|
- **A fork's note.** A review fork (`chi review --from`, `/coordinate review`) starts with a note holding the source's
|
|
366
369
|
recap and, from the coordinator, its handoff's body: a participant's review turn reads it like the rest of the
|
|
@@ -414,9 +417,77 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
414
417
|
cookie is one name: a second participant link redeemed there replaces the first), and **the owner opening a
|
|
415
418
|
participant's invite link** in their own browser swaps their owner cookie for that grant (the page asks first). A
|
|
416
419
|
continue archives the session and revokes its grants: re-share, and links to the old session stay on it.
|
|
420
|
+
- **Verify verdict cards** (`verdict_card.js`). The built-in Verify preset carries the selected source turn id and quote
|
|
421
|
+
with the submitted turn, without changing its prompt text. A Verify turn that fails fast and is rolled back hands
|
|
422
|
+
the claim back with its prompt (`prompt_restored`'s `verify`), so the owner's resend from the composer is a Verify
|
|
423
|
+
turn again. A completed Verify reply whose final non-empty line has
|
|
424
|
+
a valid `Verdict: confirmed|refuted|unclear — <reason>` appends a verdict to the session. Both pages place its card
|
|
425
|
+
after the source turn, name its author, show the reason and quote, and link to the checking turn; a live completion
|
|
426
|
+
adds the card without a reload. The participant view receives only the card fields through its allowlist, with the
|
|
427
|
+
quote and reason redacted by the view's normal rules, never the full reply.
|
|
428
|
+
- **Verify fresh** (`VerifyFresh`, `verdict_fresh.js`). An `unclear` card has a **Verify fresh** button (the owner's
|
|
429
|
+
page always; a participant's while `can_comment`, i.e. while their grant could run a turn now; never in the owner's
|
|
430
|
+
participant view). It is `POST /api/sessions/:id/verdicts/:check_turn_id/fresh` (`VerifyFreshRoutes`, `:owner`
|
|
431
|
+
and `:participant`), which starts a **fresh child**: a delegate child (`spawn_session`, `delegate: true`,
|
|
432
|
+
`parent_id`) in the session's own folder (no worktree; a folder outside git too), on its model, whose first and only
|
|
433
|
+
prompt is the claim, quoted, and "Verify this claim against the files here. You have none of the original session's
|
|
434
|
+
context. End with a line `Verdict: confirmed|refuted|unclear — <one-line reason>`." No parent history. Its first
|
|
435
|
+
turn is a Verify turn on the same anchor, so its verdict is parsed. Refused: a verdict the session doesn't have (404
|
|
436
|
+
`not_found`; a fresh verdict itself is never the target, its original is), one that isn't unclear (409
|
|
437
|
+
`not_unclear`), and, checked together under `verify_fresh.lock`: a fresh check of that verdict still running (409
|
|
438
|
+
`fresh_running`), a fresh child of the same requester still running (409 `fresh_busy`: one at a time per
|
|
439
|
+
participant, and one for the owner; each start passes the cap on saved spend, so parallel children would multiply
|
|
440
|
+
it), and the parent already running `session.max_children` children of any kind (409 `children_full`, so fresh
|
|
441
|
+
checks never crowd out the owner's own delegates). For a participant also what refuses their turn: their cap (429
|
|
442
|
+
`cap_reached`, counting their fresh children) and a live worker that predates participants' turns (409
|
|
443
|
+
`review_unavailable`). A start that involves a participant is audited in the parent's trail (`verify_fresh`:
|
|
444
|
+
`participant` whose child it is, `asked_by` the clicking participant's id or `owner`, `of`, `status`, the child and
|
|
445
|
+
mode, or the reason); the answer is `{of, running: true}`, the owner's with `child_id` too.
|
|
446
|
+
- **Whose child it is.** A verdict a participant's turn recorded (`by: p:<id>`) is checked again **as that
|
|
447
|
+
participant**, whoever clicks, the owner included: the claim is their text (the quote their Verify turn sent),
|
|
448
|
+
so it never runs with the owner's power (the owner's rules, System 1's auto-allows). Their grant must still be
|
|
449
|
+
live in this session, else 409 `author_link_ended` ("Sam's link has ended: …"), and their cap and the worker's
|
|
450
|
+
features are checked as for their turn (a participant who clicks passes their own checks first). An owner's
|
|
451
|
+
verdict (`by` none) is checked again as whoever clicks: an owner's child for the owner, the clicking
|
|
452
|
+
participant's own for a participant.
|
|
453
|
+
- **The child is its requester's.** Its session file carries `verify_fresh: {author, mode, of, anchor}`
|
|
454
|
+
(`VerifyFreshOrigin`), saved before its worker starts. `author` is the participant's (`p:<id>`), none for the
|
|
455
|
+
owner. `mode` is the participant's grant's mode in the parent at that moment (`ParticipantMode.live_for`:
|
|
456
|
+
`pair` only for a grant stamped to act in a working session whose worker runs pair turns, else `review`). Every
|
|
457
|
+
turn of a participant's child is theirs, whoever starts it (the owner typing into it, a continue, a reminder):
|
|
458
|
+
`VerifyFreshOrigin#origin_for` sets the author in `Engine#begin_turn` and in the worker, so their boundary
|
|
459
|
+
(`GuardrailWiring#turn_mode` reads the saved mode, never a lookup), their System 1 skip, their once-only asks to
|
|
460
|
+
the owner and the stamps on their messages follow. The child has no `participants.json`: its participant lookups
|
|
461
|
+
(`Session#participants_source_id`) read the parent's, so a revoke, an expiry or the parent's archive refuses the
|
|
462
|
+
child's next turn and stops a pair turn mid-turn, as in the parent; their audit lines go to the parent's
|
|
463
|
+
`participants.jsonl`. A field that doesn't read is `VerifyFreshOrigin::INVALID`: a participant author nobody
|
|
464
|
+
has, under review, so its turns are refused, never run as the owner's. Its approvals wait on the child for the
|
|
465
|
+
owner (D2); the owner's page links to it.
|
|
466
|
+
- **What follows from that.** The owner typing into a participant's child is that participant's turn: charged to
|
|
467
|
+
their cap and run under their boundary (open an ordinary session to act with the owner's own). A revoke (or an
|
|
468
|
+
expiry, or the parent's archive) stops a pair-mode child mid-turn, as a pair turn; a review-mode child finishes
|
|
469
|
+
the turn it is in and is refused at its next turn's start, as a review turn. A continue of the parent archives it
|
|
470
|
+
(and revokes its grants) and moves a running fresh child to the new link with the other open delegates: the
|
|
471
|
+
turn it is in still forwards its verdict to the archived link (the parent it started under), which shows it
|
|
472
|
+
there, and its next turn is refused (its requester's grant isn't on the new link). Nothing reaches the new link's
|
|
473
|
+
card: fails closed.
|
|
474
|
+
- **Spend.** The parent's `verify_fresh.jsonl` (one line per child: `child_id`, `of`, `author`, `at`) is the
|
|
475
|
+
rollup's index: a participant's cap check in chi web (`#participant_saved_spend`), their usage line, and the
|
|
476
|
+
worker's (`Worker#participant_spend`) add their fresh children's saved spend (`VerifyFresh.children_spend`); a
|
|
477
|
+
child's worker adds the parent's saved spend and its siblings'. A child's spend counts from its turns' ends, as
|
|
478
|
+
a turn's does.
|
|
479
|
+
- **The verdict lands on the card**, never in the parent's conversation: the child's worker writes each verdict
|
|
480
|
+
its turn recorded into the parent's `fresh_verdicts/<check turn>.json` (`fresh: true`, `of`, `child_id`) after its
|
|
481
|
+
save, and a fresh child never rings its parent (no delegate report, `ChildRing.ring`). The parent's worker takes
|
|
482
|
+
them into its `verdicts` between turns (`Worker#absorb_fresh_verdicts`), saves, deletes the files and announces
|
|
483
|
+
`:verdict_recorded`; chi web shows the ones still waiting (`VerifyFresh.verdicts_of`: the summary, the review
|
|
484
|
+
data). The card shows "Verifying fresh…" while the child runs (the summary's `verify_fresh` `{of, child_id}`,
|
|
485
|
+
the review data's `fresh_running`, ids only) and the fresh verdict as a `fresh: ✅ confirmed — …` line on the same
|
|
486
|
+
card. The participant view passes `fresh` and `of`, never the child's id (a participant can't open it). No push
|
|
487
|
+
for a fresh verdict yet (`Attention` pushes a verdict at a turn's end).
|
|
417
488
|
- **The comment box** is the owner's composer (`composer_mount.js`, styled by the shared `composer.css`), mounted by
|
|
418
489
|
`participant.js` with a subset on. It has: the height that grows with the text, the grip (drag to resize,
|
|
419
|
-
double-click resets, click or drag down folds it; folded, the grip is the handle on the
|
|
490
|
+
double-click resets, click or drag down folds it; folded, the grip is the handle on the card's top edge and typing on the
|
|
420
491
|
page opens it; Annotate opens it for the visit), the one-row layout of the owner's session composer (Send at its
|
|
421
492
|
bottom right; a phone keeps it one row), and ↑/↓ over the participant's own comments: the ones the server took from
|
|
422
493
|
this browser, in localStorage under `chi_review_history:<grant id>` (`review_history.js`; the grant id is the review
|
|
@@ -532,7 +603,8 @@ invited to has none: its files stay byte for byte as they were.
|
|
|
532
603
|
remembered and audited; or `what: command`, a participant's `/word` or
|
|
533
604
|
`!line` the Bridge or the worker refused), `turn` (chars, `status: accepted` with its enqueued id, or `refused` with
|
|
534
605
|
the reason: `not_permitted`, `too_many_turns`, `cap_reached`, `review_unavailable`, `worker_timeout`), `cap` (a new
|
|
535
|
-
cap)
|
|
606
|
+
cap), `verify_fresh` (`of`, `status`, the child and mode or the reason). A Verify fresh child's participants' lines
|
|
607
|
+
are its parent's. It goes with the session (retention, delete).
|
|
536
608
|
- **`participants.lock`** (0600, empty): the lock a participant's turn file is counted and written under when no
|
|
537
609
|
worker runs ([Turns](#turns)).
|
|
538
610
|
|
|
@@ -562,7 +634,9 @@ fixture loads and saves unchanged, `spec/turn_author_record_spec.rb`).
|
|
|
562
634
|
worker's Engine at each turn's start), the system prompt's volatile tail opens with "Participants: people other
|
|
563
635
|
than the owner review this session. …" (`SystemPrompt::PARTICIPANTS_LINE`), or in a working session with
|
|
564
636
|
`PAIR_PARTICIPANTS_LINE`, which names the pair header (and the review one, for turns stamped before). It comes
|
|
565
|
-
when the first joins and goes when the last leaves or expires.
|
|
637
|
+
when the first joins and goes when the last leaves or expires. A Verify fresh child reads its parent's
|
|
638
|
+
`participants.json` but has one participant at most: its requester, under their saved mode while their grant is
|
|
639
|
+
active; the owner's child has no line (`SessionParticipants#prompt_mode`).
|
|
566
640
|
- **Records.** `last_turn.author`, the analytics turn record's `author`, `turn_enqueued`'s `author`, and the
|
|
567
641
|
Bridge's queued rows. `turn_started` carries `author`, `author_name` and `participant_mode` on a participant's turn
|
|
568
642
|
(the owner's carries none), and so does the Bridge's turn snapshot and its replay. The owner's history
|
data/docs/internals/web-push.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Web Push (internals)
|
|
2
2
|
|
|
3
3
|
chi web pushes to the owner's phone when a session needs them, for what the tab notifies for: an approval, a
|
|
4
|
-
question, a step-limit question, a card with actions, a failed turn, and (per device,
|
|
4
|
+
question, a step-limit question, a card with actions, a failed turn, a recorded Verify verdict, and (per device,
|
|
5
|
+
off by default) a done one. The
|
|
5
6
|
phone runs chi web as a Home Screen app (iOS 16.4+), its bell subscribes the device, and chi web, the only sender,
|
|
6
7
|
pushes through the device's push service (Apple's `web.push.apple.com`). The user side is in
|
|
7
8
|
[configuration.md](../configuration.md#phone-notifications-web-push). This page is how it is built (P1, P2a and P2b of the
|
|
@@ -146,17 +147,20 @@ the top and in `pending_question` / `pending_card`, strings in `last_turn`), `no
|
|
|
146
147
|
3.5 s (notify.js `RELAY_HOLD_MS`): its parent may relay it.
|
|
147
148
|
2. a new `pending_card` id: `card`, key `"<sid>:card:<cid>"`.
|
|
148
149
|
3. a top-level turn whose `last_turn["ended_at"]` changed (a delegated child's is its parent's to report):
|
|
149
|
-
|
|
150
|
-
`
|
|
151
|
-
|
|
150
|
+
a newly recorded verdict is `verdict`, keyed by `"<sid>:<check_turn_id>"`; otherwise `failed`, or `done` when
|
|
151
|
+
`completed` and `seconds` ≥ `DONE_MIN_SECONDS` 10 or its origin is in `UNWATCHED_ORIGINS`
|
|
152
|
+
(`delegate_report`, `context`, `task`), keyed by `"<sid>:<ended_at>"`. A verdict wins over the done/no-event
|
|
153
|
+
rule, including for a short turn. A reminder turn follows the same rules (no reminder event of its own).
|
|
152
154
|
- `WAITING` (approval, question, continue, card) are the reasons that stay open until answered: badged, in `open`,
|
|
153
|
-
cleaned up, and pushed only while still open. A failed or
|
|
155
|
+
cleaned up, and pushed only while still open. A failed, done or verdict turn has nothing to answer.
|
|
154
156
|
- `Attention.closed_keys(prev, next)`: the question answered, replaced, newly relayed; the card resolved or
|
|
155
157
|
replaced; both when the session is gone.
|
|
156
158
|
- `Attention.text(summary, reason)`: notify.js `attentionText`'s words: the session's name as its card has it
|
|
157
159
|
(title, auto title, the recap's first sentence, first preview, last prompt — the same order `format.js cardName`
|
|
158
160
|
uses) clipped to 61, and "needs approval" / "needs an answer" / "hit its step limit" / "needs you" / "turn
|
|
159
|
-
failed" / "done in N s" (`last_turn["seconds"]` rounded)
|
|
161
|
+
failed" / "done in N s" (`last_turn["seconds"]` rounded) / "<who>: <icon> <verdict> — <reason>" (reason clipped
|
|
162
|
+
to 120 characters). A verdict names its participant from the session's participant sidecar, or says "You" for the
|
|
163
|
+
owner; only verdicts use that push copy, never the full reply. Never the question or the command.
|
|
160
164
|
|
|
161
165
|
`Notifier#call(event)` is a `SessionHub` sink. **The hub calls it under its Monitor**, from the tick thread and also
|
|
162
166
|
from chi web's request threads (`SessionHub#touch`, from the stop/archive/delete routes), so it only enqueues: a push
|
data/docs/sessions.md
CHANGED
|
@@ -4,6 +4,8 @@ Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/s
|
|
|
4
4
|
|
|
5
5
|
**Message times:** an entry of `messages` may carry `at`, when it happened: a local-offset ISO time with milliseconds (`2026-10-24T14:32:05.120+02:00`). User prompts, lines merged into a turn and steers, reminders, context and task notes, and the model's replies have one (a note's is its `created_at`); tool results, `!cmd` messages and chi's own turn notes don't, nor does anything saved before chi stamped messages (no backfill). It is for the UIs only (the gap dividers, a bubble's time): it never goes to the model, so it changes nothing in the requests or their prompt cache. The one time the model reads is the reminders': due reminders go into a turn as a system message headed `[SYSTEM: REMINDERS DUE 2026-10-24 14:32 local]` (the turn's local time; `ReminderQueue#inject!`), written into the saved content then, so a later request sends the same text.
|
|
6
6
|
|
|
7
|
+
**Verify verdicts:** a web Verify turn stamps its opening user message with `verify: {turn_id, quote}` (the selected source turn and quote; metadata only, never added to the prompt). When that turn completes and the final assistant reply's last non-empty line is a valid `Verdict: confirmed|refuted|unclear — <reason>`, the session file appends `{anchor: {turn_id, quote}, verdict, reason, by, check_turn_id, at}` to its optional `verdicts` array. `by` is the turn's author (nil for the owner), `check_turn_id` names the Verify turn, and `at` is its timestamp. The array is append-only; older files without it have no saved verdicts. An `unclear` verdict can be checked again by **Verify fresh** (a delegate child that gets only the claim; see *Delegating*): its verdict is appended to the parent's `verdicts` with `fresh: true`, `of` (the verdict it checked again) and `child_id`, from the parent's `fresh_verdicts/` dir, which its worker takes between turns. Verdicts are display state: none enters a prompt.
|
|
8
|
+
|
|
7
9
|
**Input files:** a message for a session's worker waits in `input/<timestamp>.json` (`SessionInbox.write_input`: `prompt`, `client_id`, `enqueued_id`, and `images`, `no_interrupt` and `delivery` when they apply; `delivery` is written only for `"queue"`). While a turn runs, the worker merges them at each step boundary in name order, except a queued one or one with images: those wait for the turn's end and run one turn each, in name order, and a file after them still merges (`Worker#pending_input_drain`). A queue is sent only to a worker whose `bridge.json` names the `delivery` feature; an older one would steer it, so `SessionManager.deliver_turn` refuses it (409 `delivery_unavailable`), and any other 4xx the Bridge answers is a refusal too, never a fallback file (except a 413, a body over its size limit: that one still goes in as a file, its `delivery` kept). A session command recognized in a file runs without a turn; its outcome is kept at `input/settled/<enqueued_id>` (`completed`, `failed` for a command error, `canceled` with `cancel_reason` `busy` or `dropped` for one refused mid-turn or dropped as the worker left; `origin: command`) so `chi send --wait` ends instead of waiting for a turn that will not run, its detail saying `the command failed` or `the command was refused (busy)` rather than a turn's words. **Reply files:** a turn that ends with visible text leaves its reply in `output/<timestamp>.txt`, or `output/<timestamp>-<enqueued_id>.txt` when the turn ran an input file with an id (`SessionInbox.write_output`), and the session's `last_turn` keeps that `enqueued_id`; so a wait for one queued message (`chi send --queue --wait`, `ReplyWait`'s `turn:`) finds its own turn's reply or end, never another turn's. The names still sort by time, and every reader takes `*.txt`.
|
|
8
10
|
|
|
9
11
|
**Removing a queued message:** a message queued for after the running turn (`chi send --queue`, the web's Alt+Enter, `/queue TEXT` in a terminal), or one with images (it waits for the turn's end too), can be taken back while it still waits: the worker's Bridge (`POST /session/:id/turn/dequeue {enqueued_id}`, the `unqueue` feature) deletes its input file and every UI drops it (`:turn_dequeued`). It is a race with the turn's end, decided by the same rename the worker uses to take the file: once a turn took it the answer is `409 already_started` (it runs), and an id the worker no longer knows is `404 unknown_enqueued_id`. A plain message sent without `--queue` is not removable (`409 not_queued`): a running turn's next step may take it at any moment. A wait for its turn (`chi send --queue --wait`, a delegate follow-up's wait) ends at once with `removed` (the tombstone `input/removed/<enqueued_id>` says so), and a `chi -p` run whose queued prompt went ends with exit 1. The `200` carries the removed `prompt`: the web and the attached terminal put it back into the composer to edit (not its images). The images a removed message named stay in the session's `images/`. Not removable: a queued session command (`/queue /model x`: it waits in the worker, not in `input/`), a message in a stopped worker's inbox (the next worker runs it), and the plain REPL's (`--no-shared`) own queue.
|
|
@@ -89,10 +91,12 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
89
91
|
|
|
90
92
|
**Ordering:**
|
|
91
93
|
|
|
94
|
+
- The web header's project chip opens a picker. The start project is the default row (including its start folder); other rows show their root, session and waiting counts. **All projects** opens every session, and choosing a project drops the open-session hash while keeping `?view=`.
|
|
95
|
+
|
|
92
96
|
- `Session.list` / `SessionManager.list_sessions` / `GET /api/sessions?sort=&order=&limit=&offset=` default to `updated_at desc` (newest activity first). Also supports `created_at`, `asc`. `X-Total-Count` header when paginated.
|
|
93
97
|
- Web UI (`chi web`): the page's scope is in its URL. Started in a git repo, `chi web` opens `/?dir=<that folder>`: that project's sessions, and new sessions start in that folder; the header chip says `<project> · all`, and `all` opens the same place as `?scope=all` (every session; a new session there starts in chi web's start folder, shown on the start page, and cards name their folder; `← <project>` goes back to the project view it came from, or to the start folder's project). A bare `/` (the LAN link, the Home Screen app) is the start folder's project too: the folder chi web runs in, or `web.start_dir` / `chi web --start-dir DIR`; outside a repo it shows every session. A pushed notification opens its session in that session's own project (`/?dir=<its project>#/s/<id>`; `?scope=all` outside a repo). One server serves every project: a second `chi web` (from another repo) finds it through `GET /api/info` and prints (with `--open`, opens) its page for its own folder instead of starting another. The 3 latest sessions sit above the chat, and the grip on the chat's top edge — the same thin handle as the composer's, its twin — puts them away and brings them back: a drag up (or a click, or Enter/Space on it) hides them, a drag down (or a click) shows them again, and the choice is remembered. A hidden strip leaves its status in the top bar (`N sessions · ● 1 live · ● 1 waiting`, from the cards), and a click on that pill opens All sessions, without showing the strip first. In a window under 900 px wide, where the strip scrolls sideways, the grip stays under it, outside the scroller; a window under 700 px tall hides the strip by itself, so a question or approval card in the stage keeps room, and the grip shows it until the window is tall again. A parent and its delegates are one card there: its `▸ 2 delegates · 1 live · 1 waiting` chip (the waiting part in the attention colour, the card's border too) opens their rows in a popover under it (a row per delegate at any depth, indented; a click opens that one, Esc or a click outside closes it, and the strip's order holds while it is open). A fork is a card of its own, and so is a delegate whose parent isn't listed (archived, another project), with its `↳ <parent>` chip; the pill counts cards, and every live or waiting session. "All sessions" (or `/`) opens every session at `#/sessions`, with a search over preview, id and status (Esc or Back returns). There a parent's card holds its delegates the same way, the chip opening their rows inside the card (each with an archive button on hover), open by itself while one of them waits on you; the count says `14 (+7 delegates)`, a search that matches a delegate shows its parent's card with the list open and the matching rows marked, and select mode picks cards (archiving a parent takes its delegates). The open session is in the URL (`#/s/<id>`), so a reload or a copied link opens it again; the chi logo top left goes back to the empty start for a new session. The message box grows with its text; drag its top edge to keep it taller (double-click resets). A file in a tool row (a read, edit or write's title) and its diff lines are refs: hover one and click to open the current file in your editor at that line, on this machine only (`web.editor`; the browser's "always allow" for the page's port and VS Code's "allow opening local files" are asked once; see [Opening files from chi web](configuration.md#opening-files-from-chi-web)). So are an edit or write approval card's paths (at the first line the dry run changes) and its diff lines, before you approve, and the numbered lines of a read's output: `lines 40–60` under it opens the text as read, numbered, when the output is the file as-is (not the head/tail preview of a big file, an error or an image; no numbers after a cut). A `path:line` (or `path:line-line`) in an answer or a step's text is one too once the turn has ended, and after a reload, when it names a file a row or card on the page touched: the path under the session's folder, else the one touched file it ends with (a bare `app.js:12` when only one touched file is named so; two such files make it none); a path without a line counts only when it is a touched file exactly. Code blocks, links, bare URLs and inline code with more than the ref in it are left alone, and a file the session didn't touch is never linked; a link whose text is such a ref alone (github-pr's link to the PR diff) becomes a ref too, and its plain click still goes to the PR. A plugin's refs on an answer (an `after_turn` hook's, see [Refs on the answer](hooks.md#refs-on-the-answer-display-only)) are paired with its links and text whatever the rows touched: they can link a file the session didn't touch, or an issue or a commit, and add their own actions to the ref's menu. A plugin tool's row carries the refs its `refs:` gives (see [Refs on a tool's row](plugins.md#refs-on-a-tools-row)): its title opens the first, and its `▾` menu adds the others as `<ref> · <action>` (the URL on hover); their URL actions work on a phone too. A ref with more than one target shows a small `▾` on hover: it opens a menu of them, in order **PR diff** (a link's), **Open in editor**, **Show in turn** and **Copy path**, and a plain click runs the first (a link's own, else the editor, else show in turn). **Show in turn** scrolls to the tool row that touched the file (looked for in the ref's own step, then its own turn, then the rows before it, then the nearest after it; there, the last one showing the ref's line, else the last one), opens the steps, the stage's steps and the row's diff (or the read showing the line) and flashes the row and the line; an answer's or a step's ref and an approval card's path have it, not a row's own title or lines. It needs no editor, so a viewer without one (a phone on the LAN) gets an answer's refs with **Show in turn** as their click; a row's title and diff lines stay plain text there. On a touch screen a tap opens the menu. A ref with a target is a tab stop: Enter runs its first target, ↓ opens the menu (↑/↓ move, Enter picks, Esc closes back to the ref). Diff and read lines have their click only. The info bar copies `chi --attach <id>` for a terminal. A session whose prompt carried model notes has a `notes: deepseek` chip there (the names without `model_notes_`; the tooltip lists each with its scope and size; `session.prompt_notes` in `GET /api/sessions/:id`, the live worker's, else the session file's; see [Memory](memory.md#model-notes)). Its `llm ctx` chip names the LLM context strategy the next turn runs under (`llm ctx stale,forget · session`, in the accent colour when the session set its own; the tooltip gives each value's source), and its popover sets the session's own strategy, apply rule and budget, or follows the model again, by running `/llm-context` in the worker (the reply shows as a command bubble); `GET /api/sessions/:id`'s `session.llm_context` carries the values (the live worker's, else resolved from the session file), and a `command_ran` that changed them carries the new ones. Its `think` chip does the same for the thinking level (`/thinking`), and on a chat host its `reasoning` chip for the reasoning history (`reasoning all · session`, `/reasoning-history`; `session.reasoning_history`, null on a native host). A `/thinking` or `/reasoning-history` change that restarts the prompt cache asks first: the reply bubble has an **Apply (restarts the cache)** button that sends its `--yes` line (the chips' Set sends that line itself; see [Changes that restart the prompt cache](configuration.md#changes-that-restart-the-prompt-cache)). It shows the context used (`ctx 42%`) and the last generation's decode speed (`87 tok/s`, `~64 tok/s` when estimated; see `/stats` in [cli.md](cli.md#session-commands)); hovering `ctx` there or on a session card lists the session's tokens in (summed over every request, with the cached share), out (with reasoning) and the cost when the provider reports one, for this session only (one estimated from a `hosts.<name>.models` price shows with `~`: `cost: ~$0.54 ($0.42 reported, ~$0.12 estimated)`); after a `/model` switch the info bar's tooltip adds a `per model:` row per run of turns on one model above those totals (`splash:qwen3-35b · 6 turns · 96.0k in / 9.0k out · ~$0.02`, a switch's prefill under its row: `└ switch prefill 58.0k uncached prompt ≈$0.01`; the timing's `model_segments`, replaced by each `generation_completed`'s; the session cards stay as they were), and right after the switch its ctx % is the new model's window's; and the memory indexes its prompt holds (`memory index: ~3.4k tokens in this session's prompt (system 2.0k, project 1.4k)`; see [Memory](memory.md#the-indexs-size)). The start page's model picker (bottom left of the composer, the chosen name `▾`) chooses the model a new session starts on, and a fresh chain link's (see [Session chains](#session-chains); there a pick shows as a `/model` command bubble in the link); it opens a search list over the conversation (↓ or a click; downward when the start page leaves no room above): an empty search shows the last 5 picks (Recent) and then each host's model ids A–Z under the host, the default host first (an id the host declares under `hosts.<name>.models` first, noted `config`, its tooltip `served by config (hosts.<name>.models)`; a host that failed to list its models keeps those ids, greyed and noted `host down`, still pickable; a remembered or default model stays chosen even then, greyed on the button); typed words must each match the host or the id (a substring, else for 3+ characters the letters in order, so `deepseek4.1 fla` finds `openrouter · deepseek/deepseek-v4.1-flash`), ⏎ picks, Esc/Tab close, a pick puts the focus in the message box: `GET /api/models` lists the hosts' models as chi spells them (`{default, models: [{name, host, id, configured?, unavailable?, sampling?, llm_context?}], warning?}`; `configured: true` marks an id declared under `hosts.<name>.models`, listed first under its host, `unavailable: true` one whose host failed to list its models; `sampling` is the model's configured request parameters as `/model` words them, the row's tooltip in the list; bare for the default host, `host:model` for the others, from the same cached lists as `/models`, a bounded wait, a host that is down noted in `warning`), and `POST /api/sessions` takes `model` (blank means the default). Beside it, an `llm ctx` chip shows the LLM context the picked model starts under (each `GET /api/models` row's `llm_context`, as the info bar's); its form sets one for the new session only, sent as `POST /api/sessions`'s `llm_context` and never remembered (see [configuration.md](configuration.md#llm-context-a-sessions-own-strategy)). The start page's first message goes as later ones do: `POST /api/sessions` with `idle: true` and `preview` (the message, which names the session until its turn is saved), then `POST /api/sessions/:id/turn`, so a failed first turn puts its prompt back in the composer too; a first line that is one of the new session's commands (`/model …`) goes to `POST /api/sessions/:id/command` instead, as later ones do. The browser remembers the last model picked; a running session's model is in the info bar and changes only with `/model`. In the composer a line is a command when it is `!…` or starts with one of the session's command names (its `commands` list; `/stats`, `/exit` and the other terminal words get the page's own reply); an unknown `/word` (`/usr/bin/env is missing`) goes to the model as a prompt, as in a terminal; a one-word `/word` no command answers (`/modle`) is not sent: the page shows `Unknown command /modle. Did you mean /model? /help lists the commands.` (the "Did you mean" part only when a name is close). A `POST /turn` (or a session's first `prompt`) that is one of the worker's commands runs as that command too (`202 {status, command_id, session_id}`), so `chi send`, `chi -p` and a page whose command list lags all get the command. ↑/↓ in the composer walk the prompt history the TUI's ↑ walks ([Persistent Prompt History](cli.md#persistent-prompt-history)): ↑ with the caret on the first line, ↓ from the last line while browsing, ↓ past the newest brings the draft back; `GET /api/history` returns `{entries: [...]}`, oldest first (the page fetches it on focus and after each send). The server records a sent line in the routes once the worker took it (`POST /turn` accepted, a `!command` through `POST /command` or as a session's first line); `"history": false` in the body keeps it out (an image-only send).
|
|
94
98
|
- Web notifications: when a session needs you while the tab is hidden or behind another window (a question or a guardrail approval, a plugin card with buttons during a turn such as check-in's, a failed turn, a turn done after 10 s or more; a delegated session only for its questions, a canceled turn never), the page title counts it, `(N) Chi`, until you come back to the tab. The bell at the right of the top bar also turns on OS notifications ("needs an answer", "needs approval", "needs you", "turn failed", "done in 42 s", under the session's first message; a click opens the session): its first click asks the browser for the permission, and the choice is kept per browser. Any session of the page's scope counts, not only the open one. What was already so when the page loaded never counts, and several chi tabs show one notification per event. A chi tab in front tells the others (a `BroadcastChannel`), so while you look at one, the ones behind neither notify nor count what it shows; coming back to a tab clears those events in the other tabs' titles too. The hub's `session` frames carry what this needs: `pending_question` (`{id, kind}`, kind `question` or `approval`), `pending_card` (`{id, bundle}`: the running turn's card with actions, from `pending_card.json` that the worker keeps in the session's folder while one is open; a card without actions, such as loop-guard's, never counts) and `last_turn` (`{outcome, ended_at, seconds, origin}`, saved in the session's JSON as the engine ends each turn).
|
|
95
|
-
- The web frontend is a zero-build ES-module stack in `lib/samagotchi/web/public/`: `data.js` (retrieval, typed SSE `openStream` for a session and `openEvents` for the session list), `sessions_list.js` (the list as a pure reducer over `GET /api/events`: a snapshot replaces it, an upsert keeps a known card in place, a removal drops it; `families()` groups delegates under their parent), `families_view.js` (a parent's family chip, its rows and the strip's popover; the chip and rows as lit-html templates), `keep_focus.js` (lit reuses a list's nodes by position: a redraw keeps the focus on the same item by its `data-id` / `data-name`), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `#N` chip and rows as lit-html templates, the info bar's ← → links, a refused continue, and the fresh-link rule), `notify.js` (which of those events needs the user, for the notifications), `app.js` (presentation/state; a session with no live stream gets one when its `session` event says `bridge_up`, after one re-read: `event_seq` starts over in each worker, so a dropped stream is never resumed with its old cursor), `bubbles.js` (the history's bubbles between the turns' rows: output chunks, end lines, every client's prompt bubbles by `enqueued_id` with their queued/steered badges, the idle recap, guardrail warnings, hooks' notices, plugins' steers, command and note bubbles; lit-html templates, put in the history with the sticky follow by `createBubbles`), `cards_place.js` (where plugin cards and a snapshot's notices go in the history: a card added or updated in place by its id, a running turn's into its step, a snapshot's each above the first turn after it, a finished turn's notice in its step's rows and its question resolved where it was asked; a card's action buttons), `format.js` (pure formatters such as `previewOf`), `plain_line.js` (markdown out of the plain one-line places: the stage headline, a closed step's title, an answered question card's kept-reply line), `prompt_history.js` (the composer's ↑/↓ over the shared prompt history), `commands.js` (session commands: which composer lines are commands, the page's own replies, a `command_ran`'s bubble, the page's command bubbles kept across a re-read), `composer.js` (where a composer line goes, `routeComposerLine`: /cut and /queue, the start page's own replies, a session command or `!cmd`, a typo hint, else a turn; and a session command sent from the composer or a chip), `delivery_line.js` (the composer's row above the text field in a session, always there so the composer keeps its height: the key hint while idle, and the delivery line while a turn runs: where a message typed now goes in, from the step's phase, clock and size, whether "cut in now" can land, and the queue link for a worker with the `delivery` feature, as a pure `deliveryLine`, its lit-html template and `createDeliveryControl`, which ticks it and keeps a choice armed from a link; see docs/cli.md, "Typing during a turn"), `restore.js` (a failed turn's prompt handed back into this tab's composer, before or after its `/turn` ack), `lists_view.js` (the session lists: the strip and its pill, all sessions with its search, count and select mode, their cards, the family and chain popovers; the cards, tile and pill as lit-html templates, drawn as new nodes each time, and the lists' orders as pure functions), `stream_handlers.js` (the open session's stream event handlers, by event type, over the page's views and hooks; a snapshot replays through them too), `stage_view.js` (the stage view: the running turn pinned above the composer, then handed off into the history; its pure rules and texts in `stage_model.js`, its live slots (headline, now row, trail, ticks) in `stage_slots.js`, its cap and held height in `stage_frame.js`, the in-use watch that times the hand-off in `stage_watch.js`), `info_bar.js` (the session bar's info line as a lit-html template over a plain model: id, status, model, chain links, chips, ctx, speed, clock, worker badge), `info_bar_model.js` (that model and the bar's buttons' states, built from the page's session state, its list and its in-flight continues and restarts as pure functions; `app.js`'s `updateInfoBar` applies them every second while a turn runs), `session_state.js` (what the page knows about the open session: its empty state, and `sessionStateFrom`, the fields a `GET /sessions/:id` payload sets), `refs.js` (refs: a kind and a target on the element, a plugin's ref data (label, http(s) URL actions) bound in a WeakMap by `bindRef`, the targets per kind, show in turn, one delegated set of click, key and hover listeners), `ref_menu.js` (a ref's `▾` and its menu), `ref_scan.js` (the `path:line` refs in an answer's or a step's text that name a file the session's rows touched), `answer_refs.js` (the refs a plugin attached to an answer, its `display_refs`: bound to the answer's bubble, paired with its links and text, bound with `bindRef`), `markdown_place.js` (where rendered markdown and its refs go: a text as markdown HTML, its `path:line` refs, a final answer's rendering), `images.js` (image chips in the composer: paste, drop and the image button, the upload before a turn, the thumbnails and the lightbox), `composer_grip.js` (the composer's grip and fold: the drag, tap and keys, the fold per visit), `composer_mount.js` (the composer mounted on a page's markup: the message box and its height, the image chips from a paste, a drop or the image button, the grip and fold, ↑/↓ over the prompt history and the keys; the page's own parts come in as hooks: what Enter and Send do, keys taken first, Esc, where the history comes from, the info bar's Stop turn and drop while folded, typing anywhere to open it; its styles are the shared `composer.css`, linked after `tokens.css` by `index.html` and `participant.html`), `strip_grip.js` (the latest-sessions strip's grip, the composer grip's twin: hides and shows the strip), `review_history.js` (a participant's ↑/↓ list on the participant page: their own comments, in localStorage per grant, never the owner's `/api/history`; `participant.js` mounts `composer_mount.js` with it, no `/` list, no delivery choices, images off), `storage.js` (the page's per-browser choices in localStorage, guarded: a choice that can't be read or written is not remembered), `unqueue.js` (the × on a message queued for after the turn: takes it back, its text into an empty composer or a toast), `toasts.js` (the page's toast stack: a timer each, sticky ones until acted on, the same text reusing its item), `toast_place.js` (where the toast sits: above the composer card, the stage and an open model panel), `dock_reserve.js` (what floats over the history: the history's bottom reserve (`--dock-h`) at the composer card's and the showing stage's height, a reader at the end kept there, and the toast's place measured for `toast_place.js`), `notice_links.js` (a hook notice line's http(s) URLs as links), `start_page.js` (the start page's model picker and its LLM context and thinking chips, a choice for the next new session only; a fresh chain link's picker and its `/model`), `session_actions.js` (Continue, Archive and its Undo, Delete and Stop, and the start page when the open session is gone), `send_turn.js` (the composer's send: a new session first on the start page, the route, the echo, the image upload, the `/turn` ack, a fast failure's restore and each error's place). Unit-tested via `npm test` (`spec/web/public/*.test.js`).
|
|
99
|
+
- The web frontend is a zero-build ES-module stack in `lib/samagotchi/web/public/`: `data.js` (retrieval, typed SSE `openStream` for a session and `openEvents` for the session list), `sessions_list.js` (the list as a pure reducer over `GET /api/events`: a snapshot replaces it, an upsert keeps a known card in place, a removal drops it; `families()` groups delegates under their parent), `families_view.js` (a parent's family chip, its rows and the strip's popover; the chip and rows as lit-html templates), `keep_focus.js` (lit reuses a list's nodes by position: a redraw keeps the focus on the same item by its `data-id` / `data-name`), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `#N` chip and rows as lit-html templates, the info bar's ← → links, a refused continue, and the fresh-link rule), `notify.js` (which of those events needs the user, for the notifications), `app.js` (presentation/state; a session with no live stream gets one when its `session` event says `bridge_up`, after one re-read: `event_seq` starts over in each worker, so a dropped stream is never resumed with its old cursor), `bubbles.js` (the history's bubbles between the turns' rows: output chunks, end lines, every client's prompt bubbles by `enqueued_id` with their queued/steered badges, the idle recap, guardrail warnings, hooks' notices, plugins' steers, command and note bubbles; lit-html templates, put in the history with the sticky follow by `createBubbles`), `cards_place.js` (where plugin cards and a snapshot's notices go in the history: a card added or updated in place by its id, a running turn's into its step, a snapshot's each above the first turn after it, a finished turn's notice in its step's rows and its question resolved where it was asked; a card's action buttons), `format.js` (pure formatters such as `previewOf`), `plain_line.js` (markdown out of the plain one-line places: the stage headline, a closed step's title, an answered question card's kept-reply line), `prompt_history.js` (the composer's ↑/↓ over the shared prompt history), `commands.js` (session commands: which composer lines are commands, the page's own replies, a `command_ran`'s bubble, the page's command bubbles kept across a re-read), `composer.js` (where a composer line goes, `routeComposerLine`: /cut and /queue, the start page's own replies, a session command or `!cmd`, a typo hint, else a turn; and a session command sent from the composer or a chip), `delivery_line.js` (the composer's row above the text field in a session, always there so the composer keeps its height: the key hint while idle, and the delivery line while a turn runs: where a message typed now goes in, from the step's phase, clock and size, whether "cut in now" can land, and the queue link for a worker with the `delivery` feature, as a pure `deliveryLine`, its lit-html template and `createDeliveryControl`, which ticks it and keeps a choice armed from a link; see docs/cli.md, "Typing during a turn"), `restore.js` (a failed turn's prompt handed back into this tab's composer, before or after its `/turn` ack), `lists_view.js` (the session lists: the strip and its pill, all sessions with its search, count and select mode, their cards, the family and chain popovers; the cards, tile and pill as lit-html templates, drawn as new nodes each time, and the lists' orders as pure functions), `stream_handlers.js` (the open session's stream event handlers, by event type, over the page's views and hooks; a snapshot replays through them too), `stage_view.js` (the stage view: the running turn pinned above the composer, then handed off into the history; its pure rules and texts in `stage_model.js`, its live slots (headline, now row, trail, ticks) in `stage_slots.js`, its cap and held height in `stage_frame.js`, the in-use watch that times the hand-off in `stage_watch.js`), `info_bar.js` (the session bar's info line as a lit-html template over a plain model: id, status, model, chain links, chips, ctx, speed, clock, worker badge), `info_bar_model.js` (that model and the bar's buttons' states, built from the page's session state, its list and its in-flight continues and restarts as pure functions; `app.js`'s `updateInfoBar` applies them every second while a turn runs), `session_state.js` (what the page knows about the open session: its empty state, and `sessionStateFrom`, the fields a `GET /sessions/:id` payload sets), `refs.js` (refs: a kind and a target on the element, a plugin's ref data (label, http(s) URL actions) bound in a WeakMap by `bindRef`, the targets per kind, show in turn, one delegated set of click, key and hover listeners), `ref_menu.js` (a ref's `▾` and its menu), `ref_scan.js` (the `path:line` refs in an answer's or a step's text that name a file the session's rows touched), `answer_refs.js` (the refs a plugin attached to an answer, its `display_refs`: bound to the answer's bubble, paired with its links and text, bound with `bindRef`), `markdown_place.js` (where rendered markdown and its refs go: a text as markdown HTML, its `path:line` refs, a final answer's rendering), `images.js` (image chips in the composer: paste, drop and the image button, the upload before a turn, the thumbnails and the lightbox), `composer_grip.js` (the composer's grip and fold: the drag, tap and keys, the fold per visit), `composer_mount.js` (the composer mounted on a page's markup: the message box and its height, the image chips from a paste, a drop or the image button, the grip and fold, ↑/↓ over the prompt history and the keys; the page's own parts come in as hooks: what Enter and Send do, keys taken first, Esc, where the history comes from, the info bar's Stop turn and drop while folded, typing anywhere to open it; its styles, the card it sits in (`.composer-card`, its footer and its line above the text field) included, are the shared `composer.css`, linked after `tokens.css` by `index.html` and `participant.html`), `strip_grip.js` (the latest-sessions strip's grip, the composer grip's twin: hides and shows the strip), `review_history.js` (a participant's ↑/↓ list on the participant page: their own comments, in localStorage per grant, never the owner's `/api/history`; `participant.js` mounts `composer_mount.js` with it, no `/` list, no delivery choices, images off), `storage.js` (the page's per-browser choices in localStorage, guarded: a choice that can't be read or written is not remembered), `unqueue.js` (the × on a message queued for after the turn: takes it back, its text into an empty composer or a toast), `toasts.js` (the page's toast stack: a timer each, sticky ones until acted on, the same text reusing its item), `toast_place.js` (where the toast sits: above the composer card, the stage and an open model panel), `dock_reserve.js` (what floats over the history: the history's bottom reserve (`--dock-h`) at the composer card's and the showing stage's height, a reader at the end kept there, and the toast's place measured for `toast_place.js`), `notice_links.js` (a hook notice line's http(s) URLs as links), `start_page.js` (the start page's model picker and its LLM context and thinking chips, a choice for the next new session only; a fresh chain link's picker and its `/model`), `session_actions.js` (Continue, Archive and its Undo, Delete and Stop, and the start page when the open session is gone), `send_turn.js` (the composer's send: a new session first on the start page, the route, the echo, the image upload, the `/turn` ack, a fast failure's restore and each error's place). Unit-tested via `npm test` (`spec/web/public/*.test.js`).
|
|
96
100
|
- Selecting a session in the web UI is read-only: `GET /api/sessions/:id` never spawns a worker (it reads a live worker's snapshot when one runs, else the session file). A prompt (`POST /turn`) or a command (`POST /command`) wakes the worker, and `/stream` briefly waits for a freshly-spawned bridge before answering. A caught-up SSE reconnect holds the stream open; `reset` markers are only sent for reconnects behind the ring window, or with a cursor from another worker (event ids are `<event_seq>-<epoch>`, one epoch per worker).
|
|
97
101
|
- The web session page's message box folds away for room to read. Drag the grip on its top edge (the pill that shows on hover; always on a phone) down, past the box by 32 px: the pill turns accent while releasing would hide it, and on release the box folds and the info bar stays as the page's bottom edge. The grip stays as a handle on the info bar's top edge, drawn always: pull it up (8 px opens it, and the box follows the pointer in the same gesture), click or tap it (opens it and focuses the box), or just type on the page (the key lands in the box) to bring it back; Enter or Space on the focused grip folds or opens too. A draft (text or images, which folding never clears) colours the handle with the accent, a session waiting on you with the attention colour; its tooltip says so. Stop turn moves into the info bar while it is folded. The fold is remembered per browser (`chi_composer_collapsed`), an archived session opens folded for the visit, and opening it there, like the page opening it itself (a restored line, a quote, continue →'s opener), is for that visit only. The fold keeps the height the grip set (`chi_composer_floor`): the box opens again at the height it had, and only a double-click on the grip forgets it. That height never takes more than half of the window the box is drawn in: a floor saved in a bigger window is held to that half in a smaller one (a rotated phone, a resized window, another device on the same origin), and the saved floor itself stays, so the height comes back when the room does. A click on the expanded grip hides the box as well: it folds 250 ms after the press, so a second click inside that window is read as a double-click and resets the height instead (a drag, Enter or Space act at once, and a drag after a click takes the wait back). The start page's grip only resizes.
|
|
98
102
|
|
|
@@ -384,6 +388,7 @@ The `delegate` tool hands a task to a **child session**: an ordinary chi session
|
|
|
384
388
|
- Every child starts with the shipped `delegated` system memory preloaded (`preloaded_memory_names: ["system/delegated"]`; `--mute delegated` would hide it): put everything in the final reply, don't delegate further, don't write memories or change config, stay in the folder. Its system prompt also says `Delegated by session <parent id>`. The parent's own `--mute` list does not carry over.
|
|
385
389
|
- **A child asks before it changes anything outside its folder** (the work tree top of the folder it started in): a write or edit there, mutating git in another checkout, a command that isn't read-only run from outside it or naming the main checkout or a sibling worktree. It's a core guardrail, on in every mode and without the guardrails bundle, and answered once or for the child's session ([Guardrails](guardrails.md#a-delegate-childs-boundary)); the approval relays to the parent's user as any other.
|
|
386
390
|
- Limits: a child cannot `delegate` (depth 1; the tool refuses), and one session may have at most `session.max_children` (default `4`, env `SAMAGOTCHI_SESSION_MAX_CHILDREN`) children running at a time, counted from the session files (a finished or idle-exited child does not count; one whose worker is still starting does, for 15 s). A refused call creates no session. Nothing stops children with the parent: `chi sessions stop ID` does.
|
|
391
|
+
- **Verify fresh children** (a web card's Verify fresh, [Participants: Verify fresh](internals/participants.md)) are delegate children chi web starts, not the model: in the parent's own folder, with only the claim as their task and none of the parent's history. Their session file carries `verify_fresh: {author, mode, of, anchor}`; a participant's child runs every turn as that participant's (their boundary, saved at the start; their cap, counted with the parent's spend; the parent's `participants.json`). One never rings its parent: its verdict goes to the parent's verdict card (`fresh_verdicts/`), not its conversation, and the parent's `verify_fresh.jsonl` lists them for the spend rollup and the running check (one per verdict at a time). They count among the parent's `session.max_children` while they run.
|
|
387
392
|
- The link is the session's `parent_id`, written before the worker starts, so a respawn keeps it (and `delegate: true`, which a fork's `parent_id` doesn't come with; a child saved before that field is known by its `system/delegated` memory); `GET /api/sessions`, `/api/sessions/:id` and the web hub's `session` frames carry it and `delegate` (a fork is `false`; the web parent's children chip counts delegates only); `SessionManager.children_of` lists a parent's children.
|
|
388
393
|
## Restart fallback
|
|
389
394
|
|
data/lib/samagotchi/bridge.rb
CHANGED
|
@@ -1071,6 +1071,7 @@ module Samagotchi
|
|
|
1071
1071
|
# request's principal; the Bridge is loopback and trusts its caller).
|
|
1072
1072
|
author = fetched(parsed, "author")
|
|
1073
1073
|
author = nil unless author.is_a?(String) && !author.empty?
|
|
1074
|
+
verify = VerifyAnchor.from(fetched(parsed, "verify"))
|
|
1074
1075
|
if sid.to_s.strip.empty? || prompt.to_s.strip.empty?
|
|
1075
1076
|
return [{ "Allow" => "POST" }, 400,
|
|
1076
1077
|
{ error: "missing_fields", detail: "session_id and prompt are required" }]
|
|
@@ -1132,7 +1133,7 @@ module Samagotchi
|
|
|
1132
1133
|
delivery = Delivery::QUEUE if @accumulator.participant_turn?
|
|
1133
1134
|
queued_behind_turn = Delivery.queue?(delivery) && !@accumulator.current_turn.nil?
|
|
1134
1135
|
enqueue_turn(prompt: prompt, client_id: client_id, enqueued_id: enqueued_id,
|
|
1135
|
-
no_interrupt: no_interrupt, images: images, delivery: delivery, author: author).tap do |ok|
|
|
1136
|
+
no_interrupt: no_interrupt, images: images, delivery: delivery, author: author, verify: verify).tap do |ok|
|
|
1136
1137
|
next unless ok
|
|
1137
1138
|
|
|
1138
1139
|
enqueued_event = { type: :turn_enqueued, enqueued_id: enqueued_id, client_id: client_id, prompt: prompt.to_s }
|
|
@@ -1296,9 +1297,9 @@ module Samagotchi
|
|
|
1296
1297
|
|
|
1297
1298
|
# Write a turn into this session's input dir, reusing the file IPC the
|
|
1298
1299
|
# worker polls. Never calls run_turn across the boundary.
|
|
1299
|
-
def enqueue_turn(prompt:, client_id: nil, enqueued_id: nil, no_interrupt: false, images: [], delivery: nil, author: nil)
|
|
1300
|
+
def enqueue_turn(prompt:, client_id: nil, enqueued_id: nil, no_interrupt: false, images: [], delivery: nil, author: nil, verify: nil)
|
|
1300
1301
|
SessionInbox.write_input(session_dir, prompt: prompt, client_id: client_id, enqueued_id: enqueued_id,
|
|
1301
|
-
no_interrupt: no_interrupt, images: images, delivery: delivery, author: author)
|
|
1302
|
+
no_interrupt: no_interrupt, images: images, delivery: delivery, author: author, verify: verify)
|
|
1302
1303
|
end
|
|
1303
1304
|
|
|
1304
1305
|
# ── HTTP plumbing ────────────────────────────────────────────────────────
|
|
@@ -14,6 +14,10 @@ require_relative "bridge_client/event_stream"
|
|
|
14
14
|
require_relative "bridge_client/stream_request"
|
|
15
15
|
|
|
16
16
|
module Samagotchi
|
|
17
|
+
# Loaded on first use (a Verify turn): keeps the bundle test kit's load
|
|
18
|
+
# budget (spec/samagotchi/testing/sandbox_spec.rb).
|
|
19
|
+
autoload :VerifyAnchor, File.expand_path("verify_anchor", __dir__)
|
|
20
|
+
|
|
17
21
|
# Client side of a session worker's Bridge: the 127.0.0.1 HTTP + SSE server
|
|
18
22
|
# each SessionManager worker runs for its Engine (see Bridge). Discovery goes
|
|
19
23
|
# through WorkerLink (the worker's `bridge.json` sidecar, WorkerSidecar, in
|
|
@@ -182,13 +186,16 @@ module Samagotchi
|
|
|
182
186
|
# owner; sent only when given (SessionManager.deliver_turn)
|
|
183
187
|
# @param pending_limit [Integer, nil] with a participant's +author+: how
|
|
184
188
|
# many of their turns may be running or waiting (429 too_many_turns past it)
|
|
185
|
-
def post_turn(prompt:, client_id: nil, no_interrupt: false, images: nil, delivery: nil, author: nil, pending_limit: nil
|
|
189
|
+
def post_turn(prompt:, client_id: nil, no_interrupt: false, images: nil, delivery: nil, author: nil, pending_limit: nil,
|
|
190
|
+
verify: nil)
|
|
186
191
|
body = { session_id: @session_id, prompt: prompt, client_id: client_id }
|
|
187
192
|
body[:no_interrupt] = true if no_interrupt
|
|
188
193
|
body[:author] = author if author
|
|
189
194
|
body[:pending_limit] = pending_limit if author && pending_limit
|
|
190
195
|
body[:images] = images if images && !images.empty?
|
|
191
196
|
body[:delivery] = delivery unless delivery.nil? || Delivery.next_step?(delivery)
|
|
197
|
+
anchor = VerifyAnchor.from(verify)
|
|
198
|
+
body[:verify] = anchor.to_file if anchor
|
|
192
199
|
body[:deadline] = deadline
|
|
193
200
|
post("turn", body, read_body: true)
|
|
194
201
|
end
|
|
@@ -26,6 +26,8 @@ class KnownNames
|
|
|
26
26
|
# name after it is what is checked.
|
|
27
27
|
TOKEN_SPLIT = %r{[/\s"'=:,;|&()<>@~#]+}
|
|
28
28
|
PART_SPLIT = /[-_.]+/
|
|
29
|
+
# Separators at a token's start or end, dropped before it is compared.
|
|
30
|
+
EDGE_SEPARATORS = /\A[-_.]+|[-_.]+\z/
|
|
29
31
|
# A candidate with a shell glob character is not checked: `workato*`
|
|
30
32
|
# is a pattern over the name, not a misspelling of it.
|
|
31
33
|
GLOB = /[*?\[\]{}]/
|
|
@@ -94,15 +96,22 @@ class KnownNames
|
|
|
94
96
|
return nil if names.empty?
|
|
95
97
|
|
|
96
98
|
scan_targets(event).each do |where, text|
|
|
97
|
-
candidates(text).each do |
|
|
99
|
+
candidates(text).each do |token|
|
|
100
|
+
next if names.key?(token.downcase)
|
|
101
|
+
|
|
102
|
+
# "coffee_assistant-" (a prefix search) is the name, not a misspelling.
|
|
103
|
+
candidate = token.gsub(EDGE_SEPARATORS, "")
|
|
98
104
|
down = candidate.downcase
|
|
99
|
-
next if names.key?(down)
|
|
105
|
+
next if candidate.empty? || names.key?(down)
|
|
100
106
|
|
|
101
107
|
names.each do |name_down, name|
|
|
108
|
+
next if camel_case?(candidate, name)
|
|
109
|
+
|
|
102
110
|
max = @max_distance || (name.length < 10 ? 1 : 2)
|
|
103
|
-
|
|
111
|
+
bare = name_down.gsub(EDGE_SEPARATORS, "")
|
|
112
|
+
next if (candidate.length - bare.length).abs > max
|
|
104
113
|
|
|
105
|
-
d = self.class.distance(down,
|
|
114
|
+
d = self.class.distance(down, bare)
|
|
106
115
|
return { miss: candidate, name: name, distance: d, where: where } if d.between?(1, max)
|
|
107
116
|
end
|
|
108
117
|
end
|
|
@@ -110,6 +119,18 @@ class KnownNames
|
|
|
110
119
|
nil
|
|
111
120
|
end
|
|
112
121
|
|
|
122
|
+
# "CoffeeAssistant" or "coffeeAssistant" for "coffee_assistant": the
|
|
123
|
+
# name's own class or variable form, not a misspelling of it. Only a
|
|
124
|
+
# form with a capital: "coffeeassistant" and "coffee-assistant" are
|
|
125
|
+
# still near misses.
|
|
126
|
+
def camel_case?(candidate, name)
|
|
127
|
+
parts = name.split(PART_SPLIT)
|
|
128
|
+
return false if parts.size < 2
|
|
129
|
+
|
|
130
|
+
upper = parts.map(&:capitalize).join
|
|
131
|
+
[upper, upper[0].downcase + upper[1..]].include?(candidate)
|
|
132
|
+
end
|
|
133
|
+
|
|
113
134
|
# [where, text] pairs to scan: the command, the cwd a command names,
|
|
114
135
|
# each path, and a write/edit call's own path (in case normalisation
|
|
115
136
|
# dropped it). Not file contents.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: known-names
|
|
3
|
-
version: 0.1.
|
|
3
|
+
version: 0.1.7
|
|
4
4
|
scope: system
|
|
5
5
|
description: Catches a near-miss of a protected name (home folder, login, git name, repo name, names from config) in a tool call and rejects it with the right spelling; mode ask / correct optional
|
|
6
6
|
trust_level: reviewed
|
|
@@ -8,7 +8,7 @@ files:
|
|
|
8
8
|
known_names.md: sha256:d5348b95b6c655017b541910b36e384220da280818160201f6ec9a50e1e4287c
|
|
9
9
|
hooks:
|
|
10
10
|
known_names.rb:
|
|
11
|
-
sha256: sha256:
|
|
11
|
+
sha256: sha256:a851637e9292f825dc5b8877cd060184de976aa4297b114dab412a89fa3cf091
|
|
12
12
|
event: before_tool_call
|
|
13
13
|
on_error: log
|
|
14
14
|
priority: 50
|
|
@@ -64,6 +64,9 @@ module Samagotchi
|
|
|
64
64
|
def ring(child, why:, state_dir:, wake: nil)
|
|
65
65
|
return nil if mode == "off"
|
|
66
66
|
return nil unless child&.delegate?
|
|
67
|
+
# A Verify fresh child's verdict reaches its parent's card
|
|
68
|
+
# (VerifyFresh.forward), never its conversation.
|
|
69
|
+
return nil if child.verify_fresh
|
|
67
70
|
|
|
68
71
|
parent_id = Session.parent_override(child.id, state_dir: state_dir) || child.parent_id
|
|
69
72
|
return nil unless parent_id
|