@adhdev/daemon-core 0.9.82-rc.173 → 0.9.82-rc.175

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
@@ -11383,13 +11383,15 @@ function executeJsonl(src, input) {
11383
11383
  try {
11384
11384
  stat2 = fs13.statSync(resolved);
11385
11385
  } catch {
11386
- return null;
11387
11386
  }
11388
- if (stat2.isFile()) {
11387
+ if (stat2 && stat2.isFile()) {
11389
11388
  sourcePath = resolved;
11390
- } else if (stat2.isDirectory()) {
11389
+ } else if (stat2 && stat2.isDirectory()) {
11391
11390
  sourcePath = newestRecentFile(resolved, filePat, windowMs, sessionFloor);
11392
11391
  }
11392
+ if (!sourcePath && hasDateTemplateSegment(src.path)) {
11393
+ sourcePath = newestRecentFileAcrossDateWindow(src.path, input, filePat, windowMs, sessionFloor);
11394
+ }
11393
11395
  }
11394
11396
  if (!sourcePath) return null;
11395
11397
  const mtime = safeMtimeMs(sourcePath);
@@ -11612,6 +11614,69 @@ function newestRecentFileAcrossGlob(template, pattern, windowMs, sessionFloorMs
11612
11614
  }
11613
11615
  return best ? best.p : null;
11614
11616
  }
