@adhdev/daemon-core 0.8.76 → 0.8.78

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.
@@ -18,6 +18,8 @@ export interface PtyRuntimeMetadata {
18
18
  runtimeKey?: string;
19
19
  displayName?: string;
20
20
  workspaceLabel?: string;
21
+ lifecycle?: string | null;
22
+ surfaceKind?: 'live_runtime' | 'recovery_snapshot' | 'inactive_record';
21
23
  writeOwner?: PtyRuntimeWriteOwner | null;
22
24
  attachedClients?: PtyRuntimeClientInfo[];
23
25
  restoredFromStorage?: boolean;
package/dist/index.js CHANGED
@@ -4409,6 +4409,61 @@ function getHostMemorySnapshot() {
4409
4409
  return { totalMem, freeMem, availableMem };
4410
4410
  }
4411
4411
 
4412
+ // src/session-host/runtime-surface.ts
4413
+ var LIVE_LIFECYCLES = /* @__PURE__ */ new Set(["starting", "running", "stopping", "interrupted"]);
4414
+ function isSessionHostLiveRuntime(record) {
4415
+ const lifecycle = String(record?.lifecycle || "").trim();
4416
+ return LIVE_LIFECYCLES.has(lifecycle);
4417
+ }
4418
+ function getSessionHostRecoveryLabel(meta) {
4419
+ const recoveryState = typeof meta?.runtimeRecoveryState === "string" ? String(meta.runtimeRecoveryState).trim() : "";
4420
+ if (!recoveryState) return null;
4421
+ if (recoveryState === "auto_resumed") return "restored after restart";
4422
+ if (recoveryState === "resume_failed") return "restore failed";
4423
+ if (recoveryState === "host_restart_interrupted") return "host restart interrupted";
4424
+ if (recoveryState === "orphan_snapshot") return "snapshot recovered";
4425
+ return recoveryState.replace(/_/g, " ");
4426
+ }
4427
+ function isSessionHostRecoverySnapshot(record) {
4428
+ if (!record) return false;
4429
+ if (isSessionHostLiveRuntime(record)) return false;
4430
+ const lifecycle = String(record.lifecycle || "").trim();
4431
+ if (lifecycle && lifecycle !== "stopped" && lifecycle !== "failed") {
4432
+ return false;
4433
+ }
4434
+ const meta = record.meta || void 0;
4435
+ if (meta?.restoredFromStorage === true) return true;
4436
+ return getSessionHostRecoveryLabel(meta) !== null;
4437
+ }
4438
+ function getSessionHostSurfaceKind(record) {
4439
+ if (isSessionHostLiveRuntime(record)) return "live_runtime";
4440
+ if (isSessionHostRecoverySnapshot(record)) return "recovery_snapshot";
4441
+ return "inactive_record";
4442
+ }
4443
+ function partitionSessionHostRecords(records) {
4444
+ const liveRuntimes = [];
4445
+ const recoverySnapshots = [];
4446
+ const inactiveRecords = [];
4447
+ for (const record of records) {
4448
+ const kind = getSessionHostSurfaceKind(record);
4449
+ if (kind === "live_runtime") {
4450
+ liveRuntimes.push(record);
4451
+ } else if (kind === "recovery_snapshot") {
4452
+ recoverySnapshots.push(record);
4453
+ } else {
4454
+ inactiveRecords.push(record);
4455
+ }
4456
+ }
4457
+ return {
4458
+ liveRuntimes,
4459
+ recoverySnapshots,
4460
+ inactiveRecords
4461
+ };
4462
+ }
4463
+ function partitionSessionHostDiagnosticsSessions(records) {
4464
+ return partitionSessionHostRecords(records || []);
4465
+ }
4466
+
4412
4467
  // src/status/chat-tail-hot-sessions.ts
4413
4468
  var DEFAULT_ACTIVE_CHAT_POLL_STATUSES = /* @__PURE__ */ new Set([
4414
4469
  "generating",
@@ -4416,6 +4471,7 @@ var DEFAULT_ACTIVE_CHAT_POLL_STATUSES = /* @__PURE__ */ new Set([
4416
4471
  "starting"
4417
4472
  ]);
4418
4473
  var DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS = 8e3;
4474
+ var LIVE_RUNTIME_LIFECYCLES = /* @__PURE__ */ new Set(["starting", "running", "stopping", "interrupted"]);
4419
4475
  function parseMessageTimestamp(value) {
4420
4476
  if (typeof value === "number" && Number.isFinite(value)) return value;
4421
4477
  if (typeof value === "string") {
@@ -4424,6 +4480,23 @@ function parseMessageTimestamp(value) {
4424
4480
  }
4425
4481
  return 0;
4426
4482
  }
4483
+ function isDefinitelyNonLiveRuntimeSession(session) {
4484
+ const surfaceKind = String(session?.runtimeSurfaceKind || "").trim();
4485
+ if (surfaceKind === "live_runtime") return false;
4486
+ if (surfaceKind === "recovery_snapshot") return true;
4487
+ if (surfaceKind === "inactive_record") return false;
4488
+ const lifecycle = String(session?.runtimeLifecycle || "").trim();
4489
+ if (lifecycle && LIVE_RUNTIME_LIFECYCLES.has(lifecycle)) return false;
4490
+ const inferredSurfaceKind = getSessionHostSurfaceKind({
4491
+ lifecycle: lifecycle || null,
4492
+ meta: {
4493
+ restoredFromStorage: session?.runtimeRestoredFromStorage === true,
4494
+ ...session?.runtimeRecoveryState ? { runtimeRecoveryState: session.runtimeRecoveryState } : {}
4495
+ }
4496
+ });
4497
+ if (inferredSurfaceKind === "recovery_snapshot") return true;
4498
+ return false;
4499
+ }
4427
4500
  function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessionIds, options = {}) {
4428
4501
  const now = options.now ?? Date.now();
4429
4502
  const recentMessageGraceMs = Math.max(
@@ -4432,9 +4505,14 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
4432
4505
  );
4433
4506
  const activeStatuses = options.activeStatuses ?? DEFAULT_ACTIVE_CHAT_POLL_STATUSES;
4434
4507
  const active = /* @__PURE__ */ new Set();
4508
+ const excluded = /* @__PURE__ */ new Set();
4435
4509
  for (const session of sessions) {
4436
4510
  const sessionId = typeof session?.id === "string" ? session.id : "";
4437
4511
  if (!sessionId) continue;
4512
+ if (isDefinitelyNonLiveRuntimeSession(session)) {
4513
+ excluded.add(sessionId);
4514
+ continue;
4515
+ }
4438
4516
  const status = String(session?.status || "").toLowerCase();
4439
4517
  const lastMessageAt = parseMessageTimestamp(session?.lastMessageAt);
4440
4518
  const recentlyUpdated = lastMessageAt > 0 && now - lastMessageAt <= recentMessageGraceMs;
@@ -4443,7 +4521,7 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
4443
4521
  }
4444
4522
  }
4445
4523
  const finalizing = new Set(
4446
- Array.from(previousHotSessionIds).filter((sessionId) => !active.has(sessionId))
4524
+ Array.from(previousHotSessionIds).filter((sessionId) => !active.has(sessionId) && !excluded.has(sessionId))
4447
4525
  );
4448
4526
  return { active, finalizing };
4449
4527
  }
@@ -8700,7 +8778,7 @@ function shouldIncludeSessionMetadata(profile) {
8700
8778
  return profile !== "live";
8701
8779
  }
8702
8780
  function shouldIncludeRuntimeMetadata(profile) {
8703
- return profile !== "live";
8781
+ return true;
8704
8782
  }
8705
8783
  function findCdpManager(cdpManagers, key) {
8706
8784
  const exact = cdpManagers.get(key);
@@ -8855,8 +8933,12 @@ function buildCliSession(state, options) {
8855
8933
  runtimeKey: state.runtime?.runtimeKey,
8856
8934
  runtimeDisplayName: state.runtime?.displayName,
8857
8935
  runtimeWorkspaceLabel: state.runtime?.workspaceLabel,
8936
+ runtimeLifecycle: state.runtime?.lifecycle ?? null,
8937
+ runtimeSurfaceKind: state.runtime?.surfaceKind,
8858
8938
  runtimeWriteOwner: state.runtime?.writeOwner || null,
8859
- runtimeAttachedClients: state.runtime?.attachedClients || []
8939
+ runtimeAttachedClients: state.runtime?.attachedClients || [],
8940
+ runtimeRestoredFromStorage: state.runtime?.restoredFromStorage === true,
8941
+ runtimeRecoveryState: state.runtime?.recoveryState ?? null
8860
8942
  },
8861
8943
  mode: state.mode,
8862
8944
  resume: state.resume,
@@ -12141,8 +12223,12 @@ var CliProviderInstance = class {
12141
12223
  runtimeKey: runtime.runtimeKey,
12142
12224
  displayName: runtime.displayName,
12143
12225
  workspaceLabel: runtime.workspaceLabel,
12226
+ lifecycle: runtime.lifecycle ?? null,
12227
+ surfaceKind: runtime.surfaceKind,
12144
12228
  writeOwner: runtime.writeOwner || null,
12145
- attachedClients: runtime.attachedClients || []
12229
+ attachedClients: runtime.attachedClients || [],
12230
+ restoredFromStorage: runtime.restoredFromStorage === true,
12231
+ recoveryState: runtime.recoveryState ?? null
12146
12232
  } : void 0,
12147
12233
  resume: this.provider.resume,
12148
12234
  controlValues: surface.controlValues,
@@ -16395,10 +16481,15 @@ function checkSize() {
16395
16481
  }
16396
16482
  var SKIP_COMMANDS = /* @__PURE__ */ new Set([
16397
16483
  "heartbeat",
16398
- "status_report"
16484
+ "status_report",
16485
+ "read_chat",
16486
+ "mark_session_seen"
16399
16487
  ]);
16488
+ function shouldLogCommand(cmd) {
16489
+ return !SKIP_COMMANDS.has(cmd);
16490
+ }
16400
16491
  function logCommand(entry) {
16401
- if (SKIP_COMMANDS.has(entry.cmd)) return;
16492
+ if (!shouldLogCommand(entry.cmd)) return;
16402
16493
  try {
16403
16494
  if (++writeCount2 % 500 === 0) {
16404
16495
  checkRotation();
@@ -16449,61 +16540,6 @@ cleanOldFiles();
16449
16540
  // src/commands/router.ts
16450
16541
  init_logger();
16451
16542
 
16452
- // src/session-host/runtime-surface.ts
16453
- var LIVE_LIFECYCLES = /* @__PURE__ */ new Set(["starting", "running", "stopping", "interrupted"]);
16454
- function isSessionHostLiveRuntime(record) {
16455
- const lifecycle = String(record?.lifecycle || "").trim();
16456
- return LIVE_LIFECYCLES.has(lifecycle);
16457
- }
16458
- function getSessionHostRecoveryLabel(meta) {
16459
- const recoveryState = typeof meta?.runtimeRecoveryState === "string" ? String(meta.runtimeRecoveryState).trim() : "";
16460
- if (!recoveryState) return null;
16461
- if (recoveryState === "auto_resumed") return "restored after restart";
16462
- if (recoveryState === "resume_failed") return "restore failed";
16463
- if (recoveryState === "host_restart_interrupted") return "host restart interrupted";
16464
- if (recoveryState === "orphan_snapshot") return "snapshot recovered";
16465
- return recoveryState.replace(/_/g, " ");
16466
- }
16467
- function isSessionHostRecoverySnapshot(record) {
16468
- if (!record) return false;
16469
- if (isSessionHostLiveRuntime(record)) return false;
16470
- const lifecycle = String(record.lifecycle || "").trim();
16471
- if (lifecycle && lifecycle !== "stopped" && lifecycle !== "failed") {
16472
- return false;
16473
- }
16474
- const meta = record.meta || void 0;
16475
- if (meta?.restoredFromStorage === true) return true;
16476
- return getSessionHostRecoveryLabel(meta) !== null;
16477
- }
16478
- function getSessionHostSurfaceKind(record) {
16479
- if (isSessionHostLiveRuntime(record)) return "live_runtime";
16480
- if (isSessionHostRecoverySnapshot(record)) return "recovery_snapshot";
16481
- return "inactive_record";
16482
- }
16483
- function partitionSessionHostRecords(records) {
16484
- const liveRuntimes = [];
16485
- const recoverySnapshots = [];
16486
- const inactiveRecords = [];
16487
- for (const record of records) {
16488
- const kind = getSessionHostSurfaceKind(record);
16489
- if (kind === "live_runtime") {
16490
- liveRuntimes.push(record);
16491
- } else if (kind === "recovery_snapshot") {
16492
- recoverySnapshots.push(record);
16493
- } else {
16494
- inactiveRecords.push(record);
16495
- }
16496
- }
16497
- return {
16498
- liveRuntimes,
16499
- recoverySnapshots,
16500
- inactiveRecords
16501
- };
16502
- }
16503
- function partitionSessionHostDiagnosticsSessions(records) {
16504
- return partitionSessionHostRecords(records || []);
16505
- }
16506
-
16507
16543
  // src/status/snapshot.ts
16508
16544
  var os16 = __toESM(require("os"));
16509
16545
  init_config();
@@ -24878,6 +24914,8 @@ var SessionHostRuntimeTransport = class {
24878
24914
  runtimeKey: record.runtimeKey,
24879
24915
  displayName: record.displayName,
24880
24916
  workspaceLabel: record.workspaceLabel,
24917
+ lifecycle: typeof record.lifecycle === "string" ? record.lifecycle : null,
24918
+ surfaceKind: record.surfaceKind,
24881
24919
  writeOwner: record.writeOwner ? {
24882
24920
  clientId: record.writeOwner.clientId,
24883
24921
  ownerType: record.writeOwner.ownerType