tuna-agent 0.1.92 → 0.1.94
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.
|
@@ -342,14 +342,17 @@ export class ClaudeCodeAdapter {
|
|
|
342
342
|
this.runReflection(task, result.result, 'failed', cwd).catch(() => { });
|
|
343
343
|
return;
|
|
344
344
|
}
|
|
345
|
-
// Track last output for reflection
|
|
346
|
-
lastTaskOutput = turnAccumulatedText.trim();
|
|
345
|
+
// Track last output for reflection (fallback to result.result if no streaming text)
|
|
346
|
+
lastTaskOutput = turnAccumulatedText.trim() || result.result;
|
|
347
347
|
if (lastTaskOutput) {
|
|
348
348
|
console.log(`[Reflection] Captured ${lastTaskOutput.length} chars of task output for reflection`);
|
|
349
349
|
}
|
|
350
350
|
// Send finalized message for the last turn's remaining text (skip if duplicate)
|
|
351
|
-
if (
|
|
352
|
-
|
|
351
|
+
// Fallback: if no streaming deltas were captured (e.g. agent_team mode may emit
|
|
352
|
+
// complete assistant messages instead of stream_event deltas), use result.result
|
|
353
|
+
const finalText = turnAccumulatedText.trim() || result.result;
|
|
354
|
+
if (finalText) {
|
|
355
|
+
const simplified = simplifyMarkdown(finalText);
|
|
353
356
|
if (!isSimilar(simplified, lastSentContent)) {
|
|
354
357
|
ws.sendPMMessage(task.id, {
|
|
355
358
|
sender: 'pm',
|
|
@@ -711,6 +711,8 @@ export declare class BrowserClaw {
|
|
|
711
711
|
page(targetId: string): CrawlPage;
|
|
712
712
|
/** The CDP endpoint URL for this browser connection. */
|
|
713
713
|
get url(): string;
|
|
714
|
+
/** PID of the Chrome process (null if connected to external Chrome). */
|
|
715
|
+
get chromePid(): number | null;
|
|
714
716
|
/**
|
|
715
717
|
* Stop the browser and clean up all resources.
|
|
716
718
|
*
|
package/dist/browser/browser.js
CHANGED
|
@@ -1049,6 +1049,10 @@ export class BrowserClaw {
|
|
|
1049
1049
|
get url() {
|
|
1050
1050
|
return this.cdpUrl;
|
|
1051
1051
|
}
|
|
1052
|
+
/** PID of the Chrome process (null if connected to external Chrome). */
|
|
1053
|
+
get chromePid() {
|
|
1054
|
+
return this.chrome?.pid ?? null;
|
|
1055
|
+
}
|
|
1052
1056
|
/**
|
|
1053
1057
|
* Stop the browser and clean up all resources.
|
|
1054
1058
|
*
|
|
@@ -36,6 +36,7 @@ function parseArgs() {
|
|
|
36
36
|
}
|
|
37
37
|
// ===== Browser State =====
|
|
38
38
|
let browser = null;
|
|
39
|
+
let chromePid = null; // Track Chrome PID for synchronous cleanup
|
|
39
40
|
const pages = new Map(); // targetId → CrawlPage
|
|
40
41
|
async function ensureBrowser(config) {
|
|
41
42
|
if (browser)
|
|
@@ -51,6 +52,7 @@ async function ensureBrowser(config) {
|
|
|
51
52
|
cdpPort: config.cdpPort,
|
|
52
53
|
});
|
|
53
54
|
}
|
|
55
|
+
chromePid = browser.chromePid;
|
|
54
56
|
return browser;
|
|
55
57
|
}
|
|
56
58
|
function sendResponse(res) {
|
|
@@ -406,6 +408,7 @@ async function handleToolCall(toolName, args) {
|
|
|
406
408
|
if (browser) {
|
|
407
409
|
await browser.stop();
|
|
408
410
|
browser = null;
|
|
411
|
+
chromePid = null;
|
|
409
412
|
pages.clear();
|
|
410
413
|
activePageId = null;
|
|
411
414
|
}
|
|
@@ -448,20 +451,39 @@ function startServer() {
|
|
|
448
451
|
process.stderr.write('[browser-mcp] stdin closed, cleaning up browser\n');
|
|
449
452
|
if (browser) {
|
|
450
453
|
await browser.stop().catch(() => { });
|
|
454
|
+
browser = null;
|
|
455
|
+
chromePid = null;
|
|
451
456
|
}
|
|
452
457
|
process.exit(0);
|
|
453
458
|
});
|
|
454
459
|
// Cleanup on process exit
|
|
455
460
|
process.on('SIGTERM', async () => {
|
|
456
|
-
if (browser)
|
|
461
|
+
if (browser) {
|
|
457
462
|
await browser.stop().catch(() => { });
|
|
463
|
+
browser = null;
|
|
464
|
+
chromePid = null;
|
|
465
|
+
}
|
|
458
466
|
process.exit(0);
|
|
459
467
|
});
|
|
460
468
|
process.on('SIGINT', async () => {
|
|
461
|
-
if (browser)
|
|
469
|
+
if (browser) {
|
|
462
470
|
await browser.stop().catch(() => { });
|
|
471
|
+
browser = null;
|
|
472
|
+
chromePid = null;
|
|
473
|
+
}
|
|
463
474
|
process.exit(0);
|
|
464
475
|
});
|
|
476
|
+
// Synchronous safety net: force kill Chrome if async cleanup didn't run
|
|
477
|
+
// This handles cases where process exits unexpectedly (crash, SIGKILL parent, etc.)
|
|
478
|
+
process.on('exit', () => {
|
|
479
|
+
if (chromePid) {
|
|
480
|
+
try {
|
|
481
|
+
process.kill(chromePid, 'SIGKILL');
|
|
482
|
+
}
|
|
483
|
+
catch { }
|
|
484
|
+
chromePid = null;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
465
487
|
}
|
|
466
488
|
// ===== Main =====
|
|
467
489
|
startServer();
|