feat: separated efficient agent mode (lite mode) for small language models

This commit is contained in:
Xiaohan-Tian
2026-06-04 16:45:06 -07:00
parent a3a0f2f4ad
commit 5c5a07b839
18 changed files with 411 additions and 20 deletions
@@ -4,6 +4,7 @@ import { upgradeConfigToV1 } from './upgradeConfigToV1';
import { upgradeConfigToV2 } from './upgradeConfigToV2';
import { upgradeConfigToV3 } from './upgradeConfigToV3';
import { upgradeConfigToV4 } from './upgradeConfigToV4';
import { upgradeConfigToV5 } from './upgradeConfigToV5';
/**
* KGConfigUpgrader — Orchestrates app-level migrations (e.g., storage backend changes).
@@ -48,6 +49,10 @@ export class KGConfigUpgrader {
await upgradeConfigToV4();
break;
}
case 5: {
await upgradeConfigToV5();
break;
}
default: {
throw new Error(`No config upgrader found for version ${nextVersion}`);
}
@@ -0,0 +1,52 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
const getRawMock = vi.fn();
const saveRawMock = vi.fn();
vi.mock('../io/KGConfigStorage', () => ({
KGConfigStorage: {
getInstance: vi.fn(() => ({
getRaw: getRawMock,
saveRaw: saveRawMock,
})),
},
}));
import { upgradeConfigToV5 } from './upgradeConfigToV5';
describe('upgradeConfigToV5', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('defaults general.agent_mode to regular when the key is missing', async () => {
const config: Record<string, unknown> = {
general: {
llm_provider: 'openai',
},
};
getRawMock.mockResolvedValue(config);
await upgradeConfigToV5();
expect(config.general).toEqual({
llm_provider: 'openai',
agent_mode: 'regular',
});
expect(saveRawMock).toHaveBeenCalledWith('userConfig', config);
});
it('preserves an explicit general.agent_mode value', async () => {
const config: Record<string, unknown> = {
general: {
agent_mode: 'efficient',
},
};
getRawMock.mockResolvedValue(config);
await upgradeConfigToV5();
expect(saveRawMock).not.toHaveBeenCalled();
expect((config.general as Record<string, unknown>).agent_mode).toBe('efficient');
});
});
@@ -0,0 +1,30 @@
import { KGConfigStorage } from '../io/KGConfigStorage';
const CONFIG_KEY = 'userConfig';
export async function upgradeConfigToV5(): Promise<void> {
const storage = KGConfigStorage.getInstance();
const rawConfig = await storage.getRaw(CONFIG_KEY);
if (!rawConfig || typeof rawConfig !== 'object') {
return;
}
const config = rawConfig as Record<string, unknown>;
const general = config.general;
if (!general || typeof general !== 'object') {
config.general = {
agent_mode: 'regular',
};
await storage.saveRaw(CONFIG_KEY, config);
return;
}
const generalRecord = general as Record<string, unknown>;
if ('agent_mode' in generalRecord) {
return;
}
generalRecord.agent_mode = 'regular';
await storage.saveRaw(CONFIG_KEY, config);
}
+3
View File
@@ -1,6 +1,7 @@
import type { ChordGuideCustomConfig } from '../ChordGuideTypes';
import { KGConfigStorage } from '../io/KGConfigStorage';
import type { LanguageSetting } from '../../i18n/types';
import type { AgentMode } from '../../util/agentMode';
/**
* Application configuration interface
@@ -8,6 +9,7 @@ import type { LanguageSetting } from '../../i18n/types';
interface AppConfig {
general: {
language: LanguageSetting;
agent_mode: AgentMode;
llm_provider: 'local_browser' | 'openai' | 'gemini' | 'claude' | 'claude_openrouter' | 'openai_compatible';
persist_api_keys_non_localhost: boolean;
auto_compact_threshold_percent: 80 | 90 | 95;
@@ -208,6 +210,7 @@ export class ConfigManager {
this.defaultConfig = {
general: {
language: 'auto',
agent_mode: 'regular',
llm_provider: 'local_browser',
persist_api_keys_non_localhost: false,
auto_compact_threshold_percent: 90,