@jjh32456/longlive 0.0.0-stage → 2.0.0
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.md +235 -0
- package/LICENSE +21 -0
- package/QUICKSTART.md +362 -0
- package/README.en.md +64 -0
- package/README.md +256 -2
- package/SPEC.md +211 -0
- package/build-info.json +1665 -0
- package/cordis.patch.yml +208 -0
- package/docs/A1-MIGRATION.md +75 -0
- package/docs/ANSWER-GUARD.md +92 -0
- package/docs/ARCHITECTURE.md +128 -0
- package/docs/AUTO-RECALL-WIRING.md +115 -0
- package/docs/AUTO-RECALL.md +237 -0
- package/docs/CONCEPTS.md +143 -0
- package/docs/CONFIG.md +839 -0
- package/docs/ERRORS.md +271 -0
- package/docs/FAQ.md +186 -0
- package/docs/FEATURES.md +579 -0
- package/docs/INDEX-FRESHNESS.md +21 -0
- package/docs/METRICS.md +244 -0
- package/docs/MIGRATION-1.6.0.md +220 -0
- package/docs/OPERATIONS.md +439 -0
- package/docs/PANEL-INTEGRATION.md +190 -0
- package/docs/PRIVACY.md +88 -0
- package/docs/QUICKSTART.md +155 -0
- package/docs/RAW-INDEX-POLICY.md +7 -0
- package/docs/README.en.md +48 -0
- package/docs/RESIDENT-WATCHER.md +90 -0
- package/docs/SESSION-WATCH.md +214 -0
- package/docs/TOOLS.md +184 -0
- package/docs/TROUBLESHOOTING.md +329 -0
- package/icon.svg +11 -0
- package/lib/client.js +436 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +163 -4
- package/runbook.md +343 -0
- package/scripts/archive-digest-build.mjs +668 -0
- package/scripts/auto-truncate-run.ps1 +752 -0
- package/scripts/backfill-auto-cards.mjs +98 -0
- package/scripts/edges-build.mjs +1003 -0
- package/scripts/index-maintain.mjs +39 -0
- package/scripts/index-reconcile.mjs +49 -0
- package/scripts/index-status.mjs +28 -0
- package/scripts/install-resident-watcher.ps1 +15 -0
- package/scripts/install-session-watch.ps1 +332 -0
- package/scripts/install-surgery-task.ps1 +174 -0
- package/scripts/lib/auto-truncate-run.ps1 +512 -0
- package/scripts/lib/session-watch-fixture.mjs +207 -0
- package/scripts/longlive-doctor.mjs +578 -0
- package/scripts/metrics-read.mjs +79 -0
- package/scripts/metrics-sample.mjs +215 -0
- package/scripts/migrate-180.mjs +163 -0
- package/scripts/migrate-200.mjs +8 -0
- package/scripts/migrate-a1-legacy.mjs +62 -0
- package/scripts/migrate-lifecycle.mjs +157 -0
- package/scripts/pack.mjs +392 -0
- package/scripts/recall-index-build.mjs +128 -0
- package/scripts/recall-links-build.mjs +420 -0
- package/scripts/rescore-cards.mjs +36 -0
- package/scripts/resident-watcher-status.ps1 +15 -0
- package/scripts/resident-watcher.ps1 +643 -0
- package/scripts/session-watch-drill.mjs +553 -0
- package/scripts/session-watch-status.ps1 +146 -0
- package/scripts/session-watch.mjs +1367 -0
- package/scripts/surgery-inspect.mjs +122 -0
- package/scripts/surgery-run.cmd +34 -0
- package/scripts/truncate-cli.mjs +279 -0
- package/scripts/unattended-surgery.ps1 +1019 -0
- package/scripts/uninstall-resident-watcher.ps1 +15 -0
- package/scripts/uninstall-session-watch.ps1 +192 -0
- package/scripts/verify-card-anchors.mjs +138 -0
- package/scripts/watch-loop.ps1 +916 -0
- package/src/actions/audit.js +125 -0
- package/src/actions/evidence.js +122 -0
- package/src/actions/fs.js +162 -0
- package/src/activity/index.js +873 -0
- package/src/activity/model.js +351 -0
- package/src/activity/store.js +786 -0
- package/src/activity/summary.js +180 -0
- package/src/activity/thinking.js +191 -0
- package/src/adapters/constants.js +11 -0
- package/src/adapters/engram/data/aliases.json +51 -0
- package/src/adapters/engram/data/policy.json +8 -0
- package/src/adapters/engram/data/routing-rules.json +546 -0
- package/src/adapters/engram/index.js +278 -0
- package/src/adapters/registry.js +315 -0
- package/src/answer/audit.js +238 -0
- package/src/answer/claim-guard.mjs +234 -0
- package/src/answer/evidence.js +30 -0
- package/src/answer/guard.js +1370 -0
- package/src/answer/index.js +1086 -0
- package/src/answer/query.js +111 -0
- package/src/answer/second-hop.mjs +101 -0
- package/src/auto-truncate-status.js +164 -0
- package/src/auto-truncate.js +1181 -0
- package/src/autoprocedure/candidate.js +342 -0
- package/src/autoprocedure/config.js +122 -0
- package/src/autoprocedure/evidence.js +345 -0
- package/src/autoprocedure/index.js +83 -0
- package/src/autoprocedure/ledger.js +329 -0
- package/src/autoprocedure/lint.js +232 -0
- package/src/autoprocedure/llm.js +409 -0
- package/src/autoprocedure/locks.js +102 -0
- package/src/autoprocedure/paths.js +39 -0
- package/src/autoprocedure/privacy.js +87 -0
- package/src/autoprocedure/rules.js +288 -0
- package/src/autoprocedure/runtime.js +718 -0
- package/src/autoprocedure/session-reader.js +328 -0
- package/src/backup.js +310 -0
- package/src/bus/bus.mjs +1446 -0
- package/src/codec.js +269 -0
- package/src/compaction/cut-engine.js +44 -0
- package/src/compaction/engine-core.js +1237 -0
- package/src/compaction/entry.js +228 -0
- package/src/compaction.js +230 -0
- package/src/conclusion.js +366 -0
- package/src/config.js +835 -0
- package/src/d6/runtime.js +517 -0
- package/src/d6/surface.js +181 -0
- package/src/deps.js +189 -0
- package/src/engine-status.js +141 -0
- package/src/features.js +1035 -0
- package/src/handoff/index.js +1077 -0
- package/src/handoff/model.js +1058 -0
- package/src/handoff/store.js +1233 -0
- package/src/heartbeat.js +385 -0
- package/src/home.js +16 -0
- package/src/host-version.js +280 -0
- package/src/hot-truncate-diag.js +98 -0
- package/src/identity/card-marker.js +281 -0
- package/src/identity/handover.js +845 -0
- package/src/identity/index.js +337 -0
- package/src/identity/inject-position.js +133 -0
- package/src/identity/writeback.js +344 -0
- package/src/identity.js +118 -0
- package/src/index.js +647 -0
- package/src/lifecycle/gap-clocks.js +364 -0
- package/src/lifecycle/index.js +269 -0
- package/src/lifecycle/proactive.js +1426 -0
- package/src/live-target.js +212 -0
- package/src/live.js +1603 -0
- package/src/log-rotation.js +153 -0
- package/src/memory/a1-migration.js +190 -0
- package/src/memory/activity-capture.js +229 -0
- package/src/memory/anchor-fallback.js +116 -0
- package/src/memory/anchors.js +194 -0
- package/src/memory/archive-cold-state.mjs +794 -0
- package/src/memory/archive-staging.mjs +305 -0
- package/src/memory/archive.mjs +415 -0
- package/src/memory/audit-records.js +222 -0
- package/src/memory/auto-cards.js +441 -0
- package/src/memory/capture-host.js +297 -0
- package/src/memory/capture.js +496 -0
- package/src/memory/card-anchors.js +203 -0
- package/src/memory/card-priority.js +110 -0
- package/src/memory/cards.js +425 -0
- package/src/memory/catchup.mjs +534 -0
- package/src/memory/conclusion-distill.js +381 -0
- package/src/memory/conclusion-drafts.js +243 -0
- package/src/memory/conflicts.js +1060 -0
- package/src/memory/consolidate.js +834 -0
- package/src/memory/decay.js +311 -0
- package/src/memory/distill.js +485 -0
- package/src/memory/event-index.js +1826 -0
- package/src/memory/evidence-chain.js +295 -0
- package/src/memory/evidence.js +213 -0
- package/src/memory/filter-runner.js +555 -0
- package/src/memory/filter.js +1035 -0
- package/src/memory/forget-v2.js +680 -0
- package/src/memory/forget.js +531 -0
- package/src/memory/frames-activation.js +249 -0
- package/src/memory/frontmatter.js +454 -0
- package/src/memory/fts-query.js +342 -0
- package/src/memory/governance.js +604 -0
- package/src/memory/index-freshness.js +234 -0
- package/src/memory/index.js +435 -0
- package/src/memory/l2-gate.js +169 -0
- package/src/memory/land.mjs +743 -0
- package/src/memory/lifecycle.js +235 -0
- package/src/memory/lock.js +121 -0
- package/src/memory/maintenance.js +1149 -0
- package/src/memory/manifest.js +245 -0
- package/src/memory/memory-health.mjs +607 -0
- package/src/memory/migrate-200.js +1681 -0
- package/src/memory/migrate-lifecycle.js +1808 -0
- package/src/memory/migrate.js +139 -0
- package/src/memory/paths.js +229 -0
- package/src/memory/procedure-candidate.mjs +377 -0
- package/src/memory/procedure.js +982 -0
- package/src/memory/prospective-memory.mjs +362 -0
- package/src/memory/provenance.js +119 -0
- package/src/memory/recall-feedback.mjs +406 -0
- package/src/memory/recall-v2.js +218 -0
- package/src/memory/recall.js +357 -0
- package/src/memory/reconcile.js +265 -0
- package/src/memory/records.js +433 -0
- package/src/memory/reinforce.js +281 -0
- package/src/memory/retention.js +162 -0
- package/src/memory/review.js +124 -0
- package/src/memory/state.js +279 -0
- package/src/memory/tiers.js +168 -0
- package/src/memory/topic-phrases.js +73 -0
- package/src/memory/trust.js +97 -0
- package/src/memory/turn-budget.mjs +290 -0
- package/src/memory/version-chain.js +264 -0
- package/src/memory/wake-bridge.mjs +2999 -0
- package/src/memory/wal.js +137 -0
- package/src/memory/working-frame.js +779 -0
- package/src/metrics/classify.mjs +191 -0
- package/src/metrics/estimate.mjs +108 -0
- package/src/metrics/index.mjs +204 -0
- package/src/metrics/measure.mjs +462 -0
- package/src/metrics/prestep-latency.mjs +307 -0
- package/src/metrics/store.mjs +264 -0
- package/src/original.js +294 -0
- package/src/policy/threshold-policy.js +224 -0
- package/src/policy-profile.js +463 -0
- package/src/recall/anaphora.mjs +87 -0
- package/src/recall/archive-config.mjs +130 -0
- package/src/recall/archive-fallback.mjs +390 -0
- package/src/recall/archive-search.mjs +428 -0
- package/src/recall/archive-state.mjs +588 -0
- package/src/recall/brain.mjs +501 -0
- package/src/recall/cards.mjs +202 -0
- package/src/recall/current-line.mjs +110 -0
- package/src/recall/edges.js +398 -0
- package/src/recall/embedding.mjs +698 -0
- package/src/recall/entities.mjs +112 -0
- package/src/recall/explain.mjs +443 -0
- package/src/recall/force-policy.mjs +138 -0
- package/src/recall/gate-log.mjs +280 -0
- package/src/recall/gate-metrics.mjs +191 -0
- package/src/recall/index.js +1337 -0
- package/src/recall/inject-order.mjs +279 -0
- package/src/recall/link-recall.mjs +183 -0
- package/src/recall/links.mjs +696 -0
- package/src/recall/privacy.mjs +208 -0
- package/src/recall/recall-core.mjs +810 -0
- package/src/recall/shared-visibility.js +302 -0
- package/src/recall/time-normalizer.mjs +196 -0
- package/src/recall/turn-budget-inject.mjs +154 -0
- package/src/retention/cold-gate.mjs +146 -0
- package/src/retention/config.js +163 -0
- package/src/retention/index.js +801 -0
- package/src/role/activation.js +191 -0
- package/src/role/attention.js +318 -0
- package/src/role/base.js +36 -0
- package/src/role/channels.js +423 -0
- package/src/role/index.js +425 -0
- package/src/role/interfaces.js +115 -0
- package/src/role/personality.js +370 -0
- package/src/role/readers.js +151 -0
- package/src/role/relationships.js +477 -0
- package/src/role/store.js +202 -0
- package/src/role/writeprotect.js +373 -0
- package/src/router/aliases.json +182 -0
- package/src/router/background/agent-runner.mjs +239 -0
- package/src/router/background/anchor.mjs +323 -0
- package/src/router/background/audit.mjs +337 -0
- package/src/router/background/budget-ledger.mjs +648 -0
- package/src/router/background/host-sim.mjs +451 -0
- package/src/router/background/index.mjs +81 -0
- package/src/router/background/memory.mjs +63 -0
- package/src/router/background/mock-llm.mjs +203 -0
- package/src/router/background/queue.mjs +224 -0
- package/src/router/background/retry.mjs +255 -0
- package/src/router/background/router.mjs +1459 -0
- package/src/router/background/stream.mjs +276 -0
- package/src/router/background/tool-policy.mjs +255 -0
- package/src/router/design-headings.json +221 -0
- package/src/router/face/config.mjs +155 -0
- package/src/router/face/context.mjs +284 -0
- package/src/router/face/face.mjs +466 -0
- package/src/router/face/identity.mjs +130 -0
- package/src/router/face/index.mjs +65 -0
- package/src/router/face/journal.mjs +119 -0
- package/src/router/face/llm.mjs +252 -0
- package/src/router/face/outbox.mjs +153 -0
- package/src/router/face/paths.mjs +54 -0
- package/src/router/judge.mjs +987 -0
- package/src/router/policies/generic.json +131 -0
- package/src/router/route.js +1766 -0
- package/src/router/router.mjs +535 -0
- package/src/router/routing-rules.json +816 -0
- package/src/router/run-sim.mjs +530 -0
- package/src/router/runtime.js +569 -0
- package/src/router/service/apply.mjs +1218 -0
- package/src/router/service/board.mjs +712 -0
- package/src/router/service/caller.mjs +131 -0
- package/src/router/service/config.mjs +361 -0
- package/src/router/service/context.mjs +314 -0
- package/src/router/service/hint.mjs +668 -0
- package/src/router/service/lease.mjs +494 -0
- package/src/router/service/live.mjs +251 -0
- package/src/router/service/lock.mjs +550 -0
- package/src/router/service/merge.mjs +255 -0
- package/src/router/service/model-resolve.mjs +350 -0
- package/src/router/service/paths.mjs +168 -0
- package/src/router/service/proposals.mjs +1461 -0
- package/src/router/service/queue.mjs +477 -0
- package/src/router/service/reconcile.mjs +271 -0
- package/src/router/service/service.mjs +2998 -0
- package/src/router/service/sources.mjs +352 -0
- package/src/router/service/status.mjs +520 -0
- package/src/router/service/store.mjs +476 -0
- package/src/router/service/ticklock.mjs +239 -0
- package/src/router/service/tokens.mjs +95 -0
- package/src/router/service/tools.mjs +248 -0
- package/src/router/service/wake.mjs +544 -0
- package/src/router/service/wal.mjs +685 -0
- package/src/router/shadow.mjs +821 -0
- package/src/surgery-recovery.js +1909 -0
- package/src/tool-output.js +485 -0
- package/src/tools.js +3262 -0
- package/src/truncate-visible.js +2416 -0
- package/src/truncate.js +999 -0
- package/src/ui/actions.js +1312 -0
- package/src/ui/flags.js +259 -0
- package/src/ui/panel-api.js +371 -0
- package/src/ui/panel-auth.js +251 -0
- package/src/ui/panel-integrity.js +243 -0
- package/src/ui/routes-readonly.js +759 -0
- package/src/ui/routes.js +284 -0
- package/src/util/append-store.js +368 -0
- package/src/util/local-day.js +30 -0
- package/src/util/redact.js +227 -0
- package/src/util/stale-locks.js +148 -0
- package/src/version.js +99 -0
- package/test/fixtures/pre-step-container.mjs +100 -0
- package/test/p1_probe.mjs +97 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
// memory/catchup.mjs — hardgate 补跑(D 补跑 / 批 C W1c 实装)
|
|
2
|
+
//
|
|
3
|
+
// 设计依据(DESIGN v0.5.1 §9 / CATCHUP-SPEC):
|
|
4
|
+
// - 双路触发:装载期 startup tick + 每宿主进程首个 pre-step;本文件只提供
|
|
5
|
+
// 纯状态机,接线由宿主入口调用(features apply)。
|
|
6
|
+
// - 状态:.longlive/hardgate/last-run.json(schema hardgate-last-run/v1),
|
|
7
|
+
// 与 .longlive/bridge/schedule.json 对账;两处任一日成功即视为当日已跑。
|
|
8
|
+
// - 决定函数 decideCatchUp 是纯函数(不读写盘、不记日志),补跑执行是
|
|
9
|
+
// runCatchUp:锁 → 重读 → 跑蒸馏槽 → 成功推进/失败退避。
|
|
10
|
+
// - 失败退避 15m / 60m / 6h,3 次 terminal,6h 后新 episode;永不向宿主抛。
|
|
11
|
+
//
|
|
12
|
+
// 出口门:d10(maintenance gate-on 0 failed)。d10 夹具从这里拿
|
|
13
|
+
// runCatchUp / decideCatchUp,并检查 decideCatchUp 是纯函数。
|
|
14
|
+
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
|
|
18
|
+
import { dayString, isoStamp } from './frontmatter.js';
|
|
19
|
+
import { writeFileAtomic } from './state.js';
|
|
20
|
+
import {
|
|
21
|
+
runDailyMaintenance,
|
|
22
|
+
readScheduleState,
|
|
23
|
+
writeScheduleState,
|
|
24
|
+
acquireScheduleLock,
|
|
25
|
+
} from './maintenance.js';
|
|
26
|
+
import { appendGateLog } from '../recall/gate-log.mjs';
|
|
27
|
+
|
|
28
|
+
export const BATCH = 'C';
|
|
29
|
+
export const MODULE = 'memory/catchup.mjs';
|
|
30
|
+
// 骨架期常量保留,便于旧测试/诊断按名引用;不再是实际行为。
|
|
31
|
+
export const UNIMPLEMENTED_CODE = 'E_HG_CATCHUP_UNIMPLEMENTED';
|
|
32
|
+
export const UNSET = Object.freeze({ status: 'UNSET' });
|
|
33
|
+
// 2.0.0 W3b(⑧):archive-state 是每日维护的第五个槽,补跑表必须认得它,
|
|
34
|
+
// 否则错过的周日探针永远不会补写(槽名与 maintenance 的 lastArchiveStateDate 对账)。
|
|
35
|
+
export const CATCHUP_SLOTS = Object.freeze(['forget-suggestions', 'review-sweep', 'archive-state']);
|
|
36
|
+
export const FAILED_DAY_STATUS = 'failed';
|
|
37
|
+
|
|
38
|
+
export const CATCHUP_SCHEMA = 'hardgate-last-run/v1';
|
|
39
|
+
export const LAST_RUN_REL = '.longlive/hardgate/last-run.json';
|
|
40
|
+
export const GATE_LOG_REL = '.longlive/hardgate/gate-log.jsonl';
|
|
41
|
+
export const CATCHUP_GATE = 'D.catchup';
|
|
42
|
+
export const CATCHUP_PERIOD_MS = 24 * 60 * 60 * 1000;
|
|
43
|
+
export const CATCHUP_TOLERANCE_MS = 5 * 60 * 1000;
|
|
44
|
+
export const CATCHUP_MAX_ATTEMPTS = 3;
|
|
45
|
+
export const CATCHUP_BACKOFF_MS = Object.freeze([15 * 60 * 1000, 60 * 60 * 1000, 6 * 60 * 60 * 1000]);
|
|
46
|
+
export const CATCHUP_TERMINAL_COOLDOWN_MS = 6 * 60 * 60 * 1000;
|
|
47
|
+
export const CATCHUP_TIMEOUT_MS = 120 * 1000;
|
|
48
|
+
export const SKELETON = Object.freeze({
|
|
49
|
+
version: '2.0.0', failClosed: true, batch: 'C', implemented: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function sha256Text(text) {
|
|
53
|
+
// 只用于状态指纹,不参与安全判断。
|
|
54
|
+
return Buffer.from(String(text)).toString('base64').slice(0, 16);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function catchupError(code, message) {
|
|
58
|
+
const error = new Error(message ?? String(code));
|
|
59
|
+
error.name = 'HardgateCatchupError';
|
|
60
|
+
error.code = code;
|
|
61
|
+
return error;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function toDate(value, fallback = new Date()) {
|
|
65
|
+
const at = value instanceof Date ? value : new Date(value ?? fallback);
|
|
66
|
+
return Number.isNaN(at.getTime()) ? fallback : at;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function parseMs(value) {
|
|
70
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
71
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
72
|
+
const ms = Date.parse(value);
|
|
73
|
+
return Number.isFinite(ms) ? ms : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function lastRunPath(memoryRoot) {
|
|
77
|
+
return path.join(String(memoryRoot), LAST_RUN_REL);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function emptyLastRun() {
|
|
81
|
+
return {
|
|
82
|
+
schema: CATCHUP_SCHEMA,
|
|
83
|
+
updatedAt: null,
|
|
84
|
+
distill: {
|
|
85
|
+
lastAttemptAt: null,
|
|
86
|
+
lastSuccessAt: null,
|
|
87
|
+
lastSuccessDay: null,
|
|
88
|
+
catchUpNeeded: false,
|
|
89
|
+
attempts: 0,
|
|
90
|
+
terminal: false,
|
|
91
|
+
nextRetryAt: null,
|
|
92
|
+
lastError: null,
|
|
93
|
+
lastTrigger: null,
|
|
94
|
+
lastResult: null,
|
|
95
|
+
lastDecision: null,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function normalizeLastRun(raw) {
|
|
101
|
+
const base = emptyLastRun();
|
|
102
|
+
if (!raw || typeof raw !== 'object') return base;
|
|
103
|
+
const distill = raw.distill && typeof raw.distill === 'object' ? raw.distill : {};
|
|
104
|
+
const attempts = Number.isFinite(Number(distill.attempts)) ? Math.max(0, Math.floor(Number(distill.attempts))) : 0;
|
|
105
|
+
return {
|
|
106
|
+
...base,
|
|
107
|
+
...raw,
|
|
108
|
+
schema: CATCHUP_SCHEMA,
|
|
109
|
+
distill: {
|
|
110
|
+
...base.distill,
|
|
111
|
+
...distill,
|
|
112
|
+
attempts,
|
|
113
|
+
terminal: distill.terminal === true,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** 读 last-run.json:缺失=空态;坏文件=corrupt 标记 + 空态(不抛)。 */
|
|
119
|
+
export function readLastRun(memoryRoot) {
|
|
120
|
+
const file = lastRunPath(memoryRoot);
|
|
121
|
+
if (!fs.existsSync(file)) return { ok: true, exists: false, corrupt: null, doc: emptyLastRun(), path: file };
|
|
122
|
+
try {
|
|
123
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
124
|
+
if (!parsed || parsed.schema !== CATCHUP_SCHEMA) {
|
|
125
|
+
return { ok: false, exists: true, corrupt: 'schema', doc: emptyLastRun(), path: file };
|
|
126
|
+
}
|
|
127
|
+
return { ok: true, exists: true, corrupt: null, doc: normalizeLastRun(parsed), path: file };
|
|
128
|
+
} catch (error) {
|
|
129
|
+
return { ok: false, exists: true, corrupt: String(error?.message ?? error), doc: emptyLastRun(), path: file };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** 原子写 last-run.json(tmp→rename,写后读回)。 */
|
|
134
|
+
export function writeLastRun(memoryRoot, doc, now = new Date()) {
|
|
135
|
+
const at = toDate(now);
|
|
136
|
+
const next = normalizeLastRun({ ...doc, schema: CATCHUP_SCHEMA, updatedAt: isoStamp(at) });
|
|
137
|
+
const write = writeFileAtomic(memoryRoot, lastRunPath(memoryRoot), `${JSON.stringify(next, null, 2)}\n`, { backup: false, now: at });
|
|
138
|
+
return { doc: next, write };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function daysBetweenDays(fromDay, toDay) {
|
|
142
|
+
const from = Date.parse(`${fromDay}T00:00:00Z`);
|
|
143
|
+
const to = Date.parse(`${toDay}T00:00:00Z`);
|
|
144
|
+
if (!Number.isFinite(from) || !Number.isFinite(to)) return null;
|
|
145
|
+
return Math.max(0, Math.round((to - from) / (24 * 60 * 60 * 1000)));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 纯函数:输入 now + lastRun + schedule,输出 {action:'run'|'skip', reason, ...}。
|
|
150
|
+
* 不写盘、不读盘、不记日志(d10 的 d10.prereq.decideCatchUp-pure 会检查)。
|
|
151
|
+
*/
|
|
152
|
+
export function decideCatchUp(input = {}) {
|
|
153
|
+
// 兼容 (now, lastRun, schedule) 位置参数。
|
|
154
|
+
let now;
|
|
155
|
+
let lastRun;
|
|
156
|
+
let schedule;
|
|
157
|
+
if (input instanceof Date || typeof input === 'string' || typeof input === 'number') {
|
|
158
|
+
now = input;
|
|
159
|
+
lastRun = arguments.length > 1 ? arguments[1] : null;
|
|
160
|
+
schedule = arguments.length > 2 ? arguments[2] : null;
|
|
161
|
+
} else if (input && typeof input === 'object') {
|
|
162
|
+
now = input.now;
|
|
163
|
+
lastRun = input.lastRun;
|
|
164
|
+
schedule = input.schedule;
|
|
165
|
+
}
|
|
166
|
+
const at = toDate(now);
|
|
167
|
+
const nowMs = at.getTime();
|
|
168
|
+
const day = dayString(at);
|
|
169
|
+
const dist = normalizeLastRun(lastRun).distill;
|
|
170
|
+
const sched = schedule && typeof schedule === 'object' ? schedule : {};
|
|
171
|
+
|
|
172
|
+
const schedAtMs = parseMs(sched.lastConclusionDistillAt);
|
|
173
|
+
const schedDay = typeof sched.lastConclusionDistillDate === 'string' ? sched.lastConclusionDistillDate : null;
|
|
174
|
+
const schedErrorDay = typeof sched.lastConclusionDistillError?.day === 'string' ? sched.lastConclusionDistillError.day : null;
|
|
175
|
+
const lastSuccessMs = Math.max(parseMs(dist.lastSuccessAt) ?? 0, schedAtMs ?? 0);
|
|
176
|
+
const lastAttemptMs = parseMs(dist.lastAttemptAt) ?? 0;
|
|
177
|
+
let attempts = dist.attempts;
|
|
178
|
+
let terminal = dist.terminal;
|
|
179
|
+
let nextRetryMs = parseMs(dist.nextRetryAt);
|
|
180
|
+
let forceRun = false;
|
|
181
|
+
|
|
182
|
+
// 1) terminal 冷却到期 → 新 episode(attempts 归零、清 nextRetryAt)。
|
|
183
|
+
if (terminal) {
|
|
184
|
+
const cooldownFrom = lastAttemptMs || nextRetryMs;
|
|
185
|
+
if (!cooldownFrom || nowMs - cooldownFrom >= CATCHUP_TERMINAL_COOLDOWN_MS) {
|
|
186
|
+
attempts = 0;
|
|
187
|
+
terminal = false;
|
|
188
|
+
nextRetryMs = null;
|
|
189
|
+
forceRun = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const base = {
|
|
193
|
+
now: at.toISOString(),
|
|
194
|
+
day,
|
|
195
|
+
attempts,
|
|
196
|
+
terminal,
|
|
197
|
+
nextRetryAt: nextRetryMs ? new Date(nextRetryMs).toISOString() : null,
|
|
198
|
+
gapMs: null,
|
|
199
|
+
missedDays: null,
|
|
200
|
+
};
|
|
201
|
+
const skip = (reason, extra = {}) => ({
|
|
202
|
+
...base, action: 'skip', outcome: 'skip', reason, ...extra,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// 2) 退避未到期 → 等。
|
|
206
|
+
if (nextRetryMs && nowMs < nextRetryMs) {
|
|
207
|
+
return skip('retry-backoff', { nextAt: new Date(nextRetryMs).toISOString() });
|
|
208
|
+
}
|
|
209
|
+
// 2b) 上一轮失败(失败晚于上次成功):立即重试,不受日周期节流。
|
|
210
|
+
if (!forceRun && attempts > 0 && lastAttemptMs > 0 && lastAttemptMs > lastSuccessMs) {
|
|
211
|
+
const retrySuccessDay = dist.lastSuccessDay
|
|
212
|
+
?? (lastSuccessMs ? dayString(new Date(lastSuccessMs)) : schedDay);
|
|
213
|
+
return {
|
|
214
|
+
...base,
|
|
215
|
+
action: 'run',
|
|
216
|
+
outcome: 'run',
|
|
217
|
+
reason: 'retry',
|
|
218
|
+
forceRun,
|
|
219
|
+
gapMs: lastAttemptMs ? nowMs - lastAttemptMs : null,
|
|
220
|
+
missedDays: retrySuccessDay ? daysBetweenDays(retrySuccessDay, day) : null,
|
|
221
|
+
lastSuccessDay: retrySuccessDay ?? null,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
// 3) 计划时钟回拨:now 早于上次成功 - 容差 → 等(防止双跑)。
|
|
225
|
+
if (lastSuccessMs && nowMs < lastSuccessMs - CATCHUP_TOLERANCE_MS) {
|
|
226
|
+
return skip('clock-rollback', { lastSuccessAt: new Date(lastSuccessMs).toISOString() });
|
|
227
|
+
}
|
|
228
|
+
// 4) 当日已成功(schedule 是跨会话的权威;自记 lastSuccessDay 是兜底)。
|
|
229
|
+
if (schedDay === day && schedErrorDay !== day) return skip('already-ran-today', { via: 'schedule' });
|
|
230
|
+
if (dist.lastSuccessDay === day && dist.lastError == null) return skip('already-ran-today', { via: 'last-run' });
|
|
231
|
+
// 5) 未到期:上一次活动(尝试或成功)距今不足一个周期(含容差)。
|
|
232
|
+
const lastActivityMs = Math.max(lastAttemptMs, lastSuccessMs);
|
|
233
|
+
const gapMs = lastActivityMs ? nowMs - lastActivityMs : null;
|
|
234
|
+
if (!forceRun && gapMs != null && gapMs < CATCHUP_PERIOD_MS - CATCHUP_TOLERANCE_MS) {
|
|
235
|
+
return skip('not-due', { gapMs });
|
|
236
|
+
}
|
|
237
|
+
// 6) 运行,并给出原因。
|
|
238
|
+
const neverRan = lastSuccessMs === 0;
|
|
239
|
+
let reason = neverRan ? 'never-ran' : 'overdue';
|
|
240
|
+
if (!neverRan && attempts > 0 && lastAttemptMs > lastSuccessMs) reason = 'retry';
|
|
241
|
+
const lastSuccessDay = dist.lastSuccessDay
|
|
242
|
+
?? (lastSuccessMs ? dayString(new Date(lastSuccessMs)) : schedDay);
|
|
243
|
+
const missedDays = lastSuccessDay ? daysBetweenDays(lastSuccessDay, day) : null;
|
|
244
|
+
return {
|
|
245
|
+
...base,
|
|
246
|
+
action: 'run',
|
|
247
|
+
outcome: 'run',
|
|
248
|
+
reason,
|
|
249
|
+
forceRun,
|
|
250
|
+
gapMs,
|
|
251
|
+
missedDays,
|
|
252
|
+
lastSuccessDay: lastSuccessDay ?? null,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function firstErrorCode(error, result) {
|
|
257
|
+
if (error) return String(error.code ?? error.message ?? error);
|
|
258
|
+
const errors = Array.isArray(result?.errors) ? result.errors : [];
|
|
259
|
+
const first = errors[0];
|
|
260
|
+
if (first && typeof first === 'object' && first.code) return String(first.code);
|
|
261
|
+
if (result?.conclusionDistill?.errors?.length) {
|
|
262
|
+
const inner = result.conclusionDistill.errors[0];
|
|
263
|
+
if (inner && typeof inner === 'object' && inner.code) return String(inner.code);
|
|
264
|
+
}
|
|
265
|
+
if (result?.conclusionDistill?.code) return String(result.conclusionDistill.code);
|
|
266
|
+
if (result?.code) return String(result.code);
|
|
267
|
+
return 'E_HG_DISTILL_FAILED';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function appendCatchupGate(memoryRoot, { reason, decision, evidence = [], at }) {
|
|
271
|
+
try {
|
|
272
|
+
return appendGateLog(memoryRoot, {
|
|
273
|
+
gate: CATCHUP_GATE,
|
|
274
|
+
decision,
|
|
275
|
+
reason,
|
|
276
|
+
evidence: evidence.map((item) => String(item)),
|
|
277
|
+
at: isoStamp(at),
|
|
278
|
+
sessionId: null,
|
|
279
|
+
turn: null,
|
|
280
|
+
});
|
|
281
|
+
} catch {
|
|
282
|
+
// gate-log 写失败不能反过来打断补跑:d10 只要求进程不抛。
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 执行一次补跑判定 + 蒸馏槽运行。
|
|
289
|
+
*
|
|
290
|
+
* @param {{memoryRoot:string, now?:Date, trigger?:string, config?:object,
|
|
291
|
+
* dailyConfig?:object, deps?:object}} options
|
|
292
|
+
* config/dailyConfig:宿主维护配置(可含 sessionsRoot/archiveState/journalRotate 等),
|
|
293
|
+
* 本函数只强制覆盖 consolidate/forget/forgetSuggestions/autoConclusion 四个开关。
|
|
294
|
+
* deps 可注入 {readSchedule, readLastRun, writeLastRun, gateLog, runDaily}(d10)。
|
|
295
|
+
* @returns {{outcome:'run'|'success'|'failure'|'skip', action:'run'|'skip', reason:string,
|
|
296
|
+
* ran:boolean, attempts:number, terminal:boolean, nextRetryAt:string|null,
|
|
297
|
+
* missedDays:number|null, gapMs:number|null, error?:string, result?:object}}
|
|
298
|
+
*/
|
|
299
|
+
export async function runCatchUp(options = {}) {
|
|
300
|
+
const at = toDate(options.now);
|
|
301
|
+
const root = typeof options.memoryRoot === 'string' && options.memoryRoot.trim() !== ''
|
|
302
|
+
? path.resolve(options.memoryRoot)
|
|
303
|
+
: null;
|
|
304
|
+
const trigger = String(options.trigger ?? 'manual');
|
|
305
|
+
const deps = options.deps && typeof options.deps === 'object' ? options.deps : {};
|
|
306
|
+
const base = {
|
|
307
|
+
ran: false, action: null, reason: null, attempts: 0, terminal: false,
|
|
308
|
+
nextRetryAt: null, missedDays: null, gapMs: null,
|
|
309
|
+
};
|
|
310
|
+
if (!root) return { ...base, outcome: 'skip', reason: 'no-memory-root' };
|
|
311
|
+
|
|
312
|
+
const readSchedule = typeof deps.readSchedule === 'function'
|
|
313
|
+
? deps.readSchedule
|
|
314
|
+
: () => readScheduleState(root).state;
|
|
315
|
+
const readLast = typeof deps.readLastRun === 'function'
|
|
316
|
+
? deps.readLastRun
|
|
317
|
+
: () => readLastRun(root).doc;
|
|
318
|
+
const writeLast = typeof deps.writeLastRun === 'function'
|
|
319
|
+
? deps.writeLastRun
|
|
320
|
+
: (doc) => writeLastRun(root, doc, at);
|
|
321
|
+
const gate = typeof deps.gateLog === 'function'
|
|
322
|
+
? deps.gateLog
|
|
323
|
+
: (row) => appendCatchupGate(root, { ...row, at });
|
|
324
|
+
const runDaily = typeof deps.runDaily === 'function' ? deps.runDaily : runDailyMaintenance;
|
|
325
|
+
// 宿主维护配置(透传 sessionsRoot 等;CATCHUP-SPEC §2「透传宿主 config」)。
|
|
326
|
+
// 兼容 v0.5.1 草稿的 dailyConfig 命名:dailyConfig 优先,其次 config。
|
|
327
|
+
const hostConfig = options.dailyConfig && typeof options.dailyConfig === 'object'
|
|
328
|
+
? options.dailyConfig
|
|
329
|
+
: (options.config && typeof options.config === 'object' ? options.config : {});
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
let schedule = readSchedule() ?? null;
|
|
333
|
+
let lastRun = normalizeLastRun(readLast());
|
|
334
|
+
const decision = decideCatchUp({ now: at, lastRun, schedule });
|
|
335
|
+
if (decision.action === 'skip') {
|
|
336
|
+
return {
|
|
337
|
+
...base,
|
|
338
|
+
outcome: 'skip',
|
|
339
|
+
action: 'skip',
|
|
340
|
+
reason: decision.reason,
|
|
341
|
+
attempts: decision.attempts,
|
|
342
|
+
terminal: decision.terminal,
|
|
343
|
+
nextRetryAt: decision.nextRetryAt,
|
|
344
|
+
missedDays: decision.missedDays,
|
|
345
|
+
gapMs: decision.gapMs,
|
|
346
|
+
decision,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const lock = acquireScheduleLock(root, { now: at });
|
|
351
|
+
if (!lock || lock.acquired !== true) {
|
|
352
|
+
// B3 C3:锁被别的进程持有是并发事实,不是「跳过召回」——不再往主 gate-log 写
|
|
353
|
+
// skip 行(当日 gate-log 的 skip 必须为 0);事实留在返回值的 outcome/reason 里。
|
|
354
|
+
return {
|
|
355
|
+
...base,
|
|
356
|
+
outcome: 'skip',
|
|
357
|
+
action: 'skip',
|
|
358
|
+
reason: 'lock-busy',
|
|
359
|
+
attempts: decision.attempts,
|
|
360
|
+
terminal: decision.terminal,
|
|
361
|
+
nextRetryAt: decision.nextRetryAt,
|
|
362
|
+
missedDays: decision.missedDays,
|
|
363
|
+
gapMs: decision.gapMs,
|
|
364
|
+
decision,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
try {
|
|
369
|
+
// 拿锁后重读:另一会话可能刚跑完同一天。
|
|
370
|
+
schedule = readSchedule() ?? schedule;
|
|
371
|
+
lastRun = normalizeLastRun(readLast());
|
|
372
|
+
const locked = decideCatchUp({ now: at, lastRun, schedule });
|
|
373
|
+
if (locked.action === 'skip' && locked.reason === 'already-ran-today') {
|
|
374
|
+
return {
|
|
375
|
+
...base,
|
|
376
|
+
outcome: 'skip',
|
|
377
|
+
action: 'skip',
|
|
378
|
+
reason: locked.reason,
|
|
379
|
+
attempts: locked.attempts,
|
|
380
|
+
terminal: locked.terminal,
|
|
381
|
+
nextRetryAt: locked.nextRetryAt,
|
|
382
|
+
missedDays: locked.missedDays,
|
|
383
|
+
gapMs: locked.gapMs,
|
|
384
|
+
decision: locked,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
let result = null;
|
|
389
|
+
let error = null;
|
|
390
|
+
try {
|
|
391
|
+
result = await runDaily({
|
|
392
|
+
memoryRoot: root,
|
|
393
|
+
// 只跑蒸馏槽(CATCHUP-SPEC §2):开关必须放 config 嵌套(maintenance.js
|
|
394
|
+
// :453-456 只读 config.*;worktree 因 B3 的 migrate200 槽 +2 行,已按语义重定位);
|
|
395
|
+
// 顶层同名键是「依赖注入形参」,传布尔会 TypeError 并被每槽 catch 成
|
|
396
|
+
// E_MAINTENANCE_FAILED。
|
|
397
|
+
config: {
|
|
398
|
+
...hostConfig,
|
|
399
|
+
consolidate: false,
|
|
400
|
+
forget: false,
|
|
401
|
+
forgetSuggestions: true,
|
|
402
|
+
autoConclusion: true,
|
|
403
|
+
},
|
|
404
|
+
now: at,
|
|
405
|
+
trigger: 'catchup',
|
|
406
|
+
lockHeld: true,
|
|
407
|
+
});
|
|
408
|
+
} catch (thrown) {
|
|
409
|
+
error = thrown;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const distillOk = !(result && result.conclusionDistill && result.conclusionDistill.ok === false);
|
|
413
|
+
const ok = !error
|
|
414
|
+
&& result && result.ok !== false
|
|
415
|
+
&& distillOk
|
|
416
|
+
&& (result.ran !== false || result.reason === 'already-ran-today');
|
|
417
|
+
|
|
418
|
+
if (ok) {
|
|
419
|
+
const day = dayString(at);
|
|
420
|
+
const iso = isoStamp(at);
|
|
421
|
+
const freshSchedule = { ...(readSchedule() ?? schedule) };
|
|
422
|
+
freshSchedule.lastConclusionDistillDate = day;
|
|
423
|
+
freshSchedule.lastConclusionDistillAt = iso;
|
|
424
|
+
freshSchedule.updatedAt = iso;
|
|
425
|
+
try { writeScheduleState(root, freshSchedule, { now: at }); } catch { /* state 写失败不改变补跑结论 */ }
|
|
426
|
+
const doc = normalizeLastRun({
|
|
427
|
+
schema: CATCHUP_SCHEMA,
|
|
428
|
+
updatedAt: iso,
|
|
429
|
+
distill: {
|
|
430
|
+
lastAttemptAt: iso,
|
|
431
|
+
lastSuccessAt: iso,
|
|
432
|
+
lastSuccessDay: day,
|
|
433
|
+
catchUpNeeded: false,
|
|
434
|
+
attempts: 0,
|
|
435
|
+
terminal: false,
|
|
436
|
+
nextRetryAt: null,
|
|
437
|
+
lastError: null,
|
|
438
|
+
lastTrigger: trigger,
|
|
439
|
+
lastResult: {
|
|
440
|
+
distilled: Number(result?.conclusionDistill?.distilled ?? result?.distilled ?? 0) || 0,
|
|
441
|
+
archived: Number(result?.conclusionDistill?.archived ?? result?.archived ?? 0) || 0,
|
|
442
|
+
trigger,
|
|
443
|
+
},
|
|
444
|
+
lastDecision: 'run',
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
try { writeLast(doc); } catch { /* 同上 */ }
|
|
448
|
+
gate({
|
|
449
|
+
reason: 'D.catchup.done',
|
|
450
|
+
decision: 'ok',
|
|
451
|
+
evidence: [trigger, `missedDays:${decision.missedDays ?? 0}`, `distilled:${doc.distill.lastResult.distilled}`],
|
|
452
|
+
});
|
|
453
|
+
return {
|
|
454
|
+
outcome: 'success',
|
|
455
|
+
action: 'run',
|
|
456
|
+
reason: decision.reason,
|
|
457
|
+
ran: true,
|
|
458
|
+
attempts: 0,
|
|
459
|
+
terminal: false,
|
|
460
|
+
nextRetryAt: null,
|
|
461
|
+
missedDays: decision.missedDays,
|
|
462
|
+
gapMs: decision.gapMs,
|
|
463
|
+
lastSuccessAt: iso,
|
|
464
|
+
lastSuccessDay: day,
|
|
465
|
+
decision,
|
|
466
|
+
result,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// 失败:attempts+1、退避、3 次 terminal、6h 后新 episode。
|
|
471
|
+
const prev = normalizeLastRun(readLast()).distill;
|
|
472
|
+
const attempts = Math.min(CATCHUP_MAX_ATTEMPTS, Math.max(1, Number(prev.attempts ?? 0) + 1));
|
|
473
|
+
const terminal = attempts >= CATCHUP_MAX_ATTEMPTS;
|
|
474
|
+
const backoff = CATCHUP_BACKOFF_MS[Math.min(attempts - 1, CATCHUP_BACKOFF_MS.length - 1)];
|
|
475
|
+
const nextRetryAt = new Date(at.getTime() + backoff).toISOString();
|
|
476
|
+
const code = firstErrorCode(error, result);
|
|
477
|
+
const doc = normalizeLastRun({
|
|
478
|
+
schema: CATCHUP_SCHEMA,
|
|
479
|
+
updatedAt: isoStamp(at),
|
|
480
|
+
distill: {
|
|
481
|
+
lastAttemptAt: isoStamp(at),
|
|
482
|
+
lastSuccessAt: prev.lastSuccessAt ?? null,
|
|
483
|
+
lastSuccessDay: prev.lastSuccessDay ?? null,
|
|
484
|
+
catchUpNeeded: true,
|
|
485
|
+
attempts,
|
|
486
|
+
terminal,
|
|
487
|
+
nextRetryAt,
|
|
488
|
+
lastError: { code, at: isoStamp(at), day: dayString(at) },
|
|
489
|
+
lastTrigger: trigger,
|
|
490
|
+
lastResult: null,
|
|
491
|
+
lastDecision: 'run',
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
try { writeLast(doc); } catch { /* 同上 */ }
|
|
495
|
+
gate({
|
|
496
|
+
reason: terminal ? 'D.catchup.terminal' : 'D.catchup.fail',
|
|
497
|
+
decision: 'fail',
|
|
498
|
+
evidence: [code, trigger, `attempts:${attempts}`],
|
|
499
|
+
});
|
|
500
|
+
return {
|
|
501
|
+
outcome: 'failure',
|
|
502
|
+
action: 'run',
|
|
503
|
+
reason: terminal ? 'terminal' : 'failed',
|
|
504
|
+
ran: true,
|
|
505
|
+
attempts,
|
|
506
|
+
terminal,
|
|
507
|
+
nextRetryAt,
|
|
508
|
+
missedDays: decision.missedDays,
|
|
509
|
+
gapMs: decision.gapMs,
|
|
510
|
+
error: code,
|
|
511
|
+
decision,
|
|
512
|
+
result,
|
|
513
|
+
};
|
|
514
|
+
} finally {
|
|
515
|
+
try { lock.release(); } catch { /* 已释放 */ }
|
|
516
|
+
}
|
|
517
|
+
} catch (error) {
|
|
518
|
+
// 永不向宿主抛:补跑失败是状态,不是崩溃。
|
|
519
|
+
return {
|
|
520
|
+
...base,
|
|
521
|
+
outcome: 'failure',
|
|
522
|
+
action: 'run',
|
|
523
|
+
reason: 'unexpected-error',
|
|
524
|
+
error: String(error?.code ?? error?.message ?? error),
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** 兼容入口:旧骨架的 catchup(),现在委托给 runCatchUp。 */
|
|
530
|
+
export function catchup(now = new Date(), options = {}) {
|
|
531
|
+
return runCatchUp({ ...options, now });
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export { sha256Text as catchupStateFingerprint };
|