@uniqbit/mate-core 0.20.0 → 0.21.1
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/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
- package/claude-plugin/hooks/hooks.json +10 -1
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- package/opencode-plugin/src/server.ts +9 -2
- package/package.json +2 -1
- package/src/cli/commands/artifact/delivery/environment.ts +28 -8
- package/src/cli/commands/artifact/delivery/link.ts +28 -9
- package/src/cli/commands/artifact/delivery/output.ts +7 -0
- package/src/cli/commands/companion/update.ts +2 -19
- package/src/cli/commands/factory/factory.ts +11 -1
- package/src/cli/commands/install.ts +47 -36
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +33 -6
- package/src/cli/commands/plugin/install.ts +27 -11
- package/src/cli/commands/report/index.ts +180 -184
- package/src/cli/commands/report/markdown.ts +67 -72
- package/src/cli/commands/shared/companion-selection.ts +3 -1
- package/src/cli/commands/studio/access.ts +6 -14
- package/src/cli/commands/studio/areas.ts +112 -33
- package/src/cli/commands/studio/companion-add.ts +87 -0
- package/src/cli/commands/studio/companion-removal.ts +15 -8
- package/src/cli/commands/studio/factory-credential.ts +1 -15
- package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
- package/src/cli/commands/studio/factory-relay.ts +18 -0
- package/src/cli/commands/studio/graph-model.ts +61 -0
- package/src/cli/commands/studio/graph.ts +336 -0
- package/src/cli/commands/studio/index.ts +4 -4
- package/src/cli/commands/studio/payload.ts +42 -15
- package/src/cli/commands/studio/repository-add.ts +116 -0
- package/src/cli/commands/studio/routes.ts +6 -0
- package/src/cli/commands/studio/selection.ts +12 -3
- package/src/cli/commands/studio/server.ts +127 -5
- package/src/cli/commands/studio/services.ts +40 -0
- package/src/cli/commands/studio/terminal.ts +45 -3
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +84 -3
- package/src/cli/commands/studio/workset-session.ts +47 -14
- package/src/cli/commands/unwrap.ts +3 -0
- package/src/cli/commands/update.ts +2 -0
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +71 -13
- package/src/cli/commands/vscode/vsix.ts +48 -7
- package/src/cli/commands/working/cleanup.ts +40 -8
- package/src/cli/commands/working/worktree.ts +176 -35
- package/src/cli/main.ts +17 -2
- package/src/cli/usage.ts +1 -1
- package/src/hooks/rtk-worktree-git.ts +48 -0
- package/src/hooks/validate-artifact-path.ts +38 -7
- package/src/lib/delivery/branch-template.ts +122 -0
- package/src/lib/delivery/branches.ts +21 -16
- package/src/lib/delivery/checkout.ts +102 -0
- package/src/lib/delivery/environment.ts +2 -0
- package/src/lib/delivery/merge-git.ts +13 -1
- package/src/lib/delivery/record-delivery.ts +83 -29
- package/src/lib/delivery/record.ts +15 -3
- package/src/lib/delivery/resolve-branch.ts +157 -110
- package/src/lib/factory/attach-client.ts +11 -1
- package/src/lib/factory/broker.ts +37 -40
- package/src/lib/factory/client.ts +22 -1
- package/src/lib/factory/clone-url.ts +39 -0
- package/src/lib/factory/command.ts +21 -5
- package/src/lib/factory/git-auth.ts +61 -0
- package/src/lib/factory/git-credential-store.ts +181 -0
- package/src/lib/factory/ids.ts +12 -2
- package/src/lib/factory/outcomes/actions.ts +20 -4
- package/src/lib/factory/outcomes/index.ts +77 -11
- package/src/lib/factory/outcomes/lifecycle.ts +9 -2
- package/src/lib/factory/outcomes/sessions.ts +23 -1
- package/src/lib/factory/prepare.ts +9 -3
- package/src/lib/factory/runner/scheduler.ts +96 -14
- package/src/lib/factory/runner/workflow.ts +5 -1
- package/src/lib/factory/runtime.ts +143 -43
- package/src/lib/orchestrator/companion-hub.ts +6 -1
- package/src/lib/orchestrator/engine-floor.ts +48 -0
- package/src/lib/orchestrator/launcher.ts +34 -1
- package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
- package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +32 -8
- package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
- package/src/lib/orchestrator/projection-entries.ts +22 -18
- package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
- package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
- package/src/lib/orchestrator/projection-types.ts +28 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +3 -1
- package/src/lib/orchestrator/session-prepare.ts +6 -1
- package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
- package/src/lib/orchestrator/types.ts +4 -0
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +24 -4
- package/src/lib/orchestrator/wrap-pass.ts +1 -0
- package/src/lib/public-npm.ts +95 -50
- package/src/lib/session-state.ts +72 -2
- package/src/lib/update-checker.ts +7 -1
- package/src/lib/usage/aggregate.ts +202 -0
- package/src/lib/usage/cache.ts +87 -0
- package/src/lib/usage/claude-pricing.ts +71 -0
- package/src/lib/usage/claude.ts +189 -0
- package/src/lib/usage/collect.ts +56 -0
- package/src/lib/usage/opencode.ts +188 -0
- package/src/lib/usage/records.ts +80 -0
- package/src/lib/usage/rtk-database.ts +72 -0
- package/src/lib/usage/savings.ts +209 -0
- package/src/lib/usage/scope.ts +182 -0
- package/src/lib/usage/source.ts +102 -0
- package/src/lib/usage/types.ts +143 -0
- package/src/lib/usage/window.ts +37 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +25 -11
- package/src/lib/workset/repositories.ts +118 -25
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +6 -2
- package/src/lib/workset/worktree.ts +591 -101
- package/src/opencode/companion-hooks.ts +46 -8
- package/src/opencode/companion-policy.ts +18 -5
- package/src/opencode/enter-worktree.ts +254 -6
- package/src/opencode/session-register.ts +2 -2
- package/src/runtime/claude-bg-isolation.ts +138 -0
- package/src/runtime/companion-git.ts +10 -2
- package/src/runtime/companion-guidance.ts +17 -4
- package/src/runtime/current-branch.ts +16 -2
- package/src/runtime/entered-worktree.ts +24 -0
- package/src/runtime/git-tracked.ts +60 -0
- package/src/runtime/repo-destination.ts +72 -0
- package/src/runtime/repo-local.ts +25 -3
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-document-manifest.ts +229 -19
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +9 -2
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/serving-claude-wrap.ts +15 -2
- package/src/runtime/umbrella-folder.ts +56 -0
- package/src/runtime/wrap-state.ts +5 -13
- package/src/studio.ts +37 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +61 -6
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +8 -4
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +9 -5
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +5 -4
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +10 -4
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +5 -1
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +61 -6
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +8 -4
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +9 -5
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +5 -4
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +10 -4
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +5 -1
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +307 -42
- package/src/tools/setup/capabilities/rtk.ts +93 -1
- package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
- package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
- package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
- package/src/tools/setup/dynamic-plugins/install.ts +24 -22
- package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
- package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
- package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
- package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
- package/src/tools/setup/mate.ts +3 -3
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
- package/src/tools/setup/providers/claude.ts +25 -3
- package/src/tools/setup/utils.ts +4 -2
- package/src/tools/setup/working-repo-cleanup.ts +2 -2
- package/src/tools/setup/working-repo-local-state.ts +2 -0
- package/src/tools/setup.ts +25 -14
- package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
- package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
- package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
- package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
- package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
- package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
- package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
- package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
- package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
- package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
- package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
- package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
- package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
- package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
- package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
- package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
- package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
- package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
- package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
- package/studio-dist/client/assets/select-CnaMd617.js +1 -0
- package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
- package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
- package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
- package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
- package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
- package/studio-dist/client/assets/store-Dw34catY.js +1 -0
- package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
- package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
- package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
- package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
- package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
- package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +102 -35
- package/studio-dist/server/assets/{actions-Bvgj9eb8.js → actions-DYSv-9VV.js} +10 -4
- package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
- package/studio-dist/server/assets/{button-CIJqAhni.js → button-CgOIVdmD.js} +13 -1702
- package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
- package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-BKVXD3TO.js} +3 -3
- package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
- package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
- package/studio-dist/server/assets/{factory-DUTa0eDs.js → factory-C7Ybg0xG.js} +1256 -353
- package/studio-dist/server/assets/{factory-DGPmNGbo.js → factory-Df5uAHjb.js} +53 -6
- package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
- package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
- package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
- package/studio-dist/server/assets/graph-CSje3029.js +801 -0
- package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
- package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
- package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
- package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-BR8dJ7aR.js} +28 -9
- package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-BR_t9iMM.js} +4 -4
- package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
- package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
- package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CQ9qQ1-n.js} +9 -10
- package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-dYDEoBeq.js} +3 -3
- package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DkRHNTpE.js} +787 -2862
- package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-B6GfOew4.js} +22 -171
- package/studio-dist/server/assets/{search-JAKurDNh.js → search-BJnWLfkG.js} +21 -2
- package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
- package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-Hq-hXgnT.js} +6 -5
- package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-B7nEuVbx.js} +9 -8
- package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-B_YYL7q8.js} +3 -3
- package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
- package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
- package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
- package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D56DApvK.js} +1 -1
- package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
- package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
- package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
- package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
- package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
- package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
- package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-BDuIUq0F.js} +8 -5
- package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-BVLp6zu3.js} +3 -3
- package/studio-dist/server/assets/{views-BgYa-za2.js → views-flRUr21z.js} +4 -4
- package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-CDy9pdgL.js} +3 -2
- package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-D9GKI2EV.js} +132 -106
- package/studio-dist/server/server.js +582 -8
- package/src/cli/commands/report/collector.ts +0 -288
- package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
- package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
- package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
- package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
- package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
- package/studio-dist/client/assets/prepaint-CwSrpdFA.js +0 -27
- package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
- package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
- package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
- package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
- package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
- package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +0 -45
- package/studio-dist/server/assets/react-Ce6dj15C.js +0 -46
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
- package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
- package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
- package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
|
@@ -1,50 +1,41 @@
|
|
|
1
1
|
import { locateChange } from "../change-layout";
|
|
2
|
-
import
|
|
2
|
+
import { companionBranchTemplate } from "./branches";
|
|
3
|
+
import type { DeliveryCheckout, HasRef, ListRefs } from "./checkout";
|
|
3
4
|
import { declaredDependencies } from "./overlap";
|
|
4
|
-
import { localMergeEvidence } from "./refresh";
|
|
5
5
|
import {
|
|
6
6
|
findWorkset,
|
|
7
7
|
resolveWorksetBranch,
|
|
8
8
|
resolveWorksetOf,
|
|
9
9
|
type WorksetRecord,
|
|
10
10
|
} from "../workset/record";
|
|
11
|
+
import {
|
|
12
|
+
branchTemplatePrefix,
|
|
13
|
+
DEFAULT_BRANCH_TEMPLATE,
|
|
14
|
+
matchBranchTemplate,
|
|
15
|
+
type BranchTemplate,
|
|
16
|
+
} from "./branch-template";
|
|
11
17
|
import {
|
|
12
18
|
defaultDeliveryBranch,
|
|
13
19
|
findDelivery,
|
|
14
|
-
isJiraKey,
|
|
15
20
|
readDeliveryRecord,
|
|
16
21
|
type DeliveryRecord,
|
|
17
22
|
} from "./record";
|
|
18
23
|
|
|
19
|
-
/** True when the ref resolves in the repository's checkout. */
|
|
20
|
-
export type HasRef = (ref: string) => Promise<boolean>;
|
|
21
|
-
|
|
22
|
-
/** Full names of the refs under the given prefixes, e.g. `refs/heads/workset/`. */
|
|
23
|
-
export type ListRefs = (prefixes: string[]) => Promise<string[]>;
|
|
24
|
-
|
|
25
24
|
/** Where the resolved branch lives: a local branch, only `origin/<branch>`, or nowhere yet. */
|
|
26
25
|
export type BranchSource = "local" | "remote" | "new";
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
/** What a Delivery Branch is resolved for: a change, or a Workset by id. */
|
|
28
|
+
export type DeliverySubject = {
|
|
29
29
|
companionPath: string;
|
|
30
30
|
/** Null when no repository is known; recorded branches are then not consulted. */
|
|
31
31
|
repository: string | null;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* Finds an existing `workset/<TICKET>-<id>` when no ticket is given; without it only
|
|
36
|
-
* `workset/<id>` is probed.
|
|
37
|
-
*/
|
|
38
|
-
listRefs?: ListRefs | null;
|
|
39
|
-
/**
|
|
40
|
-
* Checks a dependency never checked for a merge before its branch is inherited; without it
|
|
41
|
-
* such a branch is inherited with a diagnostic asking for a refresh.
|
|
42
|
-
*/
|
|
43
|
-
mergeProbe?: MergeProbe | null;
|
|
32
|
+
} & ({ change: string } | { worksetId: string });
|
|
33
|
+
|
|
34
|
+
export interface DeliveryBranchOptions {
|
|
44
35
|
/**
|
|
45
|
-
* Names the branch
|
|
46
|
-
* renames a recorded or inherited one. Defaults to the explicit Workset record's
|
|
47
|
-
* which yields to any existing
|
|
36
|
+
* Names the branch with the template and this ticket, even over an existing branch without
|
|
37
|
+
* one; never renames a recorded or inherited one. Defaults to the explicit Workset record's
|
|
38
|
+
* ticket, which yields to any existing branch the template names for the Workset.
|
|
48
39
|
*/
|
|
49
40
|
ticket?: string | null;
|
|
50
41
|
}
|
|
@@ -57,6 +48,8 @@ export interface DeliveryBranchResolution {
|
|
|
57
48
|
/** The `dependsOn` changes whose branch `branch` is; empty when it is not inherited. */
|
|
58
49
|
inheritedFrom: string[];
|
|
59
50
|
diagnostics: string[];
|
|
51
|
+
/** Set when the companion's branch template is invalid and the default applies. */
|
|
52
|
+
templateDiagnostic?: string;
|
|
60
53
|
}
|
|
61
54
|
|
|
62
55
|
interface Member {
|
|
@@ -92,47 +85,60 @@ async function sourceOf(branch: string, hasRef: HasRef): Promise<BranchSource> {
|
|
|
92
85
|
return "new";
|
|
93
86
|
}
|
|
94
87
|
|
|
95
|
-
const
|
|
88
|
+
const BRANCH_REF = /^refs\/(?:heads|remotes\/origin)\//;
|
|
96
89
|
|
|
97
|
-
/** The key
|
|
98
|
-
function ticketKeyOf(branch: string, worksetId: string): string | null {
|
|
99
|
-
|
|
100
|
-
const suffix = `-${worksetId}`;
|
|
101
|
-
if (!branch.startsWith(prefix) || !branch.endsWith(suffix)) return null;
|
|
102
|
-
const key = branch.slice(prefix.length, -suffix.length);
|
|
103
|
-
return isJiraKey(key) ? key : null;
|
|
90
|
+
/** The ticket key the template put into `branch` for the Workset, else null. */
|
|
91
|
+
function ticketKeyOf(branch: string, worksetId: string, template: BranchTemplate): string | null {
|
|
92
|
+
return matchBranchTemplate(template, branch, worksetId)?.ticket ?? null;
|
|
104
93
|
}
|
|
105
94
|
|
|
106
|
-
/** Existing
|
|
107
|
-
async function ticketedBranches(
|
|
108
|
-
|
|
95
|
+
/** Existing branches the template names for the Workset with any ticket, local or on `origin`. */
|
|
96
|
+
async function ticketedBranches(
|
|
97
|
+
worksetId: string,
|
|
98
|
+
listRefs: ListRefs,
|
|
99
|
+
template: BranchTemplate,
|
|
100
|
+
): Promise<string[]> {
|
|
101
|
+
if (!template.includes("{ticket}")) return [];
|
|
102
|
+
const prefix = branchTemplatePrefix(template);
|
|
103
|
+
const refs = await listRefs([`refs/heads/${prefix}`, `refs/remotes/origin/${prefix}`]);
|
|
109
104
|
return distinct(
|
|
110
105
|
refs.map((ref) => {
|
|
111
|
-
if (!
|
|
112
|
-
const branch =
|
|
113
|
-
return ticketKeyOf(branch, worksetId) ? branch : undefined;
|
|
106
|
+
if (!BRANCH_REF.test(ref)) return undefined;
|
|
107
|
+
const branch = ref.replace(BRANCH_REF, "");
|
|
108
|
+
return ticketKeyOf(branch, worksetId, template) ? branch : undefined;
|
|
114
109
|
}),
|
|
115
110
|
).toSorted();
|
|
116
111
|
}
|
|
117
112
|
|
|
118
|
-
|
|
119
|
-
export type MergeProbe = (
|
|
120
|
-
branch: string,
|
|
121
|
-
recordedHead: string | undefined,
|
|
122
|
-
) => Promise<"merged" | "squashed" | "open">;
|
|
113
|
+
type Existing = { branch: string; source: BranchSource } | "ambiguous" | null;
|
|
123
114
|
|
|
124
115
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
116
|
+
* An existing branch the template names for the Workset: the one without a ticket, else the
|
|
117
|
+
* single one with any ticket; `ambiguous` for several, reported in `diagnostics`. `probed` is a
|
|
118
|
+
* branch already known not to exist.
|
|
128
119
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
120
|
+
async function existingBranch(
|
|
121
|
+
worksetId: string,
|
|
122
|
+
template: BranchTemplate,
|
|
123
|
+
{ hasRef, listRefs }: DeliveryCheckout,
|
|
124
|
+
diagnostics: string[],
|
|
125
|
+
probed?: string,
|
|
126
|
+
): Promise<Existing> {
|
|
127
|
+
const plain = defaultDeliveryBranch(worksetId, null, template);
|
|
128
|
+
if (plain !== probed) {
|
|
129
|
+
const source = await sourceOf(plain, hasRef);
|
|
130
|
+
if (source !== "new") return { branch: plain, source };
|
|
131
|
+
}
|
|
132
|
+
// The ticket lives only in the branch name, so a branch created with one is found by name.
|
|
133
|
+
const ticketed = await ticketedBranches(worksetId, listRefs, template);
|
|
134
|
+
if (ticketed.length > 1) {
|
|
135
|
+
diagnostics.push(
|
|
136
|
+
`Workset ${worksetId} has several ticket branches (${ticketed.join(", ")}); select a branch explicitly.`,
|
|
137
|
+
);
|
|
138
|
+
return "ambiguous";
|
|
139
|
+
}
|
|
140
|
+
if (ticketed.length === 0) return null;
|
|
141
|
+
return { branch: ticketed[0]!, source: await sourceOf(ticketed[0]!, hasRef) };
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
const SETTLED: ReadonlySet<string> = new Set(["merged", "closed-unmerged"]);
|
|
@@ -147,14 +153,14 @@ interface Inherited {
|
|
|
147
153
|
/**
|
|
148
154
|
* The branches the Workset's direct `dependsOn` changes deliver in `repository` that are still
|
|
149
155
|
* open (not direct, not merged or dropped, present when refs can be probed), each with the
|
|
150
|
-
* dependencies recording it. A dependency never checked for a merge is probed
|
|
151
|
-
*
|
|
156
|
+
* dependencies recording it. A dependency never checked for a merge is probed in the
|
|
157
|
+
* checkout; one that looks merged is skipped and named in `diagnostics`.
|
|
152
158
|
*/
|
|
153
159
|
async function inheritedBranches(
|
|
154
160
|
companionPath: string,
|
|
155
161
|
found: Member[],
|
|
156
162
|
repository: string,
|
|
157
|
-
|
|
163
|
+
checkout: DeliveryCheckout | null,
|
|
158
164
|
diagnostics: string[],
|
|
159
165
|
): Promise<Inherited[]> {
|
|
160
166
|
const own = new Set(found.map((member) => member.change));
|
|
@@ -169,10 +175,10 @@ async function inheritedBranches(
|
|
|
169
175
|
return null;
|
|
170
176
|
}
|
|
171
177
|
const { branch } = delivery;
|
|
172
|
-
if (
|
|
178
|
+
if (checkout && (await sourceOf(branch, checkout.hasRef)) === "new") return null;
|
|
173
179
|
if (delivery.merge !== undefined) return { name, branch, unchecked: false };
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
const probed = checkout ? await checkout.mergeProbe(branch, delivery.head) : null;
|
|
181
|
+
if (probed === null) return { name, branch, unchecked: true };
|
|
176
182
|
if (probed === "open") return { name, branch, unchecked: false };
|
|
177
183
|
diagnostics.push(
|
|
178
184
|
probed === "merged"
|
|
@@ -199,17 +205,26 @@ async function inheritedBranches(
|
|
|
199
205
|
|
|
200
206
|
/** Branch order for a Workset whose identity is already checked. */
|
|
201
207
|
async function branchOf(
|
|
202
|
-
|
|
208
|
+
checkout: DeliveryCheckout | null,
|
|
209
|
+
{ companionPath, repository }: DeliverySubject,
|
|
210
|
+
options: DeliveryBranchOptions,
|
|
211
|
+
template: BranchTemplate,
|
|
203
212
|
worksetId: string,
|
|
204
213
|
): Promise<DeliveryBranchResolution> {
|
|
205
|
-
const { companionPath, repository, hasRef, listRefs } = request;
|
|
206
214
|
const workset = await findWorkset(companionPath, worksetId);
|
|
207
|
-
const ticket =
|
|
208
|
-
// The branch the ticket
|
|
209
|
-
const named = defaultDeliveryBranch(worksetId, ticket);
|
|
215
|
+
const ticket = options.ticket ?? workset?.ticket ?? null;
|
|
216
|
+
// The template's branch with the ticket; without it when there is none.
|
|
217
|
+
const named = defaultDeliveryBranch(worksetId, ticket, template);
|
|
218
|
+
// The same under the default template, for branches made before the team switched templates.
|
|
219
|
+
const defaultNamed = defaultDeliveryBranch(worksetId, ticket);
|
|
210
220
|
const found = await members(companionPath, worksetId, workset);
|
|
211
221
|
const records = found.flatMap((member) => (member.record ? [member.record] : []));
|
|
212
222
|
const diagnostics: string[] = [];
|
|
223
|
+
if (options.ticket && !template.includes("{ticket}")) {
|
|
224
|
+
diagnostics.push(
|
|
225
|
+
`Ticket ${options.ticket} is not in the branch name: branchTemplate ${template} has no {ticket}.`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
213
228
|
const unresolved = (): DeliveryBranchResolution => ({
|
|
214
229
|
branch: null,
|
|
215
230
|
source: null,
|
|
@@ -220,14 +235,14 @@ async function branchOf(
|
|
|
220
235
|
branch: string,
|
|
221
236
|
{ source, inheritedFrom = [] }: { source?: BranchSource; inheritedFrom?: string[] } = {},
|
|
222
237
|
): Promise<DeliveryBranchResolution> => {
|
|
223
|
-
if (ticket && branch !== named) {
|
|
238
|
+
if (ticket && branch !== named && branch !== defaultNamed) {
|
|
224
239
|
diagnostics.push(
|
|
225
240
|
`Ticket ${ticket} does not name the branch: ${branch} already delivers Workset ${worksetId}.`,
|
|
226
241
|
);
|
|
227
242
|
}
|
|
228
243
|
return {
|
|
229
244
|
branch,
|
|
230
|
-
source: source ?? (
|
|
245
|
+
source: source ?? (checkout ? await sourceOf(branch, checkout.hasRef) : null),
|
|
231
246
|
inheritedFrom,
|
|
232
247
|
diagnostics,
|
|
233
248
|
};
|
|
@@ -248,9 +263,11 @@ async function branchOf(
|
|
|
248
263
|
}
|
|
249
264
|
if (recorded.length === 1) {
|
|
250
265
|
const branch = recorded[0]!;
|
|
251
|
-
const key =
|
|
266
|
+
const key =
|
|
267
|
+
ticketKeyOf(branch, worksetId, template) ??
|
|
268
|
+
ticketKeyOf(branch, worksetId, DEFAULT_BRANCH_TEMPLATE);
|
|
252
269
|
// Only the branch name carries a ticket, so a wrong one is fixed by renaming the branch.
|
|
253
|
-
if (
|
|
270
|
+
if (options.ticket && key && key.toUpperCase() !== options.ticket.toUpperCase()) {
|
|
254
271
|
const changes = found.map((member) => member.change).join(" ");
|
|
255
272
|
diagnostics.push(
|
|
256
273
|
`To change the ticket of ${branch} before it is pushed, run \`git branch -m ${branch} ${named}\`, then \`mate artifact link ${changes} --branch ${named}\`.`,
|
|
@@ -263,7 +280,7 @@ async function branchOf(
|
|
|
263
280
|
companionPath,
|
|
264
281
|
found,
|
|
265
282
|
repository,
|
|
266
|
-
|
|
283
|
+
checkout,
|
|
267
284
|
diagnostics,
|
|
268
285
|
);
|
|
269
286
|
if (inherited.length > 1) {
|
|
@@ -283,63 +300,82 @@ async function branchOf(
|
|
|
283
300
|
}
|
|
284
301
|
}
|
|
285
302
|
|
|
286
|
-
const plain = defaultDeliveryBranch(worksetId);
|
|
287
|
-
|
|
303
|
+
const plain = defaultDeliveryBranch(worksetId, null, template);
|
|
304
|
+
const followsDefault = (branch: string, source: BranchSource) => {
|
|
305
|
+
diagnostics.push(
|
|
306
|
+
`${branch} follows the default template ${DEFAULT_BRANCH_TEMPLATE}, not branchTemplate ${template}; it is used because it already exists.`,
|
|
307
|
+
);
|
|
308
|
+
return resolved(branch, { source });
|
|
309
|
+
};
|
|
310
|
+
if (!checkout) return resolved(named);
|
|
311
|
+
const { hasRef } = checkout;
|
|
288
312
|
if (ticket) {
|
|
289
313
|
const source = await sourceOf(named, hasRef);
|
|
290
314
|
if (source !== "new") return resolved(named, { source });
|
|
315
|
+
if (defaultNamed !== named) {
|
|
316
|
+
const defaultSource = await sourceOf(defaultNamed, hasRef);
|
|
317
|
+
if (defaultSource !== "new") return followsDefault(defaultNamed, defaultSource);
|
|
318
|
+
}
|
|
291
319
|
// An explicit ticket asks for its own branch; a stale plain one must not take its place.
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
320
|
+
if (options.ticket) {
|
|
321
|
+
const stale = distinct([plain, defaultDeliveryBranch(worksetId)]).filter(
|
|
322
|
+
(branch) => branch !== named,
|
|
323
|
+
);
|
|
324
|
+
for (const branch of stale) {
|
|
325
|
+
// oxlint-disable-next-line no-await-in-loop -- at most two probes, reported in order
|
|
326
|
+
if ((await sourceOf(branch, hasRef)) !== "new") {
|
|
327
|
+
diagnostics.push(
|
|
328
|
+
`Existing ${branch} is not used: ticket ${ticket} names ${named}; record ${branch} with --branch to keep it.`,
|
|
329
|
+
);
|
|
330
|
+
}
|
|
297
331
|
}
|
|
298
332
|
return resolved(named, { source });
|
|
299
333
|
}
|
|
300
334
|
// A Workset record's ticket only names a branch none of whose forms exists yet.
|
|
301
335
|
}
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
if (
|
|
305
|
-
//
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
336
|
+
const existing = await existingBranch(worksetId, template, checkout, diagnostics);
|
|
337
|
+
if (existing === "ambiguous") return unresolved();
|
|
338
|
+
if (existing) return resolved(existing.branch, { source: existing.source });
|
|
339
|
+
// A branch made before the team switched templates keeps resolving.
|
|
340
|
+
if (template !== DEFAULT_BRANCH_TEMPLATE) {
|
|
341
|
+
const fallback = await existingBranch(
|
|
342
|
+
worksetId,
|
|
343
|
+
DEFAULT_BRANCH_TEMPLATE,
|
|
344
|
+
checkout,
|
|
345
|
+
diagnostics,
|
|
346
|
+
plain,
|
|
310
347
|
);
|
|
311
|
-
return unresolved();
|
|
348
|
+
if (fallback === "ambiguous") return unresolved();
|
|
349
|
+
if (fallback) return followsDefault(fallback.branch, fallback.source);
|
|
312
350
|
}
|
|
313
|
-
if (ticketed.length === 1) return resolved(ticketed[0]!);
|
|
314
351
|
return resolved(named, { source: "new" });
|
|
315
352
|
}
|
|
316
353
|
|
|
317
|
-
/** A {@link ListRefs} over a Git runner that answers stdout, or null on failure. */
|
|
318
|
-
export function listRefsWith(git: (args: string[]) => Promise<string | null>): ListRefs {
|
|
319
|
-
return async (prefixes) => {
|
|
320
|
-
const stdout = await git(["for-each-ref", "--format=%(refname)", ...prefixes]);
|
|
321
|
-
return stdout ? stdout.split("\n").filter(Boolean) : [];
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
|
|
325
354
|
/**
|
|
326
355
|
* The Delivery Branch link, worktree, and factory spawning share, for a change or a Workset in
|
|
327
356
|
* `repository`: the Workset identity check, then the branch its changes record when they agree,
|
|
328
|
-
* a branch inherited from a `dependsOn` change, then with a ticket
|
|
329
|
-
* (a record's ticket yields to any existing Workset branch); without one an existing
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
357
|
+
* a branch inherited from a `dependsOn` change, then with a ticket the template's name with it
|
|
358
|
+
* (a record's ticket yields to any existing Workset branch); without one an existing branch the
|
|
359
|
+
* template names without a ticket, else the single one with any ticket, else for a non-default
|
|
360
|
+
* template the same under the default, else the name without a ticket. The default template
|
|
361
|
+
* gives `workset/<id>` and `workset/<TICKET>-<id>`. Direct
|
|
362
|
+
* deliveries are not a Workset's branch. The template is the companion's; an invalid one
|
|
363
|
+
* counts as the default and is named in `templateDiagnostic`. Existence and merges are read
|
|
364
|
+
* in `checkout`, local branch first, so callers fetch before resolving; a null checkout gives
|
|
365
|
+
* the computed name with `source` null. A damaged record throws, as when it is read on its own.
|
|
334
366
|
*/
|
|
335
367
|
export async function resolveDeliveryBranch(
|
|
336
|
-
|
|
368
|
+
checkout: DeliveryCheckout | null,
|
|
369
|
+
subject: DeliverySubject,
|
|
370
|
+
options: DeliveryBranchOptions = {},
|
|
337
371
|
): Promise<DeliveryBranchResolution & { worksetId: string | null }> {
|
|
338
|
-
const repository =
|
|
372
|
+
const repository = subject.repository ?? undefined;
|
|
373
|
+
const setting = await companionBranchTemplate(subject.companionPath);
|
|
374
|
+
const templateField = setting.diagnostic ? { templateDiagnostic: setting.diagnostic } : {};
|
|
339
375
|
const identity =
|
|
340
|
-
"change" in
|
|
341
|
-
? await resolveWorksetOf(
|
|
342
|
-
: await resolveWorksetBranch(
|
|
376
|
+
"change" in subject
|
|
377
|
+
? await resolveWorksetOf(subject.companionPath, subject.change, repository)
|
|
378
|
+
: await resolveWorksetBranch(subject.companionPath, subject.worksetId, repository);
|
|
343
379
|
if (identity.id === null) {
|
|
344
380
|
return {
|
|
345
381
|
worksetId: null,
|
|
@@ -347,13 +383,15 @@ export async function resolveDeliveryBranch(
|
|
|
347
383
|
source: null,
|
|
348
384
|
inheritedFrom: [],
|
|
349
385
|
diagnostics: identity.diagnostics,
|
|
386
|
+
...templateField,
|
|
350
387
|
};
|
|
351
388
|
}
|
|
352
|
-
const resolution = await branchOf(
|
|
389
|
+
const resolution = await branchOf(checkout, subject, options, setting.template, identity.id);
|
|
353
390
|
return {
|
|
354
391
|
...resolution,
|
|
355
392
|
worksetId: identity.id,
|
|
356
393
|
diagnostics: [...identity.diagnostics, ...resolution.diagnostics],
|
|
394
|
+
...templateField,
|
|
357
395
|
};
|
|
358
396
|
}
|
|
359
397
|
|
|
@@ -375,9 +413,18 @@ export function worktreeAddArgs(
|
|
|
375
413
|
target: string,
|
|
376
414
|
base = "origin/HEAD",
|
|
377
415
|
): string[] {
|
|
378
|
-
if (source === "local") return ["worktree", "add", target, branch];
|
|
416
|
+
if (source === "local") return ["worktree", "add", "--end-of-options", target, branch];
|
|
379
417
|
if (source === "remote") {
|
|
380
|
-
return [
|
|
418
|
+
return [
|
|
419
|
+
"worktree",
|
|
420
|
+
"add",
|
|
421
|
+
"--track",
|
|
422
|
+
"-b",
|
|
423
|
+
branch,
|
|
424
|
+
"--end-of-options",
|
|
425
|
+
target,
|
|
426
|
+
`origin/${branch}`,
|
|
427
|
+
];
|
|
381
428
|
}
|
|
382
|
-
return ["worktree", "add", "--no-track", "-b", branch, target, base];
|
|
429
|
+
return ["worktree", "add", "--no-track", "-b", branch, "--end-of-options", target, base];
|
|
383
430
|
}
|
|
@@ -23,13 +23,23 @@ export interface AgentLaunchOptions {
|
|
|
23
23
|
/** A Claude session id; anything else never reaches the command line. */
|
|
24
24
|
export const CLAUDE_SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
25
25
|
|
|
26
|
+
/** The managed launch's command and its Mate options; the agent's own arguments follow. */
|
|
27
|
+
function managedLaunch(mode: "--prepare-only" | "--prepared", noGit?: boolean): string[] {
|
|
28
|
+
return ["mate", "claude", "--", "--yes", mode, ...(noGit ? ["--no-git"] : [])];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The launch's preparation (wrap, index) run through exec, so the attached terminal shows none of it. */
|
|
32
|
+
export function prepareCommand(options: Pick<AgentLaunchOptions, "noGit"> = {}): string[] {
|
|
33
|
+
return managedLaunch("--prepare-only", options.noGit);
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
/** The managed launch inside the Workset container, with the server-built first turn. */
|
|
27
37
|
export function agentCommand(
|
|
28
38
|
start: AttachStart,
|
|
29
39
|
intent: string,
|
|
30
40
|
options: AgentLaunchOptions = {},
|
|
31
41
|
): string[] {
|
|
32
|
-
const launch =
|
|
42
|
+
const launch = managedLaunch("--prepared", options.noGit);
|
|
33
43
|
if (start === "continue") return [...launch, "--continue"];
|
|
34
44
|
if (start === "resume") {
|
|
35
45
|
if (!options.resumeSession || !CLAUDE_SESSION_ID.test(options.resumeSession)) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AGENT_CREDENTIAL_NAMES,
|
|
3
2
|
checkedCredential,
|
|
4
3
|
credentialKind,
|
|
5
4
|
type CredentialStore,
|
|
6
5
|
NO_CREDENTIAL,
|
|
7
6
|
} from "./credential-store";
|
|
7
|
+
import { checkedGitKey, checkedGitToken, GitCredentialStore } from "./git-credential-store";
|
|
8
8
|
import { FactoryError } from "./ids";
|
|
9
9
|
import type { WorksetRuntime } from "./runtime";
|
|
10
10
|
|
|
@@ -12,11 +12,11 @@ export { AGENT_CREDENTIAL_NAMES, takeAgentCredential } from "./credential-store"
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The factory broker's API: the Workset operations and the Workset agent
|
|
15
|
-
* credential, over HTTP on a Unix socket, and nothing else. It is the boundary
|
|
15
|
+
* credential and Git tokens, over HTTP on a Unix socket, and nothing else. It is the boundary
|
|
16
16
|
* between processes running as the unprivileged user and the inner Docker
|
|
17
17
|
* daemon, so every request is checked field by field and an unexpected field is
|
|
18
|
-
* refused
|
|
19
|
-
*
|
|
18
|
+
* refused: callers cannot choose a mount, image, privilege or environment.
|
|
19
|
+
* No answer carries the credential's value.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
type Body = Record<string, unknown>;
|
|
@@ -31,19 +31,6 @@ function only(body: Body, allowed: string[]): void {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function stringRecord(value: unknown, what: string): Record<string, string> | undefined {
|
|
35
|
-
if (value === undefined) return undefined;
|
|
36
|
-
if (
|
|
37
|
-
value === null ||
|
|
38
|
-
typeof value !== "object" ||
|
|
39
|
-
Array.isArray(value) ||
|
|
40
|
-
!Object.values(value).every((entry) => typeof entry === "string")
|
|
41
|
-
) {
|
|
42
|
-
throw new FactoryError(`${what} must map names to strings`);
|
|
43
|
-
}
|
|
44
|
-
return value as Record<string, string>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
34
|
export interface BrokerHandler {
|
|
48
35
|
(operation: string, body: Body): Promise<unknown>;
|
|
49
36
|
}
|
|
@@ -51,6 +38,7 @@ export interface BrokerHandler {
|
|
|
51
38
|
export function brokerHandler(
|
|
52
39
|
runtime: WorksetRuntime,
|
|
53
40
|
credentials: CredentialStore,
|
|
41
|
+
gitTokens: GitCredentialStore = new GitCredentialStore(null, null),
|
|
54
42
|
): BrokerHandler {
|
|
55
43
|
return async (operation, body) => {
|
|
56
44
|
switch (operation) {
|
|
@@ -95,39 +83,48 @@ export function brokerHandler(
|
|
|
95
83
|
only(body, []);
|
|
96
84
|
credentials.clear();
|
|
97
85
|
return {};
|
|
86
|
+
case "companion.clone":
|
|
87
|
+
only(body, ["url"]);
|
|
88
|
+
return runtime.cloneCompanion(body.url);
|
|
89
|
+
case "remote.check":
|
|
90
|
+
only(body, ["url"]);
|
|
91
|
+
await runtime.checkRemote(body.url);
|
|
92
|
+
return {};
|
|
93
|
+
case "git.token.list":
|
|
94
|
+
only(body, []);
|
|
95
|
+
return { tokens: gitTokens.status() };
|
|
96
|
+
case "git.token.set":
|
|
97
|
+
only(body, ["key", "token"]);
|
|
98
|
+
gitTokens.set(checkedGitKey(body.key), checkedGitToken(body.token));
|
|
99
|
+
return {};
|
|
100
|
+
case "git.token.clear":
|
|
101
|
+
only(body, ["key"]);
|
|
102
|
+
gitTokens.clear(checkedGitKey(body.key));
|
|
103
|
+
return {};
|
|
98
104
|
case "exec": {
|
|
99
|
-
only(body, ["id", "command", "
|
|
105
|
+
only(body, ["id", "command", "cwd", "agent", "stdin"]);
|
|
100
106
|
if (body.stdin !== undefined && typeof body.stdin !== "string") {
|
|
101
107
|
throw new FactoryError("stdin must be base64 text");
|
|
102
108
|
}
|
|
103
|
-
const env = { ...stringRecord(body.env, "exec's environment") };
|
|
104
|
-
for (const name of AGENT_CREDENTIAL_NAMES) {
|
|
105
|
-
if (name in env) {
|
|
106
|
-
throw new FactoryError(
|
|
107
|
-
`${name} is set by the broker for agent commands, not by callers`,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
109
|
if (body.agent !== undefined && typeof body.agent !== "boolean") {
|
|
112
110
|
throw new FactoryError("agent must be true or false");
|
|
113
111
|
}
|
|
114
112
|
if (body.cwd !== undefined && typeof body.cwd !== "string") {
|
|
115
113
|
throw new FactoryError("cwd must be a path relative to the worktree");
|
|
116
114
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
115
|
+
const credential = body.agent === true ? credentials.current() : undefined;
|
|
116
|
+
if (credential === null) throw new FactoryError(NO_CREDENTIAL);
|
|
117
|
+
const result = await runtime.exec(
|
|
118
|
+
{
|
|
119
|
+
id: body.id as string,
|
|
120
|
+
command: body.command as string[],
|
|
121
|
+
cwd: body.cwd as string | undefined,
|
|
122
|
+
...(typeof body.stdin === "string"
|
|
123
|
+
? { stdin: new Uint8Array(Buffer.from(body.stdin, "base64")) }
|
|
124
|
+
: {}),
|
|
125
|
+
},
|
|
126
|
+
credential,
|
|
127
|
+
);
|
|
131
128
|
return result;
|
|
132
129
|
}
|
|
133
130
|
default:
|
|
@@ -2,6 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
|
|
3
3
|
import type { CommandResult } from "./command";
|
|
4
4
|
import type { CredentialKind, CredentialStatus } from "./credential-store";
|
|
5
|
+
import type { GitTokenStatus } from "./git-credential-store";
|
|
5
6
|
import { FactoryError } from "./ids";
|
|
6
7
|
import type { ExecRequest, SpawnRequest, WorksetInfo } from "./runtime";
|
|
7
8
|
|
|
@@ -26,6 +27,19 @@ export interface FactoryClient {
|
|
|
26
27
|
set(kind: CredentialKind, value: string): Promise<void>;
|
|
27
28
|
clear(): Promise<void>;
|
|
28
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Clones a companion into the factory's companions directory, or reports the checkout of the
|
|
32
|
+
* same repository already there; the folder is the broker's choice.
|
|
33
|
+
*/
|
|
34
|
+
cloneCompanion(url: string): Promise<{ path: string; existing: boolean }>;
|
|
35
|
+
/** Whether a Git URL answers with the stored token for it; refused with code `auth` when it needs one. */
|
|
36
|
+
checkRemote(url: string): Promise<void>;
|
|
37
|
+
/** The Git tokens by host or host and organization; no call returns a token. */
|
|
38
|
+
gitToken: {
|
|
39
|
+
list(): Promise<GitTokenStatus[]>;
|
|
40
|
+
set(key: string, token: string): Promise<void>;
|
|
41
|
+
clear(key: string): Promise<void>;
|
|
42
|
+
};
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
/** The broker serves attaches on a second socket beside its own. */
|
|
@@ -63,7 +77,7 @@ export function factoryClient(
|
|
|
63
77
|
if (!answer.ok) {
|
|
64
78
|
throw new FactoryError(
|
|
65
79
|
answer.error ?? "the factory broker refused the request",
|
|
66
|
-
answer.code === "busy"
|
|
80
|
+
answer.code === "busy" || answer.code === "auth" ? answer.code : undefined,
|
|
67
81
|
);
|
|
68
82
|
}
|
|
69
83
|
return answer.result as T;
|
|
@@ -88,5 +102,12 @@ export function factoryClient(
|
|
|
88
102
|
set: async (kind, value) => void (await call("credential.set", { kind, value })),
|
|
89
103
|
clear: async () => void (await call("credential.clear", {})),
|
|
90
104
|
},
|
|
105
|
+
cloneCompanion: (url) => call("companion.clone", { url }),
|
|
106
|
+
checkRemote: async (url) => void (await call("remote.check", { url })),
|
|
107
|
+
gitToken: {
|
|
108
|
+
list: async () => (await call<{ tokens: GitTokenStatus[] }>("git.token.list", {})).tokens,
|
|
109
|
+
set: async (key, token) => void (await call("git.token.set", { key, token })),
|
|
110
|
+
clear: async (key) => void (await call("git.token.clear", { key })),
|
|
111
|
+
},
|
|
91
112
|
};
|
|
92
113
|
}
|