phase 03: write command md files

This commit is contained in:
Adrian
2026-02-20 13:28:25 -05:00
parent f0b6ce9689
commit 5abddbcbd9
4 changed files with 174 additions and 9 deletions

View File

@@ -3,29 +3,38 @@ import { backupFile, copyDir, ensureDir, writeJson, writeText } from "../utils/f
import type { OpenCodeBundle } from "../types/opencode"
export async function writeOpenCodeBundle(outputRoot: string, bundle: OpenCodeBundle): Promise<void> {
const paths = resolveOpenCodePaths(outputRoot)
await ensureDir(paths.root)
const openCodePaths = resolveOpenCodePaths(outputRoot)
await ensureDir(openCodePaths.root)
const backupPath = await backupFile(paths.configPath)
const backupPath = await backupFile(openCodePaths.configPath)
if (backupPath) {
console.log(`Backed up existing config to ${backupPath}`)
}
await writeJson(paths.configPath, bundle.config)
await writeJson(openCodePaths.configPath, bundle.config)
const agentsDir = paths.agentsDir
const agentsDir = openCodePaths.agentsDir
for (const agent of bundle.agents) {
await writeText(path.join(agentsDir, `${agent.name}.md`), agent.content + "\n")
}
for (const commandFile of bundle.commandFiles) {
const dest = path.join(openCodePaths.commandDir, `${commandFile.name}.md`)
const cmdBackupPath = await backupFile(dest)
if (cmdBackupPath) {
console.log(`Backed up existing command file to ${cmdBackupPath}`)
}
await writeText(dest, commandFile.content + "\n")
}
if (bundle.plugins.length > 0) {
const pluginsDir = paths.pluginsDir
const pluginsDir = openCodePaths.pluginsDir
for (const plugin of bundle.plugins) {
await writeText(path.join(pluginsDir, plugin.name), plugin.content + "\n")
}
}
if (bundle.skillDirs.length > 0) {
const skillsRoot = paths.skillsDir
const skillsRoot = openCodePaths.skillsDir
for (const skill of bundle.skillDirs) {
await copyDir(skill.sourceDir, path.join(skillsRoot, skill.name))
}
@@ -43,6 +52,8 @@ function resolveOpenCodePaths(outputRoot: string) {
agentsDir: path.join(outputRoot, "agents"),
pluginsDir: path.join(outputRoot, "plugins"),
skillsDir: path.join(outputRoot, "skills"),
// .md command files; alternative to the command key in opencode.json
commandDir: path.join(outputRoot, "commands"),
}
}
@@ -53,5 +64,7 @@ function resolveOpenCodePaths(outputRoot: string) {
agentsDir: path.join(outputRoot, ".opencode", "agents"),
pluginsDir: path.join(outputRoot, ".opencode", "plugins"),
skillsDir: path.join(outputRoot, ".opencode", "skills"),
// .md command files; alternative to the command key in opencode.json
commandDir: path.join(outputRoot, ".opencode", "commands"),
}
}
}