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