pi-ext
bugabingas pi extensions
owned by bugabinga
Simplify ui status and windows launch
0d0532ee757cf86f634366c8e3f4fb8be1a7fbba
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
Browse filesCompare with HEAD
Changed files (8)
extensions/ui/__tests__/extension-ui.test.ts
Modified+18 / −0 text lines
6767 ).toMatchObject({ ).toMatchObject({ 6868 type: "ui_status", type: "ui_status", 6969 requestId: "s1", requestId: "s1", 70+ message: "gpt-5 high", 7071 statusKey: "model-info", statusKey: "model-info", 7172 statusText: "gpt-5 high", statusText: "gpt-5 high", 76+ it("keeps status clears empty instead of rendering setStatus", () => { 78+ extensionUiEventFromRequest({ 79+ type: "extension_ui_request", 83+ statusText: undefined, 7593 it("creates response commands for values, confirmations, and cancellations", () => { it("creates response commands for values, confirmations, and cancellations", () => { 7694 expect(extensionUiResponseCommand("u1", { value: "a" })).toEqual({ expect(extensionUiResponseCommand("u1", { value: "a" })).toEqual({ 7795 type: "extension_ui_response", type: "extension_ui_response", extensions/ui/__tests__/rendering.test.ts
Modified+7 / −0 text lines
3636 const js = renderAppJs(); const js = renderAppJs(); 3737 expect(js).toContain("event.streamId"); expect(js).toContain("event.streamId"); 3838 expect(js).toContain("replaceWith(row)"); expect(js).toContain("replaceWith(row)"); 39+ expect(js).toContain("finalizeStreamingRows()"); 42+ it("clears empty extension status instead of showing method names", () => { 43+ const js = renderAppJs(); 44+ expect(js).toContain("statusItems.delete(String(key))"); 45+ expect(js).not.toContain("key + ': ' + 'setStatus'"); 4148 it("does not locally echo submitted prompts", () => { it("does not locally echo submitted prompts", () => { extensions/ui/__tests__/rpc.test.ts
Modified+2 / −0 text lines
1818 expect(rpcSpawnPlan("pi.cmd", ["--mode", "rpc"], "win32")).toEqual({ expect(rpcSpawnPlan("pi.cmd", ["--mode", "rpc"], "win32")).toEqual({ 1919 command: "cmd.exe", command: "cmd.exe", 2020 args: ["/d", "/s", "/c", "pi.cmd", "--mode", "rpc"], args: ["/d", "/s", "/c", "pi.cmd", "--mode", "rpc"], 2223 expect(rpcSpawnPlan("pi", ["--mode", "rpc"], "linux")).toEqual({ expect(rpcSpawnPlan("pi", ["--mode", "rpc"], "linux")).toEqual({ 2324 command: "pi", command: "pi", 2425 args: ["--mode", "rpc"], args: ["--mode", "rpc"], extensions/ui/__tests__/runtime.test.ts
Modified+3 / −2 text lines
1313 openerCandidates("http://x", { platform: "win32", env: {} })[0], openerCandidates("http://x", { platform: "win32", env: {} })[0], 1414 ).toEqual({ ).toEqual({ 16- args: ["/c", "start", "", "http://x"], 15+ command: "explorer.exe", 1920 openerCandidates("http://x", { platform: "darwin", env: {} })[0], openerCandidates("http://x", { platform: "darwin", env: {} })[0], extensions/ui/extension-ui.ts
Modified+1 / −0 text lines
128128 fields: Record<string, unknown>, fields: Record<string, unknown>, 129129): string {): string { 130130 if (typeof fields.statusText === "string") return fields.statusText; if (typeof fields.statusText === "string") return fields.statusText; 131+ if (method === "setStatus") return ""; 131132 if (typeof fields.title === "string") return fields.title; if (typeof fields.title === "string") return fields.title; 132133 return method; return method; extensions/ui/open.ts
Modified+13 / −3 text lines
11import { spawn } from "node:child_process";import { spawn } from "node:child_process"; 22import { uiError } from "./errors";import { uiError } from "./errors"; 4+export type OpenerCandidate = { 7+ windowsHide?: boolean; 410export function openerCandidates(export function openerCandidates( 511 url: string, url: string, 612 options: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv } = {}, options: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv } = {}, 7-): Array<{ command: string; args: string[] }> { 13+): OpenerCandidate[] { 814 const platform = options.platform ?? process.platform; const platform = options.platform ?? process.platform; 915 const env = options.env ?? process.env; const env = options.env ?? process.env; 1016 if (env.TERMUX_VERSION) return [{ command: "termux-open-url", args: [url] }]; if (env.TERMUX_VERSION) return [{ command: "termux-open-url", args: [url] }]; 1117 if (platform === "darwin") return [{ command: "open", args: [url] }]; if (platform === "darwin") return [{ command: "open", args: [url] }]; 1218 if (platform === "win32") { if (platform === "win32") { 13- return [{ command: "cmd.exe", args: ["/c", "start", "", url] }]; 19+ return [{ command: "explorer.exe", args: [url], windowsHide: true }]; 1622 { command: "xdg-open", args: [url] }, { command: "xdg-open", args: [url] }, 3945function trySpawn(command: string, args: string[]): Promise<boolean> {function trySpawn(command: string, args: string[]): Promise<boolean> { 4046 return new Promise((resolve) => { return new Promise((resolve) => { 41- const child = spawn(command, args, { detached: true, stdio: "ignore" }); 47+ const child = spawn(command, args, { 4252 let settled = false; let settled = false; 4353 const done = (ok: boolean) => { const done = (ok: boolean) => { 4454 if (settled) return; if (settled) return; extensions/ui/rpc.ts
Modified+8 / −2 text lines
4545export type RpcSpawnPlan = {export type RpcSpawnPlan = { 4646 command: string; command: string; 4747 args: string[]; args: string[]; 48+ windowsHide?: boolean; 5051type Pending = {type Pending = { 7980 cwd: options.cwd, cwd: options.cwd, 8081 env: { ...process.env, ...options.env }, env: { ...process.env, ...options.env }, 8182 stdio: "pipe", stdio: "pipe", 83+ windowsHide: spawnPlan.windowsHide, 8385 const pending = new Map<string, Pending>(); const pending = new Map<string, Pending>(); 8486 const stderrChunks: string[] = []; const stderrChunks: string[] = []; 183185 platform: NodeJS.Platform = process.platform, platform: NodeJS.Platform = process.platform, 184186): RpcSpawnPlan {): RpcSpawnPlan { 185187 if (platform === "win32" && command.toLowerCase().endsWith(".cmd")) { if (platform === "win32" && command.toLowerCase().endsWith(".cmd")) { 186- return { command: "cmd.exe", args: ["/d", "/s", "/c", command, ...args] }; 190+ args: ["/d", "/s", "/c", command, ...args], 188- return { command, args }; 194+ return { command, args, windowsHide: platform === "win32" }; 191197function defaultPiBin(): string {function defaultPiBin(): string { extensions/ui/web/app.js.ts
Modified+9 / −3 text lines
9191 if (!synthetic && event.id <= lastEventId) continue; if (!synthetic && event.id <= lastEventId) continue; 9292 if (!synthetic) lastEventId = event.id; if (!synthetic) lastEventId = event.id; 9393 applyInternalEvent(event); applyInternalEvent(event); 94+ if (event.type === 'message' && event.role === 'user') finalizeStreamingRows(); 9495 if (!isStreamEvent(event)) continue; if (!isStreamEvent(event)) continue; 9596 const row = document.createElement('article'); const row = document.createElement('article'); 9697 row.className = 'ui-event ui-event-' + (event.role || event.type); row.className = 'ui-event ui-event-' + (event.role || event.type); 134135function updateMetaStatus(event) {function updateMetaStatus(event) { 135136 const key = event.statusKey || event.key || event.requestId; const key = event.statusKey || event.key || event.requestId; 136- const value = event.statusText || event.text || event.message || ''; 137- if (!key || !value) return; 138- statusItems.set(String(key), String(value)); 137+ const value = event.statusText || event.text || ''; 139+ if (!value) statusItems.delete(String(key)); 140+ else statusItems.set(String(key), String(value)); 139141 renderMetaStatus(); renderMetaStatus(); 144+function finalizeStreamingRows() { 145+ for (const row of stream.querySelectorAll('[data-stream-id]')) delete row.dataset.streamId; 142148function renderMetaStatus() {function renderMetaStatus() { 143149 const digest = document.querySelector('#ui-digest'); const digest = document.querySelector('#ui-digest'); 144150 const rows = [...statusItems.entries()].slice(-6); const rows = [...statusItems.entries()].slice(-6);