@opencode/browse 0.0.18-dev.193 → 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 (45) hide show
  1. package/dist/cli.mjs +62 -117
  2. package/package.json +13 -33
  3. package/dist/Runtime-r9sev1rq.mjs +0 -16
  4. package/dist/THIRD_PARTY_NOTICES.txt +0 -310
  5. package/dist/Undici-xgvbtsb1.mjs +0 -25295
  6. package/dist/cli-ekwkvvmm.mjs +0 -5943
  7. package/dist/coreBundle-mbshhes2.mjs +0 -8
  8. package/dist/helpers-3ycvp75a.mjs +0 -71
  9. package/dist/index-xsb9s479.mjs +0 -13
  10. package/dist/legacy-runtime-v1sdjj5h.mjs +0 -135
  11. package/dist/log-yek648ak.mjs +0 -9
  12. package/dist/main-1qwrze1y.mjs +0 -140
  13. package/dist/main-2p0v71q0.mjs +0 -1752
  14. package/dist/main-3g7fdzbh.mjs +0 -5360
  15. package/dist/main-55a4gpef.mjs +0 -1261
  16. package/dist/main-693wwz19.mjs +0 -4
  17. package/dist/main-91vhk5de.mjs +0 -38
  18. package/dist/main-9t32k44b.mjs +0 -798
  19. package/dist/main-bv9nawja.mjs +0 -5191
  20. package/dist/main-cgnkhs2x.mjs +0 -35
  21. package/dist/main-esdgpebk.mjs +0 -161
  22. package/dist/main-fg5awggs.mjs +0 -5514
  23. package/dist/main-gexpjhk5.mjs +0 -32
  24. package/dist/main-gt2gskrq.mjs +0 -160
  25. package/dist/main-gw77et6v.mjs +0 -342
  26. package/dist/main-j98fzrvv.mjs +0 -68
  27. package/dist/main-kcw411ep.mjs +0 -891
  28. package/dist/main-nnfxg7re.mjs +0 -11403
  29. package/dist/main-pcqtqhgv.mjs +0 -64
  30. package/dist/main-pmfd055v.mjs +0 -63
  31. package/dist/main-pxs5m0kb.mjs +0 -329
  32. package/dist/main-qazf3bhk.mjs +0 -223
  33. package/dist/main-sf7vaxb6.mjs +0 -17
  34. package/dist/main-stf180y1.mjs +0 -229
  35. package/dist/main-tk4axre7.mjs +0 -39
  36. package/dist/main-zedq93ez.mjs +0 -215
  37. package/dist/main-zzggnpf4.mjs +0 -73
  38. package/dist/mcp-xfx04fxe.mjs +0 -9470
  39. package/dist/migrate-4rewxqd7.mjs +0 -354
  40. package/dist/relay-me036e19.mjs +0 -18765
  41. package/dist/remove-stored-secrets-ymhge5va.mjs +0 -6
  42. package/dist/runtime-update-hd2cvy1c.mjs +0 -246
  43. package/dist/setup-0hmbzam5.mjs +0 -1052
  44. package/dist/update-vnkjbc0e.mjs +0 -17
  45. package/dist/version-jn0h3rmc.mjs +0 -8
