@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.
Files changed (240) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/package.json +5 -4
  3. package/src/cli/agent-selector.ts +16 -0
  4. package/src/cli/commands/artifact/delivery/link.ts +1 -1
  5. package/src/cli/commands/artifact/delivery/output.ts +10 -1
  6. package/src/cli/commands/artifact/delivery/resolve.ts +3 -2
  7. package/src/cli/commands/artifact/delivery/submit.ts +9 -4
  8. package/src/cli/commands/artifact/delivery/take.ts +12 -9
  9. package/src/cli/commands/artifact/finish/command.ts +16 -14
  10. package/src/cli/commands/artifact/finish/engine.ts +8 -8
  11. package/src/cli/commands/artifact/project/command.ts +2 -3
  12. package/src/cli/commands/companion/hub.ts +11 -6
  13. package/src/cli/commands/companion/link.ts +173 -46
  14. package/src/cli/commands/report/contract.ts +0 -17
  15. package/src/cli/commands/studio/access.ts +4 -0
  16. package/src/cli/commands/studio/actions.ts +35 -2
  17. package/src/cli/commands/studio/mcp-manager.ts +162 -0
  18. package/src/cli/commands/studio/routes.ts +12 -0
  19. package/src/cli/commands/studio/selection.ts +44 -11
  20. package/src/cli/commands/studio/server.ts +246 -2
  21. package/src/cli/commands/studio/services.ts +26 -0
  22. package/src/cli/commands/studio/terminal-launch.ts +21 -4
  23. package/src/cli/commands/studio/terminal.ts +3 -14
  24. package/src/cli/commands/studio/work-requests.ts +9 -0
  25. package/src/cli/commands/studio/work.ts +473 -0
  26. package/src/cli/commands/triage.ts +11 -23
  27. package/src/cli/commands/vscode/release-vsix.json +2 -2
  28. package/src/cli/commands/workflow/workflow.ts +3 -2
  29. package/src/cli/commands/working/cleanup.ts +1 -18
  30. package/src/cli/companion-link-wizard.tsx +158 -91
  31. package/src/cli/companion-selector.ts +26 -0
  32. package/src/cli/usage.ts +1 -1
  33. package/src/lib/agent-credential.ts +131 -0
  34. package/src/lib/components/select-one.tsx +122 -0
  35. package/src/lib/credential-kinds.ts +7 -0
  36. package/src/lib/delivery/merge-git.ts +16 -0
  37. package/src/lib/delivery/record-delivery.ts +12 -6
  38. package/src/lib/delivery/record.ts +5 -0
  39. package/src/lib/delivery/refresh.ts +34 -6
  40. package/src/lib/delivery/staging/refs.ts +9 -4
  41. package/src/lib/delivery/staging/submit.ts +81 -22
  42. package/src/lib/mcp-manager/resolve.ts +27 -9
  43. package/src/lib/mcp-manager/store.ts +35 -11
  44. package/src/lib/mcp-manager/types.ts +14 -0
  45. package/src/lib/mcp-manager/validate.ts +6 -10
  46. package/src/lib/opencode-server.ts +2 -17
  47. package/src/lib/orchestrator/repo-local-store.ts +14 -0
  48. package/src/lib/orchestrator/repository-link.ts +80 -52
  49. package/src/lib/orchestrator/root-context.ts +17 -1
  50. package/src/lib/studio-chat/agent.ts +139 -0
  51. package/src/lib/studio-chat/companion-context.ts +136 -0
  52. package/src/lib/studio-chat/credential.ts +79 -0
  53. package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
  54. package/src/lib/studio-chat/host-sandbox.ts +578 -0
  55. package/src/lib/studio-chat/prepare-bridges.ts +95 -0
  56. package/src/lib/studio-chat/session.ts +15 -0
  57. package/src/lib/studio-chat/turns.ts +112 -0
  58. package/src/lib/workflow/handoff.ts +1 -1
  59. package/src/lib/workflow/position.ts +29 -2
  60. package/src/lib/workset/claims.ts +85 -0
  61. package/src/lib/workset/execution.ts +71 -0
  62. package/src/lib/workset/git-transaction.ts +74 -0
  63. package/src/lib/workset/groups.ts +176 -0
  64. package/src/lib/workset/inventory.ts +196 -0
  65. package/src/lib/workset/projection.ts +237 -0
  66. package/src/lib/workset/record.ts +101 -36
  67. package/src/lib/workset/repositories.ts +24 -0
  68. package/src/lib/workset/sharing.ts +951 -0
  69. package/src/lib/workset/stages.ts +50 -14
  70. package/src/lib/workset/transactions.ts +158 -0
  71. package/src/runtime/companion-git-state.ts +1 -0
  72. package/src/runtime/companion-guidance.ts +2 -2
  73. package/src/runtime/forge-remote.ts +6 -0
  74. package/src/runtime/host-process.ts +28 -0
  75. package/src/runtime/secret-guard.ts +18 -1
  76. package/src/runtime/secret-patterns.ts +4 -3
  77. package/src/runtime/submitted-arrivals.ts +28 -2
  78. package/src/runtime/write-atomic.ts +2 -2
  79. package/src/studio.ts +52 -8
  80. package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +1 -1
  81. package/src/templates/capabilities/openspec-cap/mate-full/templates/proposal.md +1 -1
  82. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +3 -2
  83. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +5 -3
  84. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +3 -2
  85. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +5 -3
  86. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +12 -12
  87. package/src/tools/setup/capabilities/mcp-manager.ts +1 -2
  88. package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
  89. package/src/tools/setup/plugins/gitignore.ts +1 -0
  90. package/src/tools/setup/providers/claude-format.ts +1 -5
  91. package/src/tools/setup/providers/claude.ts +28 -3
  92. package/src/tools/setup/providers/opencode.ts +7 -18
  93. package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
  94. package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
  95. package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
  96. package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
  97. package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
  98. package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
  99. package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
  100. package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
  101. package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
  102. package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
  103. package/studio-dist/client/assets/{companion-view-C1F0_jbt.js → companion-view-B54_Lj0S.js} +1 -1
  104. package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
  105. package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
  106. package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
  107. package/studio-dist/client/assets/{getting-started-BN4aTpsz.js → getting-started-CAszmdDJ.js} +1 -1
  108. package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
  109. package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
  110. package/studio-dist/client/assets/{graph-canvas-Be5qgdDt.js → graph-canvas-BdNk2F9O.js} +1 -1
  111. package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
  112. package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
  113. package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
  114. package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
  115. package/studio-dist/client/assets/{markdown-view-dku7MGPn.js → markdown-view-CJ8JsLb7.js} +1 -1
  116. package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
  117. package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
  118. package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
  119. package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
  120. package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
  121. package/studio-dist/client/assets/{prepaint-BkoDSw5X.js → prepaint-sD_LlrDN.js} +1 -1
  122. package/studio-dist/client/assets/{queries-CMvC2OkU.js → queries-COL925ML.js} +1 -1
  123. package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
  124. package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
  125. package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
  126. package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
  127. package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
  128. package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
  129. package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
  130. package/studio-dist/client/assets/{specs-Bqd1ajyD.js → specs-C_tZnAvF.js} +1 -1
  131. package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
  132. package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
  133. package/studio-dist/client/assets/{store-BYnEU33C.js → store-pY9gU4uS.js} +1 -1
  134. package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
  135. package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
  136. package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
  137. package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
  138. package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
  139. package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
  140. package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
  141. package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
  142. package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
  143. package/studio-dist/client/assets/{warnings-Cnw99ugO.js → warnings-D7YY1HSG.js} +1 -1
  144. package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
  145. package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
  146. package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
  147. package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
  148. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-CS3QRY4Q.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
  149. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
  150. package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
  151. package/studio-dist/server/assets/{cn-DWFJaP_9.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
  152. package/studio-dist/server/assets/{button-Ct_WeYLc.js → button-BqA1urbl.js} +14 -7
  153. package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
  154. package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
  155. package/studio-dist/server/assets/{combobox-17vO5Uz8.js → combobox-iTjvPCtS.js} +7 -6
  156. package/studio-dist/server/assets/{companion-view-JkxnGLlp.js → companion-view-DIQ6AFIY.js} +2 -2
  157. package/studio-dist/server/assets/{companions-YNLsbnch.js → companions-aVwjRL8j.js} +1 -1
  158. package/studio-dist/server/assets/{fields-VytPpqBq.js → fields-BMap2_Ju.js} +10 -3
  159. package/studio-dist/server/assets/{friction-BW86PCPM.js → friction-BER50hoD.js} +2 -2
  160. package/studio-dist/server/assets/{friction-B6osqFSm.js → friction-BPs9KWdq.js} +8 -8
  161. package/studio-dist/server/assets/{getting-started-CFHSeX5h.js → getting-started-DGfRVmZ_.js} +2 -2
  162. package/studio-dist/server/assets/{getting-started._topic-BK2eU6AS.js → getting-started._topic-BgrBA4Vj.js} +2 -2
  163. package/studio-dist/server/assets/{getting-started.index-DZLuXnNO.js → getting-started.index-BaFfQ9Mn.js} +2 -2
  164. package/studio-dist/server/assets/{graph-BJVZBevL.js → graph-Cgzlrv3P.js} +8 -8
  165. package/studio-dist/server/assets/{graph-DGZHV-Ek.js → graph-DODpuOy_.js} +1 -1
  166. package/studio-dist/server/assets/{graph-canvas-lrNT6jbl.js → graph-canvas-DW_zU1nA.js} +2 -2
  167. package/studio-dist/server/assets/{guides-_G8Vucsk.js → guides-CA_EMG7E.js} +1 -1
  168. package/studio-dist/server/assets/{guides-CEwLOZb9.js → guides-D0SpoD32.js} +1 -1
  169. package/studio-dist/server/assets/{guides.server-ZWFKX2XJ.js → guides.server-DJjQuy03.js} +1 -1
  170. package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
  171. package/studio-dist/server/assets/{markdown-view-Bmjghg_Z.js → markdown-view-CvVBGMZV.js} +1 -1
  172. package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
  173. package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
  174. package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
  175. package/studio-dist/server/assets/{panel-DvRjyil3.js → panel-D1K6Bsux.js} +4 -32
  176. package/studio-dist/server/assets/{plugins._service._view-B32LzraG.js → plugins._service._view-DdO1nELF.js} +4 -4
  177. package/studio-dist/server/assets/{prepaint-BEHwKl51.js → prepaint-BB3dwSmz.js} +1 -1
  178. package/studio-dist/server/assets/{queries-D6Vq0AuZ.js → queries-BwiDxQy5.js} +1 -1
  179. package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
  180. package/studio-dist/server/assets/{reports-Dn92pLap.js → reports-9Pr7Bz6o.js} +7 -7
  181. package/studio-dist/server/assets/{reports-DDaH5k0H.js → reports-Cc9M3phM.js} +1 -1
  182. package/studio-dist/server/assets/{router-Bjf4S9tO.js → router-DcWe0J7Y.js} +827 -548
  183. package/studio-dist/server/assets/{routes-B4sNiE0X.js → routes-BEXxl0py.js} +8 -8
  184. package/studio-dist/server/assets/{search-DKeJRvg8.js → search-bltT7gwy.js} +39 -7
  185. package/studio-dist/server/assets/{select-CVHYL7oR.js → select-CZvHgGCi.js} +7 -6
  186. package/studio-dist/server/assets/{shell-BxbYYaAk.js → shell-BQ0vMKXN.js} +13 -4
  187. package/studio-dist/server/assets/{skills-Bj8eOgzR.js → skills-Be_52h0i.js} +1 -1
  188. package/studio-dist/server/assets/{skills-B4-0qpqN.js → skills-BpGGUl6L.js} +8 -8
  189. package/studio-dist/server/assets/{specs-rfMug6qW.js → specs-CCGgXE-V.js} +5 -5
  190. package/studio-dist/server/assets/{specs-view-qi1SE1Sl.js → specs-view-DtL5JxYM.js} +12 -11
  191. package/studio-dist/server/assets/{steps-rger6HJc.js → steps-BWFSO6dM.js} +1 -1
  192. package/studio-dist/server/assets/{store-Dg9T7oWs.js → store-X7yLPp7v.js} +1 -1
  193. package/studio-dist/server/assets/{studio-queries-CeFfmIuM.js → studio-queries-ur1ygXi3.js} +117 -13
  194. package/studio-dist/server/assets/{studio-D79JzDLc.js → studio-qzH-UETC.js} +209 -180
  195. package/studio-dist/server/assets/{usage-Dw_UQFX-.js → usage-C1o0DLzS.js} +1 -1
  196. package/studio-dist/server/assets/{usage-BJgYWRCX.js → usage-DWbSPrPD.js} +10 -9
  197. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-ciS_sEq3.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
  198. package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
  199. package/studio-dist/server/assets/{useMutation-DnWK0PhO.js → useMutation-NjlA8oFY.js} +2 -2
  200. package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
  201. package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
  202. package/studio-dist/server/assets/{vault-BzarssiL.js → vault-B_kfi1h-.js} +1 -1
  203. package/studio-dist/server/assets/{vault-CvlrLd2H.js → vault-dL79JlKH.js} +8 -115
  204. package/studio-dist/server/assets/{views-CAxwKHMK.js → views-BSGH56lb.js} +3 -3
  205. package/studio-dist/server/assets/{warnings-BpVCugHm.js → warnings-DtUVPV-k.js} +2 -2
  206. package/studio-dist/server/assets/work-D789VXGH.js +110 -0
  207. package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
  208. package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
  209. package/studio-dist/server/assets/{workflow-BdrzcCt8.js → workflow-BOZ2sRYg.js} +9 -9
  210. package/studio-dist/server/server.js +3 -3
  211. package/wrappers/bin/openspec +87 -2
  212. package/src/cli/companion-selector.tsx +0 -139
  213. package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
  214. package/studio-dist/client/assets/button-C9SQW3kI.js +0 -1
  215. package/studio-dist/client/assets/cn-DC80MJV0.js +0 -1
  216. package/studio-dist/client/assets/combobox-D7mKYCBb.js +0 -1
  217. package/studio-dist/client/assets/fields-CEep8IFT.js +0 -1
  218. package/studio-dist/client/assets/friction-D9dBU7WN.js +0 -1
  219. package/studio-dist/client/assets/getting-started-BDyGvHhc.js +0 -1
  220. package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +0 -1
  221. package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +0 -1
  222. package/studio-dist/client/assets/graph-ah7ZXfTa.js +0 -2
  223. package/studio-dist/client/assets/guides-CsL0660B.js +0 -1
  224. package/studio-dist/client/assets/index-zmRH87D4.js +0 -40
  225. package/studio-dist/client/assets/panel-COgk0vP5.js +0 -1
  226. package/studio-dist/client/assets/plugins._service._view-Cn3WBHab.js +0 -1
  227. package/studio-dist/client/assets/reports-C_AqLBYH.js +0 -1
  228. package/studio-dist/client/assets/routes-BokQmHtC.js +0 -1
  229. package/studio-dist/client/assets/search-DxidNK2M.js +0 -1
  230. package/studio-dist/client/assets/select-CYFCbHUd.js +0 -1
  231. package/studio-dist/client/assets/skills-R3vttWHM.js +0 -1
  232. package/studio-dist/client/assets/specs-view-znqFPx9p.js +0 -1
  233. package/studio-dist/client/assets/steps-tVDWn7j6.js +0 -1
  234. package/studio-dist/client/assets/studio-ndtFcS2Y.js +0 -100
  235. package/studio-dist/client/assets/studio-queries-CkUSByy7.js +0 -2
  236. package/studio-dist/client/assets/usage-Kuhr8dSl.js +0 -55
  237. package/studio-dist/client/assets/useAnchoredPopupScrollLock-dc_kP4Go.js +0 -1
  238. package/studio-dist/client/assets/useMutation-CqtM9COw.js +0 -1
  239. package/studio-dist/client/assets/vault-CSP8kwRg.js +0 -1
  240. 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 SourceStep {
35
+ interface SelectStep {
25
36
  kind: "select";
26
- field: "source";
37
+ field: "source" | "clonePath" | "replace";
27
38
  label: string;
28
- options: Array<{ key: CompanionSource; label: string }>;
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 = SourceStep | CompanionMultiSelectStep | TextStep;
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
- key: option,
81
- label: option,
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?: string[];
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
- source: CompanionSource,
117
- values: {
118
- gitUrl: string;
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 sourceOptions: SourceStep["options"] = [
126
- { key: "git", label: "git" },
163
+ const { existingCompanions, clonesOf, replacedBy } = options;
164
+ const sourceOptions: SelectStep["options"] = [
127
165
  ...(existingCompanions.length > 0
128
- ? [{ key: "existing" as const, label: "existing companion" }]
166
+ ? [{ key: "existing", label: "Use a companion already on this machine" }]
129
167
  : []),
130
- { key: "local", label: "local" },
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 sourceSpecificStep: TextStep | CompanionMultiSelectStep =
144
- source === "git"
145
- ? {
146
- kind: "text",
147
- field: "gitUrl",
148
- label: "Companion Git URL",
149
- value: values.gitUrl,
150
- }
151
- : source === "local"
152
- ? {
153
- kind: "text",
154
- field: "localPath",
155
- label: "Local Companion Path",
156
- value: values.localPath,
157
- }
158
- : {
159
- kind: "multiselect",
160
- field: "companionPaths",
161
- label: "Existing Companions",
162
- options: existingCompanions,
163
- activeIndex: values.companionActiveIndex,
164
- selected: values.companionPaths,
165
- };
166
-
167
- return [sourceStep, sourceSpecificStep];
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
- let source: CompanionSource = "git";
181
- const values = {
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(source, values, existingCompanions);
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
- const rebuildSteps = () => {
226
- steps = buildSteps(source, values, existingCompanions);
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
- source = step.options[step.activeIndex]!.key;
309
- rebuildSteps();
310
- if (currentStepIndex < steps.length - 1) {
311
- currentStepIndex++;
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, to revise it`,
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
+ };