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