samagotchi 0.170.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 (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -1
  3. data/bin/chi +6 -4
  4. data/docs/architecture.md +26 -9
  5. data/docs/bundles.md +4 -21
  6. data/docs/cli.md +81 -97
  7. data/docs/configuration.md +12 -14
  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/block-renderers.md +2 -2
  14. data/docs/internals/bridge.md +34 -7
  15. data/docs/internals/context-telemetry.md +13 -1
  16. data/docs/internals/engine.md +25 -13
  17. data/docs/internals/inline-widgets.md +1 -1
  18. data/docs/internals/objectives.md +4 -6
  19. data/docs/internals/participants.md +340 -249
  20. data/docs/internals/prompt-caching.md +4 -5
  21. data/docs/internals/web-frontend.md +185 -35
  22. data/docs/internals/working-set.md +71 -5
  23. data/docs/memory.md +1 -1
  24. data/docs/plugins.md +2 -16
  25. data/docs/releasing.md +2 -1
  26. data/docs/scheduling.md +1 -1
  27. data/docs/sessions.md +17 -48
  28. data/docs/sub-agent.md +2 -2
  29. data/docs/system-one.md +2 -2
  30. data/docs/testing.md +56 -7
  31. data/lib/samagotchi/bridge/card_store.rb +1 -0
  32. data/lib/samagotchi/bridge/sse_writer.rb +1 -0
  33. data/lib/samagotchi/bridge/turn_accumulator.rb +8 -5
  34. data/lib/samagotchi/bridge.rb +64 -20
  35. data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
  36. data/lib/samagotchi/bundle_command/test_run.rb +1 -0
  37. data/lib/samagotchi/bundle_command/try/run.rb +1 -0
  38. data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
  39. data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
  40. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
  41. data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
  42. data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
  43. data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
  44. data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
  45. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  46. data/lib/samagotchi/client_id.rb +126 -67
  47. data/lib/samagotchi/command_intake.rb +15 -3
  48. data/lib/samagotchi/compat.rb +6 -1
  49. data/lib/samagotchi/context_candidate_choice.rb +1 -3
  50. data/lib/samagotchi/context_candidates.rb +3 -4
  51. data/lib/samagotchi/continue_offer.rb +9 -2
  52. data/lib/samagotchi/delivery.rb +36 -12
  53. data/lib/samagotchi/empty_answer_error.rb +5 -0
  54. data/lib/samagotchi/engine/cards.rb +3 -0
  55. data/lib/samagotchi/engine/context_judge.rb +5 -3
  56. data/lib/samagotchi/engine/events.rb +4 -0
  57. data/lib/samagotchi/engine/hooks.rb +3 -0
  58. data/lib/samagotchi/engine/messages.rb +5 -0
  59. data/lib/samagotchi/engine/model_settings.rb +2 -0
  60. data/lib/samagotchi/engine/models.rb +10 -0
  61. data/lib/samagotchi/engine/objectives.rb +6 -0
  62. data/lib/samagotchi/engine/participants.rb +18 -14
  63. data/lib/samagotchi/engine/plugins.rb +8 -0
  64. data/lib/samagotchi/engine/questions.rb +3 -0
  65. data/lib/samagotchi/engine/recap.rb +1 -0
  66. data/lib/samagotchi/engine/session.rb +4 -0
  67. data/lib/samagotchi/engine/side_requests.rb +9 -0
  68. data/lib/samagotchi/engine/steering.rb +2 -0
  69. data/lib/samagotchi/engine/toolkit.rb +5 -0
  70. data/lib/samagotchi/engine/turn_end.rb +7 -0
  71. data/lib/samagotchi/engine/turn_helpers.rb +8 -0
  72. data/lib/samagotchi/engine/verify.rb +2 -0
  73. data/lib/samagotchi/engine.rb +8 -3
  74. data/lib/samagotchi/event_fanout.rb +22 -1
  75. data/lib/samagotchi/grants.rb +33 -22
  76. data/lib/samagotchi/guardrail_wiring.rb +23 -18
  77. data/lib/samagotchi/guardrails/approval_use.rb +59 -0
  78. data/lib/samagotchi/guardrails/approvals.rb +9 -11
  79. data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
  80. data/lib/samagotchi/guardrails/gate.rb +10 -5
  81. data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
  82. data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
  83. data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
  84. data/lib/samagotchi/guardrails/review_paths.rb +2 -3
  85. data/lib/samagotchi/guardrails.rb +1 -1
  86. data/lib/samagotchi/image_store.rb +51 -12
  87. data/lib/samagotchi/kernel_loop.rb +7 -1
  88. data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
  89. data/lib/samagotchi/llm_context_stale.rb +4 -1
  90. data/lib/samagotchi/llm_context_strategy.rb +2 -0
  91. data/lib/samagotchi/objectives.rb +1 -4
  92. data/lib/samagotchi/objectives_audit.rb +1 -1
  93. data/lib/samagotchi/objectives_track.rb +1 -1
  94. data/lib/samagotchi/owner_prompt.rb +3 -6
  95. data/lib/samagotchi/parent_report.rb +1 -0
  96. data/lib/samagotchi/participant_messages.rb +48 -4
  97. data/lib/samagotchi/participant_revise.rb +61 -0
  98. data/lib/samagotchi/participant_turn_mode.rb +50 -0
  99. data/lib/samagotchi/participant_uploads.rb +98 -0
  100. data/lib/samagotchi/participants.rb +21 -12
  101. data/lib/samagotchi/participants_watch.rb +2 -2
  102. data/lib/samagotchi/plugin/api.rb +2 -2
  103. data/lib/samagotchi/plugin/attached_context.rb +1 -1
  104. data/lib/samagotchi/plugin/context.rb +0 -4
  105. data/lib/samagotchi/plugin/sessions.rb +1 -25
  106. data/lib/samagotchi/reply_wait/poll.rb +5 -1
  107. data/lib/samagotchi/revise_anchor.rb +9 -0
  108. data/lib/samagotchi/run_options.rb +2 -3
  109. data/lib/samagotchi/send_command.rb +15 -10
  110. data/lib/samagotchi/session.rb +0 -3
  111. data/lib/samagotchi/session_access/contract.rb +1 -10
  112. data/lib/samagotchi/session_access/local.rb +10 -23
  113. data/lib/samagotchi/session_access/remote.rb +9 -20
  114. data/lib/samagotchi/session_access.rb +12 -16
  115. data/lib/samagotchi/session_chain.rb +4 -6
  116. data/lib/samagotchi/session_commands.rb +6 -3
  117. data/lib/samagotchi/session_continue.rb +1 -2
  118. data/lib/samagotchi/session_inbox.rb +20 -12
  119. data/lib/samagotchi/session_manager/delivery.rb +32 -5
  120. data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
  121. data/lib/samagotchi/session_manager/listing.rb +5 -0
  122. data/lib/samagotchi/session_manager/spawn.rb +2 -2
  123. data/lib/samagotchi/session_manager/worker_command.rb +9 -0
  124. data/lib/samagotchi/session_participants.rb +12 -8
  125. data/lib/samagotchi/session_review.rb +5 -7
  126. data/lib/samagotchi/session_stores.rb +3 -1
  127. data/lib/samagotchi/share_command.rb +10 -12
  128. data/lib/samagotchi/share_terms.rb +41 -0
  129. data/lib/samagotchi/steer.rb +8 -14
  130. data/lib/samagotchi/system_prompt.rb +16 -25
  131. data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
  132. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
  133. data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
  134. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
  135. data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
  136. data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
  137. data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
  138. data/lib/samagotchi/terminal_ui.rb +1 -2
  139. data/lib/samagotchi/testing/sessions.rb +2 -10
  140. data/lib/samagotchi/tool_runner.rb +42 -9
  141. data/lib/samagotchi/toolkit.rb +4 -22
  142. data/lib/samagotchi/toolkit_suggest.rb +3 -3
  143. data/lib/samagotchi/tools/deferred_tools.rb +1 -0
  144. data/lib/samagotchi/tools/execute.rb +11 -45
  145. data/lib/samagotchi/tools/leftovers.rb +122 -0
  146. data/lib/samagotchi/tools/memory.rb +88 -25
  147. data/lib/samagotchi/tools/task_get.rb +1 -0
  148. data/lib/samagotchi/tools/task_list.rb +3 -2
  149. data/lib/samagotchi/tools/task_record.rb +6 -4
  150. data/lib/samagotchi/tools/task_runtime.rb +199 -20
  151. data/lib/samagotchi/tools/task_wait.rb +4 -3
  152. data/lib/samagotchi/turn_anchors.rb +0 -3
  153. data/lib/samagotchi/turn_context.rb +1 -1
  154. data/lib/samagotchi/turn_origin.rb +1 -1
  155. data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
  156. data/lib/samagotchi/turn_stages/objectives.rb +2 -2
  157. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
  158. data/lib/samagotchi/turn_stages/verify_anchors.rb +13 -1
  159. data/lib/samagotchi/update_hint.rb +3 -1
  160. data/lib/samagotchi/verify_anchor.rb +6 -0
  161. data/lib/samagotchi/verify_fresh.rb +1 -1
  162. data/lib/samagotchi/verify_fresh_origin.rb +13 -11
  163. data/lib/samagotchi/version.rb +1 -1
  164. data/lib/samagotchi/web/app.rb +45 -82
  165. data/lib/samagotchi/web/participant_access.rb +139 -40
  166. data/lib/samagotchi/web/participant_images.rb +185 -0
  167. data/lib/samagotchi/web/participant_review.rb +22 -142
  168. data/lib/samagotchi/web/participant_show.rb +241 -0
  169. data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
  170. data/lib/samagotchi/web/participant_view.rb +334 -27
  171. data/lib/samagotchi/web/participants_admin.rb +21 -40
  172. data/lib/samagotchi/web/public/annotate_bar.css +1 -2
  173. data/lib/samagotchi/web/public/annotate_bar.js +1 -2
  174. data/lib/samagotchi/web/public/app.js +126 -132
  175. data/lib/samagotchi/web/public/block_host.js +7 -4
  176. data/lib/samagotchi/web/public/bubbles.js +9 -1
  177. data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
  178. data/lib/samagotchi/web/public/chip_popover.js +5 -4
  179. data/lib/samagotchi/web/public/claim_link.js +4 -4
  180. data/lib/samagotchi/web/public/composer.css +4 -6
  181. data/lib/samagotchi/web/public/composer_mode.js +11 -6
  182. data/lib/samagotchi/web/public/composer_mount.js +4 -4
  183. data/lib/samagotchi/web/public/ctx.js +12 -3
  184. data/lib/samagotchi/web/public/data.js +2 -10
  185. data/lib/samagotchi/web/public/delivery_line.js +49 -63
  186. data/lib/samagotchi/web/public/history_shape.js +5 -1
  187. data/lib/samagotchi/web/public/images.js +7 -1
  188. data/lib/samagotchi/web/public/index.html +50 -34
  189. data/lib/samagotchi/web/public/info_bar_model.js +2 -1
  190. data/lib/samagotchi/web/public/live_turn.js +1 -1
  191. data/lib/samagotchi/web/public/markdown_place.js +5 -4
  192. data/lib/samagotchi/web/public/owner_claim.js +5 -5
  193. data/lib/samagotchi/web/public/owner_verify.js +0 -2
  194. data/lib/samagotchi/web/public/participant_bar.js +107 -0
  195. data/lib/samagotchi/web/public/participant_main.js +289 -0
  196. data/lib/samagotchi/web/public/participant_model.js +5 -292
  197. data/lib/samagotchi/web/public/participant_names.js +17 -8
  198. data/lib/samagotchi/web/public/participant_revise.js +66 -0
  199. data/lib/samagotchi/web/public/participants_panel.js +32 -74
  200. data/lib/samagotchi/web/public/question_cards.js +14 -3
  201. data/lib/samagotchi/web/public/refs.js +53 -36
  202. data/lib/samagotchi/web/public/reload_check.js +70 -14
  203. data/lib/samagotchi/web/public/revise_stack.js +21 -10
  204. data/lib/samagotchi/web/public/send_turn.js +28 -29
  205. data/lib/samagotchi/web/public/session_actions.js +4 -45
  206. data/lib/samagotchi/web/public/session_fields.js +1 -2
  207. data/lib/samagotchi/web/public/session_state.js +12 -7
  208. data/lib/samagotchi/web/public/session_sync.js +9 -2
  209. data/lib/samagotchi/web/public/session_view.js +14 -5
  210. data/lib/samagotchi/web/public/settings_panel.js +4 -18
  211. data/lib/samagotchi/web/public/stage_answer.js +56 -0
  212. data/lib/samagotchi/web/public/stage_asking.js +7 -5
  213. data/lib/samagotchi/web/public/stage_cloud.js +93 -0
  214. data/lib/samagotchi/web/public/stage_dom.js +100 -0
  215. data/lib/samagotchi/web/public/stage_handoff.js +154 -0
  216. data/lib/samagotchi/web/public/stage_owner_wait.js +35 -0
  217. data/lib/samagotchi/web/public/stage_pager.js +59 -0
  218. data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
  219. data/lib/samagotchi/web/public/stage_view.js +103 -410
  220. data/lib/samagotchi/web/public/stage_waiting.js +74 -6
  221. data/lib/samagotchi/web/public/start_page.js +12 -33
  222. data/lib/samagotchi/web/public/start_settings.js +24 -78
  223. data/lib/samagotchi/web/public/start_toolkit.js +6 -10
  224. data/lib/samagotchi/web/public/storage.js +22 -0
  225. data/lib/samagotchi/web/public/stream_handlers.js +3 -10
  226. data/lib/samagotchi/web/public/tokens.css +1 -1
  227. data/lib/samagotchi/web/public/turn_block.js +2 -5
  228. data/lib/samagotchi/web/public/turn_events.js +30 -12
  229. data/lib/samagotchi/web/public/turn_html.js +9 -2
  230. data/lib/samagotchi/web/public/turn_pieces.js +3 -4
  231. data/lib/samagotchi/web/public/turn_range.js +1 -2
  232. data/lib/samagotchi/web/public/verify_target.js +2 -4
  233. data/lib/samagotchi/web/public/viewer.js +59 -0
  234. data/lib/samagotchi/web/public/viewer_self.js +59 -0
  235. data/lib/samagotchi/web/public/working_set.js +11 -5
  236. data/lib/samagotchi/web/public/working_set_view.js +53 -8
  237. data/lib/samagotchi/web/public/ws_cards.js +89 -0
  238. data/lib/samagotchi/web/public/ws_peek.js +106 -0
  239. data/lib/samagotchi/web/public/ws_preview.css +126 -0
  240. data/lib/samagotchi/web/public/ws_reader.js +319 -0
  241. data/lib/samagotchi/web/public/ws_timeline.js +200 -0
  242. data/lib/samagotchi/web/public/ws_way_in.js +25 -0
  243. data/lib/samagotchi/web/qr.rb +1 -1
  244. data/lib/samagotchi/web/session_control.rb +42 -15
  245. data/lib/samagotchi/web/session_create.rb +6 -72
  246. data/lib/samagotchi/web/session_show.rb +75 -28
  247. data/lib/samagotchi/web/session_summary.rb +1 -4
  248. data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
  249. data/lib/samagotchi/web/viewer.rb +70 -0
  250. data/lib/samagotchi/web/working_set_routes.rb +132 -0
  251. data/lib/samagotchi/worker.rb +35 -28
  252. data/lib/samagotchi/worker_inbound.rb +4 -3
  253. data/lib/samagotchi/worker_link.rb +17 -0
  254. data/lib/samagotchi/working_set.rb +322 -11
  255. metadata +32 -13
  256. data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
  257. data/lib/samagotchi/participant_mode.rb +0 -86
  258. data/lib/samagotchi/review_apply.rb +0 -131
  259. data/lib/samagotchi/review_command.rb +0 -123
  260. data/lib/samagotchi/review_start.rb +0 -196
  261. data/lib/samagotchi/web/public/participant.html +0 -218
  262. data/lib/samagotchi/web/public/participant.js +0 -719
  263. data/lib/samagotchi/web/public/participant_annotate.js +0 -76
  264. data/lib/samagotchi/web/public/review_apply.js +0 -34
  265. data/lib/samagotchi/web/public/review_history.js +0 -72
  266. data/lib/samagotchi/web/public/review_start.js +0 -55
  267. data/lib/samagotchi/web/public/tools_overview.js +0 -42
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../engine_peers"
4
+ require_relative "../log"
5
+ require_relative "../session"
6
+
3
7
  module Samagotchi
4
8
  class Engine
5
9
  # The bound session and its prompt: #session= (its recap, metrics and
@@ -1,5 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../idle_client"
4
+ require_relative "../idle_target"
5
+ require_relative "../log"
6
+ require_relative "../objectives_check"
7
+ require_relative "../objectives_track"
8
+ require_relative "../session"
9
+ require_relative "../system_one/recorder"
10
+ require_relative "../system_one/runs"
11
+
3
12
  module Samagotchi
4
13
  class Engine
5
14
  # Side requests: a plugin's ctx.ask_model and Check this on their own
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../log"
4
+
3
5
  module Samagotchi
4
6
  class Engine
5
7
  # The running turn as other threads see it: steering into it (now or
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../log"
4
+ require_relative "../tool_loads"
5
+ require_relative "../tools/tool_surface"
6
+ require_relative "../turn_stages/toolkit_suggestion"
7
+
3
8
  module Samagotchi
4
9
  class Engine
5
10
  # The session's toolkit: the kits and what a turn declares
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../answer_display"
4
+ require_relative "../answer_refs"
5
+ require_relative "../client"
6
+ require_relative "../last_turn"
7
+ require_relative "../llm/model_result"
8
+ require_relative "../log"
9
+
3
10
  module Samagotchi
4
11
  class Engine
5
12
  # How a turn ends after #end_turn's step: the normal ending and its
@@ -1,5 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../image_store"
4
+ require_relative "../llm/errors"
5
+ require_relative "../llm/turn_settings"
6
+ require_relative "../log"
7
+ require_relative "../session"
8
+ require_relative "../turn_stages/warmup"
9
+ require_relative "../vision_context"
10
+
3
11
  module Samagotchi
4
12
  class Engine
5
13
  # What a turn's steps use before and around the model: its settings,
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../turn_stages/verify_anchors"
4
+
3
5
  module Samagotchi
4
6
  class Engine
5
7
  # Verify and Revise anchors (TurnStages::VerifyAnchors): #begin_turn
@@ -48,7 +48,6 @@ require_relative "llm/openai_chat"
48
48
  require_relative "llm/turn_settings"
49
49
  require_relative "session"
50
50
  require_relative "toolkit_binding"
51
- require_relative "participant_mode"
52
51
  require_relative "context_candidates"
53
52
  require_relative "context_candidates_log"
54
53
  require_relative "context_candidate_choice"
@@ -504,7 +503,9 @@ module Samagotchi
504
503
  cancel_controller: -> { active_cancel_controller },
505
504
  # A participant's turn: their name on the owner's card, their
506
505
  # grant's mode for the turn's (GuardrailWiring#begin_turn).
507
- participant: ->(author) { @participants.entry_for(author, session: @session) }
506
+ participant: ->(author) { @participants.entry_for(author, session: @session) },
507
+ # The same clock the participants line measures "active" at.
508
+ clock: -> { @participants.now }
508
509
  )