@@ -1,32 +0,0 @@
1
- // src/agent-guide.ts
2
- var whatBrowseIs = `browse drives the user's real Chrome-family browser through the browse extension, so logins, extensions and open tabs are already there and the user can watch or take over.`;
3
- var inspectActVerify = `Use one loop: inspect, act, verify.
4
- - Inspect with \`await snapshot()\` before choosing anything. Prefer the returned refs: \`await ref("e12").click()\`. Fall back to accessible locators (\`page.getByRole(...)\`, \`getByLabel(...)\`), then CSS.
5
- - Act with the narrowest stable control, and keep dependent steps in one \`execute\` while transient UI is open.
6
- - Verify with a fresh page read (\`page.url()\`, a heading, or a new snapshot). A click that returned, or a handoff the user acknowledged, is not proof the task succeeded.`;
7
- var handoffAdvice = `When only a person can proceed — login, 2FA, passkey, captcha or payment confirmation — call \`handoff("what the user should do")\` and wait. Pass \`start\` for an action that itself blocks. Never solve a captcha yourself and never retry-loop a blocked site; if a challenge is interactive or the site refuses the visit, hand off or stop and tell the user.`;
8
- var sessionAdvice = `Each agent has its own current session when the client names the agent (OpenCode does), so bare calls don't land on another agent's page. When the client doesn't name agents, \`status\` reports \`sharedSession: true\` and all agents on this server share one current session, so when several (such as subagents) use it each should \`session_new\` its own and pass \`session\` on every call. When finished, \`session_reset\` (or \`session_delete\`) your own session; keep a session only when follow-up work is expected.`;
9
- var agentHelp = `AGENT GUIDE
10
- browse drives the user's real Chrome-family browser through the browse extension, so logins,
11
- extensions and open tabs are already there and the user can watch or take over. Agents normally
12
- use the MCP server (\`browse mcp\`); the same loop works from a terminal.
13
-
14
- Write one Playwright script to a file and run it:
15
- browse execute --file script.js
16
- It receives browser, context, page, state, snapshot(), ref() and handoff(). \`return\` a value to
17
- get it back.
18
-
19
- Inspect, act, verify:
20
- - \`await snapshot()\` before choosing anything; click the returned refs (\`await ref("e12").click()\`).
21
- - Fall back to accessible locators (\`page.getByRole(...)\`), then CSS.
22
- - Keep dependent steps in one script while transient UI is open.
23
- - Verify with a fresh page read (\`page.url()\`, a heading, a new snapshot); a click that returned
24
- proves nothing.
25
-
26
- When only a person can proceed (login, 2FA, passkey, captcha, payment), call
27
- \`handoff("what to do")\` and wait. Never solve a captcha yourself.
28
-
29
- Pass \`--session\` to keep one session across calls. \`browse session reset\` or \`browse session delete\`
30
- it when done; keep a session only for follow-up work.`;
31
-
32
- export { whatBrowseIs, inspectActVerify, handoffAdvice, sessionAdvice, agentHelp };
@@ -1,160 +0,0 @@
1
- import {
2
- writePrivateJsonFileSync
3
- } from "./main-91vhk5de.mjs";
4
- import {
5
- dataRoot,
6
- stateRoot
7
- } from "./main-1qwrze1y.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 };
@@ -1,342 +0,0 @@
1
- import {
2
- unpackedReloadAdvice,
3
- installedRuntime2,
4
- autoUpdateStatus,
5
- updateAvailable
6
- } from "./main-9t32k44b.mjs";
7
- import {
8
- cacheRoot,
9
- compiledBinary,
10
- checkoutRoot,
11
- cliCommand
12
- } from "./main-1qwrze1y.mjs";
13
-
14
- // src/update.ts
15
- import { execFile, spawnSync } from "node:child_process";
16
- import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
17
- import path from "node:path";
18
- var UPDATE_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000;
19
- var FAILED_CHECK_INTERVAL_MS = 60 * 60 * 1000;
20
- var CACHE_FILE = "update-check.json";
21
- var quietGitEnv = () => ({
22
- ...process.env,
23
- GIT_TERMINAL_PROMPT: "0",
24
- GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND ?? "ssh -o BatchMode=yes"
25
- });
26
- var gitIn = (repo) => (args, timeoutMs = 5000) => new Promise((resolve) => {
27
- execFile("git", ["-C", repo, ...args], { timeout: timeoutMs, encoding: "utf8", env: quietGitEnv() }, (error, stdout) => resolve(error ? undefined : stdout.trim()));
28
- });
29
- var short = (sha) => sha.slice(0, 7);
30
- async function defaultBranch(remote, git) {
31
- return parseDefaultBranch(await git(["ls-remote", "--symref", remote, "HEAD"], 1e4));
32
- }
33
- var parseDefaultBranch = (listed) => /^ref: (refs\/heads\/\S+)\s+HEAD$/m.exec(listed ?? "")?.[1];
34
- async function checkForUpdate(repo, git = gitIn(repo), now = Date.now()) {
35
- const [head, branch] = await Promise.all([git(["rev-parse", "HEAD"]), git(["symbolic-ref", "--short", "-q", "HEAD"])]);
36
- if (!head || !branch)
37
- return;
38
- const [remote, merge] = await Promise.all([git(["config", `branch.${branch}.remote`]), git(["config", `branch.${branch}.merge`])]);
39
- if (!remote || !merge || remote === ".")
40
- return;
41
- let upstream = `${remote}/${merge.replace(/^refs\/heads\//, "")}`;
42
- let listed = await git(["ls-remote", remote, merge], 1e4);
43
- if (listed === "") {
44
- const fallback = await defaultBranch(remote, git);
45
- if (fallback && fallback !== merge) {
46
- upstream = `${remote}/${fallback.replace(/^refs\/heads\//, "")}`;
47
- listed = await git(["ls-remote", remote, fallback], 1e4);
48
- }
49
- }
50
- const base = { repo, checkedAt: now, head, upstream };
51
- const latest = listed?.split(/\s/)[0];
52
- if (!latest || !/^[0-9a-f]{40,64}$/.test(latest))
53
- return { ...base, available: false, failed: true };
54
- if (latest === head)
55
- return { ...base, latest, available: false };
56
- if (await git(["cat-file", "-e", `${latest}^{commit}`]) !== undefined) {
57
- if (await git(["merge-base", "--is-ancestor", latest, "HEAD"]) !== undefined)
58
- return { ...base, latest, available: false };
59
- const behind = Number(await git(["rev-list", "--count", `HEAD..${latest}`]));
60
- return { ...base, latest, available: true, ...Number.isInteger(behind) && behind > 0 ? { behind } : {} };
61
- }
62
- return { ...base, latest, available: true };
63
- }
64
- function readCache(file) {
65
- try {
66
- return JSON.parse(readFileSync(file, "utf8"));
67
- } catch {
68
- return;
69
- }
70
- }
71
- function writeCache(file, check) {
72
- try {
73
- mkdirSync(path.dirname(file), { recursive: true });
74
- const temporary = `${file}.${process.pid}.tmp`;
75
- writeFileSync(temporary, JSON.stringify(check) + `
76
- `);
77
- renameSync(temporary, file);
78
- } catch {}
79
- }
80
- async function cachedUpdateCheck(options) {
81
- const git = options.git ?? gitIn(options.repo);
82
- const now = options.now ?? Date.now();
83
- const file = path.join(options.dataDir, CACHE_FILE);
84
- const cached = readCache(file);
85
- const head = await git(["rev-parse", "HEAD"]);
86
- if (!head)
87
- return;
88
- const maxAge = cached?.failed ? FAILED_CHECK_INTERVAL_MS : UPDATE_CHECK_INTERVAL_MS;
89
- if (cached && cached.repo === options.repo && cached.head === head && now - cached.checkedAt >= 0 && now - cached.checkedAt < maxAge)
90
- return cached;
91
- const fresh = await checkForUpdate(options.repo, git, now);
92
- if (fresh)
93
- writeCache(file, fresh);
94
- return fresh;
95
- }
96
- var updateCheckEnabled = () => process.env.OPENCODE_BROWSER_UPDATE_CHECK !== "0";
97
- function describeUpdate(check) {
98
- if (check.behind)
99
- return `${check.behind} new commit${check.behind === 1 ? "" : "s"} on ${check.upstream}`;
100
- return `${check.upstream} is at ${short(check.latest ?? "")} (you have ${short(check.head)})`;
101
- }
102
- function updateJson2(update) {
103
- if (!update)
104
- return null;
105
- const { check } = update;
106
- return {
107
- available: true,
108
- summary: update.summary,
109
- command: update.command,
110
- notice: formatUpdateNotice2(update),
111
- current: check.head,
112
- latest: check.latest ?? null,
113
- behind: check.behind ?? null,
114
- upstream: check.upstream
115
- };
116
- }
117
- function formatUpdateNotice2(notice) {
118
- return `Update available: ${notice.summary}. Run \`${notice.command}\`, then restart opencode.`;
119
- }
120
- async function updateNotice2(options = {}) {
121
- try {
122
- if (!options.repo) {
123
- const npm = npmUpdateNotice();
124
- if (npm !== false)
125
- return npm;
126
- }
127
- const repo = options.repo ?? checkoutRoot();
128
- if (!repo || !updateCheckEnabled() || !existsSync(path.join(repo, ".git")))
129
- return;
130
- const check = await cachedUpdateCheck({ repo, dataDir: options.dataDir ?? cacheRoot(), ...options.git ? { git: options.git } : {} });
131
- return check?.available ? { summary: describeUpdate(check), command: cliCommand("update"), check } : undefined;
132
- } catch {
133
- return;
134
- }
135
- }
136
- function npmUpdateNotice() {
137
- const runtime = installedRuntime2();
138
- if (!runtime)
139
- return false;
140
- const status = autoUpdateStatus({ runtime });
141
- const latest = status.latest;
142
- if (!latest || !updateAvailable(status) || status.effective === "off")
143
- return;
144
- if (status.effective === "on" && !status.lastError)
145
- return;
146
- const check = { repo: "npm", checkedAt: Date.now(), head: runtime.version, upstream: `npm ${status.channel ?? "latest"}`, latest, available: true };
147
- return { summary: `browse ${latest} is available (you have ${runtime.version})`, command: cliCommand("update"), check };
148
- }
149
- function createUpdateWatcher2(options = {}) {
150
- const check = options.check ?? (() => updateNotice2());
151
- const now = options.now ?? Date.now;
152
- const interval = options.intervalMs ?? FAILED_CHECK_INTERVAL_MS;
153
- let current;
154
- let lastRun;
155
- let running;
156
- return {
157
- get current() {
158
- return current;
159
- },
160
- refresh() {
161
- if (running)
162
- return running;
163
- if (lastRun !== undefined && now() - lastRun < interval)
164
- return Promise.resolve();
165
- lastRun = now();
166
- running = check().catch(() => {
167
- return;
168
- }).then((next) => {
169
- const changed = (next ? formatUpdateNotice2(next) : undefined) !== (current ? formatUpdateNotice2(current) : undefined);
170
- current = next;
171
- if (changed)
172
- options.onChange?.(next);
173
- }).finally(() => {
174
- running = undefined;
175
- });
176
- return running;
177
- }
178
- };
179
- }
180
- var syncGit = (repo) => (args, timeoutMs = 30000) => {
181
- const result = spawnSync("git", ["-C", repo, ...args], { encoding: "utf8", timeout: timeoutMs, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
182
- return { status: result.status, stdout: (result.stdout ?? "").trim(), stderr: (result.stderr ?? "").trim(), ...result.error ? { error: result.error } : {} };
183
- };
184
- var realpath = (file) => {
185
- try {
186
- return realpathSync(file);
187
- } catch {
188
- return path.resolve(file);
189
- }
190
- };
191
- var firstLine = (text) => text.split(/\r?\n/).find((line) => line.trim())?.trim() ?? "";
192
- var shellQuoted = (value) => /^[\w@%+=:,./-]+$/.test(value) ? value : JSON.stringify(value);
193
- function defaultSetup(step) {
194
- const cli = path.join(step.repo, "cli");
195
- const run = (command, args, cwd) => {
196
- const result = spawnSync(command, args, { cwd, stdio: "inherit" });
197
- return result.status === 0 ? undefined : `\`${[command, ...args].join(" ")}\` failed in ${cwd}${result.error ? ` (${result.error.message})` : ""}`;
198
- };
199
- const installs = [[step.root, step.repo], [step.cli, cli]];
200
- for (const [changed, directory] of installs) {
201
- if (!changed && existsSync(path.join(directory, "node_modules")))
202
- continue;
203
- const failed = run("bun", ["install", "--frozen-lockfile"], directory);
204
- if (failed)
205
- return failed;
206
- }
207
- const built = run("bun", ["run", "build"], cli);
208
- if (built)
209
- return built;
210
- const node = process.versions.bun ? "node" : process.execPath;
211
- return run(node, [path.join(cli, "dist", "cli.mjs"), "install", ...step.args], cli);
212
- }
213
- function installArgs(args) {
214
- const passed = [];
215
- for (let index = 0;index < args.length; index++) {
216
- const arg = args[index];
217
- if (arg === "--opencode" && args[index + 1] !== undefined)
218
- passed.push(arg, args[++index]);
219
- else if (arg === "--no-open")
220
- passed.push(arg);
221
- }
222
- return [...passed, "--no-wait"];
223
- }
224
- function runUpdate(args, deps) {
225
- const { log } = deps;
226
- const refuse = (problem, fix) => {
227
- log(`✗ Not updated: ${problem}`);
228
- log(` ${fix}`);
229
- return 1;
230
- };
231
- const repo = deps.repo;
232
- if (!repo) {
233
- log("browse was installed from npm. Update it with:");
234
- log(" npx @opencode/browse@latest install");
235
- log("then restart opencode.");
236
- return 0;
237
- }
238
- const git = deps.git ?? syncGit(repo);
239
- const at = shellQuoted(repo);
240
- const version = git(["--version"]);
241
- if (version.error || version.status !== 0)
242
- return refuse("git isn't installed or isn't on PATH.", "Install git, then run this again.");
243
- const top = git(["rev-parse", "--show-toplevel"]).stdout;
244
- if (!top || realpath(top) !== realpath(repo))
245
- return refuse(`${repo} isn't a git clone.`, `Clone it again: git clone https://github.com/anomalyco/browse.git && cd browse && bun run setup`);
246
- if (!(deps.hasBun ?? (() => !spawnSync("bun", ["--version"], { stdio: "ignore" }).error))())
247
- return refuse("bun isn't installed or isn't on PATH (setup builds with it).", "Install Bun from https://bun.sh, then run this again.");
248
- const branch = git(["symbolic-ref", "--short", "-q", "HEAD"]).stdout;
249
- const head = git(["rev-parse", "HEAD"]).stdout;
250
- if (!branch)
251
- return refuse(`${repo} isn't on a branch (HEAD is detached at ${short(head)}).`, `Check out the branch to follow, e.g. \`git -C ${at} checkout dev\`, then run this again.`);
252
- let upstream = git(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"]).stdout;
253
- const remote = git(["config", `branch.${branch}.remote`]).stdout;
254
- let merge = git(["config", `branch.${branch}.merge`]).stdout;
255
- if (!upstream || !remote || !merge || remote === ".")
256
- return refuse(`branch ${branch} doesn't track a remote branch.`, `Set one, e.g. \`git -C ${at} branch --set-upstream-to origin/dev\`, then run this again.`);
257
- const changes = git(["diff", "--name-only", "HEAD"]).stdout;
258
- if (changes) {
259
- const files = changes.split(/\r?\n/);
260
- return refuse(`${repo} has uncommitted changes (${files.slice(0, 5).join(", ")}${files.length > 5 ? `, and ${files.length - 5} more` : ""}).`, `Commit or stash them (\`git -C ${at} stash\`), then run this again.`);
261
- }
262
- if (git(["ls-remote", "--exit-code", remote, merge], 30000).status === 2) {
263
- const fallback = parseDefaultBranch(git(["ls-remote", "--symref", remote, "HEAD"], 30000).stdout);
264
- if (fallback && fallback !== merge) {
265
- const gone = upstream;
266
- merge = fallback;
267
- upstream = `${remote}/${fallback.replace(/^refs\/heads\//, "")}`;
268
- git(["config", `branch.${branch}.merge`, merge]);
269
- log(`${gone} is gone from the remote; following ${upstream}, its default branch, from now on.`);
270
- }
271
- }
272
- const fetched = git(["fetch", "--quiet", remote, merge], 120000);
273
- if (fetched.status !== 0) {
274
- const url = git(["remote", "get-url", remote]).stdout;
275
- return refuse(`couldn't fetch ${upstream}${url ? ` from ${url}` : ""}: ${firstLine(fetched.stderr) || fetched.error?.message || "git fetch failed"}.`, "Check your network connection, then run this again.");
276
- }
277
- const latest = git(["rev-parse", "FETCH_HEAD"]).stdout;
278
- if (!latest)
279
- return refuse(`couldn't read ${upstream} after fetching.`, `Run \`git -C ${at} pull --ff-only\` to see why.`);
280
- if (latest === head || git(["merge-base", "--is-ancestor", latest, "HEAD"]).status === 0) {
281
- log(`✓ Already up to date: ${short(head)} on ${branch} (${upstream}).`);
282
- log(` If your unpacked extension still reports an older protocol: ${unpackedReloadAdvice}`);
283
- return 0;
284
- }
285
- if (git(["merge-base", "--is-ancestor", "HEAD", latest]).status !== 0) {
286
- const counts = git(["rev-list", "--left-right", "--count", `HEAD...${latest}`]).stdout.split(/\s+/);
287
- return refuse(`${branch} has diverged from ${upstream} (${counts[0] ?? "?"} local commit(s), ${counts[1] ?? "?"} new on the remote), so it can't fast-forward.`, `Reconcile them yourself (e.g. \`git -C ${at} pull --rebase\`), then run \`cd ${at} && bun run setup\`.`);
288
- }
289
- const count = Number(git(["rev-list", "--count", `HEAD..${latest}`]).stdout) || 0;
290
- const commits = git(["log", "--oneline", "--no-decorate", "-n", "20", `HEAD..${latest}`]).stdout;
291
- const changed = (...files) => !!git(["diff", "--name-only", "HEAD", latest, "--", ...files]).stdout;
292
- const rootDeps = changed("package.json", "bun.lock");
293
- const cliDeps = changed("cli/package.json", "cli/bun.lock");
294
- log(`Updating browse ${short(head)} → ${short(latest)} (${count} new commit${count === 1 ? "" : "s"} on ${upstream}):`);
295
- for (const line of commits.split(/\r?\n/).filter(Boolean))
296
- log(` ${line}`);
297
- if (count > 20)
298
- log(` … and ${count - 20} more`);
299
- log("");
300
- const pulled = git(["merge", "--ff-only", "--quiet", latest], 60000);
301
- if (pulled.status !== 0)
302
- return refuse(`couldn't fast-forward to ${short(latest)}: ${firstLine(pulled.stderr) || "git merge failed"}.`, `Run \`git -C ${at} pull --ff-only\` to see why.`);
303
- const failed = (deps.setup ?? defaultSetup)({ repo, root: rootDeps, cli: cliDeps, args: installArgs(args) });
304
- if (failed) {
305
- log("");
306
- log(`✗ Pulled ${short(head)} → ${short(latest)}, but setup failed: ${failed}.`);
307
- log(` Fix it, then run \`cd ${at} && bun run setup\`.`);
308
- return 1;
309
- }
310
- log("");
311
- log(`✓ Updated browse ${short(head)} → ${short(latest)}.`);
312
- log(" Restart opencode to load the new browse MCP server.");
313
- return 0;
314
- }
315
- async function runUpdateCommand2(args) {
316
- const log = (line) => process.stdout.write(line + `
317
- `);
318
- const { runInstalledUpdate } = await import("./runtime-update-hd2cvy1c.mjs");
319
- if (await runInstalledUpdate(args))
320
- return;
321
- if (compiledBinary()) {
322
- log(`This browse isn't installed. Run \`${cliCommand("install")}\` to set it up; it updates itself from then on.`);
323
- process.exitCode = 1;
324
- return;
325
- }
326
- if (args.includes("--check")) {
327
- const repo = checkoutRoot();
328
- if (!repo)
329
- return log("Installed from npm: run `npx @opencode/browse@latest install` to update.");
330
- const check = await checkForUpdate(repo);
331
- if (check)
332
- writeCache(path.join(cacheRoot(), CACHE_FILE), check);
333
- if (!check)
334
- return log("Can't check: this clone isn't on a branch that tracks a remote.");
335
- if (check.failed)
336
- return log(`Can't check: ${check.upstream} couldn't be reached.`);
337
- return log(check.available ? formatUpdateNotice2({ summary: describeUpdate(check), command: cliCommand("update") }) : `✓ Up to date with ${check.upstream}.`);
338
- }
339
- process.exitCode = runUpdate(args, { repo: checkoutRoot(), log });
340
- }
341
-
342
- export { updateJson2, formatUpdateNotice2, updateNotice2, createUpdateWatcher2, runUpdateCommand2 };
@@ -1,68 +0,0 @@
1
- import { createRequire } from "node:module";
2
- var __create = Object.create;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- function __accessProp(key) {
8
- return this[key];
9
- }
10
- var __reExport = (target, mod, secondTarget) => {
11
- var keys = mod && typeof mod === "object" || typeof mod === "function" ? __getOwnPropNames(mod) : [];
12
- for (let key of keys)
13
- if (!__hasOwnProp.call(target, key) && key !== "default")
14
- __defProp(target, key, {
15
- get: __accessProp.bind(mod, key),
16
- enumerable: true
17
- });
18
- if (secondTarget) {
19
- for (let key of keys)
20
- if (!__hasOwnProp.call(secondTarget, key) && key !== "default")
21
- __defProp(secondTarget, key, {
22
- get: __accessProp.bind(mod, key),
23
- enumerable: true
24
- });
25
- return secondTarget;
26
- }
27
- };
28
- var __toESMCache_node;
29
- var __toESMCache_esm;
30
- var __toESM = (mod, isNodeMode, target) => {
31
- var canCache = mod != null && typeof mod === "object";
32
- if (canCache) {
33
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
34
- var cached = cache.get(mod);
35
- if (cached)
36
- return cached;
37
- }
38
- target = mod != null ? __create(__getProtoOf(mod)) : {};
39
- const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
40
- if (mod && typeof mod === "object" || typeof mod === "function") {
41
- for (let key of __getOwnPropNames(mod))
42
- if (!__hasOwnProp.call(to, key))
43
- __defProp(to, key, {
44
- get: __accessProp.bind(mod, key),
45
- enumerable: true
46
- });
47
- }
48
- if (canCache)
49
- cache.set(mod, to);
50
- return to;
51
- };
52
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
53
- var __returnValue = (v) => v;
54
- function __exportSetter(name, newValue) {
55
- this[name] = __returnValue.bind(null, newValue);
56
- }
57
- var __export = (target, all) => {
58
- for (var name in all)
59
- __defProp(target, name, {
60
- get: all[name],
61
- enumerable: true,
62
- configurable: true,
63
- set: __exportSetter.bind(all, name)
64
- });
65
- };
66
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
67
-
68
- export { __reExport, __toESM, __commonJS, __export, __require };