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
@@ -36,7 +36,7 @@ module Samagotchi
36
36
  @known = nil
37
37
  end
38
38
 
39
- # The participants in the review now: [{id:, name:, kind:}], [] for none.
39
+ # The participants in the session now: [{id:, name:}], [] for none.
40
40
  # @return [Array<Hash>]
41
41
  def active
42
42
  @mutex.synchronize { active_rows(read_entries) }
@@ -68,7 +68,7 @@ module Samagotchi
68
68
 
69
69
  def active_rows(entries)
70
70
  now = @clock.call
71
- entries.select { |entry| entry.active?(now) }.map { |entry| { id: entry.id, name: entry.name, kind: entry.kind } }
71
+ entries.select { |entry| entry.active?(now) }.map { |entry| { id: entry.id, name: entry.name } }
72
72
  end
73
73
 
74
74
  # The sidecar's entries, read again only when its mtime moved.
@@ -43,13 +43,13 @@ module Samagotchi
43
43
  "chi.tool_source" => "0.67.0", "chi.peer_source" => "0.67.0", "ctx.http" => "0.80.0",
44
44
  "ctx.cost" => "0.83.0", "ctx.sessions.children" => "0.34.0", "ctx.load_tools" => "0.99.0",
45
45
  "ctx.usage" => "0.100.0", "ctx.sessions.stop" => "0.34.0", "ctx.turn_author" => "0.106.0",
46
- "ctx.sessions.review" => "0.107.0", "ctx.sessions.send(delivery:)" => "0.64.0",
46
+ "ctx.sessions.send(delivery:)" => "0.64.0",
47
47
  "chi.toolkit(prompt:)" => "0.72.0", "ctx.ask_model(model:)" => "0.80.0", "chi.toolkit(groups:)" => "0.121.0",
48
48
  "chi.prompt_section" => "0.132.0", "chi.prompt_changed" => "0.132.0", "ctx.cache_confirm" => "0.132.0",
49
49
  "ctx.model_names" => "0.132.0", "chi.judgment" => "0.142.0", "ctx.judge" => "0.142.0",
50
50
  "ctx.judge_later" => "0.142.0", "ctx.judgments" => "0.142.0",
51
51
  "ctx.context.decline" => "0.43.0", "ctx.context.declined(url:)" => "0.43.0", "ctx.context.attach(force:)" => "0.43.0",
52
- "ctx.ask_user(effects:)" => "0.86.0", "chi.toolkit(description:)" => "0.122.0", "ctx.review" => "0.140.0",
52
+ "ctx.ask_user(effects:)" => "0.86.0", "chi.toolkit(description:)" => "0.122.0",
53
53
  "ctx.context.propose" => "0.140.0", "ctx.context.candidates" => "0.140.0", "ctx.context.withdraw" => "0.140.0",
54
54
  "ctx.continues" => "0.141.0", "ctx.context.left_behind" => "0.141.0", "ctx.context.attach(movable:)" => "0.141.0",
55
55
  "ctx.session_dir" => "0.143.0", "ctx.session_dir(create:)" => "0.144.0",
@@ -100,7 +100,7 @@ module Samagotchi
100
100
  return nil if own.declined?(candidate.name) || (url && own.declined_hints.include?(candidate.url))
101
101
 
102
102
  session = saved_session
103
- return nil if session&.review? || attached?(candidate, session)
103
+ return nil if attached?(candidate, session)
104
104
 
105
105
  recorded = own.add_candidate(candidate)
106
106
  if recorded.equal?(candidate)
@@ -276,10 +276,6 @@ module Samagotchi
276
276
  # another session handed over, not the user's own.
277
277
  def delegate? = !!saved_session&.delegate?
278
278
 
279
- # Whether the session is a review session (`chi review`, Session#review?):
280
- # one its participants read, not the owner's working session.
281
- def review? = !!saved_session&.review?
282
-
283
279
  # The id of the session this one continues (a continue's new link,
284
280
  # Session#continues), else nil.
285
281
  # @return [String, nil]
@@ -10,7 +10,6 @@ require_relative "../degrade"
10
10
  require_relative "../tools/delegate"
11
11
  require_relative "../children_status"
12
12
  require_relative "../context_move"
13
- require_relative "../review_start"
14
13
  require_relative "../model_profile"
15
14
 
16
15
  module Samagotchi
@@ -32,7 +31,7 @@ module Samagotchi
32
31
 
33
32
  # What starting a session can be refused by, answered as Error with
