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
@@ -55,7 +55,6 @@ require_relative "../system_one/client"
55
55
  require_relative "../turn_flow"
56
56
  require_relative "../session_chain"
57
57
  require_relative "../session_access"
58
- require_relative "../review_start"
59
58
  require_relative "../parent_answers_command"
60
59
  require_relative "../guardrails/parent_policy"
61
60
  require_relative "markdown_renderer"
@@ -69,15 +68,19 @@ require_relative "session_hub"
69
68
  require_relative "project_list"
70
69
  require_relative "session_access_routes"
71
70
  require_relative "principal"
71
+ require_relative "viewer"
72
72
  require_relative "participant_access"
73
+ require_relative "participant_images"
73
74
  require_relative "participants_admin"
74
75
  require_relative "participant_review"
76
+ require_relative "participant_show"
75
77
  require_relative "message_display"
76
78
  require_relative "session_show"
77
79
  require_relative "session_create"
78
80
  require_relative "session_control"
79
81
  require_relative "verify_fresh_routes"
80
82
  require_relative "reload_check_route"
83
+ require_relative "working_set_routes"
81
84
  require_relative "push_routes"
82
85
  require_relative "block_renderer_routes"
83
86
  require_relative "update_check"
@@ -105,14 +108,17 @@ module Samagotchi
105
108
  include RedactedInspect
106
109
  include SessionAccessRoutes
107
110
  include ParticipantAccess
111
+ include ParticipantImages
108
112
  include ParticipantsAdmin
109
113
  include ParticipantReview
114
+ include ParticipantShow
110
115
  include MessageDisplay
111
116
  include SessionShow
112
117
  include SessionCreate
113
118
  include SessionControl
114
119
  include VerifyFreshRoutes
115
120
  include ReloadCheckRoute
121
+ include WorkingSetRoutes
116
122
  include PushRoutes
117
123
  include BlockRendererRoutes
118
124
  include ProxyGate
@@ -223,6 +229,7 @@ module Samagotchi
223
229
  @update_ops = update_ops || UpdateOps.new(hub: hub, manager: @manager, state_dir: state_dir,
224
230
  runner: update_runner, blocked: update_blocked)
225
231
  init_participant_access(grants, state_dir)
232
+ init_participant_images
226
233
  init_proxy_gate(public_url, public_token)
227
234
  end
228
235
 
@@ -283,9 +290,8 @@ module Samagotchi
283
290
  ["POST", %r{\A/api/update/restart_web\z}, :handle_restart_web, :owner],
284
291
  ["POST", %r{\A/api/render\z}, :handle_render, :owner],
285
292
  ["GET", %r{\A/api/sessions/([^/]+)/stream\z}, :handle_stream, :participant],
286
- ["GET", %r{\A/api/sessions/([^/]+)/review\z}, :handle_review, :participant, :session],
287
293
  ["GET", %r{\A/api/sessions/([^/]+)/output\z}, :handle_output, :owner, :session],
288
- ["POST", %r{\A/api/sessions/([^/]+)/cancel\z}, :handle_cancel, :owner, :session],
294
+ ["POST", %r{\A/api/sessions/([^/]+)/cancel\z}, :handle_cancel, :participant, :session],
289
295
  ["POST", %r{\A/api/sessions/([^/]+)/tasks/([^/]+)/stop\z}, :handle_task_stop, :owner, :session],
290
296
  ["POST", %r{\A/api/sessions/([^/]+)/turn/([^/]+)/dequeue\z}, :handle_dequeue_turn, :participant, :session],
291
297
  ["POST", %r{\A/api/sessions/([^/]+)/stop\z}, :handle_stop, :owner, :session],
@@ -311,19 +317,19 @@ module Samagotchi
311
317
  ["POST", %r{\A/api/sessions/([^/]+)/answer\z}, :handle_question_answer, :owner],
312
318
  ["POST", %r{\A/api/sessions/([^/]+)/question/dismiss\z}, :handle_question_dismiss, :owner],
313
319
  ["POST", %r{\A/api/sessions/([^/]+)/command\z}, :handle_command, :owner, :session],
