Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DEFAULT_SETTINGS } from '../defaultSettings';

import { writeShowMoreItemsInSelectMenus } from './showMoreItemsInSelectMenus';
import { writeThemes } from './themes';
import { writeSettingsTheme } from './settingsTheme';
import { writeContextLimit } from './contextLimit';
import { writeInputBoxBorder } from './inputBorderBox';
import { writeThinkerFormat } from './thinkerFormat';
Expand Down Expand Up @@ -212,6 +213,12 @@ const PATCH_DEFINITIONS = [
group: PatchGroup.MISC_CONFIGURABLE,
description: 'Your custom themes will be available via /theme',
},
{
id: 'settings-theme-schema',
name: 'Settings theme schema',
group: PatchGroup.MISC_CONFIGURABLE,
description: 'Allows custom theme IDs to persist in settings.json',
},
{
id: 'thinking-verbs',
name: 'Thinking verbs',
Expand Down Expand Up @@ -695,6 +702,15 @@ export const applyCustomization = async (
JSON.stringify(DEFAULT_SETTINGS.themes)
),
},
'settings-theme-schema': {
fn: c => writeSettingsTheme(c),
condition: !!(
config.settings.themes &&
config.settings.themes.length > 0 &&
JSON.stringify(config.settings.themes) !==
JSON.stringify(DEFAULT_SETTINGS.themes)
),
},
'thinking-verbs': {
fn: c => writeThinkingVerbs(c, config.settings.thinkingVerbs!.verbs),
condition: !!config.settings.thinkingVerbs,
Expand Down
29 changes: 29 additions & 0 deletions src/patches/settingsTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { globalReplace } from './index';

// CC validates the settings.json `theme` field against built-in enum + "custom:" prefix:
// theme:VAR.union([VAR.enum(THEMES),VAR.string().startsWith("custom:").transform(fn)])
// .optional().catch(void 0)
// Tweakcc custom themes have plain IDs (e.g. "winter") that fail both constraints,
// causing the persisted theme value to be silently reset on every CC startup.
// Widen the schema to accept any string so custom IDs round-trip through settings.json.
//
// CC 2.1.x diff:
// -theme:h.union([h.enum(k7$),h.string().startsWith("custom:").transform((q)=>q)]).optional().catch(void 0)
// +theme:h.string().optional().catch(void 0)
export const writeSettingsTheme = (file: string): string | null => {
const pattern =
/,theme:([$\w]+)\.union\(\[\1\.enum\([$\w$]+\),\1\.string\(\)\.startsWith\("[^"]*"\)\.transform\(\([^)]+\)=>[^)]+\)\]\)\.optional\(\)\.catch\(void 0\)/;

let patched = 0;
const newFile = globalReplace(file, pattern, (match, zodVar) => {
patched++;
return `,theme:${zodVar as string}.string().optional().catch(void 0)`;
});

if (patched === 0) {
console.error('patch: settingsTheme: failed to find theme schema pattern');
return null;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

return newFile;
};