Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion apps/desktop/src/state/inbox.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { describe, expect, test } from "bun:test";
import type { PermissionRequest, SessionSummary } from "../acp/types";
import { DECIDED_MAX, deriveInbox, foldDecided, groupInbox, type InboxItem, showsNeedsYou } from "./inbox";
import {
DECIDED_MAX,
deriveInbox,
foldDecided,
groupInbox,
type InboxItem,
readOnlyApprovals,
showsNeedsYou,
} from "./inbox";
import type { Link } from "./orchestration";

const NOW = 1_700_000_000_000;
Expand Down Expand Up @@ -287,3 +295,39 @@ describe("the decided section", () => {
expect(folded[0]!.key).toBe(gone.key);
});
});

describe("allowing the read-only approvals", () => {
test("only plainly read-only calls count, never a write, an unknown call or a question", () => {
const items = deriveInbox(
{
sessions,
threads: {
one: {
permissions: [
request("one", 1, NOW - 4_000, { title: "read_file src/a.ts", toolKind: "read" }),
request("one", 2, NOW - 3_000, { input: { command: "rm -rf build" } }),
request("one", 3, NOW - 2_000, { title: "mystery_tool" }),
],
},
two: {
permissions: [
request("two", 4, NOW - 1_000, { title: "grep needle", toolKind: "search" }),
request("two", 5, NOW - 500, {
title: "Pick one",
question: { multiple: false } as PermissionRequest["question"],
}),
],
},
},
failed: {},
links: [],
},
NOW,
);
expect(
readOnlyApprovals(items)
.map((item) => item.request?.rpcId)
.sort(),
).toEqual([1, 4]);
});
});
17 changes: 16 additions & 1 deletion apps/desktop/src/state/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// (state/inboxDismissed.ts).

import type { PermissionRequest, SessionSummary } from "../acp/types";
import { approvalSubject, commandOf } from "../lib/approval";
import { approvalSubject, assessApproval, commandOf } from "../lib/approval";
import { type InboxDismissals, isDismissed } from "./inboxDismissed";
import type { Link } from "./orchestration";

Expand Down Expand Up @@ -285,3 +285,18 @@ export function foldDecided(
export function showsNeedsYou(items: readonly InboxItem[]): boolean {
return items.length > 0;
}

/**
* The approvals waiting across every thread that only read: plainly read-only tools and commands
* (`assessApproval` says `safe`). Questions are not approvals, and anything unknown is not safe,
* so "Allow read-only" never answers a call that could change something.
*/
export function readOnlyApprovals(items: readonly InboxItem[]): InboxItem[] {
return items.filter(
(item) =>
item.kind === "approval" &&
!!item.request &&
!item.request.question &&
assessApproval(item.request, item.project).level === "safe",
);
}
27 changes: 26 additions & 1 deletion apps/desktop/src/ui/Inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { isAllow, type PermissionOption, type PermissionRequest, projectName } from "../acp/types";
import { assessApproval, grantAllowed, optionScope } from "../lib/approval";
import { useClock } from "../lib/useNow";
import { type DecidedItem, foldDecided, groupInbox, type InboxGroup, type InboxItem } from "../state/inbox";
import {
type DecidedItem,
foldDecided,
groupInbox,
type InboxGroup,
type InboxItem,
readOnlyApprovals,
} from "../state/inbox";
import { useInboxItems } from "../state/inboxRead";
import { filteredNeedsCount } from "../state/sidebarGroups";
import {
Expand Down Expand Up @@ -411,6 +418,17 @@ export function Inbox() {
dismissInbox(items);
}, [items]);

const readOnly = useMemo(() => readOnlyApprovals(items), [items]);
const allowReadOnly = useCallback(() => {
for (const item of readOnly) {
const option =
item.request && orderedOptions(item.request.options).find((o) => optionScope(o) === "once");
if (!item.request || !option) continue;
labels.current[item.key] = "Approved";
answerPermission(item.request, option);
}
}, [readOnly]);

useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.metaKey || e.ctrlKey || e.altKey || e.isComposing) return;
Expand Down Expand Up @@ -469,6 +487,13 @@ export function Inbox() {
</span>
}
>
{readOnly.length > 1 && (
<Tooltip label="Approve once every waiting call that only reads: listing, searching, viewing files">
<Pill size="sm" onClick={allowReadOnly}>
Allow {readOnly.length} read-only
</Pill>
</Tooltip>
)}
{items.length > 0 && (
<Pill size="sm" quiet onClick={dismissAll}>
Dismiss all
Expand Down
Loading