@adhdev/daemon-standalone 1.0.30-rc.1 → 1.0.30

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/mcp-server",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "ADHDev MCP server \u2014 expose IDE agents as MCP tools",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -35,6 +35,11 @@ declare class SessionHostServer extends EventEmitter {
35
35
  private handleIncomingRequest;
36
36
  private writeEnvelopeSafely;
37
37
  private schedulePersist;
38
+ /**
39
+ * @param allowTerminal - write even if the record is terminal. Only the exit
40
+ * handler sets this, to stamp the final terminated record for the brief
41
+ * post-mortem window before cleanup.
42
+ */
38
43
  private persistNow;
39
44
  private getHostDiagnostics;
40
45
  private recordHostLog;
@@ -35,6 +35,11 @@ declare class SessionHostServer extends EventEmitter {
35
35
  private handleIncomingRequest;
36
36
  private writeEnvelopeSafely;
37
37
  private schedulePersist;
38
+ /**
39
+ * @param allowTerminal - write even if the record is terminal. Only the exit
40
+ * handler sets this, to stamp the final terminated record for the brief
41
+ * post-mortem window before cleanup.
42
+ */
38
43
  private persistNow;
39
44
  private getHostDiagnostics;
40
45
  private recordHostLog;
@@ -1074,9 +1074,15 @@ var SessionHostServer = class extends import_events.EventEmitter {
1074
1074
  this.persistNow(sessionId);
1075
1075
  }, 200));
1076
1076
  }
1077
- persistNow(sessionId) {
1077
+ /**
1078
+ * @param allowTerminal - write even if the record is terminal. Only the exit
1079
+ * handler sets this, to stamp the final terminated record for the brief
1080
+ * post-mortem window before cleanup.
1081
+ */
1082
+ persistNow(sessionId, allowTerminal = false) {
1078
1083
  const record = this.registry.getSession(sessionId);
1079
1084
  if (!record) return;
1085
+ if (!allowTerminal && (0, import_session_host_core5.isTerminalRecord)(record)) return;
1080
1086
  const snapshot = this.getSnapshot(sessionId);
1081
1087
  try {
1082
1088
  this.storage.save(record, snapshot);
@@ -1312,6 +1318,11 @@ var SessionHostServer = class extends import_events.EventEmitter {
1312
1318
  this.recordRuntimeTransition(record.sessionId, "prune_duplicate_timeout", "stopping", void 0, false, error?.message || String(error));
1313
1319
  });
1314
1320
  }
1321
+ const pendingPersistTimer = this.persistTimers.get(record.sessionId);
1322
+ if (pendingPersistTimer) {
1323
+ clearTimeout(pendingPersistTimer);
1324
+ this.persistTimers.delete(record.sessionId);
1325
+ }
1315
1326
  this.registry.deleteSession(record.sessionId);
1316
1327
  this.storage.remove(record.sessionId);
1317
1328
  this.storage.removeTombstone(record.sessionId);
@@ -1357,7 +1368,12 @@ var SessionHostServer = class extends import_events.EventEmitter {
1357
1368
  this.registry.markStopped(record.sessionId, termination.lifecycle, termination);
1358
1369
  this.runtimes.delete(record.sessionId);
1359
1370
  this.resolveExitWaiters(record.sessionId, exitCode);
1360
- this.persistNow(record.sessionId);
1371
+ const pendingPersistTimer = this.persistTimers.get(record.sessionId);
1372
+ if (pendingPersistTimer) {
1373
+ clearTimeout(pendingPersistTimer);
1374
+ this.persistTimers.delete(record.sessionId);
1375
+ }
1376
+ this.persistNow(record.sessionId, true);
1361
1377
  this.storage.saveTombstone(record.sessionId, termination);
1362
1378
  this.emitEvent({ type: "session_exit", sessionId: record.sessionId, exitCode, signal, termination });
1363
1379
  const summary = `reason=${termination.reason} exitCode=${termination.exitCode === null ? "unknown" : termination.exitCode} signal=${termination.signal ?? "none"}`;
@@ -1386,7 +1402,12 @@ var SessionHostServer = class extends import_events.EventEmitter {
1386
1402
  termination.lifecycle === "stopped",
1387
1403
  termination.lifecycle === "stopped" ? void 0 : summary
1388
1404
  );
1389
- setTimeout(() => this.storage.remove(record.sessionId), 5e3).unref?.();
1405
+ setTimeout(() => {
1406
+ const current = this.registry.getSession(record.sessionId);
1407
+ if (current && !(0, import_session_host_core5.isTerminalRecord)(current)) return;
1408
+ this.registry.deleteSession(record.sessionId);
1409
+ this.storage.remove(record.sessionId);
1410
+ }, 5e3).unref?.();
1390
1411
  return termination;
1391
1412
  }
1392
1413
  };