@opencode/browse 0.0.17-dev.180 → 0.0.17-dev.181

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.
Files changed (37) hide show
  1. package/dist/{Runtime-jrg7sc9p.mjs → Runtime-xss8qan1.mjs} +1 -1
  2. package/dist/{cli-dbb5bjne.mjs → cli-1bdh4p0a.mjs} +37 -38
  3. package/dist/cli.mjs +14 -14
  4. package/dist/{helpers-mbetgbwv.mjs → helpers-bbaa1vjs.mjs} +1 -3
  5. package/dist/{index-j79y2me1.mjs → index-gjq7chrk.mjs} +2 -2
  6. package/dist/{legacy-runtime-eky6yenx.mjs → legacy-runtime-yjsm0xpg.mjs} +30 -17
  7. package/dist/{main-44rp8pxg.mjs → main-32bwyqja.mjs} +4 -4
  8. package/dist/{main-f98q5tcf.mjs → main-6hvv25x8.mjs} +27 -29
  9. package/dist/{main-v2a390e1.mjs → main-6qfvnjxc.mjs} +7 -9
  10. package/dist/{main-3mhynene.mjs → main-9frwnsnf.mjs} +3 -5
  11. package/dist/{main-048kx59h.mjs → main-akpa411k.mjs} +6 -8
  12. package/dist/main-bt237ys7.mjs +1012 -0
  13. package/dist/main-d5ke1bpm.mjs +4 -0
  14. package/dist/{main-s3g4jwx5.mjs → main-jeta10c6.mjs} +23 -25
  15. package/dist/{main-wpt5ha44.mjs → main-m45zegrn.mjs} +371 -167
  16. package/dist/{main-fpn564ph.mjs → main-pq962g72.mjs} +7 -4
  17. package/dist/main-q4typx7c.mjs +213 -0
  18. package/dist/{main-r8g3xydm.mjs → main-qccyxwg8.mjs} +3 -5
  19. package/dist/{main-awaqqre9.mjs → main-rb7dermc.mjs} +117 -4
  20. package/dist/{main-46wtkfsd.mjs → main-reh7k0hv.mjs} +199 -989
  21. package/dist/{main-jwss6gk9.mjs → main-rvn834gn.mjs} +2 -2
  22. package/dist/{main-wfmad10p.mjs → main-sfxkq31s.mjs} +16 -18
  23. package/dist/{main-q2d5bd1e.mjs → main-tg0r67xj.mjs} +8 -10
  24. package/dist/{main-g1frnq76.mjs → main-tk2thty0.mjs} +8 -7
  25. package/dist/{mcp-amxrbrbd.mjs → mcp-rjpmt73q.mjs} +31 -32
  26. package/dist/{migrate-07f3f3yp.mjs → migrate-hggn66v2.mjs} +5 -6
  27. package/dist/{relay-e7fx469h.mjs → relay-fm6q9hnx.mjs} +87 -60
  28. package/dist/{runtime-update-xt7x7j6c.mjs → runtime-update-vdw1eajx.mjs} +9 -9
  29. package/dist/{setup-m85mamg6.mjs → setup-wyrpwq4c.mjs} +196 -129
  30. package/dist/{supervisor-6zbwkkpt.mjs → supervisor-nbce8yhg.mjs} +10 -6
  31. package/dist/{update-drswqt2m.mjs → update-be8dfw51.mjs} +3 -4
  32. package/dist/{version-v3heqz8b.mjs → version-6j8cdg2k.mjs} +1 -1
  33. package/package.json +1 -1
  34. package/dist/main-4h7rfhhr.mjs +0 -61
  35. package/dist/main-amkq7v9m.mjs +0 -4
  36. package/dist/main-gg7f12gg.mjs +0 -114
  37. package/dist/main-qazf3bhk.mjs +0 -223
@@ -63,11 +63,11 @@ import {
63
63
  installRuntime,
64
64
  installedRuntime,
65
65
  manualMcpEntry
66
- } from "./main-g1frnq76.mjs";
66
+ } from "./main-tk2thty0.mjs";
67
67
  import"./main-pmfd055v.mjs";
68
68
  import {
69
69
  opencodeBrowserBuildId2
70
- } from "./main-amkq7v9m.mjs";
70
+ } from "./main-d5ke1bpm.mjs";
71
71
  import {
72
72
  installedBinaryPath,
73
73
  installerBinaryPath,
@@ -81,11 +81,16 @@ import {
81
81
  cliCommand,
82
82
  devExtensionFolder,
83
83
  installCommand,
84
+ unpackedExtensionId,
85
+ extensionProtocolSkew,
86
+ extensionProtocolAdvice,
84
87
  autoUpdateStatus,
85
88
  describeAutoUpdate,
86
89
  runCommand
87
- } from "./main-awaqqre9.mjs";
88
- import"./main-4h7rfhhr.mjs";
90
+ } from "./main-rb7dermc.mjs";
91
+ import {
92
+ defaultPort2
93
+ } from "./main-bt237ys7.mjs";
89
94
  import {
90
95
  pairingCodeTtlMs,
91
96
  bundledPairingCodeTtlMs,
@@ -98,25 +103,29 @@ import {
98
103
  revokeBrowserToken,
99
104
  legacyPairingCode,
100
105
  removeLegacyPairingCode
101
- } from "./main-fpn564ph.mjs";
102
- import {
103
- unpackedExtensionId,
104
- extensionProtocolSkew,
105
- extensionProtocolAdvice
106
- } from "./main-gg7f12gg.mjs";
106
+ } from "./main-pq962g72.mjs";
107
107
  import"./main-tk4axre7.mjs";
108
108
  import {
109
109
  defaultSiteSecretsDir
110
- } from "./main-q2d5bd1e.mjs";
110
+ } from "./main-tg0r67xj.mjs";
111
111
  import {
112
112
  parseHostname,
113
113
  readRelayConfig,
114
114
  writeRelayConfig,
115
115
  syncDevExtension
116
- } from "./main-44rp8pxg.mjs";
116
+ } from "./main-32bwyqja.mjs";
117
117
  import {
118
118
  relayAuthorization
119
- } from "./main-jwss6gk9.mjs";
119
+ } from "./main-rvn834gn.mjs";
120
+ import {
121
+ endpointForPort,
122
+ configuredRelayPort,
123
+ resolveRelayPort,
124
+ probeRelayPort,
125
+ verifiedRelay,
126
+ verifiedRelayEndpoint,
127
+ liveRelayPort
128
+ } from "./main-q4typx7c.mjs";
120
129
 
121
130
  // src/setup.ts
122
131
  import { mkdirSync as mkdirSync2, rmSync as rmSync2, writeFileSync } from "node:fs";
@@ -244,10 +253,10 @@ function fuzzy(query, text) {
244
253
  }
245
254
 
246
255
  // src/setup/commands.ts
247
- import { spawnSync } from "node:child_process";
256
+ import { spawnSync as spawnSync2 } from "node:child_process";
248
257
  import { randomUUID } from "node:crypto";
249
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from "node:fs";
250
- import { networkInterfaces } from "node:os";
258
+ import { existsSync as existsSync2, mkdirSync, readdirSync, readFileSync, rmSync } from "node:fs";
259
+ import { networkInterfaces as networkInterfaces2 } from "node:os";
251
260
  import path from "node:path";
252
261
  import { createInterface } from "node:readline/promises";
253
262
 
