@adhdev/daemon-core 0.8.49 → 0.8.51
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 +1 -0
- package/dist/commands/cli-manager.d.ts +2 -0
- package/dist/commands/hosted-runtime-restore.d.ts +3 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +303 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +289 -23
- package/dist/index.mjs.map +1 -1
- package/dist/logging/command-log.d.ts +1 -0
- package/dist/logging/debug-config.d.ts +21 -0
- package/dist/logging/debug-trace.d.ts +35 -0
- package/dist/session-host/app-name.d.ts +6 -0
- package/dist/shared-types.d.ts +2 -0
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/boot/daemon-lifecycle.ts +1 -0
- package/src/commands/chat-commands.ts +76 -13
- package/src/commands/cli-manager.ts +11 -0
- package/src/commands/hosted-runtime-restore.ts +9 -0
- package/src/commands/router.ts +55 -5
- package/src/index.ts +22 -0
- package/src/logging/command-log.ts +3 -0
- package/src/logging/debug-config.ts +75 -0
- package/src/logging/debug-trace.ts +130 -0
- package/src/session-host/app-name.ts +15 -0
- package/src/session-host/runtime-support.ts +1 -0
- package/src/shared-types.ts +2 -0
|
@@ -31,6 +31,7 @@ export interface DaemonInitConfig {
|
|
|
31
31
|
removeAgentTracking: (key: string) => void;
|
|
32
32
|
createPtyTransportFactory?: (params: CliTransportFactoryParams) => PtyTransportFactory | null;
|
|
33
33
|
listHostedCliRuntimes?: () => Promise<HostedCliRuntimeDescriptor[]>;
|
|
34
|
+
hostedRuntimeManagerTag?: string;
|
|
34
35
|
};
|
|
35
36
|
/** CDP config */
|
|
36
37
|
enabledIdes?: string[];
|
|
@@ -25,6 +25,7 @@ export interface CliManagerDeps {
|
|
|
25
25
|
getSessionRegistry?(): SessionRegistry | null;
|
|
26
26
|
createPtyTransportFactory?: (params: CliTransportFactoryParams) => PtyTransportFactory | null;
|
|
27
27
|
listHostedCliRuntimes?: () => Promise<HostedCliRuntimeDescriptor[]>;
|
|
28
|
+
hostedRuntimeManagerTag?: string;
|
|
28
29
|
}
|
|
29
30
|
type CommandResult = {
|
|
30
31
|
success: boolean;
|
|
@@ -49,6 +50,7 @@ export interface HostedCliRuntimeDescriptor {
|
|
|
49
50
|
workspace: string;
|
|
50
51
|
cliArgs?: string[];
|
|
51
52
|
providerSessionId?: string;
|
|
53
|
+
managedBy?: string;
|
|
52
54
|
}
|
|
53
55
|
export declare function supportsExplicitSessionResume(resume?: ProviderResumeCapability): boolean;
|
|
54
56
|
export declare class DaemonCliManager {
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ export type { ManagedStatus } from './status/normalize.js';
|
|
|
51
51
|
export type { StatusSnapshotOptions, StatusSnapshot } from './status/snapshot.js';
|
|
52
52
|
export { LOG, installGlobalInterceptor, setLogLevel, getLogLevel, getRecentLogs, getDaemonLogDir, getCurrentDaemonLogPath, } from './logging/logger.js';
|
|
53
53
|
export type { ScopedLogger, LogLevel, LogEntry } from './logging/logger.js';
|
|
54
|
+
export { resolveDebugRuntimeConfig, setDebugRuntimeConfig, getDebugRuntimeConfig, resetDebugRuntimeConfig, shouldCollectTraceCategory, } from './logging/debug-config.js';
|
|
55
|
+
export type { DebugRuntimeOptions, DebugRuntimeConfig } from './logging/debug-config.js';
|
|
56
|
+
export { createDebugTraceStore, configureDebugTraceStore, recordDebugTrace, getRecentDebugTrace, clearDebugTrace, createInteractionId, } from './logging/debug-trace.js';
|
|
57
|
+
export type { DebugTraceEvent, DebugTraceEntry, DebugTraceQuery, DebugTraceStore, DebugTraceLevel } from './logging/debug-trace.js';
|
|
54
58
|
export { logCommand, getRecentCommands } from './logging/command-log.js';
|
|
55
59
|
export { DaemonCliManager } from './commands/cli-manager.js';
|
|
56
60
|
export { launchWithCdp, getAvailableIdeIds, killIdeProcess, isIdeRunning } from './launch.js';
|
|
@@ -75,6 +79,7 @@ export { NodePtyTransportFactory } from './cli-adapters/pty-transport.js';
|
|
|
75
79
|
export type { PtyRuntimeTransport, PtyTransportFactory, PtySpawnOptions } from './cli-adapters/pty-transport.js';
|
|
76
80
|
export { SessionHostPtyTransportFactory } from './cli-adapters/session-host-transport.js';
|
|
77
81
|
export type { HostedCliRuntimeDescriptor, CliTransportFactoryParams } from './commands/cli-manager.js';
|
|
82
|
+
export { DEFAULT_SESSION_HOST_APP_NAME, DEFAULT_STANDALONE_SESSION_HOST_APP_NAME, resolveSessionHostAppName, } from './session-host/app-name.js';
|
|
78
83
|
export { ensureSessionHostReady, listHostedCliRuntimes } from './session-host/runtime-support.js';
|
|
79
84
|
export type { SessionHostEndpoint } from '@adhdev/session-host-core';
|
|
80
85
|
export { getAIExtensions, installExtensions, launchIDE, isExtensionInstalled } from './installer.js';
|
package/dist/index.js
CHANGED
|
@@ -3009,6 +3009,8 @@ __export(index_exports, {
|
|
|
3009
3009
|
CliProviderInstance: () => CliProviderInstance,
|
|
3010
3010
|
DAEMON_WS_PATH: () => DAEMON_WS_PATH,
|
|
3011
3011
|
DEFAULT_DAEMON_PORT: () => DEFAULT_DAEMON_PORT,
|
|
3012
|
+
DEFAULT_SESSION_HOST_APP_NAME: () => DEFAULT_SESSION_HOST_APP_NAME,
|
|
3013
|
+
DEFAULT_STANDALONE_SESSION_HOST_APP_NAME: () => DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
|
|
3012
3014
|
DaemonAgentStreamManager: () => DaemonAgentStreamManager,
|
|
3013
3015
|
DaemonCdpInitializer: () => DaemonCdpInitializer,
|
|
3014
3016
|
DaemonCdpManager: () => DaemonCdpManager,
|
|
@@ -3030,7 +3032,11 @@ __export(index_exports, {
|
|
|
3030
3032
|
buildMachineInfo: () => buildMachineInfo,
|
|
3031
3033
|
buildSessionEntries: () => buildSessionEntries,
|
|
3032
3034
|
buildStatusSnapshot: () => buildStatusSnapshot,
|
|
3035
|
+
clearDebugTrace: () => clearDebugTrace,
|
|
3036
|
+
configureDebugTraceStore: () => configureDebugTraceStore,
|
|
3033
3037
|
connectCdpManager: () => connectCdpManager,
|
|
3038
|
+
createDebugTraceStore: () => createDebugTraceStore,
|
|
3039
|
+
createInteractionId: () => createInteractionId,
|
|
3034
3040
|
detectAllVersions: () => detectAllVersions,
|
|
3035
3041
|
detectCLIs: () => detectCLIs,
|
|
3036
3042
|
detectIDEs: () => detectIDEs,
|
|
@@ -3041,10 +3047,12 @@ __export(index_exports, {
|
|
|
3041
3047
|
getAvailableIdeIds: () => getAvailableIdeIds,
|
|
3042
3048
|
getCurrentDaemonLogPath: () => getCurrentDaemonLogPath,
|
|
3043
3049
|
getDaemonLogDir: () => getDaemonLogDir,
|
|
3050
|
+
getDebugRuntimeConfig: () => getDebugRuntimeConfig,
|
|
3044
3051
|
getHostMemorySnapshot: () => getHostMemorySnapshot,
|
|
3045
3052
|
getLogLevel: () => getLogLevel,
|
|
3046
3053
|
getRecentActivity: () => getRecentActivity,
|
|
3047
3054
|
getRecentCommands: () => getRecentCommands,
|
|
3055
|
+
getRecentDebugTrace: () => getRecentDebugTrace,
|
|
3048
3056
|
getRecentLogs: () => getRecentLogs,
|
|
3049
3057
|
getSavedProviderSessions: () => getSavedProviderSessions,
|
|
3050
3058
|
getWorkspaceState: () => getWorkspaceState,
|
|
@@ -3071,13 +3079,19 @@ __export(index_exports, {
|
|
|
3071
3079
|
normalizeManagedStatus: () => normalizeManagedStatus,
|
|
3072
3080
|
probeCdpPort: () => probeCdpPort,
|
|
3073
3081
|
readChatHistory: () => readChatHistory,
|
|
3082
|
+
recordDebugTrace: () => recordDebugTrace,
|
|
3074
3083
|
registerExtensionProviders: () => registerExtensionProviders,
|
|
3075
3084
|
resetConfig: () => resetConfig,
|
|
3085
|
+
resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
|
|
3076
3086
|
resetState: () => resetState,
|
|
3087
|
+
resolveDebugRuntimeConfig: () => resolveDebugRuntimeConfig,
|
|
3088
|
+
resolveSessionHostAppName: () => resolveSessionHostAppName,
|
|
3077
3089
|
saveConfig: () => saveConfig,
|
|
3078
3090
|
saveState: () => saveState,
|
|
3091
|
+
setDebugRuntimeConfig: () => setDebugRuntimeConfig,
|
|
3079
3092
|
setLogLevel: () => setLogLevel,
|
|
3080
3093
|
setupIdeInstance: () => setupIdeInstance,
|
|
3094
|
+
shouldCollectTraceCategory: () => shouldCollectTraceCategory,
|
|
3081
3095
|
shutdownDaemonComponents: () => shutdownDaemonComponents,
|
|
3082
3096
|
spawnDetachedDaemonUpgradeHelper: () => spawnDetachedDaemonUpgradeHelper,
|
|
3083
3097
|
startDaemonDevSupport: () => startDaemonDevSupport,
|
|
@@ -7485,6 +7499,134 @@ function flattenContent(content) {
|
|
|
7485
7499
|
|
|
7486
7500
|
// src/commands/chat-commands.ts
|
|
7487
7501
|
init_logger();
|
|
7502
|
+
|
|
7503
|
+
// src/logging/debug-config.ts
|
|
7504
|
+
var NORMAL_TRACE_BUFFER_SIZE = 200;
|
|
7505
|
+
var DEV_TRACE_BUFFER_SIZE = 1e3;
|
|
7506
|
+
var DEFAULT_CONFIG2 = {
|
|
7507
|
+
logLevel: "info",
|
|
7508
|
+
collectDebugTrace: false,
|
|
7509
|
+
traceContent: false,
|
|
7510
|
+
traceBufferSize: NORMAL_TRACE_BUFFER_SIZE,
|
|
7511
|
+
traceCategories: []
|
|
7512
|
+
};
|
|
7513
|
+
var currentConfig = { ...DEFAULT_CONFIG2 };
|
|
7514
|
+
function normalizeCategories(categories) {
|
|
7515
|
+
if (!Array.isArray(categories)) return [];
|
|
7516
|
+
return categories.map((category) => String(category || "").trim()).filter(Boolean);
|
|
7517
|
+
}
|
|
7518
|
+
function resolveDebugRuntimeConfig(options = {}) {
|
|
7519
|
+
const dev = options.dev === true;
|
|
7520
|
+
return {
|
|
7521
|
+
logLevel: options.logLevel || (dev ? "debug" : DEFAULT_CONFIG2.logLevel),
|
|
7522
|
+
collectDebugTrace: typeof options.trace === "boolean" ? options.trace : dev,
|
|
7523
|
+
traceContent: options.traceContent === true,
|
|
7524
|
+
traceBufferSize: Number.isFinite(options.traceBufferSize) ? Math.max(10, Math.floor(options.traceBufferSize)) : dev ? DEV_TRACE_BUFFER_SIZE : DEFAULT_CONFIG2.traceBufferSize,
|
|
7525
|
+
traceCategories: normalizeCategories(options.traceCategories)
|
|
7526
|
+
};
|
|
7527
|
+
}
|
|
7528
|
+
function setDebugRuntimeConfig(config) {
|
|
7529
|
+
currentConfig = {
|
|
7530
|
+
...config,
|
|
7531
|
+
traceCategories: normalizeCategories(config.traceCategories),
|
|
7532
|
+
traceBufferSize: Math.max(10, Math.floor(config.traceBufferSize || DEFAULT_CONFIG2.traceBufferSize))
|
|
7533
|
+
};
|
|
7534
|
+
}
|
|
7535
|
+
function getDebugRuntimeConfig() {
|
|
7536
|
+
return { ...currentConfig, traceCategories: [...currentConfig.traceCategories] };
|
|
7537
|
+
}
|
|
7538
|
+
function resetDebugRuntimeConfig() {
|
|
7539
|
+
currentConfig = { ...DEFAULT_CONFIG2 };
|
|
7540
|
+
}
|
|
7541
|
+
function shouldCollectTraceCategory(category) {
|
|
7542
|
+
const config = currentConfig;
|
|
7543
|
+
if (!config.collectDebugTrace) return false;
|
|
7544
|
+
if (!category) return true;
|
|
7545
|
+
if (config.traceCategories.length === 0) return true;
|
|
7546
|
+
return config.traceCategories.includes(category);
|
|
7547
|
+
}
|
|
7548
|
+
|
|
7549
|
+
// src/logging/debug-trace.ts
|
|
7550
|
+
function summarizeString(value) {
|
|
7551
|
+
return `[${value.length} chars]`;
|
|
7552
|
+
}
|
|
7553
|
+
function sanitizeTraceValue(value, traceContent) {
|
|
7554
|
+
if (traceContent) {
|
|
7555
|
+
if (Array.isArray(value)) return value.map((entry) => sanitizeTraceValue(entry, traceContent));
|
|
7556
|
+
if (value && typeof value === "object") {
|
|
7557
|
+
return Object.fromEntries(
|
|
7558
|
+
Object.entries(value).map(([key, nested]) => [key, sanitizeTraceValue(nested, traceContent)])
|
|
7559
|
+
);
|
|
7560
|
+
}
|
|
7561
|
+
return value;
|
|
7562
|
+
}
|
|
7563
|
+
if (typeof value === "string") return summarizeString(value);
|
|
7564
|
+
if (Array.isArray(value)) return value.map((entry) => sanitizeTraceValue(entry, traceContent));
|
|
7565
|
+
if (value && typeof value === "object") {
|
|
7566
|
+
return Object.fromEntries(
|
|
7567
|
+
Object.entries(value).map(([key, nested]) => [key, sanitizeTraceValue(nested, traceContent)])
|
|
7568
|
+
);
|
|
7569
|
+
}
|
|
7570
|
+
return value;
|
|
7571
|
+
}
|
|
7572
|
+
function sanitizeTracePayload(payload) {
|
|
7573
|
+
if (!payload) return {};
|
|
7574
|
+
const { traceContent } = getDebugRuntimeConfig();
|
|
7575
|
+
return sanitizeTraceValue(payload, traceContent);
|
|
7576
|
+
}
|
|
7577
|
+
function createEntry(event) {
|
|
7578
|
+
return {
|
|
7579
|
+
id: `trace_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
|
|
7580
|
+
ts: Date.now(),
|
|
7581
|
+
...event,
|
|
7582
|
+
payload: sanitizeTracePayload(event.payload)
|
|
7583
|
+
};
|
|
7584
|
+
}
|
|
7585
|
+
function createDebugTraceStore(options) {
|
|
7586
|
+
const entries = [];
|
|
7587
|
+
const capacity = Math.max(1, Math.floor(options.capacity || 100));
|
|
7588
|
+
return {
|
|
7589
|
+
record(event) {
|
|
7590
|
+
if (!options.enabled) return null;
|
|
7591
|
+
const entry = createEntry(event);
|
|
7592
|
+
entries.push(entry);
|
|
7593
|
+
if (entries.length > capacity) {
|
|
7594
|
+
entries.splice(0, entries.length - capacity);
|
|
7595
|
+
}
|
|
7596
|
+
return entry;
|
|
7597
|
+
},
|
|
7598
|
+
list(query = {}) {
|
|
7599
|
+
const limit = Math.max(1, Math.floor(query.limit || 100));
|
|
7600
|
+
return entries.filter((entry) => !query.interactionId || entry.interactionId === query.interactionId).filter((entry) => !query.category || entry.category === query.category).slice(-limit).map((entry) => ({ ...entry, payload: entry.payload ? { ...entry.payload } : {} }));
|
|
7601
|
+
},
|
|
7602
|
+
clear() {
|
|
7603
|
+
entries.splice(0, entries.length);
|
|
7604
|
+
}
|
|
7605
|
+
};
|
|
7606
|
+
}
|
|
7607
|
+
var globalStore = createDebugTraceStore({ enabled: false, capacity: getDebugRuntimeConfig().traceBufferSize });
|
|
7608
|
+
function configureDebugTraceStore() {
|
|
7609
|
+
const config = getDebugRuntimeConfig();
|
|
7610
|
+
globalStore = createDebugTraceStore({
|
|
7611
|
+
enabled: config.collectDebugTrace,
|
|
7612
|
+
capacity: config.traceBufferSize
|
|
7613
|
+
});
|
|
7614
|
+
}
|
|
7615
|
+
function recordDebugTrace(event) {
|
|
7616
|
+
if (!shouldCollectTraceCategory(event.category)) return null;
|
|
7617
|
+
return globalStore.record(event);
|
|
7618
|
+
}
|
|
7619
|
+
function getRecentDebugTrace(query = {}) {
|
|
7620
|
+
return globalStore.list(query);
|
|
7621
|
+
}
|
|
7622
|
+
function clearDebugTrace() {
|
|
7623
|
+
globalStore.clear();
|
|
7624
|
+
}
|
|
7625
|
+
function createInteractionId(prefix = "ix") {
|
|
7626
|
+
return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
7627
|
+
}
|
|
7628
|
+
|
|
7629
|
+
// src/commands/chat-commands.ts
|
|
7488
7630
|
var RECENT_SEND_WINDOW_MS = 1200;
|
|
7489
7631
|
var recentSendByTarget = /* @__PURE__ */ new Map();
|
|
7490
7632
|
function hashSignatureParts(parts) {
|
|
@@ -7551,6 +7693,20 @@ function getHistorySessionId(h, args) {
|
|
|
7551
7693
|
const providerSessionId = typeof state?.providerSessionId === "string" ? state.providerSessionId.trim() : "";
|
|
7552
7694
|
return providerSessionId || targetSessionId;
|
|
7553
7695
|
}
|
|
7696
|
+
function getInteractionId(args) {
|
|
7697
|
+
return typeof args?._interactionId === "string" && args._interactionId.trim() ? args._interactionId.trim() : void 0;
|
|
7698
|
+
}
|
|
7699
|
+
function traceProviderEvent(args, category, stage, options) {
|
|
7700
|
+
recordDebugTrace({
|
|
7701
|
+
interactionId: getInteractionId(args),
|
|
7702
|
+
category,
|
|
7703
|
+
stage,
|
|
7704
|
+
level: options.level || "info",
|
|
7705
|
+
sessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId : options.h.currentSession?.sessionId,
|
|
7706
|
+
providerType: options.provider?.type || options.h.currentProviderType || options.h.currentSession?.providerType,
|
|
7707
|
+
payload: options.payload
|
|
7708
|
+
});
|
|
7709
|
+
}
|
|
7554
7710
|
function callLegacyTextScript(script, text) {
|
|
7555
7711
|
if (typeof script !== "function") return null;
|
|
7556
7712
|
return script(text);
|
|
@@ -7796,6 +7952,16 @@ async function handleReadChat(h, args) {
|
|
|
7796
7952
|
}
|
|
7797
7953
|
if (parsed && typeof parsed === "object") {
|
|
7798
7954
|
_log(`Extension OK: ${parsed.messages?.length || 0} msgs`);
|
|
7955
|
+
traceProviderEvent(args, "provider", "extension.read_chat.success", {
|
|
7956
|
+
h,
|
|
7957
|
+
provider,
|
|
7958
|
+
payload: {
|
|
7959
|
+
method: "evaluateProviderScript",
|
|
7960
|
+
result: evalResult.result,
|
|
7961
|
+
parsed,
|
|
7962
|
+
messageCount: Array.isArray(parsed.messages) ? parsed.messages.length : 0
|
|
7963
|
+
}
|
|
7964
|
+
});
|
|
7799
7965
|
h.historyWriter.appendNewMessages(
|
|
7800
7966
|
provider?.type || "unknown_extension",
|
|
7801
7967
|
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
@@ -7808,6 +7974,12 @@ async function handleReadChat(h, args) {
|
|
|
7808
7974
|
}
|
|
7809
7975
|
} catch (e) {
|
|
7810
7976
|
_log(`Extension error: ${e.message}`);
|
|
7977
|
+
traceProviderEvent(args, "provider", "extension.read_chat.error", {
|
|
7978
|
+
h,
|
|
7979
|
+
provider,
|
|
7980
|
+
level: "warn",
|
|
7981
|
+
payload: { method: "evaluateProviderScript", error: e.message }
|
|
7982
|
+
});
|
|
7811
7983
|
}
|
|
7812
7984
|
if (h.agentStream) {
|
|
7813
7985
|
const cdp2 = h.getCdp();
|
|
@@ -7871,27 +8043,45 @@ async function handleReadChat(h, args) {
|
|
|
7871
8043
|
const script = h.getProviderScript("readChat") || h.getProviderScript("read_chat");
|
|
7872
8044
|
if (script) {
|
|
7873
8045
|
try {
|
|
7874
|
-
const
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
8046
|
+
const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
|
|
8047
|
+
if (evalResult?.result) {
|
|
8048
|
+
let parsed = evalResult.result;
|
|
8049
|
+
if (typeof parsed === "string") {
|
|
8050
|
+
try {
|
|
8051
|
+
parsed = JSON.parse(parsed);
|
|
8052
|
+
} catch {
|
|
8053
|
+
}
|
|
8054
|
+
}
|
|
8055
|
+
if (parsed && typeof parsed === "object" && parsed.messages?.length > 0) {
|
|
8056
|
+
_log(`OK: ${parsed.messages?.length} msgs`);
|
|
8057
|
+
traceProviderEvent(args, "provider", "ide.read_chat.success", {
|
|
8058
|
+
h,
|
|
8059
|
+
provider,
|
|
8060
|
+
payload: {
|
|
8061
|
+
method: "evaluate",
|
|
8062
|
+
result: evalResult.result,
|
|
8063
|
+
parsed,
|
|
8064
|
+
messageCount: Array.isArray(parsed.messages) ? parsed.messages.length : 0
|
|
8065
|
+
}
|
|
8066
|
+
});
|
|
8067
|
+
h.historyWriter.appendNewMessages(
|
|
8068
|
+
provider?.type || getCurrentProviderType(h, "unknown_ide"),
|
|
8069
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
8070
|
+
parsed.title,
|
|
8071
|
+
args?.targetSessionId,
|
|
8072
|
+
historySessionId
|
|
8073
|
+
);
|
|
8074
|
+
return buildReadChatCommandResult(parsed, args);
|
|
7880
8075
|
}
|
|
7881
|
-
}
|
|
7882
|
-
if (parsed && typeof parsed === "object" && parsed.messages?.length > 0) {
|
|
7883
|
-
_log(`OK: ${parsed.messages?.length} msgs`);
|
|
7884
|
-
h.historyWriter.appendNewMessages(
|
|
7885
|
-
provider?.type || getCurrentProviderType(h, "unknown_ide"),
|
|
7886
|
-
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
7887
|
-
parsed.title,
|
|
7888
|
-
args?.targetSessionId,
|
|
7889
|
-
historySessionId
|
|
7890
|
-
);
|
|
7891
|
-
return buildReadChatCommandResult(parsed, args);
|
|
7892
8076
|
}
|
|
7893
8077
|
} catch (e) {
|
|
7894
8078
|
LOG.info("Command", `[read_chat] Script error: ${e.message}`);
|
|
8079
|
+
traceProviderEvent(args, "provider", "ide.read_chat.error", {
|
|
8080
|
+
h,
|
|
8081
|
+
provider,
|
|
8082
|
+
level: "warn",
|
|
8083
|
+
payload: { method: "evaluate", error: e.message }
|
|
8084
|
+
});
|
|
7895
8085
|
}
|
|
7896
8086
|
}
|
|
7897
8087
|
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
@@ -11388,6 +11578,16 @@ var AcpProviderInstance = class {
|
|
|
11388
11578
|
|
|
11389
11579
|
// src/commands/cli-manager.ts
|
|
11390
11580
|
init_logger();
|
|
11581
|
+
|
|
11582
|
+
// src/commands/hosted-runtime-restore.ts
|
|
11583
|
+
function shouldRestoreHostedRuntime(record, managerTag) {
|
|
11584
|
+
if (!managerTag) return true;
|
|
11585
|
+
const managedBy = typeof record.managedBy === "string" ? record.managedBy.trim() : "";
|
|
11586
|
+
if (!managedBy) return true;
|
|
11587
|
+
return managedBy === managerTag;
|
|
11588
|
+
}
|
|
11589
|
+
|
|
11590
|
+
// src/commands/cli-manager.ts
|
|
11391
11591
|
var chalkModule = import_chalk.default;
|
|
11392
11592
|
var chalkApi = typeof chalkModule.yellow === "function" ? chalkModule : chalkModule.default || null;
|
|
11393
11593
|
function colorize(color, text) {
|
|
@@ -11883,8 +12083,16 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
11883
12083
|
const sessions = records || await this.deps.listHostedCliRuntimes?.() || [];
|
|
11884
12084
|
let restored = 0;
|
|
11885
12085
|
const restoredBindings = /* @__PURE__ */ new Set();
|
|
12086
|
+
const managerTag = this.deps.hostedRuntimeManagerTag;
|
|
11886
12087
|
for (const record of sessions) {
|
|
11887
12088
|
if (!record?.runtimeId || !record?.cliType || !record?.workspace) continue;
|
|
12089
|
+
if (!shouldRestoreHostedRuntime(record, managerTag)) {
|
|
12090
|
+
LOG.info(
|
|
12091
|
+
"CLI",
|
|
12092
|
+
`\u21B7 Skipping hosted runtime restore owned by ${record.managedBy}: ${record.runtimeKey || record.runtimeId}`
|
|
12093
|
+
);
|
|
12094
|
+
continue;
|
|
12095
|
+
}
|
|
11888
12096
|
if (this.adapters.has(record.runtimeId) || instanceManager.getInstance(record.runtimeId)) continue;
|
|
11889
12097
|
const normalizedType = this.providerLoader.resolveAlias(record.cliType);
|
|
11890
12098
|
const providerMeta = this.providerLoader.getMeta(normalizedType);
|
|
@@ -13779,6 +13987,7 @@ function logCommand(entry) {
|
|
|
13779
13987
|
ts: entry.ts,
|
|
13780
13988
|
cmd: entry.cmd,
|
|
13781
13989
|
src: entry.source,
|
|
13990
|
+
...entry.interactionId ? { interactionId: entry.interactionId } : {},
|
|
13782
13991
|
...entry.args ? { args: maskArgs(entry.args) } : {},
|
|
13783
13992
|
...entry.success !== void 0 ? { ok: entry.success } : {},
|
|
13784
13993
|
...entry.error ? { err: entry.error } : {},
|
|
@@ -13800,6 +14009,7 @@ function getRecentCommands(count = 50) {
|
|
|
13800
14009
|
ts: parsed.ts,
|
|
13801
14010
|
cmd: parsed.cmd,
|
|
13802
14011
|
source: parsed.src,
|
|
14012
|
+
interactionId: parsed.interactionId,
|
|
13803
14013
|
args: parsed.args,
|
|
13804
14014
|
success: parsed.ok,
|
|
13805
14015
|
error: parsed.err,
|
|
@@ -14267,6 +14477,13 @@ function normalizeCommandSource(source) {
|
|
|
14267
14477
|
return "unknown";
|
|
14268
14478
|
}
|
|
14269
14479
|
}
|
|
14480
|
+
function normalizeCommandArgsWithInteractionId(args) {
|
|
14481
|
+
const base = args && typeof args === "object" ? { ...args } : {};
|
|
14482
|
+
if (typeof base._interactionId !== "string" || !String(base._interactionId).trim()) {
|
|
14483
|
+
base._interactionId = createInteractionId();
|
|
14484
|
+
}
|
|
14485
|
+
return base;
|
|
14486
|
+
}
|
|
14270
14487
|
function toHostedCliRuntimeDescriptor(record) {
|
|
14271
14488
|
if (!record || typeof record !== "object") return null;
|
|
14272
14489
|
const runtimeId = typeof record.sessionId === "string" ? record.sessionId : "";
|
|
@@ -14305,20 +14522,50 @@ var DaemonCommandRouter = class {
|
|
|
14305
14522
|
async execute(cmd, args, source = "unknown") {
|
|
14306
14523
|
const cmdStart = Date.now();
|
|
14307
14524
|
const logSource = normalizeCommandSource(source);
|
|
14525
|
+
const normalizedArgs = normalizeCommandArgsWithInteractionId(args);
|
|
14526
|
+
const interactionId = typeof normalizedArgs._interactionId === "string" ? normalizedArgs._interactionId : void 0;
|
|
14527
|
+
recordDebugTrace({
|
|
14528
|
+
interactionId,
|
|
14529
|
+
category: "command",
|
|
14530
|
+
stage: "received",
|
|
14531
|
+
level: "info",
|
|
14532
|
+
payload: { cmd, source: logSource }
|
|
14533
|
+
});
|
|
14308
14534
|
try {
|
|
14309
|
-
const daemonResult = await this.executeDaemonCommand(cmd,
|
|
14535
|
+
const daemonResult = await this.executeDaemonCommand(cmd, normalizedArgs);
|
|
14310
14536
|
if (daemonResult) {
|
|
14311
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, args, success: daemonResult.success, durationMs: Date.now() - cmdStart });
|
|
14537
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, interactionId, args: normalizedArgs, success: daemonResult.success, durationMs: Date.now() - cmdStart });
|
|
14538
|
+
recordDebugTrace({
|
|
14539
|
+
interactionId,
|
|
14540
|
+
category: "command",
|
|
14541
|
+
stage: "completed",
|
|
14542
|
+
level: daemonResult.success ? "info" : "warn",
|
|
14543
|
+
payload: { cmd, source: logSource, success: daemonResult.success, durationMs: Date.now() - cmdStart }
|
|
14544
|
+
});
|
|
14312
14545
|
return daemonResult;
|
|
14313
14546
|
}
|
|
14314
|
-
const handlerResult = await this.deps.commandHandler.handle(cmd,
|
|
14315
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, args, success: handlerResult.success, durationMs: Date.now() - cmdStart });
|
|
14547
|
+
const handlerResult = await this.deps.commandHandler.handle(cmd, normalizedArgs);
|
|
14548
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, interactionId, args: normalizedArgs, success: handlerResult.success, durationMs: Date.now() - cmdStart });
|
|
14549
|
+
recordDebugTrace({
|
|
14550
|
+
interactionId,
|
|
14551
|
+
category: "command",
|
|
14552
|
+
stage: "completed",
|
|
14553
|
+
level: handlerResult.success ? "info" : "warn",
|
|
14554
|
+
payload: { cmd, source: logSource, success: handlerResult.success, durationMs: Date.now() - cmdStart }
|
|
14555
|
+
});
|
|
14316
14556
|
if (CHAT_COMMANDS.includes(cmd) && this.deps.onPostChatCommand) {
|
|
14317
14557
|
this.deps.onPostChatCommand();
|
|
14318
14558
|
}
|
|
14319
14559
|
return handlerResult;
|
|
14320
14560
|
} catch (e) {
|
|
14321
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, args, success: false, error: e.message, durationMs: Date.now() - cmdStart });
|
|
14561
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, interactionId, args: normalizedArgs, success: false, error: e.message, durationMs: Date.now() - cmdStart });
|
|
14562
|
+
recordDebugTrace({
|
|
14563
|
+
interactionId,
|
|
14564
|
+
category: "command",
|
|
14565
|
+
stage: "failed",
|
|
14566
|
+
level: "error",
|
|
14567
|
+
payload: { cmd, source: logSource, error: e?.message || String(e), durationMs: Date.now() - cmdStart }
|
|
14568
|
+
});
|
|
14322
14569
|
throw e;
|
|
14323
14570
|
}
|
|
14324
14571
|
}
|
|
@@ -14360,6 +14607,14 @@ var DaemonCommandRouter = class {
|
|
|
14360
14607
|
return { success: false, error: e.message };
|
|
14361
14608
|
}
|
|
14362
14609
|
}
|
|
14610
|
+
case "get_debug_trace": {
|
|
14611
|
+
const count = parseInt(args?.count) || parseInt(args?.limit) || 100;
|
|
14612
|
+
const sinceTs = Number(args?.since) || 0;
|
|
14613
|
+
const interactionId = typeof args?.interactionId === "string" ? args.interactionId : void 0;
|
|
14614
|
+
const category = typeof args?.category === "string" ? args.category : void 0;
|
|
14615
|
+
const trace = getRecentDebugTrace({ interactionId, category, limit: count }).filter((entry) => !sinceTs || entry.ts > sinceTs);
|
|
14616
|
+
return { success: true, trace, count: trace.length };
|
|
14617
|
+
}
|
|
14363
14618
|
case "session_host_get_diagnostics": {
|
|
14364
14619
|
if (!this.deps.sessionHostControl) return { success: false, error: "Session host control unavailable" };
|
|
14365
14620
|
const diagnostics = await this.deps.sessionHostControl.getDiagnostics({
|
|
@@ -21723,6 +21978,16 @@ var SessionHostPtyTransportFactory = class {
|
|
|
21723
21978
|
}
|
|
21724
21979
|
};
|
|
21725
21980
|
|
|
21981
|
+
// src/session-host/app-name.ts
|
|
21982
|
+
var DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
|
|
21983
|
+
var DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
|
|
21984
|
+
function resolveSessionHostAppName(options = {}) {
|
|
21985
|
+
const env = options.env || process.env;
|
|
21986
|
+
const explicit = typeof env.ADHDEV_SESSION_HOST_NAME === "string" ? env.ADHDEV_SESSION_HOST_NAME.trim() : "";
|
|
21987
|
+
if (explicit) return explicit;
|
|
21988
|
+
return options.standalone ? DEFAULT_STANDALONE_SESSION_HOST_APP_NAME : DEFAULT_SESSION_HOST_APP_NAME;
|
|
21989
|
+
}
|
|
21990
|
+
|
|
21726
21991
|
// src/session-host/runtime-support.ts
|
|
21727
21992
|
var import_session_host_core3 = require("@adhdev/session-host-core");
|
|
21728
21993
|
var STARTUP_TIMEOUT_MS = 8e3;
|
|
@@ -21772,7 +22037,8 @@ async function listHostedCliRuntimes(endpoint) {
|
|
|
21772
22037
|
cliType: record.providerType,
|
|
21773
22038
|
workspace: record.workspace,
|
|
21774
22039
|
cliArgs: Array.isArray(record.meta?.cliArgs) ? record.meta.cliArgs : [],
|
|
21775
|
-
providerSessionId: typeof record.meta?.providerSessionId === "string" ? String(record.meta.providerSessionId) : void 0
|
|
22040
|
+
providerSessionId: typeof record.meta?.providerSessionId === "string" ? String(record.meta.providerSessionId) : void 0,
|
|
22041
|
+
managedBy: typeof record.meta?.managedBy === "string" ? String(record.meta.managedBy) : void 0
|
|
21776
22042
|
}));
|
|
21777
22043
|
} finally {
|
|
21778
22044
|
await client.close().catch(() => {
|
|
@@ -22253,6 +22519,8 @@ async function shutdownDaemonComponents(components) {
|
|
|
22253
22519
|
CliProviderInstance,
|
|
22254
22520
|
DAEMON_WS_PATH,
|
|
22255
22521
|
DEFAULT_DAEMON_PORT,
|
|
22522
|
+
DEFAULT_SESSION_HOST_APP_NAME,
|
|
22523
|
+
DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
|
|
22256
22524
|
DaemonAgentStreamManager,
|
|
22257
22525
|
DaemonCdpInitializer,
|
|
22258
22526
|
DaemonCdpManager,
|
|
@@ -22274,7 +22542,11 @@ async function shutdownDaemonComponents(components) {
|
|
|
22274
22542
|
buildMachineInfo,
|
|
22275
22543
|
buildSessionEntries,
|
|
22276
22544
|
buildStatusSnapshot,
|
|
22545
|
+
clearDebugTrace,
|
|
22546
|
+
configureDebugTraceStore,
|
|
22277
22547
|
connectCdpManager,
|
|
22548
|
+
createDebugTraceStore,
|
|
22549
|
+
createInteractionId,
|
|
22278
22550
|
detectAllVersions,
|
|
22279
22551
|
detectCLIs,
|
|
22280
22552
|
detectIDEs,
|
|
@@ -22285,10 +22557,12 @@ async function shutdownDaemonComponents(components) {
|
|
|
22285
22557
|
getAvailableIdeIds,
|
|
22286
22558
|
getCurrentDaemonLogPath,
|
|
22287
22559
|
getDaemonLogDir,
|
|
22560
|
+
getDebugRuntimeConfig,
|
|
22288
22561
|
getHostMemorySnapshot,
|
|
22289
22562
|
getLogLevel,
|
|
22290
22563
|
getRecentActivity,
|
|
22291
22564
|
getRecentCommands,
|
|
22565
|
+
getRecentDebugTrace,
|
|
22292
22566
|
getRecentLogs,
|
|
22293
22567
|
getSavedProviderSessions,
|
|
22294
22568
|
getWorkspaceState,
|
|
@@ -22315,13 +22589,19 @@ async function shutdownDaemonComponents(components) {
|
|
|
22315
22589
|
normalizeManagedStatus,
|
|
22316
22590
|
probeCdpPort,
|
|
22317
22591
|
readChatHistory,
|
|
22592
|
+
recordDebugTrace,
|
|
22318
22593
|
registerExtensionProviders,
|
|
22319
22594
|
resetConfig,
|
|
22595
|
+
resetDebugRuntimeConfig,
|
|
22320
22596
|
resetState,
|
|
22597
|
+
resolveDebugRuntimeConfig,
|
|
22598
|
+
resolveSessionHostAppName,
|
|
22321
22599
|
saveConfig,
|
|
22322
22600
|
saveState,
|
|
22601
|
+
setDebugRuntimeConfig,
|
|
22323
22602
|
setLogLevel,
|
|
22324
22603
|
setupIdeInstance,
|
|
22604
|
+
shouldCollectTraceCategory,
|
|
22325
22605
|
shutdownDaemonComponents,
|
|
22326
22606
|
spawnDetachedDaemonUpgradeHelper,
|
|
22327
22607
|
startDaemonDevSupport,
|