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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) 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/report/contract.ts +0 -17
  14. package/src/cli/commands/studio/access.ts +4 -0
  15. package/src/cli/commands/studio/actions.ts +35 -2
  16. package/src/cli/commands/studio/mcp-manager.ts +162 -0
  17. package/src/cli/commands/studio/routes.ts +12 -0
  18. package/src/cli/commands/studio/selection.ts +44 -11
  19. package/src/cli/commands/studio/server.ts +246 -2
  20. package/src/cli/commands/studio/services.ts +26 -0
  21. package/src/cli/commands/studio/terminal-launch.ts +21 -4
  22. package/src/cli/commands/studio/terminal.ts +3 -14
  23. package/src/cli/commands/studio/work-requests.ts +9 -0
  24. package/src/cli/commands/studio/work.ts +473 -0
  25. package/src/cli/commands/vscode/release-vsix.json +2 -2
  26. package/src/cli/commands/working/cleanup.ts +1 -18
  27. package/src/cli/companion-link-wizard.tsx +158 -91
  28. package/src/cli/usage.ts +1 -1
  29. package/src/lib/agent-credential.ts +131 -0
  30. package/src/lib/credential-kinds.ts +7 -0
  31. package/src/lib/delivery/merge-git.ts +16 -0
  32. package/src/lib/delivery/record-delivery.ts +12 -6
  33. package/src/lib/delivery/record.ts +5 -0
  34. package/src/lib/delivery/refresh.ts +34 -6
  35. package/src/lib/delivery/staging/refs.ts +9 -4
  36. package/src/lib/delivery/staging/submit.ts +81 -22
  37. package/src/lib/mcp-manager/resolve.ts +27 -9
  38. package/src/lib/mcp-manager/store.ts +35 -11
  39. package/src/lib/mcp-manager/types.ts +14 -0
  40. package/src/lib/mcp-manager/validate.ts +6 -10
  41. package/src/lib/opencode-server.ts +2 -17
  42. package/src/lib/orchestrator/repo-local-store.ts +14 -0
  43. package/src/lib/orchestrator/repository-link.ts +80 -52
  44. package/src/lib/orchestrator/root-context.ts +17 -1
  45. package/src/lib/studio-chat/agent.ts +139 -0
  46. package/src/lib/studio-chat/companion-context.ts +136 -0
  47. package/src/lib/studio-chat/credential.ts +79 -0
  48. package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
  49. package/src/lib/studio-chat/host-sandbox.ts +578 -0
  50. package/src/lib/studio-chat/prepare-bridges.ts +95 -0
  51. package/src/lib/studio-chat/session.ts +15 -0
  52. package/src/lib/studio-chat/turns.ts +112 -0
  53. package/src/lib/workset/claims.ts +85 -0
  54. package/src/lib/workset/execution.ts +71 -0
  55. package/src/lib/workset/git-transaction.ts +74 -0
  56. package/src/lib/workset/groups.ts +176 -0
  57. package/src/lib/workset/inventory.ts +196 -0
  58. package/src/lib/workset/projection.ts +237 -0
  59. package/src/lib/workset/record.ts +101 -36
  60. package/src/lib/workset/repositories.ts +24 -0
  61. package/src/lib/workset/sharing.ts +951 -0
  62. package/src/lib/workset/stages.ts +50 -14
  63. package/src/lib/workset/transactions.ts +158 -0
  64. package/src/runtime/companion-git-state.ts +1 -0
  65. package/src/runtime/companion-guidance.ts +2 -2
  66. package/src/runtime/forge-remote.ts +6 -0
  67. package/src/runtime/host-process.ts +28 -0
  68. package/src/runtime/secret-guard.ts +18 -1
  69. package/src/runtime/secret-patterns.ts +4 -3
  70. package/src/runtime/submitted-arrivals.ts +28 -2
  71. package/src/runtime/write-atomic.ts +2 -2
  72. package/src/studio.ts +52 -8
  73. package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +1 -1
  74. package/src/templates/capabilities/openspec-cap/mate-full/templates/proposal.md +1 -1
  75. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +3 -2
  76. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +5 -3
  77. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +3 -2
  78. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +5 -3
  79. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +12 -12
  80. package/src/tools/setup/capabilities/mcp-manager.ts +1 -2
  81. package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
  82. package/src/tools/setup/plugins/gitignore.ts +1 -0
  83. package/src/tools/setup/providers/claude-format.ts +1 -5
  84. package/src/tools/setup/providers/claude.ts +28 -3
  85. package/src/tools/setup/providers/opencode.ts +7 -18
  86. package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
  87. package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
  88. package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
  89. package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
  90. package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
  91. package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
  92. package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
  93. package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
  94. package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
  95. package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
  96. package/studio-dist/client/assets/{companion-view-C1F0_jbt.js → companion-view-B54_Lj0S.js} +1 -1
  97. package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
  98. package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
  99. package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
  100. package/studio-dist/client/assets/{getting-started-BN4aTpsz.js → getting-started-CAszmdDJ.js} +1 -1
  101. package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
  102. package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
  103. package/studio-dist/client/assets/{graph-canvas-Be5qgdDt.js → graph-canvas-BdNk2F9O.js} +1 -1
  104. package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
  105. package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
  106. package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
  107. package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
  108. package/studio-dist/client/assets/{markdown-view-dku7MGPn.js → markdown-view-CJ8JsLb7.js} +1 -1
  109. package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
  110. package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
  111. package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
  112. package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
  113. package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
  114. package/studio-dist/client/assets/{prepaint-BkoDSw5X.js → prepaint-sD_LlrDN.js} +1 -1
  115. package/studio-dist/client/assets/{queries-CMvC2OkU.js → queries-COL925ML.js} +1 -1
  116. package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
  117. package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
  118. package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
  119. package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
  120. package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
  121. package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
  122. package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
  123. package/studio-dist/client/assets/{specs-Bqd1ajyD.js → specs-C_tZnAvF.js} +1 -1
  124. package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
  125. package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
  126. package/studio-dist/client/assets/{store-BYnEU33C.js → store-pY9gU4uS.js} +1 -1
  127. package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
  128. package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
  129. package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
  130. package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
  131. package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
  132. package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
  133. package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
  134. package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
  135. package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
  136. package/studio-dist/client/assets/{warnings-Cnw99ugO.js → warnings-D7YY1HSG.js} +1 -1
  137. package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
  138. package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
  139. package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
  140. package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
  141. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-CS3QRY4Q.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
  142. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
  143. package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
  144. package/studio-dist/server/assets/{cn-DWFJaP_9.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
  145. package/studio-dist/server/assets/{button-Ct_WeYLc.js → button-BqA1urbl.js} +14 -7
  146. package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
  147. package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
  148. package/studio-dist/server/assets/{combobox-17vO5Uz8.js → combobox-iTjvPCtS.js} +7 -6
  149. package/studio-dist/server/assets/{companion-view-JkxnGLlp.js → companion-view-DIQ6AFIY.js} +2 -2
  150. package/studio-dist/server/assets/{companions-YNLsbnch.js → companions-aVwjRL8j.js} +1 -1
  151. package/studio-dist/server/assets/{fields-VytPpqBq.js → fields-BMap2_Ju.js} +10 -3
  152. package/studio-dist/server/assets/{friction-BW86PCPM.js → friction-BER50hoD.js} +2 -2
  153. package/studio-dist/server/assets/{friction-B6osqFSm.js → friction-BPs9KWdq.js} +8 -8
  154. package/studio-dist/server/assets/{getting-started-CFHSeX5h.js → getting-started-DGfRVmZ_.js} +2 -2
  155. package/studio-dist/server/assets/{getting-started._topic-BK2eU6AS.js → getting-started._topic-BgrBA4Vj.js} +2 -2
  156. package/studio-dist/server/assets/{getting-started.index-DZLuXnNO.js → getting-started.index-BaFfQ9Mn.js} +2 -2
  157. package/studio-dist/server/assets/{graph-BJVZBevL.js → graph-Cgzlrv3P.js} +8 -8
  158. package/studio-dist/server/assets/{graph-DGZHV-Ek.js → graph-DODpuOy_.js} +1 -1
  159. package/studio-dist/server/assets/{graph-canvas-lrNT6jbl.js → graph-canvas-DW_zU1nA.js} +2 -2
  160. package/studio-dist/server/assets/{guides-_G8Vucsk.js → guides-CA_EMG7E.js} +1 -1
  161. package/studio-dist/server/assets/{guides-CEwLOZb9.js → guides-D0SpoD32.js} +1 -1
  162. package/studio-dist/server/assets/{guides.server-ZWFKX2XJ.js → guides.server-DJjQuy03.js} +1 -1
  163. package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
  164. package/studio-dist/server/assets/{markdown-view-Bmjghg_Z.js → markdown-view-CvVBGMZV.js} +1 -1
  165. package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
  166. package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
  167. package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
  168. package/studio-dist/server/assets/{panel-DvRjyil3.js → panel-D1K6Bsux.js} +4 -32
  169. package/studio-dist/server/assets/{plugins._service._view-B32LzraG.js → plugins._service._view-DdO1nELF.js} +4 -4
  170. package/studio-dist/server/assets/{prepaint-BEHwKl51.js → prepaint-BB3dwSmz.js} +1 -1
  171. package/studio-dist/server/assets/{queries-D6Vq0AuZ.js → queries-BwiDxQy5.js} +1 -1
  172. package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
  173. package/studio-dist/server/assets/{reports-Dn92pLap.js → reports-9Pr7Bz6o.js} +7 -7
  174. package/studio-dist/server/assets/{reports-DDaH5k0H.js → reports-Cc9M3phM.js} +1 -1
  175. package/studio-dist/server/assets/{router-Bjf4S9tO.js → router-DcWe0J7Y.js} +827 -548
  176. package/studio-dist/server/assets/{routes-B4sNiE0X.js → routes-BEXxl0py.js} +8 -8
  177. package/studio-dist/server/assets/{search-DKeJRvg8.js → search-bltT7gwy.js} +39 -7
  178. package/studio-dist/server/assets/{select-CVHYL7oR.js → select-CZvHgGCi.js} +7 -6
  179. package/studio-dist/server/assets/{shell-BxbYYaAk.js → shell-BQ0vMKXN.js} +13 -4
  180. package/studio-dist/server/assets/{skills-Bj8eOgzR.js → skills-Be_52h0i.js} +1 -1
  181. package/studio-dist/server/assets/{skills-B4-0qpqN.js → skills-BpGGUl6L.js} +8 -8
  182. package/studio-dist/server/assets/{specs-rfMug6qW.js → specs-CCGgXE-V.js} +5 -5
  183. package/studio-dist/server/assets/{specs-view-qi1SE1Sl.js → specs-view-DtL5JxYM.js} +12 -11
  184. package/studio-dist/server/assets/{steps-rger6HJc.js → steps-BWFSO6dM.js} +1 -1
  185. package/studio-dist/server/assets/{store-Dg9T7oWs.js → store-X7yLPp7v.js} +1 -1
  186. package/studio-dist/server/assets/{studio-queries-CeFfmIuM.js → studio-queries-ur1ygXi3.js} +117 -13
  187. package/studio-dist/server/assets/{studio-D79JzDLc.js → studio-qzH-UETC.js} +209 -180
  188. package/studio-dist/server/assets/{usage-Dw_UQFX-.js → usage-C1o0DLzS.js} +1 -1
  189. package/studio-dist/server/assets/{usage-BJgYWRCX.js → usage-DWbSPrPD.js} +10 -9
  190. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-ciS_sEq3.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
  191. package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
  192. package/studio-dist/server/assets/{useMutation-DnWK0PhO.js → useMutation-NjlA8oFY.js} +2 -2
  193. package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
  194. package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
  195. package/studio-dist/server/assets/{vault-BzarssiL.js → vault-B_kfi1h-.js} +1 -1
  196. package/studio-dist/server/assets/{vault-CvlrLd2H.js → vault-dL79JlKH.js} +8 -115
  197. package/studio-dist/server/assets/{views-CAxwKHMK.js → views-BSGH56lb.js} +3 -3
  198. package/studio-dist/server/assets/{warnings-BpVCugHm.js → warnings-DtUVPV-k.js} +2 -2
  199. package/studio-dist/server/assets/work-D789VXGH.js +110 -0
  200. package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
  201. package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
  202. package/studio-dist/server/assets/{workflow-BdrzcCt8.js → workflow-BOZ2sRYg.js} +9 -9
  203. package/studio-dist/server/server.js +3 -3
  204. package/wrappers/bin/openspec +87 -2
  205. package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
  206. package/studio-dist/client/assets/button-C9SQW3kI.js +0 -1
  207. package/studio-dist/client/assets/cn-DC80MJV0.js +0 -1
  208. package/studio-dist/client/assets/combobox-D7mKYCBb.js +0 -1
  209. package/studio-dist/client/assets/fields-CEep8IFT.js +0 -1
  210. package/studio-dist/client/assets/friction-D9dBU7WN.js +0 -1
  211. package/studio-dist/client/assets/getting-started-BDyGvHhc.js +0 -1
  212. package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +0 -1
  213. package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +0 -1
  214. package/studio-dist/client/assets/graph-ah7ZXfTa.js +0 -2
  215. package/studio-dist/client/assets/guides-CsL0660B.js +0 -1
  216. package/studio-dist/client/assets/index-zmRH87D4.js +0 -40
  217. package/studio-dist/client/assets/panel-COgk0vP5.js +0 -1
  218. package/studio-dist/client/assets/plugins._service._view-Cn3WBHab.js +0 -1
  219. package/studio-dist/client/assets/reports-C_AqLBYH.js +0 -1
  220. package/studio-dist/client/assets/routes-BokQmHtC.js +0 -1
  221. package/studio-dist/client/assets/search-DxidNK2M.js +0 -1
  222. package/studio-dist/client/assets/select-CYFCbHUd.js +0 -1
  223. package/studio-dist/client/assets/skills-R3vttWHM.js +0 -1
  224. package/studio-dist/client/assets/specs-view-znqFPx9p.js +0 -1
  225. package/studio-dist/client/assets/steps-tVDWn7j6.js +0 -1
  226. package/studio-dist/client/assets/studio-ndtFcS2Y.js +0 -100
  227. package/studio-dist/client/assets/studio-queries-CkUSByy7.js +0 -2
  228. package/studio-dist/client/assets/usage-Kuhr8dSl.js +0 -55
  229. package/studio-dist/client/assets/useAnchoredPopupScrollLock-dc_kP4Go.js +0 -1
  230. package/studio-dist/client/assets/useMutation-CqtM9COw.js +0 -1
  231. package/studio-dist/client/assets/vault-CSP8kwRg.js +0 -1
  232. package/studio-dist/client/assets/workflow-BPJAmmZi.js +0 -1
@@ -85,33 +85,19 @@ export class CompanionStore {
85
85
  );
86
86
  }
