@adhdev/daemon-core 0.5.21 → 0.5.24

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.ts CHANGED
@@ -1331,6 +1331,14 @@ declare class DaemonCdpManager {
1331
1331
  discoverAgentWebviews(): Promise<AgentWebviewTarget[]>;
1332
1332
  attachToAgent(target: AgentWebviewTarget): Promise<string | null>;
1333
1333
  evaluateInSession(sessionId: string, expression: string, timeoutMs?: number): Promise<unknown>;
1334
+ /**
1335
+ * Evaluate inside the child frame of an attached session.
1336
+ * Extension webviews have a nested iframe structure:
1337
+ * outer (vscode-webview://) → inner (extension React app)
1338
+ * This method navigates into the inner frame using CDP Page.getFrameTree.
1339
+ * Falls back to evaluateInSession if no child frame is found.
1340
+ */
1341
+ evaluateInSessionFrame(sessionId: string, expression: string, timeoutMs?: number): Promise<unknown>;
1334
1342
  detachAgent(sessionId: string): Promise<void>;
1335
1343
  detachAllAgents(): Promise<void>;
1336
1344
  getAgentSessions(): Map<string, AgentWebviewTarget>;
package/dist/index.js CHANGED
@@ -1631,6 +1631,60 @@ var DaemonCdpManager = class {
1631
1631
  }, timeoutMs);
1632
1632
  });
1633
1633
  }
