@lmzhen/dsh-evolution-core 0.44.0 → 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.
Files changed (62) hide show
  1. package/lib/authority-plugin.js +14 -0
  2. package/lib/composition/index.js +2 -2
  3. package/lib/{composition-CVafrlEw.js → composition-Da8NfRI7.js} +2 -2
  4. package/lib/contract.js +1 -0
  5. package/lib/index.js +54 -133
  6. package/lib/{mutations-jUuOPaCn.js → io-AmUf4lVY.js} +54 -84
  7. package/lib/io-node.js +24 -0
  8. package/lib/io-registry.js +96 -0
  9. package/lib/mutation-authority-DeJ_Wz14.js +537 -0
  10. package/lib/mutations-DwvbjRHF.js +75 -0
  11. package/lib/numeric-DLeLvvGb.js +324 -0
  12. package/lib/platform/index.js +1 -1
  13. package/lib/{platform-B06_h8t-.js → platform-CFA12Jam.js} +36 -19
  14. package/lib/policy.js +99 -0
  15. package/lib/runtime/plugin.js +8 -1
  16. package/lib/{skill-health-BLGZTIv8.js → skill-health-D1pZGk5V.js} +6 -835
  17. package/lib/{skill-history-_Cssts5o.js → skill-history-CjypdYqv.js} +2 -1
  18. package/lib/skills.js +6 -3
  19. package/lib/subagent/index.js +1 -1
  20. package/lib/types/authority-plugin.d.ts +12 -0
  21. package/lib/types/authority-plugin.js +10 -0
  22. package/lib/types/authority.d.ts +96 -0
  23. package/lib/types/authority.js +237 -0
  24. package/lib/types/contract.d.ts +116 -0
  25. package/lib/types/contract.js +10 -0
  26. package/lib/types/events.d.ts +2 -2
  27. package/lib/types/home-fence.d.ts +25 -17
  28. package/lib/types/home-fence.js +42 -92
  29. package/lib/types/index.d.ts +2 -2
  30. package/lib/types/index.js +2 -2
  31. package/lib/types/io-node.d.ts +15 -0
  32. package/lib/types/io-node.js +36 -0
  33. package/lib/types/io-registry.d.ts +71 -0
  34. package/lib/types/io-registry.js +126 -0
  35. package/lib/types/io.d.ts +29 -2
  36. package/lib/types/io.js +50 -9
  37. package/lib/types/journal-protocol.d.ts +35 -0
  38. package/lib/types/journal-protocol.js +29 -0
  39. package/lib/types/lease-store.d.ts +1 -1
  40. package/lib/types/mutation-unit.d.ts +1 -1
  41. package/lib/types/params.d.ts +2 -16
  42. package/lib/types/params.js +6 -44
  43. package/lib/types/platform/llm.js +4 -1
  44. package/lib/types/platform/projections.d.ts +10 -4
  45. package/lib/types/platform/projections.js +34 -17
  46. package/lib/types/platform-services.d.ts +2 -2
  47. package/lib/types/policy.d.ts +68 -0
  48. package/lib/types/policy.js +161 -0
  49. package/lib/types/run-registry.d.ts +2 -2
  50. package/lib/types/runtime/projections.js +12 -0
  51. package/lib/types/state-store.d.ts +1 -1
  52. package/lib/types/state-store.js +1 -1
  53. package/lib/types/store-ledger.js +2 -2
  54. package/lib/types/write-inventory.js +3 -1
  55. package/lib/write.js +2 -2
  56. package/package.json +25 -4
  57. package/persisted-write-inventory.json +10 -37
  58. package/lib/types/home-owner.d.ts +0 -4
  59. package/lib/types/home-owner.js +0 -37
  60. package/lib/types/tree-lock.d.ts +0 -54
  61. package/lib/types/tree-lock.js +0 -127
  62. package/lib/{ensure-BjToTMMj.js → ensure-C5Mo1dbB.js} +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-core",
3
3
  "description": "Shared stores, prompts, signals and lifecycle logic for the dsh-evolution plugin family (community build)",
4
- "version": "0.44.0",
4
+ "version": "0.45.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -54,7 +54,27 @@
54
54
  "./row-overrides.json": "./row-overrides.json",