34
33
  # chi's own message: a model that is gone, a toolkit the config refuses,
35
- # a bad argument. #review adds its own: a subject it won't take.
34
+ # a bad argument.
36
35
  REFUSED = [ModelProfile::MissingModel, Toolkit::Refused, ArgumentError].freeze
37
36
 
38
37
  # @param host [Host] session_id, cwd, model_name and state_dir
@@ -88,29 +87,6 @@ module Samagotchi
88
87
  raise Error, e.message
89
88
  end
90
89
 
91
- # A review of this session (ReviewStart.fork, chi review --from): a new
92
- # session in its folder, on its model and setup, seeded with its recap
93
- # (never its transcript) and +seed+ (more context: the coordinator's
94
- # handoff, say), idle, to share with participants (chi share). This
95
- # session keeps running, unarchived. Not a child: it has no parent.
96
- # The recap is the one saved (the worker is asked for a fresh one, not
97
- # waited on unless +recap_wait+ seconds are given: this runs in this
98
- # session's own worker).
99
- # @param subjects [Array<String>] files under review, relative to its
100
- # folder (ReviewStart.check_subjects)
101
- # @return [String] the review session's id
102
- # @raise [Error] no session yet, a scratch session, a subject refused
103
- # (its one message), or it could not start
104
- def review(subjects: [], seed: nil, recap_wait: 0)
105
- source = @host.session_id.call or raise Error, "this session has no id yet"
106
- raise Error, "a scratch session starts no other sessions: they would outlive it" if @host.scratch&.call
107
-
108
- ReviewStart.fork(from: source, subjects: Array(subjects), seed: seed, state_dir: state_dir,
109
- recap_wait: recap_wait).id
110
- rescue *REFUSED, ReviewStart::Refused => e
111
- raise Error, e.message
112
- end
113
-
114
90
  # Send +text+ to session +id+ as a user message (it runs as a turn;
115
91
  # an idle session is woken, but one its owner stopped or archived is
116
92
  # not: refused). Waits up to 5 s for its worker, so call
@@ -92,7 +92,11 @@ module Samagotchi
92
92
  return unless @turn && !@claimed
93
93
 
94
94
  waiting = SessionInbox.waiting_input_data(@session_dir, @turn)
95
- @own_turn_input ||= !waiting.nil? && SessionInbox.turn_end_data?(waiting)
95
+ # A participant's next-step message may go into their own running
96
+ # turn (its author's), so it runs a turn of its own only when it
97
+ # would wait even there.
98
+ @own_turn_input ||= !waiting.nil? &&
99
+ SessionInbox.turn_end_data?(waiting, running_author: Steer.sender_author(waiting["author"]))
96
100
  @participant_input ||= !waiting.nil? && Steer.participant_author?(waiting["author"])
97
101
  @claimed = waiting.nil?
98
102
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "participant_messages"
3
4
  require_relative "verify_anchor"
4
5
 
5
6
  module Samagotchi
@@ -26,6 +27,14 @@ module Samagotchi
26
27
  end
27
28
 
28
29
  ReviseAnchor::FEATURE = "revise"
