samagotchi 0.185.0 → 0.187.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 +37 -1
- data/bin/chi +2 -0
- data/docs/cli.md +1 -0
- data/docs/configuration.md +18 -0
- data/docs/guardrails.md +13 -0
- data/docs/internals/bridge.md +1 -0
- data/docs/internals/engine.md +15 -1
- data/docs/internals/inline-widgets.md +18 -0
- data/docs/internals/pages.md +172 -0
- data/docs/internals/prompt-caching.md +14 -0
- data/docs/internals/remote-sessions.md +7 -0
- data/docs/internals/web-frontend.md +5 -4
- data/docs/memory.md +7 -0
- data/docs/pages.md +150 -0
- data/docs/thin-clients.md +67 -2
- data/lib/samagotchi/bridge.rb +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +5 -2
- data/lib/samagotchi/bundles/system/self_map.md +5 -1
- data/lib/samagotchi/bundles/system/skill_pages.md +93 -0
- data/lib/samagotchi/config.rb +3 -1
- data/lib/samagotchi/context_absorber.rb +5 -2
- data/lib/samagotchi/engine.rb +9 -2
- data/lib/samagotchi/inline_widgets.rb +65 -0
- data/lib/samagotchi/llm/chat_loop.rb +16 -2
- data/lib/samagotchi/page_command.rb +234 -0
- data/lib/samagotchi/pages/builder.rb +187 -0
- data/lib/samagotchi/pages/launch.rb +187 -0
- data/lib/samagotchi/pages/runner.rb +154 -0
- data/lib/samagotchi/pages/store.rb +143 -0
- data/lib/samagotchi/pages.rb +119 -0
- data/lib/samagotchi/plain_reply.rb +75 -0
- data/lib/samagotchi/reply_for.rb +254 -0
- data/lib/samagotchi/run_options.rb +1 -0
- data/lib/samagotchi/session_access/ask.rb +5 -2
- data/lib/samagotchi/session_access/contract.rb +1 -1
- data/lib/samagotchi/session_access/exchange/token.rb +42 -7
- data/lib/samagotchi/session_access/exchange.rb +5 -2
- data/lib/samagotchi/session_access/local.rb +4 -2
- data/lib/samagotchi/session_access/remote.rb +5 -1
- data/lib/samagotchi/session_manager/delivery.rb +36 -6
- data/lib/samagotchi/steer.rb +30 -8
- data/lib/samagotchi/turn_anchors.rb +65 -17
- data/lib/samagotchi/turn_checkpoint.rb +5 -3
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +6 -6
- data/lib/samagotchi/web/ask_routes.rb +62 -17
- data/lib/samagotchi/web/page_routes.rb +116 -0
- data/lib/samagotchi/web/participant_access.rb +1 -1
- data/lib/samagotchi/web/public/app.js +24 -84
- data/lib/samagotchi/web/public/index.html +3 -0
- data/lib/samagotchi/web/public/page_blocks.js +58 -0
- data/lib/samagotchi/web/public/page_links.js +33 -0
- data/lib/samagotchi/web/public/page_model.js +68 -0
- data/lib/samagotchi/web/public/page_route.js +24 -0
- data/lib/samagotchi/web/public/page_table.js +74 -0
- data/lib/samagotchi/web/public/page_table_model.js +76 -0
- data/lib/samagotchi/web/public/page_view.js +218 -0
- data/lib/samagotchi/web/public/pages.css +77 -0
- data/lib/samagotchi/web/public/pages_group.js +65 -0
- data/lib/samagotchi/web/public/peer_text.js +22 -5
- data/lib/samagotchi/web/public/views.js +161 -0
- data/lib/samagotchi/web/session_access_routes.rb +30 -2
- data/lib/samagotchi/web/session_control.rb +21 -2
- data/lib/samagotchi/web/viewer.rb +1 -1
- data/lib/samagotchi/worker.rb +2 -1
- metadata +23 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94944da48a4a9a500ba050224b49cacf5613427dbdb58da43ea6cff2cdc8c41b
|
|
4
|
+
data.tar.gz: 65ab72242e7cb6fb521c13583e96c9daddf02030bfa70a2a002cfb1cc36496be
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e5de8e8c4e68d41371295de2d3b17d0336525d260e9b72a956a3731792110ba32249610ca8515499f5fa32bf868f8c6c9122818253693007a4571daae9063a4
|
|
7
|
+
data.tar.gz: 2afe94681dce8e824a9408a9230e4acbcec11d4ec3a06473b72932c29dab093b947cf7425e0a38da753474252c75814bb9cdc4a2846ec9c40441a9ce8154cc78
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,40 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.187.0] - 2026-11-23
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Pages: ask chi for "a page of …" and it writes a small Ruby script under the config's `pages/` folder that builds
|
|
16
|
+
text, a table and a walk (the shipped pages skill teaches it how). `chi page run | list | rm` runs, lists and
|
|
17
|
+
removes them; a run gets 30 s, one at a time per page, and a failed run keeps the last result under its failure
|
|
18
|
+
line. In chi web a page opens at `#/p/NAME` (All sessions → Pages, or a `#/p/` link in an answer, in place): Refresh
|
|
19
|
+
runs it again, a table sorts on a desktop and opens its rows on a phone, and ⋯ deletes it. Owner only.
|
|
20
|
+
|
|
21
|
+
Update with `chi update`.
|
|
22
|
+
|
|
23
|
+
## [0.186.0] - 2026-11-23
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- `reply_for` on `POST …/ask`: a thin client says what its surface can show (`"voice"`, a name from config.yml's new
|
|
28
|
+
`surfaces:`, or the values formatting, room, choices, detail), and the reply fits it: chi tells the model in a line
|
|
29
|
+
with that message, a plain surface's answer comes back without markdown (the session and the web keep the model's
|
|
30
|
+
text), and the next message from the web gets full formatting again. A surface without detail is told an approval,
|
|
31
|
+
a spending question or a user-only option in words (`needs: "detail"`), and `POST …/answer` with its `reply_for`
|
|
32
|
+
refuses them (403 `needs_detail`). `GET /api/info` lists `reply_for`; a session whose worker is older is refused
|
|
33
|
+
with 409 `reply_for_unavailable` (update chi if needed, then restart it). The iOS Shortcut recipe sends
|
|
34
|
+
`"reply_for": "voice"`.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- Peer text: a line in a peer's text that opens like one of chi's frames is now also quoted when it is led by an
|
|
39
|
+
invisible character (U+3164, U+2800, combining marks, variation selectors) or a markdown list, heading or table
|
|
40
|
+
mark, and so is a line that opens like chi's own `Updated:` / `Attached:` notes; a peer's own `(quoted) ` prefix
|
|
41
|
+
stays in the shown text, and a web bubble reads the same live and after a reload for openings like `ß`.
|
|
42
|
+
|
|
43
|
+
Update with `chi update`.
|
|
44
|
+
|
|
11
45
|
## [0.185.0] - 2026-11-22
|
|
12
46
|
|
|
13
47
|
### Added
|
|
@@ -6791,7 +6825,9 @@ and long-lived sessions.
|
|
|
6791
6825
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6792
6826
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6793
6827
|
|
|
6794
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
6828
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.187.0...HEAD
|
|
6829
|
+
[0.187.0]: https://github.com/dm1try/samagotchi/compare/v0.186.0...v0.187.0
|
|
6830
|
+
[0.186.0]: https://github.com/dm1try/samagotchi/compare/v0.185.0...v0.186.0
|
|
6795
6831
|
[0.185.0]: https://github.com/dm1try/samagotchi/compare/v0.184.0...v0.185.0
|
|
6796
6832
|
[0.184.0]: https://github.com/dm1try/samagotchi/compare/v0.183.0...v0.184.0
|
|
6797
6833
|
[0.183.0]: https://github.com/dm1try/samagotchi/compare/v0.182.0...v0.183.0
|
data/bin/chi
CHANGED
|
@@ -91,6 +91,8 @@ SUBCOMMANDS = {
|
|
|
91
91
|
"desktop" => ["samagotchi/desktop_command", "DesktopCommand"],
|
|
92
92
|
# list and remove memories (ls, rm; --scope, --format)
|
|
93
93
|
"memory" => ["samagotchi/memory_command", "MemoryCommand"],
|
|
94
|
+
# pages: scripts that say what to show (run, list, rm)
|
|
95
|
+
"page" => ["samagotchi/page_command", "PageCommand"],
|
|
94
96
|
# install, upgrade, uninstall, status, diff, list, build (--scope, --force, …)
|
|
95
97
|
"bundle" => ["samagotchi/bundle_command", "BundleCommand"],
|
|
96
98
|
# the System 1 record: replay the asks this machine's sessions already answered
|
data/docs/cli.md
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
- `chi project`, `chi project init [--new-id | --merge-subfolders] [DIR]` — this folder's project, and making a folder in no git repository one. `chi project` prints how its project was found (`kind` `git`, `marker` or `none`), its `root`, its `top` (where the AGENTS.md chain starts), a marked project's `id` (what its memories and project context are keyed on; else the root's path is) and its project `memories` folder, with a `note` for a marker a repository makes ignored, or a `$HOME` that is a git repository. `init` writes `DIR/.chi/project.yml` with a new `id:` (DIR defaults to this folder and is created when missing), so DIR and every subfolder share one memories folder (kept when DIR moves or is renamed), group their sessions and take `chi context --project`; it writes nothing in a git repository (the repository already is the project, exit 0), says so (with the id) for a folder already marked, refuses `$HOME`, a folder above it and `/` (exit 1), and marks a folder inside another marked project as its own, nested one. On a folder marked without an id (an older chi's marker) it adopts one: the folders keyed by its path move to the id, each leaving a link by its old name, and it says what moved and names memories an earlier path left (refused, exit 1, while a session of the project runs). `--new-id` gives a marked folder a fresh id with a copy of its memories and project context (a copied folder going its own way; refused elsewhere, exit 1). Memories a session on this machine saved in a subfolder before init (keyed by that subfolder's path) are named by `init` and by `chi project` (a `note`); `--merge-subfolders` moves them into the project's memories folder (marking DIR first when it isn't yet): a memory the project has by that name, or a bundle's, stays and is named, an emptied folder is removed; refused, exit 1, while a session in DIR runs; not with `--new-id` (exit 2). It prints the root, the id and the memories folder (with the memories already there: a folder chi ran in at its top keeps them, moved to the id), the running sessions in DIR to restart (`chi sessions restart ID`: their prompt keeps the old project) and, when DIR has saved sessions, that a running chi web groups them after its restart. This machine only. See [Projects without git](memory.md#projects-without-git)
|
|
41
41
|
- `chi bundle install|upgrade|uninstall|status|diff|list|build|trash|new|test|check` — manage memory bundles (see [Plugins](plugins.md) and [Bundle hooks](hooks.md#bundle-hooks)); `list` shows the installed ones and the ones shipped with chi, which `install <name>` installs; `upgrade <name>` upgrades an installed bundle by name from the source it came from (its folder, archive or git URL), `upgrade <source>` from a new one; `core` and `dev` are profiles that install a set of them (see [Bundle profiles](memory.md#bundle-profiles-core-and-dev), [Guardrails](guardrails.md), [Bundles](bundles.md#the-btw-bundle), [the mcp bundle](bundles.md#the-mcp-bundle) [the loop-guard bundle](bundles.md#the-loop-guard-bundle), [the check-in bundle](bundles.md#the-check-in-bundle) and [the skills bundle](bundles.md#the-skills-bundle)). `trash` lists and empties the bundle trash (moved files from uninstalls/upgrades). `install`/`upgrade` `--force` overwrites existing entries and also installs a bundle whose `requires_chi` this chi doesn't meet and a memory, plugin or script whose bytes disagree with its manifest `sha256`; without it such a bundle or file is refused (exit 1), nothing written. `install` and `upgrade` (`--dry-run` too) start with the bundle and its version: `NAME OLD → NEW` when it changes, `NAME VERSION` when it doesn't (or for a new install), and `NAME VERSION (already current)` when the run writes nothing, in place of the `Up to date: …` line. A plain `install` of a bundle that is already installed from the same source rewrites its rules, plugin, scripts and record: the summary lists a file that already holds the bundle's bytes as `Up to date: …`, one you wrote as `Skipped: …`, and ends with `NAME was already installed from SOURCE: its rules, plugin and scripts now match it and its record was rewritten` (plus, when a memory was kept, `your own copies of its memories were kept (chi bundle upgrade NAME merges the bundle's changes into them)`). A source with class-file hooks (`hooks/*.rb` or a manifest `hooks:` entry) is refused, `--dry-run` too; an older install's hooks are removed by the next install or upgrade (`Removed (chi no longer loads class-file bundle hooks): …`, an edited one copied to the trash first; see [Class-file hooks are retired](hooks.md#class-file-hooks-are-retired)). `status NAME` lists the bundle's guardrail rules and scripts beside its plugin, each `[ok]`, `[missing]` or `[modified]` (edited: the next install replaces it, its copy kept in the trash; an edited rule doesn't load, so it counts in `issues=`), and `diff NAME` names an edited rule or script with its recorded and current sha256 (chi keeps no base text for them). A usage error (an unknown subcommand or flag, a missing argument, a bad `build --scope`) exits 2, as for the other subcommands. Plain `chi` and `chi web` exit 1 on an unknown flag, a flag missing its value or a stray argument. `new`, `test` and `check` are for writing one: see [Writing a bundle](#writing-a-bundle-new-test-check)
|
|
42
42
|
|
|
43
|
+
- `chi page run NAME [--format text|json]` — run the page script `~/.config/samagotchi/pages/NAME.rb` in a Ruby process of its own (in the pages folder, cut at 30 s with what it started) and store what it built; it prints a summary per block (a text's first lines, a table's labels, first rows and total, a walk's steps), or `error: line N: …` with the script's stderr and "the result of … is kept". `--format json` prints the stored page. `chi page list [--format text|json]` — each page's title and `ran … ago`, `failed … ago (line N)` or `(never ran)`, `changed` when the script changed since. `chi page rm NAME` removes the script and its result. Exit 1 when the script raised, was stopped or broke a limit, when there is no such page or it is already running; 2 for the command line (an unknown flag, a name that isn't lowercase letters, digits and hyphens) — see [Pages](pages.md)
|
|
43
44
|
- `chi guardrails replay [--dry-run] [--threshold T] [--model M]` — seed System 1's record from the approvals this machine's sessions already answered: each ask is judged by the configured model and written to `guardrails/judgments.jsonl` with the answer the user gave, then a per-rule table prints (asks, allowed, denied, would-be auto-allows, false allows, asks with no judgment). A parent agent's answer is not the user's: only its deny is replayed, and only where the parent could have allowed. `--dry-run` judges without writing, `--threshold` overrides `guardrails.system_one.threshold` for the table, `--model` the configured model for this run. Exit 2 when `guardrails.system_one.mode` is off or no `host` is set; a usage error exits 2 (see [System 1](guardrails.md#system-1-experimental))
|
|
44
45
|
- `chi guardrails rule <id>` — print exactly `asks` when that rule is loaded, not disabled and votes `ask` in this `guardrails.mode` for every model; any other line says why not (no such rule, disabled, another mode, it denies, for some models only, rules that failed to load, `guardrails.enabled: false`). Exit 0 either way, 2 for a usage error. It reads config.yml and the installed bundles as a worker does (`GuardrailWiring#rules`) and takes the rule's id, never a command; the [coordinator skill](bundles.md#the-coordinator-bundle) reads it before it merges without asking
|
|
45
46
|
- `chi judgments ls` / `chi judgments report NAME [--days N]` — what [System 1's saved runs](system-one.md) hold: each judgment's digests, runs, labels, failures, models and size; one judgment's counts, p histogram and labels by value. Reads only; local only; `--days` must be a positive whole number.
|
data/docs/configuration.md
CHANGED
|
@@ -2188,6 +2188,24 @@ there; the new subscription replaces the dead one.
|
|
|
2188
2188
|
(it shows the "needs chi web's access token" page; paste the token there). Pushes keep coming meanwhile.
|
|
2189
2189
|
- chi web not running: no pushes (Serve answers 502; a tap couldn't open the page anyway).
|
|
2190
2190
|
|
|
2191
|
+
## Surfaces: names for reply_for
|
|
2192
|
+
|
|
2193
|
+
A thin client says what its surface can show with `reply_for` on `POST …/ask`
|
|
2194
|
+
([Replies that fit the surface](thin-clients.md#replies-that-fit-the-surface)):
|
|
2195
|
+
the values, or a name. `voice` is built in (`formatting: plain`, `room: short`,
|
|
2196
|
+
`choices: 3`, `detail: false`). Add names, or replace `voice`, under `surfaces:`:
|
|
2197
|
+
|
|
2198
|
+
```yaml
|
|
2199
|
+
surfaces:
|
|
2200
|
+
watch: {formatting: plain, room: one_line, choices: 2, detail: false}
|
|
2201
|
+
voice: {formatting: plain, room: short, choices: 0, detail: false}
|
|
2202
|
+
```
|
|
2203
|
+
|
|
2204
|
+
A value left out is the full one. chi web reads the name when the ask comes in,
|
|
2205
|
+
and the session saves the values, so editing a name changes the next asks, not
|
|
2206
|
+
old turns. A name whose values are wrong refuses only the asks that use it (400
|
|
2207
|
+
`invalid_ask` names the entry).
|
|
2208
|
+
|
|
2191
2209
|
## Unattended updates (`update.auto`)
|
|
2192
2210
|
|
|
2193
2211
|
By default chi web only tells you a release is out (`update.notify`, [CLI: Updating](cli.md#updating)). With
|
data/docs/guardrails.md
CHANGED
|
@@ -310,6 +310,19 @@ by editing the session file, or by running `chi --attach` on a PTY with the
|
|
|
310
310
|
markers cleared. chi's instructions for parents ([chi as a
|
|
311
311
|
sub-agent](sub-agent.md)) tell them to use `chi answer` only.
|
|
312
312
|
|
|
313
|
+
### Approvals from a surface without detail
|
|
314
|
+
|
|
315
|
+
A thin client that declares `reply_for` with `detail: false` (a voice Shortcut:
|
|
316
|
+
[thin-clients.md](thin-clients.md#replies-that-fit-the-surface)) is told an
|
|
317
|
+
approval, a spending question (a hook's: cost-cap, work-cap) or a question
|
|
318
|
+
with `user_only` options in words (`needs: "detail"`, no options), and
|
|
319
|
+
`POST …/answer` with that `reply_for` refuses such a question with 403
|
|
320
|
+
`needs_detail` (`ReplyFor#answers?`, told by the question's `kind`, never by
|
|
321
|
+
its `approval:` facts, which a relayed approval may have empty). The model's
|
|
322
|
+
own questions and the step-limit question stay answerable. Like `client_id`,
|
|
323
|
+
this is a convention for an honest client, not a barrier: the token can still
|
|
324
|
+
answer anything, and an answer without the field is the owner's.
|
|
325
|
+
|
|
313
326
|
## Who may run a session command
|
|
314
327
|
|
|
315
328
|
A message that is a session command (`/model x`, `!cmd`, `!rollback`) runs as the command only when a person sends
|
data/docs/internals/bridge.md
CHANGED
|
@@ -675,6 +675,7 @@ compatibility from its version. `Bridge::FEATURES` advertises:
|
|
|
675
675
|
| `turn_ids` | A client can wait for a particular enqueued turn across running, continued and stopped turns. |
|
|
676
676
|
| `verify` | The worker accepts and validates Verify anchors on turns. |
|
|
677
677
|
| `revise` | The worker accepts and validates Revise anchors on turns. |
|
|
678
|
+
| `reply_for` | The worker saves an ask's `reply_for` (`ReplyFor`) on the turn's opener with its baked line. Without it chi web refuses the turn (409 `reply_for_unavailable`, `SessionManager#deliver_turn_now`), and with no Bridge up writes no input file unless the sidecar of a worker holding the session lists it (no sidecar, or a dead worker's leftover one: a retry); chi web lists it in `/api/info` too. |
|
|
678
679
|
| `unqueue` | A client can take back a queued turn before it starts (`POST /session/:id/turn/dequeue`). |
|
|
679
680
|
| `review_turns` | An older chi web checks this before sending legacy participant turns; it is not a read-only mode on current workers. |
|
|
680
681
|
| `pair_turns` | The worker runs participant turns under the owner's guardrails, so chi web may invite participants. |
|
data/docs/internals/engine.md
CHANGED
|
@@ -22,7 +22,7 @@ ivars.
|
|
|
22
22
|
The skeleton is `Engine#run_turn` in `engine.rb`; read it for the order. Each step and what it owns:
|
|
23
23
|
|
|
24
24
|
```
|
|
25
|
-
Engine#run_turn(session, prompt, on_event:, …, origin:, continue:, resumed:, resume_from:, verify:, revises:, …)
|
|
25
|
+
Engine#run_turn(session, prompt, on_event:, …, origin:, continue:, resumed:, resume_from:, verify:, revises:, reply_for:, …)
|
|
26
26
|
├── begin_turn → Turn (the TurnContext published with the running flag)
|
|
27
27
|
├── Client.swap_probe_cancel (a Stop cuts this turn's /props probes)
|
|
28
28
|
├── prepare_turn → false at a STOP CHECK (stopped_before_model), else true
|
|
@@ -652,6 +652,20 @@ model-facing copy (`strip` / `strip_all`: hooks' `messages:`, the recap, `ctx.me
|
|
|
652
652
|
`KernelLoop#sanitize_history` and `ChatLoop#plain` copy them so the stored conversation keeps them across turns.
|
|
653
653
|
`Web::App#messages_for_display` re-validates `display_refs` (`AnswerRefs.for_display`).
|
|
654
654
|
|
|
655
|
+
**The saved-keys rule.** `ChatLoop#plain` rebuilds every kept message from fixed key lists, earlier turns'
|
|
656
|
+
included: a saved message field the wire needs must be listed there (or in `ContextNote::KEYS`,
|
|
657
|
+
`Steer::AUTHOR_KEYS`, `ToolResponse::SAVED_KEYS`), or it is gone after its turn and the chat wires' prefix breaks.
|
|
658
|
+
`spec/llm/chat_loop_saved_keys_spec.rb` fails on such a field; its first turn carries a visitor's `source` and an
|
|
659
|
+
ask's `reply_for` / `reply_line`.
|
|
660
|
+
|
|
661
|
+
**A turn's anchors** (`TurnAnchors`: `verify`, `revises`, `reply_for`) ride from chi web to `run_turn`'s keywords
|
|
662
|
+
(`#kwargs`), each a flat key in the Bridge body and the input file. What a layer does with a member is its rule
|
|
663
|
+
(`TurnAnchors::RULES`): `holds` (an input file naming it waits for the running turn's end, never merged into it),
|
|
664
|
+
`participant` (shown to a participant), `turn_route` (chi web's `POST …/turn` takes it from a body: `reply_for`
|
|
665
|
+
is set by `POST …/ask` alone) and `vouched` (with no Bridge, its input file goes only to a worker whose sidecar
|
|
666
|
+
lists its feature). `reply_for` (`ReplyFor`) is saved on the opening user message with its baked `reply_line`
|
|
667
|
+
(`ReplyFor.opener_fields`, also the return line; prompt-caching.md, "A reply line").
|
|
668
|
+
|
|
655
669
|
**History stamps.** User prompts, merged input and steers, reminders, context and task notes and the model's replies
|
|
656
670
|
carry `at` (`MessageTime::KEY`, `message_time.rb`). A turn reads the wall clock once (`Turn#wall`): `:turn_started`'s
|
|
657
671
|
`at`, its prompt's and its reminders' stamps. The others are stamped by `Steer::Merge#messages` (a merge),
|
|
@@ -88,6 +88,24 @@ The source is at most 16 KB, checked before the parse. After it: a picks has at
|
|
|
88
88
|
and 2-5 unique actors, and every string is at most 300 characters. An error repeats at most 40 characters of a bad
|
|
89
89
|
`type`, and never a tag.
|
|
90
90
|
|
|
91
|
+
### The data entry
|
|
92
|
+
|
|
93
|
+
`InlineWidgets.check(type, data)` takes a script's Hash instead of YAML (a page's `ui.walk`,
|
|
94
|
+
[pages.md](pages.md#the-data-entry-into-inlinewidgets)) and returns the same `Result`, so the same widget draws it.
|
|
95
|
+
|
|
96
|
+
- **One deep conversion first** (`DataTree.convert`), into what `Tree` hands `Schema`: keys made strings (a Symbol or an
|
|
97
|
+
Integer as its text; another key is refused), a String kept (scrubbed to valid UTF-8), a Symbol or a number made its
|
|
98
|
+
text, nil kept (absent, as YAML's empty value). `true`, `false` and anything else are refused with the path to them
|
|
99
|
+
(`steps[1].sees must be text, not true`; indexes from 0). A root that isn't a Hash is refused.
|
|
100
|
+
- **Its own guards:** the type is one of `TYPES` (a Symbol is taken); nesting past `MAX_DEPTH` and a Hash or Array that
|
|
101
|
+
holds itself are refused ("the data nests too deep"), with the `SystemStackError` rescue kept as the backstop.
|
|
102
|
+
- **`Schema` unchanged**, built with an empty identity Hash for folds: the same caps and rules as a block (30 steps,
|
|
103
|
+
2-5 actors, 12 rows, 300 characters) and the same messages. No folds and no lenient pass: the Result's `lenient` is
|
|
104
|
+
always false, a picks id `row_id` mends included (there was no source to be lenient with).
|
|
105
|
+
- The entry's own messages speak of "the data"; `parse` and its messages are untouched, which
|
|
106
|
+
`spec/inline_widgets_golden_spec.rb` pins (every fixture's type, data, lenient and error, in
|
|
107
|
+
`spec/fixtures/inline_widgets_golden.json`, beside the fixtures folder, whose files `inline_widgets_spec.rb` counts).
|
|
108
|
+
|
|
91
109
|
## The page (`inline_widgets.js`)
|
|
92
110
|
|
|
93
111
|
`createWidgetDrawer` is a core drawer of `block_watch.js` (its header has the contract), wired in `app.js` ahead of the
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Pages: the builder, the store, the runner
|
|
2
|
+
|
|
3
|
+
The user side is [pages.md](../pages.md). This is how a run happens and what it leaves.
|
|
4
|
+
|
|
5
|
+
## The pieces
|
|
6
|
+
|
|
7
|
+
| File | What |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `lib/samagotchi/pages.rb` | `Pages`: the limits, the name rule (`check_name!`, the one check before any path), the folders, the errors (`Refused`, `BadName`, `Missing`, `Busy`, each owning its message), the values `Stored` and `Failure` |
|
|
10
|
+
| `pages/builder.rb` | `Builder` (the script's `ui`: `text`, `table`, `walk`) and `TableBlock` (columns, formats, key columns, cells, the total) |
|
|
11
|
+
| `pages/store.rb` | `Store`: read, list, `record_run`, `record_failure`, `locked`, `remove`, `file_id` |
|
|
12
|
+
| `pages/runner.rb` | `Runner.run(argv)`: the runner process's whole job |
|
|
13
|
+
| `pages/launch.rb` | `Launch.run(name, timeout:, cancelled:)`: the one launch path |
|
|
14
|
+
| `page_command.rb` | `chi page run | list | rm` |
|
|
15
|
+
|
|
16
|
+
`pages.rb` requires json, digest, time, `inline_widgets`, `paths` and `atomic_file`, and autoloads its parts. Nothing
|
|
17
|
+
it reaches requires the engine, the config, the web, the plugins, `ChildEnv` or `ProcessGroup`: the runner loads it
|
|
18
|
+
alone. `launch.rb` is the only file that needs `ChildEnv` and `ProcessGroup`, and nothing in `pages.rb` requires it.
|
|
19
|
+
|
|
20
|
+
## The one launch path
|
|
21
|
+
|
|
22
|
+
`chi page run` does not run the script in its own process. `Launch.run` starts the runner, exactly as chi web's
|
|
23
|
+
Refresh will (Build 2), so a page that passes from the terminal passes on Refresh (the spike saw two paths give a
|
|
24
|
+
script 152 against 73 preloaded libraries and a stale `PWD`). It costs about 70 ms more per terminal run.
|
|
25
|
+
|
|
26
|
+
1. `Pages.check_name!`, then the script must exist (`Missing`), then `Store.locked(name)`: a non-blocking `flock` on
|
|
27
|
+
`<state>/samagotchi/pages/NAME.lock`, beside the page's folder so `remove` can delete the folder while holding it.
|
|
28
|
+
Held: `Busy` ("page NAME is already running"). The order means a typo leaves no lock file behind. `locked` yields
|
|
29
|
+
the lock's io.
|
|
30
|
+
2. `ProcessGroup.spawn(env, RbConfig.ruby, "-I", <this chi's lib>, "-e", 'require "samagotchi/pages/runner"; exit
|
|
31
|
+
Samagotchi::Pages::Runner.run(ARGV)', NAME, TIMEOUT, DEADLINE, 3 => lock)`, in a group of its own, `chdir:` the
|
|
32
|
+
pages folder, stdin closed, the lock on fd 3. The env is a worker's changes
|
|
33
|
+
(`SessionManager::WorkerCommand#spawn_options`): `ChildEnv.unbundled` (an installed gem's Bundler changes undone),
|
|
34
|
+
`ChildEnv.unset` (the spawner's guardrails settings and session markers), `Launch.cleared_keys` unset
|
|
35
|
+
(`CHI_REMOTE`, every `SAMAGOTCHI_WORKER_*` key and the vendor agent markers `AgentCaller::VENDOR_MARKERS`:
|
|
36
|
+
`CLAUDECODE`, `CODEX_THREAD_ID`, `AI_AGENT`, read from those constants), `Paths.absolute_xdg`, and `PWD` set to the
|
|
37
|
+
pages folder (spawn's `chdir:` doesn't change it). So a run never goes remote, never looks like a worker's child,
|
|
38
|
+
and a script's `chi send` is the owner's even from a chi web started in an agent's pane. "This chi's lib" is
|
|
39
|
+
`File.expand_path("../..", __dir__)` from `pages/launch.rb`: a checkout and an installed gem alike.
|
|
40
|
+
3. stdout and stderr are each read by a `ProcessGroup::PipeReader` (64 KB, the tail kept).
|
|
41
|
+
4. The wait polls `Process.wait2(pid, WNOHANG)`. At the timeout (30 s) `ProcessGroup.stop` TERMs the group, CONTs it,
|
|
42
|
+
waits a grace, then KILLs, with a `stopped:` that reaps (an unreaped zombie counts as alive to the default check).
|
|
43
|
+
Descendants that moved to a group of their own are found and stopped too (`walk:`); one that left the tree
|
|
44
|
+
(`setsid` and its parent gone) survives: the stated limit. `cancelled:` (a callable, chi web's "am I stopping?")
|
|
45
|
+
is polled in the same loop: true stops the group the same way, recorded as "the run was stopped".
|
|
46
|
+
5. After **any** exit the group gets a KILL (a script's background child would hold the pipes open), and the readers
|
|
47
|
+
are bounded (`reader.wait(grace) || reader.kill`).
|
|
48
|
+
6. The runner wrote the output file, or the launcher records the failure itself: the cut ("the script was stopped
|
|
49
|
+
after 30 s"), or "the runner ended without a result" (with stderr's last line) when the exit status is not 0 or 1
|
|
50
|
+
or the file is the one that was there before. "The one that was there before" is the file's inode
|
|
51
|
+
(`Store.file_id`): `AtomicFile` renames a new file in for every write, so a run that wrote changes it even within
|
|
52
|
+
one second.
|
|
53
|
+
7. An interrupt or an exception stops and reaps the group in `ensure`; the lock is released by the `File.open` block.
|
|
54
|
+
|
|
55
|
+
**A launcher that dies mid-run** (chi web or a terminal killed with `KILL`) runs no `ensure`. The runner holds the
|
|
56
|
+
lock too (the flock is shared through fd 3), so the page stays "already running" while it lives, and it ends itself:
|
|
57
|
+
its `DEADLINE` is the timeout + `Launch::GRACE_SECONDS` + `Launch::DEADLINE_MARGIN` (2 s) from its own start, later
|
|
58
|
+
than the launcher's cut, which wins whenever the launcher is alive. At the deadline a thread in the runner records
|
|
59
|
+
the cut itself ("the script was stopped after N s") and KILLs the runner's group. So a killed launcher leaves at most
|
|
60
|
+
one bounded run. A Ruby thread can't fire while a C extension holds the GVL: such a script outlives its deadline
|
|
61
|
+
until the call returns (accepted). The runner's stdout and stderr are pipes whose reader died with the launcher: Ruby
|
|
62
|
+
ignores SIGPIPE, so the script's next output that reaches the pipe (a large one, or `$stdout.sync`) raises
|
|
63
|
+
`Errno::EPIPE`, recorded as the script's failure at that line (the good blocks stay; small output stays buffered and
|
|
64
|
+
only fails at the exit, after the result is written). Accepted: the run stays bounded, only the error's words mislead.
|
|
65
|
+
|
|
66
|
+
`ContextFetch#run_command`, `#wait` and `#stop_group` are the model this follows.
|
|
67
|
+
|
|
68
|
+
## The runner
|
|
69
|
+
|
|
70
|
+
`Runner.run(argv)` (requiring `pages/runner.rb` runs nothing) first makes fd 3 close-on-exec, so the lock is the
|
|
71
|
+
runner's alone: a program the script execs (`spawn`, `system`, backticks), even one that leaves the group and
|
|
72
|
+
outlives the run, never inherits it (it would keep the page "already running" for good). A `fork` without an exec
|
|
73
|
+
(`Process.daemon` too) keeps fd 3 and holds the lock while it lives: the stated limit. A script's own `exec` replaces
|
|
74
|
+
the runner: the lock goes (close-on-exec) and so does the deadline thread; a live launcher still cuts it (it stays in
|
|
75
|
+
the group), but after a dead launcher the exec'd program runs unbounded while the page is runnable again (the same
|
|
76
|
+
limit). It arms the deadline when argv carries one (a write of the result and the deadline's record take one mutex,
|
|
77
|
+
and the write sets a done flag under it, so a result written before the deadline fires is never overwritten), checks
|
|
78
|
+
the
|
|
79
|
+
name and the script, then
|
|
80
|
+
`load(path, dsl)`: the wrap module is a fresh `Module` defining only `page`, so the script's own `def`s land in it, not
|
|
81
|
+
on `Object`. `page(title) { |ui| … }` makes a `Builder`; a second call raises `Refused`. After the load, no `page` call
|
|
82
|
+
fails the run too.
|
|
83
|
+
|
|
84
|
+
It rescues `StandardError`, `ScriptError`, `SystemExit`, `SystemStackError` (endless recursion) and `NoMemoryError` (never a `SignalException`: a TERM is the launcher's cut,
|
|
85
|
+
recorded by the launcher). The line is the first backtrace entry inside the script file (the exact path given to
|
|
86
|
+
`load`), or for a `ScriptError` the `path:LINE:` at the start of its message's first line, which every Ruby gives; the
|
|
87
|
+
message drops that prefix. An `exit 3` is "the script called exit 3". A good run goes through `Store.record_run`, which
|
|
88
|
+
refuses an output over 256 KB (`Refused`, recorded as the failure). Exit 0 ran, 1 the script failed, 2 no such page.
|
|
89
|
+
The result reaches the launcher through the file only: a `puts` in a script corrupts nothing.
|
|
90
|
+
|
|
91
|
+
## The output file
|
|
92
|
+
|
|
93
|
+
`<state>/samagotchi/pages/NAME/output.json`, written with `AtomicFile.write`:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{"name": "usage", "title": "Usage, last 7 days",
|
|
97
|
+
"blocks": [{"type": "text", "text": "…"},
|
|
98
|
+
{"type": "table",
|
|
99
|
+
"columns": [{"key": "model", "label": "Model"},
|
|
100
|
+
{"key": "cost", "label": "Stored", "format": "money", "key_column": true}],
|
|
101
|
+
"rows": [["claude:sonnet-5-5", 14.221]], "total": ["Total", 18.1252], "dropped": 0},
|
|
102
|
+
{"type": "walk", "data": {"title": "…", "actors": ["…"], "steps": ["…"]}}],
|
|
103
|
+
"ran_at": "2026-11-23T10:00:00Z", "duration_ms": 412, "script_sha": "<sha256 of the script that made the blocks>",
|
|
104
|
+
"error": null}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- A failed run rewrites only `error`: `{"message", "line" (Integer or null), "at", "script_sha"}`. The blocks, title,
|
|
108
|
+
`ran_at` and `script_sha` stay those of the last good run. A good run sets `error` to null. `Store.record_failure` is
|
|
109
|
+
the one writer of a failure, for the runner and the launcher alike, always under the page's lock.
|
|
110
|
+
- Before any good run there are no blocks and `ran_at` is null.
|
|
111
|
+
- A table's `format` is stored, not applied: cells stay raw numbers so the page can sort them. `key_column` marks the
|
|
112
|
+
columns a phone shows besides the first (never marked).
|
|
113
|
+
- `Store.read` gives a `Stored`: the fields, `state` (`:never_ran`, `:ok`, `:failed`) and `changed?` (the script's
|
|
114
|
+
sha256 now differs from `script_sha`). "Changed" means only this: the result on screen came from an older script;
|
|
115
|
+
every surface uses `changed?` as it is, never a meaning of its own. A missing or unreadable file reads as never ran; keys this version doesn't
|
|
116
|
+
know are dropped on read (a newer chi's file reads fine).
|
|
117
|
+
|
|
118
|
+
## The data entry into InlineWidgets
|
|
119
|
+
|
|
120
|
+
`ui.walk` hands its Hash to `InlineWidgets.check("walk", data)`, the same `Schema` the chat's YAML goes through, so the
|
|
121
|
+
same widget draws it ([inline-widgets.md](inline-widgets.md#the-data-entry)).
|
|
122
|
+
|
|
123
|
+
## chi web
|
|
124
|
+
|
|
125
|
+
**The routes** (`web/page_routes.rb`, `Web::PageRoutes`, its `ROUTES` splatted into `App::ROUTES` on the models row),
|
|
126
|
+
all `:owner`: a participant's token gets 403 `not_permitted` (`participant_gate_spec` sweeps them). The name capture is
|
|
127
|
+
`([^/]+)`, checked with `Pages.valid_name?` before any path is built; a name that breaks the rule is no such page.
|
|
128
|
+
|
|
129
|
+
| Route | Answers |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `GET /api/pages` | `{pages: [{name, title, state, ran_at, failed_at, changed, error_line}]}`, by name (`Store.list`) |
|
|
132
|
+
| `GET /api/pages/NAME` | the page (below); 404 `page_missing` with no script. Runs nothing |
|
|
133
|
+
| `POST /api/pages/NAME/run` | `Launch.run(name, timeout: 30, cancelled: -> { !@server_running.call })` inside the request; the page as after the run, with `stderr` (its last 2 KB) when it failed; 409 `page_busy`, 404 `page_missing`, 503 `server_stopping` (chi web's stop ended it: "the run was stopped") |
|
|
134
|
+
| `DELETE /api/pages/NAME` | `Store.remove`: `{removed: NAME}`; 409 `page_busy`, 404 `page_missing` |
|
|
135
|
+
|
|
136
|
+
The page: `{name, title, state, ran_at, duration_ms, changed, changed_after_failure, script_changed_at, error:
|
|
137
|
+
{message, line, at} | null, blocks}`. `changed` is `Stored#changed?`; `changed_after_failure` says the script differs
|
|
138
|
+
from the one that failed (so the page needs no sha); `script_changed_at` is the script's mtime. A text block carries
|
|
139
|
+
`html`, the `MarkdownRenderer`'s sanitised render, when rendering is available (`web.markdown`), else `text` only.
|
|
140
|
+
The error codes' `detail` is the exception's own message.
|
|
141
|
+
|
|
142
|
+
**The capability** `pages` (`Web::Viewer::CAPABILITIES`, never a participant's) makes the view, the group and the link
|
|
143
|
+
handler; without it none is made and no page call goes out (`viewer_boot.test.js`).
|
|
144
|
+
|
|
145
|
+
**The page's modules** (`lib/samagotchi/web/public/`): `page_route.js` (`pageHash`, `pageNameFromHash`, the open rule:
|
|
146
|
+
never a participant's, never without `pages`), `views.js` (reads the page hash before the session intent:
|
|
147
|
+
`body.page-view`, `openPage` / `closePage` / `leavePage`, the session hash not written while a page is open, a session
|
|
148
|
+
picked leaving the page), `page_view.js` (the header, the states, the calls; an answer for a page no longer open is
|
|
149
|
+
dropped, `latest.js`), `page_model.js` (the words: meta, the failed and changed lines, Copy the error), `page_blocks.js`
|
|
150
|
+
(text, walk in a widget host with `drawWalk`, an unknown type as one muted line), `page_table.js` and
|
|
151
|
+
`page_table_model.js` (cells, sort, the phone's rows), `pages_group.js` (All sessions' group), `page_links.js` (the
|
|
152
|
+
delegated click on the turn roots and the page view for `#/p/` anchors), `pages.css`. What a script wrote reaches the
|
|
153
|
+
page as text or attributes, never as markup, except the server's sanitised `html`.
|
|
154
|
+
|
|
155
|
+
**Not live**: no stream event and no polling. A run from a terminal shows on the next open; two tabs are not kept in
|
|
156
|
+
step.
|
|
157
|
+
|
|
158
|
+
## chi's side: the skill
|
|
159
|
+
|
|
160
|
+
What chi knows about pages is one memory, the system bundle's `skill_pages.md` (an index line in every prompt, the
|
|
161
|
+
text read on demand), and the `chi page` line in `self_map.md`. `spec/pages_skill_spec.rb` runs the skill's example
|
|
162
|
+
through `Runner::Collector`'s DSL and pins every command, `ui` call and limit it names to the code; a change to the
|
|
163
|
+
skill's text regenerates the turn goldens (`UPDATE_PROMPTS=1`).
|
|
164
|
+
|
|
165
|
+
The eval behind it (2026-11-23, the local Qwen3.8-Flash-Next, `chi -p … --non-interactive` in isolated dirs, N=5 per
|
|
166
|
+
task): 14 of 15 pages ran and showed the reference numbers, no ask was raised, and the task that doesn't name the
|
|
167
|
+
skill read it 5 of 5 times; without the skill (`--mute skill_pages`, N=3) 1 of 3 made a page. The archive is the
|
|
168
|
+
owner's `~/.claude/plans/evals/0016-pages-skill/`.
|
|
169
|
+
|
|
170
|
+
## Later builds
|
|
171
|
+
|
|
172
|
+
- Not planned yet: picks on a page, a data API (`runtime`), a bundle's pages, parameters.
|
|
@@ -175,6 +175,20 @@ right-hand column happens.
|
|
|
175
175
|
first participant joins and when the last leaves or expires: one history re-read each, then stable. Under D3(a)
|
|
176
176
|
the declared tools stay the session's, so an author switch costs nothing: the participant boundary is a gate
|
|
177
177
|
on the calls, not a toolkit switch. The forged-header mark (`(quoted) `) is a pure function of the text too.
|
|
178
|
+
- **A reply line** (an ask's `reply_for`, [thin-clients.md](../thin-clients.md#replies-that-fit-the-surface)).
|
|
179
|
+
The turn's opening user message is saved with the surface's values (`reply_for`) and the line baked from them
|
|
180
|
+
when the message is made (`reply_line`, `ReplyFor#line`); `content` stays the user's text. On the wire the
|
|
181
|
+
opener is: its header (a visitor's), then the `reply_line`, then the text (`Steer.wire_text`; a forged copy of
|
|
182
|
+
the line's lead, `Steer::REPLY_LEAD`, in the text is quoted). The wire reads `reply_line` only, never the values,
|
|
183
|
+
so a later release that rewords a value never changes an old turn's bytes. The first undeclared opener after a
|
|
184
|
+
declared one gets the baked return line (`ReplyFor::RETURN_LINE`), found from the history alone
|
|
185
|
+
(`ReplyFor.opener_fields`: the latest user message with a `turn_id`, no kind and not a `!` line; a step-limit
|
|
186
|
+
Stop's reason has none), and none after it.
|
|
187
|
+
All three copies of that message carry both fields: `ChatLoop#plain` lists them, `ChatLoop#wire_messages` calls
|
|
188
|
+
`Steer.wire_text` for an opener with a header or a reply line, and the worker's checkpoint copy
|
|
189
|
+
(`TurnCheckpoint#begin_turn`, what a kill before the first boundary leaves) gets the same `opener_fields`. About
|
|
190
|
+
20 tokens per restricted message and per return; a session that never declares one sends its bytes as before
|
|
191
|
+
(`spec/reply_for_history_spec.rb`: voice, web, voice, restart, voice, web on native, `openai` and `anthropic`).
|
|
178
192
|
- Side requests (idle recap, `/btw`) go through `IdleClient` with their own short system prompt (the recap's also
|
|
179
193
|
asks for its auto title line, `RecapPrompt::TITLE`: static text, still that one request). On a current
|
|
180
194
|
llama.cpp they don't evict the session (see the server settings below); chi never pins them to a slot.
|
|
@@ -102,6 +102,13 @@ command, on an idle session with its offer standing and a live worker, is bound
|
|
|
102
102
|
instead, the offer's turn id from `ReplyWait.own_turn`, as chi answer follows it; the worker's ack is not read): chi web's `POST …/ask`
|
|
103
103
|
builds one per request over a `Local` that delivers through chi web's own manager and Bridge (`Web::AskRoutes::
|
|
104
104
|
AskAccess`), and `McpServer::Tools` reuses `SessionAccess::Ask` / `Exchange` through the MCP server without chi web.
|
|
105
|
+
The ask chain carries a turn's anchors (`Ask#call` → `Exchange#attempt` → `Local#deliver_turn` → the manager's
|
|
106
|
+
`deliver_turn`, `anchors:` passed only when given): chi web's `/ask` puts a message's `reply_for` there
|
|
107
|
+
(`TurnAnchors`). `SessionAccess::Remote#deliver_turn` refuses a non-empty one (local only, exit 2), and neither
|
|
108
|
+
`chi send`, `--remote` nor the MCP tools send one. The capabilities in hand shape the answer in
|
|
109
|
+
`Web::SessionAccessRoutes#wait_result_json` (`PlainReply`, `needs: "detail"`): the request's for `/ask`, the
|
|
110
|
+
token's (`Exchange::Token`'s `f`, `Token.reply_for`) for `/wait`, the pending turn's saved opener's
|
|
111
|
+
(`ReplyFor.of_latest_turn`, read before the answer is relayed) for `/answer`'s reply.
|
|
105
112
|
An ask's `request_id` becomes its turn's enqueued id (`SessionInbox.enqueued_id_for("ask:" + it)`, a UUID v5 shape a
|
|
106
113
|
Bridge keeps): `Ask#call` first reads `prepare_wait(turn: E)`, and a `known_turn` (running, a queued input file, the
|
|
107
114
|
last to end, a reply file, settled, merged) is waited on again with `Target.wait_only(start, requested: E).with(queued:)`, nothing
|
|
@@ -14,7 +14,7 @@ by `npm run e2e` (`spec/e2e/`). `app.js` has no unit spec of its own; `viewer_bo
|
|
|
14
14
|
**Every module has a size cap, `app.js` its own**: `npm run lint` fails past `max-lines` in `eslint.config.js`
|
|
15
15
|
(counted as `wc -l` counts, comments and blank lines too). Every `public/*.js` module: 1200 (`samagotchi/module-size`,
|
|
16
16
|
about 10% over the largest, `turn_block.js`), so a module near it splits rather than becoming the next `app.js`.
|
|
17
|
-
`app.js` (`samagotchi/app-size`): 1637, its size once the diagrams' wiring went into `diagram_wiring.js
|
|
17
|
+
`app.js` (`samagotchi/app-size`): 1577, its size once the views by hash went into `views.js` and the pages' wiring landed; down from 1637, its size once the diagrams' wiring went into `diagram_wiring.js`, itself down from 1638,
|
|
18
18
|
its size once the lightbox went into `picture_viewer.js`, itself down from 1649, its
|
|
19
19
|
size plus 50 once the session-open flow went into `session_sync.js` and `session_view.js`, itself ratcheted down from 2000, itself down from 2250 when the versions, the owner's claim links and
|
|
20
20
|
Verify, the composer's mode and the strip's hide went into modules of their own. A new feature goes into a module of
|
|
@@ -37,7 +37,7 @@ sheet still keeps `isChained` and `format.js deleteConfirmText` that way; and `w
|
|
|
37
37
|
with 0.183.0's `ws_reader.js` and `ws_peek.js`, and 0.183.0's view with this `ws_reader.js`, from
|
|
38
38
|
`spec/web/public/fixtures/v0.183.0/`). `answer_fold.js`, `details_motion.js`,
|
|
39
39
|
`turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
|
|
40
|
-
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js`, `peer_text.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
40
|
+
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (The delete sheet, below), `removal_sheet_model.js` (its words: rows, button words, the archive model, the toast; DOM-free), `running_tasks.js` (a delete's or archive's tasks: their line and the toast's suffix; DOM-free, so `stop_sheet.js` and the delete sheet share its cut), `hash_intent.js` (what the hash asks for: session, all, start or keep), `views.js` (the views by hash, in one place: All sessions at `#/sessions` opened, closed and left; a page at `#/p/NAME`, read before the session intent, `hashIntent` calling it `keep`: `body.page-view`, Back to where it was opened from, the session's hash not written while it is open, a session picked leaving it; the session's `#/s/<id>` written; a hash change applied and selected; app.js makes it after the lists and hands its functions lazily to what it made before), the page's modules `page_route.js`, `page_view.js`, `page_model.js`, `page_blocks.js`, `page_table.js`, `page_table_model.js`, `pages_group.js` and `page_links.js` (a page in chi web: [pages.md](pages.md#chi-web)), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_part_peek.js`, `ws_reader.js`, `ws_way_in.js`, `ws_item_sig.js`, `ws_markdown.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ws_order.js` (the working-set list's order: last touched first, held while it is open, [working-set.md](working-set.md), The list's order), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `peer_data.js`, `peer_exchange.js`, `peer_note.js`, `peer_links.js`, `peer_text.js` (a peer's send and answer in the conversation: The peer exchange, below), `peer_chip.js` (a paired peer's one chip in the session bar: The peer exchange), `picture_viewer.js` (the picture viewer, `#lightbox`: below, Picture viewer), `pan_zoom.js` (its maths, pure), `diagram_wiring.js` (`wireDiagrams`: the block host with the viewer as its `openPicture`, the viewer closed on a theme change, the regions' layer given to the viewer; the viewer itself stays made in app.js, which `createSessionView` reads first), `block_regions.js` (a renderer's regions cleaned, pure: [block-renderers.md](block-renderers.md#regions)), `region_hit.js` (their hit test, the arrow keys' nearest region and the reveal under the card, pure), `picture_regions.js` (the regions' layer over the viewer: below, Picture viewer), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
41
41
|
|
|
42
42
|
## One page, every viewer
|
|
43
43
|
|
|
@@ -58,7 +58,7 @@ their viewer (The viewer, below), their show and stream are filtered (`Web::Part
|
|
|
58
58
|
| **The session store** (`session_store.js`; app.js `store`) | `store.selected` (the open session's id), `store.current` and `store.sessions` (below) | through the store only (see The session store); other modules get getters (`selected: () => store.selected`, `state: () => store.current`) or the store itself (`stream_handlers.js`, `send_turn.js`, `session_actions.js`) | the store runs the redraws that read what changed (below); nobody calls them by hand |
|
|
59
59
|
| **app.js module scope**: about a dozen top-level `let`s (`eventsControl`, `pageCapabilities`/`pageEditorUrl`, `scopeError`…); the open session's stream handle and re-read bookkeeping (`streamControl`, `resyncsInFlight`/`resyncAgain`, `resyncAttempts`) are `session_sync.js`'s, in its closure | the page's mode and its streams | their module only; other modules get getters and hooks (`sessionSync.hasStream()`: a stream object, also while it connects, the bar's streaming; `streamLive()`: it delivers) | the writer touches the redraw that reads it (`store.touch("infoBar")`: the stream; `version_notices.js` does it for the versions and its `restarting` set), or calls a redraw only it feeds |
|
|
60
60
|
| **`store.current`** (`session_state.js`: `emptySessionState` / `sessionStateFrom`; per field: `session_fields.js FIELDS`) | the open session's fields, about 40 (info bar, chips, verdicts, timing, worker, stream cursor) | `store.update` / `setStatus` from app.js, `stream_handlers.js`, `session_sync.js`, `session_view.js`, `send_turn.js` (`firstPreview`, `owner`), `session_actions.js` (`status`), `owner_verify.js` (`verdicts`, `verifyFresh`); `forgetSession`'s `replaceCurrent` (`session_view.js`). Two writers in place, on purpose (D8 in `FIELDS`): live_timing.js's `activeTurn`, verdict_fresh.js's running list | the store runs the field's redraws (`FIELDS[key].redraws`) |
|
|
61
|
-
| **`store.sessions`** (the hub's projection) | every card | `store.update({sessions})` from app.js: `openSessionEvents` (`applySessionEvent`), `refresh` (the list fallback), `addCreatedSession`, `applyView` (re-sorted), `replaceSelectedCard` (`setLiveStatus` through `setStatus`, `readTurnEnd`, `setUsedMemories`), the stream's close (`withoutWorker`); `session_actions.js` (`setSessions`) | the store: `lists` and `infoBar`. **Always a new array**; an entry is replaced, never changed in place. `followSelectedSession` copies the open one's owner and worker (`fieldsFromCard`) and, when not streaming, its status (`setStatus(…, "hub")`) into `store.current` |
|
|
61
|
+
| **`store.sessions`** (the hub's projection) | every card | `store.update({sessions})` from app.js: `openSessionEvents` (`applySessionEvent`), `refresh` (the list fallback), `addCreatedSession`, `views.js applyView` (re-sorted), `replaceSelectedCard` (`setLiveStatus` through `setStatus`, `readTurnEnd`, `setUsedMemories`), the stream's close (`withoutWorker`); `session_actions.js` (`setSessions`) | the store: `lists` and `infoBar`. **Always a new array**; an entry is replaced, never changed in place. `followSelectedSession` copies the open one's owner and worker (`fieldsFromCard`) and, when not streaming, its status (`setStatus(…, "hub")`) into `store.current` |
|
|
62
62
|
| **Factory closures**: the `create*` factories (popovers, panels, views) | each component's own state: open-for, busy, error, its own fetched list | the factory | an `onChange` hook back into app.js, or a getter the factory reads at draw time |
|
|
63
63
|
| **The history DOM** | the conversation as drawn (a running turn's reason bubble, `.bubble.said`, is live only: see A turn opened in the history): which turn a bubble belongs to (`data-turn-id`, `data-answer-turn`), what opens a turn (`TURN_PROMPT`, `bubbles.js`: a prompt or a wake's note, the same turns `Steer.turn_opening?` counts for a card's `turns_since`), an opening's id for a card's and the saved recap's stamp (`data-turn-id` on a prompt, `data-opening-id` on a wake's note or `/continue no`'s reason line; `card_stamps.js` places a snapshot's card after the stamped opening, `recap_stamp.js` the saved recap after the last turn it covers, each by its count (`turns_since`) only without one), kept command bubbles, which texts were shown, unnamed badges, folded answers and long prompts (`.folded`), Revise stamps (`data-revises` on a prompt; a Verify turn's `data-verify`) and the stacks' folded versions (`.stack-hidden`, `.stack-stub.open`); the switcher's version on view is `revise_stack.js`'s own (a copy `.stack-view` before the top answer, the top `.stack-swapped`; never stored) | `bubbles.js`, `cards_place.js`, `question_cards.js`, `turn_block.js`/`stage_view.js`, `answer_fold.js`, `revise_stack.js`, `stream_handlers.js` (a live `turn_completed`'s `revises` and `verify` onto its prompt) | read back as state: `turn_range.js turnElements` (one walker for a turn's elements), `keptCommandBubbles`, `seedSeenFromDom`, `nameUnnamedBadges`/`nameVerdictCards`, `answer_fold.js` and `revise_stack.js` (their observers decorate every path that fills `#history`; the stacks are `stacks()` of the stamps, read again on each change, never a store field), `history_reveal.js revealInHistory` (the one way a jump unfolds what hides its target) |
|
|
64
64
|
| **A drawn turn** (`turn_drawings` of the full read) | every finished turn, as live drew it: `turnGroups` groups by the stamps only, a turn's stamped items (`drawn: <turn_id>`) one group, and `turnHistoryNodes` draws it by feeding its drawing's events to a live turn block offscreen (`turn_block.js drawnTurnNodes`: the block's own handlers, as the stage's), the stage's extras (a reminder, merged lines, a card that waited when it arrived, an answered question) in the order live left them for the history (`turn_settle.js settleOrder`, pure: from the drawing's `part_settled` and question events, whether the turn was opened, and whether a question had a lead-in) and the end as live, then the answer, the merged lines and the steps' texts from their saved items (markdown, refs). Each of its top-level elements carries `data-drawn`: `cards_place.js` leaves that turn's in-turn CardStore entries (`of_turn`) to it, and a kept reminder bubble of that turn (`data-turn-id`) stays out after a resync. chi web sends a drawing for every finished turn (one made from its messages where live wrote none): `drawnGroup` pairs the record the end names (`end.record_id`, by place for a turn saved before turn ids), else by the turn's id, and the answer's `data-answer-turn` is the end's own `turn_id` only (a made-up id, `m…` or `…~N`, keys none: no Revise). Nothing is rebuilt from messages: an item that comes unstamped is a `plain` group drawn as a plain row of its text (its prompt or answer bubble, no steps), the running turn's as expected (`runningTurnId`, the show's `current_turn`: it has no line yet), any other a miss, marked `data-undrawn`, logged once per render (`console.warn`) and counted by the reload check (`undrawn`), never a throw; a drawing with no parts (a minimal line) draws its prompt, answer and end | chi web (the show) | `renderHistory`, the reload check's render |
|
|
@@ -263,6 +263,7 @@ gates are boot-time: a show's narrower `viewer` changes what `viewer.can` answer
|
|
|
263
263
|
| `block_renderers` | a bundle's drawn blocks (the core `chi-ui` drawer stays) | `/api/block_renderers*` |
|
|
264
264
|
| `stop_any_turn` | the stage's Stop turn (`onCancel`) | `POST …/cancel` |
|
|
265
265
|
| `steer_any_turn` | none: the delivery line reads a participant's own `steer_own_turn` instead (`viewerTurn`) | |
|
|
266
|
+
| `pages` | the page view (`#pageView`, `page_view.js`), All sessions' Pages group (`#pagesGroup`), the `#/p/` link handler (`page_links.js`); without it a `#/p/…` hash is no page | `GET /api/pages` (when All sessions opens), `GET /api/pages/:name` (a page opened), `POST …/run` (Refresh), `DELETE /api/pages/:name` |
|
|
266
267
|
|
|
267
268
|
A participant's `can` (`Viewer::PARTICIPANT_CAPABILITIES`, in their show's `viewer` and on `<body>`) names
|
|
268
269
|
capabilities of their own, not the owner's: `send` (the composer), `stop_own_turn` (Stop turn on a turn they
|
|
@@ -492,7 +493,7 @@ kept: every open starts fitted.
|
|
|
492
493
|
- **It closes by itself**, whatever it shows, on a system theme change (the diagram behind is redrawn; the viewer
|
|
493
494
|
holds the old picture; `diagram_wiring.js`), on a switch to another session or the start page (`session_view.js
|
|
494
495
|
forgetSession`, given `pictures`; the same session again keeps it) and when the all-sessions view opens (it hides
|
|
495
|
-
`#center`, the viewer's parent;
|
|
496
|
+
`#center`, the viewer's parent; `views.js applyView`). A bubble rewritten or cloned while it is open leaves it as it
|
|
496
497
|
is: it holds its own copy of the URL. The toast may show over it (both z-index 50, the toast later); it is modal by
|
|
497
498
|
`aria-modal`, `#center`'s other children aren't made `inert`.
|
|
498
499
|
- index.html keeps `<div id="lightbox" hidden><img alt=""></div>`: an older cached app.js reads that `<img>`. The
|
data/docs/memory.md
CHANGED
|
@@ -441,6 +441,13 @@ skills`, [docs/bundles.md](bundles.md#the-skills-bundle)) adds `/skill save`,
|
|
|
441
441
|
one-line diff after each update, and nudges a model that skips a failing
|
|
442
442
|
step instead of fixing the skill.
|
|
443
443
|
|
|
444
|
+
chi ships one skill itself: `skill_pages` in the system bundle
|
|
445
|
+
(`lib/samagotchi/bundles/system/skill_pages.md`), how to make, check and link a
|
|
446
|
+
page ([docs/pages.md](pages.md#asking-chi-for-a-page)). Its index line is in
|
|
447
|
+
every prompt; its text is read only when a page is asked for. It tells chi not
|
|
448
|
+
to edit it (a shipped file: a local edit would have to be merged at the next
|
|
449
|
+
upgrade) but to say what differed.
|
|
450
|
+
|
|
444
451
|
## Toolkit memories
|
|
445
452
|
|
|
446
453
|
A memory named `toolkit_<name>` defines a toolkit named `<name>`. Its body is
|