@lmzhen/dsh-evolution-core 0.59.6 → 0.60.1

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 (103) hide show
  1. package/README.md +3 -1
  2. package/lib/authority-plugin.js +3 -2
  3. package/lib/composition/index.js +2 -2
  4. package/lib/{composition-B_F4TYOD.js → composition-BSqh70z_.js} +1 -1
  5. package/lib/{ensure-BpVDuDnA.js → ensure-DTCuxAxR.js} +1 -1
  6. package/lib/{extract-plan-D3ALlAmN.js → extract-plan-CP__XlEs.js} +2 -2
  7. package/lib/extract.js +4 -4
  8. package/lib/http-routes.js +3 -2
  9. package/lib/index.js +15 -15
  10. package/lib/{io-Cpa8wuvj.js → io-DT4-MXLr.js} +25 -1
  11. package/lib/io-node.js +1 -1
  12. package/lib/io-platform.js +163 -0
  13. package/lib/io-registry.js +10 -0
  14. package/lib/{mutation-authority-CZpc9F20.js → mutation-authority-C3RYyiaT.js} +66 -41
  15. package/lib/{mutation-storage-adapter-Cq1bmS1E.js → mutation-storage-adapter-CSVn34dK.js} +327 -210
  16. package/lib/{mutations-Y-wKod7W.js → mutations-JKFlfhSO.js} +1 -1
  17. package/lib/policy.js +1 -1
  18. package/lib/{quality-NPGr3VzA.js → quality-C0ri2SgY.js} +2 -2
  19. package/lib/restrictor.js +1 -1
  20. package/lib/result.js +1 -1
  21. package/lib/{review-context-yNiZadPw.js → review-context-D2LIOEi-.js} +2 -2
  22. package/lib/runtime/plugin.js +2 -2
  23. package/lib/{session-projection-DM15fsRp.js → session-projection-Dnmm5bzt.js} +1 -1
  24. package/lib/{skill-history-BvLWFoOo.js → skill-history-BOZ4HCDB.js} +2 -2
  25. package/lib/skills.js +268 -37
  26. package/lib/state/domain/index.js +433 -0
  27. package/lib/state/index.js +136 -0
  28. package/lib/state/migrate.js +90 -0
  29. package/lib/state/storage.js +605 -0
  30. package/lib/state/store-plugin.js +23 -0
  31. package/lib/state/store.js +268 -0
  32. package/lib/subagent/index.js +1 -1
  33. package/lib/types/authority-plugin.d.ts +1 -1
  34. package/lib/types/authority-plugin.js +2 -1
  35. package/lib/types/authority.d.ts +1 -1
  36. package/lib/types/authority.js +75 -48
  37. package/lib/types/composition/ensure.js +1 -1
  38. package/lib/types/contract.d.ts +8 -0
  39. package/lib/types/http-routes.d.ts +1 -0
  40. package/lib/types/http-routes.js +2 -1
  41. package/lib/types/io-platform.d.ts +74 -0
  42. package/lib/types/io-platform.js +178 -0
  43. package/lib/types/io-registry.d.ts +4 -0
  44. package/lib/types/io-registry.js +10 -0
  45. package/lib/types/io.d.ts +7 -0
  46. package/lib/types/io.js +25 -1
  47. package/lib/types/mutation-authority.d.ts +1 -1
  48. package/lib/types/mutation-storage-adapter.d.ts +1 -1
  49. package/lib/types/opt-in.js +2 -2
  50. package/lib/types/params.js +2 -2
  51. package/lib/types/policy.js +1 -1
  52. package/lib/types/restrictor.js +2 -2
  53. package/lib/types/result.d.ts +1 -1
  54. package/lib/types/result.js +1 -1
  55. package/lib/types/runtime/coherence.js +1 -1
  56. package/lib/types/runtime/llm.d.ts +1 -1
  57. package/lib/types/runtime/llm.js +1 -1
  58. package/lib/types/runtime/platform.d.ts +3 -3
  59. package/lib/types/runtime/platform.js +2 -2
  60. package/lib/types/runtime/projections.d.ts +1 -1
  61. package/lib/types/scope.js +1 -1
  62. package/lib/types/session-projection.d.ts +1 -1
  63. package/lib/types/signals.d.ts +1 -1
  64. package/lib/types/skill-store.d.ts +37 -4
  65. package/lib/types/skill-store.js +240 -24
  66. package/lib/types/skill-write-plan.d.ts +1 -1
  67. package/lib/types/skill-write-service.js +8 -2
  68. package/lib/types/state/conformance.d.ts +47 -0
  69. package/lib/types/state/conformance.js +246 -0
  70. package/lib/types/state/constants.d.ts +52 -0
  71. package/lib/types/state/constants.js +52 -0
  72. package/lib/types/state/domain/compatibility.d.ts +40 -0
  73. package/lib/types/state/domain/compatibility.js +36 -0
  74. package/lib/types/state/domain/index.d.ts +81 -0
  75. package/lib/types/state/domain/index.js +592 -0
  76. package/lib/types/state/index.d.ts +63 -0
  77. package/lib/types/state/index.js +174 -0
  78. package/lib/types/state/medium-declaration.d.ts +37 -0
  79. package/lib/types/state/medium-declaration.js +53 -0
  80. package/lib/types/state/migrate.d.ts +34 -0
  81. package/lib/types/state/migrate.js +103 -0
  82. package/lib/types/state/record-contract.d.ts +56 -0
  83. package/lib/types/state/record-contract.js +120 -0
  84. package/lib/types/state/storage.d.ts +112 -0
  85. package/lib/types/state/storage.js +178 -0
  86. package/lib/types/state/store-plugin.d.ts +14 -0
  87. package/lib/types/state/store-plugin.js +18 -0
  88. package/lib/types/state/store.d.ts +39 -0
  89. package/lib/types/state/store.js +270 -0
  90. package/lib/types/store-ledger.js +2 -2
  91. package/lib/types/subagent/run.d.ts +1 -1
  92. package/lib/types/subagent/types.d.ts +4 -4
  93. package/lib/types/{write-kernel.d.ts → target-writer.d.ts} +32 -15
  94. package/lib/types/{write-kernel.js → target-writer.js} +40 -8
  95. package/lib/types/tool-dispatch.js +6 -3
  96. package/lib/types/{mutation-unit.d.ts → unit-kernel.d.ts} +40 -13
  97. package/lib/types/{mutation-unit.js → unit-kernel.js} +155 -118
  98. package/lib/types/write.d.ts +1 -2
  99. package/lib/types/write.js +1 -2
  100. package/lib/{usage-D7yHG2Cb.js → usage-BO4Zj_zB.js} +2 -2
  101. package/lib/write.js +4 -4
  102. package/package.json +30 -3
  103. package/persisted-write-inventory.json +14 -5
