681d7daf65
- Replaced the separate GUI-linked pi_natives.desktop.linux-x64 addon with a pure-Rust X11 backend (x11rb RustConnection capture via RandR/GetImage, XTest input with keysym mapping) compiled into the core addon on every published target; Linux arm64 and musl are now supported and headless hosts load the addon unaffected. - Removed the native-desktop-linux cargo feature, desktop_unsupported.rs, lazy desktop loader, second napi build, desktop packaging/CI steps, GUI build dependencies, and the now-unreferenced vendored libspa crate; reverted setup-system-deps to main. - Preserved the desktop input hardening semantics on the unified backend: XTest layouts reject negative origins and coordinates beyond 0..=32767, batch coordinates stay bound to the frame last returned to JS with intermediate screenshots deferred, coordinate input requires a previously returned frame, and failed chord releases still release every held key. - Enforced a 60s worker-side execute deadline (DESKTOP_DEADLINE_EXCEEDED): no input is emitted after expiry and wait-heavy batches are rejected upfront. - Added int32 fail-closed validation for coordinates, drag points, and scroll deltas at the JS ingress and gateway schema. - Exposed computer to models without native OpenAI computer-use support as a regular function tool with a typed GA action schema across OpenAI, Azure, and Codex Responses providers, including named forced choice. - Added the /computer slash command (on/off/status/toggle) for session-only enablement via runtime tool registration in SessionTools. - Updated docs, changelogs, and contract tests accordingly.
76 lines
3.4 KiB
TypeScript
76 lines
3.4 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { AuthStorage } from "@oh-my-pi/pi-ai";
|
|
import { getBundledModel } from "@oh-my-pi/pi-catalog/models";
|
|
import { ModelRegistry } from "@oh-my-pi/pi-coding-agent/config/model-registry";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { createAgentSession } from "@oh-my-pi/pi-coding-agent/sdk";
|
|
import type { AgentSession } from "@oh-my-pi/pi-coding-agent/session/agent-session";
|
|
import { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
import { removeSyncWithRetries, Snowflake } from "@oh-my-pi/pi-utils";
|
|
|
|
// Guards the /computer session-scoped toggle mechanism: createTools derives the
|
|
// built-in slate once at session start, so with `computer.enabled=false` the
|
|
// computer tool is entirely absent from the registry. `setComputerToolEnabled`
|
|
// must re-derive that one entry through the SDK-provided factory and flip the
|
|
// active slate for the next turn — without persisting anything. Constructing
|
|
// the tool is inert (the desktop worker only spawns on first execute), so this
|
|
// runs headless.
|
|
describe("AgentSession.setComputerToolEnabled", () => {
|
|
let registryDir: string;
|
|
let authStorage: AuthStorage;
|
|
let modelRegistry: ModelRegistry;
|
|
const sessions: AgentSession[] = [];
|
|
|
|
beforeAll(async () => {
|
|
registryDir = path.join(os.tmpdir(), `pi-computer-toggle-${Snowflake.next()}`);
|
|
fs.mkdirSync(registryDir, { recursive: true });
|
|
authStorage = await AuthStorage.create(path.join(registryDir, "auth.db"));
|
|
modelRegistry = new ModelRegistry(authStorage);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
for (const session of sessions) await session.dispose().catch(() => {});
|
|
authStorage.close();
|
|
if (fs.existsSync(registryDir)) removeSyncWithRetries(registryDir);
|
|
});
|
|
|
|
it("flips the active tool slate on enable and disable, session-only", async () => {
|
|
const settings = Settings.isolated({});
|
|
const { session } = await createAgentSession({
|
|
cwd: registryDir,
|
|
agentDir: registryDir,
|
|
modelRegistry,
|
|
sessionManager: SessionManager.inMemory(),
|
|
settings,
|
|
model: getBundledModel("openai", "gpt-4o-mini"),
|
|
disableExtensionDiscovery: true,
|
|
});
|
|
sessions.push(session);
|
|
|
|
// computer.enabled defaults to false: absent from registry and slate.
|
|
expect(session.getAllToolNames()).not.toContain("computer");
|
|
expect(session.getActiveToolNames()).not.toContain("computer");
|
|
|
|
// The /computer command's enable path: slate refresh + runtime override.
|
|
expect(await session.setComputerToolEnabled(true)).toBe(true);
|
|
session.settings.override("computer.enabled", true);
|
|
expect(session.getAllToolNames()).toContain("computer");
|
|
expect(session.getEnabledToolNames()).toContain("computer");
|
|
expect(session.settings.get("computer.enabled")).toBe(true);
|
|
|
|
// Disable removes it from the active slate but keeps the registry entry,
|
|
// so a re-enable never registers a second desktop controller.
|
|
expect(await session.setComputerToolEnabled(false)).toBe(true);
|
|
session.settings.override("computer.enabled", false);
|
|
expect(session.getEnabledToolNames()).not.toContain("computer");
|
|
expect(session.getAllToolNames()).toContain("computer");
|
|
|
|
// Re-enable reuses the retained registry entry.
|
|
expect(await session.setComputerToolEnabled(true)).toBe(true);
|
|
expect(session.getEnabledToolNames()).toContain("computer");
|
|
});
|
|
});
|