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.
79 lines
3.1 KiB
TypeScript
79 lines
3.1 KiB
TypeScript
// P1-1: projects/threads/fs methods and store behavior
|
|
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
import { mkdtempSync, mkdirSync, writeFileSync, rmSync, existsSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { ProjectsStore } from "../../daemon/src/store/projects.js";
|
|
import { ThreadsStore } from "../../daemon/src/store/threads.js";
|
|
import { SettingsStore } from "../../daemon/src/store/settings.js";
|
|
|
|
let dir = "";
|
|
let projDir = "";
|
|
let projects: ProjectsStore;
|
|
let threads: ThreadsStore;
|
|
|
|
beforeAll(() => {
|
|
dir = mkdtempSync(join(tmpdir(), "ac-p1-"));
|
|
projDir = join(dir, "proj");
|
|
mkdirSync(projDir, { recursive: true });
|
|
projects = new ProjectsStore(dir);
|
|
threads = new ThreadsStore(dir);
|
|
});
|
|
|
|
afterAll(() => {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("projects", () => {
|
|
it("create/dup/rename/remove", async () => {
|
|
const p = await projects.create(projDir);
|
|
expect(p.id).toMatch(/^p_/);
|
|
expect(p.name).toBe("proj");
|
|
const dup = await projects.create(projDir);
|
|
expect(dup.id).toBe(p.id); // A duplicate path returns the existing one
|
|
const r = await projects.rename(p.id, " 新名字 ");
|
|
expect(r.name).toBe("新名字");
|
|
await projects.remove(p.id);
|
|
expect(await projects.get(p.id)).toBeNull();
|
|
});
|
|
it("nonexistent path → bad_path", async () => {
|
|
await expect(projects.create(join(dir, "nope"))).rejects.toThrow(/不存在/);
|
|
});
|
|
});
|
|
|
|
describe("threads", () => {
|
|
it("create/get/patch/append/readEvents/delete→trash", async () => {
|
|
const p = await projects.create(projDir);
|
|
const t = await threads.create({ projectId: p.id, provider: "mock" });
|
|
expect(t.status).toBe("idle");
|
|
const t2 = await threads.patch(t.id, { title: "改名", pinned: true });
|
|
expect(t2.title).toBe("改名");
|
|
expect(t2.titleAuto).toBe(false);
|
|
await threads.appendEvent(t.id, { seq: 1, ts: Date.now(), threadId: t.id, type: "user_message", text: "hi" });
|
|
await threads.appendEvent(t.id, { seq: 2, ts: Date.now(), threadId: t.id, turnId: "u_1", type: "turn_ended", status: "completed" });
|
|
const ev = await threads.readEvents(t.id);
|
|
expect(ev.length).toBe(2);
|
|
expect((await threads.get(t.id))?.seq).toBe(2);
|
|
// afterSeq filtering
|
|
const ev2 = await threads.readEvents(t.id, 1);
|
|
expect(ev2.length).toBe(1);
|
|
// Delete → moved to trash
|
|
await threads.delete(t.id);
|
|
expect(await threads.get(t.id)).toBeNull();
|
|
expect(existsSync(join(dir, "trash", "threads"))).toBe(true);
|
|
await projects.remove(p.id);
|
|
});
|
|
});
|
|
|
|
describe("settings recentDirs", () => {
|
|
it("get/set preserves unknown fields", async () => {
|
|
const s = new SettingsStore(dir);
|
|
const cur = await s.get();
|
|
expect(cur.defaultProvider).toBe("claude");
|
|
const next = await s.set({ recentDirs: ["a", "b"], weirdField: 1 } as never);
|
|
expect(next.recentDirs).toEqual(["a", "b"]);
|
|
const again = await new SettingsStore(dir).get();
|
|
expect((again as { weirdField?: number }).weirdField).toBe(1); // Unknown fields are preserved
|
|
});
|
|
});
|