@amd-gaia/agent-ui 0.27.0-rc.9 → 0.27.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/assets/AdvancedSettings-R8_C2uBe.js +1 -0
- package/dist/assets/AutomationsSettings-B3zbjgZt.js +1 -0
- package/dist/assets/ConnectorsPane-BxG6qzLb.css +1 -0
- package/dist/assets/ConnectorsPane-BzcyOZRr.js +1 -0
- package/dist/assets/{DocumentLibrary-fEMoY7lH.css → DocumentLibrary-Ctwq2m2t.css} +1 -1
- package/dist/assets/DocumentLibrary-o3Fy8URO.js +5 -0
- package/dist/assets/FileBrowser-DxS29ShT.css +1 -0
- package/dist/assets/FileBrowser-_6Dx8AKt.js +4 -0
- package/dist/assets/MemoryDashboard-Bfy9g6TS.css +1 -0
- package/dist/assets/MemoryDashboard-ao_en1zm.js +1 -0
- package/dist/assets/MessagingSettings-DJq0F5BO.js +1 -0
- package/dist/assets/{MobileAccessModal-BrZMaERi.css → MobileAccessModal-DSFjH6di.css} +1 -1
- package/dist/assets/MobileAccessModal-ld0MPTgk.js +2 -0
- package/dist/assets/ScheduleManager-CEBoBLPV.css +1 -0
- package/dist/assets/ScheduleManager-px6Ly00O.js +1 -0
- package/dist/assets/folderIndexResult-BIoxqF5I.js +1 -0
- package/dist/assets/index-DXyVxzzC.css +1 -0
- package/dist/assets/index-Qh2EUbOw.js +226 -0
- package/dist/assets/useFocusTrap-Cy_PGcml.js +6 -0
- package/dist/index.html +3 -3
- package/dist/sw.js +1 -1
- package/main-safety-net.cjs +26 -2
- package/main.cjs +188 -58
- package/package.json +2 -2
- package/services/backend-crash-dialog.cjs +19 -5
- package/services/backend-health-monitor.cjs +86 -0
- package/services/backend-installer.cjs +1 -0
- package/services/backend-supervisor.cjs +35 -9
- package/services/browser-pane/dev-servers.cjs +44 -1
- package/services/browser-pane/listen-addresses.cjs +140 -0
- package/services/context-menu.cjs +79 -0
- package/services/link-policy.cjs +78 -7
- package/services/port-manager.cjs +2 -3
- package/services/process-tree.cjs +84 -14
- package/dist/assets/AdvancedSettings-tGqb_qu0.js +0 -1
- package/dist/assets/AutomationsSettings-Do-1Bwo_.js +0 -1
- package/dist/assets/ConnectorsPane-BGI8nBUb.css +0 -1
- package/dist/assets/ConnectorsPane-BtzewzJi.js +0 -1
- package/dist/assets/DocumentLibrary-BFB-H6Eq.js +0 -5
- package/dist/assets/FileBrowser-1goNp4CP.css +0 -1
- package/dist/assets/FileBrowser-CvRrSoCy.js +0 -4
- package/dist/assets/MemoryDashboard-Bkm_5AXr.js +0 -1
- package/dist/assets/MemoryDashboard-RpfLag-v.css +0 -1
- package/dist/assets/MessagingSettings-CDDnmM0a.js +0 -1
- package/dist/assets/MobileAccessModal-CrjuTauE.js +0 -2
- package/dist/assets/ScheduleManager-BZzEH2-W.css +0 -1
- package/dist/assets/ScheduleManager-CXdPfxqH.js +0 -1
- package/dist/assets/index-Co-umRxB.js +0 -225
- package/dist/assets/index-bP0Mo7oA.css +0 -1
- package/dist/assets/useFocusTrap-DgofE0fA.js +0 -6
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
const DEFAULTS = Object.freeze({
|
|
7
|
+
intervalMs: 5000,
|
|
8
|
+
failureThreshold: 3,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
function createBackendHealthMonitor({
|
|
12
|
+
check,
|
|
13
|
+
onUnhealthy,
|
|
14
|
+
intervalMs = DEFAULTS.intervalMs,
|
|
15
|
+
failureThreshold = DEFAULTS.failureThreshold,
|
|
16
|
+
setIntervalFn = setInterval,
|
|
17
|
+
clearIntervalFn = clearInterval,
|
|
18
|
+
}) {
|
|
19
|
+
if (typeof check !== "function") {
|
|
20
|
+
throw new Error("backend health monitor: check must be a function");
|
|
21
|
+
}
|
|
22
|
+
if (typeof onUnhealthy !== "function") {
|
|
23
|
+
throw new Error("backend health monitor: onUnhealthy must be a function");
|
|
24
|
+
}
|
|
25
|
+
if (!Number.isInteger(intervalMs) || intervalMs < 1) {
|
|
26
|
+
throw new Error(`backend health monitor: intervalMs must be a positive integer, got ${intervalMs}`);
|
|
27
|
+
}
|
|
28
|
+
if (!Number.isInteger(failureThreshold) || failureThreshold < 1) {
|
|
29
|
+
throw new Error(`backend health monitor: failureThreshold must be a positive integer, got ${failureThreshold}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let timer = null;
|
|
33
|
+
let generation = 0;
|
|
34
|
+
let failures = 0;
|
|
35
|
+
let checking = false;
|
|
36
|
+
let activeController = null;
|
|
37
|
+
|
|
38
|
+
async function poll(run) {
|
|
39
|
+
if (checking || timer === null || run !== generation) return;
|
|
40
|
+
checking = true;
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
activeController = controller;
|
|
43
|
+
try {
|
|
44
|
+
await check(controller.signal);
|
|
45
|
+
if (run === generation) failures = 0;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (run !== generation) return;
|
|
48
|
+
failures += 1;
|
|
49
|
+
if (failures >= failureThreshold) {
|
|
50
|
+
const consecutiveFailures = failures;
|
|
51
|
+
stop();
|
|
52
|
+
onUnhealthy(error, consecutiveFailures);
|
|
53
|
+
}
|
|
54
|
+
} finally {
|
|
55
|
+
if (activeController === controller) activeController = null;
|
|
56
|
+
checking = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function start() {
|
|
61
|
+
if (timer !== null) return;
|
|
62
|
+
const run = ++generation;
|
|
63
|
+
failures = 0;
|
|
64
|
+
timer = setIntervalFn(() => {
|
|
65
|
+
void poll(run);
|
|
66
|
+
}, intervalMs);
|
|
67
|
+
if (timer && typeof timer.unref === "function") timer.unref();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function stop() {
|
|
71
|
+
generation += 1;
|
|
72
|
+
if (activeController) {
|
|
73
|
+
activeController.abort();
|
|
74
|
+
activeController = null;
|
|
75
|
+
}
|
|
76
|
+
if (timer !== null) {
|
|
77
|
+
clearIntervalFn(timer);
|
|
78
|
+
timer = null;
|
|
79
|
+
}
|
|
80
|
+
failures = 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { start, stop };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = { createBackendHealthMonitor, DEFAULTS };
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Restarts GAIA's backend when it exits
|
|
5
|
+
* Restarts GAIA's backend when it exits or stops answering: after a growing wait,
|
|
6
6
|
* at most `maxRestarts` times in `windowMs`, then it stops and waits for the
|
|
7
|
-
* user's Restart GAIA (restartNow)
|
|
7
|
+
* user's Restart GAIA (restartNow), which also restarts a backend still
|
|
8
|
+
* reported running but hung. No Electron imports, so it unit-tests.
|
|
8
9
|
*
|
|
9
10
|
* State, as sent to the renderer:
|
|
10
11
|
* status "running" | "restarting" | "stopped"
|
|
@@ -26,7 +27,8 @@ const DEFAULTS = Object.freeze({
|
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* @param {object} deps
|
|
29
|
-
* @param {() => Promise<{port: number}>} deps.start spawns the backend and resolves once it answers
|
|
30
|
+
* @param {() => Promise<{port: number}>} deps.start spawns the backend and resolves once it answers;
|
|
31
|
+
* it rejects with an error carrying `terminal: true` when no retry can succeed
|
|
30
32
|
* @param {(state: object) => void} deps.onState called with every new state
|
|
31
33
|
* @param {(state: object) => void} [deps.onStopped] called once each time restarts run out
|
|
32
34
|
*/
|
|
@@ -74,12 +76,18 @@ function createBackendSupervisor({
|
|
|
74
76
|
({ port }) => {
|
|
75
77
|
starting = false;
|
|
76
78
|
if (stopped) return;
|
|
77
|
-
emit({ status: "running", port, since: null, attempt: 0, lastError: null });
|
|
79
|
+
emit({ status: "running", port, since: null, attempt: 0, lastExit: null, lastError: null });
|
|
78
80
|
},
|
|
79
81
|
(err) => {
|
|
80
82
|
starting = false;
|
|
81
83
|
if (stopped) return;
|
|
82
|
-
|
|
84
|
+
const lastError = err && err.message ? err.message : String(err);
|
|
85
|
+
// A retry can't fix it (the program is missing): stop now, with no crash dialog.
|
|
86
|
+
if (err && err.terminal) {
|
|
87
|
+
emit({ status: "stopped", nextAttemptAt: null, lastError });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
schedule({ lastError });
|
|
83
91
|
}
|
|
84
92
|
);
|
|
85
93
|
}
|
|
@@ -105,7 +113,13 @@ function createBackendSupervisor({
|
|
|
105
113
|
return {
|
|
106
114
|
/** The backend is up on `port` (the first start, outside the supervisor). */
|
|
107
115
|
running(port) {
|
|
108
|
-
emit({ status: "running", port, since: null, attempt: 0, nextAttemptAt: null, lastError: null });
|
|
116
|
+
emit({ status: "running", port, since: null, attempt: 0, nextAttemptAt: null, lastExit: null, lastError: null });
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/** No backend could be started at all (its program is missing): wait for Restart GAIA. */
|
|
120
|
+
failedToStart(error) {
|
|
121
|
+
if (stopped) return;
|
|
122
|
+
emit({ status: "stopped", port: null, since: now(), attempt: 0, nextAttemptAt: null, lastError: error });
|
|
109
123
|
},
|
|
110
124
|
|
|
111
125
|
/** The backend exited on its own. Returns what happens next. */
|
|
@@ -121,7 +135,17 @@ function createBackendSupervisor({
|
|
|
121
135
|
return schedule({ lastExit: { code, signal } });
|
|
122
136
|
},
|
|
123
137
|
|
|
124
|
-
/**
|
|
138
|
+
/** A running backend stopped answering, though its child process may remain alive. */
|
|
139
|
+
healthFailed(error) {
|
|
140
|
+
if (stopped) return "stopped";
|
|
141
|
+
if (starting || timer || state.status !== "running") return state.status;
|
|
142
|
+
const lastError = error && error.message ? error.message : String(error);
|
|
143
|
+
return schedule({ lastError });
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/** The user's Restart GAIA: start now, with a fresh budget. Also restarts
|
|
147
|
+
* a backend still reported "running": that is a hung backend the startup
|
|
148
|
+
* screen offers Restart for, and start() stops the old process first. */
|
|
125
149
|
restartNow() {
|
|
126
150
|
if (stopped || starting) return;
|
|
127
151
|
if (timer) {
|
|
@@ -129,8 +153,10 @@ function createBackendSupervisor({
|
|
|
129
153
|
timer = null;
|
|
130
154
|
}
|
|
131
155
|
history = [];
|
|
132
|
-
|
|
133
|
-
|
|
156
|
+
// A restart from running starts a new outage: stamp it so the banner's
|
|
157
|
+
// timer counts from here, as the crash path does. From stopped, the
|
|
158
|
+
// outage began when the backend gave up, so keep that time.
|
|
159
|
+
emit({ status: "restarting", attempt: 1, ...(state.status === "running" ? { since: now() } : {}) });
|
|
134
160
|
attemptStart();
|
|
135
161
|
},
|
|
136
162
|
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
* A ledger file records each server's pids and command lines, so the next
|
|
15
15
|
* launch can stop servers a crash left behind. It only ever signals a pid it
|
|
16
16
|
* recorded whose command line still matches.
|
|
17
|
+
*
|
|
18
|
+
* A server must listen only on loopback. Once its port answers, the
|
|
19
|
+
* addresses it is bound to are read from the OS; one bound to every interface
|
|
20
|
+
* or to a network address is stopped with an error saying how to bind it.
|
|
17
21
|
*/
|
|
18
22
|
|
|
19
23
|
"use strict";
|
|
@@ -24,6 +28,7 @@ const net = require("net");
|
|
|
24
28
|
const path = require("path");
|
|
25
29
|
const { BridgeError } = require("./bridge-error.cjs");
|
|
26
30
|
const { descendantsFromTable, killProcessTree, listProcesses } = require("../process-tree.cjs");
|
|
31
|
+
const { isLoopback, listeningAddresses } = require("./listen-addresses.cjs");
|
|
27
32
|
|
|
28
33
|
/** @typedef {import("./contract").DevServerSpec} DevServerSpec */
|
|
29
34
|
/** @typedef {import("./contract").DevServerState} DevServerState */
|
|
@@ -49,6 +54,10 @@ const LINE_CHARS = 500;
|
|
|
49
54
|
const PROBE_EVERY_MS = 100;
|
|
50
55
|
const PROBE_TIMEOUT_MS = 400;
|
|
51
56
|
const REAP_GRACE_MS = 3000;
|
|
57
|
+
const LOOPBACK_HINT =
|
|
58
|
+
'Start it bound to 127.0.0.1: in launch.json\'s runtimeArgs add "--bind 127.0.0.1" for python -m http.server, ' +
|
|
59
|
+
'"--host 127.0.0.1" for Vite or webpack serve, "--hostname 127.0.0.1" for Next.js, "-a 127.0.0.1" for http-server, ' +
|
|
60
|
+
'or "--listen tcp://127.0.0.1:<port>" for serve; for an npm script, put the flag in package.json\'s script.';
|
|
52
61
|
const ERROR_LINE = /\berror\b|\bfailed\b|\bexception\b|\bfatal\b|\bpanic\b|ERR!/i;
|
|
53
62
|
|
|
54
63
|
function envNameAllowed(name) {
|
|
@@ -56,6 +65,7 @@ function envNameAllowed(name) {
|
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
/**
|
|
68
|
+
* HOST=127.0.0.1 is the loopback bind for dev servers that read it; launch.json may set another loopback HOST.
|
|
59
69
|
* @param {DevServerSpec} spec @param {NodeJS.ProcessEnv} from
|
|
60
70
|
* @param {string | null} searchPath The backend's login-shell PATH; an app opened from the Dock has only launchd's.
|
|
61
71
|
*/
|
|
@@ -63,7 +73,7 @@ function childEnv(spec, from, searchPath = null) {
|
|
|
63
73
|
const env = {};
|
|
64
74
|
for (const name of INHERITED_ENV) if (from[name] !== undefined) env[name] = from[name];
|
|
65
75
|
if (searchPath) env.PATH = searchPath;
|
|
66
|
-
return { ...env, ...spec.env };
|
|
76
|
+
return { ...env, HOST: "127.0.0.1", ...spec.env };
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
/** True when something accepts a TCP connection on the port, over IPv4 or IPv6 loopback. */
|
|
@@ -148,6 +158,7 @@ class DevServerSupervisor {
|
|
|
148
158
|
* spawn?: typeof childProcess.spawn,
|
|
149
159
|
* listProcesses?: typeof listProcesses,
|
|
150
160
|
* killTree?: typeof killProcessTree,
|
|
161
|
+
* listeningAddresses?: typeof listeningAddresses,
|
|
151
162
|
* reapGraceMs?: number,
|
|
152
163
|
* logger?: { log: Function, error: Function },
|
|
153
164
|
* }} deps
|
|
@@ -158,6 +169,7 @@ class DevServerSupervisor {
|
|
|
158
169
|
spawn: childProcess.spawn,
|
|
159
170
|
listProcesses,
|
|
160
171
|
killTree: killProcessTree,
|
|
172
|
+
listeningAddresses,
|
|
161
173
|
reapGraceMs: REAP_GRACE_MS,
|
|
162
174
|
logger: console,
|
|
163
175
|
...deps,
|
|
@@ -427,10 +439,41 @@ class DevServerSupervisor {
|
|
|
427
439
|
}
|
|
428
440
|
await new Promise((r) => setTimeout(r, PROBE_EVERY_MS));
|
|
429
441
|
}
|
|
442
|
+
await this.requireLoopbackOnly(entry);
|
|
430
443
|
entry.status = "ready";
|
|
431
444
|
this.deps.onChange();
|
|
432
445
|
}
|
|
433
446
|
|
|
447
|
+
/** Stop a server anything off this computer could reach, or whose binding can't be read. */
|
|
448
|
+
async requireLoopbackOnly(entry) {
|
|
449
|
+
let addresses;
|
|
450
|
+
try {
|
|
451
|
+
addresses = await this.deps.listeningAddresses(entry.spec.port);
|
|
452
|
+
} catch (err) {
|
|
453
|
+
await this.halt(entry);
|
|
454
|
+
throw this.notLoopback(entry, `answered, but GAIA could not read which network addresses it listens on (${err.message}), so it stopped it rather than risk exposing it.`, []);
|
|
455
|
+
}
|
|
456
|
+
const open = addresses.filter((a) => !isLoopback(a));
|
|
457
|
+
if (addresses.length > 0 && open.length === 0) return;
|
|
458
|
+
await this.halt(entry);
|
|
459
|
+
if (addresses.length === 0) {
|
|
460
|
+
throw this.notLoopback(entry, "answered, but GAIA could not see which address it listens on, so it stopped it rather than risk exposing it.", []);
|
|
461
|
+
}
|
|
462
|
+
const everywhere = open.some((a) => a === "*" || a === "0.0.0.0" || a === "::");
|
|
463
|
+
const where = everywhere ? "all network interfaces" : `the network address ${open.join(", ")}`;
|
|
464
|
+
throw this.notLoopback(entry, `listened on ${where}, so other computers on the network could reach it; GAIA stopped it.`, open);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
notLoopback(entry, what, addresses) {
|
|
468
|
+
const { spec } = entry;
|
|
469
|
+
this.deps.logger.error(`[dev-servers] Stopped "${spec.name}" on port ${spec.port}: not bound to loopback only (${addresses.join(", ") || "binding unknown"}).`);
|
|
470
|
+
return new BridgeError("dev_server_failed", `Dev server "${spec.name}" (${spec.argv.join(" ")}) on port ${spec.port} ${what} ${LOOPBACK_HINT}`, {
|
|
471
|
+
exitCode: null,
|
|
472
|
+
lines: [],
|
|
473
|
+
addresses,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
|
|
434
477
|
failed(entry, what) {
|
|
435
478
|
const { spec } = entry;
|
|
436
479
|
const lines = readLines(entry.logFile).slice(-FAIL_LINES);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The local addresses TCP listeners on one port are bound to, read from the
|
|
6
|
+
* OS: `lsof` on macOS and other Unixes, /proc/net/tcp{,6} on Linux, and
|
|
7
|
+
* `netstat -ano` on Windows. A dev server GAIA starts must listen only on
|
|
8
|
+
* loopback, so nothing else on the network can reach the folder it serves.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
const childProcess = require("child_process");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const os = require("os");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
|
|
18
|
+
const LIST_TIMEOUT_MS = 10000;
|
|
19
|
+
const PROC_LISTEN_STATE = "0A";
|
|
20
|
+
|
|
21
|
+
/** True for 127.0.0.0/8 and ::1 (also as an IPv4-mapped address). "*", 0.0.0.0 and :: are every interface. */
|
|
22
|
+
function isLoopback(address) {
|
|
23
|
+
const a = String(address).replace(/^\[|\]$/g, "").replace(/%.*$/, "").toLowerCase();
|
|
24
|
+
if (/^127\.\d+\.\d+\.\d+$/.test(a)) return true;
|
|
25
|
+
if (/^::ffff:127\.\d+\.\d+\.\d+$/.test(a)) return true;
|
|
26
|
+
return a === "::1" || a === "0:0:0:0:0:0:0:1";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** "1.2.3.4:80" or "[::1]:80" -> { address, port }; null when there is no port. */
|
|
30
|
+
function splitHostPort(text) {
|
|
31
|
+
const cut = text.lastIndexOf(":");
|
|
32
|
+
if (cut <= 0) return null;
|
|
33
|
+
const port = Number(text.slice(cut + 1));
|
|
34
|
+
if (!Number.isInteger(port)) return null;
|
|
35
|
+
return { address: text.slice(0, cut).replace(/^\[|\]$/g, ""), port };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** `lsof -nP -iTCP:<port> -sTCP:LISTEN -Fn` output: one "n<addr>:<port>" line per socket. */
|
|
39
|
+
function parseLsof(stdout, port) {
|
|
40
|
+
const found = [];
|
|
41
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
42
|
+
if (!line.startsWith("n")) continue;
|
|
43
|
+
const hp = splitHostPort(line.slice(1));
|
|
44
|
+
if (hp && hp.port === port) found.push(hp.address);
|
|
45
|
+
}
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A /proc/net/tcp address: 32-bit words in host byte order, hex. */
|
|
50
|
+
function decodeProcAddress(hex, endianness = os.endianness()) {
|
|
51
|
+
const bytes = [];
|
|
52
|
+
for (let w = 0; w < hex.length; w += 8) {
|
|
53
|
+
const word = hex.slice(w, w + 8).match(/../g).map((b) => parseInt(b, 16));
|
|
54
|
+
bytes.push(...(endianness === "LE" ? word.reverse() : word));
|
|
55
|
+
}
|
|
56
|
+
if (bytes.length === 4) return bytes.join(".");
|
|
57
|
+
if (bytes.every((b) => b === 0)) return "::";
|
|
58
|
+
if (bytes.slice(0, 15).every((b) => b === 0) && bytes[15] === 1) return "::1";
|
|
59
|
+
if (bytes.slice(0, 10).every((b) => b === 0) && bytes[10] === 0xff && bytes[11] === 0xff) {
|
|
60
|
+
return `::ffff:${bytes.slice(12).join(".")}`;
|
|
61
|
+
}
|
|
62
|
+
const groups = [];
|
|
63
|
+
for (let i = 0; i < 16; i += 2) groups.push(((bytes[i] << 8) | bytes[i + 1]).toString(16));
|
|
64
|
+
return groups.join(":");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The listening sockets on `port` in one /proc/net/tcp or tcp6 table. */
|
|
68
|
+
function parseProcNetTcp(text, port, endianness = os.endianness()) {
|
|
69
|
+
const found = [];
|
|
70
|
+
for (const line of text.split(/\r?\n/).slice(1)) {
|
|
71
|
+
const cols = line.trim().split(/\s+/);
|
|
72
|
+
if (cols.length < 4 || cols[3] !== PROC_LISTEN_STATE) continue;
|
|
73
|
+
const [addrHex, portHex] = cols[1].split(":");
|
|
74
|
+
if (parseInt(portHex, 16) !== port) continue;
|
|
75
|
+
found.push(decodeProcAddress(addrHex, endianness));
|
|
76
|
+
}
|
|
77
|
+
return found;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* `netstat -ano` output. The state column is translated on non-English
|
|
82
|
+
* Windows, so a listener is told by its foreign address, which is always
|
|
83
|
+
* 0.0.0.0:0 or [::]:0 for one and never for a connection.
|
|
84
|
+
*/
|
|
85
|
+
function parseNetstat(stdout, port) {
|
|
86
|
+
const found = [];
|
|
87
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
88
|
+
const cols = line.trim().split(/\s+/);
|
|
89
|
+
if (cols.length < 4 || cols[0].toUpperCase() !== "TCP") continue;
|
|
90
|
+
if (cols[2] !== "0.0.0.0:0" && cols[2] !== "[::]:0") continue;
|
|
91
|
+
const hp = splitHostPort(cols[1]);
|
|
92
|
+
if (hp && hp.port === port) found.push(hp.address);
|
|
93
|
+
}
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function run(execFile, file, args) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
execFile(file, args, { timeout: LIST_TIMEOUT_MS, windowsHide: true, maxBuffer: 16 * 1024 * 1024 }, (err, stdout) => {
|
|
100
|
+
if (err) reject(Object.assign(err, { stdout: String(stdout || "") }));
|
|
101
|
+
else resolve(String(stdout));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Every local address something listens on at `port`. Rejects when the OS
|
|
108
|
+
* can't be asked, never answers "none" for a list it could not read.
|
|
109
|
+
* @param {number} port
|
|
110
|
+
* @returns {Promise<string[]>}
|
|
111
|
+
*/
|
|
112
|
+
async function listeningAddresses(
|
|
113
|
+
port,
|
|
114
|
+
{ platform = process.platform, execFile = childProcess.execFile, readFile = fs.promises.readFile, env = process.env } = {}
|
|
115
|
+
) {
|
|
116
|
+
if (platform === "linux") {
|
|
117
|
+
const v4 = await readFile("/proc/net/tcp", "utf8");
|
|
118
|
+
let v6 = "";
|
|
119
|
+
try {
|
|
120
|
+
v6 = await readFile("/proc/net/tcp6", "utf8");
|
|
121
|
+
} catch (err) {
|
|
122
|
+
if (err.code !== "ENOENT") throw err;
|
|
123
|
+
}
|
|
124
|
+
return [...parseProcNetTcp(v4, port), ...parseProcNetTcp(v6, port)];
|
|
125
|
+
}
|
|
126
|
+
if (platform === "win32") {
|
|
127
|
+
const root = env.SystemRoot || env.SYSTEMROOT || "C:\\Windows";
|
|
128
|
+
return parseNetstat(await run(execFile, path.win32.join(root, "System32", "netstat.exe"), ["-ano"]), port);
|
|
129
|
+
}
|
|
130
|
+
const lsof = platform === "darwin" ? "/usr/sbin/lsof" : "lsof";
|
|
131
|
+
try {
|
|
132
|
+
return parseLsof(await run(execFile, lsof, ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-Fn"]), port);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
// lsof exits 1 with no output when nothing matches.
|
|
135
|
+
if (err.code === 1 && !err.stdout.trim()) return [];
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = { decodeProcAddress, isLoopback, listeningAddresses, parseLsof, parseNetstat, parseProcNetTcp };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Right-click menu for the app window. Electron shows none by default, and on
|
|
6
|
+
* Windows and Linux the window has no Edit menu either. Role items take their
|
|
7
|
+
* labels from the OS, so the rest follow the OS language too.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const MAX_SUGGESTIONS = 5;
|
|
11
|
+
|
|
12
|
+
const LABELS = {
|
|
13
|
+
en: { addToDictionary: "Add to dictionary", copyLink: "Copy link address", copyImage: "Copy image" },
|
|
14
|
+
ar: { addToDictionary: "إضافة إلى القاموس", copyLink: "نسخ عنوان الرابط", copyImage: "نسخ الصورة" },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** The custom items' labels for an OS locale such as "ar-EG"; English for any language without them. */
|
|
18
|
+
function menuLabels(locale) {
|
|
19
|
+
const lang = String(locale || "").toLowerCase().split(/[-_]/)[0];
|
|
20
|
+
return LABELS[lang] || LABELS.en;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The menu template for one right-click, or [] when there is nothing to offer.
|
|
25
|
+
* `params` is Electron's context-menu ContextMenuParams.
|
|
26
|
+
*/
|
|
27
|
+
function buildContextMenuTemplate(params, actions, labels = LABELS.en) {
|
|
28
|
+
const sections = [];
|
|
29
|
+
|
|
30
|
+
if (params.isEditable) {
|
|
31
|
+
if (params.misspelledWord) {
|
|
32
|
+
const spelling = params.dictionarySuggestions
|
|
33
|
+
.slice(0, MAX_SUGGESTIONS)
|
|
34
|
+
.map((word) => ({ label: word, click: () => actions.replaceMisspelling(word) }));
|
|
35
|
+
spelling.push({
|
|
36
|
+
label: labels.addToDictionary,
|
|
37
|
+
click: () => actions.addToDictionary(params.misspelledWord),
|
|
38
|
+
});
|
|
39
|
+
sections.push(spelling);
|
|
40
|
+
}
|
|
41
|
+
const flags = params.editFlags;
|
|
42
|
+
sections.push([
|
|
43
|
+
{ role: "cut", enabled: flags.canCut },
|
|
44
|
+
{ role: "copy", enabled: flags.canCopy },
|
|
45
|
+
{ role: "paste", enabled: flags.canPaste },
|
|
46
|
+
{ type: "separator" },
|
|
47
|
+
{ role: "selectAll", enabled: flags.canSelectAll },
|
|
48
|
+
]);
|
|
49
|
+
} else if (params.selectionText && params.selectionText.trim()) {
|
|
50
|
+
sections.push([{ role: "copy" }]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (params.linkURL) {
|
|
54
|
+
sections.push([{ label: labels.copyLink, click: () => actions.copyLink(params.linkURL) }]);
|
|
55
|
+
}
|
|
56
|
+
if (params.mediaType === "image" && params.hasImageContents) {
|
|
57
|
+
sections.push([{ label: labels.copyImage, click: () => actions.copyImageAt(params.x, params.y) }]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return sections.flatMap((items, i) => (i === 0 ? items : [{ type: "separator" }, ...items]));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Show the menu on right-click in `window`'s own webContents. `locale` is the OS's, as `app.getLocale()` gives it. */
|
|
64
|
+
function installContextMenu(window, { Menu, clipboard, locale }) {
|
|
65
|
+
const wc = window.webContents;
|
|
66
|
+
const labels = menuLabels(locale);
|
|
67
|
+
wc.on("context-menu", (_event, params) => {
|
|
68
|
+
const template = buildContextMenuTemplate(params, {
|
|
69
|
+
replaceMisspelling: (word) => wc.replaceMisspelling(word),
|
|
70
|
+
addToDictionary: (word) => wc.session.addWordToSpellCheckerDictionary(word),
|
|
71
|
+
copyLink: (url) => clipboard.writeText(url),
|
|
72
|
+
copyImageAt: (x, y) => wc.copyImageAt(x, y),
|
|
73
|
+
}, labels);
|
|
74
|
+
if (template.length === 0) return;
|
|
75
|
+
Menu.buildFromTemplate(template).popup({ window });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { buildContextMenuTemplate, installContextMenu, menuLabels, MAX_SUGGESTIONS };
|
package/services/link-policy.cjs
CHANGED
|
@@ -60,26 +60,94 @@ function isInAppNavigation(targetUrl, currentUrl) {
|
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
// U+2068/U+2069 keep a URL left-to-right inside Arabic text.
|
|
64
|
+
const isolate = (text) => `${text}`;
|
|
65
|
+
|
|
66
|
+
const NOTICE_TEXT = {
|
|
67
|
+
en: {
|
|
68
|
+
blockedTitle: "Link blocked",
|
|
69
|
+
notOpenedTitle: "Link not opened",
|
|
70
|
+
ok: "OK",
|
|
71
|
+
noScheme: "no scheme",
|
|
72
|
+
blocked: (url, scheme) =>
|
|
73
|
+
`GAIA refused to open "${url}" (${scheme}). ` +
|
|
74
|
+
"Only http, https and mailto links open outside the app — a link that " +
|
|
75
|
+
"resolves to a local file or network share is never launched.",
|
|
76
|
+
openFailed: (url, reason) =>
|
|
77
|
+
`GAIA couldn't open "${url}": ${reason}. ` +
|
|
78
|
+
"Check that this PC has an app set up for that kind of link.",
|
|
79
|
+
},
|
|
80
|
+
ar: {
|
|
81
|
+
blockedTitle: "تم حظر الرابط",
|
|
82
|
+
notOpenedTitle: "لم يُفتح الرابط",
|
|
83
|
+
ok: "حسنًا",
|
|
84
|
+
noScheme: "بلا بروتوكول",
|
|
85
|
+
blocked: (url, scheme) =>
|
|
86
|
+
`رفض GAIA فتح "${isolate(url)}" (${isolate(scheme)}). ` +
|
|
87
|
+
"لا تُفتح خارج التطبيق إلا روابط http وhttps وmailto، ولا يُشغَّل أبدًا " +
|
|
88
|
+
"رابط يشير إلى ملف محلي أو مجلد مشترك على الشبكة.",
|
|
89
|
+
openFailed: (url, reason) =>
|
|
90
|
+
`تعذّر على GAIA فتح "${isolate(url)}": ${isolate(reason)}. ` +
|
|
91
|
+
"تأكد من وجود تطبيق على هذا الجهاز مُعدّ لفتح هذا النوع من الروابط.",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** The link-notice strings for an OS locale such as "ar-EG"; English for any language without them. */
|
|
96
|
+
function linkNoticeText(locale) {
|
|
97
|
+
const lang = String(locale || "").toLowerCase().split(/[-_]/)[0];
|
|
98
|
+
return NOTICE_TEXT[lang] || NOTICE_TEXT.en;
|
|
99
|
+
}
|
|
100
|
+
|
|
63
101
|
/**
|
|
64
102
|
* A one-line, user-facing reason a URL was refused. Never silently dropped —
|
|
65
103
|
* the caller logs this and shows it, so a blocked click is explainable.
|
|
66
104
|
*
|
|
67
105
|
* @param {string} rawUrl
|
|
106
|
+
* @param {string} [locale] The OS locale, as `app.getLocale()` gives it.
|
|
68
107
|
* @returns {string}
|
|
69
108
|
*/
|
|
70
|
-
function describeBlockedUrl(rawUrl) {
|
|
109
|
+
function describeBlockedUrl(rawUrl, locale) {
|
|
110
|
+
const text = linkNoticeText(locale);
|
|
71
111
|
const shown = typeof rawUrl === "string" && rawUrl ? rawUrl : String(rawUrl);
|
|
72
|
-
let scheme =
|
|
112
|
+
let scheme = text.noScheme;
|
|
73
113
|
try {
|
|
74
114
|
scheme = new URL(shown).protocol.replace(/:$/, "");
|
|
75
115
|
} catch {
|
|
76
|
-
/* keep "no scheme" */
|
|
116
|
+
/* keep the "no scheme" label */
|
|
77
117
|
}
|
|
78
|
-
return (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
118
|
+
return text.blocked(shown.slice(0, 300), scheme);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A one-line, user-facing reason the OS could not open an allowed link.
|
|
123
|
+
*
|
|
124
|
+
* @param {string} rawUrl
|
|
125
|
+
* @param {unknown} err
|
|
126
|
+
* @param {string} [locale] The OS locale, as `app.getLocale()` gives it.
|
|
127
|
+
* @returns {string}
|
|
128
|
+
*/
|
|
129
|
+
function describeOpenFailure(rawUrl, err, locale) {
|
|
130
|
+
const reason = (err && err.message ? err.message : String(err)).replace(
|
|
131
|
+
/\.+$/,
|
|
132
|
+
"",
|
|
82
133
|
);
|
|
134
|
+
return linkNoticeText(locale).openFailed(String(rawUrl).slice(0, 300), reason);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* `shell.openExternal` rejects when the OS has no handler (a mailto: link on a
|
|
139
|
+
* PC with no mail app). Unhandled, that rejection reaches the process-level
|
|
140
|
+
* fatal handler and quits the app, so every caller goes through here.
|
|
141
|
+
*
|
|
142
|
+
* @param {{ openExternal: (url: string) => Promise<void> }} shell
|
|
143
|
+
* @param {string} url
|
|
144
|
+
* @param {(err: unknown) => void} onFailure
|
|
145
|
+
* @returns {Promise<void>}
|
|
146
|
+
*/
|
|
147
|
+
function openExternalSafely(shell, url, onFailure) {
|
|
148
|
+
return Promise.resolve()
|
|
149
|
+
.then(() => shell.openExternal(url))
|
|
150
|
+
.catch(onFailure);
|
|
83
151
|
}
|
|
84
152
|
|
|
85
153
|
module.exports = {
|
|
@@ -87,4 +155,7 @@ module.exports = {
|
|
|
87
155
|
isAllowedExternalUrl,
|
|
88
156
|
isInAppNavigation,
|
|
89
157
|
describeBlockedUrl,
|
|
158
|
+
describeOpenFailure,
|
|
159
|
+
openExternalSafely,
|
|
160
|
+
linkNoticeText,
|
|
90
161
|
};
|
|
@@ -68,13 +68,12 @@ function findFreePort() {
|
|
|
68
68
|
async function killBackend(procOrPid, logger) {
|
|
69
69
|
const log = (logger && logger.log) || console.log;
|
|
70
70
|
const logError = (logger && logger.error) || console.error;
|
|
71
|
-
if (!procOrPid) return;
|
|
71
|
+
if (!procOrPid) return { killed: [], survivors: [], verified: true };
|
|
72
72
|
const proc = typeof procOrPid === "object" ? procOrPid : null;
|
|
73
73
|
if (proc && (proc.exitCode !== null || proc.signalCode !== null)) {
|
|
74
74
|
log(`[port-manager] child pid ${proc.pid} already exited (exitCode=${proc.exitCode} signal=${proc.signalCode})`);
|
|
75
|
-
return;
|
|
76
75
|
}
|
|
77
|
-
|
|
76
|
+
return killProcessTree(procOrPid, {
|
|
78
77
|
graceMs: BACKEND_KILL_GRACE_MS,
|
|
79
78
|
forceWaitMs: BACKEND_FORCE_WAIT_MS,
|
|
80
79
|
log,
|