@gmickel/gno 2.8.2 → 2.8.4

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 (66) hide show
  1. package/README.md +1 -1
  2. package/assets/spa-production.json.gz +0 -0
  3. package/browser-extension/artifacts/{gno-browser-clipper-v2.8.2.zip → gno-browser-clipper-v2.8.4.zip} +0 -0
  4. package/browser-extension/artifacts/gno-browser-clipper-v2.8.4.zip.sha256 +1 -0
  5. package/browser-extension/dist/manifest.json +1 -1
  6. package/package.json +9 -1
  7. package/spec/cli.md +77 -6
  8. package/spec/mcp.md +5 -6
  9. package/spec/output-schemas/doctor.schema.json +10 -4
  10. package/spec/output-schemas/status.schema.json +4 -2
  11. package/src/cli/commands/daemon.ts +7 -2
  12. package/src/cli/commands/doctor-activation.ts +38 -11
  13. package/src/cli/commands/doctor.ts +46 -25
  14. package/src/cli/commands/index-cmd.ts +10 -2
  15. package/src/cli/commands/links.ts +5 -22
  16. package/src/cli/commands/shared.ts +26 -1
  17. package/src/cli/commands/status.ts +76 -4
  18. package/src/cli/commands/update.ts +6 -1
  19. package/src/cli/commands/vec.ts +42 -2
  20. package/src/cli/program.ts +2 -2
  21. package/src/config/types.ts +19 -0
  22. package/src/converters/adapters/markitdownTs/adapter.ts +1 -52
  23. package/src/converters/adapters/shared/ooxml-protection.ts +58 -0
  24. package/src/converters/adapters/xlsx/adapter.ts +132 -0
  25. package/src/converters/adapters/xlsx/sheet-markdown.ts +312 -0
  26. package/src/converters/registry.ts +62 -6
  27. package/src/converters/versions.ts +2 -0
  28. package/src/core/activation-empty.ts +16 -0
  29. package/src/core/activation-status.ts +23 -5
  30. package/src/core/audit-freshness.ts +1 -1
  31. package/src/core/audit-outside-index.ts +48 -3
  32. package/src/core/change-diff.ts +16 -4
  33. package/src/core/link-destination-parse.ts +21 -4
  34. package/src/core/link-inventory-markdown.ts +23 -3
  35. package/src/core/links.ts +127 -31
  36. package/src/core/network-boundary-inventory.ts +18 -0
  37. package/src/index.ts +10 -0
  38. package/src/ingestion/document-metadata.ts +256 -0
  39. package/src/ingestion/file-child-env.ts +9 -0
  40. package/src/ingestion/file-child.ts +106 -0
  41. package/src/ingestion/file-processor.ts +546 -0
  42. package/src/ingestion/frontmatter.ts +6 -2
  43. package/src/ingestion/index.ts +1 -0
  44. package/src/ingestion/prepare-convert.ts +32 -0
  45. package/src/ingestion/prepare-file.ts +272 -0
  46. package/src/ingestion/prepare-worker.ts +43 -0
  47. package/src/ingestion/record-container.ts +7 -2
  48. package/src/ingestion/strip.ts +136 -31
  49. package/src/ingestion/sync-options.ts +7 -1
  50. package/src/ingestion/sync.ts +207 -400
  51. package/src/ingestion/types.ts +18 -0
  52. package/src/llm/native-worker/embedding-identity.ts +15 -3
  53. package/src/mcp/http-transport.ts +11 -0
  54. package/src/mcp/tools/links.ts +10 -38
  55. package/src/serve/activation-health.ts +25 -7
  56. package/src/serve/public/components/BootstrapStatus.tsx +9 -4
  57. package/src/serve/resident-request.ts +19 -0
  58. package/src/serve/resident-runtime.ts +84 -8
  59. package/src/serve/routes/links.ts +6 -24
  60. package/src/serve/server.ts +3 -2
  61. package/src/serve/status.ts +27 -8
  62. package/src/sessions/config-refresh.ts +3 -2
  63. package/src/store/sqlite/graph-similarity.ts +5 -13
  64. package/src/store/vector/partition-index.ts +100 -0
  65. package/src/store/vector/stored-vectors.ts +20 -15
  66. package/browser-extension/artifacts/gno-browser-clipper-v2.8.2.zip.sha256 +0 -1
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Maintenance of an activated vector partition's vec0 index
3
+ * (`vec_v1_<partition>`), which mirrors the partition's `vector_variants`.
4
+ * `gno vec sync` and `gno vec rebuild` use it on indexes embedded since 2.7.
5
+ * Neither changes authority, owners or variants, so the variant epoch stays.
6
+ *
7
+ * @module src/store/vector/partition-index
8
+ */
9
+ import type { Database } from "bun:sqlite";
10
+
11
+ export interface StoredPartition {
12
+ partitionId: string;
13
+ dimensions: number;
14
+ }
15
+
16
+ const tableName = (partition: StoredPartition): string =>
17
+ `vec_v1_${partition.partitionId}`;
18
+
19
+ const createTable = (db: Database, partition: StoredPartition): void => {
20
+ db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS ${tableName(partition)} USING vec0(
21
+ variant_id INTEGER PRIMARY KEY,
22
+ embedding FLOAT[${partition.dimensions}] distance_metric=cosine
23
+ )`);
24
+ };
25
+
26
+ const insertVariants = (
27
+ db: Database,
28
+ partition: StoredPartition,
29
+ rows: Iterable<{ variantId: number; embedding: Uint8Array }>
30
+ ): number => {
31
+ let inserted = 0;
32
+ for (const row of rows) {
33
+ db.run(
34
+ `INSERT INTO ${tableName(partition)}(variant_id, embedding) VALUES (?, ?)`,
35
+ [row.variantId, row.embedding]
36
+ );
37
+ inserted += 1;
38
+ }
39
+ return inserted;
40
+ };
41
+
42
+ /**
43
+ * Remove index rows without a matching variant (orphans and stale
44
+ * embeddings), then add the variants the index lacks. Requires sqlite-vec.
45
+ */
46
+ export function syncPartitionIndex(
47
+ db: Database,
48
+ partition: StoredPartition
49
+ ): { added: number; removed: number } {
50
+ const table = tableName(partition);
51
+ return db
52
+ .transaction(() => {
53
+ createTable(db, partition);
54
+ const stale = db
55
+ .query<{ variantId: number }, [string]>(`
56
+ SELECT x.variant_id AS variantId FROM ${table} x
57
+ LEFT JOIN vector_variants v ON v.variant_id = x.variant_id
58
+ AND v.partition_id = ?
59
+ WHERE v.variant_id IS NULL OR x.embedding != v.embedding
60
+ `)
61
+ .all(partition.partitionId);
62
+ for (const { variantId } of stale) {
63
+ db.run(`DELETE FROM ${table} WHERE variant_id = ?`, [variantId]);
64
+ }
65
+ const missing = db
66
+ .query<{ variantId: number; embedding: Uint8Array }, [string]>(`
67
+ SELECT v.variant_id AS variantId, v.embedding FROM vector_variants v
68
+ LEFT JOIN ${table} x ON x.variant_id = v.variant_id
69
+ WHERE v.partition_id = ? AND x.variant_id IS NULL
70
+ `)
71
+ .all(partition.partitionId);
72
+ return {
73
+ added: insertVariants(db, partition, missing),
74
+ removed: stale.length,
75
+ };
76
+ })
77
+ .immediate();
78
+ }
79
+
80
+ /** Drop and repopulate the index from the partition's variants. */
81
+ export function rebuildPartitionIndex(
82
+ db: Database,
83
+ partition: StoredPartition
84
+ ): number {
85
+ return db
86
+ .transaction(() => {
87
+ db.exec(`DROP TABLE IF EXISTS ${tableName(partition)}`);
88
+ createTable(db, partition);
89
+ return insertVariants(
90
+ db,
91
+ partition,
92
+ db
93
+ .query<{ variantId: number; embedding: Uint8Array }, [string]>(
94
+ "SELECT variant_id AS variantId, embedding FROM vector_variants WHERE partition_id = ?"
95
+ )
96
+ .iterate(partition.partitionId)
97
+ );
98
+ })
99
+ .immediate();
100
+ }
@@ -53,25 +53,30 @@ interface PartitionVectorRow {
53
53
  embedding: Uint8Array;
54
54
  }
55
55
 
56
+ const unitVector = (vector: Float32Array): Float32Array => {
57
+ let norm = 0;
58
+ for (const value of vector) norm += value * value;
59
+ norm = Math.sqrt(norm);
60
+ return norm > 0 ? vector.map((value) => value / norm) : vector;
61
+ };
62
+
56
63
  /**
57
- * Chunk vectors of current active documents, ordered by chunk seq, keyed by
58
- * document id. Partition vectors count only while their owner still yields
59
- * the stored input (the rule vector search applies). `firstChunkOnly` keeps
60
- * the lowest-seq vector per document.
64
+ * The similarity source vector of each current active document, keyed by
65
+ * document id: the stored vector of its first chunk (lowest seq whose vector
66
+ * is current), unit-normalized. Every similarity surface (CLI, MCP, REST and
67
+ * graph edges) uses this one rule, so scores agree. Partition vectors count
68
+ * only while their owner still yields the stored input (the rule vector
69
+ * search applies).
61
70
  */
62
- export function readStoredDocumentVectors(
71
+ export function readSimilaritySourceVectors(
63
72
  db: Database,
64
73
  source: StoredVectorSource,
65
- documents: StoredVectorDocument[],
66
- options: { firstChunkOnly?: boolean } = {}
67
- ): Map<number, Float32Array[]> {
68
- const vectors = new Map<number, Float32Array[]>();
74
+ documents: StoredVectorDocument[]
75
+ ): Map<number, Float32Array> {
76
+ const vectors = new Map<number, Float32Array>();
69
77
  const add = (documentId: number, blob: Uint8Array): void => {
70
- const existing = vectors.get(documentId);
71
- if (existing && options.firstChunkOnly) return;
72
- const embedding = decodeEmbedding(blob);
73
- if (existing) existing.push(embedding);
74
- else vectors.set(documentId, [embedding]);
78
+ if (!vectors.has(documentId))
79
+ vectors.set(documentId, unitVector(decodeEmbedding(blob)));
75
80
  };
76
81
  if (documents.length === 0) return vectors;
77
82
 
@@ -95,7 +100,7 @@ export function readStoredDocumentVectors(
95
100
  JSON.stringify(documents.map((document) => document.id))
96
101
  );
97
102
  for (const row of rows) {
98
- if (options.firstChunkOnly && vectors.has(row.documentId)) continue;
103
+ if (vectors.has(row.documentId)) continue;
99
104
  const input = formatDocForEmbedding(
100
105
  row.text,
101
106
  row.title ?? undefined,
@@ -1 +0,0 @@
1
- 7bc830276cb923a482b662b980208b0978bf8ddbfbade0873e67d9757cf9c989 gno-browser-clipper-v2.8.2.zip