fix: allow bash in plan mode

This commit is contained in:
Nate 2025-08-15 14:02:21 -07:00
parent d4de89ea85
commit a3cd7de581
6 changed files with 20 additions and 18 deletions

View file

@ -15,12 +15,12 @@ The default mode that follows configured permission policies from `permissions.y
### `plan`
Planning mode that **completely overrides all user permissions** to enforce read-only access. This mode absolutely prevents any write operations, file modifications, or command execution, regardless of user configuration.
Planning mode that **completely overrides all user permissions** to enforce read-only access with command execution. This mode prevents file modifications but allows command execution for analysis, regardless of user configuration.
- **Command-line flag:** `--readonly` (for backward compatibility)
- **UI Indicator:** `[plan]` shown in blue
- **Current directory:** Hidden to save space and focus on analysis
- **Permission override:** **Absolute** - excludes all write tools (Write, Edit, Bash, etc.) and allows only read tools (Read, Grep, LS, etc.)
- **Permission override:** **Absolute** - excludes write tools (Write, Edit, etc.) and allows read tools (Read, Grep, LS, etc.) and Bash for command execution
- **User config ignored:** Any user `--allow` flags for write tools are overridden
### `auto`
@ -80,5 +80,5 @@ Modes are implemented through the permission system:
### Mode-Specific Behaviors
- **normal**: No mode policies applied, uses existing user configuration; shows current directory
- **plan**: **Absolute override** - excludes all write tools (Write, Edit, Bash), allows only read tools (Read, Grep, LS); hides current directory
- **plan**: **Absolute override** - excludes write tools (Write, Edit), allows read tools (Read, Grep, LS) and Bash; hides current directory
- **auto**: **Absolute override** - allows all tools with `*: allow` policy; hides current directory

View file

@ -27,7 +27,7 @@ describe('ToolPermissionService - Mode Functionality', () => {
// Should have specific policies for write tools (excluded)
expect(policies.some(p => p.tool === 'Write' && p.permission === 'exclude')).toBe(true);
expect(policies.some(p => p.tool === 'Edit' && p.permission === 'exclude')).toBe(true);
expect(policies.some(p => p.tool === 'Bash' && p.permission === 'exclude')).toBe(true);
expect(policies.some(p => p.tool === 'Bash' && p.permission === 'allow')).toBe(true);
// Should have specific policies for read tools (allowed)
expect(policies.some(p => p.tool === 'Read' && p.permission === 'allow')).toBe(true);
@ -187,7 +187,7 @@ describe('ToolPermissionService - Mode Functionality', () => {
// Mode policies should override user config - Write should be excluded despite being in allow list
expect(policies.some(p => p.tool === 'Write' && p.permission === 'exclude')).toBe(true);
expect(policies.some(p => p.tool === 'Edit' && p.permission === 'exclude')).toBe(true);
expect(policies.some(p => p.tool === 'Bash' && p.permission === 'exclude')).toBe(true);
expect(policies.some(p => p.tool === 'Bash' && p.permission === 'allow')).toBe(true);
// Read tools should be allowed
expect(policies.some(p => p.tool === 'Read' && p.permission === 'allow')).toBe(true);

View file

@ -40,7 +40,7 @@ describe('ToolPermissionService - Real Tool Permission Test', () => {
expect(result.permission).toBe('exclude');
});
it('should deny Bash tool in plan mode', () => {
it('should allow Bash tool in plan mode', () => {
const permissions = service.getPermissions();
const toolCall = {
name: 'Bash',
@ -49,7 +49,7 @@ describe('ToolPermissionService - Real Tool Permission Test', () => {
const result = checkToolPermission(toolCall, permissions);
console.log(`Bash permission check result:`, result);
expect(result.permission).toBe('exclude');
expect(result.permission).toBe('allow');
});
it('should allow Read tool in plan mode', () => {

View file

@ -111,9 +111,9 @@ describe("ToolPermissionService", () => {
// Should exclude write tools
expect(policies).toContainEqual({ tool: 'Write', permission: 'exclude' });
expect(policies).toContainEqual({ tool: 'Edit', permission: 'exclude' });
expect(policies).toContainEqual({ tool: 'Bash', permission: 'exclude' });
// Should allow read tools
// Should allow read tools and bash
expect(policies).toContainEqual({ tool: 'Bash', permission: 'allow' });
expect(policies).toContainEqual({ tool: 'Read', permission: 'allow' });
expect(policies).toContainEqual({ tool: 'Grep', permission: 'allow' });
expect(policies).toContainEqual({ tool: 'LS', permission: 'allow' });

View file

@ -36,15 +36,15 @@ export class ToolPermissionService extends BaseService<ToolPermissionServiceStat
private generateModePolicies(): ToolPermissionPolicy[] {
switch (this.currentState.currentMode) {
case "plan":
// Plan mode: Complete override - exclude all write operations, allow only reads
// Plan mode: Complete override - exclude all write operations, allow only reads and bash
return [
// Exclude all write tools with absolute priority
{ tool: "Write", permission: "exclude" },
{ tool: "Edit", permission: "exclude" },
{ tool: "MultiEdit", permission: "exclude" },
{ tool: "NotebookEdit", permission: "exclude" },
{ tool: "Bash", permission: "exclude" },
// Allow all read tools
// Allow all read tools and bash
{ tool: "Bash", permission: "allow" },
{ tool: "Read", permission: "allow" },
{ tool: "List", permission: "allow" },
{ tool: "Search", permission: "allow" },

View file

@ -25,7 +25,7 @@ describe('getAllTools - Tool Filtering', () => {
});
});
test('should exclude Bash tool in plan mode after service initialization', async () => {
test('should allow Bash tool in plan mode after service initialization', async () => {
// Initialize services in plan mode (simulating `cn -p`)
await initializeServices({
headless: true,
@ -39,12 +39,12 @@ describe('getAllTools - Tool Filtering', () => {
expect(serviceResult.state).toBe('ready');
expect(serviceResult.value?.currentMode).toBe('plan');
// Get available tools - this should exclude Bash in plan mode
// Get available tools - this should include Bash in plan mode
const tools = getAllTools();
const toolNames = tools.map(t => t.function.name);
// Bash should be excluded in plan mode
expect(toolNames).not.toContain('Bash');
// Bash should be allowed in plan mode
expect(toolNames).toContain('Bash');
// Read-only tools should still be available
expect(toolNames).toContain('Read');
@ -145,7 +145,7 @@ describe('getAllTools - Tool Filtering', () => {
headless: true,
toolPermissionOverrides: {
mode: 'plan',
allow: ['Write', 'Bash'] // These should be ignored in plan mode
allow: ['Write', 'Edit'] // These should be ignored in plan mode
}
});
@ -155,9 +155,11 @@ describe('getAllTools - Tool Filtering', () => {
// Plan mode should still exclude write tools despite --allow flags
// This tests that plan mode policies have absolute precedence
expect(toolNames).not.toContain('Write');
expect(toolNames).not.toContain('Bash');
expect(toolNames).not.toContain('Edit');
// Bash should be available in plan mode
expect(toolNames).toContain('Bash');
// Read-only tools should be available
expect(toolNames).toContain('Read');
expect(toolNames).toContain('List');