feat(cli): integrate legacy config migration into write-omo-config

Update writeOmoConfig to detect and migrate legacy config files before
writing. Adds logic to handle oh-my-opencode.json -> oh-my-openagent.json
migration with proper path resolution and fallback handling.

🤖 Generated with assistance of OhMyOpenCode
This commit is contained in:
YeonGyu-Kim
2026-04-10 11:15:51 +09:00
parent 5000d1e37d
commit 87ddb9baf3
2 changed files with 32 additions and 3 deletions
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os"
import { join } from "node:path"
import { parseJsonc } from "../../shared/jsonc-parser"
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../shared/plugin-identity"
import type { InstallConfig } from "../types"
import { resetConfigContext } from "./config-context"
import { generateOmoConfig } from "./generate-omo-config"
@@ -35,7 +36,7 @@ describe("writeOmoConfig", () => {
beforeEach(() => {
testConfigDir = join(tmpdir(), `omo-write-config-${Date.now()}-${Math.random().toString(36).slice(2)}`)
testConfigPath = join(testConfigDir, "oh-my-opencode.json")
testConfigPath = join(testConfigDir, `${CONFIG_BASENAME}.json`)
mkdirSync(testConfigDir, { recursive: true })
process.env.OPENCODE_CONFIG_DIR = testConfigDir
@@ -78,4 +79,21 @@ describe("writeOmoConfig", () => {
expect(savedConfig).toHaveProperty(defaultKey)
}
})
it("migrates a legacy config file to the canonical basename before writing", () => {
// given
const legacyConfigPath = join(testConfigDir, `${LEGACY_CONFIG_BASENAME}.json`)
const canonicalConfigPath = join(testConfigDir, `${CONFIG_BASENAME}.json`)
writeFileSync(legacyConfigPath, JSON.stringify({ disabled_hooks: ["comment-checker"] }, null, 2) + "\n", "utf-8")
// when
const result = writeOmoConfig(installConfig)
// then
expect(result.success).toBe(true)
expect(result.configPath).toEndWith(canonicalConfigPath)
const savedConfig = parseJsonc<Record<string, unknown>>(readFileSync(canonicalConfigPath, "utf-8"))
expect(savedConfig.disabled_hooks).toEqual(["comment-checker"])
})
})
+13 -2
View File
@@ -1,5 +1,9 @@
import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs"
import { basename, dirname, extname, join } from "node:path"
import { parseJsonc } from "../../shared"
import { migrateLegacyConfigFile } from "../../shared/migrate-legacy-config-file"
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../shared/plugin-identity"
import type { ConfigMergeResult, InstallConfig } from "../types"
import { backupConfigFile } from "./backup-config"
import { getConfigDir, getOmoConfigPath } from "./config-context"
@@ -23,7 +27,14 @@ export function writeOmoConfig(installConfig: InstallConfig): ConfigMergeResult
}
}
const omoConfigPath = getOmoConfigPath()
const detectedConfigPath = getOmoConfigPath()
const canonicalConfigPath = join(dirname(detectedConfigPath), `${CONFIG_BASENAME}${extname(detectedConfigPath) || ".json"}`)
const shouldMigrateLegacyPath = basename(detectedConfigPath).startsWith(LEGACY_CONFIG_BASENAME)
const omoConfigPath = shouldMigrateLegacyPath
? ((migrateLegacyConfigFile(detectedConfigPath) || existsSync(canonicalConfigPath))
? canonicalConfigPath
: detectedConfigPath)
: detectedConfigPath
try {
const newConfig = generateOmoConfig(installConfig)
@@ -71,7 +82,7 @@ export function writeOmoConfig(installConfig: InstallConfig): ConfigMergeResult
return {
success: false,
configPath: omoConfigPath,
error: formatErrorWithSuggestion(err, "write oh-my-opencode config"),
error: formatErrorWithSuggestion(err, `write ${CONFIG_BASENAME} config`),
}
}
}