akm-cli 0.7.0-rc1 → 0.7.1

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 (314) hide show
  1. package/dist/{src/cli.js → cli.js} +100 -16
  2. package/dist/{src/commands → commands}/config-cli.js +42 -0
  3. package/dist/{src/commands → commands}/history.js +78 -7
  4. package/dist/{src/commands → commands}/registry-search.js +69 -6
  5. package/dist/{src/commands → commands}/search.js +30 -3
  6. package/dist/{src/commands → commands}/show.js +29 -0
  7. package/dist/{src/commands → commands}/source-add.js +5 -1
  8. package/dist/{src/commands → commands}/source-manage.js +7 -1
  9. package/dist/{src/core → core}/config.js +28 -0
  10. package/dist/{src/indexer → indexer}/db-search.js +1 -0
  11. package/dist/{src/indexer → indexer}/indexer.js +16 -2
  12. package/dist/{src/indexer → indexer}/matchers.js +1 -1
  13. package/dist/{src/indexer → indexer}/search-source.js +4 -2
  14. package/dist/{src/integrations → integrations}/agent/profiles.js +1 -1
  15. package/dist/{src/integrations → integrations}/agent/spawn.js +67 -16
  16. package/dist/{src/integrations → integrations}/github.js +9 -3
  17. package/dist/{src/llm → llm}/embedders/remote.js +37 -3
  18. package/dist/{src/output → output}/cli-hints.js +15 -2
  19. package/dist/{src/output → output}/renderers.js +3 -1
  20. package/dist/{src/output → output}/shapes.js +8 -1
  21. package/dist/{src/output → output}/text.js +156 -3
  22. package/dist/{src/registry → registry}/build-index.js +5 -4
  23. package/dist/{src/registry → registry}/providers/static-index.js +3 -1
  24. package/dist/{src/setup → setup}/setup.js +9 -0
  25. package/dist/{src/wiki → wiki}/wiki.js +54 -6
  26. package/dist/{src/workflows → workflows}/runs.js +37 -3
  27. package/package.json +8 -8
  28. package/dist/tests/add-website-source.test.js +0 -119
  29. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  30. package/dist/tests/agent/agent-config.test.js +0 -221
  31. package/dist/tests/agent/agent-detect.test.js +0 -100
  32. package/dist/tests/agent/agent-spawn.test.js +0 -234
  33. package/dist/tests/agent-output.test.js +0 -186
  34. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  35. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  36. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  37. package/dist/tests/asset-ref.test.js +0 -192
  38. package/dist/tests/asset-registry.test.js +0 -103
  39. package/dist/tests/asset-spec.test.js +0 -241
  40. package/dist/tests/bench/attribution.test.js +0 -995
  41. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  42. package/dist/tests/bench/cleanup.js +0 -203
  43. package/dist/tests/bench/cleanup.test.js +0 -166
  44. package/dist/tests/bench/cli.js +0 -683
  45. package/dist/tests/bench/cli.test.js +0 -177
  46. package/dist/tests/bench/compare.test.js +0 -556
  47. package/dist/tests/bench/corpus.js +0 -314
  48. package/dist/tests/bench/corpus.test.js +0 -258
  49. package/dist/tests/bench/driver.js +0 -346
  50. package/dist/tests/bench/driver.test.js +0 -443
  51. package/dist/tests/bench/evolve-metrics.js +0 -179
  52. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  53. package/dist/tests/bench/evolve.js +0 -580
  54. package/dist/tests/bench/evolve.test.js +0 -616
  55. package/dist/tests/bench/failure-modes.test.js +0 -300
  56. package/dist/tests/bench/feedback-integrity.test.js +0 -456
  57. package/dist/tests/bench/leakage.test.js +0 -125
  58. package/dist/tests/bench/learning-curve.test.js +0 -133
  59. package/dist/tests/bench/metrics.js +0 -2319
  60. package/dist/tests/bench/metrics.test.js +0 -1144
  61. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  62. package/dist/tests/bench/report.js +0 -1821
  63. package/dist/tests/bench/report.test.js +0 -989
  64. package/dist/tests/bench/runner.js +0 -536
  65. package/dist/tests/bench/runner.test.js +0 -958
  66. package/dist/tests/bench/search-bridge.test.js +0 -331
  67. package/dist/tests/bench/tmp.js +0 -41
  68. package/dist/tests/bench/trajectory.js +0 -116
  69. package/dist/tests/bench/trajectory.test.js +0 -127
  70. package/dist/tests/bench/verifier.js +0 -109
  71. package/dist/tests/bench/verifier.test.js +0 -118
  72. package/dist/tests/bench/workflow-evaluator.js +0 -557
  73. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  74. package/dist/tests/bench/workflow-spec.js +0 -358
  75. package/dist/tests/bench/workflow-spec.test.js +0 -363
  76. package/dist/tests/bench/workflow-trace.js +0 -438
  77. package/dist/tests/bench/workflow-trace.test.js +0 -254
  78. package/dist/tests/benchmark-search-quality.js +0 -536
  79. package/dist/tests/benchmark-suite.js +0 -1441
  80. package/dist/tests/capture-cli.test.js +0 -112
  81. package/dist/tests/cli-errors.test.js +0 -203
  82. package/dist/tests/commands/events.test.js +0 -370
  83. package/dist/tests/commands/history.test.js +0 -223
  84. package/dist/tests/commands/import.test.js +0 -103
  85. package/dist/tests/commands/proposal-cli.test.js +0 -209
  86. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  87. package/dist/tests/commands/remember.test.js +0 -97
  88. package/dist/tests/commands/scope-flags.test.js +0 -300
  89. package/dist/tests/commands/search.test.js +0 -537
  90. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  91. package/dist/tests/commands/show.test.js +0 -294
  92. package/dist/tests/common.test.js +0 -266
  93. package/dist/tests/completions.test.js +0 -142
  94. package/dist/tests/config-cli.test.js +0 -193
  95. package/dist/tests/config-llm-features.test.js +0 -139
  96. package/dist/tests/config.test.js +0 -544
  97. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  98. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  99. package/dist/tests/contracts/spec-helpers.js +0 -46
  100. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  101. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  102. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  103. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  104. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  105. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  106. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  107. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  108. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  109. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  110. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  111. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  112. package/dist/tests/core/write-source.test.js +0 -366
  113. package/dist/tests/curate-command.test.js +0 -87
  114. package/dist/tests/db-scoring.test.js +0 -201
  115. package/dist/tests/db.test.js +0 -654
  116. package/dist/tests/distill-cli-flag.test.js +0 -208
  117. package/dist/tests/distill.test.js +0 -515
  118. package/dist/tests/docker-install.test.js +0 -120
  119. package/dist/tests/e2e.test.js +0 -1398
  120. package/dist/tests/embedder.test.js +0 -340
  121. package/dist/tests/embedding-model-config.test.js +0 -379
  122. package/dist/tests/feedback-command.test.js +0 -172
  123. package/dist/tests/file-context.test.js +0 -552
  124. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  125. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  126. package/dist/tests/fixtures/stashes/load.js +0 -166
  127. package/dist/tests/fixtures/stashes/load.test.js +0 -88
  128. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  129. package/dist/tests/frontmatter.test.js +0 -190
  130. package/dist/tests/fts-field-weighting.test.js +0 -254
  131. package/dist/tests/fuzzy-search.test.js +0 -230
  132. package/dist/tests/git-provider-clone.test.js +0 -45
  133. package/dist/tests/github.test.js +0 -161
  134. package/dist/tests/graph-boost-ranking.test.js +0 -305
  135. package/dist/tests/graph-extraction.test.js +0 -282
  136. package/dist/tests/helpers/usage-events.js +0 -8
  137. package/dist/tests/index-pass-llm.test.js +0 -161
  138. package/dist/tests/indexer.test.js +0 -559
  139. package/dist/tests/info-command.test.js +0 -166
  140. package/dist/tests/init.test.js +0 -69
  141. package/dist/tests/install-script.test.js +0 -246
  142. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  143. package/dist/tests/issue-36-repro.test.js +0 -304
  144. package/dist/tests/issues-191-194.test.js +0 -160
  145. package/dist/tests/lesson-lint.test.js +0 -111
  146. package/dist/tests/llm-client.test.js +0 -115
  147. package/dist/tests/llm-feature-gate.test.js +0 -151
  148. package/dist/tests/llm.test.js +0 -139
  149. package/dist/tests/lockfile.test.js +0 -216
  150. package/dist/tests/manifest.test.js +0 -205
  151. package/dist/tests/markdown.test.js +0 -126
  152. package/dist/tests/matchers-unit.test.js +0 -189
  153. package/dist/tests/memory-inference.test.js +0 -299
  154. package/dist/tests/merge-scoring.test.js +0 -136
  155. package/dist/tests/metadata.test.js +0 -313
  156. package/dist/tests/migration-help.test.js +0 -89
  157. package/dist/tests/origin-resolve.test.js +0 -124
  158. package/dist/tests/output-baseline.test.js +0 -217
  159. package/dist/tests/output-shapes-unit.test.js +0 -476
  160. package/dist/tests/parallel-search.test.js +0 -272
  161. package/dist/tests/parameter-metadata.test.js +0 -365
  162. package/dist/tests/paths.test.js +0 -177
  163. package/dist/tests/progressive-disclosure.test.js +0 -280
  164. package/dist/tests/proposals.test.js +0 -279
  165. package/dist/tests/proposed-quality.test.js +0 -271
  166. package/dist/tests/provider-registry.test.js +0 -32
  167. package/dist/tests/ranking-regression.test.js +0 -548
  168. package/dist/tests/reflect-propose.test.js +0 -455
  169. package/dist/tests/registry-build-index.test.js +0 -378
  170. package/dist/tests/registry-cli.test.js +0 -290
  171. package/dist/tests/registry-index-v2.test.js +0 -430
  172. package/dist/tests/registry-install.test.js +0 -728
  173. package/dist/tests/registry-providers/parity.test.js +0 -189
  174. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  175. package/dist/tests/registry-providers/static-index.test.js +0 -204
  176. package/dist/tests/registry-resolve.test.js +0 -126
  177. package/dist/tests/registry-search.test.js +0 -723
  178. package/dist/tests/remember-frontmatter.test.js +0 -380
  179. package/dist/tests/remember-unit.test.js +0 -123
  180. package/dist/tests/ripgrep-install.test.js +0 -251
  181. package/dist/tests/ripgrep-resolve.test.js +0 -108
  182. package/dist/tests/ripgrep.test.js +0 -163
  183. package/dist/tests/save-command.test.js +0 -94
  184. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  185. package/dist/tests/scoring-pipeline.test.js +0 -648
  186. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  187. package/dist/tests/self-update.test.js +0 -442
  188. package/dist/tests/semantic-search-e2e.test.js +0 -512
  189. package/dist/tests/semantic-status.test.js +0 -471
  190. package/dist/tests/setup-run.integration.js +0 -877
  191. package/dist/tests/setup-wizard.test.js +0 -198
  192. package/dist/tests/setup.test.js +0 -131
  193. package/dist/tests/source-add.test.js +0 -11
  194. package/dist/tests/source-clone.test.js +0 -254
  195. package/dist/tests/source-manage.test.js +0 -366
  196. package/dist/tests/source-providers/filesystem.test.js +0 -82
  197. package/dist/tests/source-providers/git.test.js +0 -252
  198. package/dist/tests/source-providers/website.test.js +0 -128
  199. package/dist/tests/source-qa-fixes.test.js +0 -268
  200. package/dist/tests/source-registry.test.js +0 -350
  201. package/dist/tests/source-resolve.test.js +0 -100
  202. package/dist/tests/source-source.test.js +0 -221
  203. package/dist/tests/source.test.js +0 -533
  204. package/dist/tests/tar-utils-scan.test.js +0 -73
  205. package/dist/tests/toggle-components.test.js +0 -73
  206. package/dist/tests/usage-telemetry.test.js +0 -265
  207. package/dist/tests/utility-scoring.test.js +0 -558
  208. package/dist/tests/vault-load-error.test.js +0 -78
  209. package/dist/tests/vault-qa-fixes.test.js +0 -194
  210. package/dist/tests/vault.test.js +0 -429
  211. package/dist/tests/vector-search.test.js +0 -608
  212. package/dist/tests/walker.test.js +0 -252
  213. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  214. package/dist/tests/wave2-cluster-d.test.js +0 -180
  215. package/dist/tests/wave2-cluster-e.test.js +0 -179
  216. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  217. package/dist/tests/wiki.test.js +0 -529
  218. package/dist/tests/workflow-cli.test.js +0 -271
  219. package/dist/tests/workflow-markdown.test.js +0 -171
  220. package/dist/tests/workflow-path-escape.test.js +0 -132
  221. package/dist/tests/workflow-qa-fixes.test.js +0 -377
  222. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  223. /package/dist/{src/commands → commands}/completions.js +0 -0
  224. /package/dist/{src/commands → commands}/curate.js +0 -0
  225. /package/dist/{src/commands → commands}/distill.js +0 -0
  226. /package/dist/{src/commands → commands}/events.js +0 -0
  227. /package/dist/{src/commands → commands}/info.js +0 -0
  228. /package/dist/{src/commands → commands}/init.js +0 -0
  229. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  230. /package/dist/{src/commands → commands}/installed-stashes.js +0 -0
  231. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  232. /package/dist/{src/commands → commands}/proposal.js +0 -0
  233. /package/dist/{src/commands → commands}/propose.js +0 -0
  234. /package/dist/{src/commands → commands}/reflect.js +0 -0
  235. /package/dist/{src/commands → commands}/remember.js +0 -0
  236. /package/dist/{src/commands → commands}/self-update.js +0 -0
  237. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  238. /package/dist/{src/commands → commands}/vault.js +0 -0
  239. /package/dist/{src/core → core}/asset-ref.js +0 -0
  240. /package/dist/{src/core → core}/asset-registry.js +0 -0
  241. /package/dist/{src/core → core}/asset-spec.js +0 -0
  242. /package/dist/{src/core → core}/common.js +0 -0
  243. /package/dist/{src/core → core}/errors.js +0 -0
  244. /package/dist/{src/core → core}/events.js +0 -0
  245. /package/dist/{src/core → core}/frontmatter.js +0 -0
  246. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  247. /package/dist/{src/core → core}/markdown.js +0 -0
  248. /package/dist/{src/core → core}/paths.js +0 -0
  249. /package/dist/{src/core → core}/proposals.js +0 -0
  250. /package/dist/{src/core → core}/warn.js +0 -0
  251. /package/dist/{src/core → core}/write-source.js +0 -0
  252. /package/dist/{src/indexer → indexer}/db.js +0 -0
  253. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  254. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  255. /package/dist/{src/indexer → indexer}/graph-extraction.js +0 -0
  256. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  257. /package/dist/{src/indexer → indexer}/memory-inference.js +0 -0
  258. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  259. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  260. /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
  261. /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
  262. /package/dist/{src/indexer → indexer}/walker.js +0 -0
  263. /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
  264. /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
  265. /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
  266. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  267. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  268. /package/dist/{src/llm → llm}/client.js +0 -0
  269. /package/dist/{src/llm → llm}/embedder.js +0 -0
  270. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  271. /package/dist/{src/llm → llm}/embedders/local.js +0 -0
  272. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  273. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  274. /package/dist/{src/llm → llm}/graph-extract.js +0 -0
  275. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  276. /package/dist/{src/llm → llm}/memory-infer.js +0 -0
  277. /package/dist/{src/llm → llm}/metadata-enhance.js +0 -0
  278. /package/dist/{src/output → output}/context.js +0 -0
  279. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  280. /package/dist/{src/registry → registry}/factory.js +0 -0
  281. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  282. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  283. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  284. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  285. /package/dist/{src/registry → registry}/resolve.js +0 -0
  286. /package/dist/{src/registry → registry}/types.js +0 -0
  287. /package/dist/{src/setup → setup}/detect.js +0 -0
  288. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  289. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  290. /package/dist/{src/setup → setup}/steps.js +0 -0
  291. /package/dist/{src/sources → sources}/include.js +0 -0
  292. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  293. /package/dist/{src/sources → sources}/provider.js +0 -0
  294. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  295. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  296. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  297. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  298. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  299. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  300. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  301. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  302. /package/dist/{src/sources → sources}/providers/website.js +0 -0
  303. /package/dist/{src/sources → sources}/resolve.js +0 -0
  304. /package/dist/{src/sources → sources}/types.js +0 -0
  305. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  306. /package/dist/{src/version.js → version.js} +0 -0
  307. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  308. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  309. /package/dist/{src/workflows → workflows}/db.js +0 -0
  310. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  311. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  312. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  313. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  314. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,559 +0,0 @@
