@uniqbit/mate-core 0.18.5 → 1.0.0-canary.2

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 (390) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/marketplace.json +14 -0
  2. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +8 -0
  3. package/claude-capability-plugins/companion-mentions/hooks/companion.ts +457 -0
  4. package/claude-capability-plugins/companion-mentions/hooks/hooks.json +1 -0
  5. package/claude-capability-plugins/companion-mentions/hooks/register.ts +403 -0
  6. package/claude-plugin/hooks/companion-instructions.mjs +9 -0
  7. package/claude-plugin/hooks/hooks.json +21 -2
  8. package/claude-plugin/hooks/tokensave-route.mjs +52 -0
  9. package/opencode-plugin/src/server.ts +4 -0
  10. package/opencode-plugin/src/tui.tsx +2 -0
  11. package/opencode-plugin/tui.tsx +2 -0
  12. package/package.json +52 -15
  13. package/src/brand/art.generated.ts +69 -0
  14. package/src/brand/index.ts +12 -0
  15. package/src/brand/palette.ts +19 -0
  16. package/src/brand/svg.generated.ts +8 -0
  17. package/src/brand/terminal.ts +88 -0
  18. package/src/brand/types.ts +33 -0
  19. package/src/cli/commands/artifact/apply-context.ts +275 -0
  20. package/src/cli/commands/artifact/artifact.ts +12 -0
  21. package/src/cli/commands/artifact/delivery/archive.ts +125 -0
  22. package/src/cli/commands/artifact/delivery/branch-flags.ts +55 -0
  23. package/src/cli/commands/artifact/delivery/environment.ts +127 -0
  24. package/src/cli/commands/artifact/delivery/link.ts +174 -0
  25. package/src/cli/commands/artifact/delivery/output.ts +89 -0
  26. package/src/cli/commands/artifact/finish/command.ts +83 -8
  27. package/src/cli/commands/artifact/finish/engine.ts +91 -14
  28. package/src/cli/commands/artifact/finish/finisher.ts +10 -0
  29. package/src/cli/commands/artifact/finish/git.ts +132 -19
  30. package/src/cli/commands/artifact/finish/openspec.ts +182 -138
  31. package/src/cli/commands/artifact/finish/secret-scan.ts +43 -0
  32. package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
  33. package/src/cli/commands/artifact/pending/command.ts +31 -3
  34. package/src/cli/commands/artifact/pending/discovery.ts +21 -57
  35. package/src/cli/commands/cap/graphify.ts +52 -3
  36. package/src/cli/commands/cap/index-cmd.ts +71 -15
  37. package/src/cli/commands/cap/openspec.ts +13 -25
  38. package/src/cli/commands/cap/tokensave.ts +7 -5
  39. package/src/cli/commands/companion/link.ts +14 -1
  40. package/src/cli/commands/companion/open.ts +68 -46
  41. package/src/cli/commands/companion/sync.ts +10 -0
  42. package/src/cli/commands/companion/tui.ts +17 -7
  43. package/src/cli/commands/companion/update.ts +143 -48
  44. package/src/cli/commands/doctor.ts +195 -7
  45. package/src/cli/commands/factory/factory.ts +301 -0
  46. package/src/cli/commands/install.ts +133 -9
  47. package/src/cli/commands/launch/shared.ts +16 -11
  48. package/src/cli/commands/plugin/install.ts +9 -4
  49. package/src/cli/commands/plugin/plugin.ts +3 -2
  50. package/src/cli/commands/report/adapter.ts +11 -2
  51. package/src/cli/commands/report/contract.ts +21 -0
  52. package/src/cli/commands/report/highlight.ts +34 -4
  53. package/src/cli/commands/report/index.ts +20 -1
  54. package/src/cli/commands/report/markdown.ts +110 -0
  55. package/src/cli/commands/report/palette.ts +118 -0
  56. package/src/cli/commands/report/renderer.ts +456 -153
  57. package/src/cli/commands/report/types.ts +16 -0
  58. package/src/cli/commands/session/context.ts +102 -0
  59. package/src/cli/commands/setup.ts +50 -24
  60. package/src/cli/commands/studio/factory-credential.ts +49 -0
  61. package/src/cli/commands/studio/index.ts +29 -2
  62. package/src/cli/commands/studio/openspec-cli.ts +10 -58
  63. package/src/cli/commands/studio/payload.ts +249 -15
  64. package/src/cli/commands/studio/routes.ts +41 -6
  65. package/src/cli/commands/studio/selection.ts +161 -17
  66. package/src/cli/commands/studio/server.ts +404 -324
  67. package/src/cli/commands/studio/services.ts +60 -0
  68. package/src/cli/commands/studio/studio-app.ts +67 -0
  69. package/src/cli/commands/studio/terminal-assets.ts +21 -33
  70. package/src/cli/commands/studio/terminal.ts +85 -15
  71. package/src/cli/commands/studio/views/model.ts +18 -0
  72. package/src/cli/commands/studio/views/vault/markdown-tree.ts +267 -0
  73. package/src/cli/commands/studio/views/vault/view.ts +185 -0
  74. package/src/cli/commands/studio/workset-session.ts +131 -0
  75. package/src/cli/commands/unwrap.ts +8 -0
  76. package/src/cli/commands/update.ts +27 -1
  77. package/src/cli/commands/working/cleanup.ts +10 -1
  78. package/src/cli/commands/working/link.ts +76 -0
  79. package/src/cli/commands/working/working.ts +10 -0
  80. package/src/cli/commands/working/worktree.ts +356 -0
  81. package/src/cli/commands/wrap.ts +5 -13
  82. package/src/cli/companion-link-wizard.tsx +2 -0
  83. package/src/cli/companion-selector.tsx +2 -0
  84. package/src/cli/confirm.ts +2 -0
  85. package/src/cli/install-plan.tsx +127 -160
  86. package/src/cli/launch-selector.tsx +2 -0
  87. package/src/cli/main.ts +22 -1
  88. package/src/cli/parse-flags.ts +32 -6
  89. package/src/cli/repo-list-table.tsx +2 -0
  90. package/src/cli/setup-selector.tsx +86 -151
  91. package/src/cli/usage.ts +14 -0
  92. package/src/create-mate.ts +5 -4
  93. package/src/hooks/companion-instructions.ts +190 -0
  94. package/src/hooks/hook-io.ts +63 -0
  95. package/src/hooks/session-banner.ts +21 -29
  96. package/src/hooks/session-guidance.ts +9 -17
  97. package/src/hooks/session-prepare.ts +115 -28
  98. package/src/hooks/tokensave-route.ts +26 -0
  99. package/src/hooks/validate-artifact-path.ts +82 -24
  100. package/src/index.ts +4 -0
  101. package/src/lib/apply-context/fingerprint.ts +174 -0
  102. package/src/lib/apply-context/protocol.ts +193 -0
  103. package/src/lib/change-layout.ts +154 -0
  104. package/src/lib/components/confirm-prompt.tsx +21 -9
  105. package/src/lib/components/select-menu.tsx +10 -3
  106. package/src/lib/components/spinner.tsx +4 -2
  107. package/src/lib/components/startup-progress.tsx +227 -41
  108. package/src/lib/components/text-input-display.tsx +2 -0
  109. package/src/lib/components/wizard-footer.tsx +2 -0
  110. package/src/lib/components/wizard-header.tsx +16 -12
  111. package/src/lib/context-mode-package.ts +24 -11
  112. package/src/lib/delivery/archive-change.ts +166 -0
  113. package/src/lib/delivery/branches.ts +132 -0
  114. package/src/lib/delivery/environment.ts +35 -0
  115. package/src/lib/delivery/forge.ts +279 -0
  116. package/src/lib/delivery/merge-git.ts +261 -0
  117. package/src/lib/delivery/overlap.ts +209 -0
  118. package/src/lib/delivery/record-delivery.ts +283 -0
  119. package/src/lib/delivery/record.ts +403 -0
  120. package/src/lib/delivery/refresh.ts +268 -0
  121. package/src/lib/delivery/repository-access.ts +141 -0
  122. package/src/lib/delivery/resolve-branch.ts +162 -0
  123. package/src/lib/delivery/stages.ts +111 -0
  124. package/src/lib/delivery/token.ts +24 -0
  125. package/src/lib/factory/attach-client.ts +113 -0
  126. package/src/lib/factory/attach.ts +178 -0
  127. package/src/lib/factory/broker.ts +190 -0
  128. package/src/lib/factory/bun-commands.ts +39 -0
  129. package/src/lib/factory/client.ts +92 -0
  130. package/src/lib/factory/command.ts +61 -0
  131. package/src/lib/factory/credential-store.ts +153 -0
  132. package/src/lib/factory/frames.ts +77 -0
  133. package/src/lib/factory/ids.ts +58 -0
  134. package/src/lib/factory/keyed-serial.ts +27 -0
  135. package/src/lib/factory/outcomes/actions.ts +114 -0
  136. package/src/lib/factory/outcomes/index.ts +381 -0
  137. package/src/lib/factory/outcomes/lifecycle.ts +205 -0
  138. package/src/lib/factory/outcomes/runs.ts +81 -0
  139. package/src/lib/factory/outcomes/sessions.ts +38 -0
  140. package/src/lib/factory/prepare.ts +49 -0
  141. package/src/lib/factory/pty.ts +103 -0
  142. package/src/lib/factory/runner/companion-context.ts +178 -0
  143. package/src/lib/factory/runner/control.ts +92 -0
  144. package/src/lib/factory/runner/harness-agent.ts +250 -0
  145. package/src/lib/factory/runner/live.ts +159 -0
  146. package/src/lib/factory/runner/questions.ts +22 -0
  147. package/src/lib/factory/runner/rank.ts +26 -0
  148. package/src/lib/factory/runner/run-policy.ts +12 -0
  149. package/src/lib/factory/runner/run.ts +199 -0
  150. package/src/lib/factory/runner/scheduler.ts +416 -0
  151. package/src/lib/factory/runner/state.ts +233 -0
  152. package/src/lib/factory/runner/workflow.ts +542 -0
  153. package/src/lib/factory/runtime.ts +972 -0
  154. package/src/lib/factory/sandbox.ts +292 -0
  155. package/src/lib/factory/worktree-branch.ts +17 -0
  156. package/src/lib/frontmatter.ts +18 -0
  157. package/src/lib/install.ts +66 -14
  158. package/src/lib/live-progress.ts +36 -0
  159. package/src/lib/member-choices.ts +67 -0
  160. package/src/lib/opencode-plugin-package.ts +5 -5
  161. package/src/lib/openspec-cli.ts +116 -0
  162. package/src/lib/openspec-scopes.ts +86 -0
  163. package/src/lib/orchestrator/adapters/base.ts +55 -22
  164. package/src/lib/orchestrator/adapters/claude-args.ts +50 -0
  165. package/src/lib/orchestrator/adapters/claude.ts +54 -41
  166. package/src/lib/orchestrator/adapters/opencode.ts +2 -0
  167. package/src/lib/orchestrator/config-store.ts +3 -2
  168. package/src/lib/orchestrator/editor.ts +31 -25
  169. package/src/lib/orchestrator/openspec-store.ts +14 -54
  170. package/src/lib/orchestrator/projection-claude-commands.ts +36 -0
  171. package/src/lib/orchestrator/projection-claude-links.ts +159 -0
  172. package/src/lib/orchestrator/projection-claude-skills.ts +19 -137
  173. package/src/lib/orchestrator/projection-entries.ts +100 -34
  174. package/src/lib/orchestrator/projection-opencode-copies.ts +32 -15
  175. package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
  176. package/src/lib/orchestrator/projection-runtime-documents.ts +15 -6
  177. package/src/lib/orchestrator/projection-types.ts +36 -1
  178. package/src/lib/orchestrator/refresh-working-claude-links.ts +87 -0
  179. package/src/lib/orchestrator/session-context-link.ts +67 -0
  180. package/src/lib/orchestrator/session-prepare.ts +45 -5
  181. package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
  182. package/src/lib/orchestrator/types.ts +7 -2
  183. package/src/lib/orchestrator/working-repo-projection.ts +50 -7
  184. package/src/lib/orchestrator/workspace-document.ts +105 -0
  185. package/src/lib/orchestrator/wrap-pass.ts +22 -1
  186. package/src/lib/package-paths.ts +37 -0
  187. package/src/lib/runtime-directory-refresh.ts +17 -1
  188. package/src/lib/workset/record.ts +513 -0
  189. package/src/lib/workset/repositories.ts +55 -0
  190. package/src/lib/workset/stage.ts +148 -0
  191. package/src/lib/workset/stages.ts +113 -0
  192. package/src/lib/workset/worktree-index.ts +116 -0
  193. package/src/lib/workset/worktree.ts +830 -0
  194. package/src/opencode/companion-hooks.ts +109 -7
  195. package/src/opencode/companion-policy.ts +37 -18
  196. package/src/opencode/enter-worktree.ts +72 -0
  197. package/src/opencode/projected-guidance.ts +4 -1
  198. package/src/opencode/session-prepare.ts +2 -1
  199. package/src/opencode/tui.tsx +13 -6
  200. package/src/plugins.ts +1 -0
  201. package/src/runtime/artifact-refusal.ts +63 -0
  202. package/src/runtime/claude-delivery-plan.ts +107 -8
  203. package/src/runtime/commit-attribution-guard.ts +181 -0
  204. package/src/runtime/companion-git.ts +52 -10
  205. package/src/runtime/companion-guidance.ts +20 -8
  206. package/src/runtime/companion-instructions.ts +340 -0
  207. package/src/runtime/companion-lock.ts +30 -7
  208. package/src/runtime/env.ts +48 -3
  209. package/src/runtime/error-message.ts +4 -0
  210. package/src/runtime/git-layout.ts +219 -0
  211. package/src/runtime/index.ts +29 -0
  212. package/src/runtime/managed-block.ts +117 -0
  213. package/src/runtime/markdown-scan.ts +266 -0
  214. package/src/runtime/physical-path.ts +111 -0
  215. package/src/runtime/policy.ts +50 -2
  216. package/src/runtime/projected-flag.ts +7 -0
  217. package/src/runtime/projected-guidance.ts +1 -0
  218. package/src/runtime/runtime-directory.ts +5 -0
  219. package/src/runtime/runtime-document-manifest.ts +62 -11
  220. package/src/runtime/secret-guard.ts +162 -0
  221. package/src/runtime/secret-patterns.ts +397 -0
  222. package/src/runtime/secret-scan.ts +90 -0
  223. package/src/runtime/session-context.ts +98 -0
  224. package/src/runtime/session-kind.ts +13 -0
  225. package/src/runtime/shell-heredoc.ts +81 -0
  226. package/src/runtime/tokensave-route.ts +152 -0
  227. package/src/runtime/wrap-state.ts +44 -2
  228. package/src/runtime/write-atomic.ts +64 -0
  229. package/src/studio.ts +124 -0
  230. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +14 -10
  231. package/src/templates/capabilities/openspec-cap/mate-minimal/templates/spec.md +3 -5
  232. package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +18 -102
  233. package/src/templates/capabilities/openspec-cap/mate-v1/templates/spec.md +3 -5
  234. package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +20 -14
  235. package/src/templates/mate-skills/THIRD-PARTY-NOTICES.md +40 -0
  236. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +134 -0
  237. package/src/templates/mate-skills/agents/mate-apply-change/references/mate-compact-apply.md +47 -0
  238. package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +200 -0
  239. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +86 -0
  240. package/src/templates/mate-skills/{claude/mate-openspec-backfill → agents/mate-backfill-spec}/SKILL.md +11 -4
  241. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +110 -0
  242. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +66 -0
  243. package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +350 -0
  244. package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +11 -4
  245. package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +2 -2
  246. package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +12 -5
  247. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +108 -0
  248. package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +47 -0
  249. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +169 -0
  250. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +103 -0
  251. package/src/templates/mate-skills/agents/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +111 -24
  252. package/src/templates/mate-skills/{claude/mate-artifact-publish → agents/mate-publish-artifact}/references/openspec.md +8 -5
  253. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +95 -16
  254. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +87 -68
  255. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +134 -0
  256. package/src/templates/mate-skills/claude/mate-apply-change/references/mate-compact-apply.md +47 -0
  257. package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +200 -0
  258. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +86 -0
  259. package/src/templates/mate-skills/{agents/mate-openspec-backfill → claude/mate-backfill-spec}/SKILL.md +11 -4
  260. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +110 -0
  261. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +66 -0
  262. package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +350 -0
  263. package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +11 -4
  264. package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +2 -2
  265. package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +12 -5
  266. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +108 -0
  267. package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +47 -0
  268. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +169 -0
  269. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +103 -0
  270. package/src/templates/mate-skills/claude/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +111 -24
  271. package/src/templates/mate-skills/{agents/mate-artifact-publish → claude/mate-publish-artifact}/references/openspec.md +8 -5
  272. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +95 -16
  273. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +87 -68
  274. package/src/templates/mate-skills/openspec-references.ts +142 -0
  275. package/src/templates/root/TEMPLATE_AGENTS.md +2 -2
  276. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +3938 -391
  277. package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
  278. package/src/tools/setup/capabilities/context-mode.ts +56 -7
  279. package/src/tools/setup/capabilities/graphify-gate.ts +31 -0
  280. package/src/tools/setup/capabilities/graphify-secrets.ts +243 -0
  281. package/src/tools/setup/capabilities/graphify.ts +46 -7
  282. package/src/tools/setup/capabilities/openspec.ts +163 -272
  283. package/src/tools/setup/capabilities/react-doctor.ts +8 -1
  284. package/src/tools/setup/capabilities/rtk.ts +4 -0
  285. package/src/tools/setup/capabilities/tokensave.ts +113 -71
  286. package/src/tools/setup/context-services.ts +9 -17
  287. package/src/tools/setup/dynamic-plugins/install.ts +24 -28
  288. package/src/tools/setup/engine.ts +100 -23
  289. package/src/tools/setup/install-contract.ts +8 -0
  290. package/src/tools/setup/managed-output.ts +51 -0
  291. package/src/tools/setup/mate-skill-copies.ts +51 -0
  292. package/src/tools/setup/mate.ts +86 -11
  293. package/src/tools/setup/package-managers/uv.ts +73 -11
  294. package/src/tools/setup/plugin.ts +40 -0
  295. package/src/tools/setup/plugins/guidance.ts +7 -4
  296. package/src/tools/setup/providers/agent-file-sections.ts +4 -2
  297. package/src/tools/setup/providers/claude-attribution.ts +65 -0
  298. package/src/tools/setup/providers/claude-plugin-folders.ts +625 -0
  299. package/src/tools/setup/providers/claude-plugin-hooks.ts +51 -19
  300. package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
  301. package/src/tools/setup/providers/claude.ts +290 -8
  302. package/src/tools/setup/providers/opencode.ts +180 -1
  303. package/src/tools/setup/utils.ts +18 -4
  304. package/src/tools/setup/working-repo-cleanup.ts +29 -1
  305. package/src/tools/setup/working-repo-local-state.ts +252 -75
  306. package/src/tools/setup.ts +183 -26
  307. package/studio-dist/client/assets/companion-view-Csva26Ir.js +1 -0
  308. package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +1 -0
  309. package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
  310. package/studio-dist/client/assets/factory-B7l9ZQyx.js +4 -0
  311. package/studio-dist/client/assets/index-n6uo_92S.js +40 -0
  312. package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
  313. package/studio-dist/client/assets/prepaint-CD5OpmTM.js +24 -0
  314. package/studio-dist/client/assets/queries-CN3JwMBX.js +1 -0
  315. package/studio-dist/client/assets/react-CabXf2Ds.js +1 -0
  316. package/studio-dist/client/assets/report-time-Dc-KOqQu.js +1 -0
  317. package/studio-dist/client/assets/reports-C01RsnMA.js +1 -0
  318. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
  319. package/studio-dist/client/assets/routes-4pbC-2Hj.js +1 -0
  320. package/studio-dist/client/assets/skills-CihQganl.js +1 -0
  321. package/studio-dist/client/assets/spec-areas-C2L48N4C.js +1 -0
  322. package/studio-dist/client/assets/specs-D24_35_K.js +1 -0
  323. package/studio-dist/client/assets/studio-DKxfi691.css +1 -0
  324. package/studio-dist/client/assets/studio-queries-rvbJupCy.js +3 -0
  325. package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
  326. package/studio-dist/client/assets/vault-Bd4CQiTK.js +1 -0
  327. package/studio-dist/client/assets/warnings-V_Ys51wJ.js +1 -0
  328. package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
  329. package/studio-dist/client/assets/workflow-BJejeVwQ.js +1 -0
  330. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-BQKuMdJW.js +3881 -0
  331. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +85 -0
  332. package/studio-dist/server/assets/actions-Bvgj9eb8.js +54 -0
  333. package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
  334. package/studio-dist/server/assets/companion-view-aBady57v.js +33 -0
  335. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +459 -0
  336. package/studio-dist/server/assets/createServerRpc-tK2lE9R2.js +11 -0
  337. package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +778 -0
  338. package/studio-dist/server/assets/dist-DpJWKyCm.js +5582 -0
  339. package/studio-dist/server/assets/empty-plugin-adapters-Cipd4ZH4.js +4 -0
  340. package/studio-dist/server/assets/factory-D6xnjedJ.js +2385 -0
  341. package/studio-dist/server/assets/factory-DT3UzHlh.js +68 -0
  342. package/studio-dist/server/assets/model-PyPALjii.js +18 -0
  343. package/studio-dist/server/assets/prepaint-BMke0fo1.js +41 -0
  344. package/studio-dist/server/assets/queries-Ag2iL8q2.js +107 -0
  345. package/studio-dist/server/assets/react-COs0LHn-.js +51 -0
  346. package/studio-dist/server/assets/report-time-DAfzln-N.js +8 -0
  347. package/studio-dist/server/assets/reports-BnUNJVtx.js +126 -0
  348. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
  349. package/studio-dist/server/assets/router-BH--drIx.js +4298 -0
  350. package/studio-dist/server/assets/routes-khSDK1bV.js +361 -0
  351. package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
  352. package/studio-dist/server/assets/shell-CboT2f66.js +51 -0
  353. package/studio-dist/server/assets/skills-MWYnWoKs.js +106 -0
  354. package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +16 -0
  355. package/studio-dist/server/assets/specs-DE3w8hZP.js +155 -0
  356. package/studio-dist/server/assets/start-BW5ovN0k.js +33 -0
  357. package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
  358. package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +3365 -0
  359. package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
  360. package/studio-dist/server/assets/vault-BGulVoNh.js +70 -0
  361. package/studio-dist/server/assets/vault-CuyyhLyB.js +832 -0
  362. package/studio-dist/server/assets/views-Bd7cRr27.js +82 -0
  363. package/studio-dist/server/assets/warnings-BH05rOuG.js +15 -0
  364. package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
  365. package/studio-dist/server/assets/workflow-BSuIKWqH.js +42 -0
  366. package/studio-dist/server/server.js +16220 -0
  367. package/wrappers/bin/graphify +52 -4
  368. package/wrappers/bin/openspec +33 -9
  369. package/wrappers/lib/graphify-gate.mjs +8 -0
  370. package/src/cli/commands/studio/views/client.ts +0 -654
  371. package/src/cli/commands/studio/views/companion-picker.tsx +0 -95
  372. package/src/cli/commands/studio/views/companion-selector.tsx +0 -94
  373. package/src/cli/commands/studio/views/dashboard/changes.tsx +0 -107
  374. package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
  375. package/src/cli/commands/studio/views/document.tsx +0 -842
  376. package/src/cli/commands/studio/views/error.tsx +0 -20
  377. package/src/cli/commands/studio/views/reports/index.tsx +0 -49
  378. package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
  379. package/src/cli/commands/studio/views/skills/index.tsx +0 -87
  380. package/src/cli/commands/studio/views/specs/index.tsx +0 -157
  381. package/src/cli/commands/studio/views/styles.ts +0 -519
  382. package/src/cli/commands/studio/views/terminal.tsx +0 -484
  383. package/src/cli/commands/studio/views/vault/state.ts +0 -43
  384. package/src/cli/commands/studio/views/warnings.tsx +0 -21
  385. package/src/cli/commands/studio/views/workflow/index.tsx +0 -21
  386. package/src/cli/commands/studio/views/workflow/steps.ts +0 -337
  387. package/src/cli/commands/studio/views/workflow/transcript.tsx +0 -190
  388. package/src/lib/components/theme.ts +0 -2
  389. package/src/tools/setup/git-utils.ts +0 -30
  390. package/src/tools/setup/runtime-documents.ts +0 -291
