@uniqbit/mate-core 1.0.0-canary.3 → 1.0.0-canary.6

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 (483) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
  3. package/claude-plugin/hooks/hooks.json +61 -1
  4. package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
  5. package/claude-plugin/hooks/session-attention.mjs +10 -0
  6. package/claude-plugin/hooks/session-end.mjs +9 -0
  7. package/claude-plugin/hooks/session-guidance.mjs +1 -1
  8. package/claude-plugin/hooks/workflow-turn.mjs +68 -0
  9. package/opencode-plugin/src/companion.ts +6 -0
  10. package/opencode-plugin/src/server.ts +46 -4
  11. package/package.json +5 -2
  12. package/src/cli/commands/artifact/apply-context.ts +1 -0
  13. package/src/cli/commands/artifact/artifact.ts +16 -0
  14. package/src/cli/commands/artifact/delivery/archive.ts +37 -112
  15. package/src/cli/commands/artifact/delivery/branch-flags.ts +19 -1
  16. package/src/cli/commands/artifact/delivery/environment.ts +32 -72
  17. package/src/cli/commands/artifact/delivery/link.ts +69 -33
  18. package/src/cli/commands/artifact/delivery/output.ts +34 -5
  19. package/src/cli/commands/artifact/delivery/resolve.ts +101 -0
  20. package/src/cli/commands/artifact/delivery/submit.ts +164 -0
  21. package/src/cli/commands/artifact/delivery/take.ts +45 -0
  22. package/src/cli/commands/artifact/extract-repo-name.ts +1 -1
  23. package/src/cli/commands/artifact/finish/command.ts +455 -43
  24. package/src/cli/commands/artifact/finish/engine.ts +79 -61
  25. package/src/cli/commands/artifact/finish/finisher.ts +5 -12
  26. package/src/cli/commands/artifact/finish/git.ts +9 -10
  27. package/src/cli/commands/artifact/finish/openspec.ts +22 -177
  28. package/src/cli/commands/artifact/finish/secret-scan.ts +5 -43
  29. package/src/cli/commands/artifact/finish/worktree-cleanup.ts +57 -7
  30. package/src/cli/commands/artifact/pending/command.ts +119 -6
  31. package/src/cli/commands/artifact/pending/discovery.ts +7 -11
  32. package/src/cli/commands/artifact/project/command.ts +60 -0
  33. package/src/cli/commands/companion/companion.ts +1 -1
  34. package/src/cli/commands/companion/link.ts +36 -4
  35. package/src/cli/commands/companion/list.ts +70 -14
  36. package/src/cli/commands/companion/open.ts +40 -12
  37. package/src/cli/commands/companion/sync.ts +18 -0
  38. package/src/cli/commands/companion/update.ts +4 -19
  39. package/src/cli/commands/doctor.ts +122 -0
  40. package/src/cli/commands/install.ts +48 -36
  41. package/src/cli/commands/launch/claude.ts +2 -0
  42. package/src/cli/commands/launch/shared.ts +33 -6
  43. package/src/cli/commands/plugin/install.ts +27 -11
  44. package/src/cli/commands/report/index.ts +180 -184
  45. package/src/cli/commands/report/markdown.ts +67 -72
  46. package/src/cli/commands/session/prepare.ts +32 -4
  47. package/src/cli/commands/session/registry.ts +90 -0
  48. package/src/cli/commands/shared/companion-selection.ts +3 -1
  49. package/src/cli/commands/studio/access.ts +6 -14
  50. package/src/cli/commands/studio/areas.ts +112 -33
  51. package/src/cli/commands/studio/companion-add.ts +72 -0
  52. package/src/cli/commands/studio/companion-removal.ts +86 -0
  53. package/src/cli/commands/studio/graph-model.ts +61 -0
  54. package/src/cli/commands/studio/graph.ts +336 -0
  55. package/src/cli/commands/studio/index.ts +4 -4
  56. package/src/{lib/factory/outcomes/sessions.ts → cli/commands/studio/live-sessions.ts} +26 -2
  57. package/src/cli/commands/studio/mate-inventory.ts +1 -1
  58. package/src/cli/commands/studio/payload.ts +223 -30
  59. package/src/cli/commands/studio/reports.ts +19 -18
  60. package/src/cli/commands/studio/routes.ts +5 -18
  61. package/src/cli/commands/studio/selection.ts +12 -5
  62. package/src/cli/commands/studio/server.ts +321 -198
  63. package/src/cli/commands/studio/service-host.ts +266 -0
  64. package/src/cli/commands/studio/services.ts +54 -16
  65. package/src/cli/commands/studio/skill-files.ts +133 -0
  66. package/src/cli/commands/studio/studio-app.ts +1 -0
  67. package/src/cli/commands/studio/terminal.ts +45 -3
  68. package/src/cli/commands/studio/vault.ts +259 -84
  69. package/src/cli/commands/studio/views/model.ts +1 -14
  70. package/src/cli/commands/studio/views/vault/markdown-tree.ts +343 -10
  71. package/src/cli/commands/unwrap.ts +11 -0
  72. package/src/cli/commands/update.ts +28 -8
  73. package/src/cli/commands/vscode/release-vsix.json +4 -0
  74. package/src/cli/commands/vscode/setup.ts +213 -0
  75. package/src/cli/commands/vscode/vsix.ts +114 -0
  76. package/src/cli/commands/workflow/workflow.ts +516 -0
  77. package/src/cli/commands/working/cleanup.ts +73 -17
  78. package/src/cli/commands/working/worktree.ts +227 -36
  79. package/src/cli/commands/wrap.ts +33 -7
  80. package/src/cli/main.ts +48 -12
  81. package/src/cli/repo-list-table.tsx +73 -37
  82. package/src/cli/usage.ts +25 -9
  83. package/src/factory-host.ts +69 -0
  84. package/src/hooks/companion-instructions.ts +35 -16
  85. package/src/hooks/hook-io.ts +18 -1
  86. package/src/hooks/rtk-worktree-git.ts +48 -0
  87. package/src/hooks/session-banner.ts +30 -3
  88. package/src/hooks/session-end.ts +10 -0
  89. package/src/hooks/session-guidance.ts +10 -6
  90. package/src/hooks/session-prepare.ts +47 -31
  91. package/src/hooks/session-register.ts +199 -0
  92. package/src/hooks/tokensave-route.ts +7 -3
  93. package/src/hooks/validate-artifact-path.ts +53 -14
  94. package/src/hooks/workflow-turn.ts +219 -0
  95. package/src/lib/apply-context/fingerprint.ts +2 -1
  96. package/src/lib/apply-context/protocol.ts +2 -2
  97. package/src/lib/artifact-trailer.ts +27 -0
  98. package/src/lib/change-layout.ts +83 -38
  99. package/src/lib/delivery/branch-template.ts +114 -0
  100. package/src/lib/delivery/branches.ts +34 -14
  101. package/src/lib/delivery/checkout.ts +103 -0
  102. package/src/lib/delivery/environment.ts +131 -7
  103. package/src/lib/delivery/merge-git.ts +282 -26
  104. package/src/lib/delivery/overlap.ts +68 -16
  105. package/src/lib/delivery/record-delivery.ts +253 -57
  106. package/src/lib/delivery/record.ts +229 -53
  107. package/src/lib/delivery/refresh.ts +222 -141
  108. package/src/lib/delivery/remote.ts +66 -0
  109. package/src/lib/delivery/repository-access.ts +19 -60
  110. package/src/lib/delivery/resolve-branch.ts +318 -50
  111. package/src/lib/delivery/stages.ts +83 -50
  112. package/src/lib/delivery/staging/apply-chain.ts +164 -0
  113. package/src/lib/delivery/staging/artifact-type.ts +101 -0
  114. package/src/lib/delivery/staging/declared-type.ts +277 -0
  115. package/src/lib/delivery/staging/naming.ts +64 -0
  116. package/src/lib/delivery/staging/openspec-type.ts +135 -0
  117. package/src/lib/delivery/staging/pending-edit.ts +291 -0
  118. package/src/lib/delivery/staging/pending.ts +780 -0
  119. package/src/lib/delivery/staging/project.ts +373 -0
  120. package/src/lib/delivery/staging/publish.ts +1024 -0
  121. package/src/lib/delivery/staging/refs.ts +258 -0
  122. package/src/lib/delivery/staging/registry.ts +73 -0
  123. package/src/lib/delivery/staging/replay.ts +308 -0
  124. package/src/lib/delivery/staging/requirement-blocks.ts +10 -0
  125. package/src/lib/delivery/staging/resolve.ts +264 -0
  126. package/src/lib/delivery/staging/settle-linked.ts +290 -0
  127. package/src/lib/delivery/staging/submit.ts +929 -0
  128. package/src/lib/delivery/staging/worktree.ts +130 -0
  129. package/src/lib/delivery/submit-change.ts +443 -0
  130. package/src/lib/git-key.ts +15 -0
  131. package/src/lib/install.ts +2 -0
  132. package/src/lib/opencode-server.ts +238 -0
  133. package/src/lib/openspec-canonical-frontmatter.ts +159 -0
  134. package/src/lib/orchestrator/adapters/base.ts +31 -20
  135. package/src/lib/orchestrator/adapters/claude.ts +162 -4
  136. package/src/lib/orchestrator/adapters/opencode.ts +55 -2
  137. package/src/lib/orchestrator/checkout-adoption.ts +125 -0
  138. package/src/lib/orchestrator/companion-git-sync.ts +152 -16
  139. package/src/lib/orchestrator/companion-hub.ts +6 -1
  140. package/src/lib/orchestrator/companion-registry-store.ts +6 -2
  141. package/src/lib/orchestrator/editor.ts +2 -2
  142. package/src/lib/orchestrator/engine-floor.ts +48 -0
  143. package/src/lib/orchestrator/framework-context.ts +41 -15
  144. package/src/lib/orchestrator/global-config-store.ts +11 -0
  145. package/src/lib/orchestrator/launcher.ts +49 -3
  146. package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
  147. package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
  148. package/src/lib/orchestrator/projection-claude-links.ts +83 -11
  149. package/src/lib/orchestrator/projection-claude-skills.ts +30 -4
  150. package/src/lib/orchestrator/projection-companion-link.ts +12 -1
  151. package/src/lib/orchestrator/projection-entries.ts +22 -18
  152. package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
  153. package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
  154. package/src/lib/orchestrator/projection-types.ts +28 -1
  155. package/src/lib/orchestrator/refresh-working-claude-links.ts +4 -1
  156. package/src/lib/orchestrator/registry-checkouts.ts +177 -0
  157. package/src/lib/orchestrator/repository-link.ts +216 -57
  158. package/src/lib/orchestrator/serving-claude-wrap.ts +43 -0
  159. package/src/lib/orchestrator/session-context-link.ts +11 -5
  160. package/src/lib/orchestrator/session-prepare.ts +53 -8
  161. package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
  162. package/src/lib/orchestrator/types.ts +9 -0
  163. package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
  164. package/src/lib/orchestrator/working-repo-projection.ts +24 -4
  165. package/src/lib/orchestrator/workspace-inventory.ts +5 -1
  166. package/src/lib/orchestrator/wrap-pass.ts +1 -0
  167. package/src/lib/prebuilt-workspace-prepare.ts +2 -1
  168. package/src/lib/prebuilt-workspace.ts +1 -0
  169. package/src/lib/public-npm.ts +105 -43
  170. package/src/lib/session-attribution.ts +52 -0
  171. package/src/lib/session-state.ts +356 -0
  172. package/src/lib/session-stop.ts +64 -0
  173. package/src/lib/update-checker.ts +7 -1
  174. package/src/lib/usage/aggregate.ts +202 -0
  175. package/src/lib/usage/cache.ts +87 -0
  176. package/src/lib/usage/claude-pricing.ts +71 -0
  177. package/src/lib/usage/claude.ts +189 -0
  178. package/src/lib/usage/collect.ts +56 -0
  179. package/src/lib/usage/opencode.ts +188 -0
  180. package/src/lib/usage/records.ts +80 -0
  181. package/src/lib/usage/rtk-database.ts +72 -0
  182. package/src/lib/usage/savings.ts +209 -0
  183. package/src/lib/usage/scope.ts +182 -0
  184. package/src/lib/usage/source.ts +102 -0
  185. package/src/lib/usage/types.ts +143 -0
  186. package/src/lib/usage/window.ts +37 -0
  187. package/src/lib/workflow/declaration.ts +6 -0
  188. package/src/lib/workflow/handoff.ts +90 -0
  189. package/src/lib/workflow/hook-trust.ts +108 -0
  190. package/src/lib/workflow/position.ts +524 -0
  191. package/src/lib/workflow/report.ts +79 -0
  192. package/src/lib/workflow/work.ts +106 -0
  193. package/src/lib/workset/factory-local.ts +157 -0
  194. package/src/lib/workset/record.ts +45 -11
  195. package/src/lib/workset/repositories.ts +118 -25
  196. package/src/lib/workset/stage.ts +4 -2
  197. package/src/lib/workset/stages.ts +64 -4
  198. package/src/lib/workset/worktree-include.ts +161 -0
  199. package/src/lib/workset/worktree-index.ts +6 -2
  200. package/src/lib/workset/worktree.ts +665 -89
  201. package/src/opencode/background-server.ts +145 -0
  202. package/src/opencode/companion-hooks.ts +55 -14
  203. package/src/opencode/companion-policy.ts +20 -7
  204. package/src/opencode/enter-worktree.ts +254 -6
  205. package/src/opencode/projected-guidance.ts +7 -3
  206. package/src/opencode/session-register.ts +176 -0
  207. package/src/opencode/turn-hook.ts +241 -0
  208. package/src/playbooks/companion-guidance.ts +6 -3
  209. package/src/plugin-api.ts +42 -0
  210. package/src/runtime/artifact-trailers.ts +63 -0
  211. package/src/runtime/claude-bg-isolation.ts +138 -0
  212. package/src/runtime/claude-delivery-plan.ts +14 -3
  213. package/src/runtime/claude-hook-group.ts +2 -0
  214. package/src/runtime/companion-git-state.ts +155 -10
  215. package/src/runtime/companion-git.ts +96 -13
  216. package/src/runtime/companion-guidance.ts +107 -8
  217. package/src/runtime/companion-instructions.ts +1 -1
  218. package/src/runtime/companion-sync.ts +109 -21
  219. package/src/runtime/current-branch.ts +24 -0
  220. package/src/runtime/entered-worktree.ts +24 -0
  221. package/src/runtime/env-names.ts +2 -2
  222. package/src/runtime/env.ts +16 -9
  223. package/src/runtime/forge-remote.ts +48 -0
  224. package/src/runtime/git-layout.ts +185 -24
  225. package/src/runtime/git-tracked.ts +60 -0
  226. package/src/runtime/json-fields.ts +8 -0
  227. package/src/runtime/launch-env-guard.ts +65 -0
  228. package/src/runtime/opencode-server-record.ts +136 -0
  229. package/src/runtime/pending-records.ts +533 -0
  230. package/src/runtime/projected-guidance.ts +6 -2
  231. package/src/runtime/projection.ts +40 -6
  232. package/src/runtime/publication-secret-scan.ts +45 -0
  233. package/src/runtime/repo-destination.ts +72 -0
  234. package/src/runtime/repo-local.ts +29 -2
  235. package/src/runtime/rtk-git-guard.ts +66 -0
  236. package/src/runtime/runtime-document-manifest.ts +229 -19
  237. package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
  238. package/src/runtime/secret-guard.ts +9 -2
  239. package/src/runtime/secret-patterns.ts +3 -2
  240. package/src/runtime/secret-policy-weakening.ts +122 -0
  241. package/src/runtime/serving-claude-wrap.ts +41 -0
  242. package/src/runtime/session-context.ts +4 -3
  243. package/src/runtime/session-registry.ts +434 -0
  244. package/src/runtime/skill-prefix.ts +75 -0
  245. package/src/runtime/submitted-arrivals.ts +547 -0
  246. package/src/runtime/tokensave-route.ts +10 -5
  247. package/src/runtime/turn-state.d.mts +14 -0
  248. package/src/runtime/turn-state.mjs +93 -0
  249. package/src/runtime/umbrella-children.ts +52 -0
  250. package/src/runtime/umbrella-folder.ts +84 -0
  251. package/src/runtime/workflow/change-folders.ts +66 -0
  252. package/src/runtime/workflow/declaration.ts +720 -0
  253. package/src/runtime/workflow/globs.ts +85 -0
  254. package/src/runtime/workflow/next-handoff-process.ts +98 -0
  255. package/src/runtime/workflow/turn.ts +309 -0
  256. package/src/runtime/workflow/workflow.ts +262 -0
  257. package/src/runtime/wrap-state.ts +36 -13
  258. package/src/studio.ts +73 -19
  259. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/schema.yaml +3 -3
  260. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/design.md +1 -1
  261. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/proposal.md +1 -1
  262. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/tasks.md +1 -1
  263. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +3 -3
  264. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +147 -46
  265. package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +1 -1
  266. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +7 -75
  267. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +13 -7
  268. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +10 -0
  269. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +46 -14
  270. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +51 -38
  271. package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +14 -10
  272. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +1 -1
  273. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +113 -87
  274. package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +111 -100
  275. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +11 -5
  276. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +16 -6
  277. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +114 -0
  278. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +147 -46
  279. package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +1 -1
  280. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +7 -75
  281. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +13 -7
  282. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +10 -0
  283. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +46 -14
  284. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +51 -38
  285. package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +14 -10
  286. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +1 -1
  287. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +113 -87
  288. package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +111 -100
  289. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +11 -5
  290. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +16 -6
  291. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +114 -0
  292. package/src/templates/mate-skills/openspec-references.ts +3 -2
  293. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +1301 -154
  294. package/src/tools/setup/capabilities/openspec.ts +54 -15
  295. package/src/tools/setup/capabilities/rtk.ts +98 -5
  296. package/src/tools/setup/capabilities/tokensave.ts +3 -2
  297. package/src/tools/setup/dynamic-plugins/api.ts +38 -0
  298. package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
  299. package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
  300. package/src/tools/setup/dynamic-plugins/host.ts +2 -32
  301. package/src/tools/setup/dynamic-plugins/hydrate.ts +8 -7
  302. package/src/tools/setup/dynamic-plugins/install.ts +24 -22
  303. package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
  304. package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
  305. package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
  306. package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
  307. package/src/tools/setup/engine.ts +20 -1
  308. package/src/tools/setup/mate.ts +5 -3
  309. package/src/tools/setup/package-managers/bun.ts +8 -8
  310. package/src/tools/setup/plugin.ts +9 -1
  311. package/src/tools/setup/plugins/gitignore.ts +15 -9
  312. package/src/tools/setup/plugins/guidance.ts +4 -2
  313. package/src/tools/setup/providers/claude-plugin-hooks.ts +56 -0
  314. package/src/tools/setup/providers/claude.ts +64 -7
  315. package/src/tools/setup/service-registry.ts +69 -0
  316. package/src/tools/setup/service.ts +233 -0
  317. package/src/tools/setup/utils.ts +28 -5
  318. package/src/tools/setup/working-repo-cleanup.ts +2 -2
  319. package/src/tools/setup/working-repo-local-state.ts +2 -0
  320. package/src/tools/setup.ts +25 -14
  321. package/studio-dist/client/assets/app-BFVyWHGo.css +2 -0
  322. package/studio-dist/client/assets/button-D6LrRkOG.js +1 -0
  323. package/studio-dist/client/assets/combobox-Dk2MMZWE.js +1 -0
  324. package/studio-dist/client/assets/companion-view-BVaZNtiI.js +1 -0
  325. package/studio-dist/client/assets/fields-D_FYhxQr.js +1 -0
  326. package/studio-dist/client/assets/getting-started-ByWRg7hC.js +1 -0
  327. package/studio-dist/client/assets/getting-started-DZSjYC-b.js +1 -0
  328. package/studio-dist/client/assets/getting-started._topic-C6OyQ4G6.js +1 -0
  329. package/studio-dist/client/assets/getting-started.index-BkmPHdEm.js +1 -0
  330. package/studio-dist/client/assets/graph-7jm2XzyL.js +2 -0
  331. package/studio-dist/client/assets/graph-canvas-DDuzsNSx.js +3242 -0
  332. package/studio-dist/client/assets/guides-D9VTjWXP.js +1 -0
  333. package/studio-dist/client/assets/index-BBmFpG4y.js +40 -0
  334. package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
  335. package/studio-dist/client/assets/markdown-view-RL5YvfZg.js +1 -0
  336. package/studio-dist/client/assets/panel-B8F8sOKQ.js +1 -0
  337. package/studio-dist/client/assets/plugins._service._view-CynxTbMx.js +1 -0
  338. package/studio-dist/client/assets/queries-axYk2u9L.js +1 -0
  339. package/studio-dist/client/assets/react-r45OnJCw.js +27 -0
  340. package/studio-dist/client/assets/reports-BCAyXh6p.js +1 -0
  341. package/studio-dist/client/assets/routes-BFPqq89E.js +1 -0
  342. package/studio-dist/client/assets/skills-DTks_uBx.js +1 -0
  343. package/studio-dist/client/assets/specs-DU1kqcp5.js +1 -0
  344. package/studio-dist/client/assets/specs-view-omrd_5P3.js +1 -0
  345. package/studio-dist/client/assets/steps-DhIFuAZy.js +1 -0
  346. package/studio-dist/client/assets/store-DJ5cncKA.js +1 -0
  347. package/studio-dist/client/assets/studio-BR9j15J0.js +100 -0
  348. package/studio-dist/client/assets/studio-queries-CFP_yTpr.js +2 -0
  349. package/studio-dist/client/assets/usage-CHmwtkoM.js +55 -0
  350. package/studio-dist/client/assets/useBaseQuery-BlC-AZ35.js +1 -0
  351. package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
  352. package/studio-dist/client/assets/vault-DRg8MScm.js +1 -0
  353. package/studio-dist/client/assets/warnings-UHFy6HAp.js +1 -0
  354. package/studio-dist/client/assets/workflow-Bv9vSfVV.js +1 -0
  355. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-DAbZ6fzY.js +106 -0
  356. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +86 -31
  357. package/studio-dist/server/assets/button-BfoNadNR.js +8193 -0
  358. package/studio-dist/server/assets/combobox-oxUI6r4V.js +2089 -0
  359. package/studio-dist/server/assets/{companion-view-aBady57v.js → companion-view-DHUjPpA0.js} +13 -7
  360. package/studio-dist/server/assets/companions-kBrJZAd6.js +31 -0
  361. package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
  362. package/studio-dist/server/assets/fields-BD_c65T1.js +1190 -0
  363. package/studio-dist/server/assets/getting-started-7P0oyWaM.js +67 -0
  364. package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
  365. package/studio-dist/server/assets/getting-started._topic-B1mV0kGz.js +13 -0
  366. package/studio-dist/server/assets/getting-started.index-CeGtvUsm.js +13 -0
  367. package/studio-dist/server/assets/graph-BWtmJOH2.js +16 -0
  368. package/studio-dist/server/assets/graph-DSDVEELZ.js +801 -0
  369. package/studio-dist/server/assets/graph-canvas-CID9Nksc.js +21066 -0
  370. package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
  371. package/studio-dist/server/assets/guides-BLJenHwQ.js +5 -0
  372. package/studio-dist/server/assets/guides-Bm3RbUB-.js +13 -0
  373. package/studio-dist/server/assets/guides.server-rHHqRuzV.js +66 -0
  374. package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
  375. package/studio-dist/server/assets/markdown-view-D3v9x-cM.js +105 -0
  376. package/studio-dist/server/assets/panel-yqOl5GMU.js +169 -0
  377. package/studio-dist/server/assets/plugins._service._view-DwqJX7s9.js +92 -0
  378. package/studio-dist/server/assets/queries-DYmGrhNO.js +32 -0
  379. package/studio-dist/server/assets/react-BO0uMhpm.js +89 -0
  380. package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
  381. package/studio-dist/server/assets/reports-7yaPz7aP.js +147 -0
  382. package/studio-dist/server/assets/reports-C4Y_Jd-x.js +18 -0
  383. package/studio-dist/server/assets/router-Dnoq5auE.js +12844 -0
  384. package/studio-dist/server/assets/routes-Cok4p3mK.js +768 -0
  385. package/studio-dist/server/assets/{search-JAKurDNh.js → search-DUK7Jl6f.js} +21 -2
  386. package/studio-dist/server/assets/{shell-CboT2f66.js → shell-DNVXedgE.js} +16 -6
  387. package/studio-dist/server/assets/skills-D8qdXSku.js +267 -0
  388. package/studio-dist/server/assets/skills-pKmuAs0F.js +28 -0
  389. package/studio-dist/server/assets/specs-DeHYUNFp.js +51 -0
  390. package/studio-dist/server/assets/specs-view-BGn-5Ik_.js +425 -0
  391. package/studio-dist/server/assets/{start-BW5ovN0k.js → start-h3ICWwd2.js} +4 -1
  392. package/studio-dist/server/assets/steps-CV7Yk7L7.js +224 -0
  393. package/studio-dist/server/assets/store-CWDGIp6x.js +280 -0
  394. package/studio-dist/server/assets/studio-CB94np48.js +10437 -0
  395. package/studio-dist/server/assets/studio-queries-BqZGBE70.js +1335 -0
  396. package/studio-dist/server/assets/usage-M6Gi6Km7.js +25584 -0
  397. package/studio-dist/server/assets/usage-j5jR9gX9.js +24 -0
  398. package/studio-dist/server/assets/{studio-queries-CLnP9kGu.js → useBaseQuery-Tv_QJt9r.js} +4 -1318
  399. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-BQKuMdJW.js → useSelector-DUmCUXAs.js} +4 -498
  400. package/studio-dist/server/assets/vault-PqVmssmW.js +1035 -0
  401. package/studio-dist/server/assets/{vault-BGulVoNh.js → vault-lBlvSyD4.js} +19 -4
  402. package/studio-dist/server/assets/{views-Bd7cRr27.js → views-CsFp1i1G.js} +10 -9
  403. package/studio-dist/server/assets/warnings-BDs34j_m.js +24 -0
  404. package/studio-dist/server/assets/workflow-T0eEldsa.js +687 -0
  405. package/studio-dist/server/server.js +429 -9
  406. package/src/cli/commands/factory/factory.ts +0 -301
  407. package/src/cli/commands/report/collector.ts +0 -288
  408. package/src/cli/commands/studio/factory-credential.ts +0 -49
  409. package/src/cli/commands/studio/workset-session.ts +0 -131
  410. package/src/lib/delivery/archive-change.ts +0 -166
  411. package/src/lib/delivery/forge.ts +0 -279
  412. package/src/lib/delivery/token.ts +0 -24
  413. package/src/lib/factory/attach-client.ts +0 -113
  414. package/src/lib/factory/attach.ts +0 -178
  415. package/src/lib/factory/broker.ts +0 -190
  416. package/src/lib/factory/bun-commands.ts +0 -39
  417. package/src/lib/factory/client.ts +0 -92
  418. package/src/lib/factory/command.ts +0 -61
  419. package/src/lib/factory/credential-store.ts +0 -153
  420. package/src/lib/factory/frames.ts +0 -77
  421. package/src/lib/factory/ids.ts +0 -58
  422. package/src/lib/factory/outcomes/actions.ts +0 -114
  423. package/src/lib/factory/outcomes/index.ts +0 -381
  424. package/src/lib/factory/outcomes/lifecycle.ts +0 -205
  425. package/src/lib/factory/outcomes/runs.ts +0 -81
  426. package/src/lib/factory/prepare.ts +0 -49
  427. package/src/lib/factory/pty.ts +0 -103
  428. package/src/lib/factory/runner/companion-context.ts +0 -178
  429. package/src/lib/factory/runner/control.ts +0 -92
  430. package/src/lib/factory/runner/harness-agent.ts +0 -250
  431. package/src/lib/factory/runner/live.ts +0 -159
  432. package/src/lib/factory/runner/questions.ts +0 -22
  433. package/src/lib/factory/runner/rank.ts +0 -26
  434. package/src/lib/factory/runner/run-policy.ts +0 -12
  435. package/src/lib/factory/runner/run.ts +0 -199
  436. package/src/lib/factory/runner/scheduler.ts +0 -416
  437. package/src/lib/factory/runner/state.ts +0 -233
  438. package/src/lib/factory/runner/workflow.ts +0 -542
  439. package/src/lib/factory/runtime.ts +0 -972
  440. package/src/lib/factory/sandbox.ts +0 -292
  441. package/src/lib/factory/worktree-branch.ts +0 -17
  442. package/src/templates/capabilities/openspec-cap/mate-v1/templates/explore-brief.md +0 -25
  443. package/studio-dist/client/assets/companion-view-Csva26Ir.js +0 -1
  444. package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +0 -1
  445. package/studio-dist/client/assets/factory-B7l9ZQyx.js +0 -4
  446. package/studio-dist/client/assets/index-n6uo_92S.js +0 -40
  447. package/studio-dist/client/assets/prepaint-CD5OpmTM.js +0 -24
  448. package/studio-dist/client/assets/queries-CN3JwMBX.js +0 -1
  449. package/studio-dist/client/assets/react-CabXf2Ds.js +0 -1
  450. package/studio-dist/client/assets/report-time-Dc-KOqQu.js +0 -1
  451. package/studio-dist/client/assets/reports-C01RsnMA.js +0 -1
  452. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
  453. package/studio-dist/client/assets/routes-4pbC-2Hj.js +0 -1
  454. package/studio-dist/client/assets/skills-CihQganl.js +0 -1
  455. package/studio-dist/client/assets/spec-areas-C2L48N4C.js +0 -1
  456. package/studio-dist/client/assets/specs-D24_35_K.js +0 -1
  457. package/studio-dist/client/assets/studio-DKxfi691.css +0 -1
  458. package/studio-dist/client/assets/studio-queries-rvbJupCy.js +0 -3
  459. package/studio-dist/client/assets/vault-Bd4CQiTK.js +0 -1
  460. package/studio-dist/client/assets/warnings-V_Ys51wJ.js +0 -1
  461. package/studio-dist/client/assets/workflow-BJejeVwQ.js +0 -1
  462. package/studio-dist/server/assets/actions-Bvgj9eb8.js +0 -54
  463. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
  464. package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +0 -778
  465. package/studio-dist/server/assets/factory-D6xnjedJ.js +0 -2385
  466. package/studio-dist/server/assets/factory-DT3UzHlh.js +0 -68
  467. package/studio-dist/server/assets/prepaint-BMke0fo1.js +0 -41
  468. package/studio-dist/server/assets/queries-Ag2iL8q2.js +0 -107
  469. package/studio-dist/server/assets/react-COs0LHn-.js +0 -51
  470. package/studio-dist/server/assets/report-time-DAfzln-N.js +0 -8
  471. package/studio-dist/server/assets/reports-BnUNJVtx.js +0 -126
  472. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
  473. package/studio-dist/server/assets/router-BH--drIx.js +0 -4298
  474. package/studio-dist/server/assets/routes-khSDK1bV.js +0 -361
  475. package/studio-dist/server/assets/skills-MWYnWoKs.js +0 -106
  476. package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +0 -16
  477. package/studio-dist/server/assets/specs-DE3w8hZP.js +0 -155
  478. package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
  479. package/studio-dist/server/assets/vault-CuyyhLyB.js +0 -832
  480. package/studio-dist/server/assets/warnings-BH05rOuG.js +0 -15
  481. package/studio-dist/server/assets/workflow-BSuIKWqH.js +0 -42
  482. /package/src/lib/{factory/keyed-serial.ts → keyed-serial.ts} +0 -0
  483. /package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/spec.md +0 -0
