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
@@ -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,13 +46,13 @@ 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 { turnHistoryNodes } from "./turn_block.js";
51
- import { elementOf } from "./turn_html.js";
52
49
  import { createBubbles } from "./bubbles.js";
53
50
  import { createCardsPlace } from "./cards_place.js";
54
51
  import { createStageView } from "./stage_view.js";
55
52
  import { createReloadCheck } from "./reload_check.js";
53
+ import { placeCardsOffscreen } from "./cards_offscreen.js";
56
54
  import { createWorkingSet } from "./working_set_view.js";
55
+ import { createWorkingSetPreview } from "./ws_reader.js";
57
56
  import { createObjectives } from "./objectives_wiring.js";
58
57
  import { trackWorkerUnavailable } from "./objectives_track.js";
59
58
  import { createGapClock } from "./time_gaps.js";
@@ -62,7 +61,6 @@ import { openerFill, openTitle, restoredComposer } from "./chains.js";
62
61
  import { createTaskStopper } from "./task_stop.js";
63
62
  import { createSystemOneWrongAction } from "./system_one_wrong.js";
64
63
  import { appendQuote } from "./annotations.js";
65
- import { applyComposerText, applyRowTemplate, fetchApply } from "./review_apply.js";
66
64
  import { nameVerdictCards } from "./verdict_card.js";
67
65
  import { redrawFresh } from "./verdict_fresh.js";
68
66
  import { authorBadge, nameUnnamedBadges } from "./participant_names.js";
@@ -124,7 +122,11 @@ import { createSendTurn } from "./send_turn.js";
124
122
  import { createSessionSync } from "./session_sync.js";
125
123
  import { createSessionView } from "./session_view.js";
126
124
  import { createMarkdownTip } from "./markdown_tip.js";
125
+ import { IMAGES_NOT_HERE } from "./images.js";
127
126
  import { withoutStaleParams } from "./stale_params.js";
127
+ import { createViewer } from "./viewer.js";
128
+ import { createParticipantMain } from "./participant_main.js";
129
+ import { PARTICIPANT_REVISE_UNAVAILABLE, participantMayRevise, participantReviseUnavailable } from "./participant_revise.js";
128
130
 
129
131
  // A link's #code= (behind an auth proxy): traded for the cookie before
130
132
  // anything else runs; the page reloads without it.
@@ -141,6 +143,8 @@ const authLost = createAuthLost();
141
143
  onAuthLost(authLost);
142
144
 
143
145
  const $ = (s) => document.querySelector(s);
146
+ // Who looks and what they may do (viewer.js): every owner-only control and call asks it.
147
+ const viewer = createViewer(document.body);
144
148
  const topStripEl = $("#topStrip");
145
149
  const allListEl = $("#allList");
146
150
  const historyEl = $("#history");
@@ -150,41 +154,41 @@ const composerEl = $("#composer");
150
154
  // shows it; the tab's base ("Chi · <project>"), set by renderScope.
151
155
  const sessionTitleEl = $("#sessionTitle");
152
156
  const sessionTitleRowEl = $("#sessionTitleRow");
153
- const titleRenameBtn = $("#titleRenameBtn");
157
+ const titleRenameBtn = viewer.control($("#titleRenameBtn"), "rename");
154
158
  let tabBase = null;
155
159
  let tabShown = null;
156
160
  const infoTextEl = $("#infoText");
157
161
  // The open session's attached context, in its own row of the session bar
158
162
  // (updateInfoBar redraws #infoText every tick; the chips keep their popover).
159
- const contextChips = createContextChips({
163
+ const contextChips = viewer.can("context") ? createContextChips({
160
164
  el: $("#contextChips"),
161
165
  api: { list: listContext, show: getContext, detach: detachContext },
162
166
  toast: (text) => showToast(text),
163
- });
167
+ }) : null;
164
168
  // The open session's ⚙ chip in the info bar, and its panel (thinking,
165
169
  // reasoning history, LLM context): a pick runs its command in the session's
166
170
  // worker.
167
- const settingsControl = createSettingsControl({
171
+ const settingsControl = viewer.can("session_controls") ? createSettingsControl({
168
172
  el: infoTextEl,
169
173
  summaries: () => (store.selected ? { thinking: store.current.thinking, reasoningHistory: store.current.reasoningHistory,
170
174
  llmContext: store.current.llmContext } : null),
171
175
  session: () => store.selected,
172
176
  running: () => liveTurn.running,
173
177
  run: (line) => runSessionCommand(line),
174
- });
175
- // ⋯ on the info bar, and its menu: the chips and buttons the row has no room for.
176
- const moreSheet = createMoreSheet({ el: $("#infoBar"), button: $("#infoMoreBtn"), session: () => store.selected, hash: sessionHash });
178
+ }) : null;
179
+ // ⋯ on the info bar, and its menu: the chips and buttons the row has no room for; and the bar's other buttons.
180
+ const [continueBtn, archiveBtn, stopBtn, deleteBtn, moreBtn] = viewer.controls(
181
+ ["#infoContinueBtn", "#infoArchiveBtn", "#infoStopBtn", "#infoDeleteBtn", "#infoMoreBtn"].map($), "session_controls");
182
+ const moreSheet = moreBtn ? createMoreSheet({ el: $("#infoBar"), button: moreBtn, session: () => store.selected, hash: sessionHash }) : null;
177
183
  // The bar's fold (bar_fold.js): one row, what doesn't fit folded into ⋯. A
178
184
  // resize, the fonts or a zoom refolds it by itself: ⋯ follows on the redraw.
179
185
  const barFold = createBarFold({ barEl: $("#infoBar"), keysFor: barItemKeys, onChange: () => store.touch("infoBar") });
180
186
  // The open session's participants chip in the info bar, and its panel
181
187
  // (Invite, revoke, caps, the participant view).