30
+ # A worker that checks a participant's Revise (ParticipantRevise, at the
31
+ # stamp) and keeps their draft: what chi web needs to pass one on.
32
+ ReviseAnchor::PARTICIPANT_FEATURE = "participant_revise"
33
+ # A participant's Revise to a live worker without PARTICIPANT_FEATURE
34
+ # (SessionManager::Delivery), in their words, never UNAVAILABLE's owner ones.
35
+ ReviseAnchor::PARTICIPANT_UNAVAILABLE = {
36
+ "error" => "revise_unavailable", "detail" => ParticipantMessages::REVISE_UNAVAILABLE
37
+ }.freeze
29
38
  ReviseAnchor::UNAVAILABLE = {
30
39
  "error" => "revise_unavailable",
31
40
  "detail" => "this session's worker predates Revise turns; restart this session to use Revise"
@@ -202,8 +202,7 @@ module Samagotchi
202
202
  chi context <add|push|ls|show|refresh|rm|mute|unmute> live external text attached to sessions
203
203
  chi send [-m TEXT] ID...|--new a message into sessions, as if typed there
204
204
  chi answer ID --question QID --option N answer a question a session waits on
205
- chi share ID --name NAME | ls [ID] | cap ID P D | revoke ID [P]|--all participants who review a session
206
- chi review FILE... [--dir DIR] | --from ID a review session to share (chi share)
205
+ chi share ID --name NAME | ls [ID] | cap ID P D | revoke ID [P]|--all invite people into a session
207
206
  chi memory <ls|rm> [--scope project|system] the memories; rm moves one to the bundle trash
208
207
  chi bundle <install|upgrade|uninstall|status|diff|list|build|trash|new|test|check|try>
209
208
  chi guardrails replay [--dry-run] [--threshold T] [--model M] seed System 1's record from answered approvals
@@ -216,7 +215,7 @@ module Samagotchi
216
215
  chi project [init [DIR]] this folder's project; init makes a folder in no git repository one
217
216
  chi schedule <add|list|show|tick|run-now|enable|disable|cancel> durable schedules that outlive every worker
218
217
  chi remote <add|ls|rm> other machines' chi web, for chi --remote NAME
219
- chi --remote NAME <send|answer|note|context|sessions|share|review> … those commands on that machine (or CHI_REMOTE=NAME)
218
+ chi --remote NAME <send|answer|note|context|sessions|share> … those commands on that machine (or CHI_REMOTE=NAME)
220
219
  chi --remote NAME --attach ID | --resume ID | --dir DIR [-p TEXT] a session on that machine, in this terminal
221
220
  chi self version, paths, model and bundles
222
221
  chi update [--dry-run] update this chi, its bundles and the desktop helper
@@ -221,6 +221,11 @@ module Samagotchi
221
221
 
222
222
  UNKNOWN_VISION = VisionSupport::Answer.new(value: nil, reason: nil)
223
223
 
224
+ # .vision_refusal for +model_name+ (+typed+: as the user typed it) on
225
+ # .vision_answer's answer: chi web's turn and create routes and a
226
+ # participant's turn ask this one helper.
227
+ def self.vision_refusal_for(model_name, typed: nil) = vision_refusal(model_name, vision_answer(model_name, typed: typed))
228
+
224
229
  # What to say when +answer+ (.vision_answer's for +model_name+) is a
225
230
  # no, or nil: the words chi send and chi web's turn and create routes
226
231
  # refuse images with.
@@ -630,9 +635,9 @@ module Samagotchi
630
635
  wait_for_reply(id, target: target, timeout: options[:timeout])
631
636
  end
632
637
 
633
- # A participant's --wait -m (a review turn through chi --remote with
634
- # their token): their message always runs as a queued turn of its own
635
- # (chi web's review turns), so a running turn doesn't refuse it and
638
+ # A participant's --wait -m (a participant turn through chi --remote
639
+ # with their token): their message always runs as a queued turn of its
640
+ # own, so a running turn doesn't refuse it and
636
641
  # there is no busy check (the owner's route, refused to them). Their
637
642
  # wait routes take only a turn of theirs: the wait is on the one just
638
643
  # queued, as --wait --turn T.
@@ -643,7 +648,7 @@ module Samagotchi
643
648
 
644
649
  turn = @delivered.enqueued_id.to_s
645
650
  if turn.empty?
646
- error_line("chi send: #{target.label}: the review turn's id didn't come back; chi --remote … send --wait --turn T waits once you have it")
651
+ error_line("chi send: #{target.label}: the turn's id didn't come back; chi --remote … send --wait --turn T waits once you have it")
647
652
  return 1
648
653
  end
649
654
  start = @access.prepare_wait(id, turn: turn)
@@ -863,7 +868,7 @@ module Samagotchi
863
868
  return " (started its worker)" if owner.nil? && !@continued_here&.key?(id)
864
869
  return queue_note(result, running: running) if Delivery.queue?(delivery)
865
870
  return "" unless running
866
- # A participant's review turn was running: the worker queued it.
871
+ # A participant's turn was running: the worker queued it.
867
872
  return queue_note(result, running: running) if result.delivery == Delivery::QUEUE
868
873
 
869
874
  # A busy worker runs a message with images as its own next turn
@@ -879,14 +884,14 @@ module Samagotchi
879
884
  " #{TerminalUI::Formatting.steer_cut_note(outcome.to_sym, result.cut_after)}"
880
885
  end
881
886
 
882
- # A participant's message: queued as a review turn of its own (chi
883
- # web's), its id the one their wait takes.
887
+ # A participant's message: queued as a turn of its own, its id the one
888
+ # their wait takes.
884
889
  def participant_note(id, result)
885
890
  turn = result.enqueued_id.to_s
886
- return " (queued as a review turn)" if turn.empty?
887
- return " (queued as review turn #{turn})" if @waiting
891
+ return " (queued as their own turn)" if turn.empty?
892
+ return " (queued as turn #{turn})" if @waiting
888
893
 
889
- " (queued as review turn #{turn}; #{@access.invocation.command("send --wait --turn #{turn} #{id}")} waits for its reply)"
894
+ " (queued as turn #{turn}; #{@access.invocation.command("send --wait --turn #{turn} #{id}")} waits for its reply)"
890
895
  end
891
896
 
892
897
  # A --queue, worded from the Bridge's ack: queue when a turn ran as it
@@ -418,9 +418,6 @@ module Samagotchi
418
418
  @settings = SessionConfig::Settings.of(value)
419
419
  end
420
420
 
421
- # Whether this is a review session (chi review, the web's Start review).
422
- def review? = !@review.nil?
423
-
424
421
  # The session whose participants.json names this session's
425
422
  # participants: a Verify fresh child's parent (its requester's grant is
426
423
  # the parent's), else the session itself.
@@ -10,7 +10,7 @@ module Samagotchi
10
10
  # "chi <cmd> runs on this machine only: run it on <remote>"). The v1 scope is the remote-sessions plan's
11
11
  # D3: send, answer, note, a session's context (add, push, ls, show, rm)
12
12
  # and sessions list/stop/restart/archive/unarchive/delete, chi share
13
- # (the shared-sessions plan's P2) and chi review (P5); the rest
13
+ # (the shared-sessions plan's P2); the rest
14
14
  # stays local. bin/chi's subcommands that act on the machine, not on
15
15
  # sessions, are MACHINE. The run flags (chi --attach, -p, --resume: a
16
16
  # session in this terminal, a remote attach there) are RUN's.
@@ -124,7 +124,6 @@ module Samagotchi
124
124
  # through its chi web's participants routes.
125
125
  "share" => SUPPORTED,
126
126
  "share --name" => SUPPORTED,
127
- "share --agent" => SUPPORTED,
128
127
  "share --expires" => SUPPORTED,
129
128
  "share --cap" => SUPPORTED,
130
129
  # A chi web without bound grants (Remote#invite checks its
@@ -136,14 +135,6 @@ module Samagotchi
136
135
  "share revoke" => SUPPORTED,
137
136
  "share revoke --all" => SUPPORTED,
138
137
 
139
- # A review session (docs/sessions.md): the remote's chi web checks
140
- # the files against its own project; --dir is required there
141
- # unless --from (D4).
142
- "review" => SUPPORTED,
143
- "review --dir" => SUPPORTED,
144
- "review --model" => SUPPORTED,
145
- "review --from" => SUPPORTED,
146
-
147
138
  "broadcast" => LOCAL_ONLY
148
139
  }.freeze