314
- ["POST", %r{\A/api/sessions/([^/]+)/images\z}, :handle_image_upload, :owner],
315
- ["GET", %r{\A/api/sessions/([^/]+)/images/([^/]+)\z}, :handle_image, :owner],
320
+ ["POST", %r{\A/api/sessions/([^/]+)/images\z}, :handle_image_upload, :participant, :session],
321
+ ["GET", %r{\A/api/sessions/([^/]+)/images/([^/]+)\z}, :handle_image, :participant, :session],
316
322
  ["GET", %r{\A/api/sessions/([^/]+)/context\z}, :handle_context_list, :owner, :session],
317
323
  ["GET", %r{\A/api/sessions/([^/]+)/context/([^/]+)\z}, :handle_context_show, :owner, :session],
318
324
  ["POST", %r{\A/api/sessions/([^/]+)/context\z}, :handle_context_add, :owner, :session],
319
325
  ["POST", %r{\A/api/sessions/([^/]+)/context/([^/]+)/push\z}, :handle_context_push, :owner, :session],
320
326
  ["DELETE", %r{\A/api/sessions/([^/]+)/context/([^/]+)\z}, :handle_context_delete, :owner, :session],
321
- ["GET", %r{\A/api/sessions/([^/]+)/working_set\z}, :handle_working_set, :owner, :session],
327
+ ["GET", %r{\A/api/sessions/([^/]+)/working_set\z}, :handle_working_set, :participant, :session],
328
+ ["GET", %r{\A/api/sessions/([^/]+)/working_set/item\z}, :handle_working_set_item, :owner, :session],
322
329
  ["GET", %r{\A/api/sessions/([^/]+)/participants\z}, :handle_participants_list, :owner, :session],
323
330
  ["POST", %r{\A/api/sessions/([^/]+)/participants\z}, :handle_participants_invite, :owner, :session],
324
331
  ["DELETE", %r{\A/api/sessions/([^/]+)/participants\z}, :handle_participants_revoke, :owner, :session],
325
332
  ["POST", %r{\A/api/sessions/([^/]+)/participants/([^/]+)/cap\z}, :handle_participants_cap, :owner, :session],
326
- ["GET", %r{\A/api/sessions/([^/]+)/apply\z}, :handle_apply, :owner, :session],
327
333
  ["GET", %r{\A/api/participants\z}, :handle_participants_list, :owner],
328
334
  ["DELETE", %r{\A/api/participants\z}, :handle_participants_revoke, :owner],
329
335
  ["GET", %r{\A/api/push\z}, :handle_push_info, :owner],
@@ -1146,9 +1152,9 @@ module Samagotchi
1146
1152
  json_response(200, payload)
1147
1153
  end
1148
1154
 
1149
- # Kits the web never offers: the participants' boundary, a delegate
1150
- # child's, and ToolkitSuggest's defer sentinel.
1151
- PICKER_HIDDEN_KITS = [Toolkit::REVIEW, Toolkit::CHILD, ToolkitSuggest::UNDECIDED].freeze
1155
+ # Kits the web never offers: a delegate child's, and ToolkitSuggest's
1156
+ # defer sentinel.
1157
+ PICKER_HIDDEN_KITS = [Toolkit::CHILD, ToolkitSuggest::UNDECIDED].freeze
1152
1158
 
1153
1159
  # The start page's toolkit picker: {default:, suggest:, kits: [{name,
1154
1160
  # description?}]}. Built-in and config kits only (a bundle's load in
@@ -1387,69 +1393,6 @@ module Samagotchi
1387
1393
  end
1388
1394
  end
1389
1395
 
