Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/cli/cli-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { run } from "./run"
import { getLocalVersion } from "./get-local-version"
import { doctor } from "./doctor"
import { refreshModelCapabilities } from "./refresh-model-capabilities"
import { updateModels } from "./update-models/update-models"
import { createMcpOAuthCommand } from "./mcp-oauth"
import type { InstallArgs } from "./types"
import type { RunOptions } from "./run"
import type { GetLocalVersionOptions } from "./get-local-version/types"
import type { DoctorOptions } from "./doctor"
import type { UpdateModelsOptions } from "./update-models/types"
import packageJson from "../../package.json" with { type: "json" }

const VERSION = packageJson.version
Expand Down Expand Up @@ -195,6 +197,38 @@ program
process.exit(exitCode)
})

program
.command("update-models")
.description("Update model mappings in oh-my-opencode config")
.option("-d, --directory <path>", "Working directory to read config from")
.option("--full", "Replace all model mappings with latest recommendations")
.option("--dry-run", "Preview changes without modifying config")
.option("--json", "Output as JSON")
.addHelpText("after", `
Examples:
$ bunx oh-my-opencode update-models # Preserve custom mappings
$ bunx oh-my-opencode update-models --dry-run # Preview changes
$ bunx oh-my-opencode update-models --full # Replace all mappings
$ bunx oh-my-opencode update-models --json # JSON output

Modes:
preserve-custom (default): Update only non-customized entries
full-replacement (--full): Replace all entries with latest defaults
`)
.action(async (options) => {
const updateModelsOptions: UpdateModelsOptions = {
directory: options.directory,
mode: options.full ? "full-replacement" : "preserve-custom",
dryRun: options.dryRun ?? false,
json: options.json ?? false,
}
const result = await updateModels(updateModelsOptions)
if (!result.success) {
console.error(result.message)
}
process.exit(result.success ? 0 : 1)
})

program
.command("version")
.description("Show version information")
Expand Down
16 changes: 10 additions & 6 deletions src/cli/config-manager/detect-current-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { detectConfigFormat } from "./opencode-config-format"
import { parseOpenCodeConfigFileWithError } from "./parse-opencode-config-file"
import { extractVersionFromPluginEntry } from "./version-compatibility"

function detectProvidersFromOmoConfig(): {
function detectProvidersFromOmoConfig(projectDir?: string): {
hasOpenAI: boolean
hasOpencodeZen: boolean
hasZaiCodingPlan: boolean
hasKimiForCoding: boolean
hasOpencodeGo: boolean
hasVercelAiGateway: boolean
} {
const omoConfigPath = getOmoConfigPath()
const omoConfigPath = projectDir
? `${projectDir}/.opencode/oh-my-openagent.json`
: getOmoConfigPath()
if (!existsSync(omoConfigPath)) {
return {
hasOpenAI: true,
Expand Down Expand Up @@ -70,7 +72,7 @@ function findOurPluginEntry(plugins: string[]): string | null {
return plugins.find(isOurPlugin) ?? null
}

export function detectCurrentConfig(): DetectedConfig {
export function detectCurrentConfig(directory?: string): DetectedConfig {
const result: DetectedConfig = {
isInstalled: false,
installedVersion: null,
Expand All @@ -86,7 +88,9 @@ export function detectCurrentConfig(): DetectedConfig {
hasVercelAiGateway: false,
}

const { format, path } = detectConfigFormat()
const { format, path } = directory
? detectConfigFormat(directory)
: detectConfigFormat()
if (format === "none") {
return result
}
Expand All @@ -112,7 +116,7 @@ export function detectCurrentConfig(): DetectedConfig {
const providers = openCodeConfig.provider as Record<string, unknown> | undefined
result.hasGemini = providers ? "google" in providers : false

const { hasOpenAI, hasOpencodeZen, hasZaiCodingPlan, hasKimiForCoding, hasOpencodeGo, hasVercelAiGateway } = detectProvidersFromOmoConfig()
const { hasOpenAI, hasOpencodeZen, hasZaiCodingPlan, hasKimiForCoding, hasOpencodeGo, hasVercelAiGateway } = detectProvidersFromOmoConfig(directory)
result.hasOpenAI = hasOpenAI
result.hasOpencodeZen = hasOpencodeZen
result.hasZaiCodingPlan = hasZaiCodingPlan
Expand All @@ -121,4 +125,4 @@ export function detectCurrentConfig(): DetectedConfig {
result.hasVercelAiGateway = hasVercelAiGateway

return result
}
}
18 changes: 16 additions & 2 deletions src/cli/config-manager/opencode-config-format.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { existsSync } from "node:fs"
import { join } from "path"
import { getConfigJson, getConfigJsonc } from "./config-context"

export type ConfigFormat = "json" | "jsonc" | "none"

export function detectConfigFormat(): { format: ConfigFormat; path: string } {
export function detectConfigFormat(directory?: string): { format: ConfigFormat; path: string } {
if (directory) {
const configJsonc = join(directory, "opencode.jsonc")
const configJson = join(directory, "opencode.json")

if (existsSync(configJsonc)) {
return { format: "jsonc", path: configJsonc }
}
if (existsSync(configJson)) {
return { format: "json", path: configJson }
}
return { format: "none", path: configJson }
}

const configJsonc = getConfigJsonc()
const configJson = getConfigJson()

Expand All @@ -14,4 +28,4 @@ export function detectConfigFormat(): { format: ConfigFormat; path: string } {
return { format: "json", path: configJson }
}
return { format: "none", path: configJson }
}
}
Loading
Loading