@uniqbit/mate-core 1.0.0-canary.9 → 1.0.1-canary.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/agent-selector.ts +16 -0
- 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/triage.ts +11 -23
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/commands/workflow/workflow.ts +3 -2
- package/src/cli/commands/working/cleanup.ts +1 -18
- package/src/cli/companion-link-wizard.tsx +158 -91
- package/src/cli/companion-selector.ts +26 -0
- package/src/cli/usage.ts +1 -1
- package/src/lib/agent-credential.ts +131 -0
- package/src/lib/components/select-one.tsx +122 -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/workflow/handoff.ts +1 -1
- package/src/lib/workflow/position.ts +29 -2
- 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/src/cli/companion-selector.tsx +0 -139
- 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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** @jsxRuntime automatic */
|
|
2
2
|
/** @jsxImportSource react */
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
3
5
|
import { Box, render as inkRender } from "ink";
|
|
4
6
|
import { useEffect } from "react";
|
|
5
7
|
|
|
@@ -17,15 +19,24 @@ const companionLinkWizardDeps = {
|
|
|
17
19
|
export interface CompanionLinkInputs {
|
|
18
20
|
source: CompanionSource;
|
|
19
21
|
gitUrl?: string;
|
|
22
|
+
/** A clone already on this machine whose origin is `gitUrl`'s repository; links it instead of cloning. */
|
|
23
|
+
clonePath?: string;
|
|
20
24
|
localPath?: string;
|
|
21
25
|
companionPaths?: string[];
|
|
26
|
+
/** True replaces the companions `replacedBy` names, false keeps both. */
|
|
27
|
+
replace?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ExistingCompanion {
|
|
31
|
+
path: string;
|
|
32
|
+
registered: boolean;
|
|
22
33
|
}
|
|
23
34
|
|
|
24
|
-
interface
|
|
35
|
+
interface SelectStep {
|
|
25
36
|
kind: "select";
|
|
26
|
-
field: "source";
|
|
37
|
+
field: "source" | "clonePath" | "replace";
|
|
27
38
|
label: string;
|
|
28
|
-
options: Array<{ key:
|
|
39
|
+
options: Array<{ key: string; label: string }>;
|
|
29
40
|
activeIndex: number;
|
|
30
41
|
}
|
|
31
42
|
|
|
@@ -33,7 +44,7 @@ interface CompanionMultiSelectStep {
|
|
|
33
44
|
kind: "multiselect";
|
|
34
45
|
field: "companionPaths";
|
|
35
46
|
label: string;
|
|
36
|
-
options: string
|
|
47
|
+
options: Array<{ key: string; label: string }>;
|
|
37
48
|
activeIndex: number;
|
|
38
49
|
selected: Set<string>;
|
|
39
50
|
}
|
|
@@ -46,7 +57,7 @@ interface TextStep {
|
|
|
46
57
|
error?: string;
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
type WizardStep =
|
|
60
|
+
type WizardStep = SelectStep | CompanionMultiSelectStep | TextStep;
|
|
50
61
|
|
|
51
62
|
interface WizardAppProps {
|
|
52
63
|
step: WizardStep;
|
|
@@ -77,9 +88,8 @@ function CompanionLinkWizardApp({ step, stepNumber, totalSteps, onMounted }: Wiz
|
|
|
77
88
|
if (step.kind === "multiselect") {
|
|
78
89
|
const enterHint = isLastStep ? "enter confirm" : "enter next";
|
|
79
90
|
const items = step.options.map((option) => ({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
indicator: step.selected.has(option) ? "◉" : "○",
|
|
91
|
+
...option,
|
|
92
|
+
indicator: step.selected.has(option.key) ? "◉" : "○",
|
|
83
93
|
}));
|
|
84
94
|
return (
|
|
85
95
|
<Box flexDirection="column" width="100%">
|
|
@@ -106,65 +116,128 @@ function CompanionLinkWizardApp({ step, stepNumber, totalSteps, onMounted }: Wiz
|
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
export interface CompanionLinkWizardOptions {
|
|
109
|
-
existingCompanions?:
|
|
119
|
+
existingCompanions?: ExistingCompanion[];
|
|
120
|
+
/** Existing companions whose origin is the URL's repository. */
|
|
121
|
+
clonesOf?: (gitUrl: string) => string[];
|
|
122
|
+
/** The linked companions these inputs would replace; empty asks nothing. */
|
|
123
|
+
replacedBy?: (inputs: CompanionLinkInputs) => string[];
|
|
110
124
|
stdin?: NodeJS.ReadStream;
|
|
111
125
|
stdout?: NodeJS.WriteStream;
|
|
112
126
|
stderr?: NodeJS.WriteStream;
|
|
113
127
|
}
|
|
114
128
|
|
|
129
|
+
const REPLACE = "replace";
|
|
130
|
+
|
|
131
|
+
interface WizardValues {
|
|
132
|
+
source: CompanionSource;
|
|
133
|
+
gitUrl: string;
|
|
134
|
+
/** Into the matching clones; their count means "Clone a new copy". */
|
|
135
|
+
cloneActiveIndex: number;
|
|
136
|
+
localPath: string;
|
|
137
|
+
companionPaths: Set<string>;
|
|
138
|
+
companionActiveIndex: number;
|
|
139
|
+
replace: boolean;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function resultOf(
|
|
143
|
+
values: WizardValues,
|
|
144
|
+
clonesOf: (gitUrl: string) => string[],
|
|
145
|
+
): CompanionLinkInputs {
|
|
146
|
+
const { source } = values;
|
|
147
|
+
return {
|
|
148
|
+
source,
|
|
149
|
+
gitUrl: source === "git" ? values.gitUrl : undefined,
|
|
150
|
+
clonePath: source === "git" ? clonesOf(values.gitUrl)[values.cloneActiveIndex] : undefined,
|
|
151
|
+
localPath: source === "local" ? values.localPath : undefined,
|
|
152
|
+
companionPaths: source === "existing" ? [...values.companionPaths] : undefined,
|
|
153
|
+
replace: values.replace,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
115
157
|
function buildSteps(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
localPath: string;
|
|
120
|
-
companionPaths: Set<string>;
|
|
121
|
-
companionActiveIndex: number;
|
|
158
|
+
values: WizardValues,
|
|
159
|
+
options: Required<Pick<CompanionLinkWizardOptions, "clonesOf" | "replacedBy">> & {
|
|
160
|
+
existingCompanions: ExistingCompanion[];
|
|
122
161
|
},
|
|
123
|
-
existingCompanions: string[],
|
|
124
162
|
): WizardStep[] {
|
|
125
|
-
const
|
|
126
|
-
|
|
163
|
+
const { existingCompanions, clonesOf, replacedBy } = options;
|
|
164
|
+
const sourceOptions: SelectStep["options"] = [
|
|
127
165
|
...(existingCompanions.length > 0
|
|
128
|
-
? [{ key: "existing"
|
|
166
|
+
? [{ key: "existing", label: "Use a companion already on this machine" }]
|
|
129
167
|
: []),
|
|
130
|
-
{ key: "
|
|
168
|
+
{ key: "git", label: "Clone from a Git URL into ~/.mate/companions" },
|
|
169
|
+
{ key: "local", label: "Enter the path of another folder" },
|
|
170
|
+
];
|
|
171
|
+
const steps: WizardStep[] = [
|
|
172
|
+
{
|
|
173
|
+
kind: "select",
|
|
174
|
+
field: "source",
|
|
175
|
+
label: "Companion Source",
|
|
176
|
+
options: sourceOptions,
|
|
177
|
+
activeIndex: Math.max(
|
|
178
|
+
0,
|
|
179
|
+
sourceOptions.findIndex((option) => option.key === values.source),
|
|
180
|
+
),
|
|
181
|
+
},
|
|
131
182
|
];
|
|
132
|
-
const sourceStep: SourceStep = {
|
|
133
|
-
kind: "select",
|
|
134
|
-
field: "source",
|
|
135
|
-
label: "Companion Source",
|
|
136
|
-
options: sourceOptions,
|
|
137
|
-
activeIndex: Math.max(
|
|
138
|
-
0,
|
|
139
|
-
sourceOptions.findIndex((option) => option.key === source),
|
|
140
|
-
),
|
|
141
|
-
};
|
|
142
183
|
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
184
|
+
const clones = values.source === "git" ? clonesOf(values.gitUrl) : [];
|
|
185
|
+
if (values.source === "git") {
|
|
186
|
+
steps.push({ kind: "text", field: "gitUrl", label: "Companion Git URL", value: values.gitUrl });
|
|
187
|
+
if (clones.length > 0) {
|
|
188
|
+
steps.push({
|
|
189
|
+
kind: "select",
|
|
190
|
+
field: "clonePath",
|
|
191
|
+
label: "This repository is already cloned on this machine",
|
|
192
|
+
options: [
|
|
193
|
+
...clones.map((clone) => ({
|
|
194
|
+
key: clone,
|
|
195
|
+
label: `Use ${path.basename(clone)} ${clone}`,
|
|
196
|
+
})),
|
|
197
|
+
{ key: "new", label: "Clone a new copy" },
|
|
198
|
+
],
|
|
199
|
+
activeIndex: Math.min(values.cloneActiveIndex, clones.length),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
} else if (values.source === "local") {
|
|
203
|
+
steps.push({
|
|
204
|
+
kind: "text",
|
|
205
|
+
field: "localPath",
|
|
206
|
+
label: "Local Companion Path",
|
|
207
|
+
value: values.localPath,
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
steps.push({
|
|
211
|
+
kind: "multiselect",
|
|
212
|
+
field: "companionPaths",
|
|
213
|
+
label: "Existing Companions",
|
|
214
|
+
options: existingCompanions.map((companion) => ({
|
|
215
|
+
key: companion.path,
|
|
216
|
+
// Name and mark lead: the menu cuts long paths at the terminal's edge.
|
|
217
|
+
label: `${path.basename(companion.path)}${companion.registered ? "" : " (not registered)"} ${companion.path}`,
|
|
218
|
+
})),
|
|
219
|
+
activeIndex: values.companionActiveIndex,
|
|
220
|
+
selected: values.companionPaths,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const replaced = replacedBy(resultOf(values, clonesOf));
|
|
225
|
+
if (replaced.length > 0) {
|
|
226
|
+
steps.push({
|
|
227
|
+
kind: "select",
|
|
228
|
+
field: "replace",
|
|
229
|
+
label: "This folder is already linked to another companion",
|
|
230
|
+
options: [
|
|
231
|
+
{
|
|
232
|
+
key: REPLACE,
|
|
233
|
+
label: `Replace ${replaced.map((companion) => path.basename(companion)).join(", ")}`,
|
|
234
|
+
},
|
|
235
|
+
{ key: "keep", label: "Keep both" },
|
|
236
|
+
],
|
|
237
|
+
activeIndex: values.replace ? 0 : 1,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return steps;
|
|
168
241
|
}
|
|
169
242
|
|
|
170
243
|
export async function selectCompanionLinkInputs(
|
|
@@ -174,20 +247,27 @@ export async function selectCompanionLinkInputs(
|
|
|
174
247
|
const stdout = options.stdout ?? process.stdout;
|
|
175
248
|
const stderr = options.stderr ?? process.stderr;
|
|
176
249
|
const existingCompanions = options.existingCompanions ?? [];
|
|
250
|
+
const stepOptions = {
|
|
251
|
+
existingCompanions,
|
|
252
|
+
clonesOf: options.clonesOf ?? (() => []),
|
|
253
|
+
replacedBy: options.replacedBy ?? (() => []),
|
|
254
|
+
};
|
|
177
255
|
|
|
178
256
|
return new Promise<CompanionLinkInputs | null>((resolve, reject) => {
|
|
179
257
|
let resolved = false;
|
|
180
|
-
|
|
181
|
-
|
|
258
|
+
const values: WizardValues = {
|
|
259
|
+
source: existingCompanions.length > 0 ? "existing" : "git",
|
|
182
260
|
gitUrl: "",
|
|
261
|
+
cloneActiveIndex: 0,
|
|
183
262
|
localPath: "",
|
|
184
263
|
companionPaths: new Set<string>(),
|
|
185
264
|
companionActiveIndex: 0,
|
|
265
|
+
replace: true,
|
|
186
266
|
};
|
|
187
267
|
let currentStepIndex = 0;
|
|
188
268
|
const keepAlive = setInterval(() => {}, 1 << 30);
|
|
189
269
|
let rendered: ReturnType<typeof inkRender> | undefined;
|
|
190
|
-
let steps = buildSteps(
|
|
270
|
+
let steps = buildSteps(values, stepOptions);
|
|
191
271
|
|
|
192
272
|
const cleanup = () => {
|
|
193
273
|
clearInterval(keepAlive);
|
|
@@ -205,13 +285,6 @@ export async function selectCompanionLinkInputs(
|
|
|
205
285
|
resolve(value);
|
|
206
286
|
};
|
|
207
287
|
|
|
208
|
-
const buildResult = (): CompanionLinkInputs => ({
|
|
209
|
-
source,
|
|
210
|
-
gitUrl: source === "git" ? values.gitUrl : undefined,
|
|
211
|
-
localPath: source === "local" ? values.localPath : undefined,
|
|
212
|
-
companionPaths: source === "existing" ? [...values.companionPaths] : undefined,
|
|
213
|
-
});
|
|
214
|
-
|
|
215
288
|
const rerender = () => {
|
|
216
289
|
rendered?.rerender(
|
|
217
290
|
<CompanionLinkWizardApp
|
|
@@ -222,8 +295,16 @@ export async function selectCompanionLinkInputs(
|
|
|
222
295
|
);
|
|
223
296
|
};
|
|
224
297
|
|
|
225
|
-
|
|
226
|
-
|
|
298
|
+
// Later steps depend on earlier answers, so every submit rebuilds them.
|
|
299
|
+
const advance = () => {
|
|
300
|
+
steps = buildSteps(values, stepOptions);
|
|
301
|
+
if (currentStepIndex < steps.length - 1) {
|
|
302
|
+
currentStepIndex++;
|
|
303
|
+
rerender();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
doResolve(resultOf(values, stepOptions.clonesOf));
|
|
307
|
+
rendered?.unmount();
|
|
227
308
|
};
|
|
228
309
|
|
|
229
310
|
const onData = (chunk: string) => {
|
|
@@ -232,8 +313,8 @@ export async function selectCompanionLinkInputs(
|
|
|
232
313
|
if (step.kind === "multiselect" && chunk === " ") {
|
|
233
314
|
const option = step.options[step.activeIndex];
|
|
234
315
|
if (option) {
|
|
235
|
-
if (step.selected.has(option)) step.selected.delete(option);
|
|
236
|
-
else step.selected.add(option);
|
|
316
|
+
if (step.selected.has(option.key)) step.selected.delete(option.key);
|
|
317
|
+
else step.selected.add(option.key);
|
|
237
318
|
}
|
|
238
319
|
rerender();
|
|
239
320
|
return;
|
|
@@ -277,14 +358,7 @@ export async function selectCompanionLinkInputs(
|
|
|
277
358
|
if (parsed.action !== "submit" || !step.value.trim()) {
|
|
278
359
|
return;
|
|
279
360
|
}
|
|
280
|
-
|
|
281
|
-
if (currentStepIndex < steps.length - 1) {
|
|
282
|
-
currentStepIndex++;
|
|
283
|
-
rerender();
|
|
284
|
-
} else {
|
|
285
|
-
doResolve(buildResult());
|
|
286
|
-
rendered?.unmount();
|
|
287
|
-
}
|
|
361
|
+
advance();
|
|
288
362
|
return;
|
|
289
363
|
}
|
|
290
364
|
|
|
@@ -305,26 +379,19 @@ export async function selectCompanionLinkInputs(
|
|
|
305
379
|
}
|
|
306
380
|
|
|
307
381
|
if (step.kind === "select") {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
rerender();
|
|
382
|
+
const key = step.options[step.activeIndex]!.key;
|
|
383
|
+
if (step.field === "source") values.source = key as CompanionSource;
|
|
384
|
+
else if (step.field === "clonePath") values.cloneActiveIndex = step.activeIndex;
|
|
385
|
+
else values.replace = key === REPLACE;
|
|
386
|
+
advance();
|
|
314
387
|
return;
|
|
315
388
|
}
|
|
316
389
|
|
|
317
390
|
if (step.selected.size === 0) {
|
|
318
391
|
const option = step.options[step.activeIndex];
|
|
319
|
-
if (option) step.selected.add(option);
|
|
320
|
-
}
|
|
321
|
-
if (currentStepIndex < steps.length - 1) {
|
|
322
|
-
currentStepIndex++;
|
|
323
|
-
rerender();
|
|
324
|
-
} else {
|
|
325
|
-
doResolve(buildResult());
|
|
326
|
-
rendered?.unmount();
|
|
392
|
+
if (option) step.selected.add(option.key);
|
|
327
393
|
}
|
|
394
|
+
advance();
|
|
328
395
|
};
|
|
329
396
|
|
|
330
397
|
const onMounted = () => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { selectOne, type SelectOneOptions } from "../lib/components/select-one";
|
|
2
|
+
import type { CompanionMatch } from "../lib/orchestrator/repository-link";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prompts the user to pick one companion when the active working repo is
|
|
6
|
+
* linked from more than one companion's registry (`CompanionResolver`
|
|
7
|
+
* reports this via `ambiguousMatches`, since only one companion may be
|
|
8
|
+
* active for a repo at a time).
|
|
9
|
+
*/
|
|
10
|
+
export function selectCompanion(
|
|
11
|
+
matches: CompanionMatch[],
|
|
12
|
+
options: SelectOneOptions = {},
|
|
13
|
+
): Promise<CompanionMatch | null> {
|
|
14
|
+
return selectOne(
|
|
15
|
+
matches,
|
|
16
|
+
{
|
|
17
|
+
title: "Multiple companions link this repo — pick one",
|
|
18
|
+
toItem: (match) => ({
|
|
19
|
+
key: match.companionPath,
|
|
20
|
+
label: match.companionPath,
|
|
21
|
+
description: `(repo: ${match.repositoryId})`,
|
|
22
|
+
}),
|
|
23
|
+
},
|
|
24
|
+
options,
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/cli/usage.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function usage(): string {
|
|
|
47
47
|
` ${n} artifact submit <change>... [--repository <org/repo>]`,
|
|
48
48
|
" [--branch <b> [--direct]|--not-applicable <reason>|--skip-branch] [--fetch] [--json]",
|
|
49
49
|
` ${n} artifact submit --drop <change>... [--json]`,
|
|
50
|
-
` ${n} artifact take <change> [--json] a submitted change into this checkout
|
|
50
|
+
` ${n} artifact take <change> [--json] a submitted or shared change into this checkout`,
|
|
51
51
|
` ${n} artifact archive <change> [options] (deprecated alias of artifact submit)`,
|
|
52
52
|
` ${n} artifact resolve <change> (--capability <c> --requirement <name> --file <path>)...`,
|
|
53
53
|
" [--json] one triple per stale requirement of the change",
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { writeAtomic } from "../runtime/write-atomic";
|
|
5
|
+
import { CREDENTIAL_KIND_LABELS, CREDENTIAL_KINDS, type CredentialKind } from "./credential-kinds";
|
|
6
|
+
|
|
7
|
+
export type { CredentialKind } from "./credential-kinds";
|
|
8
|
+
|
|
9
|
+
export const AGENT_CREDENTIAL_NAMES = ["CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY"] as const;
|
|
10
|
+
export type AgentCredentialName = (typeof AGENT_CREDENTIAL_NAMES)[number];
|
|
11
|
+
|
|
12
|
+
export interface AgentCredential {
|
|
13
|
+
name: AgentCredentialName;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class AgentCredentialError extends Error {
|
|
18
|
+
override name = "AgentCredentialError";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const KINDS: Record<CredentialKind, { name: AgentCredentialName; prefixes: readonly string[] }> = {
|
|
22
|
+
subscription: { name: "CLAUDE_CODE_OAUTH_TOKEN", prefixes: ["sk-ant-oat"] },
|
|
23
|
+
"api-key": { name: "ANTHROPIC_API_KEY", prefixes: ["sk-ant-api", "sk-ant-usr"] },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function credentialKind(name: AgentCredentialName): CredentialKind {
|
|
27
|
+
return name === "CLAUDE_CODE_OAUTH_TOKEN" ? "subscription" : "api-key";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function credentialLabel(name: AgentCredentialName): string {
|
|
31
|
+
return CREDENTIAL_KIND_LABELS[credentialKind(name)];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CredentialStatus {
|
|
35
|
+
kind: CredentialKind | null;
|
|
36
|
+
/** `login`: no credential set or supplied; the local Claude login answers. */
|
|
37
|
+
source: "studio" | "startup" | "login" | null;
|
|
38
|
+
/** When it was set in Studio, as an ISO date; null otherwise. */
|
|
39
|
+
setAt: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function checkedCredential(kind: unknown, value: unknown): AgentCredential {
|
|
43
|
+
if (typeof kind !== "string" || !CREDENTIAL_KINDS.includes(kind as CredentialKind)) {
|
|
44
|
+
throw new AgentCredentialError(`kind must be one of ${CREDENTIAL_KINDS.join(", ")}`);
|
|
45
|
+
}
|
|
46
|
+
const expected = KINDS[kind as CredentialKind];
|
|
47
|
+
const label = CREDENTIAL_KIND_LABELS[kind as CredentialKind];
|
|
48
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
49
|
+
if (!text) throw new AgentCredentialError(`no ${label} was given`);
|
|
50
|
+
if (/\s/.test(text) || !expected.prefixes.some((prefix) => text.startsWith(prefix))) {
|
|
51
|
+
throw new AgentCredentialError(
|
|
52
|
+
`${label}s start with ${expected.prefixes.join(" or ")} and have no spaces; nothing was stored`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return { name: expected.name, value: text };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function parse(text: string): AgentCredential | null {
|
|
59
|
+
for (const line of text.split("\n")) {
|
|
60
|
+
const separator = line.indexOf("=");
|
|
61
|
+
const name = line.slice(0, separator) as AgentCredentialName;
|
|
62
|
+
if (separator > 0 && AGENT_CREDENTIAL_NAMES.includes(name)) {
|
|
63
|
+
const value = line.slice(separator + 1).trim();
|
|
64
|
+
if (value) return { name, value };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AgentCredentials {
|
|
71
|
+
current(): AgentCredential | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class CredentialStore implements AgentCredentials {
|
|
75
|
+
private stored: AgentCredential | null = null;
|
|
76
|
+
private setAt: Date | null = null;
|
|
77
|
+
|
|
78
|
+
constructor(
|
|
79
|
+
private readonly file: string | null,
|
|
80
|
+
private readonly startup: AgentCredential | null,
|
|
81
|
+
) {
|
|
82
|
+
if (file === null) return;
|
|
83
|
+
try {
|
|
84
|
+
this.stored = parse(fs.readFileSync(file, "utf8"));
|
|
85
|
+
this.setAt = this.stored ? fs.statSync(file).mtime : null;
|
|
86
|
+
} catch {
|
|
87
|
+
this.stored = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
current(): AgentCredential | null {
|
|
92
|
+
return this.stored ?? this.startup;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
studio(): AgentCredential | null {
|
|
96
|
+
return this.stored;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
status(): CredentialStatus {
|
|
100
|
+
if (this.stored) {
|
|
101
|
+
return {
|
|
102
|
+
kind: credentialKind(this.stored.name),
|
|
103
|
+
source: "studio",
|
|
104
|
+
setAt: this.setAt?.toISOString() ?? null,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (this.startup) {
|
|
108
|
+
return { kind: credentialKind(this.startup.name), source: "startup", setAt: null };
|
|
109
|
+
}
|
|
110
|
+
return { kind: null, source: null, setAt: null };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async set(credential: AgentCredential): Promise<void> {
|
|
114
|
+
const file = this.writable();
|
|
115
|
+
await fs.promises.mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
116
|
+
await writeAtomic(file, `${credential.name}=${credential.value}\n`, 0o600);
|
|
117
|
+
this.stored = credential;
|
|
118
|
+
this.setAt = (await fs.promises.stat(file)).mtime;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
clear(): void {
|
|
122
|
+
fs.rmSync(this.writable(), { force: true });
|
|
123
|
+
this.stored = null;
|
|
124
|
+
this.setAt = null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private writable(): string {
|
|
128
|
+
if (this.file === null) throw new AgentCredentialError("this store keeps no credential file");
|
|
129
|
+
return this.file;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** @jsxRuntime automatic */
|
|
2
|
+
/** @jsxImportSource react */
|
|
3
|
+
import { Box, render as inkRender } from "ink";
|
|
4
|
+
import React, { useEffect } from "react";
|
|
5
|
+
import { SelectMenu, type SelectMenuItem } from "./select-menu";
|
|
6
|
+
import { WizardFooter } from "./wizard-footer";
|
|
7
|
+
import { WizardHeader } from "./wizard-header";
|
|
8
|
+
|
|
9
|
+
export interface SelectOneOptions {
|
|
10
|
+
stdin?: NodeJS.ReadStream;
|
|
11
|
+
stdout?: NodeJS.WriteStream;
|
|
12
|
+
stderr?: NodeJS.WriteStream;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface SelectOneConfig<T> {
|
|
16
|
+
title: string;
|
|
17
|
+
toItem: (value: T) => SelectMenuItem;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Raw mode turns Ctrl+C into "\x03" instead of SIGINT, so it cancels like q and escape. */
|
|
21
|
+
function parseSelectOneInput(input: string): "submit" | "cancel" | "up" | "down" | null {
|
|
22
|
+
if (input === "\r" || input === "\n") return "submit";
|
|
23
|
+
if (input === "\x1b[A" || input === "[A") return "up";
|
|
24
|
+
if (input === "\x1b[B" || input === "[B") return "down";
|
|
25
|
+
if (input === "\x1b" || input === "\x03" || input.toLowerCase() === "q") return "cancel";
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SelectOneAppProps {
|
|
30
|
+
title: string;
|
|
31
|
+
items: SelectMenuItem[];
|
|
32
|
+
activeIndex: number;
|
|
33
|
+
onMounted?: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function SelectOneApp({
|
|
37
|
+
title,
|
|
38
|
+
items,
|
|
39
|
+
activeIndex,
|
|
40
|
+
onMounted,
|
|
41
|
+
}: SelectOneAppProps): React.JSX.Element {
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
onMounted?.();
|
|
44
|
+
}, [onMounted]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Box flexDirection="column" width="100%">
|
|
48
|
+
<WizardHeader title={title} step={0} totalSteps={1} />
|
|
49
|
+
<Box marginTop={1} flexDirection="column">
|
|
50
|
+
<SelectMenu items={items} activeIndex={activeIndex} />
|
|
51
|
+
</Box>
|
|
52
|
+
<WizardFooter hint="↑↓ navigate · enter select · q cancel" />
|
|
53
|
+
</Box>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Terminal menu that picks one of `values`; null when cancelled. */
|
|
58
|
+
export async function selectOne<T>(
|
|
59
|
+
values: T[],
|
|
60
|
+
config: SelectOneConfig<T>,
|
|
61
|
+
options: SelectOneOptions = {},
|
|
62
|
+
): Promise<T | null> {
|
|
63
|
+
const stdin = options.stdin ?? process.stdin;
|
|
64
|
+
const stdout = options.stdout ?? process.stdout;
|
|
65
|
+
const stderr = options.stderr ?? process.stderr;
|
|
66
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
67
|
+
throw new Error("Select menu requires a TTY.");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const items = values.map(config.toItem);
|
|
71
|
+
let activeIndex = 0;
|
|
72
|
+
let finalResult: T | null = null;
|
|
73
|
+
let rendered: ReturnType<typeof inkRender> | undefined;
|
|
74
|
+
|
|
75
|
+
stdin.resume();
|
|
76
|
+
(stdin as NodeJS.ReadStream & { ref?: () => void }).ref?.();
|
|
77
|
+
const keepAlive = setInterval(() => {}, 1 << 30);
|
|
78
|
+
|
|
79
|
+
const cleanup = () => {
|
|
80
|
+
clearInterval(keepAlive);
|
|
81
|
+
stdin.off("data", onData);
|
|
82
|
+
stdin.pause();
|
|
83
|
+
stdin.setRawMode?.(false);
|
|
84
|
+
(stdin as NodeJS.ReadStream & { unref?: () => void }).unref?.();
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const app = () => (
|
|
88
|
+
<SelectOneApp
|
|
89
|
+
title={config.title}
|
|
90
|
+
items={items}
|
|
91
|
+
activeIndex={activeIndex}
|
|
92
|
+
onMounted={onMounted}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const onMounted = () => {
|
|
97
|
+
stdin.on("data", onData);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const onData = (chunk: string) => {
|
|
101
|
+
const action = parseSelectOneInput(chunk);
|
|
102
|
+
if (!action) return;
|
|
103
|
+
if (action === "up" || action === "down") {
|
|
104
|
+
activeIndex = (activeIndex + (action === "up" ? -1 : 1) + items.length) % items.length;
|
|
105
|
+
rendered?.rerender(app());
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// Ink resolves exit only after a stdout flush; later keys must not overwrite the choice.
|
|
109
|
+
stdin.off("data", onData);
|
|
110
|
+
finalResult = action === "submit" ? (values[activeIndex] ?? null) : null;
|
|
111
|
+
rendered?.unmount();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
stdin.setEncoding("utf8");
|
|
115
|
+
stdin.setRawMode?.(true);
|
|
116
|
+
|
|
117
|
+
rendered = inkRender(app(), { stdin, stdout, stderr });
|
|
118
|
+
return rendered
|
|
119
|
+
.waitUntilExit()
|
|
120
|
+
.then(() => finalResult)
|
|
121
|
+
.finally(cleanup);
|
|
122
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const CREDENTIAL_KINDS = ["subscription", "api-key"] as const;
|
|
2
|
+
export type CredentialKind = (typeof CREDENTIAL_KINDS)[number];
|
|
3
|
+
|
|
4
|
+
export const CREDENTIAL_KIND_LABELS: Record<CredentialKind, string> = {
|
|
5
|
+
subscription: "Claude subscription token",
|
|
6
|
+
"api-key": "Anthropic API key",
|
|
7
|
+
};
|