@neuralnomads/codenomad 0.11.1 → 0.12.1
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/README.md +13 -2
- package/dist/index.js +1 -1
- package/dist/opencode-config/package.json +2 -2
- package/dist/server/http-server.js +119 -9
- package/dist/server/routes/auth-pages/login.html +2 -1
- package/dist/server/routes/auth.js +15 -1
- package/dist/server/routes/settings.js +3 -31
- package/dist/workspaces/manager.js +18 -38
- package/dist/workspaces/runtime.js +42 -0
- package/package.json +1 -1
- package/public/assets/index-BE4ptF6k.js +1 -0
- package/public/assets/index-DVSLDTNQ.css +1 -0
- package/public/assets/{loading-Bu5vIfc2.js → loading-CIrI-mp0.js} +1 -1
- package/public/assets/main-uwMqZaHh.js +250 -0
- package/public/index.html +3 -3
- package/public/loading.html +3 -3
- package/public/sw.js +1 -1
- package/public/ui-version.json +1 -1
- package/public/assets/index-Bi993fzd.js +0 -1
- package/public/assets/index-IUhCGbWv.css +0 -1
- package/public/assets/main-DN9FHv8o.js +0 -190
package/README.md
CHANGED
|
@@ -5,18 +5,21 @@
|
|
|
5
5
|
## Features & Capabilities
|
|
6
6
|
|
|
7
7
|
### 🌍 Deployment Freedom
|
|
8
|
+
|
|
8
9
|
- **Remote Access**: Host CodeNomad on a powerful workstation and access it from your lightweight laptop.
|
|
9
10
|
- **Code Anywhere**: Tunnel in via VPN or SSH to code securely from coffee shops or while traveling.
|
|
10
11
|
- **Multi-Device**: The responsive web client works on tablets and iPads, turning any screen into a dev terminal.
|
|
11
12
|
- **Always-On**: Run as a background service so your sessions are always ready when you connect.
|
|
12
13
|
|
|
13
14
|
### ⚡️ Workspace Power
|
|
15
|
+
|
|
14
16
|
- **Multi-Instance**: Juggle multiple OpenCode sessions side-by-side with per-instance tabs.
|
|
15
17
|
- **Long-Context Native**: Scroll through massive transcripts without hitches.
|
|
16
18
|
- **Deep Task Awareness**: Monitor background tasks and child sessions without losing your flow.
|
|
17
19
|
- **Command Palette**: A single, global palette to jump tabs, launch tools, and fire shortcuts.
|
|
18
20
|
|
|
19
21
|
## Prerequisites
|
|
22
|
+
|
|
20
23
|
- **OpenCode**: `opencode` must be installed and configured on your system.
|
|
21
24
|
- Node.js 18+ and npm (for running or building from source).
|
|
22
25
|
- A workspace folder on disk you want to serve.
|
|
@@ -25,6 +28,7 @@
|
|
|
25
28
|
## Usage
|
|
26
29
|
|
|
27
30
|
### Run via npx (Recommended)
|
|
31
|
+
|
|
28
32
|
You can run CodeNomad directly without installing it:
|
|
29
33
|
|
|
30
34
|
```sh
|
|
@@ -43,6 +47,7 @@ On startup, CodeNomad prints two URLs:
|
|
|
43
47
|
- `Remote Connection URL : ...` (used by browsers/other machines when remote access is enabled)
|
|
44
48
|
|
|
45
49
|
### Install Globally
|
|
50
|
+
|
|
46
51
|
Or install it globally to use the `codenomad` command:
|
|
47
52
|
|
|
48
53
|
```sh
|
|
@@ -51,6 +56,7 @@ codenomad --launch
|
|
|
51
56
|
```
|
|
52
57
|
|
|
53
58
|
### Install Locally (per-project)
|
|
59
|
+
|
|
54
60
|
If you prefer to install CodeNomad into a project and run the local binary:
|
|
55
61
|
|
|
56
62
|
```sh
|
|
@@ -61,6 +67,7 @@ npx codenomad --launch
|
|
|
61
67
|
(`npx codenomad ...` will use `./node_modules/.bin/codenomad` when present.)
|
|
62
68
|
|
|
63
69
|
### Common Flags
|
|
70
|
+
|
|
64
71
|
You can configure the server using flags or environment variables:
|
|
65
72
|
|
|
66
73
|
| Flag | Env Variable | Description |
|
|
@@ -74,7 +81,7 @@ You can configure the server using flags or environment variables:
|
|
|
74
81
|
| `--tls-ca <path>` | `CLI_TLS_CA` | Optional CA chain/bundle (PEM) |
|
|
75
82
|
| `--tlsSANs <list>` | `CLI_TLS_SANS` | Additional TLS SANs (comma-separated) |
|
|
76
83
|
| `--host <addr>` | `CLI_HOST` | Interface to bind (default 127.0.0.1) |
|
|
77
|
-
| `--workspace-root <path>` | `CLI_WORKSPACE_ROOT` |
|
|
84
|
+
| `--workspace-root <path>` | `CLI_WORKSPACE_ROOT` | Restricts the root path where new workspaces can be opened. Git worktrees are created in `.codenomad/worktrees` inside the project folder. |
|
|
78
85
|
| `--unrestricted-root` | `CLI_UNRESTRICTED_ROOT` | Allow full-filesystem browsing |
|
|
79
86
|
| `--config <path>` | `CLI_CONFIG` | Config file location |
|
|
80
87
|
| `--launch` | `CLI_LAUNCH` | Open the UI in a Chromium-based browser |
|
|
@@ -87,10 +94,11 @@ You can configure the server using flags or environment variables:
|
|
|
87
94
|
| `--ui-dir <path>` | `CLI_UI_DIR` | Directory containing the built UI bundle |
|
|
88
95
|
| `--ui-dev-server <url>` | `CLI_UI_DEV_SERVER` | Proxy UI requests to a running dev server (requires `--https=false --http=true`) |
|
|
89
96
|
| `--ui-no-update` | `CLI_UI_NO_UPDATE` | Disable remote UI updates |
|
|
90
|
-
| `--ui-auto-update <enabled>` | `CLI_UI_AUTO_UPDATE` | Enable remote UI updates (true
|
|
97
|
+
| `--ui-auto-update <enabled>` | `CLI_UI_AUTO_UPDATE` | Enable remote UI updates (`true` |
|
|
91
98
|
| `--ui-manifest-url <url>` | `CLI_UI_MANIFEST_URL` | Remote UI manifest URL |
|
|
92
99
|
|
|
93
100
|
### Dev Releases (Advanced)
|
|
101
|
+
|
|
94
102
|
If you want the latest bleeding-edge builds (published as GitHub pre-releases), use the dev package:
|
|
95
103
|
|
|
96
104
|
```sh
|
|
@@ -141,12 +149,14 @@ codenomad --tlsSANs "localhost,127.0.0.1,my-hostname,192.168.1.10"
|
|
|
141
149
|
```
|
|
142
150
|
|
|
143
151
|
### Authentication
|
|
152
|
+
|
|
144
153
|
- Default behavior: CodeNomad requires a login (username/password) and stores a session cookie in the browser.
|
|
145
154
|
- `--dangerously-skip-auth` / `CODENOMAD_SKIP_AUTH=true` disables the login prompt and treats all requests as authenticated.
|
|
146
155
|
Use this only when access is already protected by another layer (SSO proxy, VPN, Coder workspace auth, etc.).
|
|
147
156
|
If you bind to `0.0.0.0` while skipping auth, anyone who can reach the port can access the API.
|
|
148
157
|
|
|
149
158
|
### Progressive Web App (PWA)
|
|
159
|
+
|
|
150
160
|
When running as a server CodeNomad can also be installed as a PWA from any supported browser, giving you a native app experience just like the Electron installation but executing on the remote server instead.
|
|
151
161
|
|
|
152
162
|
1. Open the CodeNomad UI in a Chromium-based browser (Chrome, Edge, Brave, etc.).
|
|
@@ -158,5 +168,6 @@ When running as a server CodeNomad can also be installed as a PWA from any suppo
|
|
|
158
168
|
> If you host CodeNomad on a remote machine, use HTTPS. Self-signed certificates generally won't work unless they are explicitly trusted by the device/browser (e.g., via a custom CA).
|
|
159
169
|
|
|
160
170
|
### Data Storage
|
|
171
|
+
|
|
161
172
|
- **Config**: `~/.config/codenomad/config.json`
|
|
162
173
|
- **Instance Data**: `~/.config/codenomad/instances` (chat history, etc.)
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ function parseCliOptions(argv) {
|
|
|
45
45
|
.addOption(new Option("--tls-cert <path>", "TLS certificate (PEM)").env("CLI_TLS_CERT"))
|
|
46
46
|
.addOption(new Option("--tls-ca <path>", "TLS CA chain (PEM)").env("CLI_TLS_CA"))
|
|
47
47
|
.addOption(new Option("--tlsSANs <list>", "Additional TLS SANs (comma-separated)").env("CLI_TLS_SANS"))
|
|
48
|
-
.addOption(new Option("--workspace-root <path>", "
|
|
48
|
+
.addOption(new Option("--workspace-root <path>", "Restricts root path where workspaces can be opened").env("CLI_WORKSPACE_ROOT").default(process.cwd()))
|
|
49
49
|
.addOption(new Option("--root <path>").env("CLI_ROOT").hideHelp(true))
|
|
50
50
|
.addOption(new Option("--unrestricted-root", "Allow browsing the full filesystem").env("CLI_UNRESTRICTED_ROOT").default(false))
|
|
51
51
|
.addOption(new Option("--config <path>", "Path to the config file").env("CLI_CONFIG").default(DEFAULT_CONFIG_PATH))
|
|
@@ -282,6 +282,20 @@ function registerInstanceProxyRoutes(app, deps) {
|
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
const INSTANCE_PROXY_HOST = "127.0.0.1";
|
|
285
|
+
// Special-case OpenCode directory override.
|
|
286
|
+
//
|
|
287
|
+
// UI clients may need to scope certain requests to an arbitrary directory that is not
|
|
288
|
+
// part of the Git worktree list. Since the OpenCode SDK does not reliably support
|
|
289
|
+
// injecting per-request headers, we encode an override into the *path* and strip it
|
|
290
|
+
// before proxying to the instance.
|
|
291
|
+
//
|
|
292
|
+
// Example proxied request path:
|
|
293
|
+
// /workspaces/:id/worktrees/:slug/instance/__dir/<base64url>/session/create
|
|
294
|
+
//
|
|
295
|
+
// The server will decode <base64url> -> absolute directory, validate it, then set
|
|
296
|
+
// x-opencode-directory accordingly and forward the request to /session/create.
|
|
297
|
+
const OPENCODE_DIR_OVERRIDE_PREFIX = "__dir/";
|
|
298
|
+
const OPENCODE_DIR_OVERRIDE_MAX_LEN = 4096;
|
|
285
299
|
async function proxyWorkspaceRequest(args) {
|
|
286
300
|
const { request, reply, workspaceManager, logger, worktreeSlug } = args;
|
|
287
301
|
const workspaceId = request.params.id;
|
|
@@ -357,17 +371,43 @@ async function proxyWorkspaceRequest(args) {
|
|
|
357
371
|
reply.code(400).send({ error: "Invalid worktree slug" });
|
|
358
372
|
return;
|
|
359
373
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
reply.code(404).send({ error: "Worktree not found" });
|
|
374
|
+
let extracted;
|
|
375
|
+
try {
|
|
376
|
+
extracted = extractOpencodeDirectoryOverride(args.pathSuffix);
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
const message = error instanceof Error ? error.message : "Invalid directory override";
|
|
380
|
+
reply.code(400).send({ error: message });
|
|
368
381
|
return;
|
|
369
382
|
}
|
|
370
|
-
|
|
383
|
+
let directory = null;
|
|
384
|
+
let forwardedSuffix = extracted.forwardedSuffix;
|
|
385
|
+
if (extracted.overrideDirectory) {
|
|
386
|
+
try {
|
|
387
|
+
directory = validateAndNormalizeOverrideDirectory({
|
|
388
|
+
overrideDirectory: extracted.overrideDirectory,
|
|
389
|
+
workspaceRoot: workspace.path,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
const message = error instanceof Error ? error.message : "Invalid directory override";
|
|
394
|
+
reply.code(400).send({ error: message });
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
directory = await resolveWorktreeDirectory({
|
|
400
|
+
workspaceId,
|
|
401
|
+
workspacePath: workspace.path,
|
|
402
|
+
worktreeSlug,
|
|
403
|
+
logger,
|
|
404
|
+
});
|
|
405
|
+
if (!directory) {
|
|
406
|
+
reply.code(404).send({ error: "Worktree not found" });
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const normalizedSuffix = normalizeInstanceSuffix(forwardedSuffix);
|
|
371
411
|
const queryIndex = (request.raw.url ?? "").indexOf("?");
|
|
372
412
|
const search = queryIndex >= 0 ? (request.raw.url ?? "").slice(queryIndex) : "";
|
|
373
413
|
const targetUrl = `http://${INSTANCE_PROXY_HOST}:${port}${normalizedSuffix}${search}`;
|
|
@@ -418,6 +458,76 @@ async function proxyWorkspaceRequest(args) {
|
|
|
418
458
|
},
|
|
419
459
|
});
|
|
420
460
|
}
|
|
461
|
+
function extractOpencodeDirectoryOverride(pathSuffix) {
|
|
462
|
+
if (!pathSuffix) {
|
|
463
|
+
return { overrideDirectory: null, forwardedSuffix: pathSuffix };
|
|
464
|
+
}
|
|
465
|
+
// Fastify wildcard param does not include a leading slash.
|
|
466
|
+
const trimmed = pathSuffix.replace(/^\/+/, "");
|
|
467
|
+
if (!trimmed.startsWith(OPENCODE_DIR_OVERRIDE_PREFIX)) {
|
|
468
|
+
return { overrideDirectory: null, forwardedSuffix: pathSuffix };
|
|
469
|
+
}
|
|
470
|
+
const rest = trimmed.slice(OPENCODE_DIR_OVERRIDE_PREFIX.length);
|
|
471
|
+
const slashIndex = rest.indexOf("/");
|
|
472
|
+
const encoded = (slashIndex >= 0 ? rest.slice(0, slashIndex) : rest).trim();
|
|
473
|
+
const remaining = slashIndex >= 0 ? rest.slice(slashIndex + 1) : "";
|
|
474
|
+
if (!encoded) {
|
|
475
|
+
throw new Error("Missing directory override");
|
|
476
|
+
}
|
|
477
|
+
if (encoded.length > OPENCODE_DIR_OVERRIDE_MAX_LEN) {
|
|
478
|
+
throw new Error("Directory override too large");
|
|
479
|
+
}
|
|
480
|
+
let overrideDirectory = "";
|
|
481
|
+
try {
|
|
482
|
+
overrideDirectory = decodeBase64Url(encoded);
|
|
483
|
+
}
|
|
484
|
+
catch {
|
|
485
|
+
throw new Error("Invalid directory override");
|
|
486
|
+
}
|
|
487
|
+
const forwardedSuffix = remaining;
|
|
488
|
+
return { overrideDirectory, forwardedSuffix };
|
|
489
|
+
}
|
|
490
|
+
function decodeBase64Url(input) {
|
|
491
|
+
// base64url -> base64
|
|
492
|
+
const normalized = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
493
|
+
const padding = normalized.length % 4 === 0 ? "" : "=".repeat(4 - (normalized.length % 4));
|
|
494
|
+
const base64 = `${normalized}${padding}`;
|
|
495
|
+
return Buffer.from(base64, "base64").toString("utf-8");
|
|
496
|
+
}
|
|
497
|
+
function validateAndNormalizeOverrideDirectory(params) {
|
|
498
|
+
const raw = params.overrideDirectory.trim();
|
|
499
|
+
if (!raw) {
|
|
500
|
+
throw new Error("Override directory is empty");
|
|
501
|
+
}
|
|
502
|
+
if (!path.isAbsolute(raw)) {
|
|
503
|
+
throw new Error("Override directory must be an absolute path");
|
|
504
|
+
}
|
|
505
|
+
if (!fs.existsSync(raw)) {
|
|
506
|
+
throw new Error(`Override directory does not exist: ${raw}`);
|
|
507
|
+
}
|
|
508
|
+
const stats = fs.statSync(raw);
|
|
509
|
+
if (!stats.isDirectory()) {
|
|
510
|
+
throw new Error(`Override path is not a directory: ${raw}`);
|
|
511
|
+
}
|
|
512
|
+
const normalizedOverride = fs.realpathSync(raw);
|
|
513
|
+
const normalizedRoot = fs.realpathSync(params.workspaceRoot);
|
|
514
|
+
if (!isSubpath(normalizedOverride, normalizedRoot)) {
|
|
515
|
+
throw new Error("Override directory must be within the workspace root");
|
|
516
|
+
}
|
|
517
|
+
return normalizedOverride;
|
|
518
|
+
}
|
|
519
|
+
function isSubpath(candidate, root) {
|
|
520
|
+
const rel = path.relative(root, candidate);
|
|
521
|
+
if (rel === "")
|
|
522
|
+
return true;
|
|
523
|
+
if (rel === "..")
|
|
524
|
+
return false;
|
|
525
|
+
if (rel.startsWith(`..${path.sep}`))
|
|
526
|
+
return false;
|
|
527
|
+
if (path.isAbsolute(rel))
|
|
528
|
+
return false;
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
421
531
|
function normalizeInstanceSuffix(pathSuffix) {
|
|
422
532
|
if (!pathSuffix || pathSuffix === "/") {
|
|
423
533
|
return "/";
|
|
@@ -119,7 +119,8 @@
|
|
|
119
119
|
showError(message || `Login failed (${res.status})`)
|
|
120
120
|
return
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
// Replace history entry so Back doesn't return to /login.
|
|
123
|
+
window.location.replace("/")
|
|
123
124
|
} catch (e) {
|
|
124
125
|
showError(e && e.message ? e.message : String(e))
|
|
125
126
|
}
|
|
@@ -35,7 +35,17 @@ function getTokenHtml() {
|
|
|
35
35
|
return cachedTokenTemplate;
|
|
36
36
|
}
|
|
37
37
|
export function registerAuthRoutes(app, deps) {
|
|
38
|
-
app.get("/login", async (
|
|
38
|
+
app.get("/login", async (request, reply) => {
|
|
39
|
+
// If already authenticated, don't show the login page.
|
|
40
|
+
const session = deps.authManager.getSessionFromRequest(request);
|
|
41
|
+
if (session) {
|
|
42
|
+
reply.redirect("/");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Avoid caching the login page (helps with bfcache/back behavior).
|
|
46
|
+
reply.header("Cache-Control", "no-store");
|
|
47
|
+
reply.header("Pragma", "no-cache");
|
|
48
|
+
reply.header("Expires", "0");
|
|
39
49
|
const status = deps.authManager.getStatus();
|
|
40
50
|
reply.type("text/html").send(getLoginHtml(status.username));
|
|
41
51
|
});
|
|
@@ -48,6 +58,10 @@ export function registerAuthRoutes(app, deps) {
|
|
|
48
58
|
reply.code(404).send({ error: "Not found" });
|
|
49
59
|
return;
|
|
50
60
|
}
|
|
61
|
+
// Avoid caching the token bootstrap page.
|
|
62
|
+
reply.header("Cache-Control", "no-store");
|
|
63
|
+
reply.header("Pragma", "no-cache");
|
|
64
|
+
reply.header("Expires", "0");
|
|
51
65
|
reply.type("text/html").send(getTokenHtml());
|
|
52
66
|
});
|
|
53
67
|
app.get("/api/auth/status", async (request, reply) => {
|
|
@@ -1,39 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { buildSpawnSpec } from "../../workspaces/runtime";
|
|
2
|
+
import { probeBinaryVersion } from "../../workspaces/runtime";
|
|
4
3
|
const ValidateBinarySchema = z.object({
|
|
5
4
|
path: z.string(),
|
|
6
5
|
});
|
|
7
6
|
function validateBinaryPath(binaryPath) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
const spec = buildSpawnSpec(binaryPath, ["--version"]);
|
|
12
|
-
try {
|
|
13
|
-
const result = spawnSync(spec.command, spec.args, {
|
|
14
|
-
encoding: "utf8",
|
|
15
|
-
windowsVerbatimArguments: Boolean(spec.options.windowsVerbatimArguments),
|
|
16
|
-
});
|
|
17
|
-
if (result.error) {
|
|
18
|
-
return { valid: false, error: result.error.message };
|
|
19
|
-
}
|
|
20
|
-
if (result.status !== 0) {
|
|
21
|
-
const stderr = result.stderr?.trim();
|
|
22
|
-
const stdout = result.stdout?.trim();
|
|
23
|
-
const combined = stderr || stdout;
|
|
24
|
-
const error = combined ? `Exited with code ${result.status}: ${combined}` : `Exited with code ${result.status}`;
|
|
25
|
-
return { valid: false, error };
|
|
26
|
-
}
|
|
27
|
-
const stdout = (result.stdout ?? "").trim();
|
|
28
|
-
const firstLine = stdout.split(/\r?\n/).find((line) => line.trim().length > 0);
|
|
29
|
-
const normalized = firstLine?.trim();
|
|
30
|
-
const versionMatch = normalized?.match(/([0-9]+\.[0-9]+\.[0-9A-Za-z.-]+)/);
|
|
31
|
-
const version = versionMatch?.[1];
|
|
32
|
-
return { valid: true, version };
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return { valid: false, error: error instanceof Error ? error.message : String(error) };
|
|
36
|
-
}
|
|
7
|
+
const result = probeBinaryVersion(binaryPath);
|
|
8
|
+
return { valid: result.valid, version: result.version, error: result.error };
|
|
37
9
|
}
|
|
38
10
|
export function registerSettingsRoutes(app, deps) {
|
|
39
11
|
// Full-document access
|
|
@@ -67,9 +67,6 @@ export class WorkspaceManager {
|
|
|
67
67
|
createdAt: new Date().toISOString(),
|
|
68
68
|
updatedAt: new Date().toISOString(),
|
|
69
69
|
};
|
|
70
|
-
if (!descriptor.binaryVersion) {
|
|
71
|
-
descriptor.binaryVersion = this.detectBinaryVersion(resolvedBinaryPath);
|
|
72
|
-
}
|
|
73
70
|
this.workspaces.set(id, descriptor);
|
|
74
71
|
this.options.eventBus.publish({ type: "workspace.created", workspace: descriptor });
|
|
75
72
|
const serverConfig = this.options.settings.getOwner("config", "server");
|
|
@@ -99,7 +96,10 @@ export class WorkspaceManager {
|
|
|
99
96
|
environment,
|
|
100
97
|
onExit: (info) => this.handleProcessExit(info.workspaceId, info),
|
|
101
98
|
});
|
|
102
|
-
await this.waitForWorkspaceReadiness({ workspaceId: id, port, exitPromise, getLastOutput });
|
|
99
|
+
const runtimeVersion = await this.waitForWorkspaceReadiness({ workspaceId: id, port, exitPromise, getLastOutput });
|
|
100
|
+
if (runtimeVersion) {
|
|
101
|
+
descriptor.binaryVersion = runtimeVersion;
|
|
102
|
+
}
|
|
103
103
|
descriptor.pid = pid;
|
|
104
104
|
descriptor.port = port;
|
|
105
105
|
descriptor.status = "ready";
|
|
@@ -208,35 +208,6 @@ export class WorkspaceManager {
|
|
|
208
208
|
}
|
|
209
209
|
return candidates[0] ?? "";
|
|
210
210
|
}
|
|
211
|
-
detectBinaryVersion(resolvedPath) {
|
|
212
|
-
if (!resolvedPath) {
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
try {
|
|
216
|
-
const result = spawnSync(resolvedPath, ["--version"], { encoding: "utf8" });
|
|
217
|
-
if (result.status === 0 && result.stdout) {
|
|
218
|
-
const line = result.stdout.split(/\r?\n/).find((entry) => entry.trim().length > 0);
|
|
219
|
-
if (line) {
|
|
220
|
-
const normalized = line.trim();
|
|
221
|
-
const versionMatch = normalized.match(/([0-9]+\.[0-9]+\.[0-9A-Za-z.-]+)/);
|
|
222
|
-
if (versionMatch) {
|
|
223
|
-
const version = versionMatch[1];
|
|
224
|
-
this.options.logger.debug({ binary: resolvedPath, version }, "Detected binary version");
|
|
225
|
-
return version;
|
|
226
|
-
}
|
|
227
|
-
this.options.logger.debug({ binary: resolvedPath, reported: normalized }, "Binary reported version string");
|
|
228
|
-
return normalized;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
else if (result.error) {
|
|
232
|
-
this.options.logger.warn({ binary: resolvedPath, err: result.error }, "Failed to read binary version");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
this.options.logger.warn({ binary: resolvedPath, err: error }, "Failed to detect binary version");
|
|
237
|
-
}
|
|
238
|
-
return undefined;
|
|
239
|
-
}
|
|
240
211
|
async waitForWorkspaceReadiness(params) {
|
|
241
212
|
await Promise.race([
|
|
242
213
|
this.waitForPortAvailability(params.port),
|
|
@@ -244,13 +215,14 @@ export class WorkspaceManager {
|
|
|
244
215
|
throw this.buildStartupError(params.workspaceId, "exited before becoming ready", info, params.getLastOutput());
|
|
245
216
|
}),
|
|
246
217
|
]);
|
|
247
|
-
await this.waitForInstanceHealth(params);
|
|
218
|
+
const version = await this.waitForInstanceHealth(params);
|
|
248
219
|
await Promise.race([
|
|
249
220
|
this.delay(STARTUP_STABILITY_DELAY_MS),
|
|
250
221
|
params.exitPromise.then((info) => {
|
|
251
222
|
throw this.buildStartupError(params.workspaceId, "exited shortly after start", info, params.getLastOutput());
|
|
252
223
|
}),
|
|
253
224
|
]);
|
|
225
|
+
return version;
|
|
254
226
|
}
|
|
255
227
|
async waitForInstanceHealth(params) {
|
|
256
228
|
const probeResult = await Promise.race([
|
|
@@ -260,7 +232,7 @@ export class WorkspaceManager {
|
|
|
260
232
|
}),
|
|
261
233
|
]);
|
|
262
234
|
if (probeResult.ok) {
|
|
263
|
-
return;
|
|
235
|
+
return probeResult.version;
|
|
264
236
|
}
|
|
265
237
|
const latestOutput = params.getLastOutput().trim();
|
|
266
238
|
if (latestOutput) {
|
|
@@ -270,7 +242,7 @@ export class WorkspaceManager {
|
|
|
270
242
|
throw new Error(`Workspace ${params.workspaceId} failed health check: ${reason}.`);
|
|
271
243
|
}
|
|
272
244
|
async probeInstance(workspaceId, port) {
|
|
273
|
-
const url = `http://127.0.0.1:${port}/
|
|
245
|
+
const url = `http://127.0.0.1:${port}/global/health`;
|
|
274
246
|
try {
|
|
275
247
|
const headers = {};
|
|
276
248
|
const authHeader = this.opencodeAuth.get(workspaceId)?.authorization;
|
|
@@ -279,11 +251,19 @@ export class WorkspaceManager {
|
|
|
279
251
|
}
|
|
280
252
|
const response = await fetch(url, { headers });
|
|
281
253
|
if (!response.ok) {
|
|
282
|
-
const reason =
|
|
254
|
+
const reason = `/global/health returned HTTP ${response.status}`;
|
|
283
255
|
this.options.logger.debug({ workspaceId, status: response.status }, "Health probe returned server error");
|
|
284
256
|
return { ok: false, reason };
|
|
285
257
|
}
|
|
286
|
-
|
|
258
|
+
const payload = (await response.json().catch(() => null));
|
|
259
|
+
const healthy = payload?.healthy === true;
|
|
260
|
+
const version = typeof payload?.version === "string" ? payload.version.trim() : undefined;
|
|
261
|
+
if (!healthy) {
|
|
262
|
+
const reason = "Instance reported unhealthy";
|
|
263
|
+
this.options.logger.debug({ workspaceId, payload }, "Health probe returned unhealthy response");
|
|
264
|
+
return { ok: false, reason };
|
|
265
|
+
}
|
|
266
|
+
return { ok: true, version: version || undefined };
|
|
287
267
|
}
|
|
288
268
|
catch (error) {
|
|
289
269
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -3,6 +3,7 @@ import { existsSync, statSync } from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
export const WINDOWS_CMD_EXTENSIONS = new Set([".cmd", ".bat"]);
|
|
5
5
|
export const WINDOWS_POWERSHELL_EXTENSIONS = new Set([".ps1"]);
|
|
6
|
+
const VERSION_REGEX = /([0-9]+\.[0-9]+\.[0-9A-Za-z.-]+)/;
|
|
6
7
|
export function buildSpawnSpec(binaryPath, args) {
|
|
7
8
|
if (process.platform !== "win32") {
|
|
8
9
|
return { command: binaryPath, args, options: {} };
|
|
@@ -29,6 +30,47 @@ export function buildSpawnSpec(binaryPath, args) {
|
|
|
29
30
|
}
|
|
30
31
|
return { command: binaryPath, args, options: {} };
|
|
31
32
|
}
|
|
33
|
+
export function probeBinaryVersion(binaryPath) {
|
|
34
|
+
if (!binaryPath) {
|
|
35
|
+
return { valid: false, error: "Missing binary path" };
|
|
36
|
+
}
|
|
37
|
+
const spec = buildSpawnSpec(binaryPath, ["--version"]);
|
|
38
|
+
try {
|
|
39
|
+
const result = spawnSync(spec.command, spec.args, {
|
|
40
|
+
encoding: "utf8",
|
|
41
|
+
windowsVerbatimArguments: Boolean(spec.options.windowsVerbatimArguments),
|
|
42
|
+
});
|
|
43
|
+
if (result.error) {
|
|
44
|
+
return { valid: false, error: result.error.message };
|
|
45
|
+
}
|
|
46
|
+
if (result.status !== 0) {
|
|
47
|
+
const stderr = result.stderr?.trim();
|
|
48
|
+
const stdout = result.stdout?.trim();
|
|
49
|
+
const combined = stderr || stdout;
|
|
50
|
+
const error = combined ? `Exited with code ${result.status}: ${combined}` : `Exited with code ${result.status}`;
|
|
51
|
+
return { valid: false, error };
|
|
52
|
+
}
|
|
53
|
+
const stdoutLines = String(result.stdout ?? "")
|
|
54
|
+
.split(/\r?\n/)
|
|
55
|
+
.map((line) => line.trim())
|
|
56
|
+
.filter((line) => line.length > 0);
|
|
57
|
+
const stderrLines = String(result.stderr ?? "")
|
|
58
|
+
.split(/\r?\n/)
|
|
59
|
+
.map((line) => line.trim())
|
|
60
|
+
.filter((line) => line.length > 0);
|
|
61
|
+
// Prefer stdout; fall back to stderr (some tools report version there).
|
|
62
|
+
const reported = stdoutLines[0] ?? stderrLines[0];
|
|
63
|
+
if (!reported) {
|
|
64
|
+
return { valid: true };
|
|
65
|
+
}
|
|
66
|
+
const versionMatch = reported.match(VERSION_REGEX);
|
|
67
|
+
const version = versionMatch?.[1];
|
|
68
|
+
return { valid: true, version, reported };
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return { valid: false, error: error instanceof Error ? error.message : String(error) };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
32
74
|
const SENSITIVE_ENV_KEY = /(PASSWORD|TOKEN|SECRET)/i;
|
|
33
75
|
function redactEnvironment(env) {
|
|
34
76
|
const redacted = {};
|