@uniqbit/mate-core 0.18.5 → 0.20.0

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