小橘 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

28 lines
1.0 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, NERVE_ROOT, SENSES_DIR } from "../shared.js";
import { coderMetaSchema } 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");
export async function buildCoderRole() {
const provider = await resolveDashScopeProvider();
if (provider === null) {
throw new Error("Cannot create coder: set DASHSCOPE_API_KEY and DASHSCOPE_BASE_URL");
}
return createCursorRole<SenseMeta["coder"]>({
cwd: NERVE_ROOT,
mode: "default",
prompt: async (threadId) =>
PROMPT
.replace("{{threadId}}", threadId)
.replace("{{sensesDir}}", SENSES_DIR)
.replace("{{nerveRoot}}", NERVE_ROOT),
extract: { provider, schema: coderMetaSchema },
});
}