@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,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remediation unit generation for factory re-planning.
|
|
3
|
+
*
|
|
4
|
+
* Generates new work units to address detected gaps after a build cycle
|
|
5
|
+
* fails the completion gate. Contains:
|
|
6
|
+
* - Re-planning prompt builder (original spec + fresh audit + cycle history)
|
|
7
|
+
* - Re-planning phase orchestrator (audit, plan generation, unit creation)
|
|
8
|
+
*/
|
|
9
|
+
import { generateFactorySOP } from './sop-generator.js';
|
|
10
|
+
import { runCodebaseAudit, formatAuditReport } from './audit.js';
|
|
11
|
+
import { generateAndValidateWorkPlan, buildRetryPrompt, mapTempIdsToUuids, } from './planning.js';
|
|
12
|
+
import { getCycleEvaluations } from './queries/cycle-evaluations.js';
|
|
13
|
+
import { getInstanceWorkUnits, createWorkUnits } from './queries/work-units.js';
|
|
14
|
+
import { updateStrategyExecutionStatus } from './queries/strategies.js';
|
|
15
|
+
import { formatGateContext } from './gate-context.js';
|
|
16
|
+
import { formatPriorCycleContext, matchWorkUnitToStrategy } from './gap-detection.js';
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Constants
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/** Maximum number of retry attempts for re-plan generation. */
|
|
21
|
+
const MAX_REPLANNING_RETRIES = 2;
|
|
22
|
+
/** Log prefix for this module. */
|
|
23
|
+
const LOG_PREFIX = '[replanning]';
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Re-planning prompt builder (TEL-3)
|
|
26
|
+
// ============================================================================
|
|
27
|
+
/**
|
|
28
|
+
* Build the re-planning prompt that instructs Claude Code to generate work
|
|
29
|
+
* units for remaining gaps in a multi-cycle factory run.
|
|
30
|
+
*
|
|
31
|
+
* Key differences from buildPlanningPrompt():
|
|
32
|
+
* - Explicitly states this is iteration N (not a fresh start)
|
|
33
|
+
* - Includes prior cycle evaluation history
|
|
34
|
+
* - Includes a fresh codebase audit against the current state
|
|
35
|
+
* - Instructs the planner to only generate work for remaining gaps
|
|
36
|
+
*/
|
|
37
|
+
export function buildReplanningPrompt(specification, blueprint, auditReport, priorCycleContext, cycleNumber, gateContext) {
|
|
38
|
+
const parts = [
|
|
39
|
+
'You are a re-planning agent for a software factory system.',
|
|
40
|
+
`This is ITERATION ${cycleNumber} of a multi-cycle factory run.`,
|
|
41
|
+
'Previous cycles have already built and committed code. Your task is to analyze',
|
|
42
|
+
'what is STILL MISSING and generate work units ONLY for remaining gaps.',
|
|
43
|
+
'',
|
|
44
|
+
'## Blueprint',
|
|
45
|
+
`Name: ${blueprint.name}`,
|
|
46
|
+
];
|
|
47
|
+
if (blueprint.operationalNotes) {
|
|
48
|
+
parts.push('', '## Operational Notes', blueprint.operationalNotes);
|
|
49
|
+
}
|
|
50
|
+
if (blueprint.specConstraints) {
|
|
51
|
+
parts.push('', '## Blueprint Infrastructure Requirements', 'The following requirements are mandated by the factory blueprint and take precedence', 'over spec requirements. Do NOT generate work units that would remove or modify items', 'covered by these requirements, even if the specification appears to prohibit them.', '', blueprint.specConstraints);
|
|
52
|
+
}
|
|
53
|
+
// Resource limits
|
|
54
|
+
const limits = [];
|
|
55
|
+
if (blueprint.maxWorkUnits !== null) {
|
|
56
|
+
limits.push(`- Maximum work units: ${blueprint.maxWorkUnits}`);
|
|
57
|
+
}
|
|
58
|
+
if (blueprint.maxIterationsPerWorkUnit !== null) {
|
|
59
|
+
limits.push(`- Maximum iterations per work unit: ${blueprint.maxIterationsPerWorkUnit}`);
|
|
60
|
+
}
|
|
61
|
+
if (blueprint.maxTokenBudget !== null) {
|
|
62
|
+
limits.push(`- Token budget for entire instance: ${blueprint.maxTokenBudget}`);
|
|
63
|
+
}
|
|
64
|
+
if (blueprint.maxWallClockHours !== null) {
|
|
65
|
+
limits.push(`- Wall-clock time limit: ${blueprint.maxWallClockHours} hours`);
|
|
66
|
+
}
|
|
67
|
+
if (limits.length > 0) {
|
|
68
|
+
parts.push('', '## Resource Limits', ...limits);
|
|
69
|
+
}
|
|
70
|
+
// Pipeline SOP (generated from promise contracts)
|
|
71
|
+
const sop = generateFactorySOP(blueprint.pipelineGraph);
|
|
72
|
+
if (sop) {
|
|
73
|
+
parts.push('', sop);
|
|
74
|
+
}
|
|
75
|
+
parts.push('', '## Original Specification', specification);
|
|
76
|
+
// Prior cycle history (evaluations + completed work)
|
|
77
|
+
if (priorCycleContext) {
|
|
78
|
+
parts.push('', priorCycleContext);
|
|
79
|
+
}
|
|
80
|
+
// Fresh audit results
|
|
81
|
+
if (auditReport) {
|
|
82
|
+
parts.push('', '## Fresh Codebase Audit (current state)', '', 'The following audit was performed against the CURRENT codebase state,', 'which includes all code committed by prior cycles.', '', auditReport);
|
|
83
|
+
}
|
|
84
|
+
if (gateContext) {
|
|
85
|
+
parts.push('', gateContext);
|
|
86
|
+
}
|
|
87
|
+
// Infrastructure gate ownership context
|
|
88
|
+
parts.push('', '## Infrastructure-Owned Gate Verification', '', 'The factory engine pre-creates a "Gate verification" work unit per strategy.', 'This unit is infrastructure-owned and resolved automatically by the gate engine.', 'Do NOT generate work units for gate verification, build validation, typecheck,', 'lint, or test execution -- these are handled by the factory infrastructure.');
|
|
89
|
+
parts.push('', '## Instructions', '', `This is iteration ${cycleNumber}. Prior cycles have already built code and committed it.`, 'The completion gate evaluated each cycle and found remaining gaps (listed above).', 'A fresh codebase audit has been performed against the current state.', '', 'Your task:', '1. Review the original specification', '2. Review what prior cycles built and what gaps the completion gate found', '3. Review the fresh codebase audit to understand what currently exists', '4. Generate work units ONLY for what is STILL MISSING', '', 'CRITICAL RULES:', '- Do NOT duplicate work that prior cycles already completed', '- Do NOT create work units for features the fresh audit shows as already implemented', '- Focus on UNIMPLEMENTED FUNCTIONAL REQUIREMENTS from the specification', '- If the fresh audit contradicts the gate evaluation, trust the fresh audit', '- Each work unit should represent a distinct functional capability the specification requires', '- Each work unit is something to BUILD. Writing and running tests is part of implementing', ' a feature, not a separate deliverable. Do NOT create work units whose sole purpose is', ' to run tests, confirm builds succeed, or verify commands execute.', '- Do NOT create work units for test coverage, type safety, build validity, or', ' runtime behavioral testing -- these are validated by the factory gate system,', ' not by work units. If the gates passed, those dimensions are already verified.', '', '## Output Format', 'Return ONLY a JSON object (no markdown fencing, no commentary) with this exact structure:', '```', '{', ' "workUnits": [', ' {', ' "tempId": "wu-0",', ' "title": "Short descriptive title",', ' "description": "Detailed description of what this work unit implements",', ' "sortOrder": 0,', ' "blockedBy": []', ' }', ' ]', '}', '```', '', 'Rules:', '- Each tempId must be unique (e.g. "wu-0", "wu-1", "wu-2", ...)', '- sortOrder must start at 0 and increment by 1', '- blockedBy must only reference tempIds of other work units in the plan', '- Every work unit must have a non-empty title and description', '- Return at least one work unit');
|
|
90
|
+
if (blueprint.maxWorkUnits !== null) {
|
|
91
|
+
parts.push(`- You MUST produce no more than ${blueprint.maxWorkUnits} work units`);
|
|
92
|
+
}
|
|
93
|
+
parts.push('- Return ONLY the JSON object, nothing else');
|
|
94
|
+
return parts.join('\n');
|
|
95
|
+
}
|
|
96
|
+
// ============================================================================
|
|
97
|
+
// Re-planning phase orchestrator (TEL-4)
|
|
98
|
+
// ============================================================================
|
|
99
|
+
/**
|
|
100
|
+
* Run a full re-planning phase for a factory instance.
|
|
101
|
+
*
|
|
102
|
+
* This is the fresh-context equivalent of runPlanningPhase() but skips
|
|
103
|
+
* worktree/branch creation (already exists from cycle 1). Steps:
|
|
104
|
+
* 1. Fetch all prior cycle evaluations
|
|
105
|
+
* 2. Fetch all work units, filter to completed
|
|
106
|
+
* 3. Run fresh codebase audit against current worktree state
|
|
107
|
+
* 4. Format prior cycle context
|
|
108
|
+
* 5. Build re-planning prompt
|
|
109
|
+
* 6. Generate and validate work plan (with retries)
|
|
110
|
+
* 7. Map tempIds to UUIDs and create work units with correct cycle_number
|
|
111
|
+
*/
|
|
112
|
+
export async function runReplanningPhase(state, config, governor) {
|
|
113
|
+
const cycleNumber = state.completionGateIterations + 1;
|
|
114
|
+
console.log(`${LOG_PREFIX} Starting re-planning phase for instance ${state.instanceId} ` +
|
|
115
|
+
`(cycle ${cycleNumber})`);
|
|
116
|
+
// Guard: must have worktree and specification
|
|
117
|
+
if (!state.worktreePath || !state.specification) {
|
|
118
|
+
const error = 'Missing worktree path or specification for re-planning';
|
|
119
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
120
|
+
return { success: false, error, workUnitsCreated: 0 };
|
|
121
|
+
}
|
|
122
|
+
// Step 1: Fetch prior cycle evaluations
|
|
123
|
+
let evaluations;
|
|
124
|
+
try {
|
|
125
|
+
evaluations = await getCycleEvaluations(state.instanceId);
|
|
126
|
+
console.log(`${LOG_PREFIX} Fetched ${evaluations.length} prior cycle evaluation(s)`);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
const error = `Failed to fetch cycle evaluations: ${err instanceof Error ? err.message : String(err)}`;
|
|
130
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
131
|
+
return { success: false, error, workUnitsCreated: 0 };
|
|
132
|
+
}
|
|
133
|
+
// Step 2: Fetch completed work units
|
|
134
|
+
let allWorkUnits;
|
|
135
|
+
try {
|
|
136
|
+
allWorkUnits = await getInstanceWorkUnits(state.instanceId);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
const error = `Failed to fetch work units: ${err instanceof Error ? err.message : String(err)}`;
|
|
140
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
141
|
+
return { success: false, error, workUnitsCreated: 0 };
|
|
142
|
+
}
|
|
143
|
+
const completedUnits = allWorkUnits.filter((wu) => wu.status === 'completed' && !wu.infrastructureOwned);
|
|
144
|
+
console.log(`${LOG_PREFIX} ${completedUnits.length} completed work unit(s) from prior cycles`);
|
|
145
|
+
// Step 3: Run fresh codebase audit (best-effort)
|
|
146
|
+
let auditReportText = null;
|
|
147
|
+
try {
|
|
148
|
+
const auditReport = await runCodebaseAudit(state.worktreePath, state.specification, state.blueprint, config, governor);
|
|
149
|
+
if (auditReport) {
|
|
150
|
+
auditReportText = formatAuditReport(auditReport, state.blueprint);
|
|
151
|
+
console.log(`${LOG_PREFIX} Fresh audit completed: ` +
|
|
152
|
+
`${auditReport.existingImplementations.length} existing, ` +
|
|
153
|
+
`${auditReport.partialImplementations.length} partial, ` +
|
|
154
|
+
`${auditReport.gaps.length} gaps`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
console.warn(`${LOG_PREFIX} Fresh audit failed (non-fatal): ` +
|
|
159
|
+
`${err instanceof Error ? err.message : String(err)}`);
|
|
160
|
+
}
|
|
161
|
+
// Step 4: Format prior cycle context
|
|
162
|
+
const priorContext = formatPriorCycleContext(evaluations, completedUnits);
|
|
163
|
+
// Step 5: Build re-planning prompt -- include gate context so planner doesn't create
|
|
164
|
+
// work units for dimensions the gate layer already validates
|
|
165
|
+
const gateContext = formatGateContext(state.blueprint);
|
|
166
|
+
const originalPrompt = buildReplanningPrompt(state.specification, state.blueprint, auditReportText, priorContext, cycleNumber, gateContext);
|
|
167
|
+
// Step 6: Generate and validate work plan (with retries)
|
|
168
|
+
let currentPrompt = originalPrompt;
|
|
169
|
+
let workPlan = null;
|
|
170
|
+
let lastError = '';
|
|
171
|
+
for (let attempt = 0; attempt <= MAX_REPLANNING_RETRIES; attempt++) {
|
|
172
|
+
if (attempt > 0) {
|
|
173
|
+
console.log(`${LOG_PREFIX} Retry ${attempt}/${MAX_REPLANNING_RETRIES} -- previous error: ${lastError}`);
|
|
174
|
+
currentPrompt = buildRetryPrompt(originalPrompt, lastError);
|
|
175
|
+
}
|
|
176
|
+
if (governor)
|
|
177
|
+
await governor.acquireSlot('factory');
|
|
178
|
+
let planResult;
|
|
179
|
+
try {
|
|
180
|
+
planResult = await generateAndValidateWorkPlan(currentPrompt, config, state.worktreePath, state.blueprint);
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
if (governor)
|
|
184
|
+
governor.releaseSlot('factory');
|
|
185
|
+
}
|
|
186
|
+
if (planResult.success) {
|
|
187
|
+
workPlan = planResult.workPlan;
|
|
188
|
+
if (attempt > 0) {
|
|
189
|
+
console.log(`${LOG_PREFIX} Re-plan generation succeeded on retry ${attempt}`);
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
lastError = planResult.error;
|
|
194
|
+
console.error(`${LOG_PREFIX} Re-plan generation attempt ${attempt + 1} failed: ${lastError}`);
|
|
195
|
+
}
|
|
196
|
+
if (workPlan === null) {
|
|
197
|
+
const error = `Re-plan generation failed after ${MAX_REPLANNING_RETRIES + 1} attempt(s): ${lastError}`;
|
|
198
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
199
|
+
return { success: false, error, workUnitsCreated: 0 };
|
|
200
|
+
}
|
|
201
|
+
// Check maxWorkUnits limit including existing units
|
|
202
|
+
if (state.blueprint.maxWorkUnits !== null) {
|
|
203
|
+
const totalAfter = allWorkUnits.length + workPlan.workUnits.length;
|
|
204
|
+
if (totalAfter > state.blueprint.maxWorkUnits) {
|
|
205
|
+
const error = `Re-plan would create ${workPlan.workUnits.length} work units, ` +
|
|
206
|
+
`but total (${allWorkUnits.length} existing + ${workPlan.workUnits.length} new) ` +
|
|
207
|
+
`exceeds maxWorkUnits limit (${state.blueprint.maxWorkUnits})`;
|
|
208
|
+
console.warn(`${LOG_PREFIX} ${error}`);
|
|
209
|
+
return { success: false, error, workUnitsCreated: 0 };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Step 7: Fetch strategies for strategy-aware tagging (best-effort)
|
|
213
|
+
let strategies = [];
|
|
214
|
+
try {
|
|
215
|
+
const { getStrategiesByFactoryInstance } = await import('./strategy-design.js');
|
|
216
|
+
strategies = await getStrategiesByFactoryInstance(state.instanceId);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// Non-fatal: re-planning works without strategy tagging
|
|
220
|
+
}
|
|
221
|
+
// Step 8: Map tempIds to UUIDs and create work units
|
|
222
|
+
const maxSortOrder = allWorkUnits.reduce((max, wu) => Math.max(max, wu.sortOrder), -1);
|
|
223
|
+
let mappedUnits;
|
|
224
|
+
try {
|
|
225
|
+
mappedUnits = mapTempIdsToUuids(workPlan.workUnits).map((u, i) => ({
|
|
226
|
+
...u,
|
|
227
|
+
sortOrder: maxSortOrder + 1 + i,
|
|
228
|
+
cycleNumber,
|
|
229
|
+
strategyId: matchWorkUnitToStrategy(u.title, u.description, strategies),
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
const error = `Failed to map tempIds to UUIDs: ${err instanceof Error ? err.message : String(err)}`;
|
|
234
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
235
|
+
return { success: false, error, workUnitsCreated: 0 };
|
|
236
|
+
}
|
|
237
|
+
let created;
|
|
238
|
+
try {
|
|
239
|
+
created = await createWorkUnits(state.instanceId, mappedUnits);
|
|
240
|
+
console.log(`${LOG_PREFIX} Re-planning cycle ${cycleNumber}: created ${created.length} work unit(s)`);
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
const error = `Failed to create work units: ${err instanceof Error ? err.message : String(err)}`;
|
|
244
|
+
console.error(`${LOG_PREFIX} ${error}`);
|
|
245
|
+
return { success: false, error, workUnitsCreated: 0 };
|
|
246
|
+
}
|
|
247
|
+
// Reset only the strategies that received new work units back to 'pending'
|
|
248
|
+
// so the scheduler picks them up. Strategies with no new work assigned
|
|
249
|
+
// stay completed -- resetting them would cause unnecessary re-execution.
|
|
250
|
+
const assignedStrategyIds = new Set(mappedUnits
|
|
251
|
+
.map((u) => u.strategyId)
|
|
252
|
+
.filter((id) => id !== undefined));
|
|
253
|
+
if (assignedStrategyIds.size > 0 && strategies.length > 0) {
|
|
254
|
+
const toReset = strategies.filter((s) => assignedStrategyIds.has(s.id) && s.executionStatus === 'completed');
|
|
255
|
+
if (toReset.length > 0) {
|
|
256
|
+
await Promise.all(toReset.map((s) => updateStrategyExecutionStatus(s.id, 'pending')));
|
|
257
|
+
console.log(`${LOG_PREFIX} Reset ${toReset.length} strategy/strategies to 'pending' ` +
|
|
258
|
+
`for re-planning cycle ${cycleNumber}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return { success: true, workUnitsCreated: created.length };
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=remediation-units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remediation-units.js","sourceRoot":"","sources":["../src/remediation-units.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,GA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AO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;YACtF,OAAO,CAAC,GAAG,CACT,GAAG,UAAU,UAAU,OAAO,CAAC,MAAM,oCAAoC;gBACzE,yBAAyB,WAAW,EAAE,CACvC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fresh context re-planning module.
|
|
3
|
+
*
|
|
4
|
+
* When the completion gate finds critical gaps after a build cycle, this
|
|
5
|
+
* module orchestrates a full re-planning cycle with fresh context:
|
|
6
|
+
* 1. Fetch prior cycle evaluations and completed work units
|
|
7
|
+
* 2. Run a fresh codebase audit against the current worktree state
|
|
8
|
+
* 3. Format prior cycle history as concise context
|
|
9
|
+
* 4. Build a re-planning prompt (original spec + fresh audit + cycle history)
|
|
10
|
+
* 5. Generate and validate a new work plan in a fresh Claude Code session
|
|
11
|
+
* 6. Create work units with the correct cycle_number
|
|
12
|
+
*
|
|
13
|
+
* This replaces the shallow gap-to-work-unit approach of
|
|
14
|
+
* generateRemediationWorkUnits() with full-context AI reasoning.
|
|
15
|
+
*/
|
|
16
|
+
import type { ResourceGovernor } from '@telora/daemon-core';
|
|
17
|
+
import type { FactoryBlueprint, FactoryConfig, FactoryCycleEvaluation, FactoryInstanceState, FactoryWorkUnit } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Filter completion gate gaps to only include those describing absent
|
|
20
|
+
* functional capabilities. Strips verification-related gaps (test execution,
|
|
21
|
+
* build confirmation, etc.) that are not spec requirements.
|
|
22
|
+
*/
|
|
23
|
+
export declare function filterFunctionalGaps(gaps: Array<{
|
|
24
|
+
area: string;
|
|
25
|
+
description: string;
|
|
26
|
+
severity: string;
|
|
27
|
+
}>): Array<{
|
|
28
|
+
area: string;
|
|
29
|
+
description: string;
|
|
30
|
+
severity: string;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Format prior cycle evaluations and completed work units into a concise
|
|
34
|
+
* markdown string for injection into the re-planning prompt.
|
|
35
|
+
*
|
|
36
|
+
* Rules:
|
|
37
|
+
* - Work unit descriptions truncated to ~100 chars to save context
|
|
38
|
+
* - Only completed work units included (not failed/pending)
|
|
39
|
+
* - Gap descriptions kept in full (they are the signal for what is missing)
|
|
40
|
+
* - Total output capped at MAX_PRIOR_CONTEXT_CHARS
|
|
41
|
+
*/
|
|
42
|
+
export declare function formatPriorCycleContext(evaluations: FactoryCycleEvaluation[], completedWorkUnits: FactoryWorkUnit[]): string;
|
|
43
|
+
/**
|
|
44
|
+
* Build the re-planning prompt that instructs Claude Code to generate work
|
|
45
|
+
* units for remaining gaps in a multi-cycle factory run.
|
|
46
|
+
*
|
|
47
|
+
* Key differences from buildPlanningPrompt():
|
|
48
|
+
* - Explicitly states this is iteration N (not a fresh start)
|
|
49
|
+
* - Includes prior cycle evaluation history
|
|
50
|
+
* - Includes a fresh codebase audit against the current state
|
|
51
|
+
* - Instructs the planner to only generate work for remaining gaps
|
|
52
|
+
*/
|
|
53
|
+
export declare function buildReplanningPrompt(specification: string, blueprint: FactoryBlueprint, auditReport: string | null, priorCycleContext: string, cycleNumber: number, gateContext?: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Run a full re-planning phase for a factory instance.
|
|
56
|
+
*
|
|
57
|
+
* This is the fresh-context equivalent of runPlanningPhase() but skips
|
|
58
|
+
* worktree/branch creation (already exists from cycle 1). Steps:
|
|
59
|
+
* 1. Fetch all prior cycle evaluations
|
|
60
|
+
* 2. Fetch all work units, filter to completed
|
|
61
|
+
* 3. Run fresh codebase audit against current worktree state
|
|
62
|
+
* 4. Format prior cycle context
|
|
63
|
+
* 5. Build re-planning prompt
|
|
64
|
+
* 6. Generate and validate work plan (with retries)
|
|
65
|
+
* 7. Map tempIds to UUIDs and create work units with correct cycle_number
|
|
66
|
+
*/
|
|
67
|
+
export declare function runReplanningPhase(state: FactoryInstanceState, config: FactoryConfig, governor?: ResourceGovernor | null): Promise<{
|
|
68
|
+
success: boolean;
|
|
69
|
+
error?: string;
|
|
70
|
+
workUnitsCreated: number;
|
|
71
|
+
}>;
|
|
72
|
+
//# sourceMappingURL=replanning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replanning.d.ts","sourceRoot":"","sources":["../src/replanning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAa5D,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EAEhB,MAAM,YAAY,CAAC;AA6CpB;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,GACnE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAUhE;AAMD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,sBAAsB,EAAE,EACrC,kBAAkB,EAAE,eAAe,EAAE,GACpC,MAAM,CA6DR;AAMD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,iBAAiB,EAAE,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE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