@@ -0,0 +1,2385 @@
1
+ import { i as __toESM } from "./rolldown-runtime-DYf_mQCB.js";
2
+ import { i as useSuspenseQuery } from "./queries-Ag2iL8q2.js";
3
+ import { D as factoryLogRoute, E as TERMINAL_WASM, O as factoryLogStreamRoute, Z as useQueryClient, _ as agentCredentialKey, b as setAgentCredential, g as runFactoryAction, n as afterFactoryAction, nt as useNavigate, s as factoryQuery, v as agentCredentialQuery, x as REPORT_VIEW_PREFIX, y as clearAgentCredential } from "./studio-queries-CLnP9kGu.js";
4
+ import { A as require_react, l as require_jsx_runtime } from "./__23tanstack-start-server-fn-resolver-BQKuMdJW.js";
5
+ import { t as Warnings } from "./warnings-BH05rOuG.js";
6
+ import { n as WorkflowGraphView, r as workflowPlan } from "./delivery-path-BkKNjgkf.js";
7
+ import { n as outcomeActions } from "./actions-Bvgj9eb8.js";
8
+ import { _ as useMutation, d as parseMessage, f as sendMessage, l as loadWTerm, s as Route, u as openTerminalSocket } from "./router-BH--drIx.js";
9
+ import { n as useQuery, t as create } from "./react-COs0LHn-.js";
10
+ import { r as WORKSET_STAGE_ORDER } from "./studio-BeltxxKt.js";
11
+ // ../mate-core/src/lib/factory/runner/questions.ts
12
+ /**
13
+ * A waiting state's questions; a state written before questions were grouped holds one
14
+ * question in its own fields.
15
+ */
16
+ function questionsOf(state) {
17
+ if (Array.isArray(state.questions) && state.questions.length > 0) return state.questions;
18
+ const single = state;
19
+ return typeof single.question === "string" ? [single] : [];
20
+ }
21
+ // ../mate-core/src/lib/factory/runner/rank.ts
22
+ /**
23
+ * The factory work queue's one ordering rule: started Outcomes run in the order they were
24
+ * started. A Later Outcome has no rank.
25
+ */
26
+ function rankOf(record) {
27
+ if (!record.queuedAt) return null;
28
+ const queued = Date.parse(record.queuedAt);
29
+ return Number.isNaN(queued) ? null : queued;
30
+ }
31
+ /** Lower rank first, then identifier; Later Outcomes keep their relative order at the end. */
32
+ function compareRanked(a, b) {
33
+ if (a.rank === null || b.rank === null) {
34
+ if (a.rank === b.rank) return 0;
35
+ return a.rank === null ? 1 : -1;
36
+ }
37
+ return a.rank - b.rank || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
38
+ }
39
+ // src/views/factory/factory-companion.ts
40
+ var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
41
+ /** The companion the board acts on; set once by the Factory view. */
42
+ var FactoryCompanion = (0, import_react.createContext)("");
43
+ // src/views/factory/use-modal-dialog.ts
44
+ /**
45
+ * Shows the dialog modally once, through `show`, and calls the latest `onClose` whenever it
46
+ * closes. Close, Esc and the backdrop all end in the native close event.
47
+ */
48
+ function useModalDialog(onClose, show) {
49
+ const close = (0, import_react.useRef)(onClose);
50
+ (0, import_react.useEffect)(() => {
51
+ close.current = onClose;
52
+ });
53
+ const ref = (0, import_react.useRef)(null);
54
+ const showOnce = (0, import_react.useRef)(show);
55
+ (0, import_react.useEffect)(() => {
56
+ const dialog = ref.current;
57
+ if (!dialog) return;
58
+ if (!dialog.open) showOnce.current(dialog);
59
+ const backdrop = (event) => {
60
+ if (event.target === dialog) dialog.close();
61
+ };
62
+ const closed = () => close.current();
63
+ dialog.addEventListener("click", backdrop);
64
+ dialog.addEventListener("close", closed);
65
+ return () => {
66
+ dialog.removeEventListener("click", backdrop);
67
+ dialog.removeEventListener("close", closed);
68
+ };
69
+ }, []);
70
+ return ref;
71
+ }
72
+ // src/views/factory/agents-dialog.tsx
73
+ var import_jsx_runtime = require_jsx_runtime();
74
+ /** Each tab's form: what it asks for, and how to get it. */
75
+ var TABS = [{
76
+ kind: "subscription",
77
+ tab: "Claude subscription",
78
+ label: "Subscription token",
79
+ hint: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ol", {
80
+ className: "note agents-steps",
81
+ children: [
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
83
+ "In a terminal on your own machine, run ",
84
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "claude setup-token" }),
85
+ "."
86
+ ] }),
87
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "Sign in with your Claude account in the browser it opens." }),
88
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
89
+ "Paste the token it prints below. It starts with ",
90
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "sk-ant-oat" }),
91
+ " and is valid for a year."
92
+ ] })
93
+ ]
94
+ })
95
+ }, {
96
+ kind: "api-key",
97
+ tab: "API key",
98
+ label: "Anthropic API key",
99
+ hint: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
100
+ className: "note",
101
+ children: "Agents bill this key. It starts with sk-ant-api."
102
+ })
103
+ }];
104
+ var KIND_LABELS = {
105
+ subscription: "Claude subscription token",
106
+ "api-key": "Anthropic API key"
107
+ };
108
+ function statusText(status) {
109
+ if (!status) return "Checking…";
110
+ if (!status.kind) return "No credential set. Worksets cannot start agents until one is.";
111
+ const source = status.source === "studio" ? `set in Studio${status.setAt ? ` on ${new Date(status.setAt).toLocaleString()}` : ""}` : "supplied at startup";
112
+ return `${KIND_LABELS[status.kind]}, ${source}.`;
113
+ }
114
+ /** Reads one field and empties the form, so the value lives only in this request. */
115
+ function takeField(event, name) {
116
+ event.preventDefault();
117
+ const form = event.currentTarget;
118
+ const value = new FormData(form).get(name);
119
+ form.reset();
120
+ return typeof value === "string" ? value : "";
121
+ }
122
+ function SecretForm({ kind, label, hint, onSaved }) {
123
+ const save = useMutation({
124
+ mutationFn: (value) => setAgentCredential(kind, value),
125
+ onSuccess: onSaved
126
+ });
127
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
128
+ className: "factory-sheet",
129
+ "data-agents-form": kind,
130
+ onSubmit: (event) => save.mutate(takeField(event, "value")),
131
+ children: [
132
+ hint,
133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
134
+ className: "agents-field",
135
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
136
+ type: "password",
137
+ name: "value",
138
+ autoComplete: "off",
139
+ spellCheck: false,
140
+ required: true
141
+ })]
142
+ }),
143
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
144
+ className: "factory-sheet-actions",
145
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
146
+ type: "submit",
147
+ disabled: save.isPending,
148
+ children: "Save"
149
+ })
150
+ }),
151
+ save.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
152
+ className: "factory-problems",
153
+ role: "alert",
154
+ children: save.error.message
155
+ }) : null
156
+ ]
157
+ });
158
+ }
159
+ /** The Agents panel: sets the one Claude credential the factory's Workset agents use. */
160
+ function AgentsDialog({ onClose }) {
161
+ const queryClient = useQueryClient();
162
+ const status = useQuery(agentCredentialQuery());
163
+ const [tab, setTab] = (0, import_react.useState)("subscription");
164
+ const [saved, setSaved] = (0, import_react.useState)(false);
165
+ const form = TABS.find((entry) => entry.kind === tab);
166
+ const onSaved = (next) => {
167
+ queryClient.setQueryData(agentCredentialKey, next);
168
+ setSaved(true);
169
+ };
170
+ const clear = useMutation({
171
+ mutationFn: clearAgentCredential,
172
+ onSuccess: (next) => {
173
+ queryClient.setQueryData(agentCredentialKey, next);
174
+ setSaved(false);
175
+ }
176
+ });
177
+ const ref = useModalDialog(onClose, (dialog) => dialog.showModal?.());
178
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dialog", {
179
+ ref,
180
+ className: "outcome-dialog agents-dialog",
181
+ "aria-labelledby": "agents-title",
182
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", {
183
+ className: "outcome-dialog-head",
184
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
185
+ className: "outcome-dialog-heading",
186
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
187
+ id: "agents-title",
188
+ children: "Workset agents"
189
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
190
+ className: "outcome-dialog-state",
191
+ "data-agents-status": "",
192
+ children: status.error ? status.error.message : statusText(status.data)
193
+ })]
194
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", {
195
+ method: "dialog",
196
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
197
+ type: "submit",
198
+ className: "outcome-dialog-close",
199
+ "aria-keyshortcuts": "Escape",
200
+ children: ["Close ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "Esc" })]
201
+ })
202
+ })]
203
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
204
+ className: "agents-dialog-body",
205
+ children: [
206
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
207
+ role: "tablist",
208
+ "aria-label": "How to sign in",
209
+ className: "agents-tabs",
210
+ children: TABS.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
211
+ type: "button",
212
+ role: "tab",
213
+ id: `agents-tab-${entry.kind}`,
214
+ "aria-controls": "agents-panel",
215
+ "aria-selected": tab === entry.kind,
216
+ onClick: () => {
217
+ setTab(entry.kind);
218
+ setSaved(false);
219
+ },
220
+ children: entry.tab
221
+ }, entry.kind))
222
+ }),
223
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
224
+ role: "tabpanel",
225
+ id: "agents-panel",
226
+ "aria-labelledby": `agents-tab-${tab}`,
227
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SecretForm, {
228
+ kind: form.kind,
229
+ label: form.label,
230
+ hint: form.hint,
231
+ onSaved
232
+ }, form.kind)
233
+ }),
234
+ saved ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
235
+ className: "note",
236
+ role: "status",
237
+ children: "Saved. The next agent start uses it."
238
+ }) : null,
239
+ status.data?.source === "studio" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
240
+ className: "factory-sheet-actions agents-clear",
241
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
242
+ type: "button",
243
+ onClick: () => clear.mutate(),
244
+ disabled: clear.isPending,
245
+ children: "Remove the credential set in Studio"
246
+ }), clear.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
247
+ className: "factory-problems",
248
+ role: "alert",
249
+ children: clear.error.message
250
+ }) : null]
251
+ }) : null
252
+ ]
253
+ })]
254
+ });
255
+ }
256
+ // src/views/factory/factory-form.tsx
257
+ /**
258
+ * A board action as a form: its own fields (and the pressed button's name and value) are sent
259
+ * through one validated server function, then the board refetches. The markup stays the form
260
+ * the server-rendered board posted, so keyboard submission and field names are unchanged.
261
+ */
262
+ function FactoryForm({ action, id, className, children, ...rest }) {
263
+ const companion = (0, import_react.useContext)(FactoryCompanion);
264
+ const queryClient = useQueryClient();
265
+ const mutation = useMutation({
266
+ mutationFn: (fields) => runFactoryAction({ data: {
267
+ companion,
268
+ action,
269
+ id,
270
+ fields
271
+ } }),
272
+ onSuccess: () => afterFactoryAction(queryClient, companion)
273
+ });
274
+ const submit = (event) => {
275
+ event.preventDefault();
276
+ const form = event.currentTarget;
277
+ const submitter = event.nativeEvent.submitter;
278
+ const fields = {};
279
+ for (const [name, value] of new FormData(form, submitter)) if (typeof value === "string") fields[name] = value;
280
+ mutation.mutate(fields, { onSuccess: () => form.reset() });
281
+ };
282
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
283
+ className,
284
+ "data-factory-action": id ? `/${id}/${action}` : `/${action}`,
285
+ onSubmit: submit,
286
+ "aria-busy": mutation.isPending || void 0,
287
+ ...rest,
288
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("fieldset", {
289
+ className: "factory-form-fields",
290
+ disabled: mutation.isPending,
291
+ children
292
+ }), mutation.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
293
+ className: "factory-problems",
294
+ role: "alert",
295
+ children: mutation.error.message
296
+ }) : null]
297
+ });
298
+ }
299
+ // ../../node_modules/.bun/zustand@5.0.16+ea2f17093d73c934/node_modules/zustand/esm/middleware.mjs
300
+ function createJSONStorage(getStorage, options) {
301
+ let storage;
302
+ try {
303
+ storage = getStorage();
304
+ } catch (e) {
305
+ return;
306
+ }
307
+ return {
308
+ getItem: (name) => {
309
+ var _a;
310
+ const parse = (str2) => {
311
+ if (str2 === null) return null;
312
+ return JSON.parse(str2, options == null ? void 0 : options.reviver);
313
+ };
314
+ const str = (_a = storage.getItem(name)) != null ? _a : null;
315
+ if (str instanceof Promise) return str.then(parse);
316
+ return parse(str);
317
+ },
318
+ setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue, options == null ? void 0 : options.replacer)),
319
+ removeItem: (name) => storage.removeItem(name)
320
+ };
321
+ }
322
+ var toThenable = (fn) => (input) => {
323
+ try {
324
+ const result = fn(input);
325
+ if (result instanceof Promise) return result;
326
+ return {
327
+ then(onFulfilled) {
328
+ return toThenable(onFulfilled)(result);
329
+ },
330
+ catch(_onRejected) {
331
+ return this;
332
+ }
333
+ };
334
+ } catch (e) {
335
+ return {
336
+ then(_onFulfilled) {
337
+ return this;
338
+ },
339
+ catch(onRejected) {
340
+ return toThenable(onRejected)(e);
341
+ }
342
+ };
343
+ }
344
+ };
345
+ var persistImpl = (config, baseOptions) => (set, get, api) => {
346
+ let options = {
347
+ storage: createJSONStorage(() => window.localStorage),
348
+ partialize: (state) => state,
349
+ version: 0,
350
+ merge: (persistedState, currentState) => ({
351
+ ...currentState,
352
+ ...persistedState
353
+ }),
354
+ ...baseOptions
355
+ };
356
+ let hasHydrated = false;
357
+ let hydrationVersion = 0;
358
+ const hydrationListeners = /* @__PURE__ */ new Set();
359
+ const finishHydrationListeners = /* @__PURE__ */ new Set();
360
+ let storage = options.storage;
361
+ if (!storage) return config((...args) => {
362
+ console.warn(`[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`);
363
+ set(...args);
364
+ }, get, api);
365
+ const setItem = () => {
366
+ const state = options.partialize({ ...get() });
367
+ return storage.setItem(options.name, {
368
+ state,
369
+ version: options.version
370
+ });
371
+ };
372
+ const savedSetState = api.setState;
373
+ api.setState = (...args) => {
374
+ savedSetState(...args);
375
+ return setItem();
376
+ };
377
+ const configResult = config((...args) => {
378
+ set(...args);
379
+ return setItem();
380
+ }, get, api);
381
+ api.getInitialState = () => configResult;
382
+ let stateFromStorage;
383
+ const hydrate = () => {
384
+ var _a, _b;
385
+ if (!storage) return;
386
+ const currentVersion = ++hydrationVersion;
387
+ hasHydrated = false;
388
+ hydrationListeners.forEach((cb) => {
389
+ var _a2;
390
+ return cb((_a2 = get()) != null ? _a2 : configResult);
391
+ });
392
+ const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? void 0 : _b.call(options, (_a = get()) != null ? _a : configResult)) || void 0;
393
+ return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {
394
+ if (deserializedStorageValue) {
395
+ if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
396
+ if (options.migrate) {
397
+ const migration = options.migrate(deserializedStorageValue.state, deserializedStorageValue.version);
398
+ if (migration instanceof Promise) return migration.then((result) => [true, result]);
399
+ return [true, migration];
400
+ }
401
+ console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`);
402
+ } else return [false, deserializedStorageValue.state];
403
+ }
404
+ return [false, void 0];
405
+ }).then((migrationResult) => {
406
+ var _a2;
407
+ if (currentVersion !== hydrationVersion) return;
408
+ const [migrated, migratedState] = migrationResult;
409
+ stateFromStorage = options.merge(migratedState, (_a2 = get()) != null ? _a2 : configResult);
410
+ set(stateFromStorage, true);
411
+ if (migrated) return setItem();
412
+ }).then(() => {
413
+ if (currentVersion !== hydrationVersion) return;
414
+ postRehydrationCallback?.(get(), void 0);
415
+ stateFromStorage = get();
416
+ hasHydrated = true;
417
+ finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
418
+ }).catch((e) => {
419
+ if (currentVersion !== hydrationVersion) return;
420
+ postRehydrationCallback?.(void 0, e);
421
+ });
422
+ };
423
+ api.persist = {
424
+ setOptions: (newOptions) => {
425
+ options = {
426
+ ...options,
427
+ ...newOptions
428
+ };
429
+ if (newOptions.storage) storage = newOptions.storage;
430
+ },
431
+ clearStorage: () => {
432
+ ++hydrationVersion;
433
+ storage?.removeItem(options.name);
434
+ },
435
+ getOptions: () => options,
436
+ rehydrate: () => hydrate(),
437
+ hasHydrated: () => hasHydrated,
438
+ onHydrate: (cb) => {
439
+ hydrationListeners.add(cb);
440
+ return () => {
441
+ hydrationListeners.delete(cb);
442
+ };
443
+ },
444
+ onFinishHydration: (cb) => {
445
+ finishHydrationListeners.add(cb);
446
+ return () => {
447
+ finishHydrationListeners.delete(cb);
448
+ };
449
+ }
450
+ };
451
+ if (!options.skipHydration) hydrate();
452
+ return stateFromStorage || configResult;
453
+ };
454
+ var persist = persistImpl;
455
+ // src/stores/factory-ui.ts
456
+ var useFactoryUi = create()(persist((set) => ({
457
+ filter: "",
458
+ setFilter: (filter) => set({ filter }),
459
+ stepped: false,
460
+ setStepped: (stepped) => set({ stepped }),
461
+ agentsOpen: false,
462
+ setAgentsOpen: (agentsOpen) => set({ agentsOpen })
463
+ }), {
464
+ name: "mate.factory.filter",
465
+ storage: createJSONStorage(() => sessionStorage),
466
+ partialize: ({ filter }) => ({ filter })
467
+ }));
468
+ // src/views/factory/factory-live.ts
469
+ var SEEN_KEY = "mate.factory.needsYou";
470
+ /** Whether every word of `query` occurs in `text`, ignoring case. */
471
+ function matchesFilter(text, query) {
472
+ const haystack = text.toLowerCase();
473
+ return query.toLowerCase().split(/\s+/).every((word) => haystack.includes(word));
474
+ }
475
+ /** The page title with the decision count in front, without stacking counts. */
476
+ function titled(title, count) {
477
+ const bare = title.replace(/^\(\d+\) /, "");
478
+ return count > 0 ? `(${count}) ${bare}` : bare;
479
+ }
480
+ /** The row `delta` steps from the focused one, held at the ends; the first row when none is. */
481
+ function stepRow(rows, focused, delta) {
482
+ const at = focused ? rows.indexOf(focused) : -1;
483
+ if (at === -1) return rows[0];
484
+ return rows[Math.min(rows.length - 1, Math.max(0, at + delta))];
485
+ }
486
+ /** Whether a key press belongs to a field or the terminal rather than to a shortcut. */
487
+ function typing(target) {
488
+ return Boolean(target?.closest?.("input, textarea, select, [contenteditable], .outcome-terminal"));
489
+ }
490
+ /** In an open dialog: 1–9 pick a one-click answer, J/K the next or previous Outcome. */
491
+ function dialogButton(dialog, key) {
492
+ if (/^[1-9]$/.test(key)) return dialog.querySelector(`[data-option-key="${key}"]`);
493
+ const step = {
494
+ j: "J",
495
+ k: "K"
496
+ }[key];
497
+ if (!step) return null;
498
+ return dialog.querySelector(`[data-outcome-goto][aria-keyshortcuts="${step}"]`);
499
+ }
500
+ /** On the board: N focuses the new-outcome field, / the filter. */
501
+ function boardField(doc, key) {
502
+ if (key === "n") return doc.querySelector("form[data-outcome-input] textarea");
503
+ if (key === "/") return doc.querySelector("[data-outcome-filter]");
504
+ return null;
505
+ }
506
+ /**
507
+ * Board shortcuts: N starts a new outcome, / filters, J/K (arrows on a row) move between
508
+ * rows, Enter opens one. In an open dialog J/K step to the next or previous Outcome, 1–9
509
+ * pick a one-click answer and Ctrl/Cmd+Enter sends the form being typed in. Fields and the
510
+ * terminal keep every other key.
511
+ */
512
+ function factoryKeyHandler(doc) {
513
+ return (event) => {
514
+ if (event.defaultPrevented || event.altKey) return;
515
+ const target = event.target;
516
+ if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
517
+ const form = target?.closest?.("form");
518
+ if (target?.localName === "textarea" && form) {
519
+ event.preventDefault();
520
+ if (form.querySelector("button[type=\"submit\"].factory-primary:disabled")) return;
521
+ const start = form.querySelector("button[value=\"start\"]");
522
+ form.requestSubmit(start ?? void 0);
523
+ }
524
+ return;
525
+ }
526
+ if (event.ctrlKey || event.metaKey || typing(target)) return;
527
+ const dialog = doc.querySelector("dialog.outcome-dialog[open]");
528
+ if (dialog) {
529
+ const button = dialogButton(dialog, event.key);
530
+ if (button) {
531
+ event.preventDefault();
532
+ button.click();
533
+ }
534
+ return;
535
+ }
536
+ const field = boardField(doc, event.key);
537
+ if (field) {
538
+ event.preventDefault();
539
+ field.focus();
540
+ return;
541
+ }
542
+ const onRow = Boolean(target?.matches?.("[data-outcome-row]"));
543
+ const down = event.key === "j" || onRow && event.key === "ArrowDown";
544
+ const up = event.key === "k" || onRow && event.key === "ArrowUp";
545
+ if (!down && !up) return;
546
+ const next = stepRow([...doc.querySelectorAll("[data-outcome-row]")].filter((row) => row.getClientRects().length > 0), doc.activeElement, down ? 1 : -1);
547
+ if (!next) return;
548
+ event.preventDefault();
549
+ next.focus();
550
+ next.scrollIntoView({ block: "nearest" });
551
+ };
552
+ }
553
+ function useFactoryKeys() {
554
+ (0, import_react.useEffect)(() => {
555
+ const handler = factoryKeyHandler(document);
556
+ document.addEventListener("keydown", handler);
557
+ return () => document.removeEventListener("keydown", handler);
558
+ }, []);
559
+ }
560
+ /** Puts the decision count in the title and notifies when it grows, once per count. */
561
+ function useNeedsYou(count) {
562
+ (0, import_react.useEffect)(() => {
563
+ document.title = titled(document.title, count);
564
+ if (typeof Notification === "undefined" || Notification.permission !== "granted") return;
565
+ let seen = 0;
566
+ try {
567
+ seen = Number(sessionStorage.getItem(SEEN_KEY) || "0");
568
+ sessionStorage.setItem(SEEN_KEY, String(count));
569
+ } catch {}
570
+ if (count > seen) new Notification("Mate factory", { body: count === 1 ? "1 decision needs you" : `${count} decisions need you` });
571
+ }, [count]);
572
+ (0, import_react.useEffect)(() => () => void (document.title = titled(document.title, 0)), []);
573
+ }
574
+ /** Whether to offer notifications: only while the browser has not been asked yet. */
575
+ function useNotificationOffer() {
576
+ const [offered, setOffered] = (0, import_react.useState)(() => typeof Notification !== "undefined" && Notification.permission === "default");
577
+ return {
578
+ offered,
579
+ ask: () => void Notification.requestPermission().then(() => setOffered(false))
580
+ };
581
+ }
582
+ // src/views/factory/age.ts
583
+ /** Whole days, hours or minutes since `iso`, for an age; empty without a render time. */
584
+ function ageText(iso, now) {
585
+ if (now === void 0) return "";
586
+ const minutes = Math.max(0, Math.floor((now - Date.parse(iso)) / 6e4));
587
+ if (minutes >= 1440) return `${Math.floor(minutes / 1440)}d`;
588
+ if (minutes >= 60) return `${Math.floor(minutes / 60)}h`;
589
+ return `${minutes}m`;
590
+ }
591
+ // src/views/factory/use-outcome-log.ts
592
+ var EMPTY_LOG = {
593
+ pieces: [],
594
+ open: {}
595
+ };
596
+ /** The runner's own notes in the stored log: stage prompts, links, commits, pushes and the like. */
597
+ var FACTORY_LINE = /^(> |committed: |pushed |published |linked |Returned to automation|no review report |the review report for |\S+ is now at )/;
598
+ /**
599
+ * The stored log is plain text; its lines are told apart by the runner's prefixes. Tool calls
600
+ * are not stored, so a replay holds agent text and factory notes only.
601
+ */
602
+ function classifyStored(log) {
603
+ const pieces = [];
604
+ for (const line of log.split(/(?<=\n)/)) {
605
+ const kind = FACTORY_LINE.test(line) ? "factory" : "agent";
606
+ const last = pieces.at(-1);
607
+ if (last && (last.kind === kind || line.trim() === "")) last.text += line;
608
+ else pieces.push({
609
+ kind,
610
+ text: line
611
+ });
612
+ }
613
+ return pieces;
614
+ }
615
+ /** Streaming blocks by id, tool calls as lines, each piece kept with its kind. */
616
+ function logReducer(state, event) {
617
+ const append = (kind, text, id) => {
618
+ const pieces = [...state.pieces, id === void 0 ? {
619
+ kind,
620
+ text
621
+ } : {
622
+ id,
623
+ kind,
624
+ text
625
+ }];
626
+ return {
627
+ pieces,
628
+ open: id === void 0 ? state.open : {
629
+ ...state.open,
630
+ [id]: pieces.length - 1
631
+ }
632
+ };
633
+ };
634
+ const grow = (id, text) => {
635
+ const at = state.open[id];
636
+ if (at === void 0) return append("agent", text, id);
637
+ const pieces = [...state.pieces];
638
+ pieces[at] = {
639
+ ...pieces[at],
640
+ text: pieces[at].text + text
641
+ };
642
+ return {
643
+ ...state,
644
+ pieces
645
+ };
646
+ };
647
+ switch (event.type) {
648
+ case "replay": {
649
+ let next = {
650
+ pieces: classifyStored(event.log),
651
+ open: {}
652
+ };
653
+ for (const block of event.open) next = logReducer(next, {
654
+ type: "text",
655
+ ...block,
656
+ delta: block.text
657
+ });
658
+ return next;
659
+ }
660
+ case "text": return event.id === void 0 ? append("agent", event.delta) : grow(event.id, event.delta);
661
+ case "text-end": {
662
+ const next = grow(event.id, "\n");
663
+ const { [event.id]: _ended, ...open } = next.open;
664
+ return {
665
+ ...next,
666
+ open
667
+ };
668
+ }
669
+ case "tool": return append("tool", `› ${event.name} ${event.summary}\n`);
670
+ case "tool-done": return event.failed ? append("failed", ` ${event.name} failed\n`) : state;
671
+ case "log": return append("factory", event.text);
672
+ case "lost": return append("factory", "\nThis view fell behind the run; close and reopen the Outcome.\n");
673
+ case "settled": return state;
674
+ }
675
+ }
676
+ /**
677
+ * Follows one Outcome's run log for as long as its dialog is open. The stream keeps going
678
+ * across stages; when a stage ends the board's own update shows the new state in place.
679
+ */
680
+ function useOutcomeLog(url) {
681
+ const [state, dispatch] = (0, import_react.useReducer)((current, event) => event.type === "reset" ? {
682
+ ...EMPTY_LOG,
683
+ ended: false
684
+ } : {
685
+ ...logReducer(current, event),
686
+ ended: current.ended || event.type === "lost"
687
+ }, {
688
+ ...EMPTY_LOG,
689
+ ended: false
690
+ });
691
+ (0, import_react.useEffect)(() => {
692
+ if (typeof EventSource === "undefined") return;
693
+ dispatch({ type: "reset" });
694
+ const source = new EventSource(url);
695
+ source.addEventListener("message", (message) => {
696
+ try {
697
+ dispatch(JSON.parse(message.data));
698
+ } catch {}
699
+ });
700
+ return () => source.close();
701
+ }, [url]);
702
+ return {
703
+ pieces: state.pieces,
704
+ ended: state.ended
705
+ };
706
+ }
707
+ // src/terminal/outcome-terminal.tsx
708
+ /**
709
+ * One Outcome's Workset session in a terminal view: starts it, or attaches to the live one,
710
+ * and restarts a session that went away. Closing only detaches; the session keeps running for
711
+ * its detach window.
712
+ */
713
+ var OutcomeSession = class {
714
+ mount;
715
+ outcome;
716
+ companion;
717
+ failed;
718
+ focus;
719
+ term = null;
720
+ ws = null;
721
+ sessionId = null;
722
+ observer = null;
723
+ closed = false;
724
+ constructor(mount, outcome, companion, failed, focus) {
725
+ this.mount = mount;
726
+ this.outcome = outcome;
727
+ this.companion = companion;
728
+ this.failed = failed;
729
+ this.focus = focus;
730
+ this.open();
731
+ }
732
+ async open() {
733
+ try {
734
+ const WTerm = await loadWTerm();
735
+ if (this.closed) return;
736
+ const term = new WTerm(this.mount, {
737
+ cursorBlink: true,
738
+ autoResize: false,
739
+ wasmUrl: TERMINAL_WASM
740
+ });
741
+ this.term = term;
742
+ term.onData = (data) => this.send({
743
+ type: "input",
744
+ data
745
+ });
746
+ term.onResize = () => this.send({
747
+ type: "resize",
748
+ cols: term.cols,
749
+ rows: term.rows
750
+ });
751
+ await term.init();
752
+ if (this.closed) return;
753
+ term.fit();
754
+ this.observer = new ResizeObserver(() => {
755
+ if (this.mount.clientWidth && this.mount.clientHeight) term.fit();
756
+ });
757
+ this.observer.observe(this.mount);
758
+ this.connect();
759
+ } catch {
760
+ this.term = null;
761
+ this.failed();
762
+ }
763
+ }
764
+ send(message) {
765
+ sendMessage(this.ws, message);
766
+ }
767
+ notice(text) {
768
+ this.term?.write(`\r\n\u001b[2m${text}\u001b[0m\r\n`);
769
+ }
770
+ start() {
771
+ if (!this.term) return;
772
+ const { cols, rows } = this.term;
773
+ this.send({
774
+ type: "start",
775
+ workset: this.outcome,
776
+ companion: this.companion,
777
+ cols,
778
+ rows
779
+ });
780
+ }
781
+ connect() {
782
+ const ws = openTerminalSocket();
783
+ this.ws = ws;
784
+ ws.onopen = () => {
785
+ if (!this.term) return;
786
+ const { cols, rows } = this.term;
787
+ if (this.sessionId) this.send({
788
+ type: "attach",
789
+ sessionId: this.sessionId,
790
+ cols,
791
+ rows
792
+ });
793
+ else this.start();
794
+ };
795
+ ws.onmessage = (event) => this.receive(event.data);
796
+ ws.onclose = () => {
797
+ if (this.ws === ws) this.ws = null;
798
+ };
799
+ }
800
+ receive(data) {
801
+ const term = this.term;
802
+ if (!term) return;
803
+ if (typeof data !== "string") {
804
+ term.write(new Uint8Array(data));
805
+ return;
806
+ }
807
+ const message = parseMessage(data);
808
+ if (!message) return;
809
+ if (message.type === "ready") {
810
+ this.sessionId = message.sessionId ?? null;
811
+ term.write("\x1Bc");
812
+ if (this.focus) term.focus();
813
+ } else if (message.type === "gone") {
814
+ this.sessionId = null;
815
+ this.start();
816
+ } else if (message.type === "exit" || message.type === "ended") {
817
+ this.sessionId = null;
818
+ this.notice("The session ended. Return to automation when you are done, or close and reopen the Outcome to start it again.");
819
+ } else if (message.type === "takenOver") this.notice("Another tab has this session now.");
820
+ else if (message.type === "error" && message.reason) this.notice(message.reason);
821
+ }
822
+ close() {
823
+ this.closed = true;
824
+ this.observer?.disconnect();
825
+ this.ws?.close();
826
+ this.ws = null;
827
+ this.term?.destroy();
828
+ this.term = null;
829
+ }
830
+ };
831
+ /** The taken-over session inside an Outcome's dialog; mounting starts or attaches, unmounting detaches. */
832
+ function OutcomeTerminal({ outcome, companion, focus = true }) {
833
+ const mount = (0, import_react.useRef)(null);
834
+ const [failed, setFailed] = (0, import_react.useState)(false);
835
+ const focusOnReady = (0, import_react.useRef)(focus);
836
+ (0, import_react.useEffect)(() => {
837
+ const session = new OutcomeSession(mount.current, outcome, companion, () => setFailed(true), focusOnReady.current);
838
+ return () => session.close();
839
+ }, [outcome, companion]);
840
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
841
+ ref: mount,
842
+ className: "outcome-terminal",
843
+ "data-outcome-terminal": outcome,
844
+ "data-companion": companion,
845
+ "data-terminal-error": failed ? "" : void 0,
846
+ children: failed ? "The terminal could not start in this browser. Close and reopen the Outcome to retry." : null
847
+ });
848
+ }
849
+ // src/views/factory/outcome.ts
850
+ var ACTIVE = /* @__PURE__ */ new Set(["queued", "running"]);
851
+ /** Why an Outcome waits on a person, or `null` when it does not. */
852
+ function attentionKind(workset, run) {
853
+ if (workset.stage === "done") return null;
854
+ if (run?.control?.mode === "manual") return "control";
855
+ if (run?.state === "waiting") return "decision";
856
+ if (run?.state === "failed" || run?.state === "interrupted") return "problem";
857
+ if (run && ACTIVE.has(run.state)) return null;
858
+ if (workset.stage === "human-review") return "review";
859
+ if (workset.stage === "merge-wait") return "merge";
860
+ if (workset.stage === "publish") return "publish";
861
+ return null;
862
+ }
863
+ function byId(a, b) {
864
+ return a.workset.id < b.workset.id ? -1 : a.workset.id > b.workset.id ? 1 : 0;
865
+ }
866
+ /** When an Outcome started waiting, as far as Studio knows; unknown sorts last. */
867
+ function waitingSince(item) {
868
+ const parsed = Date.parse(item.run?.updatedAt || item.workset.queuedAt || "");
869
+ return Number.isNaN(parsed) ? Number.POSITIVE_INFINITY : parsed;
870
+ }
871
+ function itemsOf(worksets, runs) {
872
+ return worksets.map((workset) => ({
873
+ workset,
874
+ run: runs?.[workset.id]
875
+ }));
876
+ }
877
+ function rankCompare(a, b) {
878
+ return compareRanked({
879
+ id: a.workset.id,
880
+ rank: rankOf(a.workset)
881
+ }, {
882
+ id: b.workset.id,
883
+ rank: rankOf(b.workset)
884
+ });
885
+ }
886
+ /** When an Outcome last changed, newest-first ordering for the history. */
887
+ function lastChange(item) {
888
+ const stamps = [
889
+ item.run?.situations?.[0]?.at,
890
+ item.run?.updatedAt,
891
+ item.workset.queuedAt
892
+ ];
893
+ return Math.max(0, ...stamps.map((stamp) => Date.parse(stamp ?? "")).filter(Number.isFinite));
894
+ }
895
+ /** A Later Outcome that already has a plan, or a run, is under way all the same. */
896
+ function underWay(item) {
897
+ return item.workset.queuedAt !== void 0 || item.workset.changes.length > 0 || item.run !== void 0 && item.run.state !== "idle";
898
+ }
899
+ /** Every Outcome where the home shows it; the view lists one that needs the person only there. */
900
+ function factoryHome(worksets, runs) {
901
+ const items = itemsOf(worksets, runs);
902
+ const attention = items.flatMap((item) => {
903
+ const kind = attentionKind(item.workset, item.run);
904
+ return kind ? [{
905
+ ...item,
906
+ kind
907
+ }] : [];
908
+ }).toSorted((a, b) => waitingSince(a) - waitingSince(b) || byId(a, b));
909
+ const open = items.filter((item) => item.workset.stage !== "done");
910
+ return {
911
+ attention,
912
+ active: open.filter(underWay).toSorted(rankCompare),
913
+ later: open.filter((item) => !underWay(item)).toSorted(byId),
914
+ completed: items.filter((item) => item.workset.stage === "done").toSorted((a, b) => lastChange(b) - lastChange(a) || byId(a, b))
915
+ };
916
+ }
917
+ /** Each milestone is reached once the Outcome's stage is past the one named. */
918
+ var MILESTONES = [
919
+ {
920
+ label: "Understood",
921
+ after: "clarify-intent",
922
+ next: "The factory is working out what you want"
923
+ },
924
+ {
925
+ label: "Approach chosen",
926
+ after: "explore",
927
+ next: "The factory is choosing the approach"
928
+ },
929
+ {
930
+ label: "Plan ready",
931
+ after: "propose",
932
+ next: "The factory is writing the plan"
933
+ },
934
+ {
935
+ label: "Plan approved",
936
+ after: "human-review",
937
+ next: "Ready for your review"
938
+ },
939
+ {
940
+ label: "Built",
941
+ after: "apply",
942
+ next: "The factory is building it"
943
+ },
944
+ {
945
+ label: "Merged",
946
+ after: "merge-wait",
947
+ next: "Ready for you to merge"
948
+ },
949
+ {
950
+ label: "Delivered",
951
+ after: "publish",
952
+ next: "Ready to publish"
953
+ }
954
+ ];
955
+ function stageIndex(stage) {
956
+ return WORKSET_STAGE_ORDER.indexOf(stage);
957
+ }
958
+ function milestonesOf(workset) {
959
+ const at = stageIndex(workset.stage);
960
+ return MILESTONES.map((milestone) => ({
961
+ label: milestone.label,
962
+ reached: at > stageIndex(milestone.after)
963
+ }));
964
+ }
965
+ function savedForLater(workset, run) {
966
+ return !workset.queuedAt && workset.changes.length === 0 && (!run || run.state === "idle");
967
+ }
968
+ /** The next meaningful step, phrased by who acts next. */
969
+ function nextStepOf(workset, run) {
970
+ if (workset.stage === "done") return "Delivered";
971
+ if (run?.control?.mode === "manual") return "You have control";
972
+ if (run?.state === "waiting") return "Waiting for your answer";
973
+ if (run?.state === "failed" || run?.state === "interrupted") return "Stopped; needs you";
974
+ if (savedForLater(workset, run)) return "Saved for later";
975
+ const at = stageIndex(workset.stage);
976
+ return MILESTONES.find((milestone) => at <= stageIndex(milestone.after))?.next ?? "Delivered";
977
+ }
978
+ var DERIVED = {
979
+ "clarify-intent": "Understanding what you want.",
980
+ explore: "Working out the approach.",
981
+ propose: "Writing the plan.",
982
+ "human-review": "A plan is ready for your review.",
983
+ apply: "Building it.",
984
+ "merge-wait": "Built; waiting for the merge.",
985
+ publish: "Merged; ready to publish.",
986
+ done: "Delivered."
987
+ };
988
+ /** A sentence from the stage, for an Outcome the agent has not reported on. */
989
+ function derivedSituation(workset, run) {
990
+ if (run?.state === "queued") {
991
+ if (run.waiting === "workset-slot") return "Waiting for a Workset slot.";
992
+ if (run.waiting === "build-slot") return "Waiting for a build slot.";
993
+ return "Waiting for a free slot.";
994
+ }
995
+ if (run?.state === "failed") return `Stopped: ${run.reason}`;
996
+ if (run?.state === "interrupted") return "Stopped when Studio restarted.";
997
+ if (run?.state === "waiting") return "Waiting for your answer.";
998
+ if (savedForLater(workset, run)) return "Saved for later.";
999
+ return DERIVED[workset.stage] ?? workset.stageLabel;
1000
+ }
1001
+ /** Run states that say more than the last report; queued, waiting, failed and interrupted. */
1002
+ var OVERRIDING = /* @__PURE__ */ new Set([
1003
+ "queued",
1004
+ "waiting",
1005
+ "failed",
1006
+ "interrupted"
1007
+ ]);
1008
+ /** The latest reported situation, or a derived one without a time. */
1009
+ function situationOf(workset, run) {
1010
+ const reported = run?.situations?.[0];
1011
+ if (reported && !(run && OVERRIDING.has(run.state))) return reported;
1012
+ return { text: derivedSituation(workset, run) };
1013
+ }
1014
+ var ACTIVITY_LABELS = {
1015
+ running: "Running",
1016
+ queued: "Queued",
1017
+ "needs-you": "Needs you",
1018
+ control: "You have control",
1019
+ stopped: "Stopped",
1020
+ idle: "Idle",
1021
+ later: "Saved for later",
1022
+ done: "Delivered"
1023
+ };
1024
+ function activityOf(workset, run) {
1025
+ if (workset.stage === "done") return "done";
1026
+ if (run?.control?.mode === "manual") return "control";
1027
+ if (run?.state === "failed" || run?.state === "interrupted") return "stopped";
1028
+ if (run?.state === "running") return "running";
1029
+ if (run?.state === "queued") return "queued";
1030
+ if (attentionKind(workset, run)) return "needs-you";
1031
+ return underWay({
1032
+ workset,
1033
+ run
1034
+ }) ? "idle" : "later";
1035
+ }
1036
+ /** The Delivery Path map node each stage sits at; `complete` once delivered. */
1037
+ var PATH_NODES = {
1038
+ "clarify-intent": "clarify-intent",
1039
+ explore: "explore",
1040
+ propose: "propose",
1041
+ "human-review": "reviews",
1042
+ apply: "apply",
1043
+ "merge-wait": "archive",
1044
+ publish: "publish",
1045
+ done: "complete"
1046
+ };
1047
+ var pathNodeOf = (workset) => PATH_NODES[workset.stage];
1048
+ // src/views/factory/factory-view.tsx
1049
+ var ATTENTION_LABELS = {
1050
+ control: "You have control",
1051
+ decision: "Decision needed",
1052
+ review: "Plan ready for review",
1053
+ merge: "Ready to merge",
1054
+ publish: "Ready to publish",
1055
+ problem: "Something went wrong"
1056
+ };
1057
+ /** What each kind of attention expects of the person, under its heading in the dialog. */
1058
+ var ATTENTION_HINTS = {
1059
+ decision: "The run is paused on this. Pick an option or answer in your words; it continues on its own.",
1060
+ review: "Read each report, then approve to start building, or request a change to revise the plan.",
1061
+ merge: "Merge the delivery branch on your forge; the board picks it up on its next refresh.",
1062
+ publish: "Publishing commits, tags and pushes the archived specs to the companion.",
1063
+ problem: "Retry runs the stage again; take control to fix it yourself.",
1064
+ control: "You work in the factory's own conversation. Exit Claude, then return the Outcome to automation; the factory checks what changed and continues."
1065
+ };
1066
+ /** What Take control does, beside the button. */
1067
+ var TAKE_CONTROL_HINT = "Pauses automation after the current stage; you continue the factory's own conversation here.";
1068
+ var RECENT_COMPLETED = 5;
1069
+ /** "Decisions needed (3)" when the agent asked several questions together. */
1070
+ function attentionLabel(kind, run) {
1071
+ const count = run?.state === "waiting" ? questionsOf(run).length : 0;
1072
+ return kind === "decision" && count > 1 ? `Decisions needed (${count})` : ATTENTION_LABELS[kind];
1073
+ }
1074
+ /** The actions that move an Outcome forward; the rest stay quiet. */
1075
+ var PRIMARY_ACTIONS = /* @__PURE__ */ new Set([
1076
+ "answer",
1077
+ "start-apply",
1078
+ "publish",
1079
+ "return",
1080
+ "retry",
1081
+ "start"
1082
+ ]);
1083
+ function ActionForm({ id, action, label, children }) {
1084
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(FactoryForm, {
1085
+ id,
1086
+ action,
1087
+ className: "factory-action",
1088
+ children: [children, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
1089
+ type: "submit",
1090
+ className: PRIMARY_ACTIONS.has(action) ? "factory-primary" : void 0,
1091
+ children: label
1092
+ })]
1093
+ });
1094
+ }
1095
+ /** A control for one action; none when Studio is read-only or the Outcome does not accept it. */
1096
+ function actionFor(item, context) {
1097
+ const accepted = outcomeActions(item.workset, item.run, context);
1098
+ return (action, label, children) => context.writable && accepted.has(action) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionForm, {
1099
+ id: item.workset.id,
1100
+ action,
1101
+ label,
1102
+ children
1103
+ }) : null;
1104
+ }
1105
+ /** The Outcome's state as a coloured dot; the text beside it says the same in words. */
1106
+ function ActivityDot({ activity }) {
1107
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1108
+ className: "activity-dot",
1109
+ "data-activity": activity,
1110
+ title: ACTIVITY_LABELS[activity],
1111
+ "aria-hidden": "true"
1112
+ });
1113
+ }
1114
+ /** Plain-language input; Start runs it at once, Save for later keeps it unstarted. */
1115
+ function OutcomeInput({ repositories, context }) {
1116
+ if (!context.writable) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1117
+ className: "note",
1118
+ children: "Read-only mode. Start Studio with --writable to describe outcomes."
1119
+ });
1120
+ if (repositories.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1121
+ className: "note",
1122
+ children: "Link a Working Repository to this companion to describe outcomes."
1123
+ });
1124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(FactoryForm, {
1125
+ action: "create",
1126
+ className: "outcome-input",
1127
+ "data-outcome-input": "",
1128
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1129
+ className: "outcome-input-label",
1130
+ children: "What should we build or improve?"
1131
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
1132
+ name: "text",
1133
+ rows: 3,
1134
+ required: true,
1135
+ placeholder: "Make onboarding easier: fewer signup steps, and keep authentication working."
1136
+ })] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1137
+ className: "outcome-input-actions",
1138
+ children: [
1139
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
1140
+ type: "submit",
1141
+ name: "start",
1142
+ value: "start",
1143
+ className: "factory-primary",
1144
+ children: ["Start ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "⌘↵" })]
1145
+ }),
1146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
1147
+ type: "submit",
1148
+ name: "start",
1149
+ value: "later",
1150
+ children: "Save for later"
1151
+ }),
1152
+ repositories.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
1153
+ name: "repository",
1154
+ required: true,
1155
+ "aria-label": "Working Repository",
1156
+ children: repositories.map((repository) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
1157
+ value: repository,
1158
+ children: repository
1159
+ }, repository))
1160
+ }) : null
1161
+ ]
1162
+ })]
1163
+ });
1164
+ }
1165
+ /** Milestones as a row of pips and a count; the title names the next one. */
1166
+ function MilestoneTrack({ workset }) {
1167
+ const milestones = milestonesOf(workset);
1168
+ const reached = milestones.filter((milestone) => milestone.reached).length;
1169
+ const next = milestones.find((milestone) => !milestone.reached);
1170
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1171
+ className: "outcome-row-track",
1172
+ title: `${reached} of ${milestones.length} milestones${next ? `; next: ${next.label}` : ""}`,
1173
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1174
+ className: "outcome-row-pips",
1175
+ "aria-hidden": "true",
1176
+ children: milestones.map((milestone) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("i", { "data-reached": milestone.reached ? "true" : "false" }, milestone.label))
1177
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1178
+ className: "mono",
1179
+ children: [
1180
+ reached,
1181
+ "/",
1182
+ milestones.length
1183
+ ]
1184
+ })]
1185
+ });
1186
+ }
1187
+ function Checks({ checks }) {
1188
+ if (!checks?.length) return null;
1189
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
1190
+ className: "outcome-checks",
1191
+ "aria-label": "Checks",
1192
+ children: checks.map((check) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
1193
+ "data-passed": check.passed ? "true" : "false",
1194
+ children: [
1195
+ check.passed ? "✓" : "✗",
1196
+ " ",
1197
+ check.name
1198
+ ]
1199
+ }, check.name))
1200
+ });
1201
+ }
1202
+ /** Review plan and View changes, when there is something to look at. */
1203
+ function ResultLinks({ item }) {
1204
+ const reports = Object.entries(item.run?.reviewReports ?? {});
1205
+ const compare = item.run?.compareUrl;
1206
+ if (reports.length === 0 && !compare) return null;
1207
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1208
+ className: "outcome-results",
1209
+ children: [reports.map(([change, id]) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("a", {
1210
+ href: `${REPORT_VIEW_PREFIX}${id}`,
1211
+ target: "_blank",
1212
+ rel: "noreferrer",
1213
+ children: ["Review plan", reports.length > 1 ? ` · ${change}` : ""]
1214
+ }, change)), compare ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
1215
+ href: compare,
1216
+ target: "_blank",
1217
+ rel: "noreferrer",
1218
+ children: "View changes"
1219
+ }) : null]
1220
+ });
1221
+ }
1222
+ /** The stored review report per linked change, each in a frame; missing ones are named. */
1223
+ function ReviewReports({ item }) {
1224
+ const stored = item.run?.reviewReports ?? {};
1225
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1226
+ className: "factory-review-reports",
1227
+ children: item.workset.changes.map((change) => stored[change] ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("figure", {
1228
+ className: "factory-review-report",
1229
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("figcaption", {
1230
+ className: "mono",
1231
+ children: [
1232
+ change,
1233
+ " ·",
1234
+ " ",
1235
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
1236
+ href: `${REPORT_VIEW_PREFIX}${stored[change]}`,
1237
+ target: "_blank",
1238
+ rel: "noreferrer",
1239
+ children: "open"
1240
+ })
1241
+ ]
1242
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("iframe", {
1243
+ src: `${REPORT_VIEW_PREFIX}${stored[change]}`,
1244
+ title: `Review report for ${change}`,
1245
+ loading: "lazy",
1246
+ sandbox: "allow-scripts allow-modals"
1247
+ })]
1248
+ }, change) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
1249
+ className: "note",
1250
+ "data-report-missing": change,
1251
+ children: [
1252
+ "No review report for ",
1253
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1254
+ className: "mono",
1255
+ children: change
1256
+ }),
1257
+ "."
1258
+ ]
1259
+ }, change))
1260
+ });
1261
+ }
1262
+ /** Before archive feedback revises the plan; after it, it starts a new Outcome. */
1263
+ function FeedbackField({ item, context }) {
1264
+ if (!context.writable) return null;
1265
+ const { stage } = item.workset;
1266
+ if (stage === "publish" || stage === "done") return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(FactoryForm, {
1267
+ action: "create",
1268
+ className: "outcome-feedback",
1269
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
1270
+ name: "text",
1271
+ rows: 2,
1272
+ required: true,
1273
+ "aria-label": "A new outcome"
1274
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
1275
+ type: "submit",
1276
+ name: "start",
1277
+ value: "start",
1278
+ children: "Start as a new outcome"
1279
+ })]
1280
+ });
1281
+ return actionFor(item, context)("feedback", "Request a change", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
1282
+ name: "feedback",
1283
+ rows: 2,
1284
+ required: true,
1285
+ "aria-label": "Request a change",
1286
+ placeholder: "What should change?"
1287
+ }));
1288
+ }
1289
+ var runActive = (run) => run?.state === "running" || run?.state === "queued";
1290
+ /** The run's log in its dialog; the client follows it live while the dialog is open. */
1291
+ function OutcomeLog({ item }) {
1292
+ const { workset, run } = item;
1293
+ const active = runActive(run);
1294
+ if (!run?.hasLog && !active) return null;
1295
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
1296
+ className: "outcome-log-section",
1297
+ "aria-label": "Log",
1298
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", {
1299
+ className: "outcome-section-head",
1300
+ children: [
1301
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "Log" }),
1302
+ active ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1303
+ className: "outcome-log-live",
1304
+ children: "live"
1305
+ }) : null,
1306
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
1307
+ href: factoryLogRoute(workset.id),
1308
+ target: "_blank",
1309
+ rel: "noreferrer",
1310
+ children: "Full log"
1311
+ })
1312
+ ]
1313
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LiveLog, { id: workset.id })]
1314
+ });
1315
+ }
1316
+ /** The stored log, then the running stage's text and tool activity as it arrives, by who wrote it. */
1317
+ function LiveLog({ id }) {
1318
+ const { pieces, ended } = useOutcomeLog(factoryLogStreamRoute(id));
1319
+ const ref = (0, import_react.useRef)(null);
1320
+ const following = (0, import_react.useRef)(true);
1321
+ const [reading, setReading] = (0, import_react.useState)(false);
1322
+ (0, import_react.useEffect)(() => {
1323
+ const pre = ref.current;
1324
+ if (pre && pieces.length > 0 && following.current) pre.scrollTop = pre.scrollHeight;
1325
+ }, [pieces]);
1326
+ const toEnd = () => {
1327
+ const pre = ref.current;
1328
+ if (!pre) return;
1329
+ pre.scrollTop = pre.scrollHeight;
1330
+ following.current = true;
1331
+ setReading(false);
1332
+ };
1333
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1334
+ className: "outcome-log-frame",
1335
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", {
1336
+ ref,
1337
+ role: "log",
1338
+ "aria-label": "Run log",
1339
+ tabIndex: 0,
1340
+ onScroll: (event) => {
1341
+ const pre = event.currentTarget;
1342
+ following.current = pre.scrollHeight - pre.scrollTop - pre.clientHeight < 48;
1343
+ setReading(!following.current);
1344
+ },
1345
+ className: "outcome-log",
1346
+ "data-outcome-log": factoryLogStreamRoute(id),
1347
+ "data-ended": ended || void 0,
1348
+ children: pieces.length > 0 ? pieces.map((piece, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1349
+ "data-kind": piece.kind,
1350
+ children: piece.text
1351
+ }, index)) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1352
+ className: "outcome-log-empty",
1353
+ children: "Waiting for output."
1354
+ })
1355
+ }), reading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
1356
+ type: "button",
1357
+ className: "outcome-log-jump",
1358
+ onClick: toEnd,
1359
+ children: "Jump to latest"
1360
+ }) : null]
1361
+ });
1362
+ }
1363
+ /** While a person has control: the way back first, then their session on the factory's conversation. */
1364
+ function ControlSheet({ item, context }) {
1365
+ const { workset, run } = item;
1366
+ const stepped = useFactoryUi((state) => state.stepped);
1367
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1368
+ className: "factory-sheet outcome-control",
1369
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1370
+ className: "outcome-control-bar",
1371
+ children: [run?.control?.reason ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1372
+ className: "outcome-control-reason",
1373
+ children: run.control.reason
1374
+ }) : null, actionFor(item, context)("return", "Return to automation")]
1375
+ }), context.sessions && run?.control?.mode === "manual" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeTerminal, {
1376
+ outcome: workset.id,
1377
+ companion: context.companionDigest,
1378
+ focus: !stepped
1379
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1380
+ className: "note",
1381
+ children: "The terminal is not available in this Studio."
1382
+ })]
1383
+ });
1384
+ }
1385
+ /** Take control and what it does, for an Outcome whose conversation the factory still drives. */
1386
+ function TakeControl({ item, context }) {
1387
+ const { workset, run } = item;
1388
+ if (!run?.conversation || run.control || workset.stage === "done") return null;
1389
+ const form = actionFor(item, context)("take-control", "Take control");
1390
+ if (!form) return null;
1391
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1392
+ className: "outcome-control-offer",
1393
+ children: [form, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1394
+ className: "note",
1395
+ children: TAKE_CONTROL_HINT
1396
+ })]
1397
+ });
1398
+ }
1399
+ /** Between Take control and the handover: what the person waits for, above the live log. */
1400
+ function TakeoverPending({ run, now }) {
1401
+ if (run?.control?.mode !== "takeover-requested") return null;
1402
+ const stage = run.state === "running" ? run.stage : null;
1403
+ const since = run.control.updatedAt ? ageText(run.control.updatedAt, now) : "";
1404
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
1405
+ className: "outcome-dialog-attention",
1406
+ "data-kind": "control",
1407
+ "data-pending": "",
1408
+ role: "status",
1409
+ "aria-label": "Taking control",
1410
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "Taking control" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
1411
+ className: "outcome-attention-hint",
1412
+ children: [
1413
+ "Control passes to you once",
1414
+ " ",
1415
+ stage ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1416
+ "the ",
1417
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1418
+ className: "mono",
1419
+ children: stage
1420
+ }),
1421
+ " stage"
1422
+ ] }) : "the current stage",
1423
+ " ",
1424
+ "ends; the log below keeps following it. The terminal opens here then.",
1425
+ since ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1426
+ className: "factory-age mono",
1427
+ children: [
1428
+ " · asked ",
1429
+ since,
1430
+ " ago"
1431
+ ]
1432
+ }) : null
1433
+ ]
1434
+ })]
1435
+ });
1436
+ }
1437
+ /** The run in a few words: what it does at which stage, and for how long. */
1438
+ function runText(run, now) {
1439
+ if (!run || run.state === "idle") return "idle";
1440
+ const since = run.state === "running" ? run.startedAt : run.updatedAt;
1441
+ return `${run.state} ${run.stage}${since ? ` · ${ageText(since, now)}` : ""}`;
1442
+ }
1443
+ var reportsMissing = ({ workset, run }) => workset.changes.some((change) => !run?.reviewReports?.[change]);
1444
+ /** What can be done to the run itself, always in view; nothing when nothing applies. */
1445
+ function RunActions({ item, context }) {
1446
+ const { workset, run } = item;
1447
+ const form = actionFor(item, context);
1448
+ const active = runActive(run);
1449
+ const open = workset.stage !== "done";
1450
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1451
+ className: "outcome-actions",
1452
+ role: "group",
1453
+ "aria-label": "Run actions",
1454
+ children: [
1455
+ open && !workset.queuedAt ? form("start", "Start") : null,
1456
+ active ? form("cancel", "Cancel run") : null,
1457
+ workset.stage === "human-review" && !reportsMissing(item) ? form("regenerate", "Regenerate reports") : null,
1458
+ open && workset.queuedAt ? form("later", "Move to later") : null
1459
+ ]
1460
+ });
1461
+ }
1462
+ /** The execution facts beside the map: stage, changes, run and branch. */
1463
+ function Facts({ item, context }) {
1464
+ const { workset, run } = item;
1465
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dl", {
1466
+ className: "outcome-facts",
1467
+ children: [
1468
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "Stage" }),
1469
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: workset.stageLabel }),
1470
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "Run" }),
1471
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: runText(run, context.now) }),
1472
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "Changes" }),
1473
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", {
1474
+ className: "mono",
1475
+ children: workset.changes.join(", ") || "none yet"
1476
+ }),
1477
+ run?.pushedBranch ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "Branch" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", {
1478
+ className: "mono",
1479
+ children: run.pushedBranch
1480
+ })] }) : null,
1481
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "Id" }),
1482
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", {
1483
+ className: "mono",
1484
+ children: workset.id
1485
+ })
1486
+ ]
1487
+ });
1488
+ }
1489
+ /** The current node's note on the map: how the stage stands, with an age while it runs. */
1490
+ function progressNote(item, activity, now) {
1491
+ const { run } = item;
1492
+ const label = ACTIVITY_LABELS[activity].toLowerCase();
1493
+ if (run?.state === "running" && now !== void 0) return `${label} · ${ageText(run.startedAt, now)}`;
1494
+ return activity === "idle" ? "" : label;
1495
+ }
1496
+ /** The recommendation, marked in words beside the option it belongs to. */
1497
+ function RecommendedTag() {
1498
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1499
+ className: "factory-recommended",
1500
+ children: "recommended"
1501
+ });
1502
+ }
1503
+ /** A single question: one click on an option sends it; number keys pick options. */
1504
+ function SingleDecision({ item, asked, round, context }) {
1505
+ const act = context.writable && outcomeActions(item.workset, item.run, context).has("answer");
1506
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1507
+ className: "factory-sheet",
1508
+ children: [
1509
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1510
+ className: "factory-question",
1511
+ children: asked.question
1512
+ }),
1513
+ asked.options?.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1514
+ className: "factory-options",
1515
+ role: "group",
1516
+ "aria-label": "Answers",
1517
+ children: asked.options.map((option, index) => {
1518
+ const recommended = option === asked.recommended;
1519
+ const shortcut = index < 9 ? String(index + 1) : void 0;
1520
+ return act ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(FactoryForm, {
1521
+ id: item.workset.id,
1522
+ action: "answer",
1523
+ className: "factory-option",
1524
+ children: [
1525
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
1526
+ type: "hidden",
1527
+ name: "round",
1528
+ value: round
1529
+ }),
1530
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
1531
+ type: "hidden",
1532
+ name: "answer",
1533
+ value: option
1534
+ }),
1535
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
1536
+ type: "submit",
1537
+ "data-recommended": recommended ? "true" : "false",
1538
+ "data-option-key": shortcut,
1539
+ "aria-keyshortcuts": shortcut,
1540
+ children: [
1541
+ shortcut ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", {
1542
+ "aria-hidden": "true",
1543
+ children: shortcut
1544
+ }) : null,
1545
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: option }),
1546
+ recommended ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecommendedTag, {}) : null
1547
+ ]
1548
+ })
1549
+ ]
1550
+ }, option) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1551
+ className: "factory-choice",
1552
+ "data-recommended": recommended ? "true" : "false",
1553
+ children: [option, recommended ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecommendedTag, {}) : null]
1554
+ }, option);
1555
+ })
1556
+ }) : asked.recommended ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
1557
+ className: "note",
1558
+ children: ["Recommended: ", asked.recommended]
1559
+ }) : null,
1560
+ actionFor(item, context)("answer", asked.options?.length ? "Send my words" : "Answer", /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
1561
+ type: "hidden",
1562
+ name: "round",
1563
+ value: round
1564
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
1565
+ name: "answer",
1566
+ rows: 2,
1567
+ required: true,
1568
+ "aria-label": "Answer in your words",
1569
+ placeholder: asked.options?.length ? "Or answer in your words" : "Your answer"
1570
+ })] }))
1571
+ ]
1572
+ });
1573
+ }
1574
+ /** One question of a round: its options as choices, none chosen, and own words that override. */
1575
+ function QuestionBlock({ asked, index }) {
1576
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", {
1577
+ className: "factory-question-set",
1578
+ children: [
1579
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("legend", {
1580
+ className: "factory-question",
1581
+ children: [
1582
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1583
+ className: "mono",
1584
+ children: [index + 1, "."]
1585
+ }),
1586
+ " ",
1587
+ asked.question
1588
+ ]
1589
+ }),
1590
+ asked.options?.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1591
+ className: "factory-choices",
1592
+ children: asked.options.map((option) => {
1593
+ const recommended = option === asked.recommended;
1594
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
1595
+ className: "factory-choice",
1596
+ "data-recommended": recommended ? "true" : "false",
1597
+ children: [
1598
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
1599
+ type: "radio",
1600
+ name: `choice-${index}`,
1601
+ value: option
1602
+ }),
1603
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: option }),
1604
+ recommended ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecommendedTag, {}) : null
1605
+ ]
1606
+ }, option);
1607
+ })
1608
+ }) : asked.recommended ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
1609
+ className: "note",
1610
+ children: ["Recommended: ", asked.recommended]
1611
+ }) : null,
1612
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
1613
+ name: `answer-${index}`,
1614
+ rows: 1,
1615
+ "aria-label": `Answer to question ${index + 1} in your words`,
1616
+ placeholder: asked.options?.length ? "Or in your words (overrides the choice)" : "Your answer"
1617
+ })
1618
+ ]
1619
+ });
1620
+ }
1621
+ /** How many questions of a round have a choice or words, read from the form. */
1622
+ function answeredIn(form, count) {
1623
+ const data = new FormData(form);
1624
+ let answered = 0;
1625
+ for (let index = 0; index < count; index += 1) {
1626
+ const words = data.get(`answer-${index}`);
1627
+ if (data.get(`choice-${index}`) || typeof words === "string" && words.trim()) answered += 1;
1628
+ }
1629
+ return answered;
1630
+ }
1631
+ /** The questions the agent asked together: answered together, nothing chosen for the person. */
1632
+ function GroupedDecision({ item, questions, round, context }) {
1633
+ const [answered, setAnswered] = (0, import_react.useState)(0);
1634
+ if (!context.writable || !outcomeActions(item.workset, item.run, context).has("answer")) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ol", {
1635
+ className: "outcome-history",
1636
+ children: questions.map((asked) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: asked.question }, asked.question))
1637
+ });
1638
+ const count = (event) => {
1639
+ const form = event.currentTarget.closest("form");
1640
+ if (form) setAnswered(answeredIn(form, questions.length));
1641
+ };
1642
+ const recommended = questions.every((asked) => asked.recommended);
1643
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1644
+ className: "factory-sheet",
1645
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(FactoryForm, {
1646
+ id: item.workset.id,
1647
+ action: "answer",
1648
+ className: "factory-action factory-round",
1649
+ children: [
1650
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
1651
+ type: "hidden",
1652
+ name: "round",
1653
+ value: round
1654
+ }),
1655
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1656
+ className: "factory-round-questions",
1657
+ onChange: count,
1658
+ onInput: count,
1659
+ children: questions.map((asked, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QuestionBlock, {
1660
+ asked,
1661
+ index
1662
+ }, asked.question))
1663
+ }),
1664
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1665
+ className: "factory-sheet-actions",
1666
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
1667
+ type: "submit",
1668
+ className: "factory-primary",
1669
+ disabled: answered < questions.length,
1670
+ children: "Send answers"
1671
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1672
+ className: "factory-round-count mono",
1673
+ "aria-live": "polite",
1674
+ children: [
1675
+ answered,
1676
+ " of ",
1677
+ questions.length,
1678
+ " answered"
1679
+ ]
1680
+ })]
1681
+ })
1682
+ ]
1683
+ }), recommended ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(FactoryForm, {
1684
+ id: item.workset.id,
1685
+ action: "answer",
1686
+ className: "factory-action",
1687
+ children: [
1688
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
1689
+ type: "hidden",
1690
+ name: "round",
1691
+ value: round
1692
+ }),
1693
+ questions.map((asked, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
1694
+ type: "hidden",
1695
+ name: `choice-${index}`,
1696
+ value: asked.recommended
1697
+ }, asked.question)),
1698
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
1699
+ type: "submit",
1700
+ children: "Accept all recommendations"
1701
+ })
1702
+ ]
1703
+ }) : null]
1704
+ });
1705
+ }
1706
+ /** The questions the agent asked: one alone is answered in a click, several together. */
1707
+ function DecisionSheet({ item, run, context }) {
1708
+ const questions = questionsOf(run);
1709
+ if (questions.length === 1) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SingleDecision, {
1710
+ item,
1711
+ asked: questions[0],
1712
+ round: run.round ?? "",
1713
+ context
1714
+ });
1715
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GroupedDecision, {
1716
+ item,
1717
+ questions,
1718
+ round: run.round ?? "",
1719
+ context
1720
+ });
1721
+ }
1722
+ /** What a person does for one attention item, opened in place. */
1723
+ function AttentionBody({ item, kind, context }) {
1724
+ const { run } = item;
1725
+ const form = actionFor(item, context);
1726
+ if (kind === "control") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlSheet, {
1727
+ item,
1728
+ context
1729
+ });
1730
+ if (kind === "decision" && run?.state === "waiting") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DecisionSheet, {
1731
+ item,
1732
+ run,
1733
+ context
1734
+ });
1735
+ if (kind === "problem") return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1736
+ className: "factory-sheet",
1737
+ children: [
1738
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1739
+ className: "factory-problems",
1740
+ children: run?.state === "failed" ? run.reason : "Stopped when Studio restarted."
1741
+ }),
1742
+ run?.needsCredential ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OpenAgents, { label: "Set the agent credential" }) : null,
1743
+ form("retry", "Retry")
1744
+ ]
1745
+ });
1746
+ if (kind === "review") {
1747
+ const missing = reportsMissing(item);
1748
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1749
+ className: "factory-sheet",
1750
+ children: [
1751
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReviewReports, { item }),
1752
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1753
+ className: "factory-sheet-actions",
1754
+ children: [form("start-apply", "Approve"), missing ? form("regenerate", "Regenerate") : null]
1755
+ }),
1756
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FeedbackField, {
1757
+ item,
1758
+ context
1759
+ })
1760
+ ]
1761
+ });
1762
+ }
1763
+ if (kind === "merge") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1764
+ className: "factory-sheet",
1765
+ children: run?.compareUrl ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("a", {
1766
+ href: run.compareUrl,
1767
+ target: "_blank",
1768
+ rel: "noreferrer",
1769
+ children: [
1770
+ "Open ",
1771
+ run.pushedBranch ?? "the branch",
1772
+ " to merge"
1773
+ ]
1774
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
1775
+ className: "note",
1776
+ children: [
1777
+ "Merge ",
1778
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1779
+ className: "mono",
1780
+ children: run?.pushedBranch ?? "the delivery branch"
1781
+ }),
1782
+ ", then refresh."
1783
+ ]
1784
+ })
1785
+ });
1786
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1787
+ className: "factory-sheet",
1788
+ children: form("publish", "Publish")
1789
+ });
1790
+ }
1791
+ var dialogId = (id) => `outcome-${id}`;
1792
+ /**
1793
+ * Opens, steps to or closes an Outcome's dialog through the address, so it can be linked,
1794
+ * a reload reopens it and Back closes it. Stepping replaces the entry; opening adds one.
1795
+ */
1796
+ function useOutcomeAddress() {
1797
+ const navigate = useNavigate();
1798
+ const go = (outcome, replace = false) => void navigate({
1799
+ to: "/factory",
1800
+ search: (previous) => ({
1801
+ ...previous,
1802
+ outcome
1803
+ }),
1804
+ replace,
1805
+ resetScroll: false
1806
+ });
1807
+ return {
1808
+ open: (id) => go(id),
1809
+ step: (id) => go(id, true),
1810
+ close: () => go(void 0)
1811
+ };
1812
+ }
1813
+ /** One line per Outcome: what it is and where it is; the row opens the dialog. */
1814
+ function OutcomeRow({ item, context, lead, progress = true, trailing }) {
1815
+ const { workset, run } = item;
1816
+ const situation = situationOf(workset, run);
1817
+ const since = situation.at ?? (run?.updatedAt || workset.queuedAt);
1818
+ const address = useOutcomeAddress();
1819
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
1820
+ className: "outcome-row-item",
1821
+ "data-workset": workset.id,
1822
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
1823
+ type: "button",
1824
+ className: "outcome-row",
1825
+ "data-outcome-row": "",
1826
+ onClick: () => {
1827
+ useFactoryUi.getState().setStepped(false);
1828
+ address.open(workset.id);
1829
+ },
1830
+ children: [
1831
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityDot, { activity: activityOf(workset, run) }),
1832
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1833
+ className: "outcome-row-title",
1834
+ children: workset.title
1835
+ }),
1836
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1837
+ className: "outcome-row-where",
1838
+ children: lead ?? situation.text
1839
+ }),
1840
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1841
+ className: "outcome-row-progress",
1842
+ children: progress ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MilestoneTrack, { workset }) : null
1843
+ }),
1844
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1845
+ className: "outcome-row-age mono",
1846
+ children: since ? ageText(since, context.now) : ""
1847
+ })
1848
+ ]
1849
+ }), trailing]
1850
+ });
1851
+ }
1852
+ function OutcomeList({ label, section, count, children }) {
1853
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
1854
+ className: "outcome-list-section",
1855
+ "data-section": section,
1856
+ "aria-label": label,
1857
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h3", { children: [
1858
+ label,
1859
+ " ",
1860
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1861
+ className: "outcome-list-count mono",
1862
+ children: count
1863
+ })
1864
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
1865
+ className: "outcome-list",
1866
+ children
1867
+ })]
1868
+ });
1869
+ }
1870
+ var sameText = (a, b) => a.replace(/\.$/, "").toLowerCase() === b.replace(/\.$/, "").toLowerCase();
1871
+ function StepButton({ to, label, keyName }) {
1872
+ const address = useOutcomeAddress();
1873
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
1874
+ type: "button",
1875
+ className: "outcome-step",
1876
+ "data-outcome-goto": to ? dialogId(to) : void 0,
1877
+ disabled: !to,
1878
+ "aria-keyshortcuts": keyName,
1879
+ onClick: () => {
1880
+ if (!to) return;
1881
+ useFactoryUi.getState().setStepped(true);
1882
+ address.step(to);
1883
+ },
1884
+ children: [
1885
+ label,
1886
+ " ",
1887
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: keyName })
1888
+ ]
1889
+ });
1890
+ }
1891
+ /** What the person is asked to do, with what it expects of them. */
1892
+ function AttentionSection({ item, kind, context }) {
1893
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
1894
+ className: "outcome-dialog-attention",
1895
+ "data-kind": kind,
1896
+ "aria-label": "Needs you",
1897
+ children: [
1898
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: attentionLabel(kind, item.run) }),
1899
+ ATTENTION_HINTS[kind] ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1900
+ className: "outcome-attention-hint",
1901
+ children: ATTENTION_HINTS[kind]
1902
+ }) : null,
1903
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AttentionBody, {
1904
+ item,
1905
+ kind,
1906
+ context
1907
+ })
1908
+ ]
1909
+ });
1910
+ }
1911
+ /** Where the Outcome is: its situation, the next step, checks, results and problems. */
1912
+ function OutcomeStatus({ item, situation }) {
1913
+ const { workset, run } = item;
1914
+ const next = nextStepOf(workset, run);
1915
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
1916
+ className: "outcome-dialog-status",
1917
+ "aria-label": "Where it is",
1918
+ children: [
1919
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1920
+ className: "outcome-situation",
1921
+ children: situation.text
1922
+ }),
1923
+ sameText(next, situation.text) ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
1924
+ className: "outcome-next",
1925
+ children: [
1926
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1927
+ className: "muted",
1928
+ children: "Next"
1929
+ }),
1930
+ " ",
1931
+ next
1932
+ ]
1933
+ }),
1934
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checks, { checks: situation.checks }),
1935
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ResultLinks, { item }),
1936
+ workset.problems.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
1937
+ className: "factory-problems",
1938
+ children: workset.problems.map((problem) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: problem }, problem))
1939
+ }) : null
1940
+ ]
1941
+ });
1942
+ }
1943
+ /** The run's reported situations, newest first; nothing before the first report. */
1944
+ function History({ run, now }) {
1945
+ if (!run?.situations?.length) return null;
1946
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
1947
+ className: "outcome-history-section",
1948
+ "aria-label": "What happened",
1949
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "What happened" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ol", {
1950
+ className: "outcome-history",
1951
+ children: run.situations.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1952
+ className: "factory-age mono",
1953
+ children: ageText(entry.at, now)
1954
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: entry.text })] }, entry.at))
1955
+ })]
1956
+ });
1957
+ }
1958
+ /**
1959
+ * Everything about one Outcome. The main column leads with what needs the person, then the
1960
+ * log, status and the run's actions, and history; the rail shows where the Outcome is on the
1961
+ * Delivery Path, with the execution facts under it. In control the terminal takes the width.
1962
+ */
1963
+ function OutcomeDialog({ item, kind, context, place }) {
1964
+ const { workset, run } = item;
1965
+ const situation = situationOf(workset, run);
1966
+ const activity = activityOf(workset, run);
1967
+ const since = run?.state === "running" ? run.startedAt : run?.updatedAt || situation.at;
1968
+ const id = dialogId(workset.id);
1969
+ const progress = {
1970
+ current: pathNodeOf(workset),
1971
+ activity,
1972
+ note: progressNote(item, activity, context.now)
1973
+ };
1974
+ const ref = useModalDialog(useOutcomeAddress().close, (dialog) => {
1975
+ dialog.showModal();
1976
+ dialog.querySelector(".outcome-dialog-close")?.focus();
1977
+ });
1978
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dialog", {
1979
+ ref,
1980
+ id,
1981
+ className: "outcome-dialog",
1982
+ "data-workset": workset.id,
1983
+ "data-layout": kind === "control" ? "control" : void 0,
1984
+ "aria-labelledby": `${id}-title`,
1985
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", {
1986
+ className: "outcome-dialog-head",
1987
+ children: [
1988
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1989
+ className: "outcome-dialog-heading",
1990
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
1991
+ id: `${id}-title`,
1992
+ children: workset.title
1993
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
1994
+ className: "outcome-dialog-state",
1995
+ children: [
1996
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityDot, { activity }),
1997
+ ACTIVITY_LABELS[activity],
1998
+ since ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1999
+ className: "factory-age mono",
2000
+ children: ["· ", ageText(since, context.now)]
2001
+ }) : null
2002
+ ]
2003
+ })]
2004
+ }),
2005
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("nav", {
2006
+ className: "outcome-dialog-steps",
2007
+ "aria-label": "Other outcomes",
2008
+ children: [
2009
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
2010
+ className: "outcome-dialog-place mono",
2011
+ children: [
2012
+ place.index + 1,
2013
+ " of ",
2014
+ place.total
2015
+ ]
2016
+ }),
2017
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StepButton, {
2018
+ to: place.prev,
2019
+ label: "Previous",
2020
+ keyName: "K"
2021
+ }),
2022
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StepButton, {
2023
+ to: place.next,
2024
+ label: "Next",
2025
+ keyName: "J"
2026
+ })
2027
+ ]
2028
+ }),
2029
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", {
2030
+ method: "dialog",
2031
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
2032
+ type: "submit",
2033
+ className: "outcome-dialog-close",
2034
+ "aria-keyshortcuts": "Escape",
2035
+ children: ["Close ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "Esc" })]
2036
+ })
2037
+ })
2038
+ ]
2039
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
2040
+ className: "outcome-dialog-body",
2041
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
2042
+ className: "outcome-dialog-main",
2043
+ children: [
2044
+ kind ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AttentionSection, {
2045
+ item,
2046
+ kind,
2047
+ context
2048
+ }) : null,
2049
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TakeoverPending, {
2050
+ run,
2051
+ now: context.now
2052
+ }),
2053
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeLog, { item }),
2054
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeStatus, {
2055
+ item,
2056
+ situation
2057
+ }),
2058
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RunActions, {
2059
+ item,
2060
+ context
2061
+ }),
2062
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TakeControl, {
2063
+ item,
2064
+ context
2065
+ }),
2066
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(History, {
2067
+ run,
2068
+ now: context.now
2069
+ }),
2070
+ workset.intent ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
2071
+ className: "outcome-intent-section",
2072
+ "aria-label": "Request",
2073
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "Request" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
2074
+ className: "outcome-intent",
2075
+ children: workset.intent
2076
+ })]
2077
+ }) : null,
2078
+ kind !== "review" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FeedbackField, {
2079
+ item,
2080
+ context
2081
+ }) : null
2082
+ ]
2083
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("aside", {
2084
+ className: "outcome-dialog-rail",
2085
+ "aria-label": "Delivery Path",
2086
+ children: [kind === "control" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WorkflowGraphView, {
2087
+ path: context.path,
2088
+ progress,
2089
+ label: "Where it is on the Delivery Path"
2090
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Facts, {
2091
+ item,
2092
+ context
2093
+ })]
2094
+ })]
2095
+ })]
2096
+ });
2097
+ }
2098
+ function Completed({ items, context, expanded }) {
2099
+ if (items.length === 0) return null;
2100
+ const rest = expanded ? [] : items.slice(RECENT_COMPLETED);
2101
+ const row = (item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeRow, {
2102
+ item,
2103
+ context,
2104
+ progress: false
2105
+ }, item.workset.id);
2106
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(OutcomeList, {
2107
+ label: "Done",
2108
+ section: "completed",
2109
+ count: items.length,
2110
+ children: [(expanded ? items : items.slice(0, RECENT_COMPLETED)).map(row), rest.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("details", {
2111
+ className: "outcome-list-more",
2112
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("summary", { children: ["Show all ", items.length] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
2113
+ className: "outcome-list",
2114
+ children: rest.map(row)
2115
+ })]
2116
+ }) }) : null]
2117
+ });
2118
+ }
2119
+ /** The journey an Outcome takes, shown before the first one exists. */
2120
+ function FirstRun() {
2121
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
2122
+ className: "factory-first-run",
2123
+ "aria-label": "How the factory works",
2124
+ children: [
2125
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "How an outcome gets delivered" }),
2126
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ol", { children: [
2127
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "Describe what you want built or improved, and start it." }),
2128
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "The factory clarifies and explores; answer its questions as they come up." }),
2129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "It writes a plan. Review it, then approve or request a change." }),
2130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "It builds the plan on a delivery branch. Merge the branch, then publish." })
2131
+ ] }),
2132
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
2133
+ className: "note",
2134
+ children: "Everything that needs you shows under Needs you. Open an outcome to follow its log or take control of its conversation."
2135
+ })
2136
+ ]
2137
+ });
2138
+ }
2139
+ /**
2140
+ * The board's lists in board order and as the filter leaves them. Each Outcome is listed once:
2141
+ * what needs the person is not repeated under Running.
2142
+ */
2143
+ function useBoard(home) {
2144
+ const query = useFactoryUi((state) => state.filter).trim();
2145
+ const kinds = new Map(home.attention.map((item) => [item.workset.id, item.kind]));
2146
+ const running = home.active.filter((item) => !kinds.has(item.workset.id));
2147
+ const shows = (item) => {
2148
+ if (!query) return true;
2149
+ const kind = kinds.get(item.workset.id);
2150
+ const label = kind ? attentionLabel(kind, item.run) : "";
2151
+ return matchesFilter(`${item.workset.title} ${situationOf(item.workset, item.run).text} ${label}`, query);
2152
+ };
2153
+ const attention = home.attention.filter(shows);
2154
+ const runningShown = running.filter(shows);
2155
+ const later = home.later.filter(shows);
2156
+ const completed = home.completed.filter(shows);
2157
+ return {
2158
+ kinds,
2159
+ query,
2160
+ ordered: [
2161
+ ...home.attention,
2162
+ ...running,
2163
+ ...home.later,
2164
+ ...home.completed
2165
+ ],
2166
+ attention,
2167
+ running: {
2168
+ all: running,
2169
+ shown: runningShown
2170
+ },
2171
+ later,
2172
+ completed,
2173
+ shownCount: attention.length + runningShown.length + later.length + completed.length
2174
+ };
2175
+ }
2176
+ /** Opens the Agents panel. */
2177
+ function OpenAgents({ label }) {
2178
+ const setAgentsOpen = useFactoryUi((state) => state.setAgentsOpen);
2179
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
2180
+ type: "button",
2181
+ "data-open-agents": "",
2182
+ onClick: () => setAgentsOpen(true),
2183
+ children: label
2184
+ });
2185
+ }
2186
+ /** The filter, the keys and the offer to notify, above the board. */
2187
+ function BoardToolbar({ count, worksets, writable, factoryMode }) {
2188
+ const filter = useFactoryUi((state) => state.filter);
2189
+ const setFilter = useFactoryUi((state) => state.setFilter);
2190
+ const notifications = useNotificationOffer();
2191
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
2192
+ className: "view-intro",
2193
+ "data-factory-live": "",
2194
+ "data-needs-you": count,
2195
+ children: [
2196
+ worksets > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
2197
+ type: "search",
2198
+ className: "outcome-filter",
2199
+ "data-outcome-filter": "",
2200
+ placeholder: "Filter outcomes",
2201
+ "aria-label": "Filter outcomes",
2202
+ "aria-keyshortcuts": "/",
2203
+ value: filter,
2204
+ onChange: (event) => setFilter(event.target.value),
2205
+ onKeyDown: (event) => {
2206
+ if (event.key !== "Escape") return;
2207
+ setFilter("");
2208
+ event.currentTarget.blur();
2209
+ }
2210
+ }) : null,
2211
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
2212
+ className: "factory-keys",
2213
+ children: [
2214
+ writable ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "N" }), " new"] }) : null,
2215
+ worksets > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "/" }), " filter"] }) : null,
2216
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "J" }),
2217
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "K" }),
2218
+ " move ",
2219
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "↵" }),
2220
+ " open ",
2221
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "1" }),
2222
+ "–",
2223
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { children: "9" }),
2224
+ " answer"
2225
+ ]
2226
+ }),
2227
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
2228
+ type: "button",
2229
+ "data-factory-notify": "",
2230
+ hidden: !notifications.offered,
2231
+ onClick: notifications.ask,
2232
+ children: "Notify me about decisions"
2233
+ }),
2234
+ factoryMode && writable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OpenAgents, { label: "Agents" }) : null
2235
+ ]
2236
+ });
2237
+ }
2238
+ /** Outcomes as lists of one line each; everything else opens in the Outcome's dialog. */
2239
+ function Factory({ payload, companionDigest, writable, sessions = null, runs = null, now, openId, factoryMode = false }) {
2240
+ const home = factoryHome(payload.worksets, runs);
2241
+ const context = {
2242
+ companionDigest,
2243
+ writable,
2244
+ sessions,
2245
+ runner: runs !== null,
2246
+ now,
2247
+ path: workflowPlan({ topology: payload.topology }).paths[0]
2248
+ };
2249
+ const { kinds, ordered, attention, running, later, completed, shownCount, query } = useBoard(home);
2250
+ const openIndex = openId ? ordered.findIndex((item) => item.workset.id === openId) : -1;
2251
+ const idle = running.all.length === 0 && home.attention.length === 0;
2252
+ useFactoryKeys();
2253
+ useNeedsYou(home.attention.length);
2254
+ const open = openIndex >= 0 ? {
2255
+ item: ordered[openIndex],
2256
+ index: openIndex
2257
+ } : null;
2258
+ const agentsOpen = useFactoryUi((state) => state.agentsOpen);
2259
+ const setAgentsOpen = useFactoryUi((state) => state.setAgentsOpen);
2260
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FactoryCompanion.Provider, {
2261
+ value: companionDigest,
2262
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
2263
+ className: "view-section factory-home",
2264
+ "aria-label": "Factory",
2265
+ children: [
2266
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BoardToolbar, {
2267
+ count: home.attention.length,
2268
+ worksets: payload.worksets.length,
2269
+ writable,
2270
+ factoryMode
2271
+ }),
2272
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeInput, {
2273
+ repositories: payload.linkedRepositories,
2274
+ context
2275
+ }),
2276
+ attention.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeList, {
2277
+ label: "Needs you",
2278
+ section: "attention",
2279
+ count: attention.length,
2280
+ children: attention.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeRow, {
2281
+ item,
2282
+ context,
2283
+ lead: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
2284
+ className: "attention-kind",
2285
+ "data-kind": item.kind,
2286
+ children: attentionLabel(item.kind, item.run)
2287
+ })
2288
+ }, item.workset.id))
2289
+ }) : null,
2290
+ running.shown.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeList, {
2291
+ label: "Running",
2292
+ section: "active",
2293
+ count: running.shown.length,
2294
+ children: running.shown.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeRow, {
2295
+ item,
2296
+ context
2297
+ }, item.workset.id))
2298
+ }) : null,
2299
+ payload.worksets.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FirstRun, {}) : idle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
2300
+ className: "note",
2301
+ children: "The factory is idle. Describe an outcome to get it started."
2302
+ }) : null,
2303
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
2304
+ className: "note outcome-filter-empty",
2305
+ "data-outcome-filter-empty": "",
2306
+ hidden: !query || shownCount > 0,
2307
+ children: "No outcomes match the filter."
2308
+ }),
2309
+ later.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeList, {
2310
+ label: "Later",
2311
+ section: "later",
2312
+ count: later.length,
2313
+ children: later.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeRow, {
2314
+ item,
2315
+ context,
2316
+ progress: false,
2317
+ trailing: actionFor(item, context)("start", "Start")
2318
+ }, item.workset.id))
2319
+ }) : null,
2320
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Completed, {
2321
+ items: completed,
2322
+ context,
2323
+ expanded: Boolean(query)
2324
+ }),
2325
+ open ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OutcomeDialog, {
2326
+ item: open.item,
2327
+ kind: kinds.get(open.item.workset.id) ?? null,
2328
+ context,
2329
+ place: {
2330
+ index: open.index,
2331
+ total: ordered.length,
2332
+ prev: ordered[open.index - 1]?.workset.id,
2333
+ next: ordered[open.index + 1]?.workset.id
2334
+ }
2335
+ }, open.item.workset.id) : null,
2336
+ payload.worksetProblems.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Warnings, { warnings: payload.worksetProblems.map((problem) => `${problem.path} ${problem.reason}`) }) : null,
2337
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Warnings, { warnings: payload.warnings }),
2338
+ factoryMode && writable && agentsOpen ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgentsDialog, { onClose: () => setAgentsOpen(false) }) : null
2339
+ ]
2340
+ })
2341
+ });
2342
+ }
2343
+ // src/routes/factory.tsx?tsr-split=component
2344
+ function FactoryRoute() {
2345
+ const { companion, outcome } = Route.useSearch();
2346
+ const navigate = useNavigate();
2347
+ (0, import_react.useEffect)(() => {
2348
+ const legacy = /^#outcome-([a-z0-9][a-z0-9-]*)$/.exec(window.location.hash)?.[1];
2349
+ if (legacy && !outcome) navigate({
2350
+ to: "/factory",
2351
+ search: (previous) => ({
2352
+ ...previous,
2353
+ outcome: legacy
2354
+ }),
2355
+ hash: "",
2356
+ replace: true
2357
+ });
2358
+ }, [navigate, outcome]);
2359
+ if (!companion) return null;
2360
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FactoryBoard, {
2361
+ companion,
2362
+ outcome
2363
+ });
2364
+ }
2365
+ function FactoryBoard({ companion, outcome }) {
2366
+ const { data } = useSuspenseQuery(factoryQuery(companion));
2367
+ if (!data.payload) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", {
2368
+ className: "panel",
2369
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
2370
+ className: "empty",
2371
+ children: data.error ?? "No state collected for this companion."
2372
+ })
2373
+ });
2374
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Factory, {
2375
+ payload: data.payload,
2376
+ companionDigest: companion,
2377
+ writable: data.writable,
2378
+ factoryMode: data.factoryMode,
2379
+ sessions: data.sessions,
2380
+ runs: data.runs,
2381
+ now: data.renderedAt,
2382
+ openId: outcome
2383
+ });
2384
+ }
2385
+ export { FactoryRoute as component };