repositories / pi-ext

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)

+61 / −10 text lines

Diff layout

extensions/ui/__tests__/extension-ui.test.ts

Modified

+18 / −0 text lines

6767 ).toMatchObject({
6868 type: "ui_status",
6969 requestId: "s1",
70 message: "gpt-5 high",
7071 statusKey: "model-info",
7172 statusText: "gpt-5 high",
7273 });
7374 });
76 it("keeps status clears empty instead of rendering setStatus", () => {
77 expect(
78 extensionUiEventFromRequest({
79 type: "extension_ui_request",
80 id: "s2",
81 method: "setStatus",
82 statusKey: "vcs",
83 statusText: undefined,
84 }),
85 ).toMatchObject({
86 type: "ui_status",
87 requestId: "s2",
88 message: "",
89 statusKey: "vcs",
90 });
91 });
7593 it("creates response commands for values, confirmations, and cancellations", () => {
7694 expect(extensionUiResponseCommand("u1", { value: "a" })).toEqual({
7795 type: "extension_ui_response",

extensions/ui/__tests__/rendering.test.ts

Modified

+7 / −0 text lines

3636 const js = renderAppJs();
3737 expect(js).toContain("event.streamId");
3838 expect(js).toContain("replaceWith(row)");
39 expect(js).toContain("finalizeStreamingRows()");
40 });
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'");
3946 });
4148 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({
1919 command: "cmd.exe",
2020 args: ["/d", "/s", "/c", "pi.cmd", "--mode", "rpc"],
21 windowsHide: true,
2122 });
2223 expect(rpcSpawnPlan("pi", ["--mode", "rpc"], "linux")).toEqual({
2324 command: "pi",
2425 args: ["--mode", "rpc"],
26 windowsHide: false,
2527 });
2628 });

extensions/ui/__tests__/runtime.test.ts

Modified

+3 / −2 text lines

1212 expect(
1313 openerCandidates("http://x", { platform: "win32", env: {} })[0],
1414 ).toEqual({
15 command: "cmd.exe",
16 args: ["/c", "start", "", "http://x"],
15 command: "explorer.exe",
16 args: ["http://x"],
17 windowsHide: true,
1718 });
1819 expect(
1920 openerCandidates("http://x", { platform: "darwin", env: {} })[0],

extensions/ui/extension-ui.ts

Modified

+1 / −0 text lines

128128 fields: Record<string, unknown>,
129129): string {
130130 if (typeof fields.statusText === "string") return fields.statusText;
131 if (method === "setStatus") return "";
131132 if (typeof fields.title === "string") return fields.title;
132133 return method;

extensions/ui/open.ts

Modified

+13 / −3 text lines

11import { spawn } from "node:child_process";
22import { uiError } from "./errors";
4export type OpenerCandidate = {
5 command: string;
6 args: string[];
7 windowsHide?: boolean;
8};
9
410export function openerCandidates(
511 url: string,
612 options: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv } = {},
7): Array<{ command: string; args: string[] }> {
13): OpenerCandidate[] {
814 const platform = options.platform ?? process.platform;
915 const env = options.env ?? process.env;
1016 if (env.TERMUX_VERSION) return [{ command: "termux-open-url", args: [url] }];
1117 if (platform === "darwin") return [{ command: "open", args: [url] }];
1218 if (platform === "win32") {
13 return [{ command: "cmd.exe", args: ["/c", "start", "", url] }];
19 return [{ command: "explorer.exe", args: [url], windowsHide: true }];
1420 }
1521 return [
1622 { command: "xdg-open", args: [url] },
3945function trySpawn(command: string, args: string[]): Promise<boolean> {
4046 return new Promise((resolve) => {
41 const child = spawn(command, args, { detached: true, stdio: "ignore" });
47 const child = spawn(command, args, {
48 detached: true,
49 stdio: "ignore",
50 windowsHide: true,
51 });
4252 let settled = false;
4353 const done = (ok: boolean) => {
4454 if (settled) return;

extensions/ui/rpc.ts

Modified

+8 / −2 text lines

4545export type RpcSpawnPlan = {
4646 command: string;
4747 args: string[];
48 windowsHide?: boolean;
4849};
5051type Pending = {
7980 cwd: options.cwd,
8081 env: { ...process.env, ...options.env },
8182 stdio: "pipe",
83 windowsHide: spawnPlan.windowsHide,
8284 });
8385 const pending = new Map<string, Pending>();
8486 const stderrChunks: string[] = [];
183185 platform: NodeJS.Platform = process.platform,
184186): RpcSpawnPlan {
185187 if (platform === "win32" && command.toLowerCase().endsWith(".cmd")) {
186 return { command: "cmd.exe", args: ["/d", "/s", "/c", command, ...args] };
188 return {
189 command: "cmd.exe",
190 args: ["/d", "/s", "/c", command, ...args],
191 windowsHide: true,
192 };
187193 }
188 return { command, args };
194 return { command, args, windowsHide: platform === "win32" };
191197function defaultPiBin(): string {

extensions/ui/web/app.js.ts

Modified

+9 / −3 text lines

9191 if (!synthetic && event.id <= lastEventId) continue;
9292 if (!synthetic) lastEventId = event.id;
9393 applyInternalEvent(event);
94 if (event.type === 'message' && event.role === 'user') finalizeStreamingRows();
9495 if (!isStreamEvent(event)) continue;
9596 const row = document.createElement('article');
9697 row.className = 'ui-event ui-event-' + (event.role || event.type);
134135function updateMetaStatus(event) {
135136 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 || '';
138 if (!key) return;
139 if (!value) statusItems.delete(String(key));
140 else statusItems.set(String(key), String(value));
139141 renderMetaStatus();
144function finalizeStreamingRows() {
145 for (const row of stream.querySelectorAll('[data-stream-id]')) delete row.dataset.streamId;
146}
142148function renderMetaStatus() {
143149 const digest = document.querySelector('#ui-digest');
144150 const rows = [...statusItems.entries()].slice(-6);