samagotchi 0.170.0 → 0.172.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -1
  3. data/bin/chi +6 -4
  4. data/docs/architecture.md +26 -9
  5. data/docs/bundles.md +4 -21
  6. data/docs/cli.md +81 -97
  7. data/docs/configuration.md +12 -14
  8. data/docs/context.md +5 -6
  9. data/docs/guardrails.md +57 -96
  10. data/docs/hooks.md +3 -4
  11. data/docs/internals/attached-context.md +6 -7
  12. data/docs/internals/background-tasks.md +4 -3
  13. data/docs/internals/block-renderers.md +2 -2
  14. data/docs/internals/bridge.md +34 -7
  15. data/docs/internals/context-telemetry.md +13 -1
  16. data/docs/internals/engine.md +25 -13
  17. data/docs/internals/inline-widgets.md +1 -1
  18. data/docs/internals/objectives.md +4 -6
  19. data/docs/internals/participants.md +340 -249
  20. data/docs/internals/prompt-caching.md +4 -5
  21. data/docs/internals/web-frontend.md +185 -35
  22. data/docs/internals/working-set.md +71 -5
  23. data/docs/memory.md +1 -1
  24. data/docs/plugins.md +2 -16
  25. data/docs/releasing.md +2 -1
  26. data/docs/scheduling.md +1 -1
  27. data/docs/sessions.md +17 -48
  28. data/docs/sub-agent.md +2 -2
  29. data/docs/system-one.md +2 -2
  30. data/docs/testing.md +56 -7
  31. data/lib/samagotchi/bridge/card_store.rb +1 -0
  32. data/lib/samagotchi/bridge/sse_writer.rb +1 -0
  33. data/lib/samagotchi/bridge/turn_accumulator.rb +8 -5
  34. data/lib/samagotchi/bridge.rb +64 -20
  35. data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
  36. data/lib/samagotchi/bundle_command/test_run.rb +1 -0
  37. data/lib/samagotchi/bundle_command/try/run.rb +1 -0
  38. data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
  39. data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
  40. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
  41. data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
  42. data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
  43. data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
  44. data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
  45. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  46. data/lib/samagotchi/client_id.rb +126 -67
  47. data/lib/samagotchi/command_intake.rb +15 -3
  48. data/lib/samagotchi/compat.rb +6 -1
  49. data/lib/samagotchi/context_candidate_choice.rb +1 -3
  50. data/lib/samagotchi/context_candidates.rb +3 -4
  51. data/lib/samagotchi/continue_offer.rb +9 -2
  52. data/lib/samagotchi/delivery.rb +36 -12
  53. data/lib/samagotchi/empty_answer_error.rb +5 -0
  54. data/lib/samagotchi/engine/cards.rb +3 -0
  55. data/lib/samagotchi/engine/context_judge.rb +5 -3
  56. data/lib/samagotchi/engine/events.rb +4 -0
  57. data/lib/samagotchi/engine/hooks.rb +3 -0
  58. data/lib/samagotchi/engine/messages.rb +5 -0
  59. data/lib/samagotchi/engine/model_settings.rb +2 -0
  60. data/lib/samagotchi/engine/models.rb +10 -0
  61. data/lib/samagotchi/engine/objectives.rb +6 -0
  62. data/lib/samagotchi/engine/participants.rb +18 -14
  63. data/lib/samagotchi/engine/plugins.rb +8 -0
  64. data/lib/samagotchi/engine/questions.rb +3 -0
  65. data/lib/samagotchi/engine/recap.rb +1 -0
  66. data/lib/samagotchi/engine/session.rb +4 -0
  67. data/lib/samagotchi/engine/side_requests.rb +9 -0
  68. data/lib/samagotchi/engine/steering.rb +2 -0
  69. data/lib/samagotchi/engine/toolkit.rb +5 -0
  70. data/lib/samagotchi/engine/turn_end.rb +7 -0
  71. data/lib/samagotchi/engine/turn_helpers.rb +8 -0
  72. data/lib/samagotchi/engine/verify.rb +2 -0
  73. data/lib/samagotchi/engine.rb +8 -3
  74. data/lib/samagotchi/event_fanout.rb +22 -1
  75. data/lib/samagotchi/grants.rb +33 -22
  76. data/lib/samagotchi/guardrail_wiring.rb +23 -18
  77. data/lib/samagotchi/guardrails/approval_use.rb +59 -0
  78. data/lib/samagotchi/guardrails/approvals.rb +9 -11
  79. data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
  80. data/lib/samagotchi/guardrails/gate.rb +10 -5
  81. data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
  82. data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
  83. data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
  84. data/lib/samagotchi/guardrails/review_paths.rb +2 -3
  85. data/lib/samagotchi/guardrails.rb +1 -1
  86. data/lib/samagotchi/image_store.rb +51 -12
  87. data/lib/samagotchi/kernel_loop.rb +7 -1
  88. data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
  89. data/lib/samagotchi/llm_context_stale.rb +4 -1
  90. data/lib/samagotchi/llm_context_strategy.rb +2 -0
  91. data/lib/samagotchi/objectives.rb +1 -4
  92. data/lib/samagotchi/objectives_audit.rb +1 -1
  93. data/lib/samagotchi/objectives_track.rb +1 -1
  94. data/lib/samagotchi/owner_prompt.rb +3 -6
  95. data/lib/samagotchi/parent_report.rb +1 -0
  96. data/lib/samagotchi/participant_messages.rb +48 -4
  97. data/lib/samagotchi/participant_revise.rb +61 -0
  98. data/lib/samagotchi/participant_turn_mode.rb +50 -0
  99. data/lib/samagotchi/participant_uploads.rb +98 -0
  100. data/lib/samagotchi/participants.rb +21 -12
  101. data/lib/samagotchi/participants_watch.rb +2 -2
  102. data/lib/samagotchi/plugin/api.rb +2 -2
  103. data/lib/samagotchi/plugin/attached_context.rb +1 -1
  104. data/lib/samagotchi/plugin/context.rb +0 -4
  105. data/lib/samagotchi/plugin/sessions.rb +1 -25
  106. data/lib/samagotchi/reply_wait/poll.rb +5 -1
  107. data/lib/samagotchi/revise_anchor.rb +9 -0
  108. data/lib/samagotchi/run_options.rb +2 -3
  109. data/lib/samagotchi/send_command.rb +15 -10
  110. data/lib/samagotchi/session.rb +0 -3
  111. data/lib/samagotchi/session_access/contract.rb +1 -10
  112. data/lib/samagotchi/session_access/local.rb +10 -23
  113. data/lib/samagotchi/session_access/remote.rb +9 -20
  114. data/lib/samagotchi/session_access.rb +12 -16
  115. data/lib/samagotchi/session_chain.rb +4 -6
  116. data/lib/samagotchi/session_commands.rb +6 -3
  117. data/lib/samagotchi/session_continue.rb +1 -2
  118. data/lib/samagotchi/session_inbox.rb +20 -12
  119. data/lib/samagotchi/session_manager/delivery.rb +32 -5
  120. data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
  121. data/lib/samagotchi/session_manager/listing.rb +5 -0
  122. data/lib/samagotchi/session_manager/spawn.rb +2 -2
  123. data/lib/samagotchi/session_manager/worker_command.rb +9 -0
  124. data/lib/samagotchi/session_participants.rb +12 -8
  125. data/lib/samagotchi/session_review.rb +5 -7
  126. data/lib/samagotchi/session_stores.rb +3 -1
  127. data/lib/samagotchi/share_command.rb +10 -12
  128. data/lib/samagotchi/share_terms.rb +41 -0
  129. data/lib/samagotchi/steer.rb +8 -14
  130. data/lib/samagotchi/system_prompt.rb +16 -25
  131. data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
  132. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
  133. data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
  134. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
  135. data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
  136. data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
  137. data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
  138. data/lib/samagotchi/terminal_ui.rb +1 -2
  139. data/lib/samagotchi/testing/sessions.rb +2 -10
  140. data/lib/samagotchi/tool_runner.rb +42 -9
  141. data/lib/samagotchi/toolkit.rb +4 -22
  142. data/lib/samagotchi/toolkit_suggest.rb +3 -3
  143. data/lib/samagotchi/tools/deferred_tools.rb +1 -0
  144. data/lib/samagotchi/tools/execute.rb +11 -45
  145. data/lib/samagotchi/tools/leftovers.rb +122 -0
  146. data/lib/samagotchi/tools/memory.rb +88 -25
  147. data/lib/samagotchi/tools/task_get.rb +1 -0
  148. data/lib/samagotchi/tools/task_list.rb +3 -2
  149. data/lib/samagotchi/tools/task_record.rb +6 -4
  150. data/lib/samagotchi/tools/task_runtime.rb +199 -20
  151. data/lib/samagotchi/tools/task_wait.rb +4 -3
  152. data/lib/samagotchi/turn_anchors.rb +0 -3
  153. data/lib/samagotchi/turn_context.rb +1 -1
  154. data/lib/samagotchi/turn_origin.rb +1 -1
  155. data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
  156. data/lib/samagotchi/turn_stages/objectives.rb +2 -2
  157. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
  158. data/lib/samagotchi/turn_stages/verify_anchors.rb +13 -1
  159. data/lib/samagotchi/update_hint.rb +3 -1
  160. data/lib/samagotchi/verify_anchor.rb +6 -0
  161. data/lib/samagotchi/verify_fresh.rb +1 -1
  162. data/lib/samagotchi/verify_fresh_origin.rb +13 -11
  163. data/lib/samagotchi/version.rb +1 -1
  164. data/lib/samagotchi/web/app.rb +45 -82
  165. data/lib/samagotchi/web/participant_access.rb +139 -40
  166. data/lib/samagotchi/web/participant_images.rb +185 -0
  167. data/lib/samagotchi/web/participant_review.rb +22 -142
  168. data/lib/samagotchi/web/participant_show.rb +241 -0
  169. data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
  170. data/lib/samagotchi/web/participant_view.rb +334 -27
  171. data/lib/samagotchi/web/participants_admin.rb +21 -40
  172. data/lib/samagotchi/web/public/annotate_bar.css +1 -2
  173. data/lib/samagotchi/web/public/annotate_bar.js +1 -2
  174. data/lib/samagotchi/web/public/app.js +126 -132
  175. data/lib/samagotchi/web/public/block_host.js +7 -4
  176. data/lib/samagotchi/web/public/bubbles.js +9 -1
  177. data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
  178. data/lib/samagotchi/web/public/chip_popover.js +5 -4
  179. data/lib/samagotchi/web/public/claim_link.js +4 -4
  180. data/lib/samagotchi/web/public/composer.css +4 -6
  181. data/lib/samagotchi/web/public/composer_mode.js +11 -6
  182. data/lib/samagotchi/web/public/composer_mount.js +4 -4
  183. data/lib/samagotchi/web/public/ctx.js +12 -3
  184. data/lib/samagotchi/web/public/data.js +2 -10
  185. data/lib/samagotchi/web/public/delivery_line.js +49 -63
  186. data/lib/samagotchi/web/public/history_shape.js +5 -1
  187. data/lib/samagotchi/web/public/images.js +7 -1
  188. data/lib/samagotchi/web/public/index.html +50 -34
  189. data/lib/samagotchi/web/public/info_bar_model.js +2 -1
  190. data/lib/samagotchi/web/public/live_turn.js +1 -1
  191. data/lib/samagotchi/web/public/markdown_place.js +5 -4
  192. data/lib/samagotchi/web/public/owner_claim.js +5 -5
  193. data/lib/samagotchi/web/public/owner_verify.js +0 -2
  194. data/lib/samagotchi/web/public/participant_bar.js +107 -0
  195. data/lib/samagotchi/web/public/participant_main.js +289 -0
  196. data/lib/samagotchi/web/public/participant_model.js +5 -292
  197. data/lib/samagotchi/web/public/participant_names.js +17 -8
  198. data/lib/samagotchi/web/public/participant_revise.js +66 -0
  199. data/lib/samagotchi/web/public/participants_panel.js +32 -74
  200. data/lib/samagotchi/web/public/question_cards.js +14 -3
  201. data/lib/samagotchi/web/public/refs.js +53 -36
  202. data/lib/samagotchi/web/public/reload_check.js +70 -14
  203. data/lib/samagotchi/web/public/revise_stack.js +21 -10
  204. data/lib/samagotchi/web/public/send_turn.js +28 -29
  205. data/lib/samagotchi/web/public/session_actions.js +4 -45
  206. data/lib/samagotchi/web/public/session_fields.js +1 -2
  207. data/lib/samagotchi/web/public/session_state.js +12 -7
  208. data/lib/samagotchi/web/public/session_sync.js +9 -2
  209. data/lib/samagotchi/web/public/session_view.js +14 -5
  210. data/lib/samagotchi/web/public/settings_panel.js +4 -18
  211. data/lib/samagotchi/web/public/stage_answer.js +56 -0
  212. data/lib/samagotchi/web/public/stage_asking.js +7 -5
  213. data/lib/samagotchi/web/public/stage_cloud.js +93 -0
  214. data/lib/samagotchi/web/public/stage_dom.js +100 -0
  215. data/lib/samagotchi/web/public/stage_handoff.js +154 -0
  216. data/lib/samagotchi/web/public/stage_owner_wait.js +35 -0
  217. data/lib/samagotchi/web/public/stage_pager.js +59 -0
  218. data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
  219. data/lib/samagotchi/web/public/stage_view.js +103 -410
  220. data/lib/samagotchi/web/public/stage_waiting.js +74 -6
  221. data/lib/samagotchi/web/public/start_page.js +12 -33
  222. data/lib/samagotchi/web/public/start_settings.js +24 -78
  223. data/lib/samagotchi/web/public/start_toolkit.js +6 -10
  224. data/lib/samagotchi/web/public/storage.js +22 -0
  225. data/lib/samagotchi/web/public/stream_handlers.js +3 -10
  226. data/lib/samagotchi/web/public/tokens.css +1 -1
  227. data/lib/samagotchi/web/public/turn_block.js +2 -5
  228. data/lib/samagotchi/web/public/turn_events.js +30 -12
  229. data/lib/samagotchi/web/public/turn_html.js +9 -2
  230. data/lib/samagotchi/web/public/turn_pieces.js +3 -4
  231. data/lib/samagotchi/web/public/turn_range.js +1 -2
  232. data/lib/samagotchi/web/public/verify_target.js +2 -4
  233. data/lib/samagotchi/web/public/viewer.js +59 -0
  234. data/lib/samagotchi/web/public/viewer_self.js +59 -0
  235. data/lib/samagotchi/web/public/working_set.js +11 -5
  236. data/lib/samagotchi/web/public/working_set_view.js +53 -8
  237. data/lib/samagotchi/web/public/ws_cards.js +89 -0
  238. data/lib/samagotchi/web/public/ws_peek.js +106 -0
  239. data/lib/samagotchi/web/public/ws_preview.css +126 -0
  240. data/lib/samagotchi/web/public/ws_reader.js +319 -0
  241. data/lib/samagotchi/web/public/ws_timeline.js +200 -0
  242. data/lib/samagotchi/web/public/ws_way_in.js +25 -0
  243. data/lib/samagotchi/web/qr.rb +1 -1
  244. data/lib/samagotchi/web/session_control.rb +42 -15
  245. data/lib/samagotchi/web/session_create.rb +6 -72
  246. data/lib/samagotchi/web/session_show.rb +75 -28
  247. data/lib/samagotchi/web/session_summary.rb +1 -4
  248. data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
  249. data/lib/samagotchi/web/viewer.rb +70 -0
  250. data/lib/samagotchi/web/working_set_routes.rb +132 -0
  251. data/lib/samagotchi/worker.rb +35 -28
  252. data/lib/samagotchi/worker_inbound.rb +4 -3
  253. data/lib/samagotchi/worker_link.rb +17 -0
  254. data/lib/samagotchi/working_set.rb +322 -11
  255. metadata +32 -13
  256. data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
  257. data/lib/samagotchi/participant_mode.rb +0 -86
  258. data/lib/samagotchi/review_apply.rb +0 -131
  259. data/lib/samagotchi/review_command.rb +0 -123
  260. data/lib/samagotchi/review_start.rb +0 -196
  261. data/lib/samagotchi/web/public/participant.html +0 -218
  262. data/lib/samagotchi/web/public/participant.js +0 -719
  263. data/lib/samagotchi/web/public/participant_annotate.js +0 -76
  264. data/lib/samagotchi/web/public/review_apply.js +0 -34
  265. data/lib/samagotchi/web/public/review_history.js +0 -72
  266. data/lib/samagotchi/web/public/review_start.js +0 -55
  267. data/lib/samagotchi/web/public/tools_overview.js +0 -42
