samagotchi 0.178.0 → 0.180.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.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -1
  3. data/docs/architecture.md +4 -2
  4. data/docs/bundles.md +48 -8
  5. data/docs/cli.md +3 -1
  6. data/docs/configuration.md +1 -1
  7. data/docs/context.md +32 -1
  8. data/docs/guardrails.md +2 -1
  9. data/docs/internals/attached-context.md +26 -4
  10. data/docs/internals/background-tasks.md +5 -1
  11. data/docs/internals/block-renderers.md +4 -3
  12. data/docs/internals/bridge.md +11 -2
  13. data/docs/internals/bundles.md +65 -34
  14. data/docs/internals/engine.md +1 -1
  15. data/docs/internals/web-frontend.md +81 -3
  16. data/docs/plugins.md +20 -5
  17. data/docs/releasing.md +3 -3
  18. data/docs/scheduling.md +4 -0
  19. data/docs/sessions.md +8 -2
  20. data/docs/testing.md +8 -1
  21. data/lib/samagotchi/block_renderers.rb +33 -16
  22. data/lib/samagotchi/bootstrap/bundles.rb +2 -2
  23. data/lib/samagotchi/bootstrap_command.rb +1 -1
  24. data/lib/samagotchi/bridge/card_wait.rb +34 -0
  25. data/lib/samagotchi/bridge/turn_accumulator.rb +22 -4
  26. data/lib/samagotchi/bundle_command/check.rb +10 -10
  27. data/lib/samagotchi/bundle_command/installed_check.rb +2 -2
  28. data/lib/samagotchi/bundle_command/try/sandbox.rb +3 -3
  29. data/lib/samagotchi/bundle_command.rb +22 -18
  30. data/lib/samagotchi/bundle_manifest.rb +579 -0
  31. data/lib/samagotchi/bundle_needs.rb +9 -8
  32. data/lib/samagotchi/bundle_settings_check.rb +13 -9
  33. data/lib/samagotchi/bundles/claude-peer/manifest.yml +5 -3
  34. data/lib/samagotchi/bundles/claude-peer/plugin.rb +4 -4
  35. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +11 -6
  36. data/lib/samagotchi/bundles/codex-peer/manifest.yml +5 -3
  37. data/lib/samagotchi/bundles/codex-peer/plugin.rb +4 -3
  38. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +11 -6
  39. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  40. data/lib/samagotchi/bundles/system/memory_guide.md +1 -1
  41. data/lib/samagotchi/config.rb +2 -2
  42. data/lib/samagotchi/context_absorber.rb +36 -6
  43. data/lib/samagotchi/context_note.rb +8 -5
  44. data/lib/samagotchi/context_providers.rb +30 -29
  45. data/lib/samagotchi/context_sources.rb +42 -12
  46. data/lib/samagotchi/engine/messages.rb +1 -1
  47. data/lib/samagotchi/events.rb +6 -5
  48. data/lib/samagotchi/guardrail_wiring.rb +20 -21
  49. data/lib/samagotchi/guardrails/approval.rb +3 -2
  50. data/lib/samagotchi/guardrails/outside.rb +3 -3
  51. data/lib/samagotchi/{memory_bundle → installed_bundles}/bundle_hook.rb +1 -1
  52. data/lib/samagotchi/installed_bundles/dir.rb +91 -0
  53. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_digest.rb +1 -1
  54. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_standing.rb +2 -2
  55. data/lib/samagotchi/{memory_bundle/installed_manifest.rb → installed_bundles/manifest.rb} +21 -21
  56. data/lib/samagotchi/{memory_bundle → installed_bundles}/plugin_ref.rb +2 -2
  57. data/lib/samagotchi/{memory_bundle/installed_bundle.rb → installed_bundles/record.rb} +17 -17
  58. data/lib/samagotchi/installed_bundles/sha.rb +41 -0
  59. data/lib/samagotchi/installed_bundles/standing.rb +65 -0
  60. data/lib/samagotchi/installed_bundles.rb +105 -0
  61. data/lib/samagotchi/memory_bundle/asset_installer.rb +7 -7
  62. data/lib/samagotchi/memory_bundle/builder.rb +13 -13
  63. data/lib/samagotchi/memory_bundle/file_state.rb +9 -9
  64. data/lib/samagotchi/memory_bundle/installed_copy.rb +6 -6
  65. data/lib/samagotchi/memory_bundle/installer.rb +33 -33
  66. data/lib/samagotchi/memory_bundle/listing.rb +5 -5
  67. data/lib/samagotchi/memory_bundle/manifest_standing.rb +7 -7
  68. data/lib/samagotchi/memory_bundle/merger.rb +15 -15
  69. data/lib/samagotchi/memory_bundle/profile.rb +8 -8
  70. data/lib/samagotchi/memory_bundle/provenance.rb +59 -192
  71. data/lib/samagotchi/memory_bundle/remerge.rb +16 -16
  72. data/lib/samagotchi/memory_bundle/shas.rb +2 -2
  73. data/lib/samagotchi/memory_bundle/shipped_history.rb +1 -1
  74. data/lib/samagotchi/memory_bundle/shipped_update.rb +17 -17
  75. data/lib/samagotchi/memory_bundle/status.rb +19 -16
  76. data/lib/samagotchi/memory_bundle/system_bundle.rb +12 -12
  77. data/lib/samagotchi/memory_bundle/trash.rb +2 -2
  78. data/lib/samagotchi/memory_bundle/uninstaller.rb +8 -8
  79. data/lib/samagotchi/memory_bundle.rb +2 -2
  80. data/lib/samagotchi/memory_command.rb +4 -4
  81. data/lib/samagotchi/{memory_bundle → memory_index}/entry_size.rb +8 -8
  82. data/lib/samagotchi/{memory_bundle/index_size.rb → memory_index/size.rb} +6 -6
  83. data/lib/samagotchi/{memory_bundle/index_sync.rb → memory_index/sync.rb} +5 -5
  84. data/lib/samagotchi/{memory_bundle/index_updater.rb → memory_index/updater.rb} +2 -2
  85. data/lib/samagotchi/memory_usage.rb +5 -5
  86. data/lib/samagotchi/muted_memories.rb +1 -1
  87. data/lib/samagotchi/peer_exchanges.rb +76 -0
  88. data/lib/samagotchi/plugin/context.rb +4 -0
  89. data/lib/samagotchi/plugin/loader.rb +35 -33
  90. data/lib/samagotchi/plugin/peer.rb +42 -11
  91. data/lib/samagotchi/project_subfolders.rb +9 -9
  92. data/lib/samagotchi/reply_wait/target.rb +11 -4
  93. data/lib/samagotchi/self_report.rb +14 -14
  94. data/lib/samagotchi/session_access/local.rb +16 -1
  95. data/lib/samagotchi/session_access/remote.rb +2 -1
  96. data/lib/samagotchi/session_config.rb +29 -19
  97. data/lib/samagotchi/session_manager/running_tasks.rb +15 -2
  98. data/lib/samagotchi/session_retention.rb +13 -4
  99. data/lib/samagotchi/session_stores.rb +3 -0
  100. data/lib/samagotchi/system_prompt.rb +4 -4
  101. data/lib/samagotchi/terminal_ui/attach_launcher.rb +5 -1
  102. data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
  103. data/lib/samagotchi/terminal_ui/formatting.rb +15 -5
  104. data/lib/samagotchi/terminal_ui/join_replay.rb +1 -1
  105. data/lib/samagotchi/terminal_ui/model_segments_text.rb +5 -5
  106. data/lib/samagotchi/terminal_ui.rb +4 -1
  107. data/lib/samagotchi/testing/bundle.rb +3 -3
  108. data/lib/samagotchi/testing/install.rb +3 -3
  109. data/lib/samagotchi/testing/sandbox.rb +2 -2
  110. data/lib/samagotchi/tool_runner.rb +14 -14
  111. data/lib/samagotchi/tools/memory.rb +22 -22
  112. data/lib/samagotchi/tools/task_runtime.rb +12 -3
  113. data/lib/samagotchi/update_command.rb +4 -4
  114. data/lib/samagotchi/version.rb +1 -1
  115. data/lib/samagotchi/web/app.rb +14 -1
  116. data/lib/samagotchi/web/message_display.rb +6 -0
  117. data/lib/samagotchi/web/participant_view.rb +1 -1
  118. data/lib/samagotchi/web/proxy_gate.rb +1 -0
  119. data/lib/samagotchi/web/public/app.js +13 -1
  120. data/lib/samagotchi/web/public/card_kinds.js +8 -3
  121. data/lib/samagotchi/web/public/cards_place.js +15 -1
  122. data/lib/samagotchi/web/public/context_chips.js +184 -49
  123. data/lib/samagotchi/web/public/ctx.js +1 -1
  124. data/lib/samagotchi/web/public/history_shape.js +8 -3
  125. data/lib/samagotchi/web/public/index.html +66 -0
  126. data/lib/samagotchi/web/public/peer_chip.js +171 -0
  127. data/lib/samagotchi/web/public/peer_data.js +119 -0
  128. data/lib/samagotchi/web/public/peer_exchange.js +83 -0
  129. data/lib/samagotchi/web/public/peer_links.js +161 -0
  130. data/lib/samagotchi/web/public/peer_note.js +49 -0
  131. data/lib/samagotchi/web/public/session_view.js +6 -1
  132. data/lib/samagotchi/web/public/stream_handlers.js +17 -4
  133. data/lib/samagotchi/web/public/turn_block.js +46 -8
  134. data/lib/samagotchi/web/public/turn_html.js +11 -2
  135. data/lib/samagotchi/web/public/turn_settle.js +117 -0
  136. data/lib/samagotchi/web/push/notifier.rb +2 -2
  137. data/lib/samagotchi/web/session_access_routes.rb +21 -1
  138. data/lib/samagotchi/web/session_hub.rb +20 -4
  139. data/lib/samagotchi/worker_boot.rb +4 -1
  140. metadata +24 -12
  141. data/lib/samagotchi/memory_bundle/manifest.rb +0 -581
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 221dc2bfb6cf6d9e8d839dd49e5740b1b7e05f1f0ca77d64987418c755f2d82e
4
- data.tar.gz: c26aca5d929e616c3e402b323ddd850e20d4e9193a42ebfbbe7b2f4cf9d28b8b
3
+ metadata.gz: '056860037a4db0a4c2ec4fb0fa92aa022024dd344e13786bdb55d7947999c572'
4
+ data.tar.gz: 8a3bb8f657b9b05ad682abd3e708be26ee70e8759a4e5df01a212e5fc715c292
5
5
  SHA512:
6
- metadata.gz: 5d9caf39334981e0dbbe2417615f0db3e4c3e8a9fd8afc1e8caf63fb2de8bae2062c1ed11ef0de73145ec3aadbaee055a133e9f369eb915852fbd4d3fa9aed7d
7
- data.tar.gz: 4d646ee36fbbc7880235793216ae4e5f975e5f77b794b1d39f25c7f1576eafc1388a48cc9d82fafce9386ffc45e483d4bf3c8ca73bfaac077a63f4b7dcaaf443
6
+ metadata.gz: af64aaac919f8722c9b274984a82712d0f3c7464d78f3c6428ffb74c47f4ac3158e7fc11b21ad46df24c7452f581d5bbee9e8d97f782b5640802f7bd60037452
7
+ data.tar.gz: ed980f2025a4b03c1e868008f828bec79f185b6fa2682d05808a83cb94243d6b09802bfddf751a822c110582ce5849aba6aedebbc20d27746c76d3eb8011be27
data/CHANGELOG.md CHANGED
@@ -8,6 +8,61 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.180.0] - 2026-11-20
12
+
13
+ ### Added
14
+
15
+ - In the web, a send to a paired peer (Claude, Codex) and its answer link to each other: the send's row says
16
+ "waiting 2m", "changes · answered after 6m" or "not sent" and jumps down to the answer; the answer is a bubble
17
+ from the peer with its verdict and summary that jumps back up to the send, chi's instruction to the model folded
18
+ away.
19
+ - In the web, a paired peer is one chip in the session bar instead of its two `-inbox`/`-outbox` chips: it says
20
+ paired, waiting 2m, answered (with the unread dot), can't send or answers only, and opens a popover with the
21
+ last exchanges (a tap jumps to the send), View latest answer, the status card and Unpair (a bottom sheet on a
22
+ phone).
23
+
24
+ ### Changed
25
+
26
+ - The terminal shows a peer's answer note as `Claude answered · <summary>` (`Codex answered · …`) instead of `note from context claude-outbox: …`.
27
+ - A bundle that needs a newer chi now gets a warning for its `bundles:` section in config.yml, and
28
+ `--set` refuses its settings saying so, whether or not it has a plugin.
29
+ - A bundle's plugin, rule or script that isn't as installed is refused in one wording and one order everywhere (the
30
+ log, the load failures, the web's errors): "bundle NAME's plugin/FILE isn't recorded / is missing / differs from
31
+ the installed one (reinstall the bundle)". A rule with no recorded sha256 now says so instead of "differs", and
32
+ `chi bundle status NAME` shows such a plugin `[unrecorded]` instead of `[modified]`.
33
+
34
+ ### Fixed
35
+
36
+ - A background task whose shell ends just as chi exits no longer stays marked running with its leftover process left behind.
37
+ - A context source from a bundle whose manifest.json doesn't read, or isn't an object, now fails its fetch with a clear
38
+ reason, instead of an internal error or running its command unchecked.
39
+
40
+ ## [0.179.0] - 2026-11-20
41
+
42
+ ### Added
43
+
44
+ - A peer's answer names the send it answers: claude-peer and codex-peer messages carry a `ref:` line, the peers'
45
+ chi-peer skills give it back as `re` in their reply (reinstall the skill with `/claude install-skill` or
46
+ `/codex install-skill`), and chi keeps it on the answer's note and the send's row for the web to tie them. The
47
+ model reads the same text as before; an older skill's answer works as before, unlinked.
48
+ - A per-session peer exchange log records sends, transport failures and answer summaries for the owner's web view,
49
+ without storing answer texts.
50
+
51
+ ### Changed
52
+
53
+ - The retention sweep, and a `chi scratch` session's cleanup, stop the background tasks a deleted session started
54
+ (logged per task); the sweep now runs off chi web's session list lock.
55
+
56
+ ### Fixed
57
+
58
+ - A guardrail plugin (`plugin: required: true`) whose bundle's manifest.json doesn't read now denies tool calls,
59
+ as its rules would, instead of only being reported.
60
+ - A reloaded turn keeps an answered question and an asking card (check-in's) in the order they showed live: a card
61
+ that stopped asking mid-turn no longer moves back into its first step, and one still asking no longer jumps above
62
+ the question answered after it.
63
+
64
+ Update with `chi update`.
65
+
11
66
  ## [0.178.0] - 2026-11-20
12
67
 
13
68
  ### Changed
@@ -6521,7 +6576,9 @@ and long-lived sessions.
6521
6576
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
6522
6577
  hotkey panel that send selected text or the clipboard to your sessions.
6523
6578
 
6524
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.178.0...HEAD
6579
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.180.0...HEAD
6580
+ [0.180.0]: https://github.com/dm1try/samagotchi/compare/v0.179.0...v0.180.0
6581
+ [0.179.0]: https://github.com/dm1try/samagotchi/compare/v0.178.0...v0.179.0
6525
6582
  [0.178.0]: https://github.com/dm1try/samagotchi/compare/v0.177.1...v0.178.0
6526
6583
  [0.177.1]: https://github.com/dm1try/samagotchi/compare/v0.177.0...v0.177.1
6527
6584
  [0.177.0]: https://github.com/dm1try/samagotchi/compare/v0.176.0...v0.177.0
data/docs/architecture.md CHANGED
@@ -504,7 +504,8 @@ model: [internals/remote-sessions.md](internals/remote-sessions.md).
504
504
  | `POST /api/sessions/:id/wait` | owner | `cursor`, `baseline`, `turn`, `queued`, `ended_before`, `owner_grace`, `timeout` (capped at 30 s) | 200: `ReplyWait::Result`'s fields (`status`: `done`, `waiting_for_answer`, `no_reply`, `error`, `stopped`, `worker_gone`, or `timeout`: ask again; `text`, `file`, `question` as `PendingQuestion#to_file`, `outcome`, `limit`, `error_kind`, `retryable`, `cancel_reason`, `stopped_by`, `kept_steps`, `turn_id`, `origin`; never the session) and `parent_strategy` `{name, allowed, origin}` (`ParentReport.strategy_for`, this server's config.yml) | 400 `invalid_wait`; 503 `server_stopping` |
505
505
  | `POST /api/sessions/:id/notes` | owner | `text`, `source` (default `cli`, never `broadcast`) | 200 `{status: queued \| waits, session_id, queued}` (`NoteDelivery`) | 409 `owned_by_tui` (`status: refused`); 400 `note_rejected`, `missing_fields`, `invalid_source` |
506
506
  | `POST /api/sessions/:id/context` (more bodies) | owner | `{name, push: true, why, hint}` or `{name, cmd, every, why, hint}` beside the page's `{url, why, hint}`; `added_by` `cli`/`agent` (else `web`); `movable` (any body) | 201 `{status: attached, name, movable}` | 400 `invalid_source`; 409 `exists` |
507
- | `POST /api/sessions/:id/context/:name/push` | owner | `text`, `summary`, `wake`, `hint` (a source's JSON output, checked the same way) | 200 `{status: pushed, name, before, revision, changed}` | 404 `not_found`; 409 `not_push`; 410 `context_continued` (`next_id`); 400 `invalid_text` |
507
+ | `POST /api/sessions/:id/context/:name/push` | owner | `text`, `summary`, `wake`, `hint`, `re` (a source's JSON output, checked the same way) | 200 `{status: pushed, name, before, revision, changed}` | 404 `not_found`; 409 `not_push`; 410 `context_continued` (`next_id`); 400 `invalid_text` |
508
+ | `GET /api/sessions/:id/peers` | owner | | 200 `{peers: [{name, label, inbox, outbox, exchanges}]}`: last 20 joined exchanges per peer, newest first; files only | 404 `not_found` |
508
509
  | `DELETE /api/sessions/:id/context/:name?own=1` | owner | | 200 `{status: detached}`: the session's own only | 409 `project_source` (chi context rm's words); 404 |
509
510
  | `POST /api/sessions/:id/stop` | owner | `wait?` (seconds, capped at `SessionManager::STOP_WAIT`, 10: `chi --remote NAME sessions stop` sends it) | 200 `{status: stopped, session_id, released}`: `released`, whether the worker let go within the wait (without one `STOP_WAIT_SECONDS`, 2 s: the page's Stop) | 409 `owned_by_tui` |
510
511
  | `DELETE /api/sessions/:id?force=` | owner | `force=true` stops a live worker first (the page sends it) | as before | 409 `worker_running` without it |
@@ -655,7 +656,8 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
655
656
  | Session lifecycle | `session_manager/`, `worker_boot.rb`, the session sidecar files | Marker writers, derived states, lock order, crash repair and the known open windows are mapped in [Session lifecycle](internals/session-lifecycle.md). |
656
657
  | Config | `config.rb`, `config/restart_watch.rb` | Every setting as an `Entry`: env, config.yml and CLI layers ([configuration.md](configuration.md)); the notice a worker or chi web gets when config.yml changes a setting it reads only at its start. With `log.rb` it is the bottom layer: nothing it references reaches back to it, so `hosts:` and `models:` entries parse next to their types (`HostConfig.all`, `ModelSettings.all`). |
657
658
  | Paths | `paths.rb` (`Paths`) | The XDG base dirs chi's files live under, read from the env on every call: `Paths.state_home` (`$XDG_STATE_HOME`, else `~/.local/state`) and `Paths.config_home` (`$XDG_CONFIG_HOME`, else `~/.config`), both defaults under `Dir.home`; a blank variable counts as unset, a relative one is made absolute from the current directory. `Paths.tilde` shows a path with `~` for the home folder. `SessionManager` hands a spawned worker the spawner's `XDG_STATE_HOME` / `XDG_CONFIG_HOME`, when set, made absolute, so a relative one isn't read from the session's folder. |
658
- | MemoryBundle | `memory_bundle.rb`, `memory_bundle/{installer,builder,installed_bundle,plugin_ref,bundle_hook}.rb` (`Installer`, `Builder`, `InstalledBundle`, `PluginRef`, `BundleHook`) | Installing, building and reading bundles of memories, rules, plugins and scripts (`BundleHook`: an older record's retired class-file hook). |
659
+ | MemoryBundle | `memory_bundle.rb`, `memory_bundle/{installer,builder,provenance,uninstaller,status}.rb` (`Installer`, `Builder`, `Provenance`…) | Installing, upgrading, building and removing bundles of memories, rules, plugins and scripts ([internals/bundles.md](internals/bundles.md)). |
660
+ | Installed bundles | `installed_bundles.rb`, `installed_bundles/{record,manifest,dir,sha,plugin_ref,bundle_hook}.rb` (`InstalledBundles`, `Record`, `Manifest`, `Dir`, `Sha`, `PluginRef`, `BundleHook`) | What is installed, as the runtime reads it: the records, their manifests, one bundle's folder, the shas its files are checked against (`BundleHook`: an older record's retired class-file hook). `bundle_manifest.rb` (`BundleManifest`) is the `manifest.yml` format. |
659
661
  | Bundle authoring | `bundle_command.rb` (`BundleCommand`), `bundle_command/{scaffold,check,test_run}.rb`, `bundle_command/try/{run,sandbox,trace}.rb`, `testing.rb` + `testing/` (the test kit) | `chi bundle new`, `check`, `test` and `try`, and the kit a bundle's tests load it with ([bundle-authoring.md](bundle-authoring.md), [internals/bundles.md](internals/bundles.md)). |
660
662
  | Session file | `session.rb` (`Session`, `Session::FIELDS`), `session_field.rb` (`SessionField`), `session_paths.rb` (`SessionPaths`), `session_setup.rb` (`SessionSetup`) | A session's `<uuid>.json`: one `SessionField` row per key (default, cast, what the file gets; the codec on its type), from which `Session.new`, `.from_h` and `#to_h` are built; `SessionPaths` is where the file and the session's dir are and the id rule, a leaf `Session` extends (so `ArchiveStore` and `ContextSources` name no `Session` constant; both still require session.rb at load); `SessionSetup` the settings a fork and a continue carry (`.of`), applied by member name; every new-session request (chi's run flags, the one-shot, `chi send --new`, chi web's create) builds its setup with `SessionSetup.from_request`, and `spec/session_setup_entrypoints_spec.rb` holds each entrypoint's cell for each member. See [sessions.md](sessions.md#session-file). |
661
663
  | Session config (`--set`) | `session_config.rb` (`SessionConfig`, `SessionConfig::Settings`) | A session's own settings as one value (`Session#settings`, `SessionSetup#settings`): `core`, the `--set KEY=VALUE` values of the core keys marked `session: true` (`Config::Entry`), typed by `Config.coerce!` and read first through `Config.get(key, session:)` (`RecapSetup`; `Engine#session=` rebuilds the recap job, `IdleScheduler#replace_job`), file key `config_settings`; `bundles`, the `--set BUNDLE.KEY=VALUE` values, checked against the manifest's `session_settings:`, laid over `bundles: <name>:` in `ctx.settings` ([plugins.md](plugins.md)), file key `bundle_settings`. `SessionConfig.clash` refuses a bundle setting named like a core one (install, `chi bundle check`). See [configuration.md](configuration.md#per-session-settings). |
data/docs/bundles.md CHANGED
@@ -1008,13 +1008,51 @@ Claude pairs; without one the bundle costs one tool declaration.
1008
1008
  refreshes it) and `claude-outbox`, and lists the session's context. A
1009
1009
  re-pair keeps Claude's last answer.
1010
1010
  3. Claude answers a validate or a question with a JSON push to
1011
- `claude-outbox` (`text`, `summary`, `wake: true`), which wakes chi, the
1012
- first answer too (on chi 0.62 the first one arrives as a note without
1013
- waking); the model reads it with `context_read claude-outbox`.
1011
+ `claude-outbox` (`text`, `summary`, `wake: true`, and `re`: the `ref:`
1012
+ line of the message it answers), which wakes chi, the first answer too
1013
+ (on chi 0.62 the first one arrives as a note without waking); the model
1014
+ reads it with `context_read claude-outbox`. In chi's own records the
1015
+ answer's note names the send (`re`); an older skill's answer has none and
1016
+ works as before. The session's peer exchange log keeps sends and answer
1017
+ summaries, not answer texts; a new pairing starts a new log.
1018
+ - **In the web** (the owner's page), a send and its answer link to each
1019
+ other. The send's row ("sent to Claude · validate: title") says where the
1020
+ exchange is: `waiting 2m`, `changes · answered after 6m` (the verdict's
1021
+ word: `ok`, `changes`, `unsure`), `answered after 6m`, or `not sent` (the
1022
+ send didn't go out); a tap on an answered one jumps down to the answer. The
1023
+ row's line of advice to the model is its hover instead. The answer stays
1024
+ where it arrived, as a bubble from Claude: "Claude answered", the send it
1025
+ answers (a tap jumps back up to that row, opening a folded turn), its
1026
+ verdict (`VERDICT OK` with "round closed" when Claude agreed), its summary,
1027
+ and chi's instruction to the model folded under "what chi told the agent".
1028
+ The newest answer also has "Read the full answer", which opens the
1029
+ Claude chip on the outbox's text (the outbox keeps one text, so older
1030
+ answers have only their summary). An answer from an older skill (no `re`)
1031
+ links to the last waiting validate or question; one that answers no send
1032
+ has no link back. A `/claude validate …` you type gets no link in the
1033
+ conversation (command bubbles aren't kept), its answer still names it.
1034
+ - **The session bar** has one chip for the pairing, `Claude · …`, first among
1035
+ the context chips, in place of `claude-inbox` and `claude-outbox`: `paired`;
1036
+ `waiting 2m` (a validate or question has no answer yet, its age the send's);
1037
+ `answered 3m` with the unread dot (an answer the agent hasn't read);
1038
+ `can't send` (the last send didn't go through: the Claude session ended or
1039
+ restarted, pair again from Claude, which ends it; chi web can't probe the
1040
+ socket, so a dead inbox shows only after a send hits it); `answers only`, dashed (no inbox: a
1041
+ pairing through a remote). Its popover (a bottom sheet on a phone) says how
1042
+ chi sends and where it answers, lists the last exchanges (time, kind ·
1043
+ title, `waiting 2m` / `changes · 11m` / `ok · 4m` / `answered · 4m` / `no
1044
+ answer expected` / `not sent`; a tap jumps to that send's row when it is in
1045
+ the conversation), and has View latest answer, Status card (runs `/claude`)
1046
+ and Unpair (detaches both sources after one confirm; if one can't be
1047
+ detached it stops there and says which). codex-peer's is the
1048
+ same, `Codex · …`.
1014
1049
  - **The tool `claude_send(kind, title, text)`**, `kind` being `validate`,
1015
1050
  `context` or `question`, writes one JSON line to that socket. The message
1016
- starts with a header, `chi <id> · <kind> · <title>`. A text up to 4,000
1017
- characters follows inline; a longer one goes to a file,
1051
+ starts with a header, `chi <id> · <kind> · <title>`, and a second line,
1052
+ `ref: <send id>` (`s-` and 6 hex, from the kind, title and text as given:
1053
+ the same part sent again has the same id), which Claude's answer gives back
1054
+ so chi can tie it to its send; the tool's row in the web carries the id too.
1055
+ A text up to 4,000 characters follows inline; a longer one goes to a file,
1018
1056
  `$XDG_STATE_HOME/samagotchi/plugins/claude-peer/sessions/<id>/<HHMMSS>-<slug>.md`
1019
1057
  (removed with the session), and the message names it (`payload: <path>`).
1020
1058
  The tool is declared whether or not a Claude is paired, so pairing doesn't
@@ -1146,7 +1184,7 @@ session: chi sends the Codex session you work with a part of the work to
1146
1184
  validate or as context, and Codex's answer comes back into chi. It is a copy
1147
1185
  of claude-peer with the transport swapped; what differs is below, the rest
1148
1186
  (kinds, payload files, the last send, `/codex last`, the status card, the
1149
- skill install card) works the same.
1187
+ skill install card, the web's linked send and answer: "Codex answered") works the same.
1150
1188
 
1151
1189
  - **Sending is `codex queue`.** `codex_send(kind, title, text)` and
1152
1190
  `/codex validate|context <text>` run
@@ -1195,8 +1233,10 @@ skill install card) works the same.
1195
1233
  `sh <bundle>/scripts/pair` attaches `codex-inbox` (the thread id as its
1196
1234
  hint, pushed so a re-pair refreshes it) and `codex-outbox`. Run outside
1197
1235
  Codex (no `CODEX_THREAD_ID`) it refuses. Codex replies with one JSON push
1198
- to `codex-outbox` (`text`, `summary`, `wake: true`), which wakes chi, the
1199
- first answer too (that needs chi 0.63.0; the bundle's `requires_chi` is `>= 0.70.0`).
1236
+ to `codex-outbox` (`text`, `summary`, `wake: true`, `re`: the message's `ref:`
1237
+ line), which wakes chi, the first answer too (that needs chi 0.63.0; the bundle's
1238
+ `requires_chi` is `>= 0.70.0`). The session's peer exchange log keeps sends
1239
+ and answer summaries, not answer texts.
1200
1240
  - **Peer messages are user turns in Codex.** Claude Code marks an inbox
1201
1241
  message as from another session; `codex queue` lands as a plain user
1202
1242
  message. So Codex's skill starts with the rule: a message whose first line
data/docs/cli.md CHANGED
@@ -156,7 +156,7 @@ The loop for a bundle you're writing (the whole path: [bundle-authoring.md](bund
156
156
  chi reads the key from it with no reinstall, and `chi update`'s re-check names it too), `requires-chi` (this chi doesn't satisfy it:
157
157
  error; missing on a bundle with code: warn), `requires-chi-floor` (warn: the plugin calls an API newer than the
158
158
  oldest chi `requires_chi` admits, from `Plugin::Api::SINCE`, or the manifest itself uses a key newer than it, from
159
- `Manifest::SINCE`; an installed bundle gets the unknown-key row but never the floor, as it's the author's fix),
159
+ `BundleManifest::SINCE`; an installed bundle gets the unknown-key row but never the floor, as it's the author's fix),
160
160
  `trust` (warn: `trust_level: reviewed|trusted` on a
161
161
  bundle chi doesn't ship), `clash` (warn: a name chi ships, or one installed from elsewhere; the sandboxed install
162
162
  then forces), `install` (each Installer warning, a `needs` one as warn, and each plugin load failure at
@@ -596,6 +596,8 @@ refused. Its first line says it is a scratch session.
596
596
  session (`Scratch session deleted.`). `/archive` is refused. The lines typed
597
597
  are not added to the prompt history. With `-p … --non-interactive` it is one
598
598
  turn in this process, and the session is deleted as the run ends.
599
+ - Cleanup stops the background tasks it started when their process identity can
600
+ be verified; unverifiable or unreadable tasks are left alone and logged.
599
601
  - The worker deletes the session too once its terminal is gone (no terminal
600
602
  stream left for about 28 s, twice the terminal's reconnect retries, so a
601
603
  dropped stream that reconnects keeps it; or none came within 30 s), so a
@@ -127,7 +127,7 @@ own subsystems: `hosts:` (below), `models:` (see "Prompt profile" and
127
127
  `guardrails:` (see [Guardrails](guardrails.md)), `bundles:` (a bundle's
128
128
  settings for its hooks, see [Hooks: Settings](hooks.md#settings); a session's own
129
129
  `--set BUNDLE.KEY=VALUE`, for a key the bundle's manifest lists in `session_settings:`, lays over them, see
130
- [Per-session settings](plugins.md#per-session-settings); a name no installed bundle has, or a key its manifest's `settings:` rules out, warns at the start of the first session to find it and again only when the findings change or come back (a digest of the lines shown is stamped in `$XDG_STATE_HOME/samagotchi/bundles_warned`; the log has them from every session); `--set KEY=VALUE` does the same for a few core keys,
130
+ [Per-session settings](plugins.md#per-session-settings); a name no installed bundle has, a key its manifest's `settings:` rules out, or a bundle this chi is too old for (its `requires_chi`), warns at the start of the first session to find it and again only when the findings change or come back (a digest of the lines shown is stamped in `$XDG_STATE_HOME/samagotchi/bundles_warned`; the log has them from every session); `--set KEY=VALUE` does the same for a few core keys,
131
131
  see "Per-session settings" below),
132
132
  `memories:` and `append_system_prompt:` (see "Appended prompt files"). Their entry names (host names, model ids, aliases) are yours to
133
133
  choose. The `memories:` list is the persistent baseline for preloaded memory entries —
data/docs/context.md CHANGED
@@ -56,7 +56,10 @@ Its output is either:
56
56
  ```
57
57
  `summary` (one line, up to 200 characters) goes into the update note;
58
58
  `wake: true` asks for a turn ([Waking](#waking)); `hint` replaces the
59
- source's hint until a later output gives another. Unknown keys are ignored.
59
+ source's hint until a later output gives another. `re` (optional: a peer's
60
+ answer naming the send it answers, [Peer sources](#peer-sources-the-peer-loop))
61
+ is kept with the revision when it is a short id (`a-z`, `0-9`, `-`, up to 32),
62
+ else dropped; a revision without one clears it. Unknown keys are ignored.
60
63
 
61
64
  A non-zero exit, a timeout, more than 1 MiB or empty output is a failed
62
65
  fetch: the last good text stays, and the agent hears once, at the first
@@ -235,6 +238,13 @@ The web's session bar shows a chip per source (name · age; a dot when the
235
238
  agent hasn't read a change, red after a failed refresh). A chip opens the
236
239
  summary, the hint's link, the text and detach (or mute here, for a project
237
240
  source). The web attaches nothing itself: `chi context add <URL>` does.
241
+ A paired peer's two sources (`claude-inbox`, `claude-outbox`) are one chip,
242
+ drawn first: it says how the pairing stands (paired, waiting, answered,
243
+ can't send, answers only) and opens the last exchanges, the outbox's text and
244
+ Unpair ([bundles.md](bundles.md#the-claude-peer-bundle), The session bar).
245
+ A peer's answer (a note with `peer`, [Peer sources](#peer-sources-the-peer-loop)) is not drawn as a context note but
246
+ as a bubble from the peer, linked to the send it answers
247
+ ([bundles.md](bundles.md#the-claude-peer-bundle), In the web).
238
248
 
239
249
  ## Waking
240
250
 
@@ -326,6 +336,20 @@ lower.) Every other source keeps the line above. `context.peer_turns: 0` turns
326
336
  the loop off: a peer source then wakes like any other. `context_read` names a
327
337
  peer source in its header (`Peer: your peer agent Codex's answers …`).
328
338
 
339
+ Each message chi sends a peer carries a `ref: <id>` line, and the peer's
340
+ answer gives it back as `re` ([the contract](#the-command-contract)). The
341
+ answer's note keeps whose answer it is (the peer, `re`, its summary and
342
+ verdict) for the web to tie it to its send; the model's note reads as it
343
+ did. That holds for a declared peer source, with the loop on or off.
344
+
345
+ **Outside the worker it is by name.** chi web and the CLI load no plugins,
346
+ so where they show a pairing (a context row's `peer`, `leg` and `label`) a
347
+ pushed source of the session's own named `<word>-inbox` or `<word>-outbox` is
348
+ taken for one: `review-outbox` gets a peer chip too, and changed pushes to it
349
+ are logged as answers. That is display and logging only:
350
+ what is a peer's answer, and what may wake chi and how, is still the bundle's
351
+ declaration in the worker, as above.
352
+
329
353
  ## Movable context
330
354
 
331
355
  A session's own sources go with it to the next session of its work: the next
@@ -690,5 +714,12 @@ The candidates' log, `context_candidates.jsonl`, sits one level up, beside
690
714
  the sessions folder (`$XDG_STATE_HOME/samagotchi/`; see
691
715
  [The log and the report](#the-log-and-the-report)).
692
716
 
717
+ Peer exchange metadata lives separately in the session sidecar at
718
+ `$XDG_STATE_HOME/samagotchi/sessions/<id>/peer_exchanges.jsonl`. It records
719
+ sends, transport failures and answer summaries, not answer text. It is
720
+ append-only and uncapped; a continue starts a new log with its new pairing.
721
+ An unchanged text is not a new revision, even if its `re` changes, so it
722
+ does not add an answer to the log.
723
+
693
724
  Deleting a session deletes its folder. A source and its snapshot go with
694
725
  `chi context rm`; its `.lock` stays (a fetch may still hold it).
data/docs/guardrails.md CHANGED
@@ -1452,7 +1452,8 @@ else goes to chi's own rules. It needs nah installed; see its README for the set
1452
1452
  (`plugin:` `required: true`, for a `chi.on(:before_tool_call, on_error:
1453
1453
  :fail_closed)` guard, chi 0.157.0 or newer, [plugins.md](plugins.md#a-guard-that-fails-closed-on_error-fail_closed)),
1454
1454
  that fails to load (missing, syntax error, an unmet `requires_chi`, or for a
1455
- plugin a sha256 that differs from the installed one) makes chi deny
1455
+ plugin a sha256 that differs from the installed one, or its bundle's
1456
+ manifest.json that doesn't read) makes chi deny
1456
1457
  every tool call. (An older chi's class-file bundle hooks don't load at all,
1457
1458
  `fail_closed` or not, [hooks.md](hooks.md#class-file-hooks-are-retired).) A fail-closed hook that raises when called denies that call.
1458
1459
  - Other hooks stay fail-open; a load failure is a warning.
@@ -47,7 +47,7 @@ comment is the file map and [../context.md](../context.md#storage) lists it for
47
47
  - **Records** (`Data`/value objects): `Source` (definition; `cmd` nil = pushed; `movable` nil derives from
48
48
  `push?`), `Snapshot` (last good text, `revision` = SHA-256 of the text, `serial` counting revisions, `error` and
49
49
  `error_since`, `wake_serial` = the newest revision that asked to wake, `fetched_at` last success, `checked_at` last
50
- try), `Subscription` (what one session has had: `seen`/`seen_serial`, `read`, `error_seen`, `wakes_at`),
50
+ try, `re` = the send a peer's answer names, with the revision: nil for none, an older snapshot's too), `Subscription` (what one session has had: `seen`/`seen_serial`, `read`, `error_seen`, `wakes_at`),
51
51
  `Candidate`, `Left`, `Moved`/`Stayed`.
52
52
  - **Locations.** A `Location` is a folder of sources: a project's (`projects/<project_key>/`, shared by the
53
53
  project's workers) or a session's (`sessions/<id>/`, which also holds `subscriptions.json`, the `muted/` and
@@ -61,8 +61,12 @@ comment is the file map and [../context.md](../context.md#storage) lists it for
61
61
  still running finds its source gone (`ContextFetch` then writes nothing). Removing a *session* source leaves a
62
62
  `declined/<name>` marker (hint inside), which is what stops an auto-attach from bringing it back.
63
63
  - **The output contract** is `ContextSources.parse_output` (JSON object with a string `text` is
64
- `{text, summary, wake, hint}`; anything else is all text; empty or over `TEXT_MAX_BYTES` is `Invalid`), the same for
65
- a command's stdout and a push. `ContextProviders` resolves a URL to a command source from an installed bundle's
64
+ `{text, summary, wake, hint, re}`; anything else is all text; empty or over `TEXT_MAX_BYTES` is `Invalid`), the same for
65
+ a command's stdout and a push. `re` is kept only as a String of `RE_RE`, including when a snapshot is reloaded;
66
+ malformed non-null refs are debug-logged without the answer. `Fetched` and `Snapshot` default `re:` to
67
+ nil, so a caller (a spec, a bundle's) that builds them without it keeps working; the push carries it in three seats
68
+ that change together: `parse_output`, chi web's push route (`SessionAccessRoutes#handle_context_push`'s slice) and
69
+ `SessionAccess::Remote#context_push`'s body (an older chi web drops it: the answer arrives unlinked). `ContextProviders` resolves a URL to a command source from an installed bundle's
66
70
  manifest `context_providers:` (read from its provenance, so the CLI and chi web resolve without loading plugins);
67
71
  `{url}` is filled at attach, `{bundle_dir}` and `{ruby}` when the command runs.
68
72
  - **Protected.** The root is a `ProtectedPaths` entry: the file tools cannot write it, because a source's command
@@ -117,6 +121,23 @@ as a peer's answers; `peer_label` then needs `context.peer_turns` > 0. A peer de
117
121
  budget is `WorkerWakes#peer_open?` (reset only by typed input), and an answer whose summary ends in `VERDICT OK`
118
122
  (`peer_agrees?`) wakes once with the closing line, counted toward `session.max_wakes` only.
119
123
 
124
+ **Whose answer a note is.** A text note (and its wake note) of a source `PeerSources` marks as a peer's (`peer_name`:
125
+ a pushed source of the session's own that a loaded bundle declared; *not* gated on `context.peer_turns`, and nil for an
126
+ absorber built without peer sources, `ContextCandidates.deliver_notes`') carries `peer: {peer, label, re, summary, serial,
127
+ verdict, agreed}` (`peer_note`; string keys, nils dropped): `re` the snapshot's, `verdict` the summary's last
128
+ `VERDICT` match when one of `VERDICTS`, `agreed` `peer_agrees?` directly. It is display data, as `objectives` is:
129
+ `ContextNote::KEYS` keeps it (the key-by-key copier is `ChatLoop#plain`), `:context_added` carries it, the reload's note
130
+ items (`Web::MessageDisplay`) carry it with `context_source`, and no wire sends it (role and content only), so the
131
+ note's content, what the model reads, is the same byte for byte. `peer_label` and `Delivery#peer` keep deciding the
132
+ wakes.
133
+
134
+ **Exchange log.** `Plugin::Peer` appends successful sends and transport failures;
135
+ `SessionAccess::Local#context_push` appends changed session outbox answers under the
136
+ source lock, without nesting another lock. Appending failure is logged and does not
137
+ fail a send or push. `PeerExchanges` joins by time and ref, falling back to the
138
+ latest unanswered validate or question for an old skill. An owner-only chi web
139
+ route reads it without a worker; no event or model-visible text changes.
140
+
120
141
  ## Candidates
121
142
 
122
143
  `ContextCandidates` holds a session's proposed sources (`Candidate`, from `ctx.context.propose`, stored under
@@ -221,12 +242,13 @@ Keys, all in [../configuration.md](../configuration.md): `context.every_seconds`
221
242
  | File | Written by | Read by |
222
243
  |---|---|---|
223
244
  | `context/{projects/<key>,sessions/<id>}/<name>.json` | `chi context add`, a provider, a plugin (`ctx.context.attach`), `ContextCandidates.attach`, `ContextMove` | poller, absorber, `context_read`, chi web |
224
- | `<name>.snapshot.json` | `ContextFetch`, `chi context push`, `ContextMove` | absorber, `context_read`, chi web chips |
245
+ | `<name>.snapshot.json` (a push's `re` too) | `ContextFetch`, `chi context push`, `ContextMove` | absorber, `context_read`, chi web chips |
225
246
  | `<name>.lock` | `ContextFetch` / `Location#locked` | same |
226
247
  | `sessions/<id>/subscriptions.json` | the worker (`commit`, `context_read`) only | absorber, chi web (unread dot) |
227
248
  | `sessions/<id>/{muted,declined}/<name>` | `chi context mute`, a removal, `ContextMove` | poller, absorber, candidates |
228
249
  | `sessions/<id>/candidates/<name>.json` | `ctx.context.propose` | candidates, judge, `/context` |
229
250
  | `sessions/<id>/left.json` | `ContextMove` (continue) | `ctx.context.left_behind` |
230
251
  | `context_candidates.jsonl` (beside `sessions/`) | `ContextCandidatesLog` | judge (`due?`), choice (`carded?`), `chi context report` |
252
+ | `sessions/<id>/peer_exchanges.jsonl` (session sidecar, not context root) | `Plugin::Peer`, `SessionAccess::Local` | `GET /api/sessions/:id/peers` |
231
253
 
232
254
  Specs: `spec/context_*_spec.rb`; a store under test uses an isolated `XDG_STATE_HOME`.
@@ -36,7 +36,8 @@ Behavior:
36
36
  - The exit code: the command runs after an EXIT trap that writes the shell's status to the `exit_code` file (`TaskRuntime.wrapped_shell_command`, shared with `task_create`), so `exit N`, a `set -e` failure and a trailing `\` or `|` in the command all record what the shell exited with. The trap runs wherever the shell is when it exits (a `task_create` `cwd`, or a `cd` in the command), so `task_create`'s `exit_code_path` is absolute; its `output_path` stays relative (`tmp/tasks/<id>/output.log`, opened by chi in the worker's cwd before the spawn). A command that sets its own EXIT trap replaces it, and a shell killed by a signal skips it (zsh's sh mode, on TERM, INT and KILL): `execute` still reports the shell's status, and a `task_create` task or a handed-over execute gets its code from chi's waiter while the chi that started it runs (`TaskRuntime.record_exit_status`): the exit status, or `128 + the signal` (TERM → 143), with no new `stop_reason`. A record a refresh already finished without a code in between (`failed`, `process_ended_without_exit_code` or the not-chi's-process reason) is corrected, its `finished_at` kept; a stopped task (its stop flag on disk) is never touched. `process_ended_without_exit_code` is left only when the shell wrote nothing and the chi that started it was gone too.
37
37
  - `task_create` applies `execute`'s leftover rule (`Tools::Leftovers`, one implementation: `held?`, the grace, the group stop, the hint wording): `create_task` holds `output.log` with a shared `flock` across the spawn, and a handed-over execute's two logs are already held. When the task's shell exits and a process it started still holds the log (`yes >/dev/null &` with no `wait`), the task stays `running` (so the finish wake's watch and `task_wait` keep waiting) while the waiter of the chi that started it (`TaskRuntime.record_exit_status`) gives it 1.5 s (`LEFTOVER_GRACE_SEC`), then stops the group (TERM, 1 s, KILL; `Leftovers.stop_group`, only while the group still has members: a pgid isn't reused while it has any) and finishes the record in one write: the shell's status and exit code (the leftovers don't make it a failure) and `leftovers: "stopped"`. A holder outside the group with the group empty (a setsid'd `cmd &`, or a backgrounded `timeout N cmd &`: GNU `timeout` without `--foreground` moves itself and its command to a group of its own) is signalled nothing: `leftovers: "detached"`, left running, and the hint says so (`task_stop` can't reach it: kill it if it shouldn't run). A process holding no log (`nohup cmd >f 2>&1 &`) is left alone. `task_get`, `task_wait` (so the finish note too) and `task_list` add the hint line (`Leftovers.task_hint`), ``(a background process kept the task's log open and was stopped; to keep one running, run it in the foreground or end the command with `wait`)`` (or `was left running`), built from the same `Leftovers.hint` as execute's. One settler per task: while that waiter thread lives (`TaskRuntime.waiter_for`, in memory, this process only), a refresh here only reads a held record. With no waiter here (the chi that started it is gone, a worker that exited mid-grace, or another process reading), the next refresh that finds the shell dead and the log held settles it itself: a second look after 0.05 s (two `held?` probes at once read each other as holders), then the stop with a 0.5 s TERM grace and 0.5 s KILL wait (only of a group that still had members at the first look; one gone by the stop with nothing holding the log records no `leftovers`), so that read blocks up to ~1 s plus a `ps`. With no later reader of that cwd's tasks the leftovers run on; records already finished (an older chi's) are never revisited, and an older chi's record (its log never `flock`'d) reads as not held and settles as before. A `task_stop` during the grace stops the group (`Leftovers.stop_group`) and the record ends `stopped` (its stop flag wins over the waiter's write; in one process the two writes share a lock). Cost: one non-blocking `flock` try per log at shell exit (~0.2 ms), the grace only when something holds the log; a refresh of a running record whose shell is dead adds one `flock` try, and one `ps` only when the log is held.
38
38
  - On a clean exit (worker teardown or a one-shot), `Engine#shutdown` calls `TaskRuntime.settle_pending!`: this process's
39
- waiters whose shells are already reaped get time to finish their leftover grace and stop before chi exits. The wait
39
+ waiters whose shells are already reaped (the detach thread ended, the waiter settling, or the pid gone: the detach
40
+ thread runs a moment after its reap) get time to finish their leftover grace and stop before chi exits. The wait
40
41
  shares one deadline with the anytime-command joins (the later of their 3 s and ~4 s), and logs a warning if a selected waiter
41
42
  remains. A shell still running at the snapshot, including one that exits during the join, is not waited on; a crash
42
43
  or SIGKILL cannot wait either. With no later reader of that cwd, such leftovers can still run on.
@@ -56,6 +57,9 @@ Behavior:
56
57
  read, so chi web and the CLI run `stop_task` from their own cwd; without a root every path is the relative one. A
57
58
  thread the block starts doesn't inherit it (only `create_task` starts waiters, and nothing calls it under a root).
58
59
  See [sessions.md](../sessions.md) (Deleting a session).
60
+ - Retention and scratch cleanup use the same rule without asking: verified tasks stopped by them record
61
+ `stopped_by_retention` or `stopped_by_scratch`, not `stopped_by_user`. Unverified and unreadable tasks are not
62
+ signalled and are logged as not stopped. Schedule prune leaves tasks running.
59
63
  - A stop of an `execute` (the user's Stop, the limit in kill mode) is done once the shell is reaped and nothing holds the logs: a child that ignores TERM after its shell died gets the KILL.
60
64
  - A command still running at `execute.timeout_sec` is handed over as a task (`execute.on_timeout: task`, the default; `kill` stops it instead, and the `!cmd` bang always kills): the result starts `Still running at the 120s limit: moved to a background task, not killed.`, then `task_id: …` and the tails of both logs so far. A command is also handed over early when a person's message waits for the turn's next step (the `message_waiting:` probe, the same `Engine#input_waiting?` as `task_wait`'s): after `Execute::EARLY_HAND_OVER_FLOOR_SEC` (3 s: a short command ends first and its result is the better answer), in the next 0.2 s slice. The first line then reads `Still running at the 4s mark: a message from the user is waiting, so the command moved to a background task, not killed.` (the seconds it had run), and the line after `task_id:` starts `Read the message first.`; the rest is the same hand-over, and the task stays watched. Never in `kill` mode (`execute.on_timeout: kill`, a participant's pair turn, the `!cmd` bang): there the probe is not even read and the command runs to its limit and is killed. A command that can't be adopted at that moment (a record that can't be written) isn't killed early: it runs on to its limit. Everything that matches the first line builds on `Execute::HANDED_OVER` (`Still running at the`) and `Execute::HANDED_OVER_AFTER` (both defined in `ToolNames::Execute`) (`120s limit:` or `4s mark:`): `TaskTranscript.handed_over_id`, `ToolActivity::HANDED_OVER_START`, `TaskWatch` (`limit_sec` for the limit's form, `early_sec` for the mark's, which the finish note words as `handed over by execute after 4s: a message from the user was waiting`) and the web's `task_stop.js`; the slow-commands bundle reads only the limit's form, which is the only one that is a timeout. A timeout during the 1.5 s background grace is a kill (the shell is gone, nothing to hand over). If the record can't be written, the command is killed. `TaskRuntime.adopt` writes a record for the process execute already started, with `handed_over_by: "execute"`. Its logs stay where execute wrote them, so the record's paths are absolute: `output_path` (stdout), `stderr_path` (stderr, a log of its own) and `exit_code_path` (a `task_create` record's `exit_code_path` is absolute too; its `output_path` is relative). `started_at` (and `created_at`) is the spawn time, not the hand-over's; `pid_started` is read at the hand-over, while execute's detach waiter is still running. From there it is an ordinary task: `task_wait`, `task_get`, `task_list` and `task_stop` treat it as any other. Its dir gets a `task` back-pointer file holding the record's absolute path. Once per process, the first `execute` sweeps `…/execute/`: a dir whose logs no process holds is removed when it has no back-pointer and is a day old (chi died mid-command), when its record is gone, or when it is 14 days old. The records live in each project's `tmp/tasks`, which the state dir can't list: hence the back-pointer.
61
65
  - `task_wait` and `task_get` show `stderr_path` when the record has one; `task_wait`'s output tail is followed by a `stderr_tail:` of at most 10 lines when that log isn't empty. A `task_create` task has one log (stdout and stderr together) and no `stderr_path`. A `task_wait` result longer than `max_tool_output_chars` keeps its header and the tail's end, with a gap line naming `output_path`, where the whole log already is (and `stderr_path`, when the record has one) (`ToolOutputCut`'s `:head_tail_ref`; nothing is copied; see [Tool output guardrails](tool-output-limits.md#the-runners-cut-max_tool_output_chars)).
@@ -10,14 +10,15 @@ model. The TUI is untouched: it shows a fence as source.
10
10
  in document order and zips them with the fragment's `<pre>`s, setting `data-lang` after sanitize's walk. Only the first
11
11
  word, downcased, matching `BlockRenderers::LANG`. A count that differs sets nothing. **`web.markdown` off means no
12
12
  `<pre data-lang>`, so nothing draws.**
13
- 2. `BlockRenderers.for_installed` (manifest `block_renderers:`, read through `InstalledBundle#manifest`: the bundle's
13
+ 2. `BlockRenderers.for_installed` (manifest `block_renderers:`, read through `InstalledBundles::Record#manifest`: the bundle's
14
14
  kept `manifest.yml`, else its record's mirror, so chi web needs no plugins, and a bundle installed by a chi that
15
15
  didn't know the key draws once a kept manifest is there) lists
16
16
  who draws what: `GET /api/block_renderers`, `:owner`. `GET /api/block_renderers/:bundle/:file` serves a file, `:owner`:
17
17
  the URL's names go through `BlockRenderers.script_path` (membership in a listed renderer's `load` before any path is
18
- made), then `Provenance#script_failure` (the check a context provider's scripts get too); a file with no recorded sha, a missing one or a changed one is 409
18
+ made), then `InstalledBundles::Dir#file_refusal(:scripts, …)` (the check a context provider's scripts get too); a file with no recorded sha, a missing one or a changed one is 409
19
19
  `renderer_changed`, each with its own reason. ETag + `no-cache`, as static files. A `block_renderers:` list that
20
- doesn't parse is logged once per bundle and problem (each list request and file fetch reads it).
20
+ doesn't parse is logged once per bundle and problem (each list request and file fetch reads it); a bundle this chi is
21
+ too old for (`requires_chi`) draws nothing, logged once per bundle and version (`block_renderers_too_new`).
21
22
  3. `block_watch.js` (`createBlockWatch`, made by `block_host.js`'s `createBlockHost`, wired in `app.js`; a participant's page
22
23
  gets the core drawers only, no bundle's renderers: `block_renderers`) finds and watches the blocks; `block_host.js` is its frame drawer (`createFrameDrawer`). The watcher asks an
23
24
  ordered list of drawers, core ones first (`inline_widgets.js` for `chi-ui`: [inline-widgets.md](inline-widgets.md)), then the frame drawer, which waits for `/api/block_renderers`;
@@ -30,7 +30,7 @@ whose seq a cursor is) and its **secret**; both are published in `bridge.json` (
30
30
 
31
31
  A joining UI must draw a turn already half done, and the ring may have dropped its early events. The accumulator
32
32
  folds the event log into one hash, `current_turn`: the prompt, `turn_id`, origin, `at`, and ordered `parts`
33
- (generation, thinking, text, tool, input, steer, reminder, notice, card), plus `pending_question`. A tool part keeps its
33
+ (generation, thinking, text, tool, input, steer, reminder, notice, card, settle), plus `pending_question`. A tool part keeps its
34
34
  row fields (`ToolRowFields`), its `tool_id`, its output cut head-and-tail at `ToolOutputCut::WEB_PREVIEW_CHARS` so a
35
35
  joined row is the row a reload draws, `elapsed_ms` while it runs (the accumulator times running calls itself, `clock:`)
36
36
  and, once finished, the event's `duration_ms` (its own clock only for an older worker's event that has none). A
@@ -38,7 +38,16 @@ and, once finished, the event's `duration_ms` (its own clock only for an older w
38
38
  the "asking again" row, a steer's cut, a ✂ row, a question and its answer), so a join replays it through the handler
39
39
  that drew it live. A `card` part is a card the turn showed in its step (`in_turn`), its latest version in its first
40
40
  one's place; `replay_events` and `join_events` skip it (a running turn's join takes its cards from CardStore), and
41
- only `replay_events(turn, cards: true)` (a finished turn's drawing) replays it as its `card` event.
41
+ only `replay_events(turn, cards: true)` (a finished turn's drawing) replays it as its `card` event. Since the card
42
+ part keeps only the latest version, an update that ends a card's wait (`Bridge::CardWait.kind`: `asks` for an action
43
+ with a command, else `warn` for level warn, else none; the twin of the page's `card_kinds.js cardWait`, both pinned by
44
+ `spec/shared/card_wait_cases.json`) for another (none, or `warn`) appends a `settle` part at that place:
45
+ `{kind: "settle", of: "card", id:, was: "asks" | "warn", now: nil | "warn"}`. A title-only update, a card that never
46
+ waited and one that starts waiting later get none. `replay_events` replays it as `{type: :part_settled, of:, id:,
47
+ was:, now:}` with or without cards (a join's page that has no such card ignores it; a participant's read drops the
48
+ type). A question needs no settle part: its own `notice` parts (`question_requested`, then `question_answered` or
49
+ `question_cancelled`) are its arrival and its settle. The page orders a finished turn's pieces from these marks
50
+ (`turn_settle.js`, docs/internals/web-frontend.md).
42
51
 
43
52
  At the terminal event, before clearing, the accumulator hands a deep copy of the turn and the end event to its
44
53
  `on_turn_end:` hook (the Bridge's `TurnDrawings#append`). The hook runs under the accumulator's mutex and the