@adhdev/daemon-core 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.mjs CHANGED
@@ -6724,6 +6724,51 @@ function buildSessionEntries(allStates, cdpManagers) {
6724
6724
  return sessions;
6725
6725
  }
6726
6726
 
6727
+ // src/sessions/reconcile.ts
6728
+ function upsertSessionTarget(sessionRegistry, target) {
6729
+ const existing = sessionRegistry.get(target.sessionId);
6730
+ if (existing && existing.parentSessionId === target.parentSessionId && existing.providerType === target.providerType && existing.transport === target.transport && existing.cdpManagerKey === target.cdpManagerKey && existing.instanceKey === target.instanceKey) {
6731
+ return;
6732
+ }
6733
+ sessionRegistry.register(target);
6734
+ }
6735
+ function reconcileIdeRuntimeSessions(instanceManager, sessionRegistry) {
6736
+ if (!instanceManager || !sessionRegistry) return;
6737
+ for (const instanceKey of instanceManager.listInstanceIds()) {
6738
+ if (!instanceKey.startsWith("ide:")) continue;
6739
+ const ideInstance = instanceManager.getInstance(instanceKey);
6740
+ if (!ideInstance || ideInstance.category !== "ide" || typeof ideInstance.getInstanceId !== "function") {
6741
+ continue;
6742
+ }
6743
+ const managerKey = instanceKey.slice(4);
6744
+ const ideType = typeof ideInstance.type === "string" && ideInstance.type.trim() ? ideInstance.type.trim() : managerKey.split("_")[0];
6745
+ const parentSessionId = ideInstance.getInstanceId();
6746
+ if (!parentSessionId) continue;
6747
+ upsertSessionTarget(sessionRegistry, {
6748
+ sessionId: parentSessionId,
6749
+ parentSessionId: null,
6750
+ providerType: ideType,
6751
+ transport: "cdp-page",
6752
+ cdpManagerKey: managerKey,
6753
+ instanceKey
6754
+ });
6755
+ const extensions = ideInstance.getExtensionInstances?.() || [];
6756
+ for (const ext of extensions) {
6757
+ const extType = typeof ext?.type === "string" ? ext.type.trim() : "";
6758
+ const extSessionId = ext?.getInstanceId?.();
6759
+ if (!extType || !extSessionId) continue;
6760
+ upsertSessionTarget(sessionRegistry, {
6761
+ sessionId: extSessionId,
6762
+ parentSessionId,
6763
+ providerType: extType,
6764
+ transport: "cdp-webview",
6765
+ cdpManagerKey: managerKey,
6766
+ instanceKey
6767
+ });
6768
+ }
6769
+ }
6770
+ }
6771
+
6727
6772
  // src/commands/handler.ts
6728
6773
  init_logger();
6729
6774
 
@@ -8481,17 +8526,27 @@ var DaemonCommandHandler = class {
8481
8526
  return key.split("_")[0];
8482
8527
  }
8483
8528
  resolveRoute(args) {
8484
- const session = this._ctx.sessionRegistry?.get(args?.targetSessionId);
8485
- const managerKey = this.extractIdeType(args);
8486
- const providerType = args?.agentType || args?.providerType || session?.providerType || this.inferProviderType(managerKey);
8487
- return { session, managerKey, providerType };
8529
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
8530
+ let session = targetSessionId ? this._ctx.sessionRegistry?.get(targetSessionId) : void 0;
8531
+ if (targetSessionId && !session) {
8532
+ reconcileIdeRuntimeSessions(this._ctx.instanceManager, this._ctx.sessionRegistry);
8533
+ session = this._ctx.sessionRegistry?.get(targetSessionId);
8534
+ }
8535
+ const sessionLookupFailed = !!targetSessionId && !session;
8536
+ const managerKey = this.extractIdeType(args, sessionLookupFailed);
8537
+ let providerType;
8538
+ if (!sessionLookupFailed) {
8539
+ providerType = session?.providerType || args?.agentType || args?.providerType || this.inferProviderType(managerKey);
8540
+ }
8541
+ return { session, managerKey, providerType, sessionLookupFailed };
8488
8542
  }
8489
8543
  /** Extract CDP scope key from target session or explicit ideType */
8490
- extractIdeType(args) {
8544
+ extractIdeType(args, sessionLookupFailed = false) {
8491
8545
  if (args?.targetSessionId) {
8492
8546
  const target = this._ctx.sessionRegistry?.get(args.targetSessionId);
8493
8547
  if (target?.cdpManagerKey) return target.cdpManagerKey;
8494
8548
  if (this._ctx.cdpManagers.has(args.targetSessionId)) return args.targetSessionId;
8549
+ if (sessionLookupFailed) return void 0;
8495
8550
  }
8496
8551
  if (args?.ideType) {
8497
8552
  const target = this._ctx.sessionRegistry?.get(args.ideType);
@@ -8538,6 +8593,33 @@ var DaemonCommandHandler = class {
8538
8593
  this._currentRoute = this.resolveRoute(args);
8539
8594
  const startedAt = Date.now();
8540
8595
  this.logCommandStart(cmd, args);
8596
+ const sessionScopedCommands = /* @__PURE__ */ new Set([
8597
+ "read_chat",
8598
+ "send_chat",
8599
+ "list_chats",
8600
+ "new_chat",
8601
+ "switch_chat",
8602
+ "set_mode",
8603
+ "change_model",
8604
+ "set_thought_level",
8605
+ "resolve_action",
8606
+ "focus_session",
8607
+ "pty_input",
8608
+ "pty_resize",
8609
+ "invoke_provider_script",
8610
+ "list_extension_models",
8611
+ "set_extension_model",
8612
+ "list_extension_modes",
8613
+ "set_extension_mode"
8614
+ ]);
8615
+ if (this._currentRoute.sessionLookupFailed && sessionScopedCommands.has(cmd)) {
8616
+ const result2 = {
8617
+ success: false,
8618
+ error: `Live session not found for targetSessionId: ${String(args?.targetSessionId || "").trim() || "unknown"}`
8619
+ };
8620
+ this.logCommandEnd(cmd, result2, startedAt);
8621
+ return result2;
8622
+ }
8541
8623
  let result;
8542
8624
  if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
8543
8625
  const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
@@ -13925,6 +14007,7 @@ var AgentStreamPoller = class {
13925
14007
  sessionRegistry
13926
14008
  } = this.deps;
13927
14009
  if (!agentStreamManager || cdpManagers.size === 0) return;
14010
+ reconcileIdeRuntimeSessions(instanceManager, sessionRegistry);
13928
14011
  for (const [ideType, cdp] of cdpManagers) {
13929
14012
  registerExtensionProviders(providerLoader, cdp, ideType);
13930
14013
  const ideInstance = instanceManager.getInstance(`ide:${ideType}`);