repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

Put ui URL in widget

5a0d549c7a1207b520ae49076d9796b118e664c1

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

extensions/ui/__tests__/harness.test.ts

Modified
1 1 import path from "node:path";
2 2 import { afterEach, describe, expect, it } from "vitest";
3 3 import { createTestSession, type TestSession } from "../../../test/harness";
4 +import { notifyUrl } from "../index";
6 +describe("ui notifications", () => {
7 + it("omits token params from notification URLs", () => {
8 + expect(notifyUrl("http://127.0.0.1:123/?token=abc")).toBe(
9 + "http://127.0.0.1:123/",
10 + );
11 + });
12 +});
5 14 describe("ui pi-test-harness", () => {
6 15 let t: TestSession | undefined;

extensions/ui/__tests__/terminal-widget.test.ts

Modified
26 26 const text = lines.join("\n");
27 - expect(lines).toHaveLength(8);
27 + const visibleText = text.replace(OSC8_RE, "");
28 + expect(lines).toHaveLength(9);
28 29 expect(lines[0]).toMatch(/^┏━+┓$/);
29 30 expect(lines.at(-1)).toMatch(/^┗━+┛$/);
30 31 expect(lines.slice(1, -1).every((line) => /^┃.*┃$/.test(line))).toBe(true);
31 32 expect(new Set(lines.map((line) => visibleLength(line))).size).toBe(1);
32 33 expect(text).toContain("pi ui");
34 + expect(visibleText).toContain("url: http://127.0.0.1:123/");
35 + expect(visibleText).not.toContain("token=abc");
33 36 expect(text).toContain("connected");
34 37 expect(text).toContain("ui: pi-ext");
35 38 expect(text).toContain("press ESC to stop");

extensions/ui/index.ts

Modified
5 5 ExtensionContext,
6 6 } from "@earendil-works/pi-coding-agent";
7 7 import { matchesKey } from "@earendil-works/pi-tui";
8 -import { humanError, redactToken, type UiError, uiError } from "./errors";
8 +import { humanError, type UiError, uiError } from "./errors";
9 9 import { createUiRuntime, type UiRuntime } from "./runtime";
10 10 import type { UiSeedSessionManager } from "./session-seed";
11 11 import { createVisualTools } from "./visual-tools";
41 41 if (runtime) {
42 42 setWidget(ctx);
43 43 ctx.ui.notify(
44 - `ui already active: ${redactToken(runtime.status().url ?? "")}`,
44 + `ui already active: ${notifyUrl(runtime.status().url ?? "")}`,
45 45 "info",
47 47 return;
65 65 : undefined;
66 66 setWidget(ctx);
67 - ctx.ui.notify(
68 - `ui open: ${redactToken(runtime.status().url ?? "")}`,
69 - "info",
70 - );
67 + ctx.ui.notify(`ui open: ${notifyUrl(runtime.status().url ?? "")}`, "info");
73 70 pi.registerCommand("ui", {
117 114 const current = runtime.status();
118 115 ctx.ui.notify(
119 - `ui ${current.state}: ${redactToken(current.url ?? "")}`,
116 + `ui ${current.state}: ${notifyUrl(current.url ?? "")}`,
120 117 "info",
122 119 setWidget(ctx);
140 137 return `ui: ${name || "session"}`;
140 +export function notifyUrl(value: string): string {
141 + if (!value) return "";
142 + const url = new URL(value);
143 + url.search = "";
144 + url.hash = "";
145 + return url.toString();
143 148 function inactiveError(): UiError {
144 149 return uiError("runtime_not_active", "UI runtime is not active", {
145 150 action: "Run /ui first.",

extensions/ui/terminal-widget.ts

Modified
27 27 const rows = [
28 28 "pi ui",
29 29 osc8Link(state.url, "open browser ui"),
30 + `url: ${urlWithoutParams(state.url)}`,
30 31 `session: ${state.sessionLabel}`,
31 32 `state: ${state.state} · clients: ${state.clients} · rpc: ${state.rpcState ?? "not-started"}`,
32 33 `file: ${session}`,
67 68 function visibleLength(content: string): number {
68 69 return content.replace(OSC8_RE, "").length;
72 +function urlWithoutParams(value: string): string {
73 + const url = new URL(value);
74 + url.search = "";
75 + url.hash = "";
76 + return url.toString();