Files
plugins/packages/agent-console/test/v1/fixtures/fake-dsh.mjs
T
qingnian108 a431798fe1 agent-console 1.0.0: a page plugin that drives the local Agent CLIs (#535)
Adds Agent Console (@magpie-community/page-agent-console 1.0.0), a community page plugin that drives the Agent CLIs on this computer (Claude Code, Codex, ACP agents) through a local daemon on 127.0.0.1, with its source in packages/agent-console and a registry entry. Claude Code is the user's own `claude` CLI driven over stream-json (daemon/src/providers/claude/cli.ts); no Anthropic SDK is installed, bundled or in the branch's history. Cold install ~45 MB (node-pty ~26 MB), stated in the README and registry summary in en and zh.

By qingnian108 (#535).

What was run at 8e8f910 (mote, macOS, throwaway HOME, no real accounts):
- packages/agent-console: `npm ci --ignore-scripts --workspaces=false`; `node scripts/verify-build.mjs`: all five bundles byte-identical (daemon/dist/main.js 08c95aa3…, app/app.js 9a6911f3…); `vitest run`: 45 files, 254 passed, 17 skipped; `npm run check` clean.
- Real Claude Code 2.1.316 (npm @anthropic-ai/claude-code, sandbox HOME/CLAUDE_CONFIG_DIR, local fake Messages API): `AC_REAL_CLAUDE=… vitest run --config vitest.real.config.ts test/real/claude-cli.real.test.ts`: 4 of 4 (initialize lists 51 slash commands, streaming turn, Bash permission approved and denied, interrupt, --resume with set_model).
- Probe: the driver's exact argv with `--permission-mode bypassPermissions --allow-dangerously-skip-permissions`: the tool runs with no can_use_tool request.
- Repo root: `HOME=$(mktemp -d) bun test`: 4006 tests, 0 fail; `bun scripts/check.mjs` exit 0.
- Install as magpie does: `npm pack --ignore-scripts` (552 KB) then `bun add --ignore-scripts`: 45 MB node_modules, no @anthropic-ai/*, index.mjs imports.
- Read every changed line since 41c7a94: argv values limited to SAFE_ARG tokens (no cmd.exe metacharacters reach the shim path), no new network hosts, no install scripts, no eval; no commit in main..8e8f910 contains claude-agent-sdk.

Not tried: magpie's desktop window loading the page; a Windows .cmd/.ps1 claude shim end to end.
2026-10-31 20:11:22 +08:00

67 lines
3.6 KiB
JavaScript

// Behaves like `dsh --profile acp` (0.2.1-rc.5) where images are concerned, for tests. Calls no model.
// - The route it starts on is its `acp` row: deepseek-official / deepseek-v4-flash, or the provider/model of a `--patch` file.
// - initialize advertises promptCapabilities.image only when that route sees images (FAKE_DSH_VISION: comma list of provider/model).
// - session/new reports the model option as dsh does: values are JSON [provider, model].
// - A prompt with an image block on a connection that didn't advertise images is refused with dsh's error.
// FAKE_ACP_LOG file each received {argv, prompt} is appended to, one JSON line per prompt
import { appendFileSync, readFileSync } from "node:fs";
import { createInterface } from "node:readline";
const argv = process.argv.slice(2);
let route = ["deepseek-official", "deepseek-v4-flash"];
for (let i = 0; i < argv.length; i++) {
if (argv[i] !== "--patch") continue;
const y = readFileSync(argv[i + 1], "utf8");
const provider = /^\s+provider: (.+)$/m.exec(y)?.[1];
const model = /^\s+model: (.+)$/m.exec(y)?.[1];
if (/^- id: acp$/m.test(y) && provider && model) route = [JSON.parse(provider), JSON.parse(model)];
}
const vision = new Set((process.env.FAKE_DSH_VISION ?? "").split(",").filter(Boolean));
const image = vision.has(route.join("/"));
const models = [["deepseek-official", "deepseek-flash"], ["magpie", "vis"], ["magpie", "txt"]];
let current = route;
const logFile = process.env.FAKE_ACP_LOG;
const out = (msg) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...msg }) + "\n");
const answer = (id, result) => out({ id, result });
const configOptions = () => [{
id: "model", category: "model", type: "select", name: "Model", currentValue: JSON.stringify(current),
options: models.map(([p, m]) => ({ value: JSON.stringify([p, m]), name: m })),
}];
createInterface({ input: process.stdin }).on("line", (line) => {
let m;
try { m = JSON.parse(line); } catch { return; }
if (!m.method) return;
const p = m.params ?? {};
switch (m.method) {
case "initialize":
return answer(m.id, {
protocolVersion: 1,
agentInfo: { name: "deepseek-harness-acp", version: "0.0.1" },
agentCapabilities: { loadSession: false, promptCapabilities: { image, audio: false, embeddedContext: false }, sessionCapabilities: { close: {}, list: {}, resume: {} } },
authMethods: [],
});
case "session/new":
return answer(m.id, { sessionId: "fake-dsh-1", configOptions: configOptions() });
case "session/resume":
return answer(m.id, { configOptions: configOptions() });
case "session/load":
return out({ id: m.id, error: { code: -32601, message: '"Method not found": session/load' } });
case "session/set_config_option":
if (p.configId === "model") current = JSON.parse(p.value);
return answer(m.id, { configOptions: configOptions() });
case "session/prompt": {
if (logFile) appendFileSync(logFile, JSON.stringify({ argv, prompt: p.prompt }) + "\n");
if (!image && p.prompt.some((b) => b.type === "image")) {
return out({ id: m.id, error: { code: -32602, message: "Invalid params: inline image prompts were not advertised by this connection" } });
}
out({ method: "session/update", params: { sessionId: p.sessionId, update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "ok" } } } });
return answer(m.id, { stopReason: "end_turn" });
}
case "session/cancel":
return;
default:
if (m.id !== undefined) out({ id: m.id, error: { code: -32601, message: `method not found: ${m.method}` } });
}
});