@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.
@@ -163,6 +163,7 @@ export declare class ProviderCliAdapter implements CliAdapter {
163
163
  private finishResponse;
164
164
  private maybeCommitVisibleIdleTranscript;
165
165
  private commitCurrentTranscript;
166
+ private invokeCliScript;
166
167
  private runParseSession;
167
168
  private runDetectStatus;
168
169
  private runParseApproval;
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ export { syncMeshes } from './mesh/mesh-sync.js';
33
33
  export type { MeshSyncTransport, MeshSyncResult, RemoteMeshRecord } from './mesh/mesh-sync.js';
34
34
  export { appendLedgerEntry, readLedgerEntries, getLedgerSummary, getLedgerDir, getSessionRecoveryContext } from './mesh/mesh-ledger.js';
35
35
  export type { MeshLedgerEntry, MeshLedgerKind, MeshLedgerSummary, ReadLedgerOptions, SessionRecoveryContext } from './mesh/mesh-ledger.js';
36
- export { enqueueTask, getQueue, claimNextTask, updateTaskStatus, updateSessionTaskStatus } from './mesh/mesh-work-queue.js';
36
+ export { enqueueTask, getQueue, claimNextTask, updateTaskStatus, updateSessionTaskStatus, cancelTask, requeueTask } from './mesh/mesh-work-queue.js';
37
37
  export type { MeshWorkQueueEntry, MeshTaskStatus } from './mesh/mesh-work-queue.js';
38
38
  export { triggerMeshQueue } from './mesh/mesh-events.js';
39
39
  export { loadState, saveState, resetState } from './config/state-store.js';
package/dist/index.js CHANGED
@@ -980,10 +980,12 @@ var init_mesh_ledger = __esm({
980
980
  // src/mesh/mesh-work-queue.ts
981
981
  var mesh_work_queue_exports = {};
982
982
  __export(mesh_work_queue_exports, {
983
+ cancelTask: () => cancelTask,
983
984
  claimNextTask: () => claimNextTask,
984
985
  enqueueTask: () => enqueueTask,
985
986
  getMeshQueueStats: () => getMeshQueueStats,
986
987
  getQueue: () => getQueue,
988
+ requeueTask: () => requeueTask,
987
989
  updateSessionTaskStatus: () => updateSessionTaskStatus,
988
990
  updateTaskStatus: () => updateTaskStatus
989
991
  });
@@ -1058,6 +1060,40 @@ function updateTaskStatus(meshId, taskId, status) {
1058
1060
  writeQueue(meshId, queue);
1059
1061
  return queue[idx];
1060
1062
  }
1063
+ function cancelTask(meshId, taskId, opts) {
1064
+ const queue = readQueue(meshId);
1065
+ const idx = queue.findIndex((q) => q.id === taskId);
1066
+ if (idx === -1) return null;
1067
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1068
+ queue[idx].status = "cancelled";
1069
+ queue[idx].updatedAt = now;
1070
+ queue[idx].cancelledAt = now;
1071
+ if (opts?.reason) queue[idx].cancelReason = opts.reason;
1072
+ writeQueue(meshId, queue);
1073
+ return queue[idx];
1074
+ }
1075
+ function requeueTask(meshId, taskId, opts) {
1076
+ const queue = readQueue(meshId);
1077
+ const idx = queue.findIndex((q) => q.id === taskId);
1078
+ if (idx === -1) return null;
1079
+ const entry = queue[idx];
1080
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1081
+ entry.status = "pending";
1082
+ delete entry.assignedNodeId;
1083
+ delete entry.assignedSessionId;
1084
+ delete entry.cancelledAt;
1085
+ delete entry.cancelReason;
1086
+ if (opts?.clearTargetNode) delete entry.targetNodeId;
1087
+ if (typeof opts?.targetNodeId === "string") entry.targetNodeId = opts.targetNodeId;
1088
+ if (opts?.clearTargetSession !== false) delete entry.targetSessionId;
1089
+ if (typeof opts?.targetSessionId === "string") entry.targetSessionId = opts.targetSessionId;
1090
+ entry.updatedAt = now;
1091
+ entry.requeuedAt = now;
1092
+ entry.requeueCount = (entry.requeueCount || 0) + 1;
1093
+ if (opts?.reason) entry.requeueReason = opts.reason;
1094
+ writeQueue(meshId, queue);
1095
+ return entry;
1096
+ }
1061
1097
  function updateSessionTaskStatus(meshId, sessionId, status) {
1062
1098
  const queue = readQueue(meshId);
1063
1099
  for (let i = queue.length - 1; i >= 0; i--) {
@@ -1076,7 +1112,8 @@ function getMeshQueueStats(meshId) {
1076
1112
  pending: queue.filter((q) => q.status === "pending").length,
1077
1113
  assigned: queue.filter((q) => q.status === "assigned").length,
1078
1114
  completed: queue.filter((q) => q.status === "completed").length,
1079
- failed: queue.filter((q) => q.status === "failed").length
1115
+ failed: queue.filter((q) => q.status === "failed").length,
1116
+ cancelled: queue.filter((q) => q.status === "cancelled").length
1080
1117
  };
1081
1118
  }
1082
1119
  var import_fs4, import_path4, import_crypto5;
@@ -1447,12 +1484,14 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
1447
1484
  return "";
1448
1485
  }
1449
1486
  function injectMeshSystemMessage(components, args) {
1487
+ let completedTaskForLedger = null;
1450
1488
  if (args.event === "agent:generating_completed") {
1451
1489
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
1452
1490
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1453
1491
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1454
1492
  if (sessionId) {
1455
- updateSessionTaskStatus(args.meshId, sessionId, "completed");
1493
+ const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed");
1494
+ completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
1456
1495
  if (nodeId && providerType) {
1457
1496
  setTimeout(() => {
1458
1497
  tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
@@ -1465,6 +1504,7 @@ function injectMeshSystemMessage(components, args) {
1465
1504
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1466
1505
  const completedTask = sessionId ? updateSessionTaskStatus(args.meshId, sessionId, "completed") : null;
1467
1506
  if (completedTask) {
1507
+ completedTaskForLedger = { id: completedTask.id };
1468
1508
  try {
1469
1509
  appendLedgerEntry(args.meshId, {
1470
1510
  kind: "task_completed",
@@ -1476,7 +1516,8 @@ function injectMeshSystemMessage(components, args) {
1476
1516
  nodeLabel: args.nodeLabel,
1477
1517
  taskId: completedTask.id,
1478
1518
  completedViaReady: true,
1479
- providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0
1519
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
1520
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
1480
1521
  }
1481
1522
  });
1482
1523
  } catch (e) {
@@ -1519,7 +1560,9 @@ function injectMeshSystemMessage(components, args) {
1519
1560
  payload: {
1520
1561
  event: args.event,
1521
1562
  nodeLabel: args.nodeLabel,
1522
- providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0
1563
+ taskId: completedTaskForLedger?.id || void 0,
1564
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
1565
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
1523
1566
  }
1524
1567
  });
1525
1568
  } catch (e) {
@@ -1634,7 +1677,8 @@ function handleMeshForwardEvent(components, payload) {
1634
1677
  metadataEvent: {
1635
1678
  targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId) || readNonEmptyString(payload.instanceId),
1636
1679
  providerType: readNonEmptyString(payload.providerType),
1637
- providerSessionId: readNonEmptyString(payload.providerSessionId)
1680
+ providerSessionId: readNonEmptyString(payload.providerSessionId),
1681
+ finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary)
1638
1682
  }
1639
1683
  });
1640
1684
  }
@@ -3857,6 +3901,11 @@ ${lastSnapshot}`;
3857
3901
  };
3858
3902
  }
3859
3903
  // ─── Script Execution ──────────────────────────
3904
+ invokeCliScript(script, input) {
3905
+ const hasStateFactory = typeof this.cliScripts?.createState === "function";
3906
+ const expectsStateArgument = hasStateFactory || this.scriptState !== null || script.length >= 2;
3907
+ return expectsStateArgument ? script(this.scriptState, input) : script(input);
3908
+ }
3860
3909
  runParseSession() {
3861
3910
  if (typeof this.cliScripts?.parseSession !== "function") {
3862
3911
  this.parseErrorMessage = `${this.cliType} parseSession unavailable`;
@@ -3877,7 +3926,10 @@ ${lastSnapshot}`;
3877
3926
  scope: this.currentTurnScope,
3878
3927
  runtimeSettings: this.runtimeSettings
3879
3928
  });
3880
- const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
3929
+ const session = this.invokeCliScript(
3930
+ this.cliScripts.parseSession,
3931
+ { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) }
3932
+ );
3881
3933
  this.parseErrorMessage = null;
3882
3934
  return session && typeof session === "object" ? session : null;
3883
3935
  } catch (e) {
@@ -3891,7 +3943,7 @@ ${lastSnapshot}`;
3891
3943
  if (!this.cliScripts?.detectStatus) return null;
3892
3944
  try {
3893
3945
  const screenText = this.terminalScreen.getText();
3894
- const status = this.cliScripts.detectStatus(this.scriptState, {
3946
+ const status = this.invokeCliScript(this.cliScripts.detectStatus, {
3895
3947
  tail: text.slice(-500),
3896
3948
  screenText,
3897
3949
  rawBuffer: this.accumulatedRawBuffer,
@@ -3910,7 +3962,7 @@ ${lastSnapshot}`;
3910
3962
  try {
3911
3963
  const screenText = this.terminalScreen.getText();
3912
3964
  const buffer = screenText || this.accumulatedBuffer;
3913
- return this.cliScripts.parseApproval(this.scriptState, {
3965
+ return this.invokeCliScript(this.cliScripts.parseApproval, {
3914
3966
  buffer,
3915
3967
  screenText,
3916
3968
  rawBuffer: this.accumulatedRawBuffer,
@@ -4829,6 +4881,7 @@ __export(index_exports, {
4829
4881
  buildThoughtChatMessage: () => buildThoughtChatMessage,
4830
4882
  buildToolChatMessage: () => buildToolChatMessage,
4831
4883
  buildUserChatMessage: () => buildUserChatMessage,
4884
+ cancelTask: () => cancelTask,
4832
4885
  claimNextTask: () => claimNextTask,
4833
4886
  classifyChatMessageVisibility: () => classifyChatMessageVisibility,
4834
4887
  classifyHotChatSessionsForSubscriptionFlush: () => classifyHotChatSessionsForSubscriptionFlush,
@@ -4940,6 +4993,7 @@ __export(index_exports, {
4940
4993
  registerExtensionProviders: () => registerExtensionProviders,
4941
4994
  removeNode: () => removeNode,
4942
4995
  removeWorktree: () => removeWorktree,
4996
+ requeueTask: () => requeueTask,
4943
4997
  resetConfig: () => resetConfig,
4944
4998
  resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
4945
4999
  resetState: () => resetState,
@@ -23916,6 +23970,39 @@ var DaemonCommandRouter = class {
23916
23970
  return { success: false, error: e.message };
23917
23971
  }
23918
23972
  }
23973
+ case "cancel_mesh_queue_task": {
23974
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
23975
+ const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
23976
+ if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
23977
+ try {
23978
+ const { cancelTask: cancelTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
23979
+ const reason = typeof args?.reason === "string" ? args.reason : void 0;
23980
+ const task = cancelTask2(meshId, taskId, { reason });
23981
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
23982
+ return { success: true, task };
23983
+ } catch (e) {
23984
+ return { success: false, error: e.message };
23985
+ }
23986
+ }
23987
+ case "requeue_mesh_queue_task": {
23988
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
23989
+ const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
23990
+ if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
23991
+ try {
23992
+ const { requeueTask: requeueTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
23993
+ const task = requeueTask2(meshId, taskId, {
23994
+ reason: typeof args?.reason === "string" ? args.reason : void 0,
23995
+ targetNodeId: typeof args?.targetNodeId === "string" ? args.targetNodeId.trim() : void 0,
23996
+ targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : void 0,
23997
+ clearTargetNode: args?.clearTargetNode === true,
23998
+ clearTargetSession: args?.clearTargetSession !== false
23999
+ });
24000
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
24001
+ return { success: true, task };
24002
+ } catch (e) {
24003
+ return { success: false, error: e.message };
24004
+ }
24005
+ }
23919
24006
  case "add_mesh_node": {
23920
24007
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
23921
24008
  const workspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
@@ -24073,7 +24160,13 @@ var DaemonCommandRouter = class {
24073
24160
  appendLedgerEntry2(meshId, {
24074
24161
  kind: "node_removed",
24075
24162
  nodeId,
24076
- payload: { worktree: !!node?.isLocalWorktree, sessionCleanupMode }
24163
+ payload: {
24164
+ worktree: !!node?.isLocalWorktree,
24165
+ sessionCleanupMode,
24166
+ workspace: typeof node?.workspace === "string" ? node.workspace : void 0,
24167
+ daemonId: typeof node?.daemonId === "string" ? node.daemonId : void 0,
24168
+ worktreeBranch: typeof node?.worktreeBranch === "string" ? node.worktreeBranch : void 0
24169
+ }
24077
24170
  });
24078
24171
  } catch {
24079
24172
  }
@@ -32562,6 +32655,7 @@ async function shutdownDaemonComponents(components) {
32562
32655
  buildThoughtChatMessage,
32563
32656
  buildToolChatMessage,
32564
32657
  buildUserChatMessage,
32658
+ cancelTask,
32565
32659
  claimNextTask,
32566
32660
  classifyChatMessageVisibility,
32567
32661
  classifyHotChatSessionsForSubscriptionFlush,
@@ -32673,6 +32767,7 @@ async function shutdownDaemonComponents(components) {
32673
32767
  registerExtensionProviders,
32674
32768
  removeNode,
32675
32769
  removeWorktree,
32770
+ requeueTask,
32676
32771
  resetConfig,
32677
32772
  resetDebugRuntimeConfig,
32678
32773
  resetState,