@adhdev/daemon-core 0.8.28 → 0.8.30

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.
Files changed (36) hide show
  1. package/dist/agent-stream/manager.d.ts +1 -1
  2. package/dist/agent-stream/provider-adapter.d.ts +5 -0
  3. package/dist/commands/router.d.ts +5 -0
  4. package/dist/config/chat-history.d.ts +12 -0
  5. package/dist/index.js +552 -52
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +552 -52
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/providers/acp-provider-instance.d.ts +1 -0
  10. package/dist/providers/approval-utils.d.ts +7 -0
  11. package/dist/providers/cli-provider-instance.d.ts +3 -0
  12. package/dist/providers/contracts.d.ts +2 -0
  13. package/dist/providers/ide-provider-instance.d.ts +1 -0
  14. package/node_modules/@adhdev/session-host-core/dist/index.d.mts +24 -1
  15. package/node_modules/@adhdev/session-host-core/dist/index.d.ts +24 -1
  16. package/node_modules/@adhdev/session-host-core/dist/index.js +6 -1
  17. package/node_modules/@adhdev/session-host-core/dist/index.js.map +1 -1
  18. package/node_modules/@adhdev/session-host-core/dist/index.mjs +6 -1
  19. package/node_modules/@adhdev/session-host-core/dist/index.mjs.map +1 -1
  20. package/node_modules/@adhdev/session-host-core/package.json +1 -1
  21. package/package.json +1 -1
  22. package/src/agent-stream/manager.ts +2 -2
  23. package/src/agent-stream/poller.ts +38 -1
  24. package/src/agent-stream/provider-adapter.ts +97 -3
  25. package/src/cli-adapters/provider-cli-adapter.ts +3 -0
  26. package/src/commands/chat-commands.ts +53 -3
  27. package/src/commands/cli-manager.ts +14 -0
  28. package/src/commands/router.ts +11 -0
  29. package/src/config/chat-history.ts +269 -18
  30. package/src/providers/acp-provider-instance.ts +17 -2
  31. package/src/providers/approval-utils.ts +66 -0
  32. package/src/providers/cli-provider-instance.ts +47 -6
  33. package/src/providers/contracts.d.ts +1 -0
  34. package/src/providers/contracts.ts +3 -1
  35. package/src/providers/ide-provider-instance.ts +28 -23
  36. package/src/providers/provider-loader.ts +26 -2
@@ -19,6 +19,7 @@ import { ChatHistoryWriter } from '../config/chat-history.js';
19
19
  import { LOG } from '../logging/logger.js';
20
20
  import { extractProviderControlValues, normalizeProviderEffects } from './control-effects.js';
21
21
  import type { ChatMessage } from '../types.js';
22
+ import { formatAutoApprovalMessage, pickApprovalButton } from './approval-utils.js';
22
23
 
