@opencode/browse 0.0.18-dev.192 → 0.0.18-dev.198

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 (41) hide show
  1. package/dist/cli.mjs +62 -107
  2. package/package.json +13 -33
  3. package/dist/Runtime-tvxdkp60.mjs +0 -16
  4. package/dist/THIRD_PARTY_NOTICES.txt +0 -310
  5. package/dist/Undici-xgvbtsb1.mjs +0 -25295
  6. package/dist/cli-54nftqxr.mjs +0 -5939
  7. package/dist/coreBundle-mbshhes2.mjs +0 -8
  8. package/dist/helpers-yksnc17b.mjs +0 -70
  9. package/dist/index-kmxtpxxk.mjs +0 -13
  10. package/dist/legacy-runtime-e6y2jnc6.mjs +0 -134
  11. package/dist/main-4fw36c57.mjs +0 -160
  12. package/dist/main-4wycvga6.mjs +0 -797
  13. package/dist/main-c9qxrdzn.mjs +0 -73
  14. package/dist/main-d1th6z2h.mjs +0 -5395
  15. package/dist/main-de0xhbg0.mjs +0 -1269
  16. package/dist/main-dyya6jpy.mjs +0 -140
  17. package/dist/main-gexpjhk5.mjs +0 -32
  18. package/dist/main-h65pjrag.mjs +0 -11403
  19. package/dist/main-hh16893t.mjs +0 -5358
  20. package/dist/main-j98fzrvv.mjs +0 -68
  21. package/dist/main-jtgan144.mjs +0 -327
  22. package/dist/main-p44hff2a.mjs +0 -213
  23. package/dist/main-p8jk5985.mjs +0 -1750
  24. package/dist/main-p8q3wrpd.mjs +0 -342
  25. package/dist/main-pmfd055v.mjs +0 -63
  26. package/dist/main-q5w61fgh.mjs +0 -17
  27. package/dist/main-t8hspw29.mjs +0 -922
  28. package/dist/main-t8xtycpr.mjs +0 -227
  29. package/dist/main-tk4axre7.mjs +0 -39
  30. package/dist/main-w6180mxa.mjs +0 -161
  31. package/dist/main-wds0wcmt.mjs +0 -4
  32. package/dist/main-z4c819pg.mjs +0 -5512
  33. package/dist/main-zrjcdksk.mjs +0 -62
  34. package/dist/mcp-a2jkny55.mjs +0 -9466
  35. package/dist/migrate-p84kbr3y.mjs +0 -353
  36. package/dist/relay-e9q9hfc3.mjs +0 -18369
  37. package/dist/remove-stored-secrets-c90a5h72.mjs +0 -6
  38. package/dist/runtime-update-jj6pa7vd.mjs +0 -244
  39. package/dist/setup-p86ywb7k.mjs +0 -1051
  40. package/dist/update-rh24h3m1.mjs +0 -17
  41. package/dist/version-1p8wpyzk.mjs +0 -8
