samagotchi 0.126.0 → 0.128.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 +4 -0
- data/docs/cli.md +1 -1
- data/docs/configuration.md +2 -2
- data/docs/guardrails.md +5 -0
- data/docs/internals/participants.md +17 -7
- data/docs/sessions.md +3 -1
- data/docs/testing.md +3 -2
- data/lib/samagotchi/bridge.rb +2 -0
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/engine.rb +56 -0
- data/lib/samagotchi/guardrails/read_only_shell.rb +48 -1
- data/lib/samagotchi/session_manager.rb +5 -0
- data/lib/samagotchi/session_participants.rb +14 -1
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +9 -5
- data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +6 -12
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +23 -35
- data/lib/samagotchi/terminal_ui/attached_loop.rb +10 -18
- data/lib/samagotchi/terminal_ui/own_turns.rb +81 -0
- data/lib/samagotchi/verify_anchor.rb +8 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +12 -0
- data/lib/samagotchi/web/participant_access.rb +16 -1
- data/lib/samagotchi/web/participant_review.rb +4 -2
- data/lib/samagotchi/web/project_list.rb +52 -0
- data/lib/samagotchi/web/public/annotate_bar.js +14 -2
- data/lib/samagotchi/web/public/app.js +25 -4
- data/lib/samagotchi/web/public/composer.css +13 -1
- data/lib/samagotchi/web/public/index.html +35 -16
- data/lib/samagotchi/web/public/notify.js +4 -1
- data/lib/samagotchi/web/public/participant.html +33 -32
- data/lib/samagotchi/web/public/participant.js +16 -6
- data/lib/samagotchi/web/public/participant_model.js +3 -2
- data/lib/samagotchi/web/public/participant_names.js +2 -2
- data/lib/samagotchi/web/public/project_picker.js +115 -0
- data/lib/samagotchi/web/public/question_card.js +4 -1
- 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 +3 -1
- data/lib/samagotchi/web/public/session_state.js +2 -0
- data/lib/samagotchi/web/public/stage_view.js +1 -1
- data/lib/samagotchi/web/public/stream_handlers.js +7 -3
- data/lib/samagotchi/web/public/verdict_card.js +18 -3
- data/lib/samagotchi/web/public/verdict_fresh.js +11 -0
- data/lib/samagotchi/web/public/verify_card.css +1 -0
- data/lib/samagotchi/web/public/verify_preset.js +6 -0
- data/lib/samagotchi/web/push/attention.rb +24 -5
- data/lib/samagotchi/web/verify_fresh_routes.rb +12 -7
- data/lib/samagotchi/worker.rb +7 -4
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b175cb8468dd1b6dccbb74c3c372b0796aa18126b47034d07d11d6ead1e1e22
|
|
4
|
+
data.tar.gz: e6b6ea98bf78a7a43962a70ab6daf3cd35519c7db1cefdae44ad8021d4274b75
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: adcfe4e020e6829703e1b9e1d2836d53bb3ddc336da1001c598853352eef75a3ca3df25b7e4d07d292bdaf8b413be228e57487a8b570365e2fba4cecd98490f0
|
|
7
|
+
data.tar.gz: d4b57b741cd271740cb0826e0ff50845a5213c1de30b28c9477ba1b126e5448511f5b73861a3380ae2a93e4102e41df9d4093b14a193a61dcbdd7ed6894a11cd
|
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.128.0] - 2026-10-28
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Verify needs a worker that knows Verify turns: on an older worker chi web disables Verify and Verify fresh with
|
|
15
|
+
"restart this session to use Verify", and refuses anchored turns and fresh checks sent to it.
|
|
16
|
+
- `sqlite3 -readonly -safe …` (only with both flags and read/display options) and `gh`'s reading subcommands
|
|
17
|
+
(`run`/`pr`/`issue` list and view, `pr diff`/`checks`, `repo view`; never `--web`, `api` or `--watch`) count as
|
|
18
|
+
read-only shell commands, so they no longer ask.
|
|
19
|
+
- The shared composer card footer has less vertical padding on phones.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- A Verify turn records a verdict only when its quote is in the reply of the turn it points at; otherwise it runs
|
|
24
|
+
as a plain turn.
|
|
25
|
+
- A verdict's View check opens the earlier session that holds the check (after a continue), or says the check is
|
|
26
|
+
no longer on the page, instead of doing nothing.
|
|
27
|
+
- An attached piped prompt that this terminal removed before it ran says so on stderr (still exit 1) instead of
|
|
28
|
+
"the model gave an empty answer".
|
|
29
|
+
- A participant's key hint wraps to a second line in a narrow comment box instead of being cut after one.
|
|
30
|
+
|
|
31
|
+
Update with `chi update`.
|
|
32
|
+
|
|
33
|
+
## [0.127.0] - 2026-10-28
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- chi web's header project chip opens a picker to switch projects without starting chi web in each one.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- A participant's comment box sits in the same glass card as the owner's composer: the key hint above the text field,
|
|
42
|
+
their usage as the card's footer and the grip on its top edge; folded, the card keeps the usage line.
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- A new invite link opens in a browser that still holds an ended link's cookie (behind an auth proxy it showed
|
|
47
|
+
'revoked').
|
|
48
|
+
- A Verify verdict push names an owner's verdict "You" when its author is empty or the owner's mark, not "A
|
|
49
|
+
participant", on the phone and in the tab alike.
|
|
50
|
+
- A Verify fresh check's system prompt carries no participants line when the owner asked for it, and its
|
|
51
|
+
requester's own (review or pair) when a participant did, instead of the parent session's.
|
|
52
|
+
- A Verify turn that fails fast and comes back into chi web's composer keeps its claim, so sending it again still
|
|
53
|
+
puts a verdict card on the claim.
|
|
54
|
+
|
|
55
|
+
Update with `chi update`, then restart `chi web` and the session workers (`chi sessions restart`).
|
|
56
|
+
|
|
10
57
|
## [0.126.0] - 2026-10-27
|
|
11
58
|
|
|
12
59
|
### Added
|
|
@@ -4763,7 +4810,9 @@ and long-lived sessions.
|
|
|
4763
4810
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
4764
4811
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
4765
4812
|
|
|
4766
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
4813
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.128.0...HEAD
|
|
4814
|
+
[0.128.0]: https://github.com/dm1try/samagotchi/compare/v0.127.0...v0.128.0
|
|
4815
|
+
[0.127.0]: https://github.com/dm1try/samagotchi/compare/v0.126.0...v0.127.0
|
|
4767
4816
|
[0.126.0]: https://github.com/dm1try/samagotchi/compare/v0.125.0...v0.126.0
|
|
4768
4817
|
[0.125.0]: https://github.com/dm1try/samagotchi/compare/v0.124.0...v0.125.0
|
|
4769
4818
|
[0.124.0]: https://github.com/dm1try/samagotchi/compare/v0.123.0...v0.124.0
|
data/docs/architecture.md
CHANGED
|
@@ -173,6 +173,9 @@ agent logic and can be used without any terminal rendering; the UI is a thin lay
|
|
|
173
173
|
but `RelineSeam` (prepended to `Reline::LineEditor`) sends its drawing to the
|
|
174
174
|
`Screen`. The saved history and cards in a join or resync are rendered by
|
|
175
175
|
`TerminalUI::JoinReplay` with the loop's screen, view, link, gap clock and renderer.
|
|
176
|
+
With input from a pipe (`chi -p X </dev/null`), `TerminalUI::OwnTurns` keeps this
|
|
177
|
+
run's own prompts until their turns end; `#run` distinguishes an empty answer from a
|
|
178
|
+
prompt this terminal removed before it ran (both exit 1), as well as chi's other outcomes.
|
|
176
179
|
Without a capable terminal it falls back to `PlainSurface` (append-only).
|
|
177
180
|
|
|
178
181
|
#### Using the core
|
|
@@ -615,6 +618,7 @@ model: [internals/remote-sessions.md](internals/remote-sessions.md).
|
|
|
615
618
|
|---|---|---|---|---|
|
|
616
619
|
| `GET /api/sessions/resolve?id=` | owner | an id or a unique prefix | 200 `{id}` | 404 `not_found`; 400 `ambiguous_id` with `ids` |
|
|
617
620
|
| `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` |
|
|
621
|
+
| `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
622
|
| `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
623
|
| `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
624
|
| `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
|
@@ -557,6 +557,11 @@ every command in it (split at `;`, `&&`, `||`, `|`) is `ls`, `cat`, `head`,
|
|
|
557
557
|
writes or runs something (`sed -i`, `sed 's/a/b/w f'`, `find -delete`/`-exec`,
|
|
558
558
|
`rg --pre`, `sort -o`, `awk` with `>`/`|`/`system(`, `git -c`, `git diff
|
|
559
559
|
--ext-diff`, …) and no redirection other than to `/dev/null` or another fd.
|
|
560
|
+
`sqlite3` is read-only only with both `-readonly` and `-safe`; options are
|
|
561
|
+
checked even after the database name, and only its read/display options are
|
|
562
|
+
allowed (unknown options and dot-command arguments are rejected). `gh` allows
|
|
563
|
+
only `run list|view`, `pr list|view|diff|checks`, `issue list|view` and
|
|
564
|
+
`repo view`; `--web`/`-w`, `gh api` and `pr checks --watch` are not read-only.
|
|
560
565
|
`$(…)`, backticks, `$VAR` (other than `$HOME`, `$XDG_*`, `$TMPDIR` and `$PWD`
|
|
561
566
|
at a word's start), an env prefix, `sh -c`, `xargs`, `eval`, `sudo` and the
|
|
562
567
|
like make a command not read-only. It errs towards asking.
|
|
@@ -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
|
|
@@ -358,10 +359,11 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
358
359
|
reads. `queued` counts their own queued turns on the worker; `model` is the session's model as its host is sent it
|
|
359
360
|
(the alias applied, no host name), live else saved, redacted. Every source reads the grant's own author: another
|
|
360
361
|
participant's spend, the owner's and the session's totals never reach them (the red-team spec checks the body). The
|
|
361
|
-
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
|
|
362
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
|
|
363
|
-
full queue and a link's last day, "over" at the cap.
|
|
364
|
-
|
|
365
|
+
full queue and a link's last day, "over" at the cap. The key hint is the line above the text field, wrapping to at most two (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
|
|
365
367
|
turn's end, a queued or taken-back comment), not while a turn streams.
|
|
366
368
|
- **A fork's note.** A review fork (`chi review --from`, `/coordinate review`) starts with a note holding the source's
|
|
367
369
|
recap and, from the coordinator, its handoff's body: a participant's review turn reads it like the rest of the
|
|
@@ -416,7 +418,13 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
416
418
|
participant's invite link** in their own browser swaps their owner cookie for that grant (the page asks first). A
|
|
417
419
|
continue archives the session and revokes its grants: re-share, and links to the old session stay on it.
|
|
418
420
|
- **Verify verdict cards** (`verdict_card.js`). The built-in Verify preset carries the selected source turn id and quote
|
|
419
|
-
with the submitted turn, without changing its prompt text. A
|
|
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. Before the Engine stamps the anchor or records a verdict, it checks that the source turn exists and
|
|
424
|
+
its assistant reply contains the quote. Matching is case-sensitive, collapses whitespace, and strips common
|
|
425
|
+
Markdown presentation (links, headings, list/blockquote prefixes, emphasis and code delimiters) from both sides;
|
|
426
|
+
this matches the rendered text the page selects without treating different casing as the same claim. A fresh child
|
|
427
|
+
checks the same anchor against its parent's history. A completed Verify reply whose final non-empty line has
|
|
420
428
|
a valid `Verdict: confirmed|refuted|unclear — <reason>` appends a verdict to the session. Both pages place its card
|
|
421
429
|
after the source turn, name its author, show the reason and quote, and link to the checking turn; a live completion
|
|
422
430
|
adds the card without a reload. The participant view receives only the card fields through its allowlist, with the
|
|
@@ -483,7 +491,7 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
483
491
|
for a fresh verdict yet (`Attention` pushes a verdict at a turn's end).
|
|
484
492
|
- **The comment box** is the owner's composer (`composer_mount.js`, styled by the shared `composer.css`), mounted by
|
|
485
493
|
`participant.js` with a subset on. It has: the height that grows with the text, the grip (drag to resize,
|
|
486
|
-
double-click resets, click or drag down folds it; folded, the grip is the handle on the
|
|
494
|
+
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
|
|
487
495
|
page opens it; Annotate opens it for the visit), the one-row layout of the owner's session composer (Send at its
|
|
488
496
|
bottom right; a phone keeps it one row), and ↑/↓ over the participant's own comments: the ones the server took from
|
|
489
497
|
this browser, in localStorage under `chi_review_history:<grant id>` (`review_history.js`; the grant id is the review
|
|
@@ -630,7 +638,9 @@ fixture loads and saves unchanged, `spec/turn_author_record_spec.rb`).
|
|
|
630
638
|
worker's Engine at each turn's start), the system prompt's volatile tail opens with "Participants: people other
|
|
631
639
|
than the owner review this session. …" (`SystemPrompt::PARTICIPANTS_LINE`), or in a working session with
|
|
632
640
|
`PAIR_PARTICIPANTS_LINE`, which names the pair header (and the review one, for turns stamped before). It comes
|
|
633
|
-
when the first joins and goes when the last leaves or expires.
|
|
641
|
+
when the first joins and goes when the last leaves or expires. A Verify fresh child reads its parent's
|
|
642
|
+
`participants.json` but has one participant at most: its requester, under their saved mode while their grant is
|
|
643
|
+
active; the owner's child has no line (`SessionParticipants#prompt_mode`).
|
|
634
644
|
- **Records.** `last_turn.author`, the analytics turn record's `author`, `turn_enqueued`'s `author`, and the
|
|
635
645
|
Bridge's queued rows. `turn_started` carries `author`, `author_name` and `participant_mode` on a participant's turn
|
|
636
646
|
(the owner's carries none), and so does the Bridge's turn snapshot and its replay. The owner's history
|
data/docs/sessions.md
CHANGED
|
@@ -91,10 +91,12 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
91
91
|
|
|
92
92
|
**Ordering:**
|
|
93
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
|
+
|
|
94
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.
|
|
95
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).
|
|
96
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).
|
|
97
|
-
- 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`).
|
|
98
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).
|
|
99
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.
|
|
100
102
|
|
data/docs/testing.md
CHANGED
|
@@ -255,14 +255,15 @@ well formed (unique ids, known keys and labels, a rule that exists in its set).
|
|
|
255
255
|
## While you work: affected specs
|
|
256
256
|
|
|
257
257
|
```sh
|
|
258
|
-
script/affected-specs # the specs for this branch's change, best first, at most
|
|
258
|
+
script/affected-specs # the specs for this branch's change, best first, at most 16
|
|
259
259
|
bundle exec rspec $(script/affected-specs)
|
|
260
260
|
script/affected-specs --why # with the reason for each pick; --all: no cap; --run: runs them
|
|
261
261
|
script/affected-specs A..B # another range (A...B: from their merge-base); a single REV: vs the working tree
|
|
262
262
|
```
|
|
263
263
|
|
|
264
264
|
A builder runs these while working, not the full suite: the specs the change touched, the specs named after the
|
|
265
|
-
files it changed (`lib/samagotchi/foo/bar.rb` → `spec/foo/bar_spec.rb`, `bar_*_spec.rb
|
|
265
|
+
files it changed (`lib/samagotchi/foo/bar.rb` → `spec/foo/bar_spec.rb`, `bar_*_spec.rb`…;
|
|
266
|
+
`lib/samagotchi/foo/bar/baz.rb` → `spec/foo/bar_baz_spec.rb`), the specs that read
|
|
266
267
|
docs or source as text (its `RULES`: add one when a full run catches what the names missed) and the golden of a changed
|
|
267
268
|
file's layer (any `terminal_ui/*.rb` → `spec/terminal_ui_golden_spec.rb`; `turn_flow.rb` and `turn_note.rb`, whose
|
|
268
269
|
words the REPL prints, pick it by a rule). Changes to `tool_declarations.rb` and `system_prompt.rb` also pick the
|
data/lib/samagotchi/bridge.rb
CHANGED
|
@@ -11,6 +11,7 @@ require_relative "atomic_file"
|
|
|
11
11
|
require_relative "bridge_secret"
|
|
12
12
|
require_relative "delivery"
|
|
13
13
|
require_relative "session_inbox"
|
|
14
|
+
require_relative "verify_anchor"
|
|
14
15
|
|
|
15
16
|
require_relative "bridge/bounded_queue"
|
|
16
17
|
require_relative "bridge/card_store"
|
|
@@ -633,6 +634,7 @@ module Samagotchi
|
|
|
633
634
|
# turn (Guardrails::PairBoundary); a worker without it runs it as a
|
|
634
635
|
# review turn, and chi web says so (Delivery::PAIR_FEATURE).
|
|
635
636
|
FEATURES = ["restart", "task_stop", "reparent", Delivery::QUEUE_FEATURE, ReplyWait::TURN_IDS_FEATURE,
|
|
637
|
+
VerifyAnchor::FEATURE,
|
|
636
638
|
SessionInbox::UNQUEUE_FEATURE, Delivery::REVIEW_FEATURE, Delivery::PAIR_FEATURE].freeze
|
|
637
639
|
|
|
638
640
|
# The routes, by method and what follows /session/:id/: a handler takes
|
data/lib/samagotchi/engine.rb
CHANGED
|
@@ -1620,6 +1620,61 @@ module Samagotchi
|
|
|
1620
1620
|
end
|
|
1621
1621
|
private :stamp_verify_anchor
|
|
1622
1622
|
|
|
1623
|
+
def verified_anchor(session, anchor)
|
|
1624
|
+
return unless anchor
|
|
1625
|
+
|
|
1626
|
+
source = verify_anchor_source_session(session, anchor)
|
|
1627
|
+
return unless source
|
|
1628
|
+
|
|
1629
|
+
turn = AnswerTail.turn_slice(Array(source.messages), anchor.turn_id)
|
|
1630
|
+
return reject_verify_anchor(anchor, :turn_missing) unless turn
|
|
1631
|
+
|
|
1632
|
+
reply = turn.reverse.find { |message| AnswerTail.answer?(message) }
|
|
1633
|
+
return reject_verify_anchor(anchor, :reply_missing) unless reply
|
|
1634
|
+
|
|
1635
|
+
quote_text = verify_comparison_text(anchor.quote)
|
|
1636
|
+
answer_text = verify_comparison_text(reply[:content] || reply["content"])
|
|
1637
|
+
return reject_verify_anchor(anchor, :quote_missing) if quote_text.empty? || !answer_text.include?(quote_text)
|
|
1638
|
+
|
|
1639
|
+
anchor
|
|
1640
|
+
end
|
|
1641
|
+
private :verified_anchor
|
|
1642
|
+
|
|
1643
|
+
def verify_anchor_source_session(session, anchor)
|
|
1644
|
+
return session unless session.verify_fresh
|
|
1645
|
+
|
|
1646
|
+
fresh = session.verify_fresh
|
|
1647
|
+
return reject_verify_anchor(anchor, :fresh_anchor_mismatch) unless fresh.anchor == anchor
|
|
1648
|
+
return reject_verify_anchor(anchor, :fresh_parent_missing) unless session.parent_id
|
|
1649
|
+
|
|
1650
|
+
Session.load(session.parent_id, state_dir: session_state_dir)
|
|
1651
|
+
rescue ArgumentError, SystemCallError, IOError => e
|
|
1652
|
+
Log.warn(:turn, "verify_anchor_rejected", turn_id: anchor.turn_id, reason: :source_session_unavailable,
|
|
1653
|
+
error: e.class.name)
|
|
1654
|
+
nil
|
|
1655
|
+
end
|
|
1656
|
+
private :verify_anchor_source_session
|
|
1657
|
+
|
|
1658
|
+
def verify_comparison_text(text)
|
|
1659
|
+
OutputFormatter.strip_markup(text)
|
|
1660
|
+
.gsub(/!\[([^\]]*)\]\([^)]+\)/, '\1')
|
|
1661
|
+
.gsub(/\[([^\]]+)\]\([^)]+\)/, '\1')
|
|
1662
|
+
.gsub(/^[ \t]*(?:\#{1,6}[ \t]+|>[ \t]?|[-+*][ \t]+|\d+[.)][ \t]+)/, "")
|
|
1663
|
+
.gsub(/(\*\*|__|~~|`+)(.+?)\1/m, '\2')
|
|
1664
|
+
.gsub(/(?<!\w)\*(\S(?:.*?\S)?)\*(?!\w)/m, '\1')
|
|
1665
|
+
.gsub(/(?<!\w)_(\S(?:.*?\S)?)_(?!\w)/m, '\1')
|
|
1666
|
+
.tr("|", " ") # a table row's cells; the page copies them without the pipes
|
|
1667
|
+
.gsub(/\s+/, " ")
|
|
1668
|
+
.strip
|
|
1669
|
+
end
|
|
1670
|
+
private :verify_comparison_text
|
|
1671
|
+
|
|
1672
|
+
def reject_verify_anchor(anchor, reason)
|
|
1673
|
+
Log.warn(:turn, "verify_anchor_rejected", turn_id: anchor.turn_id, reason:)
|
|
1674
|
+
nil
|
|
1675
|
+
end
|
|
1676
|
+
private :reject_verify_anchor
|
|
1677
|
+
|
|
1623
1678
|
def record_verdict(turn, outcome)
|
|
1624
1679
|
return unless outcome == "completed" && turn.verify
|
|
1625
1680
|
|
|
@@ -2170,6 +2225,7 @@ module Samagotchi
|
|
|
2170
2225
|
# A participant's Verify fresh child: every turn is theirs (their
|
|
2171
2226
|
# author, boundary and cap), whoever started it.
|
|
2172
2227
|
origin = session.verify_fresh.origin_for(origin) if session.respond_to?(:verify_fresh) && session.verify_fresh
|
|
2228
|
+
verify = verified_anchor(session, VerifyAnchor.from(verify))
|
|
2173
2229
|
# Track the active session for recap and status snapshot.
|
|
2174
2230
|
@session = session
|
|
2175
2231
|
# status is turn state: running now, idle again before the turn's end
|
|
@@ -130,6 +130,53 @@ module Samagotchi
|
|
|
130
130
|
# uniq IN OUT writes OUT.
|
|
131
131
|
def uniq(args) = args.reject { |a| a.start_with?("-") }.size <= 1
|
|
132
132
|
|
|
133
|
+
SQLITE_OPTIONS = %w[-readonly -safe -json -csv -header -noheader -line -column -box -list -separator -bail
|
|
134
|
+
-batch -noinit].freeze
|
|
135
|
+
|
|
136
|
+
# sqlite3 can still write or run programs unless both safety flags are
|
|
137
|
+
# present. Its options may follow the database name, so check every word.
|
|
138
|
+
def sqlite3(args)
|
|
139
|
+
options = []
|
|
140
|
+
positional = []
|
|
141
|
+
index = 0
|
|
142
|
+
while index < args.length
|
|
143
|
+
arg = args[index]
|
|
144
|
+
if arg == "-separator"
|
|
145
|
+
return false if index + 1 == args.length
|
|
146
|
+
|
|
147
|
+
index += 2
|
|
148
|
+
elsif SQLITE_OPTIONS.include?(arg)
|
|
149
|
+
options << arg
|
|
150
|
+
index += 1
|
|
151
|
+
elsif arg.start_with?("-", ".")
|
|
152
|
+
return false
|
|
153
|
+
else
|
|
154
|
+
positional << arg
|
|
155
|
+
index += 1
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
options.include?("-readonly") && options.include?("-safe") && positional.size >= 2
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
GH_READS = {
|
|
163
|
+
"run" => %w[list view],
|
|
164
|
+
"pr" => %w[list view diff checks],
|
|
165
|
+
"issue" => %w[list view],
|
|
166
|
+
"repo" => %w[view]
|
|
167
|
+
}.freeze
|
|
168
|
+
|
|
169
|
+
def gh(args)
|
|
170
|
+
# -w alone or in a bundle of short flags (-cw) opens a browser.
|
|
171
|
+
return false if args.any? { |arg| arg.match?(/\A-[a-zA-Z]*w/) || arg.start_with?("--web") }
|
|
172
|
+
|
|
173
|
+
group, action = args
|
|
174
|
+
return false unless GH_READS.fetch(group, []).include?(action)
|
|
175
|
+
return false if group == "pr" && action == "checks" && args.any? { |arg| arg.start_with?("--watch") }
|
|
176
|
+
|
|
177
|
+
true
|
|
178
|
+
end
|
|
179
|
+
|
|
133
180
|
SED_FLAGS = /\A-[nErsuz]+\z/
|
|
134
181
|
SED_LONG = %w[--quiet --silent --regexp-extended --separate --unbuffered --null-data --posix --debug
|
|
135
182
|
--sandbox].freeze
|
|
@@ -228,7 +275,7 @@ module Samagotchi
|
|
|
228
275
|
CHECKS = {
|
|
229
276
|
"rg" => method(:rg), "find" => method(:find), "tree" => method(:tree), "file" => method(:file),
|
|
230
277
|
"sort" => method(:sort), "uniq" => method(:uniq), "sed" => method(:sed), "awk" => method(:awk),
|
|
231
|
-
"git" => method(:git)
|
|
278
|
+
"git" => method(:git), "sqlite3" => method(:sqlite3), "gh" => method(:gh)
|
|
232
279
|
}.freeze
|
|
233
280
|
|
|
234
281
|
# A sed script parsed far enough to tell that it only reads: its
|
|
@@ -1408,6 +1408,7 @@ module Samagotchi
|
|
|
1408
1408
|
end
|
|
1409
1409
|
manager.resume_session(session_id, state_dir: state_dir)
|
|
1410
1410
|
if (client = bridge.call)
|
|
1411
|
+
return verify_unavailable if verify && !worker_has?(session_dir, VerifyAnchor::FEATURE)
|
|
1411
1412
|
# A worker from before queueing (no "delivery" feature) ignores the
|
|
1412
1413
|
# field or refuses it; either way a file would steer the running turn.
|
|
1413
1414
|
return queue_unavailable if Delivery.queue?(delivery) && !worker_queues?(session_dir)
|
|
@@ -1533,6 +1534,10 @@ module Samagotchi
|
|
|
1533
1534
|
DeliverResult.new(status: :refused, code: 409, ack: Delivery::REVIEW_UNAVAILABLE)
|
|
1534
1535
|
end
|
|
1535
1536
|
|
|
1537
|
+
private_class_method def self.verify_unavailable
|
|
1538
|
+
DeliverResult.new(status: :refused, code: 409, ack: VerifyAnchor::UNAVAILABLE)
|
|
1539
|
+
end
|
|
1540
|
+
|
|
1536
1541
|
private_class_method def self.turn_timeout
|
|
1537
1542
|
DeliverResult.new(status: :timeout, via: :bridge,
|
|
1538
1543
|
ack: { "error" => "worker_timeout",
|
|
@@ -54,16 +54,29 @@ module Samagotchi
|
|
|
54
54
|
# The system prompt's participants line while anyone is in it (#active?
|
|
55
55
|
# as of the last #refresh!): ParticipantMode::PAIR when +session+ is a
|
|
56
56
|
# working session and an active participant was invited to act, else
|
|
57
|
-
# ParticipantMode::REVIEW; nil with nobody active.
|
|
57
|
+
# ParticipantMode::REVIEW; nil with nobody active. A Verify fresh
|
|
58
|
+
# child reads its parent's sidecar but has one participant at most, its
|
|
59
|
+
# requester: their saved mode while their grant is active, nil for the
|
|
60
|
+
# owner's child (no participant ever writes in it).
|
|
58
61
|
def prompt_mode(session)
|
|
59
62
|
active = @entries.select { |entry| entry.active?(@clock.call) }
|
|
60
63
|
return nil if active.empty?
|
|
61
64
|
|
|
65
|
+
fresh = session.respond_to?(:verify_fresh) && session.verify_fresh
|
|
66
|
+
return fresh_prompt_mode(fresh, active) if fresh
|
|
67
|
+
|
|
62
68
|
active.any? { |entry| ParticipantMode.for_turn(session, entry) == ParticipantMode::PAIR } ? ParticipantMode::PAIR : ParticipantMode::REVIEW
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
private
|
|
66
72
|
|
|
73
|
+
def fresh_prompt_mode(fresh, active)
|
|
74
|
+
return nil unless fresh.participant?
|
|
75
|
+
|
|
76
|
+
id = Steer.participant_id(fresh.author)
|
|
77
|
+
active.any? { |entry| entry.id == id } ? fresh.turn_mode : nil
|
|
78
|
+
end
|
|
79
|
+
|
|
67
80
|
def source_id(session)
|
|
68
81
|
return nil unless session
|
|
69
82
|
|
|
@@ -71,7 +71,8 @@ module Samagotchi
|
|
|
71
71
|
# TUI's streams and requests there (#client_id)
|
|
72
72
|
# @return [Symbol] :detached, :closed when the worker went away,
|
|
73
73
|
# :failed when the --model switch didn't go through, or (input from a
|
|
74
|
-
# pipe) :turn_failed / :empty_answer / :unanswered
|
|
74
|
+
# pipe) :turn_failed / :empty_answer / :removed / :unanswered
|
|
75
|
+
# (AttachedLoop#run)
|
|
75
76
|
def run(attach: nil, shared: false, resume: nil, prompt: nil, model: nil, no_interrupt: false, default_input: true,
|
|
76
77
|
memories: [], muted_memories: [], llm_context: {}, thinking: nil, appended_prompt_files: [], toolkit: nil,
|
|
77
78
|
toolkit_flags: [], settings: nil, parent_answers: nil, state_dir: nil, connector: nil)
|
|
@@ -146,11 +147,14 @@ module Samagotchi
|
|
|
146
147
|
err.flush
|
|
147
148
|
end
|
|
148
149
|
|
|
149
|
-
#
|
|
150
|
-
# line on stderr,
|
|
151
|
-
#
|
|
150
|
+
# An own turn with no answer, or a prompt removed before it ran
|
|
151
|
+
# (input from a pipe): one line on stderr, so a script doesn't take
|
|
152
|
+
# the silence for an answer (exit 1).
|
|
152
153
|
def report_ended(ended, err: $stderr)
|
|
153
|
-
|
|
154
|
+
case ended
|
|
155
|
+
when :empty_answer then err.puts(TerminalUI::EMPTY_ANSWER_ERROR)
|
|
156
|
+
when :removed then err.puts("chi: the prompt was removed before it ran")
|
|
157
|
+
end
|
|
154
158
|
end
|
|
155
159
|
|
|
156
160
|
# chi's exit status after #run: 0 detached, 3 a question left waiting
|
|
@@ -7,8 +7,8 @@ module Samagotchi
|
|
|
7
7
|
class AttachedLoop
|
|
8
8
|
# Queue and unqueue handling for the attached loop.
|
|
9
9
|
# Reads @client, @client_id, @first_command_id, @link, @my_queued,
|
|
10
|
-
# @
|
|
11
|
-
# @my_queued, @
|
|
10
|
+
# @own_turns, @reader, @screen, @shown_enqueued, @wait_at_eof; writes
|
|
11
|
+
# @my_queued, @prefilled, @queued_ids,
|
|
12
12
|
# @shown_enqueued.
|
|
13
13
|
# Calls the loop helpers #author_of, #first_command_flag, #mark_activity,
|
|
14
14
|
# #own?, #prompt_line, #send_prompt, #via, and #worker_down.
|
|
@@ -131,19 +131,13 @@ module Samagotchi
|
|
|
131
131
|
|
|
132
132
|
# A queued prompt was taken back before it ran (the web's ×, /unqueue
|
|
133
133
|
# in a terminal). One of this run's (wait_at_eof) will have no turn:
|
|
134
|
-
# it ends the wait
|
|
135
|
-
# line says so.
|
|
134
|
+
# it ends the wait as :removed. Another client's shown line says so.
|
|
136
135
|
def turn_dequeued(event)
|
|
137
136
|
id = event[:enqueued_id]
|
|
138
137
|
@my_queued.delete(id)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
@screen.commit("(removed before it ran)")
|
|
143
|
-
else
|
|
144
|
-
@own_failed = true
|
|
145
|
-
@screen.commit("(your queued message was removed before it ran)")
|
|
146
|
-
end
|
|
138
|
+
by_us = own?(event[:client_id])
|
|
139
|
+
if @own_turns.dequeued(id, by_us: by_us)
|
|
140
|
+
@screen.commit(by_us ? "(removed before it ran)" : "(your queued message was removed before it ran)")
|
|
147
141
|
elsif @shown_enqueued.delete?(id)
|
|
148
142
|
@screen.commit("(a queued message was removed)")
|
|
149
143
|
end
|