@uniqbit/mate-core 1.0.0-canary.5 → 1.0.0-canary.7

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 (477) 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 +41 -1
  4. package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
  5. package/claude-plugin/hooks/workflow-turn.mjs +68 -0
  6. package/opencode-plugin/src/companion.ts +6 -0
  7. package/opencode-plugin/src/server.ts +33 -2
  8. package/package.json +5 -2
  9. package/src/cli/commands/artifact/apply-context.ts +1 -0
  10. package/src/cli/commands/artifact/artifact.ts +16 -0
  11. package/src/cli/commands/artifact/delivery/archive.ts +37 -112
  12. package/src/cli/commands/artifact/delivery/branch-flags.ts +19 -1
  13. package/src/cli/commands/artifact/delivery/environment.ts +32 -72
  14. package/src/cli/commands/artifact/delivery/link.ts +53 -34
  15. package/src/cli/commands/artifact/delivery/output.ts +25 -4
  16. package/src/cli/commands/artifact/delivery/resolve.ts +101 -0
  17. package/src/cli/commands/artifact/delivery/submit.ts +164 -0
  18. package/src/cli/commands/artifact/delivery/take.ts +45 -0
  19. package/src/cli/commands/artifact/extract-repo-name.ts +1 -1
  20. package/src/cli/commands/artifact/finish/command.ts +455 -43
  21. package/src/cli/commands/artifact/finish/engine.ts +79 -61
  22. package/src/cli/commands/artifact/finish/finisher.ts +5 -12
  23. package/src/cli/commands/artifact/finish/git.ts +9 -10
  24. package/src/cli/commands/artifact/finish/openspec.ts +21 -174
  25. package/src/cli/commands/artifact/finish/secret-scan.ts +5 -43
  26. package/src/cli/commands/artifact/finish/worktree-cleanup.ts +57 -7
  27. package/src/cli/commands/artifact/pending/command.ts +119 -6
  28. package/src/cli/commands/artifact/pending/discovery.ts +7 -11
  29. package/src/cli/commands/artifact/project/command.ts +60 -0
  30. package/src/cli/commands/companion/list.ts +70 -14
  31. package/src/cli/commands/companion/sync.ts +18 -0
  32. package/src/cli/commands/companion/update.ts +4 -19
  33. package/src/cli/commands/doctor.ts +51 -0
  34. package/src/cli/commands/friction.ts +558 -0
  35. package/src/cli/commands/install.ts +48 -36
  36. package/src/cli/commands/launch/claude.ts +2 -0
  37. package/src/cli/commands/launch/shared.ts +33 -6
  38. package/src/cli/commands/plugin/install.ts +27 -11
  39. package/src/cli/commands/report/index.ts +180 -184
  40. package/src/cli/commands/report/markdown.ts +67 -72
  41. package/src/cli/commands/shared/companion-selection.ts +3 -1
  42. package/src/cli/commands/studio/access.ts +6 -14
  43. package/src/cli/commands/studio/areas.ts +112 -33
  44. package/src/cli/commands/studio/companion-add.ts +72 -0
  45. package/src/cli/commands/studio/companion-removal.ts +15 -8
  46. package/src/cli/commands/studio/connection.ts +53 -0
  47. package/src/cli/commands/studio/graph-model.ts +61 -0
  48. package/src/cli/commands/studio/graph.ts +336 -0
  49. package/src/cli/commands/studio/index.ts +4 -4
  50. package/src/{lib/factory/outcomes/sessions.ts → cli/commands/studio/live-sessions.ts} +26 -2
  51. package/src/cli/commands/studio/payload.ts +214 -32
  52. package/src/cli/commands/studio/reports.ts +19 -18
  53. package/src/cli/commands/studio/routes.ts +8 -18
  54. package/src/cli/commands/studio/selection.ts +21 -5
  55. package/src/cli/commands/studio/server.ts +322 -191
  56. package/src/cli/commands/studio/service-host.ts +266 -0
  57. package/src/cli/commands/studio/services.ts +59 -16
  58. package/src/cli/commands/studio/studio-app.ts +1 -0
  59. package/src/cli/commands/studio/terminal.ts +45 -3
  60. package/src/cli/commands/studio/vault.ts +41 -40
  61. package/src/cli/commands/studio/views/model.ts +1 -9
  62. package/src/cli/commands/studio/views/vault/markdown-tree.ts +90 -8
  63. package/src/cli/commands/triage.ts +151 -0
  64. package/src/cli/commands/unwrap.ts +3 -0
  65. package/src/cli/commands/update.ts +2 -0
  66. package/src/cli/commands/vscode/release-vsix.json +4 -0
  67. package/src/cli/commands/vscode/setup.ts +71 -13
  68. package/src/cli/commands/vscode/vsix.ts +48 -7
  69. package/src/cli/commands/workflow/workflow.ts +516 -0
  70. package/src/cli/commands/working/cleanup.ts +40 -8
  71. package/src/cli/commands/working/worktree.ts +176 -35
  72. package/src/cli/main.ts +61 -10
  73. package/src/cli/plugin-commands.ts +6 -1
  74. package/src/cli/repo-list-table.tsx +73 -37
  75. package/src/cli/usage.ts +29 -8
  76. package/src/create-mate.ts +11 -5
  77. package/src/distribution.ts +2 -0
  78. package/src/factory-host.ts +69 -0
  79. package/src/hooks/companion-instructions.ts +19 -8
  80. package/src/hooks/hook-io.ts +3 -1
  81. package/src/hooks/rtk-worktree-git.ts +48 -0
  82. package/src/hooks/session-banner.ts +25 -0
  83. package/src/hooks/validate-artifact-path.ts +108 -26
  84. package/src/hooks/workflow-turn.ts +219 -0
  85. package/src/lib/apply-context/fingerprint.ts +2 -1
  86. package/src/lib/apply-context/protocol.ts +2 -2
  87. package/src/lib/artifact-trailer.ts +27 -0
  88. package/src/lib/change-layout.ts +83 -38
  89. package/src/lib/delivery/branch-template.ts +114 -0
  90. package/src/lib/delivery/branches.ts +21 -16
  91. package/src/lib/delivery/checkout.ts +103 -0
  92. package/src/lib/delivery/environment.ts +131 -7
  93. package/src/lib/delivery/merge-git.ts +282 -26
  94. package/src/lib/delivery/overlap.ts +68 -16
  95. package/src/lib/delivery/record-delivery.ts +178 -37
  96. package/src/lib/delivery/record.ts +201 -27
  97. package/src/lib/delivery/refresh.ts +212 -151
  98. package/src/lib/delivery/remote.ts +66 -0
  99. package/src/lib/delivery/repository-access.ts +19 -60
  100. package/src/lib/delivery/resolve-branch.ts +157 -110
  101. package/src/lib/delivery/stages.ts +83 -50
  102. package/src/lib/delivery/staging/apply-chain.ts +164 -0
  103. package/src/lib/delivery/staging/artifact-type.ts +101 -0
  104. package/src/lib/delivery/staging/declared-type.ts +277 -0
  105. package/src/lib/delivery/staging/naming.ts +64 -0
  106. package/src/lib/delivery/staging/openspec-type.ts +135 -0
  107. package/src/lib/delivery/staging/pending-edit.ts +291 -0
  108. package/src/lib/delivery/staging/pending.ts +780 -0
  109. package/src/lib/delivery/staging/project.ts +373 -0
  110. package/src/lib/delivery/staging/publish.ts +1024 -0
  111. package/src/lib/delivery/staging/refs.ts +258 -0
  112. package/src/lib/delivery/staging/registry.ts +73 -0
  113. package/src/lib/delivery/staging/replay.ts +308 -0
  114. package/src/lib/delivery/staging/requirement-blocks.ts +10 -0
  115. package/src/lib/delivery/staging/resolve.ts +264 -0
  116. package/src/lib/delivery/staging/settle-linked.ts +290 -0
  117. package/src/lib/delivery/staging/submit.ts +929 -0
  118. package/src/lib/delivery/staging/worktree.ts +130 -0
  119. package/src/lib/delivery/submit-change.ts +443 -0
  120. package/src/lib/friction/describe.ts +42 -0
  121. package/src/lib/friction/fields.ts +60 -0
  122. package/src/lib/friction/mark.ts +156 -0
  123. package/src/lib/friction/view/model.ts +67 -0
  124. package/src/lib/friction/view/read.ts +136 -0
  125. package/src/lib/friction/view/select.ts +54 -0
  126. package/src/lib/git-key.ts +15 -0
  127. package/src/lib/install.ts +2 -0
  128. package/src/lib/openspec-canonical-frontmatter.ts +159 -0
  129. package/src/lib/orchestrator/adapters/base.ts +31 -20
  130. package/src/lib/orchestrator/adapters/claude.ts +21 -7
  131. package/src/lib/orchestrator/adapters/opencode.ts +4 -0
  132. package/src/lib/orchestrator/companion-git-sync.ts +152 -16
  133. package/src/lib/orchestrator/companion-hub.ts +6 -1
  134. package/src/lib/orchestrator/engine-floor.ts +48 -0
  135. package/src/lib/orchestrator/framework-context.ts +15 -1
  136. package/src/lib/orchestrator/launcher.ts +34 -1
  137. package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
  138. package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
  139. package/src/lib/orchestrator/projection-claude-links.ts +33 -8
  140. package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
  141. package/src/lib/orchestrator/projection-entries.ts +22 -18
  142. package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
  143. package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
  144. package/src/lib/orchestrator/projection-types.ts +28 -1
  145. package/src/lib/orchestrator/refresh-working-claude-links.ts +4 -1
  146. package/src/lib/orchestrator/root-context.ts +23 -6
  147. package/src/lib/orchestrator/session-prepare.ts +17 -2
  148. package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
  149. package/src/lib/orchestrator/types.ts +4 -0
  150. package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
  151. package/src/lib/orchestrator/working-repo-projection.ts +24 -4
  152. package/src/lib/orchestrator/wrap-pass.ts +1 -0
  153. package/src/lib/package-paths.ts +23 -15
  154. package/src/lib/prebuilt-workspace-prepare.ts +2 -1
  155. package/src/lib/prebuilt-workspace.ts +1 -0
  156. package/src/lib/public-npm.ts +95 -50
  157. package/src/lib/session-attribution.ts +3 -7
  158. package/src/lib/session-state.ts +74 -3
  159. package/src/lib/triage/context.ts +186 -0
  160. package/src/lib/triage/launch.ts +52 -0
  161. package/src/lib/triage/prepare.ts +97 -0
  162. package/src/lib/triage/session.ts +126 -0
  163. package/src/lib/update-checker.ts +7 -1
  164. package/src/lib/usage/aggregate.ts +202 -0
  165. package/src/lib/usage/cache.ts +87 -0
  166. package/src/lib/usage/claude-pricing.ts +71 -0
  167. package/src/lib/usage/claude.ts +189 -0
  168. package/src/lib/usage/collect.ts +56 -0
  169. package/src/lib/usage/opencode.ts +188 -0
  170. package/src/lib/usage/records.ts +80 -0
  171. package/src/lib/usage/rtk-database.ts +72 -0
  172. package/src/lib/usage/savings.ts +209 -0
  173. package/src/lib/usage/scope.ts +182 -0
  174. package/src/lib/usage/source.ts +102 -0
  175. package/src/lib/usage/types.ts +143 -0
  176. package/src/lib/usage/window.ts +37 -0
  177. package/src/lib/workflow/declaration.ts +6 -0
  178. package/src/lib/workflow/handoff.ts +90 -0
  179. package/src/lib/workflow/hook-trust.ts +108 -0
  180. package/src/lib/workflow/position.ts +524 -0
  181. package/src/lib/workflow/report.ts +79 -0
  182. package/src/lib/workflow/work.ts +106 -0
  183. package/src/lib/workset/factory-local.ts +157 -0
  184. package/src/lib/workset/record.ts +25 -11
  185. package/src/lib/workset/repositories.ts +118 -25
  186. package/src/lib/workset/stage.ts +4 -2
  187. package/src/lib/workset/stages.ts +64 -4
  188. package/src/lib/workset/worktree-include.ts +161 -0
  189. package/src/lib/workset/worktree-index.ts +6 -2
  190. package/src/lib/workset/worktree.ts +622 -114
  191. package/src/opencode/companion-hooks.ts +105 -18
  192. package/src/opencode/companion-policy.ts +18 -5
  193. package/src/opencode/enter-worktree.ts +254 -6
  194. package/src/opencode/projected-guidance.ts +7 -2
  195. package/src/opencode/session-register.ts +2 -2
  196. package/src/opencode/turn-hook.ts +241 -0
  197. package/src/playbooks/companion-guidance.ts +7 -4
  198. package/src/plugin-api.ts +47 -0
  199. package/src/runtime/artifact-trailers.ts +63 -0
  200. package/src/runtime/claude-bg-isolation.ts +138 -0
  201. package/src/runtime/claude-hook-group.ts +2 -0
  202. package/src/runtime/command-friction.ts +97 -0
  203. package/src/runtime/companion-git-state.ts +155 -10
  204. package/src/runtime/companion-git.ts +96 -13
  205. package/src/runtime/companion-guidance.ts +136 -20
  206. package/src/runtime/companion-instructions.ts +1 -1
  207. package/src/runtime/companion-sync.ts +109 -21
  208. package/src/runtime/current-branch.ts +16 -2
  209. package/src/runtime/entered-worktree.ts +24 -0
  210. package/src/runtime/env-names.ts +2 -2
  211. package/src/runtime/env.ts +7 -6
  212. package/src/runtime/forge-remote.ts +48 -0
  213. package/src/runtime/friction-fingerprint.ts +35 -0
  214. package/src/runtime/friction-log.ts +352 -0
  215. package/src/runtime/friction-recorder.ts +199 -0
  216. package/src/runtime/friction-retention.ts +1 -0
  217. package/src/runtime/friction-state.ts +110 -0
  218. package/src/runtime/friction-switch.ts +26 -0
  219. package/src/runtime/friction-vocabulary.ts +42 -0
  220. package/src/runtime/git-layout.ts +21 -7
  221. package/src/runtime/git-tracked.ts +60 -0
  222. package/src/runtime/json-fields.ts +8 -0
  223. package/src/runtime/pending-records.ts +533 -0
  224. package/src/runtime/projected-guidance.ts +8 -3
  225. package/src/runtime/publication-secret-scan.ts +45 -0
  226. package/src/runtime/repo-destination.ts +72 -0
  227. package/src/runtime/repo-local.ts +25 -3
  228. package/src/runtime/rtk-git-guard.ts +66 -0
  229. package/src/runtime/runtime-document-manifest.ts +229 -19
  230. package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
  231. package/src/runtime/secret-guard.ts +9 -2
  232. package/src/runtime/secret-patterns.ts +3 -2
  233. package/src/runtime/secret-policy-weakening.ts +122 -0
  234. package/src/runtime/secret-values.ts +16 -0
  235. package/src/runtime/serving-claude-wrap.ts +15 -2
  236. package/src/runtime/session-id.ts +24 -0
  237. package/src/runtime/session-prepare-runner.ts +3 -0
  238. package/src/runtime/skill-prefix.ts +75 -0
  239. package/src/runtime/submitted-arrivals.ts +547 -0
  240. package/src/runtime/turn-state.d.mts +14 -0
  241. package/src/runtime/turn-state.mjs +93 -0
  242. package/src/runtime/umbrella-children.ts +52 -0
  243. package/src/runtime/umbrella-folder.ts +84 -0
  244. package/src/runtime/workflow/change-folders.ts +66 -0
  245. package/src/runtime/workflow/declaration.ts +720 -0
  246. package/src/runtime/workflow/globs.ts +85 -0
  247. package/src/runtime/workflow/next-handoff-process.ts +99 -0
  248. package/src/runtime/workflow/turn.ts +309 -0
  249. package/src/runtime/workflow/workflow.ts +262 -0
  250. package/src/runtime/wrap-state.ts +5 -13
  251. package/src/studio.ts +112 -19
  252. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/schema.yaml +3 -3
  253. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/design.md +1 -1
  254. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/proposal.md +1 -1
  255. package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/tasks.md +1 -1
  256. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +3 -3
  257. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +103 -30
  258. package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +1 -1
  259. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +7 -70
  260. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +13 -7
  261. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +10 -0
  262. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +46 -14
  263. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +50 -31
  264. package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +13 -7
  265. package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +1 -1
  266. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +114 -86
  267. package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +111 -100
  268. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +11 -5
  269. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +16 -6
  270. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +114 -0
  271. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +103 -30
  272. package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +1 -1
  273. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +7 -70
  274. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +13 -7
  275. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +10 -0
  276. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +46 -14
  277. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +50 -31
  278. package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +13 -7
  279. package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +1 -1
  280. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +114 -86
  281. package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +111 -100
  282. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +11 -5
  283. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +16 -6
  284. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +114 -0
  285. package/src/templates/mate-skills/openspec-references.ts +3 -2
  286. package/src/templates/triage/PLAYBOOK.md +112 -0
  287. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +912 -139
  288. package/src/tools/setup/capabilities/openspec.ts +54 -15
  289. package/src/tools/setup/capabilities/rtk.ts +113 -9
  290. package/src/tools/setup/capabilities/tokensave.ts +3 -2
  291. package/src/tools/setup/dynamic-plugins/api.ts +38 -0
  292. package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
  293. package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
  294. package/src/tools/setup/dynamic-plugins/host.ts +2 -32
  295. package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
  296. package/src/tools/setup/dynamic-plugins/install.ts +24 -22
  297. package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
  298. package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
  299. package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
  300. package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
  301. package/src/tools/setup/engine.ts +20 -1
  302. package/src/tools/setup/mate.ts +5 -3
  303. package/src/tools/setup/package-managers/bun.ts +8 -8
  304. package/src/tools/setup/plugin.ts +14 -1
  305. package/src/tools/setup/plugins/gitignore.ts +15 -9
  306. package/src/tools/setup/plugins/guidance.ts +4 -2
  307. package/src/tools/setup/providers/claude-plugin-hooks.ts +30 -0
  308. package/src/tools/setup/providers/claude.ts +43 -6
  309. package/src/tools/setup/service-registry.ts +69 -0
  310. package/src/tools/setup/service.ts +237 -0
  311. package/src/tools/setup/utils.ts +28 -5
  312. package/src/tools/setup/working-repo-cleanup.ts +2 -2
  313. package/src/tools/setup/working-repo-local-state.ts +2 -0
  314. package/src/tools/setup.ts +41 -16
  315. package/studio-dist/client/assets/app-aIwDxf48.css +2 -0
  316. package/studio-dist/client/assets/button-CX0sWAJl.js +1 -0
  317. package/studio-dist/client/assets/combobox-BmA8RjOc.js +1 -0
  318. package/studio-dist/client/assets/companion-view-DINdPF-b.js +1 -0
  319. package/studio-dist/client/assets/fields-BobQ7zRF.js +1 -0
  320. package/studio-dist/client/assets/friction-YdYd3zaz.js +1 -0
  321. package/studio-dist/client/assets/getting-started-CY7NEtTw.js +1 -0
  322. package/studio-dist/client/assets/getting-started-djaQeWlu.js +1 -0
  323. package/studio-dist/client/assets/getting-started._topic-DVB8e5R9.js +1 -0
  324. package/studio-dist/client/assets/getting-started.index-DQvLHEr1.js +1 -0
  325. package/studio-dist/client/assets/graph-DbNnR884.js +2 -0
  326. package/studio-dist/client/assets/graph-canvas-DIcAqwtK.js +3242 -0
  327. package/studio-dist/client/assets/guides-D6T6W_jV.js +1 -0
  328. package/studio-dist/client/assets/index-CysBCSxM.js +40 -0
  329. package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
  330. package/studio-dist/client/assets/markdown-view-jMiaBTSO.js +1 -0
  331. package/studio-dist/client/assets/panel-Csr49lBo.js +1 -0
  332. package/studio-dist/client/assets/plugins._service._view-CEA_CcPe.js +1 -0
  333. package/studio-dist/client/assets/{prepaint-CwSrpdFA.js → prepaint-CKsXyJOR.js} +3 -3
  334. package/studio-dist/client/assets/queries-Dfp5deWj.js +1 -0
  335. package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
  336. package/studio-dist/client/assets/reports-CLdgxxkg.js +1 -0
  337. package/studio-dist/client/assets/routes-DGilWbDE.js +1 -0
  338. package/studio-dist/client/assets/search-CXosfvYh.js +1 -0
  339. package/studio-dist/client/assets/select-DdebbX7K.js +1 -0
  340. package/studio-dist/client/assets/skills-C3zNkU8g.js +1 -0
  341. package/studio-dist/client/assets/specs-Dl8HfGlU.js +1 -0
  342. package/studio-dist/client/assets/specs-view-B_n0Pekv.js +1 -0
  343. package/studio-dist/client/assets/steps-CKUno4lh.js +1 -0
  344. package/studio-dist/client/assets/store-DyXbi6o9.js +1 -0
  345. package/studio-dist/client/assets/studio-0ueISxwP.js +100 -0
  346. package/studio-dist/client/assets/studio-queries-BflKt9va.js +2 -0
  347. package/studio-dist/client/assets/usage-Blcl8kA_.js +55 -0
  348. package/studio-dist/client/assets/useAnchoredPopupScrollLock-BBXJpX5L.js +1 -0
  349. package/studio-dist/client/assets/useBaseQuery-C2cjmeH2.js +1 -0
  350. package/studio-dist/client/assets/useMutation-DI6LbvVa.js +1 -0
  351. package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
  352. package/studio-dist/client/assets/vault-Cb9DmM1i.js +1 -0
  353. package/studio-dist/client/assets/warnings-B-rvoW8q.js +1 -0
  354. package/studio-dist/client/assets/workflow-DN5T19jd.js +1 -0
  355. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-JoHQ5ihx.js +122 -0
  356. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +100 -39
  357. package/studio-dist/server/assets/{button-CIJqAhni.js → button-B7e1fRyW.js} +63 -3574
  358. package/studio-dist/server/assets/combobox--S_OmUfh.js +483 -0
  359. package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-D-vGM55e.js} +3 -3
  360. package/studio-dist/server/assets/companions-Dr6IpNAb.js +31 -0
  361. package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
  362. package/studio-dist/server/assets/fields-B4qM2ZwC.js +1190 -0
  363. package/studio-dist/server/assets/friction-CWOTjpCV.js +62 -0
  364. package/studio-dist/server/assets/friction-sLxaWY-H.js +903 -0
  365. package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
  366. package/studio-dist/server/assets/getting-started-Cq5Pcnsr.js +67 -0
  367. package/studio-dist/server/assets/getting-started._topic-CmWdl3u3.js +13 -0
  368. package/studio-dist/server/assets/getting-started.index-AB8xpTFY.js +13 -0
  369. package/studio-dist/server/assets/graph-B11ITte0.js +16 -0
  370. package/studio-dist/server/assets/graph-C_Hn-Wf_.js +800 -0
  371. package/studio-dist/server/assets/graph-canvas-BthrSmPS.js +21066 -0
  372. package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
  373. package/studio-dist/server/assets/guides-B8HdeK_C.js +13 -0
  374. package/studio-dist/server/assets/guides-BVQ4pt5B.js +5 -0
  375. package/studio-dist/server/assets/guides.server-DqFQAStf.js +66 -0
  376. package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
  377. package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-rwiiVcPC.js} +28 -9
  378. package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-CUxRIpYL.js} +5 -5
  379. package/studio-dist/server/assets/plugins._service._view-BSvGnlhU.js +94 -0
  380. package/studio-dist/server/assets/{prepaint-DJfTQ_VH.js → prepaint-B28ClcPN.js} +1 -1
  381. package/studio-dist/server/assets/queries-S_Pl90IG.js +32 -0
  382. package/studio-dist/server/assets/{react-Ce6dj15C.js → react-CiBZPDs8.js} +3 -4
  383. package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
  384. package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-B9k98oE6.js} +3 -3
  385. package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CJpAItPk.js} +14 -10
  386. package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DF0etoNa.js} +1322 -3127
  387. package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-6ylCLkyg.js} +221 -76
  388. package/studio-dist/server/assets/search-b-yQesv3.js +78 -0
  389. package/studio-dist/server/assets/select-CjuKScan.js +1609 -0
  390. package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-DLkP7wG9.js} +15 -6
  391. package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-DGg0mWDM.js} +3 -3
  392. package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-zeU80A9S.js} +8 -8
  393. package/studio-dist/server/assets/specs-DDBNT_v1.js +51 -0
  394. package/studio-dist/server/assets/specs-view-exvmWdg0.js +425 -0
  395. package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D1tYAyWZ.js} +88 -45
  396. package/studio-dist/server/assets/store-kS7zk0Hr.js +93 -0
  397. package/studio-dist/server/assets/studio-qRvQjRpz.js +10482 -0
  398. package/studio-dist/server/assets/studio-queries-qOXOYoPt.js +1393 -0
  399. package/studio-dist/server/assets/usage-C2um7YiV.js +25553 -0
  400. package/studio-dist/server/assets/usage-Cwle9-xY.js +24 -0
  401. package/studio-dist/server/assets/useAnchoredPopupScrollLock-kQBB3y_b.js +756 -0
  402. package/studio-dist/server/assets/useBaseQuery--iH3rd-T.js +2051 -0
  403. package/studio-dist/server/assets/useMutation-C-WO6hCM.js +690 -0
  404. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
  405. package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-B8vgVIH9.js} +10 -7
  406. package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-CEBBRLMb.js} +3 -3
  407. package/studio-dist/server/assets/{views-BgYa-za2.js → views-UgO0Qz_g.js} +9 -6
  408. package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-BxK4VfV5.js} +2 -2
  409. package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-BrTK632u.js} +152 -120
  410. package/studio-dist/server/server.js +582 -8
  411. package/src/cli/commands/factory/factory.ts +0 -301
  412. package/src/cli/commands/report/collector.ts +0 -288
  413. package/src/cli/commands/studio/factory-credential.ts +0 -49
  414. package/src/cli/commands/studio/workset-session.ts +0 -131
  415. package/src/lib/delivery/archive-change.ts +0 -165
  416. package/src/lib/delivery/forge.ts +0 -279
  417. package/src/lib/delivery/token.ts +0 -24
  418. package/src/lib/factory/attach-client.ts +0 -113
  419. package/src/lib/factory/attach.ts +0 -178
  420. package/src/lib/factory/broker.ts +0 -190
  421. package/src/lib/factory/bun-commands.ts +0 -39
  422. package/src/lib/factory/client.ts +0 -92
  423. package/src/lib/factory/command.ts +0 -61
  424. package/src/lib/factory/credential-store.ts +0 -153
  425. package/src/lib/factory/frames.ts +0 -77
  426. package/src/lib/factory/ids.ts +0 -58
  427. package/src/lib/factory/outcomes/actions.ts +0 -114
  428. package/src/lib/factory/outcomes/index.ts +0 -391
  429. package/src/lib/factory/outcomes/lifecycle.ts +0 -205
  430. package/src/lib/factory/outcomes/runs.ts +0 -81
  431. package/src/lib/factory/prepare.ts +0 -49
  432. package/src/lib/factory/pty.ts +0 -103
  433. package/src/lib/factory/runner/companion-context.ts +0 -178
  434. package/src/lib/factory/runner/control.ts +0 -92
  435. package/src/lib/factory/runner/harness-agent.ts +0 -250
  436. package/src/lib/factory/runner/live.ts +0 -159
  437. package/src/lib/factory/runner/questions.ts +0 -22
  438. package/src/lib/factory/runner/rank.ts +0 -26
  439. package/src/lib/factory/runner/run-policy.ts +0 -12
  440. package/src/lib/factory/runner/run.ts +0 -199
  441. package/src/lib/factory/runner/scheduler.ts +0 -416
  442. package/src/lib/factory/runner/state.ts +0 -233
  443. package/src/lib/factory/runner/workflow.ts +0 -542
  444. package/src/lib/factory/runtime.ts +0 -981
  445. package/src/lib/factory/sandbox.ts +0 -292
  446. package/src/lib/factory/worktree-branch.ts +0 -17
  447. package/src/templates/capabilities/openspec-cap/mate-v1/templates/explore-brief.md +0 -25
  448. package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
  449. package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
  450. package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
  451. package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
  452. package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
  453. package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
  454. package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
  455. package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
  456. package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
  457. package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
  458. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
  459. package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
  460. package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
  461. package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
  462. package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
  463. package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
  464. package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
  465. package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
  466. package/studio-dist/server/assets/actions-Bvgj9eb8.js +0 -54
  467. package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
  468. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
  469. package/studio-dist/server/assets/factory-DGPmNGbo.js +0 -69
  470. package/studio-dist/server/assets/factory-DUTa0eDs.js +0 -2172
  471. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
  472. package/studio-dist/server/assets/search-JAKurDNh.js +0 -36
  473. package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
  474. package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
  475. package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
  476. /package/src/lib/{factory/keyed-serial.ts → keyed-serial.ts} +0 -0
  477. /package/src/templates/capabilities/openspec-cap/{mate-v1 → mate-full}/templates/spec.md +0 -0