@@ -2,7 +2,7 @@ import { basename, dirname, isAbsolute, join, relative } from 'node:path';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { isCommittedWarning, isProcessAlive, TransactionNotInvokedError, transactIo } from "./io.js";
4
4
  import { exceedsContentLimit } from "./frontmatter.js";
5
- import { WriteKernel } from "./write-kernel.js";
5
+ import { TargetWriter } from "./target-writer.js";
6
6
  function underRoot(rootDir, target) {
7
7
  if (rootDir === undefined || rootDir === '')
8
8
  return false;
@@ -94,7 +94,7 @@ const noLock = {
94
94
  },
95
95
  };
96
96
  const identitySerial = async (task) => await task();
97
- export class MutationUnit {
97
+ export class UnitKernel {
98
98
  io;
99
99
  limits;
100
100
  serial;
@@ -118,7 +118,7 @@ export class MutationUnit {
118
118
  this.limits = options.limits;
119
119
  this.serial = options.serial ?? identitySerial;
120
120
  if (options.lock === undefined && options.nested !== true) {
121
- throw new Error('mutation-unit: a lock (or an explicit nested:true under an outer fence) is required');
121
+ throw new Error('unit-kernel: a lock (or an explicit nested:true under an outer fence) is required');
122
122
  }
123
123
  this.lock = options.lock ?? noLock;
124
124
  this.targetKeys = options.targetKeys;
@@ -134,7 +134,7 @@ export class MutationUnit {
134
134
  this.now = options.now ?? Date.now;
135
135
  this.journalId = 'j-' + String(this.now()) + '-' + Math.random().toString(36).slice(2);
136
136
  const transact = options.transact;
137
- this.kernel = new WriteKernel({ io: this.io, ...(transact === undefined ? {} : { transact }), now: this.now });
137
+ this.kernel = new TargetWriter({ io: this.io, ...(transact === undefined ? {} : { transact }), now: this.now });
138
138
  }
139
139
  async resolveTargetKeys(keys) {
140
140
  if (keys === undefined || this.targetKeyResolver === undefined)
@@ -151,141 +151,173 @@ export class MutationUnit {
151
151
  errors: validation.errors,
152
152
  };
153
153
  }
154
- async apply(request) {
154
+ /**
155
+ * Phase 1: acquire the lease/claim and read every target, verifying CAS and
156
+ * write validation. This performs NO durable write (no journal, snapshot,
157
+ * audit or event). The returned handle holds the lease until commit() or
158
+ * release(); callers must use try/finally.
159
+ */
160
+ async prepare(request) {
155
161
  const primary = request.name.trim();
156
162
  const unitId = request.unitId ?? 'u-' + String(this.now()) + '-' + Math.random().toString(36).slice(2);
157
163
  const validation = validateMutationRequest(request, this.limits);
158
164
  if (!validation.ok)
159
165
  return { ok: false, unitId, dryRun: request.dryRun === true, changed: [], errors: validation.errors };
160
- if (request.dryRun === true)
161
- return { ok: true, unitId, dryRun: true, changed: [], errors: [] };
162
- return await this.serial(async () => {
163
- let lease;
166
+ let lease;
167
+ try {
168
+ lease = await this.lock.acquire(await this.resolveTargetKeys(this.targetKeys));
169
+ }
170
+ catch (error) {
171
+ const code = error instanceof TransactionNotInvokedError ? 'transact-not-invoked' : 'unit-fence-failed';
172
+ return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code, message: error instanceof Error ? error.message : String(error) }] };
173
+ }
174
+ let claim;
175
+ const release = async () => {
176
+ await claim?.release().catch(() => { });
177
+ await lease.release();
178
+ };
179
+ if (this.claim !== undefined) {
164
180
  try {
165
- lease = await this.lock.acquire(await this.resolveTargetKeys(this.targetKeys));
181
+ claim = await this.claim.acquire(primary, this.claimRunId ?? this.context?.runId ?? '');
166
182
  }
167
183
  catch (error) {
168
- const code = error instanceof TransactionNotInvokedError ? 'transact-not-invoked' : 'unit-fence-failed';
169
- return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code, message: error instanceof Error ? error.message : String(error) }] };
184
+ await lease.release();
185
+ return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code: 'claim-failed', message: error instanceof Error ? error.message : String(error) }] };
170
186
  }
