diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3d37e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +__pycache__/ +*.pyc +*.pyo +*.db +.env +.venv/ +*.egg-info/ +dist/ +build/ +.nuanced/ diff --git a/db/schema.sql b/db/schema.sql new file mode 100644 index 0000000..32929cf --- /dev/null +++ b/db/schema.sql @@ -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) +); diff --git a/migrate_to_sql.py b/migrate_to_sql.py index ffce32c..f79927b 100644 --- a/migrate_to_sql.py +++ b/migrate_to_sql.py @@ -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" @@ -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: @@ -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"]: @@ -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"]: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4f3ad5e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +networkx>=3.0