@slock-ai/daemon 0.28.1-alpha.1 → 0.28.1-alpha.3
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 +60 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -434,6 +434,19 @@ var ClaudeDriver = class {
|
|
|
434
434
|
return [];
|
|
435
435
|
}
|
|
436
436
|
const events = [];
|
|
437
|
+
const pushResultError = (message, fallback) => {
|
|
438
|
+
const parts = [];
|
|
439
|
+
if (Array.isArray(message.errors)) {
|
|
440
|
+
for (const err of message.errors) {
|
|
441
|
+
if (typeof err === "string" && err.trim()) parts.push(err.trim());
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (typeof message.result === "string" && message.result.trim()) {
|
|
445
|
+
parts.push(message.result.trim());
|
|
446
|
+
}
|
|
447
|
+
const detail = parts.join(" | ") || fallback;
|
|
448
|
+
events.push({ kind: "error", message: detail });
|
|
449
|
+
};
|
|
437
450
|
switch (event.type) {
|
|
438
451
|
case "system":
|
|
439
452
|
if (event.subtype === "init" && event.session_id) {
|
|
@@ -456,6 +469,29 @@ var ClaudeDriver = class {
|
|
|
456
469
|
break;
|
|
457
470
|
}
|
|
458
471
|
case "result": {
|
|
472
|
+
const subtype = typeof event.subtype === "string" ? event.subtype : "success";
|
|
473
|
+
const stopReason = typeof event.stop_reason === "string" ? event.stop_reason : null;
|
|
474
|
+
switch (subtype) {
|
|
475
|
+
case "success":
|
|
476
|
+
if (event.is_error && stopReason !== "max_tokens") {
|
|
477
|
+
pushResultError(event, "Execution failed");
|
|
478
|
+
}
|
|
479
|
+
break;
|
|
480
|
+
case "error_during_execution":
|
|
481
|
+
if (stopReason !== "max_tokens") {
|
|
482
|
+
pushResultError(event, "Execution failed");
|
|
483
|
+
}
|
|
484
|
+
break;
|
|
485
|
+
case "error_max_budget_usd":
|
|
486
|
+
pushResultError(event, "Budget limit exceeded");
|
|
487
|
+
break;
|
|
488
|
+
case "error_max_turns":
|
|
489
|
+
pushResultError(event, "Max turns exceeded");
|
|
490
|
+
break;
|
|
491
|
+
case "error_max_structured_output_retries":
|
|
492
|
+
pushResultError(event, "Structured output retries exceeded");
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
459
495
|
events.push({ kind: "turn_end", sessionId: event.session_id });
|
|
460
496
|
break;
|
|
461
497
|
}
|
|
@@ -860,6 +896,11 @@ function summarizeCrash(code, signal) {
|
|
|
860
896
|
if (typeof code === "number") return `exit code ${code}`;
|
|
861
897
|
return "unknown exit";
|
|
862
898
|
}
|
|
899
|
+
function isMissingResumeSession(ap) {
|
|
900
|
+
if (ap.driver.id !== "claude") return false;
|
|
901
|
+
if (!ap.sessionId) return false;
|
|
902
|
+
return /No conversation found with session ID/i.test(ap.lastRuntimeError || "");
|
|
903
|
+
}
|
|
863
904
|
function getMessageDeliveryText(supportsStdinNotification) {
|
|
864
905
|
return supportsStdinNotification ? "New messages will be delivered to you automatically via stdin." : "The daemon will automatically restart you when new messages arrive.";
|
|
865
906
|
}
|
|
@@ -1077,6 +1118,25 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
|
|
|
1077
1118
|
this.idleAgentConfigs.delete(agentId);
|
|
1078
1119
|
const reason = formatCrashReason(finalCode, finalSignal, ap);
|
|
1079
1120
|
const summary = summarizeCrash(finalCode, finalSignal);
|
|
1121
|
+
if (isMissingResumeSession(ap)) {
|
|
1122
|
+
const staleSessionId = ap.sessionId;
|
|
1123
|
+
const restartConfig = { ...ap.config, sessionId: null };
|
|
1124
|
+
console.warn(
|
|
1125
|
+
`[Agent ${agentId}] Stored Claude session ${staleSessionId} is unavailable locally; falling back to cold start`
|
|
1126
|
+
);
|
|
1127
|
+
this.broadcastActivity(
|
|
1128
|
+
agentId,
|
|
1129
|
+
"working",
|
|
1130
|
+
"Stored Claude session missing; cold-starting a new session\u2026",
|
|
1131
|
+
[{ kind: "text", text: `Stored Claude session ${staleSessionId} was not found locally. Falling back to a cold start.` }]
|
|
1132
|
+
);
|
|
1133
|
+
this.startAgent(agentId, restartConfig).catch((err) => {
|
|
1134
|
+
console.error(`[Agent ${agentId}] Cold start recovery failed:`, err);
|
|
1135
|
+
this.sendToServer({ type: "agent:status", agentId, status: "inactive" });
|
|
1136
|
+
this.broadcastActivity(agentId, "offline", `Crashed (${summary})`);
|
|
1137
|
+
});
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1080
1140
|
console.error(`[Agent ${agentId}] Process crashed (${reason}) \u2014 marking inactive`);
|
|
1081
1141
|
this.sendToServer({ type: "agent:status", agentId, status: "inactive" });
|
|
1082
1142
|
this.broadcastActivity(agentId, "offline", `Crashed (${summary})`);
|