1634
+ /**
1635
+ * Evaluate inside the child frame of an attached session.
1636
+ * Extension webviews have a nested iframe structure:
1637
+ * outer (vscode-webview://) → inner (extension React app)
1638
+ * This method navigates into the inner frame using CDP Page.getFrameTree.
1639
+ * Falls back to evaluateInSession if no child frame is found.
1640
+ */
1641
+ async evaluateInSessionFrame(sessionId, expression, timeoutMs = 15e3) {
1642
+ const ws = this._browserConnected ? this.browserWs : this.ws;
1643
+ if (!ws || ws.readyState !== import_ws.default.OPEN) {
1644
+ throw new Error("CDP not connected");
1645
+ }
1646
+ const sendViaSession = (method, params = {}) => {
1647
+ return new Promise((resolve7, reject) => {
1648
+ const pendingMap = this._browserConnected ? this.browserPending : this.pending;
1649
+ const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
1650
+ pendingMap.set(id, { resolve: resolve7, reject });
1651
+ ws.send(JSON.stringify({ id, sessionId, method, params }));
1652
+ setTimeout(() => {
1653
+ if (pendingMap.has(id)) {
1654
+ pendingMap.delete(id);
1655
+ reject(new Error(`CDP session timeout: ${method}`));
1656
+ }
1657
+ }, timeoutMs);
1658
+ });
1659
+ };
1660
+ try {
1661
+ const { frameTree } = await sendViaSession("Page.getFrameTree");
1662
+ const childFrame = frameTree?.childFrames?.[0]?.frame;
1663
+ if (!childFrame) {
1664
+ return this.evaluateInSession(sessionId, expression, timeoutMs);
1665
+ }
1666
+ const { executionContextId } = await sendViaSession("Page.createIsolatedWorld", {
1667
+ frameId: childFrame.id,
1668
+ worldName: "adhdev-agent-eval",
1669
+ grantUniveralAccess: true
1670
+ });
1671
+ const result = await sendViaSession("Runtime.evaluate", {
1672
+ expression,
1673
+ returnByValue: true,
1674
+ awaitPromise: true,
1675
+ contextId: executionContextId
1676
+ });
1677
+ if (result?.result?.subtype === "error") {
1678
+ throw new Error(result.result.description);
1679
+ }
1680
+ return result?.result?.value;
1681
+ } catch (e) {
1682
+ if (e.message?.includes("getFrameTree")) {
1683
+ return this.evaluateInSession(sessionId, expression, timeoutMs);
1684
+ }
1685
+ throw e;
1686
+ }
1687
+ }
1634
1688
  async detachAgent(sessionId) {
1635
1689
  try {
1636
1690
  const sendFn = this._browserConnected ? this.sendBrowser.bind(this) : this.sendInternal.bind(this);
@@ -1777,7 +1831,7 @@ var CdpDomHandlers = class {
1777
1831
  }
1778
1832
  let result;
1779
1833
  if (sessionId) {
1780
- result = await this.getCdp().evaluateInSession(sessionId, expression);
1834
+ result = await this.getCdp().evaluateInSessionFrame(sessionId, expression);
1781
1835
  } else {
1782
1836
  result = await this.getCdp().evaluate(expression, 3e4);
1783
1837
  }
@@ -1838,7 +1892,7 @@ var CdpDomHandlers = class {
1838
1892
  try {
1839
1893
  let raw;
1840
1894
  if (sessionId) {
1841
- raw = await this.getCdp().evaluateInSession(sessionId, expression);
1895
+ raw = await this.getCdp().evaluateInSessionFrame(sessionId, expression);
1842
1896
  } else {
1843
1897
  raw = await this.getCdp().evaluate(expression, 15e3);
1844
1898
  }
@@ -1973,7 +2027,7 @@ var CdpDomHandlers = class {
1973
2027
  try {
1974
2028
  let raw;
1975
2029
  if (sessionId) {
1976
- raw = await this.getCdp().evaluateInSession(sessionId, expression);
2030
+ raw = await this.getCdp().evaluateInSessionFrame(sessionId, expression);
1977
2031
  } else {
1978
2032
  raw = await this.getCdp().evaluate(expression, 3e4);
1979
2033
  }
@@ -4221,7 +4275,7 @@ async function handleExtensionScript(h, args, scriptName) {
4221
4275
  if (!targetSessionId) {
4222
4276
  return { success: false, error: `No active session found for ${agentType}` };
4223
4277
  }
4224
- result = await cdp.evaluateInSession(targetSessionId, scriptCode);
4278
+ result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
4225
4279
  } else if (hasWebviewScript && cdp.evaluateInWebviewFrame) {
4226
4280
  const matchText = provider.webviewMatchText;
4227
4281
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
@@ -4459,7 +4513,7 @@ var DaemonCommandHandler = class {
4459
4513
  sessionId = this.getExtensionSessionId(provider);
4460
4514
  }
4461
4515
  if (!sessionId) return null;
4462
- const result2 = await cdp.evaluateInSession(sessionId, script, timeout);
4516
+ const result2 = await cdp.evaluateInSessionFrame(sessionId, script, timeout);
4463
4517
  return { result: result2, category: "extension" };
4464
4518
  }
4465
4519
  const result = await cdp.evaluate(script, timeout);
@@ -4485,6 +4539,10 @@ var DaemonCommandHandler = class {
4485
4539
  /** Extract ideType from _targetInstance or explicit ideType */
4486
4540
  extractIdeType(args) {
4487
4541
  if (args?.ideType) {
4542
+ const mappedKey = this._ctx.instanceIdMap?.get(args.ideType);
4543
+ if (mappedKey) {
4544
+ return mappedKey;
4545
+ }
4488
4546
  if (this._ctx.cdpManagers.has(args.ideType)) {
4489
4547
  return args.ideType;
4490
4548
  }
@@ -8839,7 +8897,7 @@ var DaemonAgentStreamManager = class {
8839
8897
  results.push(agent.lastState);
8840
8898
  } else {
8841
8899
  try {
8842
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
8900
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8843
8901
  const state = await agent.adapter.readChat(evaluate);
8844
8902
  agent.lastState = state;
8845
8903
  agent.lastError = null;
@@ -8877,7 +8935,7 @@ var DaemonAgentStreamManager = class {
8877
8935
  const agent = this.managed.get(agentType);
8878
8936
  if (!agent) return false;
8879
8937
  try {
8880
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
8938
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8881
8939
  await agent.adapter.sendMessage(evaluate, text);
8882
8940
  return true;
8883
8941
  } catch (e) {
@@ -8890,7 +8948,7 @@ var DaemonAgentStreamManager = class {
8890
8948
  const agent = this.managed.get(agentType);
8891
8949
  if (!agent) return false;
8892
8950
  try {
8893
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
8951
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8894
8952
  return await agent.adapter.resolveAction(evaluate, action);
8895
8953
  } catch (e) {
8896
8954
  this.logFn(`[AgentStream] resolveAction(${agentType}) error: ${e.message}`);
@@ -8902,7 +8960,7 @@ var DaemonAgentStreamManager = class {
8902
8960
  const agent = this.managed.get(agentType);
8903
8961
  if (!agent) return false;
8904
8962
  try {
8905
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
8963
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8906
8964
  await agent.adapter.newSession(evaluate);
8907
8965
  return true;
8908
8966
  } catch (e) {
@@ -8920,7 +8978,7 @@ var DaemonAgentStreamManager = class {
8920
8978
  }
8921
8979
  if (!agent || typeof agent.adapter.listChats !== "function") return [];
8922
8980
  try {
8923
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
8981
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8924
8982
  return await agent.adapter.listChats(evaluate);
8925
8983
  } catch (e) {
8926
8984
  this.logFn(`[AgentStream] listChats(${agentType}) error: ${e.message}`);
@@ -8937,7 +8995,7 @@ var DaemonAgentStreamManager = class {
8937
8995
  }
8938
8996
  if (!agent || typeof agent.adapter.switchSession !== "function") return false;
8939
8997
  try {
8940
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
8998
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8941
8999
  return await agent.adapter.switchSession(evaluate, sessionId);
8942
9000
  } catch (e) {
8943
9001
  this.logFn(`[AgentStream] switchSession(${agentType}) error: ${e.message}`);
@@ -8948,7 +9006,7 @@ var DaemonAgentStreamManager = class {
8948
9006
  const agent = this.managed.get(agentType);
8949
9007
  if (!agent || typeof agent.adapter.focusEditor !== "function") return false;
8950
9008
  try {
8951
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
9009
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8952
9010
  await agent.adapter.focusEditor(evaluate);
8953
9011
  return true;
8954
9012
  } catch (e) {