agent-console 1.3.5: Windows reconnect, per-provider model refresh, Magpie per-agent filter (#786)

agent-console 1.3.5: Windows reconnect through wails.localhost (Windows, http, no port only), model picker refresh keyed on a per-provider fingerprint of magpie's and the agent's own files, Magpie per-agent model filter, explicit picks forced past the snapshot, gateway URL anchored after the port.

Reviewed at 44661c8 on mote (fresh HOME, npm ci --ignore-scripts, Node 22): npm run check ok; vitest 535 passed, 17 skipped, 1 known flake also on main 749e9dd1 (claude-cli mid-turn CLI crash, manager.ts lastTurnStatus before idle); verify:build byte for byte; hostile wails.localhost and gateway URLs rejected on win32/darwin/linux; each of 17 new guards broken by hand turned its test red. PR CI green.
This commit is contained in:
qingnian108
2026-11-06 16:43:09 +08:00
committed by GitHub
parent 749e9dd12a
commit 856ad934a2
28 changed files with 1231 additions and 346 deletions
@@ -1,18 +1,20 @@
// Self-heal after the plugin host restarts (Magpie restarts its Bun plugin host from time to time; the old host's daemon exits with it
// and the gate key / port change). This page was opened by the gate with the Magpie plugin page URL in the fragment (#t=…&b=…).
// When the daemon can't be reached for a few seconds, the page goes back to that Magpie page: boot.js reads the fresh session.js and
// opens the new gate, which starts a new daemon. Only a loopback Magpie plugin page URL is ever followed (no open redirect),
// opens the new gate, which starts a new daemon. Only a Magpie plugin page URL on loopback or exact wails.localhost is ever followed (no open redirect),
// and the token is never put anywhere but this page's own fragment.
/** The same check as lib/gate.mjs safeBackUrl: http(s), loopback host, no credentials, /_magpie/plugin/<id>/[page/]index.html */
export function safeBackUrl(raw: string | null | undefined): string | null {
/** Same check as lib/gate.mjs safeBackUrl: http(s), loopback or exact wails.localhost, no credentials, /_magpie/plugin/<id>/[page/]index.html */
export function safeBackUrl(raw: string | null | undefined, ua = typeof navigator !== "undefined" ? navigator.userAgent : ""): string | null {
if (typeof raw !== "string" || !raw || raw.length > 2048) return null;
let u: URL;
try { u = new URL(raw); } catch { return null; }
if (u.protocol !== "http:" && u.protocol !== "https:") return null;
if (u.username || u.password) return null;
const host = u.hostname.toLowerCase();
if (host !== "127.0.0.1" && host !== "localhost" && host !== "[::1]") return null;
const loopback = host === "127.0.0.1" || host === "localhost" || host === "[::1]";
const magpieWin = /Windows/.test(ua) && host === "wails.localhost" && u.protocol === "http:" && u.port === "";
if (!loopback && !magpieWin) return null;
if (!/^\/_magpie\/plugin\/[A-Za-z0-9_-]{1,128}\/(?:page\/)?index\.html$/.test(u.pathname)) return null;
return `${u.protocol}//${u.host}${u.pathname}${u.search}`;
}