Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

fix(web): keep count badges only on Crons and Apps (#1385)

Regan Bell3c8ac28c1831
diff --git a/plugins/web-ui/src/session-scope.ts b/plugins/web-ui/src/session-scope.ts
index e77a343af..4d103928e 100644
--- a/plugins/web-ui/src/session-scope.ts
+++ b/plugins/web-ui/src/session-scope.ts
@@ -42,11 +42,6 @@ const TOOL_COUNTERS: Partial<Record<SessionTool, (scope: string) => Promise<numb
}
return count;
},
- files: async (scope) => {
- const q = new URLSearchParams({ limit: "100", scope });
- const r = await api<{ owned?: unknown[]; shared?: unknown[] }>(`/api/files?${q.toString()}`);
- return (r.owned?.length ?? 0) + (r.shared?.length ?? 0);
- },
apps: async (scope) => {
const r = await api<{ deployments?: Array<{ status?: string; ownerScopeId?: string; createdInScope?: string }> }>(
"/api/deployments",
@@ -55,10 +50,6 @@ const TOOL_COUNTERS: Partial<Record<SessionTool, (scope: string) => Promise<numb
(d) => d.status !== "archived" && (d.createdInScope === scope || d.ownerScopeId === scope),
).length;
},
- skills: async (scope) => {
- const r = await api<{ skills?: Array<{ scopeId?: string; status?: string }> }>("/api/skills?includeShadowed=1");
- return (r.skills ?? []).filter((sk) => sk.scopeId === scope && sk.status !== "archived").length;
- },
};
/** Cached count of a tool's items in a scope; kicks off a refresh and calls
@@ -133,7 +124,7 @@ export function sessionTopbarTpl(o: SessionTopbarOpts): TemplateResult {
}
`;
const tool = (t: SessionTool, glyph: Parameters<typeof icon>[0], hint: string) => {
- const count = o.toolCount?.(t) ?? null;
+ const count = t === "crons" || t === "apps" ? (o.toolCount?.(t) ?? null) : null;
return html`
<button
class="session-tool ${o.activeTool === t ? "active" : ""}"
@@ -147,7 +138,7 @@ export function sessionTopbarTpl(o: SessionTopbarOpts): TemplateResult {
`;
};
const sheetTool = (t: SessionTool, glyph: Parameters<typeof icon>[0], hint: string) => {
- const count = o.toolCount?.(t) ?? null;
+ const count = t === "crons" || t === "apps" ? (o.toolCount?.(t) ?? null) : null;
return html`
<button
class="menu-option ${o.activeTool === t ? "active" : ""}"
@@ -188,7 +179,7 @@ export function sessionTopbarTpl(o: SessionTopbarOpts): TemplateResult {
: html`<div class="session-heading">${heading}</div>`
}
<div class="topbar-actions session-tools">
- ${tool("crons", Clock3, "Crons")} ${tool("files", Files, "Files")} ${tool("apps", Rocket, "Apps")}
+ ${tool("crons", Clock3, "Crons")} ${tool("apps", Rocket, "Apps")} ${tool("files", Files, "Files")}
${tool("skills", Box, "Skills")} ${tool("memory", Brain, "Memory")}
${tool("keychain", KeyRound, "Your keychain")}
</div>
@@ -205,8 +196,8 @@ export function sessionTopbarTpl(o: SessionTopbarOpts): TemplateResult {
</button>
<div class="menu-popover" role="menu" hidden>
<div class="menu-title">This conversation's workspace</div>
- ${sheetTool("crons", Clock3, "Crons")} ${sheetTool("files", Files, "Files")}
- ${sheetTool("apps", Rocket, "Apps")} ${sheetTool("skills", Box, "Skills")}
+ ${sheetTool("crons", Clock3, "Crons")} ${sheetTool("apps", Rocket, "Apps")}
+ ${sheetTool("files", Files, "Files")} ${sheetTool("skills", Box, "Skills")}
${sheetTool("memory", Brain, "Memory")} ${sheetTool("keychain", KeyRound, "Your keychain")}
</div>
</div>
diff --git a/plugins/web-ui/src/split.ts b/plugins/web-ui/src/split.ts
index 283bcb8d3..e67ad1a61 100644
--- a/plugins/web-ui/src/split.ts
+++ b/plugins/web-ui/src/split.ts
@@ -873,8 +873,8 @@ function paneCrumb(panel: IDockviewPanel): string | null {
const PANE_TOOLS: { tool: SessionTool; glyph: Parameters<typeof icon>[0]; label: string }[] = [
{ tool: "crons", glyph: Clock3, label: "Crons" },
- { tool: "files", glyph: Files, label: "Files" },
{ tool: "apps", glyph: Rocket, label: "Apps" },
+ { tool: "files", glyph: Files, label: "Files" },
{ tool: "skills", glyph: Box, label: "Skills" },
{ tool: "memory", glyph: Brain, label: "Memory" },
{ tool: "keychain", glyph: KeyRound, label: "Your keychain" },
diff --git a/plugins/web-ui/test/session-scope.test.ts b/plugins/web-ui/test/session-scope.test.ts
new file mode 100644
index 000000000..040886b60
--- /dev/null
+++ b/plugins/web-ui/test/session-scope.test.ts
@@ -0,0 +1,154 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { stripTypeScriptTypes } from "node:module";
+import test from "node:test";
+import { runInNewContext } from "node:vm";
+import { JSDOM } from "jsdom";
+import type { SessionTool, SessionTopbarOpts } from "../src/session-scope.ts";
+
+const source = readFileSync(new URL("../src/session-scope.ts", import.meta.url), "utf8");
+const dom = new JSDOM("<!doctype html><body></body>");
+for (const [key, value] of Object.entries({
+ document: dom.window.document,
+ HTMLElement: dom.window.HTMLElement,
+ customElements: dom.window.customElements,
+}))
+ Object.defineProperty(globalThis, key, { configurable: true, value });
+const { html, nothing, render } = await import("lit");
+
+function load(api: (path: string) => Promise<unknown> = async () => ({})) {
+ return runInNewContext(
+ stripTypeScriptTypes(
+ source.replace(/^import .*;\n/gm, "").replace(/^export /gm, "") + "\n({ scopeToolCount, sessionTopbarTpl });",
+ ),
+ {
+ api,
+ html,
+ nothing,
+ icon: () => nothing,
+ tip: () => nothing,
+ closeFormMenus: () => {},
+ toggleFormMenu: () => {},
+ ...Object.fromEntries(
+ ["ArrowUpLeft", "Box", "Brain", "Clock3", "Ellipsis", "Files", "GitFork", "KeyRound", "Rocket"].map((name) => [
+ name,
+ name,
+ ]),
+ ),
+ },
+ ) as {
+ scopeToolCount: (tool: SessionTool, scope: string, ready: () => void) => number | null;
+ sessionTopbarTpl: (opts: SessionTopbarOpts) => ReturnType<typeof html>;
+ };
+}
+
+test("only Crons and Apps request counts; both count past 100", async () => {
+ const requests: string[] = [];
+ const crons = Array.from({ length: 137 }, (_, i) => ({
+ id: String(i),
+ ownerScopeId: "personal:test",
+ enabled: true,
+ }));
+ const deployments = Array.from({ length: 151 }, (_, i) => ({
+ id: String(i),
+ ownerScopeId: "personal:test",
+ status: "ready",
+ }));
+ const { scopeToolCount } = load(async (path) => {
+ requests.push(path);
+ return path === "/api/crons"
+ ? {
+ crons: [
+ ...crons,
+ { id: "disabled", ownerScopeId: "personal:test", enabled: false },
+ { id: "archived", ownerScopeId: "personal:test", enabled: true, archived: true },
+ { id: "other", ownerScopeId: "other", enabled: true },
+ ],
+ visible: crons,
+ }
+ : {
+ deployments: [
+ ...deployments,
+ { id: "archived", ownerScopeId: "personal:test", status: "archived" },
+ { id: "other", ownerScopeId: "other", status: "ready" },
+ ],
+ };
+ });
+ for (const tool of ["files", "skills", "memory", "keychain"] as const) {
+ assert.equal(
+ scopeToolCount(tool, "personal:test", () => assert.fail("unexpected refresh")),
+ null,
+ );
+ }
+ assert.deepEqual(requests, []);
+ for (const [tool, count] of [
+ ["crons", 137],
+ ["apps", 151],
+ ] as const) {
+ await new Promise<void>((resolve) => {
+ assert.equal(scopeToolCount(tool, "personal:test", resolve), null);
+ });
+ assert.equal(
+ scopeToolCount(tool, "personal:test", () => assert.fail("cached count")),
+ count,
+ );
+ }
+ assert.deepEqual(requests, ["/api/crons", "/api/deployments"]);
+});
+
+test("desktop and mobile put Crons and Apps first and badge only those tools", () => {
+ const { sessionTopbarTpl } = load();
+ const host = document.createElement("div");
+ const queried: string[] = [];
+ const clicked: string[] = [];
+ render(
+ sessionTopbarTpl({
+ crumb: null,
+ title: "Test",
+ onTool: (tool) => clicked.push(tool),
+ toolCount: (tool) => {
+ queried.push(tool);
+ return tool === "crons" ? 137 : 151;
+ },
+ }),
+ host,
+ );
+ const desktop = [...host.querySelectorAll<HTMLButtonElement>(".session-tools button")];
+ const mobile = [...host.querySelectorAll<HTMLButtonElement>(".menu-option")];
+ assert.deepEqual(
+ desktop.map((button) => button.getAttribute("aria-label")),
+ ["Crons", "Apps", "Files", "Skills", "Memory", "Your keychain"],
+ );
+ assert.deepEqual(
+ mobile.map((button) => button.querySelector(".menu-option-label")?.textContent),
+ ["Crons", "Apps", "Files", "Skills", "Memory", "Your keychain"],
+ );
+ for (const buttons of [desktop, mobile]) {
+ assert.deepEqual(
+ buttons.map((button) => button.querySelector(".session-tool-count")?.textContent ?? null),
+ ["137", "151", null, null, null, null],
+ );
+ for (const button of buttons) button.click();
+ }
+ assert.deepEqual(queried, ["crons", "apps", "crons", "apps"]);
+ assert.deepEqual(clicked, [
+ "crons",
+ "apps",
+ "files",
+ "skills",
+ "memory",
+ "keychain",
+ "crons",
+ "apps",
+ "files",
+ "skills",
+ "memory",
+ "keychain",
+ ]);
+});
+
+test("zero counts remain hidden in desktop and mobile tools", () => {
+ const host = document.createElement("div");
+ render(load().sessionTopbarTpl({ crumb: null, title: "Test", onTool: () => {}, toolCount: () => 0 }), host);
+ assert.equal(host.querySelectorAll(".session-tool-count").length, 0);
+});
diff --git a/plugins/web-ui/test/single-view-navigation.test.ts b/plugins/web-ui/test/single-view-navigation.test.ts
index accc2a8c1..edac7dd28 100644
--- a/plugins/web-ui/test/single-view-navigation.test.ts
+++ b/plugins/web-ui/test/single-view-navigation.test.ts
@@ -134,7 +134,7 @@ test("single and multiview headers render mutually exclusive tools and pane cont
},
paneScopeId: () => null,
paneKindEntry: () => null,
- PANE_TOOLS: ["Crons", "Files", "Apps", "Skills", "Memory", "Your keychain"].map((label) => ({
+ PANE_TOOLS: ["Crons", "Apps", "Files", "Skills", "Memory", "Your keychain"].map((label) => ({
label,
tool: label,
glyph: label,
@@ -176,3 +176,11 @@ test("single and multiview headers render mutually exclusive tools and pane cont
assert.equal(actions.menuOpen, false);
assert.doesNotMatch(output, /split-tools-btn|role="menu"|Close pane/);
});
+
+test("single-pane toolbar and split menu put Crons and Apps first", () => {
+ const tools = split.slice(split.indexOf("const PANE_TOOLS:"), split.indexOf("function openPaneTool"));
+ assert.deepEqual(
+ [...tools.matchAll(/tool: "([^"]+)"/g)].map((match) => match[1]),
+ ["crons", "apps", "files", "skills", "memory", "keychain"],
+ );
+});