509
510
  end
510
511
  private :build_guardrail_wiring
@@ -528,7 +529,11 @@ module Samagotchi
528
529
  served_expected_by: ->(served) { served_expected_by(served) },
529
530
  working_set_snapshot: ->(session, conversation) { working_set_snapshot(session, conversation) },
530
531
  turn_running: -> { turn_running? },
531
- announce_or_hold: ->(event) { announce_or_hold(event) }
532
+ announce_or_hold: ->(event) { announce_or_hold(event) },
533
+ # The newest request's estimate, for a client that joins mid-turn
534
+ # (see EventFanout#record_context_status). The turn thread writes it;
535
+ # the snapshot reads it once and dups it.
536
+ keep_context_status: ->(status) { @last_context_status = status }
532
537
  )
533
538
  end
534
539
  private :build_event_fanout
@@ -35,9 +35,12 @@ module Samagotchi
35
35
  # @param working_set_snapshot [#call] (session, conversation) → WorkingSet::Snapshot
36
36
  # @param turn_running [#call] → Boolean
37
37
  # @param announce_or_hold [#call] (event) → announces the event, or holds it
38
+ # @param keep_context_status [#call] (status) → keeps the newest request's
39
+ # context estimate (the Engine's @last_context_status) for a client that
40
+ # joins mid-turn
38
41
  def initialize(observer:, used_memories:, muted:, steer_cut:, thinking_notices:, metrics:, hooks:, turn_context:,
39
42
  last_turn_context:, model_settings:, session:, live_conversation:, used_memory_names:, served_expected_by:,
40
- working_set_snapshot:, turn_running:, announce_or_hold:)
43
+ working_set_snapshot:, turn_running:, announce_or_hold:, keep_context_status:)
41
44
  @observer = observer
