@gmickel/gno 2.15.0 → 2.17.0

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 (218) hide show
  1. package/README.md +1 -1
  2. package/assets/skill/SKILL.md +27 -0
  3. package/assets/skill/cli-reference.md +24 -15
  4. package/assets/spa-production.json.gz +0 -0
  5. package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.17.0.zip} +0 -0
  6. package/browser-extension/artifacts/gno-browser-clipper-v2.17.0.zip.sha256 +1 -0
  7. package/browser-extension/dist/manifest.json +1 -1
  8. package/package.json +1 -1
  9. package/spec/cli.md +43 -3
  10. package/spec/db/schema.sql +53 -1
  11. package/spec/mcp.md +9 -3
  12. package/spec/output-schemas/doctor.schema.json +27 -0
  13. package/spec/output-schemas/retrieval-trace-payloads.schema.json +14 -0
  14. package/spec/output-schemas/search-results.schema.json +14 -0
  15. package/spec/output-schemas/status.schema.json +22 -0
  16. package/src/cli/commands/agents/commands.ts +1 -1
  17. package/src/cli/commands/ask.ts +1 -1
  18. package/src/cli/commands/context-build.ts +1 -1
  19. package/src/cli/commands/doctor.ts +101 -29
  20. package/src/cli/commands/embed.ts +2 -2
  21. package/src/cli/commands/links.ts +30 -6
  22. package/src/cli/commands/mcp/install.ts +2 -2
  23. package/src/cli/commands/mcp/status.ts +1 -1
  24. package/src/cli/commands/mcp/uninstall.ts +1 -1
  25. package/src/cli/commands/query.ts +1 -1
  26. package/src/cli/commands/shared.ts +4 -4
  27. package/src/cli/commands/skill/install.ts +1 -1
  28. package/src/cli/commands/skill/paths-cmd.ts +1 -1
  29. package/src/cli/commands/skill/uninstall.ts +1 -1
  30. package/src/cli/commands/status.ts +75 -58
  31. package/src/cli/commands/vec.ts +180 -8
  32. package/src/cli/config-cache.ts +86 -0
  33. package/src/cli/globals.ts +64 -0
  34. package/src/cli/program.ts +63 -36
  35. package/src/cli/run.ts +121 -67
  36. package/src/cli/runtime-health.ts +132 -122
  37. package/src/cli/session-binding.ts +11 -2
  38. package/src/config/saver.ts +8 -0
  39. package/src/config/types.ts +6 -0
  40. package/src/converters/adapters/browser-export/formats.ts +25 -15
  41. package/src/converters/adapters/email/adapter.ts +37 -53
  42. package/src/converters/adapters/email/html.ts +37 -20
  43. package/src/converters/adapters/email/mime.ts +71 -39
  44. package/src/converters/adapters/ical/adapter.ts +20 -12
  45. package/src/converters/adapters/jsonl/adapter.ts +8 -6
  46. package/src/converters/adapters/shared/html-text.ts +55 -37
  47. package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
  48. package/src/converters/adapters/shared/utf8-lines.ts +69 -31
  49. package/src/converters/adapters/transcript/adapter.ts +12 -7
  50. package/src/converters/adapters/xlsx/adapter.ts +10 -7
  51. package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
  52. package/src/converters/canonicalize.ts +17 -3
  53. package/src/converters/native/markdown.ts +24 -17
  54. package/src/converters/native/plaintext.ts +5 -6
  55. package/src/converters/registry.ts +130 -8
  56. package/src/core/activation-status.ts +4 -8
  57. package/src/core/change-diff.ts +38 -11
  58. package/src/core/context-compiler.ts +17 -18
  59. package/src/core/context-evidence.ts +116 -25
  60. package/src/core/context-verifier.ts +70 -31
  61. package/src/core/file-lock.ts +10 -2
  62. package/src/core/graph-analysis.ts +3 -3
  63. package/src/core/link-inventory-markdown.ts +2 -2
  64. package/src/core/links.ts +20 -87
  65. package/src/core/memory-fence.ts +16 -9
  66. package/src/core/memory-recall.ts +168 -34
  67. package/src/core/path-rules.ts +143 -0
  68. package/src/core/retrieval-trace-session.ts +3 -0
  69. package/src/core/retrieval-trace.ts +9 -0
  70. package/src/core/section-parse.ts +16 -6
  71. package/src/core/typed-metadata.ts +68 -0
  72. package/src/core/vector-partition-status.ts +13 -0
  73. package/src/core/wiki-link-syntax.ts +88 -0
  74. package/src/embed/backlog.ts +142 -60
  75. package/src/embed/retry.ts +39 -33
  76. package/src/embed/variant-backlog.ts +582 -116
  77. package/src/embed/variant-retry.ts +157 -48
  78. package/src/index.ts +3 -3
  79. package/src/ingestion/budget-error-codes.ts +13 -0
  80. package/src/ingestion/chunker.ts +60 -49
  81. package/src/ingestion/compiled-context.ts +4 -5
  82. package/src/ingestion/convert-file.ts +1 -1
  83. package/src/ingestion/document-metadata.ts +16 -9
  84. package/src/ingestion/excluded-ranges.ts +97 -0
  85. package/src/ingestion/file-processor.ts +122 -37
  86. package/src/ingestion/frontmatter.ts +35 -7
  87. package/src/ingestion/graph-reconciliation.ts +187 -51
  88. package/src/ingestion/language.ts +66 -61
  89. package/src/ingestion/position.ts +5 -5
  90. package/src/ingestion/prepare-file.ts +50 -29
  91. package/src/ingestion/record-adapter-canonical.ts +37 -26
  92. package/src/ingestion/record-adapter.ts +46 -26
  93. package/src/ingestion/record-container.ts +121 -53
  94. package/src/ingestion/record-path.ts +5 -2
  95. package/src/ingestion/source-availability/darwin-io.ts +10 -7
  96. package/src/ingestion/source-availability/darwin-path.ts +21 -3
  97. package/src/ingestion/source-availability/readers.ts +51 -0
  98. package/src/ingestion/strip.ts +39 -105
  99. package/src/ingestion/sync.ts +692 -386
  100. package/src/ingestion/typed-metadata.ts +10 -4
  101. package/src/ingestion/walker.ts +485 -158
  102. package/src/llm/cache.ts +128 -84
  103. package/src/llm/http-inference.ts +112 -35
  104. package/src/llm/http-policy.ts +101 -0
  105. package/src/llm/httpEmbedding.ts +8 -1
  106. package/src/llm/httpGeneration.ts +5 -1
  107. package/src/llm/httpRerank.ts +5 -1
  108. package/src/llm/inference-scope.ts +15 -2
  109. package/src/llm/lazy-ports.ts +33 -3
  110. package/src/llm/lockfile.ts +34 -7
  111. package/src/llm/model-cleanup.ts +24 -0
  112. package/src/llm/native-worker/client.ts +23 -12
  113. package/src/llm/native-worker/dispatcher.ts +19 -9
  114. package/src/llm/native-worker/embedding-identity.ts +42 -16
  115. package/src/llm/native-worker/entry.ts +2 -1
  116. package/src/llm/native-worker/owner.ts +1 -0
  117. package/src/llm/native-worker/ports.ts +86 -23
  118. package/src/llm/native-worker/protocol.ts +386 -55
  119. package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
  120. package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
  121. package/src/llm/nodeLlamaCpp/generation.ts +194 -30
  122. package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
  123. package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
  124. package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
  125. package/src/llm/types.ts +14 -0
  126. package/src/mcp/context.ts +342 -23
  127. package/src/mcp/http-transport.ts +21 -3
  128. package/src/mcp/tool-profile-types.ts +62 -0
  129. package/src/mcp/tool-profile.ts +32 -56
  130. package/src/mcp/tools/context.ts +5 -1
  131. package/src/mcp/tools/index.ts +269 -191
  132. package/src/mcp/tools/links.ts +14 -6
  133. package/src/mcp/tools/query.ts +60 -37
  134. package/src/mcp/tools/vsearch.ts +25 -14
  135. package/src/pipeline/answer.ts +133 -40
  136. package/src/pipeline/claim-verification.ts +293 -189
  137. package/src/pipeline/claim-verifier.ts +6 -7
  138. package/src/pipeline/egress-lineage.ts +37 -26
  139. package/src/pipeline/exclude.ts +34 -11
  140. package/src/pipeline/expansion.ts +233 -19
  141. package/src/pipeline/explain.ts +17 -2
  142. package/src/pipeline/filters.ts +169 -33
  143. package/src/pipeline/graph-retrieval.ts +117 -61
  144. package/src/pipeline/hybrid.ts +626 -330
  145. package/src/pipeline/hydration.ts +86 -24
  146. package/src/pipeline/intent.ts +15 -7
  147. package/src/pipeline/owner-fusion.ts +61 -19
  148. package/src/pipeline/query-language.ts +15 -2
  149. package/src/pipeline/rerank.ts +15 -22
  150. package/src/pipeline/search.ts +193 -72
  151. package/src/pipeline/snippet.ts +15 -2
  152. package/src/pipeline/temporal.ts +51 -10
  153. package/src/pipeline/types.ts +7 -0
  154. package/src/pipeline/vsearch.ts +269 -154
  155. package/src/publish/attachment-raster.ts +2 -16
  156. package/src/publish/encrypted-export.ts +15 -5
  157. package/src/serve/browse-tree.ts +50 -42
  158. package/src/serve/connectors.ts +2 -1
  159. package/src/serve/context.ts +13 -4
  160. package/src/serve/doc-events.ts +3 -0
  161. package/src/serve/public/app.tsx +49 -21
  162. package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
  163. package/src/serve/public/components/CaptureModal.tsx +14 -10
  164. package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
  165. package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
  166. package/src/serve/public/globals.built.css +1 -1
  167. package/src/serve/public/globals.css +19 -0
  168. package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
  169. package/src/serve/public/lib/metadata-filter.ts +234 -9
  170. package/src/serve/public/pages/Browse.tsx +61 -27
  171. package/src/serve/public/pages/DocView.tsx +44 -25
  172. package/src/serve/public/pages/GraphView.tsx +8 -3
  173. package/src/serve/resident-runtime.ts +199 -48
  174. package/src/serve/routes/api.ts +98 -67
  175. package/src/serve/routes/links.ts +25 -5
  176. package/src/serve/server.ts +1370 -1180
  177. package/src/serve/spa-bundle-source.ts +52 -27
  178. package/src/serve/status.ts +101 -52
  179. package/src/serve/watch-reconciliation-fallback.ts +11 -7
  180. package/src/serve/watch-reconciliation-shared.ts +42 -4
  181. package/src/serve/watch-reconciliation.ts +21 -8
  182. package/src/serve/watch-service-events.ts +7 -1
  183. package/src/serve/watch-service-hosts.ts +3 -1
  184. package/src/serve/watch-service.ts +46 -21
  185. package/src/serve/watch-snapshot-scan.ts +6 -15
  186. package/src/sessions/archive.ts +20 -8
  187. package/src/sessions/sanitize.ts +38 -18
  188. package/src/sessions/service.ts +180 -102
  189. package/src/store/migrations/037-performance-indexes.ts +56 -0
  190. package/src/store/migrations/038-vector-mirror-null-cosine.ts +47 -0
  191. package/src/store/migrations/039-vector-mirror-v2.ts +94 -0
  192. package/src/store/migrations/index.ts +6 -0
  193. package/src/store/sqlite/adapter.ts +1260 -651
  194. package/src/store/sqlite/chunking-policy.ts +15 -1
  195. package/src/store/sqlite/eligibility.ts +110 -70
  196. package/src/store/sqlite/graph-neighbors.ts +71 -46
  197. package/src/store/sqlite/graph-reference-state.ts +27 -3
  198. package/src/store/sqlite/graph-similarity.ts +59 -12
  199. package/src/store/sqlite/metadata-predicate.ts +123 -28
  200. package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
  201. package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
  202. package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
  203. package/src/store/types.ts +32 -0
  204. package/src/store/vector/coarse-router.ts +312 -0
  205. package/src/store/vector/eligibility.ts +39 -0
  206. package/src/store/vector/lazy.ts +17 -0
  207. package/src/store/vector/partition-index.ts +333 -59
  208. package/src/store/vector/proof-cache.ts +209 -0
  209. package/src/store/vector/runtime-compat.ts +6 -0
  210. package/src/store/vector/sqlite-vec.ts +270 -162
  211. package/src/store/vector/stats.ts +37 -73
  212. package/src/store/vector/status.ts +169 -53
  213. package/src/store/vector/stored-vectors.ts +131 -45
  214. package/src/store/vector/types.ts +19 -0
  215. package/src/store/vector/v2-mirror.ts +669 -0
  216. package/src/store/vector/variant-search.ts +1187 -111
  217. package/src/store/vector/variants.ts +964 -160
  218. package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Per-invocation CLI config and session-binding cache.
3
+ *
4
+ * Eliminates 2x-3x redundant YAML/Zod parses across preAction session-binding,
5
+ * initStore, and terminal-link policy within a single CLI command while staying
6
+ * completely inactive for direct non-CLI callers and invalidating immediately
7
+ * on config writes or resetGlobals().
8
+ *
9
+ * @module src/cli/config-cache
10
+ */
11
+
12
+ import type { LoadResult } from "../config/loader";
13
+ import type { Config } from "../config/types";
14
+
15
+ import { expandPath, getConfigPaths } from "../config/paths";
16
+ import { getConfigWriteGeneration } from "../config/saver";
17
+ import { isCliInvocationActive, registerGlobalsResetListener } from "./globals";
18
+
19
+ type LoadConfigResult = LoadResult<Config>;
20
+
21
+ interface CachedConfigEntry {
22
+ generation: number;
23
+ result: LoadConfigResult;
24
+ }
25
+
26
+ const configCache = new Map<string, CachedConfigEntry>();
27
+ const verifiedBindings = new Map<string, number>();
28
+
29
+ export function clearCliConfigCache(): void {
30
+ configCache.clear();
31
+ verifiedBindings.clear();
32
+ }
33
+
34
+ registerGlobalsResetListener(clearCliConfigCache);
35
+
36
+ function resolveCanonicalConfigPath(configPath?: string): string {
37
+ return configPath ? expandPath(configPath) : getConfigPaths().configFile;
38
+ }
39
+
40
+ /**
41
+ * Load config, reusing a parsed result within the same CLI invocation when
42
+ * no config write has occurred since it was loaded.
43
+ */
44
+ export async function loadConfigCached(
45
+ configPath?: string
46
+ ): Promise<LoadConfigResult> {
47
+ const { loadConfig } = await import("../config/loader");
48
+ if (!isCliInvocationActive()) {
49
+ return loadConfig(configPath);
50
+ }
51
+ const canonical = resolveCanonicalConfigPath(configPath);
52
+ const generation = getConfigWriteGeneration();
53
+ const cached = configCache.get(canonical);
54
+ if (cached && cached.generation === generation) {
55
+ return cached.result;
56
+ }
57
+ const loaded = await loadConfig(configPath);
58
+ if (loaded.ok && getConfigWriteGeneration() === generation) {
59
+ configCache.set(canonical, { generation, result: loaded });
60
+ }
61
+ return loaded;
62
+ }
63
+
64
+ /** Check whether a (configPath, indexName) binding was already verified in this CLI invocation. */
65
+ export function isSessionBindingVerifiedInInvocation(
66
+ configPath: string,
67
+ indexName: string
68
+ ): boolean {
69
+ if (!isCliInvocationActive()) {
70
+ return false;
71
+ }
72
+ const key = `${resolveCanonicalConfigPath(configPath)}\u0000${indexName}`;
73
+ return verifiedBindings.get(key) === getConfigWriteGeneration();
74
+ }
75
+
76
+ /** Record that (configPath, indexName) passed session-binding verification in this CLI invocation. */
77
+ export function markSessionBindingVerifiedInInvocation(
78
+ configPath: string,
79
+ indexName: string
80
+ ): void {
81
+ if (!isCliInvocationActive()) {
82
+ return;
83
+ }
84
+ const key = `${resolveCanonicalConfigPath(configPath)}\u0000${indexName}`;
85
+ verifiedBindings.set(key, getConfigWriteGeneration());
86
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Shared CLI global options state.
3
+ * Extracted from src/cli/program so commands and runners do not pull in
4
+ * Commander or the full command definition tree just to read/reset globals.
5
+ *
6
+ * @module src/cli/globals
7
+ */
8
+
9
+ import type { GlobalOptions } from "./context";
10
+
11
+ import { setColorsEnabled } from "./colors";
12
+
13
+ const globalState: { current: GlobalOptions | null } = { current: null };
14
+ let cliInvocationActive = false;
15
+ const resetListeners = new Set<() => void>();
16
+
17
+ /** Register a cleanup hook invoked when CLI global state resets. */
18
+ export function registerGlobalsResetListener(listener: () => void): void {
19
+ resetListeners.add(listener);
20
+ }
21
+
22
+ /** Mark that a CLI invocation is active (enables per-invocation caches). */
23
+ export function setCliInvocationActive(active: boolean): void {
24
+ cliInvocationActive = active;
25
+ if (!active) {
26
+ for (const listener of resetListeners) {
27
+ listener();
28
+ }
29
+ }
30
+ }
31
+
32
+ /** True while inside an active runCli() invocation. */
33
+ export function isCliInvocationActive(): boolean {
34
+ return cliInvocationActive || globalState.current !== null;
35
+ }
36
+
37
+ /** Set resolved global options (called by Commander's preAction hook). */
38
+ export function setGlobals(globals: GlobalOptions): void {
39
+ globalState.current = globals;
40
+ }
41
+
42
+ /**
43
+ * Get resolved global options. Must be called after command parsing.
44
+ * Throws if called before preAction hook runs.
45
+ */
46
+ export function getGlobals(): GlobalOptions {
47
+ if (!globalState.current) {
48
+ throw new Error("Global options not resolved - called before preAction?");
49
+ }
50
+ return globalState.current;
51
+ }
52
+
53
+ /**
54
+ * Reset global state (for testing and at the start of every CLI invocation).
55
+ * Resets option state, color state, and per-invocation caches.
56
+ */
57
+ export function resetGlobals(): void {
58
+ globalState.current = null;
59
+ cliInvocationActive = false;
60
+ setColorsEnabled(true);
61
+ for (const listener of resetListeners) {
62
+ listener();
63
+ }
64
+ }
@@ -20,11 +20,6 @@ import {
20
20
  } from "../app/constants";
21
21
  import { INDEX_NAME_REQUIREMENTS, isValidIndexName } from "../app/index-name";
22
22
  import { resolveDepthPolicy } from "../core/depth-policy";
23
- import {
24
- findingsRunStatePathForIndex,
25
- formatFindingsRunStatusLine,
26
- readFindingsRunStatus,
27
- } from "../core/findings-run-state";
28
23
  import { residentShutdownHandlerInstalled } from "../core/resident-shutdown-handler";
29
24
  import { parseAndValidateTagFilter } from "../core/tags";
30
25
  import {
@@ -35,8 +30,11 @@ import {
35
30
  withCliWriteLease,
36
31
  type WriteLeaseBusyFailure,
37
32
  } from "../core/write-lease";
38
- import { type McpToolProfile, parseMcpToolProfile } from "../mcp/tool-profile";
39
- import { setColorsEnabled } from "./colors";
33
+ import {
34
+ type McpToolProfile,
35
+ parseMcpToolProfile,
36
+ } from "../mcp/tool-profile-types";
37
+ import { loadConfigCached } from "./config-cache";
40
38
  import {
41
39
  applyGlobalOptions,
42
40
  type GlobalOptions,
@@ -48,6 +46,7 @@ import {
48
46
  residentIssues,
49
47
  } from "./detach";
50
48
  import { CliError } from "./errors";
49
+ import { getGlobals, resetGlobals, setGlobals } from "./globals";
51
50
  import {
52
51
  assertFormatSupported,
53
52
  CMD,
@@ -63,32 +62,10 @@ import {
63
62
  import { resolveCliQueryText } from "./query-text";
64
63
 
65
64
  // ─────────────────────────────────────────────────────────────────────────────
66
- // Global State (set by preAction hook)
65
+ // Global State (re-exported from ./globals for backwards compatibility)
67
66
  // ─────────────────────────────────────────────────────────────────────────────
68
67
 
69
- // Using object wrapper to allow mutation while satisfying linter
70
- const globalState: { current: GlobalOptions | null } = { current: null };
71
-
72
- /**
73
- * Get resolved global options. Must be called after command parsing.
74
- * Throws if called before preAction hook runs.
75
- */
76
- export function getGlobals(): GlobalOptions {
77
- if (!globalState.current) {
78
- throw new Error("Global options not resolved - called before preAction?");
79
- }
80
- return globalState.current;
81
- }
82
-
83
- /**
84
- * Reset global state (for testing).
85
- * Resets both option state and color state to avoid test pollution.
86
- */
87
- export function resetGlobals(): void {
88
- globalState.current = null;
89
- // Reset colors to default (true) - will be set by applyGlobalOptions on next run
90
- setColorsEnabled(true);
91
- }
68
+ export { getGlobals, resetGlobals };
92
69
 
93
70
  /**
94
71
  * Resolve the user-facing argv slice (everything after `[execPath, scriptPath]`)
@@ -220,8 +197,7 @@ async function resolveTerminalLinkPolicy(
220
197
  };
221
198
  }
222
199
 
223
- const { loadConfig } = await import("../config");
224
- const configResult = await loadConfig(globals.config);
200
+ const configResult = await loadConfigCached(globals.config);
225
201
  const configTemplate = configResult.ok
226
202
  ? configResult.value.editorUriTemplate?.trim()
227
203
  : undefined;
@@ -373,7 +349,7 @@ export function createProgram(): Command {
373
349
  );
374
350
  }
375
351
  applyGlobalOptions(globals);
376
- globalState.current = globals;
352
+ setGlobals(globals);
377
353
  // convert reads no config or index, so there is no binding to check.
378
354
  if (actionCommand === convertCommand) return;
379
355
  const { assertCliSessionBinding } = await import("./session-binding");
@@ -3677,7 +3653,7 @@ function wireManagementCommands(program: Command): void {
3677
3653
  .description("Generate embeddings for indexed documents")
3678
3654
  .option("--collection <name>", "restrict to one collection")
3679
3655
  .option("--model <uri>", "embedding model URI")
3680
- .option("--batch-size <num>", "batch size", "32")
3656
+ .option("--batch-size <num>", "batch size")
3681
3657
  .option("--force", "regenerate all embeddings")
3682
3658
  .option(
3683
3659
  "--new-partition",
@@ -3720,7 +3696,10 @@ function wireManagementCommands(program: Command): void {
3720
3696
  indexName: globals.index,
3721
3697
  collection,
3722
3698
  model: cmdOpts.model as string | undefined,
3723
- batchSize: parsePositiveInt("batch-size", cmdOpts.batchSize),
3699
+ batchSize:
3700
+ cmdOpts.batchSize !== undefined
3701
+ ? parsePositiveInt("batch-size", cmdOpts.batchSize)
3702
+ : undefined,
3724
3703
  force: Boolean(cmdOpts.force),
3725
3704
  dryRun: Boolean(cmdOpts.dryRun),
3726
3705
  maxChunks: parseRunLimit("max-chunks", cmdOpts.maxChunks),
@@ -3929,6 +3908,49 @@ function wireVecCommands(program: Command): void {
3929
3908
  `${formatVecRebuild(result, { json: format === "json" })}\n`
3930
3909
  );
3931
3910
  });
3911
+
3912
+ // vec prune
3913
+ addWriteLeaseFlags(
3914
+ vecCmd
3915
+ .command("prune")
3916
+ .description(
3917
+ "Remove superseded legacy vector tables and orphaned vec_v1 mirrors"
3918
+ )
3919
+ .option(
3920
+ "--vacuum",
3921
+ "Run SQLite VACUUM after pruning to reclaim disk space"
3922
+ )
3923
+ .option("--json", "JSON output")
3924
+ ).action(async (cmdOpts: Record<string, unknown>) => {
3925
+ const format = getFormat(cmdOpts);
3926
+ const globals = getGlobals();
3927
+
3928
+ const { vecPrune, formatVecPrune } = await import("./commands/vec");
3929
+ const lease = parseWriteLeaseFlags(cmdOpts);
3930
+ const result = await withCliWriteLease(
3931
+ {
3932
+ indexName: globals.index,
3933
+ lockWaitMs: lease.lockWaitMs,
3934
+ noWait: lease.noWait,
3935
+ },
3936
+ () =>
3937
+ vecPrune({
3938
+ configPath: globals.config,
3939
+ indexName: globals.index,
3940
+ vacuum: Boolean(cmdOpts.vacuum),
3941
+ json: format === "json",
3942
+ })
3943
+ );
3944
+ throwIfWriteLeaseBusy(result, format === "json");
3945
+
3946
+ if (!result.success) {
3947
+ throw new CliError("RUNTIME", result.error);
3948
+ }
3949
+
3950
+ process.stdout.write(
3951
+ `${formatVecPrune(result, { json: format === "json" })}\n`
3952
+ );
3953
+ });
3932
3954
  }
3933
3955
 
3934
3956
  function wirePublishCommand(program: Command): void {
@@ -5251,6 +5273,11 @@ async function runDaemonStatus(deps: DaemonStatusDeps): Promise<void> {
5251
5273
  });
5252
5274
  // Persisted by the daemon after every scheduled findings attempt; absent
5253
5275
  // (null) when the pass is not configured. Read from disk, never live.
5276
+ const {
5277
+ findingsRunStatePathForIndex,
5278
+ formatFindingsRunStatusLine,
5279
+ readFindingsRunStatus,
5280
+ } = await import("../core/findings-run-state");
5254
5281
  const findings = await readFindingsRunStatus(
5255
5282
  findingsRunStatePathForIndex(deps.indexName)
5256
5283
  );
package/src/cli/run.ts CHANGED
@@ -5,13 +5,13 @@
5
5
  * @module src/cli/run
6
6
  */
7
7
 
8
- import { CommanderError } from "commander";
8
+ // node:path / node:url: no Bun equivalents for dirname/join/fileURLToPath.
9
9
  import { dirname, join } from "node:path";
10
10
  import { fileURLToPath } from "node:url";
11
11
 
12
- import { CLI_NAME, PRODUCT_NAME } from "../app/constants";
12
+ import { CLI_NAME, PRODUCT_NAME, VERSION } from "../app/constants";
13
13
  import { CliError, exitCodeFor, formatErrorForOutput } from "./errors";
14
- import { createProgram, resetGlobals } from "./program";
14
+ import { resetGlobals, setCliInvocationActive } from "./globals";
15
15
 
16
16
  /**
17
17
  * Check if argv contains --json flag (before end-of-options marker).
@@ -41,9 +41,48 @@ const KNOWN_BOOL_FLAGS = new Set([
41
41
  "--offline",
42
42
  ]);
43
43
 
44
+ // Version fast-path additionally accepts --no-pager without altering bare-CLI help parity.
45
+ const VERSION_BOOL_FLAGS = new Set([...KNOWN_BOOL_FLAGS, "--no-pager"]);
46
+
44
47
  // Known global flags that take values (--flag value or --flag=value)
45
48
  const KNOWN_VALUE_FLAGS = ["--index", "--config"] as const;
46
49
 
50
+ /**
51
+ * Check if argv requests root version (`--version` or `-V`) with no subcommand
52
+ * and only valid global flags before `--`, so we can answer without loading
53
+ * Commander or the 5,800-line command graph.
54
+ */
55
+ function hasRootVersionFlag(argv: string[]): boolean {
56
+ let sawVersion = false;
57
+ for (let i = 2; i < argv.length; i++) {
58
+ const arg = argv[i] as string;
59
+ if (arg === "--") {
60
+ return sawVersion && i === argv.length - 1;
61
+ }
62
+ if (arg === "--version" || arg === "-V") {
63
+ sawVersion = true;
64
+ continue;
65
+ }
66
+ if (VERSION_BOOL_FLAGS.has(arg)) {
67
+ continue;
68
+ }
69
+ if (isKnownValueFlag(arg) && arg.includes("=")) {
70
+ continue;
71
+ }
72
+ if (isKnownValueFlag(arg)) {
73
+ const nextArg = argv[i + 1];
74
+ if (nextArg === undefined || nextArg.startsWith("-")) {
75
+ return false;
76
+ }
77
+ i += 1;
78
+ continue;
79
+ }
80
+ // Any subcommand, --help/-h, or unknown flag falls through to Commander.
81
+ return false;
82
+ }
83
+ return sawVersion;
84
+ }
85
+
47
86
  /**
48
87
  * Check if arg is a known value flag (--index, --config, or --index=val form).
49
88
  */
@@ -174,84 +213,99 @@ export async function runCli(argv: string[]): Promise<number> {
174
213
  // Commander's per-invocation `Command.rawArgs` via `resolveCliArgv()`,
175
214
  // so no separate process-global capture is needed here.
176
215
  resetGlobals();
216
+ setCliInvocationActive(true);
177
217
 
178
- const isJson = argvWantsJson(argv);
218
+ try {
219
+ const isJson = argvWantsJson(argv);
179
220
 
180
- // Handle --skill flag: output SKILL.md for agent discovery
181
- if (argvWantsSkill(argv)) {
182
- await printSkillFile();
183
- return 0;
184
- }
221
+ // Handle --skill flag: output SKILL.md for agent discovery
222
+ if (argvWantsSkill(argv)) {
223
+ await printSkillFile();
224
+ return 0;
225
+ }
185
226
 
186
- // Handle "no subcommand" case before Commander (avoids full help display)
187
- if (hasNoSubcommand(argv)) {
188
- printConciseHelp({ json: isJson });
189
- return 0;
190
- }
227
+ // Handle root --version / -V before importing Commander and program.ts
228
+ if (hasRootVersionFlag(argv)) {
229
+ process.stdout.write(`${VERSION}\n`);
230
+ return 0;
231
+ }
191
232
 
192
- const program = createProgram();
233
+ // Handle "no subcommand" case before Commander (avoids full help display)
234
+ if (hasNoSubcommand(argv)) {
235
+ printConciseHelp({ json: isJson });
236
+ return 0;
237
+ }
193
238
 
194
- // Suppress Commander's stderr output in JSON mode
195
- // so agents get only our structured JSON envelope
196
- if (isJson) {
197
- program.configureOutput({
198
- writeErr: () => {
199
- // Intentionally empty: suppress Commander's stderr
200
- },
201
- });
202
- }
239
+ const [{ CommanderError }, { createProgram }] = await Promise.all([
240
+ import("commander"),
241
+ import("./program"),
242
+ ]);
243
+ const program = createProgram();
203
244
 
204
- try {
205
- await program.parseAsync(argv);
206
- return 0;
207
- } catch (err) {
208
- // Handle CliError with proper JSON formatting
209
- if (err instanceof CliError) {
210
- // `silent` is reserved for codes whose exit value carries the meaning
211
- // (e.g. NOT_RUNNING from `--stop` per spec/cli.md). Skip stderr but
212
- // still propagate the code.
213
- if (!err.silent) {
214
- const output = formatErrorForOutput(err, { json: isJson });
215
- process.stderr.write(`${output}\n`);
216
- }
217
- return exitCodeFor(err);
245
+ // Suppress Commander's stderr output in JSON mode
246
+ // so agents get only our structured JSON envelope
247
+ if (isJson) {
248
+ program.configureOutput({
249
+ writeErr: () => {
250
+ // Intentionally empty: suppress Commander's stderr
251
+ },
252
+ });
218
253
  }
219
254
 
220
- // Handle Commander errors (exitOverride throws these)
221
- if (err instanceof CommanderError) {
222
- // Help/version are "successful" exits
223
- // commander.helpDisplayed: --help or -h flag
224
- // commander.help: help subcommand (e.g., help collection)
225
- // commander.version: --version or -V flag
226
- if (
227
- err.code === "commander.helpDisplayed" ||
228
- err.code === "commander.help" ||
229
- err.code === "commander.version"
230
- ) {
231
- return 0;
255
+ try {
256
+ await program.parseAsync(argv);
257
+ return 0;
258
+ } catch (err) {
259
+ // Handle CliError with proper JSON formatting
260
+ if (err instanceof CliError) {
261
+ // `silent` is reserved for codes whose exit value carries the meaning
262
+ // (e.g. NOT_RUNNING from `--stop` per spec/cli.md). Skip stderr but
263
+ // still propagate the code.
264
+ if (!err.silent) {
265
+ const output = formatErrorForOutput(err, { json: isJson });
266
+ process.stderr.write(`${output}\n`);
267
+ }
268
+ return exitCodeFor(err);
269
+ }
270
+
271
+ // Handle Commander errors (exitOverride throws these)
272
+ if (err instanceof CommanderError) {
273
+ // Help/version are "successful" exits
274
+ // commander.helpDisplayed: --help or -h flag
275
+ // commander.help: help subcommand (e.g., help collection)
276
+ // commander.version: --version or -V flag
277
+ if (
278
+ err.code === "commander.helpDisplayed" ||
279
+ err.code === "commander.help" ||
280
+ err.code === "commander.version"
281
+ ) {
282
+ return 0;
283
+ }
284
+
285
+ // Validation errors (missing args, unknown options)
286
+ // Always emit JSON envelope in JSON mode (Commander stderr suppressed above)
287
+ if (isJson) {
288
+ const cliErr = new CliError("VALIDATION", err.message, {
289
+ commanderCode: err.code,
290
+ });
291
+ const output = formatErrorForOutput(cliErr, { json: true });
292
+ process.stderr.write(`${output}\n`);
293
+ }
294
+ return 1;
232
295
  }
233
296
 
234
- // Validation errors (missing args, unknown options)
235
- // Always emit JSON envelope in JSON mode (Commander stderr suppressed above)
297
+ // Unexpected errors
298
+ const message = err instanceof Error ? err.message : String(err);
236
299
  if (isJson) {
237
- const cliErr = new CliError("VALIDATION", err.message, {
238
- commanderCode: err.code,
239
- });
300
+ const cliErr = new CliError("RUNTIME", message);
240
301
  const output = formatErrorForOutput(cliErr, { json: true });
241
302
  process.stderr.write(`${output}\n`);
303
+ } else {
304
+ process.stderr.write(`Error: ${message}\n`);
242
305
  }
243
- return 1;
244
- }
245
-
246
- // Unexpected errors
247
- const message = err instanceof Error ? err.message : String(err);
248
- if (isJson) {
249
- const cliErr = new CliError("RUNTIME", message);
250
- const output = formatErrorForOutput(cliErr, { json: true });
251
- process.stderr.write(`${output}\n`);
252
- } else {
253
- process.stderr.write(`Error: ${message}\n`);
306
+ return 2;
254
307
  }
255
- return 2;
308
+ } finally {
309
+ setCliInvocationActive(false);
256
310
  }
257
311
  }