1390
- # ── The working set (web.working_set) ───────────────────────────────
1391
-
1392
- # GET /api/sessions/:id/working_set: the working set as the model has
1393
- # it ({items:, at:, running:}, WorkingSet), what the page overlays on its rows'
1394
- # set when it seeds a session's and when the expanded view opens (a
1395
- # file changed while the session sat idle). A live worker's snapshot
1396
- # messages are the truth, as #handle_show's, else the file's; the
1397
- # strategy is the session's llm_context summary's, the folder its working
1398
- # directory. running: a turn runs. The snapshot's messages lag it, so
1399
- # the answer is then the turn's last :working_set_updated (the
1400
- # snapshot's working_set, TurnAccumulator#working_set); before the
1401
- # turn emitted one, or from an older worker without the field, it is
1402
- # the session's messages, behind that turn's events, and the page
1403
- # keeps theirs (working_set.js newerSnapshot).
1404
- def handle_working_set(_req, id)
1405
- session = @session_class.load(id, state_dir: default_state_dir)
1406
- live = bridge_get_json(id, "snapshot")
1407
- worker_snapshot = live && live["snapshot"]
1408
- running = !worker_snapshot&.dig("current_turn").nil?
1409
- turn_set = running && running_working_set(live["snapshot"]["working_set"])
1410
- return json_response(200, turn_set.merge(running: true)) if turn_set
1411
-
1412
- idle_set = idle_working_set(worker_snapshot && worker_snapshot["idle_working_set"]) unless running
1413
- return json_response(200, idle_set.merge(running: false)) if idle_set
1414
-
1415
- messages = live_or_saved(worker_snapshot, "messages") { session.messages }
1416
- # A snapshot's entries have string keys (paired_runs reads symbols).
1417
- messages = Array(messages).map { |message| message.is_a?(Hash) ? message.transform_keys(&:to_sym) : message }
1418
- llm_context = SessionSetting::LLM_CONTEXT.snapshot_value(live && live["session_state_snapshot"]) do
1419
- SessionSetting::LLM_CONTEXT.saved_summary(session, registry: host_registry)
1420
- end
1421
- snapshot = WorkingSet.build(messages, cwd: session.working_directory, strategy: working_set_strategy(llm_context),
1422
- pins: session.working_set_pins)
1423
- json_response(200, snapshot.to_h.merge(running: running))
1424
- end
1425
-
1426
- # The running turn's set from a worker's snapshot ({"items", "at"}), as
1427
- # {items:, at:}; nil when it has none (none emitted yet, an older worker).
1428
- def running_working_set(set)
1429
- return nil unless set.is_a?(Hash) && set["items"].is_a?(Array) && set["at"].is_a?(Integer)
1430
-
1431
- { items: set["items"], at: set["at"] }
1432
- end
1433
-
1434
- # The worker's between-turns working set ({"items", "at", optional
1435
- # "adds"}); nil for an older or malformed snapshot.
1436
- def idle_working_set(set)
1437
- return nil unless set.is_a?(Hash) && set["items"].is_a?(Array) && set["at"].is_a?(Integer)
1438
- return nil if set.key?("adds") && !set["adds"].is_a?(Array)
1439
-
1440
- { items: set["items"], at: set["at"] }.tap do |snapshot|
1441
- snapshot[:adds] = set["adds"] if set.key?("adds")
1442
- end
1443
- end
1444
-
1445
- # The strategy an llm_context summary names ("none", "stale,forget"), as
1446
- # LLMContextView takes it; none when there is no chip.
1447
- def working_set_strategy(llm_context)
1448
- named = llm_context.is_a?(Hash) ? (llm_context[:strategy] || llm_context["strategy"]).to_s : ""
1449
- layers = named.split(",").map(&:strip).reject { |layer| layer.empty? || layer == "none" }
1450
- layers.empty? ? LLMContextView::NONE : layers.map(&:to_sym)
1451
- end
1452
-
1453
1396
  # ── Attached context (ContextSources): the session bar's chips ───────
1454
1397
  # A source's command isn't shown (the page may be on a phone over the
1455
1398
  # LAN), and the web adds a URL only, through an installed bundle's
@@ -1679,9 +1622,8 @@ module Samagotchi
1679
1622
  end
1680
1623
 
1681
1624
  # What a request's stream goes through on its way from the Bridge:
1682
- # nil, the raw bytes unchanged, for the owner; a participant's (and
1683
- # the owner's ?as=participant, the participant view) goes through
1684
- # ParticipantStreamFilter. A filter is anything with #call(chunk) ->
1625
+ # nil, the raw bytes unchanged, for the owner; a participant's goes
1626
+ # through ParticipantStreamFilter. A filter is anything with #call(chunk) ->
1685
1627
  # String (nil or "" sends nothing); see ProxyStreamBody.
1686
1628
  def stream_filter(req, id)
1687
1629
  return nil unless participant_view?(req)
@@ -1839,8 +1781,6 @@ module Samagotchi
1839
1781
  end
1840
1782
 
1841
1783
  def serve_index(req)
1842
- return participant_shell(req) if participant_view?(req)
1843
-
1844
1784
  path = File.join(@public_dir, "index.html")
1845
1785
  if File.file?(path)