149
140
 
@@ -21,7 +21,7 @@ require_relative "../chi_invocation"
21
21
  require_relative "../worker_sidecar"
22
22
  require_relative "../worker_link"
23
23
  require_relative "../worker_presence"
24
- require_relative "../review_start"
24
+ require_relative "../share_terms"
25
25
  require_relative "../launch_mode"
26
26
  require_relative "../participants"
27
27
  require_relative "../config"
@@ -144,11 +144,9 @@ module Samagotchi
144
144
  # @return [Session] the session created (its id, model_warning,
145
145
  # continues, moved_children)
146
146
  # @raise [SessionContinue::Refused, SessionManager::ArchiveRefused,
147
- # SessionManager::OwnedByTUI, ReviewStart::Refused] refused;
147
+ # SessionManager::OwnedByTUI] refused;
148
148
  # StandardError: could not start
149
149
  def create(spec)
150
- return create_review(spec) if spec.review
151
-
152
150
  start = spec.preview ? { prompt: spec.prompt, preview: spec.preview } : { prompt: spec.prompt }
153
151
  if spec.continues
154
152
  return SessionContinue.run(spec.continues, **start, model: spec.model_name, client_id: spec.client_id, **dir)
@@ -158,18 +156,6 @@ module Samagotchi
158
156
  setup: spec.setup, client_id: spec.client_id, **dir)
159
157
  end
160
158
 
