- Added the `xd://` virtual device protocol (`internal-urls/xd-protocol.ts`, `tools/xdev.ts`): tools declaring `loadMode: "discoverable"` are unmounted from the request tools array and driven via `read xd://` (list/docs+schema) and `write xd://<tool>` (execute), gated by the `tools.xdev` setting (default on) and inlined into the system prompt. - Merged the `irc`, `job`, and `launch` tools into a single `hub` tool (`tools/hub/`, `async/job-manager.ts`): messaging keeps `send`/`inbox`/`list`, job control maps to `wait`/`cancel`/`jobs`, process supervision keeps `start`/`logs`/`stop`/`restart`/`describe` with `ps`, and the unified `wait` races background jobs against peer messages; SDK `IrcTool`/`JobTool`/`LaunchTool` are replaced by `HubTool`. - Removed the hidden `resolve` tool in favor of the `xd://resolve`/`xd://reject`/`xd://propose` resolution devices, auto-including `write` whenever a deferrable tool or plan mode is present. - Removed the BM25 tool-discovery system: the `search_tool_bm25` tool, the `tool-discovery` module, the `tools.discoveryMode`/`mcp.discoveryMode`/`mcp.discoveryDefaultServers`/`tools.essentialOverride` settings, per-tool MCP selection, and the `mcp_tool_selection` message type. - Unified tool presentation on `ToolLoadMode` (`essential`|`discoverable`), replacing the custom-tool `xdev?: boolean` opt-out; custom, extension, MCP, RPC host, image-generation, and TTS tools now default to `discoverable`, and added a `satisfies` predicate to `SoftToolRequirement`. - Removed the standalone `ssh` command tool and `ssh/ssh-executor` (the `ssh://` read/write/search protocol stays), and made `--tools` address hidden built-ins. - Updated collab-web to render `xd://` dispatches and `hub` op families, dropped the `search_tool_bm25`/`ssh`/`report-finding` renderers, refreshed tool docs and prompts, and migrated the affected tests and changelogs.
95 lines
3.9 KiB
TypeScript
95 lines
3.9 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";
|
|
|
|
// Regression for issue #5305: image-gen is registered as a custom tool, and
|
|
// custom tools are force-activated regardless of the `toolNames` filter. Before
|
|
// the fix, `generate_image` survived `--no-tools` (an empty `toolNames`), any
|
|
// explicit whitelist that omitted it, and had no `generate_image.enabled`
|
|
// settings toggle. The SDK must honor the whitelist and the new setting.
|
|
describe("generate_image tool gating", () => {
|
|
let registryDir: string;
|
|
let authStorage: AuthStorage;
|
|
let modelRegistry: ModelRegistry;
|
|
const sessions: AgentSession[] = [];
|
|
|
|
beforeAll(async () => {
|
|
registryDir = path.join(os.tmpdir(), `pi-generate-image-gating-${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);
|
|
});
|
|
|
|
async function activeToolNames(settings: Settings, toolNames?: string[]): Promise<string[]> {
|
|
const { session } = await createAgentSession({
|
|
cwd: registryDir,
|
|
agentDir: registryDir,
|
|
modelRegistry,
|
|
sessionManager: SessionManager.inMemory(),
|
|
settings,
|
|
model: getBundledModel("openai", "gpt-4o-mini"),
|
|
disableExtensionDiscovery: true,
|
|
toolNames,
|
|
});
|
|
sessions.push(session);
|
|
return session.getActiveToolNames();
|
|
}
|
|
|
|
it("excludes generate_image from a restricted tool whitelist", async () => {
|
|
const names = await activeToolNames(Settings.isolated({}), ["read"]);
|
|
expect(names).toContain("read");
|
|
expect(names).not.toContain("generate_image");
|
|
});
|
|
|
|
it("excludes generate_image under --no-tools (empty whitelist)", async () => {
|
|
const names = await activeToolNames(Settings.isolated({}), []);
|
|
expect(names).not.toContain("generate_image");
|
|
});
|
|
|
|
it("respects generate_image.enabled=false even when requested", async () => {
|
|
const names = await activeToolNames(Settings.isolated({ "generate_image.enabled": false }), [
|
|
"read",
|
|
"generate_image",
|
|
]);
|
|
expect(names).not.toContain("generate_image");
|
|
});
|
|
|
|
it("includes generate_image when explicitly requested and enabled", async () => {
|
|
const names = await activeToolNames(Settings.isolated({}), ["read", "generate_image"]);
|
|
expect(names).toContain("generate_image");
|
|
});
|
|
|
|
it("exposes generate_image as an xd:// device (not top-level) in a default session", async () => {
|
|
// Default session (no explicit --tools) with tools.xdev on: image-gen is a
|
|
// discoverable custom tool, so it mounts as an xd:// device instead of
|
|
// shipping its schema top-level.
|
|
const { session } = await createAgentSession({
|
|
cwd: registryDir,
|
|
agentDir: registryDir,
|
|
modelRegistry,
|
|
sessionManager: SessionManager.inMemory(),
|
|
settings: Settings.isolated({}),
|
|
model: getBundledModel("openai", "gpt-4o-mini"),
|
|
disableExtensionDiscovery: true,
|
|
});
|
|
sessions.push(session);
|
|
expect(session.getActiveToolNames()).not.toContain("generate_image");
|
|
expect(session.getXdevToolEntries().map(entry => entry.name)).toContain("generate_image");
|
|
});
|
|
});
|