55
55
  "./persisted-write-inventory.json": "./persisted-write-inventory.json",
56
56
  "./locale/*.json": "./locale/*.json",
57
- "./runtime/locale/*.json": "./locale/runtime/*.json"
57
+ "./runtime/locale/*.json": "./locale/runtime/*.json",
58
+ "./contract": {
59
+ "types": "./lib/types/contract.d.ts",
60
+ "default": "./lib/contract.js"
61
+ },
62
+ "./io-registry": {
63
+ "types": "./lib/types/io-registry.d.ts",
64
+ "default": "./lib/io-registry.js"
65
+ },
66
+ "./io-node": {
67
+ "types": "./lib/types/io-node.d.ts",
68
+ "default": "./lib/io-node.js"
69
+ },
70
+ "./authority-plugin": {
71
+ "types": "./lib/types/authority-plugin.d.ts",
72
+ "default": "./lib/authority-plugin.js"
73
+ },
74
+ "./policy": {
75
+ "types": "./lib/types/policy.d.ts",
76
+ "default": "./lib/policy.js"
77
+ }
58
78
  },
59
79
  "files": [
60
80
  "locale/runtime/*.json",
@@ -66,10 +86,11 @@
66
86
  ],
67
87
  "license": "MIT",
68
88
  "dependencies": {
89
+ "@deepseek-ai/dsh-atomic-write": "^0.2.2-rc.0",
90
+ "js-yaml": "^4.1.0",
69
91
  "yaml": "^2.4.2",
70
92
  "zod": "^4.4.3",
71
- "js-yaml": "^4.1.0",
72
- "@lmzhen/dsh-evolution-contract": "^0.44.0"
93
+ "@deepseek-ai/schemastery": "^3.18.5"
73
94
  },
74
95
  "peerDependencies": {
75
96
  "@deepseek-ai/cordis": "^4.0.5",
@@ -82,15 +82,6 @@
82
82
  "state": [],
83
83
  "note": "Durable memory documents written by the memory tool."
84
84
  },
85
- {
86
- "id": "state",
87
- "path": "<evolutionHome>/<review|curator|pending>-state.json",
88
- "writer": "evolution-state-json/src/index.ts",
89
- "serializedBy": "transact",
90
- "marker": "new WriteKernel({ io: io() }).run({ path: join(root, file)",
91
- "state": [],
92
- "note": "The durable state stack (review/curator/pending). S4.4/O-6 moved its three warn/rewrite sets into the provider instance (QuarantineMemory), so no module-scope N12 store remains here."
93
- },
94
85
  {
95
86
  "id": "curator-reports",
96
87
  "path": "<evolutionHome>/reports/curator-*.json",
@@ -134,16 +125,7 @@
134
125
  "serializedBy": "transact",
135
126
  "marker": "transactIo(io, path, task)",
136
127
  "state": [],
137
- "note": "The same activity sidecar through the authority-fence wrapper; the helper is the one transactIo call site."
138
- },
139
- {
140
- "id": "activity-log",
141
- "path": "<evolutionHome>/activity.json",
142
- "writer": "evolution-activity/src/index.ts",
143
- "serializedBy": "transact",
144
- "marker": "transactIo(io, activityFile(root)",
145
- "state": [],
146
- "note": "The plan-applied activity sidecar. Declared by v46 S1.12: the file carried a transactional write that no inventory row vouched for, and the N20 reverse scan is what named it."
128
+ "note": "Both activity events (plan-applied and review-completed) fold through this ONE fenced writer (W9/02-P1.3); the helper is the one transactIo call site."
147
129
  },
