v0.2.0: Git-native architecture (#1)

This commit was merged in pull request #1.
This commit is contained in:
2026-05-29 12:59:45 +00:00
parent 9cf5c000d9
commit 6e637e4af0
50 changed files with 5852 additions and 135 deletions
+46 -6
View File
@@ -1,7 +1,8 @@
import * as crypto from "node:crypto";
import { execSync } from "node:child_process";
import { Decision, DecisionCategory, Alternative, confidenceToLevel } from "../types/decisions.js";
import { CIConfig } from "../types/config.js";
import { logDecision } from "./audit.js";
import { CommitBuilder, DecisionCommitInput } from "./commit-builder.js";
import { CommitDecision } from "../types/commit-meta.js";
export interface DecisionInput {
decision: string;
@@ -18,18 +19,21 @@ export interface DecisionResult {
decision: Decision;
escalated: boolean;
reason?: string;
commitMessage?: string;
}
export class DecisionEngine {
private config: CIConfig;
private projectPath: string;
private currentPhase: number;
private currentMilestone: string;
private decisionCounter: number;
constructor(config: CIConfig, projectPath: string) {
constructor(config: CIConfig, projectPath: string, milestone: string = "v1.0") {
this.config = config;
this.projectPath = projectPath;
this.currentPhase = 0;
this.currentMilestone = milestone;
this.decisionCounter = 0;
}
@@ -37,6 +41,10 @@ export class DecisionEngine {
this.currentPhase = phase;
}
setMilestone(milestone: string): void {
this.currentMilestone = milestone;
}
makeDecision(input: DecisionInput): DecisionResult {
const id = `D-${String(++this.decisionCounter).padStart(3, "0")}`;
const threshold = this.config.autonomy.decision_confidence_threshold;
@@ -55,19 +63,38 @@ export class DecisionEngine {
task: input.task,
};
logDecision(this.projectPath, this.currentPhase, decision);
const commitDecision: CommitDecision = {
id,
decision: input.decision,
rationale: input.rationale,
confidence: input.confidence,
alternatives: input.alternatives_considered.map((a) => a.option),
};
const confidenceLevel = confidenceToLevel(input.confidence);
if (input.confidence < threshold) {
const escalated = input.confidence < threshold;
let commitMessage: string | undefined;
if (this.config.git.auto_commit) {
commitMessage = CommitBuilder.buildDecisionCommit({
phase: this.currentPhase,
milestone: this.currentMilestone,
subject: input.decision,
decisions: [commitDecision],
});
}
if (escalated) {
return {
decision,
escalated: true,
reason: `Confidence ${input.confidence.toFixed(2)} below threshold ${threshold} (${confidenceLevel})`,
commitMessage,
};
}
return { decision, escalated: false };
return { decision, escalated: false, commitMessage };
}
makeHighConfidenceDecision(
@@ -113,4 +140,17 @@ export class DecisionEngine {
action.toLowerCase().includes(hook.toLowerCase())
);
}
commitDecision(commitMessage: string): boolean {
if (!this.config.git.auto_commit) return false;
try {
execSync(`git add -A && git commit -m "${commitMessage.replace(/"/g, '\\"')}" --allow-empty`, {
cwd: this.projectPath,
stdio: "pipe",
});
return true;
} catch {
return false;
}
}
}