@adhdev/daemon-core 0.7.38 → 0.7.40

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.
Files changed (95) hide show
  1. package/dist/agent-stream/forward.d.ts +8 -0
  2. package/dist/agent-stream/index.d.ts +6 -0
  3. package/dist/agent-stream/manager.d.ts +59 -0
  4. package/dist/agent-stream/poller.d.ts +41 -0
  5. package/dist/agent-stream/provider-adapter.d.ts +29 -0
  6. package/dist/agent-stream/types.d.ts +62 -0
  7. package/dist/boot/daemon-lifecycle.d.ts +97 -0
  8. package/dist/cdp/devtools.d.ts +51 -0
  9. package/dist/cdp/initializer.d.ts +50 -0
  10. package/dist/cdp/manager.d.ts +145 -0
  11. package/dist/cdp/scanner.d.ts +58 -0
  12. package/dist/cdp/setup.d.ts +58 -0
  13. package/dist/cli-adapter-types.d.ts +25 -0
  14. package/dist/cli-adapters/provider-cli-adapter.d.ts +229 -0
  15. package/dist/cli-adapters/pty-transport.d.ts +43 -0
  16. package/dist/cli-adapters/session-host-transport.d.ts +19 -0
  17. package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +12 -0
  18. package/dist/cli-adapters/terminal-backends/types.d.ts +14 -0
  19. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +13 -0
  20. package/dist/cli-adapters/terminal-screen.d.ts +27 -0
  21. package/dist/commands/cdp-commands.d.ts +15 -0
  22. package/dist/commands/chat-commands.d.ts +15 -0
  23. package/dist/commands/cli-manager.d.ts +82 -0
  24. package/dist/commands/handler.d.ts +101 -0
  25. package/dist/commands/router.d.ts +69 -0
  26. package/dist/commands/stream-commands.d.ts +13 -0
  27. package/dist/commands/workspace-commands.d.ts +11 -0
  28. package/dist/config/chat-history.d.ts +60 -0
  29. package/dist/config/config.d.ts +103 -0
  30. package/dist/config/recent-activity.d.ts +27 -0
  31. package/dist/config/workspaces.d.ts +82 -0
  32. package/dist/daemon/dev-auto-implement.d.ts +26 -0
  33. package/dist/daemon/dev-cdp-handlers.d.ts +22 -0
  34. package/dist/daemon/dev-cli-debug.d.ts +24 -0
  35. package/dist/daemon/dev-server-types.d.ts +43 -0
  36. package/dist/daemon/dev-server.d.ts +133 -0
  37. package/dist/daemon/scaffold-template.d.ts +32 -0
  38. package/dist/daemon-core.d.ts +36 -0
  39. package/dist/detection/cli-detector.d.ts +27 -0
  40. package/dist/detection/ide-detector.d.ts +34 -0
  41. package/dist/index.d.ts +72 -2499
  42. package/dist/index.js +673 -879
  43. package/dist/index.js.map +1 -1
  44. package/dist/index.mjs +680 -884
  45. package/dist/index.mjs.map +1 -1
  46. package/dist/installer.d.ts +50 -0
  47. package/dist/ipc-protocol.d.ts +111 -0
  48. package/dist/launch.d.ts +46 -0
  49. package/dist/logging/command-log.d.ts +31 -0
  50. package/dist/logging/logger.d.ts +87 -0
  51. package/dist/providers/acp-provider-instance.d.ts +101 -0
  52. package/dist/providers/cli-provider-instance.d.ts +43 -0
  53. package/dist/providers/contracts.d.ts +483 -0
  54. package/dist/providers/extension-provider-instance.d.ts +44 -0
  55. package/dist/providers/ide-provider-instance.d.ts +61 -0
  56. package/dist/providers/index.d.ts +5 -0
  57. package/dist/providers/provider-instance-manager.d.ts +84 -0
  58. package/dist/providers/provider-instance.d.ts +148 -0
  59. package/dist/providers/provider-loader.d.ts +270 -0
  60. package/dist/providers/status-monitor.d.ts +48 -0
  61. package/dist/providers/version-archive.d.ts +52 -0
  62. package/dist/session-host/runtime-support.d.ts +8 -0
  63. package/dist/sessions/registry.d.ts +24 -0
  64. package/dist/shared-types-extra.d.ts +29 -0
  65. package/dist/shared-types.d.ts +205 -0
  66. package/dist/status/builders.d.ts +33 -0
  67. package/dist/status/normalize.d.ts +14 -1
  68. package/dist/status/reporter.d.ts +69 -0
  69. package/dist/status/snapshot.d.ts +51 -0
  70. package/dist/system/host-memory.d.ts +19 -0
  71. package/dist/types.d.ts +123 -0
  72. package/node_modules/@adhdev/session-host-core/package.json +1 -1
  73. package/package.json +3 -2
  74. package/src/commands/cli-manager.ts +1 -26
  75. package/src/commands/handler.ts +0 -31
  76. package/src/commands/router.ts +27 -34
  77. package/src/commands/stream-commands.ts +2 -4
  78. package/src/commands/workspace-commands.ts +9 -23
  79. package/src/config/config.ts +7 -81
  80. package/src/config/recent-activity.ts +24 -12
  81. package/src/config/workspaces.ts +0 -24
  82. package/src/index.ts +16 -15
  83. package/src/providers/provider-loader.ts +13 -5
  84. package/src/shared-types-extra.ts +34 -0
  85. package/src/shared-types.d.ts +4 -6
  86. package/src/shared-types.ts +17 -38
  87. package/src/status/builders.ts +12 -0
  88. package/src/status/reporter.ts +2 -1
  89. package/src/status/snapshot.ts +70 -87
  90. package/src/types.ts +3 -8
  91. package/dist/index.d.mts +0 -2504
  92. package/dist/normalize-DVI4Lo5I.d.mts +0 -947
  93. package/dist/normalize-DVI4Lo5I.d.ts +0 -947
  94. package/dist/status/normalize.d.mts +0 -1
  95. package/src/config/workspace-activity.ts +0 -65
