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.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -1
  3. data/docs/architecture.md +4 -2
  4. data/docs/bundles.md +16 -7
  5. data/docs/cli.md +30 -6
  6. data/docs/context.md +25 -1
  7. data/docs/guardrails.md +3 -2
  8. data/docs/internals/attached-context.md +26 -4
  9. data/docs/internals/background-tasks.md +26 -2
  10. data/docs/internals/block-renderers.md +2 -2
  11. data/docs/internals/bridge.md +28 -8
  12. data/docs/internals/bundles.md +63 -34
  13. data/docs/internals/engine.md +1 -1
  14. data/docs/internals/remote-sessions.md +6 -1
  15. data/docs/internals/session-lifecycle.md +17 -8
  16. data/docs/internals/web-frontend.md +25 -4
  17. data/docs/internals/working-set.md +31 -5
  18. data/docs/plugins.md +14 -3
  19. data/docs/releasing.md +3 -3
  20. data/docs/scheduling.md +12 -1
  21. data/docs/sessions.md +16 -6
  22. data/docs/testing.md +4 -1
  23. data/lib/samagotchi/block_renderers.rb +12 -14
  24. data/lib/samagotchi/bootstrap/bundles.rb +2 -2
  25. data/lib/samagotchi/bootstrap_command.rb +1 -1
  26. data/lib/samagotchi/bridge/card_store.rb +2 -19
  27. data/lib/samagotchi/bridge/card_wait.rb +34 -0
  28. data/lib/samagotchi/bridge/turn_accumulator.rb +22 -4
  29. data/lib/samagotchi/bridge.rb +38 -6
  30. data/lib/samagotchi/bundle_command/check.rb +10 -10
  31. data/lib/samagotchi/bundle_command/installed_check.rb +2 -2
  32. data/lib/samagotchi/bundle_command/try/sandbox.rb +3 -3
  33. data/lib/samagotchi/bundle_command.rb +17 -17
  34. data/lib/samagotchi/bundle_manifest.rb +579 -0
  35. data/lib/samagotchi/bundle_needs.rb +9 -8
  36. data/lib/samagotchi/bundle_settings_check.rb +9 -8
  37. data/lib/samagotchi/bundles/claude-peer/manifest.yml +5 -3
  38. data/lib/samagotchi/bundles/claude-peer/plugin.rb +4 -4
  39. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +11 -6
  40. data/lib/samagotchi/bundles/codex-peer/manifest.yml +5 -3
  41. data/lib/samagotchi/bundles/codex-peer/plugin.rb +4 -3
  42. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +11 -6
  43. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  44. data/lib/samagotchi/bundles/system/memory_guide.md +1 -1
  45. data/lib/samagotchi/compat.rb +0 -7
  46. data/lib/samagotchi/config.rb +2 -2
  47. data/lib/samagotchi/context_absorber.rb +36 -6
  48. data/lib/samagotchi/context_note.rb +8 -5
  49. data/lib/samagotchi/context_providers.rb +30 -27
  50. data/lib/samagotchi/context_sources.rb +42 -12
  51. data/lib/samagotchi/engine/events.rb +43 -0
  52. data/lib/samagotchi/engine/messages.rb +1 -1
  53. data/lib/samagotchi/engine.rb +9 -3
  54. data/lib/samagotchi/event_fanout.rb +56 -0
  55. data/lib/samagotchi/events.rb +6 -5
  56. data/lib/samagotchi/guardrail_wiring.rb +20 -21
  57. data/lib/samagotchi/guardrails/approval.rb +3 -2
  58. data/lib/samagotchi/guardrails/approvals.rb +0 -4
  59. data/lib/samagotchi/guardrails/outside.rb +3 -3
  60. data/lib/samagotchi/{memory_bundle → installed_bundles}/bundle_hook.rb +1 -1
  61. data/lib/samagotchi/installed_bundles/dir.rb +129 -0
  62. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_digest.rb +1 -1
  63. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_standing.rb +2 -2
  64. data/lib/samagotchi/{memory_bundle/installed_manifest.rb → installed_bundles/manifest.rb} +21 -21
  65. data/lib/samagotchi/{memory_bundle → installed_bundles}/plugin_ref.rb +2 -2
  66. data/lib/samagotchi/{memory_bundle/installed_bundle.rb → installed_bundles/record.rb} +17 -17
  67. data/lib/samagotchi/installed_bundles/sha.rb +41 -0
  68. data/lib/samagotchi/installed_bundles/standing.rb +45 -0
  69. data/lib/samagotchi/installed_bundles.rb +90 -0
  70. data/lib/samagotchi/memory_bundle/asset_installer.rb +7 -7
  71. data/lib/samagotchi/memory_bundle/builder.rb +13 -13
  72. data/lib/samagotchi/memory_bundle/file_state.rb +9 -9
  73. data/lib/samagotchi/memory_bundle/installed_copy.rb +6 -6
  74. data/lib/samagotchi/memory_bundle/installer.rb +33 -33
  75. data/lib/samagotchi/memory_bundle/listing.rb +5 -5
  76. data/lib/samagotchi/memory_bundle/manifest_standing.rb +7 -7
  77. data/lib/samagotchi/memory_bundle/merger.rb +15 -15
  78. data/lib/samagotchi/memory_bundle/profile.rb +8 -8
  79. data/lib/samagotchi/memory_bundle/provenance.rb +59 -192
  80. data/lib/samagotchi/memory_bundle/remerge.rb +16 -16
  81. data/lib/samagotchi/memory_bundle/shas.rb +2 -2
  82. data/lib/samagotchi/memory_bundle/shipped_history.rb +1 -1
  83. data/lib/samagotchi/memory_bundle/shipped_update.rb +17 -17
  84. data/lib/samagotchi/memory_bundle/status.rb +15 -15
  85. data/lib/samagotchi/memory_bundle/system_bundle.rb +12 -12
  86. data/lib/samagotchi/memory_bundle/trash.rb +2 -2
  87. data/lib/samagotchi/memory_bundle/uninstaller.rb +8 -8
  88. data/lib/samagotchi/memory_bundle.rb +2 -2
  89. data/lib/samagotchi/memory_command.rb +4 -4
  90. data/lib/samagotchi/{memory_bundle → memory_index}/entry_size.rb +8 -8
  91. data/lib/samagotchi/{memory_bundle/index_size.rb → memory_index/size.rb} +6 -6
  92. data/lib/samagotchi/{memory_bundle/index_sync.rb → memory_index/sync.rb} +5 -5
  93. data/lib/samagotchi/{memory_bundle/index_updater.rb → memory_index/updater.rb} +2 -2
  94. data/lib/samagotchi/memory_usage.rb +5 -5
  95. data/lib/samagotchi/muted_memories.rb +1 -1
  96. data/lib/samagotchi/peer_exchanges.rb +76 -0
  97. data/lib/samagotchi/plugin/context.rb +4 -0
  98. data/lib/samagotchi/plugin/loader.rb +35 -33
  99. data/lib/samagotchi/plugin/peer.rb +42 -11
  100. data/lib/samagotchi/project_subfolders.rb +9 -9
  101. data/lib/samagotchi/reply_wait/target.rb +11 -4
  102. data/lib/samagotchi/schedules.rb +9 -4
  103. data/lib/samagotchi/self_report.rb +14 -14
  104. data/lib/samagotchi/session_access/contract.rb +4 -0
  105. data/lib/samagotchi/session_access/local.rb +32 -5
  106. data/lib/samagotchi/session_access/remote.rb +44 -10
  107. data/lib/samagotchi/session_archive_command.rb +38 -10
  108. data/lib/samagotchi/session_chain/delete.rb +75 -25
  109. data/lib/samagotchi/session_config.rb +23 -19
  110. data/lib/samagotchi/session_delete_command.rb +33 -10
  111. data/lib/samagotchi/session_lifecycle/allowed.rb +12 -9
  112. data/lib/samagotchi/session_manager/lifecycle.rb +12 -26
  113. data/lib/samagotchi/session_manager/removal.rb +109 -25
  114. data/lib/samagotchi/session_manager/running_tasks.rb +347 -0
  115. data/lib/samagotchi/session_retention.rb +13 -4
  116. data/lib/samagotchi/session_stores.rb +3 -0
  117. data/lib/samagotchi/sessions_command.rb +1 -1
  118. data/lib/samagotchi/system_prompt.rb +4 -4
  119. data/lib/samagotchi/task_files.rb +37 -4
  120. data/lib/samagotchi/terminal_ui/attach_launcher.rb +5 -1
  121. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +7 -1
  122. data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
  123. data/lib/samagotchi/terminal_ui/formatting.rb +2 -2
  124. data/lib/samagotchi/terminal_ui/local_link.rb +11 -3
  125. data/lib/samagotchi/terminal_ui/model_segments_text.rb +5 -5
  126. data/lib/samagotchi/terminal_ui.rb +4 -1
  127. data/lib/samagotchi/testing/bundle.rb +3 -3
  128. data/lib/samagotchi/testing/install.rb +3 -3
  129. data/lib/samagotchi/testing/sandbox.rb +2 -2
  130. data/lib/samagotchi/tool_runner.rb +14 -14
  131. data/lib/samagotchi/tools/memory.rb +22 -22
  132. data/lib/samagotchi/tools/task_runtime.rb +25 -6
  133. data/lib/samagotchi/update_command.rb +4 -4
  134. data/lib/samagotchi/version.rb +1 -1
  135. data/lib/samagotchi/web/app.rb +19 -2
  136. data/lib/samagotchi/web/message_display.rb +6 -0
  137. data/lib/samagotchi/web/participant_view.rb +1 -1
  138. data/lib/samagotchi/web/proxy_gate.rb +1 -0
  139. data/lib/samagotchi/web/public/card_kinds.js +8 -3
  140. data/lib/samagotchi/web/public/cards_place.js +15 -1
  141. data/lib/samagotchi/web/public/ctx.js +1 -1
  142. data/lib/samagotchi/web/public/data.js +19 -7
  143. data/lib/samagotchi/web/public/delete_sheet.js +26 -7
  144. data/lib/samagotchi/web/public/history_shape.js +3 -0
  145. data/lib/samagotchi/web/public/running_tasks.js +73 -0
  146. data/lib/samagotchi/web/public/session_actions.js +57 -8
  147. data/lib/samagotchi/web/public/stop_sheet.js +3 -2
  148. data/lib/samagotchi/web/public/turn_block.js +46 -8
  149. data/lib/samagotchi/web/public/turn_settle.js +117 -0
  150. data/lib/samagotchi/web/public/working_set.js +3 -28
  151. data/lib/samagotchi/web/public/working_set_view.js +5 -2
  152. data/lib/samagotchi/web/public/ws_item_sig.js +51 -0
  153. data/lib/samagotchi/web/public/ws_peek.js +23 -13
  154. data/lib/samagotchi/web/public/ws_reader.js +22 -12
  155. data/lib/samagotchi/web/public/ws_timeline.js +9 -6
  156. data/lib/samagotchi/web/push/notifier.rb +2 -2
  157. data/lib/samagotchi/web/session_access_routes.rb +21 -1
  158. data/lib/samagotchi/web/session_control.rb +65 -16
  159. data/lib/samagotchi/web/session_hub.rb +20 -4
  160. data/lib/samagotchi/web/working_set_routes.rb +29 -8
  161. data/lib/samagotchi/worker_boot.rb +4 -1
  162. data/lib/samagotchi/worker_link.rb +9 -1
  163. data/lib/samagotchi/working_set.rb +26 -0
  164. data/lib/samagotchi/working_set_command.rb +9 -6
  165. metadata +22 -12
  166. data/lib/samagotchi/memory_bundle/manifest.rb +0 -581
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a5b330c47fac34a4e9fd4c2d602e4cbc0241fe42a953bba227b6526ef619e7b
4
- data.tar.gz: 4c9ae4e9df6279202aa9540984c70148ef1ea6d2e9898542cb219ab1980b6f14
3
+ metadata.gz: 02c5f9b0ce43fa25f771a11ec298032ffa639b9423f5df2e934b376eef808327
4
+ data.tar.gz: 0ff81b27a6bea746ecc98735a23e6cff79db33abcba48684cad5421177cebe73
5
5
  SHA512:
6
- metadata.gz: bc2236c6ee5a909b4cfef2b66ab813b1546b9c8fe432734aec2909f84703cbe3dba48491a0e1a02f115650c9252ce9d087ea9e1b8dba327b61e5b483a9541d47
7
- data.tar.gz: a5b1653706fd962459dd639a4487d45bb28e96cdf3e022148d3fe4ce19967c84dd5a911d2f9014ad778c75945dfb0194b5c682549dd5fb39ec0c4886b3c0f65d
6
+ metadata.gz: abc693ecff041c7c142742487336cd34b16e6738a260a240e3f4194a841fea77bc752ff613d2322ad850f94c0e23fe49034b4765485385d3cb46dba96f2948ea
7
+ data.tar.gz: b7ad5b7323b35f7e748fbe0349f84ccdf2c046691cff8f1ac298369ca741ef0198873a1c7f25ec1cb49835277f8adb54b30e683db72fa027ca823d3e10b20163
data/CHANGELOG.md CHANGED
@@ -8,6 +8,57 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.179.0] - 2026-11-20
12
+
13
+ ### Added
14
+
15
+ - A peer's answer names the send it answers: claude-peer and codex-peer messages carry a `ref:` line, the peers'
16
+ chi-peer skills give it back as `re` in their reply (reinstall the skill with `/claude install-skill` or
17
+ `/codex install-skill`), and chi keeps it on the answer's note and the send's row for the web to tie them. The
18
+ model reads the same text as before; an older skill's answer works as before, unlinked.
19
+ - A per-session peer exchange log records sends, transport failures and answer summaries for the owner's web view,
20
+ without storing answer texts.
21
+
22
+ ### Changed
23
+
24
+ - The retention sweep, and a `chi scratch` session's cleanup, stop the background tasks a deleted session started
25
+ (logged per task); the sweep now runs off chi web's session list lock.
26
+
27
+ ### Fixed
28
+
29
+ - A guardrail plugin (`plugin: required: true`) whose bundle's manifest.json doesn't read now denies tool calls,
30
+ as its rules would, instead of only being reported.
31
+ - A reloaded turn keeps an answered question and an asking card (check-in's) in the order they showed live: a card
32
+ that stopped asking mid-turn no longer moves back into its first step, and one still asking no longer jumps above
33
+ the question answered after it.
34
+
35
+ Update with `chi update`.
36
+
37
+ ## [0.178.0] - 2026-11-20
38
+
39
+ ### Changed
40
+
41
+ - Deleting or archiving a session whose background tasks still run now asks first: the web names them and offers to
42
+ stop them and delete/archive; `chi sessions delete|archive` (and `/archive`, `/exit --delete`) refuse and name them,
43
+ and `--stop-tasks` stops them first. With `--remote` this needs this chi on both ends: an older chi web can't stop
44
+ them, an older CLI can't delete or archive such a session there.
45
+ - chi no longer reads a guardrail approvals.json list written by chi 0.166 and before (set aside with a warning; allow
46
+ again what you need), or a session's cards.json from before 0.151.0 (earlier cards don't show).
47
+
48
+ ### Fixed
49
+
50
+ - `chi sessions restart` no longer refuses its fallback for a background task that already ended (a record a crashed
51
+ worker left marked running).
52
+ - A background task's leftover process holding its log is stopped even when chi exits just after the task's shell
53
+ ends, instead of running on after a one-shot or worker exit.
54
+ - chi web: the working set's peek and reader show a running turn's reads while it runs, not only once the turn has
55
+ ended; they ask again only when the open item changed.
56
+ - `chi sessions restart` (and the web's restart) of a session being deleted says "the session is being deleted"
57
+ instead of "its worker is still starting"; a schedule's skip says the same, and for a worker on a newer chi says
58
+ to restart chi web or update chi, instead of "its worker is starting or leaving".
59
+
60
+ Update with `chi update`.
61
+
11
62
  ## [0.177.1] - 2026-11-19
12
63
 
13
64
  ### Fixed
@@ -6496,7 +6547,9 @@ and long-lived sessions.
6496
6547
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
6497
6548
  hotkey panel that send selected text or the clipboard to your sessions.
6498
6549
 
6499
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.177.1...HEAD
6550
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.179.0...HEAD
6551
+ [0.179.0]: https://github.com/dm1try/samagotchi/compare/v0.178.0...v0.179.0
6552
+ [0.178.0]: https://github.com/dm1try/samagotchi/compare/v0.177.1...v0.178.0
6500
6553
  [0.177.1]: https://github.com/dm1try/samagotchi/compare/v0.177.0...v0.177.1
6501
6554
  [0.177.0]: https://github.com/dm1try/samagotchi/compare/v0.176.0...v0.177.0
6502
6555
  [0.176.0]: https://github.com/dm1try/samagotchi/compare/v0.175.0...v0.176.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,20 @@ 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.
1014
1018
  - **The tool `claude_send(kind, title, text)`**, `kind` being `validate`,
1015
1019
  `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,
1020
+ starts with a header, `chi <id> · <kind> · <title>`, and a second line,
1021
+ `ref: <send id>` (`s-` and 6 hex, from the kind, title and text as given:
1022
+ the same part sent again has the same id), which Claude's answer gives back
1023
+ so chi can tie it to its send; the tool's row in the web carries the id too.
1024
+ A text up to 4,000 characters follows inline; a longer one goes to a file,
1018
1025
  `$XDG_STATE_HOME/samagotchi/plugins/claude-peer/sessions/<id>/<HHMMSS>-<slug>.md`
1019
1026
  (removed with the session), and the message names it (`payload: <path>`).
1020
1027
  The tool is declared whether or not a Claude is paired, so pairing doesn't
@@ -1195,8 +1202,10 @@ skill install card) works the same.
1195
1202
  `sh <bundle>/scripts/pair` attaches `codex-inbox` (the thread id as its
1196
1203
  hint, pushed so a re-pair refreshes it) and `codex-outbox`. Run outside
1197
1204
  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`).
