@adhdev/daemon-standalone 1.0.28-rc.17 → 1.0.28-rc.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.
@@ -5,6 +5,8 @@ import { SessionHostEndpoint, SessionHostRegistry, SessionHostRequest, SessionHo
5
5
  interface SessionHostServerOptions {
6
6
  endpoint?: SessionHostEndpoint;
7
7
  appName?: string;
8
+ /** Explicit session-host state root (runtime records + tombstones). */
9
+ storageRootDir?: string;
8
10
  }
9
11
  declare class SessionHostServer extends EventEmitter {
10
12
  readonly endpoint: SessionHostEndpoint;
@@ -5,6 +5,8 @@ import { SessionHostEndpoint, SessionHostRegistry, SessionHostRequest, SessionHo
5
5
  interface SessionHostServerOptions {
6
6
  endpoint?: SessionHostEndpoint;
7
7
  appName?: string;
8
+ /** Explicit session-host state root (runtime records + tombstones). */
9
+ storageRootDir?: string;
8
10
  }
9
11
  declare class SessionHostServer extends EventEmitter {
10
12
  readonly endpoint: SessionHostEndpoint;
@@ -36,15 +36,14 @@ __export(index_exports, {
36
36
  module.exports = __toCommonJS(index_exports);
37
37
  var import_crypto = require("crypto");
38
38
  var fs4 = __toESM(require("fs"));
39
- var os3 = __toESM(require("os"));
40
39
  var path2 = __toESM(require("path"));
41
- var import_session_host_core5 = require("@adhdev/session-host-core");
40
+ var import_session_host_core6 = require("@adhdev/session-host-core");
42
41
 
43
42
  // src/server.ts
44
43
  var import_events = require("events");
45
44
  var fs3 = __toESM(require("fs"));
46
45
  var net = __toESM(require("net"));
47
- var import_session_host_core4 = require("@adhdev/session-host-core");
46
+ var import_session_host_core5 = require("@adhdev/session-host-core");
48
47
 
49
48
  // src/runtime.ts
50
49
  var fs = __toESM(require("fs"));
@@ -395,15 +394,15 @@ var PtySessionRuntime = class {
395
394
 
396
395
  // src/storage.ts
397
396
  var fs2 = __toESM(require("fs"));
398
- var os2 = __toESM(require("os"));
399
397
  var path = __toESM(require("path"));
398
+ var import_session_host_core2 = require("@adhdev/session-host-core");
400
399
  var SessionHostStorage = class {
401
400
  rootDir;
402
401
  runtimesDir;
403
402
  tombstonesDir;
404
403
  constructor(options = {}) {
405
404
  const appName = options.appName || "adhdev";
406
- this.rootDir = path.join(os2.homedir(), ".adhdev", "session-host", appName);
405
+ this.rootDir = options.rootDir || path.join((0, import_session_host_core2.resolveInstanceConfigDir)(process.env), "session-host", appName);
407
406
  this.runtimesDir = path.join(this.rootDir, "runtimes");
408
407
  this.tombstonesDir = path.join(this.rootDir, "tombstones");
409
408
  }
@@ -490,7 +489,7 @@ var SessionHostStorage = class {
490
489
  };
491
490
 
492
491
  // src/session-diagnostics.ts
493
- var import_session_host_core2 = require("@adhdev/session-host-core");
492
+ var import_session_host_core3 = require("@adhdev/session-host-core");
494
493
  var MAX_RECENT_DIAGNOSTICS = 200;
495
494
  function pushRecent(bucket, entry, max = MAX_RECENT_DIAGNOSTICS) {
496
495
  bucket.push(entry);
@@ -546,7 +545,7 @@ function buildHostDiagnostics(params) {
546
545
  hostStartedAt: params.hostStartedAt,
547
546
  endpoint: params.endpointPath,
548
547
  runtimeCount: params.runtimeCount,
549
- supportedRequestTypes: [...import_session_host_core2.SESSION_HOST_SUPPORTED_REQUEST_TYPES],
548
+ supportedRequestTypes: [...import_session_host_core3.SESSION_HOST_SUPPORTED_REQUEST_TYPES],
550
549
  sessions,
551
550
  liveRuntimes,
552
551
  recoverySnapshots,
@@ -558,7 +557,7 @@ function buildHostDiagnostics(params) {
558
557
  }
559
558
 
560
559
  // src/session-lifecycle.ts
561
- var import_session_host_core3 = require("@adhdev/session-host-core");
560
+ var import_session_host_core4 = require("@adhdev/session-host-core");
562
561
  function compareDuplicateCandidates(a, b) {
563
562
  const score = (record) => {
564
563
  const lifecycleScore = record.lifecycle === "running" ? 4 : record.lifecycle === "starting" ? 3 : record.lifecycle === "stopping" ? 2 : record.lifecycle === "interrupted" ? 1 : 0;
@@ -623,8 +622,8 @@ function buildPayloadFromRecord(record) {
623
622
  category: record.category,
624
623
  workspace: record.workspace,
625
624
  launchCommand: record.launchCommand,
626
- cols: (0, import_session_host_core3.resolveSessionHostCols)(typeof record.meta?.sessionHostCols === "number" ? record.meta.sessionHostCols : void 0),
627
- rows: (0, import_session_host_core3.resolveSessionHostRows)(typeof record.meta?.sessionHostRows === "number" ? record.meta.sessionHostRows : void 0),
625
+ cols: (0, import_session_host_core4.resolveSessionHostCols)(typeof record.meta?.sessionHostCols === "number" ? record.meta.sessionHostCols : void 0),
626
+ rows: (0, import_session_host_core4.resolveSessionHostRows)(typeof record.meta?.sessionHostRows === "number" ? record.meta.sessionHostRows : void 0),
628
627
  meta: record.meta
629
628
  };
630
629
  }
@@ -682,7 +681,7 @@ function mergeRuntimeSnapshot(base, record, opts) {
682
681
  // src/server.ts
683
682
  var SessionHostServer = class extends import_events.EventEmitter {
684
683
  endpoint;
685
- registry = new import_session_host_core4.SessionHostRegistry();
684
+ registry = new import_session_host_core5.SessionHostRegistry();
686
685
  runtimes = /* @__PURE__ */ new Map();
687
686
  storage;
688
687
  ipcServer = null;
@@ -702,8 +701,11 @@ var SessionHostServer = class extends import_events.EventEmitter {
702
701
  stopRequests = /* @__PURE__ */ new Map();
703
702
  constructor(options = {}) {
704
703
  super();
705
- this.endpoint = options.endpoint || (0, import_session_host_core4.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
706
- this.storage = new SessionHostStorage({ appName: options.appName || "adhdev" });
704
+ this.endpoint = options.endpoint || (0, import_session_host_core5.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
705
+ this.storage = new SessionHostStorage({
706
+ appName: options.appName || "adhdev",
707
+ rootDir: options.storageRootDir
708
+ });
707
709
  }
708
710
  async start() {
709
711
  if (this.endpoint.kind === "unix") {
@@ -727,7 +729,7 @@ var SessionHostServer = class extends import_events.EventEmitter {
727
729
  } catch {
728
730
  }
729
731
  });
730
- socket.on("data", (0, import_session_host_core4.createLineParser)((envelope) => {
732
+ socket.on("data", (0, import_session_host_core5.createLineParser)((envelope) => {
731
733
  if (envelope.kind !== "request") return;
732
734
  void this.handleIncomingRequest(socket, envelope);
733
735
  }));
@@ -1038,7 +1040,7 @@ var SessionHostServer = class extends import_events.EventEmitter {
1038
1040
  durationMs: Math.max(0, Date.now() - startedAt),
1039
1041
  error: response.success ? void 0 : response.error
1040
1042
  });
1041
- this.writeEnvelopeSafely(socket, (0, import_session_host_core4.createResponseEnvelope)(envelope.requestId, response));
1043
+ this.writeEnvelopeSafely(socket, (0, import_session_host_core5.createResponseEnvelope)(envelope.requestId, response));
1042
1044
  }
1043
1045
  writeEnvelopeSafely(socket, envelope) {
1044
1046
  if (socket.destroyed || !socket.writable || socket.writableEnded) {
@@ -1342,7 +1344,7 @@ var SessionHostServer = class extends import_events.EventEmitter {
1342
1344
  */
1343
1345
  handleRuntimeExit(record, exitCode, signal) {
1344
1346
  const priorRecord = this.registry.getSession(record.sessionId);
1345
- const termination = (0, import_session_host_core4.classifyTermination)({
1347
+ const termination = (0, import_session_host_core5.classifyTermination)({
1346
1348
  exitCode,
1347
1349
  signal,
1348
1350
  osPid: priorRecord?.osPid,
@@ -1391,8 +1393,16 @@ var SessionHostServer = class extends import_events.EventEmitter {
1391
1393
 
1392
1394
  // src/index.ts
1393
1395
  var SESSION_HOST_APP_NAME = process.env.ADHDEV_SESSION_HOST_NAME || "adhdev";
1396
+ var INSTANCE_CONFIG_DIR = (0, import_session_host_core6.resolveInstanceConfigDir)(process.env);
1397
+ var INSTANCE_IPC_KEY = (0, import_session_host_core6.resolveSessionHostIpcKey)(INSTANCE_CONFIG_DIR);
1398
+ function getSessionHostEndpoint() {
1399
+ return (0, import_session_host_core6.getDefaultSessionHostEndpoint)(SESSION_HOST_APP_NAME, { ipcKey: INSTANCE_IPC_KEY });
1400
+ }
1401
+ function getSessionHostStorageRoot() {
1402
+ return path2.join(INSTANCE_CONFIG_DIR, "session-host", SESSION_HOST_APP_NAME);
1403
+ }
1394
1404
  function getSessionHostPidFile(appName) {
1395
- const dir = path2.join(os3.homedir(), ".adhdev");
1405
+ const dir = INSTANCE_CONFIG_DIR;
1396
1406
  if (!fs4.existsSync(dir)) fs4.mkdirSync(dir, { recursive: true });
1397
1407
  return path2.join(dir, `${appName}-session-host.pid`);
1398
1408
  }
@@ -1420,7 +1430,11 @@ function parseArgs(argv) {
1420
1430
  };
1421
1431
  }
1422
1432
  async function runServer() {
1423
- const server = new SessionHostServer({ appName: SESSION_HOST_APP_NAME });
1433
+ const server = new SessionHostServer({
1434
+ appName: SESSION_HOST_APP_NAME,
1435
+ endpoint: getSessionHostEndpoint(),
1436
+ storageRootDir: getSessionHostStorageRoot()
1437
+ });
1424
1438
  writeSessionHostPid(SESSION_HOST_APP_NAME);
1425
1439
  await server.start();
1426
1440
  process.on("SIGINT", async () => {
@@ -1441,7 +1455,7 @@ async function runServer() {
1441
1455
  });
1442
1456
  }
1443
1457
  async function listRuntimes(showAll = false) {
1444
- const client = new import_session_host_core5.SessionHostClient({ endpoint: (0, import_session_host_core5.getDefaultSessionHostEndpoint)(SESSION_HOST_APP_NAME) });
1458
+ const client = new import_session_host_core6.SessionHostClient({ endpoint: getSessionHostEndpoint() });
1445
1459
  try {
1446
1460
  const response = await client.request({
1447
1461
  type: "list_sessions",
@@ -1460,7 +1474,7 @@ async function listRuntimes(showAll = false) {
1460
1474
  console.log([
1461
1475
  runtime.runtimeKey,
1462
1476
  runtime.lifecycle,
1463
- (0, import_session_host_core5.formatRuntimeOwner)(runtime),
1477
+ (0, import_session_host_core6.formatRuntimeOwner)(runtime),
1464
1478
  runtime.workspaceLabel,
1465
1479
  runtime.sessionId,
1466
1480
  runtime.displayName
@@ -1472,7 +1486,7 @@ async function listRuntimes(showAll = false) {
1472
1486
  }
1473
1487
  }
1474
1488
  async function attachRuntime(target, readOnly = false, takeover = false) {
1475
- const client = new import_session_host_core5.SessionHostClient({ endpoint: (0, import_session_host_core5.getDefaultSessionHostEndpoint)(SESSION_HOST_APP_NAME) });
1489
+ const client = new import_session_host_core6.SessionHostClient({ endpoint: getSessionHostEndpoint() });
1476
1490
  const clientId = `local-terminal-${process.pid}-${(0, import_crypto.randomUUID)().slice(0, 8)}`;
1477
1491
  let lastSeq = 0;
1478
1492
  let restoredRawMode = false;
@@ -1567,7 +1581,7 @@ async function attachRuntime(target, readOnly = false, takeover = false) {
1567
1581
  if (!listResponse.success || !listResponse.result) {
1568
1582
  throw new Error(listResponse.error || "Failed to list runtimes");
1569
1583
  }
1570
- let runtimeRecord = (0, import_session_host_core5.resolveAttachableRuntimeRecord)(listResponse.result, target);
1584
+ let runtimeRecord = (0, import_session_host_core6.resolveAttachableRuntimeRecord)(listResponse.result, target);
1571
1585
  runtimeId = runtimeRecord.sessionId;
1572
1586
  if (runtimeRecord.lifecycle === "interrupted" && !readOnly) {
1573
1587
  const resumeResponse = await client.request({
@@ -1710,13 +1724,13 @@ async function main() {
1710
1724
  if (!target) {
1711
1725
  throw new Error("runtime target is required: adhdev-sessiond resume <runtimeId|runtimeKey>");
1712
1726
  }
1713
- const client = new import_session_host_core5.SessionHostClient({ endpoint: (0, import_session_host_core5.getDefaultSessionHostEndpoint)(SESSION_HOST_APP_NAME) });
1727
+ const client = new import_session_host_core6.SessionHostClient({ endpoint: getSessionHostEndpoint() });
1714
1728
  try {
1715
1729
  const listResponse = await client.request({ type: "list_sessions", payload: {} });
1716
1730
  if (!listResponse.success || !listResponse.result) {
1717
1731
  throw new Error(listResponse.error || "Failed to list runtimes");
1718
1732
  }
1719
- const runtimeRecord = (0, import_session_host_core5.resolveRuntimeRecord)(listResponse.result, target);
1733
+ const runtimeRecord = (0, import_session_host_core6.resolveRuntimeRecord)(listResponse.result, target);
1720
1734
  const resumeResponse = await client.request({
1721
1735
  type: "resume_session",
1722
1736
  payload: {