feat(persistence): SQLite schema + repository for runs/genomes/evals/cost

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 20:18:08 +02:00
parent 65dda09aff
commit 34f88865da
4 changed files with 368 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
SCHEMA_SQL = """
CREATE TABLE IF NOT EXISTS runs (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
started_at TEXT NOT NULL,
completed_at TEXT,
status TEXT NOT NULL DEFAULT 'running',
config_json TEXT NOT NULL,
total_cost_usd REAL NOT NULL DEFAULT 0.0
);
CREATE TABLE IF NOT EXISTS generations (
run_id TEXT NOT NULL,
generation_idx INTEGER NOT NULL,
started_at TEXT,
completed_at TEXT,
n_genomes INTEGER NOT NULL,
fitness_median REAL NOT NULL,
fitness_max REAL NOT NULL,
fitness_p90 REAL NOT NULL,
entropy REAL NOT NULL,
PRIMARY KEY (run_id, generation_idx),
FOREIGN KEY (run_id) REFERENCES runs(id)
);
CREATE TABLE IF NOT EXISTS genomes (
id TEXT NOT NULL,
run_id TEXT NOT NULL,
generation_idx INTEGER NOT NULL,
payload_json TEXT NOT NULL,
PRIMARY KEY (id, run_id, generation_idx),
FOREIGN KEY (run_id) REFERENCES runs(id)
);
CREATE TABLE IF NOT EXISTS evaluations (
run_id TEXT NOT NULL,
genome_id TEXT NOT NULL,
fitness REAL NOT NULL,
dsr REAL NOT NULL,
dsr_pvalue REAL NOT NULL,
sharpe REAL NOT NULL,
max_dd REAL NOT NULL,
total_return REAL NOT NULL,
n_trades INTEGER NOT NULL,
parse_error TEXT,
raw_text TEXT,
eval_ts TEXT NOT NULL,
PRIMARY KEY (run_id, genome_id),
FOREIGN KEY (run_id) REFERENCES runs(id)
);
CREATE TABLE IF NOT EXISTS cost_records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
run_id TEXT NOT NULL,
agent_id TEXT NOT NULL,
ts TEXT NOT NULL,
tier TEXT NOT NULL,
input_tokens INTEGER NOT NULL,
output_tokens INTEGER NOT NULL,
cost_usd REAL NOT NULL,
FOREIGN KEY (run_id) REFERENCES runs(id)
);
CREATE TABLE IF NOT EXISTS adversarial_findings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
run_id TEXT NOT NULL,
genome_id TEXT NOT NULL,
name TEXT NOT NULL,
severity TEXT NOT NULL,
detail TEXT NOT NULL,
FOREIGN KEY (run_id) REFERENCES runs(id)
);
CREATE INDEX IF NOT EXISTS idx_evaluations_fitness ON evaluations(run_id, fitness DESC);
CREATE INDEX IF NOT EXISTS idx_genomes_generation ON genomes(run_id, generation_idx);
CREATE INDEX IF NOT EXISTS idx_cost_run ON cost_records(run_id);
"""