@adhdev/daemon-core 0.8.35 → 0.8.36

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.
@@ -15,11 +15,12 @@ import { getHostMemorySnapshot } from '../system/host-memory.js';
15
15
  import { getTerminalBackendRuntimeStatus } from '../cli-adapters/terminal-screen.js';
16
16
  import { LOG } from '../logging/logger.js';
17
17
  import type { DaemonCdpManager } from '../cdp/manager.js';
18
- import { buildSessionEntries, isCdpConnected } from './builders.js';
18
+ import { buildSessionEntries, isCdpConnected, type SessionEntryProfile } from './builders.js';
19
19
  import type { ProviderState } from '../providers/provider-instance.js';
20
20
  import type {
21
21
  AvailableProviderInfo,
22
22
  DetectedIdeInfo,
23
+ MachineInfo,
23
24
  RecentLaunchEntry,
24
25
  RecentSessionBucket,
25
26
  SessionEntry,
@@ -54,15 +55,13 @@ export interface StatusSnapshotOptions {
54
55
  }>;
55
56
  instanceId: string;
56
57
  version: string;
57
- daemonMode: boolean;
58
58
  timestamp?: number;
59
59
  p2p?: StatusReportPayload['p2p'];
60
60
  machineNickname?: string | null;
61
+ profile?: SessionEntryProfile;
61
62
  }
62
63
 
63
- export interface StatusSnapshot extends StatusReportPayload {
64
- availableProviders: AvailableProviderInfo[];
65
- }
64
+ export type StatusSnapshot = StatusReportPayload;
66
65
 
67
66
  const READ_DEBUG_ENABLED = process.argv.includes('--dev') || process.env.ADHDEV_READ_DEBUG === '1';
68
67
 
@@ -103,6 +102,41 @@ function buildAvailableProviders(
103
102
  }));
104
103
  }
105
104
 
