@blackms/aistack 1.5.2 → 1.5.4
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/README.md +61 -11
- package/dist/cli/commands/init.js +1 -1
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +22 -12
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +5 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/task-tools.d.ts +241 -1
- package/dist/mcp/tools/task-tools.d.ts.map +1 -1
- package/dist/mcp/tools/task-tools.js +308 -3
- package/dist/mcp/tools/task-tools.js.map +1 -1
- package/dist/memory/index.d.ts +6 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +2 -2
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/sqlite-store.d.ts +68 -2
- package/dist/memory/sqlite-store.d.ts.map +1 -1
- package/dist/memory/sqlite-store.js +244 -6
- package/dist/memory/sqlite-store.js.map +1 -1
- package/dist/tasks/consensus-service.d.ts +146 -0
- package/dist/tasks/consensus-service.d.ts.map +1 -0
- package/dist/tasks/consensus-service.js +405 -0
- package/dist/tasks/consensus-service.js.map +1 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +34 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/web/routes/consensus.d.ts +7 -0
- package/dist/web/routes/consensus.d.ts.map +1 -0
- package/dist/web/routes/consensus.js +218 -0
- package/dist/web/routes/consensus.js.map +1 -0
- package/dist/web/routes/index.d.ts +1 -0
- package/dist/web/routes/index.d.ts.map +1 -1
- package/dist/web/routes/index.js +1 -0
- package/dist/web/routes/index.js.map +1 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +3 -1
- package/dist/web/server.js.map +1 -1
- package/dist/web/websocket/event-bridge.d.ts +19 -1
- package/dist/web/websocket/event-bridge.d.ts.map +1 -1
- package/dist/web/websocket/event-bridge.js +4 -0
- package/dist/web/websocket/event-bridge.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* SQLite-based memory store with FTS5 full-text search
|
|
3
3
|
*/
|
|
4
4
|
import Database from 'better-sqlite3';
|
|
5
|
-
import type { MemoryEntry, MemoryStoreOptions, Session, Task, Project, ProjectTask, Specification, TaskPhase, SpecificationType, SpecificationStatus, ReviewComment, SpawnedAgent, AgentStatus, ReviewLoopState, MemoryVersion, AgentIdentity, AgentIdentityStatus, AgentCapability, AgentIdentityAuditEntry, AgentResourceMetrics, ResourceExhaustionPhase, DeliverableCheckpoint, DeliverableType, ResourceExhaustionEvent } from '../types.js';
|
|
5
|
+
import type { MemoryEntry, MemoryStoreOptions, Session, Task, Project, ProjectTask, Specification, TaskPhase, SpecificationType, SpecificationStatus, ReviewComment, SpawnedAgent, AgentStatus, ReviewLoopState, MemoryVersion, AgentIdentity, AgentIdentityStatus, AgentCapability, AgentIdentityAuditEntry, AgentResourceMetrics, ResourceExhaustionPhase, DeliverableCheckpoint, DeliverableType, ResourceExhaustionEvent, ConsensusCheckpoint, ConsensusStatus, TaskRiskLevel, ReviewerStrategy, ProposedSubtask, ConsensusDecision } from '../types.js';
|
|
6
6
|
export declare class SQLiteStore {
|
|
7
7
|
private db;
|
|
8
8
|
private readonly dbPath;
|
|
@@ -71,9 +71,19 @@ export declare class SQLiteStore {
|
|
|
71
71
|
getActiveSession(): Session | null;
|
|
72
72
|
listSessions(status?: 'active' | 'ended', limit?: number, offset?: number): Session[];
|
|
73
73
|
private rowToSession;
|
|
74
|
-
createTask(agentType: string, input?: string, sessionId?: string
|
|
74
|
+
createTask(agentType: string, input?: string, sessionId?: string, options?: {
|
|
75
|
+
riskLevel?: TaskRiskLevel;
|
|
76
|
+
parentTaskId?: string;
|
|
77
|
+
depth?: number;
|
|
78
|
+
consensusCheckpointId?: string;
|
|
79
|
+
}): Task;
|
|
75
80
|
getTask(id: string): Task | null;
|
|
76
81
|
updateTaskStatus(id: string, status: Task['status'], output?: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Delete a task and all associated data
|
|
84
|
+
* CASCADE constraints automatically clean up task_embeddings and task_relationships
|
|
85
|
+
*/
|
|
86
|
+
deleteTask(id: string): boolean;
|
|
77
87
|
listTasks(sessionId?: string, status?: Task['status']): Task[];
|
|
78
88
|
private rowToTask;
|
|
79
89
|
createProject(name: string, path: string, description?: string, metadata?: Record<string, unknown>): Project;
|
|
@@ -257,6 +267,62 @@ export declare class SQLiteStore {
|
|
|
257
267
|
private rowToAgentResourceMetrics;
|
|
258
268
|
private rowToDeliverableCheckpoint;
|
|
259
269
|
private rowToResourceExhaustionEvent;
|
|
270
|
+
/**
|
|
271
|
+
* Create a new consensus checkpoint
|
|
272
|
+
*/
|
|
273
|
+
createConsensusCheckpoint(options: {
|
|
274
|
+
id: string;
|
|
275
|
+
taskId: string;
|
|
276
|
+
parentTaskId?: string;
|
|
277
|
+
proposedSubtasks: ProposedSubtask[];
|
|
278
|
+
riskLevel: TaskRiskLevel;
|
|
279
|
+
reviewerStrategy: ReviewerStrategy;
|
|
280
|
+
timeout: number;
|
|
281
|
+
}): ConsensusCheckpoint;
|
|
282
|
+
/**
|
|
283
|
+
* Get a consensus checkpoint by ID
|
|
284
|
+
*/
|
|
285
|
+
getConsensusCheckpoint(id: string): ConsensusCheckpoint | null;
|
|
286
|
+
/**
|
|
287
|
+
* Get consensus checkpoint by task ID
|
|
288
|
+
*/
|
|
289
|
+
getConsensusCheckpointByTaskId(taskId: string): ConsensusCheckpoint | null;
|
|
290
|
+
/**
|
|
291
|
+
* Update consensus checkpoint status
|
|
292
|
+
*/
|
|
293
|
+
updateConsensusCheckpointStatus(id: string, status: ConsensusStatus, decision?: ConsensusDecision): boolean;
|
|
294
|
+
/**
|
|
295
|
+
* List pending consensus checkpoints
|
|
296
|
+
*/
|
|
297
|
+
listPendingCheckpoints(options?: {
|
|
298
|
+
limit?: number;
|
|
299
|
+
offset?: number;
|
|
300
|
+
}): ConsensusCheckpoint[];
|
|
301
|
+
/**
|
|
302
|
+
* Count total pending consensus checkpoints
|
|
303
|
+
*/
|
|
304
|
+
countPendingCheckpoints(): number;
|
|
305
|
+
/**
|
|
306
|
+
* Expire old checkpoints
|
|
307
|
+
*/
|
|
308
|
+
expireOldCheckpoints(): number;
|
|
309
|
+
/**
|
|
310
|
+
* Get checkpoint events (audit log)
|
|
311
|
+
*/
|
|
312
|
+
getConsensusCheckpointEvents(checkpointId: string, limit?: number): Array<{
|
|
313
|
+
id: string;
|
|
314
|
+
checkpointId: string;
|
|
315
|
+
eventType: string;
|
|
316
|
+
actorId?: string;
|
|
317
|
+
actorType?: string;
|
|
318
|
+
details?: Record<string, unknown>;
|
|
319
|
+
createdAt: Date;
|
|
320
|
+
}>;
|
|
321
|
+
/**
|
|
322
|
+
* Log a consensus checkpoint event
|
|
323
|
+
*/
|
|
324
|
+
private logConsensusEvent;
|
|
325
|
+
private rowToConsensusCheckpoint;
|
|
260
326
|
/**
|
|
261
327
|
* Get the underlying database instance
|
|
262
328
|
* Used for authentication and other features that need direct DB access
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-store.d.ts","sourceRoot":"","sources":["../../src/memory/sqlite-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAItC,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,IAAI,EACJ,OAAO,EACP,WAAW,EACX,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,uBAA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,iBAAiB;IAoBzB,OAAO,CAAC,wBAAwB;IAoBhC;;;OAGG;IACH,WAAW,IAAI,QAAQ,CAAC,QAAQ;IAIhC;;;OAGG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,KAAK,CAAC,GAAG,CAAC;IAKnD,KAAK,IAAI,IAAI;IAKb,MAAM,IAAI,IAAI;CAIf"}
|
|
@@ -131,7 +131,13 @@ CREATE TABLE IF NOT EXISTS tasks (
|
|
|
131
131
|
output TEXT,
|
|
132
132
|
created_at INTEGER NOT NULL,
|
|
133
133
|
completed_at INTEGER,
|
|
134
|
-
|
|
134
|
+
risk_level TEXT CHECK (risk_level IS NULL OR risk_level IN ('low', 'medium', 'high')),
|
|
135
|
+
parent_task_id TEXT,
|
|
136
|
+
depth INTEGER,
|
|
137
|
+
consensus_checkpoint_id TEXT,
|
|
138
|
+
FOREIGN KEY (session_id) REFERENCES sessions(id),
|
|
139
|
+
FOREIGN KEY (parent_task_id) REFERENCES tasks(id),
|
|
140
|
+
FOREIGN KEY (consensus_checkpoint_id) REFERENCES consensus_checkpoints(id)
|
|
135
141
|
);
|
|
136
142
|
|
|
137
143
|
CREATE INDEX IF NOT EXISTS idx_tasks_session ON tasks(session_id);
|
|
@@ -381,6 +387,42 @@ CREATE TABLE IF NOT EXISTS resource_exhaustion_events (
|
|
|
381
387
|
|
|
382
388
|
CREATE INDEX IF NOT EXISTS idx_resource_exhaustion_events_agent ON resource_exhaustion_events(agent_id);
|
|
383
389
|
CREATE INDEX IF NOT EXISTS idx_resource_exhaustion_events_created ON resource_exhaustion_events(created_at DESC);
|
|
390
|
+
|
|
391
|
+
-- Consensus Checkpoints
|
|
392
|
+
CREATE TABLE IF NOT EXISTS consensus_checkpoints (
|
|
393
|
+
id TEXT PRIMARY KEY,
|
|
394
|
+
task_id TEXT NOT NULL,
|
|
395
|
+
parent_task_id TEXT,
|
|
396
|
+
proposed_subtasks TEXT NOT NULL,
|
|
397
|
+
risk_level TEXT NOT NULL CHECK (risk_level IN ('low', 'medium', 'high')),
|
|
398
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected', 'expired')),
|
|
399
|
+
reviewer_strategy TEXT NOT NULL CHECK (reviewer_strategy IN ('adversarial', 'different-model', 'human')),
|
|
400
|
+
reviewer_id TEXT,
|
|
401
|
+
reviewer_type TEXT CHECK (reviewer_type IN ('agent', 'human')),
|
|
402
|
+
decision TEXT,
|
|
403
|
+
created_at INTEGER NOT NULL,
|
|
404
|
+
expires_at INTEGER NOT NULL,
|
|
405
|
+
decided_at INTEGER
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
CREATE INDEX IF NOT EXISTS idx_consensus_checkpoints_task ON consensus_checkpoints(task_id);
|
|
409
|
+
CREATE INDEX IF NOT EXISTS idx_consensus_checkpoints_status ON consensus_checkpoints(status);
|
|
410
|
+
CREATE INDEX IF NOT EXISTS idx_consensus_checkpoints_expires ON consensus_checkpoints(expires_at);
|
|
411
|
+
|
|
412
|
+
-- Consensus Checkpoint Events (audit log)
|
|
413
|
+
CREATE TABLE IF NOT EXISTS consensus_checkpoint_events (
|
|
414
|
+
id TEXT PRIMARY KEY,
|
|
415
|
+
checkpoint_id TEXT NOT NULL,
|
|
416
|
+
event_type TEXT NOT NULL CHECK (event_type IN ('created', 'review_started', 'approved', 'rejected', 'expired', 'subtask_rejected')),
|
|
417
|
+
actor_id TEXT,
|
|
418
|
+
actor_type TEXT CHECK (actor_type IN ('agent', 'human', 'system')),
|
|
419
|
+
details TEXT,
|
|
420
|
+
created_at INTEGER NOT NULL,
|
|
421
|
+
FOREIGN KEY (checkpoint_id) REFERENCES consensus_checkpoints(id) ON DELETE CASCADE
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
CREATE INDEX IF NOT EXISTS idx_consensus_events_checkpoint ON consensus_checkpoint_events(checkpoint_id);
|
|
425
|
+
CREATE INDEX IF NOT EXISTS idx_consensus_events_created ON consensus_checkpoint_events(created_at DESC);
|
|
384
426
|
`;
|
|
385
427
|
export class SQLiteStore {
|
|
386
428
|
db;
|
|
@@ -615,7 +657,7 @@ export class SQLiteStore {
|
|
|
615
657
|
throw new Error('Tag name can only contain lowercase letters, numbers, hyphens, and underscores');
|
|
616
658
|
}
|
|
617
659
|
// Check if entry exists
|
|
618
|
-
const entry = this.
|
|
660
|
+
const entry = this.getById(entryId);
|
|
619
661
|
if (!entry) {
|
|
620
662
|
throw new Error(`Memory entry not found: ${entryId}`);
|
|
621
663
|
}
|
|
@@ -998,15 +1040,15 @@ export class SQLiteStore {
|
|
|
998
1040
|
};
|
|
999
1041
|
}
|
|
1000
1042
|
// ==================== Task Operations ====================
|
|
1001
|
-
createTask(agentType, input, sessionId) {
|
|
1043
|
+
createTask(agentType, input, sessionId, options) {
|
|
1002
1044
|
const id = randomUUID();
|
|
1003
1045
|
const now = Date.now();
|
|
1004
1046
|
this.db
|
|
1005
1047
|
.prepare(`
|
|
1006
|
-
INSERT INTO tasks (id, session_id, agent_type, status, input, created_at)
|
|
1007
|
-
VALUES (?, ?, ?, 'pending', ?, ?)
|
|
1048
|
+
INSERT INTO tasks (id, session_id, agent_type, status, input, created_at, risk_level, parent_task_id, depth, consensus_checkpoint_id)
|
|
1049
|
+
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?)
|
|
1008
1050
|
`)
|
|
1009
|
-
.run(id, sessionId ?? null, agentType, input ?? null, now);
|
|
1051
|
+
.run(id, sessionId ?? null, agentType, input ?? null, now, options?.riskLevel ?? null, options?.parentTaskId ?? null, options?.depth ?? null, options?.consensusCheckpointId ?? null);
|
|
1010
1052
|
return {
|
|
1011
1053
|
id,
|
|
1012
1054
|
sessionId,
|
|
@@ -1014,6 +1056,10 @@ export class SQLiteStore {
|
|
|
1014
1056
|
status: 'pending',
|
|
1015
1057
|
input,
|
|
1016
1058
|
createdAt: new Date(now),
|
|
1059
|
+
riskLevel: options?.riskLevel,
|
|
1060
|
+
parentTaskId: options?.parentTaskId,
|
|
1061
|
+
depth: options?.depth,
|
|
1062
|
+
consensusCheckpointId: options?.consensusCheckpointId,
|
|
1017
1063
|
};
|
|
1018
1064
|
}
|
|
1019
1065
|
getTask(id) {
|
|
@@ -1033,6 +1079,14 @@ export class SQLiteStore {
|
|
|
1033
1079
|
.run(status, output ?? null, completedAt, id);
|
|
1034
1080
|
return result.changes > 0;
|
|
1035
1081
|
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Delete a task and all associated data
|
|
1084
|
+
* CASCADE constraints automatically clean up task_embeddings and task_relationships
|
|
1085
|
+
*/
|
|
1086
|
+
deleteTask(id) {
|
|
1087
|
+
const result = this.db.prepare('DELETE FROM tasks WHERE id = ?').run(id);
|
|
1088
|
+
return result.changes > 0;
|
|
1089
|
+
}
|
|
1036
1090
|
listTasks(sessionId, status) {
|
|
1037
1091
|
let query = 'SELECT * FROM tasks WHERE 1=1';
|
|
1038
1092
|
const params = [];
|
|
@@ -1058,6 +1112,10 @@ export class SQLiteStore {
|
|
|
1058
1112
|
output: row.output ?? undefined,
|
|
1059
1113
|
createdAt: new Date(row.created_at),
|
|
1060
1114
|
completedAt: row.completed_at ? new Date(row.completed_at) : undefined,
|
|
1115
|
+
riskLevel: row.risk_level,
|
|
1116
|
+
parentTaskId: row.parent_task_id ?? undefined,
|
|
1117
|
+
depth: row.depth ?? undefined,
|
|
1118
|
+
consensusCheckpointId: row.consensus_checkpoint_id ?? undefined,
|
|
1061
1119
|
};
|
|
1062
1120
|
}
|
|
1063
1121
|
// ==================== Project Operations ====================
|
|
@@ -1977,6 +2035,186 @@ export class SQLiteStore {
|
|
|
1977
2035
|
createdAt: new Date(row.created_at),
|
|
1978
2036
|
};
|
|
1979
2037
|
}
|
|
2038
|
+
// ==================== Consensus Checkpoint Operations ====================
|
|
2039
|
+
/**
|
|
2040
|
+
* Create a new consensus checkpoint
|
|
2041
|
+
*/
|
|
2042
|
+
createConsensusCheckpoint(options) {
|
|
2043
|
+
const now = Date.now();
|
|
2044
|
+
const expiresAt = now + options.timeout;
|
|
2045
|
+
const proposedSubtasksJson = JSON.stringify(options.proposedSubtasks);
|
|
2046
|
+
this.db
|
|
2047
|
+
.prepare(`
|
|
2048
|
+
INSERT INTO consensus_checkpoints (
|
|
2049
|
+
id, task_id, parent_task_id, proposed_subtasks, risk_level,
|
|
2050
|
+
status, reviewer_strategy, created_at, expires_at
|
|
2051
|
+
)
|
|
2052
|
+
VALUES (?, ?, ?, ?, ?, 'pending', ?, ?, ?)
|
|
2053
|
+
`)
|
|
2054
|
+
.run(options.id, options.taskId, options.parentTaskId ?? null, proposedSubtasksJson, options.riskLevel, options.reviewerStrategy, now, expiresAt);
|
|
2055
|
+
// Log event
|
|
2056
|
+
this.logConsensusEvent(options.id, 'created', undefined, undefined, {
|
|
2057
|
+
riskLevel: options.riskLevel,
|
|
2058
|
+
subtaskCount: options.proposedSubtasks.length,
|
|
2059
|
+
});
|
|
2060
|
+
return {
|
|
2061
|
+
id: options.id,
|
|
2062
|
+
taskId: options.taskId,
|
|
2063
|
+
parentTaskId: options.parentTaskId,
|
|
2064
|
+
proposedSubtasks: options.proposedSubtasks,
|
|
2065
|
+
riskLevel: options.riskLevel,
|
|
2066
|
+
status: 'pending',
|
|
2067
|
+
reviewerStrategy: options.reviewerStrategy,
|
|
2068
|
+
createdAt: new Date(now),
|
|
2069
|
+
expiresAt: new Date(expiresAt),
|
|
2070
|
+
};
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Get a consensus checkpoint by ID
|
|
2074
|
+
*/
|
|
2075
|
+
getConsensusCheckpoint(id) {
|
|
2076
|
+
const row = this.db
|
|
2077
|
+
.prepare('SELECT * FROM consensus_checkpoints WHERE id = ?')
|
|
2078
|
+
.get(id);
|
|
2079
|
+
return row ? this.rowToConsensusCheckpoint(row) : null;
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Get consensus checkpoint by task ID
|
|
2083
|
+
*/
|
|
2084
|
+
getConsensusCheckpointByTaskId(taskId) {
|
|
2085
|
+
const row = this.db
|
|
2086
|
+
.prepare('SELECT * FROM consensus_checkpoints WHERE task_id = ? ORDER BY created_at DESC LIMIT 1')
|
|
2087
|
+
.get(taskId);
|
|
2088
|
+
return row ? this.rowToConsensusCheckpoint(row) : null;
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Update consensus checkpoint status
|
|
2092
|
+
*/
|
|
2093
|
+
updateConsensusCheckpointStatus(id, status, decision) {
|
|
2094
|
+
const now = Date.now();
|
|
2095
|
+
const decisionJson = decision ? JSON.stringify(decision) : null;
|
|
2096
|
+
const result = this.db
|
|
2097
|
+
.prepare(`
|
|
2098
|
+
UPDATE consensus_checkpoints
|
|
2099
|
+
SET status = ?, decision = ?, decided_at = ?,
|
|
2100
|
+
reviewer_id = ?, reviewer_type = ?
|
|
2101
|
+
WHERE id = ?
|
|
2102
|
+
`)
|
|
2103
|
+
.run(status, decisionJson, status !== 'pending' ? now : null, decision?.reviewedBy ?? null, decision?.reviewerType ?? null, id);
|
|
2104
|
+
if (result.changes > 0) {
|
|
2105
|
+
// Log event
|
|
2106
|
+
const eventType = status === 'approved' ? 'approved' :
|
|
2107
|
+
status === 'rejected' ? 'rejected' :
|
|
2108
|
+
status === 'expired' ? 'expired' : 'created';
|
|
2109
|
+
this.logConsensusEvent(id, eventType, decision?.reviewedBy, decision?.reviewerType, { feedback: decision?.feedback });
|
|
2110
|
+
}
|
|
2111
|
+
return result.changes > 0;
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* List pending consensus checkpoints
|
|
2115
|
+
*/
|
|
2116
|
+
listPendingCheckpoints(options) {
|
|
2117
|
+
const limit = options?.limit ?? 50;
|
|
2118
|
+
const offset = options?.offset ?? 0;
|
|
2119
|
+
const rows = this.db
|
|
2120
|
+
.prepare(`
|
|
2121
|
+
SELECT * FROM consensus_checkpoints
|
|
2122
|
+
WHERE status = 'pending'
|
|
2123
|
+
ORDER BY created_at ASC
|
|
2124
|
+
LIMIT ? OFFSET ?
|
|
2125
|
+
`)
|
|
2126
|
+
.all(limit, offset);
|
|
2127
|
+
return rows.map(row => this.rowToConsensusCheckpoint(row));
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Count total pending consensus checkpoints
|
|
2131
|
+
*/
|
|
2132
|
+
countPendingCheckpoints() {
|
|
2133
|
+
const row = this.db
|
|
2134
|
+
.prepare('SELECT COUNT(*) as count FROM consensus_checkpoints WHERE status = ?')
|
|
2135
|
+
.get('pending');
|
|
2136
|
+
return row.count;
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Expire old checkpoints
|
|
2140
|
+
*/
|
|
2141
|
+
expireOldCheckpoints() {
|
|
2142
|
+
const now = Date.now();
|
|
2143
|
+
// Get checkpoints to expire
|
|
2144
|
+
const toExpire = this.db
|
|
2145
|
+
.prepare(`
|
|
2146
|
+
SELECT id FROM consensus_checkpoints
|
|
2147
|
+
WHERE status = 'pending' AND expires_at < ?
|
|
2148
|
+
`)
|
|
2149
|
+
.all(now);
|
|
2150
|
+
// Update status
|
|
2151
|
+
const result = this.db
|
|
2152
|
+
.prepare(`
|
|
2153
|
+
UPDATE consensus_checkpoints
|
|
2154
|
+
SET status = 'expired', decided_at = ?
|
|
2155
|
+
WHERE status = 'pending' AND expires_at < ?
|
|
2156
|
+
`)
|
|
2157
|
+
.run(now, now);
|
|
2158
|
+
// Log events for each expired checkpoint
|
|
2159
|
+
for (const checkpoint of toExpire) {
|
|
2160
|
+
this.logConsensusEvent(checkpoint.id, 'expired', undefined, 'system');
|
|
2161
|
+
}
|
|
2162
|
+
return result.changes;
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* Get checkpoint events (audit log)
|
|
2166
|
+
*/
|
|
2167
|
+
getConsensusCheckpointEvents(checkpointId, limit = 100) {
|
|
2168
|
+
const rows = this.db
|
|
2169
|
+
.prepare(`
|
|
2170
|
+
SELECT * FROM consensus_checkpoint_events
|
|
2171
|
+
WHERE checkpoint_id = ?
|
|
2172
|
+
ORDER BY created_at DESC
|
|
2173
|
+
LIMIT ?
|
|
2174
|
+
`)
|
|
2175
|
+
.all(checkpointId, limit);
|
|
2176
|
+
return rows.map(row => ({
|
|
2177
|
+
id: row.id,
|
|
2178
|
+
checkpointId: row.checkpoint_id,
|
|
2179
|
+
eventType: row.event_type,
|
|
2180
|
+
actorId: row.actor_id ?? undefined,
|
|
2181
|
+
actorType: row.actor_type ?? undefined,
|
|
2182
|
+
details: row.details ? JSON.parse(row.details) : undefined,
|
|
2183
|
+
createdAt: new Date(row.created_at),
|
|
2184
|
+
}));
|
|
2185
|
+
}
|
|
2186
|
+
/**
|
|
2187
|
+
* Log a consensus checkpoint event
|
|
2188
|
+
*/
|
|
2189
|
+
logConsensusEvent(checkpointId, eventType, actorId, actorType, details) {
|
|
2190
|
+
const id = randomUUID();
|
|
2191
|
+
const detailsJson = details ? JSON.stringify(details) : null;
|
|
2192
|
+
this.db
|
|
2193
|
+
.prepare(`
|
|
2194
|
+
INSERT INTO consensus_checkpoint_events (
|
|
2195
|
+
id, checkpoint_id, event_type, actor_id, actor_type, details, created_at
|
|
2196
|
+
)
|
|
2197
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
2198
|
+
`)
|
|
2199
|
+
.run(id, checkpointId, eventType, actorId ?? null, actorType ?? null, detailsJson, Date.now());
|
|
2200
|
+
}
|
|
2201
|
+
rowToConsensusCheckpoint(row) {
|
|
2202
|
+
return {
|
|
2203
|
+
id: row.id,
|
|
2204
|
+
taskId: row.task_id,
|
|
2205
|
+
parentTaskId: row.parent_task_id ?? undefined,
|
|
2206
|
+
proposedSubtasks: JSON.parse(row.proposed_subtasks),
|
|
2207
|
+
riskLevel: row.risk_level,
|
|
2208
|
+
status: row.status,
|
|
2209
|
+
reviewerStrategy: row.reviewer_strategy,
|
|
2210
|
+
reviewerId: row.reviewer_id ?? undefined,
|
|
2211
|
+
reviewerType: row.reviewer_type,
|
|
2212
|
+
decision: row.decision ? JSON.parse(row.decision) : undefined,
|
|
2213
|
+
createdAt: new Date(row.created_at),
|
|
2214
|
+
expiresAt: new Date(row.expires_at),
|
|
2215
|
+
decidedAt: row.decided_at ? new Date(row.decided_at) : undefined,
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
1980
2218
|
// ==================== Cleanup ====================
|
|
1981
2219
|
/**
|
|
1982
2220
|
* Get the underlying database instance
|