@gmickel/gno 2.15.0 → 2.16.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 (198) hide show
  1. package/README.md +1 -1
  2. package/assets/skill/cli-reference.md +4 -2
  3. package/assets/spa-production.json.gz +0 -0
  4. package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.16.0.zip} +0 -0
  5. package/browser-extension/artifacts/gno-browser-clipper-v2.16.0.zip.sha256 +1 -0
  6. package/browser-extension/dist/manifest.json +1 -1
  7. package/package.json +1 -1
  8. package/spec/cli.md +1 -1
  9. package/src/cli/commands/agents/commands.ts +1 -1
  10. package/src/cli/commands/ask.ts +1 -1
  11. package/src/cli/commands/context-build.ts +1 -1
  12. package/src/cli/commands/embed.ts +2 -2
  13. package/src/cli/commands/links.ts +1 -1
  14. package/src/cli/commands/mcp/install.ts +2 -2
  15. package/src/cli/commands/mcp/status.ts +1 -1
  16. package/src/cli/commands/mcp/uninstall.ts +1 -1
  17. package/src/cli/commands/query.ts +1 -1
  18. package/src/cli/commands/shared.ts +4 -4
  19. package/src/cli/commands/skill/install.ts +1 -1
  20. package/src/cli/commands/skill/paths-cmd.ts +1 -1
  21. package/src/cli/commands/skill/uninstall.ts +1 -1
  22. package/src/cli/commands/status.ts +75 -58
  23. package/src/cli/config-cache.ts +86 -0
  24. package/src/cli/globals.ts +64 -0
  25. package/src/cli/program.ts +20 -36
  26. package/src/cli/run.ts +121 -67
  27. package/src/cli/runtime-health.ts +132 -122
  28. package/src/cli/session-binding.ts +11 -2
  29. package/src/config/saver.ts +8 -0
  30. package/src/converters/adapters/browser-export/formats.ts +25 -15
  31. package/src/converters/adapters/email/adapter.ts +37 -53
  32. package/src/converters/adapters/email/html.ts +37 -20
  33. package/src/converters/adapters/email/mime.ts +71 -39
  34. package/src/converters/adapters/ical/adapter.ts +20 -12
  35. package/src/converters/adapters/jsonl/adapter.ts +8 -6
  36. package/src/converters/adapters/shared/html-text.ts +55 -37
  37. package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
  38. package/src/converters/adapters/shared/utf8-lines.ts +69 -31
  39. package/src/converters/adapters/transcript/adapter.ts +12 -7
  40. package/src/converters/adapters/xlsx/adapter.ts +10 -7
  41. package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
  42. package/src/converters/canonicalize.ts +17 -3
  43. package/src/converters/native/markdown.ts +24 -17
  44. package/src/converters/native/plaintext.ts +5 -6
  45. package/src/converters/registry.ts +130 -8
  46. package/src/core/activation-status.ts +4 -8
  47. package/src/core/change-diff.ts +38 -11
  48. package/src/core/context-compiler.ts +17 -18
  49. package/src/core/context-evidence.ts +116 -25
  50. package/src/core/context-verifier.ts +70 -31
  51. package/src/core/file-lock.ts +10 -2
  52. package/src/core/graph-analysis.ts +3 -3
  53. package/src/core/link-inventory-markdown.ts +2 -2
  54. package/src/core/links.ts +20 -87
  55. package/src/core/memory-fence.ts +16 -9
  56. package/src/core/memory-recall.ts +168 -34
  57. package/src/core/path-rules.ts +143 -0
  58. package/src/core/section-parse.ts +16 -6
  59. package/src/core/typed-metadata.ts +68 -0
  60. package/src/core/wiki-link-syntax.ts +88 -0
  61. package/src/embed/backlog.ts +142 -60
  62. package/src/embed/retry.ts +39 -33
  63. package/src/embed/variant-backlog.ts +546 -114
  64. package/src/embed/variant-retry.ts +157 -48
  65. package/src/index.ts +3 -3
  66. package/src/ingestion/budget-error-codes.ts +13 -0
  67. package/src/ingestion/chunker.ts +60 -49
  68. package/src/ingestion/compiled-context.ts +4 -5
  69. package/src/ingestion/convert-file.ts +1 -1
  70. package/src/ingestion/document-metadata.ts +16 -9
  71. package/src/ingestion/excluded-ranges.ts +97 -0
  72. package/src/ingestion/file-processor.ts +122 -37
  73. package/src/ingestion/frontmatter.ts +35 -7
  74. package/src/ingestion/graph-reconciliation.ts +187 -51
  75. package/src/ingestion/language.ts +66 -61
  76. package/src/ingestion/position.ts +5 -5
  77. package/src/ingestion/prepare-file.ts +50 -29
  78. package/src/ingestion/record-adapter-canonical.ts +37 -26
  79. package/src/ingestion/record-adapter.ts +46 -26
  80. package/src/ingestion/record-container.ts +121 -53
  81. package/src/ingestion/record-path.ts +5 -2
  82. package/src/ingestion/source-availability/darwin-io.ts +10 -7
  83. package/src/ingestion/source-availability/darwin-path.ts +21 -3
  84. package/src/ingestion/source-availability/readers.ts +51 -0
  85. package/src/ingestion/strip.ts +39 -105
  86. package/src/ingestion/sync.ts +692 -386
  87. package/src/ingestion/typed-metadata.ts +10 -4
  88. package/src/ingestion/walker.ts +485 -158
  89. package/src/llm/cache.ts +128 -84
  90. package/src/llm/http-inference.ts +112 -35
  91. package/src/llm/http-policy.ts +101 -0
  92. package/src/llm/httpEmbedding.ts +8 -1
  93. package/src/llm/httpGeneration.ts +5 -1
  94. package/src/llm/httpRerank.ts +5 -1
  95. package/src/llm/inference-scope.ts +15 -2
  96. package/src/llm/lazy-ports.ts +33 -3
  97. package/src/llm/lockfile.ts +34 -7
  98. package/src/llm/model-cleanup.ts +24 -0
  99. package/src/llm/native-worker/client.ts +23 -12
  100. package/src/llm/native-worker/dispatcher.ts +19 -9
  101. package/src/llm/native-worker/embedding-identity.ts +42 -16
  102. package/src/llm/native-worker/entry.ts +2 -1
  103. package/src/llm/native-worker/owner.ts +1 -0
  104. package/src/llm/native-worker/ports.ts +86 -23
  105. package/src/llm/native-worker/protocol.ts +386 -55
  106. package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
  107. package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
  108. package/src/llm/nodeLlamaCpp/generation.ts +194 -30
  109. package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
  110. package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
  111. package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
  112. package/src/llm/types.ts +14 -0
  113. package/src/mcp/context.ts +342 -23
  114. package/src/mcp/http-transport.ts +21 -3
  115. package/src/mcp/tool-profile-types.ts +62 -0
  116. package/src/mcp/tool-profile.ts +32 -56
  117. package/src/mcp/tools/context.ts +5 -1
  118. package/src/mcp/tools/index.ts +269 -191
  119. package/src/mcp/tools/links.ts +7 -5
  120. package/src/mcp/tools/query.ts +60 -37
  121. package/src/mcp/tools/vsearch.ts +25 -14
  122. package/src/pipeline/answer.ts +133 -40
  123. package/src/pipeline/claim-verification.ts +293 -189
  124. package/src/pipeline/claim-verifier.ts +6 -7
  125. package/src/pipeline/egress-lineage.ts +37 -26
  126. package/src/pipeline/exclude.ts +34 -11
  127. package/src/pipeline/expansion.ts +233 -19
  128. package/src/pipeline/filters.ts +169 -33
  129. package/src/pipeline/graph-retrieval.ts +117 -61
  130. package/src/pipeline/hybrid.ts +598 -329
  131. package/src/pipeline/hydration.ts +86 -24
  132. package/src/pipeline/intent.ts +15 -7
  133. package/src/pipeline/owner-fusion.ts +61 -19
  134. package/src/pipeline/query-language.ts +15 -2
  135. package/src/pipeline/rerank.ts +15 -22
  136. package/src/pipeline/search.ts +193 -72
  137. package/src/pipeline/snippet.ts +15 -2
  138. package/src/pipeline/temporal.ts +51 -10
  139. package/src/pipeline/vsearch.ts +250 -152
  140. package/src/publish/attachment-raster.ts +2 -16
  141. package/src/publish/encrypted-export.ts +15 -5
  142. package/src/serve/browse-tree.ts +50 -42
  143. package/src/serve/connectors.ts +2 -1
  144. package/src/serve/context.ts +13 -4
  145. package/src/serve/doc-events.ts +3 -0
  146. package/src/serve/public/app.tsx +49 -21
  147. package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
  148. package/src/serve/public/components/CaptureModal.tsx +14 -10
  149. package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
  150. package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
  151. package/src/serve/public/globals.built.css +1 -1
  152. package/src/serve/public/globals.css +19 -0
  153. package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
  154. package/src/serve/public/lib/metadata-filter.ts +234 -9
  155. package/src/serve/public/pages/Browse.tsx +61 -27
  156. package/src/serve/public/pages/DocView.tsx +44 -25
  157. package/src/serve/public/pages/GraphView.tsx +8 -3
  158. package/src/serve/resident-runtime.ts +199 -48
  159. package/src/serve/routes/api.ts +98 -67
  160. package/src/serve/routes/links.ts +18 -4
  161. package/src/serve/server.ts +1370 -1180
  162. package/src/serve/spa-bundle-source.ts +52 -27
  163. package/src/serve/status.ts +101 -52
  164. package/src/serve/watch-reconciliation-fallback.ts +11 -7
  165. package/src/serve/watch-reconciliation-shared.ts +42 -4
  166. package/src/serve/watch-reconciliation.ts +21 -8
  167. package/src/serve/watch-service-events.ts +7 -1
  168. package/src/serve/watch-service-hosts.ts +3 -1
  169. package/src/serve/watch-service.ts +46 -21
  170. package/src/serve/watch-snapshot-scan.ts +6 -15
  171. package/src/sessions/archive.ts +20 -8
  172. package/src/sessions/sanitize.ts +38 -18
  173. package/src/sessions/service.ts +180 -102
  174. package/src/store/migrations/037-performance-indexes.ts +56 -0
  175. package/src/store/migrations/index.ts +2 -0
  176. package/src/store/sqlite/adapter.ts +1217 -651
  177. package/src/store/sqlite/chunking-policy.ts +15 -1
  178. package/src/store/sqlite/eligibility.ts +110 -70
  179. package/src/store/sqlite/graph-neighbors.ts +71 -46
  180. package/src/store/sqlite/graph-reference-state.ts +27 -3
  181. package/src/store/sqlite/graph-similarity.ts +59 -12
  182. package/src/store/sqlite/metadata-predicate.ts +123 -28
  183. package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
  184. package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
  185. package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
  186. package/src/store/types.ts +32 -0
  187. package/src/store/vector/eligibility.ts +39 -0
  188. package/src/store/vector/lazy.ts +17 -0
  189. package/src/store/vector/partition-index.ts +28 -45
  190. package/src/store/vector/proof-cache.ts +103 -0
  191. package/src/store/vector/sqlite-vec.ts +230 -139
  192. package/src/store/vector/stats.ts +29 -73
  193. package/src/store/vector/status.ts +151 -52
  194. package/src/store/vector/stored-vectors.ts +131 -45
  195. package/src/store/vector/types.ts +10 -0
  196. package/src/store/vector/variant-search.ts +771 -109
  197. package/src/store/vector/variants.ts +495 -139
  198. package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
@@ -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),
@@ -5251,6 +5230,11 @@ async function runDaemonStatus(deps: DaemonStatusDeps): Promise<void> {
5251
5230
  });
5252
5231
  // Persisted by the daemon after every scheduled findings attempt; absent
5253
5232
  // (null) when the pass is not configured. Read from disk, never live.
5233
+ const {
5234
+ findingsRunStatePathForIndex,
5235
+ formatFindingsRunStatusLine,
5236
+ readFindingsRunStatus,
5237
+ } = await import("../core/findings-run-state");
5254
5238
  const findings = await readFindingsRunStatus(
5255
5239
  findingsRunStatePathForIndex(deps.indexName)
5256
5240
  );
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
  }
@@ -146,80 +146,85 @@ const repairCommand = (target: McpTarget, scope: McpScope): string =>
146
146
  export async function checkRegistrationRuntimes(
147
147
  overrides: { cwd?: string; homeDir?: string } = {}
148
148
  ): Promise<RuntimeIssue[]> {
149
- const issues: RuntimeIssue[] = [];
150
149
  const runningBun = realpathOrNull(process.execPath);
151
150
  const versions = new Map<string, Promise<string | null>>();
152
- for (const { target, scope, paths } of resolveAllMcpPaths(
153
- "all",
154
- "all",
155
- overrides
156
- )) {
157
- let entry: unknown;
158
- let configPath = paths.configPath;
159
- try {
160
- configPath = await resolveMcpConfigLocation(paths);
161
- entry = await readRegistrationEntry(configPath, paths.configFormat);
162
- } catch {
163
- continue;
164
- }
165
- const registration =
166
- entry === undefined
167
- ? null
168
- : readExistingRegistration(entry, paths.configFormat);
169
- if (
170
- !registration ||
171
- registration.extra.enabled === false ||
172
- registration.extra.disabled === true
173
- ) {
174
- continue;
175
- }
176
- const { command, args } = registration;
177
- const viaBun = args[0] === "run" && args.length >= 2;
178
- if (!viaBun && !isGnoExecutable(command)) {
179
- continue;
180
- }
181
- const subject = `${getTargetDisplayName(target)} (${scope}) ${configPath}`;
182
- const repair = repairCommand(target, scope);
183
- const launchFiles = viaBun ? [command, args[1] ?? ""] : [command];
184
- const missing = launchFiles.filter((path) => !realpathOrNull(path));
185
- if (missing.length > 0) {
186
- issues.push({
187
- kind: "registration",
188
- severity: "error",
189
- subject,
190
- message: `launches ${missing.join(" and ")}, which no longer exists`,
191
- repair,
192
- });
193
- continue;
194
- }
195
- if (!viaBun) {
196
- // The gno launcher finds Bun on PATH when it starts.
197
- continue;
198
- }
199
- const resolved = realpathOrNull(command) ?? command;
200
- if (!versions.has(resolved)) {
201
- versions.set(resolved, interpreterVersion(command));
202
- }
203
- const version = await versions.get(resolved);
204
- if (version && !bunMeetsFloor(version)) {
205
- issues.push({
206
- kind: "registration",
207
- severity: "error",
208
- subject,
209
- message: `runs Bun ${version} (${command}), older than the supported minimum ${BUN_FLOOR}`,
210
- repair,
211
- });
212
- } else if (resolved !== runningBun) {
213
- issues.push({
214
- kind: "registration",
215
- severity: "info",
216
- subject,
217
- message: `runs ${version ? `Bun ${version}` : "a Bun of unknown version"} (${command}), not this Bun ${Bun.version}`,
218
- repair,
219
- });
220
- }
221
- }
222
- return issues;
151
+ const targets = resolveAllMcpPaths("all", "all", overrides);
152
+
153
+ const perTarget = await Promise.all(
154
+ targets.map(
155
+ async ({ target, scope, paths }): Promise<RuntimeIssue | null> => {
156
+ let entry: unknown;
157
+ let configPath = paths.configPath;
158
+ try {
159
+ configPath = await resolveMcpConfigLocation(paths);
160
+ entry = await readRegistrationEntry(configPath, paths.configFormat);
161
+ } catch {
162
+ return null;
163
+ }
164
+ const registration =
165
+ entry === undefined
166
+ ? null
167
+ : readExistingRegistration(entry, paths.configFormat);
168
+ if (
169
+ !registration ||
170
+ registration.extra.enabled === false ||
171
+ registration.extra.disabled === true
172
+ ) {
173
+ return null;
174
+ }
175
+ const { command, args } = registration;
176
+ const viaBun = args[0] === "run" && args.length >= 2;
177
+ if (!viaBun && !isGnoExecutable(command)) {
178
+ return null;
179
+ }
180
+ const subject = `${getTargetDisplayName(target)} (${scope}) ${configPath}`;
181
+ const repair = repairCommand(target, scope);
182
+ const launchFiles = viaBun ? [command, args[1] ?? ""] : [command];
183
+ const missing = launchFiles.filter((path) => !realpathOrNull(path));
184
+ if (missing.length > 0) {
185
+ return {
186
+ kind: "registration",
187
+ severity: "error",
188
+ subject,
189
+ message: `launches ${missing.join(" and ")}, which no longer exists`,
190
+ repair,
191
+ };
192
+ }
193
+ if (!viaBun) {
194
+ // The gno launcher finds Bun on PATH when it starts.
195
+ return null;
196
+ }
197
+ const resolved = realpathOrNull(command) ?? command;
198
+ let versionPromise = versions.get(resolved);
199
+ if (!versionPromise) {
200
+ versionPromise = interpreterVersion(command);
201
+ versions.set(resolved, versionPromise);
202
+ }
203
+ const version = await versionPromise;
204
+ if (version && !bunMeetsFloor(version)) {
205
+ return {
206
+ kind: "registration",
207
+ severity: "error",
208
+ subject,
209
+ message: `runs Bun ${version} (${command}), older than the supported minimum ${BUN_FLOOR}`,
210
+ repair,
211
+ };
212
+ }
213
+ if (resolved !== runningBun) {
214
+ return {
215
+ kind: "registration",
216
+ severity: "info",
217
+ subject,
218
+ message: `runs ${version ? `Bun ${version}` : "a Bun of unknown version"} (${command}), not this Bun ${Bun.version}`,
219
+ repair,
220
+ };
221
+ }
222
+ return null;
223
+ }
224
+ )
225
+ );
226
+
227
+ return perTarget.filter((issue): issue is RuntimeIssue => issue !== null);
223
228
  }
224
229
 
225
230
  /** The Bun a resident reports through `/api/status`, if it is GNO. */
@@ -269,57 +274,62 @@ function restartSteps(
269
274
  * another GNO version is read through its HTTP status; it is never signalled.
270
275
  */
271
276
  export async function checkResidentRuntimes(): Promise<RuntimeIssue[]> {
272
- const issues: RuntimeIssue[] = [];
273
- for (const kind of ["serve", "daemon"] as const) {
274
- const { pidFile } = resolveProcessPaths(kind);
275
- let payload: Awaited<ReturnType<typeof readPidFile>>;
276
- try {
277
- payload = await readPidFile(pidFile);
278
- } catch {
279
- continue;
280
- }
281
- if (!payload || payload.cmd !== kind || !isProcessAlive(payload.pid)) {
282
- continue;
283
- }
284
- const sameVersion = payload.version === VERSION;
285
- let version = payload.bun_version ?? null;
286
- if (!version && typeof payload.port === "number") {
287
- version = await residentBunVersion(payload.port);
288
- }
289
- const subject = `gno ${kind} (pid ${payload.pid}, GNO ${payload.version})`;
290
- const repair = restartSteps(kind, payload.pid, sameVersion);
291
- if (!version) {
292
- if (!sameVersion) {
293
- issues.push({
294
- kind: "resident",
295
- severity: "info",
296
- subject,
297
- message:
298
- "is running from another GNO version; its Bun version is unknown",
299
- repair,
300
- });
277
+ const perKind = await Promise.all(
278
+ (["serve", "daemon"] as const).map(
279
+ async (kind): Promise<RuntimeIssue | null> => {
280
+ const { pidFile } = resolveProcessPaths(kind);
281
+ let payload: Awaited<ReturnType<typeof readPidFile>>;
282
+ try {
283
+ payload = await readPidFile(pidFile);
284
+ } catch {
285
+ return null;
286
+ }
287
+ if (!payload || payload.cmd !== kind || !isProcessAlive(payload.pid)) {
288
+ return null;
289
+ }
290
+ const sameVersion = payload.version === VERSION;
291
+ let version = payload.bun_version ?? null;
292
+ if (!version && typeof payload.port === "number") {
293
+ version = await residentBunVersion(payload.port);
294
+ }
295
+ const subject = `gno ${kind} (pid ${payload.pid}, GNO ${payload.version})`;
296
+ const repair = restartSteps(kind, payload.pid, sameVersion);
297
+ if (!version) {
298
+ if (!sameVersion) {
299
+ return {
300
+ kind: "resident",
301
+ severity: "info",
302
+ subject,
303
+ message:
304
+ "is running from another GNO version; its Bun version is unknown",
305
+ repair,
306
+ };
307
+ }
308
+ return null;
309
+ }
310
+ if (!bunMeetsFloor(version)) {
311
+ return {
312
+ kind: "resident",
313
+ severity: "error",
314
+ subject,
315
+ message: `runs Bun ${version}, older than the supported minimum ${BUN_FLOOR}`,
316
+ repair,
317
+ };
318
+ }
319
+ if (Bun.semver.order(version, Bun.version) < 0) {
320
+ return {
321
+ kind: "resident",
322
+ severity: "warn",
323
+ subject,
324
+ message: `runs Bun ${version}, older than this Bun ${Bun.version}`,
325
+ repair,
326
+ };
327
+ }
328
+ return null;
301
329
  }
302
- continue;
303
- }
304
- if (!bunMeetsFloor(version)) {
305
- issues.push({
306
- kind: "resident",
307
- severity: "error",
308
- subject,
309
- message: `runs Bun ${version}, older than the supported minimum ${BUN_FLOOR}`,
310
- repair,
311
- });
312
- } else if (Bun.semver.order(version, Bun.version) < 0) {
313
- issues.push({
314
- kind: "resident",
315
- severity: "warn",
316
- subject,
317
- message: `runs Bun ${version}, older than this Bun ${Bun.version}`,
318
- repair,
319
- });
320
- }
321
- }
322
- return issues;
330
+ )
331
+ );
332
+ return perKind.filter((issue): issue is RuntimeIssue => issue !== null);
323
333
  }
324
334
 
325
335
  /** One line per issue for terminal output. */
@@ -12,9 +12,14 @@
12
12
  import type { Config } from "../config/types";
13
13
 
14
14
  import { getIndexDbPath } from "../app/constants";
15
- import { getConfigPaths, loadConfig } from "../config";
15
+ import { getConfigPaths } from "../config";
16
16
  import { assertSessionBinding } from "../sessions/binding";
17
17
  import { SessionsError } from "../sessions/types";
18
+ import {
19
+ isSessionBindingVerifiedInInvocation,
20
+ loadConfigCached,
21
+ markSessionBindingVerifiedInInvocation,
22
+ } from "./config-cache";
18
23
  import { CliError } from "./errors";
19
24
 
20
25
  export async function assertCliSessionBinding(
@@ -23,10 +28,13 @@ export async function assertCliSessionBinding(
23
28
  loadedConfig?: Config
24
29
  ): Promise<void> {
25
30
  const path = configPath ?? getConfigPaths().configFile;
31
+ if (isSessionBindingVerifiedInInvocation(path, indexName)) {
32
+ return;
33
+ }
26
34
  let config = loadedConfig;
27
35
  if (!config) {
28
36
  if (!(await Bun.file(path).exists())) return;
29
- const loaded = await loadConfig(path);
37
+ const loaded = await loadConfigCached(path);
30
38
  // Unreadable configs are reported by the command itself.
31
39
  if (!loaded.ok) return;
32
40
  config = loaded.value;
@@ -38,6 +46,7 @@ export async function assertCliSessionBinding(
38
46
  indexName,
39
47
  dbPath: getIndexDbPath(indexName),
40
48
  });
49
+ markSessionBindingVerifiedInInvocation(path, indexName);
41
50
  } catch (error) {
42
51
  if (error instanceof SessionsError) {
43
52
  throw new CliError("VALIDATION", error.message, {