105
+ export function buildMachineInfo(profile: 'full' | 'live' | 'metadata' = 'full'): MachineInfo {
106
+ const base: MachineInfo = {
107
+ hostname: os.hostname(),
108
+ platform: os.platform(),
109
+ };
110
+
111
+ if (profile === 'live') {
112
+ return base;
113
+ }
114
+
115
+ if (profile === 'metadata') {
116
+ const memSnap = getHostMemorySnapshot();
117
+ return {
118
+ ...base,
119
+ arch: os.arch(),
120
+ cpus: os.cpus().length,
121
+ totalMem: memSnap.totalMem,
122
+ release: os.release(),
123
+ };
124
+ }
125
+
126
+ const memSnap = getHostMemorySnapshot();
127
+ return {
128
+ ...base,
129
+ arch: os.arch(),
130
+ cpus: os.cpus().length,
131
+ totalMem: memSnap.totalMem,
132
+ freeMem: memSnap.freeMem,
133
+ availableMem: memSnap.availableMem,
134
+ loadavg: os.loadavg(),
135
+ uptime: os.uptime(),
136
+ release: os.release(),
137
+ };
138
+ }
139
+
106
140
  function parseMessageTime(value: unknown): number {
107
141
  if (typeof value === 'number' && Number.isFinite(value)) return value;
108
142
  if (typeof value === 'string') {
@@ -207,28 +241,39 @@ function buildRecentLaunches(
207
241
  }
208
242
 
209
243
  export function buildStatusSnapshot(options: StatusSnapshotOptions): StatusSnapshot {
244
+ const profile = options.profile || 'full';
210
245
  const cfg = loadConfig();
211
246
  const state = loadState();
212
247
  const wsState = getWorkspaceState(cfg);
213
- const memSnap = getHostMemorySnapshot();
214
248
  const recentActivity = getRecentActivity(state, 20);
215
- const sessions = buildSessionEntries(
249
+ const unreadSourceSessions = buildSessionEntries(
216
250
  options.allStates,
217
251
  options.cdpManagers,
252
+ { profile: 'full' },
218
253
  );
219
- for (const session of sessions) {
220
- const lastSeenAt = getSessionSeenAt(state, session.id);
221
- const seenCompletionMarker = getSessionSeenMarker(state, session.id);
222
- const lastUsedAt = getSessionLastUsedAt(session);
223
- const completionMarker = getSessionCompletionMarker(session);
224
- const { unread, inboxBucket } = session.surfaceHidden
254
+ const sessions = profile === 'full'
255
+ ? unreadSourceSessions
256
+ : buildSessionEntries(
257
+ options.allStates,
258
+ options.cdpManagers,
259
+ { profile },
260
+ );
261
+ const sessionsById = new Map(sessions.map((session) => [session.id, session]));
262
+ for (const sourceSession of unreadSourceSessions) {
263
+ const session = sessionsById.get(sourceSession.id);
264
+ if (!session) continue;
265
+ const lastSeenAt = getSessionSeenAt(state, sourceSession.id);
266
+ const seenCompletionMarker = getSessionSeenMarker(state, sourceSession.id);
267
+ const lastUsedAt = getSessionLastUsedAt(sourceSession);
268
+ const completionMarker = getSessionCompletionMarker(sourceSession);
269
+ const { unread, inboxBucket } = sourceSession.surfaceHidden
225
270
  ? { unread: false, inboxBucket: 'idle' as RecentSessionBucket }
226
271
  : getUnreadState(
227
- getSessionMessageUpdatedAt(session) > 0,
228
- session.status,
272
+ getSessionMessageUpdatedAt(sourceSession) > 0,
273
+ sourceSession.status,
229
274
  lastUsedAt,
230
275
  lastSeenAt,
231
- getLastMessageRole(session),
276
+ getLastMessageRole(sourceSession),
232
277
  completionMarker,
233
278
  seenCompletionMarker,
234
279
  );
@@ -238,39 +283,32 @@ export function buildStatusSnapshot(options: StatusSnapshotOptions): StatusSnaps
238
283
  if (READ_DEBUG_ENABLED && (session.unread || session.inboxBucket !== 'idle' || session.providerType.includes('codex'))) {
239
284
  LOG.info(
240
285
  'RecentRead',
241
- `snapshot session id=${session.id} provider=${session.providerType} status=${String(session.status || '')} bucket=${inboxBucket} unread=${String(unread)} lastSeenAt=${lastSeenAt} completionMarker=${completionMarker || '-'} seenMarker=${seenCompletionMarker || '-'} lastUpdated=${String(session.lastUpdated || 0)} lastUsedAt=${lastUsedAt} lastRole=${getLastMessageRole(session)} msgUpdatedAt=${getSessionMessageUpdatedAt(session)}`,
286
+ `snapshot session id=${session.id} provider=${session.providerType} status=${String(session.status || '')} bucket=${inboxBucket} unread=${String(unread)} lastSeenAt=${lastSeenAt} completionMarker=${completionMarker || '-'} seenMarker=${seenCompletionMarker || '-'} lastUpdated=${String(session.lastUpdated || 0)} lastUsedAt=${lastUsedAt} lastRole=${getLastMessageRole(sourceSession)} msgUpdatedAt=${getSessionMessageUpdatedAt(sourceSession)}`,
242
287
  );
243
288
  }
244
289
  }
245
- const terminalBackend = getTerminalBackendRuntimeStatus();
290
+ const includeMachineMetadata = profile !== 'live';
291
+ const terminalBackend = includeMachineMetadata
292
+ ? getTerminalBackendRuntimeStatus()
293
+ : undefined;
246
294
 
247
295
  return {
248
296
  instanceId: options.instanceId,
249
- version: options.version,
250
- daemonMode: options.daemonMode,
251
- machine: {
252
- hostname: os.hostname(),
253
- platform: os.platform(),
254
- arch: os.arch(),
255
- cpus: os.cpus().length,
256
- totalMem: memSnap.totalMem,
257
- freeMem: memSnap.freeMem,
258
- availableMem: memSnap.availableMem,
259
- loadavg: os.loadavg(),
260
- uptime: os.uptime(),
261
- release: os.release(),
262
- },
263
- machineNickname: options.machineNickname ?? cfg.machineNickname ?? null,
297
+ ...(includeMachineMetadata ? { version: options.version } : {}),
298
+ machine: buildMachineInfo(profile),
299
+ ...(includeMachineMetadata ? { machineNickname: options.machineNickname ?? cfg.machineNickname ?? null } : {}),
264
300
  timestamp: options.timestamp ?? Date.now(),
265
- detectedIdes: buildDetectedIdeInfos(options.detectedIdes, options.cdpManagers),
266
301
  ...(options.p2p ? { p2p: options.p2p } : {}),
267
302
  sessions,
268
- workspaces: wsState.workspaces,
269
- defaultWorkspaceId: wsState.defaultWorkspaceId,
270
- defaultWorkspacePath: wsState.defaultWorkspacePath,
271
- terminalSizingMode: cfg.terminalSizingMode || 'measured',
272
- recentLaunches: buildRecentLaunches(recentActivity),
273
- terminalBackend,
274
- availableProviders: buildAvailableProviders(options.providerLoader),
303
+ ...(terminalBackend ? { terminalBackend } : {}),
304
+ ...(includeMachineMetadata && {
305
+ detectedIdes: buildDetectedIdeInfos(options.detectedIdes, options.cdpManagers),
306
+ workspaces: wsState.workspaces,
307
+ defaultWorkspaceId: wsState.defaultWorkspaceId,
308
+ defaultWorkspacePath: wsState.defaultWorkspacePath,
309
+ terminalSizingMode: cfg.terminalSizingMode || 'measured',
310
+ recentLaunches: buildRecentLaunches(recentActivity),
311
+ availableProviders: buildAvailableProviders(options.providerLoader),
312
+ }),
275
313
  };
276
314
  }
package/src/types.ts CHANGED
@@ -18,7 +18,7 @@ export interface StatusResponse extends StatusReportPayload {
18
18
  /** User display name from config */
19
19
  userName?: string;
20
20
  /** Available providers */
21
- availableProviders: AvailableProviderInfo[];
21
+ availableProviders?: AvailableProviderInfo[];
22
22
  /** System info (legacy compat) */
23
23
  system?: SystemInfo;
24
24
  }