@neuralnomads/codenomad 0.13.3 → 0.14.0
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/auth/manager.js +5 -1
- package/dist/background-processes/manager.js +164 -25
- package/dist/config/schema.js +1 -0
- package/dist/events/bus.js +4 -0
- package/dist/index.js +56 -5
- package/dist/opencode-config/plugin/lib/background-process.ts +14 -2
- package/dist/plugins/voice-mode.js +2 -1
- package/dist/server/__tests__/network-addresses.test.js +68 -0
- package/dist/server/http-server.js +284 -15
- package/dist/server/network-addresses.js +43 -1
- package/dist/server/routes/background-processes.js +19 -1
- package/dist/server/routes/meta.js +0 -3
- package/dist/server/routes/plugin.js +5 -1
- package/dist/server/routes/remote-servers.js +142 -0
- package/dist/server/routes/sidecars.js +46 -0
- package/dist/settings/migrate.js +5 -0
- package/dist/settings/service.js +64 -4
- package/dist/sidecars/manager.js +193 -0
- package/dist/workspaces/manager.js +2 -0
- package/dist/workspaces/runtime.js +2 -1
- package/package.json +1 -1
- package/public/assets/ChangesTab-CFkk3tAp.js +2 -0
- package/public/assets/DiffToolbar-CQQLR1mp.js +1 -0
- package/public/assets/{FilesTab-BpYPA_Zr.js → FilesTab-CXgucPtN.js} +2 -2
- package/public/assets/GitChangesTab-BidSb28_.js +2 -0
- package/public/assets/{SplitFilePanel-DwrJM7GQ.js → SplitFilePanel-CupweEA5.js} +1 -1
- package/public/assets/StatusTab-C2Pl_Vce.js +1 -0
- package/public/assets/{bundle-full-JwmTIwMd.js → bundle-full-B-5u6Iv3.js} +1 -1
- package/public/assets/diff-viewer-_ehhYA-Z.js +1 -0
- package/public/assets/git-diff-vendor-CSgooKT_.js +52 -0
- package/public/assets/index-BnfDkr8C.js +1 -0
- package/public/assets/index-BntAaLZs.js +1 -0
- package/public/assets/index-BqiNjV6R.js +1 -0
- package/public/assets/index-BwCEJ4BE.css +1 -0
- package/public/assets/{index-CkYwnPl7.js → index-CxQr-wOF.js} +1 -1
- package/public/assets/index-DXaitXVC.js +1 -0
- package/public/assets/index-DzRzoTK8.js +2 -0
- package/public/assets/index-ShHad48G.js +1 -0
- package/public/assets/index-_EaXFUIj.js +1 -0
- package/public/assets/index-mMh5TJvW.js +1 -0
- package/public/assets/{loading-CfqkoCbA.js → loading-Dck2H3XH.js} +1 -1
- package/public/assets/main-BsIf5lOY.js +50 -0
- package/public/assets/{markdown-D2uUJada.js → markdown-CFV9kR80.js} +3 -3
- package/public/assets/monaco-viewer-CMM6n0T3.js +25 -0
- package/public/assets/{todo-i3zWdksA.js → todo-Ghwirj-b.js} +1 -1
- package/public/assets/tool-call-BC2Pv3uG.js +60 -0
- package/public/assets/unified-picker-Dw0kTXoT.js +1 -0
- package/public/assets/wrap-text-D2MJk2ad.js +1 -0
- package/public/index.html +5 -5
- package/public/loading.html +5 -5
- package/public/sw.js +1 -1
- package/public/ui-version.json +1 -1
- package/public/assets/ChangesTab-X8IIoIdB.js +0 -2
- package/public/assets/DiffToolbar-Djg0ksr_.js +0 -1
- package/public/assets/GitChangesTab-DeGsV8--.js +0 -2
- package/public/assets/StatusTab-mT1B3wST.js +0 -1
- package/public/assets/diff-viewer-CKnTxbWB.js +0 -1
- package/public/assets/git-diff-vendor-CAv-4upN.js +0 -52
- package/public/assets/index-BEzx5r3P.css +0 -1
- package/public/assets/index-BHjkPi4D.js +0 -1
- package/public/assets/index-CUkIenrg.js +0 -1
- package/public/assets/index-D9RMxxcS.js +0 -1
- package/public/assets/index-DiFfJ0HM.js +0 -1
- package/public/assets/index-LmDdmmJP.js +0 -1
- package/public/assets/index-UaIyK67v.js +0 -1
- package/public/assets/index-lhjxIgwf.js +0 -2
- package/public/assets/index-xsUu1uOf.js +0 -1
- package/public/assets/main-B3yZBpaS.js +0 -56
- package/public/assets/monaco-viewer-UU9TfOpS.js +0 -15
- package/public/assets/tool-call-Bl3Lai68.js +0 -60
- package/public/assets/unified-picker-B506AoQt.js +0 -1
package/dist/auth/manager.js
CHANGED
|
@@ -75,12 +75,16 @@ export class AuthManager {
|
|
|
75
75
|
return isLoopbackAddress(request.socket.remoteAddress);
|
|
76
76
|
}
|
|
77
77
|
getSessionFromRequest(request) {
|
|
78
|
+
return this.getSessionFromHeaders(request.headers);
|
|
79
|
+
}
|
|
80
|
+
getSessionFromHeaders(headers) {
|
|
78
81
|
if (!this.authEnabled) {
|
|
79
82
|
// When auth is disabled, treat all requests as authenticated.
|
|
80
83
|
// We still return a stable username so callers can display it.
|
|
81
84
|
return { username: this.init.username, sessionId: "auth-disabled" };
|
|
82
85
|
}
|
|
83
|
-
const
|
|
86
|
+
const cookieHeader = Array.isArray(headers.cookie) ? headers.cookie.join("; ") : headers.cookie;
|
|
87
|
+
const cookies = parseCookies(cookieHeader);
|
|
84
88
|
const sessionId = cookies[this.cookieName];
|
|
85
89
|
const session = this.sessionManager.getSession(sessionId);
|
|
86
90
|
if (!session)
|
|
@@ -19,12 +19,12 @@ export class BackgroundProcessManager {
|
|
|
19
19
|
async list(workspaceId) {
|
|
20
20
|
const records = await this.readIndex(workspaceId);
|
|
21
21
|
const enriched = await Promise.all(records.map(async (record) => ({
|
|
22
|
-
...record,
|
|
22
|
+
...this.toPublicProcess(record),
|
|
23
23
|
outputSizeBytes: await this.getOutputSize(workspaceId, record.id),
|
|
24
24
|
})));
|
|
25
25
|
return enriched;
|
|
26
26
|
}
|
|
27
|
-
async start(workspaceId, title, command) {
|
|
27
|
+
async start(workspaceId, title, command, options = {}) {
|
|
28
28
|
const workspace = this.deps.workspaceManager.get(workspaceId);
|
|
29
29
|
if (!workspace) {
|
|
30
30
|
throw new Error("Workspace not found");
|
|
@@ -53,21 +53,35 @@ export class BackgroundProcessManager {
|
|
|
53
53
|
pid: child.pid,
|
|
54
54
|
startedAt: new Date().toISOString(),
|
|
55
55
|
outputSizeBytes: 0,
|
|
56
|
+
notify: options.notify && options.notification
|
|
57
|
+
? {
|
|
58
|
+
sessionID: options.notification.sessionID,
|
|
59
|
+
directory: options.notification.directory,
|
|
60
|
+
}
|
|
61
|
+
: undefined,
|
|
62
|
+
};
|
|
63
|
+
const runningState = {
|
|
64
|
+
id,
|
|
65
|
+
child,
|
|
66
|
+
outputPath,
|
|
67
|
+
exitPromise: Promise.resolve(),
|
|
68
|
+
workspaceId,
|
|
56
69
|
};
|
|
57
70
|
const exitPromise = new Promise((resolve) => {
|
|
58
71
|
child.on("close", async (code) => {
|
|
59
72
|
await new Promise((resolve) => outputStream.end(resolve));
|
|
60
73
|
this.running.delete(id);
|
|
61
|
-
|
|
74
|
+
const completion = runningState.completion ?? this.completionFromExit(code);
|
|
75
|
+
record.terminalReason = completion.reason;
|
|
76
|
+
record.status = this.statusFromReason(completion.reason);
|
|
62
77
|
record.exitCode = code === null ? undefined : code;
|
|
63
78
|
record.stoppedAt = new Date().toISOString();
|
|
64
|
-
await this.
|
|
65
|
-
record.outputSizeBytes = await this.getOutputSize(workspaceId, record.id);
|
|
66
|
-
this.publishUpdate(workspaceId, record);
|
|
79
|
+
await this.finalizeRecord(workspaceId, record, completion);
|
|
67
80
|
resolve();
|
|
68
81
|
});
|
|
69
82
|
});
|
|
70
|
-
|
|
83
|
+
runningState.exitPromise = exitPromise;
|
|
84
|
+
this.running.set(id, runningState);
|
|
71
85
|
let lastPublishAt = 0;
|
|
72
86
|
const maybePublishSize = () => {
|
|
73
87
|
const now = Date.now();
|
|
@@ -90,7 +104,7 @@ export class BackgroundProcessManager {
|
|
|
90
104
|
await this.upsertIndex(workspaceId, record);
|
|
91
105
|
record.outputSizeBytes = await this.getOutputSize(workspaceId, record.id);
|
|
92
106
|
this.publishUpdate(workspaceId, record);
|
|
93
|
-
return record;
|
|
107
|
+
return this.toPublicProcess(record);
|
|
94
108
|
}
|
|
95
109
|
async stop(workspaceId, processId) {
|
|
96
110
|
const record = await this.findProcess(workspaceId, processId);
|
|
@@ -99,17 +113,19 @@ export class BackgroundProcessManager {
|
|
|
99
113
|
}
|
|
100
114
|
const running = this.running.get(processId);
|
|
101
115
|
if (running?.child && !running.child.killed) {
|
|
116
|
+
running.completion = { reason: "user_stopped", endContext: "normal" };
|
|
102
117
|
this.killProcessTree(running.child, "SIGTERM");
|
|
103
118
|
await this.waitForExit(running);
|
|
119
|
+
const updated = await this.findProcess(workspaceId, processId);
|
|
120
|
+
return updated ? this.toPublicProcess(updated) : this.toPublicProcess(record);
|
|
104
121
|
}
|
|
105
122
|
if (record.status === "running") {
|
|
106
123
|
record.status = "stopped";
|
|
124
|
+
record.terminalReason = "user_stopped";
|
|
107
125
|
record.stoppedAt = new Date().toISOString();
|
|
108
|
-
await this.
|
|
109
|
-
record.outputSizeBytes = await this.getOutputSize(workspaceId, record.id);
|
|
110
|
-
this.publishUpdate(workspaceId, record);
|
|
126
|
+
await this.finalizeRecord(workspaceId, record, { reason: "user_stopped", endContext: "normal" });
|
|
111
127
|
}
|
|
112
|
-
return record;
|
|
128
|
+
return this.toPublicProcess(record);
|
|
113
129
|
}
|
|
114
130
|
async terminate(workspaceId, processId) {
|
|
115
131
|
const record = await this.findProcess(workspaceId, processId);
|
|
@@ -117,15 +133,18 @@ export class BackgroundProcessManager {
|
|
|
117
133
|
return;
|
|
118
134
|
const running = this.running.get(processId);
|
|
119
135
|
if (running?.child && !running.child.killed) {
|
|
136
|
+
running.completion = { reason: "user_terminated", endContext: "normal", removeAfterFinalize: true };
|
|
120
137
|
this.killProcessTree(running.child, "SIGTERM");
|
|
121
138
|
await this.waitForExit(running);
|
|
139
|
+
return;
|
|
122
140
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
141
|
+
record.status = "stopped";
|
|
142
|
+
record.terminalReason = "user_terminated";
|
|
143
|
+
record.stoppedAt = new Date().toISOString();
|
|
144
|
+
await this.finalizeRecord(workspaceId, record, {
|
|
145
|
+
reason: "user_terminated",
|
|
146
|
+
endContext: "normal",
|
|
147
|
+
removeAfterFinalize: true,
|
|
129
148
|
});
|
|
130
149
|
}
|
|
131
150
|
async readOutput(workspaceId, processId, options) {
|
|
@@ -204,6 +223,11 @@ export class BackgroundProcessManager {
|
|
|
204
223
|
for (const [, running] of this.running.entries()) {
|
|
205
224
|
if (running.workspaceId !== workspaceId)
|
|
206
225
|
continue;
|
|
226
|
+
running.completion = {
|
|
227
|
+
reason: "user_terminated",
|
|
228
|
+
endContext: "workspace_cleanup",
|
|
229
|
+
removeAfterFinalize: true,
|
|
230
|
+
};
|
|
207
231
|
this.killProcessTree(running.child, "SIGTERM");
|
|
208
232
|
await this.waitForExit(running);
|
|
209
233
|
}
|
|
@@ -287,12 +311,16 @@ export class BackgroundProcessManager {
|
|
|
287
311
|
}
|
|
288
312
|
return args;
|
|
289
313
|
}
|
|
290
|
-
|
|
291
|
-
if (code ===
|
|
292
|
-
return "
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
314
|
+
completionFromExit(code) {
|
|
315
|
+
if (code === 0) {
|
|
316
|
+
return { reason: "finished", endContext: "normal" };
|
|
317
|
+
}
|
|
318
|
+
return { reason: "failed", endContext: "normal" };
|
|
319
|
+
}
|
|
320
|
+
statusFromReason(reason) {
|
|
321
|
+
if (reason === "failed")
|
|
322
|
+
return "error";
|
|
323
|
+
return "stopped";
|
|
296
324
|
}
|
|
297
325
|
async readOutputBytes(outputPath, sizeBytes, maxBytes) {
|
|
298
326
|
if (maxBytes === undefined || sizeBytes <= maxBytes) {
|
|
@@ -426,8 +454,119 @@ export class BackgroundProcessManager {
|
|
|
426
454
|
this.deps.eventBus.publish({
|
|
427
455
|
type: "instance.event",
|
|
428
456
|
instanceId: workspaceId,
|
|
429
|
-
event: { type: "background.process.updated", properties: { process: record } },
|
|
457
|
+
event: { type: "background.process.updated", properties: { process: this.toPublicProcess(record) } },
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
toPublicProcess(record) {
|
|
461
|
+
return {
|
|
462
|
+
id: record.id,
|
|
463
|
+
workspaceId: record.workspaceId,
|
|
464
|
+
title: record.title,
|
|
465
|
+
command: record.command,
|
|
466
|
+
cwd: record.cwd,
|
|
467
|
+
status: record.status,
|
|
468
|
+
pid: record.pid,
|
|
469
|
+
startedAt: record.startedAt,
|
|
470
|
+
stoppedAt: record.stoppedAt,
|
|
471
|
+
exitCode: record.exitCode,
|
|
472
|
+
outputSizeBytes: record.outputSizeBytes,
|
|
473
|
+
terminalReason: record.terminalReason,
|
|
474
|
+
notifyEnabled: Boolean(record.notify),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
async finalizeRecord(workspaceId, record, completion) {
|
|
478
|
+
if (this.shouldSendCompletionPrompt(record, completion)) {
|
|
479
|
+
try {
|
|
480
|
+
await this.sendCompletionPrompt(workspaceId, record);
|
|
481
|
+
if (record.notify) {
|
|
482
|
+
record.notify.sentAt = new Date().toISOString();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
this.deps.logger.warn({ err: error, workspaceId, processId: record.id }, "Failed to send background process completion prompt");
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (completion.removeAfterFinalize) {
|
|
490
|
+
await this.removeFromIndex(workspaceId, record.id);
|
|
491
|
+
await this.removeProcessDir(workspaceId, record.id);
|
|
492
|
+
this.deps.eventBus.publish({
|
|
493
|
+
type: "instance.event",
|
|
494
|
+
instanceId: workspaceId,
|
|
495
|
+
event: { type: "background.process.removed", properties: { processId: record.id } },
|
|
496
|
+
});
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
await this.upsertIndex(workspaceId, record);
|
|
500
|
+
record.outputSizeBytes = await this.getOutputSize(workspaceId, record.id);
|
|
501
|
+
this.publishUpdate(workspaceId, record);
|
|
502
|
+
}
|
|
503
|
+
shouldSendCompletionPrompt(record, completion) {
|
|
504
|
+
if (completion.endContext === "workspace_cleanup")
|
|
505
|
+
return false;
|
|
506
|
+
if (!record.notify)
|
|
507
|
+
return false;
|
|
508
|
+
return !record.notify.sentAt;
|
|
509
|
+
}
|
|
510
|
+
async sendCompletionPrompt(workspaceId, record) {
|
|
511
|
+
const notify = record.notify;
|
|
512
|
+
if (!notify || !record.terminalReason)
|
|
513
|
+
return;
|
|
514
|
+
if (!this.deps.workspaceManager.get(workspaceId)) {
|
|
515
|
+
throw new Error("Workspace not found");
|
|
516
|
+
}
|
|
517
|
+
const port = this.deps.workspaceManager.getInstancePort(workspaceId);
|
|
518
|
+
if (!port) {
|
|
519
|
+
throw new Error("Workspace instance is not ready");
|
|
520
|
+
}
|
|
521
|
+
const targetUrl = `http://127.0.0.1:${port}/session/${encodeURIComponent(notify.sessionID)}/prompt_async`;
|
|
522
|
+
const headers = {
|
|
523
|
+
"content-type": "application/json",
|
|
524
|
+
"x-opencode-directory": /[^\x00-\x7F]/.test(notify.directory) ? encodeURIComponent(notify.directory) : notify.directory,
|
|
525
|
+
};
|
|
526
|
+
const authorization = this.deps.workspaceManager.getInstanceAuthorizationHeader(workspaceId);
|
|
527
|
+
if (authorization) {
|
|
528
|
+
headers.authorization = authorization;
|
|
529
|
+
}
|
|
530
|
+
const response = await fetch(targetUrl, {
|
|
531
|
+
method: "POST",
|
|
532
|
+
headers,
|
|
533
|
+
body: JSON.stringify({
|
|
534
|
+
parts: [
|
|
535
|
+
{
|
|
536
|
+
type: "text",
|
|
537
|
+
text: this.buildSyntheticCompletionPrompt(record),
|
|
538
|
+
synthetic: true,
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
}),
|
|
430
542
|
});
|
|
543
|
+
if (!response.ok) {
|
|
544
|
+
const message = await response.text().catch(() => "");
|
|
545
|
+
throw new Error(message || `Prompt request failed with ${response.status}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
buildCompletionPrompt(record) {
|
|
549
|
+
const ref = `Background process "${record.title}" (${record.id})`;
|
|
550
|
+
switch (record.terminalReason) {
|
|
551
|
+
case "finished":
|
|
552
|
+
return `${ref} finished successfully.`;
|
|
553
|
+
case "failed":
|
|
554
|
+
return record.exitCode === undefined ? `${ref} failed.` : `${ref} failed with exit code ${record.exitCode}.`;
|
|
555
|
+
case "user_stopped":
|
|
556
|
+
return `${ref} was stopped by user.`;
|
|
557
|
+
case "user_terminated":
|
|
558
|
+
return `${ref} was terminated by user.`;
|
|
559
|
+
}
|
|
560
|
+
return `${ref} ended.`;
|
|
561
|
+
}
|
|
562
|
+
buildSyntheticCompletionPrompt(record) {
|
|
563
|
+
return `<system-message>${this.escapeTaggedText(this.buildCompletionPrompt(record))}</system-message>`;
|
|
564
|
+
}
|
|
565
|
+
escapeTaggedText(input) {
|
|
566
|
+
return input
|
|
567
|
+
.replace(/&/g, "&")
|
|
568
|
+
.replace(/</g, "<")
|
|
569
|
+
.replace(/>/g, ">");
|
|
431
570
|
}
|
|
432
571
|
generateId() {
|
|
433
572
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
package/dist/config/schema.js
CHANGED
|
@@ -23,6 +23,7 @@ const PreferencesSchema = z
|
|
|
23
23
|
showUsageMetrics: z.boolean().default(true),
|
|
24
24
|
autoCleanupBlankSessions: z.boolean().default(true),
|
|
25
25
|
listeningMode: z.enum(["local", "all"]).default("local"),
|
|
26
|
+
logLevel: z.enum(["DEBUG", "INFO", "WARN", "ERROR"]).default("DEBUG"),
|
|
26
27
|
// OS notifications
|
|
27
28
|
osNotificationsEnabled: z.boolean().default(false),
|
|
28
29
|
osNotificationsAllowWhenVisible: z.boolean().default(false),
|
package/dist/events/bus.js
CHANGED
|
@@ -20,6 +20,8 @@ export class EventBus extends EventEmitter {
|
|
|
20
20
|
this.on("workspace.error", handler);
|
|
21
21
|
this.on("workspace.stopped", handler);
|
|
22
22
|
this.on("workspace.log", handler);
|
|
23
|
+
this.on("sidecar.updated", handler);
|
|
24
|
+
this.on("sidecar.removed", handler);
|
|
23
25
|
this.on("storage.configChanged", handler);
|
|
24
26
|
this.on("storage.stateChanged", handler);
|
|
25
27
|
this.on("instance.dataChanged", handler);
|
|
@@ -31,6 +33,8 @@ export class EventBus extends EventEmitter {
|
|
|
31
33
|
this.off("workspace.error", handler);
|
|
32
34
|
this.off("workspace.stopped", handler);
|
|
33
35
|
this.off("workspace.log", handler);
|
|
36
|
+
this.off("sidecar.updated", handler);
|
|
37
|
+
this.off("sidecar.removed", handler);
|
|
34
38
|
this.off("storage.configChanged", handler);
|
|
35
39
|
this.off("storage.stateChanged", handler);
|
|
36
40
|
this.off("instance.dataChanged", handler);
|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,13 @@ import { launchInBrowser } from "./launcher";
|
|
|
20
20
|
import { resolveUi } from "./ui/remote-ui";
|
|
21
21
|
import { AuthManager, BOOTSTRAP_TOKEN_STDOUT_PREFIX, DEFAULT_AUTH_COOKIE_NAME, DEFAULT_AUTH_USERNAME } from "./auth/manager";
|
|
22
22
|
import { resolveHttpsOptions } from "./server/tls";
|
|
23
|
-
import { resolveNetworkAddresses } from "./server/network-addresses";
|
|
23
|
+
import { resolveNetworkAddresses, resolveRemoteAddresses } from "./server/network-addresses";
|
|
24
24
|
import { startDevReleaseMonitor } from "./releases/dev-release-monitor";
|
|
25
25
|
import { SpeechService } from "./speech/service";
|
|
26
|
+
import { SideCarManager } from "./sidecars/manager";
|
|
27
|
+
import { ClientConnectionManager } from "./clients/connection-manager";
|
|
28
|
+
import { PluginChannelManager } from "./plugins/channel";
|
|
29
|
+
import { VoiceModeManager } from "./plugins/voice-mode";
|
|
26
30
|
const require = createRequire(import.meta.url);
|
|
27
31
|
const packageJson = require("../package.json");
|
|
28
32
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -208,6 +212,11 @@ async function main() {
|
|
|
208
212
|
const fileSystemBrowser = new FileSystemBrowser({ rootDir: options.rootDir, unrestricted: options.unrestrictedRoot });
|
|
209
213
|
const instanceStore = new InstanceStore(configLocation.instancesDir);
|
|
210
214
|
const speechService = new SpeechService(settings, logger.child({ component: "speech" }));
|
|
215
|
+
const sidecarManager = new SideCarManager({
|
|
216
|
+
settings,
|
|
217
|
+
eventBus,
|
|
218
|
+
logger: logger.child({ component: "sidecars" }),
|
|
219
|
+
});
|
|
211
220
|
const instanceEventBridge = new InstanceEventBridge({
|
|
212
221
|
workspaceManager,
|
|
213
222
|
eventBus,
|
|
@@ -257,6 +266,13 @@ async function main() {
|
|
|
257
266
|
throw new InvalidArgumentError("UI dev proxy is only supported with --https=false --http=true");
|
|
258
267
|
}
|
|
259
268
|
const remoteAccessEnabled = options.host === "0.0.0.0" || !isLoopbackHost(options.host);
|
|
269
|
+
const clientConnectionManager = new ClientConnectionManager(logger.child({ component: "client-connections" }));
|
|
270
|
+
const pluginChannel = new PluginChannelManager(logger.child({ component: "plugin-channel" }));
|
|
271
|
+
const voiceModeManager = new VoiceModeManager({
|
|
272
|
+
connections: clientConnectionManager,
|
|
273
|
+
channel: pluginChannel,
|
|
274
|
+
logger: logger.child({ component: "voice-mode" }),
|
|
275
|
+
});
|
|
260
276
|
const httpsPortExplicit = programHasArg(process.argv.slice(2), "--https-port") || Boolean(process.env.CLI_HTTPS_PORT);
|
|
261
277
|
const httpPortExplicit = programHasArg(process.argv.slice(2), "--http-port") || Boolean(process.env.CLI_HTTP_PORT);
|
|
262
278
|
const httpsBindPort = httpsPortExplicit ? options.httpsPort : 0;
|
|
@@ -281,7 +297,11 @@ async function main() {
|
|
|
281
297
|
serverMeta,
|
|
282
298
|
instanceStore,
|
|
283
299
|
speechService,
|
|
300
|
+
sidecarManager,
|
|
284
301
|
authManager,
|
|
302
|
+
clientConnectionManager,
|
|
303
|
+
pluginChannel,
|
|
304
|
+
voiceModeManager,
|
|
285
305
|
uiStaticDir: uiResolution.uiStaticDir ?? DEFAULT_UI_STATIC_DIR,
|
|
286
306
|
uiDevServerUrl: uiResolution.uiDevServerUrl,
|
|
287
307
|
logger,
|
|
@@ -301,7 +321,11 @@ async function main() {
|
|
|
301
321
|
serverMeta,
|
|
302
322
|
instanceStore,
|
|
303
323
|
speechService,
|
|
324
|
+
sidecarManager,
|
|
304
325
|
authManager,
|
|
326
|
+
clientConnectionManager,
|
|
327
|
+
pluginChannel,
|
|
328
|
+
voiceModeManager,
|
|
305
329
|
uiStaticDir: uiResolution.uiStaticDir ?? DEFAULT_UI_STATIC_DIR,
|
|
306
330
|
uiDevServerUrl: undefined,
|
|
307
331
|
logger,
|
|
@@ -328,19 +352,23 @@ async function main() {
|
|
|
328
352
|
// which can lead clients to talk to the wrong process.
|
|
329
353
|
const localUrl = `${localProtocol}://127.0.0.1:${localStart.port}`;
|
|
330
354
|
let remoteUrl;
|
|
355
|
+
let remoteAddresses = [];
|
|
331
356
|
if (remoteStart) {
|
|
332
357
|
const wantsAll = options.host === "0.0.0.0" || !isLoopbackHost(options.host);
|
|
333
358
|
let remoteHost = options.host;
|
|
334
359
|
if (wantsAll) {
|
|
335
360
|
if (options.host === "0.0.0.0") {
|
|
336
|
-
const
|
|
337
|
-
|
|
361
|
+
const resolved = resolveRemoteAddresses({ host: options.host, protocol: remoteProtocol, port: remoteStart.port });
|
|
362
|
+
remoteAddresses = resolved.userVisible;
|
|
363
|
+
remoteUrl = resolved.primaryRemoteUrl ?? `${remoteProtocol}://localhost:${remoteStart.port}`;
|
|
338
364
|
}
|
|
339
365
|
}
|
|
340
366
|
else {
|
|
341
367
|
remoteHost = "localhost";
|
|
342
368
|
}
|
|
343
|
-
remoteUrl
|
|
369
|
+
if (!remoteUrl) {
|
|
370
|
+
remoteUrl = `${remoteProtocol}://${remoteHost}:${remoteStart.port}`;
|
|
371
|
+
}
|
|
344
372
|
}
|
|
345
373
|
serverMeta.localUrl = localUrl;
|
|
346
374
|
serverMeta.localPort = localStart.port;
|
|
@@ -349,7 +377,9 @@ async function main() {
|
|
|
349
377
|
serverMeta.host = options.host;
|
|
350
378
|
serverMeta.listeningMode = options.host === "0.0.0.0" || !isLoopbackHost(options.host) ? "all" : "local";
|
|
351
379
|
if (serverMeta.remotePort && remoteUrl) {
|
|
352
|
-
serverMeta.addresses =
|
|
380
|
+
serverMeta.addresses = remoteAddresses.length
|
|
381
|
+
? remoteAddresses
|
|
382
|
+
: resolveNetworkAddresses({ host: options.host, protocol: remoteProtocol, port: serverMeta.remotePort });
|
|
353
383
|
}
|
|
354
384
|
else {
|
|
355
385
|
serverMeta.addresses = [];
|
|
@@ -357,6 +387,15 @@ async function main() {
|
|
|
357
387
|
console.log(`Local Connection URL : ${serverMeta.localUrl}`);
|
|
358
388
|
if (serverMeta.remoteUrl) {
|
|
359
389
|
console.log(`Remote Connection URL : ${serverMeta.remoteUrl}`);
|
|
390
|
+
const additionalRemoteUrls = serverMeta.addresses
|
|
391
|
+
.map((addr) => addr.remoteUrl)
|
|
392
|
+
.filter((url) => url !== serverMeta.remoteUrl);
|
|
393
|
+
if (additionalRemoteUrls.length > 0) {
|
|
394
|
+
console.log("Other Accessible URLs:");
|
|
395
|
+
for (const url of additionalRemoteUrls) {
|
|
396
|
+
console.log(` - ${url}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
360
399
|
}
|
|
361
400
|
if (options.launch) {
|
|
362
401
|
await launchInBrowser(serverMeta.localUrl, logger.child({ component: "launcher" }));
|
|
@@ -376,6 +415,18 @@ async function main() {
|
|
|
376
415
|
catch (error) {
|
|
377
416
|
logger.warn({ err: error }, "Instance event bridge shutdown failed");
|
|
378
417
|
}
|
|
418
|
+
try {
|
|
419
|
+
await sidecarManager.shutdown();
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
logger.error({ err: error }, "SideCar manager shutdown failed");
|
|
423
|
+
}
|
|
424
|
+
try {
|
|
425
|
+
clientConnectionManager.shutdown();
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
logger.warn({ err: error }, "Client connection manager shutdown failed");
|
|
429
|
+
}
|
|
379
430
|
try {
|
|
380
431
|
await workspaceManager.shutdown();
|
|
381
432
|
logger.info("Workspace manager shutdown complete");
|
|
@@ -13,6 +13,11 @@ type BackgroundProcess = {
|
|
|
13
13
|
outputSizeBytes?: number
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
type BackgroundProcessNotificationRequest = {
|
|
17
|
+
sessionID: string
|
|
18
|
+
directory: string
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
type BackgroundProcessOptions = {
|
|
17
22
|
baseDir: string
|
|
18
23
|
}
|
|
@@ -36,12 +41,19 @@ export function createBackgroundProcessTools(config: CodeNomadConfig, options: B
|
|
|
36
41
|
args: {
|
|
37
42
|
title: tool.schema.string().describe("Short label for the process (e.g. Dev server, DB server)"),
|
|
38
43
|
command: tool.schema.string().describe("Shell command to run in the workspace"),
|
|
44
|
+
notify: tool.schema.boolean().optional().describe("Notify the current session when the process ends"),
|
|
39
45
|
},
|
|
40
|
-
async execute(args) {
|
|
46
|
+
async execute(args, context) {
|
|
41
47
|
assertCommandWithinBase(args.command, options.baseDir)
|
|
48
|
+
const notification: BackgroundProcessNotificationRequest | undefined = args.notify
|
|
49
|
+
? {
|
|
50
|
+
sessionID: context.sessionID,
|
|
51
|
+
directory: context.directory,
|
|
52
|
+
}
|
|
53
|
+
: undefined
|
|
42
54
|
const process = await request<BackgroundProcess>("", {
|
|
43
55
|
method: "POST",
|
|
44
|
-
body: JSON.stringify({ title: args.title, command: args.command }),
|
|
56
|
+
body: JSON.stringify({ title: args.title, command: args.command, notify: args.notify, notification }),
|
|
45
57
|
})
|
|
46
58
|
|
|
47
59
|
return `Started background process ${process.id} (${process.title})\nStatus: ${process.status}\nCommand: ${process.command}`
|
|
@@ -12,7 +12,7 @@ export class VoiceModeManager {
|
|
|
12
12
|
setEnabled(instanceId, connection, enabled) {
|
|
13
13
|
if (enabled && !this.options.connections.isConnected(connection)) {
|
|
14
14
|
this.options.logger.debug({ instanceId, clientId: connection.clientId, connectionId: connection.connectionId }, "Ignoring voice mode enable for disconnected client connection");
|
|
15
|
-
return;
|
|
15
|
+
return false;
|
|
16
16
|
}
|
|
17
17
|
const key = getConnectionKey(connection);
|
|
18
18
|
const current = this.enabledConnectionsByInstance.get(instanceId) ?? new Set();
|
|
@@ -30,6 +30,7 @@ export class VoiceModeManager {
|
|
|
30
30
|
}
|
|
31
31
|
this.options.logger.debug({ instanceId, clientId: connection.clientId, connectionId: connection.connectionId, enabled }, "Voice mode updated for client connection");
|
|
32
32
|
this.publishIfChanged(instanceId);
|
|
33
|
+
return true;
|
|
33
34
|
}
|
|
34
35
|
syncInstance(instanceId) {
|
|
35
36
|
this.options.channel.send(instanceId, buildVoiceModeEvent(this.isEnabled(instanceId)));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import { resolveNetworkAddresses, resolveRemoteAddresses } from "../network-addresses";
|
|
5
|
+
describe("resolveNetworkAddresses", () => {
|
|
6
|
+
it("preserves interface order among external addresses", () => {
|
|
7
|
+
const addresses = [
|
|
8
|
+
{ address: "172.24.0.1", family: "IPv4", internal: false },
|
|
9
|
+
{ address: "192.168.1.128", family: "IPv4", internal: false },
|
|
10
|
+
{ address: "10.0.0.8", family: 4, internal: false },
|
|
11
|
+
{ address: "127.0.0.1", family: "IPv4", internal: true },
|
|
12
|
+
{ address: "169.254.10.20", family: "IPv4", internal: false },
|
|
13
|
+
];
|
|
14
|
+
usingMockedNetworkInterfaces(addresses, () => {
|
|
15
|
+
const result = resolveNetworkAddresses({ host: "0.0.0.0", protocol: "https", port: 9898 });
|
|
16
|
+
assert.deepEqual(result.map((entry) => entry.ip), ["172.24.0.1", "192.168.1.128", "10.0.0.8", "169.254.10.20", "127.0.0.1"]);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe("resolveRemoteAddresses", () => {
|
|
21
|
+
it("keeps all external addresses user-visible while preferring non-link-local addresses for the primary URL", () => {
|
|
22
|
+
const addresses = [
|
|
23
|
+
{ address: "169.254.10.20", family: "IPv4", internal: false },
|
|
24
|
+
{ address: "192.168.1.128", family: "IPv4", internal: false },
|
|
25
|
+
{ address: "172.24.0.1", family: "IPv4", internal: false },
|
|
26
|
+
];
|
|
27
|
+
usingMockedNetworkInterfaces(addresses, () => {
|
|
28
|
+
const result = resolveRemoteAddresses({ host: "0.0.0.0", protocol: "https", port: 9898 });
|
|
29
|
+
assert.deepEqual(result.userVisible.map((entry) => entry.ip), ["192.168.1.128", "172.24.0.1", "169.254.10.20"]);
|
|
30
|
+
assert.equal(result.primaryRemoteUrl, "https://192.168.1.128:9898");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it("prefers private LAN addresses over public addresses", () => {
|
|
34
|
+
const addresses = [
|
|
35
|
+
{ address: "203.0.113.40", family: "IPv4", internal: false },
|
|
36
|
+
{ address: "192.168.1.128", family: "IPv4", internal: false },
|
|
37
|
+
{ address: "8.8.8.8", family: "IPv4", internal: false },
|
|
38
|
+
];
|
|
39
|
+
usingMockedNetworkInterfaces(addresses, () => {
|
|
40
|
+
const result = resolveRemoteAddresses({ host: "0.0.0.0", protocol: "https", port: 9898 });
|
|
41
|
+
assert.deepEqual(result.userVisible.map((entry) => entry.ip), ["192.168.1.128", "203.0.113.40", "8.8.8.8"]);
|
|
42
|
+
assert.equal(result.primaryRemoteUrl, "https://192.168.1.128:9898");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it("uses a public address when no private LAN address is available", () => {
|
|
46
|
+
const addresses = [
|
|
47
|
+
{ address: "169.254.10.20", family: "IPv4", internal: false },
|
|
48
|
+
{ address: "203.0.113.40", family: "IPv4", internal: false },
|
|
49
|
+
];
|
|
50
|
+
usingMockedNetworkInterfaces(addresses, () => {
|
|
51
|
+
const result = resolveRemoteAddresses({ host: "0.0.0.0", protocol: "https", port: 9898 });
|
|
52
|
+
assert.deepEqual(result.userVisible.map((entry) => entry.ip), ["203.0.113.40", "169.254.10.20"]);
|
|
53
|
+
assert.equal(result.primaryRemoteUrl, "https://203.0.113.40:9898");
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
function usingMockedNetworkInterfaces(addresses, callback) {
|
|
58
|
+
const original = os.networkInterfaces;
|
|
59
|
+
os.networkInterfaces = (() => ({
|
|
60
|
+
ethernet0: addresses,
|
|
61
|
+
}));
|
|
62
|
+
try {
|
|
63
|
+
callback();
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
os.networkInterfaces = original;
|
|
67
|
+
}
|
|
68
|
+
}
|