@skillsmith/core 0.12.0 → 0.12.2

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 (290) hide show
  1. package/CHANGELOG.md +166 -1
  2. package/README.md +7 -8
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/src/api/client.d.ts +5 -3
  5. package/dist/src/api/client.d.ts.map +1 -1
  6. package/dist/src/api/client.js +23 -33
  7. package/dist/src/api/client.js.map +1 -1
  8. package/dist/src/api/client.registry-sync.d.ts +28 -0
  9. package/dist/src/api/client.registry-sync.d.ts.map +1 -0
  10. package/dist/src/api/client.registry-sync.js +36 -0
  11. package/dist/src/api/client.registry-sync.js.map +1 -0
  12. package/dist/src/api/client.test.js +185 -0
  13. package/dist/src/api/client.test.js.map +1 -1
  14. package/dist/src/api/client.toSkill.d.ts +16 -0
  15. package/dist/src/api/client.toSkill.d.ts.map +1 -0
  16. package/dist/src/api/client.toSkill.js +46 -0
  17. package/dist/src/api/client.toSkill.js.map +1 -0
  18. package/dist/src/api/client.types.d.ts +22 -0
  19. package/dist/src/api/client.types.d.ts.map +1 -1
  20. package/dist/src/api/index.d.ts +1 -1
  21. package/dist/src/api/index.d.ts.map +1 -1
  22. package/dist/src/api/index.js.map +1 -1
  23. package/dist/src/api/schemas.d.ts +28 -0
  24. package/dist/src/api/schemas.d.ts.map +1 -1
  25. package/dist/src/api/schemas.js +13 -0
  26. package/dist/src/api/schemas.js.map +1 -1
  27. package/dist/src/audit/remote-audit.d.ts +85 -0
  28. package/dist/src/audit/remote-audit.d.ts.map +1 -1
  29. package/dist/src/audit/remote-audit.js +126 -3
  30. package/dist/src/audit/remote-audit.js.map +1 -1
  31. package/dist/src/audit/remote-audit.test.js +217 -1
  32. package/dist/src/audit/remote-audit.test.js.map +1 -1
  33. package/dist/src/config/index.d.ts +1 -0
  34. package/dist/src/config/index.d.ts.map +1 -1
  35. package/dist/src/config/index.js.map +1 -1
  36. package/dist/src/config/token-credentials.d.ts +20 -0
  37. package/dist/src/config/token-credentials.d.ts.map +1 -1
  38. package/dist/src/config/token-credentials.js +59 -0
  39. package/dist/src/config/token-credentials.js.map +1 -1
  40. package/dist/src/config/token-credentials.test.d.ts +3 -0
  41. package/dist/src/config/token-credentials.test.d.ts.map +1 -1
  42. package/dist/src/config/token-credentials.test.js +68 -0
  43. package/dist/src/config/token-credentials.test.js.map +1 -1
  44. package/dist/src/db/migration-runner.d.ts.map +1 -1
  45. package/dist/src/db/migration-runner.js +6 -0
  46. package/dist/src/db/migration-runner.js.map +1 -1
  47. package/dist/src/db/migrations/v18-skill-versions-real-content-hash.d.ts +36 -0
  48. package/dist/src/db/migrations/v18-skill-versions-real-content-hash.d.ts.map +1 -0
  49. package/dist/src/db/migrations/v18-skill-versions-real-content-hash.js +38 -0
  50. package/dist/src/db/migrations/v18-skill-versions-real-content-hash.js.map +1 -0
  51. package/dist/src/db/schema.d.ts +1 -1
  52. package/dist/src/db/schema.d.ts.map +1 -1
  53. package/dist/src/db/schema.js +3 -1
  54. package/dist/src/db/schema.js.map +1 -1
  55. package/dist/src/exports/services.d.ts +3 -7
  56. package/dist/src/exports/services.d.ts.map +1 -1
  57. package/dist/src/exports/services.install.d.ts +18 -0
  58. package/dist/src/exports/services.install.d.ts.map +1 -0
  59. package/dist/src/exports/services.install.js +62 -0
  60. package/dist/src/exports/services.install.js.map +1 -0
  61. package/dist/src/exports/services.js +12 -32
  62. package/dist/src/exports/services.js.map +1 -1
  63. package/dist/src/exports/types.d.ts +1 -1
  64. package/dist/src/exports/types.d.ts.map +1 -1
  65. package/dist/src/index.d.ts +6 -6
  66. package/dist/src/index.d.ts.map +1 -1
  67. package/dist/src/index.js +8 -5
  68. package/dist/src/index.js.map +1 -1
  69. package/dist/src/install/agent-config-merge.json.d.ts +5 -4
  70. package/dist/src/install/agent-config-merge.json.d.ts.map +1 -1
  71. package/dist/src/install/agent-config-merge.json.js +10 -9
  72. package/dist/src/install/agent-config-merge.json.js.map +1 -1
  73. package/dist/src/install/agent-config-merge.types.d.ts +11 -1
  74. package/dist/src/install/agent-config-merge.types.d.ts.map +1 -1
  75. package/dist/src/install/agent-config-merge.types.js.map +1 -1
  76. package/dist/src/install/agent-harness-targets.d.ts +30 -2
  77. package/dist/src/install/agent-harness-targets.d.ts.map +1 -1
  78. package/dist/src/install/agent-harness-targets.js +17 -0
  79. package/dist/src/install/agent-harness-targets.js.map +1 -1
  80. package/dist/src/install/agent-manifest-path-guard.d.ts +28 -3
  81. package/dist/src/install/agent-manifest-path-guard.d.ts.map +1 -1
  82. package/dist/src/install/agent-manifest-path-guard.js +59 -3
  83. package/dist/src/install/agent-manifest-path-guard.js.map +1 -1
  84. package/dist/src/install/agent-manifest-path-guard.test.js +27 -1
  85. package/dist/src/install/agent-manifest-path-guard.test.js.map +1 -1
  86. package/dist/src/install/agent-pack-installer.antigravity-mcp.d.ts +74 -0
  87. package/dist/src/install/agent-pack-installer.antigravity-mcp.d.ts.map +1 -0
  88. package/dist/src/install/agent-pack-installer.antigravity-mcp.js +106 -0
  89. package/dist/src/install/agent-pack-installer.antigravity-mcp.js.map +1 -0
  90. package/dist/src/install/agent-pack-installer.antigravity-mcp.test.d.ts +2 -0
  91. package/dist/src/install/agent-pack-installer.antigravity-mcp.test.d.ts.map +1 -0
  92. package/dist/src/install/agent-pack-installer.antigravity-mcp.test.js +157 -0
  93. package/dist/src/install/agent-pack-installer.antigravity-mcp.test.js.map +1 -0
  94. package/dist/src/install/agent-pack-installer.cursor-mcp.d.ts +53 -0
  95. package/dist/src/install/agent-pack-installer.cursor-mcp.d.ts.map +1 -0
  96. package/dist/src/install/agent-pack-installer.cursor-mcp.js +207 -0
  97. package/dist/src/install/agent-pack-installer.cursor-mcp.js.map +1 -0
  98. package/dist/src/install/agent-pack-installer.cursor-mcp.test.d.ts +2 -0
  99. package/dist/src/install/agent-pack-installer.cursor-mcp.test.d.ts.map +1 -0
  100. package/dist/src/install/agent-pack-installer.cursor-mcp.test.js +285 -0
  101. package/dist/src/install/agent-pack-installer.cursor-mcp.test.js.map +1 -0
  102. package/dist/src/install/agent-pack-installer.d.ts +8 -0
  103. package/dist/src/install/agent-pack-installer.d.ts.map +1 -1
  104. package/dist/src/install/agent-pack-installer.entry.d.ts +120 -3
  105. package/dist/src/install/agent-pack-installer.entry.d.ts.map +1 -1
  106. package/dist/src/install/agent-pack-installer.entry.js +166 -3
  107. package/dist/src/install/agent-pack-installer.entry.js.map +1 -1
  108. package/dist/src/install/agent-pack-installer.js +97 -3
  109. package/dist/src/install/agent-pack-installer.js.map +1 -1
  110. package/dist/src/install/agent-pack-installer.types.d.ts +27 -0
  111. package/dist/src/install/agent-pack-installer.types.d.ts.map +1 -1
  112. package/dist/src/install/agent-pack-installer.types.js +6 -0
  113. package/dist/src/install/agent-pack-installer.types.js.map +1 -1
  114. package/dist/src/install/agent-pack-installer.workspace-scope.test.d.ts +2 -0
  115. package/dist/src/install/agent-pack-installer.workspace-scope.test.d.ts.map +1 -0
  116. package/dist/src/install/agent-pack-installer.workspace-scope.test.js +148 -0
  117. package/dist/src/install/agent-pack-installer.workspace-scope.test.js.map +1 -0
  118. package/dist/src/install/agent-pack-uninstaller.d.ts +18 -7
  119. package/dist/src/install/agent-pack-uninstaller.d.ts.map +1 -1
  120. package/dist/src/install/agent-pack-uninstaller.js +59 -9
  121. package/dist/src/install/agent-pack-uninstaller.js.map +1 -1
  122. package/dist/src/install/agent-pack-uninstaller.test.js +74 -1
  123. package/dist/src/install/agent-pack-uninstaller.test.js.map +1 -1
  124. package/dist/src/install/fan-out.d.ts.map +1 -1
  125. package/dist/src/install/fan-out.js +6 -0
  126. package/dist/src/install/fan-out.js.map +1 -1
  127. package/dist/src/install/index.d.ts +2 -0
  128. package/dist/src/install/index.d.ts.map +1 -1
  129. package/dist/src/install/index.js +2 -0
  130. package/dist/src/install/index.js.map +1 -1
  131. package/dist/src/install/workspace-scope.d.ts +207 -0
  132. package/dist/src/install/workspace-scope.d.ts.map +1 -0
  133. package/dist/src/install/workspace-scope.js +275 -0
  134. package/dist/src/install/workspace-scope.js.map +1 -0
  135. package/dist/src/install/workspace-scope.test.d.ts +2 -0
  136. package/dist/src/install/workspace-scope.test.d.ts.map +1 -0
  137. package/dist/src/install/workspace-scope.test.js +378 -0
  138. package/dist/src/install/workspace-scope.test.js.map +1 -0
  139. package/dist/src/security/__tests__/pathValidation.test.js +30 -1
  140. package/dist/src/security/__tests__/pathValidation.test.js.map +1 -1
  141. package/dist/src/services/SubagentGenerator.client-profiles.d.ts +258 -0
  142. package/dist/src/services/SubagentGenerator.client-profiles.d.ts.map +1 -0
  143. package/dist/src/services/SubagentGenerator.client-profiles.js +260 -0
  144. package/dist/src/services/SubagentGenerator.client-profiles.js.map +1 -0
  145. package/dist/src/services/SubagentGenerator.d.ts +19 -41
  146. package/dist/src/services/SubagentGenerator.d.ts.map +1 -1
  147. package/dist/src/services/SubagentGenerator.helpers.d.ts +64 -0
  148. package/dist/src/services/SubagentGenerator.helpers.d.ts.map +1 -0
  149. package/dist/src/services/SubagentGenerator.helpers.js +228 -0
  150. package/dist/src/services/SubagentGenerator.helpers.js.map +1 -0
  151. package/dist/src/services/SubagentGenerator.js +66 -208
  152. package/dist/src/services/SubagentGenerator.js.map +1 -1
  153. package/dist/src/services/SubagentGenerator.types.d.ts +45 -0
  154. package/dist/src/services/SubagentGenerator.types.d.ts.map +1 -0
  155. package/dist/src/services/SubagentGenerator.types.js +14 -0
  156. package/dist/src/services/SubagentGenerator.types.js.map +1 -0
  157. package/dist/src/services/TransformationService.d.ts +18 -61
  158. package/dist/src/services/TransformationService.d.ts.map +1 -1
  159. package/dist/src/services/TransformationService.js +29 -17
  160. package/dist/src/services/TransformationService.js.map +1 -1
  161. package/dist/src/services/TransformationService.types.d.ts +74 -0
  162. package/dist/src/services/TransformationService.types.d.ts.map +1 -0
  163. package/dist/src/services/TransformationService.types.js +8 -0
  164. package/dist/src/services/TransformationService.types.js.map +1 -0
  165. package/dist/src/services/__tests__/SubagentGenerator.client-profiles.test.d.ts +5 -0
  166. package/dist/src/services/__tests__/SubagentGenerator.client-profiles.test.d.ts.map +1 -0
  167. package/dist/src/services/__tests__/SubagentGenerator.client-profiles.test.js +72 -0
  168. package/dist/src/services/__tests__/SubagentGenerator.client-profiles.test.js.map +1 -0
  169. package/dist/src/services/__tests__/SubagentGenerator.helpers.test.d.ts +2 -0
  170. package/dist/src/services/__tests__/SubagentGenerator.helpers.test.d.ts.map +1 -0
  171. package/dist/src/services/__tests__/SubagentGenerator.helpers.test.js +61 -0
  172. package/dist/src/services/__tests__/SubagentGenerator.helpers.test.js.map +1 -0
  173. package/dist/src/services/__tests__/SubagentGenerator.test.js +155 -0
  174. package/dist/src/services/__tests__/SubagentGenerator.test.js.map +1 -1
  175. package/dist/src/services/__tests__/TransformationService.test.js +48 -0
  176. package/dist/src/services/__tests__/TransformationService.test.js.map +1 -1
  177. package/dist/src/services/agent-pack/agent-pack.test.js +1 -0
  178. package/dist/src/services/agent-pack/agent-pack.test.js.map +1 -1
  179. package/dist/src/services/agent-pack/prompt-source.d.ts +1 -1
  180. package/dist/src/services/agent-pack/prompt-source.d.ts.map +1 -1
  181. package/dist/src/services/agent-pack/prompt-source.js +10 -3
  182. package/dist/src/services/agent-pack/prompt-source.js.map +1 -1
  183. package/dist/src/services/agent-pack/types.d.ts +26 -2
  184. package/dist/src/services/agent-pack/types.d.ts.map +1 -1
  185. package/dist/src/services/agent-pack/types.js +13 -0
  186. package/dist/src/services/agent-pack/types.js.map +1 -1
  187. package/dist/src/services/agent-tool-profile.d.ts.map +1 -1
  188. package/dist/src/services/agent-tool-profile.js +7 -0
  189. package/dist/src/services/agent-tool-profile.js.map +1 -1
  190. package/dist/src/services/agent-tool-profile.test.js +2 -2
  191. package/dist/src/services/skill-content-comparison.d.ts +71 -0
  192. package/dist/src/services/skill-content-comparison.d.ts.map +1 -0
  193. package/dist/src/services/skill-content-comparison.js +90 -0
  194. package/dist/src/services/skill-content-comparison.js.map +1 -0
  195. package/dist/src/services/skill-content-comparison.test.d.ts +6 -0
  196. package/dist/src/services/skill-content-comparison.test.d.ts.map +1 -0
  197. package/dist/src/services/skill-content-comparison.test.js +83 -0
  198. package/dist/src/services/skill-content-comparison.test.js.map +1 -0
  199. package/dist/src/services/skill-identity-classification.d.ts +202 -0
  200. package/dist/src/services/skill-identity-classification.d.ts.map +1 -0
  201. package/dist/src/services/skill-identity-classification.js +295 -0
  202. package/dist/src/services/skill-identity-classification.js.map +1 -0
  203. package/dist/src/services/skill-identity-classification.test.d.ts +6 -0
  204. package/dist/src/services/skill-identity-classification.test.d.ts.map +1 -0
  205. package/dist/src/services/skill-identity-classification.test.js +314 -0
  206. package/dist/src/services/skill-identity-classification.test.js.map +1 -0
  207. package/dist/src/services/skill-installation.content.d.ts.map +1 -1
  208. package/dist/src/services/skill-installation.content.js +6 -1
  209. package/dist/src/services/skill-installation.content.js.map +1 -1
  210. package/dist/src/services/skill-installation.helpers.d.ts +8 -15
  211. package/dist/src/services/skill-installation.helpers.d.ts.map +1 -1
  212. package/dist/src/services/skill-installation.helpers.js +11 -105
  213. package/dist/src/services/skill-installation.helpers.js.map +1 -1
  214. package/dist/src/services/skill-installation.helpers.test.js +106 -1
  215. package/dist/src/services/skill-installation.helpers.test.js.map +1 -1
  216. package/dist/src/services/skill-installation.service.js +1 -1
  217. package/dist/src/services/skill-installation.service.js.map +1 -1
  218. package/dist/src/services/skill-installation.types.d.ts +33 -0
  219. package/dist/src/services/skill-installation.types.d.ts.map +1 -1
  220. package/dist/src/services/skill-installation.types.js.map +1 -1
  221. package/dist/src/services/skill-installation.uninstall.d.ts +84 -0
  222. package/dist/src/services/skill-installation.uninstall.d.ts.map +1 -0
  223. package/dist/src/services/skill-installation.uninstall.js +252 -0
  224. package/dist/src/services/skill-installation.uninstall.js.map +1 -0
  225. package/dist/src/services/skill-manifest.d.ts +41 -0
  226. package/dist/src/services/skill-manifest.d.ts.map +1 -1
  227. package/dist/src/services/skill-manifest.js +93 -0
  228. package/dist/src/services/skill-manifest.js.map +1 -1
  229. package/dist/src/services/skill-manifest.test.js +27 -0
  230. package/dist/src/services/skill-manifest.test.js.map +1 -1
  231. package/dist/src/sync/SyncEngine.d.ts.map +1 -1
  232. package/dist/src/sync/SyncEngine.js +69 -77
  233. package/dist/src/sync/SyncEngine.js.map +1 -1
  234. package/dist/src/telemetry/agent-marker.d.ts +8 -0
  235. package/dist/src/telemetry/agent-marker.d.ts.map +1 -1
  236. package/dist/src/telemetry/agent-marker.js +7 -0
  237. package/dist/src/telemetry/agent-marker.js.map +1 -1
  238. package/dist/src/telemetry/agent-marker.test.js +7 -1
  239. package/dist/src/telemetry/agent-marker.test.js.map +1 -1
  240. package/dist/src/telemetry/index.d.ts +1 -1
  241. package/dist/src/telemetry/index.d.ts.map +1 -1
  242. package/dist/src/telemetry/index.js +1 -1
  243. package/dist/src/telemetry/index.js.map +1 -1
  244. package/dist/src/telemetry/wrap.d.ts +6 -0
  245. package/dist/src/telemetry/wrap.d.ts.map +1 -1
  246. package/dist/src/telemetry/wrap.js +65 -10
  247. package/dist/src/telemetry/wrap.js.map +1 -1
  248. package/dist/src/telemetry/wrap.test.js +81 -1
  249. package/dist/src/telemetry/wrap.test.js.map +1 -1
  250. package/dist/src/telemetry/wrap.tool-call-sink.test.d.ts +26 -0
  251. package/dist/src/telemetry/wrap.tool-call-sink.test.d.ts.map +1 -0
  252. package/dist/src/telemetry/wrap.tool-call-sink.test.js +162 -0
  253. package/dist/src/telemetry/wrap.tool-call-sink.test.js.map +1 -0
  254. package/dist/src/types/skill.d.ts +9 -1
  255. package/dist/src/types/skill.d.ts.map +1 -1
  256. package/dist/src/utils/index.d.ts +1 -1
  257. package/dist/src/utils/index.d.ts.map +1 -1
  258. package/dist/src/utils/index.js +1 -1
  259. package/dist/src/utils/index.js.map +1 -1
  260. package/dist/src/utils/version-check.d.ts +61 -0
  261. package/dist/src/utils/version-check.d.ts.map +1 -1
  262. package/dist/src/utils/version-check.js +78 -1
  263. package/dist/src/utils/version-check.js.map +1 -1
  264. package/dist/src/utils/version-check.test.js +130 -1
  265. package/dist/src/utils/version-check.test.js.map +1 -1
  266. package/dist/tests/db/migration-runner-race.test.js +19 -9
  267. package/dist/tests/db/migration-runner-race.test.js.map +1 -1
  268. package/dist/tests/install/fan-out.test.js +27 -0
  269. package/dist/tests/install/fan-out.test.js.map +1 -1
  270. package/dist/tests/skill-scanner/allowlist.test.js +7 -1
  271. package/dist/tests/skill-scanner/allowlist.test.js.map +1 -1
  272. package/dist/tests/sync/SyncEngine.abort.test.js +15 -11
  273. package/dist/tests/sync/SyncEngine.abort.test.js.map +1 -1
  274. package/dist/tests/sync/SyncEngine.status.test.js +1 -1
  275. package/dist/tests/sync/SyncEngine.status.test.js.map +1 -1
  276. package/dist/tests/sync/SyncEngine.test.d.ts +11 -2
  277. package/dist/tests/sync/SyncEngine.test.d.ts.map +1 -1
  278. package/dist/tests/sync/SyncEngine.test.js +164 -13
  279. package/dist/tests/sync/SyncEngine.test.js.map +1 -1
  280. package/dist/tests/unit/migrations/migration-v18.test.d.ts +16 -0
  281. package/dist/tests/unit/migrations/migration-v18.test.d.ts.map +1 -0
  282. package/dist/tests/unit/migrations/migration-v18.test.js +192 -0
  283. package/dist/tests/unit/migrations/migration-v18.test.js.map +1 -0
  284. package/dist/tests/unit/services/skill-installation.content.test.js +65 -1
  285. package/dist/tests/unit/services/skill-installation.content.test.js.map +1 -1
  286. package/dist/tests/unit/services/skill-installation.service.test.js +9 -8
  287. package/dist/tests/unit/services/skill-installation.service.test.js.map +1 -1
  288. package/dist/tests/unit/sync-engine.source-aware.test.js +5 -5
  289. package/dist/tests/unit/sync-engine.source-aware.test.js.map +1 -1
  290. package/package.json +3 -3
