Skip to content

Commit 8630375

Browse files
committed
fix: address tool policy review feedback
1 parent 457d28c commit 8630375

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/agents/pi-tools.policy.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ import {
2727
type SubagentSessionRole,
2828
} from "./subagent-capabilities.js";
2929
import { isToolAllowedByPolicies, isToolAllowedByPolicyName } from "./tool-policy-match.js";
30-
import { normalizeToolName } from "./tool-policy.js";
30+
import {
31+
mergeAlsoAllowPolicy,
32+
normalizeToolName,
33+
resolveToolProfilePolicy,
34+
} from "./tool-policy.js";
3135

3236
/**
3337
* Tools always denied for sub-agents regardless of depth.
@@ -426,12 +430,18 @@ export function resolveEffectiveToolPolicy(params: {
426430
const explicitProfileAlsoAllow =
427431
resolveExplicitProfileAlsoAllow(agentTools) ?? resolveExplicitProfileAlsoAllow(globalTools);
428432

429-
// Warn affected users about removed implicit grants (#47487).
433+
// Warn affected users about removed implicit grants (#47487), but only when
434+
// the active profile/explicit alsoAllow do not already grant those tools.
430435
if (profile) {
431436
const implicitGrants = detectImplicitProfileGrants({ globalTools, agentTools });
432437
if (implicitGrants) {
433-
const alreadyCovered = new Set(explicitProfileAlsoAllow ?? []);
434-
const uncovered = implicitGrants.filter((t) => !alreadyCovered.has(t));
438+
const profilePolicy = mergeAlsoAllowPolicy(
439+
resolveToolProfilePolicy(profile),
440+
explicitProfileAlsoAllow,
441+
);
442+
const uncovered = implicitGrants.filter(
443+
(toolName) => !isToolAllowedByPolicyName(toolName, profilePolicy),
444+
);
435445
if (uncovered.length > 0) {
436446
logWarn(
437447
`tools policy: profile "${profile}"${agentId ? ` (agent "${agentId}")` : ""} has ` +

src/media/local-roots.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,26 @@ describe("local media roots", () => {
154154
shouldContainPictures: false,
155155
},
156156
{
157-
name: "widens media roots again when messaging-profile agents explicitly enable filesystem tools",
157+
name: "does not widen media roots when messaging-profile agents only configure filesystem guards",
158158
stateDir: path.join("/tmp", "openclaw-messaging-fs-media-roots-state"),
159159
cfg: {
160160
tools: {
161161
profile: "messaging",
162162
fs: { workspaceOnly: false },
163163
},
164164
},
165+
shouldContainPictures: false,
166+
},
167+
{
168+
name: "widens media roots when messaging-profile agents explicitly allow reads",
169+
stateDir: path.join("/tmp", "openclaw-messaging-read-media-roots-state"),
170+
cfg: {
171+
tools: {
172+
profile: "messaging",
173+
alsoAllow: ["read"] as string[],
174+
fs: { workspaceOnly: false },
175+
},
176+
},
165177
shouldContainPictures: true,
166178
},
167179
] as const)("$name", ({ stateDir, cfg, shouldContainPictures }) => {

0 commit comments

Comments
 (0)