Skip to content

Commit 3217c24

Browse files
committed
feat: increase base permissions for agents
1 parent d5b25f7 commit 3217c24

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

packages/agent/src/adapters/claude/permission-handlers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
} from "@agentclientprotocol/sdk";
55
import type { PermissionUpdate } from "@anthropic-ai/claude-agent-sdk";
66
import type { Logger } from "@/utils/logger.js";
7+
import { isToolAllowedForMode } from "./permission-mode-config.js";
78
import { buildPermissionOptions, isWriteTool } from "./permission-options.js";
89
import {
910
getClaudePlansDir,
@@ -421,7 +422,14 @@ function handlePlanFileException(
421422
export async function evaluateToolPermission(
422423
context: ToolHandlerContext,
423424
): Promise<ToolPermissionResult> {
424-
const { toolName } = context;
425+
const { toolName, toolInput, session } = context;
426+
427+
if (isToolAllowedForMode(toolName, session.permissionMode)) {
428+
return {
429+
behavior: "allow",
430+
updatedInput: toolInput as Record<string, unknown>,
431+
};
432+
}
425433

426434
if (toolName === "ExitPlanMode") {
427435
return handleExitPlanModeTool(context);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { PermissionMode } from "@anthropic-ai/claude-agent-sdk";
2+
3+
// TODO: Use TwigToolKind here instead.
4+
const BASE_ALLOWED_TOOLS = new Set([
5+
"TodoWrite",
6+
"Glob",
7+
"Grep",
8+
"Read",
9+
"LS",
10+
"WebSearch",
11+
"WebFetch",
12+
"Task",
13+
]);
14+
15+
// TODO: Key this with our own TwigMode type instead of reusing an agents PermissionMode
16+
const MODE_ALLOWED_TOOLS: Record<PermissionMode, Set<string>> = {
17+
default: new Set(),
18+
acceptEdits: new Set(["Edit", "Write", "NotebookEdit"]),
19+
plan: new Set(),
20+
bypassPermissions: new Set(),
21+
delegate: new Set(),
22+
dontAsk: new Set(),
23+
};
24+
25+
export function isToolAllowedForMode(
26+
toolName: string,
27+
mode: PermissionMode,
28+
): boolean {
29+
if (BASE_ALLOWED_TOOLS.has(toolName)) {
30+
return true;
31+
}
32+
if (mode === "bypassPermissions") {
33+
return true;
34+
}
35+
return MODE_ALLOWED_TOOLS[mode]?.has(toolName) ?? false;
36+
}

0 commit comments

Comments
 (0)