161
- # A review session (ReviewStart): a fork of review.from, or a fresh
162
- # one in the spec's folder.
163
- def create_review(spec)
164
- review = spec.review
165
- if review.from
166
- return ReviewStart.fork(from: review.from, subjects: review.subjects, model: spec.model_name, state_dir: state_dir!)
167
- end
168
-
169
- ReviewStart.start(subjects: review.subjects, dir: spec.working_directory || Dir.pwd, model: spec.model_name,
170
- setup: spec.setup || SessionSetup.new, state_dir: state_dir!)
171
- end
172
-
173
159
  # Whether a just-created session's worker came up (its Bridge
174
160
  # answers) within +timeout+ seconds.
175
161
  def await_worker(id, timeout:)
@@ -443,15 +429,16 @@ module Samagotchi
443
429
  # header (Participants.invite).
444
430
  # @return [Invitation]
445
431
  # @raise [ArgumentError] no such session
446
- # @raise [BadRequest] a bad name, kind, ttl or identity, an archived
432
+ # @raise [BadRequest] a bad name, ttl or identity, an archived
447
433
  # session, an identity with no proxy to check it
448
- def invite(id, name:, kind:, ttl: nil, cap: nil, identity: nil)
434
+ def invite(id, name:, ttl: nil, cap: nil, identity: nil)
449
435
  public_url = configured_public_url
450
- # Stamped pair only when the warning chi share prints says their turns act.
451
- terms = ReviewStart.share_terms(Session.load(id, **dir), state_dir: state_dir!)
452
- issued = Participants.invite(grants, session_id: id, name: name, kind: kind, ttl: ttl, cap: cap,
453
- identity: identity, public_url: public_url, mode: terms.grant_mode,
454
- state_dir: state_dir!)
436
+ # No link while the live worker would refuse every turn of theirs.
437
+ terms = ShareTerms.of(Session.load(id, **dir), state_dir: state_dir!)
438
+ raise BadRequest.new(terms.refusal, code: "worker_too_old") if terms.refusal
439
+
440
+ issued = Participants.invite(grants, session_id: id, name: name, ttl: ttl, cap: cap,
441
+ identity: identity, public_url: public_url, state_dir: state_dir!)
455
442
  web = public_url ? nil : local_web
456
443
  link = if public_url then public_url.link(link_code(issued), "s=#{id}")
457
444
  else "http://#{web.ip || "127.0.0.1"}:#{web.port}/?token=#{issued.token}#s=#{id}"
@@ -104,7 +104,7 @@ module Samagotchi
104
104
 
105
105
  # The errors any route of +entry+'s chi web can answer, each its one
106
106
  # message: the token refused (401 unauthorized) or ended (401
107
- # token_revoked / token_expired), the LAN IP only (403 forbidden), a
107
+ # token_revoked / token_expired / token_outdated), the LAN IP only (403 forbidden), a
108
108
  # participant's token on an owner's route (403 not_permitted) or over
109
109
  # its limits (429 too_many_turns / cap_reached). nil for any other
110
110
  # answer (chi remote add says the same).
@@ -125,7 +125,7 @@ module Samagotchi
125
125
  end
126
126
  end
127
127
 
128
- ACCESS_ERRORS = [TokenRevoked, TokenExpired, TokenBound, NotPermitted, TooManyTurns, CapReached].freeze
128
+ ACCESS_ERRORS = [TokenRevoked, TokenExpired, TokenOutdated, TokenBound, NotPermitted, TooManyTurns, CapReached].freeze
129
129
 
130
130
  # --- ids and sessions
131
131
 
@@ -298,12 +298,12 @@ module Samagotchi
298
298
  # chi web with bound grants (BOUND_FEATURE) is asked; an older one
299
299
  # would ignore it and issue a grant anyone could open
300
300
  # @return [Invitation]
301
- # @raise [BadRequest] a bad name, kind, ttl or identity, an archived
301
+ # @raise [BadRequest] a bad name, ttl or identity, an archived
302
302
  # session, an identity that chi web has no proxy to check
303
303
  # @raise [RemoteTooOld] an identity, and a chi web without bound grants
304
- def invite(id, name:, kind:, ttl: nil, cap: nil, identity: nil)
304
+ def invite(id, name:, ttl: nil, cap: nil, identity: nil)
305
305
  require_feature!(BOUND_FEATURE) unless identity.nil?
306
- body = { name: name, kind: kind, ttl: ttl, cap: cap, identity: identity }.compact
306
+ body = { name: name, ttl: ttl, cap: cap, identity: identity }.compact
307
307
  reply = request(:post, "#{session_path(id)}/participants", body: body)
308
308
  raise_refusal(reply) unless reply.status == 201