1205
+ to `codex-outbox` (`text`, `summary`, `wake: true`, `re`: the message's `ref:`
1206
+ line), which wakes chi, the first answer too (that needs chi 0.63.0; the bundle's
1207
+ `requires_chi` is `>= 0.70.0`). The session's peer exchange log keeps sends
1208
+ and answer summaries, not answer texts.
1200
1209
  - **Peer messages are user turns in Codex.** Claude Code marks an inbox
1201
1210
  message as from another session; `codex queue` lands as a plain user
1202
1211
  message. So Codex's skill starts with the rule: a message whose first line
data/docs/cli.md CHANGED
@@ -18,7 +18,7 @@
18
18
  - `chi web --web-markdown` / `--no-web-markdown` — opt in to, or opt out of, sanitized Markdown rendering for completed assistant messages, the stage's asking text and a resolved question card's reply (`web.markdown`, off by default; `--no-web-markdown` turns a config's `web.markdown: true` off for this run)
19
19
  - `chi web --no-web-working-set` — turns the stage view's working set off (on by default; `--web-working-set` turns a config's `web.working_set: false` back on): what each turn brought into the model's context, in the stage and under each finished turn; `?working_set=1|0` on the page URL overrides it (see [The working set](#the-working-set))
20
20
  - `chi web --web-stage-collapsed` / `--no-web-stage-collapsed` — every session's stage starts folded to its status row, or not (`web.stage_collapsed`, off by default); a session folded or unfolded by hand keeps its own fold in that browser
