@gmickel/gno 1.18.0 → 1.20.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 (153) hide show
  1. package/README.md +14 -7
  2. package/assets/skill/SKILL.md +54 -12
  3. package/assets/skill/mcp-reference.md +7 -2
  4. package/assets/skill/recipes/citation-and-provenance.md +32 -9
  5. package/package.json +2 -1
  6. package/spec/AGENTS.md +83 -0
  7. package/spec/CLAUDE.md +83 -0
  8. package/spec/bench-fixture.schema.json +137 -0
  9. package/spec/cli.md +2919 -0
  10. package/spec/db/schema.sql +442 -0
  11. package/spec/evals-agentic.md +592 -0
  12. package/spec/evals.md +1106 -0
  13. package/spec/mcp.md +2279 -0
  14. package/spec/output-schemas/activation-verification.schema.json +515 -0
  15. package/spec/output-schemas/ask.schema.json +564 -0
  16. package/spec/output-schemas/backlinks.schema.json +131 -0
  17. package/spec/output-schemas/bench-result.schema.json +120 -0
  18. package/spec/output-schemas/capture-receipt.schema.json +143 -0
  19. package/spec/output-schemas/claim-verification.schema.json +291 -0
  20. package/spec/output-schemas/collection-list.schema.json +45 -0
  21. package/spec/output-schemas/context-capsule-v1.schema.json +726 -0
  22. package/spec/output-schemas/context-capsule-verification.schema.json +1338 -0
  23. package/spec/output-schemas/context-list.schema.json +21 -0
  24. package/spec/output-schemas/doctor.schema.json +313 -0
  25. package/spec/output-schemas/error.schema.json +30 -0
  26. package/spec/output-schemas/expansion.schema.json +37 -0
  27. package/spec/output-schemas/get.schema.json +140 -0
  28. package/spec/output-schemas/graph-query.schema.json +99 -0
  29. package/spec/output-schemas/graph.schema.json +371 -0
  30. package/spec/output-schemas/links-list.schema.json +186 -0
  31. package/spec/output-schemas/mcp-add-collection-result.schema.json +23 -0
  32. package/spec/output-schemas/mcp-capture-result.schema.json +152 -0
  33. package/spec/output-schemas/mcp-http-error.schema.json +30 -0
  34. package/spec/output-schemas/mcp-job-list.schema.json +58 -0
  35. package/spec/output-schemas/mcp-job-status.schema.json +224 -0
  36. package/spec/output-schemas/mcp-remove-result.schema.json +39 -0
  37. package/spec/output-schemas/mcp-sync-result.schema.json +41 -0
  38. package/spec/output-schemas/mcp-tag-result.schema.json +33 -0
  39. package/spec/output-schemas/models-list.schema.json +93 -0
  40. package/spec/output-schemas/multi-get.schema.json +103 -0
  41. package/spec/output-schemas/process-status.schema.json +119 -0
  42. package/spec/output-schemas/query-diagnose.schema.json +123 -0
  43. package/spec/output-schemas/resident-status.schema.json +154 -0
  44. package/spec/output-schemas/retrieval-trace-common.schema.json +492 -0
  45. package/spec/output-schemas/retrieval-trace-delete.schema.json +16 -0
  46. package/spec/output-schemas/retrieval-trace-export.schema.json +61 -0
  47. package/spec/output-schemas/retrieval-trace-filters.schema.json +139 -0
  48. package/spec/output-schemas/retrieval-trace-judgment.schema.json +15 -0
  49. package/spec/output-schemas/retrieval-trace-list.schema.json +18 -0
  50. package/spec/output-schemas/retrieval-trace-payloads.schema.json +178 -0
  51. package/spec/output-schemas/retrieval-trace-purge.schema.json +31 -0
  52. package/spec/output-schemas/retrieval-trace-qrels.schema.json +303 -0
  53. package/spec/output-schemas/retrieval-trace-replay.schema.json +286 -0
  54. package/spec/output-schemas/retrieval-trace-show.schema.json +69 -0
  55. package/spec/output-schemas/retrieval-trace-summary.schema.json +65 -0
  56. package/spec/output-schemas/search-result.schema.json +154 -0
  57. package/spec/output-schemas/search-results.schema.json +338 -0
  58. package/spec/output-schemas/similar.schema.json +84 -0
  59. package/spec/output-schemas/status.schema.json +676 -0
  60. package/spec/output-schemas/tags-list.schema.json +48 -0
  61. package/src/app/context-runtime-contract.ts +10 -5
  62. package/src/app/context-runtime-input.ts +29 -1
  63. package/src/app/context-runtime-types.ts +7 -0
  64. package/src/app/context-runtime.ts +20 -2
  65. package/src/app/context-surface.ts +4 -0
  66. package/src/app/verified-ask.ts +291 -0
  67. package/src/cli/commands/ask-format.ts +255 -0
  68. package/src/cli/commands/ask.ts +144 -183
  69. package/src/cli/commands/context-build.ts +56 -9
  70. package/src/cli/commands/get.ts +64 -3
  71. package/src/cli/commands/query.ts +62 -23
  72. package/src/cli/commands/replay.ts +140 -0
  73. package/src/cli/commands/search.ts +48 -3
  74. package/src/cli/commands/shared.ts +3 -1
  75. package/src/cli/commands/trace.ts +200 -0
  76. package/src/cli/commands/vsearch.ts +75 -53
  77. package/src/cli/program.ts +287 -1
  78. package/src/config/index.ts +9 -0
  79. package/src/config/retrieval-traces.ts +56 -0
  80. package/src/config/types.ts +4 -0
  81. package/src/core/context-budget.ts +6 -0
  82. package/src/core/context-capsule-retrieval-schema.ts +4 -0
  83. package/src/core/context-capsule-schema.ts +17 -0
  84. package/src/core/context-capsule-validation.ts +3 -2
  85. package/src/core/context-capsule.ts +18 -0
  86. package/src/core/context-compiler.ts +44 -25
  87. package/src/core/context-evidence.ts +6 -0
  88. package/src/core/retrieval-qrels.ts +405 -0
  89. package/src/core/retrieval-replay-candidate.ts +368 -0
  90. package/src/core/retrieval-replay-types.ts +109 -0
  91. package/src/core/retrieval-replay-validation.ts +89 -0
  92. package/src/core/retrieval-replay.ts +441 -0
  93. package/src/core/retrieval-trace-evidence-origin.ts +178 -0
  94. package/src/core/retrieval-trace-export.ts +113 -0
  95. package/src/core/retrieval-trace-filter-normalization.ts +27 -0
  96. package/src/core/retrieval-trace-filters.ts +19 -0
  97. package/src/core/retrieval-trace-management-helpers.ts +247 -0
  98. package/src/core/retrieval-trace-management-types.ts +132 -0
  99. package/src/core/retrieval-trace-management.ts +422 -0
  100. package/src/core/retrieval-trace-request.ts +141 -0
  101. package/src/core/retrieval-trace-session.ts +507 -0
  102. package/src/core/retrieval-trace.ts +472 -0
  103. package/src/llm/errors.ts +10 -1
  104. package/src/llm/httpGeneration.ts +11 -1
  105. package/src/llm/nodeLlamaCpp/generation.ts +54 -10
  106. package/src/llm/types.ts +6 -0
  107. package/src/mcp/tools/ask.ts +228 -0
  108. package/src/mcp/tools/context.ts +87 -15
  109. package/src/mcp/tools/get.ts +35 -1
  110. package/src/mcp/tools/index.ts +83 -0
  111. package/src/mcp/tools/query.ts +95 -64
  112. package/src/mcp/tools/search.ts +36 -13
  113. package/src/mcp/tools/trace.ts +143 -0
  114. package/src/mcp/tools/vsearch.ts +71 -38
  115. package/src/pipeline/answer.ts +167 -26
  116. package/src/pipeline/claim-verification-schema.ts +235 -0
  117. package/src/pipeline/claim-verification.ts +487 -0
  118. package/src/pipeline/claim-verifier.ts +474 -0
  119. package/src/pipeline/graph-retrieval.ts +15 -1
  120. package/src/pipeline/hybrid.ts +151 -43
  121. package/src/pipeline/search.ts +36 -3
  122. package/src/pipeline/trace-metadata.ts +47 -0
  123. package/src/pipeline/types.ts +68 -0
  124. package/src/pipeline/vsearch.ts +101 -38
  125. package/src/sdk/client.ts +415 -73
  126. package/src/sdk/documents.ts +48 -1
  127. package/src/sdk/index.ts +17 -0
  128. package/src/sdk/types.ts +28 -0
  129. package/src/serve/context-capsule.ts +67 -8
  130. package/src/serve/public/app.tsx +12 -1
  131. package/src/serve/public/components/AskVerificationPanel.tsx +189 -0
  132. package/src/serve/public/globals.built.css +1 -1
  133. package/src/serve/public/lib/workspace-tabs.ts +2 -0
  134. package/src/serve/public/pages/Ask.tsx +42 -4
  135. package/src/serve/public/pages/Dashboard.tsx +10 -0
  136. package/src/serve/public/pages/TraceHistory.tsx +478 -0
  137. package/src/serve/public/pages/trace-history-detail.tsx +224 -0
  138. package/src/serve/retrieval-trace.ts +28 -0
  139. package/src/serve/routes/api.ts +508 -68
  140. package/src/serve/routes/traces.ts +156 -0
  141. package/src/serve/server.ts +87 -2
  142. package/src/store/index.ts +31 -0
  143. package/src/store/migrations/014-retrieval-traces.ts +303 -0
  144. package/src/store/migrations/index.ts +2 -0
  145. package/src/store/retrieval-trace-codec.ts +384 -0
  146. package/src/store/sqlite/adapter.ts +153 -1
  147. package/src/store/sqlite/retrieval-trace-management-store.ts +341 -0
  148. package/src/store/sqlite/retrieval-trace-retention.ts +349 -0
  149. package/src/store/sqlite/retrieval-trace-rows.ts +267 -0
  150. package/src/store/sqlite/retrieval-trace-store.ts +515 -0
  151. package/src/store/types.ts +297 -0
  152. package/src/store/vector/sqlite-vec.ts +76 -1
  153. package/src/store/vector/types.ts +1 -1
@@ -26,6 +26,8 @@ import {
26
26
  shouldSortByRecency,
27
27
  type TemporalRange,
28
28
  } from "./temporal";
29
+ import { attachSearchResultPlannerMetadata } from "./trace-metadata";
30
+ import { SEARCH_RESULT_PLANNER_METADATA } from "./types";
29
31
 
30
32
  // ─────────────────────────────────────────────────────────────────────────────
31
33
  // Score Normalization
@@ -76,6 +78,7 @@ export async function searchVectorWithEmbedding(
76
78
  queryEmbedding: Float32Array,
77
79
  options: SearchOptions = {}
78
80
  ): Promise<ReturnType<typeof ok<SearchResults>>> {
81
+ const traceStartedAt = options.traceSession ? performance.now() : 0;
79
82
  const { store, vectorIndex } = deps;
80
83
  const limit = options.limit ?? 20;
81
84
  const minScore = options.minScore ?? 0;
@@ -102,6 +105,7 @@ export async function searchVectorWithEmbedding(
102
105
  retrievalLimit,
103
106
  {
104
107
  minScore,
108
+ allowedMirrorHashes: options.retrievalScope?.allowedMirrorHashes,
105
109
  }
106
110
  );
107
111
 
@@ -124,6 +128,7 @@ export async function searchVectorWithEmbedding(
124
128
  // Cache docs to avoid N+1 queries (filtered by collection and tags)
125
129
  const docByMirrorHash = await buildDocumentMap(store, {
126
130
  collection: options.collection,
131
+ relPathPrefix: options.retrievalScope?.relPathPrefix,
127
132
  tagsAll: options.tagsAll,
128
133
  tagsAny: options.tagsAny,
129
134
  since: temporalRange.since,
@@ -214,6 +219,7 @@ export async function searchVectorWithEmbedding(
214
219
  language: chunk.language,
215
220
  startLine: chunk.startLine,
216
221
  endLine: chunk.endLine,
222
+ seq: chunk.seq,
217
223
  },
218
224
  score,
219
225
  });
@@ -223,40 +229,56 @@ export async function searchVectorWithEmbedding(
223
229
 
224
230
  const collectionPath = collectionPaths.get(doc.collection);
225
231
 
226
- results.push({
227
- docid: doc.docid,
228
- score,
229
- uri: doc.uri,
230
- title: doc.title ?? undefined,
231
- contentType: doc.contentType ?? undefined,
232
- categories: doc.categories ?? undefined,
233
- line: chunk.startLine,
234
- snippet: chunk.text,
235
- snippetLanguage: chunk.language ?? undefined,
236
- snippetRange: {
237
- startLine: chunk.startLine,
238
- endLine: chunk.endLine,
239
- },
240
- source: {
241
- relPath: doc.relPath,
242
- absPath: collectionPath
243
- ? `${collectionPath}/${doc.relPath}`
244
- : undefined,
245
- mime: doc.sourceMime,
246
- ext: doc.sourceExt,
247
- modifiedAt: doc.sourceMtime,
248
- documentDate: doc.frontmatterDate ?? undefined,
249
- sizeBytes: doc.sourceSize,
250
- sourceHash: doc.sourceHash,
251
- },
252
- conversion: doc.mirrorHash
253
- ? {
254
- mirrorHash: doc.mirrorHash,
255
- converterId: doc.converterId ?? undefined,
256
- converterVersion: doc.converterVersion ?? undefined,
257
- }
258
- : undefined,
259
- });
232
+ results.push(
233
+ attachSearchResultPlannerMetadata(
234
+ {
235
+ docid: doc.docid,
236
+ score,
237
+ uri: doc.uri,
238
+ title: doc.title ?? undefined,
239
+ contentType: doc.contentType ?? undefined,
240
+ categories: doc.categories ?? undefined,
241
+ line: chunk.startLine,
242
+ snippet: chunk.text,
243
+ snippetLanguage: chunk.language ?? undefined,
244
+ snippetRange: {
245
+ startLine: chunk.startLine,
246
+ endLine: chunk.endLine,
247
+ },
248
+ source: {
249
+ relPath: doc.relPath,
250
+ absPath: collectionPath
251
+ ? `${collectionPath}/${doc.relPath}`
252
+ : undefined,
253
+ mime: doc.sourceMime,
254
+ ext: doc.sourceExt,
255
+ modifiedAt: doc.sourceMtime,
256
+ documentDate: doc.frontmatterDate ?? undefined,
257
+ sizeBytes: doc.sourceSize,
258
+ sourceHash: doc.sourceHash,
259
+ },
260
+ conversion: doc.mirrorHash
261
+ ? {
262
+ mirrorHash: doc.mirrorHash,
263
+ converterId: doc.converterId ?? undefined,
264
+ converterVersion: doc.converterVersion ?? undefined,
265
+ }
266
+ : undefined,
267
+ },
268
+ {
269
+ retrievalRank: 0,
270
+ mirrorHash: vec.mirrorHash,
271
+ seq: chunk.seq,
272
+ sources: ["vector"],
273
+ graphExpanded: false,
274
+ startLine: chunk.startLine,
275
+ endLine: chunk.endLine,
276
+ passageHash: new Bun.CryptoHasher("sha256")
277
+ .update(chunk.text)
278
+ .digest("hex"),
279
+ }
280
+ )
281
+ );
260
282
  }
261
283
 
262
284
  // For --full, fetch full content and build results
@@ -279,7 +301,7 @@ export async function searchVectorWithEmbedding(
279
301
 
280
302
  const collectionPath = collectionPaths.get(doc.collection);
281
303
 
282
- results.push({
304
+ const result: SearchResult = {
283
305
  docid: doc.docid,
284
306
  score,
285
307
  uri: doc.uri,
@@ -312,7 +334,23 @@ export async function searchVectorWithEmbedding(
312
334
  converterVersion: doc.converterVersion ?? undefined,
313
335
  }
314
336
  : undefined,
315
- });
337
+ };
338
+ results.push(
339
+ doc.mirrorHash
340
+ ? attachSearchResultPlannerMetadata(result, {
341
+ retrievalRank: 0,
342
+ mirrorHash: doc.mirrorHash,
343
+ seq: chunk.seq,
344
+ sources: ["vector"],
345
+ graphExpanded: false,
346
+ startLine: chunk.startLine,
347
+ endLine: chunk.endLine,
348
+ passageHash: new Bun.CryptoHasher("sha256")
349
+ .update(chunk.text)
350
+ .digest("hex"),
351
+ })
352
+ : result
353
+ );
316
354
  }
317
355
  }
318
356
 
@@ -334,9 +372,13 @@ export async function searchVectorWithEmbedding(
334
372
  }
335
373
 
336
374
  const finalResults = results.slice(0, limit);
375
+ for (const [index, result] of finalResults.entries()) {
376
+ const metadata = result[SEARCH_RESULT_PLANNER_METADATA];
377
+ if (metadata) metadata.retrievalRank = index + 1;
378
+ }
337
379
  await attachSearchResultContexts(store, finalResults);
338
380
 
339
- return ok({
381
+ const output: SearchResults = {
340
382
  results: finalResults,
341
383
  meta: {
342
384
  query,
@@ -353,7 +395,19 @@ export async function searchVectorWithEmbedding(
353
395
  author: options.author,
354
396
  queryLanguage,
355
397
  },
356
- });
398
+ };
399
+ const traceResult = await options.traceSession?.recordRetrieval(
400
+ output,
401
+ performance.now() - traceStartedAt
402
+ );
403
+ if (traceResult && !traceResult.ok) {
404
+ return err(
405
+ "QUERY_FAILED",
406
+ `Trace recording failed: ${traceResult.error.message}`,
407
+ traceResult.error.cause
408
+ );
409
+ }
410
+ return ok(output);
357
411
  }
358
412
 
359
413
  /**
@@ -397,6 +451,7 @@ interface ChunkInfo {
397
451
  language: string | null;
398
452
  startLine: number;
399
453
  endLine: number;
454
+ seq: number;
400
455
  }
401
456
 
402
457
  interface DocumentInfo {
@@ -425,6 +480,7 @@ interface DocumentInfo {
425
480
 
426
481
  interface DocumentMapOptions {
427
482
  collection?: string;
483
+ relPathPrefix?: string;
428
484
  tagsAll?: string[];
429
485
  tagsAny?: string[];
430
486
  since?: string;
@@ -513,6 +569,13 @@ async function buildDocumentMap(
513
569
  }
514
570
 
515
571
  for (const doc of activeDocs) {
572
+ if (
573
+ options.relPathPrefix !== undefined &&
574
+ doc.relPath !== options.relPathPrefix &&
575
+ !doc.relPath.startsWith(`${options.relPathPrefix}/`)
576
+ ) {
577
+ continue;
578
+ }
516
579
  if (!isWithinTemporalRange(doc.sourceMtime, temporalRange)) {
517
580
  continue;
518
581
  }