309
309
 
@@ -781,8 +781,10 @@ module Samagotchi
781
781
  when "toolkit_refused" then raise Toolkit::Refused, message.to_s
782
782
  # The grants store doesn't read there: chi share says what it says here.
783
783
  when "grants_unwritable" then raise Grants::Unwritable, message.to_s
784
- when /\Ainvalid_/, "missing_fields", "bad_images"
785
- # invalid_participant: chi share's name, kind or ttl, an archived session
784
+ when /\Ainvalid_/, "missing_fields", "bad_images", "worker_too_old"
785
+ # invalid_participant: chi share's name or ttl, an archived
786
+ # session; worker_too_old: an invite to a session whose worker
787
+ # must restart first
786
788
  raise BadRequest.new(message.to_s, code: error)
787
789
  end
788
790
  raise RemoteFailed, "#{@entry.label} answered #{reply.status}#{" #{error}" unless error.empty?}" \
@@ -790,8 +792,6 @@ module Samagotchi
790
792
  end
791
793
 
792
794
  def create_body(spec)
793
- return review_body(spec) if spec.review
794
-
795
795
  body = { model: spec.model_name, client_id: spec.client_id, history: false }
796
796
  if spec.preview || spec.idle
797
797
  body.merge!(idle: true, preview: spec.preview)
@@ -808,17 +808,6 @@ module Samagotchi
808
808
  body.compact
809
809
  end
810
810
 
811
- # A review session's create (chi review): its subjects as typed,
812
- # checked by the server against its own files; a fork names its
813
- # source and takes its folder.
814
- def review_body(spec)
815
- review = { subjects: spec.review.subjects, from: spec.review.from }.compact
816
- body = { review: review, model: spec.model_name }
817
- body[:dir] = spec.working_directory unless spec.review.from
818
- body.merge!(setup_body(spec.setup)) if spec.setup && !spec.review.from
819
- body.compact
820
- end
821
-
822
811
  def setup_body(words)
823
812
  llm = words.llm_context&.to_h { |field, word| [LLM_CONTEXT_KEYS.fetch(field), word] }
824
813
  { llm_context: llm, thinking: words.thinking, toolkit: words.toolkit,
@@ -51,6 +51,12 @@ module Samagotchi
51
51
  def initialize(label) = super("#{label}: #{ParticipantMessages::TOKEN_EXPIRED}")
52
52
  end
53
53
 
54
+ # 401 token_outdated: a link an older chi issued for read-only turns.
55
+ class TokenOutdated < AuthRefused
56
+ CODE = "token_outdated"
57
+ def initialize(label) = super("#{label}: #{ParticipantMessages::TOKEN_OUTDATED}")
58
+ end
59
+
54
60
  # 401 token_bound: a link bound to one account, used without that
55
61
  # account's sign-in (chi --remote doesn't go through the proxy).
56
62
  class TokenBound < AuthRefused
@@ -102,7 +108,7 @@ module Samagotchi
102
108
  # "active", "revoked" or "expired".
103
109
  # +cap+ dollars and +queue+ turns (nil from a chi web before them).
104
110
  # +identity+ the email the grant is bound to, nil for any.
105
- ParticipantView = Data.define(:id, :session_id, :kind, :name, :role, :created_at, :expires_at, :revoked_at,
111
+ ParticipantView = Data.define(:id, :session_id, :name, :role, :created_at, :expires_at, :revoked_at,
106
112
  :revoked_by, :last_used_at, :state, :cap, :queue, :identity) do
107
113
  def initialize(identity: nil, **) = super
108
114
 
@@ -112,8 +118,8 @@ module Samagotchi
112
118
  # What chi share made: the participant, their token and the link that
113
119
  # carries it (both shown this once: chi keeps only a digest), and
114
120
  # whether that chi web listens on the LAN (+lan+ false: the link works
115
- # on that machine only), and the warning for sharing a working session
116
- # (ReviewStart.share_warning; nil for a review session).
121
+ # on that machine only), and the warning that a participant's turns act
122
+ # in the session (ShareTerms#warning).
117
123
  Invitation = Data.define(:participant, :token, :link, :lan, :warning) do
118
124
  def initialize(participant:, token:, link:, lan:, warning: nil) = super
119
125
 
@@ -133,21 +139,11 @@ module Samagotchi
133
139
  # bundles). +client_id+ (chi send's, or chi answer's for a parent's
134
140
  # /continue yes) and +images+ (images follow) are for a Remote's server,
135
141
  # which checks the first line and the model as chi send checks them
136
- # here (Local checks before it creates). +review+ (a Review) makes it a
137
- # review session (chi review): idle, no prompt, and with +review.from+
138
- # a review fork of that session (its folder and setup: the rest is nil).
142
+ # here (Local checks before it creates).
139
143
  NewSession = Data.define(:prompt, :preview, :continues, :working_directory, :model_name, :setup, :client_id,
140
- :images, :idle, :review) do
144
+ :images, :idle) do
141
145
  def initialize(prompt:, preview: nil, continues: nil, working_directory: nil, model_name: nil, setup: nil,
142
- client_id: nil, images: false, idle: false, review: nil) = super
143
- end
144
-
145
- # A review session to create (NewSession#review): +subjects+ as typed
146
- # (relative to the session's folder; the side that has the files checks
147
- # them, ReviewStart.check_subjects), +from+ the session a review fork
148
- # starts from (an id, a prefix or last:<id>), or nil.
149
- Review = Data.define(:subjects, :from) do
150
- def initialize(subjects: [], from: nil) = super(subjects: Array(subjects).map(&:to_s), from: from)
146
+ client_id: nil, images: false, idle: false) = super
151
147
  end
