akm-cli 0.6.0 → 0.7.0-rc1

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 (319) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/{cli.js → src/cli.js} +672 -29
  3. package/dist/{commands → src/commands}/config-cli.js +5 -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 +120 -0
  7. package/dist/{commands → src/commands}/installed-stashes.js +28 -2
  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 +2 -1
  12. package/dist/{commands → src/commands}/remember.js +12 -0
  13. package/dist/{commands → src/commands}/search.js +74 -1
  14. package/dist/{commands → src/commands}/self-update.js +4 -3
  15. package/dist/{commands → src/commands}/show.js +67 -2
  16. package/dist/{core → src/core}/asset-ref.js +5 -5
  17. package/dist/{core → src/core}/asset-spec.js +12 -0
  18. package/dist/{core → src/core}/common.js +1 -1
  19. package/dist/{core → src/core}/config.js +175 -121
  20. package/dist/{core → src/core}/errors.js +4 -0
  21. package/dist/src/core/events.js +239 -0
  22. package/dist/src/core/lesson-lint.js +86 -0
  23. package/dist/src/core/proposals.js +406 -0
  24. package/dist/src/core/warn.js +72 -0
  25. package/dist/{core → src/core}/write-source.js +80 -5
  26. package/dist/{indexer → src/indexer}/db-search.js +119 -27
  27. package/dist/{indexer → src/indexer}/db.js +76 -23
  28. package/dist/{indexer → src/indexer}/file-context.js +0 -3
  29. package/dist/src/indexer/graph-boost.js +179 -0
  30. package/dist/src/indexer/graph-extraction.js +212 -0
  31. package/dist/{indexer → src/indexer}/indexer.js +73 -6
  32. package/dist/src/indexer/memory-inference.js +263 -0
  33. package/dist/{indexer → src/indexer}/metadata.js +114 -11
  34. package/dist/src/integrations/agent/config.js +292 -0
  35. package/dist/src/integrations/agent/detect.js +94 -0
  36. package/dist/src/integrations/agent/index.js +17 -0
  37. package/dist/src/integrations/agent/profiles.js +65 -0
  38. package/dist/src/integrations/agent/prompts.js +167 -0
  39. package/dist/src/integrations/agent/spawn.js +221 -0
  40. package/dist/{integrations → src/integrations}/lockfile.js +0 -26
  41. package/dist/{llm → src/llm}/client.js +33 -2
  42. package/dist/src/llm/feature-gate.js +108 -0
  43. package/dist/src/llm/graph-extract.js +107 -0
  44. package/dist/src/llm/index-passes.js +35 -0
  45. package/dist/src/llm/memory-infer.js +86 -0
  46. package/dist/{output → src/output}/renderers.js +60 -1
  47. package/dist/src/output/shapes.js +516 -0
  48. package/dist/{output → src/output}/text.js +447 -4
  49. package/dist/{registry → src/registry}/build-index.js +14 -4
  50. package/dist/{registry → src/registry}/factory.js +0 -8
  51. package/dist/{registry → src/registry}/providers/static-index.js +3 -2
  52. package/dist/{registry → src/registry}/resolve.js +68 -2
  53. package/dist/{setup → src/setup}/setup.js +43 -5
  54. package/dist/{sources → src/sources}/providers/git.js +7 -15
  55. package/dist/{wiki → src/wiki}/wiki.js +9 -11
  56. package/dist/tests/add-website-source.test.js +119 -0
  57. package/dist/tests/agent/agent-config-loader.test.js +70 -0
  58. package/dist/tests/agent/agent-config.test.js +221 -0
  59. package/dist/tests/agent/agent-detect.test.js +100 -0
  60. package/dist/tests/agent/agent-spawn.test.js +234 -0
  61. package/dist/tests/agent-output.test.js +186 -0
  62. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
  63. package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
  64. package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
  65. package/dist/tests/asset-ref.test.js +192 -0
  66. package/dist/tests/asset-registry.test.js +103 -0
  67. package/dist/tests/asset-spec.test.js +241 -0
  68. package/dist/tests/bench/attribution.test.js +995 -0
  69. package/dist/tests/bench/cleanup-sigint.test.js +83 -0
  70. package/dist/tests/bench/cleanup.js +203 -0
  71. package/dist/tests/bench/cleanup.test.js +166 -0
  72. package/dist/tests/bench/cli.js +683 -0
  73. package/dist/tests/bench/cli.test.js +177 -0
  74. package/dist/tests/bench/compare.test.js +556 -0
  75. package/dist/tests/bench/corpus.js +314 -0
  76. package/dist/tests/bench/corpus.test.js +258 -0
  77. package/dist/tests/bench/driver.js +346 -0
  78. package/dist/tests/bench/driver.test.js +443 -0
  79. package/dist/tests/bench/evolve-metrics.js +179 -0
  80. package/dist/tests/bench/evolve-metrics.test.js +187 -0
  81. package/dist/tests/bench/evolve.js +580 -0
  82. package/dist/tests/bench/evolve.test.js +616 -0
  83. package/dist/tests/bench/failure-modes.test.js +300 -0
  84. package/dist/tests/bench/feedback-integrity.test.js +456 -0
  85. package/dist/tests/bench/leakage.test.js +125 -0
  86. package/dist/tests/bench/learning-curve.test.js +133 -0
  87. package/dist/tests/bench/metrics.js +2319 -0
  88. package/dist/tests/bench/metrics.test.js +1144 -0
  89. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
  90. package/dist/tests/bench/report.js +1821 -0
  91. package/dist/tests/bench/report.test.js +989 -0
  92. package/dist/tests/bench/runner.js +536 -0
  93. package/dist/tests/bench/runner.test.js +958 -0
  94. package/dist/tests/bench/search-bridge.test.js +331 -0
  95. package/dist/tests/bench/tmp.js +41 -0
  96. package/dist/tests/bench/trajectory.js +116 -0
  97. package/dist/tests/bench/trajectory.test.js +127 -0
  98. package/dist/tests/bench/verifier.js +109 -0
  99. package/dist/tests/bench/verifier.test.js +118 -0
  100. package/dist/tests/bench/workflow-evaluator.js +557 -0
  101. package/dist/tests/bench/workflow-evaluator.test.js +421 -0
  102. package/dist/tests/bench/workflow-spec.js +358 -0
  103. package/dist/tests/bench/workflow-spec.test.js +363 -0
  104. package/dist/tests/bench/workflow-trace.js +438 -0
  105. package/dist/tests/bench/workflow-trace.test.js +254 -0
  106. package/dist/tests/benchmark-search-quality.js +536 -0
  107. package/dist/tests/benchmark-suite.js +1441 -0
  108. package/dist/tests/capture-cli.test.js +112 -0
  109. package/dist/tests/cli-errors.test.js +203 -0
  110. package/dist/tests/commands/events.test.js +370 -0
  111. package/dist/tests/commands/history.test.js +223 -0
  112. package/dist/tests/commands/import.test.js +103 -0
  113. package/dist/tests/commands/proposal-cli.test.js +209 -0
  114. package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
  115. package/dist/tests/commands/remember.test.js +97 -0
  116. package/dist/tests/commands/scope-flags.test.js +300 -0
  117. package/dist/tests/commands/search.test.js +537 -0
  118. package/dist/tests/commands/show-indexer-parity.test.js +117 -0
  119. package/dist/tests/commands/show.test.js +294 -0
  120. package/dist/tests/common.test.js +266 -0
  121. package/dist/tests/completions.test.js +142 -0
  122. package/dist/tests/config-cli.test.js +193 -0
  123. package/dist/tests/config-llm-features.test.js +139 -0
  124. package/dist/tests/config.test.js +544 -0
  125. package/dist/tests/contracts/migration-baseline.test.js +43 -0
  126. package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
  127. package/dist/tests/contracts/spec-helpers.js +46 -0
  128. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
  129. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
  130. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
  131. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
  132. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
  133. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
  134. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
  135. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
  136. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
  137. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
  138. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
  139. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
  140. package/dist/tests/core/write-source.test.js +366 -0
  141. package/dist/tests/curate-command.test.js +87 -0
  142. package/dist/tests/db-scoring.test.js +201 -0
  143. package/dist/tests/db.test.js +654 -0
  144. package/dist/tests/distill-cli-flag.test.js +208 -0
  145. package/dist/tests/distill.test.js +515 -0
  146. package/dist/tests/docker-install.test.js +120 -0
  147. package/dist/tests/e2e.test.js +1398 -0
  148. package/dist/tests/embedder.test.js +340 -0
  149. package/dist/tests/embedding-model-config.test.js +379 -0
  150. package/dist/tests/feedback-command.test.js +172 -0
  151. package/dist/tests/file-context.test.js +552 -0
  152. package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
  153. package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
  154. package/dist/tests/fixtures/stashes/load.js +166 -0
  155. package/dist/tests/fixtures/stashes/load.test.js +88 -0
  156. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
  157. package/dist/tests/frontmatter.test.js +190 -0
  158. package/dist/tests/fts-field-weighting.test.js +254 -0
  159. package/dist/tests/fuzzy-search.test.js +230 -0
  160. package/dist/tests/git-provider-clone.test.js +45 -0
  161. package/dist/tests/github.test.js +161 -0
  162. package/dist/tests/graph-boost-ranking.test.js +305 -0
  163. package/dist/tests/graph-extraction.test.js +282 -0
  164. package/dist/tests/helpers/usage-events.js +8 -0
  165. package/dist/tests/index-pass-llm.test.js +161 -0
  166. package/dist/tests/indexer.test.js +559 -0
  167. package/dist/tests/info-command.test.js +166 -0
  168. package/dist/tests/init.test.js +69 -0
  169. package/dist/tests/install-script.test.js +246 -0
  170. package/dist/tests/integration/agent-real-profile.test.js +94 -0
  171. package/dist/tests/issue-36-repro.test.js +304 -0
  172. package/dist/tests/issues-191-194.test.js +160 -0
  173. package/dist/tests/lesson-lint.test.js +111 -0
  174. package/dist/tests/llm-client.test.js +115 -0
  175. package/dist/tests/llm-feature-gate.test.js +151 -0
  176. package/dist/tests/llm.test.js +139 -0
  177. package/dist/tests/lockfile.test.js +216 -0
  178. package/dist/tests/manifest.test.js +205 -0
  179. package/dist/tests/markdown.test.js +126 -0
  180. package/dist/tests/matchers-unit.test.js +189 -0
  181. package/dist/tests/memory-inference.test.js +299 -0
  182. package/dist/tests/merge-scoring.test.js +136 -0
  183. package/dist/tests/metadata.test.js +313 -0
  184. package/dist/tests/migration-help.test.js +89 -0
  185. package/dist/tests/origin-resolve.test.js +124 -0
  186. package/dist/tests/output-baseline.test.js +217 -0
  187. package/dist/tests/output-shapes-unit.test.js +476 -0
  188. package/dist/tests/parallel-search.test.js +272 -0
  189. package/dist/tests/parameter-metadata.test.js +365 -0
  190. package/dist/tests/paths.test.js +177 -0
  191. package/dist/tests/progressive-disclosure.test.js +280 -0
  192. package/dist/tests/proposals.test.js +279 -0
  193. package/dist/tests/proposed-quality.test.js +271 -0
  194. package/dist/tests/provider-registry.test.js +32 -0
  195. package/dist/tests/ranking-regression.test.js +548 -0
  196. package/dist/tests/reflect-propose.test.js +455 -0
  197. package/dist/tests/registry-build-index.test.js +378 -0
  198. package/dist/tests/registry-cli.test.js +290 -0
  199. package/dist/tests/registry-index-v2.test.js +430 -0
  200. package/dist/tests/registry-install.test.js +728 -0
  201. package/dist/tests/registry-providers/parity.test.js +189 -0
  202. package/dist/tests/registry-providers/skills-sh.test.js +309 -0
  203. package/dist/tests/registry-providers/static-index.test.js +204 -0
  204. package/dist/tests/registry-resolve.test.js +126 -0
  205. package/dist/tests/registry-search.test.js +723 -0
  206. package/dist/tests/remember-frontmatter.test.js +380 -0
  207. package/dist/tests/remember-unit.test.js +123 -0
  208. package/dist/tests/ripgrep-install.test.js +251 -0
  209. package/dist/tests/ripgrep-resolve.test.js +108 -0
  210. package/dist/tests/ripgrep.test.js +163 -0
  211. package/dist/tests/save-command.test.js +94 -0
  212. package/dist/tests/save-trust-qa-fixes.test.js +270 -0
  213. package/dist/tests/scoring-pipeline.test.js +648 -0
  214. package/dist/tests/search-include-proposed-cli.test.js +118 -0
  215. package/dist/tests/self-update.test.js +442 -0
  216. package/dist/tests/semantic-search-e2e.test.js +512 -0
  217. package/dist/tests/semantic-status.test.js +471 -0
  218. package/dist/tests/setup-run.integration.js +877 -0
  219. package/dist/tests/setup-wizard.test.js +198 -0
  220. package/dist/tests/setup.test.js +131 -0
  221. package/dist/tests/source-add.test.js +11 -0
  222. package/dist/tests/source-clone.test.js +254 -0
  223. package/dist/tests/source-manage.test.js +366 -0
  224. package/dist/tests/source-providers/filesystem.test.js +82 -0
  225. package/dist/tests/source-providers/git.test.js +252 -0
  226. package/dist/tests/source-providers/website.test.js +128 -0
  227. package/dist/tests/source-qa-fixes.test.js +268 -0
  228. package/dist/tests/source-registry.test.js +350 -0
  229. package/dist/tests/source-resolve.test.js +100 -0
  230. package/dist/tests/source-source.test.js +221 -0
  231. package/dist/tests/source.test.js +533 -0
  232. package/dist/tests/tar-utils-scan.test.js +73 -0
  233. package/dist/tests/toggle-components.test.js +73 -0
  234. package/dist/tests/usage-telemetry.test.js +265 -0
  235. package/dist/tests/utility-scoring.test.js +558 -0
  236. package/dist/tests/vault-load-error.test.js +78 -0
  237. package/dist/tests/vault-qa-fixes.test.js +194 -0
  238. package/dist/tests/vault.test.js +429 -0
  239. package/dist/tests/vector-search.test.js +608 -0
  240. package/dist/tests/walker.test.js +252 -0
  241. package/dist/tests/wave2-cluster-bc.test.js +228 -0
  242. package/dist/tests/wave2-cluster-d.test.js +180 -0
  243. package/dist/tests/wave2-cluster-e.test.js +179 -0
  244. package/dist/tests/wiki-qa-fixes.test.js +270 -0
  245. package/dist/tests/wiki.test.js +529 -0
  246. package/dist/tests/workflow-cli.test.js +271 -0
  247. package/dist/tests/workflow-markdown.test.js +171 -0
  248. package/dist/tests/workflow-path-escape.test.js +132 -0
  249. package/dist/tests/workflow-qa-fixes.test.js +377 -0
  250. package/dist/tests/workflows/indexer-rejection.test.js +213 -0
  251. package/docs/README.md +8 -0
  252. package/docs/migration/release-notes/0.7.0.md +244 -0
  253. package/package.json +2 -2
  254. package/dist/core/warn.js +0 -27
  255. package/dist/output/shapes.js +0 -212
  256. /package/dist/{commands → src/commands}/completions.js +0 -0
  257. /package/dist/{commands → src/commands}/curate.js +0 -0
  258. /package/dist/{commands → src/commands}/info.js +0 -0
  259. /package/dist/{commands → src/commands}/init.js +0 -0
  260. /package/dist/{commands → src/commands}/install-audit.js +0 -0
  261. /package/dist/{commands → src/commands}/migration-help.js +0 -0
  262. /package/dist/{commands → src/commands}/source-add.js +0 -0
  263. /package/dist/{commands → src/commands}/source-clone.js +0 -0
  264. /package/dist/{commands → src/commands}/source-manage.js +0 -0
  265. /package/dist/{commands → src/commands}/vault.js +0 -0
  266. /package/dist/{core → src/core}/asset-registry.js +0 -0
  267. /package/dist/{core → src/core}/frontmatter.js +0 -0
  268. /package/dist/{core → src/core}/markdown.js +0 -0
  269. /package/dist/{core → src/core}/paths.js +0 -0
  270. /package/dist/{indexer → src/indexer}/manifest.js +0 -0
  271. /package/dist/{indexer → src/indexer}/matchers.js +0 -0
  272. /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
  273. /package/dist/{indexer → src/indexer}/search-source.js +0 -0
  274. /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
  275. /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
  276. /package/dist/{indexer → src/indexer}/walker.js +0 -0
  277. /package/dist/{integrations → src/integrations}/github.js +0 -0
  278. /package/dist/{llm → src/llm}/embedder.js +0 -0
  279. /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
  280. /package/dist/{llm → src/llm}/embedders/local.js +0 -0
  281. /package/dist/{llm → src/llm}/embedders/remote.js +0 -0
  282. /package/dist/{llm → src/llm}/embedders/types.js +0 -0
  283. /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
  284. /package/dist/{output → src/output}/cli-hints.js +0 -0
  285. /package/dist/{output → src/output}/context.js +0 -0
  286. /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
  287. /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
  288. /package/dist/{registry → src/registry}/providers/index.js +0 -0
  289. /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
  290. /package/dist/{registry → src/registry}/providers/types.js +0 -0
  291. /package/dist/{registry → src/registry}/types.js +0 -0
  292. /package/dist/{setup → src/setup}/detect.js +0 -0
  293. /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
  294. /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
  295. /package/dist/{setup → src/setup}/steps.js +0 -0
  296. /package/dist/{sources → src/sources}/include.js +0 -0
  297. /package/dist/{sources → src/sources}/provider-factory.js +0 -0
  298. /package/dist/{sources → src/sources}/provider.js +0 -0
  299. /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
  300. /package/dist/{sources → src/sources}/providers/index.js +0 -0
  301. /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
  302. /package/dist/{sources → src/sources}/providers/npm.js +0 -0
  303. /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
  304. /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
  305. /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
  306. /package/dist/{sources → src/sources}/providers/website.js +0 -0
  307. /package/dist/{sources → src/sources}/resolve.js +0 -0
  308. /package/dist/{sources → src/sources}/types.js +0 -0
  309. /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
  310. /package/dist/{version.js → src/version.js} +0 -0
  311. /package/dist/{workflows → src/workflows}/authoring.js +0 -0
  312. /package/dist/{workflows → src/workflows}/cli.js +0 -0
  313. /package/dist/{workflows → src/workflows}/db.js +0 -0
  314. /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
  315. /package/dist/{workflows → src/workflows}/parser.js +0 -0
  316. /package/dist/{workflows → src/workflows}/renderer.js +0 -0
  317. /package/dist/{workflows → src/workflows}/runs.js +0 -0
  318. /package/dist/{workflows → src/workflows}/schema.js +0 -0
  319. /package/dist/{workflows → src/workflows}/validator.js +0 -0
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Wave-2 QA fixes tests — Cluster E (output shapes, remember, info, vault, registry brief).
3
+ *
4
+ * #2 — `akm info` populates sourceProviders from stashDir when sources[] is empty.
5
+ * #7 — `akm show` JSON shape always includes path + editable.
6
+ * #20 — `akm remember --description` persisted in frontmatter.
7
+ * #28 — `registry search --detail brief` projects name + installRef + score.
8
+ * #35 — Vault list returns entries:[{key,comment}] instead of parallel arrays.
9
+ */
10
+ import { describe, expect, test } from "bun:test";
11
+ import fs from "node:fs";
12
+ import os from "node:os";
13
+ import path from "node:path";
14
+ import { buildMemoryFrontmatter } from "../src/commands/remember";
15
+ import { listEntries } from "../src/commands/vault";
16
+ import { shapeSearchHit, shapeShowOutput } from "../src/output/shapes";
17
+ // ── #7: show shape includes path + editable ───────────────────────────────────
18
+ describe("shapeShowOutput — path + editable always included (#7)", () => {
19
+ const showResult = {
20
+ type: "skill",
21
+ name: "deploy",
22
+ origin: null,
23
+ action: "akm show skill:deploy",
24
+ description: "Deploy script",
25
+ path: "/home/user/stash/skills/deploy/SKILL.md",
26
+ editable: true,
27
+ editHint: "vim /home/user/stash/skills/deploy/SKILL.md",
28
+ content: "# Deploy\nRun deploy.",
29
+ };
30
+ test("default detail includes path and editable", () => {
31
+ const out = shapeShowOutput(showResult, "normal");
32
+ expect(out).toHaveProperty("path");
33
+ expect(out).toHaveProperty("editable");
34
+ expect(out.path).toBe("/home/user/stash/skills/deploy/SKILL.md");
35
+ expect(out.editable).toBe(true);
36
+ });
37
+ test("brief detail also includes path and editable", () => {
38
+ const out = shapeShowOutput(showResult, "brief");
39
+ expect(out).toHaveProperty("path");
40
+ expect(out).toHaveProperty("editable");
41
+ });
42
+ test("full detail includes path, editable, and editHint", () => {
43
+ const out = shapeShowOutput(showResult, "full");
44
+ expect(out).toHaveProperty("path");
45
+ expect(out).toHaveProperty("editable");
46
+ expect(out).toHaveProperty("editHint");
47
+ });
48
+ test("agent mode does NOT expose path (security: keep in non-agent shape only)", () => {
49
+ const out = shapeShowOutput(showResult, "normal", /* forAgent */ true);
50
+ // Agent mode picks a minimal subset; path is not in that subset
51
+ expect(out.editable).toBeUndefined();
52
+ expect(out.path).toBeUndefined();
53
+ });
54
+ });
55
+ // ── #28: registry brief projects name + installRef + score ───────────────────
56
+ describe("shapeSearchHit — registry brief projects name + score (#28)", () => {
57
+ // v1 spec §4.2: registry hits no longer carry the legacy `curated` boolean.
58
+ const registryHit = {
59
+ type: "registry",
60
+ title: "deploy-stash",
61
+ name: "deploy-stash",
62
+ installRef: "npm:@myorg/deploy-stash",
63
+ description: "A deployment stash",
64
+ action: "akm add npm:@myorg/deploy-stash -> then search again",
65
+ score: 0.85,
66
+ };
67
+ test("brief includes name, installRef, score", () => {
68
+ const out = shapeSearchHit(registryHit, "brief");
69
+ expect(out.name).toBeTruthy();
70
+ expect(out.score).toBe(0.85);
71
+ // installRef should be present when it exists
72
+ expect(out.installRef).toBe("npm:@myorg/deploy-stash");
73
+ });
74
+ test("brief with only title (no name field): normalises title → name", () => {
75
+ const hit = {
76
+ type: "registry",
77
+ title: "some-kit",
78
+ installRef: "github:org/some-kit",
79
+ score: 0.5,
80
+ };
81
+ const out = shapeSearchHit(hit, "brief");
82
+ expect(out.name).toBe("some-kit");
83
+ });
84
+ test("brief does NOT return empty object for registry hits", () => {
85
+ const out = shapeSearchHit(registryHit, "brief");
86
+ expect(Object.keys(out).length).toBeGreaterThan(0);
87
+ });
88
+ test("normal mode keeps description, action, installRef, score (curated removed in v1)", () => {
89
+ const out = shapeSearchHit(registryHit, "normal");
90
+ expect(out.description).toBeDefined();
91
+ expect(out.installRef).toBeDefined();
92
+ expect(out.score).toBe(0.85);
93
+ expect(out).not.toHaveProperty("curated");
94
+ });
95
+ });
96
+ // ── #20: --description persisted in frontmatter ──────────────────────────────
97
+ describe("buildMemoryFrontmatter — description field (#20)", () => {
98
+ test("description is included when present", () => {
99
+ const fm = buildMemoryFrontmatter({
100
+ description: "Short description of this memory",
101
+ tags: ["test"],
102
+ });
103
+ expect(fm).toContain("description:");
104
+ expect(fm).toContain("Short description of this memory");
105
+ });
106
+ test("description is omitted when not present", () => {
107
+ const fm = buildMemoryFrontmatter({ tags: ["test"] });
108
+ expect(fm).not.toContain("description:");
109
+ });
110
+ test("description is omitted when empty", () => {
111
+ const fm = buildMemoryFrontmatter({ description: "", tags: ["test"] });
112
+ expect(fm).not.toContain("description:");
113
+ });
114
+ test("description is omitted when whitespace only", () => {
115
+ const fm = buildMemoryFrontmatter({ description: " ", tags: ["test"] });
116
+ expect(fm).not.toContain("description:");
117
+ });
118
+ test("description with special chars is safely serialised", () => {
119
+ const fm = buildMemoryFrontmatter({
120
+ description: 'value with: "quotes" and \nnewlines',
121
+ tags: ["test"],
122
+ });
123
+ expect(fm).toContain("description:");
124
+ // Should be quoted to handle special chars
125
+ });
126
+ });
127
+ // ── #35: vault list returns entries:[{key,comment}] ──────────────────────────
128
+ describe("vault listEntries — entries shape (#35)", () => {
129
+ function makeTmpVault(content) {
130
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-vault-test-"));
131
+ const vaultPath = path.join(tmpDir, "test.env");
132
+ fs.writeFileSync(vaultPath, content);
133
+ return vaultPath;
134
+ }
135
+ test("returns empty array for nonexistent vault", () => {
136
+ const result = listEntries("/tmp/nonexistent-vault-file-xyz.env");
137
+ expect(result).toEqual([]);
138
+ });
139
+ test("returns keys without comments for uncommented vault", () => {
140
+ const vaultPath = makeTmpVault("DB_URL=postgres://localhost\nAPI_KEY=secret\n");
141
+ const entries = listEntries(vaultPath);
142
+ expect(entries.map((e) => e.key)).toEqual(["DB_URL", "API_KEY"]);
143
+ expect(entries.every((e) => e.comment === undefined)).toBe(true);
144
+ });
145
+ test("associates comment with the following key", () => {
146
+ const vaultPath = makeTmpVault("# Database connection URL\nDB_URL=postgres://localhost\n");
147
+ const entries = listEntries(vaultPath);
148
+ expect(entries).toHaveLength(1);
149
+ expect(entries[0].key).toBe("DB_URL");
150
+ expect(entries[0].comment).toBe("Database connection URL");
151
+ });
152
+ test("returns {key, comment} shape", () => {
153
+ const vaultPath = makeTmpVault("# API key\nAPI_KEY=secret\n# DB\nDB_URL=pg://localhost\n");
154
+ const entries = listEntries(vaultPath);
155
+ expect(entries).toHaveLength(2);
156
+ expect(entries[0]).toMatchObject({ key: "API_KEY", comment: "API key" });
157
+ expect(entries[1]).toMatchObject({ key: "DB_URL", comment: "DB" });
158
+ });
159
+ test("duplicate keys: only first occurrence kept", () => {
160
+ const vaultPath = makeTmpVault("DB_URL=first\nDB_URL=second\n");
161
+ const entries = listEntries(vaultPath);
162
+ expect(entries.map((e) => e.key)).toEqual(["DB_URL"]);
163
+ });
164
+ test("entry has no comment field when there's no preceding comment", () => {
165
+ const vaultPath = makeTmpVault("API_KEY=abc\n");
166
+ const entries = listEntries(vaultPath);
167
+ expect(entries[0].comment).toBeUndefined();
168
+ });
169
+ });
170
+ // ── #2: info sourceProviders from stashDir ────────────────────────────────────
171
+ describe("assembleInfo — sourceProviders populated from stashDir (#2)", () => {
172
+ test("sourceProviders includes stashDir when sources[] is empty", () => {
173
+ const { assembleInfo } = require("../src/commands/info");
174
+ // We can't easily override loadConfig, but we can verify the function shape.
175
+ // The actual integration is tested via the info-command.test.ts suite.
176
+ // This is a unit-level smoke test that the function signature is stable.
177
+ expect(typeof assembleInfo).toBe("function");
178
+ });
179
+ });
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Regression tests for the 0.5.0 QA wiki fixes.
3
+ *
4
+ * Covers:
5
+ * 1. searchInWiki excludes schema.md, index.md, and log.md.
6
+ * 2. stashRaw with explicitSlug: true throws UsageError on collision;
7
+ * with explicitSlug: false auto-increments.
8
+ * 3. lintWiki emits broken-source findings for dangling sources: refs.
9
+ * 4. validateWikiName error message includes "lowercase".
10
+ * 5. wiki search on a nonexistent wiki throws NotFoundError.
11
+ */
12
+ import { afterEach, describe, expect, test } from "bun:test";
13
+ import fs from "node:fs";
14
+ import os from "node:os";
15
+ import path from "node:path";
16
+ import { UsageError } from "../src/core/errors";
17
+ import { createWiki, INDEX_MD, LOG_MD, lintWiki, SCHEMA_MD, searchInWiki, stashRaw, validateWikiName, WIKIS_SUBDIR, } from "../src/wiki/wiki";
18
+ const tempDirs = [];
19
+ function makeStash(prefix = "akm-wiki-qa-") {
20
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
21
+ tempDirs.push(dir);
22
+ return dir;
23
+ }
24
+ function writePage(wikiDir, relPath, body) {
25
+ const abs = path.join(wikiDir, relPath);
26
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
27
+ fs.writeFileSync(abs, body, "utf8");
28
+ return abs;
29
+ }
30
+ afterEach(() => {
31
+ for (const dir of tempDirs.splice(0)) {
32
+ fs.rmSync(dir, { recursive: true, force: true });
33
+ }
34
+ });
35
+ /**
36
+ * Set up an isolated stash env for searchInWiki tests.
37
+ * Returns the stash dir and a cleanup function.
38
+ */
39
+ function withIsolatedStash() {
40
+ const stash = makeStash();
41
+ const origStash = process.env.AKM_STASH_DIR;
42
+ const origHome = process.env.XDG_CONFIG_HOME;
43
+ const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "akm-wiki-qa-home-"));
44
+ tempDirs.push(tmpHome);
45
+ process.env.AKM_STASH_DIR = stash;
46
+ process.env.XDG_CONFIG_HOME = tmpHome;
47
+ return {
48
+ stash,
49
+ cleanup() {
50
+ if (origStash === undefined)
51
+ delete process.env.AKM_STASH_DIR;
52
+ else
53
+ process.env.AKM_STASH_DIR = origStash;
54
+ if (origHome === undefined)
55
+ delete process.env.XDG_CONFIG_HOME;
56
+ else
57
+ process.env.XDG_CONFIG_HOME = origHome;
58
+ },
59
+ };
60
+ }
61
+ // ── 1. searchInWiki excludes infrastructure files ───────────────────────────
62
+ describe("searchInWiki — infrastructure file exclusion", () => {
63
+ test("excludes schema.md, index.md, log.md from results", async () => {
64
+ const { stash, cleanup } = withIsolatedStash();
65
+ try {
66
+ createWiki(stash, "research");
67
+ const wikiDir = path.join(stash, WIKIS_SUBDIR, "research");
68
+ writePage(wikiDir, "ml-basics.md", "---\ndescription: Machine learning basics\n---\n# ML Basics\nContent.\n");
69
+ const response = await searchInWiki({
70
+ stashDir: stash,
71
+ wikiName: "research",
72
+ query: "machine learning",
73
+ });
74
+ // All returned hits must not be special infrastructure files
75
+ for (const hit of response.hits) {
76
+ if (hit.type === "registry")
77
+ continue;
78
+ const stashHit = hit;
79
+ if (!stashHit.path)
80
+ continue;
81
+ const basename = path.basename(stashHit.path);
82
+ expect([SCHEMA_MD, INDEX_MD, LOG_MD]).not.toContain(basename);
83
+ }
84
+ }
85
+ finally {
86
+ cleanup();
87
+ }
88
+ });
89
+ test("does not exclude real page files", async () => {
90
+ const { stash, cleanup } = withIsolatedStash();
91
+ try {
92
+ createWiki(stash, "research");
93
+ const wikiDir = path.join(stash, WIKIS_SUBDIR, "research");
94
+ writePage(wikiDir, "valid-page.md", "---\ndescription: A real page\n---\n# Valid\n");
95
+ // No assertion about hit presence (index may be absent); just no throw.
96
+ const response = await searchInWiki({
97
+ stashDir: stash,
98
+ wikiName: "research",
99
+ query: "real page",
100
+ });
101
+ expect(response).toBeDefined();
102
+ expect(Array.isArray(response.hits)).toBe(true);
103
+ }
104
+ finally {
105
+ cleanup();
106
+ }
107
+ });
108
+ });
109
+ // ── 2. stashRaw explicitSlug collision behaviour ─────────────────────────────
110
+ describe("stashRaw — explicitSlug", () => {
111
+ test("explicitSlug: true throws UsageError on collision", () => {
112
+ const stash = makeStash();
113
+ createWiki(stash, "research");
114
+ // First write succeeds
115
+ stashRaw({
116
+ stashDir: stash,
117
+ wikiName: "research",
118
+ content: "first",
119
+ preferredName: "mysource",
120
+ explicitSlug: true,
121
+ });
122
+ // Second write with same slug and explicitSlug: true must throw
123
+ expect(() => stashRaw({
124
+ stashDir: stash,
125
+ wikiName: "research",
126
+ content: "second",
127
+ preferredName: "mysource",
128
+ explicitSlug: true,
129
+ })).toThrow(UsageError);
130
+ });
131
+ test("UsageError message mentions the slug, 'already exists', and '--as'", () => {
132
+ const stash = makeStash();
133
+ createWiki(stash, "research");
134
+ stashRaw({ stashDir: stash, wikiName: "research", content: "first", preferredName: "myslug", explicitSlug: true });
135
+ let caught;
136
+ try {
137
+ stashRaw({
138
+ stashDir: stash,
139
+ wikiName: "research",
140
+ content: "second",
141
+ preferredName: "myslug",
142
+ explicitSlug: true,
143
+ });
144
+ }
145
+ catch (e) {
146
+ caught = e;
147
+ }
148
+ expect(caught).toBeInstanceOf(UsageError);
149
+ expect(caught?.message).toContain("myslug");
150
+ expect(caught?.message).toContain("already exists");
151
+ expect(caught?.message).toContain("--as");
152
+ });
153
+ test("explicitSlug: false auto-increments on collision (existing behaviour)", () => {
154
+ const stash = makeStash();
155
+ createWiki(stash, "research");
156
+ const r1 = stashRaw({
157
+ stashDir: stash,
158
+ wikiName: "research",
159
+ content: "a",
160
+ preferredName: "dup",
161
+ explicitSlug: false,
162
+ });
163
+ const r2 = stashRaw({
164
+ stashDir: stash,
165
+ wikiName: "research",
166
+ content: "b",
167
+ preferredName: "dup",
168
+ explicitSlug: false,
169
+ });
170
+ expect(r1.slug).toBe("dup");
171
+ expect(r2.slug).toBe("dup-1");
172
+ });
173
+ test("explicitSlug: undefined auto-increments (backward-compat)", () => {
174
+ const stash = makeStash();
175
+ createWiki(stash, "research");
176
+ const r1 = stashRaw({ stashDir: stash, wikiName: "research", content: "a", preferredName: "nodups" });
177
+ const r2 = stashRaw({ stashDir: stash, wikiName: "research", content: "b", preferredName: "nodups" });
178
+ expect(r1.slug).toBe("nodups");
179
+ expect(r2.slug).toBe("nodups-1");
180
+ });
181
+ test("explicitSlug: true on a new slug does NOT throw", () => {
182
+ const stash = makeStash();
183
+ createWiki(stash, "research");
184
+ expect(() => stashRaw({ stashDir: stash, wikiName: "research", content: "x", preferredName: "brand-new", explicitSlug: true })).not.toThrow();
185
+ });
186
+ });
187
+ // ── 3. lintWiki broken-source findings ──────────────────────────────────────
188
+ describe("lintWiki — broken-source", () => {
189
+ test("emits broken-source finding when sources: references a missing raw file", () => {
190
+ const stash = makeStash();
191
+ createWiki(stash, "research");
192
+ const wikiDir = path.join(stash, WIKIS_SUBDIR, "research");
193
+ // Page that references a raw file that doesn't exist
194
+ writePage(wikiDir, "orphaned-page.md", "---\ndescription: Page with dangling source ref\nxrefs:\n - wiki:research/orphaned-page\nsources:\n - raw/ghost-paper\n---\n# Orphaned\n");
195
+ const report = lintWiki(stash, "research");
196
+ const brokenSrc = report.findings.filter((f) => f.kind === "broken-source");
197
+ expect(brokenSrc.length).toBeGreaterThanOrEqual(1);
198
+ expect(brokenSrc[0].refs[0]).toBe("wiki:research/orphaned-page");
199
+ expect(brokenSrc[0].message).toContain("ghost-paper");
200
+ });
201
+ test("does NOT emit broken-source when raw file exists", () => {
202
+ const stash = makeStash();
203
+ createWiki(stash, "research");
204
+ const wikiDir = path.join(stash, WIKIS_SUBDIR, "research");
205
+ // Stash the raw file first
206
+ stashRaw({ stashDir: stash, wikiName: "research", content: "raw content", preferredName: "real-paper" });
207
+ // Page citing the existing raw file — must NOT trigger broken-source
208
+ writePage(wikiDir, "good-page.md", "---\ndescription: Page with valid source ref\nxrefs:\n - wiki:research/good-page\nsources:\n - raw/real-paper\n---\n# Good\n");
209
+ const report = lintWiki(stash, "research");
210
+ const brokenSrc = report.findings.filter((f) => f.kind === "broken-source");
211
+ expect(brokenSrc.length).toBe(0);
212
+ });
213
+ test("accepts both 'raw/slug' and 'raw/slug.md' source forms", () => {
214
+ const stash = makeStash();
215
+ createWiki(stash, "research");
216
+ const wikiDir = path.join(stash, WIKIS_SUBDIR, "research");
217
+ stashRaw({ stashDir: stash, wikiName: "research", content: "raw", preferredName: "existing-slug" });
218
+ // Cite with .md extension — should not break
219
+ writePage(wikiDir, "page-with-ext.md", "---\ndescription: Cites with .md extension\nxrefs:\n - wiki:research/page-with-ext\nsources:\n - raw/existing-slug.md\n---\n# Ext\n");
220
+ const report = lintWiki(stash, "research");
221
+ const brokenSrc = report.findings.filter((f) => f.kind === "broken-source");
222
+ expect(brokenSrc.length).toBe(0);
223
+ });
224
+ });
225
+ // ── 4. validateWikiName error message includes "lowercase" ───────────────────
226
+ describe("validateWikiName — error message", () => {
227
+ test("error message says 'lowercase' when name has uppercase letters", () => {
228
+ let caught;
229
+ try {
230
+ validateWikiName("MyWiki");
231
+ }
232
+ catch (e) {
233
+ caught = e;
234
+ }
235
+ expect(caught).toBeInstanceOf(UsageError);
236
+ expect(caught?.message.toLowerCase()).toContain("lowercase");
237
+ });
238
+ test("error message says 'lowercase' for leading-hyphen names", () => {
239
+ let caught;
240
+ try {
241
+ validateWikiName("-bad");
242
+ }
243
+ catch (e) {
244
+ caught = e;
245
+ }
246
+ expect(caught).toBeInstanceOf(UsageError);
247
+ expect(caught?.message.toLowerCase()).toContain("lowercase");
248
+ });
249
+ });
250
+ // ── 5. searchInWiki on nonexistent wiki throws NotFoundError ─────────────────
251
+ describe("searchInWiki — nonexistent wiki", () => {
252
+ test("throws (via validateWikiName) for invalid wiki names", () => {
253
+ const stash = makeStash();
254
+ // An uppercase name fails validateWikiName, which is called by searchInWiki
255
+ expect(() => searchInWiki({ stashDir: stash, wikiName: "BadName", query: "test" })).toThrow();
256
+ });
257
+ test("valid-but-missing wiki name returns zero hits (path-filter drops everything)", async () => {
258
+ // searchInWiki itself does not throw for a valid-but-absent wiki dir — it
259
+ // just returns zero hits because the path-filter drops all non-wiki-dir
260
+ // paths. The CLI layer adds the explicit existence check.
261
+ const { stash, cleanup } = withIsolatedStash();
262
+ try {
263
+ const response = await searchInWiki({ stashDir: stash, wikiName: "nonexistent", query: "test" });
264
+ expect(response.hits).toEqual([]);
265
+ }
266
+ finally {
267
+ cleanup();
268
+ }
269
+ });
270
+ });