@slock-ai/daemon 0.27.1-alpha.1 → 0.28.1-alpha.1

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.
Files changed (2) hide show
  1. package/dist/index.js +69 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -822,6 +822,44 @@ function buildUnreadSummary(messages, excludeChannel) {
822
822
  }
823
823
  var MAX_TRAJECTORY_TEXT = 2e3;
824
824
  var ACTIVITY_HEARTBEAT_MS = 6e4;
825
+ var MAX_STDERR_LINES = 8;
826
+ var MAX_STDERR_LINE_LENGTH = 240;
827
+ function pushRecentStderr(lines, chunk) {
828
+ const next = [...lines];
829
+ for (const rawLine of chunk.split(/\r?\n/)) {
830
+ const text = rawLine.trim();
831
+ if (!text) continue;
832
+ next.push(
833
+ text.length > MAX_STDERR_LINE_LENGTH ? `${text.slice(0, MAX_STDERR_LINE_LENGTH)}...` : text
834
+ );
835
+ }
836
+ return next.slice(-MAX_STDERR_LINES);
837
+ }
838
+ function formatCrashReason(code, signal, ap) {
839
+ const parts = [];
840
+ if (signal) {
841
+ parts.push(`signal ${signal}`);
842
+ } else if (typeof code === "number") {
843
+ parts.push(`exit code ${code}`);
844
+ } else {
845
+ parts.push("unknown exit");
846
+ }
847
+ if (ap.spawnError) {
848
+ parts.push(`spawn error: ${ap.spawnError}`);
849
+ }
850
+ if (ap.lastRuntimeError) {
851
+ parts.push(`runtime error: ${ap.lastRuntimeError}`);
852
+ }
853
+ if (ap.recentStderr.length > 0) {
854
+ parts.push(`stderr: ${ap.recentStderr.join(" | ")}`);
855
+ }
856
+ return parts.join(" | ");
857
+ }
858
+ function summarizeCrash(code, signal) {
859
+ if (signal) return `signal ${signal}`;
860
+ if (typeof code === "number") return `exit code ${code}`;
861
+ return "unknown exit";
862
+ }
825
863
  function getMessageDeliveryText(supportsStdinNotification) {
826
864
  return supportsStdinNotification ? "New messages will be delivered to you automatically via stdin." : "The daemon will automatically restart you when new messages arrive.";
827
865
  }
@@ -950,7 +988,12 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
950
988
  pendingNotificationCount: 0,
951
989
  activityHeartbeat: null,
952
990
  lastActivity: "",
953
- lastActivityDetail: ""
991
+ lastActivityDetail: "",
992
+ recentStderr: [],
993
+ lastRuntimeError: null,
994
+ spawnError: null,
995
+ exitCode: null,
996
+ exitSignal: null
954
997
  };
955
998
  this.startingInboxes.delete(agentId);
956
999
  this.agents.set(agentId, agentProcess);
@@ -972,10 +1015,26 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
972
1015
  const text = chunk.toString().trim();
973
1016
  if (!text) return;
974
1017
  if (/Reconnecting\.\.\.|Falling back from WebSockets/i.test(text)) return;
1018
+ const current = this.agents.get(agentId);
1019
+ if (current) {
1020
+ current.recentStderr = pushRecentStderr(current.recentStderr, text);
1021
+ }
975
1022
  console.error(`[Agent ${agentId} stderr]: ${text}`);
976
1023
  });
977
- proc.on("exit", (code) => {
978
- console.log(`[Agent ${agentId}] Process exited with code ${code}`);
1024
+ proc.on("error", (err) => {
1025
+ const current = this.agents.get(agentId);
1026
+ if (current) current.spawnError = err.message;
1027
+ console.error(`[Agent ${agentId}] Process error: ${err.message}`);
1028
+ });
1029
+ proc.on("exit", (code, signal) => {
1030
+ const current = this.agents.get(agentId);
1031
+ if (current && current.process === proc) {
1032
+ current.exitCode = code;
1033
+ current.exitSignal = signal;
1034
+ }
1035
+ console.log(`[Agent ${agentId}] Process exited with code ${code}${signal ? ` (signal ${signal})` : ""}`);
1036
+ });
1037
+ proc.on("close", (code, signal) => {
979
1038
  if (this.agents.has(agentId)) {
980
1039
  const ap = this.agents.get(agentId);
981
1040
  if (ap.process !== proc) return;
@@ -986,7 +1045,9 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
986
1045
  clearInterval(ap.activityHeartbeat);
987
1046
  }
988
1047
  this.agents.delete(agentId);
989
- if (code === 0) {
1048
+ const finalCode = ap.exitCode ?? code;
1049
+ const finalSignal = ap.exitSignal ?? signal;
1050
+ if (finalCode === 0) {
990
1051
  const queuedWakeMessage = !ap.driver.supportsStdinNotification ? ap.inbox.shift() : void 0;
991
1052
  const unreadSummary2 = queuedWakeMessage ? buildUnreadSummary(ap.inbox, formatChannelLabel(queuedWakeMessage)) : void 0;
992
1053
  if (queuedWakeMessage) {
@@ -1014,10 +1075,11 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
1014
1075
  this.broadcastActivity(agentId, "online", "Process idle");
1015
1076
  } else {
1016
1077
  this.idleAgentConfigs.delete(agentId);
1017
- const reason = code === null ? "killed by signal" : `exit code ${code}`;
1078
+ const reason = formatCrashReason(finalCode, finalSignal, ap);
1079
+ const summary = summarizeCrash(finalCode, finalSignal);
1018
1080
  console.error(`[Agent ${agentId}] Process crashed (${reason}) \u2014 marking inactive`);
1019
1081
  this.sendToServer({ type: "agent:status", agentId, status: "inactive" });
1020
- this.broadcastActivity(agentId, "offline", `Crashed (${reason})`);
1082
+ this.broadcastActivity(agentId, "offline", `Crashed (${summary})`);
1021
1083
  }
1022
1084
  }
1023
1085
  });
@@ -1399,6 +1461,7 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
1399
1461
  }
1400
1462
  break;
1401
1463
  case "error": {
1464
+ if (ap) ap.lastRuntimeError = event.message;
1402
1465
  const currentActivity = ap?.lastActivity || "working";
1403
1466
  const currentDetail = ap?.lastActivityDetail || "";
1404
1467
  this.sendToServer({ type: "agent:activity", agentId, activity: currentActivity, detail: currentDetail, entries: [{ kind: "text", text: `Error: ${event.message}` }] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slock-ai/daemon",
3
- "version": "0.27.1-alpha.1",
3
+ "version": "0.28.1-alpha.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "slock-daemon": "dist/index.js"