@adhdev/daemon-core 0.9.82-rc.174 → 0.9.82-rc.176

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
@@ -27401,6 +27401,18 @@ function interpolate(template, state, sections) {
27401
27401
  init_loader();
27402
27402
  var STARTUP_GRACE_MS = 2500;
27403
27403
  var BUSY_HOLD_MS = 6e3;
27404
+ var SUBMIT_DELAY_FLOOR_MS = 200;
27405
+ function countNewlines(s) {
27406
+ let n = 0;
27407
+ for (let i = 0; i < s.length; i += 1) if (s.charCodeAt(i) === 10) n += 1;
27408
+ return n;
27409
+ }
27410
+ function resolveSubmitDelayMs(specBeforeSubmit, text) {
27411
+ const lines = countNewlines(text);
27412
+ const linesBonus = Math.min(800, lines * 80);
27413
+ const spec = typeof specBeforeSubmit === "number" && specBeforeSubmit > 0 ? specBeforeSubmit : 0;
27414
+ return Math.max(spec, SUBMIT_DELAY_FLOOR_MS + linesBonus);
27415
+ }
27404
27416
  var SpecDriver = class {
27405
27417
  constructor(opts) {
27406
27418
  this.opts = opts;
@@ -27628,7 +27640,7 @@ var SpecDriver = class {
27628
27640
  actuallySendMessage(text) {
27629
27641
  const sm = this.spec.send_message;
27630
27642
  const perChar = sm.delay_ms_per_char ?? 0;
27631
- const beforeSubmit = sm.delay_ms_before_submit ?? 0;
27643
+ const beforeSubmit = resolveSubmitDelayMs(sm.delay_ms_before_submit, text);
27632
27644
  if (perChar === 0) {
27633
27645
  this.adapter.send_keys(text);
27634
27646
  if (beforeSubmit > 0) setTimeout(() => this.adapter.send_keys(sm.submit_key), beforeSubmit);
@@ -28778,6 +28790,50 @@ var CliProviderInstance = class {
28778
28790
  if (looksLikeActiveApprovalPromptText(content)) return false;
28779
28791
  return true;
28780
28792
  }
28793
+ readExternalCompletionMessages() {
28794
+ const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
28795
+ if (!adapterOwnsMessagesElsewhere) return null;
28796
+ if (!this.providerSessionId) return null;
28797
+ if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
28798
+ const restoredHistory = readProviderChatHistory(this.type, {
28799
+ canonicalHistory: this.provider.nativeHistory,
28800
+ historySessionId: this.providerSessionId,
28801
+ workspace: this.workingDir,
28802
+ offset: 0,
28803
+ limit: Number.MAX_SAFE_INTEGER,
28804
+ historyBehavior: this.provider.historyBehavior,
28805
+ scripts: this.provider.scripts,
28806
+ sessionStartedAtMs: this.startedAt
28807
+ });
28808
+ if (restoredHistory.source !== "provider-native") return null;
28809
+ return restoredHistory.messages;
28810
+ }
28811
+ completionFinalAssistantEvidence(parsedMessages) {
28812
+ if (this.completionHasFinalAssistantMessage(parsedMessages)) {
28813
+ return {
28814
+ present: true,
28815
+ messages: Array.isArray(parsedMessages) ? parsedMessages : [],
28816
+ source: "parsed"
28817
+ };
28818
+ }
28819
+ const externalMessages = this.readExternalCompletionMessages();
28820
+ if (externalMessages) {
28821
+ return {
28822
+ present: this.completionHasFinalAssistantMessage(externalMessages),
28823
+ messages: externalMessages,
28824
+ source: "external-native"
28825
+ };
28826
+ }
28827
+ return {
28828
+ present: false,
28829
+ messages: Array.isArray(parsedMessages) ? parsedMessages : [],
28830
+ source: "unavailable"
28831
+ };
28832
+ }
28833
+ completionFinalSummary(parsedMessages) {
28834
+ const evidence = this.completionFinalAssistantEvidence(parsedMessages);
28835
+ return extractFinalSummaryFromMessages(evidence.messages);
28836
+ }
28781
28837
  buildCompletedFinalizationDiagnostic(args) {
28782
28838
  let parsed = null;
28783
28839
  let parseError;
@@ -28786,7 +28842,8 @@ var CliProviderInstance = class {
28786
28842
  } catch (error) {
28787
28843
  parseError = error?.message || String(error);
28788
28844
  }
28789
- const visibleMessages = (Array.isArray(parsed?.messages) ? parsed.messages : []).filter((message) => isUserFacingChatMessage(message));
28845
+ const evidence = this.completionFinalAssistantEvidence(parsed?.messages);
28846
+ const visibleMessages = (Array.isArray(evidence.messages) ? evidence.messages : []).filter((message) => isUserFacingChatMessage(message));
28790
28847
  const lastVisible = visibleMessages[visibleMessages.length - 1];
28791
28848
  const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
28792
28849
  const lastVisibleKind = typeof lastVisible?.kind === "string" ? lastVisible.kind : null;
@@ -28804,7 +28861,8 @@ var CliProviderInstance = class {
28804
28861
  latestVisibleStatus: args.latestVisibleStatus,
28805
28862
  parsedStatus: typeof parsed?.status === "string" ? parsed.status : parseError ? "parse_error" : "unknown",
28806
28863
  parseError: parseError || void 0,
28807
- finalAssistantPresent: this.completionHasFinalAssistantMessage(parsed?.messages),
28864
+ finalAssistantPresent: evidence.present,
28865
+ finalAssistantEvidenceSource: evidence.source,
28808
28866
  visibleMessageCount: visibleMessages.length,
28809
28867
  lastVisibleRole,
28810
28868
  lastVisibleKind,
@@ -28867,8 +28925,21 @@ var CliProviderInstance = class {
28867
28925
  }
28868
28926
  if (parsed?.activeModal || parsed?.modal) return { reason: "parsed_modal_active", terminal: true };
28869
28927
  const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
28870
- if (!adapterOwnsMessagesElsewhere && !this.completionHasFinalAssistantMessage(parsed?.messages)) {
28871
- return { reason: "missing_final_assistant" };
28928
+ const finalAssistantEvidence = this.completionFinalAssistantEvidence(parsed?.messages);
28929
+ if (!finalAssistantEvidence.present) {
28930
+ if (adapterOwnsMessagesElsewhere) {
28931
+ if (finalAssistantEvidence.source === "external-native") {
28932
+ return { reason: "missing_final_assistant", terminal: true };
28933
+ }
28934
+ if (this.provider.requiresFinalAssistantBeforeIdle === true) {
28935
+ return { reason: "missing_final_assistant", terminal: true };
28936
+ }
28937
+ } else {
28938
+ return {
28939
+ reason: "missing_final_assistant",
28940
+ terminal: this.provider.requiresFinalAssistantBeforeIdle === true
28941
+ };
28942
+ }
28872
28943
  }
28873
28944
  try {
28874
28945
  const screenText = typeof this.adapter.getScreenText === "function" ? String(this.adapter.getScreenText() || "") : "";
@@ -28927,7 +28998,7 @@ var CliProviderInstance = class {
28927
28998
  chatTitle: pending.chatTitle,
28928
28999
  duration: pending.duration,
28929
29000
  timestamp: pending.timestamp,
28930
- finalSummary: blockReason.startsWith("parsed_status:") ? "" : extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages),
29001
+ finalSummary: blockReason.startsWith("parsed_status:") ? "" : this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages),
28931
29002
  completionDiagnostic
28932
29003
  });
28933
29004
  this.completedDebouncePending = null;
@@ -28942,7 +29013,7 @@ var CliProviderInstance = class {
28942
29013
  chatTitle: pending.chatTitle,
28943
29014
  duration: pending.duration,
28944
29015
  timestamp: pending.timestamp,
28945
- finalSummary: extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages)
29016
+ finalSummary: this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages)
28946
29017
  });
28947
29018
  this.completedDebouncePending = null;
28948
29019
  this.completedDebounceTimer = null;
@@ -29075,11 +29146,15 @@ var CliProviderInstance = class {
29075
29146
  this.generatingDebouncePending = null;
29076
29147
  this.generatingStartedAt = 0;
29077
29148
  let shortFinalSummary;
29149
+ let shortEvidenceSource = "unavailable";
29078
29150
  try {
29079
- shortFinalSummary = extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages);
29151
+ const parsedMessages = this.adapter?.getScriptParsedStatus()?.messages;
29152
+ const evidence = this.completionFinalAssistantEvidence(parsedMessages);
29153
+ shortEvidenceSource = evidence.source;
29154
+ shortFinalSummary = extractFinalSummaryFromMessages(evidence.messages);
29080
29155
  } catch {
29081
29156
  }
29082
- if (this.provider.requiresFinalAssistantBeforeIdle === true && !shortFinalSummary) {
29157
+ if ((this.provider.requiresFinalAssistantBeforeIdle === true || shortEvidenceSource === "external-native") && !shortFinalSummary) {
29083
29158
  LOG.info("CLI", `[${this.type}] suppressed short completion without final assistant evidence`);
29084
29159
  } else {
29085
29160
  this.pushEvent({
@@ -29090,7 +29165,8 @@ var CliProviderInstance = class {
29090
29165
  finalSummary: shortFinalSummary,
29091
29166
  completionDiagnostic: {
29092
29167
  reason: "short_generating_suppressed",
29093
- shortDurationMs
29168
+ shortDurationMs,
29169
+ finalAssistantEvidenceSource: shortEvidenceSource
29094
29170
  }
29095
29171
  });
29096
29172
  }