-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
189 lines (169 loc) · 5.42 KB
/
Copy pathschema.sql
File metadata and controls
189 lines (169 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
-- db/schema.sql
-- Tasks and their state
CREATE TABLE IF NOT EXISTS tasks (
id TEXT PRIMARY KEY,
goal TEXT NOT NULL,
state TEXT NOT NULL, -- 'planning', 'executing', 'verifying', 'done', 'failed'
plan_json TEXT, -- Array of Task objects
current_task_index INTEGER DEFAULT 0,
total_cost REAL DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- State transitions (for recovery)
CREATE TABLE IF NOT EXISTS state_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
task_id TEXT NOT NULL REFERENCES tasks(id),
phase TEXT NOT NULL,
state_json TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Task results
CREATE TABLE IF NOT EXISTS task_results (
id INTEGER PRIMARY KEY AUTOINCREMENT,
task_id TEXT NOT NULL REFERENCES tasks(id),
step_index INTEGER NOT NULL,
verification_json TEXT, -- VerificationReport
cost REAL,
duration_ms INTEGER,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Simple file index (no embeddings, no vectors)
CREATE TABLE IF NOT EXISTS file_index (
path TEXT PRIMARY KEY,
language TEXT,
line_count INTEGER,
last_modified DATETIME,
symbols_json TEXT -- Array of {name, type, line}
);
-- --- Memory Engine v2 Layers ---
-- Model performance logs (for dynamic router)
CREATE TABLE IF NOT EXISTS model_performance (
id INTEGER PRIMARY KEY AUTOINCREMENT,
model TEXT NOT NULL,
task_type TEXT NOT NULL,
task_complexity INTEGER NOT NULL,
success BOOLEAN NOT NULL,
cost REAL NOT NULL,
duration_ms INTEGER NOT NULL,
retry_count INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Ephemeral working memory (session-scoped)
CREATE TABLE IF NOT EXISTS working_memory (
id INTEGER PRIMARY KEY AUTOINCREMENT,
task_id TEXT NOT NULL REFERENCES tasks(id),
key TEXT NOT NULL,
value TEXT NOT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Task memory (append-only log outputs)
CREATE TABLE IF NOT EXISTS task_memory (
id INTEGER PRIMARY KEY AUTOINCREMENT,
task_id TEXT NOT NULL REFERENCES tasks(id),
log_text TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Project memory (lessons learned, conventions)
CREATE TABLE IF NOT EXISTS project_memory (
id INTEGER PRIMARY KEY AUTOINCREMENT,
category TEXT NOT NULL, -- 'convention', 'pattern', 'lesson', 'api'
key TEXT NOT NULL,
value TEXT NOT NULL,
source_task_id TEXT,
confidence REAL DEFAULT 1.0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Code Graph (structural navigation)
CREATE TABLE IF NOT EXISTS code_graph_nodes (
id TEXT PRIMARY KEY,
file_path TEXT NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL,
line_start INTEGER,
line_end INTEGER,
signature TEXT,
docstring TEXT,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS code_graph_edges (
source_id TEXT,
target_id TEXT,
relationship TEXT,
PRIMARY KEY (source_id, target_id, relationship)
);
CREATE VIRTUAL TABLE IF NOT EXISTS code_search USING fts5(
id UNINDEXED,
file_path,
name,
signature,
docstring
);
-- Local Semantic Cache & Prompt cache
CREATE TABLE IF NOT EXISTS cache_entries (
id TEXT PRIMARY KEY,
query_embedding BLOB NOT NULL, -- Serialized Float32Array
response TEXT NOT NULL,
model TEXT NOT NULL,
cost REAL NOT NULL,
similarity_threshold REAL DEFAULT 0.92,
ttl_seconds INTEGER DEFAULT 86400,
hit_count INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Goal memory (solutions, patterns)
CREATE TABLE IF NOT EXISTS goal_memory (
id TEXT PRIMARY KEY,
goal TEXT NOT NULL,
plan_json TEXT NOT NULL,
status TEXT NOT NULL, -- 'success', 'failed'
cost REAL NOT NULL,
duration_ms INTEGER NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Code embeddings (vector table fallback)
CREATE TABLE IF NOT EXISTS code_embeddings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
path TEXT NOT NULL,
content_type TEXT NOT NULL, -- 'function', 'class', 'comment', 'doc'
symbol_name TEXT NOT NULL,
line_start INTEGER NOT NULL,
line_end INTEGER NOT NULL,
embedding BLOB NOT NULL
);
-- Shared Agent Memory (V2)
CREATE TABLE IF NOT EXISTS task_plans (
task_id TEXT PRIMARY KEY,
goal_id TEXT NOT NULL,
plan_json TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS task_executions (
task_id TEXT PRIMARY KEY,
execution_json TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS task_reviews (
task_id TEXT PRIMARY KEY,
review_json TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Extended schema for v3 session management
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY,
name TEXT,
goal_id TEXT NOT NULL REFERENCES tasks(id),
status TEXT DEFAULT 'active', -- active, paused, archived
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
last_activity DATETIME DEFAULT CURRENT_TIMESTAMP,
message_count INTEGER DEFAULT 0,
total_cost REAL DEFAULT 0.0,
context_usage INTEGER DEFAULT 0, -- tokens used
git_branch TEXT,
parent_session_id TEXT REFERENCES sessions(id), -- for forks
metadata TEXT -- JSON: {model, permissionMode, etc.}
);
CREATE INDEX IF NOT EXISTS idx_sessions_status ON sessions(status);
CREATE INDEX IF NOT EXISTS idx_sessions_name ON sessions(name);
CREATE INDEX IF NOT EXISTS idx_sessions_activity ON sessions(last_activity);