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,205 @@
1
+ /**
2
+ * Tests for the `akm manifest` command (Task E-1: Deferred/Lazy Tool Loading).
3
+ *
4
+ * The manifest provides a compact asset listing (name, type, ref, one-line
5
+ * description) that stays under 500 tokens for 50 assets, giving agents a
6
+ * cheap way to discover capabilities without loading full content.
7
+ */
8
+ import { afterAll, afterEach, beforeEach, describe, expect, test } from "bun:test";
9
+ import fs from "node:fs";
10
+ import os from "node:os";
11
+ import path from "node:path";
12
+ import { saveConfig } from "../src/core/config";
13
+ import { akmIndex } from "../src/indexer/indexer";
14
+ import { akmManifest } from "../src/indexer/manifest";
15
+ // ── Temp directory tracking ─────────────────────────────────────────────────
16
+ const createdTmpDirs = [];
17
+ function createTmpDir(prefix = "akm-manifest-") {
18
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
19
+ createdTmpDirs.push(dir);
20
+ return dir;
21
+ }
22
+ afterAll(() => {
23
+ for (const dir of createdTmpDirs) {
24
+ fs.rmSync(dir, { recursive: true, force: true });
25
+ }
26
+ });
27
+ // ── Helpers ─────────────────────────────────────────────────────────────────
28
+ function tmpStash() {
29
+ const dir = createTmpDir("akm-manifest-stash-");
30
+ for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
31
+ fs.mkdirSync(path.join(dir, sub), { recursive: true });
32
+ }
33
+ return dir;
34
+ }
35
+ async function buildTestIndex(stashDir, files = {}) {
36
+ for (const [relPath, content] of Object.entries(files)) {
37
+ const fullPath = path.join(stashDir, relPath);
38
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
39
+ fs.writeFileSync(fullPath, content);
40
+ }
41
+ process.env.AKM_STASH_DIR = stashDir;
42
+ saveConfig({ semanticSearchMode: "off" });
43
+ await akmIndex({ stashDir, full: true });
44
+ }
45
+ // ── Environment isolation ───────────────────────────────────────────────────
46
+ const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
47
+ const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
48
+ const originalAkmStashDir = process.env.AKM_STASH_DIR;
49
+ let testCacheDir = "";
50
+ let testConfigDir = "";
51
+ beforeEach(() => {
52
+ testCacheDir = createTmpDir("akm-manifest-cache-");
53
+ testConfigDir = createTmpDir("akm-manifest-config-");
54
+ process.env.XDG_CACHE_HOME = testCacheDir;
55
+ process.env.XDG_CONFIG_HOME = testConfigDir;
56
+ });
57
+ afterEach(() => {
58
+ if (originalXdgCacheHome === undefined) {
59
+ delete process.env.XDG_CACHE_HOME;
60
+ }
61
+ else {
62
+ process.env.XDG_CACHE_HOME = originalXdgCacheHome;
63
+ }
64
+ if (originalXdgConfigHome === undefined) {
65
+ delete process.env.XDG_CONFIG_HOME;
66
+ }
67
+ else {
68
+ process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
69
+ }
70
+ if (originalAkmStashDir === undefined) {
71
+ delete process.env.AKM_STASH_DIR;
72
+ }
73
+ else {
74
+ process.env.AKM_STASH_DIR = originalAkmStashDir;
75
+ }
76
+ });
77
+ // ── Tests ───────────────────────────────────────────────────────────────────
78
+ describe("akm manifest", () => {
79
+ test("returns all indexed entries", async () => {
80
+ const stashDir = tmpStash();
81
+ await buildTestIndex(stashDir, {
82
+ "scripts/deploy/deploy.sh": "#!/bin/bash\n# Deploy to production\necho deploy",
83
+ "scripts/lint/lint.sh": "#!/bin/bash\n# Run linter\necho lint",
84
+ "skills/code-review/SKILL.md": "---\ndescription: Review code for quality\n---\n# Code Review",
85
+ "commands/build/BUILD.md": "---\ndescription: Build the project\n---\n# Build",
86
+ "knowledge/api-docs/api-docs.md": "---\ndescription: API documentation reference\n---\n# API Docs",
87
+ });
88
+ const result = await akmManifest({ stashDir });
89
+ expect(result.entries.length).toBe(5);
90
+ });
91
+ test("entries have compact shape (name, type, ref, description only)", async () => {
92
+ const stashDir = tmpStash();
93
+ await buildTestIndex(stashDir, {
94
+ "scripts/deploy/deploy.sh": "#!/bin/bash\n# Deploy to production\necho deploy",
95
+ });
96
+ const result = await akmManifest({ stashDir });
97
+ expect(result.entries.length).toBeGreaterThan(0);
98
+ const entry = result.entries[0];
99
+ // Must have the compact fields
100
+ expect(typeof entry.name).toBe("string");
101
+ expect(typeof entry.type).toBe("string");
102
+ expect(typeof entry.ref).toBe("string");
103
+ // Must NOT have full search hit fields like path, tags, score, action, whyMatched
104
+ const raw = entry;
105
+ expect(raw.path).toBeUndefined();
106
+ expect(raw.tags).toBeUndefined();
107
+ expect(raw.score).toBeUndefined();
108
+ expect(raw.action).toBeUndefined();
109
+ expect(raw.whyMatched).toBeUndefined();
110
+ expect(raw.searchText).toBeUndefined();
111
+ });
112
+ test("filters by type", async () => {
113
+ const stashDir = tmpStash();
114
+ await buildTestIndex(stashDir, {
115
+ "scripts/deploy/deploy.sh": "#!/bin/bash\n# Deploy to production\necho deploy",
116
+ "scripts/lint/lint.sh": "#!/bin/bash\n# Run linter\necho lint",
117
+ "skills/code-review/SKILL.md": "---\ndescription: Review code for quality\n---\n# Code Review",
118
+ });
119
+ const result = await akmManifest({ stashDir, type: "script" });
120
+ expect(result.entries.length).toBe(2);
121
+ for (const entry of result.entries) {
122
+ expect(entry.type).toBe("script");
123
+ }
124
+ });
125
+ test("descriptions are truncated to ~80 chars", async () => {
126
+ const stashDir = tmpStash();
127
+ const longDesc = "This is a very long description that goes well beyond eighty characters and should be truncated with an ellipsis indicator to keep the manifest compact and token-efficient";
128
+ await buildTestIndex(stashDir, {
129
+ "skills/verbose/SKILL.md": `---\ndescription: ${longDesc}\n---\n# Verbose Skill`,
130
+ });
131
+ const result = await akmManifest({ stashDir });
132
+ expect(result.entries.length).toBeGreaterThan(0);
133
+ const entry = result.entries.find((e) => e.name === "verbose");
134
+ expect(entry).toBeDefined();
135
+ expect(entry?.description).toBeDefined();
136
+ expect(entry?.description?.length).toBeLessThanOrEqual(83); // 80 + "..."
137
+ expect(entry?.description?.endsWith("...")).toBe(true);
138
+ });
139
+ test("output is compact (token budget) for 50 entries", async () => {
140
+ const stashDir = tmpStash();
141
+ const files = {};
142
+ // Create 50 script files
143
+ for (let i = 0; i < 50; i++) {
144
+ const name = `script-${String(i).padStart(2, "0")}`;
145
+ files[`scripts/${name}/${name}.sh`] = `#!/bin/bash\n# Task number ${i}\necho ${name}`;
146
+ }
147
+ await buildTestIndex(stashDir, files);
148
+ const result = await akmManifest({ stashDir });
149
+ expect(result.entries.length).toBe(50);
150
+ const json = JSON.stringify(result);
151
+ // Compact: each entry averages ~120 bytes (name, type, ref, short description).
152
+ // 50 entries ≈ 6000 bytes ≈ 1500 tokens. Cap at ~2500 bytes per token budget
153
+ // would be too tight for 50 entries, so we allow up to 7500 bytes (~1875 tokens).
154
+ expect(json.length).toBeLessThan(7500);
155
+ // Verify no entry carries heavyweight fields
156
+ for (const entry of result.entries) {
157
+ const raw = entry;
158
+ expect(raw.path).toBeUndefined();
159
+ expect(raw.tags).toBeUndefined();
160
+ expect(raw.score).toBeUndefined();
161
+ expect(raw.action).toBeUndefined();
162
+ }
163
+ });
164
+ test("works without an index (fallback to walker)", async () => {
165
+ const stashDir = tmpStash();
166
+ // Write files but do NOT run akmIndex
167
+ const helloDir = path.join(stashDir, "scripts", "hello");
168
+ fs.mkdirSync(helloDir, { recursive: true });
169
+ fs.writeFileSync(path.join(helloDir, "hello.sh"), "#!/bin/bash\n# Say hello\necho hello");
170
+ process.env.AKM_STASH_DIR = stashDir;
171
+ saveConfig({ semanticSearchMode: "off" });
172
+ const result = await akmManifest({ stashDir });
173
+ // Should find entries via walker fallback even without index
174
+ expect(result.entries.length).toBeGreaterThanOrEqual(1);
175
+ });
176
+ test("response has schemaVersion and entries array", async () => {
177
+ const stashDir = tmpStash();
178
+ await buildTestIndex(stashDir, {
179
+ "scripts/deploy/deploy.sh": "#!/bin/bash\n# Deploy\necho deploy",
180
+ "scripts/lint/lint.sh": "#!/bin/bash\n# Lint\necho lint",
181
+ "scripts/test/test.sh": "#!/bin/bash\n# Test\necho test",
182
+ });
183
+ const result = await akmManifest({ stashDir });
184
+ expect(result.schemaVersion).toBe(1);
185
+ expect(result.entries.length).toBe(3);
186
+ });
187
+ test("empty stash returns empty manifest", async () => {
188
+ const stashDir = tmpStash();
189
+ process.env.AKM_STASH_DIR = stashDir;
190
+ saveConfig({ semanticSearchMode: "off" });
191
+ const result = await akmManifest({ stashDir });
192
+ expect(result.entries).toEqual([]);
193
+ expect(result.schemaVersion).toBe(1);
194
+ });
195
+ test("ref field follows type:name format", async () => {
196
+ const stashDir = tmpStash();
197
+ await buildTestIndex(stashDir, {
198
+ "skills/code-review/SKILL.md": "---\ndescription: Review code quality\n---\n# Code Review",
199
+ });
200
+ const result = await akmManifest({ stashDir });
201
+ const entry = result.entries.find((e) => e.name === "code-review");
202
+ expect(entry).toBeDefined();
203
+ expect(entry?.ref).toMatch(/^skill:code-review$/);
204
+ });
205
+ });
@@ -0,0 +1,126 @@
1
+ import { expect, test } from "bun:test";
2
+ import { extractFrontmatterOnly, extractLineRange, extractSection, formatToc, parseMarkdownToc, } from "../src/core/markdown";
3
+ const SAMPLE_DOC = `---
4
+ title: Guide
5
+ description: "A test guide"
6
+ ---
7
+ # Getting Started
8
+
9
+ Welcome to the guide.
10
+
11
+ ## Installation
12
+
13
+ Run \`npm install\` to get started.
14
+
15
+ ## Configuration
16
+
17
+ Set up your config file.
18
+
19
+ ### Advanced Config
20
+
21
+ For power users.
22
+
23
+ # API Reference
24
+
25
+ The API docs.
26
+
27
+ ## Endpoints
28
+
29
+ List of endpoints.
30
+ `;
31
+ test("parseMarkdownToc extracts headings with correct levels and line numbers", () => {
32
+ const toc = parseMarkdownToc(SAMPLE_DOC);
33
+ expect(toc.headings.length).toBe(6);
34
+ expect(toc.headings[0]).toEqual({ level: 1, text: "Getting Started", line: 5 });
35
+ expect(toc.headings[1]).toEqual({ level: 2, text: "Installation", line: 9 });
36
+ expect(toc.headings[2]).toEqual({ level: 2, text: "Configuration", line: 13 });
37
+ expect(toc.headings[3]).toEqual({ level: 3, text: "Advanced Config", line: 17 });
38
+ expect(toc.headings[4]).toEqual({ level: 1, text: "API Reference", line: 21 });
39
+ expect(toc.headings[5]).toEqual({ level: 2, text: "Endpoints", line: 25 });
40
+ });
41
+ test("parseMarkdownToc skips frontmatter block", () => {
42
+ const doc = "---\ntitle: Test\n---\n# Heading\n";
43
+ const toc = parseMarkdownToc(doc);
44
+ expect(toc.headings.length).toBe(1);
45
+ expect(toc.headings[0].text).toBe("Heading");
46
+ });
47
+ test("parseMarkdownToc handles document without frontmatter", () => {
48
+ const doc = "# Title\n\nSome text\n\n## Section\n";
49
+ const toc = parseMarkdownToc(doc);
50
+ expect(toc.headings.length).toBe(2);
51
+ expect(toc.headings[0]).toEqual({ level: 1, text: "Title", line: 1 });
52
+ expect(toc.headings[1]).toEqual({ level: 2, text: "Section", line: 5 });
53
+ });
54
+ test("parseMarkdownToc handles empty content", () => {
55
+ const toc = parseMarkdownToc("");
56
+ expect(toc.headings).toEqual([]);
57
+ expect(toc.totalLines).toBe(1);
58
+ });
59
+ test("parseMarkdownToc strips trailing hash markers", () => {
60
+ const doc = "# Heading ##\n## Another ###\n";
61
+ const toc = parseMarkdownToc(doc);
62
+ expect(toc.headings[0].text).toBe("Heading");
63
+ expect(toc.headings[1].text).toBe("Another");
64
+ });
65
+ test("extractSection returns content from heading to next same-or-higher level", () => {
66
+ const result = extractSection(SAMPLE_DOC, "Installation");
67
+ expect(result).not.toBeNull();
68
+ expect(result?.content).toContain("npm install");
69
+ expect(result?.content).not.toContain("Configuration");
70
+ });
71
+ test("extractSection returns content including sub-headings", () => {
72
+ const result = extractSection(SAMPLE_DOC, "Configuration");
73
+ expect(result).not.toBeNull();
74
+ expect(result?.content).toContain("Advanced Config");
75
+ expect(result?.content).not.toContain("API Reference");
76
+ });
77
+ test("extractSection is case-insensitive", () => {
78
+ const result = extractSection(SAMPLE_DOC, "installation");
79
+ expect(result).not.toBeNull();
80
+ expect(result?.content).toContain("npm install");
81
+ });
82
+ test("extractSection returns null for non-existent heading", () => {
83
+ const result = extractSection(SAMPLE_DOC, "Nonexistent");
84
+ expect(result).toBeNull();
85
+ });
86
+ test("extractSection handles last section (no following heading)", () => {
87
+ const result = extractSection(SAMPLE_DOC, "Endpoints");
88
+ expect(result).not.toBeNull();
89
+ expect(result?.content).toContain("List of endpoints");
90
+ });
91
+ test("extractLineRange returns correct lines (1-based inclusive)", () => {
92
+ const content = "line1\nline2\nline3\nline4\nline5";
93
+ expect(extractLineRange(content, 2, 4)).toBe("line2\nline3\nline4");
94
+ });
95
+ test("extractLineRange clamps to valid range", () => {
96
+ const content = "line1\nline2\nline3";
97
+ expect(extractLineRange(content, 0, 100)).toBe("line1\nline2\nline3");
98
+ expect(extractLineRange(content, 2, 2)).toBe("line2");
99
+ });
100
+ test("extractLineRange returns empty when end is before start", () => {
101
+ const content = "line1\nline2\nline3\nline4\nline5";
102
+ expect(extractLineRange(content, 5, 2)).toBe("");
103
+ });
104
+ test("extractFrontmatterOnly returns YAML block", () => {
105
+ const fm = extractFrontmatterOnly(SAMPLE_DOC);
106
+ expect(fm).not.toBeNull();
107
+ expect(fm).toContain("title: Guide");
108
+ expect(fm).toContain('description: "A test guide"');
109
+ });
110
+ test("extractFrontmatterOnly returns null when no frontmatter", () => {
111
+ expect(extractFrontmatterOnly("# Just a heading\n")).toBeNull();
112
+ });
113
+ test("formatToc produces readable output with line numbers", () => {
114
+ const toc = parseMarkdownToc(SAMPLE_DOC);
115
+ const output = formatToc(toc);
116
+ expect(output).toContain("# Getting Started");
117
+ expect(output).toContain("## Installation");
118
+ expect(output).toContain("### Advanced Config");
119
+ expect(output).toContain("lines total");
120
+ expect(output).toMatch(/L\s*\d+/);
121
+ });
122
+ test("formatToc handles empty headings", () => {
123
+ const output = formatToc({ headings: [], totalLines: 5 });
124
+ expect(output).toContain("no headings found");
125
+ expect(output).toContain("5 lines total");
126
+ });
@@ -0,0 +1,189 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { directoryMatcher, extensionMatcher, parentDirHintMatcher, smartMdMatcher, wikiMatcher, } from "../src/indexer/matchers";
3
+ /**
4
+ * Build a synthetic FileContext for matcher unit tests. The matchers
5
+ * (except smartMdMatcher) are pure functions of path-derived fields, so
6
+ * the lazy `content`/`frontmatter`/`stat` getters can return canned data
7
+ * — no real filesystem access needed.
8
+ */
9
+ function ctx(opts) {
10
+ const segments = opts.relPath.split("/");
11
+ const fileName = segments[segments.length - 1];
12
+ const ext = (() => {
13
+ const dot = fileName.lastIndexOf(".");
14
+ return dot > 0 ? fileName.slice(dot).toLowerCase() : "";
15
+ })();
16
+ const dirSegments = segments.slice(0, -1);
17
+ const parentDir = dirSegments.length > 0 ? dirSegments[dirSegments.length - 1] : "";
18
+ const parentDirAbs = `/stash/${dirSegments.join("/")}`.replace(/\/+$/, "");
19
+ return {
20
+ absPath: `/stash/${opts.relPath}`,
21
+ relPath: opts.relPath,
22
+ ext,
23
+ fileName,
24
+ parentDir,
25
+ parentDirAbs,
26
+ ancestorDirs: dirSegments,
27
+ stashRoot: "/stash",
28
+ content: () => opts.content ?? "",
29
+ frontmatter: () => opts.frontmatter ?? null,
30
+ stat: () => {
31
+ throw new Error("stat() should not be called by these matchers");
32
+ },
33
+ };
34
+ }
35
+ // ── extensionMatcher ────────────────────────────────────────────────────────
36
+ describe("extensionMatcher", () => {
37
+ test("classifies SKILL.md anywhere as skill at high specificity", () => {
38
+ const result = extensionMatcher(ctx({ relPath: "anywhere/deep/SKILL.md" }));
39
+ expect(result).toEqual({ type: "skill", specificity: 25, renderer: "skill-md" });
40
+ });
41
+ test("does NOT classify SKILL.md under wikis/ as skill", () => {
42
+ const result = extensionMatcher(ctx({ relPath: "wikis/research/SKILL.md" }));
43
+ expect(result).toBeNull();
44
+ });
45
+ test("classifies known script extensions as script at low specificity", () => {
46
+ expect(extensionMatcher(ctx({ relPath: "stuff/deploy.sh" }))?.type).toBe("script");
47
+ expect(extensionMatcher(ctx({ relPath: "stuff/lint.ts" }))?.type).toBe("script");
48
+ expect(extensionMatcher(ctx({ relPath: "stuff/lint.ts" }))?.specificity).toBe(3);
49
+ });
50
+ test("does not handle .md files (smartMdMatcher's job)", () => {
51
+ expect(extensionMatcher(ctx({ relPath: "stuff/notes.md" }))).toBeNull();
52
+ });
53
+ test("returns null for unknown extensions", () => {
54
+ expect(extensionMatcher(ctx({ relPath: "stuff/data.bin" }))).toBeNull();
55
+ });
56
+ });
57
+ // ── directoryMatcher ────────────────────────────────────────────────────────
58
+ describe("directoryMatcher", () => {
59
+ test("scripts/ ancestor classifies a script", () => {
60
+ const result = directoryMatcher(ctx({ relPath: "scripts/azure/deploy.sh" }));
61
+ expect(result).toEqual({ type: "script", specificity: 10, renderer: "script-source" });
62
+ });
63
+ test("first matching ancestor wins (commands/ before agents/ in path)", () => {
64
+ const result = directoryMatcher(ctx({ relPath: "commands/agents/foo.md" }));
65
+ expect(result?.type).toBe("command");
66
+ });
67
+ test("agents/foo.md classifies as agent", () => {
68
+ expect(directoryMatcher(ctx({ relPath: "agents/foo.md" }))?.type).toBe("agent");
69
+ });
70
+ test("knowledge/foo.md classifies as knowledge", () => {
71
+ expect(directoryMatcher(ctx({ relPath: "knowledge/foo.md" }))?.type).toBe("knowledge");
72
+ });
73
+ test("workflows/foo.md classifies as workflow", () => {
74
+ expect(directoryMatcher(ctx({ relPath: "workflows/foo.md" }))?.type).toBe("workflow");
75
+ });
76
+ test("memories/foo.md classifies as memory", () => {
77
+ expect(directoryMatcher(ctx({ relPath: "memories/foo.md" }))?.type).toBe("memory");
78
+ });
79
+ test("vaults/.env classifies as vault", () => {
80
+ expect(directoryMatcher(ctx({ relPath: "vaults/.env" }))?.type).toBe("vault");
81
+ expect(directoryMatcher(ctx({ relPath: "vaults/staging.env" }))?.type).toBe("vault");
82
+ });
83
+ test("unmatched directories return null", () => {
84
+ expect(directoryMatcher(ctx({ relPath: "random/file.md" }))).toBeNull();
85
+ });
86
+ });
87
+ // ── parentDirHintMatcher ────────────────────────────────────────────────────
88
+ describe("parentDirHintMatcher", () => {
89
+ test("immediate parent named scripts/ classifies a script at higher specificity", () => {
90
+ const result = parentDirHintMatcher(ctx({ relPath: "my-project/scripts/run.sh" }));
91
+ expect(result).toEqual({ type: "script", specificity: 15, renderer: "script-source" });
92
+ });
93
+ test("agents parent dir classifies an .md as agent", () => {
94
+ expect(parentDirHintMatcher(ctx({ relPath: "anything/agents/foo.md" }))?.type).toBe("agent");
95
+ });
96
+ test("returns null when parent doesn't match a type", () => {
97
+ expect(parentDirHintMatcher(ctx({ relPath: "random/blah.md" }))).toBeNull();
98
+ });
99
+ });
100
+ // ── smartMdMatcher ─────────────────────────────────────────────────────────
101
+ describe("smartMdMatcher", () => {
102
+ test("returns null for non-.md files", () => {
103
+ expect(smartMdMatcher(ctx({ relPath: "stuff/run.sh", content: "" }))).toBeNull();
104
+ });
105
+ test("workflow signals classify as workflow at specificity 19", () => {
106
+ const body = `# Workflow: Deploy
107
+ ## Step: Validate
108
+ Step ID: validate
109
+
110
+ ### Instructions
111
+ Do the thing.
112
+ `;
113
+ const result = smartMdMatcher(ctx({ relPath: "anywhere.md", content: body }));
114
+ expect(result).toEqual({ type: "workflow", specificity: 19, renderer: "workflow-md" });
115
+ });
116
+ test("toolPolicy frontmatter classifies as agent at 20 (highest)", () => {
117
+ const result = smartMdMatcher(ctx({
118
+ relPath: "blah.md",
119
+ content: "body",
120
+ frontmatter: { toolPolicy: "strict" },
121
+ }));
122
+ expect(result).toEqual({ type: "agent", specificity: 20, renderer: "agent-md" });
123
+ });
124
+ test("tools frontmatter classifies as agent at 20", () => {
125
+ const result = smartMdMatcher(ctx({
126
+ relPath: "blah.md",
127
+ content: "body",
128
+ frontmatter: { tools: ["read"] },
129
+ }));
130
+ expect(result?.type).toBe("agent");
131
+ expect(result?.specificity).toBe(20);
132
+ });
133
+ test("agent-named frontmatter (OpenCode command) classifies as command at 18", () => {
134
+ const result = smartMdMatcher(ctx({
135
+ relPath: "blah.md",
136
+ content: "body",
137
+ frontmatter: { agent: "review" },
138
+ }));
139
+ expect(result).toEqual({ type: "command", specificity: 18, renderer: "command-md" });
140
+ });
141
+ test("$ARGUMENTS placeholder classifies as command at 18", () => {
142
+ const result = smartMdMatcher(ctx({
143
+ relPath: "blah.md",
144
+ content: "Run with $ARGUMENTS",
145
+ }));
146
+ expect(result).toEqual({ type: "command", specificity: 18, renderer: "command-md" });
147
+ });
148
+ test("$1 placeholder classifies as command at 18", () => {
149
+ const result = smartMdMatcher(ctx({
150
+ relPath: "blah.md",
151
+ content: "First arg is $1",
152
+ }));
153
+ expect(result?.type).toBe("command");
154
+ });
155
+ test("model frontmatter alone is a weak agent signal (specificity 8)", () => {
156
+ const result = smartMdMatcher(ctx({
157
+ relPath: "blah.md",
158
+ content: "body",
159
+ frontmatter: { model: "gpt-4o" },
160
+ }));
161
+ expect(result).toEqual({ type: "agent", specificity: 8, renderer: "agent-md" });
162
+ });
163
+ test("plain .md falls back to knowledge at specificity 5", () => {
164
+ const result = smartMdMatcher(ctx({
165
+ relPath: "blah.md",
166
+ content: "Just some prose with no signals.",
167
+ }));
168
+ expect(result).toEqual({ type: "knowledge", specificity: 5, renderer: "knowledge-md" });
169
+ });
170
+ });
171
+ // ── wikiMatcher ─────────────────────────────────────────────────────────────
172
+ describe("wikiMatcher", () => {
173
+ test("any .md under wikis/<name>/ classifies as wiki at specificity 20", () => {
174
+ const result = wikiMatcher(ctx({ relPath: "wikis/research/page.md" }));
175
+ expect(result).toEqual({ type: "wiki", specificity: 20, renderer: "wiki-md" });
176
+ });
177
+ test("nested wiki pages also classify as wiki", () => {
178
+ expect(wikiMatcher(ctx({ relPath: "wikis/research/sub/deep/page.md" }))?.type).toBe("wiki");
179
+ });
180
+ test("non-.md files are ignored", () => {
181
+ expect(wikiMatcher(ctx({ relPath: "wikis/research/page.txt" }))).toBeNull();
182
+ });
183
+ test("a stray .md at bare wikis/ root is NOT a wiki page", () => {
184
+ expect(wikiMatcher(ctx({ relPath: "wikis/orphan.md" }))).toBeNull();
185
+ });
186
+ test("paths without wikis/ are ignored", () => {
187
+ expect(wikiMatcher(ctx({ relPath: "knowledge/page.md" }))).toBeNull();
188
+ });
189
+ });