samagotchi 0.171.0 → 0.172.1

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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -1
  3. data/bin/chi +6 -4
  4. data/docs/architecture.md +24 -7
  5. data/docs/bundles.md +4 -21
  6. data/docs/cli.md +50 -80
  7. data/docs/configuration.md +11 -13
  8. data/docs/context.md +5 -6
  9. data/docs/guardrails.md +57 -96
  10. data/docs/hooks.md +3 -4
  11. data/docs/internals/attached-context.md +6 -7
  12. data/docs/internals/background-tasks.md +4 -3
  13. data/docs/internals/bridge.md +29 -3
  14. data/docs/internals/engine.md +21 -9
  15. data/docs/internals/objectives.md +3 -5
  16. data/docs/internals/participants.md +118 -143
  17. data/docs/internals/prompt-caching.md +4 -5
  18. data/docs/internals/web-frontend.md +70 -27
  19. data/docs/internals/working-set.md +7 -5
  20. data/docs/memory.md +1 -1
  21. data/docs/plugins.md +2 -16
  22. data/docs/scheduling.md +1 -1
  23. data/docs/sessions.md +15 -49
  24. data/docs/sub-agent.md +2 -2
  25. data/docs/system-one.md +2 -2
  26. data/docs/testing.md +81 -8
  27. data/lib/samagotchi/bridge/card_store.rb +1 -0
  28. data/lib/samagotchi/bridge/sse_writer.rb +1 -0
  29. data/lib/samagotchi/bridge/turn_accumulator.rb +0 -1
  30. data/lib/samagotchi/bridge.rb +26 -9
  31. data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
  32. data/lib/samagotchi/bundle_command/test_run.rb +1 -0
  33. data/lib/samagotchi/bundle_command/try/run.rb +1 -0
  34. data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
  35. data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
  36. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
  37. data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
  38. data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
  39. data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
  40. data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
  41. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  42. data/lib/samagotchi/client_id.rb +126 -67
  43. data/lib/samagotchi/command_intake.rb +15 -3
  44. data/lib/samagotchi/compat.rb +6 -1
  45. data/lib/samagotchi/context_candidate_choice.rb +1 -3
  46. data/lib/samagotchi/context_candidates.rb +3 -4
  47. data/lib/samagotchi/continue_offer.rb +9 -2
  48. data/lib/samagotchi/delivery.rb +23 -12
  49. data/lib/samagotchi/empty_answer_error.rb +5 -0
  50. data/lib/samagotchi/engine/cards.rb +3 -0
  51. data/lib/samagotchi/engine/context_judge.rb +5 -3
  52. data/lib/samagotchi/engine/events.rb +4 -0
  53. data/lib/samagotchi/engine/hooks.rb +3 -0
  54. data/lib/samagotchi/engine/messages.rb +5 -0
  55. data/lib/samagotchi/engine/model_settings.rb +2 -0
  56. data/lib/samagotchi/engine/models.rb +10 -0
  57. data/lib/samagotchi/engine/objectives.rb +6 -0
  58. data/lib/samagotchi/engine/participants.rb +18 -14
  59. data/lib/samagotchi/engine/plugins.rb +8 -0
  60. data/lib/samagotchi/engine/questions.rb +3 -0
  61. data/lib/samagotchi/engine/recap.rb +1 -0
  62. data/lib/samagotchi/engine/session.rb +4 -0
  63. data/lib/samagotchi/engine/side_requests.rb +9 -0
  64. data/lib/samagotchi/engine/steering.rb +2 -0
  65. data/lib/samagotchi/engine/toolkit.rb +5 -0
  66. data/lib/samagotchi/engine/turn_end.rb +7 -0
  67. data/lib/samagotchi/engine/turn_helpers.rb +8 -0
  68. data/lib/samagotchi/engine/verify.rb +2 -0
  69. data/lib/samagotchi/engine.rb +3 -2
  70. data/lib/samagotchi/grants.rb +28 -22
  71. data/lib/samagotchi/guardrail_wiring.rb +23 -18
  72. data/lib/samagotchi/guardrails/approval_use.rb +59 -0
  73. data/lib/samagotchi/guardrails/approvals.rb +9 -11
  74. data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
  75. data/lib/samagotchi/guardrails/gate.rb +10 -5
  76. data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
  77. data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
  78. data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
  79. data/lib/samagotchi/guardrails/review_paths.rb +2 -3
  80. data/lib/samagotchi/guardrails.rb +1 -1
  81. data/lib/samagotchi/llm_context_strategy.rb +2 -0
  82. data/lib/samagotchi/objectives.rb +1 -4
  83. data/lib/samagotchi/objectives_audit.rb +1 -1
  84. data/lib/samagotchi/objectives_track.rb +1 -1
  85. data/lib/samagotchi/owner_prompt.rb +3 -6
  86. data/lib/samagotchi/parent_report.rb +1 -0
  87. data/lib/samagotchi/participant_messages.rb +9 -4
  88. data/lib/samagotchi/participant_turn_mode.rb +50 -0
  89. data/lib/samagotchi/participants.rb +21 -12
  90. data/lib/samagotchi/participants_watch.rb +2 -2
  91. data/lib/samagotchi/plugin/api.rb +2 -2
  92. data/lib/samagotchi/plugin/attached_context.rb +1 -1
  93. data/lib/samagotchi/plugin/context.rb +0 -4
  94. data/lib/samagotchi/plugin/sessions.rb +1 -25
  95. data/lib/samagotchi/run_options.rb +2 -3
  96. data/lib/samagotchi/send_command.rb +10 -10
  97. data/lib/samagotchi/session.rb +0 -3
  98. data/lib/samagotchi/session_access/contract.rb +1 -10
  99. data/lib/samagotchi/session_access/local.rb +10 -23
  100. data/lib/samagotchi/session_access/remote.rb +9 -20
  101. data/lib/samagotchi/session_access.rb +12 -16
  102. data/lib/samagotchi/session_chain.rb +4 -6
  103. data/lib/samagotchi/session_commands.rb +6 -3
  104. data/lib/samagotchi/session_continue.rb +1 -2
  105. data/lib/samagotchi/session_manager/delivery.rb +25 -5
  106. data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
  107. data/lib/samagotchi/session_manager/listing.rb +5 -0
  108. data/lib/samagotchi/session_manager/spawn.rb +2 -2
  109. data/lib/samagotchi/session_manager/worker_command.rb +9 -0
  110. data/lib/samagotchi/session_participants.rb +12 -8
  111. data/lib/samagotchi/session_review.rb +5 -7
  112. data/lib/samagotchi/session_stores.rb +3 -3
  113. data/lib/samagotchi/share_command.rb +10 -12
  114. data/lib/samagotchi/share_terms.rb +41 -0
  115. data/lib/samagotchi/steer.rb +8 -14
  116. data/lib/samagotchi/system_prompt.rb +16 -25
  117. data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
  118. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
  119. data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
  120. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
  121. data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
  122. data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
  123. data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
  124. data/lib/samagotchi/terminal_ui.rb +1 -2
  125. data/lib/samagotchi/testing/sessions.rb +2 -10
  126. data/lib/samagotchi/tool_runner.rb +8 -9
  127. data/lib/samagotchi/toolkit.rb +4 -22
  128. data/lib/samagotchi/toolkit_suggest.rb +3 -3
  129. data/lib/samagotchi/tools/deferred_tools.rb +1 -0
  130. data/lib/samagotchi/tools/execute.rb +11 -45
  131. data/lib/samagotchi/tools/leftovers.rb +126 -0
  132. data/lib/samagotchi/tools/memory.rb +70 -26
  133. data/lib/samagotchi/tools/task_get.rb +1 -0
  134. data/lib/samagotchi/tools/task_list.rb +3 -2
  135. data/lib/samagotchi/tools/task_record.rb +6 -4
  136. data/lib/samagotchi/tools/task_runtime.rb +199 -20
  137. data/lib/samagotchi/tools/task_wait.rb +4 -3
  138. data/lib/samagotchi/turn_context.rb +1 -1
  139. data/lib/samagotchi/turn_origin.rb +1 -1
  140. data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
  141. data/lib/samagotchi/turn_stages/objectives.rb +2 -2
  142. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
  143. data/lib/samagotchi/update_hint.rb +3 -1
  144. data/lib/samagotchi/verify_fresh.rb +1 -1
  145. data/lib/samagotchi/verify_fresh_origin.rb +13 -11
  146. data/lib/samagotchi/version.rb +1 -1
  147. data/lib/samagotchi/web/app.rb +3 -5
  148. data/lib/samagotchi/web/participant_access.rb +14 -18
  149. data/lib/samagotchi/web/participant_review.rb +3 -4
  150. data/lib/samagotchi/web/participant_show.rb +4 -3
  151. data/lib/samagotchi/web/participant_view.rb +3 -3
  152. data/lib/samagotchi/web/participants_admin.rb +21 -40
  153. data/lib/samagotchi/web/public/app.js +7 -48
  154. data/lib/samagotchi/web/public/card_kinds.js +51 -0
  155. data/lib/samagotchi/web/public/cards_place.js +13 -2
  156. data/lib/samagotchi/web/public/data.js +2 -10
  157. data/lib/samagotchi/web/public/delivery_line.js +17 -60
  158. data/lib/samagotchi/web/public/index.html +10 -30
  159. data/lib/samagotchi/web/public/live_turn.js +1 -1
  160. data/lib/samagotchi/web/public/owner_claim.js +2 -2
  161. data/lib/samagotchi/web/public/participant_bar.js +4 -5
  162. data/lib/samagotchi/web/public/participant_names.js +14 -10
  163. data/lib/samagotchi/web/public/participants_panel.js +29 -62
  164. data/lib/samagotchi/web/public/question_cards.js +29 -14
  165. data/lib/samagotchi/web/public/reload_check.js +2 -3
  166. data/lib/samagotchi/web/public/send_turn.js +4 -23
  167. data/lib/samagotchi/web/public/session_actions.js +4 -45
  168. data/lib/samagotchi/web/public/session_fields.js +0 -1
  169. data/lib/samagotchi/web/public/session_state.js +0 -3
  170. data/lib/samagotchi/web/public/session_sync.js +4 -2
  171. data/lib/samagotchi/web/public/session_view.js +2 -3
  172. data/lib/samagotchi/web/public/settings_panel.js +4 -18
  173. data/lib/samagotchi/web/public/stage_answer.js +56 -0
  174. data/lib/samagotchi/web/public/stage_asking.js +30 -11
  175. data/lib/samagotchi/web/public/stage_cloud.js +93 -0
  176. data/lib/samagotchi/web/public/stage_dom.js +100 -0
  177. data/lib/samagotchi/web/public/stage_handoff.js +154 -0
  178. data/lib/samagotchi/web/public/stage_pager.js +59 -0
  179. data/lib/samagotchi/web/public/stage_place.js +144 -0
  180. data/lib/samagotchi/web/public/stage_probe.js +64 -0
  181. data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
  182. data/lib/samagotchi/web/public/stage_view.js +133 -506
  183. data/lib/samagotchi/web/public/stage_waiting.js +30 -13
  184. data/lib/samagotchi/web/public/start_page.js +12 -33
  185. data/lib/samagotchi/web/public/start_settings.js +24 -78
  186. data/lib/samagotchi/web/public/start_toolkit.js +6 -10
  187. data/lib/samagotchi/web/public/stream_handlers.js +1 -9
  188. data/lib/samagotchi/web/public/turn_block.js +3 -7
  189. data/lib/samagotchi/web/public/turn_events.js +15 -6
  190. data/lib/samagotchi/web/public/turn_pieces.js +3 -4
  191. data/lib/samagotchi/web/public/viewer_self.js +8 -2
  192. data/lib/samagotchi/web/qr.rb +1 -1
  193. data/lib/samagotchi/web/session_control.rb +3 -1
  194. data/lib/samagotchi/web/session_create.rb +5 -71
  195. data/lib/samagotchi/web/session_summary.rb +1 -4
  196. data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
  197. data/lib/samagotchi/web/viewer.rb +3 -3
  198. data/lib/samagotchi/worker.rb +16 -14
  199. data/lib/samagotchi/worker_inbound.rb +4 -3
  200. data/lib/samagotchi/worker_link.rb +17 -0
  201. data/lib/samagotchi/working_set.rb +87 -28
  202. metadata +16 -8
  203. data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
  204. data/lib/samagotchi/participant_mode.rb +0 -86
  205. data/lib/samagotchi/review_apply.rb +0 -131
  206. data/lib/samagotchi/review_command.rb +0 -123
  207. data/lib/samagotchi/review_start.rb +0 -196
  208. data/lib/samagotchi/web/public/review_apply.js +0 -34
  209. data/lib/samagotchi/web/public/review_start.js +0 -55