23
24
  export class IdeProviderInstance implements ProviderInstance {
24
25
  readonly type: string;
@@ -103,6 +104,11 @@ export class IdeProviderInstance implements ProviderInstance {
103
104
 
104
105
  getState(): ProviderState {
105
106
  const cdp = this.context?.cdp;
107
+ const autoApproveActive = (
108
+ this.currentStatus === 'waiting_approval'
109
+ || this.cachedChat?.status === 'waiting_approval'
110
+ ) && this.canAutoApprove();
111
+ const visibleStatus = (autoApproveActive ? 'generating' : this.currentStatus) as ProviderState['status'];
106
112
 
107
113
  // Collect extension status
108
114
  const extensionStates: ProviderState[] = [];
@@ -114,13 +120,15 @@ export class IdeProviderInstance implements ProviderInstance {
114
120
  type: this.type,
115
121
  name: this.provider.name,
116
122
  category: 'ide',
117
- status: this.currentStatus as ProviderState['status'],
123
+ status: visibleStatus,
118
124
  activeChat: this.cachedChat ? {
119
125
  id: this.cachedChat.id || 'active_session',
120
126
  title: this.cachedChat.title || this.type,
121
- status: this.cachedChat.status || this.currentStatus,
127
+ status: autoApproveActive && this.cachedChat.status === 'waiting_approval'
128
+ ? 'generating'
129
+ : (this.cachedChat.status || visibleStatus),
122
130
  messages: this.mergeConversationMessages(this.cachedChat.messages || []),
123
- activeModal: this.cachedChat.activeModal || null,
131
+ activeModal: autoApproveActive ? null : (this.cachedChat.activeModal || null),
124
132
  inputContent: this.cachedChat.inputContent || '',
125
133
  } : null,
126
134
  workspace: this.workspace || null,
@@ -370,9 +378,11 @@ export class IdeProviderInstance implements ProviderInstance {
370
378
  if (!chatStatus) return;
371
379
 
372
380
  const agentKey = `${this.type}:native`;
373
- const agentStatus = (chatStatus === 'streaming' || chatStatus === 'generating') ? 'generating'
381
+ const rawAgentStatus = (chatStatus === 'streaming' || chatStatus === 'generating') ? 'generating'
374
382
  : chatStatus === 'waiting_approval' ? 'waiting_approval'
375
383
  : 'idle';
384
+ const autoApproveActive = rawAgentStatus === 'waiting_approval' && this.canAutoApprove();
385
+ const agentStatus = autoApproveActive ? 'generating' : rawAgentStatus;
376
386
  const lastMsg = Array.isArray(chatData?.messages) && chatData.messages.length > 0
377
387
  ? chatData.messages[chatData.messages.length - 1]
378
388
  : null;
@@ -414,7 +424,7 @@ export class IdeProviderInstance implements ProviderInstance {
414
424
  });
415
425
 
416
426
  // Auto-approve: when waiting_approval + settings.autoApprove → auto-click approve via CDP
417
- if (agentStatus === 'waiting_approval' && this.settings.autoApprove && !this.autoApproveBusy) {
427
+ if (rawAgentStatus === 'waiting_approval' && autoApproveActive && !this.autoApproveBusy) {
418
428
  this.autoApproveViaScript(chatData);
419
429
  }
420
430
 
@@ -590,6 +600,12 @@ export class IdeProviderInstance implements ProviderInstance {
590
600
  if (this.context) this.context.cdp = cdp;
591
601
  }
592
602
 
603
+ private canAutoApprove(): boolean {
604
+ return this.settings.autoApprove !== false
605
+ && typeof this.provider.scripts?.resolveAction === 'function'
606
+ && !!this.context?.cdp?.isConnected;
607
+ }
608
+
593
609
  // ─── Auto-approve via CDP script ────────────────────
594
610
 
595
611
  private async autoApproveViaScript(_chatData: any): Promise<void> {
@@ -605,20 +621,16 @@ export class IdeProviderInstance implements ProviderInstance {
605
621
 
606
622
  this.autoApproveBusy = true;
607
623
  try {
608
- let targetButton = _chatData?.activeModal?.buttons?.[0] || 'Run';
609
- const buttons = _chatData?.activeModal?.buttons || [];
610
-
611
- // Prefer buttons like 'Run', 'Approve', 'Yes'
612
- for (const b of buttons) {
613
- const lower = String(b).toLowerCase().replace(/[^\w]/g, '');
614
- if (/^(run|approve|accept|yes|allow|always|proceed|save)/.test(lower)) {
615
- targetButton = b;
616
- break;
617
- }
618
- }
624
+ const { label: targetButton } = pickApprovalButton(_chatData?.activeModal?.buttons, this.provider);
619
625
 
620
626
  const script = scriptFn({ action: 'approve', button: targetButton, buttonText: targetButton });
621
627
  if (!script) return;
628
+ const now = Date.now();
629
+ this.appendRuntimeSystemMessage(
630
+ formatAutoApprovalMessage(_chatData?.activeModal?.message, targetButton),
631
+ `auto_approval:${now}:${targetButton}`,
632
+ now,
633
+ );
622
634
 
623
635
  LOG.info('IdeInstance', `[IdeInstance:${this.type}] autoApprove: executing resolveAction for "${targetButton}"`);
624
636
  let rawResult = await cdp.evaluate(script, 10000);
@@ -641,13 +653,6 @@ export class IdeProviderInstance implements ProviderInstance {
641
653
  LOG.warn('IdeInstance', `[IdeInstance:${this.type}] autoApprove: cdp.send() not available for coordinate click`);
642
654
  }
643
655
  }
644
-
645
- this.pushEvent({
646
- event: 'agent:auto_approved',
647
- chatTitle: _chatData?.title || this.provider.name,
648
- timestamp: Date.now(),
649
- ideType: this.type,
650
- });
651
656
  } catch (e: any) {
652
657
  LOG.warn('IdeInstance', `[IdeInstance:${this.type}] autoApprove error: ${e?.message}`);
653
658
  } finally {
@@ -994,7 +994,11 @@ export class ProviderLoader {
994
994
  */
995
995
  getSettingValue(type: string, key: string): any {
996
996
  const schemaDef = this.getSettingsSchema(type)[key];
997
- const defaultVal = schemaDef ? (schemaDef as any).default : undefined;
997
+ const defaultVal = schemaDef
998
+ ? (key === 'autoApprove' && (schemaDef as any).type === 'boolean'
999
+ ? true
1000
+ : (schemaDef as any).default)
1001
+ : undefined;
998
1002
 
999
1003
  // Load user-saved value
1000
1004
  try {
@@ -1064,15 +1068,35 @@ export class ProviderLoader {
1064
1068
  private getSettingsSchema(type: string): Record<string, ProviderSettingDef> {
1065
1069
  const provider = this.providers.get(type);
1066
1070
  if (!provider) return {};
1067
- return {
1071
+ const result = {
1068
1072
  ...this.getSyntheticSettings(type, provider),
1069
1073
  ...(provider.settings || {}),
1070
1074
  };
1075
+ if (result.autoApprove?.type === 'boolean') {
1076
+ result.autoApprove = {
1077
+ ...result.autoApprove,
1078
+ default: true,
1079
+ public: true,
1080
+ label: result.autoApprove.label || 'Auto Approve',
1081
+ description: result.autoApprove.description || 'Automatically approve actionable prompts without sending approval alerts.',
1082
+ };
1083
+ }
1084
+ return result;
1071
1085
  }
1072
1086
 
1073
1087
  private getSyntheticSettings(type: string, provider: ProviderModule): Record<string, ProviderSettingDef> {
1074
1088
  const result: Record<string, ProviderSettingDef> = {};
1075
1089
 
1090
+ if (!provider.settings?.autoApprove) {
1091
+ result.autoApprove = {
1092
+ type: 'boolean',
1093
+ default: true,
1094
+ public: true,
1095
+ label: 'Auto Approve',
1096
+ description: 'Automatically approve actionable prompts without sending approval alerts.',
1097
+ };
1098
+ }
1099
+
1076
1100
  if ((provider.category === 'cli' || provider.category === 'acp') && provider.spawn?.command && !provider.settings?.executablePath) {
1077
1101
  result.executablePath = {
1078
1102
  type: 'string',