diff --git a/src/targets/droid.ts b/src/targets/droid.ts index 85600766..23bd46e5 100644 --- a/src/targets/droid.ts +++ b/src/targets/droid.ts @@ -1,5 +1,5 @@ import path from "path" -import { copyDir, ensureDir, writeText } from "../utils/files" +import { copyDir, ensureDir, resolveCommandPath, writeText } from "../utils/files" import type { DroidBundle } from "../types/droid" export async function writeDroidBundle(outputRoot: string, bundle: DroidBundle): Promise { @@ -9,7 +9,8 @@ export async function writeDroidBundle(outputRoot: string, bundle: DroidBundle): if (bundle.commands.length > 0) { await ensureDir(paths.commandsDir) for (const command of bundle.commands) { - await writeText(path.join(paths.commandsDir, `${command.name}.md`), command.content + "\n") + const dest = await resolveCommandPath(paths.commandsDir, command.name, ".md") + await writeText(dest, command.content + "\n") } } diff --git a/src/targets/gemini.ts b/src/targets/gemini.ts index 0bc8c666..0df7d514 100644 --- a/src/targets/gemini.ts +++ b/src/targets/gemini.ts @@ -1,5 +1,5 @@ import path from "path" -import { backupFile, copyDir, ensureDir, pathExists, readJson, writeJson, writeText } from "../utils/files" +import { backupFile, copyDir, ensureDir, pathExists, readJson, resolveCommandPath, writeJson, writeText } from "../utils/files" import type { GeminiBundle } from "../types/gemini" export async function writeGeminiBundle(outputRoot: string, bundle: GeminiBundle): Promise { @@ -20,7 +20,8 @@ export async function writeGeminiBundle(outputRoot: string, bundle: GeminiBundle if (bundle.commands.length > 0) { for (const command of bundle.commands) { - await writeText(path.join(paths.commandsDir, `${command.name}.toml`), command.content + "\n") + const dest = await resolveCommandPath(paths.commandsDir, command.name, ".toml") + await writeText(dest, command.content + "\n") } } diff --git a/src/targets/opencode.ts b/src/targets/opencode.ts index b4bf53e7..cff2931a 100644 --- a/src/targets/opencode.ts +++ b/src/targets/opencode.ts @@ -1,5 +1,5 @@ import path from "path" -import { backupFile, copyDir, ensureDir, pathExists, readJson, writeJson, writeText } from "../utils/files" +import { backupFile, copyDir, ensureDir, pathExists, readJson, resolveCommandPath, writeJson, writeText } from "../utils/files" import type { OpenCodeBundle, OpenCodeConfig } from "../types/opencode" // Merges plugin config into existing opencode.json. User keys win on conflict. See ADR-002. @@ -75,7 +75,7 @@ export async function writeOpenCodeBundle(outputRoot: string, bundle: OpenCodeBu } for (const commandFile of bundle.commandFiles) { - const dest = path.join(openCodePaths.commandDir, `${commandFile.name}.md`) + const dest = await resolveCommandPath(openCodePaths.commandDir, commandFile.name, ".md") const cmdBackupPath = await backupFile(dest) if (cmdBackupPath) { console.log(`Backed up existing command file to ${cmdBackupPath}`) diff --git a/src/targets/qwen.ts b/src/targets/qwen.ts index a8228574..22fe2966 100644 --- a/src/targets/qwen.ts +++ b/src/targets/qwen.ts @@ -1,5 +1,5 @@ import path from "path" -import { backupFile, copyDir, ensureDir, writeJson, writeText } from "../utils/files" +import { backupFile, copyDir, ensureDir, resolveCommandPath, writeJson, writeText } from "../utils/files" import type { QwenBundle, QwenExtensionConfig } from "../types/qwen" export async function writeQwenBundle(outputRoot: string, bundle: QwenBundle): Promise { @@ -31,15 +31,8 @@ export async function writeQwenBundle(outputRoot: string, bundle: QwenBundle): P const commandsDir = qwenPaths.commandsDir await ensureDir(commandsDir) for (const commandFile of bundle.commandFiles) { - // Support nested commands with colon separator - const parts = commandFile.name.split(":") - if (parts.length > 1) { - const nestedDir = path.join(commandsDir, ...parts.slice(0, -1)) - await ensureDir(nestedDir) - await writeText(path.join(nestedDir, `${parts[parts.length - 1]}.md`), commandFile.content + "\n") - } else { - await writeText(path.join(commandsDir, `${commandFile.name}.md`), commandFile.content + "\n") - } + const dest = await resolveCommandPath(commandsDir, commandFile.name, ".md") + await writeText(dest, commandFile.content + "\n") } // Copy skills diff --git a/src/utils/files.ts b/src/utils/files.ts index e4a2a4ab..8ca608ae 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -75,6 +75,21 @@ export async function walkFiles(root: string): Promise { return results } +/** + * Resolve a colon-separated command name into a filesystem path. + * e.g. resolveCommandPath("/commands", "ce:plan", ".md") -> "/commands/ce/plan.md" + * Creates intermediate directories as needed. + */ +export async function resolveCommandPath(dir: string, name: string, ext: string): Promise { + const parts = name.split(":") + if (parts.length > 1) { + const nestedDir = path.join(dir, ...parts.slice(0, -1)) + await ensureDir(nestedDir) + return path.join(nestedDir, `${parts[parts.length - 1]}${ext}`) + } + return path.join(dir, `${name}${ext}`) +} + export async function copyDir(sourceDir: string, targetDir: string): Promise { await ensureDir(targetDir) const entries = await fs.readdir(sourceDir, { withFileTypes: true })