182
- const participantsControl = createParticipantsControl({
188
+ const participantsControl = viewer.can("participants_admin") ? createParticipantsControl({
183
189
  el: infoTextEl,
184
190
  session: () => store.selected,
185
191
  api: { list: listParticipants, invite: inviteParticipant, revoke: revokeParticipant, cap: setParticipantCap },
186
- startReview: (opts) => sessionActions.reviewSelected(opts),
187
- reviewing: () => sessionActions.reviewing.has(store.selected),
188
192
  // An older prompt drawn before the list came says "a participant": named now.
189
193
  onNames: () => {
190
194
  nameUnnamedBadges(document);
@@ -195,7 +199,7 @@ const participantsControl = createParticipantsControl({
195
199
  },
196
200
  onChange: () => store.touch("infoBar"),
197
201
  toast: (text, action, options) => showToast(text, action, options),
198
- });
202
+ }) : null;
199
203
  // The start page's model picker, its ⚙ panel and 🧰 list with the override chips
200
204
  // (start_page.js); a fresh chain link's picker too.
201
205
  const startPage = createStartPage({
@@ -208,7 +212,6 @@ const startPage = createStartPage({
208
212
  settingsEl: $("#settingsNew"),
209
213
  llmContextEl: $("#llmContextNew"),
210
214
  thinkingEl: $("#thinkingNew"),
211
- reviewEl: $("#reviewNew"),
212
215
  toolkitBtnEl: $("#toolkitBtn"),
213
216
  toolkitEl: $("#toolkitNew"),
214
217
  selected: () => store.selected,
@@ -226,15 +229,14 @@ const markdownTip = createMarkdownTip($("#markdownTip"));
226
229
  // What the page renders that a notice may stand in for (the server's
227
230
  // Web::Capabilities, next to markdown_warning); a notice it names isn't
228
231
  // drawn (shownElsewhere). An older server sends none: every notice shows.
229
- // And what this viewer can do (editor: open a path in this machine's
230
- // editor; per request), with the editor's URL template (editor_url) next
231
- // to it: refs.js's actions read both (pageViewer).
232
+ // And whether this request's viewer can open a path in this machine's
233
+ // editor (per request), with the editor's URL template (editor_url) next
234
+ // to it: refs.js's actions read both (refEditor).
232
235
  let pageCapabilities = {};
233
236
  let pageEditorUrl = null;
234
237
  const promptEl = $("#prompt");
235
238
  const actionBtn = $("#actionBtn");
236
- const attachBtn = $("#attachBtn");
237
- const attachInput = $("#attachInput");
239
+ const [attachBtn, attachInput] = viewer.controls([$("#attachBtn"), $("#attachInput")], "images");
238
240
  const composeHintEl = $("#composeHint");
239
241
 
240
242
  // The open session (store.selected), its fields (store.current: session_state.js;
@@ -244,6 +246,12 @@ const composeHintEl = $("#composeHint");
244
246
  // the page's first draw); an input the store doesn't hold calls
245
247
  // store.touch(name).
246
248
  const store = createSessionStore({ initial: emptySessionState() });
249
+ // An invited person's link: their session, name, bottom row and limits (participant_main.js).
250
+ const participant = viewer.kind() === "participant" ? createParticipantMain({ body: document.body, topBar: $("#topBar"), infoBar: $("#infoBar"),
251
+ composer: $("#composer"), store, running: () => liveTurn.running, stage: { redraw: () => turnDom.redraw?.() }, read: (id) => getSession(id),
252
+ onClosed: () => reviseStacks?.decorate() }) : null;
253
+ // Revise's worker gate and its words: a participant's own (participant_revise.js).
254
+ const [reviseGate, reviseOffText] = participant ? [participantReviseUnavailable, PARTICIPANT_REVISE_UNAVAILABLE] : [reviseWorkerUnavailable, undefined];
247
255
  // The page actions the open session's worker must support (feature_gates.js),
248
256
  // the store's featureGates redraw: a gate's redraw runs when its answer
249
257
  // flips (a restart brings the feature, the worker goes). forgetSession and
@@ -258,7 +266,7 @@ const featureGates = createFeatureGates([
258
266
  // Revise on an answer and the composer's Revising chip (revise_stack.js).
259
267
  {
260
268
  name: "revise",
261
- unavailable: (cur) => reviseWorkerUnavailable(cur.workerFeatures, cur.bridgeUp),
269
+ unavailable: (cur) => reviseGate(cur.workerFeatures, cur.bridgeUp),
262
270
  redraw: () => redrawRevise(),
263
271
  },
264
272
  // The objectives' Where are we? (objectives_track.js).
@@ -274,11 +282,11 @@ const openId = () => store.selected;
274
282
  let pendingReviseAnchor = null;
275
283
  let reviseStacks = null;
276
284
  const reviseChipEl = $("#reviseChip");
277
- const reviseUnavailable = () => reviseWorkerUnavailable(store.current.workerFeatures, store.current.bridgeUp);
285
+ const reviseUnavailable = () => reviseGate(store.current.workerFeatures, store.current.bridgeUp);
278
286
  function redrawRevise() {
279
287
  if (reviseChipEl) {
280
288
  render(reviseChipTemplate(pendingReviseAnchor, {
281
- unavailable: reviseUnavailable(),
289
+ unavailable: reviseUnavailable(), text: reviseOffText,
282
290
  onClear: () => { setReviseAnchor(null); focusPrompt(); },
283
291
  }), reviseChipEl);
284
292
  reviseChipEl.hidden = !pendingReviseAnchor;
@@ -314,7 +322,7 @@ let eventsControl = null;
314
322
  const shownTexts = createShownTexts();
315
323
  const markdownPlace = createMarkdownPlace({
316
324
  capabilities: () => pageCapabilities,
317
- renderText,
325
+ renderText: viewer.can("render") ? renderText : null,
318
326
  roots: () => turnRoots(),
319
327
  touchedFiles,
320
328
  currentDir: () => store.current.dir,
@@ -331,14 +339,17 @@ const { renderMarkdown, pairRefsIn, linkRefsIn, applyFinalMarkdown } = markdownP
331
339
  // what each turn brought into context, in a rail in the stage, a footprint
332
340
  // under each finished turn and a "set N" chip in the mem chip's place
333
341
  // (working_set_view.js).
334
- const workingSet = document.body.dataset.workingSet === "1"
342
+ const wsLine = viewer.can("session_controls") ? (line) => (store.selected ? sendCommand(store.selected, line, { clientId }) : null) : null;
343
+ // What chi has of an item (the owner's): the rows' peek and the reader over the stage (ws_reader.js).
344
+ const wsPreview = document.body.dataset.workingSet === "1" && viewer.can("working_set_items")
345
+ ? createWorkingSetPreview({ centerEl: $("#center"), session: () => store.selected, state: () => store.current, sendLine: wsLine }) : null;
346
+ const workingSet = document.body.dataset.workingSet === "1" && viewer.can("working_set")
335
347
  ? createWorkingSet({
336
348
  historyEl, stageRoot: () => turnDom.root, state: () => store.current, session: () => store.selected, infoEl: infoTextEl,
337
- onChange: () => store.touch("infoBar"), getWorkingSet,
338
- // A drop or undrop from the list: the session's command, as typed.
339
- sendLine: (line) => (store.selected ? sendCommand(store.selected, line, { clientId }) : null),
349
+ onChange: () => store.touch("infoBar"), getWorkingSet, sendLine: wsLine, peek: wsPreview?.peek ?? null, onTimeline: wsPreview?.open ?? null,
340
350
  })
341
351
  : null;
352
+ wsPreview?.attach(workingSet);
342
353
  document.body.classList.toggle("working-set", !!workingSet);
343
354
  // The running turn's DOM: the stage pinned above the composer
344
355
  // (stage_view.js), the turn block (turn_block.js) in its cloud.
@@ -349,14 +360,15 @@ const turnDom = createStageView({
349
360
  sessionId: () => store.selected,
350
361
  // The stop-task button on a running task_wait, for a worker that has
351
362
  // the route (its sidecar features).
352
- taskStop: createTaskStopper({ sessionId: () => store.selected, features: () => store.current.workerFeatures }),
363
+ taskStop: viewer.can("session_controls") ? createTaskStopper({ sessionId: () => store.selected, features: () => store.current.workerFeatures }) : null,
353
364
  dockEl: $("#dock"),
354
365
  centerEl: $("#center"),
355
366
  renderMarkdown,
356
367
  linkRefs: linkRefsIn,
357
368
  workingSet,
358
369
  // Stop turn in its status row (disabled until the request settles).
359
- onCancel: () => handleCancel(),
370
+ onCancel: viewer.can("stop_any_turn") || viewer.can("stop_own_turn") ? () => handleCancel() : null,
371
+ canCancel: () => !participant || participant.canCancel(), ownerWait: () => participant?.ownerWait() ?? null,
360
372
  onHandedOff: (handed) => reloadCheck.handedOff(handed),
361
373
  // The quiet signal (stage_stall.js): the stream, what the turn waits on, a joiner's step clock.
362
374
  streamLive: () => sessionSync.streamLive(), timingNote: () => liveTurn.timing.note, serverGen: () => liveTurn.serverGen,
@@ -364,11 +376,13 @@ const turnDom = createStageView({
364
376
  // The opt-in reload check (web.reload_check): a handed-off turn against a
365
377
  // reload of it, the counts to chi web (reload_check.js).
366
378
  const reloadCheck = createReloadCheck({
367
- enabled: () => document.body.dataset.reloadCheck === "1",
379
+ enabled: () => document.body.dataset.reloadCheck === "1" && viewer.can("session_controls"),
368
380
  sessionId: () => store.selected,
369
381
  running: () => liveTurn.running,
370
382
  read: (id) => getSession(id),
371
- render: (data) => turnHistoryNodes(data.messages || [], normalizeTiming(data.timing), historyOpts(data)),
383
+ render: (data) => sessionView.reloadRender(data),
384
+ place: (holder, entries) => placeCardsOffscreen(holder, entries, { capabilities: pageCapabilities, answers: viewer.can("answer_cards") }),
385
+ capabilities: () => pageCapabilities,
372
386
  post: (id, body) => api(`/api/sessions/${id}/reload_check`, { method: "POST", body: JSON.stringify(body) }),
373
387
  });
374
388
  // The history's bottom reserve and the toast's place follow the composer
@@ -388,7 +402,7 @@ function turnRoots() {
388
402
  return [historyEl, turnDom.root];
389
403
  }
390
404
  const systemOneWrongAction = createSystemOneWrongAction({ sessionId: () => store.selected });
391
- turnRoots().forEach((root) => root.addEventListener("click", systemOneWrongAction));
405
+ if (viewer.can("answer_cards")) turnRoots().forEach((root) => root.addEventListener("click", systemOneWrongAction));
392
406
  function findInTurnRoots(selector) {
393
407
  return turnRoots().flatMap((root) => [...root.querySelectorAll(selector)]);
394
408
  }
@@ -425,12 +439,12 @@ const deliveryControl = createDeliveryControl({
425
439
  serverGen: liveTurn.serverGen,
426
440
  canQueue: store.current.workerFeatures.includes("delivery"),
427
441
  model: store.current.model,
428
- participantTurn: !!liveTurn.participantTurn,
442
+ participantTurn: !!liveTurn.participantTurn, viewerTurn: participant?.deliveryTurn() ?? null,
429
443
  };
430
444
  },
431
445
  composerEmpty: () => !composer.hasDraft(),
446
+ history: viewer.can("prompt_history"),
432
447
  send: (delivery) => handleSendTurn({ delivery }),
433
- session: () => store.selected,
434
448
  });
435
449
 
436
450
  // This tab's id in the session's events: tells its own prompts from the
@@ -445,6 +459,7 @@ const objectives = createObjectives({
445
459
  const questionCards = createQuestionCards({
446
460
  sessionId: () => store.selected,
447
461
  clientId,
462
+ answers: viewer.can("answer_cards"),
448
463
  place: (card) => appendToHistory(card),
449
464
  isNearBottom: () => isNearBottom(),
450
465
  scrollToEnd: () => { historyEl.scrollTop = historyEl.scrollHeight; },
@@ -498,7 +513,7 @@ turnRoots().forEach((root) => root.addEventListener("click", cards.onCardAction)
498
513
  // the ones made later come in as getters, and each reaches the other lazily.
499
514
  const sessionView = createSessionView({
500
515
  store, historyEl, getSession,
501
- liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet, gapClock,
516
+ liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet, wsPreview, gapClock,
502
517
  bubbles, cards, markdown: markdownPlace,
503
518
  capabilities: () => pageCapabilities,
504
519
  page: {
@@ -510,7 +525,7 @@ const sessionView = createSessionView({
510
525
  commandList: () => commandList, initTasks: () => initTasks, resetTurnView: () => sessionSync.resetTurnView(),
511
526
  },
512
527
  });
513
- const { forgetSession, historyOpts, readTurnEnd, endTurnView } = sessionView;
528
+ const { forgetSession, readTurnEnd, endTurnView } = sessionView;
514
529
  const sessionSync = createSessionSync({
515
530
  store, historyEl, emptyEl, getSession, openStream,
516
531
  liveTurn, turnDom, questionCards, contextChips, participantsControl,
@@ -555,9 +570,10 @@ function sweepFoldsOnce() {
555
570
  // The list by fetching: the fallback when there is no events stream (a
556
571
  // chi web without a hub, or ?dir the server refused: the 400 is read here).
557
572
  async function refresh() {
573
+ if (!viewer.can("sessions")) return;
558
574
  try {
559
575
  store.update({ sessions: await listSessions("updated_at", "desc", { dir: scope.dir }) });
560
- notifications.noticeList(store.sessions);
576
+ notifications?.noticeList(store.sessions);
561
577
  sweepFoldsOnce();
562
578
  } catch (e) {
563
579
  if (e.status !== 400 || !scope.dir) throw e;
@@ -571,6 +587,7 @@ async function refresh() {
571
587
  // (re)connect, then upserts and removals. The selected session's owner and
572
588
  // worker follow its events (a new worker's bridge_up reconnects the stream).
573
589
  function openSessionEvents() {
590
+ if (!viewer.can("sessions")) return;
574
591
  eventsControl = openEvents({
575
592
  // The list redraws the lists and the bar (its children chip, its chain's
576
593
  // ← → links): store.update({sessions}).
@@ -578,19 +595,19 @@ function openSessionEvents() {
578
595
  versionNotices.notice(data);
579
596
  versionNotices.reconnected(data.version);
580
597
  if (data.chi_update) versionNotices.frame(data.chi_update, { snapshot: true });
581
- notifications.noticeSessions("snapshot", data);
598
+ notifications?.noticeSessions("snapshot", data);
582
599
  store.update({ sessions: applySessionEvent(store.sessions, "snapshot", data) });
583
600
  sweepFoldsOnce();
584
601
  const sess = store.sessions.find((s) => s.id === store.selected);
585
602
  if (sess) followSelectedSession(sess);
586
603
  }),
587
604
  session: (data) => store.batch(() => {
588
- notifications.noticeSessions("session", data);
605
+ notifications?.noticeSessions("session", data);
589
606
  store.update({ sessions: applySessionEvent(store.sessions, "session", data) });
590
607
  if (data.session && data.session.id === store.selected) followSelectedSession(data.session);
591
608
  }),
592
609
  session_gone: (data) => {
593
- notifications.noticeSessions("session_gone", data);
610
+ notifications?.noticeSessions("session_gone", data);
594
611
  lists.forget(data.id);
595
612
  store.update({ sessions: applySessionEvent(store.sessions, "session_gone", data) });
596
613
  leaveGoneSession(data.id, "deleted");
@@ -621,17 +638,19 @@ const EVENTS_REOPEN_MS = 3000;
621
638
  // to the same place without ?dir); "all projects" otherwise, with where a
622
639
  // new session starts on the start page.
623
640
  function renderScope() {
624
- const el = $("#scope");
625
- render(scopeTemplate(scope, { error: scopeError, where: () => ({ hash: location.hash }) }), el);
626
- el.hidden = false;
641
+ const el = viewer.control($("#scope"), "sessions");
642
+ if (el) {
643
+ render(scopeTemplate(scope, { error: scopeError, where: () => ({ hash: location.hash }) }), el);
644
+ el.hidden = false;
645
+ }
627
646
  // The tab: "<session title> · Chi · <project>" (updateSessionTitle).
628
647
  tabBase = scope.projectName ? `Chi · ${scope.projectName}` : "Chi";
629
648
  updateSessionTitle();
630
649
  }
631
650
 
632
- createProjectPicker({
633
- el: $("#scope"), scope, scopeError: () => scopeError, api,
634
- });
651
+ if (viewer.can("sessions")) createProjectPicker({ el: $("#scope"), scope, scopeError: () => scopeError, api });
652
+ // The strip, its pill and grip: the session list's (lists_view.js draws into the hidden strip all the same).
653
+ viewer.controls([topStripEl, $("#stripStatus"), $("#stripGrip")], "sessions");
635
654
 
636
655
  // The session lists (lists_view.js): the strip, all sessions, their cards,
637
656
  // select mode, the family and chain popovers.
@@ -676,7 +695,7 @@ const sessionActions = createSessionActions({
676
695
  store,
677
696
  sessions: () => store.sessions,
678
697
  setSessions: (list) => store.update({ sessions: list }),
679
- api: { continueSession, startReview, archiveSession, unarchiveSession, deleteSession, stopSession,
698
+ api: { continueSession, archiveSession, unarchiveSession, deleteSession, stopSession,
680
699
  sessionHolds, stopSessionHolds },
681
700
  eventsLive: () => !!eventsControl,
682
701
  refresh,
@@ -713,7 +732,7 @@ const rename = createRename({
713
732
  onClose: () => queueMicrotask(() => lists.catchUp()),
714
733
  run: (line) => runSessionCommand(line),
715
734
  });
716
- titleRenameBtn.addEventListener("click", () => rename.open());
735
+ titleRenameBtn?.addEventListener("click", () => rename.open());
717
736
  document.addEventListener("scroll", () => rename.reposition(), true);
718
737
  window.addEventListener("resize", () => rename.reposition());
719
738
 
@@ -723,7 +742,7 @@ const { confirmDelete, leaveGoneSession, continueSelected, archiveOne, setArchiv
723
742
  // leaves it. Opened from the page, it closes with history.back().
724
743
  let allViewPushed = false;
725
744
  function allViewOpen() {
726
- return location.hash === ALL_SESSIONS_HASH;
745
+ return !participant && location.hash === ALL_SESSIONS_HASH;
727
746
  }
728
747
  function openAllView() {
729
748
  if (allViewOpen()) return;
@@ -763,7 +782,8 @@ function setSessionHash(id) {
763
782
  function selectFromHash() {
764
783
  const claim = claimFromHash(location.hash);
765
784
  if (claim) ownerClaim.pending(claim);
766
- const intent = hashIntent(location.hash, { selected: store.selected, claim });
785
+ // A participant's page has one session, whatever the hash names.
786
+ const intent = participant ? { kind: "session", id: participant.sessionId } : hashIntent(location.hash, { selected: store.selected, claim });
767
787
  if (intent.kind === "session" && intent.id !== store.selected) select(intent.id);
768
788
  else if (claim) ownerClaim.showPending();
769
789
  else if (intent.kind === "start") clearSelection();
@@ -771,7 +791,7 @@ function selectFromHash() {
771
791
  // The page's claim links (owner_claim.js): one opened here, once drawn, and
772
792
  // annotate's Copy link.
773
793
  const ownerClaim = createOwnerClaim({
774
- historyEl, store, claimTarget: () => participantsControl.claimTarget(),
794
+ historyEl, store, claimTarget: () => participantsControl?.claimTarget() ?? null,
775
795
  toast: (...args) => showToast(...args), copyText, allViewOpen, home: document.body.dataset.home || "",
776
796
  });
777
797
  function applyView() {
@@ -807,7 +827,7 @@ window.addEventListener("hashchange", () => {
807
827
  const composerMode = createComposerMode({
808
828
  els: { body: document.body, prompt: promptEl, hint: composeHintEl, button: actionBtn, attach: attachBtn, empty: emptyEl,
809
829
  history: historyEl },
810
- store, liveTurn, startPage, deliveryControl, fitPrompt, placeToast,
830
+ store, liveTurn, startPage, deliveryControl, fitPrompt, placeToast, steers: () => !participant || participant.deliveryTurn().steer,
811
831
  });
812
832
 
813
833
  function setTurnRunning(running) {
@@ -863,8 +883,8 @@ function clearSelection() {
863
883
  store.update({ selected: null });
864
884
  setSessionHash(null);
865
885
  forgetSession();
866
- contextChips.clear();
867
- participantsControl.load(null);
886
+ contextChips?.clear();
887
+ participantsControl?.load(null);
868
888
  });
869
889
  focusPrompt();
870
890
  }
@@ -882,11 +902,9 @@ function clearNotice() {
882
902
  }
883
903
  promptEl.addEventListener("input", clearNotice);
884
904
  promptEl.addEventListener("input", () => noteDraft());
885
- // An emptied composer lets go of its Apply turn, its Verify claim and its
886
- // Revise.
905
+ // An emptied composer lets go of its Verify claim and its Revise.
887
906
  promptEl.addEventListener("input", () => {
888
907
  if (promptEl.value.trim()) return;
889
- deliveryControl.release();
890
908
  ownerVerify.clear();
891
909
  setReviseAnchor(null);
892
910
  });
@@ -901,22 +919,26 @@ function setMarkdownWarning(warning) {
901
919
  markdownWarningEl.hidden = false;
902
920
  }
903
921
 
904
- // Both from one payload, together; the body's has-editor class follows.
905
- function setCapabilities(capabilities, editorUrl) {
922
+ // Both from one payload, together; the body's has-editor class follows. A
923
+ // show's viewer narrows the page's (viewer.js); none read (forgetSession) is the stamp's again.
924
+ function setCapabilities(capabilities, editorUrl, shownViewer = null) {
906
925
  pageCapabilities = capabilities && typeof capabilities === "object" ? capabilities : {};
907
926
  pageEditorUrl = pageCapabilities.editor === true && typeof editorUrl === "string" && editorUrl ? editorUrl : null;
908
927
  document.body.classList.toggle("has-editor", pageEditorUrl !== null);
928
+ if (shownViewer) viewer.update(shownViewer);
929
+ else if (!capabilities) viewer.reset();
930
+ participant?.shown(shownViewer);
909
931
  }
910
932
 
911
- // What this viewer can do with a ref (refs.js REF_ACTIONS).
912
- function pageViewer() {
933
+ // Where this page can open a ref (refs.js REF_ACTIONS): not the viewer's capabilities (viewer.js).
934
+ function refEditor() {
913
935
  return { editor: pageCapabilities.editor === true, editorUrl: pageEditorUrl };
914
936
  }
915
937
 
916
938
  // Refs anywhere on the page (a tool row's file, its diff lines, an
917
939
  // answer's path:line): one listener set; "Copy path" says so in a toast.
918
- installRefClicks(document.body, pageViewer, {
919
- copy: async (text) => showToast((await copyText(text)) ? "Path copied" : "Couldn't copy the path"),
940
+ installRefClicks(document.body, refEditor, {
941
+ copy: async (text) => showToast((await copyText(text)) ? "Path copied" : "Couldn't copy the path"), whatChiHas: wsPreview?.whatChiHas ?? null,
920
942
  });
921
943
 
922
944
  // Sticky-follow scroll: only auto-scroll to the bottom while the user is
@@ -947,41 +969,11 @@ infoTextEl.addEventListener("click", async (e) => {
947
969
  showToast((await copyText(store.selected)) ? "Session id copied" : "Couldn't copy the session id");
948
970
  });
949
971
 
950
- // Apply (review_apply.js) under a participant's review turn that just
951
- // ended live ({turn_id, author, author_name}, from its turn_started), once:
952
- // a reload draws it from the history (turn_block.js).
953
- function placeApply(data) {
954
- const badge = authorBadge(data.author, data.author_name);
955
- if (!badge || historyEl.querySelector(`.review-apply[data-apply-turn="${CSS.escape(data.turn_id)}"]`)) return;
956
- appendToHistory(elementOf(applyRowTemplate(data.turn_id, badge)));
957
- }
958
-
959
972
  // The owner's Verify (owner_verify.js): verdict cards, Verify fresh, the claim.
960
973
  const ownerVerify = createOwnerVerify({
961
974
  historyEl, store, api, claim: ownerClaim, liveTurn, toast: (text) => showToast(text),
962
975
  });
963
976
 
964
- // Apply: the owner's Apply turn into the composer, after what is typed
965
- // there; never sent from here.
966
- historyEl.addEventListener("click", async (e) => {
967
- const button = e.target.closest(".review-apply-btn");
968
- if (!button || !store.selected) return;
969
- const id = store.selected;
970
- button.disabled = true;
971
- try {
972
- const text = await fetchApply(id, button.dataset.applyTurn);
973
- if (id === store.selected) {
974
- fillComposer(applyComposerText(promptEl.value, text));
975
- // The owner's own turn: queued after a running one, never steered in.
976
- deliveryControl.hold();
977
- }
978
- } catch (err) {
979
- showToast(err.message);
980
- } finally {
981
- button.disabled = false;
982
- }
983
- });
984
-
985
977
  // The session bar (info_bar_model.js sessionBar): its buttons, and the
986
978
  // info line rendered by info_bar.js.
987
979
  // The open session waits on the user: its card is up, or its summary says so
@@ -992,15 +984,12 @@ function sessionWaits() {
992
984
  }
993
985
  function updateInfoBar() {
994
986
  annotateBar?.refresh();
987
+ if (participant) return [participant.drawBar(), updateSessionTitle()];
995
988
  const { buttons, bar } = sessionBar({
996
989
  id: store.selected, state: store.current, sessions: store.sessions, versions: versionNotices.versions(), cardTitle: (s) => lists.cardTitle(s),
997
990
  continuing: sessionActions.continuing, restarting: versionNotices.restarting, streaming: sessionSync.hasStream(), running: liveTurn.running, waiting: sessionWaits(),
998
- workingSet: workingSet ? workingSet.chip() : undefined, participants: participantsControl.chip(),
991
+ workingSet: workingSet ? workingSet.chip() : undefined, participants: participantsControl?.chip() ?? null,
999
992
  });
1000
- const stopBtn = document.getElementById("infoStopBtn");
1001
- const deleteBtn = document.getElementById("infoDeleteBtn");
1002
- const archiveBtn = document.getElementById("infoArchiveBtn");
1003
- const continueBtn = document.getElementById("infoContinueBtn");
1004
993
  if (continueBtn) {
1005
994
  continueBtn.style.display = buttons.continue.shown ? "" : "none";
1006
995
  continueBtn.disabled = buttons.continue.disabled;
@@ -1016,6 +1005,8 @@ function updateInfoBar() {
1016
1005
  archiveBtn.title = buttons.archive.title;
1017
1006
  }
1018
1007
  if (stopBtn) stopBtn.style.display = buttons.stop.shown ? "" : "none";
1008
+ // The ⚙ chip only with its panel (session_controls, viewer.js).
1009
+ if (bar && !settingsControl) bar.settings = null;
1019
1010
  drawFoldControls();
1020
1011
  // No session: the start page hides the info bar (the storage path is on
1021
1012
  // #/sessions). The session clock ticks every second while a turn runs:
@@ -1023,7 +1014,7 @@ function updateInfoBar() {
1023
1014
  // mid-press) stay.
1024
1015
  renderInfoBar(infoTextEl, bar);
1025
1016
  const { folded } = barFold.update({ bar, buttons });
1026
- moreSheet.update({ bar, buttons, folded });
1017
+ moreSheet?.update({ bar, buttons, folded });
1027
1018
  updateSessionTitle();
1028
1019
  // A fresh link's picker follows what the bar follows: its model, its
1029
1020
  // owner, a next link continued from elsewhere.
@@ -1035,6 +1026,7 @@ function updateInfoBar() {
1035
1026
  // browser tab names it too. It follows the card's (openTitle): a chain link
1036
1027
  // reads its card's title (cardTitle), whatever opener it was sent.
1037
1028
  function shownTitle() {
1029
+ if (participant) return participant.title();
1038
1030
  const shown = store.selected ? lists.sessionsById().get(store.selected) : null;
1039
1031
  const first = store.current.firstPreview || "";
1040
1032
  const raw = !store.selected ? "" : openTitle({ shown, first, cardTitle: (s) => lists.cardTitle(s) });
@@ -1053,13 +1045,14 @@ function updateSessionTitle() {
1053
1045
  if (sessionTitleEl.textContent !== text) sessionTitleEl.textContent = text;
1054
1046
  if (sessionTitleRowEl.hidden !== !text) sessionTitleRowEl.hidden = !text;
1055
1047
  const renamable = !!text && renameShown(store.current.owner);
1056
- if (titleRenameBtn.hidden !== !renamable) titleRenameBtn.hidden = !renamable;
1048
+ if (titleRenameBtn && titleRenameBtn.hidden !== !renamable) titleRenameBtn.hidden = !renamable;
1057
1049
  const tip = text ? title : "";
1058
1050
  if (sessionTitleEl.title !== tip) sessionTitleEl.title = tip;
1059
1051
  const tab = tabBase === null ? null : tabTitle({ title, base: tabBase });
1060
1052
  if (tab !== null && tab !== tabShown) {
1061
1053
  tabShown = tab;
1062
- notifications.setBaseTitle(tab);
1054
+ if (notifications) notifications.setBaseTitle(tab);
1055
+ else document.title = tab;
1063
1056
  }
1064
1057
  rename.follow(store.selected);
1065
1058
  rename.reposition();
@@ -1139,7 +1132,7 @@ function turnEndStatus(data) {
1139
1132
 
1140
1133
  // The stream's event handlers (stream_handlers.js); renderSessionView
1141
1134
  // replays a snapshot through them too.
1142
- const streamHandlers = createStreamHandlers({
1135
+ const streamHandlers = (participant ? participant.wrapHandlers : (handlers) => handlers)(createStreamHandlers({
1143
1136
  selected: () => store.selected,
1144
1137
  store,
1145
1138
  clientId,
@@ -1152,7 +1145,6 @@ const streamHandlers = createStreamHandlers({
1152
1145
  contextChips,
1153
1146
  workingSet,
1154
1147
  participantsControl,
1155
- placeApply,
1156
1148
  placeVerdict: ownerVerify.placeVerdict,
1157
1149
  restoreVerify: (anchor) => ownerVerify.set(anchor),
1158
1150
  restoreRevise,
@@ -1191,7 +1183,7 @@ const streamHandlers = createStreamHandlers({
1191
1183
  syncModelPick: startPage.commandRan,
1192
1184
  objectivesUpdated: (data) => objectives.update(data),
1193
1185
  cardActionFailed: cards.actionFailed,
1194
- });
1186
+ }));
1195
1187
 
1196
1188
  async function refreshTimingFromSession() {
1197
1189
  if (!store.selected) return;
@@ -1216,7 +1208,7 @@ function addCreatedSession(created) {
1216
1208
 
1217
1209
  // /model, !ls … from the composer, and a control's command (the llm ctx
1218
1210
  // and thinking chips): composer.js.
1219
- const composerCommands = createComposerCommands({
1211
+ const composerCommands = viewer.can("session_controls") ? createComposerCommands({
1220
1212
  session: () => store.selected,
1221
1213
  clientId,
1222
1214
  sendCommand,
@@ -1239,7 +1231,7 @@ const composerCommands = createComposerCommands({
1239
1231
  focusPrompt({ open: false });
1240
1232
  },
1241
1233
  },
1242
- });
1234
+ }) : null;
1243
1235
 
1244
1236
  // The composer's send (send_turn.js): a line into the open session, or a
1245
1237
  // new session first on the start page.
@@ -1283,7 +1275,8 @@ const sendTurnControl = createSendTurn({
1283
1275
  followWokenWorker,
1284
1276
  refreshHistory,
1285
1277
  leaveGoneSession,
1286
- runCommand: (command) => composerCommands.send(command),
1278
+ closesOn: participant?.refused ?? null,
1279
+ runCommand: composerCommands ? (command) => composerCommands.send(command) : null,
1287
1280
  toast: showToast,
1288
1281
  });
1289
1282
  // +delivery+: the composer's choice for a running turn (Alt+Enter: queue;
@@ -1293,20 +1286,19 @@ function handleSendTurn({ delivery = null } = {}) {
1293
1286
  }
1294
1287
 
1295
1288
  function runSessionCommand(line) {
1296
- return composerCommands.run(line);
1289
+ return composerCommands?.run(line);
1297
1290
  }
1298
1291
 
1299
1292
  function clearComposer() {
1300
1293
  promptEl.value = "";
1301
- deliveryControl.release();
1302
1294
  fitPrompt();
1303
1295
  }
1304
1296
 
1305
- // A queue (Alt+Enter, or an Apply turn's Enter) to a worker that can't
1306
- // queue (it would steer): not sent, the text kept, a note says why.
1297
+ // A queue (Alt+Enter) to a worker that can't queue (it would steer): not
1298
+ // sent, the text kept, a note says why.
1307
1299
  function queueRefused(altKey) {
1308
1300
  if (!store.selected || !liveTurn.running || store.current.workerFeatures.includes("delivery")) return false;
1309
- if (!altKey && !deliveryControl.held()) return false;
1301
+ if (!altKey) return false;
1310
1302
  addCommandBubble({ label: null, line: promptEl.value.trim(), text: QUEUE_NEEDS_WORKER, failed: true });
1311
1303
  return true;
1312
1304
  }
@@ -1321,7 +1313,7 @@ async function handleCancel() {
1321
1313
  // session (from all sessions too).
1322
1314
  // The typed draft stays in the composer: paste in a session, then + new session
1323
1315
  // starts from it (with the model picker). clearSelection leaves #prompt alone.
1324
- $("#newBtn").addEventListener("click", () => {
1316
+ viewer.control($("#newBtn"), "sessions")?.addEventListener("click", () => {
1325
1317
  if (allViewOpen()) leaveAllView("");
1326
1318
  clearSelection();
1327
1319
  startPage.loadModels({ asked: true });
@@ -1347,7 +1339,8 @@ const composer = mountComposer({
1347
1339
  toast: (text) => showToast(text),
1348
1340
  onWrite: () => noteDraft(),
1349
1341
  // ↑/↓: the prompt history shared with the TUI.
1350
- loadHistory: fetchHistory,
1342
+ loadHistory: viewer.can("prompt_history") ? fetchHistory : null,
1343
+ imagesOff: viewer.can("images") ? null : IMAGES_NOT_HERE,
1351
1344
  // Alt/Option+Enter: queued for after the running turn (D6), only to a
1352
1345
  // worker that queues (else it would steer): the text stays, a note says why.
1353
1346
  send: ({ queue }) => {
@@ -1412,19 +1405,19 @@ document.addEventListener("keydown", (e) => {
1412
1405
  const commandList = createCommandList({
1413
1406
  list: $("#commandList"),
1414
1407
  prompt: promptEl,
1415
- commands: () => (store.selected && store.current.owner !== "tui" ? store.current.commands : []),
1408
+ commands: () => (viewer.can("session_controls") && store.selected && store.current.owner !== "tui" ? store.current.commands : []),
1416
1409
  afterPick: () => {
1417
1410
  noteDraft();
1418
1411
  fitPrompt();
1419
1412
  },
1420
1413
  });
1421
1414
 
1422
- $("#infoStopBtn").addEventListener("click", () => sessionActions.stopSelected());
1423
- $("#infoDeleteBtn").addEventListener("click", () => {
1415
+ stopBtn?.addEventListener("click", () => sessionActions.stopSelected());
1416
+ deleteBtn?.addEventListener("click", () => {
1424
1417
  if (store.selected) confirmDelete(store.selected);
1425
1418
  });
1426
- $("#infoContinueBtn").addEventListener("click", () => continueSelected());
1427
- $("#infoArchiveBtn").addEventListener("click", () => sessionActions.toggleArchiveSelected());
1419
+ continueBtn?.addEventListener("click", () => continueSelected());
1420
+ archiveBtn?.addEventListener("click", () => sessionActions.toggleArchiveSelected());
1428
1421
 
1429
1422
  // The new link's composer: the opener (openerText: the previous link's own,
1430
1423
  // else the constant). A draft written in this session (or the new link, or
@@ -1457,6 +1450,7 @@ function restoreDraft(draft, opener) {
1457
1450
  const toasts = createToasts({ el: $("#toast"), onChange: placeToast });
1458
1451
  // chi's versions, the update sheet and the worker Restart (version_notices.js).
1459
1452
  // After toasts: openSessionEvents, its first caller, runs at boot.
1453
+ if (participant) onAuthLost(participant.linkEnded);
1460
1454
  const versionNotices = createVersionNotices({
1461
1455
  store, toasts, dialog: $("#updateSheet"), loadedVersion: document.body.dataset.version,
1462
1456
  api: { updateChi, restartWorkers, restartWeb, restartSession },
@@ -1515,7 +1509,7 @@ turnRoots().forEach((root) => installCopy(root));
1515
1509
  // chi-ui blocks (inline_widgets.js) are a core drawer, ahead of the bundles'
1516
1510
  // renderers; a picks' Fill reply only fills the composer.
1517
1511
  const widgets = createWidgetDrawer({ roots: turnRoots(), composerText: () => promptEl.value, fillComposer });
1518
- createBlockHost({ roots: turnRoots(), sessionId: () => store.selected, drawers: [widgets] });
1512
+ createBlockHost({ roots: turnRoots(), sessionId: () => store.selected, drawers: [widgets], renderers: viewer.can("block_renderers") });
1519
1513
  // A steps block, a thinking block and the recap open and close by hand
1520
1514
  // with their height animated (details_motion.js), in the history and on
1521
1515
  // the stage.
@@ -1528,34 +1522,34 @@ installAnswerFold({
1528
1522
  });
1529
1523
  // Revise stacks (revise_stack.js): the superseded versions fold to stubs,
1530
1524
  // the top answer gets its version chip, a final answer its Revise button.
1531
- reviseStacks = installReviseStacks({
1525
+ reviseStacks = viewer.can("revise") || viewer.can("revise_own_turn") ? installReviseStacks({
1532
1526
  historyEl,
1533
1527
  sessionId: () => store.selected,
1534
1528
  projectRoot: () => store.sessions.find((s) => s.id === store.selected)?.project_root ?? null,
1535
1529
  running: () => (liveTurn.running ? { turnId: liveTurn.timing.turnId || null } : null),
1536
1530
  verifyTurn: (turnId) => (store.current.verdicts || []).some((v) => v.check_turn_id === turnId),
1537
- unavailable: reviseUnavailable,
1538
- armed: () => pendingReviseAnchor?.turn_id ?? null,
1531
+ unavailable: reviseUnavailable, unavailableText: reviseOffText,
1532
+ armed: () => pendingReviseAnchor?.turn_id ?? null, mayRevise: participant ? participantMayRevise(participant.closed) : undefined,
1539
1533
  onRevise: (anchor) => {
1540
1534
  setReviseAnchor(anchor);
1541
1535
  openForVisit();
1542
1536
  focusPrompt();
1543
1537
  },
1544
- });
1538
+ }) : null;
1545
1539
 
1546
1540
  // Notifications (notifications.js): an OS notification and a title count
1547
1541
  // when a session needs the user while this tab is not in front. On a
1548
1542
  // project's page the Home Screen app's device tidy-up still covers every
1549
1543
  // project: it gets a stream of every session of its own (allEvents).
1550
- const notifications = createNotifications({
1544
+ const notifications = viewer.can("push") ? createNotifications({
1551
1545
  button: $("#notifyBtn"),
1552
1546
  scoped: !!scope.dir,
1553
1547
  allEvents: (handlers, opts) => openEvents(handlers, opts),
1554
- });
1548
+ }) : null;
1555
1549
 
1556
1550
  // The strip hidden or shown (strip_hidden.js): its grip, the saved choice and
1557
1551
  // the short window's rule; applied now.
1558
- createStripHidden({
1552
+ if (viewer.can("sessions")) createStripHidden({
1559
1553
  gripEl: $("#stripGrip"), body: document.body, onApply: () => updateSessionTitle(),
1560
1554
  closeFamilyPop: () => lists.familyPop.close(),
1561
1555
  });
@@ -1575,7 +1569,7 @@ document.addEventListener("keydown", (e) => {
1575
1569
  // before it (none at load) would redraw nothing.
1576
1570
  store.on("lists", () => lists.render());
1577
1571
  store.on("paintActive", () => lists.paintActive());
1578
- store.on("settingsPanel", () => settingsControl.refresh());
1572
+ store.on("settingsPanel", () => settingsControl?.refresh());
1579
1573
  // The working set's list offers pin only under forget.
1580
1574
  store.on("workingSetStrategy", () => workingSet?.strategyChanged());
1581
1575
  store.on("featureGates", () => featureGates.check(store.current));
@@ -1583,7 +1577,7 @@ store.on("composer", composerMode.update);
1583
1577
  store.on("composer", () => objectives.redraw());
1584
1578
  // The answers' Revise buttons follow liveTurn.running too (none on the
1585
1579
  // running turn's answer), which touches the composer.
1586
- store.on("composer", () => reviseStacks.decorate());
1580
+ store.on("composer", () => reviseStacks?.decorate());
1587
1581
  store.on("infoBar", updateInfoBar);
1588
1582
 
1589
1583
  applyView();
@@ -1599,7 +1593,7 @@ store.batch(() => {
1599
1593
  store.touch("composer");
1600
1594
  store.touch("infoBar");
1601
1595
  });
1602
- startPage.loadModels();
1596
+ if (viewer.can("models")) startPage.loadModels();
1603
1597
  // The list: the hub's stream when the browser has EventSource, else fetched.
1604
1598
  if (typeof globalThis.EventSource === "function") openSessionEvents();
1605
1599
  else refresh();