@lmzhen/dsh-evolution-core 0.59.6 → 0.60.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/README.md +3 -1
- package/lib/authority-plugin.js +3 -2
- package/lib/composition/index.js +2 -2
- package/lib/{composition-B_F4TYOD.js → composition-BSqh70z_.js} +1 -1
- package/lib/{ensure-BpVDuDnA.js → ensure-DTCuxAxR.js} +1 -1
- package/lib/{extract-plan-D3ALlAmN.js → extract-plan-CP__XlEs.js} +2 -2
- package/lib/extract.js +4 -4
- package/lib/http-routes.js +3 -2
- package/lib/index.js +15 -15
- package/lib/{io-Cpa8wuvj.js → io-DT4-MXLr.js} +25 -1
- package/lib/io-node.js +1 -1
- package/lib/io-platform.js +163 -0
- package/lib/io-registry.js +10 -0
- package/lib/{mutation-authority-CZpc9F20.js → mutation-authority-C3RYyiaT.js} +66 -41
- package/lib/{mutation-storage-adapter-Cq1bmS1E.js → mutation-storage-adapter-CSVn34dK.js} +327 -210
- package/lib/{mutations-Y-wKod7W.js → mutations-JKFlfhSO.js} +1 -1
- package/lib/policy.js +1 -1
- package/lib/{quality-NPGr3VzA.js → quality-C0ri2SgY.js} +2 -2
- package/lib/restrictor.js +1 -1
- package/lib/result.js +1 -1
- package/lib/{review-context-yNiZadPw.js → review-context-D2LIOEi-.js} +2 -2
- package/lib/runtime/plugin.js +2 -2
- package/lib/{session-projection-DM15fsRp.js → session-projection-Dnmm5bzt.js} +1 -1
- package/lib/{skill-history-BvLWFoOo.js → skill-history-BOZ4HCDB.js} +2 -2
- package/lib/skills.js +268 -37
- package/lib/state/domain/index.js +433 -0
- package/lib/state/index.js +136 -0
- package/lib/state/migrate.js +90 -0
- package/lib/state/storage.js +605 -0
- package/lib/state/store-plugin.js +23 -0
- package/lib/state/store.js +268 -0
- package/lib/subagent/index.js +1 -1
- package/lib/types/authority-plugin.d.ts +1 -1
- package/lib/types/authority-plugin.js +2 -1
- package/lib/types/authority.d.ts +1 -1
- package/lib/types/authority.js +75 -48
- package/lib/types/composition/ensure.js +1 -1
- package/lib/types/contract.d.ts +8 -0
- package/lib/types/http-routes.d.ts +1 -0
- package/lib/types/http-routes.js +2 -1
- package/lib/types/io-platform.d.ts +74 -0
- package/lib/types/io-platform.js +178 -0
- package/lib/types/io-registry.d.ts +4 -0
- package/lib/types/io-registry.js +10 -0
- package/lib/types/io.d.ts +7 -0
- package/lib/types/io.js +25 -1
- package/lib/types/mutation-authority.d.ts +1 -1
- package/lib/types/mutation-storage-adapter.d.ts +1 -1
- package/lib/types/opt-in.js +2 -2
- package/lib/types/params.js +2 -2
- package/lib/types/policy.js +1 -1
- package/lib/types/restrictor.js +2 -2
- package/lib/types/result.d.ts +1 -1
- package/lib/types/result.js +1 -1
- package/lib/types/runtime/coherence.js +1 -1
- package/lib/types/runtime/llm.d.ts +1 -1
- package/lib/types/runtime/llm.js +1 -1
- package/lib/types/runtime/platform.d.ts +3 -3
- package/lib/types/runtime/platform.js +2 -2
- package/lib/types/runtime/projections.d.ts +1 -1
- package/lib/types/scope.js +1 -1
- package/lib/types/session-projection.d.ts +1 -1
- package/lib/types/signals.d.ts +1 -1
- package/lib/types/skill-store.d.ts +37 -4
- package/lib/types/skill-store.js +240 -24
- package/lib/types/skill-write-plan.d.ts +1 -1
- package/lib/types/skill-write-service.js +8 -2
- package/lib/types/state/conformance.d.ts +47 -0
- package/lib/types/state/conformance.js +246 -0
- package/lib/types/state/constants.d.ts +52 -0
- package/lib/types/state/constants.js +52 -0
- package/lib/types/state/domain/compatibility.d.ts +40 -0
- package/lib/types/state/domain/compatibility.js +36 -0
- package/lib/types/state/domain/index.d.ts +81 -0
- package/lib/types/state/domain/index.js +592 -0
- package/lib/types/state/index.d.ts +63 -0
- package/lib/types/state/index.js +174 -0
- package/lib/types/state/medium-declaration.d.ts +37 -0
- package/lib/types/state/medium-declaration.js +53 -0
- package/lib/types/state/migrate.d.ts +34 -0
- package/lib/types/state/migrate.js +103 -0
- package/lib/types/state/record-contract.d.ts +56 -0
- package/lib/types/state/record-contract.js +120 -0
- package/lib/types/state/storage.d.ts +112 -0
- package/lib/types/state/storage.js +178 -0
- package/lib/types/state/store-plugin.d.ts +14 -0
- package/lib/types/state/store-plugin.js +18 -0
- package/lib/types/state/store.d.ts +39 -0
- package/lib/types/state/store.js +270 -0
- package/lib/types/store-ledger.js +2 -2
- package/lib/types/subagent/run.d.ts +1 -1
- package/lib/types/subagent/types.d.ts +4 -4
- package/lib/types/{write-kernel.d.ts → target-writer.d.ts} +32 -15
- package/lib/types/{write-kernel.js → target-writer.js} +40 -8
- package/lib/types/tool-dispatch.js +6 -3
- package/lib/types/{mutation-unit.d.ts → unit-kernel.d.ts} +40 -13
- package/lib/types/{mutation-unit.js → unit-kernel.js} +155 -118
- package/lib/types/write.d.ts +1 -2
- package/lib/types/write.js +1 -2
- package/lib/{usage-D7yHG2Cb.js → usage-BO4Zj_zB.js} +2 -2
- package/lib/write.js +4 -4
- package/package.json +30 -3
- package/persisted-write-inventory.json +14 -5
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@ Shared library for the evolution family: skill and memory stores, write kernels
|
|
|
4
4
|
|
|
5
5
|
The root entry is a library, not a user-facing command. The package also exposes `./composition`, `./subagent`, `./http-routes`, `./restrictor`, and `./runtime` subpaths.
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
The `./io-platform` subpath adapts the platform filesystem service (`ctx.fs`) to the family's existing `EvolutionIoLike` seam. It is the production backend used by the shipped composition rows; `./io-node` remains available for tests and standalone consumers as the legacy local backend.
|
|
8
|
+
|
|
9
|
+
The former `./platform` compatibility barrel is removed: feature packages import port types from `@lmzhen/dsh-evolution-platform/contract`, port functions from `@lmzhen/dsh-evolution-platform/ports`, and host runtime helpers from `@lmzhen/dsh-evolution-platform/values`. `./runtime` no longer mounts `evolutionPlatform`; the bundle's `evolution-platform` row owns it and mounts before core/runtime.
|
|
8
10
|
|
|
9
11
|
`./runtime` is a function plugin. It provides `evolutionProjections`, the single owner of the five host-only session units (`evolutionActivity`, `evolutionEvidence`, `evolutionReads`, `evolutionProjectionHistory`, `evolutionSignals`); readers ask that service and degrade to `undefined` when the platform registry is absent. It also provides `evolutionLlm`, the single route/purpose/transport owner for auxiliary model calls (curator, merge judge, domain generation). A granular composition that mounts feature rows without a family bundle must mount this row too. The runtime also installs the minimal-preset guard: while the active preset is `minimal`, family model tools are hidden per agent scope and AUX review is skipped; UI/commands remain profile-level.
|
|
10
12
|
|
package/lib/authority-plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as MutationAuthority } from "./mutation-authority-
|
|
1
|
+
import { n as MutationAuthority } from "./mutation-authority-C3RYyiaT.js";
|
|
2
2
|
import { t as evolutionHome } from "./state-store-Jpa-iYIZ.js";
|
|
3
3
|
import z from "@deepseek-ai/schemastery";
|
|
4
4
|
//#region lib/types/authority-plugin.js
|
|
@@ -6,7 +6,8 @@ const Config = z.object({ keyedSkillLocks: z.boolean().default(false) });
|
|
|
6
6
|
const name = "evolution-authority";
|
|
7
7
|
const inject = ["evolutionIo"];
|
|
8
8
|
/** Expose the single home/run-fenced mutation authority to domain packages. */
|
|
9
|
-
function apply(ctx, config = { keyedSkillLocks: false }) {
|
|
9
|
+
async function apply(ctx, config = { keyedSkillLocks: false }) {
|
|
10
|
+
await ctx.evolutionIo.whenReady();
|
|
10
11
|
const authority = new MutationAuthority({
|
|
11
12
|
io: ctx.evolutionIo.provider(),
|
|
12
13
|
home: evolutionHome(),
|
package/lib/composition/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as entryListSchema, c as GOVERNANCE_PRESET_ID, d as RESTRICTED_TOOLS_ROW_ID, f as RESTRICTOR_MODULE, h as restrictedPresetId, i as composeRestrictedPresetDefinition, l as MAINTAINER_PRESET_ID, m as normalizeAllow, n as ensureRestrictedPreset, o as parsePresetRows, p as REVIEWER_PRESET_ID, r as restrictedPresetState, s as EVOLUTION_PRESET_IDS, t as disposeRestrictedPreset, u as RESTRICTED_PRESET_DISPLAY } from "../ensure-
|
|
2
|
-
import { C as trimTrailingBlankLines, S as rowSiblingEnd, _ as presetRowId, a as composePresetComposition, b as resolveBasePresetPatch, c as composePresetRow, d as listDirectories, f as loadRowOverrides, g as presetRowBody, h as presetRowBlock, i as basePresetPlugins, l as compositionRowIds, m as presetPatchText, n as AGENT_PRESET_ROOT_HINT, o as composePresetEntry, p as mergePresetRow, r as EMPTY_PATCH_SEED, s as composePresetInsert, t as AGENT_PRESET_PACKAGE, u as denseBlockSequence, v as probeDesktopScope, x as rowBlockSpan, y as removePresetRow } from "../composition-
|
|
1
|
+
import { a as entryListSchema, c as GOVERNANCE_PRESET_ID, d as RESTRICTED_TOOLS_ROW_ID, f as RESTRICTOR_MODULE, h as restrictedPresetId, i as composeRestrictedPresetDefinition, l as MAINTAINER_PRESET_ID, m as normalizeAllow, n as ensureRestrictedPreset, o as parsePresetRows, p as REVIEWER_PRESET_ID, r as restrictedPresetState, s as EVOLUTION_PRESET_IDS, t as disposeRestrictedPreset, u as RESTRICTED_PRESET_DISPLAY } from "../ensure-DTCuxAxR.js";
|
|
2
|
+
import { C as trimTrailingBlankLines, S as rowSiblingEnd, _ as presetRowId, a as composePresetComposition, b as resolveBasePresetPatch, c as composePresetRow, d as listDirectories, f as loadRowOverrides, g as presetRowBody, h as presetRowBlock, i as basePresetPlugins, l as compositionRowIds, m as presetPatchText, n as AGENT_PRESET_ROOT_HINT, o as composePresetEntry, p as mergePresetRow, r as EMPTY_PATCH_SEED, s as composePresetInsert, t as AGENT_PRESET_PACKAGE, u as denseBlockSequence, v as probeDesktopScope, x as rowBlockSpan, y as removePresetRow } from "../composition-BSqh70z_.js";
|
|
3
3
|
export { AGENT_PRESET_PACKAGE, AGENT_PRESET_ROOT_HINT, EMPTY_PATCH_SEED, EVOLUTION_PRESET_IDS, GOVERNANCE_PRESET_ID, MAINTAINER_PRESET_ID, RESTRICTED_PRESET_DISPLAY, RESTRICTED_TOOLS_ROW_ID, RESTRICTOR_MODULE, REVIEWER_PRESET_ID, basePresetPlugins, composePresetComposition, composePresetEntry, composePresetInsert, composePresetRow, composeRestrictedPresetDefinition, compositionRowIds, denseBlockSequence, disposeRestrictedPreset, ensureRestrictedPreset, entryListSchema, listDirectories, loadRowOverrides, mergePresetRow, normalizeAllow, parsePresetRows, presetPatchText, presetRowBlock, presetRowBody, presetRowId, probeDesktopScope, removePresetRow, resolveBasePresetPatch, restrictedPresetId, restrictedPresetState, rowBlockSpan, rowSiblingEnd, trimTrailingBlankLines };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as scopedPackageName } from "./ensure-
|
|
1
|
+
import { _ as scopedPackageName } from "./ensure-DTCuxAxR.js";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
@@ -2,7 +2,7 @@ import { n as errorText } from "./errors-BxzLTVbS.js";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { presetsPort } from "@lmzhen/dsh-evolution-
|
|
5
|
+
import { presetsPort } from "@lmzhen/dsh-evolution-platform/ports";
|
|
6
6
|
import * as yaml from "js-yaml";
|
|
7
7
|
//#region lib/types/package-identity.js
|
|
8
8
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as planReferenceRewrite, L as planRehoming, M as externalRefs, N as supportRefs, O as selectSections, P as applyReferenceRewrite } from "./usage-
|
|
2
|
-
import { u as frontmatterBlock } from "./mutations-
|
|
1
|
+
import { I as planReferenceRewrite, L as planRehoming, M as externalRefs, N as supportRefs, O as selectSections, P as applyReferenceRewrite } from "./usage-BO4Zj_zB.js";
|
|
2
|
+
import { u as frontmatterBlock } from "./mutations-JKFlfhSO.js";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
//#region lib/types/extract-plan.js
|
|
5
5
|
const LF = String.fromCharCode(10);
|
package/lib/extract.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { p as isPresent } from "./io-
|
|
1
|
+
import { p as isPresent } from "./io-DT4-MXLr.js";
|
|
2
2
|
import { i as DEFAULT_SKILL_LIMITS } from "./limits-CO4JGSJL.js";
|
|
3
3
|
import { a as measureUnit } from "./text-metrics-CyJhxWBs.js";
|
|
4
|
-
import { p as parseFrontmatter, r as contentHash } from "./mutations-
|
|
5
|
-
import { C as EXTRACT_PROMPT_VERSION, S as EXTRACT_PROMPT_V1, T as ownerCandidatesFromSummaries, _ as readProposalReport, b as proposalFromPlan, d as nearDuplicateSummaries, m as readExternalSupport, v as readProposalReports, w as findOwnerCandidate, x as EXTRACT_PROMPT_HASH, y as writeProposalReport } from "./quality-
|
|
6
|
-
import { n as projectExtractBodies, t as planExtract } from "./extract-plan-
|
|
4
|
+
import { p as parseFrontmatter, r as contentHash } from "./mutations-JKFlfhSO.js";
|
|
5
|
+
import { C as EXTRACT_PROMPT_VERSION, S as EXTRACT_PROMPT_V1, T as ownerCandidatesFromSummaries, _ as readProposalReport, b as proposalFromPlan, d as nearDuplicateSummaries, m as readExternalSupport, v as readProposalReports, w as findOwnerCandidate, x as EXTRACT_PROMPT_HASH, y as writeProposalReport } from "./quality-C0ri2SgY.js";
|
|
6
|
+
import { n as projectExtractBodies, t as planExtract } from "./extract-plan-CP__XlEs.js";
|
|
7
7
|
import { dirname, join } from "node:path";
|
|
8
8
|
//#region lib/types/extract-request.js
|
|
9
9
|
/** The one human-readable owner decision shared by tool and CLI. */
|
package/lib/http-routes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecord } from "./guards-3f02mnf2.js";
|
|
2
|
-
import { connectionPort } from "@lmzhen/dsh-evolution-
|
|
2
|
+
import { connectionPort } from "@lmzhen/dsh-evolution-platform/ports";
|
|
3
3
|
//#region lib/types/http-routes.js
|
|
4
4
|
/**
|
|
5
5
|
* The Host data-plane contract + Fetch-shaped helpers every family route surface shares (W1/W6).
|
|
@@ -56,7 +56,8 @@ const HOST_ROUTES = {
|
|
|
56
56
|
run: "/api/dsh-evolution/merge/run",
|
|
57
57
|
runs: "/api/dsh-evolution/merge/runs",
|
|
58
58
|
body: "/api/dsh-evolution/merge/body",
|
|
59
|
-
history: "/api/dsh-evolution/merge/history"
|
|
59
|
+
history: "/api/dsh-evolution/merge/history",
|
|
60
|
+
decision: "/api/dsh-evolution/merge/decision"
|
|
60
61
|
},
|
|
61
62
|
diagnostics: { view: "/api/dsh-evolution/diagnostics" }
|
|
62
63
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
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-
|
|
2
|
-
import { a as DEFAULT_LEASE_TTL_MS, c as HomeFence, d as AuthorityOrderError, f as AuthorityReentryError, g as leaseAsTreeLock, h as authorityHolder, i as mutationLockFrom, l as HomeFenceError, m as TargetLockSet, n as MutationAuthority, o as LeaseStore, p as HomeAuthority, r as TargetMutationLock, s as leaseFile, t as HybridMutationLock, u as AuthorityBusyError } from "./mutation-authority-
|
|
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-DT4-MXLr.js";
|
|
2
|
+
import { a as DEFAULT_LEASE_TTL_MS, c as HomeFence, d as AuthorityOrderError, f as AuthorityReentryError, g as leaseAsTreeLock, h as authorityHolder, i as mutationLockFrom, l as HomeFenceError, m as TargetLockSet, n as MutationAuthority, o as LeaseStore, p as HomeAuthority, r as TargetMutationLock, s as leaseFile, t as HybridMutationLock, u as AuthorityBusyError } from "./mutation-authority-C3RYyiaT.js";
|
|
3
3
|
import { a as isFileShapedPath, i as KEEP_LINE_RE, n as DEFAULT_CITATION_REF_BUDGET, o as resolveCitations, r as HOOK_LINE_RE, s as scanBodyHooks, t as CITATION_SUPPORT_DIRS } from "./citations-CZKTUGQF.js";
|
|
4
4
|
import { $ as SUPPORT_SPRAWL_FILES, A as DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS, B as MAX_SKILL_CONTENT_CHARS, C as DEFAULT_REVIEW_TIMEOUT_MS, D as DEFAULT_SKILL_VERSION_KEEP, E as DEFAULT_SKILL_REVIEW_TRIGGER, F as DEFAULT_USER_TOKENS, G as MEMORY_GUIDANCE_SECTION_ORDER, H as MAX_SKILL_NAME_LENGTH, I as ENTRY_DELIMITER, J as REVIEW_TEXT_PREVIEW_GRAPHEMES, K as MERGE_BODY_PREVIEW_BYTES, L as EVOLUTION_WRITE_TOOLS, M as DEFAULT_SUBSTANTIVE_MIN_USER_CHARS, N as DEFAULT_THREAT_MAX_SCAN_CHARS, O as DEFAULT_SOFT_BODY_TOKENS, P as DEFAULT_USER_CHAR_LIMIT, Q as SUPPORT_DIRS, R as FORBIDDEN_CONTROL_KEYS, S as DEFAULT_REVIEW_SKILL_INTERVAL, T as DEFAULT_SKILL_REVIEW_COMPLETION_MIN_TOOL_CALLS, U as MAX_TIMER_DELAY_MS, V as MAX_SKILL_FILE_BYTES, W as MEMORY_ENTRY_PREVIEW_GRAPHEMES, X as SKILL_ACTION_REQUIRED_FIELDS, Y as SKILLS_GUIDANCE_SECTION_ORDER, Z as SKILL_NAME_RE, _ as DEFAULT_MEMORY_CHAR_LIMIT, a as DEFAULT_SUPPORT_FILE_CHAR_POLICY, b as DEFAULT_PROBE_TIMEOUT_MS, c as AUTHORING_DESCRIPTION_BAR, d as DEFAULT_ARCHIVE_AFTER_DAYS, et as TEXT_DIFF_MAX_GRAPHEMES, f as DEFAULT_CONSOLIDATION_FAILURES, g as DEFAULT_CURATOR_REVIEW_MAX_TOKENS, h as DEFAULT_CURATOR_MODEL, i as DEFAULT_SKILL_LIMITS, j as DEFAULT_SUBSTANTIVE_MIN_TOOL_CALLS, k as DEFAULT_STALE_AFTER_DAYS, l as AUTHORING_SPLIT_LINE_CHARS, m as DEFAULT_CURATOR_INTERVAL_HOURS, n as DEFAULT_CITATION_POLICY, nt as VERSION_BODY_PREVIEW_GRAPHEMES, o as POLICY_STAGE_DEFAULTS, p as DEFAULT_CURATOR_BOOT_GRACE_SECONDS, q as PROTECTED_BUILTIN_SKILLS, r as DEFAULT_REFERENCE_REWRITE_POLICY, s as policyStageLimits, t as DEFAULT_ARCHIVE_RETENTION_POLICY, tt as UPSTREAM_LIMIT_CHARS_PER_TOKEN, u as CONTENT_SPLIT_HINT, v as DEFAULT_MEMORY_TOKENS, w as DEFAULT_SKILL_CONTENT_CHARS, x as DEFAULT_REVIEW_MEMORY_INTERVAL, y as DEFAULT_MIN_IDLE_HOURS, z as MAX_DESCRIPTION_LENGTH } from "./limits-CO4JGSJL.js";
|
|
5
|
-
import { _ as scopedPackageName, d as RESTRICTED_TOOLS_ROW_ID, f as RESTRICTOR_MODULE, g as scopeOfNearestManifest, l as MAINTAINER_PRESET_ID, p as REVIEWER_PRESET_ID, s as EVOLUTION_PRESET_IDS, u as RESTRICTED_PRESET_DISPLAY } from "./ensure-
|
|
6
|
-
import { A as retainEventArchives, C as appendEvolutionEvent, D as parseEvolutionEvents, E as listEventArchives, G as DEFAULT_WRITE_CONFIRM_MODE, H as isUnreadWrite, I as softBodyTokenBudget, K as DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS, L as RULES, O as readEvolutionEvents, P as assessStructureHealth, S as EVENT_LOG_VERSION, T as evolutionEventPayloadIssue, _ as fuzzyPatch, a as isReviewChannelSession, b as EVENT_LOG_RETAIN_ARCHIVES, c as PATTERN_OVERLAP, d as scanContentThreats, f as scanMemoryThreats, g as FUZZY_MAX_WORK, h as FUZZY_MAX_PATTERN_CHARS, i as clearReviewChannel, j as DEFAULT_HEALTH_THRESHOLDS, k as readEvolutionTimeline, l as THREAT_EXEMPTION_HINT, m as makeSerialQueue, n as recordReviewRead, o as markReviewChannel, p as scanThreats, q as authorityFrom, r as withReviewContext, s as sweepReviewChannelSessions, t as currentReviewContext, u as evaluateThreat, v as trimPatternBoundaries, w as eventsFile, x as EVENT_LOG_ROTATE_AT, y as EVENT_ARCHIVE_PREFIX, z as lintSkill } from "./review-context-
|
|
5
|
+
import { _ as scopedPackageName, d as RESTRICTED_TOOLS_ROW_ID, f as RESTRICTOR_MODULE, g as scopeOfNearestManifest, l as MAINTAINER_PRESET_ID, p as REVIEWER_PRESET_ID, s as EVOLUTION_PRESET_IDS, u as RESTRICTED_PRESET_DISPLAY } from "./ensure-DTCuxAxR.js";
|
|
6
|
+
import { A as retainEventArchives, C as appendEvolutionEvent, D as parseEvolutionEvents, E as listEventArchives, G as DEFAULT_WRITE_CONFIRM_MODE, H as isUnreadWrite, I as softBodyTokenBudget, K as DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS, L as RULES, O as readEvolutionEvents, P as assessStructureHealth, S as EVENT_LOG_VERSION, T as evolutionEventPayloadIssue, _ as fuzzyPatch, a as isReviewChannelSession, b as EVENT_LOG_RETAIN_ARCHIVES, c as PATTERN_OVERLAP, d as scanContentThreats, f as scanMemoryThreats, g as FUZZY_MAX_WORK, h as FUZZY_MAX_PATTERN_CHARS, i as clearReviewChannel, j as DEFAULT_HEALTH_THRESHOLDS, k as readEvolutionTimeline, l as THREAT_EXEMPTION_HINT, m as makeSerialQueue, n as recordReviewRead, o as markReviewChannel, p as scanThreats, q as authorityFrom, r as withReviewContext, s as sweepReviewChannelSessions, t as currentReviewContext, u as evaluateThreat, v as trimPatternBoundaries, w as eventsFile, x as EVENT_LOG_ROTATE_AT, y as EVENT_ARCHIVE_PREFIX, z as lintSkill } from "./review-context-D2LIOEi-.js";
|
|
7
7
|
import { i as HOST_LOCALES, n as errorText, r as errorTextIn, t as EVOLUTION_ERRORS } from "./errors-BxzLTVbS.js";
|
|
8
|
-
import { A as dispatchKeyOf, C as PTC_DISPATCH_EVENT, D as assertDispatchPayload, E as ToolDispatchPayloadError, F as isSkillToolName, I as readDispatchSignal, 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, _ 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-
|
|
8
|
+
import { A as dispatchKeyOf, C as PTC_DISPATCH_EVENT, D as assertDispatchPayload, E as ToolDispatchPayloadError, F as isSkillToolName, I as readDispatchSignal, 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, _ 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-Dnmm5bzt.js";
|
|
9
9
|
import { a as measureUnit, i as measureText, n as conservativeTokenEstimator, o as truncateGraphemes, r as graphemeCount, s as utf8ByteLength, t as codePointCount } from "./text-metrics-CyJhxWBs.js";
|
|
10
|
-
import { A as h2Sections, C as saveUsage, D as usageObserved, E as usageFile, F as describeReferenceRewrite, I as planReferenceRewrite, L as planRehoming, M as externalRefs, N as supportRefs, O as selectSections, P as applyReferenceRewrite, S as saveSuppressedNames, T as updateSuppressedNames, _ as loadUsage, a as applyCuratorMetaFields, b as normalizeUsageRecord, c as bumpUse, d as emptyRecord, f as foldCuratorFields, g as loadSuppressedNames, h as latestActivityAt, i as applyCuratorLifecycleFields, j as readingStats, k as displayBodyOf, l as bumpView, m as idleDays, n as SUPPRESSED_FILE_VERSION, o as bumpPatch, p as getRecord, r as VIEW_WINDOW_DAYS, s as bumpSupportRead, t as MAX_SUPPORT_READ_PATHS, u as daysSinceIso, v as markAgentCreated, w as suppressedFile, x as recentViewCount, y as mutateUsage } from "./usage-
|
|
10
|
+
import { A as h2Sections, C as saveUsage, D as usageObserved, E as usageFile, F as describeReferenceRewrite, I as planReferenceRewrite, L as planRehoming, M as externalRefs, N as supportRefs, O as selectSections, P as applyReferenceRewrite, S as saveSuppressedNames, T as updateSuppressedNames, _ as loadUsage, a as applyCuratorMetaFields, b as normalizeUsageRecord, c as bumpUse, d as emptyRecord, f as foldCuratorFields, g as loadSuppressedNames, h as latestActivityAt, i as applyCuratorLifecycleFields, j as readingStats, k as displayBodyOf, l as bumpView, m as idleDays, n as SUPPRESSED_FILE_VERSION, o as bumpPatch, p as getRecord, r as VIEW_WINDOW_DAYS, s as bumpSupportRead, t as MAX_SUPPORT_READ_PATHS, u as daysSinceIso, v as markAgentCreated, w as suppressedFile, x as recentViewCount, y as mutateUsage } from "./usage-BO4Zj_zB.js";
|
|
11
11
|
import { n as isRecord, t as asRecord } from "./guards-3f02mnf2.js";
|
|
12
|
-
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-
|
|
13
|
-
import { T as ownerCandidatesFromSummaries, _ as readProposalReport, a as SUMMARY_DUPLICATE_HINT_THRESHOLD, b as proposalFromPlan, c as computePrefixClusters, d as nearDuplicateSummaries, f as projectionText, g as proposalReportName, h as proposalReportDir, i as QUALITY_WEIGHTS, l as computeQualityScores, m as readExternalSupport, n as DEDUP_SIMILARITY_THRESHOLD, o as affinity, p as vocabulary, r as LOW_QUALITY_THRESHOLD, s as computeDedupGroups, t as DEDUP_MAX_PAIR_COMPARISONS, u as identity, v as readProposalReports, w as findOwnerCandidate, y as writeProposalReport } from "./quality-
|
|
12
|
+
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-JKFlfhSO.js";
|
|
13
|
+
import { T as ownerCandidatesFromSummaries, _ as readProposalReport, a as SUMMARY_DUPLICATE_HINT_THRESHOLD, b as proposalFromPlan, c as computePrefixClusters, d as nearDuplicateSummaries, f as projectionText, g as proposalReportName, h as proposalReportDir, i as QUALITY_WEIGHTS, l as computeQualityScores, m as readExternalSupport, n as DEDUP_SIMILARITY_THRESHOLD, o as affinity, p as vocabulary, r as LOW_QUALITY_THRESHOLD, s as computeDedupGroups, t as DEDUP_MAX_PAIR_COMPARISONS, u as identity, v as readProposalReports, w as findOwnerCandidate, y as writeProposalReport } from "./quality-C0ri2SgY.js";
|
|
14
14
|
import { n as evolutionRoot, t as evolutionHome } from "./state-store-Jpa-iYIZ.js";
|
|
15
|
-
import "./skill-history-
|
|
15
|
+
import "./skill-history-BOZ4HCDB.js";
|
|
16
16
|
import { HOST_ROUTES, MAX_REQUEST_BODY_BYTES, hostSurface, json, methodNotAllowed, readJsonObject, registerHostRoutes } from "./http-routes.js";
|
|
17
|
-
import { w as allowRowCollisions } from "./composition-
|
|
17
|
+
import { w as allowRowCollisions } from "./composition-BSqh70z_.js";
|
|
18
18
|
import { t as clampedNumber } from "./numeric-Dc53KQoe.js";
|
|
19
19
|
import { abortLink, createSubagentChannel as createSubagentKernel, createSubagentRun, probeChannelState, textOfValue, waitForSubagentEnd } from "./subagent/index.js";
|
|
20
20
|
import { createHash, randomUUID } from "node:crypto";
|
|
21
21
|
import { basename, join } from "node:path";
|
|
22
|
-
import { scopeOf } from "@lmzhen/dsh-evolution-adapter/values";
|
|
23
22
|
import { readFileSync } from "node:fs";
|
|
24
23
|
import { fileURLToPath } from "node:url";
|
|
25
24
|
import { parse } from "yaml";
|
|
26
|
-
import { settingsPort, toolsPort } from "@lmzhen/dsh-evolution-
|
|
25
|
+
import { settingsPort, toolsPort } from "@lmzhen/dsh-evolution-platform/ports";
|
|
26
|
+
import { scopeOf } from "@lmzhen/dsh-evolution-platform/values/scope";
|
|
27
27
|
//#region lib/types/tree-write.js
|
|
28
28
|
/**
|
|
29
29
|
* G1/1.5 (S7-09): the TYPED critical section around a tree write.
|
|
@@ -3436,7 +3436,7 @@ const STORE_LEDGER = [
|
|
|
3436
3436
|
artifact: "resolved record count",
|
|
3437
3437
|
declare: [{
|
|
3438
3438
|
kind: "named",
|
|
3439
|
-
module: "evolution-
|
|
3439
|
+
module: "evolution-core/src/state/constants.ts",
|
|
3440
3440
|
name: "PENDING_RESOLVED_CAP",
|
|
3441
3441
|
value: 200
|
|
3442
3442
|
}]
|
|
@@ -3451,7 +3451,7 @@ const STORE_LEDGER = [
|
|
|
3451
3451
|
artifact: "review state row count",
|
|
3452
3452
|
declare: [{
|
|
3453
3453
|
kind: "named",
|
|
3454
|
-
module: "evolution-
|
|
3454
|
+
module: "evolution-core/src/state/constants.ts",
|
|
3455
3455
|
name: "REVIEW_STATE_SESSION_CAP",
|
|
3456
3456
|
value: 500
|
|
3457
3457
|
}]
|
|
@@ -4710,7 +4710,7 @@ const PARAM_EXPOSURE = Object.freeze([
|
|
|
4710
4710
|
group: "deployment",
|
|
4711
4711
|
tier: "E2",
|
|
4712
4712
|
authority: "cordis",
|
|
4713
|
-
owner: "evolution-
|
|
4713
|
+
owner: "evolution-core",
|
|
4714
4714
|
applies: "none",
|
|
4715
4715
|
docAnchor: "PARAMETERS.md#deployment",
|
|
4716
4716
|
summary: "Registered state-store provider name.",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { cp, lstat, mkdir, open, readFile, readdir, rename, rm, stat } from "node:fs/promises";
|
|
2
|
+
import { cp, link, lstat, mkdir, open, readFile, readdir, rename, rm, stat } from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, join } from "node:path";
|
|
4
4
|
import { copyFileSync, existsSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
//#region lib/types/probe.js
|
|
@@ -180,6 +180,10 @@ function evolutionIoAdapter(provider) {
|
|
|
180
180
|
},
|
|
181
181
|
readText: (path) => provider().readText(path),
|
|
182
182
|
writeText: (path, content) => provider().writeText(path, content),
|
|
183
|
+
get createTextIfAbsent() {
|
|
184
|
+
const fn = provider().createTextIfAbsent;
|
|
185
|
+
return fn === void 0 ? void 0 : (path, content) => fn(path, content);
|
|
186
|
+
},
|
|
183
187
|
remove: (path) => provider().remove(path),
|
|
184
188
|
list: (path) => provider().list(path),
|
|
185
189
|
exists: (path) => provider().exists(path),
|
|
@@ -440,6 +444,26 @@ function nodeEvolutionIo() {
|
|
|
440
444
|
throw error;
|
|
441
445
|
}
|
|
442
446
|
},
|
|
447
|
+
async createTextIfAbsent(path, content) {
|
|
448
|
+
await mkdir(dirname(path), { recursive: true });
|
|
449
|
+
await sweepStaleTmps(path);
|
|
450
|
+
const tmp = await writeDurableTmp(path, content);
|
|
451
|
+
try {
|
|
452
|
+
await link(tmp, path);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
await rm(tmp, { force: true }).catch(() => {});
|
|
455
|
+
throw error;
|
|
456
|
+
}
|
|
457
|
+
await rm(tmp, { force: true }).catch(() => {});
|
|
458
|
+
try {
|
|
459
|
+
await fsyncDirectory(dirname(path));
|
|
460
|
+
} catch (error) {
|
|
461
|
+
throw Object.assign(/* @__PURE__ */ new Error(`createTextIfAbsent: ${path} was linked but the directory fsync failed: ${error instanceof Error ? error.message : String(error)}`), {
|
|
462
|
+
committed: true,
|
|
463
|
+
cause: error
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
},
|
|
443
467
|
async writeText(path, content) {
|
|
444
468
|
await mkdir(dirname(path), { recursive: true });
|
|
445
469
|
await inProcessWrite(path, async () => {
|
package/lib/io-node.js
CHANGED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { withFileLock } from "@lmzhen/dsh-evolution-platform/values/fs";
|
|
2
|
+
//#region lib/types/io-platform.js
|
|
3
|
+
/**
|
|
4
|
+
* Platform-backed `EvolutionIo` provider.
|
|
5
|
+
*
|
|
6
|
+
* This is the Phase-B bridge: business code keeps its existing `EvolutionIoLike`
|
|
7
|
+
* seam, while the production backend becomes the platform filesystem
|
|
8
|
+
* (`ctx.fs`, implemented by `@deepseek-ai/dsh-fs-local`) instead of the family's
|
|
9
|
+
* own `node:fs` writer. Target identity, per-target locks and atomic publication
|
|
10
|
+
* therefore have one owner: the platform.
|
|
11
|
+
*
|
|
12
|
+
* Structural `PlatformFs` is deliberate: this package consumes the platform
|
|
13
|
+
* service shape without adding a runtime dependency; every operation is a
|
|
14
|
+
* one-to-one mapping, and no plugin-local write primitive is introduced.
|
|
15
|
+
*
|
|
16
|
+
* @module @lmzhen/dsh-evolution-core/io-platform
|
|
17
|
+
*/
|
|
18
|
+
const MISSING_CODES = new Set([
|
|
19
|
+
"FS_NOT_FOUND",
|
|
20
|
+
"FS_NOT_DIRECTORY",
|
|
21
|
+
"ENOENT",
|
|
22
|
+
"ENOTDIR"
|
|
23
|
+
]);
|
|
24
|
+
function codeOf(error) {
|
|
25
|
+
return typeof error?.code === "string" ? String(error.code) : "";
|
|
26
|
+
}
|
|
27
|
+
function isMissing(error) {
|
|
28
|
+
return MISSING_CODES.has(codeOf(error));
|
|
29
|
+
}
|
|
30
|
+
function eexist(message) {
|
|
31
|
+
return Object.assign(new Error(message), { code: "EEXIST" });
|
|
32
|
+
}
|
|
33
|
+
async function readOrNull(fs, path) {
|
|
34
|
+
const target = await fs.resolve(path);
|
|
35
|
+
try {
|
|
36
|
+
return await fs.readText(target);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (isMissing(error)) return null;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Adapt one platform filesystem service to the family's existing IO seam.
|
|
44
|
+
* @param fs - the platform filesystem service (structurally `ctx.fs`).
|
|
45
|
+
* @returns the provider, ready for `ctx.evolutionIo.registerProvider`.
|
|
46
|
+
*/
|
|
47
|
+
function platformEvolutionIo(fs, options = {}) {
|
|
48
|
+
const lock = options.withFileLock;
|
|
49
|
+
return {
|
|
50
|
+
name: "platform",
|
|
51
|
+
processScope: lock === void 0 ? "single-process" : "cross-process",
|
|
52
|
+
async readText(path) {
|
|
53
|
+
return await readOrNull(fs, path);
|
|
54
|
+
},
|
|
55
|
+
async writeText(path, content) {
|
|
56
|
+
const target = await fs.resolve(path);
|
|
57
|
+
await fs.writeText(target, content);
|
|
58
|
+
},
|
|
59
|
+
async remove(path) {
|
|
60
|
+
const target = await fs.resolve(path);
|
|
61
|
+
try {
|
|
62
|
+
await fs.deleteFile(target);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (!isMissing(error)) throw error;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
async list(path) {
|
|
68
|
+
const target = await fs.resolve(path);
|
|
69
|
+
try {
|
|
70
|
+
return (await fs.listDir(target)).map((entry) => entry.name);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (isMissing(error)) return [];
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
async exists(path) {
|
|
77
|
+
const target = await fs.resolve(path);
|
|
78
|
+
try {
|
|
79
|
+
return await fs.stat(target) !== void 0;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (isMissing(error)) return false;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
async rename(path, destination) {
|
|
86
|
+
const source = await fs.resolve(path);
|
|
87
|
+
const target = await fs.resolve(destination);
|
|
88
|
+
if ((await fs.moveFile(source, target, {})).sourceDeleted !== true) throw new Error("platform move retained the source: " + path);
|
|
89
|
+
},
|
|
90
|
+
async copy(path, destination) {
|
|
91
|
+
const content = await readOrNull(fs, path);
|
|
92
|
+
if (content === null) throw new Error("cannot copy missing file: " + path);
|
|
93
|
+
const target = await fs.resolve(destination);
|
|
94
|
+
await fs.writeText(target, content);
|
|
95
|
+
},
|
|
96
|
+
async size(path) {
|
|
97
|
+
const target = await fs.resolve(path);
|
|
98
|
+
const info = await fs.stat(target);
|
|
99
|
+
return info === void 0 || info.type !== "file" ? null : info.size ?? null;
|
|
100
|
+
},
|
|
101
|
+
async isSymlink(path) {
|
|
102
|
+
const info = await fs.lstat(path);
|
|
103
|
+
return info === void 0 ? null : info.type === "symlink";
|
|
104
|
+
},
|
|
105
|
+
async createTextIfAbsent(path, content) {
|
|
106
|
+
const target = await fs.resolve(path);
|
|
107
|
+
try {
|
|
108
|
+
await fs.writeText(target, content, { kind: "createIfAbsent" });
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (codeOf(error) === "FS_ALREADY_EXISTS" || codeOf(error) === "FS_STALE_VERSION" || codeOf(error) === "FS_NOT_OBSERVED") throw eexist("target appeared before create: " + path);
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
async transact(path, task) {
|
|
115
|
+
const run = async () => {
|
|
116
|
+
const target = await fs.resolve(path);
|
|
117
|
+
const info = await fs.stat(target);
|
|
118
|
+
const current = info === void 0 ? null : await fs.readText(target);
|
|
119
|
+
const next = await task(current);
|
|
120
|
+
if (next === current) return;
|
|
121
|
+
if (next === null) {
|
|
122
|
+
if (info === void 0) return;
|
|
123
|
+
await fs.deleteFile(target, { version: info.version });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (info === void 0) {
|
|
127
|
+
try {
|
|
128
|
+
await fs.writeText(target, next, { kind: "createIfAbsent" });
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (codeOf(error) === "FS_ALREADY_EXISTS" || codeOf(error) === "FS_STALE_VERSION" || codeOf(error) === "FS_NOT_OBSERVED") throw eexist("target appeared before write: " + path);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (current === null) throw new Error("platform file vanished during transact: " + path);
|
|
136
|
+
if (current === "") await fs.writeText(target, next, {
|
|
137
|
+
kind: "replaceIfVersion",
|
|
138
|
+
version: info.version
|
|
139
|
+
});
|
|
140
|
+
else await fs.editText(target, {
|
|
141
|
+
oldString: current,
|
|
142
|
+
newString: next,
|
|
143
|
+
replaceAll: false
|
|
144
|
+
}, { version: info.version });
|
|
145
|
+
};
|
|
146
|
+
if (lock === void 0) await run();
|
|
147
|
+
else await lock(path, run);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const name = "evolution-io-platform";
|
|
152
|
+
const inject = ["evolutionIo", "fs"];
|
|
153
|
+
/**
|
|
154
|
+
* Register the platform provider as the default IO backend.
|
|
155
|
+
* @param ctx - plugin context carrying `evolutionIo` and `fs`.
|
|
156
|
+
*/
|
|
157
|
+
function apply(ctx) {
|
|
158
|
+
const fs = ctx.fs;
|
|
159
|
+
if (fs === void 0) throw new Error("evolution-io-platform requires the platform fs service");
|
|
160
|
+
ctx.effect(() => ctx.evolutionIo.registerProvider(platformEvolutionIo(fs, { withFileLock }), { default: true }), "evolution-io-platform.provider");
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
export { apply, inject, name, platformEvolutionIo };
|
package/lib/io-registry.js
CHANGED
|
@@ -11,6 +11,7 @@ var EvolutionIoRegistry = class extends Service {
|
|
|
11
11
|
/** P2-3 (v15): per-name dispose — the idempotent re-registration returns
|
|
12
12
|
* the SAME function instance, so double-dispose is a single removal. */
|
|
13
13
|
disposals = /* @__PURE__ */ new Map();
|
|
14
|
+
readyResolvers = [];
|
|
14
15
|
constructor(ctx) {
|
|
15
16
|
super(ctx, "evolutionIo");
|
|
16
17
|
}
|
|
@@ -45,8 +46,17 @@ var EvolutionIoRegistry = class extends Service {
|
|
|
45
46
|
};
|
|
46
47
|
this.providers.set(provider.name, provider);
|
|
47
48
|
this.disposals.set(provider.name, dispose);
|
|
49
|
+
for (const resolve of this.readyResolvers.splice(0)) resolve();
|
|
48
50
|
return dispose;
|
|
49
51
|
}
|
|
52
|
+
/** Resolve once at least one provider exists; plugins that construct with a
|
|
53
|
+
* provider in apply() await this instead of racing the registration row. */
|
|
54
|
+
whenReady() {
|
|
55
|
+
if (this.providers.size > 0) return Promise.resolve();
|
|
56
|
+
return new Promise((resolve) => {
|
|
57
|
+
this.readyResolvers.push(resolve);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
50
60
|
provider(name) {
|
|
51
61
|
if (name) {
|
|
52
62
|
const provider = this.providers.get(name);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as isProcessAlive, c as transactIo } from "./io-
|
|
1
|
+
import { a as isProcessAlive, c as transactIo } from "./io-DT4-MXLr.js";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
-
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
4
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
-
import { withFileLock } from "@lmzhen/dsh-evolution-
|
|
6
|
+
import { withFileLock } from "@lmzhen/dsh-evolution-platform/values/fs";
|
|
7
7
|
//#region lib/types/authority.js
|
|
8
8
|
/**
|
|
9
9
|
* The family's one mutual-exclusion entry (W9-authority, invariant I1).
|
|
@@ -206,35 +206,16 @@ var TargetLockSet = class {
|
|
|
206
206
|
const skipped = [];
|
|
207
207
|
for (const key of [...this.brokenKeys]) {
|
|
208
208
|
const path = this.lockPath(key) + ".lock";
|
|
209
|
-
let
|
|
209
|
+
let removed = false;
|
|
210
210
|
try {
|
|
211
|
-
|
|
212
|
-
} catch (error) {
|
|
213
|
-
if (error.code === "ENOENT") {
|
|
214
|
-
this.brokenKeys.delete(key);
|
|
215
|
-
repaired.push(key);
|
|
216
|
-
} else skipped.push(key);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
const pid = Number.parseInt(raw.trim(), 10);
|
|
220
|
-
if (Number.isInteger(pid) && pid > 0 && pid !== process.pid && isProcessAlive(pid)) {
|
|
221
|
-
skipped.push(key);
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
try {
|
|
225
|
-
await rm(path, { force: true });
|
|
226
|
-
try {
|
|
227
|
-
await readFile(path, "utf8");
|
|
228
|
-
skipped.push(key);
|
|
229
|
-
} catch (error) {
|
|
230
|
-
if (error.code === "ENOENT") {
|
|
231
|
-
this.brokenKeys.delete(key);
|
|
232
|
-
repaired.push(key);
|
|
233
|
-
} else skipped.push(key);
|
|
234
|
-
}
|
|
211
|
+
removed = await removeExitedLock(path);
|
|
235
212
|
} catch {
|
|
236
|
-
|
|
213
|
+
removed = false;
|
|
237
214
|
}
|
|
215
|
+
if (removed) {
|
|
216
|
+
this.brokenKeys.delete(key);
|
|
217
|
+
repaired.push(key);
|
|
218
|
+
} else skipped.push(key);
|
|
238
219
|
}
|
|
239
220
|
return {
|
|
240
221
|
repaired,
|
|
@@ -251,6 +232,61 @@ var TargetLockSet = class {
|
|
|
251
232
|
return await this.lock(path, body, { waitMs: this.waitMs });
|
|
252
233
|
}
|
|
253
234
|
};
|
|
235
|
+
/**
|
|
236
|
+
* Remove a lock file only through the platform's takeover claim protocol: write a claim named
|
|
237
|
+
* after the exact recorded holder, re-read under it, then remove only if the record and its dead
|
|
238
|
+
* PID are unchanged. A repair that rm()s directly can delete a lock another contender acquired
|
|
239
|
+
* after the dead holder's.
|
|
240
|
+
* @param lockPath - the lock file to remove.
|
|
241
|
+
* @returns true when this call removed it (or it was already absent).
|
|
242
|
+
*/
|
|
243
|
+
async function removeExitedLock(lockPath) {
|
|
244
|
+
let record;
|
|
245
|
+
try {
|
|
246
|
+
record = await readFile(lockPath, "utf8");
|
|
247
|
+
} catch (error) {
|
|
248
|
+
if (error.code === "ENOENT") return true;
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
const pid = Number.parseInt(record.trim(), 10);
|
|
252
|
+
if (Number.isInteger(pid) && pid > 0 && pid !== process.pid && isProcessAlive(pid)) return false;
|
|
253
|
+
const claim = lockPath + ".takeover-" + createHash("sha256").update(record).digest("hex").slice(0, 16);
|
|
254
|
+
try {
|
|
255
|
+
await writeFile(claim, String(process.pid) + "\n", {
|
|
256
|
+
mode: 384,
|
|
257
|
+
flag: "wx"
|
|
258
|
+
});
|
|
259
|
+
} catch (error) {
|
|
260
|
+
const code = error.code;
|
|
261
|
+
if (code === "EEXIST" || code === "EPERM") return false;
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
let again;
|
|
266
|
+
try {
|
|
267
|
+
again = await readFile(lockPath, "utf8");
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (error.code === "ENOENT") return true;
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
if (again !== record) return false;
|
|
273
|
+
const againPid = Number.parseInt(again.trim(), 10);
|
|
274
|
+
if (Number.isInteger(againPid) && againPid > 0 && againPid !== process.pid && isProcessAlive(againPid)) return false;
|
|
275
|
+
try {
|
|
276
|
+
await rm(lockPath, { force: true });
|
|
277
|
+
} catch {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
await readFile(lockPath, "utf8");
|
|
282
|
+
return false;
|
|
283
|
+
} catch (error) {
|
|
284
|
+
return error.code === "ENOENT";
|
|
285
|
+
}
|
|
286
|
+
} finally {
|
|
287
|
+
await rm(claim, { force: true }).catch(() => {});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
254
290
|
var HomeAuthority = class {
|
|
255
291
|
options;
|
|
256
292
|
held = /* @__PURE__ */ new Map();
|
|
@@ -395,18 +431,7 @@ var HomeAuthority = class {
|
|
|
395
431
|
*/
|
|
396
432
|
async repair() {
|
|
397
433
|
if (this.pending === void 0 || this.held.size > 0) return "noop";
|
|
398
|
-
|
|
399
|
-
let holder;
|
|
400
|
-
try {
|
|
401
|
-
const raw = await readFile(lockPath, "utf8");
|
|
402
|
-
const pid = Number.parseInt(raw.trim(), 10);
|
|
403
|
-
holder = Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
404
|
-
} catch (error) {
|
|
405
|
-
if (error.code !== "ENOENT") throw error;
|
|
406
|
-
holder = void 0;
|
|
407
|
-
}
|
|
408
|
-
if (holder !== void 0 && holder !== process.pid && isProcessAlive(holder)) return "noop";
|
|
409
|
-
await rm(lockPath, { force: true });
|
|
434
|
+
if (!await removeExitedLock(this.lockBase + ".lock")) return "noop";
|
|
410
435
|
this.pending = void 0;
|
|
411
436
|
return "repaired";
|
|
412
437
|
}
|