@neuralnomads/codenomad 0.9.4 → 0.10.2

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 (43) hide show
  1. package/README.md +60 -1
  2. package/dist/auth/manager.js +9 -0
  3. package/dist/config/schema.js +6 -0
  4. package/dist/index.js +160 -27
  5. package/dist/opencode-config/package.json +2 -2
  6. package/dist/opencode-config/plugin/lib/request.ts +95 -5
  7. package/dist/server/http-server.js +171 -27
  8. package/dist/server/network-addresses.js +72 -0
  9. package/dist/server/routes/auth.js +10 -4
  10. package/dist/server/routes/meta.js +23 -76
  11. package/dist/server/routes/worktrees.js +156 -0
  12. package/dist/server/tls.js +224 -0
  13. package/dist/workspaces/git-worktrees.js +199 -0
  14. package/dist/workspaces/instance-events.js +22 -2
  15. package/dist/workspaces/manager.js +2 -1
  16. package/dist/workspaces/worktree-map.js +116 -0
  17. package/package.json +4 -2
  18. package/public/apple-touch-icon-180x180.png +0 -0
  19. package/public/assets/core-BSTVzpXI.js +1 -0
  20. package/public/assets/index-B03HRcIM.css +1 -0
  21. package/public/assets/index-CytmS9NK.js +1 -0
  22. package/public/assets/index-D4PT0yE4.js +1 -0
  23. package/public/assets/index-DN20ggb1.js +1 -0
  24. package/public/assets/index-DdQ7zIzB.js +1 -0
  25. package/public/assets/{loading-BwDYSAEd.js → loading-CbmXgbWn.js} +1 -1
  26. package/public/assets/main-BVfqEQ1Q.js +184 -0
  27. package/public/favicon.ico +0 -0
  28. package/public/index.html +7 -4
  29. package/public/loading.html +7 -4
  30. package/public/logo.png +0 -0
  31. package/public/manifest.webmanifest +1 -0
  32. package/public/maskable-icon-512x512.png +0 -0
  33. package/public/pwa-192x192.png +0 -0
  34. package/public/pwa-512x512.png +0 -0
  35. package/public/pwa-64x64.png +0 -0
  36. package/public/registerSW.js +1 -0
  37. package/public/sw.js +1 -0
  38. package/public/ui-version.json +1 -1
  39. package/public/workbox-60d14903.js +1 -0
  40. package/public/assets/index-C7GIedAD.js +0 -1
  41. package/public/assets/index-DAv6RUOV.css +0 -1
  42. package/public/assets/index-DPFZXALm.js +0 -1
  43. package/public/assets/main-CPMBg7Qb.js +0 -184
package/README.md CHANGED
@@ -31,6 +31,11 @@ You can run CodeNomad directly without installing it:
31
31
  npx @neuralnomads/codenomad --launch
