@uniqbit/mate-core 1.0.0-canary.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/package.json +5 -4
- package/src/cli/commands/artifact/delivery/link.ts +1 -1
- package/src/cli/commands/artifact/delivery/output.ts +10 -1
- package/src/cli/commands/artifact/delivery/resolve.ts +3 -2
- package/src/cli/commands/artifact/delivery/submit.ts +9 -4
- package/src/cli/commands/artifact/delivery/take.ts +12 -9
- package/src/cli/commands/artifact/finish/command.ts +16 -14
- package/src/cli/commands/artifact/finish/engine.ts +8 -8
- package/src/cli/commands/artifact/project/command.ts +2 -3
- package/src/cli/commands/companion/hub.ts +11 -6
- package/src/cli/commands/companion/link.ts +173 -46
- package/src/cli/commands/report/contract.ts +0 -17
- package/src/cli/commands/studio/access.ts +4 -0
- package/src/cli/commands/studio/actions.ts +35 -2
- package/src/cli/commands/studio/mcp-manager.ts +162 -0
- package/src/cli/commands/studio/routes.ts +12 -0
- package/src/cli/commands/studio/selection.ts +44 -11
- package/src/cli/commands/studio/server.ts +246 -2
- package/src/cli/commands/studio/services.ts +26 -0
- package/src/cli/commands/studio/terminal-launch.ts +21 -4
- package/src/cli/commands/studio/terminal.ts +3 -14
- package/src/cli/commands/studio/work-requests.ts +9 -0
- package/src/cli/commands/studio/work.ts +473 -0
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/commands/working/cleanup.ts +1 -18
- package/src/cli/companion-link-wizard.tsx +158 -91
- package/src/cli/usage.ts +1 -1
- package/src/lib/agent-credential.ts +131 -0
- package/src/lib/credential-kinds.ts +7 -0
- package/src/lib/delivery/merge-git.ts +16 -0
- package/src/lib/delivery/record-delivery.ts +12 -6
- package/src/lib/delivery/record.ts +5 -0
- package/src/lib/delivery/refresh.ts +34 -6
- package/src/lib/delivery/staging/refs.ts +9 -4
- package/src/lib/delivery/staging/submit.ts +81 -22
- package/src/lib/mcp-manager/resolve.ts +27 -9
- package/src/lib/mcp-manager/store.ts +35 -11
- package/src/lib/mcp-manager/types.ts +14 -0
- package/src/lib/mcp-manager/validate.ts +6 -10
- package/src/lib/opencode-server.ts +2 -17
- package/src/lib/orchestrator/repo-local-store.ts +14 -0
- package/src/lib/orchestrator/repository-link.ts +80 -52
- package/src/lib/orchestrator/root-context.ts +17 -1
- package/src/lib/studio-chat/agent.ts +139 -0
- package/src/lib/studio-chat/companion-context.ts +136 -0
- package/src/lib/studio-chat/credential.ts +79 -0
- package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
- package/src/lib/studio-chat/host-sandbox.ts +578 -0
- package/src/lib/studio-chat/prepare-bridges.ts +95 -0
- package/src/lib/studio-chat/session.ts +15 -0
- package/src/lib/studio-chat/turns.ts +112 -0
- package/src/lib/workset/claims.ts +85 -0
- package/src/lib/workset/execution.ts +71 -0
- package/src/lib/workset/git-transaction.ts +74 -0
- package/src/lib/workset/groups.ts +176 -0
- package/src/lib/workset/inventory.ts +196 -0
- package/src/lib/workset/projection.ts +237 -0
- package/src/lib/workset/record.ts +101 -36
- package/src/lib/workset/repositories.ts +24 -0
- package/src/lib/workset/sharing.ts +951 -0
- package/src/lib/workset/stages.ts +50 -14
- package/src/lib/workset/transactions.ts +158 -0
- package/src/runtime/companion-git-state.ts +1 -0
- package/src/runtime/companion-guidance.ts +2 -2
- package/src/runtime/forge-remote.ts +6 -0
- package/src/runtime/host-process.ts +28 -0
- package/src/runtime/secret-guard.ts +18 -1
- package/src/runtime/secret-patterns.ts +4 -3
- package/src/runtime/submitted-arrivals.ts +28 -2
- package/src/runtime/write-atomic.ts +2 -2
- package/src/studio.ts +52 -8
- package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +1 -1
- package/src/templates/capabilities/openspec-cap/mate-full/templates/proposal.md +1 -1
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +3 -2
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +5 -3
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +3 -2
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +5 -3
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +12 -12
- package/src/tools/setup/capabilities/mcp-manager.ts +1 -2
- package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
- package/src/tools/setup/plugins/gitignore.ts +1 -0
- package/src/tools/setup/providers/claude-format.ts +1 -5
- package/src/tools/setup/providers/claude.ts +28 -3
- package/src/tools/setup/providers/opencode.ts +7 -18
- package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
- package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
- package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
- package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
- package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
- package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
- package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
- package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
- package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
- package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
- package/studio-dist/client/assets/{companion-view-C1F0_jbt.js → companion-view-B54_Lj0S.js} +1 -1
- package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
- package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
- package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
- package/studio-dist/client/assets/{getting-started-BN4aTpsz.js → getting-started-CAszmdDJ.js} +1 -1
- package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
- package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
- package/studio-dist/client/assets/{graph-canvas-Be5qgdDt.js → graph-canvas-BdNk2F9O.js} +1 -1
- package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
- package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
- package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
- package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
- package/studio-dist/client/assets/{markdown-view-dku7MGPn.js → markdown-view-CJ8JsLb7.js} +1 -1
- package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
- package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
- package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
- package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
- package/studio-dist/client/assets/{prepaint-BkoDSw5X.js → prepaint-sD_LlrDN.js} +1 -1
- package/studio-dist/client/assets/{queries-CMvC2OkU.js → queries-COL925ML.js} +1 -1
- package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
- package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
- package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
- package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
- package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
- package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
- package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
- package/studio-dist/client/assets/{specs-Bqd1ajyD.js → specs-C_tZnAvF.js} +1 -1
- package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
- package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
- package/studio-dist/client/assets/{store-BYnEU33C.js → store-pY9gU4uS.js} +1 -1
- package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
- package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
- package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
- package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
- package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
- package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
- package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
- package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
- package/studio-dist/client/assets/{warnings-Cnw99ugO.js → warnings-D7YY1HSG.js} +1 -1
- package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
- package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
- package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
- package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-CS3QRY4Q.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
- package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
- package/studio-dist/server/assets/{cn-DWFJaP_9.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
- package/studio-dist/server/assets/{button-Ct_WeYLc.js → button-BqA1urbl.js} +14 -7
- package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
- package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
- package/studio-dist/server/assets/{combobox-17vO5Uz8.js → combobox-iTjvPCtS.js} +7 -6
- package/studio-dist/server/assets/{companion-view-JkxnGLlp.js → companion-view-DIQ6AFIY.js} +2 -2
- package/studio-dist/server/assets/{companions-YNLsbnch.js → companions-aVwjRL8j.js} +1 -1
- package/studio-dist/server/assets/{fields-VytPpqBq.js → fields-BMap2_Ju.js} +10 -3
- package/studio-dist/server/assets/{friction-BW86PCPM.js → friction-BER50hoD.js} +2 -2
- package/studio-dist/server/assets/{friction-B6osqFSm.js → friction-BPs9KWdq.js} +8 -8
- package/studio-dist/server/assets/{getting-started-CFHSeX5h.js → getting-started-DGfRVmZ_.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-BK2eU6AS.js → getting-started._topic-BgrBA4Vj.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-DZLuXnNO.js → getting-started.index-BaFfQ9Mn.js} +2 -2
- package/studio-dist/server/assets/{graph-BJVZBevL.js → graph-Cgzlrv3P.js} +8 -8
- package/studio-dist/server/assets/{graph-DGZHV-Ek.js → graph-DODpuOy_.js} +1 -1
- package/studio-dist/server/assets/{graph-canvas-lrNT6jbl.js → graph-canvas-DW_zU1nA.js} +2 -2
- package/studio-dist/server/assets/{guides-_G8Vucsk.js → guides-CA_EMG7E.js} +1 -1
- package/studio-dist/server/assets/{guides-CEwLOZb9.js → guides-D0SpoD32.js} +1 -1
- package/studio-dist/server/assets/{guides.server-ZWFKX2XJ.js → guides.server-DJjQuy03.js} +1 -1
- package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
- package/studio-dist/server/assets/{markdown-view-Bmjghg_Z.js → markdown-view-CvVBGMZV.js} +1 -1
- package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
- package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
- package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
- package/studio-dist/server/assets/{panel-DvRjyil3.js → panel-D1K6Bsux.js} +4 -32
- package/studio-dist/server/assets/{plugins._service._view-B32LzraG.js → plugins._service._view-DdO1nELF.js} +4 -4
- package/studio-dist/server/assets/{prepaint-BEHwKl51.js → prepaint-BB3dwSmz.js} +1 -1
- package/studio-dist/server/assets/{queries-D6Vq0AuZ.js → queries-BwiDxQy5.js} +1 -1
- package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
- package/studio-dist/server/assets/{reports-Dn92pLap.js → reports-9Pr7Bz6o.js} +7 -7
- package/studio-dist/server/assets/{reports-DDaH5k0H.js → reports-Cc9M3phM.js} +1 -1
- package/studio-dist/server/assets/{router-Bjf4S9tO.js → router-DcWe0J7Y.js} +827 -548
- package/studio-dist/server/assets/{routes-B4sNiE0X.js → routes-BEXxl0py.js} +8 -8
- package/studio-dist/server/assets/{search-DKeJRvg8.js → search-bltT7gwy.js} +39 -7
- package/studio-dist/server/assets/{select-CVHYL7oR.js → select-CZvHgGCi.js} +7 -6
- package/studio-dist/server/assets/{shell-BxbYYaAk.js → shell-BQ0vMKXN.js} +13 -4
- package/studio-dist/server/assets/{skills-Bj8eOgzR.js → skills-Be_52h0i.js} +1 -1
- package/studio-dist/server/assets/{skills-B4-0qpqN.js → skills-BpGGUl6L.js} +8 -8
- package/studio-dist/server/assets/{specs-rfMug6qW.js → specs-CCGgXE-V.js} +5 -5
- package/studio-dist/server/assets/{specs-view-qi1SE1Sl.js → specs-view-DtL5JxYM.js} +12 -11
- package/studio-dist/server/assets/{steps-rger6HJc.js → steps-BWFSO6dM.js} +1 -1
- package/studio-dist/server/assets/{store-Dg9T7oWs.js → store-X7yLPp7v.js} +1 -1
- package/studio-dist/server/assets/{studio-queries-CeFfmIuM.js → studio-queries-ur1ygXi3.js} +117 -13
- package/studio-dist/server/assets/{studio-D79JzDLc.js → studio-qzH-UETC.js} +209 -180
- package/studio-dist/server/assets/{usage-Dw_UQFX-.js → usage-C1o0DLzS.js} +1 -1
- package/studio-dist/server/assets/{usage-BJgYWRCX.js → usage-DWbSPrPD.js} +10 -9
- package/studio-dist/server/assets/{useAnchoredPopupScrollLock-ciS_sEq3.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
- package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
- package/studio-dist/server/assets/{useMutation-DnWK0PhO.js → useMutation-NjlA8oFY.js} +2 -2
- package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
- package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
- package/studio-dist/server/assets/{vault-BzarssiL.js → vault-B_kfi1h-.js} +1 -1
- package/studio-dist/server/assets/{vault-CvlrLd2H.js → vault-dL79JlKH.js} +8 -115
- package/studio-dist/server/assets/{views-CAxwKHMK.js → views-BSGH56lb.js} +3 -3
- package/studio-dist/server/assets/{warnings-BpVCugHm.js → warnings-DtUVPV-k.js} +2 -2
- package/studio-dist/server/assets/work-D789VXGH.js +110 -0
- package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
- package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
- package/studio-dist/server/assets/{workflow-BdrzcCt8.js → workflow-BOZ2sRYg.js} +9 -9
- package/studio-dist/server/server.js +3 -3
- package/wrappers/bin/openspec +87 -2
- package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
- package/studio-dist/client/assets/button-C9SQW3kI.js +0 -1
- package/studio-dist/client/assets/cn-DC80MJV0.js +0 -1
- package/studio-dist/client/assets/combobox-D7mKYCBb.js +0 -1
- package/studio-dist/client/assets/fields-CEep8IFT.js +0 -1
- package/studio-dist/client/assets/friction-D9dBU7WN.js +0 -1
- package/studio-dist/client/assets/getting-started-BDyGvHhc.js +0 -1
- package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +0 -1
- package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +0 -1
- package/studio-dist/client/assets/graph-ah7ZXfTa.js +0 -2
- package/studio-dist/client/assets/guides-CsL0660B.js +0 -1
- package/studio-dist/client/assets/index-zmRH87D4.js +0 -40
- package/studio-dist/client/assets/panel-COgk0vP5.js +0 -1
- package/studio-dist/client/assets/plugins._service._view-Cn3WBHab.js +0 -1
- package/studio-dist/client/assets/reports-C_AqLBYH.js +0 -1
- package/studio-dist/client/assets/routes-BokQmHtC.js +0 -1
- package/studio-dist/client/assets/search-DxidNK2M.js +0 -1
- package/studio-dist/client/assets/select-CYFCbHUd.js +0 -1
- package/studio-dist/client/assets/skills-R3vttWHM.js +0 -1
- package/studio-dist/client/assets/specs-view-znqFPx9p.js +0 -1
- package/studio-dist/client/assets/steps-tVDWn7j6.js +0 -1
- package/studio-dist/client/assets/studio-ndtFcS2Y.js +0 -100
- package/studio-dist/client/assets/studio-queries-CkUSByy7.js +0 -2
- package/studio-dist/client/assets/usage-Kuhr8dSl.js +0 -55
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-dc_kP4Go.js +0 -1
- package/studio-dist/client/assets/useMutation-CqtM9COw.js +0 -1
- package/studio-dist/client/assets/vault-CSP8kwRg.js +0 -1
- package/studio-dist/client/assets/workflow-BPJAmmZi.js +0 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
archiveAnchors as listArchiveAnchors,
|
|
5
|
+
changeNameOf,
|
|
6
|
+
changesDirOf,
|
|
7
|
+
parseAnchor,
|
|
8
|
+
} from "../change-layout";
|
|
9
|
+
import { scopedRepositories } from "../openspec-scopes";
|
|
10
|
+
import { activeLinks, type ChangeLinks, deriveGroups } from "./groups";
|
|
11
|
+
import {
|
|
12
|
+
isRepositoryIdentity,
|
|
13
|
+
isWorksetId,
|
|
14
|
+
type LinkedChange,
|
|
15
|
+
readWorksets,
|
|
16
|
+
type WorksetListing,
|
|
17
|
+
type WorksetRecord,
|
|
18
|
+
} from "./record";
|
|
19
|
+
|
|
20
|
+
export interface ActiveChangeScope {
|
|
21
|
+
name: string;
|
|
22
|
+
repositories: string[] | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface InventoryInput {
|
|
26
|
+
listing: WorksetListing;
|
|
27
|
+
activeChanges: ActiveChangeScope[];
|
|
28
|
+
links: ChangeLinks[];
|
|
29
|
+
archiveAnchors: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface InventoryWorkset {
|
|
33
|
+
id: string;
|
|
34
|
+
implicit: boolean;
|
|
35
|
+
record: WorksetRecord;
|
|
36
|
+
members: LinkedChange[];
|
|
37
|
+
branches: string[];
|
|
38
|
+
diagnostics: string[];
|
|
39
|
+
actionable: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface WorkInventory {
|
|
43
|
+
worksets: InventoryWorkset[];
|
|
44
|
+
diagnostics: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function refuseSharedIds(entries: InventoryWorkset[]): InventoryWorkset[] {
|
|
48
|
+
const seen = new Map<string, number>();
|
|
49
|
+
for (const entry of entries) seen.set(entry.id, (seen.get(entry.id) ?? 0) + 1);
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if ((seen.get(entry.id) ?? 0) > 1) {
|
|
52
|
+
entry.diagnostics.push(`another Workset is also named ${entry.id}`);
|
|
53
|
+
entry.actionable = false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return entries;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function activeMembers(entry: InventoryWorkset): string[] {
|
|
60
|
+
return entry.members.filter((member) => member.kind === "active").map((member) => member.name);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function implicitRecord(
|
|
64
|
+
id: string,
|
|
65
|
+
members: string[],
|
|
66
|
+
repositories: string[],
|
|
67
|
+
): WorksetRecord {
|
|
68
|
+
return {
|
|
69
|
+
id,
|
|
70
|
+
title: id,
|
|
71
|
+
intent: "",
|
|
72
|
+
repositories,
|
|
73
|
+
changes: members,
|
|
74
|
+
stage: "ready",
|
|
75
|
+
createdAt: "",
|
|
76
|
+
extra: {},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function worksetIdDiagnostics(id: string): string[] {
|
|
81
|
+
return isWorksetId(id) ? [] : [`${id} is not a kebab-case name and cannot name a Workset`];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function scopeDiagnostics(change: ActiveChangeScope): string[] {
|
|
85
|
+
if (change.repositories === null) return [`the scopes of ${change.name} cannot be read`];
|
|
86
|
+
if (change.repositories.length === 0) return [`${change.name} names no scoped repository`];
|
|
87
|
+
const invalid = change.repositories.find((repository) => !isRepositoryIdentity(repository));
|
|
88
|
+
return invalid
|
|
89
|
+
? [`${change.name} scopes ${JSON.stringify(invalid)}, which is no org/repository`]
|
|
90
|
+
: [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function buildInventory(input: InventoryInput): WorkInventory {
|
|
94
|
+
const { listing } = input;
|
|
95
|
+
const active = new Map(input.activeChanges.map((change) => [change.name, change]));
|
|
96
|
+
const linksOf = new Map(input.links.map((links) => [links.name, links]));
|
|
97
|
+
const newestArchive = new Map<string, string>();
|
|
98
|
+
for (const anchor of input.archiveAnchors.toSorted()) {
|
|
99
|
+
const parsed = parseAnchor(anchor);
|
|
100
|
+
if (parsed) newestArchive.set(parsed.name, anchor);
|
|
101
|
+
}
|
|
102
|
+
const records = new Map(listing.worksets.map((record) => [record.id, record]));
|
|
103
|
+
const listedBy = new Map(
|
|
104
|
+
listing.worksets.map((record) => [record.id, record.changes.map(changeNameOf)] as const),
|
|
105
|
+
);
|
|
106
|
+
const groups = deriveGroups(
|
|
107
|
+
input.links.filter((links) => active.has(links.name)),
|
|
108
|
+
listedBy,
|
|
109
|
+
);
|
|
110
|
+
const grouped = new Set(
|
|
111
|
+
[...listedBy].filter(([, names]) => names.some((name) => active.has(name))).map(([id]) => id),
|
|
112
|
+
);
|
|
113
|
+
const unreadable = listing.problems.length > 0;
|
|
114
|
+
const entries: InventoryWorkset[] = [];
|
|
115
|
+
const pastMember = (name: string): LinkedChange => {
|
|
116
|
+
const anchor = newestArchive.get(name);
|
|
117
|
+
return anchor ? { name, kind: "archived", anchor } : { name, kind: "missing" };
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
for (const group of groups) {
|
|
121
|
+
const record = group.record ? records.get(group.record) : undefined;
|
|
122
|
+
const members: LinkedChange[] = group.members.map((name) => ({ name, kind: "active" }));
|
|
123
|
+
for (const name of listedBy.get(group.record ?? "") ?? []) {
|
|
124
|
+
if (!active.has(name)) members.push(pastMember(name));
|
|
125
|
+
}
|
|
126
|
+
const scopes = group.members.map((name) => active.get(name)!);
|
|
127
|
+
const repositories = [
|
|
128
|
+
...new Set(scopes.flatMap((scope) => scope.repositories ?? [])),
|
|
129
|
+
].toSorted();
|
|
130
|
+
const diagnostics = [
|
|
131
|
+
...group.diagnostics,
|
|
132
|
+
...scopes.flatMap(scopeDiagnostics),
|
|
133
|
+
...worksetIdDiagnostics(group.id),
|
|
134
|
+
];
|
|
135
|
+
if (!record && records.has(group.id)) {
|
|
136
|
+
diagnostics.push(
|
|
137
|
+
`Scratchpad idea ${group.id} and change ${group.id} collide; rename one of them`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if (unreadable && !record) {
|
|
141
|
+
diagnostics.push("some Scratchpad records cannot be read, so grouping is uncertain");
|
|
142
|
+
}
|
|
143
|
+
entries.push({
|
|
144
|
+
id: group.id,
|
|
145
|
+
implicit: !record,
|
|
146
|
+
record: record ?? implicitRecord(group.id, group.members, repositories),
|
|
147
|
+
members,
|
|
148
|
+
branches: [...new Set(group.members.flatMap((name) => linksOf.get(name)?.branches ?? []))],
|
|
149
|
+
diagnostics,
|
|
150
|
+
actionable: diagnostics.length === 0,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
for (const record of listing.worksets) {
|
|
155
|
+
if (grouped.has(record.id)) continue;
|
|
156
|
+
const members = record.changes.map(changeNameOf).map(pastMember);
|
|
157
|
+
const diagnostics = members
|
|
158
|
+
.filter((member) => member.kind === "missing")
|
|
159
|
+
.map((member) => `${member.name} is neither active nor archived`);
|
|
160
|
+
entries.push({
|
|
161
|
+
id: record.id,
|
|
162
|
+
implicit: false,
|
|
163
|
+
record,
|
|
164
|
+
members,
|
|
165
|
+
branches: [],
|
|
166
|
+
diagnostics,
|
|
167
|
+
actionable: diagnostics.length === 0,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
worksets: refuseSharedIds(entries).toSorted((a, b) => a.id.localeCompare(b.id)),
|
|
173
|
+
diagnostics: listing.problems.map((problem) => `${problem.path}: ${problem.reason}`),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function readWorkInventory(companionPath: string): Promise<WorkInventory> {
|
|
178
|
+
const [listing, links, anchors] = await Promise.all([
|
|
179
|
+
readWorksets(companionPath),
|
|
180
|
+
activeLinks(companionPath),
|
|
181
|
+
listArchiveAnchors(companionPath),
|
|
182
|
+
]);
|
|
183
|
+
const activeChanges = await Promise.all(
|
|
184
|
+
links.map(async ({ name }): Promise<ActiveChangeScope> => {
|
|
185
|
+
try {
|
|
186
|
+
return {
|
|
187
|
+
name,
|
|
188
|
+
repositories: await scopedRepositories(path.join(changesDirOf(companionPath), name)),
|
|
189
|
+
};
|
|
190
|
+
} catch {
|
|
191
|
+
return { name, repositories: null };
|
|
192
|
+
}
|
|
193
|
+
}),
|
|
194
|
+
);
|
|
195
|
+
return buildInventory({ listing, activeChanges, links, archiveAnchors: anchors });
|
|
196
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { Operator } from "./claims";
|
|
2
|
+
import type { InventoryWorkset } from "./inventory";
|
|
3
|
+
import type { DerivedWorksetStage, WorksetStageId } from "./stage";
|
|
4
|
+
|
|
5
|
+
export const WORK_BUCKETS = ["scratchpad", "local", "remote"] as const;
|
|
6
|
+
export type WorkBucket = (typeof WORK_BUCKETS)[number];
|
|
7
|
+
|
|
8
|
+
export type WorkActionId = "share" | "claim" | "release" | "start-manual";
|
|
9
|
+
type RefusalReason = string;
|
|
10
|
+
|
|
11
|
+
export type SharedPresence = "local" | "shared" | "partial" | "unknown";
|
|
12
|
+
|
|
13
|
+
export type SyncState = "in-sync" | "ahead" | "behind" | "diverged";
|
|
14
|
+
|
|
15
|
+
export interface SharingFacts {
|
|
16
|
+
presence: SharedPresence;
|
|
17
|
+
missingMembers: string[];
|
|
18
|
+
sync: SyncState;
|
|
19
|
+
stale: boolean;
|
|
20
|
+
remoteOnly: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const LOCAL_ONLY: SharingFacts = {
|
|
24
|
+
presence: "local",
|
|
25
|
+
missingMembers: [],
|
|
26
|
+
sync: "in-sync",
|
|
27
|
+
stale: false,
|
|
28
|
+
remoteOnly: false,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export interface WorkMemberStatus {
|
|
32
|
+
name: string;
|
|
33
|
+
stage: WorksetStageId;
|
|
34
|
+
stageLabel: string;
|
|
35
|
+
delivered: boolean;
|
|
36
|
+
problem?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Claim =
|
|
40
|
+
| { kind: "none" }
|
|
41
|
+
| { kind: "mine"; label: string }
|
|
42
|
+
| { kind: "other"; label: string }
|
|
43
|
+
| { kind: "conflict"; diagnostic: string };
|
|
44
|
+
|
|
45
|
+
export type Progress =
|
|
46
|
+
| { kind: "none" }
|
|
47
|
+
| { kind: "here"; branch: string }
|
|
48
|
+
| { kind: "elsewhere"; branch: string };
|
|
49
|
+
|
|
50
|
+
export interface WorkFacts {
|
|
51
|
+
inventory: InventoryWorkset;
|
|
52
|
+
stage: DerivedWorksetStage;
|
|
53
|
+
members: WorkMemberStatus[];
|
|
54
|
+
sharing: SharingFacts;
|
|
55
|
+
claim: Claim;
|
|
56
|
+
progress: Progress;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface WorkContext {
|
|
60
|
+
writable: boolean;
|
|
61
|
+
operator?: Operator;
|
|
62
|
+
gitBacked: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface WorkCard {
|
|
66
|
+
id: string;
|
|
67
|
+
bucket: WorkBucket;
|
|
68
|
+
claim: Claim;
|
|
69
|
+
progress: Progress;
|
|
70
|
+
stage: WorksetStageId;
|
|
71
|
+
stageLabel: string;
|
|
72
|
+
sharing: SharingFacts;
|
|
73
|
+
members: WorkMemberStatus[];
|
|
74
|
+
done: boolean;
|
|
75
|
+
actions: Partial<Record<WorkActionId, RefusalReason | null>>;
|
|
76
|
+
diagnostics: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const COMPLETED: ReadonlySet<WorksetStageId> = new Set(["merge-wait", "publish", "done"]);
|
|
80
|
+
const SUBMITTED = "submitted for publication; nothing is left to do here";
|
|
81
|
+
|
|
82
|
+
export function isShared(presence: SharedPresence): boolean {
|
|
83
|
+
return presence === "shared" || presence === "partial";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function activeCount(facts: WorkFacts): number {
|
|
87
|
+
return facts.inventory.members.filter((member) => member.kind === "active").length;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface WorkRefusal {
|
|
91
|
+
kind: "access" | "conflict";
|
|
92
|
+
reason: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const access = (reason: string): WorkRefusal => ({ kind: "access", reason });
|
|
96
|
+
|
|
97
|
+
function conflict(reason: string | null): WorkRefusal | null {
|
|
98
|
+
return reason === null ? null : { kind: "conflict", reason };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type OwnershipFacts = Pick<WorkFacts, "sharing" | "claim" | "progress">;
|
|
102
|
+
|
|
103
|
+
function isOwnWork(facts: OwnershipFacts): boolean {
|
|
104
|
+
return (
|
|
105
|
+
!isShared(facts.sharing.presence) ||
|
|
106
|
+
facts.claim.kind === "mine" ||
|
|
107
|
+
facts.progress.kind === "here"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function bucketOf(facts: WorkFacts): WorkBucket {
|
|
112
|
+
if (facts.inventory.members.length === 0 && !isShared(facts.sharing.presence)) {
|
|
113
|
+
return "scratchpad";
|
|
114
|
+
}
|
|
115
|
+
return isOwnWork(facts) ? "local" : "remote";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function first(...refusals: (WorkRefusal | null)[]): WorkRefusal | null {
|
|
119
|
+
return refusals.find((refusal) => refusal !== null) ?? null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function notOwn(facts: OwnershipFacts): WorkRefusal | null {
|
|
123
|
+
if (facts.claim.kind === "other") return access(`claimed by ${facts.claim.label}`);
|
|
124
|
+
if (isOwnWork(facts)) return null;
|
|
125
|
+
if (facts.progress.kind === "elsewhere") {
|
|
126
|
+
return conflict(`in progress on ${facts.progress.branch}`);
|
|
127
|
+
}
|
|
128
|
+
return conflict("claim it first");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function unsynced(sharing: SharingFacts): string | null {
|
|
132
|
+
if (sharing.remoteOnly) {
|
|
133
|
+
return "take its changes into this checkout first with `mate artifact take`";
|
|
134
|
+
}
|
|
135
|
+
if (sharing.sync === "behind" || sharing.sync === "diverged") {
|
|
136
|
+
return "the shared version has changes this checkout lacks; take it with `mate artifact take` first";
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const NO_OPERATOR = "configure Git user.name and user.email in the companion first";
|
|
142
|
+
|
|
143
|
+
export function workActionRefusalOf(
|
|
144
|
+
action: WorkActionId,
|
|
145
|
+
facts: WorkFacts,
|
|
146
|
+
context: WorkContext,
|
|
147
|
+
): WorkRefusal | null {
|
|
148
|
+
if (!context.writable) return access("Studio is read-only; start it with --writable");
|
|
149
|
+
if (!facts.inventory.actionable) {
|
|
150
|
+
return conflict(facts.inventory.diagnostics[0] ?? "this Workset cannot be acted on");
|
|
151
|
+
}
|
|
152
|
+
if (facts.claim.kind === "conflict") return conflict(facts.claim.diagnostic);
|
|
153
|
+
const { sharing } = facts;
|
|
154
|
+
const hasChanges = activeCount(facts) > 0;
|
|
155
|
+
const stage = facts.stage.stage;
|
|
156
|
+
const missingIdentity = conflict(context.operator ? null : NO_OPERATOR);
|
|
157
|
+
|
|
158
|
+
switch (action) {
|
|
159
|
+
case "share":
|
|
160
|
+
if (!context.gitBacked) return conflict("the companion is not a Git repository");
|
|
161
|
+
if (!hasChanges) return conflict("Scratchpad ideas are not shared; propose the change first");
|
|
162
|
+
if (COMPLETED.has(stage)) return conflict(SUBMITTED);
|
|
163
|
+
if (sharing.presence === "shared" && sharing.sync === "in-sync") {
|
|
164
|
+
return conflict("already shared with no local changes");
|
|
165
|
+
}
|
|
166
|
+
return first(conflict(unsynced(sharing)), notOwn(facts));
|
|
167
|
+
case "claim":
|
|
168
|
+
if (!isShared(sharing.presence)) return conflict("only shared work is claimed");
|
|
169
|
+
if (COMPLETED.has(stage)) return conflict(SUBMITTED);
|
|
170
|
+
if (sharing.presence === "partial") {
|
|
171
|
+
return conflict(`not all of its changes are shared (${sharing.missingMembers.join(", ")})`);
|
|
172
|
+
}
|
|
173
|
+
if (facts.claim.kind === "mine") return conflict("already yours");
|
|
174
|
+
if (facts.claim.kind === "other") return access(`claimed by ${facts.claim.label}`);
|
|
175
|
+
if (facts.progress.kind !== "none")
|
|
176
|
+
return conflict(`in progress on ${facts.progress.branch}`);
|
|
177
|
+
return missingIdentity;
|
|
178
|
+
case "release":
|
|
179
|
+
if (facts.claim.kind !== "mine") return access("only its owner can release it");
|
|
180
|
+
return missingIdentity;
|
|
181
|
+
case "start-manual":
|
|
182
|
+
if (!hasChanges) return conflict("propose the change first");
|
|
183
|
+
if (stage === "done") return conflict("already delivered");
|
|
184
|
+
if (COMPLETED.has(stage)) return conflict(SUBMITTED);
|
|
185
|
+
return first(notOwn(facts), conflict(unsynced(sharing)));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function workActionRefusal(
|
|
190
|
+
action: WorkActionId,
|
|
191
|
+
facts: WorkFacts,
|
|
192
|
+
context: WorkContext,
|
|
193
|
+
): string | null {
|
|
194
|
+
return workActionRefusalOf(action, facts, context)?.reason ?? null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function relevantActions(bucket: WorkBucket, facts: WorkFacts): WorkActionId[] {
|
|
198
|
+
const actions: WorkActionId[] = [];
|
|
199
|
+
if (bucket === "remote") actions.push("claim");
|
|
200
|
+
if (bucket === "local") actions.push("share", "start-manual");
|
|
201
|
+
if (facts.claim.kind === "mine") actions.push("release");
|
|
202
|
+
return actions;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function projectWorkCard(facts: WorkFacts, context: WorkContext): WorkCard {
|
|
206
|
+
const bucket = bucketOf(facts);
|
|
207
|
+
const actions: Partial<Record<WorkActionId, string | null>> = {};
|
|
208
|
+
for (const action of relevantActions(bucket, facts)) {
|
|
209
|
+
actions[action] = workActionRefusal(action, facts, context);
|
|
210
|
+
}
|
|
211
|
+
const diagnostics = [
|
|
212
|
+
...facts.inventory.diagnostics,
|
|
213
|
+
...(facts.claim.kind === "conflict" ? [facts.claim.diagnostic] : []),
|
|
214
|
+
...facts.members.flatMap((member) =>
|
|
215
|
+
member.problem ? [`${member.name}: ${member.problem}`] : [],
|
|
216
|
+
),
|
|
217
|
+
...(facts.sharing.presence === "partial"
|
|
218
|
+
? [`not shared yet: ${facts.sharing.missingMembers.join(", ")}`]
|
|
219
|
+
: []),
|
|
220
|
+
];
|
|
221
|
+
return {
|
|
222
|
+
id: facts.inventory.id,
|
|
223
|
+
bucket,
|
|
224
|
+
claim: facts.claim,
|
|
225
|
+
progress: facts.progress,
|
|
226
|
+
stage: facts.stage.stage,
|
|
227
|
+
stageLabel: facts.stage.label,
|
|
228
|
+
sharing: facts.sharing,
|
|
229
|
+
members: facts.members,
|
|
230
|
+
done:
|
|
231
|
+
facts.members.length > 0
|
|
232
|
+
? facts.members.every((member) => member.delivered)
|
|
233
|
+
: facts.stage.stage === "done",
|
|
234
|
+
actions,
|
|
235
|
+
diagnostics,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -7,15 +7,12 @@ import { parse, stringify } from "yaml";
|
|
|
7
7
|
import { errorMessage } from "../../runtime/error-message";
|
|
8
8
|
import { changeNameOf, locateChange, parseAnchor } from "../change-layout";
|
|
9
9
|
import { isJiraKey, normalizeJiraKey } from "../delivery/record";
|
|
10
|
+
import { fileExists } from "../fs-utils";
|
|
10
11
|
import { scopedRepositories } from "../openspec-scopes";
|
|
12
|
+
import { activeLinks, deriveGroups } from "./groups";
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* the changes shipped together, names their Working Repositories, and holds the
|
|
15
|
-
* stage only before any change exists; afterwards the stage is derived.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export const WORKSETS_RELATIVE_DIR = "worksets";
|
|
14
|
+
export const WORKSETS_RELATIVE_DIR = ".mate/scratchpad";
|
|
15
|
+
export const LEGACY_WORKSETS_RELATIVE_DIR = "worksets";
|
|
19
16
|
|
|
20
17
|
/** The stages a person moves a Workset through before propose links its first change. */
|
|
21
18
|
export const PRE_PROPOSE_STAGES = ["clarify-intent", "explore", "ready"] as const;
|
|
@@ -34,6 +31,7 @@ export interface WorksetRecord {
|
|
|
34
31
|
createdAt: string;
|
|
35
32
|
/** When the Workset was started; absent while Later, which never runs by itself. */
|
|
36
33
|
queuedAt?: string;
|
|
34
|
+
legacy?: boolean;
|
|
37
35
|
/** Fields this version does not know, kept so a write preserves them. */
|
|
38
36
|
extra: Record<string, unknown>;
|
|
39
37
|
}
|
|
@@ -79,9 +77,15 @@ export function isRepositoryIdentity(repository: string): boolean {
|
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
export function worksetsDirOf(companionPath: string): string {
|
|
82
|
-
return path.join(companionPath, WORKSETS_RELATIVE_DIR);
|
|
80
|
+
return path.join(companionPath, ...WORKSETS_RELATIVE_DIR.split("/"));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function legacyDirOf(companionPath: string): string {
|
|
84
|
+
return path.join(companionPath, LEGACY_WORKSETS_RELATIVE_DIR);
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
const SELF_IGNORE = "*\n";
|
|
88
|
+
|
|
85
89
|
function stringList(value: unknown): string[] | null {
|
|
86
90
|
if (value === undefined || value === null) return [];
|
|
87
91
|
return Array.isArray(value) && value.every((entry) => typeof entry === "string") ? value : null;
|
|
@@ -147,30 +151,48 @@ async function readWorksetFile(dir: string, id: string): Promise<WorksetRecord |
|
|
|
147
151
|
}
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
async function readDir(
|
|
155
|
+
dir: string,
|
|
156
|
+
relativeDir: string,
|
|
157
|
+
legacy: boolean,
|
|
158
|
+
): Promise<(WorksetRecord | WorksetProblem)[]> {
|
|
153
159
|
let entries: string[];
|
|
154
160
|
try {
|
|
155
161
|
entries = await fs.readdir(dir);
|
|
156
162
|
} catch (error) {
|
|
157
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return
|
|
163
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
|
|
158
164
|
throw error;
|
|
159
165
|
}
|
|
160
|
-
|
|
166
|
+
return Promise.all(
|
|
161
167
|
entries
|
|
162
168
|
.filter((name) => name.endsWith(".yaml"))
|
|
163
169
|
.toSorted()
|
|
164
170
|
.map(async (entry): Promise<WorksetRecord | WorksetProblem> => {
|
|
165
171
|
const record = await readWorksetFile(dir, entry.slice(0, -".yaml".length));
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
172
|
+
if (typeof record === "string") {
|
|
173
|
+
return { path: path.posix.join(relativeDir, entry), reason: record };
|
|
174
|
+
}
|
|
175
|
+
return legacy ? { ...record, legacy: true } : record;
|
|
169
176
|
}),
|
|
170
177
|
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isRecord(entry: WorksetRecord | WorksetProblem): entry is WorksetRecord {
|
|
181
|
+
return "id" in entry;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function readWorksets(companionPath: string): Promise<WorksetListing> {
|
|
185
|
+
const [current, legacy] = await Promise.all([
|
|
186
|
+
readDir(worksetsDirOf(companionPath), WORKSETS_RELATIVE_DIR, false),
|
|
187
|
+
readDir(legacyDirOf(companionPath), LEGACY_WORKSETS_RELATIVE_DIR, true),
|
|
188
|
+
]);
|
|
189
|
+
const ids = new Set(
|
|
190
|
+
current.map((entry) => (isRecord(entry) ? entry.id : path.posix.basename(entry.path, ".yaml"))),
|
|
191
|
+
);
|
|
192
|
+
const moved = legacy.filter(isRecord).filter((record) => !ids.has(record.id));
|
|
171
193
|
return {
|
|
172
|
-
worksets:
|
|
173
|
-
problems:
|
|
194
|
+
worksets: [...current.filter(isRecord), ...moved].toSorted((a, b) => a.id.localeCompare(b.id)),
|
|
195
|
+
problems: [...current, ...legacy].filter((entry): entry is WorksetProblem => !isRecord(entry)),
|
|
174
196
|
};
|
|
175
197
|
}
|
|
176
198
|
|
|
@@ -182,7 +204,11 @@ export async function findWorkset(
|
|
|
182
204
|
// Reads only this record's file; an id that is no file name has none.
|
|
183
205
|
if (!isWorksetId(id)) return undefined;
|
|
184
206
|
const record = await readWorksetFile(worksetsDirOf(companionPath), id);
|
|
185
|
-
|
|
207
|
+
if (typeof record !== "string") return record;
|
|
208
|
+
const scratchpadFile = path.join(worksetsDirOf(companionPath), `${id}.yaml`);
|
|
209
|
+
if (await fileExists(scratchpadFile)) return undefined;
|
|
210
|
+
const legacy = await readWorksetFile(legacyDirOf(companionPath), id);
|
|
211
|
+
return typeof legacy === "string" ? undefined : { ...legacy, legacy: true };
|
|
186
212
|
}
|
|
187
213
|
|
|
188
214
|
export type WorksetResolution =
|
|
@@ -238,6 +264,23 @@ async function resolveWorksetIdentity(
|
|
|
238
264
|
return { id, implicit, diagnostics };
|
|
239
265
|
}
|
|
240
266
|
|
|
267
|
+
async function derivedWorksetOf(
|
|
268
|
+
companionPath: string,
|
|
269
|
+
change: string,
|
|
270
|
+
worksets: readonly WorksetRecord[],
|
|
271
|
+
): Promise<{ id: string; implicit: boolean }> {
|
|
272
|
+
const links = await activeLinks(companionPath).catch(() => []);
|
|
273
|
+
if (!links.some((candidate) => candidate.name === change)) return { id: change, implicit: true };
|
|
274
|
+
const records = new Map(
|
|
275
|
+
worksets.map((record) => [record.id, record.changes.map(changeNameOf)] as const),
|
|
276
|
+
);
|
|
277
|
+
const group = deriveGroups(links, records).find((candidate) =>
|
|
278
|
+
candidate.members.includes(change),
|
|
279
|
+
);
|
|
280
|
+
if (!group) return { id: change, implicit: true };
|
|
281
|
+
return { id: group.id, implicit: group.record !== group.id };
|
|
282
|
+
}
|
|
283
|
+
|
|
241
284
|
/** Resolves membership and branch ownership; malformed records never imply standalone work. */
|
|
242
285
|
export async function resolveWorksetOf(
|
|
243
286
|
companionPath: string,
|
|
@@ -255,13 +298,10 @@ export async function resolveWorksetOf(
|
|
|
255
298
|
],
|
|
256
299
|
};
|
|
257
300
|
}
|
|
258
|
-
|
|
259
|
-
companionPath,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
repository,
|
|
263
|
-
listing,
|
|
264
|
-
);
|
|
301
|
+
if (members[0])
|
|
302
|
+
return resolveWorksetIdentity(companionPath, members[0].id, false, repository, listing);
|
|
303
|
+
const derived = await derivedWorksetOf(companionPath, changeNameOf(change), listing.worksets);
|
|
304
|
+
return resolveWorksetIdentity(companionPath, derived.id, derived.implicit, repository, listing);
|
|
265
305
|
}
|
|
266
306
|
|
|
267
307
|
function documentOf(record: WorksetRecord): Record<string, unknown> {
|
|
@@ -281,6 +321,9 @@ function documentOf(record: WorksetRecord): Record<string, unknown> {
|
|
|
281
321
|
|
|
282
322
|
async function writeTemp(dir: string, record: WorksetRecord): Promise<string> {
|
|
283
323
|
await fs.mkdir(dir, { recursive: true });
|
|
324
|
+
await fs.writeFile(path.join(dir, ".gitignore"), SELF_IGNORE, { flag: "wx" }).catch((error) => {
|
|
325
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
326
|
+
});
|
|
284
327
|
const temp = path.join(dir, `.${record.id}.${randomBytes(4).toString("hex")}.tmp`);
|
|
285
328
|
await fs.writeFile(temp, stringify(documentOf(record)), "utf8");
|
|
286
329
|
return temp;
|
|
@@ -324,6 +367,9 @@ export async function createWorkset(
|
|
|
324
367
|
...(input.start ? { queuedAt: createdAt } : {}),
|
|
325
368
|
extra: {},
|
|
326
369
|
};
|
|
370
|
+
if (await findWorkset(companionPath, record.id)) {
|
|
371
|
+
throw new WorksetError(`a Workset ${record.id} already exists`);
|
|
372
|
+
}
|
|
327
373
|
const dir = worksetsDirOf(companionPath);
|
|
328
374
|
const temp = await writeTemp(dir, record);
|
|
329
375
|
try {
|
|
@@ -390,6 +436,11 @@ export interface NewOutcome {
|
|
|
390
436
|
ticket?: string;
|
|
391
437
|
}
|
|
392
438
|
|
|
439
|
+
async function derivedIds(companionPath: string): Promise<string[]> {
|
|
440
|
+
const links = await activeLinks(companionPath).catch(() => []);
|
|
441
|
+
return [...links.map((change) => change.name), ...deriveGroups(links).map((group) => group.id)];
|
|
442
|
+
}
|
|
443
|
+
|
|
393
444
|
/** Creates a Workset from an outcome text; identifier and title are derived, the repository defaults to the only linked one. */
|
|
394
445
|
export async function createOutcome(
|
|
395
446
|
companionPath: string,
|
|
@@ -414,10 +465,14 @@ export async function createOutcome(
|
|
|
414
465
|
if (ticket !== undefined && !isJiraKey(ticket)) {
|
|
415
466
|
throw new WorksetError(`ticket ${JSON.stringify(ticket)} is not a Jira key such as ABC-123`);
|
|
416
467
|
}
|
|
417
|
-
const { worksets, problems } = await
|
|
468
|
+
const [{ worksets, problems }, derived] = await Promise.all([
|
|
469
|
+
readWorksets(companionPath),
|
|
470
|
+
derivedIds(companionPath),
|
|
471
|
+
]);
|
|
418
472
|
const taken = new Set([
|
|
419
473
|
...worksets.map((workset) => workset.id),
|
|
420
474
|
...problems.map((problem) => path.basename(problem.path, ".yaml")),
|
|
475
|
+
...derived,
|
|
421
476
|
]);
|
|
422
477
|
const title = outcomeTitle(input.text);
|
|
423
478
|
const id = worksetIdFor(title, taken);
|
|
@@ -436,11 +491,19 @@ export async function createOutcome(
|
|
|
436
491
|
);
|
|
437
492
|
}
|
|
438
493
|
|
|
439
|
-
|
|
440
|
-
|
|
494
|
+
export async function writeWorkset(
|
|
495
|
+
companionPath: string,
|
|
496
|
+
record: WorksetRecord,
|
|
497
|
+
options: { started?: boolean } = {},
|
|
498
|
+
): Promise<void> {
|
|
441
499
|
const dir = worksetsDirOf(companionPath);
|
|
442
|
-
const
|
|
500
|
+
const { legacy, ...local } = record;
|
|
501
|
+
const { queuedAt: _queuedAt, ...unstarted } = local;
|
|
502
|
+
const temp = await writeTemp(dir, legacy && !options.started ? unstarted : local);
|
|
443
503
|
await fs.rename(temp, path.join(dir, `${record.id}.yaml`));
|
|
504
|
+
if (legacy) {
|
|
505
|
+
await fs.rm(path.join(legacyDirOf(companionPath), `${record.id}.yaml`), { force: true });
|
|
506
|
+
}
|
|
444
507
|
}
|
|
445
508
|
|
|
446
509
|
/** Deletes a Workset's record; a record already gone is no error. */
|
|
@@ -448,7 +511,11 @@ export async function removeWorkset(companionPath: string, id: string): Promise<
|
|
|
448
511
|
if (!isWorksetId(id)) {
|
|
449
512
|
throw new WorksetError(`Workset identifier ${JSON.stringify(id)} is not a kebab-case name`);
|
|
450
513
|
}
|
|
451
|
-
await
|
|
514
|
+
await Promise.all(
|
|
515
|
+
[worksetsDirOf(companionPath), legacyDirOf(companionPath)].map((dir) =>
|
|
516
|
+
fs.rm(path.join(dir, `${id}.yaml`), { force: true }),
|
|
517
|
+
),
|
|
518
|
+
);
|
|
452
519
|
}
|
|
453
520
|
|
|
454
521
|
const NEXT_STAGE: Partial<Record<PreProposeStage, PreProposeStage>> = {
|
|
@@ -477,9 +544,7 @@ async function recordFor(companionPath: string, id: string): Promise<WorksetReco
|
|
|
477
544
|
const { worksets, problems } = await readWorksets(companionPath);
|
|
478
545
|
const record = worksets.find((workset) => workset.id === id);
|
|
479
546
|
if (record) return record;
|
|
480
|
-
const problem = problems.find(
|
|
481
|
-
(entry) => entry.path === path.join(WORKSETS_RELATIVE_DIR, `${id}.yaml`),
|
|
482
|
-
);
|
|
547
|
+
const problem = problems.find((entry) => path.posix.basename(entry.path) === `${id}.yaml`);
|
|
483
548
|
throw new WorksetError(problem ? `${problem.path} ${problem.reason}` : `no Workset ${id}`);
|
|
484
549
|
}
|
|
485
550
|
|
|
@@ -494,13 +559,13 @@ export async function setWorksetStarted(
|
|
|
494
559
|
now: () => Date = () => new Date(),
|
|
495
560
|
): Promise<WorksetRecord> {
|
|
496
561
|
const record = await recordFor(companionPath, id);
|
|
497
|
-
const { queuedAt: _queuedAt, ...rest } = record;
|
|
562
|
+
const { queuedAt: _queuedAt, legacy, ...rest } = record;
|
|
498
563
|
// Fields of earlier factory versions; dropped so they cannot mislead a reader.
|
|
499
564
|
const { lane: _lane, priority: _priority, ...extra } = record.extra;
|
|
500
565
|
const next: WorksetRecord = started
|
|
501
566
|
? { ...rest, extra, queuedAt: record.queuedAt ?? now().toISOString() }
|
|
502
567
|
: { ...rest, extra };
|
|
503
|
-
await writeWorkset(companionPath, next);
|
|
568
|
+
await writeWorkset(companionPath, legacy ? { ...next, legacy } : next, { started });
|
|
504
569
|
return next;
|
|
505
570
|
}
|
|
506
571
|
|