42
45
  @used_memories = used_memories
43
46
  @muted = muted
@@ -55,6 +58,7 @@ module Samagotchi
55
58
  @working_set_snapshot = working_set_snapshot
56
59
  @turn_running = turn_running
57
60
  @announce_or_hold = announce_or_hold
61
+ @keep_context_status = keep_context_status
58
62
  @working_set_emitted = nil
59
63
  end
60
64
 
@@ -97,6 +101,7 @@ module Samagotchi
97
101
  watch&.started(event[:iteration], restarted: true)
98
102
  end
99
103
  when :generation_chunk then thinking_notices.note_thought(progress[:thinking])
104
+ when :context_status then record_context_status(event)
100
105
  end
101
106
  # The chat loop asked again without the thinking fields or the
102
107
  # reasoning sent back: a notice, not an event of its own.
@@ -179,6 +184,22 @@ module Samagotchi
179
184
  event
180
185
  end
181
186
 
187
+ # The newest request's estimate, kept for a client that joins mid-turn:
188
+ # EngineSnapshots#session_state_snapshot's `context_status` reads it, so a
189
+ # page opened while a turn runs shows the percent at once instead of
190
+ # "ctx ?". Stored before the event is emitted: a snapshot read between the
191
+ # emit and this store would have a cursor past the event and the older
192
+ # value. Only a turn's stream handler comes through here, so a side
193
+ # request (/btw, a recap) can't overwrite it; the turn-end write stays.
194
+ def record_context_status(event)
195
+ pct = event.dig(:usage, :estimated_pct)
196
+ return unless pct.is_a?(Numeric)
197
+
198
+ @keep_context_status.call({ est_pct: pct, bucket: event[:bucket] })
199
+ rescue StandardError => e
200
+ Log.warn(:turn, "context_status_keep_failed", error: e.class.name, msg: e.message.to_s[0, 200])
201
+ end
202
+
182
203
  # The turn's StreamWatch, or nil when no hook listens.
