5ff277349c
- 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.
184 lines
7.0 KiB
TypeScript
184 lines
7.0 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import * as fs from "node:fs/promises";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { createTools, type ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
|
|
import { removeWithRetries } from "@oh-my-pi/pi-utils";
|
|
|
|
function createTestSession(cwd = "/tmp/test", overrides: Partial<ToolSession> = {}): ToolSession {
|
|
return {
|
|
cwd,
|
|
hasUI: true,
|
|
getSessionFile: () => null,
|
|
getSessionSpawns: () => "*",
|
|
settings: Settings.isolated({ "astGrep.enabled": true, "tools.xdev": false }),
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("ast_grep parse errors", () => {
|
|
it("reports parse errors for the searched file", async () => {
|
|
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ast-grep-parse-"));
|
|
try {
|
|
const filePath = path.join(tempDir, "broken.ts");
|
|
await Bun.write(filePath, "export function broken( { return 1; }");
|
|
|
|
const tools = await createTools(createTestSession(tempDir));
|
|
const tool = tools.find(entry => entry.name === "ast_grep");
|
|
expect(tool).toBeDefined();
|
|
|
|
const result = await tool!.execute("ast-grep-parse", {
|
|
pat: "someUnlikelyCall($A)",
|
|
path: filePath,
|
|
});
|
|
|
|
const text = result.content.find(content => content.type === "text")?.text ?? "";
|
|
const details = result.details as { parseErrors?: string[]; matchCount?: number } | undefined;
|
|
|
|
expect(details?.matchCount).toBe(0);
|
|
expect(text).toContain("No matches found");
|
|
expect(text).toContain("Parse issues mean the query may be mis-scoped");
|
|
expect(details?.parseErrors).toHaveLength(1);
|
|
expect(details?.parseErrors?.[0]).toContain("broken.ts: parse error (syntax tree contains error nodes)");
|
|
expect(details?.parseErrors?.[0]).not.toContain("someUnlikelyCall($A):");
|
|
expect(text.match(/parse error \(syntax tree contains error nodes\)/g)?.length ?? 0).toBe(1);
|
|
} finally {
|
|
await removeWithRetries(tempDir);
|
|
}
|
|
});
|
|
it("caps parseErrors at PARSE_ERRORS_LIMIT and records the original total", async () => {
|
|
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ast-grep-parse-cap-"));
|
|
try {
|
|
const fileCount = 35;
|
|
for (let i = 0; i < fileCount; i++) {
|
|
await Bun.write(path.join(tempDir, `broken-${i}.ts`), "export function broken( { return 1; }");
|
|
}
|
|
|
|
const tools = await createTools(createTestSession(tempDir));
|
|
const tool = tools.find(entry => entry.name === "ast_grep");
|
|
expect(tool).toBeDefined();
|
|
|
|
const result = await tool!.execute("ast-grep-parse-cap", {
|
|
pat: "someUnlikelyCall($A)",
|
|
path: tempDir,
|
|
});
|
|
|
|
const text = result.content.find(content => content.type === "text")?.text ?? "";
|
|
const details = result.details as
|
|
| { parseErrors?: string[]; parseErrorsTotal?: number; matchCount?: number }
|
|
| undefined;
|
|
|
|
expect(details?.matchCount).toBe(0);
|
|
expect(details?.parseErrors?.length).toBe(20);
|
|
expect(details?.parseErrorsTotal).toBe(fileCount);
|
|
expect(text).toContain(`Parse issues (20 / ${fileCount}):`);
|
|
} finally {
|
|
await removeWithRetries(tempDir);
|
|
}
|
|
});
|
|
it("combines globbing from path and glob parameters", async () => {
|
|
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ast-grep-glob-"));
|
|
try {
|
|
const packagesDir = path.join(tempDir, "packages");
|
|
const sourceDir = path.join(packagesDir, "pkg-123", "src");
|
|
const nestedDir = path.join(sourceDir, "nested");
|
|
await fs.mkdir(nestedDir, { recursive: true });
|
|
await Bun.write(path.join(sourceDir, "root.ts"), "const providerOptions = {};\n");
|
|
await Bun.write(path.join(nestedDir, "child.ts"), "const providerOptions = { nested: true };\n");
|
|
await Bun.write(path.join(sourceDir, "ignore.js"), "const providerOptions = {};\n");
|
|
await Bun.write(path.join(tempDir, "outside.ts"), "const providerOptions = {};\n");
|
|
|
|
const tools = await createTools(createTestSession(tempDir));
|
|
const tool = tools.find(entry => entry.name === "ast_grep");
|
|
expect(tool).toBeDefined();
|
|
|
|
const result = await tool!.execute("ast-grep-glob", {
|
|
pat: "providerOptions",
|
|
path: `${packagesDir}/pkg-*/src/**/*.ts`,
|
|
});
|
|
|
|
const text = result.content.find(content => content.type === "text")?.text ?? "";
|
|
const details = result.details as { matchCount?: number; fileCount?: number } | undefined;
|
|
|
|
// Multi-level tree output: `# packages/pkg-…/src/`, `## root.ts#<hash>`, then a
|
|
// nested `## nested/` directory with `### child.ts#<hash>` under it.
|
|
expect(text).toMatch(/^## root\.ts#[0-9A-F]{4}/m);
|
|
expect(text).toMatch(/^### child\.ts#[0-9A-F]{4}/m);
|
|
expect(text).not.toContain("ignore.js");
|
|
expect(text).not.toContain("outside.ts");
|
|
expect(details?.matchCount).toBe(2);
|
|
expect(details?.fileCount).toBe(2);
|
|
} finally {
|
|
await removeWithRetries(tempDir);
|
|
}
|
|
});
|
|
|
|
it("keeps multi-target paging globally ordered without truncating match totals", async () => {
|
|
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ast-grep-multi-page-"));
|
|
try {
|
|
const earlyDir = path.join(tempDir, "a");
|
|
const lateDir = path.join(tempDir, "z");
|
|
await fs.mkdir(earlyDir, { recursive: true });
|
|
await fs.mkdir(lateDir, { recursive: true });
|
|
await Bun.write(
|
|
path.join(earlyDir, "a.ts"),
|
|
Array.from({ length: 8 }, () => "const sharedSymbol = 1;").join("\n"),
|
|
);
|
|
await Bun.write(
|
|
path.join(lateDir, "z.ts"),
|
|
Array.from({ length: 8 }, () => "const sharedSymbol = 1;").join("\n"),
|
|
);
|
|
|
|
const tools = await createTools(createTestSession(tempDir));
|
|
const tool = tools.find(entry => entry.name === "ast_grep");
|
|
expect(tool).toBeDefined();
|
|
|
|
const result = await tool!.execute("ast-grep-multi-page", {
|
|
pat: "sharedSymbol",
|
|
path: `${earlyDir};${lateDir}`,
|
|
page: 2,
|
|
pageSize: 10,
|
|
});
|
|
const text = result.content.find(content => content.type === "text")?.text ?? "";
|
|
const details = result.details as
|
|
| { matchCount?: number; hasMore?: boolean; page?: number; pageSize?: number }
|
|
| undefined;
|
|
|
|
expect(details?.matchCount).toBe(16);
|
|
expect(details?.hasMore).toBe(false);
|
|
expect(details?.page).toBe(2);
|
|
expect(details?.pageSize).toBe(10);
|
|
expect(text).toContain("Page 2 of 2");
|
|
expect(text).toContain("a.ts");
|
|
expect(text).toContain("z.ts");
|
|
} finally {
|
|
await removeWithRetries(tempDir);
|
|
}
|
|
});
|
|
|
|
it("parses PlusCal content through the tlaplus language aliases", async () => {
|
|
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ast-grep-pluscal-"));
|
|
try {
|
|
const filePath = path.join(tempDir, "algo.tla");
|
|
await Bun.write(
|
|
filePath,
|
|
"---- MODULE Algo ----\n(*--algorithm Demo\nvariables x = 0;\nbegin\n x := x + 1;\nend algorithm;*)\n====\n",
|
|
);
|
|
const tools = await createTools(createTestSession(tempDir));
|
|
const tool = tools.find(entry => entry.name === "ast_grep");
|
|
expect(tool).toBeDefined();
|
|
|
|
const result = await tool!.execute("ast-grep-pluscal", {
|
|
pat: "x",
|
|
path: filePath,
|
|
lang: "pluscal",
|
|
});
|
|
const details = result.details as { matchCount?: number } | undefined;
|
|
expect(details?.matchCount).toBeGreaterThan(0);
|
|
} finally {
|
|
await removeWithRetries(tempDir);
|
|
}
|
|
});
|
|
});
|