@lmzhen/dsh-evolution-core 0.46.0 → 0.48.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/lib/authority-plugin.js +1 -1
- package/lib/composition/index.js +3 -3
- package/lib/{composition-Da8NfRI7.js → composition-Cqjbho0t.js} +1 -1
- package/lib/{ensure-C5Mo1dbB.js → ensure-CAjLGd9f.js} +1 -2
- package/lib/http-routes.js +21 -96
- package/lib/index.js +47 -246
- package/lib/{io-AmUf4lVY.js → io-GxghO3Ip.js} +30 -70
- package/lib/io-node.js +1 -1
- package/lib/io-registry.js +1 -35
- package/lib/{mutation-authority-DeJ_Wz14.js → mutation-authority-l57R626O.js} +17 -15
- package/lib/{mutations-DwvbjRHF.js → mutations-DQXddSJd.js} +1 -1
- package/lib/{numeric-DLeLvvGb.js → numeric-D8js3sqC.js} +1 -5
- package/lib/platform/index.js +1 -1
- package/lib/{platform-CFA12Jam.js → platform-Cc9cNt5j.js} +4 -28
- package/lib/policy.js +1 -1
- package/lib/runtime/plugin.js +21 -43
- package/lib/{session-projection-EB7mUOlJ.js → session-projection-DSXnUNZG.js} +3 -21
- package/lib/{skill-health-D1pZGk5V.js → skill-health-DP8z9TPf.js} +4 -25
- package/lib/{skill-history-CjypdYqv.js → skill-history-CxrDE3Rb.js} +54 -102
- package/lib/skills.js +166 -184
- package/lib/subagent/index.js +4 -10
- package/lib/types/authority.d.ts +2 -0
- package/lib/types/authority.js +5 -0
- package/lib/types/composition/preset-ids.d.ts +0 -1
- package/lib/types/composition/preset-ids.js +0 -1
- package/lib/types/constants.d.ts +0 -4
- package/lib/types/constants.js +0 -4
- package/lib/types/contract.d.ts +0 -5
- package/lib/types/curator.d.ts +0 -1
- package/lib/types/curator.js +0 -1
- package/lib/types/document-body.d.ts +0 -12
- package/lib/types/document-body.js +0 -14
- package/lib/types/health-baseline.d.ts +0 -13
- package/lib/types/health-baseline.js +0 -20
- package/lib/types/home-fence.d.ts +2 -0
- package/lib/types/home-fence.js +11 -1
- package/lib/types/http-routes.d.ts +9 -4
- package/lib/types/http-routes.js +36 -116
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -3
- package/lib/types/io-registry.d.ts +0 -16
- package/lib/types/io-registry.js +0 -27
- package/lib/types/io.d.ts +6 -54
- package/lib/types/io.js +35 -65
- package/lib/types/journal-protocol.d.ts +0 -15
- package/lib/types/journal-protocol.js +1 -19
- package/lib/types/lease-store.d.ts +1 -1
- package/lib/types/lease-store.js +4 -15
- package/lib/types/live.d.ts +0 -12
- package/lib/types/live.js +0 -18
- package/lib/types/memory-store.d.ts +0 -1
- package/lib/types/memory-store.js +13 -6
- package/lib/types/mutation-authority.js +5 -0
- package/lib/types/mutation-unit.d.ts +1 -1
- package/lib/types/mutation-unit.js +14 -31
- package/lib/types/params.d.ts +11 -29
- package/lib/types/params.js +13 -60
- package/lib/types/platform/llm.d.ts +2 -3
- package/lib/types/platform/llm.js +3 -10
- package/lib/types/platform/projections.d.ts +4 -5
- package/lib/types/platform/projections.js +4 -18
- package/lib/types/probe.d.ts +0 -3
- package/lib/types/probe.js +0 -7
- package/lib/types/run-registry.js +10 -12
- package/lib/types/runtime/llm.js +2 -2
- package/lib/types/runtime/platform.d.ts +7 -11
- package/lib/types/runtime/platform.js +13 -19
- package/lib/types/runtime/plugin.d.ts +1 -1
- package/lib/types/runtime/plugin.js +6 -4
- package/lib/types/runtime/projections.js +1 -2
- package/lib/types/session-fold.d.ts +0 -8
- package/lib/types/session-fold.js +0 -5
- package/lib/types/session-projection.js +2 -2
- package/lib/types/skill-discovery.d.ts +0 -2
- package/lib/types/skill-discovery.js +1 -2
- package/lib/types/skill-health.d.ts +29 -1
- package/lib/types/skill-history.d.ts +0 -24
- package/lib/types/skill-history.js +0 -41
- package/lib/types/skill-lint.d.ts +0 -3
- package/lib/types/skill-lint.js +0 -12
- package/lib/types/skill-store.d.ts +6 -0
- package/lib/types/skill-store.js +130 -142
- package/lib/types/subagent/readiness.d.ts +0 -1
- package/lib/types/subagent/readiness.js +2 -8
- package/lib/types/tool-dispatch.d.ts +1 -16
- package/lib/types/tool-dispatch.js +0 -18
- package/lib/types/unit-journal.d.ts +1 -1
- package/lib/types/unit-journal.js +20 -15
- package/lib/types/unit-storage.d.ts +1 -1
- package/lib/types/unit-storage.js +5 -16
- package/lib/types/write-inventory.d.ts +0 -4
- package/lib/types/write-inventory.js +0 -9
- package/lib/types/write-kernel.d.ts +3 -4
- package/lib/types/write-kernel.js +13 -25
- package/lib/write.js +2 -2
- package/package.json +1 -1
- package/persisted-write-inventory.json +72 -9
- package/lib/types/fold-untrusted.d.ts +0 -35
- package/lib/types/fold-untrusted.js +0 -44
- package/lib/types/unit-recovery.d.ts +0 -5
- package/lib/types/unit-recovery.js +0 -12
package/lib/index.js
CHANGED
|
@@ -1,52 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as leaseFile, c as evolutionHome, d as AuthorityOrderError, f as AuthorityReentryError, h as leaseAsTreeLock, i as LeaseStore, l as evolutionRoot, m as authorityHolder, n as mutationLockFrom, o as HomeFence, p as HomeAuthority, r as DEFAULT_LEASE_TTL_MS, s as HomeFenceError, t as MutationAuthority, u as AuthorityBusyError } from "./mutation-authority-
|
|
3
|
-
import { A as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { $ as
|
|
1
|
+
import { S as reportTime, _ as probeMtime, a as isProcessAlive, b as probeText, c as transactIo, d as isAbsent, f as isMissingPath, g as probeList, h as probeAbsent, i as isCommittedWarning, l as writeDurableTmp, m as isUnknown, n as atomicWriteFiles, o as nodeEvolutionIo, p as isPresent, r as evolutionIoAdapter, s as renameWithRetry, t as TransactionNotInvokedError, u as declaredReportStamp, v as probePresent, x as probeUnknown, y as probeReason } from "./io-GxghO3Ip.js";
|
|
2
|
+
import { a as leaseFile, c as evolutionHome, d as AuthorityOrderError, f as AuthorityReentryError, h as leaseAsTreeLock, i as LeaseStore, l as evolutionRoot, m as authorityHolder, n as mutationLockFrom, o as HomeFence, p as HomeAuthority, r as DEFAULT_LEASE_TTL_MS, s as HomeFenceError, t as MutationAuthority, u as AuthorityBusyError } from "./mutation-authority-l57R626O.js";
|
|
3
|
+
import { A as dispatchKeyOf, B as CITATION_SUPPORT_DIRS, C as PTC_DISPATCH_EVENT, D as assertDispatchPayload, E as ToolDispatchPayloadError, F as isSkillToolName, G as resolveCitations, H as HOOK_LINE_RE, I as readDispatchSignal, K as scanBodyHooks, L as skillReadNameOf, M as dispatchStepOf, N as foldToolDispatches, O as collectReadSkillNames, P as isSkillReadToolName, R as supportFileReadFromPath, S as NATIVE_RESULT_EVENT, T as ToolDispatchNormalizer, U as KEEP_LINE_RE, V as DEFAULT_CITATION_REF_BUDGET, W as isFileShapedPath, _ as isBookkeepingFrame, a as evolutionSignalsProjection, b as MODEL_SESSION_EVENT_TYPES, c as sessionLastEventTime, d as advanceReview, f as foldTurnEvent, g as evidenceKindIndex, h as observeEvent, i as evolutionReadsProjection, j as dispatchPathOf, k as collectReadSupportFiles, l as sessionReadNames, m as initialTurnFold, n as evolutionEvidenceProjection, o as isProjectableSession, p as foldTurnEvents, r as evolutionProjectionHistoryProjection, s as sessionEvidenceIndex, t as evolutionActivityProjection, u as sessionTurnSignals, v as DEFAULT_SUPPORT_READ_TOOL_NAMES, w as PTC_DISPATCH_START_EVENT, x as NATIVE_CALL_EVENT, y as DISPATCH_EVENT_TYPES, z as supportFileReadOf } from "./session-projection-DSXnUNZG.js";
|
|
4
|
+
import { A as DEFAULT_SUBSTANTIVE_MIN_TOOL_CALLS, B as MAX_SKILL_NAME_LENGTH, C as DEFAULT_REVIEW_TIMEOUT_MS, D as DEFAULT_SKILL_VERSION_KEEP, E as DEFAULT_SKILL_REVIEW_TRIGGER, F as EVOLUTION_WRITE_TOOLS, G as SKILL_ACTION_REQUIRED_FIELDS, H as MEMORY_GUIDANCE_SECTION_ORDER, I as FORBIDDEN_CONTROL_KEYS, J as SUPPORT_SPRAWL_FILES, K as SKILL_NAME_RE, L as MAX_DESCRIPTION_LENGTH, M as DEFAULT_THREAT_MAX_SCAN_CHARS, N as DEFAULT_USER_CHAR_LIMIT, O as DEFAULT_STALE_AFTER_DAYS, P as ENTRY_DELIMITER, R as MAX_SKILL_CONTENT_CHARS, S as DEFAULT_REVIEW_SKILL_INTERVAL, T as DEFAULT_SKILL_REVIEW_COMPLETION_MIN_TOOL_CALLS, U as PROTECTED_BUILTIN_SKILLS, V as MAX_TIMER_DELAY_MS, W as SKILLS_GUIDANCE_SECTION_ORDER, Y as UPSTREAM_LIMIT_CHARS_PER_TOKEN, _ as DEFAULT_CURATOR_REVIEW_MAX_TOKENS, a as DEFAULT_SKILL_LIMITS, b as DEFAULT_PROBE_TIMEOUT_MS, c as policyStageLimits, d as CONTENT_SPLIT_HINT, f as DEFAULT_ARCHIVE_AFTER_DAYS, g as DEFAULT_CURATOR_MODEL, h as DEFAULT_CURATOR_INTERVAL_HOURS, i as DEFAULT_REFERENCE_REWRITE_POLICY, j as DEFAULT_SUBSTANTIVE_MIN_USER_CHARS, k as DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS, l as AUTHORING_DESCRIPTION_BAR, m as DEFAULT_CURATOR_BOOT_GRACE_SECONDS, n as DEFAULT_ARCHIVE_RETENTION_POLICY, o as DEFAULT_SUPPORT_FILE_CHAR_POLICY, p as DEFAULT_CONSOLIDATION_FAILURES, q as SUPPORT_DIRS, r as DEFAULT_CITATION_POLICY, s as POLICY_STAGE_DEFAULTS, t as clampedNumber, u as AUTHORING_SPLIT_LINE_CHARS, v as DEFAULT_MEMORY_CHAR_LIMIT, w as DEFAULT_SKILL_CONTENT_CHARS, x as DEFAULT_REVIEW_MEMORY_INTERVAL, y as DEFAULT_MIN_IDLE_HOURS, z as MAX_SKILL_FILE_BYTES } from "./numeric-D8js3sqC.js";
|
|
5
|
+
import { c as MAINTAINER_PRESET_ID, d as RESTRICTOR_MODULE, f as REVIEWER_PRESET_ID, g as scopedPackageName, h as scopeOfNearestManifest, l as RESTRICTED_PRESET_DISPLAY, s as EVOLUTION_PRESET_IDS, u as RESTRICTED_TOOLS_ROW_ID } from "./ensure-CAjLGd9f.js";
|
|
6
|
+
import { $ as bumpView, A as listEventArchives, B as COST_CJK_TOKEN_HIGH, Bt as planRehoming, C as EVENT_ARCHIVE_PREFIX, D as appendEvolutionEvent, E as EVENT_LOG_VERSION, F as RULES, Ft as externalRefs, G as tokenLineFor, H as TOKEN_ASCII_WEIGHT, It as supportRefs, J as applyCuratorLifecycleFields, Jt as authorityFrom, K as MAX_SUPPORT_READ_PATHS, Kt as DEFAULT_WRITE_CONFIRM_MODE, L as lintSkill, Lt as applyReferenceRewrite, M as readEvolutionEvents, N as readEvolutionTimeline, O as eventsFile, P as retainEventArchives, Q as bumpUse, R as COST_ASCII_TOKEN_HIGH, Rt as describeReferenceRewrite, S as trimPatternBoundaries, St as readingStats, T as EVENT_LOG_ROTATE_AT, U as TOKEN_CJK_WEIGHT, Ut as isUnreadWrite, V as COST_CJK_TOKEN_LOW, W as bodyCost, X as bumpPatch, Y as applyCuratorMetaFields, Z as bumpSupportRead, _ as scanThreats, _t as planExtract, at as latestActivityAt, b as FUZZY_MAX_WORK, bt as displayBodyOf, c as clearReviewChannel, ct as markAgentCreated, d as sweepReviewChannelSessions, dt as saveSuppressedNames, et as daysSinceIso, f as PATTERN_OVERLAP, ft as saveUsage, g as scanMemoryThreats, gt as usageObserved, h as scanContentThreats, ht as usageFile, i as assessStructureHealth, it as idleDays, j as parseEvolutionEvents, k as evolutionEventPayloadIssue, kt as parseFrontmatter, l as isReviewChannelSession, lt as mutateUsage, m as evaluateThreat, mt as updateSuppressedNames, nt as foldCuratorFields, o as currentReviewContext, ot as loadSuppressedNames, p as THREAT_EXEMPTION_HINT, pt as suppressedFile, q as SUPPRESSED_FILE_VERSION, qt as DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS, rt as getRecord, s as withReviewContext, st as loadUsage, t as DEFAULT_HEALTH_THRESHOLDS, tt as emptyRecord, u as markReviewChannel, ut as normalizeUsageRecord, v as makeSerialQueue, vt as projectExtractBodies, w as EVENT_LOG_RETAIN_ARCHIVES, x as fuzzyPatch, xt as h2Sections, y as FUZZY_MAX_PATTERN_CHARS, yt as selectSections, z as COST_ASCII_TOKEN_LOW, zt as planReferenceRewrite } from "./skill-health-DP8z9TPf.js";
|
|
7
7
|
import { i as HOST_LOCALES, n as errorText, r as errorTextIn, t as EVOLUTION_ERRORS } from "./errors-BxzLTVbS.js";
|
|
8
8
|
import { n as isRecord, t as asRecord } from "./guards-3f02mnf2.js";
|
|
9
|
-
import { a as mutationsFile, i as loadMutations, n as MUTATIONS_FILE_VERSION, o as recordMutation, r as contentHash, t as DEFAULT_MUTATION_CAP } from "./mutations-
|
|
9
|
+
import { a as mutationsFile, i as loadMutations, n as MUTATIONS_FILE_VERSION, o as recordMutation, r as contentHash, t as DEFAULT_MUTATION_CAP } from "./mutations-DQXddSJd.js";
|
|
10
10
|
import { HOST_ROUTES, MAX_REQUEST_BODY_BYTES, hostSurface, json, methodNotAllowed, readJsonObject, registerHostRoutes } from "./http-routes.js";
|
|
11
|
-
import { w as allowRowCollisions } from "./composition-
|
|
12
|
-
import { u as scopeOf } from "./platform-
|
|
13
|
-
import { createSubagentChannel, probeChannelState
|
|
11
|
+
import { w as allowRowCollisions } from "./composition-Cqjbho0t.js";
|
|
12
|
+
import { u as scopeOf } from "./platform-Cc9cNt5j.js";
|
|
13
|
+
import { createSubagentChannel, probeChannelState } from "./subagent/index.js";
|
|
14
14
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
15
15
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
16
16
|
import { readFileSync } from "node:fs";
|
|
17
17
|
import { createHash, randomUUID } from "node:crypto";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import { parse } from "yaml";
|
|
20
|
-
//#region lib/types/journal-protocol.js
|
|
21
|
-
/**
|
|
22
|
-
* A journal protocol: the phases one multi-write operation records, which transitions it allows, and
|
|
23
|
-
* what a restart may do from each phase (W9-commit-protocol §3.1).
|
|
24
|
-
*
|
|
25
|
-
* The commit and undo journals used to disagree: commit had a transition table and a recovery
|
|
26
|
-
* decision but only reported it, while undo wrote a journal nobody read. Both now describe the same
|
|
27
|
-
* shape, so a resumer can be written once against `JournalProtocol` instead of per operation.
|
|
28
|
-
* @module @lmzhen/dsh-evolution-core/journal-protocol
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* True when `from` may advance to `to`.
|
|
32
|
-
* @param protocol - the journal's protocol.
|
|
33
|
-
* @param from - the recorded phase.
|
|
34
|
-
* @param to - the phase the caller wants to record next.
|
|
35
|
-
* @returns whether the transition is declared.
|
|
36
|
-
*/
|
|
37
|
-
function canAdvance(protocol, from, to) {
|
|
38
|
-
return protocol.next[from].includes(to);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* True when the phase is terminal (nothing may follow it).
|
|
42
|
-
* @param protocol - the journal's protocol.
|
|
43
|
-
* @param phase - the phase to test.
|
|
44
|
-
* @returns whether the phase is terminal.
|
|
45
|
-
*/
|
|
46
|
-
function isTerminal(protocol, phase) {
|
|
47
|
-
return protocol.next[phase].length === 0;
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
20
|
//#region lib/types/tree-write.js
|
|
51
21
|
/**
|
|
52
22
|
* G1/1.5 (S7-09): the TYPED critical section around a tree write.
|
|
@@ -1118,10 +1088,6 @@ async function readProposalReports(io, dir = proposalReportDir(), limit = 10) {
|
|
|
1118
1088
|
}
|
|
1119
1089
|
//#endregion
|
|
1120
1090
|
//#region lib/types/health-baseline.js
|
|
1121
|
-
const DEFAULT_ADMISSION = {
|
|
1122
|
-
minUserHitRate: .05,
|
|
1123
|
-
maxUserHitRate: .25
|
|
1124
|
-
};
|
|
1125
1091
|
function buildHealthBaseline(skills) {
|
|
1126
1092
|
const values = {};
|
|
1127
1093
|
for (const rule of RULES) values[rule.id] = {
|
|
@@ -1152,25 +1118,6 @@ function buildHealthBaseline(skills) {
|
|
|
1152
1118
|
values
|
|
1153
1119
|
};
|
|
1154
1120
|
}
|
|
1155
|
-
/** The admission verdict for ONE rule id (contract §4): platform corpus must not trip it, and the
|
|
1156
|
-
* user-library hit rate must land inside the band. Every failure names the number it failed on. */
|
|
1157
|
-
function admissionVerdict(baseline, ruleId, thresholds = DEFAULT_ADMISSION) {
|
|
1158
|
-
const row = baseline.values[ruleId];
|
|
1159
|
-
const failures = [];
|
|
1160
|
-
if (row === void 0) return {
|
|
1161
|
-
admitted: false,
|
|
1162
|
-
failures: ["rule " + ruleId + " has no baseline row"]
|
|
1163
|
-
};
|
|
1164
|
-
if (baseline.corpora.platform === 0) failures.push("no platform-corpus skills measured — a vacuous 0-hit count admits any rule");
|
|
1165
|
-
else if (row.platformHits !== 0) failures.push("platform corpus trips " + ruleId + " " + String(row.platformHits) + " time(s) — a rule the shipped library violates is unsatisfiable");
|
|
1166
|
-
if (baseline.corpora.user === 0) failures.push("no user-library skills measured — a rate over an empty corpus proves nothing");
|
|
1167
|
-
else if (row.userHitRate < thresholds.minUserHitRate) failures.push(ruleId + " hits " + row.userHitRate.toFixed(3) + " of the user library, below " + String(thresholds.minUserHitRate) + " — too rare to be worth a rule");
|
|
1168
|
-
else if (row.userHitRate > thresholds.maxUserHitRate) failures.push(ruleId + " hits " + row.userHitRate.toFixed(3) + " of the user library, above " + String(thresholds.maxUserHitRate) + " — furniture, no signal");
|
|
1169
|
-
return {
|
|
1170
|
-
admitted: failures.length === 0,
|
|
1171
|
-
failures
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
1121
|
//#endregion
|
|
1175
1122
|
//#region lib/types/gates.js
|
|
1176
1123
|
/**
|
|
@@ -1796,8 +1743,12 @@ var MemoryStore = class {
|
|
|
1796
1743
|
return step.write ?? current ?? null;
|
|
1797
1744
|
});
|
|
1798
1745
|
};
|
|
1799
|
-
|
|
1800
|
-
|
|
1746
|
+
try {
|
|
1747
|
+
if (this.fence !== void 0) await this.fence.run(run);
|
|
1748
|
+
else await run();
|
|
1749
|
+
} catch (error) {
|
|
1750
|
+
if (!(error instanceof TransactionNotInvokedError)) throw error;
|
|
1751
|
+
}
|
|
1801
1752
|
return outcome ?? {
|
|
1802
1753
|
ok: false,
|
|
1803
1754
|
message: "内部错误:记忆写事务没有调用任务;未执行任何写入",
|
|
@@ -2782,6 +2733,20 @@ function newRunRegistry(options) {
|
|
|
2782
2733
|
}
|
|
2783
2734
|
return [...live, ...[...perKind.values()].flat()].sort((a, b) => b.startedAt - a.startedAt);
|
|
2784
2735
|
};
|
|
2736
|
+
/** One serialization for every run-index write (live first, then terminal, then foreign rows). */
|
|
2737
|
+
const serializeIndex = (records, foreignRows) => {
|
|
2738
|
+
const kept = capped(records);
|
|
2739
|
+
const live = kept.filter((row) => row.state === "running");
|
|
2740
|
+
const done = kept.filter((row) => TERMINAL.has(row.state));
|
|
2741
|
+
return JSON.stringify({
|
|
2742
|
+
schemaVersion: 2,
|
|
2743
|
+
runs: [
|
|
2744
|
+
...live,
|
|
2745
|
+
...done,
|
|
2746
|
+
...foreignRows
|
|
2747
|
+
]
|
|
2748
|
+
}, null, 2);
|
|
2749
|
+
};
|
|
2785
2750
|
/**
|
|
2786
2751
|
* Update a surviving foreign row in place (identity stable), or add it.
|
|
2787
2752
|
*
|
|
@@ -2822,17 +2787,7 @@ function newRunRegistry(options) {
|
|
|
2822
2787
|
if (TERMINAL.has(row.state) && onDiskRow !== void 0 && !TERMINAL.has(onDiskRow.state)) merged.set(id, row);
|
|
2823
2788
|
}
|
|
2824
2789
|
for (const [id, row] of merged) if (row.state === "running" && !owned.has(id) && ownerIsGone(row)) merged.set(id, orphanOf(row));
|
|
2825
|
-
|
|
2826
|
-
const live = kept.filter((row) => row.state === "running");
|
|
2827
|
-
const done = kept.filter((row) => TERMINAL.has(row.state));
|
|
2828
|
-
return JSON.stringify({
|
|
2829
|
-
schemaVersion: 2,
|
|
2830
|
-
runs: [
|
|
2831
|
-
...live,
|
|
2832
|
-
...done,
|
|
2833
|
-
...onDisk.foreign
|
|
2834
|
-
]
|
|
2835
|
-
}, null, 2);
|
|
2790
|
+
return serializeIndex([...merged.values()], onDisk.foreign);
|
|
2836
2791
|
});
|
|
2837
2792
|
} catch (error) {
|
|
2838
2793
|
warn(`evolution-core: could not persist the run index (${error instanceof Error ? error.message : String(error)})`);
|
|
@@ -2970,17 +2925,7 @@ function newRunRegistry(options) {
|
|
|
2970
2925
|
row.supersededAt = now();
|
|
2971
2926
|
marked += 1;
|
|
2972
2927
|
}
|
|
2973
|
-
|
|
2974
|
-
const live = kept.filter((row) => row.state === "running");
|
|
2975
|
-
const done = kept.filter((row) => TERMINAL.has(row.state));
|
|
2976
|
-
return JSON.stringify({
|
|
2977
|
-
schemaVersion: 2,
|
|
2978
|
-
runs: [
|
|
2979
|
-
...live,
|
|
2980
|
-
...done,
|
|
2981
|
-
...onDisk.foreign
|
|
2982
|
-
]
|
|
2983
|
-
}, null, 2);
|
|
2928
|
+
return serializeIndex([...merged.values()], onDisk.foreign);
|
|
2984
2929
|
});
|
|
2985
2930
|
return marked;
|
|
2986
2931
|
},
|
|
@@ -3013,17 +2958,7 @@ function newRunRegistry(options) {
|
|
|
3013
2958
|
...outcome.resultRef === void 0 ? {} : { resultRef: outcome.resultRef },
|
|
3014
2959
|
...outcome.failure === void 0 ? {} : { failure: outcome.failure }
|
|
3015
2960
|
};
|
|
3016
|
-
|
|
3017
|
-
const live = kept.filter((item) => item.state === "running");
|
|
3018
|
-
const done = kept.filter((item) => TERMINAL.has(item.state));
|
|
3019
|
-
return JSON.stringify({
|
|
3020
|
-
schemaVersion: 2,
|
|
3021
|
-
runs: [
|
|
3022
|
-
...live,
|
|
3023
|
-
...done,
|
|
3024
|
-
...onDisk.foreign
|
|
3025
|
-
]
|
|
3026
|
-
}, null, 2);
|
|
2961
|
+
return serializeIndex(onDisk.records.map((item) => item.id === id ? next : item), onDisk.foreign);
|
|
3027
2962
|
});
|
|
3028
2963
|
if (changed) await this.load();
|
|
3029
2964
|
return changed;
|
|
@@ -3612,7 +3547,6 @@ const INSTANCE_KEYS = {
|
|
|
3612
3547
|
/** The per-home curator: report writing + the retention sweep. */
|
|
3613
3548
|
curator: "evolution-curator" };
|
|
3614
3549
|
let cachedSites;
|
|
3615
|
-
let cachedSymbols;
|
|
3616
3550
|
/**
|
|
3617
3551
|
* The declared persisted write sites, in file order.
|
|
3618
3552
|
*
|
|
@@ -3638,16 +3572,8 @@ function persistedWriteSites() {
|
|
|
3638
3572
|
}
|
|
3639
3573
|
const table = parseTable(JSON.parse(raw));
|
|
3640
3574
|
cachedSites = table.sites;
|
|
3641
|
-
cachedSymbols = table.symbols;
|
|
3642
3575
|
return table.sites;
|
|
3643
3576
|
}
|
|
3644
|
-
/** The inventory's symbol legend — the roots every declared path is written against, with the
|
|
3645
|
-
* segments the gate checks against the resolver's source.
|
|
3646
|
-
* @internal no production caller — the gates read the JSON asset directly. */
|
|
3647
|
-
function writePathSymbols() {
|
|
3648
|
-
persistedWriteSites();
|
|
3649
|
-
return cachedSymbols ?? {};
|
|
3650
|
-
}
|
|
3651
3577
|
/** Sites serialized by the per-home instance claim, with their instance keys.
|
|
3652
3578
|
* @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
|
|
3653
3579
|
* reads the JSON asset directly; the tests are the only in-tree consumers. */
|
|
@@ -4233,16 +4159,16 @@ async function backupsReachability(io, backupsRoot, skillsPerSnapshot) {
|
|
|
4233
4159
|
* the SAME name in two carriers (reviewMode, staleAfterDays, archiveAfterDays —
|
|
4234
4160
|
* resolved by the existing policy-shadows-row rule) and six use DIFFERENT names.
|
|
4235
4161
|
* This module owns the six: the policy/snapshot name is the canonical id, the
|
|
4236
|
-
* plugin-row name is a deprecated alias
|
|
4237
|
-
*
|
|
4238
|
-
*
|
|
4162
|
+
* plugin-row name is a deprecated alias. The alias table survives only for the one-time
|
|
4163
|
+
* legacy-document migration and the doctor's old-key report; live readers use the
|
|
4164
|
+
* canonical id and its carrier no longer falls back to the legacy spelling.
|
|
4239
4165
|
*
|
|
4240
|
-
*
|
|
4241
|
-
* writing is strict (the write path accepts canonical ids only, so no new
|
|
4242
|
-
* document is created under a deprecated name).
|
|
4166
|
+
* Writing is canonical-only (a deprecated name is not a live row field in 0.48).
|
|
4243
4167
|
* @module
|
|
4244
4168
|
*/
|
|
4245
|
-
/** Deprecated alias (plugin-row name) -> canonical id (policy/snapshot name).
|
|
4169
|
+
/** Deprecated alias (plugin-row name) -> canonical id (policy/snapshot name).
|
|
4170
|
+
* Retained for the one-time legacy-document migration and the doctor's old-key report;
|
|
4171
|
+
* live readers use the canonical id only. */
|
|
4246
4172
|
const PARAM_ALIASES = Object.freeze({
|
|
4247
4173
|
memoryInterval: "reviewMemoryInterval",
|
|
4248
4174
|
skillInterval: "reviewSkillInterval",
|
|
@@ -4251,12 +4177,6 @@ const PARAM_ALIASES = Object.freeze({
|
|
|
4251
4177
|
memoryCharLimit: "memoryChars",
|
|
4252
4178
|
userCharLimit: "userChars"
|
|
4253
4179
|
});
|
|
4254
|
-
/** Canonical ids that have at least one deprecated alias, for read fallback. */
|
|
4255
|
-
const ALIASES_BY_CANONICAL = (() => {
|
|
4256
|
-
const index = {};
|
|
4257
|
-
for (const [alias, canonical] of Object.entries(PARAM_ALIASES)) (index[canonical] ??= []).push(alias);
|
|
4258
|
-
return index;
|
|
4259
|
-
})();
|
|
4260
4180
|
/**
|
|
4261
4181
|
* Resolve any parameter id to its canonical form.
|
|
4262
4182
|
* @param id - canonical id or deprecated alias.
|
|
@@ -4274,28 +4194,14 @@ function isDeprecatedParamId(id) {
|
|
|
4274
4194
|
return PARAM_ALIASES[id] !== void 0;
|
|
4275
4195
|
}
|
|
4276
4196
|
/**
|
|
4277
|
-
*
|
|
4278
|
-
* @param id - parameter id a caller intends to write.
|
|
4279
|
-
* @returns the canonical id.
|
|
4280
|
-
* @throws {Error} when the id is a deprecated alias; the message names both ids.
|
|
4281
|
-
*/
|
|
4282
|
-
function canonicalWriteId(id) {
|
|
4283
|
-
const canonical = PARAM_ALIASES[id];
|
|
4284
|
-
if (canonical === void 0) return id;
|
|
4285
|
-
throw new Error(`parameter id \`${id}\` is deprecated; write \`${canonical}\` instead`);
|
|
4286
|
-
}
|
|
4287
|
-
/**
|
|
4288
|
-
* Read a parameter from a carrier that may still spell the legacy name.
|
|
4197
|
+
* Read a parameter by its canonical id.
|
|
4289
4198
|
* @param carrier - config/snapshot object to read from, or undefined.
|
|
4290
|
-
* @param id - canonical id (
|
|
4291
|
-
* @returns the canonical value
|
|
4199
|
+
* @param id - canonical id (an alias is resolved first, for migration callers).
|
|
4200
|
+
* @returns the canonical value, or undefined.
|
|
4292
4201
|
*/
|
|
4293
4202
|
function readParam(carrier, id) {
|
|
4294
4203
|
if (carrier === void 0) return void 0;
|
|
4295
|
-
|
|
4296
|
-
const canonical = resolveParamId(id);
|
|
4297
|
-
if (record[canonical] !== void 0) return record[canonical];
|
|
4298
|
-
for (const alias of ALIASES_BY_CANONICAL[canonical] ?? []) if (record[alias] !== void 0) return record[alias];
|
|
4204
|
+
return carrier[resolveParamId(id)];
|
|
4299
4205
|
}
|
|
4300
4206
|
/**
|
|
4301
4207
|
* Chinese display name per group, one entry per line (the scripts read this block
|
|
@@ -5513,21 +5419,9 @@ const PARAM_EXPOSURE = Object.freeze([
|
|
|
5513
5419
|
owner: "scripts",
|
|
5514
5420
|
applies: "restart",
|
|
5515
5421
|
docAnchor: "PARAMETERS.md#deployment",
|
|
5516
|
-
summary: "Install target plane (values all / host;
|
|
5422
|
+
summary: "Install target plane (values all / host; legacy modes are uninstall-only in 0.48).",
|
|
5517
5423
|
why: "install"
|
|
5518
5424
|
},
|
|
5519
|
-
{
|
|
5520
|
-
id: "install.basePreset",
|
|
5521
|
-
group: "deployment",
|
|
5522
|
-
tier: "E4",
|
|
5523
|
-
authority: "install",
|
|
5524
|
-
owner: "scripts",
|
|
5525
|
-
applies: "restart",
|
|
5526
|
-
docAnchor: "PARAMETERS.md#deployment",
|
|
5527
|
-
summary: "Agent-preset base the layered install composes from (--base).",
|
|
5528
|
-
why: "install",
|
|
5529
|
-
consumer: "basePresetPlugins"
|
|
5530
|
-
},
|
|
5531
5425
|
{
|
|
5532
5426
|
id: "install.home",
|
|
5533
5427
|
group: "deployment",
|
|
@@ -5539,18 +5433,6 @@ const PARAM_EXPOSURE = Object.freeze([
|
|
|
5539
5433
|
summary: "Harness home the installer writes into (--home).",
|
|
5540
5434
|
why: "install"
|
|
5541
5435
|
},
|
|
5542
|
-
{
|
|
5543
|
-
id: "install.presetRowOverrides",
|
|
5544
|
-
group: "deployment",
|
|
5545
|
-
tier: "E4",
|
|
5546
|
-
authority: "install",
|
|
5547
|
-
owner: "scripts",
|
|
5548
|
-
applies: "restart",
|
|
5549
|
-
docAnchor: "PARAMETERS.md#deployment",
|
|
5550
|
-
summary: "Preset row overrides the installer injects (row-overrides.json).",
|
|
5551
|
-
why: "install",
|
|
5552
|
-
consumer: "loadRowOverrides"
|
|
5553
|
-
},
|
|
5554
5436
|
{
|
|
5555
5437
|
id: "mergeApproval",
|
|
5556
5438
|
group: "merge",
|
|
@@ -5643,28 +5525,13 @@ const NAMESPACE_MIGRATIONS = Object.freeze(Object.entries(PARAM_NAMESPACES).filt
|
|
|
5643
5525
|
rowId: owner
|
|
5644
5526
|
})));
|
|
5645
5527
|
/**
|
|
5646
|
-
* The LEGACY settings namespace one owner package used to register through the family's
|
|
5647
|
-
* own seam (0.1.x). It is no longer what the platform calls the section: the platform
|
|
5648
|
-
* derives a settings namespace from the Loader entry id, and this registry's `owner` field
|
|
5649
|
-
* IS that row id, so a live lookup uses {@link paramRowId}. What remains here is the
|
|
5650
|
-
* migration SOURCE (G3 moves a user layer out of this string and into the row id).
|
|
5651
|
-
* @param owner - owner package directory name (the map's key).
|
|
5652
|
-
* @returns the legacy namespace that owner registered.
|
|
5653
|
-
* @throws when the owner has no entry in {@link PARAM_NAMESPACES}.
|
|
5654
|
-
*/
|
|
5655
|
-
function paramNamespace(owner) {
|
|
5656
|
-
const namespace = PARAM_NAMESPACES[owner];
|
|
5657
|
-
if (namespace === void 0) throw new Error("no settings namespace registered for owner `" + owner + "` (add it to PARAM_NAMESPACES)");
|
|
5658
|
-
return namespace;
|
|
5659
|
-
}
|
|
5660
|
-
/**
|
|
5661
5528
|
* The settings id one row's user layer lives under, or undefined when the owner publishes
|
|
5662
5529
|
* no user layer at all (a deployment-only row: its knobs are E2 and never reach a settings
|
|
5663
5530
|
* section). The platform derives a settings namespace from the Loader entry id and reports
|
|
5664
5531
|
* it in `settings.describe()` / `configForms.get(entryId)`, and an owner package's row id is
|
|
5665
5532
|
* its own name — spelled the same in every bundle patch.
|
|
5666
5533
|
*
|
|
5667
|
-
* This is the id to LOOK UP with; {@link
|
|
5534
|
+
* This is the id to LOOK UP with; {@link PARAM_NAMESPACES} keeps the legacy string the 0.1.x
|
|
5668
5535
|
* seam registered, which is the G3 migration source and never a live lookup key.
|
|
5669
5536
|
* @param owner - owner package directory name (the row id).
|
|
5670
5537
|
* @returns the entry id the platform reports for that row, or undefined for a row without
|
|
@@ -5997,24 +5864,6 @@ function clampOnce(warned, warn, name, value, fallback, min, max) {
|
|
|
5997
5864
|
function liveBool(value, fallback = false) {
|
|
5998
5865
|
return unwrapLive(value) ?? fallback;
|
|
5999
5866
|
}
|
|
6000
|
-
/**
|
|
6001
|
-
* Read a string (live or plain). Blank/whitespace counts as unset — the same rule `evolutionRoot` uses
|
|
6002
|
-
* for `DSH_HOME`.
|
|
6003
|
-
*/
|
|
6004
|
-
function liveString(value, fallback) {
|
|
6005
|
-
const current = unwrapLive(value)?.trim();
|
|
6006
|
-
return current === void 0 || current.length === 0 ? fallback : current;
|
|
6007
|
-
}
|
|
6008
|
-
/**
|
|
6009
|
-
* Read an enumerated string (live or plain); a value outside `allowed` falls back.
|
|
6010
|
-
*
|
|
6011
|
-
* Used for the mode-like knobs (review mode, trigger, citation policy, write-confirm mode) where a
|
|
6012
|
-
* bare `?? default` would accept a typo the schema never saw.
|
|
6013
|
-
*/
|
|
6014
|
-
function liveEnum(value, allowed, fallback) {
|
|
6015
|
-
const current = unwrapLive(value);
|
|
6016
|
-
return current !== void 0 && allowed.includes(current) ? current : fallback;
|
|
6017
|
-
}
|
|
6018
5867
|
//#endregion
|
|
6019
5868
|
//#region lib/types/opt-in.js
|
|
6020
5869
|
/**
|
|
@@ -6112,50 +5961,6 @@ function sessionAudited(ctx, sessionId, sessionScoped) {
|
|
|
6112
5961
|
return false;
|
|
6113
5962
|
}
|
|
6114
5963
|
//#endregion
|
|
6115
|
-
//#region lib/types/fold-untrusted.js
|
|
6116
|
-
/**
|
|
6117
|
-
* Untrusted text rendered as prompt lines (T3-03/A31) — ONE folding rule.
|
|
6118
|
-
*
|
|
6119
|
-
* The background-review digest embeds conversation text and tool output into a
|
|
6120
|
-
* plain-text prompt whose PRODUCT is a plan with write permission. Anything the
|
|
6121
|
-
* session ingested (a fetched page, a file body, command output) can therefore
|
|
6122
|
-
* carry a newline plus a line shaped like the prompt's own structure — a
|
|
6123
|
-
* `SYSTEM:`/`Review kind:` header, a `[result]` evidence line, a second copy
|
|
6124
|
-
* of the closing instruction — and forge structure or inject instructions.
|
|
6125
|
-
*
|
|
6126
|
-
* FOLDING, not deleting: the reader (the model) must still SEE what the data
|
|
6127
|
-
* said, it just must never become structure. Line separators become a visible
|
|
6128
|
-
* `⏎`, and a line that would read as a role/evidence header gets a visible
|
|
6129
|
-
* marker in front of it. Every original character stays in place.
|
|
6130
|
-
*
|
|
6131
|
-
* The boundary is the separator itself, not only a real newline: a payload can
|
|
6132
|
-
* paste the separator verbatim, so neutralization matches after `⏎` whether it
|
|
6133
|
-
* came from the fold or from the data. Both edits are idempotent (a second pass
|
|
6134
|
-
* cannot add a second marker).
|
|
6135
|
-
*
|
|
6136
|
-
* Scope: text rendered as its OWN line(s) of a prompt. `render-facts`'
|
|
6137
|
-
* sanitizer (evolution-maintenance) is the same posture for `key=value` fields
|
|
6138
|
-
* and additionally escapes its block delimiter; it is not superseded here.
|
|
6139
|
-
* @module @lmzhen/dsh-evolution-core
|
|
6140
|
-
*/
|
|
6141
|
-
/** Visible stand-in for a folded line separator: one character that cannot be read as line structure. */
|
|
6142
|
-
const UNTRUSTED_LINE_BREAK = " ⏎ ";
|
|
6143
|
-
/** Visible marker prefixed to a line that would otherwise read as a role/structure header. */
|
|
6144
|
-
const UNTRUSTED_LINE_MARK = "· ";
|
|
6145
|
-
const NEWLINES = /\r\n|\r|\n/g;
|
|
6146
|
-
/** A line that reads as structure: a `Label:` head (SYSTEM:, Review kind:, Signals:) or a digest evidence tag.
|
|
6147
|
-
* The head is case-TOLERANT on purpose: this family's own prompt labels are mixed case, so an
|
|
6148
|
-
* uppercase-only rule neutralized SYSTEM: while leaving a forged "Review kind:" untouched. */
|
|
6149
|
-
const STRUCTURAL_HEAD = /(^|⏎)([ \t]*)((?:[A-Za-z][A-Za-z0-9 _]{2,}:|\[result\]|\[call\]))/g;
|
|
6150
|
-
/**
|
|
6151
|
-
* Fold untrusted `text` so it cannot become structure, then bound it to `limit`
|
|
6152
|
-
* visible characters. A non-positive `limit` means "no truncation".
|
|
6153
|
-
*/
|
|
6154
|
-
function foldUntrustedLines(text, limit) {
|
|
6155
|
-
const marked = text.replace(NEWLINES, UNTRUSTED_LINE_BREAK).replace(STRUCTURAL_HEAD, (_match, boundary, spaces, head) => `${boundary}${spaces}· ${head}`);
|
|
6156
|
-
return limit > 0 ? marked.slice(0, limit) : marked;
|
|
6157
|
-
}
|
|
6158
|
-
//#endregion
|
|
6159
5964
|
//#region lib/types/diagnostics.js
|
|
6160
5965
|
const DIAGNOSTICS_VIEW_SCHEMA_VERSION = 2;
|
|
6161
5966
|
const DIAGNOSTICS_FACT_KEYS = [
|
|
@@ -6198,9 +6003,5 @@ function classifySessionEvent(event) {
|
|
|
6198
6003
|
if (type.startsWith("plugin:")) return event.ignorable === true ? "plugin-record" : "unknown";
|
|
6199
6004
|
return MODEL_EVENT_TYPES.has(type) ? "model" : "unknown";
|
|
6200
6005
|
}
|
|
6201
|
-
/** True when the event must be skipped by evidence/usage readers (tolerant, never fatal). */
|
|
6202
|
-
function isIgnorableEvent(event) {
|
|
6203
|
-
return classifySessionEvent(event) !== "model";
|
|
6204
|
-
}
|
|
6205
6006
|
//#endregion
|
|
6206
|
-
export { AUTHORING_DESCRIPTION_BAR, AUTHORING_SPLIT_LINE_CHARS, AuthorityBusyError, AuthorityOrderError, AuthorityReentryError, CITATION_SUPPORT_DIRS, COMBINED_REVIEW_PROMPT, COMPLETION_SKILL_REVIEW_PROMPT, CONTENT_SPLIT_HINT, COST_ASCII_TOKEN_HIGH, COST_ASCII_TOKEN_LOW, COST_CJK_TOKEN_HIGH, COST_CJK_TOKEN_LOW, CURATOR_DRY_RUN_BANNER, CURATOR_PROMPT, DEDUP_MAX_PAIR_COMPARISONS, DEDUP_SIMILARITY_THRESHOLD,
|
|
6007
|
+
export { AUTHORING_DESCRIPTION_BAR, AUTHORING_SPLIT_LINE_CHARS, AuthorityBusyError, AuthorityOrderError, AuthorityReentryError, CITATION_SUPPORT_DIRS, COMBINED_REVIEW_PROMPT, COMPLETION_SKILL_REVIEW_PROMPT, CONTENT_SPLIT_HINT, COST_ASCII_TOKEN_HIGH, COST_ASCII_TOKEN_LOW, COST_CJK_TOKEN_HIGH, COST_CJK_TOKEN_LOW, CURATOR_DRY_RUN_BANNER, CURATOR_PROMPT, DEDUP_MAX_PAIR_COMPARISONS, DEDUP_SIMILARITY_THRESHOLD, DEFAULT_ARCHIVE_AFTER_DAYS, DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_CITATION_REF_BUDGET, DEFAULT_CONSOLIDATION_FAILURES, DEFAULT_CURATOR_BOOT_GRACE_SECONDS, DEFAULT_CURATOR_INTERVAL_HOURS, DEFAULT_CURATOR_MODEL, DEFAULT_CURATOR_REVIEW_MAX_TOKENS, DEFAULT_LEASE_TTL_MS, DEFAULT_MEMORY_CHAR_LIMIT, DEFAULT_MIN_IDLE_HOURS, DEFAULT_MUTATION_CAP, DEFAULT_PROBE_TIMEOUT_MS, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_REVIEW_MEMORY_INTERVAL, DEFAULT_REVIEW_SKILL_INTERVAL, DEFAULT_REVIEW_TIMEOUT_MS, DEFAULT_RUN_RECORDS, DEFAULT_SKILL_CONTENT_CHARS, DEFAULT_SKILL_LIMITS, DEFAULT_SKILL_REVIEW_COMPLETION_MIN_TOOL_CALLS, DEFAULT_SKILL_REVIEW_TRIGGER, DEFAULT_SKILL_VERSION_KEEP, DEFAULT_STALE_AFTER_DAYS, DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS, DEFAULT_SUBSTANTIVE_MIN_TOOL_CALLS, DEFAULT_SUBSTANTIVE_MIN_USER_CHARS, DEFAULT_SUPPORT_FILE_CHAR_POLICY, DEFAULT_SUPPORT_READ_TOOL_NAMES, DEFAULT_THREAT_MAX_SCAN_CHARS, DEFAULT_USER_CHAR_LIMIT, DEFAULT_WRITE_CONFIRM_MODE, DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS, DIAGNOSTICS_FACT_KEYS, DIAGNOSTICS_RUNTIME_KEYS, DIAGNOSTICS_VIEW_SCHEMA_VERSION, DISPATCH_EVENT_TYPES, DRIFT_MAX_LINE_CHARS, DRIFT_SIGNALS_VERSION, DRIFT_SIGNAL_NOUNS, DSH_AUTHORING_STANDARDS, ENTRY_DELIMITER, EVENT_ARCHIVE_PREFIX, EVENT_LOG_RETAIN_ARCHIVES, EVENT_LOG_ROTATE_AT, EVENT_LOG_VERSION, EVOLUTION_ERRORS, EVOLUTION_PRESET_IDS, EVOLUTION_WRITE_TOOLS, EXTRACT_PROMPT_HASH, EXTRACT_PROMPT_V1, EXTRACT_PROMPT_VERSION, EvolutionGateSet, FAMILY_SESSION_TOOL_NAMES, FORBIDDEN_CONTROL_KEYS, FUZZY_MAX_PATTERN_CHARS, FUZZY_MAX_WORK, HOOK_LINE_RE, HOST_LOCALES, HOST_ROUTES, HomeAuthority, HomeFence, HomeFenceError, INJECT_COMBINED_REVIEW_PROMPT, INJECT_COMPLETION_SKILL_REVIEW_PROMPT, INJECT_MEMORY_REVIEW_PROMPT, INJECT_SKILL_REVIEW_PROMPT, INSTANCE_KEYS, KEEP_LINE_RE, LONG_RUNS, LOW_QUALITY_THRESHOLD, LeaseStore, MAINTAINER_PRESET_ID, MAINTAIN_OUTPUT_INSTRUCTION, MAINTAIN_PROMPT, MAX_DESCRIPTION_LENGTH, MAX_REQUEST_BODY_BYTES, MAX_SKILL_CONTENT_CHARS, MAX_SKILL_FILE_BYTES, MAX_SKILL_NAME_LENGTH, MAX_SUPPORT_READ_PATHS, MAX_TIMER_DELAY_MS, MEMORY_GUIDANCE_SECTION_ORDER, MEMORY_REVIEW_PROMPT, MODEL_SESSION_EVENT_TYPES, MUTATIONS_FILE_VERSION, MemoryStore, MutationAuthority, NAMESPACE_MIGRATIONS, NATIVE_CALL_EVENT, NATIVE_RESULT_EVENT, PARAM_ALIASES, PARAM_EXPOSURE, PARAM_GROUP_LABELS, PARAM_NAMESPACES, PATTERN_OVERLAP, PLATFORM_LINE, PLATFORM_SERVICE_PROBES, POLICY_STAGE_DEFAULTS, PROMPT_BUNDLE, PROMPT_BUNDLE_ID, PROMPT_BUNDLE_VERSION, PROTECTED_BUILTIN_SKILLS, PTC_DISPATCH_EVENT, PTC_DISPATCH_START_EVENT, QUALITY_WEIGHTS, RESTRICTED_PRESET_DISPLAY, RESTRICTED_TOOLS_ROW_ID, RESTRICTOR_MODULE, REVIEWER_PRESET_ID, RUNS_SCHEMA_VERSION, SKILLS_GUIDANCE, SKILLS_GUIDANCE_SECTION_ORDER, SKILL_ACTION_REQUIRED_FIELDS, SKILL_NAME_RE, SKILL_REVIEW_PROMPT, STORE_LEDGER, SUMMARY_DUPLICATE_HINT_THRESHOLD, SUPPORT_DIRS, SUPPORT_SPRAWL_FILES, SUPPRESSED_FILE_VERSION, THREAT_EXEMPTION_HINT, TOKEN_ASCII_WEIGHT, TOKEN_CJK_WEIGHT, ToolDispatchNormalizer, ToolDispatchPayloadError, TransactionNotInvokedError, UPSTREAM_LIMIT_CHARS_PER_TOKEN, absentHostServices, advanceReview, affinity, allowRowCollisions, appendEvolutionEvent, applyCuratorLifecycleFields, applyCuratorMetaFields, applyNamespaceMigration, applyReferenceRewrite, asRecord, assertDispatchPayload, atomicWriteFiles, authorityFrom, authorityHolder, backupsReachability, bodyCost, buildCuratorRunReport, buildExtractPlanFromLibrary, buildHealthBaseline, buildLearnPrompt, bumpPatch, bumpSupportRead, bumpUse, bumpView, callingScope, claimInstance, clampOnce, clampedNumber, classifyNamespaceMigration, classifySessionEvent, clearReviewChannel, collectReadSkillNames, collectReadSupportFiles, computeDedupGroups, computeDriftSignals, computeLifecycleTransitions, computePrefixClusters, computeQualityScores, computeScopeView, contentHash, createGateSet, createSubagentChannel, currentReviewContext, daysSinceIso, declaredReportStamp, describeReferenceRewrite, dispatchKeyOf, dispatchPathOf, dispatchStepOf, displayBodyOf, duplicateHeadings, emptyRecord, errorText, errorTextIn, evaluateThreat, eventsFile, evidenceKindIndex, evolutionActivityProjection, evolutionEventPayloadIssue, evolutionEvidenceProjection, evolutionHome, evolutionIoAdapter, evolutionProjectionHistoryProjection, evolutionReadsProjection, evolutionRoot, evolutionSignalsProjection, externalRefs, findDriftSignal, findOwnerCandidate, foldCuratorFields, foldToolDispatches, foldTurnEvent, foldTurnEvents, fuzzyPatch, getRecord, h2Sections, historyReachability, hostSurface, identity, idleDays, initialTurnFold, instanceClaimKey, instanceClaimedWriteSites, instanceHolder, isAbsent, isBookkeepingFrame, isCommittedWarning, isDeprecatedParamId, isFileShapedPath, isMissingPath, isPresent, isProcessAlive, isProjectableSession, isRecord, isReviewChannelSession, isSkillReadToolName, isSkillToolName, isUnknown, json, latestActivityAt, leaseAsTreeLock, leaseFile, lifecycleCandidate, listEventArchives, liveBool, liveNumber, loadMutations, loadSuppressedNames, loadUsage, makeSerialQueue, markAgentCreated, markReviewChannel, memoryRoot, methodNotAllowed, missingSupportPointers, mutateUsage, mutationLockFrom, mutationsFile, narrowNameMatches, nearDuplicateSummaries, newRunRegistry, nodeEvolutionIo, normalizeUsageRecord, observeEvent, overlongLines, ownerCandidatesFromSummaries, ownerDecisionText, paramRowId, paramSettingsId, parseCuratorNominations, parseEvolutionEvents, payloadText, persistedWriteSite, persistedWriteSites, pickWithPolicy, planExtract, planNamespaceMigration, planReferenceRewrite, planRehoming, policyStageLimits, probeAbsent, probeChannelState, probeList, probeMtime, probePresent, probeReason, probeText, probeUnknown, projectExtractBodies, projectionText, proposalFromPlan, proposalReportDir, proposalReportName, protectedSkillNamesOf, readDispatchSignal, readEvolutionEvents, readEvolutionTimeline, readExternalSupport, readJsonObject, readNumberParam, readParam, readProposalReport, readProposalReports, readingStats, recordMutation, redactSecrets, referencedBlobs, registerHostRoutes, releaseInstance, renameWithRetry, renderCuratorReportMarkdown, renderLongRunTable, reportTime, reportsReachability, reportsSweepLockTarget, resolveCitations, resolveParamId, retainEventArchives, retirementReport, reviewPrompt, runWriteGates, runsFile, saveSuppressedNames, saveUsage, scanBodyHooks, scanContentThreats, scanMemoryThreats, scanThreats, scopeOfNearestManifest, scopedPackageName, scopedProbeReport, selectSections, sessionAudited, sessionEvidenceIndex, sessionLastEventTime, sessionReadNames, sessionSeesFamilyTools, sessionTurnSignals, skillReadNameOf, skillWriteGateContext, supportFileReadFromPath, supportFileReadOf, supportRefs, suppressedFile, sweepReports, sweepReviewChannelSessions, tokenLineFor, transactIo, trimPatternBoundaries, unhookedSupportPointers, unwrapLive, updateSuppressedNames, usageFile, usageObserved, userSetKeys, verifyPromptBundle, vocabulary, withReviewContext, withTreeWrite, writeDurableTmp, writeProposalReport };
|
|
@@ -27,13 +27,6 @@ function isAbsent(probe) {
|
|
|
27
27
|
function isUnknown(probe) {
|
|
28
28
|
return probe.kind === "unknown";
|
|
29
29
|
}
|
|
30
|
-
/** Only a PRESENT probe yields a value; absent and unknown both fall back. */
|
|
31
|
-
function valueOr(probe, fallback) {
|
|
32
|
-
return probe.kind === "present" ? probe.value : fallback;
|
|
33
|
-
}
|
|
34
|
-
function mapProbe(probe, transform) {
|
|
35
|
-
return probe.kind === "present" ? probePresent(transform(probe.value)) : probe;
|
|
36
|
-
}
|
|
37
30
|
/** The reason an `unknown` probe carries (message, never a bare String(object)). */
|
|
38
31
|
function probeReason(error) {
|
|
39
32
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -131,6 +124,14 @@ async function reportTime(io, path, parsed) {
|
|
|
131
124
|
* Every evolution package passes `ctx.evolutionIo.provider()`; standalone
|
|
132
125
|
* consumers (and the core's own tests) can use `nodeEvolutionIo`.
|
|
133
126
|
*/
|
|
127
|
+
/** A backend's transact returned without ever calling the task; nothing was written. */
|
|
128
|
+
var TransactionNotInvokedError = class extends Error {
|
|
129
|
+
code = "transact-not-invoked";
|
|
130
|
+
constructor(path) {
|
|
131
|
+
super("transact-not-invoked: " + path);
|
|
132
|
+
this.name = "TransactionNotInvokedError";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
134
135
|
/**
|
|
135
136
|
* Run `task` inside `io.transact` when the backend provides it; otherwise fall
|
|
136
137
|
* back to a plain read → task → write/remove sequence (no cross-process lock —
|
|
@@ -140,78 +141,36 @@ async function reportTime(io, path, parsed) {
|
|
|
140
141
|
*/
|
|
141
142
|
async function transactIo(io, path, task) {
|
|
142
143
|
const committedOnly = (error) => isCommittedWarning(error);
|
|
144
|
+
const warnings = [];
|
|
145
|
+
const warnCommitted = (error) => {
|
|
146
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
147
|
+
warnings.push(message);
|
|
148
|
+
console.warn(`evolution-io: ${path} was written but its directory fsync failed — the bytes are visible, durability is unconfirmed: ${message}`);
|
|
149
|
+
};
|
|
150
|
+
let invoked = false;
|
|
151
|
+
const invoke = async (current) => {
|
|
152
|
+
invoked = true;
|
|
153
|
+
return await task(current);
|
|
154
|
+
};
|
|
143
155
|
if (io.transact) try {
|
|
144
|
-
await io.transact(path,
|
|
156
|
+
await io.transact(path, invoke);
|
|
157
|
+
if (!invoked) throw new TransactionNotInvokedError(path);
|
|
145
158
|
return;
|
|
146
159
|
} catch (error) {
|
|
147
160
|
if (!committedOnly(error)) throw error;
|
|
148
|
-
|
|
149
|
-
return;
|
|
161
|
+
warnCommitted(error);
|
|
162
|
+
return warnings;
|
|
150
163
|
}
|
|
151
164
|
const current = await io.readText(path);
|
|
152
|
-
const next = await
|
|
165
|
+
const next = await invoke(current);
|
|
153
166
|
if (next === null) await io.remove(path);
|
|
154
167
|
else if (next !== current) try {
|
|
155
168
|
await io.writeText(path, next);
|
|
156
169
|
} catch (error) {
|
|
157
170
|
if (!committedOnly(error)) throw error;
|
|
158
|
-
|
|
171
|
+
warnCommitted(error);
|
|
159
172
|
}
|
|
160
|
-
|
|
161
|
-
function outcomeFailure(error) {
|
|
162
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
163
|
-
if (isCommittedWarning(error)) return {
|
|
164
|
-
kind: "unknown",
|
|
165
|
-
message
|
|
166
|
-
};
|
|
167
|
-
const code = error?.code;
|
|
168
|
-
return {
|
|
169
|
-
kind: "rejected",
|
|
170
|
-
code: typeof code === "string" ? code : "io",
|
|
171
|
-
message
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Read-modify-commit that reports what actually happened instead of collapsing the two failure
|
|
176
|
-
* kinds. `transactIo` deliberately turns a committed-warning into success (the bytes are visible),
|
|
177
|
-
* which is right for callers that only need the write; a two-phase caller needs to know that its
|
|
178
|
-
* follow-up step is unconfirmed, so it uses this instead.
|
|
179
|
-
* @param io - the IO backend.
|
|
180
|
-
* @param path - the durable file.
|
|
181
|
-
* @param task - the read-modify-render step.
|
|
182
|
-
* @returns `landed`, `unknown` (written, durability unconfirmed) or `rejected`.
|
|
183
|
-
*/
|
|
184
|
-
async function transactOutcome(io, path, task) {
|
|
185
|
-
if (io.transact) try {
|
|
186
|
-
await io.transact(path, task);
|
|
187
|
-
return { kind: "landed" };
|
|
188
|
-
} catch (error) {
|
|
189
|
-
return outcomeFailure(error);
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const current = await io.readText(path);
|
|
193
|
-
const next = await task(current);
|
|
194
|
-
if (next === null) await io.remove(path);
|
|
195
|
-
else if (next !== current) await io.writeText(path, next);
|
|
196
|
-
return { kind: "landed" };
|
|
197
|
-
} catch (error) {
|
|
198
|
-
return outcomeFailure(error);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/** Build a {@link TransactTaskGuard} for one write path. See its doc. */
|
|
202
|
-
function transactTaskGuard(what) {
|
|
203
|
-
let invoked = false;
|
|
204
|
-
return {
|
|
205
|
-
wrap: (task) => (current) => {
|
|
206
|
-
invoked = true;
|
|
207
|
-
return task(current);
|
|
208
|
-
},
|
|
209
|
-
invoked: () => invoked,
|
|
210
|
-
assertInvoked: () => {
|
|
211
|
-
if (invoked) return;
|
|
212
|
-
throw new Error(`internal error: the write transaction for ${what} did not invoke the task; no write was performed`);
|
|
213
|
-
}
|
|
214
|
-
};
|
|
173
|
+
return warnings.length === 0 ? void 0 : warnings;
|
|
215
174
|
}
|
|
216
175
|
/** Lazy adapter over an IO provider registry, shared by every evolution consumer. */
|
|
217
176
|
function evolutionIoAdapter(provider) {
|
|
@@ -230,9 +189,10 @@ function evolutionIoAdapter(provider) {
|
|
|
230
189
|
const io = provider();
|
|
231
190
|
return io.size ? io.size(path) : Promise.resolve(null);
|
|
232
191
|
},
|
|
233
|
-
transact: (path, task) => {
|
|
192
|
+
transact: async (path, task) => {
|
|
234
193
|
const io = provider();
|
|
235
|
-
|
|
194
|
+
if (io.transact) await io.transact(path, task);
|
|
195
|
+
else await transactIo(io, path, task);
|
|
236
196
|
},
|
|
237
197
|
isSymlink: (path) => {
|
|
238
198
|
const io = provider();
|
|
@@ -685,4 +645,4 @@ function atomicWriteFiles(targetDir, writes, fs = defaultFs, logger = console.wa
|
|
|
685
645
|
}
|
|
686
646
|
}
|
|
687
647
|
//#endregion
|
|
688
|
-
export {
|
|
648
|
+
export { reportTime as S, probeMtime as _, isProcessAlive as a, probeText as b, transactIo as c, isAbsent as d, isMissingPath as f, probeList as g, probeAbsent as h, isCommittedWarning as i, writeDurableTmp as l, isUnknown as m, atomicWriteFiles as n, nodeEvolutionIo as o, isPresent as p, evolutionIoAdapter as r, renameWithRetry as s, TransactionNotInvokedError as t, declaredReportStamp as u, probePresent as v, probeUnknown as x, probeReason as y };
|
package/lib/io-node.js
CHANGED