87
87
 
88
- const registryPath = this.companionRegistryStore.configPath;
89
- const locked = await withPathLock(
90
- REGISTRY_LOCK_NAMESPACE,
91
- /** Its real path, missing segments as written: a first link has no file yet. */
92
- physicalPath(registryPath),
93
- {},
94
- async () => {
95
- // A companion's registry.yaml may not exist yet (its first-ever link):
96
- // that is not a real error here, unlike a working repo reading its own
97
- // missing config, so fall back to an empty registry instead of throwing.
98
- const working = await this.companionRegistryStore.load().catch((error) => {
99
- if (error instanceof ConfigError) return CompanionRegistryStore.defaultConfig();
100
- throw error;
101
- });
102
- const reconciled = reconcileRegistry(working.repos, repository);
103
- working.repos = reconciled.repos;
104
- await this.companionRegistryStore.save(working);
105
- return reconciled;
106
- },
107
- );
108
- if (!locked.acquired) {
109
- throw new ConfigError(
110
- `another ${FRAMEWORK_NAME} process is still writing ${registryPath}; try again.`,
111
- );
112
- }
113
-
114
- const { kept, merged } = locked.value;
88
+ const { kept, merged } = await this.withRegistryLock(async () => {
89
+ // A companion's registry.yaml may not exist yet (its first-ever link):
90
+ // that is not a real error here, unlike a working repo reading its own
91
+ // missing config, so fall back to an empty registry instead of throwing.
92
+ const working = await this.companionRegistryStore.load().catch((error) => {
93
+ if (error instanceof ConfigError) return CompanionRegistryStore.defaultConfig();
94
+ throw error;
95
+ });
96
+ const reconciled = reconcileRegistry(working.repos, repository);
97
+ working.repos = reconciled.repos;
98
+ await this.companionRegistryStore.save(working);
99
+ return reconciled;
100
+ });
115
101
  const companionPath = path.resolve(this.companionPath);
