@adhdev/daemon-core 0.9.82-rc.133 → 0.9.82-rc.135

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
@@ -2819,14 +2819,26 @@ function findRecentTerminalLedgerEvidence(args) {
2819
2819
  const entry = entries[i];
2820
2820
  if (entry.kind !== "task_completed" && entry.kind !== "task_failed" && entry.kind !== "task_stalled") continue;
2821
2821
  if (args.sessionId && entry.sessionId === args.sessionId) {
2822
- return { kind: entry.kind, payload: entry.payload || {}, timestamp: entry.timestamp };
2822
+ return { id: entry.id, kind: entry.kind, payload: entry.payload || {}, timestamp: entry.timestamp };
2823
2823
  }
2824
2824
  if (!args.sessionId && args.nodeId && entry.nodeId === args.nodeId) {
2825
- return { kind: entry.kind, payload: entry.payload || {}, timestamp: entry.timestamp };
2825
+ return { id: entry.id, kind: entry.kind, payload: entry.payload || {}, timestamp: entry.timestamp };
2826
2826
  }
2827
2827
  }
2828
2828
  return null;
2829
2829
  }
2830
+ function hasDispatchAfterTerminal(meshId, sessionId, terminalId) {
2831
+ const entries = readLedgerEntries(meshId);
2832
+ let pastTerminal = false;
2833
+ for (const entry of entries) {
2834
+ if (!pastTerminal) {
2835
+ if (entry.id === terminalId) pastTerminal = true;
2836
+ continue;
2837
+ }
2838
+ if (entry.kind === "task_dispatched" && entry.sessionId === sessionId) return true;
2839
+ }
2840
+ return false;
2841
+ }
2830
2842
  function buildLongGeneratingCompletionReconciliation(args) {
2831
2843
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
2832
2844
  const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
@@ -3331,13 +3343,16 @@ function injectMeshSystemMessage(components, args) {
3331
3343
  nodeId: eventNodeId || void 0
3332
3344
  });
3333
3345
  if (terminal?.kind === "task_completed" && !sessionHasActiveAssignment(args.meshId, eventSessionId)) {
3334
- const terminalProviderSessionId = readNonEmptyString2(terminal.payload.providerSessionId);
3335
- const terminalFinalSummary = readNonEmptyString2(terminal.payload.finalSummary);
3336
- const eventProviderSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId);
3337
- const eventFinalSummary = readNonEmptyString2(args.metadataEvent.finalSummary);
3338
- if (terminalProviderSessionId && terminalProviderSessionId === eventProviderSessionId || terminalFinalSummary && terminalFinalSummary === eventFinalSummary || args.metadataEvent.source === "long_generating_reconciliation") {
3339
- LOG.info("MeshEvents", `Suppressed duplicate completion with existing terminal ledger evidence for mesh ${args.meshId} session ${eventSessionId}`);
3340
- return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true, terminalLedgerEvidence: true };
3346
+ const newDispatchAfterTerminal = hasDispatchAfterTerminal(args.meshId, eventSessionId, terminal.id);
3347
+ if (!newDispatchAfterTerminal) {
3348
+ const terminalProviderSessionId = readNonEmptyString2(terminal.payload.providerSessionId);
3349
+ const terminalFinalSummary = readNonEmptyString2(terminal.payload.finalSummary);
3350
+ const eventProviderSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId);
3351
+ const eventFinalSummary = readNonEmptyString2(args.metadataEvent.finalSummary);
3352
+ if (terminalProviderSessionId && terminalProviderSessionId === eventProviderSessionId || terminalFinalSummary && terminalFinalSummary === eventFinalSummary || args.metadataEvent.source === "long_generating_reconciliation") {
3353
+ LOG.info("MeshEvents", `Suppressed duplicate completion with existing terminal ledger evidence for mesh ${args.meshId} session ${eventSessionId}`);
3354
+ return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true, terminalLedgerEvidence: true };
3355
+ }
3341
3356
  }
3342
3357
  }
3343
3358
  const duplicateCompletion = isDuplicateMeshCompletionEvent({
@@ -21352,7 +21367,10 @@ var CliProviderInstance = class {
21352
21367
  if (!isCliGeneratingLikeStatus(parsedRawStatus)) return false;
21353
21368
  if (adapterRawStatus !== "idle") return false;
21354
21369
  if (hasNonEmptyCliModalButtons(parsedStatus?.activeModal ?? parsedStatus?.modal)) return false;
21355
- return !this.hasAdapterPendingResponse();
21370
+ if (this.hasAdapterPendingResponse()) return false;
21371
+ const adapterAny = this.adapter;
21372
+ if (typeof adapterAny?.responseBuffer === "string" && adapterAny.responseBuffer.trim()) return false;
21373
+ return true;
21356
21374
  }
21357
21375
  getCompletedFinalizationBlock(latestVisibleStatus) {
21358
21376
  if (latestVisibleStatus !== "idle") return { reason: `status:${latestVisibleStatus}`, terminal: true };
@@ -21550,13 +21568,30 @@ var CliProviderInstance = class {
21550
21568
  } else if (newStatus === "idle" && (this.lastStatus === "generating" || this.lastStatus === "waiting_approval")) {
21551
21569
  const duration = this.generatingStartedAt ? Math.round((now - this.generatingStartedAt) / 1e3) : 0;
21552
21570
  if (this.generatingDebouncePending) {
21553
- LOG.info("CLI", `[${this.type}] suppressed short generating (${now - this.generatingStartedAt}ms)`);
21571
+ const shortDurationMs = this.generatingStartedAt ? now - this.generatingStartedAt : 0;
21572
+ LOG.info("CLI", `[${this.type}] suppressed short generating (${shortDurationMs}ms)`);
21554
21573
  if (this.generatingDebounceTimer) {
21555
21574
  clearTimeout(this.generatingDebounceTimer);
21556
21575
  this.generatingDebounceTimer = null;
21557
21576
  }
21558
21577
  this.generatingDebouncePending = null;
21559
21578
  this.generatingStartedAt = 0;
21579
+ let shortFinalSummary;
21580
+ try {
21581
+ shortFinalSummary = extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages);
21582
+ } catch {
21583
+ }
21584
+ this.pushEvent({
21585
+ event: "agent:generating_completed",
21586
+ chatTitle,
21587
+ duration: 0,
21588
+ timestamp: now,
21589
+ finalSummary: shortFinalSummary,
21590
+ completionDiagnostic: {
21591
+ reason: "short_generating_suppressed",
21592
+ shortDurationMs
21593
+ }
21594
+ });
21560
21595
  } else {
21561
21596
  this.completedDebouncePending = { chatTitle, duration, timestamp: now, firstObservedAt: now };
21562
21597
  this.scheduleCompletedDebounceFlush(3e3);