@adhdev/daemon-core 0.5.57 → 0.5.60

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
@@ -2739,11 +2739,35 @@ var IdeProviderInstance = class {
2739
2739
  }
2740
2740
  this.autoApproveBusy = true;
2741
2741
  try {
2742
- const script = scriptFn({ action: "approve", button: "", buttonText: "" });
2742
+ let targetButton = _chatData?.activeModal?.buttons?.[0] || "Run";
2743
+ const buttons = _chatData?.activeModal?.buttons || [];
2744
+ for (const b of buttons) {
2745
+ const lower = String(b).toLowerCase().replace(/[^\w]/g, "");
2746
+ if (/^(run|approve|accept|yes|allow|always|proceed|save)/.test(lower)) {
2747
+ targetButton = b;
2748
+ break;
2749
+ }
2750
+ }
2751
+ const script = scriptFn({ action: "approve", button: targetButton, buttonText: targetButton });
2743
2752
  if (!script) return;
2744
- LOG.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove: executing resolveAction`);
2745
- const result = await cdp.evaluate(script, 1e4);
2753
+ LOG.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove: executing resolveAction for "${targetButton}"`);
2754
+ let rawResult = await cdp.evaluate(script, 1e4);
2755
+ if (typeof rawResult === "string") {
2756
+ try {
2757
+ rawResult = JSON.parse(rawResult);
2758
+ } catch {
2759
+ }
2760
+ }
2761
+ const result = rawResult;
2746
2762
  LOG.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove result: ${JSON.stringify(result)?.slice(0, 200)}`);
2763
+ if (result?.found && result.x != null && result.y != null) {
2764
+ const x = result.x;
2765
+ const y = result.y;
2766
+ const anyCdp = cdp;
2767
+ await anyCdp.send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 1 });
2768
+ await anyCdp.send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount: 1 });
2769
+ LOG.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove: dispatched mouse event at ${x},${y}`);
2770
+ }
2747
2771
  this.pushEvent({
2748
2772
  event: "agent:auto_approved",
2749
2773
  chatTitle: _chatData?.title || this.provider.name,
@@ -2755,7 +2779,7 @@ var IdeProviderInstance = class {
2755
2779
  } finally {
2756
2780
  setTimeout(() => {
2757
2781
  this.autoApproveBusy = false;
2758
- }, 500);
2782
+ }, 1e3);
2759
2783
  }
2760
2784
  }
2761
2785
  };
