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 { TesterMeta } from "./roles/tester/index.js"; import type { CommitterMeta } from "./roles/committer/index.js"; export type WorkflowMeta = { planner: PlannerMeta; coder: CoderMeta; tester: TesterMeta; committer: CommitterMeta; }; export const moderator: Moderator = (context) => { if (context.steps.length === 0) { return "planner"; } const last = context.steps[context.steps.length - 1]; if (last.role === "planner") { if (last.meta.workflowName.trim().length > 0) return "coder"; const plannerAttempts = context.steps.filter((s) => s.role === "planner").length; return plannerAttempts < 3 ? "planner" : END; } if (last.role === "coder") { if (last.meta.lintPassed && last.meta.buildPassed) { return "tester"; } if (last.meta.attempt < 3) { return "coder"; } return END; } if (last.role === "tester") { if (last.meta.passed) { return "committer"; } if (last.meta.attempt < 3) { return "coder"; } return END; } return END; };