@lmzhen/dsh-evolution-core 0.47.0 → 0.49.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 (60) hide show
  1. package/lib/authority-plugin.js +1 -1
  2. package/lib/index.js +27 -136
  3. package/lib/{io-BCBSr6Ot.js → io-GxghO3Ip.js} +30 -8
  4. package/lib/io-node.js +1 -1
  5. package/lib/io-registry.js +1 -20
  6. package/lib/{mutation-authority-CM6wRgyK.js → mutation-authority-l57R626O.js} +14 -2
  7. package/lib/{mutations-DihgpfgG.js → mutations-DQXddSJd.js} +1 -1
  8. package/lib/{numeric-DLeLvvGb.js → numeric-D8js3sqC.js} +1 -5
  9. package/lib/platform/index.js +1 -1
  10. package/lib/{platform-CFA12Jam.js → platform-Cc9cNt5j.js} +4 -28
  11. package/lib/policy.js +1 -1
  12. package/lib/runtime/plugin.js +21 -43
  13. package/lib/{session-projection-BhlDXqws.js → session-projection-DSXnUNZG.js} +1 -19
  14. package/lib/{skill-health-BzkUQDi7.js → skill-health-DP8z9TPf.js} +3 -3
  15. package/lib/{skill-history-RWt1-kbZ.js → skill-history-CxrDE3Rb.js} +43 -51
  16. package/lib/skills.js +165 -183
  17. package/lib/types/authority.d.ts +2 -0
  18. package/lib/types/authority.js +5 -0
  19. package/lib/types/constants.d.ts +0 -4
  20. package/lib/types/constants.js +0 -4
  21. package/lib/types/contract.d.ts +0 -5
  22. package/lib/types/health-baseline.d.ts +0 -13
  23. package/lib/types/health-baseline.js +0 -20
  24. package/lib/types/home-fence.d.ts +2 -0
  25. package/lib/types/home-fence.js +11 -1
  26. package/lib/types/io-registry.d.ts +0 -16
  27. package/lib/types/io-registry.js +0 -24
  28. package/lib/types/io.d.ts +6 -1
  29. package/lib/types/io.js +35 -9
  30. package/lib/types/long-runs.d.ts +0 -5
  31. package/lib/types/long-runs.js +0 -7
  32. package/lib/types/memory-store.js +13 -5
  33. package/lib/types/mutation-authority.js +5 -0
  34. package/lib/types/mutation-unit.d.ts +1 -1
  35. package/lib/types/mutation-unit.js +9 -27
  36. package/lib/types/params.d.ts +11 -29
  37. package/lib/types/params.js +13 -60
  38. package/lib/types/platform/llm.d.ts +2 -3
  39. package/lib/types/platform/llm.js +3 -10
  40. package/lib/types/platform/projections.d.ts +4 -5
  41. package/lib/types/platform/projections.js +4 -18
  42. package/lib/types/runtime/llm.js +2 -2
  43. package/lib/types/runtime/platform.d.ts +7 -11
  44. package/lib/types/runtime/platform.js +13 -19
  45. package/lib/types/runtime/plugin.d.ts +1 -1
  46. package/lib/types/runtime/plugin.js +6 -4
  47. package/lib/types/runtime/projections.js +1 -2
  48. package/lib/types/skill-health.d.ts +29 -1
  49. package/lib/types/skill-store.d.ts +6 -0
  50. package/lib/types/skill-store.js +130 -142
  51. package/lib/types/tool-dispatch.d.ts +1 -16
  52. package/lib/types/tool-dispatch.js +0 -18
  53. package/lib/types/unit-journal.js +19 -12
  54. package/lib/types/write-inventory.d.ts +0 -15
  55. package/lib/types/write-inventory.js +0 -25
  56. package/lib/types/write-kernel.d.ts +3 -4
  57. package/lib/types/write-kernel.js +13 -25
  58. package/lib/write.js +2 -2
  59. package/package.json +1 -1
  60. package/persisted-write-inventory.json +31 -13