32
32
  ```
33
33
 
34
+ On startup, CodeNomad prints two URLs:
35
+
36
+ - `Local Connection URL : ...` (used by desktop shells)
37
+ - `Remote Connection URL : ...` (used by browsers/other machines when remote access is enabled)
38
+
34
39
  ### Install Globally
35
40
  Or install it globally to use the `codenomad` command:
36
41
 
@@ -44,7 +49,14 @@ You can configure the server using flags or environment variables:
44
49
 
45
50
  | Flag | Env Variable | Description |
46
51
  |------|--------------|-------------|
47
- | `--port <number>` | `CLI_PORT` | HTTP port (default 9898) |
52
+ | `--https <enabled>` | `CLI_HTTPS` | Enable HTTPS listener (default `true`) |
53
+ | `--http <enabled>` | `CLI_HTTP` | Enable HTTP listener (default `false`) |
54
+ | `--https-port <number>` | `CLI_HTTPS_PORT` | HTTPS port (default `9898`, use `0` for auto) |
55
+ | `--http-port <number>` | `CLI_HTTP_PORT` | HTTP port (default `9899`, use `0` for auto) |
56
+ | `--tls-key <path>` | `CLI_TLS_KEY` | TLS private key (PEM). Requires `--tls-cert`. |
57
+ | `--tls-cert <path>` | `CLI_TLS_CERT` | TLS certificate (PEM). Requires `--tls-key`. |
58
+ | `--tls-ca <path>` | `CLI_TLS_CA` | Optional CA chain/bundle (PEM) |
59
+ | `--tlsSANs <list>` | `CLI_TLS_SANS` | Additional TLS SANs (comma-separated) |
48
60
  | `--host <addr>` | `CLI_HOST` | Interface to bind (default 127.0.0.1) |
49
61
  | `--workspace-root <path>` | `CLI_WORKSPACE_ROOT` | Default root for new workspaces |
50
62
  | `--unrestricted-root` | `CLI_UNRESTRICTED_ROOT` | Allow full-filesystem browsing |
@@ -56,12 +68,59 @@ You can configure the server using flags or environment variables:
56
68
  | `--generate-token` | `CODENOMAD_GENERATE_TOKEN` | Emit a one-time local bootstrap token for desktop flows |
57
69
  | `--dangerously-skip-auth` | `CODENOMAD_SKIP_AUTH` | Disable CodeNomad's internal auth (use only behind a trusted perimeter) |
58
70
 
71
+ ### HTTP vs HTTPS
72
+
73
+ - Default: `--https=true --http=false` (HTTPS only).
74
+ - To run plain HTTP only (useful for development):
75
+
76
+ ```sh
77
+ codenomad --https=false --http=true
78
+ ```
79
+
80
+ - To run both HTTPS (for remote) and HTTP loopback (for desktop):
81
+
82
+ ```sh
83
+ codenomad --https=true --http=true
84
+ ```
85
+
86
+ ### Remote Access Binding Rules
87
+
88
+ - When remote access is enabled (bind host is non-loopback, e.g. `--host 0.0.0.0`):
89
+ - HTTP listens on `127.0.0.1` only.
90
+ - HTTPS listens on `--host` (LAN/all interfaces).
91
+ - When remote access is disabled (bind host is loopback, e.g. `--host 127.0.0.1`):
92
+ - Both HTTP and HTTPS listen on `127.0.0.1`.
93
+
94
+ ### Self-Signed Certificates
95
+
96
+ If `--https=true` and you do not provide `--tls-key/--tls-cert`, CodeNomad generates a local certificate automatically under your config directory:
97
+
98
+ - `~/.config/codenomad/tls/ca-cert.pem`
99
+ - `~/.config/codenomad/tls/server-cert.pem`
100
+
101
+ Certificates are valid for about 30 days and rotate automatically on startup when needed. You can add extra SANs via:
102
+
103
+ ```sh
104
+ codenomad --tlsSANs "localhost,127.0.0.1,my-hostname,192.168.1.10"
105
+ ```
106
+
59
107
  ### Authentication
60
108
  - Default behavior: CodeNomad requires a login (username/password) and stores a session cookie in the browser.
61
109
  - `--dangerously-skip-auth` / `CODENOMAD_SKIP_AUTH=true` disables the login prompt and treats all requests as authenticated.
62
110
  Use this only when access is already protected by another layer (SSO proxy, VPN, Coder workspace auth, etc.).
63
111
  If you bind to `0.0.0.0` while skipping auth, anyone who can reach the port can access the API.
64
112
 
113
+ ### Progressive Web App (PWA)
114
+ 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.
115
+
116
+ 1. Open the CodeNomad UI in a Chromium-based browser (Chrome, Edge, Brave, etc.).
117
+ 2. Click the install icon in the address bar, or use the browser menu → "Install CodeNomad".
118
+ 3. The app will open in a standalone window and appear in your OS app list.
119
+
120
+ > **TLS requirement**
121
+ > Browsers require a secure (`https://`) connection for PWA installation.
122
+ > 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).
123
+
65
124
  ### Data Storage
