@staff0rd/assist 0.567.1 → 0.568.1
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/commands/sessions/web/bundle.js +324 -324
- package/dist/index.js +93 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.568.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -35264,14 +35264,24 @@ import { spawn as spawn11 } from "child_process";
|
|
|
35264
35264
|
|
|
35265
35265
|
// src/commands/sessions/daemon/logChildStream.ts
|
|
35266
35266
|
import { createInterface as createInterface8 } from "readline";
|
|
35267
|
-
function logChildStream(stream, label2) {
|
|
35267
|
+
function logChildStream(stream, label2, onLine) {
|
|
35268
35268
|
if (!stream) return;
|
|
35269
35269
|
const lines2 = createInterface8({ input: stream });
|
|
35270
|
-
lines2.on("line", (line) =>
|
|
35270
|
+
lines2.on("line", (line) => {
|
|
35271
|
+
daemonLog(`[${label2}] ${line}`);
|
|
35272
|
+
onLine?.(line);
|
|
35273
|
+
});
|
|
35271
35274
|
lines2.on("error", () => {
|
|
35272
35275
|
});
|
|
35273
35276
|
}
|
|
35274
35277
|
|
|
35278
|
+
// src/commands/sessions/daemon/windowsBridgeFailureCause.ts
|
|
35279
|
+
var WINDOWS_BRIDGE_FAILURE_PREFIX = "windows bridge unavailable:";
|
|
35280
|
+
function windowsBridgeFailureCause(line) {
|
|
35281
|
+
const index3 = line.indexOf(WINDOWS_BRIDGE_FAILURE_PREFIX);
|
|
35282
|
+
return index3 === -1 ? null : line.slice(index3).trim();
|
|
35283
|
+
}
|
|
35284
|
+
|
|
35275
35285
|
// src/commands/sessions/daemon/ensureWindowsDaemonRunning.ts
|
|
35276
35286
|
var SPAWN_TIMEOUT_MS2 = 3e4;
|
|
35277
35287
|
var RETRY_DELAY_MS3 = 300;
|
|
@@ -35281,27 +35291,31 @@ async function ensureWindowsDaemonRunning() {
|
|
|
35281
35291
|
return;
|
|
35282
35292
|
}
|
|
35283
35293
|
daemonLog("windows daemon: not running, launching via pwsh.exe");
|
|
35284
|
-
launchWindowsDaemon();
|
|
35285
|
-
await waitForWindowsDaemon();
|
|
35294
|
+
await waitForWindowsDaemon(launchWindowsDaemon());
|
|
35286
35295
|
}
|
|
35287
35296
|
function launchWindowsDaemon() {
|
|
35288
35297
|
const child = spawn11("pwsh.exe", ["-Command", "assist daemon run"], {
|
|
35289
35298
|
detached: true,
|
|
35290
35299
|
stdio: ["ignore", "pipe", "pipe"]
|
|
35291
35300
|
});
|
|
35292
|
-
|
|
35293
|
-
|
|
35294
|
-
|
|
35295
|
-
|
|
35296
|
-
|
|
35297
|
-
);
|
|
35301
|
+
let cause = null;
|
|
35302
|
+
const watchForFailure = (line) => {
|
|
35303
|
+
cause ??= windowsBridgeFailureCause(line);
|
|
35304
|
+
};
|
|
35305
|
+
logChildStream(child.stdout, "windows daemon run", watchForFailure);
|
|
35306
|
+
logChildStream(child.stderr, "windows daemon run", watchForFailure);
|
|
35307
|
+
child.on("error", (e) => {
|
|
35308
|
+
daemonLog(`failed to launch windows daemon: ${e.message}`);
|
|
35309
|
+
cause ??= `could not launch pwsh.exe: ${e.message}`;
|
|
35310
|
+
});
|
|
35298
35311
|
child.on("exit", (code) => {
|
|
35299
35312
|
if (code !== 0)
|
|
35300
35313
|
daemonLog(`windows daemon launch exited early with code ${code}`);
|
|
35301
35314
|
});
|
|
35302
35315
|
child.unref();
|
|
35316
|
+
return { failureCause: () => cause };
|
|
35303
35317
|
}
|
|
35304
|
-
async function waitForWindowsDaemon() {
|
|
35318
|
+
async function waitForWindowsDaemon(launch) {
|
|
35305
35319
|
const start3 = Date.now();
|
|
35306
35320
|
const deadline = start3 + SPAWN_TIMEOUT_MS2;
|
|
35307
35321
|
let attempts = 0;
|
|
@@ -35314,6 +35328,13 @@ async function waitForWindowsDaemon() {
|
|
|
35314
35328
|
);
|
|
35315
35329
|
return;
|
|
35316
35330
|
}
|
|
35331
|
+
const cause = launch.failureCause();
|
|
35332
|
+
if (cause) {
|
|
35333
|
+
daemonLog(
|
|
35334
|
+
`windows daemon: launch failed after ${attempts} attempts: ${cause}`
|
|
35335
|
+
);
|
|
35336
|
+
throw new Error(`Windows daemon failed to start: ${cause}`);
|
|
35337
|
+
}
|
|
35317
35338
|
}
|
|
35318
35339
|
daemonLog(
|
|
35319
35340
|
`windows daemon: did NOT start within ${SPAWN_TIMEOUT_MS2}ms (${attempts} attempts)`
|
|
@@ -36327,7 +36348,7 @@ var SessionManager = class {
|
|
|
36327
36348
|
|
|
36328
36349
|
// src/commands/sessions/daemon/startDaemonServer.ts
|
|
36329
36350
|
import { unlinkSync as unlinkSync24 } from "fs";
|
|
36330
|
-
import * as
|
|
36351
|
+
import * as net4 from "net";
|
|
36331
36352
|
|
|
36332
36353
|
// src/commands/sessions/daemon/handleConnection.ts
|
|
36333
36354
|
import { createInterface as createInterface10 } from "readline";
|
|
@@ -36770,12 +36791,67 @@ function cleanupOwnedFiles() {
|
|
|
36770
36791
|
}
|
|
36771
36792
|
}
|
|
36772
36793
|
|
|
36794
|
+
// src/commands/sessions/daemon/startWindowsBridge.ts
|
|
36795
|
+
import * as net3 from "net";
|
|
36796
|
+
var BIND_ATTEMPTS = 3;
|
|
36797
|
+
var BIND_RETRY_DELAY_MS = 250;
|
|
36798
|
+
var KEEPALIVE_PROBE_MS2 = 1e4;
|
|
36799
|
+
async function startWindowsBridge(manager) {
|
|
36800
|
+
const port = windowsDaemonPort();
|
|
36801
|
+
for (let attempt = 1; attempt <= BIND_ATTEMPTS; attempt++) {
|
|
36802
|
+
const error = await bindBridge(manager, port);
|
|
36803
|
+
if (!error) {
|
|
36804
|
+
daemonLog(`windows bridge listening on :${port}`);
|
|
36805
|
+
return true;
|
|
36806
|
+
}
|
|
36807
|
+
daemonLog(
|
|
36808
|
+
`windows bridge bind attempt ${attempt}/${BIND_ATTEMPTS} on :${port} failed: ${error.message}`
|
|
36809
|
+
);
|
|
36810
|
+
if (attempt < BIND_ATTEMPTS) await delay3(BIND_RETRY_DELAY_MS);
|
|
36811
|
+
}
|
|
36812
|
+
daemonLog(
|
|
36813
|
+
`${WINDOWS_BRIDGE_FAILURE_PREFIX} could not bind port ${port} after ${BIND_ATTEMPTS} attempts; the port is held by another process or reserved by a Hyper-V/WSL dynamic port range \u2014 set sessions.windowsDaemonPort to a free port outside 49152-65535`
|
|
36814
|
+
);
|
|
36815
|
+
return false;
|
|
36816
|
+
}
|
|
36817
|
+
function bindBridge(manager, port) {
|
|
36818
|
+
return new Promise((resolve24) => {
|
|
36819
|
+
const bridge = net3.createServer((socket) => {
|
|
36820
|
+
socket.setKeepAlive(true, KEEPALIVE_PROBE_MS2);
|
|
36821
|
+
handleConnection(socket, manager);
|
|
36822
|
+
});
|
|
36823
|
+
bridge.once("error", (error) => {
|
|
36824
|
+
bridge.close(() => {
|
|
36825
|
+
});
|
|
36826
|
+
resolve24(error);
|
|
36827
|
+
});
|
|
36828
|
+
bridge.listen(port, () => {
|
|
36829
|
+
bridge.removeAllListeners("error");
|
|
36830
|
+
bridge.on("error", (error) => {
|
|
36831
|
+
daemonLog(
|
|
36832
|
+
`${WINDOWS_BRIDGE_FAILURE_PREFIX} ${error.message} after listening; exiting so the next launch can take over`
|
|
36833
|
+
);
|
|
36834
|
+
process.exit(1);
|
|
36835
|
+
});
|
|
36836
|
+
resolve24(null);
|
|
36837
|
+
});
|
|
36838
|
+
});
|
|
36839
|
+
}
|
|
36840
|
+
function delay3(ms) {
|
|
36841
|
+
return new Promise((resolve24) => setTimeout(resolve24, ms));
|
|
36842
|
+
}
|
|
36843
|
+
|
|
36773
36844
|
// src/commands/sessions/daemon/startDaemonServer.ts
|
|
36774
|
-
function startDaemonServer(manager, checkAutoExit) {
|
|
36775
|
-
|
|
36845
|
+
async function startDaemonServer(manager, checkAutoExit) {
|
|
36846
|
+
if (process.platform === "win32" && !await startWindowsBridge(manager)) {
|
|
36847
|
+
daemonLog(
|
|
36848
|
+
"exiting before binding the pipe so the next launch can take over"
|
|
36849
|
+
);
|
|
36850
|
+
process.exit(1);
|
|
36851
|
+
}
|
|
36852
|
+
const server = net4.createServer(
|
|
36776
36853
|
(socket) => handleConnection(socket, manager)
|
|
36777
36854
|
);
|
|
36778
|
-
if (process.platform === "win32") startWindowsBridge(manager);
|
|
36779
36855
|
let retried = false;
|
|
36780
36856
|
server.on("error", (e) => {
|
|
36781
36857
|
if (e.code !== "EADDRINUSE" || retried) {
|
|
@@ -36791,18 +36867,6 @@ function listenWithSingleOnListening(server, manager, checkAutoExit) {
|
|
|
36791
36867
|
server.removeAllListeners("listening");
|
|
36792
36868
|
server.listen(daemonPaths.socket, () => onListening(manager, checkAutoExit));
|
|
36793
36869
|
}
|
|
36794
|
-
function startWindowsBridge(manager) {
|
|
36795
|
-
const port = windowsDaemonPort();
|
|
36796
|
-
const bridge = net3.createServer((socket) => {
|
|
36797
|
-
socket.setKeepAlive(true, 1e4);
|
|
36798
|
-
handleConnection(socket, manager);
|
|
36799
|
-
});
|
|
36800
|
-
bridge.on(
|
|
36801
|
-
"error",
|
|
36802
|
-
(e) => daemonLog(`windows bridge error: ${e.message}`)
|
|
36803
|
-
);
|
|
36804
|
-
bridge.listen(port, () => daemonLog(`windows bridge listening on :${port}`));
|
|
36805
|
-
}
|
|
36806
36870
|
async function recoverFromAddrInUse(server, manager, checkAutoExit) {
|
|
36807
36871
|
if (await isDaemonRunning()) {
|
|
36808
36872
|
daemonLog("another daemon owns the socket; exiting");
|
|
@@ -36835,7 +36899,7 @@ async function runDaemon() {
|
|
|
36835
36899
|
});
|
|
36836
36900
|
const manager = new SessionManager(checkAutoExit);
|
|
36837
36901
|
setDaemonLogSink(manager.clients.emitLog);
|
|
36838
|
-
startDaemonServer(manager, checkAutoExit);
|
|
36902
|
+
await startDaemonServer(manager, checkAutoExit);
|
|
36839
36903
|
}
|
|
36840
36904
|
|
|
36841
36905
|
// src/commands/sessions/daemon/registerDaemon.ts
|