@@ -0,0 +1,25 @@
1
+ /**
2
+ * CliAdapter — common interface for CLI agents
3
+ *
4
+ * Contract implemented by all CLI adapters (ProviderCliAdapter etc).
5
+ */
6
+ export interface CliAdapter {
7
+ cliType: string;
8
+ cliName: string;
9
+ workingDir: string;
10
+ spawn(): Promise<void>;
11
+ sendMessage(text: string): Promise<void>;
12
+ getStatus(): any;
13
+ getPartialResponse(): string;
14
+ saveAndStop?(): Promise<void>;
15
+ shutdown(): void;
16
+ detach?(): void;
17
+ cancel(): void;
18
+ isProcessing(): boolean;
19
+ isReady(): boolean;
20
+ setOnStatusChange(callback: () => void): void;
21
+ setServerConn?(serverConn: any): void;
22
+ setOnPtyData?(callback: (data: string) => void): void;
23
+ writeRaw?(data: string): void;
24
+ resize?(cols: number, rows: number): void;
25
+ }
@@ -0,0 +1,229 @@
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 { ProviderResumeCapability } from '../providers/contracts.js';
18
+ import { type PtyRuntimeMetadata, type PtyTransportFactory } from './pty-transport.js';
19
+ export interface CliChatMessage {
20
+ role: 'user' | 'assistant';
21
+ content: string;
22
+ timestamp?: number;
23
+ }
24
+ export interface CliSessionStatus {
25
+ status: 'idle' | 'generating' | 'waiting_approval' | 'error' | 'stopped' | 'starting';
26
+ messages: CliChatMessage[];
27
+ workingDir: string;
28
+ activeModal: {
29
+ message: string;
30
+ buttons: string[];
31
+ } | null;
32
+ terminalHistory?: string;
33
+ }
34
+ /**
35
+ * CLI Script Functions.
36
+ * Unlike IDE scripts (which return JS code strings for CDP evaluate),
37
+ * CLI scripts are Node.js functions that receive PTY buffer data and return structured results.
38
+ */
39
+ export interface CliScripts {
40
+ /** Full PTY buffer → ReadChatResult (messages, status, activeModal) */
41
+ parseOutput?: (input: CliScriptInput) => any;
42
+ /** Lightweight status detection (high-frequency polling) → AgentStatus string */
43
+ detectStatus?: (input: {
44
+ tail: string;
45
+ screenText?: string;
46
+ rawBuffer?: string;
47
+ }) => string | null;
48
+ /** Parse approval modal from PTY output → ModalInfo | null */
49
+ parseApproval?: (input: {
50
+ buffer: string;
51
+ screenText?: string;
52
+ rawBuffer?: string;
53
+ tail: string;
54
+ }) => {
55
+ message: string;
56
+ buttons: string[];
57
+ } | null;
58
+ /** Produce a cli-specific prompt from a dashboard action payload */
59
+ resolveAction?: (data: any) => string;
60
+ /** Custom scripts */
61
+ [name: string]: ((input: any) => any) | undefined;
62
+ }
63
+ export interface CliScriptInput {
64
+ buffer: string;
65
+ rawBuffer: string;
66
+ recentBuffer: string;
67
+ screenText: string;
68
+ terminalHistory?: string;
69
+ messages: CliChatMessage[];
70
+ partialResponse: string;
71
+ }
72
+ export interface CliProviderModule {
73
+ type: string;
74
+ name: string;
75
+ category: 'cli';
76
+ binary: string;
77
+ sendDelayMs?: number;
78
+ sendKey?: string;
79
+ submitStrategy?: 'wait_for_echo' | 'immediate';
80
+ spawn: {
81
+ command: string;
82
+ args: string[];
83
+ shell: boolean;
84
+ env: Record<string, string>;
85
+ };
86
+ timeouts?: {
87
+ /** PTY output batch transmit interval (default 50ms) */
88
+ ptyFlush?: number;
89
+ /** Wait for startup dialog auto-proceed (default 300ms) */
90
+ dialogAccept?: number;
91
+ /** Approval detect cooldown (default 2000ms) */
92
+ approvalCooldown?: number;
93
+ /** Check for completion on no-response during generating (default 6000ms) */
94
+ generatingIdle?: number;
95
+ /** Check for completion on no-response (default 5000ms) */
96
+ idleFinish?: number;
97
+ /** Max response wait (default 300000ms = 5min) */
98
+ maxResponse?: number;
99
+ /** shutdown after kill wait (default 1000ms) */
100
+ shutdownGrace?: number;
101
+ /** Output settle debounce before evaluating status (default 300ms) */
102
+ outputSettle?: number;
103
+ };
104
+ resume?: ProviderResumeCapability;
105
+ }
106
+ /**
107
+ * Normalize raw provider JSON for auto-implement approval patterns.
108
+ * Used by dev-server only — ProviderCliAdapter itself uses scripts.
109
+ */
110
+ export declare function normalizeCliProviderForRuntime(raw: any): {
111
+ patterns: {
112
+ approval: RegExp[];
113
+ };
114
+ };
115
+ export declare class ProviderCliAdapter implements CliAdapter {
116
+ private extraArgs;
117
+ readonly cliType: string;
118
+ readonly cliName: string;
119
+ workingDir: string;
120
+ private provider;
121
+ private ptyProcess;
122
+ private transportFactory;
123
+ private messages;
124
+ private committedMessages;
125
+ private structuredMessages;
126
+ private currentStatus;
127
+ private onStatusChange;
128
+ private responseBuffer;
129
+ private recentOutputBuffer;
130
+ private isWaitingForResponse;
131
+ private activeModal;
132
+ private responseTimeout;
133
+ private idleTimeout;
134
+ private ready;
135
+ private startupBuffer;
136
+ private startupParseGate;
137
+ private spawnAt;
138
+ private onPtyDataCallback;
139
+ private pendingOutputParseBuffer;
140
+ private pendingOutputParseTimer;
141
+ private ptyOutputBuffer;
142
+ private ptyOutputFlushTimer;
143
+ private serverConn;
144
+ private logBuffer;
145
+ private lastApprovalResolvedAt;
146
+ private approvalTransitionBuffer;
147
+ private approvalExitTimeout;
148
+ private pendingScriptStatus;
149
+ private pendingScriptStatusSince;
150
+ private pendingScriptStatusTimer;
151
+ private settleTimer;
152
+ private settledBuffer;
153
+ private submitPendingUntil;
154
+ private responseSettleIgnoreUntil;
155
+ private responseEpoch;
156
+ private submitRetryTimer;
157
+ private submitRetryUsed;
158
+ private submitRetryPromptSnippet;
159
+ private resizeSuppressUntil;
160
+ private statusHistory;
161
+ private cliScripts;
162
+ /** Full accumulated ANSI-stripped PTY output */
163
+ private accumulatedBuffer;
164
+ /** Full accumulated raw PTY output (with ANSI) */
165
+ private accumulatedRawBuffer;
166
+ /** Current visible terminal screen snapshot */
167
+ private terminalScreen;
168
+ /** Rolling append-only terminal transcript built from screen snapshots */
169
+ private terminalHistory;
170
+ /** Max accumulated buffer size (last 50KB) */
171
+ private static readonly MAX_ACCUMULATED_BUFFER;
172
+ private currentTurnScope;
173
+ private syncMessageViews;
174
+ private sliceFromOffset;
175
+ private buildParseInput;
176
+ private setStatus;
177
+ private readonly timeouts;
178
+ private readonly approvalKeys;
179
+ private readonly sendDelayMs;
180
+ private readonly sendKey;
181
+ private readonly submitStrategy;
182
+ private static readonly SCRIPT_STATUS_DEBOUNCE_MS;
183
+ constructor(provider: CliProviderModule, workingDir: string, extraArgs?: string[], transportFactory?: PtyTransportFactory);
184
+ /** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
185
+ setCliScripts(scripts: CliScripts): void;
186
+ setServerConn(serverConn: any): void;
187
+ setOnStatusChange(callback: () => void): void;
188
+ setOnPtyData(callback: (data: string) => void): void;
189
+ private flushPendingOutputParse;
190
+ spawn(): Promise<void>;
191
+ private handleOutput;
192
+ private scheduleSettle;
193
+ private armApprovalExitTimeout;
194
+ private looksLikeVisibleIdlePrompt;
195
+ private evaluateSettled;
196
+ private finishResponse;
197
+ private commitCurrentTranscript;
198
+ private runDetectStatus;
199
+ private runParseApproval;
200
+ getStatus(): CliSessionStatus;
201
+ /**
202
+ * Script-based full parse — returns ReadChatResult.
203
+ * Called by command handler / dashboard for rich content rendering.
204
+ */
205
+ getScriptParsedStatus(): any;
206
+ private parseCurrentTranscript;
207
+ /** Whether this adapter has CLI scripts loaded */
208
+ hasCliScripts(): boolean;
209
+ /**
210
+ * Resolves an action (like 'fix' lint error) from the dashboard.
211
+ * Uses resolveAction script if available, otherwise falls back to standard text.
212
+ */
213
+ resolveAction(data: any): Promise<void>;
214
+ sendMessage(text: string): Promise<void>;
215
+ getPartialResponse(): string;
216
+ getRuntimeMetadata(): PtyRuntimeMetadata | null;
217
+ cancel(): void;
218
+ saveAndStop(): Promise<void>;
219
+ private waitForStopped;
220
+ shutdown(): void;
221
+ detach(): void;
222
+ clearHistory(): void;
223
+ isProcessing(): boolean;
224
+ isReady(): boolean;
225
+ writeRaw(data: string): void;
226
+ resolveModal(buttonIndex: number): void;
227
+ resize(cols: number, rows: number): void;
228
+ getDebugState(): Record<string, any>;
229
+ }
@@ -0,0 +1,43 @@
1
+ export interface PtySpawnOptions {
2
+ cwd: string;
3
+ env: Record<string, string>;
4
+ cols: number;
5
+ rows: number;
6
+ }
7
+ export interface PtyRuntimeWriteOwner {
8
+ clientId: string;
9
+ ownerType: 'agent' | 'user';
10
+ }
11
+ export interface PtyRuntimeClientInfo {
12
+ clientId: string;
13
+ type: 'daemon' | 'web' | 'local-terminal';
14
+ readOnly: boolean;
15
+ }
16
+ export interface PtyRuntimeMetadata {
17
+ runtimeId: string;
18
+ runtimeKey?: string;
19
+ displayName?: string;
20
+ workspaceLabel?: string;
21
+ writeOwner?: PtyRuntimeWriteOwner | null;
22
+ attachedClients?: PtyRuntimeClientInfo[];
23
+ }
24
+ export interface PtyRuntimeTransport {
25
+ readonly pid: number;
26
+ readonly ready: Promise<void>;
27
+ write(data: string): void;
28
+ resize(cols: number, rows: number): void;
29
+ kill(): void;
30
+ clearBuffer?(): void;
31
+ detach?(): void;
32
+ getMetadata?(): PtyRuntimeMetadata | null;
33
+ onData(callback: (data: string) => void): void;
34
+ onExit(callback: (info: {
35
+ exitCode: number;
36
+ }) => void): void;
37
+ }
38
+ export interface PtyTransportFactory {
39
+ spawn(command: string, args: string[], options: PtySpawnOptions): PtyRuntimeTransport;
40
+ }
41
+ export declare class NodePtyTransportFactory implements PtyTransportFactory {
42
+ spawn(command: string, args: string[], options: PtySpawnOptions): PtyRuntimeTransport;
43
+ }
@@ -0,0 +1,19 @@
1
+ import { type SessionHostEndpoint, type SessionHostCategory } from '@adhdev/session-host-core';
2
+ import type { PtyRuntimeTransport, PtySpawnOptions, PtyTransportFactory } from './pty-transport.js';
3
+ interface SessionHostPtyTransportFactoryOptions {
4
+ endpoint?: SessionHostEndpoint;
5
+ appName?: string;
6
+ clientId: string;
7
+ runtimeId: string;
8
+ providerType: string;
9
+ category?: SessionHostCategory;
10
+ workspace: string;
11
+ meta?: Record<string, unknown>;
12
+ attachExisting?: boolean;
13
+ }
14
+ export declare class SessionHostPtyTransportFactory implements PtyTransportFactory {
15
+ private readonly options;
16
+ constructor(options: SessionHostPtyTransportFactoryOptions);
17
+ spawn(command: string, args: string[], spawnOptions: PtySpawnOptions): PtyRuntimeTransport;
18
+ }
19
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { TerminalViewportBackend, TerminalViewportBackendOptions, TerminalViewportBackendPreference } from './types.js';
2
+ export declare function resolveTerminalBackendPreference(): TerminalViewportBackendPreference;
3
+ export declare function isGhosttyVtBackendAvailable(): boolean;
4
+ export declare class GhosttyVtTerminalBackend implements TerminalViewportBackend {
5
+ readonly kind: "ghostty-vt";
6
+ private terminal;
7
+ constructor(options: TerminalViewportBackendOptions);
8
+ resize(rows: number, cols: number): void;
9
+ write(data: string): void;
10
+ getText(): string;
11
+ dispose(): void;
12
+ }
@@ -0,0 +1,14 @@
1
+ export type TerminalViewportBackendKind = 'xterm' | 'ghostty-vt';
2
+ export type TerminalViewportBackendPreference = TerminalViewportBackendKind | 'auto';
3
+ export type TerminalViewportBackendOptions = {
4
+ rows: number;
5
+ cols: number;
6
+ scrollback: number;
7
+ };
8
+ export interface TerminalViewportBackend {
9
+ readonly kind: TerminalViewportBackendKind;
10
+ resize(rows: number, cols: number): void;
11
+ write(data: string): void;
12
+ getText(): string;
13
+ dispose(): void;
14
+ }
@@ -0,0 +1,13 @@
1
+ import type { TerminalViewportBackend, TerminalViewportBackendOptions } from './types.js';
2
+ export declare class XtermTerminalBackend implements TerminalViewportBackend {
3
+ readonly kind: "xterm";
4
+ private rows;
5
+ private cols;
6
+ private terminal;
7
+ constructor(options: TerminalViewportBackendOptions);
8
+ resize(rows: number, cols: number): void;
9
+ write(data: string): void;
10
+ getText(): string;
11
+ dispose(): void;
12
+ private createTerminal;
13
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * PTY screen snapshot abstraction.
3
+ *
4
+ * We currently keep xterm as the default parser/model because it is already
5
+ * proven in production, but the surface is now backend-agnostic so we can
6
+ * swap in libghostty-vt once a native Node binding is available.
7
+ */
8
+ import type { TerminalViewportBackendKind, TerminalViewportBackendPreference } from './terminal-backends/types.js';
9
+ export declare function getTerminalBackendRuntimeStatus(): {
10
+ backend: TerminalViewportBackendKind;
11
+ preference: TerminalViewportBackendPreference;
12
+ ghosttyAvailable: boolean;
13
+ };
14
+ export declare class TerminalScreen {
15
+ readonly backendKind: TerminalViewportBackendKind;
16
+ private rows;
17
+ private cols;
18
+ private readonly preference;
19
+ private terminal;
20
+ constructor(rows?: number, cols?: number);
21
+ reset(rows?: number, cols?: number): void;
22
+ resize(rows: number, cols: number): void;
23
+ write(data: string): void;
24
+ getText(): string;
25
+ dispose(): void;
26
+ private createBackend;
27
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * CDP Commands — cdpEval, screenshot, cdpCommand, cdpBatch, cdpRemoteAction,
3
+ * discoverAgents, file operations
4
+ */
5
+ import type { CommandResult, CommandHelpers } from './handler.js';
6
+ export declare function handleCdpEval(h: CommandHelpers, args: any): Promise<CommandResult>;
7
+ export declare function handleScreenshot(h: CommandHelpers, args: any): Promise<CommandResult>;
8
+ export declare function handleCdpCommand(h: CommandHelpers, args: any): Promise<CommandResult>;
9
+ export declare function handleCdpBatch(h: CommandHelpers, args: any): Promise<CommandResult>;
10
+ export declare function handleCdpRemoteAction(h: CommandHelpers, args: any): Promise<CommandResult>;
11
+ export declare function handleDiscoverAgents(h: CommandHelpers, args: any): Promise<CommandResult>;
12
+ export declare function handleFileRead(h: CommandHelpers, args: any): Promise<CommandResult>;
13
+ export declare function handleFileWrite(h: CommandHelpers, args: any): Promise<CommandResult>;
14
+ export declare function handleFileList(h: CommandHelpers, args: any): Promise<CommandResult>;
15
+ export declare function handleFileListBrowse(h: CommandHelpers, args: any): Promise<CommandResult>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Chat Commands — readChat, sendChat, listChats, newChat, switchChat,
3
+ * setMode, changeModel, setThoughtLevel, resolveAction, chatHistory
4
+ */
5
+ import type { CommandResult, CommandHelpers } from './handler.js';
6
+ export declare function handleChatHistory(h: CommandHelpers, args: any): Promise<CommandResult>;
7
+ export declare function handleReadChat(h: CommandHelpers, args: any): Promise<CommandResult>;
8
+ export declare function handleSendChat(h: CommandHelpers, args: any): Promise<CommandResult>;
9
+ export declare function handleListChats(h: CommandHelpers, args: any): Promise<CommandResult>;
10
+ export declare function handleNewChat(h: CommandHelpers, args: any): Promise<CommandResult>;
11
+ export declare function handleSwitchChat(h: CommandHelpers, args: any): Promise<CommandResult>;
12
+ export declare function handleSetMode(h: CommandHelpers, args: any): Promise<CommandResult>;
13
+ export declare function handleChangeModel(h: CommandHelpers, args: any): Promise<CommandResult>;
14
+ export declare function handleSetThoughtLevel(h: CommandHelpers, args: any): Promise<CommandResult>;
15
+ export declare function handleResolveAction(h: CommandHelpers, args: any): Promise<CommandResult>;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * DaemonCliManager — CLI session creation, management, and command handling
3
+ *
4
+ * Separated from adhdev-daemon.ts.
5
+ * CLI cases of createAdapter, startCliSession, stopCliSession, executeDaemonCommand extracted to independent module extract.
6
+ */
7
+ import type { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
8
+ import { ProviderLoader } from '../providers/provider-loader.js';
9
+ import type { CliAdapter } from '../cli-adapter-types.js';
10
+ import type { PtyTransportFactory } from '../cli-adapters/pty-transport.js';
11
+ import type { SessionRegistry } from '../sessions/registry.js';
12
+ export interface CliManagerDeps {
13
+ /** Server connection — injected into adapter */
14
+ getServerConn(): any | null;
15
+ /** P2P — PTY output transmit */
16
+ getP2p(): {
17
+ broadcastPtyOutput(key: string, data: string): void;
18
+ } | null;
19
+ /** StatusReporter callback */
20
+ onStatusChange(): void;
21
+ removeAgentTracking(key: string): void;
22
+ /** InstanceManager — register in CLI unified status */
23
+ getInstanceManager(): ProviderInstanceManager | null;
24
+ getSessionRegistry?(): SessionRegistry | null;
25
+ createPtyTransportFactory?: (params: CliTransportFactoryParams) => PtyTransportFactory | null;
26
+ listHostedCliRuntimes?: () => Promise<HostedCliRuntimeDescriptor[]>;
27
+ }
28
+ type CommandResult = {
29
+ success: boolean;
30
+ [key: string]: unknown;
31
+ };
32
+ export interface CliTransportFactoryParams {
33
+ runtimeId: string;
34
+ providerType: string;
35
+ workspace: string;
36
+ cliArgs?: string[];
37
+ attachExisting?: boolean;
38
+ }
39
+ export interface HostedCliRuntimeDescriptor {
40
+ runtimeId: string;
41
+ runtimeKey?: string;
42
+ displayName?: string;
43
+ workspaceLabel?: string;
44
+ lifecycle?: 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted';
45
+ recoveryState?: string | null;
46
+ cliType: string;
47
+ workspace: string;
48
+ cliArgs?: string[];
49
+ }
50
+ export declare class DaemonCliManager {
51
+ readonly adapters: Map<string, CliAdapter>;
52
+ private deps;
53
+ private providerLoader;
54
+ constructor(deps: CliManagerDeps, providerLoader: ProviderLoader);
55
+ getCliKey(cliType: string, dir: string): string;
56
+ private persistRecentActivity;
57
+ private getTransportFactory;
58
+ private createAdapter;
59
+ private startCliExitMonitor;
60
+ private registerCliInstance;
61
+ startSession(cliType: string, workingDir: string, cliArgs?: string[], initialModel?: string): Promise<void>;
62
+ stopSession(key: string): Promise<void>;
63
+ stopSessionWithMode(key: string, mode: 'hard' | 'save'): Promise<void>;
64
+ shutdownAll(): void;
65
+ detachAll(): void;
66
+ restoreHostedSessions(records?: HostedCliRuntimeDescriptor[]): Promise<number>;
67
+ /**
68
+ * Search for CLI adapter. Priority order:
69
+ * 0. sessionId (UUID direct match)
70
+ * 1. agentType + dir (iteration match)
71
+ * 2. agentType fuzzy match (⚠ returns first match when multiple sessions exist)
72
+ */
73
+ findAdapter(agentType: string, opts?: {
74
+ dir?: string;
75
+ instanceKey?: string;
76
+ }): {
77
+ adapter: CliAdapter;
78
+ key: string;
79
+ } | null;
80
+ handleCliCommand(cmd: string, args: any): Promise<CommandResult | null>;
81
+ }
82
+ export {};
@@ -0,0 +1,101 @@
1
+ /**
2
+ * DaemonCommandHandler — unified command routing for CDP & CLI
3
+ *
4
+ * Routes incoming commands (from server WS, P2P, or local WS) to
5
+ * the correct CDP manager or CLI adapter.
6
+ *
7
+ * Key concepts:
8
+ * - extractIdeType(): determines target IDE from targetSessionId or ideType
9
+ * - getCdp(): returns the DaemonCdpManager for current command
10
+ * - getProvider(): returns the ProviderModule for current command
11
+ * - handle(): main entry point, sets context then dispatches
12
+ */
13
+ import type { DaemonCdpManager } from '../cdp/manager.js';
14
+ import { ProviderLoader } from '../providers/provider-loader.js';
15
+ import type { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
16
+ import type { ProviderModule } from '../providers/contracts.js';
17
+ import type { DaemonAgentStreamManager } from '../agent-stream/index.js';
18
+ import { ChatHistoryWriter } from '../config/chat-history.js';
19
+ import type { SessionRegistry, SessionRuntimeTarget } from '../sessions/registry.js';
20
+ export interface CommandResult {
21
+ success: boolean;
22
+ [key: string]: unknown;
23
+ }
24
+ export interface CommandContext {
25
+ cdpManagers: Map<string, DaemonCdpManager>;
26
+ ideType: string;
27
+ adapters: Map<string, any>;
28
+ providerLoader?: ProviderLoader;
29
+ /** ProviderInstanceManager — for runtime settings propagation */
30
+ instanceManager?: ProviderInstanceManager;
31
+ sessionRegistry?: SessionRegistry;
32
+ }
33
+ /**
34
+ * Shared helpers interface — passed to sub-module command functions
35
+ * for accessing CDP, providers, agent streams, and other handler-owned state.
36
+ */
37
+ export interface CommandHelpers {
38
+ getCdp(ideType?: string): DaemonCdpManager | null;
39
+ getProvider(overrideType?: string): ProviderModule | undefined;
40
+ getProviderScript(scriptName: string, params?: Record<string, string>, ideType?: string): string | null;
41
+ evaluateProviderScript(scriptName: string, params?: Record<string, string>, timeout?: number): Promise<{
42
+ result: any;
43
+ category: string;
44
+ } | null>;
45
+ getCliAdapter(type?: string): any | null;
46
+ readonly currentManagerKey: string | undefined;
47
+ readonly currentIdeType: string | undefined;
48
+ readonly currentProviderType: string | undefined;
49
+ readonly currentSession: SessionRuntimeTarget | undefined;
50
+ readonly agentStream: DaemonAgentStreamManager | null;
51
+ readonly ctx: CommandContext;
52
+ readonly historyWriter: ChatHistoryWriter;
53
+ }
54
+ export declare class DaemonCommandHandler implements CommandHelpers {
55
+ private _ctx;
56
+ private _agentStream;
57
+ private domHandlers;
58
+ private _historyWriter;
59
+ /** Current request route context */
60
+ private _currentRoute;
61
+ constructor(ctx: CommandContext);
62
+ get ctx(): CommandContext;
63
+ get agentStream(): DaemonAgentStreamManager | null;
64
+ get historyWriter(): ChatHistoryWriter;
65
+ get currentManagerKey(): string | undefined;
66
+ get currentIdeType(): string | undefined;
67
+ get currentProviderType(): string | undefined;
68
+ get currentSession(): SessionRuntimeTarget | undefined;
69
+ /** Get CDP manager for a specific session or manager key. */
70
+ getCdp(ideType?: string): DaemonCdpManager | null;
71
+ /**
72
+ * Get provider module — _currentProviderType (agentType priority) use.
73
+ */
74
+ getProvider(overrideType?: string): ProviderModule | undefined;
75
+ /** Get a provider script by name from ProviderLoader. */
76
+ getProviderScript(scriptName: string, params?: Record<string, string>, ideType?: string): string | null;
77
+ /**
78
+ * per-category CDP script execute:
79
+ * IDE → cdp.evaluate(script) (main window)
80
+ * Extension → cdp.evaluateInSession(sessionId, script) (webview)
81
+ */
82
+ evaluateProviderScript(scriptName: string, params?: Record<string, string>, timeout?: number): Promise<{
83
+ result: any;
84
+ category: string;
85
+ } | null>;
86
+ /** CLI adapter search */
87
+ getCliAdapter(type?: string): any | null;
88
+ private inferProviderType;
89
+ private resolveRoute;
90
+ /** Extract CDP scope key from target session or explicit ideType */
91
+ private extractIdeType;
92
+ private logCommandStart;
93
+ private logCommandEnd;
94
+ setAgentStreamManager(manager: DaemonAgentStreamManager): void;
95
+ handle(cmd: string, args: any): Promise<CommandResult>;
96
+ private dispatch;
97
+ private handleRefreshScripts;
98
+ private proxyDevServerPost;
99
+ private proxyDevServerGet;
100
+ private proxyDevServerScaffold;
101
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * DaemonCommandRouter — Unified command routing for daemon-level commands
3
+ *
4
+ * Unified command routing for daemon-level commands.
5
+ *
6
+ * Routing flow:
7
+ * 1. Daemon-level commands (launch_ide, stop_ide, restart_ide, etc.) → handled here
8
+ * 2. CLI/ACP commands → delegated to cliManager
9
+ * 3. Everything else → delegated to commandHandler.handle()
10
+ */
11
+ import { DaemonCdpManager } from '../cdp/manager.js';
12
+ import { DaemonCommandHandler } from './handler.js';
13
+ import { DaemonCliManager } from './cli-manager.js';
14
+ import type { ProviderLoader } from '../providers/provider-loader.js';
15
+ import type { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
16
+ import { SessionRegistry } from '../sessions/registry.js';
17
+ export interface CommandRouterDeps {
18
+ commandHandler: DaemonCommandHandler;
19
+ cliManager: DaemonCliManager;
20
+ cdpManagers: Map<string, DaemonCdpManager>;
21
+ providerLoader: ProviderLoader;
22
+ instanceManager: ProviderInstanceManager;
23
+ /** Reference to detected IDEs array (mutable — router updates it) */
24
+ detectedIdes: {
25
+ value: any[];
26
+ };
27
+ sessionRegistry: SessionRegistry;
28
+ /** Callback for CDP manager creation after launch_ide */
29
+ onCdpManagerCreated?: (ideType: string, manager: DaemonCdpManager) => void;
30
+ /** Callback after IDE connected (e.g., startAgentStreamPolling) */
31
+ onIdeConnected?: () => void;
32
+ /** Callback after status change (stop_ide, restart) */
33
+ onStatusChange?: () => void;
34
+ /** Callback after chat-related commands */
35
+ onPostChatCommand?: () => void;
36
+ /** Get a connected CDP manager (for agent stream reset check) */
37
+ getCdpLogFn?: (ideType: string) => (msg: string) => void;
38
+ /** Package name for upgrade detection ('adhdev' or '@adhdev/daemon-standalone') */
39
+ packageName?: string;
40
+ }
41
+ export interface CommandRouterResult {
42
+ success: boolean;
43
+ [key: string]: unknown;
44
+ }
45
+ export declare class DaemonCommandRouter {
46
+ private deps;
47
+ constructor(deps: CommandRouterDeps);
48
+ /**
49
+ * Unified command routing.
50
+ * Returns result for all commands:
51
+ * 1. Daemon-level commands (launch_ide, stop_ide, etc.)
52
+ * 2. CLI commands (launch_cli, stop_cli, agent_command)
53
+ * 3. DaemonCommandHandler delegation (CDP/agent-stream/file commands)
54
+ *
55
+ * @param cmd Command name
56
+ * @param args Command arguments
57
+ * @param source Log source ('ws' | 'p2p' | 'standalone' | etc.)
58
+ */
59
+ execute(cmd: string, args: any, source?: string): Promise<CommandRouterResult>;
60
+ /**
61
+ * Daemon-level command execution (IDE start/stop/restart, CLI, detect, logs).
62
+ * Returns null if not handled at this level → caller delegates to CommandHandler.
63
+ */
64
+ private executeDaemonCommand;
65
+ /**
66
+ * IDE stop: CDP disconnect + InstanceManager cleanup + optionally kill OS process
67
+ */
68
+ private stopIde;
69
+ }