11617
+ function hasDateTemplateSegment(template) {
11618
+ return /\{yyyy\}|\{mm\}|\{dd\}/.test(template);
11619
+ }
11620
+ function newestRecentFileAcrossDateWindow(template, input, pattern, windowMs, sessionFloorMs) {
11621
+ const cutoff = Math.max(Date.now() - windowMs, sessionFloorMs);
11622
+ let best = null;
11623
+ for (let dayOffset = 0; dayOffset < 3; dayOffset += 1) {
11624
+ const dayMs = Date.now() - dayOffset * 24 * 60 * 60 * 1e3;
11625
+ const dayInput = { ...input, sessionStartedAtMs: sessionFloorMs };
11626
+ const resolved = expandPathForDate(template, dayInput, new Date(dayMs));
11627
+ if (!resolved) continue;
11628
+ let entries;
11629
+ try {
11630
+ entries = fs13.readdirSync(resolved, { withFileTypes: true });
11631
+ } catch {
11632
+ continue;
11633
+ }
11634
+ for (const e of entries) {
11635
+ if (!e.isFile() || !pattern.test(e.name)) continue;
11636
+ const p = path25.join(resolved, e.name);
11637
+ const mtime = safeMtimeMs(p);
11638
+ if (mtime < cutoff) continue;
11639
+ if (!best || mtime > best.mtime) best = { p, mtime };
11640
+ }
11641
+ }
11642
+ return best ? best.p : null;
11643
+ }
11644
+ function expandPathForDate(template, input, day) {
11645
+ if (!template) return null;
11646
+ let out = template;
11647
+ if (out.startsWith("~/") || out === "~") {
11648
+ out = path25.join(os18.homedir(), out.slice(2));
11649
+ }
11650
+ out = out.replace(/\$\{([A-Z_][A-Z0-9_]*)(?::-(.*?))?\}/g, (_m, name, fallback) => {
11651
+ const v = input.envOverrides?.[name] ?? process.env[name];
11652
+ return v != null && v !== "" ? v : fallback ?? "";
11653
+ });
11654
+ if (out.startsWith("~/")) out = path25.join(os18.homedir(), out.slice(2));
11655
+ const workspaceRaw = input.workspace ?? "";
11656
+ let workspaceResolved = workspaceRaw;
11657
+ if (workspaceRaw) {
11658
+ try {
11659
+ workspaceResolved = fs13.realpathSync(workspaceRaw);
11660
+ } catch {
11661
+ }
11662
+ }
11663
+ const vars = {
11664
+ cwd: workspaceResolved,
11665
+ cwd_dashed: workspaceResolved.replace(/\//g, "-"),
11666
+ session_id: input.providerSessionId || input.sessionId || input.historySessionId || "",
11667
+ yyyy: String(day.getUTCFullYear()),
11668
+ mm: String(day.getUTCMonth() + 1).padStart(2, "0"),
11669
+ dd: String(day.getUTCDate()).padStart(2, "0")
11670
+ };
11671
+ let missing = false;
11672
+ out = out.replace(/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g, (_m, name) => {
11673
+ const v = vars[name] ?? "";
11674
+ if (!v) missing = true;
11675
+ return v;
11676
+ });
11677
+ if (missing) return null;
11678
+ return out;
11679
+ }
11615
11680
  function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
11616
11681
  let entries;
11617
11682
  try {
@@ -27336,6 +27401,18 @@ function interpolate(template, state, sections) {
27336
27401
  init_loader();
27337
27402
  var STARTUP_GRACE_MS = 2500;
27338
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
+ }
27339
27416
  var SpecDriver = class {
27340
27417
  constructor(opts) {
27341
27418
  this.opts = opts;
@@ -27563,7 +27640,7 @@ var SpecDriver = class {
27563
27640
  actuallySendMessage(text) {
27564
27641
  const sm = this.spec.send_message;
27565
27642
  const perChar = sm.delay_ms_per_char ?? 0;
27566
- const beforeSubmit = sm.delay_ms_before_submit ?? 0;
27643
+ const beforeSubmit = resolveSubmitDelayMs(sm.delay_ms_before_submit, text);
27567
27644
  if (perChar === 0) {
27568
27645
  this.adapter.send_keys(text);
27569
27646
  if (beforeSubmit > 0) setTimeout(() => this.adapter.send_keys(sm.submit_key), beforeSubmit);
@@ -28713,6 +28790,50 @@ var CliProviderInstance = class {
28713
28790
  if (looksLikeActiveApprovalPromptText(content)) return false;
28714
28791
  return true;
28715
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
+ }
28716
28837
  buildCompletedFinalizationDiagnostic(args) {
28717
28838
  let parsed = null;
28718
28839
  let parseError;
@@ -28721,7 +28842,8 @@ var CliProviderInstance = class {
28721
28842
  } catch (error) {
28722
28843
  parseError = error?.message || String(error);
28723
28844
  }
28724
- 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));
28725
28847
  const lastVisible = visibleMessages[visibleMessages.length - 1];
28726
28848
  const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
28727
28849
  const lastVisibleKind = typeof lastVisible?.kind === "string" ? lastVisible.kind : null;
@@ -28739,7 +28861,8 @@ var CliProviderInstance = class {
28739
28861
  latestVisibleStatus: args.latestVisibleStatus,
28740
28862
  parsedStatus: typeof parsed?.status === "string" ? parsed.status : parseError ? "parse_error" : "unknown",
28741
28863
  parseError: parseError || void 0,
28742
- finalAssistantPresent: this.completionHasFinalAssistantMessage(parsed?.messages),
28864
+ finalAssistantPresent: evidence.present,
28865
+ finalAssistantEvidenceSource: evidence.source,
28743
28866
  visibleMessageCount: visibleMessages.length,
28744
28867
  lastVisibleRole,
28745
28868
  lastVisibleKind,
@@ -28802,8 +28925,21 @@ var CliProviderInstance = class {
28802
28925
  }
28803
28926
  if (parsed?.activeModal || parsed?.modal) return { reason: "parsed_modal_active", terminal: true };
28804
28927
  const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
28805
- if (!adapterOwnsMessagesElsewhere && !this.completionHasFinalAssistantMessage(parsed?.messages)) {
28806
- 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
+ }
28807
28943
  }
28808
28944
  try {
28809
28945
  const screenText = typeof this.adapter.getScreenText === "function" ? String(this.adapter.getScreenText() || "") : "";
@@ -28862,7 +28998,7 @@ var CliProviderInstance = class {
28862
28998
  chatTitle: pending.chatTitle,
28863
28999
  duration: pending.duration,
28864
29000
  timestamp: pending.timestamp,
28865
- finalSummary: blockReason.startsWith("parsed_status:") ? "" : extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages),
29001
+ finalSummary: blockReason.startsWith("parsed_status:") ? "" : this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages),
28866
29002
  completionDiagnostic
28867
29003
  });
28868
29004
  this.completedDebouncePending = null;
@@ -28877,7 +29013,7 @@ var CliProviderInstance = class {
28877
29013
  chatTitle: pending.chatTitle,
28878
29014
  duration: pending.duration,
28879
29015
  timestamp: pending.timestamp,
28880
- finalSummary: extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages)
29016
+ finalSummary: this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages)
28881
29017
  });
28882
29018
  this.completedDebouncePending = null;
28883
29019
  this.completedDebounceTimer = null;
@@ -29010,11 +29146,15 @@ var CliProviderInstance = class {
29010
29146
  this.generatingDebouncePending = null;
29011
29147
  this.generatingStartedAt = 0;
29012
29148
  let shortFinalSummary;
29149
+ let shortEvidenceSource = "unavailable";
29013
29150
  try {
29014
- 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);
29015
29155
  } catch {
29016
29156
  }
29017
- if (this.provider.requiresFinalAssistantBeforeIdle === true && !shortFinalSummary) {
29157
+ if ((this.provider.requiresFinalAssistantBeforeIdle === true || shortEvidenceSource === "external-native") && !shortFinalSummary) {
29018
29158
  LOG.info("CLI", `[${this.type}] suppressed short completion without final assistant evidence`);
29019
29159
  } else {
29020
29160
  this.pushEvent({
@@ -29025,7 +29165,8 @@ var CliProviderInstance = class {
29025
29165
  finalSummary: shortFinalSummary,
29026
29166
  completionDiagnostic: {
29027
29167
  reason: "short_generating_suppressed",
29028
- shortDurationMs
29168
+ shortDurationMs,
29169
+ finalAssistantEvidenceSource: shortEvidenceSource
29029
29170
  }
29030
29171
  });
29031
29172
  }