@opencode/browse 0.0.0 → 0.0.6-dev.17
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/LICENSE +21 -0
- package/dist/cli-b4sbkefj.mjs +1725 -0
- package/dist/cli.mjs +63 -0
- package/dist/main-3qpkwaa7.mjs +1425 -0
- package/dist/main-4bht27ry.mjs +72 -0
- package/dist/main-4p2p9eey.mjs +334 -0
- package/dist/main-e4stqtf2.mjs +1698 -0
- package/dist/main-g5mke6rn.mjs +731 -0
- package/dist/main-kvmxefp1.mjs +217 -0
- package/dist/main-y7c1atbf.mjs +4 -0
- package/dist/main-zwe0c783.mjs +315 -0
- package/dist/mcp-2smdsn8z.mjs +870 -0
- package/dist/relay-helpers-pjcbxs7p.mjs +68 -0
- package/dist/relay-ns525pms.mjs +18151 -0
- package/dist/runtime-update-0mddkfy5.mjs +187 -0
- package/dist/setup-f2qjnvre.mjs +11320 -0
- package/dist/update-cyy1grjj.mjs +15 -0
- package/dist/version-wrebjhy7.mjs +8 -0
- package/package.json +55 -1
- package/skills/browse/SKILL.md +999 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cliCommand,
|
|
3
|
+
installCommand,
|
|
4
|
+
runtimeLayout,
|
|
5
|
+
versionEntry,
|
|
6
|
+
channelOf,
|
|
7
|
+
UPDATE_VERSION,
|
|
8
|
+
compareVersions,
|
|
9
|
+
readCurrent,
|
|
10
|
+
writeCurrent,
|
|
11
|
+
readState,
|
|
12
|
+
updateState,
|
|
13
|
+
npmRuntime,
|
|
14
|
+
autoUpdateOverride,
|
|
15
|
+
registryUrl,
|
|
16
|
+
fetchPublished,
|
|
17
|
+
installVersion,
|
|
18
|
+
pruneVersions,
|
|
19
|
+
switchVersion
|
|
20
|
+
} from "./main-g5mke6rn.mjs";
|
|
21
|
+
import {
|
|
22
|
+
Service,
|
|
23
|
+
layerFetch,
|
|
24
|
+
restartRelay,
|
|
25
|
+
startManagedRelay
|
|
26
|
+
} from "./main-3qpkwaa7.mjs";
|
|
27
|
+
import"./main-y7c1atbf.mjs";
|
|
28
|
+
import"./main-4bht27ry.mjs";
|
|
29
|
+
|
|
30
|
+
// src/runtime-update.ts
|
|
31
|
+
import { Effect } from "effect";
|
|
32
|
+
import { existsSync } from "node:fs";
|
|
33
|
+
var log = (line) => process.stdout.write(line + `
|
|
34
|
+
`);
|
|
35
|
+
async function switchTo(layout, version, options) {
|
|
36
|
+
const entry = versionEntry(layout, version);
|
|
37
|
+
if (!existsSync(entry))
|
|
38
|
+
return `${version} isn't installed`;
|
|
39
|
+
const before = readCurrent(layout);
|
|
40
|
+
let switched = false;
|
|
41
|
+
const point = Effect.sync(() => {
|
|
42
|
+
switchVersion(layout, version, options.previous);
|
|
43
|
+
switched = true;
|
|
44
|
+
});
|
|
45
|
+
const program = Effect.gen(function* () {
|
|
46
|
+
const relay = yield* Service;
|
|
47
|
+
const running = yield* Effect.result(relay.version);
|
|
48
|
+
if (running._tag === "Failure") {
|
|
49
|
+
yield* point;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
yield* restartRelay({
|
|
53
|
+
relay,
|
|
54
|
+
clientKind: "cli",
|
|
55
|
+
force: options.force,
|
|
56
|
+
otherBuild: true,
|
|
57
|
+
onShutdownAccepted: point,
|
|
58
|
+
start: Effect.suspend(() => switched ? Effect.void : point).pipe(Effect.andThen(startManagedRelay(entry)))
|
|
59
|
+
});
|
|
60
|
+
const now = yield* relay.version;
|
|
61
|
+
return now.version === version ? undefined : `a relay of version ${now.version} started first`;
|
|
62
|
+
}).pipe(Effect.provide(layerFetch));
|
|
63
|
+
const refused = await Effect.runPromise(program.pipe(Effect.catch((error) => Effect.succeed(error.message ?? String(error)))));
|
|
64
|
+
if (refused && switched && before)
|
|
65
|
+
writeCurrent(layout, before);
|
|
66
|
+
return refused;
|
|
67
|
+
}
|
|
68
|
+
function npmOnly(command) {
|
|
69
|
+
const runtime = npmRuntime();
|
|
70
|
+
if (runtime)
|
|
71
|
+
return runtime;
|
|
72
|
+
log(`\`${command}\` is for npm installs (\`${installCommand()}\`); this one isn't.`);
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
async function runRollback(args) {
|
|
77
|
+
const runtime = npmOnly("rollback");
|
|
78
|
+
if (!runtime)
|
|
79
|
+
return;
|
|
80
|
+
const { layout } = runtime;
|
|
81
|
+
const current = readCurrent(layout);
|
|
82
|
+
const previous = current.previous;
|
|
83
|
+
if (!previous || !existsSync(versionEntry(layout, previous))) {
|
|
84
|
+
log(`Nothing to roll back to: ${current.version} has no previous version installed.`);
|
|
85
|
+
process.exitCode = 1;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const refused = await switchTo(layout, previous, { previous: current.version, force: args.includes("--force") });
|
|
89
|
+
if (refused) {
|
|
90
|
+
log(`✗ Not rolled back: the relay didn't restart (${refused}).`);
|
|
91
|
+
log(` When no agent is using the browser, run \`${cliCommand("rollback")}\` again (or add --force to end what's blocking it).`);
|
|
92
|
+
process.exitCode = 1;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
updateState(layout, ({ pending: _pending, ...state }) => ({ ...state, skipped: current.version, lastUpdate: { from: current.version, to: previous, at: new Date().toISOString() } }));
|
|
96
|
+
log(`✓ Rolled back ${current.version} → ${previous}. Auto-update skips ${current.version} until a newer version is published.`);
|
|
97
|
+
log(" Running MCP servers switch to it between requests; restart opencode if a tool still reports the old version.");
|
|
98
|
+
}
|
|
99
|
+
async function runNpmUpdate(args, layout) {
|
|
100
|
+
const runtime = npmRuntime(layout ? { layout } : {});
|
|
101
|
+
if (!runtime)
|
|
102
|
+
return false;
|
|
103
|
+
const lay = runtime.layout;
|
|
104
|
+
const channel = channelOf(runtime.version);
|
|
105
|
+
const published = await fetchPublished({ registry: await registryUrl(), channel }).catch((error) => error);
|
|
106
|
+
if (published instanceof Error) {
|
|
107
|
+
log(`✗ Couldn't check for updates: ${published.message}`);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
updateState(lay, ({ failed: _failed, ...state }) => ({ ...state, checkedAt: Date.now(), latest: published.version, integrity: published.integrity }));
|
|
112
|
+
if (compareVersions(published.version, runtime.version) <= 0) {
|
|
113
|
+
log(`✓ Up to date: ${runtime.version} is the newest on the ${channel} channel.`);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (args.includes("--check")) {
|
|
117
|
+
log(`Update available: ${published.version} (you have ${runtime.version}). Run \`${cliCommand("update")}\` to install it.`);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
log(`Installing ${published.version} (you have ${runtime.version})…`);
|
|
121
|
+
const entry = await installVersion({ layout: lay, version: published.version, integrity: published.integrity, ...process.env.OPENCODE_BROWSER_NPM_REGISTRY ? { registry: await registryUrl() } : {} }).catch((error) => {
|
|
122
|
+
log(`✗ ${error.message}`);
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
return;
|
|
125
|
+
});
|
|
126
|
+
if (!entry)
|
|
127
|
+
return true;
|
|
128
|
+
updateState(lay, ({ skipped: _skipped, ...state }) => ({ ...state, pending: published.version }));
|
|
129
|
+
const current = readCurrent(lay);
|
|
130
|
+
const refused = await switchTo(lay, published.version, { previous: current.version, force: args.includes("--force") });
|
|
131
|
+
if (refused) {
|
|
132
|
+
const automatic = (autoUpdateOverride() ?? readState(lay).mode ?? "on") === "on";
|
|
133
|
+
log(`! Installed ${published.version}, but the relay didn't restart (${refused}).`);
|
|
134
|
+
log(automatic ? " It switches to the new version by itself once no agent is using the browser." : ` When no agent is using the browser, run \`${cliCommand("update")}\` again.`);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
updateState(lay, ({ pending: _pending, ...state }) => ({ ...state, lastUpdate: { from: current.version, to: published.version, at: new Date().toISOString() } }));
|
|
138
|
+
pruneVersions(lay);
|
|
139
|
+
log(`✓ Updated ${current.version} → ${published.version}.`);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
async function runRuntimeInstall(args) {
|
|
143
|
+
const layout = runtimeLayout();
|
|
144
|
+
const version = args[0];
|
|
145
|
+
const integrityAt = args.indexOf("--integrity");
|
|
146
|
+
const integrity = integrityAt === -1 ? undefined : args[integrityAt + 1];
|
|
147
|
+
if (!version || !UPDATE_VERSION.test(version)) {
|
|
148
|
+
log(`runtime-install: invalid version ${JSON.stringify(version)}`);
|
|
149
|
+
process.exitCode = 2;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const clear = (installing) => installing?.pid === process.pid ? undefined : installing;
|
|
153
|
+
try {
|
|
154
|
+
await installVersion({ layout, version, ...integrity ? { integrity } : {}, ...process.env.OPENCODE_BROWSER_NPM_REGISTRY ? { registry: await registryUrl() } : {} });
|
|
155
|
+
updateState(layout, ({ installing, lastError: _error, ...state }) => {
|
|
156
|
+
const still = clear(installing);
|
|
157
|
+
return { ...state, ...still ? { installing: still } : {}, pending: version };
|
|
158
|
+
});
|
|
159
|
+
log(`${new Date().toISOString()} installed ${version}`);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
updateState(layout, ({ installing, ...state }) => {
|
|
162
|
+
const still = clear(installing);
|
|
163
|
+
return { ...state, ...still ? { installing: still } : {}, lastError: { message: error.message, at: new Date().toISOString(), version } };
|
|
164
|
+
});
|
|
165
|
+
log(`${new Date().toISOString()} install of ${version} failed: ${error.message}`);
|
|
166
|
+
process.exitCode = 1;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function runRuntimeSwitch(args) {
|
|
170
|
+
const layout = runtimeLayout();
|
|
171
|
+
const version = args[0];
|
|
172
|
+
const current = readCurrent(layout);
|
|
173
|
+
if (!version || !current) {
|
|
174
|
+
process.exitCode = 2;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const refused = await switchTo(layout, version, { previous: current.version, force: false });
|
|
178
|
+
log(`${new Date().toISOString()} switch ${current.version} → ${version}: ${refused ? `refused (${refused})` : "done"}`);
|
|
179
|
+
if (refused)
|
|
180
|
+
process.exitCode = 1;
|
|
181
|
+
}
|
|
182
|
+
export {
|
|
183
|
+
runNpmUpdate,
|
|
184
|
+
runRollback,
|
|
185
|
+
runRuntimeInstall,
|
|
186
|
+
runRuntimeSwitch
|
|
187
|
+
};
|