pi-web-ui 0.21.1 → 0.21.2

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.
package/bin/pi-web-ui.mjs CHANGED
@@ -172,12 +172,24 @@ function parseFlags(argv) {
172
172
 
173
173
  /** Open a URL in the OS default browser; failures are ignored (best-effort). */
174
174
  function openBrowser(url) {
175
+ let res;
175
176
  if (isMac) {
176
- spawnSync("open", [url], { stdio: "ignore" });
177
+ res = spawnSync("open", [url], { stdio: "ignore" });
177
178
  } else if (isWin) {
178
- spawnSync("cmd", ["/c", "start", "", url], { stdio: "ignore" });
179
+ res = spawnSync("cmd", ["/c", "start", "", url], { stdio: "ignore" });
179
180
  } else {
180
- spawnSync("xdg-open", [url], { stdio: "ignore" });
181
+ res = spawnSync("xdg-open", [url], { stdio: "ignore" });
182
+ }
183
+ // spawnSync 不抛异常:命令缺失(headless 服务器)时在返回对象里带 error 字段。
184
+ if (res?.error) {
185
+ if (res.error.code === "ENOENT") {
186
+ console.warn(
187
+ `[browser] 未找到打开器 (${res.error.path || "command not found"}),` +
188
+ "headless 服务器可用 --no-browser 关闭自动打开"
189
+ );
190
+ } else {
191
+ console.warn("[browser] 打开浏览器失败:", res.error.message);
192
+ }
181
193
  }
182
194
  }
183
195
 
@@ -76,17 +76,25 @@ function parseArgs(args: string): { port?: number; cwd?: string; noBrowser: bool
76
76
  /** 打开浏览器 */
77
77
  async function openBrowser(url: string): Promise<void> {
78
78
  const { platform } = process;
79
- const cmd =
79
+ const [cmd, ...rest] =
80
80
  platform === "darwin"
81
81
  ? ["open", url]
82
82
  : platform === "win32"
83
83
  ? ["cmd", "/c", "start", "", url]
84
84
  : ["xdg-open", url];
85
- try {
86
- spawn(cmd[0], cmd.slice(1), { stdio: "ignore", detached: true }).unref();
87
- } catch {
88
- /* 忽略打开失败(headless 等场景) */
89
- }
85
+ // 无界面环境缺少 xdg-open 等打开器时,ENOENT 以异步 'error' 事件触发,
86
+ // try/catch 拦不住会崩掉整个进程 —— 必须挂 error 监听。
87
+ spawn(cmd, rest, { stdio: "ignore", detached: true })
88
+ .on("error", (err) => {
89
+ if ((err as NodeJS.ErrnoException)?.code === "ENOENT") {
90
+ console.warn(
91
+ `[webui] 未找到浏览器打开器 (${(err as NodeJS.ErrnoException).path || "command not found"}),请用 --no-browser 关闭自动打开`
92
+ );
93
+ } else {
94
+ console.warn("[webui] 打开浏览器失败:", err.message);
95
+ }
96
+ })
97
+ .unref();
90
98
  }
91
99
 
92
100
  export default function (pi: ExtensionAPI): void {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web-ui",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "Web chat interface for the pi coding agent, powered by the pi SDK (@earendil-works/pi-coding-agent) — one-command run, Docker/systemd/launchd deployable",
5
5
  "license": "MIT",
6
6
  "type": "module",