171
- let claim;
172
- if (this.claim !== undefined) {
173
- try {
174
- claim = await this.claim.acquire(primary, this.claimRunId ?? this.context?.runId ?? '');
187
+ }
188
+ const snapshots = [];
189
+ try {
190
+ for (const op of validation.ops) {
191
+ const current = await this.io.readText(op.target);
192
+ const baseline = op.expected === undefined ? current : op.expected;
193
+ if (current !== baseline) {
194
+ await release();
195
+ return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code: 'cas-drift', message: 'target changed after plan', target: op.target }] };
175
196
  }
176
- catch (error) {
177
- await lease.release();
178
- return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code: 'claim-failed', message: error instanceof Error ? error.message : String(error) }] };
197
+ snapshots.push({ target: op.target, before: current, after: op.kind === 'write' ? op.content : null, baseline });
198
+ }
199
+ for (const op of validation.ops) {
200
+ const refusal = this.validateWrite?.(op) ?? null;
201
+ if (refusal !== null) {
202
+ await release();
203
+ return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code: 'write-validation', message: refusal, target: op.target }] };
179
204
  }
180
205
  }
181
- const changed = [];
182
- const warnings = [];
183
- const bestEffort = async (task) => {
206
+ }
207
+ catch (error) {
208
+ await release();
209
+ return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code: 'write-failed', message: error instanceof Error ? error.message : String(error) }] };
210
+ }
211
+ const eventOps = snapshots.map(snapshot => {
212
+ const op = validation.ops.find(entry => entry.target === snapshot.target);
213
+ return {
214
+ target: snapshot.target,
215
+ before: snapshot.before,
216
+ after: op?.kind === 'write' ? op.content : null,
217
+ ...(op?.skill === undefined ? {} : { skill: op.skill }),
218
+ };
219
+ });
220
+ const changed = [];
221
+ const warnings = [];
222
+ const bestEffort = async (task) => {
223
+ try {
224
+ await task();
225
+ }
226
+ catch (error) {
227
+ if (!isCommittedWarning(error))
228
+ throw error;
229
+ warnings.push(error instanceof Error ? error.message : String(error));
230
+ }
231
+ };
232
+ return { kind: 'prepared', unitId, request, primary, validation, snapshots, eventOps, changed, warnings, bestEffort, release };
233
+ }
234
+ /** Phase 2: the only durable write phase. Releases the prepare lease in all paths. */
235
+ async commit(prepared) {
236
+ const { unitId, request, primary, validation, snapshots, eventOps, changed, warnings, bestEffort } = prepared;
237
+ const cleanup = request.cleanupPaths === undefined ? {} : { cleanup: request.cleanupPaths };
238
+ try {
239
+ if (this.snapshots !== undefined)
240
+ await bestEffort(() => this.snapshots.write({ unitId, journalId: this.journalId, state: 'prepared', ops: eventOps, ...cleanup, createdAt: this.now(), ...this.contextFields() }));
241
+ await bestEffort(async () => this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'prepared', changed: [], target: validation.roots.find(root => root.name === primary)?.name ?? primary, roots: validation.roots.map(root => root.name) }));
242
+ for (const op of validation.ops) {
243
+ const snapshot = snapshots.find(entry => entry.target === op.target);
244
+ if (snapshot === undefined)
245
+ throw new Error('snapshot missing for ' + op.target);
184
246
  try {
185
- await task();
247
+ const opWarnings = await this.applyOp(op, snapshot.baseline);
248
+ warnings.push(...opWarnings);
249
+ changed.push(op.target);
186
250
  }
187
251
  catch (error) {
252
+ if (error?.noWrite !== true)
253
+ changed.push(op.target);
188
254
  if (!isCommittedWarning(error))
189
255
  throw error;
190
256
  warnings.push(error instanceof Error ? error.message : String(error));
191
257
  }
192
- };
193
- const snapshots = [];
258
+ }
259
+ await bestEffort(async () => this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'unit-written', changed, target: primary, roots: validation.roots.map(root => root.name) }));
260
+ if (this.snapshots !== undefined)
261
+ await bestEffort(() => this.snapshots.write({ unitId, journalId: this.journalId, state: 'committed', ops: eventOps, ...cleanup, createdAt: this.now(), ...this.contextFields() }));
262
+ await bestEffort(async () => this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'committed', changed, target: primary, roots: validation.roots.map(root => root.name) }));
194
263
  try {
195
- for (const op of validation.ops) {
196
- const current = await this.io.readText(op.target);
197
- const baseline = op.expected === undefined ? current : op.expected;
198
- if (current !== baseline) {
199
- return { ok: false, unitId, dryRun: false, changed, errors: [{ code: 'cas-drift', message: 'target changed after plan', target: op.target }] };
200
- }
201
- snapshots.push({ target: op.target, before: current, after: op.kind === 'write' ? op.content : null, baseline });
202
- }
203
- for (const op of validation.ops) {
204
- const refusal = this.validateWrite?.(op) ?? null;
205
- if (refusal !== null)
206
- return { ok: false, unitId, dryRun: false, changed: [], errors: [{ code: 'write-validation', message: refusal, target: op.target }] };
207
- }
208
- const eventOps = snapshots.map(snapshot => {
209
- const op = validation.ops.find(entry => entry.target === snapshot.target);
210
- return {
211
- target: snapshot.target,
212
- before: snapshot.before,
213
- after: op?.kind === 'write' ? op.content : null,
214
- ...(op?.skill === undefined ? {} : { skill: op.skill }),
215
- };
216
- });
217
- const cleanup = request.cleanupPaths === undefined ? {} : { cleanup: request.cleanupPaths };
218
- if (this.snapshots !== undefined)
219
- await bestEffort(() => this.snapshots.write({ unitId, journalId: this.journalId, state: 'prepared', ops: eventOps, ...cleanup, createdAt: this.now(), ...this.contextFields() }));
220
- await bestEffort(async () => this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'prepared', changed: [], target: validation.roots.find(root => root.name === primary)?.name ?? primary, roots: validation.roots.map(root => root.name) }));
221
- for (const op of validation.ops) {
222
- const snapshot = snapshots.find(entry => entry.target === op.target);
223
- if (snapshot === undefined)
224
- throw new Error('snapshot missing for ' + op.target);
225
- try {
226
- const opWarnings = await this.applyOp(op, snapshot.baseline);
227
- warnings.push(...opWarnings);
228
- changed.push(op.target);
229
- }
230
- catch (error) {
231
- if (error?.noWrite !== true)
232
- changed.push(op.target);
233
- if (!isCommittedWarning(error))
234
- throw error;
235
- warnings.push(error instanceof Error ? error.message : String(error));
236
- }
237
- }
238
- await bestEffort(async () => this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'unit-written', changed, target: primary, roots: validation.roots.map(root => root.name) }));
239
- // P2-1: the committed snapshot is the recovery authority. Write it BEFORE the journal's
240
- // committed phase so a crash in this window recovers as committed, never rolled back.
241
- if (this.snapshots !== undefined)
242
- await bestEffort(() => this.snapshots.write({ unitId, journalId: this.journalId, state: 'committed', ops: eventOps, ...cleanup, createdAt: this.now(), ...this.contextFields() }));
243
- await bestEffort(async () => this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'committed', changed, target: primary, roots: validation.roots.map(root => root.name) }));
244
- try {
245
- await this.hooks?.committed?.({ unitId, changed, ops: eventOps, roots: validation.roots.map(root => root.name) });
246
- }
247
- catch {
248
- // Hooks are audit/history/event side effects; a completed write must not be rolled back by one.
249
- }
250
- return { ok: true, unitId, dryRun: false, changed, errors: [], ...(warnings.length === 0 ? {} : { warnings }) };
264
+ await this.hooks?.committed?.({ unitId, changed, ops: eventOps, roots: validation.roots.map(root => root.name) });
251
265
  }