@@ -346,7 +346,6 @@ export function isSkillReadToolName(name) {
346
346
  return SKILL_READ_TOOL_NAMES.has(name);
347
347
  }
348
348
  /** Tool names whose dispatch opens a code program, i.e. whose sub-dispatches are \`program\`. */
349
- const PROGRAM_TOOL_NAMES = new Set(['run_code']);
350
349
  /**
351
350
  * Does this signal read one skill, and did it not fail?
352
351
  * @param signal - a normalized dispatch.
@@ -510,14 +509,6 @@ const SKILL_TOOL_NAMES = new Set([...SKILL_READ_TOOL_NAMES, 'skill_manage']);
510
509
  export function isSkillToolName(name) {
511
510
  return SKILL_TOOL_NAMES.has(name);
512
511
  }
513
- /**
514
- * Does this dispatched tool name open a code program?
515
- * @param name - the dispatched tool name.
516
- * @returns \`true\` for the tool whose sub-dispatches are \`program\` kind.
517
- */
518
- export function isProgramToolName(name) {
519
- return PROGRAM_TOOL_NAMES.has(name);
520
- }
521
512
  /**
522
513
  * Assert that a payload really is the dispatch event it claims to be.
523
514
  *
@@ -554,13 +545,4 @@ export function assertDispatchPayload(event) {
554
545
  return;
555
546
  throw new ToolDispatchPayloadError(`${event.type} is not a platform dispatch event; compare signal.kind instead of event types`);
556
547
  }
557
- /**
558
- * Total dispatches in a log, deduplicated.
559
- * @param events - the log, oldest first.
560
- * @returns the number of distinct dispatches, one per dispatch regardless of
561
- * how many events carried it.
562
- */
563
- export function countDispatches(events) {
564
- return foldToolDispatches(events).length;
565
- }
566
548
  //# sourceMappingURL=tool-dispatch.js.map
@@ -35,18 +35,7 @@ export function assertUnitJournalTransition(from, to) {
35
35
  if (unitJournalPhaseRank(to) <= unitJournalPhaseRank(from))
36
36
  throw new Error('unit-journal-nonmonotonic:' + from + '->' + to);
37
37
  }
