From 2f1ede072fef5f39bbd464e880c5886ed272b527 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 31 Dec 2025 12:41:22 +0900 Subject: [PATCH] refactor(index): use migration module from shared MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes inline migration logic from index.ts and imports from shared/migration module. This completes the refactoring to extract testable migration logic into a dedicated module. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/index.ts | 94 +--------------------------------------------------- 1 file changed, 1 insertion(+), 93 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9fa97ad..fb2cff3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,103 +61,11 @@ import { builtinTools, createCallOmoAgent, createBackgroundTools, createLookAt, import { BackgroundManager } from "./features/background-agent"; import { createBuiltinMcps } from "./mcp"; import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig, type HookName } from "./config"; -import { log, deepMerge, getUserConfigDir, addConfigLoadError, parseJsonc, detectConfigFile } from "./shared"; +import { log, deepMerge, getUserConfigDir, addConfigLoadError, parseJsonc, detectConfigFile, migrateConfigFile } from "./shared"; import { PLAN_SYSTEM_PROMPT, PLAN_PERMISSION } from "./agents/plan-prompt"; import * as fs from "fs"; import * as path from "path"; -// Migration map: old keys → new keys (for backward compatibility) -const AGENT_NAME_MAP: Record = { - // Legacy names (backward compatibility) - omo: "Sisyphus", - "OmO": "Sisyphus", - "OmO-Plan": "Planner-Sisyphus", - "omo-plan": "Planner-Sisyphus", - // Current names - sisyphus: "Sisyphus", - "planner-sisyphus": "Planner-Sisyphus", - build: "build", - oracle: "oracle", - librarian: "librarian", - explore: "explore", - "frontend-ui-ux-engineer": "frontend-ui-ux-engineer", - "document-writer": "document-writer", - "multimodal-looker": "multimodal-looker", -}; - -// Migration map: old hook names → new hook names (for backward compatibility) -const HOOK_NAME_MAP: Record = { - // Legacy names (backward compatibility) - "anthropic-auto-compact": "anthropic-context-window-limit-recovery", -}; - -function migrateAgentNames(agents: Record): { migrated: Record; changed: boolean } { - const migrated: Record = {}; - let changed = false; - - for (const [key, value] of Object.entries(agents)) { - const newKey = AGENT_NAME_MAP[key.toLowerCase()] ?? AGENT_NAME_MAP[key] ?? key; - if (newKey !== key) { - changed = true; - } - migrated[newKey] = value; - } - - return { migrated, changed }; -} - -function migrateHookNames(hooks: string[]): { migrated: string[]; changed: boolean } { - const migrated: string[] = []; - let changed = false; - - for (const hook of hooks) { - const newHook = HOOK_NAME_MAP[hook] ?? hook; - if (newHook !== hook) { - changed = true; - } - migrated.push(newHook); - } - - return { migrated, changed }; -} - -function migrateConfigFile(configPath: string, rawConfig: Record): boolean { - let needsWrite = false; - - if (rawConfig.agents && typeof rawConfig.agents === "object") { - const { migrated, changed } = migrateAgentNames(rawConfig.agents as Record); - if (changed) { - rawConfig.agents = migrated; - needsWrite = true; - } - } - - if (rawConfig.omo_agent) { - rawConfig.sisyphus_agent = rawConfig.omo_agent; - delete rawConfig.omo_agent; - needsWrite = true; - } - - if (rawConfig.disabled_hooks && Array.isArray(rawConfig.disabled_hooks)) { - const { migrated, changed } = migrateHookNames(rawConfig.disabled_hooks as string[]); - if (changed) { - rawConfig.disabled_hooks = migrated; - needsWrite = true; - } - } - - if (needsWrite) { - try { - fs.writeFileSync(configPath, JSON.stringify(rawConfig, null, 2) + "\n", "utf-8"); - log(`Migrated config file: ${configPath}`); - } catch (err) { - log(`Failed to write migrated config to ${configPath}:`, err); - } - } - - return needsWrite; -} - function loadConfigFromPath(configPath: string, ctx: any): OhMyOpenCodeConfig | null { try { if (fs.existsSync(configPath)) {