183
204
  def stream_watch(cancel_controller)
184
205
  return nil unless cancel_controller && hooks.any?(Hooks::StreamWatch::EVENT)
@@ -5,7 +5,6 @@ require "fileutils"
5
5
  require "json"
6
6
  require "openssl"
7
7
  require_relative "steer"
8
- require_relative "participant_mode"
9
8
  require "securerandom"
10
9
  require "time"
11
10
  require_relative "atomic_file"
@@ -16,6 +15,7 @@ require_relative "session"
16
15
  require_relative "redacted_inspect"
17
16
  require_relative "private_files"
18
17
  require_relative "participant_exposure"
18
+ require_relative "participant_turn_mode"
19
19
 
20
20
  module Samagotchi
21
21
  # Participants' access to one session each (the shared-sessions plan,
@@ -53,14 +53,13 @@ module Samagotchi
53
53
  KEEP_ENDED = 30 * DAY
54
54
  # last_used_at is written at most this often per grant.
55
55
  TOUCH_INTERVAL = 60
56
- KINDS = %w[human agent].freeze
57
- # The only role in v1: a reviewer reads and (P3) comments.
56
+ # Grants retain the stored "reviewer" role; its user-facing label is participant.
58
57
  ROLES = %w[reviewer].freeze
59
- # The participant mode a grant was issued for (ParticipantMode): "pair"
60
- # only when the owner was shown that a participant's turns act
61
- # (ReviewStart::PAIR_WARNING); none for every other grant, and every
62
- # grant from before it, whose turns stay review turns.
63
- PAIR_MODE = ParticipantMode::PAIR.to_s
58
+ # The mark of a grant this chi honours: every grant is issued with it
59
+ # (a participant's turns act under the owner's rules). A grant without
60
+ # it was issued by an older chi for read-only turns, which this chi
61
+ # doesn't run: it reads as ended (Grant#state :outdated).
62
+ PAIR_MODE = ParticipantTurnMode::PAIR_MODE
64
63
  NAME_MAX = ParticipantName::MAX