38
- export async function writeUnitJournal(io, home, journal, scope = 'merge') {
39
- const key = journal.journalId ?? journal.unitId;
40
- const path = unitJournalPath(home, key, scope);
41
- const existing = await readUnitJournal(io, home, key, scope);
42
- if (existing !== null)
43
- assertUnitJournalTransition(existing.phase, journal.phase);
44
- const content = JSON.stringify(journal, null, 2) + '\n';
45
- await transactIo(io, path, () => content);
46
- return path;
47
- }
48
- export async function readUnitJournal(io, home, unitId, scope = 'merge') {
49
- const raw = await io.readText(unitJournalPath(home, unitId, scope));
38
+ function parseUnitJournal(raw) {
50
39
  if (raw === null)
51
40
  return null;
52
41
  try {
@@ -56,4 +45,22 @@ export async function readUnitJournal(io, home, unitId, scope = 'merge') {
56
45
  return null;
57
46
  }
58
47
  }
48
+ export async function writeUnitJournal(io, home, journal, scope = 'merge') {
49
+ const key = journal.journalId ?? journal.unitId;
50
+ const path = unitJournalPath(home, key, scope);
51
+ const content = JSON.stringify(journal, null, 2) + '\n';
52
+ // The read and the monotonicity assertion share the write's critical section; reading them
53
+ // outside transact left a window where two writers both validated the old phase and the
54
+ // slower one silently overwrote a committed journal.
55
+ await transactIo(io, path, (current) => {
56
+ const existing = parseUnitJournal(current);
57
+ if (existing !== null)
58
+ assertUnitJournalTransition(existing.phase, journal.phase);
59
+ return content;
60
+ });
61
+ return path;
62
+ }
63
+ export async function readUnitJournal(io, home, unitId, scope = 'merge') {
64
+ return parseUnitJournal(await io.readText(unitJournalPath(home, unitId, scope)));
65
+ }
59
66
  //# sourceMappingURL=unit-journal.js.map
@@ -70,20 +70,5 @@ export declare const INSTANCE_KEYS: {
70
70
  * @returns the sites, in file order.
71
71
  */
72
72
  export declare function persistedWriteSites(): readonly PersistedWriteSite[];
73
- /** The inventory's symbol legend — the roots every declared path is written against, with the
74
- * segments the gate checks against the resolver's source.
75
- * @internal no production caller — the gates read the JSON asset directly. */
76
- export declare function writePathSymbols(): Readonly<Record<string, WritePathSymbol>>;
77
- /** Sites serialized by the per-home instance claim, with their instance keys.
78
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
79
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
80
- export declare function instanceClaimedWriteSites(): readonly (PersistedWriteSite & {
81
- readonly instance: string;
82
- })[];
83
- /** One declared site by id. An undeclared id throws — a stale caller must fail
84
- * loud rather than read "nothing is declared".
85
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
86
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
87
- export declare function persistedWriteSite(id: string): PersistedWriteSite;
88
73
  export {};
89
74
  //# sourceMappingURL=write-inventory.d.ts.map
@@ -103,7 +103,6 @@ export const INSTANCE_KEYS = {
103
103
  // Both caches are READONLY on purpose: the table's own shape is readonly, and copying it into a
104
104
  // mutable array would be a second source of truth for the same rows.
105
105
  let cachedSites;
106
- let cachedSymbols;
107
106
  /**
108
107
  * The declared persisted write sites, in file order.
109
108
  *
@@ -131,30 +130,6 @@ export function persistedWriteSites() {
131
130
  }
132
131
  const table = parseTable(JSON.parse(raw));
133
132
  cachedSites = table.sites;
134
- cachedSymbols = table.symbols;
135
133
  return table.sites;
136
134
  }
137
- /** The inventory's symbol legend — the roots every declared path is written against, with the
138
- * segments the gate checks against the resolver's source.
139
- * @internal no production caller — the gates read the JSON asset directly. */
140
- export function writePathSymbols() {
141
- persistedWriteSites();
142
- return cachedSymbols ?? {};
143
- }
144
- /** Sites serialized by the per-home instance claim, with their instance keys.
145
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
146
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
147
- export function instanceClaimedWriteSites() {
148
- return persistedWriteSites().filter((site) => site.serializedBy === 'instance-claim');
149
- }
150
- /** One declared site by id. An undeclared id throws — a stale caller must fail
151
- * loud rather than read "nothing is declared".
152
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
153
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
154
- export function persistedWriteSite(id) {
155
- const site = persistedWriteSites().find(candidate => candidate.id === id);
156
- if (site === undefined)
157
- throw new Error(`evolution-core: no persisted write site "${id}" in persisted-write-inventory.json`);
158
- return site;
159
- }
160
135
  //# sourceMappingURL=write-inventory.js.map
@@ -1,6 +1,5 @@
1
- import { type EvolutionIoLike } from './io.ts';
1
+ import { transactIo, type EvolutionIoLike } from './io.ts';
2
2
  /** The four persistent writer kinds the family permits. */
3
- export type WriteUnitKind = 'skill' | 'state' | 'merge' | 'curator';
4
3
  /** One planned write: expected is the baseline read before the plan, next is the new bytes. */
5
4
  export interface WriteTarget {
6
5
  readonly path: string;
@@ -10,7 +9,7 @@ export interface WriteTarget {
10
9
  }
11
10
  /** A structured failure; conflict always means the target changed before/inside the write. */
12
11
  export interface WriteKernelError {
13
- readonly code: 'cas-conflict' | 'write-failed' | 'compensation-blocked';
12
+ readonly code: 'cas-conflict' | 'write-failed' | 'compensation-blocked' | 'transact-not-invoked';
14
13
  readonly message: string;
15
14
  readonly target: string;
16
15
  }
@@ -23,7 +22,7 @@ export interface WriteKernelResult {
23
22
  }
24
23
  export interface WriteKernelOptions {
25
24
  readonly io: EvolutionIoLike;
26
- readonly transact?: ((io: EvolutionIoLike, path: string, task: (current: string | null) => string | null | Promise<string | null>) => Promise<void>) | undefined;
25
+ readonly transact?: typeof transactIo | undefined;
27
26
  readonly now?: (() => number) | undefined;
28
27
  }
29
28
  export interface WriteOneOptions {
@@ -1,4 +1,4 @@
1
- import { isCommittedWarning } from "./io.js";
1
+ import { isCommittedWarning, TransactionNotInvokedError, transactIo } from "./io.js";
2
2
  /**
3
3
  * The family's single write primitive: compare the baseline INSIDE the write
4
4
  * transaction, never overwrite a concurrent value, and compensate only this
@@ -24,6 +24,7 @@ export class WriteKernel {
24
24
  async run(target, task) {
25
25
  let invoked = false;
26
26
  let conflict = false;
27
+ let transactionWarnings;
27
28
  const invoke = async (current) => {
28
29
  if (target.expected !== undefined && current !== target.expected) {
29
30
  conflict = true;
@@ -34,17 +35,9 @@ export class WriteKernel {
34
35
  };
35
36
  try {
36
37
  if (this.transact !== undefined)
37
- await this.transact(this.io, target.path, invoke);
38
- else if (this.io.transact !== undefined)
39
- await this.io.transact(target.path, invoke);
40
- else {
41
- const current = await this.io.readText(target.path);
42
- const next = await invoke(current);
43
- if (next === null && current !== null)
44
- await this.io.remove(target.path);
45
- else if (next !== null && next !== current)
46
- await this.io.writeText(target.path, next);
47
- }
38
+ transactionWarnings = await this.transact(this.io, target.path, invoke);
39
+ else
40
+ transactionWarnings = await transactIo(this.io, target.path, invoke);
48
41
  }
49
42
  catch (error) {
50
43
  if (conflict)
@@ -55,7 +48,7 @@ export class WriteKernel {
55
48
  }
56
49
  if (!invoked)
57
50
  throw new Error('internal error: the write transaction for ' + target.path + ' did not invoke the task; no write was performed');
58
- return {};
51
+ return transactionWarnings === undefined ? {} : { warnings: transactionWarnings };
59
52
  }
60
53
  /**
61
54
  * Write one target only if the current bytes still equal the baseline.
@@ -68,6 +61,7 @@ export class WriteKernel {
68
61
  let wrote = false;
69
62
  let deferred = false;
70
63
  let conflict = false;
64
+ let transactionWarnings;
71
65
  const task = (current) => {
72
66
  if (current !== target.expected) {
73
67
  if (guard) {
@@ -82,30 +76,24 @@ export class WriteKernel {
82
76
  };
83
77
  try {
84
78
  if (this.transact !== undefined)
85
- await this.transact(this.io, target.path, task);
86
- else if (this.io.transact !== undefined)
87
- await this.io.transact(target.path, task);
88
- else {
89
- const current = await this.io.readText(target.path);
90
- const next = task(current);
91
- if (next === null && current !== null)
92
- await this.io.remove(target.path);
93
- else if (next !== null && next !== current)
94
- await this.io.writeText(target.path, next);
95
- }
79
+ transactionWarnings = await this.transact(this.io, target.path, task);
80
+ else
81
+ transactionWarnings = await transactIo(this.io, target.path, task);
96
82
  }
97
83
  catch (error) {
98
84
  if (conflict)
99
85
  return { ok: false, changed: [], errors: [{ code: 'cas-conflict', message: error instanceof Error ? error.message : String(error), target: target.path }] };
100
86
  if (isCommittedWarning(error))
101
87
  return { ok: true, changed: [target.path], errors: [], warnings: [error instanceof Error ? error.message : String(error)] };
88
+ if (error instanceof TransactionNotInvokedError)
89
+ return { ok: false, changed: [], errors: [{ code: 'transact-not-invoked', message: error.message, target: target.path }] };
102
90
  return { ok: false, changed: [], errors: [{ code: 'write-failed', message: error instanceof Error ? error.message : String(error), target: target.path }] };
103
91
  }
104
92
  if (conflict || (!wrote && deferred))
105
93
  return { ok: false, changed: [], errors: [{ code: 'cas-conflict', message: 'concurrent modification detected: ' + target.path, target: target.path }] };
106
94
  if (!wrote)
107
95
  return { ok: false, changed: [], errors: [{ code: 'write-failed', message: 'transaction did not invoke the write task: ' + target.path, target: target.path }] };
108
- return { ok: true, changed: [target.path], errors: [] };
96
+ return { ok: true, changed: [target.path], errors: [], ...(transactionWarnings === undefined ? {} : { warnings: transactionWarnings }) };
109
97
  }
110
98
  /**
111
99
  * Write a plan in order. A preflight drift writes nothing; a later failure
package/lib/write.js CHANGED
@@ -1,5 +1,5 @@
1
- import { r as contentHash } from "./mutations-DihgpfgG.js";
2
- import { $ as validateMutationRequest, A as UNIT_JOURNAL_SCHEMA_VERSION, B as readUnitSnapshot, D as unitJournalPort, E as pruneTreeChangeUnits, F as writeUnitJournal, G as unitSnapshotsDir, H as unitIndexPath, I as UNIT_STORAGE_SCHEMA_VERSION, J as writeUnitEvidence, K as unitStorageKey, L as readUnitEvidence, M as readUnitJournal, N as unitJournalPath, O as unitSnapshotPort, P as unitJournalPhaseRank, Q as fileMutationLock, R as readUnitIndex, U as unitReceiptPath, V as unitEvidencePath, W as unitSnapshotPath, X as writeUnitSnapshot, Y as writeUnitReceipt, Z as MutationUnit, d as entryTarget, et as WriteKernel, j as assertUnitJournalTransition, k as UNIT_JOURNAL_PHASES, q as upsertUnitIndex, z as readUnitReceipt } from "./skill-history-RWt1-kbZ.js";
1
+ import { r as contentHash } from "./mutations-DQXddSJd.js";
2
+ import { $ as validateMutationRequest, A as UNIT_JOURNAL_SCHEMA_VERSION, B as readUnitSnapshot, D as unitJournalPort, E as pruneTreeChangeUnits, F as writeUnitJournal, G as unitSnapshotsDir, H as unitIndexPath, I as UNIT_STORAGE_SCHEMA_VERSION, J as writeUnitEvidence, K as unitStorageKey, L as readUnitEvidence, M as readUnitJournal, N as unitJournalPath, O as unitSnapshotPort, P as unitJournalPhaseRank, Q as fileMutationLock, R as readUnitIndex, U as unitReceiptPath, V as unitEvidencePath, W as unitSnapshotPath, X as writeUnitSnapshot, Y as writeUnitReceipt, Z as MutationUnit, d as entryTarget, et as WriteKernel, j as assertUnitJournalTransition, k as UNIT_JOURNAL_PHASES, q as upsertUnitIndex, z as readUnitReceipt } from "./skill-history-CxrDE3Rb.js";
3
3
  //#region lib/types/unit-undo.js
4
4
  /**
5
5
  * Cross-skill unit undo executor.
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.47.0",
4
+ "version": "0.49.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -141,9 +141,9 @@
141
141
  "path": "<callerSupplied>",
142
142
  "writer": "evolution-core/src/skill-store.ts",
143
143
  "serializedBy": "transact",
144
- "marker": "transactIo(ioLike, path, task)",
144
+ "marker": "this.transact = transact ?? (io.transact ? transactIo : undefined)",
145
145
  "state": [],
146
- "note": "The store's transaction helper: it prefers the backend's own transact and falls back to the seam's transactIo. The target is the caller's path — each durable target has its own row above; this row vouches for the primitive itself."
146
+ "note": "The store's ONE transaction seam: explicit injection wins, a backend with transact binds transactIo (typed not-invoked + committed warnings), a backend without it keeps the plain read→write. The target is the caller's path — each durable target has its own row above; this row vouches for the primitive itself."
147
147
  },
148
148
  {
149
149
  "id": "feedback-events",
@@ -271,15 +271,6 @@
271
271
  "state": [],
272
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."
273
273
  },
274
- {
275
- "id": "merge-pair-index",
276
- "path": "<evolutionHome>/merge/pair-index.json",
277
- "writer": "evolution-merge/src/domain/pair-index-store.ts",
278
- "serializedBy": "transact",
279
- "marker": "transactIo(io, pairIndexPath(home)",
280
- "state": [],
281
- "note": "pairKey → result/runId/target index; RMW under the same IO lock so two merge runs cannot lose each other's entries."
282
- },
283
274
  {
284
275
  "id": "unit-snapshot-and-evidence",
285
276
  "path": "<evolutionHome>/merge/unit-snapshots/** | <evolutionHome>/units/skill/snapshots/** | <evolutionHome>/merge/units/**/evidence.json",
@@ -312,9 +303,9 @@
312
303
  "path": "<evolutionHome>/merge/unit-journals/** | <evolutionHome>/units/skill/journals/**",
313
304
  "writer": "evolution-core/src/unit-journal.ts",
314
305
  "serializedBy": "transact",
315
- "marker": "transactIo(io, path, () => content)",
306
+ "marker": "transactIo(io, path, (current) => {",
316
307
  "state": [],
317
- "note": "Phase transitions are validated against the existing journal before the transaction; the write itself is the shared transactIo path."
308
+ "note": "Phase transitions are validated against the current journal inside the transactIo callback; the callback returns the new bytes only after the monotonicity check."
318
309
  },
319
310
  {
320
311
  "id": "run-lease",
@@ -324,6 +315,33 @@
324
315
  "marker": "transactIo(this.io, path, (raw)",
325
316
  "state": [],
326
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
+ },
319
+ {
320
+ "id": "write-kernel-run",
321
+ "path": "<evolutionHome>/units/**",
322
+ "writer": "evolution-core/src/write-kernel.ts",
323
+ "serializedBy": "transact",
324
+ "marker": "transactIo(this.io, target.path, invoke)",
325
+ "state": [],
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
+ },
328
+ {
329
+ "id": "write-kernel-write-one",
330
+ "path": "<evolutionHome>/units/**",
331
+ "writer": "evolution-core/src/write-kernel.ts",
332
+ "serializedBy": "transact",
333
+ "marker": "transactIo(this.io, target.path, task)",
334
+ "state": [],
335
+ "note": "Single-target CAS path: same transactIo seam."
336
+ },
337
+ {
338
+ "id": "mutation-lock",
339
+ "path": "<evolutionHome>/.mutation-lock",
340
+ "writer": "evolution-core/src/mutation-unit.ts",
341
+ "serializedBy": "transact",
342
+ "marker": "transactIo(io, path, task)",
343
+ "state": [],
344
+ "note": "fileMutationLock updates the lock record through transactIo; no private direct-write fallback remains."
327
345
  }
328
346
  ]
329
347
  }