karajan-code 2.7.3 → 2.8.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 +4 -4
- package/package.json +24 -4
- package/scripts/diet-baseline.mjs +170 -0
- package/scripts/regen-arch-stats.sh +71 -0
- package/src/agents/availability.js +15 -9
- package/src/agents/claude-agent.js +143 -45
- package/src/agents/model-registry.js +1 -1
- package/src/audit/agent-readiness.js +240 -0
- package/src/bootstrap.js +26 -1
- package/src/brain/decision-tracker.js +3 -1
- package/src/brain/decisor.js +1 -1
- package/src/canvas/parse-md.js +238 -0
- package/src/canvas/schema.js +101 -0
- package/src/canvas/to-flat.js +85 -0
- package/src/canvas/validate.js +163 -0
- package/src/checks/binaries.js +1 -1
- package/src/checks/ports.js +97 -27
- package/src/checks/runner.js +26 -10
- package/src/checks/sonar.js +1 -1
- package/src/checks/system.js +1 -1
- package/src/checks/tokens.js +77 -24
- package/src/cli/_shared.js +30 -0
- package/src/cli/register-meta.js +204 -0
- package/src/cli/register-pipeline.js +212 -0
- package/src/cli/register-plan.js +152 -0
- package/src/cli/register-roles-skills.js +38 -0
- package/src/cli/register-sonar.js +28 -0
- package/src/cli.js +83 -468
- package/src/commands/agents.js +18 -6
- package/src/commands/architect.js +29 -2
- package/src/commands/audit.js +27 -3
- package/src/commands/board.js +160 -30
- package/src/commands/clean.js +83 -0
- package/src/commands/code.js +7 -2
- package/src/commands/discover.js +7 -2
- package/src/commands/init.js +2 -2
- package/src/commands/plan/_shared.js +40 -0
- package/src/commands/plan/add-hu.js +21 -0
- package/src/commands/plan/delete.js +9 -0
- package/src/commands/plan/generate.js +284 -0
- package/src/commands/plan/index.js +14 -0
- package/src/commands/plan/list.js +21 -0
- package/src/commands/plan/ready.js +46 -0
- package/src/commands/plan/remove-hu.js +17 -0
- package/src/commands/plan/show.js +81 -0
- package/src/commands/plan/validate.js +20 -0
- package/src/commands/plan.js +14 -291
- package/src/commands/researcher.js +7 -2
- package/src/commands/resume.js +24 -1
- package/src/commands/review.js +7 -2
- package/src/commands/run.js +52 -1
- package/src/commands/status.js +1 -1
- package/src/commands/sync.js +75 -0
- package/src/commands/triage.js +7 -2
- package/src/commands/undo.js +1 -1
- package/src/config/defaults.js +213 -0
- package/src/config/loader.js +137 -0
- package/src/config/overrides.js +199 -0
- package/src/config/role-resolver.js +159 -0
- package/src/config/test-harness.js +79 -0
- package/src/config.js +30 -609
- package/src/git/automation.js +2 -2
- package/src/guards/output-guard.js +0 -2
- package/src/hu/acceptance-runner.js +52 -10
- package/src/hu/store.js +11 -0
- package/src/mcp/handlers/direct-handlers.js +2 -5
- package/src/mcp/handlers/management-handlers.js +48 -4
- package/src/mcp/handlers/run-handler.js +9 -8
- package/src/mcp/preflight.js +32 -13
- package/src/mcp/server-handlers.js +4 -3
- package/src/mcp/suggest-handler.js +3 -2
- package/src/mcp/tools.js +15 -0
- package/src/orchestrator/agent-fallback.js +1 -1
- package/src/orchestrator/ci-integration.js +10 -10
- package/src/orchestrator/config-init.js +25 -7
- package/src/orchestrator/direct-actions.js +6 -2
- package/src/orchestrator/drivers/error-recovery.js +287 -0
- package/src/orchestrator/drivers/init-context.js +222 -0
- package/src/orchestrator/drivers/iteration-loop.js +311 -0
- package/src/orchestrator/drivers/iteration-phases/coder-and-refactorer.js +48 -0
- package/src/orchestrator/drivers/iteration-phases/guards.js +84 -0
- package/src/orchestrator/drivers/iteration-phases/handle-approved.js +29 -0
- package/src/orchestrator/drivers/iteration-phases/quality-gates.js +76 -0
- package/src/orchestrator/drivers/iteration-phases/reviewer-gate.js +60 -0
- package/src/orchestrator/drivers/post-loop.js +370 -0
- package/src/orchestrator/drivers/pre-loop-phases/auto-hu-batch.js +116 -0
- package/src/orchestrator/drivers/pre-loop-phases/config-deprecations.js +47 -0
- package/src/orchestrator/drivers/pre-loop-phases/ensure-addyosmani-skills.js +84 -0
- package/src/orchestrator/drivers/pre-loop-phases/inject-loaded-plan.js +268 -0
- package/src/orchestrator/drivers/pre-loop.js +434 -0
- package/src/orchestrator/drivers/run-hu-batch.js +367 -0
- package/src/orchestrator/flow-control.js +4 -3
- package/src/orchestrator/flow-runner.js +121 -2019
- package/src/orchestrator/fs-leak-detector.js +156 -0
- package/src/orchestrator/hu-sub-pipeline.js +197 -9
- package/src/orchestrator/integrations.js +88 -0
- package/src/orchestrator/post-loop-stages.js +35 -8
- package/src/orchestrator/preflight-checks.js +30 -3
- package/src/orchestrator/repair/repair-detector.js +117 -0
- package/src/orchestrator/repair/repair-runner.js +142 -0
- package/src/orchestrator/reviewer-fallback.js +1 -1
- package/src/orchestrator/solomon-escalation.js +3 -2
- package/src/orchestrator/solomon-rules.js +7 -3
- package/src/orchestrator/stages/architect-stage.js +12 -11
- package/src/orchestrator/stages/coder-stage.js +56 -7
- package/src/orchestrator/stages/hu-reviewer-phases/detect-and-apply-splits.js +127 -0
- package/src/orchestrator/stages/hu-reviewer-stage.js +6 -79
- package/src/orchestrator/stages/planner-stage.js +1 -1
- package/src/orchestrator/stages/research-stage.js +1 -1
- package/src/orchestrator/stages/reviewer-stage.js +7 -7
- package/src/orchestrator/stages/sonar-stage.js +94 -10
- package/src/orchestrator/stages/stage-classes.js +86 -0
- package/src/orchestrator/stages/stage-executor.js +1 -1
- package/src/orchestrator/stages/triage-stage.js +1 -1
- package/src/orchestrator/standby.js +3 -2
- package/src/orchestrator/verification-gate.js +20 -12
- package/src/plan/adr-generator.js +170 -0
- package/src/plan/adr-loader.js +60 -0
- package/src/plan/plan-executor.js +19 -1
- package/src/plan/plan-hu-ops.js +170 -1
- package/src/plan/plan-reviewer.js +199 -0
- package/src/plan/plan-schema.js +69 -1
- package/src/plan/plan-store.js +40 -3
- package/src/plan/spec-detector.js +61 -0
- package/src/plan/tests-synthesizer.js +116 -0
- package/src/planning-game/client.js +3 -14
- package/src/planning-game/decomposition.js +1 -1
- package/src/planning-game/pipeline-adapter.js +36 -5
- package/src/prompts/coder.js +172 -1
- package/src/prompts/hu-reviewer.js +0 -1
- package/src/prompts/planner.js +81 -4
- package/src/review/diff-generator.js +35 -22
- package/src/review/snapshot-diff.js +1 -1
- package/src/roles/coder-role.js +25 -3
- package/src/roles/planner-role.js +42 -1
- package/src/roles/repairer-role.js +181 -0
- package/src/roles/tester-role.js +70 -4
- package/src/session/mutators.js +304 -0
- package/src/session/runtime-overrides.js +59 -0
- package/src/{session-store.js → session/store.js} +8 -2
- package/src/skills/semantic-detector.js +10 -5
- package/src/skills/skill-detector.js +1 -1
- package/src/sonar/cloud-scanner.js +0 -1
- package/src/sonar/credentials.js +14 -6
- package/src/sonar/discovery.js +123 -0
- package/src/sonar/manager.js +18 -0
- package/src/sync/detect-drift.js +113 -0
- package/src/tracker-bootstrap.js +44 -0
- package/src/utils/agent-detect.js +15 -11
- package/src/utils/board-prompt-bridge.js +109 -0
- package/src/utils/cli-progress.js +161 -0
- package/src/utils/cwd-confirm.js +39 -0
- package/src/utils/derive-project-name-from-cwd.js +119 -0
- package/src/utils/garbage-collector.js +396 -0
- package/src/utils/git.js +16 -4
- package/src/utils/locale.js +1 -1
- package/src/utils/paths.js +21 -1
- package/src/utils/process.js +1 -1
- package/src/utils/prompt-project-name.js +35 -0
- package/src/utils/run-context.js +75 -0
- package/src/utils/run-log.js +12 -0
- package/src/utils/task-file.js +1 -1
- package/src/utils/telemetry.js +13 -1
- package/src/webperf/devtools-detect.js +1 -1
- package/templates/coder-rules.md +13 -0
- package/templates/roles/coder.md +34 -0
- package/templates/roles/repairer.md +94 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iteration-loop driver — extracted from src/orchestrator/flow-runner.js
|
|
3
|
+
* in TSK-0335 (Oleada 3 of the v2.7.4 audit refactor).
|
|
4
|
+
*
|
|
5
|
+
* Everything inside the coder→reviewer loop:
|
|
6
|
+
*
|
|
7
|
+
* - runCoderAndRefactorerStages: coder (+ refactorer if enabled), with
|
|
8
|
+
* standby handling per stage.
|
|
9
|
+
* - runGuardStages: deterministic output/perf guards on the diff.
|
|
10
|
+
* - runQualityGateStages: TDD check, Sonar (local + cloud), Impeccable.
|
|
11
|
+
* - runReviewerGateStage: reviewer role, with standby handling.
|
|
12
|
+
* - handleApprovedReview: wire post-loop stages + finalize session.
|
|
13
|
+
* - runSingleIteration: one coder→reviewer cycle (the iteration body).
|
|
14
|
+
* - runIterationLoop: the while loop, checkpoints, budget/time
|
|
15
|
+
* gates, error recovery via Solomon,
|
|
16
|
+
* max-iterations extension path.
|
|
17
|
+
*
|
|
18
|
+
* Extracted verbatim; no behavior change. flow-runner.js now imports these
|
|
19
|
+
* instead of defining them. Part of breaking up the 2254-LOC god-module —
|
|
20
|
+
* see docs/ARCHITECTURE.md and the TSK-0335 acceptance criteria.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { emitProgress, makeEvent } from "../../utils/events.js";
|
|
24
|
+
import { msg, getLang } from "../../utils/messages.js";
|
|
25
|
+
import { saveSession, markSessionStatus } from "../../session/store.js";
|
|
26
|
+
import {
|
|
27
|
+
setReviewerFeedback, resetRetryCount,
|
|
28
|
+
} from "../../session/mutators.js";
|
|
29
|
+
import { invokeSolomon } from "../solomon-escalation.js";
|
|
30
|
+
import {
|
|
31
|
+
handleCiEarlyPrOrPush, handleCiReviewDispatch,
|
|
32
|
+
} from "../ci-integration.js";
|
|
33
|
+
import {
|
|
34
|
+
handleCheckpoint, checkSessionTimeout, checkBudgetExceeded,
|
|
35
|
+
takeCheckpointSnapshot,
|
|
36
|
+
} from "../flow-control.js";
|
|
37
|
+
import {
|
|
38
|
+
handleSolomonCheck, handleReviewerRetryAndSolomon,
|
|
39
|
+
} from "./error-recovery.js";
|
|
40
|
+
import { handleMaxIterationsReached } from "./post-loop.js";
|
|
41
|
+
import { runCoderAndRefactorerStages } from "./iteration-phases/coder-and-refactorer.js";
|
|
42
|
+
import { runGuardStages } from "./iteration-phases/guards.js";
|
|
43
|
+
import { runQualityGateStages } from "./iteration-phases/quality-gates.js";
|
|
44
|
+
import { runReviewerGateStage } from "./iteration-phases/reviewer-gate.js";
|
|
45
|
+
import { handleApprovedReview } from "./iteration-phases/handle-approved.js";
|
|
46
|
+
|
|
47
|
+
// Re-export for back-compat with any external caller; the canonical
|
|
48
|
+
// definitions now live in ./iteration-phases/.
|
|
49
|
+
export { runCoderAndRefactorerStages } from "./iteration-phases/coder-and-refactorer.js";
|
|
50
|
+
export { runGuardStages } from "./iteration-phases/guards.js";
|
|
51
|
+
export { runQualityGateStages } from "./iteration-phases/quality-gates.js";
|
|
52
|
+
export { runReviewerGateStage } from "./iteration-phases/reviewer-gate.js";
|
|
53
|
+
export { handleApprovedReview } from "./iteration-phases/handle-approved.js";
|
|
54
|
+
|
|
55
|
+
// `runCoderAndRefactorerStages`, `runGuardStages`, `runQualityGateStages`,
|
|
56
|
+
// `runReviewerGateStage` and `handleApprovedReview` were extracted to
|
|
57
|
+
// ./iteration-phases/ in the v2.7.x audit follow-up (same pattern as
|
|
58
|
+
// pre-loop-phases/). The imports above pull them back in; re-exports
|
|
59
|
+
// keep the previous public surface for any external caller. Behaviour
|
|
60
|
+
// is unchanged.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
export async function runSingleIteration(ctx) {
|
|
64
|
+
// Use plannedTask (HU-scoped or planner-enriched) over the raw original task.
|
|
65
|
+
// When running per-HU sub-pipelines, plannedTask is the HU's text, not the full spec.
|
|
66
|
+
const { config, logger, emitter, eventBase, session, iteration: i } = ctx;
|
|
67
|
+
const task = ctx.plannedTask || ctx.task;
|
|
68
|
+
|
|
69
|
+
const iterStart = Date.now();
|
|
70
|
+
const ciEnabled = Boolean(config.ci?.enabled) && ctx.gitCtx?.enabled;
|
|
71
|
+
logger.setContext({ iteration: i, stage: "iteration" });
|
|
72
|
+
|
|
73
|
+
const reviewerRetryCount = session.reviewer_retry_count || 0;
|
|
74
|
+
const maxReviewerRetries = config.session.max_reviewer_retries ?? config.session.fail_fast_repeats;
|
|
75
|
+
const iterLang = getLang(config);
|
|
76
|
+
const iterMsg = msg("pipeline_iteration", iterLang, { current: i, max: config.max_iterations });
|
|
77
|
+
emitProgress(emitter, makeEvent("iteration:start", { ...eventBase, stage: "iteration" }, {
|
|
78
|
+
message: iterMsg,
|
|
79
|
+
detail: { iteration: i, maxIterations: config.max_iterations, reviewerRetryCount, maxReviewerRetries }
|
|
80
|
+
}));
|
|
81
|
+
logger.info(iterMsg);
|
|
82
|
+
|
|
83
|
+
const crResult = await runCoderAndRefactorerStages({
|
|
84
|
+
coderRoleInstance: ctx.coderRoleInstance, coderRole: ctx.coderRole, refactorerRole: ctx.refactorerRole,
|
|
85
|
+
pipelineFlags: ctx.pipelineFlags, config, logger, emitter, eventBase, session,
|
|
86
|
+
plannedTask: ctx.plannedTask, trackBudget: ctx.trackBudget, i, brainCtx: ctx.brainCtx
|
|
87
|
+
});
|
|
88
|
+
if (crResult.action === "return" || crResult.action === "retry") return crResult;
|
|
89
|
+
|
|
90
|
+
const guardResult = await runGuardStages({ config, logger, emitter, eventBase, session, iteration: i });
|
|
91
|
+
if (guardResult.action === "return") return guardResult;
|
|
92
|
+
|
|
93
|
+
const qgResult = await runQualityGateStages({
|
|
94
|
+
config, logger, emitter, eventBase, session, trackBudget: ctx.trackBudget, i,
|
|
95
|
+
askQuestion: ctx.askQuestion, repeatDetector: ctx.repeatDetector, budgetSummary: ctx.budgetSummary,
|
|
96
|
+
sonarState: ctx.sonarState, task, stageResults: ctx.stageResults, coderRole: ctx.coderRole,
|
|
97
|
+
pipelineFlags: ctx.pipelineFlags, brainCtx: ctx.brainCtx
|
|
98
|
+
});
|
|
99
|
+
if (qgResult.action === "return" || qgResult.action === "continue") return qgResult;
|
|
100
|
+
|
|
101
|
+
await handleCiEarlyPrOrPush({
|
|
102
|
+
ciEnabled, config, session, emitter, eventBase, gitCtx: ctx.gitCtx, task, logger,
|
|
103
|
+
stageResults: ctx.stageResults, i
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const revResult = await runReviewerGateStage({
|
|
107
|
+
pipelineFlags: ctx.pipelineFlags, reviewerRole: ctx.reviewerRole, config, logger, emitter, eventBase,
|
|
108
|
+
session, trackBudget: ctx.trackBudget, i, reviewRules: ctx.reviewRules, task,
|
|
109
|
+
repeatDetector: ctx.repeatDetector, budgetSummary: ctx.budgetSummary, askQuestion: ctx.askQuestion,
|
|
110
|
+
brainCtx: ctx.brainCtx
|
|
111
|
+
});
|
|
112
|
+
if (revResult.action === "return" || revResult.action === "retry") return revResult;
|
|
113
|
+
const review = revResult.review;
|
|
114
|
+
|
|
115
|
+
const iterDuration = Date.now() - iterStart;
|
|
116
|
+
emitProgress(emitter, makeEvent("iteration:end", { ...eventBase, stage: "iteration" }, {
|
|
117
|
+
message: `Iteration ${i} completed`, detail: { duration: iterDuration }
|
|
118
|
+
}));
|
|
119
|
+
resetRetryCount(session, "standby");
|
|
120
|
+
|
|
121
|
+
// --- Journal: record iteration ---
|
|
122
|
+
// Uses the richer iteration-logger from TSK-0286: captures blocking-issue
|
|
123
|
+
// details, sonar counts and Solomon rulings in addition to summaries.
|
|
124
|
+
if (ctx.journalIterations) {
|
|
125
|
+
try {
|
|
126
|
+
const { recordIteration, extractIterationData } = await import("../../session/journal/iteration-logger.js");
|
|
127
|
+
const iterationData = extractIterationData({
|
|
128
|
+
iteration: i,
|
|
129
|
+
durationMs: iterDuration,
|
|
130
|
+
stageResults: ctx.stageResults,
|
|
131
|
+
session: ctx.session,
|
|
132
|
+
});
|
|
133
|
+
// Derive a richer reviewer summary if none was produced.
|
|
134
|
+
if (!iterationData.reviewerSummary && review) {
|
|
135
|
+
iterationData.reviewerSummary = review.approved
|
|
136
|
+
? `Approved: ${review.raw_summary || ""}`
|
|
137
|
+
: `Rejected: ${(review?.blocking_issues || []).length} blocking issue(s)`;
|
|
138
|
+
}
|
|
139
|
+
if (!iterationData.blockingIssues || iterationData.blockingIssues.length === 0) {
|
|
140
|
+
iterationData.blockingIssues = review?.blocking_issues || [];
|
|
141
|
+
}
|
|
142
|
+
recordIteration(ctx.session, iterationData);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
logger.warn(`Iteration journal record failed (non-blocking): ${err.message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const solomonResult = await handleSolomonCheck({
|
|
149
|
+
config, session, emitter, eventBase, logger, task, i, askQuestion: ctx.askQuestion,
|
|
150
|
+
ciEnabled, blockingIssues: review?.blocking_issues, brainCtx: ctx.brainCtx
|
|
151
|
+
});
|
|
152
|
+
if (solomonResult.action === "pause") return { action: "return", result: solomonResult.result };
|
|
153
|
+
|
|
154
|
+
await handleCiReviewDispatch({ ciEnabled, config, session, review, i, logger });
|
|
155
|
+
|
|
156
|
+
if (review.approved) {
|
|
157
|
+
const approvedResult = await handleApprovedReview({
|
|
158
|
+
config, session, emitter, eventBase, coderRole: ctx.coderRole, trackBudget: ctx.trackBudget, i, task,
|
|
159
|
+
stageResults: ctx.stageResults, pipelineFlags: ctx.pipelineFlags, askQuestion: ctx.askQuestion, logger,
|
|
160
|
+
gitCtx: ctx.gitCtx, budgetSummary: ctx.budgetSummary, pgCard: ctx.pgCard, pgProject: ctx.pgProject, review,
|
|
161
|
+
rtkTracker: ctx.rtkTracker, brainCtx: ctx.brainCtx
|
|
162
|
+
});
|
|
163
|
+
if (approvedResult.action === "return" || approvedResult.action === "continue") return approvedResult;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Solomon already evaluated the rejection in runReviewerStage -> handleReviewerRejection
|
|
167
|
+
// Only use retry counter as fallback if Solomon is disabled
|
|
168
|
+
if (!config.pipeline?.solomon?.enabled) {
|
|
169
|
+
const retryResult = await handleReviewerRetryAndSolomon({ config, session, emitter, eventBase, logger, review, task, i, askQuestion: ctx.askQuestion });
|
|
170
|
+
if (retryResult.action === "return") return retryResult;
|
|
171
|
+
} else {
|
|
172
|
+
// Solomon is enabled — feed back the blocking issues for the next coder iteration
|
|
173
|
+
setReviewerFeedback(session, review.blocking_issues
|
|
174
|
+
.map((x) => {
|
|
175
|
+
const parts = [`[${x.severity || "high"}] ${x.id || "ISSUE"}: ${x.description || "Missing description"}`];
|
|
176
|
+
if (x.file) parts.push(` File: ${x.file}${x.line ? `:${x.line}` : ""}`);
|
|
177
|
+
if (x.suggested_fix) parts.push(` Fix: ${x.suggested_fix}`);
|
|
178
|
+
return parts.join("\n");
|
|
179
|
+
})
|
|
180
|
+
.join("\n\n"));
|
|
181
|
+
await saveSession(session);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return { action: "next" };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Run the standard iteration loop for a given task using the pipeline context.
|
|
190
|
+
* Returns a result object with at least { approved: boolean }.
|
|
191
|
+
* Used both as the main loop and as the per-HU callback in sub-pipeline mode.
|
|
192
|
+
*/
|
|
193
|
+
export async function runIterationLoop(ctx, { task: loopTask, askQuestion, emitter, logger }) {
|
|
194
|
+
ctx.plannedTask = loopTask;
|
|
195
|
+
|
|
196
|
+
const checkpointIntervalMs = (ctx.config.session.checkpoint_interval_minutes ?? 5) * 60 * 1000;
|
|
197
|
+
let lastCheckpointAt = Date.now();
|
|
198
|
+
let checkpointDisabled = false;
|
|
199
|
+
let lastCheckpointSnapshot = takeCheckpointSnapshot(ctx.session);
|
|
200
|
+
|
|
201
|
+
let i = 0;
|
|
202
|
+
while (i < ctx.config.max_iterations) {
|
|
203
|
+
i += 1;
|
|
204
|
+
const elapsedMinutes = (Date.now() - ctx.startedAt) / 60000;
|
|
205
|
+
|
|
206
|
+
const cpResult = await handleCheckpoint({
|
|
207
|
+
checkpointDisabled, askQuestion, lastCheckpointAt, checkpointIntervalMs, elapsedMinutes,
|
|
208
|
+
i, config: ctx.config, budgetTracker: ctx.budgetTracker, stageResults: ctx.stageResults, emitter, eventBase: ctx.eventBase, session: ctx.session, budgetSummary: ctx.budgetSummary, lastCheckpointSnapshot
|
|
209
|
+
});
|
|
210
|
+
if (cpResult.action === "stop") {
|
|
211
|
+
return cpResult.result;
|
|
212
|
+
}
|
|
213
|
+
checkpointDisabled = cpResult.checkpointDisabled;
|
|
214
|
+
lastCheckpointAt = cpResult.lastCheckpointAt;
|
|
215
|
+
if (cpResult.lastCheckpointSnapshot !== undefined) lastCheckpointSnapshot = cpResult.lastCheckpointSnapshot;
|
|
216
|
+
|
|
217
|
+
await checkSessionTimeout({ askQuestion, elapsedMinutes, config: ctx.config, session: ctx.session, emitter, eventBase: ctx.eventBase, i, budgetSummary: ctx.budgetSummary });
|
|
218
|
+
await checkBudgetExceeded({ budgetTracker: ctx.budgetTracker, config: ctx.config, session: ctx.session, emitter, eventBase: ctx.eventBase, i, budgetLimit: ctx.budgetLimit, budgetSummary: ctx.budgetSummary });
|
|
219
|
+
|
|
220
|
+
ctx.eventBase.iteration = i;
|
|
221
|
+
ctx.iteration = i;
|
|
222
|
+
|
|
223
|
+
let iterResult;
|
|
224
|
+
try {
|
|
225
|
+
iterResult = await runSingleIteration(ctx);
|
|
226
|
+
} catch (stageError) {
|
|
227
|
+
// ANY unhandled error in a stage = out of normal flow → Solomon decides
|
|
228
|
+
logger.warn(`Stage error caught — escalating to Solomon: ${stageError.message}`);
|
|
229
|
+
const solomonResult = await invokeSolomon({
|
|
230
|
+
config: ctx.config, logger, emitter, eventBase: ctx.eventBase,
|
|
231
|
+
stage: "stage_error", askQuestion, session: ctx.session, iteration: i,
|
|
232
|
+
conflict: {
|
|
233
|
+
stage: "stage_error",
|
|
234
|
+
task: loopTask,
|
|
235
|
+
iterationCount: i,
|
|
236
|
+
maxIterations: ctx.config.max_iterations,
|
|
237
|
+
budget_usd: ctx.budgetSummary()?.total_cost_usd || 0,
|
|
238
|
+
history: [{ agent: "pipeline", feedback: `Stage threw: ${stageError.message}` }]
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (solomonResult.action === "approve") {
|
|
243
|
+
logger.info("Solomon approved despite stage error");
|
|
244
|
+
return { approved: true, sessionId: ctx.session.id, reason: "solomon_approved_after_error" };
|
|
245
|
+
}
|
|
246
|
+
if (solomonResult.action === "continue") {
|
|
247
|
+
if (solomonResult.humanGuidance) {
|
|
248
|
+
setReviewerFeedback(ctx.session, `Solomon guidance: ${solomonResult.humanGuidance}`);
|
|
249
|
+
}
|
|
250
|
+
continue; // next iteration
|
|
251
|
+
}
|
|
252
|
+
if (solomonResult.action === "pause") {
|
|
253
|
+
return { paused: true, sessionId: ctx.session.id, question: solomonResult.question, context: "stage_error" };
|
|
254
|
+
}
|
|
255
|
+
// Solomon couldn't resolve — fail
|
|
256
|
+
await markSessionStatus(ctx.session, "failed");
|
|
257
|
+
return { approved: false, sessionId: ctx.session.id, reason: "stage_error", error: stageError.message };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (iterResult.action === "return") {
|
|
261
|
+
return iterResult.result;
|
|
262
|
+
}
|
|
263
|
+
if (iterResult.action === "retry") { i -= 1; }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Solomon decides whether to extend iterations or stop
|
|
267
|
+
const maxIterResult = await handleMaxIterationsReached({ session: ctx.session, budgetSummary: ctx.budgetSummary, emitter, eventBase: ctx.eventBase, config: ctx.config, stageResults: ctx.stageResults, logger, askQuestion, task: loopTask, rtkTracker: ctx.rtkTracker, brainCtx: ctx.brainCtx });
|
|
268
|
+
|
|
269
|
+
// Solomon said "continue" — extend iterations and keep going
|
|
270
|
+
if (maxIterResult.reason === "max_iterations_extended") {
|
|
271
|
+
const extra = maxIterResult.extraIterations || ctx.config.max_iterations;
|
|
272
|
+
ctx.config.max_iterations += extra;
|
|
273
|
+
logger.info(`Solomon extended pipeline by ${extra} iterations (new max: ${ctx.config.max_iterations})`);
|
|
274
|
+
|
|
275
|
+
if (maxIterResult.humanGuidance) {
|
|
276
|
+
setReviewerFeedback(ctx.session, `Solomon guidance: ${maxIterResult.humanGuidance}`);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Continue the loop
|
|
280
|
+
while (i < ctx.config.max_iterations) {
|
|
281
|
+
i += 1;
|
|
282
|
+
const elapsedMinutes = (Date.now() - ctx.startedAt) / 60000;
|
|
283
|
+
|
|
284
|
+
const cpResult = await handleCheckpoint({
|
|
285
|
+
checkpointDisabled, askQuestion, lastCheckpointAt, checkpointIntervalMs, elapsedMinutes,
|
|
286
|
+
i, config: ctx.config, budgetTracker: ctx.budgetTracker, stageResults: ctx.stageResults, emitter, eventBase: ctx.eventBase, session: ctx.session, budgetSummary: ctx.budgetSummary, lastCheckpointSnapshot
|
|
287
|
+
});
|
|
288
|
+
if (cpResult.action === "stop") return cpResult.result;
|
|
289
|
+
checkpointDisabled = cpResult.checkpointDisabled;
|
|
290
|
+
lastCheckpointAt = cpResult.lastCheckpointAt;
|
|
291
|
+
if (cpResult.lastCheckpointSnapshot !== undefined) lastCheckpointSnapshot = cpResult.lastCheckpointSnapshot;
|
|
292
|
+
|
|
293
|
+
await checkSessionTimeout({ askQuestion, elapsedMinutes, config: ctx.config, session: ctx.session, emitter, eventBase: ctx.eventBase, i, budgetSummary: ctx.budgetSummary });
|
|
294
|
+
await checkBudgetExceeded({ budgetTracker: ctx.budgetTracker, config: ctx.config, session: ctx.session, emitter, eventBase: ctx.eventBase, i, budgetLimit: ctx.budgetLimit, budgetSummary: ctx.budgetSummary });
|
|
295
|
+
|
|
296
|
+
ctx.eventBase.iteration = i;
|
|
297
|
+
ctx.iteration = i;
|
|
298
|
+
|
|
299
|
+
const iterResult = await runSingleIteration(ctx);
|
|
300
|
+
if (iterResult.action === "return") return iterResult.result;
|
|
301
|
+
if (iterResult.action === "retry") { i -= 1; }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Extended iterations also exhausted — final Solomon call
|
|
305
|
+
const finalResult = await handleMaxIterationsReached({ session: ctx.session, budgetSummary: ctx.budgetSummary, emitter, eventBase: ctx.eventBase, config: ctx.config, stageResults: ctx.stageResults, logger, askQuestion, task: loopTask, rtkTracker: ctx.rtkTracker, brainCtx: ctx.brainCtx });
|
|
306
|
+
return finalResult;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return maxIterResult;
|
|
310
|
+
}
|
|
311
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iteration phase: coder (+ refactorer if enabled) with standby handling.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `src/orchestrator/drivers/iteration-loop.js` in
|
|
5
|
+
* the v2.7.x audit follow-up to keep the iteration-loop driver under the
|
|
6
|
+
* 600-LOC ceiling. Behaviour is byte-for-byte identical to the inlined
|
|
7
|
+
* version. The extraction follows the same pattern as
|
|
8
|
+
* `pre-loop-phases/` (see TSK-0337).
|
|
9
|
+
*
|
|
10
|
+
* Returns { action: "ok" | "return" | "retry", result? }.
|
|
11
|
+
* - "ok" → caller continues to the next phase.
|
|
12
|
+
* - "return" → caller returns `result` to its own caller (pause/abort).
|
|
13
|
+
* - "retry" → caller decrements its iteration counter and retries.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { runRefactorerStage } from "../../iteration-stages.js";
|
|
17
|
+
import { stageRegistry } from "../../stages/stage-classes.js";
|
|
18
|
+
import { runStage } from "../../stages/stage-executor.js";
|
|
19
|
+
import { handleStandbyResult } from "../error-recovery.js";
|
|
20
|
+
|
|
21
|
+
export async function runCoderAndRefactorerStages({ coderRoleInstance, coderRole, refactorerRole, pipelineFlags, config, logger, emitter, eventBase, session, plannedTask, trackBudget, i, brainCtx }) {
|
|
22
|
+
// Coder via StageRegistry (TSK-0336). canRun = coderRequired !== false; in
|
|
23
|
+
// analysis-only task types coderRequired is set to false by policy, so the
|
|
24
|
+
// stage is never even entered — matches the previous guard at the top of
|
|
25
|
+
// runFlow.
|
|
26
|
+
const coderCtx = { coderRoleInstance, coderRole, config, logger, emitter, eventBase, session, plannedTask, trackBudget, iteration: i, brainCtx, pipelineFlags };
|
|
27
|
+
const coderResult = await runStage(stageRegistry.get("coder"), coderCtx);
|
|
28
|
+
if (coderResult?.action === "pause") return { action: "return", result: coderResult.result };
|
|
29
|
+
const coderStandby = await handleStandbyResult({ stageResult: coderResult, session, emitter, eventBase, i, stage: "coder", logger, config });
|
|
30
|
+
if (coderStandby.handled) {
|
|
31
|
+
return coderStandby.action === "return"
|
|
32
|
+
? { action: "return", result: coderStandby.result }
|
|
33
|
+
: { action: "retry" };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (pipelineFlags.refactorerEnabled) {
|
|
37
|
+
const refResult = await runRefactorerStage({ refactorerRole, config, logger, emitter, eventBase, session, plannedTask, trackBudget, iteration: i });
|
|
38
|
+
if (refResult?.action === "pause") return { action: "return", result: refResult.result };
|
|
39
|
+
const refStandby = await handleStandbyResult({ stageResult: refResult, session, emitter, eventBase, i, stage: "refactorer", logger, config });
|
|
40
|
+
if (refStandby.handled) {
|
|
41
|
+
return refStandby.action === "return"
|
|
42
|
+
? { action: "return", result: refStandby.result }
|
|
43
|
+
: { action: "retry" };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { action: "ok" };
|
|
48
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iteration phase: deterministic output / perf guards on the diff.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `src/orchestrator/drivers/iteration-loop.js` in
|
|
5
|
+
* the v2.7.x audit follow-up to keep the iteration-loop driver under the
|
|
6
|
+
* 600-LOC ceiling. Behaviour is byte-for-byte identical to the inlined
|
|
7
|
+
* version.
|
|
8
|
+
*
|
|
9
|
+
* Returns { action: "ok" | "return", result? }.
|
|
10
|
+
* - "ok" → caller continues to the next phase.
|
|
11
|
+
* - "return" → caller returns `result` (output guard blocked on critical
|
|
12
|
+
* violations).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { emitProgress, makeEvent } from "../../../utils/events.js";
|
|
16
|
+
import { markSessionStatus, addCheckpoint } from "../../../session/store.js";
|
|
17
|
+
import { generateDiff, computeBaseRef } from "../../../review/diff-generator.js";
|
|
18
|
+
import { scanDiff } from "../../../guards/output-guard.js";
|
|
19
|
+
import { scanPerfDiff } from "../../../guards/perf-guard.js";
|
|
20
|
+
|
|
21
|
+
export async function runGuardStages({ config, logger, emitter, eventBase, session, iteration }) {
|
|
22
|
+
const outputEnabled = config.guards?.output?.enabled !== false;
|
|
23
|
+
const perfEnabled = config.guards?.perf?.enabled !== false;
|
|
24
|
+
|
|
25
|
+
if (!outputEnabled && !perfEnabled) return { action: "ok" };
|
|
26
|
+
|
|
27
|
+
const baseBranch = config.base_branch || "main";
|
|
28
|
+
let diff;
|
|
29
|
+
try {
|
|
30
|
+
const baseRef = await computeBaseRef({ baseBranch });
|
|
31
|
+
diff = await generateDiff({ baseRef });
|
|
32
|
+
} catch {
|
|
33
|
+
logger.warn("Guards: could not generate diff, skipping");
|
|
34
|
+
return { action: "ok" };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!diff) return { action: "ok" };
|
|
38
|
+
|
|
39
|
+
if (outputEnabled) {
|
|
40
|
+
const outputResult = scanDiff(diff, config);
|
|
41
|
+
if (outputResult.violations.length > 0) {
|
|
42
|
+
const critical = outputResult.violations.filter(v => v.severity === "critical");
|
|
43
|
+
const warnings = outputResult.violations.filter(v => v.severity === "warning");
|
|
44
|
+
emitProgress(emitter, makeEvent("guard:output", { ...eventBase, stage: "guard" }, {
|
|
45
|
+
message: `Output guard: ${critical.length} critical, ${warnings.length} warnings`,
|
|
46
|
+
detail: { violations: outputResult.violations, executorType: "local" }
|
|
47
|
+
}));
|
|
48
|
+
logger.info(`Output guard: ${outputResult.violations.length} violation(s) found`);
|
|
49
|
+
for (const v of outputResult.violations) {
|
|
50
|
+
logger.info(` [${v.severity}] ${v.file}:${v.line} — ${v.message}`);
|
|
51
|
+
}
|
|
52
|
+
await addCheckpoint(session, { stage: "guard-output", iteration, pass: outputResult.pass, violations: outputResult.violations.length });
|
|
53
|
+
|
|
54
|
+
if (!outputResult.pass && config.guards.output.on_violation === "block") {
|
|
55
|
+
await markSessionStatus(session, "failed");
|
|
56
|
+
emitProgress(emitter, makeEvent("guard:blocked", { ...eventBase, stage: "guard" }, {
|
|
57
|
+
message: "Output guard blocked: critical violations detected",
|
|
58
|
+
detail: { violations: critical }
|
|
59
|
+
}));
|
|
60
|
+
return {
|
|
61
|
+
action: "return",
|
|
62
|
+
result: { approved: false, sessionId: session.id, reason: "guard_blocked", violations: critical }
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (perfEnabled) {
|
|
69
|
+
const perfResult = scanPerfDiff(diff, config);
|
|
70
|
+
if (!perfResult.skipped && perfResult.violations.length > 0) {
|
|
71
|
+
emitProgress(emitter, makeEvent("guard:perf", { ...eventBase, stage: "guard" }, {
|
|
72
|
+
message: `Perf guard: ${perfResult.violations.length} issue(s)`,
|
|
73
|
+
detail: { violations: perfResult.violations, executorType: "local" }
|
|
74
|
+
}));
|
|
75
|
+
logger.info(`Perf guard: ${perfResult.violations.length} issue(s) found`);
|
|
76
|
+
for (const v of perfResult.violations) {
|
|
77
|
+
logger.info(` [${v.severity}] ${v.file}:${v.line} — ${v.message}`);
|
|
78
|
+
}
|
|
79
|
+
await addCheckpoint(session, { stage: "guard-perf", iteration, pass: perfResult.pass, violations: perfResult.violations.length });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { action: "ok" };
|
|
84
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iteration phase: post-loop wiring + session finalization when the
|
|
3
|
+
* reviewer approves.
|
|
4
|
+
*
|
|
5
|
+
* Extracted verbatim from `src/orchestrator/drivers/iteration-loop.js` in
|
|
6
|
+
* the v2.7.x audit follow-up to keep the iteration-loop driver under the
|
|
7
|
+
* 600-LOC ceiling. Behaviour is byte-for-byte identical to the inlined
|
|
8
|
+
* version.
|
|
9
|
+
*
|
|
10
|
+
* Returns { action: "return" | "continue", result? }.
|
|
11
|
+
* - "return" → caller returns `result` (final approved session).
|
|
12
|
+
* - "continue" → caller continues the iteration loop.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { resetRetryCount } from "../../../session/mutators.js";
|
|
16
|
+
import { handlePostLoopStages, finalizeApprovedSession } from "../post-loop.js";
|
|
17
|
+
|
|
18
|
+
export async function handleApprovedReview({ config, session, emitter, eventBase, coderRole, trackBudget, i, task, stageResults, pipelineFlags, askQuestion, logger, gitCtx, budgetSummary, pgCard, pgProject, review, rtkTracker, brainCtx }) {
|
|
19
|
+
resetRetryCount(session, "reviewer");
|
|
20
|
+
const postLoopResult = await handlePostLoopStages({
|
|
21
|
+
config, session, emitter, eventBase, coderRole, trackBudget, i, task, stageResults,
|
|
22
|
+
ciEnabled: Boolean(config.ci?.enabled), testerEnabled: pipelineFlags.testerEnabled, securityEnabled: pipelineFlags.securityEnabled, askQuestion, logger, brainCtx
|
|
23
|
+
});
|
|
24
|
+
if (postLoopResult.action === "return") return { action: "return", result: postLoopResult.result };
|
|
25
|
+
if (postLoopResult.action === "continue") return { action: "continue" };
|
|
26
|
+
|
|
27
|
+
const result = await finalizeApprovedSession({ config, gitCtx, task, logger, session, stageResults, emitter, eventBase, budgetSummary, pgCard, pgProject, review, i, rtkTracker });
|
|
28
|
+
return { action: "return", result };
|
|
29
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iteration phase: quality gates (TDD check, SonarQube local + cloud,
|
|
3
|
+
* Impeccable design audit).
|
|
4
|
+
*
|
|
5
|
+
* Extracted verbatim from `src/orchestrator/drivers/iteration-loop.js` in
|
|
6
|
+
* the v2.7.x audit follow-up to keep the iteration-loop driver under the
|
|
7
|
+
* 600-LOC ceiling. Behaviour is byte-for-byte identical to the inlined
|
|
8
|
+
* version.
|
|
9
|
+
*
|
|
10
|
+
* Returns { action: "ok" | "return" | "continue", result? }.
|
|
11
|
+
* - "ok" → caller continues to the next phase.
|
|
12
|
+
* - "return" → caller returns `result` (pause / stalled / blocked).
|
|
13
|
+
* - "continue" → caller continues the iteration loop (next iteration).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { generateDiff } from "../../../review/diff-generator.js";
|
|
17
|
+
import {
|
|
18
|
+
runTddCheckStage, runSonarStage, runSonarCloudStage,
|
|
19
|
+
} from "../../iteration-stages.js";
|
|
20
|
+
import { runImpeccableStage } from "../../post-loop-stages.js";
|
|
21
|
+
import { tryCiComment } from "../../ci-integration.js";
|
|
22
|
+
|
|
23
|
+
export async function runQualityGateStages({ config, logger, emitter, eventBase, session, trackBudget, i, askQuestion, repeatDetector, budgetSummary, sonarState, task, stageResults, coderRole, pipelineFlags, brainCtx }) {
|
|
24
|
+
const tddResult = await runTddCheckStage({ config, logger, emitter, eventBase, session, trackBudget, iteration: i, askQuestion, task, brainCtx });
|
|
25
|
+
if (tddResult.action === "pause") return { action: "return", result: tddResult.result };
|
|
26
|
+
if (tddResult.action === "continue") return { action: "continue" };
|
|
27
|
+
|
|
28
|
+
// Sonar runs for code tasks per policy. Since v2.7.4 it is NOT
|
|
29
|
+
// toggleable via config — that's intrinsic to Karajan. The taskType
|
|
30
|
+
// policy (resolved_policies.sonar) is the single source of truth.
|
|
31
|
+
// Solomon may skip a single iteration via rule alerts; that's a
|
|
32
|
+
// runtime decision, not a config option.
|
|
33
|
+
//
|
|
34
|
+
// Test-harness escape hatch via config.testHarness.disableSonarStage
|
|
35
|
+
// — production code reads `config?.testHarness?.disableSonarStage`,
|
|
36
|
+
// never `globalThis.*`. The legacy override surface is documented
|
|
37
|
+
// (and exclusively read) in src/config/test-harness.js. ESLint rule
|
|
38
|
+
// (#557) blocks any re-introduction of `globalThis.__KJ_*` outside
|
|
39
|
+
// that one file.
|
|
40
|
+
const sonarStageDisabledForTest = config?.testHarness?.disableSonarStage === true;
|
|
41
|
+
if (!sonarStageDisabledForTest && session.resolved_policies?.sonar !== false) {
|
|
42
|
+
const sonarResult = await runSonarStage({
|
|
43
|
+
config, logger, emitter, eventBase, session, trackBudget, iteration: i,
|
|
44
|
+
repeatDetector, budgetSummary, sonarState, askQuestion, task, brainCtx
|
|
45
|
+
});
|
|
46
|
+
if (sonarResult.action === "stalled" || sonarResult.action === "pause") return { action: "return", result: sonarResult.result };
|
|
47
|
+
if (sonarResult.action === "continue") return { action: "continue" };
|
|
48
|
+
if (sonarResult.stageResult) {
|
|
49
|
+
stageResults.sonar = sonarResult.stageResult;
|
|
50
|
+
await tryCiComment({ config, session, logger, agent: "Sonar", body: `SonarQube scan: ${sonarResult.stageResult.summary || "completed"}` });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (config.sonarcloud?.enabled) {
|
|
55
|
+
const cloudResult = await runSonarCloudStage({
|
|
56
|
+
config, logger, emitter, eventBase, session, trackBudget, iteration: i
|
|
57
|
+
});
|
|
58
|
+
if (cloudResult.stageResult) {
|
|
59
|
+
stageResults.sonarcloud = cloudResult.stageResult;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (pipelineFlags?.impeccableEnabled) {
|
|
64
|
+
const diff = await generateDiff({ baseRef: session.session_start_sha });
|
|
65
|
+
const impeccableMode = pipelineFlags?.impeccableMode || "audit";
|
|
66
|
+
const impeccableResult = await runImpeccableStage({
|
|
67
|
+
config, logger, emitter, eventBase, session, coderRole, trackBudget,
|
|
68
|
+
iteration: i, task, diff, mode: impeccableMode
|
|
69
|
+
});
|
|
70
|
+
if (impeccableResult.stageResult) {
|
|
71
|
+
stageResults.impeccable = impeccableResult.stageResult;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { action: "ok" };
|
|
76
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iteration phase: reviewer stage with standby handling.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `src/orchestrator/drivers/iteration-loop.js` in
|
|
5
|
+
* the v2.7.x audit follow-up to keep the iteration-loop driver under the
|
|
6
|
+
* 600-LOC ceiling. Behaviour is byte-for-byte identical to the inlined
|
|
7
|
+
* version.
|
|
8
|
+
*
|
|
9
|
+
* Returns { action: "ok" | "return" | "retry", review?, result? }.
|
|
10
|
+
* - "ok" → caller proceeds with `review` (approved or with blocking
|
|
11
|
+
* issues).
|
|
12
|
+
* - "return" → caller returns `result` (pause / stalled).
|
|
13
|
+
* - "retry" → caller decrements its iteration counter and retries.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { stageRegistry } from "../../stages/stage-classes.js";
|
|
17
|
+
import { runStage } from "../../stages/stage-executor.js";
|
|
18
|
+
import { handleStandbyResult } from "../error-recovery.js";
|
|
19
|
+
|
|
20
|
+
export async function runReviewerGateStage({ pipelineFlags, reviewerRole, config, logger, emitter, eventBase, session, trackBudget, i, reviewRules, task, repeatDetector, budgetSummary, askQuestion, brainCtx }) {
|
|
21
|
+
// Reviewer via StageRegistry (TSK-0336). ReviewerStage.canRun returns
|
|
22
|
+
// `reviewerEnabled !== false`; when false, runStage returns null and we
|
|
23
|
+
// synthesize the "disabled-by-pipeline" stub (same shape as the previous
|
|
24
|
+
// early-return). Otherwise execute() runs runReviewerStage.
|
|
25
|
+
const reviewerCtx = {
|
|
26
|
+
reviewerRole, config, logger, emitter, eventBase, session, trackBudget,
|
|
27
|
+
iteration: i, reviewRules, task, repeatDetector, budgetSummary, askQuestion,
|
|
28
|
+
brainCtx, pipelineFlags,
|
|
29
|
+
};
|
|
30
|
+
const reviewerResult = await runStage(stageRegistry.get("reviewer"), reviewerCtx);
|
|
31
|
+
if (reviewerResult === null) {
|
|
32
|
+
return {
|
|
33
|
+
action: "ok",
|
|
34
|
+
review: { approved: true, blocking_issues: [], non_blocking_suggestions: [], summary: "Reviewer disabled by pipeline", confidence: 1 }
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (reviewerResult.action === "pause") return { action: "return", result: reviewerResult.result };
|
|
38
|
+
const revStandby = await handleStandbyResult({ stageResult: reviewerResult, session, emitter, eventBase, i, stage: "reviewer", logger, config, askQuestion });
|
|
39
|
+
if (revStandby.handled) {
|
|
40
|
+
if (revStandby.action === "return") return { action: "return", result: revStandby.result };
|
|
41
|
+
if (revStandby.action === "skip") {
|
|
42
|
+
// Solomon said skip review — treat as approved
|
|
43
|
+
return { action: "ok", review: { approved: true, blocking_issues: [], non_blocking_suggestions: [], summary: "Review skipped (agent rate-limited, Solomon approved)", confidence: 0.7 } };
|
|
44
|
+
}
|
|
45
|
+
if (revStandby.action === "retry_reviewer_only") {
|
|
46
|
+
// Retry just the reviewer — use alternative agent if Solomon recommended one
|
|
47
|
+
let retryReviewerRole = reviewerRole;
|
|
48
|
+
const alt = session._alternative_agent;
|
|
49
|
+
if (alt?.stage === "reviewer" && alt?.provider) {
|
|
50
|
+
retryReviewerRole = { provider: alt.provider, model: null };
|
|
51
|
+
logger.info(`Retrying reviewer with alternative agent: ${alt.provider}`);
|
|
52
|
+
delete session._alternative_agent;
|
|
53
|
+
}
|
|
54
|
+
return runReviewerGateStage({ pipelineFlags: { reviewerEnabled: true }, reviewerRole: retryReviewerRole, config, logger, emitter, eventBase, session, trackBudget, i, reviewRules, task, repeatDetector, budgetSummary, askQuestion });
|
|
55
|
+
}
|
|
56
|
+
return { action: "retry" };
|
|
57
|
+
}
|
|
58
|
+
if (reviewerResult.stalled) return { action: "return", result: reviewerResult.stalledResult };
|
|
59
|
+
return { action: "ok", review: reviewerResult.review };
|
|
60
|
+
}
|