@adhdev/daemon-core 0.9.30 → 0.9.31
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 +35 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -10
- package/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +57 -17
package/package.json
CHANGED
|
@@ -583,11 +583,18 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
583
583
|
|
|
584
584
|
// Extension transport: evaluateInSession
|
|
585
585
|
if (isExtensionTransport(transport)) {
|
|
586
|
+
let extensionReadChatError = '';
|
|
586
587
|
try {
|
|
587
588
|
const evalResult = await h.evaluateProviderScript('readChat', undefined, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
|
|
588
589
|
if (evalResult?.result) {
|
|
589
590
|
let parsed = evalResult.result;
|
|
590
|
-
if (typeof parsed === 'string') {
|
|
591
|
+
if (typeof parsed === 'string') {
|
|
592
|
+
try {
|
|
593
|
+
parsed = JSON.parse(parsed);
|
|
594
|
+
} catch (e: any) {
|
|
595
|
+
extensionReadChatError = `extension read_chat parse failed: ${e?.message || String(e)}`;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
591
598
|
if (parsed && typeof parsed === 'object') {
|
|
592
599
|
const validated = validateReadChatResultPayload(parsed, 'extension read_chat');
|
|
593
600
|
_log(`Extension OK: ${validated.messages?.length || 0} msgs`);
|
|
@@ -610,8 +617,14 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
610
617
|
);
|
|
611
618
|
return buildReadChatCommandResult(validated as Record<string, any>, args);
|
|
612
619
|
}
|
|
620
|
+
if (!extensionReadChatError) {
|
|
621
|
+
extensionReadChatError = 'extension read_chat returned a non-object payload';
|
|
622
|
+
}
|
|
623
|
+
} else {
|
|
624
|
+
extensionReadChatError = 'extension read_chat returned no payload';
|
|
613
625
|
}
|
|
614
626
|
} catch (e: any) {
|
|
627
|
+
extensionReadChatError = `extension read_chat failed: ${e?.message || String(e)}`;
|
|
615
628
|
_log(`Extension error: ${e.message}`);
|
|
616
629
|
traceProviderEvent(args, 'provider', 'extension.read_chat.error', {
|
|
617
630
|
h,
|
|
@@ -626,8 +639,8 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
626
639
|
const parentSessionId = h.currentSession?.parentSessionId;
|
|
627
640
|
if (cdp && parentSessionId) {
|
|
628
641
|
const stream = await h.agentStream.collectActiveSession(cdp, parentSessionId);
|
|
629
|
-
if (stream
|
|
630
|
-
return
|
|
642
|
+
if (stream && stream.agentType !== provider?.type) {
|
|
643
|
+
return { success: false, error: `extension read_chat stream agent mismatch for ${provider?.type || 'unknown_extension'}` };
|
|
631
644
|
}
|
|
632
645
|
if (stream) {
|
|
633
646
|
h.historyWriter.appendNewMessages(
|
|
@@ -645,7 +658,7 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
645
658
|
}
|
|
646
659
|
}
|
|
647
660
|
}
|
|
648
|
-
return
|
|
661
|
+
return { success: false, error: extensionReadChatError || 'extension read_chat unavailable' };
|
|
649
662
|
}
|
|
650
663
|
|
|
651
664
|
// IDE category (default): cdp.evaluate
|
|
@@ -655,6 +668,7 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
655
668
|
// webview IDE (Kiro, PearAI) → evaluateInWebviewFrame directly use
|
|
656
669
|
const webviewScript = h.getProviderScript('webviewReadChat') || h.getProviderScript('webview_read_chat');
|
|
657
670
|
if (webviewScript) {
|
|
671
|
+
let webviewReadChatError = '';
|
|
658
672
|
try {
|
|
659
673
|
const matchText = provider?.webviewMatchText;
|
|
660
674
|
const matchFn = matchText
|
|
@@ -663,37 +677,56 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
663
677
|
const raw = await cdp.evaluateInWebviewFrame(webviewScript, matchFn);
|
|
664
678
|
if (raw) {
|
|
665
679
|
let parsed: any = raw;
|
|
666
|
-
if (typeof parsed === 'string') {
|
|
680
|
+
if (typeof parsed === 'string') {
|
|
681
|
+
try {
|
|
682
|
+
parsed = JSON.parse(parsed);
|
|
683
|
+
} catch (e: any) {
|
|
684
|
+
webviewReadChatError = `webview read_chat parse failed: ${e?.message || String(e)}`;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
667
687
|
if (parsed && typeof parsed === 'object') {
|
|
668
688
|
const validated = validateReadChatResultPayload(parsed, 'webview read_chat');
|
|
669
689
|
_log(`Webview OK: ${validated.messages?.length || 0} msgs`);
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
690
|
+
h.historyWriter.appendNewMessages(
|
|
691
|
+
provider?.type || getCurrentProviderType(h, 'unknown_webview'),
|
|
692
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(validated)),
|
|
693
|
+
validated.title,
|
|
694
|
+
args?.targetSessionId,
|
|
695
|
+
historySessionId,
|
|
696
|
+
);
|
|
677
697
|
return buildReadChatCommandResult(validated as Record<string, any>, args);
|
|
678
698
|
}
|
|
699
|
+
if (!webviewReadChatError) {
|
|
700
|
+
webviewReadChatError = 'webview read_chat returned a non-object payload';
|
|
701
|
+
}
|
|
702
|
+
} else {
|
|
703
|
+
webviewReadChatError = 'webview read_chat returned no payload';
|
|
679
704
|
}
|
|
680
705
|
} catch (e: any) {
|
|
706
|
+
webviewReadChatError = `webview read_chat failed: ${e?.message || String(e)}`;
|
|
681
707
|
_log(`Webview readChat error: ${e.message}`);
|
|
682
708
|
}
|
|
683
|
-
return
|
|
709
|
+
return { success: false, error: webviewReadChatError || 'webview read_chat unavailable' };
|
|
684
710
|
}
|
|
685
711
|
|
|
686
712
|
// Regular IDE (Cursor, Windsurf, Trae etc) → main DOM evaluate
|
|
687
713
|
const script = h.getProviderScript('readChat') || h.getProviderScript('read_chat');
|
|
688
714
|
if (script) {
|
|
715
|
+
let ideReadChatError = '';
|
|
689
716
|
try {
|
|
690
717
|
const evalResult = await h.evaluateProviderScript('readChat', undefined, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
|
|
691
718
|
if (evalResult?.result) {
|
|
692
719
|
let parsed: any = evalResult.result;
|
|
693
|
-
if (typeof parsed === 'string') {
|
|
694
|
-
|
|
720
|
+
if (typeof parsed === 'string') {
|
|
721
|
+
try {
|
|
722
|
+
parsed = JSON.parse(parsed);
|
|
723
|
+
} catch (e: any) {
|
|
724
|
+
ideReadChatError = `ide read_chat parse failed: ${e?.message || String(e)}`;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (parsed && typeof parsed === 'object') {
|
|
695
728
|
const validated = validateReadChatResultPayload(parsed, 'ide read_chat');
|
|
696
|
-
_log(`OK: ${validated.messages?.length} msgs`);
|
|
729
|
+
_log(`OK: ${validated.messages?.length || 0} msgs`);
|
|
697
730
|
traceProviderEvent(args, 'provider', 'ide.read_chat.success', {
|
|
698
731
|
h,
|
|
699
732
|
provider,
|
|
@@ -713,8 +746,14 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
713
746
|
);
|
|
714
747
|
return buildReadChatCommandResult(validated as Record<string, any>, args);
|
|
715
748
|
}
|
|
749
|
+
if (!ideReadChatError) {
|
|
750
|
+
ideReadChatError = 'ide read_chat returned a non-object payload';
|
|
751
|
+
}
|
|
752
|
+
} else {
|
|
753
|
+
ideReadChatError = 'ide read_chat returned no payload';
|
|
716
754
|
}
|
|
717
755
|
} catch (e: any) {
|
|
756
|
+
ideReadChatError = `ide read_chat failed: ${e?.message || String(e)}`;
|
|
718
757
|
LOG.info('Command', `[read_chat] Script error: ${e.message}`);
|
|
719
758
|
traceProviderEvent(args, 'provider', 'ide.read_chat.error', {
|
|
720
759
|
h,
|
|
@@ -723,9 +762,10 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
723
762
|
payload: { method: 'evaluate', error: e.message },
|
|
724
763
|
});
|
|
725
764
|
}
|
|
765
|
+
return { success: false, error: ideReadChatError || 'ide read_chat unavailable' };
|
|
726
766
|
}
|
|
727
767
|
|
|
728
|
-
return
|
|
768
|
+
return { success: false, error: 'read_chat unavailable' };
|
|
729
769
|
}
|
|
730
770
|
|
|
731
771
|
export async function handleSendChat(h: CommandHelpers, args: any): Promise<CommandResult> {
|