diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx
index 8539f8db6..b6286c157 100644
--- a/src/ui/TUIChat.tsx
+++ b/src/ui/TUIChat.tsx
@@ -262,6 +262,7 @@ interface ScreenContentProps {
requestId: string,
approved: boolean,
createPolicy?: boolean,
+ stopStream?: boolean,
) => void;
handleUserMessage: (message: string) => void;
isWaitingForResponse: boolean;
diff --git a/src/ui/__tests__/TUIChat.streamStopping.test.tsx b/src/ui/__tests__/TUIChat.streamStopping.test.tsx
index 96a9fff39..976b66b69 100644
--- a/src/ui/__tests__/TUIChat.streamStopping.test.tsx
+++ b/src/ui/__tests__/TUIChat.streamStopping.test.tsx
@@ -37,11 +37,12 @@ describe("TUIChat - Stream Stopping on Tool Rejection", () => {
await vi.advanceTimersByTimeAsync(50);
- // Verify that the tool was rejected
+ // Verify that the tool was rejected with stop stream
expect(handleResponse).toHaveBeenCalledWith(
"test-request-123",
false, // approved = false
- false // createPolicy = false
+ false, // createPolicy = false
+ true // stopStream = true
);
});
@@ -67,11 +68,12 @@ describe("TUIChat - Stream Stopping on Tool Rejection", () => {
await vi.advanceTimersByTimeAsync(50);
- // Verify rejection
+ // Verify rejection with stop stream
expect(handleResponse).toHaveBeenCalledWith(
"dangerous-request",
false, // rejected
- false
+ false, // createPolicy = false
+ true // stopStream = true
);
});
diff --git a/src/ui/__tests__/TUIChat.toolPermission.test.tsx b/src/ui/__tests__/TUIChat.toolPermission.test.tsx
index d90b8a2ec..55381cb6e 100644
--- a/src/ui/__tests__/TUIChat.toolPermission.test.tsx
+++ b/src/ui/__tests__/TUIChat.toolPermission.test.tsx
@@ -38,10 +38,12 @@ describe("TUIChat - Tool Permission Tests", () => {
expect(frame).toContain("Would you like to continue?");
expect(frame).toContain("Continue");
expect(frame).toContain("Continue + don't ask again");
- expect(frame).toContain("Cancel");
+ expect(frame).toContain("No, and tell Continue what to do differently");
expect(frame).toContain("(tab)");
expect(frame).toContain("(shift+tab)");
expect(frame).toContain("(esc)");
+ // Verify old Cancel option is not shown
+ expect(frame).not.toContain("Cancel");
});
it("handles keyboard shortcuts for permission approval and rejection", async () => {
@@ -69,6 +71,7 @@ describe("TUIChat - Tool Permission Tests", () => {
expect(handleResponse).toHaveBeenCalledWith(
"test-request-123",
true,
+ false,
false
);
});
@@ -97,7 +100,8 @@ describe("TUIChat - Tool Permission Tests", () => {
expect(handleResponse).toHaveBeenCalledWith(
"test-request-456",
false,
- false
+ false,
+ true
);
});
@@ -125,7 +129,8 @@ describe("TUIChat - Tool Permission Tests", () => {
expect(handleResponse).toHaveBeenCalledWith(
"test-request-789",
false,
- false
+ false,
+ true
);
});
@@ -156,6 +161,7 @@ describe("TUIChat - Tool Permission Tests", () => {
expect(handleResponse).toHaveBeenCalledWith(
"test-request-123",
true,
+ undefined,
undefined
);
});
@@ -185,7 +191,53 @@ describe("TUIChat - Tool Permission Tests", () => {
expect(handleResponse).toHaveBeenCalledWith(
"test-request-policy",
true,
- true
+ true,
+ false
+ );
+ });
+
+ it("shows the new 'No, and tell Continue what to do differently' option in the UI", async () => {
+ const handleResponse = vi.fn();
+
+ const { lastFrame } = render(
+
+ );
+
+ await vi.advanceTimersByTimeAsync(50);
+
+ // Verify the new option exists in the rendered output
+ const frame = lastFrame();
+ expect(frame).toContain("No, and tell Continue what to do differently");
+
+ // Verify all 3 options are present
+ expect(frame).toContain("Continue");
+ expect(frame).toContain("Continue + don't ask again");
+ expect(frame).toContain("No, and tell Continue what to do differently");
+ // Verify old Cancel option is not shown
+ expect(frame).not.toContain("Cancel");
+ });
+
+ it("can trigger the new stop stream option programmatically", () => {
+ const handleResponse = vi.fn();
+
+ // Test the function signature directly - this verifies that our interface supports the new parameter
+ handleResponse("test-request", false, undefined, true);
+
+ // Verify the handler was called with stopStream = true
+ expect(handleResponse).toHaveBeenCalledWith(
+ "test-request",
+ false, // approved = false
+ undefined, // createPolicy = undefined
+ true // stopStream = true
);
});
diff --git a/src/ui/components/ToolPermissionSelector.tsx b/src/ui/components/ToolPermissionSelector.tsx
index 1ab6c36bc..fed7c2203 100644
--- a/src/ui/components/ToolPermissionSelector.tsx
+++ b/src/ui/components/ToolPermissionSelector.tsx
@@ -12,6 +12,7 @@ interface PermissionOption {
color: string;
approved: boolean;
createPolicy?: boolean;
+ stopStream?: boolean;
}
interface ToolPermissionSelectorProps {
@@ -23,6 +24,7 @@ interface ToolPermissionSelectorProps {
requestId: string,
approved: boolean,
createPolicy?: boolean,
+ stopStream?: boolean,
) => void;
}
@@ -35,7 +37,13 @@ const PERMISSION_OPTIONS: PermissionOption[] = [
approved: true,
createPolicy: true,
},
- { id: "deny", name: "Cancel", color: "red", approved: false },
+ {
+ id: "deny_stop",
+ name: "No, and tell Continue what to do differently",
+ color: "yellow",
+ approved: false,
+ stopStream: true,
+ },
];
export const ToolPermissionSelector: React.FC = ({
@@ -54,25 +62,26 @@ export const ToolPermissionSelector: React.FC = ({
requestId,
selectedOption.approved,
selectedOption.createPolicy,
+ selectedOption.stopStream,
);
return;
}
// Tab to continue (approve)
if (key.tab && !key.shift) {
- onResponse(requestId, true, false);
+ onResponse(requestId, true, false, false);
return;
}
// Shift+Tab to continue with policy creation
if (key.tab && key.shift) {
- onResponse(requestId, true, true);
+ onResponse(requestId, true, true, false);
return;
}
- // Escape to reject (deny)
+ // Escape to reject with stop stream
if (key.escape) {
- onResponse(requestId, false, false);
+ onResponse(requestId, false, false, true);
return;
}
@@ -86,9 +95,9 @@ export const ToolPermissionSelector: React.FC = ({
// Also support y/n for quick responses
if (input === "y" || input === "Y") {
- onResponse(requestId, true, false);
+ onResponse(requestId, true, false, false);
} else if (input === "n" || input === "N") {
- onResponse(requestId, false, false);
+ onResponse(requestId, false, false, true);
}
});
@@ -121,7 +130,7 @@ export const ToolPermissionSelector: React.FC = ({
let shortcut = "";
if (option.id === "approve") shortcut = "(tab)";
else if (option.id === "approve_policy") shortcut = "(shift+tab)";
- else if (option.id === "deny") shortcut = "(esc)";
+ else if (option.id === "deny_stop") shortcut = "(esc)";
return (
diff --git a/src/ui/hooks/useChat.ts b/src/ui/hooks/useChat.ts
index ef965492f..fda1c8d1d 100644
--- a/src/ui/hooks/useChat.ts
+++ b/src/ui/hooks/useChat.ts
@@ -12,13 +12,13 @@ import { logger } from "../../util/logger.js";
import { DisplayMessage } from "../types.js";
import {
+ formatMessageWithFiles,
+ handleAutoCompaction,
handleCompactCommand,
+ handleSpecialCommands,
initChatHistory,
processSlashCommandResult,
trackUserMessage,
- handleAutoCompaction,
- formatMessageWithFiles,
- handleSpecialCommands,
} from "./useChat.helpers.js";
import {
handleRemoteMessage,
@@ -29,9 +29,9 @@ import {
executeStreaming,
} from "./useChat.stream.helpers.js";
import {
- UseChatProps,
- AttachedFile,
ActivePermissionRequest,
+ AttachedFile,
+ UseChatProps,
} from "./useChat.types.js";
export function useChat({
@@ -367,6 +367,7 @@ export function useChat({
requestId: string,
approved: boolean,
createPolicy?: boolean,
+ stopStream?: boolean,
) => {
// Capture the current permission request before clearing it
const currentRequest = activePermissionRequest;
@@ -402,6 +403,23 @@ export function useChat({
toolPermissionManager.approveRequest(requestId);
} else {
toolPermissionManager.rejectRequest(requestId);
+
+ // If this is a "stop stream" rejection, abort the current request
+ if (stopStream && abortController && isWaitingForResponse) {
+ abortController.abort();
+ setMessages((prev) => [
+ ...prev,
+ {
+ role: "system",
+ content:
+ "[Tool canceled - please tell Continue what to do differently]",
+ messageType: "system" as const,
+ },
+ ]);
+ setIsWaitingForResponse(false);
+ setResponseStartTime(null);
+ setInputMode(true);
+ }
}
};