@adhdev/daemon-standalone 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.js CHANGED
@@ -32178,10 +32178,12 @@ Follow these recovery rules:
32178
32178
  });
32179
32179
  var mesh_work_queue_exports = {};
32180
32180
  __export2(mesh_work_queue_exports, {
32181
+ cancelTask: () => cancelTask,
32181
32182
  claimNextTask: () => claimNextTask,
32182
32183
  enqueueTask: () => enqueueTask,
32183
32184
  getMeshQueueStats: () => getMeshQueueStats,
32184
32185
  getQueue: () => getQueue,
32186
+ requeueTask: () => requeueTask,
32185
32187
  updateSessionTaskStatus: () => updateSessionTaskStatus,
32186
32188
  updateTaskStatus: () => updateTaskStatus
32187
32189
  });
@@ -32256,6 +32258,40 @@ Follow these recovery rules:
32256
32258
  writeQueue(meshId, queue);
32257
32259
  return queue[idx];
32258
32260
  }
32261
+ function cancelTask(meshId, taskId, opts) {
32262
+ const queue = readQueue(meshId);
32263
+ const idx = queue.findIndex((q2) => q2.id === taskId);
32264
+ if (idx === -1) return null;
32265
+ const now = (/* @__PURE__ */ new Date()).toISOString();
32266
+ queue[idx].status = "cancelled";
32267
+ queue[idx].updatedAt = now;
32268
+ queue[idx].cancelledAt = now;
32269
+ if (opts?.reason) queue[idx].cancelReason = opts.reason;
32270
+ writeQueue(meshId, queue);
32271
+ return queue[idx];
32272
+ }
32273
+ function requeueTask(meshId, taskId, opts) {
32274
+ const queue = readQueue(meshId);
32275
+ const idx = queue.findIndex((q2) => q2.id === taskId);
32276
+ if (idx === -1) return null;
32277
+ const entry = queue[idx];
32278
+ const now = (/* @__PURE__ */ new Date()).toISOString();
32279
+ entry.status = "pending";
32280
+ delete entry.assignedNodeId;
32281
+ delete entry.assignedSessionId;
32282
+ delete entry.cancelledAt;
32283
+ delete entry.cancelReason;
32284
+ if (opts?.clearTargetNode) delete entry.targetNodeId;
32285
+ if (typeof opts?.targetNodeId === "string") entry.targetNodeId = opts.targetNodeId;
32286
+ if (opts?.clearTargetSession !== false) delete entry.targetSessionId;
32287
+ if (typeof opts?.targetSessionId === "string") entry.targetSessionId = opts.targetSessionId;
32288
+ entry.updatedAt = now;
32289
+ entry.requeuedAt = now;
32290
+ entry.requeueCount = (entry.requeueCount || 0) + 1;
32291
+ if (opts?.reason) entry.requeueReason = opts.reason;
32292
+ writeQueue(meshId, queue);
32293
+ return entry;
32294
+ }
32259
32295
  function updateSessionTaskStatus(meshId, sessionId, status) {
32260
32296
  const queue = readQueue(meshId);
32261
32297
  for (let i = queue.length - 1; i >= 0; i--) {
@@ -32274,7 +32310,8 @@ Follow these recovery rules:
32274
32310
  pending: queue.filter((q2) => q2.status === "pending").length,
32275
32311
  assigned: queue.filter((q2) => q2.status === "assigned").length,
32276
32312
  completed: queue.filter((q2) => q2.status === "completed").length,
32277
- failed: queue.filter((q2) => q2.status === "failed").length
32313
+ failed: queue.filter((q2) => q2.status === "failed").length,
32314
+ cancelled: queue.filter((q2) => q2.status === "cancelled").length
32278
32315
  };
32279
32316
  }
32280
32317
  var import_fs4;
@@ -32662,12 +32699,14 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32662
32699
  return "";
32663
32700
  }
