@opencode/browse 0.0.6-dev.17 → 0.0.6-dev.19

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.
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  isNodeError
3
- } from "./main-e4stqtf2.mjs";
3
+ } from "./main-75rdz6bc.mjs";
4
4
  import {
5
5
  dataRoot
6
- } from "./main-g5mke6rn.mjs";
6
+ } from "./main-yd50d95g.mjs";
7
7
  import {
8
8
  isValidSessionId2
9
- } from "./main-3qpkwaa7.mjs";
9
+ } from "./main-8a245rm1.mjs";
10
10
 
11
- // src/session-journal.ts
11
+ // src/session-manager/journal.ts
12
12
  import fs from "node:fs";
13
13
  import path from "node:path";
14
14
  import { Option, Schema } from "effect";
@@ -0,0 +1,4 @@
1
+ // src/version.ts
2
+ var opencodeBrowserVersion2 = "0.0.6-dev.19";
3
+ var opencodeBrowserBuildId2 = "2026-11-04T14:18:59.577Z";
4
+ export { opencodeBrowserVersion2, opencodeBrowserBuildId2 };
@@ -1,13 +1,13 @@
1
1
  import {
2
- ensurePrivateDirectory
3
- } from "./main-4bht27ry.mjs";
2
+ writePrivateJsonFileSync
3
+ } from "./main-75rdz6bc.mjs";
4
4
  import {
5
5
  dataRoot,
6
6
  devExtensionUrl,
7
7
  devExtensionFolder
8
- } from "./main-g5mke6rn.mjs";
8
+ } from "./main-yd50d95g.mjs";
9
9
 
10
- // src/browser-pairing.ts
10
+ // src/relay/browser-pairing.ts
11
11
  import crypto from "node:crypto";
12
12
  import fs from "node:fs";
13
13
  import path from "node:path";
@@ -45,7 +45,7 @@ function writePendingCodes(root, pending) {
45
45
  fs.rmSync(pairingCodesPath(root), { force: true });
46
46
  return;
47
47
  }
48
- writePrivateJson(pairingCodesPath(root), pending);
48
+ writePrivateJsonFileSync(pairingCodesPath(root), pending, { ensureParent: true });
49
49
  }
