@adhdev/daemon-core 0.7.3 → 0.7.5
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/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +119 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/boot/daemon-lifecycle.ts +1 -1
- package/src/cdp/initializer.ts +5 -5
- package/src/cdp/scanner.ts +2 -2
- package/src/commands/handler.ts +126 -3
- package/src/commands/stream-commands.ts +0 -1
package/dist/index.mjs
CHANGED
|
@@ -4239,7 +4239,7 @@ var DaemonCdpScanner = class {
|
|
|
4239
4239
|
if (!manager) return;
|
|
4240
4240
|
registerExtensionProviders(this.ctx.providerLoader, manager, ide);
|
|
4241
4241
|
this.ctx.cdpManagers.set(ide, manager);
|
|
4242
|
-
LOG.info("
|
|
4242
|
+
LOG.info("IDE", `Attached: ${ide} (port ${port})`);
|
|
4243
4243
|
await setupIdeInstance(this.ctx, { ideType: ide, manager });
|
|
4244
4244
|
this.opts.onConnected?.(ide, ide, manager);
|
|
4245
4245
|
}
|
|
@@ -4272,7 +4272,7 @@ var DaemonCdpScanner = class {
|
|
|
4272
4272
|
);
|
|
4273
4273
|
if (!manager) continue;
|
|
4274
4274
|
this.ctx.cdpManagers.set(managerKey, manager);
|
|
4275
|
-
LOG.info("
|
|
4275
|
+
LOG.info("IDE", `Attached window: ${managerKey} (port ${port}, page "${target.title}")`);
|
|
4276
4276
|
await setupIdeInstance(this.ctx, {
|
|
4277
4277
|
ideType: ide,
|
|
4278
4278
|
manager,
|
|
@@ -4317,9 +4317,9 @@ var DaemonCdpInitializer = class {
|
|
|
4317
4317
|
await this.connectIdePort(port, ide);
|
|
4318
4318
|
}
|
|
4319
4319
|
if (cdpManagers.size > 0) {
|
|
4320
|
-
LOG.info("
|
|
4320
|
+
LOG.info("IDE", `${cdpManagers.size} IDE window(s) attached: ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}`);
|
|
4321
4321
|
} else {
|
|
4322
|
-
LOG.warn("
|
|
4322
|
+
LOG.warn("IDE", `No IDE windows attached \u2014 tried: ${filtered.map((p) => `${p.ide}:${p.port}`).join(", ")}`);
|
|
4323
4323
|
}
|
|
4324
4324
|
}
|
|
4325
4325
|
// ─── Per-port connection (multi-window aware) ───
|
|
@@ -4345,7 +4345,7 @@ var DaemonCdpInitializer = class {
|
|
|
4345
4345
|
if (connected) {
|
|
4346
4346
|
registerExtensionProviders(providerLoader, manager, ide);
|
|
4347
4347
|
cdpManagers.set(ide, manager);
|
|
4348
|
-
LOG.info("
|
|
4348
|
+
LOG.info("IDE", `Attached: ${ide} (port ${port})`);
|
|
4349
4349
|
await this.config.onConnected?.(ide, manager, ide);
|
|
4350
4350
|
}
|
|
4351
4351
|
return;
|
|
@@ -4378,7 +4378,7 @@ var DaemonCdpInitializer = class {
|
|
|
4378
4378
|
if (connected) {
|
|
4379
4379
|
registerExtensionProviders(providerLoader, manager, ide);
|
|
4380
4380
|
cdpManagers.set(managerKey, manager);
|
|
4381
|
-
LOG.info("
|
|
4381
|
+
LOG.info("IDE", `Attached window: ${managerKey} (port ${port}${targets.length > 1 ? `, page "${target.title}"` : ""})`);
|
|
4382
4382
|
await this.config.onConnected?.(ide, manager, managerKey);
|
|
4383
4383
|
}
|
|
4384
4384
|
}
|
|
@@ -4407,7 +4407,7 @@ var DaemonCdpInitializer = class {
|
|
|
4407
4407
|
} catch {
|
|
4408
4408
|
}
|
|
4409
4409
|
this.config.cdpManagers.delete(key);
|
|
4410
|
-
LOG.info("
|
|
4410
|
+
LOG.info("IDE", `Detached window: ${key} (${reason})`);
|
|
4411
4411
|
await this.config.onDisconnected?.(ide, manager, key, reason);
|
|
4412
4412
|
}
|
|
4413
4413
|
}
|
|
@@ -5803,7 +5803,6 @@ function handleSetProviderSetting(h, args) {
|
|
|
5803
5803
|
}
|
|
5804
5804
|
async function handleExtensionScript(h, args, scriptName) {
|
|
5805
5805
|
const { agentType, ideType } = args || {};
|
|
5806
|
-
LOG.info("Command", `[ExtScript] ${scriptName} agentType=${agentType} ideType=${ideType} session=${h.currentSession?.sessionId || ""}`);
|
|
5807
5806
|
if (!agentType) return { success: false, error: "agentType is required" };
|
|
5808
5807
|
const loader = h.ctx.providerLoader;
|
|
5809
5808
|
if (!loader) return { success: false, error: "ProviderLoader not initialized" };
|
|
@@ -6017,6 +6016,83 @@ function handleWorkspaceSetDefault(args) {
|
|
|
6017
6016
|
|
|
6018
6017
|
// src/commands/handler.ts
|
|
6019
6018
|
init_workspaces();
|
|
6019
|
+
var COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
|
|
6020
|
+
"pty_input",
|
|
6021
|
+
"pty_resize",
|
|
6022
|
+
"cdp_eval",
|
|
6023
|
+
"cdp_batch",
|
|
6024
|
+
"cdp_dom_query",
|
|
6025
|
+
"cdp_dom_dump",
|
|
6026
|
+
"cdp_dom_debug"
|
|
6027
|
+
]);
|
|
6028
|
+
function logAtLevel(level, category, message) {
|
|
6029
|
+
switch (level) {
|
|
6030
|
+
case "debug":
|
|
6031
|
+
LOG.debug(category, message);
|
|
6032
|
+
return;
|
|
6033
|
+
case "warn":
|
|
6034
|
+
LOG.warn(category, message);
|
|
6035
|
+
return;
|
|
6036
|
+
case "error":
|
|
6037
|
+
LOG.error(category, message);
|
|
6038
|
+
return;
|
|
6039
|
+
default:
|
|
6040
|
+
LOG.info(category, message);
|
|
6041
|
+
}
|
|
6042
|
+
}
|
|
6043
|
+
function getCommandLogLevel(cmd) {
|
|
6044
|
+
return COMMAND_DEBUG_LEVELS.has(cmd) ? "debug" : "info";
|
|
6045
|
+
}
|
|
6046
|
+
function summarizeLogValue(value) {
|
|
6047
|
+
if (value === null) return "null";
|
|
6048
|
+
if (value === void 0) return "undefined";
|
|
6049
|
+
if (typeof value === "string") {
|
|
6050
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
6051
|
+
if (!normalized) return '""';
|
|
6052
|
+
if (normalized.length <= 80) return JSON.stringify(normalized);
|
|
6053
|
+
return `${JSON.stringify(normalized.slice(0, 80))}\u2026(${normalized.length} chars)`;
|
|
6054
|
+
}
|
|
6055
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
6056
|
+
if (Array.isArray(value)) return `[${value.length} items]`;
|
|
6057
|
+
if (typeof value === "object") return "{...}";
|
|
6058
|
+
return String(value);
|
|
6059
|
+
}
|
|
6060
|
+
function summarizeCommandArgs(args) {
|
|
6061
|
+
if (!args || typeof args !== "object") return "-";
|
|
6062
|
+
const preferredKeys = [
|
|
6063
|
+
"targetSessionId",
|
|
6064
|
+
"providerType",
|
|
6065
|
+
"agentType",
|
|
6066
|
+
"ideType",
|
|
6067
|
+
"model",
|
|
6068
|
+
"mode",
|
|
6069
|
+
"action",
|
|
6070
|
+
"button",
|
|
6071
|
+
"key",
|
|
6072
|
+
"force",
|
|
6073
|
+
"offset",
|
|
6074
|
+
"limit",
|
|
6075
|
+
"cols",
|
|
6076
|
+
"rows",
|
|
6077
|
+
"path",
|
|
6078
|
+
"command",
|
|
6079
|
+
"commandId",
|
|
6080
|
+
"workspace",
|
|
6081
|
+
"dir",
|
|
6082
|
+
"url",
|
|
6083
|
+
"text",
|
|
6084
|
+
"message",
|
|
6085
|
+
"data",
|
|
6086
|
+
"value"
|
|
6087
|
+
];
|
|
6088
|
+
const entries = [];
|
|
6089
|
+
for (const key of preferredKeys) {
|
|
6090
|
+
if (!(key in args) || args[key] === void 0) continue;
|
|
6091
|
+
const value = key === "text" || key === "message" ? `${String(args[key] || "").length} chars` : key === "data" ? `${String(args[key] || "").length} chars` : summarizeLogValue(args[key]);
|
|
6092
|
+
entries.push(`${key}=${value}`);
|
|
6093
|
+
}
|
|
6094
|
+
return entries.length ? entries.join(" ") : "{...}";
|
|
6095
|
+
}
|
|
6020
6096
|
var DaemonCommandHandler = class {
|
|
6021
6097
|
_ctx;
|
|
6022
6098
|
_agentStream = null;
|
|
@@ -6164,23 +6240,54 @@ var DaemonCommandHandler = class {
|
|
|
6164
6240
|
}
|
|
6165
6241
|
return void 0;
|
|
6166
6242
|
}
|
|
6243
|
+
logCommandStart(cmd, args) {
|
|
6244
|
+
const routeBits = [
|
|
6245
|
+
this._currentRoute.session?.sessionId ? `session=${this._currentRoute.session.sessionId}` : "",
|
|
6246
|
+
this._currentRoute.managerKey ? `manager=${this._currentRoute.managerKey}` : "",
|
|
6247
|
+
this._currentRoute.providerType ? `provider=${this._currentRoute.providerType}` : ""
|
|
6248
|
+
].filter(Boolean).join(" ");
|
|
6249
|
+
const summary = summarizeCommandArgs(args);
|
|
6250
|
+
logAtLevel(
|
|
6251
|
+
getCommandLogLevel(cmd),
|
|
6252
|
+
"Command",
|
|
6253
|
+
`[${cmd}] start${routeBits ? ` ${routeBits}` : ""} args=${summary}`
|
|
6254
|
+
);
|
|
6255
|
+
}
|
|
6256
|
+
logCommandEnd(cmd, result, startedAt) {
|
|
6257
|
+
const durationMs = Date.now() - startedAt;
|
|
6258
|
+
const parts = [`[${cmd}] end`, `success=${result.success}`, `duration=${durationMs}ms`];
|
|
6259
|
+
if (typeof result.error === "string" && result.error) {
|
|
6260
|
+
parts.push(`error=${JSON.stringify(result.error)}`);
|
|
6261
|
+
}
|
|
6262
|
+
const level = result.success ? getCommandLogLevel(cmd) : "warn";
|
|
6263
|
+
logAtLevel(level, "Command", parts.join(" "));
|
|
6264
|
+
}
|
|
6167
6265
|
setAgentStreamManager(manager) {
|
|
6168
6266
|
this._agentStream = manager;
|
|
6169
6267
|
}
|
|
6170
6268
|
// ─── Command Dispatcher ──────────────────────────
|
|
6171
6269
|
async handle(cmd, args) {
|
|
6172
6270
|
this._currentRoute = this.resolveRoute(args);
|
|
6271
|
+
const startedAt = Date.now();
|
|
6272
|
+
this.logCommandStart(cmd, args);
|
|
6273
|
+
let result;
|
|
6173
6274
|
if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
|
|
6174
6275
|
const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
|
|
6175
6276
|
if (cdpCommands.includes(cmd)) {
|
|
6176
|
-
|
|
6277
|
+
result = { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
|
|
6278
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
6279
|
+
return result;
|
|
6177
6280
|
}
|
|
6178
6281
|
}
|
|
6179
6282
|
try {
|
|
6180
|
-
|
|
6283
|
+
result = await this.dispatch(cmd, args);
|
|
6284
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
6285
|
+
return result;
|
|
6181
6286
|
} catch (e) {
|
|
6182
6287
|
LOG.error("Command", `[${cmd}] Unhandled error: ${e?.message || e}`);
|
|
6183
|
-
|
|
6288
|
+
result = { success: false, error: `Internal error: ${e?.message || "unknown"}` };
|
|
6289
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
6290
|
+
return result;
|
|
6184
6291
|
}
|
|
6185
6292
|
}
|
|
6186
6293
|
async dispatch(cmd, args) {
|
|
@@ -14519,7 +14626,7 @@ async function initDaemonComponents(config) {
|
|
|
14519
14626
|
const ideInstance = instanceManager.getInstance(instanceKey);
|
|
14520
14627
|
if (ideInstance) {
|
|
14521
14628
|
instanceManager.removeInstance(instanceKey);
|
|
14522
|
-
LOG.info("
|
|
14629
|
+
LOG.info("IDE", `Instance removed after detach: ${instanceKey}`);
|
|
14523
14630
|
}
|
|
14524
14631
|
if (ideInstance?.getInstanceId) {
|
|
14525
14632
|
agentStreamManager?.resetParentSession(ideInstance.getInstanceId());
|