@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,233 @@
1
+ import {
2
+ parse,
3
+ parse2,
4
+ $parseDocument,
5
+ agentLocations,
6
+ browseServerCommand,
7
+ editAgentConfig,
8
+ configureMcp
9
+ } from "./main-fkskfb8a.mjs";
10
+ import"./main-1ja7rnnp.mjs";
11
+ import {
12
+ configRoot2,
13
+ dataRoot,
14
+ stateRoot,
15
+ cacheRoot,
16
+ binRoot,
17
+ binaryName
18
+ } from "./main-qzvstggv.mjs";
19
+ import"./main-vgzr4689.mjs";
20
+ import"./main-3d4mj1xj.mjs";
21
+ import"./main-mrew6jy8.mjs";
22
+
23
+ // src/setup/migrate.ts
24
+ import fs from "node:fs";
25
+ import os from "node:os";
26
+ import path from "node:path";
27
+ import { randomUUID } from "node:crypto";
28
+ function oldDataRoot(home) {
29
+ if (home !== os.homedir())
30
+ return path.join(home, ".local", "share", "opencode-browser");
31
+ if (process.platform === "win32")
32
+ return path.join(process.env.LOCALAPPDATA ?? path.join(home, "AppData", "Local"), "opencode-browser");
33
+ return path.join(process.env.XDG_DATA_HOME ?? path.join(home, ".local", "share"), "opencode-browser");
34
+ }
35
+ var normalized = (value) => value.replaceAll("\\", "/");
36
+ function destination(relative, home) {
37
+ const file = normalized(relative);
38
+ const [top, ...rest] = file.split("/");
39
+ if (top === "runtime" || top === "versions")
40
+ return;
41
+ if (top === "bin") {
42
+ const name = rest.join("/");
43
+ return name === binaryName() ? path.join(binRoot(home), binaryName()) : undefined;
44
+ }
45
+ if (file === "settings.json" || file === "config.json")
46
+ return path.join(configRoot2(home), file);
47
+ if (file === "update-check.json" || file === "extension.json" || top === "extension")
48
+ return path.join(cacheRoot(home), file);
49
+ if (file === "old-store-extension" || file === "auto-update.json" || file === "pairing-codes.json" || file === "session.json" || top === "logs" || top === "sessions")
50
+ return path.join(stateRoot(home), file);
51
+ if (top === "relays")
52
+ return path.join(path.basename(file) === "lifecycle.jsonl" ? stateRoot(home) : dataRoot(home), file);
53
+ return path.join(dataRoot(home), file);
54
+ }
55
+ var privatePath = (relative) => {
56
+ const file = normalized(relative);
57
+ return file === "relay-token" || file === "browser-tokens.json" || file === "pairing-codes.json" || file === "extension-pairing" || file === "session.json" || file.startsWith("secrets/") || file.startsWith("site-secrets/") || file.startsWith("sessions/") || file === "auto-update.json" || file === "old-store-extension";
58
+ };
59
+ function filesUnder(root, relative = "") {
60
+ let entries;
61
+ try {
62
+ entries = fs.readdirSync(path.join(root, relative), { withFileTypes: true });
63
+ } catch {
64
+ return [];
65
+ }
66
+ return entries.flatMap((entry) => {
67
+ const next = path.join(relative, entry.name);
68
+ if (entry.isDirectory())
69
+ return filesUnder(root, next);
70
+ return entry.isFile() ? [next] : [];
71
+ });
72
+ }
73
+ function copyPrivate(from, to, relative) {
74
+ if (fs.existsSync(to))
75
+ return;
76
+ fs.mkdirSync(path.dirname(to), { recursive: true, mode: privatePath(relative) ? 448 : 493 });
77
+ const temporary = `${to}.migrate-${process.pid}`;
78
+ fs.rmSync(temporary, { force: true });
79
+ try {
80
+ fs.copyFileSync(from, temporary);
81
+ const source = fs.statSync(from);
82
+ fs.chmodSync(temporary, privatePath(relative) ? 384 : source.mode & 511);
83
+ fs.renameSync(temporary, to);
84
+ } finally {
85
+ fs.rmSync(temporary, { force: true });
86
+ }
87
+ }
88
+ function configIsValid(file) {
89
+ const extension = path.extname(file).toLowerCase();
90
+ try {
91
+ const text = fs.readFileSync(file, "utf8");
92
+ if (extension === ".toml") {
93
+ parse2(text);
94
+ return true;
95
+ }
96
+ if (extension === ".yaml" || extension === ".yml") {
97
+ return $parseDocument(text, { merge: true }).errors.length === 0;
98
+ }
99
+ if (extension === ".json" || extension === ".jsonc") {
100
+ const errors = [];
101
+ parse(text, errors, { allowTrailingComma: true });
102
+ return errors.length === 0;
103
+ }
104
+ return true;
105
+ } catch {
106
+ return false;
107
+ }
108
+ }
109
+ function writeTextAtomic(file, text) {
110
+ const mode = fs.statSync(file).mode & 511;
111
+ const temporary = path.join(path.dirname(file), `.${path.basename(file)}.${process.pid}.${randomUUID()}.tmp`);
112
+ try {
113
+ fs.writeFileSync(temporary, text, { mode, flag: "wx" });
114
+ fs.chmodSync(temporary, mode);
115
+ fs.renameSync(temporary, file);
116
+ } finally {
117
+ fs.rmSync(temporary, { force: true });
118
+ }
119
+ }
120
+ function rewriteBinaryText(file, oldBinary, newBinary) {
121
+ if (!configIsValid(file))
122
+ return false;
123
+ let text;
124
+ try {
125
+ text = fs.readFileSync(file, "utf8");
126
+ } catch {
127
+ return false;
128
+ }
129
+ const before = text;
130
+ for (const [from, to] of [[oldBinary, newBinary], [oldBinary.replaceAll("\\", "\\\\"), newBinary.replaceAll("\\", "\\\\")]])
131
+ text = text.split(from).join(to);
132
+ if (text === before)
133
+ return false;
134
+ writeTextAtomic(file, text);
135
+ return true;
136
+ }
137
+ function referencesPath(file, needle) {
138
+ try {
139
+ const text = fs.readFileSync(file, "utf8");
140
+ return text.includes(needle) || text.includes(needle.replaceAll("\\", "\\\\"));
141
+ } catch {
142
+ return false;
143
+ }
144
+ }
145
+ var absoluteNode = (command) => /(^|[\\/])(node|node\.exe)$/i.test(command);
146
+ var npmEntry = (entry) => /(?:opencode-browser\.mjs|_npx[\\/].*@opencode[\\/]browse|node_modules[\\/]@opencode[\\/]browse)/i.test(entry);
147
+ function rewriteAgent(name, file, oldBinary, newBinary) {
148
+ if (!fs.existsSync(file))
149
+ return false;
150
+ const command = browseServerCommand(name, file);
151
+ if (!command || command.at(-1) !== "mcp")
152
+ return false;
153
+ const target = command.at(-2);
154
+ if (!target)
155
+ return false;
156
+ if (command[0] === oldBinary || normalized(command[0] ?? "") === normalized(oldBinary)) {
157
+ if (name === "opencode")
158
+ return !!configureMcp(file, newBinary, oldBinary);
159
+ const changed = editAgentConfig({ name, file, entry: oldBinary }, true);
160
+ return changed === "removed" && editAgentConfig({ name, file, entry: newBinary }) === "added";
161
+ }
162
+ if (absoluteNode(command[0] ?? "") && npmEntry(target)) {
163
+ if (name === "opencode")
164
+ return !!configureMcp(file, "browse", target);
165
+ const changed = editAgentConfig({ name, file, node: command[0], entry: target }, true);
166
+ return changed === "removed" && editAgentConfig({ name, file, entry: "browse" }) === "added";
167
+ }
168
+ return false;
169
+ }
170
+ function migrateLegacy(home = os.homedir()) {
171
+ const result = { moved: 0, rewritten: 0, removed: [] };
172
+ if (process.env.OPENCODE_BROWSER_HOME)
173
+ return result;
174
+ const roots = [path.join(home, ".browse"), oldDataRoot(home)];
175
+ for (const root of roots) {
176
+ if (!fs.existsSync(root))
177
+ continue;
178
+ let complete = true;
179
+ for (const relative of filesUnder(root)) {
180
+ const to = destination(relative, home);
181
+ if (!to)
182
+ continue;
183
+ try {
184
+ copyPrivate(path.join(root, relative), to, relative);
185
+ result.moved++;
186
+ } catch {
187
+ complete = false;
188
+ }
189
+ }
190
+ if (complete)
191
+ result.removed.push(root);
192
+ }
193
+ const oldBinary = path.join(home, ".browse", "bin", binaryName());
194
+ const newBinary = path.join(binRoot(home), binaryName());
195
+ const settingsFile = path.join(configRoot2(home), "settings.json");
196
+ try {
197
+ rewriteBinaryText(settingsFile, oldBinary, newBinary);
198
+ } catch {}
199
+ 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");
200
+ const locations = agentLocations(home, config, () => {
201
+ return;
202
+ }, path.join(config, "opencode", "opencode.json"));
203
+ for (const location of locations) {
204
+ try {
205
+ if (rewriteAgent(location.name, location.file, oldBinary, newBinary))
206
+ result.rewritten++;
207
+ else if (rewriteBinaryText(location.file, oldBinary, newBinary))
208
+ result.rewritten++;
209
+ } catch {}
210
+ }
211
+ const stillReferences = (needle) => locations.some((location) => referencesPath(location.file, needle));
212
+ const keep = new Set;
213
+ const browseRoot = path.join(home, ".browse");
214
+ const oldData = oldDataRoot(home);
215
+ if (stillReferences(oldBinary))
216
+ keep.add(normalized(browseRoot));
217
+ if (stillReferences(oldData))
218
+ keep.add(normalized(oldData));
219
+ if (referencesPath(settingsFile, oldBinary))
220
+ keep.add(normalized(browseRoot));
221
+ result.removed = result.removed.filter((root) => !keep.has(normalized(root)));
222
+ const removable = result.removed.splice(0);
223
+ for (const root of removable) {
224
+ try {
225
+ fs.rmSync(root, { recursive: true, force: true });
226
+ result.removed.push(root);
227
+ } catch {}
228
+ }
229
+ return result;
230
+ }
231
+ export {
232
+ migrateLegacy
233
+ };