refactor: auto-migrate legacy config in gateway
This commit is contained in:
@@ -204,6 +204,10 @@ vi.mock("../config/config.js", () => {
|
||||
CONFIG_PATH_CLAWDIS: resolveConfigPath(),
|
||||
STATE_DIR_CLAWDIS: path.dirname(resolveConfigPath()),
|
||||
isNixMode: false,
|
||||
migrateLegacyConfig: (raw: unknown) => ({
|
||||
config: raw as Record<string, unknown>,
|
||||
changes: [],
|
||||
}),
|
||||
loadConfig: () => ({
|
||||
agent: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
CONFIG_PATH_CLAWDIS,
|
||||
isNixMode,
|
||||
loadConfig,
|
||||
migrateLegacyConfig,
|
||||
parseConfigJson5,
|
||||
readConfigFileSnapshot,
|
||||
STATE_DIR_CLAWDIS,
|
||||
@@ -1322,6 +1323,31 @@ export async function startGatewayServer(
|
||||
port = 18789,
|
||||
opts: GatewayServerOptions = {},
|
||||
): Promise<GatewayServer> {
|
||||
const configSnapshot = await readConfigFileSnapshot();
|
||||
if (configSnapshot.legacyIssues.length > 0) {
|
||||
if (isNixMode) {
|
||||
throw new Error(
|
||||
"Legacy config entries detected while running in Nix mode. Update your Nix config to the latest schema and restart.",
|
||||
);
|
||||
}
|
||||
const { config: migrated, changes } = migrateLegacyConfig(
|
||||
configSnapshot.parsed,
|
||||
);
|
||||
if (!migrated) {
|
||||
throw new Error(
|
||||
"Legacy config entries detected but auto-migration failed. Run \"clawdis doctor\" to migrate.",
|
||||
);
|
||||
}
|
||||
await writeConfigFile(migrated);
|
||||
if (changes.length > 0) {
|
||||
log.info(
|
||||
`gateway: migrated legacy config entries:\n${changes
|
||||
.map((entry) => `- ${entry}`)
|
||||
.join("\n")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const cfgAtStart = loadConfig();
|
||||
const bindMode = opts.bind ?? cfgAtStart.gateway?.bind ?? "loopback";
|
||||
const bindHost = opts.host ?? resolveGatewayBindHost(bindMode);
|
||||
|
||||
Reference in New Issue
Block a user