@adhdev/daemon-core 0.7.4 → 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 CHANGED
@@ -965,6 +965,8 @@ declare class DaemonCommandHandler implements CommandHelpers {
965
965
  private resolveRoute;
966
966
  /** Extract CDP scope key from target session or explicit ideType */
967
967
  private extractIdeType;
968
+ private logCommandStart;
969
+ private logCommandEnd;
968
970
  setAgentStreamManager(manager: DaemonAgentStreamManager): void;
969
971
  handle(cmd: string, args: any): Promise<CommandResult$1>;
970
972
  private dispatch;
package/dist/index.d.ts CHANGED
@@ -965,6 +965,8 @@ declare class DaemonCommandHandler implements CommandHelpers {
965
965
  private resolveRoute;
966
966
  /** Extract CDP scope key from target session or explicit ideType */
967
967
  private extractIdeType;
968
+ private logCommandStart;
969
+ private logCommandEnd;
968
970
  setAgentStreamManager(manager: DaemonAgentStreamManager): void;
969
971
  handle(cmd: string, args: any): Promise<CommandResult$1>;
970
972
  private dispatch;
package/dist/index.js CHANGED
@@ -4314,7 +4314,7 @@ var DaemonCdpScanner = class {
4314
4314
  if (!manager) return;
4315
4315
  registerExtensionProviders(this.ctx.providerLoader, manager, ide);
4316
4316
  this.ctx.cdpManagers.set(ide, manager);
4317
- LOG.info("CDP", `Connected: ${ide} (port ${port})`);
4317
+ LOG.info("IDE", `Attached: ${ide} (port ${port})`);
4318
4318
  await setupIdeInstance(this.ctx, { ideType: ide, manager });
4319
4319
  this.opts.onConnected?.(ide, ide, manager);
4320
4320
  }
@@ -4347,7 +4347,7 @@ var DaemonCdpScanner = class {
4347
4347
  );
4348
4348
  if (!manager) continue;
4349
4349
  this.ctx.cdpManagers.set(managerKey, manager);
4350
- LOG.info("CDP", `Connected: ${managerKey} (port ${port}, page "${target.title}")`);
4350
+ LOG.info("IDE", `Attached window: ${managerKey} (port ${port}, page "${target.title}")`);
4351
4351
  await setupIdeInstance(this.ctx, {
4352
4352
  ideType: ide,
4353
4353
  manager,
@@ -4392,9 +4392,9 @@ var DaemonCdpInitializer = class {
4392
4392
  await this.connectIdePort(port, ide);
4393
4393
  }
4394
4394
  if (cdpManagers.size > 0) {
4395
- LOG.info("CDP", `${cdpManagers.size} IDE(s) connected: ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}`);
4395
+ LOG.info("IDE", `${cdpManagers.size} IDE window(s) attached: ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}`);
4396
4396
  } else {
4397
- LOG.warn("CDP", `No IDEs connected \u2014 tried: ${filtered.map((p) => `${p.ide}:${p.port}`).join(", ")}`);
4397
+ LOG.warn("IDE", `No IDE windows attached \u2014 tried: ${filtered.map((p) => `${p.ide}:${p.port}`).join(", ")}`);
4398
4398
  }
4399
4399
  }
4400
4400
  // ─── Per-port connection (multi-window aware) ───
@@ -4420,7 +4420,7 @@ var DaemonCdpInitializer = class {
4420
4420
  if (connected) {
4421
4421
  registerExtensionProviders(providerLoader, manager, ide);
4422
4422
  cdpManagers.set(ide, manager);
4423
- LOG.info("CDP", `Connected: ${ide} (port ${port})`);
4423
+ LOG.info("IDE", `Attached: ${ide} (port ${port})`);
4424
4424
  await this.config.onConnected?.(ide, manager, ide);
4425
4425
  }
4426
4426
  return;
@@ -4453,7 +4453,7 @@ var DaemonCdpInitializer = class {
4453
4453
  if (connected) {
4454
4454
  registerExtensionProviders(providerLoader, manager, ide);
4455
4455
  cdpManagers.set(managerKey, manager);
4456
- LOG.info("CDP", `Connected: ${managerKey} (port ${port}${targets.length > 1 ? `, page "${target.title}"` : ""})`);
4456
+ LOG.info("IDE", `Attached window: ${managerKey} (port ${port}${targets.length > 1 ? `, page "${target.title}"` : ""})`);
4457
4457
  await this.config.onConnected?.(ide, manager, managerKey);
4458
4458
  }
4459
4459
  }
@@ -4482,7 +4482,7 @@ var DaemonCdpInitializer = class {
4482
4482
  } catch {
4483
4483
  }
4484
4484
  this.config.cdpManagers.delete(key);
4485
- LOG.info("CDP", `Removed stale manager: ${key} (${reason})`);
4485
+ LOG.info("IDE", `Detached window: ${key} (${reason})`);
4486
4486
  await this.config.onDisconnected?.(ide, manager, key, reason);
4487
4487
  }
4488
4488
  }
@@ -5878,7 +5878,6 @@ function handleSetProviderSetting(h, args) {
5878
5878
  }
5879
5879
  async function handleExtensionScript(h, args, scriptName) {
5880
5880
  const { agentType, ideType } = args || {};
5881
- LOG.info("Command", `[ExtScript] ${scriptName} agentType=${agentType} ideType=${ideType} session=${h.currentSession?.sessionId || ""}`);
5882
5881
  if (!agentType) return { success: false, error: "agentType is required" };
5883
5882
  const loader = h.ctx.providerLoader;
5884
5883
  if (!loader) return { success: false, error: "ProviderLoader not initialized" };
@@ -6092,6 +6091,83 @@ function handleWorkspaceSetDefault(args) {
6092
6091
 
6093
6092
  // src/commands/handler.ts
6094
6093
  init_workspaces();
6094
+ var COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
6095
+ "pty_input",
6096
+ "pty_resize",
6097
+ "cdp_eval",
6098
+ "cdp_batch",
6099
+ "cdp_dom_query",
6100
+ "cdp_dom_dump",
6101
+ "cdp_dom_debug"
6102
+ ]);
6103
+ function logAtLevel(level, category, message) {
6104
+ switch (level) {
6105
+ case "debug":
6106
+ LOG.debug(category, message);
6107
+ return;
6108
+ case "warn":
6109
+ LOG.warn(category, message);
6110
+ return;
6111
+ case "error":
6112
+ LOG.error(category, message);
6113
+ return;
6114
+ default:
6115
+ LOG.info(category, message);
6116
+ }
6117
+ }
6118
+ function getCommandLogLevel(cmd) {
6119
+ return COMMAND_DEBUG_LEVELS.has(cmd) ? "debug" : "info";
6120
+ }
6121
+ function summarizeLogValue(value) {
6122
+ if (value === null) return "null";
6123
+ if (value === void 0) return "undefined";
6124
+ if (typeof value === "string") {
6125
+ const normalized = value.replace(/\s+/g, " ").trim();
6126
+ if (!normalized) return '""';
6127
+ if (normalized.length <= 80) return JSON.stringify(normalized);
6128
+ return `${JSON.stringify(normalized.slice(0, 80))}\u2026(${normalized.length} chars)`;
6129
+ }
6130
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
6131
+ if (Array.isArray(value)) return `[${value.length} items]`;
6132
+ if (typeof value === "object") return "{...}";
6133
+ return String(value);
6134
+ }
6135
+ function summarizeCommandArgs(args) {
6136
+ if (!args || typeof args !== "object") return "-";
6137
+ const preferredKeys = [
6138
+ "targetSessionId",
6139
+ "providerType",
6140
+ "agentType",
6141
+ "ideType",
6142
+ "model",
6143
+ "mode",
6144
+ "action",
6145
+ "button",
6146
+ "key",
6147
+ "force",
6148
+ "offset",
6149
+ "limit",
6150
+ "cols",
6151
+ "rows",
6152
+ "path",
6153
+ "command",
6154
+ "commandId",
6155
+ "workspace",
6156
+ "dir",
6157
+ "url",
6158
+ "text",
6159
+ "message",
6160
+ "data",
6161
+ "value"
6162
+ ];
6163
+ const entries = [];
6164
+ for (const key of preferredKeys) {
6165
+ if (!(key in args) || args[key] === void 0) continue;
6166
+ const value = key === "text" || key === "message" ? `${String(args[key] || "").length} chars` : key === "data" ? `${String(args[key] || "").length} chars` : summarizeLogValue(args[key]);
6167
+ entries.push(`${key}=${value}`);
6168
+ }
6169
+ return entries.length ? entries.join(" ") : "{...}";
6170
+ }
6095
6171
  var DaemonCommandHandler = class {
6096
6172
  _ctx;
6097
6173
  _agentStream = null;
@@ -6239,23 +6315,54 @@ var DaemonCommandHandler = class {
6239
6315
  }
6240
6316
  return void 0;
6241
6317
  }
6318
+ logCommandStart(cmd, args) {
6319
+ const routeBits = [
6320
+ this._currentRoute.session?.sessionId ? `session=${this._currentRoute.session.sessionId}` : "",
6321
+ this._currentRoute.managerKey ? `manager=${this._currentRoute.managerKey}` : "",
6322
+ this._currentRoute.providerType ? `provider=${this._currentRoute.providerType}` : ""
6323
+ ].filter(Boolean).join(" ");
6324
+ const summary = summarizeCommandArgs(args);
6325
+ logAtLevel(
6326
+ getCommandLogLevel(cmd),
6327
+ "Command",
6328
+ `[${cmd}] start${routeBits ? ` ${routeBits}` : ""} args=${summary}`
6329
+ );
6330
+ }
6331
+ logCommandEnd(cmd, result, startedAt) {
6332
+ const durationMs = Date.now() - startedAt;
6333
+ const parts = [`[${cmd}] end`, `success=${result.success}`, `duration=${durationMs}ms`];
6334
+ if (typeof result.error === "string" && result.error) {
6335
+ parts.push(`error=${JSON.stringify(result.error)}`);
6336
+ }
6337
+ const level = result.success ? getCommandLogLevel(cmd) : "warn";
6338
+ logAtLevel(level, "Command", parts.join(" "));
6339
+ }
6242
6340
  setAgentStreamManager(manager) {
6243
6341
  this._agentStream = manager;
6244
6342
  }
6245
6343
  // ─── Command Dispatcher ──────────────────────────
6246
6344
  async handle(cmd, args) {
6247
6345
  this._currentRoute = this.resolveRoute(args);
6346
+ const startedAt = Date.now();
6347
+ this.logCommandStart(cmd, args);
6348
+ let result;
6248
6349
  if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
6249
6350
  const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
6250
6351
  if (cdpCommands.includes(cmd)) {
6251
- return { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
6352
+ result = { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
6353
+ this.logCommandEnd(cmd, result, startedAt);
6354
+ return result;
6252
6355
  }
6253
6356
  }
6254
6357
  try {
6255
- return await this.dispatch(cmd, args);
6358
+ result = await this.dispatch(cmd, args);
6359
+ this.logCommandEnd(cmd, result, startedAt);
6360
+ return result;
6256
6361
  } catch (e) {
6257
6362
  LOG.error("Command", `[${cmd}] Unhandled error: ${e?.message || e}`);
6258
- return { success: false, error: `Internal error: ${e?.message || "unknown"}` };
6363
+ result = { success: false, error: `Internal error: ${e?.message || "unknown"}` };
6364
+ this.logCommandEnd(cmd, result, startedAt);
6365
+ return result;
6259
6366
  }
6260
6367
  }
6261
6368
  async dispatch(cmd, args) {
@@ -14589,7 +14696,7 @@ async function initDaemonComponents(config) {
14589
14696
  const ideInstance = instanceManager.getInstance(instanceKey);
14590
14697
  if (ideInstance) {
14591
14698
  instanceManager.removeInstance(instanceKey);
14592
- LOG.info("CDP", `Instance removed after disconnect: ${instanceKey}`);
14699
+ LOG.info("IDE", `Instance removed after detach: ${instanceKey}`);
14593
14700
  }
14594
14701
  if (ideInstance?.getInstanceId) {
14595
14702
  agentStreamManager?.resetParentSession(ideInstance.getInstanceId());