@adhdev/daemon-core 0.6.68 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.6.68",
3
+ "version": "0.6.69",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Shared helper for forwarding agent stream snapshots into the IDE instance.
3
+ *
4
+ * Both cloud and standalone daemons use the same InstanceManager wiring.
5
+ */
6
+
7
+ export function forwardAgentStreamsToIdeInstance(
8
+ instanceManager: { getInstance: (key: string) => any },
9
+ ideType: string,
10
+ streams: any[],
11
+ ): void {
12
+ const ideInstance = instanceManager.getInstance(`ide:${ideType}`) as
13
+ | { onEvent?: (event: string, payload: Record<string, unknown>) => void }
14
+ | undefined;
15
+
16
+ if (!ideInstance?.onEvent) return;
17
+
18
+ for (const stream of streams) {
19
+ ideInstance.onEvent('stream_update', {
20
+ extensionType: stream.agentType,
21
+ streams: [stream],
22
+ messages: stream.messages || [],
23
+ status: stream.status || 'idle',
24
+ activeModal: stream.activeModal || null,
25
+ model: stream.model || undefined,
26
+ mode: stream.mode || undefined,
27
+ });
28
+ }
29
+ }
package/src/index.ts CHANGED
@@ -75,6 +75,8 @@ export type { CommandRouterDeps, CommandRouterResult } from './commands/router.j
75
75
  // ── Status ──
76
76
  export { DaemonStatusReporter } from './status/reporter.js';
77
77
  export { buildManagedIdes, buildManagedClis, buildManagedAcps, buildAllManagedEntries, findCdpManager, hasCdpManager, isCdpConnected } from './status/builders.js';
78
+ export { buildStatusSnapshot } from './status/snapshot.js';
79
+ export type { StatusSnapshotOptions, StatusSnapshot } from './status/snapshot.js';
78
80
 
79
81
  // ── Logger ──
80
82
  export { LOG, installGlobalInterceptor, setLogLevel, getLogLevel, getRecentLogs } from './logging/logger.js';
@@ -97,6 +99,7 @@ export { readChatHistory } from './config/chat-history.js';
97
99
  export { DaemonAgentStreamManager } from './agent-stream/index.js';
98
100
  export { AgentStreamPoller } from './agent-stream/index.js';
99
101
  export type { AgentStreamPollerDeps } from './agent-stream/index.js';
102
+ export { forwardAgentStreamsToIdeInstance } from './agent-stream/forward.js';
100
103
 
101
104
  // ── Providers ──
102
105
  export { ProviderLoader } from './providers/provider-loader.js';
@@ -122,4 +125,3 @@ export type { ExtensionInfo as InstallerExtensionInfo } from './installer.js';
122
125
  // ── Boot / Lifecycle ──
123
126
  export { initDaemonComponents, shutdownDaemonComponents } from './boot/daemon-lifecycle.js';
124
127
  export type { DaemonInitConfig, DaemonComponents } from './boot/daemon-lifecycle.js';
125
-
@@ -5,14 +5,9 @@
5
5
  * Each Instance manages its own status/transition. This module only assembles + transmits.
6
6
  */
7
7
 
8
- import * as os from 'os';
9
- import * as path from 'path';
10
- import { loadConfig } from '../config/config.js';
11
- import { getWorkspaceState } from '../config/workspaces.js';
12
- import { getHostMemorySnapshot } from '../system/host-memory.js';
13
- import { getWorkspaceActivity } from '../config/workspace-activity.js';
14
8
  import { LOG } from '../logging/logger.js';
15
9
  import { buildAllManagedEntries } from './builders.js';
10
+ import { buildStatusSnapshot } from './snapshot.js';
16
11
  import type {
17
12
  ProviderState,
18
13
  IdeProviderState,
@@ -27,9 +22,8 @@ export interface StatusReporterDeps {
27
22
  cdpManagers: Map<string, { isConnected: boolean }>;
28
23
  p2p: { isConnected: boolean; isAvailable: boolean; connectionState: string; connectedPeerCount: number; screenshotActive: boolean; sendStatus(data: any): void } | null;
29
24
  providerLoader: { resolve(type: string): any; getAll(): any[] };
30
- adapters: Map<string, { cliType: string; cliName: string; workingDir: string; getStatus(): any; getPartialResponse(): string }>;
31
25
  detectedIdes: any[];
32
- ideType: string;
26
+ instanceId: string;
33
27
  daemonVersion?: string;
34
28
  instanceManager: { collectAllStates(): ProviderState[]; collectStatesByCategory(cat: string): ProviderState[] };
35
29
  getScreenshotUsage?: () => { dailyUsedMinutes: number; dailyBudgetMinutes: number; budgetExhausted: boolean } | null;
@@ -163,50 +157,26 @@ export class DaemonStatusReporter {
163
157
  this.deps.cdpManagers as Map<string, any>,
164
158
  );
165
159
 
166
-
167
-
168
-
169
-
170
- const cfg = loadConfig();
171
- const wsState = getWorkspaceState(cfg);
172
- const memSnap = getHostMemorySnapshot();
173
-
174
160
  // ═══ Assemble payload (P2P — required data only) ═══
175
161
  const payload: Record<string, any> = {
176
- daemonMode: true,
177
- version: this.deps.daemonVersion || 'unknown',
178
- workspaces: wsState.workspaces,
179
- defaultWorkspaceId: wsState.defaultWorkspaceId,
180
- defaultWorkspacePath: wsState.defaultWorkspacePath,
181
- workspaceActivity: getWorkspaceActivity(cfg, 15),
182
- machine: {
183
- hostname: os.hostname(),
184
- platform: os.platform(),
185
- arch: os.arch(),
186
- cpus: os.cpus().length,
187
- totalMem: memSnap.totalMem,
188
- freeMem: memSnap.freeMem,
189
- availableMem: memSnap.availableMem,
190
- loadavg: os.loadavg(),
191
- uptime: os.uptime(),
192
- },
193
- managedIdes,
194
- managedClis,
195
- managedAcps,
196
- p2p: {
197
- available: p2p?.isAvailable || false,
198
- state: p2p?.connectionState || 'unavailable',
199
- peers: p2p?.connectedPeerCount || 0,
200
- screenshotActive: p2p?.screenshotActive || false,
201
- },
162
+ ...buildStatusSnapshot({
163
+ allStates,
164
+ cdpManagers: this.deps.cdpManagers as Map<string, unknown>,
165
+ providerLoader: this.deps.providerLoader,
166
+ detectedIdes: this.deps.detectedIdes || [],
167
+ instanceId: this.deps.instanceId,
168
+ version: this.deps.daemonVersion || 'unknown',
169
+ daemonMode: true,
170
+ timestamp: now,
171
+ p2p: {
172
+ available: p2p?.isAvailable || false,
173
+ state: p2p?.connectionState || 'unavailable',
174
+ peers: p2p?.connectedPeerCount || 0,
175
+ screenshotActive: p2p?.screenshotActive || false,
176
+ },
177
+ }),
202
178
  screenshotUsage: this.deps.getScreenshotUsage?.() || null,
203
179
  connectedExtensions: [],
204
- detectedIdes: this.deps.detectedIdes || [],
205
- availableProviders: this.deps.providerLoader.getAll().map((p: any) => ({
206
- type: p.type, icon: p.icon || '💻', displayName: p.displayName || p.type,
207
- category: p.category,
208
- })),
209
- timestamp: now,
210
180
  };
211
181
 
212
182
  // ═══ P2P transmit ═══
@@ -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
+ }