@@ -11,7 +11,7 @@ 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 "../participant_mode"
14
+ require_relative "../worker_link"
15
15
  require_relative "../participant_revise"
16
16
  require_relative "../participants"
17
17
  require_relative "../session"
@@ -19,12 +19,13 @@ require_relative "../turn_checkpoint"
19
19
  require_relative "../turn_origin"
20
20
  require_relative "../verify_fresh"
21
21
  require_relative "../log"
22
+ require_relative "proxy_gate"
22
23
 
23
24
  module Samagotchi
24
25
  module Web
25
26
  # What a participant (a Grants token) may do in chi web, mixed into
26
27
  # App: the gate's lookup of their grant, the refusals that are theirs
27
- # (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
28
29
  # link bound to another account, another session's
29
30
  # 404, not_permitted by role), the trimmed answers of their own routes
30
31
  # (info, the session, resolve, a wait on their turn), their turns, and
@@ -44,7 +45,8 @@ module Samagotchi
44
45
 
45
46
  ENDED = {
46
47
  revoked: ["token_revoked", ParticipantMessages::TOKEN_REVOKED],
47
- expired: ["token_expired", ParticipantMessages::TOKEN_EXPIRED]
48
+ expired: ["token_expired", ParticipantMessages::TOKEN_EXPIRED],
49
+ outdated: ["token_outdated", ParticipantMessages::TOKEN_OUTDATED]
48
50
  }.freeze
