2026-04-28 02:38:07 +00:00

45 lines
1.3 KiB
TypeScript

import { createCursorRole } from "@uncaged/nerve-workflow-utils";
import { resolveDashScopeProvider, buildSenseExamples, getNerveYaml, NERVE_ROOT } from "../shared.js";
import { plannerMetaSchema } from "../types.js";
import type { SenseMeta } from "../types.js";
const senseExamples = buildSenseExamples();
const nerveYaml = getNerveYaml();
export async function buildPlannerRole() {
const provider = await resolveDashScopeProvider();
if (provider === null) {
throw new Error("Cannot create planner: set DASHSCOPE_API_KEY and DASHSCOPE_BASE_URL");
}
return createCursorRole<SenseMeta["planner"]>({
cwd: NERVE_ROOT,
mode: "ask",
prompt: async (threadId) =>
`You are planning a new Nerve sense.
Read the workflow thread for the user's request: \`nerve thread ${threadId}\`
Pick a good kebab-case name for this sense. Produce a PLAN (not code) in markdown:
## Sense Design
### Name — kebab-case
### Fields — name, type (integer/real/text), description
### Compute Logic — step-by-step, specific Node.js APIs or shell commands
### Trigger Config — group, interval, throttle, timeout
Reference senses:
${senseExamples}
Current nerve.yaml:
\`\`\`yaml
${nerveYaml}
\`\`\`
Output ONLY the plan. Be precise and implementation-ready.`,
extract: {
provider,
schema: plannerMetaSchema,
},
});
}