152
148
 
153
149
  # chi send --new's setup flags as typed, for a Remote: +llm_context+
@@ -82,14 +82,12 @@ module Samagotchi
82
82
  end
83
83
 
84
84
  # The last answer as the carry note takes it, in at most +room+ bytes;
85
- # nil with session.carry_last_answer off, when there is none, when a
86
- # review link has it (a continue copies review: but not the grants, so
87
- # the next link's participants could differ) or when the session can't
88
- # be read: this runs inside a continue's rollback, and a note without it
89
- # is still a good note.
85
+ # nil with session.carry_last_answer off, when there is none, or when
86
+ # the session can't be read: this runs inside a continue's rollback, and
87
+ # a note without it is still a good note.
90
88
  # @return [String, nil]
91
89
  def carried_answer(previous, room:, state_dir:)
92
- return nil if previous.review? || !Config.get("session.carry_last_answer")
90
+ return nil unless Config.get("session.carry_last_answer")
93
91
 
94
92
  text = last_answer(Session.load(previous.id, state_dir: state_dir).messages)
95
93
  text && keep_end(text, room)
@@ -178,7 +178,7 @@ module Samagotchi
178
178
  match: ->(text) { text.casecmp?("/unqueue") })
179
179
  # chi share for the attached session (TerminalUI::ParticipantCommands):
180
180
  # a participant's turns run on its worker.
