小橘 a811660a33 refactor(sense-generator): extract prompts to prompt.md templates
Each role's prompt is now a separate markdown file with {{mustache}} placeholders,
loaded at module init and interpolated at runtime.

小橘 🍊(NEKO Team)
2026-04-28 03:32:51 +00:00

30 lines
1.1 KiB
TypeScript

import { createCursorRole } from "@uncaged/nerve-workflow-utils";
import { readFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { resolveDashScopeProvider, buildSenseExamples, getNerveYaml, NERVE_ROOT } from "../shared.js";
import { plannerMetaSchema } from "../types.js";
import type { SenseMeta } from "../types.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
const PROMPT = readFileSync(join(__dirname, "prompt.md"), "utf-8");
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) =>
PROMPT
.replace("{{threadId}}", threadId)
.replace("{{senseExamples}}", senseExamples)
.replace("{{nerveYaml}}", nerveYaml),
extract: { provider, schema: plannerMetaSchema },
});
}