148
130
  {
149
131
  "id": "skill-history-index",
@@ -166,21 +148,12 @@
166
148
  {
167
149
  "id": "feedback-events",
168
150
  "path": "<evolutionHome>/events.json",
169
- "writer": "evolution-feedback/src/index.ts",
151
+ "writer": "evolution-activity/src/feedback/index.ts",
170
152
  "serializedBy": "transact",
171
153
  "marker": "transactIo(io, eventsPath,",
172
154
  "state": [],
173
155
  "note": "Feedback appends to the family event log under the cross-process lock. Declared by v46 S1.12 (N20 reverse). Shares ONE file with the \"events\" site (two writers, one log under the IO lock)."
174
156
  },
175
- {
176
- "id": "pending-archive",
177
- "path": "<evolutionHome>/pending-state-archive.json",
178
- "writer": "evolution-state-json/src/index.ts",
179
- "serializedBy": "transact",
180
- "marker": "transactIo(io(), pathOf(PENDING_ARCHIVE_FILE)",
181
- "state": [],
182
- "note": "The resolved-pending archive (the legacy merge target). The store already declared its record map; v46 S1.12 declared the archive append as well — the second site in one file is exactly what the reverse scan exists to find."
183
- },
184
157
  {
185
158
  "id": "merge-state",
186
159
  "path": "<evolutionHome>/merge/merge-state.json",
@@ -283,20 +256,20 @@
283
256
  {
284
257
  "id": "merge-tree-lock-acquire",
285
258
  "path": "<evolutionHome>/merge/.tree-lock",
286
- "writer": "evolution-core/src/tree-lock.ts",
287
- "serializedBy": "transact",
288
- "marker": "transactIo(io, path",
259
+ "writer": "evolution-core/src/authority.ts",
260
+ "serializedBy": "platform-file-lock",
261
+ "marker": "readFile(join(home, '.authority', 'home.lock')",
289
262
  "state": [],
290
- "note": "The cooperative merge/curator tree lock create/replace. Two processes must not both win; the transaction is the lock."
263
+ "note": "The home writer lock record (W9-authority): the platform withFileLock owns exclusion and the record is read for diagnostics and takeover checks."
291
264
  },
292
265
  {
293
266
  "id": "merge-tree-lock-release",
294
267
  "path": "<evolutionHome>/merge/.tree-lock",
295
- "writer": "evolution-core/src/tree-lock.ts",
296
- "serializedBy": "transact",
297
- "marker": "transactIo(options.io, path",
268
+ "writer": "evolution-core/src/authority.ts",
269
+ "serializedBy": "platform-file-lock",
270
+ "marker": "rm(lockPath",
298
271
  "state": [],
299
- "note": "The release half of the same lock: delete only when the recorded token still matches."
272
+ "note": "Stale-lock removal after a failed release (W9-authority): repair() only removes a lock whose holder is gone; the release itself is the platform lock."
300
273
  },
301
274
  {
302
275
  "id": "merge-pair-index",
@@ -1,4 +0,0 @@
1
- import type { EvolutionIoLike } from './io.ts';
2
- /** Fail loud when another live process already owns this DSH home. Single-host contract. */
3
- export declare function assertHomeOwner(io: EvolutionIoLike, home: string): Promise<void>;
4
- //# sourceMappingURL=home-owner.d.ts.map
@@ -1,37 +0,0 @@
1
- import { join } from 'node:path';
2
- const OWNER_FILE = '.evolution-owner.json';
3
- function isAlive(pid) {
4
- if (!Number.isInteger(pid) || pid <= 0)
5
- return false;
6
- try {
7
- process.kill(pid, 0);
8
- return true;
9
- }
10
- catch (error) {
11
- return error.code === 'EPERM';
12
- }
13
- }
14
- /** Fail loud when another live process already owns this DSH home. Single-host contract. */
15
- export async function assertHomeOwner(io, home) {
16
- const path = join(home, OWNER_FILE);
17
- const raw = await io.readText(path);
18
- if (raw !== null) {
19
- let record;
20
- try {
21
- const parsed = JSON.parse(raw);
22
- if (typeof parsed.pid !== 'number' || typeof parsed.startedAt !== 'string')
23
- throw new Error('bad owner record');
24
- record = { pid: parsed.pid, startedAt: parsed.startedAt };
25
- }
26
- catch {
27
- throw new Error('evolution home owner record is unreadable; refusing a second owner (' + path + ')');
28
- }
29
- if (record.pid === process.pid)
30
- return;
31
- if (isAlive(record.pid)) {
32
- throw new Error('evolution home is owned by another live process (pid ' + String(record.pid) + '); this deployment is single-host only');
33
- }
34
- }
35
- await io.writeText(path, JSON.stringify({ pid: process.pid, startedAt: new Date().toISOString() }));
36
- }
37
- //# sourceMappingURL=home-owner.js.map
@@ -1,54 +0,0 @@
1
- import type { EvolutionIoLike } from './io.ts';
2
- export interface TreeLockRecord {
3
- readonly token: string;
4
- readonly epoch: number;
5
- readonly pid: number;
6
- readonly startedAt: number;
7
- }
8
- export interface TreeLock {
9
- readonly token: string;
10
- readonly epoch: number;
11
- readonly path: string;
12
- readonly acquiredAt: number;
13
- release(): Promise<void>;
14
- assertHeld(): Promise<boolean>;
15
- }
16
- export type TreeLockAcquireResult = {
17
- readonly ok: true;
18
- readonly lock: TreeLock;
19
- } | {
20
- readonly ok: false;
21
- readonly reason: 'busy' | 'io';
22
- readonly holder?: TreeLockRecord;
23
- readonly message?: string;
24
- };
25
- export interface TreeLockOptions {
26
- readonly io: EvolutionIoLike;
27
- /** Evolution home; the lock lives at <home>/merge/.tree-lock. */
28
- readonly home: string;
29
- /** How long to wait for a busy lock. Default 5000 ms. */
30
- readonly waitMs?: number;
31
- /** Poll interval. Default 25 ms. */
32
- readonly pollMs?: number;
33
- readonly now?: () => number;
34
- readonly sleep?: (ms: number) => Promise<void>;
35
- }
36
- /** The one lock path. */
37
- export declare function treeLockFile(home: string): string;
38
- /** Read the current holder without creating or changing anything. */
39
- export declare function readTreeLock(io: EvolutionIoLike, home: string): Promise<TreeLockRecord | undefined>;
40
- /**
41
- * Acquire the tree write lock, waiting up to `waitMs`.
42
- *
43
- * A live holder is never stolen. A record whose pid is gone (or a corrupt record) is
44
- * taken over; that is how a killed process releases its lock without a timer.
45
- */
46
- export declare function acquireTreeWriteLock(options: TreeLockOptions): Promise<TreeLockAcquireResult>;
47
- /** Acquire, run, release; the lock is released even when the body throws. */
48
- export declare function withTreeWriteLock<T>(options: TreeLockOptions, body: (lock: TreeLock) => Promise<T>): Promise<{
49
- ok: true;
50
- value: T;
51
- } | Exclude<TreeLockAcquireResult, {
52
- ok: true;
53
- }>>;
54
- //# sourceMappingURL=tree-lock.d.ts.map
@@ -1,127 +0,0 @@
1
- /**
2
- * Tree write lock.
3
- *
4
- * The merge run holds this lock for its whole lifetime; curator's pass takes the same
5
- * lock. The record is created through `transactIo`, so exclusion is exactly as strong as
6
- * the IO backend's `transact`: the platform `ctx.fs` provider is cross-process, while the
7
- * standalone `nodeEvolutionIo` is explicitly single-process (G2 S4). This module builds no
8
- * file lock or WAL of its own. A holder whose pid is gone is stale and may be taken over;
9
- * a live pid is respected, even for a long run (a live long run is what the lock protects).
10
- *
11
- * `commitMerge` deliberately does NOT take this lock itself: the run shell owns it, so a
12
- * run and its commit share one acquisition. Taking it inside the store would also
13
- * deadlock the same-process curator path.
14
- */
15
- import { randomUUID } from 'node:crypto';
16
- import { join } from 'node:path';
17
- import { isProcessAlive, transactIo } from "./io.js";
18
- /** The one lock path. */
19
- export function treeLockFile(home) {
20
- return join(home, 'merge', '.tree-lock');
21
- }
22
- function parseLock(raw) {
23
- if (raw === null)
24
- return undefined;
25
- try {
26
- const value = JSON.parse(raw);
27
- if (typeof value.token !== 'string' || typeof value.pid !== 'number' || typeof value.startedAt !== 'number')
28
- return undefined;
29
- return { token: value.token, epoch: typeof value.epoch === 'number' ? value.epoch : 0, pid: value.pid, startedAt: value.startedAt };
30
- }
31
- catch {
32
- return undefined;
33
- }
34
- }
35
- const sleepDefault = (ms) => new Promise(resolve => setTimeout(resolve, ms));
36
- /** Read the current holder without creating or changing anything. */
37
- export async function readTreeLock(io, home) {
38
- return parseLock(await io.readText(treeLockFile(home)));
39
- }
40
- /** Try once. A stale record (dead pid or unparsable) is replaced. */
41
- async function tryAcquire(io, home, now) {
42
- const path = treeLockFile(home);
43
- let token;
44
- let epoch;
45
- let holder;
46
- await transactIo(io, path, (current) => {
47
- const existing = parseLock(current);
48
- if (existing !== undefined && isProcessAlive(existing.pid)) {
49
- holder = existing;
50
- return current;
51
- }
52
- // Absent, corrupt, our own stale row, or a dead owner: take it and bump the epoch.
53
- token = randomUUID();
54
- epoch = (existing?.epoch ?? 0) + 1;
55
- return JSON.stringify({ token, epoch, pid: process.pid, startedAt: now() });
56
- });
57
- return token === undefined ? (holder === undefined ? {} : { holder }) : { token, epoch: epoch ?? 0 };
58
- }
59
- /**
60
- * Acquire the tree write lock, waiting up to `waitMs`.
61
- *
62
- * A live holder is never stolen. A record whose pid is gone (or a corrupt record) is
63
- * taken over; that is how a killed process releases its lock without a timer.
64
- */
65
- export async function acquireTreeWriteLock(options) {
66
- const now = options.now ?? (() => Date.now());
67
- const waitMs = options.waitMs ?? 5_000;
68
- const pollMs = options.pollMs ?? 25;
69
- const sleep = options.sleep ?? sleepDefault;
70
- const deadline = now() + Math.max(0, waitMs);
71
- let lastHolder;
72
- try {
73
- for (;;) {
74
- const attempt = await tryAcquire(options.io, options.home, now);
75
- if (attempt.token !== undefined) {
76
- const token = attempt.token;
77
- const epoch = attempt.epoch ?? 0;
78
- const path = treeLockFile(options.home);
79
- let released = false;
80
- const lock = {
81
- token,
82
- epoch,
83
- path,
84
- acquiredAt: now(),
85
- async assertHeld() {
86
- const current = parseLock(await options.io.readText(path));
87
- return current?.token === token && current.epoch === epoch;
88
- },
89
- async release() {
90
- if (released)
91
- return;
92
- await transactIo(options.io, path, (current) => {
93
- const existing = parseLock(current);
94
- return existing?.token === token && existing.epoch === epoch ? null : current;
95
- });
96
- // Mark released only after the delete committed. Marking first made every retry a
97
- // silent no-op, so a transient unlink failure left the lock on disk while the
98
- // caller believed it was released.
99
- released = true;
100
- },
101
- };
102
- return { ok: true, lock };
103
- }
104
- lastHolder = attempt.holder;
105
- if (now() >= deadline)
106
- break;
107
- await sleep(pollMs);
108
- }
109
- return { ok: false, reason: 'busy', ...(lastHolder !== undefined ? { holder: lastHolder } : {}) };
110
- }
111
- catch (error) {
112
- return { ok: false, reason: 'io', message: error instanceof Error ? error.message : String(error) };
113
- }
114
- }
115
- /** Acquire, run, release; the lock is released even when the body throws. */
116
- export async function withTreeWriteLock(options, body) {
117
- const acquired = await acquireTreeWriteLock(options);
118
- if (!acquired.ok)
119
- return acquired;
120
- try {
121
- return { ok: true, value: await body(acquired.lock) };
122
- }
123
- finally {
124
- await acquired.lock.release();
125
- }
126
- }
127
- //# sourceMappingURL=tree-lock.js.map
@@ -1,7 +1,7 @@
1
1
  import { n as errorText } from "./errors-BxzLTVbS.js";
2
2
  import { t as presetsPort } from "./presets-C8vuCuNA.js";
3
- import { existsSync, readFileSync } from "node:fs";
4
3
  import { dirname, join } from "node:path";
4
+ import { existsSync, readFileSync } from "node:fs";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import * as yaml from "js-yaml";
7
7
  //#region lib/types/package-identity.js