@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/types/io.d.ts
CHANGED
|
@@ -67,6 +67,11 @@ export interface EvolutionIoLike {
|
|
|
67
67
|
*/
|
|
68
68
|
mtime?(this: void, path: string): Promise<number | null>;
|
|
69
69
|
}
|
|
70
|
+
/** A backend's transact returned without ever calling the task; nothing was written. */
|
|
71
|
+
export declare class TransactionNotInvokedError extends Error {
|
|
72
|
+
readonly code = "transact-not-invoked";
|
|
73
|
+
constructor(path: string);
|
|
74
|
+
}
|
|
70
75
|
/**
|
|
71
76
|
* Run `task` inside `io.transact` when the backend provides it; otherwise fall
|
|
72
77
|
* back to a plain read → task → write/remove sequence (no cross-process lock —
|
|
@@ -74,60 +79,7 @@ export interface EvolutionIoLike {
|
|
|
74
79
|
* byte-identical task result skips the write (C-07 — parity with the
|
|
75
80
|
* node backend's V5-03 short-circuit).
|
|
76
81
|
*/
|
|
77
|
-
export declare function transactIo(io: EvolutionIoLike, path: string, task: (current: string | null) => string | null | Promise<string | null>): Promise<
|
|
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>;
|
|
103
|
-
/**
|
|
104
|
-
* V43 F-4 (S0-6): the shared "the transaction really invoked the task" guard.
|
|
105
|
-
* A backend that implements `transact` but never calls `task` resolves
|
|
106
|
-
* cleanly, so every caller that reads the outcome out of the task itself (a
|
|
107
|
-
* result slot filled inside it, a `Promise<void>` save path) reported success
|
|
108
|
-
* for a write that never happened — the silent-lost-write family the inline
|
|
109
|
-
* C-01 (memory-store) and V6-19 (skill-store) guards cover one call site at a
|
|
110
|
-
* time. Wrap the task handed to `transactIo`/`io.transact` and probe after
|
|
111
|
-
* the call: `invoked()` for a path that owns a structured refusal, or
|
|
112
|
-
* `assertInvoked()` for a void-returning path with no result channel (the
|
|
113
|
-
* family's fail-loud discipline, same wording as skill-store's guard).
|
|
114
|
-
*
|
|
115
|
-
* The wrapper is an identity pass-through — neither the backend nor the task
|
|
116
|
-
* sees a difference — and a task that IS invoked but skips the write (a
|
|
117
|
-
* dedupe no-op) counts as invoked: the probe answers "did the write path get
|
|
118
|
-
* to decide", not "did bytes change".
|
|
119
|
-
* @param what - the write being attempted, named in the thrown message
|
|
120
|
-
*/
|
|
121
|
-
export interface TransactTaskGuard {
|
|
122
|
-
/** Wrap the task handed to the transact backend, marking its invocation. */
|
|
123
|
-
wrap<A, R>(task: (current: A) => R): (current: A) => R;
|
|
124
|
-
/** Did the backend invoke the wrapped task? */
|
|
125
|
-
invoked(): boolean;
|
|
126
|
-
/** Throw when the backend never invoked it (nothing was written). */
|
|
127
|
-
assertInvoked(): void;
|
|
128
|
-
}
|
|
129
|
-
/** Build a {@link TransactTaskGuard} for one write path. See its doc. */
|
|
130
|
-
export declare function transactTaskGuard(what: string): TransactTaskGuard;
|
|
82
|
+
export declare function transactIo(io: EvolutionIoLike, path: string, task: (current: string | null) => string | null | Promise<string | null>): Promise<readonly string[] | undefined>;
|
|
131
83
|
/** Lazy adapter over an IO provider registry, shared by every evolution consumer. */
|
|
132
84
|
export declare function evolutionIoAdapter(provider: () => EvolutionIoLike): EvolutionIoLike;
|
|
133
85
|
/**
|
package/lib/types/io.js
CHANGED
|
@@ -12,6 +12,14 @@ import { randomBytes } from 'node:crypto';
|
|
|
12
12
|
// there" lives in probe.ts; this backend delegates instead of keeping a second
|
|
13
13
|
// copy of the same two codes.
|
|
14
14
|
import { isMissingPath } from "./probe.js";
|
|
15
|
+
/** A backend's transact returned without ever calling the task; nothing was written. */
|
|
16
|
+
export class TransactionNotInvokedError extends Error {
|
|
17
|
+
code = 'transact-not-invoked';
|
|
18
|
+
constructor(path) {
|
|
19
|
+
super('transact-not-invoked: ' + path);
|
|
20
|
+
this.name = 'TransactionNotInvokedError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
15
23
|
/**
|
|
16
24
|
* Run `task` inside `io.transact` when the backend provides it; otherwise fall
|
|
17
25
|
* back to a plain read → task → write/remove sequence (no cross-process lock —
|
|
@@ -26,22 +34,36 @@ export async function transactIo(io, path, task) {
|
|
|
26
34
|
// packages: propagating it made memory/usage/mutations/state/activity/
|
|
27
35
|
// feedback/events report "not written" for a write that happened, and a
|
|
28
36
|
// two-phase caller could then roll back a visible write. The durability loss
|
|
29
|
-
// is still observable — it is logged
|
|
37
|
+
// is still observable — it is logged AND returned so a two-phase caller can
|
|
38
|
+
// report it instead of silently losing the warning.
|
|
30
39
|
const committedOnly = (error) => isCommittedWarning(error);
|
|
40
|
+
const warnings = [];
|
|
41
|
+
const warnCommitted = (error) => {
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
warnings.push(message);
|
|
44
|
+
console.warn(`evolution-io: ${path} was written but its directory fsync failed — the bytes are visible, durability is unconfirmed: ${message}`);
|
|
45
|
+
};
|
|
46
|
+
let invoked = false;
|
|
47
|
+
const invoke = async (current) => {
|
|
48
|
+
invoked = true;
|
|
49
|
+
return await task(current);
|
|
50
|
+
};
|
|
31
51
|
if (io.transact) {
|
|
32
52
|
try {
|
|
33
|
-
await io.transact(path,
|
|
34
|
-
|
|
53
|
+
await io.transact(path, invoke);
|
|
54
|
+
if (!invoked)
|
|
55
|
+
throw new TransactionNotInvokedError(path);
|
|
56
|
+
return undefined;
|
|
35
57
|
}
|
|
36
58
|
catch (error) {
|
|
37
59
|
if (!committedOnly(error))
|
|
38
60
|
throw error;
|
|
39
|
-
|
|
40
|
-
return;
|
|
61
|
+
warnCommitted(error);
|
|
62
|
+
return warnings;
|
|
41
63
|
}
|
|
42
64
|
}
|
|
43
65
|
const current = await io.readText(path);
|
|
44
|
-
const next = await
|
|
66
|
+
const next = await invoke(current);
|
|
45
67
|
if (next === null)
|
|
46
68
|
await io.remove(path);
|
|
47
69
|
// C-07: a byte-identical result is a no-op — the same V5-03
|
|
@@ -55,65 +77,10 @@ export async function transactIo(io, path, task) {
|
|
|
55
77
|
catch (error) {
|
|
56
78
|
if (!committedOnly(error))
|
|
57
79
|
throw error;
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
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);
|
|
80
|
+
warnCommitted(error);
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
|
-
|
|
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
|
-
}
|
|
102
|
-
/** Build a {@link TransactTaskGuard} for one write path. See its doc. */
|
|
103
|
-
export function transactTaskGuard(what) {
|
|
104
|
-
let invoked = false;
|
|
105
|
-
return {
|
|
106
|
-
wrap: (task) => (current) => {
|
|
107
|
-
invoked = true;
|
|
108
|
-
return task(current);
|
|
109
|
-
},
|
|
110
|
-
invoked: () => invoked,
|
|
111
|
-
assertInvoked: () => {
|
|
112
|
-
if (invoked)
|
|
113
|
-
return;
|
|
114
|
-
throw new Error(`internal error: the write transaction for ${what} did not invoke the task; no write was performed`);
|
|
115
|
-
},
|
|
116
|
-
};
|
|
83
|
+
return warnings.length === 0 ? undefined : warnings;
|
|
117
84
|
}
|
|
118
85
|
/** Lazy adapter over an IO provider registry, shared by every evolution consumer. */
|
|
119
86
|
export function evolutionIoAdapter(provider) {
|
|
@@ -133,9 +100,12 @@ export function evolutionIoAdapter(provider) {
|
|
|
133
100
|
},
|
|
134
101
|
// Transact and symlink probes are forwarding-only: the fallback semantics
|
|
135
102
|
// live in the consumer helper / the backend itself.
|
|
136
|
-
transact: (path, task) => {
|
|
103
|
+
transact: async (path, task) => {
|
|
137
104
|
const io = provider();
|
|
138
|
-
|
|
105
|
+
if (io.transact)
|
|
106
|
+
await io.transact(path, task);
|
|
107
|
+
else
|
|
108
|
+
await transactIo(io, path, task);
|
|
139
109
|
},
|
|
140
110
|
isSymlink: (path) => {
|
|
141
111
|
const io = provider();
|
|
@@ -17,19 +17,4 @@ export interface JournalProtocol<P extends string> {
|
|
|
17
17
|
/** The restart decision for a journal left in `phase`. */
|
|
18
18
|
recoveryOf(phase: P): JournalRecovery;
|
|
19
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
20
|
//# sourceMappingURL=journal-protocol.d.ts.map
|
|
@@ -7,23 +7,5 @@
|
|
|
7
7
|
* shape, so a resumer can be written once against `JournalProtocol` instead of per operation.
|
|
8
8
|
* @module @lmzhen/dsh-evolution-core/journal-protocol
|
|
9
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
|
-
}
|
|
10
|
+
export {};
|
|
29
11
|
//# sourceMappingURL=journal-protocol.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MutationOwner } from './contract.ts';
|
|
2
|
-
import type
|
|
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 {
|
|
5
5
|
readonly id: string;
|
package/lib/types/lease-store.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { transactIo } from "./io.js";
|
|
3
4
|
export const DEFAULT_LEASE_TTL_MS = 30_000;
|
|
4
5
|
export function leaseFile(home, runId) {
|
|
5
6
|
return join(home, 'leases', encodeURIComponent(runId) + '.json');
|
|
@@ -17,18 +18,6 @@ function parseLease(raw) {
|
|
|
17
18
|
return undefined;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
async function transact(io, path, task) {
|
|
21
|
-
if (io.transact !== undefined) {
|
|
22
|
-
await io.transact(path, task);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const current = await io.readText(path);
|
|
26
|
-
const next = task(current);
|
|
27
|
-
if (next === null)
|
|
28
|
-
await io.remove(path);
|
|
29
|
-
else if (next !== current)
|
|
30
|
-
await io.writeText(path, next);
|
|
31
|
-
}
|
|
32
21
|
function tokenOf(record) {
|
|
33
22
|
return { id: record.id, owner: record.owner, runId: record.runId, epoch: record.epoch };
|
|
34
23
|
}
|
|
@@ -58,7 +47,7 @@ export class LeaseStore {
|
|
|
58
47
|
const now = this.now();
|
|
59
48
|
let created;
|
|
60
49
|
let holder;
|
|
61
|
-
await
|
|
50
|
+
await transactIo(this.io, path, (raw) => {
|
|
62
51
|
const current = parseLease(raw);
|
|
63
52
|
if (current !== undefined && current.state === 'active' && now < current.expiresAt) {
|
|
64
53
|
holder = current;
|
|
@@ -93,7 +82,7 @@ export class LeaseStore {
|
|
|
93
82
|
async renew(token, ttlMs = this.ttlMs) {
|
|
94
83
|
const path = this.path(token.runId);
|
|
95
84
|
let next = null;
|
|
96
|
-
await
|
|
85
|
+
await transactIo(this.io, path, (raw) => {
|
|
97
86
|
const current = parseLease(raw);
|
|
98
87
|
if (current === undefined || current.state !== 'active' || current.id !== token.id || current.epoch !== token.epoch)
|
|
99
88
|
return raw;
|
|
@@ -105,7 +94,7 @@ export class LeaseStore {
|
|
|
105
94
|
}
|
|
106
95
|
async release(token) {
|
|
107
96
|
const path = this.path(token.runId);
|
|
108
|
-
await
|
|
97
|
+
await transactIo(this.io, path, (raw) => {
|
|
109
98
|
const current = parseLease(raw);
|
|
110
99
|
if (current === undefined || current.id !== token.id || current.epoch !== token.epoch)
|
|
111
100
|
return raw;
|
package/lib/types/live.d.ts
CHANGED
|
@@ -63,16 +63,4 @@ export declare function clampOnce(warned: Set<string>, warn: (message: string) =
|
|
|
63
63
|
* reference, which is the silent failure this reader exists to prevent.
|
|
64
64
|
*/
|
|
65
65
|
export declare function liveBool(value: LiveValue<boolean>, fallback?: boolean): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Read a string (live or plain). Blank/whitespace counts as unset — the same rule `evolutionRoot` uses
|
|
68
|
-
* for `DSH_HOME`.
|
|
69
|
-
*/
|
|
70
|
-
export declare function liveString(value: LiveValue<string>, fallback: string): string;
|
|
71
|
-
/**
|
|
72
|
-
* Read an enumerated string (live or plain); a value outside `allowed` falls back.
|
|
73
|
-
*
|
|
74
|
-
* Used for the mode-like knobs (review mode, trigger, citation policy, write-confirm mode) where a
|
|
75
|
-
* bare `?? default` would accept a typo the schema never saw.
|
|
76
|
-
*/
|
|
77
|
-
export declare function liveEnum<T extends string>(value: LiveValue<T>, allowed: readonly T[], fallback: T): T;
|
|
78
66
|
//# sourceMappingURL=live.d.ts.map
|
package/lib/types/live.js
CHANGED
|
@@ -86,22 +86,4 @@ export function clampOnce(warned, warn, name, value, fallback, min, max) {
|
|
|
86
86
|
export function liveBool(value, fallback = false) {
|
|
87
87
|
return unwrapLive(value) ?? fallback;
|
|
88
88
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Read a string (live or plain). Blank/whitespace counts as unset — the same rule `evolutionRoot` uses
|
|
91
|
-
* for `DSH_HOME`.
|
|
92
|
-
*/
|
|
93
|
-
export function liveString(value, fallback) {
|
|
94
|
-
const current = unwrapLive(value)?.trim();
|
|
95
|
-
return current === undefined || current.length === 0 ? fallback : current;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Read an enumerated string (live or plain); a value outside `allowed` falls back.
|
|
99
|
-
*
|
|
100
|
-
* Used for the mode-like knobs (review mode, trigger, citation policy, write-confirm mode) where a
|
|
101
|
-
* bare `?? default` would accept a typo the schema never saw.
|
|
102
|
-
*/
|
|
103
|
-
export function liveEnum(value, allowed, fallback) {
|
|
104
|
-
const current = unwrapLive(value);
|
|
105
|
-
return current !== undefined && allowed.includes(current) ? current : fallback;
|
|
106
|
-
}
|
|
107
89
|
//# sourceMappingURL=live.js.map
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Stores are MEMORY.md and USER.md under $DSH_HOME/memories (~/.dsh/memories).
|
|
4
4
|
*/
|
|
5
5
|
import { type EvolutionIoLike } from './io.ts';
|
|
6
|
-
export { ENTRY_DELIMITER } from './constants.ts';
|
|
7
6
|
export type MemoryTarget = 'memory' | 'user';
|
|
8
7
|
export interface MemoryOperation {
|
|
9
8
|
action: 'add' | 'replace' | 'remove';
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
* Stores are MEMORY.md and USER.md under $DSH_HOME/memories (~/.dsh/memories).
|
|
4
4
|
*/
|
|
5
5
|
import { basename, join } from 'node:path';
|
|
6
|
-
import { nodeEvolutionIo, transactIo } from "./io.js";
|
|
6
|
+
import { nodeEvolutionIo, TransactionNotInvokedError, transactIo } from "./io.js";
|
|
7
7
|
import { evolutionRoot } from "./state-store.js";
|
|
8
8
|
import { makeSerialQueue } from "./serial.js";
|
|
9
9
|
import { payloadText } from "./payload.js";
|
|
10
10
|
import { scanMemoryThreats } from "./threats.js";
|
|
11
11
|
import { ENTRY_DELIMITER, DEFAULT_MEMORY_CHAR_LIMIT, DEFAULT_USER_CHAR_LIMIT, DEFAULT_CONSOLIDATION_FAILURES } from "./constants.js";
|
|
12
|
-
export { ENTRY_DELIMITER } from "./constants.js";
|
|
13
12
|
/**
|
|
14
13
|
* Read-guard factor: a memory file larger than this multiple of its target's
|
|
15
14
|
* char limit is treated as externally corrupted and skipped instead of being
|
|
@@ -286,10 +285,18 @@ export class MemoryStore {
|
|
|
286
285
|
return step.write ?? (current ?? null);
|
|
287
286
|
});
|
|
288
287
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
288
|
+
try {
|
|
289
|
+
if (this.fence !== undefined)
|
|
290
|
+
await this.fence.run(run);
|
|
291
|
+
else
|
|
292
|
+
await run();
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
// C-01: the transact seam now reports a contract-violating backend with a
|
|
296
|
+
// typed error; memory's contract is a structured refusal, not a throw.
|
|
297
|
+
if (!(error instanceof TransactionNotInvokedError))
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
293
300
|
// C-01: a transact backend that violates the contract (never invokes the
|
|
294
301
|
// task) leaves `outcome` undefined — the old `undefined as
|
|
295
302
|
// MemoryApplyResult` cast handed callers an object whose `.ok` dereference
|
|
@@ -19,6 +19,11 @@ export class MutationAuthority {
|
|
|
19
19
|
get mutationLock() {
|
|
20
20
|
return {
|
|
21
21
|
acquire: async () => {
|
|
22
|
+
// A nested writer running inside an already-held home fence must reuse that
|
|
23
|
+
// exclusion, not queue behind its own lease (merge undo/consolidate call public
|
|
24
|
+
// mutators under one pass-level fence). A caller outside the fence still acquires.
|
|
25
|
+
if (this.fence.holdsTree())
|
|
26
|
+
return { release: async () => { } };
|
|
22
27
|
const lease = await this.fence.acquire();
|
|
23
28
|
return { release: async () => { await lease.release(); } };
|
|
24
29
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { basename, dirname, isAbsolute, join, relative } from 'node:path';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { isCommittedWarning, isProcessAlive } from "./io.js";
|
|
3
|
+
import { isCommittedWarning, isProcessAlive, TransactionNotInvokedError, transactIo } from "./io.js";
|
|
4
4
|
import { WriteKernel } from "./write-kernel.js";
|
|
5
5
|
function underRoot(rootDir, target) {
|
|
6
6
|
if (rootDir === undefined || rootDir === '')
|
|
@@ -154,7 +154,8 @@ export class MutationUnit {
|
|
|
154
154
|
lease = await this.lock.acquire();
|
|
155
155
|
}
|
|
156
156
|
catch (error) {
|
|
157
|
-
|
|
157
|
+
const code = error instanceof TransactionNotInvokedError ? 'transact-not-invoked' : 'unit-fence-failed';
|
|
158
|
+
return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code, message: error instanceof Error ? error.message : String(error) }] };
|
|
158
159
|
}
|
|
159
160
|
let claim;
|
|
160
161
|
if (this.claim !== undefined) {
|
|
@@ -247,6 +248,7 @@ export class MutationUnit {
|
|
|
247
248
|
rollbackFailure = rollbackError instanceof Error ? rollbackError.message : String(rollbackError);
|
|
248
249
|
}
|
|
249
250
|
const detail = rollbackFailure === '' ? message : message + '; rollback failed: ' + rollbackFailure;
|
|
251
|
+
const failureCode = error?.code === 'transact-not-invoked' ? 'transact-not-invoked' : 'write-failed';
|
|
250
252
|
await this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'failed', changed, error: detail });
|
|
251
253
|
try {
|
|
252
254
|
await this.hooks?.rolledBack?.({
|
|
@@ -267,7 +269,7 @@ export class MutationUnit {
|
|
|
267
269
|
catch {
|
|
268
270
|
// best-effort hook; the structured write error remains authoritative
|
|
269
271
|
}
|
|
270
|
-
return { ok: false, unitId, dryRun: false, changed, errors: [{ code:
|
|
272
|
+
return { ok: false, unitId, dryRun: false, changed, errors: [{ code: failureCode, message: detail }] };
|
|
271
273
|
}
|
|
272
274
|
finally {
|
|
273
275
|
await claim?.release().catch(() => { });
|
|
@@ -298,7 +300,8 @@ export class MutationUnit {
|
|
|
298
300
|
lease = await this.lock.acquire();
|
|
299
301
|
}
|
|
300
302
|
catch (error) {
|
|
301
|
-
|
|
303
|
+
const code = error instanceof TransactionNotInvokedError ? 'transact-not-invoked' : 'unit-fence-failed';
|
|
304
|
+
return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code, message: error instanceof Error ? error.message : String(error) }] };
|
|
302
305
|
}
|
|
303
306
|
const reverted = [];
|
|
304
307
|
try {
|
|
@@ -390,10 +393,11 @@ export class MutationUnit {
|
|
|
390
393
|
if (op === undefined)
|
|
391
394
|
continue;
|
|
392
395
|
try {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
396
|
+
// restore(target) writes `before` only while the current bytes equal `after`; the undo
|
|
397
|
+
// wrote op.before, so the compensation passes (before=op.after, after=op.before).
|
|
398
|
+
const restored = await this.kernel.restore({ path: target, before: op.after, after: op.before });
|
|
399
|
+
if (!restored.ok)
|
|
400
|
+
throw new Error(restored.errors[0]?.message ?? 'compensation blocked: ' + target);
|
|
397
401
|
}
|
|
398
402
|
catch {
|
|
399
403
|
// best-effort undo compensation; the structured error below remains honest
|
|
@@ -410,7 +414,7 @@ export class MutationUnit {
|
|
|
410
414
|
async applyOp(op, baseline) {
|
|
411
415
|
const result = await this.kernel.writeOne({ path: op.target, expected: baseline, next: op.kind === 'delete' ? null : op.content, ...op.skill === undefined ? {} : { skill: op.skill } }, { guardBaseline: this.transactGuard });
|
|
412
416
|
if (!result.ok)
|
|
413
|
-
throw Object.assign(new Error(result.errors[0]?.message ?? 'write failed: ' + op.target), { noWrite: true });
|
|
417
|
+
throw Object.assign(new Error(result.errors[0]?.message ?? 'write failed: ' + op.target), { noWrite: true, code: result.errors[0]?.code });
|
|
414
418
|
return [...(result.warnings ?? [])];
|
|
415
419
|
}
|
|
416
420
|
async rollback(snapshots) {
|
|
@@ -447,28 +451,7 @@ export function fileMutationLock(io, root, options = {}) {
|
|
|
447
451
|
const now = options.now ?? Date.now;
|
|
448
452
|
const sleep = options.sleep ?? defaultSleep;
|
|
449
453
|
const update = async (task) => {
|
|
450
|
-
|
|
451
|
-
let ran = false;
|
|
452
|
-
await io.transact(path, current => {
|
|
453
|
-
ran = true;
|
|
454
|
-
return task(current);
|
|
455
|
-
});
|
|
456
|
-
if (!ran)
|
|
457
|
-
throw new Error('mutation-lock-transact-not-run: ' + path);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
const current = await io.readText(path);
|
|
461
|
-
const next = task(current);
|
|
462
|
-
try {
|
|
463
|
-
if (next === null)
|
|
464
|
-
await io.remove(path);
|
|
465
|
-
else
|
|
466
|
-
await io.writeText(path, next);
|
|
467
|
-
}
|
|
468
|
-
catch (error) {
|
|
469
|
-
if (!isCommittedWarning(error))
|
|
470
|
-
throw error;
|
|
471
|
-
}
|
|
454
|
+
await transactIo(io, path, task);
|
|
472
455
|
};
|
|
473
456
|
return {
|
|
474
457
|
async acquire() {
|
package/lib/types/params.d.ts
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* the SAME name in two carriers (reviewMode, staleAfterDays, archiveAfterDays —
|
|
6
6
|
* resolved by the existing policy-shadows-row rule) and six use DIFFERENT names.
|
|
7
7
|
* This module owns the six: the policy/snapshot name is the canonical id, the
|
|
8
|
-
* plugin-row name is a deprecated alias
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* plugin-row name is a deprecated alias. The alias table survives only for the one-time
|
|
9
|
+
* legacy-document migration and the doctor's old-key report; live readers use the
|
|
10
|
+
* canonical id and its carrier no longer falls back to the legacy spelling.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* writing is strict (the write path accepts canonical ids only, so no new
|
|
14
|
-
* document is created under a deprecated name).
|
|
12
|
+
* Writing is canonical-only (a deprecated name is not a live row field in 0.48).
|
|
15
13
|
* @module
|
|
16
14
|
*/
|
|
17
|
-
/** Deprecated alias (plugin-row name) -> canonical id (policy/snapshot name).
|
|
15
|
+
/** Deprecated alias (plugin-row name) -> canonical id (policy/snapshot name).
|
|
16
|
+
* Retained for the one-time legacy-document migration and the doctor's old-key report;
|
|
17
|
+
* live readers use the canonical id only. */
|
|
18
18
|
export declare const PARAM_ALIASES: Readonly<Record<string, string>>;
|
|
19
19
|
/**
|
|
20
20
|
* Resolve any parameter id to its canonical form.
|
|
@@ -29,17 +29,10 @@ export declare function resolveParamId(id: string): string;
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function isDeprecatedParamId(id: string): boolean;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @param id - parameter id a caller intends to write.
|
|
34
|
-
* @returns the canonical id.
|
|
35
|
-
* @throws {Error} when the id is a deprecated alias; the message names both ids.
|
|
36
|
-
*/
|
|
37
|
-
export declare function canonicalWriteId(id: string): string;
|
|
38
|
-
/**
|
|
39
|
-
* Read a parameter from a carrier that may still spell the legacy name.
|
|
32
|
+
* Read a parameter by its canonical id.
|
|
40
33
|
* @param carrier - config/snapshot object to read from, or undefined.
|
|
41
|
-
* @param id - canonical id (
|
|
42
|
-
* @returns the canonical value
|
|
34
|
+
* @param id - canonical id (an alias is resolved first, for migration callers).
|
|
35
|
+
* @returns the canonical value, or undefined.
|
|
43
36
|
*/
|
|
44
37
|
export declare function readParam(carrier: object | undefined, id: string): unknown;
|
|
45
38
|
/** Exposure group (design §7.2): the unit a developer changes together.
|
|
@@ -159,17 +152,6 @@ export declare const NAMESPACE_MIGRATIONS: readonly {
|
|
|
159
152
|
readonly namespace: string;
|
|
160
153
|
readonly rowId: string;
|
|
161
154
|
}[];
|
|
162
|
-
/**
|
|
163
|
-
* The LEGACY settings namespace one owner package used to register through the family's
|
|
164
|
-
* own seam (0.1.x). It is no longer what the platform calls the section: the platform
|
|
165
|
-
* derives a settings namespace from the Loader entry id, and this registry's `owner` field
|
|
166
|
-
* IS that row id, so a live lookup uses {@link paramRowId}. What remains here is the
|
|
167
|
-
* migration SOURCE (G3 moves a user layer out of this string and into the row id).
|
|
168
|
-
* @param owner - owner package directory name (the map's key).
|
|
169
|
-
* @returns the legacy namespace that owner registered.
|
|
170
|
-
* @throws when the owner has no entry in {@link PARAM_NAMESPACES}.
|
|
171
|
-
*/
|
|
172
|
-
export declare function paramNamespace(owner: string): string;
|
|
173
155
|
/**
|
|
174
156
|
* The settings id one row's user layer lives under, or undefined when the owner publishes
|
|
175
157
|
* no user layer at all (a deployment-only row: its knobs are E2 and never reach a settings
|
|
@@ -177,7 +159,7 @@ export declare function paramNamespace(owner: string): string;
|
|
|
177
159
|
* it in `settings.describe()` / `configForms.get(entryId)`, and an owner package's row id is
|
|
178
160
|
* its own name — spelled the same in every bundle patch.
|
|
179
161
|
*
|
|
180
|
-
* This is the id to LOOK UP with; {@link
|
|
162
|
+
* This is the id to LOOK UP with; {@link PARAM_NAMESPACES} keeps the legacy string the 0.1.x
|
|
181
163
|
* seam registered, which is the G3 migration source and never a live lookup key.
|
|
182
164
|
* @param owner - owner package directory name (the row id).
|
|
183
165
|
* @returns the entry id the platform reports for that row, or undefined for a row without
|