Files
ci/src/core/decision-engine.ts
T
CI fb3f1df13e release(v0.4.0): purge learnship, migrate .planning→.ci, fix backends, add test coverage
- Remove all learnship references: Decision.learnship_equivalent field,
  agent persona prompts, opencode.json permissions, test fixtures
- Migrate verification layers from .planning/ to .ci/: structural
  checks .ci/ dir + ROADMAP.md, behavioral checks ROADMAP.md
- Fix ollama-local: remove sync require+curl blocking, use async
  fetchAvailableModels() in callModel
- Fix opencode.json: use __OPENCODE_DIR__ template tokens, remove
  legacy learnship permission entries
- Remove duplicate install script from package.json (keep postinstall)
- Fix quality any-regex false positives (target type annotations only)
- Add backends test coverage: backends.test.ts, tool-registry.test.ts
- Version bump 0.3.0 → 0.4.0
- Artifacts module: rename .planning→.ci internal paths
- Remove dead TODO_PATTERN/FIXME_PATTERN constants

---ci---
phase: 3
milestone: v0.4
status: complete
requirements:
  covered: [REQ-09, REQ-10, REQ-11, REQ-13, REQ-14, REQ-17]
  partial: []
decisions:
  - id: D-001
    decision: purge all learnship references from codebase
    rationale: project is CI-only, learnship is no longer a dependency
    confidence: 0.99
    category: scope
    alternatives: [keep for historical reference]
  - id: D-002
    decision: migrate verification from .planning/ to .ci/ paths
    rationale: .planning/ is removed schema, all current state lives in .ci/
    confidence: 0.95
    category: architecture
    alternatives: [keep dual-path support]
  - id: D-003
    decision: use __OPENCODE_DIR__ template tokens in opencode.json
    rationale: hardcoded ~ paths fail in containers and non-standard homes
    confidence: 0.90
    category: implementation_approach
    alternatives: [keep tilde expansion]
---/ci---
2026-05-29 16:18:30 +00:00

150 lines
4.0 KiB
TypeScript

import { execSync } from "node:child_process";
import { Decision, DecisionCategory, Alternative, confidenceToLevel } from "../types/decisions.js";
import { CIConfig } from "../types/config.js";
import { CommitBuilder, DecisionCommitInput } from "./commit-builder.js";
import { CommitDecision } from "../types/commit-meta.js";
export interface DecisionInput {
decision: string;
rationale: string;
confidence: number;
category: DecisionCategory;
alternatives_considered: Alternative[];
phase?: string;
task?: string;
}
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, milestone: string = "v1.0") {
this.config = config;
this.projectPath = projectPath;
this.currentPhase = 0;
this.currentMilestone = milestone;
this.decisionCounter = 0;
}
setPhase(phase: number): void {
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;
const decision: Decision = {
id,
timestamp: new Date().toISOString(),
decision: input.decision,
rationale: input.rationale,
confidence: input.confidence,
category: input.category,
alternatives_considered: input.alternatives_considered,
human_override: null,
phase: input.phase,
task: input.task,
};
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);
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, commitMessage };
}
makeHighConfidenceDecision(
decision: string,
rationale: string,
category: DecisionCategory,
alternatives: Alternative[] = []
): DecisionResult {
return this.makeDecision({
decision,
rationale,
confidence: 0.95,
category,
alternatives_considered: alternatives,
});
}
makeMediumConfidenceDecision(
decision: string,
rationale: string,
category: DecisionCategory,
alternatives: Alternative[] = []
): DecisionResult {
return this.makeDecision({
decision,
rationale,
confidence: 0.7,
category,
alternatives_considered: alternatives,
});
}
shouldAutoDecide(confidence: number): boolean {
return confidence >= this.config.autonomy.decision_confidence_threshold;
}
isIrreversibleAction(action: string): boolean {
return this.config.autonomy.escalation_hooks.some((hook) =>
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;
}
}
}