65
64
  ID_RE = /\Ap_[0-9a-f]{8}\z/
66
65
  # D7: what a participant's turns (and the side calls they cause) may
@@ -72,6 +71,11 @@ module Samagotchi
72
71
  # (config web.participants.queue); at most MAX_QUEUE.
73
72
  DEFAULT_QUEUE = 3
74
73
  MAX_QUEUE = 20
74
+ # How many distinct image files a participant may upload into the
75
+ # grant's session (ParticipantUploads, chi web's participant upload),
76
+ # and how many uploads they may try in all, refused ones counted.
77
+ MAX_IMAGES = 40
78
+ MAX_IMAGE_ATTEMPTS = 2 * MAX_IMAGES
75
79
  # chi share --expires and config web.participants.expires: Nh or Nd.
76
80
  EXPIRES_RE = /\A(\d+)([hd])\z/
77
81
 
@@ -137,17 +141,18 @@ module Samagotchi
137
141
  # +cap+ (dollars) and +queue+ (turns waiting) as issued; nil in a
138
142
  # grant from before them, which takes the config's (#spend_cap,
139
143
  # #queue_limit).
140
- # +exposure+: what the participant learns of the review's usage
144
+ # +exposure+: what the participant learns of the session's usage
141
145
  # (ParticipantExposure; "own" for every grant today, and for one from
142
146
  # before it). Kept as stored: a level this chi doesn't know reads as
143
147
  # the narrowest, and is written back as it was.
144
148
  # +extra+: the stored keys this chi doesn't know (a newer chi's,
145
149
  # such as a field added to a grant without a version bump), written
146
150
  # back as they were, so a rewrite here never drops them.
147
- # +mode+: PAIR_MODE when the owner invited them to act (Grants#issue's
148
- # mode:), nil otherwise. Stored only when set; a chi that doesn't know
149
- # it keeps it in +extra+ and runs their turns as review turns.
150
- Grant = Data.define(:id, :session_id, :digest, :kind, :name, :role, :created_at, :expires_at, :revoked_at,
151
+ # +mode+: PAIR_MODE for every grant this chi issues; nil in a grant an
152
+ # older chi issued for read-only turns, which reads as ended
153
+ # (#state :outdated). Stored only when set; a chi that doesn't know it
154
+ # keeps it in +extra+.
155
+ Grant = Data.define(:id, :session_id, :digest, :name, :role, :created_at, :expires_at, :revoked_at,
151
156
  :revoked_by, :last_used_at, :cap, :queue, :identity, :exposure, :mode, :extra) do
152
157
  # identity: the proxy identity (an email, lower case) the grant is
153
158
  # bound to, nil for any (Web::ProxyGate; issued from shared-sessions P6).
@@ -158,7 +163,7 @@ module Samagotchi
158
163
 
159
164
  def self.from_h(hash)
160
165
  known = members - [:extra]
161
- extra = hash.reject { |key, _| known.include?(key.to_s.to_sym) }
166
+ extra = hash.reject { |key, _| known.include?(key.to_s.to_sym) || self::RETIRED.include?(key.to_s) }
162
167
  new(**known.to_h { |key| [key, hash[key.to_s]] }, extra: extra)
163
168
  end
164
169
 
@@ -171,10 +176,13 @@ module Samagotchi
171
176
  # The author a participant's turn carries (Principal#author).
172
177
  def author = Steer.author_for(id)
173
178
 
174
- # :active, :revoked or :expired at +now+ (a Time).
179
+ # :active, :revoked, :expired or :outdated (an older chi's grant
180
+ # for read-only turns: no PAIR_MODE) at +now+ (a Time). Derived, never
181
+ # written: an outdated grant is swept as any other once it expires.
175
182
  def state(now)
176
183
  return :revoked if revoked_at
177
184
  return :expired if Time.iso8601(expires_at) <= now
185
+ return :outdated unless ParticipantTurnMode.invite_mode?(mode)
178
186
 
179
187
  :active
180
188
  end
@@ -191,7 +199,7 @@ module Samagotchi
191
199
 
192
200
  # Never the digest: what chi share ls and the owner's routes show.
193
201
  def public_h(now)
194
- { id: id, session_id: session_id, kind: kind, name: name, role: role, created_at: created_at,
202
+ { id: id, session_id: session_id, name: name, role: role, created_at: created_at,
195
203
  expires_at: expires_at, revoked_at: revoked_at, revoked_by: revoked_by, last_used_at: last_used_at,
196
204
  state: state(now).to_s, cap: spend_cap, queue: queue_limit, identity: identity }
197
205
  end
@@ -217,6 +225,12 @@ module Samagotchi
217
225
  alias_method :to_s, :inspect
218
226
  end
219
227
 
228
+ # Keys an older chi stored that this one reads as known and drops:
229
+ # "kind" (human / agent, retired with the agent label). Not kept in
230
+ # #extra, so a newer store's check for unknown fields (#reload) doesn't
231
+ # leave an older pair grant out for it.
232
+ Grant::RETIRED = %w[kind].freeze
233
+
220
234
  # A new grant and its token: the only time the token exists outside
221
235
  # the participant's hands.
222
236
  Issued = Data.define(:grant, :token) do
@@ -326,16 +340,13 @@ module Samagotchi
326
340
  # @param on_write [#call, nil] see #update
327
341
  # @return [Issued]
328
342
  # @raise [Invalid]
329
- def issue(session_id:, name:, kind: "human", role: "reviewer", ttl: nil, cap: nil, identity: nil, mode: nil,
330
- on_write: nil)
343
+ def issue(session_id:, name:, role: "reviewer", ttl: nil, cap: nil, identity: nil, on_write: nil)
331
344
  Session.check_id!(session_id)
332
345
  ttl ||= Grants.default_ttl
333
346
  cap = Grants.default_cap if cap.nil?
334
- raise Invalid, "kind is human or agent, not #{kind}" unless KINDS.include?(kind)
335
347
  raise Invalid, "role is reviewer, not #{role}" unless ROLES.include?(role)
336
348
  raise Invalid, "a grant lasts 1 hour to 30 days" unless ttl.is_a?(Integer) && ttl.between?(3600, MAX_TTL)
337
349
  raise Invalid, CAP_RANGE unless Grants.cap?(cap)
338
- raise Invalid, "mode is #{PAIR_MODE} or none, not #{mode}" unless mode.nil? || mode == PAIR_MODE
339
350
 
340
351
  clean = Grants.clean_name(name)
341
352
  identity = Grants.clean_identity(identity) unless identity.nil?
@@ -343,10 +354,10 @@ module Samagotchi
343
354
  issued = now
344
355
  update(on_write) do |grants|
345
356
  id = fresh_id(grants)
346
- grant = Grant.new(id: id, session_id: session_id, digest: Grants.digest(token), kind: kind, name: clean,
357
+ grant = Grant.new(id: id, session_id: session_id, digest: Grants.digest(token), name: clean,
347
358
  role: role, created_at: stamp(issued), expires_at: stamp(issued + ttl), revoked_at: nil,
348
359
  revoked_by: nil, last_used_at: nil, cap: cap.to_f, queue: Grants.default_queue,
349
- identity: identity, mode: mode)
360
+ identity: identity, mode: PAIR_MODE)
350
361
  [grants + [grant], Issued.new(grant: grant, token: token)]
351
362
  end
352
363
  end
@@ -15,7 +15,8 @@ require_relative "edit_preview"
15
15
  require_relative "system_one"
16
16
  require_relative "tool_activity"
17
17
  require_relative "turn_origin"
18
- require_relative "participant_mode"
18
+ require_relative "grants"
19
+ require_relative "participant_turn_mode"
19
20
 
20
21
  module Samagotchi
21
22
  # An Engine's tool guardrails: who can approve (the interface), the YAML
@@ -58,8 +59,10 @@ module Samagotchi
58
59
  # @param participant [#call] (author) → the participant's
59
60
  # Participants::Entry (participants.json: their name, their grant's
60
61
  # mode), nil for none
62
+ # @param clock [#call] → Time a participant's invite is checked at
63
+ # (ParticipantTurnMode), the Engine's SessionParticipants#now
61
64
  def initialize(scratch:, tools:, session:, cancelled:, ask:, notify: ->(_message) {}, system_one: -> {},
62
- system_one_runs: -> {}, cancel_controller: -> {}, participant: ->(_author) {})
65
+ system_one_runs: -> {}, cancel_controller: -> {}, participant: ->(_author) {}, clock: -> { Time.now })
63
66
  @scratch = scratch
64
67
  @tools_lookup = tools
65
68
  @session_lookup = session
@@ -70,6 +73,9 @@ module Samagotchi
70
73
  @system_one_runs = system_one_runs
71
74
  @cancel_controller = cancel_controller
72
75
  @participant = participant
76
+ # → Time: what a participant's invite is current at (the Engine's
77
+ # SessionParticipants clock).
78
+ @clock = clock
73
79
  # Bundle name → the rules last loaded from it whole, kept while the
74
80
  # installed version needs a newer chi; [name, version] said so once.
75
81
  @loaded_bundle_rules = {}
@@ -118,14 +124,18 @@ module Samagotchi
118
124
  mode: author && participant_turn_mode(session, entry))
