samagotchi 0.187.0 → 0.189.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 +96 -1
- data/bin/chi +2 -0
- data/docs/architecture.md +13 -7
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +139 -120
- data/docs/cli.md +46 -8
- data/docs/configuration.md +4 -4
- data/docs/context.md +18 -162
- data/docs/guardrails.md +6 -3
- data/docs/hooks.md +2 -1
- data/docs/internals/attached-context.md +19 -37
- data/docs/internals/bridge.md +1 -0
- data/docs/internals/bundles.md +3 -3
- data/docs/internals/engine.md +2 -2
- data/docs/internals/llm-context-forget.md +5 -6
- data/docs/internals/objectives.md +1 -0
- data/docs/internals/pages.md +71 -21
- data/docs/internals/peers.md +149 -0
- data/docs/internals/remote-sessions.md +7 -4
- data/docs/internals/session-lifecycle.md +19 -6
- data/docs/internals/web-frontend.md +63 -39
- data/docs/internals/web-push.md +12 -6
- data/docs/memory.md +1 -1
- data/docs/pages.md +70 -16
- data/docs/peers.md +144 -0
- data/docs/plugins.md +77 -28
- data/docs/releasing.md +1 -1
- data/docs/scheduling.md +71 -8
- data/docs/sessions.md +12 -8
- data/docs/sub-agent.md +5 -5
- data/docs/testing.md +1 -1
- 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/bundle_manifest.rb +34 -5
- 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/schedules/manifest.yml +11 -0
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +159 -0
- 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 +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +2 -2
- data/lib/samagotchi/bundles/system/skill_pages.md +9 -4
- 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 +11 -3
- data/lib/samagotchi/installed_bundles/manifest.rb +8 -1
- data/lib/samagotchi/log_line.rb +1 -1
- data/lib/samagotchi/memory_bundle/asset_installer.rb +3 -2
- data/lib/samagotchi/memory_bundle/builder.rb +1 -0
- data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
- data/lib/samagotchi/note_move.rb +3 -1
- data/lib/samagotchi/page_command.rb +25 -13
- data/lib/samagotchi/pages/builder.rb +7 -8
- data/lib/samagotchi/pages/bundled.rb +83 -0
- data/lib/samagotchi/pages/launch.rb +22 -4
- data/lib/samagotchi/pages/runner.rb +7 -2
- data/lib/samagotchi/pages/runtime.rb +83 -0
- data/lib/samagotchi/pages/store.rb +29 -7
- data/lib/samagotchi/pages.rb +47 -3
- data/lib/samagotchi/peer_command.rb +192 -0
- data/lib/samagotchi/peer_continue.rb +105 -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 -2
- data/lib/samagotchi/schedule_command.rb +88 -39
- data/lib/samagotchi/schedule_display.rb +101 -0
- data/lib/samagotchi/schedules/busy_part.rb +146 -0
- data/lib/samagotchi/schedules/edit_part.rb +120 -0
- data/lib/samagotchi/schedules/history_part.rb +51 -0
- data/lib/samagotchi/schedules/listing_part.rb +52 -0
- data/lib/samagotchi/schedules/notices_part.rb +116 -0
- data/lib/samagotchi/schedules/protection_part.rb +103 -0
- data/lib/samagotchi/schedules/recurrence.rb +103 -0
- data/lib/samagotchi/schedules.rb +134 -330
- data/lib/samagotchi/session_access/contract.rb +18 -1
- data/lib/samagotchi/session_access/local.rb +140 -14
- data/lib/samagotchi/session_access/remote.rb +6 -3
- data/lib/samagotchi/session_access/remote_peers.rb +75 -0
- data/lib/samagotchi/session_chain/delete.rb +7 -5
- data/lib/samagotchi/session_continue.rb +12 -0
- data/lib/samagotchi/session_inbox_delivery.rb +5 -2
- data/lib/samagotchi/session_lifecycle/allowed.rb +2 -1
- data/lib/samagotchi/session_lifecycle.rb +3 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -3
- data/lib/samagotchi/session_manager/removal.rb +18 -9
- data/lib/samagotchi/session_manager/spawn.rb +2 -1
- data/lib/samagotchi/session_manager.rb +1 -0
- data/lib/samagotchi/session_protection.rb +99 -0
- data/lib/samagotchi/session_retention.rb +21 -6
- data/lib/samagotchi/session_stores.rb +17 -0
- data/lib/samagotchi/sessions_command.rb +4 -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 +17 -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/cancel_schedule.rb +5 -2
- data/lib/samagotchi/tools/context_read.rb +0 -14
- data/lib/samagotchi/tools/list_schedules.rb +8 -3
- data/lib/samagotchi/turn_outcome.rb +41 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +2 -13
- data/lib/samagotchi/web/message_display.rb +4 -2
- data/lib/samagotchi/web/page_routes.rb +13 -8
- data/lib/samagotchi/web/peer_routes.rb +133 -0
- data/lib/samagotchi/web/public/app.js +23 -29
- 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 +24 -2
- data/lib/samagotchi/web/public/notify.js +1 -1
- data/lib/samagotchi/web/public/owner_claim.js +7 -5
- data/lib/samagotchi/web/public/page_links.js +1 -1
- data/lib/samagotchi/web/public/page_view.js +10 -6
- data/lib/samagotchi/web/public/pages.css +9 -2
- data/lib/samagotchi/web/public/pages_group.js +21 -19
- data/lib/samagotchi/web/public/pages_list.js +73 -0
- data/lib/samagotchi/web/public/pages_model.js +54 -0
- data/lib/samagotchi/web/public/pages_wiring.js +66 -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 +77 -23
- data/lib/samagotchi/web/push/attention.rb +3 -2
- data/lib/samagotchi/web/push/notifier.rb +4 -3
- data/lib/samagotchi/web/server.rb +3 -1
- data/lib/samagotchi/web/session_access_routes.rb +3 -20
- data/lib/samagotchi/web/session_hub.rb +64 -19
- 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 +35 -2
- data/lib/samagotchi/peer_sources.rb +0 -58
data/docs/internals/pages.md
CHANGED
|
@@ -6,16 +6,44 @@ The user side is [pages.md](../pages.md). This is how a run happens and what it
|
|
|
6
6
|
|
|
7
7
|
| File | What |
|
|
8
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` |
|
|
9
|
+
| `lib/samagotchi/pages.rb` | `Pages`: the limits, the name rule (`check_name!`, the one check before any path), the folders, the resolver (`script_path`, `user_script_path`, `bundled`), the errors (`Refused`, `BadName`, `Missing`, `FromBundle`, `Busy`, each owning its message), the values `Stored` and `Failure` |
|
|
10
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` |
|
|
11
|
+
| `pages/store.rb` | `Store`: read, list, `record_run`, `record_failure`, `locked`, `remove`, `file_id`, `remove_temporary_outputs` |
|
|
12
12
|
| `pages/runner.rb` | `Runner.run(argv)`: the runner process's whole job |
|
|
13
|
+
| `pages/runtime.rb` | `Runtime`, a script's `runtime`: `#schedules` (`ScheduleList`, `Schedule`, `Run`, `Unreadable`) |
|
|
14
|
+
| `pages/bundled.rb` | `Bundled`: the pages installed bundles ship (a manifest's `pages:`), `Page#refusal` |
|
|
13
15
|
| `pages/launch.rb` | `Launch.run(name, timeout:, cancelled:)`: the one launch path |
|
|
14
16
|
| `page_command.rb` | `chi page run | list | rm` |
|
|
15
17
|
|
|
16
18
|
`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
|
|
18
|
-
alone. `launch.rb` is the only file that needs `ChildEnv` and `ProcessGroup`, and nothing in `pages.rb`
|
|
19
|
+
it reaches at load requires the engine, the config, the web, the plugins, `ChildEnv` or `ProcessGroup`: the runner
|
|
20
|
+
loads it alone. `launch.rb` is the only file that needs `ChildEnv` and `ProcessGroup`, and nothing in `pages.rb`
|
|
21
|
+
requires it. Two parts load more, and only when used: `Runtime#schedules` requires `schedules.rb` (which reaches the
|
|
22
|
+
config, `SessionManager` and `ProcessGroup`; about 70 ms) when a script calls it, and `Bundled` requires
|
|
23
|
+
`installed_bundles.rb` (the config) when a name has no script of the user's. `spec/pages_runtime_spec.rb` pins it: a
|
|
24
|
+
real runner process running a user's page that never calls `runtime` has loaded no `runtime.rb`, `schedules.rb` or
|
|
25
|
+
`config.rb`.
|
|
26
|
+
|
|
27
|
+
**The resolver.** `Pages.script_path(name)` is the script a name runs: the user's `NAME.rb` when it exists, else the
|
|
28
|
+
page of that name an installed bundle ships (`Bundled.find`), else the user's path (no such page). Every read and run
|
|
29
|
+
goes through it (`Store.read`/`script_sha`, `Launch`, `Runner`, `PageRoutes`). `Store.remove` never does: it deletes
|
|
30
|
+
only `Pages.user_script_path(name)`, and with no user script a bundle's page raises `FromBundle` before anything is
|
|
31
|
+
touched (`pages_bundled_spec` checks the bundle's file is still there). `Store.list` is the user's names (the pages
|
|
32
|
+
folder) and `Bundled.all`'s, one per name. `Stored#bundle` is the bundle whose script runs (nil when the user's runs,
|
|
33
|
+
so a shadowing copy reads as the user's) and `Stored#script` its path.
|
|
34
|
+
|
|
35
|
+
**Bundle pages** (`Bundled`, from the install records like `BlockRenderers.for_installed`, so chi web loads no plugin):
|
|
36
|
+
each usable `InstalledBundles.standings` record's `manifest.pages` (`InstalledBundles::Manifest#pages`: the kept
|
|
37
|
+
`manifest.yml` only, never the record's mirror, since a key a later manifest gains is never mirrored), the first
|
|
38
|
+
bundle by name winning a name; an unreadable or too-new bundle ships none. Since `pages:` isn't mirrored, a kept
|
|
39
|
+
`manifest.yml` that is edited, stale or missing (`InstalledBundles::Manifest#standing`), or a `pages:` that doesn't
|
|
40
|
+
parse, ships no page either: `Bundled.unread` logs `bundle_pages_unread` (bundle, why) once per process when the kept
|
|
41
|
+
file names `pages:` (or the key failed), and `chi bundle status NAME` says the file is edited. `Page#refusal` is
|
|
42
|
+
`InstalledBundles::Dir#file_refusal(:scripts, …)` against the recorded sha: `Launch.run` checks it under the lock and,
|
|
43
|
+
on one, records it as the run's failure and starts nothing. A bundle page whose installed script is gone is still
|
|
44
|
+
a page (`Pages.exists?`, which `Launch.run` and `GET /api/pages/NAME` ask): its run fails with the `file_missing`
|
|
45
|
+
refusal, not "no page". A bundle page's run loads `installed_bundles.rb` in the
|
|
46
|
+
runner too (its `Pages.script_path`), accepted: the shipped one loads the schedules anyway.
|
|
19
47
|
|
|
20
48
|
## The one launch path
|
|
21
49
|
|
|
@@ -47,7 +75,9 @@ script 152 against 73 preloaded libraries and a stale `PWD`). It costs about 70
|
|
|
47
75
|
are bounded (`reader.wait(grace) || reader.kill`).
|
|
48
76
|
6. The runner wrote the output file, or the launcher records the failure itself: the cut ("the script was stopped
|
|
49
77
|
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.
|
|
78
|
+
or the file is the one that was there before. A timeout cut is skipped when the run wrote its result and exited
|
|
79
|
+
0 or 1; a failure the runner already recorded is never overwritten. "The one that was there before" is the file's
|
|
80
|
+
inode
|
|
51
81
|
(`Store.file_id`): `AtomicFile` renames a new file in for every write, so a run that wrote changes it even within
|
|
52
82
|
one second.
|
|
53
83
|
7. An interrupt or an exception stops and reaps the group in `ensure`; the lock is released by the `File.open` block.
|
|
@@ -77,8 +107,8 @@ limit). It arms the deadline when argv carries one (a write of the result and th
|
|
|
77
107
|
and the write sets a done flag under it, so a result written before the deadline fires is never overwritten), checks
|
|
78
108
|
the
|
|
79
109
|
name and the script, then
|
|
80
|
-
`load(path, dsl)`: the wrap module is a fresh `Module` defining only `page
|
|
81
|
-
on `Object`. `page(title) { |ui| … }` makes a `Builder`; a second call raises `Refused`. After the load, no `page` call
|
|
110
|
+
`load(path, dsl)`: the wrap module is a fresh `Module` defining only `page` and `runtime` (the Collector's
|
|
111
|
+
`Runtime`, made on the first call), so the script's own `def`s land in it, not on `Object`. `page(title) { |ui| … }` makes a `Builder`; a second call raises `Refused`. After the load, no `page` call
|
|
82
112
|
fails the run too.
|
|
83
113
|
|
|
84
114
|
It rescues `StandardError`, `ScriptError`, `SystemExit`, `SystemStackError` (endless recursion) and `NoMemoryError` (never a `SignalException`: a TERM is the launcher's cut,
|
|
@@ -105,7 +135,8 @@ The result reaches the launcher through the file only: a `puts` in a script corr
|
|
|
105
135
|
```
|
|
106
136
|
|
|
107
137
|
- 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
|
|
138
|
+
`ran_at` and `script_sha` stay those of the last good run, and fields this chi does not know are kept in the file
|
|
139
|
+
(dropped only by `Store.read`). A good run sets `error` to null. `Store.record_failure` is
|
|
109
140
|
the one writer of a failure, for the runner and the launcher alike, always under the page's lock.
|
|
110
141
|
- Before any good run there are no blocks and `ran_at` is null.
|
|
111
142
|
- A table's `format` is stored, not applied: cells stay raw numbers so the page can sort them. `key_column` marks the
|
|
@@ -128,32 +159,48 @@ all `:owner`: a participant's token gets 403 `not_permitted` (`participant_gate_
|
|
|
128
159
|
|
|
129
160
|
| Route | Answers |
|
|
130
161
|
|---|---|
|
|
131
|
-
| `GET /api/pages` | `{pages: [{name, title, state, ran_at, failed_at, changed, error_line}]}`, by name (`Store.list`) |
|
|
162
|
+
| `GET /api/pages` | `{pages: [{name, title, state, ran_at, failed_at, changed, error_line, bundle}]}`, by name (`Store.list`) |
|
|
132
163
|
| `GET /api/pages/NAME` | the page (below); 404 `page_missing` with no script. Runs nothing |
|
|
133
164
|
| `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` |
|
|
165
|
+
| `DELETE /api/pages/NAME` | `Store.remove`: `{removed: NAME}`; 409 `page_busy`, 409 `page_bundled` (a bundle's page, `FromBundle`), 404 `page_missing` |
|
|
135
166
|
|
|
136
|
-
The page: `{name, title, state, ran_at, duration_ms, changed, changed_after_failure, script_changed_at, error:
|
|
137
|
-
{message, line, at} | null, blocks}`. `
|
|
167
|
+
The page: `{name, title, state, ran_at, duration_ms, changed, bundle, changed_after_failure, script_changed_at, error:
|
|
168
|
+
{message, line, at} | null, blocks}`. `bundle` (`Stored#bundle`) makes `page_view.js` leave out `⋯` and its Delete;
|
|
169
|
+
an older cached app.js still offers it, and the 409's message shows in its toast. `changed` is `Stored#changed?`; `changed_after_failure` says the script differs
|
|
138
170
|
from the one that failed (so the page needs no sha); `script_changed_at` is the script's mtime. A text block carries
|
|
139
171
|
`html`, the `MarkdownRenderer`'s sanitised render, when rendering is available (`web.markdown`), else `text` only.
|
|
140
172
|
The error codes' `detail` is the exception's own message.
|
|
141
173
|
|
|
142
|
-
**The capability** `pages` (`Web::Viewer::CAPABILITIES`, never a participant's) makes the
|
|
143
|
-
|
|
174
|
+
**The capability** `pages` (`Web::Viewer::CAPABILITIES`, never a participant's) makes the pill, the list, the view and
|
|
175
|
+
the link handler (`pages_wiring.js`, one call in app.js; the pill is `viewer.control(#pagesBtn, "pages")`); without it
|
|
176
|
+
none is made and no page call goes out (`viewer_boot.test.js`).
|
|
144
177
|
|
|
145
178
|
**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
|
|
147
|
-
`body.page-view`, `openPage` / `closePage` / `leavePage`,
|
|
148
|
-
|
|
179
|
+
never a participant's, never without `pages`), `views.js` (reads the page hash and the list's `#/pages` before the
|
|
180
|
+
session intent: `body.page-view` / `body.pages-list`, `openPage` / `closePage` / `leavePage`, `openPagesList` /
|
|
181
|
+
`closePagesList`, where a page or the list was opened from kept in its history entry (`history.pushState({from})`:
|
|
182
|
+
`pages`, `sessions`, `back`, `pill`; Back and its label read `history.state.from`, so Back and Forward keep them;
|
|
183
|
+
an entry with no state was typed or replaced and leaves for the list, or the session), the pill's `aria-pressed`, the session hash not written while either is open, a session picked
|
|
184
|
+
leaving it; a page with nowhere to go back to, or gone, lands on the list), `pages_model.js` (the page's one list of
|
|
185
|
+
pages: `load` shares a read that is out, `reload` asks again, a failed read keeps the last list; DOM-free),
|
|
186
|
+
`pages_wiring.js` (the model, the pill, the list, the view and the links; when the list is read),
|
|
187
|
+
`pages_list.js` (the Pages list, `#/pages`: its hash, its cards in `/api/pages`'s order), `page_view.js` (the header, the states, the calls; an answer for a page no longer open is
|
|
149
188
|
dropped, `latest.js`), `page_model.js` (the words: meta, the failed and changed lines, Copy the error), `page_blocks.js`
|
|
150
189
|
(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
|
|
190
|
+
`page_table_model.js` (cells, sort, the phone's rows), `pages_group.js` (All sessions' former group, kept for an
|
|
191
|
+
older cached app.js until after 0.189.0; nothing new imports it), `page_links.js` (the
|
|
152
192
|
delegated click on the turn roots and the page view for `#/p/` anchors), `pages.css`. What a script wrote reaches the
|
|
153
193
|
page as text or attributes, never as markup, except the server's sanitised `html`.
|
|
154
194
|
|
|
155
|
-
**
|
|
156
|
-
|
|
195
|
+
**The list is live, a page isn't.** chi web's session hub stats the scripts folder (`Pages.scripts_dir`) once a tick
|
|
196
|
+
and sends a `pages` event (no data) on `GET /api/events` when its mtime moved: a script made, renamed in or removed
|
|
197
|
+
(an editor's temp file or a data file beside the scripts counts too: one extra `GET /api/pages` per open tab). Never on
|
|
198
|
+
the first look; a folder that appears or goes is a change. A run changes nothing there (its output is under the state
|
|
199
|
+
dir), unless the script writes a file beside itself (it runs with the pages folder as its working folder): then each
|
|
200
|
+
run refreshes every open tab's list. The page reads the list again on that event and on every snapshot (the first one
|
|
201
|
+
shares the boot read while that is out; a later one is a reconnect: the hub has no replay); with no hub stream (no `EventSource`, the list's fetch fallback) the list is read only when a view opens. A
|
|
202
|
+
page's own result has no stream event and no polling: a run from a terminal shows on the next open; two tabs are not
|
|
203
|
+
kept in step.
|
|
157
204
|
|
|
158
205
|
## chi's side: the skill
|
|
159
206
|
|
|
@@ -169,4 +216,7 @@ owner's `~/.claude/plans/evals/0016-pages-skill/`.
|
|
|
169
216
|
|
|
170
217
|
## Later builds
|
|
171
218
|
|
|
172
|
-
-
|
|
219
|
+
- `runtime` has one method, `schedules`, with its first page (the schedules bundle). A method comes with its first
|
|
220
|
+
caller: sessions, a session's stats, a config value are the candidates.
|
|
221
|
+
- Not planned yet: picks on a page, parameters, a live install (the hub watches the pages folder only, so a bundle's
|
|
222
|
+
page shows on the next list read).
|
|
@@ -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.
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
There is no persisted lifecycle enum. A state is derived from the session file, sidecar files, locks, and the worker
|
|
4
4
|
link: `SessionLifecycle.read(id)` (`session_lifecycle.rb`) reads them once (`WorkerPresence` with its link looked at,
|
|
5
5
|
never unlinked, and `ContinueIntent.in_flight`) and names the first of its 15 states whose facts hold (Derived states).
|
|
6
|
-
The same session can satisfy more than one fact (archived while its worker is leaving); the precedence picks one.
|
|
7
|
-
|
|
6
|
+
The same session can satisfy more than one fact (archived while its worker is leaving); the precedence picks one. Two
|
|
7
|
+
deciders read `SessionLifecycle`: `restart_session`'s precheck and a schedule's busy check (`Schedules#busy_cell`;
|
|
8
|
+
Allowed operations). The others still read their own
|
|
8
9
|
subset of the facts in their own order, and what each answers per state is `ALLOWED` (Allowed operations), pinned by
|
|
9
10
|
the characterization matrix. The session file layout and user-facing session behavior are in [Sessions](../sessions.md); the Worker and
|
|
10
11
|
SessionManager boundaries are in [Architecture](../architecture.md) and [Engine internals](engine.md).
|
|
@@ -98,7 +99,7 @@ Link resolution (`SessionInbox::Head.resolve`, `Schedules#target_of`) stays outs
|
|
|
98
99
|
|
|
99
100
|
The running-tasks check of a user's delete and archive (`SessionManager::RunningTasks`, `tasks_running`) is op-local,
|
|
100
101
|
not an `ALLOWED` cell: it reads the transcript and each `task.json`, not the lifecycle's facts, and runs after the
|
|
101
|
-
lifecycle refusals (`
|
|
102
|
+
lifecycle refusals (`refuse_protected!`, `archivable!`), before the worker is stopped.
|
|
102
103
|
|
|
103
104
|
`restart_session` is the first decider migrated to the table: its lifecycle precheck is `SessionLifecycle.read` (the
|
|
104
105
|
owner read through `session_owner`) and `ALLOWED[:restart]`: `owned_by_tui` raises `OwnedByTUI`, a refusal cell
|
|
@@ -106,7 +107,19 @@ raises `RestartRefused` with it as the reason (`starting`, `not_running`, `stop_
|
|
|
106
107
|
`restart_fallback` (skew, a stuck start) and `go` asks the live worker. Its op-local checks stay where they were: the
|
|
107
108
|
SIGSTOP check (`:stopped`, the worker's pid: a different condition with its own words, before the table's refusal),
|
|
108
109
|
the worker's `restart` feature, the Bridge's reply and the fallback's holds. The matrix still drives it, so its
|
|
109
|
-
column is pinned against the precheck and the op-local paths together.
|
|
110
|
+
column is pinned against the precheck and the op-local paths together.
|
|
111
|
+
|
|
112
|
+
A schedule's busy check (`Schedules#busy_reason`, `schedules/busy_part.rb`) is the second: it reads `WorkerPresence`
|
|
113
|
+
as before (the owner through `session_owner`, the link looked at), derives the state with `Reading.derive` on that
|
|
114
|
+
presence with `exists: true` (the target resolved already, and a delete mid-way, its JSON gone under the deleting
|
|
115
|
+
lock, must read `deleting`, not `absent`; no `ContinueIntent` read), and `#busy_cell` takes `ALLOWED[:sched_chain]`
|
|
116
|
+
or `[:sched_same]` for it. Two op-local overrides keep today's order, each named by its `KNOWN_DIFFERENCES` entries: the
|
|
117
|
+
stop marker before the owner (any cell but `deleting` becomes `stopped`: F1, and an unknown owner's stop), and chain
|
|
118
|
+
mode's starting check with no one-turn-run check (a fresh starting marker without a worker's lock makes `go`
|
|
119
|
+
`worker_busy`: F1b). A skip cell's words are `BUSY_WORDS` (`worker_newer` is Skew's own). On `go`, a live worker
|
|
120
|
+
is asked through its Bridge (`#live_busy_reason`: `/activity`, an old chi, the three activity signals, chain mode's
|
|
121
|
+
open streams) and any other session goes to the file checks (`#file_busy_reason`): those stay op-local, as restart's
|
|
122
|
+
SIGSTOP, features and Bridge reply do. The other deciders don't read `ALLOWED` yet.
|
|
110
123
|
|
|
111
124
|
## Characterization matrix
|
|
112
125
|
|
|
@@ -123,8 +136,8 @@ code can't make (a one-turn run's lock with a stop) is marked `reachable: false`
|
|
|
123
136
|
Every answer must equal `ALLOWED[op][state]` (for the session hub, `SHOWN[state]`: `Web::SessionSummary.build`'s
|
|
124
137
|
status and bridge_up, its `SessionRow`'s live), or be named by exactly one `KNOWN_DIFFERENCES` entry (op, a `when`
|
|
125
138
|
over the row, a plain reason); an entry that names no mismatch fails as stale. The entries are the findings for the
|
|
126
|
-
owner, not fixed: stop-first schedule checks under a one-turn run's or an unknown owner's lock, and attach's under a
|
|
127
|
-
one-turn run's, a deleter's or an unknown owner's; chain mode's starting check before any one-turn-run check; a start
|
|
139
|
+
owner, not fixed: stop-first schedule checks under a one-turn run's or an unknown owner's lock (`#busy_cell`'s stop override), and attach's under a
|
|
140
|
+
one-turn run's, a deleter's or an unknown owner's; chain mode's starting check before any one-turn-run check (`#busy_cell`'s F1b override); a start
|
|
128
141
|
marked after the stop holding a resume off;
|
|
129
142
|
`wake_for_report` reporting a worker's `:live` as `:owned`; the hub's bridge_up, live and status overlay. (Restart
|
|
130
143
|
never reading the stop, the restart and schedule reading a deleter as starting, the schedule's Skew words, and
|