1846
1786
  # A block: a preset's \& or \' is text, never a backreference.
@@ -1956,17 +1896,21 @@ module Samagotchi
1956
1896
  # #code= and the app's start_url "/" all land there). ?dir= beats
1957
1897
  # ?scope=all.
1958
1898
  def index_data_attributes(req)
1899
+ return participant_index_data(req) unless principal(req).owner?
1900
+
1959
1901
  # version: the chi that served the page; the events snapshot names
1960
1902
  # the one serving now (an upgraded chi web after a reconnect).
1961
1903
  attrs = { "sessions-dir" => sessions_dir_label, "server-dir" => home_label(start_dir), "version" => Samagotchi::VERSION }
1962
- # The owner's home: a claim link's quote reads it "~", as the
1963
- # participant page shows it (claim_link.js).
1904
+ # The owner's home: a claim link's quote reads it "~", as a
1905
+ # participant's page shows it (claim_link.js).
1964
1906
  attrs["home"] = Dir.home
1965
1907
  # Only when on: the page reads its presence.
1966
1908
  attrs["working-set"] = "1" if working_set?(req.params["working_set"])
1967
1909
  # The opt-in reload check (reload_check.js): only when on.
1968
1910
  attrs["reload-check"] = "1" if @reload_check
1969
1911
  attrs.merge!(annotate_presets_data)
1912
+ # Who looks and what they may do (Viewer; viewer.js reads it at boot).
1913
+ attrs.merge!(Viewer.for(principal(req)).body_attributes)
1970
1914
  dir, = scope_dir(req.params["dir"])
1971
1915
  unless dir
1972
1916
  dir = default_scope_dir(req)
@@ -1989,11 +1933,30 @@ module Samagotchi
1989
1933
  body_data(attrs)
1990
1934
  end
1991
1935
 
1936
+ # A participant's <body> data for index.html: who they are (Viewer), their
1937
+ # grant's session and its participant title (the tab's), the version
1938
+ # and the Annotate presets, and whether the working set is on
1939
+ # (web.working_set: their stage's file column, as the owner's).
1940
+ # Nothing of the owner's machine: no home, folders, project or way
1941
+ # back (sessions-dir, server-dir, home, scope-dir, project-*, back-*).
1942
+ def participant_index_data(req)
1943
+ grant = principal(req).grant
1944
+ attrs = { "version" => Samagotchi::VERSION, "session" => grant.session_id }
1945
+ attrs["working-set"] = "1" if working_set?(req.params["working_set"])
1946
+ title = Degrade.call(:web, "participant_title_unreadable", fallback: nil) do
1947
+ participant_title(@session_class.load(grant.session_id, state_dir: default_state_dir))
1948
+ end
1949
+ attrs["session-title"] = title if title
1950
+ attrs.merge!(annotate_presets_data)
1951
+ attrs.merge!(Viewer.for(principal(req)).body_attributes)
1952
+ body_data(attrs)
1953
+ end
1954
+
1992
1955
  # +attrs+ as <body> data attributes, each value escaped.