119
125
  end
120
126
 
121
- # A participant's turn's mode: in a Verify fresh child the one saved
122
- # on it at spawn (VerifyFreshOrigin#turn_mode: :review unless saved
123
- # :pair), never looked up again; elsewhere ParticipantMode.for_turn
124
- # (:pair only in a working session for a participant invited to act).
127
+ # A participant's turn's mode: PAIR (it acts under the owner's
128
+ # guardrails, PairBoundary) when ParticipantTurnMode says :pair, else
129
+ # REFUSED (no current invite, an older chi's read-only one, no session,
130
+ # the owner's own Verify fresh child: ParticipantRefusal). Never nil
131
+ # for a participant's turn: the tools scrub the owner's env on any mode.
125
132
  def participant_turn_mode(session, entry)
126
- fresh = session.respond_to?(:verify_fresh) && session.verify_fresh
127
- fresh ? fresh.turn_mode : ParticipantMode.for_turn(session, entry)
133
+ ParticipantTurnMode.of(entry: entry, session: session, now: @clock.call) == :pair ? PAIR : REFUSED
128
134
  end
135
+
136
+ # A participant's turn's modes (TurnContext#participant_mode).
137
+ PAIR = :pair
138
+ REFUSED = :refused
129
139
  private :participant_turn_mode
130
140
 
131
141
  # The gate every tool call asks first, given the call's TurnContext
@@ -149,10 +159,9 @@ module Samagotchi
149
159
  # The gate's core checks, in order. A delegate child's boundary comes
150
160
  # before the rules, so its ask keeps the child-boundary rule id (and
151
161
  # its once/session scopes) when a strict rule asks too. The
152
- # participant's boundary comes before both, by the session's
153
- # ParticipantMode: a review turn's (ReviewBoundary) or a pair turn's
154
- # (PairBoundary). Either denies what a participant's turn may not do,
155
- # never asks about it; both are no-ops for the owner's turns.
162
+ # participant's boundary comes before both, by the turn's mode: a pair
163
+ # turn's (PairBoundary), else every call denied (ParticipantRefusal).
164
+ # Either is a no-op for the owner's turns.
156
165
  # @param turn [TurnContext] the call's turn
157
166
  def checks(turn)
158
167
  rules = self.rules
@@ -163,13 +172,9 @@ module Samagotchi
163
172
  # The boundary for a participant's turn in this session (#checks), by
