@wopr-network/defcon 0.2.0 → 0.2.2
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/src/execution/cli.js +0 -0
- package/package.json +3 -2
- package/dist/api/router.d.ts +0 -24
- package/dist/api/router.js +0 -44
- package/dist/api/server.d.ts +0 -13
- package/dist/api/server.js +0 -280
- package/dist/api/wire-types.d.ts +0 -46
- package/dist/api/wire-types.js +0 -5
- package/dist/config/db-path.d.ts +0 -1
- package/dist/config/db-path.js +0 -1
- package/dist/config/exporter.d.ts +0 -3
- package/dist/config/exporter.js +0 -87
- package/dist/config/index.d.ts +0 -4
- package/dist/config/index.js +0 -4
- package/dist/config/seed-loader.d.ts +0 -10
- package/dist/config/seed-loader.js +0 -108
- package/dist/config/zod-schemas.d.ts +0 -165
- package/dist/config/zod-schemas.js +0 -283
- package/dist/cors.d.ts +0 -8
- package/dist/cors.js +0 -21
- package/dist/engine/constants.d.ts +0 -1
- package/dist/engine/constants.js +0 -1
- package/dist/engine/engine.d.ts +0 -69
- package/dist/engine/engine.js +0 -485
- package/dist/engine/event-emitter.d.ts +0 -9
- package/dist/engine/event-emitter.js +0 -19
- package/dist/engine/event-types.d.ts +0 -105
- package/dist/engine/event-types.js +0 -1
- package/dist/engine/flow-spawner.d.ts +0 -8
- package/dist/engine/flow-spawner.js +0 -28
- package/dist/engine/gate-command-validator.d.ts +0 -6
- package/dist/engine/gate-command-validator.js +0 -46
- package/dist/engine/gate-evaluator.d.ts +0 -12
- package/dist/engine/gate-evaluator.js +0 -233
- package/dist/engine/handlebars.d.ts +0 -9
- package/dist/engine/handlebars.js +0 -51
- package/dist/engine/index.d.ts +0 -12
- package/dist/engine/index.js +0 -7
- package/dist/engine/invocation-builder.d.ts +0 -18
- package/dist/engine/invocation-builder.js +0 -58
- package/dist/engine/on-enter.d.ts +0 -8
- package/dist/engine/on-enter.js +0 -102
- package/dist/engine/ssrf-guard.d.ts +0 -22
- package/dist/engine/ssrf-guard.js +0 -159
- package/dist/engine/state-machine.d.ts +0 -12
- package/dist/engine/state-machine.js +0 -74
- package/dist/execution/active-runner.d.ts +0 -45
- package/dist/execution/active-runner.js +0 -165
- package/dist/execution/admin-schemas.d.ts +0 -116
- package/dist/execution/admin-schemas.js +0 -125
- package/dist/execution/cli.d.ts +0 -57
- package/dist/execution/cli.js +0 -498
- package/dist/execution/handlers/admin.d.ts +0 -67
- package/dist/execution/handlers/admin.js +0 -200
- package/dist/execution/handlers/flow.d.ts +0 -25
- package/dist/execution/handlers/flow.js +0 -289
- package/dist/execution/handlers/query.d.ts +0 -31
- package/dist/execution/handlers/query.js +0 -64
- package/dist/execution/index.d.ts +0 -4
- package/dist/execution/index.js +0 -3
- package/dist/execution/mcp-helpers.d.ts +0 -42
- package/dist/execution/mcp-helpers.js +0 -23
- package/dist/execution/mcp-server.d.ts +0 -33
- package/dist/execution/mcp-server.js +0 -1020
- package/dist/execution/provision-worktree.d.ts +0 -16
- package/dist/execution/provision-worktree.js +0 -123
- package/dist/execution/tool-schemas.d.ts +0 -40
- package/dist/execution/tool-schemas.js +0 -44
- package/dist/logger.d.ts +0 -8
- package/dist/logger.js +0 -12
- package/dist/main.d.ts +0 -14
- package/dist/main.js +0 -28
- package/dist/repositories/drizzle/entity.repo.d.ts +0 -27
- package/dist/repositories/drizzle/entity.repo.js +0 -190
- package/dist/repositories/drizzle/event.repo.d.ts +0 -12
- package/dist/repositories/drizzle/event.repo.js +0 -24
- package/dist/repositories/drizzle/flow.repo.d.ts +0 -22
- package/dist/repositories/drizzle/flow.repo.js +0 -364
- package/dist/repositories/drizzle/gate.repo.d.ts +0 -16
- package/dist/repositories/drizzle/gate.repo.js +0 -98
- package/dist/repositories/drizzle/index.d.ts +0 -6
- package/dist/repositories/drizzle/index.js +0 -7
- package/dist/repositories/drizzle/invocation.repo.d.ts +0 -23
- package/dist/repositories/drizzle/invocation.repo.js +0 -199
- package/dist/repositories/drizzle/schema.d.ts +0 -1932
- package/dist/repositories/drizzle/schema.js +0 -155
- package/dist/repositories/drizzle/transition-log.repo.d.ts +0 -11
- package/dist/repositories/drizzle/transition-log.repo.js +0 -42
- package/dist/repositories/interfaces.d.ts +0 -321
- package/dist/repositories/interfaces.js +0 -2
- package/dist/utils/redact.d.ts +0 -2
- package/dist/utils/redact.js +0 -62
- package/gates/blocking-graph.d.ts +0 -26
- package/gates/blocking-graph.js +0 -102
- package/gates/test/bad-return-gate.d.ts +0 -1
- package/gates/test/bad-return-gate.js +0 -4
- package/gates/test/passing-gate.d.ts +0 -2
- package/gates/test/passing-gate.js +0 -3
- package/gates/test/slow-gate.d.ts +0 -2
- package/gates/test/slow-gate.js +0 -5
- package/gates/test/throwing-gate.d.ts +0 -1
- package/gates/test/throwing-gate.js +0 -3
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { and, asc, eq, isNotNull, isNull, sql } from "drizzle-orm";
|
|
2
|
-
import { entities, invocations } from "./schema.js";
|
|
3
|
-
function toInvocation(row) {
|
|
4
|
-
return {
|
|
5
|
-
id: row.id,
|
|
6
|
-
entityId: row.entityId,
|
|
7
|
-
stage: row.stage,
|
|
8
|
-
mode: row.mode,
|
|
9
|
-
prompt: row.prompt,
|
|
10
|
-
context: row.context,
|
|
11
|
-
claimedBy: row.claimedBy,
|
|
12
|
-
claimedAt: row.claimedAt ? new Date(row.claimedAt) : null,
|
|
13
|
-
startedAt: row.startedAt ? new Date(row.startedAt) : null,
|
|
14
|
-
completedAt: row.completedAt ? new Date(row.completedAt) : null,
|
|
15
|
-
failedAt: row.failedAt ? new Date(row.failedAt) : null,
|
|
16
|
-
signal: row.signal,
|
|
17
|
-
artifacts: row.artifacts,
|
|
18
|
-
error: row.error,
|
|
19
|
-
ttlMs: row.ttlMs ?? 1800000,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export class DrizzleInvocationRepository {
|
|
23
|
-
db;
|
|
24
|
-
constructor(db) {
|
|
25
|
-
this.db = db;
|
|
26
|
-
}
|
|
27
|
-
async create(entityId, stage, prompt, mode, ttlMs, context) {
|
|
28
|
-
const id = crypto.randomUUID();
|
|
29
|
-
this.db
|
|
30
|
-
.insert(invocations)
|
|
31
|
-
.values({
|
|
32
|
-
id,
|
|
33
|
-
entityId,
|
|
34
|
-
stage,
|
|
35
|
-
prompt,
|
|
36
|
-
mode,
|
|
37
|
-
ttlMs: ttlMs ?? 1800000,
|
|
38
|
-
context: context ?? null,
|
|
39
|
-
createdAt: Date.now(),
|
|
40
|
-
})
|
|
41
|
-
.run();
|
|
42
|
-
const created = await this.get(id);
|
|
43
|
-
if (!created)
|
|
44
|
-
throw new Error(`Invocation ${id} not found after insert`);
|
|
45
|
-
return created;
|
|
46
|
-
}
|
|
47
|
-
async get(id) {
|
|
48
|
-
const rows = this.db.select().from(invocations).where(eq(invocations.id, id)).all();
|
|
49
|
-
return rows.length > 0 ? toInvocation(rows[0]) : null;
|
|
50
|
-
}
|
|
51
|
-
async claim(invocationId, agentId) {
|
|
52
|
-
const now = Date.now();
|
|
53
|
-
const result = this.db
|
|
54
|
-
.update(invocations)
|
|
55
|
-
.set({ claimedBy: agentId, claimedAt: now })
|
|
56
|
-
.where(and(eq(invocations.id, invocationId), isNull(invocations.claimedBy), isNull(invocations.completedAt), isNull(invocations.failedAt)))
|
|
57
|
-
.run();
|
|
58
|
-
if (result.changes === 0)
|
|
59
|
-
return null;
|
|
60
|
-
return this.get(invocationId);
|
|
61
|
-
}
|
|
62
|
-
async complete(id, signal, artifacts) {
|
|
63
|
-
const result = this.db
|
|
64
|
-
.update(invocations)
|
|
65
|
-
.set({ completedAt: Date.now(), signal, artifacts: artifacts ?? null })
|
|
66
|
-
.where(and(eq(invocations.id, id), isNull(invocations.completedAt), isNull(invocations.failedAt)))
|
|
67
|
-
.run();
|
|
68
|
-
if (result.changes === 0) {
|
|
69
|
-
const existing = this.db.select().from(invocations).where(eq(invocations.id, id)).all();
|
|
70
|
-
if (existing.length === 0)
|
|
71
|
-
throw new Error(`Invocation ${id} not found`);
|
|
72
|
-
if (existing[0].completedAt)
|
|
73
|
-
throw new Error(`Invocation ${id} already completed`);
|
|
74
|
-
if (existing[0].failedAt)
|
|
75
|
-
throw new Error(`Invocation ${id} already failed`);
|
|
76
|
-
throw new Error(`Invocation ${id} concurrent modification detected`);
|
|
77
|
-
}
|
|
78
|
-
const row = this.db.select().from(invocations).where(eq(invocations.id, id)).all();
|
|
79
|
-
if (row.length === 0)
|
|
80
|
-
throw new Error(`Invocation ${id} not found after update`);
|
|
81
|
-
return toInvocation(row[0]);
|
|
82
|
-
}
|
|
83
|
-
async fail(id, error) {
|
|
84
|
-
const result = this.db
|
|
85
|
-
.update(invocations)
|
|
86
|
-
.set({ failedAt: Date.now(), error })
|
|
87
|
-
.where(and(eq(invocations.id, id), isNull(invocations.completedAt), isNull(invocations.failedAt)))
|
|
88
|
-
.run();
|
|
89
|
-
if (result.changes === 0) {
|
|
90
|
-
const existing = this.db.select().from(invocations).where(eq(invocations.id, id)).all();
|
|
91
|
-
if (existing.length === 0)
|
|
92
|
-
throw new Error(`Invocation ${id} not found`);
|
|
93
|
-
if (existing[0].completedAt)
|
|
94
|
-
throw new Error(`Invocation ${id} already completed`);
|
|
95
|
-
if (existing[0].failedAt)
|
|
96
|
-
throw new Error(`Invocation ${id} already failed`);
|
|
97
|
-
throw new Error(`Invocation ${id} concurrent modification detected`);
|
|
98
|
-
}
|
|
99
|
-
const row = this.db.select().from(invocations).where(eq(invocations.id, id)).all();
|
|
100
|
-
if (row.length === 0)
|
|
101
|
-
throw new Error(`Invocation ${id} not found after update`);
|
|
102
|
-
return toInvocation(row[0]);
|
|
103
|
-
}
|
|
104
|
-
async releaseClaim(id) {
|
|
105
|
-
this.db
|
|
106
|
-
.update(invocations)
|
|
107
|
-
.set({ claimedBy: null, claimedAt: null })
|
|
108
|
-
.where(and(eq(invocations.id, id), isNull(invocations.completedAt), isNull(invocations.failedAt)))
|
|
109
|
-
.run();
|
|
110
|
-
}
|
|
111
|
-
async findByEntity(entityId) {
|
|
112
|
-
const rows = this.db
|
|
113
|
-
.select()
|
|
114
|
-
.from(invocations)
|
|
115
|
-
.where(eq(invocations.entityId, entityId))
|
|
116
|
-
// order by creation time for stable chronological ordering across databases
|
|
117
|
-
.orderBy(asc(invocations.createdAt))
|
|
118
|
-
.all();
|
|
119
|
-
return rows.map(toInvocation);
|
|
120
|
-
}
|
|
121
|
-
async findUnclaimedWithAffinity(flowId, role, workerId) {
|
|
122
|
-
const now = Date.now();
|
|
123
|
-
const rows = this.db
|
|
124
|
-
.select({ inv: invocations })
|
|
125
|
-
.from(invocations)
|
|
126
|
-
.innerJoin(entities, eq(invocations.entityId, entities.id))
|
|
127
|
-
.where(and(eq(entities.flowId, flowId), isNull(invocations.claimedBy), isNull(invocations.completedAt), isNull(invocations.failedAt), eq(entities.affinityWorkerId, workerId), eq(entities.affinityRole, role), sql `${entities.affinityExpiresAt} > ${now}`))
|
|
128
|
-
.all();
|
|
129
|
-
return rows.map((r) => toInvocation(r.inv));
|
|
130
|
-
}
|
|
131
|
-
async findUnclaimedByFlow(flowId) {
|
|
132
|
-
const rows = this.db
|
|
133
|
-
.select({ inv: invocations })
|
|
134
|
-
.from(invocations)
|
|
135
|
-
.innerJoin(entities, eq(invocations.entityId, entities.id))
|
|
136
|
-
.where(and(eq(entities.flowId, flowId), isNull(invocations.claimedBy), isNull(invocations.completedAt), isNull(invocations.failedAt)))
|
|
137
|
-
.all();
|
|
138
|
-
return rows.map((r) => toInvocation(r.inv));
|
|
139
|
-
}
|
|
140
|
-
async findByFlow(flowId) {
|
|
141
|
-
const rows = this.db
|
|
142
|
-
.select({ inv: invocations })
|
|
143
|
-
.from(invocations)
|
|
144
|
-
.innerJoin(entities, eq(invocations.entityId, entities.id))
|
|
145
|
-
.where(eq(entities.flowId, flowId))
|
|
146
|
-
// order by creation time for stable chronological ordering across databases
|
|
147
|
-
.orderBy(asc(invocations.createdAt))
|
|
148
|
-
.all();
|
|
149
|
-
return rows.map((r) => toInvocation(r.inv));
|
|
150
|
-
}
|
|
151
|
-
async findUnclaimedActive(flowId) {
|
|
152
|
-
const conditions = [
|
|
153
|
-
eq(invocations.mode, "active"),
|
|
154
|
-
isNull(invocations.claimedBy),
|
|
155
|
-
isNull(invocations.completedAt),
|
|
156
|
-
isNull(invocations.failedAt),
|
|
157
|
-
];
|
|
158
|
-
if (flowId) {
|
|
159
|
-
conditions.push(eq(entities.flowId, flowId));
|
|
160
|
-
}
|
|
161
|
-
const rows = this.db
|
|
162
|
-
.select({ inv: invocations })
|
|
163
|
-
.from(invocations)
|
|
164
|
-
.innerJoin(entities, eq(invocations.entityId, entities.id))
|
|
165
|
-
.where(and(...conditions))
|
|
166
|
-
// raw SQL: order by creation time for fair FIFO claim ordering across databases
|
|
167
|
-
.orderBy(asc(invocations.createdAt))
|
|
168
|
-
.all();
|
|
169
|
-
return rows.map((r) => toInvocation(r.inv));
|
|
170
|
-
}
|
|
171
|
-
async countActiveByFlow(flowId) {
|
|
172
|
-
const rows = this.db
|
|
173
|
-
.select({ count: sql `count(*)` })
|
|
174
|
-
.from(invocations)
|
|
175
|
-
.innerJoin(entities, eq(invocations.entityId, entities.id))
|
|
176
|
-
.where(and(eq(entities.flowId, flowId), isNotNull(invocations.claimedAt), isNull(invocations.completedAt), isNull(invocations.failedAt)))
|
|
177
|
-
.get();
|
|
178
|
-
return rows?.count ?? 0;
|
|
179
|
-
}
|
|
180
|
-
async countPendingByFlow(flowId) {
|
|
181
|
-
const rows = this.db
|
|
182
|
-
.select({ count: sql `count(*)` })
|
|
183
|
-
.from(invocations)
|
|
184
|
-
.innerJoin(entities, eq(invocations.entityId, entities.id))
|
|
185
|
-
.where(and(eq(entities.flowId, flowId), isNull(invocations.claimedAt), isNull(invocations.completedAt), isNull(invocations.failedAt)))
|
|
186
|
-
.get();
|
|
187
|
-
return rows?.count ?? 0;
|
|
188
|
-
}
|
|
189
|
-
async reapExpired() {
|
|
190
|
-
const now = Date.now();
|
|
191
|
-
const rows = this.db
|
|
192
|
-
.update(invocations)
|
|
193
|
-
.set({ claimedBy: null, claimedAt: null })
|
|
194
|
-
.where(and(isNull(invocations.completedAt), isNull(invocations.failedAt), sql `${invocations.claimedBy} IS NOT NULL`, sql `${invocations.claimedAt} + ${invocations.ttlMs} < ${now}`))
|
|
195
|
-
.returning()
|
|
196
|
-
.all();
|
|
197
|
-
return rows.map(toInvocation);
|
|
198
|
-
}
|
|
199
|
-
}
|