@@ -3347,13 +3371,23 @@ async function handleSendChat(h, args) {
3347
3371
  if (!text) return { success: false, error: "text required" };
3348
3372
  const _log = (msg) => LOG.debug("Command", `[send_chat] ${msg}`);
3349
3373
  const provider = h.getProvider();
3374
+ const _logSendSuccess = (method, targetAgent) => {
3375
+ h.historyWriter.appendNewMessages(
3376
+ targetAgent || provider?.type || h.currentIdeType || "unknown_agent",
3377
+ [{ role: "user", content: text, receivedAt: Date.now() }],
3378
+ void 0,
3379
+ // title
3380
+ args?.instanceId
3381
+ );
3382
+ return { success: true, sent: true, method, targetAgent };
3383
+ };
3350
3384
  if (provider?.category === "cli" || provider?.category === "acp") {
3351
3385
  const adapter = h.getCliAdapter(provider.type);
3352
3386
  if (adapter) {
3353
3387
  _log(`${provider.category} adapter: ${adapter.cliType}`);
3354
3388
  try {
3355
3389
  await adapter.sendMessage(text);
3356
- return { success: true, sent: true, method: `${provider.category}-adapter`, targetAgent: adapter.cliType };
3390
+ return _logSendSuccess(`${provider.category}-adapter`, adapter.cliType);
3357
3391
  } catch (e) {
3358
3392
  return { success: false, error: `${provider.category} send failed: ${e.message}` };
3359
3393
  }
@@ -3373,7 +3407,7 @@ async function handleSendChat(h, args) {
3373
3407
  }
3374
3408
  if (parsed?.sent) {
3375
3409
  _log(`Extension script sent OK`);
3376
- return { success: true, sent: true, method: "extension-script" };
3410
+ return _logSendSuccess("extension-script");
3377
3411
  }
3378
3412
  if (parsed?.needsTypeAndSend) {
3379
3413
  _log(`Extension needsTypeAndSend \u2192 AgentStreamManager`);
@@ -3386,7 +3420,7 @@ async function handleSendChat(h, args) {
3386
3420
  const ok = await h.agentStream.sendToAgent(h.getCdp(), provider.type, text, h.currentIdeType);
3387
3421
  if (ok) {
3388
3422
  _log(`AgentStreamManager sent OK`);
3389
- return { success: true, sent: true, method: "agent-stream" };
3423
+ return _logSendSuccess("agent-stream");
3390
3424
  }
3391
3425
  }
3392
3426
  return { success: false, error: `Extension '${provider.type}' send failed` };
@@ -3413,7 +3447,7 @@ async function handleSendChat(h, args) {
3413
3447
  }
3414
3448
  if (wvParsed?.sent) {
3415
3449
  _log(`webviewSendMessage (priority) OK`);
3416
- return { success: true, sent: true, method: "webview-script-priority" };
3450
+ return _logSendSuccess("webview-script-priority");
3417
3451
  }
3418
3452
  _log(`webviewSendMessage (priority) did not confirm sent, falling through`);
3419
3453
  }
@@ -3426,7 +3460,7 @@ async function handleSendChat(h, args) {
3426
3460
  const sent = await targetCdp.typeAndSend(provider.inputSelector, text);
3427
3461
  if (sent) {
3428
3462
  _log(`typeAndSend(provider.inputSelector=${provider.inputSelector}) success`);
3429
- return { success: true, sent: true, method: "typeAndSend-provider" };
3463
+ return _logSendSuccess("typeAndSend-provider");
3430
3464
  }
3431
3465
  } catch (e) {
3432
3466
  _log(`typeAndSend(provider) failed: ${e.message}`);
@@ -3445,14 +3479,14 @@ async function handleSendChat(h, args) {
3445
3479
  }
3446
3480
  if (parsed?.sent) {
3447
3481
  _log(`sendMessage script OK`);
3448
- return { success: true, sent: true, method: "script" };
3482
+ return _logSendSuccess("script");
3449
3483
  }
3450
3484
  if (parsed?.needsTypeAndSend && parsed?.selector) {
3451
3485
  try {
3452
3486
  const sent = await targetCdp.typeAndSend(parsed.selector, text);
3453
3487
  if (sent) {
3454
3488
  _log(`typeAndSend(script.selector=${parsed.selector}) success`);
3455
- return { success: true, sent: true, method: "typeAndSend-script" };
3489
+ return _logSendSuccess("typeAndSend-script");
3456
3490
  }
3457
3491
  } catch (e) {
3458
3492
  _log(`typeAndSend(script.selector) failed: ${e.message}`);
@@ -3474,7 +3508,7 @@ async function handleSendChat(h, args) {
3474
3508
  }
3475
3509
  if (wvParsed?.sent) {
3476
3510
  _log(`webviewSendMessage OK`);
3477
- return { success: true, sent: true, method: "webview-script" };
3511
+ return _logSendSuccess("webview-script");
3478
3512
  }
3479
3513
  }
3480
3514
  } catch (e) {
@@ -3487,7 +3521,7 @@ async function handleSendChat(h, args) {
3487
3521
  const sent = await targetCdp.typeAndSendAt(x, y, text);
3488
3522
  if (sent) {
3489
3523
  _log(`typeAndSendAt(${x},${y}) success`);
3490
- return { success: true, sent: true, method: "typeAndSendAt-script" };
3524
+ return _logSendSuccess("typeAndSendAt-script");
3491
3525
  }
3492
3526
  } catch (e) {
3493
3527
  _log(`typeAndSendAt failed: ${e.message}`);