Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__pycache__/
*.pyc
*.pyo
*.db
.env
.venv/
*.egg-info/
dist/
build/
.nuanced/
64 changes: 64 additions & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- db/schema.sql
-- Normalized schema for the LogicAIn Codebase-as-Data registry.
-- Used by migrate_to_sql.py for the advanced cross-module pipeline.

CREATE TABLE IF NOT EXISTS modules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
path TEXT UNIQUE NOT NULL,
sha256 TEXT,
last_synced TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS imports (
id INTEGER PRIMARY KEY AUTOINCREMENT,
module_id INTEGER NOT NULL,
imported_module TEXT,
imported_names TEXT,
line_number INTEGER,
FOREIGN KEY(module_id) REFERENCES modules(id)
);

CREATE TABLE IF NOT EXISTS classes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
module_id INTEGER NOT NULL,
name TEXT NOT NULL,
bases TEXT,
docstring TEXT,
line_number INTEGER,
FOREIGN KEY(module_id) REFERENCES modules(id)
);

CREATE TABLE IF NOT EXISTS functions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
module_id INTEGER NOT NULL,
class_id INTEGER,
name TEXT NOT NULL,
arguments TEXT,
return_type TEXT,
docstring TEXT,
logic_calls TEXT,
line_start INTEGER,
line_end INTEGER,
resolved_logic_id INTEGER,
FOREIGN KEY(module_id) REFERENCES modules(id),
FOREIGN KEY(class_id) REFERENCES classes(id),
FOREIGN KEY(resolved_logic_id) REFERENCES functions(id)
);

CREATE TABLE IF NOT EXISTS constants (
id INTEGER PRIMARY KEY AUTOINCREMENT,
module_id INTEGER NOT NULL,
name TEXT NOT NULL,
value TEXT,
line_number INTEGER,
FOREIGN KEY(module_id) REFERENCES modules(id)
);

CREATE TABLE IF NOT EXISTS dependency_map (
id INTEGER PRIMARY KEY AUTOINCREMENT,
source_function_id INTEGER NOT NULL,
target_function_id INTEGER NOT NULL,
call_type TEXT DEFAULT 'direct',
FOREIGN KEY(source_function_id) REFERENCES functions(id),
FOREIGN KEY(target_function_id) REFERENCES functions(id)
);
11 changes: 6 additions & 5 deletions migrate_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sqlite3
import json
import hashlib
from src.ast_decomposer import decompose_source
from src.ast_decomposer import ASTDecomposer

DB_PATH = "db/logic_registry.db"
SCHEMA_PATH = "db/schema.sql"
Expand Down Expand Up @@ -40,7 +40,8 @@ def migrate():
with open(file_path, "r") as f:
source = f.read()

logic = decompose_source(source)
decomposer = ASTDecomposer(source)
logic = decomposer.get_full_decomposition()

# Upsert module
if row:
Expand All @@ -58,7 +59,7 @@ def migrate():
# Insert Imports
for imp in logic["imports"]:
cursor.execute("INSERT INTO imports (module_id, imported_module, imported_names, line_number) VALUES (?, ?, ?, ?)",
(module_id, imp["module"], json.dumps(imp["names"]), imp["line" nhm]))
(module_id, imp["module"], json.dumps(imp["names"]), imp["line"]))

# Insert Classes
for cls in logic["classes"]:
Expand All @@ -67,12 +68,12 @@ def migrate():
class_id = cursor.lastrowid
for method in cls["methods"]:
cursor.execute("INSERT INTO functions (module_id, class_id, name, arguments, return_type, docstring, logic_calls, line_start, line_end) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
(module_id, class_id, method["name"], json.dumps(method["arguments"]), method["return_type"], method["docstring"], json.dumps(method["logic_calls"]), method["line_start"], method["line_end"]))
(module_id, class_id, method["self_explanatory_name"], json.dumps(method["arguments"]), method["return_type"], method["docstring"], json.dumps(method["logic_calls"]), method["line_start"], method["line_end"]))

# Insert Top-level Functions
for func in logic["functions"]:
cursor.execute("INSERT INTO functions (module_id, class_id, name, arguments, return_type, docstring, logic_calls, line_start, line_end) VALUES (?, NULL, ?, ?, ?, ?, ?, ?, ?)",
(module_id, func["name"], json.dumps(func["arguments"]), func["return_type"], func["docstring"], json.dumps(func["logic_calls"]), func["line_start"], func["line_end"]))
(module_id, func["self_explanatory_name"], json.dumps(func["arguments"]), func["return_type"], func["docstring"], json.dumps(func["logic_calls"]), func["line_start"], func["line_end"]))

# Insert Constants
for const in logic["constants"]:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
networkx>=3.0