- Rename build* → create* workflow factories - Workflow factories accept adapters: Record<string, AgentFn> - Each role file exports createXxxRole(adapter, ...) factory - _shared/workspace-committer accepts adapter as first param - All adapter imports moved to index.ts (injection point) - solve-issue roles also updated Closes #15
68 lines
1.9 KiB
TypeScript
68 lines
1.9 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 { resolveRepoCwd } from "../../lib/repo-context.js";
|
|
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 type CreateCommitterRoleDeps = {
|
|
extract: LlmExtractorConfig;
|
|
nerveRoot: string;
|
|
};
|
|
|
|
export function createCommitterRole(
|
|
adapter: AgentFn,
|
|
{ extract, nerveRoot }: CreateCommitterRoleDeps,
|
|
): Role<CommitterMeta> {
|
|
const innerRole = createRole(
|
|
adapter,
|
|
async (start: StartStep) =>
|
|
committerPrompt({
|
|
threadId: start.meta.threadId,
|
|
nerveRoot,
|
|
}),
|
|
committerMetaSchema,
|
|
extract,
|
|
);
|
|
|
|
return async (start: StartStep, messages: WorkflowMessage[]): Promise<RoleResult<CommitterMeta>> => {
|
|
const cwd = resolveRepoCwd(messages);
|
|
if (cwd === null) {
|
|
return {
|
|
content: "committer cannot run: missing repo path in thread markers",
|
|
meta: { committed: false },
|
|
};
|
|
}
|
|
|
|
if (isDryRun(start)) {
|
|
return {
|
|
content: "[dry-run] committer skipped (no git branch/commit/push)",
|
|
meta: { committed: true },
|
|
};
|
|
}
|
|
|
|
const innerStart = {
|
|
...start,
|
|
meta: { ...start.meta, workdir: cwd },
|
|
} as StartStep;
|
|
|
|
try {
|
|
return await innerRole(innerStart, messages);
|
|
} catch (e) {
|
|
const msg = e instanceof Error ? e.message : String(e);
|
|
return {
|
|
content: `committer failed: ${msg}`,
|
|
meta: { committed: false },
|
|
};
|
|
}
|
|
};
|
|
}
|