akm-cli 0.7.0 → 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 (327) hide show
  1. package/package.json +8 -8
  2. package/dist/tests/add-website-source.test.js +0 -119
  3. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  4. package/dist/tests/agent/agent-config.test.js +0 -221
  5. package/dist/tests/agent/agent-detect.test.js +0 -100
  6. package/dist/tests/agent/agent-spawn.test.js +0 -234
  7. package/dist/tests/agent-output.test.js +0 -186
  8. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  9. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  10. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  11. package/dist/tests/asset-ref.test.js +0 -192
  12. package/dist/tests/asset-registry.test.js +0 -103
  13. package/dist/tests/asset-spec.test.js +0 -241
  14. package/dist/tests/bench/attribution.test.js +0 -996
  15. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  16. package/dist/tests/bench/cleanup.js +0 -234
  17. package/dist/tests/bench/cleanup.test.js +0 -166
  18. package/dist/tests/bench/cli.js +0 -1018
  19. package/dist/tests/bench/cli.test.js +0 -445
  20. package/dist/tests/bench/compare.test.js +0 -556
  21. package/dist/tests/bench/corpus.js +0 -317
  22. package/dist/tests/bench/corpus.test.js +0 -258
  23. package/dist/tests/bench/doctor.js +0 -525
  24. package/dist/tests/bench/driver.js +0 -401
  25. package/dist/tests/bench/driver.test.js +0 -584
  26. package/dist/tests/bench/environment.js +0 -233
  27. package/dist/tests/bench/environment.test.js +0 -199
  28. package/dist/tests/bench/evolve-metrics.js +0 -179
  29. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  30. package/dist/tests/bench/evolve.js +0 -647
  31. package/dist/tests/bench/evolve.test.js +0 -624
  32. package/dist/tests/bench/failure-modes.test.js +0 -349
  33. package/dist/tests/bench/feedback-integrity.test.js +0 -457
  34. package/dist/tests/bench/leakage.test.js +0 -228
  35. package/dist/tests/bench/learning-curve.test.js +0 -134
  36. package/dist/tests/bench/metrics.js +0 -2395
  37. package/dist/tests/bench/metrics.test.js +0 -1150
  38. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  39. package/dist/tests/bench/opencode-config.js +0 -194
  40. package/dist/tests/bench/opencode-config.test.js +0 -370
  41. package/dist/tests/bench/report.js +0 -1885
  42. package/dist/tests/bench/report.test.js +0 -1038
  43. package/dist/tests/bench/run-config.js +0 -355
  44. package/dist/tests/bench/run-config.test.js +0 -298
  45. package/dist/tests/bench/run-curate-test.js +0 -32
  46. package/dist/tests/bench/run-failing-tasks.js +0 -56
  47. package/dist/tests/bench/run-full-bench.js +0 -51
  48. package/dist/tests/bench/run-items36-targeted.js +0 -69
  49. package/dist/tests/bench/run-nano-quick.js +0 -42
  50. package/dist/tests/bench/run-waveg-targeted.js +0 -62
  51. package/dist/tests/bench/runner.js +0 -699
  52. package/dist/tests/bench/runner.test.js +0 -958
  53. package/dist/tests/bench/search-bridge.test.js +0 -331
  54. package/dist/tests/bench/tmp.js +0 -131
  55. package/dist/tests/bench/trajectory.js +0 -116
  56. package/dist/tests/bench/trajectory.test.js +0 -127
  57. package/dist/tests/bench/verifier.js +0 -114
  58. package/dist/tests/bench/verifier.test.js +0 -118
  59. package/dist/tests/bench/workflow-evaluator.js +0 -557
  60. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  61. package/dist/tests/bench/workflow-spec.js +0 -345
  62. package/dist/tests/bench/workflow-spec.test.js +0 -363
  63. package/dist/tests/bench/workflow-trace.js +0 -472
  64. package/dist/tests/bench/workflow-trace.test.js +0 -254
  65. package/dist/tests/benchmark-search-quality.js +0 -536
  66. package/dist/tests/benchmark-suite.js +0 -1441
  67. package/dist/tests/capture-cli.test.js +0 -112
  68. package/dist/tests/cli-errors.test.js +0 -204
  69. package/dist/tests/commands/events.test.js +0 -370
  70. package/dist/tests/commands/history.test.js +0 -418
  71. package/dist/tests/commands/import.test.js +0 -103
  72. package/dist/tests/commands/proposal-cli.test.js +0 -209
  73. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  74. package/dist/tests/commands/remember.test.js +0 -97
  75. package/dist/tests/commands/scope-flags.test.js +0 -300
  76. package/dist/tests/commands/search.test.js +0 -537
  77. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  78. package/dist/tests/commands/show.test.js +0 -294
  79. package/dist/tests/common.test.js +0 -266
  80. package/dist/tests/completions.test.js +0 -142
  81. package/dist/tests/config-cli.test.js +0 -193
  82. package/dist/tests/config-llm-features.test.js +0 -139
  83. package/dist/tests/config.test.js +0 -569
  84. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  85. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  86. package/dist/tests/contracts/spec-helpers.js +0 -46
  87. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  88. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  89. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  90. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  91. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  92. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  93. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  94. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  95. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  96. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  97. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  98. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  99. package/dist/tests/core/write-source.test.js +0 -366
  100. package/dist/tests/curate-command.test.js +0 -87
  101. package/dist/tests/db-scoring.test.js +0 -201
  102. package/dist/tests/db.test.js +0 -654
  103. package/dist/tests/distill-cli-flag.test.js +0 -208
  104. package/dist/tests/distill.test.js +0 -515
  105. package/dist/tests/docker-install.test.js +0 -120
  106. package/dist/tests/e2e.test.js +0 -1419
  107. package/dist/tests/embedder.test.js +0 -340
  108. package/dist/tests/embedding-model-config.test.js +0 -379
  109. package/dist/tests/feedback-command.test.js +0 -172
  110. package/dist/tests/file-context.test.js +0 -552
  111. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  112. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  113. package/dist/tests/fixtures/stashes/load.js +0 -166
  114. package/dist/tests/fixtures/stashes/load.test.js +0 -97
  115. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  116. package/dist/tests/frontmatter.test.js +0 -190
  117. package/dist/tests/fts-field-weighting.test.js +0 -254
  118. package/dist/tests/fuzzy-search.test.js +0 -230
  119. package/dist/tests/git-provider-clone.test.js +0 -45
  120. package/dist/tests/github.test.js +0 -161
  121. package/dist/tests/graph-boost-ranking.test.js +0 -305
  122. package/dist/tests/graph-extraction.test.js +0 -282
  123. package/dist/tests/helpers/usage-events.js +0 -8
  124. package/dist/tests/index-pass-llm.test.js +0 -161
  125. package/dist/tests/indexer.test.js +0 -570
  126. package/dist/tests/info-command.test.js +0 -166
  127. package/dist/tests/init.test.js +0 -69
  128. package/dist/tests/install-script.test.js +0 -246
  129. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  130. package/dist/tests/issue-36-repro.test.js +0 -304
  131. package/dist/tests/issues-191-194.test.js +0 -160
  132. package/dist/tests/lesson-lint.test.js +0 -111
  133. package/dist/tests/llm-client.test.js +0 -115
  134. package/dist/tests/llm-feature-gate.test.js +0 -151
  135. package/dist/tests/llm.test.js +0 -139
  136. package/dist/tests/lockfile.test.js +0 -216
  137. package/dist/tests/manifest.test.js +0 -205
  138. package/dist/tests/markdown.test.js +0 -126
  139. package/dist/tests/matchers-unit.test.js +0 -189
  140. package/dist/tests/memory-inference.test.js +0 -299
  141. package/dist/tests/merge-scoring.test.js +0 -136
  142. package/dist/tests/metadata.test.js +0 -313
  143. package/dist/tests/migration-help.test.js +0 -89
  144. package/dist/tests/origin-resolve.test.js +0 -124
  145. package/dist/tests/output-baseline.test.js +0 -218
  146. package/dist/tests/output-shapes-unit.test.js +0 -478
  147. package/dist/tests/parallel-search.test.js +0 -272
  148. package/dist/tests/parameter-metadata.test.js +0 -365
  149. package/dist/tests/paths.test.js +0 -177
  150. package/dist/tests/progressive-disclosure.test.js +0 -280
  151. package/dist/tests/proposals.test.js +0 -279
  152. package/dist/tests/proposed-quality.test.js +0 -271
  153. package/dist/tests/provider-registry.test.js +0 -32
  154. package/dist/tests/ranking-regression.test.js +0 -548
  155. package/dist/tests/reflect-propose.test.js +0 -455
  156. package/dist/tests/registry-build-index.test.js +0 -394
  157. package/dist/tests/registry-cli.test.js +0 -290
  158. package/dist/tests/registry-index-v2.test.js +0 -430
  159. package/dist/tests/registry-install.test.js +0 -728
  160. package/dist/tests/registry-providers/parity.test.js +0 -189
  161. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  162. package/dist/tests/registry-providers/static-index.test.js +0 -238
  163. package/dist/tests/registry-resolve.test.js +0 -126
  164. package/dist/tests/registry-search.test.js +0 -923
  165. package/dist/tests/remember-frontmatter.test.js +0 -378
  166. package/dist/tests/remember-unit.test.js +0 -123
  167. package/dist/tests/ripgrep-install.test.js +0 -251
  168. package/dist/tests/ripgrep-resolve.test.js +0 -108
  169. package/dist/tests/ripgrep.test.js +0 -163
  170. package/dist/tests/save-command.test.js +0 -94
  171. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  172. package/dist/tests/scoring-pipeline.test.js +0 -648
  173. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  174. package/dist/tests/self-update.test.js +0 -442
  175. package/dist/tests/semantic-search-e2e.test.js +0 -512
  176. package/dist/tests/semantic-status.test.js +0 -471
  177. package/dist/tests/setup-run.integration.js +0 -877
  178. package/dist/tests/setup-wizard.test.js +0 -198
  179. package/dist/tests/setup.test.js +0 -131
  180. package/dist/tests/source-add.test.js +0 -11
  181. package/dist/tests/source-clone.test.js +0 -254
  182. package/dist/tests/source-manage.test.js +0 -366
  183. package/dist/tests/source-providers/filesystem.test.js +0 -82
  184. package/dist/tests/source-providers/git.test.js +0 -252
  185. package/dist/tests/source-providers/website.test.js +0 -128
  186. package/dist/tests/source-qa-fixes.test.js +0 -286
  187. package/dist/tests/source-registry.test.js +0 -350
  188. package/dist/tests/source-resolve.test.js +0 -100
  189. package/dist/tests/source-source.test.js +0 -281
  190. package/dist/tests/source.test.js +0 -533
  191. package/dist/tests/tar-utils-scan.test.js +0 -73
  192. package/dist/tests/toggle-components.test.js +0 -73
  193. package/dist/tests/usage-telemetry.test.js +0 -265
  194. package/dist/tests/utility-scoring.test.js +0 -558
  195. package/dist/tests/vault-load-error.test.js +0 -78
  196. package/dist/tests/vault-qa-fixes.test.js +0 -194
  197. package/dist/tests/vault.test.js +0 -429
  198. package/dist/tests/vector-search.test.js +0 -608
  199. package/dist/tests/walker.test.js +0 -252
  200. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  201. package/dist/tests/wave2-cluster-d.test.js +0 -180
  202. package/dist/tests/wave2-cluster-e.test.js +0 -179
  203. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  204. package/dist/tests/wiki.test.js +0 -529
  205. package/dist/tests/workflow-cli.test.js +0 -271
  206. package/dist/tests/workflow-markdown.test.js +0 -171
  207. package/dist/tests/workflow-path-escape.test.js +0 -132
  208. package/dist/tests/workflow-qa-fixes.test.js +0 -395
  209. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  210. /package/dist/{src/cli.js → cli.js} +0 -0
  211. /package/dist/{src/commands → commands}/completions.js +0 -0
  212. /package/dist/{src/commands → commands}/config-cli.js +0 -0
  213. /package/dist/{src/commands → commands}/curate.js +0 -0
  214. /package/dist/{src/commands → commands}/distill.js +0 -0
  215. /package/dist/{src/commands → commands}/events.js +0 -0
  216. /package/dist/{src/commands → commands}/history.js +0 -0
  217. /package/dist/{src/commands → commands}/info.js +0 -0
  218. /package/dist/{src/commands → commands}/init.js +0 -0
  219. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  220. /package/dist/{src/commands → commands}/installed-stashes.js +0 -0
  221. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  222. /package/dist/{src/commands → commands}/proposal.js +0 -0
  223. /package/dist/{src/commands → commands}/propose.js +0 -0
  224. /package/dist/{src/commands → commands}/reflect.js +0 -0
  225. /package/dist/{src/commands → commands}/registry-search.js +0 -0
  226. /package/dist/{src/commands → commands}/remember.js +0 -0
  227. /package/dist/{src/commands → commands}/search.js +0 -0
  228. /package/dist/{src/commands → commands}/self-update.js +0 -0
  229. /package/dist/{src/commands → commands}/show.js +0 -0
  230. /package/dist/{src/commands → commands}/source-add.js +0 -0
  231. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  232. /package/dist/{src/commands → commands}/source-manage.js +0 -0
  233. /package/dist/{src/commands → commands}/vault.js +0 -0
  234. /package/dist/{src/core → core}/asset-ref.js +0 -0
  235. /package/dist/{src/core → core}/asset-registry.js +0 -0
  236. /package/dist/{src/core → core}/asset-spec.js +0 -0
  237. /package/dist/{src/core → core}/common.js +0 -0
  238. /package/dist/{src/core → core}/config.js +0 -0
  239. /package/dist/{src/core → core}/errors.js +0 -0
  240. /package/dist/{src/core → core}/events.js +0 -0
  241. /package/dist/{src/core → core}/frontmatter.js +0 -0
  242. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  243. /package/dist/{src/core → core}/markdown.js +0 -0
  244. /package/dist/{src/core → core}/paths.js +0 -0
  245. /package/dist/{src/core → core}/proposals.js +0 -0
  246. /package/dist/{src/core → core}/warn.js +0 -0
  247. /package/dist/{src/core → core}/write-source.js +0 -0
  248. /package/dist/{src/indexer → indexer}/db-search.js +0 -0
  249. /package/dist/{src/indexer → indexer}/db.js +0 -0
  250. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  251. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  252. /package/dist/{src/indexer → indexer}/graph-extraction.js +0 -0
  253. /package/dist/{src/indexer → indexer}/indexer.js +0 -0
  254. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  255. /package/dist/{src/indexer → indexer}/matchers.js +0 -0
  256. /package/dist/{src/indexer → indexer}/memory-inference.js +0 -0
  257. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  258. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  259. /package/dist/{src/indexer → indexer}/search-source.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/profiles.js +0 -0
  267. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  268. /package/dist/{src/integrations → integrations}/agent/spawn.js +0 -0
  269. /package/dist/{src/integrations → integrations}/github.js +0 -0
  270. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  271. /package/dist/{src/llm → llm}/client.js +0 -0
  272. /package/dist/{src/llm → llm}/embedder.js +0 -0
  273. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  274. /package/dist/{src/llm → llm}/embedders/local.js +0 -0
  275. /package/dist/{src/llm → llm}/embedders/remote.js +0 -0
  276. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  277. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  278. /package/dist/{src/llm → llm}/graph-extract.js +0 -0
  279. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  280. /package/dist/{src/llm → llm}/memory-infer.js +0 -0
  281. /package/dist/{src/llm → llm}/metadata-enhance.js +0 -0
  282. /package/dist/{src/output → output}/cli-hints.js +0 -0
  283. /package/dist/{src/output → output}/context.js +0 -0
  284. /package/dist/{src/output → output}/renderers.js +0 -0
  285. /package/dist/{src/output → output}/shapes.js +0 -0
  286. /package/dist/{src/output → output}/text.js +0 -0
  287. /package/dist/{src/registry → registry}/build-index.js +0 -0
  288. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  289. /package/dist/{src/registry → registry}/factory.js +0 -0
  290. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  291. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  292. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  293. /package/dist/{src/registry → registry}/providers/static-index.js +0 -0
  294. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  295. /package/dist/{src/registry → registry}/resolve.js +0 -0
  296. /package/dist/{src/registry → registry}/types.js +0 -0
  297. /package/dist/{src/setup → setup}/detect.js +0 -0
  298. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  299. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  300. /package/dist/{src/setup → setup}/setup.js +0 -0
  301. /package/dist/{src/setup → setup}/steps.js +0 -0
  302. /package/dist/{src/sources → sources}/include.js +0 -0
  303. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  304. /package/dist/{src/sources → sources}/provider.js +0 -0
  305. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  306. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  307. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  308. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  309. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  310. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  311. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  312. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  313. /package/dist/{src/sources → sources}/providers/website.js +0 -0
  314. /package/dist/{src/sources → sources}/resolve.js +0 -0
  315. /package/dist/{src/sources → sources}/types.js +0 -0
  316. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  317. /package/dist/{src/version.js → version.js} +0 -0
  318. /package/dist/{src/wiki → wiki}/wiki.js +0 -0
  319. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  320. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  321. /package/dist/{src/workflows → workflows}/db.js +0 -0
  322. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  323. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  324. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  325. /package/dist/{src/workflows → workflows}/runs.js +0 -0
  326. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  327. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,299 +0,0 @@
1
- /**
2
- * Tests for the memory-inference pass (#201).
3
- *
4
- * The LLM client is never called for real — `splitMemoryIntoAtomicFacts` is
5
- * mocked via `mock.module` to return deterministic atomic-fact splits. These
6
- * tests cover:
7
- * - pending detection (parent vs already-inferred vs already-processed)
8
- * - the disabled-by-default path (no `akm.llm` configured)
9
- * - the `index.memory.llm = false` opt-out
10
- * - children written with `inferred: true` + `source:` backref
11
- * - re-running the pass is idempotent (no duplicate children, parent stays
12
- * processed, inferred children are not deleted when toggled off)
13
- */
14
- import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
15
- import fs from "node:fs";
16
- import os from "node:os";
17
- import path from "node:path";
18
- import { parseFrontmatter } from "../src/core/frontmatter";
19
- // ── Module-level LLM stub ───────────────────────────────────────────────────
20
- //
21
- // `mock.module` must run before the module under test is imported, so we set
22
- // up the stub here at the top of the file. The behaviour is controlled by
23
- // the mutable `splitter` variable — each test sets it to whatever
24
- // deterministic split it wants.
25
- let splitter = () => [];
26
- mock.module("../src/llm/memory-infer", () => ({
27
- splitMemoryIntoAtomicFacts: async (_config, body) => splitter(body),
28
- }));
29
- // Import AFTER mock.module so the pass picks up the stub.
30
- const { runMemoryInferencePass, isPendingMemory, collectPendingMemories } = await import("../src/indexer/memory-inference");
31
- // ── Test fixtures ───────────────────────────────────────────────────────────
32
- let tmpStash = "";
33
- beforeEach(() => {
34
- tmpStash = fs.mkdtempSync(path.join(os.tmpdir(), "akm-memory-infer-"));
35
- fs.mkdirSync(path.join(tmpStash, "memories"), { recursive: true });
36
- splitter = () => [];
37
- });
38
- afterEach(() => {
39
- if (tmpStash) {
40
- fs.rmSync(tmpStash, { recursive: true, force: true });
41
- tmpStash = "";
42
- }
43
- });
44
- function writeMemory(name, frontmatter, body) {
45
- const fmLines = ["---"];
46
- for (const [key, value] of Object.entries(frontmatter)) {
47
- fmLines.push(`${key}: ${typeof value === "string" ? value : JSON.stringify(value)}`);
48
- }
49
- fmLines.push("---");
50
- const content = `${fmLines.join("\n")}\n\n${body}\n`;
51
- const filePath = path.join(tmpStash, "memories", `${name}.md`);
52
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
53
- fs.writeFileSync(filePath, content, "utf8");
54
- return filePath;
55
- }
56
- const SAMPLE_LLM = {
57
- endpoint: "http://localhost:11434/v1/chat/completions",
58
- model: "llama3.2",
59
- };
60
- function configWithLlm() {
61
- return {
62
- semanticSearchMode: "auto",
63
- llm: { ...SAMPLE_LLM },
64
- };
65
- }
66
- function configOptedOut() {
67
- return {
68
- semanticSearchMode: "auto",
69
- llm: { ...SAMPLE_LLM },
70
- index: { memory: { llm: false } },
71
- };
72
- }
73
- function sources() {
74
- return [{ path: tmpStash }];
75
- }
76
- // ── isPendingMemory predicate ───────────────────────────────────────────────
77
- describe("isPendingMemory", () => {
78
- test("plain memory with no inference markers is pending", () => {
79
- expect(isPendingMemory({ description: "anything" })).toBe(true);
80
- });
81
- test("inferred children are not pending", () => {
82
- expect(isPendingMemory({ inferred: true, source: "memory:parent" })).toBe(false);
83
- });
84
- test("memory already marked processed is not pending", () => {
85
- expect(isPendingMemory({ inferenceProcessed: true })).toBe(false);
86
- });
87
- test("inference markers must be literal `true` — non-boolean is treated as not-set", () => {
88
- expect(isPendingMemory({ inferred: "yes" })).toBe(true);
89
- expect(isPendingMemory({ inferenceProcessed: 1 })).toBe(true);
90
- });
91
- });
92
- // ── collectPendingMemories ──────────────────────────────────────────────────
93
- describe("collectPendingMemories", () => {
94
- test("returns empty when memories/ does not exist", () => {
95
- const fresh = fs.mkdtempSync(path.join(os.tmpdir(), "akm-mi-empty-"));
96
- try {
97
- expect(collectPendingMemories(fresh)).toEqual([]);
98
- }
99
- finally {
100
- fs.rmSync(fresh, { recursive: true, force: true });
101
- }
102
- });
103
- test("walks markdown files and filters by predicate", () => {
104
- writeMemory("plain", {}, "Plain body, needs splitting.");
105
- writeMemory("already-inferred", { inferred: true, source: "memory:plain" }, "Atomic.");
106
- writeMemory("already-processed", { inferenceProcessed: true }, "Already split.");
107
- writeMemory("nested/sub", {}, "Nested memory body.");
108
- // A non-markdown file under memories/ must be ignored.
109
- fs.writeFileSync(path.join(tmpStash, "memories", "notes.txt"), "ignore me");
110
- const pending = collectPendingMemories(tmpStash);
111
- const names = pending.map((p) => p.ref).sort();
112
- expect(names).toEqual(["memory:nested/sub", "memory:plain"]);
113
- });
114
- });
115
- // ── runMemoryInferencePass — disabled paths ─────────────────────────────────
116
- describe("runMemoryInferencePass — disabled by default", () => {
117
- test("returns no-op when no akm.llm is configured", async () => {
118
- writeMemory("plain", {}, "Plain body, needs splitting.");
119
- splitter = () => ["should not be called"];
120
- const result = await runMemoryInferencePass({ semanticSearchMode: "auto" }, sources());
121
- expect(result).toEqual({ considered: 0, splitParents: 0, writtenFacts: 0, skippedNoFacts: 0 });
122
- });
123
- test("returns no-op when index.memory.llm = false", async () => {
124
- const filePath = writeMemory("plain", {}, "Plain body, needs splitting.");
125
- splitter = () => ["should not be called"];
126
- const result = await runMemoryInferencePass(configOptedOut(), sources());
127
- expect(result.writtenFacts).toBe(0);
128
- // Existing inferred children are NOT deleted — but here we just confirm
129
- // the parent file is unchanged, since the toggle should not mutate state.
130
- const fm = parseFrontmatter(fs.readFileSync(filePath, "utf8"));
131
- expect(fm.data.inferenceProcessed).toBeUndefined();
132
- });
133
- test("toggling off after a previous run leaves existing inferred children intact", async () => {
134
- // First run: enabled. Splits one parent into two facts.
135
- writeMemory("parent", {}, "Body.");
136
- splitter = () => ["fact 1", "fact 2"];
137
- await runMemoryInferencePass(configWithLlm(), sources());
138
- const factsDir = path.join(tmpStash, "memories", "parent.facts");
139
- expect(fs.existsSync(path.join(factsDir, "fact-1.md"))).toBe(true);
140
- expect(fs.existsSync(path.join(factsDir, "fact-2.md"))).toBe(true);
141
- // Second run: disabled. Children must remain on disk.
142
- splitter = () => {
143
- throw new Error("must not be called when disabled");
144
- };
145
- await runMemoryInferencePass(configOptedOut(), sources());
146
- expect(fs.existsSync(path.join(factsDir, "fact-1.md"))).toBe(true);
147
- expect(fs.existsSync(path.join(factsDir, "fact-2.md"))).toBe(true);
148
- });
149
- });
150
- // ── runMemoryInferencePass — orthogonal gating (§14 + #208) ─────────────────
151
- describe("runMemoryInferencePass — feature flag and per-pass key are orthogonal", () => {
152
- test("runs when both gates allow (feature on, per-pass on)", async () => {
153
- writeMemory("parent", {}, "Body.");
154
- splitter = () => ["fact 1"];
155
- const cfg = {
156
- semanticSearchMode: "auto",
157
- llm: { ...SAMPLE_LLM, features: { memory_inference: true } },
158
- // index.memory.llm omitted → defaults to enabled.
159
- };
160
- const result = await runMemoryInferencePass(cfg, sources());
161
- expect(result.writtenFacts).toBe(1);
162
- expect(result.splitParents).toBe(1);
163
- });
164
- test("skipped when llm.features.memory_inference = false even with index.memory.llm enabled", async () => {
165
- const filePath = writeMemory("parent", {}, "Body.");
166
- let invocations = 0;
167
- splitter = () => {
168
- invocations += 1;
169
- return ["should never be called"];
170
- };
171
- const cfg = {
172
- semanticSearchMode: "auto",
173
- llm: { ...SAMPLE_LLM, features: { memory_inference: false } },
174
- index: { memory: { llm: true } },
175
- };
176
- const result = await runMemoryInferencePass(cfg, sources());
177
- expect(result).toEqual({ considered: 0, splitParents: 0, writtenFacts: 0, skippedNoFacts: 0 });
178
- expect(invocations).toBe(0);
179
- // Parent is not mutated when the feature gate blocks.
180
- const fm = parseFrontmatter(fs.readFileSync(filePath, "utf8"));
181
- expect(fm.data.inferenceProcessed).toBeUndefined();
182
- });
183
- test("skipped when index.memory.llm = false even with llm.features.memory_inference = true", async () => {
184
- const filePath = writeMemory("parent", {}, "Body.");
185
- let invocations = 0;
186
- splitter = () => {
187
- invocations += 1;
188
- return ["should never be called"];
189
- };
190
- const cfg = {
191
- semanticSearchMode: "auto",
192
- llm: { ...SAMPLE_LLM, features: { memory_inference: true } },
193
- index: { memory: { llm: false } },
194
- };
195
- const result = await runMemoryInferencePass(cfg, sources());
196
- expect(result.writtenFacts).toBe(0);
197
- expect(invocations).toBe(0);
198
- const fm = parseFrontmatter(fs.readFileSync(filePath, "utf8"));
199
- expect(fm.data.inferenceProcessed).toBeUndefined();
200
- });
201
- });
202
- // ── runMemoryInferencePass — enabled path ───────────────────────────────────
203
- describe("runMemoryInferencePass — enabled", () => {
204
- test("writes atomic children with `inferred: true` and `source:` backref", async () => {
205
- writeMemory("parent", { description: "before" }, "Two facts in one body.");
206
- splitter = () => ["First atomic fact.", "Second atomic fact."];
207
- const result = await runMemoryInferencePass(configWithLlm(), sources());
208
- expect(result).toEqual({
209
- considered: 1,
210
- splitParents: 1,
211
- writtenFacts: 2,
212
- skippedNoFacts: 0,
213
- });
214
- const factsDir = path.join(tmpStash, "memories", "parent.facts");
215
- const child1 = parseFrontmatter(fs.readFileSync(path.join(factsDir, "fact-1.md"), "utf8"));
216
- expect(child1.data.inferred).toBe(true);
217
- expect(child1.data.source).toBe("memory:parent");
218
- expect(child1.content.trim()).toBe("First atomic fact.");
219
- const child2 = parseFrontmatter(fs.readFileSync(path.join(factsDir, "fact-2.md"), "utf8"));
220
- expect(child2.data.inferred).toBe(true);
221
- expect(child2.data.source).toBe("memory:parent");
222
- expect(child2.content.trim()).toBe("Second atomic fact.");
223
- });
224
- test("marks parent with inferenceProcessed: true and preserves prior frontmatter", async () => {
225
- const filePath = writeMemory("parent", { description: "preserve me", tags: "[a, b]" }, "Body.");
226
- splitter = () => ["only fact"];
227
- await runMemoryInferencePass(configWithLlm(), sources());
228
- const parentFm = parseFrontmatter(fs.readFileSync(filePath, "utf8"));
229
- expect(parentFm.data.inferenceProcessed).toBe(true);
230
- expect(parentFm.data.description).toBe("preserve me");
231
- });
232
- test("re-running the pass is idempotent — no duplicate splits", async () => {
233
- writeMemory("parent", {}, "Body.");
234
- let calls = 0;
235
- splitter = () => {
236
- calls += 1;
237
- return ["fact A", "fact B"];
238
- };
239
- await runMemoryInferencePass(configWithLlm(), sources());
240
- await runMemoryInferencePass(configWithLlm(), sources());
241
- // Second invocation must not call the splitter — the parent is already
242
- // marked `inferenceProcessed: true`.
243
- expect(calls).toBe(1);
244
- const factsDir = path.join(tmpStash, "memories", "parent.facts");
245
- const childFiles = fs
246
- .readdirSync(factsDir)
247
- .filter((f) => f.endsWith(".md"))
248
- .sort();
249
- expect(childFiles).toEqual(["fact-1.md", "fact-2.md"]);
250
- });
251
- test("inferred children are themselves filtered out — they don't get re-split", async () => {
252
- writeMemory("parent", {}, "Body.");
253
- splitter = () => ["c1", "c2"];
254
- await runMemoryInferencePass(configWithLlm(), sources());
255
- // Now reset the splitter to verify a second run finds no pending memories.
256
- let secondRunInvocations = 0;
257
- splitter = () => {
258
- secondRunInvocations += 1;
259
- return ["should not happen"];
260
- };
261
- const second = await runMemoryInferencePass(configWithLlm(), sources());
262
- expect(secondRunInvocations).toBe(0);
263
- expect(second.considered).toBe(0);
264
- expect(second.writtenFacts).toBe(0);
265
- });
266
- test("LLM returning zero facts leaves the parent unprocessed (retried next run)", async () => {
267
- const filePath = writeMemory("parent", {}, "Body.");
268
- splitter = () => [];
269
- const result = await runMemoryInferencePass(configWithLlm(), sources());
270
- expect(result.skippedNoFacts).toBe(1);
271
- expect(result.splitParents).toBe(0);
272
- expect(result.writtenFacts).toBe(0);
273
- // Parent must NOT be marked processed — a transient empty response
274
- // should be retried on the next `akm index`.
275
- const fm = parseFrontmatter(fs.readFileSync(filePath, "utf8"));
276
- expect(fm.data.inferenceProcessed).toBeUndefined();
277
- });
278
- test("does not write under cache-only sources (only the primary stash)", async () => {
279
- // Add a second source dir simulating a read-only cache. The pass must
280
- // ignore it: only sources[0] (primary stash) is writable.
281
- const cacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-mi-cache-"));
282
- fs.mkdirSync(path.join(cacheDir, "memories"), { recursive: true });
283
- const cacheParent = path.join(cacheDir, "memories", "cache-parent.md");
284
- fs.writeFileSync(cacheParent, "---\n---\n\nCache body.\n");
285
- try {
286
- writeMemory("primary", {}, "Primary body.");
287
- splitter = () => ["primary fact"];
288
- const result = await runMemoryInferencePass(configWithLlm(), [{ path: tmpStash }, { path: cacheDir }]);
289
- // Only the primary parent was considered.
290
- expect(result.considered).toBe(1);
291
- expect(result.writtenFacts).toBe(1);
292
- // No `cache-parent.facts` directory should have been created.
293
- expect(fs.existsSync(path.join(cacheDir, "memories", "cache-parent.facts"))).toBe(false);
294
- }
295
- finally {
296
- fs.rmSync(cacheDir, { recursive: true, force: true });
297
- }
298
- });
299
- });
@@ -1,136 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { mergeSearchHits } from "../src/commands/search";
3
- // Local test helper — mirrors the pre-v1 mergeStashHits logic that was removed
4
- // from production code when the OpenViking provider was dropped (Phase 1).
5
- function mergeStashHits(localHits, additionalHits, limit) {
6
- if (additionalHits.length === 0)
7
- return localHits.slice(0, limit);
8
- const localKeys = new Set();
9
- for (const h of localHits)
10
- localKeys.add(h.path ?? h.ref ?? h.name);
11
- const providerOnly = additionalHits.filter((h) => !localKeys.has(h.path ?? h.ref ?? h.name));
12
- return [...localHits, ...providerOnly].sort((a, b) => (b.score ?? 0) - (a.score ?? 0)).slice(0, limit);
13
- }
14
- // ── Helpers ─────────────────────────────────────────────────────────────────
15
- function makeStashHit(name, score) {
16
- return {
17
- type: "script",
18
- name,
19
- path: `/stash/scripts/${name}`,
20
- ref: `script:${name}`,
21
- score,
22
- };
23
- }
24
- function makeRegistryHit(name, score) {
25
- return {
26
- type: "registry",
27
- name,
28
- id: `npm:${name}`,
29
- description: `${name} package`,
30
- score,
31
- };
32
- }
33
- // ── mergeStashHits ──────────────────────────────────────────────────────────
34
- describe("mergeStashHits — fair score merge", () => {
35
- test("returns local hits when additionalHits is empty", () => {
36
- const local = [makeStashHit("a", 0.03), makeStashHit("b", 0.02)];
37
- const result = mergeStashHits(local, [], 10);
38
- expect(result).toHaveLength(2);
39
- expect(result[0].name).toBe("a");
40
- expect(result[1].name).toBe("b");
41
- });
42
- test("respects limit when additionalHits is empty", () => {
43
- const local = [makeStashHit("a", 0.03), makeStashHit("b", 0.02), makeStashHit("c", 0.01)];
44
- const result = mergeStashHits(local, [], 2);
45
- expect(result).toHaveLength(2);
46
- });
47
- test("provider hits keep original scores and sort alongside local hits", () => {
48
- const local = [makeStashHit("local-1", 0.85), makeStashHit("local-2", 0.65), makeStashHit("local-3", 0.4)];
49
- const additional = [makeStashHit("remote-1", 0.9), makeStashHit("remote-2", 0.5)];
50
- const result = mergeStashHits(local, additional, 6);
51
- expect(result).toHaveLength(5);
52
- // Sorted by score descending — remote-1 (0.9) ranks above local-1 (0.85)
53
- expect(result[0].name).toBe("remote-1");
54
- expect(result[0].score).toBe(0.9);
55
- expect(result[1].name).toBe("local-1");
56
- expect(result[1].score).toBe(0.85);
57
- expect(result[2].name).toBe("local-2");
58
- expect(result[2].score).toBe(0.65);
59
- expect(result[3].name).toBe("remote-2");
60
- expect(result[3].score).toBe(0.5);
61
- expect(result[4].name).toBe("local-3");
62
- expect(result[4].score).toBe(0.4);
63
- });
64
- test("duplicate items: local version wins, provider copy dropped", () => {
65
- const local = [makeStashHit("shared-item", 0.85), makeStashHit("local-only", 0.6)];
66
- const additional = [makeStashHit("shared-item", 0.95), makeStashHit("remote-only", 0.7)];
67
- const result = mergeStashHits(local, additional, 10);
68
- // shared-item appears once with local score, not duplicated
69
- expect(result.filter((h) => h.name === "shared-item")).toHaveLength(1);
70
- expect(result.find((h) => h.name === "shared-item")?.score).toBe(0.85);
71
- // remote-only keeps its original score and sorts by score
72
- const remoteOnly = result.find((h) => h.name === "remote-only");
73
- expect(remoteOnly).toBeDefined();
74
- expect(remoteOnly?.score).toBe(0.7);
75
- });
76
- test("respects limit parameter", () => {
77
- const local = [makeStashHit("a", 0.03), makeStashHit("b", 0.02)];
78
- const additional = [makeStashHit("c", 0.5), makeStashHit("d", 0.4)];
79
- const result = mergeStashHits(local, additional, 2);
80
- expect(result).toHaveLength(2);
81
- });
82
- test("provider hits retain their scores unmodified", () => {
83
- const local = [makeStashHit("local-1", 0.85)];
84
- const additional = [makeStashHit("remote-1", 0.7), makeStashHit("remote-2", 0.3)];
85
- const result = mergeStashHits(local, additional, 10);
86
- expect(result).toHaveLength(3);
87
- expect(result[0].name).toBe("local-1");
88
- expect(result[0].score).toBe(0.85);
89
- // Provider scores are preserved exactly
90
- expect(result[1].name).toBe("remote-1");
91
- expect(result[1].score).toBe(0.7);
92
- expect(result[2].name).toBe("remote-2");
93
- expect(result[2].score).toBe(0.3);
94
- });
95
- test("empty localHits: provider hits keep their scores", () => {
96
- const additional = [makeStashHit("remote-1", 0.8), makeStashHit("remote-2", 0.5)];
97
- const result = mergeStashHits([], additional, 10);
98
- expect(result).toHaveLength(2);
99
- expect(result[0].name).toBe("remote-1");
100
- expect(result[0].score).toBe(0.8);
101
- expect(result[1].name).toBe("remote-2");
102
- expect(result[1].score).toBe(0.5);
103
- });
104
- });
105
- // ── mergeSearchHits ─────────────────────────────────────────────────────────
106
- describe("mergeSearchHits — simple concatenation", () => {
107
- test("returns local hits when registryHits is empty", () => {
108
- const local = [makeStashHit("a", 0.85)];
109
- const result = mergeSearchHits(local, [], 10);
110
- expect(result).toHaveLength(1);
111
- expect(result[0].name).toBe("a");
112
- expect(result[0].score).toBe(0.85);
113
- });
114
- test("returns registry hits when localHits is empty", () => {
115
- const registry = [makeRegistryHit("pkg-a", 0.9)];
116
- const result = mergeSearchHits([], registry, 10);
117
- expect(result).toHaveLength(1);
118
- expect(result[0].name).toBe("pkg-a");
119
- });
120
- test("concatenates local and registry hits", () => {
121
- const local = [makeStashHit("local-1", 0.85), makeStashHit("local-2", 0.65)];
122
- const registry = [makeRegistryHit("pkg-1", 0.95), makeRegistryHit("pkg-2", 0.8)];
123
- const result = mergeSearchHits(local, registry, 10);
124
- expect(result).toHaveLength(4);
125
- expect(result[0].name).toBe("local-1");
126
- expect(result[1].name).toBe("local-2");
127
- expect(result[2].name).toBe("pkg-1");
128
- expect(result[3].name).toBe("pkg-2");
129
- });
130
- test("respects limit parameter", () => {
131
- const local = [makeStashHit("a", 0.85), makeStashHit("b", 0.65)];
132
- const registry = [makeRegistryHit("c", 0.9), makeRegistryHit("d", 0.8)];
133
- const result = mergeSearchHits(local, registry, 2);
134
- expect(result).toHaveLength(2);
135
- });
136
- });