fix(acp): include external directory permission context (#30567)

This commit is contained in:
Shoubhit Dash
2026-06-03 19:05:28 +05:30
committed by GitHub
parent fc62b3dc48
commit e707e416ed
5 changed files with 79 additions and 8 deletions

View File

@@ -78,6 +78,9 @@ export function toLocations(toolName: string, input: ToolInput): ToolCallLocatio
case "write":
return locationFrom(input.filePath ?? input.filepath)
case "external_directory":
return locationFrom(input.filePath ?? input.filepath, input.parentDir, input.directories)
case "grep":
case "glob":
case "context":
@@ -255,9 +258,19 @@ export const buildDuplicateRunningToolUpdate = duplicateRunningToolUpdate
export const buildCompletedToolUpdate = completedToolUpdate
export const buildErrorToolUpdate = errorToolUpdate
function locationFrom(value: unknown): ToolCallLocation[] {
const path = stringValue(value)
return path ? [{ path }] : []
function locationFrom(...values: unknown[]): ToolCallLocation[] {
return Array.from(
new Set(
values.flatMap((value): string[] => {
if (Array.isArray(value)) {
return value.filter((item): item is string => typeof item === "string" && item.length > 0)
}
const path = stringValue(value)
return path ? [path] : []
}),
),
(path) => ({ path }),
)
}
function diffContent(input: ToolInput): ToolCallContent[] {

View File

@@ -263,9 +263,14 @@ const parse = Effect.fn("ShellTool.parse")(function* (command: string, ps: boole
return tree
})
const ask = Effect.fn("ShellTool.ask")(function* (ctx: Tool.Context, scan: Scan) {
const ask = Effect.fn("ShellTool.ask")(function* (
ctx: Tool.Context,
scan: Scan,
input: { command: string; description: string },
) {
if (scan.dirs.size > 0) {
const globs = Array.from(scan.dirs).map((dir) => {
const directories = Array.from(scan.dirs)
const globs = directories.map((dir) => {
if (process.platform === "win32") return FSUtil.normalizePathPattern(path.join(dir, "*"))
return path.join(dir, "*")
})
@@ -273,7 +278,12 @@ const ask = Effect.fn("ShellTool.ask")(function* (ctx: Tool.Context, scan: Scan)
permission: "external_directory",
patterns: globs,
always: globs,
metadata: {},
metadata: {
command: input.command,
description: input.description,
directories,
patterns: globs,
},
})
}
@@ -282,7 +292,10 @@ const ask = Effect.fn("ShellTool.ask")(function* (ctx: Tool.Context, scan: Scan)
permission: ShellID.ToolID,
patterns: Array.from(scan.patterns),
always: Array.from(scan.always),
metadata: {},
metadata: {
command: input.command,
description: input.description,
},
})
})
@@ -625,7 +638,7 @@ export const ShellTool = Tool.define(
)
const scan = yield* collect(tree.rootNode, cwd, ps, shell, instanceCtx)
if (!containsPath(cwd, instanceCtx)) scan.dirs.add(cwd)
yield* ask(ctx, scan)
yield* ask(ctx, scan, params)
}),
)