@contextgit/store 0.0.3
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.
- package/dist/branch-merge.test.d.ts +2 -0
- package/dist/branch-merge.test.d.ts.map +1 -0
- package/dist/branch-merge.test.js +101 -0
- package/dist/branch-merge.test.js.map +1 -0
- package/dist/engine-integration.test.d.ts +2 -0
- package/dist/engine-integration.test.d.ts.map +1 -0
- package/dist/engine-integration.test.js +77 -0
- package/dist/engine-integration.test.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/interface.d.ts +30 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +2 -0
- package/dist/interface.js.map +1 -0
- package/dist/local/claims.test.d.ts +2 -0
- package/dist/local/claims.test.d.ts.map +1 -0
- package/dist/local/claims.test.js +151 -0
- package/dist/local/claims.test.js.map +1 -0
- package/dist/local/index.d.ts +39 -0
- package/dist/local/index.d.ts.map +1 -0
- package/dist/local/index.js +319 -0
- package/dist/local/index.js.map +1 -0
- package/dist/local/local-store.test.d.ts +2 -0
- package/dist/local/local-store.test.d.ts.map +1 -0
- package/dist/local/local-store.test.js +141 -0
- package/dist/local/local-store.test.js.map +1 -0
- package/dist/local/migrations.d.ts +3 -0
- package/dist/local/migrations.d.ts.map +1 -0
- package/dist/local/migrations.js +78 -0
- package/dist/local/migrations.js.map +1 -0
- package/dist/local/queries.d.ts +44 -0
- package/dist/local/queries.d.ts.map +1 -0
- package/dist/local/queries.js +527 -0
- package/dist/local/queries.js.map +1 -0
- package/dist/local/schema.d.ts +15 -0
- package/dist/local/schema.d.ts.map +1 -0
- package/dist/local/schema.js +144 -0
- package/dist/local/schema.js.map +1 -0
- package/dist/remote/index.d.ts +39 -0
- package/dist/remote/index.d.ts.map +1 -0
- package/dist/remote/index.js +216 -0
- package/dist/remote/index.js.map +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
// All SQL queries for LocalStore.
|
|
2
|
+
// Dates are stored as INTEGER (Unix ms) and converted to/from Date at this layer.
|
|
3
|
+
// IDs are generated by the caller (nanoid).
|
|
4
|
+
// ─── Row → domain type converters ───────────────────────────────────────────
|
|
5
|
+
function toProject(row) {
|
|
6
|
+
return {
|
|
7
|
+
id: row.id,
|
|
8
|
+
name: row.name,
|
|
9
|
+
description: row.description ?? undefined,
|
|
10
|
+
githubUrl: row.github_url ?? undefined,
|
|
11
|
+
createdAt: new Date(row.created_at),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function toBranch(row) {
|
|
15
|
+
return {
|
|
16
|
+
id: row.id,
|
|
17
|
+
projectId: row.project_id,
|
|
18
|
+
name: row.name,
|
|
19
|
+
gitBranch: row.git_branch,
|
|
20
|
+
githubPrUrl: row.github_pr_url ?? undefined,
|
|
21
|
+
parentBranchId: row.parent_branch_id ?? undefined,
|
|
22
|
+
headCommitId: row.head_commit_id ?? undefined,
|
|
23
|
+
status: row.status,
|
|
24
|
+
createdAt: new Date(row.created_at),
|
|
25
|
+
mergedAt: row.merged_at ? new Date(row.merged_at) : undefined,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function toCommit(row) {
|
|
29
|
+
return {
|
|
30
|
+
id: row.id,
|
|
31
|
+
branchId: row.branch_id,
|
|
32
|
+
parentId: row.parent_id ?? undefined,
|
|
33
|
+
mergeSourceBranchId: row.merge_source_branch_id ?? undefined,
|
|
34
|
+
agentId: row.agent_id,
|
|
35
|
+
agentRole: row.agent_role,
|
|
36
|
+
tool: row.tool,
|
|
37
|
+
workflowType: row.workflow_type,
|
|
38
|
+
loopIteration: row.loop_iteration ?? undefined,
|
|
39
|
+
ciRunId: row.ci_run_id ?? undefined,
|
|
40
|
+
pipelineName: row.pipeline_name ?? undefined,
|
|
41
|
+
message: row.message,
|
|
42
|
+
content: row.content,
|
|
43
|
+
summary: row.summary,
|
|
44
|
+
commitType: row.commit_type,
|
|
45
|
+
gitCommitSha: row.git_commit_sha ?? undefined,
|
|
46
|
+
createdAt: new Date(row.created_at),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function toThread(row) {
|
|
50
|
+
return {
|
|
51
|
+
id: row.id,
|
|
52
|
+
projectId: row.project_id,
|
|
53
|
+
branchId: row.branch_id,
|
|
54
|
+
description: row.description,
|
|
55
|
+
status: row.status,
|
|
56
|
+
workflowType: row.workflow_type ?? undefined,
|
|
57
|
+
openedInCommit: row.opened_in_commit,
|
|
58
|
+
closedInCommit: row.closed_in_commit ?? undefined,
|
|
59
|
+
closedNote: row.closed_note ?? undefined,
|
|
60
|
+
createdAt: new Date(row.created_at),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function toClaim(row) {
|
|
64
|
+
return {
|
|
65
|
+
id: row.id,
|
|
66
|
+
projectId: row.project_id,
|
|
67
|
+
branchId: row.branch_id,
|
|
68
|
+
task: row.task,
|
|
69
|
+
agentId: row.agent_id,
|
|
70
|
+
role: row.role,
|
|
71
|
+
claimedAt: new Date(row.claimed_at),
|
|
72
|
+
status: row.status,
|
|
73
|
+
ttl: row.ttl,
|
|
74
|
+
releasedAt: row.released_at ? new Date(row.released_at) : undefined,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function toAgent(row) {
|
|
78
|
+
return {
|
|
79
|
+
id: row.id,
|
|
80
|
+
projectId: row.project_id,
|
|
81
|
+
role: row.role,
|
|
82
|
+
tool: row.tool,
|
|
83
|
+
workflowType: row.workflow_type,
|
|
84
|
+
displayName: row.display_name ?? undefined,
|
|
85
|
+
totalCommits: row.total_commits,
|
|
86
|
+
lastSeen: new Date(row.last_seen),
|
|
87
|
+
createdAt: new Date(row.created_at),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// ─── Queries class ───────────────────────────────────────────────────────────
|
|
91
|
+
export class Queries {
|
|
92
|
+
db;
|
|
93
|
+
// Prepared statements (lazy init pattern via getters is avoided for simplicity;
|
|
94
|
+
// statements are prepared once in constructor)
|
|
95
|
+
stmts;
|
|
96
|
+
constructor(db) {
|
|
97
|
+
this.db = db;
|
|
98
|
+
this.stmts = {
|
|
99
|
+
// Projects
|
|
100
|
+
insertProject: db.prepare(`
|
|
101
|
+
INSERT INTO projects (id, name, description, github_url, created_at)
|
|
102
|
+
VALUES (@id, @name, @description, @github_url, @created_at)
|
|
103
|
+
`),
|
|
104
|
+
selectProject: db.prepare(`SELECT * FROM projects WHERE id = ?`),
|
|
105
|
+
// Branches
|
|
106
|
+
insertBranch: db.prepare(`
|
|
107
|
+
INSERT INTO branches
|
|
108
|
+
(id, project_id, name, git_branch, github_pr_url, parent_branch_id,
|
|
109
|
+
head_commit_id, status, created_at)
|
|
110
|
+
VALUES
|
|
111
|
+
(@id, @project_id, @name, @git_branch, @github_pr_url, @parent_branch_id,
|
|
112
|
+
@head_commit_id, @status, @created_at)
|
|
113
|
+
`),
|
|
114
|
+
selectBranch: db.prepare(`SELECT * FROM branches WHERE id = ?`),
|
|
115
|
+
selectBranchByGit: db.prepare(`SELECT * FROM branches WHERE project_id = ? AND git_branch = ? LIMIT 1`),
|
|
116
|
+
selectBranches: db.prepare(`SELECT * FROM branches WHERE project_id = ? ORDER BY created_at DESC`),
|
|
117
|
+
updateBranchHead: db.prepare(`UPDATE branches SET head_commit_id = ? WHERE id = ?`),
|
|
118
|
+
updateBranchMerged: db.prepare(`UPDATE branches SET status = 'merged', merged_at = ? WHERE id = ?`),
|
|
119
|
+
// Commits
|
|
120
|
+
insertCommit: db.prepare(`
|
|
121
|
+
INSERT INTO commits
|
|
122
|
+
(id, branch_id, parent_id, merge_source_branch_id, agent_id, agent_role,
|
|
123
|
+
tool, workflow_type, loop_iteration, ci_run_id, pipeline_name,
|
|
124
|
+
message, content, summary, commit_type, git_commit_sha, created_at)
|
|
125
|
+
VALUES
|
|
126
|
+
(@id, @branch_id, @parent_id, @merge_source_branch_id, @agent_id, @agent_role,
|
|
127
|
+
@tool, @workflow_type, @loop_iteration, @ci_run_id, @pipeline_name,
|
|
128
|
+
@message, @content, @summary, @commit_type, @git_commit_sha, @created_at)
|
|
129
|
+
`),
|
|
130
|
+
selectCommit: db.prepare(`SELECT * FROM commits WHERE id = ?`),
|
|
131
|
+
selectCommits: db.prepare(`SELECT * FROM commits WHERE branch_id = ? ORDER BY created_at DESC, rowid DESC LIMIT ? OFFSET ?`),
|
|
132
|
+
selectCommitsByRole: db.prepare(`SELECT * FROM commits WHERE branch_id = ? AND agent_role = ? ORDER BY created_at DESC, rowid DESC LIMIT ?`),
|
|
133
|
+
selectLastCommit: db.prepare(`SELECT * FROM commits WHERE branch_id = ? ORDER BY created_at DESC, rowid DESC LIMIT 1`),
|
|
134
|
+
// Threads
|
|
135
|
+
insertThread: db.prepare(`
|
|
136
|
+
INSERT INTO threads
|
|
137
|
+
(id, project_id, branch_id, description, status, workflow_type,
|
|
138
|
+
opened_in_commit, created_at)
|
|
139
|
+
VALUES
|
|
140
|
+
(@id, @project_id, @branch_id, @description, 'open', @workflow_type,
|
|
141
|
+
@opened_in_commit, @created_at)
|
|
142
|
+
`),
|
|
143
|
+
syncThread: db.prepare(`
|
|
144
|
+
INSERT OR IGNORE INTO threads
|
|
145
|
+
(id, project_id, branch_id, description, status, workflow_type,
|
|
146
|
+
opened_in_commit, created_at)
|
|
147
|
+
VALUES
|
|
148
|
+
(@id, @project_id, @branch_id, @description, @status, @workflow_type,
|
|
149
|
+
@opened_in_commit, @created_at)
|
|
150
|
+
`),
|
|
151
|
+
closeThread: db.prepare(`
|
|
152
|
+
UPDATE threads
|
|
153
|
+
SET status = 'closed', closed_in_commit = ?, closed_note = ?
|
|
154
|
+
WHERE id = ?
|
|
155
|
+
`),
|
|
156
|
+
selectOpenThreads: db.prepare(`SELECT * FROM threads WHERE project_id = ? AND status = 'open' ORDER BY created_at ASC`),
|
|
157
|
+
selectOpenThreadsByBranch: db.prepare(`SELECT * FROM threads WHERE branch_id = ? AND status = 'open' ORDER BY created_at ASC`),
|
|
158
|
+
reassignThreads: db.prepare(`UPDATE threads SET branch_id = ? WHERE branch_id = ? AND status = 'open'`),
|
|
159
|
+
// Agents
|
|
160
|
+
insertAgent: db.prepare(`
|
|
161
|
+
INSERT INTO agents
|
|
162
|
+
(id, project_id, role, tool, workflow_type, display_name, total_commits,
|
|
163
|
+
last_seen, created_at)
|
|
164
|
+
VALUES
|
|
165
|
+
(@id, @project_id, @role, @tool, @workflow_type, @display_name, 0,
|
|
166
|
+
@last_seen, @created_at)
|
|
167
|
+
`),
|
|
168
|
+
upsertAgent: db.prepare(`
|
|
169
|
+
INSERT INTO agents
|
|
170
|
+
(id, project_id, role, tool, workflow_type, display_name, total_commits,
|
|
171
|
+
last_seen, created_at)
|
|
172
|
+
VALUES
|
|
173
|
+
(@id, @project_id, @role, @tool, @workflow_type, @display_name, 0,
|
|
174
|
+
@last_seen, @created_at)
|
|
175
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
176
|
+
role = excluded.role,
|
|
177
|
+
tool = excluded.tool,
|
|
178
|
+
workflow_type = excluded.workflow_type,
|
|
179
|
+
display_name = excluded.display_name,
|
|
180
|
+
last_seen = excluded.last_seen
|
|
181
|
+
`),
|
|
182
|
+
selectAgent: db.prepare(`SELECT * FROM agents WHERE id = ?`),
|
|
183
|
+
selectAgents: db.prepare(`SELECT * FROM agents WHERE project_id = ? ORDER BY last_seen DESC`),
|
|
184
|
+
incrementAgentCommits: db.prepare(`
|
|
185
|
+
UPDATE agents SET total_commits = total_commits + 1, last_seen = ? WHERE id = ?
|
|
186
|
+
`),
|
|
187
|
+
// Claims
|
|
188
|
+
insertClaim: db.prepare(`
|
|
189
|
+
INSERT INTO claims
|
|
190
|
+
(id, project_id, branch_id, task, agent_id, role, claimed_at, status, ttl, released_at)
|
|
191
|
+
VALUES
|
|
192
|
+
(@id, @project_id, @branch_id, @task, @agent_id, @role, @claimed_at, @status, @ttl, NULL)
|
|
193
|
+
`),
|
|
194
|
+
selectClaim: db.prepare(`SELECT * FROM claims WHERE id = ?`),
|
|
195
|
+
listActiveClaims: db.prepare(`
|
|
196
|
+
SELECT * FROM claims
|
|
197
|
+
WHERE project_id = ?
|
|
198
|
+
AND status != 'released'
|
|
199
|
+
AND (claimed_at + ttl) > ?
|
|
200
|
+
ORDER BY claimed_at ASC
|
|
201
|
+
`),
|
|
202
|
+
updateClaimStatus: db.prepare(`
|
|
203
|
+
UPDATE claims SET status = @status, released_at = @released_at WHERE id = @id
|
|
204
|
+
`),
|
|
205
|
+
releaseClaimsByAgent: db.prepare(`
|
|
206
|
+
UPDATE claims
|
|
207
|
+
SET status = 'released', released_at = ?
|
|
208
|
+
WHERE agent_id = ? AND branch_id = ? AND status != 'released'
|
|
209
|
+
`),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
// ─── Projects ────────────────────────────────────────────────────────────
|
|
213
|
+
insertProject(input) {
|
|
214
|
+
const now = Date.now();
|
|
215
|
+
this.stmts.insertProject.run({
|
|
216
|
+
id: input.id,
|
|
217
|
+
name: input.name,
|
|
218
|
+
description: input.description ?? null,
|
|
219
|
+
github_url: input.githubUrl ?? null,
|
|
220
|
+
created_at: now,
|
|
221
|
+
});
|
|
222
|
+
return toProject({
|
|
223
|
+
id: input.id,
|
|
224
|
+
name: input.name,
|
|
225
|
+
description: input.description ?? null,
|
|
226
|
+
github_url: input.githubUrl ?? null,
|
|
227
|
+
created_at: now,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
getProject(id) {
|
|
231
|
+
const row = this.stmts.selectProject.get(id);
|
|
232
|
+
return row ? toProject(row) : null;
|
|
233
|
+
}
|
|
234
|
+
// ─── Branches ────────────────────────────────────────────────────────────
|
|
235
|
+
insertBranch(input) {
|
|
236
|
+
const now = Date.now();
|
|
237
|
+
this.stmts.insertBranch.run({
|
|
238
|
+
id: input.id,
|
|
239
|
+
project_id: input.projectId,
|
|
240
|
+
name: input.name,
|
|
241
|
+
git_branch: input.gitBranch,
|
|
242
|
+
github_pr_url: input.githubPrUrl ?? null,
|
|
243
|
+
parent_branch_id: input.parentBranchId ?? null,
|
|
244
|
+
head_commit_id: null,
|
|
245
|
+
status: 'active',
|
|
246
|
+
created_at: now,
|
|
247
|
+
});
|
|
248
|
+
return toBranch({
|
|
249
|
+
id: input.id,
|
|
250
|
+
project_id: input.projectId,
|
|
251
|
+
name: input.name,
|
|
252
|
+
git_branch: input.gitBranch,
|
|
253
|
+
github_pr_url: input.githubPrUrl ?? null,
|
|
254
|
+
parent_branch_id: input.parentBranchId ?? null,
|
|
255
|
+
head_commit_id: null,
|
|
256
|
+
status: 'active',
|
|
257
|
+
created_at: now,
|
|
258
|
+
merged_at: null,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
getBranch(id) {
|
|
262
|
+
const row = this.stmts.selectBranch.get(id);
|
|
263
|
+
return row ? toBranch(row) : null;
|
|
264
|
+
}
|
|
265
|
+
getBranchByGitName(projectId, gitBranch) {
|
|
266
|
+
const row = this.stmts.selectBranchByGit.get(projectId, gitBranch);
|
|
267
|
+
return row ? toBranch(row) : null;
|
|
268
|
+
}
|
|
269
|
+
listBranches(projectId) {
|
|
270
|
+
const rows = this.stmts.selectBranches.all(projectId);
|
|
271
|
+
return rows.map(toBranch);
|
|
272
|
+
}
|
|
273
|
+
updateBranchHead(branchId, commitId) {
|
|
274
|
+
this.stmts.updateBranchHead.run(commitId, branchId);
|
|
275
|
+
}
|
|
276
|
+
markBranchMerged(branchId) {
|
|
277
|
+
this.stmts.updateBranchMerged.run(Date.now(), branchId);
|
|
278
|
+
}
|
|
279
|
+
// ─── Commits ─────────────────────────────────────────────────────────────
|
|
280
|
+
insertCommit(id, input, parentId, mergeSourceBranchId = null) {
|
|
281
|
+
const now = Date.now();
|
|
282
|
+
this.stmts.insertCommit.run({
|
|
283
|
+
id,
|
|
284
|
+
branch_id: input.branchId,
|
|
285
|
+
parent_id: parentId,
|
|
286
|
+
merge_source_branch_id: mergeSourceBranchId,
|
|
287
|
+
agent_id: input.agentId,
|
|
288
|
+
agent_role: input.agentRole,
|
|
289
|
+
tool: input.tool,
|
|
290
|
+
workflow_type: input.workflowType,
|
|
291
|
+
loop_iteration: input.loopIteration ?? null,
|
|
292
|
+
ci_run_id: input.ciRunId ?? null,
|
|
293
|
+
pipeline_name: input.pipelineName ?? null,
|
|
294
|
+
message: input.message,
|
|
295
|
+
content: input.content,
|
|
296
|
+
summary: input.summary,
|
|
297
|
+
commit_type: input.commitType,
|
|
298
|
+
git_commit_sha: input.gitCommitSha ?? null,
|
|
299
|
+
created_at: now,
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
id,
|
|
303
|
+
branchId: input.branchId,
|
|
304
|
+
parentId: parentId ?? undefined,
|
|
305
|
+
mergeSourceBranchId: mergeSourceBranchId ?? undefined,
|
|
306
|
+
agentId: input.agentId,
|
|
307
|
+
agentRole: input.agentRole,
|
|
308
|
+
tool: input.tool,
|
|
309
|
+
workflowType: input.workflowType,
|
|
310
|
+
loopIteration: input.loopIteration,
|
|
311
|
+
ciRunId: input.ciRunId,
|
|
312
|
+
pipelineName: input.pipelineName,
|
|
313
|
+
message: input.message,
|
|
314
|
+
content: input.content,
|
|
315
|
+
summary: input.summary,
|
|
316
|
+
commitType: input.commitType,
|
|
317
|
+
gitCommitSha: input.gitCommitSha,
|
|
318
|
+
createdAt: new Date(now),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
getCommit(id) {
|
|
322
|
+
const row = this.stmts.selectCommit.get(id);
|
|
323
|
+
return row ? toCommit(row) : null;
|
|
324
|
+
}
|
|
325
|
+
listCommits(branchId, pagination) {
|
|
326
|
+
const rows = this.stmts.selectCommits.all(branchId, pagination.limit, pagination.offset);
|
|
327
|
+
return rows.map(toCommit);
|
|
328
|
+
}
|
|
329
|
+
getLastCommit(branchId) {
|
|
330
|
+
const row = this.stmts.selectLastCommit.get(branchId);
|
|
331
|
+
return row ? toCommit(row) : null;
|
|
332
|
+
}
|
|
333
|
+
// ─── Threads ──────────────────────────────────────────────────────────────
|
|
334
|
+
insertThread(id, description, projectId, branchId, openedInCommit, workflowType) {
|
|
335
|
+
const now = Date.now();
|
|
336
|
+
this.stmts.insertThread.run({
|
|
337
|
+
id,
|
|
338
|
+
project_id: projectId,
|
|
339
|
+
branch_id: branchId,
|
|
340
|
+
description,
|
|
341
|
+
workflow_type: workflowType,
|
|
342
|
+
opened_in_commit: openedInCommit,
|
|
343
|
+
created_at: now,
|
|
344
|
+
});
|
|
345
|
+
return {
|
|
346
|
+
id,
|
|
347
|
+
projectId,
|
|
348
|
+
branchId,
|
|
349
|
+
description,
|
|
350
|
+
status: 'open',
|
|
351
|
+
workflowType: workflowType ?? undefined,
|
|
352
|
+
openedInCommit,
|
|
353
|
+
createdAt: new Date(now),
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
syncThread(thread) {
|
|
357
|
+
this.stmts.syncThread.run({
|
|
358
|
+
id: thread.id,
|
|
359
|
+
project_id: thread.projectId,
|
|
360
|
+
branch_id: thread.branchId,
|
|
361
|
+
description: thread.description,
|
|
362
|
+
status: thread.status,
|
|
363
|
+
workflow_type: thread.workflowType ?? null,
|
|
364
|
+
opened_in_commit: thread.openedInCommit,
|
|
365
|
+
created_at: thread.createdAt.getTime(),
|
|
366
|
+
});
|
|
367
|
+
return thread;
|
|
368
|
+
}
|
|
369
|
+
closeThread(threadId, closedInCommit, note) {
|
|
370
|
+
this.stmts.closeThread.run(closedInCommit, note, threadId);
|
|
371
|
+
}
|
|
372
|
+
listOpenThreads(projectId) {
|
|
373
|
+
const rows = this.stmts.selectOpenThreads.all(projectId);
|
|
374
|
+
return rows.map(toThread);
|
|
375
|
+
}
|
|
376
|
+
listOpenThreadsByBranch(branchId) {
|
|
377
|
+
const rows = this.stmts.selectOpenThreadsByBranch.all(branchId);
|
|
378
|
+
return rows.map(toThread);
|
|
379
|
+
}
|
|
380
|
+
/** Move open threads from source branch to target (called during merge). */
|
|
381
|
+
reassignOpenThreads(fromBranchId, toBranchId) {
|
|
382
|
+
this.stmts.reassignThreads.run(toBranchId, fromBranchId);
|
|
383
|
+
}
|
|
384
|
+
// ─── Agents ───────────────────────────────────────────────────────────────
|
|
385
|
+
upsertAgent(input) {
|
|
386
|
+
const now = Date.now();
|
|
387
|
+
const existing = this.stmts.selectAgent.get(input.id);
|
|
388
|
+
this.stmts.upsertAgent.run({
|
|
389
|
+
id: input.id,
|
|
390
|
+
project_id: input.projectId,
|
|
391
|
+
role: input.role,
|
|
392
|
+
tool: input.tool,
|
|
393
|
+
workflow_type: input.workflowType,
|
|
394
|
+
display_name: input.displayName ?? null,
|
|
395
|
+
last_seen: now,
|
|
396
|
+
created_at: existing ? existing.created_at : now,
|
|
397
|
+
});
|
|
398
|
+
const row = this.stmts.selectAgent.get(input.id);
|
|
399
|
+
return toAgent(row);
|
|
400
|
+
}
|
|
401
|
+
incrementAgentCommits(agentId) {
|
|
402
|
+
this.stmts.incrementAgentCommits.run(Date.now(), agentId);
|
|
403
|
+
}
|
|
404
|
+
listAgents(projectId) {
|
|
405
|
+
const rows = this.stmts.selectAgents.all(projectId);
|
|
406
|
+
return rows.map(toAgent);
|
|
407
|
+
}
|
|
408
|
+
// ─── Claims ───────────────────────────────────────────────────────────────
|
|
409
|
+
insertClaim(id, projectId, branchId, input) {
|
|
410
|
+
const now = Date.now();
|
|
411
|
+
const ttl = input.ttl ?? 7_200_000;
|
|
412
|
+
const status = input.status ?? 'proposed';
|
|
413
|
+
this.stmts.insertClaim.run({
|
|
414
|
+
id,
|
|
415
|
+
project_id: projectId,
|
|
416
|
+
branch_id: branchId,
|
|
417
|
+
task: input.task,
|
|
418
|
+
agent_id: input.agentId,
|
|
419
|
+
role: input.role,
|
|
420
|
+
claimed_at: now,
|
|
421
|
+
status,
|
|
422
|
+
ttl,
|
|
423
|
+
});
|
|
424
|
+
return toClaim(this.stmts.selectClaim.get(id));
|
|
425
|
+
}
|
|
426
|
+
listActiveClaims(projectId) {
|
|
427
|
+
const rows = this.stmts.listActiveClaims.all(projectId, Date.now());
|
|
428
|
+
return rows.map(toClaim);
|
|
429
|
+
}
|
|
430
|
+
updateClaimStatus(id, status, releasedAt = null) {
|
|
431
|
+
this.stmts.updateClaimStatus.run({ id, status, released_at: releasedAt });
|
|
432
|
+
}
|
|
433
|
+
releaseClaimsByAgent(agentId, branchId) {
|
|
434
|
+
this.stmts.releaseClaimsByAgent.run(Date.now(), agentId, branchId);
|
|
435
|
+
}
|
|
436
|
+
// ─── Session snapshot helpers ─────────────────────────────────────────────
|
|
437
|
+
getSessionSnapshot(projectId, branchId, options) {
|
|
438
|
+
// Project summary: head commit summary of the 'main' branch
|
|
439
|
+
const mainBranch = this.getBranchByGitName(projectId, 'main')
|
|
440
|
+
?? this.getBranchByGitName(projectId, 'master');
|
|
441
|
+
const projectSummary = mainBranch?.headCommitId
|
|
442
|
+
? (this.getCommit(mainBranch.headCommitId)?.summary ?? '')
|
|
443
|
+
: '';
|
|
444
|
+
// Branch summary: head commit summary of current branch
|
|
445
|
+
const branch = this.getBranch(branchId);
|
|
446
|
+
const branchSummary = branch?.headCommitId
|
|
447
|
+
? (this.getCommit(branch.headCommitId)?.summary ?? '')
|
|
448
|
+
: '';
|
|
449
|
+
// Last 3 commits on current branch (optionally filtered by agent role)
|
|
450
|
+
const recentCommits = options?.agentRole
|
|
451
|
+
? this.stmts.selectCommitsByRole.all(branchId, options.agentRole, 3).map(toCommit)
|
|
452
|
+
: this.listCommits(branchId, { limit: 3, offset: 0 });
|
|
453
|
+
// All open threads for the project
|
|
454
|
+
const openThreads = this.listOpenThreads(projectId);
|
|
455
|
+
const activeClaims = this.listActiveClaims(projectId);
|
|
456
|
+
return {
|
|
457
|
+
projectSummary,
|
|
458
|
+
branchName: branch?.name ?? '',
|
|
459
|
+
branchSummary,
|
|
460
|
+
recentCommits,
|
|
461
|
+
openThreads,
|
|
462
|
+
activeClaims,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
// ─── Semantic search (sqlite-vec) ─────────────────────────────────────────
|
|
466
|
+
semanticSearch(db, embeddingVector, projectId, limit) {
|
|
467
|
+
try {
|
|
468
|
+
// KNN query joining commit_embeddings with commits filtered by project
|
|
469
|
+
const stmt = db.prepare(`
|
|
470
|
+
SELECT c.*, ce.distance
|
|
471
|
+
FROM commit_embeddings ce
|
|
472
|
+
JOIN commits c ON c.id = ce.commit_id
|
|
473
|
+
JOIN branches b ON b.id = c.branch_id
|
|
474
|
+
WHERE b.project_id = ?
|
|
475
|
+
AND ce.embedding MATCH ?
|
|
476
|
+
AND k = ?
|
|
477
|
+
ORDER BY ce.distance
|
|
478
|
+
`);
|
|
479
|
+
const rows = stmt.all(projectId, embeddingVector, limit);
|
|
480
|
+
return rows.map((r) => ({
|
|
481
|
+
commit: toCommit(r),
|
|
482
|
+
score: 1 - r.distance, // cosine similarity approximation
|
|
483
|
+
matchType: 'semantic',
|
|
484
|
+
}));
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
// sqlite-vec not available or no embeddings indexed
|
|
488
|
+
return [];
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// ─── Full-text search (FTS5) ──────────────────────────────────────────────
|
|
492
|
+
fullTextSearch(db, query, projectId) {
|
|
493
|
+
try {
|
|
494
|
+
const stmt = db.prepare(`
|
|
495
|
+
SELECT c.*, bm25(commits_fts) AS score
|
|
496
|
+
FROM commits_fts
|
|
497
|
+
JOIN commits c ON c.rowid = commits_fts.rowid
|
|
498
|
+
JOIN branches b ON b.id = c.branch_id
|
|
499
|
+
WHERE b.project_id = ?
|
|
500
|
+
AND commits_fts MATCH ?
|
|
501
|
+
ORDER BY score
|
|
502
|
+
LIMIT 20
|
|
503
|
+
`);
|
|
504
|
+
const rows = stmt.all(projectId, query);
|
|
505
|
+
return rows.map((r) => ({
|
|
506
|
+
commit: toCommit(r),
|
|
507
|
+
score: Math.abs(r.score),
|
|
508
|
+
matchType: 'fulltext',
|
|
509
|
+
}));
|
|
510
|
+
}
|
|
511
|
+
catch {
|
|
512
|
+
// FTS5 migration not yet applied or query error
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
// ─── Embed helpers ────────────────────────────────────────────────────────
|
|
517
|
+
insertEmbedding(db, commitId, embedding) {
|
|
518
|
+
try {
|
|
519
|
+
const stmt = db.prepare(`INSERT OR REPLACE INTO commit_embeddings (commit_id, embedding) VALUES (?, ?)`);
|
|
520
|
+
stmt.run(commitId, embedding);
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
// sqlite-vec not available
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/local/queries.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,kFAAkF;AAClF,4CAA4C;AAqG5C,+EAA+E;AAE/E,SAAS,SAAS,CAAC,GAAe;IAChC,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,SAAS;QACzC,SAAS,EAAE,GAAG,CAAC,UAAU,IAAI,SAAS;QACtC,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;KACpC,CAAA;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,GAAc;IAC9B,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,WAAW,EAAE,GAAG,CAAC,aAAa,IAAI,SAAS;QAC3C,cAAc,EAAE,GAAG,CAAC,gBAAgB,IAAI,SAAS;QACjD,YAAY,EAAE,GAAG,CAAC,cAAc,IAAI,SAAS;QAC7C,MAAM,EAAE,GA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YACP,2BAA2B;QAC7B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const CREATE_PROJECTS = "\nCREATE TABLE IF NOT EXISTS projects (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n description TEXT,\n github_url TEXT,\n created_at INTEGER NOT NULL\n)\n";
|
|
2
|
+
export declare const CREATE_BRANCHES = "\nCREATE TABLE IF NOT EXISTS branches (\n id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL REFERENCES projects(id),\n name TEXT NOT NULL,\n git_branch TEXT NOT NULL,\n github_pr_url TEXT,\n parent_branch_id TEXT REFERENCES branches(id),\n head_commit_id TEXT,\n status TEXT NOT NULL DEFAULT 'active',\n created_at INTEGER NOT NULL,\n merged_at INTEGER\n)\n";
|
|
3
|
+
export declare const CREATE_COMMITS = "\nCREATE TABLE IF NOT EXISTS commits (\n id TEXT PRIMARY KEY,\n branch_id TEXT NOT NULL REFERENCES branches(id),\n parent_id TEXT REFERENCES commits(id),\n merge_source_branch_id TEXT REFERENCES branches(id),\n agent_id TEXT NOT NULL,\n agent_role TEXT NOT NULL DEFAULT 'solo',\n tool TEXT NOT NULL,\n workflow_type TEXT NOT NULL DEFAULT 'interactive',\n loop_iteration INTEGER,\n ci_run_id TEXT,\n pipeline_name TEXT,\n message TEXT NOT NULL,\n content TEXT NOT NULL,\n summary TEXT NOT NULL,\n commit_type TEXT NOT NULL DEFAULT 'manual',\n git_commit_sha TEXT,\n created_at INTEGER NOT NULL\n)\n";
|
|
4
|
+
export declare const CREATE_THREADS = "\nCREATE TABLE IF NOT EXISTS threads (\n id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL REFERENCES projects(id),\n branch_id TEXT NOT NULL REFERENCES branches(id),\n description TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'open',\n workflow_type TEXT,\n opened_in_commit TEXT NOT NULL REFERENCES commits(id),\n closed_in_commit TEXT REFERENCES commits(id),\n closed_note TEXT,\n created_at INTEGER NOT NULL\n)\n";
|
|
5
|
+
export declare const CREATE_AGENTS = "\nCREATE TABLE IF NOT EXISTS agents (\n id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL REFERENCES projects(id),\n role TEXT NOT NULL DEFAULT 'solo',\n tool TEXT NOT NULL,\n workflow_type TEXT NOT NULL DEFAULT 'interactive',\n display_name TEXT,\n total_commits INTEGER NOT NULL DEFAULT 0,\n last_seen INTEGER NOT NULL,\n created_at INTEGER NOT NULL\n)\n";
|
|
6
|
+
export declare const CREATE_COMMIT_EMBEDDINGS = "\nCREATE VIRTUAL TABLE IF NOT EXISTS commit_embeddings USING vec0(\n commit_id TEXT PRIMARY KEY,\n embedding FLOAT[384]\n)\n";
|
|
7
|
+
export declare const CREATE_COMMITS_FTS = "\nCREATE VIRTUAL TABLE IF NOT EXISTS commits_fts USING fts5(\n commit_id UNINDEXED,\n message,\n content,\n summary,\n content='commits',\n content_rowid='rowid'\n)\n";
|
|
8
|
+
export declare const CREATE_INDEXES: string[];
|
|
9
|
+
export declare const SCHEMA_V1_DDL: string[];
|
|
10
|
+
export declare const CREATE_FTS_TRIGGER = "\nCREATE TRIGGER IF NOT EXISTS commits_ai AFTER INSERT ON commits BEGIN\n INSERT INTO commits_fts(rowid, commit_id, message, content, summary)\n VALUES (new.rowid, new.id, new.message, new.content, new.summary);\nEND\n";
|
|
11
|
+
export declare const SCHEMA_V2_DDL: string[];
|
|
12
|
+
export declare const SCHEMA_V3_DDL: string[];
|
|
13
|
+
export declare const CREATE_CLAIMS = "\nCREATE TABLE IF NOT EXISTS claims (\n id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL REFERENCES projects(id),\n branch_id TEXT NOT NULL REFERENCES branches(id),\n task TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n role TEXT NOT NULL,\n claimed_at INTEGER NOT NULL,\n status TEXT NOT NULL DEFAULT 'proposed',\n ttl INTEGER NOT NULL,\n released_at INTEGER\n)\n";
|
|
14
|
+
export declare const SCHEMA_V4_DDL: string[];
|
|
15
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/local/schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,0LAQ3B,CAAA;AAED,eAAO,MAAM,eAAe,obAa3B,CAAA;AAED,eAAO,MAAM,cAAc,wzBAoB1B,CAAA;AAED,eAAO,MAAM,cAAc,qeAa1B,CAAA;AAED,eAAO,MAAM,aAAa,wZAYzB,CAAA;AAID,eAAO,MAAM,wBAAwB,mIAKpC,CAAA;AAGD,eAAO,MAAM,kBAAkB,iLAS9B,CAAA;AAED,eAAO,MAAM,cAAc,UAK1B,CAAA;AAGD,eAAO,MAAM,aAAa,UAOzB,CAAA;AAID,eAAO,MAAM,kBAAkB,iOAK9B,CAAA;AAGD,eAAO,MAAM,aAAa,UAEzB,CAAA;AAGD,eAAO,MAAM,aAAa,UAEzB,CAAA;AAGD,eAAO,MAAM,aAAa,0aAazB,CAAA;AAED,eAAO,MAAM,aAAa,UAGzB,CAAA"}
|