Skip to content
Merged
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
52 changes: 50 additions & 2 deletions packages/core/src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import { RipGrepTool, canUseRipgrep } from '../tools/ripGrep.js';
import { logRipgrepFallback } from '../telemetry/loggers.js';
import { RipgrepFallbackEvent } from '../telemetry/types.js';
import { ToolRegistry } from '../tools/tool-registry.js';
import { ACTIVATE_SKILL_TOOL_NAME } from '../tools/tool-names.js';
import {
ACTIVATE_SKILL_TOOL_NAME,
ENTER_PLAN_MODE_TOOL_NAME,
EXIT_PLAN_MODE_TOOL_NAME,
} from '../tools/tool-names.js';
import type { SkillDefinition } from '../skills/skillLoader.js';
import { DEFAULT_MODEL_CONFIGS } from './defaultModelConfigs.js';
import {
Expand Down Expand Up @@ -198,7 +202,7 @@ import { getCodeAssistServer } from '../code_assist/codeAssist.js';
import { getExperiments } from '../code_assist/experiments/experiments.js';
import type { CodeAssistServer } from '../code_assist/server.js';
import { ContextManager } from '../services/contextManager.js';
import { UserTierId } from 'src/code_assist/types.js';
import { UserTierId } from '../code_assist/types.js';

vi.mock('../core/baseLlmClient.js');
vi.mock('../core/tokenLimits.js', () => ({
Expand Down Expand Up @@ -2398,3 +2402,47 @@ describe('Plans Directory Initialization', () => {
expect(context.getDirectories()).not.toContain(plansDir);
});
});

describe('Config Dynamic Tool Exclusion', () => {
const baseParams: ConfigParameters = {
sessionId: 'test-session',
targetDir: '/tmp',
debugMode: false,
model: 'gemini-pro',
cwd: '/tmp',
};

it('should exclude ENTER_PLAN_MODE_TOOL_NAME when in Plan Mode', () => {
const config = new Config(baseParams);

vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true);
config.setApprovalMode(ApprovalMode.PLAN);

const excluded = config.getExcludeTools();

expect(excluded?.has(ENTER_PLAN_MODE_TOOL_NAME)).toBe(true);
expect(excluded?.has(EXIT_PLAN_MODE_TOOL_NAME)).toBe(false);
});

it('should exclude EXIT_PLAN_MODE_TOOL_NAME when in Default Mode', () => {
const config = new Config(baseParams);
vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true);
config.setApprovalMode(ApprovalMode.DEFAULT);

const excluded = config.getExcludeTools();

expect(excluded?.has(EXIT_PLAN_MODE_TOOL_NAME)).toBe(true);
expect(excluded?.has(ENTER_PLAN_MODE_TOOL_NAME)).toBe(false);
});

it('should exclude EXIT_PLAN_MODE_TOOL_NAME when in Auto-Edit Mode', () => {
const config = new Config(baseParams);
vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true);
config.setApprovalMode(ApprovalMode.AUTO_EDIT);

const excluded = config.getExcludeTools();

expect(excluded?.has(EXIT_PLAN_MODE_TOOL_NAME)).toBe(true);
expect(excluded?.has(ENTER_PLAN_MODE_TOOL_NAME)).toBe(false);
});
});
14 changes: 14 additions & 0 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {
import { PromptRegistry } from '../prompts/prompt-registry.js';
import { ResourceRegistry } from '../resources/resource-registry.js';
import { ToolRegistry } from '../tools/tool-registry.js';
import {
ENTER_PLAN_MODE_TOOL_NAME,
EXIT_PLAN_MODE_TOOL_NAME,
} from '../tools/tool-names.js';
import { LSTool } from '../tools/ls.js';
import { ReadFileTool } from '../tools/read-file.js';
import { GrepTool } from '../tools/grep.js';
Expand Down Expand Up @@ -1329,6 +1333,16 @@ export class Config {
excludeToolsSet.add(tool);
}
}

const mode = this.getApprovalMode();
if (mode === ApprovalMode.PLAN) {
excludeToolsSet.add(ENTER_PLAN_MODE_TOOL_NAME);
excludeToolsSet.delete(EXIT_PLAN_MODE_TOOL_NAME);
} else {
excludeToolsSet.add(EXIT_PLAN_MODE_TOOL_NAME);
excludeToolsSet.delete(ENTER_PLAN_MODE_TOOL_NAME);
}

return excludeToolsSet;
}

Expand Down
Loading
Loading