@adhdev/daemon-core 0.8.33 → 0.8.35
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/dist/index.d.ts +1 -1
- package/dist/index.js +127 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -102
- package/dist/index.mjs.map +1 -1
- package/dist/shared-types.d.ts +38 -0
- package/dist/status/reporter.d.ts +3 -0
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/agent-stream/forward.d.ts +8 -0
- package/src/agent-stream/index.d.ts +6 -0
- package/src/agent-stream/manager.d.ts +60 -0
- package/src/agent-stream/poller.d.ts +41 -0
- package/src/agent-stream/provider-adapter.d.ts +36 -0
- package/src/agent-stream/types.d.ts +68 -0
- package/src/boot/daemon-lifecycle.d.ts +100 -0
- package/src/cdp/devtools.d.ts +51 -0
- package/src/cdp/initializer.d.ts +50 -0
- package/src/cdp/manager.d.ts +147 -0
- package/src/cdp/scanner.d.ts +58 -0
- package/src/cdp/setup.d.ts +58 -0
- package/src/cli-adapter-types.d.ts +57 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +177 -0
- package/src/cli-adapters/provider-cli-adapter.ts +115 -91
- package/src/cli-adapters/provider-cli-config.d.ts +30 -0
- package/src/cli-adapters/provider-cli-parse.d.ts +42 -0
- package/src/cli-adapters/provider-cli-runtime.d.ts +29 -0
- package/src/cli-adapters/provider-cli-shared.d.ts +158 -0
- package/src/cli-adapters/pty-transport.d.ts +48 -0
- package/src/cli-adapters/session-host-transport.d.ts +20 -0
- package/src/cli-adapters/spawn-env.d.ts +8 -0
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +16 -0
- package/src/cli-adapters/terminal-backends/types.d.ts +18 -0
- package/src/cli-adapters/terminal-backends/xterm-backend.d.ts +17 -0
- package/src/cli-adapters/terminal-screen.d.ts +33 -0
- package/src/commands/cdp-commands.d.ts +15 -0
- package/src/commands/chat-commands.d.ts +15 -0
- package/src/commands/cli-manager.d.ts +94 -0
- package/src/commands/handler.d.ts +103 -0
- package/src/commands/router.d.ts +98 -0
- package/src/commands/stream-commands.d.ts +14 -0
- package/src/commands/upgrade-helper.d.ts +10 -0
- package/src/commands/workspace-commands.d.ts +11 -0
- package/src/config/chat-history.d.ts +99 -0
- package/src/config/config.d.ts +14 -0
- package/src/config/recent-activity.d.ts +29 -0
- package/src/config/saved-sessions.d.ts +22 -0
- package/src/config/state-store.d.ts +32 -0
- package/src/config/workspaces.d.ts +0 -1
- package/src/daemon/dev-auto-implement.d.ts +43 -0
- package/src/daemon/dev-cdp-handlers.d.ts +22 -0
- package/src/daemon/dev-cli-debug.d.ts +106 -0
- package/src/daemon/dev-server-types.d.ts +43 -0
- package/src/daemon/dev-server.d.ts +140 -0
- package/src/daemon/scaffold-template.d.ts +32 -0
- package/src/daemon-core.d.ts +36 -0
- package/src/detection/cli-detector.d.ts +31 -0
- package/src/detection/ide-detector.d.ts +35 -0
- package/src/index.d.ts +83 -0
- package/src/index.ts +2 -0
- package/src/installer.d.ts +50 -0
- package/src/ipc-protocol.d.ts +111 -0
- package/src/launch.d.ts +46 -0
- package/src/logging/command-log.d.ts +31 -0
- package/src/logging/logger.d.ts +89 -0
- package/src/providers/acp-provider-instance.d.ts +102 -0
- package/src/providers/approval-utils.d.ts +7 -0
- package/src/providers/cli-provider-instance.d.ts +86 -0
- package/src/providers/contracts.d.ts +193 -1
- package/src/providers/control-effects.d.ts +4 -0
- package/src/providers/extension-provider-instance.d.ts +61 -0
- package/src/providers/ide-provider-instance.d.ts +70 -0
- package/src/providers/provider-instance-manager.d.ts +84 -0
- package/src/providers/provider-instance.d.ts +7 -1
- package/src/providers/provider-loader.d.ts +299 -0
- package/src/providers/status-monitor.d.ts +48 -0
- package/src/providers/version-archive.d.ts +52 -0
- package/src/session-host/runtime-support.d.ts +8 -0
- package/src/sessions/reconcile.d.ts +22 -0
- package/src/sessions/registry.d.ts +24 -0
- package/src/shared-types-extra.d.ts +29 -0
- package/src/shared-types.d.ts +79 -22
- package/src/shared-types.ts +40 -0
- package/src/status/builders.d.ts +33 -0
- package/src/status/reporter.d.ts +69 -0
- package/src/status/reporter.ts +16 -13
- package/src/status/snapshot.d.ts +58 -0
- package/src/system/host-memory.d.ts +19 -0
- package/src/types.d.ts +3 -7
package/dist/shared-types.d.ts
CHANGED
|
@@ -77,6 +77,25 @@ export interface SessionEntry {
|
|
|
77
77
|
inboxBucket?: RecentSessionBucket;
|
|
78
78
|
surfaceHidden?: boolean;
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Compact session metadata stored in UserSessionDO and reused by server-side
|
|
82
|
+
* status/convenience APIs. This intentionally excludes rich UI-only fields.
|
|
83
|
+
*/
|
|
84
|
+
export interface CompactSessionEntry {
|
|
85
|
+
id: string;
|
|
86
|
+
parentId: string | null;
|
|
87
|
+
providerType: string;
|
|
88
|
+
providerName: string;
|
|
89
|
+
kind: SessionKind;
|
|
90
|
+
transport: SessionTransport;
|
|
91
|
+
status: SessionStatus;
|
|
92
|
+
title: string;
|
|
93
|
+
workspace: string | null;
|
|
94
|
+
cdpConnected?: boolean;
|
|
95
|
+
currentModel?: string;
|
|
96
|
+
currentPlan?: string;
|
|
97
|
+
currentAutoApprove?: string;
|
|
98
|
+
}
|
|
80
99
|
/** Available provider information */
|
|
81
100
|
export interface AvailableProviderInfo {
|
|
82
101
|
type: string;
|
|
@@ -176,6 +195,25 @@ export interface RecentLaunchEntry {
|
|
|
176
195
|
currentModel?: string;
|
|
177
196
|
lastLaunchedAt: number;
|
|
178
197
|
}
|
|
198
|
+
/** Compact machine payload broadcast by UserSessionDO to cloud dashboards. */
|
|
199
|
+
export interface CompactDaemonEntry {
|
|
200
|
+
id: string;
|
|
201
|
+
type?: string;
|
|
202
|
+
machineId?: string;
|
|
203
|
+
platform?: string;
|
|
204
|
+
hostname?: string;
|
|
205
|
+
nickname?: string;
|
|
206
|
+
p2p?: StatusReportPayload['p2p'];
|
|
207
|
+
cdpConnected?: boolean;
|
|
208
|
+
timestamp?: number;
|
|
209
|
+
version?: string;
|
|
210
|
+
serverVersion?: string;
|
|
211
|
+
versionMismatch?: boolean;
|
|
212
|
+
terminalBackend?: TerminalBackendStatus;
|
|
213
|
+
detectedIdes?: DetectedIdeInfo[];
|
|
214
|
+
availableProviders?: AvailableProviderInfo[];
|
|
215
|
+
sessions?: CompactSessionEntry[];
|
|
216
|
+
}
|
|
179
217
|
export interface StatusReportPayload {
|
|
180
218
|
/** Unique daemon instance identifier */
|
|
181
219
|
instanceId: string;
|
|
@@ -44,6 +44,7 @@ export declare class DaemonStatusReporter {
|
|
|
44
44
|
private lastStatusSentAt;
|
|
45
45
|
private statusPendingThrottle;
|
|
46
46
|
private lastP2PStatusHash;
|
|
47
|
+
private lastServerStatusHash;
|
|
47
48
|
private lastStatusSummary;
|
|
48
49
|
private statusTimer;
|
|
49
50
|
private p2pTimer;
|
|
@@ -63,6 +64,8 @@ export declare class DaemonStatusReporter {
|
|
|
63
64
|
private summarizeLargePayloadSessions;
|
|
64
65
|
sendUnifiedStatusReport(opts?: {
|
|
65
66
|
p2pOnly?: boolean;
|
|
67
|
+
forceServer?: boolean;
|
|
68
|
+
reason?: string;
|
|
66
69
|
}): Promise<void>;
|
|
67
70
|
private sendP2PPayload;
|
|
68
71
|
private simpleHash;
|
package/package.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
export declare function forwardAgentStreamsToIdeInstance(instanceManager: {
|
|
7
|
+
getInstance: (key: string) => any;
|
|
8
|
+
}, ideType: string, streams: any[]): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DaemonAgentStreamManager } from './manager.js';
|
|
2
|
+
export type { ManagedAgent } from './manager.js';
|
|
3
|
+
export { ProviderStreamAdapter } from './provider-adapter.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export { AgentStreamPoller } from './poller.js';
|
|
6
|
+
export type { AgentStreamPollerDeps } from './poller.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DaemonAgentStreamManager — manage agent streams (ported for Daemon)
|
|
3
|
+
*
|
|
4
|
+
* Agent stream manager for extension data collection.
|
|
5
|
+
* All vscode dependencies removed — pure Node.js environment.
|
|
6
|
+
*
|
|
7
|
+
* Panel focus is delegated to Extension via IPC.
|
|
8
|
+
* CDP session management uses DaemonCdpManager directly.
|
|
9
|
+
*/
|
|
10
|
+
import { DaemonCdpManager, AgentWebviewTarget } from '../cdp/manager.js';
|
|
11
|
+
import { ProviderLoader } from '../providers/provider-loader.js';
|
|
12
|
+
import { SessionRegistry } from '../sessions/registry.js';
|
|
13
|
+
import type { IAgentStreamAdapter, AgentStreamState, AgentChatListItem } from './types.js';
|
|
14
|
+
export interface ManagedAgent {
|
|
15
|
+
adapter: IAgentStreamAdapter;
|
|
16
|
+
runtimeSessionId: string;
|
|
17
|
+
parentSessionId: string;
|
|
18
|
+
cdpSessionId: string;
|
|
19
|
+
target: AgentWebviewTarget;
|
|
20
|
+
lastState: AgentStreamState | null;
|
|
21
|
+
lastError: string | null;
|
|
22
|
+
lastHiddenCheckTime: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class DaemonAgentStreamManager {
|
|
25
|
+
private readonly sessionRegistry?;
|
|
26
|
+
private adaptersByType;
|
|
27
|
+
private managedBySessionId;
|
|
28
|
+
private enabled;
|
|
29
|
+
private logFn;
|
|
30
|
+
private lastDiscoveryTimeByParent;
|
|
31
|
+
private discoveryIntervalMsByParent;
|
|
32
|
+
private activeSessionIdByParent;
|
|
33
|
+
constructor(logFn?: (msg: string) => void, providerLoader?: ProviderLoader, sessionRegistry?: SessionRegistry);
|
|
34
|
+
setEnabled(enabled: boolean): void;
|
|
35
|
+
get isEnabled(): boolean;
|
|
36
|
+
getActiveSessionId(parentSessionId: string): string | null;
|
|
37
|
+
private isRecoverableSessionError;
|
|
38
|
+
private getSessionTarget;
|
|
39
|
+
resetParentSession(parentSessionId: string): void;
|
|
40
|
+
/** Panel focus based on provider.js focusPanel or extensionId (currently no-op) */
|
|
41
|
+
ensureSessionPanelOpen(_sessionId: string): Promise<void>;
|
|
42
|
+
setActiveSession(cdp: DaemonCdpManager, parentSessionId: string, sessionId: string | null): Promise<void>;
|
|
43
|
+
private resolveSessionIdForTarget;
|
|
44
|
+
private getStateError;
|
|
45
|
+
private connectManagedSession;
|
|
46
|
+
/** Agent webview discovery + session connection */
|
|
47
|
+
syncActiveSession(cdp: DaemonCdpManager, parentSessionId: string): Promise<void>;
|
|
48
|
+
/** Collect active extension session state */
|
|
49
|
+
collectActiveSession(cdp: DaemonCdpManager, parentSessionId: string): Promise<AgentStreamState | null>;
|
|
50
|
+
sendToSession(cdp: DaemonCdpManager, sessionId: string, text: string): Promise<boolean>;
|
|
51
|
+
resolveSessionAction(cdp: DaemonCdpManager, sessionId: string, action: 'approve' | 'reject', button?: string): Promise<boolean>;
|
|
52
|
+
newSession(cdp: DaemonCdpManager, sessionId: string): Promise<boolean>;
|
|
53
|
+
listSessionChats(cdp: DaemonCdpManager, sessionId: string): Promise<AgentChatListItem[]>;
|
|
54
|
+
switchConversation(cdp: DaemonCdpManager, sessionId: string, conversationId: string): Promise<boolean>;
|
|
55
|
+
focusSession(cdp: DaemonCdpManager, sessionId: string): Promise<boolean>;
|
|
56
|
+
getConnectedSessions(parentSessionId?: string): string[];
|
|
57
|
+
getManagedSession(sessionId: string): ManagedAgent | undefined;
|
|
58
|
+
dispose(cdpManagers: Map<string, DaemonCdpManager>): Promise<void>;
|
|
59
|
+
resolveSessionForAgent(parentSessionId: string, agentType: string): string | null;
|
|
60
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentStreamPoller — Periodic agent stream polling + extension dynamic management
|
|
3
|
+
*
|
|
4
|
+
* Handles periodic agent stream polling and extension dynamic management.
|
|
5
|
+
*
|
|
6
|
+
* Responsibilities:
|
|
7
|
+
* 1. Refresh extension providers in CDP managers (config changes take effect immediately)
|
|
8
|
+
* 2. Dynamically add/remove IDE instance extensions based on enabled state
|
|
9
|
+
* 3. Sync agent sessions + collect agent streams
|
|
10
|
+
* 4. Auto-discover agents in connected IDEs
|
|
11
|
+
*/
|
|
12
|
+
import type { DaemonCdpManager } from '../cdp/manager.js';
|
|
13
|
+
import type { DaemonAgentStreamManager } from './manager.js';
|
|
14
|
+
import type { ProviderLoader } from '../providers/provider-loader.js';
|
|
15
|
+
import type { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
|
|
16
|
+
import type { SessionRegistry } from '../sessions/registry.js';
|
|
17
|
+
import type { AgentStreamState } from './types.js';
|
|
18
|
+
export interface AgentStreamPollerDeps {
|
|
19
|
+
agentStreamManager: DaemonAgentStreamManager;
|
|
20
|
+
providerLoader: ProviderLoader;
|
|
21
|
+
instanceManager: ProviderInstanceManager;
|
|
22
|
+
cdpManagers: Map<string, DaemonCdpManager>;
|
|
23
|
+
sessionRegistry: SessionRegistry;
|
|
24
|
+
/** Callback when agent streams are updated */
|
|
25
|
+
onStreamsUpdated?: (ideType: string, streams: AgentStreamState[]) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare class AgentStreamPoller {
|
|
28
|
+
private deps;
|
|
29
|
+
private timer;
|
|
30
|
+
constructor(deps: AgentStreamPollerDeps);
|
|
31
|
+
/** Currently active IDE type for agent streaming */
|
|
32
|
+
get activeIde(): string | null;
|
|
33
|
+
/** Reset active IDE tracking (e.g., when IDE is stopped) */
|
|
34
|
+
resetActiveIde(parentSessionId: string): void;
|
|
35
|
+
/** Start polling (idempotent — ignored if already started) */
|
|
36
|
+
start(intervalMs?: number): void;
|
|
37
|
+
/** Stop polling */
|
|
38
|
+
stop(): void;
|
|
39
|
+
/** Single poll tick — can also be called manually */
|
|
40
|
+
private tick;
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProviderStreamAdapter — generic Extension adapter based on provider.js
|
|
3
|
+
*
|
|
4
|
+
* Consolidates ClineAdapter, RooCodeAdapter, ContinueAdapter.
|
|
5
|
+
* Auto-configured using provider.js scripts + metadata.
|
|
6
|
+
*/
|
|
7
|
+
import type { IAgentStreamAdapter, AgentStreamState, AgentChatListItem, AgentEvaluateFn } from './types.js';
|
|
8
|
+
import type { ProviderModule } from '../providers/contracts.js';
|
|
9
|
+
export declare class ProviderStreamAdapter implements IAgentStreamAdapter {
|
|
10
|
+
readonly agentType: string;
|
|
11
|
+
readonly agentName: string;
|
|
12
|
+
readonly extensionId: string;
|
|
13
|
+
readonly extensionIdPattern: RegExp;
|
|
14
|
+
private provider;
|
|
15
|
+
private lastSuccessState;
|
|
16
|
+
constructor(provider: ProviderModule);
|
|
17
|
+
private callScript;
|
|
18
|
+
private hasScript;
|
|
19
|
+
private getStateTitle;
|
|
20
|
+
private parseMaybeJson;
|
|
21
|
+
private summarizeRaw;
|
|
22
|
+
private isTransportError;
|
|
23
|
+
private titlesMatch;
|
|
24
|
+
private messageCount;
|
|
25
|
+
private lastMessageSignature;
|
|
26
|
+
private verifySendOutcome;
|
|
27
|
+
private readStableBaselineState;
|
|
28
|
+
readChat(evaluate: AgentEvaluateFn): Promise<AgentStreamState>;
|
|
29
|
+
sendMessage(evaluate: AgentEvaluateFn, text: string): Promise<void>;
|
|
30
|
+
resolveAction(evaluate: AgentEvaluateFn, action: string, button?: string): Promise<boolean>;
|
|
31
|
+
newSession(evaluate: AgentEvaluateFn): Promise<void>;
|
|
32
|
+
listChats(evaluate: AgentEvaluateFn): Promise<AgentChatListItem[]>;
|
|
33
|
+
switchSession(evaluate: AgentEvaluateFn, sessionId: string): Promise<boolean>;
|
|
34
|
+
focusEditor(evaluate: AgentEvaluateFn): Promise<void>;
|
|
35
|
+
private errorState;
|
|
36
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Stream Types — ported for Daemon (identical to original)
|
|
3
|
+
*
|
|
4
|
+
* Agent stream types.
|
|
5
|
+
* No vscode dependency — can be used as-is.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProviderEffect } from '../providers/contracts.js';
|
|
8
|
+
/** Agent chat message */
|
|
9
|
+
export interface AgentChatMessage {
|
|
10
|
+
role: 'user' | 'assistant' | 'system';
|
|
11
|
+
content: string;
|
|
12
|
+
timestamp?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Agent chat history item */
|
|
15
|
+
export interface AgentChatListItem {
|
|
16
|
+
title: string;
|
|
17
|
+
id: string;
|
|
18
|
+
status?: string;
|
|
19
|
+
time?: string;
|
|
20
|
+
cost?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Agent stream status */
|
|
23
|
+
export interface AgentStreamState {
|
|
24
|
+
agentType: string;
|
|
25
|
+
agentName: string;
|
|
26
|
+
extensionId: string;
|
|
27
|
+
status: 'idle' | 'streaming' | 'waiting_approval' | 'error' | 'disconnected' | 'panel_hidden' | 'not_monitored';
|
|
28
|
+
messages: AgentChatMessage[];
|
|
29
|
+
inputContent: string;
|
|
30
|
+
title?: string;
|
|
31
|
+
/** @deprecated Use controlValues['model'] — kept for backward compatibility */
|
|
32
|
+
model?: string;
|
|
33
|
+
/** @deprecated Use controlValues['mode'] — kept for backward compatibility */
|
|
34
|
+
mode?: string;
|
|
35
|
+
activeModal?: {
|
|
36
|
+
message: string;
|
|
37
|
+
buttons: string[];
|
|
38
|
+
};
|
|
39
|
+
error?: string;
|
|
40
|
+
_error?: string;
|
|
41
|
+
/** Dynamic control current values (populated from readChat + provider controls schema) */
|
|
42
|
+
controlValues?: Record<string, string | number | boolean>;
|
|
43
|
+
/** Provider-driven UI effects from readChat */
|
|
44
|
+
effects?: ProviderEffect[];
|
|
45
|
+
}
|
|
46
|
+
/** Agent webview target info */
|
|
47
|
+
export interface AgentWebviewTarget {
|
|
48
|
+
targetId: string;
|
|
49
|
+
extensionId: string;
|
|
50
|
+
agentType: string;
|
|
51
|
+
url: string;
|
|
52
|
+
}
|
|
53
|
+
/** Agent stream adapter interface */
|
|
54
|
+
export interface IAgentStreamAdapter {
|
|
55
|
+
readonly agentType: string;
|
|
56
|
+
readonly agentName: string;
|
|
57
|
+
readonly extensionId: string;
|
|
58
|
+
readonly extensionIdPattern: RegExp;
|
|
59
|
+
readChat(evaluate: AgentEvaluateFn): Promise<AgentStreamState>;
|
|
60
|
+
sendMessage(evaluate: AgentEvaluateFn, text: string): Promise<void>;
|
|
61
|
+
resolveAction(evaluate: AgentEvaluateFn, action: string, button?: string): Promise<boolean>;
|
|
62
|
+
newSession(evaluate: AgentEvaluateFn): Promise<void>;
|
|
63
|
+
listChats?(evaluate: AgentEvaluateFn): Promise<AgentChatListItem[]>;
|
|
64
|
+
switchSession?(evaluate: AgentEvaluateFn, sessionId: string): Promise<boolean>;
|
|
65
|
+
focusEditor?(evaluate: AgentEvaluateFn): Promise<void>;
|
|
66
|
+
setProvider?(provider: any): void;
|
|
67
|
+
}
|
|
68
|
+
export type AgentEvaluateFn = (expression: string, timeoutMs?: number) => Promise<unknown>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon Lifecycle — Shared init + shutdown logic
|
|
3
|
+
*
|
|
4
|
+
* initDaemonComponents(): Creates all core daemon components in correct order.
|
|
5
|
+
* shutdownDaemonComponents(): Graceful shutdown of all components.
|
|
6
|
+
*
|
|
7
|
+
* Transport-specific setup (ServerConnection, P2P, HTTP/WS) remains in each daemon.
|
|
8
|
+
*/
|
|
9
|
+
import { DaemonCdpManager } from '../cdp/manager.js';
|
|
10
|
+
import { DaemonCdpInitializer } from '../cdp/initializer.js';
|
|
11
|
+
import { DaemonCommandHandler } from '../commands/handler.js';
|
|
12
|
+
import { DaemonCommandRouter } from '../commands/router.js';
|
|
13
|
+
import type { SessionHostControlPlane } from '../commands/router.js';
|
|
14
|
+
import { DaemonCliManager, type CliTransportFactoryParams, type HostedCliRuntimeDescriptor } from '../commands/cli-manager.js';
|
|
15
|
+
import { DaemonAgentStreamManager } from '../agent-stream/manager.js';
|
|
16
|
+
import { AgentStreamPoller } from '../agent-stream/poller.js';
|
|
17
|
+
import { ProviderLoader } from '../providers/provider-loader.js';
|
|
18
|
+
import { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
|
|
19
|
+
import { DevServer } from '../daemon/dev-server.js';
|
|
20
|
+
import { type IDEInfo } from '../detection/ide-detector.js';
|
|
21
|
+
import { SessionRegistry } from '../sessions/registry.js';
|
|
22
|
+
import type { PtyTransportFactory } from '../cli-adapters/pty-transport.js';
|
|
23
|
+
export interface DaemonInitConfig {
|
|
24
|
+
/** ProviderLoader log function */
|
|
25
|
+
providerLogFn?: (msg: string) => void;
|
|
26
|
+
/** CLI Manager deps (transport-specific) */
|
|
27
|
+
cliManagerDeps: {
|
|
28
|
+
getServerConn: () => any;
|
|
29
|
+
getP2p: () => any;
|
|
30
|
+
onStatusChange: () => void;
|
|
31
|
+
removeAgentTracking: (key: string) => void;
|
|
32
|
+
createPtyTransportFactory?: (params: CliTransportFactoryParams) => PtyTransportFactory | null;
|
|
33
|
+
listHostedCliRuntimes?: () => Promise<HostedCliRuntimeDescriptor[]>;
|
|
34
|
+
};
|
|
35
|
+
/** CDP config */
|
|
36
|
+
enabledIdes?: string[];
|
|
37
|
+
/** Router transport-specific callbacks */
|
|
38
|
+
onStatusChange?: () => void;
|
|
39
|
+
onPostChatCommand?: () => void;
|
|
40
|
+
sessionHostControl?: SessionHostControlPlane | null;
|
|
41
|
+
getCdpLogFn?: (ideType: string) => (msg: string) => void;
|
|
42
|
+
/** Additional callback after CDP manager created (transport-specific extras) */
|
|
43
|
+
onCdpManagerSetup?: (ideType: string, manager: DaemonCdpManager, managerKey: string) => void | Promise<void>;
|
|
44
|
+
/** Poller callback (transport-specific) */
|
|
45
|
+
onStreamsUpdated?: (ideType: string, streams: any[]) => void;
|
|
46
|
+
/** Instance ticking interval (ms), default 5000 */
|
|
47
|
+
tickIntervalMs?: number;
|
|
48
|
+
/** CDP scan interval (ms), default 30000 */
|
|
49
|
+
cdpScanIntervalMs?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface DaemonComponents {
|
|
52
|
+
providerLoader: ProviderLoader;
|
|
53
|
+
instanceManager: ProviderInstanceManager;
|
|
54
|
+
cliManager: DaemonCliManager;
|
|
55
|
+
commandHandler: DaemonCommandHandler;
|
|
56
|
+
agentStreamManager: DaemonAgentStreamManager;
|
|
57
|
+
router: DaemonCommandRouter;
|
|
58
|
+
poller: AgentStreamPoller;
|
|
59
|
+
cdpInitializer: DaemonCdpInitializer;
|
|
60
|
+
cdpManagers: Map<string, DaemonCdpManager>;
|
|
61
|
+
sessionRegistry: SessionRegistry;
|
|
62
|
+
detectedIdes: {
|
|
63
|
+
value: IDEInfo[];
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface DaemonDevSupportOptions {
|
|
67
|
+
components: DaemonComponents;
|
|
68
|
+
logFn?: (msg: string) => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Initialize all daemon core components.
|
|
72
|
+
*
|
|
73
|
+
* Order:
|
|
74
|
+
* 1. Global log interceptor
|
|
75
|
+
* 2. ProviderLoader
|
|
76
|
+
* 3. InstanceManager + CliManager
|
|
77
|
+
* 4. Detect IDEs
|
|
78
|
+
* 5. CdpInitializer → connectAll + periodic scan + discovery
|
|
79
|
+
* 6. CommandHandler + AgentStreamManager
|
|
80
|
+
* 7. Router + Poller
|
|
81
|
+
* 8. Start instance ticking
|
|
82
|
+
*/
|
|
83
|
+
export declare function initDaemonComponents(config: DaemonInitConfig): Promise<DaemonComponents>;
|
|
84
|
+
/**
|
|
85
|
+
* Start shared dev-only helpers:
|
|
86
|
+
* - DevServer on port 19280
|
|
87
|
+
* - Provider hot-reload watcher
|
|
88
|
+
*/
|
|
89
|
+
export declare function startDaemonDevSupport(options: DaemonDevSupportOptions): Promise<DevServer>;
|
|
90
|
+
/**
|
|
91
|
+
* Graceful shutdown of all daemon components.
|
|
92
|
+
*
|
|
93
|
+
* Order:
|
|
94
|
+
* 1. Stop timers (poller, cdpInitializer)
|
|
95
|
+
* 2. Dispose agent stream
|
|
96
|
+
* 3. Shutdown CLIs
|
|
97
|
+
* 4. Dispose instances
|
|
98
|
+
* 5. Disconnect CDPs
|
|
99
|
+
*/
|
|
100
|
+
export declare function shutdownDaemonComponents(components: DaemonComponents): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP DOM Analysis Tools — DOM dump, query, debug
|
|
3
|
+
*
|
|
4
|
+
* Separated from daemon-commands.ts.
|
|
5
|
+
* Tools for analyzing DOM structure when developing new IDE scripts.
|
|
6
|
+
*/
|
|
7
|
+
import type { DaemonCdpManager } from './manager.js';
|
|
8
|
+
import type { CommandResult } from '../commands/handler.js';
|
|
9
|
+
type CdpGetter = (ideType?: string) => DaemonCdpManager | null;
|
|
10
|
+
/**
|
|
11
|
+
* CDP DOM analysis handler
|
|
12
|
+
*
|
|
13
|
+
* Uses getCdp from DaemonCommandHandler.
|
|
14
|
+
*/
|
|
15
|
+
export declare class CdpDomHandlers {
|
|
16
|
+
private getCdp;
|
|
17
|
+
constructor(getCdp: CdpGetter);
|
|
18
|
+
/**
|
|
19
|
+
* CDP DOM Dump — IDE's DOM tree retrieve
|
|
20
|
+
*
|
|
21
|
+
* args:
|
|
22
|
+
* selector?: string — CSS selector to dump specific area only (default: All)
|
|
23
|
+
* depth?: number — Dump depth limit (default: 10)
|
|
24
|
+
* attrs?: boolean — Whether to include properties (default: true)
|
|
25
|
+
* maxLength?: number — Max character count (default: 200000)
|
|
26
|
+
* format?: 'html' | 'tree' | 'summary' — Output format (default: 'html')
|
|
27
|
+
* sessionId?: string — Agent webview session ID (if provided, match webview DOM)
|
|
28
|
+
*/
|
|
29
|
+
handleDomDump(args: any): Promise<CommandResult>;
|
|
30
|
+
/**
|
|
31
|
+
* CDP DOM Query — CSS Test selector
|
|
32
|
+
* Check how many elements match selector and what elements they are
|
|
33
|
+
*
|
|
34
|
+
* args:
|
|
35
|
+
* selector: string — CSS selector
|
|
36
|
+
* limit?: number — Max element count to return (default: 20)
|
|
37
|
+
* content?: boolean — Whether to include text content (default: true)
|
|
38
|
+
* sessionId?: string — agent webview session ID
|
|
39
|
+
*/
|
|
40
|
+
handleDomQuery(args: any): Promise<CommandResult>;
|
|
41
|
+
/**
|
|
42
|
+
* CDP DOM Debug — IDE AI panel specialized analysis
|
|
43
|
+
* Collect all essential info at once when supporting new IDE
|
|
44
|
+
*
|
|
45
|
+
* args:
|
|
46
|
+
* ideType?: string — IDE type hint
|
|
47
|
+
* sessionId?: string — agent webview session ID
|
|
48
|
+
*/
|
|
49
|
+
handleDomDebug(args: any): Promise<CommandResult>;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DaemonCdpInitializer — Unified CDP initialization + periodic scanning
|
|
3
|
+
*
|
|
4
|
+
* Unified CDP initialization + periodic scanning.
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* 1. Initial connection: connectAll() — multi-window aware
|
|
8
|
+
* 2. Periodic scan: startPeriodicScan() — auto-detect newly opened IDEs
|
|
9
|
+
* 3. Discovery: startDiscovery() — periodic agent webview discovery
|
|
10
|
+
*/
|
|
11
|
+
import { DaemonCdpManager } from './manager.js';
|
|
12
|
+
import type { ProviderLoader } from '../providers/provider-loader.js';
|
|
13
|
+
export interface CdpInitializerConfig {
|
|
14
|
+
providerLoader: ProviderLoader;
|
|
15
|
+
cdpManagers: Map<string, DaemonCdpManager>;
|
|
16
|
+
/** Filter: only connect these IDEs (empty/undefined = all) */
|
|
17
|
+
enabledIdes?: string[];
|
|
18
|
+
/** Callback when a new CDP manager is connected */
|
|
19
|
+
onConnected?: (ideType: string, manager: DaemonCdpManager, managerKey: string) => void | Promise<void>;
|
|
20
|
+
/** Callback when a stale/disconnected CDP manager is removed */
|
|
21
|
+
onDisconnected?: (ideType: string, manager: DaemonCdpManager, managerKey: string, reason: 'ide_closed' | 'target_closed' | 'target_rekeyed') => void | Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare class DaemonCdpInitializer {
|
|
24
|
+
private config;
|
|
25
|
+
private scanTimer;
|
|
26
|
+
private discoveryTimer;
|
|
27
|
+
constructor(config: CdpInitializerConfig);
|
|
28
|
+
/**
|
|
29
|
+
* Connect to all detected IDEs.
|
|
30
|
+
* Multi-window aware: creates separate CdpManager per workbench page.
|
|
31
|
+
*/
|
|
32
|
+
connectAll(detectedIdes: any[]): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Connect to a single IDE port.
|
|
35
|
+
* Tries multi-window first (listAllTargets), falls back to direct connect.
|
|
36
|
+
*/
|
|
37
|
+
private connectIdePort;
|
|
38
|
+
private pruneStaleManagers;
|
|
39
|
+
/**
|
|
40
|
+
* Start periodic scanning for newly opened IDEs.
|
|
41
|
+
* Idempotent — ignored if already started.
|
|
42
|
+
*/
|
|
43
|
+
startPeriodicScan(intervalMs?: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Start periodic agent webview discovery.
|
|
46
|
+
*/
|
|
47
|
+
startDiscovery(intervalMs?: number): void;
|
|
48
|
+
/** Stop all timers */
|
|
49
|
+
stop(): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP Manager for ADHDev Daemon
|
|
3
|
+
*
|
|
4
|
+
* Ported cdp.ts from Extension for Daemon use.
|
|
5
|
+
* vscode dependencies removed — works in pure Node.js environment.
|
|
6
|
+
*
|
|
7
|
+
* Connects to IDE CDP port (9222, 9333 etc) to:
|
|
8
|
+
* - Execute JS via Runtime.evaluate
|
|
9
|
+
* - Agent webview iframe search & session connection
|
|
10
|
+
* - DOM query
|
|
11
|
+
*/
|
|
12
|
+
import type { CdpTargetFilter } from '../providers/contracts.js';
|
|
13
|
+
interface CdpTarget {
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
title: string;
|
|
17
|
+
url: string;
|
|
18
|
+
webSocketDebuggerUrl: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentWebviewTarget {
|
|
21
|
+
targetId: string;
|
|
22
|
+
extensionId: string;
|
|
23
|
+
agentType: string;
|
|
24
|
+
url: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class DaemonCdpManager {
|
|
27
|
+
private ws;
|
|
28
|
+
private browserWs;
|
|
29
|
+
private browserMsgId;
|
|
30
|
+
private browserPending;
|
|
31
|
+
private msgId;
|
|
32
|
+
private pending;
|
|
33
|
+
private port;
|
|
34
|
+
private _connected;
|
|
35
|
+
private _browserConnected;
|
|
36
|
+
private targetUrl;
|
|
37
|
+
private reconnectTimer;
|
|
38
|
+
private contexts;
|
|
39
|
+
private connectPromise;
|
|
40
|
+
private failureCount;
|
|
41
|
+
private readonly MAX_FAILURES;
|
|
42
|
+
private agentSessions;
|
|
43
|
+
private logFn;
|
|
44
|
+
private extensionProviders;
|
|
45
|
+
private _lastDiscoverSig;
|
|
46
|
+
private _targetId;
|
|
47
|
+
private _pageTitle;
|
|
48
|
+
private _targetFilter;
|
|
49
|
+
private _lastDiscoveredTargets?;
|
|
50
|
+
constructor(port?: number, logFn?: (msg: string) => void, targetId?: string, targetFilter?: CdpTargetFilter);
|
|
51
|
+
/** Set target filter (can be updated after construction) */
|
|
52
|
+
setTargetFilter(filter: CdpTargetFilter): void;
|
|
53
|
+
/** Clear a previously pinned target so the next connect can reselect a page. */
|
|
54
|
+
clearTargetId(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a page title should be excluded (non-main page).
|
|
57
|
+
* Uses provider-configured titleExcludes, falls back to default pattern.
|
|
58
|
+
*/
|
|
59
|
+
private isNonMainTitle;
|
|
60
|
+
/**
|
|
61
|
+
* Check if a page URL matches the main window criteria.
|
|
62
|
+
* Uses provider-configured urlIncludes/urlExcludes.
|
|
63
|
+
*/
|
|
64
|
+
private isMainPageUrl;
|
|
65
|
+
/** Connected page title (includes workspace name) */
|
|
66
|
+
get pageTitle(): string;
|
|
67
|
+
/** Connected target ID */
|
|
68
|
+
get targetId(): string | null;
|
|
69
|
+
/**
|
|
70
|
+
* Query all workbench pages on port (static)
|
|
71
|
+
* Returns multiple entries if multiple IDE windows are open on same port
|
|
72
|
+
*/
|
|
73
|
+
static listAllTargets(port: number): Promise<CdpTarget[]>;
|
|
74
|
+
setPort(port: number): void;
|
|
75
|
+
getPort(): number;
|
|
76
|
+
private log;
|
|
77
|
+
connect(): Promise<boolean>;
|
|
78
|
+
private doConnect;
|
|
79
|
+
private findTargetOnPort;
|
|
80
|
+
private findTarget;
|
|
81
|
+
setExtensionProviders(providers: {
|
|
82
|
+
agentType: string;
|
|
83
|
+
extensionId: string;
|
|
84
|
+
extensionIdPattern: RegExp;
|
|
85
|
+
}[]): void;
|
|
86
|
+
private connectToTarget;
|
|
87
|
+
/** Browser-level CDP connection — needed for Target discovery */
|
|
88
|
+
private connectBrowserWs;
|
|
89
|
+
private getBrowserWsUrl;
|
|
90
|
+
private sendBrowser;
|
|
91
|
+
private scheduleReconnect;
|
|
92
|
+
disconnect(): void;
|
|
93
|
+
get isConnected(): boolean;
|
|
94
|
+
private sendInternal;
|
|
95
|
+
send(method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<any>;
|
|
96
|
+
sendCdpCommand(method: string, params?: Record<string, unknown>): Promise<any>;
|
|
97
|
+
evaluate(expression: string, timeoutMs?: number): Promise<unknown>;
|
|
98
|
+
querySelector(selector: string): Promise<string | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Input text via CDP protocol then send Enter
|
|
101
|
+
* Used for editors where execCommand does not work (e.g. Lexical).
|
|
102
|
+
*
|
|
103
|
+
* 1. Find editor by selector, focus + click
|
|
104
|
+
* 2. Insert text via Input.insertText
|
|
105
|
+
* 3. Send Enter via Input.dispatchKeyEvent
|
|
106
|
+
*/
|
|
107
|
+
typeAndSend(selector: string, text: string): Promise<boolean>;
|
|
108
|
+
/**
|
|
109
|
+
* Coordinate-based typeAndSend — for input fields inside webview iframe
|
|
110
|
+
* Receives coordinates directly instead of selector for click+input+Enter
|
|
111
|
+
*/
|
|
112
|
+
typeAndSendAt(x: number, y: number, text: string): Promise<boolean>;
|
|
113
|
+
/**
|
|
114
|
+
* Evaluate JS from inside Webview iframe
|
|
115
|
+
* Kiro, PearAI etc Used for IDEs where chat UI is inside webview iframe.
|
|
116
|
+
*
|
|
117
|
+
* 1. Query Target.getTargets via browser WS → find vscode-webview iframes
|
|
118
|
+
* 2. Target.attachToTarget → session acquire
|
|
119
|
+
* 3. Page.getFrameTree → nested iframe find
|
|
120
|
+
* 4. Page.createIsolatedWorld → contextId acquire
|
|
121
|
+
* 5. Runtime.evaluate → result return
|
|
122
|
+
*
|
|
123
|
+
* @param expression JS expression to execute
|
|
124
|
+
* @param matchFn webview iframe URL match function (optional, all webview attempt)
|
|
125
|
+
* @returns evaluate result or null
|
|
126
|
+
*/
|
|
127
|
+
evaluateInWebviewFrame(expression: string, matchFn?: (bodyPreview: string) => boolean): Promise<string | null>;
|
|
128
|
+
discoverAgentWebviews(): Promise<AgentWebviewTarget[]>;
|
|
129
|
+
attachToAgent(target: AgentWebviewTarget): Promise<string | null>;
|
|
130
|
+
evaluateInSession(sessionId: string, expression: string, timeoutMs?: number): Promise<unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* Evaluate inside the child frame of an attached session.
|
|
133
|
+
* Extension webviews have a nested iframe structure:
|
|
134
|
+
* outer (vscode-webview://) → inner (extension React app)
|
|
135
|
+
* This method navigates into the inner frame using CDP Page.getFrameTree.
|
|
136
|
+
* Falls back to evaluateInSession if no child frame is found.
|
|
137
|
+
*/
|
|
138
|
+
evaluateInSessionFrame(sessionId: string, expression: string, timeoutMs?: number): Promise<unknown>;
|
|
139
|
+
detachAgent(sessionId: string): Promise<void>;
|
|
140
|
+
detachAllAgents(): Promise<void>;
|
|
141
|
+
getAgentSessions(): Map<string, AgentWebviewTarget>;
|
|
142
|
+
private getCurrentPageWebviewUrls;
|
|
143
|
+
captureScreenshot(opts?: {
|
|
144
|
+
quality?: number;
|
|
145
|
+
}): Promise<Buffer | null>;
|
|
146
|
+
}
|
|
147
|
+
export {};
|