@uniqbit/mate-core 1.0.0-canary.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) 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/commands/artifact/delivery/link.ts +1 -1
  4. package/src/cli/commands/artifact/delivery/output.ts +10 -1
  5. package/src/cli/commands/artifact/delivery/resolve.ts +3 -2
  6. package/src/cli/commands/artifact/delivery/submit.ts +9 -4
  7. package/src/cli/commands/artifact/delivery/take.ts +12 -9
  8. package/src/cli/commands/artifact/finish/command.ts +16 -14
  9. package/src/cli/commands/artifact/finish/engine.ts +8 -8
  10. package/src/cli/commands/artifact/project/command.ts +2 -3
  11. package/src/cli/commands/companion/hub.ts +11 -6
  12. package/src/cli/commands/companion/link.ts +173 -46
  13. package/src/cli/commands/doctor.ts +17 -0
  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/vscode/release-vsix.json +2 -2
  27. package/src/cli/commands/working/cleanup.ts +1 -18
  28. package/src/cli/companion-link-wizard.tsx +158 -91
  29. package/src/cli/usage.ts +1 -1
  30. package/src/create-mate.ts +4 -1
  31. package/src/lib/agent-credential.ts +131 -0
  32. package/src/lib/credential-kinds.ts +7 -0
  33. package/src/lib/delivery/merge-git.ts +16 -0
  34. package/src/lib/delivery/record-delivery.ts +12 -6
  35. package/src/lib/delivery/record.ts +5 -0
  36. package/src/lib/delivery/refresh.ts +34 -6
  37. package/src/lib/delivery/staging/refs.ts +9 -4
  38. package/src/lib/delivery/staging/submit.ts +81 -22
  39. package/src/lib/mcp-manager/resolve.ts +88 -0
  40. package/src/lib/mcp-manager/store.ts +133 -0
  41. package/src/lib/mcp-manager/types.ts +72 -0
  42. package/src/lib/mcp-manager/validate.ts +242 -0
  43. package/src/lib/opencode-server.ts +2 -17
  44. package/src/lib/orchestrator/config-store.ts +30 -7
  45. package/src/lib/orchestrator/engine-floor.ts +16 -4
  46. package/src/lib/orchestrator/engine-guard.ts +7 -1
  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/orchestrator/types.ts +4 -0
  51. package/src/lib/studio-chat/agent.ts +139 -0
  52. package/src/lib/studio-chat/companion-context.ts +136 -0
  53. package/src/lib/studio-chat/credential.ts +79 -0
  54. package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
  55. package/src/lib/studio-chat/host-sandbox.ts +578 -0
  56. package/src/lib/studio-chat/prepare-bridges.ts +95 -0
  57. package/src/lib/studio-chat/session.ts +15 -0
  58. package/src/lib/studio-chat/turns.ts +112 -0
  59. package/src/lib/workset/claims.ts +85 -0
  60. package/src/lib/workset/execution.ts +71 -0
  61. package/src/lib/workset/git-transaction.ts +74 -0
  62. package/src/lib/workset/groups.ts +176 -0
  63. package/src/lib/workset/inventory.ts +196 -0
  64. package/src/lib/workset/projection.ts +237 -0
  65. package/src/lib/workset/record.ts +101 -36
  66. package/src/lib/workset/repositories.ts +24 -0
  67. package/src/lib/workset/sharing.ts +951 -0
  68. package/src/lib/workset/stages.ts +50 -14
  69. package/src/lib/workset/transactions.ts +158 -0
  70. package/src/runtime/companion-git-state.ts +1 -0
  71. package/src/runtime/companion-guidance.ts +2 -2
  72. package/src/runtime/forge-remote.ts +6 -0
  73. package/src/runtime/host-process.ts +28 -0
  74. package/src/runtime/secret-guard.ts +18 -1
  75. package/src/runtime/secret-patterns.ts +4 -3
  76. package/src/runtime/submitted-arrivals.ts +28 -2
  77. package/src/runtime/workflow/turn.ts +14 -12
  78. package/src/runtime/write-atomic.ts +2 -2
  79. package/src/studio.ts +61 -0
  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 +73 -0
  88. package/src/tools/setup/context-services.ts +35 -6
  89. package/src/tools/setup/dynamic-plugins/audiences.ts +3 -2
  90. package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
  91. package/src/tools/setup/engine.ts +55 -3
  92. package/src/tools/setup/plugin.ts +14 -0
  93. package/src/tools/setup/plugins/gitignore.ts +1 -0
  94. package/src/tools/setup/providers/claude-format.ts +40 -7
  95. package/src/tools/setup/providers/claude.ts +38 -3
  96. package/src/tools/setup/providers/opencode-format.ts +13 -3
  97. package/src/tools/setup/providers/opencode.ts +7 -18
  98. package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
  99. package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
  100. package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
  101. package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
  102. package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
  103. package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
  104. package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
  105. package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
  106. package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
  107. package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
  108. package/studio-dist/client/assets/{companion-view-C_N237bf.js → companion-view-B54_Lj0S.js} +1 -1
  109. package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
  110. package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
  111. package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
  112. package/studio-dist/client/assets/{getting-started-djaQeWlu.js → getting-started-CAszmdDJ.js} +1 -1
  113. package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
  114. package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
  115. package/studio-dist/client/assets/{graph-canvas-ySGKMhmk.js → graph-canvas-BdNk2F9O.js} +1 -1
  116. package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
  117. package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
  118. package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
  119. package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
  120. package/studio-dist/client/assets/{markdown-view-jMiaBTSO.js → markdown-view-CJ8JsLb7.js} +1 -1
  121. package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
  122. package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
  123. package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
  124. package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
  125. package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
  126. package/studio-dist/client/assets/{prepaint-CKsXyJOR.js → prepaint-sD_LlrDN.js} +1 -1
  127. package/studio-dist/client/assets/{queries-Dfp5deWj.js → queries-COL925ML.js} +1 -1
  128. package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
  129. package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
  130. package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
  131. package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
  132. package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
  133. package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
  134. package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
  135. package/studio-dist/client/assets/{specs-BrCOjOch.js → specs-C_tZnAvF.js} +1 -1
  136. package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
  137. package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
  138. package/studio-dist/client/assets/{store-C3vJq8Wj.js → store-pY9gU4uS.js} +1 -1
  139. package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
  140. package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
  141. package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
  142. package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
  143. package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
  144. package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
  145. package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
  146. package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
  147. package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
  148. package/studio-dist/client/assets/{warnings-CqOOGlPD.js → warnings-D7YY1HSG.js} +1 -1
  149. package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
  150. package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
  151. package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
  152. package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
  153. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-gVfW5vIV.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
  154. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
  155. package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
  156. package/studio-dist/server/assets/{cn-FXJAM0KO.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
  157. package/studio-dist/server/assets/{button-D6bvrFmm.js → button-BqA1urbl.js} +14 -7
  158. package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
  159. package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
  160. package/studio-dist/server/assets/{combobox-D2MbYV1O.js → combobox-iTjvPCtS.js} +7 -6
  161. package/studio-dist/server/assets/{companion-view-Mf1ANbMb.js → companion-view-DIQ6AFIY.js} +2 -2
  162. package/studio-dist/server/assets/{companions-Dr6IpNAb.js → companions-aVwjRL8j.js} +1 -1
  163. package/studio-dist/server/assets/{fields-B4mAPETz.js → fields-BMap2_Ju.js} +10 -3
  164. package/studio-dist/server/assets/{friction-CWOTjpCV.js → friction-BER50hoD.js} +2 -2
  165. package/studio-dist/server/assets/{friction-9a5S1m7U.js → friction-BPs9KWdq.js} +8 -8
  166. package/studio-dist/server/assets/{getting-started-RU6tYU2Q.js → getting-started-DGfRVmZ_.js} +2 -2
  167. package/studio-dist/server/assets/{getting-started._topic-C02HGrC6.js → getting-started._topic-BgrBA4Vj.js} +2 -2
  168. package/studio-dist/server/assets/{getting-started.index-EzLRosbb.js → getting-started.index-BaFfQ9Mn.js} +2 -2
  169. package/studio-dist/server/assets/{graph-CZ2H9Fzr.js → graph-Cgzlrv3P.js} +8 -8
  170. package/studio-dist/server/assets/{graph-B11ITte0.js → graph-DODpuOy_.js} +1 -1
  171. package/studio-dist/server/assets/{graph-canvas-rP5TT14Z.js → graph-canvas-DW_zU1nA.js} +2 -2
  172. package/studio-dist/server/assets/{guides-BGftp4wf.js → guides-CA_EMG7E.js} +1 -1
  173. package/studio-dist/server/assets/{guides-B8HdeK_C.js → guides-D0SpoD32.js} +1 -1
  174. package/studio-dist/server/assets/{guides.server-DqFQAStf.js → guides.server-DJjQuy03.js} +1 -1
  175. package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
  176. package/studio-dist/server/assets/{markdown-view-CArpV-CS.js → markdown-view-CvVBGMZV.js} +1 -1
  177. package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
  178. package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
  179. package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
  180. package/studio-dist/server/assets/{panel-DR0iq46J.js → panel-D1K6Bsux.js} +4 -32
  181. package/studio-dist/server/assets/{plugins._service._view-n7u2k5dF.js → plugins._service._view-DdO1nELF.js} +4 -4
  182. package/studio-dist/server/assets/{prepaint-B28ClcPN.js → prepaint-BB3dwSmz.js} +1 -1
  183. package/studio-dist/server/assets/{queries-D-yVP9i0.js → queries-BwiDxQy5.js} +1 -1
  184. package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
  185. package/studio-dist/server/assets/{reports-C2SmTgqh.js → reports-9Pr7Bz6o.js} +7 -7
  186. package/studio-dist/server/assets/{reports-B9k98oE6.js → reports-Cc9M3phM.js} +1 -1
  187. package/studio-dist/server/assets/{router-CPt0TAk_.js → router-DcWe0J7Y.js} +827 -548
  188. package/studio-dist/server/assets/{routes-CwH8LEy2.js → routes-BEXxl0py.js} +8 -8
  189. package/studio-dist/server/assets/{search-b-yQesv3.js → search-bltT7gwy.js} +39 -7
  190. package/studio-dist/server/assets/{select-C3i6TTX-.js → select-CZvHgGCi.js} +7 -6
  191. package/studio-dist/server/assets/{shell-CagqZZMZ.js → shell-BQ0vMKXN.js} +13 -4
  192. package/studio-dist/server/assets/{skills-DGg0mWDM.js → skills-Be_52h0i.js} +1 -1
  193. package/studio-dist/server/assets/{skills-C21Mg_8-.js → skills-BpGGUl6L.js} +8 -8
  194. package/studio-dist/server/assets/{specs-DetoMiaB.js → specs-CCGgXE-V.js} +5 -5
  195. package/studio-dist/server/assets/{specs-view-CmbfLDwN.js → specs-view-DtL5JxYM.js} +12 -11
  196. package/studio-dist/server/assets/{steps-D1tYAyWZ.js → steps-BWFSO6dM.js} +1 -1
  197. package/studio-dist/server/assets/{store-aC-I6f6o.js → store-X7yLPp7v.js} +1 -1
  198. package/studio-dist/server/assets/{studio-queries-Dqf-3nzj.js → studio-queries-ur1ygXi3.js} +117 -13
  199. package/studio-dist/server/assets/{studio-qRvQjRpz.js → studio-qzH-UETC.js} +1555 -179
  200. package/studio-dist/server/assets/{usage-Cwle9-xY.js → usage-C1o0DLzS.js} +1 -1
  201. package/studio-dist/server/assets/{usage-CS4CBK9D.js → usage-DWbSPrPD.js} +10 -9
  202. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-BjMNgXv9.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
  203. package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
  204. package/studio-dist/server/assets/{useMutation-DpBIuWXt.js → useMutation-NjlA8oFY.js} +2 -2
  205. package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
  206. package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
  207. package/studio-dist/server/assets/{vault-CEBBRLMb.js → vault-B_kfi1h-.js} +1 -1
  208. package/studio-dist/server/assets/{vault-DVQidlId.js → vault-dL79JlKH.js} +8 -115
  209. package/studio-dist/server/assets/{views-UgO0Qz_g.js → views-BSGH56lb.js} +3 -3
  210. package/studio-dist/server/assets/{warnings-C7hgXpdk.js → warnings-DtUVPV-k.js} +2 -2
  211. package/studio-dist/server/assets/work-D789VXGH.js +110 -0
  212. package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
  213. package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
  214. package/studio-dist/server/assets/{workflow-6dZZ1ofw.js → workflow-BOZ2sRYg.js} +9 -9
  215. package/studio-dist/server/server.js +3 -3
  216. package/wrappers/bin/openspec +87 -2
  217. package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
  218. package/studio-dist/client/assets/button-amJ3g5oD.js +0 -1
  219. package/studio-dist/client/assets/cn-BQPKiwI4.js +0 -1
  220. package/studio-dist/client/assets/combobox-CJ7aGFid.js +0 -1
  221. package/studio-dist/client/assets/fields-BAiGkJ5N.js +0 -1
  222. package/studio-dist/client/assets/friction-DqOU59v7.js +0 -1
  223. package/studio-dist/client/assets/getting-started-yp42dj5S.js +0 -1
  224. package/studio-dist/client/assets/getting-started._topic-C9zVXz_m.js +0 -1
  225. package/studio-dist/client/assets/getting-started.index-DWbDKICP.js +0 -1
  226. package/studio-dist/client/assets/graph-BYaD_5Bq.js +0 -2
  227. package/studio-dist/client/assets/guides-D6T6W_jV.js +0 -1
  228. package/studio-dist/client/assets/index-Qx7reRPD.js +0 -40
  229. package/studio-dist/client/assets/panel-C4bf_h2W.js +0 -1
  230. package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +0 -1
  231. package/studio-dist/client/assets/reports-JFSwSueq.js +0 -1
  232. package/studio-dist/client/assets/routes-BdOWSgzK.js +0 -1
  233. package/studio-dist/client/assets/search-CXosfvYh.js +0 -1
  234. package/studio-dist/client/assets/select-BHYYWPhK.js +0 -1
  235. package/studio-dist/client/assets/skills-Bo9FLsBd.js +0 -1
  236. package/studio-dist/client/assets/specs-view-CdE2rlli.js +0 -1
  237. package/studio-dist/client/assets/steps-CKUno4lh.js +0 -1
  238. package/studio-dist/client/assets/studio-0ueISxwP.js +0 -100
  239. package/studio-dist/client/assets/studio-queries-BflKt9va.js +0 -2
  240. package/studio-dist/client/assets/usage-BLsLy0nN.js +0 -55
  241. package/studio-dist/client/assets/useAnchoredPopupScrollLock-DC7f8GOp.js +0 -1
  242. package/studio-dist/client/assets/useMutation-uJUrejsi.js +0 -1
  243. package/studio-dist/client/assets/vault-BB1B_OhR.js +0 -1
  244. package/studio-dist/client/assets/workflow-BFzmI-06.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 = () => {
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",
@@ -3,6 +3,7 @@ import { setActiveDistribution, type DistributionConfig } from "./distribution";
3
3
  import { FRAMEWORK_NAME } from "./framework";
4
4
  import { currentSession } from "./lib/session-attribution";
5
5
  import { runRecordingFailure } from "./runtime/command-friction";
6
+ import { createMcpManagerPlugin } from "./tools/setup/capabilities/mcp-manager";
6
7
  import { createBunPlugin } from "./tools/setup/package-managers/bun";
7
8
  import { createUvPlugin } from "./tools/setup/package-managers/uv";
8
9
  import type { PluginRegistration } from "./tools/setup/plugin";
@@ -26,7 +27,8 @@ export interface MateCli {
26
27
  * Assemble a distribution from an identity config and plugin registration
27
28
  * entries. Distributions choose their plugin set; the framework always adds
28
29
  * bun as the required runtime substrate, uv for the capabilities that install
29
- * through it (enabled only by them, e.g. Graphify), plus gitignore management
30
+ * through it (enabled only by them, e.g. Graphify), the `mcp-manager`
31
+ * Capability (enabled by a `mcpManager` section), plus gitignore management
30
32
  * named after the framework identity (built last since it reads the full
31
33
  * plugin set). Returns the runnable CLI.
32
34
  */
@@ -35,6 +37,7 @@ export function createMate({ config, plugins, main: runMain = main }: CreateMate
35
37
  ...plugins,
36
38
  { plugin: createBunPlugin(), policy: "required" },
37
39
  { plugin: createUvPlugin(), policy: "optional" },
40
+ createMcpManagerPlugin(),
38
41
  createGitignorePlugin(FRAMEWORK_NAME),
39
42
  ]);
40
43
  setActiveDistribution({ config, registry });
@@ -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,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
+ };
@@ -48,6 +48,8 @@ export interface FetchResult {
48
48
  message?: string;
49
49
  /** The delivery branch no longer exists on `origin`. */
50
50
  branchDeleted?: boolean;
51
+ /** The delivery branch is missing on `origin` because its head was never pushed. */
52
+ branchUnpushed?: boolean;
51
53
  }
52
54
 
53
55
  /** The first default-branch commit holding a delivery's content. */
@@ -102,6 +104,11 @@ export interface MergeGit {
102
104
  * False when a merge commit brought it in; null when Git could not tell.
103
105
  */
104
106
  onFirstParent(commit: string, defaultBranch: string): Promise<boolean | null>;
107
+ /**
108
+ * True when every entry of the local branch's reflog is `head`: the branch never moved since
109
+ * it was created there. False when one differs; null without a reflog or when Git fails.
110
+ */
111
+ neverAdvanced(branch: string, head: string): Promise<boolean | null>;
105
112
  /**
106
113
  * The commit on `origin/<defaultBranch>` that carries the delivery's changes by patch
107
114
  * identity: every branch commit (rebase), else the whole branch diff (squash). Null in a
@@ -381,6 +388,15 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
381
388
  const parent = await value("rev-parse", `${oldest}^1`);
382
389
  return parent ? parent === commit : null;
383
390
  },
391
+ async neverAdvanced(branch, head) {
392
+ const reflog = await git(["reflog", "show", "--format=%H", `refs/heads/${branch}`, "--"]);
393
+ if (reflog.code !== 0) return null;
394
+ const entries = reflog.stdout
395
+ .split("\n")
396
+ .map((entry) => entry.trim())
397
+ .filter(Boolean);
398
+ return entries.length > 0 ? entries.every((entry) => entry === head) : null;
399
+ },
384
400
  async patchMatch(head, defaultBranch) {
385
401
  if (await isPartialClone()) return null;
386
402
  const upstream = remoteRef(defaultBranch);
@@ -90,8 +90,9 @@ export interface DeliveryRequest {
90
90
  /** Resolve and refuse as usual, but write nothing. */
91
91
  dryRun?: boolean;
92
92
  /**
93
- * With `refresh`: refuse when Git settles a delivery as merged while a work tree that has its
94
- * branch checked out holds modified tracked files, since that work is on no commit.
93
+ * With `refresh`: refuse a delivery branch without commits of its own, and one Git settles or
94
+ * suggests as merged while a work tree that has it checked out holds modified tracked files,
95
+ * since that work is on no commit.
95
96
  */
96
97
  refuseUncommitted?: boolean;
97
98
  }
@@ -116,6 +117,8 @@ export type DeliveryRefusal =
116
117
  branch: string;
117
118
  worktree: string;
118
119
  }