49
51
  NOT_PERMITTED = ParticipantMessages::NOT_PERMITTED
50
52
 
@@ -139,7 +141,7 @@ module Samagotchi
139
141
  grant.with(revoked_at: @grants.now.utc.iso8601, revoked_by: by)
140
142
  end
141
143
 
142
- # 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
143
145
  # page's HTML says the same words), nil when none was presented.
144
146
  def grant_ended_response(req)
145
147
  grant, state = req.env[ENDED_GRANT_ENV]
@@ -240,13 +242,7 @@ module Samagotchi
240
242
  # first prompt's opening words: the conversation).
241
243
  def participant_title(session)
242
244
  title = session.title.to_s.strip
243
- return title unless title.empty?
244
-
245
- # A review session's subjects are what participants read anyway.
246
- subjects = session.review&.subjects || []
247
- return UNTITLED if subjects.empty?
248
-
249
- "review of #{subjects.first}#{" +#{subjects.size - 1}" if subjects.size > 1}"
245
+ title.empty? ? UNTITLED : title
250
246
  end
251
247
 
252
248
  UNTITLED = "an untitled session"
@@ -254,7 +250,7 @@ module Samagotchi
254
250
  def participant_names(id)
255
251
  now = @grants.now
256
252
  Participants.read(id, state_dir: default_state_dir).select { |entry| entry.active?(now) }
257
- .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 } }
258
254
  end
259
255
 
260
256
  # POST …/cancel from a participant: only their own running turn, named
@@ -287,7 +283,7 @@ module Samagotchi
287
283
  # would stop whatever runs, the owner's next turn too.
288
284
  def cancels_by_turn_id?(id)
289
285
  session = @session_class.load(id, state_dir: default_state_dir)
290
- Array(ParticipantMode.live_features(session, default_state_dir)).include?(Delivery::CANCEL_TURN_ID_FEATURE)
286
+ Array(WorkerLink.live_features(session.id, state_dir: default_state_dir)).include?(Delivery::CANCEL_TURN_ID_FEATURE)
291
287
  end
292
288
 
293
289
  # 409 cancel_unavailable, audited; nothing is relayed.
@@ -310,7 +306,7 @@ module Samagotchi
310
306
  # POST /api/sessions/:id/turn from a participant: their turn (D6,
311
307
  # D10). Of the body only the prompt, the delivery and images they
312
308
  # uploaded count: the author and client id are the grant's
313
- # (review:<id>), no no_interrupt; the owner's prompt history never
309
+ # (participant:<id>), no no_interrupt; the owner's prompt history never
314
310
  # sees it. The delivery
315
311
  # is queue or next step (none: next step): the worker puts a next-step
316
312
  # message into a running turn only when that turn is theirs, else it
@@ -337,7 +333,7 @@ module Samagotchi
337
333
 
338
334
  # A Verify turn's claim, a Revise turn's draft of their own answer.
339
335
  delivery = Delivery.queue?(body["delivery"]) ? Delivery::QUEUE : Delivery::NEXT_STEP