181
- registry.register("/share", "invite someone to review this session (/share NAME [--agent] [--expires 3d] [--cap 2])",
181
+ registry.register("/share", "invite someone into this session (/share NAME [--expires 3d] [--cap 2])",
182
182
  local: true, uis: [:attached], match: ->(text) { text.match?(%r{\A/share(?:\s.*)?\z}i) })
183
183
  registry.register("/participants", "list this session's participants (revoke [P], cap P DOLLARS)",
184
184
  local: true, uis: [:attached], match: ->(text) { text.match?(%r{\A/participants(?:\s.*)?\z}i) })
@@ -450,8 +450,8 @@ module Samagotchi
450
450
  # /guardrails: the rules (by source), what failed to load, the stored
451
451
  # approvals, numbered; /guardrails revoke N removes approval N.
452
452
  # /context, /context attach NAME, /context decline NAME
453
- # (ContextCandidateChoice.choose: the owner's own; a participant can't
454
- # send a / line, and a review session refuses them).
453
+ # (ContextCandidateChoice.choose is the owner's only; a participant
454
+ # cannot send a / line).
455
455
  def context_command(args)
456
456
  return reply(context_listing) if args.empty?
457
457
 
@@ -529,6 +529,9 @@ module Samagotchi
529
529
  mode = Config.get("guardrails.system_one.mode").to_s
530
530
  return if mode == "off" && entries.empty?
531
531
 
532
+ # The worker's (an Engine's) listing: the attached TUI and chi send load
533
+ # this file too and never need the judgment client.
534
+ require_relative "system_one/client"
532
535
  no_judgment = SystemOne::Client.no_judgment_reason(host_registry: @engine.host_registry, mode: mode)
533
536
  lines << (no_judgment ? "System 1 (#{mode}, but nothing is judged: #{no_judgment}):" : "System 1 (#{mode}):")
534
537
  auto_allows = system_one_auto_allows(entries)
@@ -534,8 +534,7 @@ module Samagotchi
534
534
  # IdleRecap#request_now) and wait, up to +wait+ seconds, for recap.json
535
535
  # to change. A worker that is gone wrote its recap when it left; one
536
536
  # that has nothing new to say, too short a conversation, or recaps off
537
- # answers at once. Best effort: the continue goes on without. A review
538
- # fork (ReviewStart) asks the same, with nothing archived after.
537
+ # answers at once. Best effort: the continue goes on without.
539
538
  def self.recap_before_archive(id, state_dir, wait:)
540
539
  dir = Session.session_dir(id, state_dir: state_dir)
541
540
  client = WorkerLink.client(id, session_dir: dir) or return
@@ -313,15 +313,18 @@ module Samagotchi
313
313
  # Whether a mid-turn drain leaves this unclaimed input file for a turn
314
314
  # of its own instead of merging it at a step boundary: a queued message
315
315
  # (`delivery: queue`), an image message (steering merges text only), or
316
- # a participant's, whatever its delivery says: theirs always runs as its
317
- # own turn, never inside another author's (D6; chi web queues it, and
318
- # this is the worker's own layer).
316
+ # one whose author isn't the running turn's: a participant's goes into
317
+ # their own running turn only, never another author's, and nobody's
318
+ # goes into a participant's but theirs (D6; the Bridge queues it, and
319
+ # this is the worker's own layer). +running_author+: the running turn's
320
+ # participant author (TurnOrigin#participant_author), nil for the
321
+ # owner's.
319
322
  # The drain skips such a file without stopping at it, so a later text
320
323
  # line still merges; the drain's file filter reads this one predicate,
321
324
  # so what a boundary leaves changes in one place.
322
- def self.waits_for_turn_end?(input_file)
325
+ def self.waits_for_turn_end?(input_file, running_author: nil)
323
326
  data = JSON.parse(File.read(input_file))
324
- data.is_a?(Hash) && turn_end_data?(data)
327
+ data.is_a?(Hash) && turn_end_data?(data, running_author: running_author)
325
328
  rescue JSON::ParserError, SystemCallError
326
329
  false
327
330
  end
@@ -339,10 +342,13 @@ module Samagotchi
339
342
 
340
343
  # A parsed input file's #waits_for_turn_end?. A Verify or a Revise turn
341
344
  # waits too: merged into a running turn as a steer, its anchor would be
342
- # lost.
343
- def self.turn_end_data?(data)
344
- Array(data["images"]).any? || Delivery.queue?(data["delivery"]) || Steer.participant_author?(data["author"]) ||
345
- TurnAnchors.named_in?(data)
345
+ # lost. Without +running_author+ (the owner's turn, or none named) a
346
+ # participant's file waits, as before.
347
+ def self.turn_end_data?(data, running_author: nil)
348
+ return true if Array(data["images"]).any? || Delivery.queue?(data["delivery"]) || TurnAnchors.named_in?(data)
349
+
350
+ author = Steer.sender_author(data["author"])
351
+ running_author ? author != running_author : Steer.participant_author?(data["author"])
346
352
  end
347
353
 
348
354
  # Whether a message waits that a running turn's next boundary merges and
@@ -352,11 +358,13 @@ module Samagotchi
352
358
  # ends on it (Worker#input_waiting?). It only peeks: nothing is claimed;
353
359
  # a file the drain or a dequeue claims meanwhile (ENOENT) or one that
354
360
  # doesn't parse is skipped.
355
- def self.steer_waiting?(session_dir)
361
+ # In a participant's turn (+running_author+) only their own message
362
+ # counts.
363
+ def self.steer_waiting?(session_dir, running_author: nil)
356
364
  find_new_input_files(session_dir).any? do |file|
357
365
  data = JSON.parse(File.read(file))
358
- data.is_a?(Hash) && !turn_end_data?(data) && !data["prompt"].to_s.strip.empty? &&
359
- Steer.cuts?(Steer.source_for_client(data["client_id"]))
366
+ data.is_a?(Hash) && !turn_end_data?(data, running_author: running_author) && !data["prompt"].to_s.strip.empty? &&
367
+ (running_author || Steer.cuts?(Steer.source_for_client(data["client_id"])))
360
368
  rescue JSON::ParserError, SystemCallError
361
369
  false
362
370
  end