Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(computer): skip the "use your computer" card at Full access (#4325)

Aditya Umale3ac9368bb99b
diff --git a/server/host-lazy-claim.e2e.test.ts b/server/host-lazy-claim.e2e.test.ts
index e4ab5287e8..0da08a35b9 100644
--- a/server/host-lazy-claim.e2e.test.ts
+++ b/server/host-lazy-claim.e2e.test.ts
@@ -113,6 +113,8 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
}
// Auto may land on the person's own desktop only on macOS and Windows.
const itAutoHost = process.platform === "linux" ? it.skip : it;
+ // Full access, the default, is the person's grant to use this computer without asking; every other level asks.
+ const ASKS = "ask";
beforeAll(async () => {
home = mkdtempSync(join(tmpdir(), "omb-host-lazy-claim-"));
@@ -144,7 +146,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("holds no computer:host claim and records no pin until a screen tool runs", async () => {
await start();
- const { bot: holder } = await apiOk("POST", "/api/bots", { name: "Screenless Host Bot" });
+ const { bot: holder } = await apiOk("POST", "/api/bots", { name: "Screenless Host Bot", settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${holder.id}/tasks`, {});
resetTurn();
await apiOk("POST", `/api/bots/${holder.id}/messages`, { text: "Work slowly without touching the screen.", threadId: task.threadId });
@@ -153,7 +155,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
expect(computer.env.OMB_CUA_COMMAND).toBe("/fixture/cua-driver");
expect(computer.args.some((arg: string) => arg.includes("local-computer-proxy"))).toBe(true);
expect(savedTask(holder.id, task.threadId)).not.toHaveProperty("surface");
- const { bot: claimer } = await apiOk("POST", "/api/bots", { name: "Host Claim Bot" });
+ const { bot: claimer } = await apiOk("POST", "/api/bots", { name: "Host Claim Bot", settings: { approvalMode: ASKS } });
const { task: claimTask } = await apiOk("POST", `/api/bots/${claimer.id}/tasks`, {});
await apiOk("POST", `/api/bots/${claimer.id}/messages`, { text: "Work slowly too.", threadId: claimTask.threadId });
await busy(claimer.id, claimTask.threadId);
@@ -167,7 +169,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("claims the seat and records the pin on the first screen tool call", async () => {
await start();
- const { bot } = await apiOk("POST", "/api/bots", { name: "Host Screen Bot" });
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Screen Bot", settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
resetTurn();
await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Work slowly; the screen comes later.", threadId: task.threadId });
@@ -177,7 +179,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
expect(await withAnswer(base, task.threadId, gate(computer))).toEqual({ held: false, helpOpen: false });
await until(() => savedTask(bot.id, task.threadId)?.surface === "local", Boolean);
expect(savedTask(bot.id, task.threadId)).toMatchObject({ surface: "local", surfaceSource: "auto" });
- const { bot: second } = await apiOk("POST", "/api/bots", { name: "Host Contended Bot" });
+ const { bot: second } = await apiOk("POST", "/api/bots", { name: "Host Contended Bot", settings: { approvalMode: ASKS } });
const { task: secondTask } = await apiOk("POST", `/api/bots/${second.id}/tasks`, {});
await apiOk("POST", `/api/bots/${second.id}/messages`, { text: "Also work slowly.", threadId: secondTask.threadId });
await busy(second.id, secondTask.threadId);
@@ -193,7 +195,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("a busy computer is waited for inside the call: it answers when the holder ends, and a person's hold is waited out", async () => {
await start();
const turn = async (name: string) => {
- const { bot } = await apiOk("POST", "/api/bots", { name });
+ const { bot } = await apiOk("POST", "/api/bots", { name, settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Work slowly on the screen.", threadId: task.threadId });
await busy(bot.id, task.threadId);
@@ -245,7 +247,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("a person's hold past the wait ceiling is not waited for: the turn is told to stop and say so", async () => {
const ceilingMs = 2_000;
await start({ OMB_COMPUTER_WAIT_MAX_MS: String(ceilingMs) });
- const { bot } = await apiOk("POST", "/api/bots", { name: "Host Away Bot" });
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Away Bot", settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Work slowly on the screen.", threadId: task.threadId });
await busy(bot.id, task.threadId);
@@ -272,7 +274,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("a call waiting behind another turn never goes through once its own turn is stopped", async () => {
await start();
const turn = async (name: string) => {
- const { bot } = await apiOk("POST", "/api/bots", { name });
+ const { bot } = await apiOk("POST", "/api/bots", { name, settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Work slowly on the screen.", threadId: task.threadId });
await busy(bot.id, task.threadId);
@@ -295,10 +297,9 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
await idle(waiter.bot.id, waiter.threadId);
}, 60_000);
- itAutoHost("asks once before the first screen call even at Just do it, in plain words naming the app and the site", async () => {
+ itAutoHost("never asks at Full access, the default: the first screen call goes straight through", async () => {
await start();
- const { bot } = await apiOk("POST", "/api/bots", { name: "Host Asking Bot" });
- // The default approval level is "Just do it": nothing else in this turn asks.
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Full Access Bot" });
expect(bot.approvalMode ?? "full").toBe("full");
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
resetTurn();
@@ -306,6 +307,23 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
await busy(bot.id, task.threadId);
const computer = mountedComputer(await dumpFor(bot.id));
const client = createControlClient({ url: computer.env.OMB_CONTROL_URL, token: computer.env.OMB_CONTROL_TOKEN });
+ expect(await client.state(true, { app: "Chrome", site: "calendar.google.com" })).toEqual({ held: false, helpOpen: false });
+ const cards = (await apiOk("GET", `/api/threads/${task.threadId}/messages?limit=200`)).messages
+ .filter((message: any) => message.card?.tool === "use_your_computer");
+ expect(cards).toEqual([]);
+ writeFileSync(finishFile, "finish");
+ await idle(bot.id, task.threadId);
+ }, 60_000);
+
+ itAutoHost("asks once before the first screen call below Full access, in plain words naming the app and the site", async () => {
+ await start();
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Asking Bot", settings: { approvalMode: ASKS } });
+ const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
+ resetTurn();
+ await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Look at my calendar slowly.", threadId: task.threadId });
+ await busy(bot.id, task.threadId);
+ const computer = mountedComputer(await dumpFor(bot.id));
+ const client = createControlClient({ url: computer.env.OMB_CONTROL_URL, token: computer.env.OMB_CONTROL_TOKEN });
// Exactly what the mounted proxy sends for launch_app { bundle_id: "com.google.Chrome", urls: [...] }.
const first = timed(client.state(true, { app: "Chrome", site: "calendar.google.com" }));
const card = await openYourComputerCard(base, task.threadId);
@@ -329,7 +347,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("a No is an answer, not a failure: the screen stays untouched and the bot is told to finish another way", async () => {
await start();
- const { bot } = await apiOk("POST", "/api/bots", { name: "Host Declined Bot" });
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Declined Bot", settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
resetTurn();
await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Book a table slowly.", threadId: task.threadId });
@@ -351,7 +369,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("a question the request outlives is closed, and answers nothing", async () => {
await start();
- const { bot } = await apiOk("POST", "/api/bots", { name: "Host Stopped Bot" });
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Stopped Bot", settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
resetTurn();
await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Work slowly on the screen.", threadId: task.threadId });
@@ -368,7 +386,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
itAutoHost("asks again on the next request, and never when the person picked this computer themselves", async () => {
await start();
- const { bot } = await apiOk("POST", "/api/bots", { name: "Host Again Bot" });
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Again Bot", settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
const request = async (text: string) => {
resetTurn();
@@ -398,7 +416,7 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
// Like the tests above, this needs the desktop driver fixture, which only macOS and Windows have here.
itAutoHost("never asks in a thread the app pinned to this computer once the bot works on this computer", async () => {
await start();
- const { bot } = await apiOk("POST", "/api/bots", { name: "Host Works On Bot" });
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Works On Bot", settings: { approvalMode: ASKS } });
const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
await apiOk("PATCH", `/api/bots/${bot.id}`, { computer: "local" });
await stop();
diff --git a/server/index.ts b/server/index.ts
index b9e086bdc5..4e33e2d8ce 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -410,7 +410,7 @@ import { shellTimeoutHookResult } from "./shell-timeout-hint.ts";
import { spillToolResult } from "./tool-result-spill.ts";
import { gatedLocalComputer } from "./local-computer.ts";
import { desktopComputer, thisComputerNotReady } from "./desktop-computer.ts";
-import { askToUseYourComputer, cancelYourComputerAsks, dismissStaleYourComputerCards, yourComputerCallFrom, yourComputerWaiting } from "./your-computer-consent.ts"; import { createComputerAsksHost } from "./host/computer-asks-host.ts";
+import { askToUseYourComputer, cancelYourComputerAsks, claimWithYourComputerConsent, dismissStaleYourComputerCards, yourComputerCallFrom, yourComputerWaiting } from "./your-computer-consent.ts"; import { createComputerAsksHost } from "./host/computer-asks-host.ts";
import { discoverExistingPerBotLocalVms, localVmInventoryEntry } from "./local-vm-inventory.ts";
import { createLocalVmUpdater, LOCAL_VM_UPDATING_PROBLEM, recoverLocalVms, VPS_OUTDATED_HINT, vpsDesktopOutdated, withoutHostWhileUpdating } from "./desktop-updates.ts";
import { keepInstalledAppsBeforeRemove } from "./local-vm-profiles.ts";
@@ -5864,8 +5864,8 @@ function cloudComputerTools(botId: string, owner: TurnOwner, boxId: string | nul
};
}
-/** `ask`: the person did not pick this computer themselves (an Auto pin), so the first screen call asks them once. */
-async function mountHostComputer(owner: TurnOwner, botId: string, providerSupportsLocal: boolean, onRejected: (failure: string, error?: unknown) => void, ask = false, journal = false) {
+/** `askNow`: read at the first screen call (an Auto pin below Full access, checked live), so the person is asked once then. */
+async function mountHostComputer(owner: TurnOwner, botId: string, providerSupportsLocal: boolean, onRejected: (failure: string, error?: unknown) => void, askNow: () => boolean = () => false, journal = false) {
if (!shouldMountLocalComputer({ requested: "local", hostPlatform: process.platform, providerSupportsLocal })) {
throw new Error(providerSupportsLocal
? "bots can't use this computer on this system — choose another place for this bot to work"
@@ -5876,7 +5876,7 @@ async function mountHostComputer(owner: TurnOwner, botId: string, providerSuppor
await bindTurnComputer(owner, "computer:host");
autoVmClaims.set(owner.threadId, {
owner, lazy: true, label: "this computer", onRejected,
- claim: async (call) => { if (ask) await askToUseYourComputer(approvalBus, store.bot(botId) ?? undefined, owner, call); await bindTurnComputer(owner, "computer:host", true); },
+ claim: (call) => claimWithYourComputerConsent(askNow, () => askToUseYourComputer(approvalBus, store.bot(botId) ?? undefined, owner, call), () => bindTurnComputer(owner, "computer:host", true)),
});
return gatedLocalComputer(cua, controlIntegration(botId, owner.threadId, owner.generation, "this computer"), journal);
}
@@ -8263,7 +8263,7 @@ async function beginTurn(
if (wants === "vm") {
if (await attachLocalVm(true)) computerKind = "vm";
} else if (wants === "local") {
- integrations.localComputer = await mountHostComputer(resourceOwner, bot.id, mountsLocalComputer, surfaceLazyClaimRejection("this computer"), placeSource === "auto-pin", savedSteps.journals(directRequestOwners.get(threadId)));
+ integrations.localComputer = await mountHostComputer(resourceOwner, bot.id, mountsLocalComputer, surfaceLazyClaimRejection("this computer"), () => placeSource === "auto-pin" && liveApprovalMode(bot, threadId, commsDepth > 0) !== "full", savedSteps.journals(directRequestOwners.get(threadId)));
computerKind = "local";
}
@@ -8341,8 +8341,7 @@ async function beginTurn(
label: "this computer",
onRejected: surfaceLazyClaimRejection("this computer"),
claim: async (call) => {
- await askToUseYourComputer(approvalBus, bot, resourceOwner, call);
- await bindTurnComputer(resourceOwner, "computer:host", true);
+ await claimWithYourComputerConsent(() => liveApprovalMode(bot, threadId, commsDepth > 0) !== "full", () => askToUseYourComputer(approvalBus, bot, resourceOwner, call), () => bindTurnComputer(resourceOwner, "computer:host", true));
pinAutoSurface("local"); recordTurnPlace(bot.id, threadId, "local");
},
});
diff --git a/server/room-roots.e2e.test.ts b/server/room-roots.e2e.test.ts
index 0986685cf8..018d34047b 100644
--- a/server/room-roots.e2e.test.ts
+++ b/server/room-roots.e2e.test.ts
@@ -359,13 +359,13 @@ itHost("R5 queues a member's root on the computer seat at the wait ceiling, FIFO
try { return (await fetch(base + "/api/health")).ok; } catch { return false; }
}, Boolean);
- const { bot: holder } = await apiOk("POST", "/api/bots", { name: "Seat Holder" });
+ const { bot: holder } = await apiOk("POST", "/api/bots", { name: "Seat Holder", settings: { approvalMode: "ask" } });
const { task: held } = await apiOk("POST", `/api/bots/${holder.id}/tasks`, {});
await apiOk("POST", `/api/bots/${holder.id}/messages`, { text: "Hold the screen slowly.", threadId: held.threadId });
await until(() => taskOf(holder.id, held.threadId), (task) => task?.busy === true);
- // On Auto the person is asked once before each turn first uses their computer.
+ // Below Full access (these bots ask), the person is asked once before each turn first uses their computer.
expect(await withAnswer(base, held.threadId, gate(await dumpFor(holder.id)))).toEqual({ held: false, helpOpen: false });
- const { bot: waiter } = await apiOk("POST", "/api/bots", { name: "Seat Waiter" });
+ const { bot: waiter } = await apiOk("POST", "/api/bots", { name: "Seat Waiter", settings: { approvalMode: "ask" } });
const { task: wait } = await apiOk("POST", `/api/bots/${waiter.id}/tasks`, {});
await apiOk("POST", `/api/bots/${waiter.id}/messages`, { text: "R5-DIRECT: use the screen too.", threadId: wait.threadId });
await until(() => taskOf(waiter.id, wait.threadId), (task) => task?.busy === true);
diff --git a/server/runtime-roots.e2e.test.ts b/server/runtime-roots.e2e.test.ts
index 9e01a673c8..cc4c9d45d5 100644
--- a/server/runtime-roots.e2e.test.ts
+++ b/server/runtime-roots.e2e.test.ts
@@ -461,13 +461,13 @@ itHost("T7 queues a root on the computer seat at the wait ceiling and continues
try { return (await fetch(base + "/api/health")).ok; } catch { return false; }
}, Boolean);
- const { bot: holder } = await apiOk("POST", "/api/bots", { name: "Seat Holder" });
+ const { bot: holder } = await apiOk("POST", "/api/bots", { name: "Seat Holder", settings: { approvalMode: "ask" } });
const { task: held } = await apiOk("POST", `/api/bots/${holder.id}/tasks`, {});
await apiOk("POST", `/api/bots/${holder.id}/messages`, { text: "Hold the screen slowly.", threadId: held.threadId });
await until(() => taskOf(holder.id, held.threadId), (task) => task?.busy === true);
- // On Auto the person is asked once before each turn first uses their computer.
+ // Below Full access (these bots ask), the person is asked once before each turn first uses their computer.
expect(await withAnswer(base, held.threadId, gate(await dumpFor(holder.id)))).toEqual({ held: false, helpOpen: false });
- const { bot: waiter } = await apiOk("POST", "/api/bots", { name: "Seat Waiter" });
+ const { bot: waiter } = await apiOk("POST", "/api/bots", { name: "Seat Waiter", settings: { approvalMode: "ask" } });
const { task: wait } = await apiOk("POST", `/api/bots/${waiter.id}/tasks`, {});
await apiOk("POST", `/api/bots/${waiter.id}/messages`, { text: "T7-JOB: use the screen too.", threadId: wait.threadId });
await until(() => taskOf(waiter.id, wait.threadId), (task) => task?.busy === true);
@@ -481,7 +481,7 @@ itHost("T7 queues a root on the computer seat at the wait ceiling and continues
const parkedChip = chat.find((message) => chipText(message).includes("Parked — it continues automatically when the computer is free"));
expect(parkedChip, JSON.stringify(chat.map(chipText))).toBeDefined();
expect(chipText(parkedChip)).toContain("Seat Holder");
- const { bot: second } = await apiOk("POST", "/api/bots", { name: "Seat Second" });
+ const { bot: second } = await apiOk("POST", "/api/bots", { name: "Seat Second", settings: { approvalMode: "ask" } });
const { task: wait2 } = await apiOk("POST", `/api/bots/${second.id}/tasks`, {});
await apiOk("POST", `/api/bots/${second.id}/messages`, { text: "T7-JOB-2: use the screen as well.", threadId: wait2.threadId });
await until(() => taskOf(second.id, wait2.threadId), (task) => task?.busy === true);
diff --git a/server/surface.test.ts b/server/surface.test.ts
index 7574bdccaa..cebe16cd2d 100644
--- a/server/surface.test.ts
+++ b/server/surface.test.ts
@@ -219,7 +219,7 @@ describe("surfacePrompt", () => {
expect(beside).toContain("This computer is the person's own: their screen, their apps and the browsers they are signed in to.");
expect(beside).toContain("use, in this order: a connected app that does it, your built-in browser, a cloud computer if select_computer offers one.");
expect(beside).toContain("Use their own browser or screen only when the task needs their own signed-in session and nothing else works.");
- expect(beside).toContain("OpenMausBot asks them once whether you may, at every approval level");
+ expect(beside).toContain("OpenMausBot asks them once whether you may, at every approval level except Full access");
expect(beside).toContain("never mention DevTools, CDP, debugging ports, profiles, grants, binding, attaching, endpoints or drivers");
const alone = surfacePrompt({ computer: "local", browser: false });
expect(alone).not.toMatch(/web pages included/);
diff --git a/server/surface.ts b/server/surface.ts
index 430316b106..5ce007afd1 100644
--- a/server/surface.ts
+++ b/server/surface.ts
@@ -161,7 +161,7 @@ export function surfaceLabel(surface: Surface): string {
/** This computer is the person's own: web work goes elsewhere first, and their first-use question is the harness's to ask. */
const WEB_WORK_ORDER = "For web work such as finding, booking or looking something up, use, in this order:";
const YOUR_COMPUTER_LAST =
- " Use their own browser or screen only when the task needs their own signed-in session and nothing else works. Before your first action on it in a request, OpenMausBot asks them once whether you may, at every approval level: do not ask in chat yourself, and if they say no, finish another way. " + PLAIN_WORDS;
+ " Use their own browser or screen only when the task needs their own signed-in session and nothing else works. Before your first action on it in a request, OpenMausBot asks them once whether you may, at every approval level except Full access: do not ask in chat yourself, and if they say no, finish another way. " + PLAIN_WORDS;
const YOUR_COMPUTER_BESIDE_BROWSER =
` This computer is the person's own: their screen, their apps and the browsers they are signed in to. ${WEB_WORK_ORDER} a connected app that does it, your built-in browser, a cloud computer if select_computer offers one.${YOUR_COMPUTER_LAST}`;
const YOUR_COMPUTER_ALONE =
diff --git a/server/your-computer-consent.test.ts b/server/your-computer-consent.test.ts
new file mode 100644
index 0000000000..e299ddf715
--- /dev/null
+++ b/server/your-computer-consent.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from "vitest";
+
+import { claimWithYourComputerConsent, YourComputerDeclined } from "./your-computer-consent.ts";
+
+describe("claimWithYourComputerConsent", () => {
+ const run = (levels: boolean[], answer: "allow" | "deny" = "allow") => {
+ const steps: string[] = [];
+ let reads = 0;
+ const askNow = () => levels[Math.min(reads++, levels.length - 1)];
+ const ask = async () => { steps.push("ask"); if (answer === "deny") throw new YourComputerDeclined("no"); };
+ const bind = async () => { steps.push("bind"); };
+ return { steps, done: claimWithYourComputerConsent(askNow, ask, bind) };
+ };
+
+ it("never asks at Full access, before or after the wait", async () => {
+ const { steps, done } = run([false, false]);
+ await done;
+ expect(steps).toEqual(["bind"]);
+ });
+
+ it("asks once, before the wait, below Full access", async () => {
+ const { steps, done } = run([true, true]);
+ await done;
+ expect(steps).toEqual(["ask", "bind"]);
+ });
+
+ it("asks after the wait when the thread dropped to Ask while it waited", async () => {
+ const { steps, done } = run([false, true]);
+ await done;
+ expect(steps).toEqual(["bind", "ask"]);
+ });
+
+ it("fails the claim when the person denies after the wait", async () => {
+ const { steps, done } = run([false, true], "deny");
+ await expect(done).rejects.toBeInstanceOf(YourComputerDeclined);
+ expect(steps).toEqual(["bind", "ask"]);
+ });
+});
diff --git a/server/your-computer-consent.ts b/server/your-computer-consent.ts
index f65ae83ece..5d64d858db 100644
--- a/server/your-computer-consent.ts
+++ b/server/your-computer-consent.ts
@@ -1,7 +1,7 @@
-// Asking before a bot uses the person's own computer. "Just do it" covers what a bot does in its own places (its
-// browser, a cloud desktop, its files), never taking over the person's screen: when a turn reaches this computer without
-// the person having picked it as the place, its first screen call waits on one plain card, Allow once or Deny, at every
-// approval level. The answer covers that turn only. Pending asks live in memory; a card left by a previous run is closed.
+// Asking before a bot uses the person's own computer. When a turn reaches this computer without the person having
+// picked it as the place, its first screen call waits on one plain card, Allow once or Deny, at every approval level
+// except Full access ("Just do it"), which is the person's grant to act without asking. The answer covers that turn
+// only. Pending asks live in memory; a card left by a previous run is closed.
import { newId } from "./contracts.ts";
import { optionCardsForTools } from "./message-db.ts";
import { buildNotification, type Notification } from "./notify.ts";
@@ -147,3 +147,15 @@ export function dismissStaleYourComputerCards(store: Store): number {
}
return dismissed;
}
+
+/**
+ * Asks before waiting for this computer, and once more after the wait if the turn dropped below Full access while
+ * it waited, so a thread switched to Ask mid-wait never gets the screen without a card. In that rare case the host
+ * stays held while the person answers; a Deny fails the claim and no screen call runs.
+ */
+export async function claimWithYourComputerConsent(askNow: () => boolean, ask: () => Promise<void>, bind: () => Promise<void>): Promise<void> {
+ const askedFirst = askNow();
+ if (askedFirst) await ask();
+ await bind();
+ if (!askedFirst && askNow()) await ask();
+}