@opencode/browse 0.0.11-dev.76 → 0.0.11-dev.78

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 (33) hide show
  1. package/dist/{cli-qpkh40gh.mjs → cli-e9x2hzbm.mjs} +63 -52
  2. package/dist/cli.mjs +30 -19
  3. package/dist/{helpers-kp0j46jt.mjs → helpers-681ybn8r.mjs} +2 -2
  4. package/dist/{index-0dcypq31.mjs → index-yzz55kxm.mjs} +1 -1
  5. package/dist/{main-eej5z0y5.mjs → main-0yxzwqt8.mjs} +6 -6
  6. package/dist/main-1ja7rnnp.mjs +4 -0
  7. package/dist/main-3d4mj1xj.mjs +157 -0
  8. package/dist/main-4qeb707s.mjs +161 -0
  9. package/dist/{main-rt6g5418.mjs → main-8z9d979q.mjs} +15 -15
  10. package/dist/{main-nqmm7pdz.mjs → main-93xmqcr3.mjs} +47 -47
  11. package/dist/{main-gevbt7h7.mjs → main-csnx585b.mjs} +151 -151
  12. package/dist/{setup-j76yv51b.mjs → main-fkskfb8a.mjs} +3608 -4406
  13. package/dist/main-ftsbt0hk.mjs +73 -0
  14. package/dist/{main-brv9dhy5.mjs → main-gdvgbgce.mjs} +9 -9
  15. package/dist/{main-ajza8egc.mjs → main-mysz5yma.mjs} +44 -39
  16. package/dist/main-qzvstggv.mjs +465 -0
  17. package/dist/main-vgzr4689.mjs +61 -0
  18. package/dist/{mcp-sy8qgkyr.mjs → mcp-3v0wxzr5.mjs} +139 -138
  19. package/dist/migrate-5phz1hha.mjs +233 -0
  20. package/dist/{relay-ateyg5ax.mjs → relay-4chyv51v.mjs} +128 -123
  21. package/dist/runtime-update-pzazb7sh.mjs +156 -0
  22. package/dist/setup-5g5kza58.mjs +956 -0
  23. package/dist/{skill-text-x7sccp6h.mjs → skill-text-mrxy6zpc.mjs} +5 -4
  24. package/dist/{supervisor-0rvjpf4e.mjs → supervisor-bfrn5cxb.mjs} +38 -17
  25. package/dist/{update-rbd2025v.mjs → update-42j1j7w1.mjs} +3 -3
  26. package/dist/{version-4cjr3wpp.mjs → version-w0dwcyve.mjs} +1 -1
  27. package/package.json +1 -1
  28. package/skills/browse/SKILL.md +5 -4
  29. package/dist/main-7wgmq04v.mjs +0 -303
  30. package/dist/main-exnm62gg.mjs +0 -4
  31. package/dist/main-hm4fcpfz.mjs +0 -131
  32. package/dist/main-rn7hdcq2.mjs +0 -805
  33. package/dist/runtime-update-70gqzynp.mjs +0 -200
