agentroam 0.2.0-preview.77 → 0.2.0-preview.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.
- package/dist/opencode-runtime-manager.js +44 -23
- package/package.json +7 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { constants } from "node:fs";
|
|
3
3
|
import { access, chmod, mkdir, mkdtemp, open, rename, rm, stat } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
4
5
|
import { delimiter, isAbsolute, relative, resolve, win32 } from "node:path";
|
|
5
6
|
import { promisify } from "node:util";
|
|
6
7
|
import { resolveNpmExecutor } from "./codex-runtime-manager.js";
|
|
@@ -12,6 +13,7 @@ export const OPENCODE_MINIMUM_VERSION = "1.18.27";
|
|
|
12
13
|
const OPENCODE_PACKAGE = `opencode-ai@${OPENCODE_RUNTIME_VERSION}`;
|
|
13
14
|
const NPM_REGISTRY = "https://registry.npmjs.org";
|
|
14
15
|
const defaults = {
|
|
16
|
+
accessible,
|
|
15
17
|
async run(command, args, timeoutMs, signal) {
|
|
16
18
|
try {
|
|
17
19
|
const { stdout, stderr } = await execFileAsync(command, args, {
|
|
@@ -53,9 +55,15 @@ async function resolveRuntime(options) {
|
|
|
53
55
|
const absolute = platform === "win32" ? win32.isAbsolute(explicit) : isAbsolute(explicit);
|
|
54
56
|
if (!absolute)
|
|
55
57
|
throw new Error("AGENT_OPENCODE_BIN must be an absolute path");
|
|
56
|
-
|
|
58
|
+
if (platform === "win32" && /^opencode\.(?:cmd|bat)$/i.test(win32.basename(explicit))) {
|
|
59
|
+
const bundled = await firstCompatible(windowsOpenCodeNpmCandidates(windowsNpmModules(win32.dirname(explicit)), win32.resolve), "explicit", dependencies);
|
|
60
|
+
if (bundled)
|
|
61
|
+
return bundled;
|
|
62
|
+
throw new Error("AGENT_OPENCODE_BIN points to a Windows launcher without a compatible OpenCode executable");
|
|
63
|
+
}
|
|
64
|
+
return validate(explicit, "explicit", dependencies);
|
|
57
65
|
}
|
|
58
|
-
const global = await findGlobal(environment
|
|
66
|
+
const global = await findGlobal(environment, platform, dependencies);
|
|
59
67
|
if (global)
|
|
60
68
|
return global;
|
|
61
69
|
const managedRoot = resolve(options.dataDir, "runtimes", "opencode", OPENCODE_RUNTIME_VERSION);
|
|
@@ -74,8 +82,7 @@ export function parseOpenCodeVersion(output) {
|
|
|
74
82
|
export function managedOpenCodeBinaryCandidates(root, platform) {
|
|
75
83
|
return platform === "win32"
|
|
76
84
|
? [
|
|
77
|
-
resolve(root, "node_modules",
|
|
78
|
-
resolve(root, "node_modules", ".bin", "opencode.cmd"),
|
|
85
|
+
...windowsOpenCodeNpmCandidates(resolve(root, "node_modules"), resolve),
|
|
79
86
|
resolve(root, "node_modules", ".bin", "opencode.exe"),
|
|
80
87
|
]
|
|
81
88
|
: [
|
|
@@ -83,21 +90,35 @@ export function managedOpenCodeBinaryCandidates(root, platform) {
|
|
|
83
90
|
resolve(root, "node_modules", ".bin", "opencode"),
|
|
84
91
|
];
|
|
85
92
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
function windowsNpmModules(prefix) {
|
|
94
|
+
return win32.resolve(prefix, win32.basename(prefix).toLowerCase() === ".bin" ? ".." : "node_modules");
|
|
95
|
+
}
|
|
96
|
+
function windowsOpenCodeNpmCandidates(modules, resolvePath) {
|
|
97
|
+
return ["opencode-ai", "opencode-windows-x64-baseline", "opencode-windows-x64"]
|
|
98
|
+
.map(name => resolvePath(modules, name, "bin", "opencode.exe"));
|
|
99
|
+
}
|
|
100
|
+
async function findGlobal(environment, platform, dependencies) {
|
|
101
|
+
const windows = platform === "win32";
|
|
102
|
+
const directories = (environment.PATH ?? environment.Path ?? "").split(windows ? ";" : delimiter).filter(Boolean);
|
|
103
|
+
if (!windows) {
|
|
104
|
+
return firstCompatible(directories.map(dir => resolve(dir, "opencode")), "global", dependencies, true);
|
|
105
|
+
}
|
|
106
|
+
const pathDirs = directories.map(dir => dir.trim().replace(/^"(.*)"$/, "$1")).filter(Boolean);
|
|
107
|
+
const roaming = environment.APPDATA || win32.join(homedir(), "AppData", "Roaming");
|
|
108
|
+
const prefixes = [environment.npm_config_prefix || environment.NPM_CONFIG_PREFIX, win32.join(roaming, "npm")];
|
|
109
|
+
return firstCompatible([
|
|
110
|
+
...pathDirs.flatMap(dir => [win32.resolve(dir, "opencode.exe"), ...windowsOpenCodeNpmCandidates(windowsNpmModules(dir), win32.resolve)]),
|
|
111
|
+
...prefixes.filter((dir) => Boolean(dir)).flatMap(dir => windowsOpenCodeNpmCandidates(windowsNpmModules(dir), win32.resolve)),
|
|
112
|
+
], "global", dependencies);
|
|
113
|
+
}
|
|
114
|
+
async function firstCompatible(candidates, source, dependencies, executable = false) {
|
|
115
|
+
for (const candidate of new Set(candidates)) {
|
|
116
|
+
if (!await dependencies.accessible(candidate, executable))
|
|
117
|
+
continue;
|
|
118
|
+
try {
|
|
119
|
+
return await validate(candidate, source, dependencies);
|
|
100
120
|
}
|
|
121
|
+
catch { /* Keep looking for a compatible install. */ }
|
|
101
122
|
}
|
|
102
123
|
return null;
|
|
103
124
|
}
|
|
@@ -185,21 +206,21 @@ async function acquireLock(lockPath, managedRoot, platform, dependencies, waitMs
|
|
|
185
206
|
}
|
|
186
207
|
async function validateManaged(root, platform, dependencies) {
|
|
187
208
|
for (const executable of managedOpenCodeBinaryCandidates(root, platform)) {
|
|
188
|
-
if (!within(root, executable) || !(await accessible(executable)))
|
|
209
|
+
if (!within(root, executable) || !(await dependencies.accessible(executable)))
|
|
189
210
|
continue;
|
|
190
211
|
try {
|
|
191
212
|
if (platform !== "win32")
|
|
192
213
|
await chmod(executable, 0o755);
|
|
193
|
-
return await validate(executable, "managed",
|
|
214
|
+
return await validate(executable, "managed", dependencies);
|
|
194
215
|
}
|
|
195
216
|
catch {
|
|
196
|
-
|
|
217
|
+
// An unusable launcher may coexist with a working platform binary.
|
|
197
218
|
}
|
|
198
219
|
}
|
|
199
220
|
return null;
|
|
200
221
|
}
|
|
201
|
-
async function validate(executable, source,
|
|
202
|
-
if (!(await accessible(executable)))
|
|
222
|
+
async function validate(executable, source, dependencies) {
|
|
223
|
+
if (!(await dependencies.accessible(executable)))
|
|
203
224
|
throw new Error(`OpenCode executable not found: ${executable}`);
|
|
204
225
|
const result = await dependencies.run(executable, ["--version"], 5_000);
|
|
205
226
|
const version = parseOpenCodeVersion(`${result.stdout}\n${result.stderr}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentroam",
|
|
3
|
-
"version": "0.2.0-preview.
|
|
3
|
+
"version": "0.2.0-preview.78",
|
|
4
4
|
"description": "Zero-install mobile remote terminal and file console",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"ws": "^8.21.3"
|
|
28
28
|
},
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"agentroam-runtime-darwin-arm64": "0.2.0-preview.
|
|
31
|
-
"agentroam-runtime-win32-x64": "0.2.0-preview.
|
|
32
|
-
"agentroam-cloudflared-darwin-arm64": "0.2.0-preview.
|
|
33
|
-
"agentroam-cloudflared-win32-x64": "0.2.0-preview.
|
|
34
|
-
"agentroam-tui-darwin-arm64": "0.2.0-preview.
|
|
35
|
-
"@caoqu/agentroam-tui-win32-x64": "0.2.0-preview.
|
|
30
|
+
"agentroam-runtime-darwin-arm64": "0.2.0-preview.78",
|
|
31
|
+
"agentroam-runtime-win32-x64": "0.2.0-preview.78",
|
|
32
|
+
"agentroam-cloudflared-darwin-arm64": "0.2.0-preview.78",
|
|
33
|
+
"agentroam-cloudflared-win32-x64": "0.2.0-preview.78",
|
|
34
|
+
"agentroam-tui-darwin-arm64": "0.2.0-preview.78",
|
|
35
|
+
"@caoqu/agentroam-tui-win32-x64": "0.2.0-preview.78"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^22.0.0",
|