@adhdev/daemon-core 0.9.77-rc.33 → 0.9.77-rc.35

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.mjs CHANGED
@@ -975,10 +975,12 @@ var init_mesh_ledger = __esm({
975
975
  // src/mesh/mesh-work-queue.ts
976
976
  var mesh_work_queue_exports = {};
977
977
  __export(mesh_work_queue_exports, {
978
+ cancelTask: () => cancelTask,
978
979
  claimNextTask: () => claimNextTask,
979
980
  enqueueTask: () => enqueueTask,
980
981
  getMeshQueueStats: () => getMeshQueueStats,
981
982
  getQueue: () => getQueue,
983
+ requeueTask: () => requeueTask,
982
984
  updateSessionTaskStatus: () => updateSessionTaskStatus,
983
985
  updateTaskStatus: () => updateTaskStatus
984
986
  });
@@ -1056,6 +1058,40 @@ function updateTaskStatus(meshId, taskId, status) {
1056
1058
  writeQueue(meshId, queue);
1057
1059
  return queue[idx];
1058
1060
  }
1061
+ function cancelTask(meshId, taskId, opts) {
1062
+ const queue = readQueue(meshId);
1063
+ const idx = queue.findIndex((q) => q.id === taskId);
1064
+ if (idx === -1) return null;
1065
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1066
+ queue[idx].status = "cancelled";
1067
+ queue[idx].updatedAt = now;
1068
+ queue[idx].cancelledAt = now;
1069
+ if (opts?.reason) queue[idx].cancelReason = opts.reason;
1070
+ writeQueue(meshId, queue);
1071
+ return queue[idx];
1072
+ }
1073
+ function requeueTask(meshId, taskId, opts) {
1074
+ const queue = readQueue(meshId);
1075
+ const idx = queue.findIndex((q) => q.id === taskId);
1076
+ if (idx === -1) return null;
1077
+ const entry = queue[idx];
1078
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1079
+ entry.status = "pending";
1080
+ delete entry.assignedNodeId;
1081
+ delete entry.assignedSessionId;
1082
+ delete entry.cancelledAt;
1083
+ delete entry.cancelReason;
1084
+ if (opts?.clearTargetNode) delete entry.targetNodeId;
1085
+ if (typeof opts?.targetNodeId === "string") entry.targetNodeId = opts.targetNodeId;
1086
+ if (opts?.clearTargetSession !== false) delete entry.targetSessionId;
1087
+ if (typeof opts?.targetSessionId === "string") entry.targetSessionId = opts.targetSessionId;
1088
+ entry.updatedAt = now;
1089
+ entry.requeuedAt = now;
1090
+ entry.requeueCount = (entry.requeueCount || 0) + 1;
1091
+ if (opts?.reason) entry.requeueReason = opts.reason;
1092
+ writeQueue(meshId, queue);
1093
+ return entry;
1094
+ }
1059
1095
  function updateSessionTaskStatus(meshId, sessionId, status) {
1060
1096
  const queue = readQueue(meshId);
1061
1097
  for (let i = queue.length - 1; i >= 0; i--) {
@@ -1074,7 +1110,8 @@ function getMeshQueueStats(meshId) {
1074
1110
  pending: queue.filter((q) => q.status === "pending").length,
1075
1111
  assigned: queue.filter((q) => q.status === "assigned").length,
1076
1112
  completed: queue.filter((q) => q.status === "completed").length,
1077
- failed: queue.filter((q) => q.status === "failed").length
1113
+ failed: queue.filter((q) => q.status === "failed").length,
1114
+ cancelled: queue.filter((q) => q.status === "cancelled").length
1078
1115
  };
1079
1116
  }
1080
1117
  var init_mesh_work_queue = __esm({
@@ -1441,12 +1478,14 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
1441
1478
  return "";
1442
1479
  }
1443
1480
  function injectMeshSystemMessage(components, args) {
1481
+ let completedTaskForLedger = null;
1444
1482
  if (args.event === "agent:generating_completed") {
1445
1483
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
1446
1484
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1447
1485
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1448
1486
  if (sessionId) {
1449
- updateSessionTaskStatus(args.meshId, sessionId, "completed");
1487
+ const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed");
1488
+ completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
1450
1489
  if (nodeId && providerType) {
1451
1490
  setTimeout(() => {
1452
1491
  tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
@@ -1459,6 +1498,7 @@ function injectMeshSystemMessage(components, args) {
1459
1498
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1460
1499
  const completedTask = sessionId ? updateSessionTaskStatus(args.meshId, sessionId, "completed") : null;
1461
1500
  if (completedTask) {
1501
+ completedTaskForLedger = { id: completedTask.id };
1462
1502
  try {
1463
1503
  appendLedgerEntry(args.meshId, {
1464
1504
  kind: "task_completed",
@@ -1470,7 +1510,8 @@ function injectMeshSystemMessage(components, args) {
1470
1510
  nodeLabel: args.nodeLabel,
1471
1511
  taskId: completedTask.id,
1472
1512
  completedViaReady: true,
1473
- providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0
1513
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
1514
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
1474
1515
  }
1475
1516
  });
1476
1517
  } catch (e) {
@@ -1513,7 +1554,9 @@ function injectMeshSystemMessage(components, args) {
1513
1554
  payload: {
1514
1555
  event: args.event,
1515
1556
  nodeLabel: args.nodeLabel,
1516
- providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0
1557
+ taskId: completedTaskForLedger?.id || void 0,
1558
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
1559
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
1517
1560
  }
1518
1561
  });
1519
1562
  } catch (e) {
@@ -1628,7 +1671,8 @@ function handleMeshForwardEvent(components, payload) {
1628
1671
  metadataEvent: {
1629
1672
  targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId) || readNonEmptyString(payload.instanceId),
1630
1673
  providerType: readNonEmptyString(payload.providerType),
1631
- providerSessionId: readNonEmptyString(payload.providerSessionId)
1674
+ providerSessionId: readNonEmptyString(payload.providerSessionId),
1675
+ finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary)
1632
1676
  }
1633
1677
  });
1634
1678
  }
@@ -3853,6 +3897,11 @@ ${lastSnapshot}`;
3853
3897
  };
3854
3898
  }
3855
3899
  // ─── Script Execution ──────────────────────────
3900
+ invokeCliScript(script, input) {
3901
+ const hasStateFactory = typeof this.cliScripts?.createState === "function";
3902
+ const expectsStateArgument = hasStateFactory || this.scriptState !== null || script.length >= 2;
3903
+ return expectsStateArgument ? script(this.scriptState, input) : script(input);
3904
+ }
3856
3905
  runParseSession() {
3857
3906
  if (typeof this.cliScripts?.parseSession !== "function") {
3858
3907
  this.parseErrorMessage = `${this.cliType} parseSession unavailable`;
@@ -3873,7 +3922,10 @@ ${lastSnapshot}`;
3873
3922
  scope: this.currentTurnScope,
3874
3923
  runtimeSettings: this.runtimeSettings
3875
3924
  });
3876
- const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
3925
+ const session = this.invokeCliScript(
3926
+ this.cliScripts.parseSession,
3927
+ { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) }
3928
+ );
3877
3929
  this.parseErrorMessage = null;
3878
3930
  return session && typeof session === "object" ? session : null;
3879
3931
  } catch (e) {
@@ -3887,7 +3939,7 @@ ${lastSnapshot}`;
3887
3939
  if (!this.cliScripts?.detectStatus) return null;
3888
3940
  try {
3889
3941
  const screenText = this.terminalScreen.getText();
3890
- const status = this.cliScripts.detectStatus(this.scriptState, {
3942
+ const status = this.invokeCliScript(this.cliScripts.detectStatus, {
3891
3943
  tail: text.slice(-500),
3892
3944
  screenText,
3893
3945
  rawBuffer: this.accumulatedRawBuffer,
@@ -3906,7 +3958,7 @@ ${lastSnapshot}`;
3906
3958
  try {
3907
3959
  const screenText = this.terminalScreen.getText();
3908
3960
  const buffer = screenText || this.accumulatedBuffer;
3909
- return this.cliScripts.parseApproval(this.scriptState, {
3961
+ return this.invokeCliScript(this.cliScripts.parseApproval, {
3910
3962
  buffer,
3911
3963
  screenText,
3912
3964
  rawBuffer: this.accumulatedRawBuffer,
@@ -23699,6 +23751,39 @@ var DaemonCommandRouter = class {
23699
23751
  return { success: false, error: e.message };
23700
23752
  }
23701
23753
  }
23754
+ case "cancel_mesh_queue_task": {
23755
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
23756
+ const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
23757
+ if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
23758
+ try {
23759
+ const { cancelTask: cancelTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
23760
+ const reason = typeof args?.reason === "string" ? args.reason : void 0;
23761
+ const task = cancelTask2(meshId, taskId, { reason });
23762
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
23763
+ return { success: true, task };
23764
+ } catch (e) {
23765
+ return { success: false, error: e.message };
23766
+ }
23767
+ }
23768
+ case "requeue_mesh_queue_task": {
23769
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
23770
+ const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
23771
+ if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
23772
+ try {
23773
+ const { requeueTask: requeueTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
23774
+ const task = requeueTask2(meshId, taskId, {
23775
+ reason: typeof args?.reason === "string" ? args.reason : void 0,
23776
+ targetNodeId: typeof args?.targetNodeId === "string" ? args.targetNodeId.trim() : void 0,
23777
+ targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : void 0,
23778
+ clearTargetNode: args?.clearTargetNode === true,
23779
+ clearTargetSession: args?.clearTargetSession !== false
23780
+ });
23781
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
23782
+ return { success: true, task };
23783
+ } catch (e) {
23784
+ return { success: false, error: e.message };
23785
+ }
23786
+ }
23702
23787
  case "add_mesh_node": {
23703
23788
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
23704
23789
  const workspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
@@ -23856,7 +23941,13 @@ var DaemonCommandRouter = class {
23856
23941
  appendLedgerEntry2(meshId, {
23857
23942
  kind: "node_removed",
23858
23943
  nodeId,
23859
- payload: { worktree: !!node?.isLocalWorktree, sessionCleanupMode }
23944
+ payload: {
23945
+ worktree: !!node?.isLocalWorktree,
23946
+ sessionCleanupMode,
23947
+ workspace: typeof node?.workspace === "string" ? node.workspace : void 0,
23948
+ daemonId: typeof node?.daemonId === "string" ? node.daemonId : void 0,
23949
+ worktreeBranch: typeof node?.worktreeBranch === "string" ? node.worktreeBranch : void 0
23950
+ }
23860
23951
  });
23861
23952
  } catch {
23862
23953
  }
@@ -32349,6 +32440,7 @@ export {
32349
32440
  buildThoughtChatMessage,
32350
32441
  buildToolChatMessage,
32351
32442
  buildUserChatMessage,
32443
+ cancelTask,
32352
32444
  claimNextTask,
32353
32445
  classifyChatMessageVisibility,
32354
32446
  classifyHotChatSessionsForSubscriptionFlush,
@@ -32460,6 +32552,7 @@ export {
32460
32552
  registerExtensionProviders,
32461
32553
  removeNode,
32462
32554
  removeWorktree,
32555
+ requeueTask,
32463
32556
  resetConfig,
32464
32557
  resetDebugRuntimeConfig,
32465
32558
  resetState,