- 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
66 lines
2.5 KiB
TypeScript
66 lines
2.5 KiB
TypeScript
import type { AgentFn, Role, StartStep } from "@uncaged/nerve-core";
|
|
import type { LlmExtractorConfig } from "@uncaged/nerve-workflow-utils";
|
|
import { createRole } from "@uncaged/nerve-workflow-utils";
|
|
import { z } from "zod";
|
|
|
|
export const plannerMetaSchema = z.object({
|
|
ready: z.boolean().describe("true if requirements are clear and a workflow can be implemented"),
|
|
});
|
|
export type PlannerMeta = z.infer<typeof plannerMetaSchema>;
|
|
|
|
export function plannerPrompt({ threadId }: { threadId: string }): string {
|
|
return `You are a Nerve workflow planner. You can **create new workflows** or **modify existing ones**.
|
|
|
|
Read the workflow thread for the user's request: \`nerve thread ${threadId}\`
|
|
Read the nerve-dev skill for workflow conventions: \`cat node_modules/@uncaged/nerve-skills/nerve-dev/SKILL.md\`
|
|
List existing workflows: \`ls workflows/\`
|
|
|
|
## Determine the task type
|
|
|
|
1. If the user wants to **modify an existing workflow** — read its current code (\`cat workflows/<name>/moderator.ts\`, \`cat workflows/<name>/build.ts\`, \`ls workflows/<name>/roles/\`, etc.) and understand its current structure before planning changes.
|
|
2. If the user wants to **create a new workflow** — look at existing workflows in \`workflows/\` for patterns to follow.
|
|
|
|
## Produce a PLAN (not code) in markdown
|
|
|
|
For **new workflows**:
|
|
- Workflow name (kebab-case)
|
|
- Roles list (name, purpose, tool)
|
|
- Flow transitions / moderator routing logic
|
|
- Validation loops design
|
|
- External dependencies
|
|
- Data flow between roles
|
|
|
|
For **modifications to existing workflows**:
|
|
- Workflow name (existing)
|
|
- What changes are needed and why
|
|
- Files to add/modify/delete
|
|
- Impact on moderator routing logic (this workflow's typical order is planner → coder → reviewer → tester → committer)
|
|
- Backward compatibility considerations (if any)
|
|
|
|
**For every role (new or modified)**, include a **Role Behavior** section that describes:
|
|
- What the role should do, check, or produce
|
|
- What tools or commands it should use
|
|
- What criteria determine its meta output (e.g. approved/passed/done)
|
|
- Preserve the user's specific requirements verbatim — do NOT summarize away details
|
|
|
|
If requirements are NOT clear, describe what is missing or ambiguous.
|
|
|
|
End your response with a JSON block:
|
|
\`\`\`json
|
|
{ "ready": true }
|
|
\`\`\`
|
|
or
|
|
\`\`\`json
|
|
{ "ready": false }
|
|
\`\`\``;
|
|
}
|
|
|
|
export function createPlannerRole(adapter: AgentFn, extract: LlmExtractorConfig): Role<PlannerMeta> {
|
|
return createRole(
|
|
adapter,
|
|
async (start: StartStep) => plannerPrompt({ threadId: start.meta.threadId }),
|
|
plannerMetaSchema,
|
|
extract,
|
|
);
|
|
}
|