pi-weave 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Browser opening for /weave-view (docs/weave-view.md §4).
3
+ * Kept separate from the command so the per-platform command mapping is
4
+ * unit-testable without stubbing globals.
5
+ */
6
+
7
+ import { platform } from "node:os";
8
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
9
+
10
+ /** The OS command used to open a URL in the default browser. */
11
+ export function browserCommand(
12
+ url: string,
13
+ os: NodeJS.Platform = platform(),
14
+ ): { command: string; args: string[] } {
15
+ if (os === "darwin") return { command: "open", args: [url] };
16
+ if (os === "win32") return { command: "cmd", args: ["/c", "start", "", url] };
17
+ return { command: "xdg-open", args: [url] };
18
+ }
19
+
20
+ /**
21
+ * Open the viewer URL in the user's browser — only in TUI mode with UI
22
+ * present; suppressible via PI_WEAVE_VIEW_NO_OPEN=1 (CI/headless/evals).
23
+ */
24
+ export async function openInBrowser(pi: ExtensionAPI, ctx: ExtensionContext, url: string): Promise<void> {
25
+ if (!ctx.hasUI || ctx.mode !== "tui") return;
26
+ if (process.env.PI_WEAVE_VIEW_NO_OPEN === "1") return;
27
+ const { command, args } = browserCommand(url);
28
+ await pi.exec(command, args, { timeout: 5_000 });
29
+ }