Computer use for the Pi coding agent — Windows apps, browsers and desktops through native UI trees, screenshots and real input.
TypeScript accessibilityagent-toolsai-agentbrowser-automationcomputer-usecuadesktop-automationelectronpipi-coding-agentpi-extensionpi-packageplaywrighttypescriptui-automationvisionwebview2windowswindows-automationwsl
fix: Delete's force option resolves through the IDE and malformed addresses refuse (LPT-934)
alexshpunt-clanker[bot]93625d988717
diff --git a/src/computer-resources.ts b/src/computer-resources.tsindex ae0c702..dc6bc0c 100644--- a/src/computer-resources.ts+++ b/src/computer-resources.ts@@ -128,7 +128,7 @@ function openTarget(command: Record<string, unknown>, where: string): string | {return { path: command.path, args: args as string[], ...(command.debugging ? { debugging: true } : {}) };}/** The Delete option that kills the process of a hung window the session opened instead of asking it to close. */-const FORCE = "?force=true";+export const FORCE = "?force=true";const FILE_ACTIONS = ["put", "get", "files", "clipboard_read", "clipboard_write", "record_start", "record_stop", "audio_record"];/** Speech in a WAV file as text, with faster-whisper run through uv on the agent's own machine. */async function transcribe(wav: string): Promise<{ text: string; language: string; segments: { start: number; end: number; text: string }[] }> {@@ -1368,7 +1368,10 @@ export class ComputerResources {/** Parse a tool-owned path without allowing an unknown computer URI to fall through to files. */export function requireComputerAddress(source: string): ComputerAddress {- const address = parseComputerAddress(source);+ let address;+ // A malformed address is a refused request: nothing was sent anywhere.+ try { address = parseComputerAddress(source); }+ catch (error) { throw new ComputerRequestError(error instanceof Error ? error.message : String(error)); }if (!address) throw new ComputerRequestError("Not a computer resource.");return address;}diff --git a/src/provider.ts b/src/provider.tsindex 716bc14..e516cdd 100644--- a/src/provider.ts+++ b/src/provider.ts@@ -5,7 +5,7 @@ import { connectTextEditorPlugin, TEXT_EDITOR_PROTOCOL, TEXT_EDITOR_API_VERSIONimport type { ResourceResolver } from "pi-agent-ide/api/resource";import { connectAgentDocumentation } from "pi-agent-ide/api/documentation";import { readFile } from "node:fs/promises";-import { ComputerResources, computerResultText, ComputerRequestError, LOCAL_MACHINE, type SandboxFactory, type MachineFactory } from "./computer-resources.ts";+import { ComputerResources, computerResultText, ComputerRequestError, FORCE, LOCAL_MACHINE, type SandboxFactory, type MachineFactory } from "./computer-resources.ts";import { computerSource, displaySource, type ComputerAddress } from "./computer-address.ts";import type { WebLogEntry } from "./web-browser.ts";import { diffIsEmpty, type PixelReport, type StateDiff } from "./successor.ts";@@ -396,7 +396,7 @@ export async function computerAction(resources: ComputerResources, source: strinexport function deleteComputer(resources: ComputerResources, source: string, input: Record<string, unknown>, cwd: string, signal?: AbortSignal) {return computerAction(resources, source, "close", () => {if (Object.keys(input).some(key => key !== "path")) throw new ComputerRequestError("Delete of a computer address takes only its path; it closes the whole resource.");- return resources.address(source.replace(/\?force=true$/, ""));+ return resources.address(source.endsWith(FORCE) ? source.slice(0, -FORCE.length) : source);}, () => resources.delete(source, cwd, signal));}/** A receipt whose window, sandbox and observation addresses are this run's short aliases. */@@ -430,7 +430,8 @@ export async function registerComputerProvider(pi: ExtensionAPI, getSession: (cwasync tryResolve(source) {if (!owns(source)) return { kind: "not-handled" };try {- const address = resources.address(source);+ // Delete's force option is not part of the address; Delete itself checks where it applies.+ const address = resources.address(source.endsWith(FORCE) ? source.slice(0, -FORCE.length) : source);return { kind: "resolved", resource: { source, skipPostEdit: true,// An expired reference still resolves, so Write/Insert reach the handler and return a refused receipt.read: async () => {diff --git a/test/computer-tools.test.ts b/test/computer-tools.test.tsindex 9999445..b862d5c 100644--- a/test/computer-tools.test.ts+++ b/test/computer-tools.test.ts@@ -74,6 +74,8 @@ test("Delete reports a window that stays open and refuses what it cannot close",// Force kills only processes this session started.expect((await kept.remove(`computer:window/${ref}?force=true`)).summary).toContain("Only windows this session opened can be force-closed");expect((await kept.remove("computer:machine/local?force=true")).summary).toContain("?force=true applies to window addresses only.");+ // A malformed address is refused before anything is sent, like an invalid field.+ expect((await kept.remove("computer:display/primary")).script).toMatchObject({ outcome: "refused", effect: "not-applied" });expect((await kept.remove("computer:machine/local/windows")).summary).toContain("Delete closes a window, a sandbox or isolated session, a machine or computer:session.");// Safe mode closes only windows this session opened, like any other input.diff --git a/test/extension-modes.integration.test.ts b/test/extension-modes.integration.test.tsindex bcbd89e..ba6e69b 100644--- a/test/extension-modes.integration.test.ts+++ b/test/extension-modes.integration.test.ts@@ -42,6 +42,7 @@ test("without Pi Agent IDE, tool_search finds the deferred computer tools and thfor (const tool of ["computer_open", "computer_window", "computer_display", "computer_delete"]) expect(getToolResultText(result, "find")).toContain(tool);// A typed tool refuses a bad address with a receipt before any native work.expect(getToolExecution(result, "display").isError).toBe(true);+ expect(getToolResultText(result, "display")).not.toContain("unknown");expect(getToolResultText(result, "display")).toContain("Display addresses name their machine");expect(getToolResultText(result, "delete")).toContain("Computer closed");expect(getToolResultText(result, "guide")).toMatch(/^# Computer resources/);@@ -65,8 +66,11 @@ test("with Pi Agent IDE, computer use extends Read, Search, Insert and Delete an{ id: "find", name: "tool_search", arguments: { query: "computer read windows displays" } },{ id: "session", name: "read", arguments: { path: "computer:session" } },{ id: "close", name: "insert", arguments: { path: "computer:session", text: '{"action":"close"}' } },+ { id: "force", name: "delete", arguments: { path: "computer:machine/local?force=true" } },{ id: "delete", name: "delete", arguments: { path: "computer:session" } },]);+ // The force option reaches computer use through the IDE's resolver, which then refuses it for a machine.+ expect(getToolResultText(result, "force")).toContain("?force=true applies to window addresses only.");expect(getToolResultText(result, "find")).not.toContain("computer_read");expect(getToolResultText(result, "find")).not.toContain("computer_delete");for (const tool of ["computer_open", "computer_window", "computer_display"]) expect(getToolResultText(result, "find")).toContain(tool);diff --git a/test/unified-tools.integration.test.ts b/test/unified-tools.integration.test.tsindex b3f7bdd..0762d7d 100644--- a/test/unified-tools.integration.test.ts+++ b/test/unified-tools.integration.test.ts@@ -30,7 +30,7 @@ test("production Pi exposes only computer tools, with no direct or Codemode brow],}).run("Check the production loadout. Only discover apps; never open a window or send input.");// Without Pi Agent IDE, production computer use offers deferred tools that tool_search loads.- const standalone = ["computer_insert", "computer_read", "computer_search", "computer_write"];+ const standalone = ["computer_delete", "computer_display", "computer_insert", "computer_open", "computer_read", "computer_search", "computer_window", "computer_write"];expect(getToolExecutionDetails(getToolExecution(result, "registry"))).toEqual({names: standalone,exposure: Object.fromEntries(standalone.map(name => [name, "deferred"])),