@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
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { DeliveryEnvironment } from "../environment";
|
|
2
|
+
import {
|
|
3
|
+
findDelivery,
|
|
4
|
+
sameRepository,
|
|
5
|
+
type Delivery,
|
|
6
|
+
type DeliveryPatch,
|
|
7
|
+
type DeliveryRecord,
|
|
8
|
+
} from "../record";
|
|
9
|
+
import { isSettled, refreshRecord, type RefreshCache } from "../refresh";
|
|
10
|
+
import { repositoryAccessFor, type RepositoryAccessDeps } from "../repository-access";
|
|
11
|
+
|
|
12
|
+
/** A merge Git proved for one delivery, as a patch to the record's delivery. */
|
|
13
|
+
export interface FoundMerge {
|
|
14
|
+
repository: string;
|
|
15
|
+
branch: string;
|
|
16
|
+
patch: DeliveryPatch;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A linked delivery left unchecked: the signal aborted before its turn, or its check threw. */
|
|
20
|
+
export interface UncheckedDelivery {
|
|
21
|
+
change: string;
|
|
22
|
+
repository: string;
|
|
23
|
+
branch: string;
|
|
24
|
+
/** Why its check failed; absent when it never started. */
|
|
25
|
+
error?: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface FindLinkedMergesDeps extends RepositoryAccessDeps {
|
|
29
|
+
now?: () => Date;
|
|
30
|
+
/** Once aborted, no further check starts and running checks' Git commands are killed. */
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
/**
|
|
33
|
+
* Called for each delivery left unchecked, including one whose fetch failed and that Git found
|
|
34
|
+
* unmerged. Without it the first failed check stops the others and then throws, and skipped
|
|
35
|
+
* deliveries go unreported.
|
|
36
|
+
*/
|
|
37
|
+
onUnchecked?: (delivery: UncheckedDelivery) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A delivery a linked checkout may settle: a branch, not direct, not merged or dropped yet. */
|
|
41
|
+
export function settleable(delivery: Delivery): delivery is Delivery & { branch: string } {
|
|
42
|
+
return (
|
|
43
|
+
delivery.notApplicable === undefined &&
|
|
44
|
+
Boolean(delivery.branch) &&
|
|
45
|
+
!delivery.direct &&
|
|
46
|
+
!isSettled(delivery)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One linked delivery to check, numbered in submit order. */
|
|
51
|
+
interface Check {
|
|
52
|
+
index: number;
|
|
53
|
+
change: string;
|
|
54
|
+
record: DeliveryRecord;
|
|
55
|
+
repository: string;
|
|
56
|
+
branch: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Merges Git proves for linked deliveries of `submitted`, by change name in submit order. Only
|
|
61
|
+
* checkouts the environment links are inspected; nothing is recorded. Repositories are checked
|
|
62
|
+
* side by side; one repository's checks run in turn, since concurrent fetches into one checkout
|
|
63
|
+
* contend for its refs.
|
|
64
|
+
*/
|
|
65
|
+
export async function findLinkedMerges(
|
|
66
|
+
environment: DeliveryEnvironment,
|
|
67
|
+
submitted: readonly { name: string; delivery: { record: DeliveryRecord | null } }[],
|
|
68
|
+
deps: FindLinkedMergesDeps = {},
|
|
69
|
+
): Promise<Map<string, FoundMerge[]>> {
|
|
70
|
+
const stop = new AbortController();
|
|
71
|
+
const signal = deps.signal ? AbortSignal.any([deps.signal, stop.signal]) : stop.signal;
|
|
72
|
+
const access = repositoryAccessFor(environment, { openCheckout: deps.openCheckout, signal });
|
|
73
|
+
const unchecked = (
|
|
74
|
+
{ change, repository, branch }: Omit<UncheckedDelivery, "error">,
|
|
75
|
+
error?: unknown,
|
|
76
|
+
) =>
|
|
77
|
+
deps.onUnchecked?.({ change, repository, branch, ...(error === undefined ? {} : { error }) });
|
|
78
|
+
const linked = new Map<string, Promise<boolean>>();
|
|
79
|
+
const isLinked = (repository: string): Promise<boolean> => {
|
|
80
|
+
const key = repository.toLowerCase();
|
|
81
|
+
let known = linked.get(key);
|
|
82
|
+
if (!known) {
|
|
83
|
+
known = (environment.checkoutOf?.(repository) ?? Promise.resolve(null)).then(Boolean);
|
|
84
|
+
linked.set(key, known);
|
|
85
|
+
}
|
|
86
|
+
return known;
|
|
87
|
+
};
|
|
88
|
+
const checks: Check[] = [];
|
|
89
|
+
const queues = new Map<string, Check[]>();
|
|
90
|
+
for (const change of submitted) {
|
|
91
|
+
const record = change.delivery.record;
|
|
92
|
+
if (!record) continue;
|
|
93
|
+
for (const delivery of record.deliveries.filter(settleable)) {
|
|
94
|
+
const { repository, branch } = delivery;
|
|
95
|
+
let isLinkedHere: boolean;
|
|
96
|
+
try {
|
|
97
|
+
// oxlint-disable-next-line no-await-in-loop -- one registry read, then cached
|
|
98
|
+
isLinkedHere = await isLinked(repository);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (!deps.onUnchecked) throw error;
|
|
101
|
+
unchecked({ change: change.name, repository, branch }, error);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (!isLinkedHere) continue;
|
|
105
|
+
const check = { index: checks.length, change: change.name, record, repository, branch };
|
|
106
|
+
checks.push(check);
|
|
107
|
+
const key = repository.toLowerCase();
|
|
108
|
+
queues.set(key, [...(queues.get(key) ?? []), check]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const cache: RefreshCache = new Map();
|
|
113
|
+
const merges: (FoundMerge | null)[] = checks.map(() => null);
|
|
114
|
+
let failure: { error: unknown } | undefined;
|
|
115
|
+
await Promise.all(
|
|
116
|
+
[...queues.values()].map(async (queue) => {
|
|
117
|
+
for (const check of queue) {
|
|
118
|
+
if (signal.aborted) {
|
|
119
|
+
unchecked(check);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const { index, record, repository } = check;
|
|
123
|
+
let refreshed: Awaited<ReturnType<typeof refreshRecord>>;
|
|
124
|
+
try {
|
|
125
|
+
// oxlint-disable-next-line no-await-in-loop -- shared branches are checked once
|
|
126
|
+
refreshed = await refreshRecord(record, {
|
|
127
|
+
now: deps.now ?? (() => new Date()),
|
|
128
|
+
localAccess: async (repo) => (await access(repo).local?.()) ?? null,
|
|
129
|
+
fetch: environment.gitAutoMode === true,
|
|
130
|
+
repository,
|
|
131
|
+
cache,
|
|
132
|
+
});
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (deps.onUnchecked) {
|
|
135
|
+
unchecked(check, error ?? new Error("merge check failed"));
|
|
136
|
+
} else {
|
|
137
|
+
failure ??= { error };
|
|
138
|
+
stop.abort();
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const after = findDelivery(refreshed.record, repository);
|
|
143
|
+
if (after?.merge?.state === "merged" && after.branch) {
|
|
144
|
+
merges[index] = {
|
|
145
|
+
repository: after.repository,
|
|
146
|
+
branch: after.branch,
|
|
147
|
+
patch: {
|
|
148
|
+
merge: after.merge,
|
|
149
|
+
...(after.head ? { head: after.head } : {}),
|
|
150
|
+
...(after.pr ? { pr: after.pr } : {}),
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
// Killed mid-check, or answered from refs a failed fetch left stale: no answer.
|
|
156
|
+
if (signal.aborted) {
|
|
157
|
+
unchecked(check);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const fetch = refreshed.outcomes.find((outcome) =>
|
|
161
|
+
sameRepository(outcome.repository, repository),
|
|
162
|
+
)?.fetch;
|
|
163
|
+
if (fetch?.ok === false) unchecked(check, new Error(fetch.message ?? "git fetch failed"));
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
if (failure) throw failure.error;
|
|
168
|
+
|
|
169
|
+
const found = new Map<string, FoundMerge[]>();
|
|
170
|
+
for (const check of checks) {
|
|
171
|
+
const merge = merges[check.index];
|
|
172
|
+
if (merge) found.set(check.change, [...(found.get(check.change) ?? []), merge]);
|
|
173
|
+
}
|
|
174
|
+
return found;
|
|
175
|
+
}
|
|
@@ -11,6 +11,8 @@ export { repositorySegment };
|
|
|
11
11
|
export interface DeliveryGroupName {
|
|
12
12
|
/** Delivery Group, e.g. `acme_widgets/workset/acme-login`. */
|
|
13
13
|
group: string;
|
|
14
|
+
/** The repository the group is named after; absent for `change/<change>`. */
|
|
15
|
+
repository?: string;
|
|
14
16
|
/** Set when the record names different branches for different repositories. */
|
|
15
17
|
warning?: string;
|
|
16
18
|
}
|
|
@@ -50,6 +52,7 @@ export function deliveryGroupFor(
|
|
|
50
52
|
const group = groupOf(preferred);
|
|
51
53
|
return {
|
|
52
54
|
group,
|
|
55
|
+
repository: preferred.repository,
|
|
53
56
|
...(distinct.length > 1
|
|
54
57
|
? {
|
|
55
58
|
warning: `${change} records different branches (${distinct.join(", ")}); submitting it in ${group}.`,
|
|
@@ -30,13 +30,18 @@ function capabilityOf(file: string): string | null {
|
|
|
30
30
|
|
|
31
31
|
interface ValidatedItem {
|
|
32
32
|
valid?: boolean;
|
|
33
|
-
issues?: Array<{ level?: string; message?: string }>;
|
|
33
|
+
issues?: Array<{ level?: string; path?: string; message?: string }>;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
interface Validation {
|
|
37
|
+
items?: ValidatedItem[];
|
|
38
|
+
status?: Array<{ severity?: string; message?: string }>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `openspec validate --json` output, or null when it is not that JSON. */
|
|
42
|
+
function parseValidation(stdout: string): Validation | null {
|
|
38
43
|
try {
|
|
39
|
-
return
|
|
44
|
+
return JSON.parse(stdout) as Validation;
|
|
40
45
|
} catch {
|
|
41
46
|
return null;
|
|
42
47
|
}
|
|
@@ -60,7 +65,7 @@ async function validateSpec(
|
|
|
60
65
|
if (run.code === null) {
|
|
61
66
|
return { path: file, detail: `openspec validate ${capability} ran out of time` };
|
|
62
67
|
}
|
|
63
|
-
const items =
|
|
68
|
+
const items = parseValidation(run.stdout)?.items;
|
|
64
69
|
if (!items) {
|
|
65
70
|
if (run.code === 0) return null;
|
|
66
71
|
const output = (run.stderr || run.stdout).trim().split("\n").slice(-3).join("\n");
|
|
@@ -75,19 +80,45 @@ async function validateSpec(
|
|
|
75
80
|
return { path: file, detail: errors.join("; ") || "invalid" };
|
|
76
81
|
}
|
|
77
82
|
|
|
83
|
+
/**
|
|
84
|
+
* The failing lines of `openspec validate --strict --json` output: each ERROR and WARNING issue
|
|
85
|
+
* (strict fails on both, INFO fails nothing) and each error status, such as an unknown change.
|
|
86
|
+
* Null when the output is not that JSON.
|
|
87
|
+
*/
|
|
88
|
+
function failingIssues(stdout: string): string[] | null {
|
|
89
|
+
const parsed = parseValidation(stdout);
|
|
90
|
+
if (!parsed) return null;
|
|
91
|
+
const issues = (parsed.items ?? [])
|
|
92
|
+
.filter((item) => item.valid === false)
|
|
93
|
+
.flatMap((item) => item.issues ?? [])
|
|
94
|
+
.filter((issue) => (issue.level === "ERROR" || issue.level === "WARNING") && issue.message)
|
|
95
|
+
.map((issue) => `[${issue.level}] ${issue.path ? `${issue.path}: ` : ""}${issue.message}`);
|
|
96
|
+
const statuses = (parsed.status ?? []).flatMap((status) =>
|
|
97
|
+
status.severity === "error" && status.message ? [status.message] : [],
|
|
98
|
+
);
|
|
99
|
+
return [...issues, ...statuses];
|
|
100
|
+
}
|
|
101
|
+
|
|
78
102
|
/** Why `openspec validate <change> --strict` refuses the change in `dir`, or null. */
|
|
79
103
|
async function checkChange(
|
|
80
104
|
dir: string,
|
|
81
105
|
change: string,
|
|
82
106
|
runner: RunOpenSpec,
|
|
83
107
|
): Promise<string | null> {
|
|
84
|
-
const run = await runner(["validate", "--strict", "--no-interactive", "--", change], {
|
|
108
|
+
const run = await runner(["validate", "--strict", "--json", "--no-interactive", "--", change], {
|
|
85
109
|
cwd: dir,
|
|
86
110
|
timeout: OPENSPEC_TIMEOUT_MS,
|
|
87
111
|
});
|
|
88
112
|
if (run.code === 0) return null;
|
|
89
113
|
if (run.code === null) return `openspec validate ${change} --strict ran out of time`;
|
|
90
|
-
const
|
|
114
|
+
const failing = failingIssues(run.stdout);
|
|
115
|
+
if (failing && failing.length > 0) return failing.join("\n");
|
|
116
|
+
// JSON naming no failure says nothing here, so only stderr can say why.
|
|
117
|
+
const output = (run.stderr || (failing ? "" : run.stdout))
|
|
118
|
+
.trim()
|
|
119
|
+
.split("\n")
|
|
120
|
+
.slice(-5)
|
|
121
|
+
.join("\n");
|
|
91
122
|
return output || `openspec validate ${change} --strict failed`;
|
|
92
123
|
}
|
|
93
124
|
|
|
@@ -24,17 +24,23 @@ import {
|
|
|
24
24
|
submitters,
|
|
25
25
|
} from "../../../runtime/pending-records";
|
|
26
26
|
import { blobsAt } from "../../../runtime/submitted-arrivals";
|
|
27
|
+
import { errorMessage } from "../../../runtime/error-message";
|
|
28
|
+
import type { DeliveryEnvironment } from "../environment";
|
|
27
29
|
import { declaredDependencies } from "../overlap";
|
|
28
30
|
import {
|
|
31
|
+
findDelivery,
|
|
29
32
|
isPublishable,
|
|
30
33
|
readDeliveryState,
|
|
31
34
|
sameRepository,
|
|
35
|
+
settleDelivery,
|
|
36
|
+
upsertDelivery,
|
|
32
37
|
type DeliveryBlock,
|
|
33
38
|
type DeliveryRecord,
|
|
34
39
|
type DeliveryState,
|
|
35
40
|
type MergeSource,
|
|
36
41
|
} from "../record";
|
|
37
42
|
import type { ArtifactType, StalePart } from "./artifact-type";
|
|
43
|
+
import { findLinkedMerges, settleable, type UncheckedDelivery } from "./linked-merges";
|
|
38
44
|
import type { DeltaFailure } from "./replay";
|
|
39
45
|
import { deliveryGroupFor } from "./naming";
|
|
40
46
|
import {
|
|
@@ -59,6 +65,8 @@ export interface SubmittedChange {
|
|
|
59
65
|
path: string;
|
|
60
66
|
/** Its Delivery Record, settled against its scopes. */
|
|
61
67
|
delivery: DeliveryState;
|
|
68
|
+
/** The repositories it is scoped to. */
|
|
69
|
+
scoped: string[];
|
|
62
70
|
blocked?: DeliveryBlock;
|
|
63
71
|
specBase?: string;
|
|
64
72
|
/** Change names it declares in `dependsOn`. */
|
|
@@ -213,6 +221,23 @@ async function materializeChanges(
|
|
|
213
221
|
);
|
|
214
222
|
}
|
|
215
223
|
|
|
224
|
+
/** Compares change names as Git lists the folders one commit adds: `acme-a-b/` before `acme-a/`. */
|
|
225
|
+
export function byFolderPath(a: string, b: string): number {
|
|
226
|
+
return `${a}/` < `${b}/` ? -1 : `${a}/` > `${b}/` ? 1 : 0;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Compares change names by their place in `order`, then by `tie`; names not in it go last. */
|
|
230
|
+
export function bySubmitOrder(
|
|
231
|
+
order: readonly string[],
|
|
232
|
+
tie: (a: string, b: string) => number = (a, b) => a.localeCompare(b),
|
|
233
|
+
): (a: string, b: string) => number {
|
|
234
|
+
const rank = (name: string): number => {
|
|
235
|
+
const at = order.indexOf(name);
|
|
236
|
+
return at === -1 ? order.length : at;
|
|
237
|
+
};
|
|
238
|
+
return (a, b) => rank(a) - rank(b) || tie(a, b);
|
|
239
|
+
}
|
|
240
|
+
|
|
216
241
|
/**
|
|
217
242
|
* The changes of `type` submitted at `ref` (`state: submitted` in their Delivery Record), in
|
|
218
243
|
* submit order, then by name; with `only`, just those of that name. Only each folder's Delivery
|
|
@@ -240,11 +265,13 @@ export async function submittedAt(
|
|
|
240
265
|
const delivery = await readDeliveryState(dir);
|
|
241
266
|
if (delivery.record?.state !== "submitted") return null;
|
|
242
267
|
const { record } = delivery;
|
|
268
|
+
const scoped = await scopedRepositories(dir);
|
|
243
269
|
return {
|
|
244
270
|
name,
|
|
245
|
-
group: deliveryGroupFor(name, record,
|
|
271
|
+
group: deliveryGroupFor(name, record, scoped).group,
|
|
246
272
|
path: sourcePathOf(type, name),
|
|
247
273
|
delivery,
|
|
274
|
+
scoped,
|
|
248
275
|
...(record.blocked ? { blocked: record.blocked } : {}),
|
|
249
276
|
...(record.specBase ? { specBase: record.specBase } : {}),
|
|
250
277
|
dependsOn: await declaredDependencies(dir),
|
|
@@ -254,11 +281,8 @@ export async function submittedAt(
|
|
|
254
281
|
const found = read.filter((entry): entry is SubmittedChange => entry !== null);
|
|
255
282
|
// One change needs no order.
|
|
256
283
|
const order = found.length > 1 ? await submitOrder(git, ref, type) : [];
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
return at === -1 ? order.length : at;
|
|
260
|
-
};
|
|
261
|
-
return found.toSorted((a, b) => rank(a.name) - rank(b.name) || a.name.localeCompare(b.name));
|
|
284
|
+
const compare = bySubmitOrder(order);
|
|
285
|
+
return found.toSorted((a, b) => compare(a.name, b.name));
|
|
262
286
|
} finally {
|
|
263
287
|
await fs.rm(scratch, { recursive: true, force: true });
|
|
264
288
|
}
|
|
@@ -648,8 +672,10 @@ export interface SubmittedChangeView {
|
|
|
648
672
|
origin: "yours" | "others";
|
|
649
673
|
/** Who submitted it, by the pending branch's history; absent when Git cannot say. */
|
|
650
674
|
author?: string;
|
|
651
|
-
/** Its final merge results and who recorded each; see {@link MergeClaim}. */
|
|
675
|
+
/** Its final merge results on the pending branch and who recorded each; see {@link MergeClaim}. */
|
|
652
676
|
merges: MergeClaim[];
|
|
677
|
+
/** Deliveries whose merge this run's check found and nothing recorded yet; absent when none. */
|
|
678
|
+
found?: FoundDelivery[];
|
|
653
679
|
}
|
|
654
680
|
|
|
655
681
|
export interface SubmittedGroupView {
|
|
@@ -661,6 +687,27 @@ export interface SubmittedGroupView {
|
|
|
661
687
|
publishable: boolean;
|
|
662
688
|
/** Changes of other groups it depends on whose group cannot publish yet. */
|
|
663
689
|
heldBy: string[];
|
|
690
|
+
/**
|
|
691
|
+
* Publishable only through a merge in `found`, of its own or of a dependency's group: publish
|
|
692
|
+
* it with `--refresh`, which records that merge.
|
|
693
|
+
*/
|
|
694
|
+
needsRefresh?: true;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** A branch delivery of one repository. */
|
|
698
|
+
export interface FoundDelivery {
|
|
699
|
+
repository: string;
|
|
700
|
+
branch: string;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** The local merge check of one discovery; see {@link DiscoverSubmittedOptions.checkMerges}. */
|
|
704
|
+
export interface MergeCheck {
|
|
705
|
+
/** False when the check was not asked for or could not run. */
|
|
706
|
+
ran: boolean;
|
|
707
|
+
/** Linked deliveries not checked in time, or whose check failed; their stored state stands. */
|
|
708
|
+
unchecked: (FoundDelivery & { change: string })[];
|
|
709
|
+
/** Why the check, or some delivery's check, failed. */
|
|
710
|
+
warning?: string;
|
|
664
711
|
}
|
|
665
712
|
|
|
666
713
|
/** `stale`: the fetch failed or was not attempted; the refs are the last fetched ones. */
|
|
@@ -672,6 +719,8 @@ export interface SubmittedDiscovery {
|
|
|
672
719
|
stale: boolean;
|
|
673
720
|
error?: string;
|
|
674
721
|
groups: SubmittedGroupView[];
|
|
722
|
+
/** Present when the caller asked for the merge check. */
|
|
723
|
+
mergeCheck?: MergeCheck;
|
|
675
724
|
}
|
|
676
725
|
|
|
677
726
|
/** `changes` at `ref` without those the default branch already archived. */
|
|
@@ -697,6 +746,12 @@ export interface DiscoverSubmittedOptions {
|
|
|
697
746
|
type?: ArtifactType;
|
|
698
747
|
/** Home of Mate's local companion state; `HOME` by default. */
|
|
699
748
|
stateHome?: string;
|
|
749
|
+
/**
|
|
750
|
+
* Checks unsettled branch deliveries in the checkouts `environment` links, stopping every check
|
|
751
|
+
* after `budgetMs`, and counts the merges Git proves without recording them. `environment` is
|
|
752
|
+
* resolved only when such a delivery exists. Off when absent.
|
|
753
|
+
*/
|
|
754
|
+
checkMerges?: { environment: () => Promise<DeliveryEnvironment>; budgetMs: number };
|
|
700
755
|
}
|
|
701
756
|
|
|
702
757
|
/** Bound on discovery's fetch and reads. */
|
|
@@ -717,7 +772,15 @@ export async function discoverSubmitted(
|
|
|
717
772
|
): Promise<SubmittedDiscovery> {
|
|
718
773
|
const git = (options.git ?? discoveryGit)(companionPath);
|
|
719
774
|
const remote = await stagingRemote(git);
|
|
720
|
-
if (!remote)
|
|
775
|
+
if (!remote) {
|
|
776
|
+
return {
|
|
777
|
+
pendingBranch: null,
|
|
778
|
+
fetchedAt: null,
|
|
779
|
+
stale: false,
|
|
780
|
+
groups: [],
|
|
781
|
+
...(options.checkMerges ? { mergeCheck: { ran: false, unchecked: [] } } : {}),
|
|
782
|
+
};
|
|
783
|
+
}
|
|
721
784
|
let stale = !options.fetch;
|
|
722
785
|
let error: string | undefined;
|
|
723
786
|
if (options.fetch) {
|
|
@@ -729,13 +792,17 @@ export async function discoverSubmitted(
|
|
|
729
792
|
}
|
|
730
793
|
const type = options.type ?? defaultArtifactType();
|
|
731
794
|
// Published, but the inbox was not emptied yet: no longer pending.
|
|
732
|
-
const
|
|
795
|
+
const stored = await withoutPublished(
|
|
733
796
|
git,
|
|
734
797
|
remote,
|
|
735
798
|
pendingRef(remote),
|
|
736
799
|
type,
|
|
737
800
|
await submittedAt(git, pendingRef(remote), type, options.tmpRoot),
|
|
738
801
|
);
|
|
802
|
+
const checked = options.checkMerges
|
|
803
|
+
? await withFoundMerges(stored, options.checkMerges)
|
|
804
|
+
: { submitted: stored, found: new Map<string, FoundDelivery[]>(), mergeCheck: undefined };
|
|
805
|
+
const { submitted, found, mergeCheck } = checked;
|
|
739
806
|
const who = await submitters(
|
|
740
807
|
companionPath,
|
|
741
808
|
pendingRef(remote),
|
|
@@ -744,16 +811,21 @@ export async function discoverSubmitted(
|
|
|
744
811
|
);
|
|
745
812
|
const groups = groupsOf(submitted);
|
|
746
813
|
const publishable = publishableGroups(groups, submitted);
|
|
747
|
-
|
|
814
|
+
// A group publishable only through a found merge, its own or a dependency's, needs a refresh.
|
|
815
|
+
const storedPublishable =
|
|
816
|
+
found.size > 0 ? publishableGroups(groupsOf(stored), stored) : publishable;
|
|
817
|
+
// Stored records only: a found merge is nobody's claim yet.
|
|
818
|
+
const claims = await mapLimited(stored, READ_CONCURRENCY, (change) =>
|
|
748
819
|
mergeClaims(git, pendingRef(remote), change.path, change.delivery.record, type),
|
|
749
820
|
);
|
|
750
|
-
const merges = new Map(
|
|
821
|
+
const merges = new Map(stored.map((change, index) => [change.name, claims[index]!]));
|
|
751
822
|
return {
|
|
752
823
|
pendingBranch: remote.pendingBranch,
|
|
753
824
|
ref: pendingRef(remote),
|
|
754
825
|
fetchedAt: await lastFetchedAt(git),
|
|
755
826
|
stale,
|
|
756
827
|
...(error ? { error } : {}),
|
|
828
|
+
...(mergeCheck ? { mergeCheck } : {}),
|
|
757
829
|
groups: groups.map((group) => ({
|
|
758
830
|
group: group.group,
|
|
759
831
|
changes: group.changes.map((change) => {
|
|
@@ -768,6 +840,7 @@ export async function discoverSubmitted(
|
|
|
768
840
|
origin: submitter?.mine ? ("yours" as const) : ("others" as const),
|
|
769
841
|
...(submitter?.author ? { author: submitter.author } : {}),
|
|
770
842
|
merges: merges.get(change.name) ?? [],
|
|
843
|
+
...(found.has(change.name) ? { found: found.get(change.name)! } : {}),
|
|
771
844
|
};
|
|
772
845
|
}),
|
|
773
846
|
blocked: group.changes.some((change) => change.blocked !== undefined),
|
|
@@ -775,6 +848,75 @@ export async function discoverSubmitted(
|
|
|
775
848
|
heldBy: unpublishedDependencies(group, submitted)
|
|
776
849
|
.filter((change) => publishable.get(change.group) !== true)
|
|
777
850
|
.map((change) => change.name),
|
|
851
|
+
...(publishable.get(group.group) === true && storedPublishable.get(group.group) !== true
|
|
852
|
+
? { needsRefresh: true as const }
|
|
853
|
+
: {}),
|
|
778
854
|
})),
|
|
779
855
|
};
|
|
780
856
|
}
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* `submitted` with each change settled as if the merges the local check proves were recorded,
|
|
860
|
+
* and the deliveries found that way by change. Records nothing: `record` stays the stored one.
|
|
861
|
+
*/
|
|
862
|
+
async function withFoundMerges(
|
|
863
|
+
submitted: SubmittedChange[],
|
|
864
|
+
{ environment, budgetMs }: NonNullable<DiscoverSubmittedOptions["checkMerges"]>,
|
|
865
|
+
): Promise<{
|
|
866
|
+
submitted: SubmittedChange[];
|
|
867
|
+
found: Map<string, FoundDelivery[]>;
|
|
868
|
+
mergeCheck: MergeCheck;
|
|
869
|
+
}> {
|
|
870
|
+
if (!submitted.some((change) => change.delivery.record?.deliveries.some(settleable))) {
|
|
871
|
+
return { submitted, found: new Map(), mergeCheck: { ran: true, unchecked: [] } };
|
|
872
|
+
}
|
|
873
|
+
const unchecked: UncheckedDelivery[] = [];
|
|
874
|
+
// Kills the checks' Git commands too, so the budget bounds the whole check.
|
|
875
|
+
const signal = budgetMs > 0 ? AbortSignal.timeout(budgetMs) : AbortSignal.abort();
|
|
876
|
+
let merges: Awaited<ReturnType<typeof findLinkedMerges>>;
|
|
877
|
+
try {
|
|
878
|
+
merges = await findLinkedMerges(await environment(), submitted, {
|
|
879
|
+
signal,
|
|
880
|
+
onUnchecked: (delivery) => unchecked.push(delivery),
|
|
881
|
+
});
|
|
882
|
+
} catch (error) {
|
|
883
|
+
const warning = `could not run: ${errorMessage(error)}`;
|
|
884
|
+
return { submitted, found: new Map(), mergeCheck: { ran: false, unchecked: [], warning } };
|
|
885
|
+
}
|
|
886
|
+
const found = new Map<string, FoundDelivery[]>();
|
|
887
|
+
const next = submitted.map((change) => {
|
|
888
|
+
let record = change.delivery.record;
|
|
889
|
+
const applied: FoundDelivery[] = [];
|
|
890
|
+
for (const { repository, branch, patch } of merges.get(change.name) ?? []) {
|
|
891
|
+
const delivery = record && findDelivery(record, repository);
|
|
892
|
+
if (!record || !delivery || delivery.branch !== branch || !settleable(delivery)) continue;
|
|
893
|
+
record = upsertDelivery(record, repository, patch);
|
|
894
|
+
applied.push({ repository: delivery.repository, branch });
|
|
895
|
+
}
|
|
896
|
+
if (applied.length === 0) return change;
|
|
897
|
+
found.set(change.name, applied);
|
|
898
|
+
return {
|
|
899
|
+
...change,
|
|
900
|
+
delivery: { ...change.delivery, ...settleDelivery(record, change.scoped) },
|
|
901
|
+
};
|
|
902
|
+
});
|
|
903
|
+
const failures = unchecked
|
|
904
|
+
.filter((delivery) => delivery.error !== undefined)
|
|
905
|
+
.map(
|
|
906
|
+
(failure) =>
|
|
907
|
+
`checking ${failure.branch} in ${failure.repository} failed: ${errorMessage(failure.error)}`,
|
|
908
|
+
);
|
|
909
|
+
return {
|
|
910
|
+
submitted: next,
|
|
911
|
+
found,
|
|
912
|
+
mergeCheck: {
|
|
913
|
+
ran: true,
|
|
914
|
+
unchecked: unchecked.map(({ change, repository, branch }) => ({
|
|
915
|
+
change,
|
|
916
|
+
repository,
|
|
917
|
+
branch,
|
|
918
|
+
})),
|
|
919
|
+
...(failures.length > 0 ? { warning: failures.join("; ") } : {}),
|
|
920
|
+
},
|
|
921
|
+
};
|
|
922
|
+
}
|