@adhdev/daemon-core 0.9.82-rc.331 → 0.9.82-rc.333
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 +189 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +187 -86
- package/dist/index.mjs.map +1 -1
- package/dist/providers/cli-provider-instance.d.ts +15 -0
- package/dist/system/load-better-sqlite3.d.ts +21 -0
- package/package.json +2 -2
- package/src/cli-adapters/provider-cli-adapter.ts +12 -0
- package/src/mesh/mesh-events-coordinator.ts +15 -0
- package/src/mesh/mesh-reconcile-loop.ts +38 -2
- package/src/mesh/mesh-runtime-store.ts +2 -5
- package/src/providers/cli-provider-instance.ts +45 -0
- package/src/providers/native-history/hermes-cli-transcript.ts +2 -2
- package/src/providers/spec/native-history-executor.ts +2 -2
- package/src/system/load-better-sqlite3.ts +68 -0
package/dist/index.mjs
CHANGED
|
@@ -311,10 +311,10 @@ function readInjected(value) {
|
|
|
311
311
|
}
|
|
312
312
|
function getDaemonBuildInfo() {
|
|
313
313
|
if (cached) return cached;
|
|
314
|
-
const commit = readInjected(true ? "
|
|
315
|
-
const commitShort = readInjected(true ? "
|
|
316
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
317
|
-
const builtAt = readInjected(true ? "2026-06-
|
|
314
|
+
const commit = readInjected(true ? "5d9635b2a6476691469ecfe32b26a17e13484b2b" : void 0) ?? "unknown";
|
|
315
|
+
const commitShort = readInjected(true ? "5d9635b2" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
316
|
+
const version = readInjected(true ? "0.9.82-rc.333" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
317
|
+
const builtAt = readInjected(true ? "2026-06-20T02:23:56.856Z" : void 0);
|
|
318
318
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
319
319
|
return cached;
|
|
320
320
|
}
|
|
@@ -582,10 +582,10 @@ async function getGitRepoStatus(workspace, options = {}) {
|
|
|
582
582
|
} catch (error) {
|
|
583
583
|
const gitError = error instanceof GitCommandError ? error : new GitCommandError("git_command_failed", "Failed to read Git status", { cause: error });
|
|
584
584
|
if (isTransientGitFailure(gitError)) {
|
|
585
|
-
const
|
|
586
|
-
if (
|
|
585
|
+
const cached3 = lastKnownGoodStatus.get(workspace);
|
|
586
|
+
if (cached3) {
|
|
587
587
|
return {
|
|
588
|
-
...
|
|
588
|
+
...cached3,
|
|
589
589
|
lastCheckedAt,
|
|
590
590
|
upstreamStatus: "unavailable",
|
|
591
591
|
error: gitError.stderr || gitError.message,
|
|
@@ -708,9 +708,9 @@ function resolveChangeImpactConfigForRepo(repoRoot, options) {
|
|
|
708
708
|
return { config: null, sourceKey: "no-repo-root" };
|
|
709
709
|
}
|
|
710
710
|
const loaded = loadChangeImpactConfig(repoRoot);
|
|
711
|
-
const
|
|
712
|
-
if (
|
|
713
|
-
return { config:
|
|
711
|
+
const cached3 = changeImpactConfigCache.get(repoRoot);
|
|
712
|
+
if (cached3 && cached3.sourceKey === loaded.sourceKey) {
|
|
713
|
+
return { config: cached3.config, sourceKey: loaded.sourceKey };
|
|
714
714
|
}
|
|
715
715
|
const config = loaded.sourceType === "repo_file" ? loaded.config ?? null : null;
|
|
716
716
|
changeImpactConfigCache.set(repoRoot, { sourceKey: loaded.sourceKey, config });
|
|
@@ -2536,6 +2536,46 @@ Follow these recovery rules:
|
|
|
2536
2536
|
}
|
|
2537
2537
|
});
|
|
2538
2538
|
|
|
2539
|
+
// src/system/load-better-sqlite3.ts
|
|
2540
|
+
import { createRequire } from "module";
|
|
2541
|
+
function loadBetterSqlite3() {
|
|
2542
|
+
if (cached2) return cached2;
|
|
2543
|
+
const errors = [];
|
|
2544
|
+
if (typeof __require === "function") {
|
|
2545
|
+
try {
|
|
2546
|
+
cached2 = __require("better-sqlite3");
|
|
2547
|
+
return cached2;
|
|
2548
|
+
} catch (e) {
|
|
2549
|
+
errors.push(e);
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
try {
|
|
2553
|
+
const metaUrl = typeof import.meta?.url === "string" ? import.meta.url : void 0;
|
|
2554
|
+
if (metaUrl) {
|
|
2555
|
+
cached2 = createRequire(metaUrl)("better-sqlite3");
|
|
2556
|
+
return cached2;
|
|
2557
|
+
}
|
|
2558
|
+
} catch (e) {
|
|
2559
|
+
errors.push(e);
|
|
2560
|
+
}
|
|
2561
|
+
try {
|
|
2562
|
+
cached2 = createRequire(`${process.cwd()}/__adhdev_better_sqlite3_loader__.js`)(
|
|
2563
|
+
"better-sqlite3"
|
|
2564
|
+
);
|
|
2565
|
+
return cached2;
|
|
2566
|
+
} catch (e) {
|
|
2567
|
+
errors.push(e);
|
|
2568
|
+
}
|
|
2569
|
+
const detail = errors.map((e) => e instanceof Error ? e.message : String(e)).join("; ");
|
|
2570
|
+
throw new Error(`Failed to load better-sqlite3: ${detail}`);
|
|
2571
|
+
}
|
|
2572
|
+
var cached2;
|
|
2573
|
+
var init_load_better_sqlite3 = __esm({
|
|
2574
|
+
"src/system/load-better-sqlite3.ts"() {
|
|
2575
|
+
"use strict";
|
|
2576
|
+
}
|
|
2577
|
+
});
|
|
2578
|
+
|
|
2539
2579
|
// src/mesh/mesh-ledger.ts
|
|
2540
2580
|
var mesh_ledger_exports = {};
|
|
2541
2581
|
__export(mesh_ledger_exports, {
|
|
@@ -2969,8 +3009,8 @@ function readLedgerFromStore(meshId) {
|
|
|
2969
3009
|
}
|
|
2970
3010
|
function getCachedRawEntries(meshId) {
|
|
2971
3011
|
const now = Date.now();
|
|
2972
|
-
const
|
|
2973
|
-
if (
|
|
3012
|
+
const cached3 = ledgerReadCache.get(meshId);
|
|
3013
|
+
if (cached3 && now - cached3.cachedAt < LEDGER_CACHE_TTL_MS) return cached3.entries;
|
|
2974
3014
|
let entries;
|
|
2975
3015
|
try {
|
|
2976
3016
|
entries = readLedgerFromStore(meshId);
|
|
@@ -3849,11 +3889,9 @@ var init_mesh_work_queue = __esm({
|
|
|
3849
3889
|
// src/mesh/mesh-runtime-store.ts
|
|
3850
3890
|
import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, statSync as statSync4 } from "fs";
|
|
3851
3891
|
import { dirname as dirname2, join as join8 } from "path";
|
|
3852
|
-
import { createRequire } from "module";
|
|
3853
3892
|
function loadDatabaseCtor() {
|
|
3854
3893
|
if (DatabaseCtor) return DatabaseCtor;
|
|
3855
|
-
|
|
3856
|
-
DatabaseCtor = runtimeRequire("better-sqlite3");
|
|
3894
|
+
DatabaseCtor = loadBetterSqlite3();
|
|
3857
3895
|
return DatabaseCtor;
|
|
3858
3896
|
}
|
|
3859
3897
|
function safeMeshId(meshId) {
|
|
@@ -3884,6 +3922,7 @@ var DatabaseCtor, MeshRuntimeStore;
|
|
|
3884
3922
|
var init_mesh_runtime_store = __esm({
|
|
3885
3923
|
"src/mesh/mesh-runtime-store.ts"() {
|
|
3886
3924
|
"use strict";
|
|
3925
|
+
init_load_better_sqlite3();
|
|
3887
3926
|
init_mesh_ledger();
|
|
3888
3927
|
init_mesh_work_queue();
|
|
3889
3928
|
MeshRuntimeStore = class _MeshRuntimeStore {
|
|
@@ -9415,8 +9454,8 @@ function resolveCoordinatorDrainDaemonIds(components) {
|
|
|
9415
9454
|
}
|
|
9416
9455
|
function getCachedMeshByWorkspace(workspace) {
|
|
9417
9456
|
const now = Date.now();
|
|
9418
|
-
const
|
|
9419
|
-
if (
|
|
9457
|
+
const cached3 = meshByWorkspaceCache.get(workspace);
|
|
9458
|
+
if (cached3 && now - cached3.cachedAt < MESH_WORKSPACE_CACHE_TTL_MS) return cached3.mesh;
|
|
9420
9459
|
const mesh = getMeshByRepo(workspace);
|
|
9421
9460
|
meshByWorkspaceCache.set(workspace, { mesh, cachedAt: now });
|
|
9422
9461
|
return mesh;
|
|
@@ -10666,6 +10705,21 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
10666
10705
|
targetSessionId: readNonEmptyString2(payload.targetSessionId) || readNonEmptyString2(payload.sessionId) || readNonEmptyString2(payload.instanceId),
|
|
10667
10706
|
providerType: readNonEmptyString2(payload.providerType),
|
|
10668
10707
|
providerSessionId: readNonEmptyString2(payload.providerSessionId),
|
|
10708
|
+
// Carry the session identity fields the worker provider event emits so the
|
|
10709
|
+
// coordinator's mirror (updateMeshOwnedSession) gets a real workspace/title/
|
|
10710
|
+
// settings. Without these the remote-relay hop reconstructs metadataEvent with
|
|
10711
|
+
// an empty workspace, and the dashboard flaps to the generic
|
|
10712
|
+
// "Terminal (Mesh Node)" title (and degrades the provider label) between live
|
|
10713
|
+
// events and the periodic get_status_metadata snapshot. The local in-process
|
|
10714
|
+
// forward path (onMeshCoordinatorEventForwarded) already preserves these; this
|
|
10715
|
+
// mirrors them for the remote-only relay path.
|
|
10716
|
+
workspace: readNonEmptyString2(payload.workspace) || readNonEmptyString2(payload.workspaceName),
|
|
10717
|
+
workspaceName: readNonEmptyString2(payload.workspaceName) || readNonEmptyString2(payload.workspace),
|
|
10718
|
+
sessionTitle: readNonEmptyString2(payload.sessionTitle),
|
|
10719
|
+
sessionStatus: readNonEmptyString2(payload.sessionStatus),
|
|
10720
|
+
sessionChatStatus: readNonEmptyString2(payload.sessionChatStatus),
|
|
10721
|
+
providerName: readNonEmptyString2(payload.providerName),
|
|
10722
|
+
...payload.sessionSettings && typeof payload.sessionSettings === "object" && !Array.isArray(payload.sessionSettings) ? { sessionSettings: payload.sessionSettings } : {},
|
|
10669
10723
|
finalSummary: readNonEmptyString2(payload.finalSummary) || readNonEmptyString2(payload.summary),
|
|
10670
10724
|
jobId: readNonEmptyString2(payload.jobId),
|
|
10671
10725
|
interactionId: readNonEmptyString2(payload.interactionId),
|
|
@@ -11545,7 +11599,8 @@ function findLiveCoordinators(components) {
|
|
|
11545
11599
|
const meshId = readNonEmptyString2(settings.meshCoordinatorFor);
|
|
11546
11600
|
if (!meshId) continue;
|
|
11547
11601
|
const status = readNonEmptyString2(state.status).toLowerCase();
|
|
11548
|
-
|
|
11602
|
+
const modalParked = status === "waiting_choice" || status === "waiting_approval";
|
|
11603
|
+
out.push({ meshId, instance: inst, idle: status === "idle", modalParked });
|
|
11549
11604
|
}
|
|
11550
11605
|
return out;
|
|
11551
11606
|
}
|
|
@@ -11634,9 +11689,16 @@ async function runMeshReconcileTick(components) {
|
|
|
11634
11689
|
}
|
|
11635
11690
|
for (const [meshId, meshCoordinators] of byMesh) {
|
|
11636
11691
|
const idleCoordinators = meshCoordinators.filter((c) => c.idle);
|
|
11637
|
-
const generatingCoordinators = meshCoordinators.filter((c) => !c.idle);
|
|
11692
|
+
const generatingCoordinators = meshCoordinators.filter((c) => !c.idle && !c.modalParked);
|
|
11693
|
+
const modalParkedCoordinators = meshCoordinators.filter((c) => !c.idle && c.modalParked);
|
|
11638
11694
|
const targetCoordinators = idleCoordinators.length > 0 ? idleCoordinators : generatingCoordinators;
|
|
11639
11695
|
const forceOnly = idleCoordinators.length === 0;
|
|
11696
|
+
if (targetCoordinators.length === 0) {
|
|
11697
|
+
if (modalParkedCoordinators.length > 0) {
|
|
11698
|
+
LOG.info("MeshReconcile", `Reconcile skip \u2192 modal-parked: holding pending event(s) for mesh ${meshId} (${modalParkedCoordinators.length} coordinator(s) awaiting a modal answer; events left queued)`);
|
|
11699
|
+
}
|
|
11700
|
+
continue;
|
|
11701
|
+
}
|
|
11640
11702
|
if (store) {
|
|
11641
11703
|
try {
|
|
11642
11704
|
if (store.pendingEventCount(meshId) === 0) continue;
|
|
@@ -15237,10 +15299,10 @@ ${lastSnapshot}`;
|
|
|
15237
15299
|
return this.accumulatedRawBuffer.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
15238
15300
|
}
|
|
15239
15301
|
getFreshParsedStatusCache() {
|
|
15240
|
-
const
|
|
15302
|
+
const cached3 = this.parsedStatusCache;
|
|
15241
15303
|
const accumulatedRawBufferKey = this.getAccumulatedRawBufferCacheKey();
|
|
15242
|
-
if (
|
|
15243
|
-
return
|
|
15304
|
+
if (cached3 && cached3.responseBuffer === this.responseBuffer && cached3.currentTurnScope === this.engine.currentTurnScope && cached3.recentOutputBuffer === this.recentOutputBuffer && cached3.accumulatedBuffer === this.accumulatedBuffer && cached3.accumulatedRawBufferKey === accumulatedRawBufferKey && cached3.screenText === this.lastScreenText && cached3.currentStatus === this.engine.currentStatus && cached3.activeModal === this.engine.activeModal && cached3.cliName === this.cliName) {
|
|
15305
|
+
return cached3.result;
|
|
15244
15306
|
}
|
|
15245
15307
|
return null;
|
|
15246
15308
|
}
|
|
@@ -15702,10 +15764,10 @@ ${lastSnapshot}`;
|
|
|
15702
15764
|
getScriptParsedStatus() {
|
|
15703
15765
|
const screenText = this.readTerminalScreenText();
|
|
15704
15766
|
const parseScreenText = this.getParseScreenText(screenText);
|
|
15705
|
-
const
|
|
15767
|
+
const cached3 = this.parsedStatusCache;
|
|
15706
15768
|
const accumulatedRawBufferKey = this.getAccumulatedRawBufferCacheKey();
|
|
15707
|
-
if (!this.providerOwnsTranscript() &&
|
|
15708
|
-
return
|
|
15769
|
+
if (!this.providerOwnsTranscript() && cached3 && cached3.responseBuffer === this.responseBuffer && cached3.currentTurnScope === this.engine.currentTurnScope && cached3.recentOutputBuffer === this.recentOutputBuffer && cached3.accumulatedBuffer === this.accumulatedBuffer && cached3.accumulatedRawBufferKey === accumulatedRawBufferKey && cached3.screenText === parseScreenText && cached3.currentStatus === this.engine.currentStatus && cached3.activeModal === this.engine.activeModal && cached3.cliName === this.cliName) {
|
|
15770
|
+
return cached3.result;
|
|
15709
15771
|
}
|
|
15710
15772
|
const parsed = this.runParseSession();
|
|
15711
15773
|
if (!parsed || !Array.isArray(parsed.messages)) {
|
|
@@ -15952,6 +16014,10 @@ ${lastSnapshot}`;
|
|
|
15952
16014
|
if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
|
|
15953
16015
|
const content = String(text || "");
|
|
15954
16016
|
if (!content.trim()) return;
|
|
16017
|
+
if (this.engine.currentStatus === "waiting_approval" || this.engine.hasActionableApproval()) {
|
|
16018
|
+
LOG.info("CLI", `[${this.cliType}] force-send held \u2014 session parked on approval modal (status=${this.engine.currentStatus})`);
|
|
16019
|
+
return;
|
|
16020
|
+
}
|
|
15955
16021
|
LOG.info("CLI", `[${this.cliType}] force-sending prompt while status=${this.engine.currentStatus}`);
|
|
15956
16022
|
await this.writeToPty(content + this.sendKey);
|
|
15957
16023
|
this.onStatusChange?.();
|
|
@@ -22102,11 +22168,11 @@ var savedHistoryRollupInFlight = /* @__PURE__ */ new Set();
|
|
|
22102
22168
|
var BOUNDED_TAIL_CACHE_MAX_ENTRIES = 64;
|
|
22103
22169
|
var boundedTailReadCache = /* @__PURE__ */ new Map();
|
|
22104
22170
|
function readBoundedTailCache(key, signature) {
|
|
22105
|
-
const
|
|
22106
|
-
if (!
|
|
22171
|
+
const cached3 = boundedTailReadCache.get(key);
|
|
22172
|
+
if (!cached3 || cached3.signature !== signature) return null;
|
|
22107
22173
|
boundedTailReadCache.delete(key);
|
|
22108
|
-
boundedTailReadCache.set(key,
|
|
22109
|
-
return
|
|
22174
|
+
boundedTailReadCache.set(key, cached3);
|
|
22175
|
+
return cached3.result;
|
|
22110
22176
|
}
|
|
22111
22177
|
function writeBoundedTailCache(key, signature, result) {
|
|
22112
22178
|
boundedTailReadCache.delete(key);
|
|
@@ -22590,9 +22656,9 @@ function computeSavedHistorySessionSummaries(agentType, dir, files, fileSignatur
|
|
|
22590
22656
|
for (const file of files.slice().sort()) {
|
|
22591
22657
|
const filePath = path14.join(dir, file);
|
|
22592
22658
|
const signature = fileSignatures.get(file) || `${file}:missing`;
|
|
22593
|
-
const
|
|
22659
|
+
const cached3 = savedHistoryFileSummaryCache.get(filePath);
|
|
22594
22660
|
const persisted = persistedEntries.get(file);
|
|
22595
|
-
const reusableEntry =
|
|
22661
|
+
const reusableEntry = cached3?.signature === signature ? cached3 : persisted?.signature === signature ? persisted : null;
|
|
22596
22662
|
const fileSummary = reusableEntry?.summary || computeSavedHistoryFileSummary(dir, file);
|
|
22597
22663
|
const nextEntry = reusableEntry || {
|
|
22598
22664
|
signature,
|
|
@@ -23088,16 +23154,16 @@ function readFileTailLines(filePath, needed) {
|
|
|
23088
23154
|
incrementalTailCache.delete(filePath);
|
|
23089
23155
|
return { lines: [], coversWholeFile: true };
|
|
23090
23156
|
}
|
|
23091
|
-
const
|
|
23092
|
-
if (
|
|
23093
|
-
if (
|
|
23157
|
+
const cached3 = incrementalTailCache.get(filePath);
|
|
23158
|
+
if (cached3) {
|
|
23159
|
+
if (cached3.size === size && cached3.mtimeMs === mtimeMs) {
|
|
23094
23160
|
incrementalTailCache.delete(filePath);
|
|
23095
|
-
incrementalTailCache.set(filePath,
|
|
23096
|
-
if (
|
|
23097
|
-
return { lines:
|
|
23161
|
+
incrementalTailCache.set(filePath, cached3);
|
|
23162
|
+
if (cached3.coversWholeFile || cached3.lines.length >= needed) {
|
|
23163
|
+
return { lines: cached3.lines, coversWholeFile: cached3.coversWholeFile };
|
|
23098
23164
|
}
|
|
23099
|
-
} else if (size >
|
|
23100
|
-
const incremental = tryIncrementalTailGrowth(filePath,
|
|
23165
|
+
} else if (size > cached3.size) {
|
|
23166
|
+
const incremental = tryIncrementalTailGrowth(filePath, cached3, size, mtimeMs, needed);
|
|
23101
23167
|
if (incremental) return { lines: incremental.lines, coversWholeFile: incremental.coversWholeFile };
|
|
23102
23168
|
}
|
|
23103
23169
|
incrementalTailCache.delete(filePath);
|
|
@@ -23123,22 +23189,22 @@ function readFileTailLines(filePath, needed) {
|
|
|
23123
23189
|
storeIncrementalTailCache(filePath, result.size, result.mtimeMs, result.lines, result.coversWholeFile);
|
|
23124
23190
|
return { lines: result.lines, coversWholeFile: result.coversWholeFile };
|
|
23125
23191
|
}
|
|
23126
|
-
function tryIncrementalTailGrowth(filePath,
|
|
23192
|
+
function tryIncrementalTailGrowth(filePath, cached3, size, mtimeMs, needed) {
|
|
23127
23193
|
const fd = fs6.openSync(filePath, "r");
|
|
23128
23194
|
try {
|
|
23129
|
-
if (
|
|
23195
|
+
if (cached3.size > 0) {
|
|
23130
23196
|
const boundary = Buffer.alloc(1);
|
|
23131
|
-
fs6.readSync(fd, boundary, 0, 1,
|
|
23197
|
+
fs6.readSync(fd, boundary, 0, 1, cached3.size - 1);
|
|
23132
23198
|
if (boundary[0] !== 10) return null;
|
|
23133
23199
|
}
|
|
23134
|
-
const appendedLength = size -
|
|
23200
|
+
const appendedLength = size - cached3.size;
|
|
23135
23201
|
const appended = Buffer.alloc(appendedLength);
|
|
23136
|
-
fs6.readSync(fd, appended, 0, appendedLength,
|
|
23202
|
+
fs6.readSync(fd, appended, 0, appendedLength, cached3.size);
|
|
23137
23203
|
const newLines = appended.toString("utf-8").split("\n");
|
|
23138
23204
|
if (newLines.length && newLines[newLines.length - 1] === "") newLines.pop();
|
|
23139
|
-
const merged =
|
|
23205
|
+
const merged = cached3.lines.concat(newLines);
|
|
23140
23206
|
const trimmed = merged.length > TAIL_LINES_RETAINED ? merged.slice(merged.length - TAIL_LINES_RETAINED) : merged;
|
|
23141
|
-
const coversWholeFile =
|
|
23207
|
+
const coversWholeFile = cached3.coversWholeFile && trimmed.length === merged.length;
|
|
23142
23208
|
storeIncrementalTailCache(filePath, size, mtimeMs, trimmed, coversWholeFile);
|
|
23143
23209
|
if (coversWholeFile || trimmed.length >= needed) {
|
|
23144
23210
|
return { lines: trimmed, coversWholeFile };
|
|
@@ -23203,8 +23269,8 @@ function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, ex
|
|
|
23203
23269
|
const fileSignatures = buildSavedHistoryFileSignatureMap(dir, files);
|
|
23204
23270
|
const cacheKey = `${sanitized}\0${historySessionId || ""}\0${offset}\0${limit}\0${excludeRecentCount}\0${historyBehavior?.collapseConsecutiveAssistantTurns ? "1" : "0"}`;
|
|
23205
23271
|
const signature = buildSavedHistoryCacheSignature(files, fileSignatures);
|
|
23206
|
-
const
|
|
23207
|
-
if (
|
|
23272
|
+
const cached3 = readBoundedTailCache(cacheKey, signature);
|
|
23273
|
+
if (cached3) return cached3;
|
|
23208
23274
|
const numericLimit = Math.max(1, Number(limit));
|
|
23209
23275
|
const numericOffset = Math.max(0, Number(offset));
|
|
23210
23276
|
const numericExclude = Math.max(0, Number(excludeRecentCount));
|
|
@@ -23247,23 +23313,23 @@ function listSavedHistorySessions(agentType, options = {}, historyBehavior) {
|
|
|
23247
23313
|
savedHistorySessionCache.delete(sanitized);
|
|
23248
23314
|
return { sessions: [], hasMore: false };
|
|
23249
23315
|
}
|
|
23250
|
-
const
|
|
23316
|
+
const cached3 = savedHistorySessionCache.get(sanitized);
|
|
23251
23317
|
const offset = Math.max(0, options.offset || 0);
|
|
23252
23318
|
const limit = Math.max(1, options.limit || 30);
|
|
23253
23319
|
const indexSignature = buildSavedHistoryIndexFileSignature(dir);
|
|
23254
23320
|
let cacheWasInvalidated = false;
|
|
23255
|
-
if (
|
|
23256
|
-
const cacheLooksPersisted =
|
|
23257
|
-
const cacheStillValid = cacheLooksPersisted ?
|
|
23321
|
+
if (cached3) {
|
|
23322
|
+
const cacheLooksPersisted = cached3.signature.startsWith("index:");
|
|
23323
|
+
const cacheStillValid = cacheLooksPersisted ? cached3.signature === indexSignature : (() => {
|
|
23258
23324
|
const files2 = listHistoryFiles(dir);
|
|
23259
23325
|
const fileSignatures2 = buildSavedHistoryFileSignatureMap(dir, files2);
|
|
23260
|
-
return
|
|
23326
|
+
return cached3.signature === buildSavedHistoryCacheSignature(files2, fileSignatures2);
|
|
23261
23327
|
})();
|
|
23262
23328
|
if (cacheStillValid) {
|
|
23263
|
-
const sliced2 =
|
|
23329
|
+
const sliced2 = cached3.summaries.slice(offset, offset + limit);
|
|
23264
23330
|
return {
|
|
23265
23331
|
sessions: sliced2,
|
|
23266
|
-
hasMore:
|
|
23332
|
+
hasMore: cached3.summaries.length > offset + limit
|
|
23267
23333
|
};
|
|
23268
23334
|
}
|
|
23269
23335
|
cacheWasInvalidated = true;
|
|
@@ -32208,6 +32274,7 @@ function collectStableSizes(when, sizes) {
|
|
|
32208
32274
|
|
|
32209
32275
|
// src/providers/spec/native-history-executor.ts
|
|
32210
32276
|
init_logger();
|
|
32277
|
+
init_load_better_sqlite3();
|
|
32211
32278
|
import * as fs13 from "fs";
|
|
32212
32279
|
import * as os17 from "os";
|
|
32213
32280
|
import * as path22 from "path";
|
|
@@ -32335,7 +32402,7 @@ function executeSqlite(src, input) {
|
|
|
32335
32402
|
if (!resolved || !fs13.existsSync(resolved)) return null;
|
|
32336
32403
|
let Database;
|
|
32337
32404
|
try {
|
|
32338
|
-
Database =
|
|
32405
|
+
Database = loadBetterSqlite3();
|
|
32339
32406
|
} catch {
|
|
32340
32407
|
return null;
|
|
32341
32408
|
}
|
|
@@ -34501,6 +34568,35 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
34501
34568
|
this.settings = rest;
|
|
34502
34569
|
this.adapter.updateRuntimeSettings?.(this.settings);
|
|
34503
34570
|
}
|
|
34571
|
+
/**
|
|
34572
|
+
* The resolved modal-park status of this session, or null when it is not
|
|
34573
|
+
* parked on a modal awaiting a human answer. Mirrors the overlay logic in
|
|
34574
|
+
* getState(): an active AskUserQuestion interactive prompt resolves to
|
|
34575
|
+
* waiting_choice; otherwise the adapter's waiting_approval (tool consent)
|
|
34576
|
+
* counts — UNLESS auto-approve will dismiss it, in which case the session is
|
|
34577
|
+
* effectively generating and is NOT modal-parked. This is the single signal
|
|
34578
|
+
* the mesh force-inject guard consults, and the same status string the
|
|
34579
|
+
* reconcile loop reads off get_status_metadata. Lowercase literals only —
|
|
34580
|
+
* the SessionStatus enum is forked across modules and waiting_choice is
|
|
34581
|
+
* absent from some of them.
|
|
34582
|
+
*/
|
|
34583
|
+
resolveModalParkStatus() {
|
|
34584
|
+
if (this.activeInteractivePrompt) return "waiting_choice";
|
|
34585
|
+
let adapterStatus;
|
|
34586
|
+
try {
|
|
34587
|
+
adapterStatus = this.adapter.getStatus({ allowParse: false });
|
|
34588
|
+
} catch {
|
|
34589
|
+
return null;
|
|
34590
|
+
}
|
|
34591
|
+
if (adapterStatus.status === "waiting_approval" && !this.shouldAutoApprove()) {
|
|
34592
|
+
return "waiting_approval";
|
|
34593
|
+
}
|
|
34594
|
+
return null;
|
|
34595
|
+
}
|
|
34596
|
+
/** True when this session is parked on a modal awaiting a human answer. */
|
|
34597
|
+
isModalParked() {
|
|
34598
|
+
return this.resolveModalParkStatus() !== null;
|
|
34599
|
+
}
|
|
34504
34600
|
onEvent(event, data) {
|
|
34505
34601
|
if (event === "send_message") {
|
|
34506
34602
|
const input = normalizeInputEnvelope(data);
|
|
@@ -34508,6 +34604,10 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
34508
34604
|
const promptText = buildCliStructuredInputPrompt(input);
|
|
34509
34605
|
if (promptText) {
|
|
34510
34606
|
const force = data?.force === true;
|
|
34607
|
+
if (force && this.isModalParked()) {
|
|
34608
|
+
LOG.info("CLI", `[${this.type}] force send_message held \u2014 coordinator parked on modal (${this.resolveModalParkStatus()})`);
|
|
34609
|
+
return;
|
|
34610
|
+
}
|
|
34511
34611
|
void this.adapter.sendMessage(promptText, force ? { force: true } : {}).catch((e) => {
|
|
34512
34612
|
LOG.warn("CLI", `[${this.type}] send_message failed: ${e?.message || e}`);
|
|
34513
34613
|
});
|
|
@@ -39128,6 +39228,7 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
39128
39228
|
}
|
|
39129
39229
|
|
|
39130
39230
|
// src/providers/native-history/hermes-cli-transcript.ts
|
|
39231
|
+
init_load_better_sqlite3();
|
|
39131
39232
|
import * as fs20 from "fs";
|
|
39132
39233
|
import * as path30 from "path";
|
|
39133
39234
|
import * as os21 from "os";
|
|
@@ -39143,7 +39244,7 @@ function statMtimeMs4(p) {
|
|
|
39143
39244
|
function openDb() {
|
|
39144
39245
|
if (!fs20.existsSync(HERMES_STATE_DB)) return null;
|
|
39145
39246
|
try {
|
|
39146
|
-
const Database =
|
|
39247
|
+
const Database = loadBetterSqlite3();
|
|
39147
39248
|
return new Database(HERMES_STATE_DB, { readonly: true, fileMustExist: true });
|
|
39148
39249
|
} catch {
|
|
39149
39250
|
return null;
|
|
@@ -40518,8 +40619,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
40518
40619
|
return null;
|
|
40519
40620
|
}
|
|
40520
40621
|
registerProviderScriptRootSafely(path33.dirname(path33.dirname(providerDir)));
|
|
40521
|
-
const
|
|
40522
|
-
if (
|
|
40622
|
+
const cached3 = this.scriptsCache.get(dir);
|
|
40623
|
+
if (cached3) return cached3;
|
|
40523
40624
|
const scriptsJs = path33.join(dir, "scripts.js");
|
|
40524
40625
|
if (fs22.existsSync(scriptsJs)) {
|
|
40525
40626
|
try {
|
|
@@ -43598,13 +43699,13 @@ function sanitizeInlineMesh(inlineMesh) {
|
|
|
43598
43699
|
nodes
|
|
43599
43700
|
};
|
|
43600
43701
|
}
|
|
43601
|
-
function reconcileInlineMeshCache(
|
|
43602
|
-
if (!
|
|
43603
|
-
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) return
|
|
43604
|
-
const cachedNodes = Array.isArray(
|
|
43702
|
+
function reconcileInlineMeshCache(cached3, incoming) {
|
|
43703
|
+
if (!cached3 || typeof cached3 !== "object" || Array.isArray(cached3)) return incoming;
|
|
43704
|
+
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) return cached3;
|
|
43705
|
+
const cachedNodes = Array.isArray(cached3.nodes) ? cached3.nodes : [];
|
|
43605
43706
|
const incomingNodes = Array.isArray(incoming.nodes) ? incoming.nodes : [];
|
|
43606
|
-
if (!cachedNodes.length || !incomingNodes.length) return { ...
|
|
43607
|
-
const cachedUpdatedAt = Date.parse(readStringValue(
|
|
43707
|
+
if (!cachedNodes.length || !incomingNodes.length) return { ...cached3, ...incoming };
|
|
43708
|
+
const cachedUpdatedAt = Date.parse(readStringValue(cached3.updatedAt, cached3.updated_at) || "");
|
|
43608
43709
|
const incomingUpdatedAt = Date.parse(readStringValue(incoming.updatedAt, incoming.updated_at) || "");
|
|
43609
43710
|
const preserveCachedMembership = Number.isFinite(cachedUpdatedAt) && (!Number.isFinite(incomingUpdatedAt) || cachedUpdatedAt > incomingUpdatedAt);
|
|
43610
43711
|
const cachedById = /* @__PURE__ */ new Map();
|
|
@@ -43633,7 +43734,7 @@ function reconcileInlineMeshCache(cached2, incoming) {
|
|
|
43633
43734
|
}
|
|
43634
43735
|
}
|
|
43635
43736
|
return {
|
|
43636
|
-
...
|
|
43737
|
+
...cached3,
|
|
43637
43738
|
...incoming,
|
|
43638
43739
|
nodes
|
|
43639
43740
|
};
|
|
@@ -43966,9 +44067,9 @@ var MeshGitProbeCache = class {
|
|
|
43966
44067
|
*/
|
|
43967
44068
|
async probe(daemonId, workspace, probe) {
|
|
43968
44069
|
const key = this.key(daemonId, workspace);
|
|
43969
|
-
const
|
|
43970
|
-
if (
|
|
43971
|
-
return
|
|
44070
|
+
const cached3 = this.recent.get(key);
|
|
44071
|
+
if (cached3 && this.now() - cached3.at < this.reuseMs) {
|
|
44072
|
+
return cached3.value;
|
|
43972
44073
|
}
|
|
43973
44074
|
const existing = this.inflight.get(key);
|
|
43974
44075
|
if (existing) return existing;
|
|
@@ -45616,13 +45717,13 @@ var DaemonCommandRouter = class {
|
|
|
45616
45717
|
};
|
|
45617
45718
|
}
|
|
45618
45719
|
getCachedAggregateMeshStatus(meshId, mesh, options) {
|
|
45619
|
-
const
|
|
45620
|
-
if (!
|
|
45621
|
-
if (
|
|
45622
|
-
let snapshot = this.cloneJsonValue(
|
|
45720
|
+
const cached3 = this.aggregateMeshStatusCache.get(meshId);
|
|
45721
|
+
if (!cached3?.snapshot || cached3.snapshot.success !== true || !Array.isArray(cached3.snapshot.nodes)) return null;
|
|
45722
|
+
if (cached3.queueRevision !== getMeshQueueRevision(meshId)) return null;
|
|
45723
|
+
let snapshot = this.cloneJsonValue(cached3.snapshot);
|
|
45623
45724
|
snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
|
|
45624
45725
|
if (shouldRefreshStalePendingAggregate(snapshot, options)) return null;
|
|
45625
|
-
const ageMs = Math.max(0, Date.now() -
|
|
45726
|
+
const ageMs = Math.max(0, Date.now() - cached3.builtAt);
|
|
45626
45727
|
const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
|
|
45627
45728
|
snapshot.sourceOfTruth = {
|
|
45628
45729
|
...sourceOfTruth,
|
|
@@ -45633,7 +45734,7 @@ var DaemonCommandRouter = class {
|
|
|
45633
45734
|
source: "memory",
|
|
45634
45735
|
refreshReason: "memory_cache_hit",
|
|
45635
45736
|
ageMs,
|
|
45636
|
-
cachedAt: new Date(
|
|
45737
|
+
cachedAt: new Date(cached3.builtAt).toISOString(),
|
|
45637
45738
|
returnedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
45638
45739
|
}
|
|
45639
45740
|
};
|
|
@@ -45680,9 +45781,9 @@ var DaemonCommandRouter = class {
|
|
|
45680
45781
|
meshId,
|
|
45681
45782
|
sanitizeInlineMesh(normalizeInlineMeshNodeIdentity(inlineMesh))
|
|
45682
45783
|
);
|
|
45683
|
-
const
|
|
45684
|
-
if (
|
|
45685
|
-
const merged = reconcileInlineMeshCache(
|
|
45784
|
+
const cached3 = this.inlineMeshCache.get(meshId);
|
|
45785
|
+
if (cached3) {
|
|
45786
|
+
const merged = reconcileInlineMeshCache(cached3, sanitizedInlineMesh);
|
|
45686
45787
|
this.inlineMeshCache.set(meshId, merged);
|
|
45687
45788
|
return merged;
|
|
45688
45789
|
}
|
|
@@ -45692,17 +45793,17 @@ var DaemonCommandRouter = class {
|
|
|
45692
45793
|
async getMeshForCommand(meshId, inlineMesh, options) {
|
|
45693
45794
|
const preferInline = options?.preferInline === true;
|
|
45694
45795
|
if (preferInline) {
|
|
45695
|
-
const
|
|
45696
|
-
if (
|
|
45796
|
+
const cached4 = this.getCachedInlineMesh(meshId);
|
|
45797
|
+
if (cached4) {
|
|
45697
45798
|
if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
|
|
45698
45799
|
const merged = reconcileInlineMeshCache(
|
|
45699
|
-
|
|
45800
|
+
cached4,
|
|
45700
45801
|
this.applyInlineMeshNodeTombstones(meshId, inlineMesh)
|
|
45701
45802
|
);
|
|
45702
45803
|
this.inlineMeshCache.set(meshId, sanitizeInlineMesh(normalizeInlineMeshNodeIdentity(merged)));
|
|
45703
45804
|
return { mesh: merged, inline: true, source: "inline_cache" };
|
|
45704
45805
|
}
|
|
45705
|
-
return { mesh:
|
|
45806
|
+
return { mesh: cached4, inline: true, source: "inline_cache" };
|
|
45706
45807
|
}
|
|
45707
45808
|
if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
|
|
45708
45809
|
this.warmInlineMeshCache(meshId, inlineMesh);
|
|
@@ -45715,8 +45816,8 @@ var DaemonCommandRouter = class {
|
|
|
45715
45816
|
if (mesh) return { mesh, inline: false, source: "local_config" };
|
|
45716
45817
|
} catch {
|
|
45717
45818
|
}
|
|
45718
|
-
const
|
|
45719
|
-
if (
|
|
45819
|
+
const cached3 = this.getCachedInlineMesh(meshId);
|
|
45820
|
+
if (cached3) return { mesh: cached3, inline: true, source: "inline_cache" };
|
|
45720
45821
|
const warmedInline = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
45721
45822
|
return warmedInline ? { mesh: warmedInline, inline: true, source: "inline_bootstrap" } : null;
|
|
45722
45823
|
}
|
|
@@ -47146,8 +47247,8 @@ ${hintLines.join("\n")}` : "",
|
|
|
47146
47247
|
const repoRootBaseRef = /* @__PURE__ */ new Map();
|
|
47147
47248
|
const submodulePathsByRepoRoot = /* @__PURE__ */ new Map();
|
|
47148
47249
|
const resolveBaseRef = async (repoRoot) => {
|
|
47149
|
-
const
|
|
47150
|
-
if (
|
|
47250
|
+
const cached3 = repoRootBaseRef.get(repoRoot);
|
|
47251
|
+
if (cached3) return cached3;
|
|
47151
47252
|
let baseBranch = "main";
|
|
47152
47253
|
try {
|
|
47153
47254
|
const { stdout } = await execFileAsync4("git", ["branch", "--show-current"], { cwd: repoRoot, encoding: "utf8" });
|