samagotchi 0.171.0 → 0.172.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -1
  3. data/bin/chi +6 -4
  4. data/docs/architecture.md +24 -7
  5. data/docs/bundles.md +4 -21
  6. data/docs/cli.md +50 -80
  7. data/docs/configuration.md +11 -13
  8. data/docs/context.md +5 -6
  9. data/docs/guardrails.md +57 -96
  10. data/docs/hooks.md +3 -4
  11. data/docs/internals/attached-context.md +6 -7
  12. data/docs/internals/background-tasks.md +4 -3
  13. data/docs/internals/bridge.md +29 -3
  14. data/docs/internals/engine.md +21 -9
  15. data/docs/internals/objectives.md +3 -5
  16. data/docs/internals/participants.md +118 -143
  17. data/docs/internals/prompt-caching.md +4 -5
  18. data/docs/internals/web-frontend.md +33 -14
  19. data/docs/internals/working-set.md +7 -5
  20. data/docs/memory.md +1 -1
  21. data/docs/plugins.md +2 -16
  22. data/docs/scheduling.md +1 -1
  23. data/docs/sessions.md +15 -49
  24. data/docs/sub-agent.md +2 -2
  25. data/docs/system-one.md +2 -2
  26. data/docs/testing.md +56 -7
  27. data/lib/samagotchi/bridge/card_store.rb +1 -0
  28. data/lib/samagotchi/bridge/sse_writer.rb +1 -0
  29. data/lib/samagotchi/bridge/turn_accumulator.rb +0 -1
  30. data/lib/samagotchi/bridge.rb +26 -9
  31. data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
  32. data/lib/samagotchi/bundle_command/test_run.rb +1 -0
  33. data/lib/samagotchi/bundle_command/try/run.rb +1 -0
  34. data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
  35. data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
  36. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
  37. data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
  38. data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
  39. data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
  40. data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
  41. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  42. data/lib/samagotchi/client_id.rb +126 -67
  43. data/lib/samagotchi/command_intake.rb +15 -3
  44. data/lib/samagotchi/compat.rb +6 -1
  45. data/lib/samagotchi/context_candidate_choice.rb +1 -3
  46. data/lib/samagotchi/context_candidates.rb +3 -4
  47. data/lib/samagotchi/continue_offer.rb +9 -2
  48. data/lib/samagotchi/delivery.rb +23 -12
  49. data/lib/samagotchi/empty_answer_error.rb +5 -0
  50. data/lib/samagotchi/engine/cards.rb +3 -0
  51. data/lib/samagotchi/engine/context_judge.rb +5 -3
  52. data/lib/samagotchi/engine/events.rb +4 -0
  53. data/lib/samagotchi/engine/hooks.rb +3 -0
  54. data/lib/samagotchi/engine/messages.rb +5 -0
  55. data/lib/samagotchi/engine/model_settings.rb +2 -0
  56. data/lib/samagotchi/engine/models.rb +10 -0
  57. data/lib/samagotchi/engine/objectives.rb +6 -0
  58. data/lib/samagotchi/engine/participants.rb +18 -14
  59. data/lib/samagotchi/engine/plugins.rb +8 -0
  60. data/lib/samagotchi/engine/questions.rb +3 -0
  61. data/lib/samagotchi/engine/recap.rb +1 -0
  62. data/lib/samagotchi/engine/session.rb +4 -0
  63. data/lib/samagotchi/engine/side_requests.rb +9 -0
  64. data/lib/samagotchi/engine/steering.rb +2 -0
  65. data/lib/samagotchi/engine/toolkit.rb +5 -0
  66. data/lib/samagotchi/engine/turn_end.rb +7 -0
  67. data/lib/samagotchi/engine/turn_helpers.rb +8 -0
  68. data/lib/samagotchi/engine/verify.rb +2 -0
  69. data/lib/samagotchi/engine.rb +3 -2
  70. data/lib/samagotchi/grants.rb +28 -22
  71. data/lib/samagotchi/guardrail_wiring.rb +23 -18
  72. data/lib/samagotchi/guardrails/approval_use.rb +59 -0
  73. data/lib/samagotchi/guardrails/approvals.rb +9 -11
  74. data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
  75. data/lib/samagotchi/guardrails/gate.rb +10 -5
  76. data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
  77. data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
  78. data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
  79. data/lib/samagotchi/guardrails/review_paths.rb +2 -3
  80. data/lib/samagotchi/guardrails.rb +1 -1
  81. data/lib/samagotchi/llm_context_strategy.rb +2 -0
  82. data/lib/samagotchi/objectives.rb +1 -4
  83. data/lib/samagotchi/objectives_audit.rb +1 -1
  84. data/lib/samagotchi/objectives_track.rb +1 -1
  85. data/lib/samagotchi/owner_prompt.rb +3 -6
  86. data/lib/samagotchi/parent_report.rb +1 -0
  87. data/lib/samagotchi/participant_messages.rb +9 -4
  88. data/lib/samagotchi/participant_turn_mode.rb +50 -0
  89. data/lib/samagotchi/participants.rb +21 -12
  90. data/lib/samagotchi/participants_watch.rb +2 -2
  91. data/lib/samagotchi/plugin/api.rb +2 -2
  92. data/lib/samagotchi/plugin/attached_context.rb +1 -1
  93. data/lib/samagotchi/plugin/context.rb +0 -4
  94. data/lib/samagotchi/plugin/sessions.rb +1 -25
  95. data/lib/samagotchi/run_options.rb +2 -3
  96. data/lib/samagotchi/send_command.rb +10 -10
  97. data/lib/samagotchi/session.rb +0 -3
  98. data/lib/samagotchi/session_access/contract.rb +1 -10
  99. data/lib/samagotchi/session_access/local.rb +10 -23
  100. data/lib/samagotchi/session_access/remote.rb +9 -20
  101. data/lib/samagotchi/session_access.rb +12 -16
  102. data/lib/samagotchi/session_chain.rb +4 -6
  103. data/lib/samagotchi/session_commands.rb +6 -3
  104. data/lib/samagotchi/session_continue.rb +1 -2
  105. data/lib/samagotchi/session_manager/delivery.rb +25 -5
  106. data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
  107. data/lib/samagotchi/session_manager/listing.rb +5 -0
  108. data/lib/samagotchi/session_manager/spawn.rb +2 -2
  109. data/lib/samagotchi/session_manager/worker_command.rb +9 -0
  110. data/lib/samagotchi/session_participants.rb +12 -8
  111. data/lib/samagotchi/session_review.rb +5 -7
  112. data/lib/samagotchi/session_stores.rb +3 -3
  113. data/lib/samagotchi/share_command.rb +10 -12
  114. data/lib/samagotchi/share_terms.rb +41 -0
  115. data/lib/samagotchi/steer.rb +8 -14
  116. data/lib/samagotchi/system_prompt.rb +16 -25
  117. data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
  118. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
  119. data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
  120. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
  121. data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
  122. data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
  123. data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
  124. data/lib/samagotchi/terminal_ui.rb +1 -2
  125. data/lib/samagotchi/testing/sessions.rb +2 -10
  126. data/lib/samagotchi/tool_runner.rb +8 -9
  127. data/lib/samagotchi/toolkit.rb +4 -22
  128. data/lib/samagotchi/toolkit_suggest.rb +3 -3
  129. data/lib/samagotchi/tools/deferred_tools.rb +1 -0
  130. data/lib/samagotchi/tools/execute.rb +11 -45
  131. data/lib/samagotchi/tools/leftovers.rb +122 -0
  132. data/lib/samagotchi/tools/memory.rb +70 -26
  133. data/lib/samagotchi/tools/task_get.rb +1 -0
  134. data/lib/samagotchi/tools/task_list.rb +3 -2
  135. data/lib/samagotchi/tools/task_record.rb +6 -4
  136. data/lib/samagotchi/tools/task_runtime.rb +199 -20
  137. data/lib/samagotchi/tools/task_wait.rb +4 -3
  138. data/lib/samagotchi/turn_context.rb +1 -1
  139. data/lib/samagotchi/turn_origin.rb +1 -1
  140. data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
  141. data/lib/samagotchi/turn_stages/objectives.rb +2 -2
  142. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
  143. data/lib/samagotchi/update_hint.rb +3 -1
  144. data/lib/samagotchi/verify_fresh.rb +1 -1
  145. data/lib/samagotchi/verify_fresh_origin.rb +13 -11
  146. data/lib/samagotchi/version.rb +1 -1
  147. data/lib/samagotchi/web/app.rb +3 -5
  148. data/lib/samagotchi/web/participant_access.rb +14 -18
  149. data/lib/samagotchi/web/participant_review.rb +3 -4
  150. data/lib/samagotchi/web/participant_show.rb +4 -3
  151. data/lib/samagotchi/web/participant_view.rb +3 -3
  152. data/lib/samagotchi/web/participants_admin.rb +21 -40
  153. data/lib/samagotchi/web/public/app.js +5 -47
  154. data/lib/samagotchi/web/public/data.js +2 -10
  155. data/lib/samagotchi/web/public/delivery_line.js +17 -60
  156. data/lib/samagotchi/web/public/index.html +10 -30
  157. data/lib/samagotchi/web/public/live_turn.js +1 -1
  158. data/lib/samagotchi/web/public/owner_claim.js +2 -2
  159. data/lib/samagotchi/web/public/participant_bar.js +4 -5
  160. data/lib/samagotchi/web/public/participant_names.js +14 -10
  161. data/lib/samagotchi/web/public/participants_panel.js +29 -62
  162. data/lib/samagotchi/web/public/reload_check.js +2 -3
  163. data/lib/samagotchi/web/public/send_turn.js +4 -23
  164. data/lib/samagotchi/web/public/session_actions.js +4 -45
  165. data/lib/samagotchi/web/public/session_fields.js +0 -1
  166. data/lib/samagotchi/web/public/session_state.js +0 -3
  167. data/lib/samagotchi/web/public/session_view.js +2 -3
  168. data/lib/samagotchi/web/public/settings_panel.js +4 -18
  169. data/lib/samagotchi/web/public/stage_answer.js +56 -0
  170. data/lib/samagotchi/web/public/stage_asking.js +1 -1
  171. data/lib/samagotchi/web/public/stage_cloud.js +93 -0
  172. data/lib/samagotchi/web/public/stage_dom.js +100 -0
  173. data/lib/samagotchi/web/public/stage_handoff.js +154 -0
  174. data/lib/samagotchi/web/public/stage_pager.js +59 -0
  175. data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
  176. data/lib/samagotchi/web/public/stage_view.js +90 -411
  177. data/lib/samagotchi/web/public/start_page.js +12 -33
  178. data/lib/samagotchi/web/public/start_settings.js +24 -78
  179. data/lib/samagotchi/web/public/start_toolkit.js +6 -10
  180. data/lib/samagotchi/web/public/stream_handlers.js +1 -9
  181. data/lib/samagotchi/web/public/turn_block.js +3 -7
  182. data/lib/samagotchi/web/public/turn_events.js +15 -6
  183. data/lib/samagotchi/web/public/turn_pieces.js +3 -4
  184. data/lib/samagotchi/web/public/viewer_self.js +8 -2
  185. data/lib/samagotchi/web/qr.rb +1 -1
  186. data/lib/samagotchi/web/session_control.rb +3 -1
  187. data/lib/samagotchi/web/session_create.rb +5 -71
  188. data/lib/samagotchi/web/session_summary.rb +1 -4
  189. data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
  190. data/lib/samagotchi/web/viewer.rb +3 -3
  191. data/lib/samagotchi/worker.rb +16 -14
  192. data/lib/samagotchi/worker_inbound.rb +4 -3
  193. data/lib/samagotchi/worker_link.rb +17 -0
  194. data/lib/samagotchi/working_set.rb +87 -28
  195. metadata +13 -8
  196. data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
  197. data/lib/samagotchi/participant_mode.rb +0 -86
  198. data/lib/samagotchi/review_apply.rb +0 -131
  199. data/lib/samagotchi/review_command.rb +0 -123
  200. data/lib/samagotchi/review_start.rb +0 -196
  201. data/lib/samagotchi/web/public/review_apply.js +0 -34
  202. data/lib/samagotchi/web/public/review_start.js +0 -55
