Show on the desktop app's taskbar when Plan2Code needs you

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-26 06:36:45 -07:00
1 parent 765d2b3536
commit c602dfed57
25 files changed
+1038 -112

No files matched your search

+41 -1
View File
@@ -11,7 +11,7 @@ import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, windowTitleFor, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS } from "../plan2code-app/ui/meter.js";
import { attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, taskbarSwitch, windowTitleFor, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS } from "../plan2code-app/ui/meter.js";
import { findBrowser, launchBrowser } from "./browser.mjs";
const HERE = path.dirname(fileURLToPath(import.meta.url));
@@ -258,3 +258,43 @@ test("pickDefaultAgent with nothing installed returns the remembered id, else th
assert.equal(pickDefaultAgent(none, null), "claude");
assert.equal(pickDefaultAgent([], null), null);
});
test("pickDefaultAgent drops a remembered id the list no longer has, unless there is no list at all", () => {
const none = AVAIL([["claude", false], ["devin", false], ["codex", false]]);
// A custom agent deleted since: the picker could not show it, so the first entry it can.
assert.equal(pickDefaultAgent(none, "gone"), "claude");
// The availability check failed: the fixed options are on the card, the remembered id stands.
assert.equal(pickDefaultAgent([], "devin"), "devin");
});
test("the launch card shows agents.json warnings, and Check again asks for a fresh PATH", () => {
assert.match(INDEX_HTML, /<p id="launch-agents-warning" hidden><\/p>/);
assert.match(APP_JS, /invoke\('agent_availability', \{ refresh \}\)/);
assert.match(APP_JS, /async function checkAgentsAgain\(\) \{\n await loadAgentAvailability\(true\);/);
});
// The console page's taskbar messages reach the app only as one of four fixed
// words or a boolean (attention.rs decides what they mean); app.js forwards
// them through these checks and nothing else.
test("attentionSignal passes only the four favicon states, and taskbarSwitch only a boolean", () => {
for (const state of ["busy", "ready", "attention", "plain"]) {
assert.equal(attentionSignal({ plan2code: "attention", state }), state);
}
for (const data of [{ state: "Ready" }, { state: "urgent" }, { state: "" }, { state: 1 }, {}, null, undefined]) {
assert.equal(attentionSignal(data), null, `${JSON.stringify(data)} is not forwarded`);
}
assert.equal(taskbarSwitch({ on: true }), true);
assert.equal(taskbarSwitch({ on: false }), false);
for (const data of [{ on: "false" }, { on: 0 }, { on: null }, {}, null]) {
assert.equal(taskbarSwitch(data), null, `${JSON.stringify(data)} is not forwarded`);
}
});
test("app.js forwards attention and taskbar through those checks, and clears the dot on a new frame and a lost hello", () => {
assert.match(APP_JS, /const signal = attentionSignal\(event\.data\);\s+if \(signal\) invoke\('set_attention', \{ signal \}\)/);
assert.match(APP_JS, /const on = taskbarSwitch\(event\.data\);\s+if \(on === null\) return;/);
assert.match(APP_JS, /invoke\('set_taskbar_signal', \{ on \}\)/);
assert.match(APP_JS, /function loadFrame\(url\) \{[^}]*clearAttention\(\);[^}]*frame\.src = url;/);
assert.match(APP_JS, /async function onNoHello\(\) \{\s+if \(frameReady \|\| !consoleKnown \|\| restarting\) return;[\s\S]{0,120}clearAttention\(\);/);
assert.match(APP_JS, /plan2code: 'taskbar-state', on/, "the page hears the saved switch on its hello");
});
+30 -1
View File
@@ -704,6 +704,31 @@ test("launcher agents: the model menu is the agent's own models, with no shipped
assert.deepEqual(cli.args(["--model=m2", "-x"]), ["--yes", "/plan2code", "--model", "m2", "--bypass", "-x"]);
});
test("launcher agents: the menu lists the built-ins found first, then the custom agents that resolve", (t) => {
const box = sandbox(["goose", "codex", "claude"]);
t.after(box.cleanup);
const file = writeAgents(box, { schema: 1, agents: [GOOSE, { id: "ghost", name: "Ghost", command: "ghost-cmd" }] });
const { customClis, runnableClis } = require(LAUNCHER);
const realPath = process.env.PATH;
process.env.PATH = path.join(box.dir, "bin");
t.after(() => {
process.env.PATH = realPath;
});
const { installed, missing } = runnableClis(customClis(file, false));
assert.deepEqual(installed.map((cli) => cli.id), ["claude", "codex", "goose"]);
assert.deepEqual(missing.map((cli) => cli.id), ["ghost"]);
});
test("launcher agents: with no terminal to ask, a custom agent's model line names its own default", (t) => {
const box = sandbox(["goose"]);
t.after(box.cleanup);
writeAgents(box, goose());
const result = box.run(["--cli", "goose"]);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Goose will start with its own default model\. To pick one, run `plan2code --model <id>`\./);
assert.doesNotMatch(result.stdout, /last used/);
});
test("launcher agents: a custom agent whose command is not found is left out and named when nothing can run", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
@@ -769,13 +794,17 @@ test("launcher agents: a full-path command starts, and on Windows a .cmd in a fo
if (IS_WINDOWS) {
file = path.join(spaced, "spaced.cmd");
fs.writeFileSync(file, `@"${process.execPath}" "${recorder}" spaced %*\r\n`);
// A same-named file in the project folder (the launcher's cwd) must not run instead.
fs.writeFileSync(path.join(box.dir, "spaced.cmd"), `@"${process.execPath}" "${recorder}" decoy %*\r\n`);
} else {
file = path.join(spaced, "spaced");
fs.writeFileSync(file, `#!/bin/sh\nexec "${process.execPath}" "${recorder}" spaced "$@"\n`);
fs.chmodSync(file, 0o755);
}
writeAgents(box, { schema: 1, agents: [{ id: "spaced", name: "Spaced", command: file, args: ["{prompt}"] }] });
const result = box.run(["--cli", "spaced", "--note", "a b"]);
// Some shells already set the switch the launcher sets; the run starts without it.
const result = box.run(["--cli", "spaced", "--note", "a b"], { NoDefaultCurrentDirectoryInExePath: undefined });
assert.equal(result.status, 0, result.stderr);
assert.deepEqual(box.argsOf("spaced"), ["/plan2code", "--note", "a b"]);
assert.equal(box.argsOf("decoy"), null);
});
+64 -1
View File
@@ -10,7 +10,8 @@ import fs from "node:fs";
import http from "node:http";
import path from "node:path";
import { spawn } from "node:child_process";
import { CONSOLE_CLI, ENV, HOME, cli } from "./web-console-test-helpers.mjs";
import { CONSOLE_CLI, ENV, HOME, cli, until } from "./web-console-test-helpers.mjs";
import { openSession, pageSuite } from "./page-test-helpers.mjs";
import { announcePage, inAppSignal } from "../src/web-console/in-app.mjs";
// A stand-in for the app's announce endpoint: records every POST it accepts.
@@ -268,3 +269,65 @@ test("with nothing shown in the window yet, open makes the first session and ann
app.close();
}
});
// The page inside the app's frame: the taskbar's two messages. Driven in a
// real browser (page-test-helpers.mjs), with a parent that keeps every
// message posted to it.
const pages = pageSuite(test);
const FAKE_APP_FRAME = () => {
window.__toApp = [];
Object.defineProperty(window, "parent", { configurable: true, get: () => ({ postMessage: (m) => window.__toApp.push(m) }) });
};
const toApp = (s, kind) => s.page.evaluate((k) => window.__toApp.filter((m) => m.plan2code === k), kind);
const ASKING = { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }], agent: { status: "waiting" } };
test("framed, the page tells the app its state once per change, never on a redraw, and plain when it goes away", async (t) => {
const s = await openSession(await pages.browser(), { t, workflow: "implement", clock: true, payload: ASKING, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
await until(async () => (await toApp(s, "attention")).length >= 1, 5000);
assert.deepEqual((await toApp(s, "attention")).at(-1), { plan2code: "attention", state: "ready" }, "a question waiting is the person's move, as a named request");
const before = (await toApp(s, "attention")).length;
await s.page.clock.fastForward(5_000);
assert.equal((await toApp(s, "attention")).length, before, "the status line's tick redraws without telling the app again");
s.post({ settle: true, items: [{ id: "q1", status: "answered", answer: { text: "x" } }], agent: { status: "working", activity: "Task 1 of 2" } });
await until(async () => (await toApp(s, "attention")).at(-1).state !== "ready", 5000);
const states = (await toApp(s, "attention")).map((m) => m.state);
assert.ok(states.every((state) => ["busy", "ready", "attention", "plain"].includes(state)), states.join(", "));
assert.ok(states.every((state, i) => i === 0 || state !== states[i - 1]), `no state is told twice in a row: ${states.join(", ")}`);
await s.page.evaluate(() => dispatchEvent(new Event("pagehide")));
assert.deepEqual((await toApp(s, "attention")).at(-1), { plan2code: "attention", state: "plain" });
});
test("the Desktop app group shows only in the app's frame, reflects the app's saved switch and tells the app when it changes", async (t) => {
const browser = await pages.browser();
const plain = await openSession(browser, { t, workflow: "implement", payload: ASKING });
await plain.page.locator("#btn-looks").click();
assert.equal(await plain.page.locator("#looks-desktop").isVisible(), false, "not in a browser tab");
const s = await openSession(browser, { t, workflow: "implement", payload: ASKING, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
await s.page.locator("#btn-looks").click();
const box = s.page.locator("#looks-taskbar");
assert.ok(await s.page.locator("#looks-desktop").isVisible(), "shown inside the app");
assert.ok(await box.isChecked(), "on until the app says otherwise");
// The app's answer to the page's hello, from a real window standing in as
// the parent. The same answer from anywhere else is ignored.
await s.page.evaluate(() => {
const frame = document.createElement("iframe");
document.body.append(frame);
const app = frame.contentWindow;
app.postMessage = (m) => window.__toApp.push(m);
Object.defineProperty(window, "parent", { configurable: true, get: () => app });
window.__app = app;
dispatchEvent(new MessageEvent("message", { data: { plan2code: "taskbar-state", on: false }, source: window }));
});
assert.equal(await box.isChecked(), true, "a taskbar-state from anywhere but the parent changes nothing");
await s.page.evaluate(() => {
dispatchEvent(new MessageEvent("message", { data: { plan2code: "taskbar-state", on: false }, source: window.__app }));
});
assert.equal(await box.isChecked(), false, "the parent's saved value");
await box.check();
assert.deepEqual(await toApp(s, "taskbar"), [{ plan2code: "taskbar", on: true }], "a named request with one boolean");
});