Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 57 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export type CommitConfig = {

export type ProviderConfig = Partial<Omit<Provider, 'createModel'>>;

export type ReasoningLevel = 'disabled' | 'low' | 'medium' | 'high';
export type CompletionSound =
| 'off'
| 'terminal-bell'
| 'fx-ok01'
| 'fx-ack01'
| 'custom';
export type PlaySoundsTiming = 'always' | 'when-focused' | 'when-unfocused';
export type DiffDisplayMode = 'github' | 'unified';
export type Theme = 'dark' | 'light';

export type Config = {
model: string;
planModel: string;
Expand All @@ -63,6 +74,14 @@ export type Config = {
autoUpdate?: boolean;
browser?: boolean;
temperature?: number;
reasoningLevel?: ReasoningLevel;
completionSound?: CompletionSound;
playSounds?: PlaySoundsTiming;
showTips?: boolean;
diffDisplayMode?: DiffDisplayMode;
respectGitignore?: boolean;
theme?: Theme;
autoConnectIDE?: boolean;
};

const DEFAULT_CONFIG: Partial<Config> = {
Expand All @@ -77,6 +96,14 @@ const DEFAULT_CONFIG: Partial<Config> = {
outputFormat: 'text',
autoUpdate: true,
browser: false,
reasoningLevel: 'disabled',
completionSound: 'off',
playSounds: 'always',
showTips: true,
diffDisplayMode: 'unified',
respectGitignore: true,
theme: 'dark',
autoConnectIDE: false,
};
const VALID_CONFIG_KEYS = [
...Object.keys(DEFAULT_CONFIG),
Expand All @@ -92,6 +119,14 @@ const VALID_CONFIG_KEYS = [
'provider',
'browser',
'temperature',
'reasoningLevel',
'completionSound',
'playSounds',
'showTips',
'diffDisplayMode',
'respectGitignore',
'theme',
'autoConnectIDE',
];
const ARRAY_CONFIG_KEYS = ['plugins'];
const OBJECT_CONFIG_KEYS = ['mcpServers', 'commit', 'provider'];
Expand All @@ -101,7 +136,19 @@ const BOOLEAN_CONFIG_KEYS = [
'autoCompact',
'autoUpdate',
'browser',
'showTips',
'respectGitignore',
'autoConnectIDE',
];
const ENUM_CONFIG_KEYS = {
approvalMode: ['default', 'autoEdit', 'yolo'],
reasoningLevel: ['disabled', 'low', 'medium', 'high'],
completionSound: ['off', 'terminal-bell', 'fx-ok01', 'fx-ack01', 'custom'],
playSounds: ['always', 'when-focused', 'when-unfocused'],
diffDisplayMode: ['github', 'unified'],
theme: ['dark', 'light'],
outputFormat: ['text', 'stream-json', 'json'],
} as const;

export class ConfigManager {
globalConfig: Partial<Config>;
Expand Down Expand Up @@ -317,6 +364,16 @@ export class ConfigManager {
if (OBJECT_CONFIG_KEYS.includes(key)) {
newValue = JSON.parse(value);
}
// Validate enum values
if (key in ENUM_CONFIG_KEYS) {
const validValues =
ENUM_CONFIG_KEYS[key as keyof typeof ENUM_CONFIG_KEYS];
if (!validValues.includes(newValue as never)) {
throw new Error(
`Invalid value "${newValue}" for config key "${key}". Valid values are: ${validValues.join(', ')}`,
);
}
}
(config[key as keyof Config] as any) = newValue;
}

Expand Down
2 changes: 2 additions & 0 deletions src/slash-commands/builtin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createModelCommand } from './model';
import { createOutputStyleCommand } from './output-style';
import { createResumeCommand } from './resume';
import { createReviewCommand } from './review';
import { createSettingCommand } from './setting';
import { brainstormCommand } from './spec/brainstorm';
import { executePlanCommand } from './spec/execute-plan';
import { saveDesignCommand } from './spec/save-design';
Expand All @@ -36,6 +37,7 @@ export function createBuiltinCommands(opts: {
createOutputStyleCommand(),
createResumeCommand(),
createReviewCommand(opts.language),
createSettingCommand(),
createTerminalSetupCommand(),
createBugCommand(),
compactCommand,
Expand Down
Loading