fix(P03): honest execution — real rollback, honest orchestrator, git-native verification
---ci---
project: ci
phase: 3
milestone: v0.5
status: complete
decisions:
- id: D-026
decision: Phase 3 Honest Execution complete
rationale: All HONEST requirements covered; no more fake success returns
confidence: 0.95
alternatives: []
requirements:
covered: [HONEST-01, HONEST-02, HONEST-03]
---/ci---
This commit is contained in:
@@ -224,7 +224,8 @@ export class OrchestratorAgent extends BaseAgent {
|
||||
cwd: context.project_path,
|
||||
stdio: "pipe",
|
||||
});
|
||||
} catch {
|
||||
} catch (err) {
|
||||
this.warn(`Specify commit failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -275,6 +276,21 @@ export class OrchestratorAgent extends BaseAgent {
|
||||
this.log("Researching project domain...");
|
||||
this.decisionEngine!.setPhase(1);
|
||||
|
||||
const archMd = this.ciFiles!.readArchitectureMd();
|
||||
if (!archMd) {
|
||||
this.log("No ARCHITECTURE.md found — mechanical research cannot proceed without backend");
|
||||
return {
|
||||
phase: this.pipelineState!.current_phase,
|
||||
stage: "research",
|
||||
success: false,
|
||||
artifacts_created: artifactsCreated,
|
||||
decisions_made: decisionsMade,
|
||||
escalations_raised: escalationsRaised,
|
||||
duration_ms: Date.now() - stageStart,
|
||||
error: "Research stage requires intelligence backend or existing ARCHITECTURE.md",
|
||||
};
|
||||
}
|
||||
|
||||
if (this.config.git.auto_commit && this.gitContext!.isGitRepo()) {
|
||||
const researchCommit = CommitBuilder.buildResearchCommit(
|
||||
1,
|
||||
@@ -288,7 +304,8 @@ export class OrchestratorAgent extends BaseAgent {
|
||||
cwd: context.project_path,
|
||||
stdio: "pipe",
|
||||
});
|
||||
} catch {
|
||||
} catch (err) {
|
||||
this.warn(`Research commit failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,11 +326,42 @@ export class OrchestratorAgent extends BaseAgent {
|
||||
|
||||
case "execute":
|
||||
this.log("Executing implementation...");
|
||||
if (!context.backend) {
|
||||
this.log("No backend available — mechanical execution cannot implement code changes");
|
||||
return {
|
||||
phase: this.pipelineState!.current_phase,
|
||||
stage: "execute",
|
||||
success: false,
|
||||
artifacts_created: artifactsCreated,
|
||||
decisions_made: decisionsMade,
|
||||
escalations_raised: escalationsRaised,
|
||||
duration_ms: Date.now() - stageStart,
|
||||
error: "Execute stage requires intelligence backend for code implementation",
|
||||
};
|
||||
}
|
||||
this.pipelineState!.execute_completed = true;
|
||||
break;
|
||||
|
||||
case "verify": {
|
||||
this.log("Running verification...");
|
||||
|
||||
const { VerificationPipeline } = await import("../verification/index.js");
|
||||
const verification = new VerificationPipeline(context.project_path);
|
||||
const verifyResult = await verification.run(this.pipelineState!.current_phase || 1);
|
||||
|
||||
if (!verifyResult.all_passed) {
|
||||
return {
|
||||
phase: this.pipelineState!.current_phase,
|
||||
stage: "verify",
|
||||
success: false,
|
||||
artifacts_created: artifactsCreated,
|
||||
decisions_made: decisionsMade,
|
||||
escalations_raised: escalationsRaised,
|
||||
duration_ms: Date.now() - stageStart,
|
||||
error: `Verification failed: ${verifyResult.escalations_needed.join("; ")}`,
|
||||
};
|
||||
}
|
||||
|
||||
this.pipelineState!.verify_completed = true;
|
||||
|
||||
if (this.config.git.auto_commit && this.gitContext!.isGitRepo()) {
|
||||
@@ -329,7 +377,8 @@ export class OrchestratorAgent extends BaseAgent {
|
||||
cwd: context.project_path,
|
||||
stdio: "pipe",
|
||||
});
|
||||
} catch {
|
||||
} catch (err) {
|
||||
this.warn(`Verify commit failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +403,8 @@ export class OrchestratorAgent extends BaseAgent {
|
||||
cwd: context.project_path,
|
||||
stdio: "pipe",
|
||||
});
|
||||
} catch {
|
||||
} catch (err) {
|
||||
this.warn(`Completion commit failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import { CIConfig } from "../types/config.js";
|
||||
|
||||
export interface RetryConfig {
|
||||
@@ -67,12 +68,39 @@ export class ErrorRecovery {
|
||||
}
|
||||
|
||||
async rollback(phase: number, reason: string): Promise<RecoveryResult> {
|
||||
try {
|
||||
const phaseBranch = `phase/${String(phase).padStart(2, "0")}`;
|
||||
const branches = this.git("branch --list");
|
||||
const branchExists = branches.split("\n").some((b) => b.trim().replace(/^\*?\s+/, "") === phaseBranch);
|
||||
|
||||
if (branchExists) {
|
||||
const currentBranch = this.git("rev-parse --abbrev-ref HEAD");
|
||||
if (currentBranch === phaseBranch) {
|
||||
this.git("checkout main");
|
||||
}
|
||||
this.git(`branch -D ${phaseBranch}`);
|
||||
}
|
||||
|
||||
const tag = `v0.5.${phase}`;
|
||||
const tags = this.git("tag -l").split("\n").map((t) => t.trim());
|
||||
if (tags.includes(tag)) {
|
||||
this.git(`tag -d ${tag}`);
|
||||
}
|
||||
|
||||
return {
|
||||
recovered: true,
|
||||
strategy: "rollback",
|
||||
attempts: 1,
|
||||
message: `Rolled back phase ${phase}: ${reason}`,
|
||||
message: `Rolled back phase ${phase}: ${reason}. Branch ${branchExists ? `${phaseBranch} deleted` : "not found"}. Tag ${tags.includes(tag) ? `${tag} deleted` : "not found"}.`,
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
recovered: false,
|
||||
strategy: "rollback",
|
||||
attempts: 1,
|
||||
message: `Rollback failed for phase ${phase}: ${err instanceof Error ? err.message : String(err)}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
canAutoDebug(error: string, confidence: number): boolean {
|
||||
@@ -86,4 +114,16 @@ export class ErrorRecovery {
|
||||
getMaxRevisions(): number {
|
||||
return this.config.autonomy.max_revision_iterations;
|
||||
}
|
||||
|
||||
private git(args: string): string {
|
||||
try {
|
||||
return execSync(`git ${args}`, {
|
||||
cwd: this.projectPath,
|
||||
encoding: "utf-8",
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,10 +49,33 @@ describe("BehavioralVerification", () => {
|
||||
expect(testFilesCheck?.status).toBe("pass");
|
||||
});
|
||||
|
||||
it("passes with specification and requirements", async () => {
|
||||
it("passes with REQUIREMENTS.md", async () => {
|
||||
const ciDir = path.join(tempDir, ".ci");
|
||||
fs.mkdirSync(ciDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(ciDir, "specification.md"), "# Test\n## Objective\nBuild it\n\n## Requirements\n- Must have auth\n- Shall support CRUD\n");
|
||||
fs.writeFileSync(path.join(ciDir, "REQUIREMENTS.md"), "# Requirements\n\n| REQ-ID | Requirement | Priority | Phase | Status |\n|--------|-------------|----------|-------|--------|\n| REQ-01 | Must have auth | P0 | 1 | pending |\n");
|
||||
|
||||
const verifier = new BehavioralVerification();
|
||||
const result = await verifier.verify(tempDir, 1);
|
||||
|
||||
const specCheck = result.checks.find((c) => c.name === "Specification requirements traceable");
|
||||
expect(specCheck?.status).toBe("pass");
|
||||
});
|
||||
|
||||
it("skips when no REQUIREMENTS.md or PROJECT.md", async () => {
|
||||
const ciDir = path.join(tempDir, ".ci");
|
||||
fs.mkdirSync(ciDir, { recursive: true });
|
||||
|
||||
const verifier = new BehavioralVerification();
|
||||
const result = await verifier.verify(tempDir, 1);
|
||||
|
||||
const specCheck = result.checks.find((c) => c.name === "Specification requirements traceable");
|
||||
expect(specCheck?.status).toBe("skipped");
|
||||
});
|
||||
|
||||
it("passes with PROJECT.md when no REQUIREMENTS.md", async () => {
|
||||
const ciDir = path.join(tempDir, ".ci");
|
||||
fs.mkdirSync(ciDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(ciDir, "PROJECT.md"), "# Test\n\n## What This Is\nBuild it\n\n## Requirements\n\n### Active\n\n- [ ] Must have auth\n- [ ] Shall support CRUD\n");
|
||||
|
||||
const verifier = new BehavioralVerification();
|
||||
const result = await verifier.verify(tempDir, 1);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { execSync } from "node:child_process";
|
||||
import { VerificationLayer, VerificationResult, VerificationCheck } from "./types.js";
|
||||
|
||||
const TEST_FRAMEWORK_PATTERNS = [
|
||||
@@ -106,15 +107,59 @@ export class BehavioralVerification extends VerificationLayer {
|
||||
}
|
||||
|
||||
private checkSpecificationRequirements(projectPath: string): VerificationCheck {
|
||||
const specPath = path.join(projectPath, ".ci", "specification.md");
|
||||
const reqPath = path.join(projectPath, ".ci", "REQUIREMENTS.md");
|
||||
const projectPath_md = path.join(projectPath, ".ci", "PROJECT.md");
|
||||
|
||||
const specPath = reqPath;
|
||||
if (!fs.existsSync(specPath)) {
|
||||
const altPath = projectPath_md;
|
||||
if (!fs.existsSync(altPath)) {
|
||||
return this.check(
|
||||
"Specification requirements traceable",
|
||||
"skipped",
|
||||
"No specification file found"
|
||||
"No REQUIREMENTS.md or PROJECT.md found"
|
||||
);
|
||||
}
|
||||
return this.checkFromProjectMd(altPath);
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(specPath, "utf-8");
|
||||
const requirements = content
|
||||
.split("\n")
|
||||
.filter((line) => /^\|.*\|.*\|.*\|/.test(line) && !line.includes("REQ-ID") && !line.includes("---"))
|
||||
.map((line) => {
|
||||
const cols = line.split("|").map((c) => c.trim()).filter(Boolean);
|
||||
return cols.length >= 2 ? cols[1] : "";
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
if (requirements.length === 0) {
|
||||
const listRequirements = content
|
||||
.split("\n")
|
||||
.filter((line) => line.trim().startsWith("- "))
|
||||
.map((line) => line.trim().slice(2));
|
||||
if (listRequirements.length === 0) {
|
||||
return this.check(
|
||||
"Specification requirements traceable",
|
||||
"warning",
|
||||
"No requirements found in REQUIREMENTS.md"
|
||||
);
|
||||
}
|
||||
return this.check(
|
||||
"Specification requirements traceable",
|
||||
"pass",
|
||||
`Found ${listRequirements.length} requirement(s)`
|
||||
);
|
||||
}
|
||||
|
||||
return this.check(
|
||||
"Specification requirements traceable",
|
||||
"pass",
|
||||
`Found ${requirements.length} requirement(s) in REQUIREMENTS.md`
|
||||
);
|
||||
}
|
||||
|
||||
private checkFromProjectMd(specPath: string): VerificationCheck {
|
||||
const content = fs.readFileSync(specPath, "utf-8");
|
||||
const requirements = content
|
||||
.split("\n")
|
||||
@@ -129,7 +174,7 @@ export class BehavioralVerification extends VerificationLayer {
|
||||
return this.check(
|
||||
"Specification requirements traceable",
|
||||
"warning",
|
||||
"No requirements found in specification"
|
||||
"No requirements found in PROJECT.md"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user