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

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 (249) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/package.json +6 -3
  3. package/src/cli/commands/artifact/delivery/submit.ts +6 -4
  4. package/src/cli/commands/artifact/finish/command.ts +28 -11
  5. package/src/cli/commands/artifact/pending/command.ts +71 -7
  6. package/src/cli/commands/cap/tokensave.ts +2 -2
  7. package/src/cli/commands/companion/update.ts +2 -3
  8. package/src/cli/commands/doctor.ts +67 -4
  9. package/src/cli/commands/friction.ts +558 -0
  10. package/src/cli/commands/install.ts +8 -4
  11. package/src/cli/commands/plugin/install.ts +82 -35
  12. package/src/cli/commands/studio/connection.ts +53 -0
  13. package/src/cli/commands/studio/routes.ts +3 -0
  14. package/src/cli/commands/studio/selection.ts +10 -1
  15. package/src/cli/commands/studio/server.ts +31 -0
  16. package/src/cli/commands/studio/service-host.ts +3 -0
  17. package/src/cli/commands/studio/services.ts +25 -0
  18. package/src/cli/commands/triage.ts +172 -0
  19. package/src/cli/commands/vscode/release-vsix.json +2 -2
  20. package/src/cli/install-plan.tsx +3 -0
  21. package/src/cli/main.ts +85 -19
  22. package/src/cli/plugin-commands.ts +6 -1
  23. package/src/cli/usage.ts +12 -2
  24. package/src/create-mate.ts +11 -5
  25. package/src/distribution.ts +2 -0
  26. package/src/factory-host.ts +6 -0
  27. package/src/hooks/validate-artifact-path.ts +64 -14
  28. package/src/index.ts +1 -0
  29. package/src/lib/delivery/merge-git.ts +31 -7
  30. package/src/lib/delivery/overlap.ts +14 -1
  31. package/src/lib/delivery/repository-access.ts +11 -6
  32. package/src/lib/delivery/staging/apply-chain.ts +25 -7
  33. package/src/lib/delivery/staging/linked-merges.ts +175 -0
  34. package/src/lib/delivery/staging/naming.ts +3 -0
  35. package/src/lib/delivery/staging/openspec-type.ts +38 -7
  36. package/src/lib/delivery/staging/pending.ts +153 -11
  37. package/src/lib/delivery/staging/preflight.ts +239 -0
  38. package/src/lib/delivery/staging/project.ts +243 -104
  39. package/src/lib/delivery/staging/replay.ts +5 -3
  40. package/src/lib/delivery/staging/settle-linked.ts +5 -119
  41. package/src/lib/delivery/staging/submit.ts +139 -18
  42. package/src/lib/delivery/submit-change.ts +163 -37
  43. package/src/lib/friction/describe.ts +42 -0
  44. package/src/lib/friction/fields.ts +60 -0
  45. package/src/lib/friction/mark.ts +194 -0
  46. package/src/lib/friction/view/model.ts +67 -0
  47. package/src/lib/friction/view/read.ts +145 -0
  48. package/src/lib/friction/view/select.ts +54 -0
  49. package/src/lib/openspec-cli.ts +10 -5
  50. package/src/lib/orchestrator/adapters/claude.ts +5 -4
  51. package/src/lib/orchestrator/adapters/opencode.ts +2 -0
  52. package/src/lib/orchestrator/root-context.ts +23 -6
  53. package/src/lib/package-paths.ts +23 -15
  54. package/src/lib/session-attribution.ts +3 -7
  55. package/src/lib/skills-cli.ts +38 -0
  56. package/src/lib/tool-manifest.ts +73 -0
  57. package/src/lib/triage/context.ts +312 -0
  58. package/src/lib/triage/launch.ts +52 -0
  59. package/src/lib/triage/prepare.ts +112 -0
  60. package/src/lib/triage/session.ts +126 -0
  61. package/src/opencode/companion-hooks.ts +53 -5
  62. package/src/opencode/projected-guidance.ts +2 -0
  63. package/src/playbooks/companion-guidance.ts +2 -2
  64. package/src/plugin-api.ts +6 -0
  65. package/src/runtime/command-arg.ts +15 -0
  66. package/src/runtime/command-friction.ts +97 -0
  67. package/src/runtime/companion-guidance.ts +33 -16
  68. package/src/runtime/friction-fingerprint.ts +35 -0
  69. package/src/runtime/friction-log.ts +376 -0
  70. package/src/runtime/friction-recorder.ts +212 -0
  71. package/src/runtime/friction-retention.ts +1 -0
  72. package/src/runtime/friction-state.ts +110 -0
  73. package/src/runtime/friction-switch.ts +26 -0
  74. package/src/runtime/friction-vocabulary.ts +42 -0
  75. package/src/runtime/git-tracked.ts +13 -2
  76. package/src/runtime/projected-guidance.ts +2 -1
  77. package/src/runtime/secret-values.ts +16 -0
  78. package/src/runtime/session-id.ts +24 -0
  79. package/src/runtime/session-prepare-runner.ts +3 -0
  80. package/src/runtime/workflow/next-handoff-process.ts +2 -1
  81. package/src/studio.ts +47 -1
  82. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +5 -1
  83. package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
  84. package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +42 -4
  85. package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +27 -2
  86. package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
  87. package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +26 -1
  88. package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +28 -0
  89. package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +28 -3
  90. package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
  91. package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
  92. package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
  93. package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
  94. package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +28 -3
  95. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +28 -6
  96. package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +27 -2
  97. package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +28 -0
  98. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +24 -2
  99. package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +42 -4
  100. package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +27 -2
  101. package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
  102. package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +26 -1
  103. package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +28 -0
  104. package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +28 -3
  105. package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
  106. package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
  107. package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
  108. package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
  109. package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +28 -3
  110. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +28 -6
  111. package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +27 -2
  112. package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +28 -0
  113. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +24 -2
  114. package/src/templates/triage/PLAYBOOK.md +120 -0
  115. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +108 -108
  116. package/src/tools/setup/capabilities/graphify.ts +23 -1
  117. package/src/tools/setup/capabilities/rtk.ts +46 -94
  118. package/src/tools/setup/capabilities/tokensave.ts +76 -54
  119. package/src/tools/setup/dynamic-plugins/audiences.ts +28 -14
  120. package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
  121. package/src/tools/setup/dynamic-plugins/install.ts +2 -0
  122. package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
  123. package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
  124. package/src/tools/setup/dynamic-plugins/local.ts +492 -0
  125. package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
  126. package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
  127. package/src/tools/setup/dynamic-plugins/workspaces.ts +17 -8
  128. package/src/tools/setup/mate.ts +26 -1
  129. package/src/tools/setup/plugin.ts +5 -0
  130. package/src/tools/setup/plugins/gitignore.ts +45 -12
  131. package/src/tools/setup/service.ts +12 -0
  132. package/src/tools/setup/utils.ts +10 -1
  133. package/src/tools/setup.ts +16 -2
  134. package/studio-dist/client/assets/app-ggXJ_QVh.css +2 -0
  135. package/studio-dist/client/assets/button-amJ3g5oD.js +1 -0
  136. package/studio-dist/client/assets/cn-BQPKiwI4.js +1 -0
  137. package/studio-dist/client/assets/combobox-CJ7aGFid.js +1 -0
  138. package/studio-dist/client/assets/{companion-view-BVaZNtiI.js → companion-view-C_N237bf.js} +1 -1
  139. package/studio-dist/client/assets/fields-BAiGkJ5N.js +1 -0
  140. package/studio-dist/client/assets/friction-DqOU59v7.js +1 -0
  141. package/studio-dist/client/assets/getting-started-djaQeWlu.js +1 -0
  142. package/studio-dist/client/assets/getting-started-yp42dj5S.js +1 -0
  143. package/studio-dist/client/assets/getting-started._topic-C9zVXz_m.js +1 -0
  144. package/studio-dist/client/assets/getting-started.index-DWbDKICP.js +1 -0
  145. package/studio-dist/client/assets/graph-BYaD_5Bq.js +2 -0
  146. package/studio-dist/client/assets/{graph-canvas-DDuzsNSx.js → graph-canvas-ySGKMhmk.js} +1 -1
  147. package/studio-dist/client/assets/guides-D6T6W_jV.js +1 -0
  148. package/studio-dist/client/assets/index-Qx7reRPD.js +40 -0
  149. package/studio-dist/client/assets/markdown-view-jMiaBTSO.js +1 -0
  150. package/studio-dist/client/assets/panel-C4bf_h2W.js +1 -0
  151. package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +1 -0
  152. package/studio-dist/client/assets/prepaint-CKsXyJOR.js +27 -0
  153. package/studio-dist/client/assets/{queries-axYk2u9L.js → queries-Dfp5deWj.js} +1 -1
  154. package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
  155. package/studio-dist/client/assets/reports-JFSwSueq.js +1 -0
  156. package/studio-dist/client/assets/routes-BdOWSgzK.js +1 -0
  157. package/studio-dist/client/assets/search-CXosfvYh.js +1 -0
  158. package/studio-dist/client/assets/select-BHYYWPhK.js +1 -0
  159. package/studio-dist/client/assets/skills-Bo9FLsBd.js +1 -0
  160. package/studio-dist/client/assets/{specs-DU1kqcp5.js → specs-BrCOjOch.js} +1 -1
  161. package/studio-dist/client/assets/specs-view-CdE2rlli.js +1 -0
  162. package/studio-dist/client/assets/{steps-DhIFuAZy.js → steps-CKUno4lh.js} +1 -1
  163. package/studio-dist/client/assets/store-C3vJq8Wj.js +1 -0
  164. package/studio-dist/client/assets/{studio-BR9j15J0.js → studio-0ueISxwP.js} +8 -8
  165. package/studio-dist/client/assets/{studio-queries-CFP_yTpr.js → studio-queries-BflKt9va.js} +2 -2
  166. package/studio-dist/client/assets/{usage-CHmwtkoM.js → usage-BLsLy0nN.js} +16 -16
  167. package/studio-dist/client/assets/useAnchoredPopupScrollLock-DC7f8GOp.js +1 -0
  168. package/studio-dist/client/assets/useMutation-uJUrejsi.js +1 -0
  169. package/studio-dist/client/assets/vault-BB1B_OhR.js +1 -0
  170. package/studio-dist/client/assets/warnings-CqOOGlPD.js +1 -0
  171. package/studio-dist/client/assets/workflow-BFzmI-06.js +1 -0
  172. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-DAbZ6fzY.js → __23tanstack-start-server-fn-resolver-gVfW5vIV.js} +30 -14
  173. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +66 -50
  174. package/studio-dist/server/assets/{button-BfoNadNR.js → button-D6bvrFmm.js} +226 -3478
  175. package/studio-dist/server/assets/cn-FXJAM0KO.js +5528 -0
  176. package/studio-dist/server/assets/combobox-D2MbYV1O.js +484 -0
  177. package/studio-dist/server/assets/{companion-view-DHUjPpA0.js → companion-view-Mf1ANbMb.js} +2 -2
  178. package/studio-dist/server/assets/{companions-kBrJZAd6.js → companions-Dr6IpNAb.js} +1 -1
  179. package/studio-dist/server/assets/{fields-BD_c65T1.js → fields-B4mAPETz.js} +2 -1
  180. package/studio-dist/server/assets/friction-9a5S1m7U.js +943 -0
  181. package/studio-dist/server/assets/friction-CWOTjpCV.js +62 -0
  182. package/studio-dist/server/assets/{getting-started-7P0oyWaM.js → getting-started-RU6tYU2Q.js} +2 -2
  183. package/studio-dist/server/assets/{getting-started._topic-B1mV0kGz.js → getting-started._topic-C02HGrC6.js} +2 -2
  184. package/studio-dist/server/assets/{getting-started.index-CeGtvUsm.js → getting-started.index-EzLRosbb.js} +2 -2
  185. package/studio-dist/server/assets/{graph-BWtmJOH2.js → graph-B11ITte0.js} +1 -1
  186. package/studio-dist/server/assets/{graph-DSDVEELZ.js → graph-CZ2H9Fzr.js} +8 -8
  187. package/studio-dist/server/assets/{graph-canvas-CID9Nksc.js → graph-canvas-rP5TT14Z.js} +2 -2
  188. package/studio-dist/server/assets/{guides-Bm3RbUB-.js → guides-B8HdeK_C.js} +1 -1
  189. package/studio-dist/server/assets/{guides-BLJenHwQ.js → guides-BGftp4wf.js} +1 -1
  190. package/studio-dist/server/assets/{guides.server-rHHqRuzV.js → guides.server-DqFQAStf.js} +1 -1
  191. package/studio-dist/server/assets/{markdown-view-D3v9x-cM.js → markdown-view-CArpV-CS.js} +1 -1
  192. package/studio-dist/server/assets/{panel-yqOl5GMU.js → panel-DR0iq46J.js} +4 -3
  193. package/studio-dist/server/assets/{plugins._service._view-DwqJX7s9.js → plugins._service._view-n7u2k5dF.js} +11 -6
  194. package/studio-dist/server/assets/prepaint-B28ClcPN.js +45 -0
  195. package/studio-dist/server/assets/{queries-DYmGrhNO.js → queries-D-yVP9i0.js} +1 -1
  196. package/studio-dist/server/assets/react-CiBZPDs8.js +45 -0
  197. package/studio-dist/server/assets/{reports-C4Y_Jd-x.js → reports-B9k98oE6.js} +1 -1
  198. package/studio-dist/server/assets/{reports-7yaPz7aP.js → reports-C2SmTgqh.js} +7 -7
  199. package/studio-dist/server/assets/{router-Dnoq5auE.js → router-CPt0TAk_.js} +654 -1565
  200. package/studio-dist/server/assets/{routes-Cok4p3mK.js → routes-CwH8LEy2.js} +8 -8
  201. package/studio-dist/server/assets/{search-DUK7Jl6f.js → search-b-yQesv3.js} +25 -2
  202. package/studio-dist/server/assets/{combobox-oxUI6r4V.js → select-C3i6TTX-.js} +35 -514
  203. package/studio-dist/server/assets/{shell-DNVXedgE.js → shell-CagqZZMZ.js} +4 -3
  204. package/studio-dist/server/assets/{skills-D8qdXSku.js → skills-C21Mg_8-.js} +8 -8
  205. package/studio-dist/server/assets/{skills-pKmuAs0F.js → skills-DGg0mWDM.js} +1 -1
  206. package/studio-dist/server/assets/{specs-DeHYUNFp.js → specs-DetoMiaB.js} +4 -4
  207. package/studio-dist/server/assets/{specs-view-BGn-5Ik_.js → specs-view-CmbfLDwN.js} +10 -9
  208. package/studio-dist/server/assets/{steps-CV7Yk7L7.js → steps-D1tYAyWZ.js} +1 -1
  209. package/studio-dist/server/assets/store-aC-I6f6o.js +93 -0
  210. package/studio-dist/server/assets/{studio-CB94np48.js → studio-qRvQjRpz.js} +47 -2
  211. package/studio-dist/server/assets/{studio-queries-BqZGBE70.js → studio-queries-Dqf-3nzj.js} +66 -8
  212. package/studio-dist/server/assets/{usage-M6Gi6Km7.js → usage-CS4CBK9D.js} +13 -44
  213. package/studio-dist/server/assets/{usage-j5jR9gX9.js → usage-Cwle9-xY.js} +1 -1
  214. package/studio-dist/server/assets/useAnchoredPopupScrollLock-BjMNgXv9.js +756 -0
  215. package/studio-dist/server/assets/useMutation-DpBIuWXt.js +690 -0
  216. package/studio-dist/server/assets/{vault-lBlvSyD4.js → vault-CEBBRLMb.js} +1 -1
  217. package/studio-dist/server/assets/{vault-PqVmssmW.js → vault-DVQidlId.js} +6 -6
  218. package/studio-dist/server/assets/{views-CsFp1i1G.js → views-UgO0Qz_g.js} +2 -2
  219. package/studio-dist/server/assets/{warnings-BDs34j_m.js → warnings-C7hgXpdk.js} +2 -2
  220. package/studio-dist/server/assets/{workflow-T0eEldsa.js → workflow-6dZZ1ofw.js} +9 -9
  221. package/studio-dist/server/server.js +2 -2
  222. package/tool-manifest.yaml +85 -0
  223. package/studio-dist/client/assets/app-BFVyWHGo.css +0 -2
  224. package/studio-dist/client/assets/button-D6LrRkOG.js +0 -1
  225. package/studio-dist/client/assets/combobox-Dk2MMZWE.js +0 -1
  226. package/studio-dist/client/assets/fields-D_FYhxQr.js +0 -1
  227. package/studio-dist/client/assets/getting-started-ByWRg7hC.js +0 -1
  228. package/studio-dist/client/assets/getting-started-DZSjYC-b.js +0 -1
  229. package/studio-dist/client/assets/getting-started._topic-C6OyQ4G6.js +0 -1
  230. package/studio-dist/client/assets/getting-started.index-BkmPHdEm.js +0 -1
  231. package/studio-dist/client/assets/graph-7jm2XzyL.js +0 -2
  232. package/studio-dist/client/assets/guides-D9VTjWXP.js +0 -1
  233. package/studio-dist/client/assets/index-BBmFpG4y.js +0 -40
  234. package/studio-dist/client/assets/markdown-view-RL5YvfZg.js +0 -1
  235. package/studio-dist/client/assets/panel-B8F8sOKQ.js +0 -1
  236. package/studio-dist/client/assets/plugins._service._view-CynxTbMx.js +0 -1
  237. package/studio-dist/client/assets/react-r45OnJCw.js +0 -27
  238. package/studio-dist/client/assets/reports-BCAyXh6p.js +0 -1
  239. package/studio-dist/client/assets/routes-BFPqq89E.js +0 -1
  240. package/studio-dist/client/assets/skills-DTks_uBx.js +0 -1
  241. package/studio-dist/client/assets/specs-view-omrd_5P3.js +0 -1
  242. package/studio-dist/client/assets/store-DJ5cncKA.js +0 -1
  243. package/studio-dist/client/assets/useBaseQuery-BlC-AZ35.js +0 -1
  244. package/studio-dist/client/assets/vault-DRg8MScm.js +0 -1
  245. package/studio-dist/client/assets/warnings-UHFy6HAp.js +0 -1
  246. package/studio-dist/client/assets/workflow-Bv9vSfVV.js +0 -1
  247. package/studio-dist/server/assets/react-BO0uMhpm.js +0 -89
  248. package/studio-dist/server/assets/store-CWDGIp6x.js +0 -280
  249. package/studio-dist/server/assets/useBaseQuery-Tv_QJt9r.js +0 -2051
