Skip to content

Commit a0ca788

Browse files
committed
fix: pass custom instructions to agent when rejecting tool permissions
1 parent 663966a commit a0ca788

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

apps/code/src/renderer/components/action-selector/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
import type { PermissionOption } from "@agentclientprotocol/sdk";
2+
13
export const OTHER_OPTION_ID = "_other";
24
export const OTHER_OPTION_ID_ALT = "other";
35
export const SUBMIT_OPTION_ID = "_submit";
46
export const CANCEL_OPTION_ID = "cancel";
57
export const OPTION_ID_PREFIX = "option_";
8+
export const REJECT_OPTION_ID = "reject";
9+
10+
export function isRejectWithInstructionOption(
11+
permissionOption: PermissionOption,
12+
): boolean {
13+
return (
14+
permissionOption.optionId === REJECT_OPTION_ID &&
15+
permissionOption._meta?.customInput === true
16+
);
17+
}
618

719
export function isOtherOption(optionId: string): boolean {
820
return optionId === OTHER_OPTION_ID || optionId === OTHER_OPTION_ID_ALT;

apps/code/src/renderer/features/sessions/components/SessionView.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { isOtherOption } from "@components/action-selector/constants";
1+
import {
2+
isOtherOption,
3+
isRejectWithInstructionOption,
4+
} from "@components/action-selector/constants";
25
import { PermissionSelector } from "@components/permissions/PermissionSelector";
36
import {
47
MessageEditor,
@@ -252,7 +255,10 @@ export function SessionView({
252255
}
253256

254257
if (customInput) {
255-
if (isOtherOption(optionId)) {
258+
if (
259+
isOtherOption(optionId) ||
260+
(selectedOption && isRejectWithInstructionOption(selectedOption))
261+
) {
256262
await getSessionService().respondToPermission(
257263
taskId,
258264
firstPendingPermission.toolCallId,

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,14 @@ async function handleDefaultPermissionFlow(
388388
updatedInput: toolInput as Record<string, unknown>,
389389
};
390390
} else {
391-
const message = "User refused permission to run tool";
391+
const feedback = (
392+
response._meta?.customInput as string | undefined
393+
)?.trim();
394+
const message = feedback
395+
? `User refused permission to run tool with feedback: ${feedback}`
396+
: "User refused permission to run tool";
392397
await emitToolDenial(context, message);
393-
return {
394-
behavior: "deny",
395-
message,
396-
};
398+
return { behavior: "deny", message, interrupt: !feedback };
397399
}
398400
}
399401

0 commit comments

Comments
 (0)