@boxcrew/cli 0.1.12 → 0.1.13
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 +25 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -509,18 +509,17 @@ function runDaemon(agentName) {
|
|
|
509
509
|
let sendToServer = null;
|
|
510
510
|
let reconnectAttempt = 0;
|
|
511
511
|
let shouldReconnect = true;
|
|
512
|
-
const
|
|
513
|
-
if (activeProcess) {
|
|
514
|
-
activeProcess.kill("SIGTERM");
|
|
515
|
-
activeProcess = null;
|
|
516
|
-
}
|
|
517
|
-
const { messageId, message, sessionId } = msg;
|
|
512
|
+
const buildChildEnv = () => {
|
|
518
513
|
const childEnv = { ...process.env };
|
|
519
514
|
delete childEnv.CLAUDECODE;
|
|
520
515
|
delete childEnv.CLAUDE_CODE_ENTRYPOINT;
|
|
521
516
|
for (const key of Object.keys(childEnv)) {
|
|
522
517
|
if (key.startsWith("_BX_")) delete childEnv[key];
|
|
523
518
|
}
|
|
519
|
+
return childEnv;
|
|
520
|
+
};
|
|
521
|
+
const spawnRuntime = (messageId, message, sessionId, retriedWithoutSession) => {
|
|
522
|
+
const childEnv = buildChildEnv();
|
|
524
523
|
let cmd;
|
|
525
524
|
let args;
|
|
526
525
|
if (runtime === "opencode") {
|
|
@@ -543,6 +542,7 @@ function runDaemon(agentName) {
|
|
|
543
542
|
child.stdin.write(message);
|
|
544
543
|
child.stdin.end();
|
|
545
544
|
}
|
|
545
|
+
let producedOutput = false;
|
|
546
546
|
if (runtime === "openclaw") {
|
|
547
547
|
let stdout = "";
|
|
548
548
|
let stderrChunks = "";
|
|
@@ -578,11 +578,17 @@ function runDaemon(agentName) {
|
|
|
578
578
|
rl.on("line", (line) => {
|
|
579
579
|
const event = parseLine(line);
|
|
580
580
|
if (event && sendToServer) {
|
|
581
|
+
producedOutput = true;
|
|
581
582
|
sendToServer({ type: "event", messageId, event });
|
|
582
583
|
}
|
|
583
584
|
});
|
|
584
585
|
child.on("exit", (code) => {
|
|
585
586
|
if (activeProcess === child) activeProcess = null;
|
|
587
|
+
if (code && code !== 0 && sessionId && !retriedWithoutSession && !producedOutput) {
|
|
588
|
+
console.log(`[${(/* @__PURE__ */ new Date()).toISOString()}] Session resume failed, retrying without --resume`);
|
|
589
|
+
spawnRuntime(messageId, message, void 0, true);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
586
592
|
if (code && code !== 0 && sendToServer) {
|
|
587
593
|
const errorMsg = stderrChunks.trim() || `${runtime} exited with code ${code}`;
|
|
588
594
|
console.error(`${runtime} exited with code ${code}: ${stderrChunks.trim()}`);
|
|
@@ -598,6 +604,13 @@ function runDaemon(agentName) {
|
|
|
598
604
|
sendToServer?.({ type: "error", messageId, error: `Failed to spawn: ${err.message}` });
|
|
599
605
|
});
|
|
600
606
|
};
|
|
607
|
+
const handleChat = (msg) => {
|
|
608
|
+
if (activeProcess) {
|
|
609
|
+
activeProcess.kill("SIGTERM");
|
|
610
|
+
activeProcess = null;
|
|
611
|
+
}
|
|
612
|
+
spawnRuntime(msg.messageId, msg.message, msg.sessionId, false);
|
|
613
|
+
};
|
|
601
614
|
const cleanup = () => {
|
|
602
615
|
try {
|
|
603
616
|
unlinkSync(getPidFile(agentName));
|
|
@@ -641,6 +654,12 @@ function runDaemon(agentName) {
|
|
|
641
654
|
activeProcess.kill("SIGTERM");
|
|
642
655
|
activeProcess = null;
|
|
643
656
|
}
|
|
657
|
+
if (code === 4004) {
|
|
658
|
+
console.log(`[${(/* @__PURE__ */ new Date()).toISOString()}] Replaced by new connection. Shutting down.`);
|
|
659
|
+
cleanup();
|
|
660
|
+
process.exit(0);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
644
663
|
if (code === 4006) {
|
|
645
664
|
console.log(`[${(/* @__PURE__ */ new Date()).toISOString()}] Agent was deleted. Shutting down.`);
|
|
646
665
|
cleanup();
|