@@ -16,9 +16,22 @@ import { errorMessage } from "../../../runtime/error-message";
16
16
  import { inboxText } from "../../../runtime/pending-records";
17
17
  import { declaredDependencies } from "../overlap";
18
18
  import { isCommitId, readDeliveryRecord } from "../record";
19
- import { applyChain, describeFailure, failureRemedy, isChainFailure } from "./apply-chain";
19
+ import {
20
+ applyChain,
21
+ describeFailure,
22
+ failureRemedy,
23
+ isChainFailure,
24
+ type AppliedChain,
25
+ type ChainFailure,
26
+ } from "./apply-chain";
20
27
  import { sourceDir, type ArtifactType } from "./artifact-type";
21
- import { deltaBase, orderByDependencies, submittedAt, type SubmittedChange } from "./pending";
28
+ import {
29
+ deltaBase,
30
+ orderByDependencies,
31
+ sourcePathOf,
32
+ submittedAt,
33
+ type SubmittedChange,
34
+ } from "./pending";
22
35
  import {
23
36
  anchorsAt,
24
37
  defaultRef,
@@ -28,6 +41,7 @@ import {
28
41
  type StagingRemote,
29
42
  } from "./refs";
30
43
  import { defaultArtifactType } from "./registry";
44
+ import { acceptsBlock } from "./submit";
31
45
  import { assertNoLinkedContent, WITHOUT_HOOKS, withTemporaryWorktree } from "./worktree";
32
46
 
33
47
  /** Bound on one projection, the optional fetch included. */
@@ -70,52 +84,73 @@ export interface ProjectDeps {
70
84
  const defaultGit = (cwd: string): CompanionGit =>
71
85
  companionGit(cwd, { prompt: "never", budgetMs: PROJECTION_BUDGET_MS });
72
86
 
73
- interface ChainMember {
87
+ /** A change a chain run applies, read from this checkout or the pending branch. */
88
+ export interface RunMember {
74
89
  name: string;
75
90
  source: ChainSource;
76
91
  dependsOn: string[];
77
92
  /** The submitted copy, for its delta base; absent for a local change. */
78
93
  submitted?: SubmittedChange;
94
+ /**
95
+ * A blocked change submitted again: when submit accepts the block, the default tip is its base.
96
+ * Set on a submitted copy only once submit is known to accept it.
97
+ */
98
+ rebased?: boolean;
99
+ }
100
+
101
+ /** Read from this checkout when `local` (its `dependsOn`) is set, else from `copy`. */
102
+ export function runMember(name: string, local: string[] | null, copy?: SubmittedChange): RunMember {
103
+ return {
104
+ name,
105
+ source: local !== null ? "local" : "submitted",
106
+ dependsOn: local ?? copy?.dependsOn ?? [],
107
+ ...(copy ? { submitted: copy } : {}),
108
+ };
79
109
  }
80
110
 
81
111
  function failed(change: string, status: "conflict" | "error", message: string): ProjectionResult {
82
112
  return { status, change, chain: [], dir: null, files: [], message };
83
113
  }
84
114
 
85
- /**
86
- * The canonical files as they will read once change `name`'s `dependsOn` chain is published:
87
- * the chain, from this checkout or the pending branch, is applied in dependency order in a
88
- * temporary worktree of the default branch with publication's apply code, and the files it
89
- * changes are copied to a temporary folder. Commits and pushes nothing and leaves the checkout
90
- * untouched; a chain publication would refuse fails with publication's reason. Never throws.
91
- */
92
- export async function projectChange(
93
- companionPath: string,
94
- name: string,
95
- deps: ProjectDeps = {},
96
- ): Promise<ProjectionResult> {
97
- if (!isChangeName(name)) return failed(name, "error", `mate: "${name}" is no change name.`);
98
- try {
99
- return await project(companionPath, name, deps);
100
- } catch (error) {
101
- return failed(name, "error", `mate: projecting ${name} failed. ${errorMessage(error)}`);
102
- }
115
+ /** What a chain run reads: this checkout, and the default and pending branches as last fetched. */
116
+ export interface ChainContext {
117
+ companionPath: string;
118
+ type: ArtifactType;
119
+ gitFor: (cwd: string) => CompanionGit;
120
+ git: CompanionGit;
121
+ remote: StagingRemote | null;
122
+ /** The default branch, or `HEAD` without one. */
123
+ baseRef: string;
124
+ /** The changes on the pending branch, in submit order. */
125
+ submitted: SubmittedChange[];
126
+ /** Change names the default branch archived. */
127
+ published: ReadonlySet<string>;
128
+ /** Why the refs are the last fetched ones, as a message suffix; empty otherwise. */
129
+ warning: string;
130
+ /** The failed fetch's error that {@link warning} wraps. */
131
+ fetchError?: string;
132
+ tmpRoot?: string;
133
+ /** The `dependsOn` of a change in this checkout; null when it has no folder here. */
134
+ localDependencies: (change: string) => Promise<string[] | null>;
103
135
  }
104
136
 
105
- async function project(
137
+ /** Reads the {@link ChainContext} of `companionPath`, fetching first with `deps.fetch`. */
138
+ export async function chainContext(
106
139
  companionPath: string,
107
- name: string,
108
- deps: ProjectDeps,
109
- ): Promise<ProjectionResult> {
140
+ deps: ProjectDeps = {},
141
+ ): Promise<ChainContext> {
110
142
  const type = deps.artifactType ?? defaultArtifactType(deps.runOpenSpec);
111
143
  const gitFor = deps.git ?? defaultGit;
112
144
  const git = gitFor(companionPath);
113
145
  let remote: StagingRemote | null = await stagingRemote(git);
114
146
  let warning = "";
147
+ let fetchError: string | undefined;
115
148
  if (remote && deps.fetch) {
116
149
  const fetched = await fetchPendingBranches(git, remote);
117
- if ("error" in fetched) warning = ` (${fetched.error}; read the last fetched state)`;
118
- else remote = fetched;
150
+ if ("error" in fetched) {
151
+ fetchError = fetched.error;
152
+ warning = ` (${fetched.error}; read the last fetched state)`;
153
+ } else remote = fetched;
119
154
  }
120
155
  const baseRef =
121
156
  remote &&
@@ -124,48 +159,80 @@ async function project(
124
159
  : "HEAD";
125
160
  const submitted = remote ? await submittedAt(git, pendingRef(remote), type, deps.tmpRoot) : [];
126
161
  const published = new Set((await anchorsAt(git, baseRef, type)).map((id) => type.recordName(id)));
127
-
128
- const localDependencies = async (change: string): Promise<string[] | null> => {
129
- const dir = sourceDir(companionPath, type, change);
130
- return (await pathIsDirectory(dir)) ? declaredDependencies(dir) : null;
162
+ return {
163
+ companionPath,
164
+ type,
165
+ gitFor,
166
+ git,
167
+ remote,
168
+ baseRef,
169
+ submitted,
170
+ published,
171
+ warning,
172
+ ...(fetchError ? { fetchError } : {}),
173
+ ...(deps.tmpRoot ? { tmpRoot: deps.tmpRoot } : {}),
174
+ localDependencies: async (change) => {
175
+ const dir = sourceDir(companionPath, type, change);
176
+ return (await pathIsDirectory(dir)) ? declaredDependencies(dir) : null;
177
+ },
131
178
  };
132
- const own =
133
- (await localDependencies(name)) ??
134
- submitted.find((change) => change.name === name)?.dependsOn ??
135
- null;
136
- if (own === null) {
137
- return failed(name, "error", `mate: no change named ${name} here or on the pending branch.`);
138
- }
179
+ }
139
180
 
140
- const { chain, missing } = await collectChain(name, own, submitted, published, localDependencies);
141
- if (missing.length > 0) {
142
- return failed(
143
- name,
144
- "error",
145
- `mate: ${name} depends on ${missing.map(inboxText).join(", ")}, which is neither here, submitted nor published.`,
146
- );
147
- }
181
+ /**
182
+ * - `missing`: a dependency is neither here, submitted nor published; nothing was applied
183
+ * - `empty`: nothing to apply
184
+ * - `conflict`: publication would refuse the run, for `failure`
185
+ */
186
+ export type ChainRun<T> =
187
+ | { status: "missing"; missing: string[] }
188
+ | { status: "empty" }
189
+ | {
190
+ status: "conflict";
191
+ chain: ProjectionResult["chain"];
192
+ failure: ChainFailure;
193
+ branch: string;
194
+ }
195
+ | { status: "ok"; chain: ProjectionResult["chain"]; value: T };
196
+
197
+ /**
198
+ * Applies, in a temporary worktree of the default branch and with publication's apply code, the
199
+ * unpublished `dependsOn` chain `dependencies` reach, then `members` as publication orders a
200
+ * group: `dependsOn` among them, then their given order. Neither `members` nor `exclude` join
201
+ * the chain. `onApplied` reads the worktree before it is removed. Commits and pushes nothing.
202
+ */
203
+ export async function runChain<T>(
204
+ context: ChainContext,
205
+ input: {
206
+ dependencies: readonly string[];
207
+ members?: readonly RunMember[];
208
+ exclude?: readonly string[];
209
+ },
210
+ onApplied: (dir: string, applied: AppliedChain) => Promise<T>,
211
+ ): Promise<ChainRun<T>> {
212
+ const { companionPath, type, gitFor, git, remote, baseRef } = context;
213
+ const members = orderByDependencies(input.members ?? []);
214
+ const exclude = new Set([...(input.exclude ?? []), ...members.map((member) => member.name)]);
215
+ const { chain, missing } = await collectChain(
216
+ exclude,
217
+ input.dependencies,
218
+ context.submitted,
219
+ context.published,
220
+ context.localDependencies,
221
+ );
222
+ if (missing.length > 0) return { status: "missing", missing };
148
223
  const ordered = orderByDependencies(chain);
149
224
  const reported = ordered.map((member) => ({ name: member.name, source: member.source }));
150
- if (ordered.length === 0) {
151
- return {
152
- status: "ok",
153
- change: name,
154
- chain: [],
155
- dir: null,
156
- files: [],
157
- message: `${name} depends on no unpublished change; the canonical files apply as they are.${warning}`,
158
- };
159
- }
225
+ const applying = [...ordered, ...members];
226
+ if (applying.length === 0) return { status: "empty" };
160
227
 
161
228
  return withTemporaryWorktree(
162
229
  companionPath,
163
230
  baseRef,
164
- async (dir) => {
231
+ async (dir): Promise<ChainRun<T>> => {
165
232
  const work = gitFor(dir);
166
233
  const start = (await work.run(["rev-parse", "HEAD"])).stdout.trim();
167
234
  const pending = remote ? pendingRef(remote) : null;
168
- await stageChain(work, companionPath, dir, type, ordered, pending);
235
+ await stageChain(work, companionPath, dir, type, applying, pending);
169
236
  // A scaffold commit the stale check reads the chain from; it never leaves this worktree.
170
237
  await work.run(["add", "-f", "-A"]);
171
238
  const scaffold = await work.run([
@@ -183,25 +250,37 @@ async function project(
183
250
  if (scaffold.status !== 0) throw new Error(describeGitFailure(scaffold));
184
251
  // The worktree checked only the base; the pending branch's folders arrived since.
185
252
  await assertNoLinkedContent(work, "HEAD", [type], "the projected chain");
253
+ const baseOf = async (member: RunMember): Promise<string | null> => {
254
+ if (member.source === "submitted" && member.submitted && remote && pending) {
255
+ return deltaBase(git, defaultRef(remote), pending, member.submitted, type);
256
+ }
257
+ const record = await readDeliveryRecord(sourceDir(dir, type, member.name)).catch(
258
+ () => null,
259
+ );
260
+ const base = record?.specBase;
261
+ if (!base || !isCommitId(base)) return null;
262
+ // Where submit's record puts it, and publication reads it from.
263
+ const shared = await work.run(["merge-base", base, start]);
264
+ const commit = shared.stdout.trim();
265
+ return shared.status === 0 && isCommitId(commit) ? commit : null;
266
+ };
186
267
  const bases = await Promise.all(
187
- ordered.map(async (member) => {
188
- if (member.submitted && remote && pending) {
189
- return deltaBase(git, defaultRef(remote), pending, member.submitted, type);
190
- }
191
- const record = await readDeliveryRecord(sourceDir(dir, type, member.name)).catch(
192
- () => null,
193
- );
194
- const base = record?.specBase;
195
- if (!base || !isCommitId(base)) return null;
196
- const held = await work.run(["merge-base", "--is-ancestor", base, start]);
197
- return held.status === 0 ? base : null;
268
+ applying.map(async (member) => {
269
+ const base = await baseOf(member);
270
+ const folder = sourcePathOf(type, member.name);
271
+ // Submit then moves the base to the tip, as it does for an accepted block.
272
+ const accepted =
273
+ member.rebased === true &&
274
+ (member.source === "submitted" ||
275
+ (base !== null && (await acceptsBlock(type, work, "HEAD", folder, base, start))));
276
+ return accepted ? null : base;
198
277
  }),
199
278
  );
200
279
  const applied = await applyChain({
201
280
  type,
202
281
  work,
203
282
  dir,
204
- members: ordered.map((member, index) => ({
283
+ members: applying.map((member, index) => ({
205
284
  name: member.name,
206
285
  base: bases[index] ?? null,
207
286
  })),
@@ -210,50 +289,115 @@ async function project(
210
289
  });
211
290
  if (isChainFailure(applied)) {
212
291
  const branch = remote?.defaultBranch ?? "the default branch";
213
- return {
214
- ...failed(
215
- name,
216
- "conflict",
217
- `mate: ${name}'s dependencies cannot be published: ${describeFailure(applied, branch)}. ${failureRemedy(applied)}`,
218
- ),
219
- chain: reported,
220
- };
292
+ return { status: "conflict", chain: reported, failure: applied, branch };
221
293
  }
222
- const derived = applied.changed.filter(
223
- (file) =>
224
- !file.startsWith(`${type.source}/`) &&
225
- (type.archiveRoot === undefined || !file.startsWith(`${type.archiveRoot}/`)),
226
- );
227
- const { out, files } = await writeProjection(dir, derived, deps.outRoot ?? os.tmpdir());
228
- return {
229
- status: "ok",
230
- change: name,
231
- chain: reported,
232
- dir: out,
233
- files,
234
- message: `Projected ${files.length} file${files.length === 1 ? "" : "s"} once ${reported.map((member) => member.name).join(", ")} ${reported.length === 1 ? "is" : "are"} published, in ${out}.${warning}`,
235
- };
294
+ return { status: "ok", chain: reported, value: await onApplied(dir, applied) };
236
295
  },
237
- { git: gitFor, types: [type], ...(deps.tmpRoot ? { tmpRoot: deps.tmpRoot } : {}) },
296
+ { git: gitFor, types: [type], ...(context.tmpRoot ? { tmpRoot: context.tmpRoot } : {}) },
238
297
  );
239
298
  }
240
299
 
300
+ /**
301
+ * The canonical files as they will read once change `name`'s `dependsOn` chain is published:
302
+ * the chain, from this checkout or the pending branch, is applied in dependency order in a
303
+ * temporary worktree of the default branch with publication's apply code, and the files it
304
+ * changes are copied to a temporary folder. Commits and pushes nothing and leaves the checkout
305
+ * untouched; a chain publication would refuse fails with publication's reason. Never throws.
306
+ */
307
+ export async function projectChange(
308
+ companionPath: string,
309
+ name: string,
310
+ deps: ProjectDeps = {},
311
+ ): Promise<ProjectionResult> {
312
+ if (!isChangeName(name)) return failed(name, "error", `mate: "${name}" is no change name.`);
313
+ try {
314
+ return await project(companionPath, name, deps);
315
+ } catch (error) {
316
+ return failed(name, "error", `mate: projecting ${name} failed. ${errorMessage(error)}`);
317
+ }
318
+ }
319
+
320
+ async function project(
321
+ companionPath: string,
322
+ name: string,
323
+ deps: ProjectDeps,
324
+ ): Promise<ProjectionResult> {
325
+ const context = await chainContext(companionPath, deps);
326
+ const { type, warning } = context;
327
+ const own =
328
+ (await context.localDependencies(name)) ??
329
+ context.submitted.find((change) => change.name === name)?.dependsOn ??
330
+ null;
331
+ if (own === null) {
332
+ return failed(name, "error", `mate: no change named ${name} here or on the pending branch.`);
333
+ }
334
+
335
+ const run = await runChain(context, { dependencies: own, exclude: [name] }, (dir, applied) => {
336
+ const derived = applied.changed.filter(
337
+ (file) =>
338
+ !file.startsWith(`${type.source}/`) &&
339
+ (type.archiveRoot === undefined || !file.startsWith(`${type.archiveRoot}/`)),
340
+ );
341
+ return writeProjection(dir, derived, deps.outRoot ?? os.tmpdir());
342
+ });
343
+ if (run.status === "missing") {
344
+ return failed(
345
+ name,
346
+ "error",
347
+ `mate: ${name} depends on ${run.missing.map(inboxText).join(", ")}, which is neither here, submitted nor published.`,
348
+ );
349
+ }
350
+ if (run.status === "empty") {
351
+ return {
352
+ status: "ok",
353
+ change: name,
354
+ chain: [],
355
+ dir: null,
356
+ files: [],
357
+ message: `${name} depends on no unpublished change; the canonical files apply as they are.${warning}`,
358
+ };
359
+ }
360
+
361
+ if (run.status === "conflict") {
362
+ return {
363
+ ...failed(
364
+ name,
365
+ "conflict",
366
+ `mate: ${name}'s dependencies cannot be published: ${describeFailure(run.failure, run.branch)}. ${failureRemedy(run.failure)}`,
367
+ ),
368
+ chain: run.chain,
369
+ };
370
+ }
371
+ const { chain } = run;
372
+ const { out, files } = run.value;
373
+ return {
374
+ status: "ok",
375
+ change: name,
376
+ chain,
377
+ dir: out,
378
+ files,
379
+ message: `Projected ${files.length} file${files.length === 1 ? "" : "s"} once ${chain.map((member) => member.name).join(", ")} ${chain.length === 1 ? "is" : "are"} published, in ${out}.${warning}`,
380
+ };
381
+ }
382
+
241
383
  /**
242
384
  * The unpublished changes `dependencies` reach, transitively and depth first, and those found
243
385
  * neither here, submitted nor published. A submitted change also present here is read locally.
386
+ * Those in `exclude` are passed over.
244
387
  */
245
388
  async function collectChain(
246
- name: string,
389
+ exclude: ReadonlySet<string>,
247
390
  dependencies: readonly string[],
248
391
  submitted: readonly SubmittedChange[],
249
392
  published: ReadonlySet<string>,
250
393
  localDependencies: (change: string) => Promise<string[] | null>,
251
- ): Promise<{ chain: ChainMember[]; missing: string[] }> {
252
- const chain: ChainMember[] = [];
394
+ ): Promise<{ chain: RunMember[]; missing: string[] }> {
395
+ const chain: RunMember[] = [];
253
396
  const missing: string[] = [];
254
397
  const visit = async (next: readonly string[]): Promise<void> => {
255
398
  for (const dependency of next) {
256
- if (dependency === name || chain.some((member) => member.name === dependency)) continue;
399
+ if (exclude.has(dependency) || chain.some((member) => member.name === dependency)) continue;
400
+ if (missing.includes(dependency)) continue;
257
401
  const copy = submitted.find((change) => change.name === dependency);
258
402
  // oxlint-disable-next-line no-await-in-loop -- a short chain
259
403
  const local = await localDependencies(dependency);
@@ -262,12 +406,7 @@ async function collectChain(
262
406
  missing.push(dependency);
263
407
  continue;
264
408
  }
265
- const member: ChainMember = {
266
- name: dependency,
267
- source: local !== null ? "local" : "submitted",
268
- dependsOn: local ?? copy!.dependsOn,
269
- ...(copy ? { submitted: copy } : {}),
270
- };
409
+ const member = runMember(dependency, local, copy);
271
410
  chain.push(member);
272
411
  // oxlint-disable-next-line no-await-in-loop -- depth first
273
412
  await visit(member.dependsOn);
@@ -283,7 +422,7 @@ async function stageChain(
283
422
  companionPath: string,
284
423
  dir: string,
285
424
  type: ArtifactType,
286
- ordered: readonly ChainMember[],
425
+ ordered: readonly RunMember[],
287
426
  pending: string | null,
288
427
  ): Promise<void> {
289
428
  for (const member of ordered) {
@@ -11,6 +11,8 @@ import { endsRequirements, REQUIREMENT_HEADER } from "./requirement-blocks";
11
11
  export interface DeltaFailure {
12
12
  capability: string;
13
13
  requirement: string;
14
+ /** Why OpenSpec refused the delta, as it said, e.g. `not found`. */
15
+ reason?: string;
14
16
  /**
15
17
  * For a requirement changed since the delta base, the three texts to resolve it from: the
16
18
  * requirement at the base, the delta's version (null when the delta removes it or renames it
@@ -39,13 +41,13 @@ function lastLines(text: string, count = 5): string {
39
41
  return text.trim().split("\n").slice(-count).join("\n");
40
42
  }
41
43
 
42
- /** The delta named in OpenSpec's `<capability> <SECTION> failed for header "..."` line. */
44
+ /** The delta named in OpenSpec's `<capability> <SECTION> failed for header "..." - <reason>` line. */
43
45
  export function deltaFailure(output: string): DeltaFailure | null {
44
46
  const match =
45
- /^(\S+) (?:ADDED|MODIFIED|REMOVED|RENAMED) failed for header "### Requirement: (.+?)"/m.exec(
47
+ /^(\S+) (?:ADDED|MODIFIED|REMOVED|RENAMED) failed for header "### Requirement: (.+?)"(?: - (.+))?/m.exec(
46
48
  output,
47
49
  );
48
- return match ? { capability: match[1]!, requirement: match[2]! } : null;
50
+ return match ? { capability: match[1]!, requirement: match[2]!, reason: match[3] } : null;
49
51
  }
50
52
 
51
53
  /** The canonical spec file of `capability`, relative to the companion root. */
@@ -10,18 +10,9 @@ import {
10
10
  import { errorMessage } from "../../../runtime/error-message";
11
11
  import type { PublicationSecretScan } from "../../../runtime/publication-secret-scan";
12
12
  import { linkedDeliveryEnvironment, type DeliveryEnvironment } from "../environment";
13
- import {
14
- findDelivery,
15
- readDeliveryRecord,
16
- upsertDelivery,
17
- writeDeliveryRecord,
18
- type Delivery,
19
- type DeliveryPatch,
20
- type DeliveryRecord,
21
- } from "../record";
22
- import { isSettled, refreshRecord, type RefreshCache } from "../refresh";
23
- import { repositoryAccessFor, type RepositoryAccessDeps } from "../repository-access";
13
+ import { findDelivery, readDeliveryRecord, upsertDelivery, writeDeliveryRecord } from "../record";
24
14
  import { sourceDir, type ArtifactType } from "./artifact-type";
15
+ import { findLinkedMerges, settleable, type FindLinkedMergesDeps } from "./linked-merges";
25
16
  import { commitToPending } from "./pending-edit";
26
17
  import { sourcePathOf, submittedAt } from "./pending";
27
18
  import {
@@ -36,7 +27,7 @@ import { defaultArtifactType } from "./registry";
36
27
  /** Bound on the pending-branch fetches and the push; the merge checks have their own. */
37
28
  const SETTLE_BUDGET_MS = 60_000;
38
29
 
39
- export interface SettleLinkedDeps extends RepositoryAccessDeps {
30
+ export interface SettleLinkedDeps extends Omit<FindLinkedMergesDeps, "onUnchecked"> {
40
31
  git?: (cwd: string) => CompanionGit;
41
32
  artifactType?: ArtifactType;
42
33
  /** Scans the records a merge is written into; the publication scan by default. */
@@ -57,13 +48,6 @@ export interface SettleLinkedResult {
57
48
  warning: string | null;
58
49
  }
59
50
 
60
- /** A merge found for one delivery, applied to the record as the pending branch holds it. */
61
- interface FoundMerge {
62
- repository: string;
63
- branch: string;
64
- patch: DeliveryPatch;
65
- }
66
-
67
51
  const defaultGit = (cwd: string): CompanionGit =>
68
52
  companionGit(cwd, { prompt: "never", budgetMs: SETTLE_BUDGET_MS });
69
53
 
@@ -98,16 +82,6 @@ function failed(error: unknown): SettleLinkedResult {
98
82
  return { recorded: [], warning: `settling merges failed: ${errorMessage(error)}` };
99
83
  }
100
84
 
101
- /** A delivery a linked checkout may settle: a branch, not direct, not merged or dropped yet. */
102
- function settleable(delivery: Delivery): delivery is Delivery & { branch: string } {
103
- return (
104
- delivery.notApplicable === undefined &&
105
- Boolean(delivery.branch) &&
106
- !delivery.direct &&
107
- !isSettled(delivery)
108
- );
109
- }
110
-
111
85
  /**
112
86
  * Settles the deliveries of submitted changes whose repositories are linked on this machine and
113
87
  * records each newly found Git merge in the change's Delivery Record on the pending branch: one
@@ -138,7 +112,8 @@ async function settle(
138
112
  if ("error" in fetched) return { recorded: [], warning: `settling merges: ${fetched.error}` };
139
113
  const type = deps.artifactType ?? environment.artifactType ?? defaultArtifactType();
140
114
 
141
- const found = await findMerges(environment, git, fetched, type, deps);
115
+ const submitted = await submittedAt(git, pendingRef(fetched), type, deps.tmpRoot);
116
+ const found = await findLinkedMerges(environment, submitted, deps);
142
117
  if (found.size === 0 || deps.signal?.aborted) return { recorded: [], warning: null };
143
118
 
144
119
  const recorded: string[] = [];
@@ -199,92 +174,3 @@ async function settle(
199
174
  function recordFailure(remote: StagingRemote, result: Parameters<typeof describeGitFailure>[0]) {
200
175
  return `recording merges on ${pendingPlace(remote)} failed; the next settlement tries again. ${describeGitFailure(result)}`;
201
176
  }
202
-
203
- /** One linked delivery to check, numbered in submit order. */
204
- interface Check {
205
- index: number;
206
- change: string;
207
- record: DeliveryRecord;
208
- repository: string;
209
- }
210
-
211
- /**
212
- * Merges Git proves for linked deliveries of the submitted changes, by change name in submit
213
- * order. Repositories are checked side by side; one repository's checks run in turn, since
214
- * concurrent fetches into one checkout contend for its refs.
215
- */
216
- async function findMerges(
217
- environment: DeliveryEnvironment,
218
- git: CompanionGit,
219
- remote: StagingRemote,
220
- type: ArtifactType,
221
- deps: SettleLinkedDeps,
222
- ): Promise<Map<string, FoundMerge[]>> {
223
- const submitted = await submittedAt(git, pendingRef(remote), type, deps.tmpRoot);
224
- const access = repositoryAccessFor(environment, deps);
225
- const linked = new Map<string, Promise<boolean>>();
226
- const isLinked = (repository: string): Promise<boolean> => {
227
- const key = repository.toLowerCase();
228
- let known = linked.get(key);
229
- if (!known) {
230
- known = (environment.checkoutOf?.(repository) ?? Promise.resolve(null)).then(Boolean);
231
- linked.set(key, known);
232
- }
233
- return known;
234
- };
235
- const checks: Check[] = [];
236
- const queues = new Map<string, Check[]>();
237
- for (const change of submitted) {
238
- const record = change.delivery.record;
239
- if (!record) continue;
240
- for (const delivery of record.deliveries.filter(settleable)) {
241
- // oxlint-disable-next-line no-await-in-loop -- one registry read, then cached
242
- if (!(await isLinked(delivery.repository))) continue;
243
- const check = {
244
- index: checks.length,
245
- change: change.name,
246
- record,
247
- repository: delivery.repository,
248
- };
249
- checks.push(check);
250
- const key = delivery.repository.toLowerCase();
251
- queues.set(key, [...(queues.get(key) ?? []), check]);
252
- }
253
- }
254
-
255
- const cache: RefreshCache = new Map();
256
- const merges: (FoundMerge | null)[] = checks.map(() => null);
257
- await Promise.all(
258
- [...queues.values()].map(async (queue) => {
259
- for (const { index, record, repository } of queue) {
260
- if (deps.signal?.aborted) return;
261
- // oxlint-disable-next-line no-await-in-loop -- shared branches are checked once
262
- const refreshed = await refreshRecord(record, {
263
- now: deps.now ?? (() => new Date()),
264
- localAccess: async (repo) => (await access(repo).local?.()) ?? null,
265
- fetch: environment.gitAutoMode === true,
266
- repository,
267
- cache,
268
- });
269
- const after = findDelivery(refreshed.record, repository);
270
- if (after?.merge?.state !== "merged" || !after.branch) continue;
271
- merges[index] = {
272
- repository: after.repository,
273
- branch: after.branch,
274
- patch: {
275
- merge: after.merge,
276
- ...(after.head ? { head: after.head } : {}),
277
- ...(after.pr ? { pr: after.pr } : {}),
278
- },
279
- };
280
- }
281
- }),
282
- );
283
-
284
- const found = new Map<string, FoundMerge[]>();
285
- for (const check of checks) {
286
- const merge = merges[check.index];
287
- if (merge) found.set(check.change, [...(found.get(check.change) ?? []), merge]);
288
- }
289
- return found;
290
- }