164
173
  # the turn's mode.
165
174
  def participant_boundary(turn)
166
- turn.participant_mode == ParticipantMode::PAIR ? pair_boundary(turn) : review_boundary(turn)
167
- end
175
+ return pair_boundary(turn) if turn.participant_mode == PAIR
168
176
 
169
- # A participant's review turn's boundary (Guardrails::ReviewBoundary): a
170
- # no-op unless +turn+'s author is a participant's.
171
- def review_boundary(turn)
172
- Guardrails::ReviewBoundary.new(author: -> { turn.author }, root: -> { boundary_root(turn.git) })
177
+ Guardrails::ParticipantRefusal.new(author: -> { turn.author })
173
178
  end
174
179
 
175
180
  # A participant's pair turn's boundary (Guardrails::PairBoundary): a
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "approvals"
4
+ require_relative "../turn_origin"
5
+
6
+ module Samagotchi
7
+ module Guardrails
8
+ # Which stored approvals an ask may use: the one place that says so
9
+ # (Gate#settle_ask asks it before it looks in the store).
10
+ # all — any stored entry: session, repo or rule (an owner's turn);
11
+ # session — only this session's own "Allow for this session" entries:
12
+ # a participant's turn (the owner's repo or rule approvals
13
+ # are the owner's, for the owner's turns), and an ask of a
14
+ # rule in SESSION_ONLY_RULES (a delegate child's boundary: a
15
+ # repo entry would hold in every worktree, for every child);
16
+ # none — no stored entry: a fresh ask (Verdict#fresh_ask, the pair
17
+ # boundary's own asks).
18
+ # A later policy (say a softer one for participants) is one more
19
+ # POLICIES key and one branch in .policy.
20
+ module ApprovalUse
21
+ POLICIES = { all: Approvals::STORED_SCOPES, session: %w[session].freeze, none: [].freeze }.freeze
22
+ # Rules a stored answer allows only for its session: their asks offer
23
+ # once/session, and a repo entry for the same call (from another
24
+ # rule) would hold in every worktree, for every child. The id is
25
+ # ChildBoundary::RULE (spelled here so the store needs no shell lexer;
26
+ # approval_use_spec checks they agree).
27
+ SESSION_ONLY_RULES = %w[child-boundary].freeze
28
+
29
+ module_function
30
+
31
+ # Fail closed: only a turn known to be the owner's gets :all. A call
32
+ # with no TurnContext (nil, or anything that can't say whose turn it
33
+ # is) gets :session, and so does one whose judged context names a
34
+ # participant's author (verdict.context's origin), whatever the turn
35
+ # says: a wider approval is the owner's, and an unknown caller is no
36
+ # owner.
37
+ # @param verdict [Verdict] the ask
38
+ # @param turn [TurnContext, nil] the call's turn
39
+ # @return [Symbol] a POLICIES key
40
+ def policy(verdict, turn)
41
+ return :none if verdict.fresh_ask?
42
+ return :session unless turn.respond_to?(:participant?)
43
+ return :session if turn.participant? || participant_call?(verdict) || SESSION_ONLY_RULES.include?(verdict.rule.to_s)
44
+
45
+ :all
46
+ end
47
+
48
+ # @return [Array<String>] the stored scopes +verdict+ may match (empty: none)
49
+ def scopes(verdict, turn) = POLICIES.fetch(policy(verdict, turn))
50
+
51
+ # Whether the call's judged context (Gate#evaluate's) names a
52
+ # participant's author.
53
+ def participant_call?(verdict)
54
+ origin = verdict.context.respond_to?(:origin) ? verdict.context.origin : nil
55
+ !!TurnOrigin.from(origin)&.participant?
56
+ end
57
+ end
58
+ end
59
+ end
@@ -37,10 +37,6 @@ module Samagotchi
37
37
  COLLECTION = "approvals"
38
38
  FORMAT = StateFormat.new(version: 1, members: [StateFormat.required(:scope), StateFormat.extra(:extra, in_version: 1)])
39
39
  STORED_SCOPES = %w[session repo rule].freeze
40
- # Rules a stored answer allows only for its session: their asks offer
41
- # once/session, and a repo entry for the same call (from another
42
- # rule) would hold in every worktree, for every child.
43
- SESSION_ONLY_RULES = %w[child-boundary].freeze
44
40
 
45
41
  # @param sessions_dir [String] Session's state dir
46
42
  # ($XDG_STATE_HOME/samagotchi/sessions): the store sits beside it,
@@ -62,9 +58,11 @@ module Samagotchi
62
58
  end
63
59
 
64
60
  # @param verdict [Verdict] an ask with its targets and context
61
+ # @param scopes [Array<String>] the entries' scopes it may use
62
+ # (ApprovalUse.scopes: which ones an ask may use is decided there)
65
63
  # @return [Hash, nil] the first entry that allows it
66
- def match(verdict)
67
- self.class.find_in(read.first, verdict)
64
+ def match(verdict, scopes: STORED_SCOPES)
65
+ self.class.find_in(read.first, verdict, scopes: scopes)
68
66
  end
69
67
 
70
68
  # Store the verdict's allowed scope (not "once").
@@ -77,17 +75,17 @@ module Samagotchi
77
75
  end
78
76
 
79
77
  # @param list [Array<Hash>] entries
78
+ # @param scopes [Array<String>] the scopes of the entries it may use
80
79
  # @return [Hash, nil] the first of +list+ that allows +verdict+
81
- def self.find_in(list, verdict)
80
+ def self.find_in(list, verdict, scopes: STORED_SCOPES)
82
81
  key = key_for(verdict)
83
82
  place = place_for(verdict)
84
83
  repo = verdict.targets&.repo
85
84
  here = ->(e) { e["repo"] ? e["repo"] == repo : e["repo_root"] == place }
86
85
  session_id = verdict.context&.session_id
87
- session_only = SESSION_ONLY_RULES.include?(verdict.rule.to_s)
88
86
  command_place = session_place(verdict)
89
87
  list.find do |e|
90
- next false if session_only && e["scope"] != "session"
88
+ next false unless scopes.include?(e["scope"])
91
89
 
92
90
  case e["scope"]
93
91
  when "session"
