@adhdev/daemon-core 0.6.67 → 0.6.69

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.
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Shared status snapshot builders.
3
+ *
4
+ * Used by:
5
+ * - DaemonStatusReporter (cloud)
6
+ * - daemon-standalone HTTP/WS status responses
7
+ */
8
+
9
+ import * as os from 'os';
10
+ import { loadConfig } from '../config/config.js';
11
+ import { getWorkspaceState } from '../config/workspaces.js';
12
+ import { getWorkspaceActivity } from '../config/workspace-activity.js';
13
+ import { getHostMemorySnapshot } from '../system/host-memory.js';
14
+ import { buildAllManagedEntries, isCdpConnected } from './builders.js';
15
+ import type { ProviderState } from '../providers/provider-instance.js';
16
+ import type {
17
+ AvailableProviderInfo,
18
+ DetectedIdeInfo,
19
+ StatusReportPayload,
20
+ } from '../shared-types.js';
21
+
22
+ export interface StatusSnapshotOptions {
23
+ allStates: ProviderState[];
24
+ cdpManagers: Map<string, unknown>;
25
+ providerLoader: {
26
+ getAll(): Array<{
27
+ type: string;
28
+ icon?: string;
29
+ displayName?: string;
30
+ category: 'ide' | 'extension' | 'cli' | 'acp';
31
+ }>;
32
+ };
33
+ detectedIdes: Array<{
34
+ id: string;
35
+ name?: string;
36
+ displayName?: string;
37
+ installed?: boolean;
38
+ path?: string;
39
+ }>;
40
+ instanceId: string;
41
+ version: string;
42
+ daemonMode: boolean;
43
+ timestamp?: number;
44
+ p2p?: StatusReportPayload['p2p'];
45
+ machineNickname?: string | null;
46
+ }
47
+
48
+ export interface StatusSnapshot extends StatusReportPayload {
49
+ availableProviders: AvailableProviderInfo[];
50
+ }
51
+
52
+ function buildDetectedIdeInfos(
53
+ detectedIdes: StatusSnapshotOptions['detectedIdes'],
54
+ cdpManagers: StatusSnapshotOptions['cdpManagers'],
55
+ ): DetectedIdeInfo[] {
56
+ return detectedIdes
57
+ .filter((ide) => ide.installed !== false)
58
+ .map((ide) => ({
59
+ id: ide.id,
60
+ type: ide.id,
61
+ name: ide.displayName || ide.name || ide.id,
62
+ running: isCdpConnected(cdpManagers as Map<string, any>, ide.id),
63
+ ...(ide.path ? { path: ide.path } : {}),
64
+ }));
65
+ }
66
+
67
+ function buildAvailableProviders(
68
+ providerLoader: StatusSnapshotOptions['providerLoader'],
69
+ ): AvailableProviderInfo[] {
70
+ return providerLoader.getAll().map((provider) => ({
71
+ type: provider.type,
72
+ name: provider.displayName || provider.type,
73
+ displayName: provider.displayName || provider.type,
74
+ icon: provider.icon || '💻',
75
+ category: provider.category,
76
+ }));
77
+ }
78
+
79
+ export function buildStatusSnapshot(options: StatusSnapshotOptions): StatusSnapshot {
80
+ const cfg = loadConfig();
81
+ const wsState = getWorkspaceState(cfg);
82
+ const memSnap = getHostMemorySnapshot();
83
+ const { managedIdes, managedClis, managedAcps } = buildAllManagedEntries(
84
+ options.allStates,
85
+ options.cdpManagers as Map<string, any>,
86
+ {
87
+ detectedIdes: options.detectedIdes.map((ide) => ({
88
+ id: ide.id,
89
+ installed: ide.installed !== false,
90
+ })),
91
+ },
92
+ );
93
+
94
+ return {
95
+ instanceId: options.instanceId,
96
+ version: options.version,
97
+ daemonMode: options.daemonMode,
98
+ machine: {
99
+ hostname: os.hostname(),
100
+ platform: os.platform(),
101
+ arch: os.arch(),
102
+ cpus: os.cpus().length,
103
+ totalMem: memSnap.totalMem,
104
+ freeMem: memSnap.freeMem,
105
+ availableMem: memSnap.availableMem,
106
+ loadavg: os.loadavg(),
107
+ uptime: os.uptime(),
108
+ release: os.release(),
109
+ },
110
+ machineNickname: options.machineNickname ?? cfg.machineNickname ?? null,
111
+ timestamp: options.timestamp ?? Date.now(),
112
+ detectedIdes: buildDetectedIdeInfos(options.detectedIdes, options.cdpManagers),
113
+ ...(options.p2p ? { p2p: options.p2p } : {}),
114
+ managedIdes,
115
+ managedClis,
116
+ managedAcps,
117
+ workspaces: wsState.workspaces,
118
+ defaultWorkspaceId: wsState.defaultWorkspaceId,
119
+ defaultWorkspacePath: wsState.defaultWorkspacePath,
120
+ workspaceActivity: getWorkspaceActivity(cfg, 15),
121
+ availableProviders: buildAvailableProviders(options.providerLoader),
122
+ };
123
+ }
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ADHDev Daemon Core — Shared Types
3
3
  *
4
- * Shared types referenced by daemon-core, daemon-standalone, daemon-cloud, web-core.
4
+ * Shared types referenced by daemon-core, daemon-standalone, and web-core.
5
5
  * When modifying this file, also update interface contracts in AGENT_PROTOCOL.md.
6
6
  */
7
7
  import type { StatusReportPayload } from './shared-types.js';