samagotchi 0.177.1 → 0.179.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 +54 -1
- data/docs/architecture.md +4 -2
- data/docs/bundles.md +16 -7
- data/docs/cli.md +30 -6
- data/docs/context.md +25 -1
- data/docs/guardrails.md +3 -2
- data/docs/internals/attached-context.md +26 -4
- data/docs/internals/background-tasks.md +26 -2
- data/docs/internals/block-renderers.md +2 -2
- data/docs/internals/bridge.md +28 -8
- data/docs/internals/bundles.md +63 -34
- data/docs/internals/engine.md +1 -1
- data/docs/internals/remote-sessions.md +6 -1
- data/docs/internals/session-lifecycle.md +17 -8
- data/docs/internals/web-frontend.md +25 -4
- data/docs/internals/working-set.md +31 -5
- data/docs/plugins.md +14 -3
- data/docs/releasing.md +3 -3
- data/docs/scheduling.md +12 -1
- data/docs/sessions.md +16 -6
- data/docs/testing.md +4 -1
- data/lib/samagotchi/block_renderers.rb +12 -14
- data/lib/samagotchi/bootstrap/bundles.rb +2 -2
- data/lib/samagotchi/bootstrap_command.rb +1 -1
- data/lib/samagotchi/bridge/card_store.rb +2 -19
- data/lib/samagotchi/bridge/card_wait.rb +34 -0
- data/lib/samagotchi/bridge/turn_accumulator.rb +22 -4
- data/lib/samagotchi/bridge.rb +38 -6
- data/lib/samagotchi/bundle_command/check.rb +10 -10
- data/lib/samagotchi/bundle_command/installed_check.rb +2 -2
- data/lib/samagotchi/bundle_command/try/sandbox.rb +3 -3
- data/lib/samagotchi/bundle_command.rb +17 -17
- data/lib/samagotchi/bundle_manifest.rb +579 -0
- data/lib/samagotchi/bundle_needs.rb +9 -8
- data/lib/samagotchi/bundle_settings_check.rb +9 -8
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +5 -3
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +4 -4
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +11 -6
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +5 -3
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +4 -3
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +11 -6
- data/lib/samagotchi/bundles/system/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/memory_guide.md +1 -1
- data/lib/samagotchi/compat.rb +0 -7
- data/lib/samagotchi/config.rb +2 -2
- data/lib/samagotchi/context_absorber.rb +36 -6
- data/lib/samagotchi/context_note.rb +8 -5
- data/lib/samagotchi/context_providers.rb +30 -27
- data/lib/samagotchi/context_sources.rb +42 -12
- data/lib/samagotchi/engine/events.rb +43 -0
- data/lib/samagotchi/engine/messages.rb +1 -1
- data/lib/samagotchi/engine.rb +9 -3
- data/lib/samagotchi/event_fanout.rb +56 -0
- data/lib/samagotchi/events.rb +6 -5
- data/lib/samagotchi/guardrail_wiring.rb +20 -21
- data/lib/samagotchi/guardrails/approval.rb +3 -2
- data/lib/samagotchi/guardrails/approvals.rb +0 -4
- data/lib/samagotchi/guardrails/outside.rb +3 -3
- data/lib/samagotchi/{memory_bundle → installed_bundles}/bundle_hook.rb +1 -1
- data/lib/samagotchi/installed_bundles/dir.rb +129 -0
- data/lib/samagotchi/{memory_bundle → installed_bundles}/file_digest.rb +1 -1
- data/lib/samagotchi/{memory_bundle → installed_bundles}/file_standing.rb +2 -2
- data/lib/samagotchi/{memory_bundle/installed_manifest.rb → installed_bundles/manifest.rb} +21 -21
- data/lib/samagotchi/{memory_bundle → installed_bundles}/plugin_ref.rb +2 -2
- data/lib/samagotchi/{memory_bundle/installed_bundle.rb → installed_bundles/record.rb} +17 -17
- data/lib/samagotchi/installed_bundles/sha.rb +41 -0
- data/lib/samagotchi/installed_bundles/standing.rb +45 -0
- data/lib/samagotchi/installed_bundles.rb +90 -0
- data/lib/samagotchi/memory_bundle/asset_installer.rb +7 -7
- data/lib/samagotchi/memory_bundle/builder.rb +13 -13
- data/lib/samagotchi/memory_bundle/file_state.rb +9 -9
- data/lib/samagotchi/memory_bundle/installed_copy.rb +6 -6
- data/lib/samagotchi/memory_bundle/installer.rb +33 -33
- data/lib/samagotchi/memory_bundle/listing.rb +5 -5
- data/lib/samagotchi/memory_bundle/manifest_standing.rb +7 -7
- data/lib/samagotchi/memory_bundle/merger.rb +15 -15
- data/lib/samagotchi/memory_bundle/profile.rb +8 -8
- data/lib/samagotchi/memory_bundle/provenance.rb +59 -192
- data/lib/samagotchi/memory_bundle/remerge.rb +16 -16
- data/lib/samagotchi/memory_bundle/shas.rb +2 -2
- data/lib/samagotchi/memory_bundle/shipped_history.rb +1 -1
- data/lib/samagotchi/memory_bundle/shipped_update.rb +17 -17
- data/lib/samagotchi/memory_bundle/status.rb +15 -15
- data/lib/samagotchi/memory_bundle/system_bundle.rb +12 -12
- data/lib/samagotchi/memory_bundle/trash.rb +2 -2
- data/lib/samagotchi/memory_bundle/uninstaller.rb +8 -8
- data/lib/samagotchi/memory_bundle.rb +2 -2
- data/lib/samagotchi/memory_command.rb +4 -4
- data/lib/samagotchi/{memory_bundle → memory_index}/entry_size.rb +8 -8
- data/lib/samagotchi/{memory_bundle/index_size.rb → memory_index/size.rb} +6 -6
- data/lib/samagotchi/{memory_bundle/index_sync.rb → memory_index/sync.rb} +5 -5
- data/lib/samagotchi/{memory_bundle/index_updater.rb → memory_index/updater.rb} +2 -2
- data/lib/samagotchi/memory_usage.rb +5 -5
- data/lib/samagotchi/muted_memories.rb +1 -1
- data/lib/samagotchi/peer_exchanges.rb +76 -0
- data/lib/samagotchi/plugin/context.rb +4 -0
- data/lib/samagotchi/plugin/loader.rb +35 -33
- data/lib/samagotchi/plugin/peer.rb +42 -11
- data/lib/samagotchi/project_subfolders.rb +9 -9
- data/lib/samagotchi/reply_wait/target.rb +11 -4
- data/lib/samagotchi/schedules.rb +9 -4
- data/lib/samagotchi/self_report.rb +14 -14
- data/lib/samagotchi/session_access/contract.rb +4 -0
- data/lib/samagotchi/session_access/local.rb +32 -5
- data/lib/samagotchi/session_access/remote.rb +44 -10
- data/lib/samagotchi/session_archive_command.rb +38 -10
- data/lib/samagotchi/session_chain/delete.rb +75 -25
- data/lib/samagotchi/session_config.rb +23 -19
- data/lib/samagotchi/session_delete_command.rb +33 -10
- data/lib/samagotchi/session_lifecycle/allowed.rb +12 -9
- data/lib/samagotchi/session_manager/lifecycle.rb +12 -26
- data/lib/samagotchi/session_manager/removal.rb +109 -25
- data/lib/samagotchi/session_manager/running_tasks.rb +347 -0
- data/lib/samagotchi/session_retention.rb +13 -4
- data/lib/samagotchi/session_stores.rb +3 -0
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +4 -4
- data/lib/samagotchi/task_files.rb +37 -4
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +5 -1
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +7 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +2 -2
- data/lib/samagotchi/terminal_ui/local_link.rb +11 -3
- data/lib/samagotchi/terminal_ui/model_segments_text.rb +5 -5
- data/lib/samagotchi/terminal_ui.rb +4 -1
- data/lib/samagotchi/testing/bundle.rb +3 -3
- data/lib/samagotchi/testing/install.rb +3 -3
- data/lib/samagotchi/testing/sandbox.rb +2 -2
- data/lib/samagotchi/tool_runner.rb +14 -14
- data/lib/samagotchi/tools/memory.rb +22 -22
- data/lib/samagotchi/tools/task_runtime.rb +25 -6
- data/lib/samagotchi/update_command.rb +4 -4
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +19 -2
- data/lib/samagotchi/web/message_display.rb +6 -0
- data/lib/samagotchi/web/participant_view.rb +1 -1
- data/lib/samagotchi/web/proxy_gate.rb +1 -0
- data/lib/samagotchi/web/public/card_kinds.js +8 -3
- data/lib/samagotchi/web/public/cards_place.js +15 -1
- data/lib/samagotchi/web/public/ctx.js +1 -1
- data/lib/samagotchi/web/public/data.js +19 -7
- data/lib/samagotchi/web/public/delete_sheet.js +26 -7
- data/lib/samagotchi/web/public/history_shape.js +3 -0
- data/lib/samagotchi/web/public/running_tasks.js +73 -0
- data/lib/samagotchi/web/public/session_actions.js +57 -8
- data/lib/samagotchi/web/public/stop_sheet.js +3 -2
- data/lib/samagotchi/web/public/turn_block.js +46 -8
- data/lib/samagotchi/web/public/turn_settle.js +117 -0
- data/lib/samagotchi/web/public/working_set.js +3 -28
- data/lib/samagotchi/web/public/working_set_view.js +5 -2
- data/lib/samagotchi/web/public/ws_item_sig.js +51 -0
- data/lib/samagotchi/web/public/ws_peek.js +23 -13
- data/lib/samagotchi/web/public/ws_reader.js +22 -12
- data/lib/samagotchi/web/public/ws_timeline.js +9 -6
- data/lib/samagotchi/web/push/notifier.rb +2 -2
- data/lib/samagotchi/web/session_access_routes.rb +21 -1
- data/lib/samagotchi/web/session_control.rb +65 -16
- data/lib/samagotchi/web/session_hub.rb +20 -4
- data/lib/samagotchi/web/working_set_routes.rb +29 -8
- data/lib/samagotchi/worker_boot.rb +4 -1
- data/lib/samagotchi/worker_link.rb +9 -1
- data/lib/samagotchi/working_set.rb +26 -0
- data/lib/samagotchi/working_set_command.rb +9 -6
- metadata +22 -12
- data/lib/samagotchi/memory_bundle/manifest.rb +0 -581
data/docs/internals/bundles.md
CHANGED
|
@@ -3,7 +3,16 @@
|
|
|
3
3
|
How `lib/samagotchi/memory_bundle/` turns a bundle (a dir, git URL, zip or tar holding `manifest.yml`, `*.md`
|
|
4
4
|
memories and optional `guardrails/`, a plugin file and `scripts/`) into installed state, and back. The
|
|
5
5
|
user-facing side (what a bundle owns, profiles, needs) is in [memory.md](../memory.md#what-a-bundle-owns) and
|
|
6
|
-
[plugins.md](../plugins.md) and [bundles.md](../bundles.md).
|
|
6
|
+
[plugins.md](../plugins.md) and [bundles.md](../bundles.md). The managed memory index helpers live in
|
|
7
|
+
`lib/samagotchi/memory_index/`.
|
|
8
|
+
|
|
9
|
+
Three namespaces share the work. `BundleManifest` (`lib/samagotchi/bundle_manifest.rb`) is the `manifest.yml`
|
|
10
|
+
format. `InstalledBundles` (`lib/samagotchi/installed_bundles.rb` + `installed_bundles/`) is the read side of what is
|
|
11
|
+
installed: the records, their manifests, the walk, one bundle's folder and the shas its files are checked against;
|
|
12
|
+
the runtime (the plugin loader, guardrails, context providers, block renderers, session settings) reads bundles only
|
|
13
|
+
through it, and loading it loads nothing of `memory_bundle/` (`spec/samagotchi/installed_bundles_spec.rb`).
|
|
14
|
+
`MemoryBundle` is the install machinery (install, upgrade, merge, build, uninstall, status, listing), built on the
|
|
15
|
+
read side, never the reverse.
|
|
7
16
|
|
|
8
17
|
## Where things live
|
|
9
18
|
|
|
@@ -12,7 +21,7 @@ user-facing side (what a bundle owns, profiles, needs) is in [memory.md](../memo
|
|
|
12
21
|
project <system>/projects/<project key>
|
|
13
22
|
*.md, index.md the bundle's memories, one managed index line each ("· from <bundle>")
|
|
14
23
|
<system memories>/.bundles/ MemoryPaths.bundles_dir
|
|
15
|
-
<name>/manifest.json the install record (Provenance#write, read as
|
|
24
|
+
<name>/manifest.json the install record (Provenance#write, read as InstalledBundles::Record)
|
|
16
25
|
<name>/manifest.yml the bundle's own manifest as installed (Provenance#write's manifest_from:), its sha
|
|
17
26
|
the record's manifest_sha; a dev install links it to the source (DEV_SHA)
|
|
18
27
|
<name>/bases/ each file's base for the next upgrade's 3-way merge: as installed, or the
|
|
@@ -31,71 +40,91 @@ user-facing side (what a bundle owns, profiles, needs) is in [memory.md](../memo
|
|
|
31
40
|
|
|
32
41
|
| Piece | Role |
|
|
33
42
|
|---|---|
|
|
34
|
-
| `
|
|
43
|
+
| `InstalledBundles` (`installed_bundles.rb`) | `.each(holding:, dir:)` (each installed bundle by name, its `Record`; one whose `manifest.json` doesn't read with `error` set, and with `holding:` only those with that key, or that dir when it doesn't read), `.claimants` (which bundles own a memory file), `.dir` (`MemoryPaths.bundles_dir`) |
|
|
44
|
+
| `InstalledBundles::Dir` (installed_bundles/dir.rb) | one bundle's `.bundles/<name>/` as the runtime reads it: `Dir.new(name:, dir:)`, `#record`, `#plugin_dir`, `#plugin_path`, `#scripts_dir`, `#guardrails_dir`, `#kept_manifest_path`, `#file_refusal(kind, file, recorded)` (the one "is this installed file as installed" check: `:plugin`, `:scripts`, `:guardrails`, each with its own order and words today, a `Refusal`). Its only state is the name and the folder; `Provenance` is one |
|
|
45
|
+
| `InstalledBundles::Standing`, `Refusal` (installed_bundles/standing.rb) | the usability verdict: `.standings(holding:, dir:)` (the walk, each bundle's `Standing`), `.standing(name, dir:)` (one record; a `manifest.json` that doesn't parse raises), `Standing.of(name, record)`: `#refusal` is `:unreadable` (the record) or `:too_new` (requires_chi), nil when chi may use it; none of the bundle's own files is hashed (a manifest cache miss hashes the kept `manifest.yml`, as `Manifest.of` does). A `Refusal` has `kind`, `text` and, for `:file_changed`, the `actual` and `expected` shas. Each reader keeps only its reaction (below) |
|
|
46
|
+
| `InstalledBundles::Sha` (installed_bundles/sha.rb) | the record's shas: `.recorded` (either format, `""` for none), `.of_file`, `DEV` (a dev install's `sha256:dev`), `.unchecked?`, `.matches?` |
|
|
47
|
+
| `BundleCommand` (`lib/samagotchi/bundle_command.rb`) | `chi bundle install/upgrade/uninstall/status/diff/list/build/trash/new/test/check/try` (`install --dev`: the Installer's `dev:`, links and `InstalledBundles::Sha::DEV`); runs the Installer, prints its summary, runs the conflict agent step; refuses a source already installed under another name (`installed_under_another_name?`: a git URL bundle recorded under its repo's name before the manifest named it). `upgrade` resolves its argument by `upgrade_source`: a git URL or an existing path, then a shipped name, then the bare name of an installed bundle — whose record's source it then uses (a git URL with its `#ref`, a dir or an archive that is still there), printed as `Upgrading NAME from SOURCE`; a dev record is refused with `Installer.dev_install_line`, a recorded source that is relative, empty or gone says so and asks for the path or URL of a copy (`Installer.source_gone_line`, the words `ManifestStanding` uses too). After an upgrade or uninstall that changed the bundle's plugin (or brought one in), one line names the sessions still running its old code (`LiveVersions.workers`, the ones whose worker takes a restart) and `chi sessions restart ID` for each: only the plugin stays in memory, since a bundle's rules reload by their stamp and its scripts run from the replaced files. |
|
|
35
48
|
| `BundleCommand::Check` (bundle_command/check.rb) | `chi bundle check [PATH] [--fix] [--set K=V]`: a bundle being written, checked as an install takes it (docs/cli.md lists the codes); parses the manifest from `Shas.parseable` (a placeholder sha is a `sha` finding, not a YAML error), reads the user's installed bundles only for `clash`, and installs and loads through `Testing::Install` in a `Testing::Sandbox` with `force: true`, the log's echoes swallowed |
|
|
36
49
|
| `BundleCommand::Try` (`bundle_command/try/`) | `chi bundle try PATH -p TEXT`: `Command` (its flags, help and checks) drives the rest and `Render` prints the trace; a filtered-config `Sandbox` (its folders a `SandboxLayout`, the layout `Testing::Sandbox` uses too) installs the tried bundle and shipped `guardrails` / `cost-cap` in a separate child, then `Run` starts one non-interactive chi process from its realpath work dir; `TraceReader` reads that session's analytics, cards (`Bridge::CardStore.saved`, as the web does) and session JSON by id (never `Session.list`), joining timing and tool args for text or experimental JSON output (a turn a `--timeout` interrupt cut keeps its calls like a Ctrl-C, the one cut short answered as interrupted, so its rows come from the saved calls too; `Run::Result#timed_out` becomes `timed_out`). `Sandbox#child_env` is a Hash, never an ENV mutation; it keeps ordinary user model settings and Keychain access while dropping the spawner's session/guardrail/worker markers (`ChildEnv`, the scrub a session's worker spawn uses too). Every dropped key is sent as nil, so the child really lacks it: a spawn env is merged onto the spawner's, so a key only deleted from the Hash is still inherited (`ChildEnv.spawn_env`). The child runs in its own process group: a `--timeout` sends it INT, then `ProcessGroup.stop` (the groups its processes started too); after any exit the group is signalled only while a straggler is still in it, never a reaped group. `Sandbox#stop_leftovers` (before the trace, and in `cleanup`) stops what left the child's tree, found by the sandbox's own records: a delegate's worker by its session's `owner.lock`, a task by its running `task.json` whose pid still leads its group. |
|
|
37
50
|
| `BundleCommand::ApiCalls` (bundle_command/api_calls.rb) | what a plugin's source calls of the API, by Prism: `#findings` (a call or keyword the API's classes lack, `check`'s `api`), `#keywords` (the floor check's `call(keyword:)`). Its only list is `MEMBERS`, which object a member gives (`ctx.sessions` → `Plugin::Sessions`); a new such object joins it |
|
|
38
51
|
| `BundleCommand::Scaffold` (bundle_command/scaffold.rb) | `chi bundle new NAME`: the starting files (block-form `plugin:` entry, `requires_chi` at this chi, a kit test that passes as written); the manifest's shas are filled through `Shas.refresh` |
|
|
39
52
|
| `BundleCommand::TestRun` (bundle_command/test_run.rb) | `chi bundle test`: `RbConfig.ruby -I <chi's lib>` on `test/**/*_test.rb` (Minitest) or `spec/` (RSpec, as `rake bundles:specs`), under `Bundler.with_unbundled_env` when Bundler's runtime is loaded |
|
|
40
53
|
| `Shas` (shas.rb) | a manifest's `sha256:` lines: `.refresh(dir[, text])` rewrites them line by line (the layout kept; a `files:` entry it can't place raises `Shas::Error`), `.stale` → `[Stale(file, old, new)]` (`old` `""` for a placeholder, nil for a plugin / script entry with no sha line), `.parseable` (a placeholder `sha256: sha256:` isn't YAML). Plain Ruby: `rake bundles:sha` / `bundles:check` (`script/release/release_tools.rb`) and `chi bundle check --fix` share it |
|
|
41
|
-
| `FileDigest` (file_digest.rb) | the one digest of a file on disk: `.hex(path)` (its bytes, streamed; nil when the path isn't a file, a raise for one that can't be read), `.sha256(path)` = `"sha256:<hex>"`, nil with no file — the shape a record writes for a rule, plugin or script. `
|
|
54
|
+
| `InstalledBundles::FileDigest` (installed_bundles/file_digest.rb) | the one digest of a file on disk: `.hex(path)` (its bytes, streamed; nil when the path isn't a file, a raise for one that can't be read), `.sha256(path)` = `"sha256:<hex>"`, nil with no file — the shape a record writes for a rule, plugin or script. `InstalledBundles::Sha.of_file`, `Merger.digest`, `Status.checksum`, `InstalledBundles::Record#source_sha`, `FileStanding.differs?` and the Installer's checksum verifiers all go through it; a digest of bytes already in memory (a merge's text, a memory's content that is also its base) stays with the code holding them |
|
|
42
55
|
| `SourceNormalizer` (source.rb) | source → local dir; a git/zip/tar extract is *owned* and removed after the install |
|
|
43
56
|
| `SourceIdentity` (source.rb) | what a source is, for comparing two installs of one name: `shipped:<dir>` (any gem or checkout), `git:<url>` (no `#ref`, trailing `/` or `.git`), `path:<realpath>`; nil when it can't place one |
|
|
44
57
|
| `PreparedSource` (source.rb) | one source normalized once (dir, owned, git commit): `BundleCommand` reads the bundle's name from its `manifest.yml` (the name for every kind of source, a git URL too) and hands it to the Installer (`prepared:`), so a source is cloned or extracted once per command |
|
|
45
58
|
| `MemoryFiles` | which top-level `*.md` files of a bundle are its memories (`.select`: the `files:` list, else all but README/LICENSE and the like), `.unshipped` (listed, not shipped) and `.symlinks` (skipped: a symlink is never a memory) |
|
|
46
|
-
| `
|
|
59
|
+
| `BundleManifest` (`lib/samagotchi/bundle_manifest.rb`) | parses/validates `manifest.yml` (`name:` is the bundle's name and a directory under `.bundles/`, so a path such as `../x`, `a/b`, `.` or `..` is refused: `name: … is not a bundle name`; YAML that doesn't parse or isn't a mapping is a `ValidationError` too; files, plugin, scripts, needs, requires_chi, includes, context_providers, session_settings: the keys a session's `chi --set` may give, a list or a mapping of them to types (`SESSION_SETTING_TYPES`), recorded at install in `manifest.json` (`session_settings`, `session_setting_types`) for `SessionConfig` to check; settings: the keys config.yml's `bundles: <name>:` may have, the same shape, recorded as `settings` (nil when the manifest has none) and `setting_types` for `BundleSettingsCheck`, whose warnings the Engine holds for the first turn and `SessionConfig`'s refusals share the words of) and writes it (`BundleManifest.write`, for Builder). It ignores `requires_chi_next`, a shipped bundle's release-time marker (`script/release/release_tools.rb`, docs/releasing.md). `KEYS` is every top-level key it reads, so a key outside it is one this chi ignores: `#unknown_keys`, in the order the manifest lists them, said in `BundleManifest.unknown_key_line`'s words by the Installer and `chi bundle check`. `SINCE` is the first release that read each key or shape (taken from the tags), and `#floor_keys` names the ones this manifest uses — including the shapes only a newer chi reads (a `files:` mapping, a typed `session_settings:`/`settings:`) — for check's `requires-chi-floor`. A `hooks:` entry is `BundleManifest::HooksRetired` (a `ValidationError`; `WORDS` is the one wording of the retirement, `.for_key`, `.for_files`, `.files_in` a source's `hooks/*.rb`) on a strict read and ignored by `BundleManifest.tolerant` |
|
|
47
60
|
| `Installer` | one install/upgrade/dry run of one bundle (below) |
|
|
48
61
|
| `AssetInstaller` | the parts that live in `.bundles/<name>/`: guardrail rules, plugin, scripts (and `#retire_hooks`: an older chi's `hooks/` removed, below); returns `AssetInstaller::Installed` (the paths the record keeps). Each folder is one loop, `#install_set(kind_of_file, incoming)`: every file's `AssetState` (`AssetState.in`: the files there at any depth, the incoming and the recorded ones), its row in `FileActions`' `ASSET_INSTALL` or (an upgrade over a record) `ASSET_UPGRADE`, one `Installer::FileResult` per incoming file with the state and action (a dry run's word through `AssetInstaller::DRY_WORDS`, nothing written), a `save_first` file copied to the Installer's `Trash` first (`Trash#copy`, as `guardrails/x`, `plugin/x`, `scripts/sub/x`), then the folder replaced; the named-but-missing and symlink `InstallError`s come before it, the checksum warning after the write (a plugin or script, not a dev link). An older chi's `hooks/` keep `Trash#copy_edits` |
|
|
49
|
-
| `FileState` (file_state.rb) | one bundle memory as a command meets it, derived, never stored: `FileState.of(key, record:, provenance:, target_dir:, source_dir:, claimants:, shipped:)` reads the file (D), its base (B), the bundle's text (I) and the record's entry (R) once into `Digests` (`disk`, `base`, `incoming`, `recorded`, `marked_incoming`; `:unreadable` for a file it can't read) and names its `kind` and `mark` (`:none`, `:current`, `:legacy` = `
|
|
62
|
+
| `FileState` (file_state.rb) | one bundle memory as a command meets it, derived, never stored: `FileState.of(key, record:, provenance:, target_dir:, source_dir:, claimants:, shipped:)` reads the file (D), its base (B), the bundle's text (I) and the record's entry (R) once into `Digests` (`disk`, `base`, `incoming`, `recorded`, `marked_incoming`; `:unreadable` for a file it can't read) and names its `kind` and `mark` (`:none`, `:current`, `:legacy` = `InstalledBundles::Record.legacy_mark?`). With a source (install, upgrade, remerge, restore, a plan): `:new`, `:user_same`, `:user_file` (not the bundle's), `:missing`, `:level` (D == I), `:pristine`, `:edited`, `:diverged`, `:pristine_no_base`, `:edited_no_base`, `:dropped_pristine`, `:dropped_edited`, `:dropped_missing` (`shipped: false`: the bundle no longer ships the key), `:unreadable`; with `source_dir: nil` (status, uninstall, diff) only `:pristine`, `:edited`, `:pristine_no_base`, `:edited_no_base`, `:missing`, `:unreadable`. Edited or not is always `#edited?` = `!Provenance.unchanged?` (the one edited rule: the checksum first, then the base); the base then says what changed, and a base the checksum contradicts (equal to an edited file) is no base to merge from (`:edited_no_base`). `#source_moved?` (a mark that speaks of other text than the bundle ships: Remerge's first question), `#shared_with` (the other bundles listing it, `InstalledBundles.claimants` asked lazily, at most once: only a dropped file and an uninstall ask) |
|
|
50
63
|
| `AssetState` (asset_state.rb) | one rule, plugin or script of a bundle's own folder as a command meets it, derived, never stored: `AssetState.of(path, kind_of_file:, recorded:, incoming:)` → `state` (`:new`, `:unchanged` (the source's bytes, a dev link to them too), `:pristine`, `:edited`, `:linked` (a link to other bytes), `:dropped_pristine`, `:dropped_edited`, `:missing`; with no source, as uninstall and status read it, a file there is a `dropped_*` or `:linked`), `#edited?` (the asset rule: `Trash.edit?`, its bytes neither the recorded sha, none recorded counting as edited, nor the incoming file's; a link never), `#label` (`guardrails/x`, as the trash and the plan name it). `AssetState.in(dir, …)` is a folder's set. Read by `AssetInstaller`, `ShippedUpdate#trash_bound`, `Uninstaller#save_edits`, `Status.asset_states` and `chi bundle diff`; `asset_state_spec` checks it against the corpus's asset cases |
|
|
51
64
|
| `FileActions` (file_actions.rb) | what each command that acts does in each state: one table per command (`INSTALL`, `FORCE` = install and upgrade `--force`, `UPGRADE`, `REMERGE`, `RESTORE`, `UNINSTALL`), a cell keyed `[kind, mark]`, `[kind, :any]` or `[kind, :shared]`, its value an `Action` (`do`: `:write_incoming`, `:merge`, `:decide`, `:keep`, `:skip`, `:move_to_trash`, `:refuse`, `:restore`; `save_first`; `next_base`: `:on_disk`, `:incoming`, `:recorded`, `:none`; `word`, the report bucket; `record`: `:own`, `:keep_entry`, `:mark`, `:hold_mark`, `:clear_mark`, `:drop`, `:not_owned`). `.for(command, state)`. A `:decide` cell (`[:diverged, :any]`, the legacy guard's `[:pristine, :legacy]`) isn't a function of kind and mark: `Merger::Upgrade#decision` answers it with an `Outcome`, which `.decided(outcome, command)` turns into the action. A dry run reads its command's row and doesn't do it (`Installer::DRY_WORDS` gives its word). Assets have their own tables, `ASSET_INSTALL`, `ASSET_UPGRADE` (an upgrade lists a replaced rule as installed, the plugin and a script as updated: the one cell keyed by kind, `[state, kind_of_file]`) and `ASSET_UNINSTALL`, read with `.for_asset(command, asset)`; their `do` adds `:remove` (deleted, `save_first` copying an edit). A new kind or a new acting command adds a row in each table it reaches; `file_actions_spec` checks every cell against the bundle-state corpus |
|
|
52
|
-
| `Merger` | the upgrade's merge. `Merger::Upgrade` (provenance, target dir, source dir) is the one way to ask what an upgrade does to a file, nothing written: `#decision(key[, state])` → a `Decision` (the `FileState`, the UPGRADE action with a `:decide` cell answered, and the `Outcome`), `#outcome` its `Outcome` (`status`: `install`, `fast_forward`, `keep`, `noop`, `conflict`, `merged`; `base`: the next base, `Action#next_base`'s words), `#state`, `#forecast` (a `Forecast` of `merged` and `behind` in one pass), `#behind` (a `conflict` outcome as a `FileStanding::Behind`: why, and from `TextMerge.changed_sections` what it missed, nothing for an older mark, whose base may be the user's text), `#paths`, used by the Installer's merge and dry run, `Remerge`, `ShippedUpdate.plan` and `SystemBundle.sync(dry_run:)`. A `:decide` cell runs `.merge_outcome` (`TextMerge` where both sides changed, git once per call: `merged`, with its `TextMerge::Result` and the digest it read as the Outcome's `merge` and `current_sha`; `ALREADY_MERGED`, a `keep` with base `:incoming`, when the merge adds nothing; or `conflict` with that `merge`, whose `why` says why none was possible; no base: `TextMerge::NO_BASE`, a base the checksum contradicts: `FileStanding::LEGACY_BASE`). `.write_merged` puts a merge in place: the digest checked just before the rename (`AtomicFile.write`'s block), through a symlink, the mode kept, the old file in the `Trash`; false when a live `memory_write` got in. A mark from an older chi (`
|
|
65
|
+
| `Merger` | the upgrade's merge. `Merger::Upgrade` (provenance, target dir, source dir) is the one way to ask what an upgrade does to a file, nothing written: `#decision(key[, state])` → a `Decision` (the `FileState`, the UPGRADE action with a `:decide` cell answered, and the `Outcome`), `#outcome` its `Outcome` (`status`: `install`, `fast_forward`, `keep`, `noop`, `conflict`, `merged`; `base`: the next base, `Action#next_base`'s words), `#state`, `#forecast` (a `Forecast` of `merged` and `behind` in one pass), `#behind` (a `conflict` outcome as a `FileStanding::Behind`: why, and from `TextMerge.changed_sections` what it missed, nothing for an older mark, whose base may be the user's text), `#paths`, used by the Installer's merge and dry run, `Remerge`, `ShippedUpdate.plan` and `SystemBundle.sync(dry_run:)`. A `:decide` cell runs `.merge_outcome` (`TextMerge` where both sides changed, git once per call: `merged`, with its `TextMerge::Result` and the digest it read as the Outcome's `merge` and `current_sha`; `ALREADY_MERGED`, a `keep` with base `:incoming`, when the merge adds nothing; or `conflict` with that `merge`, whose `why` says why none was possible; no base: `TextMerge::NO_BASE`, a base the checksum contradicts: `FileStanding::LEGACY_BASE`). `.write_merged` puts a merge in place: the digest checked just before the rename (`AtomicFile.write`'s block), through a symlink, the mode kept, the old file in the `Trash`; false when a live `memory_write` got in. A mark from an older chi (`InstalledBundles::Record.legacy_mark?`: no `incoming_sha`, or `legacy_base`, which keeps that known once the digest is recorded, until the mark goes) may have the user's own text as its base, 0.149's doing, and a merge against it would undo that text with nothing to show, or a fast-forward replace all of it: the upgrade's `[:pristine, :legacy]` cell decides: `#decision` makes a fast-forward that takes a line out of the file, and `.merge_outcome` a merge that does, a `conflict` (`FileStanding::LEGACY_BASE`), on the Installer's and `Remerge`'s path alike, unless `ShippedHistory` proves the base is a version chi shipped. The price, with no such gem left or for a bundle chi doesn't ship: a real base looks the same, so such a file whose bundle rewords or removes a line it still holds stays behind until it is resolved by hand, with `--agent` or with `--force`; no retry fixes it. A fast-forward that goes ahead over a mark is a `save_first` cell (`Installer#save_first`): a file put back to its base under this chi's mark, or an older mark with a proved base or an update that only adds. `.markers?` (a file holding a merge's `<<<<<<<`/`>>>>>>>` lines; `=======` alone is a Markdown underline) |
|
|
53
66
|
| `ShippedHistory` | `.shipped?(bundle, file, path)`: whether those bytes are that file of that bundle (by manifest name, since a shipped dir can be renamed) in an installed `samagotchi-<version>` gem. Reads `<gem dir>/gems/` by hand, for `Gem.path` (set by a chi home's boot string) and the home's `gem_dirs` from home.json (a checkout or another Ruby runs on other gems), never `Gem::Specification`. Size, then bytes, then the manifest. Anything it can't read is no match, which keeps the guard. Asked only when `Merger`'s guard would otherwise fire: with 54 gems on the Studio a miss costs about 4 ms, a hit less |
|
|
54
67
|
| `TextMerge` | the text merge: `.merge(base:, ours:, theirs:)` → a `Result` (`status` `:clean` with `text`, `:conflict` with `hunks`, `:failed` with `why`). `git merge-file -p --diff3 --marker-size=20` on temp copies in a temp cwd, with every `GIT_*` that points at a repository or a config unset or at `/dev/null` (it can run inside another tool's hook). git isn't a runtime dependency: none on PATH, or macOS's `/usr/bin/git` with no developer tools behind it (`.apple_stub?`, by `xcode-select -p`; running it pops a dialog), is `:failed`. So is a git past `TIMEOUT` (10 s; its process group is killed: this runs under `SystemBundle`'s lock), and any doubt about the answer: `min(hunks, 127)` against the exit status, a status over 127, a NUL in a side, marker lines that don't pair up (a user's line equal to one), a line no input holds, or an empty answer to non-empty inputs. `Scan` reads the output: a hunk unions (ours, then the entries of theirs that ours lacks) only when the last heading before it, at level 1 or 2 and outside code fences, HTML comments and any hunk, is titled exactly `Changelog` or `Change log`, with nothing but list entries (an item and its indented lines) since that heading and no fence or comment open, and base, ours and theirs each hold only list entries, with every base entry still on both sides: both only added. Any other hunk is a real conflict, and markers never leave the module. An entry is an item and the lines indented deeper under it, nested items too, and the union compares whole entries. `.changed_sections(base, theirs, ours)`: the headings of the sections the bundle changed and the file hasn't got, and whether text under no heading did, which is what names a miss: a conflict's hunks can't, since the whole file stays and the one hunk may be a Changelog line beside a whole new section. `Hunk#heading` counts the places under no heading |
|
|
55
|
-
| `FileStanding` | the one owner of what chi says of an edited bundle file, used by every surface: `Behind` (`#state`, `#line`: `x.md stays behind 0.8.0: no merge possible (why); missed ## A, ## B, ## C and 2 more`, `would stay` in a dry run), `MergeNote`, `.merged_line`, `.no_merge` (for `LEGACY_BASE` it says chi can't tell whether the file holds edits), `.clauses` (a report's clauses for one bundle), `.behind_count`, `.stay_behind`, `.counts_sentence` (the push), `.still_behind`, `.text` (UTF-8, whatever a name or heading was tagged), `FORCE_TAKES`, `FORCE_MOVES`, `IN_THE_TRASH`. Behind means marked and bytes other than the mark's `incoming_sha` (`.behind?`, read by `
|
|
68
|
+
| `InstalledBundles::FileStanding` (installed_bundles/file_standing.rb) | the one owner of what chi says of an edited bundle file, used by every surface: `Behind` (`#state`, `#line`: `x.md stays behind 0.8.0: no merge possible (why); missed ## A, ## B, ## C and 2 more`, `would stay` in a dry run), `MergeNote`, `.merged_line`, `.no_merge` (for `LEGACY_BASE` it says chi can't tell whether the file holds edits), `.clauses` (a report's clauses for one bundle), `.behind_count`, `.stay_behind`, `.counts_sentence` (the push), `.still_behind`, `.text` (UTF-8, whatever a name or heading was tagged), `FORCE_TAKES`, `FORCE_MOVES`, `IN_THE_TRASH`. Behind means marked and bytes other than the mark's `incoming_sha` (`.behind?`, read by `InstalledBundles::Record#behind_files` and `Remerge` alike): a file brought level by hand isn't, a missing one is a missing file, and one that can't be read is. An older mark no retry has looked at reads `may be behind` (`Behind#unsure`, and the counts say so), and isn't behind at all when level with its recorded source on disk (`InstalledBundles::Record#behind_file?`). A new surface reads these and adds no wording |
|
|
56
69
|
| `Remerge` | the retry at the same version, memory files only, for a file marked `conflict` (its `FileState` and `REMERGE` row; a `:decide` cell through `Merger::Upgrade#decision`): `#run(dry_run:)` → a `Result` (`merged`, `settled`, `stamped`, `behind`, `warnings`, `trash_copy`). It merges what merges and settles those entries (`Provenance#resolve_conflicts`, the index line refreshed), checking a merged incoming file against the manifest's sha256, in a dry run too. It leaves `version`, `installed_at` and the assets alone: the Installer would `rm_rf` guardrails, plugin and scripts under live sessions. Every file it leaves is in `behind`, with why: one not shipped now (`MemoryFiles.select`) keeps its mark, base and text; one whose `incoming_sha` isn't the shipped text (a checkout at one VERSION) is left alone, no git runs, and it reads as its mark says; a mark with no digest (older chi) is tried as well, and a real conflict then records it (`Provenance#refresh_marks`, which writes only when the mark would read differently, so a conflict at each start writes nothing). A mark whose digest matches is tried on every run, since the file or git may have changed. `noop` and `keep` settle quietly; `fast_forward` waits for the next upgrade, reading as behind until then; `install` is a missing file, which isn't behind, and a warning says so. A file it can't read or replace stays as it is, saying why. Called from `ShippedUpdate.plan_row`/`apply` (`chi update`) and `SystemBundle.sync`'s equal-version branch, under its lock (each chi start and `chi update`); a bundle chi doesn't ship retries through `chi bundle upgrade`. No marks: nothing is read beyond the record. One marked file costs one git run per Engine start, about 12 ms on the Studio (0.1 ms with none) |
|
|
57
|
-
| `Provenance` | the `.bundles/<name>/` dir: `#write` the record + bases (its `files:` is the full list: a key left out is dropped, a nil value keeps the entry with no base; `marks:` are the files left behind, each a `FileStanding::Behind`, and `incoming_dir:` the bundle text each speaks of, recorded as `incoming_sha` and saved at `#incoming_path`; an older mark that stays keeps `legacy_base`), `#resolve_conflicts` (base to the incoming file, mark and its fields (`MARK_FIELDS`) and saved text gone; a file whose incoming copy is gone keeps both), `#refresh_marks` (what a retry found: why, missed, the digest and `legacy_base`, the saved text), `#note_merged` and `#clear_merge_notes(notes)` (`MERGE_NOTE_FIELDS`, kept through `#write`; the saved text is best effort, after the manifest, so it can't leave a plugin under the old record's sha; any other failure writing the record still can, until a retry), `#record` → `
|
|
58
|
-
| `
|
|
59
|
-
| `ManifestStanding` (manifest_standing.rb) | the one owner of the words for an installed bundle's `manifest.yml` as `
|
|
60
|
-
| `
|
|
61
|
-
| `BlockRenderers` (`lib/samagotchi/block_renderers.rb`) | a manifest's `block_renderers:`: `.parse_list`, and what chi web asks without loading plugins: `.for_installed` (first bundle by name wins a language; a record with an error, an unmet `requires_chi` or a list that doesn't parse is skipped) and `.script_path` (`load` membership first, then `
|
|
70
|
+
| `Provenance` | the `.bundles/<name>/` dir's write side (an `InstalledBundles::Dir`): `#write` the record + bases (its `files:` is the full list: a key left out is dropped, a nil value keeps the entry with no base; `marks:` are the files left behind, each a `FileStanding::Behind`, and `incoming_dir:` the bundle text each speaks of, recorded as `incoming_sha` and saved at `#incoming_path`; an older mark that stays keeps `legacy_base`), `#resolve_conflicts` (base to the incoming file, mark and its fields (`MARK_FIELDS`) and saved text gone; a file whose incoming copy is gone keeps both), `#refresh_marks` (what a retry found: why, missed, the digest and `legacy_base`, the saved text), `#note_merged` and `#clear_merge_notes(notes)` (`MERGE_NOTE_FIELDS`, kept through `#write`; the saved text is best effort, after the manifest, so it can't leave a plugin under the old record's sha; any other failure writing the record still can, until a retry), `#record` → `InstalledBundles::Record` (the Dir's). `#write(manifest_from: DIR)` keeps `DIR/manifest.yml` at `#kept_manifest_path` (written aside and renamed; for `dev:` a link to its realpath) and records `manifest_sha` (`FileDigest.sha256`, `DEV_SHA` for dev) and `installed_by` (this chi's VERSION); the Installer and `Profile.install` pass their source dir, and a write without it carries the existing record's two fields, the kept file left alone. The in-place edits (`#resolve_conflicts`, `#record_restored`, `#refresh_marks`, `#note_merged`, `#clear_merge_notes`) keep them. The record's mirror of the manifest keys (`requires_chi` … `setting_types`) is still written from the kwargs, exactly as before: an older chi sharing the memories dir (an old worker, chi web, gem or worktree) reads only the record, and without the mirror's `requires_chi` it would load a too-new bundle's plugin. A key a later manifest gains is never mirrored. Any chi without the kept manifest that rewrites a record drops `manifest_sha` and `installed_by` (it rebuilds the record from its own kwargs). `#adopt_manifest(dir, dry_run:)` heals such a record (`InstalledBundles::Record#manifest_unkept?`: no `manifest_sha`, or its file gone): when `dir` is the source of what's installed (its manifest names the bundle at the recorded version; each mirrored key, normalised as `#mirror_fields` records it (the one shape `#write` uses too), equals the record's, a key the record lacks being fine only when `BundleManifest::SINCE` has it, since an older chi couldn't have recorded it (a recorded hook doesn't count: retired); and every recorded plugin, hook, script, rule and unmarked memory sha is that of `dir`'s file; else the why names the key or file) it keeps `dir/manifest.yml` and records `manifest_sha`, nothing else (not `installed_at`, the mirror or `installed_by`); otherwise it returns why and writes nothing. Never for a dev record (its next `install --dev` links the file) |
|
|
71
|
+
| `InstalledBundles::Manifest` (installed_bundles/manifest.rb) | the one answer to "this installed bundle's manifest" (`InstalledBundles::Record#manifest`): requires_chi, trust_level, needs, the scripts' names, context providers, block renderers, session settings and settings with their types, file descriptions, a profile's includes. Read from the kept `manifest.yml` (`origin: :kept`) when the record's `manifest_sha` is set and the file still has it (`InstalledBundles::Sha.matches?`, so a dev link is never checked), else from the record's `mirror` (`origin: :record`), in these cases: no kept file and no `manifest_sha` (a record from before chi kept it; no problem); no kept file, or something other than a file in its place, while `manifest_sha` is set (`:missing`); a kept file and no `manifest_sha` (a chi without the kept manifest rewrote the record: `problems["manifest.yml"] = :stale`); a kept file with another sha, or one that isn't a YAML mapping (`:edited`); the sha matches (`:kept`). `#standing` is that symbol, `#key_problems` the rest. The kept file is read by `BundleManifest.tolerant` key by key in a fixed order (its comment): a key that doesn't parse under this chi takes the mirror's value if that parses, else empty, with its message in `problems` (a reader that logged it logs that); `block_renderers` is checked against the record's scripts when the kept `scripts:` fails, and an older install's `hooks:` is ignored (no problem row). `description` and `unknown_keys` come only from a kept file; a profile's `includes` is always the record's (its members, identity). The value is deep-frozen, since callers share it. One process-wide cache (a Hash under a Mutex, cleared at `CACHE_LIMIT`) keyed by the record value and the kept file's stat (mtime, size, inode, device; a dev link's target): chi web asks per request, a worker at start and per `ContextProviders.resolve`. `#requires_chi_failure(version = VERSION)` is the one requires_chi gate; `#experimental?`, `#needs?`, `#context_providers?`, `#block_renderers?` |
|
|
72
|
+
| `ManifestStanding` (manifest_standing.rb) | the one owner of the words for an installed bundle's `manifest.yml` as `InstalledBundles::Manifest` read it: `.state` (`:kept`, `:legacy`, `:stale`, `:missing`, `:edited`), `.label` (`[kept]` / `[from the install record]`), `.line(bundle, refused:)` (the case and the command: `chi bundle upgrade NAME` (reads it again from a git URL, or a source that didn't match, with why), `chi update keeps it` while untried, the source is gone (`Installer.source_gone_line`), `chi bundle install --dev SOURCE` for a dev record; for a kept one, only the keys whose `BundleManifest::SINCE` floor is above the record's `installed_by`: newer than its installer), `.keep(bundle, source_dir:, dry_run:)` → `Outcome` (the record after, the line, `kept`): `Provenance#adopt_manifest` from `source_dir`, else from the recorded source (a dir; a zip/tar through `PreparedSource`, cleaned up; never a git clone). Read by `ShippedUpdate` (`Row#manifest`, the plan's dry `keep` and apply's), `UpdateCommand#external_rows` (a `kept its manifest` row, else a warn row, before the bundle's re-check, which then sees the kept file) and `chi bundle status NAME` (`BundleCommand#manifest_line`: `Manifest:`, the label, `.status_line`: for a record with a folder source (a bundle chi ships: this chi's shipped copy at the recorded version, which `chi update` reads), a dry `adopt_manifest` first, so the line says whether `chi update` keeps it or why not; an archive isn't extracted there, its line says `chi update tries to keep it`; a profile chi doesn't ship is never kept by `chi update`, so its line names `chi bundle upgrade NAME`) |
|
|
73
|
+
| `InstalledBundles::Record`, `BundleHook`, `PluginRef` (installed_bundles/record.rb, bundle_hook.rb, plugin_ref.rb) | value objects for the record; tolerant of older records (missing keys read as empty). `InstalledBundles::Record`'s members are identity and state (name, version, scope, source, `installed_at`, `source_commit`, files and their marks, hooks, guardrails, scripts and the plugin with their shas, a profile's `includes`, `dev`, `dir`, the kept manifest's `manifest_sha` and `installed_by`, nil on a record from before it was kept); the manifest keys it records sit in one `mirror` Hash (`MIRROR_KEYS`, frozen: a key a later manifest gains is never mirrored) that only `InstalledBundles::Manifest` reads, so manifest data is read through `#manifest`. `BundleHook` is an older record's hook entry: `.parse` and `#sha256` (what the retire, uninstall and the trash selection read) |
|
|
74
|
+
| `BlockRenderers` (`lib/samagotchi/block_renderers.rb`) | a manifest's `block_renderers:`: `.parse_list`, and what chi web asks without loading plugins: `.for_installed` (first bundle by name wins a language; a record with an error, an unmet `requires_chi` or a list that doesn't parse is skipped) and `.script_path` (`load` membership first, then `InstalledBundles::Sha.matches?`). `BundleManifest` checks each `load` is a `scripts:` key; the files are ordinary scripts everywhere else ([block-renderers.md](block-renderers.md)) |
|
|
62
75
|
| `Builder` | `chi bundle build`: memories (+ the installed bundle's rules, plugin, scripts; never an older record's hooks) → zip/tar/dir |
|
|
63
76
|
| `Profile` | meta bundles (`includes:`): install the members, record which; `InstallResult#kept_own` names a new member's memory files the user already had, with other bytes (`kept_own_line`, printed by `chi bundle`, `chi update` and `chi bootstrap`); a dry run runs each member's Installer as a dry run too, so it names them as well |
|
|
64
77
|
| `SystemBundle`, `ShippedUpdate` | the built-in system bundle (`ensure!` at Engine start, `sync` in `chi update`) and `chi update`'s upgrade of shipped bundles; both drive the Installer with `upgrade: true` and `Remerge` at an equal version (`ShippedUpdate::Row`'s `:would_merge`, `:merged`; `SystemBundle::Result`'s `:merged`). `SystemBundle` also puts back a memory missing at an equal version, that file alone, with no Installer (`verify_files_present`, `Provenance#record_restored`), checked against the manifest's `files:` sha as an installed one is (`FileDigest.mismatch`). A sync's `Result#warnings` reach `chi update`'s row (`UpdateCommand#system_bundle_row`) and `chi bootstrap`'s line (`BootstrapCommand#system_bundle_line`); `ShippedUpdate.apply` puts an update's `Checksum mismatch` warnings in `Row#note`. `ensure!` echoes a merge in one line, in the row's words. That reaches a terminal launch; a worker has only its log (`Log.configure(stderr: false)`), so every merge leaves a note on the file's record (`Installer#note_merges`, a failed run's too, and `Remerge#note_merges`; `Provenance#note_merged`: version, time, trash dir). `chi bundle status` shows it, and `chi update` reads the notes before the run (`SystemBundle.merge_notes`, `ShippedUpdate::Row#earlier`), names them in the row and clears after it those exact ones and the notes of the files that run merged (a worker's meanwhile, on another file, stays), unless it was a dry run, the row failed or has no place for them (a skipped system row), or the run is unattended (`ChildEnv::UNATTENDED_UPDATE`, which `Web::UpdateOps` sets for `update.auto`, an env marker so a hand-over's exec keeps it and an older chi ignores it; `--json` alone says nothing, as a person or script may use it). `chi bundle upgrade` clears the notes of what it printed, and `--force` those of the files it replaced. `--json`'s `merged` is this run's, `earlier` the notes'. `ensure!` says what an upgrade left behind and nothing of a file already behind, which `Result#behind` still has for the row. A plan or sync that can't read a file is that bundle's failed row, in `Trash.failure_message`'s words (`ShippedUpdate.plan_row`, `SystemBundle.sync`). At an equal version both keep the shipped `manifest.yml` for a record an older chi wrote (`Provenance#adopt_manifest` from the shipped dir): `SystemBundle.sync` under its lock, not in a dry run (so at the first Engine start or `chi update` after the upgrade, once), and `ShippedUpdate.apply` for a row that ends `:up_to_date` or `:merged` (`#keep_manifest`, through `ManifestStanding.keep`: `Row#manifest` is its line, `would keep its manifest` from the plan's dry run, appended to the row's status); a bumped bundle gets it from its Installer. `ShippedUpdate::Row#replaced` is what the upgrade copies to the trash (`ShippedUpdate.trash_bound`: the edited `AssetState`s against the shipped source over the rules, plugin and scripts folders, and `Trash.edits` over an older record's `hooks/` (which `#retire_hooks` removes whole), no recorded sha counting as edited), the same rule and files as `AssetInstaller`'s copies. `ShippedUpdate.edited_executables` (`chi bundle check`'s "does chi load it?") stays sha-only, as `Status.plugin_status` does. `ShippedUpdate.external` is the rest: what `chi update` only checks |
|
|
65
|
-
| `InstalledCopy`, `BundleCommand::InstalledCheck` | `chi update`'s re-check of the bundles chi didn't ship ([docs/cli.md](../cli.md#updating)). `InstalledCopy` lays a record and its installed files out as a source folder (manifest.yml from `
|
|
78
|
+
| `InstalledCopy`, `BundleCommand::InstalledCheck` | `chi update`'s re-check of the bundles chi didn't ship ([docs/cli.md](../cli.md#updating)). `InstalledCopy` lays a record and its installed files out as a source folder (manifest.yml from `BundleManifest.write`, the files' own shas, memories from `bases/`; its `files:`, `plugin:` and `scripts:` are always what the record and the copy hold (no `hooks:`), so a memory the install left out or one with no base gives no `missing-file`, and every other key is the kept `manifest.yml`'s when `InstalledBundles::Manifest` read it, so the check sees its unknown keys, else the mirror's; a kept key that didn't parse keeps the value `InstalledBundles::Manifest` fell back to, since `InstalledCheck` already names its problem); `InstalledCheck` forks per bundle (a plugin's `exit` or hang is that bundle's row; stdio to /dev/null, so `--json` stays parseable; `TIMEOUT`, then KILL of its group) and runs `Check.new(dir, installed: true)` there, which leaves out what only suits a source tree. Its `boundary` finding is narrower there than in a source tree: `Testing::Boundary.gone?` calls a reference gone only when its constant doesn't resolve or the object has no method the name names, so a bundle reaching `Samagotchi::Log` gets no row. lib loads lazily, so when a name doesn't resolve `gone?` requires every file of this chi's library in that same child and asks again (about 0.2 s, only for a bundle that reaches into chi at all); anything it can't read — a `const_get`, a require of a file that is there — is taken as still there. The fork is the point: `Sandbox` swaps ENV and the plugin's code is arbitrary. `UpdateCommand#external_rows` makes the rows (`level`, never `failed`) and holds the check back while a newer gem is yet to take over (`@not_checked`), since a fork is this chi's code |
|
|
66
79
|
| `Uninstaller`, `Trash`, `Status`, `Listing` | remove (the bundle's own folder too: an edited file there is copied to the trash first, `Uninstaller#trash_copy_line`); keep removed files (`Trash#move`) and a copy of overwritten ones (`Trash#copy`, its `as:` keeping a subfolder); `Provenance.unchanged?` (the record's checksum, else the base; neither counts as edited) is the one edited rule, read by `prune_dropped_files`, the uninstall's refusal and `chi bundle status`'s `modified`; `chi bundle status` (per file, `behind`, `merge_note`, `unreadable`; per rule and script `Status.asset_states`: ok, `modified` = `AssetState#edited?`, missing; `issues=` counts behind, missing and unreadable files, a missing or edited rule (it doesn't load) and a missing script, not an edited memory or script); `chi bundle list` (`Installed#behind`) |
|
|
67
|
-
| `
|
|
68
|
-
| `EntrySize` | one memory's size in tokens: `memory.entry_warn_tokens`' crossing note after a memory write, `chi self`'s `big memories` row |
|
|
69
|
-
| `
|
|
80
|
+
| `MemoryIndex::Updater`, `MemoryIndex::Sync` | the managed `index.md` lines (Installer; and the write/edit tools for memories) |
|
|
81
|
+
| `MemoryIndex::EntrySize` | one memory's size in tokens: `memory.entry_warn_tokens`' crossing note after a memory write, `chi self`'s `big memories` row |
|
|
82
|
+
| `MemoryIndex::Size` | one scope's memory index as the prompt carries it (tokens, lines, bytes): `memory.index_warn_tokens`' crossing note after a memory write, `chi self`'s summary, the prompt's figures (`SystemPrompt`) |
|
|
70
83
|
| `Placeholder` | `{{placeholder}}` patterns left in an installed memory, one line per file from `Installer#detect_placeholders`; a hint, never a gate |
|
|
71
84
|
|
|
72
85
|
A dev install (`chi bundle install --dev PATH`, `Installer#initialize(dev: true)`) links instead of copying:
|
|
73
86
|
`AssetInstaller#place` symlinks each rule file, plugin and script into `.bundles/<name>/` to its realpath in
|
|
74
87
|
the source (memories are still copied: their bases and the index are the install's), and the record gets `"dev": true`
|
|
75
|
-
(`
|
|
76
|
-
place of every rule, plugin and script sha256. `
|
|
88
|
+
(`InstalledBundles::Record#dev`, `source` the realpath) with `InstalledBundles::Sha::DEV` (`sha256:dev`, never a hex digest) in
|
|
89
|
+
place of every rule, plugin and script sha256. `InstalledBundles::Sha.matches?` / `.unchecked?` read it as "not
|
|
77
90
|
checked", which is how the readers below skip it for that bundle only. `Installer#refuse_dev_mismatch` keeps a dev
|
|
78
91
|
and a normal install from replacing each other (this is also why `chi bundle upgrade` refuses a dev bundle);
|
|
79
92
|
`Uninstaller` removes links with `rm_rf`/`rm_f`, which never follow them into the source.
|
|
80
93
|
|
|
81
|
-
Readers of the installed state
|
|
82
|
-
`
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
Readers of the installed state ask one verdict and keep only their reaction. The verdict is
|
|
95
|
+
`InstalledBundles.standings` (the walk) or `.standing(name)` (one record): a `Standing` whose `refusal` is
|
|
96
|
+
`:unreadable` (the record doesn't read) or `:too_new` (requires_chi), then, for a file chi loads, runs, serves or
|
|
97
|
+
reads, `InstalledBundles::Dir#file_refusal(:plugin | :scripts | :guardrails, file, recorded)` (`:file_missing`,
|
|
98
|
+
`:file_unrecorded`, `:file_changed`; each kind keeps today's order and words, so the same failure wins as before).
|
|
99
|
+
What each does with a refusal stays its own:
|
|
100
|
+
|
|
101
|
+
| Reader | `:unreadable` | `:too_new` | a file's refusal |
|
|
102
|
+
|---|---|---|---|
|
|
103
|
+
| `Plugin::Loader.load_bundle` | a failure that fails closed (required) unless its kept `manifest.yml` reads and names no required plugin (`#unreadable_required?`) | a failure (required for a guardrail plugin) | a failure, the refusal's text |
|
|
104
|
+
| `GuardrailWiring#bundle_rules` | a required failure | `#too_new_bundle_rules` (the rules loaded before stay) | a required failure per rule file |
|
|
105
|
+
| `ContextProviders.resolve` / `.any?` | skipped | skipped, `providers_too_new` logged once (only when it declares providers) | n/a |
|
|
106
|
+
| `ContextProviders.command_for` | not refused (a `manifest.json` that doesn't parse raises `JSON::ParserError`: D7; one that isn't an object runs: D8) | `Invalid` | `Invalid`, per recorded script |
|
|
107
|
+
| `BlockRenderers.for_installed` / `.script_path` | lists none | skipped | `Invalid` |
|
|
108
|
+
| `SessionConfig.availability` | left out | a note, only when it has a plugin (D2) | a note |
|
|
109
|
+
| `BundleSettingsCheck.warnings`, `BundleNeeds.entry_markers`, `MemoryCommand.entries` | skipped | still read (D1, D5) | n/a |
|
|
110
|
+
| `MemoryBundle::Status.plugin_status` | n/a | `requires_failure` | `missing`, else `modified` (D9) |
|
|
111
|
+
|
|
112
|
+
`InstalledBundles.claimants` skips an unreadable record off the record itself (`Record#error?`), so a claimant
|
|
113
|
+
check reads no manifest. `ContextProviders`' once-per-process log is a Set under a Mutex, like `GuardrailWiring`'s
|
|
114
|
+
kept-rules notice. The D rows are the plan's V2 decisions; until then each reaction is pinned as it is.
|
|
115
|
+
They read shas and state off the record, and
|
|
116
|
+
manifest data (requires_chi, needs, providers, renderers, settings) through `InstalledBundles::Record#manifest`
|
|
117
|
+
(`InstalledBundles::Manifest`: the kept `manifest.yml` when its sha holds, else the record's mirror), as do `SessionConfig`, `BundleSettingsCheck`, `BlockRenderers`, `Status`, `BundleCommand`'s
|
|
118
|
+
status and diff, `Builder` and `InstalledCopy`. The one requires_chi gate is `InstalledBundles::Manifest#requires_chi_failure`, which the runtime readers reach through `Standing` (`:too_new`). `GuardrailWiring#rules_stamp` stats each bundle's
|
|
90
119
|
`manifest.yml` with its `manifest.json` and `guardrails/*`, so a changed requires_chi re-reads the rules. No reader
|
|
91
|
-
calls `
|
|
92
|
-
A guardrail plugin (`plugin:` `required: true`) is known from `
|
|
120
|
+
calls `BundleManifest.new` on a kept file: `BundleManifest.tolerant` through `InstalledBundles::Manifest` is the one read.
|
|
121
|
+
A guardrail plugin (`plugin:` `required: true`) is known from `InstalledBundles::Manifest#plugin_required` before
|
|
93
122
|
`Plugin::Loader.load_bundle` builds it: the install records the flag in the record's `plugin:` (`PluginRef#required`,
|
|
94
123
|
`Provenance#write`'s `plugin_required:`), and the kept manifest's flag is ORed with it, so a missing, edited or
|
|
95
124
|
unparsable kept manifest.yml never drops it (an older chi's `PluginRef` ignores the key):
|
|
96
125
|
its failure goes to the hook failures as required (`ExtensionLoad#load_plugins` passes them as `guardrail_failures:`),
|
|
97
126
|
where the gate denies every tool call; a `chi.on(on_error: :fail_closed)` hook is wrapped `Hooks.wrap(policy: :deny)`.
|
|
98
|
-
|
|
127
|
+
`Plugin::Loader.load_bundle` asks the verdict (`InstalledBundles::Standing`, then `Dir#file_refusal(:plugin, …)`) and reacts (`.namespace_for` is the bundle's
|
|
99
128
|
`Samagotchi::Bundles::<bundle>` module); the loading itself is `Plugin::Loader.register_file` (one
|
|
100
129
|
plugin file: build, `register`, `commit!`), which raises instead of logging: the bundle test kit
|
|
101
130
|
(`Samagotchi::Testing::Bundle`) loads a bundle's source through them, unchecked. `Samagotchi::Testing::Install` is the
|
|
@@ -106,9 +135,9 @@ bundle, or a SyntaxError's own line), which `Install` maps from the installed co
|
|
|
106
135
|
back to the source dir.
|
|
107
136
|
|
|
108
137
|
Class-file hooks (retired). A record an older chi installed may still have a `hooks` map and `hooks/*.rb`
|
|
109
|
-
(`
|
|
138
|
+
(`InstalledBundles::Record#hooks`). Nothing loads them, and nothing announces them any more (the first turn, `chi bundle
|
|
110
139
|
status` and `chi update` did from 0.158 to 0.166). A source with
|
|
111
|
-
hooks is refused before its manifest is read (`
|
|
140
|
+
hooks is refused before its manifest is read (`BundleManifest::HooksRetired.refuse_source_files`, then `BundleManifest.read`),
|
|
112
141
|
strict or not, a dry run too; `ShippedUpdate`'s plan skips one the same way. Over such a record,
|
|
113
142
|
after the plugin and scripts (so a refused install leaves them), `AssetInstaller#retire_hooks` copies every edited or
|
|
114
143
|
unknown file under `hooks/` to the trash
|
|
@@ -217,7 +246,7 @@ copy is still there. Any other keeps its old base and mark, and the command exit
|
|
|
217
246
|
`select_memories` (all but `index.md`/hidden; with `--files` the named ones + their overlays, else leaving out files
|
|
218
247
|
another installed bundle owns) → `checksum_memories` → `installed_parts` (`Builder::InstalledParts`: the same-name
|
|
219
248
|
installed bundle's rules, plugin, scripts, context providers, else the scope dir's `guardrails/`) →
|
|
220
|
-
`stage_files` + `write_manifest` (requires_chi, needs, settings… from the installed bundle's `
|
|
249
|
+
`stage_files` + `write_manifest` (requires_chi, needs, settings… from the installed bundle's `InstalledBundles::Manifest`;
|
|
221
250
|
`trust_level` and `description` the CLI's, else that manifest's; a kept manifest's unknown keys carried, each with a
|
|
222
251
|
`unknown_key_line` warning) in a temp dir → `write_out` (zip, tar, tgz, or a new/empty dir). An installed
|
|
223
252
|
profile's name is refused (`refuse_profile!`): a build can't remake its includes.
|
data/docs/internals/engine.md
CHANGED
|
@@ -284,7 +284,7 @@ long as the Engine (tools, hooks, the gate). The rules an edit gets wrong:
|
|
|
284
284
|
`tool_refs` (`ToolResponse::SAVED_KEYS`, never sent) and `MessageParts#tool_part` re-checks them
|
|
285
285
|
(`RowRefs.for_display`).
|
|
286
286
|
- An unknown tool gets `ToolSurface#unknown_tool_error` ("Error: no such tool ...", never repeating the wrong name).
|
|
287
|
-
- Edit and write: the file is diffed, and a memory's index line refreshed (`
|
|
287
|
+
- Edit and write: the file is diffed, and a memory's index line refreshed (`MemoryIndex::Sync`). At most
|
|
288
288
|
`MAX_IMAGES_PER_RESULT` images per result. Non-UTF-8 bytes are scrubbed.
|
|
289
289
|
- The output cap (`max_tool_output_chars`, a `memory_read`'s `memory.read_max_chars`) cuts by the tool's
|
|
290
290
|
`ToolOutputCut` policy; an execute's whole output is saved by `ToolOutputFiles` in `TurnContext#session_dir`. See
|
|
@@ -133,7 +133,12 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
|
|
|
133
133
|
`ArgumentError` for another `not_found`, `Session::AmbiguousId`,
|
|
134
134
|
`SessionManager::OwnedByTUI` / `DeleteRefused` / `ArchiveRefused` / `RestartRefused`, `SessionContinue::Refused`,
|
|
135
135
|
and `ModelProfile::MissingModel` for `invalid_model` (no model there, or `--model`'s host unknown there: "could not
|
|
136
|
-
start a session: …", exit 1, as here).
|
|
136
|
+
start a session: …", exit 1, as here). A delete's or archive's `409 tasks_running` carries `op` (`delete` or
|
|
137
|
+
`archive`), `tasks` (`{running, unverified, unreadable}`), `worker_stopped`, `stopped_worker` (whose; an older chi web sends only the Boolean) and a chain's `links`: `raise_refusal`
|
|
138
|
+
rebuilds `DeleteRefused` or `ArchiveRefused` by `op`, with the `RunningTasks::Listing`, and makes the words here
|
|
139
|
+
(`RunningTasks.words`), not from chi web's `message`. Its own code, not archive's `busy`: an older client prints
|
|
140
|
+
`RemoteFailed "… answered 409 tasks_running: …"` rather than "a turn is running". `--stop-tasks` asks for the
|
|
141
|
+
`stop_tasks` feature first (`RemoteTooOld` without it).
|
|
137
142
|
Checks the client would make locally come back as `SessionAccess::Refused` (`parent_answers_refused`,
|
|
138
143
|
`parent_continue_refused`, `no_vision`, exit 1) or `BadRequest` (the other `invalid_*`, `missing_fields`, `bad_images`,
|
|
139
144
|
exit 2, the usage-error path). That is for the routes `raise_refusal` reads (create, uploads, …). `POST …/turn` is
|
|
@@ -41,9 +41,9 @@ These are reader labels, not stored values:
|
|
|
41
41
|
|---|---|
|
|
42
42
|
| `absent` | No session file; a leftover sidecar directory may still exist (its facts are ignored). |
|
|
43
43
|
| `tui_owned` | `owner.lock` held with kind `tui` (a one-shot `chi -p --non-interactive` owns it): an in-process one-turn host, not a worker. Wins over a stop, a start, an archive. |
|
|
44
|
-
| `deleting` | `owner.lock` held with kind `deleting` while the session's files go (`WorkerLink` reads it as `Starting`). Every delivery is refused (`WakePolicy`'s `:deleting`). |
|
|
44
|
+
| `deleting` | `owner.lock` held with kind `deleting` while the session's files go (`WorkerLink` reads it as `Starting`). Every delivery is refused (`WakePolicy`'s `:deleting`); restart refuses it (`deleting`); a schedule skips it ("the session is being deleted"). |
|
|
45
45
|
| `stopping` | A worker holds the lock and the `stopped` marker exists, whatever its link. |
|
|
46
|
-
| `skew` | A worker holds the lock and its sidecar speaks a newer protocol (`WorkerLink::Skew`). |
|
|
46
|
+
| `skew` | A worker holds the lock and its sidecar speaks a newer protocol (`WorkerLink::Skew`); a schedule skips it with Skew's short words. |
|
|
47
47
|
| `leaving` | The worker closed its Bridge and still holds the lock (`leaving_at`, `WorkerLink::Leaving`). |
|
|
48
48
|
| `booting_stuck` | A worker has held the lock past `WorkerLink::START_LIMIT` without its sidecar (`Starting`, stuck). |
|
|
49
49
|
| `booting` | A worker holds the lock without its matching sidecar yet (`Starting`); also an owner of unknown kind (a lock record still blank after `OWNER_READ_ATTEMPTS`). |
|
|
@@ -88,16 +88,21 @@ state. A cell is `:go`, `:wait` or the decider's own refusal reason; `SessionLif
|
|
|
88
88
|
- **Literal columns** (`LITERAL`): resume (`resume_session`), restart (`restart_session`: `stop_marked` in every
|
|
89
89
|
state with the stop marked: stopping, stopped, stopped_starting), stop (`stop_session`),
|
|
90
90
|
archive (`archivable!`), delete (`release_for_delete!`, without a stop), sched_chain and sched_same
|
|
91
|
-
(`Schedules#busy_reason`; `worker_busy` is "its worker is starting or leaving"
|
|
91
|
+
(`Schedules#busy_reason`; `worker_busy` is "its worker is starting or leaving", `deleting` the delivery's "the
|
|
92
|
+
session is being deleted", `worker_newer` `WorkerLink::Skew#short_message`) and attach
|
|
92
93
|
(`TerminalUI::LocalLink#live_worker`: `gone_stopped`, `gone_worker_newer`). They assume neutral op-local facts: not
|
|
93
94
|
scratch, saved status idle, no `input/`, no question or offer, not SIGSTOPped, features restart and activity, an idle
|
|
94
95
|
worker with no streams. Absent's delete and schedule cells are unreachable (a gone session is refused first).
|
|
95
96
|
|
|
96
97
|
Link resolution (`SessionInbox::Head.resolve`, `Schedules#target_of`) stays outside: the cells are the link's own.
|
|
97
98
|
|
|
99
|
+
The running-tasks check of a user's delete and archive (`SessionManager::RunningTasks`, `tasks_running`) is op-local,
|
|
100
|
+
not an `ALLOWED` cell: it reads the transcript and each `task.json`, not the lifecycle's facts, and runs after the
|
|
101
|
+
lifecycle refusals (`refuse_scheduled!`, `archivable!`), before the worker is stopped.
|
|
102
|
+
|
|
98
103
|
`restart_session` is the first decider migrated to the table: its lifecycle precheck is `SessionLifecycle.read` (the
|
|
99
104
|
owner read through `session_owner`) and `ALLOWED[:restart]`: `owned_by_tui` raises `OwnedByTUI`, a refusal cell
|
|
100
|
-
raises `RestartRefused` with it as the reason (`starting`, `not_running`, `stop_marked`), `fallback` goes to
|
|
105
|
+
raises `RestartRefused` with it as the reason (`starting`, `not_running`, `stop_marked`, `deleting`), `fallback` goes to
|
|
101
106
|
`restart_fallback` (skew, a stuck start) and `go` asks the live worker. Its op-local checks stay where they were: the
|
|
102
107
|
SIGSTOP check (`:stopped`, the worker's pid: a different condition with its own words, before the table's refusal),
|
|
103
108
|
the worker's `restart` feature, the Bridge's reply and the fallback's holds. The matrix still drives it, so its
|
|
@@ -118,11 +123,13 @@ code can't make (a one-turn run's lock with a stop) is marked `reachable: false`
|
|
|
118
123
|
Every answer must equal `ALLOWED[op][state]` (for the session hub, `SHOWN[state]`: `Web::SessionSummary.build`'s
|
|
119
124
|
status and bridge_up, its `SessionRow`'s live), or be named by exactly one `KNOWN_DIFFERENCES` entry (op, a `when`
|
|
120
125
|
over the row, a plain reason); an entry that names no mismatch fails as stale. The entries are the findings for the
|
|
121
|
-
owner, not fixed: stop-first schedule
|
|
122
|
-
chain mode's starting check before any one-turn-run check; a start
|
|
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
|
|
128
|
+
marked after the stop holding a resume off;
|
|
123
129
|
`wake_for_report` reporting a worker's `:live` as `:owned`; the hub's bridge_up, live and status overlay. (Restart
|
|
124
|
-
never reading the stop and
|
|
125
|
-
|
|
130
|
+
never reading the stop, the restart and schedule reading a deleter as starting, the schedule's Skew words, and
|
|
131
|
+
`busy_reason`'s live branch falling through to the starting check were fixed: their entries went stale and were
|
|
132
|
+
removed.) The delivery columns are
|
|
126
133
|
generated from `WakePolicy::ROWS`, so for deliveries the matrix proves the states are drawn right (decide is a function
|
|
127
134
|
of the state), not what WakePolicy does; the literal columns and `SHOWN` are goldens.
|
|
128
135
|
|
|
@@ -151,6 +158,8 @@ These are documented race boundaries, not promises of an atomic lifecycle transi
|
|
|
151
158
|
| Stop reads an owner pid, then sends TERM. | `LifecyclePart#stop_session` (`session_manager/lifecycle.rb`): the pid can be reused between the owner read and `Process.kill`; protecting that requires a real pid-reuse scenario. | No unit pin: pid reuse/process signaling is not reliably representable without real processes. |
|
|
152
159
|
| Saved `status` is used as a lifecycle hint. | `LifecyclePart#restart_fallback_holds` and `RemovalPart#archive_refusal` (`session_manager/lifecycle.rb`, `session_manager/removal.rb`) use saved `running` status as a busy hint; status is not a lock or proof that a worker is alive. | Unit spec: pin fallback refusal from saved status without a live Bridge. |
|
|
153
160
|
| Stop/start ordering depends on wall-clock `at`. | `SpawnPart#claim_start` and `StartingMarker#claim` (`session_manager/spawn.rb`, `starting_marker.rb`) compare `starting.at` with `Session.stopped_at`; same-time starts are treated as before the stop. Clock adjustments across processes are not serialized. | Unit spec: pin the inclusive `at <= over_before` takeover boundary. |
|
|
161
|
+
| A delete stops a session's background tasks. | `RemovalPart#remove_session_files` (`session_manager/removal.rb`): with `running_tasks:` a stop, `RunningTasks.stop!` runs under the DELETING owner lock, after the `StartingMarker.fresh?` re-check and `still`, for up to ~4 s; meanwhile a send, a schedule or a resume is refused as deleting. With `REFUSE` the same seat lists the final file again and refuses a task started since the op's check (`worker_stopped` set when the op stopped the worker; `stopped_worker` names whose). `SessionChain::Delete` lists a whole batch (a link and its D7 delegates) once under the batch's locks, before any of it goes (`refuse_tasks!`), and its removals then skip the per-id re-check (`RunningTasks.after_check`), so no refusal comes after part of the batch went. A chain with `--stop-tasks` stops link by link inside each `locked(batch)`, serially: up to ~4.5 s per link, N links N times that, with that batch's locks held; a link refused part-way keeps its tasks running. A stop that outlives the join's deadline (`unconfirmed`) is reported as not stopped and may still finish after the files are gone (its thread goes on writing the record under the session's working directory, not the session dir). | `removal_spec.rb` (a worker's `OwnerLock.acquire` during the stop fails; the re-check refuses a new task), `session_chain/delete_spec.rb` (link by link, part-way; a task started after the up-front check keeps the link, its delegate and the chain whole). |
|
|
162
|
+
| An archive stops a session's background tasks without a lock. | `RemovalPart#archive_session`: the stop runs after the tree's workers were stopped and waited for (`stop_session(wait:)`), before the marker; a worker that outlives the wait records the stop itself from the `stop_requested_by` flag on disk (`record_exit_status` / `correct_finished_record`). A task started after the listing isn't stopped: archive already refuses `busy` up front. | `removal_spec.rb` (the stop sees no owner left). |
|
|
154
163
|
| Several methods write or remove the same marker. | The definitions/callers in `session.rb`, `starting_marker.rb`, `archive_store.rb`, `bridge.rb`, and `reminder_carry.rb` are the source of truth; these APIs have multiple call sites. | `spec/session_lifecycle_writers_spec.rb` pins the call-site allow-lists; it does not claim their operations are one transaction. |
|
|
155
164
|
|
|
156
165
|
## Adding a transition
|
|
@@ -31,7 +31,7 @@ page. A factory dep a new version stops passing is the same hazard the other way
|
|
|
31
31
|
out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
|
|
32
32
|
until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
|
|
33
33
|
`turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
|
|
34
|
-
`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` (Deleting a chained session, below), `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_reader.js`, `ws_way_in.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), `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), `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).
|
|
34
|
+
`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` (Deleting a chained session, below), `running_tasks.js` (a delete's or archive's 409 `tasks_running`: the tasks' line, the second confirm, the toast's suffix; DOM-free, so `stop_sheet.js` and `delete_sheet.js` 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_reader.js`, `ws_way_in.js`, `ws_item_sig.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), `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), `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).
|
|
35
35
|
|
|
36
36
|
## One page, every viewer
|
|
37
37
|
|
|
@@ -55,7 +55,7 @@ their viewer (The viewer, below), their show and stream are filtered (`Web::Part
|
|
|
55
55
|
| **`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` |
|
|
56
56
|
| **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 |
|
|
57
57
|
| **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) |
|
|
58
|
-
| **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
|
|
58
|
+
| **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 |
|
|
59
59
|
| **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 |
|
|
60
60
|
| **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 |
|
|
61
61
|
| **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) |
|
|
@@ -587,6 +587,23 @@ none. The replayed card opens the turn as live; a question answered earlier in t
|
|
|
587
587
|
replayed `question_answered`, and `releaseHeldWait` reads a pending card, not the `waiting` class the replay's one task
|
|
588
588
|
hasn't refreshed yet.
|
|
589
589
|
|
|
590
|
+
**After the turn's end, reloaded:** a drawn turn's pieces beside its block come back in the order the rows above left
|
|
591
|
+
them, live (`turn_settle.js settleOrder` over the drawing's events): a reminder or a merged line where it arrived; a
|
|
592
|
+
question with a lead-in at its request (the turn opens first: what the extras held goes to the history before the
|
|
593
|
+
lead-in, as `openTurn` does), one without at its answer; a card that waited when it arrived (its arrival
|
|
594
|
+
wait is the drawing's first `part_settled` for it, `Bridge::TurnAccumulator#fold_card`: the card part keeps only its
|
|
595
|
+
latest version) where it stopped waiting while the turn was opened, else at the hand-off; what still waits at the end
|
|
596
|
+
goes last (a warning with the block's kept cards). A question is drawn as an empty slot (`turn_block.js questionSlot`,
|
|
597
|
+
`data-question-slot`, stamped `data-drawn`) that `cards_place.js placeResolvedQuestion` fills with the resolved card
|
|
598
|
+
(its lead-in as before); a turn drawn without its question events (an older drawing) gets today's place (before the
|
|
599
|
+
lines steered after it and the answer), and `placeSnapshotCards` drops a slot no question came for. `history_shape.js`
|
|
600
|
+
reads an empty slot as a `question` item, which the reload check drops with the cards. A drawing written before
|
|
601
|
+
`settle` parts orders its cards by their latest version. **Mid-turn**, a reload or a join still can't say when a card
|
|
602
|
+
stopped waiting (the replay has no cards; the snapshot's are upserted after it): `stage_cuts_parity.test.js` lists
|
|
603
|
+
those differences. The approval question is asked after its call's `tool_call_started` (`ToolRunner#run`:
|
|
604
|
+
`settle_ask` runs after the row); a `before_tool_call` hook's question is asked before it (in the gate's `evaluate`),
|
|
605
|
+
where live shows no lead-in but the reload gives it one (not fixed).
|
|
606
|
+
|
|
590
607
|
## Frames
|
|
591
608
|
|
|
592
609
|
During a turn the cost is frames, not code: JS, layout and style are each a few percent of a core, while an animation
|
|
@@ -648,8 +665,12 @@ for the set, its jumps and its list, and `whatChiHas` for refs.js), `ws_way_in.j
|
|
|
648
665
|
flag turn_html.js reads; on only once the reader is attached). State: the reader's own closure (the open item, its
|
|
649
666
|
answer, the tab), never `store.current`. The reader is a `section` in `#center` over the history and the composer
|
|
650
667
|
(both `inert` while it is open, so their scroll place stays; a phone's is `position: fixed`). Each item answer goes
|
|
651
|
-
through `createLatest` keyed by the session and the item
|
|
652
|
-
|
|
668
|
+
through `createLatest` keyed by the session and the item, and an answer older than the drawn one within one running
|
|
669
|
+
turn (same `turn_id`, lower `at`) is dropped (`ws_item_sig.js olderAnswer`); a new server snapshot (`onServer`, and the
|
|
670
|
+
peek's `refresh` on an event) asks again only when the open item's server signature changed (`ws_item_sig.js serverSig`:
|
|
671
|
+
its `count`, `ops`, `tokens`, `state`, `has_drop`, `pinned`; mid-turn the route answers the running turn's view as of
|
|
672
|
+
its last step). The peek asks `latest=1` (only the events `peekOf` picks, and `counts`), the reader the whole
|
|
673
|
+
timeline. Leaving the session closes it and the peek: `session_view.js
|
|
653
674
|
forgetSession` (a switch, the start page, + New, a deleted or archived session) calls `wsPreview.reset()`, so
|
|
654
675
|
`#center` is never left inert, whatever the next session's GET does; close gives focus back to where it was at the
|
|
655
676
|
open (not after a jump or a reset). Styles: `ws_preview.css`.
|
|
@@ -161,9 +161,27 @@ Engine emits only a set that differs from the last one), and the GET builds from
|
|
|
161
161
|
does one from an older worker without the field, its answer then behind the turn's events, which the page keeps.
|
|
162
162
|
|
|
163
163
|
**An item's timeline while a turn runs** (`GET …/working_set/item`, [Timeline](#timeline-what-the-model-has-of-one-item))
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
is the running turn's as of its last step, the moment the rows are from. At every `:generation_started`, on the turn's
|
|
165
|
+
thread and before the event goes out, `EventFanout#keep_turn_view` keeps a `TurnView`: a shallow copy of the running
|
|
166
|
+
turn's conversation (`conversation.map(&:dup)`, a new Array and each entry Hash dup'ed, strings shared), its size
|
|
167
|
+
(`at`), the set's strategy, the session's folder and the turn's id. Every step, not only when the set changed (an edit
|
|
168
|
+
or a forget changes what the model has without changing the rows). A copy, because the turn's thread writes entries in
|
|
169
|
+
place (`LLMContextEdit.store`'s `:edits`) while a Bridge thread reads; shallow is enough because every in-turn writer
|
|
170
|
+
changes top-level keys only (`LLMContextEdit.store`/`.remove`, the forget store, ChatLoop's `:interrupted`; KernelLoop
|
|
171
|
+
appends or pops; `spec/engine_working_set_spec.rb` pins it). Cost: about 0.02 ms and 32 KB for 200 entries, 0.03 ms and
|
|
172
|
+
82 KB for 500, one copy kept. `EventFanout#turn_view` hands it out only while its turn id is the running turn's (the
|
|
173
|
+
guard `Engine#live_conversation` uses), so a view left from another turn is never read; `Engine#end_turn` also drops
|
|
174
|
+
it (`EventFanout#drop_turn_view`) under the event lock as it puts the kept messages in place, before its
|
|
175
|
+
`:working_set_updated` and before the turn has ended, so no answer in that gap is the running view. `Engine#working_set_view` is
|
|
176
|
+
the conversation the set is built from now (that view, else a copy of the session's messages: a starting turn shares
|
|
177
|
+
their entries and writes them in place), read by `Engine#working_set_item`
|
|
178
|
+
(the Bridge's `GET working_set/item`, feature `working_set_item`: chi web asks a worker with it for just the item and an
|
|
179
|
+
older worker for its snapshot, as the route below says) and by `/working-set`'s listing (mid-turn the copy holds the
|
|
180
|
+
sent note, so no op is pending). The answer carries `at`, `running` and, mid-turn, `turn_id`. The page asks again only
|
|
181
|
+
when the open item's server signature changed (its `count`, `ops`, `tokens`, `state`, `has_drop`, `pinned`; a re-read
|
|
182
|
+
raises `count`), at the peek's refresh on an event and the reader's `onServer`; it drops an answer with a lower `at`
|
|
183
|
+
only within one running turn (`at` can go down at a turn's end, which keeps less). The peek asks `latest=1`
|
|
184
|
+
(`Timeline#peek_h`: only the events `peekOf` picks and the per-op `counts`); the reader the whole timeline.
|
|
167
185
|
|
|
168
186
|
## Steering: drop and undrop
|
|
169
187
|
|
|
@@ -283,8 +301,16 @@ file is; nil without a stamp.
|
|
|
283
301
|
|
|
284
302
|
**The route.** `GET /api/sessions/:id/working_set/item?kind=&key=` (`WorkingSetRoutes#handle_working_set_item`,
|
|
285
303
|
`:owner, :session`: a participant gets 403 from `not_permitted_for`) answers `timeline.to_h`, and with `&now=1` for a
|
|
286
|
-
memory `now:` too.
|
|
287
|
-
`
|
|
304
|
+
memory `now:` too. A live worker that advertises `working_set_item` (`WorkingSet::ITEM_FEATURE`,
|
|
305
|
+
`WorkerLink.live_features`) is asked for just the item: the Bridge's `GET working_set/item` (`Engine#working_set_item`,
|
|
306
|
+
the query encoded with `URI.encode_www_form`, so a key with spaces or `&` arrives whole), its answer passed on with its
|
|
307
|
+
`at` and `running`; no snapshot is fetched and the session file is not read. No reply, or one other than 200 or 404, is
|
|
308
|
+
`502 bridge_error`: the page marks its ask failed and asks again at the next event, instead of drawing lagging messages
|
|
309
|
+
it would not ask again for. An older worker without the feature, or one answering 404 (no such route), is read as
|
|
310
|
+
before: `working_set_source` over its snapshot's messages; with no live worker the file's (no Bridge call). Either way
|
|
311
|
+
the session's strategy and folder. `&latest=1` (the peek) answers `Timeline#peek_h` instead: only the events
|
|
312
|
+
`ws_timeline.js peekOf` picks (the latest edit with a diff and the newest event after it, else the newest run that isn't
|
|
313
|
+
an edit), the per-op `counts` (`read`, `edit`) and `latest: true`. Its texts
|
|
288
314
|
are whole (about 1.7k lines at the most seen in real sessions): the tool limits bound them (`read.truncate_at_bytes`,
|
|
289
315
|
the ToolRunner cap), so the page asks this route, never a row's `output` (a 2000-char `ToolOutputCut::WEB_PREVIEW_CHARS`
|
|
290
316
|
preview for a long one). 400 without a known `kind` and a `key`.
|