@dadado/agent-kit-cli 4.8.8 → 5.0.0

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.
@@ -4,7 +4,8 @@
4
4
  *
5
5
  * Allocates a stable per-workspace listen port (hash of snapshot root in the
6
6
  * 3333–3588 range unless PORT is set), detach-starts `serve.mjs` when needed,
7
- * waits until HTTP 200, prints the URL, and opens the default browser.
7
+ * waits until HTTP 200, prints the URL, and opens one preferred browser
8
+ * (or OS default). Never opens more than one browser process.
8
9
  *
9
10
  * Never kills a listener whose system.repoRoot belongs to another workspace.
10
11
  *
@@ -17,17 +18,18 @@
17
18
 
18
19
  import { execFileSync, execSync, spawn } from "node:child_process";
19
20
  import { existsSync, openSync } from "node:fs";
20
- import { platform } from "node:os";
21
21
  import { dirname, join, resolve } from "node:path";
22
22
  import { fileURLToPath } from "node:url";
23
23
  import {
24
24
  REPO_ROOT_ENV,
25
25
  escapePerlDoubleQuoted,
26
26
  repoRootLogId,
27
+ resolveContextConfigPath,
27
28
  resolveMissionControlPort,
28
29
  resolveSnapshotRepoRoot,
29
30
  sameRepoRoot,
30
31
  } from "./lib/guards.mjs";
32
+ import { openBrowser, readPreferredBrowserFromConfig } from "./lib/open-browser.mjs";
31
33
 
32
34
  const __dirname = dirname(fileURLToPath(import.meta.url));
33
35
  const KIT_ROOT = join(__dirname, "..");
@@ -188,24 +190,6 @@ async function waitReady() {
188
190
  return false;
189
191
  }
190
192
 
191
- function openBrowser(url) {
192
- const os = platform();
193
- try {
194
- if (os === "darwin") {
195
- spawn("open", [url], { detached: true, stdio: "ignore" }).unref();
196
- return true;
197
- }
198
- if (os === "win32") {
199
- spawn("cmd", ["/c", "start", "", url], { detached: true, stdio: "ignore" }).unref();
200
- return true;
201
- }
202
- spawn("xdg-open", [url], { detached: true, stdio: "ignore" }).unref();
203
- return true;
204
- } catch {
205
- return false;
206
- }
207
- }
208
-
209
193
  async function ensureServer() {
210
194
  const allocation = resolveMissionControlPort({
211
195
  repoRoot: ROOT,
@@ -271,11 +255,23 @@ async function main() {
271
255
  if (process.env.MISSION_CONTROL_NO_OPEN === "1") {
272
256
  return;
273
257
  }
274
- if (openBrowser(URL)) {
275
- console.log(
276
- "Opened in the default browser. In Cursor, Simple Browser or /dashboard also works.",
277
- );
278
- } else {
258
+ let configValue = null;
259
+ const cfg = resolveContextConfigPath(ROOT, { existsSync });
260
+ if (cfg.ok) {
261
+ configValue = readPreferredBrowserFromConfig(cfg.path);
262
+ }
263
+ const result = openBrowser(URL, { configValue });
264
+ if (result.opened) {
265
+ if (result.reason === "preferred-fallback") {
266
+ console.log(
267
+ "Preferred browser failed; opened with the OS default. In Cursor, Simple Browser or /dashboard also works.",
268
+ );
269
+ } else {
270
+ console.log(
271
+ "Opened in the preferred browser (or OS default). In Cursor, Simple Browser or /dashboard also works.",
272
+ );
273
+ }
274
+ } else if (result.reason !== "no-open") {
279
275
  console.log("Open that URL in a browser (Cursor: Simple Browser, or run /dashboard in chat).");
280
276
  }
281
277
  }