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/",
5 14 describe(
"ui pi-test-harness", ()
=> {
6 15 let t
: TestSession | undefined;
extensions/ui/__tests__/terminal-widget.test.ts
Modified26 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 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";
44 - `ui already active: ${redactToken(runtime.status().url ?? "")}`,
44 + `ui already active: ${notifyUrl(runtime.status().url ?? "")}`,
68 - `ui open: ${redactToken(runtime.status().url ?? "")}`,
67 + ctx.ui.
notify(
`ui open: ${notifyUrl(runtime.status().url ?? "")}`,
"info");
73 70 pi.
registerCommand(
"ui", {
117 114 const current
= runtime.
status();
119 - `ui ${current.state}: ${redactToken(current.url ?? "")}`,
116 + `ui ${current.state}: ${notifyUrl(current.url ?? "")}`,
140 137 return `ui: ${name || "session"}`;
140 +export function notifyUrl(value
: string)
: string {
141 + if (
!value)
return "";
142 + const url
= new URL(value);
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
Modified29 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);
76 + return url.
toString();