Skip to content

Commit c47b116

Browse files
committed
feat: when defaultMode is set to allowAll, "unknown" scope permissions should be allowed by default.
1 parent bac4937 commit c47b116

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

packages/core/src/common/permissions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export function evaluatePermissionScopes(
273273
defaultMode: "allowAll",
274274
}
275275
): PermissionDecision {
276-
if (scopes.includes("unknown")) {
276+
if (scopes.includes("unknown") && settings.defaultMode !== "allowAll") {
277277
return "ask";
278278
}
279279
if (scopes.length === 0) {
@@ -304,7 +304,9 @@ export function getPermissionScopesRequiringAsk(
304304
const result: AskPermissionScope[] = [];
305305
for (const scope of scopes) {
306306
if (scope === "unknown") {
307-
result.push(scope);
307+
if (settings.defaultMode !== "allowAll") {
308+
result.push(scope);
309+
}
308310
continue;
309311
}
310312
if (settings.deny.includes(scope)) {

packages/core/src/tests/permissions.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
appendProjectPermissionAllows,
88
computeToolCallPermissions,
99
evaluatePermissionScopes,
10+
getPermissionScopesRequiringAsk,
1011
hasUserPermissionReplies,
1112
isPathInAnyDirectory,
1213
parseBashSideEffects,
@@ -46,6 +47,47 @@ test("evaluatePermissionScopes applies deny, ask, allow, and default mode preced
4647
assert.equal(evaluatePermissionScopes(["unknown"], settings), "ask");
4748
});
4849

50+
test("evaluatePermissionScopes allows unknown when defaultMode is allowAll", () => {
51+
const allowAllSettings = {
52+
allow: [] as const,
53+
deny: [] as const,
54+
ask: [] as const,
55+
defaultMode: "allowAll" as const,
56+
};
57+
assert.equal(evaluatePermissionScopes(["unknown"], allowAllSettings), "allow");
58+
59+
// unknown + other scopes that would otherwise trigger ask should still ask for those scopes
60+
const askNetworkSettings = {
61+
allow: [] as const,
62+
deny: [] as const,
63+
ask: ["network" as const],
64+
defaultMode: "allowAll" as const,
65+
};
66+
assert.equal(evaluatePermissionScopes(["unknown", "network"], askNetworkSettings), "ask");
67+
});
68+
69+
test("getPermissionScopesRequiringAsk excludes unknown when defaultMode is allowAll", () => {
70+
const allowAllSettings = {
71+
allow: [] as const,
72+
deny: [] as const,
73+
ask: ["network" as const],
74+
defaultMode: "allowAll" as const,
75+
};
76+
const result = getPermissionScopesRequiringAsk(["unknown", "network"], allowAllSettings);
77+
assert.deepEqual(result, ["network"]);
78+
});
79+
80+
test("getPermissionScopesRequiringAsk includes unknown when defaultMode is askAll", () => {
81+
const askAllSettings = {
82+
allow: [] as const,
83+
deny: [] as const,
84+
ask: ["network" as const],
85+
defaultMode: "askAll" as const,
86+
};
87+
const result = getPermissionScopesRequiringAsk(["unknown", "network"], askAllSettings);
88+
assert.deepEqual(result, ["unknown", "network"]);
89+
});
90+
4991
test("computeToolCallPermissions maps tool calls to permission requests", () => {
5092
const projectRoot = createTempDir("deepcode-permissions-workspace-");
5193
const plan = computeToolCallPermissions({

0 commit comments

Comments
 (0)