@boxcrew/cli 0.1.11 → 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 +28 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -509,23 +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
|
-
const
|
|
522
|
-
|
|
523
|
-
if (proxyToken) {
|
|
524
|
-
childEnv.ANTHROPIC_API_KEY = proxyToken;
|
|
525
|
-
if (proxyBaseUrl) {
|
|
526
|
-
childEnv.ANTHROPIC_BASE_URL = proxyBaseUrl;
|
|
527
|
-
}
|
|
516
|
+
for (const key of Object.keys(childEnv)) {
|
|
517
|
+
if (key.startsWith("_BX_")) delete childEnv[key];
|
|
528
518
|
}
|
|
519
|
+
return childEnv;
|
|
520
|
+
};
|
|
521
|
+
const spawnRuntime = (messageId, message, sessionId, retriedWithoutSession) => {
|
|
522
|
+
const childEnv = buildChildEnv();
|
|
529
523
|
let cmd;
|
|
530
524
|
let args;
|
|
531
525
|
if (runtime === "opencode") {
|
|
@@ -548,6 +542,7 @@ function runDaemon(agentName) {
|
|
|
548
542
|
child.stdin.write(message);
|
|
549
543
|
child.stdin.end();
|
|
550
544
|
}
|
|
545
|
+
let producedOutput = false;
|
|
551
546
|
if (runtime === "openclaw") {
|
|
552
547
|
let stdout = "";
|
|
553
548
|
let stderrChunks = "";
|
|
@@ -583,11 +578,17 @@ function runDaemon(agentName) {
|
|
|
583
578
|
rl.on("line", (line) => {
|
|
584
579
|
const event = parseLine(line);
|
|
585
580
|
if (event && sendToServer) {
|
|
581
|
+
producedOutput = true;
|
|
586
582
|
sendToServer({ type: "event", messageId, event });
|
|
587
583
|
}
|
|
588
584
|
});
|
|
589
585
|
child.on("exit", (code) => {
|
|
590
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
|
+
}
|
|
591
592
|
if (code && code !== 0 && sendToServer) {
|
|
592
593
|
const errorMsg = stderrChunks.trim() || `${runtime} exited with code ${code}`;
|
|
593
594
|
console.error(`${runtime} exited with code ${code}: ${stderrChunks.trim()}`);
|
|
@@ -603,6 +604,13 @@ function runDaemon(agentName) {
|
|
|
603
604
|
sendToServer?.({ type: "error", messageId, error: `Failed to spawn: ${err.message}` });
|
|
604
605
|
});
|
|
605
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
|
+
};
|
|
606
614
|
const cleanup = () => {
|
|
607
615
|
try {
|
|
608
616
|
unlinkSync(getPidFile(agentName));
|
|
@@ -646,6 +654,12 @@ function runDaemon(agentName) {
|
|
|
646
654
|
activeProcess.kill("SIGTERM");
|
|
647
655
|
activeProcess = null;
|
|
648
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
|
+
}
|
|
649
663
|
if (code === 4006) {
|
|
650
664
|
console.log(`[${(/* @__PURE__ */ new Date()).toISOString()}] Agent was deleted. Shutting down.`);
|
|
651
665
|
cleanup();
|
|
@@ -697,9 +711,7 @@ function registerConnectCommand(program2) {
|
|
|
697
711
|
_BX_WS_URL: config2.websocket_url,
|
|
698
712
|
_BX_CLAUDE_PATH: options.claudePath,
|
|
699
713
|
_BX_AGENT_NAME: config2.agent_name,
|
|
700
|
-
_BX_RUNTIME: config2.runtime
|
|
701
|
-
_BX_PROXY_TOKEN: config2.proxy_token,
|
|
702
|
-
_BX_PROXY_BASE_URL: config2.proxy_base_url
|
|
714
|
+
_BX_RUNTIME: config2.runtime
|
|
703
715
|
};
|
|
704
716
|
delete daemonEnv.CLAUDECODE;
|
|
705
717
|
delete daemonEnv.CLAUDE_CODE_ENTRYPOINT;
|