@@ -1,76 +0,0 @@
1
- // Annotate on the participant page (participant.js): a selection in the
2
- // Plan (the review's subject) or in the thread quotes it into the comment
3
- // box, with where it came from, the way the owner's page does
4
- // (annotations.js, annotate_bar.js):
5
- //
6
- // From docs/plan.md:
7
- // > step 3
8
- //
9
- // Is step 3 safe?
10
- //
11
- // A model reply carries no label (the owner's answers carry none); a
12
- // comment names its author ("From Alex's comment:", "From my earlier
13
- // comment:"). Not annotatable: the reply still streaming, tool rows,
14
- // status lines, time gaps, the header. The bar's source and quote options
15
- // (createAnnotateBar); no DOM state beyond Element#closest, so it runs
16
- // under `node --test` with stand-ins. A module of its own: static JS is
17
- // cached at unversioned URLs, and a new export on an old module would
18
- // blank the page.
19
-
20
- import { quoteBlock } from "./annotations.js";
21
- import { isParticipantAuthor } from "./participant_model.js";
22
-
23
- // Where a node on the participant page came from: { kind, root, … } where
24
- // root is the element a selection is clipped to, or null.
25
- // plan: { path } the subject shown (#planDoc's data-path)
26
- // reply: a model reply's bubble
27
- // comment: { by, name } a prompt's bubble; by is "me", "participant",
28
- // "owner" or "automatic" (its .p-msg's data-by), name the
29
- // participant's (data-name)
30
- export function participantSource(node) {
31
- const el = node && node.nodeType === 3 ? node.parentElement : node;
32
- if (!el?.closest) return null;
33
- const plan = el.closest("#planDoc");
34
- if (plan) {
35
- // The "only the first part is shown" note isn't the subject's text.
36
- if (el.closest(".p-plan-note")) return null;
37
- return { kind: "plan", path: plan.dataset?.path || "", root: plan };
38
- }
39
- const bubble = el.closest(".p-bubble");
40
- const msg = bubble?.closest(".p-msg");
41
- if (!msg || msg.classList.contains("live")) return null;
42
- if (msg.classList.contains("reply")) return { kind: "reply", root: bubble };
43
- if (msg.classList.contains("user")) {
44
- return { kind: "comment", by: msg.dataset?.by || "owner", name: msg.dataset?.name || "", root: bubble };
45
- }
46
- return null;
47
- }
48
-
49
- // The line naming +source+ above the quote, or null (a reply).
50
- export function participantLabel(source) {
51
- if (source?.kind === "plan") return source.path ? `From ${source.path}:` : "From the plan:";
52
- if (source?.kind !== "comment") return null;
53
- if (source.by === "me") return "From my earlier comment:";
54
- if (source.by === "participant") return `From ${source.name || "a participant"}'s comment:`;
55
- if (source.by === "automatic") return "From the automatic turn:";
56
- return "From the owner's message:";
57
- }
58
-
59
- // The quote block for the selected +text+ (annotations.js quoteBlock's
60
- // lines) under +source+'s label; null when it holds no text.
61
- export function participantQuote(text, source) {
62
- const block = quoteBlock(text, { kind: "answer" });
63
- if (!block) return null;
64
- const label = participantLabel(source);
65
- return label ? `${label}\n${block}` : block;
66
- }
67
-
68
- // What a message's .p-msg carries for participantSource: data-by and, for
69
- // another participant, data-name. +message+ is a review message (the
70
- // participant route's: mine, author, author_name, automatic).
71
- export function messageAuthorData(message) {
72
- if (message?.mine) return { by: "me" };
73
- if (isParticipantAuthor(message?.author)) return { by: "participant", name: message.author_name || "" };
74
- if (message?.automatic) return { by: "automatic" };
75
- return { by: "owner" };
76
- }
@@ -1,34 +0,0 @@
1
- // Apply (the owner's page): under a participant's review turn's reply, a
2
- // button that puts the owner's Apply turn in the composer: one line of the
3
- // owner's and the proposal quoted (GET …/apply, ReviewApply on the server),
4
- // never sent by itself. The owner reads it, edits it, sends it or not.
5
- import { html } from "./vendor/lit-html.js";
6
-
7
- // The row under a review turn's reply: +badge+ is authorBadge's
8
- // ({author, name, color}).
9
- export function applyRowTemplate(turnId, badge) {
10
- return html`<div class="review-apply" data-apply-turn=${turnId} style=${`--author-color:${badge.color}`}><button
11
- type="button" class="review-apply-btn" data-apply-turn=${turnId}
12
- title=${`Put an Apply turn in the composer: ${badge.name}'s proposal, quoted. You read it before you send it.`}>Apply</button
13
- ><span class="review-apply-note">${badge.name}'s proposal, quoted in your composer; you send it</span></div>`;
14
- }
15
-
16
- // The composer with the Apply turn: after what is typed there already.
17
- export function applyComposerText(current, composed) {
18
- const typed = String(current || "").trimEnd();
19
- return typed ? `${typed}\n\n${composed}` : composed;
20
- }
21
-
22
- export function applyURL(sessionId, turnId) {
23
- return `/api/sessions/${encodeURIComponent(sessionId)}/apply?turn=${encodeURIComponent(turnId)}`;
24
- }
25
-
26
- // The Apply turn's text for review turn +turnId+, or an Error with the
27
- // server's words.
28
- export async function fetchApply(sessionId, turnId, fetchImpl = fetch) {
29
- const res = await fetchImpl(applyURL(sessionId, turnId), { credentials: "same-origin" });
30
- let json = null;
31
- try { json = await res.json(); } catch { json = null; }
32
- if (!res.ok || typeof json?.text !== "string") throw new Error(json?.detail || `Apply failed (HTTP ${res.status})`);
33
- return json.text;
34
- }
@@ -1,72 +0,0 @@
1
- // A participant's ↑/↓ in the comment box (participant.js over
2
- // prompt_history.js): their own comments sent from this browser, newest
3
- // last, in localStorage under one key per grant, never the owner's GET
4
- // /api/history (the owner may open a link in the same browser, on the same
5
- // origin: each grant's list and the owner's stay apart). Read and written
6
- // through storage.js (guarded): a list that can't be read or written is just
7
- // not there. A link that ends forgets its list; one that ended while no page
8
- // was open goes when the next link's page loads (pruneReviewHistory).
9
- import { readStored, removeStored, storedKeys, writeStored } from "./storage.js";
10
-
11
- export const REVIEW_HISTORY_PREFIX = "chi_review_history:";
12
- const REVIEW_HISTORY_SESSION_PREFIX = "chi_review_history_session:";
13
- // How many comments a grant's list keeps (the oldest go first).
14
- export const REVIEW_HISTORY_MAX = 50;
15
-
16
- // The key for grant +grantId+'s list; null without one (an older server's
17
- // review data): no history then.
18
- export function reviewHistoryKey(grantId) {
19
- return grantId ? `${REVIEW_HISTORY_PREFIX}${grantId}` : null;
20
- }
21
-
22
- // The grant's comments, oldest first; [] when there are none or they can't
23
- // be read.
24
- export function readReviewHistory(grantId) {
25
- const key = reviewHistoryKey(grantId);
26
- if (!key) return [];
27
- try {
28
- const list = JSON.parse(readStored(key, "[]"));
29
- return Array.isArray(list) ? list.filter((entry) => typeof entry === "string") : [];
30
- } catch (_) {
31
- return [];
32
- }
33
- }
34
-
35
- // The list with +text+ added at the end (not twice in a row), at most
36
- // REVIEW_HISTORY_MAX long. Pure.
37
- export function withComment(list, text) {
38
- const entry = String(text || "").trim();
39
- if (!entry) return list;
40
- const next = list.at(-1) === entry ? list : [...list, entry];
41
- return next.slice(-REVIEW_HISTORY_MAX);
42
- }
43
-
44
- // A comment the server took: saved at the end of the grant's list.
45
- export function recordReviewComment(grantId, text) {
46
- const key = reviewHistoryKey(grantId);
47
- if (!key) return;
48
- writeStored(key, JSON.stringify(withComment(readReviewHistory(grantId), text)));
49
- }
50
-
51
- export function rememberReviewHistory(sessionId, grantId) {
52
- if (sessionId && grantId) writeStored(`${REVIEW_HISTORY_SESSION_PREFIX}${sessionId}`, grantId);
53
- }
54
-
55
- export function forgetReviewHistory(grantId, sessionId) {
56
- const sessionKey = sessionId ? `${REVIEW_HISTORY_SESSION_PREFIX}${sessionId}` : null;
57
- const remembered = sessionKey ? readStored(sessionKey) : null;
58
- if (sessionKey) removeStored(sessionKey);
59
- const key = reviewHistoryKey(grantId || remembered);
60
- if (key) removeStored(key);
61
- }
62
-
63
- // A participant page's first read (+sessionId+, its grant +grantId+): every
64
- // other grant's list and every other session's pointer go, so the lists of
65
- // links that ended while no page was open don't stay for good. Without
66
- // either id (the owner's view, an older server's data) nothing goes.
67
- export function pruneReviewHistory(sessionId, grantId) {
68
- if (!sessionId || !grantId) return;
69
- const keep = new Set([reviewHistoryKey(grantId), `${REVIEW_HISTORY_SESSION_PREFIX}${sessionId}`]);
70
- for (const key of storedKeys(REVIEW_HISTORY_PREFIX)) if (!keep.has(key)) removeStored(key);
71
- for (const key of storedKeys(REVIEW_HISTORY_SESSION_PREFIX)) if (!keep.has(key)) removeStored(key);
72
- }
@@ -1,55 +0,0 @@
1
- // Start review (the web's entry points to a review session, docs/sessions.md
2
- // Review sessions): the start page's review files (the ⚙ panel's review
3
- // view, start_settings.js), which make the new session a review session
4
- // (POST /api/sessions {review: {subjects}}), and the session bar's review
5
- // button, a review fork of the open session ({review: {from}}): its recap,
6
- // not its transcript; it keeps running.
7
- import { html, nothing } from "./vendor/lit-html.js";
8
-
9
- // The files typed: split on commas, spaces and new lines, no repeats; a
10
- // path with a space (or a comma) in double quotes ("docs/my plan.md").
11
- // @return {subjects, error}: error, a quote left open (then no subjects)
12
- export function readSubjects(text) {
13
- const found = [];
14
- for (const m of String(text || "").matchAll(/"([^"]*)("?)|[^\s,"]+/g)) {
15
- if (m[1] !== undefined && !m[2]) return { subjects: [], error: `A quote isn't closed: "${m[1].trim()}` };
16
- const path = (m[1] ?? m[0]).trim();
17
- if (path) found.push(path);
18
- }
19
- return { subjects: [...new Set(found)], error: null };
20
- }
21
-
22
- // The files as the form shows them again: a path with a space, a comma or
23
- // a quote in quotes, so readSubjects reads it back whole.
24
- export function formatSubjects(subjects) {
25
- return (subjects || []).map((s) => (/[\s,"]/.test(s) ? `"${s}"` : s)).join(", ");
26
- }
27
-
28
- // The start page's override chip: "review…" with none, else the files' names.
29
- export function reviewChipModel(subjects) {
30
- const list = subjects || [];
31
- if (!list.length) {
32
- return { text: "review…", own: false, title: "Start a review session instead: pick the project files participants will read beside the thread" };
33
- }
34
- const names = list.map((s) => s.split("/").pop());
35
- return { text: `review: ${names[0]}${names.length > 1 ? ` +${names.length - 1}` : ""}`, own: true,
36
- title: `A review session of ${list.join(", ")}: Start makes it (your message, if any, is its first turn); then invite someone from the participants chip` };
37
- }
38
-
39
- // +error+: why the files weren't taken (a quote left open, the server's
40
- // refusal at Start), shown above Set; +text+ the form's text as typed;
41
- // +back+: a ‹ before the heading (data-act="back": the start page's ⚙
42
- // panel, start_settings.js, whose view this is).
43
- export function reviewFormTemplate(subjects, { error = null, text = null, back = false } = {}) {
44
- return html`<div class="ctx-pop-head">${back ? html`<button type="button" class="sset-back" data-act="back"
45
- aria-label="Back to the settings" title="Back to the settings">‹</button>` : nothing}<strong>Review</strong><span class="ctx-pop-kind">new session</span
46
- ><button type="button" class="ctx-pop-close" data-act="close" aria-label="Close">×</button></div>
47
- <div class="ctx-pop-meta" id="reviewNewHelp">The files participants read beside the thread: project paths, relative to this folder,
48
- a path with a space in quotes. Secrets (.env, keys) and files outside the project are refused.</div>
49
- <form class="rs-form"><textarea name="subjects" rows="2" placeholder="docs/plan.md, docs/spec.md" aria-label="Files to review"
50
- aria-describedby="reviewNewHelp" aria-invalid=${error ? "true" : "false"}
51
- autocomplete="off" spellcheck="false" .value=${text ?? formatSubjects(subjects)}></textarea>
52
- <div class="ctx-pop-error" role="alert" ?hidden=${!error}>${error || ""}</div>
53
- <div class="ctx-pop-actions">${subjects?.length ? html`<button type="button" data-act="clear">No review</button>` : nothing}<button
54
- type="submit">Set</button></div></form>`;
55
- }
@@ -1,42 +0,0 @@
1
- // A turn's tool rows as one line: "read 12 files · ran 3 commands · edited
2
- // 2 files (engine.rb, worker.rb)". Pure, names only (rows carry a tool name
3
- // and a project path, never args or output); the participant page folds a
4
- // turn's rows into it, and the owner's page may later.
5
- const READERS = new Set(["read"]);
6
- const COMMANDS = new Set(["execute", "bash"]);
7
- const EDITORS = new Set(["write", "edit"]);
8
- const FILE_NAMES = 3;
9
-
10
- const rowsOf = (rows) => (Array.isArray(rows) ? rows : []);
11
- const namedPath = (row) => typeof row?.path === "string" && row.path ? row.path : null;
12
- const basename = (path) => path.split(/[\\/]/).at(-1);
13
- const noun = (count, singular, plural) => `${count} ${count === 1 ? singular : plural}`;
14
-
15
- function fileCount(rows) {
16
- const paths = new Set(rows.map(namedPath).filter(Boolean));
17
- return paths.size + rows.filter((row) => !namedPath(row)).length;
18
- }
19
-
20
- function fileNames(rows) {
21
- const paths = [...new Set(rows.map(namedPath).filter(Boolean))];
22
- const names = paths.slice(0, FILE_NAMES).map(basename);
23
- if (paths.length > FILE_NAMES) names.push("…");
24
- return names.length ? ` (${names.join(", ")})` : "";
25
- }
26
-
27
- export function toolsOverview(rows) {
28
- const list = rowsOf(rows);
29
- if (!list.length) return "";
30
-
31
- const readers = list.filter((row) => READERS.has(row?.tool));
32
- const commands = list.filter((row) => COMMANDS.has(row?.tool));
33
- const editors = list.filter((row) => EDITORS.has(row?.tool));
34
- const otherCount = list.length - readers.length - commands.length - editors.length;
35
- const parts = [];
36
-
37
- if (readers.length) parts.push(`read ${noun(fileCount(readers), "file", "files")}`);
38
- if (commands.length) parts.push(`ran ${noun(commands.length, "command", "commands")}`);
39
- if (editors.length) parts.push(`edited ${noun(fileCount(editors), "file", "files")}${fileNames(editors)}`);
40
- if (otherCount) parts.push(`used ${noun(otherCount, "other tool", "other tools")}`);
41
- return parts.join(" · ");
42
- }