@adhdev/daemon-core 0.8.34 → 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.
- package/dist/boot/daemon-lifecycle.d.ts +4 -0
- package/dist/commands/router.d.ts +3 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +585 -256
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +584 -256
- package/dist/index.mjs.map +1 -1
- package/dist/shared-types.d.ts +286 -16
- package/dist/status/builders.d.ts +5 -1
- package/dist/status/normalize.d.ts +11 -1
- package/dist/status/normalize.js +36 -16
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +35 -16
- package/dist/status/normalize.mjs.map +1 -1
- package/dist/status/reporter.d.ts +7 -0
- package/dist/status/snapshot.d.ts +5 -5
- package/dist/types.d.ts +1 -1
- 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/boot/daemon-lifecycle.ts +7 -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/chat-commands.ts +192 -17
- 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/router.ts +25 -0
- package/src/commands/stream-commands.d.ts +14 -0
- package/src/commands/stream-commands.ts +14 -10
- 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/config.ts +8 -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 +34 -1
- 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 +204 -38
- package/src/shared-types.ts +319 -16
- package/src/status/builders.d.ts +33 -0
- package/src/status/builders.ts +110 -54
- package/src/status/normalize.ts +54 -19
- package/src/status/reporter.d.ts +69 -0
- package/src/status/reporter.ts +104 -26
- package/src/status/snapshot.d.ts +58 -0
- package/src/status/snapshot.ts +79 -41
- package/src/system/host-memory.d.ts +19 -0
- package/src/types.d.ts +3 -7
- package/src/types.ts +1 -1
|
@@ -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 {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DaemonCdpScanner — Periodic CDP port scanning & auto-connect
|
|
3
|
+
*
|
|
4
|
+
* Periodic CDP port scanning and auto-connect for IDE discovery.
|
|
5
|
+
* Provides a unified approach to:
|
|
6
|
+
* 1. Initial CDP port discovery
|
|
7
|
+
* 2. Periodic scanning for newly launched IDEs
|
|
8
|
+
* 3. Multi-window support (multiple pages on same port)
|
|
9
|
+
*/
|
|
10
|
+
import { DaemonCdpManager } from './manager.js';
|
|
11
|
+
import { type CdpSetupContext } from './setup.js';
|
|
12
|
+
export interface CdpScannerOptions {
|
|
13
|
+
/** Context for setup operations */
|
|
14
|
+
ctx: CdpSetupContext;
|
|
15
|
+
/** Log function for per-IDE CDP logs */
|
|
16
|
+
logFn?: (ideType: string) => (msg: string) => void;
|
|
17
|
+
/** Whether to support multi-window (multiple pages per port) */
|
|
18
|
+
multiWindow?: boolean;
|
|
19
|
+
/** Scan interval in ms (default: 30000) */
|
|
20
|
+
scanIntervalMs?: number;
|
|
21
|
+
/** Callback when a new CDP connection is established */
|
|
22
|
+
onConnected?: (ideType: string, managerKey: string, manager: DaemonCdpManager) => void;
|
|
23
|
+
}
|
|
24
|
+
export declare class DaemonCdpScanner {
|
|
25
|
+
private ctx;
|
|
26
|
+
private opts;
|
|
27
|
+
private scanTimer;
|
|
28
|
+
private discoveryTimer;
|
|
29
|
+
constructor(opts: CdpScannerOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Initial CDP discovery — connect to all available IDEs.
|
|
32
|
+
* Supports both single-window and multi-window modes.
|
|
33
|
+
*/
|
|
34
|
+
initialScan(enabledIdes?: string[]): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Start periodic scanning for newly launched IDEs.
|
|
37
|
+
*/
|
|
38
|
+
startPeriodicScan(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Start periodic agent webview discovery on all connected CDPs.
|
|
41
|
+
*/
|
|
42
|
+
startWebviewDiscovery(intervalMs?: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Stop all timers.
|
|
45
|
+
*/
|
|
46
|
+
stop(): void;
|
|
47
|
+
private getLogFn;
|
|
48
|
+
/**
|
|
49
|
+
* Single-window connection (standalone mode).
|
|
50
|
+
* One CDP manager per IDE, first working port wins.
|
|
51
|
+
*/
|
|
52
|
+
private connectSingleWindow;
|
|
53
|
+
/**
|
|
54
|
+
* Multi-window connection.
|
|
55
|
+
* Multiple CDP managers per IDE — one per workbench page.
|
|
56
|
+
*/
|
|
57
|
+
private connectMultiWindow;
|
|
58
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DaemonCdpSetup — Shared CDP initialization helpers
|
|
3
|
+
*
|
|
4
|
+
* Common CDP setup logic for consistent
|
|
5
|
+
* CDP → ProviderInstance registration.
|
|
6
|
+
*/
|
|
7
|
+
import { DaemonCdpManager } from './manager.js';
|
|
8
|
+
import { ProviderLoader } from '../providers/provider-loader.js';
|
|
9
|
+
import { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
|
|
10
|
+
import { IdeProviderInstance } from '../providers/ide-provider-instance.js';
|
|
11
|
+
import { SessionRegistry } from '../sessions/registry.js';
|
|
12
|
+
export interface CdpSetupContext {
|
|
13
|
+
providerLoader: ProviderLoader;
|
|
14
|
+
instanceManager: ProviderInstanceManager;
|
|
15
|
+
cdpManagers: Map<string, DaemonCdpManager>;
|
|
16
|
+
sessionRegistry: SessionRegistry;
|
|
17
|
+
/** Server connection (optional) */
|
|
18
|
+
serverConn?: any;
|
|
19
|
+
}
|
|
20
|
+
export interface SetupIdeInstanceOptions {
|
|
21
|
+
/** Provider-based IDE type (e.g., 'antigravity', 'cursor') */
|
|
22
|
+
ideType: string;
|
|
23
|
+
/** Connected CDP manager */
|
|
24
|
+
manager: DaemonCdpManager;
|
|
25
|
+
/** CDP manager key (for multi-window: 'antigravity_remote_vs', single: 'antigravity') */
|
|
26
|
+
managerKey?: string;
|
|
27
|
+
/** Provider settings override */
|
|
28
|
+
settings?: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register extension providers on a CDP manager.
|
|
32
|
+
* Common pattern used during CDP init and periodic scans.
|
|
33
|
+
*/
|
|
34
|
+
export declare function registerExtensionProviders(providerLoader: ProviderLoader, manager: DaemonCdpManager, ideType: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Setup a CDP-connected IDE as a ProviderInstance.
|
|
37
|
+
*
|
|
38
|
+
* Performs:
|
|
39
|
+
* 1. providerLoader.resolve() to get scripts
|
|
40
|
+
* 2. Create IdeProviderInstance
|
|
41
|
+
* 3. Register in InstanceManager
|
|
42
|
+
* 4. Register enabled extensions
|
|
43
|
+
* 5. Register runtime sessions (workspace + extension children)
|
|
44
|
+
*
|
|
45
|
+
* @returns The created IdeProviderInstance, or null if provider not found
|
|
46
|
+
*/
|
|
47
|
+
export declare function setupIdeInstance(ctx: CdpSetupContext, opts: SetupIdeInstanceOptions): Promise<IdeProviderInstance | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Create and connect a DaemonCdpManager for a given port.
|
|
50
|
+
*
|
|
51
|
+
* @returns Connected manager or null if connection failed
|
|
52
|
+
*/
|
|
53
|
+
export declare function connectCdpManager(port: number, ideType: string, logFn: (msg: string) => void, providerLoader: ProviderLoader, targetId?: string): Promise<DaemonCdpManager | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Probe a CDP port to check if it's listening.
|
|
56
|
+
* @returns true if CDP is available on this port
|
|
57
|
+
*/
|
|
58
|
+
export declare function probeCdpPort(port: number, timeoutMs?: number): Promise<boolean>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CliAdapter — common interface for CLI agents
|
|
3
|
+
*
|
|
4
|
+
* Contract implemented by all CLI adapters (ProviderCliAdapter etc).
|
|
5
|
+
*/
|
|
6
|
+
import type { ChatMessage } from './types.js';
|
|
7
|
+
export interface CliAdapterStatus {
|
|
8
|
+
status?: string;
|
|
9
|
+
messages?: ChatMessage[];
|
|
10
|
+
activeModal?: {
|
|
11
|
+
message: string;
|
|
12
|
+
buttons: string[];
|
|
13
|
+
} | null;
|
|
14
|
+
}
|
|
15
|
+
export interface AcpAdapterHandle {
|
|
16
|
+
onEvent(event: string, data?: unknown): void;
|
|
17
|
+
getState(): {
|
|
18
|
+
status: string;
|
|
19
|
+
activeChat?: {
|
|
20
|
+
messages?: ChatMessage[];
|
|
21
|
+
activeModal?: {
|
|
22
|
+
message: string;
|
|
23
|
+
buttons: string[];
|
|
24
|
+
} | null;
|
|
25
|
+
} | null;
|
|
26
|
+
};
|
|
27
|
+
setMode?(mode: string): Promise<void>;
|
|
28
|
+
setConfigOption?(configId: string, value: string): Promise<void>;
|
|
29
|
+
resolvePermission?(approved: boolean): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export interface CliAdapter {
|
|
32
|
+
cliType: string;
|
|
33
|
+
cliName: string;
|
|
34
|
+
workingDir: string;
|
|
35
|
+
_acpInstance?: AcpAdapterHandle;
|
|
36
|
+
spawn(): Promise<void>;
|
|
37
|
+
sendMessage(text: string): Promise<void>;
|
|
38
|
+
getStatus(): CliAdapterStatus;
|
|
39
|
+
getScriptParsedStatus?(): unknown;
|
|
40
|
+
invokeScript?(scriptName: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
41
|
+
getPartialResponse(): string;
|
|
42
|
+
saveAndStop?(): Promise<void>;
|
|
43
|
+
shutdown(): void;
|
|
44
|
+
detach?(): void;
|
|
45
|
+
cancel(): void;
|
|
46
|
+
isProcessing(): boolean;
|
|
47
|
+
isReady(): boolean;
|
|
48
|
+
setOnStatusChange(callback: () => void): void;
|
|
49
|
+
updateRuntimeSettings?(settings: Record<string, unknown>): void;
|
|
50
|
+
setServerConn?(serverConn: unknown): void;
|
|
51
|
+
clearHistory?(): void;
|
|
52
|
+
resolveAction?(data: unknown): Promise<void>;
|
|
53
|
+
resolveModal?(buttonIndex: number): void;
|
|
54
|
+
setOnPtyData?(callback: (data: string) => void): void;
|
|
55
|
+
writeRaw?(data: string): void;
|
|
56
|
+
resize?(cols: number, rows: number): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProviderCliAdapter — Script-based CLI Adapter
|
|
3
|
+
*
|
|
4
|
+
* All CLI providers use versioned scripts (like IDE providers).
|
|
5
|
+
* Scripts are Node.js functions that receive PTY buffer data and return structured results.
|
|
6
|
+
*
|
|
7
|
+
* Required scripts in scripts/{version}/scripts.js:
|
|
8
|
+
* - detectStatus(input) → AgentStatus string ('idle' | 'generating' | 'waiting_approval')
|
|
9
|
+
* - parseOutput(input) → ReadChatResult { messages, status, activeModal, ... }
|
|
10
|
+
* - parseApproval(input) → ModalInfo | null
|
|
11
|
+
*
|
|
12
|
+
* provider.json contract:
|
|
13
|
+
* type, name, category: 'cli', binary, spawn, approvalKeys
|
|
14
|
+
* compatibility: [{ ideVersion, scriptDir }] ← versioned scripts
|
|
15
|
+
*/
|
|
16
|
+
import type { CliAdapter } from '../cli-adapter-types.js';
|
|
17
|
+
import { type PtyRuntimeMetadata, type PtyTransportFactory } from './pty-transport.js';
|
|
18
|
+
import { type CliChatMessage, type CliProviderModule, type CliScripts, type CliSessionStatus } from './provider-cli-shared.js';
|
|
19
|
+
import { type ProviderResolutionMeta } from './provider-cli-config.js';
|
|
20
|
+
export { normalizeCliProviderForRuntime, type CliApprovalInput, type CliChatMessage, type CliProviderModule, type CliScreenLine, type CliScreenSnapshot, type CliScriptInput, type CliScripts, type CliSessionStatus, type CliStatusInput, type CliTraceEntry, } from './provider-cli-shared.js';
|
|
21
|
+
type SeedCliChatMessage = Omit<Partial<CliChatMessage>, 'role'> & {
|
|
22
|
+
role?: string;
|
|
23
|
+
content?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare class ProviderCliAdapter implements CliAdapter {
|
|
26
|
+
private extraArgs;
|
|
27
|
+
readonly cliType: string;
|
|
28
|
+
readonly cliName: string;
|
|
29
|
+
workingDir: string;
|
|
30
|
+
private provider;
|
|
31
|
+
private ptyProcess;
|
|
32
|
+
private transportFactory;
|
|
33
|
+
private messages;
|
|
34
|
+
private committedMessages;
|
|
35
|
+
private structuredMessages;
|
|
36
|
+
private currentStatus;
|
|
37
|
+
private onStatusChange;
|
|
38
|
+
private responseBuffer;
|
|
39
|
+
private recentOutputBuffer;
|
|
40
|
+
private isWaitingForResponse;
|
|
41
|
+
private activeModal;
|
|
42
|
+
private responseTimeout;
|
|
43
|
+
private idleTimeout;
|
|
44
|
+
private ready;
|
|
45
|
+
private startupBuffer;
|
|
46
|
+
private startupParseGate;
|
|
47
|
+
private startupSettleTimer;
|
|
48
|
+
private spawnAt;
|
|
49
|
+
private startupFirstOutputAt;
|
|
50
|
+
private onPtyDataCallback;
|
|
51
|
+
private pendingOutputParseBuffer;
|
|
52
|
+
private pendingOutputParseTimer;
|
|
53
|
+
private ptyOutputBuffer;
|
|
54
|
+
private ptyOutputFlushTimer;
|
|
55
|
+
private pendingTerminalQueryTail;
|
|
56
|
+
private lastOutputAt;
|
|
57
|
+
private lastNonEmptyOutputAt;
|
|
58
|
+
private lastScreenChangeAt;
|
|
59
|
+
private lastScreenSnapshot;
|
|
60
|
+
private serverConn;
|
|
61
|
+
private logBuffer;
|
|
62
|
+
private lastApprovalResolvedAt;
|
|
63
|
+
private approvalTransitionBuffer;
|
|
64
|
+
private approvalExitTimeout;
|
|
65
|
+
private pendingScriptStatus;
|
|
66
|
+
private pendingScriptStatusSince;
|
|
67
|
+
private pendingScriptStatusTimer;
|
|
68
|
+
private settleTimer;
|
|
69
|
+
private settledBuffer;
|
|
70
|
+
private submitPendingUntil;
|
|
71
|
+
private responseSettleIgnoreUntil;
|
|
72
|
+
private responseEpoch;
|
|
73
|
+
private submitRetryTimer;
|
|
74
|
+
private submitRetryUsed;
|
|
75
|
+
private submitRetryPromptSnippet;
|
|
76
|
+
private idleFinishCandidate;
|
|
77
|
+
private finishRetryTimer;
|
|
78
|
+
private finishRetryCount;
|
|
79
|
+
private resizeSuppressUntil;
|
|
80
|
+
private statusHistory;
|
|
81
|
+
private cliScripts;
|
|
82
|
+
private runtimeSettings;
|
|
83
|
+
/** Full accumulated ANSI-stripped PTY output */
|
|
84
|
+
private accumulatedBuffer;
|
|
85
|
+
/** Full accumulated raw PTY output (with ANSI) */
|
|
86
|
+
private accumulatedRawBuffer;
|
|
87
|
+
/** Current visible terminal screen snapshot */
|
|
88
|
+
private terminalScreen;
|
|
89
|
+
/** Max accumulated buffer size (last 50KB) */
|
|
90
|
+
private static readonly MAX_ACCUMULATED_BUFFER;
|
|
91
|
+
private currentTurnScope;
|
|
92
|
+
private traceEntries;
|
|
93
|
+
private traceSeq;
|
|
94
|
+
private traceSessionId;
|
|
95
|
+
private static readonly MAX_TRACE_ENTRIES;
|
|
96
|
+
private readonly providerResolutionMeta;
|
|
97
|
+
private static readonly IDLE_FINISH_CONFIRM_MS;
|
|
98
|
+
private static readonly STATUS_ACTIVITY_HOLD_MS;
|
|
99
|
+
private static readonly FINISH_RETRY_DELAY_MS;
|
|
100
|
+
private static readonly MAX_FINISH_RETRIES;
|
|
101
|
+
private syncMessageViews;
|
|
102
|
+
private setStatus;
|
|
103
|
+
private clearIdleFinishCandidate;
|
|
104
|
+
private armIdleFinishCandidate;
|
|
105
|
+
private recordTrace;
|
|
106
|
+
private resetTraceSession;
|
|
107
|
+
private readonly timeouts;
|
|
108
|
+
private readonly approvalKeys;
|
|
109
|
+
private readonly sendDelayMs;
|
|
110
|
+
private readonly sendKey;
|
|
111
|
+
private readonly submitStrategy;
|
|
112
|
+
private static readonly SCRIPT_STATUS_DEBOUNCE_MS;
|
|
113
|
+
constructor(provider: CliProviderModule, workingDir: string, extraArgs?: string[], transportFactory?: PtyTransportFactory);
|
|
114
|
+
/** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
|
|
115
|
+
setCliScripts(scripts: CliScripts): void;
|
|
116
|
+
updateRuntimeSettings(settings: Record<string, any>): void;
|
|
117
|
+
setServerConn(serverConn: any): void;
|
|
118
|
+
setOnStatusChange(callback: () => void): void;
|
|
119
|
+
setOnPtyData(callback: (data: string) => void): void;
|
|
120
|
+
private flushPendingOutputParse;
|
|
121
|
+
spawn(): Promise<void>;
|
|
122
|
+
private handleOutput;
|
|
123
|
+
private resolveStartupState;
|
|
124
|
+
private scheduleStartupSettleCheck;
|
|
125
|
+
private scheduleSettle;
|
|
126
|
+
private armApprovalExitTimeout;
|
|
127
|
+
private looksLikeVisibleIdlePrompt;
|
|
128
|
+
private findLastMatchingLineIndex;
|
|
129
|
+
private looksLikeClaudeGeneratingLine;
|
|
130
|
+
private detectClaudeGeneratingOverride;
|
|
131
|
+
private refineDetectedStatus;
|
|
132
|
+
private looksLikeVisibleAssistantCandidate;
|
|
133
|
+
private shouldRetryFinishResponse;
|
|
134
|
+
private hasRecentInteractiveActivity;
|
|
135
|
+
private getStartupConfirmationModal;
|
|
136
|
+
private shouldResolveModalWithEnter;
|
|
137
|
+
private waitForInteractivePrompt;
|
|
138
|
+
private evaluateSettled;
|
|
139
|
+
private finishResponse;
|
|
140
|
+
private commitCurrentTranscript;
|
|
141
|
+
private runDetectStatus;
|
|
142
|
+
private runParseApproval;
|
|
143
|
+
getStatus(): CliSessionStatus;
|
|
144
|
+
seedCommittedMessages(messages: SeedCliChatMessage[]): void;
|
|
145
|
+
/**
|
|
146
|
+
* Script-based full parse — returns ReadChatResult.
|
|
147
|
+
* Called by command handler / dashboard for rich content rendering.
|
|
148
|
+
*/
|
|
149
|
+
getScriptParsedStatus(): any;
|
|
150
|
+
invokeScript(scriptName: string, args?: Record<string, any>): Promise<any>;
|
|
151
|
+
private parseCurrentTranscript;
|
|
152
|
+
/** Whether this adapter has CLI scripts loaded */
|
|
153
|
+
hasCliScripts(): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Resolves an action (like 'fix' lint error) from the dashboard.
|
|
156
|
+
* Uses resolveAction script if available, otherwise falls back to standard text.
|
|
157
|
+
*/
|
|
158
|
+
resolveAction(data: any): Promise<void>;
|
|
159
|
+
sendMessage(text: string): Promise<void>;
|
|
160
|
+
getPartialResponse(): string;
|
|
161
|
+
getRuntimeMetadata(): PtyRuntimeMetadata | null;
|
|
162
|
+
updateRuntimeMeta(meta: Record<string, unknown>, replace?: boolean): void;
|
|
163
|
+
cancel(): void;
|
|
164
|
+
saveAndStop(): Promise<void>;
|
|
165
|
+
private waitForStopped;
|
|
166
|
+
shutdown(): void;
|
|
167
|
+
detach(): void;
|
|
168
|
+
clearHistory(): void;
|
|
169
|
+
isProcessing(): boolean;
|
|
170
|
+
isReady(): boolean;
|
|
171
|
+
writeRaw(data: string): void;
|
|
172
|
+
resolveModal(buttonIndex: number): void;
|
|
173
|
+
resize(cols: number, rows: number): void;
|
|
174
|
+
getDebugState(): Record<string, any>;
|
|
175
|
+
getTraceState(limit?: number): Record<string, any>;
|
|
176
|
+
getProviderResolutionMeta(): ProviderResolutionMeta;
|
|
177
|
+
}
|