From 11ab4a9218042ef60052f9acfe11a339b1028557 Mon Sep 17 00:00:00 2001 From: Lex Christopherson Date: Tue, 20 Jan 2026 09:51:59 -0600 Subject: [PATCH] feat(04-01): add sql.js dependency and graph schema - Add sql.js ^1.12.0 dependency for WASM SQLite - Add GRAPH_SCHEMA constant with nodes/edges tables - Nodes use virtual id from JSON body for upserts - Edges indexed by source and target for relationship queries Co-Authored-By: Claude Opus 4.5 --- hooks/gsd-intel-index.js | 19 +++++++++++++++++++ package.json | 3 +++ 2 files changed, 22 insertions(+) diff --git a/hooks/gsd-intel-index.js b/hooks/gsd-intel-index.js index b371beef8..a02bf2386 100755 --- a/hooks/gsd-intel-index.js +++ b/hooks/gsd-intel-index.js @@ -5,6 +5,25 @@ const fs = require('fs'); const path = require('path'); +const initSqlJs = require('sql.js'); + +// Graph database schema (simple-graph pattern) +const GRAPH_SCHEMA = ` +CREATE TABLE IF NOT EXISTS nodes ( + body TEXT, + id TEXT GENERATED ALWAYS AS (json_extract(body, '$.id')) VIRTUAL NOT NULL UNIQUE +); +CREATE INDEX IF NOT EXISTS id_idx ON nodes(id); + +CREATE TABLE IF NOT EXISTS edges ( + source TEXT NOT NULL, + target TEXT NOT NULL, + relationship TEXT DEFAULT 'depends_on', + UNIQUE(source, target, relationship) ON CONFLICT REPLACE +); +CREATE INDEX IF NOT EXISTS source_idx ON edges(source); +CREATE INDEX IF NOT EXISTS target_idx ON edges(target); +`; // JS/TS file extensions to index const INDEXABLE_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs']; diff --git a/package.json b/package.json index d2d924ce9..36cde3f88 100644 --- a/package.json +++ b/package.json @@ -32,5 +32,8 @@ }, "engines": { "node": ">=16.7.0" + }, + "dependencies": { + "sql.js": "^1.12.0" } }