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,252 @@
1
+ import { afterAll, afterEach, describe, expect, test } from "bun:test";
2
+ import { spawnSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { walkStash, walkStashFlat } from "../src/indexer/walker";
7
+ const createdTmpDirs = [];
8
+ function tmpDir() {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-walker-"));
10
+ createdTmpDirs.push(dir);
11
+ return dir;
12
+ }
13
+ afterAll(() => {
14
+ for (const dir of createdTmpDirs) {
15
+ fs.rmSync(dir, { recursive: true, force: true });
16
+ }
17
+ });
18
+ function writeFile(filePath, content = "") {
19
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
20
+ fs.writeFileSync(filePath, content);
21
+ }
22
+ describe("walkStash", () => {
23
+ test("returns empty array for non-existent directory", () => {
24
+ expect(walkStash("/nonexistent/path", "script")).toEqual([]);
25
+ });
26
+ test("returns empty array for empty directory", () => {
27
+ const dir = tmpDir();
28
+ expect(walkStash(dir, "script")).toEqual([]);
29
+ });
30
+ test("groups script files by parent directory", () => {
31
+ const root = tmpDir();
32
+ writeFile(path.join(root, "docker", "build.sh"), "echo build\n");
33
+ writeFile(path.join(root, "docker", "compose.sh"), "echo compose\n");
34
+ writeFile(path.join(root, "git", "diff.ts"), "console.log('diff')\n");
35
+ const groups = walkStash(root, "script");
36
+ expect(groups).toHaveLength(2);
37
+ const dockerGroup = groups.find((g) => g.dirPath.endsWith("docker"));
38
+ const gitGroup = groups.find((g) => g.dirPath.endsWith("git"));
39
+ expect(dockerGroup).toBeDefined();
40
+ expect(dockerGroup?.files).toHaveLength(2);
41
+ expect(gitGroup).toBeDefined();
42
+ expect(gitGroup?.files).toHaveLength(1);
43
+ });
44
+ test("skips .stash.json files", () => {
45
+ const root = tmpDir();
46
+ writeFile(path.join(root, "group", "run.sh"), "echo hi\n");
47
+ writeFile(path.join(root, "group", ".stash.json"), '{"entries":[]}');
48
+ const groups = walkStash(root, "script");
49
+ expect(groups).toHaveLength(1);
50
+ const files = groups[0].files;
51
+ expect(files).toHaveLength(1);
52
+ expect(files[0]).toContain("run.sh");
53
+ });
54
+ test("only includes relevant files for script type", () => {
55
+ const root = tmpDir();
56
+ writeFile(path.join(root, "group", "run.sh"), "echo hi\n");
57
+ writeFile(path.join(root, "group", "README.md"), "ignore\n");
58
+ writeFile(path.join(root, "group", "data.json"), "{}");
59
+ const groups = walkStash(root, "script");
60
+ expect(groups).toHaveLength(1);
61
+ expect(groups[0].files).toHaveLength(1);
62
+ });
63
+ test("only includes SKILL.md for skill type", () => {
64
+ const root = tmpDir();
65
+ writeFile(path.join(root, "review", "SKILL.md"), "# Review\n");
66
+ writeFile(path.join(root, "review", "README.md"), "ignore\n");
67
+ writeFile(path.join(root, "refactor", "SKILL.md"), "# Refactor\n");
68
+ const groups = walkStash(root, "skill");
69
+ expect(groups).toHaveLength(2);
70
+ for (const group of groups) {
71
+ expect(group.files).toHaveLength(1);
72
+ expect(group.files[0]).toContain("SKILL.md");
73
+ }
74
+ });
75
+ test("only includes .md for command type", () => {
76
+ const root = tmpDir();
77
+ writeFile(path.join(root, "release.md"), "release\n");
78
+ writeFile(path.join(root, "setup.sh"), "echo setup\n");
79
+ const groups = walkStash(root, "command");
80
+ expect(groups).toHaveLength(1);
81
+ expect(groups[0].files).toHaveLength(1);
82
+ expect(groups[0].files[0]).toContain("release.md");
83
+ });
84
+ test("walks nested directories", () => {
85
+ const root = tmpDir();
86
+ writeFile(path.join(root, "a", "b", "c", "deep.sh"), "echo deep\n");
87
+ const groups = walkStash(root, "script");
88
+ expect(groups).toHaveLength(1);
89
+ expect(groups[0].files[0]).toContain("deep.sh");
90
+ });
91
+ test("includes files from root level", () => {
92
+ const root = tmpDir();
93
+ writeFile(path.join(root, "deploy.sh"), "echo deploy\n");
94
+ const groups = walkStash(root, "script");
95
+ expect(groups).toHaveLength(1);
96
+ expect(groups[0].dirPath).toBe(root);
97
+ });
98
+ test("handles knowledge type (.md files)", () => {
99
+ const root = tmpDir();
100
+ writeFile(path.join(root, "guide.md"), "# Guide\n");
101
+ writeFile(path.join(root, "reference.md"), "# Reference\n");
102
+ writeFile(path.join(root, "data.json"), "{}");
103
+ const groups = walkStash(root, "knowledge");
104
+ expect(groups).toHaveLength(1);
105
+ expect(groups[0].files).toHaveLength(2);
106
+ });
107
+ });
108
+ describe("walkStashFlat", () => {
109
+ test("returns FileContext objects (not plain paths)", () => {
110
+ const root = tmpDir();
111
+ writeFile(path.join(root, "scripts", "build.sh"), "echo build\n");
112
+ const results = walkStashFlat(root);
113
+ expect(results).toHaveLength(1);
114
+ const ctx = results[0];
115
+ expect(typeof ctx.absPath).toBe("string");
116
+ expect(typeof ctx.relPath).toBe("string");
117
+ expect(typeof ctx.ext).toBe("string");
118
+ expect(typeof ctx.fileName).toBe("string");
119
+ expect(typeof ctx.stashRoot).toBe("string");
120
+ expect(typeof ctx.content).toBe("function");
121
+ expect(typeof ctx.frontmatter).toBe("function");
122
+ expect(typeof ctx.stat).toBe("function");
123
+ });
124
+ test("walks across all asset type directories", () => {
125
+ const root = tmpDir();
126
+ writeFile(path.join(root, "scripts", "build.sh"), "echo build\n");
127
+ writeFile(path.join(root, "agents", "helper.md"), "# Helper\n");
128
+ writeFile(path.join(root, "knowledge", "guide.md"), "# Guide\n");
129
+ writeFile(path.join(root, "scripts", "deploy.py"), "print('deploy')\n");
130
+ const results = walkStashFlat(root);
131
+ expect(results).toHaveLength(4);
132
+ const fileNames = results.map((r) => r.fileName).sort();
133
+ expect(fileNames).toEqual(["build.sh", "deploy.py", "guide.md", "helper.md"]);
134
+ });
135
+ test("does not filter by asset type", () => {
136
+ const root = tmpDir();
137
+ writeFile(path.join(root, "data.json"), '{"key":"value"}');
138
+ writeFile(path.join(root, "script.py"), "print('hi')\n");
139
+ const results = walkStashFlat(root);
140
+ expect(results).toHaveLength(2);
141
+ const fileNames = results.map((r) => r.fileName).sort();
142
+ expect(fileNames).toEqual(["data.json", "script.py"]);
143
+ });
144
+ test("skips directories starting with dot", () => {
145
+ const root = tmpDir();
146
+ writeFile(path.join(root, ".hidden", "file.txt"), "secret\n");
147
+ writeFile(path.join(root, "visible", "file.txt"), "public\n");
148
+ const results = walkStashFlat(root);
149
+ expect(results).toHaveLength(1);
150
+ expect(results[0].fileName).toBe("file.txt");
151
+ expect(results[0].absPath).toContain("visible");
152
+ });
153
+ test("preserves stashRoot on all FileContext results", () => {
154
+ const root = tmpDir();
155
+ writeFile(path.join(root, "a", "one.sh"), "echo one\n");
156
+ writeFile(path.join(root, "b", "two.md"), "# Two\n");
157
+ writeFile(path.join(root, "c", "three.py"), "print(3)\n");
158
+ const results = walkStashFlat(root);
159
+ expect(results).toHaveLength(3);
160
+ for (const ctx of results) {
161
+ expect(ctx.stashRoot).toBe(root);
162
+ }
163
+ });
164
+ test("git walk stays scoped to the stash root subtree", () => {
165
+ const repoRoot = tmpDir();
166
+ const stashRoot = path.join(repoRoot, "stash");
167
+ writeFile(path.join(repoRoot, "outside.txt"), "outside\n");
168
+ writeFile(path.join(stashRoot, "scripts", "build.sh"), "echo build\n");
169
+ const gitInit = spawnSync("git", ["init"], { cwd: repoRoot, encoding: "utf8" });
170
+ expect(gitInit.status).toBe(0);
171
+ const results = walkStashFlat(stashRoot);
172
+ expect(results).toHaveLength(1);
173
+ expect(results[0]?.relPath).toBe("scripts/build.sh");
174
+ expect(results[0]?.absPath.startsWith(stashRoot)).toBe(true);
175
+ });
176
+ });
177
+ // ── T6: isInsideGitRepo in nested repo ───────────────────────────────────────
178
+ //
179
+ // Gap: isInsideGitRepo() walks up the directory tree looking for .git. In a
180
+ // nested git repo (e.g. a stash directory inside a monorepo worktree), it
181
+ // should find the nearest .git — but creating nested repos in CI is fragile
182
+ // and platform-dependent, so this gap is intentionally left untested here.
183
+ // If regression is suspected, test manually by creating a nested git init
184
+ // inside an existing repo and verifying walkStashFlat still uses the git walker.
185
+ // ── R4.3: symlink escape ─────────────────────────────────────────────────────
186
+ //
187
+ // walkStashFlat (manual fallback) must skip symlinks that point outside the
188
+ // stash root so that malicious or accidental symlinks cannot leak files from
189
+ // the host filesystem into search results.
190
+ describe("walkStashFlat — symlink escape", () => {
191
+ // Track extra files created outside tmpDir() so we can clean them up.
192
+ const extraFiles = [];
193
+ afterEach(() => {
194
+ for (const f of extraFiles.splice(0)) {
195
+ try {
196
+ fs.rmSync(f, { force: true });
197
+ }
198
+ catch {
199
+ // best-effort
200
+ }
201
+ }
202
+ });
203
+ test("symlink pointing outside stash root is NOT included in results", () => {
204
+ // Create a stash root that is NOT inside a git repo so the manual walker
205
+ // is used (the git walker relies on git ls-files which won't list a
206
+ // symlink that targets an untracked file outside the repo).
207
+ const stashRoot = tmpDir();
208
+ const skillsDir = path.join(stashRoot, "skills");
209
+ fs.mkdirSync(skillsDir, { recursive: true });
210
+ // Create a real file OUTSIDE the stash root
211
+ const outsideFile = path.join(os.tmpdir(), `akm-symlink-target-${process.pid}-${Date.now()}.md`);
212
+ fs.writeFileSync(outsideFile, "# Secret content outside stash\n");
213
+ extraFiles.push(outsideFile);
214
+ // Create a symlink inside the stash that points to the outside file
215
+ const symlinkPath = path.join(skillsDir, "escaped.md");
216
+ fs.symlinkSync(outsideFile, symlinkPath);
217
+ // Also create a legitimate file so we can confirm the walker still works
218
+ writeFile(path.join(skillsDir, "legitimate.md"), "# Legit\n");
219
+ const results = walkStashFlat(stashRoot);
220
+ const resultPaths = results.map((r) => r.absPath);
221
+ // The symlink must NOT appear in results
222
+ expect(resultPaths).not.toContain(symlinkPath);
223
+ // Confirm the outside target is also not reached through the symlink
224
+ expect(resultPaths).not.toContain(outsideFile);
225
+ // The legitimate file should still be found
226
+ expect(resultPaths.some((p) => p.endsWith("legitimate.md"))).toBe(true);
227
+ // Cleanup the symlink (tmpDir cleanup handles the rest)
228
+ fs.rmSync(symlinkPath, { force: true });
229
+ });
230
+ test("symlink pointing to a directory outside stash root is also skipped", () => {
231
+ const stashRoot = tmpDir();
232
+ const knowledgeDir = path.join(stashRoot, "knowledge");
233
+ fs.mkdirSync(knowledgeDir, { recursive: true });
234
+ // Create a directory OUTSIDE the stash with a file inside
235
+ const outsideDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-symlink-dir-target-"));
236
+ extraFiles.push(outsideDir);
237
+ fs.writeFileSync(path.join(outsideDir, "secret.md"), "# Outside dir secret\n");
238
+ // Symlink the outside directory into the stash
239
+ const symlinkDir = path.join(knowledgeDir, "escaped-dir");
240
+ fs.symlinkSync(outsideDir, symlinkDir);
241
+ // Create a legitimate file to confirm walker still functions
242
+ writeFile(path.join(knowledgeDir, "real.md"), "# Real\n");
243
+ const results = walkStashFlat(stashRoot);
244
+ const resultPaths = results.map((r) => r.absPath);
245
+ // No file from inside the outside dir must appear
246
+ expect(resultPaths.some((p) => p.startsWith(outsideDir))).toBe(false);
247
+ // The legitimate file should still be found
248
+ expect(resultPaths.some((p) => p.endsWith("real.md"))).toBe(true);
249
+ // Cleanup the symlink
250
+ fs.rmSync(symlinkDir, { force: true });
251
+ });
252
+ });
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Wave-2 QA fixes tests — Cluster B (#21, #36) and Cluster C (#6, #14, #24).
3
+ *
4
+ * Cluster B: defaultWriteTarget and llm/embedding subkey support in config-cli.
5
+ * Cluster C: empty-query guards + minScore floor for semantic-only hits.
6
+ */
7
+ import { describe, expect, test } from "bun:test";
8
+ import { getConfigValue, listConfig, parseConfigValue, setConfigValue, unsetConfigValue, } from "../src/commands/config-cli";
9
+ // ── Cluster B: #21 defaultWriteTarget ────────────────────────────────────────
10
+ describe("config-cli: defaultWriteTarget (#21)", () => {
11
+ const base = { semanticSearchMode: "auto" };
12
+ test("parseConfigValue returns defaultWriteTarget", () => {
13
+ expect(parseConfigValue("defaultWriteTarget", "my-stash")).toEqual({
14
+ defaultWriteTarget: "my-stash",
15
+ });
16
+ });
17
+ test("parseConfigValue rejects empty defaultWriteTarget", () => {
18
+ expect(() => parseConfigValue("defaultWriteTarget", "")).toThrow();
19
+ });
20
+ test("getConfigValue returns null when not set", () => {
21
+ expect(getConfigValue(base, "defaultWriteTarget")).toBeNull();
22
+ });
23
+ test("getConfigValue returns the set value", () => {
24
+ const config = { ...base, defaultWriteTarget: "my-stash" };
25
+ expect(getConfigValue(config, "defaultWriteTarget")).toBe("my-stash");
26
+ });
27
+ test("setConfigValue sets defaultWriteTarget — no sources configured", () => {
28
+ const result = setConfigValue(base, "defaultWriteTarget", "any-name");
29
+ expect(result.defaultWriteTarget).toBe("any-name");
30
+ });
31
+ test("setConfigValue validates name against sources when sources[] is non-empty", () => {
32
+ const config = {
33
+ ...base,
34
+ sources: [{ type: "filesystem", path: "/tmp/stash", name: "primary" }],
35
+ };
36
+ expect(() => setConfigValue(config, "defaultWriteTarget", "unknown-stash")).toThrow(/Unknown source name/);
37
+ });
38
+ test("setConfigValue accepts a valid source name", () => {
39
+ const config = {
40
+ ...base,
41
+ sources: [{ type: "filesystem", path: "/tmp/stash", name: "primary" }],
42
+ };
43
+ const result = setConfigValue(config, "defaultWriteTarget", "primary");
44
+ expect(result.defaultWriteTarget).toBe("primary");
45
+ });
46
+ test("unsetConfigValue clears defaultWriteTarget", () => {
47
+ const config = { ...base, defaultWriteTarget: "primary" };
48
+ const result = unsetConfigValue(config, "defaultWriteTarget");
49
+ expect(result.defaultWriteTarget).toBeUndefined();
50
+ });
51
+ test("listConfig includes defaultWriteTarget when set", () => {
52
+ const config = { ...base, defaultWriteTarget: "primary" };
53
+ const listed = listConfig(config);
54
+ expect(listed.defaultWriteTarget).toBe("primary");
55
+ });
56
+ test("listConfig omits defaultWriteTarget when not set", () => {
57
+ const listed = listConfig(base);
58
+ expect(listed.defaultWriteTarget).toBeUndefined();
59
+ });
60
+ });
61
+ // ── Cluster B: #36 llm/embedding subkey support ───────────────────────────────
62
+ describe("config-cli: llm.* and embedding.* subkeys (#36)", () => {
63
+ const base = { semanticSearchMode: "auto" };
64
+ // ── parseConfigValue ──────────────────────────────────────────────────────
65
+ test("parseConfigValue handles llm.endpoint", () => {
66
+ const result = parseConfigValue("llm.endpoint", "http://localhost:11434/v1/chat/completions");
67
+ expect(result.llm?.endpoint).toBe("http://localhost:11434/v1/chat/completions");
68
+ });
69
+ test("parseConfigValue handles llm.model", () => {
70
+ const result = parseConfigValue("llm.model", "llama3.2");
71
+ expect(result.llm?.model).toBe("llama3.2");
72
+ });
73
+ test("parseConfigValue handles llm.apiKey", () => {
74
+ const result = parseConfigValue("llm.apiKey", "sk-test");
75
+ expect(result.llm?.apiKey).toBe("sk-test");
76
+ });
77
+ test("parseConfigValue handles embedding.endpoint", () => {
78
+ const result = parseConfigValue("embedding.endpoint", "http://localhost:11434/v1/embeddings");
79
+ expect(result.embedding?.endpoint).toBe("http://localhost:11434/v1/embeddings");
80
+ });
81
+ test("parseConfigValue handles embedding.model", () => {
82
+ const result = parseConfigValue("embedding.model", "nomic-embed-text");
83
+ expect(result.embedding?.model).toBe("nomic-embed-text");
84
+ });
85
+ test("parseConfigValue handles embedding.apiKey", () => {
86
+ const result = parseConfigValue("embedding.apiKey", "sk-embed");
87
+ expect(result.embedding?.apiKey).toBe("sk-embed");
88
+ });
89
+ test("parseConfigValue rejects empty llm.endpoint", () => {
90
+ expect(() => parseConfigValue("llm.endpoint", "")).toThrow();
91
+ });
92
+ // ── getConfigValue ────────────────────────────────────────────────────────
93
+ test("getConfigValue: llm.endpoint returns null when llm not set", () => {
94
+ expect(getConfigValue(base, "llm.endpoint")).toBeNull();
95
+ });
96
+ test("getConfigValue: llm.endpoint returns value when set", () => {
97
+ const config = {
98
+ ...base,
99
+ llm: { endpoint: "http://localhost/v1", model: "llama3.2" },
100
+ };
101
+ expect(getConfigValue(config, "llm.endpoint")).toBe("http://localhost/v1");
102
+ expect(getConfigValue(config, "llm.model")).toBe("llama3.2");
103
+ expect(getConfigValue(config, "llm.apiKey")).toBeNull();
104
+ });
105
+ test("getConfigValue: embedding subkeys work", () => {
106
+ const config = {
107
+ ...base,
108
+ embedding: { endpoint: "http://localhost/emb", model: "bge-small" },
109
+ };
110
+ expect(getConfigValue(config, "embedding.endpoint")).toBe("http://localhost/emb");
111
+ expect(getConfigValue(config, "embedding.model")).toBe("bge-small");
112
+ expect(getConfigValue(config, "embedding.apiKey")).toBeNull();
113
+ });
114
+ // ── setConfigValue with deep merge ────────────────────────────────────────
115
+ test("setConfigValue: llm.endpoint preserves sibling model field", () => {
116
+ const config = {
117
+ ...base,
118
+ llm: { endpoint: "http://old/", model: "old-model" },
119
+ };
120
+ const result = setConfigValue(config, "llm.endpoint", "http://new/");
121
+ expect(result.llm?.endpoint).toBe("http://new/");
122
+ expect(result.llm?.model).toBe("old-model");
123
+ });
124
+ test("setConfigValue: llm.model preserves sibling endpoint field", () => {
125
+ const config = {
126
+ ...base,
127
+ llm: { endpoint: "http://localhost/v1", model: "old-model" },
128
+ };
129
+ const result = setConfigValue(config, "llm.model", "gpt-4o");
130
+ expect(result.llm?.model).toBe("gpt-4o");
131
+ expect(result.llm?.endpoint).toBe("http://localhost/v1");
132
+ });
133
+ test("setConfigValue: llm.apiKey merges into existing llm config", () => {
134
+ const config = {
135
+ ...base,
136
+ llm: { endpoint: "http://localhost/v1", model: "llama3.2" },
137
+ };
138
+ const result = setConfigValue(config, "llm.apiKey", "sk-secret");
139
+ expect(result.llm?.apiKey).toBe("sk-secret");
140
+ expect(result.llm?.endpoint).toBe("http://localhost/v1");
141
+ });
142
+ test("setConfigValue: embedding.endpoint works when embedding was undefined", () => {
143
+ const result = setConfigValue(base, "embedding.endpoint", "http://localhost/emb");
144
+ expect(result.embedding?.endpoint).toBe("http://localhost/emb");
145
+ expect(result.embedding?.model).toBe("");
146
+ });
147
+ // ── unsetConfigValue ──────────────────────────────────────────────────────
148
+ test("unsetConfigValue: llm.endpoint sets endpoint to empty string", () => {
149
+ const config = {
150
+ ...base,
151
+ llm: { endpoint: "http://localhost/v1", model: "llama3.2" },
152
+ };
153
+ const result = unsetConfigValue(config, "llm.endpoint");
154
+ expect(result.llm?.endpoint).toBe("");
155
+ expect(result.llm?.model).toBe("llama3.2");
156
+ });
157
+ test("unsetConfigValue: llm.apiKey removes the key", () => {
158
+ const config = {
159
+ ...base,
160
+ llm: { endpoint: "http://localhost/v1", model: "llama3.2", apiKey: "sk-secret" },
161
+ };
162
+ const result = unsetConfigValue(config, "llm.apiKey");
163
+ expect(result.llm?.apiKey).toBeUndefined();
164
+ expect(result.llm?.endpoint).toBe("http://localhost/v1");
165
+ });
166
+ test("unsetConfigValue: embedding.apiKey removes the key", () => {
167
+ const config = {
168
+ ...base,
169
+ embedding: { endpoint: "http://localhost/emb", model: "bge-small", apiKey: "sk-embed" },
170
+ };
171
+ const result = unsetConfigValue(config, "embedding.apiKey");
172
+ expect(result.embedding?.apiKey).toBeUndefined();
173
+ expect(result.embedding?.endpoint).toBe("http://localhost/emb");
174
+ });
175
+ });
176
+ // ── Cluster C: #14 empty query guard ────────────────────────────────────────
177
+ describe("search empty-query guard (#14, #24)", () => {
178
+ // Note: The empty-query guard for `akmSearch` lives in the CLI layer (src/cli.ts),
179
+ // not in `akmSearch` itself (which accepts empty queries for programmatic list-all).
180
+ // The guard for `akmCurate` IS in the function itself since curation always
181
+ // requires a meaningful query.
182
+ test("akmCurate throws UsageError for empty string query", async () => {
183
+ const { akmCurate } = await import("../src/commands/curate");
184
+ await expect(akmCurate({ query: "" })).rejects.toThrow(/query is required/i);
185
+ });
186
+ test("akmCurate throws UsageError for whitespace-only query", async () => {
187
+ const { akmCurate } = await import("../src/commands/curate");
188
+ await expect(akmCurate({ query: " " })).rejects.toThrow(/query is required/i);
189
+ });
190
+ test("akmCurate UsageError has MISSING_REQUIRED_ARGUMENT code", async () => {
191
+ const { akmCurate } = await import("../src/commands/curate");
192
+ const { UsageError } = await import("../src/core/errors");
193
+ try {
194
+ await akmCurate({ query: "" });
195
+ throw new Error("should have thrown");
196
+ }
197
+ catch (err) {
198
+ expect(err).toBeInstanceOf(UsageError);
199
+ expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
200
+ }
201
+ });
202
+ });
203
+ // ── Cluster C: #6 minScore floor ─────────────────────────────────────────────
204
+ describe("search.minScore floor in config (#6)", () => {
205
+ test("AkmConfig accepts search.minScore", () => {
206
+ const config = {
207
+ semanticSearchMode: "auto",
208
+ search: { minScore: 0.3 },
209
+ };
210
+ expect(config.search?.minScore).toBe(0.3);
211
+ });
212
+ test("AkmConfig accepts search.minScore of 0 (disabled)", () => {
213
+ const config = {
214
+ semanticSearchMode: "auto",
215
+ search: { minScore: 0 },
216
+ };
217
+ expect(config.search?.minScore).toBe(0);
218
+ });
219
+ test("minScore default is 0.2 in db-search (white-box)", () => {
220
+ // Verify the default is what the implementation docs: if search is
221
+ // undefined then minScore should be 0.2 (defaulted in db-search.ts).
222
+ const config = { semanticSearchMode: "auto" };
223
+ expect(config.search?.minScore).toBeUndefined();
224
+ // The effective default 0.2 is applied inside searchDatabase; we just
225
+ // confirm the config field default is undefined here. An integration test
226
+ // would require a live DB with semantic hits, which is out of scope.
227
+ });
228
+ });
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Wave-2 QA fixes tests — Cluster D (errors, exit codes, hint text).
3
+ *
4
+ * #8 — hint field rendered in error output (already working; regression guard).
5
+ * #13 — UsageError exits 2, ConfigError exits 78, NotFoundError exits 1.
6
+ * #15 — `akm show foo` (malformed ref) throws UsageError/MISSING_REQUIRED_ARGUMENT.
7
+ * #16 — `config set sources <bad>` says "sources" not "stashes".
8
+ * #27 — clone missing asset: user-facing message, no "Stash type root" leakage.
9
+ * #38 — deprecation hints reference real commands.
10
+ */
11
+ import { describe, expect, test } from "bun:test";
12
+ import { parseConfigValue } from "../src/commands/config-cli";
13
+ import { parseAssetRef } from "../src/core/asset-ref";
14
+ import { ConfigError, NotFoundError, UsageError } from "../src/core/errors";
15
+ // ── #15: parseAssetRef — MISSING_REQUIRED_ARGUMENT code ────────────────────
16
+ describe("parseAssetRef error codes (#15)", () => {
17
+ test("empty ref throws UsageError with MISSING_REQUIRED_ARGUMENT", () => {
18
+ try {
19
+ parseAssetRef("");
20
+ throw new Error("should have thrown");
21
+ }
22
+ catch (err) {
23
+ expect(err).toBeInstanceOf(UsageError);
24
+ expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
25
+ }
26
+ });
27
+ test("ref without colon throws UsageError with MISSING_REQUIRED_ARGUMENT", () => {
28
+ try {
29
+ parseAssetRef("foo");
30
+ throw new Error("should have thrown");
31
+ }
32
+ catch (err) {
33
+ expect(err).toBeInstanceOf(UsageError);
34
+ expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
35
+ }
36
+ });
37
+ test("ref with invalid type throws UsageError with MISSING_REQUIRED_ARGUMENT", () => {
38
+ try {
39
+ parseAssetRef("badtype:name");
40
+ throw new Error("should have thrown");
41
+ }
42
+ catch (err) {
43
+ expect(err).toBeInstanceOf(UsageError);
44
+ expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
45
+ }
46
+ });
47
+ test("valid ref parses correctly", () => {
48
+ const ref = parseAssetRef("skill:deploy");
49
+ expect(ref.type).toBe("skill");
50
+ expect(ref.name).toBe("deploy");
51
+ });
52
+ test("MISSING_REQUIRED_ARGUMENT has a hint in errors.ts", () => {
53
+ const err = new UsageError("test", "MISSING_REQUIRED_ARGUMENT");
54
+ expect(err.hint()).toBeDefined();
55
+ expect(err.hint()).toMatch(/type:name/);
56
+ });
57
+ });
58
+ // ── #13: exit code classification ────────────────────────────────────────────
59
+ describe("error class exit-code classification (#13)", () => {
60
+ test("UsageError should be classified as exit 2", () => {
61
+ const err = new UsageError("bad input");
62
+ // Verify the code exists so callers can distinguish
63
+ expect(err.name).toBe("UsageError");
64
+ expect(err instanceof UsageError).toBe(true);
65
+ });
66
+ test("ConfigError should be classified as exit 78", () => {
67
+ const err = new ConfigError("config bad");
68
+ expect(err.name).toBe("ConfigError");
69
+ expect(err instanceof ConfigError).toBe(true);
70
+ });
71
+ test("NotFoundError should be classified as exit 1 (GENERAL)", () => {
72
+ const err = new NotFoundError("not found");
73
+ expect(err.name).toBe("NotFoundError");
74
+ expect(err instanceof NotFoundError).toBe(true);
75
+ });
76
+ test("UsageError and ConfigError are distinguishable via instanceof", () => {
77
+ const usage = new UsageError("bad");
78
+ const config = new ConfigError("bad");
79
+ expect(usage instanceof UsageError).toBe(true);
80
+ expect(usage instanceof ConfigError).toBe(false);
81
+ expect(config instanceof ConfigError).toBe(true);
82
+ expect(config instanceof UsageError).toBe(false);
83
+ });
84
+ });
85
+ // ── #8: hint field rendered ───────────────────────────────────────────────────
86
+ describe("error hint rendering (#8)", () => {
87
+ test("ConfigError with hint: true returns hint", () => {
88
+ const err = new ConfigError("bad", "STASH_DIR_NOT_FOUND");
89
+ expect(err.hint()).toBeDefined();
90
+ expect(err.hint()).toMatch(/akm init/);
91
+ });
92
+ test("ConfigError with explicit hint returns it", () => {
93
+ const err = new ConfigError("bad", "INVALID_CONFIG_FILE", "my custom hint");
94
+ expect(err.hint()).toBe("my custom hint");
95
+ });
96
+ test("UsageError with INVALID_SOURCE_VALUE has a hint", () => {
97
+ const err = new UsageError("bad source", "INVALID_SOURCE_VALUE");
98
+ expect(err.hint()).toBeDefined();
99
+ expect(err.hint()).toContain("stash");
100
+ });
101
+ test("NotFoundError with ASSET_NOT_FOUND has a canned hint (Wave C #284)", () => {
102
+ const err = new NotFoundError("not found");
103
+ // Wave C added a default hint for ASSET_NOT_FOUND pointing at search/index.
104
+ expect(err.hint()).toContain("akm search");
105
+ });
106
+ test("NotFoundError with explicit hint returns it", () => {
107
+ const err = new NotFoundError("not found", "ASSET_NOT_FOUND", "run akm init");
108
+ expect(err.hint()).toBe("run akm init");
109
+ });
110
+ });
111
+ // ── #16: config set sources error message says "sources" ─────────────────────
112
+ describe("config-cli parseConfigValue sources error message (#16)", () => {
113
+ test("invalid sources value shows 'sources' not 'stashes' in error", () => {
114
+ try {
115
+ parseConfigValue("sources", "not-json");
116
+ throw new Error("should have thrown");
117
+ }
118
+ catch (err) {
119
+ expect(err).toBeInstanceOf(UsageError);
120
+ const msg = err.message;
121
+ expect(msg).toContain("sources");
122
+ expect(msg).not.toContain("stashes");
123
+ }
124
+ });
125
+ test("stashes alias also shows 'sources' in error", () => {
126
+ try {
127
+ parseConfigValue("stashes", "not-json");
128
+ throw new Error("should have thrown");
129
+ }
130
+ catch (err) {
131
+ expect(err).toBeInstanceOf(UsageError);
132
+ const msg = err.message;
133
+ expect(msg).toContain("sources");
134
+ }
135
+ });
136
+ test("invalid array element shows 'sources[0]' not 'stashes[0]'", () => {
137
+ try {
138
+ parseConfigValue("sources", "[{}]");
139
+ throw new Error("should have thrown");
140
+ }
141
+ catch (err) {
142
+ expect(err).toBeInstanceOf(UsageError);
143
+ const msg = err.message;
144
+ expect(msg).toContain("sources[0]");
145
+ expect(msg).not.toContain("stashes[0]");
146
+ }
147
+ });
148
+ });
149
+ // ── #27: source-resolve user-facing error messages ───────────────────────────
150
+ describe("source-resolve user-facing errors (#27)", () => {
151
+ test("error message does not contain 'Stash type root'", async () => {
152
+ // Import the resolver lazily so we don't pull in full DB on every test run.
153
+ const { resolveAssetPath } = await import("../src/sources/resolve");
154
+ try {
155
+ await resolveAssetPath("/tmp/nonexistent-stash-dir-xyz", "skill", "missing-skill");
156
+ throw new Error("should have thrown");
157
+ }
158
+ catch (err) {
159
+ expect(err).toBeInstanceOf(NotFoundError);
160
+ const msg = err.message;
161
+ expect(msg).not.toContain("Stash type root");
162
+ // Should contain user-facing wording
163
+ expect(msg).toMatch(/Asset not found for ref|not found for ref|not accessible/i);
164
+ }
165
+ });
166
+ test("error hint is set on the not-found error from source-resolve", async () => {
167
+ const { resolveAssetPath } = await import("../src/sources/resolve");
168
+ try {
169
+ await resolveAssetPath("/tmp/nonexistent-stash-dir-xyz", "skill", "missing-skill");
170
+ throw new Error("should have thrown");
171
+ }
172
+ catch (err) {
173
+ expect(err).toBeInstanceOf(NotFoundError);
174
+ const hint = err.hint();
175
+ // Should have an actionable hint
176
+ expect(hint).toBeDefined();
177
+ expect(hint).toMatch(/akm list|akm index/i);
178
+ }
179
+ });
180
+ });