@adhdev/daemon-core 0.5.58 → 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 +47 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +20 -9
- package/src/providers/ide-provider-instance.ts +32 -5
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ export async function handleChatHistory(h: CommandHelpers, args: any): Promise<C
|
|
|
21
21
|
|
|
22
22
|
export async function handleReadChat(h: CommandHelpers, args: any): Promise<CommandResult> {
|
|
23
23
|
const provider = h.getProvider();
|
|
24
|
+
|
|
24
25
|
const _log = (msg: string) => LOG.debug('Command', `[read_chat] ${msg}`);
|
|
25
26
|
|
|
26
27
|
// CLI / ACP category: read from adapter
|
|
@@ -141,6 +142,16 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
141
142
|
const _log = (msg: string) => LOG.debug('Command', `[send_chat] ${msg}`);
|
|
142
143
|
const provider = h.getProvider();
|
|
143
144
|
|
|
145
|
+
const _logSendSuccess = (method: string, targetAgent?: string) => {
|
|
146
|
+
h.historyWriter.appendNewMessages(
|
|
147
|
+
targetAgent || provider?.type || h.currentIdeType || 'unknown_agent',
|
|
148
|
+
[{ role: 'user', content: text, receivedAt: Date.now() }],
|
|
149
|
+
undefined, // title
|
|
150
|
+
args?.instanceId
|
|
151
|
+
);
|
|
152
|
+
return { success: true, sent: true, method, targetAgent };
|
|
153
|
+
};
|
|
154
|
+
|
|
144
155
|
// CLI / ACP category: transmit via adapter
|
|
145
156
|
if (provider?.category === 'cli' || provider?.category === 'acp') {
|
|
146
157
|
const adapter = h.getCliAdapter(provider.type);
|
|
@@ -148,7 +159,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
148
159
|
_log(`${provider.category} adapter: ${(adapter as any).cliType}`);
|
|
149
160
|
try {
|
|
150
161
|
await adapter.sendMessage(text);
|
|
151
|
-
return
|
|
162
|
+
return _logSendSuccess(`${provider.category}-adapter`, (adapter as any).cliType);
|
|
152
163
|
} catch (e: any) {
|
|
153
164
|
return { success: false, error: `${provider.category} send failed: ${e.message}` };
|
|
154
165
|
}
|
|
@@ -166,7 +177,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
166
177
|
if (typeof parsed === 'string') { try { parsed = JSON.parse(parsed); } catch { } }
|
|
167
178
|
if (parsed?.sent) {
|
|
168
179
|
_log(`Extension script sent OK`);
|
|
169
|
-
return
|
|
180
|
+
return _logSendSuccess('extension-script');
|
|
170
181
|
}
|
|
171
182
|
if (parsed?.needsTypeAndSend) {
|
|
172
183
|
_log(`Extension needsTypeAndSend → AgentStreamManager`);
|
|
@@ -180,7 +191,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
180
191
|
const ok = await h.agentStream.sendToAgent(h.getCdp()!, provider.type, text, h.currentIdeType);
|
|
181
192
|
if (ok) {
|
|
182
193
|
_log(`AgentStreamManager sent OK`);
|
|
183
|
-
return
|
|
194
|
+
return _logSendSuccess('agent-stream');
|
|
184
195
|
}
|
|
185
196
|
}
|
|
186
197
|
return { success: false, error: `Extension '${provider.type}' send failed` };
|
|
@@ -207,7 +218,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
207
218
|
if (typeof wvResult === 'string') { try { wvParsed = JSON.parse(wvResult); } catch { } }
|
|
208
219
|
if (wvParsed?.sent) {
|
|
209
220
|
_log(`webviewSendMessage (priority) OK`);
|
|
210
|
-
return
|
|
221
|
+
return _logSendSuccess('webview-script-priority');
|
|
211
222
|
}
|
|
212
223
|
_log(`webviewSendMessage (priority) did not confirm sent, falling through`);
|
|
213
224
|
}
|
|
@@ -222,7 +233,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
222
233
|
const sent = await targetCdp.typeAndSend(provider.inputSelector, text);
|
|
223
234
|
if (sent) {
|
|
224
235
|
_log(`typeAndSend(provider.inputSelector=${provider.inputSelector}) success`);
|
|
225
|
-
return
|
|
236
|
+
return _logSendSuccess('typeAndSend-provider');
|
|
226
237
|
}
|
|
227
238
|
} catch (e: any) {
|
|
228
239
|
_log(`typeAndSend(provider) failed: ${e.message}`);
|
|
@@ -238,7 +249,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
238
249
|
if (typeof result === 'string') { try { parsed = JSON.parse(result); } catch { } }
|
|
239
250
|
if (parsed?.sent) {
|
|
240
251
|
_log(`sendMessage script OK`);
|
|
241
|
-
return
|
|
252
|
+
return _logSendSuccess('script');
|
|
242
253
|
}
|
|
243
254
|
// needsTypeAndSend response: typeAndSend using script-specified selector
|
|
244
255
|
if (parsed?.needsTypeAndSend && parsed?.selector) {
|
|
@@ -246,7 +257,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
246
257
|
const sent = await targetCdp.typeAndSend(parsed.selector, text);
|
|
247
258
|
if (sent) {
|
|
248
259
|
_log(`typeAndSend(script.selector=${parsed.selector}) success`);
|
|
249
|
-
return
|
|
260
|
+
return _logSendSuccess('typeAndSend-script');
|
|
250
261
|
}
|
|
251
262
|
} catch (e: any) {
|
|
252
263
|
_log(`typeAndSend(script.selector) failed: ${e.message}`);
|
|
@@ -264,7 +275,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
264
275
|
if (typeof wvResult === 'string') { try { wvParsed = JSON.parse(wvResult); } catch { } }
|
|
265
276
|
if (wvParsed?.sent) {
|
|
266
277
|
_log(`webviewSendMessage OK`);
|
|
267
|
-
return
|
|
278
|
+
return _logSendSuccess('webview-script');
|
|
268
279
|
}
|
|
269
280
|
}
|
|
270
281
|
} catch (e: any) {
|
|
@@ -278,7 +289,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
278
289
|
const sent = await targetCdp.typeAndSendAt(x, y, text);
|
|
279
290
|
if (sent) {
|
|
280
291
|
_log(`typeAndSendAt(${x},${y}) success`);
|
|
281
|
-
return
|
|
292
|
+
return _logSendSuccess('typeAndSendAt-script');
|
|
282
293
|
}
|
|
283
294
|
} catch (e: any) {
|
|
284
295
|
_log(`typeAndSendAt failed: ${e.message}`);
|
|
@@ -406,13 +406,40 @@ export class IdeProviderInstance implements ProviderInstance {
|
|
|
406
406
|
|
|
407
407
|
this.autoApproveBusy = true;
|
|
408
408
|
try {
|
|
409
|
-
|
|
409
|
+
let targetButton = _chatData?.activeModal?.buttons?.[0] || 'Run';
|
|
410
|
+
const buttons = _chatData?.activeModal?.buttons || [];
|
|
411
|
+
|
|
412
|
+
// Prefer buttons like 'Run', 'Approve', 'Yes'
|
|
413
|
+
for (const b of buttons) {
|
|
414
|
+
const lower = String(b).toLowerCase().replace(/[^\w]/g, '');
|
|
415
|
+
if (/^(run|approve|accept|yes|allow|always|proceed|save)/.test(lower)) {
|
|
416
|
+
targetButton = b;
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const script = scriptFn({ action: 'approve', button: targetButton, buttonText: targetButton });
|
|
410
422
|
if (!script) return;
|
|
411
423
|
|
|
412
|
-
LOG.info('IdeInstance', `[IdeInstance:${this.type}] autoApprove: executing resolveAction`);
|
|
413
|
-
|
|
424
|
+
LOG.info('IdeInstance', `[IdeInstance:${this.type}] autoApprove: executing resolveAction for "${targetButton}"`);
|
|
425
|
+
let rawResult = await cdp.evaluate(script, 10000);
|
|
426
|
+
if (typeof rawResult === 'string') {
|
|
427
|
+
try { rawResult = JSON.parse(rawResult); } catch { }
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const result: any = rawResult;
|
|
414
431
|
LOG.info('IdeInstance', `[IdeInstance:${this.type}] autoApprove result: ${JSON.stringify(result)?.slice(0, 200)}`);
|
|
415
432
|
|
|
433
|
+
if (result?.found && result.x != null && result.y != null) {
|
|
434
|
+
// Coordinate-based click (fallback when script cannot .click() directly)
|
|
435
|
+
const x = result.x;
|
|
436
|
+
const y = result.y;
|
|
437
|
+
const anyCdp = cdp as any;
|
|
438
|
+
await anyCdp.send('Input.dispatchMouseEvent', { type: 'mousePressed', x, y, button: 'left', clickCount: 1 });
|
|
439
|
+
await anyCdp.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x, y, button: 'left', clickCount: 1 });
|
|
440
|
+
LOG.info('IdeInstance', `[IdeInstance:${this.type}] autoApprove: dispatched mouse event at ${x},${y}`);
|
|
441
|
+
}
|
|
442
|
+
|
|
416
443
|
this.pushEvent({
|
|
417
444
|
event: 'agent:auto_approved',
|
|
418
445
|
chatTitle: _chatData?.title || this.provider.name,
|
|
@@ -422,8 +449,8 @@ export class IdeProviderInstance implements ProviderInstance {
|
|
|
422
449
|
} catch (e: any) {
|
|
423
450
|
LOG.warn('IdeInstance', `[IdeInstance:${this.type}] autoApprove error: ${e?.message}`);
|
|
424
451
|
} finally {
|
|
425
|
-
// Debounce: prevent rapid re-approval
|
|
426
|
-
setTimeout(() => { this.autoApproveBusy = false; },
|
|
452
|
+
// Debounce: prevent rapid re-approval
|
|
453
|
+
setTimeout(() => { this.autoApproveBusy = false; }, 1000);
|
|
427
454
|
}
|
|
428
455
|
}
|
|
429
456
|
}
|