@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
package/src/status/builders.ts
CHANGED
|
@@ -17,7 +17,35 @@ import type {
|
|
|
17
17
|
ExtensionProviderState,
|
|
18
18
|
ProviderState,
|
|
19
19
|
} from '../providers/provider-instance.js';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
LIVE_STATUS_ACTIVE_CHAT_OPTIONS,
|
|
22
|
+
normalizeActiveChatData,
|
|
23
|
+
normalizeManagedStatus,
|
|
24
|
+
type NormalizeActiveChatOptions,
|
|
25
|
+
} from './normalize.js';
|
|
26
|
+
|
|
27
|
+
export type SessionEntryProfile = 'full' | 'live' | 'metadata';
|
|
28
|
+
|
|
29
|
+
export interface SessionEntryBuildOptions {
|
|
30
|
+
profile?: SessionEntryProfile;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getActiveChatOptions(profile: SessionEntryProfile): NormalizeActiveChatOptions {
|
|
34
|
+
if (profile === 'full') return {};
|
|
35
|
+
return LIVE_STATUS_ACTIVE_CHAT_OPTIONS;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function shouldIncludeSessionControls(profile: SessionEntryProfile): boolean {
|
|
39
|
+
return profile !== 'live';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function shouldIncludeSessionMetadata(profile: SessionEntryProfile): boolean {
|
|
43
|
+
return profile !== 'live';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function shouldIncludeRuntimeMetadata(profile: SessionEntryProfile): boolean {
|
|
47
|
+
return profile !== 'live';
|
|
48
|
+
}
|
|
21
49
|
|
|
22
50
|
// ─── CDP Manager lookup helpers ──────────────────────
|
|
23
51
|
|
|
@@ -186,33 +214,39 @@ const ACP_SESSION_CAPABILITIES: SessionCapability[] = [
|
|
|
186
214
|
function buildIdeWorkspaceSession(
|
|
187
215
|
state: IdeProviderState,
|
|
188
216
|
cdpManagers: Map<string, DaemonCdpManager>,
|
|
217
|
+
options: SessionEntryBuildOptions,
|
|
189
218
|
): SessionEntry {
|
|
190
|
-
const
|
|
219
|
+
const profile = options.profile || 'full';
|
|
220
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
221
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
222
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
191
223
|
const title = activeChat?.title || state.name;
|
|
192
224
|
return {
|
|
193
225
|
id: state.instanceId || state.type,
|
|
194
226
|
parentId: null,
|
|
195
227
|
providerType: state.type,
|
|
196
|
-
providerName: state.name,
|
|
228
|
+
...(includeSessionMetadata && { providerName: state.name }),
|
|
197
229
|
kind: 'workspace',
|
|
198
230
|
transport: 'cdp-page',
|
|
199
231
|
status: normalizeManagedStatus(activeChat?.status || state.status, {
|
|
200
232
|
activeModal: activeChat?.activeModal || null,
|
|
201
233
|
}),
|
|
202
234
|
title,
|
|
203
|
-
workspace: state.workspace || null,
|
|
235
|
+
...(includeSessionMetadata && { workspace: state.workspace || null }),
|
|
204
236
|
activeChat,
|
|
205
|
-
capabilities: IDE_SESSION_CAPABILITIES,
|
|
237
|
+
...(includeSessionMetadata && { capabilities: IDE_SESSION_CAPABILITIES }),
|
|
206
238
|
cdpConnected: state.cdpConnected ?? isCdpConnected(cdpManagers, state.type),
|
|
207
239
|
currentModel: state.currentModel,
|
|
208
240
|
currentPlan: state.currentPlan,
|
|
209
241
|
currentAutoApprove: state.currentAutoApprove,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
242
|
+
...(includeSessionControls && {
|
|
243
|
+
controlValues: state.controlValues,
|
|
244
|
+
providerControls: buildFallbackControls(
|
|
245
|
+
state.providerControls,
|
|
246
|
+
state.currentModel,
|
|
247
|
+
state.currentPlan
|
|
248
|
+
),
|
|
249
|
+
}),
|
|
216
250
|
errorMessage: state.errorMessage,
|
|
217
251
|
errorReason: state.errorReason,
|
|
218
252
|
lastUpdated: state.lastUpdated,
|
|
@@ -222,43 +256,53 @@ function buildIdeWorkspaceSession(
|
|
|
222
256
|
function buildExtensionAgentSession(
|
|
223
257
|
parent: IdeProviderState,
|
|
224
258
|
ext: ExtensionProviderState,
|
|
259
|
+
options: SessionEntryBuildOptions,
|
|
225
260
|
): SessionEntry {
|
|
226
|
-
const
|
|
261
|
+
const profile = options.profile || 'full';
|
|
262
|
+
const activeChat = normalizeActiveChatData(ext.activeChat, getActiveChatOptions(profile));
|
|
263
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
264
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
227
265
|
return {
|
|
228
266
|
id: ext.instanceId || `${parent.instanceId}:${ext.type}`,
|
|
229
267
|
parentId: parent.instanceId || parent.type,
|
|
230
268
|
providerType: ext.type,
|
|
231
|
-
providerName: ext.name,
|
|
269
|
+
...(includeSessionMetadata && { providerName: ext.name }),
|
|
232
270
|
kind: 'agent',
|
|
233
271
|
transport: 'cdp-webview',
|
|
234
272
|
status: normalizeManagedStatus(activeChat?.status || ext.status, {
|
|
235
273
|
activeModal: activeChat?.activeModal || null,
|
|
236
274
|
}),
|
|
237
275
|
title: activeChat?.title || ext.name,
|
|
238
|
-
workspace: parent.workspace || null,
|
|
276
|
+
...(includeSessionMetadata && { workspace: parent.workspace || null }),
|
|
239
277
|
activeChat,
|
|
240
|
-
capabilities: EXTENSION_SESSION_CAPABILITIES,
|
|
278
|
+
...(includeSessionMetadata && { capabilities: EXTENSION_SESSION_CAPABILITIES }),
|
|
241
279
|
currentModel: ext.currentModel,
|
|
242
280
|
currentPlan: ext.currentPlan,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
281
|
+
...(includeSessionControls && {
|
|
282
|
+
controlValues: ext.controlValues,
|
|
283
|
+
providerControls: buildFallbackControls(
|
|
284
|
+
ext.providerControls,
|
|
285
|
+
ext.currentModel,
|
|
286
|
+
ext.currentPlan
|
|
287
|
+
),
|
|
288
|
+
}),
|
|
249
289
|
errorMessage: ext.errorMessage,
|
|
250
290
|
errorReason: ext.errorReason,
|
|
251
291
|
lastUpdated: ext.lastUpdated,
|
|
252
292
|
};
|
|
253
293
|
}
|
|
254
294
|
|
|
255
|
-
function buildCliSession(state: CliProviderState): SessionEntry {
|
|
256
|
-
const
|
|
295
|
+
function buildCliSession(state: CliProviderState, options: SessionEntryBuildOptions): SessionEntry {
|
|
296
|
+
const profile = options.profile || 'full';
|
|
297
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
298
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
299
|
+
const includeRuntimeMetadata = shouldIncludeRuntimeMetadata(profile);
|
|
300
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
257
301
|
return {
|
|
258
302
|
id: state.instanceId,
|
|
259
303
|
parentId: null,
|
|
260
304
|
providerType: state.type,
|
|
261
|
-
providerName: state.name,
|
|
305
|
+
...(includeSessionMetadata && { providerName: state.name }),
|
|
262
306
|
providerSessionId: state.providerSessionId,
|
|
263
307
|
kind: 'agent',
|
|
264
308
|
transport: 'pty',
|
|
@@ -266,54 +310,65 @@ function buildCliSession(state: CliProviderState): SessionEntry {
|
|
|
266
310
|
activeModal: activeChat?.activeModal || null,
|
|
267
311
|
}),
|
|
268
312
|
title: activeChat?.title || state.name,
|
|
269
|
-
workspace: state.workspace || null,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
313
|
+
...(includeSessionMetadata && { workspace: state.workspace || null }),
|
|
314
|
+
...(includeRuntimeMetadata && {
|
|
315
|
+
runtimeKey: state.runtime?.runtimeKey,
|
|
316
|
+
runtimeDisplayName: state.runtime?.displayName,
|
|
317
|
+
runtimeWorkspaceLabel: state.runtime?.workspaceLabel,
|
|
318
|
+
runtimeWriteOwner: state.runtime?.writeOwner || null,
|
|
319
|
+
runtimeAttachedClients: state.runtime?.attachedClients || [],
|
|
320
|
+
}),
|
|
275
321
|
mode: state.mode,
|
|
276
322
|
resume: state.resume,
|
|
277
323
|
activeChat,
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
324
|
+
...(includeSessionMetadata && {
|
|
325
|
+
capabilities: state.mode === 'terminal' ? PTY_SESSION_CAPABILITIES : CLI_CHAT_SESSION_CAPABILITIES,
|
|
326
|
+
}),
|
|
327
|
+
...(includeSessionControls && {
|
|
328
|
+
controlValues: state.controlValues,
|
|
329
|
+
providerControls: buildFallbackControls(
|
|
330
|
+
state.providerControls
|
|
331
|
+
),
|
|
332
|
+
}),
|
|
283
333
|
errorMessage: state.errorMessage,
|
|
284
334
|
errorReason: state.errorReason,
|
|
285
335
|
lastUpdated: state.lastUpdated,
|
|
286
336
|
};
|
|
287
337
|
}
|
|
288
338
|
|
|
289
|
-
function buildAcpSession(state: AcpProviderState): SessionEntry {
|
|
290
|
-
const
|
|
339
|
+
function buildAcpSession(state: AcpProviderState, options: SessionEntryBuildOptions): SessionEntry {
|
|
340
|
+
const profile = options.profile || 'full';
|
|
341
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
342
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
343
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
291
344
|
return {
|
|
292
345
|
id: state.instanceId,
|
|
293
346
|
parentId: null,
|
|
294
347
|
providerType: state.type,
|
|
295
|
-
providerName: state.name,
|
|
348
|
+
...(includeSessionMetadata && { providerName: state.name }),
|
|
296
349
|
kind: 'agent',
|
|
297
350
|
transport: 'acp',
|
|
298
351
|
status: normalizeManagedStatus(activeChat?.status || state.status, {
|
|
299
352
|
activeModal: activeChat?.activeModal || null,
|
|
300
353
|
}),
|
|
301
354
|
title: activeChat?.title || state.name,
|
|
302
|
-
workspace: state.workspace || null,
|
|
355
|
+
...(includeSessionMetadata && { workspace: state.workspace || null }),
|
|
303
356
|
activeChat,
|
|
304
|
-
capabilities: ACP_SESSION_CAPABILITIES,
|
|
357
|
+
...(includeSessionMetadata && { capabilities: ACP_SESSION_CAPABILITIES }),
|
|
305
358
|
currentModel: state.currentModel,
|
|
306
359
|
currentPlan: state.currentPlan,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
360
|
+
...(includeSessionControls && {
|
|
361
|
+
acpConfigOptions: state.acpConfigOptions,
|
|
362
|
+
acpModes: state.acpModes,
|
|
363
|
+
controlValues: state.controlValues,
|
|
364
|
+
providerControls: buildFallbackControls(
|
|
365
|
+
state.providerControls,
|
|
366
|
+
state.currentModel,
|
|
367
|
+
state.currentPlan,
|
|
368
|
+
state.acpConfigOptions,
|
|
369
|
+
state.acpModes
|
|
370
|
+
),
|
|
371
|
+
}),
|
|
317
372
|
errorMessage: state.errorMessage,
|
|
318
373
|
errorReason: state.errorReason,
|
|
319
374
|
lastUpdated: state.lastUpdated,
|
|
@@ -323,6 +378,7 @@ function buildAcpSession(state: AcpProviderState): SessionEntry {
|
|
|
323
378
|
export function buildSessionEntries(
|
|
324
379
|
allStates: ProviderState[],
|
|
325
380
|
cdpManagers: Map<string, DaemonCdpManager>,
|
|
381
|
+
options: SessionEntryBuildOptions = {},
|
|
326
382
|
): SessionEntry[] {
|
|
327
383
|
const sessions: SessionEntry[] = [];
|
|
328
384
|
|
|
@@ -331,18 +387,18 @@ export function buildSessionEntries(
|
|
|
331
387
|
const acpStates = allStates.filter((s): s is AcpProviderState => s.category === 'acp');
|
|
332
388
|
|
|
333
389
|
for (const state of ideStates) {
|
|
334
|
-
sessions.push(buildIdeWorkspaceSession(state, cdpManagers));
|
|
390
|
+
sessions.push(buildIdeWorkspaceSession(state, cdpManagers, options));
|
|
335
391
|
for (const ext of state.extensions as ExtensionProviderState[]) {
|
|
336
|
-
sessions.push(buildExtensionAgentSession(state, ext));
|
|
392
|
+
sessions.push(buildExtensionAgentSession(state, ext, options));
|
|
337
393
|
}
|
|
338
394
|
}
|
|
339
395
|
|
|
340
396
|
for (const state of cliStates) {
|
|
341
|
-
sessions.push(buildCliSession(state));
|
|
397
|
+
sessions.push(buildCliSession(state, options));
|
|
342
398
|
}
|
|
343
399
|
|
|
344
400
|
for (const state of acpStates) {
|
|
345
|
-
sessions.push(buildAcpSession(state));
|
|
401
|
+
sessions.push(buildAcpSession(state, options));
|
|
346
402
|
}
|
|
347
403
|
|
|
348
404
|
// Hide native IDE parent rows from inbox/recent surfaces when extension tabs exist.
|
package/src/status/normalize.ts
CHANGED
|
@@ -20,13 +20,39 @@ const WORKING_STATUSES = new Set([
|
|
|
20
20
|
'active',
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
export interface NormalizeActiveChatOptions {
|
|
24
|
+
includeMessages?: boolean;
|
|
25
|
+
includeInputContent?: boolean;
|
|
26
|
+
includeActiveModal?: boolean;
|
|
27
|
+
messageLimit?: number;
|
|
28
|
+
totalBytesLimit?: number;
|
|
29
|
+
stringLimit?: number;
|
|
30
|
+
fallbackStringLimit?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Full snapshots are still capped, but can carry recent chat context for API/inspection use.
|
|
34
|
+
const FULL_STATUS_ACTIVE_CHAT_OPTIONS: Required<NormalizeActiveChatOptions> = {
|
|
35
|
+
includeMessages: true,
|
|
36
|
+
includeInputContent: true,
|
|
37
|
+
includeActiveModal: true,
|
|
38
|
+
messageLimit: 60,
|
|
39
|
+
totalBytesLimit: 96 * 1024,
|
|
40
|
+
stringLimit: 4 * 1024,
|
|
41
|
+
fallbackStringLimit: 1024,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Live/metadata snapshots only need routing + UI summary. Current chat text is loaded
|
|
45
|
+
// on demand via `read_chat`, and older history via `chat_history`.
|
|
46
|
+
export const LIVE_STATUS_ACTIVE_CHAT_OPTIONS: Required<NormalizeActiveChatOptions> = {
|
|
47
|
+
includeMessages: false,
|
|
48
|
+
includeInputContent: false,
|
|
49
|
+
includeActiveModal: false,
|
|
50
|
+
messageLimit: 0,
|
|
51
|
+
totalBytesLimit: 0,
|
|
52
|
+
stringLimit: 512,
|
|
53
|
+
fallbackStringLimit: 256,
|
|
54
|
+
};
|
|
55
|
+
|
|
30
56
|
const STATUS_MODAL_MESSAGE_LIMIT = 2 * 1024;
|
|
31
57
|
const STATUS_MODAL_BUTTON_LIMIT = 120;
|
|
32
58
|
|
|
@@ -81,23 +107,27 @@ function normalizeMessageTime(message: unknown): unknown {
|
|
|
81
107
|
return msg;
|
|
82
108
|
}
|
|
83
109
|
|
|
84
|
-
function trimMessagesForStatus(
|
|
110
|
+
function trimMessagesForStatus(
|
|
111
|
+
messages: unknown[] | null | undefined,
|
|
112
|
+
options: Required<NormalizeActiveChatOptions>,
|
|
113
|
+
): unknown[] {
|
|
114
|
+
if (!options.includeMessages || options.messageLimit <= 0 || options.totalBytesLimit <= 0) return [];
|
|
85
115
|
if (!Array.isArray(messages) || messages.length === 0) return [];
|
|
86
116
|
|
|
87
|
-
const recent = messages.slice(-
|
|
117
|
+
const recent = messages.slice(-options.messageLimit);
|
|
88
118
|
const kept: unknown[] = [];
|
|
89
119
|
let totalBytes = 0;
|
|
90
120
|
|
|
91
121
|
for (let i = recent.length - 1; i >= 0; i -= 1) {
|
|
92
|
-
let normalized = normalizeMessageTime(trimMessageForStatus(recent[i],
|
|
122
|
+
let normalized = normalizeMessageTime(trimMessageForStatus(recent[i], options.stringLimit));
|
|
93
123
|
let size = estimateBytes(normalized);
|
|
94
124
|
|
|
95
|
-
if (size >
|
|
96
|
-
normalized = normalizeMessageTime(trimMessageForStatus(recent[i],
|
|
125
|
+
if (size > options.totalBytesLimit) {
|
|
126
|
+
normalized = normalizeMessageTime(trimMessageForStatus(recent[i], options.fallbackStringLimit));
|
|
97
127
|
size = estimateBytes(normalized);
|
|
98
128
|
}
|
|
99
129
|
|
|
100
|
-
if (kept.length > 0 && (totalBytes + size) >
|
|
130
|
+
if (kept.length > 0 && (totalBytes + size) > options.totalBytesLimit) {
|
|
101
131
|
continue;
|
|
102
132
|
}
|
|
103
133
|
|
|
@@ -143,20 +173,25 @@ export function isManagedStatusWaiting(
|
|
|
143
173
|
|
|
144
174
|
export function normalizeActiveChatData<T extends ActiveChatData | null | undefined>(
|
|
145
175
|
activeChat: T,
|
|
176
|
+
options: NormalizeActiveChatOptions = FULL_STATUS_ACTIVE_CHAT_OPTIONS,
|
|
146
177
|
): T {
|
|
147
178
|
if (!activeChat) return activeChat;
|
|
179
|
+
const resolvedOptions: Required<NormalizeActiveChatOptions> = {
|
|
180
|
+
...FULL_STATUS_ACTIVE_CHAT_OPTIONS,
|
|
181
|
+
...options,
|
|
182
|
+
};
|
|
148
183
|
return {
|
|
149
184
|
...activeChat,
|
|
150
185
|
status: normalizeManagedStatus(activeChat.status, { activeModal: activeChat.activeModal }),
|
|
151
|
-
messages: trimMessagesForStatus(activeChat.messages) as T extends { messages: infer M } ? M : never,
|
|
152
|
-
activeModal: activeChat.activeModal ? {
|
|
186
|
+
messages: trimMessagesForStatus(activeChat.messages, resolvedOptions) as T extends { messages: infer M } ? M : never,
|
|
187
|
+
activeModal: resolvedOptions.includeActiveModal && activeChat.activeModal ? {
|
|
153
188
|
message: truncateString(activeChat.activeModal.message || '', STATUS_MODAL_MESSAGE_LIMIT),
|
|
154
189
|
buttons: (activeChat.activeModal.buttons || []).map((button) =>
|
|
155
190
|
truncateString(String(button || ''), STATUS_MODAL_BUTTON_LIMIT)
|
|
156
191
|
),
|
|
157
|
-
} :
|
|
158
|
-
inputContent: activeChat.inputContent
|
|
159
|
-
? truncateString(activeChat.inputContent,
|
|
160
|
-
:
|
|
192
|
+
} : null,
|
|
193
|
+
inputContent: resolvedOptions.includeInputContent && activeChat.inputContent
|
|
194
|
+
? truncateString(activeChat.inputContent, 2 * 1024)
|
|
195
|
+
: undefined,
|
|
161
196
|
} as T;
|
|
162
197
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DaemonStatusReporter — status collect & transmit (StatusReport / P2P / StatusEvent)
|
|
3
|
+
*
|
|
4
|
+
* Collect status from ProviderInstanceManager → assemble payload → transmit
|
|
5
|
+
* Each Instance manages its own status/transition. This module only assembles + transmits.
|
|
6
|
+
*/
|
|
7
|
+
import type { DaemonCdpManager } from '../cdp/manager.js';
|
|
8
|
+
import type { ProviderState } from '../providers/provider-instance.js';
|
|
9
|
+
export interface StatusReporterDeps {
|
|
10
|
+
serverConn: {
|
|
11
|
+
isConnected(): boolean;
|
|
12
|
+
sendMessage(type: string, data: any): void;
|
|
13
|
+
getUserPlan(): string;
|
|
14
|
+
} | null;
|
|
15
|
+
cdpManagers: Map<string, DaemonCdpManager>;
|
|
16
|
+
p2p: {
|
|
17
|
+
isConnected: boolean;
|
|
18
|
+
isAvailable: boolean;
|
|
19
|
+
connectionState: string;
|
|
20
|
+
connectedPeerCount: number;
|
|
21
|
+
screenshotActive: boolean;
|
|
22
|
+
sendStatus(data: any): void;
|
|
23
|
+
} | null;
|
|
24
|
+
providerLoader: {
|
|
25
|
+
resolve(type: string): any;
|
|
26
|
+
getAll(): any[];
|
|
27
|
+
};
|
|
28
|
+
detectedIdes: any[];
|
|
29
|
+
instanceId: string;
|
|
30
|
+
daemonVersion?: string;
|
|
31
|
+
instanceManager: {
|
|
32
|
+
collectAllStates(): ProviderState[];
|
|
33
|
+
collectStatesByCategory(cat: string): ProviderState[];
|
|
34
|
+
};
|
|
35
|
+
getScreenshotUsage?: () => {
|
|
36
|
+
dailyUsedMinutes: number;
|
|
37
|
+
dailyBudgetMinutes: number;
|
|
38
|
+
budgetExhausted: boolean;
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
export declare class DaemonStatusReporter {
|
|
42
|
+
private deps;
|
|
43
|
+
private log;
|
|
44
|
+
private lastStatusSentAt;
|
|
45
|
+
private statusPendingThrottle;
|
|
46
|
+
private lastP2PStatusHash;
|
|
47
|
+
private lastStatusSummary;
|
|
48
|
+
private statusTimer;
|
|
49
|
+
private p2pTimer;
|
|
50
|
+
constructor(deps: StatusReporterDeps, opts?: {
|
|
51
|
+
logFn?: (msg: string) => void;
|
|
52
|
+
});
|
|
53
|
+
startReporting(): void;
|
|
54
|
+
stopReporting(): void;
|
|
55
|
+
onStatusChange(): void;
|
|
56
|
+
throttledReport(): void;
|
|
57
|
+
emitStatusEvent(event: Record<string, unknown>): void;
|
|
58
|
+
removeAgentTracking(_key: string): void;
|
|
59
|
+
updateAgentStreams(_ideType: string, _streams: any[]): void;
|
|
60
|
+
/** Reset P2P dedup hash — forces next send to transmit even if content unchanged */
|
|
61
|
+
resetP2PHash(): void;
|
|
62
|
+
private ts;
|
|
63
|
+
private summarizeLargePayloadSessions;
|
|
64
|
+
sendUnifiedStatusReport(opts?: {
|
|
65
|
+
p2pOnly?: boolean;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
private sendP2PPayload;
|
|
68
|
+
private simpleHash;
|
|
69
|
+
}
|