252
- catch (error) {
253
- const message = error instanceof Error ? error.message : String(error);
254
- let rollbackFailure = '';
255
- try {
256
- await this.rollback(snapshots.filter(snapshot => changed.includes(snapshot.target)));
257
- }
258
- catch (rollbackError) {
259
- rollbackFailure = rollbackError instanceof Error ? rollbackError.message : String(rollbackError);
260
- }
261
- const detail = rollbackFailure === '' ? message : message + '; rollback failed: ' + rollbackFailure;
262
- const failureCode = error?.code === 'transact-not-invoked' ? 'transact-not-invoked' : 'write-failed';
263
- await this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'failed', changed, error: detail });
264
- try {
265
- await this.hooks?.rolledBack?.({
266
- unitId,
267
- changed,
268
- ops: snapshots.map(snapshot => {
269
- const op = validation.ops.find(entry => entry.target === snapshot.target);
270
- return {
271
- target: snapshot.target,
272
- before: snapshot.before,
273
- after: op?.kind === 'write' ? op.content : null,
274
- ...(op?.skill === undefined ? {} : { skill: op.skill }),
275
- };
276
- }),
277
- roots: validation.roots.map(root => root.name),
278
- });
279
- }
280
- catch {
281
- // best-effort hook; the structured write error remains authoritative
282
- }
283
- return { ok: false, unitId, dryRun: false, changed, errors: [{ code: failureCode, message: detail }] };
266
+ catch {
267
+ // Hooks are audit/history/event side effects; a completed write must not be rolled back by one.
284
268
  }