1
- import { afterEach, beforeEach, expect, mock, spyOn, test } from "bun:test";
2
- import fs from "node:fs";
3
- import os from "node:os";
4
- import path from "node:path";
5
- import { getDbPath } from "../src/core/paths";
6
- import { closeDatabase, DB_VERSION, getAllEntries, getEmbeddingCount, getMeta, openDatabase } from "../src/indexer/db";
7
- import { akmIndex, buildFileBasenameMap, matchEntryToFile } from "../src/indexer/indexer";
8
- import { buildSearchText } from "../src/indexer/search-fields";
9
- import * as embedderModule from "../src/llm/embedder";
10
- let testConfigDir = "";
11
- let testCacheDir = "";
12
- let embedBatchImpl;
13
- const actualEmbedBatch = embedderModule.embedBatch;
14
- const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
15
- const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
16
- mock.module("../src/embedder.js", () => ({
17
- ...embedderModule,
18
- embedBatch: (texts, embeddingConfig) => embedBatchImpl ? embedBatchImpl(texts, embeddingConfig) : actualEmbedBatch(texts, embeddingConfig),
19
- }));
20
- // Each test gets a fresh database and isolated config/cache
21
- beforeEach(() => {
22
- testConfigDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-idx-config-"));
23
- testCacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-idx-cache-"));
24
- process.env.XDG_CONFIG_HOME = testConfigDir;
25
- process.env.XDG_CACHE_HOME = testCacheDir;
26
- embedBatchImpl = undefined;
27
- const dbPath = getDbPath();
28
- for (const f of [dbPath, `${dbPath}-wal`, `${dbPath}-shm`]) {
29
- try {
30
- fs.unlinkSync(f);
31
- }
32
- catch {
33
- /* ignore */
34
- }
35
- }
36
- });
37
- afterEach(() => {
38
- embedBatchImpl = undefined;
39
- if (originalXdgConfigHome === undefined) {
40
- delete process.env.XDG_CONFIG_HOME;
41
- }
42
- else {
43
- process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
44
- }
45
- if (originalXdgCacheHome === undefined) {
46
- delete process.env.XDG_CACHE_HOME;
47
- }
48
- else {
49
- process.env.XDG_CACHE_HOME = originalXdgCacheHome;
50
- }
51
- if (testConfigDir) {
52
- fs.rmSync(testConfigDir, { recursive: true, force: true });
53
- testConfigDir = "";
54
- }
55
- if (testCacheDir) {
56
- fs.rmSync(testCacheDir, { recursive: true, force: true });
57
- testCacheDir = "";
58
- }
59
- });
60
- function tmpStash() {
61
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-idx-"));
62
- for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
63
- fs.mkdirSync(path.join(dir, sub), { recursive: true });
64
- }
65
- return dir;
66
- }
67
- function writeFile(filePath, content = "") {
68
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
69
- fs.writeFileSync(filePath, content);
70
- }
71
- test("akmIndex scans directories and builds index", async () => {
72
- const stashDir = tmpStash();
73
- writeFile(path.join(stashDir, "scripts", "deploy", "deploy.sh"), "#!/usr/bin/env bash\n# Deploy to staging\necho deploy\n");
74
- writeFile(path.join(stashDir, "scripts", "lint", "lint.ts"), "/**\n * Lint source code\n */\nconsole.log('lint')\n");
75
- process.env.AKM_STASH_DIR = stashDir;
76
- const result = await akmIndex({ stashDir });
77
- expect(result.totalEntries).toBe(2);
78
- expect(result.generatedMetadata).toBe(2);
79
- expect(result.stashDir).toBe(stashDir);
80
- // Verify entries are in the database (not in .stash.json files)
81
- const deployStash = path.join(stashDir, "scripts", "deploy", ".stash.json");
82
- expect(fs.existsSync(deployStash)).toBe(false);
83
- const db = openDatabase();
84
- const entries = getAllEntries(db);
85
- expect(entries.length).toBe(2);
86
- const deployEntry = entries.find((e) => e.entry.name.includes("deploy"));
87
- expect(deployEntry).toBeDefined();
88
- expect(deployEntry?.entry.quality).toBe("generated");
89
- closeDatabase(db);
90
- });
91
- test("akmIndex preserves manually-written .stash.json", async () => {
92
- const stashDir = tmpStash();
93
- writeFile(path.join(stashDir, "scripts", "git", "summarize.ts"), "console.log('x')\n");
94
- writeFile(path.join(stashDir, "scripts", "git", ".stash.json"), JSON.stringify({
95
- entries: [
96
- {
97
- name: "git-summarize",
98
- type: "script",
99
- description: "Summarize git changes",
100
- tags: ["git", "summary"],
101
- filename: "summarize.ts",
102
- },
103
- ],
104
- }));
105
- const result = await akmIndex({ stashDir });
106
- expect(result.totalEntries).toBe(1);
107
- expect(result.generatedMetadata).toBe(0); // no generation needed
108
- // Verify the manual .stash.json was not overwritten
109
- const stash = JSON.parse(fs.readFileSync(path.join(stashDir, "scripts", "git", ".stash.json"), "utf8"));
110
- expect(stash.entries[0].name).toBe("git-summarize");
111
- expect(stash.entries[0].quality).toBeUndefined();
112
- });
113
- test("akmIndex writes index to SQLite database", async () => {
114
- const stashDir = tmpStash();
115
- writeFile(path.join(stashDir, "scripts", "hello", "hello.sh"), "#!/bin/bash\necho hi\n");
116
- const result = await akmIndex({ stashDir });
117
- expect(fs.existsSync(result.indexPath)).toBe(true);
118
- expect(result.indexPath).toEndWith(".db");
119
- const db = openDatabase();
120
- const version = getMeta(db, "version");
121
- expect(version).toBe(String(DB_VERSION));
122
- const entries = getAllEntries(db);
123
- expect(entries.length).toBeGreaterThan(0);
124
- closeDatabase(db);
125
- });
126
- test("akmIndex handles empty stash gracefully", async () => {
127
- const stashDir = tmpStash();
128
- const result = await akmIndex({ stashDir });
129
- expect(result.totalEntries).toBe(0);
130
- expect(result.generatedMetadata).toBe(0);
131
- expect(result.verification.ok).toBe(true);
132
- expect(result.verification.message).toContain("No assets");
133
- });
134
- test("akmIndex handles markdown assets", async () => {
135
- const stashDir = tmpStash();
136
- writeFile(path.join(stashDir, "commands", "release.md"), '---\ndescription: "Release the project"\n---\nRun the release\n');
137
- writeFile(path.join(stashDir, "skills", "refactor", "SKILL.md"), '---\ndescription: "Refactor code"\n---\n# Refactor skill\n');
138
- const result = await akmIndex({ stashDir });
139
- expect(result.totalEntries).toBe(2);
140
- });
141
- test("akmIndex includes wiki raw files but excludes infrastructure files from the primary stash index", async () => {
142
- const stashDir = tmpStash();
143
- writeFile(path.join(stashDir, "wikis", "research", "schema.md"), "---\ndescription: Schema\n---\n# Schema\n");
144
- writeFile(path.join(stashDir, "wikis", "research", "index.md"), "---\ndescription: Index\n---\n# Index\n");
145
- writeFile(path.join(stashDir, "wikis", "research", "log.md"), "---\ndescription: Log\n---\n# Log\n");
146
- writeFile(path.join(stashDir, "wikis", "research", "raw", "paper.md"), "---\ndescription: Raw source\n---\n# Paper\n");
147
- writeFile(path.join(stashDir, "wikis", "research", "page.md"), "---\ndescription: Indexed page\n---\n# Page\n");
148
- await akmIndex({ stashDir, full: true });
149
- const db = openDatabase();
150
- const wikiEntries = getAllEntries(db, "wiki")
151
- .map((row) => row.entry.name)
152
- .sort();
153
- expect(wikiEntries).toEqual(["research/page", "research/raw/paper"]);
154
- closeDatabase(db);
155
- });
156
- test("akmIndex includes wiki raw files but excludes infrastructure files for wiki-root stash sources", async () => {
157
- const primaryStash = tmpStash();
158
- const wikiSource = fs.mkdtempSync(path.join(os.tmpdir(), "akm-idx-wiki-source-"));
159
- writeFile(path.join(wikiSource, "schema.md"), "---\ndescription: Schema\n---\n# Schema\n");
160
- writeFile(path.join(wikiSource, "index.md"), "---\ndescription: Index\n---\n# Index\n");
161
- writeFile(path.join(wikiSource, "log.md"), "---\ndescription: Log\n---\n# Log\n");
162
- writeFile(path.join(wikiSource, "raw", "paper.md"), "---\ndescription: Raw source\n---\n# Paper\n");
163
- writeFile(path.join(wikiSource, "page.md"), "---\ndescription: Indexed page\n---\n# Page\n");
164
- writeFile(path.join(wikiSource, "sub", "page-two.md"), "---\ndescription: Indexed page two\n---\n# Page Two\n");
165
- const origStash = process.env.AKM_STASH_DIR;
166
- try {
167
- const { saveConfig } = await import("../src/core/config");
168
- process.env.AKM_STASH_DIR = primaryStash;
169
- saveConfig({
170
- semanticSearchMode: "off",
171
- sources: [{ type: "filesystem", path: wikiSource, wikiName: "research" }],
172
- });
173
- await akmIndex({ stashDir: primaryStash, full: true });
174
- const db = openDatabase();
175
- const wikiEntries = getAllEntries(db, "wiki")
176
- .map((row) => row.entry.name)
177
- .sort();
178
- expect(wikiEntries).toEqual(["research/page", "research/raw/paper", "research/sub/page-two"]);
179
- closeDatabase(db);
180
- }
181
- finally {
182
- if (origStash === undefined)
183
- delete process.env.AKM_STASH_DIR;
184
- else
185
- process.env.AKM_STASH_DIR = origStash;
186
- fs.rmSync(wikiSource, { recursive: true, force: true });
187
- }
188
- });
189
- test("akmIndex skips malformed workflow assets and reports warnings", async () => {
190
- const stashDir = tmpStash();
191
- writeFile(path.join(stashDir, "workflows", "good.md"), [
192
- "---",
193
- "description: Good workflow",
194
- "---",
195
- "",
196
- "# Workflow: Good",
197
- "",
198
- "## Step: First",
199
- "Step ID: first",
200
- "### Instructions",
201
- "Do it.",
202
- "",
203
- ].join("\n"));
204
- // Truly malformed: no `# Workflow:` heading at all. (Intro prose between
205
- // the title and the first step is now permitted — see #158.)
206
- writeFile(path.join(stashDir, "workflows", "bad.md"), [
207
- "---",
208
- "description: Bad workflow",
209
- "---",
210
- "",
211
- "## Step: First",
212
- "Step ID: first",
213
- "### Instructions",
214
- "Do it.",
215
- "",
216
- ].join("\n"));
217
- const result = await akmIndex({ stashDir, full: true });
218
- expect(result.totalEntries).toBe(1);
219
- expect(result.warnings).toBeDefined();
220
- expect(result.warnings?.some((warning) => warning.includes(path.join(stashDir, "workflows", "bad.md")))).toBe(true);
221
- const db = openDatabase();
222
- const workflowEntries = getAllEntries(db, "workflow")
223
- .map((row) => row.entry.name)
224
- .sort();
225
- expect(workflowEntries).toEqual(["good"]);
226
- closeDatabase(db);
227
- });
228
- test("akmIndex generates TOC in database for knowledge entries", async () => {
229
- const stashDir = tmpStash();
230
- writeFile(path.join(stashDir, "knowledge", "guide.md"), '---\ndescription: "A guide"\n---\n# Getting Started\n\nIntro.\n\n## Installation\n\nInstall steps.\n');
231
- const result = await akmIndex({ stashDir });
232
- expect(result.totalEntries).toBe(1);
233
- // TOC is stored in the database, not in .stash.json
234
- expect(fs.existsSync(path.join(stashDir, "knowledge", ".stash.json"))).toBe(false);
235
- const db = openDatabase();
236
- const entries = getAllEntries(db, "knowledge");
237
- expect(entries.length).toBe(1);
238
- expect(entries[0].entry.toc).toBeDefined();
239
- expect(entries[0].entry.toc?.length).toBe(2);
240
- expect(entries[0].entry.toc?.[0].text).toBe("Getting Started");
241
- expect(entries[0].entry.toc?.[1].text).toBe("Installation");
242
- closeDatabase(db);
243
- });
244
- test("isDirStale detects modified source file newer than index", async () => {
245
- const stashDir = tmpStash();
246
- const deployFile = path.join(stashDir, "scripts", "deploy", "deploy.sh");
247
- writeFile(deployFile, "#!/usr/bin/env bash\necho deploy\n");
248
- // First index
249
- const result1 = await akmIndex({ stashDir });
250
- expect(result1.totalEntries).toBe(1);
251
- expect(result1.mode).toBe("full");
252
- // Second index (incremental) — nothing changed, so dir should be skipped
253
- const result2 = await akmIndex({ stashDir });
254
- expect(result2.mode).toBe("incremental");
255
- expect(result2.directoriesSkipped).toBeGreaterThanOrEqual(1);
256
- // Now touch the source file to make it newer than the index
257
- const futureTime = new Date(Date.now() + 2000);
258
- fs.utimesSync(deployFile, futureTime, futureTime);
259
- // Third index (incremental) — should detect stale dir
260
- const result3 = await akmIndex({ stashDir });
261
- expect(result3.mode).toBe("incremental");
262
- expect(result3.directoriesScanned).toBeGreaterThanOrEqual(1);
263
- });
264
- test("akmIndex --full mode returns mode full", async () => {
265
- const stashDir = tmpStash();
266
- writeFile(path.join(stashDir, "scripts", "hello", "hello.sh"), "#!/bin/bash\necho hi\n");
267
- // First index to create a previous index
268
- await akmIndex({ stashDir });
269
- // Second index with full flag — should force full reindex
270
- const result = await akmIndex({ stashDir, full: true });
271
- expect(result.mode).toBe("full");
272
- });
273
- test("akmIndex reports progress events and semantic-search verification details", async () => {
274
- const originalFetch = globalThis.fetch;
275
- globalThis.fetch = (async () => {
276
- throw new Error("TEST_EMBEDDING_ERROR");
277
- });
278
- const warnSpy = spyOn(console, "warn").mockImplementation(() => { });
279
- try {
280
- const stashDir = tmpStash();
281
- writeFile(path.join(stashDir, "scripts", "hello", "hello.sh"), "#!/bin/bash\necho hi\n");
282
- const { saveConfig } = await import("../src/core/config");
283
- process.env.AKM_STASH_DIR = stashDir;
284
- saveConfig({
285
- semanticSearchMode: "auto",
286
- embedding: {
287
- endpoint: "https://example.test/v1/embeddings",
288
- model: "demo-embed",
289
- },
290
- });
291
- const messages = [];
292
- const result = await akmIndex({
293
- stashDir,
294
- onProgress: ({ message }) => {
295
- messages.push(message);
296
- },
297
- });
298
- expect(messages[0]).toContain("Starting full index");
299
- expect(messages[0]).toContain("1 stash source");
300
- expect(messages[0]).toContain("semantic search: remote embeddings");
301
- expect(messages.some((message) => message.includes("Scanned"))).toBe(true);
302
- expect(messages.some((message) => message.includes("Embedding generation failed: TEST_EMBEDDING_ERROR"))).toBe(true);
303
- expect(warnSpy).toHaveBeenCalledWith("Embedding generation failed, continuing without:", "TEST_EMBEDDING_ERROR");
304
- expect(messages.at(-1)).toContain("Semantic search verification failed");
305
- expect(result.verification.ok).toBe(false);
306
- expect(result.verification.semanticSearchMode).toBe("auto");
307
- expect(result.verification.semanticStatus).toBe("blocked");
308
- expect(result.verification.embeddingProvider).toBe("remote");
309
- expect(result.verification.guidance).toContain("akm index --full --verbose");
310
- }
311
- finally {
312
- warnSpy.mockRestore();
313
- globalThis.fetch = originalFetch;
314
- }
315
- });
316
- test("akmIndex verifies semantic search when remote embeddings succeed", async () => {
317
- const stashDir = tmpStash();
318
- writeFile(path.join(stashDir, "scripts", "hello", "hello.sh"), "#!/bin/bash\necho hi\n");
319
- const { saveConfig } = await import("../src/core/config");
320
- process.env.AKM_STASH_DIR = stashDir;
321
- saveConfig({
322
- semanticSearchMode: "auto",
323
- embedding: {
324
- endpoint: "https://example.test/v1/embeddings",
325
- model: "demo-embed",
326
- dimension: 3,
327
- },
328
- });
329
- const originalFetch = globalThis.fetch;
330
- globalThis.fetch = (async (_input, _init) => new Response(JSON.stringify({
331
- data: [{ index: 0, embedding: [0.1, 0.2, 0.3] }],
332
- }), { status: 200 }));
333
- try {
334
- const result = await akmIndex({ stashDir });
335
- expect(result.verification.ok).toBe(true);
336
- expect(result.verification.semanticSearchMode).toBe("auto");
337
- expect(["ready-js", "ready-vec"]).toContain(result.verification.semanticStatus);
338
- expect(result.verification.embeddingCount).toBe(result.totalEntries);
339
- expect(result.verification.message).toContain("Semantic search ready");
340
- }
341
- finally {
342
- globalThis.fetch = originalFetch;
343
- }
344
- });
345
- test("buildSearchText includes TOC heading text for knowledge entries", async () => {
346
- const entry = {
347
- name: "guide",
348
- type: "knowledge",
349
- description: "A guide",
350
- toc: [
351
- { level: 1, text: "Getting Started", line: 4 },
352
- { level: 2, text: "Installation", line: 8 },
353
- ],
354
- };
355
- const text = buildSearchText(entry);
356
- expect(text).toContain("getting started");
357
- expect(text).toContain("installation");
358
- });
359
- test("buildSearchText includes searchHints array content", () => {
360
- const entry = {
361
- name: "git-diff",
362
- type: "script",
363
- description: "summarize git changes",
364
- searchHints: ["explain what changed in a repository", "show commit summary"],
365
- };
366
- const text = buildSearchText(entry);
367
- expect(text).toContain("explain what changed in a repository");
368
- expect(text).toContain("show commit summary");
369
- });
370
- test("buildSearchText includes usage array content", () => {
371
- const entry = {
372
- name: "ci-runner",
373
- type: "script",
374
- description: "run CI pipeline",
375
- usage: ["run in CI", "deploy to production"],
376
- };
377
- const text = buildSearchText(entry);
378
- expect(text).toContain("run in ci");
379
- expect(text).toContain("deploy to production");
380
- });
381
- test("buildSearchText handles entries with both searchHints and intent fields", () => {
382
- const entry = {
383
- name: "deploy",
384
- type: "script",
385
- description: "deploy services",
386
- searchHints: ["deploy to production", "push services live"],
387
- intent: { when: "user needs to deploy", input: "service name", output: "status" },
388
- };
389
- const text = buildSearchText(entry);
390
- expect(text).toContain("deploy to production");
391
- expect(text).toContain("push services live");
392
- expect(text).toContain("user needs to deploy");
393
- expect(text).toContain("service name");
394
- });
395
- test("akmIndex does not generate heuristic searchHints (LLM-only)", async () => {
396
- const stashDir = tmpStash();
397
- writeFile(path.join(stashDir, "scripts", "deploy", "deploy.sh"), "#!/usr/bin/env bash\n# Deploy services to production\necho deploy\n");
398
- await akmIndex({ stashDir });
399
- // Search hints are only generated when LLM is configured
400
- const db = openDatabase();
401
- const entries = getAllEntries(db, "script");
402
- expect(entries.length).toBe(1);
403
- expect(entries[0].entry.searchHints).toBeUndefined();
404
- closeDatabase(db);
405
- });
406
- // ── T2: Incremental indexing with multi-stash-dir deduplication ─────────────
407
- //
408
- // When multiple stash directories contain overlapping paths (e.g. a shared
409
- // directory or symlinked directory appears in two stash sources), the indexer
410
- // should deduplicate using the `seenPaths` set so each directory is only
411
- // indexed once and entries are not duplicated.
412
- test("akmIndex deduplicates overlapping directories across multiple stash dirs", async () => {
413
- // Create a primary stash dir with a script
414
- const primaryStash = tmpStash();
415
- writeFile(path.join(primaryStash, "scripts", "shared", "shared.sh"), "#!/bin/bash\necho shared\n");
416
- // Create a second stash dir that is actually the SAME directory
417
- // (simulates overlapping stashes pointing to the same location)
418
- const secondStash = primaryStash;
419
- // Write a config that includes the same directory twice via stashes
420
- const { saveConfig } = await import("../src/core/config");
421
- process.env.AKM_STASH_DIR = primaryStash;
422
- saveConfig({ semanticSearchMode: "off", sources: [{ type: "filesystem", path: secondStash }] });
423
- const result = await akmIndex({ stashDir: primaryStash });
424
- // The shared script should appear exactly once, not duplicated
425
- const db = openDatabase();
426
- const entries = getAllEntries(db, "script");
427
- const sharedEntries = entries.filter((e) => e.entry.name.includes("shared"));
428
- expect(sharedEntries).toHaveLength(1);
429
- closeDatabase(db);
430
- expect(result.totalEntries).toBeGreaterThanOrEqual(1);
431
- });
432
- test("akmIndex deduplicates when two stash dirs share a common subdirectory", async () => {
433
- // Create a shared directory with content
434
- const sharedDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-idx-shared-"));
435
- for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
436
- fs.mkdirSync(path.join(sharedDir, sub), { recursive: true });
437
- }
438
- writeFile(path.join(sharedDir, "scripts", "utility", "util.sh"), "#!/bin/bash\necho utility\n");
439
- // Create two stash dirs, both pointing to the same shared dir
440
- const stash1 = sharedDir;
441
- const stash2 = sharedDir;
442
- const { saveConfig } = await import("../src/core/config");
443
- process.env.AKM_STASH_DIR = stash1;
444
- saveConfig({ semanticSearchMode: "off", sources: [{ type: "filesystem", path: stash2 }] });
445
- await akmIndex({ stashDir: stash1, full: true });
446
- const db = openDatabase();
447
- const entries = getAllEntries(db);
448
- // Count entries with the utility name — should be exactly 1
449
- const utilEntries = entries.filter((e) => e.entry.name.includes("util"));
450
- expect(utilEntries).toHaveLength(1);
451
- closeDatabase(db);
452
- // Clean up
453
- fs.rmSync(sharedDir, { recursive: true, force: true });
454
- });
455
- // ── Issue #13: matchEntryToFile returns null for empty files ─────────────
456
- test("matchEntryToFile returns null when files array is empty", () => {
457
- const fileMap = buildFileBasenameMap([]);
458
- const result = matchEntryToFile("nonexistent-entry", fileMap, []);
459
- expect(result).toBeNull();
460
- });
461
- test("matchEntryToFile returns first file when no name match exists", () => {
462
- const files = ["/stash/scripts/deploy/deploy.sh"];
463
- const fileMap = buildFileBasenameMap(files);
464
- const result = matchEntryToFile("no-match", fileMap, files);
465
- expect(result).toBe("/stash/scripts/deploy/deploy.sh");
466
- });
467
- test("matchEntryToFile returns exact match when entry name matches basename", () => {
468
- const files = ["/stash/scripts/deploy/deploy.sh", "/stash/scripts/deploy/util.sh"];
469
- const fileMap = buildFileBasenameMap(files);
470
- const result = matchEntryToFile("deploy", fileMap, files);
471
- expect(result).toBe("/stash/scripts/deploy/deploy.sh");
472
- });
473
- test("matchEntryToFile matches last path segment for hierarchical names", () => {
474
- const files = ["/stash/scripts/deploy/deploy.sh"];
475
- const fileMap = buildFileBasenameMap(files);
476
- const result = matchEntryToFile("corpus/deploy", fileMap, files);
477
- expect(result).toBe("/stash/scripts/deploy/deploy.sh");
478
- });
479
- test("usage_events are re-linked after full reindex", async () => {
480
- const stashDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-relink-"));
481
- process.env.AKM_STASH_DIR = stashDir;
482
- // Create a test asset
483
- const scriptDir = path.join(stashDir, "scripts", "deploy");
484
- fs.mkdirSync(scriptDir, { recursive: true });
485
- fs.writeFileSync(path.join(scriptDir, "deploy.sh"), "#!/bin/bash\necho deploy\n");
486
- // First index to populate entries
487
- await akmIndex({ stashDir, full: true });
488
- // Insert a usage event referencing an entry
489
- const dbPath = getDbPath();
490
- const db = openDatabase(dbPath);
491
- const entry = db.prepare("SELECT id, entry_key FROM entries LIMIT 1").get();
492
- expect(entry).toBeTruthy();
493
- // entry_key is "stashDir:type:name", entry_ref is "type:name"
494
- const parts = entry.entry_key.split(":");
495
- const entryRef = parts.slice(1).join(":");
496
- db.prepare("INSERT INTO usage_events (event_type, entry_id, entry_ref, created_at) VALUES (?, ?, ?, datetime('now'))").run("show", entry.id, entryRef);
497
- // Verify event exists with entry_id set
498
- const before = db.prepare("SELECT entry_id, entry_ref FROM usage_events WHERE entry_ref = ?").get(entryRef);
499
- expect(before.entry_id).toBe(entry.id);
500
- closeDatabase(db);
501
- // Full reindex — detaches then re-links usage_events
502
- await akmIndex({ stashDir, full: true });
503
- // Verify event was re-linked to the new entry_id
504
- const db2 = openDatabase(dbPath);
505
- const after = db2.prepare("SELECT entry_id, entry_ref FROM usage_events WHERE entry_ref = ?").get(entryRef);
506
- expect(after.entry_ref).toBe(entryRef);
507
- expect(after.entry_id).not.toBeNull();
508
- closeDatabase(db2);
509
- fs.rmSync(stashDir, { recursive: true, force: true });
510
- });
511
- test("incremental reindex clears embeddings when provider fingerprint changes", async () => {
512
- const stashDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-fp-"));
513
- process.env.AKM_STASH_DIR = stashDir;
514
- embedBatchImpl = async (texts) => texts.map((_text, index) => {
515
- const embedding = new Float32Array(384);
516
- embedding[0] = index + 1;
517
- return embedding;
518
- });
519
- const scriptDir = path.join(stashDir, "scripts", "test");
520
- fs.mkdirSync(scriptDir, { recursive: true });
521
- fs.writeFileSync(path.join(scriptDir, "test.sh"), "#!/bin/bash\necho test\n");
522
- // First index — generates embeddings with default local fingerprint
523
- await akmIndex({ stashDir, full: true });
524
- const dbPath = getDbPath();
525
- const db = openDatabase(dbPath);
526
- const fp1 = getMeta(db, "embeddingFingerprint");
527
- expect(fp1).toContain("local:");
528
- // Verify embeddings were generated during first index
529
- const embeddingsAfterFirst = getEmbeddingCount(db);
530
- expect(embeddingsAfterFirst).toBeGreaterThan(0);
531
- const entryCount = db.prepare("SELECT COUNT(*) as c FROM entries").get();
532
- expect(entryCount.c).toBeGreaterThan(0);
533
- closeDatabase(db);
534
- // Change embedding config to a different provider (simulated via env/config change)
535
- // Re-index with a different embedding fingerprint by passing a config override
536
- // Since we can't easily change the config mid-test, verify the meta key exists
537
- // and that a fingerprint change would trigger a purge by checking the code path.
538
- const db2 = openDatabase(dbPath);
539
- // Manually set a different fingerprint to simulate a provider change
540
- db2
541
- .prepare("INSERT OR REPLACE INTO index_meta (key, value) VALUES (?, ?)")
542
- .run("embeddingFingerprint", "remote:http://localhost:11434/v1/embeddings|nomic-embed-text|768");
543
- closeDatabase(db2);
544
- // Run incremental index — should detect fingerprint mismatch and purge old embeddings
545
- await akmIndex({ stashDir });
546
- const db3 = openDatabase(dbPath);
547
- const fp2 = getMeta(db3, "embeddingFingerprint");
548
- // Fingerprint should be back to local (since we used default config)
549
- expect(fp2).toContain("local:");
550
- expect(fp2).not.toBe("remote:http://localhost:11434/v1/embeddings|nomic-embed-text|768");
551
- // After reindex, embeddings should still exist (purged then regenerated)
552
- const embeddingsAfterReindex = getEmbeddingCount(db3);
553
- expect(embeddingsAfterReindex).toBeGreaterThan(0);
554
- // hasEmbeddings meta should be "1" after reindex
555
- const hasEmbeddings = getMeta(db3, "hasEmbeddings");
556
- expect(hasEmbeddings).toBe("1");
557
- closeDatabase(db3);
558
- fs.rmSync(stashDir, { recursive: true, force: true });
559
- });