@lmzhen/dsh-evolution-core 0.59.6 → 0.60.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 (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
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Published conformance suite for `EvolutionStateStorage` providers (J-5 / S3-2).
3
+ *
4
+ * A third-party provider (or a new medium inside this family) runs ONE call to
5
+ * check the seam contract end to end: field-complete round-trips, claim/resolve
6
+ * rollback, refusal at the write boundary, clone/alias independence, unknown-field
7
+ * preservation, and the two seam caps (the resolved pending tail and the
8
+ * review-state session rows).
9
+ *
10
+ * The assertion surface is INJECTED ({@link ConformanceAssert}) rather than
11
+ * imported: vitest satisfies it in-tree, and a host that only has node:assert can
12
+ * wrap it in a few lines. That keeps this module free of any test-runner import,
13
+ * so it ships inside the published package.
14
+ */
15
+ /**
16
+ * Cross-provider consistency harness (G7.4, 0.3.22; V4-07 0.3.28).
17
+ *
18
+ * Runs the SAME observable operation sequence against an
19
+ * `EvolutionStateStorage` provider (json or domain) and asserts both yield the
20
+ * same field-complete result. Every pending-record field that is carried
21
+ * through a round-trip is compared field by field: id, kind, status, summary,
22
+ * args, createdAt, origin, sessionId, claimedBy. The wall-clock holder stamps
23
+ * (claimedAt, resolvedAt) are generated by each provider at its own transact
24
+ * time and legitimately differ in value between the two claims, so they are
25
+ * asserted only for presence/type (a string), never for equality — and
26
+ * claimedAt is asserted to be cleared on release. Status filtering / release
27
+ * rollback must agree. S2-4 (v29): the two seam caps — the resolved pending
28
+ * tail (P2-4) and the review-state session rows (V24-08) — are exercised through
29
+ * the same public operations on both providers, so neither medium can keep the
30
+ * bound to itself.
31
+ */
32
+ // Self-package imports by NAME would be an undeclared dependency (the closure
33
+ // gate rejects it) and a cycle: the seam's own modules are imported relatively.
34
+ import { PENDING_RESOLVED_CAP, REVIEW_STATE_SESSION_CAP } from "./constants.js";
35
+ /** Build a fixture pending record, optionally carrying origin/sessionId. The suite's own stamp and
36
+ * namespace come from {@link ConformanceOptions} — see `basePendingOf`'s call sites. */
37
+ const basePendingOf = (id, kind = 'memory', attribution = {}) => ({
38
+ id,
39
+ kind,
40
+ summary: `${kind}:${id}`,
41
+ args: {},
42
+ createdAt: 'now',
43
+ status: 'pending',
44
+ ...attribution,
45
+ });
46
+ /** Every non-holder pending field must equal the input, field by field. */
47
+ const expectPendingCarried = (assert, actual, input) => {
48
+ assert(actual).toBeDefined();
49
+ const carried = actual;
50
+ assert(carried.id).toBe(input.id);
51
+ assert(carried.kind).toBe(input.kind);
52
+ assert(carried.summary).toBe(input.summary);
53
+ assert(carried.args).toEqual(input.args);
54
+ assert(carried.createdAt).toBe(input.createdAt);
55
+ assert(carried.origin).toBe(input.origin);
56
+ assert(carried.sessionId).toBe(input.sessionId);
57
+ };
58
+ /** The listing must contain `id`; a missing row fails the SUITE, not the runner. */
59
+ const findRecord = (records, id) => {
60
+ const found = records.find(record => record.id === id);
61
+ if (found === undefined)
62
+ throw new Error(`conformance: pending record "${id}" missing from the listing`);
63
+ return found;
64
+ };
65
+ export async function runStateProviderConsistency(provider, assert, options = {}) {
66
+ const idPrefix = options.idPrefix ?? 'c-';
67
+ const claimPrefix = options.claimPrefix ?? 'claim-';
68
+ const stamp = options.createdAt ?? 'now';
69
+ const sessionId = options.sessionId ?? 's-consistent';
70
+ const attributionSessionId = options.attributionSessionId ?? 'sess-attrib';
71
+ const reviewSessionPrefix = options.reviewSessionPrefix ?? 's-cap-';
72
+ /** This run's fixture record: the module helper's fields under THIS run's namespace and stamp. */
73
+ const pending = (id, kind = 'memory', attribution = {}) => ({ ...basePendingOf(id, kind, attribution), createdAt: stamp });
74
+ // --- since 0.3.22 (G7.4): review-state round-trip ---
75
+ await provider.saveReviewState(sessionId, { turnsSinceMemory: 1, turnsSinceSkill: 2, lastTurn: 3 });
76
+ assert(await provider.loadReviewState(sessionId)).toEqual({ turnsSinceMemory: 1, turnsSinceSkill: 2, lastTurn: 3 });
77
+ // --- since 0.3.22 (G7.4): curator-state — missing seed creates; null = keep; overwrite replaces ---
78
+ assert(await provider.loadCuratorState()).toBeNull();
79
+ await provider.transactCuratorState(() => ({ lastRunAt: 10, runCount: 0, lastSummary: 'seed', paused: false }));
80
+ assert(await provider.loadCuratorState()).toEqual({ lastRunAt: 10, runCount: 0, lastSummary: 'seed', paused: false });
81
+ await provider.transactCuratorState(() => null);
82
+ assert(await provider.loadCuratorState()).toEqual({ lastRunAt: 10, runCount: 0, lastSummary: 'seed', paused: false });
83
+ await provider.transactCuratorState(current => ({ ...current, lastSummary: 'updated' }));
84
+ assert(await provider.loadCuratorState()).toEqual({ lastRunAt: 10, runCount: 0, lastSummary: 'updated', paused: false });
85
+ // --- V27 S4 (PLAN S1.3, 2026-09-16): the record handed to the task is the
86
+ // task's COPY — a task that mutates it in place and then refuses the write
87
+ // (null = keep the current record) must not leak the mutation into the
88
+ // medium. json used to hand out the very object its null path wrote back,
89
+ // so the mutated graph was serialized on the "unchanged" path; this vector
90
+ // pins the hand-off discipline for EVERY provider (json, domain, custom). ---
91
+ await provider.transactCuratorState((current) => {
92
+ if (current !== null) {
93
+ current.runCount = 999;
94
+ current.paused = true;
95
+ }
96
+ return null;
97
+ });
98
+ assert(await provider.loadCuratorState()).toEqual({ lastRunAt: 10, runCount: 0, lastSummary: 'updated', paused: false });
99
+ // --- since 0.3.22 (G7.4): claim → resolve (pending → executing → approved) ---
100
+ const live = pending(`${idPrefix}live`);
101
+ await provider.savePending(live);
102
+ assert((await provider.listPending('pending')).map(record => record.id)).toContain(`${idPrefix}live`);
103
+ const claimed = await provider.claimPending(`${idPrefix}live`, `${claimPrefix}a`);
104
+ assert(claimed?.status).toBe('executing');
105
+ assert(claimed?.claimedBy).toBe(`${claimPrefix}a`);
106
+ expectPendingCarried(assert, claimed, live);
107
+ assert(typeof claimed?.claimedAt).toBe('string');
108
+ const resolved = await provider.tryResolvePending(`${idPrefix}live`, 'approved');
109
+ assert(resolved.applied).toBe(true);
110
+ assert(resolved.record?.id).toBe(`${idPrefix}live`);
111
+ assert(resolved.record?.status).toBe('approved');
112
+ expectPendingCarried(assert, resolved.record, live);
113
+ assert(resolved.record?.claimedBy).toBe(`${claimPrefix}a`);
114
+ assert(typeof resolved.record?.claimedAt).toBe('string');
115
+ assert(typeof resolved.record?.resolvedAt).toBe('string');
116
+ assert((await provider.listPending('approved')).map(record => record.id)).toContain(`${idPrefix}live`);
117
+ assert((await provider.listPending('pending')).map(record => record.id)).not.toContain(`${idPrefix}live`);
118
+ // --- since 0.3.22 (G7.4): attribution (origin/sessionId) survives claim → resolve ---
119
+ const attrib = pending(`${idPrefix}attrib`, 'memory', { origin: 'background_review', sessionId: attributionSessionId });
120
+ await provider.savePending(attrib);
121
+ expectPendingCarried(assert, await provider.claimPending(`${idPrefix}attrib`, `${claimPrefix}a`), attrib);
122
+ const attribResolved = await provider.tryResolvePending(`${idPrefix}attrib`, 'approved');
123
+ expectPendingCarried(assert, attribResolved.record, attrib);
124
+ assert(attribResolved.record?.origin).toBe('background_review');
125
+ assert(attribResolved.record?.sessionId).toBe(attributionSessionId);
126
+ assert(typeof attribResolved.record?.resolvedAt).toBe('string');
127
+ // --- since 0.3.22 (G7.4): claim → release rolls executing back to pending (failure path) ---
128
+ const rel = pending(`${idPrefix}release`, 'skill');
129
+ await provider.savePending(rel);
130
+ assert((await provider.claimPending(`${idPrefix}release`, `${claimPrefix}b`))?.status).toBe('executing');
131
+ await provider.releasePendingClaim(`${idPrefix}release`, `${claimPrefix}b`);
132
+ const released = (await provider.listPending('pending')).find(record => record.id === `${idPrefix}release`);
133
+ assert(released?.status).toBe('pending');
134
+ expectPendingCarried(assert, released, rel);
135
+ assert(released?.claimedBy).toBeUndefined();
136
+ assert(released?.claimedAt).toBeUndefined();
137
+ // --- E1 (v15): claim-scoped resolve (expectedClaimId) is provider-wide
138
+ // contract — a foreign claimId refuses; the owner succeeds; the unscoped
139
+ // form still works. (v14 shipped this on json with zero domain coverage.) ---
140
+ const scoped = pending(`${idPrefix}scoped`);
141
+ await provider.savePending(scoped);
142
+ await provider.claimPending(`${idPrefix}scoped`, `${claimPrefix}owner`);
143
+ const foreignScope = await provider.tryResolvePending(`${idPrefix}scoped`, 'approved', `${claimPrefix}foreign`);
144
+ assert(foreignScope.applied).toBe(false);
145
+ assert((await provider.listPending('executing')).map(record => record.id)).toContain(`${idPrefix}scoped`);
146
+ const ownerScope = await provider.tryResolvePending(`${idPrefix}scoped`, 'approved', `${claimPrefix}owner`);
147
+ assert(ownerScope.applied).toBe(true);
148
+ assert(ownerScope.record?.status).toBe('approved');
149
+ // --- since 0.3.22 (G7.4): status filtering is consistent (a pending record is not 'approved') ---
150
+ const filt = pending(`${idPrefix}filter`);
151
+ await provider.savePending(filt);
152
+ assert((await provider.listPending('pending')).map(record => record.id)).toContain(`${idPrefix}filter`);
153
+ assert((await provider.listPending('approved')).map(record => record.id)).not.toContain(`${idPrefix}filter`);
154
+ // --- V8-15 (0.3.46): release AFTER resolve is a no-op on BOTH providers —
155
+ // the resolved record keeps its audit attribution (the domain provider had
156
+ // the status guard; json now matches — G7.4 previously covered only the
157
+ // executing→release path) ---
158
+ const post = pending(`${idPrefix}post-resolve`, 'memory');
159
+ await provider.savePending(post);
160
+ await provider.claimPending(`${idPrefix}post-resolve`, `${claimPrefix}c`);
161
+ await provider.tryResolvePending(`${idPrefix}post-resolve`, 'rejected');
162
+ await provider.releasePendingClaim(`${idPrefix}post-resolve`, `${claimPrefix}c`);
163
+ const postResolved = (await provider.listPending('rejected')).find(record => record.id === `${idPrefix}post-resolve`);
164
+ assert(postResolved?.status).toBe('rejected');
165
+ assert(postResolved?.claimedBy).toBe(`${claimPrefix}c`);
166
+ assert(typeof postResolved?.claimedAt).toBe('string');
167
+ assert(typeof postResolved?.resolvedAt).toBe('string');
168
+ // --- I-4 (v18): a malformed record must be REFUSED at the write boundary.
169
+ // Both providers gate writes (json's field gate, domain's zod schema), and
170
+ // C-3 aligned them on the required `args` key — a JS caller or a hand-edited
171
+ // file must not persist a record the other provider would refuse to open. ---
172
+ await assert(provider.savePending({
173
+ id: `${idPrefix}bad`, kind: 'memory', summary: 'bad', createdAt: stamp, status: 'pending',
174
+ })).rejects.toThrow();
175
+ // --- I-4 (v18): mutating a returned record — top level AND nested `args` —
176
+ // must not poison the medium. The domain provider used to hand back live
177
+ // objects, so a caller's edit rewrote the in-memory record before any save
178
+ // (and survived a rejected save). ---
179
+ const poison = pending(`${idPrefix}poison`);
180
+ poison.args = { nested: { value: 1 } };
181
+ await provider.savePending(poison);
182
+ const returned = findRecord(await provider.listPending('pending'), `${idPrefix}poison`);
183
+ returned.summary = 'poisoned';
184
+ returned.args.nested.value = 99;
185
+ const reread = findRecord(await provider.listPending('pending'), `${idPrefix}poison`);
186
+ assert(reread.summary).toBe(`memory:${idPrefix}poison`);
187
+ assert(reread.args.nested.value).toBe(1);
188
+ // --- P2-15 (v19): a non-cloneable payload is refused by BOTH providers at
189
+ // the write boundary. The domain read path deep-clones every record, so a
190
+ // single poisoned record would break every later read for every status. ---
191
+ const uncloneable = { ...pending(`${idPrefix}uncloneable`), args: { fn: () => { } } };
192
+ await assert(provider.savePending(uncloneable)).rejects.toThrow();
193
+ // --- P2-14 (v19): mutating the CALLER's args after save must not change the
194
+ // stored record (the domain provider used to store the reference). ---
195
+ const aliased = pending(`${idPrefix}alias`);
196
+ aliased.args = { nested: { value: 1 } };
197
+ await provider.savePending(aliased);
198
+ aliased.args.nested.value = 99;
199
+ const aliasedBack = findRecord(await provider.listPending('pending'), `${idPrefix}alias`);
200
+ assert(aliasedBack.args.nested.value).toBe(1);
201
+ // --- P2-16 (v19): a malformed schemaVersion is refused by both providers
202
+ // (json used to accept and rewrite it; domain refused it). ---
203
+ await assert(provider.saveCuratorState({
204
+ lastRunAt: 1, runCount: 0, lastSummary: 'x', paused: false, schemaVersion: -1,
205
+ })).rejects.toThrow();
206
+ // --- P2-18 (v19): unknown fields are PRESERVED by both providers (zod's
207
+ // default strip used to delete them on the domain side only). ---
208
+ await provider.savePending({ ...pending(`${idPrefix}extra`), extraField: 'kept' });
209
+ const extraBack = (await provider.listPending('pending')).find(record => record.id === `${idPrefix}extra`);
210
+ assert(extraBack.extraField).toBe('kept');
211
+ // --- P2-4 (v15) / C-6 (v18): the RESOLVED pending tail is bounded by the
212
+ // seam constant on the resolve path, on BOTH providers. The vector seeds
213
+ // through the public seam (save then claim then resolve) because json's own
214
+ // cap spec reads its file and the domain medium has no file at all: a
215
+ // medium-specific seed would stop being a shared vector. ---
216
+ const capPrefix = `${idPrefix}cap-`;
217
+ await provider.savePending(pending(`${idPrefix}cap-live`, 'skill'));
218
+ for (let index = 0; index <= PENDING_RESOLVED_CAP + 1; index += 1) {
219
+ const id = capPrefix + String(index).padStart(3, '0');
220
+ await provider.savePending(pending(id));
221
+ await provider.claimPending(id, `${claimPrefix}cap`);
222
+ await provider.tryResolvePending(id, 'approved');
223
+ }
224
+ const resolvedNow = (await provider.listPending('approved')).concat(await provider.listPending('rejected'))
225
+ .filter(record => record.kind !== 'capability');
226
+ assert(resolvedNow).toHaveLength(PENDING_RESOLVED_CAP);
227
+ const resolvedIds = resolvedNow.map(record => record.id);
228
+ assert(resolvedIds).not.toContain(capPrefix + '000');
229
+ assert(resolvedIds).not.toContain(capPrefix + '001');
230
+ assert(resolvedIds).toContain(capPrefix + String(PENDING_RESOLVED_CAP + 1).padStart(3, '0'));
231
+ assert((await provider.listPending('pending')).map(record => record.id)).toContain(`${idPrefix}cap-live`);
232
+ // --- V24-08 (v24): review-state rows are bounded per session table, and the
233
+ // SAVING session is never the victim — one row is dropped per over-cap save,
234
+ // so re-saving the oldest session re-enters it and evicts the next oldest. ---
235
+ const sessionPrefix = reviewSessionPrefix;
236
+ const reviewStateOf = (turns) => ({ turnsSinceMemory: turns, turnsSinceSkill: 0, lastTurn: turns });
237
+ for (let index = 0; index <= REVIEW_STATE_SESSION_CAP; index += 1) {
238
+ await provider.saveReviewState(sessionPrefix + String(index), reviewStateOf(index));
239
+ }
240
+ assert(await provider.loadReviewState(sessionPrefix + '0')).toBeNull();
241
+ assert(await provider.loadReviewState(sessionPrefix + '1')).toEqual(reviewStateOf(1));
242
+ assert(await provider.loadReviewState(sessionPrefix + String(REVIEW_STATE_SESSION_CAP))).toEqual(reviewStateOf(REVIEW_STATE_SESSION_CAP));
243
+ await provider.saveReviewState(sessionPrefix + '0', reviewStateOf(999));
244
+ assert(await provider.loadReviewState(sessionPrefix + '0')).toEqual(reviewStateOf(999));
245
+ }
246
+ //# sourceMappingURL=conformance.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Single source for the state-stack magic strings (audit v10 S-06).
3
+ *
4
+ * The singleton curator key, the on-disk state file names, the provider names
5
+ * and the domain table names live here so the two providers (json/domain)
6
+ * cannot drift a literal independently — a drifted literal is exactly the
7
+ * E-10 divergence class both providers already guard against elsewhere.
8
+ * These values are FORMAT-STABLE: the file names and the `'primary'` key are
9
+ * on-disk contracts, the provider names are registry keys, and the table
10
+ * names are domain-spec keys — renaming any of them orphans data or breaks
11
+ * the seam, never rename casually.
12
+ * @module @lmzhen/dsh-evolution-core/state/storage/src/constants
13
+ */
14
+ /** Singleton curator-state record key in both providers (the json map key and
15
+ * the domain table key). */
16
+ export declare const CURATOR_STATE_KEY = "primary";
17
+ /** Provider names as registered on the `evolutionStateStorage` seam. */
18
+ export declare const PROVIDER_DOMAIN = "domain";
19
+ export declare const PROVIDER_STORE = "store";
20
+ /** Marker written after an explicit domain→store migration; `auto` uses it to pick the authority. */
21
+ export declare const STATE_MIGRATION_MARKER = ".migrated-from-domain.json";
22
+ /** Domain table names of the evolution storage-domain spec. */
23
+ export declare const REVIEW_STATE_TABLE = "review_state";
24
+ export declare const CURATOR_STATE_TABLE = "curator_state";
25
+ export declare const PENDING_TABLE = "pending";
26
+ /** P2-4 (v15): the live pending map/table is BOUNDED on the RESOLVE path —
27
+ * `tryResolvePending` drops the oldest resolved (approved/rejected) records by
28
+ * `resolvedAt` once more than this many exist. Single source (the v15 audit
29
+ * found the bound was json-only, so domain deployments grew the table without
30
+ * bound).
31
+ *
32
+ * C-6 (v18) contract precision: a direct `savePending` of an already-resolved
33
+ * record does NOT trigger eviction (the cap is maintained by the resolve
34
+ * operation, not by the writer), and pending/executing records are never
35
+ * trimmed. Callers that write resolved audit records themselves own that
36
+ * growth; the seam's resolve path is what keeps the table bounded.
37
+ * The audit ARCHIVE sidecar that json maintains beyond the cap stays
38
+ * json-specific (domain has no sidecar facility) — declared in both READMEs. */
39
+ export declare const PENDING_RESOLVED_CAP = 200;
40
+ /**
41
+ * V24-08 (v24): session rows in the review-state table, per session id. The
42
+ * review pipeline saves on EVERY turn/end of EVERY session and nothing ever
43
+ * deleted rows, so the file grew (and was fully rewritten) with the deploy's
44
+ * whole session history — the same unbounded-growth class the pending cap
45
+ * above already fixed for approvals. A review row is advisory cadence state:
46
+ * evicting the least-recently-active session merely lets that session's next
47
+ * review fire from a fresh counter, so a generous cap is loss-less in
48
+ * practice. Enforced by BOTH providers inside their save path (no seam
49
+ * interface change, no background sweeper).
50
+ */
51
+ export declare const REVIEW_STATE_SESSION_CAP = 500;
52
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Single source for the state-stack magic strings (audit v10 S-06).
3
+ *
4
+ * The singleton curator key, the on-disk state file names, the provider names
5
+ * and the domain table names live here so the two providers (json/domain)
6
+ * cannot drift a literal independently — a drifted literal is exactly the
7
+ * E-10 divergence class both providers already guard against elsewhere.
8
+ * These values are FORMAT-STABLE: the file names and the `'primary'` key are
9
+ * on-disk contracts, the provider names are registry keys, and the table
10
+ * names are domain-spec keys — renaming any of them orphans data or breaks
11
+ * the seam, never rename casually.
12
+ * @module @lmzhen/dsh-evolution-core/state/storage/src/constants
13
+ */
14
+ /** Singleton curator-state record key in both providers (the json map key and
15
+ * the domain table key). */
16
+ export const CURATOR_STATE_KEY = 'primary';
17
+ /** Provider names as registered on the `evolutionStateStorage` seam. */
18
+ export const PROVIDER_DOMAIN = 'domain';
19
+ export const PROVIDER_STORE = 'store';
20
+ /** Marker written after an explicit domain→store migration; `auto` uses it to pick the authority. */
21
+ export const STATE_MIGRATION_MARKER = '.migrated-from-domain.json';
22
+ /** Domain table names of the evolution storage-domain spec. */
23
+ export const REVIEW_STATE_TABLE = 'review_state';
24
+ export const CURATOR_STATE_TABLE = 'curator_state';
25
+ export const PENDING_TABLE = 'pending';
26
+ /** P2-4 (v15): the live pending map/table is BOUNDED on the RESOLVE path —
27
+ * `tryResolvePending` drops the oldest resolved (approved/rejected) records by
28
+ * `resolvedAt` once more than this many exist. Single source (the v15 audit
29
+ * found the bound was json-only, so domain deployments grew the table without
30
+ * bound).
31
+ *
32
+ * C-6 (v18) contract precision: a direct `savePending` of an already-resolved
33
+ * record does NOT trigger eviction (the cap is maintained by the resolve
34
+ * operation, not by the writer), and pending/executing records are never
35
+ * trimmed. Callers that write resolved audit records themselves own that
36
+ * growth; the seam's resolve path is what keeps the table bounded.
37
+ * The audit ARCHIVE sidecar that json maintains beyond the cap stays
38
+ * json-specific (domain has no sidecar facility) — declared in both READMEs. */
39
+ export const PENDING_RESOLVED_CAP = 200;
40
+ /**
41
+ * V24-08 (v24): session rows in the review-state table, per session id. The
42
+ * review pipeline saves on EVERY turn/end of EVERY session and nothing ever
43
+ * deleted rows, so the file grew (and was fully rewritten) with the deploy's
44
+ * whole session history — the same unbounded-growth class the pending cap
45
+ * above already fixed for approvals. A review row is advisory cadence state:
46
+ * evicting the least-recently-active session merely lets that session's next
47
+ * review fire from a fresh counter, so a generous cap is loss-less in
48
+ * practice. Enforced by BOTH providers inside their save path (no seam
49
+ * interface change, no background sweeper).
50
+ */
51
+ export const REVIEW_STATE_SESSION_CAP = 500;
52
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * G2b/2b.4: the domain compatibility declaration (S1-07).
3
+ *
4
+ * A domain spec says WHAT is stored; nothing said what happens to records the CURRENT schema rejects,
5
+ * nor which earlier versions stay readable. Today the answer is implicit and unstated: 0 declared
6
+ * compatibility surface. This file is the ONE place that states it.
7
+ *
8
+ * MIGRATION NOTE: upstream P2-E1 (docs/v33-no-action-register.md) asks storage-domain to add optional
9
+ * `layout` / `compatibleVersions` / `invalidRecords` fields to `DomainSpec`. When that lands, this
10
+ * declaration MOVES onto the platform spec - the fields exist precisely so a domain can state this once.
11
+ * It must not then live in two places.
12
+ *
13
+ * @module @lmzhen/dsh-evolution-core/state/domain/compatibility
14
+ */
15
+ /** How bad it is to lose one record of a table, by whether the data can come back. */
16
+ export type RecordLossTier = 'regenerable' | 'irreplaceable';
17
+ /** One table's answer to "what if a stored record fails the current schema?". */
18
+ export interface InvalidRecordPolicy {
19
+ readonly table: string;
20
+ /** `regenerable`: the record can be rebuilt from another surface. `irreplaceable`: it cannot. */
21
+ readonly tier: RecordLossTier;
22
+ /** Why that tier, in one line — the claim a reader can check. */
23
+ readonly why: string;
24
+ }
25
+ /**
26
+ * The declaration. `compatibleVersions` and `layout` are ALTERNATIVES, not complements: a domain either
27
+ * states which earlier format versions it still reads, or states the layout it expects - declaring both
28
+ * would leave the reader two answers to one question. Exactly one must be present.
29
+ */
30
+ export interface DomainCompatibility {
31
+ /** One entry per declared table; a table with no entry is an unstated loss policy. */
32
+ readonly invalidRecords: readonly InvalidRecordPolicy[];
33
+ /** Earlier domain versions this build still opens. */
34
+ readonly compatibleVersions?: readonly number[] | undefined;
35
+ /** The layout this build expects on the medium, when version compatibility is not the axis. */
36
+ readonly layout?: string | undefined;
37
+ }
38
+ /** The evolution domain's statement. Absence of this constant is what the criterion calls red. */
39
+ export declare const EVOLUTION_DOMAIN_COMPATIBILITY: DomainCompatibility;
40
+ //# sourceMappingURL=compatibility.d.ts.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * G2b/2b.4: the domain compatibility declaration (S1-07).
3
+ *
4
+ * A domain spec says WHAT is stored; nothing said what happens to records the CURRENT schema rejects,
5
+ * nor which earlier versions stay readable. Today the answer is implicit and unstated: 0 declared
6
+ * compatibility surface. This file is the ONE place that states it.
7
+ *
8
+ * MIGRATION NOTE: upstream P2-E1 (docs/v33-no-action-register.md) asks storage-domain to add optional
9
+ * `layout` / `compatibleVersions` / `invalidRecords` fields to `DomainSpec`. When that lands, this
10
+ * declaration MOVES onto the platform spec - the fields exist precisely so a domain can state this once.
11
+ * It must not then live in two places.
12
+ *
13
+ * @module @lmzhen/dsh-evolution-core/state/domain/compatibility
14
+ */
15
+ /** The evolution domain's statement. Absence of this constant is what the criterion calls red. */
16
+ export const EVOLUTION_DOMAIN_COMPATIBILITY = {
17
+ invalidRecords: [
18
+ {
19
+ table: 'review_state',
20
+ tier: 'regenerable',
21
+ why: 'turn counters are observations of a session; a lost row costs one session its counters and the next run rewrites it',
22
+ },
23
+ {
24
+ table: 'curator_state',
25
+ tier: 'regenerable',
26
+ why: 'run bookkeeping only — runCount/lastRunAt are re-derived from the run records on the next run',
27
+ },
28
+ {
29
+ table: 'pending',
30
+ tier: 'irreplaceable',
31
+ why: 'a staged write is the ONLY copy of an approved-but-unapplied change; losing it loses the operator decision',
32
+ },
33
+ ],
34
+ compatibleVersions: [1],
35
+ };
36
+ //# sourceMappingURL=compatibility.js.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * storage-domain provider for evolution state.
3
+ *
4
+ * When this provider is mounted, review/curator/pending records live in the
5
+ * DSH storage-domain data form: schema-validated, change-emitting, durable KV
6
+ * with whatever backend the domain facility routes (`json`, `sqlite`, remote
7
+ * RPC, …). The provider is one of several implementations of the same seam.
8
+ * @module @lmzhen/dsh-evolution-core/state/domain
9
+ */
10
+ import type { Context } from '@deepseek-ai/cordis';
11
+ import { z } from 'zod';
12
+ import { type CuratorStateRecord, type PendingRecord, type ReviewStateRecord } from '../index.ts';
13
+ export declare const name = "evolution-state-domain";
14
+ export declare const inject: string[];
15
+ /**
16
+ * Review-state record schema of the storage-domain table.
17
+ * @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
18
+ * below — not public API surface (audit v10 S-03); the record contract lives
19
+ * in `@lmzhen/dsh-evolution-core/state-storage` types.
20
+ */
21
+ export declare const reviewStateSchema: z.ZodObject<{
22
+ turnsSinceMemory: z.ZodNumber;
23
+ turnsSinceSkill: z.ZodNumber;
24
+ lastTurn: z.ZodNumber;
25
+ }, z.core.$loose>;
26
+ /**
27
+ * Curator-state record schema of the storage-domain table.
28
+ * @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
29
+ * below — not public API surface (audit v10 S-03).
30
+ */
31
+ export declare const curatorStateSchema: z.ZodObject<{
32
+ schemaVersion: z.ZodOptional<z.ZodNumber>;
33
+ lastRunAt: z.ZodNumber;
34
+ runCount: z.ZodNumber;
35
+ lastSummary: z.ZodString;
36
+ paused: z.ZodBoolean;
37
+ }, z.core.$loose>;
38
+ /**
39
+ * Pending record schema of the storage-domain table.
40
+ * @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
41
+ * below — not public API surface (audit v10 S-03).
42
+ */
43
+ export declare const pendingSchema: z.ZodObject<{
44
+ id: z.ZodString;
45
+ kind: z.ZodEnum<{
46
+ memory: "memory";
47
+ skill: "skill";
48
+ capability: "capability";
49
+ }>;
50
+ summary: z.ZodString;
51
+ args: z.ZodUnknown;
52
+ createdAt: z.ZodString;
53
+ status: z.ZodEnum<{
54
+ pending: "pending";
55
+ executing: "executing";
56
+ approved: "approved";
57
+ rejected: "rejected";
58
+ }>;
59
+ resolvedAt: z.ZodOptional<z.ZodString>;
60
+ claimedBy: z.ZodOptional<z.ZodString>;
61
+ claimedAt: z.ZodOptional<z.ZodString>;
62
+ origin: z.ZodOptional<z.ZodString>;
63
+ sessionId: z.ZodOptional<z.ZodString>;
64
+ }, z.core.$loose>;
65
+ /**
66
+ * The evolution storage-domain spec: three schema-validated KV tables.
67
+ * @internal Referenced only by this package's own tests and `open()` — not
68
+ * public API surface (audit v10 S-03).
69
+ */
70
+ export declare const EVOLUTION_DOMAIN: {
71
+ name: string;
72
+ version: number;
73
+ tables: {
74
+ review_state: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, ReviewStateRecord>;
75
+ curator_state: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, CuratorStateRecord>;
76
+ pending: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, PendingRecord>;
77
+ };
78
+ };
79
+ export declare function apply(ctx: Context): void;
80
+ export * from './compatibility.ts';
81
+ //# sourceMappingURL=index.d.ts.map