feat: OpenCode 和 Claude Code 适配器及测试
This commit is contained in:
37
src/adapters/claude-code.ts
Normal file
37
src/adapters/claude-code.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { STAGES } from "../types.ts";
|
||||
|
||||
const COMMANDS_DIR = ".claude/commands";
|
||||
|
||||
export async function injectClaudeCode(projectRoot: string): Promise<void> {
|
||||
for (const stage of STAGES) {
|
||||
const hasChangeName = stage !== "discuss";
|
||||
|
||||
const commandDir = join(projectRoot, COMMANDS_DIR);
|
||||
await mkdir(commandDir, { recursive: true });
|
||||
const commandPath = join(commandDir, `${stage}.md`);
|
||||
if (!existsSync(commandPath)) {
|
||||
const cmd = hasChangeName
|
||||
? `rune ${stage} <变更名>`
|
||||
: `rune ${stage}`;
|
||||
const nameHint = hasChangeName
|
||||
? "\n如果用户没有指定变更名称,请向用户确认。"
|
||||
: "";
|
||||
await writeFile(
|
||||
commandPath,
|
||||
`执行以下命令,将输出作为当前阶段的工作指引:\n\`\`\`bash\n${cmd}\n\`\`\`${nameHint}\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const commandDir = join(projectRoot, COMMANDS_DIR);
|
||||
const statusPath = join(commandDir, "rune-status.md");
|
||||
if (!existsSync(statusPath)) {
|
||||
await writeFile(
|
||||
statusPath,
|
||||
`执行以下命令查看变更状态:\n\`\`\`bash\nrune status\n\`\`\`\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user