adhdev 0.8.49 → 0.8.50
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/cli/index.js +485 -76
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +456 -66
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4990,6 +4990,145 @@ var init_contracts = __esm({
|
|
|
4990
4990
|
}
|
|
4991
4991
|
});
|
|
4992
4992
|
|
|
4993
|
+
// ../../oss/packages/daemon-core/src/logging/debug-config.ts
|
|
4994
|
+
function normalizeCategories(categories) {
|
|
4995
|
+
if (!Array.isArray(categories)) return [];
|
|
4996
|
+
return categories.map((category) => String(category || "").trim()).filter(Boolean);
|
|
4997
|
+
}
|
|
4998
|
+
function resolveDebugRuntimeConfig(options = {}) {
|
|
4999
|
+
const dev = options.dev === true;
|
|
5000
|
+
return {
|
|
5001
|
+
logLevel: options.logLevel || (dev ? "debug" : DEFAULT_CONFIG2.logLevel),
|
|
5002
|
+
collectDebugTrace: typeof options.trace === "boolean" ? options.trace : dev,
|
|
5003
|
+
traceContent: options.traceContent === true,
|
|
5004
|
+
traceBufferSize: Number.isFinite(options.traceBufferSize) ? Math.max(10, Math.floor(options.traceBufferSize)) : dev ? DEV_TRACE_BUFFER_SIZE : DEFAULT_CONFIG2.traceBufferSize,
|
|
5005
|
+
traceCategories: normalizeCategories(options.traceCategories)
|
|
5006
|
+
};
|
|
5007
|
+
}
|
|
5008
|
+
function setDebugRuntimeConfig(config2) {
|
|
5009
|
+
currentConfig = {
|
|
5010
|
+
...config2,
|
|
5011
|
+
traceCategories: normalizeCategories(config2.traceCategories),
|
|
5012
|
+
traceBufferSize: Math.max(10, Math.floor(config2.traceBufferSize || DEFAULT_CONFIG2.traceBufferSize))
|
|
5013
|
+
};
|
|
5014
|
+
}
|
|
5015
|
+
function getDebugRuntimeConfig() {
|
|
5016
|
+
return { ...currentConfig, traceCategories: [...currentConfig.traceCategories] };
|
|
5017
|
+
}
|
|
5018
|
+
function resetDebugRuntimeConfig() {
|
|
5019
|
+
currentConfig = { ...DEFAULT_CONFIG2 };
|
|
5020
|
+
}
|
|
5021
|
+
function shouldCollectTraceCategory(category) {
|
|
5022
|
+
const config2 = currentConfig;
|
|
5023
|
+
if (!config2.collectDebugTrace) return false;
|
|
5024
|
+
if (!category) return true;
|
|
5025
|
+
if (config2.traceCategories.length === 0) return true;
|
|
5026
|
+
return config2.traceCategories.includes(category);
|
|
5027
|
+
}
|
|
5028
|
+
var NORMAL_TRACE_BUFFER_SIZE, DEV_TRACE_BUFFER_SIZE, DEFAULT_CONFIG2, currentConfig;
|
|
5029
|
+
var init_debug_config = __esm({
|
|
5030
|
+
"../../oss/packages/daemon-core/src/logging/debug-config.ts"() {
|
|
5031
|
+
"use strict";
|
|
5032
|
+
NORMAL_TRACE_BUFFER_SIZE = 200;
|
|
5033
|
+
DEV_TRACE_BUFFER_SIZE = 1e3;
|
|
5034
|
+
DEFAULT_CONFIG2 = {
|
|
5035
|
+
logLevel: "info",
|
|
5036
|
+
collectDebugTrace: false,
|
|
5037
|
+
traceContent: false,
|
|
5038
|
+
traceBufferSize: NORMAL_TRACE_BUFFER_SIZE,
|
|
5039
|
+
traceCategories: []
|
|
5040
|
+
};
|
|
5041
|
+
currentConfig = { ...DEFAULT_CONFIG2 };
|
|
5042
|
+
}
|
|
5043
|
+
});
|
|
5044
|
+
|
|
5045
|
+
// ../../oss/packages/daemon-core/src/logging/debug-trace.ts
|
|
5046
|
+
function summarizeString(value) {
|
|
5047
|
+
return `[${value.length} chars]`;
|
|
5048
|
+
}
|
|
5049
|
+
function sanitizeTraceValue(value, traceContent) {
|
|
5050
|
+
if (traceContent) {
|
|
5051
|
+
if (Array.isArray(value)) return value.map((entry) => sanitizeTraceValue(entry, traceContent));
|
|
5052
|
+
if (value && typeof value === "object") {
|
|
5053
|
+
return Object.fromEntries(
|
|
5054
|
+
Object.entries(value).map(([key, nested]) => [key, sanitizeTraceValue(nested, traceContent)])
|
|
5055
|
+
);
|
|
5056
|
+
}
|
|
5057
|
+
return value;
|
|
5058
|
+
}
|
|
5059
|
+
if (typeof value === "string") return summarizeString(value);
|
|
5060
|
+
if (Array.isArray(value)) return value.map((entry) => sanitizeTraceValue(entry, traceContent));
|
|
5061
|
+
if (value && typeof value === "object") {
|
|
5062
|
+
return Object.fromEntries(
|
|
5063
|
+
Object.entries(value).map(([key, nested]) => [key, sanitizeTraceValue(nested, traceContent)])
|
|
5064
|
+
);
|
|
5065
|
+
}
|
|
5066
|
+
return value;
|
|
5067
|
+
}
|
|
5068
|
+
function sanitizeTracePayload(payload) {
|
|
5069
|
+
if (!payload) return {};
|
|
5070
|
+
const { traceContent } = getDebugRuntimeConfig();
|
|
5071
|
+
return sanitizeTraceValue(payload, traceContent);
|
|
5072
|
+
}
|
|
5073
|
+
function createEntry(event) {
|
|
5074
|
+
return {
|
|
5075
|
+
id: `trace_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
|
|
5076
|
+
ts: Date.now(),
|
|
5077
|
+
...event,
|
|
5078
|
+
payload: sanitizeTracePayload(event.payload)
|
|
5079
|
+
};
|
|
5080
|
+
}
|
|
5081
|
+
function createDebugTraceStore(options) {
|
|
5082
|
+
const entries = [];
|
|
5083
|
+
const capacity = Math.max(1, Math.floor(options.capacity || 100));
|
|
5084
|
+
return {
|
|
5085
|
+
record(event) {
|
|
5086
|
+
if (!options.enabled) return null;
|
|
5087
|
+
const entry = createEntry(event);
|
|
5088
|
+
entries.push(entry);
|
|
5089
|
+
if (entries.length > capacity) {
|
|
5090
|
+
entries.splice(0, entries.length - capacity);
|
|
5091
|
+
}
|
|
5092
|
+
return entry;
|
|
5093
|
+
},
|
|
5094
|
+
list(query = {}) {
|
|
5095
|
+
const limit = Math.max(1, Math.floor(query.limit || 100));
|
|
5096
|
+
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 } : {} }));
|
|
5097
|
+
},
|
|
5098
|
+
clear() {
|
|
5099
|
+
entries.splice(0, entries.length);
|
|
5100
|
+
}
|
|
5101
|
+
};
|
|
5102
|
+
}
|
|
5103
|
+
function configureDebugTraceStore() {
|
|
5104
|
+
const config2 = getDebugRuntimeConfig();
|
|
5105
|
+
globalStore = createDebugTraceStore({
|
|
5106
|
+
enabled: config2.collectDebugTrace,
|
|
5107
|
+
capacity: config2.traceBufferSize
|
|
5108
|
+
});
|
|
5109
|
+
}
|
|
5110
|
+
function recordDebugTrace(event) {
|
|
5111
|
+
if (!shouldCollectTraceCategory(event.category)) return null;
|
|
5112
|
+
return globalStore.record(event);
|
|
5113
|
+
}
|
|
5114
|
+
function getRecentDebugTrace(query = {}) {
|
|
5115
|
+
return globalStore.list(query);
|
|
5116
|
+
}
|
|
5117
|
+
function clearDebugTrace() {
|
|
5118
|
+
globalStore.clear();
|
|
5119
|
+
}
|
|
5120
|
+
function createInteractionId(prefix = "ix") {
|
|
5121
|
+
return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
5122
|
+
}
|
|
5123
|
+
var globalStore;
|
|
5124
|
+
var init_debug_trace = __esm({
|
|
5125
|
+
"../../oss/packages/daemon-core/src/logging/debug-trace.ts"() {
|
|
5126
|
+
"use strict";
|
|
5127
|
+
init_debug_config();
|
|
5128
|
+
globalStore = createDebugTraceStore({ enabled: false, capacity: getDebugRuntimeConfig().traceBufferSize });
|
|
5129
|
+
}
|
|
5130
|
+
});
|
|
5131
|
+
|
|
4993
5132
|
// ../../oss/packages/daemon-core/src/commands/chat-commands.ts
|
|
4994
5133
|
function hashSignatureParts(parts) {
|
|
4995
5134
|
let hash2 = 2166136261;
|
|
@@ -5055,6 +5194,20 @@ function getHistorySessionId(h, args) {
|
|
|
5055
5194
|
const providerSessionId = typeof state?.providerSessionId === "string" ? state.providerSessionId.trim() : "";
|
|
5056
5195
|
return providerSessionId || targetSessionId;
|
|
5057
5196
|
}
|
|
5197
|
+
function getInteractionId(args) {
|
|
5198
|
+
return typeof args?._interactionId === "string" && args._interactionId.trim() ? args._interactionId.trim() : void 0;
|
|
5199
|
+
}
|
|
5200
|
+
function traceProviderEvent(args, category, stage, options) {
|
|
5201
|
+
recordDebugTrace({
|
|
5202
|
+
interactionId: getInteractionId(args),
|
|
5203
|
+
category,
|
|
5204
|
+
stage,
|
|
5205
|
+
level: options.level || "info",
|
|
5206
|
+
sessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId : options.h.currentSession?.sessionId,
|
|
5207
|
+
providerType: options.provider?.type || options.h.currentProviderType || options.h.currentSession?.providerType,
|
|
5208
|
+
payload: options.payload
|
|
5209
|
+
});
|
|
5210
|
+
}
|
|
5058
5211
|
function callLegacyTextScript(script, text) {
|
|
5059
5212
|
if (typeof script !== "function") return null;
|
|
5060
5213
|
return script(text);
|
|
@@ -5300,6 +5453,16 @@ async function handleReadChat(h, args) {
|
|
|
5300
5453
|
}
|
|
5301
5454
|
if (parsed && typeof parsed === "object") {
|
|
5302
5455
|
_log(`Extension OK: ${parsed.messages?.length || 0} msgs`);
|
|
5456
|
+
traceProviderEvent(args, "provider", "extension.read_chat.success", {
|
|
5457
|
+
h,
|
|
5458
|
+
provider,
|
|
5459
|
+
payload: {
|
|
5460
|
+
method: "evaluateProviderScript",
|
|
5461
|
+
result: evalResult.result,
|
|
5462
|
+
parsed,
|
|
5463
|
+
messageCount: Array.isArray(parsed.messages) ? parsed.messages.length : 0
|
|
5464
|
+
}
|
|
5465
|
+
});
|
|
5303
5466
|
h.historyWriter.appendNewMessages(
|
|
5304
5467
|
provider?.type || "unknown_extension",
|
|
5305
5468
|
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
@@ -5312,6 +5475,12 @@ async function handleReadChat(h, args) {
|
|
|
5312
5475
|
}
|
|
5313
5476
|
} catch (e) {
|
|
5314
5477
|
_log(`Extension error: ${e.message}`);
|
|
5478
|
+
traceProviderEvent(args, "provider", "extension.read_chat.error", {
|
|
5479
|
+
h,
|
|
5480
|
+
provider,
|
|
5481
|
+
level: "warn",
|
|
5482
|
+
payload: { method: "evaluateProviderScript", error: e.message }
|
|
5483
|
+
});
|
|
5315
5484
|
}
|
|
5316
5485
|
if (h.agentStream) {
|
|
5317
5486
|
const cdp2 = h.getCdp();
|
|
@@ -5375,27 +5544,45 @@ async function handleReadChat(h, args) {
|
|
|
5375
5544
|
const script = h.getProviderScript("readChat") || h.getProviderScript("read_chat");
|
|
5376
5545
|
if (script) {
|
|
5377
5546
|
try {
|
|
5378
|
-
const
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5547
|
+
const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
|
|
5548
|
+
if (evalResult?.result) {
|
|
5549
|
+
let parsed = evalResult.result;
|
|
5550
|
+
if (typeof parsed === "string") {
|
|
5551
|
+
try {
|
|
5552
|
+
parsed = JSON.parse(parsed);
|
|
5553
|
+
} catch {
|
|
5554
|
+
}
|
|
5555
|
+
}
|
|
5556
|
+
if (parsed && typeof parsed === "object" && parsed.messages?.length > 0) {
|
|
5557
|
+
_log(`OK: ${parsed.messages?.length} msgs`);
|
|
5558
|
+
traceProviderEvent(args, "provider", "ide.read_chat.success", {
|
|
5559
|
+
h,
|
|
5560
|
+
provider,
|
|
5561
|
+
payload: {
|
|
5562
|
+
method: "evaluate",
|
|
5563
|
+
result: evalResult.result,
|
|
5564
|
+
parsed,
|
|
5565
|
+
messageCount: Array.isArray(parsed.messages) ? parsed.messages.length : 0
|
|
5566
|
+
}
|
|
5567
|
+
});
|
|
5568
|
+
h.historyWriter.appendNewMessages(
|
|
5569
|
+
provider?.type || getCurrentProviderType(h, "unknown_ide"),
|
|
5570
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
5571
|
+
parsed.title,
|
|
5572
|
+
args?.targetSessionId,
|
|
5573
|
+
historySessionId
|
|
5574
|
+
);
|
|
5575
|
+
return buildReadChatCommandResult(parsed, args);
|
|
5384
5576
|
}
|
|
5385
|
-
}
|
|
5386
|
-
if (parsed && typeof parsed === "object" && parsed.messages?.length > 0) {
|
|
5387
|
-
_log(`OK: ${parsed.messages?.length} msgs`);
|
|
5388
|
-
h.historyWriter.appendNewMessages(
|
|
5389
|
-
provider?.type || getCurrentProviderType(h, "unknown_ide"),
|
|
5390
|
-
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
5391
|
-
parsed.title,
|
|
5392
|
-
args?.targetSessionId,
|
|
5393
|
-
historySessionId
|
|
5394
|
-
);
|
|
5395
|
-
return buildReadChatCommandResult(parsed, args);
|
|
5396
5577
|
}
|
|
5397
5578
|
} catch (e) {
|
|
5398
5579
|
LOG.info("Command", `[read_chat] Script error: ${e.message}`);
|
|
5580
|
+
traceProviderEvent(args, "provider", "ide.read_chat.error", {
|
|
5581
|
+
h,
|
|
5582
|
+
provider,
|
|
5583
|
+
level: "warn",
|
|
5584
|
+
payload: { method: "evaluate", error: e.message }
|
|
5585
|
+
});
|
|
5399
5586
|
}
|
|
5400
5587
|
}
|
|
5401
5588
|
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
@@ -6043,6 +6230,7 @@ var init_chat_commands = __esm({
|
|
|
6043
6230
|
init_contracts();
|
|
6044
6231
|
init_chat_history();
|
|
6045
6232
|
init_logger();
|
|
6233
|
+
init_debug_trace();
|
|
6046
6234
|
RECENT_SEND_WINDOW_MS = 1200;
|
|
6047
6235
|
recentSendByTarget = /* @__PURE__ */ new Map();
|
|
6048
6236
|
}
|
|
@@ -32136,6 +32324,7 @@ function logCommand(entry) {
|
|
|
32136
32324
|
ts: entry.ts,
|
|
32137
32325
|
cmd: entry.cmd,
|
|
32138
32326
|
src: entry.source,
|
|
32327
|
+
...entry.interactionId ? { interactionId: entry.interactionId } : {},
|
|
32139
32328
|
...entry.args ? { args: maskArgs(entry.args) } : {},
|
|
32140
32329
|
...entry.success !== void 0 ? { ok: entry.success } : {},
|
|
32141
32330
|
...entry.error ? { err: entry.error } : {},
|
|
@@ -32157,6 +32346,7 @@ function getRecentCommands(count = 50) {
|
|
|
32157
32346
|
ts: parsed.ts,
|
|
32158
32347
|
cmd: parsed.cmd,
|
|
32159
32348
|
source: parsed.src,
|
|
32349
|
+
interactionId: parsed.interactionId,
|
|
32160
32350
|
args: parsed.args,
|
|
32161
32351
|
success: parsed.ok,
|
|
32162
32352
|
error: parsed.err,
|
|
@@ -32663,6 +32853,13 @@ function normalizeCommandSource(source) {
|
|
|
32663
32853
|
return "unknown";
|
|
32664
32854
|
}
|
|
32665
32855
|
}
|
|
32856
|
+
function normalizeCommandArgsWithInteractionId(args) {
|
|
32857
|
+
const base = args && typeof args === "object" ? { ...args } : {};
|
|
32858
|
+
if (typeof base._interactionId !== "string" || !String(base._interactionId).trim()) {
|
|
32859
|
+
base._interactionId = createInteractionId();
|
|
32860
|
+
}
|
|
32861
|
+
return base;
|
|
32862
|
+
}
|
|
32666
32863
|
function toHostedCliRuntimeDescriptor(record2) {
|
|
32667
32864
|
if (!record2 || typeof record2 !== "object") return null;
|
|
32668
32865
|
const runtimeId = typeof record2.sessionId === "string" ? record2.sessionId : "";
|
|
@@ -32700,6 +32897,7 @@ var init_router = __esm({
|
|
|
32700
32897
|
init_logger();
|
|
32701
32898
|
init_command_log();
|
|
32702
32899
|
init_logger();
|
|
32900
|
+
init_debug_trace();
|
|
32703
32901
|
init_builders();
|
|
32704
32902
|
init_snapshot();
|
|
32705
32903
|
init_snapshot();
|
|
@@ -32732,20 +32930,50 @@ var init_router = __esm({
|
|
|
32732
32930
|
async execute(cmd, args, source = "unknown") {
|
|
32733
32931
|
const cmdStart = Date.now();
|
|
32734
32932
|
const logSource = normalizeCommandSource(source);
|
|
32933
|
+
const normalizedArgs = normalizeCommandArgsWithInteractionId(args);
|
|
32934
|
+
const interactionId = typeof normalizedArgs._interactionId === "string" ? normalizedArgs._interactionId : void 0;
|
|
32935
|
+
recordDebugTrace({
|
|
32936
|
+
interactionId,
|
|
32937
|
+
category: "command",
|
|
32938
|
+
stage: "received",
|
|
32939
|
+
level: "info",
|
|
32940
|
+
payload: { cmd, source: logSource }
|
|
32941
|
+
});
|
|
32735
32942
|
try {
|
|
32736
|
-
const daemonResult = await this.executeDaemonCommand(cmd,
|
|
32943
|
+
const daemonResult = await this.executeDaemonCommand(cmd, normalizedArgs);
|
|
32737
32944
|
if (daemonResult) {
|
|
32738
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, args, success: daemonResult.success, durationMs: Date.now() - cmdStart });
|
|
32945
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, interactionId, args: normalizedArgs, success: daemonResult.success, durationMs: Date.now() - cmdStart });
|
|
32946
|
+
recordDebugTrace({
|
|
32947
|
+
interactionId,
|
|
32948
|
+
category: "command",
|
|
32949
|
+
stage: "completed",
|
|
32950
|
+
level: daemonResult.success ? "info" : "warn",
|
|
32951
|
+
payload: { cmd, source: logSource, success: daemonResult.success, durationMs: Date.now() - cmdStart }
|
|
32952
|
+
});
|
|
32739
32953
|
return daemonResult;
|
|
32740
32954
|
}
|
|
32741
|
-
const handlerResult = await this.deps.commandHandler.handle(cmd,
|
|
32742
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, args, success: handlerResult.success, durationMs: Date.now() - cmdStart });
|
|
32955
|
+
const handlerResult = await this.deps.commandHandler.handle(cmd, normalizedArgs);
|
|
32956
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, interactionId, args: normalizedArgs, success: handlerResult.success, durationMs: Date.now() - cmdStart });
|
|
32957
|
+
recordDebugTrace({
|
|
32958
|
+
interactionId,
|
|
32959
|
+
category: "command",
|
|
32960
|
+
stage: "completed",
|
|
32961
|
+
level: handlerResult.success ? "info" : "warn",
|
|
32962
|
+
payload: { cmd, source: logSource, success: handlerResult.success, durationMs: Date.now() - cmdStart }
|
|
32963
|
+
});
|
|
32743
32964
|
if (CHAT_COMMANDS.includes(cmd) && this.deps.onPostChatCommand) {
|
|
32744
32965
|
this.deps.onPostChatCommand();
|
|
32745
32966
|
}
|
|
32746
32967
|
return handlerResult;
|
|
32747
32968
|
} catch (e) {
|
|
32748
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, args, success: false, error: e.message, durationMs: Date.now() - cmdStart });
|
|
32969
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd, source: logSource, interactionId, args: normalizedArgs, success: false, error: e.message, durationMs: Date.now() - cmdStart });
|
|
32970
|
+
recordDebugTrace({
|
|
32971
|
+
interactionId,
|
|
32972
|
+
category: "command",
|
|
32973
|
+
stage: "failed",
|
|
32974
|
+
level: "error",
|
|
32975
|
+
payload: { cmd, source: logSource, error: e?.message || String(e), durationMs: Date.now() - cmdStart }
|
|
32976
|
+
});
|
|
32749
32977
|
throw e;
|
|
32750
32978
|
}
|
|
32751
32979
|
}
|
|
@@ -32787,6 +33015,14 @@ var init_router = __esm({
|
|
|
32787
33015
|
return { success: false, error: e.message };
|
|
32788
33016
|
}
|
|
32789
33017
|
}
|
|
33018
|
+
case "get_debug_trace": {
|
|
33019
|
+
const count = parseInt(args?.count) || parseInt(args?.limit) || 100;
|
|
33020
|
+
const sinceTs = Number(args?.since) || 0;
|
|
33021
|
+
const interactionId = typeof args?.interactionId === "string" ? args.interactionId : void 0;
|
|
33022
|
+
const category = typeof args?.category === "string" ? args.category : void 0;
|
|
33023
|
+
const trace = getRecentDebugTrace({ interactionId, category, limit: count }).filter((entry) => !sinceTs || entry.ts > sinceTs);
|
|
33024
|
+
return { success: true, trace, count: trace.length };
|
|
33025
|
+
}
|
|
32790
33026
|
case "session_host_get_diagnostics": {
|
|
32791
33027
|
if (!this.deps.sessionHostControl) return { success: false, error: "Session host control unavailable" };
|
|
32792
33028
|
const diagnostics = await this.deps.sessionHostControl.getDiagnostics({
|
|
@@ -40256,6 +40492,22 @@ var init_session_host_transport = __esm({
|
|
|
40256
40492
|
}
|
|
40257
40493
|
});
|
|
40258
40494
|
|
|
40495
|
+
// ../../oss/packages/daemon-core/src/session-host/app-name.ts
|
|
40496
|
+
function resolveSessionHostAppName(options = {}) {
|
|
40497
|
+
const env = options.env || process.env;
|
|
40498
|
+
const explicit = typeof env.ADHDEV_SESSION_HOST_NAME === "string" ? env.ADHDEV_SESSION_HOST_NAME.trim() : "";
|
|
40499
|
+
if (explicit) return explicit;
|
|
40500
|
+
return options.standalone ? DEFAULT_STANDALONE_SESSION_HOST_APP_NAME : DEFAULT_SESSION_HOST_APP_NAME;
|
|
40501
|
+
}
|
|
40502
|
+
var DEFAULT_SESSION_HOST_APP_NAME, DEFAULT_STANDALONE_SESSION_HOST_APP_NAME;
|
|
40503
|
+
var init_app_name = __esm({
|
|
40504
|
+
"../../oss/packages/daemon-core/src/session-host/app-name.ts"() {
|
|
40505
|
+
"use strict";
|
|
40506
|
+
DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
|
|
40507
|
+
DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
|
|
40508
|
+
}
|
|
40509
|
+
});
|
|
40510
|
+
|
|
40259
40511
|
// ../../oss/packages/daemon-core/src/session-host/runtime-support.ts
|
|
40260
40512
|
async function canConnect(endpoint) {
|
|
40261
40513
|
const client = new SessionHostClient({ endpoint });
|
|
@@ -40825,6 +41077,8 @@ __export(src_exports, {
|
|
|
40825
41077
|
CliProviderInstance: () => CliProviderInstance,
|
|
40826
41078
|
DAEMON_WS_PATH: () => DAEMON_WS_PATH,
|
|
40827
41079
|
DEFAULT_DAEMON_PORT: () => DEFAULT_DAEMON_PORT,
|
|
41080
|
+
DEFAULT_SESSION_HOST_APP_NAME: () => DEFAULT_SESSION_HOST_APP_NAME,
|
|
41081
|
+
DEFAULT_STANDALONE_SESSION_HOST_APP_NAME: () => DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
|
|
40828
41082
|
DaemonAgentStreamManager: () => DaemonAgentStreamManager,
|
|
40829
41083
|
DaemonCdpInitializer: () => DaemonCdpInitializer,
|
|
40830
41084
|
DaemonCdpManager: () => DaemonCdpManager,
|
|
@@ -40846,7 +41100,11 @@ __export(src_exports, {
|
|
|
40846
41100
|
buildMachineInfo: () => buildMachineInfo,
|
|
40847
41101
|
buildSessionEntries: () => buildSessionEntries,
|
|
40848
41102
|
buildStatusSnapshot: () => buildStatusSnapshot,
|
|
41103
|
+
clearDebugTrace: () => clearDebugTrace,
|
|
41104
|
+
configureDebugTraceStore: () => configureDebugTraceStore,
|
|
40849
41105
|
connectCdpManager: () => connectCdpManager,
|
|
41106
|
+
createDebugTraceStore: () => createDebugTraceStore,
|
|
41107
|
+
createInteractionId: () => createInteractionId,
|
|
40850
41108
|
detectAllVersions: () => detectAllVersions,
|
|
40851
41109
|
detectCLIs: () => detectCLIs,
|
|
40852
41110
|
detectIDEs: () => detectIDEs,
|
|
@@ -40857,10 +41115,12 @@ __export(src_exports, {
|
|
|
40857
41115
|
getAvailableIdeIds: () => getAvailableIdeIds,
|
|
40858
41116
|
getCurrentDaemonLogPath: () => getCurrentDaemonLogPath,
|
|
40859
41117
|
getDaemonLogDir: () => getDaemonLogDir,
|
|
41118
|
+
getDebugRuntimeConfig: () => getDebugRuntimeConfig,
|
|
40860
41119
|
getHostMemorySnapshot: () => getHostMemorySnapshot,
|
|
40861
41120
|
getLogLevel: () => getLogLevel,
|
|
40862
41121
|
getRecentActivity: () => getRecentActivity,
|
|
40863
41122
|
getRecentCommands: () => getRecentCommands,
|
|
41123
|
+
getRecentDebugTrace: () => getRecentDebugTrace,
|
|
40864
41124
|
getRecentLogs: () => getRecentLogs,
|
|
40865
41125
|
getSavedProviderSessions: () => getSavedProviderSessions,
|
|
40866
41126
|
getWorkspaceState: () => getWorkspaceState,
|
|
@@ -40887,13 +41147,19 @@ __export(src_exports, {
|
|
|
40887
41147
|
normalizeManagedStatus: () => normalizeManagedStatus,
|
|
40888
41148
|
probeCdpPort: () => probeCdpPort,
|
|
40889
41149
|
readChatHistory: () => readChatHistory,
|
|
41150
|
+
recordDebugTrace: () => recordDebugTrace,
|
|
40890
41151
|
registerExtensionProviders: () => registerExtensionProviders,
|
|
40891
41152
|
resetConfig: () => resetConfig,
|
|
41153
|
+
resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
|
|
40892
41154
|
resetState: () => resetState,
|
|
41155
|
+
resolveDebugRuntimeConfig: () => resolveDebugRuntimeConfig,
|
|
41156
|
+
resolveSessionHostAppName: () => resolveSessionHostAppName,
|
|
40893
41157
|
saveConfig: () => saveConfig,
|
|
40894
41158
|
saveState: () => saveState,
|
|
41159
|
+
setDebugRuntimeConfig: () => setDebugRuntimeConfig,
|
|
40895
41160
|
setLogLevel: () => setLogLevel,
|
|
40896
41161
|
setupIdeInstance: () => setupIdeInstance,
|
|
41162
|
+
shouldCollectTraceCategory: () => shouldCollectTraceCategory,
|
|
40897
41163
|
shutdownDaemonComponents: () => shutdownDaemonComponents,
|
|
40898
41164
|
spawnDetachedDaemonUpgradeHelper: () => spawnDetachedDaemonUpgradeHelper,
|
|
40899
41165
|
startDaemonDevSupport: () => startDaemonDevSupport,
|
|
@@ -40924,6 +41190,8 @@ var init_src = __esm({
|
|
|
40924
41190
|
init_snapshot();
|
|
40925
41191
|
init_normalize();
|
|
40926
41192
|
init_logger();
|
|
41193
|
+
init_debug_config();
|
|
41194
|
+
init_debug_trace();
|
|
40927
41195
|
init_command_log();
|
|
40928
41196
|
init_cli_manager();
|
|
40929
41197
|
init_launch();
|
|
@@ -40942,6 +41210,7 @@ var init_src = __esm({
|
|
|
40942
41210
|
init_provider_cli_adapter();
|
|
40943
41211
|
init_pty_transport();
|
|
40944
41212
|
init_session_host_transport();
|
|
41213
|
+
init_app_name();
|
|
40945
41214
|
init_runtime_support();
|
|
40946
41215
|
init_installer();
|
|
40947
41216
|
init_daemon_lifecycle();
|
|
@@ -49116,18 +49385,6 @@ function killPid2(pid) {
|
|
|
49116
49385
|
}
|
|
49117
49386
|
function getWindowsProcessCommandLine(pid) {
|
|
49118
49387
|
const pidFilter = `ProcessId=${pid}`;
|
|
49119
|
-
try {
|
|
49120
|
-
const wmicOut = (0, import_child_process11.execFileSync)("wmic", [
|
|
49121
|
-
"process",
|
|
49122
|
-
"where",
|
|
49123
|
-
pidFilter,
|
|
49124
|
-
"get",
|
|
49125
|
-
"CommandLine"
|
|
49126
|
-
], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
49127
|
-
const text = wmicOut.trim();
|
|
49128
|
-
if (text) return text;
|
|
49129
|
-
} catch {
|
|
49130
|
-
}
|
|
49131
49388
|
try {
|
|
49132
49389
|
const psOut = (0, import_child_process11.execFileSync)("powershell.exe", [
|
|
49133
49390
|
"-NoProfile",
|
|
@@ -49141,6 +49398,18 @@ function getWindowsProcessCommandLine(pid) {
|
|
|
49141
49398
|
if (text) return text;
|
|
49142
49399
|
} catch {
|
|
49143
49400
|
}
|
|
49401
|
+
try {
|
|
49402
|
+
const wmicOut = (0, import_child_process11.execFileSync)("wmic", [
|
|
49403
|
+
"process",
|
|
49404
|
+
"where",
|
|
49405
|
+
pidFilter,
|
|
49406
|
+
"get",
|
|
49407
|
+
"CommandLine"
|
|
49408
|
+
], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
49409
|
+
const text = wmicOut.trim();
|
|
49410
|
+
if (text) return text;
|
|
49411
|
+
} catch {
|
|
49412
|
+
}
|
|
49144
49413
|
return null;
|
|
49145
49414
|
}
|
|
49146
49415
|
function stopSessionHost() {
|
|
@@ -49149,7 +49418,7 @@ function stopSessionHost() {
|
|
|
49149
49418
|
try {
|
|
49150
49419
|
if (fs16.existsSync(pidFile)) {
|
|
49151
49420
|
const pid = Number.parseInt(fs16.readFileSync(pidFile, "utf8").trim(), 10);
|
|
49152
|
-
if (Number.isFinite(pid)) {
|
|
49421
|
+
if (Number.isFinite(pid) && pid !== process.pid) {
|
|
49153
49422
|
stopped = killPid2(pid) || stopped;
|
|
49154
49423
|
}
|
|
49155
49424
|
}
|
|
@@ -49185,7 +49454,7 @@ function stopSessionHost() {
|
|
|
49185
49454
|
const raw = (0, import_child_process11.execFileSync)("pgrep", ["-f", "session-host-daemon"], { encoding: "utf8" }).trim();
|
|
49186
49455
|
for (const line of raw.split("\n")) {
|
|
49187
49456
|
const pid = Number.parseInt(line.trim(), 10);
|
|
49188
|
-
if (Number.isFinite(pid)) {
|
|
49457
|
+
if (Number.isFinite(pid) && pid !== process.pid && pid !== process.ppid) {
|
|
49189
49458
|
stopped = killPid2(pid) || stopped;
|
|
49190
49459
|
}
|
|
49191
49460
|
}
|
|
@@ -49498,11 +49767,21 @@ function removeDaemonPid() {
|
|
|
49498
49767
|
}
|
|
49499
49768
|
function isDaemonRunning() {
|
|
49500
49769
|
try {
|
|
49501
|
-
const
|
|
49502
|
-
const
|
|
49503
|
-
|
|
49504
|
-
|
|
49505
|
-
|
|
49770
|
+
const { execFileSync: execFileSync3 } = require("child_process");
|
|
49771
|
+
const probe = `
|
|
49772
|
+
const http = require('http');
|
|
49773
|
+
const req = http.get('http://127.0.0.1:${DEFAULT_DAEMON_PORT}/health', { timeout: 1500 }, (res) => {
|
|
49774
|
+
process.stdout.write(String(res.statusCode));
|
|
49775
|
+
res.resume();
|
|
49776
|
+
});
|
|
49777
|
+
req.on('error', () => process.stdout.write('0'));
|
|
49778
|
+
req.on('timeout', () => { req.destroy(); process.stdout.write('0'); });
|
|
49779
|
+
`;
|
|
49780
|
+
const result = execFileSync3(process.execPath, ["-e", probe], {
|
|
49781
|
+
encoding: "utf-8",
|
|
49782
|
+
timeout: 3e3,
|
|
49783
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
49784
|
+
}).trim();
|
|
49506
49785
|
if (result === "200") return true;
|
|
49507
49786
|
} catch {
|
|
49508
49787
|
}
|
|
@@ -49511,12 +49790,46 @@ function isDaemonRunning() {
|
|
|
49511
49790
|
if (!fs17.existsSync(pidFile)) return false;
|
|
49512
49791
|
const pid = parseInt(fs17.readFileSync(pidFile, "utf-8").trim());
|
|
49513
49792
|
process.kill(pid, 0);
|
|
49793
|
+
if (!isAdhdevProcess(pid)) {
|
|
49794
|
+
removeDaemonPid();
|
|
49795
|
+
return false;
|
|
49796
|
+
}
|
|
49514
49797
|
return true;
|
|
49515
49798
|
} catch {
|
|
49516
49799
|
removeDaemonPid();
|
|
49517
49800
|
return false;
|
|
49518
49801
|
}
|
|
49519
49802
|
}
|
|
49803
|
+
function isAdhdevProcess(pid) {
|
|
49804
|
+
try {
|
|
49805
|
+
if (process.platform === "win32") {
|
|
49806
|
+
const { execFileSync: execFileSync3 } = require("child_process");
|
|
49807
|
+
try {
|
|
49808
|
+
const psOut = execFileSync3("powershell.exe", [
|
|
49809
|
+
"-NoProfile",
|
|
49810
|
+
"-NonInteractive",
|
|
49811
|
+
"-ExecutionPolicy",
|
|
49812
|
+
"Bypass",
|
|
49813
|
+
"-Command",
|
|
49814
|
+
`(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CommandLine`
|
|
49815
|
+
], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
49816
|
+
return /adhdev|daemon/i.test(psOut);
|
|
49817
|
+
} catch {
|
|
49818
|
+
return true;
|
|
49819
|
+
}
|
|
49820
|
+
} else {
|
|
49821
|
+
const { execFileSync: execFileSync3 } = require("child_process");
|
|
49822
|
+
const cmdline = execFileSync3("ps", ["-o", "command=", "-p", String(pid)], {
|
|
49823
|
+
encoding: "utf-8",
|
|
49824
|
+
timeout: 2e3,
|
|
49825
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
49826
|
+
}).trim();
|
|
49827
|
+
return /adhdev|daemon/i.test(cmdline);
|
|
49828
|
+
}
|
|
49829
|
+
} catch {
|
|
49830
|
+
return true;
|
|
49831
|
+
}
|
|
49832
|
+
}
|
|
49520
49833
|
function getDaemonPid() {
|
|
49521
49834
|
const pidFile = getDaemonPidFile();
|
|
49522
49835
|
try {
|
|
@@ -49558,7 +49871,7 @@ var init_adhdev_daemon = __esm({
|
|
|
49558
49871
|
import_ws3 = require("ws");
|
|
49559
49872
|
import_chalk2 = __toESM(require("chalk"));
|
|
49560
49873
|
init_version();
|
|
49561
|
-
pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.
|
|
49874
|
+
pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.50" });
|
|
49562
49875
|
ACTIVE_CHAT_POLL_STATUSES = /* @__PURE__ */ new Set([
|
|
49563
49876
|
"generating",
|
|
49564
49877
|
"waiting_approval",
|
|
@@ -49585,6 +49898,8 @@ var init_adhdev_daemon = __esm({
|
|
|
49585
49898
|
ideType = "unknown";
|
|
49586
49899
|
pendingMandatoryUpdate = null;
|
|
49587
49900
|
mandatoryUpgradeInFlight = false;
|
|
49901
|
+
debugConfig = resolveDebugRuntimeConfig();
|
|
49902
|
+
recentInteractionIdsBySession = /* @__PURE__ */ new Map();
|
|
49588
49903
|
static MANDATORY_UPDATE_BLOCKED_COMMANDS = /* @__PURE__ */ new Set([
|
|
49589
49904
|
"launch_ide",
|
|
49590
49905
|
"launch_cli",
|
|
@@ -49595,6 +49910,36 @@ var init_adhdev_daemon = __esm({
|
|
|
49595
49910
|
constructor() {
|
|
49596
49911
|
this.localPort = 19222;
|
|
49597
49912
|
}
|
|
49913
|
+
applyDebugRuntime(options) {
|
|
49914
|
+
this.debugConfig = resolveDebugRuntimeConfig({
|
|
49915
|
+
dev: options.dev,
|
|
49916
|
+
logLevel: options.logLevel,
|
|
49917
|
+
trace: options.trace,
|
|
49918
|
+
traceContent: options.traceContent,
|
|
49919
|
+
traceBufferSize: options.traceBufferSize,
|
|
49920
|
+
traceCategories: options.traceCategories
|
|
49921
|
+
});
|
|
49922
|
+
setDebugRuntimeConfig(this.debugConfig);
|
|
49923
|
+
configureDebugTraceStore();
|
|
49924
|
+
setLogLevel(this.debugConfig.logLevel);
|
|
49925
|
+
LOG.info("Daemon", `Debug runtime configured: level=${this.debugConfig.logLevel} trace=${this.debugConfig.collectDebugTrace ? "on" : "off"} traceContent=${this.debugConfig.traceContent ? "on" : "off"} traceBuffer=${this.debugConfig.traceBufferSize}`);
|
|
49926
|
+
}
|
|
49927
|
+
ensureInteractionContext(args) {
|
|
49928
|
+
const normalized = args && typeof args === "object" ? { ...args } : {};
|
|
49929
|
+
if (typeof normalized._interactionId !== "string" || !String(normalized._interactionId).trim()) {
|
|
49930
|
+
normalized._interactionId = createInteractionId();
|
|
49931
|
+
}
|
|
49932
|
+
const interactionId = String(normalized._interactionId);
|
|
49933
|
+
const targetSessionId = typeof normalized.targetSessionId === "string" ? normalized.targetSessionId : "";
|
|
49934
|
+
if (targetSessionId) {
|
|
49935
|
+
this.recentInteractionIdsBySession.set(targetSessionId, interactionId);
|
|
49936
|
+
}
|
|
49937
|
+
return normalized;
|
|
49938
|
+
}
|
|
49939
|
+
getSessionInteractionId(sessionId) {
|
|
49940
|
+
if (!sessionId) return void 0;
|
|
49941
|
+
return this.recentInteractionIdsBySession.get(sessionId);
|
|
49942
|
+
}
|
|
49598
49943
|
getCliPresentationMode(sessionId) {
|
|
49599
49944
|
if (!sessionId || !this.components) return null;
|
|
49600
49945
|
const instance = this.components.instanceManager.getInstance(sessionId);
|
|
@@ -49709,11 +50054,27 @@ var init_adhdev_daemon = __esm({
|
|
|
49709
50054
|
return null;
|
|
49710
50055
|
}
|
|
49711
50056
|
subscription.lastDeliveredSignature = deliverySignature;
|
|
50057
|
+
const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
|
|
50058
|
+
recordDebugTrace({
|
|
50059
|
+
interactionId,
|
|
50060
|
+
category: "topic",
|
|
50061
|
+
stage: "session.chat_tail_published",
|
|
50062
|
+
level: "info",
|
|
50063
|
+
sessionId: subscription.params.targetSessionId,
|
|
50064
|
+
payload: {
|
|
50065
|
+
syncMode,
|
|
50066
|
+
totalMessages: Number(result.totalMessages || 0),
|
|
50067
|
+
replaceFrom: Number(result.replaceFrom || 0),
|
|
50068
|
+
hasModal: !!activeModal,
|
|
50069
|
+
hasTitle: typeof result.title === "string"
|
|
50070
|
+
}
|
|
50071
|
+
});
|
|
49712
50072
|
return {
|
|
49713
50073
|
topic: "session.chat_tail",
|
|
49714
50074
|
key: subscription.key,
|
|
49715
50075
|
sessionId: subscription.params.targetSessionId,
|
|
49716
50076
|
...subscription.params.historySessionId ? { historySessionId: subscription.params.historySessionId } : {},
|
|
50077
|
+
...interactionId ? { interactionId } : {},
|
|
49717
50078
|
seq: subscription.seq,
|
|
49718
50079
|
timestamp: Date.now(),
|
|
49719
50080
|
messages: Array.isArray(result.messages) ? result.messages : [],
|
|
@@ -49859,6 +50220,20 @@ var init_adhdev_daemon = __esm({
|
|
|
49859
50220
|
subscription.lastDeliveredSignature = deliverySignature;
|
|
49860
50221
|
subscription.seq += 1;
|
|
49861
50222
|
subscription.lastSentAt = now;
|
|
50223
|
+
const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
|
|
50224
|
+
recordDebugTrace({
|
|
50225
|
+
interactionId,
|
|
50226
|
+
category: "topic",
|
|
50227
|
+
stage: "session.modal_published",
|
|
50228
|
+
level: "info",
|
|
50229
|
+
sessionId: subscription.params.targetSessionId,
|
|
50230
|
+
payload: {
|
|
50231
|
+
status,
|
|
50232
|
+
hasTitle: !!title,
|
|
50233
|
+
modalMessage: modalMessage ? modalMessage.slice(0, 140) : void 0,
|
|
50234
|
+
modalButtonCount: modalButtons.length
|
|
50235
|
+
}
|
|
50236
|
+
});
|
|
49862
50237
|
return {
|
|
49863
50238
|
topic: "session.modal",
|
|
49864
50239
|
key: subscription.key,
|
|
@@ -49867,6 +50242,7 @@ var init_adhdev_daemon = __esm({
|
|
|
49867
50242
|
...title ? { title } : {},
|
|
49868
50243
|
...modalMessage ? { modalMessage } : {},
|
|
49869
50244
|
...modalButtons.length > 0 ? { modalButtons } : {},
|
|
50245
|
+
...interactionId ? { interactionId } : {},
|
|
49870
50246
|
seq: subscription.seq,
|
|
49871
50247
|
timestamp: now
|
|
49872
50248
|
};
|
|
@@ -49912,6 +50288,7 @@ var init_adhdev_daemon = __esm({
|
|
|
49912
50288
|
}
|
|
49913
50289
|
async start(options = {}) {
|
|
49914
50290
|
installGlobalInterceptor();
|
|
50291
|
+
this.applyDebugRuntime(options);
|
|
49915
50292
|
process.on("uncaughtException", (err) => {
|
|
49916
50293
|
LOG.error("Daemon", `Uncaught exception: ${err?.message}
|
|
49917
50294
|
${err?.stack || ""}`);
|
|
@@ -49938,6 +50315,7 @@ ${err?.stack || ""}`);
|
|
|
49938
50315
|
console.log(import_chalk2.default.gray(" Run `adhdev setup` first.\n"));
|
|
49939
50316
|
process.exit(1);
|
|
49940
50317
|
}
|
|
50318
|
+
await this.startLocalIpcServer();
|
|
49941
50319
|
const sessionHostEndpoint = await ensureSessionHostReady2();
|
|
49942
50320
|
this.sessionHostEndpoint = sessionHostEndpoint;
|
|
49943
50321
|
this.sessionHostController = new SessionHostController(
|
|
@@ -50000,7 +50378,6 @@ ${err?.stack || ""}`);
|
|
|
50000
50378
|
}
|
|
50001
50379
|
});
|
|
50002
50380
|
await this.components.cliManager.restoreHostedSessions();
|
|
50003
|
-
await this.startLocalIpcServer();
|
|
50004
50381
|
this.components.providerLoader.fetchLatest().then(({ updated }) => {
|
|
50005
50382
|
if (updated) {
|
|
50006
50383
|
this.components.providerLoader.reload();
|
|
@@ -50214,7 +50591,9 @@ ${err?.stack || ""}`);
|
|
|
50214
50591
|
});
|
|
50215
50592
|
}
|
|
50216
50593
|
async handleCommand(msg, cmd, args) {
|
|
50217
|
-
|
|
50594
|
+
const normalizedArgs = this.ensureInteractionContext(args);
|
|
50595
|
+
const interactionId = String(normalizedArgs._interactionId);
|
|
50596
|
+
LOG.info("Command", `${cmd}${normalizedArgs?.targetSessionId ? ` \u2192 session:${String(normalizedArgs.targetSessionId).split("_")[0]}` : ""} [${interactionId}]`);
|
|
50218
50597
|
const cmdStart = Date.now();
|
|
50219
50598
|
const source = msg.ipcWs ? "ext" : typeof msg.source === "string" && msg.source.trim() ? msg.source : "ws";
|
|
50220
50599
|
try {
|
|
@@ -50224,18 +50603,20 @@ ${err?.stack || ""}`);
|
|
|
50224
50603
|
code: "DAEMON_UPDATE_REQUIRED",
|
|
50225
50604
|
required: true,
|
|
50226
50605
|
latest: this.pendingMandatoryUpdate.targetVersion,
|
|
50227
|
-
reason: this.pendingMandatoryUpdate.reason
|
|
50606
|
+
reason: this.pendingMandatoryUpdate.reason,
|
|
50607
|
+
interactionId
|
|
50228
50608
|
});
|
|
50229
50609
|
return;
|
|
50230
50610
|
}
|
|
50231
50611
|
if (source === "api" && !loadConfig().allowServerApiProxy) {
|
|
50232
50612
|
this.sendResult(msg, false, {
|
|
50233
50613
|
error: "Server API relay is disabled on this daemon. Enable it explicitly with `adhdev daemon:api enable`.",
|
|
50234
|
-
code: "SERVER_API_DISABLED"
|
|
50614
|
+
code: "SERVER_API_DISABLED",
|
|
50615
|
+
interactionId
|
|
50235
50616
|
});
|
|
50236
50617
|
return;
|
|
50237
50618
|
}
|
|
50238
|
-
const result = await this.components.router.execute(cmd,
|
|
50619
|
+
const result = await this.components.router.execute(cmd, normalizedArgs, source);
|
|
50239
50620
|
if (cmd.startsWith("workspace_")) this.statusReporter?.throttledReport();
|
|
50240
50621
|
if (cmd === "get_status_metadata" || cmd.startsWith("workspace_") || cmd.startsWith("session_host_")) {
|
|
50241
50622
|
void this.flushP2PDaemonMetadataSubscriptions();
|
|
@@ -50246,24 +50627,34 @@ ${err?.stack || ""}`);
|
|
|
50246
50627
|
if (cmd === "resolve_action" || cmd === "send_chat" || cmd === "read_chat") {
|
|
50247
50628
|
void this.flushP2PSessionModalSubscriptions();
|
|
50248
50629
|
}
|
|
50249
|
-
this.sendResult(msg, result.success, result);
|
|
50630
|
+
this.sendResult(msg, result.success, { ...result, interactionId });
|
|
50631
|
+
recordDebugTrace({
|
|
50632
|
+
interactionId,
|
|
50633
|
+
category: "command",
|
|
50634
|
+
stage: "result_sent",
|
|
50635
|
+
level: result.success ? "info" : "warn",
|
|
50636
|
+
sessionId: typeof normalizedArgs.targetSessionId === "string" ? normalizedArgs.targetSessionId : void 0,
|
|
50637
|
+
payload: { cmd, source, durationMs: Date.now() - cmdStart, success: result.success }
|
|
50638
|
+
});
|
|
50250
50639
|
} catch (e) {
|
|
50251
50640
|
console.error(import_chalk2.default.red(` \u2717 Command failed: ${e.message}`));
|
|
50252
|
-
this.sendResult(msg, false, { error: e.message });
|
|
50641
|
+
this.sendResult(msg, false, { error: e.message, interactionId });
|
|
50253
50642
|
}
|
|
50254
50643
|
}
|
|
50255
50644
|
/** P2P command processing — P2P-only commands + unified router */
|
|
50256
50645
|
async handleP2PCommand(cmdType, data) {
|
|
50646
|
+
const normalizedData = this.ensureInteractionContext(data);
|
|
50647
|
+
const interactionId = String(normalizedData._interactionId);
|
|
50257
50648
|
const cmdStart = Date.now();
|
|
50258
50649
|
try {
|
|
50259
50650
|
switch (cmdType) {
|
|
50260
50651
|
case "get_runtime_snapshot": {
|
|
50261
|
-
const sessionId = typeof
|
|
50262
|
-
if (!sessionId) return { success: false, error: "sessionId is required" };
|
|
50652
|
+
const sessionId = typeof normalizedData.sessionId === "string" ? normalizedData.sessionId : "";
|
|
50653
|
+
if (!sessionId) return { success: false, error: "sessionId is required", interactionId };
|
|
50263
50654
|
if (!this.isCliSession(sessionId)) {
|
|
50264
|
-
return { success: false, error: "CLI session runtime unavailable", code: "CLI_RUNTIME_UNAVAILABLE" };
|
|
50655
|
+
return { success: false, error: "CLI session runtime unavailable", code: "CLI_RUNTIME_UNAVAILABLE", interactionId };
|
|
50265
50656
|
}
|
|
50266
|
-
if (!this.sessionHostEndpoint) return { success: false, error: "Session host unavailable" };
|
|
50657
|
+
if (!this.sessionHostEndpoint) return { success: false, error: "Session host unavailable", interactionId };
|
|
50267
50658
|
const client = new SessionHostClient({ endpoint: this.sessionHostEndpoint });
|
|
50268
50659
|
try {
|
|
50269
50660
|
await client.connect();
|
|
@@ -50272,31 +50663,30 @@ ${err?.stack || ""}`);
|
|
|
50272
50663
|
payload: { sessionId }
|
|
50273
50664
|
});
|
|
50274
50665
|
if (!snapshot.success || !snapshot.result) {
|
|
50275
|
-
return { success: false, error: snapshot.error || "Runtime snapshot unavailable" };
|
|
50666
|
+
return { success: false, error: snapshot.error || "Runtime snapshot unavailable", interactionId };
|
|
50276
50667
|
}
|
|
50277
|
-
return { success: true, result: snapshot.result };
|
|
50668
|
+
return { success: true, result: snapshot.result, interactionId };
|
|
50278
50669
|
} finally {
|
|
50279
50670
|
await client.close().catch(() => {
|
|
50280
50671
|
});
|
|
50281
50672
|
}
|
|
50282
50673
|
}
|
|
50283
50674
|
case "set_machine_nickname": {
|
|
50284
|
-
const nickname =
|
|
50675
|
+
const nickname = normalizedData.nickname?.trim() || null;
|
|
50285
50676
|
const config2 = loadConfig();
|
|
50286
50677
|
config2.machineNickname = nickname;
|
|
50287
50678
|
saveConfig(config2);
|
|
50288
50679
|
void this.flushP2PDaemonMetadataSubscriptions();
|
|
50289
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd: cmdType, source: "p2p", args: { nickname }, success: true, durationMs: Date.now() - cmdStart });
|
|
50290
|
-
return { success: true, nickname };
|
|
50680
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd: cmdType, source: "p2p", interactionId, args: { nickname }, success: true, durationMs: Date.now() - cmdStart });
|
|
50681
|
+
return { success: true, nickname, interactionId };
|
|
50291
50682
|
}
|
|
50292
50683
|
case "get_command_history": {
|
|
50293
|
-
const
|
|
50294
|
-
const
|
|
50295
|
-
|
|
50296
|
-
return { success: true, history };
|
|
50684
|
+
const count = parseInt(normalizedData.count) || 50;
|
|
50685
|
+
const history = getRecentCommands(count);
|
|
50686
|
+
return { success: true, history, interactionId };
|
|
50297
50687
|
}
|
|
50298
50688
|
}
|
|
50299
|
-
const routed = await this.components.router.execute(cmdType,
|
|
50689
|
+
const routed = await this.components.router.execute(cmdType, normalizedData, "p2p");
|
|
50300
50690
|
if (cmdType.startsWith("workspace_")) this.statusReporter?.throttledReport();
|
|
50301
50691
|
if (cmdType === "get_status_metadata" || cmdType.startsWith("workspace_") || cmdType.startsWith("session_host_")) {
|
|
50302
50692
|
void this.flushP2PDaemonMetadataSubscriptions();
|
|
@@ -50307,10 +50697,10 @@ ${err?.stack || ""}`);
|
|
|
50307
50697
|
if (cmdType === "resolve_action" || cmdType === "send_chat" || cmdType === "read_chat") {
|
|
50308
50698
|
void this.flushP2PSessionModalSubscriptions();
|
|
50309
50699
|
}
|
|
50310
|
-
return routed;
|
|
50700
|
+
return { ...routed, interactionId };
|
|
50311
50701
|
} catch (e) {
|
|
50312
|
-
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd: cmdType, source: "p2p", success: false, error: e.message, durationMs: Date.now() - cmdStart });
|
|
50313
|
-
return { success: false, error: e.message };
|
|
50702
|
+
logCommand({ ts: (/* @__PURE__ */ new Date()).toISOString(), cmd: cmdType, source: "p2p", interactionId, success: false, error: e.message, durationMs: Date.now() - cmdStart });
|
|
50703
|
+
return { success: false, error: e.message, interactionId };
|
|
50314
50704
|
}
|
|
50315
50705
|
}
|
|
50316
50706
|
async startLocalIpcServer() {
|