@@ -0,0 +1,45 @@
1
+ import { isChangeName } from "../../../../lib/change-layout";
2
+ import { takeSubmitted, type TakeResult } from "../../../../lib/delivery/staging/submit";
3
+ import { type BooleanFlagSet, parseFlags, positionalArgs } from "../../../parse-flags";
4
+ import { resolveDeliveryEnvironment, type DeliveryEnvironmentDeps } from "./environment";
5
+ import { commandOutput } from "./output";
6
+
7
+ export interface TakeCommandDeps extends DeliveryEnvironmentDeps {
8
+ stdout?: (line: string) => void;
9
+ stderr?: (line: string) => void;
10
+ take?: typeof takeSubmitted;
11
+ }
12
+
13
+ const BOOLEAN_FLAGS: BooleanFlagSet = new Set(["json"]);
14
+
15
+ /**
16
+ * @command mate artifact take <change>
17
+ * @description Takes a submitted change into this checkout to revise it: fetches the pending
18
+ * branch and writes the change's folder as it is there to `openspec/changes/<change>/`,
19
+ * untracked, recorded as submitted from this checkout. `mate artifact submit <change>` then
20
+ * pushes the revised folder again. Nothing is pushed and the pending branch is not changed.
21
+ * @flags
22
+ * - `--json` — emit a {@link TakeResult}.
23
+ * @remarks Refused, exiting non-zero, when the checkout already holds a folder of that name or
24
+ * the change is not submitted on the pending branch.
25
+ */
26
+ export async function runArtifactTakeCommand(
27
+ argv: string[],
28
+ deps: TakeCommandDeps = {},
29
+ ): Promise<void> {
30
+ const { emitOut, refuse } = commandOutput(deps);
31
+ const flags = parseFlags(argv, BOOLEAN_FLAGS);
32
+ const [change, ...extra] = positionalArgs(argv, BOOLEAN_FLAGS);
33
+ if (!change || extra.length > 0 || !isChangeName(change)) {
34
+ return refuse("mate: artifact take requires one submitted change name.");
35
+ }
36
+ const environment = await resolveDeliveryEnvironment(deps);
37
+ if ("error" in environment) return refuse(environment.error);
38
+ const take = deps.take ?? takeSubmitted;
39
+ const { companionPath, artifactType } = environment;
40
+ const result: TakeResult = await (artifactType
41
+ ? take(companionPath, change, { artifactType })
42
+ : take(companionPath, change));
43
+ if (result.status === "refused") process.exitCode = 1;
44
+ emitOut(flags.json === true ? JSON.stringify(result) : result.message);
45
+ }
@@ -25,7 +25,7 @@ export function extractRepoName(url: string): string | null {
25
25
  repositoryPath = cleaned.replace(/^https?:\/\//i, "");
26
26
  }
27
27
 
28
- const lastPart = repositoryPath.split("/").filter(Boolean).at(-1);
28
+ const lastPart = repositoryPath.split("/").findLast(Boolean);
29
29
  if (!lastPart) {
30
30
  return null;
31
31
  }
@@ -1,4 +1,29 @@
1
+ import { ARTIFACT_TRAILER, archiveOfArtifact } from "../../../../lib/artifact-trailer";
2
+ import { changeNameOf, parseAnchor } from "../../../../lib/change-layout";
3
+ import {
4
+ recordDelivery,
5
+ type DeliveryEdit,
6
+ type RecordDeliveryDeps,
7
+ } from "../../../../lib/delivery/record-delivery";
8
+ import type { ArtifactType } from "../../../../lib/delivery/staging/artifact-type";
9
+ import { isDeliveryGroup } from "../../../../lib/delivery/staging/naming";
10
+ import { declaredSubmitType } from "../../../../lib/delivery/staging/registry";
11
+ import { errorMessage } from "../../../../runtime/error-message";
12
+ import { settleLinked } from "../../../../lib/delivery/staging/settle-linked";
13
+ import {
14
+ publicationQueue,
15
+ publishSubmitted,
16
+ type PublicationQueue,
17
+ type PublicationResult,
18
+ type PublishDeps,
19
+ } from "../../../../lib/delivery/staging/publish";
20
+ import { stagingRemote } from "../../../../lib/delivery/staging/refs";
1
21
  import { resolveForCapability } from "../../../../lib/orchestrator/framework-context";
22
+ import { companionGit, outputLines } from "../../../../runtime/companion-git";
23
+ import type { BranchOutcome } from "../../../../lib/delivery/refresh";
24
+ import { CONFIRM_FLAGS, confirmFlag } from "../delivery/branch-flags";
25
+ import { resolveDeliveryEnvironment, type DeliveryEnvironmentDeps } from "../delivery/environment";
26
+ import { renderOutcome } from "../delivery/output";
2
27
  import type { LaunchContext } from "../../../../lib/orchestrator/framework-context";
3
28
  import type { CapabilityConfig } from "../../../../lib/orchestrator/types";
4
29
  import { WorkingRepoRequiredError } from "../../../../lib/orchestrator/types";
@@ -35,12 +60,135 @@ export interface PublishCommandDeps {
35
60
  ) => Promise<PublicationSecretScan>;
36
61
  /** Injectable readers and prune for the cleanup after a Workset becomes Done. */
37
62
  worktreeCleanup?: WorktreeCleanupDeps;
63
+ /** Publishes a Delivery Group of submitted changes; see {@link publishSubmitted}. */
64
+ publishSubmitted?: (
65
+ companionPath: string,
66
+ target: string,
67
+ deps: PublishDeps,
68
+ ) => Promise<PublicationResult>;
69
+ /** True when the companion has an upstream a Delivery Group publishes to. */
70
+ hasRemote?: (companionPath: string) => Promise<boolean>;
71
+ /** True when an earlier publication of the target is committed on `HEAD` but not pushed. */
72
+ unpushedPublication?: (companionPath: string, target: string) => Promise<boolean>;
73
+ /** The Delivery Groups `--all` publishes; see {@link publicationQueue}. */
74
+ publicationQueue?: (companionPath: string) => Promise<PublicationQueue>;
75
+ /** Builds the delivery environment `--refresh` and `--confirm-*` settle with. */
76
+ deliveryEnvironment?: DeliveryEnvironmentDeps & RecordDeliveryDeps;
77
+ /** `--refresh`: records the merges linked checkouts settle first; see {@link settleLinked}. */
78
+ settleLinked?: typeof settleLinked;
38
79
  stdout?: (line: string) => void;
39
80
  stderr?: (line: string) => void;
40
81
  }
