@adhdev/daemon-core 0.5.8 → 0.5.17

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,203 @@
1
+ /**
2
+ * ADHDev Shared Types — Cross-package type definitions
3
+ *
4
+ * Types used across daemon-core, web-core, web-cloud, server, etc.
5
+ * Import via: import type { ... } from '@adhdev/daemon-core/types'
6
+ *
7
+ * IMPORTANT: This file must remain runtime-free (types only).
8
+ * Cloudflare Workers (server) can import type-only modules safely.
9
+ */
10
+
11
+ import type {
12
+ StatusResponse,
13
+ ChatMessage,
14
+ ExtensionInfo,
15
+ SystemInfo,
16
+ DetectedIde,
17
+ AgentEntry,
18
+ } from './types.js';
19
+
20
+ export type {
21
+ StatusResponse,
22
+ ChatMessage,
23
+ ExtensionInfo,
24
+ SystemInfo,
25
+ DetectedIde,
26
+ AgentEntry,
27
+ };
28
+
29
+ // Re-export provider types (except ProviderErrorReason which is defined below)
30
+ export type {
31
+ ProviderState,
32
+ ProviderStatus,
33
+ ActiveChatData,
34
+ IdeProviderState,
35
+ CliProviderState,
36
+ AcpProviderState,
37
+ ExtensionProviderState,
38
+ ProviderEvent,
39
+ } from './providers/provider-instance.js';
40
+
41
+ // Re-export ProviderErrorReason (defined in this file, imported by provider-instance)
42
+ export type { ProviderErrorReason } from './providers/provider-instance.js';
43
+
44
+ // Local import for use in Managed*Entry types below
45
+ import type { ActiveChatData as _ActiveChatData } from './providers/provider-instance.js';
46
+ import type { WorkspaceEntry } from './config/workspaces.js';
47
+
48
+ // Re-export WorkspaceEntry for downstream consumers
49
+ export type { WorkspaceEntry } from './config/workspaces.js';
50
+
51
+ // ─── Managed Entry Types (reporter → server/web) ────────────────────
52
+ // These define the shape of data sent by DaemonStatusReporter
53
+ // and consumed by web-core, web-cloud, and server.
54
+
55
+ /** IDE entry as reported by daemon to server/dashboard */
56
+ export interface ManagedIdeEntry {
57
+ ideType: string;
58
+ ideVersion: string;
59
+ instanceId: string;
60
+ workspace: string | null;
61
+ terminals: number;
62
+ aiAgents: unknown[];
63
+ activeChat: _ActiveChatData | null;
64
+ chats: unknown[];
65
+ agentStreams: ManagedAgentStream[];
66
+ cdpConnected: boolean;
67
+ currentModel?: string;
68
+ currentPlan?: string;
69
+ currentAutoApprove?: string;
70
+ }
71
+
72
+ /** CLI entry as reported by daemon to server/dashboard */
73
+ export interface ManagedCliEntry {
74
+ id: string;
75
+ instanceId: string;
76
+ cliType: string;
77
+ cliName: string;
78
+ status: string;
79
+ mode: 'terminal' | 'chat';
80
+ workspace: string;
81
+ activeChat: _ActiveChatData | null;
82
+ }
83
+
84
+ /** ACP entry as reported by daemon to server/dashboard */
85
+ export interface ManagedAcpEntry {
86
+ id: string;
87
+ acpType: string;
88
+ acpName: string;
89
+ status: string;
90
+ mode: 'chat';
91
+ workspace: string;
92
+ activeChat: _ActiveChatData | null;
93
+ currentModel?: string;
94
+ currentPlan?: string;
95
+ acpConfigOptions?: AcpConfigOption[];
96
+ acpModes?: AcpMode[];
97
+ /** Error details */
98
+ errorMessage?: string;
99
+ errorReason?: 'not_installed' | 'auth_failed' | 'spawn_error' | 'init_failed' | 'crash' | 'timeout' | 'cdp_error' | 'disconnected';
100
+ }
101
+
102
+ /** Agent stream within an IDE (extension status) */
103
+ export interface ManagedAgentStream {
104
+ agentType: string;
105
+ agentName: string;
106
+ extensionId: string;
107
+ status: string;
108
+ messages: ChatMessage[];
109
+ inputContent: string;
110
+ model?: string;
111
+ activeModal: { message: string; buttons: string[] } | null;
112
+ }
113
+
114
+ /** Available provider information */
115
+ export interface AvailableProviderInfo {
116
+ type: string;
117
+ name: string;
118
+ category: 'ide' | 'extension' | 'cli' | 'acp';
119
+ displayName: string;
120
+ icon: string;
121
+ }
122
+
123
+ /** ACP config option (model/mode/thought_level selection) */
124
+ export interface AcpConfigOption {
125
+ category: 'model' | 'mode' | 'thought_level' | 'other';
126
+ configId: string;
127
+ currentValue?: string;
128
+ options: { value: string; name: string; description?: string; group?: string }[];
129
+ }
130
+
131
+ /** ACP mode */
132
+ export interface AcpMode {
133
+ id: string;
134
+ name: string;
135
+ description?: string;
136
+ }
137
+
138
+ // ─── Common Sub-Types (used across StatusReportPayload, BaseDaemonData, etc.) ──
139
+
140
+ /** Machine hardware/OS info (reported by daemon, displayed by web) */
141
+ export interface MachineInfo {
142
+ hostname: string;
143
+ platform: string;
144
+ arch: string;
145
+ cpus: number;
146
+ totalMem: number;
147
+ freeMem: number;
148
+ /** macOS: reclaimable-inclusive; prefer for UI used% */
149
+ availableMem?: number;
150
+ loadavg: number[];
151
+ uptime: number;
152
+ release: string;
153
+ }
154
+
155
+ /** Detected IDE on a machine */
156
+ export interface DetectedIdeInfo {
157
+ type: string;
158
+ id?: string;
159
+ name: string;
160
+ running: boolean;
161
+ path?: string;
162
+ }
163
+
164
+ /** Workspace recent activity */
165
+ export interface WorkspaceActivity {
166
+ path: string;
167
+ lastUsedAt: number;
168
+ kind?: string;
169
+ agentType?: string;
170
+ }
171
+
172
+ // ─── Status Report Payload (daemon → server) ────────────────────────
173
+ // Full payload shape sent via WebSocket status_report
174
+
175
+ export interface StatusReportPayload {
176
+ /** Daemon instance ID */
177
+ instanceId: string;
178
+ /** Daemon version */
179
+ version: string;
180
+ /** Daemon mode flag */
181
+ daemonMode: boolean;
182
+ /** Machine info */
183
+ machine: MachineInfo;
184
+ /** Machine nickname (user-set) */
185
+ machineNickname?: string | null;
186
+ /** Timestamp */
187
+ timestamp: number;
188
+ /** Detected IDEs on this machine */
189
+ detectedIdes: DetectedIdeInfo[];
190
+ /** P2P state */
191
+ p2p?: { available: boolean; state: string; peers: number; screenshotActive?: boolean };
192
+ /** Managed IDE instances */
193
+ managedIdes: ManagedIdeEntry[];
194
+ /** Managed CLI instances */
195
+ managedClis: ManagedCliEntry[];
196
+ /** Managed ACP instances */
197
+ managedAcps: ManagedAcpEntry[];
198
+ /** Saved workspaces */
199
+ workspaces?: WorkspaceEntry[];
200
+ defaultWorkspaceId?: string | null;
201
+ defaultWorkspacePath?: string | null;
202
+ workspaceActivity?: WorkspaceActivity[];
203
+ }
@@ -12,6 +12,14 @@ import { getWorkspaceState } from '../config/workspaces.js';
12
12
  import { getHostMemorySnapshot } from '../system/host-memory.js';
