@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
@@ -0,0 +1,157 @@
1
+ import {
2
+ writePrivateJsonFileSync
3
+ } from "./main-vgzr4689.mjs";
4
+ import {
5
+ dataRoot,
6
+ stateRoot
7
+ } from "./main-qzvstggv.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) {
73
+ writePrivateJsonFileSync(path.join(extensionDirectory, extensionPairingFileName), { code });
74
+ }
75
+ function readBrowserPairings(root = dataRoot()) {
76
+ try {
77
+ const value = JSON.parse(fs.readFileSync(browserTokensPath(root), "utf8"));
78
+ if (value === null || typeof value !== "object" || Array.isArray(value))
79
+ return {};
80
+ return Object.fromEntries(Object.entries(value).filter(([, entry]) => typeof entry?.token === "string" && /^[A-Za-z0-9_-]{43}$/.test(entry.token)));
81
+ } catch {
82
+ return {};
83
+ }
84
+ }
85
+ function writeBrowserPairings(root, pairings) {
86
+ writePrivateJsonFileSync(browserTokensPath(root), pairings, { ensureParent: true });
87
+ }
88
+ function browserToken(key, root = dataRoot()) {
89
+ return readBrowserPairings(root)[key]?.token;
90
+ }
91
+ var newBrowserToken = () => crypto.randomBytes(32).toString("base64url");
92
+ function issueBrowserToken(key, root = dataRoot(), now = Date.now(), token = newBrowserToken(), receipt) {
93
+ const pairings = readBrowserPairings(root);
94
+ writeBrowserPairings(root, { ...pairings, [key]: { token, pairedAt: now, ...receipt ? { receipt } : {} } });
95
+ return token;
96
+ }
97
+ function touchBrowserPairing(key, seen, root = dataRoot(), now = Date.now()) {
98
+ const pairings = readBrowserPairings(root);
99
+ const entry = pairings[key];
100
+ if (!entry)
101
+ return;
102
+ writeBrowserPairings(root, { ...pairings, [key]: { ...entry, lastSeen: now, id: seen.id, name: seen.name } });
103
+ }
104
+ function revokeBrowserToken(key, root = dataRoot()) {
105
+ const pairings = readBrowserPairings(root);
106
+ if (!(key in pairings))
107
+ return false;
108
+ delete pairings[key];
109
+ writeBrowserPairings(root, pairings);
110
+ return true;
111
+ }
112
+ function legacyPairingCode(root = dataRoot()) {
113
+ try {
114
+ const code = fs.readFileSync(legacyPairingCodePath(root), "utf8").trim();
115
+ return new RegExp(`^[${crockford}]{32}$`).test(code) ? code : undefined;
116
+ } catch {
117
+ return;
118
+ }
119
+ }
120
+ function removeLegacyPairingCode(root = dataRoot()) {
121
+ const existed = legacyPairingCode(root) !== undefined;
122
+ fs.rmSync(legacyPairingCodePath(root), { force: true });
123
+ return existed;
124
+ }
125
+ function legacyPairingProof(code, role, port, ownNonce, peerNonce) {
126
+ return crypto.createHmac("sha256", code).update(`${legacyContext}|${role}|${pairingEndpoint(port)}|${peerNonce}|${ownNonce}`).digest("base64url");
127
+ }
128
+ function pairingEndpoint(port) {
129
+ return `127.0.0.1:${port}/extension`;
130
+ }
131
+ function pairingProof(token, role, port, ownNonce, peerNonce) {
132
+ return crypto.createHmac("sha256", token).update(`${context}|${role}|${pairingEndpoint(port)}|${peerNonce}|${ownNonce}`).digest("base64url");
133
+ }
134
+ function ecdhExchange(peerPublicKey) {
135
+ const peer = Buffer.from(peerPublicKey, "base64url");
136
+ if (peer.length !== 65 || peer[0] !== 4)
137
+ return;
138
+ const ecdh = crypto.createECDH("prime256v1");
139
+ const publicKey = ecdh.generateKeys().toString("base64url");
140
+ try {
141
+ return { publicKey, secret: ecdh.computeSecret(peer) };
142
+ } catch {
143
+ return;
144
+ }
145
+ }
146
+ function pairingSessionKey(material, secret, transcript) {
147
+ return crypto.createHmac("sha256", material).update(`${context}|session|${pairingEndpoint(transcript.port)}|${transcript.extensionNonce}|${transcript.relayNonce}|${transcript.extensionKey}|${transcript.relayKey}|`).update(secret).digest();
148
+ }
149
+ function sessionProof(sessionKey, role) {
150
+ return crypto.createHmac("sha256", sessionKey).update(`${context}|proof|${role}`).digest("base64url");
151
+ }
152
+ function wrapToken(sessionKey, token) {
153
+ const mask = crypto.createHmac("sha256", sessionKey).update(`${context}|wrap`).digest();
154
+ return Buffer.from(Buffer.from(token, "base64url").map((byte, index) => byte ^ mask[index])).toString("base64url");
155
+ }
156
+
157
+ 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 };
@@ -0,0 +1,161 @@
1
+ import {
2
+ writePrivateJsonFileSync
3
+ } from "./main-vgzr4689.mjs";
4
+ import {
5
+ bundledPairingCodeTtlMs,
6
+ mintPairingCode,
7
+ writeExtensionPairing
8
+ } from "./main-3d4mj1xj.mjs";
9
+ import {
10
+ configRoot2,
11
+ cacheRoot,
12
+ devExtensionUrl,
13
+ devExtensionFolder
14
+ } from "./main-qzvstggv.mjs";
15
+
16
+ // src/setup/dev-extension.ts
17
+ import { createHash } from "node:crypto";
18
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
19
+ import path from "node:path";
20
+ import { crc32, inflateRawSync } from "node:zlib";
21
+ var devExtensionRecord = (root = cacheRoot()) => path.join(root, "extension.json");
22
+ function installedDevExtension(root = cacheRoot()) {
23
+ try {
24
+ const record = JSON.parse(readFileSync(devExtensionRecord(root), "utf8"));
25
+ return typeof record.sha256 === "string" && existsSync(path.join(devExtensionFolder(root), "manifest.json")) ? record : undefined;
26
+ } catch {
27
+ return;
28
+ }
29
+ }
30
+ async function syncDevExtension(extension, options = {}) {
31
+ const root = options.root ?? cacheRoot();
32
+ const folder = devExtensionFolder(root);
33
+ if (installedDevExtension(root)?.sha256 === extension.sha256)
34
+ return "current";
35
+ const url = devExtensionUrl(extension, options.env);
36
+ const response = await (options.fetch ?? fetch)(url, { signal: AbortSignal.timeout(120000), headers: { "user-agent": "browse/dev" } });
37
+ if (!response.ok)
38
+ throw new Error(`downloading the dev extension from ${url} failed: HTTP ${response.status}`);
39
+ const zip = Buffer.from(await response.arrayBuffer());
40
+ const sha256 = createHash("sha256").update(zip).digest("hex");
41
+ if (zip.length !== extension.size || sha256 !== extension.sha256)
42
+ throw new Error(`the dev extension from ${url} isn't the one this version was built with (sha256 ${sha256}, ${zip.length} bytes)`);
43
+ mkdirSync(root, { recursive: true });
44
+ const staging = path.join(root, `.extension-${process.pid}-${Date.now()}`);
45
+ const old = `${staging}-old`;
46
+ rmSync(staging, { recursive: true, force: true });
47
+ try {
48
+ for (const entry of unzip(zip)) {
49
+ const target = path.join(staging, ...entry.name.split("/"));
50
+ mkdirSync(path.dirname(target), { recursive: true });
51
+ if (!entry.directory)
52
+ writeFileSync(target, entry.data);
53
+ }
54
+ const manifest = JSON.parse(readFileSync(path.join(staging, "manifest.json"), "utf8"));
55
+ if (!manifest.key)
56
+ throw new Error("the dev extension has no manifest key, so it wouldn't have browse's unpacked ID");
57
+ writeExtensionPairing(staging, mintPairingCode(undefined, { ttlMs: bundledPairingCodeTtlMs }));
58
+ const build = (() => {
59
+ try {
60
+ return JSON.parse(readFileSync(path.join(staging, "build.json"), "utf8")).build;
61
+ } catch {
62
+ return;
63
+ }
64
+ })();
65
+ if (existsSync(folder))
66
+ renameSync(folder, old);
67
+ renameSync(staging, folder);
68
+ const version = manifest.version_name ?? manifest.version;
69
+ const record = { ...version ? { version } : {}, file: extension.file, sha256, ...build ? { build } : {}, installedAt: new Date().toISOString() };
70
+ writeFileSync(devExtensionRecord(root), JSON.stringify(record, null, 2) + `
71
+ `);
72
+ return "updated";
73
+ } finally {
74
+ rmSync(staging, { recursive: true, force: true });
75
+ rmSync(old, { recursive: true, force: true });
76
+ }
77
+ }
78
+ function unzip(zip) {
79
+ let end = -1;
80
+ for (let offset = zip.length - 22;offset >= Math.max(0, zip.length - 22 - 65535); offset--)
81
+ if (zip.readUInt32LE(offset) === 101010256) {
82
+ end = offset;
83
+ break;
84
+ }
85
+ if (end < 0)
86
+ throw new Error("not a zip archive");
87
+ const count = zip.readUInt16LE(end + 10);
88
+ let offset = zip.readUInt32LE(end + 16);
89
+ const entries = [];
90
+ for (let index = 0;index < count; index++) {
91
+ if (zip.readUInt32LE(offset) !== 33639248)
92
+ throw new Error("corrupt zip central directory");
93
+ const method = zip.readUInt16LE(offset + 10);
94
+ const crc = zip.readUInt32LE(offset + 16);
95
+ const compressed = zip.readUInt32LE(offset + 20);
96
+ const size = zip.readUInt32LE(offset + 24);
97
+ const nameLength = zip.readUInt16LE(offset + 28);
98
+ const extraLength = zip.readUInt16LE(offset + 30);
99
+ const commentLength = zip.readUInt16LE(offset + 32);
100
+ const mode = zip.readUInt32LE(offset + 38) >>> 16;
101
+ const local = zip.readUInt32LE(offset + 42);
102
+ const name = zip.toString("utf8", offset + 46, offset + 46 + nameLength);
103
+ offset += 46 + nameLength + extraLength + commentLength;
104
+ if (!name || name.startsWith("/") || name.includes("\\") || name.split("/").some((part) => part === ".." || part === "."))
105
+ throw new Error(`unsafe path in zip: ${JSON.stringify(name)}`);
106
+ if ((mode & 61440) === 40960)
107
+ throw new Error(`symbolic link in zip: ${name}`);
108
+ if (compressed === 4294967295 || size === 4294967295)
109
+ throw new Error("ZIP64 archives aren't supported");
110
+ const directory = name.endsWith("/");
111
+ if (directory) {
112
+ entries.push({ name: name.slice(0, -1), directory, data: Buffer.alloc(0) });
113
+ continue;
114
+ }
115
+ if (zip.readUInt32LE(local) !== 67324752)
116
+ throw new Error(`corrupt zip entry ${name}`);
117
+ const start = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
118
+ const raw = zip.subarray(start, start + compressed);
119
+ const data = method === 0 ? Buffer.from(raw) : method === 8 ? inflateRawSync(raw) : undefined;
120
+ if (!data)
121
+ throw new Error(`unsupported compression method ${method} for ${name}`);
122
+ if (data.length !== size || crc32(data) !== crc)
123
+ throw new Error(`zip entry ${name} is corrupt`);
124
+ entries.push({ name, directory, data });
125
+ }
126
+ return entries;
127
+ }
128
+
129
+ // src/relay/config.ts
130
+ import fs from "node:fs";
131
+ import path2 from "node:path";
132
+ var relayConfigPath = (root = configRoot2()) => path2.join(root, "config.json");
133
+ function parseHostname(input) {
134
+ if (typeof input !== "string")
135
+ return;
136
+ const value = input.trim().toLowerCase();
137
+ if (value === "127.0.0.1" || value === "localhost")
138
+ return "127.0.0.1";
139
+ if (value === "0.0.0.0")
140
+ return "0.0.0.0";
141
+ return;
142
+ }
143
+ function readRelayConfig(root = configRoot2()) {
144
+ try {
145
+ const value = JSON.parse(fs.readFileSync(relayConfigPath(root), "utf8"));
146
+ const hostname = parseHostname(value?.hostname);
147
+ return hostname === undefined ? {} : { hostname };
148
+ } catch {
149
+ return {};
150
+ }
151
+ }
152
+ function writeRelayConfig(config, root = configRoot2()) {
153
+ writePrivateJsonFileSync(relayConfigPath(root), config, { ensureParent: true });
154
+ }
155
+ var relayHostname = (root = configRoot2()) => readRelayConfig(root).hostname ?? "127.0.0.1";
156
+ function isLocalPeer(socket) {
157
+ const remote = socket.remoteAddress?.replace(/^::ffff:/, "");
158
+ return remote !== undefined && (remote === "::1" || remote.startsWith("127."));
159
+ }
160
+
161
+ export { parseHostname, readRelayConfig, writeRelayConfig, relayHostname, isLocalPeer, installedDevExtension, syncDevExtension };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  succeed,
3
- fail,
3
+ fail2,
4
4
  isResult,