116
102
  const source = options.companionSource ?? "git";
117
103
  // Repo-local registry write is a cache, not the source of truth: the
@@ -138,6 +124,41 @@ export class CompanionStore {
138
124
  return kept;
139
125
  }
140
126
 
127
+ /** Drops every entry whose path resolves to `repositoryPath`, under the registry's lock; a missing registry is left alone. */
128
+ async removeRepository(repositoryPath: string): Promise<void> {
129
+ const resolvedRepositoryPath = path.resolve(repositoryPath);
130
+ await this.withRegistryLock(async () => {
131
+ const working = await this.companionRegistryStore.load().catch((error) => {
132
+ if (error instanceof ConfigError) return null;
133
+ throw error;
134
+ });
135
+ if (!working) return;
136
+ const repos = working.repos.filter(
137
+ (repo) => path.resolve(repo.path) !== resolvedRepositoryPath,
138
+ );
139
+ if (repos.length === working.repos.length) return;
140
+ working.repos = repos;
141
+ await this.companionRegistryStore.save(working);
142
+ });
143
+ }
144
+
145
+ private async withRegistryLock<T>(update: () => Promise<T>): Promise<T> {
146
+ const registryPath = this.companionRegistryStore.configPath;
147
+ const locked = await withPathLock(
148
+ REGISTRY_LOCK_NAMESPACE,
149
+ /** Its real path, missing segments as written: a first link has no file yet. */
150
+ physicalPath(registryPath),
151
+ {},
152
+ update,
153
+ );
154
+ if (!locked.acquired) {
155
+ throw new ConfigError(
156
+ `another ${FRAMEWORK_NAME} process is still writing ${registryPath}; try again.`,
157
+ );
158
+ }
159
+ return locked.value;
160
+ }
161
+
141
162
  async getRepository(repositoryId: string): Promise<LinkedRepository | undefined> {
142
163
  const working = await this.companionRegistryStore.load();
143
164
  return working.repos.find((r) => r.id === repositoryId);
@@ -287,6 +308,23 @@ interface ResolveOptions {
287
308
  logFailures?: boolean;
288
309
  /** `false` looks up without the self-heal or the stale-pointer prune, so a caller can refuse first. */
289
310
  write?: boolean;
311
+ /** Only links recorded for `cwd` itself: none inherited from an ancestor folder or another Checkout of the clone. */
312
+ own?: boolean;
313
+ }
314
+
315
+ interface LinkRegistry {
316
+ companions: RepoLocalCompanionPointer[];
317
+ repository?: { path?: unknown };
318
+ }
319
+
320
+ /** A repo-local registry; null when unreadable or another shape, such as a companion's own `{ repos }`. */
321
+ async function readLinkRegistry(registryPath: string): Promise<LinkRegistry | null> {
322
+ try {
323
+ const parsed = parse(await fs.readFile(registryPath, "utf8")) as Partial<LinkRegistry> | null;
324
+ return parsed && Array.isArray(parsed.companions) ? (parsed as LinkRegistry) : null;
325
+ } catch {
326
+ return null;
327
+ }
290
328
  }
291
329
 
292
330
  /**
@@ -356,9 +394,10 @@ export class CompanionResolver {
356
394
  * Another Checkout of the clone only: a subfolder of the entry's own
357
395
  * folder matches nothing, as before, so `mate working cleanup` there sticks.
358
396
  */
359
- const byClone = clone
360
- ? repos.find((r) => entryOfClone(r, clone) && physicalPath(r.path) !== checkoutRoot)
361
- : undefined;
397
+ const byClone =
398
+ clone && !options.own
399
+ ? repos.find((r) => entryOfClone(r, clone) && physicalPath(r.path) !== checkoutRoot)
400
+ : undefined;
362
401
  return byClone && checkoutRoot
363
402
  ? { companionPath, repositoryId: byClone.id, folder: checkoutRoot }
364
403
  : null;
@@ -400,20 +439,14 @@ export class CompanionResolver {
400
439
  options: ResolveOptions,
401
440
  ): Promise<CompanionResolutionResult | null> {
402
441
  const found = await findRepoLocalRegistryFile(resolvedCwd);
403
- if (!found) return null;
442
+ if (!found || (options.own && found.repoRoot !== resolvedCwd)) return null;
404
443
 
405
- let pointers: RepoLocalCompanionPointer[];
406
- try {
407
- const raw = await fs.readFile(found.registryPath, "utf8");
408
- const parsed = parse(raw) as { companions?: unknown; repository?: { path?: unknown } } | null;
409
- if (!parsed || !Array.isArray(parsed.companions)) return null;
410
- /** A cache copied from another Checkout of the clone is that Checkout's, not this one's. */
411
- const named = parsed.repository?.path;
412
- if (typeof named === "string" && namesOtherCheckout(found.repoRoot, named)) return null;
413
- pointers = parsed.companions as RepoLocalCompanionPointer[];
414
- } catch {
415
- return null;
416
- }
444
+ const registry = await readLinkRegistry(found.registryPath);
445
+ if (!registry) return null;
446
+ /** A cache copied from another Checkout of the clone is that Checkout's, not this one's. */
447
+ const named = registry.repository?.path;
448
+ if (typeof named === "string" && namesOtherCheckout(found.repoRoot, named)) return null;
449
+ const pointers = registry.companions;
417
450
 
418
451
  if (pointers.length === 0) return null;
419
452
 
@@ -617,16 +650,11 @@ export async function findDescendantRepoLocalRegistries(rootPath: string): Promi
617
650
  }
618
651
  }
