@adhdev/daemon-core 0.5.38 → 0.5.40

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
@@ -4365,7 +4365,13 @@ async function handleExtensionScript(h, args, scriptName) {
4365
4365
  return { success: false, error: `Script '${actualScriptName}' not available for ${agentType}` };
4366
4366
  }
4367
4367
  const scriptFn = provider.scripts[actualScriptName];
4368
- const scriptCode = scriptFn(args);
4368
+ const normalizedArgs = { ...args };
4369
+ for (const key of ["mode", "model", "message", "action", "button", "text", "sessionId"]) {
4370
+ if (key in normalizedArgs && !(key.toUpperCase() in normalizedArgs)) {
4371
+ normalizedArgs[key.toUpperCase()] = normalizedArgs[key];
4372
+ }
4373
+ }
4374
+ const scriptCode = scriptFn(normalizedArgs);
4369
4375
  if (!scriptCode) return { success: false, error: `Script '${actualScriptName}' returned null` };
4370
4376
  const cdpKey = provider.category === "ide" ? h.currentIdeType || agentType : h.currentIdeType || ideType;
4371
4377
  LOG.info("Command", `[ExtScript] provider=${provider.type} category=${provider.category} cdpKey=${cdpKey}`);
@@ -4382,10 +4388,31 @@ async function handleExtensionScript(h, args, scriptName) {
4382
4388
  break;
4383
4389
  }
4384
4390
  }
4385
- if (!targetSessionId) {
4386
- return { success: false, error: `No active session found for ${agentType}` };
4391
+ const IDE_LEVEL_SCRIPTS = ["listModes", "setMode", "listModels", "setModel"];
4392
+ if (IDE_LEVEL_SCRIPTS.includes(scriptName)) {
4393
+ if (targetSessionId) {
4394
+ try {
4395
+ result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
4396
+ const parsed = typeof result === "string" ? JSON.parse(result) : result;
4397
+ const notFound = parsed?.error?.includes("not found") || parsed?.error?.includes("no root");
4398
+ if (notFound) {
4399
+ LOG.info("Command", `[ExtScript] ${scriptName} not found in session frame \u2192 trying IDE main page`);
4400
+ result = await cdp.evaluate(scriptCode, 3e4);
4401
+ }
4402
+ } catch {
4403
+ LOG.info("Command", `[ExtScript] ${scriptName} session frame failed \u2192 trying IDE main page`);
4404
+ result = await cdp.evaluate(scriptCode, 3e4);
4405
+ }
4406
+ } else {
4407
+ LOG.info("Command", `[ExtScript] ${scriptName} no session \u2192 trying IDE main page`);
4408
+ result = await cdp.evaluate(scriptCode, 3e4);
4409
+ }
4410
+ } else {
4411
+ if (!targetSessionId) {
4412
+ return { success: false, error: `No active session found for ${agentType}` };
4413
+ }
4414
+ result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
4387
4415
  }
4388
- result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
4389
4416
  } else if (hasWebviewScript && cdp.evaluateInWebviewFrame) {
4390
4417
  const matchText = provider.webviewMatchText;
4391
4418
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
@@ -10256,14 +10283,29 @@ var DevServer = class _DevServer {
10256
10283
  return;
10257
10284
  }
10258
10285
  this.log(`Exec script length: ${scriptCode.length}, first 50 chars: ${scriptCode.slice(0, 50)}...`);
10259
- const isWebviewScript = provider.category === "extension" || scriptName.toLowerCase().includes("webview");
10286
+ const isWebviewScript = scriptName.toLowerCase().includes("webview");
10260
10287
  let raw;
10261
- if (isWebviewScript) {
10288
+ if (provider.category === "extension" && !isWebviewScript) {
10289
+ const sessions = cdp.getAgentSessions();
10290
+ let sessionId = null;
10291
+ for (const [sid, target] of sessions) {
10292
+ if (target.agentType === type) {
10293
+ sessionId = sid;
10294
+ break;
10295
+ }
10296
+ }
10297
+ if (sessionId) {
10298
+ raw = await cdp.evaluateInSessionFrame(sessionId, scriptCode);
10299
+ } else if (cdp.evaluateInWebviewFrame) {
10300
+ const matchText = provider.webviewMatchText;
10301
+ const matchFn = matchText ? (body2) => body2.includes(matchText) : void 0;
10302
+ raw = await cdp.evaluateInWebviewFrame(scriptCode, matchFn);
10303
+ } else {
10304
+ raw = await cdp.evaluate(scriptCode, 3e4);
10305
+ }
10306
+ } else if (isWebviewScript && cdp.evaluateInWebviewFrame) {
10262
10307
  const matchText = provider.webviewMatchText;
10263
10308
  const matchFn = matchText ? (body2) => body2.includes(matchText) : void 0;
10264
- if (!cdp.evaluateInWebviewFrame) {
10265
- throw new Error(`CDP manager does not support evaluateInWebviewFrame`);
10266
- }
10267
10309
  raw = await cdp.evaluateInWebviewFrame(scriptCode, matchFn);
10268
10310
  } else {
10269
10311
  raw = await cdp.evaluate(scriptCode, 3e4);