@adhdev/daemon-core 0.8.20 → 0.8.22

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/session-host-core",
3
- "version": "0.8.20",
3
+ "version": "0.8.22",
4
4
  "description": "ADHDev local session host core — session registry, protocol, buffers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.8.20",
3
+ "version": "0.8.22",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -90,6 +90,31 @@ function isRecentDuplicateSend(key: string): boolean {
90
90
  return false;
91
91
  }
92
92
 
93
+ function parseMaybeJson(value: any): any {
94
+ if (typeof value !== 'string') return value;
95
+ try {
96
+ return JSON.parse(value);
97
+ } catch {
98
+ return value;
99
+ }
100
+ }
101
+
102
+ function didProviderConfirmSend(result: any): boolean {
103
+ const parsed = parseMaybeJson(result);
104
+ if (parsed === true) return true;
105
+ if (typeof parsed === 'string') {
106
+ const normalized = parsed.trim().toLowerCase();
107
+ return normalized === 'ok' || normalized === 'sent' || normalized === 'success' || normalized === 'true';
108
+ }
109
+ if (!parsed || typeof parsed !== 'object') return false;
110
+
111
+ return parsed.sent === true
112
+ || parsed.success === true
113
+ || parsed.ok === true
114
+ || parsed.submitted === true
115
+ || parsed.dispatched === true;
116
+ }
117
+
93
118
  export async function handleChatHistory(h: CommandHelpers, args: any): Promise<CommandResult> {
94
119
  const { agentType, offset, limit } = args;
95
120
  const historySessionId = getHistorySessionId(h, args);
@@ -280,9 +305,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
280
305
  try {
281
306
  const evalResult = await h.evaluateProviderScript('sendMessage', { MESSAGE: text }, 30000);
282
307
  if (evalResult?.result) {
283
- let parsed = evalResult.result;
284
- if (typeof parsed === 'string') { try { parsed = JSON.parse(parsed); } catch { } }
285
- if (parsed?.sent) {
308
+ const parsed = parseMaybeJson(evalResult.result);
309
+ if (didProviderConfirmSend(parsed)) {
286
310
  _log(`Extension script sent OK`);
287
311
  return _logSendSuccess('extension-script');
288
312
  }
@@ -318,9 +342,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
318
342
  if (sendScript) {
319
343
  try {
320
344
  const result = await targetCdp.evaluate(sendScript, 30000);
321
- let parsed: any = result;
322
- if (typeof result === 'string') { try { parsed = JSON.parse(result); } catch { } }
323
- if (parsed?.sent) {
345
+ const parsed: any = parseMaybeJson(result);
346
+ if (didProviderConfirmSend(parsed)) {
324
347
  _log(`sendMessage script OK`);
325
348
  return _logSendSuccess('script');
326
349
  }
@@ -365,9 +388,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
365
388
  const matchText = provider.webviewMatchText;
366
389
  const matchFn = matchText ? (body: string) => body.includes(matchText) : undefined;
367
390
  const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
368
- let wvParsed: any = wvResult;
369
- if (typeof wvResult === 'string') { try { wvParsed = JSON.parse(wvResult); } catch { } }
370
- if (wvParsed?.sent) {
391
+ const wvParsed: any = parseMaybeJson(wvResult);
392
+ if (didProviderConfirmSend(wvParsed)) {
371
393
  _log(`webviewSendMessage OK`);
372
394
  return _logSendSuccess('webview-script');
373
395
  }
@@ -390,9 +412,8 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
390
412
  const matchText = provider.webviewMatchText;
391
413
  const matchFn = matchText ? (body: string) => body.includes(matchText) : undefined;
392
414
  const wvResult = await targetCdp.evaluateInWebviewFrame(webviewScript, matchFn);
393
- let wvParsed: any = wvResult;
394
- if (typeof wvResult === 'string') { try { wvParsed = JSON.parse(wvResult); } catch { } }
395
- if (wvParsed?.sent) {
415
+ const wvParsed: any = parseMaybeJson(wvResult);
416
+ if (didProviderConfirmSend(wvParsed)) {
396
417
  _log(`webviewSendMessage OK`);
397
418
  return _logSendSuccess('webview-script');
398
419
  }