MCPcopy Index your code
hub / github.com/anomalyco/opencode / migrateTuiConfig

Function migrateTuiConfig

packages/opencode/src/config/tui-migrate.ts:29–68  ·  view source on GitHub ↗
(input: MigrateInput)

Source from the content-addressed store, hash-verified

27 * skips only locations where a tui.json already exists.
28 */
29export async function migrateTuiConfig(input: MigrateInput) {
30 const opencode = await opencodeFiles(input)
31 for (const file of opencode) {
32 const source = await Filesystem.readText(file).catch(() => undefined)
33 if (!source) continue
34 const errors: JsoncParseError[] = []
35 const data = parseJsonc(source, errors, { allowTrailingComma: true })
36 if (errors.length || !data || typeof data !== "object" || Array.isArray(data)) continue
37
38 const theme = decodeTheme("theme" in data ? data.theme : undefined)
39 const keybinds = decodeRecord("keybinds" in data ? data.keybinds : undefined)
40 const legacyTui = decodeRecord("tui" in data ? data.tui : undefined)
41 const extracted = {
42 theme: Option.getOrUndefined(theme),
43 keybinds: Option.getOrUndefined(keybinds),
44 tui: Option.getOrUndefined(legacyTui),
45 }
46 const tui = extracted.tui ? normalizeTui(extracted.tui) : undefined
47 if (extracted.theme === undefined && extracted.keybinds === undefined && !tui) continue
48
49 const target = path.join(path.dirname(file), "tui.json")
50 const targetExists = await Filesystem.exists(target)
51 if (targetExists) continue
52
53 const payload: Record<string, unknown> = {
54 $schema: TUI_SCHEMA_URL,
55 }
56 if (extracted.theme !== undefined) payload.theme = extracted.theme
57 if (extracted.keybinds !== undefined) payload.keybinds = extracted.keybinds
58 if (tui) Object.assign(payload, tui)
59
60 const wrote = await Filesystem.write(target, JSON.stringify(payload, null, 2))
61 .then(() => true)
62 .catch(() => false)
63 if (!wrote) continue
64
65 const stripped = await backupAndStripLegacy(file, source)
66 if (!stripped) continue
67 }
68}
69
70function normalizeTui(data: Record<string, unknown>):
71 | {

Callers 1

tui.tsFile · 0.90

Calls 5

opencodeFilesFunction · 0.85
normalizeTuiFunction · 0.85
backupAndStripLegacyFunction · 0.85
writeMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected