@adhdev/daemon-standalone 0.7.17 → 0.7.19

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 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 ensureSessionHostReady() {
33759
- const endpoint = getDefaultSessionHostEndpoint(SESSION_HOST_APP_NAME);
33760
- if (await canConnect(endpoint)) return endpoint;
33761
- const entry = resolveSessionHostEntry();
33762
- const child = (0, import_child_process8.spawn)(process.execPath, [entry], {
33763
- detached: true,
33764
- stdio: "ignore",
33765
- windowsHide: true
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 listHostedCliRuntimes(endpoint) {
33772
- const client = new SessionHostClient({ endpoint });
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 ensureSessionHostReady();
33813
+ await ensureSessionHostReady2();
33799
33814
  return runSessionHostCli(["list", ...showAll ? ["--all"] : []]);
33800
33815
  }
33801
33816
  async function proxySessionHostAttach(target, options = {}) {
33802
- await ensureSessionHostReady();
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 ensureSessionHostReady();
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 () => listHostedCliRuntimes(sessionHostEndpoint)
34049
+ listHostedCliRuntimes: async () => listHostedCliRuntimes2(sessionHostEndpoint)
34035
34050
  },
34036
34051
  onStatusChange: () => this.broadcastStatus(),
34037
34052
  onStreamsUpdated: (ideType, streams) => {