Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(agents): answer a permission request from its line in the conversation (#1170)

l0ng-aifd4921c58af0
diff --git a/src/features/agents/Session.module.css b/src/features/agents/Session.module.css
index 7df8308db..8b18605d3 100644
--- a/src/features/agents/Session.module.css
+++ b/src/features/agents/Session.module.css
@@ -463,6 +463,14 @@
.permissionLine > .muted {
flex: none;
}
+.permissionAnswers {
+ flex: 1 1 160px;
+ min-width: 0;
+ display: flex;
+ flex-wrap: wrap;
+ gap: 2px 12px;
+ margin-left: 6px;
+}
.error {
display: flex;
diff --git a/src/features/agents/SessionEditor.tsx b/src/features/agents/SessionEditor.tsx
index ff57ff3a1..7251f0638 100644
--- a/src/features/agents/SessionEditor.tsx
+++ b/src/features/agents/SessionEditor.tsx
@@ -1147,7 +1147,45 @@ function WorkingSubagents({ entries, onOpen }: { entries: AgentEntry[] | null; o
/** Agent-written titles with the task's own folder dropped from paths. */
const shortTitle = (task: AgentTask, title: string) => title.replaceAll(`${task.cwd}/`, "");
-function PermissionLine({ task, entry }: { task: AgentTask; entry: Extract<AgentEntry, { type: "permission" }> }) {
+type PermissionEntry = Extract<AgentEntry, { type: "permission" }>;
+
+/**
+ * The answers to an open permission request. A request without options (some agents send
+ * none) can still be cancelled, so the agent doesn't wait for an answer it can't get.
+ */
+function PermissionAnswers({
+ task,
+ entry,
+ className,
+}: {
+ task: AgentTask;
+ entry: PermissionEntry;
+ className?: string;
+}) {
+ const [busy, setBusy] = useState(false);
+ const answer = (option: string | null) => {
+ setBusy(true);
+ void respond(task.id, entry.id, option).finally(() => setBusy(false));
+ };
+ return (
+ <span className={className}>
+ {entry.options.length ? (
+ entry.options.map((o) => (
+ <button key={o.id} type="button" className={styles.bannerLink} disabled={busy} onClick={() => answer(o.id)}>
+ {o.name}
+ </button>
+ ))
+ ) : (
+ <button type="button" className={styles.bannerLink} disabled={busy} onClick={() => answer(null)}>
+ <T>Cancel</T>
+ </button>
+ )}
+ </span>
+ );
+}
+
+/** A permission request in the conversation; while open, answered right there as in the banner. */
+function PermissionLine({ task, entry }: { task: AgentTask; entry: PermissionEntry }) {
return (
<div className={styles.permissionLine}>
<Icon name={!entry.chosen ? "warning" : entry.chosen === "Cancelled" ? "minus" : "check"} size={13} />
@@ -1155,32 +1193,20 @@ function PermissionLine({ task, entry }: { task: AgentTask; entry: Extract<Agent
{shortTitle(task, entry.title)}
</span>
<span className={styles.muted}>{entry.chosen ?? <T>Waiting for your answer</T>}</span>
+ {!entry.chosen && <PermissionAnswers task={task} entry={entry} className={styles.permissionAnswers} />}
</div>
);
}
/** The open permission request, as an editor notification banner above the conversation. */
function PermissionBanner({ task, entries }: { task: AgentTask; entries: AgentEntry[] | null }) {
- const [busy, setBusy] = useState(false);
- const entry = entries?.find(
- (e): e is Extract<AgentEntry, { type: "permission" }> => e.type === "permission" && !e.chosen,
- );
+ const entry = entries?.find((e): e is PermissionEntry => e.type === "permission" && !e.chosen);
if (!entry) return null;
- const answer = (option: string | null) => {
- setBusy(true);
- void respond(task.id, entry.id, option).finally(() => setBusy(false));
- };
return (
<div className={styles.banner} role="alert" aria-label={entry.title}>
<Icon name="warning" size={16} />
<span className={styles.bannerText}>{shortTitle(task, entry.title)}</span>
- <span className={styles.bannerActions}>
- {entry.options.map((o) => (
- <button key={o.id} type="button" className={styles.bannerLink} disabled={busy} onClick={() => answer(o.id)}>
- {o.name}
- </button>
- ))}
- </span>
+ <PermissionAnswers task={task} entry={entry} className={styles.bannerActions} />
</div>
);
}
diff --git a/src/features/agents/sessionState.test.tsx b/src/features/agents/sessionState.test.tsx
index 9348c369c..9d0a361f4 100644
--- a/src/features/agents/sessionState.test.tsx
+++ b/src/features/agents/sessionState.test.tsx
@@ -135,6 +135,47 @@ describe("a pending question", () => {
});
});
+describe("a pending permission request in the conversation", () => {
+ it("is answered from its line too, and one without options can be cancelled", async () => {
+ backend.entries.set("A", [
+ {
+ type: "permission",
+ id: 3,
+ title: "ls d:/project",
+ options: [
+ { id: "once", name: "Allow once", kind: "allow_once" },
+ { id: "reject", name: "Reject", kind: "reject_once" },
+ ],
+ chosen: null,
+ },
+ ]);
+ backend.entries.set("B", [
+ { type: "permission", id: 4, title: "The agent asks for permission", options: [], chosen: null },
+ ]);
+ backend.answers = [];
+ useAgents.setState({ entries: new Map(backend.entries) });
+ const { unmount } = render(<SessionEditor input={input("A")} />);
+ const line = (await screen.findAllByText("ls d:/project")).find((e) =>
+ e.classList.contains(styles.permissionTitle!),
+ )!.parentElement!;
+ const answers = within(line.querySelector<HTMLElement>(`.${styles.permissionAnswers}`)!).getAllByRole("button");
+ expect(answers.map((b) => b.textContent)).toEqual(["Allow once", "Reject"]);
+ fireEvent.click(answers[0]!);
+ await waitFor(() => expect(backend.answers).toEqual([["A", 3, "once"]]));
+ unmount();
+
+ render(<SessionEditor input={input("B")} />);
+ const banner = await screen.findByRole("alert", { name: "The agent asks for permission" });
+ fireEvent.click(within(banner).getByRole("button", { name: "Cancel" }));
+ await waitFor(() =>
+ expect(backend.answers).toEqual([
+ ["A", 3, "once"],
+ ["B", 4, null],
+ ]),
+ );
+ });
+});
+
describe("session state across tasks and hosts", () => {
it("returns to the task conversation when the docked task changes after opening a subagent", async () => {
const dispose = registerActions(taskActions);