340
- result = SessionManager.deliver_turn(id, prompt: prompt, client_id: ClientId.review(grant.id),
336
+ result = SessionManager.deliver_turn(id, prompt: prompt, client_id: ClientId.participant(grant.id),
341
337
  delivery: delivery, author: grant.author,
342
338
  **(images.empty? ? {} : { images: images }),
343
339
  anchors: anchors,
@@ -369,7 +365,7 @@ module Samagotchi
369
365
  return nil unless anchors.revises
370
366
 
371
367
  session = @session_class.load(id, state_dir: default_state_dir)
372
- features = ParticipantMode.live_features(session, default_state_dir)
368
+ features = WorkerLink.live_features(session.id, state_dir: default_state_dir)
373
369
  if features && !features.include?(ReviseAnchor::PARTICIPANT_FEATURE)
374
370
  return [409, "revise_unavailable", ParticipantMessages::REVISE_UNAVAILABLE]
375
371
  end
@@ -589,7 +585,7 @@ module Samagotchi
589
585
  <!doctype html>
590
586
  <html lang="en"><head><meta charset="utf-8">
591
587
  <meta name="viewport" content="width=device-width, initial-scale=1">
592
- <title>chi: review link ended</title>
588
+ <title>chi: link ended</title>
593
589
  <style>#{PAGE_STYLE}</style></head>
594
590
  <body>
595
591
  <h1>chi</h1>
@@ -611,7 +607,7 @@ module Samagotchi
611
607
  </script>
612
608
  </body></html>
613
609
  HTML
614
- 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>")
615
611
  end
616
612
  end
617
613
  end
@@ -5,7 +5,6 @@ require_relative "token"
5
5
  require_relative "participant_stream_filter"
6
6
  require_relative "../participant_exposure"
7
7
  require_relative "../session_metrics"
8
- require_relative "../participant_mode"
9
8
  require_relative "../verify_fresh"
10
9
 
11
10
  module Samagotchi
@@ -80,9 +79,9 @@ module Samagotchi
80
79
  def review_viewer(req, id, session:, state:, queued:, viewer:)
81
80
  grant = principal(req).grant
82
81
  capped = !participant_cap_refusal(grant).nil?
83
- # Theirs: pair only when their grant was issued to act (ParticipantMode.live_for).
84
- mode = ParticipantMode.live_for(session, grant, state_dir: default_state_dir).to_s
85
- { kind: "participant", id: grant.id, name: grant.name, participant_kind: grant.kind, mode: mode, can_comment: !capped,
82
+ # Their turns act under the owner's rules (every active grant is pair).
83
+ mode = Grants::PAIR_MODE
84
+ { kind: "participant", id: grant.id, name: grant.name, mode: mode, can_comment: !capped,
86
85
  cap_reached: capped, session_id: id,
87
86
  usage: review_usage(grant, session: session, state: state, queued: queued, viewer: viewer) }
88
87
  end
@@ -4,9 +4,10 @@ require "json"
4
4
  require_relative "participant_view"
5
5
  require_relative "viewer"
6
6
  require_relative "../bridge/turn_accumulator"
7
- require_relative "../participant_mode"
7
+ require_relative "../worker_link"
8
8
  require_relative "../verify_anchor"
9
9
  require_relative "../verify_fresh"
10
+ require_relative "capabilities"
10
11
 
11
12
  module Samagotchi
12
13
  module Web
@@ -40,7 +41,7 @@ module Samagotchi
40
41
  session = reads.session
41
42
  viewer = participant_viewer(req, session)
42
43
  turn_snapshot = reads.turn_snapshot
43
- features = ParticipantMode.live_features(session, default_state_dir)
44
+ features = WorkerLink.live_features(session.id, state_dir: default_state_dir)
44
45
  timing = participant_timing(reads.id, live_metrics: reads.state && reads.state["metrics"])
45
46
  raw = visible_replies(reads.raw_messages)
46
47
  drawn = drawn_lines(reads.id, raw, timing: {}, entries: [], cwd: session.working_directory,
@@ -110,7 +111,7 @@ module Samagotchi
110
111
  session = reads.session
111
112
  review = review_viewer(req, reads.id, session: session, state: reads.state, queued: queued, viewer: viewer)
112
113
  Viewer.for(principal(req)).to_h.merge(
113
- review.slice(:participant_kind, :mode, :cap_reached, :usage),
114
+ review.slice(:mode, :cap_reached, :usage),
114
115
  session_stopped: session.status == Session::STATUS_STOPPED,
115
116
  waiting_for_owner: participant_waiting(reads.turn_snapshot)
116
117
  )
@@ -3,7 +3,6 @@
3
3
  require_relative "../output_formatter"
4
4
  require_relative "../steer"
5
5
  require_relative "../turn_origin"
6
- require_relative "../participant_mode"
7
6
  require_relative "../revise_anchor"
8
7
  require_relative "../verify_anchor"
9
8
  require_relative "../redact"
@@ -33,8 +32,9 @@ module Samagotchi
33
32
  # home folder), defence in depth only: the allowlist is the control.
34
33
  # Pure: no I/O; keys of what comes in may be strings (JSON) or symbols.
35
34
  module ParticipantView
36
- # A turn's participant_mode values the view passes on (ParticipantMode).
37
- PARTICIPANT_MODES = [ParticipantMode::REVIEW.to_s, ParticipantMode::PAIR.to_s].freeze
35
+ # A turn's participant_mode values the view passes on: "pair", and an
36
+ # older chi's "review" (its saved turns keep their stamp).
37
+ PARTICIPANT_MODES = %w[review pair].freeze
38
38
 
39
39
  # The stream's event types a participant gets, each rebuilt by the
40
40
  # method named. Every other type is dropped.
@@ -2,17 +2,16 @@
2
2
 
3
3
  require_relative "../grants"
4
4
  require_relative "qr"
5
- require_relative "../review_start"
6
- require_relative "../review_apply"
5
+ require_relative "../share_terms"
7
6
  require_relative "../session_metrics"
8
7
  require_relative "../participants"
9
8
  require_relative "../session"
9
+ require_relative "link_codes"
10
10
 
11
11
  module Samagotchi
12
12
  module Web
13
13
  # The owner's routes for a session's participants, mixed into App:
14
- # invite, list, revoke, a participant's cap, and the review Apply (the
15
- # owner's turn quoting a review turn's proposal). What a participant
14
+ # invite, list, revoke and a participant's cap. What a participant
16
15
  # may do themselves is ParticipantAccess's. See
17
16
  # docs/internals/participants.md.
18
17
  module ParticipantsAdmin
@@ -21,12 +20,11 @@ module Samagotchi
21
20
  # GET /api/sessions/:id/participants, GET /api/participants: the
22
21
  # grants (one session's, or every one), in every state, never a token
23
22
  # or digest. One session's also carries +warning+: the share warning
24
- # for a session that isn't a review session (ReviewStart.share_warning,
25
- # null for one), which the panel shows before its Invite; and
26
- # +identity_header+: the header this chi web's auth proxy names the
27
- # signed-in user in (null without one), for the Invite's email field;
28
- # +mode+: what a participant invited now gets, "pair" or "review"
29
- # (ReviewStart.share_terms), for the panel's words; +link_base+: where
23
+ # (ShareTerms#warning: what a participant's turns do there, or why no
24
+ # one can be invited until the session restarts), which the panel shows
25
+ # before its Invite; +identity_header+: the header this chi web's auth
26
+ # proxy names the signed-in user in (null without one), for the
27
+ # Invite's email field; and +link_base+: where
30
28
  # a participant's link opens (participant_base), for a claim link
31
29
  # (claim_link.js) the participant's browser opens with its cookie.
32
30
  def handle_participants_list(req, id = nil)
@@ -34,8 +32,8 @@ module Samagotchi
34
32
  grants = @grants.list(session_id: id).map { |grant| grant.public_h(now) }
35
33
  return json_response(200, { participants: grants }) unless id
36
34
 
37
- terms = ReviewStart.share_terms(Session.load(id, state_dir: default_state_dir), state_dir: default_state_dir)
38
- json_response(200, { participants: with_spend(id, grants), warning: terms.warning, mode: terms.mode.to_s,
35
+ terms = ShareTerms.of(Session.load(id, state_dir: default_state_dir), state_dir: default_state_dir)
36
+ json_response(200, { participants: with_spend(id, grants), warning: terms.warning,
39
37
  identity_header: @public_url&.identity_header, link_base: participant_base(req) })
40
38
  rescue Grants::Unwritable => e
41
39
  grants_unwritable(e)
@@ -57,12 +55,12 @@ module Samagotchi
57
55
  end
58
56
  end
59
57
 
60
- # POST /api/sessions/:id/participants {name, kind?, ttl? (seconds),
58
+ # POST /api/sessions/:id/participants {name, ttl? (seconds),
61
59
  # cap? (dollars), identity? (an email: the grant is bound to it, only
62
60
  # behind an auth proxy with an identity header)}: a new grant. The
63
61
  # answer carries the token and the link once (chi keeps only its
64
- # digest), and +warning+ for a session that isn't a review session
65
- # (ReviewStart.share_warning; null for one).
62
+ # digest), and +warning+ (ShareTerms#warning); 409 worker_too_old
63
+ # while the session's live worker would refuse their turns.
66
64
  def handle_participants_invite(req, id)
67
65
  body = body_hash(req) or return error_response(400, "invalid_json", "invalid JSON body")
68
66
  ttl = body["ttl"]
@@ -71,12 +69,14 @@ module Samagotchi
71
69
  cap = body["cap"]
72
70
  return error_response(400, "invalid_participant", Grants::CAP_RANGE) unless cap.nil? || Grants.cap?(cap)
73
71
 
74
- # The grant is stamped pair only when the warning that comes back says
75
- # their turns act (one read: ReviewStart.share_terms).
76
- terms = ReviewStart.share_terms(Session.load(id, state_dir: default_state_dir), state_dir: default_state_dir)
77
- issued = Participants.invite(@grants, session_id: id, name: body["name"], kind: (body["kind"] || "human").to_s,
78
- ttl: ttl, cap: cap, identity: body["identity"], public_url: @public_url,
79
- mode: terms.grant_mode, state_dir: default_state_dir)
72
+ # No link while the live worker would refuse every turn of theirs
73
+ # (one read: ShareTerms.of, the warning that comes back).
74
+ terms = ShareTerms.of(Session.load(id, state_dir: default_state_dir), state_dir: default_state_dir)
75
+ return error_response(409, "worker_too_old", terms.refusal) if terms.refusal
76
+
77
+ # An older chi --remote share --agent's kind is ignored.
78
+ issued = Participants.invite(@grants, session_id: id, name: body["name"], ttl: ttl, cap: cap, identity: body["identity"], public_url: @public_url,
79
+ state_dir: default_state_dir)
80
80
  link = participant_link(req, id, issued.token, expires_at: issued.grant.expires_at)
81
81
  json_response(201, { participant: issued.grant.public_h(@grants.now), token: issued.token,
82
82
  link: link, lan: !@lan.nil? || !@public_url.nil?, qr_svg: QR.svg(link), warning: terms.warning })
@@ -86,25 +86,6 @@ module Samagotchi
86
86
  grants_unwritable(e)
87
87
  end
88
88
 
89
- # GET /api/sessions/:id/apply[?turn=T] (owner): the owner's turn that
90
- # applies review turn T's proposal (ReviewApply: the reply quoted
91
- # under one line of the owner's), for the composer: never sent from
92
- # here. Without turn, the latest review turn with a reply. Read from
93
- # the live worker's messages, else the saved ones.
94
- # @return 200 {text, turn_id, author, author_name}; 404 not_found (no
95
- # such turn, or no review turn); 400 not_review_turn; 409 no_reply
96
- def handle_apply(req, id)
97
- session = @session_class.load(id, state_dir: default_state_dir)
98
- live = bridge_get_json(id, "snapshot")
99
- messages = live_or_saved(live && live["snapshot"], "messages") { session.messages }
100
- proposal = ReviewApply.find(messages, req.params["turn"])
101
- json_response(200, { text: ReviewApply.compose(proposal), turn_id: proposal.turn_id, author: proposal.author,
102
- author_name: proposal.author_name })
103
- rescue ReviewApply::Refused => e
104
- status = { not_found: 404, not_review_turn: 400, no_reply: 409 }.fetch(e.code)
105
- error_response(status, e.code.to_s, e.message)
106
- end
107
-
108
89
  # DELETE /api/sessions/:id/participants[?id=p_…], DELETE
109
90
  # /api/participants: revokes one participant, a session's or every
110
91
  # one's; their open streams end within a poll.
@@ -15,7 +15,6 @@ import {
15
15
  openEvents,
16
16
  createIdleSession,
17
17
  continueSession,
18
- startReview,
19
18
  uploadImage,
20
19
  listModels,
21
20
  fetchHistory,
@@ -47,7 +46,6 @@ import { createSessionStore } from "./session_store.js";
47
46
  import { createFeatureGates } from "./feature_gates.js";
48
47
  import { stillOn } from "./latest.js";
49
48
  import { normalize, cantText } from "./format.js";
50
- import { elementOf } from "./turn_html.js";
51
49
  import { createBubbles } from "./bubbles.js";
52
50
  import { createCardsPlace } from "./cards_place.js";
53
51
  import { createStageView } from "./stage_view.js";
@@ -63,7 +61,6 @@ import { openerFill, openTitle, restoredComposer } from "./chains.js";
63
61
  import { createTaskStopper } from "./task_stop.js";
64
62
  import { createSystemOneWrongAction } from "./system_one_wrong.js";
65
63
  import { appendQuote } from "./annotations.js";
66
- import { applyComposerText, applyRowTemplate, fetchApply } from "./review_apply.js";
67
64
  import { nameVerdictCards } from "./verdict_card.js";
68
65
  import { redrawFresh } from "./verdict_fresh.js";
69
66
  import { authorBadge, nameUnnamedBadges } from "./participant_names.js";
@@ -192,8 +189,6 @@ const participantsControl = viewer.can("participants_admin") ? createParticipant
192
189
  el: infoTextEl,
193
190
  session: () => store.selected,
194
191
  api: { list: listParticipants, invite: inviteParticipant, revoke: revokeParticipant, cap: setParticipantCap },
195
- startReview: (opts) => sessionActions.reviewSelected(opts),
196
- reviewing: () => sessionActions.reviewing.has(store.selected),
197
192
  // An older prompt drawn before the list came says "a participant": named now.
198
193
  onNames: () => {
199
194
  nameUnnamedBadges(document);
@@ -217,7 +212,6 @@ const startPage = createStartPage({
217
212
  settingsEl: $("#settingsNew"),
218
213
  llmContextEl: $("#llmContextNew"),
219
214
  thinkingEl: $("#thinkingNew"),
220
- reviewEl: $("#reviewNew"),
221
215
  toolkitBtnEl: $("#toolkitBtn"),
222
216
  toolkitEl: $("#toolkitNew"),
223
217
  selected: () => store.selected,
@@ -451,7 +445,6 @@ const deliveryControl = createDeliveryControl({
451
445
  composerEmpty: () => !composer.hasDraft(),
452
446
  history: viewer.can("prompt_history"),
453
447
  send: (delivery) => handleSendTurn({ delivery }),
454
- session: () => store.selected,
455
448
  });
456
449
 
457
450
  // This tab's id in the session's events: tells its own prompts from the
@@ -478,7 +471,8 @@ const questionCards = createQuestionCards({
478
471
  // The bar's chip reads questionCards.pendingQuestion() (sessionWaits).
479
472
  onPending: () => store.touch("infoBar"),
480
473
  // The stage's waiting cards as data (stage_waiting.js).
481
- onSettled: (key) => turnDom.settleWaiting?.(key),
474
+ onArrive: (key, info) => turnDom.expectWaiting?.(key, info),
475
+ onSettled: (key, opts) => turnDom.settleWaiting?.(key, opts),
482
476
  });
483
477
  // The history's bubbles (bubbles.js): output, end lines, every client's
484
478
  // prompts, the recap, warnings and notices, command and note bubbles.
@@ -523,7 +517,6 @@ const sessionView = createSessionView({
523
517
  liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet, wsPreview, gapClock,
524
518
  bubbles, cards, markdown: markdownPlace,
525
519
  capabilities: () => pageCapabilities,
526
- can: viewer.can,
527
520
  page: {
528
521
  setReviseAnchor, renderInitRow, setMarkdownWarning, setCapabilities, findInTurnRoots, appendToHistory,
529
522
  setTurnRunning, mergeTurnTiming, applySessionPayload, turnEndStatus, replaceSelectedCard,
@@ -703,7 +696,7 @@ const sessionActions = createSessionActions({
703
696
  store,
704
697
  sessions: () => store.sessions,
705
698
  setSessions: (list) => store.update({ sessions: list }),
706
- api: { continueSession, startReview, archiveSession, unarchiveSession, deleteSession, stopSession,
699
+ api: { continueSession, archiveSession, unarchiveSession, deleteSession, stopSession,
707
700
  sessionHolds, stopSessionHolds },
708
701
  eventsLive: () => !!eventsControl,
709
702
  refresh,
@@ -910,11 +903,9 @@ function clearNotice() {
910
903
  }
911
904
  promptEl.addEventListener("input", clearNotice);
912
905
  promptEl.addEventListener("input", () => noteDraft());
913
- // An emptied composer lets go of its Apply turn, its Verify claim and its
914
- // Revise.
906
+ // An emptied composer lets go of its Verify claim and its Revise.
915
907
  promptEl.addEventListener("input", () => {
916
908
  if (promptEl.value.trim()) return;
917
- deliveryControl.release();
918
909
  ownerVerify.clear();
919
910
  setReviseAnchor(null);
920
911
  });
@@ -979,41 +970,11 @@ infoTextEl.addEventListener("click", async (e) => {
979
970
  showToast((await copyText(store.selected)) ? "Session id copied" : "Couldn't copy the session id");
980
971
  });
981
972
 
982
- // Apply (review_apply.js) under a participant's review turn that just
983
- // ended live ({turn_id, author, author_name}, from its turn_started), once:
984
- // a reload draws it from the history (turn_block.js).
985
- function placeApply(data) {
986
- const badge = authorBadge(data.author, data.author_name);
987
- if (!badge || historyEl.querySelector(`.review-apply[data-apply-turn="${CSS.escape(data.turn_id)}"]`)) return;
988
- appendToHistory(elementOf(applyRowTemplate(data.turn_id, badge)));
989
- }
990
-
991
973
  // The owner's Verify (owner_verify.js): verdict cards, Verify fresh, the claim.
992
974
  const ownerVerify = createOwnerVerify({
993
975
  historyEl, store, api, claim: ownerClaim, liveTurn, toast: (text) => showToast(text),
994
976
  });
995
977
 
996
- // Apply: the owner's Apply turn into the composer, after what is typed
997
- // there; never sent from here.
998
- if (viewer.can("apply")) historyEl.addEventListener("click", async (e) => {
999
- const button = e.target.closest(".review-apply-btn");
1000
- if (!button || !store.selected) return;
1001
- const id = store.selected;
1002
- button.disabled = true;
1003
- try {
1004
- const text = await fetchApply(id, button.dataset.applyTurn);
1005
- if (id === store.selected) {
1006
- fillComposer(applyComposerText(promptEl.value, text));
1007
- // The owner's own turn: queued after a running one, never steered in.
1008
- deliveryControl.hold();
1009
- }
1010
- } catch (err) {
1011
- showToast(err.message);
1012
- } finally {
1013
- button.disabled = false;
1014
- }
1015
- });
1016
-
1017
978
  // The session bar (info_bar_model.js sessionBar): its buttons, and the
1018
979
  // info line rendered by info_bar.js.
1019
980
  // The open session waits on the user: its card is up, or its summary says so
@@ -1185,7 +1146,6 @@ const streamHandlers = (participant ? participant.wrapHandlers : (handlers) => h
1185
1146
  contextChips,
1186
1147
  workingSet,
1187
1148
  participantsControl,
1188
- placeApply: viewer.can("apply") ? placeApply : null,
1189
1149
  placeVerdict: ownerVerify.placeVerdict,
1190
1150
  restoreVerify: (anchor) => ownerVerify.set(anchor),
1191
1151
  restoreRevise,
@@ -1332,15 +1292,14 @@ function runSessionCommand(line) {
1332
1292
 
1333
1293
  function clearComposer() {
1334
1294
  promptEl.value = "";
1335
- deliveryControl.release();
1336
1295
  fitPrompt();
1337
1296
  }
1338
1297
 
1339
- // A queue (Alt+Enter, or an Apply turn's Enter) to a worker that can't
1340
- // queue (it would steer): not sent, the text kept, a note says why.
1298
+ // A queue (Alt+Enter) to a worker that can't queue (it would steer): not
1299
+ // sent, the text kept, a note says why.
1341
1300
  function queueRefused(altKey) {
1342
1301
  if (!store.selected || !liveTurn.running || store.current.workerFeatures.includes("delivery")) return false;
1343
- if (!altKey && !deliveryControl.held()) return false;
1302
+ if (!altKey) return false;
1344
1303
  addCommandBubble({ label: null, line: promptEl.value.trim(), text: QUEUE_NEEDS_WORKER, failed: true });
1345
1304
  return true;
1346
1305
  }
@@ -0,0 +1,51 @@
1
+ // What a card waits as, from its data (stage_waiting.js KINDS): the kind,
2
+ // whether it is an approval, and the folded row's text (stage_asking.js
3
+ // foldedText), read from the pending question, the continue offer or the
4
+ // plugin card before its node is drawn. question_cards.js and cards_place.js
5
+ // hand it to the stage (onArrive / expectWaiting) right before the card is
6
+ // placed; the stage still reads the node (waitingKind, foldedText) as a
7
+ // cross-check, and as the fallback for a card that came without it.
8
+ // Pure: no DOM. The same rules question_cards.js and card.js draw by:
9
+ // data-kind, data-relay and the step-limit class; the question text and the
10
+ // approval's summary line; a plugin card's actions and level.
11
+ import { approvalView, isContinue, relayView, summaryText } from "./question_card.js";
12
+
13
+ // The question a card shows (its .question-text): a delegate's relayed
14
+ // question's own words, else the question.
15
+ export function questionText(pq) {
16
+ return String((relayView(pq) && pq.relay.asked) || pq?.question || "");
17
+ }
18
+
19
+ // A pending question's wait: the step limit is "continue", a delegate's
20
+ // relayed card "relay", else its kind (approval, hook, question).
21
+ export function questionWait(pq) {
22
+ const approval = pq?.kind === "approval";
23
+ const kind = isContinue(pq) ? "continue" : relayView(pq) ? "relay" : ["approval", "hook"].includes(pq?.kind) ? pq.kind : "question";
24
+ if (!approval) return { kind, approval, summary: questionText(pq) };
25
+ // The summary's own words and the command's (or the tool's) first line.
26
+ const view = approvalView(pq);
27
+ const what = String(view.what || view.tool || "").trim().split("\n")[0].trim();
28
+ return { kind, approval, summary: [summaryText(pq).trim(), what].filter(Boolean).join(" ") };
29
+ }
30
+
31
+ // The old continue card: no question text.
32
+ export function continueWait() {
33
+ return { kind: "continue", approval: false, summary: "" };
34
+ }
35
+
36
+ // A plugin card's wait: a running turn's card with an action asks (as
37
+ // check-in's), a warning stays in sight; null: it doesn't wait.
38
+ export function cardWait(card) {
39
+ const asks = !!card?.in_turn && (card.actions || []).some((a) => a && a.command);
40
+ return { kind: asks ? "asks" : card?.level === "warn" ? "warn" : null, approval: false, summary: String(card?.title || "") };
41
+ }
42
+
43
+ // The cross-check: the data and the node disagree about +key+'s +what+
44
+ // ("kind", "summary"). Said once per key and field.
45
+ const said = new Set();
46
+ export function warnDiffers(what, key, data, dom) {
47
+ const id = `${what}:${key}`;
48
+ if (said.has(id)) return;
49
+ said.add(id);
50
+ console.warn(`stage: waiting ${what} differs`, key, data, dom);
51
+ }
@@ -16,6 +16,7 @@ import { llmContextNotice, noticeLine } from "./turn_events.js";
16
16
  import { hookNoticeTemplate, TURN_PROMPT, turnPromptBubbles } from "./bubbles.js";
17
17
  import { stillOn } from "./latest.js";
18
18
  import { pluginCardKey } from "./stage_waiting.js";
19
+ import { cardWait } from "./card_kinds.js";
19
20
 
20
21
  // The elements of the reloaded turn that ends before +before+ (the next
21
22
  // turn's prompt, or null for the last turn), its prompt first.
@@ -74,17 +75,27 @@ export function createCardsPlace({
74
75
  const existing = cardElement(card.id);
75
76
  const asks = (card.actions || []).some((a) => a && a.command);
76
77
  if (existing) {
78
+ const wasWarn = existing.classList.contains("warn");
77
79
  const drawn = drawCard(existing, card);
78
80
  drawn.classList.add("card-updated");
79
81
  setTimeout(() => drawn.classList.remove("card-updated"), 900);
80
82
  // Redrawn without its actions (check-in's card turned into its notice
81
- // row): it no longer asks (stage_waiting.js).
82
- if (!asks) turnDom.settleWaiting?.(pluginCardKey(card.id), { only: "asks" });
83
+ // row): it no longer asks; redrawn neither asking nor a warning: it no
84
+ // longer stays in sight. Then, still waiting (check-in's new title, an
85
+ // asking card now a warning: in sight, not docked), the stage's entry
86
+ // says what it waits as now (stage_waiting.js).
87
+ const key = pluginCardKey(card.id);
88
+ const wait = cardWait(card);
89
+ if (!asks) turnDom.settleWaiting?.(key, { only: "asks" });
90
+ if (wasWarn && !asks && card.level !== "warn") turnDom.settleWaiting?.(key, { only: "warn" });
91
+ if (wait.kind) turnDom.updateWaiting?.(key, wait);
83
92
  return;
84
93
  }
85
94
  bubbles.removeHintIfEmpty();
86
95
  const el = drawCard(document.createElement(isNoticeCard(card) ? "details" : "div"), card);
87
96
  if (card.in_turn && !before && !asks && turnDom.card(el)) return;
97
+ // What it waits as, for the stage's place (stage_place.js).
98
+ if (!before) turnDom.expectWaiting?.(pluginCardKey(card.id), cardWait(card));
88
99
  bubbles.placeFollowing(el, before);
89
100
  }
90
101
 
@@ -60,11 +60,9 @@ export function listSessions(sort, order, { dir, ...opts } = {}) {
60
60
  // start page's ⚙ panel set some; thinking: its own level ("low"), when the
61
61
  // start page's ⚙ panel set one; toolkit: the kit it starts on, when the
62
62
  // start page's 🧰 list picked one (none: config's default, maybe suggested).
63
- // review: {subjects} makes it a review session (it starts idle; no preview).
64
63
  // The other fields are api()'s fetch options.
65
- export function createIdleSession({ dir, model, preview, llm_context: llmContext, thinking, toolkit, review,
66
- ...opts } = {}) {
67
- const start = review ? { review } : { idle: true, ...(preview ? { preview } : {}) };
64
+ export function createIdleSession({ dir, model, preview, llm_context: llmContext, thinking, toolkit, ...opts } = {}) {
65
+ const start = { idle: true, ...(preview ? { preview } : {}) };
68
66
  const body = { ...start, ...(dir ? { dir } : {}), ...(model ? { model } : {}),
69
67
  ...(llmContext ? { llm_context: llmContext } : {}), ...(thinking ? { thinking } : {}),
70
68
  ...(toolkit ? { toolkit } : {}) };
@@ -80,12 +78,6 @@ export function continueSession(id, opts = {}) {
80
78
  return api("/api/sessions", { method: "POST", body: JSON.stringify({ continues: id, idle: true }), ...opts });
81
79
  }
82
80
 
83
- // A review fork of +id+ (docs/sessions.md, Review sessions): a new session in
84
- // its folder, seeded with its recap, not its transcript; +id+ keeps running.
85
- export function startReview(id, opts = {}) {
86
- return api("/api/sessions", { method: "POST", body: JSON.stringify({ review: { from: id } }), ...opts });
87
- }
88
-
89
81
  // The models a new session can start on: {default, models: [{name, host, id}],
90
82
  // warning?} (a host that failed is in the warning, the list has the rest).
91
83
  export function listModels(opts = {}) {