fix(command-loader): preserve model field for opencode commands only

- Claude Code commands (user, project scope): sanitize model to undefined
- OpenCode commands (opencode, opencode-project scope): preserve model as-is

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-14 12:24:59 +09:00
parent 2292a61887
commit 0c8a500de4
3 changed files with 14 additions and 13 deletions

View File

@@ -34,12 +34,13 @@ $ARGUMENTS
const formattedDescription = `(${scope}) ${data.description || ""}` const formattedDescription = `(${scope}) ${data.description || ""}`
const isOpencodeSource = scope === "opencode" || scope === "opencode-project"
const definition: CommandDefinition = { const definition: CommandDefinition = {
name: commandName, name: commandName,
description: formattedDescription, description: formattedDescription,
template: wrappedTemplate, template: wrappedTemplate,
agent: data.agent, agent: data.agent,
model: sanitizeModelField(data.model), model: sanitizeModelField(data.model, isOpencodeSource ? "opencode" : "claude-code"),
subtask: data.subtask, subtask: data.subtask,
argumentHint: data["argument-hint"], argumentHint: data["argument-hint"],
} }

View File

@@ -1,13 +1,12 @@
/** type CommandSource = "claude-code" | "opencode"
* Sanitizes model field from frontmatter.
* Always returns undefined to let SDK use default model. export function sanitizeModelField(model: unknown, source: CommandSource = "claude-code"): string | undefined {
* if (source === "claude-code") {
* Claude Code and OpenCode use different model ID formats, return undefined
* so we ignore the model field and let OpenCode use its configured default. }
*
* @param _model - Raw model value from frontmatter (ignored) if (typeof model === "string" && model.trim().length > 0) {
* @returns Always undefined to inherit default model return model.trim()
*/ }
export function sanitizeModelField(_model: unknown): undefined {
return undefined return undefined
} }

View File

@@ -24,11 +24,12 @@ function discoverCommandsFromDir(commandsDir: string, scope: CommandScope): Comm
const content = readFileSync(commandPath, "utf-8") const content = readFileSync(commandPath, "utf-8")
const { data, body } = parseFrontmatter(content) const { data, body } = parseFrontmatter(content)
const isOpencodeSource = scope === "opencode" || scope === "opencode-project"
const metadata: CommandMetadata = { const metadata: CommandMetadata = {
name: commandName, name: commandName,
description: data.description || "", description: data.description || "",
argumentHint: data["argument-hint"], argumentHint: data["argument-hint"],
model: sanitizeModelField(data.model), model: sanitizeModelField(data.model, isOpencodeSource ? "opencode" : "claude-code"),
agent: data.agent, agent: data.agent,
subtask: Boolean(data.subtask), subtask: Boolean(data.subtask),
} }