import type { AgentFn, Role, RoleResult, StartStep, WorkflowMessage } from "@uncaged/nerve-core"; import type { LlmExtractorConfig } from "@uncaged/nerve-workflow-utils"; import { createRole, isDryRun } from "@uncaged/nerve-workflow-utils"; import { z } from "zod"; import { committerPrompt } from "./prompt.js"; export const committerMetaSchema = z.object({ committed: z .boolean() .describe("true if branch created, changes committed, and pushed successfully"), }); export type CommitterMeta = z.infer; export function createCommitterRole( adapter: AgentFn, extract: LlmExtractorConfig, ): Role { const innerRole = createRole( adapter, async (start: StartStep) => committerPrompt({ threadId: start.meta.threadId }), committerMetaSchema, extract, ); return async (start: StartStep, messages: WorkflowMessage[]): Promise> => { if (isDryRun(start)) { return { content: "[dry-run] committer skipped (no git branch/commit/push)", meta: { committed: true }, }; } try { return await innerRole(start, messages); } catch (e) { const msg = e instanceof Error ? e.message : String(e); return { content: `committer failed: ${msg}`, meta: { committed: false }, }; } }; }