120
+ /** `refuseUncommitted`: the delivery branch has no commits of its own, so it delivers nothing. */
121
+ | { reason: "empty-delivery-branch"; change: string; repository: string; branch: string }
119
122
  | {
120
123
  reason: "no-delivery-branch";
121
124
  change: string;
@@ -424,11 +427,14 @@ export async function recordDelivery(
424
427
  record = refreshed.record;
425
428
  outcomes = refreshed.outcomes;
426
429
  for (const outcome of request.refuseUncommitted ? outcomes : []) {
427
- if (outcome.result !== "merged") continue;
428
- const local = await access(outcome.repository).local?.();
429
- const worktree = await local?.git.dirtyWorktree(outcome.branch);
430
+ const { repository: repo, branch } = outcome;
431
+ if (outcome.answerReason === "empty-branch") {
432
+ return { refusal: { reason: "empty-delivery-branch", change, repository: repo, branch } };
433
+ }
434
+ if (outcome.result !== "merged" && outcome.answerReason !== "likely-merged") continue;
435
+ const local = await access(repo).local?.();
436
+ const worktree = await local?.git.dirtyWorktree(branch);
430
437
  if (worktree) {
431
- const { repository: repo, branch } = outcome;
432
438
  return {
433
439
  refusal: { reason: "uncommitted-work", change, repository: repo, branch, worktree },
434
440
  };
@@ -66,6 +66,11 @@ export type SubmissionState = "active" | "submitted" | "dropped";
66
66
 
67
67
  const SUBMISSION_STATES: readonly SubmissionState[] = ["active", "submitted", "dropped"];
68
68
 
69
+ export function submissionStateOf(text: string | null): SubmissionState {
70
+ const state = text ? /^state:\s*["']?(\w+)["']?\s*(?:#.*)?$/m.exec(text)?.[1] : undefined;
71
+ return state === "submitted" || state === "dropped" ? state : "active";
72
+ }
73
+
69
74
  /** Why the change's Delivery Group could not publish; cleared by resubmit, resolution or publication. */
70
75
  export interface DeliveryBlock {
71
76
  reason: string;