akm-cli 0.9.17-alpha.8 → 0.9.17

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 (111) hide show
  1. package/CHANGELOG.md +277 -1694
  2. package/STABILITY.md +9 -8
  3. package/dist/assets/hints/cli-hints-full.md +6 -7
  4. package/dist/assets/improve-strategies/catchup.json +0 -3
  5. package/dist/assets/improve-strategies/consolidate.json +0 -1
  6. package/dist/assets/improve-strategies/default.json +1 -2
  7. package/dist/assets/improve-strategies/proactive-maintenance.json +1 -2
  8. package/dist/assets/improve-strategies/quick.json +1 -2
  9. package/dist/assets/improve-strategies/reflect-distill.json +1 -2
  10. package/dist/assets/improve-strategies/thorough.json +0 -3
  11. package/dist/assets/prompts/consolidate-pair.md +20 -0
  12. package/dist/assets/stash-skeleton/facts/conventions/backlinks.md +17 -19
  13. package/dist/assets/stash-skeleton/facts/conventions/domains.md +2 -2
  14. package/dist/assets/templates/html/health.html +3 -5
  15. package/dist/cli/retired-commands.js +1 -1
  16. package/dist/cli/unknown-flags.js +24 -1
  17. package/dist/cli.js +46 -1
  18. package/dist/commands/health/archive-usage.js +92 -0
  19. package/dist/commands/health/data-dir-usage.js +25 -13
  20. package/dist/commands/health/html-report.js +1 -4
  21. package/dist/commands/health/improve-metrics.js +25 -37
  22. package/dist/commands/health/md-report.js +1 -6
  23. package/dist/commands/health/report-view-model.js +4 -14
  24. package/dist/commands/health/windows.js +0 -1
  25. package/dist/commands/health.js +13 -0
  26. package/dist/commands/improve/consolidate/continuity-check.js +137 -0
  27. package/dist/commands/improve/consolidate/pair-pass.js +791 -0
  28. package/dist/commands/improve/consolidate.js +38 -63
  29. package/dist/commands/improve/extract-prompt.js +1 -2
  30. package/dist/commands/improve/improve-cli.js +1 -1
  31. package/dist/commands/improve/improve-strategies.js +23 -5
  32. package/dist/commands/improve/improve.js +19 -30
  33. package/dist/commands/improve/ledger.js +3 -2
  34. package/dist/commands/improve/loop-stages.js +5 -85
  35. package/dist/commands/improve/memory/memory-belief.js +3 -1
  36. package/dist/commands/improve/memory/memory-improve.js +262 -11
  37. package/dist/commands/improve/planner.js +0 -5
  38. package/dist/commands/improve/preparation.js +20 -135
  39. package/dist/commands/improve/retrieval-scope.js +19 -4
  40. package/dist/commands/improve/salience.js +1 -14
  41. package/dist/commands/improve/stage.js +0 -1
  42. package/dist/commands/lint/base-linter.js +19 -11
  43. package/dist/commands/proposal/drain.js +8 -1
  44. package/dist/commands/proposal/proposal-cli.js +16 -2
  45. package/dist/commands/proposal/proposal-types.js +7 -0
  46. package/dist/commands/proposal/proposal.js +37 -6
  47. package/dist/commands/proposal/repository.js +613 -4
  48. package/dist/commands/proposal/validators/proposals.js +9 -0
  49. package/dist/commands/read/knowledge.js +3 -2
  50. package/dist/commands/read/show.js +0 -14
  51. package/dist/commands/sources/info.js +122 -18
  52. package/dist/commands/sources/stash-cli.js +23 -3
  53. package/dist/core/bundle-rename.js +1 -7
  54. package/dist/core/config/config-schema.js +8 -1
  55. package/dist/core/config/config.js +23 -48
  56. package/dist/core/config/engine-semantics.js +0 -2
  57. package/dist/core/config/schema/improve-processes.js +17 -42
  58. package/dist/core/config/schema/index-config.js +5 -25
  59. package/dist/core/file-change.js +13 -5
  60. package/dist/core/improve-result.js +22 -6
  61. package/dist/core/improve-types.js +0 -1
  62. package/dist/core/loopback.js +7 -12
  63. package/dist/core/parse.js +13 -16
  64. package/dist/core/state/migrations.js +15 -0
  65. package/dist/core/time.js +0 -20
  66. package/dist/indexer/db/llm-cache.js +2 -2
  67. package/dist/indexer/ensure-index.js +2 -2
  68. package/dist/indexer/index-written-assets.js +2 -3
  69. package/dist/indexer/indexer.js +18 -418
  70. package/dist/indexer/passes/metadata.js +0 -19
  71. package/dist/indexer/walk/walker.js +3 -4
  72. package/dist/llm/client.js +8 -10
  73. package/dist/llm/embedders/remote.js +1 -2
  74. package/dist/llm/feature-gate.js +0 -5
  75. package/dist/output/shapes/helpers.js +20 -4
  76. package/dist/output/text/command-format.js +9 -8
  77. package/dist/output/text/proposal-format.js +47 -1
  78. package/dist/output/text/show-format.js +0 -20
  79. package/dist/scripts/akm-migrate-node.js +923 -950
  80. package/dist/scripts/akm-migrate.js +923 -950
  81. package/dist/setup/steps/connection.js +5 -6
  82. package/dist/setup/steps/platforms.js +2 -2
  83. package/dist/sources/providers/git-stash.js +83 -4
  84. package/dist/storage/repositories/improve-ledger-repository.js +48 -7
  85. package/dist/storage/repositories/index-connection.js +5 -2
  86. package/dist/storage/repositories/index-entries-repository.js +4 -7
  87. package/dist/storage/repositories/index-entry-schema.js +4 -2
  88. package/dist/storage/repositories/index-llm-cache-repository.js +7 -26
  89. package/dist/storage/repositories/index-schema.js +55 -104
  90. package/dist/storage/repositories/proposals-repository.js +61 -0
  91. package/dist/storage/repositories/salience-repository.js +1 -19
  92. package/docs/migration/README.md +1 -1
  93. package/docs/migration/release-notes/0.9.17.md +130 -41
  94. package/docs/migration/release-notes/README.md +7 -0
  95. package/docs/reference/cli.md +27 -21
  96. package/docs/reference/configuration.md +21 -12
  97. package/docs/reference/data-and-telemetry.md +0 -1
  98. package/package.json +1 -1
  99. package/schemas/akm-config.json +0 -342
  100. package/dist/assets/improve-strategies/graph-refresh.json +0 -15
  101. package/dist/assets/prompts/contradiction-judge.md +0 -33
  102. package/dist/assets/prompts/graph-extract-system.md +0 -1
  103. package/dist/assets/prompts/graph-extract-user-prompt.md +0 -35
  104. package/dist/assets/prompts/metadata-enhance-system.md +0 -1
  105. package/dist/assets/tasks/improve/akm-graph-refresh-weekly.yml +0 -4
  106. package/dist/indexer/db/graph-db.js +0 -399
  107. package/dist/indexer/graph/graph-extraction.js +0 -809
  108. package/dist/indexer/graph/graph-related.js +0 -131
  109. package/dist/indexer/graph/graph-types.js +0 -4
  110. package/dist/llm/graph-extract.js +0 -892
  111. package/dist/llm/metadata-enhance.js +0 -95
