adhdev 0.7.1 → 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.js CHANGED
@@ -3096,9 +3096,9 @@ var init_initializer = __esm({
3096
3096
  await this.connectIdePort(port, ide);
3097
3097
  }
3098
3098
  if (cdpManagers.size > 0) {
3099
- LOG.info("CDP", `${cdpManagers.size} IDE(s) connected: ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}`);
3099
+ LOG.info("IDE", `${cdpManagers.size} IDE window(s) attached: ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}`);
3100
3100
  } else {
3101
- LOG.warn("CDP", `No IDEs connected \u2014 tried: ${filtered.map((p) => `${p.ide}:${p.port}`).join(", ")}`);
3101
+ LOG.warn("IDE", `No IDE windows attached \u2014 tried: ${filtered.map((p) => `${p.ide}:${p.port}`).join(", ")}`);
3102
3102
  }
3103
3103
  }
3104
3104
  // ─── Per-port connection (multi-window aware) ───
@@ -3124,7 +3124,7 @@ var init_initializer = __esm({
3124
3124
  if (connected) {
3125
3125
  registerExtensionProviders(providerLoader, manager, ide);
3126
3126
  cdpManagers.set(ide, manager);
3127
- LOG.info("CDP", `Connected: ${ide} (port ${port})`);
3127
+ LOG.info("IDE", `Attached: ${ide} (port ${port})`);
3128
3128
  await this.config.onConnected?.(ide, manager, ide);
3129
3129
  }
3130
3130
  return;
@@ -3157,7 +3157,7 @@ var init_initializer = __esm({
3157
3157
  if (connected) {
3158
3158
  registerExtensionProviders(providerLoader, manager, ide);
3159
3159
  cdpManagers.set(managerKey, manager);
3160
- LOG.info("CDP", `Connected: ${managerKey} (port ${port}${targets.length > 1 ? `, page "${target.title}"` : ""})`);
3160
+ LOG.info("IDE", `Attached window: ${managerKey} (port ${port}${targets.length > 1 ? `, page "${target.title}"` : ""})`);
3161
3161
  await this.config.onConnected?.(ide, manager, managerKey);
3162
3162
  }
3163
3163
  }
@@ -3186,7 +3186,7 @@ var init_initializer = __esm({
3186
3186
  } catch {
3187
3187
  }
3188
3188
  this.config.cdpManagers.delete(key);
3189
- LOG.info("CDP", `Removed stale manager: ${key} (${reason})`);
3189
+ LOG.info("IDE", `Detached window: ${key} (${reason})`);
3190
3190
  await this.config.onDisconnected?.(ide, manager, key, reason);
3191
3191
  }
3192
3192
  }
@@ -4590,7 +4590,6 @@ function handleSetProviderSetting(h, args) {
4590
4590
  }
4591
4591
  async function handleExtensionScript(h, args, scriptName) {
4592
4592
  const { agentType, ideType } = args || {};
4593
- LOG.info("Command", `[ExtScript] ${scriptName} agentType=${agentType} ideType=${ideType} session=${h.currentSession?.sessionId || ""}`);
4594
4593
  if (!agentType) return { success: false, error: "agentType is required" };
4595
4594
  const loader = h.ctx.providerLoader;
4596
4595
  if (!loader) return { success: false, error: "ProviderLoader not initialized" };
@@ -4816,7 +4815,75 @@ var init_workspace_commands = __esm({
4816
4815
  });
4817
4816
 
4818
4817
  // ../../oss/packages/daemon-core/src/commands/handler.ts
4819
- var DaemonCommandHandler;
4818
+ function logAtLevel(level, category, message) {
4819
+ switch (level) {
4820
+ case "debug":
4821
+ LOG.debug(category, message);
4822
+ return;
4823
+ case "warn":
4824
+ LOG.warn(category, message);
4825
+ return;
4826
+ case "error":
4827
+ LOG.error(category, message);
4828
+ return;
4829
+ default:
4830
+ LOG.info(category, message);
4831
+ }
4832
+ }
4833
+ function getCommandLogLevel(cmd) {
4834
+ return COMMAND_DEBUG_LEVELS.has(cmd) ? "debug" : "info";
4835
+ }
4836
+ function summarizeLogValue(value) {
4837
+ if (value === null) return "null";
4838
+ if (value === void 0) return "undefined";
4839
+ if (typeof value === "string") {
4840
+ const normalized = value.replace(/\s+/g, " ").trim();
4841
+ if (!normalized) return '""';
4842
+ if (normalized.length <= 80) return JSON.stringify(normalized);
4843
+ return `${JSON.stringify(normalized.slice(0, 80))}\u2026(${normalized.length} chars)`;
4844
+ }
4845
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
4846
+ if (Array.isArray(value)) return `[${value.length} items]`;
4847
+ if (typeof value === "object") return "{...}";
4848
+ return String(value);
4849
+ }
4850
+ function summarizeCommandArgs(args) {
4851
+ if (!args || typeof args !== "object") return "-";
4852
+ const preferredKeys = [
4853
+ "targetSessionId",
4854
+ "providerType",
4855
+ "agentType",
4856
+ "ideType",
4857
+ "model",
4858
+ "mode",
4859
+ "action",
4860
+ "button",
4861
+ "key",
4862
+ "force",
4863
+ "offset",
4864
+ "limit",
4865
+ "cols",
4866
+ "rows",
4867
+ "path",
4868
+ "command",
4869
+ "commandId",
4870
+ "workspace",
4871
+ "dir",
4872
+ "url",
4873
+ "text",
4874
+ "message",
4875
+ "data",
4876
+ "value"
4877
+ ];
4878
+ const entries = [];
4879
+ for (const key of preferredKeys) {
4880
+ if (!(key in args) || args[key] === void 0) continue;
4881
+ const value = key === "text" || key === "message" ? `${String(args[key] || "").length} chars` : key === "data" ? `${String(args[key] || "").length} chars` : summarizeLogValue(args[key]);
4882
+ entries.push(`${key}=${value}`);
4883
+ }
4884
+ return entries.length ? entries.join(" ") : "{...}";
4885
+ }
4886
+ var COMMAND_DEBUG_LEVELS, DaemonCommandHandler;
4820
4887
  var init_handler = __esm({
4821
4888
  "../../oss/packages/daemon-core/src/commands/handler.ts"() {
4822
4889
  "use strict";
@@ -4831,6 +4898,15 @@ var init_handler = __esm({
4831
4898
  init_workspace_commands();
4832
4899
  init_workspaces();
4833
4900
  init_workspace_activity();
4901
+ COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
4902
+ "pty_input",
4903
+ "pty_resize",
4904
+ "cdp_eval",
4905
+ "cdp_batch",
4906
+ "cdp_dom_query",
4907
+ "cdp_dom_dump",
4908
+ "cdp_dom_debug"
4909
+ ]);
4834
4910
  DaemonCommandHandler = class {
4835
4911
  _ctx;
4836
4912
  _agentStream = null;
@@ -4978,23 +5054,54 @@ var init_handler = __esm({
4978
5054
  }
4979
5055
  return void 0;
4980
5056
  }
5057
+ logCommandStart(cmd, args) {
5058
+ const routeBits = [
5059
+ this._currentRoute.session?.sessionId ? `session=${this._currentRoute.session.sessionId}` : "",
5060
+ this._currentRoute.managerKey ? `manager=${this._currentRoute.managerKey}` : "",
5061
+ this._currentRoute.providerType ? `provider=${this._currentRoute.providerType}` : ""
5062
+ ].filter(Boolean).join(" ");
5063
+ const summary = summarizeCommandArgs(args);
5064
+ logAtLevel(
5065
+ getCommandLogLevel(cmd),
5066
+ "Command",
5067
+ `[${cmd}] start${routeBits ? ` ${routeBits}` : ""} args=${summary}`
5068
+ );
5069
+ }
5070
+ logCommandEnd(cmd, result, startedAt) {
5071
+ const durationMs = Date.now() - startedAt;
5072
+ const parts = [`[${cmd}] end`, `success=${result.success}`, `duration=${durationMs}ms`];
5073
+ if (typeof result.error === "string" && result.error) {
5074
+ parts.push(`error=${JSON.stringify(result.error)}`);
5075
+ }
5076
+ const level = result.success ? getCommandLogLevel(cmd) : "warn";
5077
+ logAtLevel(level, "Command", parts.join(" "));
5078
+ }
4981
5079
  setAgentStreamManager(manager) {
4982
5080
  this._agentStream = manager;
4983
5081
  }
4984
5082
  // ─── Command Dispatcher ──────────────────────────
4985
5083
  async handle(cmd, args) {
4986
5084
  this._currentRoute = this.resolveRoute(args);
5085
+ const startedAt = Date.now();
5086
+ this.logCommandStart(cmd, args);
5087
+ let result;
4987
5088
  if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
4988
5089
  const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
4989
5090
  if (cdpCommands.includes(cmd)) {
4990
- return { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
5091
+ result = { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
5092
+ this.logCommandEnd(cmd, result, startedAt);
5093
+ return result;
4991
5094
  }
4992
5095
  }
4993
5096
  try {
4994
- return await this.dispatch(cmd, args);
5097
+ result = await this.dispatch(cmd, args);
5098
+ this.logCommandEnd(cmd, result, startedAt);
5099
+ return result;
4995
5100
  } catch (e) {
4996
5101
  LOG.error("Command", `[${cmd}] Unhandled error: ${e?.message || e}`);
4997
- return { success: false, error: `Internal error: ${e?.message || "unknown"}` };
5102
+ result = { success: false, error: `Internal error: ${e?.message || "unknown"}` };
5103
+ this.logCommandEnd(cmd, result, startedAt);
5104
+ return result;
4998
5105
  }
4999
5106
  }
5000
5107
  async dispatch(cmd, args) {
@@ -41562,7 +41669,7 @@ async function initDaemonComponents(config2) {
41562
41669
  const ideInstance = instanceManager.getInstance(instanceKey);
41563
41670
  if (ideInstance) {
41564
41671
  instanceManager.removeInstance(instanceKey);
41565
- LOG.info("CDP", `Instance removed after disconnect: ${instanceKey}`);
41672
+ LOG.info("IDE", `Instance removed after detach: ${instanceKey}`);
41566
41673
  }
41567
41674
  if (ideInstance?.getInstanceId) {
41568
41675
  agentStreamManager?.resetParentSession(ideInstance.getInstanceId());
@@ -42398,7 +42505,7 @@ ${e?.stack || ""}`);
42398
42505
  this.notifyStateChange();
42399
42506
  }
42400
42507
  }
42401
- /** Process files channel message */
42508
+ /** Process unified data channel message */
42402
42509
  handleCommandMessage(peerId, msg) {
42403
42510
  const text = typeof msg === "string" ? msg : msg.toString("utf-8");
42404
42511
  try {
@@ -42466,12 +42573,6 @@ ${e?.stack || ""}`);
42466
42573
  }
42467
42574
  return;
42468
42575
  }
42469
- if (parsed.type === "chat_history") {
42470
- const { agent, offset, limit, id, instanceId } = parsed;
42471
- const result = readChatHistory(agent || "", offset || 0, limit || 30, instanceId);
42472
- this.sendToPeer(peerId, { type: "chat_history_result", id, ...result, agent });
42473
- return;
42474
- }
42475
42576
  this.handleFileRequest(peerId, parsed);
42476
42577
  } catch (e) {
42477
42578
  log(`Parse error from peer ${peerId}: ${e?.message}`);
@@ -43033,7 +43134,7 @@ var init_adhdev_daemon = __esm({
43033
43134
  fs12 = __toESM(require("fs"));
43034
43135
  path14 = __toESM(require("path"));
43035
43136
  import_chalk2 = __toESM(require("chalk"));
43036
- pkgVersion = "0.7.1";
43137
+ pkgVersion = "0.7.5";
43037
43138
  if (pkgVersion === "unknown") {
43038
43139
  try {
43039
43140
  const possiblePaths = [
@@ -43427,13 +43528,16 @@ ${err?.stack || ""}`);
43427
43528
  // ─── CDP helpers ─────────────────────────────
43428
43529
  /** Return CDP manager for specific IDE.
43429
43530
  * Lookup order:
43430
- * 1. Exact match on cdpManagers (full manager key)
43431
- * 2. Prefix match on cdpManagers (ideType_workspace)
43531
+ * 1. If passed a runtime session UUID, resolve via sessionRegistry → cdpManagerKey
43532
+ * 2. Exact match on cdpManagers (full manager key)
43533
+ * 3. Prefix match on cdpManagers (ideType_workspace)
43432
43534
  */
43433
43535
  getCdpFor(ideType) {
43434
43536
  if (!this.components) return null;
43435
43537
  const key = ideType.toLowerCase();
43436
- return findCdpManager(this.components.cdpManagers, key);
43538
+ const sessionTarget = this.components.sessionRegistry.get(key);
43539
+ const resolvedKey = sessionTarget?.cdpManagerKey || key;
43540
+ return findCdpManager(this.components.cdpManagers, resolvedKey);
43437
43541
  }
43438
43542
  };
43439
43543
  }