@gmickel/gno 1.18.0 → 1.19.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 (129) hide show
  1. package/README.md +5 -3
  2. package/assets/skill/SKILL.md +27 -0
  3. package/package.json +2 -1
  4. package/spec/AGENTS.md +83 -0
  5. package/spec/CLAUDE.md +83 -0
  6. package/spec/bench-fixture.schema.json +137 -0
  7. package/spec/cli.md +2894 -0
  8. package/spec/db/schema.sql +442 -0
  9. package/spec/evals-agentic.md +510 -0
  10. package/spec/evals.md +1106 -0
  11. package/spec/mcp.md +2229 -0
  12. package/spec/output-schemas/activation-verification.schema.json +515 -0
  13. package/spec/output-schemas/ask.schema.json +366 -0
  14. package/spec/output-schemas/backlinks.schema.json +131 -0
  15. package/spec/output-schemas/bench-result.schema.json +120 -0
  16. package/spec/output-schemas/capture-receipt.schema.json +143 -0
  17. package/spec/output-schemas/collection-list.schema.json +45 -0
  18. package/spec/output-schemas/context-capsule-v1.schema.json +691 -0
  19. package/spec/output-schemas/context-capsule-verification.schema.json +1338 -0
  20. package/spec/output-schemas/context-list.schema.json +21 -0
  21. package/spec/output-schemas/doctor.schema.json +313 -0
  22. package/spec/output-schemas/error.schema.json +30 -0
  23. package/spec/output-schemas/expansion.schema.json +37 -0
  24. package/spec/output-schemas/get.schema.json +140 -0
  25. package/spec/output-schemas/graph-query.schema.json +99 -0
  26. package/spec/output-schemas/graph.schema.json +371 -0
  27. package/spec/output-schemas/links-list.schema.json +186 -0
  28. package/spec/output-schemas/mcp-add-collection-result.schema.json +23 -0
  29. package/spec/output-schemas/mcp-capture-result.schema.json +152 -0
  30. package/spec/output-schemas/mcp-http-error.schema.json +30 -0
  31. package/spec/output-schemas/mcp-job-list.schema.json +58 -0
  32. package/spec/output-schemas/mcp-job-status.schema.json +224 -0
  33. package/spec/output-schemas/mcp-remove-result.schema.json +39 -0
  34. package/spec/output-schemas/mcp-sync-result.schema.json +41 -0
  35. package/spec/output-schemas/mcp-tag-result.schema.json +33 -0
  36. package/spec/output-schemas/models-list.schema.json +93 -0
  37. package/spec/output-schemas/multi-get.schema.json +103 -0
  38. package/spec/output-schemas/process-status.schema.json +119 -0
  39. package/spec/output-schemas/query-diagnose.schema.json +123 -0
  40. package/spec/output-schemas/resident-status.schema.json +154 -0
  41. package/spec/output-schemas/retrieval-trace-common.schema.json +492 -0
  42. package/spec/output-schemas/retrieval-trace-delete.schema.json +16 -0
  43. package/spec/output-schemas/retrieval-trace-export.schema.json +61 -0
  44. package/spec/output-schemas/retrieval-trace-filters.schema.json +139 -0
  45. package/spec/output-schemas/retrieval-trace-judgment.schema.json +15 -0
  46. package/spec/output-schemas/retrieval-trace-list.schema.json +18 -0
  47. package/spec/output-schemas/retrieval-trace-payloads.schema.json +178 -0
  48. package/spec/output-schemas/retrieval-trace-purge.schema.json +31 -0
  49. package/spec/output-schemas/retrieval-trace-qrels.schema.json +303 -0
  50. package/spec/output-schemas/retrieval-trace-replay.schema.json +286 -0
  51. package/spec/output-schemas/retrieval-trace-show.schema.json +69 -0
  52. package/spec/output-schemas/retrieval-trace-summary.schema.json +65 -0
  53. package/spec/output-schemas/search-result.schema.json +154 -0
  54. package/spec/output-schemas/search-results.schema.json +338 -0
  55. package/spec/output-schemas/similar.schema.json +84 -0
  56. package/spec/output-schemas/status.schema.json +676 -0
  57. package/spec/output-schemas/tags-list.schema.json +48 -0
  58. package/src/app/context-runtime-types.ts +3 -0
  59. package/src/app/context-runtime.ts +15 -1
  60. package/src/cli/commands/ask.ts +106 -36
  61. package/src/cli/commands/context-build.ts +56 -9
  62. package/src/cli/commands/get.ts +64 -3
  63. package/src/cli/commands/query.ts +62 -23
  64. package/src/cli/commands/replay.ts +140 -0
  65. package/src/cli/commands/search.ts +48 -3
  66. package/src/cli/commands/shared.ts +3 -1
  67. package/src/cli/commands/trace.ts +200 -0
  68. package/src/cli/commands/vsearch.ts +75 -53
  69. package/src/cli/program.ts +255 -0
  70. package/src/config/index.ts +9 -0
  71. package/src/config/retrieval-traces.ts +56 -0
  72. package/src/config/types.ts +4 -0
  73. package/src/core/context-compiler.ts +11 -4
  74. package/src/core/retrieval-qrels.ts +405 -0
  75. package/src/core/retrieval-replay-candidate.ts +368 -0
  76. package/src/core/retrieval-replay-types.ts +109 -0
  77. package/src/core/retrieval-replay-validation.ts +89 -0
  78. package/src/core/retrieval-replay.ts +441 -0
  79. package/src/core/retrieval-trace-evidence-origin.ts +175 -0
  80. package/src/core/retrieval-trace-export.ts +113 -0
  81. package/src/core/retrieval-trace-filter-normalization.ts +27 -0
  82. package/src/core/retrieval-trace-filters.ts +19 -0
  83. package/src/core/retrieval-trace-management-helpers.ts +247 -0
  84. package/src/core/retrieval-trace-management-types.ts +132 -0
  85. package/src/core/retrieval-trace-management.ts +422 -0
  86. package/src/core/retrieval-trace-request.ts +141 -0
  87. package/src/core/retrieval-trace-session.ts +494 -0
  88. package/src/core/retrieval-trace.ts +472 -0
  89. package/src/mcp/tools/context.ts +59 -8
  90. package/src/mcp/tools/get.ts +35 -1
  91. package/src/mcp/tools/index.ts +74 -0
  92. package/src/mcp/tools/query.ts +95 -64
  93. package/src/mcp/tools/search.ts +36 -13
  94. package/src/mcp/tools/trace.ts +143 -0
  95. package/src/mcp/tools/vsearch.ts +71 -38
  96. package/src/pipeline/answer.ts +167 -26
  97. package/src/pipeline/graph-retrieval.ts +15 -1
  98. package/src/pipeline/hybrid.ts +151 -43
  99. package/src/pipeline/search.ts +36 -3
  100. package/src/pipeline/trace-metadata.ts +47 -0
  101. package/src/pipeline/types.ts +43 -0
  102. package/src/pipeline/vsearch.ts +101 -38
  103. package/src/sdk/client.ts +380 -71
  104. package/src/sdk/documents.ts +48 -1
  105. package/src/sdk/index.ts +17 -0
  106. package/src/sdk/types.ts +28 -0
  107. package/src/serve/context-capsule.ts +67 -8
  108. package/src/serve/public/app.tsx +12 -1
  109. package/src/serve/public/globals.built.css +1 -1
  110. package/src/serve/public/lib/workspace-tabs.ts +2 -0
  111. package/src/serve/public/pages/Dashboard.tsx +10 -0
  112. package/src/serve/public/pages/TraceHistory.tsx +478 -0
  113. package/src/serve/public/pages/trace-history-detail.tsx +224 -0
  114. package/src/serve/retrieval-trace.ts +28 -0
  115. package/src/serve/routes/api.ts +366 -72
  116. package/src/serve/routes/traces.ts +156 -0
  117. package/src/serve/server.ts +87 -2
  118. package/src/store/index.ts +31 -0
  119. package/src/store/migrations/014-retrieval-traces.ts +303 -0
  120. package/src/store/migrations/index.ts +2 -0
  121. package/src/store/retrieval-trace-codec.ts +384 -0
  122. package/src/store/sqlite/adapter.ts +153 -1
  123. package/src/store/sqlite/retrieval-trace-management-store.ts +341 -0
  124. package/src/store/sqlite/retrieval-trace-retention.ts +349 -0
  125. package/src/store/sqlite/retrieval-trace-rows.ts +267 -0
  126. package/src/store/sqlite/retrieval-trace-store.ts +515 -0
  127. package/src/store/types.ts +297 -0
  128. package/src/store/vector/sqlite-vec.ts +76 -1
  129. package/src/store/vector/types.ts +1 -1
@@ -0,0 +1,267 @@
1
+ /** SQLite row codecs and shared validation for retrieval trace storage. */
2
+
3
+ import type { Database } from "bun:sqlite";
4
+
5
+ import type {
6
+ RetrievalTraceDeleteCounts,
7
+ RetrievalTraceEventInput,
8
+ RetrievalTraceEventRow,
9
+ RetrievalTraceExportInput,
10
+ RetrievalTraceExportRow,
11
+ RetrievalTraceJudgmentInput,
12
+ RetrievalTraceJudgmentRow,
13
+ RetrievalTraceRow,
14
+ RetrievalTraceRunInput,
15
+ RetrievalTraceRunRow,
16
+ StoreResult,
17
+ } from "../types";
18
+
19
+ import { traceJsonObjectSchema } from "../retrieval-trace-codec";
20
+ import { err } from "../types";
21
+
22
+ export interface DbRetrievalTraceRow {
23
+ trace_id: string;
24
+ schema_version: "1.0";
25
+ redaction_mode: "metadata" | "replay";
26
+ replay_capable: number;
27
+ query_text: string | null;
28
+ query_digest: string | null;
29
+ query_shape_json: string;
30
+ goal_text: string | null;
31
+ goal_digest: string | null;
32
+ goal_shape_json: string;
33
+ filters_json: string;
34
+ pipeline_fingerprint: string;
35
+ model_fingerprint: string;
36
+ config_fingerprint: string;
37
+ index_fingerprint: string;
38
+ status: RetrievalTraceRow["status"];
39
+ created_at_ms: number;
40
+ updated_at_ms: number;
41
+ expires_at_ms: number;
42
+ byte_size: number;
43
+ creation_digest: string;
44
+ }
45
+
46
+ export interface DbRetrievalTraceRunRow {
47
+ run_id: string;
48
+ trace_id: string;
49
+ idempotency_key: string;
50
+ kind: RetrievalTraceRunInput["kind"];
51
+ payload_json: string;
52
+ payload_bytes: number;
53
+ canonical_digest: string;
54
+ created_at_ms: number;
55
+ }
56
+
57
+ export interface DbRetrievalTraceEventRow {
58
+ event_id: string;
59
+ trace_id: string;
60
+ run_id: string | null;
61
+ idempotency_key: string;
62
+ kind: RetrievalTraceEventInput["kind"];
63
+ payload_json: string;
64
+ payload_bytes: number;
65
+ canonical_digest: string;
66
+ created_at_ms: number;
67
+ }
68
+
69
+ export interface DbRetrievalTraceJudgmentRow {
70
+ judgment_id: string;
71
+ trace_id: string;
72
+ run_id: string | null;
73
+ idempotency_key: string;
74
+ label: RetrievalTraceJudgmentInput["label"];
75
+ target_kind: RetrievalTraceJudgmentInput["targetKind"];
76
+ target_ref: string;
77
+ target_json: string;
78
+ target_bytes: number;
79
+ canonical_digest: string;
80
+ created_at_ms: number;
81
+ }
82
+
83
+ export interface DbRetrievalTraceExportRow {
84
+ export_id: string;
85
+ trace_id: string;
86
+ format: RetrievalTraceExportInput["format"];
87
+ artifact_hash: string;
88
+ created_at_ms: number;
89
+ }
90
+
91
+ const parseJsonObject = (raw: string): Record<string, unknown> =>
92
+ traceJsonObjectSchema.parse(JSON.parse(raw));
93
+
94
+ export const mapTraceRow = (row: DbRetrievalTraceRow): RetrievalTraceRow => ({
95
+ traceId: row.trace_id,
96
+ schemaVersion: row.schema_version,
97
+ redactionMode: row.redaction_mode,
98
+ replayCapable: row.replay_capable === 1,
99
+ queryText: row.query_text,
100
+ queryDigest: row.query_digest,
101
+ queryShape: JSON.parse(
102
+ row.query_shape_json
103
+ ) as RetrievalTraceRow["queryShape"],
104
+ goalText: row.goal_text,
105
+ goalDigest: row.goal_digest,
106
+ goalShape: JSON.parse(row.goal_shape_json) as RetrievalTraceRow["goalShape"],
107
+ filters: parseJsonObject(row.filters_json),
108
+ fingerprints: {
109
+ pipeline: row.pipeline_fingerprint,
110
+ model: row.model_fingerprint,
111
+ config: row.config_fingerprint,
112
+ index: row.index_fingerprint,
113
+ },
114
+ status: row.status,
115
+ createdAtMs: row.created_at_ms,
116
+ updatedAtMs: row.updated_at_ms,
117
+ expiresAtMs: row.expires_at_ms,
118
+ byteSize: row.byte_size,
119
+ creationDigest: row.creation_digest,
120
+ });
121
+
122
+ export const mapRunRow = (
123
+ row: DbRetrievalTraceRunRow
124
+ ): RetrievalTraceRunRow => ({
125
+ runId: row.run_id,
126
+ traceId: row.trace_id,
127
+ idempotencyKey: row.idempotency_key,
128
+ kind: row.kind,
129
+ payload: parseJsonObject(row.payload_json),
130
+ payloadBytes: row.payload_bytes,
131
+ canonicalDigest: row.canonical_digest,
132
+ createdAtMs: row.created_at_ms,
133
+ });
134
+
135
+ export const mapEventRow = (
136
+ row: DbRetrievalTraceEventRow
137
+ ): RetrievalTraceEventRow => ({
138
+ eventId: row.event_id,
139
+ traceId: row.trace_id,
140
+ runId: row.run_id,
141
+ idempotencyKey: row.idempotency_key,
142
+ kind: row.kind,
143
+ payload: parseJsonObject(row.payload_json),
144
+ payloadBytes: row.payload_bytes,
145
+ canonicalDigest: row.canonical_digest,
146
+ createdAtMs: row.created_at_ms,
147
+ });
148
+
149
+ export const mapJudgmentRow = (
150
+ row: DbRetrievalTraceJudgmentRow
151
+ ): RetrievalTraceJudgmentRow => ({
152
+ judgmentId: row.judgment_id,
153
+ traceId: row.trace_id,
154
+ runId: row.run_id,
155
+ idempotencyKey: row.idempotency_key,
156
+ label: row.label,
157
+ targetKind: row.target_kind,
158
+ targetRef: row.target_ref,
159
+ target: parseJsonObject(row.target_json),
160
+ targetBytes: row.target_bytes,
161
+ canonicalDigest: row.canonical_digest,
162
+ createdAtMs: row.created_at_ms,
163
+ });
164
+
165
+ export const mapExportRow = (
166
+ row: DbRetrievalTraceExportRow
167
+ ): RetrievalTraceExportRow => ({
168
+ exportId: row.export_id,
169
+ traceId: row.trace_id,
170
+ format: row.format,
171
+ artifactHash: row.artifact_hash,
172
+ createdAtMs: row.created_at_ms,
173
+ });
174
+
175
+ export class RetrievalTraceConflictError extends Error {
176
+ constructor(message: string) {
177
+ super(message);
178
+ this.name = "RetrievalTraceConflictError";
179
+ }
180
+ }
181
+
182
+ export const validateTraceId = (value: string, label: string): void => {
183
+ if (value.length < 1 || value.length > 128) {
184
+ throw new RangeError(`${label} must be from 1 to 128 characters`);
185
+ }
186
+ };
187
+
188
+ export const traceWriteError = <T>(
189
+ cause: unknown,
190
+ fallback: string
191
+ ): StoreResult<T> => {
192
+ const message = cause instanceof Error ? cause.message : fallback;
193
+ if (
194
+ cause instanceof RetrievalTraceConflictError ||
195
+ message.includes("constraint failed") ||
196
+ message.includes("FOREIGN KEY constraint") ||
197
+ message.includes("retrieval trace record cap exceeded")
198
+ ) {
199
+ return err("CONSTRAINT_VIOLATION", message, cause);
200
+ }
201
+ if (
202
+ cause instanceof RangeError ||
203
+ (cause instanceof Error && cause.name === "ZodError")
204
+ ) {
205
+ return err("INVALID_INPUT", message, cause);
206
+ }
207
+ return err("QUERY_FAILED", message, cause);
208
+ };
209
+
210
+ export const traceReadError = <T>(
211
+ cause: unknown,
212
+ fallback: string
213
+ ): StoreResult<T> =>
214
+ cause instanceof RangeError
215
+ ? err("INVALID_INPUT", cause.message, cause)
216
+ : err(
217
+ "QUERY_FAILED",
218
+ cause instanceof Error ? cause.message : fallback,
219
+ cause
220
+ );
221
+
222
+ const countRows = (db: Database, table: string, traceId?: string): number => {
223
+ if (traceId === undefined) {
224
+ return (
225
+ db
226
+ .query<{ count: number }, []>(`SELECT COUNT(*) AS count FROM ${table}`)
227
+ .get()?.count ?? 0
228
+ );
229
+ }
230
+ return (
231
+ db
232
+ .query<{ count: number }, [string]>(
233
+ `SELECT COUNT(*) AS count FROM ${table} WHERE trace_id = ?`
234
+ )
235
+ .get(traceId)?.count ?? 0
236
+ );
237
+ };
238
+
239
+ export const countTraceContent = (
240
+ db: Database,
241
+ traceId?: string
242
+ ): RetrievalTraceDeleteCounts => {
243
+ const exportCount =
244
+ traceId === undefined
245
+ ? countRows(db, "retrieval_trace_exports")
246
+ : (db
247
+ .query<{ count: number }, [string, string]>(
248
+ `SELECT COUNT(*) AS count FROM retrieval_trace_exports x
249
+ WHERE EXISTS (
250
+ SELECT 1 FROM retrieval_trace_export_traces own
251
+ WHERE own.export_id = x.export_id AND own.trace_id = ?
252
+ )
253
+ AND NOT EXISTS (
254
+ SELECT 1 FROM retrieval_trace_export_traces other
255
+ WHERE other.export_id = x.export_id AND other.trace_id != ?
256
+ )`
257
+ )
258
+ .get(traceId, traceId)?.count ?? 0);
259
+ return {
260
+ traces: countRows(db, "retrieval_traces", traceId),
261
+ runs: countRows(db, "retrieval_trace_runs", traceId),
262
+ events: countRows(db, "retrieval_trace_events", traceId),
263
+ judgments: countRows(db, "retrieval_trace_judgments", traceId),
264
+ exports: exportCount,
265
+ exportLinks: countRows(db, "retrieval_trace_export_traces", traceId),
266
+ };
267
+ };