285
- finally {
286
- await claim?.release().catch(() => { });
287
- await lease.release();
269
+ return { ok: true, unitId, dryRun: false, changed, errors: [], ...(warnings.length === 0 ? {} : { warnings }) };
270
+ }
271
+ catch (error) {
272
+ const message = error instanceof Error ? error.message : String(error);
273
+ let rollbackFailure = '';
274
+ try {
275
+ await this.rollback(snapshots.filter(snapshot => changed.includes(snapshot.target)));
276
+ }
277
+ catch (rollbackError) {
278
+ rollbackFailure = rollbackError instanceof Error ? rollbackError.message : String(rollbackError);
279
+ }
280
+ const detail = rollbackFailure === '' ? message : message + '; rollback failed: ' + rollbackFailure;
281
+ const failureCode = error?.code === 'transact-not-invoked' ? 'transact-not-invoked' : 'write-failed';
282
+ await this.journal?.write({ unitId, journalId: this.journalId, ...(this.context?.runId === undefined ? {} : { runId: this.context.runId }), phase: 'failed', changed, error: detail });
283
+ try {
284
+ await this.hooks?.rolledBack?.({
285
+ unitId,
286
+ changed,
287
+ ops: snapshots.map(snapshot => {
288
+ const op = validation.ops.find(entry => entry.target === snapshot.target);
289
+ return {
290
+ target: snapshot.target,
291
+ before: snapshot.before,
292
+ after: op?.kind === 'write' ? op.content : null,
293
+ ...(op?.skill === undefined ? {} : { skill: op.skill }),
294
+ };
295
+ }),
296
+ roots: validation.roots.map(root => root.name),
297
+ });
298
+ }
299
+ catch {
300
+ // best-effort hook; the structured write error remains authoritative
288
301
  }
302
+ return { ok: false, unitId, dryRun: false, changed, errors: [{ code: failureCode, message: detail }] };
303
+ }
304
+ finally {
305
+ await prepared.release();
306
+ }
307
+ }
308
+ async apply(request) {
309
+ if (request.dryRun === true) {
310
+ const unitId = request.unitId ?? 'u-' + String(this.now()) + '-' + Math.random().toString(36).slice(2);
311
+ const validation = validateMutationRequest(request, this.limits);
312
+ return validation.ok
313
+ ? { ok: true, unitId, dryRun: true, changed: [], errors: [] }
314
+ : { ok: false, unitId, dryRun: true, changed: [], errors: validation.errors };
315
+ }
316
+ return await this.serial(async () => {
317
+ const prepared = await this.prepare(request);
318
+ if (prepared.kind !== 'prepared')
319
+ return prepared;
320
+ return await this.commit(prepared);
289
321
  });
290
322
  }
