@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
@@ -0,0 +1,255 @@
1
+ import type { AskResult } from "../../pipeline/types";
2
+ import type { AskCommandOptions, AskCommandResult } from "./ask";
3
+
4
+ interface FormatOptions {
5
+ showSources?: boolean;
6
+ }
7
+
8
+ const exactSpan = (uri: string, startLine: number, endLine: number): string =>
9
+ `${uri}:L${startLine}${startLine === endLine ? "" : `-L${endLine}`}`;
10
+
11
+ const replaceEvidenceMarkers = (value: string, data: AskResult): string => {
12
+ const citationNumbers = new Map(
13
+ (data.citations ?? []).flatMap((citation, index) =>
14
+ citation.evidenceId ? [[citation.evidenceId, index + 1] as const] : []
15
+ )
16
+ );
17
+ return value.replace(
18
+ /\[evidence:([a-f0-9]{64})\]/g,
19
+ (marker, evidenceId: string) => {
20
+ const citationNumber = citationNumbers.get(evidenceId);
21
+ return citationNumber === undefined ? marker : `[${citationNumber}]`;
22
+ }
23
+ );
24
+ };
25
+
26
+ const readableAnswer = (data: AskResult): string | undefined =>
27
+ data.answer ? replaceEvidenceMarkers(data.answer, data) : undefined;
28
+
29
+ const capsuleEvidence = (data: AskResult) =>
30
+ data.verification?.capsule.evidence ?? [];
31
+
32
+ const terminalVerification = (
33
+ verification: NonNullable<AskResult["verification"]>
34
+ ): string[] => {
35
+ const { claims, capsule, semantic } = verification;
36
+ const lines = [
37
+ "Verification:",
38
+ ` Answer status: ${claims.answerStatus}`,
39
+ ` Coverage: ${claims.coverage.supportedClaims}/${claims.coverage.totalClaims} supported (${(claims.coverage.supportedRatio * 100).toFixed(0)}%)`,
40
+ ` Semantic verifier: ${semantic.status} (${semantic.reason})`,
41
+ ];
42
+ if (claims.abstentionReason) {
43
+ lines.push(` Abstention: ${claims.abstentionReason}`);
44
+ }
45
+ for (const [index, claim] of claims.claims.entries()) {
46
+ lines.push(` Claim ${index + 1} [${claim.status}]: ${claim.text}`);
47
+ for (const evidence of claim.evidence) {
48
+ lines.push(
49
+ ` Evidence: ${exactSpan(evidence.uri, evidence.startLine, evidence.endLine)}`
50
+ );
51
+ }
52
+ }
53
+ const degraded = Object.entries(capsule.retrieval.capabilityStates).filter(
54
+ ([, state]) => state.requested && state.outcome !== "used"
55
+ );
56
+ for (const [name, state] of degraded) {
57
+ const reasons =
58
+ state.fallbackReasons.length > 0
59
+ ? ` (${state.fallbackReasons.join(", ")})`
60
+ : "";
61
+ lines.push(` Capability: ${name} ${state.outcome}${reasons}`);
62
+ }
63
+ for (const facet of capsule.coverage.unresolvedFacets) {
64
+ lines.push(` Gap: unresolved facet ${facet}`);
65
+ }
66
+ for (const gap of capsule.coverage.gaps) {
67
+ lines.push(` Gap: ${gap.facet} (${gap.code})`);
68
+ }
69
+ lines.push("");
70
+ return lines;
71
+ };
72
+
73
+ const markdownVerification = (
74
+ verification: NonNullable<AskResult["verification"]>
75
+ ): string[] => {
76
+ const { claims, capsule, semantic } = verification;
77
+ const lines = [
78
+ "## Verification",
79
+ "",
80
+ `- Answer status: **${claims.answerStatus}**`,
81
+ `- Coverage: **${claims.coverage.supportedClaims}/${claims.coverage.totalClaims}** supported (${(claims.coverage.supportedRatio * 100).toFixed(0)}%)`,
82
+ `- Semantic verifier: **${semantic.status}** (\`${semantic.reason}\`)`,
83
+ ];
84
+ if (claims.abstentionReason) {
85
+ lines.push(`- Abstention: \`${claims.abstentionReason}\``);
86
+ }
87
+ lines.push("");
88
+ for (const [index, claim] of claims.claims.entries()) {
89
+ lines.push(`### Claim ${index + 1}: ${claim.status}`);
90
+ lines.push("");
91
+ lines.push(claim.text);
92
+ lines.push("");
93
+ for (const evidence of claim.evidence) {
94
+ lines.push(
95
+ `- Evidence: \`${exactSpan(evidence.uri, evidence.startLine, evidence.endLine)}\``
96
+ );
97
+ }
98
+ if (claim.evidence.length === 0) {
99
+ lines.push("- Evidence: none retained");
100
+ }
101
+ lines.push("");
102
+ }
103
+ const degraded = Object.entries(capsule.retrieval.capabilityStates).filter(
104
+ ([, state]) => state.requested && state.outcome !== "used"
105
+ );
106
+ if (
107
+ degraded.length > 0 ||
108
+ capsule.coverage.unresolvedFacets.length > 0 ||
109
+ capsule.coverage.gaps.length > 0
110
+ ) {
111
+ lines.push("### Gaps and degradation");
112
+ lines.push("");
113
+ for (const [name, state] of degraded) {
114
+ const reasons =
115
+ state.fallbackReasons.length > 0
116
+ ? `: ${state.fallbackReasons.join(", ")}`
117
+ : "";
118
+ lines.push(`- Capability \`${name}\`: ${state.outcome}${reasons}`);
119
+ }
120
+ for (const facet of capsule.coverage.unresolvedFacets) {
121
+ lines.push(`- Unresolved facet: ${facet}`);
122
+ }
123
+ for (const gap of capsule.coverage.gaps) {
124
+ lines.push(`- Gap: ${gap.facet} (\`${gap.code}\`)`);
125
+ }
126
+ lines.push("");
127
+ }
128
+ return lines;
129
+ };
130
+
131
+ const formatTerminal = (data: AskResult, opts: FormatOptions = {}): string => {
132
+ const lines: string[] = [];
133
+ const hasAnswer = Boolean(data.answer);
134
+ const answer = readableAnswer(data);
135
+ if (answer) {
136
+ lines.push("Answer:", answer, "");
137
+ }
138
+ if (data.verification) {
139
+ lines.push(...terminalVerification(data.verification));
140
+ }
141
+ if (data.citations && data.citations.length > 0) {
142
+ lines.push("Cited Sources:");
143
+ for (const [index, citation] of data.citations.entries()) {
144
+ const range =
145
+ citation.startLine === undefined
146
+ ? ""
147
+ : `:L${citation.startLine}${citation.endLine === undefined || citation.endLine === citation.startLine ? "" : `-L${citation.endLine}`}`;
148
+ lines.push(` [${index + 1}] ${citation.uri}${range}`);
149
+ }
150
+ lines.push("");
151
+ }
152
+ const showAllSources = !hasAnswer || opts.showSources;
153
+ const verifiedEvidence = capsuleEvidence(data);
154
+ if (showAllSources && verifiedEvidence.length > 0) {
155
+ lines.push("All Capsule Evidence:");
156
+ for (const evidence of verifiedEvidence) {
157
+ lines.push(
158
+ ` [${evidence.docid}] ${exactSpan(evidence.uri, evidence.startLine, evidence.endLine)}`
159
+ );
160
+ if (evidence.title) lines.push(` ${evidence.title}`);
161
+ }
162
+ } else if (showAllSources && data.results.length > 0) {
163
+ lines.push(hasAnswer ? "All Retrieved Sources:" : "Sources:");
164
+ for (const result of data.results) {
165
+ lines.push(` [${result.docid}] ${result.uri}`);
166
+ if (result.title) lines.push(` ${result.title}`);
167
+ }
168
+ } else if (hasAnswer && data.results.length > 0) {
169
+ const citedCount = data.citations?.length ?? 0;
170
+ if (data.results.length > citedCount) {
171
+ lines.push(
172
+ `(${data.results.length} sources retrieved, use --show-sources to list all)`
173
+ );
174
+ }
175
+ }
176
+ if (!data.answer && data.results.length === 0) {
177
+ lines.push("No relevant sources found.");
178
+ }
179
+ return replaceEvidenceMarkers(lines.join("\n"), data);
180
+ };
181
+
182
+ const formatMarkdown = (data: AskResult, opts: FormatOptions = {}): string => {
183
+ const lines: string[] = [`# Question: ${data.query}`, ""];
184
+ const hasAnswer = Boolean(data.answer);
185
+ const answer = readableAnswer(data);
186
+ if (answer) {
187
+ lines.push("## Answer", "", answer, "");
188
+ }
189
+ if (data.verification) {
190
+ lines.push(...markdownVerification(data.verification));
191
+ }
192
+ if (data.citations && data.citations.length > 0) {
193
+ lines.push("## Cited Sources", "");
194
+ for (const [index, citation] of data.citations.entries()) {
195
+ const range =
196
+ citation.startLine === undefined
197
+ ? ""
198
+ : `:L${citation.startLine}${citation.endLine === undefined || citation.endLine === citation.startLine ? "" : `-L${citation.endLine}`}`;
199
+ lines.push(`**[${index + 1}]** \`${citation.uri}${range}\``);
200
+ }
201
+ lines.push("");
202
+ }
203
+ if (!hasAnswer || opts.showSources) {
204
+ const verifiedEvidence = capsuleEvidence(data);
205
+ lines.push(
206
+ verifiedEvidence.length > 0
207
+ ? "## All Capsule Evidence"
208
+ : hasAnswer
209
+ ? "## All Retrieved Sources"
210
+ : "## Sources",
211
+ ""
212
+ );
213
+ if (verifiedEvidence.length > 0) {
214
+ for (const [index, evidence] of verifiedEvidence.entries()) {
215
+ lines.push(
216
+ `${index + 1}. **${evidence.title || evidence.uri}**`,
217
+ ` - URI: \`${exactSpan(evidence.uri, evidence.startLine, evidence.endLine)}\``
218
+ );
219
+ }
220
+ } else {
221
+ for (const [index, result] of data.results.entries()) {
222
+ lines.push(
223
+ `${index + 1}. **${result.title || result.source.relPath}**`
224
+ );
225
+ lines.push(` - URI: \`${result.uri}\``);
226
+ lines.push(` - Score: ${result.score.toFixed(2)}`);
227
+ }
228
+ if (data.results.length === 0) lines.push("*No relevant sources found.*");
229
+ }
230
+ }
231
+ lines.push(
232
+ "",
233
+ "---",
234
+ `*Mode: ${data.mode} | Expanded: ${data.meta.expanded} | Reranked: ${data.meta.reranked}*`
235
+ );
236
+ return replaceEvidenceMarkers(lines.join("\n"), data);
237
+ };
238
+
239
+ export function formatAsk(
240
+ result: AskCommandResult,
241
+ options: AskCommandOptions
242
+ ): string {
243
+ if (!result.success) {
244
+ return options.json
245
+ ? JSON.stringify({
246
+ error: { code: "ASK_FAILED", message: result.error },
247
+ })
248
+ : `Error: ${result.error}`;
249
+ }
250
+ if (options.json) return JSON.stringify(result.data, null, 2);
251
+ const formatOptions = { showSources: options.showSources };
252
+ return options.md
253
+ ? formatMarkdown(result.data, formatOptions)
254
+ : formatTerminal(result.data, formatOptions);
255
+ }