@@ -269,8 +267,8 @@ module Samagotchi
269
267
  # The store's entries, then this session's own.
270
268
  def entries = @store.entries + @mutex.synchronize { @own.dup }
271
269
 
272
- def match(verdict)
273
- @mutex.synchronize { Approvals.find_in(@own, verdict) } || @store.match(verdict)
270
+ def match(verdict, scopes: STORED_SCOPES)
271
+ @mutex.synchronize { Approvals.find_in(@own, verdict, scopes: scopes) } || @store.match(verdict, scopes: scopes)
274
272
  end
275
273
 
276
274
  def add(verdict, scope)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "outside"
4
4
  require_relative "path_resolve"
5
+ require_relative "targets"
5
6
  require_relative "shell_lex"
6
7
  require_relative "shell_paths"
7
8
  require_relative "shared_git"
@@ -4,6 +4,7 @@ require_relative "verdict"
4
4
  require_relative "context"
5
5
  require_relative "targets"
6
6
  require_relative "approvals"
7
+ require_relative "approval_use"
7
8
  require_relative "protected_paths"
8
9
  require_relative "../log"
9
10
 
@@ -81,12 +82,14 @@ module Samagotchi
81
82
  # Settle an ask: the approver asks the user; with none, or one that
82
83
  # fails, it is denied.
83
84
  # @return [Verdict]
84
- # A stored approval that covers the call allows it without asking; an
85
- # answer that allows it beyond this once is stored.
85
+ # A stored approval that covers the call allows it without asking
86
+ # (only the scopes ApprovalUse lets this ask use: none for a fresh
87
+ # ask, this session's own for a participant's turn); an answer that
88
+ # allows it beyond this once is stored.
86
89
  # @param context [TurnContext] the call's turn (the approver's)
87
90
  def settle_ask(verdict, context:)
88
91
  approvals = @approvals_lookup.call
89
- if !verdict.fresh_ask? && (entry = stored(approvals, verdict))
92
+ if (entry = stored(approvals, verdict, ApprovalUse.scopes(verdict, context)))
90
93
  verdict.settle!(:allow, decided_by: "approval")
91
94
  verdict.scope = entry["scope"]
92
95
  return verdict
@@ -104,8 +107,10 @@ module Samagotchi
104
107
 
105
108
  private
106
109
 
107
- def stored(approvals, verdict)
108
- approvals&.match(verdict)
110
+ def stored(approvals, verdict, scopes)
111
+ return nil if scopes.empty?
112
+
113
+ approvals&.match(verdict, scopes: scopes)
109
114
  rescue StandardError
110
115
  nil
111
116
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "shell_lex"
4
+ require_relative "pair_command"
4
5
 
5
6
  module Samagotchi
6
7
  module Guardrails
@@ -9,10 +9,10 @@ require_relative "../steer"
9
9
 
10
10
  module Samagotchi
11
11
  module Guardrails
12
- # A participant's pair turn (ParticipantMode :pair, a working session):
13
- # it acts with the session's tools under the owner's guardrails, and
14
- # their asks go to the owner (GuardrailWiring#request_approval). This
15
- # check sits in ReviewBoundary's seat (GuardrailWiring#checks), on in
12
+ # A participant's turn (GuardrailWiring::PAIR): it acts with the
13
+ # session's tools under the owner's guardrails, and their asks go to the
14
+ # owner (GuardrailWiring#request_approval). This check sits in the
15
+ # participant boundary's seat (GuardrailWiring#checks), on in
16
16
  # every guardrails mode and with guardrails.enabled: false, active only
17
17
  # while the running turn's author is a participant. An accident guard
18
18
  # for a trusted team, not containment. It denies, never asks (the
@@ -146,8 +146,8 @@ module Samagotchi
146
146
  )
147
147
 
148
148
  # @param author [#call] → String, nil: the running turn's author
149
- # (the call's TurnContext#author, GuardrailWiring#review_boundary /
150
- # #pair_boundary); the check is off unless it is a
149
+ # (the call's TurnContext#author, GuardrailWiring#pair_boundary);
150
+ # the check is off unless it is a
151
151
  # participant's (Steer.participant_author?)
152
152
  # @param denied_dirs [#call] → Array<String>: chi's own dirs
153
153
  # @param home [#call] → String, nil
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../steer"
4
+
5
+ module Samagotchi
6
+ module Guardrails
7
+ # The participant boundary's seat (GuardrailWiring#checks) for a
8
+ # participant's turn this chi doesn't run under the owner's rules: no
9
+ # current invite (an older chi's read-only one, no grant at all), a
10
+ # Verify fresh child saved for a read-only turn, or no session. The
11
+ # worker refuses such a turn before it starts (Worker#participant_refusal);
12
+ # this is the fail-closed fallback should one start anyway: every call is
13
+ # denied, nobody is asked. A no-op for the owner's turns.
14
+ class ParticipantRefusal
15
+ RULE = "participant-refused"
16
+ SOURCE = "core"
17
+ REASON = "this participant's turn runs no tools: their invite is from an older chi or has ended"
18
+ ADVICE = "Answer in text only; the session's owner can invite them again."
19
+
20
+ # @param author [#call] → String, nil: the running turn's author
21
+ def initialize(author:)
22
+ @author = author
23
+ end
24
+
25
+ # Vote on +verdict+.
26
+ def check(verdict)
27
+ return verdict unless Steer.participant_author?(@author.call)
28
+
29
+ verdict.deny!(REASON, rule: RULE, source: SOURCE, decided_by: "core", advice: ADVICE)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -14,9 +14,8 @@ module Samagotchi
14
14
  # checked on the path as given and as it resolves (a symlink in the
15
15
  # project to ~/.ssh is ~/.ssh; a `..` after a symlinked dir climbs out
16
16
  # of its target, as the kernel opens it: PathResolve.reals).
17
- # ReviewBoundary asks it for every read of a participant's turn; a
18
- # review session's subjects (chi review, the participant page's Plan)
19
- # go through the same check.
17
+ # PairBoundary asks it for every path a participant's turn reads or
18
+ # writes.
20
19
  class ReviewPaths
21
20
  # Home folders that hold keys and tokens, never read in a review turn
22
21
  # (nor read or written in a pair turn).