@mduenas/codegraph 0.4.0 → 0.4.1

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 (2) hide show
  1. package/dist/db/schema.sql +149 -0
  2. package/package.json +2 -2
@@ -0,0 +1,149 @@
1
+ -- CodeGraph SQLite Schema
2
+ -- Version 1
3
+
4
+ -- Schema version tracking
5
+ CREATE TABLE IF NOT EXISTS schema_versions (
6
+ version INTEGER PRIMARY KEY,
7
+ applied_at INTEGER NOT NULL,
8
+ description TEXT
9
+ );
10
+
11
+ -- Insert initial version
12
+ INSERT INTO schema_versions (version, applied_at, description)
13
+ VALUES (1, strftime('%s', 'now') * 1000, 'Initial schema');
14
+
15
+ -- =============================================================================
16
+ -- Core Tables
17
+ -- =============================================================================
18
+
19
+ -- Nodes: Code symbols (functions, classes, variables, etc.)
20
+ CREATE TABLE IF NOT EXISTS nodes (
21
+ id TEXT PRIMARY KEY,
22
+ kind TEXT NOT NULL,
23
+ name TEXT NOT NULL,
24
+ qualified_name TEXT NOT NULL,
25
+ file_path TEXT NOT NULL,
26
+ language TEXT NOT NULL,
27
+ start_line INTEGER NOT NULL,
28
+ end_line INTEGER NOT NULL,
29
+ start_column INTEGER NOT NULL,
30
+ end_column INTEGER NOT NULL,
31
+ docstring TEXT,
32
+ signature TEXT,
33
+ visibility TEXT,
34
+ is_exported INTEGER DEFAULT 0,
35
+ is_async INTEGER DEFAULT 0,
36
+ is_static INTEGER DEFAULT 0,
37
+ is_abstract INTEGER DEFAULT 0,
38
+ decorators TEXT, -- JSON array
39
+ type_parameters TEXT, -- JSON array
40
+ updated_at INTEGER NOT NULL
41
+ );
42
+
43
+ -- Edges: Relationships between nodes
44
+ CREATE TABLE IF NOT EXISTS edges (
45
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
46
+ source TEXT NOT NULL,
47
+ target TEXT NOT NULL,
48
+ kind TEXT NOT NULL,
49
+ metadata TEXT, -- JSON object
50
+ line INTEGER,
51
+ col INTEGER,
52
+ FOREIGN KEY (source) REFERENCES nodes(id) ON DELETE CASCADE,
53
+ FOREIGN KEY (target) REFERENCES nodes(id) ON DELETE CASCADE
54
+ );
55
+
56
+ -- Files: Tracked source files
57
+ CREATE TABLE IF NOT EXISTS files (
58
+ path TEXT PRIMARY KEY,
59
+ content_hash TEXT NOT NULL,
60
+ language TEXT NOT NULL,
61
+ size INTEGER NOT NULL,
62
+ modified_at INTEGER NOT NULL,
63
+ indexed_at INTEGER NOT NULL,
64
+ node_count INTEGER DEFAULT 0,
65
+ errors TEXT -- JSON array
66
+ );
67
+
68
+ -- Unresolved References: References that need resolution after full indexing
69
+ CREATE TABLE IF NOT EXISTS unresolved_refs (
70
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
71
+ from_node_id TEXT NOT NULL,
72
+ reference_name TEXT NOT NULL,
73
+ reference_kind TEXT NOT NULL,
74
+ line INTEGER NOT NULL,
75
+ col INTEGER NOT NULL,
76
+ candidates TEXT, -- JSON array
77
+ FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE
78
+ );
79
+
80
+ -- =============================================================================
81
+ -- Indexes for Query Performance
82
+ -- =============================================================================
83
+
84
+ -- Node indexes
85
+ CREATE INDEX IF NOT EXISTS idx_nodes_kind ON nodes(kind);
86
+ CREATE INDEX IF NOT EXISTS idx_nodes_name ON nodes(name);
87
+ CREATE INDEX IF NOT EXISTS idx_nodes_qualified_name ON nodes(qualified_name);
88
+ CREATE INDEX IF NOT EXISTS idx_nodes_file_path ON nodes(file_path);
89
+ CREATE INDEX IF NOT EXISTS idx_nodes_language ON nodes(language);
90
+ CREATE INDEX IF NOT EXISTS idx_nodes_file_line ON nodes(file_path, start_line);
91
+
92
+ -- Full-text search index on node names and docstrings
93
+ CREATE VIRTUAL TABLE IF NOT EXISTS nodes_fts USING fts5(
94
+ id,
95
+ name,
96
+ qualified_name,
97
+ docstring,
98
+ content='nodes',
99
+ content_rowid='rowid'
100
+ );
101
+
102
+ -- Triggers to keep FTS index in sync
103
+ CREATE TRIGGER IF NOT EXISTS nodes_ai AFTER INSERT ON nodes BEGIN
104
+ INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring)
105
+ VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring);
106
+ END;
107
+
108
+ CREATE TRIGGER IF NOT EXISTS nodes_ad AFTER DELETE ON nodes BEGIN
109
+ INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring)
110
+ VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring);
111
+ END;
112
+
113
+ CREATE TRIGGER IF NOT EXISTS nodes_au AFTER UPDATE ON nodes BEGIN
114
+ INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring)
115
+ VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring);
116
+ INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring)
117
+ VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring);
118
+ END;
119
+
120
+ -- Edge indexes
121
+ CREATE INDEX IF NOT EXISTS idx_edges_source ON edges(source);
122
+ CREATE INDEX IF NOT EXISTS idx_edges_target ON edges(target);
123
+ CREATE INDEX IF NOT EXISTS idx_edges_kind ON edges(kind);
124
+ CREATE INDEX IF NOT EXISTS idx_edges_source_kind ON edges(source, kind);
125
+ CREATE INDEX IF NOT EXISTS idx_edges_target_kind ON edges(target, kind);
126
+
127
+ -- File indexes
128
+ CREATE INDEX IF NOT EXISTS idx_files_language ON files(language);
129
+ CREATE INDEX IF NOT EXISTS idx_files_modified_at ON files(modified_at);
130
+
131
+ -- Unresolved refs indexes
132
+ CREATE INDEX IF NOT EXISTS idx_unresolved_from_node ON unresolved_refs(from_node_id);
133
+ CREATE INDEX IF NOT EXISTS idx_unresolved_name ON unresolved_refs(reference_name);
134
+
135
+ -- =============================================================================
136
+ -- Vector Storage (for future semantic search)
137
+ -- =============================================================================
138
+
139
+ -- Vector embeddings for semantic search
140
+ -- Note: No foreign key constraint to allow standalone vector testing
141
+ -- The VectorManager handles node-vector relationship at the application level
142
+ CREATE TABLE IF NOT EXISTS vectors (
143
+ node_id TEXT PRIMARY KEY,
144
+ embedding BLOB NOT NULL, -- Float32 array stored as blob
145
+ model TEXT NOT NULL, -- Model used to generate embedding
146
+ created_at INTEGER NOT NULL
147
+ );
148
+
149
+ CREATE INDEX IF NOT EXISTS idx_vectors_model ON vectors(model);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mduenas/codegraph",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Supercharge Claude Code with semantic code intelligence. 30% fewer tokens, 25% fewer tool calls, 100% local.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "build": "tsc && npm run copy-assets",
17
17
  "postinstall": "node scripts/postinstall.js",
18
- "copy-assets": "cp -r src/extraction/queries dist/extraction/ && cp src/db/schema.sql dist/db/",
18
+ "copy-assets": "mkdir -p dist/db && cp src/db/schema.sql dist/db/ && (cp -r src/extraction/queries dist/extraction/ 2>/dev/null || true)",
19
19
  "dev": "tsc --watch",
20
20
  "cli": "npm run build && node dist/bin/codegraph.js",
21
21
  "test": "vitest run",