@ouro.bot/cli 0.1.0-alpha.663 → 0.1.0-alpha.664
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/changelog.json +6 -0
- package/dist/heart/context-loss-sentinel.js +122 -13
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.664",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Coalesce unchanged periodic Arc Sentinel daemon-health receipts so healthy daemons do not keep synced bundles dirty."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.663",
|
|
6
12
|
"changes": [
|
|
@@ -126,6 +126,103 @@ function compareReceiptOrder(left, right) {
|
|
|
126
126
|
function shouldReplaceReceipt(existing, candidate) {
|
|
127
127
|
return existing === null || compareReceiptOrder(candidate, existing) >= 0;
|
|
128
128
|
}
|
|
129
|
+
function orderFromReceipt(receipt) {
|
|
130
|
+
return { generatedAt: receipt.generatedAt, id: receipt.id };
|
|
131
|
+
}
|
|
132
|
+
function compareOrder(left, right) {
|
|
133
|
+
const leftTime = Date.parse(left.generatedAt);
|
|
134
|
+
const rightTime = Date.parse(right.generatedAt);
|
|
135
|
+
if (leftTime !== rightTime)
|
|
136
|
+
return leftTime - rightTime;
|
|
137
|
+
return left.id.localeCompare(right.id);
|
|
138
|
+
}
|
|
139
|
+
function maxOrder(left, right) {
|
|
140
|
+
if (!left)
|
|
141
|
+
return right;
|
|
142
|
+
if (!right)
|
|
143
|
+
return left;
|
|
144
|
+
return compareOrder(left, right) >= 0 ? left : right;
|
|
145
|
+
}
|
|
146
|
+
function isOrder(value) {
|
|
147
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
148
|
+
return false;
|
|
149
|
+
const record = value;
|
|
150
|
+
return typeof record.generatedAt === "string"
|
|
151
|
+
&& isValidTimestamp(record.generatedAt)
|
|
152
|
+
&& typeof record.id === "string";
|
|
153
|
+
}
|
|
154
|
+
function sentinelWatermarkPath(agentRoot) {
|
|
155
|
+
return path.join(agentRoot, "state", "arc", "context-loss-sentinel-watermark.json");
|
|
156
|
+
}
|
|
157
|
+
function readWatermark(agentRoot) {
|
|
158
|
+
const filePath = sentinelWatermarkPath(agentRoot);
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
161
|
+
return {
|
|
162
|
+
schemaVersion: 1,
|
|
163
|
+
latest: isOrder(parsed.latest) ? parsed.latest : null,
|
|
164
|
+
latestReady: isOrder(parsed.latestReady) ? parsed.latestReady : null,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return { schemaVersion: 1, latest: null, latestReady: null };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function writeWatermark(agentRoot, watermark) {
|
|
172
|
+
atomicWriteJson(sentinelWatermarkPath(agentRoot), watermark);
|
|
173
|
+
}
|
|
174
|
+
function updateWatermarkOrder(watermark, key, candidate) {
|
|
175
|
+
watermark[key] = maxOrder(watermark[key], orderFromReceipt(candidate));
|
|
176
|
+
}
|
|
177
|
+
function stableReceiptState(receipt) {
|
|
178
|
+
return JSON.stringify({
|
|
179
|
+
verdict: receipt.verdict,
|
|
180
|
+
summary: receipt.summary,
|
|
181
|
+
latestReadyLocator: receipt.latestReadyLocator,
|
|
182
|
+
recoveryAnchor: receipt.recoveryAnchor,
|
|
183
|
+
gauntlet: receipt.gauntlet,
|
|
184
|
+
signals: receipt.signals,
|
|
185
|
+
resumeSnapshot: receipt.resumeSnapshot,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function sameRecoveryState(left, right) {
|
|
189
|
+
return stableReceiptState(left) === stableReceiptState(right);
|
|
190
|
+
}
|
|
191
|
+
function setReceiptFileMtime(filePath, receipt) {
|
|
192
|
+
const timestamp = new Date(receipt.generatedAt);
|
|
193
|
+
fs.utimesSync(filePath, timestamp, timestamp);
|
|
194
|
+
}
|
|
195
|
+
function selectLatestReadyReceipt(existingReady, candidate, latestReadyOrder) {
|
|
196
|
+
if (candidate.verdict !== "ready")
|
|
197
|
+
return existingReady;
|
|
198
|
+
if (latestReadyOrder && compareOrder(orderFromReceipt(candidate), latestReadyOrder) < 0)
|
|
199
|
+
return existingReady;
|
|
200
|
+
return candidate;
|
|
201
|
+
}
|
|
202
|
+
function shouldReplaceLatestReceipt(existingLatest, candidate, latestOrder) {
|
|
203
|
+
if (latestOrder && compareOrder(orderFromReceipt(candidate), latestOrder) < 0)
|
|
204
|
+
return false;
|
|
205
|
+
if (!existingLatest)
|
|
206
|
+
return true;
|
|
207
|
+
return shouldReplaceReceipt(existingLatest, candidate);
|
|
208
|
+
}
|
|
209
|
+
function coalescedDaemonHealthReceipt(agentRoot, existingLatest, existingReady, candidate, watermark) {
|
|
210
|
+
if (candidate.trigger !== "daemon_health")
|
|
211
|
+
return null;
|
|
212
|
+
if (!existingLatest || !sameRecoveryState(existingLatest, candidate))
|
|
213
|
+
return null;
|
|
214
|
+
if (candidate.verdict === "ready" && (!existingReady || !sameRecoveryState(existingReady, candidate)))
|
|
215
|
+
return null;
|
|
216
|
+
const candidateOrder = orderFromReceipt(candidate);
|
|
217
|
+
if (watermark.latest && compareOrder(candidateOrder, watermark.latest) <= 0)
|
|
218
|
+
return existingLatest;
|
|
219
|
+
updateWatermarkOrder(watermark, "latest", candidate);
|
|
220
|
+
if (candidate.verdict === "ready" && existingReady) {
|
|
221
|
+
updateWatermarkOrder(watermark, "latestReady", candidate);
|
|
222
|
+
}
|
|
223
|
+
writeWatermark(agentRoot, watermark);
|
|
224
|
+
return existingLatest;
|
|
225
|
+
}
|
|
129
226
|
function readJson(filePath) {
|
|
130
227
|
try {
|
|
131
228
|
return { ok: true, value: JSON.parse(fs.readFileSync(filePath, "utf-8")) };
|
|
@@ -619,26 +716,38 @@ function recordBlockedReceiptEvent(agentRoot, receipt) {
|
|
|
619
716
|
}
|
|
620
717
|
async function persistReceipt(agentRoot, receipt, lockTimeoutMs) {
|
|
621
718
|
const paths = contextLossSentinelPaths(agentRoot);
|
|
622
|
-
|
|
719
|
+
return withFileLock(paths.lock, lockTimeoutMs, async () => {
|
|
623
720
|
ensureSentinelDirs(paths);
|
|
624
721
|
const existingLatest = readReceiptFile(paths.latest, "latest.json", []);
|
|
625
722
|
const existingReady = readLatestReady(agentRoot);
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
723
|
+
const watermark = readWatermark(agentRoot);
|
|
724
|
+
const latestOrder = maxOrder(maxOrder(maxOrder(existingLatest ? orderFromReceipt(existingLatest) : null, existingReady ? orderFromReceipt(existingReady) : null), watermark.latest), watermark.latestReady);
|
|
725
|
+
const latestReadyOrder = maxOrder(maxOrder(existingReady ? orderFromReceipt(existingReady) : null, watermark.latestReady), existingLatest?.verdict === "ready" ? orderFromReceipt(existingLatest) : null);
|
|
726
|
+
const nextReady = selectLatestReadyReceipt(existingReady, receipt, latestReadyOrder);
|
|
629
727
|
syncLatestReadyState(receipt, nextReady);
|
|
728
|
+
const coalesced = coalescedDaemonHealthReceipt(agentRoot, existingLatest, existingReady, receipt, watermark);
|
|
729
|
+
if (coalesced)
|
|
730
|
+
return coalesced;
|
|
630
731
|
atomicWriteJson(path.join(paths.receiptsDir, `${receipt.id}.json`), receipt);
|
|
631
732
|
appendHistory(paths, receipt);
|
|
632
|
-
if (
|
|
733
|
+
if (shouldReplaceLatestReceipt(existingLatest, receipt, latestOrder)) {
|
|
633
734
|
atomicWriteJson(paths.latest, receipt);
|
|
735
|
+
updateWatermarkOrder(watermark, "latest", receipt);
|
|
736
|
+
writeWatermark(agentRoot, watermark);
|
|
737
|
+
setReceiptFileMtime(paths.latest, receipt);
|
|
634
738
|
recordBlockedReceiptEvent(agentRoot, receipt);
|
|
635
739
|
}
|
|
636
|
-
else if (existingLatest &&
|
|
637
|
-
|
|
740
|
+
else if (existingLatest && nextReady === receipt) {
|
|
741
|
+
const updatedLatest = syncLatestReadyState(existingLatest, nextReady);
|
|
742
|
+
atomicWriteJson(paths.latest, updatedLatest);
|
|
638
743
|
}
|
|
639
744
|
if (receipt.verdict === "ready" && nextReady === receipt) {
|
|
640
745
|
atomicWriteJson(paths.latestReady, receipt);
|
|
746
|
+
updateWatermarkOrder(watermark, "latestReady", receipt);
|
|
747
|
+
writeWatermark(agentRoot, watermark);
|
|
748
|
+
setReceiptFileMtime(paths.latestReady, receipt);
|
|
641
749
|
}
|
|
750
|
+
return receipt;
|
|
642
751
|
});
|
|
643
752
|
}
|
|
644
753
|
async function refreshContextLossSentinel(agentName, agentRoot, options) {
|
|
@@ -647,7 +756,7 @@ async function refreshContextLossSentinel(agentName, agentRoot, options) {
|
|
|
647
756
|
if (options.delayBeforeWriteMs && options.delayBeforeWriteMs > 0) {
|
|
648
757
|
await sleep(options.delayBeforeWriteMs);
|
|
649
758
|
}
|
|
650
|
-
await persistReceipt(agentRoot, receipt, options.lockTimeoutMs ?? 5_000);
|
|
759
|
+
const persistedReceipt = await persistReceipt(agentRoot, receipt, options.lockTimeoutMs ?? 5_000);
|
|
651
760
|
(0, runtime_1.emitNervesEvent)({
|
|
652
761
|
component: "engine",
|
|
653
762
|
event: "engine.context_loss_sentinel_refreshed",
|
|
@@ -655,13 +764,13 @@ async function refreshContextLossSentinel(agentName, agentRoot, options) {
|
|
|
655
764
|
meta: {
|
|
656
765
|
agentName,
|
|
657
766
|
trigger: options.trigger,
|
|
658
|
-
verdict:
|
|
659
|
-
receiptId:
|
|
660
|
-
blockedSignals:
|
|
661
|
-
watchSignals:
|
|
767
|
+
verdict: persistedReceipt.verdict,
|
|
768
|
+
receiptId: persistedReceipt.id,
|
|
769
|
+
blockedSignals: persistedReceipt.signals.filter((entry) => entry.verdictImpact === "blocked").map((entry) => entry.id),
|
|
770
|
+
watchSignals: persistedReceipt.signals.filter((entry) => entry.verdictImpact === "watch").map((entry) => entry.id),
|
|
662
771
|
},
|
|
663
772
|
});
|
|
664
|
-
return
|
|
773
|
+
return persistedReceipt;
|
|
665
774
|
}
|
|
666
775
|
function readHistory(paths, limit, issues) {
|
|
667
776
|
if (!fs.existsSync(paths.historyDir))
|