@wopr-network/defcon 0.2.0
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 +274 -0
- package/dist/api/router.d.ts +24 -0
- package/dist/api/router.js +44 -0
- package/dist/api/server.d.ts +13 -0
- package/dist/api/server.js +280 -0
- package/dist/api/wire-types.d.ts +46 -0
- package/dist/api/wire-types.js +5 -0
- package/dist/config/db-path.d.ts +1 -0
- package/dist/config/db-path.js +1 -0
- package/dist/config/exporter.d.ts +3 -0
- package/dist/config/exporter.js +87 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.js +4 -0
- package/dist/config/seed-loader.d.ts +10 -0
- package/dist/config/seed-loader.js +108 -0
- package/dist/config/zod-schemas.d.ts +165 -0
- package/dist/config/zod-schemas.js +283 -0
- package/dist/cors.d.ts +8 -0
- package/dist/cors.js +21 -0
- package/dist/engine/constants.d.ts +1 -0
- package/dist/engine/constants.js +1 -0
- package/dist/engine/engine.d.ts +69 -0
- package/dist/engine/engine.js +485 -0
- package/dist/engine/event-emitter.d.ts +9 -0
- package/dist/engine/event-emitter.js +19 -0
- package/dist/engine/event-types.d.ts +105 -0
- package/dist/engine/event-types.js +1 -0
- package/dist/engine/flow-spawner.d.ts +8 -0
- package/dist/engine/flow-spawner.js +28 -0
- package/dist/engine/gate-command-validator.d.ts +6 -0
- package/dist/engine/gate-command-validator.js +46 -0
- package/dist/engine/gate-evaluator.d.ts +12 -0
- package/dist/engine/gate-evaluator.js +233 -0
- package/dist/engine/handlebars.d.ts +9 -0
- package/dist/engine/handlebars.js +51 -0
- package/dist/engine/index.d.ts +12 -0
- package/dist/engine/index.js +7 -0
- package/dist/engine/invocation-builder.d.ts +18 -0
- package/dist/engine/invocation-builder.js +58 -0
- package/dist/engine/on-enter.d.ts +8 -0
- package/dist/engine/on-enter.js +102 -0
- package/dist/engine/ssrf-guard.d.ts +22 -0
- package/dist/engine/ssrf-guard.js +159 -0
- package/dist/engine/state-machine.d.ts +12 -0
- package/dist/engine/state-machine.js +74 -0
- package/dist/execution/active-runner.d.ts +45 -0
- package/dist/execution/active-runner.js +165 -0
- package/dist/execution/admin-schemas.d.ts +116 -0
- package/dist/execution/admin-schemas.js +125 -0
- package/dist/execution/cli.d.ts +57 -0
- package/dist/execution/cli.js +498 -0
- package/dist/execution/handlers/admin.d.ts +67 -0
- package/dist/execution/handlers/admin.js +200 -0
- package/dist/execution/handlers/flow.d.ts +25 -0
- package/dist/execution/handlers/flow.js +289 -0
- package/dist/execution/handlers/query.d.ts +31 -0
- package/dist/execution/handlers/query.js +64 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.js +3 -0
- package/dist/execution/mcp-helpers.d.ts +42 -0
- package/dist/execution/mcp-helpers.js +23 -0
- package/dist/execution/mcp-server.d.ts +33 -0
- package/dist/execution/mcp-server.js +1020 -0
- package/dist/execution/provision-worktree.d.ts +16 -0
- package/dist/execution/provision-worktree.js +123 -0
- package/dist/execution/tool-schemas.d.ts +40 -0
- package/dist/execution/tool-schemas.js +44 -0
- package/dist/gates/blocking-graph.d.ts +26 -0
- package/dist/gates/blocking-graph.js +102 -0
- package/dist/gates/test/bad-return-gate.d.ts +1 -0
- package/dist/gates/test/bad-return-gate.js +4 -0
- package/dist/gates/test/passing-gate.d.ts +2 -0
- package/dist/gates/test/passing-gate.js +3 -0
- package/dist/gates/test/slow-gate.d.ts +2 -0
- package/dist/gates/test/slow-gate.js +5 -0
- package/dist/gates/test/throwing-gate.d.ts +1 -0
- package/dist/gates/test/throwing-gate.js +3 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +12 -0
- package/dist/main.d.ts +14 -0
- package/dist/main.js +28 -0
- package/dist/repositories/drizzle/entity.repo.d.ts +27 -0
- package/dist/repositories/drizzle/entity.repo.js +190 -0
- package/dist/repositories/drizzle/event.repo.d.ts +12 -0
- package/dist/repositories/drizzle/event.repo.js +24 -0
- package/dist/repositories/drizzle/flow.repo.d.ts +22 -0
- package/dist/repositories/drizzle/flow.repo.js +364 -0
- package/dist/repositories/drizzle/gate.repo.d.ts +16 -0
- package/dist/repositories/drizzle/gate.repo.js +98 -0
- package/dist/repositories/drizzle/index.d.ts +6 -0
- package/dist/repositories/drizzle/index.js +7 -0
- package/dist/repositories/drizzle/invocation.repo.d.ts +23 -0
- package/dist/repositories/drizzle/invocation.repo.js +199 -0
- package/dist/repositories/drizzle/schema.d.ts +1932 -0
- package/dist/repositories/drizzle/schema.js +155 -0
- package/dist/repositories/drizzle/transition-log.repo.d.ts +11 -0
- package/dist/repositories/drizzle/transition-log.repo.js +42 -0
- package/dist/repositories/interfaces.d.ts +321 -0
- package/dist/repositories/interfaces.js +2 -0
- package/dist/src/api/router.d.ts +24 -0
- package/dist/src/api/router.js +44 -0
- package/dist/src/api/server.d.ts +13 -0
- package/dist/src/api/server.js +280 -0
- package/dist/src/api/wire-types.d.ts +46 -0
- package/dist/src/api/wire-types.js +5 -0
- package/dist/src/config/db-path.d.ts +1 -0
- package/dist/src/config/db-path.js +1 -0
- package/dist/src/config/exporter.d.ts +3 -0
- package/dist/src/config/exporter.js +87 -0
- package/dist/src/config/index.d.ts +4 -0
- package/dist/src/config/index.js +4 -0
- package/dist/src/config/seed-loader.d.ts +14 -0
- package/dist/src/config/seed-loader.js +131 -0
- package/dist/src/config/zod-schemas.d.ts +165 -0
- package/dist/src/config/zod-schemas.js +283 -0
- package/dist/src/cors.d.ts +8 -0
- package/dist/src/cors.js +21 -0
- package/dist/src/engine/constants.d.ts +1 -0
- package/dist/src/engine/constants.js +1 -0
- package/dist/src/engine/engine.d.ts +69 -0
- package/dist/src/engine/engine.js +485 -0
- package/dist/src/engine/event-emitter.d.ts +9 -0
- package/dist/src/engine/event-emitter.js +19 -0
- package/dist/src/engine/event-types.d.ts +105 -0
- package/dist/src/engine/event-types.js +1 -0
- package/dist/src/engine/flow-spawner.d.ts +8 -0
- package/dist/src/engine/flow-spawner.js +28 -0
- package/dist/src/engine/gate-command-validator.d.ts +6 -0
- package/dist/src/engine/gate-command-validator.js +46 -0
- package/dist/src/engine/gate-evaluator.d.ts +12 -0
- package/dist/src/engine/gate-evaluator.js +233 -0
- package/dist/src/engine/handlebars.d.ts +9 -0
- package/dist/src/engine/handlebars.js +51 -0
- package/dist/src/engine/index.d.ts +12 -0
- package/dist/src/engine/index.js +7 -0
- package/dist/src/engine/invocation-builder.d.ts +18 -0
- package/dist/src/engine/invocation-builder.js +58 -0
- package/dist/src/engine/on-enter.d.ts +8 -0
- package/dist/src/engine/on-enter.js +102 -0
- package/dist/src/engine/ssrf-guard.d.ts +22 -0
- package/dist/src/engine/ssrf-guard.js +159 -0
- package/dist/src/engine/state-machine.d.ts +12 -0
- package/dist/src/engine/state-machine.js +74 -0
- package/dist/src/execution/active-runner.d.ts +45 -0
- package/dist/src/execution/active-runner.js +165 -0
- package/dist/src/execution/admin-schemas.d.ts +116 -0
- package/dist/src/execution/admin-schemas.js +125 -0
- package/dist/src/execution/cli.d.ts +57 -0
- package/dist/src/execution/cli.js +501 -0
- package/dist/src/execution/handlers/admin.d.ts +67 -0
- package/dist/src/execution/handlers/admin.js +200 -0
- package/dist/src/execution/handlers/flow.d.ts +25 -0
- package/dist/src/execution/handlers/flow.js +289 -0
- package/dist/src/execution/handlers/query.d.ts +31 -0
- package/dist/src/execution/handlers/query.js +64 -0
- package/dist/src/execution/index.d.ts +4 -0
- package/dist/src/execution/index.js +3 -0
- package/dist/src/execution/mcp-helpers.d.ts +42 -0
- package/dist/src/execution/mcp-helpers.js +23 -0
- package/dist/src/execution/mcp-server.d.ts +33 -0
- package/dist/src/execution/mcp-server.js +1020 -0
- package/dist/src/execution/provision-worktree.d.ts +16 -0
- package/dist/src/execution/provision-worktree.js +123 -0
- package/dist/src/execution/tool-schemas.d.ts +40 -0
- package/dist/src/execution/tool-schemas.js +44 -0
- package/dist/src/logger.d.ts +8 -0
- package/dist/src/logger.js +12 -0
- package/dist/src/main.d.ts +14 -0
- package/dist/src/main.js +28 -0
- package/dist/src/repositories/drizzle/entity.repo.d.ts +27 -0
- package/dist/src/repositories/drizzle/entity.repo.js +190 -0
- package/dist/src/repositories/drizzle/event.repo.d.ts +12 -0
- package/dist/src/repositories/drizzle/event.repo.js +24 -0
- package/dist/src/repositories/drizzle/flow.repo.d.ts +22 -0
- package/dist/src/repositories/drizzle/flow.repo.js +364 -0
- package/dist/src/repositories/drizzle/gate.repo.d.ts +16 -0
- package/dist/src/repositories/drizzle/gate.repo.js +98 -0
- package/dist/src/repositories/drizzle/index.d.ts +6 -0
- package/dist/src/repositories/drizzle/index.js +7 -0
- package/dist/src/repositories/drizzle/invocation.repo.d.ts +23 -0
- package/dist/src/repositories/drizzle/invocation.repo.js +199 -0
- package/dist/src/repositories/drizzle/schema.d.ts +1932 -0
- package/dist/src/repositories/drizzle/schema.js +155 -0
- package/dist/src/repositories/drizzle/transition-log.repo.d.ts +11 -0
- package/dist/src/repositories/drizzle/transition-log.repo.js +42 -0
- package/dist/src/repositories/interfaces.d.ts +321 -0
- package/dist/src/repositories/interfaces.js +2 -0
- package/dist/src/utils/redact.d.ts +2 -0
- package/dist/src/utils/redact.js +62 -0
- package/dist/utils/redact.d.ts +2 -0
- package/dist/utils/redact.js +62 -0
- package/drizzle/.gitkeep +0 -0
- package/drizzle/0000_simple_surge.sql +144 -0
- package/drizzle/0001_peaceful_marvel_apes.sql +18 -0
- package/drizzle/0002_add_invocations_created_at.sql +1 -0
- package/drizzle/0003_drop_integration_config.sql +1 -0
- package/drizzle/0004_add_flow_discipline.sql +2 -0
- package/drizzle/0004_lucky_silverclaw.sql +5 -0
- package/drizzle/0005_old_blue_shield.sql +2 -0
- package/drizzle/0006_solid_magik.sql +2 -0
- package/drizzle/0007_fancy_luke_cage.sql +1 -0
- package/drizzle/0008_thick_dark_beast.sql +1 -0
- package/drizzle/0009_brief_midnight.sql +1 -0
- package/drizzle/0010_amusing_bastion.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +996 -0
- package/drizzle/meta/0004_snapshot.json +1008 -0
- package/drizzle/meta/0005_snapshot.json +1023 -0
- package/drizzle/meta/0006_snapshot.json +1037 -0
- package/drizzle/meta/0007_snapshot.json +1044 -0
- package/drizzle/meta/0008_snapshot.json +1051 -0
- package/drizzle/meta/0009_snapshot.json +1058 -0
- package/drizzle/meta/0010_snapshot.json +1065 -0
- package/drizzle/meta/_journal.json +83 -0
- package/gates/.gitkeep +0 -0
- package/gates/blocking-graph.d.ts +26 -0
- package/gates/blocking-graph.js +102 -0
- package/gates/blocking-graph.ts +121 -0
- package/gates/check-design-posted.sh +39 -0
- package/gates/check-merge.sh +51 -0
- package/gates/check-pr-capacity.sh +17 -0
- package/gates/check-review-ready.sh +47 -0
- package/gates/check-spec-posted.sh +34 -0
- package/gates/check-unblocked.sh +56 -0
- package/gates/ci-green.sh +9 -0
- package/gates/merge-queue.sh +14 -0
- package/gates/review-bots-ready.sh +9 -0
- package/gates/spec-posted.sh +31 -0
- package/gates/test/bad-return-gate.d.ts +1 -0
- package/gates/test/bad-return-gate.js +4 -0
- package/gates/test/bad-return-gate.ts +4 -0
- package/gates/test/passing-gate.d.ts +2 -0
- package/gates/test/passing-gate.js +3 -0
- package/gates/test/passing-gate.ts +5 -0
- package/gates/test/slow-gate.d.ts +2 -0
- package/gates/test/slow-gate.js +5 -0
- package/gates/test/slow-gate.ts +7 -0
- package/gates/test/throwing-gate.d.ts +1 -0
- package/gates/test/throwing-gate.js +3 -0
- package/gates/test/throwing-gate.ts +3 -0
- package/gates/test-fail.sh +2 -0
- package/gates/test-pass.sh +2 -0
- package/gates/timeout-gate-script.sh +3 -0
- package/package.json +64 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for defcon's REST and MCP APIs.
|
|
3
|
+
* Exported for consumers (e.g. norad) to import instead of duplicating.
|
|
4
|
+
*/
|
|
5
|
+
export type ClaimResponse = {
|
|
6
|
+
next_action: "check_back";
|
|
7
|
+
retry_after_ms: number;
|
|
8
|
+
message: string;
|
|
9
|
+
} | {
|
|
10
|
+
worker_id?: string;
|
|
11
|
+
entity_id: string;
|
|
12
|
+
invocation_id: string;
|
|
13
|
+
flow: string | null;
|
|
14
|
+
stage: string;
|
|
15
|
+
prompt: string;
|
|
16
|
+
context: Record<string, unknown> | null;
|
|
17
|
+
worker_notice?: string;
|
|
18
|
+
};
|
|
19
|
+
export type ReportResponse = {
|
|
20
|
+
next_action: "continue";
|
|
21
|
+
new_state: string;
|
|
22
|
+
gates_passed?: string[];
|
|
23
|
+
prompt: string | null;
|
|
24
|
+
context: Record<string, unknown> | null;
|
|
25
|
+
} | {
|
|
26
|
+
next_action: "waiting";
|
|
27
|
+
new_state: null;
|
|
28
|
+
gated: true;
|
|
29
|
+
gate_output: string;
|
|
30
|
+
gateName: string;
|
|
31
|
+
failure_prompt: string | null;
|
|
32
|
+
} | {
|
|
33
|
+
next_action: "check_back";
|
|
34
|
+
message: string;
|
|
35
|
+
retry_after_ms: number;
|
|
36
|
+
timeout_prompt?: string;
|
|
37
|
+
} | {
|
|
38
|
+
next_action: "completed";
|
|
39
|
+
new_state: string;
|
|
40
|
+
gates_passed?: string[];
|
|
41
|
+
prompt: null;
|
|
42
|
+
context: null;
|
|
43
|
+
};
|
|
44
|
+
export interface CreateEntityResponse {
|
|
45
|
+
id: string;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DB_PATH = "./agentic-flow.db";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DB_PATH = "./agentic-flow.db";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export async function exportSeed(flowRepo, gateRepo) {
|
|
2
|
+
const flows = await flowRepo.listAll();
|
|
3
|
+
// Fetch all gates once, build ID->name map (no N+1)
|
|
4
|
+
const allGates = await gateRepo.listAll();
|
|
5
|
+
const gateIdToName = new Map(allGates.map((g) => [g.id, g.name]));
|
|
6
|
+
const gateById = new Map(allGates.map((g) => [g.id, g]));
|
|
7
|
+
const exportedFlows = flows.filter((f) => f.discipline !== null);
|
|
8
|
+
// Collect gate IDs referenced by transitions of exported flows only
|
|
9
|
+
const referencedGateIds = new Set();
|
|
10
|
+
for (const flow of exportedFlows) {
|
|
11
|
+
for (const t of flow.transitions) {
|
|
12
|
+
if (t.gateId)
|
|
13
|
+
referencedGateIds.add(t.gateId);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Build gates array from referenced gates (already loaded)
|
|
17
|
+
const gateEntries = [];
|
|
18
|
+
for (const gateId of referencedGateIds) {
|
|
19
|
+
const gate = gateById.get(gateId);
|
|
20
|
+
if (!gate)
|
|
21
|
+
continue;
|
|
22
|
+
if (gate.type === "command" && gate.command) {
|
|
23
|
+
gateEntries.push({
|
|
24
|
+
name: gate.name,
|
|
25
|
+
type: "command",
|
|
26
|
+
command: gate.command,
|
|
27
|
+
timeoutMs: gate.timeoutMs ?? undefined,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else if (gate.type === "function" && gate.functionRef) {
|
|
31
|
+
gateEntries.push({
|
|
32
|
+
name: gate.name,
|
|
33
|
+
type: "function",
|
|
34
|
+
functionRef: gate.functionRef,
|
|
35
|
+
timeoutMs: gate.timeoutMs ?? undefined,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else if (gate.type === "api" && gate.apiConfig) {
|
|
39
|
+
gateEntries.push({
|
|
40
|
+
name: gate.name,
|
|
41
|
+
type: "api",
|
|
42
|
+
apiConfig: gate.apiConfig,
|
|
43
|
+
timeoutMs: gate.timeoutMs ?? undefined,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const seedFlows = exportedFlows.map((f) => ({
|
|
48
|
+
name: f.name,
|
|
49
|
+
description: f.description ?? undefined,
|
|
50
|
+
entitySchema: f.entitySchema ?? undefined,
|
|
51
|
+
initialState: f.initialState,
|
|
52
|
+
maxConcurrent: f.maxConcurrent,
|
|
53
|
+
maxConcurrentPerRepo: f.maxConcurrentPerRepo,
|
|
54
|
+
affinityWindowMs: f.affinityWindowMs,
|
|
55
|
+
gateTimeoutMs: f.gateTimeoutMs ?? undefined,
|
|
56
|
+
version: f.version,
|
|
57
|
+
createdBy: f.createdBy ?? undefined,
|
|
58
|
+
discipline: f.discipline,
|
|
59
|
+
defaultModelTier: f.defaultModelTier ?? undefined,
|
|
60
|
+
timeoutPrompt: f.timeoutPrompt ?? undefined,
|
|
61
|
+
}));
|
|
62
|
+
const seedStates = exportedFlows.flatMap((f) => f.states.map((s) => ({
|
|
63
|
+
name: s.name,
|
|
64
|
+
flowName: f.name,
|
|
65
|
+
modelTier: s.modelTier ?? undefined,
|
|
66
|
+
mode: s.mode,
|
|
67
|
+
promptTemplate: s.promptTemplate ?? undefined,
|
|
68
|
+
constraints: s.constraints ?? undefined,
|
|
69
|
+
})));
|
|
70
|
+
const seedTransitions = exportedFlows.flatMap((f) => f.transitions.map((t) => ({
|
|
71
|
+
flowName: f.name,
|
|
72
|
+
fromState: t.fromState,
|
|
73
|
+
toState: t.toState,
|
|
74
|
+
trigger: t.trigger,
|
|
75
|
+
gateName: t.gateId ? gateIdToName.get(t.gateId) : undefined,
|
|
76
|
+
condition: t.condition ?? undefined,
|
|
77
|
+
priority: t.priority,
|
|
78
|
+
spawnFlow: t.spawnFlow ?? undefined,
|
|
79
|
+
spawnTemplate: t.spawnTemplate ?? undefined,
|
|
80
|
+
})));
|
|
81
|
+
return {
|
|
82
|
+
flows: seedFlows,
|
|
83
|
+
states: seedStates,
|
|
84
|
+
gates: gateEntries,
|
|
85
|
+
transitions: seedTransitions,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type Database from "better-sqlite3";
|
|
2
|
+
import type { IFlowRepository, IGateRepository } from "../repositories/interfaces.js";
|
|
3
|
+
export interface LoadSeedOptions {
|
|
4
|
+
allowedRoot?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface LoadSeedResult {
|
|
7
|
+
flows: number;
|
|
8
|
+
gates: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function loadSeed(seedPath: string, flowRepo: IFlowRepository, gateRepo: IGateRepository, sqlite: InstanceType<typeof Database>, options?: LoadSeedOptions): Promise<LoadSeedResult>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { relative, resolve, sep } from "node:path";
|
|
3
|
+
import { SeedFileSchema } from "./zod-schemas.js";
|
|
4
|
+
export async function loadSeed(seedPath, flowRepo, gateRepo, sqlite, options) {
|
|
5
|
+
const allowedRoot = options?.allowedRoot ?? process.cwd();
|
|
6
|
+
const resolvedRoot = resolve(allowedRoot);
|
|
7
|
+
const resolvedSeed = resolve(seedPath);
|
|
8
|
+
const lexicalRel = relative(resolvedRoot, resolvedSeed);
|
|
9
|
+
if (lexicalRel === ".." || lexicalRel.startsWith(`..${sep}`)) {
|
|
10
|
+
throw new Error(`Seed path escapes allowed root: ${resolvedSeed} is not under ${resolvedRoot}`);
|
|
11
|
+
}
|
|
12
|
+
const realSeed = realpathSync(resolvedSeed);
|
|
13
|
+
let realRoot;
|
|
14
|
+
try {
|
|
15
|
+
realRoot = realpathSync(resolvedRoot);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
realRoot = resolvedRoot;
|
|
19
|
+
}
|
|
20
|
+
const realRel = relative(realRoot, realSeed);
|
|
21
|
+
if (realRel === ".." || realRel.startsWith(`..${sep}`)) {
|
|
22
|
+
throw new Error(`Seed path escapes allowed root: resolved symlink ${realSeed} is not under ${realRoot}`);
|
|
23
|
+
}
|
|
24
|
+
const raw = readFileSync(realSeed, "utf-8");
|
|
25
|
+
return parseSeedAndLoad(parseJson(raw, realSeed), flowRepo, gateRepo, sqlite);
|
|
26
|
+
}
|
|
27
|
+
function parseJson(raw, path) {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
33
|
+
throw new Error(`Invalid JSON in seed file: ${path}: ${msg}`, { cause: e });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function parseSeedAndLoad(json, flowRepo, gateRepo, sqlite) {
|
|
37
|
+
const parsed = SeedFileSchema.parse(json);
|
|
38
|
+
sqlite.exec("BEGIN");
|
|
39
|
+
try {
|
|
40
|
+
// 1. Create gates first (transitions reference them by name)
|
|
41
|
+
const gateNameToId = new Map();
|
|
42
|
+
for (const g of parsed.gates) {
|
|
43
|
+
const gate = await gateRepo.create({
|
|
44
|
+
name: g.name,
|
|
45
|
+
type: g.type,
|
|
46
|
+
command: "command" in g ? g.command : undefined,
|
|
47
|
+
functionRef: "functionRef" in g ? g.functionRef : undefined,
|
|
48
|
+
apiConfig: "apiConfig" in g ? g.apiConfig : undefined,
|
|
49
|
+
timeoutMs: g.timeoutMs,
|
|
50
|
+
failurePrompt: g.failurePrompt,
|
|
51
|
+
timeoutPrompt: g.timeoutPrompt,
|
|
52
|
+
});
|
|
53
|
+
gateNameToId.set(g.name, gate.id);
|
|
54
|
+
}
|
|
55
|
+
// 2. Create flows, states, and transitions
|
|
56
|
+
for (const f of parsed.flows) {
|
|
57
|
+
const flow = await flowRepo.create({
|
|
58
|
+
name: f.name,
|
|
59
|
+
description: f.description,
|
|
60
|
+
entitySchema: f.entitySchema,
|
|
61
|
+
initialState: f.initialState,
|
|
62
|
+
maxConcurrent: f.maxConcurrent,
|
|
63
|
+
maxConcurrentPerRepo: f.maxConcurrentPerRepo,
|
|
64
|
+
gateTimeoutMs: f.gateTimeoutMs,
|
|
65
|
+
createdBy: f.createdBy,
|
|
66
|
+
discipline: f.discipline,
|
|
67
|
+
defaultModelTier: f.defaultModelTier,
|
|
68
|
+
timeoutPrompt: f.timeoutPrompt,
|
|
69
|
+
});
|
|
70
|
+
const flowStates = parsed.states.filter((s) => s.flowName === f.name);
|
|
71
|
+
for (const s of flowStates) {
|
|
72
|
+
await flowRepo.addState(flow.id, {
|
|
73
|
+
name: s.name,
|
|
74
|
+
modelTier: s.modelTier,
|
|
75
|
+
mode: s.mode,
|
|
76
|
+
promptTemplate: s.promptTemplate,
|
|
77
|
+
constraints: s.constraints,
|
|
78
|
+
onEnter: s.onEnter,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const flowTransitions = parsed.transitions.filter((t) => t.flowName === f.name);
|
|
82
|
+
for (const t of flowTransitions) {
|
|
83
|
+
if (t.gateName && !gateNameToId.has(t.gateName)) {
|
|
84
|
+
throw new Error(`Transition from "${t.fromState}" to "${t.toState}" in flow "${f.name}" references unknown gate "${t.gateName}"`);
|
|
85
|
+
}
|
|
86
|
+
await flowRepo.addTransition(flow.id, {
|
|
87
|
+
fromState: t.fromState,
|
|
88
|
+
toState: t.toState,
|
|
89
|
+
trigger: t.trigger,
|
|
90
|
+
gateId: t.gateName ? gateNameToId.get(t.gateName) : undefined,
|
|
91
|
+
condition: t.condition,
|
|
92
|
+
priority: t.priority,
|
|
93
|
+
spawnFlow: t.spawnFlow,
|
|
94
|
+
spawnTemplate: t.spawnTemplate,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
sqlite.exec("COMMIT");
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
sqlite.exec("ROLLBACK");
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
flows: parsed.flows.length,
|
|
106
|
+
gates: parsed.gates.length,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const FlowDefinitionSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
description: z.ZodOptional<z.ZodString>;
|
|
5
|
+
entitySchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
6
|
+
initialState: z.ZodString;
|
|
7
|
+
maxConcurrent: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
8
|
+
maxConcurrentPerRepo: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
9
|
+
affinityWindowMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
10
|
+
gateTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
12
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
13
|
+
discipline: z.ZodString;
|
|
14
|
+
defaultModelTier: z.ZodOptional<z.ZodString>;
|
|
15
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const OnEnterSchema: z.ZodObject<{
|
|
18
|
+
command: z.ZodString;
|
|
19
|
+
artifacts: z.ZodArray<z.ZodString>;
|
|
20
|
+
timeout_ms: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export declare const StateDefinitionSchema: z.ZodObject<{
|
|
23
|
+
name: z.ZodString;
|
|
24
|
+
flowName: z.ZodString;
|
|
25
|
+
modelTier: z.ZodOptional<z.ZodString>;
|
|
26
|
+
mode: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
27
|
+
passive: "passive";
|
|
28
|
+
active: "active";
|
|
29
|
+
}>>>;
|
|
30
|
+
promptTemplate: z.ZodOptional<z.ZodString>;
|
|
31
|
+
constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
32
|
+
onEnter: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
command: z.ZodString;
|
|
34
|
+
artifacts: z.ZodArray<z.ZodString>;
|
|
35
|
+
timeout_ms: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export declare const CommandGateSchema: z.ZodObject<{
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
42
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
43
|
+
type: z.ZodLiteral<"command">;
|
|
44
|
+
command: z.ZodString;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
export declare const FunctionGateSchema: z.ZodObject<{
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
50
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
51
|
+
type: z.ZodLiteral<"function">;
|
|
52
|
+
functionRef: z.ZodString;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export declare const ApiGateSchema: z.ZodObject<{
|
|
55
|
+
name: z.ZodString;
|
|
56
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
58
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
59
|
+
type: z.ZodLiteral<"api">;
|
|
60
|
+
apiConfig: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
export declare const GateDefinitionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
63
|
+
name: z.ZodString;
|
|
64
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
66
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
67
|
+
type: z.ZodLiteral<"command">;
|
|
68
|
+
command: z.ZodString;
|
|
69
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
70
|
+
name: z.ZodString;
|
|
71
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
72
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
73
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
74
|
+
type: z.ZodLiteral<"function">;
|
|
75
|
+
functionRef: z.ZodString;
|
|
76
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
77
|
+
name: z.ZodString;
|
|
78
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
80
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
81
|
+
type: z.ZodLiteral<"api">;
|
|
82
|
+
apiConfig: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
83
|
+
}, z.core.$strip>], "type">;
|
|
84
|
+
export declare const TransitionRuleSchema: z.ZodObject<{
|
|
85
|
+
flowName: z.ZodString;
|
|
86
|
+
fromState: z.ZodString;
|
|
87
|
+
toState: z.ZodString;
|
|
88
|
+
trigger: z.ZodString;
|
|
89
|
+
gateName: z.ZodOptional<z.ZodString>;
|
|
90
|
+
condition: z.ZodOptional<z.ZodString>;
|
|
91
|
+
priority: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
92
|
+
spawnFlow: z.ZodOptional<z.ZodString>;
|
|
93
|
+
spawnTemplate: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
export declare const SeedFileSchema: z.ZodObject<{
|
|
96
|
+
flows: z.ZodArray<z.ZodObject<{
|
|
97
|
+
name: z.ZodString;
|
|
98
|
+
description: z.ZodOptional<z.ZodString>;
|
|
99
|
+
entitySchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
100
|
+
initialState: z.ZodString;
|
|
101
|
+
maxConcurrent: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
102
|
+
maxConcurrentPerRepo: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
103
|
+
affinityWindowMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
104
|
+
gateTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
105
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
106
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
107
|
+
discipline: z.ZodString;
|
|
108
|
+
defaultModelTier: z.ZodOptional<z.ZodString>;
|
|
109
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
110
|
+
}, z.core.$strip>>;
|
|
111
|
+
states: z.ZodArray<z.ZodObject<{
|
|
112
|
+
name: z.ZodString;
|
|
113
|
+
flowName: z.ZodString;
|
|
114
|
+
modelTier: z.ZodOptional<z.ZodString>;
|
|
115
|
+
mode: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
116
|
+
passive: "passive";
|
|
117
|
+
active: "active";
|
|
118
|
+
}>>>;
|
|
119
|
+
promptTemplate: z.ZodOptional<z.ZodString>;
|
|
120
|
+
constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
121
|
+
onEnter: z.ZodOptional<z.ZodObject<{
|
|
122
|
+
command: z.ZodString;
|
|
123
|
+
artifacts: z.ZodArray<z.ZodString>;
|
|
124
|
+
timeout_ms: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
125
|
+
}, z.core.$strip>>;
|
|
126
|
+
}, z.core.$strip>>;
|
|
127
|
+
gates: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
128
|
+
name: z.ZodString;
|
|
129
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
130
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
131
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
132
|
+
type: z.ZodLiteral<"command">;
|
|
133
|
+
command: z.ZodString;
|
|
134
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
135
|
+
name: z.ZodString;
|
|
136
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
137
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
138
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
139
|
+
type: z.ZodLiteral<"function">;
|
|
140
|
+
functionRef: z.ZodString;
|
|
141
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
142
|
+
name: z.ZodString;
|
|
143
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
failurePrompt: z.ZodOptional<z.ZodString>;
|
|
145
|
+
timeoutPrompt: z.ZodOptional<z.ZodString>;
|
|
146
|
+
type: z.ZodLiteral<"api">;
|
|
147
|
+
apiConfig: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
148
|
+
}, z.core.$strip>], "type">>>>;
|
|
149
|
+
transitions: z.ZodArray<z.ZodObject<{
|
|
150
|
+
flowName: z.ZodString;
|
|
151
|
+
fromState: z.ZodString;
|
|
152
|
+
toState: z.ZodString;
|
|
153
|
+
trigger: z.ZodString;
|
|
154
|
+
gateName: z.ZodOptional<z.ZodString>;
|
|
155
|
+
condition: z.ZodOptional<z.ZodString>;
|
|
156
|
+
priority: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
157
|
+
spawnFlow: z.ZodOptional<z.ZodString>;
|
|
158
|
+
spawnTemplate: z.ZodOptional<z.ZodString>;
|
|
159
|
+
}, z.core.$strip>>;
|
|
160
|
+
}, z.core.$strict>;
|
|
161
|
+
export type FlowDefinition = z.infer<typeof FlowDefinitionSchema>;
|
|
162
|
+
export type StateDefinition = z.infer<typeof StateDefinitionSchema>;
|
|
163
|
+
export type GateDefinition = z.infer<typeof GateDefinitionSchema>;
|
|
164
|
+
export type TransitionRule = z.infer<typeof TransitionRuleSchema>;
|
|
165
|
+
export type SeedFile = z.infer<typeof SeedFileSchema>;
|