@uniqbit/mate-core 1.0.0-canary.7 → 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.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/package.json +6 -3
- package/src/cli/commands/artifact/delivery/submit.ts +6 -4
- package/src/cli/commands/artifact/finish/command.ts +28 -11
- package/src/cli/commands/artifact/pending/command.ts +71 -7
- package/src/cli/commands/cap/tokensave.ts +2 -2
- package/src/cli/commands/companion/update.ts +2 -3
- package/src/cli/commands/doctor.ts +16 -4
- package/src/cli/commands/install.ts +8 -4
- package/src/cli/commands/plugin/install.ts +82 -35
- package/src/cli/commands/studio/service-host.ts +3 -0
- package/src/cli/commands/triage.ts +32 -11
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/install-plan.tsx +3 -0
- package/src/cli/main.ts +51 -7
- package/src/cli/usage.ts +3 -3
- package/src/factory-host.ts +6 -0
- package/src/index.ts +1 -0
- package/src/lib/delivery/merge-git.ts +31 -7
- package/src/lib/delivery/overlap.ts +14 -1
- package/src/lib/delivery/repository-access.ts +11 -6
- package/src/lib/delivery/staging/apply-chain.ts +25 -7
- package/src/lib/delivery/staging/linked-merges.ts +175 -0
- package/src/lib/delivery/staging/naming.ts +3 -0
- package/src/lib/delivery/staging/openspec-type.ts +38 -7
- package/src/lib/delivery/staging/pending.ts +153 -11
- package/src/lib/delivery/staging/preflight.ts +239 -0
- package/src/lib/delivery/staging/project.ts +243 -104
- package/src/lib/delivery/staging/replay.ts +5 -3
- package/src/lib/delivery/staging/settle-linked.ts +5 -119
- package/src/lib/delivery/staging/submit.ts +139 -18
- package/src/lib/delivery/submit-change.ts +163 -37
- package/src/lib/friction/mark.ts +49 -11
- package/src/lib/friction/view/read.ts +10 -1
- package/src/lib/openspec-cli.ts +10 -5
- package/src/lib/skills-cli.ts +38 -0
- package/src/lib/tool-manifest.ts +73 -0
- package/src/lib/triage/context.ts +138 -12
- package/src/lib/triage/prepare.ts +19 -4
- package/src/plugin-api.ts +1 -0
- package/src/runtime/command-arg.ts +15 -0
- package/src/runtime/companion-guidance.ts +1 -1
- package/src/runtime/friction-log.ts +41 -17
- package/src/runtime/friction-recorder.ts +15 -2
- package/src/runtime/git-tracked.ts +13 -2
- package/src/studio.ts +6 -1
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +5 -1
- package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +42 -4
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +27 -2
- package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +26 -1
- package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +28 -3
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +28 -3
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +28 -6
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +27 -2
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +24 -2
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +42 -4
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +27 -2
- package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +26 -1
- package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +28 -3
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +28 -3
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +28 -6
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +27 -2
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +24 -2
- package/src/templates/triage/PLAYBOOK.md +9 -1
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +108 -108
- package/src/tools/setup/capabilities/graphify.ts +23 -1
- package/src/tools/setup/capabilities/rtk.ts +27 -86
- package/src/tools/setup/capabilities/tokensave.ts +76 -54
- package/src/tools/setup/dynamic-plugins/audiences.ts +28 -14
- package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
- package/src/tools/setup/dynamic-plugins/install.ts +2 -0
- package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
- package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
- package/src/tools/setup/dynamic-plugins/local.ts +492 -0
- package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
- package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
- package/src/tools/setup/dynamic-plugins/workspaces.ts +17 -8
- package/src/tools/setup/mate.ts +26 -1
- package/src/tools/setup/plugins/gitignore.ts +45 -12
- package/src/tools/setup/service.ts +8 -0
- package/src/tools/setup/utils.ts +10 -1
- package/studio-dist/client/assets/app-ggXJ_QVh.css +2 -0
- package/studio-dist/client/assets/button-amJ3g5oD.js +1 -0
- package/studio-dist/client/assets/cn-BQPKiwI4.js +1 -0
- package/studio-dist/client/assets/combobox-CJ7aGFid.js +1 -0
- package/studio-dist/client/assets/{companion-view-DINdPF-b.js → companion-view-C_N237bf.js} +1 -1
- package/studio-dist/client/assets/fields-BAiGkJ5N.js +1 -0
- package/studio-dist/client/assets/friction-DqOU59v7.js +1 -0
- package/studio-dist/client/assets/getting-started-yp42dj5S.js +1 -0
- package/studio-dist/client/assets/{getting-started._topic-DVB8e5R9.js → getting-started._topic-C9zVXz_m.js} +1 -1
- package/studio-dist/client/assets/{getting-started.index-DQvLHEr1.js → getting-started.index-DWbDKICP.js} +1 -1
- package/studio-dist/client/assets/graph-BYaD_5Bq.js +2 -0
- package/studio-dist/client/assets/{graph-canvas-DIcAqwtK.js → graph-canvas-ySGKMhmk.js} +1 -1
- package/studio-dist/client/assets/index-Qx7reRPD.js +40 -0
- package/studio-dist/client/assets/panel-C4bf_h2W.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +1 -0
- package/studio-dist/client/assets/reports-JFSwSueq.js +1 -0
- package/studio-dist/client/assets/routes-BdOWSgzK.js +1 -0
- package/studio-dist/client/assets/select-BHYYWPhK.js +1 -0
- package/studio-dist/client/assets/skills-Bo9FLsBd.js +1 -0
- package/studio-dist/client/assets/{specs-Dl8HfGlU.js → specs-BrCOjOch.js} +1 -1
- package/studio-dist/client/assets/specs-view-CdE2rlli.js +1 -0
- package/studio-dist/client/assets/{store-DyXbi6o9.js → store-C3vJq8Wj.js} +1 -1
- package/studio-dist/client/assets/{usage-Blcl8kA_.js → usage-BLsLy0nN.js} +13 -13
- package/studio-dist/client/assets/{useAnchoredPopupScrollLock-BBXJpX5L.js → useAnchoredPopupScrollLock-DC7f8GOp.js} +1 -1
- package/studio-dist/client/assets/useMutation-uJUrejsi.js +1 -0
- package/studio-dist/client/assets/vault-BB1B_OhR.js +1 -0
- package/studio-dist/client/assets/warnings-CqOOGlPD.js +1 -0
- package/studio-dist/client/assets/workflow-BFzmI-06.js +1 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-JoHQ5ihx.js → __23tanstack-start-server-fn-resolver-gVfW5vIV.js} +1 -1
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +42 -42
- package/studio-dist/server/assets/{button-B7e1fRyW.js → button-D6bvrFmm.js} +3 -3480
- package/studio-dist/server/assets/cn-FXJAM0KO.js +5528 -0
- package/studio-dist/server/assets/{combobox--S_OmUfh.js → combobox-D2MbYV1O.js} +6 -5
- package/studio-dist/server/assets/{companion-view-D-vGM55e.js → companion-view-Mf1ANbMb.js} +2 -2
- package/studio-dist/server/assets/{fields-B4qM2ZwC.js → fields-B4mAPETz.js} +2 -1
- package/studio-dist/server/assets/{friction-sLxaWY-H.js → friction-9a5S1m7U.js} +54 -14
- package/studio-dist/server/assets/{getting-started-Cq5Pcnsr.js → getting-started-RU6tYU2Q.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-CmWdl3u3.js → getting-started._topic-C02HGrC6.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-AB8xpTFY.js → getting-started.index-EzLRosbb.js} +2 -2
- package/studio-dist/server/assets/{graph-C_Hn-Wf_.js → graph-CZ2H9Fzr.js} +7 -6
- package/studio-dist/server/assets/{graph-canvas-BthrSmPS.js → graph-canvas-rP5TT14Z.js} +1 -1
- package/studio-dist/server/assets/{guides-BVQ4pt5B.js → guides-BGftp4wf.js} +1 -1
- package/studio-dist/server/assets/{markdown-view-rwiiVcPC.js → markdown-view-CArpV-CS.js} +1 -1
- package/studio-dist/server/assets/{panel-CUxRIpYL.js → panel-DR0iq46J.js} +4 -3
- package/studio-dist/server/assets/{plugins._service._view-BSvGnlhU.js → plugins._service._view-n7u2k5dF.js} +7 -4
- package/studio-dist/server/assets/{queries-S_Pl90IG.js → queries-D-yVP9i0.js} +1 -1
- package/studio-dist/server/assets/{reports-CJpAItPk.js → reports-C2SmTgqh.js} +6 -5
- package/studio-dist/server/assets/{router-DF0etoNa.js → router-CPt0TAk_.js} +54 -29
- package/studio-dist/server/assets/{routes-6ylCLkyg.js → routes-CwH8LEy2.js} +8 -7
- package/studio-dist/server/assets/{select-CjuKScan.js → select-C3i6TTX-.js} +5 -4
- package/studio-dist/server/assets/{shell-DLkP7wG9.js → shell-CagqZZMZ.js} +2 -1
- package/studio-dist/server/assets/{skills-zeU80A9S.js → skills-C21Mg_8-.js} +7 -6
- package/studio-dist/server/assets/{specs-DDBNT_v1.js → specs-DetoMiaB.js} +3 -3
- package/studio-dist/server/assets/{specs-view-exvmWdg0.js → specs-view-CmbfLDwN.js} +9 -8
- package/studio-dist/server/assets/{store-kS7zk0Hr.js → store-aC-I6f6o.js} +1 -1
- package/studio-dist/server/assets/{studio-queries-qOXOYoPt.js → studio-queries-Dqf-3nzj.js} +1 -1
- package/studio-dist/server/assets/{usage-C2um7YiV.js → usage-CS4CBK9D.js} +9 -9
- package/studio-dist/server/assets/{useAnchoredPopupScrollLock-kQBB3y_b.js → useAnchoredPopupScrollLock-BjMNgXv9.js} +2 -2
- package/studio-dist/server/assets/{useMutation-C-WO6hCM.js → useMutation-DpBIuWXt.js} +2 -2
- package/studio-dist/server/assets/{vault-B8vgVIH9.js → vault-DVQidlId.js} +6 -6
- package/studio-dist/server/assets/{warnings-BxK4VfV5.js → warnings-C7hgXpdk.js} +2 -1
- package/studio-dist/server/assets/{workflow-BrTK632u.js → workflow-6dZZ1ofw.js} +7 -6
- package/studio-dist/server/server.js +2 -2
- package/tool-manifest.yaml +85 -0
- package/studio-dist/client/assets/app-aIwDxf48.css +0 -2
- package/studio-dist/client/assets/button-CX0sWAJl.js +0 -1
- package/studio-dist/client/assets/combobox-BmA8RjOc.js +0 -1
- package/studio-dist/client/assets/fields-BobQ7zRF.js +0 -1
- package/studio-dist/client/assets/friction-YdYd3zaz.js +0 -1
- package/studio-dist/client/assets/getting-started-CY7NEtTw.js +0 -1
- package/studio-dist/client/assets/graph-DbNnR884.js +0 -2
- package/studio-dist/client/assets/index-CysBCSxM.js +0 -40
- package/studio-dist/client/assets/panel-Csr49lBo.js +0 -1
- package/studio-dist/client/assets/plugins._service._view-CEA_CcPe.js +0 -1
- package/studio-dist/client/assets/reports-CLdgxxkg.js +0 -1
- package/studio-dist/client/assets/routes-DGilWbDE.js +0 -1
- package/studio-dist/client/assets/select-DdebbX7K.js +0 -1
- package/studio-dist/client/assets/skills-C3zNkU8g.js +0 -1
- package/studio-dist/client/assets/specs-view-B_n0Pekv.js +0 -1
- package/studio-dist/client/assets/useBaseQuery-C2cjmeH2.js +0 -1
- package/studio-dist/client/assets/useMutation-DI6LbvVa.js +0 -1
- package/studio-dist/client/assets/vault-Cb9DmM1i.js +0 -1
- package/studio-dist/client/assets/warnings-B-rvoW8q.js +0 -1
- package/studio-dist/client/assets/workflow-DN5T19jd.js +0 -1
- package/studio-dist/server/assets/useBaseQuery--iH3rd-T.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 {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
137
|
+
/** Reads the {@link ChainContext} of `companionPath`, fetching first with `deps.fetch`. */
|
|
138
|
+
export async function chainContext(
|
|
106
139
|
companionPath: string,
|
|
107
|
-
|
|
108
|
-
|
|
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)
|
|
118
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
151
|
-
|
|
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,
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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:
|
|
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
|
-
|
|
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], ...(
|
|
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
|
-
|
|
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:
|
|
252
|
-
const chain:
|
|
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
|
|
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
|
|
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
|
|
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 "..."
|
|
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: (.+?)"
|
|
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]
|
|
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
|
|
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
|
|
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
|
-
}
|