@adhdev/daemon-standalone 0.7.16 → 0.7.18
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/index.js +102 -60
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-mHBeW9vR.js +68 -0
- package/public/index.html +1 -1
- package/public/assets/index-BWW2S6O1.js +0 -68
package/dist/index.js
CHANGED
|
@@ -33462,6 +33462,59 @@ var SessionHostPtyTransportFactory = class {
|
|
|
33462
33462
|
});
|
|
33463
33463
|
}
|
|
33464
33464
|
};
|
|
33465
|
+
var STARTUP_TIMEOUT_MS = 8e3;
|
|
33466
|
+
var STARTUP_POLL_MS = 200;
|
|
33467
|
+
async function canConnect(endpoint) {
|
|
33468
|
+
const client = new SessionHostClient({ endpoint });
|
|
33469
|
+
try {
|
|
33470
|
+
await client.connect();
|
|
33471
|
+
await client.close();
|
|
33472
|
+
return true;
|
|
33473
|
+
} catch {
|
|
33474
|
+
return false;
|
|
33475
|
+
}
|
|
33476
|
+
}
|
|
33477
|
+
async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
|
|
33478
|
+
const deadline = Date.now() + timeoutMs;
|
|
33479
|
+
while (Date.now() < deadline) {
|
|
33480
|
+
if (await canConnect(endpoint)) return;
|
|
33481
|
+
await new Promise((resolve92) => setTimeout(resolve92, STARTUP_POLL_MS));
|
|
33482
|
+
}
|
|
33483
|
+
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
33484
|
+
}
|
|
33485
|
+
async function ensureSessionHostReady(options) {
|
|
33486
|
+
const endpoint = getDefaultSessionHostEndpoint(options.appName || "adhdev");
|
|
33487
|
+
if (await canConnect(endpoint)) return endpoint;
|
|
33488
|
+
options.spawnHost();
|
|
33489
|
+
await waitForReady(endpoint, options.timeoutMs);
|
|
33490
|
+
return endpoint;
|
|
33491
|
+
}
|
|
33492
|
+
async function listHostedCliRuntimes(endpoint) {
|
|
33493
|
+
const client = new SessionHostClient({ endpoint });
|
|
33494
|
+
try {
|
|
33495
|
+
const response = await client.request({
|
|
33496
|
+
type: "list_sessions",
|
|
33497
|
+
payload: {}
|
|
33498
|
+
});
|
|
33499
|
+
if (!response.success || !response.result) {
|
|
33500
|
+
return [];
|
|
33501
|
+
}
|
|
33502
|
+
return response.result.filter((record2) => record2.category === "cli" && ["running", "interrupted"].includes(record2.lifecycle)).sort((a, b) => b.lastActivityAt - a.lastActivityAt).map((record2) => ({
|
|
33503
|
+
runtimeId: record2.sessionId,
|
|
33504
|
+
runtimeKey: record2.runtimeKey,
|
|
33505
|
+
displayName: record2.displayName,
|
|
33506
|
+
workspaceLabel: record2.workspaceLabel,
|
|
33507
|
+
lifecycle: record2.lifecycle,
|
|
33508
|
+
recoveryState: typeof record2.meta?.runtimeRecoveryState === "string" ? String(record2.meta.runtimeRecoveryState) : null,
|
|
33509
|
+
cliType: record2.providerType,
|
|
33510
|
+
workspace: record2.workspace,
|
|
33511
|
+
cliArgs: Array.isArray(record2.meta?.cliArgs) ? record2.meta.cliArgs : []
|
|
33512
|
+
}));
|
|
33513
|
+
} finally {
|
|
33514
|
+
await client.close().catch(() => {
|
|
33515
|
+
});
|
|
33516
|
+
}
|
|
33517
|
+
}
|
|
33465
33518
|
var SessionRegistry = class {
|
|
33466
33519
|
bySessionId = /* @__PURE__ */ new Map();
|
|
33467
33520
|
byManagerKey = /* @__PURE__ */ new Map();
|
|
@@ -33708,27 +33761,7 @@ async function shutdownDaemonComponents(components) {
|
|
|
33708
33761
|
// src/session-host.ts
|
|
33709
33762
|
var import_child_process8 = require("child_process");
|
|
33710
33763
|
var path15 = __toESM(require("path"));
|
|
33711
|
-
var STARTUP_TIMEOUT_MS = 8e3;
|
|
33712
|
-
var STARTUP_POLL_MS = 200;
|
|
33713
33764
|
var SESSION_HOST_APP_NAME = process.env.ADHDEV_SESSION_HOST_NAME || "adhdev";
|
|
33714
|
-
async function canConnect(endpoint) {
|
|
33715
|
-
const client = new SessionHostClient({ endpoint });
|
|
33716
|
-
try {
|
|
33717
|
-
await client.connect();
|
|
33718
|
-
await client.close();
|
|
33719
|
-
return true;
|
|
33720
|
-
} catch {
|
|
33721
|
-
return false;
|
|
33722
|
-
}
|
|
33723
|
-
}
|
|
33724
|
-
async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
|
|
33725
|
-
const deadline = Date.now() + timeoutMs;
|
|
33726
|
-
while (Date.now() < deadline) {
|
|
33727
|
-
if (await canConnect(endpoint)) return;
|
|
33728
|
-
await new Promise((resolve12) => setTimeout(resolve12, STARTUP_POLL_MS));
|
|
33729
|
-
}
|
|
33730
|
-
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
33731
|
-
}
|
|
33732
33765
|
function resolveSessionHostEntry() {
|
|
33733
33766
|
const localCandidates = [
|
|
33734
33767
|
path15.resolve(__dirname, "../vendor/session-host-daemon/index.js"),
|
|
@@ -33755,51 +33788,33 @@ async function runSessionHostCli(args) {
|
|
|
33755
33788
|
child.on("exit", (code) => resolve12(code ?? 0));
|
|
33756
33789
|
});
|
|
33757
33790
|
}
|
|
33758
|
-
async function
|
|
33759
|
-
|
|
33760
|
-
|
|
33761
|
-
|
|
33762
|
-
|
|
33763
|
-
|
|
33764
|
-
|
|
33765
|
-
|
|
33791
|
+
async function ensureSessionHostReady2() {
|
|
33792
|
+
return ensureSessionHostReady({
|
|
33793
|
+
appName: SESSION_HOST_APP_NAME,
|
|
33794
|
+
spawnHost: () => {
|
|
33795
|
+
const entry = resolveSessionHostEntry();
|
|
33796
|
+
const child = (0, import_child_process8.spawn)(process.execPath, [entry], {
|
|
33797
|
+
detached: true,
|
|
33798
|
+
stdio: "ignore",
|
|
33799
|
+
windowsHide: true,
|
|
33800
|
+
env: {
|
|
33801
|
+
...process.env,
|
|
33802
|
+
ADHDEV_SESSION_HOST_NAME: SESSION_HOST_APP_NAME
|
|
33803
|
+
}
|
|
33804
|
+
});
|
|
33805
|
+
child.unref();
|
|
33806
|
+
}
|
|
33766
33807
|
});
|
|
33767
|
-
child.unref();
|
|
33768
|
-
await waitForReady(endpoint);
|
|
33769
|
-
return endpoint;
|
|
33770
33808
|
}
|
|
33771
|
-
async function
|
|
33772
|
-
|
|
33773
|
-
try {
|
|
33774
|
-
const response = await client.request({
|
|
33775
|
-
type: "list_sessions",
|
|
33776
|
-
payload: {}
|
|
33777
|
-
});
|
|
33778
|
-
if (!response.success || !response.result) {
|
|
33779
|
-
return [];
|
|
33780
|
-
}
|
|
33781
|
-
return response.result.filter((record2) => record2.category === "cli" && ["running", "interrupted"].includes(record2.lifecycle)).sort((a, b) => b.lastActivityAt - a.lastActivityAt).map((record2) => ({
|
|
33782
|
-
runtimeId: record2.sessionId,
|
|
33783
|
-
runtimeKey: record2.runtimeKey,
|
|
33784
|
-
displayName: record2.displayName,
|
|
33785
|
-
workspaceLabel: record2.workspaceLabel,
|
|
33786
|
-
lifecycle: record2.lifecycle,
|
|
33787
|
-
recoveryState: typeof record2.meta?.runtimeRecoveryState === "string" ? String(record2.meta.runtimeRecoveryState) : null,
|
|
33788
|
-
cliType: record2.providerType,
|
|
33789
|
-
workspace: record2.workspace,
|
|
33790
|
-
cliArgs: Array.isArray(record2.meta?.cliArgs) ? record2.meta.cliArgs : []
|
|
33791
|
-
}));
|
|
33792
|
-
} finally {
|
|
33793
|
-
await client.close().catch(() => {
|
|
33794
|
-
});
|
|
33795
|
-
}
|
|
33809
|
+
async function listHostedCliRuntimes2(endpoint) {
|
|
33810
|
+
return listHostedCliRuntimes(endpoint);
|
|
33796
33811
|
}
|
|
33797
33812
|
async function proxySessionHostList(showAll = false) {
|
|
33798
|
-
await
|
|
33813
|
+
await ensureSessionHostReady2();
|
|
33799
33814
|
return runSessionHostCli(["list", ...showAll ? ["--all"] : []]);
|
|
33800
33815
|
}
|
|
33801
33816
|
async function proxySessionHostAttach(target, options = {}) {
|
|
33802
|
-
await
|
|
33817
|
+
await ensureSessionHostReady2();
|
|
33803
33818
|
const args = ["attach", target];
|
|
33804
33819
|
if (options.readOnly) args.push("--read-only");
|
|
33805
33820
|
if (options.takeover) args.push("--takeover");
|
|
@@ -33999,7 +34014,7 @@ var StandaloneServer = class {
|
|
|
33999
34014
|
async start(options = {}) {
|
|
34000
34015
|
const port = options.port || DEFAULT_PORT;
|
|
34001
34016
|
const host = options.host || "127.0.0.1";
|
|
34002
|
-
const sessionHostEndpoint = await
|
|
34017
|
+
const sessionHostEndpoint = await ensureSessionHostReady2();
|
|
34003
34018
|
this.sessionHostEndpoint = sessionHostEndpoint;
|
|
34004
34019
|
this.authToken = options.token || process.env.ADHDEV_TOKEN || null;
|
|
34005
34020
|
this.components = await initDaemonComponents({
|
|
@@ -34031,7 +34046,7 @@ var StandaloneServer = class {
|
|
|
34031
34046
|
managedBy: "adhdev-standalone"
|
|
34032
34047
|
}
|
|
34033
34048
|
}),
|
|
34034
|
-
listHostedCliRuntimes: async () =>
|
|
34049
|
+
listHostedCliRuntimes: async () => listHostedCliRuntimes2(sessionHostEndpoint)
|
|
34035
34050
|
},
|
|
34036
34051
|
onStatusChange: () => this.broadcastStatus(),
|
|
34037
34052
|
onStreamsUpdated: (ideType, streams) => {
|
|
@@ -34399,6 +34414,7 @@ var StandaloneServer = class {
|
|
|
34399
34414
|
console.log(`[WS] Client connected (total: ${this.clients.size})`);
|
|
34400
34415
|
const status = this.getStatus();
|
|
34401
34416
|
ws.send(JSON.stringify({ type: "status", data: status }));
|
|
34417
|
+
void this.pushWsRuntimeSnapshots(ws);
|
|
34402
34418
|
ws.on("message", async (raw) => {
|
|
34403
34419
|
try {
|
|
34404
34420
|
const msg = JSON.parse(raw.toString());
|
|
@@ -34442,6 +34458,32 @@ var StandaloneServer = class {
|
|
|
34442
34458
|
daemonMode: false
|
|
34443
34459
|
});
|
|
34444
34460
|
}
|
|
34461
|
+
async pushWsRuntimeSnapshots(ws) {
|
|
34462
|
+
if (!this.components || !this.sessionHostEndpoint || ws.readyState !== import_ws2.WebSocket.OPEN) return;
|
|
34463
|
+
const client = new SessionHostClient({ endpoint: this.sessionHostEndpoint || void 0 });
|
|
34464
|
+
await client.connect();
|
|
34465
|
+
try {
|
|
34466
|
+
const states = this.components.instanceManager.collectAllStates();
|
|
34467
|
+
for (const state of states) {
|
|
34468
|
+
const sessionId = typeof state?.instanceId === "string" ? state.instanceId : "";
|
|
34469
|
+
if (!sessionId || state?.category !== "cli") continue;
|
|
34470
|
+
const snapshot = await client.request({
|
|
34471
|
+
type: "get_snapshot",
|
|
34472
|
+
payload: { sessionId }
|
|
34473
|
+
});
|
|
34474
|
+
if (!snapshot.success || !snapshot.result || ws.readyState !== import_ws2.WebSocket.OPEN) continue;
|
|
34475
|
+
ws.send(JSON.stringify({
|
|
34476
|
+
type: "runtime_snapshot",
|
|
34477
|
+
sessionId,
|
|
34478
|
+
...snapshot.result
|
|
34479
|
+
}));
|
|
34480
|
+
}
|
|
34481
|
+
} catch {
|
|
34482
|
+
} finally {
|
|
34483
|
+
await client.close().catch(() => {
|
|
34484
|
+
});
|
|
34485
|
+
}
|
|
34486
|
+
}
|
|
34445
34487
|
getStatus(snapshot = this.buildSharedSnapshot()) {
|
|
34446
34488
|
const cfgSnap = loadConfig();
|
|
34447
34489
|
return {
|