21
- - `chi sessions list|stop|restart|archive|unarchive|delete|prune|clean|stats` — manage persisted sessions; `list` shows this git project's, `list --scope=all` every one, a delegated session with `↳ <parent>`, `list --archived` the archived ones too (see [Sessions](sessions.md)); one line per session (`<id> <state> <ctx> <updated_at> <text> [flags] ↳ … ↪ …`) and one footer (`N session(s) (sort=… order=…)`, or the project note) for the plain list, the `--live`/`--cwd` text and `--remote`. `stats ID` prints a session's cost, tokens and progress, and its own settings (`--set`; a `settings:` line), from a live worker's `GET stats`, else its saved `analytics.json` (`--format json` one object, with `settings`), without running a model turn. A usage error (an unknown subcommand or flag, a flag missing its value, `stop`, `restart` or `delete` with no ids, a bad `list --format`, `--scope`, `--sort` or `--order`, a `--days`, `--keep` or `--limit` that isn't a whole number) exits 2; an unknown or refused session exits 1
21
+ - `chi sessions list|stop|restart|archive|unarchive|delete|prune|clean|stats` — manage persisted sessions; `list` shows this git project's, `list --scope=all` every one, a delegated session with `↳ <parent>`, `list --archived` the archived ones too (see [Sessions](sessions.md)); one line per session (`<id> <state> <ctx> <updated_at> <text> [flags] ↳ … ↪ …`) and one footer (`N session(s) (sort=… order=…)`, or the project note) for the plain list, the `--live`/`--cwd` text and `--remote`. `stats ID` prints a session's cost, tokens and progress, and its own settings (`--set`; a `settings:` line), from a live worker's `GET stats`, else its saved `analytics.json` (`--format json` one object, with `settings`), without running a model turn. A usage error (an unknown subcommand or flag, a flag missing its value, `stop`, `restart` or `delete` with no ids, `unarchive --stop-tasks`, a bad `list --format`, `--scope`, `--sort` or `--order`, a `--days`, `--keep` or `--limit` that isn't a whole number) exits 2; an unknown or refused session exits 1
22
22
  - `chi note [--source NAME] [-m TEXT] (ID|PREFIX)... | --all` — add a context note (TEXT or stdin) to sessions: background the model sees on its next turn; it starts no turn (see [Sessions: Context notes](sessions.md#context-notes))
23
23
  - `chi broadcast [-m TEXT] [--all] [--dry-run]`, `chi broadcast log [--last N] [--format json]`, `chi broadcast deliver BROADCAST_ID (ID|PREFIX)...` — share one piece of information (TEXT or stdin) with every session it may concern, as a context note from `broadcast` (see [Broadcast](broadcast.md))
24
24
  - `chi context <add|push|ls|show|refresh|rm|mute|unmute> …` — attach live external text to sessions (a command chi runs every so often, or text pushed in); the model gets a short note when it changes and reads it with `context_read`; `chi context add <URL>` attaches a GitHub PR with the github-pr bundle; `chi context push NAME -m TEXT` (the long form is `--message TEXT`) gives a `--push` source its new text, read from stdin when no `-m` is given (see [Attached context](context.md))
@@ -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
@@ -763,10 +765,16 @@ a delegate's follow-up or a reminder. The web archives from the info bar
763
765
  (`archive`, before `stop`); the `archived` toggle by the all-sessions search
764
766
  finds archived sessions. `/archive` in a terminal leaves the session and
765
767
  archives it (an empty session is discarded instead; `chi scratch` refuses
766
- it). See
768
+ it). A session whose background tasks (its `task_create` tasks, an `execute`
769
+ handed over at its limit, its delegates' too) still run is refused, naming
770
+ them (`ab12cd34 refused: background tasks it started are still running: npm
771
+ run dev (--stop-tasks stops them first)`, exit 1); `archive --stop-tasks`
772
+ stops them first (TERM, then KILL) and says so (`archived (stopped its
773
+ worker; stopped 1 background task)`). `/archive` says the same and names
774
+ `chi sessions archive --stop-tasks ID`; the web asks a second confirm. See
767
775
  [Sessions](sessions.md#archiving-a-session).
768
776
 
769
- `chi sessions delete [--force] [--chain] ID...` deletes sessions for good: the
777
+ `chi sessions delete [--force] [--chain] [--stop-tasks] ID...` deletes sessions for good: the
770
778
  session file and its whole directory (notes, images, queued input). Each id
771
779
  (or unique prefix) gets one line: `deleted`, or `refused` with the reason.
772
780
  Deleting a chain's newest link undoes its continue and says so (`… deleted;
@@ -778,10 +786,20 @@ schedule on the chain refuses it. See docs/sessions.md (Session chains →
778
786
  Deleting a link). A
779
787
  session whose worker runs is refused unless `--force` stops the worker first;
780
788
  one a `--non-interactive` run has is always refused ("in use by a one-turn chi
781
- --non-interactive run or an older chi's terminal; let it finish first"). Exit
789
+ --non-interactive run or an older chi's terminal; let it finish first"). A
790
+ session whose background tasks still run (its own, or a delegate's or link's
791
+ the delete takes) is refused, naming them (`refused: background tasks it
792
+ started are still running: npm run dev, rspec (--stop-tasks stops them
793
+ first)`); `--stop-tasks` stops them first and the line says so (`deleted
794
+ (stopped its worker; stopped 2 background tasks)`; one chi can't verify or
795
+ read is never signalled: `1 not stopped: task 3f9a2c1d (may still be
796
+ running)`). `--stop-tasks` is not `--force`: a live worker is still refused
797
+ without it. `/exit --delete` refuses the same way and names `chi sessions
798
+ delete --stop-tasks ID`. Exit
782
799
  status: 0 when all are gone, 1 when any was refused or unknown, 2 on a usage
783
800
  error. The Web UI deletes too: `delete` in the info bar, or the ✕ on a card in
784
- All sessions; it asks first and stops a live worker.
801
+ All sessions; it asks first and stops a live worker, and asks again, naming
802
+ them, when background tasks still run (OK stops them).
785
803
 
786
804
  `chi sessions stats ID [--format text|json]` prints a session's cost, tokens
787
805
  and progress without running a model turn — the same text `/stats` prints in
@@ -1653,6 +1671,12 @@ CHI_REMOTE=studio chi context push claude-outbox ab12 < answer.json
1653
1671
  answer ab12 --question q1 --option N`, `chi --remote studio send --wait …`),
1654
1672
  under `CHI_REMOTE` too, an attach as well (`chi --remote studio --attach
1655
1673
  ab12 shows it`, `sessions stop`'s `chi --remote studio --resume ab12`).
1674
+ - `sessions delete|archive --stop-tasks` needs a chi web there that lists the
1675
+ `stop_tasks` feature (`GET /api/info`); an older one is refused before
1676
+ anything is sent (update and restart chi web there), and without the flag
1677
+ an older one deletes or archives as it always did. A new chi web answers an
1678
+ older CLI's delete or archive of a session whose tasks run with 409
1679
+ `tasks_running`, which that CLI prints as a failure.
1656
1680
  - A remote that can't be reached names itself and why (`chi send: remote
1657
1681
  studio (http://192.168.1.29:4567): connection refused`, exit 1; with
1658
1682
  `--format json` an `error` object).
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
@@ -326,6 +329,20 @@ lower.) Every other source keeps the line above. `context.peer_turns: 0` turns
326
329
  the loop off: a peer source then wakes like any other. `context_read` names a
327
330
  peer source in its header (`Peer: your peer agent Codex's answers …`).
328
331
 
332
+ Each message chi sends a peer carries a `ref: <id>` line, and the peer's
333
+ answer gives it back as `re` ([the contract](#the-command-contract)). The
334
+ answer's note keeps whose answer it is (the peer, `re`, its summary and
335
+ verdict) for the web to tie it to its send; the model's note reads as it
336
+ did. That holds for a declared peer source, with the loop on or off.
337
+
338
+ **Outside the worker it is by name.** chi web and the CLI load no plugins,
339
+ so where they show a pairing (a context row's `peer`, `leg` and `label`) a
340
+ pushed source of the session's own named `<word>-inbox` or `<word>-outbox` is
341
+ taken for one: `review-outbox` gets a peer chip too, and changed pushes to it
342
+ are logged as answers. That is display and logging only:
343
+ what is a peer's answer, and what may wake chi and how, is still the bundle's
344
+ declaration in the worker, as above.
345
+
329
346
  ## Movable context
330
347
 
331
348
  A session's own sources go with it to the next session of its work: the next
@@ -690,5 +707,12 @@ The candidates' log, `context_candidates.jsonl`, sits one level up, beside
690
707
  the sessions folder (`$XDG_STATE_HOME/samagotchi/`; see
691
708
  [The log and the report](#the-log-and-the-report)).
692
709
 
710
+ Peer exchange metadata lives separately in the session sidecar at
711
+ `$XDG_STATE_HOME/samagotchi/sessions/<id>/peer_exchanges.jsonl`. It records
712
+ sends, transport failures and answer summaries, not answer text. It is
713
+ append-only and uncapped; a continue starts a new log with its new pairing.
714
+ An unchanged text is not a new revision, even if its `re` changes, so it
715
+ does not add an answer to the log.
716
+
693
717
  Deleting a session deletes its folder. A source and its snapshot go with
694
718
  `chi context rm`; its `.lock` stays (a fetch may still hold it).
data/docs/guardrails.md CHANGED
@@ -121,7 +121,7 @@ looks in the store): an owner's ask uses every scope; a [participant's turn](#a-
121
121
  (`Verdict#fresh_ask`) uses none.
122
122
  The file is a versioned store (`{"version": 1, "approvals": [...]}`, `Approvals::FORMAT`); a write keeps its version,
123
123
  the keys this chi doesn't know and an entry with no `scope`. A bare list of entries, as chi 0.166 and before wrote it,
124
- is read and converted to a versioned store on the next write. Chi 0.165 and before set a versioned store aside, so restart their sessions
124
+ is now set aside like an unreadable file. Chi 0.165 and before set a versioned store aside, so restart their sessions
125
125
  (`chi sessions restart`); a downgrade to 0.165 or before moves the store to a recoverable `approvals.json.corrupt-*`.
126
126
  A file that doesn't parse, or a versioned store whose `approvals` isn't a list, is moved aside to
127
127
  `approvals.json.corrupt-<UTC time>` with one warning, and chi starts with no stored approvals (more asks, nothing lost).
@@ -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`.
@@ -20,9 +20,9 @@ load the process code, and does not (`spec/require_cycle_spec.rb`, the thin clie
20
20
 
21
21
  | Module | Holds | Read by |
22
22
  |---|---|---|
23
- | `Tools::TaskRuntime` (`tools/task_runtime.rb`) | the lifecycle: `create_task`, `adopt`, the waiter (`record_exit_status`, `waiter_for`), refresh, `stop_task`, `get_record`, `list_records`, `running_created_in`, the leftovers; all process state (`@waiters`, `@settle_lock`) | the task tools, `execute`, `Bridge`, `HoldStop`, `TaskWatch`, `TurnEndings`, `Worker` |
23
+ | `Tools::TaskRuntime` (`tools/task_runtime.rb`) | the lifecycle: `create_task`, `adopt`, the waiter (`record_exit_status`, `waiter_for`), refresh, `stop_task`, `get_record`, `list_records`, `running_created_in`, the leftovers; all process state (`@waiters`, `@settle_lock`) | the task tools, `execute`, `Bridge`, `HoldStop`, `TaskWatch`, `TurnEndings`, `Worker`, `SessionManager::RunningTasks.stop!` (loaded at call time) |
24
24
  | `SpawnEnv` (`spawn_env.rb`) | the env a spawned command gets: `sanitized_spawn_env`, `spawn_env_for` (task_create's `env` checks), `SANITIZED_ENV_KEYS`, `MARKER_ENV_KEYS` | `execute`, `create_task`, `ProjectEnv.spawn_env` (required at call time: `child_env` requires `project_env`) |
25
- | `TaskFiles` (`task_files.rb`) | where a task's files are: `TASKS_DIR`, `METADATA_FILENAME`, `OUTPUT_FILENAME`, `EXIT_CODE_FILENAME`, `TASK_ID`, `metadata_path`, `task_dir_for`, `command_of` (a record read, no refresh) | `TaskRuntime`, `execute`, `ToolActivity`, `SessionManager`, `chi bundle try`'s sandbox, the slow-commands bundle |
25
+ | `TaskFiles` (`task_files.rb`) | where a task's files are: `TASKS_DIR`, `METADATA_FILENAME`, `OUTPUT_FILENAME`, `EXIT_CODE_FILENAME`, `TASK_ID`, `metadata_path`, `task_dir_for`, `tasks_dir`, `command_of` (a record read, no refresh), `with_root` (this thread's paths under another folder) | `TaskRuntime`, `execute`, `ToolActivity`, `SessionManager`, `chi bundle try`'s sandbox, the slow-commands bundle |
26
26
  | `TaskTranscript` (`task_transcript.rb`) | which tasks a conversation started, from its results' text: `created_ids_in`, `created_id`, `handed_over_id`, `RAN_AS_LINE` (matching on `ToolNames::Execute`) | `TaskRuntime.running_created_in`, `Bridge`, `TaskWatch`, `WorkerTaskWakes`, `SessionManager` |
27
27
 
28
28
  Behavior:
@@ -35,6 +35,30 @@ Behavior:
35
35
  - `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped (the result's hint says to start a long job with `task_create` in the foreground, no `&`: a `cmd &` left behind there is stopped too); one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, which says chi can't stop it and to kill it if it shouldn't run, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
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
+ - 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
40
+ 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
+ remains. A shell still running at the snapshot, including one that exits during the join, is not waited on; a crash
42
+ or SIGKILL cannot wait either. With no later reader of that cwd, such leftovers can still run on.
43
+ - Nothing stops a running task when its worker leaves, so a user's delete or archive asks about the tasks the session
44
+ (and what the op takes with it) started: `SessionManager::RunningTasks` (`session_manager/running_tasks.rb`).
45
+ `.of(ids, state_dir:)` reads, per session, its file's transcript (`TaskTranscript.created_ids_in`) and each
46
+ `<working_directory>/tmp/tasks/<id>/task.json`, writing nothing and loading no `TaskRuntime`: a `Listing` of
47
+ `running` (the pid leads its group at the recorded `pid_started`), `unverified` (a group leader with no start time
48
+ to compare: none recorded, or none readable now) and `unreadable` (log `session_task_check_failed`). `Policy`
49
+ (`IGNORE`, the default; `REFUSE`; `Policy.stop(by:)` with its `Tally`) is the op's `running_tasks:`; restart's
50
+ fallback holds on a non-empty listing too. `.stop!` signals only `running` entries, one thread each, each running
51
+ `TaskRuntime.stop_task(id, by:)` inside `TaskFiles.with_root(root)`, all joined against one deadline
52
+ (`STOP_GRACE_SEC + ProcessGroup::KILL_WAIT_SEC + 0.5`); outcomes `stopped`, `ended`, `failed`, `unconfirmed` (and
53
+ the never-signalled `unverified`/`unreadable`) go into the tally, no command text logged.
54
+ `TaskFiles.with_root` sets a thread-local root that `metadata_path`, `task_dir_for`, `tasks_dir`,
55
+ `ensure_tasks_dir`, `list_records`' glob and `log_paths` (a relative `output_path` joined at read, stored unchanged)
56
+ 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
+ thread the block starts doesn't inherit it (only `create_task` starts waiters, and nothing calls it under a root).
58
+ See [sessions.md](../sessions.md) (Deleting a session).
59
+ - Retention and scratch cleanup use the same rule without asking: verified tasks stopped by them record
60
+ `stopped_by_retention` or `stopped_by_scratch`, not `stopped_by_user`. Unverified and unreadable tasks are not
61
+ signalled and are logged as not stopped. Schedule prune leaves tasks running.
38
62
  - 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.
39
63
  - 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.
40
64
  - `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,12 +10,12 @@ 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
20
  doesn't parse is logged once per bundle and problem (each list request and file fetch reads it).
21
21
  3. `block_watch.js` (`createBlockWatch`, made by `block_host.js`'s `createBlockHost`, wired in `app.js`; a participant's page
@@ -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
@@ -209,8 +218,9 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
209
218
  so the stamp and the count always name one place, and the page finds it by the bubble (`card_stamps.js`: `data-turn-id`, or `data-opening-id` on a wake's note or a reason line), not by counting
210
219
  bubbles. An entry shown after reason lines also saves which one it came after (`after_opening`, beside `past_idless`): read
211
220
  first while that line is still in the run, so a later release can drop the count. No stamp (the page counts `turns_since`) for
212
- an entry before every opening, after a line an older chi wrote with no id, or from a version 1 file (`base_since`). A rollback
213
- keeps today's rule: a rolled-back turn's cards name the opening before it.
221
+ an entry before every opening or after a line an older chi wrote with no id. A version 1 file is no longer read (its earlier
222
+ cards do not show); `base_since` remains readable in version 2 files saved since. A rollback keeps today's rule: a rolled-back
223
+ turn's cards name the opening before it.
214
224
  The saved recap carries the same stamp: `saved_recap`'s `opening_id` (`RecapPlace.opening_id`, the id of the last
215
225
  opening its `covered` messages hold, read at read time, so `recap.json` is unchanged), which the page places it after
216
226
  (`recap_stamp.js`); an older worker's `saved_recap` has none, and the page counts `turns_since`.
@@ -237,9 +247,8 @@ the "asking again" and steer-cut rows, ✂ rows and questions (with how they wer
237
247
  are the worker's own (each start announces them) and an unanswered question waits for no one: neither is saved or seeded. An
238
248
  entry from an earlier worker lists with `earlier: true`; one shown during a turn comes back **without its actions** (their
239
249
  turn no longer runs), while a between-turns card keeps its buttons.
240
- - **Version 1.** A file from before the log (top-level `turns`, each entry its own, maybe `running`) keeps its places, drift
241
- included: `seed` turns each count into `base_since`, new openings add to it, and such an entry never reads as having left
242
- nothing (no id to check). The next save writes version 2 with `base_since` kept. `SessionManager.cards_empty?` reads both.
250
+ - **Version 1.** A file from before the log (top-level `turns`, each entry its own, maybe `running`) is no longer read, so its
251
+ earlier cards do not show. `SessionManager.cards_empty?` still reads both versions to decide whether a session is empty.
243
252
  - **An older chi on a version 2 file.** Its `seed` wants an integer `turns`, finds none, and starts with no entries. A chi web not
244
253
  yet restarted only reads: it lists no cards for that session until restarted, and the file stays whole. An older **writer** does
245
254
  damage: at its first saved event, `:turn_started`, it writes `{"version":1,"turns":0,"running":true,"entries":[]}` over the file
@@ -488,7 +497,17 @@ The Bridge exposes:
488
497
  `cards` (`CardStore#list`; a card an earlier worker showed during a turn comes back read-only, with no
489
498
  actions: its turn no longer runs), `event_seq`, `event_id`, all taken in one event-log hold; no message
490
499
  list, so it costs the same however long the session is. `?turn_id=` answers that turn's answer
491
- (an unknown or missing id: the newest); the only route that reads its query.
500
+ (an unknown or missing id: the newest). A handler in `Bridge::QUERY_HANDLERS` gets the query string; no other one does.
501
+ - `GET /session/:id/working_set/item?kind=&key=[&now=1][&latest=1]` — what the model has of one working-set item
502
+ (`Engine#working_set_item`: `WorkingSet.timeline_of`'s `{kind, key, events}`, `now:` for a memory with `now=1`;
503
+ with `latest=1` only the peek's events and `counts`, `WorkingSet::Timeline#peek_h`), plus
504
+ `at` (the conversation's size it was built from) and `running`. While a turn runs it reads the turn's view
505
+ (`EventFanout#turn_view`: a shallow copy of the running turn's conversation taken at each `:generation_started`,
506
+ used only while that turn's id is the running one, dropped at the turn's end under the event lock), else a copy of
507
+ the session's messages. `400 invalid_item`
508
+ (`WorkingSet::INVALID_ITEM`, chi web's words) for a kind it doesn't know or a blank key. Owner-only is chi web's
509
+ (its route is `:owner`); the Bridge's gate is its secret. Advertised as `working_set_item`
510
+ ([working-set.md](working-set.md#delivery)).
492
511
  - No browser: only chi's own clients talk to a Bridge. A request with an `Origin` header, a `Sec-Fetch-Site`
493
512
  other than `none`, or a `Host` that isn't loopback (a DNS-rebound page) is `403 cross_origin`
494
513
  (`Bridge#browser_request?`, before any route); there is no CORS and no `OPTIONS` route. The browser reaches a
@@ -647,6 +666,7 @@ compatibility from its version. `Bridge::FEATURES` advertises:
647
666
  | `cancel_turn_id` | `POST /session/:id/cancel` can stop only the named turn. |
648
667
  | `participant_revise` | chi web can pass a participant's Revise draft for worker-side validation. |
649
668
  | `participant_client_id` | chi web can identify a participant as `participant:<id>` instead of using the legacy `review:<id>`. |
669
+ | `working_set_item` | `GET /session/:id/working_set/item` answers one item's timeline (the running turn's mid-turn), so chi web asks for it instead of the whole snapshot. |
650
670
 
651
671
  `chi web`'s `GET /api/sessions/:id/stream` proxies this bridge
652
672
  (503 `not_live` for no worker, a leaving or stuck worker, or an unreachable Bridge; 502 `worker_newer` for skew and