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.
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import { describe, it, expect, beforeEach } from "vitest";
|
|
import { cachedDetect, cachedModels, clearProviderCache, dropPlaceholder } from "../../daemon/src/providers/infoCache.js";
|
|
import type { Provider } from "../../daemon/src/providers/types.js";
|
|
|
|
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
function slowProvider(id: string, counter: { detect: number; models: number }): Provider {
|
|
return {
|
|
id,
|
|
name: id,
|
|
capabilities: { resume: false, interrupt: true, steer: false, images: false, plan: false, questions: false, cost: false, effort: [], modes: ["default"] },
|
|
async detect() { counter.detect++; await sleep(200); return { available: true }; },
|
|
async listModels() { counter.models++; await sleep(200); return [{ id: "m1", name: "M1" }]; },
|
|
async createSession() { throw new Error("unused"); },
|
|
} as Provider;
|
|
}
|
|
|
|
beforeEach(() => clearProviderCache());
|
|
|
|
describe("Provider info cache", () => {
|
|
it("second detection/model fetch hits the cache", async () => {
|
|
const c = { detect: 0, models: 0 };
|
|
const p = slowProvider("slow", c);
|
|
await cachedDetect(p);
|
|
await cachedModels(p);
|
|
const t0 = Date.now();
|
|
await cachedDetect(p);
|
|
await cachedModels(p);
|
|
expect(Date.now() - t0).toBeLessThan(50);
|
|
expect(c).toEqual({ detect: 1, models: 1 });
|
|
});
|
|
|
|
it("concurrent requests run only once", async () => {
|
|
const c = { detect: 0, models: 0 };
|
|
const p = slowProvider("conc", c);
|
|
await Promise.all([cachedModels(p), cachedModels(p), cachedModels(p)]);
|
|
expect(c.models).toBe(1);
|
|
});
|
|
|
|
it("detects again after clearProviderCache", async () => {
|
|
const c = { detect: 0, models: 0 };
|
|
const p = slowProvider("clr", c);
|
|
await cachedDetect(p);
|
|
clearProviderCache();
|
|
await cachedDetect(p);
|
|
expect(c.detect).toBe(2);
|
|
});
|
|
|
|
it("a model list with only a default placeholder counts as empty", () => {
|
|
expect(dropPlaceholder([{ id: "default", name: "默认", isDefault: true }])).toEqual([]);
|
|
expect(dropPlaceholder([{ id: "gpt", name: "GPT" }])).toHaveLength(1);
|
|
});
|
|
});
|