291
323
  /** Recover every prepared snapshot known to the port; safe to call at boot. */
@@ -429,11 +461,16 @@ export class MutationUnit {
429
461
  return [...(result.warnings ?? [])];
430
462
  }
431
463
  async rollback(snapshots) {
464
+ // A5: one blocked target must not stop compensation of the others. A later target whose bytes
465
+ // still match this unit is restorable; only the blocked one is left for the prepared snapshot.
466
+ const errors = [];
432
467
  for (const snapshot of [...snapshots].reverse()) {
433
468
  const result = await this.kernel.restore({ path: snapshot.target, before: snapshot.before, after: snapshot.after });
434
469
  if (!result.ok)
435
- throw new Error(result.errors[0]?.message ?? 'rollback failed: ' + snapshot.target);
470
+ errors.push(snapshot.target + ': ' + (result.errors[0]?.message ?? 'rollback failed'));
436
471
  }
472
+ if (errors.length > 0)
473
+ throw new Error('rollback incomplete: ' + errors.join('; '));
437
474
  }
438
475
  }
439
476
  function parseFileLock(raw) {
@@ -498,4 +535,4 @@ export function fileMutationLock(io, root, options = {}) {
498
535
  },
499
536
  };
500
537
  }
501
- //# sourceMappingURL=mutation-unit.js.map
538
+ //# sourceMappingURL=unit-kernel.js.map
@@ -1,6 +1,5 @@
1
1
  /** The one byte-write engine surface. Consumers must import it from the documented subpath. */
2
- export * from './write-kernel.ts';
3
- export * from './mutation-unit.ts';
2
+ export * from './unit-kernel.ts';
4
3
  export * from './mutation-storage-adapter.ts';
5
4
  export * from './unit-claim.ts';
6
5
  export * from './unit-journal.ts';
@@ -1,6 +1,5 @@
1
1
  /** The one byte-write engine surface. Consumers must import it from the documented subpath. */
2
- export * from "./write-kernel.js";
3
- export * from "./mutation-unit.js";
2
+ export * from "./unit-kernel.js";
4
3
  export * from "./mutation-storage-adapter.js";
5
4
  export * from "./unit-claim.js";
6
5
  export * from "./unit-journal.js";
@@ -1,7 +1,7 @@
1
- import { c as transactIo, o as nodeEvolutionIo } from "./io-Cpa8wuvj.js";
1
+ import { c as transactIo, o as nodeEvolutionIo } from "./io-DT4-MXLr.js";
2
2
  import { o as resolveCitations } from "./citations-CZKTUGQF.js";
3
3
  import { n as isRecord } from "./guards-3f02mnf2.js";
4
- import { p as parseFrontmatter, u as frontmatterBlock } from "./mutations-Y-wKod7W.js";
4
+ import { p as parseFrontmatter, u as frontmatterBlock } from "./mutations-JKFlfhSO.js";
5
5
  import { join } from "node:path";
6
6
  //#region lib/types/reference-rewrite.js
