samagotchi 0.186.0 → 0.188.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 +68 -1
- data/bin/chi +4 -0
- data/docs/architecture.md +8 -4
- data/docs/bundles.md +124 -120
- data/docs/cli.md +26 -5
- data/docs/configuration.md +4 -4
- data/docs/context.md +18 -162
- data/docs/guardrails.md +3 -1
- data/docs/hooks.md +2 -1
- data/docs/internals/attached-context.md +19 -37
- data/docs/internals/bridge.md +1 -0
- data/docs/internals/engine.md +2 -2
- data/docs/internals/inline-widgets.md +18 -0
- data/docs/internals/llm-context-forget.md +5 -6
- data/docs/internals/objectives.md +1 -0
- data/docs/internals/pages.md +175 -0
- data/docs/internals/peers.md +149 -0
- data/docs/internals/remote-sessions.md +7 -4
- data/docs/internals/web-frontend.md +65 -40
- data/docs/internals/web-push.md +1 -1
- data/docs/memory.md +8 -1
- data/docs/pages.md +151 -0
- data/docs/peers.md +141 -0
- data/docs/plugins.md +52 -27
- data/docs/sessions.md +8 -4
- data/docs/sub-agent.md +5 -5
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundle_command/api_calls.rb +2 -1
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -18
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +22 -16
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +48 -39
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +15 -73
- data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +16 -16
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -15
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +35 -24
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +51 -40
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +18 -54
- data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +16 -16
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/plugin.rb +14 -8
- 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/client_id.rb +15 -1
- data/lib/samagotchi/config.rb +8 -7
- data/lib/samagotchi/context_absorber.rb +23 -277
- data/lib/samagotchi/context_sources.rb +17 -69
- data/lib/samagotchi/engine/messages.rb +12 -1
- data/lib/samagotchi/engine/plugins.rb +1 -1
- data/lib/samagotchi/engine.rb +7 -6
- data/lib/samagotchi/engine_peers.rb +0 -3
- data/lib/samagotchi/guardrail_wiring.rb +2 -0
- data/lib/samagotchi/guardrails/chi_dirs.rb +4 -3
- data/lib/samagotchi/guardrails/parent_approvals.rb +6 -5
- data/lib/samagotchi/guardrails/protected_paths.rb +6 -3
- data/lib/samagotchi/inline_widgets.rb +73 -0
- data/lib/samagotchi/log_line.rb +1 -1
- data/lib/samagotchi/note_move.rb +3 -1
- data/lib/samagotchi/page_command.rb +243 -0
- data/lib/samagotchi/pages/builder.rb +186 -0
- data/lib/samagotchi/pages/launch.rb +193 -0
- data/lib/samagotchi/pages/runner.rb +154 -0
- data/lib/samagotchi/pages/store.rb +152 -0
- data/lib/samagotchi/pages.rb +119 -0
- data/lib/samagotchi/peer_command.rb +192 -0
- data/lib/samagotchi/peer_continue.rb +99 -0
- data/lib/samagotchi/peer_exchanges.rb +3 -3
- data/lib/samagotchi/peer_mailbox.rb +360 -0
- data/lib/samagotchi/peer_note.rb +208 -0
- data/lib/samagotchi/peer_receipts.rb +247 -0
- data/lib/samagotchi/peer_registry.rb +44 -0
- data/lib/samagotchi/peer_roster.rb +79 -0
- data/lib/samagotchi/peer_say.rb +168 -0
- data/lib/samagotchi/plugin/api.rb +29 -21
- data/lib/samagotchi/plugin/context.rb +7 -0
- data/lib/samagotchi/plugin/loader.rb +3 -3
- data/lib/samagotchi/plugin/peer.rb +175 -64
- data/lib/samagotchi/plugin/peers.rb +70 -0
- data/lib/samagotchi/run_options.rb +3 -1
- data/lib/samagotchi/schedule_command.rb +10 -3
- data/lib/samagotchi/schedule_display.rb +32 -0
- data/lib/samagotchi/session_access/contract.rb +19 -2
- data/lib/samagotchi/session_access/local.rb +132 -14
- data/lib/samagotchi/session_access/remote.rb +4 -2
- data/lib/samagotchi/session_access/remote_peers.rb +75 -0
- data/lib/samagotchi/session_continue.rb +12 -0
- data/lib/samagotchi/session_inbox_delivery.rb +5 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -3
- data/lib/samagotchi/session_manager/removal.rb +2 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -1
- data/lib/samagotchi/session_manager.rb +1 -0
- data/lib/samagotchi/session_stores.rb +17 -0
- data/lib/samagotchi/steer.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +4 -1
- data/lib/samagotchi/testing/boundary.rb +4 -13
- data/lib/samagotchi/testing/bundle.rb +40 -5
- data/lib/samagotchi/testing/install.rb +4 -4
- data/lib/samagotchi/testing/recording_api.rb +2 -1
- data/lib/samagotchi/tools/context_read.rb +0 -14
- data/lib/samagotchi/tools/list_schedules.rb +8 -3
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +7 -18
- data/lib/samagotchi/web/message_display.rb +4 -2
- data/lib/samagotchi/web/page_routes.rb +116 -0
- data/lib/samagotchi/web/peer_routes.rb +133 -0
- data/lib/samagotchi/web/public/app.js +35 -95
- data/lib/samagotchi/web/public/bubbles.js +2 -2
- data/lib/samagotchi/web/public/cards_place.js +20 -1
- data/lib/samagotchi/web/public/context_chips.js +45 -46
- data/lib/samagotchi/web/public/history_reveal.js +4 -1
- data/lib/samagotchi/web/public/history_shape.js +3 -2
- data/lib/samagotchi/web/public/index.html +16 -0
- data/lib/samagotchi/web/public/notify.js +1 -1
- 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 +219 -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_chip.js +60 -74
- data/lib/samagotchi/web/public/peer_data.js +13 -11
- data/lib/samagotchi/web/public/peer_links.js +12 -7
- data/lib/samagotchi/web/public/peer_mailbox_api.js +20 -0
- data/lib/samagotchi/web/public/peer_note.js +7 -3
- data/lib/samagotchi/web/public/peer_text.js +4 -4
- data/lib/samagotchi/web/public/quiet_notes.js +199 -0
- data/lib/samagotchi/web/public/revise_stack.js +4 -3
- data/lib/samagotchi/web/public/session_view.js +2 -2
- data/lib/samagotchi/web/public/stream_handlers.js +3 -2
- data/lib/samagotchi/web/public/turn_block.js +7 -3
- data/lib/samagotchi/web/public/turn_events.js +6 -0
- data/lib/samagotchi/web/public/views.js +161 -0
- data/lib/samagotchi/web/push/attention.rb +3 -2
- data/lib/samagotchi/web/session_access_routes.rb +3 -20
- data/lib/samagotchi/web/viewer.rb +1 -1
- data/lib/samagotchi/worker/leave.rb +3 -0
- data/lib/samagotchi/worker/mail.rb +73 -0
- data/lib/samagotchi/worker/startup.rb +3 -0
- data/lib/samagotchi/worker/wake_turns.rb +20 -5
- data/lib/samagotchi/worker.rb +12 -6
- data/lib/samagotchi/worker_inbound/mail.rb +214 -0
- data/lib/samagotchi/worker_inbound.rb +43 -46
- data/lib/samagotchi/worker_wakes.rb +26 -21
- metadata +39 -2
- data/lib/samagotchi/peer_sources.rb +0 -58
|
@@ -194,6 +194,7 @@ command), which absorbs the file. It no longer waits for the fallback tick.
|
|
|
194
194
|
- **The entry** (`objectives_entry.js`, from `turn_html.js noteBubbleTemplate`): `Objectives.entry` puts the note's items
|
|
195
195
|
and, against the list before it, `changes` (`Objectives.changes`, display only) on the history item and on
|
|
196
196
|
`context_added`. A first list is pills; a later one a line, `You marked O1 done`. The raw text stays the tooltip.
|
|
197
|
+
It is a `.bubble.note`, so it folds into the history's notes row (`quiet_notes.js`, named `objectives` there).
|
|
197
198
|
- **Moves** (`objectives_moves.js`): a tool row's id is a chip (`moveRowText`), and a row that recorded a move carries
|
|
198
199
|
`data-move-id`. One observer on `#history` reads those back into a line after each finished `.turn-work`, so a reload,
|
|
199
200
|
a live end and a hand-off all draw it. The newest line's Not yet is `objectivesStrip.notYet`. A decision card's
|
|
@@ -0,0 +1,175 @@
|
|
|
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`, `remove_temporary_outputs` |
|
|
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. A timeout cut is skipped when the run wrote its result and exited
|
|
51
|
+
0 or 1; a failure the runner already recorded is never overwritten. "The one that was there before" is the file's
|
|
52
|
+
inode
|
|
53
|
+
(`Store.file_id`): `AtomicFile` renames a new file in for every write, so a run that wrote changes it even within
|
|
54
|
+
one second.
|
|
55
|
+
7. An interrupt or an exception stops and reaps the group in `ensure`; the lock is released by the `File.open` block.
|
|
56
|
+
|
|
57
|
+
**A launcher that dies mid-run** (chi web or a terminal killed with `KILL`) runs no `ensure`. The runner holds the
|
|
58
|
+
lock too (the flock is shared through fd 3), so the page stays "already running" while it lives, and it ends itself:
|
|
59
|
+
its `DEADLINE` is the timeout + `Launch::GRACE_SECONDS` + `Launch::DEADLINE_MARGIN` (2 s) from its own start, later
|
|
60
|
+
than the launcher's cut, which wins whenever the launcher is alive. At the deadline a thread in the runner records
|
|
61
|
+
the cut itself ("the script was stopped after N s") and KILLs the runner's group. So a killed launcher leaves at most
|
|
62
|
+
one bounded run. A Ruby thread can't fire while a C extension holds the GVL: such a script outlives its deadline
|
|
63
|
+
until the call returns (accepted). The runner's stdout and stderr are pipes whose reader died with the launcher: Ruby
|
|
64
|
+
ignores SIGPIPE, so the script's next output that reaches the pipe (a large one, or `$stdout.sync`) raises
|
|
65
|
+
`Errno::EPIPE`, recorded as the script's failure at that line (the good blocks stay; small output stays buffered and
|
|
66
|
+
only fails at the exit, after the result is written). Accepted: the run stays bounded, only the error's words mislead.
|
|
67
|
+
|
|
68
|
+
`ContextFetch#run_command`, `#wait` and `#stop_group` are the model this follows.
|
|
69
|
+
|
|
70
|
+
## The runner
|
|
71
|
+
|
|
72
|
+
`Runner.run(argv)` (requiring `pages/runner.rb` runs nothing) first makes fd 3 close-on-exec, so the lock is the
|
|
73
|
+
runner's alone: a program the script execs (`spawn`, `system`, backticks), even one that leaves the group and
|
|
74
|
+
outlives the run, never inherits it (it would keep the page "already running" for good). A `fork` without an exec
|
|
75
|
+
(`Process.daemon` too) keeps fd 3 and holds the lock while it lives: the stated limit. A script's own `exec` replaces
|
|
76
|
+
the runner: the lock goes (close-on-exec) and so does the deadline thread; a live launcher still cuts it (it stays in
|
|
77
|
+
the group), but after a dead launcher the exec'd program runs unbounded while the page is runnable again (the same
|
|
78
|
+
limit). It arms the deadline when argv carries one (a write of the result and the deadline's record take one mutex,
|
|
79
|
+
and the write sets a done flag under it, so a result written before the deadline fires is never overwritten), checks
|
|
80
|
+
the
|
|
81
|
+
name and the script, then
|
|
82
|
+
`load(path, dsl)`: the wrap module is a fresh `Module` defining only `page`, so the script's own `def`s land in it, not
|
|
83
|
+
on `Object`. `page(title) { |ui| … }` makes a `Builder`; a second call raises `Refused`. After the load, no `page` call
|
|
84
|
+
fails the run too.
|
|
85
|
+
|
|
86
|
+
It rescues `StandardError`, `ScriptError`, `SystemExit`, `SystemStackError` (endless recursion) and `NoMemoryError` (never a `SignalException`: a TERM is the launcher's cut,
|
|
87
|
+
recorded by the launcher). The line is the first backtrace entry inside the script file (the exact path given to
|
|
88
|
+
`load`), or for a `ScriptError` the `path:LINE:` at the start of its message's first line, which every Ruby gives; the
|
|
89
|
+
message drops that prefix. An `exit 3` is "the script called exit 3". A good run goes through `Store.record_run`, which
|
|
90
|
+
refuses an output over 256 KB (`Refused`, recorded as the failure). Exit 0 ran, 1 the script failed, 2 no such page.
|
|
91
|
+
The result reaches the launcher through the file only: a `puts` in a script corrupts nothing.
|
|
92
|
+
|
|
93
|
+
## The output file
|
|
94
|
+
|
|
95
|
+
`<state>/samagotchi/pages/NAME/output.json`, written with `AtomicFile.write`:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{"name": "usage", "title": "Usage, last 7 days",
|
|
99
|
+
"blocks": [{"type": "text", "text": "…"},
|
|
100
|
+
{"type": "table",
|
|
101
|
+
"columns": [{"key": "model", "label": "Model"},
|
|
102
|
+
{"key": "cost", "label": "Stored", "format": "money", "key_column": true}],
|
|
103
|
+
"rows": [["claude:sonnet-5-5", 14.221]], "total": ["Total", 18.1252], "dropped": 0},
|
|
104
|
+
{"type": "walk", "data": {"title": "…", "actors": ["…"], "steps": ["…"]}}],
|
|
105
|
+
"ran_at": "2026-11-23T10:00:00Z", "duration_ms": 412, "script_sha": "<sha256 of the script that made the blocks>",
|
|
106
|
+
"error": null}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- A failed run rewrites only `error`: `{"message", "line" (Integer or null), "at", "script_sha"}`. The blocks, title,
|
|
110
|
+
`ran_at` and `script_sha` stay those of the last good run, and fields this chi does not know are kept in the file
|
|
111
|
+
(dropped only by `Store.read`). A good run sets `error` to null. `Store.record_failure` is
|
|
112
|
+
the one writer of a failure, for the runner and the launcher alike, always under the page's lock.
|
|
113
|
+
- Before any good run there are no blocks and `ran_at` is null.
|
|
114
|
+
- A table's `format` is stored, not applied: cells stay raw numbers so the page can sort them. `key_column` marks the
|
|
115
|
+
columns a phone shows besides the first (never marked).
|
|
116
|
+
- `Store.read` gives a `Stored`: the fields, `state` (`:never_ran`, `:ok`, `:failed`) and `changed?` (the script's
|
|
117
|
+
sha256 now differs from `script_sha`). "Changed" means only this: the result on screen came from an older script;
|
|
118
|
+
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
|
|
119
|
+
know are dropped on read (a newer chi's file reads fine).
|
|
120
|
+
|
|
121
|
+
## The data entry into InlineWidgets
|
|
122
|
+
|
|
123
|
+
`ui.walk` hands its Hash to `InlineWidgets.check("walk", data)`, the same `Schema` the chat's YAML goes through, so the
|
|
124
|
+
same widget draws it ([inline-widgets.md](inline-widgets.md#the-data-entry)).
|
|
125
|
+
|
|
126
|
+
## chi web
|
|
127
|
+
|
|
128
|
+
**The routes** (`web/page_routes.rb`, `Web::PageRoutes`, its `ROUTES` splatted into `App::ROUTES` on the models row),
|
|
129
|
+
all `:owner`: a participant's token gets 403 `not_permitted` (`participant_gate_spec` sweeps them). The name capture is
|
|
130
|
+
`([^/]+)`, checked with `Pages.valid_name?` before any path is built; a name that breaks the rule is no such page.
|
|
131
|
+
|
|
132
|
+
| Route | Answers |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `GET /api/pages` | `{pages: [{name, title, state, ran_at, failed_at, changed, error_line}]}`, by name (`Store.list`) |
|
|
135
|
+
| `GET /api/pages/NAME` | the page (below); 404 `page_missing` with no script. Runs nothing |
|
|
136
|
+
| `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") |
|
|
137
|
+
| `DELETE /api/pages/NAME` | `Store.remove`: `{removed: NAME}`; 409 `page_busy`, 404 `page_missing` |
|
|
138
|
+
|
|
139
|
+
The page: `{name, title, state, ran_at, duration_ms, changed, changed_after_failure, script_changed_at, error:
|
|
140
|
+
{message, line, at} | null, blocks}`. `changed` is `Stored#changed?`; `changed_after_failure` says the script differs
|
|
141
|
+
from the one that failed (so the page needs no sha); `script_changed_at` is the script's mtime. A text block carries
|
|
142
|
+
`html`, the `MarkdownRenderer`'s sanitised render, when rendering is available (`web.markdown`), else `text` only.
|
|
143
|
+
The error codes' `detail` is the exception's own message.
|
|
144
|
+
|
|
145
|
+
**The capability** `pages` (`Web::Viewer::CAPABILITIES`, never a participant's) makes the view, the group and the link
|
|
146
|
+
handler; without it none is made and no page call goes out (`viewer_boot.test.js`).
|
|
147
|
+
|
|
148
|
+
**The page's modules** (`lib/samagotchi/web/public/`): `page_route.js` (`pageHash`, `pageNameFromHash`, the open rule:
|
|
149
|
+
never a participant's, never without `pages`), `views.js` (reads the page hash before the session intent:
|
|
150
|
+
`body.page-view`, `openPage` / `closePage` / `leavePage`, the session hash not written while a page is open, a session
|
|
151
|
+
picked leaving the page), `page_view.js` (the header, the states, the calls; an answer for a page no longer open is
|
|
152
|
+
dropped, `latest.js`), `page_model.js` (the words: meta, the failed and changed lines, Copy the error), `page_blocks.js`
|
|
153
|
+
(text, walk in a widget host with `drawWalk`, an unknown type as one muted line), `page_table.js` and
|
|
154
|
+
`page_table_model.js` (cells, sort, the phone's rows), `pages_group.js` (All sessions' group), `page_links.js` (the
|
|
155
|
+
delegated click on the turn roots and the page view for `#/p/` anchors), `pages.css`. What a script wrote reaches the
|
|
156
|
+
page as text or attributes, never as markup, except the server's sanitised `html`.
|
|
157
|
+
|
|
158
|
+
**Not live**: no stream event and no polling. A run from a terminal shows on the next open; two tabs are not kept in
|
|
159
|
+
step.
|
|
160
|
+
|
|
161
|
+
## chi's side: the skill
|
|
162
|
+
|
|
163
|
+
What chi knows about pages is one memory, the system bundle's `skill_pages.md` (an index line in every prompt, the
|
|
164
|
+
text read on demand), and the `chi page` line in `self_map.md`. `spec/pages_skill_spec.rb` runs the skill's example
|
|
165
|
+
through `Runner::Collector`'s DSL and pins every command, `ui` call and limit it names to the code; a change to the
|
|
166
|
+
skill's text regenerates the turn goldens (`UPDATE_PROMPTS=1`).
|
|
167
|
+
|
|
168
|
+
The eval behind it (2026-11-23, the local Qwen3.8-Flash-Next, `chi -p … --non-interactive` in isolated dirs, N=5 per
|
|
169
|
+
task): 14 of 15 pages ran and showed the reference numbers, no ask was raised, and the task that doesn't name the
|
|
170
|
+
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
|
|
171
|
+
owner's `~/.claude/plans/evals/0016-pages-skill/`.
|
|
172
|
+
|
|
173
|
+
## Later builds
|
|
174
|
+
|
|
175
|
+
- Not planned yet: picks on a page, a data API (`runtime`), a bundle's pages, parameters.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Peers: the mailbox, the receipts, the mail path
|
|
2
|
+
|
|
3
|
+
The user side is [peers.md](../peers.md). A peer's messages are their own layer, not attached context: a
|
|
4
|
+
context source is "a source with one latest text you can read"; a peer is communication with rules (every
|
|
5
|
+
message kept, in order, each with a receipt). Nothing here is shared with `ContextSources` but its text limits
|
|
6
|
+
and `RE_RE` (a send ref).
|
|
7
|
+
|
|
8
|
+
## The two stores
|
|
9
|
+
|
|
10
|
+
**The peer's side, `<state>/samagotchi/mailbox/<session id>/<peer>/`** (`PeerMailbox`): the only folder a
|
|
11
|
+
sandboxed peer writes, beside the sessions folder and apart from it.
|
|
12
|
+
|
|
13
|
+
- `link.json`: `PeerLink(peer, address, paired_at, from)`; `address` nil: answers only. `chi peer pair` writes it
|
|
14
|
+
whole; `unpair` removes only it.
|
|
15
|
+
- `in/<serial>.json`: `PeerMessage(serial, text, summary, wake, re, at)`, one file per message, written whole
|
|
16
|
+
(`AtomicFile`; its temp name never matches `FILE_RE`).
|
|
17
|
+
- `lock`: the say's, while it picks a serial and writes (`flock`, opened `NOFOLLOW`).
|
|
18
|
+
|
|
19
|
+
No head file: the next serial is `max(the newest file, taken) + 1`, and trim (by the say) removes only files at
|
|
20
|
+
or below `taken`, keeping the newest `TAKEN_KEPT` (50) of them, so a number is never reused and an untaken
|
|
21
|
+
message is never deleted. A forged file with a high serial pushes the next real one above it instead of hiding
|
|
22
|
+
it. No gap limit: a writer of the folder can plant a `SERIAL_MAX` file and use up a peer's serials; the folder's
|
|
23
|
+
writers are trusted that far (they can delete its files too). Every file is checked before it is trusted
|
|
24
|
+
(`PeerMessage.from_file`): its name a serial, a regular file (`lstat`, `NOFOLLOW`), its size under
|
|
25
|
+
`FILE_MAX_BYTES` before it is read, the serial in it its name's, the field types, the summary already one line.
|
|
26
|
+
A bad file is a `BadFile` with its reason. A directory link is never followed: a linked peer folder isn't
|
|
27
|
+
listed, `serials` reads a linked folder as empty and `post` refuses one.
|
|
28
|
+
|
|
29
|
+
**chi's side, `sessions/<id>/peer_receipts.json`** (`PeerReceipts`), written only by the session's worker, on
|
|
30
|
+
its loop thread: `{peers: {<peer>: {box, taken, receipts}}}`, `Receipt(serial, state, reason, turn, outcome,
|
|
31
|
+
at)`. `box` is 6 random hex the worker mints (and writes at once) with a peer's first message; `taken` is the
|
|
32
|
+
newest serial it took. The CLI and chi web only read it.
|
|
33
|
+
|
|
34
|
+
`SessionStores` rows: `link.json`, `in/`, `lock` (removal `:peer_mailbox`: a delete removes the session's
|
|
35
|
+
mailbox folder) and `peer_receipts.json` (`:session_files`); a continue leaves all of them with the previous
|
|
36
|
+
link (below).
|
|
37
|
+
|
|
38
|
+
## Who is a peer
|
|
39
|
+
|
|
40
|
+
- **The worker:** `PeerRegistry`, filled by `chi.peer NAME` (`Plugin::Api#peer`, staged until the plugin's
|
|
41
|
+
register returns). It alone decides that a mailbox message becomes a peer's note and may wake. A name no
|
|
42
|
+
loaded bundle declared gets a `refused` receipt (`undeclared`) and `taken` doesn't move, so it is delivered
|
|
43
|
+
once the bundle loads.
|
|
44
|
+
- **The CLI and chi web:** "paired" means `link.json` exists; they decide no behaviour.
|
|
45
|
+
- **The label** is `PeerMailbox.label(name)`, the name capitalised, in every process.
|
|
46
|
+
|
|
47
|
+
`chi.peer_source` is a method that raises "chi.peer_source is gone: upgrade this bundle (chi bundle install
|
|
48
|
+
<name> --force)", so an installed older peer bundle fails to load (`Plugin::Loader` records the failure) and chi
|
|
49
|
+
starts without it.
|
|
50
|
+
|
|
51
|
+
## The say
|
|
52
|
+
|
|
53
|
+
`chi peer say` (`PeerCommand`) → `SessionAccess::Local#peer_say` (`RemotePeers#peer_say` through `--remote`,
|
|
54
|
+
which posts `…/peers/NAME/say` with its `wait`: chi web waits, and its read timeout is the wait plus 30 s).
|
|
55
|
+
|
|
56
|
+
1. Refused before anything is written: no session, continued (with the next id), no `link.json`, a live worker
|
|
57
|
+
without the `peer_mail` Bridge feature (`WorkerLink.live_features`, read only), `UNTAKEN_MAX` (200) untaken
|
|
58
|
+
messages or noted receipts.
|
|
59
|
+
2. `SessionInbox.deliver(:peer)` (`WakePolicy::ROWS[:peer]`, the push row; `START_EVENTS[:peer] =
|
|
60
|
+
:peer_woke_session`): a session gone or being deleted refuses before its block writes. Inside the block:
|
|
61
|
+
the lock, the serial, the write, the trim. The block's "asks for a worker" is the message's own `wake`: no
|
|
62
|
+
`context.wake`, no 10-minute window.
|
|
63
|
+
3. The line (`PeerSay`): what the say saw at once (a running turn, a stopped or archived session, a one-turn run,
|
|
64
|
+
a failed start), else a receipt read every 250 ms within the wait, then the peer's other held receipts.
|
|
65
|
+
|
|
66
|
+
`chi peer pair` makes the old-worker and continued checks too, with the same sentences (`PeerPaired`).
|
|
67
|
+
|
|
68
|
+
## The worker's mail path
|
|
69
|
+
|
|
70
|
+
`WorkerInbound#absorb_mail(hold:)` (`worker_inbound/mail.rb`), a fourth inbound kind, from `Worker#pass` (before
|
|
71
|
+
`absorb_context`), `run_prompt`'s before-turn absorb and `Worker#left`; never in a one-shot run. `hold:` names
|
|
72
|
+
why a wake can't run: `:queued`, `:exit`, `:leaving`, `:before_turn` (nil: it may).
|
|
73
|
+
|
|
74
|
+
- **Change detection:** names and mtimes of each `<peer>/in`, each pass.
|
|
75
|
+
- **Which folders:** every `<peer>/in`, whatever its `link.json` (the link gates the say only).
|
|
76
|
+
- **Order:** by `at`, then peer name, then serial. One note each: id `peer-<name>-<box>-<serial>` (the box keeps
|
|
77
|
+
a fork's seed notes from hiding its own third message), source `peer <Label>`, the `peer` hash (`PeerNote.payload`
|
|
78
|
+
plus `box`), its text by `PeerNote.body` (a wake note up to the tool output cap, a plain one up to
|
|
79
|
+
`PeerNote::HELD_CHARS`; over it, `PeerNote.message_text` points at `<peer>_read(serial: N)`).
|
|
80
|
+
- **Wake:** the batch wakes when a message in it asked, `peer.turns` is above 0 (else `held: off`), the caller
|
|
81
|
+
gave no `hold:` and `WorkerWakes#wake_hold(peer: !agreed)` is nil. The turn starts at the batch's last note;
|
|
82
|
+
its wake line, its origin (`peer:<name>`, `ClientId::PEER_PREFIX`) and the count come from the newest message
|
|
83
|
+
that asked; an agreeing one (`VERDICT OK`) counts toward `session.max_wakes` only. In the start grace nothing
|
|
84
|
+
is taken and `mail_wake_waiting?` joins `idle_wait`'s check.
|
|
85
|
+
- **Order of writes:** the notes, the session save, then the receipts (`PeerReceipts#absorbed`). A crash between
|
|
86
|
+
the save and the receipts: the next pass finds the notes already there (ids dedupe); a turn-start note with no
|
|
87
|
+
receipt is put back plain, wakes pause and its receipt is `held: paused`; no second wake turn. A batch with a
|
|
88
|
+
note already in the conversation doesn't wake.
|
|
89
|
+
- **An unreadable file** (a transient read error) raises and the batch retries on the next pass; a bad file's
|
|
90
|
+
contents are refused as `invalid` and move `taken`.
|
|
91
|
+
- **The wake turn:** `MailWake(peer, turn_id, plain_note, agreed)`, run by `WakeTurnsPart#run_mail_wake_turn`
|
|
92
|
+
through `run_wake`. The one-time hook notice for a held message (`WorkerInbound#peer_held`) is the TUI's and
|
|
93
|
+
the web's.
|
|
94
|
+
|
|
95
|
+
## The receipts' three calls
|
|
96
|
+
|
|
97
|
+
`PeerReceipts` (loop thread only):
|
|
98
|
+
|
|
99
|
+
- `absorbed(batch, waking:, hold:)`: `woke` (+ the turn id) for each message that asked in a waking batch;
|
|
100
|
+
`held` + reason for one that asked in a batch that doesn't; `noted` for one that didn't ask; `refused`
|
|
101
|
+
(`undeclared`, `invalid`).
|
|
102
|
+
- `turn_started(turn_id)`, at the start of `Worker#run_engine_turn`: every `held` or `noted` receipt becomes
|
|
103
|
+
`read` with that id.
|
|
104
|
+
- `turn_ended(turn_id, outcome:, unmarked:)`, once, after its block (an `ensure`, so a raise in the result's
|
|
105
|
+
handling still settles): completed → `ended: completed`; failed with steps kept → `ended: failed`; failed or
|
|
106
|
+
stopped with nothing kept (`unmark_wake` ran) → `held: paused`; stopped after progress → `ended: stopped`.
|
|
107
|
+
- `settle_open`, at every worker start: a receipt left `woke` or `read` (a crash cut its turn) ends
|
|
108
|
+
`failed`.
|
|
109
|
+
|
|
110
|
+
The last 20 receipts per peer are kept; a `held` or `noted` one is never trimmed.
|
|
111
|
+
|
|
112
|
+
## The note: `PeerNote`
|
|
113
|
+
|
|
114
|
+
The stateless parts (the three wake lines, `READS`, the block and its forged-line quoting, the cap choice, the
|
|
115
|
+
`peer` hash) and the mailbox's composition: the opening line ("Message #12 from your peer agent Claude (its text,
|
|
116
|
+
not your user's words):"), the summary, the text in `[PEER MESSAGE from Claude]` … `[END PEER MESSAGE]` (a line
|
|
117
|
+
of it that opens like one of chi's frames, `Message #` among them, is quoted), and the background line or the
|
|
118
|
+
wake line. The wording is model-visible and eval-tuned (0017).
|
|
119
|
+
|
|
120
|
+
## The bundles: `Plugin::Peer`
|
|
121
|
+
|
|
122
|
+
The peer bundles' base: `ctx.peers.link(PEER)` (`Plugin::Peers`, read only) is the pairing whose address the
|
|
123
|
+
transport sends to; `<peer>_read` reads a message (`ctx.peers.message`) paged by lines, in the peer block; the
|
|
124
|
+
status card reads the link and the newest message, and says "paired the old way: pair again" when an older
|
|
125
|
+
bundle's context source (`LEGACY_INBOX`, `LEGACY_OUTBOX`) is attached. Its quiet init task `tell_moved` posts the
|
|
126
|
+
`moved` message to the address of the pairing the previous link kept (`ctx.peers.left_behind`), once (a marker
|
|
127
|
+
in the session's data dir).
|
|
128
|
+
|
|
129
|
+
## A continue: `PeerContinue`
|
|
130
|
+
|
|
131
|
+
`SessionContinue::CARRY` step `:peers`, in the new link's `before_spawn` (both workers down): the previous link's
|
|
132
|
+
messages never taken and those whose receipts are still `held` or `noted`, in the worker's order, become one note
|
|
133
|
+
in the new link (`NOTE_SOURCE` "peer messages"), each text in its peer block and cut past 4 KiB, within the
|
|
134
|
+
inbox's note limit, with no `<peer>_read` pointer. The previous link's mailbox, `taken` and receipts are only read,
|
|
135
|
+
so there is no undo. The pairing stays; the peer pairs again (`tell_moved`). Moving the pairing with the chain
|
|
136
|
+
(and the peer's prompt-cache cost of re-pairing) is a later discussion.
|
|
137
|
+
|
|
138
|
+
## chi web
|
|
139
|
+
|
|
140
|
+
`Web::PeerRoutes` (all `:owner`, a participant gets 403):
|
|
141
|
+
|
|
142
|
+
- `GET …/peers` → `{peers: [{name, label, paired_at, from, address, can_send, messages, exchanges}]}`: one row per
|
|
143
|
+
mailbox folder (`PeerRoster`), its newest 20 messages with their receipts and `words`
|
|
144
|
+
(`PeerRoster.state_words`), and `exchanges` (`PeerExchanges.joined` over chi's sends and the messages as answer
|
|
145
|
+
lines). No text.
|
|
146
|
+
- `GET …/peers/NAME/messages/SERIAL` (the text and its receipt); `DELETE …/peers/NAME` (Unpair); `POST
|
|
147
|
+
…/peers/NAME/pair` and `…/say` (the remote's; the say waits here).
|
|
148
|
+
|
|
149
|
+
The page's peer chip is fed by `GET …/peers` alone ([web-frontend.md](web-frontend.md), The peer exchange).
|
|
@@ -532,7 +532,10 @@ the closing line reads `stopped` as `unreachable`, the words it always had.
|
|
|
532
532
|
"could not send", yet ran: sending it again runs it twice (no idempotency key yet).
|
|
533
533
|
|
|
534
534
|
- Through a remote the pair scripts (`bundles/{claude,codex}-peer/scripts/pair`) detect `CHI_REMOTE` or `--remote` in
|
|
535
|
-
`CHI` the way Dispatch does, and
|
|
536
|
-
thread, so chi's replies reach Claude only when relayed
|
|
537
|
-
|
|
538
|
-
|
|
535
|
+
`CHI` the way Dispatch does, and pair with no address (answers only): chi there can't reach this machine's Claude
|
|
536
|
+
socket or Codex thread, so chi's replies reach Claude only when relayed (claude-peer's `pair-remote` forwards the
|
|
537
|
+
socket over SSH instead). `chi peer say` through a remote posts `…/peers/NAME/say` with its `wait`: chi web waits
|
|
538
|
+
for the receipt and returns the line (`RemotePeers`, a read timeout of the wait plus 30 s); an older chi web's 404
|
|
539
|
+
is "chi web on <remote> is older: it has no chi peer".
|
|
540
|
+
- The peer skills (`skill_claude_peer`, `skill_codex_peer`) have no remote recipe. The `/claude` card says "paired for
|
|
541
|
+
answers only" for an answers-only pairing.
|
|
@@ -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
|
|
@@ -35,9 +35,9 @@ the next release (its baseline refresh) for the same reason, marked as kept for
|
|
|
35
35
|
sheet still keeps `isChained` and `format.js deleteConfirmText` that way; and `ws_peek.js`'s `PEEK_WIDTH`, which 0.183.0's
|
|
36
36
|
`working_set_view.js` imports though the view is 520 wide always now: `ws_part_peek_mixed_cache.test.js` loads this view
|
|
37
37
|
with 0.183.0's `ws_reader.js` and `ws_peek.js`, and 0.183.0's view with this `ws_reader.js`, from
|
|
38
|
-
`spec/web/public/fixtures/v0.183.0/`). `answer_fold.js`, `details_motion.js`,
|
|
38
|
+
`spec/web/public/fixtures/v0.183.0/`). `answer_fold.js`, `quiet_notes.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), `peer_mailbox_api.js` (the chip's message and Unpair calls), `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,15 +58,30 @@ 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
|
-
| **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) |
|
|
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`), the notes rows over a stretch of background items (`.quiet-notes`, open by its `open` class, the items `.quiet-hidden`; never stored), 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`, `quiet_notes.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`, `quiet_notes.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 |
|
|
65
65
|
| **The cards as data** (`card_registry.js`; app.js `cardRegistry`) | every question, continue offer and plugin card of the open session, keyed as `stage_waiting.js` keys them (`q:<id>`, `c:<id>`, `continue`): its kind and folded text (`card_kinds.js`), status (pending, answered, cancelled; resolved or dropped for the continue offer; asks or shown for a plugin card), `of_turn`, `opening_id`, step, `relayed_to` | `observeCards` around the stream handlers (outside the participant wrap: the page's handler first, then `apply`), so a read's replay feeds it too; `session_view.js renderSessionView` seeds it from the read right before the replay (`seed`: CardStore's listing, the pending question, the continue offer; it replaces), `forgetSession` resets it. Idempotent: a merge per key, a final status never back to pending, the first `of_turn`/`opening_id`/step kept, so seed then replay is what live holds. A question still pending at its turn's end is cancelled (the page cancels the card, no event comes) | an observer: nothing on the page draws from it; its one reader is the opt-in reload check (`reload_check.js`: this turn's entries against a registry seeded from a fresh read). `stage_cuts_parity.test.js` checks it against the stage's waiting cards at each cut, `card_registry.test.js` the events against each cut's seed and replay |
|
|
66
66
|
| **What was opened of a running turn** (`stage_view_memory.js`, in `session_view.js`) | per session, for this tab: the cloud open, the steps opened in it, the working set's reader on an item; a Map of at most 20 sessions, nothing stored or sent (the peek isn't kept: it closes with its popover) | `session_view.js leaveSession`, from `session_sync.js select` and from `forgetSession` itself for the session it drew last (so the start page, `clearSelection`, keeps it too) before its reset (`captureView`); dropped by `endTurnView` | `renderSessionView`, once the read is drawn: put back (`applyView`) only when the read's running turn (`current_turn.turn_id`) is the one saved; taken either way |
|
|
67
67
|
| **localStorage** (`storage.js` `readStored`/`writeStored`, guarded) | per-browser choices only; a session's view settings per session (`session_prefs.js`) | the module that owns the choice | read at start, a session's view settings again when its view is drawn (see Storage keys) |
|
|
68
68
|
| **SSE** | see Streams | the server | events go into the DOM directly (a participant's through `participant_main.js wrapHandlers` first) |
|
|
69
69
|
|
|
70
|
+
**The notes rows** (`quiet_notes.js`): what nobody says in the conversation folds, so a phone shows the prompt and
|
|
71
|
+
the answer, not the background under them. A stretch is a run of `#history` children that match `QUIET` (a
|
|
72
|
+
`.bubble.hook-notice` but the empty-answer line, a `.bubble.note` that is neither a wake's opening `.turn-start` nor a
|
|
73
|
+
`.peer-answer`, so objectives lines too, and a `.bubble.steer-row`); the `.turn-timing` line passes through it, and
|
|
74
|
+
anything else ends it (a prompt, an answer, a card, a peer's answer, a time divider, another fold's row). Each stretch
|
|
75
|
+
gets one `<button class="quiet-notes">` before its first item, closed, and its items get `.quiet-hidden`. The row is a
|
|
76
|
+
sibling tied to its first item (WeakMaps, as `answer_fold.js`'s), not a wrapper: the bubbles stay direct children of
|
|
77
|
+
`#history`, where every walker (`turn_range.js`, `cards_place.js`, the stage's hand-off, the reload check) and the
|
|
78
|
+
other observers expect them; a row something was placed after goes back before its item and keeps its open class.
|
|
79
|
+
A between-turn notice is placed after its turn, not below the next divider (`cards_place.js afterTurnEnd`). Its one
|
|
80
|
+
observer watches `#history`'s own children, and a settle writes only what changed (the copy, answer-fold,
|
|
81
|
+
Revise and objectives observers see class and subtree writes). `revise_stack.js historyTurns`, `history_shape.js
|
|
82
|
+
childItems` and `bubbles.js showRecap`'s walk skip the rows, and `history_reveal.js revealInHistory` opens one over a
|
|
83
|
+
jump's target.
|
|
84
|
+
|
|
70
85
|
The objectives' strip keeps the list in its own closure (`objectives_strip.js`, seeded by `renderSessionView`, reset by
|
|
71
86
|
`forgetSession`, updated by `objectives_updated`): [objectives.md](objectives.md#the-page).
|
|
72
87
|
|
|
@@ -263,6 +278,7 @@ gates are boot-time: a show's narrower `viewer` changes what `viewer.can` answer
|
|
|
263
278
|
| `block_renderers` | a bundle's drawn blocks (the core `chi-ui` drawer stays) | `/api/block_renderers*` |
|
|
264
279
|
| `stop_any_turn` | the stage's Stop turn (`onCancel`) | `POST …/cancel` |
|
|
265
280
|
| `steer_any_turn` | none: the delivery line reads a participant's own `steer_own_turn` instead (`viewerTurn`) | |
|
|
281
|
+
| `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
282
|
|
|
267
283
|
A participant's `can` (`Viewer::PARTICIPANT_CAPABILITIES`, in their show's `viewer` and on `<body>`) names
|
|
268
284
|
capabilities of their own, not the owner's: `send` (the composer), `stop_own_turn` (Stop turn on a turn they
|
|
@@ -492,7 +508,7 @@ kept: every open starts fitted.
|
|
|
492
508
|
- **It closes by itself**, whatever it shows, on a system theme change (the diagram behind is redrawn; the viewer
|
|
493
509
|
holds the old picture; `diagram_wiring.js`), on a switch to another session or the start page (`session_view.js
|
|
494
510
|
forgetSession`, given `pictures`; the same session again keeps it) and when the all-sessions view opens (it hides
|
|
495
|
-
`#center`, the viewer's parent;
|
|
511
|
+
`#center`, the viewer's parent; `views.js applyView`). A bubble rewritten or cloned while it is open leaves it as it
|
|
496
512
|
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
513
|
`aria-modal`, `#center`'s other children aren't made `inert`.
|
|
498
514
|
- index.html keeps `<div id="lightbox" hidden><img alt=""></div>`: an older cached app.js reads that `<img>`. The
|
|
@@ -835,39 +851,45 @@ rendered slice (no `.read-line` in it).
|
|
|
835
851
|
## The peer exchange
|
|
836
852
|
|
|
837
853
|
A send to a paired peer (claude-peer's `claude_send`, codex-peer's) and the peer's answer, linked in the owner's
|
|
838
|
-
conversation ([bundles.md](../bundles.md#the-claude-peer-bundle), In the web
|
|
839
|
-
/api/sessions/:id/peers` (owner only, read from the session's files:
|
|
840
|
-
|
|
841
|
-
`
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
854
|
+
conversation ([bundles.md](../bundles.md#the-claude-peer-bundle), In the web; the store: [peers.md](peers.md)). The
|
|
855
|
+
data is the server's: `GET /api/sessions/:id/peers` (owner only, read from the session's files without a worker: the
|
|
856
|
+
mailbox, the receipts and `PeerExchanges.joined` over `peer_exchanges.jsonl`) gives each peer with a mailbox folder,
|
|
857
|
+
its pairing (`paired_at`, `address`, `can_send`), its newest messages with their receipts and the receipt's words
|
|
858
|
+
(`words`: "held · peer turns"), and its last exchanges, newest first, with their `state` (waiting, answered,
|
|
859
|
+
none_expected, failed) and an answer's `serial` and `verdict`; a send row carries the send's id as its `peer` ref, a
|
|
860
|
+
peer's message note its `peer` hash (`peer`, `label`, `re`, `summary`, `serial`, `verdict`, `agreed`, `box` for a
|
|
861
|
+
mailbox message, and `inline` when the note's content holds the peer's text). The page joins nothing; the one parse is
|
|
862
|
+
`peer_text.js`'s cut of an `inline` note's text block.
|
|
845
863
|
|
|
846
864
|
- `peer_data.js` (state): `listPeers` (an older chi web's 404 is an empty list) and `createPeers`, the page's one model
|
|
847
865
|
of the open session's peers (app.js `peers`, made only with the `context` capability, so a participant's page has
|
|
848
866
|
none): its own closure holds the last read for the open session (`createLatest`: an older read, or one for a
|
|
849
|
-
session left, is dropped); `exchange(id)` (the newest of an id: each send has its own, but an older chi's resend shared one), `answer(name, serial, re)`. It
|
|
850
|
-
|
|
867
|
+
session left, is dropped); `exchange(id)` (the newest of an id: each send has its own, but an older chi's resend shared one), `answer(name, serial, re)`, `peers()`. It
|
|
868
|
+
is the peer chip's only feed, so the page reads it for every session it opens (`hasPeer: () => true`).
|
|
851
869
|
Read again on: the session drawn (`session_view.js renderSessionView`, through `peerLinks.drawn()`), a
|
|
852
870
|
`context_added` with `peer`, a `tool_call_completed` with a peer ref, `command_ran` (a `/claude validate`), window
|
|
853
871
|
focus, and a 60 s tick while an exchange waits; a `turn_completed` redraws without a fetch (`touch()`) (one interval, cleared with the session: `forgetSession` →
|
|
854
872
|
`peerLinks.reset()`). The peer chips read the same model: its `onChange` also calls `contextChips.peersChanged()`, and
|
|
855
|
-
the chips' own load (a session opened
|
|
856
|
-
|
|
873
|
+
the chips' own load (a session opened) calls `peers.refresh({ reuse: true })`. A pairing made from the peer's side
|
|
874
|
+
sends the page nothing: the chip appears at the next read (a focus, a peer note, a send).
|
|
875
|
+
- `peer_mailbox_api.js` (state): `getPeerMessage(id, name, serial)` (a message's text: View latest answer, a
|
|
876
|
+
mailbox note's "Read the full answer") and `unpairPeer(id, name)` (`DELETE …/peers/NAME`).
|
|
857
877
|
- `peer_exchange.js` (pure): `peerRef(row)`, `stateText` (long and the phone's short words, both drawn; CSS picks),
|
|
858
878
|
`pillTemplate` (a button with ↓ once answered, a span otherwise; its title the row's output text).
|
|
859
879
|
- `peer_note.js`: `peerNoteTemplate`, which `turn_html.js noteBubbleTemplate` draws a note with `peer` as. It keeps
|
|
860
880
|
what an opening note has (`bubble note`, `turn-start`, `data-opening-id`, the time title), so `TURN_PROMPT`,
|
|
861
881
|
`card_stamps.js`, `stage_handoff.js OPENING`, `reload_check.js` and `revise_stack.js` (its `.note-text` is the
|
|
862
|
-
summary) read it as any wake note.
|
|
882
|
+
summary) read it as any wake note. A live `context_added` wake note carries `turn_start`/`turn_id`, so live and reload
|
|
883
|
+
agree on its opening. With `peer.inline` the peer's text goes in `.peer-text` under the summary (an
|
|
863
884
|
element of its own, not a `data-peer-slot`, its source in `data-peer-md`): already as markdown when a history
|
|
864
|
-
read sent the note's `peer_html` (`MessageDisplay#peer_text_html`, `
|
|
885
|
+
read sent the note's `peer_html` (`MessageDisplay#peer_text_html`, `PeerNote.text_of`, rendered and
|
|
865
886
|
sanitized as an answer is), else as plain text (a live `context_added`, an older server), the "what chi told the
|
|
866
887
|
agent" fold shows the content without the block, and the bubble carries `data-peer-inline`. Without it (an older
|
|
867
|
-
session,
|
|
888
|
+
session, a message over the cap) the bubble draws as before. A mailbox message's note (its hash has `box`) carries
|
|
889
|
+
`data-peer-box` and no source; an older context answer's keeps its `<peer>-outbox` source as `data-peer-source`.
|
|
868
890
|
- `peer_text.js` (pure): `peerBlock(content)` cuts the text out between the first `[PEER MESSAGE from …]` line and the
|
|
869
|
-
last `[END PEER MESSAGE]` line and undoes the
|
|
870
|
-
(`PEER_FORGED_OPENINGS` and `PEER_FORGED_LINES`, the Ruby `
|
|
891
|
+
last `[END PEER MESSAGE]` line and undoes the `PeerNote.block` mark on forged frame lines
|
|
892
|
+
(`PEER_FORGED_OPENINGS` and `PEER_FORGED_LINES`, the Ruby `PeerNote::FORGED_OPENINGS` and `FORGED_LINES`, and the same line breaks and leads
|
|
871
893
|
as `Steer::FORGED_BREAKS` / `FORGED_LEAD`: `peer_text.test.js` keeps the lists alike and undoes the Ruby specs' cases);
|
|
872
894
|
null without a block.
|
|
873
895
|
- **The slot idiom.** Finished rows are never drawn again and a reload makes them anew, so what arrives later is
|
|
@@ -880,30 +902,33 @@ parse is `peer_text.js`'s cut of an `inline` note's text block.
|
|
|
880
902
|
sent" when its row failed, or once its turn has ended when its peer's list is under the server's cap of 20
|
|
881
903
|
(`EXCHANGES_CAP`) or holds a send drawn before it; else it is unknown and gets no pill, as are the sends of a peer
|
|
882
904
|
the read doesn't name), the ↑ into each answer (none for an answer no send claims) and "Read the full
|
|
883
|
-
answer" into
|
|
905
|
+
answer" into each mailbox message, and into the last of an older pairing's answers of each source, unless that
|
|
906
|
+
bubble is `data-peer-inline` (its text is there). It
|
|
884
907
|
also swaps a plain inline bubble's `.peer-text` (not `.markdown`: one that came with `peer_html` asks nothing) for
|
|
885
908
|
its markdown (`renderMarkdown`, POST /api/render, sanitized there; an
|
|
886
909
|
optional factory dep, so a cached older app.js leaves the text plain), once per element; `history_shape.js` reads a
|
|
887
910
|
`[data-peer-md]` element as its source, so live and an offscreen reload compare alike. Its one delegated click handler on the turn roots does the jumps,
|
|
888
911
|
buttons, never an `href` (the page routes by its hash): ↓ `revealInHistory` + `scrollIntoView` on the answer; ↑
|
|
889
912
|
`refs.js showRow` on the last row of that id before the answer (its `ref:reveal` opens a folded step or the stage's
|
|
890
|
-
cloud); focus moves to the target (`tabindex="-1"`). "Read the full answer" calls `context_chips.js
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
chip, the first state that applies: answers only (
|
|
897
|
-
`
|
|
898
|
-
newest validate/question `waiting`, its age the send's), answered
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
and
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
the
|
|
913
|
+
cloud); focus moves to the target (`tabindex="-1"`). "Read the full answer" calls `context_chips.js
|
|
914
|
+
showMessage(name, serial)` for a mailbox message (its peer chip's popover on that message's text) or
|
|
915
|
+
`showText(source)` for an older answer (that source's own chip), in a task of its own (the click's way to the
|
|
916
|
+
document would close it).
|
|
917
|
+
- `peer_chip.js` (pure): a paired peer in the session bar. `peerGroups(peers)` gives one group per peer of the
|
|
918
|
+
model that is paired (`paired_at`; an unpaired one keeps its messages but has no chip): `{key: "peer:<name>", name,
|
|
919
|
+
label, peer}`. `peerChipModel` is the chip, the first state that applies: answers only (`can_send` false: a pairing
|
|
920
|
+
with no address), can't send (the newest send `failed` and the pairing not renewed since, `paired_at` past the failed
|
|
921
|
+
send's time ends it, `cantSend`), waiting (the newest validate/question `waiting`, its age the send's), answered
|
|
922
|
+
(its newest message unread: no receipt, `held` or `noted`; with the dot), paired. A peer the read doesn't name, an
|
|
923
|
+
older chi web or a send not in the list is never "can't send": only the server's `failed` is. `peerPopoverTemplate`
|
|
924
|
+
is its popover (scene 2 of the design): where chi sends (the address), how it answers, the last 8 exchanges (sends,
|
|
925
|
+
and messages no send claims as `#N · summary`) with `exchangeState`'s words and the answer's receipt words, View
|
|
926
|
+
latest answer, Status card (`peerStatusCommand`: `/<name>` when the session lists it) and Unpair.
|
|
927
|
+
`context_chips.js` draws it: its chips are keyed (`data-name`: a source's name, a peer's `peer:<name>`), peer chips
|
|
928
|
+
first; context rows are never grouped (a `claude-outbox` source is an ordinary chip); an open popover stays while its
|
|
929
|
+
key is among the drawn chips; View latest answer reads the newest message (`api.message`), Unpair confirms once,
|
|
930
|
+
`DELETE`s the pairing and reads the peers again (the chip goes; a failure names itself in a toast); after a detach
|
|
931
|
+
or Unpair that took the focused chip, focus goes to the strip's first chip, else the composer (`focusAway`); an
|
|
907
932
|
exchange row is a button only when its send's row is drawn (`peerLinks.hasSend`) and jumps there
|
|
908
933
|
(`peerLinks.showSend`) after closing the popover. Under 600 px the peer popover is a bottom sheet (`sheetPlace`);
|
|
909
934
|
ordinary chips' popovers stay at their chip.
|