@@ -1,8 +0,0 @@
1
- // src/execute/coreBundle.ts
2
- import { chromium, errors, selectors } from "patchright-core";
3
- import { default as default2 } from "patchright-core/lib/coreBundle";
4
- export {
5
- chromium,
6
- errors,
7
- default2 as internals
8
- };
@@ -1,70 +0,0 @@
1
- import {
2
- HttpRouteError2,
3
- formatHostForUrl2,
4
- listenHttpServer2,
5
- closeHttpServer2,
6
- closeWebSocketServer2,
7
- logCloseError2,
8
- sendJson2,
9
- readJsonBody2,
10
- stableUnpackedExtensionOrigin2,
11
- chromeExtensionOriginForPath2,
12
- parseAdditionalExtensionOrigins2,
13
- validateHostHeader2,
14
- validateBrowserFetchSite2,
15
- validateWebSocketOrigin2,
16
- defaultHost2,
17
- defaultPort2,
18
- optionalSessionId2,
19
- isValidSessionId2,
20
- requiredSessionId2,
21
- parseTargetSelection2,
22
- generateSessionId2,
23
- sendCdpResponse2,
24
- sendCdpEvent2,
25
- getObject2,
26
- getString2,
27
- createTargetUrl2,
28
- getNumber2,
29
- getIdText2,
30
- headerValue2,
31
- getTargetInfo2,
32
- isRestrictedTarget2,
33
- isRestrictedUrl2,
34
- dataUrlDocument2
35
- } from "./main-t8hspw29.mjs";
36
- export {
37
- HttpRouteError2 as HttpRouteError,
38
- chromeExtensionOriginForPath2 as chromeExtensionOriginForPath,
39
- closeHttpServer2 as closeHttpServer,
40
- closeWebSocketServer2 as closeWebSocketServer,
41
- createTargetUrl2 as createTargetUrl,
42
- dataUrlDocument2 as dataUrlDocument,
43
- defaultHost2 as defaultHost,
44
- defaultPort2 as defaultPort,
45
- formatHostForUrl2 as formatHostForUrl,
46
- generateSessionId2 as generateSessionId,
47
- getIdText2 as getIdText,
48
- getNumber2 as getNumber,
49
- getObject2 as getObject,
50
- getString2 as getString,
51
- getTargetInfo2 as getTargetInfo,
52
- headerValue2 as headerValue,
53
- isRestrictedTarget2 as isRestrictedTarget,
54
- isRestrictedUrl2 as isRestrictedUrl,
55
- isValidSessionId2 as isValidSessionId,
56
- listenHttpServer2 as listenHttpServer,
57
- logCloseError2 as logCloseError,
58
- optionalSessionId2 as optionalSessionId,
59
- parseAdditionalExtensionOrigins2 as parseAdditionalExtensionOrigins,
60
- parseTargetSelection2 as parseTargetSelection,
61
- readJsonBody2 as readJsonBody,
62
- requiredSessionId2 as requiredSessionId,
63
- sendCdpEvent2 as sendCdpEvent,
64
- sendCdpResponse2 as sendCdpResponse,
65
- sendJson2 as sendJson,
66
- stableUnpackedExtensionOrigin2 as stableUnpackedExtensionOrigin,
67
- validateBrowserFetchSite2 as validateBrowserFetchSite,
68
- validateHostHeader2 as validateHostHeader,
69
- validateWebSocketOrigin2 as validateWebSocketOrigin
70
- };
@@ -1,13 +0,0 @@
1
- import {
2
- exports_NodeHttpClient,
3
- exports_NodeRuntime,
4
- exports_NodeStdio,
5
- exports_NodeServices
6
- } from "./main-hh16893t.mjs";
7
- import"./main-zrjcdksk.mjs";
8
- export {
9
- exports_NodeHttpClient as NodeHttpClient,
10
- exports_NodeRuntime as NodeRuntime,
11
- exports_NodeServices as NodeServices,
12
- exports_NodeStdio as NodeStdio
13
- };
@@ -1,134 +0,0 @@
1
- import"./main-t8hspw29.mjs";
2
- import {
3
- channelOf,
4
- installedRuntime2
5
- } from "./main-4wycvga6.mjs";
6
- import {
7
- legacyRuntimeActive,
8
- insidePath,
9
- samePath2
10
- } from "./main-pmfd055v.mjs";
11
- import {
12
- opencodeBrowserVersion2
13
- } from "./main-wds0wcmt.mjs";
14
- import {
15
- relayPortPinned,
16
- resolveRelayPort,
17
- probeRelayPort
18
- } from "./main-p44hff2a.mjs";
19
- import {
20
- installerBinaryPath,
21
- compiledBinary
22
- } from "./main-dyya6jpy.mjs";
23
-
24
- // src/setup/legacy-runtime.ts
25
- import fs from "node:fs";
26
- import net from "node:net";
27
- import os from "node:os";
28
- import path from "node:path";
29
- var FORWARDER = "// browse: this old runtime folder runs the current install";
30
- var legacyEntry = (root, version) => path.join(root, "runtime", "versions", version, "node_modules", "@opencode", "browse", "dist", "cli.mjs");
31
- function currentInstall(options = {}) {
32
- if (!(options.compiled ?? compiledBinary()))
33
- return installedRuntime2();
34
- const binary = installerBinaryPath(options.home);
35
- return realpath(binary) === realpath(options.execPath ?? process.execPath) ? { kind: "binary", entry: binary, version: opencodeBrowserVersion2 } : undefined;
36
- }
37
- var pending;
38
- async function prepareLegacyTakeover(legacy, options = {}) {
39
- const env = options.env ?? process.env;
40
- const install = "install" in options ? options.install : currentInstall();
41
- if (!legacy || !legacyRuntimeActive(legacy) || !install || install.kind === "npx" || insidePath(install.entry, legacy.root))
42
- return false;
43
- if (env.OPENCODE_BROWSER_HOME && !samePath2(env.OPENCODE_BROWSER_HOME, legacy.root))
44
- return false;
45
- const port = options.relayPort ?? (Number(env.OPENCODE_BROWSER_PORT) || resolveRelayPort());
46
- if (options.pinned ?? relayPortPinned(env)) {
47
- if (await portInUse(port))
48
- return false;
49
- } else {
50
- const owner = await probeRelayPort(port);
51
- if (owner === "browse" || owner === "nobody" && await portInUse(port))
52
- return false;
53
- }
54
- const home = options.home ?? os.homedir();
55
- const { copyLegacyData } = await import("./migrate-p84kbr3y.mjs");
56
- delete env.OPENCODE_BROWSER_HOME;
57
- copyLegacyData(home);
58
- pending = { legacy, install, home };
59
- return true;
60
- }
61
- async function commitLegacyTakeover(now = Date.now()) {
62
- if (!pending)
63
- return false;
64
- const { legacy, install, home } = pending;
65
- pending = undefined;
66
- try {
67
- if (!adoptLegacyRuntime(legacy, install, now))
68
- return false;
69
- const { migrateLegacy } = await import("./migrate-p84kbr3y.mjs");
70
- migrateLegacy(home, now);
71
- return true;
72
- } catch {
73
- return false;
74
- }
75
- }
76
- function adoptLegacyRuntime(legacy, runtime = currentInstall(), now = Date.now()) {
77
- if (!legacy || !legacyRuntimeActive(legacy) || !runtime || runtime.kind === "npx" || insidePath(runtime.entry, legacy.root))
78
- return false;
79
- const entry = legacyEntry(legacy.root, runtime.version);
80
- if (!fs.existsSync(entry) || fs.readFileSync(entry, "utf8").includes(FORWARDER))
81
- writeForwarder(entry, runtime);
82
- writeAtomic(path.join(legacy.root, "runtime", "current.json"), JSON.stringify({
83
- version: runtime.version,
84
- previous: legacy.version,
85
- channel: channelOf(runtime.version),
86
- switchedAt: new Date(now).toISOString(),
87
- movedTo: runtime.entry
88
- }, null, 2) + `
89
- `, 384);
90
- return true;
91
- }
92
- function writeForwarder(entry, runtime) {
93
- const packageDir = path.dirname(path.dirname(entry));
94
- fs.mkdirSync(path.dirname(entry), { recursive: true });
95
- writeAtomic(path.join(packageDir, "package.json"), JSON.stringify({ name: "@opencode/browse", version: runtime.version, private: true }) + `
96
- `);
97
- const target = JSON.stringify(runtime.entry);
98
- const run = runtime.kind === "binary" ? [
99
- `import { spawn } from "node:child_process"`,
100
- `const child = spawn(${target}, process.argv.slice(2), { stdio: "inherit" })`,
101
- `for (const signal of ["SIGTERM", "SIGINT"]) process.on(signal, () => child.kill(signal))`,
102
- `child.on("exit", (code, signal) => { process.exitCode = code ?? (signal ? 1 : 0) })`
103
- ] : [
104
- `import { pathToFileURL } from "node:url"`,
105
- `process.argv[1] = ${target}`,
106
- `await import(pathToFileURL(${target}).href)`
107
- ];
108
- writeAtomic(entry, ["#!/usr/bin/env node", `${FORWARDER} (${runtime.kind}). Don't edit.`, ...run, ""].join(`
109
- `));
110
- }
111
- function realpath(file) {
112
- try {
113
- return fs.realpathSync(file);
114
- } catch {
115
- return path.resolve(file);
116
- }
117
- }
118
- function portInUse(port) {
119
- return new Promise((resolve) => {
120
- const socket = net.connect({ host: "127.0.0.1", port });
121
- socket.setTimeout(1000, () => (socket.destroy(), resolve(true)));
122
- socket.once("connect", () => (socket.destroy(), resolve(true)));
123
- socket.once("error", (error) => resolve(error.code !== "ECONNREFUSED"));
124
- });
125
- }
126
- function writeAtomic(file, text, mode = 420) {
127
- const temporary = `${file}.${process.pid}.tmp`;
128
- fs.writeFileSync(temporary, text, { mode });
129
- fs.renameSync(temporary, file);
130
- }
131
- export {
132
- commitLegacyTakeover,
133
- prepareLegacyTakeover
134
- };
@@ -1,160 +0,0 @@
1
- import {
2
- writePrivateJsonFileSync
3
- } from "./main-t8hspw29.mjs";
4
- import {
5
- dataRoot,
6
- stateRoot
7
- } from "./main-dyya6jpy.mjs";
8
-
9
- // src/relay/browser-pairing.ts
10
- import crypto from "node:crypto";
11
- import fs from "node:fs";
12
- import path from "node:path";
13
- var legacyContext = "opencode-browser-pairing-v2";
14
- var context = "opencode-browser-pairing-v3";
15
- var crockford = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
16
- var pairingCodeLength = 8;
17
- var codeKeyIterations = 1e5;
18
- var codeKeySalt = `${context}|code`;
19
- var pairingCodeTtlMs = 10 * 60000;
20
- var bundledPairingCodeTtlMs = 60 * 60000;
21
- var maxPairingFailures = 5;
22
- var maxPendingCodes = 5;
23
- var extensionPairingFileName = "relay-pairing.json";
24
- var pairingCodesPath = (root = stateRoot()) => path.join(root, "pairing-codes.json");
25
- var browserTokensPath = (root = dataRoot()) => path.join(root, "browser-tokens.json");
26
- var legacyPairingCodePath = (root = dataRoot()) => path.join(root, "extension-pairing");
27
- function formatPairingCode(code) {
28
- return code.match(/.{1,4}/g)?.join("-") ?? code;
29
- }
30
- function pairingCodeKey(code) {
31
- return crypto.pbkdf2Sync(code, codeKeySalt, codeKeyIterations, 32, "sha256").toString("hex");
32
- }
33
- function readPendingCodes(root, now) {
34
- try {
35
- const value = JSON.parse(fs.readFileSync(pairingCodesPath(root), "utf8"));
36
- 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) : [];
37
- return { codes, failures: typeof value.failures === "number" ? value.failures : 0 };
38
- } catch {
39
- return { codes: [], failures: 0 };
40
- }
41
- }
42
- function writePendingCodes(root, pending) {
43
- if (pending.codes.length === 0 && pending.failures === 0) {
44
- fs.rmSync(pairingCodesPath(root), { force: true });
45
- return;
46
- }
47
- writePrivateJsonFileSync(pairingCodesPath(root), pending, { ensureParent: true });
48
- }
49
- function mintPairingCode(root = stateRoot(), options = {}) {
50
- const now = options.now ?? Date.now();
51
- const code = Array.from(crypto.randomBytes(pairingCodeLength), (byte) => crockford[byte & 31]).join("");
52
- const pending = readPendingCodes(root, now);
53
- pending.codes.push({ key: pairingCodeKey(code), expiresAt: now + (options.ttlMs ?? pairingCodeTtlMs), ...options.receipt ? { receipt: options.receipt } : {} });
54
- writePendingCodes(root, { codes: pending.codes.slice(-maxPendingCodes), failures: 0 });
55
- return code;
56
- }
57
- function pendingPairingCodeKeys(root = stateRoot(), now = Date.now()) {
58
- return readPendingCodes(root, now).codes.map((entry) => entry.key);
59
- }
60
- function consumePairingCode(key, root = stateRoot(), now = Date.now()) {
61
- const pending = readPendingCodes(root, now);
62
- writePendingCodes(root, { codes: pending.codes.filter((entry) => entry.key !== key), failures: 0 });
63
- return pending.codes.find((entry) => entry.key === key)?.receipt;
64
- }
65
- function recordPairingFailure(root = stateRoot(), now = Date.now()) {
66
- const pending = readPendingCodes(root, now);
67
- const failures = pending.failures + 1;
68
- const exhausted = failures >= maxPairingFailures;
69
- writePendingCodes(root, exhausted ? { codes: [], failures: 0 } : { codes: pending.codes, failures });
70
- return exhausted && pending.codes.length > 0;
71
- }
72
- function writeExtensionPairing(extensionDirectory, code, port) {
73
- writePrivateJsonFileSync(path.join(extensionDirectory, extensionPairingFileName), {
74
- code,
75
- ...port === undefined ? {} : { port }
76
- });
77
- }
78
- function readBrowserPairings(root = dataRoot()) {
79
- try {
80
- const value = JSON.parse(fs.readFileSync(browserTokensPath(root), "utf8"));
81
- if (value === null || typeof value !== "object" || Array.isArray(value))
82
- return {};
83
- return Object.fromEntries(Object.entries(value).filter(([, entry]) => typeof entry?.token === "string" && /^[A-Za-z0-9_-]{43}$/.test(entry.token)));
84
- } catch {
85
- return {};
86
- }
87
- }
88
- function writeBrowserPairings(root, pairings) {
89
- writePrivateJsonFileSync(browserTokensPath(root), pairings, { ensureParent: true });
90
- }
91
- function browserToken(key, root = dataRoot()) {
92
- return readBrowserPairings(root)[key]?.token;
93
- }
94
- var newBrowserToken = () => crypto.randomBytes(32).toString("base64url");
95
- function issueBrowserToken(key, root = dataRoot(), now = Date.now(), token = newBrowserToken(), receipt) {
96
- const pairings = readBrowserPairings(root);
97
- writeBrowserPairings(root, { ...pairings, [key]: { token, pairedAt: now, ...receipt ? { receipt } : {} } });
98
- return token;
99
- }
100
- function touchBrowserPairing(key, seen, root = dataRoot(), now = Date.now()) {
101
- const pairings = readBrowserPairings(root);
102
- const entry = pairings[key];
103
- if (!entry)
104
- return;
105
- writeBrowserPairings(root, { ...pairings, [key]: { ...entry, lastSeen: now, id: seen.id, name: seen.name } });
106
- }
107
- function revokeBrowserToken(key, root = dataRoot()) {
108
- const pairings = readBrowserPairings(root);
109
- if (!(key in pairings))
110
- return false;
111
- delete pairings[key];
112
- writeBrowserPairings(root, pairings);
113
- return true;
114
- }
115
- function legacyPairingCode(root = dataRoot()) {
116
- try {
117
- const code = fs.readFileSync(legacyPairingCodePath(root), "utf8").trim();
118
- return new RegExp(`^[${crockford}]{32}$`).test(code) ? code : undefined;
119
- } catch {
120
- return;
121
- }
122
- }
123
- function removeLegacyPairingCode(root = dataRoot()) {
124
- const existed = legacyPairingCode(root) !== undefined;
125
- fs.rmSync(legacyPairingCodePath(root), { force: true });
126
- return existed;
127
- }
128
- function legacyPairingProof(code, role, port, ownNonce, peerNonce) {
129
- return crypto.createHmac("sha256", code).update(`${legacyContext}|${role}|${pairingEndpoint(port)}|${peerNonce}|${ownNonce}`).digest("base64url");
130
- }
131
- function pairingEndpoint(port) {
132
- return `127.0.0.1:${port}/extension`;
133
- }
134
- function pairingProof(token, role, port, ownNonce, peerNonce) {
135
- return crypto.createHmac("sha256", token).update(`${context}|${role}|${pairingEndpoint(port)}|${peerNonce}|${ownNonce}`).digest("base64url");
136
- }
137
- function ecdhExchange(peerPublicKey) {
138
- const peer = Buffer.from(peerPublicKey, "base64url");
139
- if (peer.length !== 65 || peer[0] !== 4)
140
- return;
141
- const ecdh = crypto.createECDH("prime256v1");
142
- const publicKey = ecdh.generateKeys().toString("base64url");
143
- try {
144
- return { publicKey, secret: ecdh.computeSecret(peer) };
145
- } catch {
146
- return;
147
- }
148
- }
149
- function pairingSessionKey(material, secret, transcript) {
150
- return crypto.createHmac("sha256", material).update(`${context}|session|${pairingEndpoint(transcript.port)}|${transcript.extensionNonce}|${transcript.relayNonce}|${transcript.extensionKey}|${transcript.relayKey}|`).update(secret).digest();
151
- }
152
- function sessionProof(sessionKey, role) {
153
- return crypto.createHmac("sha256", sessionKey).update(`${context}|proof|${role}`).digest("base64url");
154
- }
155
- function wrapToken(sessionKey, token) {
156
- const mask = crypto.createHmac("sha256", sessionKey).update(`${context}|wrap`).digest();
157
- return Buffer.from(Buffer.from(token, "base64url").map((byte, index) => byte ^ mask[index])).toString("base64url");
158
- }
159
-
160
- export { context, pairingCodeTtlMs, bundledPairingCodeTtlMs, formatPairingCode, pairingCodeKey, mintPairingCode, pendingPairingCodeKeys, consumePairingCode, recordPairingFailure, writeExtensionPairing, readBrowserPairings, browserToken, newBrowserToken, issueBrowserToken, touchBrowserPairing, revokeBrowserToken, legacyPairingCode, removeLegacyPairingCode, legacyPairingProof, pairingProof, ecdhExchange, pairingSessionKey, sessionProof, wrapToken };