@@ -0,0 +1,207 @@
1
+ /**
2
+ * ADR-139: Global-vs-Workspace Install Scope Resolution, Keyed by (Scope, Client, Name).
3
+ *
4
+ * @see docs/internal/adr/139-global-vs-workspace-install-scope-resolution.md
5
+ * @see SMI-6266, SMI-6274 (Wave 4), SMI-5894 (the (client, name) keying precedent this
6
+ * extends to scope), SMI-1630 (the repo-local-overrides-global promise this generalizes)
7
+ *
8
+ * Two scopes, both per-client:
9
+ * - `global` — `CLIENT_NATIVE_PATHS[client]` (unchanged).
10
+ * - `workspace` — `<workspace-root>/<client's workspace segments>`, from
11
+ * {@link CLIENT_WORKSPACE_SEGMENTS} (a sibling table to `CLIENT_NATIVE_PATHS`
12
+ * in `./paths.ts`).
13
+ *
14
+ * {@link findWorkspaceRoot} is deliberately NOT a reuse of
15
+ * `findMainRepoRoot()` (`packages/doc-retrieval-mcp/src/retrieval-log/project-dir.ts`).
16
+ * That helper requires `.git` to be a real DIRECTORY, specifically so it skips
17
+ * worktrees and returns the *main* repo root — correct for its own purpose
18
+ * (telemetry attribution) and exactly wrong here: `.git` is a *file* in both
19
+ * worktrees and submodules, and this repo's own default development workflow
20
+ * is worktree-based, so requiring a directory would resolve every worktree's
21
+ * workspace installs back to the main checkout. `findWorkspaceRoot()` tests
22
+ * path EXISTENCE (`existsSync`), never `isDirectory()`, for `.git` — the two
23
+ * walks are near-neighbours with deliberately OPPOSITE `.git` predicates; see
24
+ * `findMainRepoRoot()`'s own header note pointing back here.
25
+ */
26
+ import { type ClientId } from './paths.js';
27
+ export type InstallScope = 'global' | 'workspace';
28
+ /**
29
+ * Workspace-relative path segments per client, sibling table to
30
+ * `CLIENT_NATIVE_PATHS` (`./paths.ts`). `null` means the client has no
31
+ * documented workspace convention and can only ever resolve to `global`
32
+ * scope — adding one later is a table entry here, not a code change
33
+ * (ADR-139 Consequences / Neutral).
34
+ *
35
+ * Verified 2026-08-29 against `docs/internal/research/smi-5386-opencode-antigravity-skill-dirs.md`
36
+ * and ADR-139's own Decision §1: `antigravity` and `agents` deliberately
37
+ * share the SAME segments (`.agents/skills`) — AntiGravity reads project
38
+ * skills from the same open-standard cross-agent convention `agents`'
39
+ * GLOBAL path (`~/.agents/skills`) already uses, which is exactly the
40
+ * pathological case ADR-139 point 4's termination-before-candidacy fix
41
+ * exists for (see `findWorkspaceRoot` below).
42
+ */
43
+ export declare const CLIENT_WORKSPACE_SEGMENTS: Readonly<Record<ClientId, readonly string[] | null>>;
44
+ /** An explicit `--scope`/`SKILLSMITH_SCOPE` value that isn't `global`/`workspace`. */
45
+ export declare class InvalidScopeValueError extends Error {
46
+ constructor(message: string);
47
+ }
48
+ /**
49
+ * An explicit workspace-scope request (flag, env var, or config default)
50
+ * that cannot be satisfied — the client has no workspace convention, or no
51
+ * workspace root exists above `cwd`. ADR-139 point 2: this is a HARD ERROR,
52
+ * never a silent downgrade to global.
53
+ */
54
+ export declare class UnsatisfiableWorkspaceScopeError extends Error {
55
+ constructor(message: string);
56
+ }
57
+ /**
58
+ * Parse a raw `--scope`/`SKILLSMITH_SCOPE` string. Returns `undefined` for
59
+ * an absent/empty value (meaning "no opinion at this rank" — the caller
60
+ * falls through to the next precedence rank), and throws for anything
61
+ * present but not `global`/`workspace`.
62
+ */
63
+ export declare function parseInstallScope(raw: string | undefined | null): InstallScope | undefined;
64
+ /**
65
+ * Per-client persisted default scope from `~/.skillsmith/config.json`
66
+ * (`defaultScope.<client>`, e.g. `defaultScope.antigravity = "workspace"`).
67
+ * Fails soft (`undefined`) on any read/parse error — a corrupt config file
68
+ * must never crash scope resolution, only fall through to auto-detection.
69
+ */
70
+ export declare function getDefaultScopeForClient(client: ClientId): InstallScope | undefined;
71
+ export interface WorkspaceRootResult {
72
+ /** Absolute path to the resolved workspace root. */
73
+ root: string;
74
+ /** Which tier matched: the client's own marker directory, or a `.git` VCS boundary. */
75
+ via: 'marker' | 'vcs';
76
+ }
77
+ export interface FindWorkspaceRootOptions {
78
+ /**
79
+ * Override for `os.homedir()`'s return value. Defaults to the real
80
+ * `os.homedir()`. This is a test seam only (mirrors `agent-home-relocate.ts`'s
81
+ * `homeDir` override precedent elsewhere in this package) — production
82
+ * callers never pass it, and the walk otherwise ALWAYS sources home via
83
+ * `os.homedir()`, never manual `~` expansion (ADR-139 point 4,
84
+ * Windows-safety).
85
+ */
86
+ homeDirOverride?: string;
87
+ }
88
+ /**
89
+ * Resolve the nearest workspace root for `client` above (and including)
90
+ * `cwd`, or `null` when `cwd` is outside any workspace for that client.
91
+ *
92
+ * Implements ADR-139 point 4's algorithm EXACTLY, including its load-bearing
93
+ * ordering: at every directory in the walk, **termination is evaluated
94
+ * before candidacy**. An earlier draft of ADR-139 checked candidacy first,
95
+ * which meant a walk reaching `$HOME` would test `$HOME/<segments>` for a
96
+ * marker BEFORE applying "stop, no match" — and for the `agents` client,
97
+ * `$HOME/.agents/skills` IS the GLOBAL path, so that ordering collapsed
98
+ * global and workspace scope for that client. Termination-before-candidacy
99
+ * is the fix; do not reorder these two phases.
100
+ *
101
+ * `$HOME` is an EXCLUSIVE bound: the walk stops AT it without ever
102
+ * considering it as a candidate. `.git` existence is checked via
103
+ * `existsSync` (file OR directory) — see the module header for why this is
104
+ * the opposite predicate from `findMainRepoRoot()`.
105
+ */
106
+ export declare function findWorkspaceRoot(cwd: string, client: ClientId, options?: FindWorkspaceRootOptions): WorkspaceRootResult | null;
107
+ /** `<workspaceRoot>/.skillsmith/manifest.json` — self-scoping, self-cleaning (ADR-139 point 1). */
108
+ export declare function resolveWorkspaceManifestPath(workspaceRoot: string): string;
109
+ export interface ResolveScopeParams {
110
+ client: ClientId;
111
+ /** Defaults to `process.cwd()`. */
112
+ cwd?: string;
113
+ /**
114
+ * Rank 1 — explicit `--scope` flag value, if the caller parsed one. Typed
115
+ * `| undefined` explicitly (not just optional `?:`) so callers can pass
116
+ * `parseInstallScope(raw)`'s own `InstallScope | undefined` return value
117
+ * straight through under this repo's `exactOptionalPropertyTypes`.
118
+ */
119
+ explicitScope?: InstallScope | undefined;
120
+ /**
121
+ * Rank 2 — raw `SKILLSMITH_SCOPE` value. Defaults to
122
+ * `process.env.SKILLSMITH_SCOPE` when omitted (mirrors `resolveClientPath()`'s
123
+ * own override convention in `./paths.ts`). Pass `''` explicitly to force
124
+ * "no env value" in tests without touching real process env.
125
+ */
126
+ envScope?: string | undefined;
127
+ /**
128
+ * Rank 3 — per-client persisted default. Three states, distinguished by
129
+ * value (not by whether the key is present, since an optional TS property
130
+ * can't tell "present as undefined" from "absent" at runtime):
131
+ * - omitted / `undefined` — read the real default via
132
+ * `getDefaultScopeForClient(client)` (`~/.skillsmith/config.json`).
133
+ * - `null` — explicitly "no config default configured", WITHOUT
134
+ * touching the real config file. The test seam for isolating ranks
135
+ * 4-5 from a developer's real `~/.skillsmith/config.json`.
136
+ * - an actual `InstallScope` — used directly, also without touching disk.
137
+ */
138
+ configDefaultScope?: InstallScope | null;
139
+ /** Test seam — see {@link FindWorkspaceRootOptions.homeDirOverride}. */
140
+ homeDirOverride?: string;
141
+ }
142
+ export interface ResolvedSkillScope {
143
+ scope: InstallScope;
144
+ /** Absolute path to the resolved skills directory for this scope. */
145
+ dir: string;
146
+ /** Present only when `scope === 'workspace'`. */
147
+ workspaceRoot?: string;
148
+ /** Present only when `scope === 'workspace'`. */
149
+ via?: 'marker' | 'vcs';
150
+ /**
151
+ * `true` only when THIS call created the workspace directory — always
152
+ * `false` for `global` and for an already-existing workspace marker.
153
+ * Callers must print the absolute path they wrote when this is `true`
154
+ * (ADR-139 point 5).
155
+ */
156
+ created: boolean;
157
+ }
158
+ /**
159
+ * Resolve the install scope for one `(client, cwd)` pair per ADR-139 point 2's
160
+ * five-rank precedence:
161
+ *
162
+ * 1. Explicit `--scope` flag
163
+ * 2. `SKILLSMITH_SCOPE` env var
164
+ * 3. Per-client `~/.skillsmith/config.json` default
165
+ * 4. Auto-detection of an EXISTING workspace marker (read-only, never creates)
166
+ * 5. Global (default)
167
+ *
168
+ * Ranks 1-3 all represent an explicit request for a scope: requesting
169
+ * `workspace` at any of these ranks resolves via {@link findWorkspaceRoot}
170
+ * and, when the walk found a VCS boundary but no marker yet, CREATES the
171
+ * marker directory (`mkdirSync(..., { recursive: true })`) — this is the
172
+ * ONLY path that ever creates a workspace directory (ADR-139 point 5).
173
+ * Requesting `workspace` for a client with no workspace convention, or from
174
+ * outside any workspace entirely (no marker AND no ancestor `.git`), throws
175
+ * {@link UnsatisfiableWorkspaceScopeError} — never a silent downgrade.
176
+ *
177
+ * Rank 4 (auto-detection) is deliberately narrower: it only matches an
178
+ * EXISTING marker directory (`findWorkspaceRoot(...).via === 'marker'`) — a
179
+ * bare VCS boundary with no marker does NOT count as an auto-detected hit,
180
+ * and this rank never creates anything. Falling through this rank with no
181
+ * match resolves to rank 5 (global) silently and successfully — the
182
+ * ordinary case, not a warning-worthy one (ADR-139 point 6).
183
+ */
184
+ export declare function resolveSkillScope(params: ResolveScopeParams): ResolvedSkillScope;
185
+ export interface ScopedInstallTarget extends ResolvedSkillScope {
186
+ /**
187
+ * The manifest to record this install in: the workspace-local
188
+ * `<workspaceRoot>/.skillsmith/manifest.json` when `scope === 'workspace'`,
189
+ * else the global `~/.skillsmith/manifest.json` (or `globalManifestPath`
190
+ * when the caller passed one — CLI/MCP callers with their own resolved
191
+ * default should pass their own constant here so it stays byte-identical
192
+ * to `DEFAULT_MANIFEST_PATH` elsewhere, per ADR-139 point 1's requirement
193
+ * that the global manifest and `manifestKeyFor()`'s key shape are left
194
+ * completely untouched by this change).
195
+ */
196
+ manifestPath: string;
197
+ }
198
+ /**
199
+ * Convenience wrapper over {@link resolveSkillScope} that also resolves the
200
+ * manifest path to record the install in — the one call CLI/MCP commands
201
+ * need for `install`/`list`/`update`/`remove` (ADR-139 point 7: "One shared
202
+ * resolver, in core, for every command").
203
+ */
204
+ export declare function resolveScopedSkillsDir(params: ResolveScopeParams & {
205
+ globalManifestPath?: string;
206
+ }): ScopedInstallTarget;
207
+ //# sourceMappingURL=workspace-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-scope.d.ts","sourceRoot":"","sources":["../../../src/install/workspace-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAOH,OAAO,EAAuB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAA;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G;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;;;;;;;OAUG;IACH,kBAAkB,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IACxC,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,YAAY,CAAA;IACnB,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAA;IACX,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,iDAAiD;IACjD,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;IACtB;;;;;OAKG;IACH,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAyEhF;AAED,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D;;;;;;;;;OASG;IACH,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,kBAAkB,GAAG;IAAE,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3D,mBAAmB,CAOrB"}
@@ -0,0 +1,275 @@
1
+ /**
2
+ * ADR-139: Global-vs-Workspace Install Scope Resolution, Keyed by (Scope, Client, Name).
3
+ *
4
+ * @see docs/internal/adr/139-global-vs-workspace-install-scope-resolution.md
5
+ * @see SMI-6266, SMI-6274 (Wave 4), SMI-5894 (the (client, name) keying precedent this
6
+ * extends to scope), SMI-1630 (the repo-local-overrides-global promise this generalizes)
7
+ *
8
+ * Two scopes, both per-client:
9
+ * - `global` — `CLIENT_NATIVE_PATHS[client]` (unchanged).
10
+ * - `workspace` — `<workspace-root>/<client's workspace segments>`, from
11
+ * {@link CLIENT_WORKSPACE_SEGMENTS} (a sibling table to `CLIENT_NATIVE_PATHS`
12
+ * in `./paths.ts`).
13
+ *
14
+ * {@link findWorkspaceRoot} is deliberately NOT a reuse of
15
+ * `findMainRepoRoot()` (`packages/doc-retrieval-mcp/src/retrieval-log/project-dir.ts`).
16
+ * That helper requires `.git` to be a real DIRECTORY, specifically so it skips
17
+ * worktrees and returns the *main* repo root — correct for its own purpose
18
+ * (telemetry attribution) and exactly wrong here: `.git` is a *file* in both
19
+ * worktrees and submodules, and this repo's own default development workflow
20
+ * is worktree-based, so requiring a directory would resolve every worktree's
21
+ * workspace installs back to the main checkout. `findWorkspaceRoot()` tests
22
+ * path EXISTENCE (`existsSync`), never `isDirectory()`, for `.git` — the two
23
+ * walks are near-neighbours with deliberately OPPOSITE `.git` predicates; see
24
+ * `findMainRepoRoot()`'s own header note pointing back here.
25
+ */
26
+ import { existsSync, mkdirSync } from 'node:fs';
27
+ import { homedir } from 'node:os';
28
+ import { dirname, join, resolve } from 'node:path';
29
+ import { loadConfig } from '../config/index.js';
30
+ import { CLIENT_NATIVE_PATHS } from './paths.js';
31
+ /**
32
+ * Workspace-relative path segments per client, sibling table to
33
+ * `CLIENT_NATIVE_PATHS` (`./paths.ts`). `null` means the client has no
34
+ * documented workspace convention and can only ever resolve to `global`
35
+ * scope — adding one later is a table entry here, not a code change
36
+ * (ADR-139 Consequences / Neutral).
37
+ *
38
+ * Verified 2026-08-29 against `docs/internal/research/smi-5386-opencode-antigravity-skill-dirs.md`
39
+ * and ADR-139's own Decision §1: `antigravity` and `agents` deliberately
40
+ * share the SAME segments (`.agents/skills`) — AntiGravity reads project
41
+ * skills from the same open-standard cross-agent convention `agents`'
42
+ * GLOBAL path (`~/.agents/skills`) already uses, which is exactly the
43
+ * pathological case ADR-139 point 4's termination-before-candidacy fix
44
+ * exists for (see `findWorkspaceRoot` below).
45
+ */
46
+ export const CLIENT_WORKSPACE_SEGMENTS = {
47
+ 'claude-code': ['.claude', 'skills'],
48
+ cursor: ['.cursor', 'skills'],
49
+ copilot: null,
50
+ windsurf: null,
51
+ agents: ['.agents', 'skills'],
52
+ opencode: ['.opencode', 'skills'],
53
+ hermes: null,
54
+ grok: null,
55
+ antigravity: ['.agents', 'skills'],
56
+ };
57
+ // ---------------------------------------------------------------------------
58
+ // Errors
59
+ // ---------------------------------------------------------------------------
60
+ /** An explicit `--scope`/`SKILLSMITH_SCOPE` value that isn't `global`/`workspace`. */
61
+ export class InvalidScopeValueError extends Error {
62
+ constructor(message) {
63
+ super(message);
64
+ this.name = 'InvalidScopeValueError';
65
+ }
66
+ }
67
+ /**
68
+ * An explicit workspace-scope request (flag, env var, or config default)
69
+ * that cannot be satisfied — the client has no workspace convention, or no
70
+ * workspace root exists above `cwd`. ADR-139 point 2: this is a HARD ERROR,
71
+ * never a silent downgrade to global.
72
+ */
73
+ export class UnsatisfiableWorkspaceScopeError extends Error {
74
+ constructor(message) {
75
+ super(message);
76
+ this.name = 'UnsatisfiableWorkspaceScopeError';
77
+ }
78
+ }
79
+ /**
80
+ * Parse a raw `--scope`/`SKILLSMITH_SCOPE` string. Returns `undefined` for
81
+ * an absent/empty value (meaning "no opinion at this rank" — the caller
82
+ * falls through to the next precedence rank), and throws for anything
83
+ * present but not `global`/`workspace`.
84
+ */
85
+ export function parseInstallScope(raw) {
86
+ if (raw === undefined || raw === null || raw === '')
87
+ return undefined;
88
+ if (raw === 'global' || raw === 'workspace')
89
+ return raw;
90
+ throw new InvalidScopeValueError(`Invalid scope '${raw}'. Valid values: global | workspace.`);
91
+ }
92
+ function isInstallScope(value) {
93
+ return value === 'global' || value === 'workspace';
94
+ }
95
+ /**
96
+ * Per-client persisted default scope from `~/.skillsmith/config.json`
97
+ * (`defaultScope.<client>`, e.g. `defaultScope.antigravity = "workspace"`).
98
+ * Fails soft (`undefined`) on any read/parse error — a corrupt config file
99
+ * must never crash scope resolution, only fall through to auto-detection.
100
+ */
101
+ export function getDefaultScopeForClient(client) {
102
+ try {
103
+ const config = loadConfig();
104
+ const raw = config.defaultScope?.[client];
105
+ return isInstallScope(raw) ? raw : undefined;
106
+ }
107
+ catch {
108
+ return undefined;
109
+ }
110
+ }
111
+ // ---------------------------------------------------------------------------
112
+ // Ancestor-search boundary (ADR-139 points 3 + 4)
113
+ // ---------------------------------------------------------------------------
114
+ /**
115
+ * Loop guard against symlink cycles / pathological mounts — matches the cap
116
+ * `findMainRepoRoot()` (`project-dir.ts`) already uses, so the two walks
117
+ * agree on their one shared parameter rather than picking independent
118
+ * numbers. NOT a configurable max depth (ADR-139 point 4): a configurable
119
+ * cap makes the same command behave differently on two machines and is
120
+ * effectively undebuggable when it silently stops one level short of a
121
+ * marker.
122
+ */
123
+ const MAX_ANCESTOR_WALK_DEPTH = 64;
124
+ /**
125
+ * Resolve the nearest workspace root for `client` above (and including)
126
+ * `cwd`, or `null` when `cwd` is outside any workspace for that client.
127
+ *
128
+ * Implements ADR-139 point 4's algorithm EXACTLY, including its load-bearing
129
+ * ordering: at every directory in the walk, **termination is evaluated
130
+ * before candidacy**. An earlier draft of ADR-139 checked candidacy first,
131
+ * which meant a walk reaching `$HOME` would test `$HOME/<segments>` for a
132
+ * marker BEFORE applying "stop, no match" — and for the `agents` client,
133
+ * `$HOME/.agents/skills` IS the GLOBAL path, so that ordering collapsed
134
+ * global and workspace scope for that client. Termination-before-candidacy
135
+ * is the fix; do not reorder these two phases.
136
+ *
137
+ * `$HOME` is an EXCLUSIVE bound: the walk stops AT it without ever
138
+ * considering it as a candidate. `.git` existence is checked via
139
+ * `existsSync` (file OR directory) — see the module header for why this is
140
+ * the opposite predicate from `findMainRepoRoot()`.
141
+ */
142
+ export function findWorkspaceRoot(cwd, client, options = {}) {
143
+ const segments = CLIENT_WORKSPACE_SEGMENTS[client];
144
+ if (!segments)
145
+ return null;
146
+ const home = options.homeDirOverride ?? homedir();
147
+ let current = resolve(cwd);
148
+ let vcsFallback = null;
149
+ for (let depth = 0; depth < MAX_ANCESTOR_WALK_DEPTH; depth += 1) {
150
+ // ---- PHASE 1: TERMINATION (always first — see doc comment above) ----
151
+ if (current === home)
152
+ break;
153
+ // ---- PHASE 2: CANDIDACY (only for directories that survived phase 1) ----
154
+ if (existsSync(join(current, ...segments))) {
155
+ return { root: current, via: 'marker' };
156
+ }
157
+ if (existsSync(join(current, '.git'))) {
158
+ vcsFallback = current;
159
+ break; // the first VCS boundary also terminates the marker search
160
+ }
161
+ const parent = dirname(current);
162
+ if (parent === current)
163
+ break; // filesystem root
164
+ current = parent;
165
+ }
166
+ return vcsFallback ? { root: vcsFallback, via: 'vcs' } : null;
167
+ }
168
+ /** `<workspaceRoot>/.skillsmith/manifest.json` — self-scoping, self-cleaning (ADR-139 point 1). */
169
+ export function resolveWorkspaceManifestPath(workspaceRoot) {
170
+ return join(workspaceRoot, '.skillsmith', 'manifest.json');
171
+ }
172
+ function defaultGlobalManifestPath() {
173
+ return join(homedir(), '.skillsmith', 'manifest.json');
174
+ }
175
+ /**
176
+ * Resolve the install scope for one `(client, cwd)` pair per ADR-139 point 2's
177
+ * five-rank precedence:
178
+ *
179
+ * 1. Explicit `--scope` flag
180
+ * 2. `SKILLSMITH_SCOPE` env var
181
+ * 3. Per-client `~/.skillsmith/config.json` default
182
+ * 4. Auto-detection of an EXISTING workspace marker (read-only, never creates)
183
+ * 5. Global (default)
184
+ *
185
+ * Ranks 1-3 all represent an explicit request for a scope: requesting
186
+ * `workspace` at any of these ranks resolves via {@link findWorkspaceRoot}
187
+ * and, when the walk found a VCS boundary but no marker yet, CREATES the
188
+ * marker directory (`mkdirSync(..., { recursive: true })`) — this is the
189
+ * ONLY path that ever creates a workspace directory (ADR-139 point 5).
190
+ * Requesting `workspace` for a client with no workspace convention, or from
191
+ * outside any workspace entirely (no marker AND no ancestor `.git`), throws
192
+ * {@link UnsatisfiableWorkspaceScopeError} — never a silent downgrade.
193
+ *
194
+ * Rank 4 (auto-detection) is deliberately narrower: it only matches an
195
+ * EXISTING marker directory (`findWorkspaceRoot(...).via === 'marker'`) — a
196
+ * bare VCS boundary with no marker does NOT count as an auto-detected hit,
197
+ * and this rank never creates anything. Falling through this rank with no
198
+ * match resolves to rank 5 (global) silently and successfully — the
199
+ * ordinary case, not a warning-worthy one (ADR-139 point 6).
200
+ */
201
+ export function resolveSkillScope(params) {
202
+ const { client } = params;
203
+ const cwd = params.cwd ?? process.cwd();
204
+ const segments = CLIENT_WORKSPACE_SEGMENTS[client];
205
+ const findOpts = params.homeDirOverride !== undefined ? { homeDirOverride: params.homeDirOverride } : {};
206
+ const fromFlag = params.explicitScope;
207
+ const envRaw = params.envScope !== undefined ? params.envScope : process.env['SKILLSMITH_SCOPE'];
208
+ const fromEnv = fromFlag === undefined ? parseInstallScope(envRaw) : undefined;
209
+ const fromConfig = fromFlag === undefined && fromEnv === undefined
210
+ ? params.configDefaultScope === undefined
211
+ ? getDefaultScopeForClient(client)
212
+ : (params.configDefaultScope ?? undefined)
213
+ : undefined;
214
+ const requested = fromFlag ?? fromEnv ?? fromConfig;
215
+ const requestSource = fromFlag !== undefined
216
+ ? 'the --scope flag'
217
+ : fromEnv !== undefined
218
+ ? 'the SKILLSMITH_SCOPE environment variable'
219
+ : fromConfig !== undefined
220
+ ? `the ~/.skillsmith/config.json default for '${client}'`
221
+ : undefined;
222
+ if (requested === 'global') {
223
+ return { scope: 'global', dir: CLIENT_NATIVE_PATHS[client], created: false };
224
+ }
225
+ if (requested === 'workspace') {
226
+ if (!segments) {
227
+ throw new UnsatisfiableWorkspaceScopeError(`Workspace scope was requested (via ${requestSource}) but client '${client}' has no ` +
228
+ `documented workspace convention — it can only be installed at global scope.`);
229
+ }
230
+ const found = findWorkspaceRoot(cwd, client, findOpts);
231
+ if (!found) {
232
+ throw new UnsatisfiableWorkspaceScopeError(`Workspace scope was requested (via ${requestSource}) but no workspace root was found ` +
233
+ `at or above '${cwd}' — no existing ${segments.join('/')} directory and no ancestor ` +
234
+ `.git. Run this from inside a repository, or drop --scope to install globally.`);
235
+ }
236
+ const dir = join(found.root, ...segments);
237
+ if (found.via === 'marker') {
238
+ return { scope: 'workspace', dir, workspaceRoot: found.root, via: 'marker', created: false };
239
+ }
240
+ // via === 'vcs': no marker exists on disk yet. An explicit workspace
241
+ // request (any of ranks 1-3) is the ONLY thing permitted to create one.
242
+ mkdirSync(dir, { recursive: true });
243
+ return { scope: 'workspace', dir, workspaceRoot: found.root, via: 'vcs', created: true };
244
+ }
245
+ // Rank 4: auto-detection. Only an EXISTING marker counts — never the bare
246
+ // VCS fallback, and this rank never creates anything.
247
+ if (segments) {
248
+ const found = findWorkspaceRoot(cwd, client, findOpts);
249
+ if (found && found.via === 'marker') {
250
+ return {
251
+ scope: 'workspace',
252
+ dir: join(found.root, ...segments),
253
+ workspaceRoot: found.root,
254
+ via: 'marker',
255
+ created: false,
256
+ };
257
+ }
258
+ }
259
+ // Rank 5: global, silently and successfully.
260
+ return { scope: 'global', dir: CLIENT_NATIVE_PATHS[client], created: false };
261
+ }
262
+ /**
263
+ * Convenience wrapper over {@link resolveSkillScope} that also resolves the
264
+ * manifest path to record the install in — the one call CLI/MCP commands
265
+ * need for `install`/`list`/`update`/`remove` (ADR-139 point 7: "One shared
266
+ * resolver, in core, for every command").
267
+ */
268
+ export function resolveScopedSkillsDir(params) {
269
+ const resolved = resolveSkillScope(params);
270
+ const manifestPath = resolved.scope === 'workspace' && resolved.workspaceRoot
271
+ ? resolveWorkspaceManifestPath(resolved.workspaceRoot)
272
+ : (params.globalManifestPath ?? defaultGlobalManifestPath());
273
+ return { ...resolved, manifestPath };
274
+ }
275
+ //# sourceMappingURL=workspace-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-scope.js","sourceRoot":"","sources":["../../../src/install/workspace-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAElD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AAG,EAAE,mBAAmB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AAC9E,CAAC;AAgBD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAA4D;IAE5D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAC1C,MAAM,YAAY,GAChB,QAAQ,CAAC,KAAK,KAAK,WAAW,IAAI,QAAQ,CAAC,aAAa;QACtD,CAAC,CAAC,4BAA4B,CAAC,QAAQ,CAAC,aAAa,CAAC;QACtD,CAAC,CAAC,CAAC,MAAM,CAAC,kBAAkB,IAAI,yBAAyB,EAAE,CAAC,CAAA;IAChE,OAAO,EAAE,GAAG,QAAQ,EAAE,YAAY,EAAE,CAAA;AACtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=workspace-scope.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-scope.test.d.ts","sourceRoot":"","sources":["../../../src/install/workspace-scope.test.ts"],"names":[],"mappings":""}