@uniqbit/mate-core 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) 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 +10 -1
  4. package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
  5. package/opencode-plugin/src/server.ts +9 -2
  6. package/package.json +2 -1
  7. package/src/cli/commands/artifact/delivery/environment.ts +28 -8
  8. package/src/cli/commands/artifact/delivery/link.ts +28 -9
  9. package/src/cli/commands/artifact/delivery/output.ts +7 -0
  10. package/src/cli/commands/companion/update.ts +2 -19
  11. package/src/cli/commands/factory/factory.ts +11 -1
  12. package/src/cli/commands/install.ts +47 -36
  13. package/src/cli/commands/launch/claude.ts +2 -0
  14. package/src/cli/commands/launch/shared.ts +33 -6
  15. package/src/cli/commands/plugin/install.ts +27 -11
  16. package/src/cli/commands/report/index.ts +180 -184
  17. package/src/cli/commands/report/markdown.ts +67 -72
  18. package/src/cli/commands/shared/companion-selection.ts +3 -1
  19. package/src/cli/commands/studio/access.ts +6 -14
  20. package/src/cli/commands/studio/areas.ts +112 -33
  21. package/src/cli/commands/studio/companion-add.ts +87 -0
  22. package/src/cli/commands/studio/companion-removal.ts +15 -8
  23. package/src/cli/commands/studio/factory-credential.ts +1 -15
  24. package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
  25. package/src/cli/commands/studio/factory-relay.ts +18 -0
  26. package/src/cli/commands/studio/graph-model.ts +61 -0
  27. package/src/cli/commands/studio/graph.ts +336 -0
  28. package/src/cli/commands/studio/index.ts +4 -4
  29. package/src/cli/commands/studio/payload.ts +42 -15
  30. package/src/cli/commands/studio/repository-add.ts +116 -0
  31. package/src/cli/commands/studio/routes.ts +6 -0
  32. package/src/cli/commands/studio/selection.ts +12 -3
  33. package/src/cli/commands/studio/server.ts +127 -5
  34. package/src/cli/commands/studio/services.ts +40 -0
  35. package/src/cli/commands/studio/terminal.ts +45 -3
  36. package/src/cli/commands/studio/views/vault/markdown-tree.ts +84 -3
  37. package/src/cli/commands/studio/workset-session.ts +47 -14
  38. package/src/cli/commands/unwrap.ts +3 -0
  39. package/src/cli/commands/update.ts +2 -0
  40. package/src/cli/commands/vscode/release-vsix.json +4 -0
  41. package/src/cli/commands/vscode/setup.ts +71 -13
  42. package/src/cli/commands/vscode/vsix.ts +48 -7
  43. package/src/cli/commands/working/cleanup.ts +40 -8
  44. package/src/cli/commands/working/worktree.ts +176 -35
  45. package/src/cli/main.ts +17 -2
  46. package/src/cli/usage.ts +1 -1
  47. package/src/hooks/rtk-worktree-git.ts +48 -0
  48. package/src/hooks/validate-artifact-path.ts +38 -7
  49. package/src/lib/delivery/branch-template.ts +122 -0
  50. package/src/lib/delivery/branches.ts +21 -16
  51. package/src/lib/delivery/checkout.ts +102 -0
  52. package/src/lib/delivery/environment.ts +2 -0
  53. package/src/lib/delivery/merge-git.ts +13 -1
  54. package/src/lib/delivery/record-delivery.ts +83 -29
  55. package/src/lib/delivery/record.ts +15 -3
  56. package/src/lib/delivery/resolve-branch.ts +157 -110
  57. package/src/lib/factory/attach-client.ts +11 -1
  58. package/src/lib/factory/broker.ts +37 -40
  59. package/src/lib/factory/client.ts +22 -1
  60. package/src/lib/factory/clone-url.ts +39 -0
  61. package/src/lib/factory/command.ts +21 -5
  62. package/src/lib/factory/git-auth.ts +61 -0
  63. package/src/lib/factory/git-credential-store.ts +181 -0
  64. package/src/lib/factory/ids.ts +12 -2
  65. package/src/lib/factory/outcomes/actions.ts +20 -4
  66. package/src/lib/factory/outcomes/index.ts +77 -11
  67. package/src/lib/factory/outcomes/lifecycle.ts +9 -2
  68. package/src/lib/factory/outcomes/sessions.ts +23 -1
  69. package/src/lib/factory/prepare.ts +9 -3
  70. package/src/lib/factory/runner/scheduler.ts +96 -14
  71. package/src/lib/factory/runner/workflow.ts +5 -1
  72. package/src/lib/factory/runtime.ts +143 -43
  73. package/src/lib/orchestrator/companion-hub.ts +6 -1
  74. package/src/lib/orchestrator/engine-floor.ts +48 -0
  75. package/src/lib/orchestrator/launcher.ts +34 -1
  76. package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
  77. package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
  78. package/src/lib/orchestrator/projection-claude-links.ts +32 -8
  79. package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
  80. package/src/lib/orchestrator/projection-entries.ts +22 -18
  81. package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
  82. package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
  83. package/src/lib/orchestrator/projection-types.ts +28 -1
  84. package/src/lib/orchestrator/refresh-working-claude-links.ts +3 -1
  85. package/src/lib/orchestrator/session-prepare.ts +6 -1
  86. package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
  87. package/src/lib/orchestrator/types.ts +4 -0
  88. package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
  89. package/src/lib/orchestrator/working-repo-projection.ts +24 -4
  90. package/src/lib/orchestrator/wrap-pass.ts +1 -0
  91. package/src/lib/public-npm.ts +95 -50
  92. package/src/lib/session-state.ts +72 -2
  93. package/src/lib/update-checker.ts +7 -1
  94. package/src/lib/usage/aggregate.ts +202 -0
  95. package/src/lib/usage/cache.ts +87 -0
  96. package/src/lib/usage/claude-pricing.ts +71 -0
  97. package/src/lib/usage/claude.ts +189 -0
  98. package/src/lib/usage/collect.ts +56 -0
  99. package/src/lib/usage/opencode.ts +188 -0
  100. package/src/lib/usage/records.ts +80 -0
  101. package/src/lib/usage/rtk-database.ts +72 -0
  102. package/src/lib/usage/savings.ts +209 -0
  103. package/src/lib/usage/scope.ts +182 -0
  104. package/src/lib/usage/source.ts +102 -0
  105. package/src/lib/usage/types.ts +143 -0
  106. package/src/lib/usage/window.ts +37 -0
  107. package/src/lib/workset/factory-local.ts +157 -0
  108. package/src/lib/workset/record.ts +25 -11
  109. package/src/lib/workset/repositories.ts +118 -25
  110. package/src/lib/workset/worktree-include.ts +161 -0
  111. package/src/lib/workset/worktree-index.ts +6 -2
  112. package/src/lib/workset/worktree.ts +591 -101
  113. package/src/opencode/companion-hooks.ts +46 -8
  114. package/src/opencode/companion-policy.ts +18 -5
  115. package/src/opencode/enter-worktree.ts +254 -6
  116. package/src/opencode/session-register.ts +2 -2
  117. package/src/runtime/claude-bg-isolation.ts +138 -0
  118. package/src/runtime/companion-git.ts +10 -2
  119. package/src/runtime/companion-guidance.ts +17 -4
  120. package/src/runtime/current-branch.ts +16 -2
  121. package/src/runtime/entered-worktree.ts +24 -0
  122. package/src/runtime/git-tracked.ts +60 -0
  123. package/src/runtime/repo-destination.ts +72 -0
  124. package/src/runtime/repo-local.ts +25 -3
  125. package/src/runtime/rtk-git-guard.ts +66 -0
  126. package/src/runtime/runtime-document-manifest.ts +229 -19
  127. package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
  128. package/src/runtime/secret-guard.ts +9 -2
  129. package/src/runtime/secret-policy-weakening.ts +122 -0
  130. package/src/runtime/serving-claude-wrap.ts +15 -2
  131. package/src/runtime/umbrella-folder.ts +56 -0
  132. package/src/runtime/wrap-state.ts +5 -13
  133. package/src/studio.ts +37 -0
  134. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +61 -6
  135. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +8 -4
  136. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +9 -5
  137. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +5 -4
  138. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +10 -4
  139. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +5 -1
  140. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +61 -6
  141. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +8 -4
  142. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +9 -5
  143. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +5 -4
  144. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +10 -4
  145. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +5 -1
  146. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +305 -42
  147. package/src/tools/setup/capabilities/rtk.ts +93 -1
  148. package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
  149. package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
  150. package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
  151. package/src/tools/setup/dynamic-plugins/install.ts +24 -22
  152. package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
  153. package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
  154. package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
  155. package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
  156. package/src/tools/setup/mate.ts +3 -3
  157. package/src/tools/setup/plugins/gitignore.ts +15 -9
  158. package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
  159. package/src/tools/setup/providers/claude.ts +25 -3
  160. package/src/tools/setup/utils.ts +4 -2
  161. package/src/tools/setup/working-repo-cleanup.ts +2 -2
  162. package/src/tools/setup.ts +25 -14
  163. package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
  164. package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
  165. package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
  166. package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
  167. package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
  168. package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
  169. package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
  170. package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
  171. package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
  172. package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
  173. package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
  174. package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
  175. package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
  176. package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
  177. package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
  178. package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
  179. package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
  180. package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
  181. package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
  182. package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
  183. package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
  184. package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
  185. package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
  186. package/studio-dist/client/assets/select-CnaMd617.js +1 -0
  187. package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
  188. package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
  189. package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
  190. package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
  191. package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
  192. package/studio-dist/client/assets/store-Dw34catY.js +1 -0
  193. package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
  194. package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
  195. package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
  196. package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
  197. package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
  198. package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
  199. package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
  200. package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
  201. package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
  202. package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
  203. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +102 -35
  204. package/studio-dist/server/assets/{actions-Bvgj9eb8.js → actions-DYSv-9VV.js} +10 -4
  205. package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
  206. package/studio-dist/server/assets/{button-CIJqAhni.js → button-CgOIVdmD.js} +13 -1702
  207. package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
  208. package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-BKVXD3TO.js} +3 -3
  209. package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
  210. package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
  211. package/studio-dist/server/assets/{factory-DUTa0eDs.js → factory-C7Ybg0xG.js} +1256 -353
  212. package/studio-dist/server/assets/{factory-DGPmNGbo.js → factory-Df5uAHjb.js} +53 -6
  213. package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
  214. package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
  215. package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
  216. package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
  217. package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
  218. package/studio-dist/server/assets/graph-CSje3029.js +801 -0
  219. package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
  220. package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
  221. package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
  222. package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
  223. package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
  224. package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
  225. package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
  226. package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-BR8dJ7aR.js} +28 -9
  227. package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-BR_t9iMM.js} +4 -4
  228. package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
  229. package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
  230. package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
  231. package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
  232. package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CQ9qQ1-n.js} +9 -10
  233. package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-dYDEoBeq.js} +3 -3
  234. package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DkRHNTpE.js} +787 -2862
  235. package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-B6GfOew4.js} +22 -171
  236. package/studio-dist/server/assets/{search-JAKurDNh.js → search-BJnWLfkG.js} +21 -2
  237. package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
  238. package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-Hq-hXgnT.js} +6 -5
  239. package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-B7nEuVbx.js} +9 -8
  240. package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-B_YYL7q8.js} +3 -3
  241. package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
  242. package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
  243. package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
  244. package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D56DApvK.js} +1 -1
  245. package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
  246. package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
  247. package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
  248. package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
  249. package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
  250. package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
  251. package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
  252. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
  253. package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-BDuIUq0F.js} +8 -5
  254. package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-BVLp6zu3.js} +3 -3
  255. package/studio-dist/server/assets/{views-BgYa-za2.js → views-flRUr21z.js} +4 -4
  256. package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-CDy9pdgL.js} +3 -2
  257. package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-D9GKI2EV.js} +132 -106
  258. package/studio-dist/server/server.js +582 -8
  259. package/src/cli/commands/report/collector.ts +0 -288
  260. package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
  261. package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
  262. package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
  263. package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
  264. package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
  265. package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
  266. package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
  267. package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
  268. package/studio-dist/client/assets/prepaint-CwSrpdFA.js +0 -27
  269. package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
  270. package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
  271. package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
  272. package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
  273. package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
  274. package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
  275. package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
  276. package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
  277. package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
  278. package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
  279. package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
  280. package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
  281. package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +0 -45
  282. package/studio-dist/server/assets/react-Ce6dj15C.js +0 -46
  283. package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
  284. package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
  285. package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
  286. package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
