@adhdev/daemon-standalone 0.8.23 → 0.8.25

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
@@ -34564,6 +34564,49 @@ ${effect.notification.body || ""}`.trim();
34564
34564
  }
34565
34565
  return sessions;
34566
34566
  }
34567
+ function upsertSessionTarget(sessionRegistry, target) {
34568
+ const existing = sessionRegistry.get(target.sessionId);
34569
+ if (existing && existing.parentSessionId === target.parentSessionId && existing.providerType === target.providerType && existing.transport === target.transport && existing.cdpManagerKey === target.cdpManagerKey && existing.instanceKey === target.instanceKey) {
34570
+ return;
34571
+ }
34572
+ sessionRegistry.register(target);
34573
+ }
34574
+ function reconcileIdeRuntimeSessions(instanceManager, sessionRegistry) {
34575
+ if (!instanceManager || !sessionRegistry) return;
34576
+ for (const instanceKey of instanceManager.listInstanceIds()) {
34577
+ if (!instanceKey.startsWith("ide:")) continue;
34578
+ const ideInstance = instanceManager.getInstance(instanceKey);
34579
+ if (!ideInstance || ideInstance.category !== "ide" || typeof ideInstance.getInstanceId !== "function") {
34580
+ continue;
34581
+ }
34582
+ const managerKey = instanceKey.slice(4);
34583
+ const ideType = typeof ideInstance.type === "string" && ideInstance.type.trim() ? ideInstance.type.trim() : managerKey.split("_")[0];
34584
+ const parentSessionId = ideInstance.getInstanceId();
34585
+ if (!parentSessionId) continue;
34586
+ upsertSessionTarget(sessionRegistry, {
34587
+ sessionId: parentSessionId,
34588
+ parentSessionId: null,
34589
+ providerType: ideType,
34590
+ transport: "cdp-page",
34591
+ cdpManagerKey: managerKey,
34592
+ instanceKey
34593
+ });
34594
+ const extensions = ideInstance.getExtensionInstances?.() || [];
34595
+ for (const ext of extensions) {
34596
+ const extType = typeof ext?.type === "string" ? ext.type.trim() : "";
34597
+ const extSessionId = ext?.getInstanceId?.();
34598
+ if (!extType || !extSessionId) continue;
34599
+ upsertSessionTarget(sessionRegistry, {
34600
+ sessionId: extSessionId,
34601
+ parentSessionId,
34602
+ providerType: extType,
34603
+ transport: "cdp-webview",
34604
+ cdpManagerKey: managerKey,
34605
+ instanceKey
34606
+ });
34607
+ }
34608
+ }
34609
+ }
34567
34610
  init_logger();
34568
34611
  init_logger();
34569
34612
  var RECENT_SEND_WINDOW_MS = 1200;
@@ -36310,17 +36353,27 @@ ${effect.notification.body || ""}`.trim();
36310
36353
  return key.split("_")[0];
36311
36354
  }
36312
36355
  resolveRoute(args) {
36313
- const session = this._ctx.sessionRegistry?.get(args?.targetSessionId);
36314
- const managerKey = this.extractIdeType(args);
36315
- const providerType = args?.agentType || args?.providerType || session?.providerType || this.inferProviderType(managerKey);
36316
- return { session, managerKey, providerType };
36356
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
36357
+ let session = targetSessionId ? this._ctx.sessionRegistry?.get(targetSessionId) : void 0;
36358
+ if (targetSessionId && !session) {
36359
+ reconcileIdeRuntimeSessions(this._ctx.instanceManager, this._ctx.sessionRegistry);
36360
+ session = this._ctx.sessionRegistry?.get(targetSessionId);
36361
+ }
36362
+ const sessionLookupFailed = !!targetSessionId && !session;
36363
+ const managerKey = this.extractIdeType(args, sessionLookupFailed);
36364
+ let providerType;
36365
+ if (!sessionLookupFailed) {
36366
+ providerType = session?.providerType || args?.agentType || args?.providerType || this.inferProviderType(managerKey);
36367
+ }
36368
+ return { session, managerKey, providerType, sessionLookupFailed };
36317
36369
  }
36318
36370
  /** Extract CDP scope key from target session or explicit ideType */
36319
- extractIdeType(args) {
36371
+ extractIdeType(args, sessionLookupFailed = false) {
36320
36372
  if (args?.targetSessionId) {
36321
36373
  const target = this._ctx.sessionRegistry?.get(args.targetSessionId);
36322
36374
  if (target?.cdpManagerKey) return target.cdpManagerKey;
36323
36375
  if (this._ctx.cdpManagers.has(args.targetSessionId)) return args.targetSessionId;
36376
+ if (sessionLookupFailed) return void 0;
36324
36377
  }
36325
36378
  if (args?.ideType) {
36326
36379
  const target = this._ctx.sessionRegistry?.get(args.ideType);
@@ -36367,6 +36420,33 @@ ${effect.notification.body || ""}`.trim();
36367
36420
  this._currentRoute = this.resolveRoute(args);
36368
36421
  const startedAt = Date.now();
36369
36422
  this.logCommandStart(cmd, args);
36423
+ const sessionScopedCommands = /* @__PURE__ */ new Set([
36424
+ "read_chat",
36425
+ "send_chat",
36426
+ "list_chats",
36427
+ "new_chat",
36428
+ "switch_chat",
36429
+ "set_mode",
36430
+ "change_model",
36431
+ "set_thought_level",
36432
+ "resolve_action",
36433
+ "focus_session",
36434
+ "pty_input",
36435
+ "pty_resize",
36436
+ "invoke_provider_script",
36437
+ "list_extension_models",
36438
+ "set_extension_model",
36439
+ "list_extension_modes",
36440
+ "set_extension_mode"
36441
+ ]);
36442
+ if (this._currentRoute.sessionLookupFailed && sessionScopedCommands.has(cmd)) {
36443
+ const result2 = {
36444
+ success: false,
36445
+ error: `Live session not found for targetSessionId: ${String(args?.targetSessionId || "").trim() || "unknown"}`
36446
+ };
36447
+ this.logCommandEnd(cmd, result2, startedAt);
36448
+ return result2;
36449
+ }
36370
36450
  let result;
36371
36451
  if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
36372
36452
  const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
@@ -41707,6 +41787,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
41707
41787
  sessionRegistry
41708
41788
  } = this.deps;
41709
41789
  if (!agentStreamManager || cdpManagers.size === 0) return;
41790
+ reconcileIdeRuntimeSessions(instanceManager, sessionRegistry);
41710
41791
  for (const [ideType, cdp] of cdpManagers) {
41711
41792
  registerExtensionProviders(providerLoader, cdp, ideType);
41712
41793
  const ideInstance = instanceManager.getInstance(`ide:${ideType}`);