小橘 0a9da468f7 refactor: simplify workspace committer — agent infers context from thread
Remove nerveRoot, workflowName, conventionalCommitScopeHint, branchCheckoutExample params.
Signature: createWorkspaceCommitterRole(adapter, extract)
Agent reads thread history to decide branch name, scope, and commit message.

Closes #17
2026-04-29 12:52:56 +00:00

45 lines
1.3 KiB
TypeScript

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<typeof committerMetaSchema>;
export function createCommitterRole(
adapter: AgentFn,
extract: LlmExtractorConfig,
): Role<CommitterMeta> {
const innerRole = createRole(
adapter,
async (start: StartStep) => committerPrompt({ threadId: start.meta.threadId }),
committerMetaSchema,
extract,
);
return async (start: StartStep, messages: WorkflowMessage[]): Promise<RoleResult<CommitterMeta>> => {
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 },
};
}
};
}