@adhdev/daemon-core 0.9.82-rc.57 → 0.9.82-rc.58

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
@@ -2280,10 +2280,15 @@ function isMeshCoordinatorEvent(eventName) {
2280
2280
  return typeof eventName === "string" && MESH_COORDINATOR_EVENTS.has(eventName);
2281
2281
  }
2282
2282
  function formatCompletionMetadata(event) {
2283
+ const completionDiagnostic = event.completionDiagnostic && typeof event.completionDiagnostic === "object" ? event.completionDiagnostic : null;
2284
+ const diagnosticReason = completionDiagnostic ? readNonEmptyString(completionDiagnostic.blockReason) || "present" : "";
2285
+ const finalAssistantPresent = typeof completionDiagnostic?.finalAssistantPresent === "boolean" ? String(completionDiagnostic.finalAssistantPresent) : "";
2283
2286
  const parts = [
2284
2287
  readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
2285
2288
  readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
2286
- readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
2289
+ readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : "",
2290
+ diagnosticReason ? `completion_diagnostic=${diagnosticReason}` : "",
2291
+ finalAssistantPresent ? `final_assistant=${finalAssistantPresent}` : ""
2287
2292
  ].filter(Boolean);
2288
2293
  return parts.length > 0 ? ` (${parts.join("; ")})` : "";
2289
2294
  }
@@ -2827,6 +2832,7 @@ function injectMeshSystemMessage(components, args) {
2827
2832
  taskId: completedTaskForLedger?.id || void 0,
2828
2833
  providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
2829
2834
  finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0,
2835
+ completionDiagnostic: args.metadataEvent.completionDiagnostic && typeof args.metadataEvent.completionDiagnostic === "object" ? args.metadataEvent.completionDiagnostic : void 0,
2830
2836
  evidence: completionEvidence
2831
2837
  }
2832
2838
  });
@@ -3912,7 +3918,9 @@ function resolveCliSpawnPlan(options) {
3912
3918
  const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
3913
3919
  const binaryPath = findBinary(configuredCommand);
3914
3920
  const isWin = os10.platform() === "win32";
3915
- const allArgs = [...spawnConfig.args, ...extraArgs];
3921
+ const allArgs = [...spawnConfig.args, ...extraArgs].map(
3922
+ (arg) => typeof arg === "string" ? arg.replace(/\{\{workingDir\}\}/g, workingDir) : arg
3923
+ );
3916
3924
  let shellCmd;
3917
3925
  let shellArgs;
3918
3926
  const useShellUnix = !isWin && (!!spawnConfig.shell || !path15.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
@@ -18526,6 +18534,44 @@ var CliProviderInstance = class {
18526
18534
  const content = lastVisible ? flattenContent(lastVisible.content).trim() : "";
18527
18535
  return role === "assistant" && !!content;
18528
18536
  }
18537
+ buildCompletedFinalizationDiagnostic(args) {
18538
+ let parsed = null;
18539
+ let parseError;
18540
+ try {
18541
+ parsed = this.adapter.getScriptParsedStatus();
18542
+ } catch (error) {
18543
+ parseError = error?.message || String(error);
18544
+ }
18545
+ const visibleMessages = (Array.isArray(parsed?.messages) ? parsed.messages : []).filter((message) => isUserFacingChatMessage(message));
18546
+ const lastVisible = visibleMessages[visibleMessages.length - 1];
18547
+ const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
18548
+ const lastVisibleKind = typeof lastVisible?.kind === "string" ? lastVisible.kind : null;
18549
+ const lastVisibleContentLength = lastVisible ? flattenContent(lastVisible.content).trim().length : 0;
18550
+ return {
18551
+ providerType: this.type,
18552
+ sessionId: this.instanceId,
18553
+ providerSessionId: this.providerSessionId || null,
18554
+ workspace: this.workingDir,
18555
+ blockReason: args.blockReason,
18556
+ emittedAfterFinalizationTimeout: args.emittedAfterFinalizationTimeout,
18557
+ waitedMs: args.waitedMs,
18558
+ maxWaitMs: COMPLETED_FINALIZATION_MAX_WAIT_MS,
18559
+ adapterStatus: typeof args.latestStatus?.status === "string" ? args.latestStatus.status : null,
18560
+ latestVisibleStatus: args.latestVisibleStatus,
18561
+ parsedStatus: typeof parsed?.status === "string" ? parsed.status : parseError ? "parse_error" : "unknown",
18562
+ parseError: parseError || void 0,
18563
+ finalAssistantPresent: this.completionHasFinalAssistantMessage(parsed?.messages),
18564
+ visibleMessageCount: visibleMessages.length,
18565
+ lastVisibleRole,
18566
+ lastVisibleKind,
18567
+ lastVisibleContentLength,
18568
+ pendingStartedAt: this.generatingStartedAt || null,
18569
+ pendingFirstObservedAt: args.pending.firstObservedAt,
18570
+ pendingTimestamp: args.pending.timestamp,
18571
+ pendingDurationSec: args.pending.duration,
18572
+ previousBlockReason: args.pending.loggedBlockReason || null
18573
+ };
18574
+ }
18529
18575
  hasAdapterPendingResponse() {
18530
18576
  const adapterAny = this.adapter;
18531
18577
  if (adapterAny?.isWaitingForResponse === true) return true;
@@ -18598,7 +18644,23 @@ var CliProviderInstance = class {
18598
18644
  this.scheduleCompletedDebounceFlush(COMPLETED_FINALIZATION_RETRY_MS);
18599
18645
  return;
18600
18646
  }
18601
- LOG.warn("CLI", `[${this.type}] suppressed completed event after ${waitedMs}ms without finalized assistant turn (${blockReason})`);
18647
+ const completionDiagnostic = this.buildCompletedFinalizationDiagnostic({
18648
+ blockReason,
18649
+ latestStatus,
18650
+ latestVisibleStatus,
18651
+ waitedMs,
18652
+ pending,
18653
+ emittedAfterFinalizationTimeout: true
18654
+ });
18655
+ LOG.warn("CLI", `[${this.type}] emitting completed event after ${waitedMs}ms without finalized assistant turn (${blockReason})`);
18656
+ this.pushEvent({
18657
+ event: "agent:generating_completed",
18658
+ chatTitle: pending.chatTitle,
18659
+ duration: pending.duration,
18660
+ timestamp: pending.timestamp,
18661
+ finalSummary: extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages),
18662
+ completionDiagnostic
18663
+ });
18602
18664
  this.completedDebouncePending = null;
18603
18665
  this.completedDebounceTimer = null;
18604
18666
  this.generatingStartedAt = 0;