import { END } from "@uncaged/nerve-core"; import type { Moderator } from "@uncaged/nerve-core"; import type { PlannerMeta } from "./roles/planner/index.js"; import type { CoderMeta } from "./roles/coder/index.js"; import type { ReviewerMeta } from "./roles/reviewer/index.js"; import type { TesterMeta } from "./roles/tester/index.js"; import type { CommitterMeta } from "./roles/committer/index.js"; export type WorkflowMeta = { planner: PlannerMeta; coder: CoderMeta; reviewer: ReviewerMeta; tester: TesterMeta; committer: CommitterMeta; }; const MAX_CODER_ITERATIONS = 5; export const moderator: Moderator = (context) => { if (context.steps.length === 0) return "planner"; const last = context.steps[context.steps.length - 1]; const coderCount = context.steps.filter((s) => s.role === "coder").length; if (last.role === "planner") { return last.meta.ready ? "coder" : END; } if (last.role === "coder") { if (last.meta.done) return "reviewer"; return coderCount < MAX_CODER_ITERATIONS ? "coder" : END; } if (last.role === "reviewer") { if (last.meta.approved) return "tester"; return coderCount < MAX_CODER_ITERATIONS ? "coder" : END; } if (last.role === "tester") { if (last.meta.passed) return "committer"; return coderCount < MAX_CODER_ITERATIONS ? "coder" : END; } if (last.role === "committer") { if (last.meta.success) return END; return coderCount < MAX_CODER_ITERATIONS ? "coder" : END; } return END; };