@@ -1,292 +0,0 @@
1
- import net from "node:net";
2
- import path from "node:path";
3
-
4
- import type { HarnessV1NetworkSandboxSession } from "@ai-sdk/harness";
5
-
6
- import { AGENT_CREDENTIAL_NAMES } from "./broker";
7
- import { bunCommand } from "./bun-commands";
8
- import type { FactoryClient } from "./client";
9
- import {
10
- encodeControl,
11
- encodeData,
12
- FRAME_CONTROL,
13
- FRAME_DATA,
14
- FRAME_STDERR,
15
- FrameDecoder,
16
- } from "./frames";
17
- import { FactoryError } from "./ids";
18
-
19
- /**
20
- * The harness's sandbox, made of the factory broker: commands and files through broker
21
- * `exec`, long-running processes (the Claude Code bridge) through the non-TTY attach,
22
- * ports through the container's inner-network address. Studio never holds the agent
23
- * credential: a process the harness starts with a credential variable is started with
24
- * `agent: true` instead, and the broker sets the real value inside the container.
25
- */
26
-
27
- type SandboxSession = ReturnType<HarnessV1NetworkSandboxSession["restricted"]>;
28
- type ProcessOptions = {
29
- command: string;
30
- workingDirectory?: string;
31
- env?: Record<string, string>;
32
- abortSignal?: AbortSignal;
33
- };
34
-
35
- export interface WorksetSandboxOptions {
36
- /** The Workset identifier. */
37
- id: string;
38
- /** Absolute worktree path, identical inside the container. */
39
- worktree: string;
40
- /** The unprivileged user's home inside the container, where harness state lives. */
41
- home: string;
42
- client: FactoryClient;
43
- attachSocket: string;
44
- /** The port the bridge binds inside the container. */
45
- bridgePort: number;
46
- /** Long-running processes are the harness bridge: start each with the agent credential. */
47
- agentSpawns?: boolean;
48
- /** A fresh session marker per spawned process. */
49
- sessionId: () => string;
50
- connect?: (socketPath: string) => net.Socket;
51
- }
52
-
53
- const CREDENTIAL_NAMES = new Set<string>(AGENT_CREDENTIAL_NAMES);
54
- const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
55
-
56
- function shellQuote(value: string): string {
57
- return `'${value.replace(/'/g, `'\\''`)}'`;
58
- }
59
-
60
- /** Splits the harness's environment into plain variables and whether it asked for the credential. */
61
- function splitEnv(env: Record<string, string> = {}): {
62
- plain: Record<string, string>;
63
- agent: boolean;
64
- } {
65
- const plain: Record<string, string> = {};
66
- let agent = false;
67
- for (const [name, value] of Object.entries(env)) {
68
- if (!ENV_NAME.test(name))
69
- throw new FactoryError(`environment variable ${JSON.stringify(name)} is invalid`);
70
- if (CREDENTIAL_NAMES.has(name)) agent = true;
71
- else plain[name] = value;
72
- }
73
- return { plain, agent };
74
- }
75
-
76
- /** `env K=V … bash -c <command>`, Node tools rewritten to Bun; credential variables never appear here. */
77
- function wrap(command: string, cwd: string, env: Record<string, string>): string[] {
78
- const assignments = Object.entries(env).map(([name, value]) => `${name}=${value}`);
79
- return ["env", ...assignments, "bash", "-c", `cd ${shellQuote(cwd)} && ${bunCommand(command)}`];
80
- }
81
-
82
- export function createWorksetSandbox(
83
- options: WorksetSandboxOptions,
84
- ): HarnessV1NetworkSandboxSession {
85
- const roots = [options.worktree, options.home];
86
- const connect = options.connect ?? ((socketPath: string) => net.connect(socketPath));
87
- const live = new Set<net.Socket>();
88
-
89
- /** Absolute and inside the worktree or the harness's home; anything else is refused. */
90
- const resolvePath = (target: string): string => {
91
- const resolved = path.resolve(options.worktree, target);
92
- if (!roots.some((root) => resolved === root || resolved.startsWith(`${root}${path.sep}`))) {
93
- throw new FactoryError(`${target} is outside the Workset's worktree and home`);
94
- }
95
- return resolved;
96
- };
97
-
98
- const exec = (command: string[], extra: { stdin?: Uint8Array; agent?: boolean } = {}) =>
99
- options.client.exec({ id: options.id, command, ...extra });
100
-
101
- const run: SandboxSession["run"] = async (process: ProcessOptions) => {
102
- const cwd = resolvePath(process.workingDirectory ?? options.worktree);
103
- const { plain, agent } = splitEnv(process.env);
104
- const result = await exec(wrap(process.command, cwd, plain), agent ? { agent } : {});
105
- return { exitCode: result.status, stdout: result.stdout, stderr: result.stderr };
106
- };
107
-
108
- const readBinaryFile = async ({ path: target }: { path: string }): Promise<Uint8Array | null> => {
109
- const file = resolvePath(target);
110
- const result = await exec([
111
- "sh",
112
- "-c",
113
- 'test -f "$1" || exit 3; base64 -w0 -- "$1"',
114
- "read",
115
- file,
116
- ]);
117
- if (result.status === 3) return null;
118
- if (result.status !== 0)
119
- throw new FactoryError(`reading ${target} failed: ${result.stderr.trim()}`);
120
- return new Uint8Array(Buffer.from(result.stdout.trim(), "base64"));
121
- };
122
-
123
- const writeBinaryFile = async ({
124
- path: target,
125
- content,
126
- }: {
127
- path: string;
128
- content: Uint8Array;
129
- }) => {
130
- const file = resolvePath(target);
131
- const result = await exec(
132
- ["sh", "-c", 'mkdir -p "$(dirname "$1")" && cat > "$1"', "write", file],
133
- { stdin: content },
134
- );
135
- if (result.status !== 0)
136
- throw new FactoryError(`writing ${target} failed: ${result.stderr.trim()}`);
137
- };
138
-
139
- const spawnProcess = async (process: ProcessOptions & { stdin?: boolean }) => {
140
- const cwd = resolvePath(process.workingDirectory ?? options.worktree);
141
- const { plain, agent: asked } = splitEnv(process.env);
142
- const agent = asked || options.agentSpawns === true;
143
- const socket = connect(options.attachSocket);
144
- live.add(socket);
145
- const decoder = new FrameDecoder();
146
- let stdoutController!: ReadableStreamDefaultController<Uint8Array>;
147
- let stderrController!: ReadableStreamDefaultController<Uint8Array>;
148
- const stdout = new ReadableStream<Uint8Array>({ start: (c) => void (stdoutController = c) });
149
- const stderr = new ReadableStream<Uint8Array>({ start: (c) => void (stderrController = c) });
150
- let exitCode: number | null = null;
151
- const exited = new Promise<{ exitCode: number }>((resolve) => {
152
- socket.on("close", () => {
153
- live.delete(socket);
154
- for (const controller of [stdoutController, stderrController]) {
155
- try {
156
- controller.close();
157
- } catch {
158
- /** Already closed. */
159
- }
160
- }
161
- resolve({ exitCode: exitCode ?? 137 });
162
- });
163
- });
164
- socket.on("error", () => {});
165
- socket.on("data", (chunk: Buffer) => {
166
- for (const frame of decoder.push(new Uint8Array(chunk))) {
167
- if (frame.type === FRAME_DATA) stdoutController.enqueue(frame.data);
168
- else if (frame.type === FRAME_STDERR) stderrController.enqueue(frame.data);
169
- else if (frame.type === FRAME_CONTROL && frame.message.type === "exit") {
170
- exitCode = typeof frame.message.status === "number" ? frame.message.status : 1;
171
- } else if (frame.type === FRAME_CONTROL && frame.message.type === "error") {
172
- stderrController.enqueue(new TextEncoder().encode(`${String(frame.message.reason)}\n`));
173
- exitCode = 1;
174
- }
175
- }
176
- });
177
- await new Promise<void>((resolve, reject) => {
178
- socket.once("connect", () => resolve());
179
- socket.once("error", (error) =>
180
- reject(new FactoryError(`the factory broker is not reachable: ${error.message}`)),
181
- );
182
- });
183
- socket.write(
184
- encodeControl({
185
- type: "start",
186
- id: options.id,
187
- session: options.sessionId(),
188
- command: wrap(process.command, cwd, plain),
189
- agent,
190
- tty: false,
191
- }),
192
- );
193
- process.abortSignal?.addEventListener("abort", () => socket.destroy(), { once: true });
194
- const handle = {
195
- stdout,
196
- stderr,
197
- wait: () => exited,
198
- // Closing the attach makes the broker stop the process and all it started.
199
- kill: async () => {
200
- socket.destroy();
201
- await exited;
202
- },
203
- };
204
- if (!process.stdin) return handle;
205
- return {
206
- ...handle,
207
- stdin: new WritableStream<Uint8Array>({
208
- write: (chunk) => void socket.write(encodeData(chunk)),
209
- close: () => void socket.write(encodeControl({ type: "eof" })),
210
- }),
211
- };
212
- };
213
-
214
- const restricted = {
215
- description: `A Mate Workset container. The worktree is ${options.worktree}; commands run there as an unprivileged user with their own Docker daemon.`,
216
- run,
217
- readBinaryFile,
218
- readFile: async ({ path: target }: { path: string }) => {
219
- const bytes = await readBinaryFile({ path: target });
220
- if (bytes === null) return null;
221
- return new ReadableStream<Uint8Array>({
222
- start: (controller) => {
223
- controller.enqueue(bytes);
224
- controller.close();
225
- },
226
- });
227
- },
228
- readTextFile: async ({
229
- path: target,
230
- startLine,
231
- endLine,
232
- }: {
233
- path: string;
234
- startLine?: number;
235
- endLine?: number;
236
- }) => {
237
- const bytes = await readBinaryFile({ path: target });
238
- if (bytes === null) return null;
239
- const text = new TextDecoder().decode(bytes);
240
- if (startLine === undefined && endLine === undefined) return text;
241
- return text
242
- .split("\n")
243
- .slice((startLine ?? 1) - 1, endLine)
244
- .join("\n");
245
- },
246
- writeBinaryFile,
247
- writeTextFile: ({ path: target, content }: { path: string; content: string }) =>
248
- writeBinaryFile({ path: target, content: new TextEncoder().encode(content) }),
249
- writeFile: async ({
250
- path: target,
251
- content,
252
- }: {
253
- path: string;
254
- content: ReadableStream<Uint8Array>;
255
- }) => {
256
- const chunks: Uint8Array[] = [];
257
- for await (const chunk of content as unknown as AsyncIterable<Uint8Array>) chunks.push(chunk);
258
- await writeBinaryFile({ path: target, content: new Uint8Array(Buffer.concat(chunks)) });
259
- },
260
- spawn: spawnProcess,
261
- } as unknown as SandboxSession;
262
-
263
- const endpoint = async ({
264
- port,
265
- protocol,
266
- }: {
267
- port: number;
268
- protocol?: "http" | "https" | "ws";
269
- }) => {
270
- if (port !== options.bridgePort)
271
- throw new FactoryError(`port ${port} is not exposed by this Workset`);
272
- return { url: `${protocol ?? "http"}://${await options.client.address(options.id)}:${port}` };
273
- };
274
-
275
- const stop = async () => {
276
- for (const socket of live) socket.destroy();
277
- };
278
-
279
- return {
280
- ...restricted,
281
- id: `workset-${options.id}`,
282
- defaultWorkingDirectory: options.worktree,
283
- ports: [options.bridgePort],
284
- getPortEndpoint: endpoint,
285
- getPortUrl: async (request: { port: number; protocol?: "http" | "https" | "ws" }) =>
286
- (await endpoint(request)).url,
287
- // The Workset container outlives a run; only this run's processes stop.
288
- stop,
289
- destroy: stop,
290
- restricted: () => restricted,
291
- } as unknown as HarnessV1NetworkSandboxSession;
292
- }
@@ -1,17 +0,0 @@
1
- import type { CommandResult } from "./command";
2
- import { FactoryError } from "./ids";
3
-
4
- /** Reads actual delivery ownership; detached or unreadable HEAD must not become a default. */
5
- export async function readWorktreeBranch(
6
- worktree: string,
7
- git: (args: string[]) => Promise<CommandResult>,
8
- ): Promise<string> {
9
- const result = await git(["-C", worktree, "symbolic-ref", "--quiet", "--short", "HEAD"]);
10
- const branch = result.stdout.trim();
11
- if (result.status !== 0 || !branch) {
12
- throw new FactoryError(
13
- `Worktree ${worktree} has detached or unreadable HEAD; select a delivery branch explicitly before continuing.`,
14
- );
15
- }
16
- return branch;
17
- }
@@ -1,25 +0,0 @@
1
- ---
2
- type: change-exploration
3
- change: <change-name>
4
- schema: mate-v1
5
- tags: [openspec/change, openspec/explore]
6
- scopes:
7
- - repository: org/repository
8
- area: .
9
- ---
10
-
11
- ## Evidence
12
-
13
- <!-- Summarize relevant repository facts, behavior, and constraints. -->
14
-
15
- ## Unknowns
16
-
17
- <!-- Record only unresolved, high-leverage questions and their answers. -->
18
-
19
- ## Options
20
-
21
- <!-- List plausible directions and the trade-offs that matter. -->
22
-
23
- ## Direction
24
-
25
- <!-- State the agreed scope and intended direction for the proposal. -->
@@ -1 +0,0 @@
1
- import{i as e}from"./queries-CN3JwMBX.js";import{Et as t,o as n}from"./studio-queries-rvbJupCy.js";var r=t();function i({companionPath:e,reason:t}){return(0,r.jsxs)(`section`,{className:`panel error`,children:[(0,r.jsx)(`h3`,{children:`Could not read this companion`}),(0,r.jsx)(`p`,{className:`mono`,children:e}),(0,r.jsx)(`p`,{children:t})]})}function a({view:t,search:a,children:o}){let{data:s}=e(n(t,a));return s.error?(0,r.jsx)(i,{companionPath:s.error.companionPath,reason:s.error.reason}):(0,r.jsx)(r.Fragment,{children:o(s)})}export{a as t};
@@ -1 +0,0 @@
1
- import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{D as t,E as n,Et as r,I as i,T as a,qt as o,z as s}from"./studio-queries-rvbJupCy.js";var c=[`mate-clarify-intent`,`mate-interview-me`,`mate-grill-me`],l={"mate-clarify-intent":`Default. Reads what the request already states and routes to an interview, grilling, or skip, then runs that one mode.`,"mate-interview-me":`Explicit mode: guided, one-question-at-a-time clarification when intent, constraints, or scope still need confirmation.`,"mate-grill-me":`Explicit mode: round-based stress test of a mostly known direction to surface hidden assumptions and risks.`},u={"clarify-intent":{what:`Settles who the change is for, why it is needed, how success is measured, and what binds it, before any artifact exists.`,why:`Intent gaps are cheapest to close before exploration turns them into documents.`},explore:{what:`Resolves repository evidence, unknowns, and options, with scope taken from the companion context map, and suggests slicing a large feature.`,why:`It separates uncertainty from the proposal's committed scope.`},propose:{what:`Chooses the schema from the minimal eligibility test, checks slicing when explore agreed none, and writes the change's planning artifacts in one prompt.`,why:`One prompt writes every artifact; each one is then reviewed on its own.`},apply:{what:`Records the delivery branch, avoiding protected branches, then implements the reviewed tasks.`,why:`The recorded branch is what archive and publication later wait on.`},"inspect-outcome":{what:`Shows what the applied change did as a rendered diagram and diff in a Mate report.`,why:`Seeing the result tells the reviewer whether cleanup is warranted.`},"refine-code":{what:`Looks for smaller, clearer code once tests pass, preserving behavior.`,why:`Cleanup lands before archive, so shipped code and recorded specs agree.`},archive:{what:`Applies the delta specs to the local canonical specs and records the delivery; allowed before the branch merges.`,why:`A feature's later changes build on canonical specs that already include this one.`},publish:{what:`Commits, tags, and pushes archived changes whose delivery branches are merged, chosen by the developer.`,why:`Published canonical specs then describe the default branch; unmerged archives wait.`}};function d(e,t,n){return{what:(t?.schemaName===n?t.artifacts.find(t=>t.id===e)?.description:void 0)??`A person reviews the ${e} artifact.`,why:`Reviews stay with people: Mate never marks them approved.`}}function f(e,t){if(e.kind===`human`)return null;if(e.id===`clarify-intent`)return`/${e.skill} about ${s}`;let n=e.id===`propose`&&t!==`mate-v1`?` (use schema: ${t})`:``;return`/${e.skill}${n} for ${i}`}function p(e){return e&&e.replace(` ${i}`,``).replace(` ${s}`,``)}function m(e){return c.filter(e).map(e=>({name:e,description:l[e],prompt:`/${e} about ${s}`,copyPrompt:`/${e} about`}))}var h=new Set([`explore`,`propose`,`apply`,`archive`]);function g(e){if(e.kind===`human`)return[`human-review`];let t=e.optional?[`optional`,`skill`]:[`skill`];return h.has(e.id)&&t.push(`openspec`),t}var _={"mate-v1":{tagline:`full planning`,description:`Full planning path: proposal, specs, design, and tasks.`},"mate-minimal":{tagline:`minimal planning`,description:`Short path: specs and tasks only, for one-Area, low-risk changes with clear intent.`}};function v(e){return t(e)?_[e]:{tagline:`custom schema`,description:`Planning path of the ${e} schema.`}}var y={plan:`Plan`,review:`Review`,build:`Build`,ship:`Ship`};function b(e,t){return e.kind===`human`?`review`:e.id===`apply`||t===`build`&&e.optional?`build`:t===void 0||t===`plan`?`plan`:`ship`}function x(e){return e.kind===`human`?`human`:e.optional?`optional`:null}function S(e){let t=[];for(let n of e){let e=x(n),r=t.at(-1);e&&r?.group===e?r.steps.push(n):t.push({group:e,steps:[n]})}return t.map(e=>e.group===`human`||e.group===`optional`&&e.steps.length>1?{kind:`group`,group:e.group,steps:e.steps}:{kind:`stage`,step:e.steps[0]})}function C(e,t,r){let i=r.skills?new Set(r.skills):null,a=e=>!i||i.has(e),o=n(t),s=[];for(let t of o.stages){let n=t.kind===`human`?d(t.artifact,r.topology,e):u[t.id],i=f(t,e),o=s.at(-1),c={...t,what:n.what,why:n.why,badges:g(t),prompt:i,copyPrompt:p(i),phase:b(t,o?.phase)};t.id===`clarify-intent`&&(c.alternatives=m(a)),t.kind===`skill`&&!a(t.skill)&&(c.missingSkill=t.skill),t.id===`apply`&&(c.sessionBreakBefore=!0),s.push(c)}return{schema:e,label:e,...v(e),steps:s,map:S(s),reviewsKnown:o.reviewsKnown}}function w(e,n){return n?.schemaName===e?n.artifacts.map(e=>e.id):t(e)?a[e]:void 0}function T(e={}){let n=e.topology?.schemaName;return{paths:(n&&!t(n)?[n]:Object.keys(a)).map(t=>C(t,w(t,e.topology),e))}}var E=e=>({id:e.id,kind:`stage`,step:e});function ee(e){let t=e.map.map(e=>e.kind===`stage`?{nodes:[E(e.step)],optional:e.step.optional,phase:e.step.phase}:e.group===`human`?{nodes:[{id:`reviews`,kind:`review-group`,steps:e.steps}],optional:!1,phase:e.steps[0].phase}:{nodes:e.steps.map(E),optional:!0,phase:e.steps[0].phase});return t.unshift({nodes:[{id:`start`,kind:`start`}],optional:!1,phase:t[0]?.phase??`plan`}),t}function te(e){return e.kind===`stage`?!!e.step.sessionBreakBefore:e.kind===`review-group`&&!!e.steps[0].sessionBreakBefore}function D(e){let t=[],n=(e,n,r)=>{for(let i of e)for(let e of n)t.push({from:i.id,to:e.id,kind:r,newSession:te(e)})};return e.forEach((t,r)=>{let i=e[r+1];i&&n(t.nodes,i.nodes,`flow`);let a=e[r-1];t.optional&&a&&i&&n(a.nodes,i.nodes,`bypass`)}),t}function O(e){let t=[];return e.forEach((e,n)=>{let r=t.at(-1);r?.phase===e.phase?r.to=n+1:t.push({phase:e.phase,label:y[e.phase],from:n,to:n+1})}),t}function k(e){let t=e.findIndex(e=>e.nodes.some(e=>e.id===`archive`));return t===-1?null:{from:0,to:t+1}}function A(e){let t=ee(e),n=Math.max(1,...t.map(e=>e.nodes.length)),r=t.flatMap((e,t)=>e.nodes.map((r,i)=>e.nodes.length===1?{...r,column:t,row:0,rowSpan:n}:{...r,column:t,row:i,rowSpan:1}));return{columns:t.length,rows:n,nodes:r,edges:D(t),bands:O(t),cycle:k(t)}}var j=e=>e.rows*2+1;function M(e){return{along:e.column+.5,across:e.row*2+e.rowSpan}}var N=e=>Math.round(e*1e4)/1e4,P=(e,t)=>`${N(e/t*100)}%`,F=({along:e,across:t})=>`${N(t)} ${N(e)}`;function I(e,t){let n=t=>{let n=e.nodes.find(e=>e.id===t);if(!n)throw Error(`Unknown graph node: ${t}`);return M(n)};return[n(t.from),n(t.to)]}function L(e,t){let[n,r]=I(e,t);if(t.kind===`bypass`){let t=j(e);return`M ${F(n)} C ${F({along:n.along,across:t})}, ${F({along:r.along,across:t})}, ${F(r)}`}let i=(n.along+r.along)/2;return`M ${F(n)} C ${F({along:i,across:n.across})}, ${F({along:i,across:r.across})}, ${F(r)}`}function R(e,t){let[n,r]=I(e,t),i=(n.along+r.along)/2;return t.kind===`bypass`?{along:i,across:(n.across+r.across)/8+j(e)*3/4}:{along:i,across:(n.across+r.across)/2}}function z(e,t){return{x:P(t.across,j(e)),y:P(t.along,e.columns)}}function B(e,t){return{top:P(t.from,e.columns),height:P(t.to-t.from,e.columns)}}var V=e(o(),1),H=r();function ne({payload:e}){let t=T({skills:e.skills&&e.skills.length>0?e.skills:void 0,topology:e.topology}),[n,r]=(0,V.useState)(t.paths[0]?.schema);return(0,H.jsx)(`section`,{className:`workflow-delivery-path`,"aria-label":`Delivery Path`,children:t.paths.length>1?(0,H.jsxs)(`div`,{className:`workflow-schema`,"data-workflow-schema-root":!0,children:[(0,H.jsxs)(`label`,{className:`view-choice`,children:[(0,H.jsx)(`span`,{children:`OpenSpec schema`}),(0,H.jsx)(`select`,{"data-workflow-schema-select":!0,value:n,onChange:e=>r(e.target.value),children:t.paths.map(e=>(0,H.jsxs)(`option`,{value:e.schema,children:[e.label,` – `,e.tagline]},e.schema))})]}),(0,H.jsx)(`div`,{className:`workflow-schema-panels`,children:t.paths.map(e=>(0,H.jsx)(`section`,{"data-workflow-schema-panel":e.schema,"data-active":e.schema===n?`true`:`false`,children:(0,H.jsx)(U,{path:e})},e.schema))})]}):(0,H.jsxs)(`div`,{className:`workflow-schema`,children:[(0,H.jsxs)(`p`,{className:`view-choice`,children:[(0,H.jsx)(`span`,{children:`OpenSpec schema`}),(0,H.jsxs)(`code`,{children:[t.paths[0].label,` – `,t.paths[0].tagline]})]}),(0,H.jsx)(U,{path:t.paths[0]})]})})}function U({path:e}){return(0,H.jsxs)(`div`,{className:`workflow-path`,children:[(0,H.jsxs)(`div`,{className:`workflow-path-graph`,children:[(0,H.jsx)(J,{path:e}),(0,H.jsx)(Y,{})]}),(0,H.jsxs)(`aside`,{className:`workflow-detail`,"aria-label":`${e.label} stage details`,children:[(0,H.jsxs)(`div`,{className:`workflow-detail-overview`,id:G(e),children:[(0,H.jsx)(`p`,{className:`workflow-description`,children:e.description}),e.reviewsKnown?null:(0,H.jsx)(`p`,{className:`workflow-description`,children:`The schema's artifacts could not be read, so its review stages are unknown.`}),(0,H.jsx)(`p`,{className:`workflow-description`,children:`A workset is one or more changes published together: after Archive change, start again at the top for the next change, and publish once they are archived.`}),(0,H.jsx)(`p`,{className:`workflow-detail-hint`,children:`Select a node in the graph to see what that stage does and the prompt that runs it.`})]}),e.steps.map(t=>(0,H.jsx)(re,{path:e,step:t},t.id))]})]})}var W=(e,t)=>`workflow-${e.schema}-${t.id}`,G=e=>`workflow-${e.schema}-overview`;function K(e,t){if(!t)return()=>void 0;let n=q(e,t.current);return e=>e.column<n?`done`:e.id===t.current?`current`:`next`}function q(e,t){let n=e.nodes.find(e=>e.id===t);return n?n.column:t===`complete`?e.columns:-1}function J({path:e,progress:t,label:n=`Delivery Path map`}){let r=A(e),i=K(r,t);return(0,H.jsxs)(`nav`,{className:`workflow-graph`,"aria-label":n,"data-progress-activity":t?.activity,style:{"--graph-columns":String(r.columns),"--graph-rows":String(r.rows)},children:[(0,H.jsxs)(`div`,{className:`workflow-graph-bands`,"aria-hidden":`true`,children:[r.bands.map(e=>(0,H.jsx)(`div`,{className:`workflow-graph-band`,"data-band":e.phase,style:B(r,e),children:e.label},e.phase)),r.cycle?(0,H.jsx)(`div`,{className:`workflow-graph-cycle`,style:B(r,r.cycle),children:(0,H.jsx)(`span`,{children:`repeats for each change`})}):null,(0,H.jsx)(`div`,{className:`workflow-graph-workset`,children:(0,H.jsx)(`span`,{children:`workset`})})]}),(0,H.jsx)(Z,{graph:r,stateOf:i}),(0,H.jsx)(`ol`,{className:`workflow-graph-nodes`,children:r.nodes.map(n=>n.kind===`start`?null:(0,H.jsx)(`li`,{className:`workflow-graph-node`,"data-node-kind":n.kind,"data-progress":i(n),"aria-current":i(n)===`current`?`step`:void 0,style:{"--graph-row":String(n.column+1),"--graph-lane":String(n.row+1),"--graph-span":String(n.rowSpan)},children:n.kind===`stage`?(0,H.jsx)(Q,{path:e,step:n.step,box:!0,plain:!!t,children:(0,H.jsx)(X,{progress:t,state:i(n)})}):(0,H.jsxs)(`div`,{className:`workflow-graph-box workflow-graph-group`,"data-map-group":`human`,children:[(0,H.jsx)(`span`,{className:`workflow-graph-group-label`,children:`Human review`}),(0,H.jsx)(`ol`,{children:n.steps.map(n=>(0,H.jsx)(`li`,{children:(0,H.jsx)(Q,{path:e,step:n,plain:!!t})},n.id))}),(0,H.jsx)(X,{progress:t,state:i(n)})]})},n.id))})]})}function Y(){return(0,H.jsxs)(`ul`,{className:`workflow-graph-legend`,"aria-hidden":`true`,children:[(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`i`,{className:`workflow-legend-optional`}),`optional`]}),(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`i`,{className:`workflow-graph-openspec`}),`OpenSpec`]}),(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`i`,{className:`workflow-legend-session`}),`new session`]}),(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`i`,{className:`workflow-legend-skip`}),`can be skipped`]})]})}function X({progress:e,state:t}){return t===`done`?(0,H.jsx)(`span`,{className:`visually-hidden`,children:`, done`}):t!==`current`||!e?.note?null:(0,H.jsx)(`span`,{className:`workflow-graph-note`,children:e.note})}function Z({graph:e,stateOf:t}){let n=n=>{let r=e.nodes.find(e=>e.id===n.to),i=r?t(r):void 0;return n.kind===`flow`&&(i===`done`||i===`current`)};return(0,H.jsxs)(`svg`,{className:`workflow-graph-layer`,"aria-hidden":`true`,focusable:`false`,children:[(0,H.jsx)(`svg`,{viewBox:`0 0 ${j(e)} ${e.columns}`,preserveAspectRatio:`none`,overflow:`visible`,children:e.edges.map(t=>(0,H.jsx)(`path`,{className:`workflow-graph-edge`,d:L(e,t),"data-edge-kind":t.kind,"data-edge-from":t.from,"data-edge-to":t.to,"data-new-session":t.newSession?`true`:void 0,"data-travelled":n(t)?`true`:void 0},`${t.kind}-${t.from}-${t.to}`))}),e.nodes.map(t=>{if(t.kind!==`start`)return null;let{x:n,y:r}=z(e,M(t));return(0,H.jsx)(`circle`,{className:`workflow-graph-start`,cx:n,cy:r,r:`3.5`},t.id)}),e.edges.map(t=>{if(!t.newSession)return null;let{x:n,y:r}=z(e,R(e,t));return(0,H.jsx)(`circle`,{className:`workflow-graph-session`,"data-session-mark":t.to,cx:n,cy:r,r:`3.5`},`${t.from}-${t.to}`)})]})}function Q({path:e,step:t,box:n,plain:r,children:i}){return(0,H.jsxs)(r?`span`:`a`,{className:n?`workflow-graph-link workflow-graph-box`:`workflow-graph-link`,href:r?void 0:`#${W(e,t)}`,"data-map-stage":t.id,"data-stage-kind":t.kind,"data-optional":t.optional?`true`:void 0,"aria-label":t.kind===`human`?t.label:void 0,children:[t.badges.includes(`openspec`)?(0,H.jsx)(`span`,{className:`workflow-graph-openspec`,"aria-hidden":`true`}):null,t.kind===`human`?t.artifact:t.label,i]})}function re({path:e,step:t}){return(0,H.jsxs)(`article`,{className:`workflow-card`,id:W(e,t),"data-stage":t.id,"data-stage-kind":t.kind,"data-optional":t.optional?`true`:void 0,children:[(0,H.jsxs)(`header`,{className:`workflow-card-header`,children:[(0,H.jsxs)(`div`,{className:`workflow-card-heading`,children:[(0,H.jsx)(`h3`,{children:t.label}),(0,H.jsx)(se,{badges:oe(t)})]}),(0,H.jsxs)(`p`,{className:`workflow-card-meta`,children:[(0,H.jsx)(`span`,{children:y[t.phase]}),t.skill?(0,H.jsx)(`code`,{children:t.skill}):null,t.sessionBreakBefore?(0,H.jsx)(`span`,{className:`workflow-card-session`,children:`New session / clean chat`}):null]})]}),(0,H.jsx)(ie,{step:t}),t.missingSkill?(0,H.jsxs)(`p`,{className:`workflow-missing-skill`,role:`note`,children:[`Skill not reported for this companion: `,(0,H.jsx)(`code`,{children:t.missingSkill}),`. Run`,` `,(0,H.jsx)(`code`,{children:`mate companion update`}),`; this stage is not complete.`]}):null,(0,H.jsxs)(`dl`,{className:`workflow-card-explanation`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`What`}),(0,H.jsx)(`dd`,{children:t.what})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`Why`}),(0,H.jsx)(`dd`,{children:t.why})]})]}),(0,H.jsx)(`footer`,{className:`workflow-card-footer`,children:(0,H.jsx)(`a`,{href:`#${G(e)}`,children:`Path overview`})})]})}function ie({step:e}){return e.kind===`human`?(0,H.jsxs)(`p`,{className:`workflow-card-human`,children:[`Review `,e.artifact,` yourself — no skill, no prompt`]}):e.alternatives?.length?(0,H.jsx)(ae,{step:e}):e.prompt?(0,H.jsxs)(`div`,{className:`workflow-command`,children:[(0,H.jsx)(`span`,{className:`workflow-command-label`,children:`Run`}),(0,H.jsx)(`code`,{children:e.prompt}),(0,H.jsx)($,{text:e.copyPrompt??e.prompt,label:`${e.label} prompt`})]}):null}function ae({step:e}){return e.alternatives?.length?(0,H.jsx)(`div`,{className:`workflow-option-list`,children:e.alternatives.map(e=>(0,H.jsxs)(`div`,{className:`workflow-option`,children:[(0,H.jsxs)(`div`,{className:`workflow-command`,children:[(0,H.jsx)(`span`,{className:`workflow-command-label`,children:`Option`}),(0,H.jsx)(`code`,{children:e.prompt}),(0,H.jsx)($,{text:e.copyPrompt,label:`${e.name} prompt`})]}),(0,H.jsx)(`small`,{children:e.description})]},e.name))}):null}function $({text:e,label:t}){return(0,H.jsx)(`button`,{type:`button`,className:`runway-step-copy`,"data-copy":e,"data-copy-label":t,children:`Copy`})}var oe=e=>e.badges.filter(e=>e!==`skill`);function se({badges:e}){return(0,H.jsx)(`span`,{className:`workflow-badges`,children:e.map(e=>(0,H.jsx)(`em`,{className:`runway-step-badge runway-step-badge-${e}`,children:e===`human-review`?`Human review`:e},e))})}export{J as n,T as r,ne as t};
@@ -1,4 +0,0 @@
1
- import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{i as t}from"./queries-CN3JwMBX.js";import{C as n,Et as r,F as i,N as a,O as o,P as s,_ as c,b as l,bt as u,g as d,ht as f,n as p,qt as m,s as h,v as g,y as _}from"./studio-queries-rvbJupCy.js";import{t as v}from"./warnings-V_Ys51wJ.js";import{n as y,r as ee}from"./delivery-path-DJMpRmiY.js";import{c as te,d as b,g as x,l as S,o as ne,u as re}from"./index-n6uo_92S.js";import{n as ie,t as ae}from"./react-CabXf2Ds.js";function C(e){if(Array.isArray(e.questions)&&e.questions.length>0)return e.questions;let t=e;return typeof t.question==`string`?[t]:[]}function oe(e,t){return t===`failed`||t===`interrupted`?null:`Workset ${e} has no failed or interrupted run to retry`}var se=[`start`,`later`,`answer`,`take-control`,`return`,`retry`,`cancel`,`feedback`,`regenerate`,`start-apply`,`publish`],ce=`the AFK runner needs the appliance's factory mode for this companion`;function le(e,t,n,r){let{id:i,stage:a,stageLabel:o}=t,s=n?.state??`idle`;switch(e){case`start`:case`later`:return a===`done`?`Workset ${i} is done`:null}if(!r.runner)return ce;switch(e){case`answer`:return s===`waiting`?null:`this question was already answered`;case`take-control`:return n?.conversation?n.control?`a person already has, or asked for, this Outcome's conversation`:a===`done`?`Workset ${i} is done`:null:`this Outcome has no factory conversation to take over`;case`return`:return n?.control&&n.control.mode!==`automatic`?null:`the factory already drives this Outcome`;case`retry`:return oe(i,s);case`cancel`:return s===`queued`||s===`running`?null:`Workset ${i} has no run to cancel`;case`feedback`:return a===`human-review`||a===`apply`||a===`merge-wait`?null:`Workset ${i} takes no feedback at ${o}; start a new outcome instead`;case`regenerate`:case`start-apply`:return a===`human-review`?null:`Workset ${i} is not in the Human Reviews; it is at ${o}`;case`publish`:return a===`publish`?null:`Workset ${i} is not merged and archived; it is at ${o}`}}function w(e,t,n){return new Set(se.filter(r=>le(r,e,t,n)===null))}function ue(e){if(!e.queuedAt)return null;let t=Date.parse(e.queuedAt);return Number.isNaN(t)?null:t}function de(e,t){return e.rank===null||t.rank===null?e.rank===t.rank?0:e.rank===null?1:-1:e.rank-t.rank||(e.id<t.id?-1:+(e.id>t.id))}var T=e(m(),1),fe=(0,T.createContext)(``);function pe(e,t){let n=(0,T.useRef)(e);(0,T.useEffect)(()=>{n.current=e});let r=(0,T.useRef)(null),i=(0,T.useRef)(t);return(0,T.useEffect)(()=>{let e=r.current;if(!e)return;e.open||i.current(e);let t=t=>{t.target===e&&e.close()},a=()=>n.current();return e.addEventListener(`click`,t),e.addEventListener(`close`,a),()=>{e.removeEventListener(`click`,t),e.removeEventListener(`close`,a)}},[]),r}var E=r(),D=[{kind:`subscription`,tab:`Claude subscription`,label:`Subscription token`,hint:(0,E.jsxs)(`ol`,{className:`note agents-steps`,children:[(0,E.jsxs)(`li`,{children:[`In a terminal on your own machine, run `,(0,E.jsx)(`code`,{children:`claude setup-token`}),`.`]}),(0,E.jsx)(`li`,{children:`Sign in with your Claude account in the browser it opens.`}),(0,E.jsxs)(`li`,{children:[`Paste the token it prints below. It starts with `,(0,E.jsx)(`code`,{children:`sk-ant-oat`}),` and is valid for a year.`]})]})},{kind:`api-key`,tab:`API key`,label:`Anthropic API key`,hint:(0,E.jsx)(`p`,{className:`note`,children:`Agents bill this key. It starts with sk-ant-api.`})}],me={subscription:`Claude subscription token`,"api-key":`Anthropic API key`};function he(e){if(!e)return`Checking…`;if(!e.kind)return`No credential set. Worksets cannot start agents until one is.`;let t=e.source===`studio`?`set in Studio${e.setAt?` on ${new Date(e.setAt).toLocaleString()}`:``}`:`supplied at startup`;return`${me[e.kind]}, ${t}.`}function ge(e,t){e.preventDefault();let n=e.currentTarget,r=new FormData(n).get(t);return n.reset(),typeof r==`string`?r:``}function _e({kind:e,label:t,hint:n,onSaved:r}){let i=x({mutationFn:t=>l(e,t),onSuccess:r});return(0,E.jsxs)(`form`,{className:`factory-sheet`,"data-agents-form":e,onSubmit:e=>i.mutate(ge(e,`value`)),children:[n,(0,E.jsxs)(`label`,{className:`agents-field`,children:[(0,E.jsx)(`span`,{children:t}),(0,E.jsx)(`input`,{type:`password`,name:`value`,autoComplete:`off`,spellCheck:!1,required:!0})]}),(0,E.jsx)(`div`,{className:`factory-sheet-actions`,children:(0,E.jsx)(`button`,{type:`submit`,disabled:i.isPending,children:`Save`})}),i.error?(0,E.jsx)(`p`,{className:`factory-problems`,role:`alert`,children:i.error.message}):null]})}function ve({onClose:e}){let t=f(),n=ie(g()),[r,i]=(0,T.useState)(`subscription`),[a,o]=(0,T.useState)(!1),s=D.find(e=>e.kind===r),l=e=>{t.setQueryData(c,e),o(!0)},u=x({mutationFn:_,onSuccess:e=>{t.setQueryData(c,e),o(!1)}}),d=pe(e,e=>e.showModal?.());return(0,E.jsxs)(`dialog`,{ref:d,className:`outcome-dialog agents-dialog`,"aria-labelledby":`agents-title`,children:[(0,E.jsxs)(`header`,{className:`outcome-dialog-head`,children:[(0,E.jsxs)(`div`,{className:`outcome-dialog-heading`,children:[(0,E.jsx)(`h2`,{id:`agents-title`,children:`Workset agents`}),(0,E.jsx)(`p`,{className:`outcome-dialog-state`,"data-agents-status":``,children:n.error?n.error.message:he(n.data)})]}),(0,E.jsx)(`form`,{method:`dialog`,children:(0,E.jsxs)(`button`,{type:`submit`,className:`outcome-dialog-close`,"aria-keyshortcuts":`Escape`,children:[`Close `,(0,E.jsx)(`kbd`,{children:`Esc`})]})})]}),(0,E.jsxs)(`div`,{className:`agents-dialog-body`,children:[(0,E.jsx)(`div`,{role:`tablist`,"aria-label":`How to sign in`,className:`agents-tabs`,children:D.map(e=>(0,E.jsx)(`button`,{type:`button`,role:`tab`,id:`agents-tab-${e.kind}`,"aria-controls":`agents-panel`,"aria-selected":r===e.kind,onClick:()=>{i(e.kind),o(!1)},children:e.tab},e.kind))}),(0,E.jsx)(`div`,{role:`tabpanel`,id:`agents-panel`,"aria-labelledby":`agents-tab-${r}`,children:(0,E.jsx)(_e,{kind:s.kind,label:s.label,hint:s.hint,onSaved:l},s.kind)}),a?(0,E.jsx)(`p`,{className:`note`,role:`status`,children:`Saved. The next agent start uses it.`}):null,n.data?.source===`studio`?(0,E.jsxs)(`div`,{className:`factory-sheet-actions agents-clear`,children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>u.mutate(),disabled:u.isPending,children:`Remove the credential set in Studio`}),u.error?(0,E.jsx)(`p`,{className:`factory-problems`,role:`alert`,children:u.error.message}):null]}):null]})]})}function O({action:e,id:t,className:n,children:r,...i}){let a=(0,T.useContext)(fe),o=f(),s=x({mutationFn:n=>d({data:{companion:a,action:e,id:t,fields:n}}),onSuccess:()=>p(o,a)});return(0,E.jsxs)(`form`,{className:n,"data-factory-action":t?`/${t}/${e}`:`/${e}`,onSubmit:e=>{e.preventDefault();let t=e.currentTarget,n=e.nativeEvent.submitter,r={};for(let[e,i]of new FormData(t,n))typeof i==`string`&&(r[e]=i);s.mutate(r,{onSuccess:()=>t.reset()})},"aria-busy":s.isPending||void 0,...i,children:[(0,E.jsx)(`fieldset`,{className:`factory-form-fields`,disabled:s.isPending,children:r}),s.error?(0,E.jsx)(`p`,{className:`factory-problems`,role:`alert`,children:s.error.message}):null]})}function k(e,t){let n;try{n=e()}catch{return}return{getItem:e=>{let r=e=>e===null?null:JSON.parse(e,t?.reviver),i=n.getItem(e)??null;return i instanceof Promise?i.then(r):r(i)},setItem:(e,r)=>n.setItem(e,JSON.stringify(r,t?.replacer)),removeItem:e=>n.removeItem(e)}}var A=e=>t=>{try{let n=e(t);return n instanceof Promise?n:{then(e){return A(e)(n)},catch(e){return this}}}catch(e){return{then(e){return this},catch(t){return A(t)(e)}}}},j=ae()(((e,t)=>(n,r,i)=>{let a={storage:k(()=>window.localStorage),partialize:e=>e,version:0,merge:(e,t)=>({...t,...e}),...t},o=!1,s=0,c=new Set,l=new Set,u=a.storage;if(!u)return e((...e)=>{console.warn(`[zustand persist middleware] Unable to update item '${a.name}', the given storage is currently unavailable.`),n(...e)},r,i);let d=()=>{let e=a.partialize({...r()});return u.setItem(a.name,{state:e,version:a.version})},f=i.setState;i.setState=(...e)=>(f(...e),d());let p=e((...e)=>(n(...e),d()),r,i);i.getInitialState=()=>p;let m,h=()=>{if(!u)return;let e=++s;o=!1,c.forEach(e=>e(r()??p));let t=a.onRehydrateStorage?.call(a,r()??p)||void 0;return A(u.getItem.bind(u))(a.name).then(e=>{if(e){if(typeof e.version==`number`&&e.version!==a.version){if(a.migrate){let t=a.migrate(e.state,e.version);return t instanceof Promise?t.then(e=>[!0,e]):[!0,t]}console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`)}else return[!1,e.state]}return[!1,void 0]}).then(t=>{if(e!==s)return;let[i,o]=t;if(m=a.merge(o,r()??p),n(m,!0),i)return d()}).then(()=>{e===s&&(t?.(r(),void 0),m=r(),o=!0,l.forEach(e=>e(m)))}).catch(n=>{e===s&&t?.(void 0,n)})};return i.persist={setOptions:e=>{a={...a,...e},e.storage&&(u=e.storage)},clearStorage:()=>{++s,u?.removeItem(a.name)},getOptions:()=>a,rehydrate:()=>h(),hasHydrated:()=>o,onHydrate:e=>(c.add(e),()=>{c.delete(e)}),onFinishHydration:e=>(l.add(e),()=>{l.delete(e)})},a.skipHydration||h(),m||p})(e=>({filter:``,setFilter:t=>e({filter:t}),stepped:!1,setStepped:t=>e({stepped:t}),agentsOpen:!1,setAgentsOpen:t=>e({agentsOpen:t})}),{name:`mate.factory.filter`,storage:k(()=>sessionStorage),partialize:({filter:e})=>({filter:e})})),M=`mate.factory.needsYou`;function ye(e,t){let n=e.toLowerCase();return t.toLowerCase().split(/\s+/).every(e=>n.includes(e))}function N(e,t){let n=e.replace(/^\(\d+\) /,``);return t>0?`(${t}) ${n}`:n}function be(e,t,n){let r=t?e.indexOf(t):-1;return r===-1?e[0]:e[Math.min(e.length-1,Math.max(0,r+n))]}function xe(e){return!!e?.closest?.(`input, textarea, select, [contenteditable], .outcome-terminal`)}function Se(e,t){if(/^[1-9]$/.test(t))return e.querySelector(`[data-option-key="${t}"]`);let n={j:`J`,k:`K`}[t];return n?e.querySelector(`[data-outcome-goto][aria-keyshortcuts="${n}"]`):null}function Ce(e,t){return t===`n`?e.querySelector(`form[data-outcome-input] textarea`):t===`/`?e.querySelector(`[data-outcome-filter]`):null}function we(e){return t=>{if(t.defaultPrevented||t.altKey)return;let n=t.target;if(t.key===`Enter`&&(t.ctrlKey||t.metaKey)){let e=n?.closest?.(`form`);if(n?.localName===`textarea`&&e){if(t.preventDefault(),e.querySelector(`button[type="submit"].factory-primary:disabled`))return;let n=e.querySelector(`button[value="start"]`);e.requestSubmit(n??void 0)}return}if(t.ctrlKey||t.metaKey||xe(n))return;let r=e.querySelector(`dialog.outcome-dialog[open]`);if(r){let e=Se(r,t.key);e&&(t.preventDefault(),e.click());return}let i=Ce(e,t.key);if(i){t.preventDefault(),i.focus();return}let a=!!n?.matches?.(`[data-outcome-row]`),o=t.key===`j`||a&&t.key===`ArrowDown`,s=t.key===`k`||a&&t.key===`ArrowUp`;if(!o&&!s)return;let c=be([...e.querySelectorAll(`[data-outcome-row]`)].filter(e=>e.getClientRects().length>0),e.activeElement,o?1:-1);c&&(t.preventDefault(),c.focus(),c.scrollIntoView({block:`nearest`}))}}function Te(){(0,T.useEffect)(()=>{let e=we(document);return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[])}function Ee(e){(0,T.useEffect)(()=>{if(document.title=N(document.title,e),typeof Notification>`u`||Notification.permission!==`granted`)return;let t=0;try{t=Number(sessionStorage.getItem(M)||`0`),sessionStorage.setItem(M,String(e))}catch{}e>t&&new Notification(`Mate factory`,{body:e===1?`1 decision needs you`:`${e} decisions need you`})},[e]),(0,T.useEffect)(()=>()=>void(document.title=N(document.title,0)),[])}function De(){let[e,t]=(0,T.useState)(()=>typeof Notification<`u`&&Notification.permission==="default");return{offered:e,ask:()=>void Notification.requestPermission().then(()=>t(!1))}}function P(e,t){if(t===void 0)return``;let n=Math.max(0,Math.floor((t-Date.parse(e))/6e4));return n>=1440?`${Math.floor(n/1440)}d`:n>=60?`${Math.floor(n/60)}h`:`${n}m`}var F={pieces:[],open:{}},Oe=/^(> |committed: |pushed |published |linked |Returned to automation|no review report |the review report for |\S+ is now at )/;function ke(e){let t=[];for(let n of e.split(/(?<=\n)/)){let e=Oe.test(n)?`factory`:`agent`,r=t.at(-1);r&&(r.kind===e||n.trim()===``)?r.text+=n:t.push({kind:e,text:n})}return t}function I(e,t){let n=(t,n,r)=>{let i=[...e.pieces,r===void 0?{kind:t,text:n}:{id:r,kind:t,text:n}];return{pieces:i,open:r===void 0?e.open:{...e.open,[r]:i.length-1}}},r=(t,r)=>{let i=e.open[t];if(i===void 0)return n(`agent`,r,t);let a=[...e.pieces];return a[i]={...a[i],text:a[i].text+r},{...e,pieces:a}};switch(t.type){case`replay`:{let e={pieces:ke(t.log),open:{}};for(let n of t.open)e=I(e,{type:`text`,...n,delta:n.text});return e}case`text`:return t.id===void 0?n(`agent`,t.delta):r(t.id,t.delta);case`text-end`:{let e=r(t.id,`
2
- `),{[t.id]:n,...i}=e.open;return{...e,open:i}}case`tool`:return n(`tool`,`› ${t.name} ${t.summary}\n`);case`tool-done`:return t.failed?n(`failed`,` ${t.name} failed\n`):e;case`log`:return n(`factory`,t.text);case`lost`:return n(`factory`,`
3
- This view fell behind the run; close and reopen the Outcome.
4
- `);case`settled`:return e}}function Ae(e){let[t,n]=(0,T.useReducer)((e,t)=>t.type===`reset`?{...F,ended:!1}:{...I(e,t),ended:e.ended||t.type===`lost`},{...F,ended:!1});return(0,T.useEffect)(()=>{if(typeof EventSource>`u`)return;n({type:`reset`});let t=new EventSource(e);return t.addEventListener(`message`,e=>{try{n(JSON.parse(e.data))}catch{}}),()=>t.close()},[e]),{pieces:t.pieces,ended:t.ended}}var je=class{mount;outcome;companion;failed;focus;term=null;ws=null;sessionId=null;observer=null;closed=!1;constructor(e,t,n,r,i){this.mount=e,this.outcome=t,this.companion=n,this.failed=r,this.focus=i,this.open()}async open(){try{let e=await te();if(this.closed)return;let t=new e(this.mount,{cursorBlink:!0,autoResize:!1,wasmUrl:a});if(this.term=t,t.onData=e=>this.send({type:`input`,data:e}),t.onResize=()=>this.send({type:`resize`,cols:t.cols,rows:t.rows}),await t.init(),this.closed)return;t.fit(),this.observer=new ResizeObserver(()=>{this.mount.clientWidth&&this.mount.clientHeight&&t.fit()}),this.observer.observe(this.mount),this.connect()}catch{this.term=null,this.failed()}}send(e){b(this.ws,e)}notice(e){this.term?.write(`\r\n\u001b[2m${e}\u001b[0m\r\n`)}start(){if(!this.term)return;let{cols:e,rows:t}=this.term;this.send({type:`start`,workset:this.outcome,companion:this.companion,cols:e,rows:t})}connect(){let e=S();this.ws=e,e.onopen=()=>{if(!this.term)return;let{cols:e,rows:t}=this.term;this.sessionId?this.send({type:`attach`,sessionId:this.sessionId,cols:e,rows:t}):this.start()},e.onmessage=e=>this.receive(e.data),e.onclose=()=>{this.ws===e&&(this.ws=null)}}receive(e){let t=this.term;if(!t)return;if(typeof e!=`string`){t.write(new Uint8Array(e));return}let n=re(e);n&&(n.type===`ready`?(this.sessionId=n.sessionId??null,t.write(`\x1Bc`),this.focus&&t.focus()):n.type===`gone`?(this.sessionId=null,this.start()):n.type===`exit`||n.type===`ended`?(this.sessionId=null,this.notice(`The session ended. Return to automation when you are done, or close and reopen the Outcome to start it again.`)):n.type===`takenOver`?this.notice(`Another tab has this session now.`):n.type===`error`&&n.reason&&this.notice(n.reason))}close(){this.closed=!0,this.observer?.disconnect(),this.ws?.close(),this.ws=null,this.term?.destroy(),this.term=null}};function Me({outcome:e,companion:t,focus:n=!0}){let r=(0,T.useRef)(null),[i,a]=(0,T.useState)(!1),o=(0,T.useRef)(n);return(0,T.useEffect)(()=>{let n=new je(r.current,e,t,()=>a(!0),o.current);return()=>n.close()},[e,t]),(0,E.jsx)(`div`,{ref:r,className:`outcome-terminal`,"data-outcome-terminal":e,"data-companion":t,"data-terminal-error":i?``:void 0,children:i?`The terminal could not start in this browser. Close and reopen the Outcome to retry.`:null})}var Ne=new Set([`queued`,`running`]);function L(e,t){return e.stage===`done`?null:t?.control?.mode===`manual`?`control`:t?.state===`waiting`?`decision`:t?.state===`failed`||t?.state===`interrupted`?`problem`:t&&Ne.has(t.state)?null:e.stage===`human-review`?`review`:e.stage===`merge-wait`?`merge`:e.stage===`publish`?`publish`:null}function R(e,t){return e.workset.id<t.workset.id?-1:+(e.workset.id>t.workset.id)}function z(e){let t=Date.parse(e.run?.updatedAt||e.workset.queuedAt||``);return Number.isNaN(t)?1/0:t}function Pe(e,t){return e.map(e=>({workset:e,run:t?.[e.id]}))}function Fe(e,t){return de({id:e.workset.id,rank:ue(e.workset)},{id:t.workset.id,rank:ue(t.workset)})}function B(e){let t=[e.run?.situations?.[0]?.at,e.run?.updatedAt,e.workset.queuedAt];return Math.max(0,...t.map(e=>Date.parse(e??``)).filter(Number.isFinite))}function V(e){return e.workset.queuedAt!==void 0||e.workset.changes.length>0||e.run!==void 0&&e.run.state!==`idle`}function Ie(e,t){let n=Pe(e,t),r=n.flatMap(e=>{let t=L(e.workset,e.run);return t?[{...e,kind:t}]:[]}).toSorted((e,t)=>z(e)-z(t)||R(e,t)),i=n.filter(e=>e.workset.stage!==`done`);return{attention:r,active:i.filter(V).toSorted(Fe),later:i.filter(e=>!V(e)).toSorted(R),completed:n.filter(e=>e.workset.stage===`done`).toSorted((e,t)=>B(t)-B(e)||R(e,t))}}var H=[{label:`Understood`,after:`clarify-intent`,next:`The factory is working out what you want`},{label:`Approach chosen`,after:`explore`,next:`The factory is choosing the approach`},{label:`Plan ready`,after:`propose`,next:`The factory is writing the plan`},{label:`Plan approved`,after:`human-review`,next:`Ready for your review`},{label:`Built`,after:`apply`,next:`The factory is building it`},{label:`Merged`,after:`merge-wait`,next:`Ready for you to merge`},{label:`Delivered`,after:`publish`,next:`Ready to publish`}];function U(e){return n.indexOf(e)}function Le(e){let t=U(e.stage);return H.map(e=>({label:e.label,reached:t>U(e.after)}))}function W(e,t){return!e.queuedAt&&e.changes.length===0&&(!t||t.state===`idle`)}function Re(e,t){if(e.stage===`done`)return`Delivered`;if(t?.control?.mode===`manual`)return`You have control`;if(t?.state===`waiting`)return`Waiting for your answer`;if(t?.state===`failed`||t?.state===`interrupted`)return`Stopped; needs you`;if(W(e,t))return`Saved for later`;let n=U(e.stage);return H.find(e=>n<=U(e.after))?.next??`Delivered`}var ze={"clarify-intent":`Understanding what you want.`,explore:`Working out the approach.`,propose:`Writing the plan.`,"human-review":`A plan is ready for your review.`,apply:`Building it.`,"merge-wait":`Built; waiting for the merge.`,publish:`Merged; ready to publish.`,done:`Delivered.`};function Be(e,t){return t?.state===`queued`?t.waiting===`workset-slot`?`Waiting for a Workset slot.`:t.waiting===`build-slot`?`Waiting for a build slot.`:`Waiting for a free slot.`:t?.state===`failed`?`Stopped: ${t.reason}`:t?.state===`interrupted`?`Stopped when Studio restarted.`:t?.state===`waiting`?`Waiting for your answer.`:W(e,t)?`Saved for later.`:ze[e.stage]??e.stageLabel}var Ve=new Set([`queued`,`waiting`,`failed`,`interrupted`]);function G(e,t){let n=t?.situations?.[0];return n&&!(t&&Ve.has(t.state))?n:{text:Be(e,t)}}var K={running:`Running`,queued:`Queued`,"needs-you":`Needs you`,control:`You have control`,stopped:`Stopped`,idle:`Idle`,later:`Saved for later`,done:`Delivered`};function q(e,t){return e.stage===`done`?`done`:t?.control?.mode===`manual`?`control`:t?.state===`failed`||t?.state===`interrupted`?`stopped`:t?.state===`running`?`running`:t?.state===`queued`?`queued`:L(e,t)?`needs-you`:V({workset:e,run:t})?`idle`:`later`}var He={"clarify-intent":`clarify-intent`,explore:`explore`,propose:`propose`,"human-review":`reviews`,apply:`apply`,"merge-wait":`archive`,publish:`publish`,done:`complete`},Ue=e=>He[e.stage],We={control:`You have control`,decision:`Decision needed`,review:`Plan ready for review`,merge:`Ready to merge`,publish:`Ready to publish`,problem:`Something went wrong`},Ge={decision:`The run is paused on this. Pick an option or answer in your words; it continues on its own.`,review:`Read each report, then approve to start building, or request a change to revise the plan.`,merge:`Merge the delivery branch on your forge; the board picks it up on its next refresh.`,publish:`Publishing commits, tags and pushes the archived specs to the companion.`,problem:`Retry runs the stage again; take control to fix it yourself.`,control:`You work in the factory's own conversation. Exit Claude, then return the Outcome to automation; the factory checks what changed and continues.`},Ke=`Pauses automation after the current stage; you continue the factory's own conversation here.`,qe=5;function J(e,t){let n=t?.state===`waiting`?C(t).length:0;return e===`decision`&&n>1?`Decisions needed (${n})`:We[e]}var Je=new Set([`answer`,`start-apply`,`publish`,`return`,`retry`,`start`]);function Ye({id:e,action:t,label:n,children:r}){return(0,E.jsxs)(O,{id:e,action:t,className:`factory-action`,children:[r,(0,E.jsx)(`button`,{type:`submit`,className:Je.has(t)?`factory-primary`:void 0,children:n})]})}function Y(e,t){let n=w(e.workset,e.run,t);return(r,i,a)=>t.writable&&n.has(r)?(0,E.jsx)(Ye,{id:e.workset.id,action:r,label:i,children:a}):null}function Xe({activity:e}){return(0,E.jsx)(`span`,{className:`activity-dot`,"data-activity":e,title:K[e],"aria-hidden":`true`})}function Ze({repositories:e,context:t}){return t.writable?e.length===0?(0,E.jsx)(`p`,{className:`note`,children:`Link a Working Repository to this companion to describe outcomes.`}):(0,E.jsxs)(O,{action:`create`,className:`outcome-input`,"data-outcome-input":``,children:[(0,E.jsxs)(`label`,{children:[(0,E.jsx)(`span`,{className:`outcome-input-label`,children:`What should we build or improve?`}),(0,E.jsx)(`textarea`,{name:`text`,rows:3,required:!0,placeholder:`Make onboarding easier: fewer signup steps, and keep authentication working.`})]}),(0,E.jsxs)(`div`,{className:`outcome-input-actions`,children:[(0,E.jsxs)(`button`,{type:`submit`,name:`start`,value:`start`,className:`factory-primary`,children:[`Start `,(0,E.jsx)(`kbd`,{children:`⌘↵`})]}),(0,E.jsx)(`button`,{type:`submit`,name:`start`,value:`later`,children:`Save for later`}),e.length>1?(0,E.jsx)(`select`,{name:`repository`,required:!0,"aria-label":`Working Repository`,children:e.map(e=>(0,E.jsx)(`option`,{value:e,children:e},e))}):null]})]}):(0,E.jsx)(`p`,{className:`note`,children:`Read-only mode. Start Studio with --writable to describe outcomes.`})}function Qe({workset:e}){let t=Le(e),n=t.filter(e=>e.reached).length,r=t.find(e=>!e.reached);return(0,E.jsxs)(`span`,{className:`outcome-row-track`,title:`${n} of ${t.length} milestones${r?`; next: ${r.label}`:``}`,children:[(0,E.jsx)(`span`,{className:`outcome-row-pips`,"aria-hidden":`true`,children:t.map(e=>(0,E.jsx)(`i`,{"data-reached":e.reached?`true`:`false`},e.label))}),(0,E.jsxs)(`span`,{className:`mono`,children:[n,`/`,t.length]})]})}function $e({checks:e}){return e?.length?(0,E.jsx)(`ul`,{className:`outcome-checks`,"aria-label":`Checks`,children:e.map(e=>(0,E.jsxs)(`li`,{"data-passed":e.passed?`true`:`false`,children:[e.passed?`✓`:`✗`,` `,e.name]},e.name))}):null}function et({item:e}){let t=Object.entries(e.run?.reviewReports??{}),n=e.run?.compareUrl;return t.length===0&&!n?null:(0,E.jsxs)(`div`,{className:`outcome-results`,children:[t.map(([e,n])=>(0,E.jsxs)(`a`,{href:`${o}${n}`,target:`_blank`,rel:`noreferrer`,children:[`Review plan`,t.length>1?` · ${e}`:``]},e)),n?(0,E.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,children:`View changes`}):null]})}function tt({item:e}){let t=e.run?.reviewReports??{};return(0,E.jsx)(`div`,{className:`factory-review-reports`,children:e.workset.changes.map(e=>t[e]?(0,E.jsxs)(`figure`,{className:`factory-review-report`,children:[(0,E.jsxs)(`figcaption`,{className:`mono`,children:[e,` ·`,` `,(0,E.jsx)(`a`,{href:`${o}${t[e]}`,target:`_blank`,rel:`noreferrer`,children:`open`})]}),(0,E.jsx)(`iframe`,{src:`${o}${t[e]}`,title:`Review report for ${e}`,loading:`lazy`,sandbox:`allow-scripts allow-modals`})]},e):(0,E.jsxs)(`p`,{className:`note`,"data-report-missing":e,children:[`No review report for `,(0,E.jsx)(`span`,{className:`mono`,children:e}),`.`]},e))})}function nt({item:e,context:t}){if(!t.writable)return null;let{stage:n}=e.workset;return n===`publish`||n===`done`?(0,E.jsxs)(O,{action:`create`,className:`outcome-feedback`,children:[(0,E.jsx)(`textarea`,{name:`text`,rows:2,required:!0,"aria-label":`A new outcome`}),(0,E.jsx)(`button`,{type:`submit`,name:`start`,value:`start`,children:`Start as a new outcome`})]}):Y(e,t)(`feedback`,`Request a change`,(0,E.jsx)(`textarea`,{name:`feedback`,rows:2,required:!0,"aria-label":`Request a change`,placeholder:`What should change?`}))}var rt=e=>e?.state===`running`||e?.state===`queued`;function it({item:e}){let{workset:t,run:n}=e,r=rt(n);return!n?.hasLog&&!r?null:(0,E.jsxs)(`section`,{className:`outcome-log-section`,"aria-label":`Log`,children:[(0,E.jsxs)(`header`,{className:`outcome-section-head`,children:[(0,E.jsx)(`h3`,{children:`Log`}),r?(0,E.jsx)(`span`,{className:`outcome-log-live`,children:`live`}):null,(0,E.jsx)(`a`,{href:s(t.id),target:`_blank`,rel:`noreferrer`,children:`Full log`})]}),(0,E.jsx)(at,{id:t.id})]})}function at({id:e}){let{pieces:t,ended:n}=Ae(i(e)),r=(0,T.useRef)(null),a=(0,T.useRef)(!0),[o,s]=(0,T.useState)(!1);return(0,T.useEffect)(()=>{let e=r.current;e&&t.length>0&&a.current&&(e.scrollTop=e.scrollHeight)},[t]),(0,E.jsxs)(`div`,{className:`outcome-log-frame`,children:[(0,E.jsx)(`pre`,{ref:r,role:`log`,"aria-label":`Run log`,tabIndex:0,onScroll:e=>{let t=e.currentTarget;a.current=t.scrollHeight-t.scrollTop-t.clientHeight<48,s(!a.current)},className:`outcome-log`,"data-outcome-log":i(e),"data-ended":n||void 0,children:t.length>0?t.map((e,t)=>(0,E.jsx)(`span`,{"data-kind":e.kind,children:e.text},t)):(0,E.jsx)(`span`,{className:`outcome-log-empty`,children:`Waiting for output.`})}),o?(0,E.jsx)(`button`,{type:`button`,className:`outcome-log-jump`,onClick:()=>{let e=r.current;e&&(e.scrollTop=e.scrollHeight,a.current=!0,s(!1))},children:`Jump to latest`}):null]})}function ot({item:e,context:t}){let{workset:n,run:r}=e,i=j(e=>e.stepped);return(0,E.jsxs)(`div`,{className:`factory-sheet outcome-control`,children:[(0,E.jsxs)(`div`,{className:`outcome-control-bar`,children:[r?.control?.reason?(0,E.jsx)(`p`,{className:`outcome-control-reason`,children:r.control.reason}):null,Y(e,t)(`return`,`Return to automation`)]}),t.sessions&&r?.control?.mode===`manual`?(0,E.jsx)(Me,{outcome:n.id,companion:t.companionDigest,focus:!i}):(0,E.jsx)(`p`,{className:`note`,children:`The terminal is not available in this Studio.`})]})}function st({item:e,context:t}){let{workset:n,run:r}=e;if(!r?.conversation||r.control||n.stage===`done`)return null;let i=Y(e,t)(`take-control`,`Take control`);return i?(0,E.jsxs)(`div`,{className:`outcome-control-offer`,children:[i,(0,E.jsx)(`p`,{className:`note`,children:Ke})]}):null}function ct({run:e,now:t}){if(e?.control?.mode!==`takeover-requested`)return null;let n=e.state===`running`?e.stage:null,r=e.control.updatedAt?P(e.control.updatedAt,t):``;return(0,E.jsxs)(`section`,{className:`outcome-dialog-attention`,"data-kind":`control`,"data-pending":``,role:`status`,"aria-label":`Taking control`,children:[(0,E.jsx)(`h3`,{children:`Taking control`}),(0,E.jsxs)(`p`,{className:`outcome-attention-hint`,children:[`Control passes to you once`,` `,n?(0,E.jsxs)(E.Fragment,{children:[`the `,(0,E.jsx)(`span`,{className:`mono`,children:n}),` stage`]}):`the current stage`,` `,`ends; the log below keeps following it. The terminal opens here then.`,r?(0,E.jsxs)(`span`,{className:`factory-age mono`,children:[` · asked `,r,` ago`]}):null]})]})}function lt(e,t){if(!e||e.state===`idle`)return`idle`;let n=e.state===`running`?e.startedAt:e.updatedAt;return`${e.state} ${e.stage}${n?` · ${P(n,t)}`:``}`}var ut=({workset:e,run:t})=>e.changes.some(e=>!t?.reviewReports?.[e]);function dt({item:e,context:t}){let{workset:n,run:r}=e,i=Y(e,t),a=rt(r),o=n.stage!==`done`;return(0,E.jsxs)(`div`,{className:`outcome-actions`,role:`group`,"aria-label":`Run actions`,children:[o&&!n.queuedAt?i(`start`,`Start`):null,a?i(`cancel`,`Cancel run`):null,n.stage===`human-review`&&!ut(e)?i(`regenerate`,`Regenerate reports`):null,o&&n.queuedAt?i(`later`,`Move to later`):null]})}function ft({item:e,context:t}){let{workset:n,run:r}=e;return(0,E.jsxs)(`dl`,{className:`outcome-facts`,children:[(0,E.jsx)(`dt`,{children:`Stage`}),(0,E.jsx)(`dd`,{children:n.stageLabel}),(0,E.jsx)(`dt`,{children:`Run`}),(0,E.jsx)(`dd`,{children:lt(r,t.now)}),(0,E.jsx)(`dt`,{children:`Changes`}),(0,E.jsx)(`dd`,{className:`mono`,children:n.changes.join(`, `)||`none yet`}),r?.pushedBranch?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Branch`}),(0,E.jsx)(`dd`,{className:`mono`,children:r.pushedBranch})]}):null,(0,E.jsx)(`dt`,{children:`Id`}),(0,E.jsx)(`dd`,{className:`mono`,children:n.id})]})}function pt(e,t,n){let{run:r}=e,i=K[t].toLowerCase();return r?.state===`running`&&n!==void 0?`${i} · ${P(r.startedAt,n)}`:t===`idle`?``:i}function X(){return(0,E.jsx)(`span`,{className:`factory-recommended`,children:`recommended`})}function mt({item:e,asked:t,round:n,context:r}){let i=r.writable&&w(e.workset,e.run,r).has(`answer`);return(0,E.jsxs)(`div`,{className:`factory-sheet`,children:[(0,E.jsx)(`p`,{className:`factory-question`,children:t.question}),t.options?.length?(0,E.jsx)(`div`,{className:`factory-options`,role:`group`,"aria-label":`Answers`,children:t.options.map((r,a)=>{let o=r===t.recommended,s=a<9?String(a+1):void 0;return i?(0,E.jsxs)(O,{id:e.workset.id,action:`answer`,className:`factory-option`,children:[(0,E.jsx)(`input`,{type:`hidden`,name:`round`,value:n}),(0,E.jsx)(`input`,{type:`hidden`,name:`answer`,value:r}),(0,E.jsxs)(`button`,{type:`submit`,"data-recommended":o?`true`:`false`,"data-option-key":s,"aria-keyshortcuts":s,children:[s?(0,E.jsx)(`kbd`,{"aria-hidden":`true`,children:s}):null,(0,E.jsx)(`span`,{children:r}),o?(0,E.jsx)(X,{}):null]})]},r):(0,E.jsxs)(`span`,{className:`factory-choice`,"data-recommended":o?`true`:`false`,children:[r,o?(0,E.jsx)(X,{}):null]},r)})}):t.recommended?(0,E.jsxs)(`p`,{className:`note`,children:[`Recommended: `,t.recommended]}):null,Y(e,r)(`answer`,t.options?.length?`Send my words`:`Answer`,(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`input`,{type:`hidden`,name:`round`,value:n}),(0,E.jsx)(`textarea`,{name:`answer`,rows:2,required:!0,"aria-label":`Answer in your words`,placeholder:t.options?.length?`Or answer in your words`:`Your answer`})]}))]})}function ht({asked:e,index:t}){return(0,E.jsxs)(`fieldset`,{className:`factory-question-set`,children:[(0,E.jsxs)(`legend`,{className:`factory-question`,children:[(0,E.jsxs)(`span`,{className:`mono`,children:[t+1,`.`]}),` `,e.question]}),e.options?.length?(0,E.jsx)(`div`,{className:`factory-choices`,children:e.options.map(n=>{let r=n===e.recommended;return(0,E.jsxs)(`label`,{className:`factory-choice`,"data-recommended":r?`true`:`false`,children:[(0,E.jsx)(`input`,{type:`radio`,name:`choice-${t}`,value:n}),(0,E.jsx)(`span`,{children:n}),r?(0,E.jsx)(X,{}):null]},n)})}):e.recommended?(0,E.jsxs)(`p`,{className:`note`,children:[`Recommended: `,e.recommended]}):null,(0,E.jsx)(`textarea`,{name:`answer-${t}`,rows:1,"aria-label":`Answer to question ${t+1} in your words`,placeholder:e.options?.length?`Or in your words (overrides the choice)`:`Your answer`})]})}function gt(e,t){let n=new FormData(e),r=0;for(let e=0;e<t;e+=1){let t=n.get(`answer-${e}`);(n.get(`choice-${e}`)||typeof t==`string`&&t.trim())&&(r+=1)}return r}function _t({item:e,questions:t,round:n,context:r}){let[i,a]=(0,T.useState)(0);if(!r.writable||!w(e.workset,e.run,r).has(`answer`))return(0,E.jsx)(`ol`,{className:`outcome-history`,children:t.map(e=>(0,E.jsx)(`li`,{children:e.question},e.question))});let o=e=>{let n=e.currentTarget.closest(`form`);n&&a(gt(n,t.length))},s=t.every(e=>e.recommended);return(0,E.jsxs)(`div`,{className:`factory-sheet`,children:[(0,E.jsxs)(O,{id:e.workset.id,action:`answer`,className:`factory-action factory-round`,children:[(0,E.jsx)(`input`,{type:`hidden`,name:`round`,value:n}),(0,E.jsx)(`div`,{className:`factory-round-questions`,onChange:o,onInput:o,children:t.map((e,t)=>(0,E.jsx)(ht,{asked:e,index:t},e.question))}),(0,E.jsxs)(`div`,{className:`factory-sheet-actions`,children:[(0,E.jsx)(`button`,{type:`submit`,className:`factory-primary`,disabled:i<t.length,children:`Send answers`}),(0,E.jsxs)(`span`,{className:`factory-round-count mono`,"aria-live":`polite`,children:[i,` of `,t.length,` answered`]})]})]}),s?(0,E.jsxs)(O,{id:e.workset.id,action:`answer`,className:`factory-action`,children:[(0,E.jsx)(`input`,{type:`hidden`,name:`round`,value:n}),t.map((e,t)=>(0,E.jsx)(`input`,{type:`hidden`,name:`choice-${t}`,value:e.recommended},e.question)),(0,E.jsx)(`button`,{type:`submit`,children:`Accept all recommendations`})]}):null]})}function vt({item:e,run:t,context:n}){let r=C(t);return r.length===1?(0,E.jsx)(mt,{item:e,asked:r[0],round:t.round??``,context:n}):(0,E.jsx)(_t,{item:e,questions:r,round:t.round??``,context:n})}function yt({item:e,kind:t,context:n}){let{run:r}=e,i=Y(e,n);if(t===`control`)return(0,E.jsx)(ot,{item:e,context:n});if(t===`decision`&&r?.state===`waiting`)return(0,E.jsx)(vt,{item:e,run:r,context:n});if(t===`problem`)return(0,E.jsxs)(`div`,{className:`factory-sheet`,children:[(0,E.jsx)(`p`,{className:`factory-problems`,children:r?.state===`failed`?r.reason:`Stopped when Studio restarted.`}),r?.needsCredential?(0,E.jsx)(At,{label:`Set the agent credential`}):null,i(`retry`,`Retry`)]});if(t===`review`){let t=ut(e);return(0,E.jsxs)(`div`,{className:`factory-sheet`,children:[(0,E.jsx)(tt,{item:e}),(0,E.jsxs)(`div`,{className:`factory-sheet-actions`,children:[i(`start-apply`,`Approve`),t?i(`regenerate`,`Regenerate`):null]}),(0,E.jsx)(nt,{item:e,context:n})]})}return t===`merge`?(0,E.jsx)(`div`,{className:`factory-sheet`,children:r?.compareUrl?(0,E.jsxs)(`a`,{href:r.compareUrl,target:`_blank`,rel:`noreferrer`,children:[`Open `,r.pushedBranch??`the branch`,` to merge`]}):(0,E.jsxs)(`p`,{className:`note`,children:[`Merge `,(0,E.jsx)(`span`,{className:`mono`,children:r?.pushedBranch??`the delivery branch`}),`, then refresh.`]})}):(0,E.jsx)(`div`,{className:`factory-sheet`,children:i(`publish`,`Publish`)})}var bt=e=>`outcome-${e}`;function Z(){let e=u(),t=(t,n=!1)=>void e({to:`/factory`,search:e=>({...e,outcome:t}),replace:n,resetScroll:!1});return{open:e=>t(e),step:e=>t(e,!0),close:()=>t(void 0)}}function Q({item:e,context:t,lead:n,progress:r=!0,trailing:i}){let{workset:a,run:o}=e,s=G(a,o),c=s.at??(o?.updatedAt||a.queuedAt),l=Z();return(0,E.jsxs)(`li`,{className:`outcome-row-item`,"data-workset":a.id,children:[(0,E.jsxs)(`button`,{type:`button`,className:`outcome-row`,"data-outcome-row":``,onClick:()=>{j.getState().setStepped(!1),l.open(a.id)},children:[(0,E.jsx)(Xe,{activity:q(a,o)}),(0,E.jsx)(`span`,{className:`outcome-row-title`,children:a.title}),(0,E.jsx)(`span`,{className:`outcome-row-where`,children:n??s.text}),(0,E.jsx)(`span`,{className:`outcome-row-progress`,children:r?(0,E.jsx)(Qe,{workset:a}):null}),(0,E.jsx)(`span`,{className:`outcome-row-age mono`,children:c?P(c,t.now):``})]}),i]})}function $({label:e,section:t,count:n,children:r}){return(0,E.jsxs)(`section`,{className:`outcome-list-section`,"data-section":t,"aria-label":e,children:[(0,E.jsxs)(`h3`,{children:[e,` `,(0,E.jsx)(`span`,{className:`outcome-list-count mono`,children:n})]}),(0,E.jsx)(`ul`,{className:`outcome-list`,children:r})]})}var xt=(e,t)=>e.replace(/\.$/,``).toLowerCase()===t.replace(/\.$/,``).toLowerCase();function St({to:e,label:t,keyName:n}){let r=Z();return(0,E.jsxs)(`button`,{type:`button`,className:`outcome-step`,"data-outcome-goto":e?bt(e):void 0,disabled:!e,"aria-keyshortcuts":n,onClick:()=>{e&&(j.getState().setStepped(!0),r.step(e))},children:[t,` `,(0,E.jsx)(`kbd`,{children:n})]})}function Ct({item:e,kind:t,context:n}){return(0,E.jsxs)(`section`,{className:`outcome-dialog-attention`,"data-kind":t,"aria-label":`Needs you`,children:[(0,E.jsx)(`h3`,{children:J(t,e.run)}),Ge[t]?(0,E.jsx)(`p`,{className:`outcome-attention-hint`,children:Ge[t]}):null,(0,E.jsx)(yt,{item:e,kind:t,context:n})]})}function wt({item:e,situation:t}){let{workset:n,run:r}=e,i=Re(n,r);return(0,E.jsxs)(`section`,{className:`outcome-dialog-status`,"aria-label":`Where it is`,children:[(0,E.jsx)(`p`,{className:`outcome-situation`,children:t.text}),xt(i,t.text)?null:(0,E.jsxs)(`p`,{className:`outcome-next`,children:[(0,E.jsx)(`span`,{className:`muted`,children:`Next`}),` `,i]}),(0,E.jsx)($e,{checks:t.checks}),(0,E.jsx)(et,{item:e}),n.problems.length>0?(0,E.jsx)(`ul`,{className:`factory-problems`,children:n.problems.map(e=>(0,E.jsx)(`li`,{children:e},e))}):null]})}function Tt({run:e,now:t}){return e?.situations?.length?(0,E.jsxs)(`section`,{className:`outcome-history-section`,"aria-label":`What happened`,children:[(0,E.jsx)(`h3`,{children:`What happened`}),(0,E.jsx)(`ol`,{className:`outcome-history`,children:e.situations.map(e=>(0,E.jsxs)(`li`,{children:[(0,E.jsx)(`span`,{className:`factory-age mono`,children:P(e.at,t)}),(0,E.jsx)(`span`,{children:e.text})]},e.at))})]}):null}function Et({item:e,kind:t,context:n,place:r}){let{workset:i,run:a}=e,o=G(i,a),s=q(i,a),c=a?.state===`running`?a.startedAt:a?.updatedAt||o.at,l=bt(i.id),u={current:Ue(i),activity:s,note:pt(e,s,n.now)},d=pe(Z().close,e=>{e.showModal(),e.querySelector(`.outcome-dialog-close`)?.focus()});return(0,E.jsxs)(`dialog`,{ref:d,id:l,className:`outcome-dialog`,"data-workset":i.id,"data-layout":t===`control`?`control`:void 0,"aria-labelledby":`${l}-title`,children:[(0,E.jsxs)(`header`,{className:`outcome-dialog-head`,children:[(0,E.jsxs)(`div`,{className:`outcome-dialog-heading`,children:[(0,E.jsx)(`h2`,{id:`${l}-title`,children:i.title}),(0,E.jsxs)(`p`,{className:`outcome-dialog-state`,children:[(0,E.jsx)(Xe,{activity:s}),K[s],c?(0,E.jsxs)(`span`,{className:`factory-age mono`,children:[`· `,P(c,n.now)]}):null]})]}),(0,E.jsxs)(`nav`,{className:`outcome-dialog-steps`,"aria-label":`Other outcomes`,children:[(0,E.jsxs)(`span`,{className:`outcome-dialog-place mono`,children:[r.index+1,` of `,r.total]}),(0,E.jsx)(St,{to:r.prev,label:`Previous`,keyName:`K`}),(0,E.jsx)(St,{to:r.next,label:`Next`,keyName:`J`})]}),(0,E.jsx)(`form`,{method:`dialog`,children:(0,E.jsxs)(`button`,{type:`submit`,className:`outcome-dialog-close`,"aria-keyshortcuts":`Escape`,children:[`Close `,(0,E.jsx)(`kbd`,{children:`Esc`})]})})]}),(0,E.jsxs)(`div`,{className:`outcome-dialog-body`,children:[(0,E.jsxs)(`div`,{className:`outcome-dialog-main`,children:[t?(0,E.jsx)(Ct,{item:e,kind:t,context:n}):null,(0,E.jsx)(ct,{run:a,now:n.now}),(0,E.jsx)(it,{item:e}),(0,E.jsx)(wt,{item:e,situation:o}),(0,E.jsx)(dt,{item:e,context:n}),(0,E.jsx)(st,{item:e,context:n}),(0,E.jsx)(Tt,{run:a,now:n.now}),i.intent?(0,E.jsxs)(`section`,{className:`outcome-intent-section`,"aria-label":`Request`,children:[(0,E.jsx)(`h3`,{children:`Request`}),(0,E.jsx)(`p`,{className:`outcome-intent`,children:i.intent})]}):null,t===`review`?null:(0,E.jsx)(nt,{item:e,context:n})]}),(0,E.jsxs)(`aside`,{className:`outcome-dialog-rail`,"aria-label":`Delivery Path`,children:[t===`control`?null:(0,E.jsx)(y,{path:n.path,progress:u,label:`Where it is on the Delivery Path`}),(0,E.jsx)(ft,{item:e,context:n})]})]})]})}function Dt({items:e,context:t,expanded:n}){if(e.length===0)return null;let r=n?[]:e.slice(qe),i=e=>(0,E.jsx)(Q,{item:e,context:t,progress:!1},e.workset.id);return(0,E.jsxs)($,{label:`Done`,section:`completed`,count:e.length,children:[(n?e:e.slice(0,qe)).map(i),r.length>0?(0,E.jsx)(`li`,{children:(0,E.jsxs)(`details`,{className:`outcome-list-more`,children:[(0,E.jsxs)(`summary`,{children:[`Show all `,e.length]}),(0,E.jsx)(`ul`,{className:`outcome-list`,children:r.map(i)})]})}):null]})}function Ot(){return(0,E.jsxs)(`section`,{className:`factory-first-run`,"aria-label":`How the factory works`,children:[(0,E.jsx)(`h3`,{children:`How an outcome gets delivered`}),(0,E.jsxs)(`ol`,{children:[(0,E.jsx)(`li`,{children:`Describe what you want built or improved, and start it.`}),(0,E.jsx)(`li`,{children:`The factory clarifies and explores; answer its questions as they come up.`}),(0,E.jsx)(`li`,{children:`It writes a plan. Review it, then approve or request a change.`}),(0,E.jsx)(`li`,{children:`It builds the plan on a delivery branch. Merge the branch, then publish.`})]}),(0,E.jsx)(`p`,{className:`note`,children:`Everything that needs you shows under Needs you. Open an outcome to follow its log or take control of its conversation.`})]})}function kt(e){let t=j(e=>e.filter).trim(),n=new Map(e.attention.map(e=>[e.workset.id,e.kind])),r=e.active.filter(e=>!n.has(e.workset.id)),i=e=>{if(!t)return!0;let r=n.get(e.workset.id),i=r?J(r,e.run):``;return ye(`${e.workset.title} ${G(e.workset,e.run).text} ${i}`,t)},a=e.attention.filter(i),o=r.filter(i),s=e.later.filter(i),c=e.completed.filter(i);return{kinds:n,query:t,ordered:[...e.attention,...r,...e.later,...e.completed],attention:a,running:{all:r,shown:o},later:s,completed:c,shownCount:a.length+o.length+s.length+c.length}}function At({label:e}){let t=j(e=>e.setAgentsOpen);return(0,E.jsx)(`button`,{type:`button`,"data-open-agents":``,onClick:()=>t(!0),children:e})}function jt({count:e,worksets:t,writable:n,factoryMode:r}){let i=j(e=>e.filter),a=j(e=>e.setFilter),o=De();return(0,E.jsxs)(`div`,{className:`view-intro`,"data-factory-live":``,"data-needs-you":e,children:[t>0?(0,E.jsx)(`input`,{type:`search`,className:`outcome-filter`,"data-outcome-filter":``,placeholder:`Filter outcomes`,"aria-label":`Filter outcomes`,"aria-keyshortcuts":`/`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(a(``),e.currentTarget.blur())}}):null,(0,E.jsxs)(`p`,{className:`factory-keys`,children:[n?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`kbd`,{children:`N`}),` new`]}):null,t>0?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`kbd`,{children:`/`}),` filter`]}):null,(0,E.jsx)(`kbd`,{children:`J`}),(0,E.jsx)(`kbd`,{children:`K`}),` move `,(0,E.jsx)(`kbd`,{children:`↵`}),` open `,(0,E.jsx)(`kbd`,{children:`1`}),`–`,(0,E.jsx)(`kbd`,{children:`9`}),` answer`]}),(0,E.jsx)(`button`,{type:`button`,"data-factory-notify":``,hidden:!o.offered,onClick:o.ask,children:`Notify me about decisions`}),r&&n?(0,E.jsx)(At,{label:`Agents`}):null]})}function Mt({payload:e,companionDigest:t,writable:n,sessions:r=null,runs:i=null,now:a,openId:o,factoryMode:s=!1}){let c=Ie(e.worksets,i),l={companionDigest:t,writable:n,sessions:r,runner:i!==null,now:a,path:ee({topology:e.topology}).paths[0]},{kinds:u,ordered:d,attention:f,running:p,later:m,completed:h,shownCount:g,query:_}=kt(c),y=o?d.findIndex(e=>e.workset.id===o):-1,te=p.all.length===0&&c.attention.length===0;Te(),Ee(c.attention.length);let b=y>=0?{item:d[y],index:y}:null,x=j(e=>e.agentsOpen),S=j(e=>e.setAgentsOpen);return(0,E.jsx)(fe.Provider,{value:t,children:(0,E.jsxs)(`section`,{className:`view-section factory-home`,"aria-label":`Factory`,children:[(0,E.jsx)(jt,{count:c.attention.length,worksets:e.worksets.length,writable:n,factoryMode:s}),(0,E.jsx)(Ze,{repositories:e.linkedRepositories,context:l}),f.length>0?(0,E.jsx)($,{label:`Needs you`,section:`attention`,count:f.length,children:f.map(e=>(0,E.jsx)(Q,{item:e,context:l,lead:(0,E.jsx)(`span`,{className:`attention-kind`,"data-kind":e.kind,children:J(e.kind,e.run)})},e.workset.id))}):null,p.shown.length>0?(0,E.jsx)($,{label:`Running`,section:`active`,count:p.shown.length,children:p.shown.map(e=>(0,E.jsx)(Q,{item:e,context:l},e.workset.id))}):null,e.worksets.length===0?(0,E.jsx)(Ot,{}):te?(0,E.jsx)(`p`,{className:`note`,children:`The factory is idle. Describe an outcome to get it started.`}):null,(0,E.jsx)(`p`,{className:`note outcome-filter-empty`,"data-outcome-filter-empty":``,hidden:!_||g>0,children:`No outcomes match the filter.`}),m.length>0?(0,E.jsx)($,{label:`Later`,section:`later`,count:m.length,children:m.map(e=>(0,E.jsx)(Q,{item:e,context:l,progress:!1,trailing:Y(e,l)(`start`,`Start`)},e.workset.id))}):null,(0,E.jsx)(Dt,{items:h,context:l,expanded:!!_}),b?(0,E.jsx)(Et,{item:b.item,kind:u.get(b.item.workset.id)??null,context:l,place:{index:b.index,total:d.length,prev:d[b.index-1]?.workset.id,next:d[b.index+1]?.workset.id}},b.item.workset.id):null,e.worksetProblems.length>0?(0,E.jsx)(v,{warnings:e.worksetProblems.map(e=>`${e.path} ${e.reason}`)}):null,(0,E.jsx)(v,{warnings:e.warnings}),s&&n&&x?(0,E.jsx)(ve,{onClose:()=>S(!1)}):null]})})}function Nt(){let{companion:e,outcome:t}=ne.useSearch(),n=u();return(0,T.useEffect)(()=>{let e=/^#outcome-([a-z0-9][a-z0-9-]*)$/.exec(window.location.hash)?.[1];e&&!t&&n({to:`/factory`,search:t=>({...t,outcome:e}),hash:``,replace:!0})},[n,t]),e?(0,E.jsx)(Pt,{companion:e,outcome:t}):null}function Pt({companion:e,outcome:n}){let{data:r}=t(h(e));return r.payload?(0,E.jsx)(Mt,{payload:r.payload,companionDigest:e,writable:r.writable,factoryMode:r.factoryMode,sessions:r.sessions,runs:r.runs,now:r.renderedAt,openId:n}):(0,E.jsx)(`section`,{className:`panel`,children:(0,E.jsx)(`p`,{className:`empty`,children:r.error??`No state collected for this companion.`})})}export{Nt as component};