41
82
 
42
83
  /** Presence-only flags; every other `--flag` consumes the following token as its value. */
43
- const BOOLEAN_FLAGS: BooleanFlagSet = new Set(["no-push", "json", "specs", "all"]);
84
+ const BOOLEAN_FLAGS: BooleanFlagSet = new Set([
85
+ "no-push",
86
+ "json",
87
+ "specs",
88
+ "all",
89
+ "refresh",
90
+ ...CONFIRM_FLAGS,
91
+ ]);
92
+
93
+ async function defaultHasRemote(companionPath: string): Promise<boolean> {
94
+ return (await stagingRemote(companionGit(companionPath, { prompt: "never" }))) !== null;
95
+ }
96
+
97
+ /**
98
+ * An earlier publication of `target` committed on `HEAD` that never reached the upstream: a
99
+ * `--no-push` commit, or a tag an older Mate version created. It is pushed from the checkout.
100
+ */
101
+ export async function unpushedPublication(companionPath: string, target: string): Promise<boolean> {
102
+ const git = companionGit(companionPath, { prompt: "never" });
103
+ const upstream = (await git.upstreamTarget())?.ref;
104
+ if (!upstream) return false;
105
+ const log = await git.run([
106
+ "log",
107
+ `--format=%(trailers:key=${ARTIFACT_TRAILER},valueonly,separator=%x0a)`,
108
+ "--end-of-options",
109
+ `${upstream}..HEAD`,
110
+ ]);
111
+ const matches = (anchor: string): boolean =>
112
+ anchor === target || (parseAnchor(anchor) !== null && changeNameOf(anchor) === target);
113
+ const published = log.status === 0 ? outputLines(log.stdout).map(archiveOfArtifact) : [];
114
+ if (published.some((anchor) => anchor !== null && matches(anchor))) return true;
115
+ const tags = await git.run([
116
+ "for-each-ref",
117
+ "--format=%(refname:strip=3)",
118
+ "refs/tags/openspec/",
119
+ ]);
120
+ if (tags.status !== 0) return false;
121
+ for (const anchor of outputLines(tags.stdout).filter(matches)) {
122
+ const tag = `refs/tags/openspec/${anchor}`;
123
+ // A tag left on a commit a rebase replaced is not on HEAD, so it marks nothing to push.
124
+ // oxlint-disable-next-line no-await-in-loop -- one tag per archive of the change
125
+ const onHead = await git.run(["merge-base", "--is-ancestor", tag, "HEAD"]);
126
+ if (onHead.status !== 0) continue;
127
+ // oxlint-disable-next-line no-await-in-loop -- same tag
128
+ const reached = await git.run(["merge-base", "--is-ancestor", tag, upstream]);
129
+ if (reached.status === 1) return true;
130
+ }
131
+ return false;
132
+ }
133
+
134
+ /** A Delivery Group publication as the publish result the skill reads. */
135
+ function publicationResult(
136
+ type: string,
137
+ target: string,
138
+ publication: PublicationResult,
139
+ ): FinishResult {
140
+ const ok = publication.status === "ok";
141
+ return {
142
+ type,
143
+ name: target,
144
+ anchorName: publication.records[0] ?? null,
145
+ tag: null,
146
+ ...(publication.commit ? { commit: publication.commit } : {}),
147
+ ...(publication.group ? { group: publication.group } : {}),
148
+ changes: publication.changes,
149
+ anchors: publication.records,
150
+ ...(publication.reason ? { reason: publication.reason } : {}),
151
+ ...(publication.heldBy ? { heldBy: publication.heldBy } : {}),
152
+ ...(publication.merges ? { merges: publication.merges } : {}),
153
+ ...(publication.blocked ? { blocked: true } : {}),
154
+ ...(publication.conflict ? { conflict: publication.conflict } : {}),
155
+ ...(publication.dependencies
156
+ ? {
157
+ dependencies: publication.dependencies.map((dependency) =>
158
+ publicationResult(type, dependency.group ?? target, dependency),
159
+ ),
160
+ }
161
+ : {}),
162
+ resumed: publication.alreadyPublished === true,
163
+ step: ok ? "done" : publication.status === "held" ? "resolve" : "publish",
164
+ status: publication.status,
165
+ conflictedPaths: publication.conflictedPaths,
166
+ local: { committed: ok, tagged: false, pushed: ok },
167
+ message: publication.message,
168
+ ...(publication.secretFindings ? { secretFindings: publication.secretFindings } : {}),
169
+ ...(publication.warnings.length > 0 ? { warning: publication.warnings.join(" ") } : {}),
170
+ };
171
+ }
172
+
173
+ /** Every result a publication carries: its own and those of dependencies published first. */
174
+ function flattened(results: readonly FinishResult[]): FinishResult[] {
175
+ return results.flatMap((result) => [...flattened(result.dependencies ?? []), result]);
176
+ }
177
+
178
+ /** A deferral halts too: the remote is likely still unreachable. */
179
+ function halted(result: FinishResult): boolean {
180
+ return result.status === "conflict" || result.status === "error" || result.status === "deferred";
181
+ }
182
+
183
+ /** The archives an `ok` result published. */
184
+ function publishedBy(result: FinishResult): string[] {
185
+ if (result.status !== "ok") return [];
186
+ return result.anchors ?? (result.anchorName ? [result.anchorName] : []);
187
+ }
188
+
189
+ function deliveryRefusal(changes: string[], reason: string): string {
190
+ return `mate: the delivery of ${changes.join(", ")} could not be recorded (${reason}).`;
191
+ }
44
192
 
