akm-cli 0.6.1 → 0.7.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 (333) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/{cli.js → src/cli.js} +712 -34
  3. package/dist/{commands → src/commands}/config-cli.js +47 -4
  4. package/dist/src/commands/distill.js +283 -0
  5. package/dist/src/commands/events.js +108 -0
  6. package/dist/src/commands/history.js +191 -0
  7. package/dist/{commands → src/commands}/installed-stashes.js +1 -1
  8. package/dist/src/commands/proposal.js +119 -0
  9. package/dist/src/commands/propose.js +171 -0
  10. package/dist/src/commands/reflect.js +193 -0
  11. package/dist/{commands → src/commands}/registry-search.js +71 -7
  12. package/dist/{commands → src/commands}/remember.js +12 -0
  13. package/dist/{commands → src/commands}/search.js +104 -4
  14. package/dist/{commands → src/commands}/self-update.js +4 -3
  15. package/dist/{commands → src/commands}/show.js +73 -0
  16. package/dist/{commands → src/commands}/source-add.js +5 -1
  17. package/dist/{commands → src/commands}/source-manage.js +7 -1
  18. package/dist/{core → src/core}/asset-ref.js +5 -5
  19. package/dist/{core → src/core}/asset-spec.js +12 -0
  20. package/dist/{core → src/core}/common.js +1 -1
  21. package/dist/{core → src/core}/config.js +203 -121
  22. package/dist/{core → src/core}/errors.js +4 -0
  23. package/dist/src/core/events.js +239 -0
  24. package/dist/src/core/lesson-lint.js +86 -0
  25. package/dist/src/core/proposals.js +406 -0
  26. package/dist/src/core/warn.js +72 -0
  27. package/dist/{core → src/core}/write-source.js +80 -5
  28. package/dist/{indexer → src/indexer}/db-search.js +114 -24
  29. package/dist/{indexer → src/indexer}/db.js +76 -23
  30. package/dist/{indexer → src/indexer}/file-context.js +0 -3
  31. package/dist/src/indexer/graph-boost.js +179 -0
  32. package/dist/src/indexer/graph-extraction.js +212 -0
  33. package/dist/{indexer → src/indexer}/indexer.js +88 -7
  34. package/dist/{indexer → src/indexer}/matchers.js +1 -1
  35. package/dist/src/indexer/memory-inference.js +263 -0
  36. package/dist/{indexer → src/indexer}/metadata.js +111 -3
  37. package/dist/{indexer → src/indexer}/search-source.js +4 -2
  38. package/dist/src/integrations/agent/config.js +292 -0
  39. package/dist/src/integrations/agent/detect.js +94 -0
  40. package/dist/src/integrations/agent/index.js +17 -0
  41. package/dist/src/integrations/agent/profiles.js +65 -0
  42. package/dist/src/integrations/agent/prompts.js +167 -0
  43. package/dist/src/integrations/agent/spawn.js +272 -0
  44. package/dist/{integrations → src/integrations}/github.js +9 -3
  45. package/dist/{integrations → src/integrations}/lockfile.js +0 -26
  46. package/dist/{llm → src/llm}/client.js +33 -2
  47. package/dist/{llm → src/llm}/embedders/remote.js +37 -3
  48. package/dist/src/llm/feature-gate.js +108 -0
  49. package/dist/src/llm/graph-extract.js +107 -0
  50. package/dist/src/llm/index-passes.js +35 -0
  51. package/dist/src/llm/memory-infer.js +86 -0
  52. package/dist/{output → src/output}/cli-hints.js +15 -2
  53. package/dist/{output → src/output}/renderers.js +63 -2
  54. package/dist/src/output/shapes.js +523 -0
  55. package/dist/src/output/text.js +1116 -0
  56. package/dist/{registry → src/registry}/build-index.js +19 -8
  57. package/dist/{registry → src/registry}/factory.js +0 -8
  58. package/dist/{registry → src/registry}/providers/static-index.js +6 -3
  59. package/dist/{registry → src/registry}/resolve.js +68 -2
  60. package/dist/{setup → src/setup}/setup.js +52 -5
  61. package/dist/{sources → src/sources}/providers/git.js +7 -15
  62. package/dist/{wiki → src/wiki}/wiki.js +54 -6
  63. package/dist/{workflows → src/workflows}/runs.js +37 -3
  64. package/dist/tests/add-website-source.test.js +119 -0
  65. package/dist/tests/agent/agent-config-loader.test.js +70 -0
  66. package/dist/tests/agent/agent-config.test.js +221 -0
  67. package/dist/tests/agent/agent-detect.test.js +100 -0
  68. package/dist/tests/agent/agent-spawn.test.js +234 -0
  69. package/dist/tests/agent-output.test.js +186 -0
  70. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
  71. package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
  72. package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
  73. package/dist/tests/asset-ref.test.js +192 -0
  74. package/dist/tests/asset-registry.test.js +103 -0
  75. package/dist/tests/asset-spec.test.js +241 -0
  76. package/dist/tests/bench/attribution.test.js +996 -0
  77. package/dist/tests/bench/cleanup-sigint.test.js +83 -0
  78. package/dist/tests/bench/cleanup.js +234 -0
  79. package/dist/tests/bench/cleanup.test.js +166 -0
  80. package/dist/tests/bench/cli.js +1018 -0
  81. package/dist/tests/bench/cli.test.js +445 -0
  82. package/dist/tests/bench/compare.test.js +556 -0
  83. package/dist/tests/bench/corpus.js +317 -0
  84. package/dist/tests/bench/corpus.test.js +258 -0
  85. package/dist/tests/bench/doctor.js +525 -0
  86. package/dist/tests/bench/driver.js +401 -0
  87. package/dist/tests/bench/driver.test.js +584 -0
  88. package/dist/tests/bench/environment.js +233 -0
  89. package/dist/tests/bench/environment.test.js +199 -0
  90. package/dist/tests/bench/evolve-metrics.js +179 -0
  91. package/dist/tests/bench/evolve-metrics.test.js +187 -0
  92. package/dist/tests/bench/evolve.js +647 -0
  93. package/dist/tests/bench/evolve.test.js +624 -0
  94. package/dist/tests/bench/failure-modes.test.js +349 -0
  95. package/dist/tests/bench/feedback-integrity.test.js +457 -0
  96. package/dist/tests/bench/leakage.test.js +228 -0
  97. package/dist/tests/bench/learning-curve.test.js +134 -0
  98. package/dist/tests/bench/metrics.js +2395 -0
  99. package/dist/tests/bench/metrics.test.js +1150 -0
  100. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
  101. package/dist/tests/bench/opencode-config.js +194 -0
  102. package/dist/tests/bench/opencode-config.test.js +370 -0
  103. package/dist/tests/bench/report.js +1885 -0
  104. package/dist/tests/bench/report.test.js +1038 -0
  105. package/dist/tests/bench/run-config.js +355 -0
  106. package/dist/tests/bench/run-config.test.js +298 -0
  107. package/dist/tests/bench/run-curate-test.js +32 -0
  108. package/dist/tests/bench/run-failing-tasks.js +56 -0
  109. package/dist/tests/bench/run-full-bench.js +51 -0
  110. package/dist/tests/bench/run-items36-targeted.js +69 -0
  111. package/dist/tests/bench/run-nano-quick.js +42 -0
  112. package/dist/tests/bench/run-waveg-targeted.js +62 -0
  113. package/dist/tests/bench/runner.js +699 -0
  114. package/dist/tests/bench/runner.test.js +958 -0
  115. package/dist/tests/bench/search-bridge.test.js +331 -0
  116. package/dist/tests/bench/tmp.js +131 -0
  117. package/dist/tests/bench/trajectory.js +116 -0
  118. package/dist/tests/bench/trajectory.test.js +127 -0
  119. package/dist/tests/bench/verifier.js +114 -0
  120. package/dist/tests/bench/verifier.test.js +118 -0
  121. package/dist/tests/bench/workflow-evaluator.js +557 -0
  122. package/dist/tests/bench/workflow-evaluator.test.js +421 -0
  123. package/dist/tests/bench/workflow-spec.js +345 -0
  124. package/dist/tests/bench/workflow-spec.test.js +363 -0
  125. package/dist/tests/bench/workflow-trace.js +472 -0
  126. package/dist/tests/bench/workflow-trace.test.js +254 -0
  127. package/dist/tests/benchmark-search-quality.js +536 -0
  128. package/dist/tests/benchmark-suite.js +1441 -0
  129. package/dist/tests/capture-cli.test.js +112 -0
  130. package/dist/tests/cli-errors.test.js +204 -0
  131. package/dist/tests/commands/events.test.js +370 -0
  132. package/dist/tests/commands/history.test.js +418 -0
  133. package/dist/tests/commands/import.test.js +103 -0
  134. package/dist/tests/commands/proposal-cli.test.js +209 -0
  135. package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
  136. package/dist/tests/commands/remember.test.js +97 -0
  137. package/dist/tests/commands/scope-flags.test.js +300 -0
  138. package/dist/tests/commands/search.test.js +537 -0
  139. package/dist/tests/commands/show-indexer-parity.test.js +117 -0
  140. package/dist/tests/commands/show.test.js +294 -0
  141. package/dist/tests/common.test.js +266 -0
  142. package/dist/tests/completions.test.js +142 -0
  143. package/dist/tests/config-cli.test.js +193 -0
  144. package/dist/tests/config-llm-features.test.js +139 -0
  145. package/dist/tests/config.test.js +569 -0
  146. package/dist/tests/contracts/migration-baseline.test.js +43 -0
  147. package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
  148. package/dist/tests/contracts/spec-helpers.js +46 -0
  149. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
  150. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
  151. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
  152. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
  153. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
  154. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
  155. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
  156. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
  157. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
  158. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
  159. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
  160. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
  161. package/dist/tests/core/write-source.test.js +366 -0
  162. package/dist/tests/curate-command.test.js +87 -0
  163. package/dist/tests/db-scoring.test.js +201 -0
  164. package/dist/tests/db.test.js +654 -0
  165. package/dist/tests/distill-cli-flag.test.js +208 -0
  166. package/dist/tests/distill.test.js +515 -0
  167. package/dist/tests/docker-install.test.js +120 -0
  168. package/dist/tests/e2e.test.js +1419 -0
  169. package/dist/tests/embedder.test.js +340 -0
  170. package/dist/tests/embedding-model-config.test.js +379 -0
  171. package/dist/tests/feedback-command.test.js +172 -0
  172. package/dist/tests/file-context.test.js +552 -0
  173. package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
  174. package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
  175. package/dist/tests/fixtures/stashes/load.js +166 -0
  176. package/dist/tests/fixtures/stashes/load.test.js +97 -0
  177. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
  178. package/dist/tests/frontmatter.test.js +190 -0
  179. package/dist/tests/fts-field-weighting.test.js +254 -0
  180. package/dist/tests/fuzzy-search.test.js +230 -0
  181. package/dist/tests/git-provider-clone.test.js +45 -0
  182. package/dist/tests/github.test.js +161 -0
  183. package/dist/tests/graph-boost-ranking.test.js +305 -0
  184. package/dist/tests/graph-extraction.test.js +282 -0
  185. package/dist/tests/helpers/usage-events.js +8 -0
  186. package/dist/tests/index-pass-llm.test.js +161 -0
  187. package/dist/tests/indexer.test.js +570 -0
  188. package/dist/tests/info-command.test.js +166 -0
  189. package/dist/tests/init.test.js +69 -0
  190. package/dist/tests/install-script.test.js +246 -0
  191. package/dist/tests/integration/agent-real-profile.test.js +94 -0
  192. package/dist/tests/issue-36-repro.test.js +304 -0
  193. package/dist/tests/issues-191-194.test.js +160 -0
  194. package/dist/tests/lesson-lint.test.js +111 -0
  195. package/dist/tests/llm-client.test.js +115 -0
  196. package/dist/tests/llm-feature-gate.test.js +151 -0
  197. package/dist/tests/llm.test.js +139 -0
  198. package/dist/tests/lockfile.test.js +216 -0
  199. package/dist/tests/manifest.test.js +205 -0
  200. package/dist/tests/markdown.test.js +126 -0
  201. package/dist/tests/matchers-unit.test.js +189 -0
  202. package/dist/tests/memory-inference.test.js +299 -0
  203. package/dist/tests/merge-scoring.test.js +136 -0
  204. package/dist/tests/metadata.test.js +313 -0
  205. package/dist/tests/migration-help.test.js +89 -0
  206. package/dist/tests/origin-resolve.test.js +124 -0
  207. package/dist/tests/output-baseline.test.js +218 -0
  208. package/dist/tests/output-shapes-unit.test.js +478 -0
  209. package/dist/tests/parallel-search.test.js +272 -0
  210. package/dist/tests/parameter-metadata.test.js +365 -0
  211. package/dist/tests/paths.test.js +177 -0
  212. package/dist/tests/progressive-disclosure.test.js +280 -0
  213. package/dist/tests/proposals.test.js +279 -0
  214. package/dist/tests/proposed-quality.test.js +271 -0
  215. package/dist/tests/provider-registry.test.js +32 -0
  216. package/dist/tests/ranking-regression.test.js +548 -0
  217. package/dist/tests/reflect-propose.test.js +455 -0
  218. package/dist/tests/registry-build-index.test.js +394 -0
  219. package/dist/tests/registry-cli.test.js +290 -0
  220. package/dist/tests/registry-index-v2.test.js +430 -0
  221. package/dist/tests/registry-install.test.js +728 -0
  222. package/dist/tests/registry-providers/parity.test.js +189 -0
  223. package/dist/tests/registry-providers/skills-sh.test.js +309 -0
  224. package/dist/tests/registry-providers/static-index.test.js +238 -0
  225. package/dist/tests/registry-resolve.test.js +126 -0
  226. package/dist/tests/registry-search.test.js +923 -0
  227. package/dist/tests/remember-frontmatter.test.js +378 -0
  228. package/dist/tests/remember-unit.test.js +123 -0
  229. package/dist/tests/ripgrep-install.test.js +251 -0
  230. package/dist/tests/ripgrep-resolve.test.js +108 -0
  231. package/dist/tests/ripgrep.test.js +163 -0
  232. package/dist/tests/save-command.test.js +94 -0
  233. package/dist/tests/save-trust-qa-fixes.test.js +270 -0
  234. package/dist/tests/scoring-pipeline.test.js +648 -0
  235. package/dist/tests/search-include-proposed-cli.test.js +118 -0
  236. package/dist/tests/self-update.test.js +442 -0
  237. package/dist/tests/semantic-search-e2e.test.js +512 -0
  238. package/dist/tests/semantic-status.test.js +471 -0
  239. package/dist/tests/setup-run.integration.js +877 -0
  240. package/dist/tests/setup-wizard.test.js +198 -0
  241. package/dist/tests/setup.test.js +131 -0
  242. package/dist/tests/source-add.test.js +11 -0
  243. package/dist/tests/source-clone.test.js +254 -0
  244. package/dist/tests/source-manage.test.js +366 -0
  245. package/dist/tests/source-providers/filesystem.test.js +82 -0
  246. package/dist/tests/source-providers/git.test.js +252 -0
  247. package/dist/tests/source-providers/website.test.js +128 -0
  248. package/dist/tests/source-qa-fixes.test.js +286 -0
  249. package/dist/tests/source-registry.test.js +350 -0
  250. package/dist/tests/source-resolve.test.js +100 -0
  251. package/dist/tests/source-source.test.js +281 -0
  252. package/dist/tests/source.test.js +533 -0
  253. package/dist/tests/tar-utils-scan.test.js +73 -0
  254. package/dist/tests/toggle-components.test.js +73 -0
  255. package/dist/tests/usage-telemetry.test.js +265 -0
  256. package/dist/tests/utility-scoring.test.js +558 -0
  257. package/dist/tests/vault-load-error.test.js +78 -0
  258. package/dist/tests/vault-qa-fixes.test.js +194 -0
  259. package/dist/tests/vault.test.js +429 -0
  260. package/dist/tests/vector-search.test.js +608 -0
  261. package/dist/tests/walker.test.js +252 -0
  262. package/dist/tests/wave2-cluster-bc.test.js +228 -0
  263. package/dist/tests/wave2-cluster-d.test.js +180 -0
  264. package/dist/tests/wave2-cluster-e.test.js +179 -0
  265. package/dist/tests/wiki-qa-fixes.test.js +270 -0
  266. package/dist/tests/wiki.test.js +529 -0
  267. package/dist/tests/workflow-cli.test.js +271 -0
  268. package/dist/tests/workflow-markdown.test.js +171 -0
  269. package/dist/tests/workflow-path-escape.test.js +132 -0
  270. package/dist/tests/workflow-qa-fixes.test.js +395 -0
  271. package/dist/tests/workflows/indexer-rejection.test.js +213 -0
  272. package/docs/README.md +8 -0
  273. package/docs/migration/release-notes/0.7.0.md +244 -0
  274. package/package.json +2 -2
  275. package/dist/core/warn.js +0 -27
  276. package/dist/output/shapes.js +0 -212
  277. package/dist/output/text.js +0 -520
  278. /package/dist/{commands → src/commands}/completions.js +0 -0
  279. /package/dist/{commands → src/commands}/curate.js +0 -0
  280. /package/dist/{commands → src/commands}/info.js +0 -0
  281. /package/dist/{commands → src/commands}/init.js +0 -0
  282. /package/dist/{commands → src/commands}/install-audit.js +0 -0
  283. /package/dist/{commands → src/commands}/migration-help.js +0 -0
  284. /package/dist/{commands → src/commands}/source-clone.js +0 -0
  285. /package/dist/{commands → src/commands}/vault.js +0 -0
  286. /package/dist/{core → src/core}/asset-registry.js +0 -0
  287. /package/dist/{core → src/core}/frontmatter.js +0 -0
  288. /package/dist/{core → src/core}/markdown.js +0 -0
  289. /package/dist/{core → src/core}/paths.js +0 -0
  290. /package/dist/{indexer → src/indexer}/manifest.js +0 -0
  291. /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
  292. /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
  293. /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
  294. /package/dist/{indexer → src/indexer}/walker.js +0 -0
  295. /package/dist/{llm → src/llm}/embedder.js +0 -0
  296. /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
  297. /package/dist/{llm → src/llm}/embedders/local.js +0 -0
  298. /package/dist/{llm → src/llm}/embedders/types.js +0 -0
  299. /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
  300. /package/dist/{output → src/output}/context.js +0 -0
  301. /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
  302. /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
  303. /package/dist/{registry → src/registry}/providers/index.js +0 -0
  304. /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
  305. /package/dist/{registry → src/registry}/providers/types.js +0 -0
  306. /package/dist/{registry → src/registry}/types.js +0 -0
  307. /package/dist/{setup → src/setup}/detect.js +0 -0
  308. /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
  309. /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
  310. /package/dist/{setup → src/setup}/steps.js +0 -0
  311. /package/dist/{sources → src/sources}/include.js +0 -0
  312. /package/dist/{sources → src/sources}/provider-factory.js +0 -0
  313. /package/dist/{sources → src/sources}/provider.js +0 -0
  314. /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
  315. /package/dist/{sources → src/sources}/providers/index.js +0 -0
  316. /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
  317. /package/dist/{sources → src/sources}/providers/npm.js +0 -0
  318. /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
  319. /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
  320. /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
  321. /package/dist/{sources → src/sources}/providers/website.js +0 -0
  322. /package/dist/{sources → src/sources}/resolve.js +0 -0
  323. /package/dist/{sources → src/sources}/types.js +0 -0
  324. /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
  325. /package/dist/{version.js → src/version.js} +0 -0
  326. /package/dist/{workflows → src/workflows}/authoring.js +0 -0
  327. /package/dist/{workflows → src/workflows}/cli.js +0 -0
  328. /package/dist/{workflows → src/workflows}/db.js +0 -0
  329. /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
  330. /package/dist/{workflows → src/workflows}/parser.js +0 -0
  331. /package/dist/{workflows → src/workflows}/renderer.js +0 -0
  332. /package/dist/{workflows → src/workflows}/schema.js +0 -0
  333. /package/dist/{workflows → src/workflows}/validator.js +0 -0
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Tests for setup wizard interactive logic:
3
+ * - onCancel: Escape on confirmation should stay, not exit
4
+ * - stepAddSources: recommended GitHub repos multiselect, cancel returns to menu
5
+ */
6
+ import { beforeEach, describe, expect, mock, test } from "bun:test";
7
+ // ── Mock plumbing ────────────────────────────────────────────────────────────
8
+ /** Sentinel returned by mocked prompts when simulating Escape / Ctrl-C. */
9
+ const CANCEL = Symbol("clack:cancel");
10
+ /** Per-test response queues — shift one value per prompt call. */
11
+ const q = {
12
+ confirms: [],
13
+ selects: [],
14
+ texts: [],
15
+ multiselects: [],
16
+ logged: [],
17
+ };
18
+ function reset() {
19
+ q.confirms.length = 0;
20
+ q.selects.length = 0;
21
+ q.texts.length = 0;
22
+ q.multiselects.length = 0;
23
+ q.logged.length = 0;
24
+ }
25
+ // Must be called **before** any module that imports @clack/prompts is loaded.
26
+ mock.module("@clack/prompts", () => ({
27
+ isCancel: (v) => v === CANCEL,
28
+ cancel: (msg) => {
29
+ q.logged.push(`[cancel] ${msg}`);
30
+ },
31
+ confirm: async () => q.confirms.shift() ?? false,
32
+ select: async () => q.selects.shift() ?? "done",
33
+ text: async () => q.texts.shift() ?? "",
34
+ multiselect: async () => q.multiselects.shift() ?? [],
35
+ spinner: () => ({ start: () => { }, stop: () => { } }),
36
+ log: {
37
+ info: (msg) => {
38
+ q.logged.push(msg);
39
+ },
40
+ success: (msg) => {
41
+ q.logged.push(msg);
42
+ },
43
+ warn: (msg) => {
44
+ q.logged.push(msg);
45
+ },
46
+ step: () => { },
47
+ },
48
+ intro: () => { },
49
+ outro: () => { },
50
+ note: (msg, title) => {
51
+ q.logged.push(`[note] ${title ?? ""} ${msg}`.trim());
52
+ },
53
+ }));
54
+ // ── onCancel tests ───────────────────────────────────────────────────────────
55
+ describe("onCancel – escape handling", () => {
56
+ beforeEach(reset);
57
+ test("pressing Escape on the exit-confirmation stays in the wizard", async () => {
58
+ const { onCancel } = await import("../src/setup/setup");
59
+ // Simulate: user already pressed Escape in a prompt (value = CANCEL),
60
+ // then presses Escape again on the "Exit the wizard?" confirmation.
61
+ q.confirms.push(CANCEL);
62
+ const stayed = await onCancel(CANCEL);
63
+ expect(stayed).toBe(true);
64
+ });
65
+ test("choosing No on the exit-confirmation stays in the wizard", async () => {
66
+ const { onCancel } = await import("../src/setup/setup");
67
+ q.confirms.push(false);
68
+ const stayed = await onCancel(CANCEL);
69
+ expect(stayed).toBe(true);
70
+ });
71
+ test("choosing Yes on the exit-confirmation calls bail (exits)", async () => {
72
+ const { onCancel } = await import("../src/setup/setup");
73
+ q.confirms.push(true);
74
+ // bail() calls process.exit — mock it so it throws instead of killing the runner
75
+ const originalExit = process.exit;
76
+ process.exit = ((code) => {
77
+ throw new Error(`EXIT:${code}`);
78
+ });
79
+ try {
80
+ await expect(onCancel(CANCEL)).rejects.toThrow("EXIT:0");
81
+ }
82
+ finally {
83
+ process.exit = originalExit;
84
+ }
85
+ });
86
+ test("non-cancel input is a no-op (returns false)", async () => {
87
+ const { onCancel } = await import("../src/setup/setup");
88
+ const stayed = await onCancel("normal-value");
89
+ expect(stayed).toBe(false);
90
+ });
91
+ });
92
+ // ── stepAddSources tests ───────────────────────────────────────────────────
93
+ describe("stepAddSources – recommended GitHub repos", () => {
94
+ beforeEach(reset);
95
+ test("with no recommended repos configured, the multiselect prompt is skipped", async () => {
96
+ const { stepAddSources } = await import("../src/setup/setup");
97
+ // No multiselect should be consumed because the recommended-repos array
98
+ // is empty. Only the "Add another source?" select should be needed.
99
+ q.selects.push("done");
100
+ const result = await stepAddSources({ sources: [] });
101
+ expect(result).toEqual([]);
102
+ // multiselect queue should still be empty (nothing pushed, nothing consumed)
103
+ expect(q.multiselects.length).toBe(0);
104
+ });
105
+ test("preserves an existing git stash that points at the legacy context-hub URL", async () => {
106
+ const { stepAddSources } = await import("../src/setup/setup");
107
+ const ctxHubUrl = "https://github.com/andrewyng/context-hub";
108
+ const cfg = {
109
+ sources: [{ type: "git", url: ctxHubUrl, name: "context-hub" }],
110
+ };
111
+ q.selects.push("done");
112
+ const result = await stepAddSources(cfg);
113
+ const hub = result.find((s) => s.url === ctxHubUrl);
114
+ expect(hub).toBeDefined();
115
+ expect(hub?.type).toBe("git");
116
+ });
117
+ });
118
+ describe("semantic search setup", () => {
119
+ beforeEach(reset);
120
+ test("should list local model and sqlite-vec guidance when describing semantic search assets", async () => {
121
+ const { describeSemanticSearchAssets } = await import("../src/setup/setup");
122
+ const assets = describeSemanticSearchAssets();
123
+ expect(assets[0]).toContain("Local embedding model");
124
+ expect(assets[0]).toContain("download");
125
+ expect(assets[1]).toContain("sqlite-vec");
126
+ });
127
+ test("stepSemanticSearch returns disabled when user opts out", async () => {
128
+ const { stepSemanticSearch } = await import("../src/setup/setup");
129
+ q.confirms.push(false);
130
+ const result = await stepSemanticSearch({ semanticSearchMode: "auto" });
131
+ expect(result).toEqual({ mode: "off", prepareAssets: false });
132
+ });
133
+ test("stepSemanticSearch shows assets and allows asset preparation", async () => {
134
+ const { stepSemanticSearch } = await import("../src/setup/setup");
135
+ q.confirms.push(true, true);
136
+ const result = await stepSemanticSearch({ semanticSearchMode: "auto" });
137
+ expect(result).toEqual({ mode: "auto", prepareAssets: true });
138
+ expect(q.logged.some((entry) => entry.includes("Semantic Search Assets"))).toBe(true);
139
+ });
140
+ });
141
+ describe("stepAddSources – custom GitHub repo", () => {
142
+ beforeEach(reset);
143
+ test("adds a custom GitHub repo with type 'git'", async () => {
144
+ const { stepAddSources } = await import("../src/setup/setup");
145
+ // multiselect recommended repos → none
146
+ q.multiselects.push([]);
147
+ // select "Add another source?" → "github-repo"
148
+ q.selects.push("github-repo");
149
+ // text: GitHub URL
150
+ q.texts.push("https://github.com/owner/repo");
151
+ // text: name
152
+ q.texts.push("my-repo");
153
+ // select → done
154
+ q.selects.push("done");
155
+ const result = await stepAddSources({ sources: [] });
156
+ const repo = result.find((s) => s.url === "https://github.com/owner/repo");
157
+ expect(repo).toBeDefined();
158
+ expect(repo?.type).toBe("git");
159
+ expect(repo?.name).toBe("my-repo");
160
+ });
161
+ });
162
+ describe("stepAddSources – cancel within sub-actions", () => {
163
+ beforeEach(reset);
164
+ test("pressing Escape on a sub-action text prompt returns to menu", async () => {
165
+ const { stepAddSources } = await import("../src/setup/setup");
166
+ // multiselect recommended → none
167
+ q.multiselects.push([]);
168
+ // select → github-repo
169
+ q.selects.push("github-repo");
170
+ // text: press Escape (cancel) → should return to menu, not re-prompt
171
+ q.texts.push(CANCEL);
172
+ // back at menu → done
173
+ q.selects.push("done");
174
+ const result = await stepAddSources({ sources: [] });
175
+ // No repo was added because the user cancelled
176
+ expect(result).toEqual([]);
177
+ });
178
+ test("pressing Escape on filesystem path returns to menu", async () => {
179
+ const { stepAddSources } = await import("../src/setup/setup");
180
+ q.multiselects.push([]);
181
+ q.selects.push("filesystem");
182
+ q.texts.push(CANCEL); // cancel the path prompt
183
+ q.selects.push("done");
184
+ const result = await stepAddSources({ sources: [] });
185
+ expect(result).toEqual([]);
186
+ });
187
+ test("pressing Escape on name prompt returns to menu without adding", async () => {
188
+ const { stepAddSources } = await import("../src/setup/setup");
189
+ q.multiselects.push([]);
190
+ q.selects.push("github-repo");
191
+ q.texts.push("https://github.com/owner/repo"); // provide URL
192
+ q.texts.push(CANCEL); // cancel on name prompt
193
+ q.selects.push("done");
194
+ const result = await stepAddSources({ sources: [] });
195
+ // Repo was NOT added because user cancelled at the name step
196
+ expect(result).toEqual([]);
197
+ });
198
+ });
@@ -0,0 +1,131 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ // ── detect.ts tests ─────────────────────────────────────────────────────────
6
+ describe("detectAgentPlatforms", () => {
7
+ let testHome;
8
+ const originalHome = process.env.HOME;
9
+ beforeEach(() => {
10
+ testHome = fs.mkdtempSync(path.join(os.tmpdir(), "akm-detect-"));
11
+ process.env.HOME = testHome;
12
+ });
13
+ afterEach(() => {
14
+ process.env.HOME = originalHome;
15
+ fs.rmSync(testHome, { recursive: true, force: true });
16
+ });
17
+ test("returns empty array when no platforms found", async () => {
18
+ const { detectAgentPlatforms } = await import("../src/setup/detect");
19
+ const result = detectAgentPlatforms();
20
+ expect(result).toEqual([]);
21
+ });
22
+ test("detects .claude directory", async () => {
23
+ fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
24
+ // Re-import to pick up fresh HOME
25
+ const { detectAgentPlatforms } = await import("../src/setup/detect");
26
+ const result = detectAgentPlatforms();
27
+ const claude = result.find((p) => p.name === "Claude Code");
28
+ expect(claude).toBeDefined();
29
+ expect(claude?.path).toBe(path.join(testHome, ".claude"));
30
+ });
31
+ test("detects .config/opencode directory", async () => {
32
+ fs.mkdirSync(path.join(testHome, ".config", "opencode"), { recursive: true });
33
+ const { detectAgentPlatforms } = await import("../src/setup/detect");
34
+ const result = detectAgentPlatforms();
35
+ const opencode = result.find((p) => p.name === "OpenCode");
36
+ expect(opencode).toBeDefined();
37
+ expect(opencode?.path).toBe(path.join(testHome, ".config", "opencode"));
38
+ });
39
+ test("detects multiple platforms", async () => {
40
+ fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
41
+ fs.mkdirSync(path.join(testHome, ".cursor"), { recursive: true });
42
+ fs.mkdirSync(path.join(testHome, ".continue"), { recursive: true });
43
+ const { detectAgentPlatforms } = await import("../src/setup/detect");
44
+ const result = detectAgentPlatforms();
45
+ expect(result.length).toBeGreaterThanOrEqual(3);
46
+ });
47
+ test("ignores files (only detects directories)", async () => {
48
+ fs.writeFileSync(path.join(testHome, ".claude"), "not a directory");
49
+ const { detectAgentPlatforms } = await import("../src/setup/detect");
50
+ const result = detectAgentPlatforms();
51
+ const claude = result.find((p) => p.name === "Claude Code");
52
+ expect(claude).toBeUndefined();
53
+ });
54
+ test("returns empty when HOME and USERPROFILE are both unset", async () => {
55
+ delete process.env.HOME;
56
+ delete process.env.USERPROFILE;
57
+ const { detectAgentPlatforms } = await import("../src/setup/detect");
58
+ const result = detectAgentPlatforms();
59
+ expect(result).toEqual([]);
60
+ });
61
+ test("falls back to USERPROFILE when HOME is unset (Windows)", async () => {
62
+ delete process.env.HOME;
63
+ process.env.USERPROFILE = testHome;
64
+ fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
65
+ const { detectAgentPlatforms } = await import("../src/setup/detect");
66
+ const result = detectAgentPlatforms();
67
+ const claude = result.find((p) => p.name === "Claude Code");
68
+ expect(claude).toBeDefined();
69
+ expect(claude?.path).toBe(path.join(testHome, ".claude"));
70
+ delete process.env.USERPROFILE;
71
+ });
72
+ });
73
+ describe("detectOllama", () => {
74
+ let originalFetch;
75
+ beforeEach(() => {
76
+ originalFetch = globalThis.fetch;
77
+ });
78
+ afterEach(() => {
79
+ globalThis.fetch = originalFetch;
80
+ });
81
+ test("returns available=true with models from API", async () => {
82
+ globalThis.fetch = (async (input) => {
83
+ const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
84
+ if (url.includes("/api/tags")) {
85
+ return new Response(JSON.stringify({
86
+ models: [{ name: "llama3.2:latest" }, { name: "nomic-embed-text:latest" }, { name: "codellama:latest" }],
87
+ }), { status: 200 });
88
+ }
89
+ return new Response("", { status: 404 });
90
+ });
91
+ const { detectOllama } = await import("../src/setup/detect");
92
+ const result = await detectOllama();
93
+ expect(result.available).toBe(true);
94
+ expect(result.models).toContain("llama3.2");
95
+ expect(result.models).toContain("nomic-embed-text");
96
+ expect(result.models).toContain("codellama");
97
+ });
98
+ test("strips :latest suffix from model names", async () => {
99
+ globalThis.fetch = (async () => {
100
+ return new Response(JSON.stringify({
101
+ models: [{ name: "llama3.2:latest" }, { name: "phi3:v2" }],
102
+ }), { status: 200 });
103
+ });
104
+ const { detectOllama } = await import("../src/setup/detect");
105
+ const result = await detectOllama();
106
+ expect(result.models).toContain("llama3.2");
107
+ expect(result.models).toContain("phi3:v2");
108
+ expect(result.models).not.toContain("llama3.2:latest");
109
+ });
110
+ test("returns available=false when fetch fails", async () => {
111
+ globalThis.fetch = (async () => {
112
+ throw new Error("Connection refused");
113
+ });
114
+ const { detectOllama } = await import("../src/setup/detect");
115
+ const result = await detectOllama();
116
+ // May still be available=true if `ollama list` CLI works, or false if both fail
117
+ // Just verify it doesn't throw
118
+ expect(typeof result.available).toBe("boolean");
119
+ expect(Array.isArray(result.models)).toBe(true);
120
+ });
121
+ test("returns sorted model names", async () => {
122
+ globalThis.fetch = (async () => {
123
+ return new Response(JSON.stringify({
124
+ models: [{ name: "zephyr:latest" }, { name: "alpaca:latest" }, { name: "mistral:latest" }],
125
+ }), { status: 200 });
126
+ });
127
+ const { detectOllama } = await import("../src/setup/detect");
128
+ const result = await detectOllama();
129
+ expect(result.models).toEqual(["alpaca", "mistral", "zephyr"]);
130
+ });
131
+ });
@@ -0,0 +1,11 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { shouldAddAsWebsiteUrl } from "../src/commands/source-add";
3
+ describe("shouldAddAsWebsiteUrl", () => {
4
+ test("treats docs-style URLs as website sources", () => {
5
+ expect(shouldAddAsWebsiteUrl("https://docs.example.com/guide")).toBe(true);
6
+ });
7
+ test("keeps known git hosts on the registry install path", () => {
8
+ expect(shouldAddAsWebsiteUrl("https://gitlab.com/acme/project")).toBe(false);
9
+ expect(shouldAddAsWebsiteUrl("https://example.com/acme/project.git")).toBe(false);
10
+ });
11
+ });
@@ -0,0 +1,254 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { akmClone } from "../src/commands/source-clone";
6
+ import { saveConfig } from "../src/core/config";
7
+ import { UsageError } from "../src/core/errors";
8
+ const originalStashDir = process.env.AKM_STASH_DIR;
9
+ const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
10
+ const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
11
+ let testConfigDir = "";
12
+ let testCacheDir = "";
13
+ let stashDir = "";
14
+ let searchPathDir = "";
15
+ function writeFile(filePath, content) {
16
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
17
+ fs.writeFileSync(filePath, content);
18
+ }
19
+ function createStashDir(prefix) {
20
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
21
+ for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
22
+ fs.mkdirSync(path.join(dir, sub), { recursive: true });
23
+ }
24
+ return dir;
25
+ }
26
+ beforeEach(() => {
27
+ testConfigDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-config-"));
28
+ testCacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-cache-"));
29
+ stashDir = createStashDir("akm-clone-working-");
30
+ searchPathDir = createStashDir("akm-clone-searchpath-");
31
+ process.env.XDG_CONFIG_HOME = testConfigDir;
32
+ process.env.XDG_CACHE_HOME = testCacheDir;
33
+ process.env.AKM_STASH_DIR = stashDir;
34
+ saveConfig({
35
+ semanticSearchMode: "off",
36
+ sources: [{ type: "filesystem", path: searchPathDir }],
37
+ });
38
+ });
39
+ afterEach(() => {
40
+ process.env.AKM_STASH_DIR = originalStashDir ?? undefined;
41
+ if (originalXdgConfigHome === undefined)
42
+ delete process.env.XDG_CONFIG_HOME;
43
+ else
44
+ process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
45
+ if (originalXdgCacheHome === undefined)
46
+ delete process.env.XDG_CACHE_HOME;
47
+ else
48
+ process.env.XDG_CACHE_HOME = originalXdgCacheHome;
49
+ for (const dir of [testConfigDir, testCacheDir, stashDir, searchPathDir]) {
50
+ if (dir)
51
+ fs.rmSync(dir, { recursive: true, force: true });
52
+ }
53
+ });
54
+ describe("akmClone", () => {
55
+ test("clones a script from search path to primary stash", async () => {
56
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "#!/bin/bash\necho deploy\n");
57
+ const result = await akmClone({ sourceRef: "script:deploy.sh" });
58
+ expect(result.destination.ref).toContain("script:deploy.sh");
59
+ expect(result.overwritten).toBe(false);
60
+ expect(fs.existsSync(path.join(stashDir, "scripts", "deploy.sh"))).toBe(true);
61
+ expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("#!/bin/bash\necho deploy\n");
62
+ });
63
+ test("clones a skill directory", async () => {
64
+ writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review Skill\n");
65
+ writeFile(path.join(searchPathDir, "skills", "review", "helper.md"), "# Helper\n");
66
+ const result = await akmClone({ sourceRef: "skill:review" });
67
+ expect(result.overwritten).toBe(false);
68
+ expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
69
+ expect(fs.existsSync(path.join(stashDir, "skills", "review", "helper.md"))).toBe(true);
70
+ });
71
+ test("clones with a new name", async () => {
72
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
73
+ const result = await akmClone({ sourceRef: "script:deploy.sh", newName: "my-deploy.sh" });
74
+ expect(fs.existsSync(path.join(stashDir, "scripts", "my-deploy.sh"))).toBe(true);
75
+ expect(result.destination.ref).toContain("my-deploy.sh");
76
+ });
77
+ test("throws when asset already exists without --force", async () => {
78
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo original\n");
79
+ writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo existing\n");
80
+ await expect(akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh` })).rejects.toThrow("already exists");
81
+ });
82
+ test("overwrites with --force", async () => {
83
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo updated\n");
84
+ writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo old\n");
85
+ const result = await akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh`, force: true });
86
+ expect(result.overwritten).toBe(true);
87
+ expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("echo updated\n");
88
+ });
89
+ test("force overwrite removes stale files from skill directory", async () => {
90
+ // Source skill has only SKILL.md
91
+ writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Updated\n");
92
+ // Existing working skill has an extra file
93
+ writeFile(path.join(stashDir, "skills", "review", "SKILL.md"), "# Old\n");
94
+ writeFile(path.join(stashDir, "skills", "review", "stale.md"), "# Stale\n");
95
+ await akmClone({ sourceRef: `${searchPathDir}//skill:review`, force: true });
96
+ expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
97
+ expect(fs.existsSync(path.join(stashDir, "skills", "review", "stale.md"))).toBe(false);
98
+ });
99
+ test("throws when source asset not found", async () => {
100
+ await expect(akmClone({ sourceRef: "script:nonexistent.sh" })).rejects.toThrow();
101
+ });
102
+ test("clones from working stash to itself with new name", async () => {
103
+ writeFile(path.join(stashDir, "scripts", "original.sh"), "echo original\n");
104
+ const _result = await akmClone({ sourceRef: "script:original.sh", newName: "copy.sh" });
105
+ expect(fs.existsSync(path.join(stashDir, "scripts", "copy.sh"))).toBe(true);
106
+ });
107
+ test("throws when self-cloning a script without rename", async () => {
108
+ writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo deploy\n");
109
+ await expect(akmClone({ sourceRef: "script:deploy.sh" })).rejects.toThrow("same path");
110
+ // Verify the file was not destroyed
111
+ expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("echo deploy\n");
112
+ });
113
+ test("throws when self-cloning a skill without rename", async () => {
114
+ writeFile(path.join(stashDir, "skills", "review", "SKILL.md"), "# Review\n");
115
+ await expect(akmClone({ sourceRef: "skill:review" })).rejects.toThrow("same path");
116
+ // Verify the skill was not destroyed
117
+ expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
118
+ });
119
+ describe("newName validation", () => {
120
+ beforeEach(() => {
121
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
122
+ writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review\n");
123
+ });
124
+ test("throws on empty string newName", async () => {
125
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "" })).rejects.toThrow(UsageError);
126
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "" })).rejects.toThrow(/empty/);
127
+ });
128
+ test("throws on '.' as newName", async () => {
129
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "." })).rejects.toThrow(UsageError);
130
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "." })).rejects.toThrow(/Unsafe/);
131
+ });
132
+ test("throws on '..' as newName", async () => {
133
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: ".." })).rejects.toThrow(UsageError);
134
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: ".." })).rejects.toThrow(/Unsafe/);
135
+ });
136
+ test("throws on path-traversal newName", async () => {
137
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "../escape.sh" })).rejects.toThrow(UsageError);
138
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "../escape.sh" })).rejects.toThrow(/Unsafe/);
139
+ });
140
+ test("throws on absolute path as newName", async () => {
141
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "/etc/evil.sh" })).rejects.toThrow(UsageError);
142
+ await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "/etc/evil.sh" })).rejects.toThrow(/Unsafe/);
143
+ });
144
+ test("empty newName does not wipe the type directory for skills", async () => {
145
+ writeFile(path.join(stashDir, "skills", "existing", "SKILL.md"), "# Existing\n");
146
+ await expect(akmClone({ sourceRef: "skill:review", newName: "", force: true })).rejects.toThrow(UsageError);
147
+ // Existing skill must be untouched
148
+ expect(fs.existsSync(path.join(stashDir, "skills", "existing", "SKILL.md"))).toBe(true);
149
+ });
150
+ });
151
+ });
152
+ describe("akmClone --dest", () => {
153
+ let customDest;
154
+ beforeEach(() => {
155
+ customDest = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-dest-"));
156
+ });
157
+ afterEach(() => {
158
+ if (customDest)
159
+ fs.rmSync(customDest, { recursive: true, force: true });
160
+ });
161
+ test("clones script to custom destination preserving type dir structure", async () => {
162
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "#!/bin/bash\necho deploy\n");
163
+ const result = await akmClone({ sourceRef: "script:deploy.sh", dest: customDest });
164
+ expect(result.destination.path).toBe(path.join(customDest, "scripts", "deploy.sh"));
165
+ expect(fs.existsSync(path.join(customDest, "scripts", "deploy.sh"))).toBe(true);
166
+ expect(fs.readFileSync(path.join(customDest, "scripts", "deploy.sh"), "utf8")).toBe("#!/bin/bash\necho deploy\n");
167
+ // Working stash should NOT have the file
168
+ expect(fs.existsSync(path.join(stashDir, "scripts", "deploy.sh"))).toBe(false);
169
+ });
170
+ test("clones skill directory to custom destination", async () => {
171
+ writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review Skill\n");
172
+ writeFile(path.join(searchPathDir, "skills", "review", "helper.md"), "# Helper\n");
173
+ const result = await akmClone({ sourceRef: "skill:review", dest: customDest });
174
+ expect(fs.existsSync(path.join(customDest, "skills", "review", "SKILL.md"))).toBe(true);
175
+ expect(fs.existsSync(path.join(customDest, "skills", "review", "helper.md"))).toBe(true);
176
+ expect(result.overwritten).toBe(false);
177
+ });
178
+ test("--dest does not require a working stash", async () => {
179
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
180
+ // Point AKM_STASH_DIR to a non-existent directory to simulate no working stash
181
+ process.env.AKM_STASH_DIR = path.join(os.tmpdir(), `nonexistent-stash-${Date.now()}`);
182
+ const result = await akmClone({
183
+ sourceRef: `${searchPathDir}//script:deploy.sh`,
184
+ dest: customDest,
185
+ });
186
+ expect(fs.existsSync(path.join(customDest, "scripts", "deploy.sh"))).toBe(true);
187
+ expect(result.destination.path).toBe(path.join(customDest, "scripts", "deploy.sh"));
188
+ });
189
+ test("--dest with --force overwrites at custom destination", async () => {
190
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo updated\n");
191
+ writeFile(path.join(customDest, "scripts", "deploy.sh"), "echo old\n");
192
+ const result = await akmClone({
193
+ sourceRef: `${searchPathDir}//script:deploy.sh`,
194
+ force: true,
195
+ dest: customDest,
196
+ });
197
+ expect(result.overwritten).toBe(true);
198
+ expect(fs.readFileSync(path.join(customDest, "scripts", "deploy.sh"), "utf8")).toBe("echo updated\n");
199
+ });
200
+ test("throws when asset exists at --dest without --force", async () => {
201
+ writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo new\n");
202
+ writeFile(path.join(customDest, "scripts", "deploy.sh"), "echo existing\n");
203
+ await expect(akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh`, dest: customDest })).rejects.toThrow("already exists at destination");
204
+ });
205
+ });
206
+ describe("akmClone remote", () => {
207
+ let remoteFixtureDir;
208
+ beforeEach(() => {
209
+ // Create a fixture directory that simulates a remote package
210
+ remoteFixtureDir = createStashDir("akm-clone-remote-fixture-");
211
+ writeFile(path.join(remoteFixtureDir, "scripts", "remote-tool.sh"), "#!/bin/bash\necho remote\n");
212
+ writeFile(path.join(remoteFixtureDir, "skills", "remote-skill", "SKILL.md"), "# Remote Skill\n");
213
+ });
214
+ afterEach(() => {
215
+ if (remoteFixtureDir)
216
+ fs.rmSync(remoteFixtureDir, { recursive: true, force: true });
217
+ });
218
+ test("clones a script from a remote origin via installRegistryRef", async () => {
219
+ // Use bare path as origin — not in stashes, so isRemoteOrigin returns true
220
+ const result = await akmClone({
221
+ sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
222
+ });
223
+ expect(result.remoteFetched).toBeDefined();
224
+ expect(result.remoteFetched?.origin).toBe(remoteFixtureDir);
225
+ expect(fs.existsSync(path.join(stashDir, "scripts", "remote-tool.sh"))).toBe(true);
226
+ expect(fs.readFileSync(path.join(stashDir, "scripts", "remote-tool.sh"), "utf8")).toBe("#!/bin/bash\necho remote\n");
227
+ });
228
+ test("returns remoteFetched metadata", async () => {
229
+ const result = await akmClone({
230
+ sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
231
+ });
232
+ expect(result.remoteFetched).toBeDefined();
233
+ expect(result.remoteFetched?.stashRoot).toBeTruthy();
234
+ expect(result.remoteFetched?.cacheDir).toBeTruthy();
235
+ });
236
+ test("throws when remote fetch succeeds but asset not found in package", async () => {
237
+ await expect(akmClone({ sourceRef: `${remoteFixtureDir}//script:nonexistent.sh` })).rejects.toThrow("not found");
238
+ });
239
+ test("clones from remote origin to custom destination", async () => {
240
+ const customDest = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-remote-dest-"));
241
+ try {
242
+ const result = await akmClone({
243
+ sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
244
+ dest: customDest,
245
+ });
246
+ expect(result.remoteFetched).toBeDefined();
247
+ expect(fs.existsSync(path.join(customDest, "scripts", "remote-tool.sh"))).toBe(true);
248
+ expect(result.destination.path).toBe(path.join(customDest, "scripts", "remote-tool.sh"));
249
+ }
250
+ finally {
251
+ fs.rmSync(customDest, { recursive: true, force: true });
252
+ }
253
+ });
254
+ });