@@ -3,7 +3,8 @@ import { promisify } from "node:util";
3
3
 
4
4
  import { readCompanionConfig } from "../orchestrator/config-store";
5
5
  import type { CapabilityConfig, TicketFormat } from "../orchestrator/types";
6
- import { listRefsWith } from "./resolve-branch";
6
+ import { parseBranchTemplate, type BranchTemplateSetting } from "./branch-template";
7
+ import { deliveryCheckout } from "./checkout";
7
8
 
8
9
  export type { TicketFormat };
9
10
 
@@ -80,6 +81,22 @@ export async function companionTicketFormat(companionPath: string): Promise<Tick
80
81
  return configuredTicketFormat(config.capabilities ?? []).format;
81
82
  }
82
83
 
84
+ /** The openspec capability's `branchTemplate`; absent or invalid means the default. */
85
+ export function configuredBranchTemplate(
86
+ capabilities: readonly CapabilityConfig[],
87
+ ): BranchTemplateSetting {
88
+ const openspec = capabilities.find((capability) => capability.name === "openspec");
89
+ return parseBranchTemplate(openspec?.branchTemplate);
90
+ }
91
+
92
+ /** The Delivery Branch template in a companion's `framework.yaml`, with its diagnostic. */
93
+ export async function companionBranchTemplate(
94
+ companionPath: string,
95
+ ): Promise<BranchTemplateSetting> {
96
+ const config = await readCompanionConfig(companionPath);
97
+ return configuredBranchTemplate(config.capabilities ?? []);
98
+ }
99
+
83
100
  /** Read-only local Git queries against a Working Repository. Nothing here touches the network. */