13
13
  import { getWorkspaceActivity } from '../config/workspace-activity.js';
14
14
  import { LOG } from '../logging/logger.js';
15
+ import type { ManagedIdeEntry, ManagedCliEntry, ManagedAcpEntry } from '../shared-types.js';
16
+ import type {
17
+ ProviderState,
18
+ IdeProviderState,
19
+ CliProviderState,
20
+ AcpProviderState,
21
+ ExtensionProviderState,
22
+ } from '../providers/provider-instance.js';
15
23
 
16
24
  // ─── Daemon dependency interface ──────────────────────
17
25
 
@@ -23,7 +31,8 @@ export interface StatusReporterDeps {
23
31
  adapters: Map<string, { cliType: string; cliName: string; workingDir: string; getStatus(): any; getPartialResponse(): string }>;
24
32
  detectedIdes: any[];
25
33
  ideType: string;
26
- instanceManager: { collectAllStates(): any[]; collectStatesByCategory(cat: string): any[] };
34
+ daemonVersion?: string;
35
+ instanceManager: { collectAllStates(): ProviderState[]; collectStatesByCategory(cat: string): ProviderState[] };
27
36
  }
28
37
 
29
38
  export class DaemonStatusReporter {
@@ -117,21 +126,21 @@ export class DaemonStatusReporter {
117
126
  const target = opts?.p2pOnly ? 'P2P' : 'P2P+Server';
118
127
 
119
128
  const allStates = this.deps.instanceManager.collectAllStates();
120
- const ideStates = allStates.filter((s: any) => s.category === 'ide');
121
- const cliStates = allStates.filter((s: any) => s.category === 'cli');
122
- const acpStates = allStates.filter((s: any) => s.category === 'acp');
129
+ const ideStates = allStates.filter((s): s is IdeProviderState => s.category === 'ide');
130
+ const cliStates = allStates.filter((s): s is CliProviderState => s.category === 'cli');
131
+ const acpStates = allStates.filter((s): s is AcpProviderState => s.category === 'acp');
123
132
 
124
133
  // IDE summary
125
- const ideSummary = ideStates.map((s: any) => {
134
+ const ideSummary = ideStates.map((s) => {
126
135
  const msgs = s.activeChat?.messages?.length || 0;
127
- const exts = (s.extensions || []).length;
136
+ const exts = s.extensions.length;
128
137
  return `${s.type}(${s.status},${msgs}msg,${exts}ext${s.currentModel ? ',model=' + s.currentModel : ''})`;
129
138
  }).join(', ');
130
139
 
131
140
  // CLI summary
132
- const cliSummary = cliStates.map((s: any) => `${s.type}(${s.status})`).join(', ');
141
+ const cliSummary = cliStates.map((s) => `${s.type}(${s.status})`).join(', ');
133
142
  // ACP summary
134
- const acpSummary = acpStates.map((s: any) => `${s.type}(${s.status})`).join(', ');
143
+ const acpSummary = acpStates.map((s) => `${s.type}(${s.status})`).join(', ');
135
144
 
136
145
  // P2P-only = 5s heartbeat → DEBUG, P2P+Server = 30s interval → INFO
137
146
  const logLevel = opts?.p2pOnly ? 'debug' : 'info';
@@ -148,17 +157,16 @@ export class DaemonStatusReporter {
148
157
  }
149
158
 
150
159
  // IDE states → managedIdes
151
- const managedIdes: any[] = ideStates.map((s: any) => ({
160
+ const managedIdes: ManagedIdeEntry[] = ideStates.map((s) => ({
152
161
  ideType: s.type,
153
162
  ideVersion: '',
154
163
  instanceId: s.instanceId,
155
- workspaceFolders: s.workspaceFolders || [],
156
- activeFile: s.activeFile || null,
164
+ workspace: s.workspace || null,
157
165
  terminals: 0,
158
166
  aiAgents: [],
159
167
  activeChat: s.activeChat,
160
168
  chats: [],
161
- agentStreams: (s.extensions || []).map((ext: any) => ({
169
+ agentStreams: s.extensions.map((ext) => ({
162
170
  agentType: ext.type,
163
171
  agentName: ext.name,
164
172
  extensionId: ext.type,
@@ -167,7 +175,7 @@ export class DaemonStatusReporter {
167
175
  inputContent: ext.activeChat?.inputContent || '',
168
176
  activeModal: ext.activeChat?.activeModal || null,
169
177
  })),
170
- cdpConnected: s.cdpConnected || false,
178
+ cdpConnected: s.cdpConnected,
171
179
  currentModel: s.currentModel,
172
180
  currentPlan: s.currentPlan,
173
181
  currentAutoApprove: s.currentAutoApprove,
@@ -177,30 +185,32 @@ export class DaemonStatusReporter {
177
185
 
178
186
 
179
187
  // CLI states → managedClis
180
- const managedClis: any[] = cliStates.map((s: any) => ({
188
+ const managedClis: ManagedCliEntry[] = cliStates.map((s) => ({
181
189
  id: s.instanceId,
182
190
  instanceId: s.instanceId,
183
191
  cliType: s.type,
184
192
  cliName: s.name,
185
193
  status: s.status,
186
- mode: s.mode || 'terminal',
187
- workingDir: s.workingDir || '',
194
+ mode: s.mode,
195
+ workspace: s.workspace || '',
188
196
  activeChat: s.activeChat,
189
197
  }));
190
198
 
191
- // ACP states → managedAcps (separated into per-type arrays)
192
- const managedAcps: any[] = acpStates.map((s: any) => ({
199
+ // ACP states → managedAcps
200
+ const managedAcps: ManagedAcpEntry[] = acpStates.map((s) => ({
193
201
  id: s.instanceId,
194
202
  acpType: s.type,
195
203
  acpName: s.name,
196
204
  status: s.status,
197
- mode: 'chat',
198
- workingDir: s.workingDir || '',
205
+ mode: s.mode,
206
+ workspace: s.workspace || '',
199
207
  activeChat: s.activeChat,
200
208
  currentModel: s.currentModel,
201
209
  currentPlan: s.currentPlan,
202
210
  acpConfigOptions: s.acpConfigOptions,
203
211
  acpModes: s.acpModes,
212
+ errorMessage: s.errorMessage,
213
+ errorReason: s.errorReason,
204
214
  }));
205
215
 
206
216
 
@@ -212,6 +222,7 @@ export class DaemonStatusReporter {
212
222
  // ═══ Assemble payload (P2P — required data only) ═══
213
223
  const payload: Record<string, any> = {
214
224
  daemonMode: true,
225
+ version: this.deps.daemonVersion || 'unknown',
215
226
  machineNickname: cfg.machineNickname || null,
216
227
  workspaces: wsState.workspaces,
217
228
  defaultWorkspaceId: wsState.defaultWorkspaceId,
@@ -237,7 +248,6 @@ export class DaemonStatusReporter {
237
248
  peers: p2p?.connectedPeerCount || 0,
238
249
  screenshotActive: p2p?.screenshotActive || false,
239
250
  },
240
- cdpConnected: [...cdpManagers.values()].some(c => c.isConnected),
241
251
  connectedExtensions: [],
242
252
  detectedIdes: this.deps.detectedIdes || [],
243
253
  availableProviders: this.deps.providerLoader.getAll().map((p: any) => ({
@@ -277,7 +287,6 @@ export class DaemonStatusReporter {
277
287
  id: a.id, acpType: a.acpType, acpName: a.acpName,
278
288
  })),
279
289
  p2p: payload.p2p,
280
- cdpConnected: payload.cdpConnected,
281
290
  timestamp: now,
282
291
  };
283
292
  serverConn.sendMessage('status_report', wsPayload);
package/src/types.ts CHANGED
@@ -4,99 +4,45 @@
4
4
  * Shared types referenced by daemon-core, daemon-standalone, daemon-cloud, web-core.
5
5
  * When modifying this file, also update interface contracts in AGENT_PROTOCOL.md.
6
6
  */
7
+ import type { ManagedIdeEntry, ManagedCliEntry, ManagedAcpEntry, WorkspaceEntry, WorkspaceActivity, StatusReportPayload } from './shared-types.js';
7
8
 
8
9
  // ── Daemon Status ──
9
10
 
10
- export interface DaemonStatus {
11
- id: string;
12
- type: string;
13
- platform?: string;
14
- hostname?: string;
15
- nickname?: string;
16
- cdpConnected?: boolean;
17
- timestamp: number;
18
- ides: IdeEntry[];
19
- clis: CliEntry[];
20
- acps?: AcpEntry[];
21
- }
22
-
23
- // ── IDE Entry ──
24
-
25
- export interface IdeEntry {
26
- /** Format: "{daemonId}:ide:{instanceId}" */
27
- id: string;
28
- instanceId: string;
29
- /** IDE type: "cursor", "windsurf", "vscode", etc. */
30
- type: string;
31
- name?: string;
32
- cdpConnected?: boolean;
33
- cdpPort?: number;
34
- /** Current chat messages (live) */
35
- chats?: ChatMessage[];
36
- /** Active chat session */
37
- activeChat?: Record<string, unknown> | null;
38
- /** Chat history (legacy) */
39
- chatHistory?: unknown[];
40
- /** Agent status: 'idle' | 'working' */
41
- agentStatus?: string;
42
- /** Agent streams from extensions */
43
- agentStreams?: AgentStreamEntry[];
44
- /** Extension agents monitored via CDP */
45
- extensions?: ExtensionInfo[];
46
- /** IDE-reported workspace roots (name + path) */
47
- workspaceFolders?: { name: string; path: string }[];
48
- /** Active file path */
49
- activeFile?: string | null;
50
- /** Current AI model */
51
- currentModel?: string;
52
- /** Current AI mode/plan */
53
- currentPlan?: string;
54
- /** Managed agents list */
55
- agents?: unknown[];
56
- }
57
-
58
- // ── CLI Entry ──
59
-
60
- export interface CliEntry {
61
- /** Format: "{daemonId}:cli:{cliId}" */
62
- id: string;
63
- cliId: string;
64
- /** CLI type: "gemini-cli", "claude-code", "codex-cli", etc. */
65
- type: string;
66
- name?: string;
67
- /** Whether the CLI process is running */
68
- isRunning?: boolean;
69
- /** Active session info */
70
- sessionId?: string;
71
- }
72
-
73
- // ── ACP Entry ──
74
-
75
- export interface AcpEntry {
76
- /** Format: "{daemonId}:acp:{acpId}" */
77
- id: string;
78
- acpId: string;
79
- /** Agent type: "gemini-acp", "cline-acp", etc. */
80
- type: string;
81
- name?: string;
82
- /** Process running state */
83
- isRunning?: boolean;
84
- /** Error state */
85
- errorReason?: string;
86
- errorMessage?: string;
11
+ /** Full status response from /api/v1/status and WS events */
12
+ export interface StatusResponse extends StatusReportPayload {
13
+ /** For standalone API compat */
14
+ id: string; // standalone specific
15
+ type: string; // usually 'standalone'
16
+ platform: string;
17
+ hostname: string;
18
+ /** User display name from config */
19
+ userName?: string;
20
+ /** Available providers */
21
+ availableProviders: ProviderInfo[];
22
+ /** System info (legacy compat) */
23
+ system?: SystemInfo;
87
24
  }
88
25
 
89
26
  // ── Chat Message ──
90
27
 
91
28
  export interface ChatMessage {
92
- role: string; // 'user' | 'assistant' | 'human' | 'system'
29
+ role: string; // 'user' | 'assistant' | 'system' | 'human'
93
30
  /** Plain text (legacy) or rich content blocks (ACP standard) */
94
31
  content: string | ContentBlock[];
95
- kind?: string; // 'standard' | 'thought' | 'tool' | 'system'
32
+ kind?: string; // 'standard' | 'thought' | 'tool' | 'terminal' | 'system'
96
33
  id?: string;
34
+ index?: number;
97
35
  timestamp?: number;
36
+ receivedAt?: number;
98
37
  /** Tool calls associated with this message */
99
38
  toolCalls?: ToolCallInfo[];
39
+ /** Optional: fiber metadata */
40
+ _type?: string;
41
+ _sub?: string;
42
+ /** Meta information for thought/terminal logs etc */
43
+ meta?: { label?: string; isRunning?: boolean } | Record<string, any>;
44
+ /** Sender name for shared sessions */
45
+ senderName?: string;
100
46
  }
101
47
 
102
48
  // Re-export from contracts for convenience
@@ -138,7 +84,7 @@ export interface ProviderConfig {
138
84
  // ── Event Types ──
139
85
 
140
86
  export type DaemonEvent =
141
- | { type: 'status'; data: DaemonStatus }
87
+ | { type: 'status'; data: StatusResponse }
142
88
  | { type: 'chat_update'; data: { ideId: string; messages: ChatMessage[] } }
143
89
  | { type: 'screenshot'; data: { ideId: string; base64: string } }
144
90
  | { type: 'action_log'; data: { ideId: string; text: string; timestamp: number } }
@@ -172,36 +118,6 @@ export interface ProviderInfo {
172
118
  category: string;
173
119
  }
174
120
 
175
- /** Full status response from /api/v1/status */
176
- export interface StatusResponse {
177
- id: string;
178
- type: string;
179
- platform: string;
180
- hostname: string;
181
- timestamp: number;
182
- ides: IdeEntry[];
183
- clis: CliEntry[];
184
- cdpConnected: boolean;
185
- detectedIdes: DetectedIde[];
186
- availableProviders: ProviderInfo[];
187
- system: SystemInfo;
188
- /** Saved workspaces (standalone WS / HTTP status) */
189
- workspaces?: { id: string; path: string; label?: string; addedAt: number }[];
190
- defaultWorkspaceId?: string | null;
191
- defaultWorkspacePath?: string | null;
192
- workspaceActivity?: { path: string; lastUsedAt: number; kind?: string; agentType?: string }[];
193
- }
194
-
195
- /** Agent stream entry within an IDE */
196
- export interface AgentStreamEntry {
197
- agentType: string;
198
- agentName: string;
199
- extensionId: string;
200
- status: string;
201
- messages: unknown[];
202
- inputContent: string;
203
- activeModal: { message: string; buttons: string[] } | null;
204
- }
205
121
 
206
122
  /** Flattened agent entry from /api/v1/agents */
207
123
  export interface AgentEntry {