32664
32701
  function injectMeshSystemMessage(components, args) {
32702
+ let completedTaskForLedger = null;
32665
32703
  if (args.event === "agent:generating_completed") {
32666
32704
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
32667
32705
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
32668
32706
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
32669
32707
  if (sessionId) {
32670
- updateSessionTaskStatus(args.meshId, sessionId, "completed");
32708
+ const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed");
32709
+ completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
32671
32710
  if (nodeId && providerType) {
32672
32711
  setTimeout(() => {
32673
32712
  tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
@@ -32680,6 +32719,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32680
32719
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
32681
32720
  const completedTask = sessionId ? updateSessionTaskStatus(args.meshId, sessionId, "completed") : null;
32682
32721
  if (completedTask) {
32722
+ completedTaskForLedger = { id: completedTask.id };
32683
32723
  try {
32684
32724
  appendLedgerEntry(args.meshId, {
32685
32725
  kind: "task_completed",
@@ -32691,7 +32731,8 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32691
32731
  nodeLabel: args.nodeLabel,
32692
32732
  taskId: completedTask.id,
32693
32733
  completedViaReady: true,
32694
- providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0
32734
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
32735
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
32695
32736
  }
32696
32737
  });
32697
32738
  } catch (e) {
@@ -32734,7 +32775,9 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32734
32775
  payload: {
32735
32776
  event: args.event,
32736
32777
  nodeLabel: args.nodeLabel,
32737
- providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0
32778
+ taskId: completedTaskForLedger?.id || void 0,
32779
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
32780
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
32738
32781
  }
32739
32782
  });
32740
32783
  } catch (e) {
@@ -32849,7 +32892,8 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32849
32892
  metadataEvent: {
32850
32893
  targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId) || readNonEmptyString(payload.instanceId),
32851
32894
  providerType: readNonEmptyString(payload.providerType),
32852
- providerSessionId: readNonEmptyString(payload.providerSessionId)
32895
+ providerSessionId: readNonEmptyString(payload.providerSessionId),
32896
+ finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary)
32853
32897
  }
32854
32898
  });
32855
32899
  }
@@ -35073,6 +35117,11 @@ ${lastSnapshot}`;
35073
35117
  };
35074
35118
  }
35075
35119
  // ─── Script Execution ──────────────────────────
35120
+ invokeCliScript(script, input) {
35121
+ const hasStateFactory = typeof this.cliScripts?.createState === "function";
35122
+ const expectsStateArgument = hasStateFactory || this.scriptState !== null || script.length >= 2;
35123
+ return expectsStateArgument ? script(this.scriptState, input) : script(input);
35124
+ }
35076
35125
  runParseSession() {
35077
35126
  if (typeof this.cliScripts?.parseSession !== "function") {
35078
35127
  this.parseErrorMessage = `${this.cliType} parseSession unavailable`;
@@ -35093,7 +35142,10 @@ ${lastSnapshot}`;
35093
35142
  scope: this.currentTurnScope,
35094
35143
  runtimeSettings: this.runtimeSettings
35095
35144
  });
35096
- const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
35145
+ const session = this.invokeCliScript(
35146
+ this.cliScripts.parseSession,
35147
+ { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) }
35148
+ );
35097
35149
  this.parseErrorMessage = null;
35098
35150
  return session && typeof session === "object" ? session : null;