45
193
  /**
46
194
  * Every non-flag token, in order. Consumes the value of a value-taking flag exactly as
@@ -67,7 +215,7 @@ async function defaultLoadCapabilities(context: LaunchContext): Promise<Capabili
67
215
  return config.capabilities ?? [];
68
216
  }
69
217
 
70
- /** A publication the pipeline never ran: nothing was resolved, committed, tagged, or pushed. */
218
+ /** A publication the pipeline never ran: nothing was resolved, committed, or pushed. */
71
219
  function nothingToPublish(name: string, message: string): FinishResult {
72
220
  return {
73
221
  type: DEFAULT_FINISHER_TYPE,
@@ -100,25 +248,43 @@ function refusalResult(type: string, name: string, message: string): FinishResul
100
248
 
101
249
  /**
102
250
  * @command mate artifact publish <target>
103
- * @description Publishes an already-produced artifact. Resolves the launch context for the
104
- * current working repo, loads the enabled capabilities, and runs {@link runFinishEngine} to
105
- * commit/tag/push via {@link GitOps}. Two publication units exist: an archived change,
106
- * named positionally, and a spec publication of drifted canonical specs, selected with
107
- * `--specs`. Archiving is a precondition performed by the archive workflow; this command
108
- * never archives.
251
+ * @description Publishes artifacts to the companion's default branch. A submitted change is
252
+ * published with its whole Delivery Group, from any machine, once every delivery in it is
253
+ * merged: in a temporary worktree of the fetched default branch its changes are applied in
254
+ * `dependsOn` order, then submit order (stale check against `specBase`, `openspec archive`,
255
+ * spec validation), committed once with a `Mate-Artifact` trailer per change and a
256
+ * `Mate-Transaction` trailer, secret-scanned and pushed without force, rebuilt once. The
257
+ * group then leaves the inbox `mate/inbox`. A conflict publishes nothing and records `blocked`
258
+ * in the change's `delivery.yaml` on the pending branch; a refused push is
259
+ * `awaiting-publisher`. The checkout and its `HEAD` are not touched. A change depending on an
260
+ * unpublished change of another group publishes that group first, or is held
261
+ * (`dependency-unpublished`). Archives an earlier Mate left uncommitted in this checkout,
262
+ * drifted canonical specs (`--specs`), `--no-push`, and companions without a remote use the
263
+ * commit pipeline on `HEAD` (resolve, branch guard, cap sync, secret scan, commit,
264
+ * sync-with-remote, push). No tag is created; results carry the published `commit`.
109
265
  * @flags
110
- * - `<target>` — a dated archive anchor (`YYYY-MM-DD-<name>`), or a change name matching
111
- * exactly one archive. Mutually exclusive with `--specs` and `--all`.
112
- * - `--specs [<path>...]` — publish drifted canonical specs as their own publication under a
113
- * new `openspec/specs/<date>-<specs>` tag. Bare, it publishes every drifted spec; with paths, only
114
- * those. A bare name alongside it is a change target and is refused.
115
- * - `--all` — publish every pending change in discovery order, then one spec publication for
116
- * the drift that remains. Skips an archive the merge gate holds back, reporting why, and
117
- * halts at the first conflict or error; with `--json` it emits a
118
- * single array of results in execution order.
266
+ * - `<target>` — a Delivery Group (`<repository>/<branch>`, `change/<name>`), a submitted change
267
+ * name, or the dated anchor (`YYYY-MM-DD-<name>`) or name of a local archive from an earlier
268
+ * Mate. Mutually exclusive with `--specs` and `--all`.
269
+ * - `--refresh` — before publishing, record the merges this machine's linked checkouts settle
270
+ * for every submitted change, then check each branch of the group's changes in its linked
271
+ * checkout, recorded in its `delivery.yaml` on the pending branch (published with the group,
272
+ * else pushed there alone).
273
+ * - `--confirm-merged` / `--confirm-open` / `--confirm-dropped` — the user's answer for the
274
+ * group's Working Repository delivery, recorded the same way. One at a time; never with
275
+ * `--all`, `--specs` or `--no-push`.
276
+ * - `--specs [<path>...]` — publish drifted canonical specs as their own publication. Bare, it
277
+ * publishes every drifted spec; with paths, only those. A bare name alongside it is a change
278
+ * target and is refused.
279
+ * - `--all` — publish every submitted Delivery Group, dependencies first, then every local
280
+ * archive of an earlier Mate, then one spec publication for the drift that remains. Skips
281
+ * what is held or awaits a publisher, and a group resting on a merge someone else answered
282
+ * that no checkout found (`unconfirmed-merge`; publish it by name to accept the answer); a group's conflict blocks only that group and the run
283
+ * goes on, exiting 1 at the end. Halts at the first error or deferral; with `--json` it emits
284
+ * a single array of results in execution order.
119
285
  * - `--type <type>` — finisher type to use; see `knownFinisherTypes()`. `--specs` and
120
286
  * `--all` are openspec-only.
121
- * - `--no-push` — commit and tag locally but skip the remote sync and push.
287
+ * - `--no-push` — commit a local archive on `HEAD` but skip the remote sync and push.
122
288
  * - `--json` — emit machine-readable JSON instead of human-readable text.
123
289
  * @remarks No-ops (with a message on stderr) when the selected finisher is disabled for the
124
290
  * repo's configured capabilities — nothing is resolved or mutated in that case.
@@ -163,7 +329,29 @@ export async function runArtifactPublishCommand(
163
329
  return;
164
330
  }
165
331
  if (!allMode && !specsMode && positionals.length === 0) {
166
- refuse("mate: artifact publish requires an archive anchor or change name, --specs, or --all.");
332
+ refuse(
333
+ "mate: artifact publish requires a Delivery Group, a change name or archive anchor, --specs, or --all.",
334
+ );
335
+ return;
336
+ }
337
+ const confirmation = confirmFlag(flags);
338
+ if ("error" in confirmation) {
339
+ refuse(confirmation.error);
340
+ return;
341
+ }
342
+ const { confirm } = confirmation;
343
+ const refresh = flags.refresh === true;
344
+ const settling = refresh || confirm !== undefined;
345
+ if (confirm !== undefined && (allMode || specsMode)) {
346
+ refuse(
347
+ "mate: --confirm-* answers for the Delivery Group of one target; name it instead of --all or --specs.",
348
+ );
349
+ return;
350
+ }
351
+ if (settling && (specsMode || noPush)) {
352
+ refuse(
353
+ "mate: --refresh and --confirm-* record on the pending branch, which --specs and --no-push never reach; record with `mate artifact link` instead.",
354
+ );
167
355
  return;
168
356
  }
169
357
  if ((allMode || specsMode) && type !== DEFAULT_FINISHER_TYPE) {
@@ -203,6 +391,17 @@ export async function runArtifactPublishCommand(
203
391
  const loadCapabilities = deps.loadCapabilities ?? defaultLoadCapabilities;
204
392
  const capabilities = await loadCapabilities(context);
205
393
 
394
+ // The declared type the companion's submit handles; an invalid declaration publishes nothing.
395
+ let declaredType: ArtifactType | undefined;
396
+ try {
397
+ declaredType = await declaredSubmitType(context.companionPath);
398
+ } catch (err) {
399
+ emitErr(`mate: ${errorMessage(err)}`);
400
+ process.exitCode = 1;
401
+ return;
402
+ }
403
+ const typeDeps = declaredType ? { artifactType: declaredType } : {};
404
+
206
405
  let git: GitOps;
207
406
  const finishContext: FinishContext = {
208
407
  companionPath: context.companionPath,
@@ -247,31 +446,209 @@ export async function runArtifactPublishCommand(
247
446
  secretScan: (commitPaths: string[]) => scanPublicationFn(context.companionPath, commitPaths),
248
447
  };
249
448
 
250
- const runChange = (target: string, printResult = true): Promise<FinishResult> =>
251
- runFinishEngine(finisher, { name: target, noPush }, { ...engineDeps, printResult });
449
+ const deliveryEnvironment = () =>
450
+ resolveDeliveryEnvironment({
451
+ ensureUnambiguousCompanion: async () => true,
452
+ resolveContext: async () => context,
453
+ loadCapabilities: async () => capabilities,
454
+ ...deps.deliveryEnvironment,
455
+ });
456
+
457
+ /** `--refresh`: the merges linked checkouts settle are recorded once per run, before any group. */
458
+ let linkedSettled: Promise<boolean> | undefined;
459
+ /** True when it pushed a record, which leaves refs fetched before it stale. */
460
+ const settleLinkedOnce = (): Promise<boolean> =>
461
+ (linkedSettled ??= (async () => {
462
+ const environment = await deliveryEnvironment();
463
+ if ("error" in environment) return false;
464
+ const settled = await (deps.settleLinked ?? settleLinked)(
465
+ environment,
466
+ deps.deliveryEnvironment ?? {},
467
+ );
468
+ if (settled.warning && !quiet) emitErr(`mate: ${settled.warning}`);
469
+ return settled.recorded.length > 0;
470
+ })());
471
+
472
+ /** What `--refresh` found per change, kept for the result of a group it leaves held. */
473
+ const refreshOutcomes = new Map<string, BranchOutcome[]>();
474
+ /** Names why a group held as unmerged still waits: the lookups that need the user's answer. */
475
+ const withOutcomes = (result: FinishResult): FinishResult => {
476
+ const dependencies = result.dependencies?.map(withOutcomes);
477
+ const next = dependencies ? { ...result, dependencies } : result;
478
+ if (result.status !== "held" || result.reason !== "unmerged") return next;
479
+ const seen = new Set<string>();
480
+ const outcomes = (result.changes ?? [])
481
+ .flatMap((change) => refreshOutcomes.get(change) ?? [])
482
+ .filter((outcome) => {
483
+ const key = `${outcome.repository}\n${outcome.branch}`;
484
+ if (!outcome.needsAnswer || seen.has(key)) return false;
485
+ seen.add(key);
486
+ return true;
487
+ });
488
+ if (outcomes.length === 0) return next;
489
+ const lines = outcomes.flatMap(renderOutcome);
490
+ return {
491
+ ...next,
492
+ outcomes,
493
+ message: `${result.message}\n${lines.join("\n")}\n Answer with --confirm-merged, --confirm-open or --confirm-dropped.`,
494
+ };
495
+ };
496
+
497
+ /** Records `--refresh` and, unless `refreshOnly`, `--confirm-*` into the changes in `dir`. */
498
+ const settleWith =
499
+ (refreshOnly: boolean) =>
500
+ async (dir: string, changes: string[]): Promise<string | null> => {
501
+ const environment = await deliveryEnvironment();
502
+ if ("error" in environment) return environment.error;
503
+ const answer = refreshOnly ? undefined : confirm;
504
+ const record = (names: string[], edit: DeliveryEdit = {}) =>
505
+ recordDelivery(
506
+ { ...environment, companionPath: dir },
507
+ {
508
+ changes: names,
509
+ refresh: edit.confirm === undefined && refresh,
510
+ refreshAll: true,
511
+ edit,
512
+ // The worktree's HEAD is the publication tip; a base set here would hide staleness.
513
+ leaveSpecBase: true,
514
+ },
515
+ deps.deliveryEnvironment ?? {},
516
+ );
517
+ if (refresh) {
518
+ const outcome = await record(changes);
519
+ if ("refusal" in outcome) return deliveryRefusal(changes, outcome.refusal.reason);
520
+ if ("results" in outcome) {
521
+ for (const entry of outcome.results) refreshOutcomes.set(entry.change, entry.outcomes);
522
+ }
523
+ }
524
+ if (!answer) return null;
525
+ // The answer is for the Working Repository's delivery; changes without one keep theirs.
526
+ let confirmed = 0;
527
+ for (const change of changes) {
528
+ // oxlint-disable-next-line no-await-in-loop -- one record at a time, in group order
529
+ const outcome = await record([change], { confirm: answer });
530
+ if (!("refusal" in outcome)) confirmed += 1;
531
+ else if (outcome.refusal.reason !== "no-delivery-branch") {
532
+ return deliveryRefusal([change], outcome.refusal.reason);
533
+ }
534
+ }
535
+ return confirmed > 0 ? null : deliveryRefusal(changes, "no-delivery-branch");
536
+ };
537
+
538
+ const hasRemote = !noPush && (await (deps.hasRemote ?? defaultHasRemote)(context.companionPath));
539
+
540
+ /** One capability sync per run, however many groups `--all` publishes. */
541
+ let capSynced: Promise<boolean> | undefined;
542
+ /** Set by the `--all` queue's fetch; the next publication reuses it instead of fetching again. */
543
+ let refsFresh = false;
544
+ const publishGroup = async (target: string, inQueue = false): Promise<FinishResult> => {
545
+ capSynced ??= finisher.capSync ? finisher.capSync() : Promise.resolve(true);
546
+ if (!(await capSynced)) {
547
+ process.exitCode = 1;
548
+ return refusalResult(type, target, "mate: cap sync failed; nothing was published.");
549
+ }
550
+ if (refresh && (await settleLinkedOnce())) refsFresh = false;
551
+ const fresh = refsFresh;
552
+ refsFresh = false;
553
+ const publication = await (deps.publishSubmitted ?? publishSubmitted)(
554
+ context.companionPath,
555
+ target,
556
+ {
557
+ ...(settling ? { settle: settleWith(false) } : {}),
558
+ ...(refresh ? { settleDependency: settleWith(true) } : {}),
559
+ ...(fresh ? { fresh } : {}),
560
+ // `--all` publishes dependencies in queue order instead, and takes nobody's answer.
561
+ ...(inQueue ? { withDependencies: false, ownAnswersOnly: true } : {}),
562
+ scan: scanPublicationFn,
563
+ ...typeDeps,
564
+ },
565
+ );
566
+ const result = withOutcomes(publicationResult(type, target, publication));
567
+ if (result.status === "conflict" || result.status === "error") process.exitCode = 1;
568
+ return result;
569
+ };
570
+
571
+ /** Uncommitted archives of an earlier Mate, which publish from this checkout only. */
572
+ const localPendingArchives = async (changed = git.changedPaths()) => {
573
+ const paths = await changed;
574
+ const changeKinds = (await git.changedPathKinds?.()) ?? {};
575
+ return pendingArchives(await discoverArchives(context.companionPath, paths, changeKinds));
576
+ };
577
+
578
+ /**
579
+ * Names of the checkout's pending archives, read once per run: publishing commits one but never
580
+ * adds one.
581
+ */
582
+ let pendingArchiveNames: Promise<Set<string>> | undefined;
583
+
584
+ /**
585
+ * Publishes from this checkout what only it holds (an archive of an earlier Mate, an unpushed
586
+ * earlier publication) and everything without a remote; otherwise the Delivery Group.
587
+ */
588
+ const usesCheckout = async (target: string): Promise<boolean> => {
589
+ if (!hasRemote) return true;
590
+ if (isDeliveryGroup(target)) return false;
591
+ if (parseAnchor(target)) return true;
592
+ pendingArchiveNames ??= localPendingArchives().then(
593
+ (entries) => new Set(entries.map((entry) => entry.name)),
594
+ );
595
+ if ((await pendingArchiveNames).has(target)) return true;
596
+ return (deps.unpushedPublication ?? unpushedPublication)(context.companionPath, target);
597
+ };
598
+
599
+ /** Never prints: the caller does, once cleanup has attached `worktrees`. */
600
+ const runChange = async (target: string): Promise<FinishResult> => {
601
+ if (!hasRemote && isDeliveryGroup(target)) {
602
+ process.exitCode = 1;
603
+ return refusalResult(
604
+ type,
605
+ target,
606
+ `mate: ${target} is a Delivery Group, which publishes to the companion remote; ${noPush ? "drop --no-push" : "the companion has no remote"}.`,
607
+ );
608
+ }
609
+ if (!(await usesCheckout(target))) return await publishGroup(target);
610
+ if (!settling) {
611
+ return runFinishEngine(
612
+ finisher,
613
+ { name: target, noPush },
614
+ { ...engineDeps, printResult: false },
615
+ );
616
+ }
617
+ process.exitCode = 1;
618
+ return refusalResult(
619
+ type,
620
+ target,
621
+ `mate: ${target} is not submitted, so --refresh or --confirm-* has nothing to record on; record with \`mate artifact link\`, then publish again.`,
622
+ );
623
+ };
252
624
 
253
625
  /**
254
626
  * Cleans up the Worksets these change results made Done and attaches each outcome to the
255
627
  * result that completed it. Runs after every status and exit code is final; never throws.
256
628
  */
257
629
  const cleanUpWorktrees = async (changeResults: readonly FinishResult[]): Promise<void> => {
258
- const published = changeResults.flatMap((result) =>
259
- result.status === "ok" && result.anchorName ? [result.anchorName] : [],
260
- );
630
+ const all = flattened(changeResults);
261
631
  const outcomes = await cleanUpCompletedWorksets(
262
632
  context.companionPath,
263
- published,
633
+ all.flatMap((result) =>
634
+ publishedBy(result).map((anchor) => ({
635
+ anchor,
636
+ ...(result.commit ? { commit: result.commit } : {}),
637
+ })),
638
+ ),
264
639
  deps.worktreeCleanup,
265
640
  );
266
- for (const result of changeResults) {
267
- const outcome = result.anchorName ? outcomes.get(result.anchorName) : undefined;
641
+ for (const result of all) {
642
+ const outcome = publishedBy(result)
643
+ .map((anchor) => outcomes.get(anchor))
644
+ .find((found) => found !== undefined);
268
645
  if (outcome) result.worktrees = outcome;
269
646
  }
270
647
  };
271
648
 
272
649
  const printWorktrees = (changeResults: readonly FinishResult[]): void => {
273
650
  if (json) return;
274
- for (const { worktrees } of changeResults) {
651
+ for (const { worktrees } of flattened(changeResults)) {
275
652
  for (const entry of worktrees?.removed ?? []) emitErr(`mate: removed worktree ${entry.path}`);
276
653
  for (const entry of worktrees?.kept ?? []) {
277
654
  emitErr(`mate: kept worktree ${entry.path} (${entry.reason})`);
@@ -293,24 +670,55 @@ export async function runArtifactPublishCommand(
293
670
  return runFinishEngine(specsFinisher, { name: "--specs", noPush }, engineDeps);
294
671
  };
295
672
 
296
- /** A deferral halts too: the remote is likely still unreachable, and the re-run must tag its own commit. */
297
- const halted = (result: FinishResult): boolean =>
298
- result.status === "conflict" || result.status === "error" || result.status === "deferred";
299
-
300
673
  if (allMode) {
301
674
  const results: FinishResult[] = [];
302
675
  const changeResults: FinishResult[] = [];
303
- const changed = await git.changedPaths();
304
- const changeKinds = (await git.changedPathKinds?.()) ?? {};
305
- const archives = await discoverArchives(context.companionPath, changed, changeKinds);
676
+ let blocked = false;
677
+ const stop = async (): Promise<void> => {
678
+ // Worksets completed before the halt are still cleaned up.
679
+ await cleanUpWorktrees(changeResults);
680
+ printWorktrees(changeResults);
681
+ if (json) emitOut(JSON.stringify(results));
682
+ };
683
+
684
+ if (hasRemote) {
685
+ const queue = await (deps.publicationQueue ?? publicationQueue)(
686
+ context.companionPath,
687
+ typeDeps,
688
+ );
689
+ // A queue read from stale refs: the first publication fetches for itself.
690
+ refsFresh = queue.fresh;
691
+ for (const group of queue.groups) {
692
+ // oxlint-disable-next-line no-await-in-loop -- publications push one after another
693
+ const result = await publishGroup(group, true);
694
+ if (!quiet) printFinishResult(result, { json, stdout: emitOut, stderr: emitErr });
695
+ results.push(result);
696
+ // A group waiting on a merge, a dependency or a publisher does not stop the others.
697
+ if (result.status === "held" || result.status === "awaiting-publisher") continue;
698
+ changeResults.push(result);
699
+ // A group publication never touches the checkout, so its conflict blocks only that group.
700
+ if (result.status === "conflict") {
701
+ blocked = true;
702
+ continue;
703
+ }
704
+ if (halted(result)) {
705
+ // oxlint-disable-next-line no-await-in-loop -- ends the loop
706
+ await stop();
707
+ return;
708
+ }
709
+ }
710
+ refsFresh = false;
711
+ }
306
712
 
307
- for (const entry of pendingArchives(archives)) {
713
+ const changed = git.changedPaths();
714
+ for (const entry of await localPendingArchives(changed)) {
308
715
  // A held-back archive waits for its merge; it does not stop the merged ones.
309
716
  // Same cache as the finisher's resolve step, so both see one pending set and agree.
717
+ // oxlint-disable-next-line no-await-in-loop -- one archive after another
310
718
  const hold = await publicationHold(
311
719
  context.companionPath,
312
720
  entry.anchor,
313
- async () => changed,
721
+ () => changed,
314
722
  finishContext.holdCache,
315
723
  );
316
724
  if (hold) {
@@ -318,14 +726,17 @@ export async function runArtifactPublishCommand(
318
726
  results.push(nothingToPublish(entry.anchor, hold));
319
727
  continue;
320
728
  }
321
- const result = await runChange(entry.anchor);
729
+ // oxlint-disable-next-line no-await-in-loop -- one archive after another
730
+ const result = await runFinishEngine(
731
+ finisher,
732
+ { name: entry.anchor, noPush },
733
+ { ...engineDeps, printResult: true },
734
+ );
322
735
  results.push(result);
323
736
  changeResults.push(result);
324
737
  if (halted(result)) {
325
- // Worksets completed before the halt are still cleaned up.
326
- await cleanUpWorktrees(changeResults);
327
- printWorktrees(changeResults);
328
- if (json) emitOut(JSON.stringify(results));
738
+ // oxlint-disable-next-line no-await-in-loop -- ends the loop
739
+ await stop();
329
740
  return;
330
741
  }
331
742
  }
@@ -333,6 +744,7 @@ export async function runArtifactPublishCommand(
333
744
  /** Drift is recomputed: a spec a change just committed is no longer drifted. */
334
745
  const specResult = await runSpecs([]);
335
746
  if (specResult) results.push(specResult);
747
+ if (blocked) process.exitCode = 1;
336
748
 
337
749
  await cleanUpWorktrees(changeResults);
338
750
  printWorktrees(changeResults);
@@ -354,7 +766,7 @@ export async function runArtifactPublishCommand(
354
766
  }
355
767
 
356
768
  // Printed here, after cleanup, so `--json` stays one object that carries `worktrees`.
357
- const result = await runChange(positionals[0], false);
769
+ const result = await runChange(positionals[0]);
358
770
  await cleanUpWorktrees([result]);
359
771
  printFinishResult(result, { json, stdout: emitOut, stderr: emitErr });
360
772
  printWorktrees([result]);