settingsMigrations top-level property
All settings migrations in order.
Implementation
final settingsMigrations = <Migration>[
// v1 → v2: Flatten permission rules, add sandbox settings
Migration(
fromVersion: 1,
toVersion: 2,
description: 'Flatten permission rules, add sandbox config',
migrate: (data) async {
final result = Map<String, dynamic>.from(data);
// Move nested permissions to flat structure
if (result.containsKey('permissions')) {
final perms = result['permissions'];
if (perms is Map && perms.containsKey('rules')) {
result['permissionRules'] = perms['rules'];
result['permissionMode'] = perms['mode'] ?? 'default';
}
}
// Add default sandbox settings
result.putIfAbsent(
'sandbox',
() => {
'enabled': false,
'writePaths': <String>['.'],
'readPaths': <String>['/'],
},
);
result['configVersion'] = 2;
return result;
},
),
// v2 → v3: Add model overrides, MCP server configs
Migration(
fromVersion: 2,
toVersion: 3,
description: 'Add model overrides, MCP server configs',
migrate: (data) async {
final result = Map<String, dynamic>.from(data);
result.putIfAbsent('modelOverrides', () => <String, dynamic>{});
result.putIfAbsent('mcpServers', () => <String, dynamic>{});
result.putIfAbsent('hooks', () => <String, dynamic>{});
// Migrate old model names
if (result['model'] is String) {
result['model'] = _remapModelName(result['model'] as String);
}
result['configVersion'] = 3;
return result;
},
),
];