@@ -4,12 +4,21 @@
4
4
  /** Proposal validation and the one content repair applied before promotion. */
5
5
  import { repairTruncatedDescription } from "../../../core/text-truncation.js";
6
6
  import { splitFrontmatter } from "../../improve/reflect-noise.js";
7
+ import { isRetireProposal } from "../proposal-types.js";
7
8
  import { runProposalValidators } from "./proposal-validators.js";
8
9
  /**
9
10
  * Validate a proposal before promotion: it must parse and carry a body, and a
10
11
  * type with a canonical validator runs it.
12
+ *
13
+ * A retire proposal (alpha.9 consolidate pair pass) writes no new content —
14
+ * it deletes an asset that already passed validation when IT was created —
15
+ * so the content-quality validators (built for new/updated bodies: a
16
+ * description, lesson shape, reflect size ratio, …) do not apply and are
17
+ * skipped entirely rather than misreading the empty body as a defect.
11
18
  */
12
19
  export function validateProposal(proposal) {
20
+ if (isRetireProposal(proposal))
21
+ return { ok: true, findings: [] };
13
22
  return runProposalValidators(proposal);
14
23
  }
15
24
  /**
@@ -612,8 +612,9 @@ export async function writeMarkdownAsset(options) {
612
612
  // no longer trigger reindexes, so keeping the index current is the writer's
613
613
  // job. Demoted files reindex under their own containing root (usually the
614
614
  // write target itself; the working stash when writing to a --target) so
615
- // `--belief current` filtering and the beliefState ranking demotion take
616
- // effect without waiting for the next full index.
615
+ // `--belief current` filtering takes effect without waiting for the next
616
+ // full index. (alpha.4 removed belief weights from ranking; `--belief` is
617
+ // the only reader of `beliefState` today.)
617
618
  const demotedInTargetRoot = demotedByRoot.get(source.path) ?? [];
618
619
  demotedByRoot.delete(source.path);
619
620
  await indexWrittenAssets(source.path, [result.path, ...demotedInTargetRoot], { bundleId: resolved.ref.origin });
@@ -33,7 +33,6 @@ import { appendEvent } from "../../core/events.js";
33
33
  import { SCRIPT_EXTENSIONS } from "../../core/recognition-util.js";
34
34
  import { presentationFor } from "../../core/type-presentation.js";
35
35
  import { warn, warnOnce } from "../../core/warn.js";
36
- import { listRelatedPathsForFile } from "../../indexer/graph/graph-related.js";
37
36
  import { lookupBundleRef, lookupBundleRefWithResolution } from "../../indexer/indexer.js";
38
37
  import { projectMarkdownFragmentContent } from "../../indexer/passes/metadata.js";
39
38
  import { ensurePrimaryIndexForRead, resolveReadSources } from "../../indexer/read-preflight.js";
@@ -384,19 +383,6 @@ export async function showLocal(input) {
384
383
  origin: source?.registryId ?? null,
385
384
  editable,
386
385
  ...(!editable ? { editHint: buildEditHint(canonicalRef) } : {}),
387
- related: (() => {
388
- try {
389
- return withIndexDb((db) => {
390
- const related = listRelatedPathsForFile(sourceStashDir, assetPath, 5, db);
391
- return { total: related.length, hits: related };
392
- });
393
- }
394
- catch (err) {
395
- rethrowIfTestIsolationError(err);
396
- rethrowIfDataDirUnreadable(err);
397
- return { total: 0, hits: [] };
398
- }
399
- })(),
400
386
  ...showLinks(indexedEntry.itemRef, displayDefaultBundle),
401
387
  };
402
388
  const activeRun = await getActiveWorkflowRun(getCurrentWorkflowScopeKey());
@@ -1,30 +1,87 @@
1
1
  // This Source Code Form is subject to the terms of the Mozilla Public
2
2
  // License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+ import path from "node:path";
4
5
  import { placementTypes } from "../../core/asset/asset-placement.js";
5
6
  import { resolveStashDir } from "../../core/common.js";
6
- import { getSources, loadConfig } from "../../core/config/config.js";
7
+ import { DEFAULT_CONFIG, getSources, loadConfig } from "../../core/config/config.js";
8
+ import { ConfigError } from "../../core/errors.js";
7
9
  import { classifyPathAccess, describeInaccessiblePath } from "../../core/path-access.js";
8
- import { getCacheDir, getConfigDir, getDataDir, getDbPath, getStateDir } from "../../core/paths.js";
10
+ import { getCacheDir, getConfigDir, getDataDir, getDefaultStashDir, getStateDir } from "../../core/paths.js";
9
11
  import { formatRegistryUrl } from "../../core/registry-url.js";
10
12
  import { error } from "../../core/warn.js";
11
- import { closeDatabase, openExistingDatabase } from "../../storage/repositories/index-connection.js";
13
+ import { closeDatabase, openReadonlyExistingDatabase } from "../../storage/repositories/index-connection.js";
12
14
  import { getEntryCount, getEntryCountByType } from "../../storage/repositories/index-entries-repository.js";
13
15
  import { countLinksByKind } from "../../storage/repositories/index-links-repository.js";
14
16
  import { getMeta } from "../../storage/repositories/index-meta-repository.js";
17
+ import { isSqliteContentionError } from "../../storage/sqlite-transaction.js";
15
18
  import { pkgVersion } from "../../version.js";
19
+ /**
20
+ * Bound for `akm info`'s diagnostic index.db read — short enough that a
21
+ * locked database never stalls the command, unlike the shared 30s
22
+ * `SQLITE_BUSY_TIMEOUT_MS` every write-capable opener uses. The opener's own
23
+ * layout check (`checkIndexLayout`) swallows a busy error on its one SELECT
24
+ * rather than surfacing it, so a genuinely locked database costs this
25
+ * timeout TWICE before the first real query here (`countLinksByKind`)
26
+ * throws for real — 750ms keeps that ~1.5s worst case well clear of the 3s
27
+ * bound integration tests hold this to, on a loaded CI box.
28
+ */
29
+ const INFO_INDEX_BUSY_TIMEOUT_MS = 750;
16
30
  /**
17
31
  * Assemble system info describing the current capabilities, configuration,
18
- * and index state. Used by `akm info`.
32
+ * and index state. Used by `akm info`, which must behave like a help
33
+ * command (owner ruling): always print a report and exit 0, whatever else
34
+ * is happening. Every section below is read best-effort, so one failing
35
+ * lookup degrades only its own field(s) instead of the whole report;
36
+ * `infoCommand` itself (stash-cli.ts) wraps this whole call as the final
37
+ * backstop for anything left over — e.g. a path resolver that needs an
38
+ * environment variable nothing here sets, such as `HOME`.
19
39
  *
20
40
  * @param options.dbPath - Override the database path (useful for testing)
21
41
  */
22
42
  export function assembleInfo(options) {
23
- const config = loadConfig();
43
+ let config;
44
+ let configError;
45
+ try {
46
+ config = loadConfig();
47
+ }
48
+ catch (err) {
49
+ config = DEFAULT_CONFIG;
50
+ configError = err instanceof Error ? err.message : String(err);
51
+ }
24
52
  // Primary stash directory + default bundle name — same resolution
25
53
  // `akm sources list` uses (R-057), so `akm info` and `akm sources list`
26
- // agree on which stash is primary.
27
- const stashDir = resolveStashDir();
54
+ // agree on which stash is primary. No bundle created yet
55
+ // (STASH_DIR_NOT_FOUND, the ordinary fresh-install state) reports where a
56
+ // fresh `akm setup`/`akm bundle create` would put it, same as "report the
57
+ // defaults" for a missing config — no error needed, nothing is actually
58
+ // wrong. A bundle that WAS configured (an env override or `bundles.*` in
59
+ // config) but doesn't resolve (STASH_DIR_UNREADABLE/STASH_DIR_NOT_A_DIRECTORY)
60
+ // is different: the fallback path is a courtesy, not a way to hide a
61
+ // genuine misconfiguration, so that reason is kept in `bundleDirError`.
62
+ let stashDir;
63
+ let bundleDirError;
64
+ try {
65
+ stashDir = resolveStashDir();
66
+ }
67
+ catch (err) {
68
+ if (!(err instanceof ConfigError) || err.code !== "STASH_DIR_NOT_FOUND") {
69
+ bundleDirError = err instanceof Error ? err.message : String(err);
70
+ }
71
+ // The fallback itself resolves purely from `HOME` (or its platform
72
+ // equivalent) and can throw the exact same way `resolveStashDir()` can
73
+ // (e.g. HOME entirely unset) — guarded so a blank `bundleDir` (never a
74
+ // throw) still always carries a reason, reusing the one above when the
75
+ // outer catch already set it (a configured-but-broken path takes
76
+ // precedence over restating "and the default isn't resolvable either").
77
+ try {
78
+ stashDir = getDefaultStashDir();
79
+ }
80
+ catch (fallbackErr) {
81
+ stashDir = "";
82
+ bundleDirError ??= fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
83
+ }
84
+ }
28
85
  const defaultBundle = config.defaultBundle ?? null;
29
86
  // Asset types (copy into a mutable array — `placementTypes()` returns readonly)
30
87
  const assetTypes = [...placementTypes()];
@@ -45,11 +102,29 @@ export function assembleInfo(options) {
45
102
  ...(s.url ? { url: s.url } : {}),
46
103
  ...(s.enabled !== undefined ? { enabled: s.enabled } : {}),
47
104
  }));
48
- // Index stats — `options.dbPath` is a test-only override (see the param
49
- // doc above); real callers fall through to the same `getDbPath()` that
50
- // health and search use, so info reads the same database they do.
51
- const resolvedDbPath = options?.dbPath ?? getDbPath();
52
- const indexStats = readIndexStats(resolvedDbPath);
105
+ // Data directory. `getDataDir()` can itself throw (e.g. TEST_ISOLATION_MISSING
106
+ // when NODE_ENV=test leaks into a real invocation — a JS test runner's
107
+ // child process — with no XDG_DATA_HOME/AKM_DATA_DIR override), caught
108
+ // here so that failure degrades only `dataDir`/`indexStats` rather than
109
+ // the whole report. Always attempted, even when `options.dbPath` (a
110
+ // test-only override, see the param doc above) means it is not needed to
111
+ // resolve the index path below — `dataDir` is its own reported field.
112
+ let dataDir = "";
113
+ let dataDirError;
114
+ try {
115
+ dataDir = getDataDir();
116
+ }
117
+ catch (err) {
118
+ dataDirError = err instanceof Error ? err.message : String(err);
119
+ }
120
+ // Index stats. `options.dbPath` overrides the resolved path outright;
121
+ // otherwise it is derived from `dataDir` above, so a data dir that failed
122
+ // to resolve degrades index stats the same way rather than retrying (and
123
+ // re-throwing) `getDataDir()` a second time.
124
+ const resolvedDbPath = options?.dbPath ?? (dataDir ? path.join(dataDir, "index.db") : undefined);
125
+ const indexStats = resolvedDbPath
126
+ ? readIndexStats(resolvedDbPath)
127
+ : { entryCount: 0, byType: {}, lastBuiltAt: null, hasEmbeddings: false, unavailable: dataDirError };
53
128
  // Semantic status is read live from the index's own state, not a cached
54
129
  // verdict — a failed embed attempt at search time falls back to FTS and
55
130
  // reports that in the search response, it never disables the mode here.
@@ -63,10 +138,12 @@ export function assembleInfo(options) {
63
138
  version: pkgVersion,
64
139
  bundleDir: stashDir,
65
140
  defaultBundle,
66
- dataDir: getDataDir(),
67
- configDir: getConfigDir(),
68
- cacheDir: getCacheDir(),
69
- stateDir: getStateDir(),
141
+ ...(configError ? { configError } : {}),
142
+ ...(bundleDirError ? { bundleDirError } : {}),
143
+ dataDir,
144
+ configDir: safePath(getConfigDir),
145
+ cacheDir: safePath(getCacheDir),
146
+ stateDir: safePath(getStateDir),
70
147
  assetTypes,
71
148
  searchModes,
72
149
  semanticSearch: {
@@ -78,6 +155,15 @@ export function assembleInfo(options) {
78
155
  indexStats,
79
156
  };
80
157
  }
158
+ /** Best-effort path resolution for a section that must degrade, not throw: an empty string in place of an exception. */
159
+ function safePath(fn) {
160
+ try {
161
+ return fn();
162
+ }
163
+ catch {
164
+ return "";
165
+ }
166
+ }
81
167
  function readIndexStats(resolvedPath) {
82
168
  const EMPTY = {
83
169
  entryCount: 0,
@@ -99,7 +185,15 @@ function readIndexStats(resolvedPath) {
99
185
  }
100
186
  let db;
101
187
  try {
102
- db = openExistingDatabase(resolvedPath);
188
+ // Never writes the index — no schema or journal-mode change — and
189
+ // bounded to INFO_INDEX_BUSY_TIMEOUT_MS rather than the shared 30s
190
+ // busy_timeout every write-capable opener uses. A newer index layout is
191
+ // reported below rather than refused (checkIndexLayout throws); an
192
+ // older layout just warns and is served as-is, never migrated — both
193
+ // already true of this opener.
194
+ db = openReadonlyExistingDatabase(resolvedPath, { busyTimeoutMs: INFO_INDEX_BUSY_TIMEOUT_MS });
195
+ if (!db)
196
+ return EMPTY; // raced away (deleted) between the access check above and here
103
197
  const links = countLinksByKind(db);
104
198
  return {
105
199
  entryCount: getEntryCount(db),
@@ -115,7 +209,7 @@ function readIndexStats(resolvedPath) {
115
209
  // Routed through core/warn's `error()` (not a raw process.stderr.write)
116
210
  // so `--quiet`/`setQuiet()` actually gate this line (R-057).
117
211
  error(`[akm info] failed to read index stats from ${resolvedPath}: ${String(err)}`);
118
- return EMPTY;
212
+ return { ...EMPTY, unavailable: describeIndexReadFailure(err) };
119
213
  }
120
214
  finally {
121
215
  if (db) {
@@ -128,3 +222,13 @@ function readIndexStats(resolvedPath) {
128
222
  }
129
223
  }
130
224
  }
225
+ /**
226
+ * Reason for `indexStats.unavailable`. Contention gets its own clear
227
+ * wording; everything else (a too-new layout, on-disk corruption, ...) is
228
+ * already descriptive as the driver/opener's own message.
229
+ */
230
+ function describeIndexReadFailure(err) {
231
+ if (isSqliteContentionError(err))
232
+ return "index.db is locked by another akm process";
233
+ return err instanceof Error ? err.message : String(err);
234
+ }
@@ -33,6 +33,7 @@ import * as p from "../../cli/clack.js";
33
33
  import { getParsedInvocation } from "../../cli/invocation.js";
34
34
  import { defineJsonCommand, GLOBAL_OUTPUT_ARGS, output, parseAllFlagValues, runWithJsonErrors } from "../../cli/shared.js";
35
35
  import { assertFlatAssetName } from "../../core/asset/asset-create.js";
36
+ import { placementTypes } from "../../core/asset/asset-placement.js";
36
37
  import { parseFrontmatter } from "../../core/asset/frontmatter.js";
37
38
  import { isHttpUrl, resolveStashDir } from "../../core/common.js";
38
39
  import { loadConfig } from "../../core/config/config.js";
@@ -45,6 +46,7 @@ import { resolveWriteTarget } from "../../core/write-source.js";
45
46
  import { releaseIndexRebuildLock, tryAcquireIndexRebuildLock } from "../../indexer/index-rebuild-lock.js";
46
47
  import { akmIndex } from "../../indexer/indexer.js";
47
48
  import { getHyphenatedBoolean, getOutputMode } from "../../output/context.js";
49
+ import { pkgVersion } from "../../version.js";
48
50
  import { inferAssetName, mergeXrefsIntoContent, readKnowledgeInput, resolveSupersedesForWrite, resolveSupersedesWriteTarget, resolveXrefsForWrite, writeMarkdownAsset, } from "../read/knowledge.js";
49
51
  import { assembleInfo } from "./info.js";
50
52
  /** Matches the high-frequency per-committed-batch progress line (#954), excluded from non-verbose JSON-mode stderr. */
@@ -83,10 +85,10 @@ export const indexCommand = defineCommand({
83
85
  async run({ args }) {
84
86
  await runWithJsonErrors(async () => {
85
87
  if (getHyphenatedBoolean(args, "enrich") || getParsedInvocation().getFlagValue("--enrich") !== undefined) {
86
- throw new UsageError("`akm index --enrich` has been removed. Plain `akm index` now performs metadata enrichment by default.");
88
+ throw new UsageError("`akm index --enrich` has been removed. Metadata enrichment during indexing is retired; it never runs.");
87
89
  }
88
90
  if (getHyphenatedBoolean(args, "re-enrich") || getParsedInvocation().getFlagValue("--re-enrich") !== undefined) {
89
- throw new UsageError("`akm index --re-enrich` has been removed. Re-enrichment of index-time LLM passes is not exposed in this slice.");
91
+ throw new UsageError("`akm index --re-enrich` has been removed. Metadata enrichment during indexing is retired; there is nothing to re-enrich.");
90
92
  }
91
93
  // #956: opt-in, non-blocking rebuild lock — never gates a human-typed
92
94
  // `akm index` (it only warns and contends), but a scheduled/opportunistic
@@ -181,7 +183,25 @@ export const indexCommand = defineCommand({
181
183
  export const infoCommand = defineJsonCommand({
182
184
  meta: { name: "info", description: "Show system capabilities, configuration, and index stats" },
183
185
  run() {
184
- const result = assembleInfo();
186
+ // `akm info` must behave like a help command: always exit 0 with a
187
+ // report. `assembleInfo()` already degrades what it reasonably can
188
+ // per-section; this is the final backstop for whatever it can't (e.g.
189
+ // every path resolver needs an environment variable, such as `HOME`,
190
+ // that this process genuinely does not have) — still a report, with
191
+ // whatever is cheap and safe enough to never itself throw.
192
+ let result;
193
+ try {
194
+ result = assembleInfo();
195
+ }
196
+ catch (err) {
197
+ result = {
198
+ schemaVersion: 1,
199
+ version: pkgVersion,
200
+ error: err instanceof Error ? err.message : String(err),
201
+ assetTypes: [...placementTypes()],
202
+ searchModes: ["fts"],
203
+ };
204
+ }
185
205
  output("info", result);
186
206
  },
187
207
  });
@@ -30,7 +30,6 @@ import fs from "node:fs";
30
30
  import { readLockfile, renameLockEntry } from "../integrations/lockfile.js";
31
31
  import { closeDatabase, openIndexDatabase, openReadonlyExistingDatabase, } from "../storage/repositories/index-connection.js";
32
32
  import { getFilePathsByBundle, renameEntriesBundleId } from "../storage/repositories/index-entries-repository.js";
33
- import { renameLlmCacheAssetRefs } from "../storage/repositories/index-llm-cache-repository.js";
34
33
  import { countProposalsForBundleRename, renameProposalsBundleRef } from "../storage/repositories/proposals-repository.js";
35
34
  import { countTaskHistoryTargetRefs, renameTaskHistoryTargetRefs, } from "../storage/repositories/task-history-repository.js";
36
35
  import { selectBackend } from "../tasks/backends/index.js";
@@ -243,18 +242,13 @@ export async function renameBundle(oldId, newId, options = {}, deps) {
243
242
  // e.g. a plain filesystem bundle).
244
243
  await renameLockEntry(oldId, newId);
245
244
  // Index: bundle_id/item_ref on every entry row (see index-entries-repository's
246
- // renameEntriesBundleId docstring for why no FTS/vector rebuild is needed),
247
- // and the metadata-enrichment LLM cache keyed by the same canonical
248
- // item_ref — in the SAME write, so a rename can never land between the two
249
- // and leave the cache stranded under the old prefix (the next `akm index`'s
250
- // clearStaleCacheEntries would then delete it, forcing a full re-enrich).
245
+ // renameEntriesBundleId docstring for why no FTS/vector rebuild is needed).
251
246
  const readIndexDb = openReadonlyExistingDatabase(getDbPath());
252
247
  if (readIndexDb) {
253
248
  closeDatabase(readIndexDb);
254
249
  const writeIndexDb = openIndexDatabase(getDbPath());
255
250
  try {
256
251
  renameEntriesBundleId(writeIndexDb, oldId, newId);
257
- renameLlmCacheAssetRefs(writeIndexDb, oldId, newId);
258
252
  }
259
253
  finally {
260
254
  closeDatabase(writeIndexDb);
@@ -60,7 +60,7 @@ export { EngineConfigSchema, EnginesSchema, LlmConnectionConfigSchema, LlmProfil
60
60
  export { ExperimentalConfigSchema } from "./schema/experimental.js";
61
61
  export { FEEDBACK_FAILURE_MODES, FeedbackConfigSchema } from "./schema/feedback.js";
62
62
  export { ImproveConfigSchema } from "./schema/improve.js";
63
- export { ConsolidateProcessConfigSchema, DistillProcessConfigSchema, ExtractProcessConfigSchema, GraphExtractionProcessConfigSchema, ImproveProcessConfigSchema, ImproveProfileConfigSchema, MemoryInferenceProcessConfigSchema, ProactiveMaintenanceProcessConfigSchema, ReflectProcessConfigSchema, TriageProcessConfigSchema, ValidationProcessConfigSchema, } from "./schema/improve-processes.js";
63
+ export { ConsolidateProcessConfigSchema, DistillProcessConfigSchema, ExtractProcessConfigSchema, ImproveProcessConfigSchema, ImproveProfileConfigSchema, MemoryInferenceProcessConfigSchema, ProactiveMaintenanceProcessConfigSchema, ReflectProcessConfigSchema, TriageProcessConfigSchema, ValidationProcessConfigSchema, } from "./schema/improve-processes.js";
64
64
  export { IndexConfigSchema, IndexPassConfigSchema } from "./schema/index-config.js";
65
65
  export { OutputConfigSchema } from "./schema/output.js";
66
66
  export { CURRENT_CONFIG_VERSION, LlmInvocationOverridesSchema } from "./schema/primitives.js";
@@ -240,6 +240,13 @@ export const AkmConfigSchema = AkmConfigBaseSchema.superRefine((config, ctx) =>
240
240
  }
241
241
  const defaultStrategy = config.defaults?.improveStrategy;
242
242
  if (defaultStrategy &&
243
+ // graph-refresh is exempt from this eager, config-load-time check: unlike
244
+ // a plain typo, it is a specific, known retirement, and refusing it here
245
+ // would fail every command's config load (including `akm migrate apply`,
246
+ // the one that fixes this). `resolveImproveStrategy`
247
+ // (src/commands/improve/improve-strategies.ts) refuses it lazily, at
248
+ // improve-invocation time, with the same message either way.
249
+ defaultStrategy !== "graph-refresh" &&
243
250
  !BUILTIN_IMPROVE_STRATEGY_NAMES.includes(defaultStrategy) &&
244
251
  !config.improve?.strategies?.[defaultStrategy]) {
245
252
  ctx.addIssue({
@@ -27,36 +27,6 @@ export { VALID_HARNESS_IDS } from "./config-types.js";
27
27
  // Canonical taxonomy lives in the schema/validator layer; re-exported here so
28
28
  // existing `../core/config/config` import sites keep working.
29
29
  export { FEEDBACK_FAILURE_MODES } from "./config-schema.js";
30
- /**
31
- * Default value for {@link IndexPassConfig.graphExtractionBatchSize}. Chosen
32
- * empirically: 4 amortises the per-call HTTP overhead 4× while keeping the
33
- * combined prompt size well under common 8K/16K context windows (each body is
34
- * sliced to ~500 chars in the graph-extract prompt builder).
35
- */
36
- const DEFAULT_GRAPH_EXTRACTION_BATCH_SIZE = 4;
37
- /**
38
- * Approximate character budget per asset body inside a batched
39
- * graph-extraction prompt — used by {@link resolveBatchSize} to derive a
40
- * context-window ceiling when `llm.contextLength` is configured. This accounts
41
- * for the actual `MAX_BODY_CHARS` (500) in graph-extract.ts plus the system
42
- * prompt, user prompt wrapper, and expected JSON response overhead.
43
- */
44
- const GRAPH_EXTRACTION_CHARS_PER_BODY = 1500;
45
- /**
46
- * Clamp a configured batch size against the model's known context window.
47
- *
48
- * `configured` defaults to {@link DEFAULT_GRAPH_EXTRACTION_BATCH_SIZE} when
49
- * `undefined`. When `contextLength` is provided, the result is the smaller of
50
- * `configured` and `floor(contextLength / GRAPH_EXTRACTION_CHARS_PER_BODY)`,
51
- * with a floor of 1 so the batched path always processes at least one body.
52
- */
53
- export function resolveBatchSize(configured, contextLength) {
54
- const base = configured && configured > 0 ? configured : DEFAULT_GRAPH_EXTRACTION_BATCH_SIZE;
55
- if (!contextLength || contextLength <= 0)
56
- return base;
57
- const ceiling = Math.max(1, Math.floor(contextLength / GRAPH_EXTRACTION_CHARS_PER_BODY));
58
- return Math.max(1, Math.min(base, ceiling));
59
- }
60
30
  // ── Defaults ────────────────────────────────────────────────────────────────
61
31
  export const DEFAULT_CONFIG = {
62
32
  configVersion: "0.9.0",
@@ -210,6 +180,18 @@ function buildEffectiveConfig(liftedLocalRaw, sourcePath) {
210
180
  assertUniquePhysicalBundleRoots(finalResult.data, sourcePath);
211
181
  return finalResult.data;
212
182
  }
183
+ /**
184
+ * Retired `index.<passName>` keys that still validate against the generic
185
+ * per-pass catchall schema (`IndexPassConfigSchema`), so `resolveSchemaAt`
186
+ * below never returns `undefined` for them and the walk would otherwise
187
+ * treat them as a live, ordinary pass. Named here so the same three
188
+ * guarantees apply as any other retired config key (AGENTS.md "Reading
189
+ * persisted data"): a config setting one keeps loading, is named once by
190
+ * the unknown-key warning, and is dropped only by `akm migrate apply`.
191
+ * Both were retired in 0.9.17-alpha.9: `index.graph` (the LLM entity-graph
192
+ * extraction pass) and `index.metadataEnhance` (LLM metadata enrichment).
193
+ */
194
+ const RETIRED_CATCHALL_KEY_PATHS = new Set(["index.graph", "index.metadataEnhance"]);
213
195
  /**
214
196
  * Every dotted key in `raw` the schema does not know, at any depth (arrays
215
197
  * are not descended). Unknown keys are never an error: they are a typo, or a
@@ -221,7 +203,7 @@ export function unknownConfigKeyPaths(root, node = root, prefix = []) {
221
203
  const found = [];
222
204
  for (const key of Object.keys(node).sort()) {
223
205
  const keyPath = [...prefix, key];
224
- if (resolveSchemaAt(keyPath, root) === undefined) {
206
+ if (RETIRED_CATCHALL_KEY_PATHS.has(keyPath.join(".")) || resolveSchemaAt(keyPath, root) === undefined) {
225
207
  found.push(keyPath);
226
208
  continue;
227
209
  }
@@ -695,6 +677,16 @@ export function normalizeConfigFile(configPath, options) {
695
677
  const body = withSchedulerOnDisk(configWriteBody(localRaw, current, next), next);
696
678
  for (const keyPath of unknownConfigKeyPaths(body))
697
679
  deleteConfigPath(body, keyPath);
680
+ // `improve.strategies["graph-refresh"]` is schema-valid (any name is a
681
+ // legal custom-strategy key), so it never reaches the unknown-key sweep
682
+ // above. It can only be a leftover override of the deleted graph-refresh
683
+ // built-in (0.9.17-alpha.9) — resolveImproveStrategy now refuses that
684
+ // name unconditionally, so the override can never apply again. Drop it
685
+ // the same way any other retired key is dropped: only by `akm migrate
686
+ // apply`, never by an ordinary write.
687
+ const strategies = body.improve?.strategies;
688
+ if (strategies && Object.hasOwn(strategies, "graph-refresh"))
689
+ delete strategies["graph-refresh"];
698
690
  const keys = [...new Set([...Object.keys(raw), ...Object.keys(body)])]
699
691
  .filter((key) => JSON.stringify(raw[key]) !== JSON.stringify(body[key]))
700
692
  .sort();
@@ -928,23 +920,6 @@ export function resolveSecret(value, resolveFromStore) {
928
920
  return resolved ?? "";
929
921
  });
930
922
  }
931
- /**
932
- * Read a per-pass {@link IndexPassConfig} entry from {@link IndexConfig},
933
- * filtering out the reserved feature-section keys so callers don't mistake
934
- * `metadataEnhance` for a pass.
935
- */
936
- /** Reserved well-known keys on IndexConfig that are NOT per-pass entries. */
937
- const INDEX_RESERVED_KEYS = new Set(["metadataEnhance"]);
938
- export function getIndexPassConfig(config, passName) {
939
- if (!config)
940
- return undefined;
941
- if (INDEX_RESERVED_KEYS.has(passName))
942
- return undefined;
943
- const entry = config[passName];
944
- if (!entry || typeof entry !== "object")
945
- return undefined;
946
- return entry;
947
- }
948
923
  // Re-export source runtime helpers — implementation lives in config-sources.ts.
949
924
  export { bundleComponentConfig, bundleContentRoot, bundleContentRoots, bundleEntryToSourceEntry, bundleKeyForContentRoot, bundlePhysicalContentRoot, bundleSourceId, bundlesToSourceEntries, installedSourceDescriptor, isBundleEnabled, parseSourceSpec, primaryBundlePath, resolveActiveConfiguredSources, resolveConfiguredSources, } from "./config-sources.js";
950
925
  /**
@@ -6,7 +6,6 @@ export const BUILTIN_IMPROVE_STRATEGY_NAMES = [
6
6
  "default",
7
7
  "quick",
8
8
  "thorough",
9
- "graph-refresh",
10
9
  "consolidate",
11
10
  "catchup",
12
11
  "reflect-distill",
@@ -18,7 +17,6 @@ export const IMPROVE_PROCESS_ENGINE_CAPABILITIES = {
18
17
  distill: "llm",
19
18
  consolidate: "llm",
20
19
  memoryInference: "llm",
21
- graphExtraction: "llm",
22
20
  extract: "llm",
23
21
  validation: "llm",
24
22
  triage: "runner",
@@ -10,13 +10,14 @@ import { IMPROVE_PROCESS_ENGINE_CAPABILITIES } from "../engine-semantics.js";
10
10
  import { engineName, LlmInvocationOverridesSchema, nonEmptyString, positiveInt } from "./primitives.js";
11
11
  // ── Improve profile / process ──────────────────────────────────────────────
12
12
  //
13
- // WI-9.6 (§4.2/§10.2): each of the 9 improve processes (reflect, distill,
14
- // consolidate, memoryInference, graphExtraction, extract, validation, triage,
15
- // proactiveMaintenance) gets its OWN schema below — a shared base (engine,
16
- // model, llm, enabled, timeoutMs) extended with only the fields meaningful on
17
- // that process — replacing the prior single ImproveProcessConfigSchema reused
18
- // via `.optional()` for all 9 keys (which accepted, and silently ignored, any
19
- // field on any process). Field→process assignment is derived from each
13
+ // WI-9.6 (§4.2/§10.2): each of the improve processes (reflect, distill,
14
+ // consolidate, memoryInference, extract, validation, triage,
15
+ // proactiveMaintenance — graphExtraction had one too, until the LLM
16
+ // entity-graph it ran was retired in 0.9.17-alpha.9) gets its OWN schema
17
+ // below — a shared base (engine, model, llm, enabled, timeoutMs) extended
18
+ // with only the fields meaningful on that process — replacing the prior
19
+ // single ImproveProcessConfigSchema reused via `.optional()` for all of them
20
+ // (which accepted, and silently ignored, any field on any process). Field→process assignment is derived from each
20
21
  // field's original "only meaningful on X" doc comment, cross-checked against
21
22
  // its actual runtime consumers and the built-in strategy assets
22
23
  // (src/assets/improve-strategies/*.json).
@@ -164,12 +165,6 @@ const CONSOLIDATE_PROCESS_FIELDS = {
164
165
  // entirely (emits `pool_below_min_size`). 0 disables the guard. Default 500.
165
166
  minPoolSize: z.number().int().min(0).optional(),
166
167
  maxChunkSize: z.number().int().min(1).max(50).optional(),
167
- // Narrow candidate pool to memories modified within this duration window
168
- // plus their graph neighbours. Absent = full-pool sweep.
169
- incrementalSince: z.string().optional(),
170
- // Graph neighbours per changed memory during incremental consolidation.
171
- // Default 5. Only meaningful with incrementalSince.
172
- neighborsPerChanged: z.number().int().min(1).optional(),
173
168
  // Fallback p90 wall-clock time per consolidation chunk in seconds, used for
174
169
  // cold-start budget estimation when no telemetry history exists. The actual
175
170
  // p90 is derived from observed run durations once sufficient history
@@ -182,29 +177,6 @@ const MEMORY_INFERENCE_PROCESS_FIELDS = {
182
177
  minPendingCount: z.number().int().min(0).optional(),
183
178
  cls: clsField,
184
179
  };
185
- /**
186
- * GraphExtraction process fields: one strategy's graph extraction scope and
187
- * batching. `includeTypes` and `batchSize` override `index.graph`'s
188
- * `graphExtractionIncludeTypes` and `graphExtractionBatchSize`; unset, the
189
- * pass reads those.
190
- */
191
- const GRAPH_EXTRACTION_PROCESS_FIELDS = {
192
- // #624 P2: when set, rank eligible files by utility_scores DESC and process
193
- // only the top-N per run (incremental high-signal-first sweep). Unset =
194
- // process all eligible (current behavior).
195
- topN: positiveInt.optional(),
196
- includeTypes: z.array(z.string().min(1)).min(1).optional(),
197
- batchSize: positiveInt.optional(),
198
- // Full-corpus scan. When true, graph extraction runs on ALL stash files
199
- // instead of only files touched by actionable refs in the current run.
200
- // Used by the `graph-refresh` built-in profile / a scheduled weekly task.
201
- fullScan: z.boolean().optional(),
202
- // R12b + R20: cap on chunks processed per asset. A body chunked beyond this
203
- // is truncated to the first N chunks instead of paying for unbounded
204
- // per-asset LLM calls; the coverage loss is recorded as truncatedChunks.
205
- // Absent = default 8 (src/llm/graph-extract.ts DEFAULT_MAX_CHUNKS_PER_ASSET).
206
- maxChunksPerAsset: positiveInt.optional(),
207
- };
208
180
  const EXTRACT_PROCESS_FIELDS = {
209
181
  defaultSince: z.string().min(1).optional(),
210
182
  maxTotalChars: positiveInt.optional(),
@@ -264,7 +236,6 @@ export const ImproveProcessConfigSchema = z
264
236
  ...DISTILL_PROCESS_FIELDS,
265
237
  ...CONSOLIDATE_PROCESS_FIELDS,
266
238
  ...MEMORY_INFERENCE_PROCESS_FIELDS,
267
- ...GRAPH_EXTRACTION_PROCESS_FIELDS,
268
239
  ...EXTRACT_PROCESS_FIELDS,
269
240
  ...TRIAGE_PROCESS_FIELDS,
270
241
  ...PROACTIVE_MAINTENANCE_PROCESS_FIELDS,
@@ -288,10 +259,6 @@ export const ConsolidateProcessConfigSchema = z
288
259
  export const MemoryInferenceProcessConfigSchema = z
289
260
  .object({ ...IMPROVE_PROCESS_BASE_FIELDS, ...MEMORY_INFERENCE_PROCESS_FIELDS })
290
261
  .passthrough();
291
- /** `processes.graphExtraction` — narrow per-process schema (WI-9.6). */
292
- export const GraphExtractionProcessConfigSchema = z
293
- .object({ ...IMPROVE_PROCESS_BASE_FIELDS, ...GRAPH_EXTRACTION_PROCESS_FIELDS })
294
- .passthrough();
295
262
  /** `processes.extract` — narrow per-process schema (WI-9.6). */
296
263
  export const ExtractProcessConfigSchema = z
297
264
  .object({ ...IMPROVE_PROCESS_BASE_FIELDS, ...EXTRACT_PROCESS_FIELDS })
@@ -306,13 +273,20 @@ export const TriageProcessConfigSchema = z
306
273
  export const ProactiveMaintenanceProcessConfigSchema = z
307
274
  .object({ ...IMPROVE_PROCESS_BASE_FIELDS, ...PROACTIVE_MAINTENANCE_PROCESS_FIELDS })
308
275
  .passthrough();
276
+ /**
277
+ * Process names that once had a dedicated schema and are now gone. Setting
278
+ * one, even with `enabled: true`, is tolerated rather than rejected by the
279
+ * "unknown enabled process" check below — an old config must keep loading
280
+ * (AGENTS.md "Reading persisted data"). `graphExtraction`: the LLM
281
+ * entity-graph extraction it ran was retired in 0.9.17-alpha.9.
282
+ */
283
+ const RETIRED_PROCESS_NAMES = new Set(["graphExtraction"]);
309
284
  const ImproveProfileProcessesSchema = z
310
285
  .object({
311
286
  reflect: ReflectProcessConfigSchema.optional(),
312
287
  distill: DistillProcessConfigSchema.optional(),
313
288
  consolidate: ConsolidateProcessConfigSchema.optional(),
314
289
  memoryInference: MemoryInferenceProcessConfigSchema.optional(),
315
- graphExtraction: GraphExtractionProcessConfigSchema.optional(),
316
290
  extract: ExtractProcessConfigSchema.optional(),
317
291
  validation: ValidationProcessConfigSchema.optional(),
318
292
  triage: TriageProcessConfigSchema.optional(),
@@ -335,6 +309,7 @@ const ImproveProfileProcessesSchema = z
335
309
  }
336
310
  for (const [name, process] of Object.entries(val)) {
337
311
  if (!(name in IMPROVE_PROCESS_ENGINE_CAPABILITIES) &&
312
+ !RETIRED_PROCESS_NAMES.has(name) &&
338
313
  process !== null &&
339
314
  typeof process === "object" &&
340
315
  process.enabled === true) {