1993
1956
  def body_data(attrs) = attrs.map { |key, value| %(data-#{key}="#{Rack::Utils.escape_html(value)}") }.join(" ")
1994
1957
 
1995
- # The Annotate presets (web.annotate_presets) for a page's <body>, the
1996
- # owner's and the participant page's. Always there: an empty one means
1958
+ # The Annotate presets (web.annotate_presets) for the page's <body>,
1959
+ # the owner's and a participant's. Always there: an empty one means
1997
1960
  # no presets, not the default.
1998
1961
  def annotate_presets_data = { "annotate-presets" => @annotate_presets }
1999
1962
 
@@ -11,17 +11,21 @@ require_relative "../session_inbox"
11
11
  require_relative "../session_metrics"
12
12
  require_relative "../parent_report"
13
13
  require_relative "../participant_messages"
14
+ require_relative "../worker_link"
15
+ require_relative "../participant_revise"
14
16
  require_relative "../participants"
15
17
  require_relative "../session"
16
18
  require_relative "../turn_checkpoint"
19
+ require_relative "../turn_origin"
17
20
  require_relative "../verify_fresh"
18
21
  require_relative "../log"
22
+ require_relative "proxy_gate"
19
23
 
20
24
  module Samagotchi
21
25
  module Web
22
26
  # What a participant (a Grants token) may do in chi web, mixed into
23
27
  # App: the gate's lookup of their grant, the refusals that are theirs
24
- # (token_revoked, token_expired with its ended page, token_bound for a
28
+ # (token_revoked, token_expired, token_outdated with its ended page, token_bound for a
25
29
  # link bound to another account, another session's
26
30
  # 404, not_permitted by role), the trimmed answers of their own routes
27
31
  # (info, the session, resolve, a wait on their turn), their turns, and
@@ -41,7 +45,8 @@ module Samagotchi
41
45
 
42
46
  ENDED = {
43
47
  revoked: ["token_revoked", ParticipantMessages::TOKEN_REVOKED],
44
- expired: ["token_expired", ParticipantMessages::TOKEN_EXPIRED]
48
+ expired: ["token_expired", ParticipantMessages::TOKEN_EXPIRED],
49
+ outdated: ["token_outdated", ParticipantMessages::TOKEN_OUTDATED]
45
50
  }.freeze
46
51
  NOT_PERMITTED = ParticipantMessages::NOT_PERMITTED
47
52
 
@@ -136,7 +141,7 @@ module Samagotchi
136
141
  grant.with(revoked_at: @grants.now.utc.iso8601, revoked_by: by)
137
142
  end
138
143
 
139
- # 401 token_revoked / token_expired for an ended grant's token (the
144
+ # 401 token_revoked / token_expired / token_outdated for an ended grant's token (the
140
145
  # page's HTML says the same words), nil when none was presented.
141
146
  def grant_ended_response(req)
142
147
  grant, state = req.env[ENDED_GRANT_ENV]
@@ -237,13 +242,7 @@ module Samagotchi
237
242
  # first prompt's opening words: the conversation).
238
243
  def participant_title(session)
239
244
  title = session.title.to_s.strip
240
- return title unless title.empty?
241
-
242
- # A review session's subjects are what participants read anyway.
243
- subjects = session.review&.subjects || []
244
- return UNTITLED if subjects.empty?
245
-
246
- "review of #{subjects.first}#{" +#{subjects.size - 1}" if subjects.size > 1}"
245
+ title.empty? ? UNTITLED : title
247
246
  end
248
247
 
249
248
  UNTITLED = "an untitled session"
@@ -251,35 +250,97 @@ module Samagotchi
251
250
  def participant_names(id)
252
251
  now = @grants.now
253
252
  Participants.read(id, state_dir: default_state_dir).select { |entry| entry.active?(now) }
254
- .map { |entry| { id: entry.id, name: entry.name, kind: entry.kind, role: entry.role } }
253
+ .map { |entry| { id: entry.id, name: entry.name, role: entry.role } }
254
+ end
255
+
256
+ # POST …/cancel from a participant: only their own running turn, named
257
+ # by its turn_id. The live snapshot's turn must be that turn and
258
+ # theirs (its author is the grant's), and the worker is asked to
259
+ # cancel that turn id (TurnState#cancel! compares it under its lock,
260
+ # 409 turn_mismatch): a turn that ended and gave way to another
261
+ # person's between the read and the cancel is never stopped. No
262
+ # turn_id (the Bridge would cancel whatever runs), or a turn that
263
+ # isn't theirs: 403 not_permitted, audited. The reason is the
264
+ # server's, never the body's.
265
+ def participant_cancel(req, id)
266
+ parsed = parse_json(request_body(req))
267
+ turn_id = (parsed["turn_id"] if parsed.is_a?(Hash)).to_s.strip
268
+ return not_permitted_for(req, principal(req)) if turn_id.empty?
269
+
270
+ live = bridge_get_json(id, "snapshot")
271
+ return not_live(id) unless live.is_a?(Hash)
272
+
273
+ turn = live.dig("snapshot", "current_turn")
274
+ return json_response(409, { error: "not_running", detail: "no active turn to cancel", session_id: id }) unless turn.is_a?(Hash)
275
+ return not_permitted_for(req, principal(req)) unless own_running_turn?(principal(req).grant, turn, turn_id)
276
+ return cancel_unavailable(req) unless cancels_by_turn_id?(id)
277
+
278
+ relay_cancel(id, ->(client) { client.cancel(reason: PARTICIPANT_CANCEL_REASON, turn_id: turn_id) })
279
+ end
280
+
281
+ # Whether the session's live worker cancels only the turn_id it is
282
+ # named (Delivery::CANCEL_TURN_ID_FEATURE): an older one ignores it and
283
+ # would stop whatever runs, the owner's next turn too.
284
+ def cancels_by_turn_id?(id)
285
+ session = @session_class.load(id, state_dir: default_state_dir)
286
+ Array(WorkerLink.live_features(session.id, state_dir: default_state_dir)).include?(Delivery::CANCEL_TURN_ID_FEATURE)
287
+ end
288
+
289
+ # 409 cancel_unavailable, audited; nothing is relayed.
290
+ def cancel_unavailable(req)
291
+ audit_refused(req, principal(req).grant, reason: "cancel_unavailable")
292
+ error_response(409, "cancel_unavailable", ParticipantMessages::CANCEL_UNAVAILABLE)
293
+ end
294
+
295
+ # Bridge::CANCEL_REASONS' "user": the person who sent it stopped it.
296
+ PARTICIPANT_CANCEL_REASON = "user"
297
+
298
+ # Whether the snapshot's running +turn+ is +turn_id+ and +grant+'s.
299
+ def own_running_turn?(grant, turn, turn_id)
300
+ author = turn["author"] || TurnOrigin.from(turn["origin"])&.author
301
+ turn["turn_id"].to_s == turn_id && author.to_s == grant.author
255
302
  end
256
303
 
257
304
  # ── A participant's turn ──────────────────────────────────────────
258
305
 
259
- # POST /api/sessions/:id/turn from a participant: a review turn (D6,
260
- # D10). Of the body only the prompt counts: the author and client id
261
- # are the grant's (review:<id>), the delivery is always queue, no
262
- # images, no no_interrupt; the owner's prompt history never sees it.
263
- # Refused: a line starting ! or / (403 not_permitted: shell lines
264
- # and commands are the owner's), images (403), their turn limit (429
265
- # too_many_turns, the Bridge counts) and their cap (429 cap_reached).
306
+ # POST /api/sessions/:id/turn from a participant: their turn (D6,
307
+ # D10). Of the body only the prompt, the delivery and images they
308
+ # uploaded count: the author and client id are the grant's
309
+ # (participant:<id>), no no_interrupt; the owner's prompt history never
310
+ # sees it. The delivery
311
+ # is queue or next step (none: next step): the worker puts a next-step
312
+ # message into a running turn only when that turn is theirs, else it
313
+ # runs as their own turn after it (Bridge#same_author_steer?; an older
314
+ # worker queues it). Refused: a line starting ! or / (403
315
+ # not_permitted: shell lines and commands are the owner's), a cut
316
+ # (403: theirs never cuts), their cap (429 cap_reached), images not
317
+ # theirs or a model without vision (ParticipantImages#
318
+ # participant_images_refusal) and their turn limit (429
319
+ # too_many_turns, the Bridge counts).
266
320
  # Every answer is audited (turn: accepted or refused, why).
267
321
  def handle_participant_turn(req, id, body)
268
322
  grant = principal(req).grant
269
323
  prompt = body["prompt"].to_s
270
324
  return error_response(400, "missing_fields", "prompt is required") if prompt.strip.empty?
271
325
 
272
- reason = participant_turn_refusal(grant, prompt, body)
273
- return participant_turn_refused(grant, prompt, *reason) if reason
326
+ anchors = TurnAnchors.from(body)
327
+ revises = anchors.revises&.turn_id
328
+ reason = participant_turn_refusal(grant, prompt, body) || participant_revise_refusal(grant, id, anchors)
329
+ return participant_turn_refused(grant, prompt, *reason, revises: revises) if reason
330
+
331
+ reason, images = participant_images_refusal(grant, id, body["images"])
332
+ return participant_turn_refused(grant, prompt, *reason, revises: revises) if reason
274
333
 
275
- # A Verify turn's claim; never a Revise (the owner's stacks).
276
- result = SessionManager.deliver_turn(id, prompt: prompt, client_id: ClientId.review(grant.id),
277
- delivery: Delivery::QUEUE, author: grant.author,
278
- anchors: TurnAnchors.from(body).without_revises,
334
+ # A Verify turn's claim, a Revise turn's draft of their own answer.
335
+ delivery = Delivery.queue?(body["delivery"]) ? Delivery::QUEUE : Delivery::NEXT_STEP
336
+ result = SessionManager.deliver_turn(id, prompt: prompt, client_id: ClientId.participant(grant.id),
337
+ delivery: delivery, author: grant.author,
338
+ **(images.empty? ? {} : { images: images }),
339
+ anchors: anchors,
279
340
  pending_limit: grant.queue_limit + 1,
280
341
  state_dir: @state_dir, manager: @manager,
281
342
  bridge: -> { live_bridge_client(id) })
282
- participant_turn_result(grant, prompt, result)
343
+ participant_turn_result(grant, prompt, result, images: images.empty? ? nil : images.size, revises: revises)
283
344
  rescue SessionManager::OwnedByTUI => e
284
345
  owned_by_tui(e)
285
346
  end
@@ -287,11 +348,35 @@ module Samagotchi
287
348
  # [status, code, detail] for a turn refused before delivery, nil to send it.
288
349
  def participant_turn_refusal(grant, prompt, body)
289
350
  return [403, "not_permitted", NOT_PERMITTED] if prompt.lstrip.start_with?("!", "/")
290
- return [403, "not_permitted", NOT_PERMITTED] unless body["images"].nil? || body["images"] == []
351
+ return [403, "not_permitted", NOT_PERMITTED] if Delivery.cut?(body["delivery"])
291
352
 
292
353
  participant_cap_refusal(grant)
293
354
  end
294
355
 
356
+ # [status, code, detail] for a Revise draft (+anchors+' revises) they
357
+ # may not send, nil without one or when they may: a live worker
358
+ # without ReviseAnchor::PARTICIPANT_FEATURE (409 revise_unavailable:
359
+ # it wouldn't check it at the stamp), then ParticipantRevise over the
360
+ # messages a live worker's snapshot has (the session file lags it
361
+ # mid-turn and just after a turn's end), the file's only with no
362
+ # live worker: 403 revise_not_own (a missing turn answers the same),
363
+ # 409 revise_overtaken. The worker checks again at the stamp.
364
+ def participant_revise_refusal(grant, id, anchors)
365
+ return nil unless anchors.revises
366
+
367
+ session = @session_class.load(id, state_dir: default_state_dir)
368
+ features = WorkerLink.live_features(session.id, state_dir: default_state_dir)
369
+ if features && !features.include?(ReviseAnchor::PARTICIPANT_FEATURE)
370
+ return [409, "revise_unavailable", ParticipantMessages::REVISE_UNAVAILABLE]
371
+ end
372
+
373
+ messages = show_reads(id, session).raw_messages
374
+ case ParticipantRevise.refusal(messages, turn_id: anchors.revises.turn_id, author: grant.author)
375
+ when :not_own then [403, "revise_not_own", ParticipantMessages::REVISE_NOT_OWN]
376
+ when :overtaken then [409, "revise_overtaken", ParticipantMessages::REVISE_OVERTAKEN]
377
+ end
378
+ end
379
+
295
380
  # [429, cap_reached, …] once the grant spent its cap (D7: their turns
296
381
  # and the side requests they caused, from the session's saved
297
382
  # analytics, and their Verify fresh children's; a running turn's
@@ -311,23 +396,36 @@ module Samagotchi
311
396
  VerifyFresh.children_spend(grant.session_id, grant.author, state_dir: default_state_dir)
312
397
  end
313
398
 
314
- def participant_turn_refused(grant, prompt, status, code, detail)
315
- audit_turn(grant, prompt, status: "refused", reason: code)
399
+ # +audit_detail+: what only the audit line says (no_vision's full
400
+ # words); +revises+: the turn id a Revise draft named (nil: none).
401
+ def participant_turn_refused(grant, prompt, status, code, detail, audit_detail = nil, revises: nil)
402
+ audit_turn(grant, prompt, status: "refused", reason: code, detail: audit_detail, revises: revises)
316
403
  error_response(status, code, detail)
317
404
  end
318
405
 
319
- def participant_turn_result(grant, prompt, result)
406
+ # +images+: how many the turn carried (nil: none), +revises+ the turn
407
+ # id its Revise draft named, for the audit line.
408
+ def participant_turn_result(grant, prompt, result, images: nil, revises: nil)
320
409
  case result.status
321
410
  when :accepted
322
411
  enqueued_id = result.ack["enqueued_id"]
323
412
  remember_participant_turn(enqueued_id, grant.id)
324
- audit_turn(grant, prompt, status: "accepted", enqueued_id: enqueued_id)
325
- json_response(202, result.ack.merge("via" => result.via.to_s, "delivery" => Delivery::QUEUE))
413
+ audit_turn(grant, prompt, status: "accepted", enqueued_id: enqueued_id, images: images, revises: revises)
414
+ # What the worker says will happen (a turn of its own, or into
415
+ # their running turn at its next step); a file (no worker yet)
416
+ # runs as the next turn, which reads as a queue.
417
+ json_response(202, result.ack.merge("via" => result.via.to_s, "delivery" => result.ack["delivery"] || Delivery::QUEUE))
326
418
  when :refused
327
- audit_turn(grant, prompt, status: "refused", reason: result.ack["error"])
419
+ audit_turn(grant, prompt, status: "refused", reason: result.ack["error"], images: images, revises: revises)
420
+ # A worker without Revise at all: the participant's words, never
421
+ # the owner's "restart this session".
422
+ if result.ack["error"] == ReviseAnchor::UNAVAILABLE["error"]
423
+ return error_response(409, "revise_unavailable", ParticipantMessages::REVISE_UNAVAILABLE)
424
+ end
425
+
328
426
  json_response(result.code, result.ack)
329
427
  when :timeout
330
- audit_turn(grant, prompt, status: "refused", reason: "worker_timeout")
428
+ audit_turn(grant, prompt, status: "refused", reason: "worker_timeout", images: images, revises: revises)
331
429
  error_response(504, "worker_timeout", result.detail)
332
430
  else error_response(500, "enqueue_failed", "could not write turn input")
333
431
  end
@@ -416,17 +514,18 @@ module Samagotchi
416
514
  # answer trimmed to what their turn's reply is (status, text, turn
417
515
  # id, a cancel's reason): no file path, no question (an approval or a
418
516
  # question their turn raised is the owner's to answer: the status
419
- # says waiting_for_owner), no origin, no parent strategy. It waits as
420
- # for a queued turn (theirs always is: never merged), so it never
421
- # falls back to the next reply past a cursor, which would be anyone's;
422
- # the body's cursor doesn't count. A revoke or the expiry ends a wait
517
+ # says waiting_for_owner), no origin, no parent strategy. It waits on
518
+ # their turn's id, so it never falls back to the next reply past a
519
+ # cursor, which would be anyone's (the body's cursor doesn't count);
520
+ # a message merged into their own running turn is followed into it by
521
+ # its merge record (ReplyWait::Poll#follow_merge), a turn of theirs. A revoke or the expiry ends a wait
423
522
  # already running (the gate checked the grant when it began): 401
424
523
  # token_revoked / token_expired, as their next request would get.
425
524
  def participant_wait(req, id, options)
426
525
  grant = principal(req).grant
427
526
  return not_permitted_for(req, principal(req)) unless own_turn?(grant, id, options[:turn])
428
527
 
429
- options = options.merge(queued: true, cursor: nil)
528
+ options = options.merge(queued: false, cursor: nil)
430
529
  session = session_access.show(id)
431
530
  result = session_access.wait_reply(id, **options, poll_interval: @wait_poll_interval,
432
531
  cancelled: -> { !@server_running.call || !@grants.active?(grant.id) })
@@ -486,7 +585,7 @@ module Samagotchi
486
585
  <!doctype html>
487
586
  <html lang="en"><head><meta charset="utf-8">
488
587
  <meta name="viewport" content="width=device-width, initial-scale=1">
489
- <title>chi: review link ended</title>
588
+ <title>chi: link ended</title>
490
589
  <style>#{PAGE_STYLE}</style></head>
491
590
  <body>
492
591
  <h1>chi</h1>
@@ -508,7 +607,7 @@ module Samagotchi
508
607
  </script>
509
608
  </body></html>
510
609
  HTML
511
- BOUND_PAGE = ENDED_PAGE.sub("<title>chi: review link ended</title>", "<title>chi: review link for another account</title>")
610
+ BOUND_PAGE = ENDED_PAGE.sub("<title>chi: link ended</title>", "<title>chi: link for another account</title>")
512
611
  end
513
612
  end
514
613
  end