50
50
  function mintPairingCode(root = dataRoot(), options = {}) {
51
51
  const now = options.now ?? Date.now();
@@ -71,7 +71,7 @@ function recordPairingFailure(root = dataRoot(), now = Date.now()) {
71
71
  return exhausted && pending.codes.length > 0;
72
72
  }
73
73
  function writeExtensionPairing(extensionDirectory, code) {
74
- writePrivateJson(path.join(extensionDirectory, extensionPairingFileName), { code });
74
+ writePrivateJsonFileSync(path.join(extensionDirectory, extensionPairingFileName), { code });
75
75
  }
76
76
  function readBrowserPairings(root = dataRoot()) {
77
77
  try {
@@ -84,8 +84,7 @@ function readBrowserPairings(root = dataRoot()) {
84
84
  }
85
85
  }
86
86
  function writeBrowserPairings(root, pairings) {
87
- ensurePrivateDirectory(root);
88
- writePrivateJson(browserTokensPath(root), pairings);
87
+ writePrivateJsonFileSync(browserTokensPath(root), pairings, { ensureParent: true });
89
88
  }
90
89
  function browserToken(key, root = dataRoot()) {
91
90
  return readBrowserPairings(root)[key]?.token;
@@ -155,14 +154,8 @@ function wrapToken(sessionKey, token) {
155
154
  const mask = crypto.createHmac("sha256", sessionKey).update(`${context}|wrap`).digest();
156
155
  return Buffer.from(Buffer.from(token, "base64url").map((byte, index) => byte ^ mask[index])).toString("base64url");
157
156
  }
158
- function writePrivateJson(file, value) {
159
- const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
160
- fs.writeFileSync(temporary, `${JSON.stringify(value, null, 2)}
161
- `, { mode: 384 });
162
- fs.renameSync(temporary, file);
163
- }
164
157
 
165
- // src/dev-extension.ts
158
+ // src/setup/dev-extension.ts
166
159
  import { createHash } from "node:crypto";
167
160
  import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
168
161
  import path2 from "node:path";
@@ -275,7 +268,7 @@ function unzip(zip) {
275
268
  return entries;
276
269
  }
277
270
 
278
- // src/relay-config.ts
271
+ // src/relay/config.ts
279
272
  import fs2 from "node:fs";
280
273
  import path3 from "node:path";
281
274
  var relayConfigPath = (root = dataRoot()) => path3.join(root, "config.json");
@@ -299,12 +292,7 @@ function readRelayConfig(root = dataRoot()) {
299
292
  }
300
293
  }
301
294
  function writeRelayConfig(config, root = dataRoot()) {
302
- fs2.mkdirSync(root, { recursive: true, mode: 448 });
303
- const file = relayConfigPath(root);
304
- const temporary = `${file}.${process.pid}.tmp`;
305
- fs2.writeFileSync(temporary, `${JSON.stringify(config, null, 2)}
306
- `, { mode: 384 });
307
- fs2.renameSync(temporary, file);
295
+ writePrivateJsonFileSync(relayConfigPath(root), config, { ensureParent: true });
308
296
  }
309
297
  var relayHostname = (root = dataRoot()) => readRelayConfig(root).hostname ?? "127.0.0.1";
310
298
  function isLocalPeer(socket) {
@@ -1,113 +1,9 @@
1
- // src/protocol.ts
2
- var extensionProtocolVersion = 3;
3
- var minExtensionProtocolVersion = 3;
4
- var unpackedExtensionId = "afeafocngkodbmaipcngoamamfmekgfo";
5
- var unpackedReloadAdvice = "Reload Browse on your browser's extensions page (↻).";
6
- var checkoutReloadPrefix = "Extension protocol incompatible: extension-older; reload ";
7
- var extensionReconnectAlarmPeriodMs = 30000;
8
- var legacyExtensionProtocolVersion = 1;
9
- function extensionProtocolCompatibility(value) {
10
- const legacy = value === undefined;
11
- const valid = typeof value === "number" && Number.isSafeInteger(value) && value > 0;
12
- const version = valid ? value : legacy ? legacyExtensionProtocolVersion : null;
13
- return { version, compatible: version !== null && version >= minExtensionProtocolVersion && version <= extensionProtocolVersion, legacy };
14
- }
15
- function extensionProtocolSkew(version) {
16
- if (typeof version !== "number")
17
- return;
18
- if (version > extensionProtocolVersion)
19
- return "extension-newer";
20
- if (version < minExtensionProtocolVersion)
21
- return "extension-older";
22
- return;
23
- }
24
- function extensionProtocolAdvice(version, commands, distribution) {
25
- const skew = extensionProtocolSkew(version);
26
- const versions = `extension protocol ${version ?? "unknown"}, this relay speaks ${minExtensionProtocolVersion === extensionProtocolVersion ? extensionProtocolVersion : `${minExtensionProtocolVersion} to ${extensionProtocolVersion}`}`;
27
- if (skew === "extension-newer")
28
- return `The Browse extension is newer than this browse CLI (${versions}). Update the CLI: run \`${commands.install}\` (an npm install with automatic updates also catches up by itself within a day), then restart opencode.`;
29
- if (skew === "extension-older") {
30
- const store = "The Chrome Web Store updates it within a few hours (to update now, open chrome://extensions, turn on Developer mode and click Update).";
31
- const next = distribution === "unpacked" ? unpackedReloadAdvice : distribution === "store" ? store : `For an unpacked extension: ${unpackedReloadAdvice} For a store extension: ${store}`;
32
- return `The Browse extension is older than this browse CLI (${versions}). ${next}`;
33
- }
34
- return `The Browse extension and this browse CLI don't speak the same protocol (${versions}). Run \`${commands.install}\` again and update the extension.`;
35
- }
36
- function makePageStatus(options) {
37
- return {
38
- state: options.state,
39
- owner: options.targetOwner === "user" ? "user" : "session",
40
- ...options.sessionId ? { sessionId: options.sessionId } : {},
41
- ...options.sessionId && options.readOnly ? { readOnly: true } : {},
42
- ...options.message ? { message: options.message } : {},
43
- ...options.handoffId ? { handoffId: options.handoffId } : {},
44
- ...options.recording ? { recording: true } : {}
45
- };
46
- }
47
- var extensionCommandMethodValues = [
48
- "ping",
49
- "debugger.attach",
50
- "debugger.detach",
51
- "debugger.sendCommand",
52
- "tabs.create",
53
- "tabs.remove",
54
- "tabs.group",
55
- "tabs.ungroup",
56
- "action.setAttached",
57
- "action.setBadge",
58
- "pageStatus.set",
59
- "pageStatus.clear",
60
- "runtime.reload",
61
- "recording.start",
62
- "recording.stop",
63
- "recording.status",
64
- "recording.cancel",
65
- "tabs.cleanup",
66
- "update.notice",
67
- "relay.settings",
68
- "settings.get",
69
- "settings.set"
70
- ];
71
- var extensionEventMethodValues = [
72
- "protocol",
73
- "hello",
74
- "auth.code",
75
- "auth.response",
76
- "ready",
77
- "toolbar.clicked",
78
- "handoff.completed",
79
- "debugger.event",
80
- "debugger.attached",
81
- "debugger.detached",
82
- "tabs.removed",
83
- "tabs.opened",
84
- "pong",
85
- "log",
86
- "recording.cancelled",
87
- "pageStatus.requested",
88
- "settings"
89
- ];
90
- function parseJsonObject(input) {
91
- const parsed = JSON.parse(input);
92
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
93
- throw new Error("Expected JSON object");
94
- }
95
- return parsed;
96
- }
97
- var extensionCommandMethods = new Set(extensionCommandMethodValues);
98
- var extensionEventMethods = new Set(extensionEventMethodValues);
99
- function isCdpRequest(input) {
100
- return typeof input.id === "number" && typeof input.method === "string" && (input.params === undefined || isJsonObject(input.params)) && (input.sessionId === undefined || typeof input.sessionId === "string");
101
- }
102
- function isExtensionResponse(input) {
103
- return typeof input.id === "number" && (input.result === undefined || isJsonObject(input.result)) && (input.error === undefined || typeof input.error === "string") && !(input.result !== undefined && input.error !== undefined);
104
- }
105
- function isExtensionEvent(input) {
106
- return typeof input.method === "string" && extensionEventMethods.has(input.method) && (input.params === undefined || isJsonObject(input.params));
107
- }
108
- function isJsonObject(value) {
109
- return value !== null && typeof value === "object" && !Array.isArray(value);
110
- }
1
+ // src/update/auto-update.ts
2
+ import { spawn } from "node:child_process";
3
+ import { chmodSync, closeSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import path2 from "node:path";
6
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
111
7
 
112
8
  // src/paths.ts
113
9
  import fs from "node:fs";
@@ -147,7 +43,7 @@ function storeConfig(env = process.env, baked = { id: "mfnicocicmmlkpjnaffgihfjh
147
43
  return id ? { id } : {};
148
44
  }
149
45
  var RELEASE_SERVICE = "https://anoma.ly/release";
150
- function devExtension(baked = { file: "browse-extension-0.0.6-dev.17.zip", sha256: "8bf258faf0bd4ea3e14dc6fa69efc1c553b8490f22bc7883e9016673521169d3", size: 38398 }) {
46
+ function devExtension(baked = { file: "browse-extension-0.0.6-dev.19.zip", sha256: "30109734aef3a06d41b6dc2ee5f8471eb0f2f0090fd29cc501ce8b1a70f92ea6", size: 39247 }) {
151
47
  return baked && /^[0-9a-f]{64}$/.test(baked.sha256) && /^[\w.-]+\.zip$/.test(baked.file) ? baked : undefined;
152
48
  }
153
49
  var devExtensionUrl = (extension, env = process.env) => `${(env.OPENCODE_BROWSER_RELEASE_SERVICE || RELEASE_SERVICE).replace(/\/+$/, "")}/browse/files/${extension.sha256}/${extension.file}`;
@@ -157,12 +53,7 @@ function installCommand() {
157
53
  return fromCheckout() ? `cd ${quoted(path.dirname(packageRoot()))} && bun run setup` : "npx @opencode/browse install";
158
54
  }
159
55
 
160
- // src/auto-update.ts
161
- import { spawn } from "node:child_process";
162
- import { chmodSync, closeSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
163
- import { createRequire } from "node:module";
164
- import path2 from "node:path";
165
- import { fileURLToPath as fileURLToPath2 } from "node:url";
56
+ // src/update/auto-update.ts
166
57
  var PACKAGE_NAME = "@opencode/browse";
167
58
  var DAY_MS = 24 * 60 * 60 * 1000;
168
59
  var DEFAULT_REGISTRY = "https://registry.npmjs.org";
@@ -728,4 +619,115 @@ function spawnRuntimeChild(layout, entry, args, onExit, env = process.env) {
728
619
  }
729
620
  }
730
621
 
731
- export { extensionProtocolVersion, minExtensionProtocolVersion, unpackedExtensionId, unpackedReloadAdvice, checkoutReloadPrefix, extensionReconnectAlarmPeriodMs, extensionProtocolCompatibility, extensionProtocolSkew, extensionProtocolAdvice, makePageStatus, parseJsonObject, isCdpRequest, isExtensionResponse, isExtensionEvent, isJsonObject, dataRoot, oldStoreMarker, fromCheckout, checkoutRoot, cliCommand, storeConfig, devExtension, devExtensionUrl, devExtensionFolder, storeUrl, installCommand, autoUpdateModes, runtimeLayout, versionEntry, channelOf, UPDATE_VERSION, compareVersions, readCurrent, writeCurrent, readState, updateState, npmRuntime, autoUpdateOverride, storedMode, setStoredMode, autoUpdateStatus, describeAutoUpdate, registryUrl, fetchPublished, installVersion, pruneVersions, switchVersion, createAutoUpdater };
622
+ // src/protocol.ts
623
+ var extensionProtocolVersion = 3;
624
+ var minExtensionProtocolVersion = 3;
625
+ var unpackedExtensionId = "afeafocngkodbmaipcngoamamfmekgfo";
626
+ var unpackedReloadAdvice = "Reload Browse on your browser's extensions page (↻).";
627
+ var checkoutReloadPrefix = "Extension protocol incompatible: extension-older; reload ";
628
+ var extensionReconnectAlarmPeriodMs = 30000;
629
+ var legacyExtensionProtocolVersion = 1;
630
+ function extensionProtocolCompatibility(value) {
631
+ const legacy = value === undefined;
632
+ const valid = typeof value === "number" && Number.isSafeInteger(value) && value > 0;
633
+ const version = valid ? value : legacy ? legacyExtensionProtocolVersion : null;
634
+ return { version, compatible: version !== null && version >= minExtensionProtocolVersion && version <= extensionProtocolVersion, legacy };
635
+ }
636
+ function extensionProtocolSkew(version) {
637
+ if (typeof version !== "number")
638
+ return;
639
+ if (version > extensionProtocolVersion)
640
+ return "extension-newer";
641
+ if (version < minExtensionProtocolVersion)
642
+ return "extension-older";
643
+ return;
644
+ }
645
+ function extensionProtocolAdvice(version, commands, distribution) {
646
+ const skew = extensionProtocolSkew(version);
647
+ const versions = `extension protocol ${version ?? "unknown"}, this relay speaks ${minExtensionProtocolVersion === extensionProtocolVersion ? extensionProtocolVersion : `${minExtensionProtocolVersion} to ${extensionProtocolVersion}`}`;
648
+ if (skew === "extension-newer")
649
+ return `The Browse extension is newer than this browse CLI (${versions}). Update the CLI: run \`${commands.install}\` (an npm install with automatic updates also catches up by itself within a day), then restart opencode.`;
650
+ if (skew === "extension-older") {
651
+ const store = "The Chrome Web Store updates it within a few hours (to update now, open chrome://extensions, turn on Developer mode and click Update).";
652
+ const next = distribution === "unpacked" ? unpackedReloadAdvice : distribution === "store" ? store : `For an unpacked extension: ${unpackedReloadAdvice} For a store extension: ${store}`;
653
+ return `The Browse extension is older than this browse CLI (${versions}). ${next}`;
654
+ }
655
+ return `The Browse extension and this browse CLI don't speak the same protocol (${versions}). Run \`${commands.install}\` again and update the extension.`;
656
+ }
657
+ function makePageStatus(options) {
658
+ return {
659
+ state: options.state,
660
+ owner: options.targetOwner === "user" ? "user" : "session",
661
+ ...options.sessionId ? { sessionId: options.sessionId } : {},
662
+ ...options.sessionId && options.readOnly ? { readOnly: true } : {},
663
+ ...options.message ? { message: options.message } : {},
664
+ ...options.handoffId ? { handoffId: options.handoffId } : {},
665
+ ...options.recording ? { recording: true } : {}
666
+ };
667
+ }
668
+ var extensionCommandMethodValues = [
669
+ "ping",
670
+ "debugger.attach",
671
+ "debugger.detach",
672
+ "debugger.sendCommand",
673
+ "tabs.create",
674
+ "tabs.remove",
675
+ "tabs.group",
676
+ "tabs.ungroup",
677
+ "action.setAttached",
678
+ "action.setBadge",
679
+ "pageStatus.set",
680
+ "pageStatus.clear",
681
+ "runtime.reload",
682
+ "recording.start",
683
+ "recording.stop",
684
+ "recording.status",
685
+ "recording.cancel",
686
+ "tabs.cleanup",
687
+ "update.notice",
688
+ "relay.settings",
689
+ "settings.get",
690
+ "settings.set"
691
+ ];
692
+ var extensionEventMethodValues = [
693
+ "protocol",
694
+ "hello",
695
+ "auth.code",
696
+ "auth.response",
697
+ "ready",
698
+ "toolbar.clicked",
699
+ "handoff.completed",
700
+ "debugger.event",
701
+ "debugger.attached",
702
+ "debugger.detached",
703
+ "tabs.removed",
704
+ "tabs.opened",
705
+ "pong",
706
+ "log",
707
+ "recording.cancelled",
708
+ "pageStatus.requested",
709
+ "settings"
710
+ ];
711
+ function parseJsonObject(input) {
712
+ const parsed = JSON.parse(input);
713
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
714
+ throw new Error("Expected JSON object");
715
+ }
716
+ return parsed;
717
+ }
718
+ var extensionCommandMethods = new Set(extensionCommandMethodValues);
719
+ var extensionEventMethods = new Set(extensionEventMethodValues);
720
+ function isCdpRequest(input) {
721
+ return typeof input.id === "number" && typeof input.method === "string" && (input.params === undefined || isJsonObject(input.params)) && (input.sessionId === undefined || typeof input.sessionId === "string");
722
+ }
723
+ function isExtensionResponse(input) {
724
+ return typeof input.id === "number" && (input.result === undefined || isJsonObject(input.result)) && (input.error === undefined || typeof input.error === "string") && !(input.result !== undefined && input.error !== undefined);
725
+ }
726
+ function isExtensionEvent(input) {
727
+ return typeof input.method === "string" && extensionEventMethods.has(input.method) && (input.params === undefined || isJsonObject(input.params));
728
+ }
729
+ function isJsonObject(value) {
730
+ return value !== null && typeof value === "object" && !Array.isArray(value);
731
+ }
732
+
733
+ export { dataRoot, oldStoreMarker, fromCheckout, checkoutRoot, cliCommand, storeConfig, devExtension, devExtensionUrl, devExtensionFolder, storeUrl, installCommand, autoUpdateModes, runtimeLayout, versionEntry, channelOf, UPDATE_VERSION, compareVersions, readCurrent, writeCurrent, updateState, npmRuntime, autoUpdateOverride, storedMode, effectiveMode, setStoredMode, autoUpdateStatus, describeAutoUpdate, registryUrl, fetchPublished, installVersion, pruneVersions, switchVersion, createAutoUpdater, extensionProtocolVersion, minExtensionProtocolVersion, unpackedExtensionId, unpackedReloadAdvice, checkoutReloadPrefix, extensionReconnectAlarmPeriodMs, extensionProtocolCompatibility, extensionProtocolSkew, extensionProtocolAdvice, makePageStatus, parseJsonObject, isCdpRequest, isExtensionResponse, isExtensionEvent, isJsonObject };