A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
feat(island): queue concurrent agent permission requests (#870)
Ohualtexc926de1fab7d
diff --git a/windows/src/core/state.ts b/windows/src/core/state.tsindex bab28737..a548a22d 100644--- a/windows/src/core/state.ts+++ b/windows/src/core/state.ts@@ -232,6 +232,8 @@ class AppState {searchResult: SearchResult | null = null;chatHistory: ChatMessage[] = [];pendingApproval: ApprovalInfo | null = null;+ /** Requests waiting in line when another card is already up (Mac ApprovalQueue). */+ approvalQueue: ApprovalInfo[] = [];/** The pill that was in front when the card came up; it comes back after. */focusBeforeApproval: string | null = null;@@ -330,6 +332,16 @@ class AppState {this.isPinned = false;this.updateTask(req.pillId, "working");this.setPillBadge(req.pillId, null);++ // If another request is waiting in line, promote it next+ const next = this.approvalQueue.shift();+ if (next) {+ this.beginApproval(next);+ this.updateTask(next.pillId, next.questions ? "question" : "approval");+ this.notify();+ return;+ }+const previous = this.focusBeforeApproval;this.focusBeforeApproval = null;if (previous && this.focusId === req.pillId && this.tasks.some((t) => t.id === previous)) {diff --git a/windows/src/island/hooks.ts b/windows/src/island/hooks.tsindex b96e82a5..9a71fe4c 100644--- a/windows/src/island/hooks.ts+++ b/windows/src/island/hooks.ts@@ -26,6 +26,13 @@ let pendingTimeout: number | null = null;export function dropPendingCard(island: Island): void {if (!State.pendingApproval) return;State.endApproval();+ if (State.pendingApproval) {+ const view = State.pendingApproval.questions ? "question" : "approval";+ island.setView(view);+ Sound.play(view);+ State.notify();+ return;+ }island.dropPin();if (State.view === "approval" || State.view === "question") {island.setView(State.defaultView());@@ -246,6 +253,7 @@ export function registerHookHandlers(island: Island) {// The relay stopped waiting without a decision and the terminal has taken// over: a card still up for that request would be lying (#857).void onEvent<string>("approval-expired", (requestId) => {+ State.approvalQueue = State.approvalQueue.filter((x) => x.requestId !== requestId);if (State.pendingApproval?.requestId !== requestId) return;if (pendingTimeout != null) window.clearTimeout(pendingTimeout);pendingTimeout = null;@@ -498,38 +506,46 @@ function handleHook(island: Island, payload: HookPayload) {}const requestId = payload.request_id ?? "";- // One card, one request. A second one must never quietly replace the first- // — that would leave a human staring at request B while request A waits for- // a decision nobody can give. Hand it straight back to the terminal.- if (State.pendingApproval && State.pendingApproval.requestId !== requestId) {+ // If this exact request is already showing or queued, ack again and leave it alone+ if (State.pendingApproval?.requestId === requestId || State.approvalQueue.some((x) => x.requestId === requestId)) {+ if (requestId) void Bridge.approvalAck(requestId);+ break;+ }++ // Max 5 concurrent requests waiting (matching macOS ApprovalQueue.maxPending)+ const totalPending = (State.pendingApproval ? 1 : 0) + State.approvalQueue.length;+ if (totalPending >= 5) {if (requestId) void Bridge.approvalDecline(requestId);break;}+ensurePill();supersedeStop();- if (pendingTimeout != null) window.clearTimeout(pendingTimeout);const tool = payload.tool_name ?? "Tool";const input = payload.tool_input ?? {};- // Claude Code asking a question is not a permission to grant: the island- // shows the options and sends back the one that was picked. Only Claude- // Code asks questions this way.const questions = isExternalAgent ? null : askedQuestions(tool, input);const view = questions ? "question" : "approval";- // The card always comes up, even over another pill or an island that is- // already open: its pill comes to the front, and the one you were on- // comes back once you answer (Mac #117, #120).- State.beginApproval({++ const info: ApprovalInfo = {requestId,sessionId,pillId: agentId,tool,command: approvalTarget(tool, input),...(questions ? { questions } : {}),- });- // The relay's short ack window closes in 800 ms; everything below this- // line is synchronous, so the card really is up by the time it lands.- if (requestId) void Bridge.approvalAck(requestId);- State.updateTask(agentId, view);+ };++ if (!State.pendingApproval) {+ if (pendingTimeout != null) window.clearTimeout(pendingTimeout);+ State.beginApproval(info);+ if (requestId) void Bridge.approvalAck(requestId);+ State.updateTask(agentId, view);+ Sound.play(view);+ } else {+ // Queue behind the currently showing request+ State.approvalQueue.push(info);+ if (requestId) void Bridge.approvalAck(requestId);+ }Sound.play(view);// Any agent's card (Claude Code, Codex, Copilot CLI, Muse Code) comes up// the same way: beginApproval brought its pill to the front.diff --git a/windows/src/island/island.ts b/windows/src/island/island.tsindex 090d2729..af46560e 100644--- a/windows/src/island/island.ts+++ b/windows/src/island/island.ts@@ -146,6 +146,12 @@ export class Island {/** The request has its answer: the card goes and the session carries on. */private closeApproval() {State.endApproval();+ if (State.pendingApproval) {+ const view = State.pendingApproval.questions ? "question" : "approval";+ this.setView(view);+ Sound.play(view);+ return;+ }this.fsm.pinned = false;this.setView(State.defaultView());}diff --git a/windows/tests/hooks.test.mjs b/windows/tests/hooks.test.mjsindex 552bbd5f..0ecbb9dd 100644--- a/windows/tests/hooks.test.mjs+++ b/windows/tests/hooks.test.mjs@@ -519,13 +519,27 @@ test("a request from Claude Code in Cursor's terminal goes on the Cursor pill",assert.equal(task().state, "idle");});-test("a second request never replaces the card: it goes back to the terminal", () => {+test("a second request is queued in line: it waits for the first card to finish (#870)", () => {ask("r1");ask("r2", { tool_name: "Bash", tool_input: { command: "ls" } });assert.equal(State.pendingApproval.requestId, "r1");assert.equal(State.pendingApproval.tool, "Write");- assert.deepEqual(sent("approval_decline"), [{ requestId: "r2" }]);- assert.deepEqual(sent("approval_ack"), [{ requestId: "r1" }]);+ assert.equal(State.approvalQueue.length, 1);+ assert.equal(State.approvalQueue[0].requestId, "r2");+ assert.deepEqual(sent("approval_decline"), []);+ assert.deepEqual(sent("approval_ack"), [{ requestId: "r1" }, { requestId: "r2" }]);++ // When r1 finishes, r2 takes the card+ State.endApproval();+ assert.equal(State.pendingApproval.requestId, "r2");+ assert.equal(State.pendingApproval.tool, "Bash");+ assert.equal(State.approvalQueue.length, 0);++ // Beyond maxPending (5 total), new requests are declined+ ask("r3"); ask("r4"); ask("r5"); ask("r6");+ assert.equal(State.approvalQueue.length, 4); // r2 active + r3..r6 queued = 5 total+ ask("r7");+ assert.deepEqual(sent("approval_decline"), [{ requestId: "r7" }]);});test("the same request arriving twice is acknowledged again, not declined", () => {@@ -707,9 +721,9 @@ test("a declined permission request leaves the stop timer running", () => {{ coucou_agent: "gemini" },);assert.equal(task("agent_gemini"), undefined);- // So is a second request while a card is already up.+ // So is a request from an agent that doesn't take approvals.ask("r1");- afterStop(() => ask("r2"));+ afterStop(() => hook({ hook_event_name: "PermissionRequest", request_id: "r2", coucou_agent: "gemini", tool_name: "Bash" }));assert.deepEqual(sent("approval_decline"), [{ requestId: "r1" }, { requestId: "r2" }]);assert.equal(task().state, "idle");});