小橘 2d63639ed1 refactor(sense-generator): split roles into separate directories
Following nerve-dev best practice: each role gets its own directory.

Structure:
  index.ts                    — 31 lines (WorkflowDefinition + moderator)
  roles/planner/index.ts      — 48 lines (createCursorRole)
  roles/coder/index.ts        — 33 lines (createCursorRole)
  roles/tester/index.ts       — 122 lines (hand-written smoke test)
  roles/shared.ts             — 63 lines (providers, helpers)
  roles/types.ts              — 5 lines (SenseMeta)

Was: single 416-line index.ts

Refs uncaged/nerve#210
小橘 🍊(NEKO Team)
2026-04-28 02:30:12 +00:00

34 lines
1.2 KiB
TypeScript

import { createCursorRole } from "@uncaged/nerve-workflow-utils";
import { z } from "zod";
import { resolveDashScopeProvider, NERVE_ROOT, SENSES_DIR } from "../shared.js";
import type { SenseMeta } from "../types.js";
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) =>
`Read the workflow thread for the planner's sense design: \`nerve thread ${threadId}\`
Implement the sense. Create exactly:
1. The sense directory under ${SENSES_DIR}/<sense-name>/
2. index.js — export async function compute(db, _peers), import schema from "./schema.ts"
3. schema.ts — drizzle-orm/sqlite-core
4. migrations/0001_init.sql — must match schema.ts
5. Update ${NERVE_ROOT}/nerve.yaml — add sense config + reflex entry
Follow the patterns from existing senses. Create all files now.`,
extract: {
provider,
schema: z.object({
filesCreated: z.boolean().describe("true if the sense files were created"),
}),
},
});
}