35099
35151
  } catch (e) {
@@ -35107,7 +35159,7 @@ ${lastSnapshot}`;
35107
35159
  if (!this.cliScripts?.detectStatus) return null;
35108
35160
  try {
35109
35161
  const screenText = this.terminalScreen.getText();
35110
- const status = this.cliScripts.detectStatus(this.scriptState, {
35162
+ const status = this.invokeCliScript(this.cliScripts.detectStatus, {
35111
35163
  tail: text.slice(-500),
35112
35164
  screenText,
35113
35165
  rawBuffer: this.accumulatedRawBuffer,
@@ -35126,7 +35178,7 @@ ${lastSnapshot}`;
35126
35178
  try {
35127
35179
  const screenText = this.terminalScreen.getText();
35128
35180
  const buffer = screenText || this.accumulatedBuffer;
35129
- return this.cliScripts.parseApproval(this.scriptState, {
35181
+ return this.invokeCliScript(this.cliScripts.parseApproval, {
35130
35182
  buffer,
35131
35183
  screenText,
35132
35184
  rawBuffer: this.accumulatedRawBuffer,
@@ -36043,6 +36095,7 @@ ${lastSnapshot}`;
36043
36095
  buildThoughtChatMessage: () => buildThoughtChatMessage,
36044
36096
  buildToolChatMessage: () => buildToolChatMessage,
36045
36097
  buildUserChatMessage: () => buildUserChatMessage,
36098
+ cancelTask: () => cancelTask,
36046
36099
  claimNextTask: () => claimNextTask,
36047
36100
  classifyChatMessageVisibility: () => classifyChatMessageVisibility,
36048
36101
  classifyHotChatSessionsForSubscriptionFlush: () => classifyHotChatSessionsForSubscriptionFlush2,
@@ -36154,6 +36207,7 @@ ${lastSnapshot}`;
36154
36207
  registerExtensionProviders: () => registerExtensionProviders,
36155
36208
  removeNode: () => removeNode,
36156
36209
  removeWorktree: () => removeWorktree,
36210
+ requeueTask: () => requeueTask,
36157
36211
  resetConfig: () => resetConfig,
36158
36212
  resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
36159
36213
  resetState: () => resetState,
@@ -54960,6 +55014,39 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
54960
55014
  return { success: false, error: e.message };
54961
55015
  }
54962
55016
  }
55017
+ case "cancel_mesh_queue_task": {
55018
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
55019
+ const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
55020
+ if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
55021
+ try {
55022
+ const { cancelTask: cancelTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
55023
+ const reason = typeof args?.reason === "string" ? args.reason : void 0;
55024
+ const task = cancelTask2(meshId, taskId, { reason });
55025
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
55026
+ return { success: true, task };
55027
+ } catch (e) {
55028
+ return { success: false, error: e.message };
55029
+ }
55030
+ }
55031
+ case "requeue_mesh_queue_task": {
55032
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
55033
+ const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
55034
+ if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
55035
+ try {
55036
+ const { requeueTask: requeueTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
55037
+ const task = requeueTask2(meshId, taskId, {
55038
+ reason: typeof args?.reason === "string" ? args.reason : void 0,
55039
+ targetNodeId: typeof args?.targetNodeId === "string" ? args.targetNodeId.trim() : void 0,
55040
+ targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : void 0,
55041
+ clearTargetNode: args?.clearTargetNode === true,
55042
+ clearTargetSession: args?.clearTargetSession !== false
55043
+ });
55044
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
55045
+ return { success: true, task };
55046
+ } catch (e) {
55047
+ return { success: false, error: e.message };
55048
+ }
55049
+ }
54963
55050
  case "add_mesh_node": {
54964
55051
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
54965
55052
  const workspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
@@ -55117,7 +55204,13 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
55117
55204
  appendLedgerEntry2(meshId, {
55118
55205
  kind: "node_removed",
55119
55206
  nodeId,
55120
- payload: { worktree: !!node?.isLocalWorktree, sessionCleanupMode }
55207
+ payload: {
55208
+ worktree: !!node?.isLocalWorktree,
55209
+ sessionCleanupMode,
55210
+ workspace: typeof node?.workspace === "string" ? node.workspace : void 0,
55211
+ daemonId: typeof node?.daemonId === "string" ? node.daemonId : void 0,
55212
+ worktreeBranch: typeof node?.worktreeBranch === "string" ? node.worktreeBranch : void 0
55213
+ }
55121
55214
  });
55122
55215
  } catch {
55123
55216
  }