@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,354 +0,0 @@
1
- import {
2
- parse,
3
- parse2,
4
- $parseDocument,
5
- agentLocations,
6
- browseServerCommand,
7
- editAgentConfig,
8
- OPENCODE_CONFIG_NAMES,
9
- configureMcp
10
- } from "./main-nnfxg7re.mjs";
11
- import {
12
- legacyDataRoot,
13
- legacyRoots,
14
- legacyRuntime,
15
- LEGACY_HANDOVER_GRACE_MS
16
- } from "./main-pmfd055v.mjs";
17
- import"./main-693wwz19.mjs";
18
- import"./main-9t32k44b.mjs";
19
- import"./main-tk4axre7.mjs";
20
- import"./main-91vhk5de.mjs";
21
- import"./main-gt2gskrq.mjs";
22
- import"./main-kcw411ep.mjs";
23
- import {
24
- removeStoredSecrets2
25
- } from "./main-sf7vaxb6.mjs";
26
- import {
27
- configRoot2,
28
- dataRoot,
29
- stateRoot,
30
- cacheRoot,
31
- binRoot,
32
- binaryName,
33
- devExtensionFolder
34
- } from "./main-1qwrze1y.mjs";
35
-
36
- // src/setup/migrate.ts
37
- import fs from "node:fs";
38
- import os from "node:os";
39
- import path from "node:path";
40
- import { randomUUID } from "node:crypto";
41
- var normalized = (value) => value.replaceAll("\\", "/");
42
- function destination(relative, home) {
43
- const file = normalized(relative);
44
- const [top, ...rest] = file.split("/");
45
- if (top === "runtime" || top === "versions")
46
- return;
47
- if (top === "secrets" || top === "site-secrets")
48
- return;
49
- if (top === "bin") {
50
- const name = rest.join("/");
51
- return name === binaryName() ? path.join(binRoot(home), binaryName()) : undefined;
52
- }
53
- if (file === "settings.json" || file === "config.json")
54
- return path.join(configRoot2(home), file);
55
- if (file === "update-check.json" || file === "extension.json" || top === "extension")
56
- return path.join(cacheRoot(home), file);
57
- if (file === "old-store-extension" || file === "auto-update.json" || file === "pairing-codes.json" || file === "session.json" || top === "logs" || top === "sessions")
58
- return path.join(stateRoot(home), file);
59
- if (top === "relays")
60
- return path.join(path.basename(file) === "lifecycle.jsonl" ? stateRoot(home) : dataRoot(home), file);
61
- return path.join(dataRoot(home), file);
62
- }
63
- var lexists = (file) => {
64
- try {
65
- fs.lstatSync(file);
66
- return true;
67
- } catch {
68
- return false;
69
- }
70
- };
71
- var privatePath = (relative) => {
72
- const file = normalized(relative);
73
- return file === "relay-token" || file === "browser-tokens.json" || file === "pairing-codes.json" || file === "extension-pairing" || file === "session.json" || file.startsWith("sessions/") || file === "auto-update.json" || file === "old-store-extension";
74
- };
75
- function filesUnder(root, relative = "") {
76
- let entries;
77
- try {
78
- entries = fs.readdirSync(path.join(root, relative), { withFileTypes: true });
79
- } catch {
80
- return [];
81
- }
82
- return entries.flatMap((entry) => {
83
- const next = path.join(relative, entry.name);
84
- if (entry.isDirectory())
85
- return filesUnder(root, next);
86
- return entry.isFile() ? [next] : [];
87
- });
88
- }
89
- function copyPrivate(from, to, relative, overwrite = false) {
90
- if (!overwrite && fs.existsSync(to))
91
- return;
92
- fs.mkdirSync(path.dirname(to), { recursive: true, mode: privatePath(relative) ? 448 : 493 });
93
- const temporary = `${to}.migrate-${process.pid}`;
94
- fs.rmSync(temporary, { force: true });
95
- try {
96
- fs.copyFileSync(from, temporary);
97
- const source = fs.statSync(from);
98
- fs.chmodSync(temporary, privatePath(relative) ? 384 : source.mode & 511);
99
- fs.renameSync(temporary, to);
100
- } finally {
101
- fs.rmSync(temporary, { force: true });
102
- }
103
- }
104
- function configIsValid(file) {
105
- const extension = path.extname(file).toLowerCase();
106
- try {
107
- const text = fs.readFileSync(file, "utf8");
108
- if (extension === ".toml") {
109
- parse2(text);
110
- return true;
111
- }
112
- if (extension === ".yaml" || extension === ".yml") {
113
- return $parseDocument(text, { merge: true }).errors.length === 0;
114
- }
115
- if (extension === ".json" || extension === ".jsonc") {
116
- const errors = [];
117
- parse(text, errors, { allowTrailingComma: true });
118
- return errors.length === 0;
119
- }
120
- return true;
121
- } catch {
122
- return false;
123
- }
124
- }
125
- function writeTextAtomic(file, text) {
126
- const mode = fs.statSync(file).mode & 511;
127
- const temporary = path.join(path.dirname(file), `.${path.basename(file)}.${process.pid}.${randomUUID()}.tmp`);
128
- try {
129
- fs.writeFileSync(temporary, text, { mode, flag: "wx" });
130
- fs.chmodSync(temporary, mode);
131
- fs.renameSync(temporary, file);
132
- } finally {
133
- fs.rmSync(temporary, { force: true });
134
- }
135
- }
136
- function rewriteBinaryText(file, oldBinary, newBinary) {
137
- if (!configIsValid(file))
138
- return false;
139
- let text;
140
- try {
141
- text = fs.readFileSync(file, "utf8");
142
- } catch {
143
- return false;
144
- }
145
- const before = text;
146
- for (const [from, to] of [[oldBinary, newBinary], [oldBinary.replaceAll("\\", "\\\\"), newBinary.replaceAll("\\", "\\\\")]])
147
- text = text.split(from).join(to);
148
- if (text === before)
149
- return false;
150
- writeTextAtomic(file, text);
151
- return true;
152
- }
153
- function referencesPath(file, needle) {
154
- try {
155
- const text = fs.readFileSync(file, "utf8");
156
- return text.includes(needle) || text.includes(needle.replaceAll("\\", "\\\\"));
157
- } catch {
158
- return false;
159
- }
160
- }
161
- var absoluteNode = (command) => /(^|[\\/])(node|node\.exe)$/i.test(command);
162
- var npmEntry = (entry) => /(?:opencode-browser\.mjs|_npx[\\/].*@opencode[\\/]browse|node_modules[\\/]@opencode[\\/]browse)/i.test(entry);
163
- function rewriteAgent(name, file, oldBinary, newBinary) {
164
- if (!fs.existsSync(file))
165
- return false;
166
- const command = browseServerCommand(name, file);
167
- if (!command || command.at(-1) !== "mcp")
168
- return false;
169
- const target = command.at(-2);
170
- if (!target)
171
- return false;
172
- if (command[0] === oldBinary || normalized(command[0] ?? "") === normalized(oldBinary)) {
173
- if (name === "opencode")
174
- return !!configureMcp(file, newBinary, oldBinary);
175
- const changed = editAgentConfig({ name, file, entry: oldBinary }, true);
176
- return changed === "removed" && editAgentConfig({ name, file, entry: newBinary }) === "added";
177
- }
178
- if (absoluteNode(command[0] ?? "") && npmEntry(target)) {
179
- if (name === "opencode")
180
- return !!configureMcp(file, "browse", target);
181
- const changed = editAgentConfig({ name, file, node: command[0], entry: target }, true);
182
- return changed === "removed" && editAgentConfig({ name, file, entry: "browse" }) === "added";
183
- }
184
- return false;
185
- }
186
- function copyLegacyData(home = os.homedir()) {
187
- const root = legacyDataRoot(home);
188
- const record = takeoverRecord(home);
189
- for (const file of readCopied(record))
190
- fs.rmSync(file, { force: true });
191
- const copies = filesUnder(root).flatMap((relative) => {
192
- const to = destination(relative, home);
193
- return to ? [{ relative, to }] : [];
194
- });
195
- try {
196
- fs.mkdirSync(path.dirname(record), { recursive: true, mode: 448 });
197
- fs.writeFileSync(record, JSON.stringify({ copied: copies.map((copy) => copy.to) }) + `
198
- `, { mode: 384 });
199
- } catch {}
200
- for (const { relative, to } of copies) {
201
- try {
202
- copyPrivate(path.join(root, relative), to, relative, true);
203
- } catch {}
204
- }
205
- }
206
- var takeoverRecord = (home) => path.join(stateRoot(home), "legacy-takeover.json");
207
- function readCopied(record) {
208
- try {
209
- const copied = JSON.parse(fs.readFileSync(record, "utf8")).copied;
210
- return Array.isArray(copied) ? copied.filter((file) => typeof file === "string") : [];
211
- } catch {
212
- return [];
213
- }
214
- }
215
- function recordedConfigs(home) {
216
- return [path.join(configRoot2(home), "settings.json"), path.join(home, ".browse", "settings.json"), path.join(legacyDataRoot(home), "settings.json")].flatMap((file) => {
217
- try {
218
- const settings = JSON.parse(fs.readFileSync(file, "utf8"));
219
- return [
220
- ...(settings.opencodeConfigs ?? []).filter((config) => typeof config === "string").map((config) => ({ name: "opencode", file: config })),
221
- ...(settings.agents ?? []).filter((agent) => typeof agent?.file === "string").map((agent) => ({ name: agent.name, file: agent.file }))
222
- ];
223
- } catch {
224
- return [];
225
- }
226
- });
227
- }
228
- function linkLegacyExtension(root, home) {
229
- const old = path.join(root, "extension");
230
- const folder = devExtensionFolder(cacheRoot(home));
231
- try {
232
- if (!fs.lstatSync(old).isDirectory())
233
- return;
234
- } catch {
235
- if (!fs.existsSync(folder))
236
- return;
237
- try {
238
- if (!fs.readdirSync(root).some((name) => name.startsWith("extension.link-")))
239
- return;
240
- } catch {
241
- return;
242
- }
243
- }
244
- const link = `${old}.link-${process.pid}`;
245
- try {
246
- fs.mkdirSync(path.dirname(folder), { recursive: true });
247
- fs.rmSync(link, { force: true });
248
- fs.symlinkSync(folder, link, "junction");
249
- if (fs.existsSync(folder))
250
- fs.rmSync(old, { recursive: true, force: true });
251
- else {
252
- try {
253
- fs.renameSync(old, folder);
254
- } catch {
255
- fs.cpSync(old, folder, { recursive: true });
256
- fs.rmSync(old, { recursive: true, force: true });
257
- }
258
- }
259
- fs.renameSync(link, old);
260
- } catch {
261
- fs.rmSync(link, { force: true });
262
- }
263
- }
264
- function migrateLegacy(home = os.homedir(), now = Date.now()) {
265
- const result = { moved: 0, rewritten: 0, removed: [] };
266
- if (process.env.OPENCODE_BROWSER_HOME)
267
- return result;
268
- removeStoredSecrets2(home);
269
- const roots = legacyRoots(home);
270
- const oldData = legacyDataRoot(home);
271
- const recorded = recordedConfigs(home);
272
- for (const root of roots) {
273
- if (!fs.existsSync(root))
274
- continue;
275
- if (root === oldData)
276
- linkLegacyExtension(root, home);
277
- let complete = true;
278
- for (const relative of filesUnder(root)) {
279
- const to = destination(relative, home);
280
- if (!to)
281
- continue;
282
- try {
283
- copyPrivate(path.join(root, relative), to, relative);
284
- result.moved++;
285
- const top = normalized(relative).split("/")[0];
286
- if (top !== "bin" && top !== "extension")
287
- fs.rmSync(path.join(root, relative), { force: true });
288
- } catch {
289
- complete = false;
290
- }
291
- }
292
- if (complete)
293
- result.removed.push(root);
294
- }
295
- const oldBinary = path.join(home, ".browse", "bin", binaryName());
296
- const newBinary = path.join(binRoot(home), binaryName());
297
- const settingsFile = path.join(configRoot2(home), "settings.json");
298
- try {
299
- rewriteBinaryText(settingsFile, oldBinary, newBinary);
300
- } catch {}
301
- const config = home === os.homedir() && process.env.XDG_CONFIG_HOME && path.isAbsolute(process.env.XDG_CONFIG_HOME) ? process.env.XDG_CONFIG_HOME : path.join(home, ".config");
302
- const opencodeConfigs = OPENCODE_CONFIG_NAMES.map((name) => path.join(config, "opencode", name));
303
- const locations = [
304
- ...agentLocations(home, config, () => {
305
- return;
306
- }, opencodeConfigs[0]).filter((location) => location.name !== "opencode"),
307
- ...opencodeConfigs.map((file) => ({ name: "opencode", file })),
308
- ...recorded
309
- ].filter((location, index, all) => all.findIndex((other) => other.name === location.name && normalized(other.file) === normalized(location.file)) === index);
310
- for (const location of locations) {
311
- try {
312
- if (rewriteAgent(location.name, location.file, oldBinary, newBinary))
313
- result.rewritten++;
314
- else if (rewriteBinaryText(location.file, oldBinary, newBinary))
315
- result.rewritten++;
316
- } catch {}
317
- }
318
- const stillReferences = (needle) => locations.some((location) => referencesPath(location.file, needle));
319
- const keep = new Set;
320
- const browseRoot = path.join(home, ".browse");
321
- if (stillReferences(oldBinary))
322
- keep.add(normalized(browseRoot));
323
- if (stillReferences(oldData))
324
- keep.add(normalized(oldData));
325
- const takenOver = legacyRuntime(home);
326
- if (takenOver?.movedTo && !(now - Date.parse(takenOver.switchedAt ?? "") >= LEGACY_HANDOVER_GRACE_MS))
327
- keep.add(normalized(oldData));
328
- if (takenOver?.movedTo) {
329
- try {
330
- fs.rmSync(takeoverRecord(home), { force: true });
331
- } catch {}
332
- }
333
- if (referencesPath(settingsFile, oldBinary))
334
- keep.add(normalized(browseRoot));
335
- result.removed = result.removed.filter((root) => !keep.has(normalized(root)));
336
- const removable = result.removed.splice(0);
337
- for (const root of removable) {
338
- try {
339
- const keepExtension = root === oldData && lexists(path.join(root, "extension"));
340
- if (!keepExtension)
341
- fs.rmSync(root, { recursive: true, force: true });
342
- else
343
- for (const name of fs.readdirSync(root))
344
- if (name !== "extension")
345
- fs.rmSync(path.join(root, name), { recursive: true, force: true });
346
- result.removed.push(root);
347
- } catch {}
348
- }
349
- return result;
350
- }
351
- export {
352
- copyLegacyData,
353
- migrateLegacy
354
- };