Switch build.ts and solve-issue inner roles to @uncaged/nerve-workflow-utils createRole with LlmExtractorConfig. Remove @uncaged/nerve-daemon from workspace dependencies; keep override for linking. Planner uses createCursorAdapter ask mode; dynamic cwd via start.meta.workdir. Made-with: Cursor
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import type { Role, RoleResult, StartStep, WorkflowMessage } from "@uncaged/nerve-core";
|
|
import { createCursorAdapter } from "@uncaged/nerve-adapter-cursor";
|
|
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 { buildPlanPrompt } from "./prompt.js";
|
|
|
|
export const planMetaSchema = z.object({
|
|
ready: z.boolean().describe("true if plan is clear and actionable"),
|
|
});
|
|
export type PlanMeta = z.infer<typeof planMetaSchema>;
|
|
|
|
export type BuildPlanDeps = {
|
|
extract: LlmExtractorConfig;
|
|
nerveRoot: string;
|
|
};
|
|
|
|
const CURSOR_TIMEOUT_MS = 300_000;
|
|
|
|
export function buildPlanRole({ extract, nerveRoot }: BuildPlanDeps): Role<PlanMeta> {
|
|
return async (start: StartStep, messages: WorkflowMessage[]): Promise<RoleResult<PlanMeta>> => {
|
|
const cwd = resolveRepoCwd(messages);
|
|
if (cwd === null) {
|
|
return {
|
|
content: "plan cannot run: missing ---SOLVE_ISSUE_REPO--- or ---SOLVE_ISSUE_PARSE--- in thread",
|
|
meta: { ready: false },
|
|
};
|
|
}
|
|
|
|
const innerRole = createRole(
|
|
createCursorAdapter({
|
|
type: "cursor",
|
|
mode: "ask",
|
|
model: "auto",
|
|
timeout: CURSOR_TIMEOUT_MS,
|
|
}),
|
|
async (innerStart: StartStep) =>
|
|
buildPlanPrompt({
|
|
threadId: innerStart.meta.threadId,
|
|
nerveRoot,
|
|
}),
|
|
planMetaSchema,
|
|
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: `plan failed: ${msg}`,
|
|
meta: { ready: false },
|
|
};
|
|
}
|
|
};
|
|
}
|