@@ -208,8 +208,9 @@ values between calls on \`state\`. A single run without an \`await\` is stopped
208
208
  about 2 seconds; split heavy loops with
209
209
  \`await new Promise(r => setTimeout(r, 0))\` or do the work in the page.
210
210
 
211
- It runs in a sandbox because a page can try to prompt-inject the agent writing
212
- it. There is no \`process\`, \`require\`, \`import()\`, \`eval\`, \`fs\`, \`os\`,
211
+ It runs in a restricted JavaScript realm, not a sandbox. It shares the relay's
212
+ process, so it is not a security boundary: treat code as running as you. There
213
+ is no \`process\`, \`require\`, \`import()\`, \`eval\`, \`fs\`, \`os\`,
213
214
  \`child_process\`, \`http\`/\`https\` or Node-side \`fetch\`, and Playwright internals,
214
215
  \`page.request\`, \`context.request\` and \`browser.browserType()\` are unavailable.
215
216
  Files go through \`files\` and Playwright file options, which accept absolute paths
@@ -273,8 +274,8 @@ browse refuses navigations to \`file:\`, \`chrome:\`, \`chrome-extension:\`,
273
274
  shared browser state, including browser close and cookie/cache clearing. Never
274
275
  work around those guardrails.
275
276
 
276
- Every execute is journaled under \`<data root>/sessions/<id>/journal.jsonl\`
277
- (\`~/.local/share/opencode-browser\` on macOS and Linux). Never place credentials
277
+ Every execute is journaled under \`<state root>/sessions/<id>/journal.jsonl\`
278
+ (\`~/.local/state/browse\` on macOS and Linux). Never place credentials
278
279
  directly in execute source.
279
280
 
280
281
  ## Network capture
@@ -1,30 +1,45 @@
1
- import"./main-exnm62gg.mjs";
1
+ import"./main-1ja7rnnp.mjs";
2
2
  import {
3
- versionEntry,
4
- readCurrent,
5
- npmRuntime
6
- } from "./main-rn7hdcq2.mjs";
3
+ entryCommand,
4
+ installedRuntime2,
5
+ installedVersion
6
+ } from "./main-qzvstggv.mjs";
7
7
 
8
8
  // src/mcp/supervisor.ts
9
9
  import { spawn } from "node:child_process";
10
- import { existsSync } from "node:fs";
10
+ import { existsSync, statSync } from "node:fs";
11
+ import path from "node:path";
11
12
  import { createInterface } from "node:readline";
12
13
  var directEnvironmentVariable = "OPENCODE_BROWSER_MCP_DIRECT";
14
+ var watchedFile = (runtime) => runtime.kind === "binary" ? runtime.entry : path.join(path.dirname(path.dirname(runtime.entry)), "package.json");
15
+ function versionReader(runtime, initial) {
16
+ let version = initial;
17
+ let stamp = "";
18
+ return () => {
19
+ try {
20
+ const stat = statSync(watchedFile(runtime));
21
+ const next = `${stat.mtimeMs}:${stat.size}`;
22
+ if (next === stamp)
23
+ return version;
24
+ stamp = next;
25
+ version = installedVersion(runtime) ?? version;
26
+ return version;
27
+ } catch {
28
+ return version;
29
+ }
30
+ };
31
+ }
13
32
  async function runBinaryMcp(args) {
14
- const runtime = npmRuntime();
15
- if (!runtime) {
33
+ const runtime = installedRuntime2();
34
+ if (!runtime || runtime.kind === "npx") {
16
35
  process.env[directEnvironmentVariable] = "1";
17
- const { runCli } = await import("./cli-qpkh40gh.mjs");
36
+ const { runCli } = await import("./cli-e9x2hzbm.mjs");
18
37
  return runCli();
19
38
  }
20
- const { layout } = runtime;
21
39
  const REPLAY = "opencode-browser-shim-initialize";
22
40
  const relayPort = Number(process.env.OPENCODE_BROWSER_PORT) || 19988;
23
- const current = () => readCurrent(layout)?.version ?? runtime.version;
24
- const command = (version) => {
25
- const entry = versionEntry(layout, version, true);
26
- return existsSync(entry) ? entry : runtime.current.binary ?? process.execPath;
27
- };
41
+ const current = versionReader(runtime, installedVersion(runtime) ?? runtime.version);
42
+ const command = () => runtime.entry;
28
43
  process.env.OPENCODE_BROWSER_MCP_SESSION ??= "mcp-" + Math.random().toString(16).slice(2, 10).padEnd(8, "0");
29
44
  process.env.OPENCODE_BROWSER_CLIENT_PID = String(process.pid);
30
45
  let version = current();
@@ -62,7 +77,8 @@ async function runBinaryMcp(args) {
62
77
  toChild(line);
63
78
  };
64
79
  const start = (replay) => {
65
- const next = spawn(command(version), ["mcp", ...args], { stdio: ["pipe", "pipe", "inherit"], env: { ...process.env, [directEnvironmentVariable]: "1" } });
80
+ const [file, ...prefix] = entryCommand(command());
81
+ const next = spawn(file, [...prefix, "mcp", ...args], { stdio: ["pipe", "pipe", "inherit"], env: { ...process.env, [directEnvironmentVariable]: "1" } });
66
82
  next.stdin.on("error", () => {});
67
83
  child = next;
68
84
  next.on("exit", (code, signal) => {
@@ -161,6 +177,11 @@ async function runBinaryMcp(args) {
161
177
  });
162
178
  setInterval(() => void maybeSwap(), 1000).unref();
163
179
  }
180
+ function supervisesMcp() {
181
+ const runtime = installedRuntime2();
182
+ return !!runtime && runtime.kind !== "npx" && existsSync(runtime.entry);
183
+ }
164
184
  export {
165
- runBinaryMcp
185
+ runBinaryMcp,
186
+ supervisesMcp
166
187
  };
@@ -4,10 +4,10 @@ import {
4
4
  updateNotice2,
5
5
  createUpdateWatcher2,
6
6
  runUpdateCommand2
7
- } from "./main-brv9dhy5.mjs";
7
+ } from "./main-gdvgbgce.mjs";
8
8
  import"./main-mrew6jy8.mjs";
9
- import"./main-rn7hdcq2.mjs";
10
- import"./main-exnm62gg.mjs";
9
+ import"./main-qzvstggv.mjs";
10
+ import"./main-1ja7rnnp.mjs";
11
11
  export {
12
12
  createUpdateWatcher2 as createUpdateWatcher,
13
13
  formatUpdateNotice2 as formatUpdateNotice,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  opencodeBrowserVersion2,
3
3
  opencodeBrowserBuildId2
4
- } from "./main-exnm62gg.mjs";
4
+ } from "./main-1ja7rnnp.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.11-dev.76",
3
+ "version": "0.0.11-dev.78",
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",
@@ -207,8 +207,9 @@ values between calls on `state`. A single run without an `await` is stopped afte
207
207
  about 2 seconds; split heavy loops with
208
208
  `await new Promise(r => setTimeout(r, 0))` or do the work in the page.
209
209
 
210
- It runs in a sandbox because a page can try to prompt-inject the agent writing
211
- it. There is no `process`, `require`, `import()`, `eval`, `fs`, `os`,
210
+ It runs in a restricted JavaScript realm, not a sandbox. It shares the relay's
211
+ process, so it is not a security boundary: treat code as running as you. There
212
+ is no `process`, `require`, `import()`, `eval`, `fs`, `os`,
212
213
  `child_process`, `http`/`https` or Node-side `fetch`, and Playwright internals,
213
214
  `page.request`, `context.request` and `browser.browserType()` are unavailable.
214
215
  Files go through `files` and Playwright file options, which accept absolute paths
@@ -272,8 +273,8 @@ browse refuses navigations to `file:`, `chrome:`, `chrome-extension:`,
272
273
  shared browser state, including browser close and cookie/cache clearing. Never
273
274
  work around those guardrails.
274
275
 
275
- Every execute is journaled under `<data root>/sessions/<id>/journal.jsonl`
276
- (`~/.local/share/opencode-browser` on macOS and Linux). Never place credentials
276
+ Every execute is journaled under `<state root>/sessions/<id>/journal.jsonl`
277
+ (`~/.local/state/browse` on macOS and Linux). Never place credentials
277
278
  directly in execute source.
278
279
 
279
280
  ## Network capture
@@ -1,303 +0,0 @@
1
- import {
2
- writePrivateJsonFileSync
3
- } from "./main-hm4fcpfz.mjs";
4
- import {
5
- dataRoot,
6
- devExtensionUrl,
7
- devExtensionFolder
8
- } from "./main-rn7hdcq2.mjs";
9
-
10
- // src/relay/browser-pairing.ts
11
- import crypto from "node:crypto";
12
- import fs from "node:fs";
13
- import path from "node:path";
14
- var legacyContext = "opencode-browser-pairing-v2";
15
- var context2 = "opencode-browser-pairing-v3";
16
- var crockford = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
17
- var pairingCodeLength = 8;
18
- var codeKeyIterations = 1e5;
19
- var codeKeySalt = `${context2}|code`;
20
- var pairingCodeTtlMs = 10 * 60000;
21
- var bundledPairingCodeTtlMs = 60 * 60000;
22
- var maxPairingFailures = 5;
23
- var maxPendingCodes = 5;
24
- var extensionPairingFileName = "relay-pairing.json";
25
- var pairingCodesPath = (root = dataRoot()) => path.join(root, "pairing-codes.json");
26
- var browserTokensPath = (root = dataRoot()) => path.join(root, "browser-tokens.json");
27
- var legacyPairingCodePath = (root = dataRoot()) => path.join(root, "extension-pairing");
28
- function formatPairingCode(code) {
29
- return code.match(/.{1,4}/g)?.join("-") ?? code;
30
- }
31
- function pairingCodeKey(code) {
32
- return crypto.pbkdf2Sync(code, codeKeySalt, codeKeyIterations, 32, "sha256").toString("hex");
33
- }
34
- function readPendingCodes(root, now) {
35
- try {
36
- const value = JSON.parse(fs.readFileSync(pairingCodesPath(root), "utf8"));
37
- const codes = Array.isArray(value.codes) ? value.codes.filter((entry) => typeof entry?.key === "string" && /^[0-9a-f]{64}$/.test(entry.key) && typeof entry.expiresAt === "number" && entry.expiresAt >= now) : [];
38
- return { codes, failures: typeof value.failures === "number" ? value.failures : 0 };
39
- } catch {
40
- return { codes: [], failures: 0 };
41
- }
42
- }
43
- function writePendingCodes(root, pending) {
44
- if (pending.codes.length === 0 && pending.failures === 0) {
45
- fs.rmSync(pairingCodesPath(root), { force: true });
46
- return;
47
- }
48
- writePrivateJsonFileSync(pairingCodesPath(root), pending, { ensureParent: true });
49
- }
50
- function mintPairingCode(root = dataRoot(), options = {}) {
51
- const now = options.now ?? Date.now();
52
- const code = Array.from(crypto.randomBytes(pairingCodeLength), (byte) => crockford[byte & 31]).join("");
53
- const pending = readPendingCodes(root, now);
54
- pending.codes.push({ key: pairingCodeKey(code), expiresAt: now + (options.ttlMs ?? pairingCodeTtlMs), ...options.receipt ? { receipt: options.receipt } : {} });
55
- writePendingCodes(root, { codes: pending.codes.slice(-maxPendingCodes), failures: 0 });
56
- return code;
57
- }
58
- function pendingPairingCodeKeys(root = dataRoot(), now = Date.now()) {
59
- return readPendingCodes(root, now).codes.map((entry) => entry.key);
60
- }
61
- function consumePairingCode(key, root = dataRoot(), now = Date.now()) {
62
- const pending = readPendingCodes(root, now);
63
- writePendingCodes(root, { codes: pending.codes.filter((entry) => entry.key !== key), failures: 0 });
64
- return pending.codes.find((entry) => entry.key === key)?.receipt;
65
- }
66
- function recordPairingFailure(root = dataRoot(), now = Date.now()) {
67
- const pending = readPendingCodes(root, now);
68
- const failures = pending.failures + 1;
69
- const exhausted = failures >= maxPairingFailures;
70
- writePendingCodes(root, exhausted ? { codes: [], failures: 0 } : { codes: pending.codes, failures });
71
- return exhausted && pending.codes.length > 0;
72
- }
73
- function writeExtensionPairing(extensionDirectory, code) {
74
- writePrivateJsonFileSync(path.join(extensionDirectory, extensionPairingFileName), { code });
75
- }
76
- function readBrowserPairings(root = dataRoot()) {
77
- try {
78
- const value = JSON.parse(fs.readFileSync(browserTokensPath(root), "utf8"));
79
- if (value === null || typeof value !== "object" || Array.isArray(value))
80
- return {};
81
- return Object.fromEntries(Object.entries(value).filter(([, entry]) => typeof entry?.token === "string" && /^[A-Za-z0-9_-]{43}$/.test(entry.token)));
82
- } catch {
83
- return {};
84
- }
85
- }
86
- function writeBrowserPairings(root, pairings) {
87
- writePrivateJsonFileSync(browserTokensPath(root), pairings, { ensureParent: true });
88
- }
89
- function browserToken(key, root = dataRoot()) {
90
- return readBrowserPairings(root)[key]?.token;
91
- }
92
- var newBrowserToken = () => crypto.randomBytes(32).toString("base64url");
93
- function issueBrowserToken(key, root = dataRoot(), now = Date.now(), token = newBrowserToken(), receipt) {
94
- const pairings = readBrowserPairings(root);
95
- writeBrowserPairings(root, { ...pairings, [key]: { token, pairedAt: now, ...receipt ? { receipt } : {} } });
96
- return token;
97
- }
98
- function touchBrowserPairing(key, seen, root = dataRoot(), now = Date.now()) {
99
- const pairings = readBrowserPairings(root);
100
- const entry = pairings[key];
101
- if (!entry)
102
- return;
103
- writeBrowserPairings(root, { ...pairings, [key]: { ...entry, lastSeen: now, id: seen.id, name: seen.name } });
104
- }
105
- function revokeBrowserToken(key, root = dataRoot()) {
106
- const pairings = readBrowserPairings(root);
107
- if (!(key in pairings))
108
- return false;
109
- delete pairings[key];
110
- writeBrowserPairings(root, pairings);
111
- return true;
112
- }
113
- function legacyPairingCode(root = dataRoot()) {
114
- try {
115
- const code = fs.readFileSync(legacyPairingCodePath(root), "utf8").trim();
116
- return new RegExp(`^[${crockford}]{32}$`).test(code) ? code : undefined;
117
- } catch {
118
- return;
119
- }
120
- }
121
- function removeLegacyPairingCode(root = dataRoot()) {
122
- const existed = legacyPairingCode(root) !== undefined;
123
- fs.rmSync(legacyPairingCodePath(root), { force: true });
124
- return existed;
125
- }
126
- function legacyPairingProof(code, role, port, ownNonce, peerNonce) {
127
- return crypto.createHmac("sha256", code).update(`${legacyContext}|${role}|${pairingEndpoint(port)}|${peerNonce}|${ownNonce}`).digest("base64url");
128
- }
129
- function pairingEndpoint(port) {
130
- return `127.0.0.1:${port}/extension`;
131
- }
132
- function pairingProof(token, role, port, ownNonce, peerNonce) {
133
- return crypto.createHmac("sha256", token).update(`${context2}|${role}|${pairingEndpoint(port)}|${peerNonce}|${ownNonce}`).digest("base64url");
134
- }
135
- function ecdhExchange(peerPublicKey) {
136
- const peer = Buffer.from(peerPublicKey, "base64url");
137
- if (peer.length !== 65 || peer[0] !== 4)
138
- return;
139
- const ecdh = crypto.createECDH("prime256v1");
140
- const publicKey = ecdh.generateKeys().toString("base64url");
141
- try {
142
- return { publicKey, secret: ecdh.computeSecret(peer) };
143
- } catch {
144
- return;
145
- }
146
- }
147
- function pairingSessionKey(material, secret, transcript) {
148
- return crypto.createHmac("sha256", material).update(`${context2}|session|${pairingEndpoint(transcript.port)}|${transcript.extensionNonce}|${transcript.relayNonce}|${transcript.extensionKey}|${transcript.relayKey}|`).update(secret).digest();
149
- }
150
- function sessionProof(sessionKey, role) {
151
- return crypto.createHmac("sha256", sessionKey).update(`${context2}|proof|${role}`).digest("base64url");
152
- }
153
- function wrapToken(sessionKey, token) {
154
- const mask = crypto.createHmac("sha256", sessionKey).update(`${context2}|wrap`).digest();
155
- return Buffer.from(Buffer.from(token, "base64url").map((byte, index) => byte ^ mask[index])).toString("base64url");
156
- }
157
-
158
- // src/setup/dev-extension.ts
159
- import { createHash } from "node:crypto";
160
- import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
161
- import path2 from "node:path";
162
- import { crc32, inflateRawSync } from "node:zlib";
163
- var devExtensionRecord = (root = dataRoot()) => path2.join(root, "extension.json");
164
- function installedDevExtension(root = dataRoot()) {
165
- try {
166
- const record = JSON.parse(readFileSync(devExtensionRecord(root), "utf8"));
167
- return typeof record.sha256 === "string" && existsSync(path2.join(devExtensionFolder(root), "manifest.json")) ? record : undefined;
168
- } catch {
169
- return;
170
- }
171
- }
172
- async function syncDevExtension(extension, options = {}) {
173
- const root = options.root ?? dataRoot();
174
- const folder = devExtensionFolder(root);
175
- if (installedDevExtension(root)?.sha256 === extension.sha256)
176
- return "current";
177
- const url = devExtensionUrl(extension, options.env);
178
- const response = await (options.fetch ?? fetch)(url, { signal: AbortSignal.timeout(120000), headers: { "user-agent": "browse/dev" } });
179
- if (!response.ok)
180
- throw new Error(`downloading the dev extension from ${url} failed: HTTP ${response.status}`);
181
- const zip = Buffer.from(await response.arrayBuffer());
182
- const sha256 = createHash("sha256").update(zip).digest("hex");
183
- if (zip.length !== extension.size || sha256 !== extension.sha256)
184
- throw new Error(`the dev extension from ${url} isn't the one this version was built with (sha256 ${sha256}, ${zip.length} bytes)`);
185
- mkdirSync(root, { recursive: true });
186
- const staging = path2.join(root, `.extension-${process.pid}-${Date.now()}`);
187
- const old = `${staging}-old`;
188
- rmSync(staging, { recursive: true, force: true });
189
- try {
190
- for (const entry of unzip(zip)) {
191
- const target = path2.join(staging, ...entry.name.split("/"));
192
- mkdirSync(path2.dirname(target), { recursive: true });
193
- if (!entry.directory)
194
- writeFileSync(target, entry.data);
195
- }
196
- const manifest = JSON.parse(readFileSync(path2.join(staging, "manifest.json"), "utf8"));
197
- if (!manifest.key)
198
- throw new Error("the dev extension has no manifest key, so it wouldn't have browse's unpacked ID");
199
- writeExtensionPairing(staging, mintPairingCode(root, { ttlMs: bundledPairingCodeTtlMs }));
200
- const build = (() => {
201
- try {
202
- return JSON.parse(readFileSync(path2.join(staging, "build.json"), "utf8")).build;
203
- } catch {
204
- return;
205
- }
206
- })();
207
- if (existsSync(folder))
208
- renameSync(folder, old);
209
- renameSync(staging, folder);
210
- const version = manifest.version_name ?? manifest.version;
211
- const record = { ...version ? { version } : {}, file: extension.file, sha256, ...build ? { build } : {}, installedAt: new Date().toISOString() };
212
- writeFileSync(devExtensionRecord(root), JSON.stringify(record, null, 2) + `
213
- `);
214
- return "updated";
215
- } finally {
216
- rmSync(staging, { recursive: true, force: true });
217
- rmSync(old, { recursive: true, force: true });
218
- }
219
- }
220
- function unzip(zip) {
221
- let end = -1;
222
- for (let offset = zip.length - 22;offset >= Math.max(0, zip.length - 22 - 65535); offset--)
223
- if (zip.readUInt32LE(offset) === 101010256) {
224
- end = offset;
225
- break;
226
- }
227
- if (end < 0)
228
- throw new Error("not a zip archive");
229
- const count = zip.readUInt16LE(end + 10);
230
- let offset = zip.readUInt32LE(end + 16);
231
- const entries = [];
232
- for (let index = 0;index < count; index++) {
233
- if (zip.readUInt32LE(offset) !== 33639248)
234
- throw new Error("corrupt zip central directory");
235
- const method = zip.readUInt16LE(offset + 10);
236
- const crc = zip.readUInt32LE(offset + 16);
237
- const compressed = zip.readUInt32LE(offset + 20);
238
- const size = zip.readUInt32LE(offset + 24);
239
- const nameLength = zip.readUInt16LE(offset + 28);
240
- const extraLength = zip.readUInt16LE(offset + 30);
241
- const commentLength = zip.readUInt16LE(offset + 32);
242
- const mode = zip.readUInt32LE(offset + 38) >>> 16;
243
- const local = zip.readUInt32LE(offset + 42);
244
- const name = zip.toString("utf8", offset + 46, offset + 46 + nameLength);
245
- offset += 46 + nameLength + extraLength + commentLength;
246
- if (!name || name.startsWith("/") || name.includes("\\") || name.split("/").some((part) => part === ".." || part === "."))
247
- throw new Error(`unsafe path in zip: ${JSON.stringify(name)}`);
248
- if ((mode & 61440) === 40960)
249
- throw new Error(`symbolic link in zip: ${name}`);
250
- if (compressed === 4294967295 || size === 4294967295)
251
- throw new Error("ZIP64 archives aren't supported");
252
- const directory = name.endsWith("/");
253
- if (directory) {
254
- entries.push({ name: name.slice(0, -1), directory, data: Buffer.alloc(0) });
255
- continue;
256
- }
257
- if (zip.readUInt32LE(local) !== 67324752)
258
- throw new Error(`corrupt zip entry ${name}`);
259
- const start = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
260
- const raw = zip.subarray(start, start + compressed);
261
- const data = method === 0 ? Buffer.from(raw) : method === 8 ? inflateRawSync(raw) : undefined;
262
- if (!data)
263
- throw new Error(`unsupported compression method ${method} for ${name}`);
264
- if (data.length !== size || crc32(data) !== crc)
265
- throw new Error(`zip entry ${name} is corrupt`);
266
- entries.push({ name, directory, data });
267
- }
268
- return entries;
269
- }
270
-
271
- // src/relay/config.ts
272
- import fs2 from "node:fs";
273
- import path3 from "node:path";
274
- var relayConfigPath = (root = dataRoot()) => path3.join(root, "config.json");
275
- function parseHostname(input) {
276
- if (typeof input !== "string")
277
- return;
278
- const value = input.trim().toLowerCase();
279
- if (value === "127.0.0.1" || value === "localhost")
280
- return "127.0.0.1";
281
- if (value === "0.0.0.0")
282
- return "0.0.0.0";
283
- return;
284
- }
285
- function readRelayConfig(root = dataRoot()) {
286
- try {
287
- const value = JSON.parse(fs2.readFileSync(relayConfigPath(root), "utf8"));
288
- const hostname = parseHostname(value?.hostname);
289
- return hostname === undefined ? {} : { hostname };
290
- } catch {
291
- return {};
292
- }
293
- }
294
- function writeRelayConfig(config, root = dataRoot()) {
295
- writePrivateJsonFileSync(relayConfigPath(root), config, { ensureParent: true });
296
- }
297
- var relayHostname = (root = dataRoot()) => readRelayConfig(root).hostname ?? "127.0.0.1";
298
- function isLocalPeer(socket) {
299
- const remote = socket.remoteAddress?.replace(/^::ffff:/, "");
300
- return remote !== undefined && (remote === "::1" || remote.startsWith("127."));
301
- }
302
-
303
- export { parseHostname, readRelayConfig, writeRelayConfig, relayHostname, isLocalPeer, context2, pairingCodeTtlMs, bundledPairingCodeTtlMs, formatPairingCode, pairingCodeKey, mintPairingCode, pendingPairingCodeKeys, consumePairingCode, recordPairingFailure, writeExtensionPairing, readBrowserPairings, browserToken, newBrowserToken, issueBrowserToken, touchBrowserPairing, revokeBrowserToken, legacyPairingCode, removeLegacyPairingCode, legacyPairingProof, pairingProof, ecdhExchange, pairingSessionKey, sessionProof, wrapToken, installedDevExtension, syncDevExtension };
@@ -1,4 +0,0 @@
1
- // src/version.ts
2
- var opencodeBrowserVersion2 = "0.0.11-dev.76";
3
- var opencodeBrowserBuildId2 = "2026-11-06T22:26:14.062Z";
4
- export { opencodeBrowserVersion2, opencodeBrowserBuildId2 };
@@ -1,131 +0,0 @@
1
- import {
2
- isString
3
- } from "./main-yf9xhpn4.mjs";
4
- import {
5
- dataRoot
6
- } from "./main-rn7hdcq2.mjs";
7
- // src/relay/secrets.ts
8
- import crypto2 from "node:crypto";
9
- import fs2 from "node:fs";
10
- import path2 from "node:path";
11
-
12
- // src/fs-durability.ts
13
- import crypto from "node:crypto";
14
- import fsSync from "node:fs";
15
- import fs from "node:fs/promises";
16
- import path from "node:path";
17
- var unsupportedDirectorySyncCodes = new Set(["EPERM", "EINVAL", "ENOTSUP"]);
18
- function isNodeError(error) {
19
- return error instanceof Error && "code" in error;
20
- }
21
- function isUnsupportedDirectorySyncError(error) {
22
- return isNodeError(error) && isString(error.code) && unsupportedDirectorySyncCodes.has(error.code);
23
- }
24
- async function writeJsonFileAtomically(filePath, value, options = {}) {
25
- const directory = path.dirname(filePath);
26
- await fs.mkdir(directory, {
27
- recursive: true,
28
- ...options.dirMode === undefined ? {} : { mode: options.dirMode }
29
- });
30
- if (options.dirMode !== undefined) {
31
- await fs.chmod(directory, options.dirMode);
32
- }
33
- const temporaryPath = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
34
- let renamed = false;
35
- try {
36
- await fs.writeFile(temporaryPath, `${JSON.stringify(value, null, 2)}
37
- `, { mode: 384 });
38
- await fs.rename(temporaryPath, filePath);
39
- renamed = true;
40
- await fs.chmod(filePath, 384);
41
- } finally {
42
- if (!renamed)
43
- await fs.rm(temporaryPath, { force: true }).catch(() => {});
44
- }
45
- }
46
- function ensurePrivateDirectorySync(directory) {
47
- fsSync.mkdirSync(directory, { recursive: true, mode: 448 });
48
- if (process.platform !== "win32")
49
- fsSync.chmodSync(directory, 448);
50
- }
51
- function writePrivateJsonFileSync(filePath, value, options = {}) {
52
- if (options.ensureParent)
53
- ensurePrivateDirectorySync(path.dirname(filePath));
54
- const temporaryPath = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
55
- let renamed = false;
56
- try {
57
- fsSync.writeFileSync(temporaryPath, `${JSON.stringify(value, null, 2)}
58
- `, { mode: 384 });
59
- fsSync.renameSync(temporaryPath, filePath);
60
- renamed = true;
61
- if (process.platform !== "win32")
62
- fsSync.chmodSync(filePath, 384);
63
- } finally {
64
- if (!renamed)
65
- fsSync.rmSync(temporaryPath, { force: true });
66
- }
67
- }
68
-
69
- // src/relay/secrets.ts
70
- var relayTokenQueryParam = "opencodeBrowserToken";
71
- var tokenPattern = /^[A-Za-z0-9_-]{43}$/;
72
- function relayTokenPath(root = dataRoot()) {
73
- return path2.join(root, "relay-token");
74
- }
75
- function relayToken(root = dataRoot()) {
76
- return readOrCreateSecret(relayTokenPath(root), () => crypto2.randomBytes(32).toString("base64url"), (value) => tokenPattern.test(value));
77
- }
78
- function relayAuthorization(root = dataRoot()) {
79
- return `Bearer ${relayToken(root)}`;
80
- }
81
- function secretsEqual(expected, actual) {
82
- if (actual === undefined)
83
- return false;
84
- const a = crypto2.createHash("sha256").update(expected).digest();
85
- const b = crypto2.createHash("sha256").update(actual).digest();
86
- return crypto2.timingSafeEqual(a, b) && expected.length === actual.length;
87
- }
88
- function readOrCreateSecret(file, generate, valid) {
89
- const existing = readSecret(file);
90
- if (existing !== undefined && valid(existing))
91
- return existing;
92
- ensurePrivateDirectory(path2.dirname(file));
93
- const temporary = `${file}.${process.pid}.${crypto2.randomUUID()}.tmp`;
94
- fs2.writeFileSync(temporary, `${generate()}
95
- `, { mode: 384 });
96
- try {
97
- if (existing === undefined) {
98
- try {
99
- fs2.linkSync(temporary, file);
100
- } catch (error) {
101
- if (error.code !== "EEXIST")
102
- throw error;
103
- }
104
- } else {
105
- fs2.renameSync(temporary, file);
106
- }
107
- } finally {
108
- fs2.rmSync(temporary, { force: true });
109
- }
110
- const created = readSecret(file);
111
- if (created === undefined || !valid(created))
112
- throw new Error(`Could not create ${file}`);
113
- return created;
114
- }
115
- function readSecret(file) {
116
- try {
117
- const stat = fs2.statSync(file);
118
- if (process.platform !== "win32" && (stat.mode & 63) !== 0)
119
- fs2.chmodSync(file, 384);
120
- return fs2.readFileSync(file, "utf8").trim();
121
- } catch (error) {
122
- if (error.code === "ENOENT")
123
- return;
124
- throw error;
125
- }
126
- }
127
- function ensurePrivateDirectory(directory = dataRoot()) {
128
- ensurePrivateDirectorySync(directory);
129
- }
130
-
131
- export { isNodeError, isUnsupportedDirectorySyncError, writeJsonFileAtomically, ensurePrivateDirectorySync, writePrivateJsonFileSync, relayTokenQueryParam, relayToken, relayAuthorization, secretsEqual, ensurePrivateDirectory };