repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

style(the-system): apply repository formatting

10f616b9395009cd24842d1da1d0a7731eee49f8

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

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (5)

+64 / −26 text lines

Diff layout

extensions/the-system/__e2e__/mockup.spec.ts

Modified

+3 / −1 text lines

6666 await page.getByLabel("Pin note").fill("tighten spacing");
6767 const annotationGeometry = await fragment.evaluate((element) => {
6868 const fragmentRect = element.getBoundingClientRect();
69 const bubbleRect = element.querySelector(".pin-bubble")?.getBoundingClientRect();
69 const bubbleRect = element
70 .querySelector(".pin-bubble")
71 ?.getBoundingClientRect();
7072 const pinRect = element.querySelector(".pin")?.getBoundingClientRect();
7173 return {
7274 clientWidth: element.clientWidth,

extensions/the-system/__tests__/mockup-tool.test.ts

Modified

+25 / −7 text lines

4545const roots: string[] = [];
4646afterEach(async () => {
47 await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true })));
47 await Promise.all(
48 roots.splice(0).map((root) => rm(root, { recursive: true })),
49 );
4850});
5052async function temporaryRoot(): Promise<string> {
121123 request.options[0].html,
122124 );
123125 assert.deepStrictEqual(
124 JSON.parse(await readFile(path.join(path.dirname(first), "request.json"), "utf8")),
126 JSON.parse(
127 await readFile(path.join(path.dirname(first), "request.json"), "utf8"),
128 ),
125129 request,
126130 );
127131 assert.deepStrictEqual(
128 JSON.parse(await readFile(path.join(path.dirname(first), "feedback.json"), "utf8")),
132 JSON.parse(
133 await readFile(path.join(path.dirname(first), "feedback.json"), "utf8"),
134 ),
129135 result,
130136 );
131137 const manifest = JSON.parse(await readFile(second, "utf8"));
156162 cacheManifest: "/cache/two/manifest.json",
157163 },
158164 ]);
159 assert.ok(capsule.indexOf("Current: iteration 2, accept") < capsule.indexOf("Earlier iterations"));
165 assert.ok(
166 capsule.indexOf("Current: iteration 2, accept") <
167 capsule.indexOf("Earlier iterations"),
168 );
160169 assert.match(capsule, /Selected: none/);
161170 assert.match(capsule, /never infer rejection from non-selection/);
162 assert.match(capsule, /1 iterate; selected dense \(Dense\); notes: keep density/);
171 assert.match(
172 capsule,
173 /1 iterate; selected dense \(Dense\); notes: keep density/,
174 );
163175 assert.match(capsule, /annotation dense: tighten/);
164176 });
191203 ],
192204 },
193205 }) as unknown as ExtensionContext;
194 const runtime = createMockupRuntime({ cacheRoot: root, openBrowser: false });
206 const runtime = createMockupRuntime({
207 cacheRoot: root,
208 openBrowser: false,
209 });
195210 assert.strictEqual(runtime.contextCapsule(context("owner")), capsule);
196 assert.strictEqual(runtime.contextCapsule(context("new-session")), undefined);
211 assert.strictEqual(
212 runtime.contextCapsule(context("new-session")),
213 undefined,
214 );
197215 });
199217 it("removes orphaned and expired entries while protecting the current session", async () => {

extensions/the-system/__tests__/mockup.test.ts

Modified

+1 / −3 text lines

307307 action: "iterate",
308308 selected: ["a"],
309309 notes: "keep A, denser drawer",
310 annotations: [
311 { optionId: "a", x: 0.25, y: 0.5, note: "tighten" },
312 ],
310 annotations: [{ optionId: "a", x: 0.25, y: 0.5, note: "tighten" }],
313311 userAgent: client.userAgent,
314312 viewport: client.viewport,
315313 },

extensions/the-system/mockup-tool.ts

Modified

+31 / −12 text lines

11import { randomUUID } from "node:crypto";
2import { access, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
2import {
3 access,
4 mkdir,
5 readdir,
6 readFile,
7 rm,
8 stat,
9 writeFile,
10} from "node:fs/promises";
311import { homedir } from "node:os";
412import path from "node:path";
513import {
157165 if (!details) return new Text("", 0, 0);
158166 const annotations = details.annotations ?? [];
159167 const summary = `${details.action ?? "submitted"} · ${(details.selected ?? []).join(", ") || "none"} · ${annotations.length} annotation${annotations.length === 1 ? "" : "s"}`;
160 if (!context.expanded)
161 return new Text(theme.fg("dim", summary), 0, 0);
168 if (!context.expanded) return new Text(theme.fg("dim", summary), 0, 0);
162169 return new Text(
163170 [
164171 theme.fg("dim", summary),
211218 toolCallId,
212219 request,
213220 result,
214 previousManifest: continuing
215 ? previous.cacheManifest
216 : undefined,
221 previousManifest: continuing ? previous.cacheManifest : undefined,
217222 });
218223 } catch (error) {
219224 cacheError = error instanceof Error ? error.message : String(error);
304309 if (entry.type !== "message") continue;
305310 const message = entry.message;
306311 if (!isRecord(message)) continue;
307 if (message.role !== "toolResult" || message.toolName !== "mockup") continue;
312 if (message.role !== "toolResult" || message.toolName !== "mockup")
313 continue;
308314 const details = message.details;
309315 if (!isRecord(details) || typeof details.contextCapsule !== "string")
310316 return undefined;
375381function selectedLabels(entry: MockupHistoryEntry): string {
376382 if (entry.selected.length === 0) return "none";
377 const labels = new Map(entry.options.map((option) => [option.id, option.label]));
383 const labels = new Map(
384 entry.options.map((option) => [option.id, option.label]),
385 );
378386 return entry.selected
379387 .map((id) => `${id} (${labels.get(id) ?? id})`)
380388 .join(", ");
394402 );
395403 if (platform === "darwin")
396404 return path.join(home, "Library", "Caches", "pi", "mockups");
397 return path.join(env.XDG_CACHE_HOME ?? path.join(home, ".cache"), "pi", "mockups");
405 return path.join(
406 env.XDG_CACHE_HOME ?? path.join(home, ".cache"),
407 "pi",
408 "mockups",
409 );
400412type PersistInput = {
433445 `${JSON.stringify(input.result, null, 2)}\n`,
434446 ),
435447 ...input.request.options.map((option) =>
436 writeFile(path.join(iterationDir, `${safeSegment(option.id)}.html`), option.html),
448 writeFile(
449 path.join(iterationDir, `${safeSegment(option.id)}.html`),
450 option.html,
451 ),
437452 ),
438453 ]);
439454 const manifest = path.join(iterationDir, "manifest.json");
473488 },
474489): Promise<void> {
475490 const sessions = await directories(root);
476 const candidates: Array<{ path: string; modified: number; bytes: number }> = [];
491 const candidates: Array<{ path: string; modified: number; bytes: number }> =
492 [];
477493 for (const session of sessions) {
478494 if (session.name === safeSegment(protectedSessionId ?? "")) continue;
479495 const metadataPath = path.join(session.path, "session.json");
517533 try {
518534 return (await readdir(root, { withFileTypes: true }))
519535 .filter((entry) => entry.isDirectory() && !entry.isSymbolicLink())
520 .map((entry) => ({ name: entry.name, path: path.join(root, entry.name) }));
536 .map((entry) => ({
537 name: entry.name,
538 path: path.join(root, entry.name),
539 }));
521540 } catch (error) {
522541 if (isNotFound(error)) return [];
523542 throw error;

extensions/the-system/mockup.ts

Modified

+4 / −3 text lines

127127 }
128128 function armRoundTimeout(): void {
129129 clearRoundTimeout();
130 timeout = setTimeout(() =>
131 terminate(new Error("mockup timed out waiting for browser Submit")),
132 DEFAULT_TIMEOUT_MS);
130 timeout = setTimeout(
131 () => terminate(new Error("mockup timed out waiting for browser Submit")),
132 DEFAULT_TIMEOUT_MS,
133 );
133134 timeout.unref();
134135 }
135136 function broadcast(type: string, data: unknown): void {