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
48 changes: 47 additions & 1 deletion extensions/cli/src/permissions/defaultPolicies.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { describe, expect, it } from "vitest";

import { getDefaultToolPolicies } from "./defaultPolicies.js";
import {
getDefaultToolPolicies,
PLAN_MODE_POLICIES,
} from "./defaultPolicies.js";
const DEFAULT_TOOL_POLICIES = getDefaultToolPolicies();

describe("defaultPolicies", () => {
Expand Down Expand Up @@ -63,3 +66,46 @@ describe("defaultPolicies", () => {
expect(catchAllIndex).toBe(DEFAULT_TOOL_POLICIES.length - 1);
});
});

describe("PLAN_MODE_POLICIES", () => {
it("should require confirmation for Bash in plan mode", () => {
const bashPolicy = PLAN_MODE_POLICIES.find((p) => p.tool === "Bash");
expect(bashPolicy).toEqual({ tool: "Bash", permission: "ask" });
});

it("should exclude write tools in plan mode", () => {
const writeTools = ["Write", "Edit", "MultiEdit"];
for (const tool of writeTools) {
const policy = PLAN_MODE_POLICIES.find((p) => p.tool === tool);
expect(policy).toEqual({ tool, permission: "exclude" });
}
});

it("should allow read-only tools in plan mode", () => {
const readOnlyTools = [
"Read",
"List",
"Search",
"Fetch",
"Exit",
"Diff",
"Checklist",
"CheckBackgroundJob",
"AskQuestion",
"ReportFailure",
"Skills",
"Status",
"UploadArtifact",
];

for (const tool of readOnlyTools) {
const policy = PLAN_MODE_POLICIES.find((p) => p.tool === tool);
expect(policy).toEqual({ tool, permission: "allow" });
}
});

it("should allow MCP tools with wildcard in plan mode", () => {
const catchAllPolicy = PLAN_MODE_POLICIES.find((p) => p.tool === "*");
expect(catchAllPolicy).toEqual({ tool: "*", permission: "allow" });
});
});
6 changes: 3 additions & 3 deletions extensions/cli/src/permissions/defaultPolicies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export function getDefaultToolPolicies(
return policies;
}

// Plan mode: Complete override - exclude all write operations, allow only reads and bash
// Plan mode: Complete override - exclude all write operations, require confirmation for bash, allow reads
export const PLAN_MODE_POLICIES: ToolPermissionPolicy[] = [
{ tool: "Edit", permission: "exclude" },
{ tool: "MultiEdit", permission: "exclude" },
{ tool: "Write", permission: "exclude" },

// TODO address bash read only concerns, maybe make permissions more granular
{ tool: "Bash", permission: "allow" },
// Require user confirmation for bash in plan mode (principle of least privilege)
{ tool: "Bash", permission: "ask" },
{ tool: "CheckBackgroundJob", permission: "allow" },
{ tool: "AskQuestion", permission: "allow" },
{ tool: "Checklist", permission: "allow" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("ToolPermissionService - Mode Functionality", () => {
policies.some((p) => p.tool === "Edit" && p.permission === "exclude"),
).toBe(true);
expect(
policies.some((p) => p.tool === "Bash" && p.permission === "allow"),
policies.some((p) => p.tool === "Bash" && p.permission === "ask"),
).toBe(true);

// Should have specific policies for read tools (allowed)
Expand Down Expand Up @@ -232,7 +232,7 @@ describe("ToolPermissionService - Mode Functionality", () => {
policies.some((p) => p.tool === "Edit" && p.permission === "exclude"),
).toBe(true);
expect(
policies.some((p) => p.tool === "Bash" && p.permission === "allow"),
policies.some((p) => p.tool === "Bash" && p.permission === "ask"),
).toBe(true);

// Read tools should be allowed
Expand Down
Loading