data/docs/testing.md CHANGED
@@ -8,7 +8,7 @@ npm test # web frontend specs
8
8
  npm run lint # web frontend: undefined names and unused imports (ESLint; CI runs it)
9
9
  npm run e2e # web UI happy paths in Chromium, fake model (once: npx playwright install chromium)
10
10
  npx playwright test spec/e2e/stage.spec.js # one e2e file (the root playwright.config.js is the suite's)
11
- bundle exec rake lint # RuboCop: no offenses (CI runs it)
11
+ bundle exec rake lint # RuboCop and script/load-check --strict: no offenses, no findings (CI runs it)
12
12
  ```
13
13
 
14
14
  Run `bundle exec rubocop -a` on the files you changed before committing: every enabled style cop follows the
@@ -20,7 +20,7 @@ bug) or a broken spec: fix it, or disable that line with the reason (`# rubocop:
20
20
  with two rules only, `no-undef` (a name used but never imported or declared: a dropped import) and `no-unused-vars`
21
21
  (an import or variable left over), over the browser's globals (`eslint.config.js`). It is a missing-name guard, not a
22
22
  style pass: add a rule only for a bug class it would have caught. It runs in about 2 s, in CI's `npm test` job and in
23
- `rake release:check`; `rake lint` stays RuboCop alone (CI's rubocop job has no node). A name that is also a browser
23
+ `rake release:check`; `rake lint` stays Ruby only (RuboCop and the load check: CI's rubocop job has no node). A name that is also a browser
24
24
  global (`name`, `status`, `open`…) passes even when its import is gone: give an export such a name only with care.
25
25
  It also caps every web module's size and `app.js`'s own, lower (`max-lines`; see docs/internals/web-frontend.md).
26
26
  It also checks `spec/e2e/` for two things: `no-unused-vars`, and the Playwright twin of `Samagotchi/SpecSleep`: no `page.waitForTimeout`.
@@ -64,8 +64,8 @@ The whole-turn goldens (`spec/engine_turn_golden_spec.rb`, `spec/fixtures/turn_g
64
64
  `Engine#run_turn` (its own KernelLoop, ChatLoop, ToolRunner, Gate and GuardrailWiring) over `FakeProviderServer` on
65
65
  the native (llama.cpp `/completion`, Qwen tool calls), `api: openai` and `api: anthropic` wires: a turn of two tool
66
66
  iterations (a muted `memory_read` and a `read`, then a `write` a config rule asks about, allowed through the question
67
- flow), a `before_turn` hook switching the model (the request names the new model with the old one's sampling), and a
68
- review participant's turn whose `write` the review boundary refuses. Each golden pins every request (the chi-set
67
+ flow), a `before_turn` hook switching the model (the request names the new model with the old one's sampling), and an
68
+ older chi's read-only participant's turn whose `read` and `write` the participant seat refuses (`ParticipantRefusal`). Each golden pins every request (the chi-set
69
69
  headers, the body in its key order, the native prompt as text), the turn's events (keys sorted; the context-status
70
70
  estimates and clock values masked), each `before_tool_call` payload, the approval asked and the session's messages.
71
71
  System 1, the toolkit suggestion, the context judge, the recap and the warm-up are off by config, so the order is the
@@ -84,11 +84,16 @@ next round folds the first three into one wiring example each in `effective_mode
84
84
  `session_model_settings_spec.rb` and `session_setting_spec.rb`, and the ladders the round after into the setting
85
85
  modules' and `model_lookup_spec.rb`.
86
86
 
87
+ The sender rows (`ClientId::ROWS`) have three pins: `spec/client_id_characterization_spec.rb` (what every id chi
88
+ makes, a sample per prefix, nil, "" and unknown ids get from `human?`, `owner?`, `interactive?`, `wake_kind`, `origin`
89
+ and `Steer.source_for_client`: a row change shows up there), `spec/client_id_spec.rb` (every String constant of
90
+ `ClientId` has a row) and `spec/shared/labels_matrix.json` (a client case per row, both UIs' labels).
91
+
87
92
  The session file goldens (`spec/session_file_goldens_spec.rb`, `spec/fixtures/session_goldens/`) pin the bytes `Session#save`
88
93
  writes: every field away from its default, a new session, a newer chi's file, an old chi's file in a git repo, every key
89
94
  present as `null`, the plain writers' raw values, a running turn's checkpoint and the scrub (the `*_in.json` files are
90
95
  hand-written inputs, never regenerated); and the file each path that makes or rewrites a session writes (a fork, a
91
- continue, a delegate child, a plain spawn, a review, a Verify fresh child, a respawn; a resume and an archive leave the bytes as they were), with
96
+ continue, a delegate child, a plain spawn, a Verify fresh child, a respawn; a resume and an archive leave the bytes as they were), with
92
97
  `carry_matrix.json`, what each keeps of its source. They are pinned before Session's fields became one table and are kept
93
98
  as the file format's pins, not retired: a diff is a change to every session file on disk, so only a commit that means to
94
99
  change the format regenerates them (`UPDATE_GOLDENS=1 bundle exec rspec spec/session_file_goldens_spec.rb`).
@@ -190,7 +195,9 @@ registered in `Compat::SHIMS` (`lib/samagotchi/compat.rb`): an id, the release
190
195
  that added it, `remove_after` (nil: the owner hasn't dated it) and its files,
191
196
  each Ruby one naming it in a comment (`compat shim <id>`). `spec/compat_spec.rb`
192
197
  fails once `Samagotchi::VERSION` passes a shim's `remove_after`, naming it:
193
- remove the shim, or move its date with the owner's OK. A new shim gets a row.
198
+ remove the shim, or move its date with the owner's OK. A new shim gets a row
199
+ (`review_client_id`: a participant's `review:<id>` from 0.171 and before, until 0.173; its old-shape samples are
200
+ hand-made in `spec/fixtures/compat_review_client_id/`, as no corpus recorded one).
194
201
 
195
202
  ## Levels
196
203
 
@@ -242,7 +249,7 @@ Each level owns its own share; a detail is asserted once, at the lowest level th
242
249
  its items into turns and gives each a minimal drawing (not the synthesizer: what a real drawing holds is the
243
250
  fixtures'). The
244
251
  `lan` project's chi web is on the LAN only
245
- when the machine has a private IPv4: without one its LAN tests skip and the participant review journey runs on
252
+ when the machine has a private IPv4: without one its LAN tests skip and the participant journey runs on
246
253
  loopback.
247
254
 
248
255
  ## Waiting and time
@@ -588,3 +595,45 @@ The code is `script/deps/deps_check.rb`; its spec stubs every request and comman
588
595
  names (Prism; `be_foo`/`have_foo` count for `foo?`/`has_foo?`), as `path:line name [notes]` with a count; a note says
589
596
  what may explain a row (a doc, a name built at run time, a framework hook). Advisory: it always exits 0, CI doesn't
590
597
  run it. Its spec is `spec/script/dead_code_spec.rb`.
598
+
599
+ ## The load check
600
+
601
+ `script/load-check` reads every file under `lib/samagotchi/` (the shipped bundles under
602
+ `lib/samagotchi/bundles/` apart) and `bin/chi` with Prism and **never loads them**, then checks three rules:
603
+
604
+ 1. **call-time reference** — a constant a method body names is defined in the file or reached by its
605
+ `require`/`require_relative`/`autoload` lines, transitively (a `require` inside a method counts here only);
606
+ 2. **load-time reference** — a constant evaluated while the file loads (a superclass, `include`/`extend`/
607
+ `prepend`, a class body) comes from a file required above that line, and a require cycle does not
608
+ guarantee it;
609
+ 3. **autoload** — an `autoload` may name a constant defined in one file; one that names a namespace
610
+ reopened in several files is a finding. A dynamically named autoload is reported unread, since its name
611
+ cannot be checked.
612
+
613
+ A name that resolves to nothing of chi's (a stdlib or gem constant) is out of scope, and lexical scope is
614
+ mimicked: a bare `Log` inside `module Samagotchi` is `Samagotchi::Log`. Each line is
615
+ `RULE file:line Constant — why`; the summary counts findings per rule, per `lib/samagotchi/<dir or file>`,
616
+ and the files scanned. Report mode exits 0; `--strict` exits 1 when findings remain, and `rake lint` (so
617
+ CI) runs `--strict`: the tree reports none. Its spec is `spec/script/load_check_spec.rb`.
618
+
619
+ **Reading a finding.** `1 lib/samagotchi/engine/models.rb:63 Samagotchi::Log — no require or autoload here
620
+ reaches lib/samagotchi/log.rb, which defines it` says that a method in `models.rb` names `Log` and that the
621
+ file works today only because someone else required `log.rb` first. The fix is the require the line names,
622
+ at the top of the file (`require_relative "../log"`): a require only adds what the file already gets through
623
+ its loaders, so the processes' loaded files don't change (`spec/require_cycle_spec.rb`'s budgets say if they
624
+ do). Prefer an existing door when there is one: `LLM::ChatLoop` is `llm/backend.rb`'s autoload, so a file
625
+ naming it requires `llm/backend`. When the file is needed only on one path a thin process never takes,
626
+ require it inside that method (a method-body require satisfies rule 1). When the require would close a cycle
627
+ (the defining file requires this one: a part naming its host's constants), the finding goes in the
628
+ allow-list. A rule 2 finding is a load-order bug and is fixed, not allow-listed. A rule 3 finding is fixed
629
+ by pointing the autoload at the namespace's base file, or allow-listed when that file requires every file
630
+ that reopens the namespace and nothing else does (then firing the autoload loads it whole).
631
+
632
+ **The allow-list.** `script/load_check/allow.yml` (`--allow FILE` reads another): each entry matches on
633
+ `rule`, `file` and `constant`, with `*` and `[A-Z]` globs, and says why in `reason`. Its entries are of
634
+ four kinds: a part naming its host's value constants (`Samagotchi::Engine::[A-Z][A-Z_]*` in
635
+ `engine/*.rb`: the host requires the part, so a require back is a cycle; the glob leaves classes a part
636
+ names from elsewhere checked), one-off host pairs (`ToolRun` in `tool_response.rb`), the namespace
637
+ autoloads that load whole (`SessionManager`, `Objectives`, `Config`), and `Plugin::Http`'s (its base file
638
+ loads the reopening file only inside a method, and that file requires the base file first). The summary counts the entries that
639
+ matched and those that match nothing: delete a stale one.
@@ -7,6 +7,7 @@ require_relative "../events"
7
7
  require_relative "../state_format"
8
8
  require_relative "card_places"
9
9
  require_relative "turn_notice"
10
+ require_relative "../log"
10
11
 
11
12
  module Samagotchi
12
13
  class Bridge
@@ -5,6 +5,7 @@ require "json"
5
5
  require_relative "client_event"
6
6
  require_relative "event_id"
7
7
  require_relative "../llm/utf8_scrub"
8
+ require_relative "bounded_queue"
8
9
 
9
10
  module Samagotchi
10
11
  class Bridge
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../events"
4
- require_relative "../kernel_loop"
5
4
  require_relative "../log"
6
5
  require_relative "../steer"
7
6
  require_relative "../tool_output_cut"
@@ -118,6 +118,11 @@ module Samagotchi
118
118
  MAX_BODY_BYTES = 1_000_000
119
119
  # A request's deadline (see #handle_post_turn) that isn't epoch seconds.
120
120
  BAD_DEADLINE = [{ "Allow" => "POST" }, 400, { error: "bad_deadline", detail: "deadline must be epoch seconds" }].freeze
121
+ # A POST /command that names no sender: every sender names itself
122
+ # (ClientId::NONE is never the owner's), so it runs nothing.
123
+ UNNAMED_COMMAND = "a session command must name its sender: send client_id (a web tab's web:<id>, a chi TUI's " \
124
+ "tui:<pid>, chi send's cli:send)"
125
+ UNNAMED_COMMAND_REPLY = [{ "Allow" => "POST" }, 400, { error: "missing_client_id", detail: UNNAMED_COMMAND }].freeze
121
126
  # The request header that names the Bridge's secret, lowercased as #read_request keeps it.
122
127
  SECRET_HEADER = BridgeSecret::HEADER.downcase
123
128
  # Bytes of randomness in a Bridge's secret (hex in bridge.json: twice as many characters).
@@ -773,12 +778,12 @@ module Samagotchi
773
778
  # Stop's last_turn carry the turn's enqueued_id (ReplyWait.own_turn).
774
779
  # unqueue: POST turn/dequeue (#handle_dequeue_turn) takes a queued
775
780
  # message back before it runs.
776
- # review_turns: a participant's turn runs as its own, inside the review
777
- # boundary (Guardrails::ReviewBoundary); a worker without it has none,
778
- # so chi web sends it no participant's turn (Delivery::REVIEW_FEATURE).
779
- # pair_turns: a participant's turn in a working session runs as a pair
780
- # turn (Guardrails::PairBoundary); a worker without it runs it as a
781
- # review turn, and chi web says so (Delivery::PAIR_FEATURE).
781
+ # review_turns: a participant's turn runs as its own, inside a
782
+ # boundary; kept for an older chi web, which sends no participant's turn
783
+ # to a worker without it (Delivery::REVIEW_FEATURE).
784
+ # pair_turns: a participant's turn runs under the owner's guardrails
785
+ # (Guardrails::PairBoundary); chi web sends no participant's turn to a
786
+ # worker without it, nor invites anyone to its session (Delivery::PAIR_FEATURE).
782
787
  # participant_steer: a participant's message sent while their own turn
783
788
  # runs goes in at its next step (a worker without it queues it); only
784
789
  # what the page's delivery line and chi web's ack say depends on it
@@ -791,11 +796,14 @@ module Samagotchi
791
796
  # to pass one on (ReviseAnchor::PARTICIPANT_FEATURE).
792
797
  # activity: GET /activity answers with Worker#activity_snapshot, so
793
798
  # `chi schedule tick` can ask a live worker what it is busy with.
799
+ # participant_client_id: it reads a participant's client id as
800
+ # participant:<id>; chi web sends a worker without it review:<id>
801
+ # (Delivery::PARTICIPANT_ID_FEATURE).
794
802
  FEATURES = ["restart", "task_stop", "reparent", Delivery::QUEUE_FEATURE, ReplyWait::TURN_IDS_FEATURE,
795
803
  VerifyAnchor::FEATURE, ReviseAnchor::FEATURE,
796
804
  SessionInbox::UNQUEUE_FEATURE, Delivery::REVIEW_FEATURE, Delivery::PAIR_FEATURE, TurnDrawings::FEATURE,
797
805
  WorkerLink::ACTIVITY_FEATURE, ObjectivesTrack::FEATURE, Delivery::OWN_TURN_STEER_FEATURE,
798
- Delivery::CANCEL_TURN_ID_FEATURE, ReviseAnchor::PARTICIPANT_FEATURE].freeze
806
+ Delivery::CANCEL_TURN_ID_FEATURE, ReviseAnchor::PARTICIPANT_FEATURE, Delivery::PARTICIPANT_ID_FEATURE].freeze
799
807
 
800
808
  # The routes, by method and what follows /session/:id/: a handler takes
801
809
  # the session id and the request body and returns [headers, status, body].
@@ -1073,11 +1081,20 @@ module Samagotchi
1073
1081
  return [{ "Allow" => "POST" }, 400, { error: "unknown_command", detail: detail }]
1074
1082
  end
1075
1083
 
1084
+ client_id = fetched(parsed, "client_id")
1085
+ return UNNAMED_COMMAND_REPLY if client_id.to_s.strip.empty?
1086
+
1087
+ # Only the owner's senders and chi answer's (CommandIntake.allowed?),
1088
+ # as for a command sent as a message.
1089
+ unless CommandIntake.allowed?(client_id)
1090
+ Log.warn(:bridge, "command_refused", client_id: client_id)
1091
+ return [{}, 403, { error: CommandIntake::REFUSED_ERROR, detail: CommandIntake.refusal(line) }]
1092
+ end
1093
+
1076
1094
  deadline = fetched(parsed, "deadline")
1077
1095
  return BAD_DEADLINE unless deadline_valid?(deadline)
1078
1096
 
1079
- queue_command_request(session_id, line, client_id: fetched(parsed, "client_id"), deadline: deadline,
1080
- card: fetched(parsed, "card") == true)
1097
+ queue_command_request(session_id, line, client_id: client_id, deadline: deadline, card: fetched(parsed, "card") == true)
1081
1098
  end
1082
1099
 
1083
1100
  # Queues +line+ (a session command) for the worker and announces its
@@ -3,6 +3,8 @@
3
3
  require "json"
4
4
  require "uri"
5
5
  require_relative "../bridge_secret"
6
+ require_relative "sse_parser"
7
+ require_relative "stream_open"
6
8
 
7
9
  module Samagotchi
8
10
  class BridgeClient
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rbconfig"
4
4
  require_relative "../cli/flags"
5
+ require_relative "../cli/exit"
5
6
 
6
7
  module Samagotchi
7
8
  class BundleCommand
@@ -4,6 +4,7 @@ require "open3"
4
4
  require "rbconfig"
5
5
  require_relative "../../cli/exit"
6
6
  require_relative "../../process_group"
7
+ require_relative "sandbox"
7
8
 
8
9
  module Samagotchi
9
10
  class BundleCommand
@@ -1,21 +1,20 @@
1
1
  ---
2
2
  name: coordinator
3
- version: 0.8.1
3
+ version: 0.9.0
4
4
  scope: system
5
- description: "Coordinate parallel work: the coordinator skill (split the work, one worktree and child session per task, check each report, merges under a guardrail approval (the git-merge rule) or a question, a handoff memory to resume from), /coordinate <goal>, /coordinate resume, /coordinate end, /coordinate review (experimental: a sprint review session to share) and /children; the coordinator toolkit (lean + delegate, delegate_result, list_sessions, objectives) and the coding toolkit for build children (child + be concise)"
5
+ description: "Coordinate parallel work: the coordinator skill (split the work, one worktree and child session per task, check each report, merges under a guardrail approval (the git-merge rule) or a question, a handoff memory to resume from), /coordinate <goal>, /coordinate resume, /coordinate end and /children; the coordinator toolkit (lean + delegate, delegate_result, list_sessions, objectives) and the coding toolkit for build children (child + be concise)"
6
6
  trust_level: reviewed
7
7
  files:
8
8
  skill_coordinator.md:
9
- sha256: sha256:1cac885facd28757aaa0197b28889246f845834c17101d59b5625d1b2b89679a
9
+ sha256: sha256:21a56711f4ac1252ff6012a6ed0a743cb90732939abed406a9b8753a755c8d0c
10
10
  description: "Coordinate parallel work: split it, delegate each task wait:false in its own worktree (cwd:), check each report, merge under the git-merge approval or ask the user; resume from a handoff_* memory"
11
11
  plugin:
12
12
  file: plugin.rb
13
- sha256: sha256:540dd6369342ea4dcbc6ba5ee17fb20d980b880df614a475668c70115e7ec6b8
13
+ sha256: sha256:406b9827485535a8be17d4f1b291997ebf5c3f7d5616d20812c53b4ea153f601
14
14
  # the coordinator toolkit needs chi.toolkit and ctx.use_toolkit (0.66.0); the
15
15
  # coding toolkit (chi.toolkit prompt:) and the skill's delegate toolkit: need
16
16
  # the next chi.
17
17
  requires_chi: ">= 0.107.0"
18
- # /coordinate review uses ctx.sessions.review (the next chi).
19
18
  # No requires_chi_next for guardrails/merge.yml: its keys are long supported, and first-ever too-new rules would make a
20
19
  # live older worker deny every call. A chi without `chi guardrails rule` gives a usage error, and the skill then asks.
21
20
  # Nor for the objectives tool in the kit and the skill: on an older chi the kit's add names nothing (it declares only what
@@ -27,14 +27,6 @@
27
27
  # (/coordinate resume <name>); none: says so. It reads the project's
28
28
  # memories folder, nothing else.
29
29
  #
30
- # /coordinate review [handoff] (experimental) opens a sprint review: a review
31
- # session of this one (ctx.sessions.review: its recap, never its transcript;
32
- # this session keeps running), seeded with the open handoff's body (the one
33
- # named, the only one open, or a card with a Review action each when several
34
- # are), for participants (chi share): its model answers their new context
35
- # with a hand-off diff and the owner applies it (the skill's Sprint review).
36
- # With none open it starts from the recap alone and says so.
37
- #
38
30
  # /coordinate end ends the day: the model is asked to follow the skill's End
39
31
  # of day (bring its handoff up to date, keep it OPEN unless all is done, give
40
32
  # a short report). It reads nothing itself; "end" with more words is a goal.
@@ -64,21 +56,9 @@ class Plugin
64
56
  TEXT_CHARS = 80
65
57
  USAGE = "usage: /children [all] | /children stop <id>"
66
58
  COORDINATE_USAGE = "usage: /coordinate <goal> — chi splits it into tasks, one child session and worktree each; " \
67
- "/coordinate resume [name] — pick up an open handoff; /coordinate end — save the handoff, end-of-day report; " \
68
- "/coordinate review [name] — a sprint review session to share (experimental)"
59
+ "/coordinate resume [name] — pick up an open handoff; /coordinate end — save the handoff, end-of-day report"
69
60
  RESUME_CARD_ID = "coordinate-resume"
70
- REVIEW_CARD_ID = "coordinate-review"
71
- # The seed's note: what to do (the skill's Sprint review section, copied:
72
- # a participant's turn may read project memories only, and the skill is
73
- # where its bundle was installed, usually system) and the handoff's body.
74
- REVIEW_SEED = "This is a sprint review of the coordinator session %<source>s (experimental). The " \
75
- "skill_coordinator memory's Sprint review section, which you follow here:"
76
- SKILL = "skill_coordinator"
77
- SPRINT_REVIEW_HEADING = /^## Sprint review\b.*$/
78
- # The section's gist when the skill's file can't be read.
79
- SPRINT_REVIEW_FALLBACK = "A participant's turn may only read. Answer new context with a hand-off diff (the " \
80
- "handoff's lines as they would change, in a diff block) and what it means per branch. When " \
81
- "the owner applies it, update the handoff and re-plan in words; start, stop or merge nothing here."
61
+ REVIEW_GONE = "/coordinate review is gone (coordinator 0.9.0): chi has no review sessions; invite someone with chi share"
82
62
  # A card takes 6 actions.
83
63
  MAX_RESUMES = 6
84
64
  HANDOFF_LINE = /^- \*\*(handoff_[^*\s]+)\*\*(.*)$/
@@ -98,8 +78,7 @@ class Plugin
98
78
  children_command(args.to_s.strip, ctx)
99
79
  end
100
80
  chi.command "/coordinate", "run work in parallel: chi splits <goal> into tasks, each in a child session and worktree; " \
101
- "resume: pick up an open handoff; end: save the handoff, end-of-day report; " \
102
- "review: a sprint review session to share (experimental)",
81
+ "resume: pick up an open handoff; end: save the handoff, end-of-day report",
103
82
  anytime: true do |args, ctx|
104
83
  coordinate(args.to_s.strip, ctx)
105
84
  end
@@ -163,8 +142,9 @@ class Plugin
163
142
  verb, rest = goal.split(/\s+/, 2)
164
143
  # "resume" and at most a name; "resume the old work" is a goal.
165
144
  return resume(rest.to_s.strip, ctx) if verb == "resume" && !rest.to_s.strip.match?(/\s/)
166
- # "review" and at most a name; "review the specs" is a goal.
167
- return review(rest.to_s.strip, ctx) if verb == "review" && !rest.to_s.strip.match?(/\s/)
145
+ # "review" and at most a name (an old card's action, a habit): gone, said
146
+ # once rather than run as a goal; "review the specs" is a goal.
147
+ return REVIEW_GONE if verb == "review" && !rest.to_s.strip.match?(/\s/)
168
148
  # A bare "end" only; "end the flaky specs" is a goal.
169
149
  return end_of_day(ctx) if verb == "end" && rest.to_s.strip.empty?
170
150
 
@@ -198,59 +178,6 @@ class Plugin
198
178
  "asked chi to end the day; a running turn gets it at its next step")
199
179
  end
200
180
 
201
- # /coordinate review [name]
202
- def review(name, ctx)
203
- open = open_handoffs(ctx)
204
- if name.empty?
205
- return handoff_card(open, ctx, verb: "review", id: REVIEW_CARD_ID) if open.size > 1
206
-
207
- name = open.first&.dig(:name)
208
- else
209
- name = "handoff_#{name}" unless name.start_with?("handoff_")
210
- unless open.any? { |handoff| handoff[:name] == name }
211
- return "/coordinate review: no open handoff #{name} in this project (#{open.empty? ? "none is open" : "open: #{open.map { |h| h[:name] }.join(", ")}"})"
212
- end
213
- end
214
- start_review(name, ctx)
215
- end
216
-
217
- def start_review(name, ctx)
218
- seed = "#{format(REVIEW_SEED, source: ctx.session_id.to_s[0, 8])}\n\n#{sprint_review_section(ctx)}"
219
- seed += "\n\nThe coordinator's handoff #{name} as of now (memory_read it, scope: project, for the latest):\n\n#{handoff_body(name, ctx)}" if name
220
- id = ctx.sessions.review(seed: seed)
221
- short = id.to_s[0, 8]
222
- ["sprint review #{short} started from this session (experimental), #{name ? "seeded with #{name}" : "from its recap alone: no open handoff"}; " \
223
- "this session keeps running.",
224
- "invite someone: chi share #{short} --name NAME (or the participants chip on its page); their new context comes " \
225
- "back as a hand-off diff; Apply under it (on its page) puts the change in your composer there."].join("\n")
226
- rescue Samagotchi::Plugin::Sessions::Error => e
227
- "/coordinate review: #{e.message}"
228
- end
229
-
230
- # The skill's Sprint review section as installed (system scope, else the
231
- # project's), heading to the next heading; the fallback without one.
232
- def sprint_review_section(ctx)
233
- %w[system project].each do |scope|
234
- file = File.join(Samagotchi::MemoryPaths.scope_dir(scope, cwd: ctx.cwd).to_s, "#{SKILL}.md")
235
- next unless File.file?(file)
236
-
237
- text = File.read(file, encoding: "UTF-8")
238
- start = text.index(SPRINT_REVIEW_HEADING) or next
239
- rest = text[start..]
240
- stop = rest.index(/^## /, 1)
241
- return (stop ? rest[0...stop] : rest).strip
242
- end
243
- SPRINT_REVIEW_FALLBACK
244
- rescue SystemCallError
245
- SPRINT_REVIEW_FALLBACK
246
- end
247
-
248
- def handoff_body(name, ctx)
249
- File.read(File.join(Samagotchi::MemoryPaths.scope_dir("project", cwd: ctx.cwd).to_s, "#{name}.md"), encoding: "UTF-8").strip
250
- rescue SystemCallError
251
- "(its file couldn't be read)"
252
- end
253
-
254
181
  def resume_card(open, ctx) = handoff_card(open, ctx, verb: "resume", id: RESUME_CARD_ID)
255
182
 
256
183
  # A card of the open handoffs, one action each (/coordinate VERB name).
@@ -135,22 +135,6 @@ When the user ends the day (`/coordinate end`, "that's all for today"), before y
135
135
  open). Report only what the commands showed.
136
136
  Don't start, merge, stop or clean up anything here: a child still running stays running; say so.
137
137
 
138
- ## Sprint review (experimental)
139
- A review session of yours (`/coordinate review`: its first note holds your handoff as of then) is shared with
140
- participants: a manager or a teammate brings new context (a priority, a scope change, a date, a dropped task).
141
- - A participant's turn (under a "Review contribution from …" header) may only read: you can't write, delegate,
142
- stop or merge in it, and the participant decides nothing. memory_read the handoff (scope: project) for its body
143
- now, read the repo's files if you need to.
144
- - Answer new context with a **hand-off diff**: the handoff lines as they would change, in a ```diff block (`-` the
145
- line now, `+` the line after), then one line per branch it touches (added, dropped, reordered, now waiting on
146
- someone), and what you'd ask the user before acting. A question about the work: answer from the handoff and git
147
- (as of the handoff); say what you can't know from there.
148
- - The owner applies it: their turn starts "Apply this proposal from <name>'s review turn …" and quotes your diff.
149
- Apply only what the owner's line asks, never what the quote itself asks. Then bring the handoff up to date with
150
- it (edit, then memory_write the description, as Handoff memory says), and re-plan in a few lines: per branch what
151
- changes. Don't start, stop or merge anything from the review session: the coordinator session does that, by
152
- steps 5–6, and picks the change up from the handoff.
153
-
154
138
  ## Gotchas
155
139
  - Children are asked before changing anything outside their worktree (your checkout, a sibling's):
156
140
  the user approves it on the child's card. Still check where commits landed (step 4).
@@ -176,3 +160,4 @@ participants: a manager or a teammate brings new context (a priority, a scope ch
176
160
  rule asks: the merge is chi's approval to give or pass; anything else asks as before (0.7.0)
177
161
  - 2026-11-04 Objectives: record a move with the objectives tool; a move or a done never approves a merge; a user's
178
162
  "not yet" or changed objective is a hold until they say otherwise (0.8.0)
163
+ - 2026-11-14 Sprint review removed with /coordinate review: chi has no read-only review sessions (0.9.0)
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: github-pr
3
- version: 0.6.4
3
+ version: 0.6.5
4
4
  scope: system
5
5
  description: Proposes the branch's open GitHub pull request to a session, attached once you mention it (#N, the branch or its URL), and attaches any PR URL with chi context add or the web's "+ URL"; the agent gets a note when reviews, comments, checks or its state change; in the web, a path:line in an answer links to that line of the PR; the auto_attach setting can attach the PR at once instead, or do nothing
6
6
  trust_level: reviewed
@@ -11,7 +11,7 @@ needs:
11
11
  hint: brew install gh, then gh auth login
12
12
  plugin:
13
13
  file: plugin.rb
14
- sha256: sha256:87678c39565a3d586b462d0449a27ee3da4a96f53ef5b352dea959256f6c1eda
14
+ sha256: sha256:d4da48d8d3ed9efe393d468bb659c3ec6b43225a20efa06fa9ee6482eaaf0791
15
15
  scripts:
16
16
  pr_context.rb: sha256:a883d2780e89c68c0d7b6d5e0fcb22c273f17bb167e79064e0e99db6bd2ee6f0
17
17
  context_providers:
@@ -96,7 +96,6 @@ class Plugin
96
96
  mode = auto_attach_mode(ctx)
97
97
  return "auto_attach: off" if mode == :off
98
98
  return "skipped: a delegate child" if mode == :attach && ctx.delegate?
99
- return "skipped: a review session" if mode == :propose && ctx.review?
100
99
 
101
100
  branch = run(ctx, "git", "branch", "--show-current").to_s.strip
102
101
  return "not on a branch" if branch.empty?
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: inline-widgets
3
- version: 0.1.1
3
+ version: 0.1.2
4
4
  scope: system
5
5
  description: "Teaches the model the chi-ui blocks chi web draws: picks (rows of options that fill your reply) and walk (a scenario stepped through)"
6
6
  trust_level: reviewed
7
7
  plugin:
8
8
  file: plugin.rb
9
- sha256: sha256:e54a0096ba3b20ccf6bbca2798cb53afd86986a2cb7bee1c02e5520f2ddb5033
9
+ sha256: sha256:b68599ba9e61004b8090ec0d317f6b4a5ba0042ca54a9b35fbe1a39539e1f03f
10
10
  # chi.prompt_section is 0.132.0's; the web draws chi-ui blocks only from the next release
11
11
  requires_chi: ">= 0.155.0"
@@ -10,10 +10,9 @@
10
10
  # The text is eval 0013's round-2 hint, split in two. It is static, so the
11
11
  # prompt cache keeps: same text at every build. A delegate child's answer is
12
12
  # read by its parent, not drawn for a user, a one-shot (-p --non-interactive)
13
- # prints to a terminal, and a review session (chi review) is read by its
14
- # participants, whose page draws no widgets: none of them gets a section. A
15
- # working session the owner pairs in keeps them: the owner's page draws them,
16
- # and a participant invited later mustn't change the prompt (the cache).
13
+ # prints to a terminal: neither gets a section. A session with participants
14
+ # keeps them: its pages draw them, and a participant invited later mustn't
15
+ # change the prompt (the cache).
17
16
  class Plugin
18
17
  PICKS = <<~TEXT
19
18
  The web UI draws fenced ```chi-ui code blocks (YAML inside) as interactive widgets; the terminal shows their source. Use one whenever it helps the user more than prose: a widget replaces the long explanation, it doesn't sit beside one. Never use one for what markdown shows well (tables, lists, key-value). At most one widget per answer; keep the prose around it to a few sentences and don't repeat the widget's content.
@@ -76,5 +75,5 @@ class Plugin
76
75
 
77
76
  # Whether the session's answers reach a web page that draws them. Decided by
78
77
  # the session's kind, so the same at every build.
79
- def drawn?(ctx) = ctx.frontend != :one_shot && !ctx.delegate? && !ctx.review?
78
+ def drawn?(ctx) = ctx.frontend != :one_shot && !ctx.delegate?
80
79
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: samagotchi-system
3
- version: 0.171.0
3
+ version: 0.172.0
4
4
  scope: system
5
5
  description: Default system memories — identity, self map, config modification protocol, memory guide and the delegated-session rules
6
6
  files: