@opencode/browse 0.0.17-dev.155 → 0.0.17-dev.157

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.
@@ -5,6 +5,9 @@ import {
5
5
  extensionProtocolAdvice,
6
6
  parseJsonObject
7
7
  } from "./main-b3jrctcx.mjs";
8
+ import {
9
+ ensurePrivateDirectorySync
10
+ } from "./main-4h7rfhhr.mjs";
8
11
  import {
9
12
  get,
10
13
  post,
@@ -15,8 +18,9 @@ import {
15
18
  } from "./main-bc8cjey0.mjs";
16
19
  import {
17
20
  opencodeBrowserBuildId2
18
- } from "./main-n77bcfj8.mjs";
21
+ } from "./main-4pt08reg.mjs";
19
22
  import {
23
+ stateRoot,
20
24
  compiledBinary,
21
25
  scriptEntry,
22
26
  cliCommand,
@@ -24,10 +28,10 @@ import {
24
28
  compareVersions,
25
29
  installedRuntime2,
26
30
  installedVersion
27
- } from "./main-a6x41zxr.mjs";
31
+ } from "./main-s8p6mgme.mjs";
28
32
  import {
29
33
  relayAuthorization
30
- } from "./main-5hhgehca.mjs";
34
+ } from "./main-2be5p7he.mjs";
31
35
  import {
32
36
  Pointer,
33
37
  passthrough,
@@ -132,6 +136,9 @@ import {
132
136
  isObject,
133
137
  isTagged
134
138
  } from "./main-qazf3bhk.mjs";
139
+ import {
140
+ __require
141
+ } from "./main-j98fzrvv.mjs";
135
142
 
136
143
  // node_modules/effect/dist/ConfigProvider.js
137
144
  function makeValue(value) {
@@ -1320,8 +1327,8 @@ async function dataUrlDocument2(url) {
1320
1327
  // src/relay/lifecycle.ts
1321
1328
  import { execFileSync, spawn } from "node:child_process";
1322
1329
  import crypto2 from "node:crypto";
1323
- import path from "node:path";
1324
- import process2 from "node:process";
1330
+ import path3 from "node:path";
1331
+ import process3 from "node:process";
1325
1332
  import { fileURLToPath } from "node:url";
1326
1333
  // src/relay/client.ts
1327
1334
  var portConfig = Int("OPENCODE_BROWSER_PORT").pipe(withDefault(defaultPort2));
@@ -1507,8 +1514,177 @@ function mcpClientPid() {
1507
1514
  }
1508
1515
  var layerFetchMcp = effect(Service, make3({ clientPid: mcpClientPid() })).pipe(provide2(layerNodeHttp));
1509
1516
 
1517
+ // src/relay/log.ts
1518
+ import fs from "node:fs";
1519
+ import os from "node:os";
1520
+ import path from "node:path";
1521
+ var maxLogBytes = 1e6;
1522
+ var maxEntryCharacters = 64000;
1523
+ function managedRelayLogPath(home = os.homedir()) {
1524
+ return path.join(stateRoot(home), "logs", "relay.log");
1525
+ }
1526
+ function appendManagedRelayProcessLog(message, home = os.homedir()) {
1527
+ try {
1528
+ const logPath = managedRelayLogPath(home);
1529
+ ensurePrivateDirectorySync(path.dirname(logPath));
1530
+ const entry = `${new Date().toISOString()} ${message.slice(0, maxEntryCharacters)}
1531
+ `;
1532
+ const stat = fs.statSync(logPath, { throwIfNoEntry: false });
1533
+ if (stat && stat.size + Buffer.byteLength(entry) > maxLogBytes)
1534
+ fs.renameSync(logPath, `${logPath}.1`);
1535
+ fs.appendFileSync(logPath, entry, { encoding: "utf8", mode: 384 });
1536
+ fs.chmodSync(logPath, 384);
1537
+ } catch {}
1538
+ }
1539
+ function relayLog(event, fields = {}) {
1540
+ const detail = Object.entries(fields).filter(([, value]) => value !== undefined).map(([key, value]) => `${key}=${typeof value === "string" && !/\s/.test(value) ? value : JSON.stringify(value)}`).join(" ");
1541
+ appendManagedRelayProcessLog(detail ? `${event} ${detail}` : event);
1542
+ }
1543
+
1544
+ // src/relay/windows-launch.ts
1545
+ import { existsSync } from "node:fs";
1546
+ import path2 from "node:path";
1547
+ import process2 from "node:process";
1548
+ var createNewProcessGroup = 512;
1549
+ var createUnicodeEnvironment = 1024;
1550
+ var createNoWindow = 134217728;
1551
+ var startupInfoSize = 104;
1552
+ var processInformationSize = 24;
1553
+ var windowsAbsolutePath = /^(?:[A-Za-z]:[\\/]|\\\\)/;
1554
+ var kernel32;
1555
+ function kernel32Library() {
1556
+ if (kernel32)
1557
+ return kernel32;
1558
+ const ffi = __require("bun:ffi");
1559
+ kernel32 = ffi.dlopen("kernel32.dll", {
1560
+ CreateProcessW: {
1561
+ args: [
1562
+ ffi.FFIType.ptr,
1563
+ ffi.FFIType.ptr,
1564
+ ffi.FFIType.ptr,
1565
+ ffi.FFIType.ptr,
1566
+ ffi.FFIType.i32,
1567
+ ffi.FFIType.u32,
1568
+ ffi.FFIType.ptr,
1569
+ ffi.FFIType.ptr,
1570
+ ffi.FFIType.ptr,
1571
+ ffi.FFIType.ptr
1572
+ ],
1573
+ returns: ffi.FFIType.i32
1574
+ },
1575
+ CloseHandle: { args: [ffi.FFIType.ptr], returns: ffi.FFIType.i32 },
1576
+ GetLastError: { args: [], returns: ffi.FFIType.u32 }
1577
+ });
1578
+ return kernel32;
1579
+ }
1580
+ function resolveWindowsExecutable(executable, env, exists) {
1581
+ if (!executable || executable.includes("\x00"))
1582
+ return;
1583
+ if (windowsAbsolutePath.test(executable))
1584
+ return executable;
1585
+ if (/[\\/:]/.test(executable))
1586
+ return;
1587
+ const searchPath = windowsPathVariable(env);
1588
+ if (!searchPath)
1589
+ return;
1590
+ const names = path2.win32.extname(executable) ? [executable] : [`${executable}.exe`, `${executable}.com`];
1591
+ for (const entry of searchPath.split(path2.win32.delimiter)) {
1592
+ const trimmed = entry.trim();
1593
+ const directory = trimmed.startsWith('"') && trimmed.endsWith('"') ? trimmed.slice(1, -1) : trimmed;
1594
+ if (!windowsAbsolutePath.test(directory))
1595
+ continue;
1596
+ for (const name of names) {
1597
+ const candidate = path2.win32.join(directory, name);
1598
+ if (exists(candidate))
1599
+ return candidate;
1600
+ }
1601
+ }
1602
+ return;
1603
+ }
1604
+ function windowsPathVariable(env) {
1605
+ let value;
1606
+ for (const [name, candidate] of Object.entries(env)) {
1607
+ if (name.toUpperCase() === "PATH" && candidate !== undefined)
1608
+ value = candidate;
1609
+ }
1610
+ return value;
1611
+ }
1612
+ function windowsLaunchProblem(launch, env) {
1613
+ if (!launch.executable)
1614
+ return "the executable is empty";
1615
+ if (launch.executable.includes("\x00") || launch.args.some((argument) => argument.includes("\x00")))
1616
+ return "the executable or an argument contains NUL";
1617
+ if (Object.values(env).some((value) => value?.includes("\x00")))
1618
+ return "an environment value contains NUL";
1619
+ return;
1620
+ }
1621
+ function launchWindowsRelay(launch, env, onFallback) {
1622
+ const fallback = (reason) => {
1623
+ onFallback?.(reason);
1624
+ return false;
1625
+ };
1626
+ const problem = windowsLaunchProblem(launch, env);
1627
+ if (problem)
1628
+ return fallback(problem);
1629
+ if (!process2.versions.bun)
1630
+ return fallback("this process is not running under Bun");
1631
+ const executable = resolveWindowsExecutable(launch.executable, env, existsSync);
1632
+ if (!executable)
1633
+ return fallback(`could not resolve ${JSON.stringify(launch.executable)} through PATH`);
1634
+ let started = false;
1635
+ try {
1636
+ const kernel32 = kernel32Library();
1637
+ const startupInfo = new Uint8Array(startupInfoSize);
1638
+ const startup = new DataView(startupInfo.buffer);
1639
+ startup.setUint32(0, startupInfoSize, true);
1640
+ startup.setUint32(60, 1, true);
1641
+ startup.setUint16(64, 0, true);
1642
+ const processInformation = new Uint8Array(processInformationSize);
1643
+ const created = kernel32.symbols.CreateProcessW(wideZ(executable), wideZ(windowsCommandLine(executable, launch.args)), null, null, 0, createNoWindow | createNewProcessGroup | createUnicodeEnvironment, Buffer.from(windowsEnvironmentBlock(env), "utf16le"), null, startupInfo, processInformation);
1644
+ if (!created) {
1645
+ let code;
1646
+ try {
1647
+ code = kernel32.symbols.GetLastError();
1648
+ } catch {}
1649
+ return fallback(`CreateProcessW failed${code === undefined ? "" : ` (GetLastError() = ${code})`}`);
1650
+ }
1651
+ started = true;
1652
+ const info = new DataView(processInformation.buffer);
1653
+ kernel32.symbols.CloseHandle(info.getBigUint64(0, true));
1654
+ kernel32.symbols.CloseHandle(info.getBigUint64(8, true));
1655
+ return true;
1656
+ } catch (error) {
1657
+ if (started)
1658
+ return true;
1659
+ return fallback(error instanceof Error ? error.message : String(error));
1660
+ }
1661
+ }
1662
+ function quoteWindowsArgument(argument) {
1663
+ return `"${argument.replace(/(\\*)"/g, "$1$1\\\"").replace(/(\\+)$/, "$1$1")}"`;
1664
+ }
1665
+ function windowsCommandLine(executable, args) {
1666
+ return [executable, ...args].map(quoteWindowsArgument).join(" ");
1667
+ }
1668
+ function windowsEnvironmentBlock(env) {
1669
+ const entries = new Map;
1670
+ for (const [name, value] of Object.entries(env)) {
1671
+ if (value === undefined || name === "" || name.includes("=") || name.includes("\x00"))
1672
+ continue;
1673
+ entries.set(name.toUpperCase(), [name, value]);
1674
+ }
1675
+ const sorted = [...entries.values()].sort(([left], [right]) => {
1676
+ const a = left.toUpperCase();
1677
+ const b = right.toUpperCase();
1678
+ return a < b ? -1 : a > b ? 1 : 0;
1679
+ });
1680
+ return sorted.length === 0 ? "\x00\x00" : `${sorted.map(([name, value]) => `${name}=${value}\x00`).join("")}\x00`;
1681
+ }
1682
+ function wideZ(value) {
1683
+ return Buffer.from(`${value}\x00`, "utf16le");
1684
+ }
1685
+
1510
1686
  // src/relay/lifecycle.ts
1511
- var loadedCliEntrypoint = compiledBinary() ? process2.execPath : fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "../main.ts" : "./cli.mjs", import.meta.url));
1687
+ var loadedCliEntrypoint = compiledBinary() ? process3.execPath : fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "../main.ts" : "./cli.mjs", import.meta.url));
1512
1688
  var clientInstanceId = crypto2.randomUUID();
1513
1689
  function shouldWaitForExtensionReconnect(readiness) {
1514
1690
  return readiness.started || readiness.waitForReconnect === true;
@@ -1734,18 +1910,20 @@ function stoppedRelayStatus(endpoint) {
1734
1910
  function statusCollections(status) {
1735
1911
  return status.sessions && status.targets ? { sessions: status.sessions, targets: status.targets } : undefined;
1736
1912
  }
1737
- function startManagedRelay(entrypoint = loadedCliEntrypoint, executable = process2.execPath, execArgv = process2.execArgv, options = {}) {
1913
+ function startManagedRelay(entrypoint = loadedCliEntrypoint, executable = process3.execPath, execArgv = process3.execArgv, options = {}) {
1738
1914
  return try_2({
1739
1915
  try: () => {
1740
1916
  if (!entrypoint) {
1741
1917
  throw new Error("Cannot locate the browse CLI entrypoint");
1742
1918
  }
1743
1919
  const launch = managedRelayLaunch(entrypoint, executable, execArgv);
1744
- const { OPENCODE_BROWSER_RESTART_REQUEST_ID: _inheritedRestartRequestId, ...env } = relayEnvironment(process2.env);
1920
+ const env = Object.fromEntries(Object.entries(relayEnvironment(process3.env)).filter(([name]) => name.toUpperCase() !== "OPENCODE_BROWSER_RESTART_REQUEST_ID"));
1745
1921
  const childEnv = { ...env, OPENCODE_BROWSER_MANAGED_RELAY: "1", ...options.restartRequestId ? { OPENCODE_BROWSER_RESTART_REQUEST_ID: options.restartRequestId } : {} };
1746
- if (process2.platform === "win32") {
1747
- const args = launch.args.map((s) => `"${s.replace(/(\\*)"/g, "$1$1\\\"").replace(/(\\+)$/, "$1$1")}"`).join(" ");
1748
- execFileSync(path.join(process2.env.SystemRoot, "System32/WindowsPowerShell/v1.0/powershell.exe"), ["-NoProfile", "-NonInteractive", "-Command", "Start-Process -ErrorAction Stop -WindowStyle Hidden -FilePath $env:BROWSE_EXE -ArgumentList $env:BROWSE_ARGS"], { env: { ...childEnv, BROWSE_EXE: launch.executable, BROWSE_ARGS: args }, windowsHide: true, stdio: "ignore" });
1922
+ if (process3.platform === "win32") {
1923
+ if (launchWindowsRelay(launch, childEnv, (reason) => relayLog("relay.launch.fallback", { executable: launch.executable, reason })))
1924
+ return;
1925
+ const args = launch.args.map(quoteWindowsArgument).join(" ");
1926
+ execFileSync(path3.join(process3.env.SystemRoot, "System32/WindowsPowerShell/v1.0/powershell.exe"), ["-NoProfile", "-NonInteractive", "-Command", "Start-Process -ErrorAction Stop -WindowStyle Hidden -FilePath $env:BROWSE_EXE -ArgumentList $env:BROWSE_ARGS"], { env: { ...childEnv, BROWSE_EXE: launch.executable, BROWSE_ARGS: args }, windowsHide: true, stdio: "ignore" });
1749
1927
  return;
1750
1928
  }
1751
1929
  const child = spawn(launch.executable, launch.args, {
@@ -1809,7 +1987,7 @@ function relayEnvironment(env) {
1809
1987
  return relayEnvironmentNames.has(upper) || relayEnvironmentPrefixes.some((prefix) => upper.startsWith(prefix));
1810
1988
  }));
1811
1989
  }
1812
- function managedRelayLaunch(entrypoint = loadedCliEntrypoint, executable = process2.execPath, execArgv = process2.execArgv) {
1990
+ function managedRelayLaunch(entrypoint = loadedCliEntrypoint, executable = process3.execPath, execArgv = process3.execArgv) {
1813
1991
  if (!scriptEntry(entrypoint))
1814
1992
  return { executable: entrypoint, args: ["serve"] };
1815
1993
  return {
@@ -1818,9 +1996,9 @@ function managedRelayLaunch(entrypoint = loadedCliEntrypoint, executable = proce
1818
1996
  };
1819
1997
  }
1820
1998
  function managedRelayEntrypoint(entrypoint) {
1821
- const name = path.basename(entrypoint);
1999
+ const name = path3.basename(entrypoint);
1822
2000
  if (name === "index.ts" || name === "opencode-browser-client.ts" || name === "cli.ts")
1823
- return path.join(path.dirname(entrypoint), "main.ts");
2001
+ return path3.join(path3.dirname(entrypoint), "main.ts");
1824
2002
  return entrypoint;
1825
2003
  }
1826
2004
  function isRelayUnreachable(error) {
@@ -1833,4 +2011,4 @@ function isRelayStartingOrUnreachable(error) {
1833
2011
  return isRelayStarting(error) || isRelayUnreachable(error);
1834
2012
  }
1835
2013
 
1836
- export { withDefault, option, String2, Int, Boolean2, SessionContainer, SessionsContainer, SessionDeleted, SessionResetResponse, ExecuteRequest, SessionAdoptRequest, SessionNewRequest, SessionEnsureRequest, SessionIdRequest, SessionAllowlistRequest, SessionAdoptResponse, ExecuteLogEntry, ExecuteLogSummary, ExecuteAftermath, AuthenticatedJsonRequest, AuthenticatedJsonOutcome, ExtensionStatus, RelayVersion, RelayShutdownRequest, NetworkStartRequest, NetworkSessionRequest, NetworkStopRequest, AuthProfileSummary, NetworkStopResponse, AuthProfileRequest, AuthRefreshRequest, AuthRunRequest, AuthRunResponse, RecordingQuality, RecordingTargetRequest, RecordingStartRequest, TabsCleanupResponse, SettingsGetResponse, SettingsSetResponse, FlightRecorderStartRequest, FlightRecorderSaveRequest, HttpRouteError2, formatHostForUrl2, listenHttpServer2, closeHttpServer2, closeWebSocketServer2, logCloseError2, sendJson2, readJsonBody2, stableUnpackedExtensionOrigin2, chromeExtensionOriginForPath2, parseAdditionalExtensionOrigins2, validateHostHeader2, validateBrowserFetchSite2, validateWebSocketOrigin2, defaultHost2, defaultPort2, optionalSessionId2, isValidSessionId2, requiredSessionId2, parseTargetSelection2, generateSessionId2, sendCdpResponse2, sendCdpEvent2, getObject2, getString2, createTargetUrl2, getNumber2, getIdText2, headerValue2, getTargetInfo2, isRestrictedTarget2, isRestrictedUrl2, dataUrlDocument2, portConfig, extensionOriginsConfig, endpointForPort, RelayUnreachable, RelayRejected, Service, layerFetch, layerFetchMcp, shouldWaitForExtensionReconnect, relayBuildProblem, ensureRelay, restartRelay, extensionReconnectWaitMs, ensureExtensionConnected, stoppedRelayStatus, statusCollections, startManagedRelay };
2014
+ export { withDefault, option, String2, Int, Boolean2, SessionContainer, SessionsContainer, SessionDeleted, SessionResetResponse, ExecuteRequest, SessionAdoptRequest, SessionNewRequest, SessionEnsureRequest, SessionIdRequest, SessionAllowlistRequest, SessionAdoptResponse, ExecuteLogEntry, ExecuteLogSummary, ExecuteAftermath, AuthenticatedJsonRequest, AuthenticatedJsonOutcome, ExtensionStatus, RelayVersion, RelayShutdownRequest, NetworkStartRequest, NetworkSessionRequest, NetworkStopRequest, AuthProfileSummary, NetworkStopResponse, AuthProfileRequest, AuthRefreshRequest, AuthRunRequest, AuthRunResponse, RecordingQuality, RecordingTargetRequest, RecordingStartRequest, TabsCleanupResponse, SettingsGetResponse, SettingsSetResponse, FlightRecorderStartRequest, FlightRecorderSaveRequest, HttpRouteError2, formatHostForUrl2, listenHttpServer2, closeHttpServer2, closeWebSocketServer2, logCloseError2, sendJson2, readJsonBody2, stableUnpackedExtensionOrigin2, chromeExtensionOriginForPath2, parseAdditionalExtensionOrigins2, validateHostHeader2, validateBrowserFetchSite2, validateWebSocketOrigin2, defaultHost2, defaultPort2, optionalSessionId2, isValidSessionId2, requiredSessionId2, parseTargetSelection2, generateSessionId2, sendCdpResponse2, sendCdpEvent2, getObject2, getString2, createTargetUrl2, getNumber2, getIdText2, headerValue2, getTargetInfo2, isRestrictedTarget2, isRestrictedUrl2, dataUrlDocument2, portConfig, extensionOriginsConfig, endpointForPort, RelayUnreachable, RelayRejected, Service, layerFetch, layerFetchMcp, appendManagedRelayProcessLog, relayLog, shouldWaitForExtensionReconnect, relayBuildProblem, ensureRelay, restartRelay, extensionReconnectWaitMs, ensureExtensionConnected, stoppedRelayStatus, statusCollections, startManagedRelay };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./main-4h7rfhhr.mjs";
4
4
  import {
5
5
  isValidSessionId2
6
- } from "./main-aqdqrj4m.mjs";
6
+ } from "./main-ttge8j3c.mjs";
7
7
  import {
8
8
  decodeUnknownOption,
9
9
  optionalKey,
@@ -19,7 +19,7 @@ import {
19
19
  } from "./main-xycdhwqs.mjs";
20
20
  import {
21
21
  stateRoot
22
- } from "./main-a6x41zxr.mjs";
22
+ } from "./main-s8p6mgme.mjs";
23
23
 
24
24
  // src/session-manager/journal.ts
25
25
  import fs from "node:fs";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  dataRoot,
6
6
  stateRoot
7
- } from "./main-a6x41zxr.mjs";
7
+ } from "./main-s8p6mgme.mjs";
8
8
 
9
9
  // src/relay/browser-pairing.ts
10
10
  import crypto from "node:crypto";
@@ -45,11 +45,11 @@ import {
45
45
  } from "./main-bc8cjey0.mjs";
46
46
  import {
47
47
  opencodeBrowserVersion2
48
- } from "./main-n77bcfj8.mjs";
48
+ } from "./main-4pt08reg.mjs";
49
49
  import {
50
50
  cliCommand,
51
51
  autoUpdateStatus
52
- } from "./main-a6x41zxr.mjs";
52
+ } from "./main-s8p6mgme.mjs";
53
53
  import"./main-b3jrctcx.mjs";
54
54
  import {
55
55
  option,
@@ -69,12 +69,12 @@ import {
69
69
  relayBuildProblem,
70
70
  ensureRelay,
71
71
  ensureExtensionConnected
72
- } from "./main-aqdqrj4m.mjs";
72
+ } from "./main-ttge8j3c.mjs";
73
73
  import"./main-4h7rfhhr.mjs";
74
74
  import {
75
75
  updateJson2,
76
76
  createUpdateWatcher2
77
- } from "./main-ppp9k1gv.mjs";
77
+ } from "./main-5d6tc78f.mjs";
78
78
  import {
79
79
  settingSpecs,
80
80
  securityVariables,
@@ -155,12 +155,12 @@ import {
155
155
  toolResultForValue2,
156
156
  mcpErrorMessage2,
157
157
  toolResult
158
- } from "./main-eqpe2r3r.mjs";
158
+ } from "./main-nf1jjqr6.mjs";
159
159
  import {
160
160
  makeUnsafe,
161
161
  make3,
162
162
  listSecrets
163
- } from "./main-p31nga7a.mjs";
163
+ } from "./main-jqerqpen.mjs";
164
164
  import {
165
165
  Clock,
166
166
  type,
@@ -175,7 +175,7 @@ import {
175
175
  orElse,
176
176
  exhaustive
177
177
  } from "./main-4074weqb.mjs";
178
- import"./main-5hhgehca.mjs";
178
+ import"./main-2be5p7he.mjs";
179
179
  import {
180
180
  Class,
181
181
  taggedEnum,
@@ -6,8 +6,8 @@ import {
6
6
  browseServerCommand,
7
7
  editAgentConfig,
8
8
  configureMcp
9
- } from "./main-8126mrjm.mjs";
10
- import"./main-n77bcfj8.mjs";
9
+ } from "./main-d5r6evna.mjs";
10
+ import"./main-4pt08reg.mjs";
11
11
  import {
12
12
  configRoot2,
13
13
  dataRoot,
@@ -15,9 +15,10 @@ import {
15
15
  cacheRoot,
16
16
  binRoot,
17
17
  binaryName
18
- } from "./main-a6x41zxr.mjs";
18
+ } from "./main-s8p6mgme.mjs";
19
+ import"./main-tk4axre7.mjs";
19
20
  import"./main-4h7rfhhr.mjs";
20
- import"./main-kx4ygn02.mjs";
21
+ import"./main-yy5d2qyc.mjs";
21
22
  import"./main-b3jrctcx.mjs";
22
23
  import {
23
24
  legacyDataRoot,