@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.js +154 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -13
- package/dist/index.mjs.map +1 -1
- package/dist/providers/cli-provider-instance.d.ts +3 -0
- package/dist/providers/spec/driver.d.ts +10 -0
- package/package.json +1 -1
- package/src/providers/cli-provider-instance.ts +90 -13
- package/src/providers/spec/driver.ts +39 -1
- package/src/providers/spec/native-history-executor.ts +86 -3
package/dist/index.js
CHANGED
|
@@ -11385,13 +11385,15 @@ function executeJsonl(src, input) {
|
|
|
11385
11385
|
try {
|
|
11386
11386
|
stat2 = fs13.statSync(resolved);
|
|
11387
11387
|
} catch {
|
|
11388
|
-
return null;
|
|
11389
11388
|
}
|
|
11390
|
-
if (stat2.isFile()) {
|
|
11389
|
+
if (stat2 && stat2.isFile()) {
|
|
11391
11390
|
sourcePath = resolved;
|
|
11392
|
-
} else if (stat2.isDirectory()) {
|
|
11391
|
+
} else if (stat2 && stat2.isDirectory()) {
|
|
11393
11392
|
sourcePath = newestRecentFile(resolved, filePat, windowMs, sessionFloor);
|
|
11394
11393
|
}
|
|
11394
|
+
if (!sourcePath && hasDateTemplateSegment(src.path)) {
|
|
11395
|
+
sourcePath = newestRecentFileAcrossDateWindow(src.path, input, filePat, windowMs, sessionFloor);
|
|
11396
|
+
}
|
|
11395
11397
|
}
|
|
11396
11398
|
if (!sourcePath) return null;
|
|
11397
11399
|
const mtime = safeMtimeMs(sourcePath);
|
|
@@ -11614,6 +11616,69 @@ function newestRecentFileAcrossGlob(template, pattern, windowMs, sessionFloorMs
|
|
|
11614
11616
|
}
|
|
11615
11617
|
return best ? best.p : null;
|
|
11616
11618
|
}
|
|
11619
|
+
function hasDateTemplateSegment(template) {
|
|
11620
|
+
return /\{yyyy\}|\{mm\}|\{dd\}/.test(template);
|
|
11621
|
+
}
|
|
11622
|
+
function newestRecentFileAcrossDateWindow(template, input, pattern, windowMs, sessionFloorMs) {
|
|
11623
|
+
const cutoff = Math.max(Date.now() - windowMs, sessionFloorMs);
|
|
11624
|
+
let best = null;
|
|
11625
|
+
for (let dayOffset = 0; dayOffset < 3; dayOffset += 1) {
|
|
11626
|
+
const dayMs = Date.now() - dayOffset * 24 * 60 * 60 * 1e3;
|
|
11627
|
+
const dayInput = { ...input, sessionStartedAtMs: sessionFloorMs };
|
|
11628
|
+
const resolved = expandPathForDate(template, dayInput, new Date(dayMs));
|
|
11629
|
+
if (!resolved) continue;
|
|
11630
|
+
let entries;
|
|
11631
|
+
try {
|
|
11632
|
+
entries = fs13.readdirSync(resolved, { withFileTypes: true });
|
|
11633
|
+
} catch {
|
|
11634
|
+
continue;
|
|
11635
|
+
}
|
|
11636
|
+
for (const e of entries) {
|
|
11637
|
+
if (!e.isFile() || !pattern.test(e.name)) continue;
|
|
11638
|
+
const p = path25.join(resolved, e.name);
|
|
11639
|
+
const mtime = safeMtimeMs(p);
|
|
11640
|
+
if (mtime < cutoff) continue;
|
|
11641
|
+
if (!best || mtime > best.mtime) best = { p, mtime };
|
|
11642
|
+
}
|
|
11643
|
+
}
|
|
11644
|
+
return best ? best.p : null;
|
|
11645
|
+
}
|
|
11646
|
+
function expandPathForDate(template, input, day) {
|
|
11647
|
+
if (!template) return null;
|
|
11648
|
+
let out = template;
|
|
11649
|
+
if (out.startsWith("~/") || out === "~") {
|
|
11650
|
+
out = path25.join(os18.homedir(), out.slice(2));
|
|
11651
|
+
}
|
|
11652
|
+
out = out.replace(/\$\{([A-Z_][A-Z0-9_]*)(?::-(.*?))?\}/g, (_m, name, fallback) => {
|
|
11653
|
+
const v = input.envOverrides?.[name] ?? process.env[name];
|
|
11654
|
+
return v != null && v !== "" ? v : fallback ?? "";
|
|
11655
|
+
});
|
|
11656
|
+
if (out.startsWith("~/")) out = path25.join(os18.homedir(), out.slice(2));
|
|
11657
|
+
const workspaceRaw = input.workspace ?? "";
|
|
11658
|
+
let workspaceResolved = workspaceRaw;
|
|
11659
|
+
if (workspaceRaw) {
|
|
11660
|
+
try {
|
|
11661
|
+
workspaceResolved = fs13.realpathSync(workspaceRaw);
|
|
11662
|
+
} catch {
|
|
11663
|
+
}
|
|
11664
|
+
}
|
|
11665
|
+
const vars = {
|
|
11666
|
+
cwd: workspaceResolved,
|
|
11667
|
+
cwd_dashed: workspaceResolved.replace(/\//g, "-"),
|
|
11668
|
+
session_id: input.providerSessionId || input.sessionId || input.historySessionId || "",
|
|
11669
|
+
yyyy: String(day.getUTCFullYear()),
|
|
11670
|
+
mm: String(day.getUTCMonth() + 1).padStart(2, "0"),
|
|
11671
|
+
dd: String(day.getUTCDate()).padStart(2, "0")
|
|
11672
|
+
};
|
|
11673
|
+
let missing = false;
|
|
11674
|
+
out = out.replace(/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g, (_m, name) => {
|
|
11675
|
+
const v = vars[name] ?? "";
|
|
11676
|
+
if (!v) missing = true;
|
|
11677
|
+
return v;
|
|
11678
|
+
});
|
|
11679
|
+
if (missing) return null;
|
|
11680
|
+
return out;
|
|
11681
|
+
}
|
|
11617
11682
|
function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
|
|
11618
11683
|
let entries;
|
|
11619
11684
|
try {
|
|
@@ -27646,6 +27711,18 @@ function interpolate(template, state, sections) {
|
|
|
27646
27711
|
init_loader();
|
|
27647
27712
|
var STARTUP_GRACE_MS = 2500;
|
|
27648
27713
|
var BUSY_HOLD_MS = 6e3;
|
|
27714
|
+
var SUBMIT_DELAY_FLOOR_MS = 200;
|
|
27715
|
+
function countNewlines(s) {
|
|
27716
|
+
let n = 0;
|
|
27717
|
+
for (let i = 0; i < s.length; i += 1) if (s.charCodeAt(i) === 10) n += 1;
|
|
27718
|
+
return n;
|
|
27719
|
+
}
|
|
27720
|
+
function resolveSubmitDelayMs(specBeforeSubmit, text) {
|
|
27721
|
+
const lines = countNewlines(text);
|
|
27722
|
+
const linesBonus = Math.min(800, lines * 80);
|
|
27723
|
+
const spec = typeof specBeforeSubmit === "number" && specBeforeSubmit > 0 ? specBeforeSubmit : 0;
|
|
27724
|
+
return Math.max(spec, SUBMIT_DELAY_FLOOR_MS + linesBonus);
|
|
27725
|
+
}
|
|
27649
27726
|
var SpecDriver = class {
|
|
27650
27727
|
constructor(opts) {
|
|
27651
27728
|
this.opts = opts;
|
|
@@ -27873,7 +27950,7 @@ var SpecDriver = class {
|
|
|
27873
27950
|
actuallySendMessage(text) {
|
|
27874
27951
|
const sm = this.spec.send_message;
|
|
27875
27952
|
const perChar = sm.delay_ms_per_char ?? 0;
|
|
27876
|
-
const beforeSubmit = sm.delay_ms_before_submit
|
|
27953
|
+
const beforeSubmit = resolveSubmitDelayMs(sm.delay_ms_before_submit, text);
|
|
27877
27954
|
if (perChar === 0) {
|
|
27878
27955
|
this.adapter.send_keys(text);
|
|
27879
27956
|
if (beforeSubmit > 0) setTimeout(() => this.adapter.send_keys(sm.submit_key), beforeSubmit);
|
|
@@ -29023,6 +29100,50 @@ var CliProviderInstance = class {
|
|
|
29023
29100
|
if (looksLikeActiveApprovalPromptText(content)) return false;
|
|
29024
29101
|
return true;
|
|
29025
29102
|
}
|
|
29103
|
+
readExternalCompletionMessages() {
|
|
29104
|
+
const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
|
|
29105
|
+
if (!adapterOwnsMessagesElsewhere) return null;
|
|
29106
|
+
if (!this.providerSessionId) return null;
|
|
29107
|
+
if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
|
|
29108
|
+
const restoredHistory = readProviderChatHistory(this.type, {
|
|
29109
|
+
canonicalHistory: this.provider.nativeHistory,
|
|
29110
|
+
historySessionId: this.providerSessionId,
|
|
29111
|
+
workspace: this.workingDir,
|
|
29112
|
+
offset: 0,
|
|
29113
|
+
limit: Number.MAX_SAFE_INTEGER,
|
|
29114
|
+
historyBehavior: this.provider.historyBehavior,
|
|
29115
|
+
scripts: this.provider.scripts,
|
|
29116
|
+
sessionStartedAtMs: this.startedAt
|
|
29117
|
+
});
|
|
29118
|
+
if (restoredHistory.source !== "provider-native") return null;
|
|
29119
|
+
return restoredHistory.messages;
|
|
29120
|
+
}
|
|
29121
|
+
completionFinalAssistantEvidence(parsedMessages) {
|
|
29122
|
+
if (this.completionHasFinalAssistantMessage(parsedMessages)) {
|
|
29123
|
+
return {
|
|
29124
|
+
present: true,
|
|
29125
|
+
messages: Array.isArray(parsedMessages) ? parsedMessages : [],
|
|
29126
|
+
source: "parsed"
|
|
29127
|
+
};
|
|
29128
|
+
}
|
|
29129
|
+
const externalMessages = this.readExternalCompletionMessages();
|
|
29130
|
+
if (externalMessages) {
|
|
29131
|
+
return {
|
|
29132
|
+
present: this.completionHasFinalAssistantMessage(externalMessages),
|
|
29133
|
+
messages: externalMessages,
|
|
29134
|
+
source: "external-native"
|
|
29135
|
+
};
|
|
29136
|
+
}
|
|
29137
|
+
return {
|
|
29138
|
+
present: false,
|
|
29139
|
+
messages: Array.isArray(parsedMessages) ? parsedMessages : [],
|
|
29140
|
+
source: "unavailable"
|
|
29141
|
+
};
|
|
29142
|
+
}
|
|
29143
|
+
completionFinalSummary(parsedMessages) {
|
|
29144
|
+
const evidence = this.completionFinalAssistantEvidence(parsedMessages);
|
|
29145
|
+
return extractFinalSummaryFromMessages(evidence.messages);
|
|
29146
|
+
}
|
|
29026
29147
|
buildCompletedFinalizationDiagnostic(args) {
|
|
29027
29148
|
let parsed = null;
|
|
29028
29149
|
let parseError;
|
|
@@ -29031,7 +29152,8 @@ var CliProviderInstance = class {
|
|
|
29031
29152
|
} catch (error) {
|
|
29032
29153
|
parseError = error?.message || String(error);
|
|
29033
29154
|
}
|
|
29034
|
-
const
|
|
29155
|
+
const evidence = this.completionFinalAssistantEvidence(parsed?.messages);
|
|
29156
|
+
const visibleMessages = (Array.isArray(evidence.messages) ? evidence.messages : []).filter((message) => isUserFacingChatMessage(message));
|
|
29035
29157
|
const lastVisible = visibleMessages[visibleMessages.length - 1];
|
|
29036
29158
|
const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
|
|
29037
29159
|
const lastVisibleKind = typeof lastVisible?.kind === "string" ? lastVisible.kind : null;
|
|
@@ -29049,7 +29171,8 @@ var CliProviderInstance = class {
|
|
|
29049
29171
|
latestVisibleStatus: args.latestVisibleStatus,
|
|
29050
29172
|
parsedStatus: typeof parsed?.status === "string" ? parsed.status : parseError ? "parse_error" : "unknown",
|
|
29051
29173
|
parseError: parseError || void 0,
|
|
29052
|
-
finalAssistantPresent:
|
|
29174
|
+
finalAssistantPresent: evidence.present,
|
|
29175
|
+
finalAssistantEvidenceSource: evidence.source,
|
|
29053
29176
|
visibleMessageCount: visibleMessages.length,
|
|
29054
29177
|
lastVisibleRole,
|
|
29055
29178
|
lastVisibleKind,
|
|
@@ -29112,8 +29235,21 @@ var CliProviderInstance = class {
|
|
|
29112
29235
|
}
|
|
29113
29236
|
if (parsed?.activeModal || parsed?.modal) return { reason: "parsed_modal_active", terminal: true };
|
|
29114
29237
|
const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
|
|
29115
|
-
|
|
29116
|
-
|
|
29238
|
+
const finalAssistantEvidence = this.completionFinalAssistantEvidence(parsed?.messages);
|
|
29239
|
+
if (!finalAssistantEvidence.present) {
|
|
29240
|
+
if (adapterOwnsMessagesElsewhere) {
|
|
29241
|
+
if (finalAssistantEvidence.source === "external-native") {
|
|
29242
|
+
return { reason: "missing_final_assistant", terminal: true };
|
|
29243
|
+
}
|
|
29244
|
+
if (this.provider.requiresFinalAssistantBeforeIdle === true) {
|
|
29245
|
+
return { reason: "missing_final_assistant", terminal: true };
|
|
29246
|
+
}
|
|
29247
|
+
} else {
|
|
29248
|
+
return {
|
|
29249
|
+
reason: "missing_final_assistant",
|
|
29250
|
+
terminal: this.provider.requiresFinalAssistantBeforeIdle === true
|
|
29251
|
+
};
|
|
29252
|
+
}
|
|
29117
29253
|
}
|
|
29118
29254
|
try {
|
|
29119
29255
|
const screenText = typeof this.adapter.getScreenText === "function" ? String(this.adapter.getScreenText() || "") : "";
|
|
@@ -29172,7 +29308,7 @@ var CliProviderInstance = class {
|
|
|
29172
29308
|
chatTitle: pending.chatTitle,
|
|
29173
29309
|
duration: pending.duration,
|
|
29174
29310
|
timestamp: pending.timestamp,
|
|
29175
|
-
finalSummary: blockReason.startsWith("parsed_status:") ? "" :
|
|
29311
|
+
finalSummary: blockReason.startsWith("parsed_status:") ? "" : this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages),
|
|
29176
29312
|
completionDiagnostic
|
|
29177
29313
|
});
|
|
29178
29314
|
this.completedDebouncePending = null;
|
|
@@ -29187,7 +29323,7 @@ var CliProviderInstance = class {
|
|
|
29187
29323
|
chatTitle: pending.chatTitle,
|
|
29188
29324
|
duration: pending.duration,
|
|
29189
29325
|
timestamp: pending.timestamp,
|
|
29190
|
-
finalSummary:
|
|
29326
|
+
finalSummary: this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages)
|
|
29191
29327
|
});
|
|
29192
29328
|
this.completedDebouncePending = null;
|
|
29193
29329
|
this.completedDebounceTimer = null;
|
|
@@ -29320,11 +29456,15 @@ var CliProviderInstance = class {
|
|
|
29320
29456
|
this.generatingDebouncePending = null;
|
|
29321
29457
|
this.generatingStartedAt = 0;
|
|
29322
29458
|
let shortFinalSummary;
|
|
29459
|
+
let shortEvidenceSource = "unavailable";
|
|
29323
29460
|
try {
|
|
29324
|
-
|
|
29461
|
+
const parsedMessages = this.adapter?.getScriptParsedStatus()?.messages;
|
|
29462
|
+
const evidence = this.completionFinalAssistantEvidence(parsedMessages);
|
|
29463
|
+
shortEvidenceSource = evidence.source;
|
|
29464
|
+
shortFinalSummary = extractFinalSummaryFromMessages(evidence.messages);
|
|
29325
29465
|
} catch {
|
|
29326
29466
|
}
|
|
29327
|
-
if (this.provider.requiresFinalAssistantBeforeIdle === true && !shortFinalSummary) {
|
|
29467
|
+
if ((this.provider.requiresFinalAssistantBeforeIdle === true || shortEvidenceSource === "external-native") && !shortFinalSummary) {
|
|
29328
29468
|
LOG.info("CLI", `[${this.type}] suppressed short completion without final assistant evidence`);
|
|
29329
29469
|
} else {
|
|
29330
29470
|
this.pushEvent({
|
|
@@ -29335,7 +29475,8 @@ var CliProviderInstance = class {
|
|
|
29335
29475
|
finalSummary: shortFinalSummary,
|
|
29336
29476
|
completionDiagnostic: {
|
|
29337
29477
|
reason: "short_generating_suppressed",
|
|
29338
|
-
shortDurationMs
|
|
29478
|
+
shortDurationMs,
|
|
29479
|
+
finalAssistantEvidenceSource: shortEvidenceSource
|
|
29339
29480
|
}
|
|
29340
29481
|
});
|
|
29341
29482
|
}
|