page-agent-console 1.1.0: QA fixes, neutral accent, own dropdown menus, self-heal after a host restart, by qingnian108 (#569)

page-agent-console 1.1.0, by qingnian108 (#569).

QA fixes B1-B21, a reworked UI, a new logo, and self-heal after a plugin host restart. In this version:
- Accent: a fixed neutral grey (charcoal in light mode, light grey in dark mode). Magpie's accent tokens are dropped on purpose. Surfaces, text, lines, fonts and semantic colours still follow magpie.
- Every native <select> (composer effort/mode/Cursor fast, Settings, Debug) is now the page's own SelectMenu, a button plus a listbox.
- The registry summary again discloses the 127.0.0.1 service and its lifecycle, that only its own page gets the token, the ~46 MB first install, and that Claude Code isn't bundled (en, zh).
- session.js is written once at bind with beat:false, and beats every 4s only after the first /open. A new host deletes a dead host's session.js at startup (owner pid in session-owner.json, outside the page folder).
- The daemon swallows console EPIPE after a hard host kill and handles a lifeline close once.

Run at 930c6e2 on macOS (mote, Node 22), in a fresh copy:
- npm ci, then npm run check (tsc daemon + web): ok
- npx vitest run: 46 files, 288 passed, 17 skipped
- npm run verify:build: app.js, app.css, index.html and daemon/dist/main.js(.map) rebuild byte-identical
- bun scripts/check.mjs agent-console: ok
- Playwright Chromium and WebKit, light and dark, sandbox HOME, page served under /_magpie/plugin/<id>/page with a stub bridge passing accent #ff0000:
  - accent: --accent and the primary button stay grey (rgb(38,38,38) light, rgb(229,229,229) dark); no <select> anywhere.
  - Settings menus: click opens the menu inside the window; ArrowDown+Enter picks, closes and refocuses the trigger; the pick persists through the daemon.
  - Esc closes the menu, not the dialog, and then closes the dialog. Clicking an option keeps the dialog open; a click outside closes the menu.
  - A host that was never opened writes beat:false and doesn't rewrite session.js. SIGKILL it, start a new host: the stale file is removed and the page reaches the new daemon.
  - After an open, session.js beats. SIGKILL the host: the page heals in ~5.3s and stays. A daemon-only crash heals in ~5.3s.
  - Daemon logs: no uncaughtException or EPIPE, one lifeline line per daemon exit.
Not tried: the composer pickers in a browser (they need a thread with an installed agent; same SelectMenu component), magpie's real sandboxed frame, Windows and Linux.
This commit is contained in:
qingnian108
2026-11-01 00:37:07 +08:00
committed by GitHub
parent 6727a1e68c
commit 08ad5e3956
77 changed files with 3541 additions and 1251 deletions
@@ -3,6 +3,7 @@ import { execFile } from "node:child_process";
import { existsSync } from "node:fs";
import { cp, mkdir, readFile, rename, rm, stat } from "node:fs/promises";
import { join, normalize, sep } from "node:path";
import { tr } from "../util/i18n.js";
export type GitFileEntry = {
path: string;
@@ -21,7 +22,7 @@ function runGit(cwd: string, args: string[]): Promise<{ code: number; out: strin
execFile("git", ["-c", "core.quotepath=false", ...args], { cwd, timeout: TIMEOUT, maxBuffer: 8 * 1024 * 1024, windowsHide: true }, (e, stdout, stderr) => {
const code = e && typeof (e as { code?: number }).code === "number" ? (e as { code: number }).code! : e ? 1 : 0;
const missing = (e as NodeJS.ErrnoException | null)?.code === "ENOENT";
res({ code, out: String(stdout ?? ""), err: missing ? "找不到 git(请先安装 git 并加入 PATH)" : String(stderr || (e?.message ?? "")) });
res({ code, out: String(stdout ?? ""), err: missing ? tr("git.missing") : String(stderr || (e?.message ?? "")) });
});
});
}
@@ -84,18 +85,18 @@ export class GitService {
// Unified diff text; {tooLarge:true} when the diff is > 1MB
async diff(projectPath: string, p: string): Promise<{ diff?: string; tooLarge?: boolean; untracked?: boolean; error?: string }> {
const rel = insidePath(projectPath, p);
if (!rel) return { error: "路径不允许" };
if (!rel) return { error: tr("fs.pathDenied") };
// Check untracked first (git diff prints nothing for untracked files)
const ls = await runGit(projectPath, ["ls-files", "--error-unmatch", "--", rel]);
if (ls.code !== 0) {
// Untracked/not in the index: treat the whole file as added
const full = join(projectPath, rel);
if (!existsSync(full)) return { error: "文件不存在" };
if (!existsSync(full)) return { error: tr("fs.fileMissing") };
const s = await stat(full);
if (!s.isFile()) return { error: "不是文件" };
if (!s.isFile()) return { error: tr("fs.notFile") };
if (s.size > DIFF_LIMIT) return { tooLarge: true };
const text = await readFile(full, "utf8").catch(() => null);
if (text === null) return { error: "二进制或无法读取" };
if (text === null) return { error: tr("git.binary") };
const lines = text.split("\n").map((l) => "+" + l).join("\n");
return { untracked: true, diff: `--- /dev/null\n+++ b/${rel}\n@@ -0,0 +1,${text.split("\n").length} @@\n${lines}` };
}
@@ -112,9 +113,9 @@ export class GitService {
// Tracked → git restore; untracked → move to trash/discarded/<ts>/<relpath>
async discard(projectPath: string, p: string, dataDir: string): Promise<{ ok: boolean; trashedTo?: string; error?: string }> {
const rel = insidePath(projectPath, p);
if (!rel) return { ok: false, error: "路径不允许" };
if (!rel) return { ok: false, error: tr("fs.pathDenied") };
// Only discard a single file: an empty path / "." would make git restore act on the whole repository
if (rel === "." || rel === "" || rel === "./") return { ok: false, error: "路径不允许" };
if (rel === "." || rel === "" || rel === "./") return { ok: false, error: tr("fs.pathDenied") };
const ls = await runGit(projectPath, ["ls-files", "--error-unmatch", "--", rel]);
if (ls.code === 0) {
let r = await runGit(projectPath, ["restore", "--staged", "--worktree", "--", rel]);
@@ -123,7 +124,7 @@ export class GitService {
return { ok: true };
}
const full = join(projectPath, rel);
if (!existsSync(full)) return { ok: false, error: "文件不存在" };
if (!existsSync(full)) return { ok: false, error: tr("fs.fileMissing") };
const stamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
const dest = join(dataDir, "trash", "discarded", stamp, rel);
await mkdir(join(dest, ".."), { recursive: true });