7
7
  /**
package/lib/write.js CHANGED
@@ -1,6 +1,6 @@
1
- import { r as contentHash } from "./mutations-Y-wKod7W.js";
2
- import { p as entryTarget } from "./skill-history-BvLWFoOo.js";
3
- import { C as writeUnitEvidence, D as fileMutationLock, E as MutationUnit, O as validateMutationRequest, S as upsertUnitIndex, T as writeUnitSnapshot, _ as unitIndexPath, a as UNIT_JOURNAL_SCHEMA_VERSION, b as unitSnapshotsDir, c as unitJournalPath, d as UNIT_STORAGE_SCHEMA_VERSION, f as readUnitEvidence, g as unitEvidencePath, h as readUnitSnapshot, i as UNIT_JOURNAL_PHASES, k as WriteKernel, l as unitJournalPhaseRank, m as readUnitReceipt, n as unitJournalPort, o as assertUnitJournalTransition, p as readUnitIndex, r as unitSnapshotPort, s as readUnitJournal, t as pruneTreeChangeUnits, u as writeUnitJournal, v as unitReceiptPath, w as writeUnitReceipt, x as unitStorageKey, y as unitSnapshotPath } from "./mutation-storage-adapter-Cq1bmS1E.js";
1
+ import { r as contentHash } from "./mutations-JKFlfhSO.js";
2
+ import { p as entryTarget } from "./skill-history-BOZ4HCDB.js";
3
+ import { C as writeUnitEvidence, D as fileMutationLock, E as UnitKernel, O as validateMutationRequest, S as upsertUnitIndex, T as writeUnitSnapshot, _ as unitIndexPath, a as UNIT_JOURNAL_SCHEMA_VERSION, b as unitSnapshotsDir, c as unitJournalPath, d as UNIT_STORAGE_SCHEMA_VERSION, f as readUnitEvidence, g as unitEvidencePath, h as readUnitSnapshot, i as UNIT_JOURNAL_PHASES, l as unitJournalPhaseRank, m as readUnitReceipt, n as unitJournalPort, o as assertUnitJournalTransition, p as readUnitIndex, r as unitSnapshotPort, s as readUnitJournal, t as pruneTreeChangeUnits, u as writeUnitJournal, v as unitReceiptPath, w as writeUnitReceipt, x as unitStorageKey, y as unitSnapshotPath } from "./mutation-storage-adapter-CSVn34dK.js";
4
4
  //#region lib/types/unit-undo.js
5
5
  /**
6
6
  * Cross-skill unit undo executor.
@@ -355,4 +355,4 @@ function staleRouteStubs(indexes) {
355
355
  return out.sort((a, b) => a.skill.localeCompare(b.skill) || a.v - b.v || a.owner.localeCompare(b.owner));
356
356
  }
357
357
  //#endregion
358
- export { MutationUnit, UNIT_JOURNAL_PHASES, UNIT_JOURNAL_SCHEMA_VERSION, UNIT_STORAGE_SCHEMA_VERSION, WriteKernel, assertUnitJournalTransition, candidateSkills, executeUnitUndo, fileMutationLock, isLandmark, landmarkVerdict, planUnitUndoAcross, pruneTreeChangeUnits, readUnitEvidence, readUnitIndex, readUnitJournal, readUnitReceipt, readUnitSnapshot, resolveUnitMembers, resolveUnitMembersFromIndexes, staleRouteStubs, unitEvidencePath, unitIndexPath, unitJournalPath, unitJournalPhaseRank, unitJournalPort, unitMembersAreComplete, unitReceiptPath, unitSnapshotPath, unitSnapshotPort, unitSnapshotsDir, unitStorageKey, upsertUnitIndex, validateMutationRequest, writeUnitEvidence, writeUnitJournal, writeUnitReceipt, writeUnitSnapshot };
358
+ export { UNIT_JOURNAL_PHASES, UNIT_JOURNAL_SCHEMA_VERSION, UNIT_STORAGE_SCHEMA_VERSION, UnitKernel, assertUnitJournalTransition, candidateSkills, executeUnitUndo, fileMutationLock, isLandmark, landmarkVerdict, planUnitUndoAcross, pruneTreeChangeUnits, readUnitEvidence, readUnitIndex, readUnitJournal, readUnitReceipt, readUnitSnapshot, resolveUnitMembers, resolveUnitMembersFromIndexes, staleRouteStubs, unitEvidencePath, unitIndexPath, unitJournalPath, unitJournalPhaseRank, unitJournalPort, unitMembersAreComplete, unitReceiptPath, unitSnapshotPath, unitSnapshotPort, unitSnapshotsDir, unitStorageKey, upsertUnitIndex, validateMutationRequest, writeUnitEvidence, writeUnitJournal, writeUnitReceipt, writeUnitSnapshot };
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.59.6",
4
+ "version": "0.60.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -75,6 +75,10 @@
75
75
  "types": "./lib/types/io-node.d.ts",
76
76
  "default": "./lib/io-node.js"
77
77
  },
78
+ "./io-platform": {
79
+ "types": "./lib/types/io-platform.d.ts",
80
+ "default": "./lib/io-platform.js"
81
+ },
78
82
  "./authority-plugin": {
79
83
  "types": "./lib/types/authority-plugin.d.ts",
80
84
  "default": "./lib/authority-plugin.js"
@@ -82,6 +86,30 @@
82
86
  "./policy": {
83
87
  "types": "./lib/types/policy.d.ts",
84
88
  "default": "./lib/policy.js"
89
+ },
90
+ "./state": {
91
+ "types": "./lib/types/state/index.d.ts",
92
+ "default": "./lib/state/index.js"
93
+ },
94
+ "./state/storage": {
95
+ "types": "./lib/types/state/storage.d.ts",
96
+ "default": "./lib/state/storage.js"
97
+ },
98
+ "./state/domain": {
99
+ "types": "./lib/types/state/domain/index.d.ts",
100
+ "default": "./lib/state/domain/index.js"
101
+ },
102
+ "./state/store": {
103
+ "types": "./lib/types/state/store.d.ts",
104
+ "default": "./lib/state/store.js"
105
+ },
106
+ "./state/migrate": {
107
+ "types": "./lib/types/state/migrate.d.ts",
108
+ "default": "./lib/state/migrate.js"
109
+ },
110
+ "./state/store-plugin": {
111
+ "types": "./lib/types/state/store-plugin.d.ts",
112
+ "default": "./lib/state/store-plugin.js"
85
113
  }
86
114
  },
87
115
  "files": [
@@ -98,8 +126,7 @@
98
126
  "yaml": "^2.4.2",
99
127
  "zod": "^4.4.3",
100
128
  "@deepseek-ai/schemastery": "^3.18.5",
101
- "@lmzhen/dsh-evolution-adapter": "0.59.6",
102
- "@lmzhen/dsh-evolution-platform-contract": "0.59.6"
129
+ "@lmzhen/dsh-evolution-platform": "0.60.1"
103
130
  },
104
131
  "peerDependencies": {
105
132
  "@deepseek-ai/cordis": "^4.0.5"
@@ -317,18 +317,18 @@
317
317
  "note": "Lease acquire/heartbeat/release all use transactIo now: the old private fallback did not tolerate a committed-fsync warning, so acquire could report failure after the active lease had landed."
318
318
  },
319
319
  {
320
- "id": "write-kernel-run",
320
+ "id": "unit-kernel-run",
321
321
  "path": "<evolutionHome>/units/**",
322
- "writer": "evolution-core/src/write-kernel.ts",
322
+ "writer": "evolution-core/src/target-writer.ts",
323
323
  "serializedBy": "transact",
324
324
  "marker": "transactIo(this.io, target.path, invoke)",
325
325
  "state": [],
326
326
  "note": "Run/task path: the kernel no longer carries its own direct-write fallback; transactIo is the one seam and reports a typed not-invoked error."
327
327
  },
328
328
  {
329
- "id": "write-kernel-write-one",
329
+ "id": "unit-kernel-write-one",
330
330
  "path": "<evolutionHome>/units/**",
331
- "writer": "evolution-core/src/write-kernel.ts",
331
+ "writer": "evolution-core/src/target-writer.ts",
332
332
  "serializedBy": "transact",
333
333
  "marker": "transactIo(this.io, target.path, task)",
334
334
  "state": [],
@@ -337,11 +337,20 @@
337
337
  {
338
338
  "id": "mutation-lock",
339
339
  "path": "<evolutionHome>/.mutation-lock",
340
- "writer": "evolution-core/src/mutation-unit.ts",
340
+ "writer": "evolution-core/src/unit-kernel.ts",
341
341
  "serializedBy": "transact",
342
342
  "marker": "transactIo(io, path, task)",
343
343
  "state": [],
344
344
  "note": "fileMutationLock updates the lock record through transactIo; no private direct-write fallback remains."
345
+ },
346
+ {
347
+ "id": "state-store",
348
+ "path": "<evolutionHome>/state/store.json",
349
+ "writer": "evolution-core/src/state/store.ts",
350
+ "serializedBy": "transact",
351
+ "marker": "transactIo(io, file",
352
+ "state": [],
353
+ "note": "File-backed StateStore provider (D1a, not mounted yet): every mutation is one transactIo read-modify-write; no process-local authority."
345
354
  }
346
355
  ]
347
356
  }