@@ -284,11 +293,12 @@ function pairStoreExtension(options, effects = systemEffects) {
284
293
  if (!match)
285
294
  return "none";
286
295
  const interactive = options.allowOpen && options.env.display && !options.env.ssh;
287
- if (interactive && effects.open(match.browser, `chrome-extension://${match.id}/welcome.html#code=${options.code()}`, match.profile.dir)) {
296
+ const port = options.port === undefined || options.port === defaultPort2 ? "" : `&port=${options.port}`;
297
+ if (interactive && effects.open(match.browser, `chrome-extension://${match.id}/welcome.html#code=${options.code()}${port}`, match.profile.dir)) {
288
298
  effects.log(`✓ Opened browse in ${match.browser.name} to connect it`);
289
299
  return "opened";
290
300
  }
291
- effects.log(`To connect browse in ${match.browser.name}: ${manualPair(options.code())}`);
301
+ effects.log(`To connect browse in ${match.browser.name}: ${manualPair(options.code(), options.port)}`);
292
302
  return "manual";
293
303
  }
294
304
  async function waitForExtension(options) {
@@ -302,8 +312,76 @@ async function waitForExtension(options) {
302
312
  }
303
313
  }
304
314
 
315
+ // src/setup/remote.ts
316
+ import { spawnSync } from "node:child_process";
317
+ import { existsSync } from "node:fs";
318
+ import { networkInterfaces } from "node:os";
319
+ var tailnetIPv4 = /^100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./;
320
+ var virtualInterface = /^(lo|docker|br-|veth|virbr|vmnet|vboxnet|cni|flannel|podman|utun|awdl|llw|bridge)/;
321
+ function remoteRelayAddresses(interfaces, options = {}) {
322
+ const ipv4 = Object.entries(interfaces).filter(([name]) => !virtualInterface.test(name)).flatMap(([, addresses]) => addresses ?? []).filter((address) => address.family === "IPv4" && !address.internal && !address.address.startsWith("169.254.")).map((address) => address.address);
323
+ const tailnet = ipv4.filter((address) => tailnetIPv4.test(address));
324
+ const hosts = tailnet.length ? [...options.magicDns ? [options.magicDns] : [], ...tailnet] : ipv4;
325
+ const port = options.port && options.port !== 19988 ? `:${options.port}` : "";
326
+ return [...new Set(hosts)].map((host) => host + port);
327
+ }
328
+ function remoteRelayLines(addresses, code, ttlMs = pairingCodeTtlMs) {
329
+ return [
330
+ `Relay address ${addresses[0] ?? "this computer's IP address"}`,
331
+ ...addresses.slice(1).map((address) => ` or ${address}`),
332
+ `Pairing code ${formatPairingCode(code)}`,
333
+ "",
334
+ `The code works once, within ${ttlMs / 60000} minutes. For a new one, run: ${cliCommand("pair")}`
335
+ ];
336
+ }
337
+ function magicDnsName() {
338
+ const mac = "/Applications/Tailscale.app/Contents/MacOS/Tailscale";
339
+ const cli = findOnPath("tailscale") ?? (process.platform === "darwin" && existsSync(mac) ? mac : undefined);
340
+ if (!cli)
341
+ return;
342
+ const status = spawnSync(cli, ["status", "--json"], { encoding: "utf8", timeout: 5000 });
343
+ const name = parseJson(status.stdout)?.Self?.DNSName;
344
+ return typeof name === "string" && name ? name.replace(/\.$/, "") : undefined;
345
+ }
346
+ async function installRemote(entry, tty) {
347
+ const config = readRelayConfig();
348
+ if (config.hostname !== "0.0.0.0") {
349
+ writeRelayConfig({ ...config, hostname: "0.0.0.0" });
350
+ const running = await probeRelayPort(resolveRelayPort(), 2000) === "browse";
351
+ const [file, ...prefix] = entrySpawnCommand(entry);
352
+ const restarted = running && spawnSync(file, [...prefix, "relay", "restart"], { encoding: "utf8", timeout: 60000 }).status === 0;
353
+ if (running && !restarted) {
354
+ process.exitCode = 1;
355
+ log(`! The relay is still only reachable from this computer. When no agent is using it, run: ${cliCommand("relay restart --force")}`);
356
+ } else
357
+ log("✓ Opened the relay to other computers");
358
+ } else
359
+ log("✓ The relay is open to other computers");
360
+ ensureRelay(entry);
361
+ const port = resolveRelayPort();
362
+ const interfaces = networkInterfaces();
363
+ const onTailnet = Object.values(interfaces).flat().some((address) => address?.family === "IPv4" && tailnetIPv4.test(address.address));
364
+ const addresses = remoteRelayAddresses(interfaces, { port, magicDns: onTailnet ? magicDnsName() : undefined });
365
+ const lines = remoteRelayLines(addresses, mintPairingCode());
366
+ const where = 'In Chrome on the other computer, open browse, choose "Connect an agent on another computer" and enter:';
367
+ if (rail.active)
368
+ note(lines.join(`
369
+ `), "Enter this in browse on the other computer");
370
+ else {
371
+ log("");
372
+ log(where);
373
+ for (const line of lines)
374
+ log(line && ` ${line}`);
375
+ log("");
376
+ }
377
+ if (!onTailnet)
378
+ log("! browse doesn't encrypt this connection: use it on a network you trust, or over Tailscale, not the open internet.");
379
+ if (!tty)
380
+ log("Agent: give the user the relay address and pairing code above to enter in browse in their browser. The code works once and expires; if it does, run `" + cliCommand("pair") + "` for a new one.");
381
+ }
382
+
305
383
  // src/setup/commands.ts
306
- var relayBase = () => `http://127.0.0.1:${Number(process.env.OPENCODE_BROWSER_PORT) || 19988}`;
384
+ var relayBase = () => endpointForPort(resolveRelayPort());
307
385
  var relayHeaders = () => {
308
386
  try {
309
387
  return { authorization: relayAuthorization() };
@@ -311,21 +389,52 @@ var relayHeaders = () => {
311
389
  return {};
312
390
  }
313
391
  };
314
- function ensureRelay(entry) {
392
+ async function relayRequest(path2, options = {}) {
393
+ const endpoint = await verifiedRelayEndpoint();
394
+ if (endpoint === undefined)
395
+ return;
396
+ return fetch(`${endpoint}${path2}`, {
397
+ ...options.method === undefined ? {} : { method: options.method },
398
+ ...options.body === undefined ? {} : { body: options.body },
399
+ headers: { ...relayHeaders(), ...options.headers },
400
+ redirect: "error",
401
+ signal: AbortSignal.timeout(options.timeoutMs ?? 3000)
402
+ }).catch(() => {
403
+ return;
404
+ });
405
+ }
406
+ function startRelay(entry) {
315
407
  const [file, ...prefix] = entrySpawnCommand(entry);
316
- const started = spawnSync(file, [...prefix, "session", "list", "--json"], {
408
+ return spawnSync2(file, [...prefix, "session", "list", "--json"], {
317
409
  encoding: "utf8",
318
410
  timeout: 30000
319
411
  });
412
+ }
413
+ function relayFailure(started) {
414
+ return started.stderr?.trim() || `Couldn't reach the browse relay: ${started.error?.message || `run ${cliCommand("doctor")}`}`;
415
+ }
416
+ function ensureRelay(entry) {
417
+ const started = startRelay(entry);
320
418
  if (started.status !== 0)
321
- fail(started.stderr?.trim() || `Couldn't reach the browse relay: ${started.error?.message || `run ${cliCommand("doctor")}`}`);
322
- }
323
- var extensionStatus = (installWaiting = false) => fetch(`${relayBase()}/extension/status`, {
324
- headers: { ...relayHeaders(), ...installWaiting ? { "x-browse-install": "waiting" } : {} },
325
- signal: AbortSignal.timeout(3000)
326
- }).then((response) => response.ok ? response.json() : undefined).catch(() => {
327
- return;
328
- });
419
+ fail(relayFailure(started));
420
+ }
421
+ function ensureRelayQuietly(entry) {
422
+ const started = startRelay(entry);
423
+ return started.status === 0 ? undefined : relayFailure(started);
424
+ }
425
+ var extensionStatus = async (installWaiting = false) => {
426
+ const response = await relayRequest("/extension/status", {
427
+ headers: installWaiting ? { "x-browse-install": "waiting" } : {},
428
+ timeoutMs: 3000
429
+ });
430
+ if (!response?.ok)
431
+ return;
432
+ try {
433
+ return await response.json();
434
+ } catch {
435
+ return;
436
+ }
437
+ };
329
438
  async function settledExtensionStatus(entry) {
330
439
  let status = await extensionStatus();
331
440
  if (!status && Object.keys(readBrowserPairings()).length) {
@@ -344,12 +453,12 @@ async function reloadOutdatedExtension(before, folder) {
344
453
  const bundled = readJson(path.join(folder, "build.json"))?.build;
345
454
  if (bundled && before.build === bundled)
346
455
  return "current";
347
- const sent = await fetch(`${relayBase()}/extension/reload`, {
456
+ const sent = (await relayRequest("/extension/reload", {
348
457
  method: "POST",
349
458
  body: "{}",
350
- headers: { "content-type": "application/json", ...relayHeaders() },
351
- signal: AbortSignal.timeout(5000)
352
- }).then((response) => response.ok, () => false);
459
+ headers: { "content-type": "application/json" },
460
+ timeoutMs: 5000
461
+ }))?.ok === true;
353
462
  if (!sent)
354
463
  return "stale";
355
464
  for (let attempt = 0;attempt < 20; attempt++) {
@@ -369,13 +478,14 @@ async function syncDev() {
369
478
  fail(`Could not get the dev extension: ${error.message}`);
370
479
  }
371
480
  }
372
- function pairUnpacked() {
373
- const directories = [...checkoutExtensionDirs, ...dev ? [devExtensionFolder(paths.cache)] : []].filter((directory) => existsSync(path.join(directory, "manifest.json")));
481
+ async function pairUnpacked() {
482
+ const directories = [...checkoutExtensionDirs, ...dev ? [devExtensionFolder(paths.cache)] : []].filter((directory) => existsSync2(path.join(directory, "manifest.json")));
374
483
  if (directories.length === 0)
375
484
  return;
485
+ const port = await liveRelayPort();
376
486
  const code = mintPairingCode(undefined, { ttlMs: bundledPairingCodeTtlMs });
377
487
  for (const directory of directories)
378
- writeExtensionPairing(directory, code);
488
+ writeExtensionPairing(directory, code, port);
379
489
  }
380
490
  async function extension() {
381
491
  const folder = unpackedFolder();
@@ -387,9 +497,12 @@ async function extension() {
387
497
  return;
388
498
  }
389
499
  await syncDev();
390
- if (!existsSync(path.join(folder, "manifest.json")))
500
+ if (!existsSync2(path.join(folder, "manifest.json")))
391
501
  fail(`${folder} has no built extension. Run \`${installCommand()}\` first.`);
392
- pairUnpacked();
502
+ const failure = ensureRelayQuietly(readJson(files.settings)?.entry ?? runningEntry());
503
+ if (failure)
504
+ log(`! Couldn't start the relay: ${failure}`);
505
+ await pairUnpacked();
393
506
  revealFolder(folder);
394
507
  log(`Load unpacked from: ${folder}`);
395
508
  }
@@ -408,8 +521,10 @@ async function pair(args) {
408
521
  ensureRelay(readJson(files.settings)?.entry ?? runningEntry());
409
522
  const receipt = randomUUID();
410
523
  const code = mintPairingCode(undefined, { receipt });
524
+ const port = resolveRelayPort();
525
+ const remote = readRelayConfig().hostname === "0.0.0.0" ? remoteRelayAddresses(networkInterfaces2(), { port })[0] : undefined;
411
526
  log(`Pairing code: ${formatPairingCode(code)}`);
412
- log(`${manualPair(code)} It works once, within ${pairingCodeTtlMs / 60000} minutes.`);
527
+ log(`${manualPair(code, port, remote)} It works once, within ${pairingCodeTtlMs / 60000} minutes.`);
413
528
  log(`Waiting up to ${timeoutMs / 1000}s for that browser. Later, \`${cliCommand("pair --list")}\` shows paired browsers.`);
414
529
  let paired;
415
530
  await waitForExtension({
@@ -470,12 +585,20 @@ async function revokePairing(target) {
470
585
  process.exitCode = 1;
471
586
  return;
472
587
  }
473
- const dropped = await fetch(`${relayBase()}/extension/revoke`, {
588
+ const response = await relayRequest("/extension/revoke", {
474
589
  method: "POST",
475
590
  body: JSON.stringify({ key: browser.key }),
476
- headers: { "content-type": "application/json", ...relayHeaders() },
477
- signal: AbortSignal.timeout(3000)
478
- }).then(async (response) => response.ok ? (await response.json()).dropped === true : false, () => false);
591
+ headers: { "content-type": "application/json" },
592
+ timeoutMs: 3000
593
+ });
594
+ let dropped = false;
595
+ if (response?.ok) {
596
+ try {
597
+ dropped = (await response.json()).dropped === true;
598
+ } catch {
599
+ dropped = false;
600
+ }
601
+ }
479
602
  log(`✓ Unpaired ${browser.id ?? browser.key}${dropped ? " and disconnected it" : ""}. To use it again, pair it with a new code.`);
480
603
  }
481
604
  async function set(args) {
@@ -490,27 +613,29 @@ async function set(args) {
490
613
  }
491
614
  writeRelayConfig({ ...readRelayConfig(), hostname });
492
615
  log(`✓ hostname is ${hostname}`);
493
- const running = await fetch(`${relayBase()}/version`, { signal: AbortSignal.timeout(2000) }).then((response) => response.ok, () => false);
616
+ const running = await probeRelayPort(resolveRelayPort(), 2000) === "browse";
494
617
  if (running) {
495
618
  const [file, ...prefix] = entrySpawnCommand(runningEntry());
496
- const restarted = spawnSync(file, [...prefix, "relay", "restart"], { stdio: "inherit" });
619
+ const restarted = spawnSync2(file, [...prefix, "relay", "restart"], { stdio: "inherit" });
497
620
  if (restarted.status !== 0)
498
621
  log(`! The relay is still running with the old hostname. Run \`${cliCommand("relay restart --force")}\` to apply it.`);
499
622
  }
500
623
  if (hostname === "127.0.0.1")
501
624
  return;
502
- const tailscale = Object.values(networkInterfaces()).flat().find((address) => address?.family === "IPv4" && /^100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./.test(address.address))?.address;
625
+ ensureRelayQuietly(readJson(files.settings)?.entry ?? runningEntry());
626
+ const port = resolveRelayPort();
627
+ const tailscale = Object.values(networkInterfaces2()).flat().find((address) => address?.family === "IPv4" && /^100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./.test(address.address))?.address;
503
628
  log("");
504
629
  log("In the browser on the other computer, open browse's options (right-click its toolbar button, then Options),");
505
630
  log("and under advanced enter:");
506
- log(` Relay ${tailscale ?? "this computer's address"}`);
631
+ log(` Relay ${(tailscale ?? "this computer's address") + (port === defaultPort2 ? "" : `:${port}`)}`);
507
632
  log(` Pairing code ${formatPairingCode(mintPairingCode())} (works once, within ${pairingCodeTtlMs / 60000} minutes; \`${cliCommand("pair")}\` prints another)`);
508
633
  log("The connection isn't encrypted by browse: use it over Tailscale or a LAN you trust, not the open internet.");
509
634
  }
510
635
  async function confirmSecretRemoval(args) {
511
636
  const secrets = path.join(files.dir, "secrets");
512
637
  const siteSecrets = defaultSiteSecretsDir();
513
- const count = (directory) => existsSync(directory) ? readdirSync(directory).filter((name) => name.endsWith(".json")).length : 0;
638
+ const count = (directory) => existsSync2(directory) ? readdirSync(directory).filter((name) => name.endsWith(".json")).length : 0;
514
639
  const profiles = count(secrets);
515
640
  const sites = count(siteSecrets);
516
641
  if (profiles === 0 && sites === 0 || args.includes("--yes") || args.includes("-y"))
@@ -528,12 +653,12 @@ async function confirmSecretRemoval(args) {
528
653
  }
529
654
  async function stopInstalledRelay() {
530
655
  const base = relayBase();
531
- const audit = path.join(paths.state, "relays", new URL(base).port, "lifecycle.jsonl");
532
- if (!existsSync(audit))
656
+ const audit = path.join(paths.state, "relays", String(configuredRelayPort()), "lifecycle.jsonl");
657
+ if (!existsSync2(audit))
533
658
  return;
534
659
  const probe = async () => {
535
660
  try {
536
- const response = await fetch(`${base}/version`, { redirect: "error", signal: AbortSignal.timeout(2000) });
661
+ const response = await fetch(`${base}/version`, { redirect: "manual", signal: AbortSignal.timeout(2000) });
537
662
  return response.ok ? await response.json() : undefined;
538
663
  } catch (error) {
539
664
  const e = error;
@@ -556,7 +681,10 @@ async function stopInstalledRelay() {
556
681
  return;
557
682
  if (relay.shutdownProtocol !== 2)
558
683
  throw new Error("Stop the legacy relay manually, then run uninstall again.");
559
- const response = await fetch(`${base}/shutdown`, {
684
+ const verified = await verifiedRelay();
685
+ if (verified === undefined || verified.endpoint !== base || verified.instanceId !== relay.instanceId)
686
+ throw new Error("Could not verify the running relay; stop it manually, then run uninstall again.");
687
+ const response = await fetch(`${verified.endpoint}/shutdown`, {
560
688
  method: "POST",
561
689
  redirect: "error",
562
690
  headers: { ...relayHeaders(), "content-type": "application/json" },
@@ -598,8 +726,8 @@ async function uninstall(args) {
598
726
  const binary = installedBinaryPath();
599
727
  if (compiledBinary()) {
600
728
  const installer = installerBinaryPath();
601
- if (installer !== binary && existsSync(installer) && !samePath(installer, binary)) {
602
- if (!existsSync(defaultSettingsPath()) && isInstallerBinary(installer, binary)) {
729
+ if (installer !== binary && existsSync2(installer) && !samePath(installer, binary)) {
730
+ if (!existsSync2(defaultSettingsPath()) && isInstallerBinary(installer, binary)) {
603
731
  try {
604
732
  rmSync(installer, { force: true });
605
733
  log(`✓ Removed ${installer}`);
@@ -611,7 +739,7 @@ async function uninstall(args) {
611
739
  }
612
740
  }
613
741
  }
614
- if (existsSync(binary)) {
742
+ if (existsSync2(binary)) {
615
743
  const left = removeBinaryInstall(binary);
616
744
  log(left ? `! Couldn't remove ${left}. After uninstall exits, close any browse agents using the file(s) and delete them.` : `✓ Removed ${binary}`);
617
745
  }
@@ -636,74 +764,6 @@ async function uninstall(args) {
636
764
  log("Remove the extension from your browser to finish.");
637
765
  }
638
766
 
639
- // src/setup/remote.ts
640
- import { spawnSync as spawnSync2 } from "node:child_process";
641
- import { existsSync as existsSync2 } from "node:fs";
642
- import { networkInterfaces as networkInterfaces2 } from "node:os";
643
- var tailnetIPv4 = /^100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./;
644
- var virtualInterface = /^(lo|docker|br-|veth|virbr|vmnet|vboxnet|cni|flannel|podman|utun|awdl|llw|bridge)/;
645
- function remoteRelayAddresses(interfaces, options = {}) {
646
- const ipv4 = Object.entries(interfaces).filter(([name]) => !virtualInterface.test(name)).flatMap(([, addresses]) => addresses ?? []).filter((address) => address.family === "IPv4" && !address.internal && !address.address.startsWith("169.254.")).map((address) => address.address);
647
- const tailnet = ipv4.filter((address) => tailnetIPv4.test(address));
648
- const hosts = tailnet.length ? [...options.magicDns ? [options.magicDns] : [], ...tailnet] : ipv4;
649
- const port = options.port && options.port !== 19988 ? `:${options.port}` : "";
650
- return [...new Set(hosts)].map((host) => host + port);
651
- }
652
- function remoteRelayLines(addresses, code, ttlMs = pairingCodeTtlMs) {
653
- return [
654
- `Relay address ${addresses[0] ?? "this computer's IP address"}`,
655
- ...addresses.slice(1).map((address) => ` or ${address}`),
656
- `Pairing code ${formatPairingCode(code)}`,
657
- "",
658
- `The code works once, within ${ttlMs / 60000} minutes. For a new one, run: ${cliCommand("pair")}`
659
- ];
660
- }
661
- function magicDnsName() {
662
- const mac = "/Applications/Tailscale.app/Contents/MacOS/Tailscale";
663
- const cli = findOnPath("tailscale") ?? (process.platform === "darwin" && existsSync2(mac) ? mac : undefined);
664
- if (!cli)
665
- return;
666
- const status = spawnSync2(cli, ["status", "--json"], { encoding: "utf8", timeout: 5000 });
667
- const name = parseJson(status.stdout)?.Self?.DNSName;
668
- return typeof name === "string" && name ? name.replace(/\.$/, "") : undefined;
669
- }
670
- async function installRemote(entry, tty) {
671
- const config = readRelayConfig();
672
- if (config.hostname !== "0.0.0.0") {
673
- writeRelayConfig({ ...config, hostname: "0.0.0.0" });
674
- const running = await fetch(`${relayBase()}/version`, { signal: AbortSignal.timeout(2000) }).then((response) => response.ok, () => false);
675
- const [file, ...prefix] = entrySpawnCommand(entry);
676
- const restarted = running && spawnSync2(file, [...prefix, "relay", "restart"], { encoding: "utf8", timeout: 60000 }).status === 0;
677
- if (running && !restarted) {
678
- process.exitCode = 1;
679
- log(`! The relay is still only reachable from this computer. When no agent is using it, run: ${cliCommand("relay restart --force")}`);
680
- } else
681
- log("✓ Opened the relay to other computers");
682
- } else
683
- log("✓ The relay is open to other computers");
684
- ensureRelay(entry);
685
- const port = Number(process.env.OPENCODE_BROWSER_PORT) || 19988;
686
- const interfaces = networkInterfaces2();
687
- const onTailnet = Object.values(interfaces).flat().some((address) => address?.family === "IPv4" && tailnetIPv4.test(address.address));
688
- const addresses = remoteRelayAddresses(interfaces, { port, magicDns: onTailnet ? magicDnsName() : undefined });
689
- const lines = remoteRelayLines(addresses, mintPairingCode());
690
- const where = 'In Chrome on the other computer, open browse, choose "Connect an agent on another computer" and enter:';
691
- if (rail.active)
692
- note(lines.join(`
693
- `), "Enter this in browse on the other computer");
694
- else {
695
- log("");
696
- log(where);
697
- for (const line of lines)
698
- log(line && ` ${line}`);
699
- log("");
700
- }
701
- if (!onTailnet)
702
- log("! browse doesn't encrypt this connection: use it on a network you trust, or over Tailscale, not the open internet.");
703
- if (!tty)
704
- log("Agent: give the user the relay address and pairing code above to enter in browse in their browser. The code works once and expires; if it does, run `" + cliCommand("pair") + "` for a new one.");
705
- }
706
-
707
767
  // src/setup.ts
708
768
  function checkNode() {
709
769
  if (compiledBinary())
@@ -848,7 +908,7 @@ async function installSteps(args, tty, caller) {
848
908
  const needsPairing = initial?.pairingState === "unpaired" || initial?.pairingState === "refused";
849
909
  const folder = unpackedFolder();
850
910
  if (folder && !pairedOffline) {
851
- pairUnpacked();
911
+ await pairUnpacked();
852
912
  const reload = connected ? await reloadOutdatedExtension(connected, folder) : "current";
853
913
  if (reload === "reloaded")
854
914
  log("✓ Reloaded browse in your browser");
@@ -895,7 +955,13 @@ async function installSteps(args, tty, caller) {
895
955
  });
896
956
  if (connected || found === "off" || pairedOffline)
897
957
  return;
898
- ensureRelay(spawnEntry);
958
+ if (folder) {
959
+ const failure = ensureRelayQuietly(spawnEntry);
960
+ if (failure)
961
+ fail(failure);
962
+ await pairUnpacked();
963
+ } else
964
+ ensureRelay(spawnEntry);
899
965
  let code;
900
966
  const pairingCode = () => code && pendingPairingCodeKeys().includes(pairingCodeKey(code)) ? code : code = mintPairingCode();
901
967
  const pairStore = (scanned) => pairStoreExtension({
@@ -903,18 +969,19 @@ async function installSteps(args, tty, caller) {
903
969
  preferred: defaultBrowser(scanned.map((d) => d.browser)),
904
970
  allowOpen: !args.includes("--no-open"),
905
971
  env,
906
- code: pairingCode
972
+ code: pairingCode,
973
+ port: resolveRelayPort()
907
974
  });
908
975
  if (needsPairing)
909
976
  log("browse is installed in a browser but isn't paired with this relay yet.");
910
977
  let offer = ssh ? "none" : pairStore(detections);
911
978
  const blocked = detections.filter((d) => d.blocked).map((d) => d.browser.name);
912
979
  if (offer === "none" && blocked.length) {
913
- log(`Couldn't check ${blocked.join(", ")}. If browse is already installed there, pair it manually. ${manualPair(pairingCode())}`);
980
+ log(`Couldn't check ${blocked.join(", ")}. If browse is already installed there, pair it manually. ${manualPair(pairingCode(), resolveRelayPort())}`);
914
981
  offer = "manual";
915
982
  }
916
983
  if (needsPairing && offer === "none") {
917
- log(manualPair(pairingCode()));
984
+ log(manualPair(pairingCode(), resolveRelayPort()));
918
985
  offer = "code";
919
986
  }
920
987
  const next = needsPairing ? `If it isn't paired, run \`${cliCommand("pair")}\` for a new code and enter it in browse's Options.` : `If browse isn't connected after you add it, run \`${cliCommand("install")}\` again to pair it.`;
@@ -963,7 +1030,7 @@ async function installSteps(args, tty, caller) {
963
1030
  } while (!stopped && Date.now() < deadline);
964
1031
  if (!env.tty)
965
1032
  return log(`! Not connected yet. ${agentNext()}`);
966
- log(`! Not connected yet. ${code ? manualPair(pairingCode()) : next}`);
1033
+ log(`! Not connected yet. ${code ? manualPair(pairingCode(), resolveRelayPort()) : next}`);
967
1034
  process.exitCode = 1;
968
1035
  } finally {
969
1036
  process.off("SIGINT", stop);
@@ -1,10 +1,15 @@
1
- import"./main-pmfd055v.mjs";
2
- import"./main-amkq7v9m.mjs";
1
+ import"./main-bt237ys7.mjs";
3
2
  import {
4
3
  entrySpawnCommand,
5
4
  installedRuntime2,
6
5
  installedVersion
7
- } from "./main-awaqqre9.mjs";
6
+ } from "./main-rb7dermc.mjs";
7
+ import"./main-pmfd055v.mjs";
8
+ import"./main-d5ke1bpm.mjs";
9
+ import {
10
+ endpointForPort,
11
+ resolveRelayPort
12
+ } from "./main-q4typx7c.mjs";
8
13
 
9
14
  // src/mcp/supervisor.ts
10
15
  import { spawn } from "node:child_process";
@@ -35,11 +40,10 @@ async function runBinaryMcp(args) {
35
40
  const runtime = installedRuntime2();
36
41
  if (!runtime || runtime.kind === "npx") {
37
42
  process.env[directEnvironmentVariable] = "1";
38
- const { runCli } = await import("./cli-dbb5bjne.mjs");
43
+ const { runCli } = await import("./cli-1bdh4p0a.mjs");
39
44
  return runCli();
40
45
  }
41
46
  const REPLAY = `opencode-browser-shim-initialize-${randomUUID()}`;
42
- const relayPort = Number(process.env.OPENCODE_BROWSER_PORT) || 19988;
43
47
  const current = versionReader(runtime, installedVersion(runtime) ?? runtime.version);
44
48
  const command = () => runtime.entry;
45
49
  process.env.OPENCODE_BROWSER_MCP_SESSION ??= "mcp-" + Math.random().toString(16).slice(2, 10).padEnd(8, "0");
@@ -200,7 +204,7 @@ async function runBinaryMcp(args) {
200
204
  };
201
205
  let checking = false;
202
206
  let unreachable = 0;
203
- const relayVersion = () => fetch(`http://127.0.0.1:${relayPort}/version`, { signal: AbortSignal.timeout(2000) }).then((response) => response.ok ? response.json() : undefined).then((body) => body && typeof body.version === "string" ? { version: body.version, draining: body.draining === true } : undefined, () => {
207
+ const relayVersion = () => fetch(`${endpointForPort(resolveRelayPort())}/version`, { redirect: "manual", signal: AbortSignal.timeout(2000) }).then((response) => response.ok ? response.json() : undefined).then((body) => body && typeof body.version === "string" && typeof body.instanceId === "string" ? { version: body.version, draining: body.draining === true } : undefined, () => {
204
208
  return;
205
209
  });
206
210
  const maybeSwap = async () => {
@@ -4,11 +4,10 @@ import {
4
4
  updateNotice2,
5
5
  createUpdateWatcher2,
6
6
  runUpdateCommand2
7
- } from "./main-r8g3xydm.mjs";
8
- import"./main-gg7f12gg.mjs";
9
- import"./main-awaqqre9.mjs";
7
+ } from "./main-qccyxwg8.mjs";
8
+ import"./main-rb7dermc.mjs";
10
9
  import"./main-pmfd055v.mjs";
11
- import"./main-amkq7v9m.mjs";
10
+ import"./main-d5ke1bpm.mjs";
12
11
  export {
13
12
  createUpdateWatcher2 as createUpdateWatcher,
14
13
  formatUpdateNotice2 as formatUpdateNotice,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  opencodeBrowserVersion2,
3
3
  opencodeBrowserBuildId2
4
- } from "./main-amkq7v9m.mjs";
4
+ } from "./main-d5ke1bpm.mjs";
5
5
  export {
6
6
  opencodeBrowserBuildId2 as opencodeBrowserBuildId,
7
7
  opencodeBrowserVersion2 as opencodeBrowserVersion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode/browse",
3
- "version": "0.0.17-dev.180",
3
+ "version": "0.0.17-dev.181",
4
4
  "description": "browse: connect the extension to opencode, and drive your browser from any agent (CLI, MCP, Playwright).",
5
5
  "type": "module",
6
6
  "license": "MIT",