@telora/factory 0.4.5
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/audit.d.ts +69 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +376 -0
- package/dist/audit.js.map +1 -0
- package/dist/builder-completion.d.ts +35 -0
- package/dist/builder-completion.d.ts.map +1 -0
- package/dist/builder-completion.js +375 -0
- package/dist/builder-completion.js.map +1 -0
- package/dist/builder-spawner.d.ts +40 -0
- package/dist/builder-spawner.d.ts.map +1 -0
- package/dist/builder-spawner.js +493 -0
- package/dist/builder-spawner.js.map +1 -0
- package/dist/completion-gate.d.ts +52 -0
- package/dist/completion-gate.d.ts.map +1 -0
- package/dist/completion-gate.js +336 -0
- package/dist/completion-gate.js.map +1 -0
- package/dist/completion-report.d.ts +36 -0
- package/dist/completion-report.d.ts.map +1 -0
- package/dist/completion-report.js +348 -0
- package/dist/completion-report.js.map +1 -0
- package/dist/completion.d.ts +58 -0
- package/dist/completion.d.ts.map +1 -0
- package/dist/completion.js +287 -0
- package/dist/completion.js.map +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +57 -0
- package/dist/config.js.map +1 -0
- package/dist/context-manager.d.ts +152 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +421 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/crash-detection.d.ts +70 -0
- package/dist/crash-detection.d.ts.map +1 -0
- package/dist/crash-detection.js +123 -0
- package/dist/crash-detection.js.map +1 -0
- package/dist/crash-recovery.d.ts +83 -0
- package/dist/crash-recovery.d.ts.map +1 -0
- package/dist/crash-recovery.js +522 -0
- package/dist/crash-recovery.js.map +1 -0
- package/dist/crash-resolution.d.ts +34 -0
- package/dist/crash-resolution.d.ts.map +1 -0
- package/dist/crash-resolution.js +382 -0
- package/dist/crash-resolution.js.map +1 -0
- package/dist/escalation.d.ts +150 -0
- package/dist/escalation.d.ts.map +1 -0
- package/dist/escalation.js +352 -0
- package/dist/escalation.js.map +1 -0
- package/dist/execution-target.d.ts +31 -0
- package/dist/execution-target.d.ts.map +1 -0
- package/dist/execution-target.js +71 -0
- package/dist/execution-target.js.map +1 -0
- package/dist/execution-unit-init.d.ts +28 -0
- package/dist/execution-unit-init.d.ts.map +1 -0
- package/dist/execution-unit-init.js +115 -0
- package/dist/execution-unit-init.js.map +1 -0
- package/dist/execution.d.ts +17 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +20 -0
- package/dist/execution.js.map +1 -0
- package/dist/factory-engine.d.ts +100 -0
- package/dist/factory-engine.d.ts.map +1 -0
- package/dist/factory-engine.js +243 -0
- package/dist/factory-engine.js.map +1 -0
- package/dist/gap-detection.d.ts +43 -0
- package/dist/gap-detection.d.ts.map +1 -0
- package/dist/gap-detection.js +149 -0
- package/dist/gap-detection.js.map +1 -0
- package/dist/gate-context.d.ts +23 -0
- package/dist/gate-context.d.ts.map +1 -0
- package/dist/gate-context.js +63 -0
- package/dist/gate-context.js.map +1 -0
- package/dist/gate-engine.d.ts +55 -0
- package/dist/gate-engine.d.ts.map +1 -0
- package/dist/gate-engine.js +191 -0
- package/dist/gate-engine.js.map +1 -0
- package/dist/gates/adversarial.d.ts +59 -0
- package/dist/gates/adversarial.d.ts.map +1 -0
- package/dist/gates/adversarial.js +426 -0
- package/dist/gates/adversarial.js.map +1 -0
- package/dist/gates/adversary-spawner.d.ts +35 -0
- package/dist/gates/adversary-spawner.d.ts.map +1 -0
- package/dist/gates/adversary-spawner.js +286 -0
- package/dist/gates/adversary-spawner.js.map +1 -0
- package/dist/gates/adversary-test-dir.d.ts +41 -0
- package/dist/gates/adversary-test-dir.d.ts.map +1 -0
- package/dist/gates/adversary-test-dir.js +150 -0
- package/dist/gates/adversary-test-dir.js.map +1 -0
- package/dist/gates/behavioral-parser.d.ts +32 -0
- package/dist/gates/behavioral-parser.d.ts.map +1 -0
- package/dist/gates/behavioral-parser.js +190 -0
- package/dist/gates/behavioral-parser.js.map +1 -0
- package/dist/gates/behavioral-runner.d.ts +36 -0
- package/dist/gates/behavioral-runner.d.ts.map +1 -0
- package/dist/gates/behavioral-runner.js +306 -0
- package/dist/gates/behavioral-runner.js.map +1 -0
- package/dist/gates/behavioral.d.ts +37 -0
- package/dist/gates/behavioral.d.ts.map +1 -0
- package/dist/gates/behavioral.js +485 -0
- package/dist/gates/behavioral.js.map +1 -0
- package/dist/gates/deterministic.d.ts +24 -0
- package/dist/gates/deterministic.d.ts.map +1 -0
- package/dist/gates/deterministic.js +186 -0
- package/dist/gates/deterministic.js.map +1 -0
- package/dist/git-factory.d.ts +59 -0
- package/dist/git-factory.d.ts.map +1 -0
- package/dist/git-factory.js +102 -0
- package/dist/git-factory.js.map +1 -0
- package/dist/guard-evaluation.d.ts +48 -0
- package/dist/guard-evaluation.d.ts.map +1 -0
- package/dist/guard-evaluation.js +416 -0
- package/dist/guard-evaluation.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/instance-completion.d.ts +34 -0
- package/dist/instance-completion.d.ts.map +1 -0
- package/dist/instance-completion.js +366 -0
- package/dist/instance-completion.js.map +1 -0
- package/dist/instance-lifecycle.d.ts +15 -0
- package/dist/instance-lifecycle.d.ts.map +1 -0
- package/dist/instance-lifecycle.js +18 -0
- package/dist/instance-lifecycle.js.map +1 -0
- package/dist/instance-phase-dispatch.d.ts +75 -0
- package/dist/instance-phase-dispatch.d.ts.map +1 -0
- package/dist/instance-phase-dispatch.js +674 -0
- package/dist/instance-phase-dispatch.js.map +1 -0
- package/dist/instance-poll-loop.d.ts +43 -0
- package/dist/instance-poll-loop.d.ts.map +1 -0
- package/dist/instance-poll-loop.js +360 -0
- package/dist/instance-poll-loop.js.map +1 -0
- package/dist/instance-state-machine.d.ts +52 -0
- package/dist/instance-state-machine.d.ts.map +1 -0
- package/dist/instance-state-machine.js +235 -0
- package/dist/instance-state-machine.js.map +1 -0
- package/dist/log-manager.d.ts +28 -0
- package/dist/log-manager.d.ts.map +1 -0
- package/dist/log-manager.js +71 -0
- package/dist/log-manager.js.map +1 -0
- package/dist/pipeline-evaluator.d.ts +61 -0
- package/dist/pipeline-evaluator.d.ts.map +1 -0
- package/dist/pipeline-evaluator.js +107 -0
- package/dist/pipeline-evaluator.js.map +1 -0
- package/dist/pipeline-metrics.d.ts +52 -0
- package/dist/pipeline-metrics.d.ts.map +1 -0
- package/dist/pipeline-metrics.js +40 -0
- package/dist/pipeline-metrics.js.map +1 -0
- package/dist/pipeline-traversal.d.ts +43 -0
- package/dist/pipeline-traversal.d.ts.map +1 -0
- package/dist/pipeline-traversal.js +68 -0
- package/dist/pipeline-traversal.js.map +1 -0
- package/dist/plan-parser.d.ts +76 -0
- package/dist/plan-parser.d.ts.map +1 -0
- package/dist/plan-parser.js +223 -0
- package/dist/plan-parser.js.map +1 -0
- package/dist/planning-phase.d.ts +52 -0
- package/dist/planning-phase.d.ts.map +1 -0
- package/dist/planning-phase.js +444 -0
- package/dist/planning-phase.js.map +1 -0
- package/dist/planning-prompt.d.ts +64 -0
- package/dist/planning-prompt.d.ts.map +1 -0
- package/dist/planning-prompt.js +251 -0
- package/dist/planning-prompt.js.map +1 -0
- package/dist/planning.d.ts +16 -0
- package/dist/planning.d.ts.map +1 -0
- package/dist/planning.js +17 -0
- package/dist/planning.js.map +1 -0
- package/dist/process-runner.d.ts +41 -0
- package/dist/process-runner.d.ts.map +1 -0
- package/dist/process-runner.js +81 -0
- package/dist/process-runner.js.map +1 -0
- package/dist/product-config.d.ts +34 -0
- package/dist/product-config.d.ts.map +1 -0
- package/dist/product-config.js +43 -0
- package/dist/product-config.js.map +1 -0
- package/dist/queries/cycle-evaluations.d.ts +23 -0
- package/dist/queries/cycle-evaluations.d.ts.map +1 -0
- package/dist/queries/cycle-evaluations.js +37 -0
- package/dist/queries/cycle-evaluations.js.map +1 -0
- package/dist/queries/escalations.d.ts +30 -0
- package/dist/queries/escalations.d.ts.map +1 -0
- package/dist/queries/escalations.js +42 -0
- package/dist/queries/escalations.js.map +1 -0
- package/dist/queries/execution-units.d.ts +76 -0
- package/dist/queries/execution-units.d.ts.map +1 -0
- package/dist/queries/execution-units.js +109 -0
- package/dist/queries/execution-units.js.map +1 -0
- package/dist/queries/gate-results.d.ts +32 -0
- package/dist/queries/gate-results.d.ts.map +1 -0
- package/dist/queries/gate-results.js +44 -0
- package/dist/queries/gate-results.js.map +1 -0
- package/dist/queries/instances.d.ts +51 -0
- package/dist/queries/instances.d.ts.map +1 -0
- package/dist/queries/instances.js +77 -0
- package/dist/queries/instances.js.map +1 -0
- package/dist/queries/sessions.d.ts +50 -0
- package/dist/queries/sessions.d.ts.map +1 -0
- package/dist/queries/sessions.js +81 -0
- package/dist/queries/sessions.js.map +1 -0
- package/dist/queries/shared.d.ts +38 -0
- package/dist/queries/shared.d.ts.map +1 -0
- package/dist/queries/shared.js +119 -0
- package/dist/queries/shared.js.map +1 -0
- package/dist/queries/specs.d.ts +12 -0
- package/dist/queries/specs.d.ts.map +1 -0
- package/dist/queries/specs.js +21 -0
- package/dist/queries/specs.js.map +1 -0
- package/dist/queries/strategies.d.ts +14 -0
- package/dist/queries/strategies.d.ts.map +1 -0
- package/dist/queries/strategies.js +18 -0
- package/dist/queries/strategies.js.map +1 -0
- package/dist/queries/work-units.d.ts +42 -0
- package/dist/queries/work-units.d.ts.map +1 -0
- package/dist/queries/work-units.js +57 -0
- package/dist/queries/work-units.js.map +1 -0
- package/dist/queries/workflows.d.ts +29 -0
- package/dist/queries/workflows.d.ts.map +1 -0
- package/dist/queries/workflows.js +103 -0
- package/dist/queries/workflows.js.map +1 -0
- package/dist/remediation-units.d.ts +40 -0
- package/dist/remediation-units.d.ts.map +1 -0
- package/dist/remediation-units.js +263 -0
- package/dist/remediation-units.js.map +1 -0
- package/dist/replanning.d.ts +72 -0
- package/dist/replanning.d.ts.map +1 -0
- package/dist/replanning.js +403 -0
- package/dist/replanning.js.map +1 -0
- package/dist/resource-limits.d.ts +62 -0
- package/dist/resource-limits.d.ts.map +1 -0
- package/dist/resource-limits.js +322 -0
- package/dist/resource-limits.js.map +1 -0
- package/dist/scheduler.d.ts +98 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +203 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/session-adapter.d.ts +89 -0
- package/dist/session-adapter.d.ts.map +1 -0
- package/dist/session-adapter.js +108 -0
- package/dist/session-adapter.js.map +1 -0
- package/dist/sop-generator.d.ts +29 -0
- package/dist/sop-generator.d.ts.map +1 -0
- package/dist/sop-generator.js +235 -0
- package/dist/sop-generator.js.map +1 -0
- package/dist/spec-profiles.d.ts +41 -0
- package/dist/spec-profiles.d.ts.map +1 -0
- package/dist/spec-profiles.js +131 -0
- package/dist/spec-profiles.js.map +1 -0
- package/dist/strategy-design-graph.d.ts +23 -0
- package/dist/strategy-design-graph.d.ts.map +1 -0
- package/dist/strategy-design-graph.js +205 -0
- package/dist/strategy-design-graph.js.map +1 -0
- package/dist/strategy-design-prompt.d.ts +28 -0
- package/dist/strategy-design-prompt.d.ts.map +1 -0
- package/dist/strategy-design-prompt.js +108 -0
- package/dist/strategy-design-prompt.js.map +1 -0
- package/dist/strategy-design-schema.d.ts +767 -0
- package/dist/strategy-design-schema.d.ts.map +1 -0
- package/dist/strategy-design-schema.js +126 -0
- package/dist/strategy-design-schema.js.map +1 -0
- package/dist/strategy-design.d.ts +69 -0
- package/dist/strategy-design.d.ts.map +1 -0
- package/dist/strategy-design.js +411 -0
- package/dist/strategy-design.js.map +1 -0
- package/dist/strategy-gating.d.ts +31 -0
- package/dist/strategy-gating.d.ts.map +1 -0
- package/dist/strategy-gating.js +276 -0
- package/dist/strategy-gating.js.map +1 -0
- package/dist/team-prompt-builder.d.ts +47 -0
- package/dist/team-prompt-builder.d.ts.map +1 -0
- package/dist/team-prompt-builder.js +362 -0
- package/dist/team-prompt-builder.js.map +1 -0
- package/dist/trace-engine.d.ts +40 -0
- package/dist/trace-engine.d.ts.map +1 -0
- package/dist/trace-engine.js +344 -0
- package/dist/trace-engine.js.map +1 -0
- package/dist/types.d.ts +612 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/unit-session-lifecycle.d.ts +78 -0
- package/dist/unit-session-lifecycle.d.ts.map +1 -0
- package/dist/unit-session-lifecycle.js +141 -0
- package/dist/unit-session-lifecycle.js.map +1 -0
- package/dist/unit-session.d.ts +30 -0
- package/dist/unit-session.d.ts.map +1 -0
- package/dist/unit-session.js +370 -0
- package/dist/unit-session.js.map +1 -0
- package/dist/watchdogs.d.ts +33 -0
- package/dist/watchdogs.d.ts.map +1 -0
- package/dist/watchdogs.js +170 -0
- package/dist/watchdogs.js.map +1 -0
- package/dist/work-unit-scheduler.d.ts +34 -0
- package/dist/work-unit-scheduler.d.ts.map +1 -0
- package/dist/work-unit-scheduler.js +91 -0
- package/dist/work-unit-scheduler.js.map +1 -0
- package/dist/workflow-transition.d.ts +90 -0
- package/dist/workflow-transition.d.ts.map +1 -0
- package/dist/workflow-transition.js +340 -0
- package/dist/workflow-transition.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-design-schema.d.ts","sourceRoot":"","sources":["../src/strategy-design-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,GAAG,UAAU,GAAG,MAAM,CAAC;AAExF;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,qCAAqC;IACrC,IAAI,EAAE,gBAAgB,CAAC;IACvB,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAclC,CAAC;AAEH,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE9C,CAAC;AAMH;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,GAAG,IAAI,CAgEpF;AAGD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy design types, Zod schemas, and dependency validation.
|
|
3
|
+
*
|
|
4
|
+
* Pure data definitions and validation logic for AI-generated strategy designs.
|
|
5
|
+
* No side effects, no I/O -- safe to import from any module.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Zod schemas for AI output validation
|
|
10
|
+
// ============================================================================
|
|
11
|
+
export const ContractItemSchema = z.object({
|
|
12
|
+
kind: z.enum(['file', 'export', 'api_endpoint', 'db_table', 'type']),
|
|
13
|
+
identifier: z.string().min(1),
|
|
14
|
+
description: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
export const StrategyContractSchema = z.object({
|
|
17
|
+
produces: z.array(ContractItemSchema),
|
|
18
|
+
consumes: z.array(ContractItemSchema),
|
|
19
|
+
});
|
|
20
|
+
export const InterfaceContractSchema = z.object({
|
|
21
|
+
name: z.string().min(1),
|
|
22
|
+
provider: z.string().min(1),
|
|
23
|
+
consumer: z.string().min(1),
|
|
24
|
+
description: z.string().min(1),
|
|
25
|
+
});
|
|
26
|
+
export const StrategyDesignUnitSchema = z.object({
|
|
27
|
+
tempId: z.string().min(1),
|
|
28
|
+
name: z.string().min(1).max(200),
|
|
29
|
+
description: z.string().min(1),
|
|
30
|
+
techContext: z.string().min(1),
|
|
31
|
+
priorityRank: z.number().int().min(0),
|
|
32
|
+
dependsOn: z.array(z.string()),
|
|
33
|
+
interfaceContract: StrategyContractSchema,
|
|
34
|
+
});
|
|
35
|
+
export const StrategyDesignPlanSchema = z.object({
|
|
36
|
+
strategies: z.array(StrategyDesignUnitSchema).min(1),
|
|
37
|
+
interfaceContracts: z.array(InterfaceContractSchema),
|
|
38
|
+
summary: z.string().min(1),
|
|
39
|
+
});
|
|
40
|
+
/** Zod schema for validating getStrategiesByFactoryInstance response. */
|
|
41
|
+
export const PersistedStrategySchema = z.object({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
name: z.string(),
|
|
44
|
+
description: z.string().nullable(),
|
|
45
|
+
techContext: z.string().nullable(),
|
|
46
|
+
priorityRank: z.number(),
|
|
47
|
+
status: z.string(),
|
|
48
|
+
executionStatus: z.enum(['pending', 'in_progress', 'completed', 'failed', 'gating_deterministic', 'gating_behavioral', 'gating_adversarial', 'gate_fix_pending']).nullable(),
|
|
49
|
+
interfaceContract: z.object({
|
|
50
|
+
produces: z.array(ContractItemSchema),
|
|
51
|
+
consumes: z.array(ContractItemSchema),
|
|
52
|
+
}).nullable(),
|
|
53
|
+
dependsOn: z.array(z.string()),
|
|
54
|
+
gateFixStartedAt: z.string().nullable().optional().default(null),
|
|
55
|
+
});
|
|
56
|
+
export const GetInstanceStrategiesResponseSchema = z.object({
|
|
57
|
+
strategies: z.array(PersistedStrategySchema),
|
|
58
|
+
});
|
|
59
|
+
// ============================================================================
|
|
60
|
+
// Dependency validation
|
|
61
|
+
// ============================================================================
|
|
62
|
+
/**
|
|
63
|
+
* Validate that all dependsOn references point to valid tempIds within the plan,
|
|
64
|
+
* and that interface contract provider/consumer references are valid.
|
|
65
|
+
*
|
|
66
|
+
* Also checks for self-dependencies and cycles (via topological sort).
|
|
67
|
+
* Returns an error message if validation fails, null if valid.
|
|
68
|
+
*/
|
|
69
|
+
export function validateStrategyDependencies(plan) {
|
|
70
|
+
const validTempIds = new Set(plan.strategies.map((s) => s.tempId));
|
|
71
|
+
// Check for duplicate tempIds
|
|
72
|
+
if (validTempIds.size !== plan.strategies.length) {
|
|
73
|
+
return 'Duplicate tempId found in strategies';
|
|
74
|
+
}
|
|
75
|
+
// Validate dependsOn references
|
|
76
|
+
for (const strategy of plan.strategies) {
|
|
77
|
+
for (const dep of strategy.dependsOn) {
|
|
78
|
+
if (!validTempIds.has(dep)) {
|
|
79
|
+
return `Strategy "${strategy.tempId}" references unknown dependency "${dep}"`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (strategy.dependsOn.includes(strategy.tempId)) {
|
|
83
|
+
return `Strategy "${strategy.tempId}" has a self-dependency`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Validate interface contract references
|
|
87
|
+
for (const contract of plan.interfaceContracts) {
|
|
88
|
+
if (!validTempIds.has(contract.provider)) {
|
|
89
|
+
return `Interface contract "${contract.name}" references unknown provider "${contract.provider}"`;
|
|
90
|
+
}
|
|
91
|
+
if (!validTempIds.has(contract.consumer)) {
|
|
92
|
+
return `Interface contract "${contract.name}" references unknown consumer "${contract.consumer}"`;
|
|
93
|
+
}
|
|
94
|
+
if (contract.provider === contract.consumer) {
|
|
95
|
+
return `Interface contract "${contract.name}" has same provider and consumer "${contract.provider}"`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Topological sort to detect cycles
|
|
99
|
+
const visited = new Set();
|
|
100
|
+
const inStack = new Set();
|
|
101
|
+
const adjList = new Map();
|
|
102
|
+
for (const strategy of plan.strategies) {
|
|
103
|
+
adjList.set(strategy.tempId, strategy.dependsOn);
|
|
104
|
+
}
|
|
105
|
+
function hasCycle(node) {
|
|
106
|
+
if (inStack.has(node))
|
|
107
|
+
return true;
|
|
108
|
+
if (visited.has(node))
|
|
109
|
+
return false;
|
|
110
|
+
visited.add(node);
|
|
111
|
+
inStack.add(node);
|
|
112
|
+
for (const dep of adjList.get(node) ?? []) {
|
|
113
|
+
if (hasCycle(dep))
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
inStack.delete(node);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
for (const strategy of plan.strategies) {
|
|
120
|
+
if (hasCycle(strategy.tempId)) {
|
|
121
|
+
return `Cycle detected in strategy dependencies involving "${strategy.tempId}"`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=strategy-design-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-design-schema.js","sourceRoot":"","sources":["../src/strategy-design-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAyKxB,+EAA+E;AAC/E,uCAAuC;AACvC,+EAA+E;AAE/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IACpE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACnC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACrC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC;CACtC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
|
+
* Strategy design phase for factory instances.
|
|
3
|
+
*
|
|
4
|
+
* When an instance transitions to 'designing', this module:
|
|
5
|
+
* 1. Spawns Claude Code in --print mode to decompose the specification
|
|
6
|
+
* into bounded strategies with dependency edges and interface contracts
|
|
7
|
+
* 2. Validates the AI output with Zod
|
|
8
|
+
* 3. Maps tempId references to real UUIDs for dependency edges
|
|
9
|
+
* 4. Persists strategies to product_strategies (linked via factory_instance_id)
|
|
10
|
+
* 5. Transitions the instance to 'planning' on success
|
|
11
|
+
*
|
|
12
|
+
* The implementation has been split into focused modules:
|
|
13
|
+
* - strategy-design-schema.ts -- types, Zod schemas, dependency validation
|
|
14
|
+
* - strategy-design-prompt.ts -- prompt builders
|
|
15
|
+
* - strategy-design-graph.ts -- dependency graph builder, contract validation
|
|
16
|
+
*
|
|
17
|
+
* This file contains generation, persistence, and orchestration logic,
|
|
18
|
+
* plus barrel re-exports from the split modules.
|
|
19
|
+
*/
|
|
20
|
+
import { type ParsedTokenUsage } from './queries/shared.js';
|
|
21
|
+
import type { ResourceGovernor } from '@telora/daemon-core';
|
|
22
|
+
import type { FactoryBlueprint, FactoryConfig, FactoryInstanceState } from './types.js';
|
|
23
|
+
import type { StrategyDesignPlan, StrategyGenerationResult, StrategyMapping, PersistedStrategy } from './strategy-design-schema.js';
|
|
24
|
+
export type { ContractItemKind, ContractItem, StrategyContract, InterfaceContract, StrategyDesignUnit, StrategyDesignPlan, StrategyGraphNode, StrategyDependencyGraph, ContractValidationResult, ContractMismatch, ContractWarning, StrategyMapping, StrategyExecutionStatus, PersistedStrategy, StrategyGenerationResult, StrategyGraphInput, } from './strategy-design-schema.js';
|
|
25
|
+
export { ContractItemSchema, StrategyContractSchema, InterfaceContractSchema, StrategyDesignUnitSchema, StrategyDesignPlanSchema, PersistedStrategySchema, GetInstanceStrategiesResponseSchema, validateStrategyDependencies, } from './strategy-design-schema.js';
|
|
26
|
+
export { buildStrategyDesignPrompt, buildStrategyRetryPrompt } from './strategy-design-prompt.js';
|
|
27
|
+
export { buildStrategyDependencyGraph, validateInterfaceContracts } from './strategy-design-graph.js';
|
|
28
|
+
/** Default timeout for the strategy design Claude Code session (5 minutes). */
|
|
29
|
+
export declare const DEFAULT_STRATEGY_DESIGN_TIMEOUT_MS = 300000;
|
|
30
|
+
/** Maximum number of retry attempts when strategy generation fails validation. */
|
|
31
|
+
export declare const MAX_STRATEGY_DESIGN_RETRIES = 2;
|
|
32
|
+
/**
|
|
33
|
+
* Spawn Claude Code and validate the resulting strategy design.
|
|
34
|
+
*
|
|
35
|
+
* Follows the same pattern as generateAndValidateWorkPlan() in planning.ts:
|
|
36
|
+
* - Spawns Claude Code in --print mode with the given prompt
|
|
37
|
+
* - Extracts and parses the JSON strategy design from the output
|
|
38
|
+
* - Validates schema, dependencies, and DAG structure
|
|
39
|
+
*
|
|
40
|
+
* Extracted as a standalone function so it can be called in a retry loop.
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateAndValidateStrategyDesign(prompt: string, config: FactoryConfig, worktreePath: string, blueprint?: FactoryBlueprint): Promise<StrategyGenerationResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Map tempId references to real UUIDs and persist strategies as product_strategy rows.
|
|
45
|
+
*
|
|
46
|
+
* Creates product_strategy rows via the product-api edge function, linked to the
|
|
47
|
+
* factory instance via factory_instance_id.
|
|
48
|
+
*
|
|
49
|
+
* @returns Array of mappings from tempId to real strategy UUID.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mapAndPersistStrategies(state: FactoryInstanceState, strategyDesign: StrategyDesignPlan): Promise<StrategyMapping[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Get strategies created by a factory instance (full data for planning).
|
|
54
|
+
*/
|
|
55
|
+
export declare function getStrategiesByFactoryInstance(instanceId: string): Promise<PersistedStrategy[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Run the full strategy design phase for a factory instance.
|
|
58
|
+
*
|
|
59
|
+
* Orchestrates: audit -> prompt -> generate -> validate -> persist -> transition.
|
|
60
|
+
* Called by runDesigning() in instance-lifecycle.ts.
|
|
61
|
+
*
|
|
62
|
+
* @returns An object indicating success or failure with an optional error message.
|
|
63
|
+
*/
|
|
64
|
+
export declare function runStrategyDesignPhase(state: FactoryInstanceState, config: FactoryConfig, governor?: ResourceGovernor | null): Promise<{
|
|
65
|
+
success: boolean;
|
|
66
|
+
error?: string;
|
|
67
|
+
tokenUsage?: ParsedTokenUsage | null;
|
|
68
|
+
}>;
|
|
69
|
+
//# sourceMappingURL=strategy-design.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-design.d.ts","sourceRoot":"","sources":["../src/strategy-design.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAOH,OAAO,EAA4C,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMxF,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AASrC,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,mCAAmC,EACnC,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAGlG,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAMtG,+EAA+E;AAC/E,eAAO,MAAM,kCAAkC,SAAU,CAAC;AAE1D,kFAAkF;AAClF,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAS7C;;;;;;;;;GASG;AACH,wBAAsB,iCAAiC,CACrD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,wBAAwB,CAAC,CA2JnC;AAMD;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,oBAAoB,EAC3B,cAAc,EAAE,kBAAkB,GACjC,OAAO,CAAC,eAAe,EAAE,CAAC,CA2D5B;AAGD;;GAEG;AACH,wBAAsB,8BAA8B,CAClD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAO9B;AAMD;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,oBAAoB,EAC3B,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,gBAAgB,GAAG,IAAI,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;CAAE,CAAC,CAoKrF"}
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy design phase for factory instances.
|
|
3
|
+
*
|
|
4
|
+
* When an instance transitions to 'designing', this module:
|
|
5
|
+
* 1. Spawns Claude Code in --print mode to decompose the specification
|
|
6
|
+
* into bounded strategies with dependency edges and interface contracts
|
|
7
|
+
* 2. Validates the AI output with Zod
|
|
8
|
+
* 3. Maps tempId references to real UUIDs for dependency edges
|
|
9
|
+
* 4. Persists strategies to product_strategies (linked via factory_instance_id)
|
|
10
|
+
* 5. Transitions the instance to 'planning' on success
|
|
11
|
+
*
|
|
12
|
+
* The implementation has been split into focused modules:
|
|
13
|
+
* - strategy-design-schema.ts -- types, Zod schemas, dependency validation
|
|
14
|
+
* - strategy-design-prompt.ts -- prompt builders
|
|
15
|
+
* - strategy-design-graph.ts -- dependency graph builder, contract validation
|
|
16
|
+
*
|
|
17
|
+
* This file contains generation, persistence, and orchestration logic,
|
|
18
|
+
* plus barrel re-exports from the split modules.
|
|
19
|
+
*/
|
|
20
|
+
import { randomUUID } from 'node:crypto';
|
|
21
|
+
import { z } from 'zod';
|
|
22
|
+
import { buildPlanningEnv, extractWorkPlanJson } from './planning.js';
|
|
23
|
+
import { spawnAsync } from './process-runner.js';
|
|
24
|
+
import { callApiValidated } from './queries/shared.js';
|
|
25
|
+
import { parseTokenUsageFromOutput, sumTokenUsage } from './queries/shared.js';
|
|
26
|
+
import { GetInstanceStrategiesResponseSchema, StrategyDesignPlanSchema, validateStrategyDependencies, } from './strategy-design-schema.js';
|
|
27
|
+
import { buildStrategyDesignPrompt, buildStrategyRetryPrompt } from './strategy-design-prompt.js';
|
|
28
|
+
import { buildStrategyDependencyGraph, validateInterfaceContracts } from './strategy-design-graph.js';
|
|
29
|
+
export { ContractItemSchema, StrategyContractSchema, InterfaceContractSchema, StrategyDesignUnitSchema, StrategyDesignPlanSchema, PersistedStrategySchema, GetInstanceStrategiesResponseSchema, validateStrategyDependencies, } from './strategy-design-schema.js';
|
|
30
|
+
// Prompt builders
|
|
31
|
+
export { buildStrategyDesignPrompt, buildStrategyRetryPrompt } from './strategy-design-prompt.js';
|
|
32
|
+
// Graph utilities
|
|
33
|
+
export { buildStrategyDependencyGraph, validateInterfaceContracts } from './strategy-design-graph.js';
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Constants
|
|
36
|
+
// ============================================================================
|
|
37
|
+
/** Default timeout for the strategy design Claude Code session (5 minutes). */
|
|
38
|
+
export const DEFAULT_STRATEGY_DESIGN_TIMEOUT_MS = 300_000;
|
|
39
|
+
/** Maximum number of retry attempts when strategy generation fails validation. */
|
|
40
|
+
export const MAX_STRATEGY_DESIGN_RETRIES = 2;
|
|
41
|
+
/** Log prefix for this module. */
|
|
42
|
+
const LOG_PREFIX = '[strategy-design]';
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Generation and validation
|
|
45
|
+
// ============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* Spawn Claude Code and validate the resulting strategy design.
|
|
48
|
+
*
|
|
49
|
+
* Follows the same pattern as generateAndValidateWorkPlan() in planning.ts:
|
|
50
|
+
* - Spawns Claude Code in --print mode with the given prompt
|
|
51
|
+
* - Extracts and parses the JSON strategy design from the output
|
|
52
|
+
* - Validates schema, dependencies, and DAG structure
|
|
53
|
+
*
|
|
54
|
+
* Extracted as a standalone function so it can be called in a retry loop.
|
|
55
|
+
*/
|
|
56
|
+
export async function generateAndValidateStrategyDesign(prompt, config, worktreePath, blueprint) {
|
|
57
|
+
const timeoutMs = blueprint?.strategyDesignTimeoutMs ?? DEFAULT_STRATEGY_DESIGN_TIMEOUT_MS;
|
|
58
|
+
// -- Spawn Claude Code --
|
|
59
|
+
let rawOutput;
|
|
60
|
+
try {
|
|
61
|
+
const args = ['--print', '--output-format', 'json', '--verbose'];
|
|
62
|
+
const env = buildPlanningEnv(config);
|
|
63
|
+
console.log(`${LOG_PREFIX} Spawning Claude Code for strategy design generation...`);
|
|
64
|
+
rawOutput = await spawnAsync(config.claudeCodePath, args, {
|
|
65
|
+
input: prompt,
|
|
66
|
+
encoding: 'utf-8',
|
|
67
|
+
timeout: timeoutMs,
|
|
68
|
+
cwd: worktreePath,
|
|
69
|
+
env,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
const execErr = err;
|
|
74
|
+
if (execErr.killed || execErr.signal === 'SIGTERM') {
|
|
75
|
+
return { success: false, error: `Claude Code timed out after ${timeoutMs / 1000}s`, tokenUsage: null };
|
|
76
|
+
}
|
|
77
|
+
const stderr = execErr.stderr ? String(execErr.stderr).slice(0, 500) : '';
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
error: `Claude Code failed (exit ${execErr.status ?? 'unknown'}): ${execErr.message ?? 'unknown error'}${stderr ? ` | stderr: ${stderr}` : ''}`,
|
|
81
|
+
tokenUsage: null,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!rawOutput || rawOutput.trim().length === 0) {
|
|
85
|
+
return { success: false, error: 'Claude Code returned empty output', tokenUsage: null };
|
|
86
|
+
}
|
|
87
|
+
// Parse token usage from the NDJSON output (TEL-6: cost tracking for planner sessions)
|
|
88
|
+
const tokenUsage = parseTokenUsageFromOutput(rawOutput);
|
|
89
|
+
// -- Extract and validate the strategy design --
|
|
90
|
+
let designJson;
|
|
91
|
+
try {
|
|
92
|
+
designJson = extractWorkPlanJson(rawOutput);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
error: `Failed to extract strategy design JSON: ${err instanceof Error ? err.message : String(err)}`,
|
|
98
|
+
tokenUsage,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
let parsedJson;
|
|
102
|
+
try {
|
|
103
|
+
parsedJson = JSON.parse(designJson);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: `Strategy design is not valid JSON: ${err instanceof Error ? err.message : String(err)}`,
|
|
109
|
+
tokenUsage,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// Normalize: AI sometimes returns a bare array instead of an object.
|
|
113
|
+
// If single-element array containing an object, unwrap it.
|
|
114
|
+
// If array of strategy-shaped items, wrap as { strategies: [...] }.
|
|
115
|
+
if (Array.isArray(parsedJson)) {
|
|
116
|
+
if (parsedJson.length === 1 && typeof parsedJson[0] === 'object' && parsedJson[0] !== null && !Array.isArray(parsedJson[0])) {
|
|
117
|
+
parsedJson = parsedJson[0];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
parsedJson = { strategies: parsedJson, interfaceContracts: [], summary: 'Auto-wrapped from array response' };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const validation = StrategyDesignPlanSchema.safeParse(parsedJson);
|
|
124
|
+
if (!validation.success) {
|
|
125
|
+
const issues = validation.error.issues
|
|
126
|
+
.map((i) => `${i.path.join('.')}: ${i.message}`)
|
|
127
|
+
.join('; ');
|
|
128
|
+
// Diagnostic: log top-level keys and first strategy item keys to diagnose field name mismatches
|
|
129
|
+
const topKeys = typeof parsedJson === 'object' && parsedJson !== null ? Object.keys(parsedJson) : [];
|
|
130
|
+
const obj = parsedJson;
|
|
131
|
+
const strategies = Array.isArray(obj.strategies) ? obj.strategies : [];
|
|
132
|
+
const firstItem = strategies.length > 0 && typeof strategies[0] === 'object' && strategies[0] !== null
|
|
133
|
+
? Object.keys(strategies[0])
|
|
134
|
+
: [];
|
|
135
|
+
console.error(`${LOG_PREFIX} Validation failed. Top-level keys: [${topKeys}], strategies count: ${strategies.length}, first item keys: [${firstItem}]`);
|
|
136
|
+
if (strategies.length > 0) {
|
|
137
|
+
console.error(`${LOG_PREFIX} First strategy item: ${JSON.stringify(strategies[0]).slice(0, 500)}`);
|
|
138
|
+
}
|
|
139
|
+
return { success: false, error: `Strategy design validation failed: ${issues}`, tokenUsage };
|
|
140
|
+
}
|
|
141
|
+
const strategyDesign = validation.data;
|
|
142
|
+
console.log(`${LOG_PREFIX} Strategy design validated: ${strategyDesign.strategies.length} strategy(ies)`);
|
|
143
|
+
// -- Validate dependencies and DAG structure --
|
|
144
|
+
const depError = validateStrategyDependencies(strategyDesign);
|
|
145
|
+
if (depError) {
|
|
146
|
+
return { success: false, error: `Strategy dependency error: ${depError}`, tokenUsage };
|
|
147
|
+
}
|
|
148
|
+
// -- Validate interface contracts pre-persistence (using tempIds) --
|
|
149
|
+
// Check that every consumed artifact is produced by at least one dependency.
|
|
150
|
+
// This runs BEFORE persistence so contract errors are caught by the retry loop.
|
|
151
|
+
if (strategyDesign.strategies.length > 1) {
|
|
152
|
+
const producesMap = new Map(); // tempId -> Set<"kind:identifier">
|
|
153
|
+
for (const s of strategyDesign.strategies) {
|
|
154
|
+
const pSet = new Set();
|
|
155
|
+
for (const p of s.interfaceContract.produces) {
|
|
156
|
+
pSet.add(`${p.kind}:${p.identifier}`);
|
|
157
|
+
}
|
|
158
|
+
producesMap.set(s.tempId, pSet);
|
|
159
|
+
}
|
|
160
|
+
const contractErrors = [];
|
|
161
|
+
for (const s of strategyDesign.strategies) {
|
|
162
|
+
for (const consumed of s.interfaceContract.consumes) {
|
|
163
|
+
const key = `${consumed.kind}:${consumed.identifier}`;
|
|
164
|
+
let satisfied = false;
|
|
165
|
+
for (const depId of s.dependsOn) {
|
|
166
|
+
const depProduces = producesMap.get(depId);
|
|
167
|
+
if (depProduces?.has(key)) {
|
|
168
|
+
satisfied = true;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!satisfied) {
|
|
173
|
+
const depNames = s.dependsOn
|
|
174
|
+
.map((id) => strategyDesign.strategies.find((x) => x.tempId === id)?.name ?? id)
|
|
175
|
+
.join(', ');
|
|
176
|
+
contractErrors.push(`"${s.name}" consumes ${consumed.kind}:${consumed.identifier} but ` +
|
|
177
|
+
`none of its dependencies (${depNames || 'none'}) produce it`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (contractErrors.length > 0) {
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
error: `Interface contract validation failed: ${contractErrors.join('; ')}`,
|
|
185
|
+
tokenUsage,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { success: true, strategyDesign, tokenUsage };
|
|
190
|
+
}
|
|
191
|
+
// ============================================================================
|
|
192
|
+
// Persistence: map tempIds and create product_strategies
|
|
193
|
+
// ============================================================================
|
|
194
|
+
/**
|
|
195
|
+
* Map tempId references to real UUIDs and persist strategies as product_strategy rows.
|
|
196
|
+
*
|
|
197
|
+
* Creates product_strategy rows via the product-api edge function, linked to the
|
|
198
|
+
* factory instance via factory_instance_id.
|
|
199
|
+
*
|
|
200
|
+
* @returns Array of mappings from tempId to real strategy UUID.
|
|
201
|
+
*/
|
|
202
|
+
export async function mapAndPersistStrategies(state, strategyDesign) {
|
|
203
|
+
// Build tempId -> UUID mapping
|
|
204
|
+
const idMap = new Map();
|
|
205
|
+
for (const strategy of strategyDesign.strategies) {
|
|
206
|
+
idMap.set(strategy.tempId, randomUUID());
|
|
207
|
+
}
|
|
208
|
+
// Build strategy rows for bulk insert
|
|
209
|
+
const strategies = strategyDesign.strategies.map((strategy) => ({
|
|
210
|
+
id: idMap.get(strategy.tempId),
|
|
211
|
+
name: strategy.name,
|
|
212
|
+
description: strategy.description,
|
|
213
|
+
techContext: strategy.techContext,
|
|
214
|
+
priorityRank: strategy.priorityRank,
|
|
215
|
+
dependsOn: strategy.dependsOn.map((tempId) => {
|
|
216
|
+
const realId = idMap.get(tempId);
|
|
217
|
+
if (!realId) {
|
|
218
|
+
throw new Error(`BUG: tempId "${tempId}" not found in idMap`);
|
|
219
|
+
}
|
|
220
|
+
return realId;
|
|
221
|
+
}),
|
|
222
|
+
interfaceContract: strategy.interfaceContract,
|
|
223
|
+
}));
|
|
224
|
+
// Persist via edge function (validated response)
|
|
225
|
+
const CreateStrategiesResponseSchema = z.object({
|
|
226
|
+
strategies: z.array(z.object({ id: z.string(), name: z.string() })),
|
|
227
|
+
});
|
|
228
|
+
const result = await callApiValidated('factory_create_strategies', CreateStrategiesResponseSchema, {
|
|
229
|
+
instanceId: state.instanceId,
|
|
230
|
+
productId: state.productId,
|
|
231
|
+
strategies,
|
|
232
|
+
interfaceContracts: strategyDesign.interfaceContracts.map((c) => {
|
|
233
|
+
const provider = idMap.get(c.provider);
|
|
234
|
+
if (!provider) {
|
|
235
|
+
throw new Error(`BUG: interface contract "${c.name}" provider tempId "${c.provider}" not found in idMap`);
|
|
236
|
+
}
|
|
237
|
+
const consumer = idMap.get(c.consumer);
|
|
238
|
+
if (!consumer) {
|
|
239
|
+
throw new Error(`BUG: interface contract "${c.name}" consumer tempId "${c.consumer}" not found in idMap`);
|
|
240
|
+
}
|
|
241
|
+
return { ...c, provider, consumer };
|
|
242
|
+
}),
|
|
243
|
+
});
|
|
244
|
+
console.log(`${LOG_PREFIX} Persisted ${result.strategies.length} strategies for instance ${state.instanceId}`);
|
|
245
|
+
// Return mappings
|
|
246
|
+
return strategyDesign.strategies.map((s) => ({
|
|
247
|
+
tempId: s.tempId,
|
|
248
|
+
strategyId: idMap.get(s.tempId),
|
|
249
|
+
name: s.name,
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get strategies created by a factory instance (full data for planning).
|
|
254
|
+
*/
|
|
255
|
+
export async function getStrategiesByFactoryInstance(instanceId) {
|
|
256
|
+
const result = await callApiValidated('factory_get_instance_strategies', GetInstanceStrategiesResponseSchema, { instanceId });
|
|
257
|
+
return result.strategies;
|
|
258
|
+
}
|
|
259
|
+
// ============================================================================
|
|
260
|
+
// Orchestrator: full designing phase
|
|
261
|
+
// ============================================================================
|
|
262
|
+
/**
|
|
263
|
+
* Run the full strategy design phase for a factory instance.
|
|
264
|
+
*
|
|
265
|
+
* Orchestrates: audit -> prompt -> generate -> validate -> persist -> transition.
|
|
266
|
+
* Called by runDesigning() in instance-lifecycle.ts.
|
|
267
|
+
*
|
|
268
|
+
* @returns An object indicating success or failure with an optional error message.
|
|
269
|
+
*/
|
|
270
|
+
export async function runStrategyDesignPhase(state, config, governor) {
|
|
271
|
+
const { instanceId, blueprint } = state;
|
|
272
|
+
const specification = state.specification;
|
|
273
|
+
console.log(`${LOG_PREFIX} Starting strategy design phase for instance ${instanceId}`);
|
|
274
|
+
// -- Guard: specification is required --
|
|
275
|
+
if (!specification || specification.trim().length === 0) {
|
|
276
|
+
const error = 'Instance has no specification -- cannot generate strategy design';
|
|
277
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
278
|
+
return { success: false, error };
|
|
279
|
+
}
|
|
280
|
+
// -- Guard: worktree must exist --
|
|
281
|
+
// The designing phase expects the worktree to be created by the lifecycle manager.
|
|
282
|
+
// If not present, we cannot run Claude Code.
|
|
283
|
+
if (!state.worktreePath) {
|
|
284
|
+
const error = 'Instance has no worktree path -- cannot run strategy design';
|
|
285
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
286
|
+
return { success: false, error };
|
|
287
|
+
}
|
|
288
|
+
// -- Step 1: Run codebase audit (best-effort) --
|
|
289
|
+
let auditReportText = null;
|
|
290
|
+
try {
|
|
291
|
+
const { runCodebaseAudit, formatAuditReport } = await import('./audit.js');
|
|
292
|
+
const auditReport = await runCodebaseAudit(state.worktreePath, specification, blueprint, config, governor);
|
|
293
|
+
if (auditReport) {
|
|
294
|
+
auditReportText = formatAuditReport(auditReport, blueprint);
|
|
295
|
+
console.log(`${LOG_PREFIX} Codebase audit completed: ` +
|
|
296
|
+
`${auditReport.existingImplementations.length} existing, ` +
|
|
297
|
+
`${auditReport.partialImplementations.length} partial, ` +
|
|
298
|
+
`${auditReport.gaps.length} gaps`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
const auditError = err instanceof Error ? err.message : String(err);
|
|
303
|
+
console.warn(`${LOG_PREFIX} Codebase audit failed (non-fatal): ${auditError}`);
|
|
304
|
+
// Record audit failure on the instance so users have visibility
|
|
305
|
+
try {
|
|
306
|
+
const { updateInstanceStatus } = await import('./queries/instances.js');
|
|
307
|
+
await updateInstanceStatus(instanceId, state.status, {
|
|
308
|
+
escalationMessage: `Strategy design audit failed (non-fatal): ${auditError}. Proceeding without audit context.`,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
catch (updateErr) {
|
|
312
|
+
console.warn(`${LOG_PREFIX} Failed to record audit failure on instance: ` +
|
|
313
|
+
`${updateErr instanceof Error ? updateErr.message : String(updateErr)}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// -- Step 2: Generate and validate strategy design (with retries) --
|
|
317
|
+
const originalPrompt = buildStrategyDesignPrompt(specification, blueprint, auditReportText, state.specType, state.reviewGaps);
|
|
318
|
+
let currentPrompt = originalPrompt;
|
|
319
|
+
let strategyDesign = null;
|
|
320
|
+
let lastError = '';
|
|
321
|
+
const allTokenUsages = [];
|
|
322
|
+
for (let attempt = 0; attempt <= MAX_STRATEGY_DESIGN_RETRIES; attempt++) {
|
|
323
|
+
if (attempt > 0) {
|
|
324
|
+
// Exponential backoff with jitter: base 2s, 4s, 8s... + random 0-1s jitter
|
|
325
|
+
const baseDelayMs = Math.min(2000 * Math.pow(2, attempt - 1), 30_000);
|
|
326
|
+
const jitterMs = Math.floor(Math.random() * 1000);
|
|
327
|
+
const delayMs = baseDelayMs + jitterMs;
|
|
328
|
+
console.log(`${LOG_PREFIX} Retry ${attempt}/${MAX_STRATEGY_DESIGN_RETRIES} after ${delayMs}ms backoff -- ` +
|
|
329
|
+
`previous error: ${lastError}`);
|
|
330
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
331
|
+
currentPrompt = buildStrategyRetryPrompt(originalPrompt, lastError);
|
|
332
|
+
}
|
|
333
|
+
if (governor)
|
|
334
|
+
await governor.acquireSlot('factory');
|
|
335
|
+
let genResult;
|
|
336
|
+
try {
|
|
337
|
+
genResult = await generateAndValidateStrategyDesign(currentPrompt, config, state.worktreePath, state.blueprint);
|
|
338
|
+
}
|
|
339
|
+
finally {
|
|
340
|
+
if (governor)
|
|
341
|
+
governor.releaseSlot('factory');
|
|
342
|
+
}
|
|
343
|
+
allTokenUsages.push(genResult.tokenUsage);
|
|
344
|
+
if (genResult.success) {
|
|
345
|
+
strategyDesign = genResult.strategyDesign;
|
|
346
|
+
if (attempt > 0) {
|
|
347
|
+
console.log(`${LOG_PREFIX} Strategy design generation succeeded on retry ${attempt}`);
|
|
348
|
+
}
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
lastError = genResult.error;
|
|
352
|
+
console.error(`${LOG_PREFIX} Strategy design attempt ${attempt + 1} failed: ${lastError}`);
|
|
353
|
+
}
|
|
354
|
+
const accumulatedTokenUsage = sumTokenUsage(allTokenUsages);
|
|
355
|
+
if (strategyDesign === null) {
|
|
356
|
+
const error = `Strategy design failed after ${MAX_STRATEGY_DESIGN_RETRIES + 1} attempt(s): ${lastError}`;
|
|
357
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
358
|
+
return { success: false, error, tokenUsage: accumulatedTokenUsage };
|
|
359
|
+
}
|
|
360
|
+
// -- Step 3: Map and persist strategies --
|
|
361
|
+
let mappings;
|
|
362
|
+
try {
|
|
363
|
+
mappings = await mapAndPersistStrategies(state, strategyDesign);
|
|
364
|
+
console.log(`${LOG_PREFIX} Created ${mappings.length} strategy(ies) for instance ${instanceId}: ` +
|
|
365
|
+
mappings.map((m) => m.name).join(', '));
|
|
366
|
+
}
|
|
367
|
+
catch (err) {
|
|
368
|
+
const error = `Failed to persist strategies: ${err instanceof Error ? err.message : String(err)}`;
|
|
369
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
370
|
+
return { success: false, error, tokenUsage: accumulatedTokenUsage };
|
|
371
|
+
}
|
|
372
|
+
// -- Step 4: Build dependency graph and validate contracts --
|
|
373
|
+
if (mappings.length > 1) {
|
|
374
|
+
try {
|
|
375
|
+
// Build graph from persisted strategy data
|
|
376
|
+
const graphNodes = strategyDesign.strategies.map((s) => {
|
|
377
|
+
const mapping = mappings.find((m) => m.tempId === s.tempId);
|
|
378
|
+
return {
|
|
379
|
+
strategyId: mapping.strategyId,
|
|
380
|
+
name: s.name,
|
|
381
|
+
dependsOn: s.dependsOn.map((dep) => mappings.find((m) => m.tempId === dep).strategyId),
|
|
382
|
+
interfaceContract: s.interfaceContract,
|
|
383
|
+
};
|
|
384
|
+
});
|
|
385
|
+
const graph = buildStrategyDependencyGraph(graphNodes);
|
|
386
|
+
console.log(`${LOG_PREFIX} Dependency graph: ${graph.executionOrder.length} nodes, ` +
|
|
387
|
+
`${graph.independentSubgraphs.length} independent subgraph(s)`);
|
|
388
|
+
// Validate interface contracts
|
|
389
|
+
const validation = validateInterfaceContracts(graph);
|
|
390
|
+
if (!validation.valid) {
|
|
391
|
+
const errorDetails = validation.errors
|
|
392
|
+
.map((e) => e.reason)
|
|
393
|
+
.join('; ');
|
|
394
|
+
console.error(`${LOG_PREFIX} Contract validation failed: ${errorDetails}`);
|
|
395
|
+
return { success: false, error: `Interface contract validation failed: ${errorDetails}`, tokenUsage: accumulatedTokenUsage };
|
|
396
|
+
}
|
|
397
|
+
if (validation.warnings.length > 0) {
|
|
398
|
+
for (const warning of validation.warnings) {
|
|
399
|
+
console.warn(`${LOG_PREFIX} Contract warning: ${warning.message}`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
catch (err) {
|
|
404
|
+
const error = `Dependency graph validation failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
405
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
406
|
+
return { success: false, error, tokenUsage: accumulatedTokenUsage };
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return { success: true, tokenUsage: accumulatedTokenUsage };
|
|
410
|
+
}
|
|
411
|
+
//# sourceMappingURL=strategy-design.js.map
|