Each role's index.ts + prompt.ts merged into a single <role>.ts file. Committer stays as re-export from _shared. Import paths updated in build.ts and moderator.ts. Closes #13
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { END } from "@uncaged/nerve-core";
|
|
import type { Moderator } from "@uncaged/nerve-core";
|
|
import type { PlannerMeta } from "./roles/planner.js";
|
|
import type { CoderMeta } from "./roles/coder.js";
|
|
import type { ReviewerMeta } from "./roles/reviewer.js";
|
|
import type { TesterMeta } from "./roles/tester.js";
|
|
import type { CommitterMeta } from "./roles/committer.js";
|
|
|
|
export type SenseMeta = {
|
|
planner: PlannerMeta;
|
|
coder: CoderMeta;
|
|
reviewer: ReviewerMeta;
|
|
tester: TesterMeta;
|
|
committer: CommitterMeta;
|
|
};
|
|
|
|
const MAX_CODER_ROUNDS = 20;
|
|
const MAX_TOTAL_REJECTIONS = 10;
|
|
|
|
function coderRounds(steps: { role: string }[]): number {
|
|
return steps.filter((s) => s.role === "coder").length;
|
|
}
|
|
|
|
function totalRejections(steps: { role: string; meta: unknown }[]): number {
|
|
return steps.filter((s) => {
|
|
if (s.role === "reviewer") return !(s.meta as Record<string, boolean>).approved;
|
|
if (s.role === "tester") return !(s.meta as Record<string, boolean>).passed;
|
|
if (s.role === "committer") return !(s.meta as Record<string, boolean>).committed;
|
|
return false;
|
|
}).length;
|
|
}
|
|
|
|
function canRetryCoder(steps: { role: string; meta: unknown }[]): boolean {
|
|
return coderRounds(steps) < MAX_CODER_ROUNDS && totalRejections(steps) < MAX_TOTAL_REJECTIONS;
|
|
}
|
|
|
|
export const moderator: Moderator<SenseMeta> = (context) => {
|
|
if (context.steps.length === 0) return "planner";
|
|
|
|
const last = context.steps[context.steps.length - 1];
|
|
|
|
if (last.role === "planner") return "coder";
|
|
|
|
if (last.role === "coder") {
|
|
if (last.meta.filesCreated) return "reviewer";
|
|
return canRetryCoder(context.steps) ? "coder" : END;
|
|
}
|
|
|
|
if (last.role === "reviewer") {
|
|
if (last.meta.approved) return "tester";
|
|
return canRetryCoder(context.steps) ? "coder" : END;
|
|
}
|
|
|
|
if (last.role === "tester") {
|
|
if (last.meta.passed) return "committer";
|
|
return canRetryCoder(context.steps) ? "coder" : END;
|
|
}
|
|
|
|
if (last.role === "committer") {
|
|
if (last.meta.committed) return END;
|
|
return canRetryCoder(context.steps) ? "coder" : END;
|
|
}
|
|
|
|
return END;
|
|
};
|