66
125
  - **Config**: `~/.config/codenomad/config.json`
67
126
  - **Instance Data**: `~/.config/codenomad/instances` (chat history, etc.)
@@ -90,9 +90,15 @@ export class AuthManager {
90
90
  setSessionCookie(reply, sessionId) {
91
91
  reply.header("Set-Cookie", buildSessionCookie(this.cookieName, sessionId));
92
92
  }
93
+ setSessionCookieWithOptions(reply, sessionId, options) {
94
+ reply.header("Set-Cookie", buildSessionCookie(this.cookieName, sessionId, options));
95
+ }
93
96
  clearSessionCookie(reply) {
94
97
  reply.header("Set-Cookie", buildSessionCookie(this.cookieName, "", { maxAgeSeconds: 0 }));
95
98
  }
99
+ clearSessionCookieWithOptions(reply, options) {
100
+ reply.header("Set-Cookie", buildSessionCookie(this.cookieName, "", { maxAgeSeconds: 0, ...options }));
101
+ }
96
102
  requireAuthStore() {
97
103
  if (!this.authStore) {
98
104
  throw new Error("Auth store is unavailable");
@@ -112,6 +118,9 @@ function resolvePath(filePath) {
112
118
  }
113
119
  function buildSessionCookie(name, value, options) {
114
120
  const parts = [`${name}=${encodeURIComponent(value)}`, "HttpOnly", "Path=/", "SameSite=Lax"];
121
+ if (options?.secure) {
122
+ parts.push("Secure");
123
+ }
115
124
  if (options?.maxAgeSeconds !== undefined) {
116
125
  parts.push(`Max-Age=${Math.max(0, Math.floor(options.maxAgeSeconds))}`);
117
126
  }
@@ -9,6 +9,7 @@ const PreferencesSchema = z.object({
9
9
  showThinkingBlocks: z.boolean().default(false),
10
10
  thinkingBlocksExpansion: z.enum(["expanded", "collapsed"]).default("expanded"),
11
11
  showTimelineTools: z.boolean().default(true),
12
+ promptSubmitOnEnter: z.boolean().default(false),
12
13
  lastUsedBinary: z.string().optional(),
13
14
  locale: z.string().optional(),
14
15
  environmentVariables: z.record(z.string()).default({}),
@@ -21,6 +22,11 @@ const PreferencesSchema = z.object({
21
22
  showUsageMetrics: z.boolean().default(true),
22
23
  autoCleanupBlankSessions: z.boolean().default(true),
23
24
  listeningMode: z.enum(["local", "all"]).default("local"),
25
+ // OS notifications
26
+ osNotificationsEnabled: z.boolean().default(false),
27
+ osNotificationsAllowWhenVisible: z.boolean().default(false),
28
+ notifyOnNeedsInput: z.boolean().default(true),
29
+ notifyOnIdle: z.boolean().default(true),
24
30
  });
25
31
  const RecentFolderSchema = z.object({
26
32
  path: z.string(),
package/dist/index.js CHANGED
@@ -18,21 +18,31 @@ import { createLogger } from "./logger";
18
18
  import { launchInBrowser } from "./launcher";
19
19
  import { resolveUi } from "./ui/remote-ui";
20
20
  import { AuthManager, BOOTSTRAP_TOKEN_STDOUT_PREFIX, DEFAULT_AUTH_USERNAME } from "./auth/manager";
21
+ import { resolveHttpsOptions } from "./server/tls";
22
+ import { resolveNetworkAddresses } from "./server/network-addresses";
21
23
  const require = createRequire(import.meta.url);
22
24
  const packageJson = require("../package.json");
23
25
  const __filename = fileURLToPath(import.meta.url);
24
26
  const __dirname = path.dirname(__filename);
25
27
  const DEFAULT_UI_STATIC_DIR = path.resolve(__dirname, "../public");
26
- const DEFAULT_PORT = 9898;
27
28
  const DEFAULT_HOST = "127.0.0.1";
28
29
  const DEFAULT_CONFIG_PATH = "~/.config/codenomad/config.json";
30
+ const DEFAULT_HTTPS_PORT = 9898;
31
+ const DEFAULT_HTTP_PORT = 9899;
29
32
  function parseCliOptions(argv) {
30
33
  const program = new Command()
31
34
  .name("codenomad")
32
35
  .description("CodeNomad CLI server")
33
36
  .version(packageJson.version, "-v, --version", "Show the CLI version")
34
37
  .addOption(new Option("--host <host>", "Host interface to bind").env("CLI_HOST").default(DEFAULT_HOST))
35
- .addOption(new Option("--port <number>", "Port for the HTTP server").env("CLI_PORT").default(DEFAULT_PORT).argParser(parsePort))
38
+ .addOption(new Option("--https <enabled>", "Enable HTTPS listener (true|false)").env("CLI_HTTPS").default("true"))
39
+ .addOption(new Option("--http <enabled>", "Enable HTTP listener (true|false)").env("CLI_HTTP").default("false"))
40
+ .addOption(new Option("--https-port <number>", "HTTPS port (0 for auto)").env("CLI_HTTPS_PORT").default(DEFAULT_HTTPS_PORT).argParser(parsePort))
41
+ .addOption(new Option("--http-port <number>", "HTTP port (0 for auto)").env("CLI_HTTP_PORT").default(DEFAULT_HTTP_PORT).argParser(parsePort))
42
+ .addOption(new Option("--tls-key <path>", "TLS private key (PEM)").env("CLI_TLS_KEY"))
43
+ .addOption(new Option("--tls-cert <path>", "TLS certificate (PEM)").env("CLI_TLS_CERT"))
44
+ .addOption(new Option("--tls-ca <path>", "TLS CA chain (PEM)").env("CLI_TLS_CA"))
45
+ .addOption(new Option("--tlsSANs <list>", "Additional TLS SANs (comma-separated)").env("CLI_TLS_SANS"))
36
46
  .addOption(new Option("--workspace-root <path>", "Workspace root directory").env("CLI_WORKSPACE_ROOT").default(process.cwd()))
37
47
  .addOption(new Option("--root <path>").env("CLI_ROOT").hideHelp(true))
38
48
  .addOption(new Option("--unrestricted-root", "Allow browsing the full filesystem").env("CLI_UNRESTRICTED_ROOT").default(false))
@@ -65,9 +75,21 @@ function parseCliOptions(argv) {
65
75
  const normalizedHost = resolveHost(parsed.host);
66
76
  const autoUpdateString = (parsed.uiAutoUpdate ?? "true").trim().toLowerCase();
67
77
  const uiAutoUpdate = autoUpdateString === "1" || autoUpdateString === "true" || autoUpdateString === "yes";
78
+ const httpsEnabled = parseBooleanEnv(parsed.https);
79
+ const httpEnabled = parseBooleanEnv(parsed.http);
80
+ if (!httpsEnabled && !httpEnabled) {
81
+ throw new InvalidArgumentError("At least one listener must be enabled (--https or --http)");
82
+ }
68
83
  return {
69
- port: parsed.port,
70
84
  host: normalizedHost,
85
+ https: httpsEnabled,
86
+ http: httpEnabled,
87
+ httpsPort: parsed.httpsPort,
88
+ httpPort: parsed.httpPort,
89
+ tlsKeyPath: parsed.tlsKey,
90
+ tlsCertPath: parsed.tlsCert,
91
+ tlsCaPath: parsed.tlsCa,
92
+ tlsSANs: parsed.tlsSANs,
71
93
  rootDir: resolvedRoot,
72
94
  configPath: parsed.config,
73
95
  unrestrictedRoot: Boolean(parsed.unrestrictedRoot),
@@ -104,6 +126,12 @@ function resolveHost(input) {
104
126
  }
105
127
  return trimmed;
106
128
  }
129
+ function resolvePath(filePath) {
130
+ if (filePath.startsWith("~/")) {
131
+ return path.join(process.env.HOME ?? "", filePath.slice(2));
132
+ }
133
+ return path.resolve(filePath);
134
+ }
107
135
  function programHasArg(argv, flag) {
108
136
  return argv.includes(flag);
109
137
  }
@@ -123,12 +151,18 @@ async function main() {
123
151
  }
124
152
  const eventBus = new EventBus(eventLogger);
125
153
  const isLoopbackHost = (host) => host === "127.0.0.1" || host === "::1" || host.startsWith("127.");
154
+ const configDir = path.dirname(resolvePath(options.configPath));
155
+ if ((options.tlsKeyPath && !options.tlsCertPath) || (!options.tlsKeyPath && options.tlsCertPath)) {
156
+ throw new InvalidArgumentError("--tls-key and --tls-cert must be provided together");
157
+ }
126
158
  const serverMeta = {
127
- httpBaseUrl: `http://${options.host}:${options.port}`,
159
+ localUrl: "http://localhost:0",
160
+ remoteUrl: undefined,
128
161
  eventsUrl: `/api/events`,
129
162
  host: options.host,
130
163
  listeningMode: isLoopbackHost(options.host) ? "local" : "all",
131
- port: options.port,
164
+ localPort: 0,
165
+ remotePort: undefined,
132
166
  hostLabel: options.host,
133
167
  workspaceRoot: options.rootDir,
134
168
  addresses: [],
@@ -146,6 +180,17 @@ async function main() {
146
180
  console.log(`${BOOTSTRAP_TOKEN_STDOUT_PREFIX}${token}`);
147
181
  }
148
182
  }
183
+ const tlsResolution = resolveHttpsOptions({
184
+ enabled: options.https,
185
+ configDir,
186
+ host: options.host,
187
+ tlsKeyPath: options.tlsKeyPath,
188
+ tlsCertPath: options.tlsCertPath,
189
+ tlsCaPath: options.tlsCaPath,
190
+ tlsSANs: options.tlsSANs,
191
+ logger: logger.child({ component: "tls" }),
192
+ });
193
+ const nodeExtraCaCertsPath = !options.http ? tlsResolution?.caCertPath : undefined;
149
194
  const configStore = new ConfigStore(options.configPath, eventBus, configLogger);
150
195
  const binaryRegistry = new BinaryRegistry(configStore, eventBus, configLogger);
151
196
  const workspaceManager = new WorkspaceManager({
@@ -154,7 +199,8 @@ async function main() {
154
199
  binaryRegistry,
155
200
  eventBus,
156
201
  logger: workspaceLogger,
157
- getServerBaseUrl: () => serverMeta.httpBaseUrl,
202
+ getServerBaseUrl: () => serverMeta.localUrl,
203
+ nodeExtraCaCertsPath,
158
204
  });
159
205
  const fileSystemBrowser = new FileSystemBrowser({ rootDir: options.rootDir, unrestricted: options.unrestrictedRoot });
160
206
  const instanceStore = new InstanceStore();
@@ -189,26 +235,113 @@ async function main() {
189
235
  latestServerUrl: uiResolution.latestServerUrl,
190
236
  minServerVersion: uiResolution.minServerVersion,
191
237
  };
192
- const server = createHttpServer({
193
- host: options.host,
194
- port: options.port,
195
- workspaceManager,
196
- configStore,
197
- binaryRegistry,
198
- fileSystemBrowser,
199
- eventBus,
200
- serverMeta,
201
- instanceStore,
202
- authManager,
203
- uiStaticDir: uiResolution.uiStaticDir ?? DEFAULT_UI_STATIC_DIR,
204
- uiDevServerUrl: uiResolution.uiDevServerUrl,
205
- logger,
206
- });
207
- const startInfo = await server.start();
208
- logger.info({ port: startInfo.port, host: options.host }, "HTTP server listening");
209
- console.log(`CodeNomad Server is ready at ${startInfo.url}`);
238
+ if (uiResolution.uiDevServerUrl && options.https) {
239
+ throw new InvalidArgumentError("UI dev proxy is only supported with --https=false --http=true");
240
+ }
241
+ const remoteAccessEnabled = options.host === "0.0.0.0" || !isLoopbackHost(options.host);
242
+ const httpsPortExplicit = programHasArg(process.argv.slice(2), "--https-port") || Boolean(process.env.CLI_HTTPS_PORT);
243
+ const httpPortExplicit = programHasArg(process.argv.slice(2), "--http-port") || Boolean(process.env.CLI_HTTP_PORT);
244
+ const httpsBindPort = httpsPortExplicit ? options.httpsPort : 0;
245
+ const httpBindPort = httpPortExplicit ? options.httpPort : 0;
246
+ // Listener binding rules:
247
+ // - Remote access enabled: HTTP listens on loopback, HTTPS on all IPs (host=0.0.0.0 / LAN IP).
248
+ // - Remote access disabled: both listen on loopback.
249
+ // - HTTP-only mode: respect --host (used for dev/testing).
250
+ const httpsBindHost = remoteAccessEnabled ? options.host : "127.0.0.1";
251
+ const httpBindHost = options.http ? (options.https ? "127.0.0.1" : options.host) : "127.0.0.1";
252
+ const servers = [];
253
+ const httpServer = options.http
254
+ ? createHttpServer({
255
+ bindHost: httpBindHost,
256
+ bindPort: httpBindPort,
257
+ defaultPort: options.httpPort,
258
+ protocol: "http",
259
+ workspaceManager,
260
+ configStore,
261
+ binaryRegistry,
262
+ fileSystemBrowser,
263
+ eventBus,
264
+ serverMeta,
265
+ instanceStore,
266
+ authManager,
267
+ uiStaticDir: uiResolution.uiStaticDir ?? DEFAULT_UI_STATIC_DIR,
268
+ uiDevServerUrl: uiResolution.uiDevServerUrl,
269
+ logger,
270
+ })
271
+ : null;
272
+ const httpsServer = options.https
273
+ ? createHttpServer({
274
+ bindHost: httpsBindHost,
275
+ bindPort: httpsBindPort,
276
+ defaultPort: options.httpsPort,
277
+ protocol: "https",
278
+ httpsOptions: tlsResolution?.httpsOptions,
279
+ workspaceManager,
280
+ configStore,
281
+ binaryRegistry,
282
+ fileSystemBrowser,
283
+ eventBus,
284
+ serverMeta,
285
+ instanceStore,
286
+ authManager,
287
+ uiStaticDir: uiResolution.uiStaticDir ?? DEFAULT_UI_STATIC_DIR,
288
+ uiDevServerUrl: undefined,
289
+ logger,
290
+ })
291
+ : null;
292
+ if (httpServer)
293
+ servers.push(httpServer);
294
+ if (httpsServer)
295
+ servers.push(httpsServer);
296
+ const [httpStart, httpsStart] = await Promise.all([
297
+ httpServer ? httpServer.start() : Promise.resolve(null),
298
+ httpsServer ? httpsServer.start() : Promise.resolve(null),
299
+ ]);
300
+ const localStart = httpStart ?? httpsStart;
301
+ if (!localStart) {
302
+ throw new Error("No listeners started");
303
+ }
304
+ const remoteStart = httpsStart ?? httpStart;
305
+ const localProtocol = httpStart ? "http" : "https";
306
+ const remoteProtocol = httpsStart ? "https" : "http";
307
+ // Use an explicit IPv4 loopback address for the "local" URL.
308
+ // On macOS, `localhost` often resolves to ::1 first, and it is possible to have
309
+ // another instance bound on IPv6 while this instance binds IPv4 (or vice versa),
310
+ // which can lead clients to talk to the wrong process.
311
+ const localUrl = `${localProtocol}://127.0.0.1:${localStart.port}`;
312
+ let remoteUrl;
313
+ if (remoteStart) {
314
+ const wantsAll = options.host === "0.0.0.0" || !isLoopbackHost(options.host);
315
+ let remoteHost = options.host;
316
+ if (wantsAll) {
317
+ if (options.host === "0.0.0.0") {
318
+ const candidates = resolveNetworkAddresses({ host: options.host, protocol: remoteProtocol, port: remoteStart.port });
319
+ remoteHost = candidates.find((addr) => addr.scope === "external")?.ip ?? "localhost";
320
+ }
321
+ }
322
+ else {
323
+ remoteHost = "localhost";
324
+ }
325
+ remoteUrl = `${remoteProtocol}://${remoteHost}:${remoteStart.port}`;
326
+ }
327
+ serverMeta.localUrl = localUrl;
328
+ serverMeta.localPort = localStart.port;
329
+ serverMeta.remoteUrl = remoteUrl;
330
+ serverMeta.remotePort = remoteStart?.port;
331
+ serverMeta.host = options.host;
332
+ serverMeta.listeningMode = options.host === "0.0.0.0" || !isLoopbackHost(options.host) ? "all" : "local";
333
+ if (serverMeta.remotePort && remoteUrl) {
334
+ serverMeta.addresses = resolveNetworkAddresses({ host: options.host, protocol: remoteProtocol, port: serverMeta.remotePort });
335
+ }
336
+ else {
337
+ serverMeta.addresses = [];
338
+ }
339
+ console.log(`Local Connection URL : ${serverMeta.localUrl}`);
340
+ if (serverMeta.remoteUrl) {
341
+ console.log(`Remote Connection URL : ${serverMeta.remoteUrl}`);
342
+ }
210
343
  if (options.launch) {
211
- await launchInBrowser(startInfo.url, logger.child({ component: "launcher" }));
344
+ await launchInBrowser(serverMeta.localUrl, logger.child({ component: "launcher" }));
212
345
  }
213
346
  let shuttingDown = false;
214
347
  const shutdown = async () => {
@@ -235,8 +368,8 @@ async function main() {
235
368
  })();
236
369
  const shutdownHttp = (async () => {
237
370
  try {
238
- await server.stop();
239
- logger.info("HTTP server stopped");
371
+ await Promise.allSettled(servers.map((srv) => srv.stop()));
372
+ logger.info("HTTP server(s) stopped");
240
373
  }
241
374
  catch (error) {
242
375
  logger.error({ err: error }, "Failed to stop HTTP server");
@@ -4,6 +4,6 @@
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "@opencode-ai/plugin": "1.1.42"
7
+ "@opencode-ai/plugin": "1.1.53"
8
8
  }
9
- }
9
+ }
@@ -1,3 +1,7 @@
1
+ import http from "http"
2
+ import https from "https"
3
+ import { Readable } from "stream"
4
+
1
5
  export type PluginEvent = {
2
6
  type: string
3
7
  properties?: Record<string, unknown>
@@ -16,7 +20,8 @@ export function getCodeNomadConfig(): CodeNomadConfig {
16
20
  }
17
21
 
18
22
  export function createCodeNomadRequester(config: CodeNomadConfig) {
19
- const baseUrl = config.baseUrl.replace(/\/+$/, "")
23
+ const rawBaseUrl = (config.baseUrl ?? "").trim()
24
+ const baseUrl = rawBaseUrl.replace(/\/+$/, "")
20
25
  const pluginBase = `${baseUrl}/workspaces/${encodeURIComponent(config.instanceId)}/plugin`
21
26
  const authorization = buildInstanceAuthorizationHeader()
22
27
 
@@ -42,10 +47,10 @@ export function createCodeNomadRequester(config: CodeNomadConfig) {
42
47
  const hasBody = init?.body !== undefined
43
48
  const headers = buildHeaders(init?.headers, hasBody)
44
49
 
45
- return fetch(url, {
46
- ...init,
47
- headers,
48
- })
50
+ // The CodeNomad plugin only talks to the local CodeNomad server.
51
+ // Use a single request implementation that tolerates custom/self-signed certs
52
+ // without disabling TLS verification for the whole Node process.
53
+ return nodeFetch(url, { ...init, headers }, { rejectUnauthorized: false })
49
54
  }
50
55
 
51
56
  const requestJson = async <T>(path: string, init?: RequestInit): Promise<T> => {
@@ -87,6 +92,91 @@ export function createCodeNomadRequester(config: CodeNomadConfig) {
87
92
  }
88
93
  }
89
94
 
95
+ async function nodeFetch(
96
+ url: string,
97
+ init: RequestInit & { headers?: Record<string, string> },
98
+ tls: { rejectUnauthorized: boolean },
99
+ ): Promise<Response> {
100
+ const parsed = new URL(url)
101
+ const isHttps = parsed.protocol === "https:"
102
+ const requestFn = isHttps ? https.request : http.request
103
+
104
+ const method = (init.method ?? "GET").toUpperCase()
105
+ const headers = init.headers ?? {}
106
+ const body = init.body
107
+
108
+ return await new Promise<Response>((resolve, reject) => {
109
+ const req = requestFn(
110
+ {
111
+ protocol: parsed.protocol,
112
+ hostname: parsed.hostname,
113
+ port: parsed.port ? Number(parsed.port) : undefined,
114
+ path: `${parsed.pathname}${parsed.search}`,
115
+ method,
116
+ headers,
117
+ ...(isHttps ? { rejectUnauthorized: tls.rejectUnauthorized } : {}),
118
+ },
119
+ (res) => {
120
+ const responseHeaders = new Headers()
121
+ for (const [key, value] of Object.entries(res.headers)) {
122
+ if (value === undefined) continue
123
+ if (Array.isArray(value)) {
124
+ responseHeaders.set(key, value.join(", "))
125
+ } else {
126
+ responseHeaders.set(key, String(value))
127
+ }
128
+ }
129
+
130
+ // Convert Node stream -> Web ReadableStream for Response.
131
+ const webBody = Readable.toWeb(res) as unknown as ReadableStream<Uint8Array>
132
+ resolve(new Response(webBody, { status: res.statusCode ?? 0, headers: responseHeaders }))
133
+ },
134
+ )
135
+
136
+ const signal = init.signal
137
+ const abort = () => {
138
+ const err = new Error("Request aborted")
139
+ ;(err as any).name = "AbortError"
140
+ req.destroy(err)
141
+ reject(err)
142
+ }
143
+
144
+ if (signal) {
145
+ if (signal.aborted) {
146
+ abort()
147
+ return
148
+ }
149
+ signal.addEventListener("abort", abort, { once: true })
150
+ req.once("close", () => signal.removeEventListener("abort", abort))
151
+ }
152
+
153
+ req.once("error", reject)
154
+
155
+ if (body === undefined || body === null) {
156
+ req.end()
157
+ return
158
+ }
159
+
160
+ if (typeof body === "string") {
161
+ req.end(body)
162
+ return
163
+ }
164
+
165
+ if (body instanceof Uint8Array) {
166
+ req.end(Buffer.from(body))
167
+ return
168
+ }
169
+
170
+ if (body instanceof ArrayBuffer) {
171
+ req.end(Buffer.from(new Uint8Array(body)))
172
+ return
173
+ }
174
+
175
+ // Fallback for less common BodyInit types.
176
+ req.end(String(body))
177
+ })
178
+ }
179
+
90
180
  function requireEnv(key: string): string {
91
181
  const value = process.env[key]
92
182
  if (!value || !value.trim()) {