Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: computer use screen-only payment words and send switch Enter rule

ogsamrat3095977a8363
diff --git a/apps/server/src/computer-use/contract-policy.test.ts b/apps/server/src/computer-use/contract-policy.test.ts
index bb2e9355..cb7fbf57 100644
--- a/apps/server/src/computer-use/contract-policy.test.ts
+++ b/apps/server/src/computer-use/contract-policy.test.ts
@@ -227,6 +227,7 @@ describe("policy: approvals per permission mode", () => {
["subscribe target", { target: { text: "Subscribe for $9.99/month" } }, ["risky_target"]],
["donate intent", { intent: "Donate 5 dollars" }, ["risky_intent"]],
["transfer intent", { intent: "Transfer $500 to savings" }, ["risky_intent"]],
+ ["transfer target", { target: { text: "Transfer" } }, ["risky_target"]],
["send money target", { target: { text: "Send $20" } }, ["risky_target"]],
["reorder target", { target: { text: "Reorder" } }, ["risky_target"]],
["book now target", { target: { text: "Book now" } }, ["risky_target"]],
@@ -262,6 +263,11 @@ describe("policy: approvals per permission mode", () => {
["send target (switch off)", { target: { text: "Send" } }, []],
["empty trash target (switch off)", { target: { text: "Empty Trash" } }, []],
["shift+delete (switch off)", { action: { type: "key", key: "Delete", modifiers: ["shift"] } }, []],
+ ["address book intent", { intent: "Open the address book" }, []],
+ ["transfer a file intent", { intent: "Transfer the file to the server" }, []],
+ ["upgrade intent", { intent: "Upgrade the dependency" }, []],
+ ["read the tip intent", { intent: "Read the tip" }, []],
+ ["Enter after typing (switch off)", { action: { type: "key", key: "Enter" }, target: {}, typed_before: true }, []],
["plain typing", { action: { type: "type", text: "Meeting notes for Tuesday" }, intent: "Type the notes" }, []],
["move over a pay button", { action: { type: "move", x: 1, y: 1 }, target: { text: "Pay" } }, []],
// Kept: an act outside the approved window (a session never sends one).
@@ -283,9 +289,12 @@ describe("policy: approvals per permission mode", () => {
expect(riskyWords("track my order")).toEqual([]);
expect(riskyWords("Send $20 to Bob")).toEqual(["amount"]);
expect(riskyWords("Transfer 500 EUR")).toEqual(["transfer", "amount"]);
+ expect(riskyWords("Transfer 500 EUR", "intent")).toEqual(["amount"]);
+ expect(riskyWords("Book now", "intent")).toEqual([]);
+ expect(riskyWords("Buy the plan", "intent")).toEqual(["buy"]);
expect(actApproval({ ...plain, intent: "Buy it" }).reasons[0]).toEqual({ code: "risky_intent", detail: "buy" });
for (const code of ["careful", "risky_intent", "risky_target", "secure_field", "credential_text", "credential_intent", "other_window"]) expect(typeof ASK_REASONS[code as keyof typeof ASK_REASONS]).toBe("string");
- expect(Object.keys(ASK_REASONS).sort()).toEqual(["careful", "credential_intent", "credential_text", "delete_chord", "other_window", "risky_intent", "risky_page", "risky_target", "secure_field", "send_delete_target"]);
+ expect(Object.keys(ASK_REASONS).sort()).toEqual(["careful", "credential_intent", "credential_text", "delete_chord", "other_window", "risky_intent", "risky_page", "risky_target", "secure_field", "send_after_typing", "send_delete_target"]);
expect(looksLikeCredential("AKIAABCDEFGHIJKLMNOP")).toBe(true);
expect(looksLikeCredential("password=Sup3rS3cret!")).toBe(true);
expect(looksLikeCredential("Xk9#mP2$vL7qR4@nT8wZ")).toBe(true);
@@ -300,6 +309,9 @@ describe("policy: approvals per permission mode", () => {
expect(actApproval({ ...plain, action: { type: "key", key: "Enter" }, target: { text: "Send" } }, on).ask).toBe(true);
for (const chord of [{ key: "Delete", modifiers: ["shift"] }, { key: "Backspace", modifiers: ["meta"] }]) expect(actApproval({ ...plain, action: { type: "key", ...chord } }, on).reasons).toEqual([{ code: "delete_chord" }]);
expect(actApproval({ ...plain, intent: "Send the email and delete the draft" }, on).ask).toBe(false);
+ for (const modifiers of [[], ["ctrl"], ["meta"]]) expect(actApproval({ ...plain, action: { type: "key", key: "Enter", modifiers }, target: { text: "Message #general" }, typed_before: true }, on).reasons).toEqual([{ code: "send_after_typing" }]);
+ expect(actApproval({ ...plain, action: { type: "key", key: "Enter" }, target: {}, typed_before: false }, on).ask).toBe(false);
+ expect(actApproval({ ...plain, action: { type: "key", key: "Enter", modifiers: ["shift"] }, target: {}, typed_before: true }, on).ask).toBe(false);
expect(actApproval({ ...plain, target: {} }, on).ask).toBe(false);
expect(actApproval({ ...plain, target: { text: "Move to Trash" } }, on).ask).toBe(false);
expect(actApproval({ ...plain, target: { text: "Sender" } }, on).ask).toBe(false);
diff --git a/apps/server/src/computer-use/shared/PARITY.sha256 b/apps/server/src/computer-use/shared/PARITY.sha256
index 8c10862f..0c177ee1 100644
--- a/apps/server/src/computer-use/shared/PARITY.sha256
+++ b/apps/server/src/computer-use/shared/PARITY.sha256
@@ -2,12 +2,12 @@
# A change to one must be ported to the other and this list updated in both.
59abb350a935c9462f3ea2e863396cdc785634dd2907f2f8947d87e9b30ec209 contract.mjs
aef0973f520f56ab8ad2699c14428bb2dd7ddb4b00dff823e4598e64d0c4a35b contract.d.mts
-f5b379f5c8270acf2bbbd319206d9217d7bd03fc0e18102c3d0334cd5396f9e6 policy.mjs
-8bb6597a3dd4d2b5b12ffcda52d344144c5f512e1d79b78cdbf6c743e17cd3d2 policy.d.mts
+cbfe657947a1e3a093b76e91b150e16df2b8b70756b0b816e27255c1c6f70190 policy.mjs
+8b7a75400b54beb385301d6ebb67624fb19b970525da73ef0413ba238918fb0d policy.d.mts
a96246342720364eb3e5843ba70fbbf640365f94597fc4dbb6a7be7d95254ec4 image.mjs
5eac31868aedd3e1d1e71b445f9a55d01316da7397f27f6db11472453bee4588 image.d.mts
e47c9ff67b9fce2ec12307737e973ce22551719c482b87f601569bd4f8a77e17 media.mjs
eabdf78c56733577d05aad490d9d7d5ece6c22e9b3ea9e6e9803d1a4a546fdd4 media.d.mts
a0bd964a5d0c7c5e26b4ce4ed8e8300f80a0a3a9da5d7f49c36f6ac2c907e934 native-worker.mjs
-2ca377ffc46df9ae4530a73bad1ce5b49f66d8b985b375f18f7a0d3e9f128e66 portable-host.mjs
+cf76c3a7653aa9eba112a2387f890ce1d75e69075dbe9cfabc134b4ce1ff19a3 portable-host.mjs
641be80cebb04d353031392d8f53f45ead1e1beaf83f1e67d24945f0eda330bf portable-host.d.mts
diff --git a/apps/server/src/computer-use/shared/policy.d.mts b/apps/server/src/computer-use/shared/policy.d.mts
index df4fda36..23d779cb 100644
--- a/apps/server/src/computer-use/shared/policy.d.mts
+++ b/apps/server/src/computer-use/shared/policy.d.mts
@@ -51,11 +51,11 @@ export function readAncestors(options?: { pid?: number; platform?: string; limit
export function nestedAgent(options?: { env?: Record<string, string | undefined>; ancestors?: ProcessInfo[] }): boolean;
export const RISKY_WORDS: readonly string[];
-export function riskyWords(value: unknown): string[];
+export function riskyWords(value: unknown, from?: "screen" | "intent"): string[];
export function looksLikeCredential(value: unknown): boolean;
export const ASK_SEND_DELETE: boolean;
-export type AskReasonCode = "careful" | "risky_intent" | "risky_target" | "secure_field" | "credential_text" | "credential_intent" | "other_window" | "risky_page" | "send_delete_target" | "delete_chord";
+export type AskReasonCode = "careful" | "risky_intent" | "risky_target" | "secure_field" | "credential_text" | "credential_intent" | "other_window" | "risky_page" | "send_delete_target" | "delete_chord" | "send_after_typing";
export type ApprovalInput = {
mode?: PermissionMode | string;
action?: Action | Record<string, unknown>;
@@ -63,6 +63,8 @@ export type ApprovalInput = {
target?: { text?: string; secure?: boolean };
window?: { id?: string | number; app_id?: string; title?: string };
approved?: { window_id?: string | number; app_id?: string };
+ /** The agent's previous act in this window typed text (and no click or Enter since). */
+ typed_before?: boolean;
};
export function actApproval(input?: ApprovalInput, options?: { sendDelete?: boolean }): { ask: boolean; reasons: Array<{ code: AskReasonCode; detail?: string }> };
export const ASK_REASONS: Readonly<Record<AskReasonCode, string>>;
diff --git a/apps/server/src/computer-use/shared/policy.mjs b/apps/server/src/computer-use/shared/policy.mjs
index cfc0b6c5..a29c1676 100644
--- a/apps/server/src/computer-use/shared/policy.mjs
+++ b/apps/server/src/computer-use/shared/policy.mjs
@@ -268,14 +268,20 @@ const BENIGN = /\b(in\s+order\s+(to|for)|sort\s+order|order\s+by|ordered\s+list|
const AMOUNT = /[$€£₹¥]\s?\d|\b\d[\d,.]*\s?(usd|eur|gbp|inr|jpy|dollars?|euros?|rupees?|pounds?)\b/i;
const MOVES_MONEY = /\b(send|transfer|give|confirm|complete|submit|request|withdraw|deposit|pay|tip|donate)\b/i;
-/** The paying/buying/ordering words found in `value` (intent or on-screen text), lower case ("amount": money with a verb that moves it). */
-export function riskyWords(value) {
+/** Words that also name everyday work ("the address book", "transfer the file"): they count in on-screen text and page titles, not in the agent's intent. */
+const SCREEN_ONLY_WORDS = new Set(["book", "book now", "reserve", "rent", "tip", "bid", "place bid", "upgrade", "renew", "transfer"]);
+
+/**
+ * The paying/buying/ordering words found in `value`, lower case ("amount": money with a verb that moves it).
+ * `from`: "screen" (on-screen text, page titles; the default) or "intent" (the agent's own words: SCREEN_ONLY_WORDS left out).
+ */
+export function riskyWords(value, from = "screen") {
if (typeof value !== "string" || !value) return [];
const textValue = value.replace(BENIGN, " ");
const found = new Set();
const re = new RegExp(RISKY_RE.source, "giu");
let m;
- while ((m = re.exec(textValue)) !== null) found.add(m[2].toLowerCase().replace(/\s+/g, " "));
+ while ((m = re.exec(textValue)) !== null) { const word = m[2].toLowerCase().replace(/\s+/g, " "); if (from !== "intent" || !SCREEN_ONLY_WORDS.has(word)) found.add(word); }
if (AMOUNT.test(textValue) && MOVES_MONEY.test(textValue)) found.add("amount");
return [...found];
}
@@ -340,14 +346,16 @@ export function looksLikeCredential(value) {
* looks like a credential, or an intent that says so); plus an act outside
* the approved window, which a session never does (acts go to the approved
* window, other apps need their own open consent). With ASK_SEND_DELETE
- * (or options.sendDelete) also OS-read send/permanent-delete targets and
- * the Shift+Delete / Cmd+Backspace chords;
+ * (or options.sendDelete) also OS-read send/permanent-delete targets, the
+ * Shift+Delete / Cmd+Backspace chords and Enter (or Ctrl/Cmd+Enter) right
+ * after typing in the window;
* - auto: never.
* In every mode the open-session consent, the deny list, hit-testing, the
* indicator and Stop still apply.
* `input`: { mode, action, intent, target: { text, secure }, window: { id,
- * app_id, title }, approved: { window_id, app_id } } (target.text undefined:
- * the host reads no text there). `options`: { sendDelete }.
+ * app_id, title }, approved: { window_id, app_id }, typed_before } (target.text
+ * undefined: the host reads no text there; typed_before: the agent's last act
+ * in this window typed text). `options`: { sendDelete }.
* Returns { ask, reasons: [{ code, detail? }] }.
*/
export function actApproval(input = {}, options = {}) {
@@ -361,7 +369,7 @@ export function actApproval(input = {}, options = {}) {
const window = isRecord(input.window) ? input.window : null;
const key = action.type === "key" ? String(action.key ?? "").toLowerCase() : "";
const mods = new Set(Array.isArray(action.modifiers) ? action.modifiers : []);
- const intentWords = riskyWords(input.intent);
+ const intentWords = riskyWords(input.intent, "intent");
if (intentWords.length) reasons.push({ code: "risky_intent", detail: intentWords.join(", ") });
// Clicks, and Enter or Space on the focused control (no modifiers).
const presses = ["click", "double_click", "right_click", "drag"].includes(action.type) || ((key === "enter" || key === "space") && mods.size === 0);
@@ -373,6 +381,8 @@ export function actApproval(input = {}, options = {}) {
if (sendDelete && typeof target.text === "string" && (SEND_TARGET.test(target.text) || DELETE_TARGET.test(target.text))) reasons.push({ code: "send_delete_target", detail: target.text.slice(0, 80) });
}
if (sendDelete && action.type === "key" && ((mods.has("shift") && key === "delete") || (mods.has("meta") && (key === "backspace" || key === "delete")))) reasons.push({ code: "delete_chord" });
+ // Enter (or Ctrl/Cmd+Enter) right after the agent typed in this window sends a chat message or an e-mail.
+ if (sendDelete && key === "enter" && input.typed_before === true && [...mods].every((m) => m === "ctrl" || m === "meta")) reasons.push({ code: "send_after_typing" });
if (action.type === "type") {
if (target.secure === true) reasons.push({ code: "secure_field" });
if (looksLikeCredential(action.text)) reasons.push({ code: "credential_text" });
@@ -391,6 +401,7 @@ export const ASK_REASONS = Object.freeze({
risky_page: "The page looks like a checkout or payment page",
send_delete_target: "The target looks like a button that sends, posts or deletes for good",
delete_chord: "The shortcut deletes for good.",
+ send_after_typing: "It would press Enter right after typing, which may send what was typed.",
secure_field: "It would type into a password field.",
credential_text: "The text looks like a password or key.",
credential_intent: "The agent says it is typing a password, code or key.",
diff --git a/apps/server/src/computer-use/shared/portable-host.mjs b/apps/server/src/computer-use/shared/portable-host.mjs
index 2d796654..de47c04a 100644
--- a/apps/server/src/computer-use/shared/portable-host.mjs
+++ b/apps/server/src/computer-use/shared/portable-host.mjs
@@ -384,7 +384,7 @@ export async function createPortableHost({ native: firstNative, nativeFactory =
if (compare.stale) return finish({ ...common, ok: false, code: "stale_observation", message: "The window changed since the observation. Observe again.", next: "computer_observe" });
}
// Per-action approval by permission mode (host channel, never the engine's).
- const decision = actApproval({ mode: settings()?.mode, action, intent: args.intent, target: await targetAt(observed, action, current, s), window: { id: String(current.id), app_id: current.appId, title: current.title }, approved: s.approved });
+ const decision = actApproval({ mode: settings()?.mode, action, intent: args.intent, target: await targetAt(observed, action, current, s), window: { id: String(current.id), app_id: current.appId, title: current.title }, approved: s.approved, typed_before: s.typedIn === String(current.id) });
let approval = { asked: false };
if (decision.ask) {
// The same action with the same intent, allowed a moment ago (a retry after a fresh observation), is not asked again.
@@ -427,6 +427,9 @@ export async function createPortableHost({ native: firstNative, nativeFactory =
// Typing goes to the control the last click focused: its secure-field check reads this point.
if (["click", "double_click"].includes(action.type) && mapped.length === 1) s.focusPoint = { window: String(current.id), screen: mapped[0].screen };
else if (action.type === "key" && String(action.key).toLowerCase() === "tab") s.focusPoint = null;
+ // Typing arms "Enter right after typing" (the send/delete switch); a click or Enter disarms it.
+ if (action.type === "type") s.typedIn = String(current.id);
+ else if (["click", "double_click"].includes(action.type) || (action.type === "key" && String(action.key).toLowerCase() === "enter")) s.typedIn = null;
const cursorAfter = await native.call("cursor").catch(() => null);
const done = { ...common, approval, point, path, cursor_before: cursorBefore, cursor_after: cursorAfter, ok: true, may_have_acted: action.type !== "wait" };
if (!args.observe_after) return finish({ ...done, next: "computer_observe" });