@lmzhen/dsh-evolution-core 0.43.2-rc.1 → 0.45.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 +14 -0
- package/lib/composition/index.js +2 -2
- package/lib/{composition-CVafrlEw.js → composition-Da8NfRI7.js} +2 -2
- package/lib/contract.js +1 -0
- package/lib/index.js +59 -133
- package/lib/{mutations-jUuOPaCn.js → io-AmUf4lVY.js} +54 -84
- package/lib/io-node.js +24 -0
- package/lib/io-registry.js +96 -0
- package/lib/mutation-authority-DeJ_Wz14.js +537 -0
- package/lib/mutations-DwvbjRHF.js +75 -0
- package/lib/numeric-DLeLvvGb.js +324 -0
- package/lib/platform/index.js +1 -1
- package/lib/{platform-B06_h8t-.js → platform-CFA12Jam.js} +36 -19
- package/lib/policy.js +99 -0
- package/lib/runtime/plugin.js +8 -1
- package/lib/{skill-health-BLGZTIv8.js → skill-health-D1pZGk5V.js} +6 -835
- package/lib/{skill-history-_Cssts5o.js → skill-history-CjypdYqv.js} +2 -1
- package/lib/skills.js +6 -3
- package/lib/subagent/index.js +1 -1
- package/lib/types/authority-plugin.d.ts +12 -0
- package/lib/types/authority-plugin.js +10 -0
- package/lib/types/authority.d.ts +96 -0
- package/lib/types/authority.js +237 -0
- package/lib/types/contract.d.ts +116 -0
- package/lib/types/contract.js +10 -0
- package/lib/types/events.d.ts +2 -2
- package/lib/types/home-fence.d.ts +25 -17
- package/lib/types/home-fence.js +42 -92
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.js +2 -2
- package/lib/types/io-node.d.ts +15 -0
- package/lib/types/io-node.js +36 -0
- package/lib/types/io-registry.d.ts +71 -0
- package/lib/types/io-registry.js +126 -0
- package/lib/types/io.d.ts +29 -2
- package/lib/types/io.js +50 -9
- package/lib/types/journal-protocol.d.ts +35 -0
- package/lib/types/journal-protocol.js +29 -0
- package/lib/types/lease-store.d.ts +1 -1
- package/lib/types/mutation-unit.d.ts +1 -1
- package/lib/types/params.d.ts +2 -16
- package/lib/types/params.js +6 -44
- package/lib/types/platform/llm.js +4 -1
- package/lib/types/platform/projections.d.ts +10 -4
- package/lib/types/platform/projections.js +34 -17
- package/lib/types/platform-services.d.ts +2 -2
- package/lib/types/platform-services.js +1 -0
- package/lib/types/policy.d.ts +68 -0
- package/lib/types/policy.js +161 -0
- package/lib/types/run-registry.d.ts +2 -2
- package/lib/types/runtime/projections.js +12 -0
- package/lib/types/state-store.d.ts +1 -1
- package/lib/types/state-store.js +1 -1
- package/lib/types/store-ledger.js +2 -2
- package/lib/types/write-inventory.js +3 -1
- package/lib/write.js +2 -2
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/runtime/de.json +6 -0
- package/locale/runtime/en.json +6 -0
- package/locale/runtime/es.json +6 -0
- package/locale/runtime/fr.json +6 -0
- package/locale/runtime/ja.json +6 -0
- package/locale/runtime/pt.json +6 -0
- package/locale/runtime/ru.json +6 -0
- package/locale/runtime/zh.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +29 -4
- package/persisted-write-inventory.json +10 -37
- package/lib/types/home-owner.d.ts +0 -4
- package/lib/types/home-owner.js +0 -37
- package/lib/types/tree-lock.d.ts +0 -54
- package/lib/types/tree-lock.js +0 -127
- package/lib/{ensure-BjToTMMj.js → ensure-C5Mo1dbB.js} +1 -1
package/lib/types/home-fence.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Lease adapter over the one HomeAuthority (W9-authority).
|
|
3
|
+
*
|
|
4
|
+
* The fence owns no lock protocol of its own any more: cross-process exclusion is the platform
|
|
5
|
+
* writer lock inside {@link HomeAuthority}, and this class only keeps the family's historical
|
|
6
|
+
* `run`/`acquire` API so call sites (mutation units, the commit shell) keep working. A failed
|
|
7
|
+
* release is recorded on the authority instead of poisoning every later writer.
|
|
8
|
+
* @module @lmzhen/dsh-evolution-core/home-fence
|
|
9
|
+
*/
|
|
10
|
+
import { AuthorityBusyError, HomeAuthority } from "./authority.js";
|
|
3
11
|
export class HomeFenceError extends Error {
|
|
4
12
|
reason;
|
|
5
13
|
constructor(reason, message) {
|
|
@@ -8,109 +16,51 @@ export class HomeFenceError extends Error {
|
|
|
8
16
|
this.reason = reason;
|
|
9
17
|
}
|
|
10
18
|
}
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/** A lock view for bodies that only need `assertHeld`; the authority releases on scope exit. */
|
|
20
|
+
function lockView(authority) {
|
|
21
|
+
return {
|
|
22
|
+
token: 'authority',
|
|
23
|
+
epoch: 0,
|
|
24
|
+
path: 'authority:tree',
|
|
25
|
+
acquiredAt: Date.now(),
|
|
26
|
+
assertHeld: async () => authority.assertHeld('tree'),
|
|
27
|
+
release: async () => { },
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
|
-
function
|
|
22
|
-
return error instanceof
|
|
30
|
+
function classify(error) {
|
|
31
|
+
return error instanceof AuthorityBusyError ? new HomeFenceError('busy', error.message) : error;
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* One home-level writer queue. It serializes same-process callers before the
|
|
29
|
-
* tree lock, and the tree lock remains the only cross-process guard the current
|
|
30
|
-
* backend can provide (nodeEvolutionIo is single-process).
|
|
31
|
-
*
|
|
32
|
-
* `acquire` is public only for legacy call sites; W0 keeps it usable but makes a
|
|
33
|
-
* failed release advance the queue and poison the fence instead of wedging every
|
|
34
|
-
* later writer. Nested acquisition is not supported: the state layer must reuse
|
|
35
|
-
* the transaction it is already inside (see evolution-state-json appendArchive).
|
|
36
|
-
*/
|
|
33
|
+
/** The family's home-level writer queue, backed by the one authority. */
|
|
37
34
|
export class HomeFence {
|
|
38
|
-
|
|
39
|
-
poisoned;
|
|
40
|
-
options;
|
|
35
|
+
authority;
|
|
41
36
|
constructor(options) {
|
|
42
|
-
this.
|
|
37
|
+
this.authority = options.authority ?? new HomeAuthority({
|
|
38
|
+
home: options.home,
|
|
39
|
+
...(options.waitMs === undefined ? {} : { waitMs: options.waitMs }),
|
|
40
|
+
});
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
await lock.release();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
if (!transientReleaseError(error) || attempt >= RELEASE_RETRY_MS.length)
|
|
53
|
-
throw error;
|
|
54
|
-
await sleep(RELEASE_RETRY_MS[attempt] ?? 100);
|
|
55
|
-
attempt += 1;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
42
|
+
/** The last release failure, if any; diagnostics only. */
|
|
43
|
+
get releaseFailure() {
|
|
44
|
+
return this.authority.releaseFailure;
|
|
58
45
|
}
|
|
59
|
-
async
|
|
60
|
-
if (this.poisoned !== undefined) {
|
|
61
|
-
throw new HomeFenceError('io', 'home fence is poisoned after a failed lock release: ' + this.poisoned.message);
|
|
62
|
-
}
|
|
63
|
-
const previous = this.tail;
|
|
64
|
-
let releaseQueue = () => { };
|
|
65
|
-
this.tail = new Promise(resolve => { releaseQueue = resolve; });
|
|
66
|
-
await previous;
|
|
46
|
+
async run(body) {
|
|
67
47
|
try {
|
|
68
|
-
|
|
69
|
-
if (!acquired.ok) {
|
|
70
|
-
throw new HomeFenceError(acquired.reason, acquired.message ?? 'home fence is ' + acquired.reason);
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
await assertHomeOwner(this.options.io, this.options.home);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
await acquired.lock.release().catch(() => { });
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
let released = false;
|
|
80
|
-
return {
|
|
81
|
-
lock: acquired.lock,
|
|
82
|
-
release: async () => {
|
|
83
|
-
if (released)
|
|
84
|
-
return;
|
|
85
|
-
released = true;
|
|
86
|
-
let failure;
|
|
87
|
-
try {
|
|
88
|
-
await this.releaseLock(acquired.lock);
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
failure = asError(error);
|
|
92
|
-
this.poisoned = failure;
|
|
93
|
-
}
|
|
94
|
-
finally {
|
|
95
|
-
releaseQueue();
|
|
96
|
-
}
|
|
97
|
-
if (failure !== undefined)
|
|
98
|
-
throw failure;
|
|
99
|
-
},
|
|
100
|
-
};
|
|
48
|
+
return await this.authority.runExclusive('tree', async () => await body(lockView(this.authority)));
|
|
101
49
|
}
|
|
102
50
|
catch (error) {
|
|
103
|
-
|
|
104
|
-
throw error;
|
|
51
|
+
throw classify(error);
|
|
105
52
|
}
|
|
106
53
|
}
|
|
107
|
-
async
|
|
108
|
-
const lease = await this.acquire();
|
|
54
|
+
async acquire() {
|
|
109
55
|
try {
|
|
110
|
-
|
|
56
|
+
const lease = await this.authority.lease('tree');
|
|
57
|
+
return {
|
|
58
|
+
lock: lockView(this.authority),
|
|
59
|
+
release: async () => { await lease.release(); },
|
|
60
|
+
};
|
|
111
61
|
}
|
|
112
|
-
|
|
113
|
-
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw classify(error);
|
|
114
64
|
}
|
|
115
65
|
}
|
|
116
66
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
* seam itself).
|
|
32
32
|
* @module @lmzhen/dsh-evolution-core
|
|
33
33
|
*/
|
|
34
|
+
export * from './authority.ts';
|
|
35
|
+
export * from './journal-protocol.ts';
|
|
34
36
|
export * from './citations.ts';
|
|
35
37
|
export * from './tree-write.ts';
|
|
36
38
|
export * from './limits.ts';
|
|
@@ -68,9 +70,7 @@ export * from './redact.ts';
|
|
|
68
70
|
export * from './review-channel.ts';
|
|
69
71
|
export * from './review-context.ts';
|
|
70
72
|
export * from './run-registry.ts';
|
|
71
|
-
export * from './tree-lock.ts';
|
|
72
73
|
export * from './home-fence.ts';
|
|
73
|
-
export * from './home-owner.ts';
|
|
74
74
|
export * from './lease-store.ts';
|
|
75
75
|
export * from './mutation-authority.ts';
|
|
76
76
|
export * from './reports.ts';
|
package/lib/types/index.js
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
* seam itself).
|
|
32
32
|
* @module @lmzhen/dsh-evolution-core
|
|
33
33
|
*/
|
|
34
|
+
export * from "./authority.js";
|
|
35
|
+
export * from "./journal-protocol.js";
|
|
34
36
|
export * from "./citations.js";
|
|
35
37
|
// G1/1.1: the ONE authority behind a write (its type and the authorityFrom builder).
|
|
36
38
|
export * from "./tree-write.js";
|
|
@@ -69,9 +71,7 @@ export * from "./redact.js";
|
|
|
69
71
|
export * from "./review-channel.js";
|
|
70
72
|
export * from "./review-context.js";
|
|
71
73
|
export * from "./run-registry.js";
|
|
72
|
-
export * from "./tree-lock.js";
|
|
73
74
|
export * from "./home-fence.js";
|
|
74
|
-
export * from "./home-owner.js";
|
|
75
75
|
export * from "./lease-store.js";
|
|
76
76
|
export * from "./mutation-authority.js";
|
|
77
77
|
export * from "./reports.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local atomic node:fs IO provider.
|
|
3
|
+
*
|
|
4
|
+
* The implementation is the single `nodeEvolutionIo()` from
|
|
5
|
+
* `dsh-evolution-core` (no duplicate copy: the old fork once diverged in
|
|
6
|
+
* exists(), made directories report absent and let re-archives overwrite
|
|
7
|
+
* older archive folders). Only the provider's `name` is added here.
|
|
8
|
+
*
|
|
9
|
+
* @module @lmzhen/dsh-evolution-core/io-node
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
export declare const name = "evolution-io-node";
|
|
13
|
+
export declare const inject: string[];
|
|
14
|
+
export declare function apply(ctx: Context): void;
|
|
15
|
+
//# sourceMappingURL=io-node.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local atomic node:fs IO provider.
|
|
3
|
+
*
|
|
4
|
+
* The implementation is the single `nodeEvolutionIo()` from
|
|
5
|
+
* `dsh-evolution-core` (no duplicate copy: the old fork once diverged in
|
|
6
|
+
* exists(), made directories report absent and let re-archives overwrite
|
|
7
|
+
* older archive folders). Only the provider's `name` is added here.
|
|
8
|
+
*
|
|
9
|
+
* @module @lmzhen/dsh-evolution-core/io-node
|
|
10
|
+
*/
|
|
11
|
+
import { nodeEvolutionIo } from "./io.js";
|
|
12
|
+
// Compile-time satisfiability (G1.3, F-340): the node backend (with its
|
|
13
|
+
// `name`) must satisfy the narrowed seam. A backend/seam drift fails `tsc`.
|
|
14
|
+
const _nodeProviderIsSeam = { name: 'node', ...nodeEvolutionIo() };
|
|
15
|
+
void _nodeProviderIsSeam;
|
|
16
|
+
export const name = 'evolution-io-node';
|
|
17
|
+
export const inject = ['evolutionIo'];
|
|
18
|
+
// P2-3 (v15): the provider is a MODULE-level singleton. `nodeEvolutionIo()`
|
|
19
|
+
// carries no per-instance state (its cross-call bookkeeping, e.g.
|
|
20
|
+
// `pendingSelfCleanup`, is already module-level in core), so instances are
|
|
21
|
+
// interchangeable — a single identity makes the registry's identical-object
|
|
22
|
+
// idempotency work: a second apply (HMR / re-mounted row) re-registers the
|
|
23
|
+
// SAME object and gets the original dispose instead of "already registered".
|
|
24
|
+
const provider = { name: 'node', ...nodeEvolutionIo() };
|
|
25
|
+
export function apply(ctx) {
|
|
26
|
+
// P2-7 (v14): declare the node backend as the nameless `provider()` default
|
|
27
|
+
// so an additionally registered backend cannot silently become the one every
|
|
28
|
+
// production consumer resolves.
|
|
29
|
+
// P2-3 (v15): no `hasProvider` early-return — the v14 early-return made the
|
|
30
|
+
// "foreign provider under the same name fails loud" contract UNREACHABLE
|
|
31
|
+
// (any name collision was silently swallowed, and the second mount silently
|
|
32
|
+
// dropped its default declaration and dispose). The registry now
|
|
33
|
+
// distinguishes: identical object → idempotent; different object → throw.
|
|
34
|
+
ctx.effect(() => ctx.evolutionIo.registerProvider(provider, { default: true }), 'evolution-io-node.provider');
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=io-node.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IO seam for evolution providers.
|
|
3
|
+
* @module @lmzhen/dsh-evolution-core/io-registry
|
|
4
|
+
*/
|
|
5
|
+
import { Context, Service } from '@deepseek-ai/cordis';
|
|
6
|
+
import type { EvolutionIoLike } from './io.ts';
|
|
7
|
+
/**
|
|
8
|
+
* The family's IO seam. Everything except `transact` is single-sourced from
|
|
9
|
+
* core `EvolutionIoLike` (0.3.23 G1.3, F-340): the seam no longer redeclares
|
|
10
|
+
* `size`/`isSymlink`/`mtime` or their `this: void` and null-vs-undefined
|
|
11
|
+
* contracts, so a drift between seam and core in those fields is impossible by
|
|
12
|
+
* construction. `name` stays seam-only and is added here.
|
|
13
|
+
*
|
|
14
|
+
* `transact` stays intentionally narrower than core: seam backends (e.g.
|
|
15
|
+
* `nodeEvolutionIo`) are uniformly async, so the task may return only a
|
|
16
|
+
* `Promise`. Core additionally allows a sync return (0.3.16 S1.14 X-1); the
|
|
17
|
+
* bidirectional-await-compatible consumers live in `transactIo` and the
|
|
18
|
+
* evolution IO adapter.
|
|
19
|
+
*/
|
|
20
|
+
export type EvolutionIo = Omit<EvolutionIoLike, 'transact'> & {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
transact?(this: void, path: string, task: (current: string | null) => Promise<string | null>): Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
declare module '@deepseek-ai/cordis' {
|
|
25
|
+
interface Context {
|
|
26
|
+
evolutionIo: EvolutionIoRegistry;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export declare class EvolutionIoRegistry extends Service {
|
|
30
|
+
private readonly providers;
|
|
31
|
+
/** Name of the provider that declared itself the default (P2-7, v14). */
|
|
32
|
+
private defaultName;
|
|
33
|
+
/** P2-3 (v15): per-name dispose — the idempotent re-registration returns
|
|
34
|
+
* the SAME function instance, so double-dispose is a single removal. */
|
|
35
|
+
private readonly disposals;
|
|
36
|
+
constructor(ctx: Context);
|
|
37
|
+
/**
|
|
38
|
+
* @param options.default - mark this provider as the one a nameless
|
|
39
|
+
* `provider()` resolves. The first explicit default wins; without any
|
|
40
|
+
* default the registry keeps its historical registration-order fallback.
|
|
41
|
+
*
|
|
42
|
+
* P2-3 (v15): re-registering the IDENTICAL provider object is idempotent —
|
|
43
|
+
* it returns the original dispose and does not throw. This is what lets a
|
|
44
|
+
* backend (io-node) re-apply (HMR / re-mounted row) without the silent
|
|
45
|
+
* `hasProvider` early-return the v14 fix used, which had made the
|
|
46
|
+
* fail-loud-below unreachable for a FOREIGN provider under the same name.
|
|
47
|
+
* A different object under a registered name still throws.
|
|
48
|
+
*/
|
|
49
|
+
registerProvider(provider: EvolutionIo, options?: {
|
|
50
|
+
default?: boolean;
|
|
51
|
+
}): () => void;
|
|
52
|
+
provider(name?: string): EvolutionIo;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The read-only face of the marker: what served THIS registry, without resolving anything.
|
|
56
|
+
* @param registry - the seam registry the caller already holds.
|
|
57
|
+
* @returns `known` with the observation, or `unknown` when nothing resolved through this registry yet.
|
|
58
|
+
*/
|
|
59
|
+
export declare function describeMedium(registry: object): {
|
|
60
|
+
readonly state: 'known';
|
|
61
|
+
readonly requested: readonly string[];
|
|
62
|
+
readonly resolved: string | undefined;
|
|
63
|
+
readonly via: string;
|
|
64
|
+
} | {
|
|
65
|
+
readonly state: 'unknown';
|
|
66
|
+
};
|
|
67
|
+
export declare function preferProvider<T>(registry: {
|
|
68
|
+
provider(name?: string): T;
|
|
69
|
+
}, names: readonly string[]): T;
|
|
70
|
+
export default EvolutionIoRegistry;
|
|
71
|
+
//# sourceMappingURL=io-registry.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IO seam for evolution providers.
|
|
3
|
+
* @module @lmzhen/dsh-evolution-core/io-registry
|
|
4
|
+
*/
|
|
5
|
+
import { Service } from '@deepseek-ai/cordis';
|
|
6
|
+
// Compile-time satisfiability (G1.3, F-340): the narrow seam must remain a
|
|
7
|
+
// valid core `EvolutionIoLike` so consumers typed against the wide core accept
|
|
8
|
+
// it. A drift that widens the seam or re-narrows a core field fails `tsc`.
|
|
9
|
+
const _seamSatisfiesCore = null;
|
|
10
|
+
void _seamSatisfiesCore;
|
|
11
|
+
export class EvolutionIoRegistry extends Service {
|
|
12
|
+
providers = new Map();
|
|
13
|
+
/** Name of the provider that declared itself the default (P2-7, v14). */
|
|
14
|
+
defaultName;
|
|
15
|
+
/** P2-3 (v15): per-name dispose — the idempotent re-registration returns
|
|
16
|
+
* the SAME function instance, so double-dispose is a single removal. */
|
|
17
|
+
disposals = new Map();
|
|
18
|
+
constructor(ctx) {
|
|
19
|
+
super(ctx, 'evolutionIo');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @param options.default - mark this provider as the one a nameless
|
|
23
|
+
* `provider()` resolves. The first explicit default wins; without any
|
|
24
|
+
* default the registry keeps its historical registration-order fallback.
|
|
25
|
+
*
|
|
26
|
+
* P2-3 (v15): re-registering the IDENTICAL provider object is idempotent —
|
|
27
|
+
* it returns the original dispose and does not throw. This is what lets a
|
|
28
|
+
* backend (io-node) re-apply (HMR / re-mounted row) without the silent
|
|
29
|
+
* `hasProvider` early-return the v14 fix used, which had made the
|
|
30
|
+
* fail-loud-below unreachable for a FOREIGN provider under the same name.
|
|
31
|
+
* A different object under a registered name still throws.
|
|
32
|
+
*/
|
|
33
|
+
registerProvider(provider, options = {}) {
|
|
34
|
+
const idempotent = this.providers.get(provider.name) === provider;
|
|
35
|
+
if (!idempotent && this.providers.has(provider.name))
|
|
36
|
+
throw new Error(`evolution IO provider "${provider.name}" already registered`);
|
|
37
|
+
// P3 (v16): the default declaration is handled BEFORE the idempotent
|
|
38
|
+
// early-return — the first cut evaluated it only on the fresh path, so a
|
|
39
|
+
// same-object re-registration that (now) declares default was silently
|
|
40
|
+
// swallowed with no warn and no effect, inconsistent with the warn below.
|
|
41
|
+
if (options.default === true) {
|
|
42
|
+
if (this.defaultName !== undefined && this.defaultName !== provider.name) {
|
|
43
|
+
this.ctx.logger.warn(`evolution IO provider "${provider.name}" declared itself the default, but "${this.defaultName}" already is — the first declaration wins`);
|
|
44
|
+
}
|
|
45
|
+
this.defaultName ??= provider.name;
|
|
46
|
+
}
|
|
47
|
+
if (idempotent) {
|
|
48
|
+
const existing = this.disposals.get(provider.name);
|
|
49
|
+
if (existing !== undefined)
|
|
50
|
+
return existing;
|
|
51
|
+
}
|
|
52
|
+
const dispose = () => {
|
|
53
|
+
// P3 (v16): GENERATION GUARD — a dispose handle acts only while it is
|
|
54
|
+
// still the CURRENT one for this name. Without this, the
|
|
55
|
+
// dispose→re-register(same singleton)→stale-handle sequence removed the
|
|
56
|
+
// NEW registration (the object-identity check cannot tell generations
|
|
57
|
+
// apart), leaving the registry empty for a live mount.
|
|
58
|
+
if (this.disposals.get(provider.name) !== dispose)
|
|
59
|
+
return;
|
|
60
|
+
this.providers.delete(provider.name);
|
|
61
|
+
this.disposals.delete(provider.name);
|
|
62
|
+
if (this.defaultName === provider.name)
|
|
63
|
+
this.defaultName = undefined;
|
|
64
|
+
};
|
|
65
|
+
this.providers.set(provider.name, provider);
|
|
66
|
+
this.disposals.set(provider.name, dispose);
|
|
67
|
+
return dispose;
|
|
68
|
+
}
|
|
69
|
+
// P3-D1 (v15): the speculative `hasProviders()` from v14 was removed — zero
|
|
70
|
+
// consumers (the lazy/boot-time probe it was written for reads the
|
|
71
|
+
// state-storage registry's own `hasProviders`).
|
|
72
|
+
// v20 (A-3): `hasProvider(name)` removed for the same reason — its only
|
|
73
|
+
// callers were this package's own spec; a presence probe goes through
|
|
74
|
+
// `provider(name)`, which fails loud on a missing name.
|
|
75
|
+
provider(name) {
|
|
76
|
+
if (name) {
|
|
77
|
+
const provider = this.providers.get(name);
|
|
78
|
+
if (provider)
|
|
79
|
+
return provider;
|
|
80
|
+
throw new Error(`evolution IO provider "${name}" is not registered`);
|
|
81
|
+
}
|
|
82
|
+
// P2-7 (v14): prefer the provider that explicitly declared itself the
|
|
83
|
+
// default; registration order remains the fallback for backends/tests that
|
|
84
|
+
// do not declare one.
|
|
85
|
+
const declared = this.defaultName === undefined ? undefined : this.providers.get(this.defaultName);
|
|
86
|
+
const first = declared ?? this.providers.values().next().value;
|
|
87
|
+
// P3 (v15): actionable message — the empty-registry case is always a
|
|
88
|
+
// missing mount, and every state seam error in the family names the row
|
|
89
|
+
// to add.
|
|
90
|
+
// P3 (v16): dual-scope guidance — published installs resolve @lmzhen, the
|
|
91
|
+
// upstream overlay resolves @deepseek-ai (see the scope-occupancy note in
|
|
92
|
+
// packages/README.md).
|
|
93
|
+
if (!first)
|
|
94
|
+
throw new Error('no evolution IO provider registered — mount evolution-io-node (@lmzhen/dsh-evolution-io-node published, @lmzhen/dsh-evolution-core/io-node in the dev overlay; ships with evolution-host/evolution-all) and retry');
|
|
95
|
+
return first;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const mediumObservations = new WeakMap();
|
|
99
|
+
/**
|
|
100
|
+
* The read-only face of the marker: what served THIS registry, without resolving anything.
|
|
101
|
+
* @param registry - the seam registry the caller already holds.
|
|
102
|
+
* @returns `known` with the observation, or `unknown` when nothing resolved through this registry yet.
|
|
103
|
+
*/
|
|
104
|
+
export function describeMedium(registry) {
|
|
105
|
+
const observation = mediumObservations.get(registry);
|
|
106
|
+
if (observation === undefined)
|
|
107
|
+
return { state: 'unknown' };
|
|
108
|
+
return { state: 'known', requested: observation.requested, resolved: observation.resolved, via: observation.via };
|
|
109
|
+
}
|
|
110
|
+
export function preferProvider(registry, names) {
|
|
111
|
+
for (const name of names) {
|
|
112
|
+
try {
|
|
113
|
+
const resolved = registry.provider(name);
|
|
114
|
+
mediumObservations.set(registry, { requested: names, resolved: name, via: 'preference' });
|
|
115
|
+
return resolved;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Not registered: this name is a preference, not a requirement (see the JSDoc).
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const fallback = registry.provider();
|
|
122
|
+
mediumObservations.set(registry, { requested: names, resolved: undefined, via: 'default' });
|
|
123
|
+
return fallback;
|
|
124
|
+
}
|
|
125
|
+
export default EvolutionIoRegistry;
|
|
126
|
+
//# sourceMappingURL=io-registry.js.map
|
package/lib/types/io.d.ts
CHANGED
|
@@ -75,6 +75,31 @@ export interface EvolutionIoLike {
|
|
|
75
75
|
* node backend's V5-03 short-circuit).
|
|
76
76
|
*/
|
|
77
77
|
export declare function transactIo(io: EvolutionIoLike, path: string, task: (current: string | null) => string | null | Promise<string | null>): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* The result of one durable write, in the shape W9-commit-protocol §3.3 requires: a caller may not
|
|
80
|
+
* retry an `unknown` (the bytes landed), and must roll back a `rejected` one.
|
|
81
|
+
*/
|
|
82
|
+
export type WriteOutcome = {
|
|
83
|
+
readonly kind: 'landed';
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: 'rejected';
|
|
86
|
+
readonly code: string;
|
|
87
|
+
readonly message: string;
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: 'unknown';
|
|
90
|
+
readonly message: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Read-modify-commit that reports what actually happened instead of collapsing the two failure
|
|
94
|
+
* kinds. `transactIo` deliberately turns a committed-warning into success (the bytes are visible),
|
|
95
|
+
* which is right for callers that only need the write; a two-phase caller needs to know that its
|
|
96
|
+
* follow-up step is unconfirmed, so it uses this instead.
|
|
97
|
+
* @param io - the IO backend.
|
|
98
|
+
* @param path - the durable file.
|
|
99
|
+
* @param task - the read-modify-render step.
|
|
100
|
+
* @returns `landed`, `unknown` (written, durability unconfirmed) or `rejected`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function transactOutcome(io: EvolutionIoLike, path: string, task: (current: string | null) => string | null | Promise<string | null>): Promise<WriteOutcome>;
|
|
78
103
|
/**
|
|
79
104
|
* V43 F-4 (S0-6): the shared "the transaction really invoked the task" guard.
|
|
80
105
|
* A backend that implements `transact` but never calls `task` resolves
|
|
@@ -166,8 +191,10 @@ export declare function isCommittedWarning(error: unknown): boolean;
|
|
|
166
191
|
/**
|
|
167
192
|
* Build the Node IO backend: plain fs promises, durable tmp + rename commits (crash atomicity) and
|
|
168
193
|
* ONE concurrency guarantee of its own — writes to the same path are serialized in-process (see
|
|
169
|
-
* `inProcessWrite`).
|
|
170
|
-
*
|
|
194
|
+
* `inProcessWrite`). Cross-process exclusion is not this backend's job: every durable writer takes
|
|
195
|
+
* the home lock through `HomeAuthority` (W9-authority), which delegates to the platform's
|
|
196
|
+
* `withFileLock`. The earlier claim that a `ctx.fs` provider supplied it was never true — no such
|
|
197
|
+
* provider exists in the family source.
|
|
171
198
|
*/
|
|
172
199
|
export declare function nodeEvolutionIo(): EvolutionIoLike;
|
|
173
200
|
/** F-211: the fs surface atomicWriteFiles uses — injectable so the commit-phase
|
package/lib/types/io.js
CHANGED
|
@@ -59,6 +59,46 @@ export async function transactIo(io, path, task) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
function outcomeFailure(error) {
|
|
63
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
+
if (isCommittedWarning(error))
|
|
65
|
+
return { kind: 'unknown', message };
|
|
66
|
+
const code = error?.code;
|
|
67
|
+
return { kind: 'rejected', code: typeof code === 'string' ? code : 'io', message };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Read-modify-commit that reports what actually happened instead of collapsing the two failure
|
|
71
|
+
* kinds. `transactIo` deliberately turns a committed-warning into success (the bytes are visible),
|
|
72
|
+
* which is right for callers that only need the write; a two-phase caller needs to know that its
|
|
73
|
+
* follow-up step is unconfirmed, so it uses this instead.
|
|
74
|
+
* @param io - the IO backend.
|
|
75
|
+
* @param path - the durable file.
|
|
76
|
+
* @param task - the read-modify-render step.
|
|
77
|
+
* @returns `landed`, `unknown` (written, durability unconfirmed) or `rejected`.
|
|
78
|
+
*/
|
|
79
|
+
export async function transactOutcome(io, path, task) {
|
|
80
|
+
if (io.transact) {
|
|
81
|
+
try {
|
|
82
|
+
await io.transact(path, task);
|
|
83
|
+
return { kind: 'landed' };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return outcomeFailure(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const current = await io.readText(path);
|
|
91
|
+
const next = await task(current);
|
|
92
|
+
if (next === null)
|
|
93
|
+
await io.remove(path);
|
|
94
|
+
else if (next !== current)
|
|
95
|
+
await io.writeText(path, next);
|
|
96
|
+
return { kind: 'landed' };
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
return outcomeFailure(error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
62
102
|
/** Build a {@link TransactTaskGuard} for one write path. See its doc. */
|
|
63
103
|
export function transactTaskGuard(what) {
|
|
64
104
|
let invoked = false;
|
|
@@ -286,8 +326,10 @@ export function isCommittedWarning(error) {
|
|
|
286
326
|
/**
|
|
287
327
|
* Build the Node IO backend: plain fs promises, durable tmp + rename commits (crash atomicity) and
|
|
288
328
|
* ONE concurrency guarantee of its own — writes to the same path are serialized in-process (see
|
|
289
|
-
* `inProcessWrite`).
|
|
290
|
-
*
|
|
329
|
+
* `inProcessWrite`). Cross-process exclusion is not this backend's job: every durable writer takes
|
|
330
|
+
* the home lock through `HomeAuthority` (W9-authority), which delegates to the platform's
|
|
331
|
+
* `withFileLock`. The earlier claim that a `ctx.fs` provider supplied it was never true — no such
|
|
332
|
+
* provider exists in the family source.
|
|
291
333
|
*/
|
|
292
334
|
export function nodeEvolutionIo() {
|
|
293
335
|
/**
|
|
@@ -304,13 +346,12 @@ export function nodeEvolutionIo() {
|
|
|
304
346
|
/** True when the pid is alive (single source: `isProcessAlive`). */
|
|
305
347
|
const isAlive = isProcessAlive;
|
|
306
348
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* exclusion are different concerns.
|
|
349
|
+
* This backend keeps exactly one concurrency guarantee of its own: writes to the SAME path inside
|
|
350
|
+
* THIS process are serialized (a promise chain per path: no timers, no lock files, no takeover
|
|
351
|
+
* windows). Cross-process exclusion belongs to `HomeAuthority` (W9-authority), which every
|
|
352
|
+
* durable writer takes and which delegates to the platform's `withFileLock`; a standalone caller
|
|
353
|
+
* that shares a directory across processes must take that lock too. The durable tmp + rename
|
|
354
|
+
* commit stays here — crash atomicity and mutual exclusion are different concerns.
|
|
314
355
|
*/
|
|
315
356
|
const queues = new Map();
|
|
316
357
|
const inProcessWrite = async (path, run) => {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A journal protocol: the phases one multi-write operation records, which transitions it allows, and
|
|
3
|
+
* what a restart may do from each phase (W9-commit-protocol §3.1).
|
|
4
|
+
*
|
|
5
|
+
* The commit and undo journals used to disagree: commit had a transition table and a recovery
|
|
6
|
+
* decision but only reported it, while undo wrote a journal nobody read. Both now describe the same
|
|
7
|
+
* shape, so a resumer can be written once against `JournalProtocol` instead of per operation.
|
|
8
|
+
* @module @lmzhen/dsh-evolution-core/journal-protocol
|
|
9
|
+
*/
|
|
10
|
+
/** What a restart may do with a journal that stopped in this phase. */
|
|
11
|
+
export type JournalRecovery = 'retry' | 'continue' | 'done' | 'refuse';
|
|
12
|
+
export interface JournalProtocol<P extends string> {
|
|
13
|
+
/** Every phase, in the order an operation normally passes through them. */
|
|
14
|
+
readonly phases: readonly P[];
|
|
15
|
+
/** Allowed transitions; an empty list marks a terminal phase. */
|
|
16
|
+
readonly next: Readonly<Record<P, readonly P[]>>;
|
|
17
|
+
/** The restart decision for a journal left in `phase`. */
|
|
18
|
+
recoveryOf(phase: P): JournalRecovery;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* True when `from` may advance to `to`.
|
|
22
|
+
* @param protocol - the journal's protocol.
|
|
23
|
+
* @param from - the recorded phase.
|
|
24
|
+
* @param to - the phase the caller wants to record next.
|
|
25
|
+
* @returns whether the transition is declared.
|
|
26
|
+
*/
|
|
27
|
+
export declare function canAdvance<P extends string>(protocol: JournalProtocol<P>, from: P, to: P): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* True when the phase is terminal (nothing may follow it).
|
|
30
|
+
* @param protocol - the journal's protocol.
|
|
31
|
+
* @param phase - the phase to test.
|
|
32
|
+
* @returns whether the phase is terminal.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isTerminal<P extends string>(protocol: JournalProtocol<P>, phase: P): boolean;
|
|
35
|
+
//# sourceMappingURL=journal-protocol.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A journal protocol: the phases one multi-write operation records, which transitions it allows, and
|
|
3
|
+
* what a restart may do from each phase (W9-commit-protocol §3.1).
|
|
4
|
+
*
|
|
5
|
+
* The commit and undo journals used to disagree: commit had a transition table and a recovery
|
|
6
|
+
* decision but only reported it, while undo wrote a journal nobody read. Both now describe the same
|
|
7
|
+
* shape, so a resumer can be written once against `JournalProtocol` instead of per operation.
|
|
8
|
+
* @module @lmzhen/dsh-evolution-core/journal-protocol
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* True when `from` may advance to `to`.
|
|
12
|
+
* @param protocol - the journal's protocol.
|
|
13
|
+
* @param from - the recorded phase.
|
|
14
|
+
* @param to - the phase the caller wants to record next.
|
|
15
|
+
* @returns whether the transition is declared.
|
|
16
|
+
*/
|
|
17
|
+
export function canAdvance(protocol, from, to) {
|
|
18
|
+
return protocol.next[from].includes(to);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* True when the phase is terminal (nothing may follow it).
|
|
22
|
+
* @param protocol - the journal's protocol.
|
|
23
|
+
* @param phase - the phase to test.
|
|
24
|
+
* @returns whether the phase is terminal.
|
|
25
|
+
*/
|
|
26
|
+
export function isTerminal(protocol, phase) {
|
|
27
|
+
return protocol.next[phase].length === 0;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=journal-protocol.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MutationOwner } from '
|
|
1
|
+
import type { MutationOwner } from './contract.ts';
|
|
2
2
|
import type { EvolutionIoLike } from './io.ts';
|
|
3
3
|
/** One persisted run/claim lease. Epoch increments on every re-acquire. */
|
|
4
4
|
export interface LeaseRecord {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type transactIo } from './io.ts';
|
|
2
2
|
import type { UnitClaimPort } from './unit-claim.ts';
|
|
3
|
-
import type { MutationOwner } from '
|
|
3
|
+
import type { MutationOwner } from './contract.ts';
|
|
4
4
|
export interface MutationRoot {
|
|
5
5
|
name: string;
|
|
6
6
|
protection: 'write' | 'delete' | 'none';
|