84
101
  export interface WorkingRepoGit {
85
102
  /** Checked-out branch, or null in a detached HEAD. */
@@ -108,20 +125,8 @@ export function workingRepoGit(repoPath: string): WorkingRepoGit {
108
125
  }
109
126
  };
110
127
 
111
- const remoteTip = async (branch: string): Promise<string | null> =>
112
- (await run("rev-parse", "--verify", "--quiet", `refs/remotes/origin/${branch}`)) || null;
113
- const defaultBranch = async (): Promise<string> => {
114
- const remoteHead = await run("symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD");
115
- if (remoteHead) return remoteHead.replace(/^origin\//, "");
116
- for (const candidate of ["main", "master"]) {
117
- // oxlint-disable-next-line no-await-in-loop -- the steps are a decision chain
118
- if (await remoteTip(candidate)) return candidate;
119
- }
120
- return (await run("config", "--get", "init.defaultBranch")) || "main";
121
- };
122
-
123
- const hasRef = async (ref: string): Promise<boolean> =>
124
- (await run("rev-parse", "--verify", "--quiet", ref)) !== null;
128
+ // Ref queries are the ones a Delivery Branch resolves through.
129
+ const { hasRef, listRefs, defaultBranch } = deliveryCheckout(repoPath);
125
130
 
126
131
  const currentBranch = async (): Promise<string | null> =>
127
132
  (await run("symbolic-ref", "--quiet", "--short", "HEAD")) || null;
@@ -142,6 +147,6 @@ export function workingRepoGit(repoPath: string): WorkingRepoGit {
142
147
  );
143
148
  },
