- 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
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import type { AgentFn, Role, RoleResult, StartStep, WorkflowMessage } from "@uncaged/nerve-core";
|
|
import type { LlmExtractorConfig } from "@uncaged/nerve-workflow-utils";
|
|
import { createRole } from "@uncaged/nerve-workflow-utils";
|
|
import { z } from "zod";
|
|
|
|
import { resolveRepoCwd } from "../../lib/repo-context.js";
|
|
import { buildImplementPrompt } from "./prompt.js";
|
|
|
|
export const implementMetaSchema = z.object({
|
|
done: z.boolean().describe("true when changes are complete and build passes this round"),
|
|
});
|
|
export type ImplementMeta = z.infer<typeof implementMetaSchema>;
|
|
|
|
export type CreateImplementRoleDeps = {
|
|
extract: LlmExtractorConfig;
|
|
nerveRoot: string;
|
|
};
|
|
|
|
export function createImplementRole(
|
|
adapter: AgentFn,
|
|
{ extract, nerveRoot }: CreateImplementRoleDeps,
|
|
): Role<ImplementMeta> {
|
|
return async (start: StartStep, messages: WorkflowMessage[]): Promise<RoleResult<ImplementMeta>> => {
|
|
const cwd = resolveRepoCwd(messages);
|
|
if (cwd === null) {
|
|
return {
|
|
content: "implement cannot run: missing repo path in thread markers",
|
|
meta: { done: false },
|
|
};
|
|
}
|
|
|
|
const innerRole = createRole(
|
|
adapter,
|
|
async (innerStart: StartStep) =>
|
|
buildImplementPrompt({
|
|
threadId: innerStart.meta.threadId,
|
|
nerveRoot,
|
|
}),
|
|
implementMetaSchema,
|
|
extract,
|
|
);
|
|
|
|
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: `implement failed: ${msg}`,
|
|
meta: { done: false },
|
|
};
|
|
}
|
|
};
|
|
}
|