5
5
  isSuccess,
6
6
  ClockRef,
7
- currentTimeMillis
8
- } from "./main-gevbt7h7.mjs";
7
+ currentTimeMillis2
8
+ } from "./main-csnx585b.mjs";
9
9
  import {
10
10
  pipeArguments,
11
11
  identity,
@@ -16,7 +16,7 @@ import {
16
16
 
17
17
  // node_modules/effect/dist/Clock.js
18
18
  var Clock = ClockRef;
19
- var currentTimeMillis2 = currentTimeMillis;
19
+ var currentTimeMillis = currentTimeMillis2;
20
20
 
21
21
  // node_modules/effect/dist/internal/matcher.js
22
22
  var TypeId = "~effect/Match/Matcher";
@@ -114,8 +114,8 @@ var makePredicate = (pattern) => {
114
114
  return (u) => u === pattern;
115
115
  };
116
116
  var type2 = () => makeTypeMatcher(identity, []);
117
- var value = (i) => makeValueMatcher(i, fail(i));
118
- var when = (pattern, f) => (self) => self.add(makeWhen(makePredicate(pattern), f));
117
+ var value2 = (i) => makeValueMatcher(i, fail2(i));
118
+ var when2 = (pattern, f) => (self) => self.add(makeWhen(makePredicate(pattern), f));
119
119
  var discriminator = (field) => (...pattern) => {
120
120
  const f = pattern[pattern.length - 1];
121
121
  const values = pattern.slice(0, -1);
@@ -126,9 +126,9 @@ var discriminators = (field) => (fields) => {
126
126
  const predicate = makeWhen((arg) => arg != null && Object.hasOwn(fields, arg[field]), (data) => fields[data[field]](data));
127
127
  return (self) => self.add(predicate);
128
128
  };
129
- var tag = /* @__PURE__ */ discriminator("_tag");
129
+ var tag2 = /* @__PURE__ */ discriminator("_tag");
130
130
  var tags2 = /* @__PURE__ */ discriminators("_tag");
131
- var is = (...literals) => {
131
+ var is2 = (...literals) => {
132
132
  const len = literals.length;
133
133
  return (u) => {
134
134
  for (let i = 0;i < len; i++) {
@@ -163,7 +163,7 @@ var result = (self) => {
163
163
  } else if (_case._tag === "Not" && _case.guard(input) === false) {
164
164
  return succeed(_case.evaluate(input, ...args));
165
165
  }
166
- return fail(input);
166
+ return fail2(input);
167
167
  };
168
168
  }
169
169
  return (...args) => {
@@ -176,7 +176,7 @@ var result = (self) => {
176
176
  return succeed(_case.evaluate(input, ...args));
177
177
  }
178
178
  }
179
- return fail(input);
179
+ return fail2(input);
180
180
  };
181
181
  };
182
182
  var getExhaustiveAbsurdErrorMessage = "effect/match/Match/exhaustive: absurd";
@@ -199,15 +199,15 @@ var exhaustive2 = (self) => {
199
199
 
200
200
  // node_modules/effect/dist/Match.js
201
201
  var type = type2;
202
- var value2 = value;
203
- var when2 = when;
204
- var tag2 = tag;
202
+ var value = value2;
203
+ var when = when2;
204
+ var tag = tag2;
205
205
  var tags = tags2;
206
- var is2 = is;
206
+ var is = is2;
207
207
  var string = isString;
208
208
  var number = isNumber;
209
209
  var boolean = isBoolean;
210
210
  var orElse = orElse2;
211
211
  var exhaustive = exhaustive2;
212
212
 
213
- export { Clock, currentTimeMillis2, type, value2, when2, tag2, tags, is2, string, number, boolean, orElse, exhaustive };
213
+ export { Clock, currentTimeMillis, type, value, when, tag, tags, is, string, number, boolean, orElse, exhaustive };