@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
|
@@ -106,6 +106,20 @@ export interface LocalMember {
|
|
|
106
106
|
group: string;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** The active members of `group` not in `names`: submitting `names` waits for them. */
|
|
110
|
+
export function waitingMembers(
|
|
111
|
+
members: readonly LocalMember[],
|
|
112
|
+
group: string,
|
|
113
|
+
names: readonly string[],
|
|
114
|
+
): string[] {
|
|
115
|
+
return members
|
|
116
|
+
.filter(
|
|
117
|
+
(member) =>
|
|
118
|
+
member.group === group && member.state === "active" && !names.includes(member.name),
|
|
119
|
+
)
|
|
120
|
+
.map((member) => member.name);
|
|
121
|
+
}
|
|
122
|
+
|
|
109
123
|
/** Every local source folder of `type` with its state and Delivery Group, by name. */
|
|
110
124
|
export async function localMembers(
|
|
111
125
|
companionPath: string,
|
|
@@ -393,7 +407,7 @@ export interface PushOptions {
|
|
|
393
407
|
* conflict, submitted it again, and what remains stale (a removal, a plain rename) replaces no
|
|
394
408
|
* one's text. A part it would overwrite still needs `mate artifact resolve`.
|
|
395
409
|
*/
|
|
396
|
-
async function acceptsBlock(
|
|
410
|
+
export async function acceptsBlock(
|
|
397
411
|
type: ArtifactType,
|
|
398
412
|
work: CompanionGit,
|
|
399
413
|
ref: string,
|
|
@@ -662,6 +676,120 @@ export async function hasUnsubmittedWork(
|
|
|
662
676
|
return (await editedSinceSubmit(git, companionPath, relative, submitted)) === true;
|
|
663
677
|
}
|
|
664
678
|
|
|
679
|
+
/**
|
|
680
|
+
* The `submitted` members of `groups`, those in `named` left out, that {@link submitGroups} pushes
|
|
681
|
+
* as edited. Call it before refreshing them: a refresh rewrites `delivery.yaml`, which the
|
|
682
|
+
* comparison covers. A member Git cannot judge is left out, since {@link submitGroups} fails its
|
|
683
|
+
* group. `recordOnly`: only its Delivery Record differs from what this checkout last submitted or
|
|
684
|
+
* took, so its content already passed a check.
|
|
685
|
+
*/
|
|
686
|
+
export async function editedSubmittedMembers(
|
|
687
|
+
companionPath: string,
|
|
688
|
+
groups: ReadonlySet<string>,
|
|
689
|
+
named: readonly string[],
|
|
690
|
+
deps: Pick<SubmitDeps, "git" | "artifactType" | "stateHome"> = {},
|
|
691
|
+
): Promise<(LocalMember & { recordOnly: boolean })[]> {
|
|
692
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
693
|
+
const git = (deps.git ?? defaultGit)(companionPath);
|
|
694
|
+
const submitted = readSubmittedFolders(companionPath, deps.stateHome);
|
|
695
|
+
const edited: (LocalMember & { recordOnly: boolean })[] = [];
|
|
696
|
+
for (const member of await localMembers(companionPath, type)) {
|
|
697
|
+
if (member.state !== "submitted" || !groups.has(member.group)) continue;
|
|
698
|
+
if (named.includes(member.name)) continue;
|
|
699
|
+
const relative = sourcePathOf(type, member.name);
|
|
700
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
701
|
+
if ((await editedSinceSubmit(git, companionPath, relative, submitted)) !== true) continue;
|
|
702
|
+
const content = submitted[relative]?.content;
|
|
703
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
704
|
+
const files = content === undefined ? null : await ownFiles(git, companionPath, relative);
|
|
705
|
+
const recordOnly =
|
|
706
|
+
files !== null &&
|
|
707
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
708
|
+
(await folderDigest(
|
|
709
|
+
path.join(companionPath, ...relative.split("/")),
|
|
710
|
+
files.filter((file) => file !== DELIVERY_FILE),
|
|
711
|
+
)) === content;
|
|
712
|
+
edited.push({ ...member, recordOnly });
|
|
713
|
+
}
|
|
714
|
+
return edited;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** What {@link submitGroups} hands {@link pushGroup} for one group. */
|
|
718
|
+
interface PushPlan {
|
|
719
|
+
/** The local members it pushes. */
|
|
720
|
+
pushed: string[];
|
|
721
|
+
/** Those of {@link pushed} staged only when the pending branch lacks them. */
|
|
722
|
+
ifMissing: string[];
|
|
723
|
+
/** Members Git cannot judge: the group fails. */
|
|
724
|
+
unknown: string[];
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
async function planPush(
|
|
728
|
+
git: CompanionGit,
|
|
729
|
+
companionPath: string,
|
|
730
|
+
type: ArtifactType,
|
|
731
|
+
inGroup: readonly LocalMember[],
|
|
732
|
+
names: readonly string[],
|
|
733
|
+
submitted: Record<string, SubmittedFolder>,
|
|
734
|
+
): Promise<PushPlan> {
|
|
735
|
+
const plan: PushPlan = { pushed: [], ifMissing: [], unknown: [] };
|
|
736
|
+
for (const member of inGroup) {
|
|
737
|
+
const named = names.includes(member.name);
|
|
738
|
+
if (member.state === "dropped" && !named) continue;
|
|
739
|
+
const edited =
|
|
740
|
+
(named && member.state !== "submitted") ||
|
|
741
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
742
|
+
(await editedSinceSubmit(git, companionPath, sourcePathOf(type, member.name), submitted));
|
|
743
|
+
if (edited === null) plan.unknown.push(member.name);
|
|
744
|
+
else if (edited || named) plan.pushed.push(member.name);
|
|
745
|
+
if (edited === false && named) plan.ifMissing.push(member.name);
|
|
746
|
+
}
|
|
747
|
+
return plan;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* The members of `group` whose local folder submitting `names` puts on the pending branch, as
|
|
752
|
+
* {@link submitGroups} and {@link pushGroup} decide: pushed, and not kept as the pending branch
|
|
753
|
+
* has it (`onPending`), which a folder named unchanged is, and one whose content equals what this
|
|
754
|
+
* checkout last submitted. Null when Git cannot tell, as the push then fails.
|
|
755
|
+
*/
|
|
756
|
+
export async function localPushes(
|
|
757
|
+
companionPath: string,
|
|
758
|
+
group: string,
|
|
759
|
+
names: readonly string[],
|
|
760
|
+
onPending: ReadonlySet<string>,
|
|
761
|
+
deps: Pick<SubmitDeps, "git" | "artifactType" | "stateHome"> = {},
|
|
762
|
+
): Promise<string[] | null> {
|
|
763
|
+
const type = deps.artifactType ?? defaultArtifactType();
|
|
764
|
+
const git = (deps.git ?? defaultGit)(companionPath);
|
|
765
|
+
const inGroup = (await localMembers(companionPath, type)).filter(
|
|
766
|
+
(member) => member.group === group,
|
|
767
|
+
);
|
|
768
|
+
const submitted = readSubmittedFolders(companionPath, deps.stateHome);
|
|
769
|
+
const plan = await planPush(git, companionPath, type, inGroup, names, submitted);
|
|
770
|
+
if (plan.unknown.length > 0) return null;
|
|
771
|
+
const carried: string[] = [];
|
|
772
|
+
for (const name of plan.pushed) {
|
|
773
|
+
const relative = sourcePathOf(type, name);
|
|
774
|
+
const mine = submitted[relative]?.content;
|
|
775
|
+
if (onPending.has(name)) {
|
|
776
|
+
if (plan.ifMissing.includes(name)) continue;
|
|
777
|
+
if (mine !== undefined) {
|
|
778
|
+
// oxlint-disable-next-line no-await-in-loop -- a few members per group
|
|
779
|
+
const files = await ownFiles(git, companionPath, relative);
|
|
780
|
+
if (files === null) return null;
|
|
781
|
+
const own = files.filter((file) => file !== DELIVERY_FILE);
|
|
782
|
+
// oxlint-disable-next-line no-await-in-loop -- same member
|
|
783
|
+
if ((await folderDigest(path.join(companionPath, ...relative.split("/")), own)) === mine) {
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
carried.push(name);
|
|
789
|
+
}
|
|
790
|
+
return carried;
|
|
791
|
+
}
|
|
792
|
+
|
|
665
793
|
export type GroupStatus = "pushed" | "unchanged" | "waiting" | "failed";
|
|
666
794
|
|
|
667
795
|
export interface GroupSubmission {
|
|
@@ -698,28 +826,21 @@ export async function submitGroups(
|
|
|
698
826
|
const submissions: GroupSubmission[] = [];
|
|
699
827
|
for (const group of groups) {
|
|
700
828
|
const inGroup = members.filter((member) => member.group === group);
|
|
701
|
-
const waitingFor = inGroup
|
|
702
|
-
.filter((member) => member.state === "active" && !names.includes(member.name))
|
|
703
|
-
.map((member) => member.name);
|
|
829
|
+
const waitingFor = waitingMembers(inGroup, group, names);
|
|
704
830
|
if (waitingFor.length > 0) {
|
|
705
831
|
submissions.push({ group, status: "waiting", waitingFor });
|
|
706
832
|
continue;
|
|
707
833
|
}
|
|
708
|
-
const pushed: string[] = [];
|
|
709
|
-
const ifMissing: string[] = [];
|
|
710
|
-
const unknown: string[] = [];
|
|
711
834
|
const submitted = readSubmittedFolders(companionPath, options.stateHome);
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
if (edited === false && named) ifMissing.push(member.name);
|
|
722
|
-
}
|
|
835
|
+
// oxlint-disable-next-line no-await-in-loop -- one group at a time
|
|
836
|
+
const { pushed, ifMissing, unknown } = await planPush(
|
|
837
|
+
local,
|
|
838
|
+
companionPath,
|
|
839
|
+
type,
|
|
840
|
+
inGroup,
|
|
841
|
+
names,
|
|
842
|
+
submitted,
|
|
843
|
+
);
|
|
723
844
|
if (unknown.length > 0) {
|
|
724
845
|
const detail = `Git could not tell whether ${unknown.join(", ")} changed locally; nothing was pushed.`;
|
|
725
846
|
const push: GroupPush = { ...failed("failed", detail, null), group, changes: [] };
|
|
@@ -28,13 +28,16 @@ import type { BranchOutcome } from "./refresh";
|
|
|
28
28
|
import { repositoryAccessFor } from "./repository-access";
|
|
29
29
|
import { sourceDir, type ArtifactType } from "./staging/artifact-type";
|
|
30
30
|
import { openspecArtifactType } from "./staging/openspec-type";
|
|
31
|
+
import { preflightGroup } from "./staging/preflight";
|
|
31
32
|
import { loadSubmitWorkflow } from "./staging/registry";
|
|
32
33
|
import {
|
|
33
34
|
dropSubmitted,
|
|
35
|
+
editedSubmittedMembers,
|
|
34
36
|
groupOfChange,
|
|
35
37
|
localMembers,
|
|
36
38
|
submissionState,
|
|
37
39
|
submitGroups,
|
|
40
|
+
waitingMembers,
|
|
38
41
|
type DropResult,
|
|
39
42
|
type GroupSubmission,
|
|
40
43
|
type PendingFailure,
|
|
@@ -63,7 +66,7 @@ export interface SubmitResult {
|
|
|
63
66
|
group: string | null;
|
|
64
67
|
/** Local members of the group that keep it from being submitted. */
|
|
65
68
|
waitingFor: string[];
|
|
66
|
-
/** Whether this run pushed the group's folders. */
|
|
69
|
+
/** Whether this run pushed the group's folders; for an edited `submitted` member, its own. */
|
|
67
70
|
pushed: boolean;
|
|
68
71
|
/** The submit commit this run pushed. */
|
|
69
72
|
commit: string | null;
|
|
@@ -107,18 +110,27 @@ export interface SubmitChangeDeps extends RecordDeliveryDeps, Omit<SubmitDeps, "
|
|
|
107
110
|
openTasks?: typeof openTasks;
|
|
108
111
|
/**
|
|
109
112
|
* Called per change once before its check runs, so warnings are visible even when the check or
|
|
110
|
-
* the push fails or hangs
|
|
113
|
+
* the push fails or hangs, and once per group whose pre-flight was skipped, read only the last
|
|
114
|
+
* fetched refs, or found a change publication will block. Never called for `needs-branch` or a
|
|
115
|
+
* refusal.
|
|
111
116
|
*/
|
|
112
117
|
onWarnings?: (change: string, warnings: SubmitWarning[], unscoped: UnscopedDelivery[]) => void;
|
|
113
118
|
/** Pushes the groups; {@link submitGroups} by default. */
|
|
114
119
|
submitGroups?: typeof submitGroups;
|
|
120
|
+
/** Archives a group as publication would; {@link preflightGroup} by default. */
|
|
121
|
+
preflightGroup?: typeof preflightGroup;
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
/** A change past recording and its check, before the group push. */
|
|
118
125
|
type Prepared = Omit<
|
|
119
126
|
SubmitResult,
|
|
120
127
|
"status" | "group" | "waitingFor" | "pushed" | "commit" | "pendingBranch" | "state" | "message"
|
|
121
|
-
> & {
|
|
128
|
+
> & {
|
|
129
|
+
group: string;
|
|
130
|
+
failure?: string;
|
|
131
|
+
/** The failure is the group's pre-flight refusal of a change other than this one. */
|
|
132
|
+
groupRefused?: boolean;
|
|
133
|
+
};
|
|
122
134
|
|
|
123
135
|
/**
|
|
124
136
|
* What submitting leaves unfinished for `change`, as warnings: `stage-open` for
|
|
@@ -184,6 +196,7 @@ async function prepare(
|
|
|
184
196
|
type: ArtifactType,
|
|
185
197
|
workflow: Workflow,
|
|
186
198
|
deps: SubmitChangeDeps,
|
|
199
|
+
check = true,
|
|
187
200
|
): Promise<{ refusal: DeliveryRefusal } | { result: SubmitResult } | { prepared: Prepared }> {
|
|
188
201
|
const outcome = await recordDelivery(
|
|
189
202
|
environment,
|
|
@@ -238,16 +251,23 @@ async function prepare(
|
|
|
238
251
|
deps.onWarnings?.(change, warnings, settlement.unscoped);
|
|
239
252
|
|
|
240
253
|
const fields = { defaultBranch, diagnostics, record, settlement, outcomes, warnings };
|
|
241
|
-
const failure = await type.check(cwd, change);
|
|
254
|
+
const failure = check ? await type.check(cwd, change) : null;
|
|
242
255
|
if (failure) return { prepared: { ...fields, change, group: named.group, failure } };
|
|
243
256
|
return { prepared: { ...fields, change, group: named.group } };
|
|
244
257
|
}
|
|
245
258
|
|
|
246
|
-
function groupMessage(
|
|
259
|
+
function groupMessage(
|
|
260
|
+
change: string,
|
|
261
|
+
submission: GroupSubmission,
|
|
262
|
+
refused: ReadonlyMap<string, string>,
|
|
263
|
+
): string {
|
|
247
264
|
const { group, push } = submission;
|
|
248
265
|
if (submission.status === "waiting") {
|
|
249
|
-
|
|
250
|
-
? `${
|
|
266
|
+
const waiting = submission.waitingFor.map((name) =>
|
|
267
|
+
refused.has(name) ? `${name} (its delivery was refused: ${refused.get(name)})` : name,
|
|
268
|
+
);
|
|
269
|
+
return waiting.length > 0
|
|
270
|
+
? `${change} is not submitted: group ${group} lands together and waits for: ${waiting.join(", ")}. Finish, fix or drop them, then submit again; nothing was pushed.`
|
|
251
271
|
: `Checked ${change}; nothing was pushed.`;
|
|
252
272
|
}
|
|
253
273
|
const place = push?.pendingBranch ?? "the pending branch";
|
|
@@ -285,16 +305,77 @@ async function readySiblings(
|
|
|
285
305
|
return ready;
|
|
286
306
|
}
|
|
287
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Runs {@link preflightGroup} once per group of `prepared` that is not `held` and has no member
|
|
310
|
+
* left to wait for, with the names `submitGroups` gets: `edited` members are left out. A refused
|
|
311
|
+
* member fails as its check would and is returned; a refused change outside `prepared` fails
|
|
312
|
+
* every member of its group. A skipped or blocking pre-flight warns on each member and through
|
|
313
|
+
* `onWarnings`.
|
|
314
|
+
*/
|
|
315
|
+
async function preflight(
|
|
316
|
+
companionPath: string,
|
|
317
|
+
type: ArtifactType,
|
|
318
|
+
prepared: readonly Prepared[],
|
|
319
|
+
held: ReadonlyMap<string, unknown>,
|
|
320
|
+
edited: ReadonlySet<string>,
|
|
321
|
+
deps: SubmitChangeDeps,
|
|
322
|
+
): Promise<Prepared[]> {
|
|
323
|
+
const run = deps.preflightGroup ?? preflightGroup;
|
|
324
|
+
const locals = await localMembers(companionPath, type);
|
|
325
|
+
const refused: Prepared[] = [];
|
|
326
|
+
const pushing = new Map<string, string[]>();
|
|
327
|
+
for (const group of new Set(prepared.map((entry) => entry.group))) {
|
|
328
|
+
const named = prepared.filter((entry) => entry.group === group).map((entry) => entry.change);
|
|
329
|
+
if (held.has(group) || waitingMembers(locals, group, named).length > 0) continue;
|
|
330
|
+
pushing.set(
|
|
331
|
+
group,
|
|
332
|
+
named.filter((name) => !edited.has(name)),
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
for (const [group, names] of pushing) {
|
|
336
|
+
const entries = prepared.filter((entry) => entry.group === group);
|
|
337
|
+
// Fetched: the push builds on the remote's current inbox and default tip.
|
|
338
|
+
// oxlint-disable-next-line no-await-in-loop -- one worktree at a time
|
|
339
|
+
const outcome = await run(companionPath, group, names, {
|
|
340
|
+
...deps,
|
|
341
|
+
artifactType: type,
|
|
342
|
+
fetch: true,
|
|
343
|
+
pushing,
|
|
344
|
+
});
|
|
345
|
+
if (outcome.status === "failed") {
|
|
346
|
+
const target = entries.find((entry) => entry.change === outcome.change);
|
|
347
|
+
for (const entry of target ? [target] : entries) {
|
|
348
|
+
entry.failure = outcome.message;
|
|
349
|
+
if (!target) entry.groupRefused = true;
|
|
350
|
+
refused.push(entry);
|
|
351
|
+
}
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (outcome.status === "passed" && !outcome.message) continue;
|
|
355
|
+
const warning: SubmitWarning = {
|
|
356
|
+
kind: outcome.status === "blocked" ? "preflight-blocked" : "preflight-skipped",
|
|
357
|
+
change: outcome.status === "blocked" ? outcome.change : entries[0]!.change,
|
|
358
|
+
message: outcome.message!,
|
|
359
|
+
};
|
|
360
|
+
for (const entry of entries) entry.warnings.push(warning);
|
|
361
|
+
deps.onWarnings?.(entries[0]!.change, [warning], []);
|
|
362
|
+
}
|
|
363
|
+
return refused;
|
|
364
|
+
}
|
|
365
|
+
|
|
288
366
|
/**
|
|
289
367
|
* The Submit change stage for `request.changes` and their Worksets: each named change's delivery
|
|
290
368
|
* is recorded and refreshed, with warnings about overlapping requirements, unsubmitted
|
|
291
369
|
* dependencies, incomplete planning, an unfinished required stage of the Delivery Path and its
|
|
292
370
|
* Delivery Group, and the type's `check` runs. The
|
|
293
371
|
* other active changes of its Delivery Group join when every task of theirs is checked and they
|
|
294
|
-
* pass the same steps
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
372
|
+
* pass the same steps, as do its `submitted` members edited since this checkout submitted or took
|
|
373
|
+
* them. A group whose members all pass is then archived as publication would, in a temporary
|
|
374
|
+
* worktree; a member that archive refuses fails its check. A group is then pushed whole, in one
|
|
375
|
+
* commit that sets its changes `submitted`, or not at all: while a member has open tasks, fails
|
|
376
|
+
* its check, cannot be refreshed or has a merged branch with uncommitted work, the group waits
|
|
377
|
+
* and no state changes. Never archives in this checkout and never writes canonical specs; merge
|
|
378
|
+
* state is reported, never a refusal.
|
|
298
379
|
*/
|
|
299
380
|
export async function submitChanges(
|
|
300
381
|
environment: DeliveryEnvironment,
|
|
@@ -310,23 +391,26 @@ export async function submitChanges(
|
|
|
310
391
|
deps.artifactType ?? environment.artifactType ?? openspecArtifactType(deps.runOpenSpec);
|
|
311
392
|
const cwd = environment.companionPath;
|
|
312
393
|
const workflow = environment.workflow ?? (await loadSubmitWorkflow(cwd)).workflow;
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// oxlint-disable-next-line no-await-in-loop -- a few changes per run
|
|
318
|
-
const checked = await recordDelivery(
|
|
394
|
+
// A delivery Git would settle while its work tree holds uncommitted work is refused before that
|
|
395
|
+
// merge is recorded.
|
|
396
|
+
const dryRun = (own: SubmitRequest, change: string) =>
|
|
397
|
+
recordDelivery(
|
|
319
398
|
environment,
|
|
320
399
|
{
|
|
321
|
-
...deliveryRequest(
|
|
400
|
+
...deliveryRequest(own, change),
|
|
322
401
|
dryRun: true,
|
|
323
402
|
refresh: true,
|
|
324
403
|
refreshAll: true,
|
|
325
|
-
...(
|
|
404
|
+
...(own.fetch ? { fetch: true } : {}),
|
|
326
405
|
refuseUncommitted: true,
|
|
327
406
|
},
|
|
328
407
|
deps,
|
|
329
408
|
);
|
|
409
|
+
// Every change is refused or accepted before any record is written, so a refused later one
|
|
410
|
+
// leaves no earlier record changed.
|
|
411
|
+
for (const change of request.changes) {
|
|
412
|
+
// oxlint-disable-next-line no-await-in-loop -- a few changes per run
|
|
413
|
+
const checked = await dryRun(request, change);
|
|
330
414
|
if ("refusal" in checked) return checked;
|
|
331
415
|
}
|
|
332
416
|
const steps: ({ result: SubmitResult } | { prepared: Prepared })[] = [];
|
|
@@ -337,34 +421,72 @@ export async function submitChanges(
|
|
|
337
421
|
steps.push(step);
|
|
338
422
|
}
|
|
339
423
|
const named = steps.flatMap((step) => ("prepared" in step ? [step.prepared] : []));
|
|
424
|
+
const groups = new Set(named.map((entry) => entry.group));
|
|
340
425
|
const siblings = await readySiblings(
|
|
341
426
|
cwd,
|
|
342
427
|
type,
|
|
343
|
-
|
|
428
|
+
groups,
|
|
344
429
|
request.changes,
|
|
345
430
|
deps.openTasks ?? openTasks,
|
|
346
431
|
);
|
|
432
|
+
/** Why each unnamed change could not be prepared, for the message of the group waiting for it. */
|
|
433
|
+
const refused = new Map<string, string>();
|
|
434
|
+
const prepareUnnamed = async (
|
|
435
|
+
change: string,
|
|
436
|
+
extra: Pick<SubmitRequest, "skipBranch"> = {},
|
|
437
|
+
check = true,
|
|
438
|
+
): Promise<void> => {
|
|
439
|
+
const own: SubmitRequest = {
|
|
440
|
+
changes: [change],
|
|
441
|
+
...extra,
|
|
442
|
+
...(request.fetch ? { fetch: true } : {}),
|
|
443
|
+
};
|
|
444
|
+
const checked = await dryRun(own, change);
|
|
445
|
+
const step =
|
|
446
|
+
"refusal" in checked
|
|
447
|
+
? checked
|
|
448
|
+
: await prepare(environment, own, change, type, workflow, deps, check);
|
|
449
|
+
if ("refusal" in step) refused.set(change, step.refusal.reason);
|
|
450
|
+
else if ("prepared" in step) steps.push(step);
|
|
451
|
+
};
|
|
452
|
+
// One that cannot be prepared stays active, so its group waits for it.
|
|
347
453
|
for (const change of siblings) {
|
|
348
454
|
// oxlint-disable-next-line no-await-in-loop -- warnings reach stderr change by change
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
455
|
+
await prepareUnnamed(change);
|
|
456
|
+
}
|
|
457
|
+
// The archive alias pushes nothing, and its `--json` stays one object for one change.
|
|
458
|
+
const edited = request.holdPush
|
|
459
|
+
? []
|
|
460
|
+
: await editedSubmittedMembers(cwd, groups, request.changes, { ...deps, artifactType: type });
|
|
461
|
+
const editedNames = new Set(edited.map((member) => member.name));
|
|
462
|
+
// Accepted once already, so a change nobody named never answers `needs-branch`. One whose
|
|
463
|
+
// content is as last submitted skips its check: that content passed one, and the push may keep
|
|
464
|
+
// a teammate's copy instead.
|
|
465
|
+
for (const member of edited) {
|
|
466
|
+
// oxlint-disable-next-line no-await-in-loop -- warnings reach stderr change by change
|
|
467
|
+
await prepareUnnamed(member.name, { skipBranch: true }, !member.recordOnly);
|
|
359
468
|
}
|
|
360
469
|
const prepared = steps.flatMap((step) => ("prepared" in step ? [step.prepared] : []));
|
|
361
470
|
|
|
362
471
|
// A group with a failed check is not pushed at all: it waits for the failing changes.
|
|
363
472
|
const failing = new Map<string, string[]>();
|
|
364
|
-
|
|
365
|
-
failing.set(
|
|
473
|
+
const hold = (group: string, change: string): void => {
|
|
474
|
+
failing.set(group, [...(failing.get(group) ?? []), change]);
|
|
475
|
+
};
|
|
476
|
+
for (const entry of prepared.filter((each) => each.failure)) hold(entry.group, entry.change);
|
|
477
|
+
// `submitGroups` would push one unprepared: a `submitted` member never makes a group wait there.
|
|
478
|
+
for (const member of edited) {
|
|
479
|
+
if (!prepared.some((entry) => entry.change === member.name)) hold(member.group, member.name);
|
|
366
480
|
}
|
|
367
|
-
|
|
481
|
+
// The archive alias pushes nothing, so publication's view of a push does not apply.
|
|
482
|
+
const archiveRefused = request.holdPush
|
|
483
|
+
? []
|
|
484
|
+
: await preflight(cwd, type, prepared, failing, editedNames, deps);
|
|
485
|
+
for (const entry of archiveRefused) hold(entry.group, entry.change);
|
|
486
|
+
// Left unnamed: `submitGroups` pushes them anyway, and a name would accept a pending block.
|
|
487
|
+
const ready = prepared.filter(
|
|
488
|
+
(entry) => !failing.has(entry.group) && !editedNames.has(entry.change),
|
|
489
|
+
);
|
|
368
490
|
const held: GroupSubmission[] = [...failing].map(([group, waitingFor]) => ({
|
|
369
491
|
group,
|
|
370
492
|
status: "waiting",
|
|
@@ -389,7 +511,7 @@ export async function submitChanges(
|
|
|
389
511
|
|
|
390
512
|
const results = new Map<Prepared, SubmitResult>();
|
|
391
513
|
for (const entry of prepared) {
|
|
392
|
-
const { failure, ...fields } = entry;
|
|
514
|
+
const { failure, groupRefused, ...fields } = entry;
|
|
393
515
|
const base = { ...fields, waitingFor: [], pushed: false, commit: null, pendingBranch: null };
|
|
394
516
|
// oxlint-disable-next-line no-await-in-loop -- a few changes per run
|
|
395
517
|
const current = await submissionState(sourceDir(cwd, type, entry.change));
|
|
@@ -399,7 +521,9 @@ export async function submitChanges(
|
|
|
399
521
|
status: "failed",
|
|
400
522
|
state: current,
|
|
401
523
|
reason: "check-failed",
|
|
402
|
-
message:
|
|
524
|
+
message: groupRefused
|
|
525
|
+
? `mate: ${entry.change} was not submitted: publication would refuse its group ${entry.group}; nothing was pushed.\n${failure}`
|
|
526
|
+
: `mate: ${entry.change} failed its check; nothing was pushed.\n${failure}`,
|
|
403
527
|
});
|
|
404
528
|
continue;
|
|
405
529
|
}
|
|
@@ -408,18 +532,20 @@ export async function submitChanges(
|
|
|
408
532
|
const push = submission.push;
|
|
409
533
|
const landed = submission.status === "pushed" || submission.status === "unchanged";
|
|
410
534
|
const state: SubmissionState = landed ? "submitted" : current;
|
|
535
|
+
// The push leaves out an edited member whose copy on the pending branch stands.
|
|
536
|
+
const carried = !editedNames.has(entry.change) || push?.changes.includes(entry.change) === true;
|
|
411
537
|
results.set(entry, {
|
|
412
538
|
...base,
|
|
413
539
|
status: landed ? "submitted" : submission.status === "waiting" ? "waiting" : "failed",
|
|
414
540
|
waitingFor: submission.waitingFor,
|
|
415
|
-
pushed: submission.status === "pushed",
|
|
541
|
+
pushed: submission.status === "pushed" && carried,
|
|
416
542
|
commit: push?.commit ?? null,
|
|
417
543
|
pendingBranch: push?.pendingBranch ?? null,
|
|
418
544
|
state,
|
|
419
545
|
record: { ...entry.record, state },
|
|
420
546
|
...(push?.reason ? { reason: push.reason } : {}),
|
|
421
547
|
...(push?.secretFindings ? { secretFindings: push.secretFindings } : {}),
|
|
422
|
-
message: groupMessage(entry.change, submission),
|
|
548
|
+
message: groupMessage(entry.change, submission, refused),
|
|
423
549
|
});
|
|
424
550
|
}
|
|
425
551
|
return {
|
package/src/lib/friction/mark.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
findEvent,
|
|
3
|
+
findEvents,
|
|
4
|
+
findFingerprint,
|
|
5
|
+
findReport,
|
|
6
|
+
type FrictionEvent,
|
|
7
|
+
type FrictionReport,
|
|
8
|
+
readReportIds,
|
|
9
|
+
} from "../../runtime/friction-log";
|
|
2
10
|
import {
|
|
3
11
|
FrictionStateFileError,
|
|
4
12
|
type FrictionStatesFile,
|
|
@@ -32,6 +40,10 @@ export type MarkResult =
|
|
|
32
40
|
|
|
33
41
|
const REPORT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
34
42
|
|
|
43
|
+
/** Report ids are stored in lower case; a fingerprint is kept exactly as given. */
|
|
44
|
+
const canonicalTarget = (target: string) =>
|
|
45
|
+
REPORT_ID.test(target) ? target.toLowerCase() : target;
|
|
46
|
+
|
|
35
47
|
const unknownTarget = (target: string) =>
|
|
36
48
|
new FrictionRefusal(
|
|
37
49
|
"unknown-target",
|
|
@@ -62,6 +74,38 @@ function checkLink(link: string | null, state: MarkState): void {
|
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
76
|
|
|
77
|
+
/** A Friction Item a person can mark or triage, with its records from the whole Friction Log. */
|
|
78
|
+
export type FrictionTarget =
|
|
79
|
+
| { id: string; kind: "fingerprint"; events: FrictionEvent[] }
|
|
80
|
+
| { id: string; kind: "report"; report: FrictionReport };
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Looks a fingerprint or Free Report id up in the whole Friction Log; throws a `FrictionRefusal`
|
|
84
|
+
* for an unknown id or a report on an event. `verb` names the action the refusal points to.
|
|
85
|
+
*/
|
|
86
|
+
export function lookupFrictionTarget(
|
|
87
|
+
given: string,
|
|
88
|
+
options: { homeDir?: string; verb?: string } = {},
|
|
89
|
+
): FrictionTarget {
|
|
90
|
+
const { homeDir, verb = "Mark" } = options;
|
|
91
|
+
const target = canonicalTarget(given);
|
|
92
|
+
if (!REPORT_ID.test(target)) {
|
|
93
|
+
const events = findEvents((event) => event.fingerprint === target, { homeDir });
|
|
94
|
+
if (events.length === 0) throw unknownTarget(target);
|
|
95
|
+
return { id: target, kind: "fingerprint", events };
|
|
96
|
+
}
|
|
97
|
+
const report = findReport(target, { homeDir });
|
|
98
|
+
if (!report) throw unknownTarget(target);
|
|
99
|
+
if (report.eventId) {
|
|
100
|
+
const event = findEvent(report.eventId, { homeDir });
|
|
101
|
+
throw new FrictionRefusal(
|
|
102
|
+
"report-on-event",
|
|
103
|
+
`${target} is a report on an event; it follows the state of its fingerprint${event ? ` ${event.fingerprint}` : ""}. ${verb} that fingerprint instead; nothing was changed.`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return { id: target, kind: "report", report };
|
|
107
|
+
}
|
|
108
|
+
|
|
65
109
|
function resolveTarget(
|
|
66
110
|
target: string,
|
|
67
111
|
known: { fingerprints: object; reports: object },
|
|
@@ -70,18 +114,11 @@ function resolveTarget(
|
|
|
70
114
|
if (Object.hasOwn(known.fingerprints, target)) return "fingerprints";
|
|
71
115
|
if (Object.hasOwn(known.reports, target)) return "reports";
|
|
72
116
|
if (!REPORT_ID.test(target)) {
|
|
117
|
+
// Stops at the newest match; mark needs no full scan.
|
|
73
118
|
if (!findFingerprint(target, { homeDir })) throw unknownTarget(target);
|
|
74
119
|
return "fingerprints";
|
|
75
120
|
}
|
|
76
|
-
|
|
77
|
-
if (!report) throw unknownTarget(target);
|
|
78
|
-
if (report.eventId) {
|
|
79
|
-
const event = findEvent(report.eventId, { homeDir });
|
|
80
|
-
throw new FrictionRefusal(
|
|
81
|
-
"report-on-event",
|
|
82
|
-
`${target} is a report on an event; it follows the state of its fingerprint${event ? ` ${event.fingerprint}` : ""}. Mark that fingerprint instead; nothing was changed.`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
121
|
+
lookupFrictionTarget(target, { homeDir });
|
|
85
122
|
return "reports";
|
|
86
123
|
}
|
|
87
124
|
|
|
@@ -100,11 +137,12 @@ function forgetExpiredReports(
|
|
|
100
137
|
* live here once for every caller; the Friction Log is never written.
|
|
101
138
|
*/
|
|
102
139
|
export async function markFriction(
|
|
103
|
-
|
|
140
|
+
given: string,
|
|
104
141
|
state: MarkState,
|
|
105
142
|
input: MarkInput,
|
|
106
143
|
deps: MarkDeps = {},
|
|
107
144
|
): Promise<MarkResult> {
|
|
145
|
+
const target = canonicalTarget(given);
|
|
108
146
|
try {
|
|
109
147
|
const note = textOrNull(input.note);
|
|
110
148
|
const link = textOrNull(input.link);
|
|
@@ -45,7 +45,16 @@ export function readFrictionRecords(scope: FrictionScope, window: FrictionWindow
|
|
|
45
45
|
homeDir: window.homeDir,
|
|
46
46
|
now: window.now,
|
|
47
47
|
});
|
|
48
|
-
|
|
48
|
+
return joinFrictionStates(events, reports, window.homeDir);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Adds the Friction States of the given records' fingerprints and Free Reports. */
|
|
52
|
+
export function joinFrictionStates(
|
|
53
|
+
events: FrictionEvent[],
|
|
54
|
+
reports: FrictionReport[],
|
|
55
|
+
homeDir?: string,
|
|
56
|
+
): FrictionRecords {
|
|
57
|
+
const stored = readFrictionStates(homeDir);
|
|
49
58
|
const fingerprints: Record<string, FrictionGroupState> = {};
|
|
50
59
|
for (const [fingerprint, grouped] of byFingerprint(events)) {
|
|
51
60
|
const state = stored.fingerprints[fingerprint];
|
package/src/lib/openspec-cli.ts
CHANGED
|
@@ -79,6 +79,15 @@ export const openSpecCliDeps = {
|
|
|
79
79
|
locate: (): OpenSpecLocation => resolveOpenSpec(),
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* How to start a CLI mate-core depends on. A JS entry runs on the current runtime, not its
|
|
84
|
+
* `#!/usr/bin/env node` shebang, which needs an executable bit and `node` on PATH and does
|
|
85
|
+
* not work on Windows.
|
|
86
|
+
*/
|
|
87
|
+
export function bundledCliCommand(bin: string, args: string[]): [string, string[]] {
|
|
88
|
+
return /\.m?js$/.test(bin) ? [process.execPath, [bin, ...args]] : [bin, args];
|
|
89
|
+
}
|
|
90
|
+
|
|
82
91
|
/** The CLI every OpenSpec process Mate starts runs. */
|
|
83
92
|
export function locateOpenSpec(): OpenSpecLocation {
|
|
84
93
|
return openSpecCliDeps.locate();
|
|
@@ -91,11 +100,7 @@ export function runOpenSpec(args: string[], options: OpenSpecRunOptions): Promis
|
|
|
91
100
|
return Promise.resolve({ code: 1, stdout: "", stderr: location.missing, missing: true });
|
|
92
101
|
}
|
|
93
102
|
return new Promise((resolve) => {
|
|
94
|
-
|
|
95
|
-
// which needs an executable bit and `node` on PATH and does not work on Windows.
|
|
96
|
-
const [command, commandArgs] = location.bin.endsWith(".js")
|
|
97
|
-
? [process.execPath, [location.bin, ...args]]
|
|
98
|
-
: [location.bin, args];
|
|
103
|
+
const [command, commandArgs] = bundledCliCommand(location.bin, args);
|
|
99
104
|
const child = spawn(command, commandArgs, {
|
|
100
105
|
cwd: options.cwd,
|
|
101
106
|
env: { ...(options.env ?? process.env), ...OPENSPEC_ENV },
|