619
652
 
653
+ // A missing or unreadable registry, or a companion's own, is not a shadowed link.
620
654
  const shadowedPaths = await Promise.all(
621
- registryCandidates.map(async ({ registryPath, shadowedPath }) => {
622
- try {
623
- const stats = await fs.stat(registryPath);
624
- return stats.isFile() ? shadowedPath : null;
625
- } catch {
626
- // A missing or unreadable registry is not a shadowed link.
627
- return null;
628
- }
629
- }),
655
+ registryCandidates.map(async ({ registryPath, shadowedPath }) =>
656
+ (await readLinkRegistry(registryPath)) ? shadowedPath : null,
657
+ ),
630
658
  );
631
659
  return shadowedPaths.filter((candidate): candidate is string => candidate !== null).toSorted();
632
660
  }
@@ -1,6 +1,8 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
+ import { parse } from "yaml";
5
+
4
6
  import { FRAMEWORK_NAME } from "../../framework";
5
7
  import {
6
8
  CompanionResolver,
@@ -42,10 +44,24 @@ const emptyResolution = (): CompanionResolutionResult => ({
42
44
  failures: [],
43
45
  });
44
46
 
45
- function kindForConfig(config: FrameworkConfig): Exclude<RootKind, "core"> {
47
+ function kindForConfig(config: Pick<FrameworkConfig, "type">): Exclude<RootKind, "core"> {
46
48
  return config.type === "hub" ? "hub" : config.type === "working" ? "working" : "companion";
47
49
  }
48
50
 
51
+ /** The kind a folder's own `framework.yaml` names; null without one. A file that cannot be read or parsed counts as a companion's. */
52
+ export async function localRootKind(folder: string): Promise<Exclude<RootKind, "core"> | null> {
53
+ try {
54
+ const raw = await fs.readFile(
55
+ path.join(folder, `.${FRAMEWORK_NAME}`, "config", "framework.yaml"),
56
+ "utf8",
57
+ );
58
+ return kindForConfig((parse(raw) as Pick<FrameworkConfig, "type"> | null) ?? {});
59
+ } catch (error) {
60
+ const code = (error as NodeJS.ErrnoException).code;
61
+ return code === "ENOENT" || code === "ENOTDIR" ? null : "companion";
62
+ }
63
+ }
64
+
49
65
  async function loadRootConfig(
50
66
  rootPath: string,
51
67
  write?: boolean,
@@ -0,0 +1,139 @@
1
+ import type { UIMessage, UIMessageChunk } from "ai";
2
+
3
+ export interface ChatTurnRequest {
4
+ companionPath: string;
5
+ messages: UIMessage[];
6
+ signal: AbortSignal;
7
+ harness?: ChatHarness;
8
+ model?: ChatModel;
9
+ effort?: ChatEffort;
10
+ }
11
+
12
+ export const CHAT_NO_CREDENTIAL = "Studio Chat has no Claude credential";
13
+ export const CHAT_CREDENTIAL_REJECTED = "The chat credential was rejected";
14
+ export const CHAT_NO_LOGIN = "Claude Code has no local login on this machine";
15
+
16
+ export function isCredentialFailure(text: string): boolean {
17
+ return [CHAT_NO_CREDENTIAL, CHAT_CREDENTIAL_REJECTED, CHAT_NO_LOGIN].some((start) =>
18
+ text.startsWith(start),
19
+ );
20
+ }
21
+
22
+ export type ChatHarness = "claude-code" | "opencode";
23
+
24
+ /**
25
+ * OpenCode is held back: its 1.19.5 server loads the companion's `.opencode` plugins despite
26
+ * `OPENCODE_DISABLE_PROJECT_CONFIG`, so its turns would not be read-only.
27
+ */
28
+ export const CHAT_HARNESSES: readonly ChatHarness[] = ["claude-code"];
29
+
30
+ /** A model's id as its harness takes it: a Claude Code alias, or OpenCode's `provider/model`. */
31
+ export type ChatModel = string;
32
+
33
+ export interface ChatModelChoice {
34
+ id: ChatModel;
35
+ name: string;
36
+ description: string;
37
+ effortless?: boolean;
38
+ }
39
+
40
+ export const CHAT_HARNESS_NAMES: Readonly<Record<ChatHarness, string>> = {
41
+ "claude-code": "Claude Code",
42
+ opencode: "OpenCode",
43
+ };
44
+
45
+ /** Each harness's models; the first is its default. */
46
+ export const CHAT_MODELS: Readonly<Record<ChatHarness, readonly ChatModelChoice[]>> = {
47
+ "claude-code": [
48
+ { id: "sonnet", name: "Sonnet", description: "Careful answers at a good pace" },
49
+ { id: "opus", name: "Opus", description: "Most capable, for hard questions; slower" },
50
+ { id: "haiku", name: "Haiku", description: "Fastest, for quick lookups", effortless: true },
51
+ ],
52
+ opencode: [
53
+ {
54
+ id: "anthropic/claude-sonnet-5-5",
55
+ name: "Claude Sonnet 5.5",
56
+ description: "Anthropic, with ANTHROPIC_API_KEY",
57
+ },
58
+ {
59
+ id: "anthropic/claude-opus-5-5",
60
+ name: "Claude Opus 5.5",
61
+ description: "Anthropic's most capable; slower",
62
+ },
63
+ {
64
+ id: "openai/gpt-6.1-sol",
65
+ name: "GPT-6.1 Sol",
66
+ description: "OpenAI, with OPENAI_API_KEY or an OpenCode login",
67
+ },
68
+ {
69
+ id: "google/gemini-3.8-flash",
70
+ name: "Gemini 3.8 Flash",
71
+ description: "Google, with GOOGLE_GENERATIVE_AI_API_KEY",
72
+ },
73
+ ],
74
+ };
75
+
76
+ export function chatModel(harness: ChatHarness, id: ChatModel): ChatModelChoice | undefined {
77
+ return CHAT_MODELS[harness].find((model) => model.id === id);
78
+ }
79
+
80
+ /** Thinking effort a turn can ask for; the middle one is the default. */
81
+ export const CHAT_EFFORTS = ["low", "medium", "high"] as const;
82
+ export type ChatEffort = (typeof CHAT_EFFORTS)[number];
83
+
84
+ export interface ChatAgent {
85
+ turn(request: ChatTurnRequest): ReadableStream<UIMessageChunk>;
86
+ }
87
+
88
+ /** Characters of earlier turns replayed into a prompt; the newest are kept. */
89
+ export const CHAT_HISTORY_BUDGET = 40_000;
90
+ const CUT_MARK = "[…] ";
91
+
92
+ export function messageText(message: UIMessage): string {
93
+ return message.parts
94
+ .flatMap((part) => (part.type === "text" ? [part.text] : []))
95
+ .join("\n")
96
+ .trim();
97
+ }
98
+
99
+ export function renderPrompt(messages: UIMessage[], budget = CHAT_HISTORY_BUDGET): string | null {
100
+ const last = messages.at(-1);
101
+ const question = last?.role === "user" ? messageText(last) : "";
102
+ if (!question) return null;
103
+ const kept = keptHistory(messages.slice(0, -1), budget);
104
+ if (kept.length === 0) return question;
105
+ return [
106
+ "Earlier in this conversation (oldest first; older turns may be left out):",
107
+ "<conversation>",
108
+ kept.join("\n\n"),
109
+ "</conversation>",
110
+ "",
111
+ "The new question:",
112
+ question,
113
+ ].join("\n");
114
+ }
115
+
116
+ /** Characters of `messages` the next question replays, out of `CHAT_HISTORY_BUDGET`. */
117
+ export function replayedChars(messages: UIMessage[]): number {
118
+ return keptHistory(messages, CHAT_HISTORY_BUDGET).reduce((sum, entry) => sum + entry.length, 0);
119
+ }
120
+
121
+ function keptHistory(history: UIMessage[], budget: number): string[] {
122
+ const kept: string[] = [];
123
+ let used = 0;
124
+ for (const message of history.toReversed()) {
125
+ if (message.role !== "user" && message.role !== "assistant") continue;
126
+ const text = messageText(message);
127
+ if (!text) continue;
128
+ const label = `${message.role === "user" ? "User" : "Assistant"}: `;
129
+ const entry = `${label}${text}`;
130
+ if (used + entry.length > budget) {
131
+ const room = budget - used - label.length - CUT_MARK.length;
132
+ if (room > 0) kept.push(`${label}${CUT_MARK}${text.slice(-room)}`);
133
+ break;
134
+ }
135
+ kept.push(entry);
136
+ used += entry.length;
137
+ }
138
+ return kept.toReversed();
139
+ }
@@ -0,0 +1,136 @@
1
+ import fs from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ import { deployReactDoctorSkill } from "../../tools/setup/capabilities/react-doctor";
6
+ import { applyMateSkills } from "../../tools/setup/mate";
7
+ import { isWithin, physicalPath } from "../../runtime/physical-path";
8
+ import { FRONTMATTER_PATTERN, readFrontmatter } from "../frontmatter";
9
+ import { readCompanionConfig } from "../orchestrator/config-store";
10
+ import type { FrameworkConfig } from "../orchestrator/types";
11
+
12
+ export interface CompanionSkill {
13
+ name: string;
14
+ description: string;
15
+ content: string;
16
+ files: { path: string; content: string }[];
17
+ }
18
+
19
+ const MAX_FILE_BYTES = 256 * 1024;
20
+ const SKILL_NAME = /^[a-z0-9][a-z0-9-]*$/;
21
+
22
+ async function textFile(file: string, realRoot: string): Promise<string | null> {
23
+ if (!isWithin(physicalPath(file), realRoot)) return null;
24
+ const stat = await fs.stat(file).catch(() => null);
25
+ if (!stat?.isFile() || stat.size > MAX_FILE_BYTES) return null;
26
+ const bytes = await fs.readFile(file);
27
+ if (bytes.includes(0)) return null;
28
+ return bytes.toString("utf8");
29
+ }
30
+
31
+ async function skillFiles(
32
+ dir: string,
33
+ realRoot: string,
34
+ ): Promise<{ path: string; content: string }[]> {
35
+ const entries = await fs.readdir(dir, { recursive: true, withFileTypes: true });
36
+ const files = await Promise.all(
37
+ entries
38
+ .filter((entry) => entry.isFile())
39
+ .map(async (entry) => {
40
+ const absolute = path.join(entry.parentPath, entry.name);
41
+ const relative = path.relative(dir, absolute).split(path.sep).join("/");
42
+ if (relative === "SKILL.md") return null;
43
+ const content = await textFile(absolute, realRoot);
44
+ return content === null ? null : { path: relative, content };
45
+ }),
46
+ );
47
+ return files
48
+ .filter((file): file is { path: string; content: string } => file !== null)
49
+ .toSorted((a, b) => a.path.localeCompare(b.path));
50
+ }
51
+
52
+ const MATE_SKILL_DEPLOYERS = [
53
+ { capability: "openspec", deploy: (skillsDir: string) => applyMateSkills(skillsDir, "claude") },
54
+ { capability: "react-doctor", deploy: deployReactDoctorSkill },
55
+ ] as const;
56
+
57
+ async function readSkill(
58
+ dir: string,
59
+ name: string,
60
+ realRoot: string,
61
+ ): Promise<CompanionSkill | null> {
62
+ const content = await textFile(path.join(dir, "SKILL.md"), realRoot);
63
+ if (content === null) return null;
64
+ const meta = readFrontmatter(content) ?? {};
65
+ const description =
66
+ typeof meta.description === "string" ? meta.description.replace(/\s+/g, " ").trim() : "";
67
+ if (!description) return null;
68
+ // The harness writes its own `name`/`description` frontmatter above `content` and
69
+ // inserts the description unquoted, so it gets a quoted YAML scalar and the body only.
70
+ return {
71
+ name,
72
+ description: JSON.stringify(description),
73
+ content: content.replace(FRONTMATTER_PATTERN, "").trimStart(),
74
+ files: await skillFiles(dir, realRoot),
75
+ };
76
+ }
77
+
78
+ async function readSkills(skillsDir: string, root: string): Promise<CompanionSkill[]> {
79
+ const entries = await fs.readdir(skillsDir, { withFileTypes: true }).catch(() => []);
80
+ const realRoot = physicalPath(root);
81
+ const skills = await Promise.all(
82
+ entries
83
+ .filter((entry) => entry.isDirectory() && SKILL_NAME.test(entry.name))
84
+ .map((entry) => readSkill(path.join(skillsDir, entry.name), entry.name, realRoot)),
85
+ );
86
+ return skills.filter((skill): skill is CompanionSkill => skill !== null);
87
+ }
88
+
89
+ const mateSkillsByCapabilities = new Map<string, Promise<CompanionSkill[]>>();
90
+
91
+ function installedMateSkills(config: FrameworkConfig): Promise<CompanionSkill[]> {
92
+ if (!config.allowedAgents?.includes("claude")) return Promise.resolve([]);
93
+ const enabled = new Set((config.capabilities ?? []).map((capability) => capability.name));
94
+ const deployers = MATE_SKILL_DEPLOYERS.filter((deployer) => enabled.has(deployer.capability));
95
+ if (deployers.length === 0) return Promise.resolve([]);
96
+ const key = deployers.map((deployer) => deployer.capability).join(",");
97
+ let skills = mateSkillsByCapabilities.get(key);
98
+ if (!skills) {
99
+ skills = deployMateSkills(deployers);
100
+ mateSkillsByCapabilities.set(key, skills);
101
+ skills.catch(() => mateSkillsByCapabilities.delete(key));
102
+ }
103
+ return skills;
104
+ }
105
+
106
+ async function deployMateSkills(
107
+ deployers: readonly (typeof MATE_SKILL_DEPLOYERS)[number][],
108
+ ): Promise<CompanionSkill[]> {
109
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), "mate-chat-skills-"));
110
+ try {
111
+ for (const deployer of deployers) {
112
+ // oxlint-disable-next-line no-await-in-loop -- deployers write into the same directory
113
+ await deployer.deploy(dir);
114
+ }
115
+ return await readSkills(dir, dir);
116
+ } finally {
117
+ await fs.rm(dir, { recursive: true, force: true });
118
+ }
119
+ }
120
+
121
+ export async function companionSkills(
122
+ companionPath: string,
123
+ config?: FrameworkConfig,
124
+ ): Promise<CompanionSkill[]> {
125
+ const [own, mate] = await Promise.all([
126
+ readSkills(path.join(companionPath, ".claude", "skills"), companionPath),
127
+ installedMateSkills(config ?? (await readCompanionConfig(companionPath))),
128
+ ]);
129
+ const byName = new Map([...own, ...mate].map((skill) => [skill.name, skill]));
130
+ return [...byName.values()].toSorted((a, b) => a.name.localeCompare(b.name));
131
+ }
132
+
133
+ export async function companionAgentsText(companionPath: string): Promise<string> {
134
+ const agents = path.join(companionPath, "AGENTS.md");
135
+ return (await textFile(agents, physicalPath(companionPath)))?.trim() ?? "";
136
+ }
@@ -0,0 +1,79 @@
1
+ import path from "node:path";
2
+
3
+ import { mateHome } from "../../runtime/runtime-directory";
4
+ import {
5
+ type AgentCredential,
6
+ AgentCredentialError,
7
+ type CredentialStatus,
8
+ CredentialStore,
9
+ } from "../agent-credential";
10
+ import { CHAT_NO_CREDENTIAL } from "./agent";
11
+
12
+ const STARTUP_NAMES = ["ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN"] as const;
13
+ /**
14
+ * The appliance takes an Anthropic API key only: Anthropic's terms keep subscription credentials
15
+ * out of a hosted agent product.
16
+ */
17
+ const APPLIANCE_NAMES = ["ANTHROPIC_API_KEY"] as const;
18
+
19
+ export const NO_CHAT_CREDENTIAL = `${CHAT_NO_CREDENTIAL}. Set one under Credential in the session panel, or supply ANTHROPIC_API_KEY through credentials:.`;
20
+
21
+ export type ChatAuth = AgentCredential | "login" | null;
22
+
23
+ export interface ChatCredentials {
24
+ auth(): ChatAuth;
25
+ status(): CredentialStatus;
26
+ set(credential: AgentCredential): Promise<void>;
27
+ clear(): void;
28
+ }
29
+
30
+ export function chatCredentialFile(home: string = mateHome()): string {
31
+ return path.join(home, "studio-chat", "credential.env");
32
+ }
33
+
34
+ function startupCredential(
35
+ env: NodeJS.ProcessEnv,
36
+ names: readonly AgentCredential["name"][],
37
+ ): AgentCredential | null {
38
+ for (const name of names) {
39
+ const value = env[name]?.trim();
40
+ if (value) return { name, value };
41
+ }
42
+ return null;
43
+ }
44
+
45
+ export function createChatCredentials(
46
+ options: {
47
+ appliance?: boolean;
48
+ file?: string;
49
+ env?: NodeJS.ProcessEnv;
50
+ } = {},
51
+ ): ChatCredentials {
52
+ const appliance = options.appliance === true;
53
+ const startup = startupCredential(
54
+ options.env ?? process.env,
55
+ appliance ? APPLIANCE_NAMES : STARTUP_NAMES,
56
+ );
57
+ const store = new CredentialStore(options.file ?? chatCredentialFile(), startup);
58
+ const studio = store.studio();
59
+ if (appliance && studio && studio.name !== "ANTHROPIC_API_KEY") store.clear();
60
+ return {
61
+ auth() {
62
+ return store.current() ?? (appliance ? null : "login");
63
+ },
64
+ status() {
65
+ const status = store.status();
66
+ if (status.source === null && !appliance) return { ...status, source: "login" };
67
+ return status;
68
+ },
69
+ async set(credential) {
70
+ if (appliance && credential.name !== "ANTHROPIC_API_KEY") {
71
+ throw new AgentCredentialError(
72
+ "the appliance takes an Anthropic API key only; nothing was stored",
73
+ );
74
+ }
75
+ await store.set(credential);
76
+ },
77
+ clear: () => store.clear(),
78
+ };
79
+ }