144
149
  hasRef,
145
- listRefs: listRefsWith((args) => run(...args)),
150
+ listRefs,
146
151
  };
147
152
  }
@@ -0,0 +1,102 @@
1
+ import {
2
+ localGitEnv,
3
+ mergeGit,
4
+ spawnProcess,
5
+ type MergeGit,
6
+ type ProcessResult,
7
+ } from "./merge-git";
8
+ import { localMergeEvidence } from "./refresh";
9
+
10
+ /** True when the ref resolves in the checkout. */
11
+ export type HasRef = (ref: string) => Promise<boolean>;
12
+
13
+ /** Full names of the refs under the given prefixes, e.g. `refs/heads/workset/`. */
14
+ export type ListRefs = (prefixes: string[]) => Promise<string[]>;
15
+
16
+ /**
17
+ * A local merge check, without fetch or forge: a merge commit settles `merged`, commits
18
+ * matched on the default branch read as `squashed`. A head on the default branch's own line
19
+ * is `open`: it may be a fast-forward, but then its commits are already there and continuing
20
+ * on it is safe.
21
+ */
22
+ export type MergeProbeResult = "merged" | "squashed" | "open";
23
+
24
+ /** The local Git a Delivery Branch resolves in: refs, the default branch, and merge checks. */
25
+ export interface DeliveryCheckout {
26
+ hasRef: HasRef;
27
+ listRefs: ListRefs;
28
+ /** `origin/HEAD`, then an existing `origin/main` or `origin/master`, then `init.defaultBranch`, then `main`. */
29
+ defaultBranch(): Promise<string>;
30
+ /** Null when the checkout cannot check merges; the branch then counts as never checked. */
31
+ mergeProbe(branch: string, recordedHead: string | undefined): Promise<MergeProbeResult | null>;
32
+ }
33
+
34
+ /**
35
+ * Runs `git` in the checkout. `env` is the environment local queries need; a runner with
36
+ * its own Git policy (another user, extra `-c` settings) may keep its own instead.
37
+ */
38
+ export type CheckoutRunner = (
39
+ args: readonly string[],
40
+ options: { env: NodeJS.ProcessEnv; input?: string; timeoutMs?: number },
41
+ ) => Promise<ProcessResult>;
42
+
43
+ /** A {@link ListRefs} over a Git runner that answers stdout, or null on failure. */
44
+ function listRefsWith(git: (args: string[]) => Promise<string | null>): ListRefs {
45
+ return async (prefixes) => {
46
+ const stdout = await git(["for-each-ref", "--format=%(refname)", ...prefixes]);
47
+ return stdout ? stdout.split("\n").filter(Boolean) : [];
48
+ };
49
+ }
50
+
51
+ /** The default branch over a Git runner that answers trimmed stdout, or null on failure. */
52
+ async function defaultBranchWith(
53
+ run: (...args: string[]) => Promise<string | null>,
54
+ ): Promise<string> {
55
+ const remoteHead = await run("symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD");
56
+ if (remoteHead) return remoteHead.replace(/^origin\//, "");
57
+ for (const candidate of ["main", "master"]) {
58
+ // oxlint-disable-next-line no-await-in-loop -- the steps are a decision chain
59
+ if (await run("rev-parse", "--verify", "--quiet", `refs/remotes/origin/${candidate}`)) {
60
+ return candidate;
61
+ }
62
+ }
63
+ return (await run("config", "--get", "init.defaultBranch")) || "main";
64
+ }
65
+
66
+ /** The merge check over local merge queries; see {@link MergeProbeResult}. */
67
+ export async function probeMerge(
68
+ git: MergeGit,
69
+ defaultBranch: string,
70
+ branch: string,
71
+ recordedHead: string | undefined,
72
+ ): Promise<MergeProbeResult> {
73
+ const evidence = await localMergeEvidence(git, defaultBranch, branch, recordedHead);
74
+ if (evidence.merged) return "merged";
75
+ const style = evidence.suggestion?.style;
76
+ return style === "squash" || style === "rebase" ? "squashed" : "open";
77
+ }
78
+
79
+ /**
80
+ * The checkout at `path`, every query through one runner, so a caller's Git policy reaches
81
+ * ref lookups and merge checks alike. Without `run`, `git` is spawned in `path`.
82
+ */
83
+ export function deliveryCheckout(path: string, run?: CheckoutRunner): DeliveryCheckout {
84
+ const git: CheckoutRunner =
85
+ run ?? ((args, options) => spawnProcess("git", args, { cwd: path, ...options }));
86
+ const env = localGitEnv();
87
+ const stdout = async (...args: string[]): Promise<string | null> => {
88
+ const result = await git(args, { env });
89
+ return result.code === 0 ? result.stdout.trim() || null : null;
90
+ };
91
+ let defaultBranch: Promise<string> | undefined;
92
+ const merges = mergeGit(path, { spawn: (_command, args, options) => git(args, options) });
93
+ const checkout: DeliveryCheckout = {
94
+ hasRef: async (ref) =>
95
+ (await git(["rev-parse", "--verify", "--quiet", ref], { env })).code === 0,
96
+ listRefs: listRefsWith((args) => stdout(...args)),
97
+ defaultBranch: () => (defaultBranch ??= defaultBranchWith(stdout)),
98
+ mergeProbe: async (branch, recordedHead) =>
99
+ probeMerge(merges, await checkout.defaultBranch(), branch, recordedHead),
100
+ };
101
+ return checkout;
102
+ }
@@ -9,6 +9,8 @@ export interface WorkingRepoInfo {
9
9
  slug: string | null;
10
10
  forgeRepo: ForgeRepo | null;
11
11
  git: WorkingRepoGit;
12
+ /** Set when the Working Repository is an Umbrella Repository: its children's repository paths. */
13
+ umbrellaChildren?: string[];
12
14
  }
13
15
 
14
16
  /** The companion, the Working Repository with its remote identity, and protected-branch patterns. */
@@ -117,10 +117,22 @@ function patchIds(output: string): Array<[string, string]> {
117
117
  .filter((parts): parts is [string, string] => parts.length === 2 && parts[0] !== "");
118
118
  }
119
119
 
120
+ function promptlessEnv(base: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
121
+ return { ...withoutAskPass(base), GIT_TERMINAL_PROMPT: "0" };
122
+ }
123
+
124
+ /** Environment for local Git queries: never prompts, never fetches lazily. */
125
+ export function localGitEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
126
+ return {
127
+ ...promptlessEnv(gitEnvironment(env) as NodeJS.ProcessEnv),
128
+ GIT_NO_LAZY_FETCH: "1",
129
+ };
130
+ }
131
+
120
132
  export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
121
133
  const spawnFn = deps.spawn ?? spawnProcess;
122
134
  const base = gitEnvironment(deps.env ?? process.env) as NodeJS.ProcessEnv;
123
- const promptless: NodeJS.ProcessEnv = { ...withoutAskPass(base), GIT_TERMINAL_PROMPT: "0" };
135
+ const promptless = promptlessEnv(base);
124
136
  const localEnv: NodeJS.ProcessEnv = { ...promptless, GIT_NO_LAZY_FETCH: "1" };
125
137
 
126
138
  const git = (args: readonly string[], input?: string) =>
@@ -5,6 +5,7 @@ import {
5
5
  type WorkingRepoGit,
6
6
  } from "./branches";
7
7
  import { changeNameOf, locateChange, type ChangeLocation } from "../change-layout";
8
+ import { scopedRepositories } from "../openspec-scopes";
8
9
  import { companionRelative, type DeliveryEnvironment } from "./environment";
9
10
  import {
10
11
  canaryTicketOf,
@@ -26,12 +27,8 @@ import {
26
27
  type RefreshAccess,
27
28
  type RefreshCache,
28
29
  } from "./refresh";
29
- import {
30
- mergeProbeWith,
31
- resolveDeliveryBranch,
32
- type HasRef,
33
- type ListRefs,
34
- } from "./resolve-branch";
30
+ import { probeMerge, type DeliveryCheckout } from "./checkout";
31
+ import { resolveDeliveryBranch } from "./resolve-branch";
35
32
  import {
36
33
  repositoryAccessFor,
37
34
  type RepositoryAccess,
@@ -46,8 +43,9 @@ export interface DeliveryEdit {
46
43
  /** The user's answer, recorded after any refresh with source `user`. */
47
44
  confirm?: MergeState;
48
45
  /**
49
- * Records the Delivery Branch resolved with this Jira key, which names a new branch
50
- * `workset/<TICKET>-<id>`; the key itself is not stored. Refused while tickets are off.
46
+ * Records the Delivery Branch resolved with this Jira key, which names a new branch by the
47
+ * template (default `workset/<TICKET>-<id>`); the key itself is not stored. Refused while
48
+ * tickets are off.
51
49
  */
52
50
  ticket?: string;
53
51
  }
@@ -78,6 +76,8 @@ export interface DeliveryRequest {
78
76
  export type DeliveryRefusal =
79
77
  | { reason: "unknown-change"; change: string }
80
78
  | { reason: "no-repository" }
79
+ /** An edit in an Umbrella Repository whose changes are scoped to not exactly one child. */
80
+ | { reason: "umbrella-repository"; umbrella: string; scoped: string[]; children: string[] }
81
81
  | { reason: "tickets-off" }
82
82
  | { reason: "no-resolved-branch"; change: string; diagnostics: string[] }
83
83
  /** `--ticket` on a repository whose delivery is direct or not applicable. */
@@ -117,7 +117,7 @@ export interface NeedsBranch {
117
117
  diagnostics: string[];
118
118
  change: string;
119
119
  record: DeliveryRecord;
120
- /** First existing safe default or legacy branch in the Working Repository. */
120
+ /** First existing safe default or legacy branch in the session's checkout of the repository. */
121
121
  suggestedBranch: string | null;
122
122
  }
123
123
 
@@ -143,14 +143,55 @@ async function checkoutGit(
143
143
  return checkout ? workingRepoGit(checkout) : null;
144
144
  }
145
145
 
146
- /** Ref lookups in the repository's local checkout; null when none is known. */
147
- async function refsIn(
146
+ /** The Umbrella Repository's children the changes are scoped to, in scope order. */
147
+ async function scopedChildren(
148
+ located: readonly { dir: string }[],
149
+ children: readonly string[],
150
+ ): Promise<string[]> {
151
+ const scoped: string[] = [];
152
+ for (const { dir } of located) {
153
+ // oxlint-disable-next-line no-await-in-loop -- a few small files, in order
154
+ for (const repository of await scopedRepositories(dir)) {
155
+ const child = children.find((entry) => sameRepository(entry, repository));
156
+ if (child && !scoped.includes(child)) scoped.push(child);
157
+ }
158
+ }
159
+ return scoped;
160
+ }
161
+
162
+ /**
163
+ * The Git whose branches the session works on: the Working Repository's, or in an Umbrella
164
+ * Repository, which is no checkout, the delivery's child checkout.
165
+ */
166
+ async function sessionGitOf(
167
+ environment: DeliveryEnvironment,
168
+ repository: string | null,
169
+ ): Promise<WorkingRepoGit | null> {
170
+ const working = environment.workingRepo;
171
+ if (!working?.umbrellaChildren) return working?.git ?? null;
172
+ return repository ? checkoutGit(environment, repository) : null;
173
+ }
174
+
175
+ /**
176
+ * The repository's local checkout for resolving its Delivery Branch; null when none is known.
177
+ * Merges are checked through the repository's local merge access, without a fetch.
178
+ */
179
+ async function deliveryCheckoutIn(
148
180
  environment: DeliveryEnvironment,
149
181
  repository: string,
150
- ): Promise<{ hasRef: HasRef; listRefs: ListRefs | null } | null> {
182
+ access: RepositoryAccess,
183
+ ): Promise<DeliveryCheckout | null> {
151
184
  const git = await checkoutGit(environment, repository);
152
185
  if (!git) return null;
153
- return { hasRef: (ref) => git.hasRef(ref), listRefs: git.listRefs?.bind(git) ?? null };
186
+ return {
187
+ hasRef: (ref) => git.hasRef(ref),
188
+ listRefs: async (prefixes) => (await git.listRefs?.(prefixes)) ?? [],
189
+ defaultBranch: () => git.defaultBranch(),
190
+ mergeProbe: async (branch, recordedHead) => {
191
+ const local = await access.local?.();
192
+ return local ? probeMerge(local.git, local.defaultBranch, branch, recordedHead) : null;
193
+ },
194
+ };
154
195
  }
155
196
 
156
197
  /** A delivery a ticket must not replace: direct, or not applicable. */
@@ -189,7 +230,6 @@ export async function recordDelivery(
189
230
  located.push({ ...location, change });
190
231
  }
191
232
 
192
- const repository = request.repository ?? environment.workingRepo?.slug ?? null;
193
233
  const ticketFormat = environment.ticket?.format ?? "none";
194
234
  if (edit.ticket !== undefined && ticketFormat === "none") {
195
235
  return { refusal: { reason: "tickets-off" } };
@@ -199,6 +239,19 @@ export async function recordDelivery(
199
239
  edit.pr !== undefined ||
200
240
  edit.confirm !== undefined ||
201
241
  edit.ticket !== undefined;
242
+ const working = environment.workingRepo;
243
+ let repository = request.repository ?? working?.slug ?? null;
244
+ // In an Umbrella Repository the changes' only scoped child stands in for the Working Repository.
245
+ if (!repository && working?.umbrellaChildren) {
246
+ const children = working.umbrellaChildren;
247
+ const scoped = await scopedChildren(located, children);
248
+ if (scoped.length === 1) repository = scoped[0]!;
249
+ else if (edits) {
250
+ return {
251
+ refusal: { reason: "umbrella-repository", umbrella: working.path, scoped, children },
252
+ };
253
+ }
254
+ }
202
255
  if (edits && !repository) return { refusal: { reason: "no-repository" } };
203
256
  const refuseProtected = async (
204
257
  repo: string,
@@ -223,23 +276,24 @@ export async function recordDelivery(
223
276
  };
224
277
  const cache: RefreshCache = new Map();
225
278
  const resolved: Array<DeliveryResult & { dir: string }> = [];
226
- const refs = repository ? await refsIn(environment, repository) : null;
227
- const local = repository ? await access(repository).local?.() : null;
228
- const mergeProbe = local ? mergeProbeWith(local.git, local.defaultBranch) : null;
229
- const currentBranch = (await environment.workingRepo?.git.currentBranch()) ?? null;
279
+ const checkout = repository
280
+ ? await deliveryCheckoutIn(environment, repository, access(repository))
281
+ : null;
282
+ const sessionGit = await sessionGitOf(environment, repository);
283
+ const currentBranch = (await sessionGit?.currentBranch()) ?? null;
230
284
 
231
285
  for (const { change, dir, archived } of located) {
232
286
  let record = await readOrUnlinkedRecord(dir, change);
233
- const resolution = await resolveDeliveryBranch({
234
- companionPath: environment.companionPath,
235
- repository,
236
- hasRef: refs?.hasRef ?? null,
237
- listRefs: refs?.listRefs ?? null,
238
- mergeProbe,
239
- change,
240
- ...(edit.ticket !== undefined ? { ticket: edit.ticket } : {}),
241
- });
242
- const diagnostics = resolution.diagnostics;
287
+ const resolution = await resolveDeliveryBranch(
288
+ checkout,
289
+ { companionPath: environment.companionPath, repository, change },
290
+ edit.ticket !== undefined ? { ticket: edit.ticket } : {},
291
+ );
292
+ // Reported once, on the first change, as it concerns the companion, not a change.
293
+ const templateDiagnostic = resolved.length === 0 ? resolution.templateDiagnostic : null;
294
+ const diagnostics = templateDiagnostic
295
+ ? [templateDiagnostic, ...resolution.diagnostics]
296
+ : resolution.diagnostics;
243
297
  const defaultBranch = resolution.branch;
244
298
  const recordedBranch = repository ? findDelivery(record, repository)?.branch : undefined;
245
299
  if (recordedBranch && defaultBranch && recordedBranch !== defaultBranch) {
@@ -277,7 +331,7 @@ export async function recordDelivery(
277
331
  if (request.requireDelivery && record.deliveries.length === 0) {
278
332
  let suggestedBranch: string | null = null;
279
333
  for (const candidate of [defaultBranch, legacyDeliveryBranch(changeNameOf(change))]) {
280
- if (candidate && (await environment.workingRepo?.git.branchExists(candidate))) {
334
+ if (candidate && (await sessionGit?.branchExists(candidate))) {
281
335
  suggestedBranch = candidate;
282
336
  break;
283
337
  }
@@ -5,6 +5,11 @@ import { parse, stringify } from "yaml";
5
5
  import { errorMessage } from "../../runtime/error-message";
6
6
  import { changeNameOf } from "../change-layout";
7
7
  import { scopedRepositories } from "../openspec-scopes";
8
+ import {
9
+ applyBranchTemplate,
10
+ DEFAULT_BRANCH_TEMPLATE,
11
+ type BranchTemplate,
12
+ } from "./branch-template";
8
13
 
9
14
  /** The Delivery Record's file name at a change root; it moves with the change into its archive. */
10
15
  export const DELIVERY_FILE = "delivery.yaml";
@@ -131,9 +136,16 @@ export function legacyDeliveryWarning(anchorName: string): string {
131
136
  return `${anchorName} has no delivery.yaml, so its merge was not checked; publishing it as a legacy archive.`;
132
137
  }
133
138
 
134
- /** `workset/<workset-id>`, or `workset/<TICKET>-<workset-id>` when a ticket is given. */
135
- export function defaultDeliveryBranch(worksetId: string, ticket?: string | null): string {
136
- return ticket ? `workset/${ticket}-${worksetId}` : `workset/${worksetId}`;
139
+ /**
140
+ * The template's branch for a Workset; with the default template `workset/<workset-id>`, or
141
+ * `workset/<TICKET>-<workset-id>` when a ticket is given.
142
+ */
143
+ export function defaultDeliveryBranch(
144
+ worksetId: string,
145
+ ticket?: string | null,
146
+ template: BranchTemplate = DEFAULT_BRANCH_TEMPLATE,
147
+ ): string {
148
+ return applyBranchTemplate(template, worksetId, ticket);
137
149
  }
138
150
 
139
151
  export function legacyDeliveryBranch(change: string): string {