@adhdev/daemon-core 0.8.24 → 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
@@ -6809,6 +6809,51 @@ function buildSessionEntries(allStates, cdpManagers) {
6809
6809
  return sessions;
6810
6810
  }
6811
6811
 
6812
+ // src/sessions/reconcile.ts
6813
+ function upsertSessionTarget(sessionRegistry, target) {
6814
+ const existing = sessionRegistry.get(target.sessionId);
6815
+ if (existing && existing.parentSessionId === target.parentSessionId && existing.providerType === target.providerType && existing.transport === target.transport && existing.cdpManagerKey === target.cdpManagerKey && existing.instanceKey === target.instanceKey) {
6816
+ return;
6817
+ }
6818
+ sessionRegistry.register(target);
6819
+ }
6820
+ function reconcileIdeRuntimeSessions(instanceManager, sessionRegistry) {
6821
+ if (!instanceManager || !sessionRegistry) return;
6822
+ for (const instanceKey of instanceManager.listInstanceIds()) {
6823
+ if (!instanceKey.startsWith("ide:")) continue;
6824
+ const ideInstance = instanceManager.getInstance(instanceKey);
6825
+ if (!ideInstance || ideInstance.category !== "ide" || typeof ideInstance.getInstanceId !== "function") {
6826
+ continue;
6827
+ }
6828
+ const managerKey = instanceKey.slice(4);
6829
+ const ideType = typeof ideInstance.type === "string" && ideInstance.type.trim() ? ideInstance.type.trim() : managerKey.split("_")[0];
6830
+ const parentSessionId = ideInstance.getInstanceId();
6831
+ if (!parentSessionId) continue;
6832
+ upsertSessionTarget(sessionRegistry, {
6833
+ sessionId: parentSessionId,
6834
+ parentSessionId: null,
6835
+ providerType: ideType,
6836
+ transport: "cdp-page",
6837
+ cdpManagerKey: managerKey,
6838
+ instanceKey
6839
+ });
6840
+ const extensions = ideInstance.getExtensionInstances?.() || [];
6841
+ for (const ext of extensions) {
6842
+ const extType = typeof ext?.type === "string" ? ext.type.trim() : "";
6843
+ const extSessionId = ext?.getInstanceId?.();
6844
+ if (!extType || !extSessionId) continue;
6845
+ upsertSessionTarget(sessionRegistry, {
6846
+ sessionId: extSessionId,
6847
+ parentSessionId,
6848
+ providerType: extType,
6849
+ transport: "cdp-webview",
6850
+ cdpManagerKey: managerKey,
6851
+ instanceKey
6852
+ });
6853
+ }
6854
+ }
6855
+ }
6856
+
6812
6857
  // src/commands/handler.ts
6813
6858
  init_logger();
6814
6859
 
@@ -8566,17 +8611,27 @@ var DaemonCommandHandler = class {
8566
8611
  return key.split("_")[0];
8567
8612
  }
8568
8613
  resolveRoute(args) {
8569
- const session = this._ctx.sessionRegistry?.get(args?.targetSessionId);
8570
- const managerKey = this.extractIdeType(args);
8571
- const providerType = args?.agentType || args?.providerType || session?.providerType || this.inferProviderType(managerKey);
8572
- return { session, managerKey, providerType };
8614
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
8615
+ let session = targetSessionId ? this._ctx.sessionRegistry?.get(targetSessionId) : void 0;
8616
+ if (targetSessionId && !session) {
8617
+ reconcileIdeRuntimeSessions(this._ctx.instanceManager, this._ctx.sessionRegistry);
8618
+ session = this._ctx.sessionRegistry?.get(targetSessionId);
8619
+ }
8620
+ const sessionLookupFailed = !!targetSessionId && !session;
8621
+ const managerKey = this.extractIdeType(args, sessionLookupFailed);
8622
+ let providerType;
8623
+ if (!sessionLookupFailed) {
8624
+ providerType = session?.providerType || args?.agentType || args?.providerType || this.inferProviderType(managerKey);
8625
+ }
8626
+ return { session, managerKey, providerType, sessionLookupFailed };
8573
8627
  }
8574
8628
  /** Extract CDP scope key from target session or explicit ideType */
8575
- extractIdeType(args) {
8629
+ extractIdeType(args, sessionLookupFailed = false) {
8576
8630
  if (args?.targetSessionId) {
8577
8631
  const target = this._ctx.sessionRegistry?.get(args.targetSessionId);
8578
8632
  if (target?.cdpManagerKey) return target.cdpManagerKey;
8579
8633
  if (this._ctx.cdpManagers.has(args.targetSessionId)) return args.targetSessionId;
8634
+ if (sessionLookupFailed) return void 0;
8580
8635
  }
8581
8636
  if (args?.ideType) {
8582
8637
  const target = this._ctx.sessionRegistry?.get(args.ideType);
@@ -8623,6 +8678,33 @@ var DaemonCommandHandler = class {
8623
8678
  this._currentRoute = this.resolveRoute(args);
8624
8679
  const startedAt = Date.now();
8625
8680
  this.logCommandStart(cmd, args);
8681
+ const sessionScopedCommands = /* @__PURE__ */ new Set([
8682
+ "read_chat",
8683
+ "send_chat",
8684
+ "list_chats",
8685
+ "new_chat",
8686
+ "switch_chat",
8687
+ "set_mode",
8688
+ "change_model",
8689
+ "set_thought_level",
8690
+ "resolve_action",
8691
+ "focus_session",
8692
+ "pty_input",
8693
+ "pty_resize",
8694
+ "invoke_provider_script",
8695
+ "list_extension_models",
8696
+ "set_extension_model",
8697
+ "list_extension_modes",
8698
+ "set_extension_mode"
8699
+ ]);
8700
+ if (this._currentRoute.sessionLookupFailed && sessionScopedCommands.has(cmd)) {
8701
+ const result2 = {
8702
+ success: false,
8703
+ error: `Live session not found for targetSessionId: ${String(args?.targetSessionId || "").trim() || "unknown"}`
8704
+ };
8705
+ this.logCommandEnd(cmd, result2, startedAt);
8706
+ return result2;
8707
+ }
8626
8708
  let result;
8627
8709
  if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
8628
8710
  const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
@@ -14005,6 +14087,7 @@ var AgentStreamPoller = class {
14005
14087
  sessionRegistry
14006
14088
  } = this.deps;
14007
14089
  if (!agentStreamManager || cdpManagers.size === 0) return;
14090
+ reconcileIdeRuntimeSessions(instanceManager, sessionRegistry);
14008
14091
  for (const [ideType, cdp] of cdpManagers) {
14009
14092
  registerExtensionProviders(providerLoader, cdp, ideType);
14010
14093
  const ideInstance = instanceManager.getInstance(`ide:${ideType}`);