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.
113 lines
4.7 KiB
TypeScript
113 lines
4.7 KiB
TypeScript
/**
|
|
* Unified `hub` wait: one blocking primitive racing background jobs against
|
|
* incoming peer messages. These contracts are new to the merge — the halves
|
|
* (pure message wait, pure job poll) are covered by the pre-existing
|
|
* messaging/job suites.
|
|
*/
|
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
import { AsyncJobManager } from "@oh-my-pi/pi-coding-agent/async/job-manager";
|
|
import { IrcBus } from "@oh-my-pi/pi-coding-agent/irc/bus";
|
|
import { AgentRegistry } from "@oh-my-pi/pi-coding-agent/registry/agent-registry";
|
|
import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
|
|
import { type CoordinationDetails, HubTool } from "@oh-my-pi/pi-coding-agent/tools/hub";
|
|
|
|
const SELF_ID = "Main";
|
|
|
|
function makeSession(manager: AsyncJobManager | undefined): ToolSession {
|
|
const stub = {
|
|
cwd: process.cwd(),
|
|
settings: {
|
|
get(key: string): unknown {
|
|
if (key === "async.pollWaitDuration") return "5m";
|
|
if (key === "irc.timeoutMs") return 120_000;
|
|
return undefined;
|
|
},
|
|
},
|
|
agentRegistry: AgentRegistry.global(),
|
|
asyncJobManager: manager,
|
|
getAgentId: () => SELF_ID,
|
|
};
|
|
// Structurally-partial test session: HubTool only touches the fields above.
|
|
return stub as unknown as ToolSession;
|
|
}
|
|
|
|
/** Register a job that never settles on its own; returns its id + resolver. */
|
|
function registerHangingJob(manager: AsyncJobManager, label: string): { id: string; finish: (text: string) => void } {
|
|
const { promise, resolve } = Promise.withResolvers<string>();
|
|
const id = manager.register("bash", label, async () => promise, { ownerId: SELF_ID });
|
|
return { id, finish: resolve };
|
|
}
|
|
|
|
describe("hub unified wait", () => {
|
|
beforeEach(() => {
|
|
AgentRegistry.resetGlobalForTests();
|
|
IrcBus.resetGlobalForTests();
|
|
});
|
|
afterEach(() => {
|
|
AgentRegistry.resetGlobalForTests();
|
|
IrcBus.resetGlobalForTests();
|
|
});
|
|
|
|
test("an incoming message settles the wait while watched jobs keep running", async () => {
|
|
const registry = AgentRegistry.global();
|
|
registry.register({ id: SELF_ID, displayName: "main", kind: "main", session: null });
|
|
registry.register({ id: "Peer", displayName: "task", kind: "sub", parentId: SELF_ID, session: null });
|
|
|
|
const manager = new AsyncJobManager({ onJobComplete: () => {} });
|
|
const job = registerHangingJob(manager, "sleep forever");
|
|
const tool = new HubTool(makeSession(manager));
|
|
|
|
// The bus waiter is parked synchronously before execute()'s first
|
|
// suspension, so the send below cannot race the park.
|
|
const pending = tool.execute("call_1", { op: "wait" });
|
|
await IrcBus.global().send({ from: "Peer", to: SELF_ID, body: "shared file is yours" });
|
|
|
|
const result = await pending;
|
|
const details = result.details as CoordinationDetails;
|
|
expect(result.isError).not.toBe(true);
|
|
expect(details.op).toBe("wait");
|
|
expect(details.waited?.from).toBe("Peer");
|
|
expect(details.waited?.body).toBe("shared file is yours");
|
|
// The job was not consumed by the message win.
|
|
expect(manager.getJob(job.id)?.status).toBe("running");
|
|
|
|
manager.cancel(job.id);
|
|
});
|
|
|
|
test("a settling job returns the snapshot exactly like the old poll", async () => {
|
|
const registry = AgentRegistry.global();
|
|
registry.register({ id: SELF_ID, displayName: "main", kind: "main", session: null });
|
|
registry.register({ id: "Peer", displayName: "task", kind: "sub", parentId: SELF_ID, session: null });
|
|
|
|
const manager = new AsyncJobManager({ onJobComplete: () => {} });
|
|
const job = registerHangingJob(manager, "quick job");
|
|
const tool = new HubTool(makeSession(manager));
|
|
|
|
const pending = tool.execute("call_2", { op: "wait", ids: [job.id] });
|
|
job.finish("done output");
|
|
|
|
const result = await pending;
|
|
const details = result.details as CoordinationDetails;
|
|
expect(details.op).toBe("wait");
|
|
expect(details.jobs?.map(j => j.status)).toEqual(["completed"]);
|
|
expect(details.jobs?.[0]?.resultText).toBe("done output");
|
|
const text = result.content[0]?.type === "text" ? result.content[0].text : "";
|
|
expect(text).toContain("## Completed (1)");
|
|
});
|
|
|
|
test("bare wait with no jobs and no running peers returns immediately", async () => {
|
|
const registry = AgentRegistry.global();
|
|
registry.register({ id: SELF_ID, displayName: "main", kind: "main", session: null });
|
|
registry.register({ id: "Sleeper", displayName: "task", kind: "sub", session: null, status: "idle" });
|
|
|
|
const manager = new AsyncJobManager({ onJobComplete: () => {} });
|
|
const tool = new HubTool(makeSession(manager));
|
|
|
|
// A regression to a blocking message wait fails via the test timeout.
|
|
const result = await tool.execute("call_3", { op: "wait" });
|
|
const text = result.content[0]?.type === "text" ? result.content[0].text : "";
|
|
expect(text).toContain("No running background jobs to wait for.");
|
|
expect(result.useless).toBe(true);
|
|
});
|
|
});
|