@sentropic/cluster-mesh 0.21.0 → 0.21.2

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 (53) hide show
  1. package/assets/storage/engram-memory/contract-manifest.json +155 -0
  2. package/assets/storage/engram-memory/equivalence.json +46 -0
  3. package/dist/comments/postgres.d.ts +2 -2
  4. package/dist/engram-memory/codec.d.ts +46 -0
  5. package/dist/engram-memory/codec.d.ts.map +1 -0
  6. package/dist/engram-memory/codec.js +146 -0
  7. package/dist/engram-memory/codec.js.map +1 -0
  8. package/dist/engram-memory/contract.d.ts +15 -0
  9. package/dist/engram-memory/contract.d.ts.map +1 -0
  10. package/dist/engram-memory/contract.js +16 -0
  11. package/dist/engram-memory/contract.js.map +1 -0
  12. package/dist/engram-memory/limits.d.ts +17 -0
  13. package/dist/engram-memory/limits.d.ts.map +1 -0
  14. package/dist/engram-memory/limits.js +47 -0
  15. package/dist/engram-memory/limits.js.map +1 -0
  16. package/dist/engram-memory/manifest.d.ts +84 -0
  17. package/dist/engram-memory/manifest.d.ts.map +1 -0
  18. package/dist/engram-memory/manifest.js +195 -0
  19. package/dist/engram-memory/manifest.js.map +1 -0
  20. package/dist/engram-memory/postgres-queries.d.ts +26 -0
  21. package/dist/engram-memory/postgres-queries.d.ts.map +1 -0
  22. package/dist/engram-memory/postgres-queries.js +91 -0
  23. package/dist/engram-memory/postgres-queries.js.map +1 -0
  24. package/dist/engram-memory/postgres.d.ts +55 -0
  25. package/dist/engram-memory/postgres.d.ts.map +1 -0
  26. package/dist/engram-memory/postgres.js +115 -0
  27. package/dist/engram-memory/postgres.js.map +1 -0
  28. package/dist/engram-memory/replay-policy.d.ts +25 -0
  29. package/dist/engram-memory/replay-policy.d.ts.map +1 -0
  30. package/dist/engram-memory/replay-policy.js +31 -0
  31. package/dist/engram-memory/replay-policy.js.map +1 -0
  32. package/dist/engram-memory/sqlite-queries.d.ts +11 -0
  33. package/dist/engram-memory/sqlite-queries.d.ts.map +1 -0
  34. package/dist/engram-memory/sqlite-queries.js +38 -0
  35. package/dist/engram-memory/sqlite-queries.js.map +1 -0
  36. package/dist/engram-memory/sqlite.d.ts +63 -0
  37. package/dist/engram-memory/sqlite.d.ts.map +1 -0
  38. package/dist/engram-memory/sqlite.js +83 -0
  39. package/dist/engram-memory/sqlite.js.map +1 -0
  40. package/dist/engram-memory/validation.d.ts +31 -0
  41. package/dist/engram-memory/validation.d.ts.map +1 -0
  42. package/dist/engram-memory/validation.js +92 -0
  43. package/dist/engram-memory/validation.js.map +1 -0
  44. package/dist/storage/common-contract.d.ts +73 -0
  45. package/dist/storage/common-contract.d.ts.map +1 -0
  46. package/dist/storage/common-contract.js +188 -0
  47. package/dist/storage/common-contract.js.map +1 -0
  48. package/dist/storage/contracts.d.ts +2 -2
  49. package/dist/storage/contracts.d.ts.map +1 -1
  50. package/dist/storage/contracts.js +1 -1
  51. package/dist/storage/contracts.js.map +1 -1
  52. package/dist/storage/postgres/index.d.ts +2 -2
  53. package/package.json +6 -1
@@ -0,0 +1,84 @@
1
+ import type { ModuleDescriptor } from '../storage/descriptor.js';
2
+ export declare const MEMORY_MODULE_ID: "engram-memory";
3
+ export declare const MEMORY_CONTRACT_VERSION: "memory-binding-v1";
4
+ /** Pinned contract-manifest digest, co-signed C2/C6. Never recomputed silently. */
5
+ export declare const MEMORY_CONTRACT_DIGEST: "sha256:dff737ced37d801ef48bb4d7088fc4fbc92021d21fe2034ff33ea643b49bec28";
6
+ export declare const MEMORY_REQUIRED_PROFILES: readonly string[];
7
+ export declare const MEMORY_OPTIONAL_PROFILES: readonly string[];
8
+ export interface MemoryProfileClaim {
9
+ readonly name: string;
10
+ readonly version: string;
11
+ readonly digest: string;
12
+ }
13
+ /** Pinned profile negotiation table: every profile pinned to version and semantic digest. */
14
+ export declare const MEMORY_PINNED_PROFILES: readonly MemoryProfileClaim[];
15
+ export declare const MEMORY_QUERY_NAMES: readonly string[];
16
+ export declare const MEMORY_BOUNDARIES: readonly string[];
17
+ export declare const MEMORY_SCHEMA_VERSIONS: readonly string[];
18
+ export declare const MEMORY_CHAIN_KINDS: Readonly<{
19
+ 'memory-journal': Readonly<{
20
+ kind: "memory-journal-event";
21
+ chain: "memory-journal";
22
+ }>;
23
+ }>;
24
+ export declare const MEMORY_RECORD_KINDS: Readonly<{
25
+ 'memory-record-blobs': "memory-record-blob";
26
+ 'memory-projection-outbox': "memory-outbox-batch";
27
+ }>;
28
+ export declare const MEMORY_AGGREGATE_KINDS: Readonly<{
29
+ 'memory-pending-controls': "memory-pending-control";
30
+ 'memory-sealed-envelopes': "memory-sealed-envelope";
31
+ 'memory-fold-state': "memory-fold-state";
32
+ 'memory-capture-idempotency': "memory-capture-idempotency";
33
+ 'memory-admission-outcomes': "memory-admission-outcome";
34
+ 'memory-store-meta': "memory-store-meta";
35
+ }>;
36
+ export declare const MEMORY_CODEC_MANIFEST: readonly string[];
37
+ export declare const MEMORY_KEY_MANIFEST: readonly string[];
38
+ export declare const MEMORY_POLICY_MANIFEST: readonly string[];
39
+ export declare const MEMORY_KIND_MANIFEST: Readonly<{
40
+ chains: {
41
+ 'memory-journal': Readonly<{
42
+ kind: "memory-journal-event";
43
+ chain: "memory-journal";
44
+ }>;
45
+ };
46
+ records: {
47
+ 'memory-record-blobs': "memory-record-blob";
48
+ 'memory-projection-outbox': "memory-outbox-batch";
49
+ };
50
+ aggregates: {
51
+ 'memory-pending-controls': "memory-pending-control";
52
+ 'memory-sealed-envelopes': "memory-sealed-envelope";
53
+ 'memory-fold-state': "memory-fold-state";
54
+ 'memory-capture-idempotency': "memory-capture-idempotency";
55
+ 'memory-admission-outcomes': "memory-admission-outcome";
56
+ 'memory-store-meta': "memory-store-meta";
57
+ };
58
+ }>;
59
+ export declare const MEMORY_KEY_FORMATS: readonly string[];
60
+ export declare const MEMORY_ASSET_MANIFEST: Readonly<{
61
+ contract: Readonly<{
62
+ name: "l3a-generic-module-storage-port";
63
+ version: "v4.1";
64
+ digest: "c7111c9e7293ee270a0b4dde277f1cfc40fa3c863c3915c6f9ccdd6935c46294";
65
+ }>;
66
+ additive: readonly string[];
67
+ }>;
68
+ /**
69
+ * The complete registered contract manifest covered by the contract digest
70
+ * (binding section 2.2.3). Exported so every section gets its own
71
+ * digest-mutation test.
72
+ */
73
+ export declare const memoryContractManifest: () => Record<string, unknown>;
74
+ /** Contract digest over a manifest, for mutation tests (binding section 2.2.3). */
75
+ export declare const memoryDescriptorDigest: (manifest: Record<string, unknown>) => string;
76
+ /**
77
+ * Deterministic generator/check: recompute the pinned literal from the
78
+ * manifest. Production never silently accepts changed bytes by recomputing
79
+ * a new identity on import.
80
+ */
81
+ export declare const checkMemoryContractDigest: (manifest?: Record<string, unknown>) => void;
82
+ /** The frozen memory descriptor (binding section 2.2). */
83
+ export declare const MEMORY_DESCRIPTOR: ModuleDescriptor;
84
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/engram-memory/manifest.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,eAAO,MAAM,gBAAgB,iBAA2B,CAAC;AAEzD,eAAO,MAAM,uBAAuB,qBAA+B,CAAC;AAEpE,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,2EACiD,CAAC;AAErF,eAAO,MAAM,wBAAwB,mBAMnC,CAAC;AAEH,eAAO,MAAM,wBAAwB,mBAAyC,CAAC;AAa/E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,6FAA6F;AAC7F,eAAO,MAAM,sBAAsB,EAAE,SAAS,kBAAkB,EAM5D,CAAC;AAEL,eAAO,MAAM,kBAAkB,mBAM7B,CAAC;AAEH,eAAO,MAAM,iBAAiB,mBAAgD,CAAC;AAE/E,eAAO,MAAM,sBAAsB,mBAKjC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;EAE7B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;EAG9B,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;EAOjC,CAAC;AAEH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAajD,CAAC;AAEH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAW/C,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;EAI/B,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAU9C,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;EAchC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAO,OAAO,MAAM,EAAE,OAAO,CAuB9D,CAAC;AAWH,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,aAAc,OAAO,MAAM,EAAE,OAAO,CAAC,KAAG,MAAoC,CAAC;AAEhH;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,cAAc,OAAO,MAAM,EAAE,OAAO,CAAC,KAA8B,IAKxG,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,EAAE,gBAa5B,CAAC"}
@@ -0,0 +1,195 @@
1
+ // engram-memory semantic manifest: pinned neutral contract bytes, profile
2
+ // digests, codecs, key encodings and index policies covered by the contract
3
+ // digest (binding sections 1.2, 2.2, 3.1, 3.2, 5.3, 6.3). Data-pure.
4
+ // Digest rule: SHA-256 over UTF-8 `graphify-memory/l3a-module-descriptor/v1`
5
+ // followed by one NUL byte, then `canonicalizeMemoryJcs(manifest)`; rendered
6
+ // as `sha256:` plus hexadecimal. The manifest excludes `contractDigest`
7
+ // itself. Profile rule: SHA-256 over UTF-8
8
+ // `graphify-memory/l3a-profile/v1`, NUL, profile name, NUL, version.
9
+ import { createHash } from 'node:crypto';
10
+ import { canonicalizeMemoryJcs } from './codec.js';
11
+ export const MEMORY_MODULE_ID = 'engram-memory';
12
+ export const MEMORY_CONTRACT_VERSION = 'memory-binding-v1';
13
+ /** Pinned contract-manifest digest, co-signed C2/C6. Never recomputed silently. */
14
+ export const MEMORY_CONTRACT_DIGEST = 'sha256:dff737ced37d801ef48bb4d7088fc4fbc92021d21fe2034ff33ea643b49bec28';
15
+ export const MEMORY_REQUIRED_PROFILES = Object.freeze([
16
+ 'atomic-units-v1',
17
+ 'immutable-chains-v1',
18
+ 'immutable-boundaries-v1',
19
+ 'scope-outbox-v1',
20
+ 'fenced-writers-v1',
21
+ ]);
22
+ export const MEMORY_OPTIONAL_PROFILES = Object.freeze(['leased-snapshots-v1']);
23
+ const PROFILE_DIGEST_DOMAIN = 'graphify-memory/l3a-profile/v1\0';
24
+ const profileDigest = (name, version) => {
25
+ const hash = createHash('sha256');
26
+ hash.update(PROFILE_DIGEST_DOMAIN, 'utf8');
27
+ hash.update(name, 'utf8');
28
+ hash.update('\0', 'utf8');
29
+ hash.update(version, 'utf8');
30
+ return `sha256:${hash.digest('hex')}`;
31
+ };
32
+ /** Pinned profile negotiation table: every profile pinned to version and semantic digest. */
33
+ export const MEMORY_PINNED_PROFILES = (() => {
34
+ const rows = [];
35
+ for (const name of [...MEMORY_REQUIRED_PROFILES, ...MEMORY_OPTIONAL_PROFILES]) {
36
+ rows.push(Object.freeze({ name, version: '1', digest: profileDigest(name, '1') }));
37
+ }
38
+ return Object.freeze(rows);
39
+ })();
40
+ export const MEMORY_QUERY_NAMES = Object.freeze([
41
+ 'memory-journal-page',
42
+ 'memory-record-by-id',
43
+ 'memory-accepted-snapshot',
44
+ 'memory-outbox-page',
45
+ 'scope-chain-index',
46
+ ]);
47
+ export const MEMORY_BOUNDARIES = Object.freeze(['scope-root', 'exact-cursor']);
48
+ export const MEMORY_SCHEMA_VERSIONS = Object.freeze([
49
+ 'memory-journal-1',
50
+ 'memory-record-2',
51
+ 'memory-lifecycle-event-2',
52
+ 'memory-checkpoint-1',
53
+ ]);
54
+ export const MEMORY_CHAIN_KINDS = Object.freeze({
55
+ 'memory-journal': Object.freeze({ kind: 'memory-journal-event', chain: 'memory-journal' }),
56
+ });
57
+ export const MEMORY_RECORD_KINDS = Object.freeze({
58
+ 'memory-record-blobs': 'memory-record-blob',
59
+ 'memory-projection-outbox': 'memory-outbox-batch',
60
+ });
61
+ export const MEMORY_AGGREGATE_KINDS = Object.freeze({
62
+ 'memory-pending-controls': 'memory-pending-control',
63
+ 'memory-sealed-envelopes': 'memory-sealed-envelope',
64
+ 'memory-fold-state': 'memory-fold-state',
65
+ 'memory-capture-idempotency': 'memory-capture-idempotency',
66
+ 'memory-admission-outcomes': 'memory-admission-outcome',
67
+ 'memory-store-meta': 'memory-store-meta',
68
+ });
69
+ export const MEMORY_CODEC_MANIFEST = Object.freeze([
70
+ 'jcs-rfc8785+nfc',
71
+ 'graphify-memory/payload/v2',
72
+ 'graphify-memory/record/v2',
73
+ 'graphify-memory/memory-journal-event/v1',
74
+ 'graphify-memory/memory-journal-intent/v1',
75
+ 'graphify-memory/canonical-transaction/v1',
76
+ 'graphify-memory/recovery-checkpoint/v1',
77
+ 'graphify-memory/accepted-lexical/v1',
78
+ 'graphify-memory/projection-outbox/v1',
79
+ 'graphify-memory/projection-batch/v1',
80
+ 'graphify-memory/capture-idempotency/v1',
81
+ 'graphify-memory/operational-capability/v1',
82
+ ]);
83
+ export const MEMORY_KEY_MANIFEST = Object.freeze([
84
+ 'memory-journal',
85
+ 'memory-record-v1',
86
+ 'memory-pending-control-v1',
87
+ 'memory-sealed-envelope-v1',
88
+ 'memory-state-v1',
89
+ 'memory-outbox-v1',
90
+ 'memory-capture-idempotency-v1',
91
+ 'memory-admission-outcome-v1',
92
+ 'memory-store-meta-v1',
93
+ 'memory-lexical-v1',
94
+ ]);
95
+ export const MEMORY_POLICY_MANIFEST = Object.freeze([
96
+ 'first-proof-immutable:memory-capture-idempotency',
97
+ 'first-proof-immutable:memory-admission-outcomes',
98
+ 'journal-identity:memory-journal-event',
99
+ ]);
100
+ export const MEMORY_KIND_MANIFEST = Object.freeze({
101
+ chains: { ...MEMORY_CHAIN_KINDS },
102
+ records: { ...MEMORY_RECORD_KINDS },
103
+ aggregates: { ...MEMORY_AGGREGATE_KINDS },
104
+ });
105
+ export const MEMORY_KEY_FORMATS = Object.freeze([
106
+ '["memory-record-v1","<record_id>"]',
107
+ '["memory-pending-control-v1","<candidate_id>"]',
108
+ '["memory-sealed-envelope-v1","<candidate_id>"]',
109
+ '["memory-state-v1","candidate|record","<entity_id>"]',
110
+ '["memory-outbox-v1","<through_cursor_inclusive>","<batch_digest>"]',
111
+ '["memory-capture-idempotency-v1","<candidate_id>"]',
112
+ '["memory-admission-outcome-v1","<candidate_id>"]',
113
+ '["memory-store-meta-v1","binding"]',
114
+ '["memory-lexical-v1","<scope_ref>","<record_id>"]',
115
+ ]);
116
+ export const MEMORY_ASSET_MANIFEST = Object.freeze({
117
+ contract: Object.freeze({
118
+ name: 'l3a-generic-module-storage-port',
119
+ version: 'v4.1',
120
+ digest: 'c7111c9e7293ee270a0b4dde277f1cfc40fa3c863c3915c6f9ccdd6935c46294',
121
+ }),
122
+ additive: Object.freeze([
123
+ 'acquireFence/checkFence/releaseFence canonical-instance acquisition (binding §9)',
124
+ 'CommitOptions.fence writer-fence identity (binding §§9.3–9.6)',
125
+ 'readCommitResult scoped original-result recovery (R-G4-7, binding §8.2)',
126
+ 'profileClaims with pinned versions and semantic digests (binding §6.3)',
127
+ 'memory-* named queries and scope-chain-index for memory-journal (binding §4.1)',
128
+ 'memory key encodings, codec manifest, and index policies in the contract digest (binding §§2.2.3, 3.1, 3.2, 5.3)',
129
+ ]),
130
+ });
131
+ /**
132
+ * The complete registered contract manifest covered by the contract digest
133
+ * (binding section 2.2.3). Exported so every section gets its own
134
+ * digest-mutation test.
135
+ */
136
+ export const memoryContractManifest = () => ({
137
+ contractVersion: MEMORY_CONTRACT_VERSION,
138
+ schemaVersions: [...MEMORY_SCHEMA_VERSIONS],
139
+ requiredProfiles: [...MEMORY_REQUIRED_PROFILES],
140
+ optionalProfiles: [...MEMORY_OPTIONAL_PROFILES],
141
+ chainKinds: Object.keys(MEMORY_CHAIN_KINDS),
142
+ queryNames: [...MEMORY_QUERY_NAMES],
143
+ boundaries: [...MEMORY_BOUNDARIES],
144
+ pageLimits: { maxRecords: 2000, maxEncodedBytes: 1048576 },
145
+ profileClaims: MEMORY_PINNED_PROFILES.map((claim) => ({ ...claim })),
146
+ codecs: [...MEMORY_CODEC_MANIFEST],
147
+ keys: [...MEMORY_KEY_MANIFEST],
148
+ keyFormats: [...MEMORY_KEY_FORMATS],
149
+ kinds: {
150
+ chains: { ...MEMORY_KIND_MANIFEST.chains },
151
+ records: { ...MEMORY_KIND_MANIFEST.records },
152
+ aggregates: { ...MEMORY_KIND_MANIFEST.aggregates },
153
+ },
154
+ policies: [...MEMORY_POLICY_MANIFEST],
155
+ assets: {
156
+ contract: { ...MEMORY_ASSET_MANIFEST.contract },
157
+ additive: [...MEMORY_ASSET_MANIFEST.additive],
158
+ },
159
+ });
160
+ const DESCRIPTOR_DIGEST_DOMAIN = 'graphify-memory/l3a-module-descriptor/v1\0';
161
+ const descriptorDigest = (body) => {
162
+ const hash = createHash('sha256');
163
+ hash.update(DESCRIPTOR_DIGEST_DOMAIN, 'utf8');
164
+ hash.update(canonicalizeMemoryJcs(body), 'utf8');
165
+ return `sha256:${hash.digest('hex')}`;
166
+ };
167
+ /** Contract digest over a manifest, for mutation tests (binding section 2.2.3). */
168
+ export const memoryDescriptorDigest = (manifest) => descriptorDigest(manifest);
169
+ /**
170
+ * Deterministic generator/check: recompute the pinned literal from the
171
+ * manifest. Production never silently accepts changed bytes by recomputing
172
+ * a new identity on import.
173
+ */
174
+ export const checkMemoryContractDigest = (manifest = memoryContractManifest()) => {
175
+ const recomputed = descriptorDigest(manifest);
176
+ if (recomputed !== MEMORY_CONTRACT_DIGEST) {
177
+ throw new Error(`Memory contract digest mismatch: expected ${MEMORY_CONTRACT_DIGEST}, computed ${recomputed}`);
178
+ }
179
+ };
180
+ /** The frozen memory descriptor (binding section 2.2). */
181
+ export const MEMORY_DESCRIPTOR = (() => {
182
+ checkMemoryContractDigest();
183
+ return Object.freeze({
184
+ contractVersion: MEMORY_CONTRACT_VERSION,
185
+ contractDigest: MEMORY_CONTRACT_DIGEST,
186
+ schemaVersions: Object.freeze([...MEMORY_SCHEMA_VERSIONS]),
187
+ requiredProfiles: Object.freeze([...MEMORY_REQUIRED_PROFILES]),
188
+ optionalProfiles: Object.freeze([...MEMORY_OPTIONAL_PROFILES]),
189
+ chainKinds: Object.freeze(Object.keys(MEMORY_CHAIN_KINDS)),
190
+ queryNames: Object.freeze([...MEMORY_QUERY_NAMES]),
191
+ boundaries: Object.freeze([...MEMORY_BOUNDARIES]),
192
+ pageLimits: Object.freeze({ maxRecords: 2000, maxEncodedBytes: 1048576 }),
193
+ });
194
+ })();
195
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/engram-memory/manifest.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4EAA4E;AAC5E,qEAAqE;AACrE,6EAA6E;AAC7E,6EAA6E;AAC7E,wEAAwE;AACxE,2CAA2C;AAC3C,qEAAqE;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAwB,CAAC;AAEzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAA4B,CAAC;AAEpE,mFAAmF;AACnF,MAAM,CAAC,MAAM,sBAAsB,GACjC,yEAAkF,CAAC;AAErF,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,iB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,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;KAC1E,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { PgRegisteredQuery } from '../storage/postgres/protocol.js';
2
+ import { MEMORY_QUERY_NAMES } from './manifest.js';
3
+ export type MemoryQueryName = (typeof MEMORY_QUERY_NAMES)[number];
4
+ export declare const isMemoryQueryName: (value: unknown) => value is string;
5
+ /** Strict page input: ascending cursor, 1–2,000 rows, under the byte ceiling. */
6
+ export declare const validateMemoryPageInput: (input: unknown, maxRecords: number) => {
7
+ readonly after: string;
8
+ readonly limit: number;
9
+ };
10
+ export declare const validateMemoryRecordByIdInput: (input: unknown) => {
11
+ readonly recordId: string;
12
+ };
13
+ export declare const validateMemorySnapshotInput: (input: unknown, maxCandidates: number) => {
14
+ readonly systemAsOf: string;
15
+ readonly scopeRef?: string;
16
+ readonly maxCandidates: number;
17
+ };
18
+ export declare const memoryPgQuery: (name: MemoryQueryName) => PgRegisteredQuery;
19
+ export declare const MEMORY_PG_QUERIES: Readonly<{
20
+ 'memory-journal-page': PgRegisteredQuery;
21
+ 'memory-record-by-id': PgRegisteredQuery;
22
+ 'memory-accepted-snapshot': PgRegisteredQuery;
23
+ 'memory-outbox-page': PgRegisteredQuery;
24
+ 'scope-chain-index': PgRegisteredQuery;
25
+ }>;
26
+ //# sourceMappingURL=postgres-queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-queries.d.ts","sourceRoot":"","sources":["../../src/engram-memory/postgres-queries.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAe,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,eAAO,MAAM,iBAAiB,UAAW,OAAO,oBACwC,CAAC;AAEzF,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,UAAW,OAAO,cAAc,MAAM,KAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAc5H,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAAW,OAAO,KAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CASzF,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAC/B,OAAO,iBACC,MAAM,KACpB;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAkB3F,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,eAAe,KAAG,iBAwBrD,CAAC;AAMF,eAAO,MAAM,iBAAiB;;;;;;EAM5B,CAAC"}
@@ -0,0 +1,91 @@
1
+ // engram-memory Postgres named queries (binding section 4.1): input
2
+ // validation and scope checks for the five registered queries. Query
3
+ // execution against the memory projection tables lands in G1b with the
4
+ // append-only memory migration chain; until then every validated query
5
+ // refuses with a typed unavailable error instead of touching another
6
+ // module's tables.
7
+ import { StorageInvalidCommandError, StorageUnavailableError } from '../storage/errors.js';
8
+ import { MEMORY_QUERY_NAMES } from './manifest.js';
9
+ import { isCanonicalU64 } from './codec.js';
10
+ export const isMemoryQueryName = (value) => typeof value === 'string' && MEMORY_QUERY_NAMES.includes(value);
11
+ /** Strict page input: ascending cursor, 1–2,000 rows, under the byte ceiling. */
12
+ export const validateMemoryPageInput = (input, maxRecords) => {
13
+ if (typeof input !== 'object' || input === null) {
14
+ throw new StorageInvalidCommandError('memory page query requires an object input');
15
+ }
16
+ const candidate = input;
17
+ const after = candidate['after'];
18
+ if (!isCanonicalU64(after)) {
19
+ throw new StorageInvalidCommandError('memory page query requires a canonical u64 after cursor');
20
+ }
21
+ const limit = candidate['limit'];
22
+ if (typeof limit !== 'number' || !Number.isSafeInteger(limit) || limit < 1 || limit > maxRecords) {
23
+ throw new StorageInvalidCommandError(`memory page query limit must be within 1 and ${maxRecords}`);
24
+ }
25
+ return { after, limit };
26
+ };
27
+ export const validateMemoryRecordByIdInput = (input) => {
28
+ if (typeof input !== 'object' || input === null) {
29
+ throw new StorageInvalidCommandError('memory record query requires an object input');
30
+ }
31
+ const recordId = input['record_id'];
32
+ if (typeof recordId !== 'string' || recordId.length === 0) {
33
+ throw new StorageInvalidCommandError('memory record query requires a record_id');
34
+ }
35
+ return { recordId };
36
+ };
37
+ export const validateMemorySnapshotInput = (input, maxCandidates) => {
38
+ if (typeof input !== 'object' || input === null) {
39
+ throw new StorageInvalidCommandError('memory snapshot query requires an object input');
40
+ }
41
+ const candidate = input;
42
+ const systemAsOf = candidate['system_as_of'];
43
+ if (!isCanonicalU64(systemAsOf)) {
44
+ throw new StorageInvalidCommandError('memory snapshot query requires a canonical u64 system_as_of');
45
+ }
46
+ const max = candidate['max_candidates'];
47
+ if (typeof max !== 'number' || !Number.isSafeInteger(max) || max < 1 || max > maxCandidates) {
48
+ throw new StorageInvalidCommandError(`memory snapshot max_candidates must be within 1 and ${maxCandidates}`);
49
+ }
50
+ const scopeRef = candidate['scope_ref'];
51
+ if (scopeRef !== undefined && (typeof scopeRef !== 'string' || scopeRef.length === 0)) {
52
+ throw new StorageInvalidCommandError('memory snapshot scope_ref must be a non-empty string when present');
53
+ }
54
+ return { systemAsOf, scopeRef: scopeRef, maxCandidates: max };
55
+ };
56
+ export const memoryPgQuery = (name) => {
57
+ if (!isMemoryQueryName(name)) {
58
+ throw new StorageInvalidCommandError(`unknown memory query: ${String(name)}`);
59
+ }
60
+ return async (supplied, context) => {
61
+ if (context.cursor !== null && typeof context.cursor !== 'string') {
62
+ throw new StorageInvalidCommandError('invalid memory query continuation');
63
+ }
64
+ switch (name) {
65
+ case 'memory-journal-page':
66
+ case 'memory-outbox-page':
67
+ validateMemoryPageInput(supplied, context.limit);
68
+ break;
69
+ case 'memory-record-by-id':
70
+ validateMemoryRecordByIdInput(supplied);
71
+ break;
72
+ case 'memory-accepted-snapshot':
73
+ validateMemorySnapshotInput(supplied, context.limit);
74
+ break;
75
+ case 'scope-chain-index':
76
+ break;
77
+ }
78
+ return pendingTables(name);
79
+ };
80
+ };
81
+ const pendingTables = (name) => {
82
+ throw new StorageUnavailableError(`memory query ${name} requires the G1b memory projection tables`);
83
+ };
84
+ export const MEMORY_PG_QUERIES = Object.freeze({
85
+ 'memory-journal-page': memoryPgQuery('memory-journal-page'),
86
+ 'memory-record-by-id': memoryPgQuery('memory-record-by-id'),
87
+ 'memory-accepted-snapshot': memoryPgQuery('memory-accepted-snapshot'),
88
+ 'memory-outbox-page': memoryPgQuery('memory-outbox-page'),
89
+ 'scope-chain-index': memoryPgQuery('scope-chain-index'),
90
+ });
91
+ //# sourceMappingURL=postgres-queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-queries.js","sourceRoot":"","sources":["../../src/engram-memory/postgres-queries.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,qEAAqE;AACrE,uEAAuE;AACvE,uEAAuE;AACvE,qEAAqE;AACrE,mBAAmB;AAEnB,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAI5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAA4B,EAAE,CAC5E,OAAO,KAAK,KAAK,QAAQ,IAAK,kBAAwC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAEzF,iFAAiF;AACjF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAc,EAAE,UAAkB,EAAsD,EAAE;IAChI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QA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AAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAClE,MAAM,IAAI,0BAA0B,CAAC,mCAAmC,CAAC,CAAC;QAC5E,CAAC;QACD,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,qBAAqB,CAAC;YAC3B,KAAK,oBAAoB;gBACvB,uBAAuB,CAAC,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,qBAAqB;gBACxB,6BAA6B,CAAC,QAAQ,CAAC,CAAC;gBACxC,MAAM;YACR,KAAK,0BAA0B;gBAC7B,2BAA2B,CAAC,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;gBACrD,MAAM;YACR,KAAK,mBAAmB;gBACtB,MAAM;QACV,CAAC;QACD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,IAAY,EAAe,EAAE;IAClD,MAAM,IAAI,uBAAuB,CAAC,gBAAgB,IAAI,4CAA4C,CAAC,CAAC;AACtG,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,qBAAqB,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAC3D,qBAAqB,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAC3D,0BAA0B,EAAE,aAAa,CAAC,0BAA0B,CAAC;IACrE,oBAAoB,EAAE,aAAa,CAAC,oBAAoB,CAAC;IACzD,mBAAmB,EAAE,aAAa,CAAC,mBAAmB,CAAC;CACxD,CAAC,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { PostgresStorageOptions } from '../storage/postgres/protocol.js';
2
+ import { loadPgAssets } from '../storage/postgres/migrations.js';
3
+ import type { AtomicUnit } from '../storage/atomic.js';
4
+ import { MEMORY_DESCRIPTOR } from './manifest.js';
5
+ import { MEMORY_PG_QUERIES } from './postgres-queries.js';
6
+ import { MEMORY_STORAGE_LIMITS } from './limits.js';
7
+ export interface MemoryPostgresRegistration {
8
+ readonly assets: Awaited<ReturnType<typeof loadPgAssets>>;
9
+ readonly descriptor: typeof MEMORY_DESCRIPTOR;
10
+ readonly validateEffects: (effects: AtomicUnit, context: unknown) => Promise<void>;
11
+ readonly queries: typeof MEMORY_PG_QUERIES;
12
+ readonly limits: typeof MEMORY_STORAGE_LIMITS;
13
+ }
14
+ /**
15
+ * Current-state reader for stateful enforcement: returns the decoded
16
+ * aggregate value already stored under the key, or undefined when absent.
17
+ * The G1b transactional projection will supply a backend-backed reader;
18
+ * tests and offline composition supply their own.
19
+ */
20
+ export type MemoryCurrentStateResolver = (key: string) => Promise<unknown>;
21
+ /** Stored aggregate envelope as returned by kernel aggregate reads. */
22
+ export interface MemoryStoredAggregate {
23
+ readonly value: {
24
+ readonly format: 'utf8' | 'base64';
25
+ readonly data: string;
26
+ };
27
+ }
28
+ /**
29
+ * Build a current-state resolver from a kernel-style aggregate reader.
30
+ * Stored bytes decode through the same envelope path as proposed updates,
31
+ * so transition validators compare identical representations. G1b will
32
+ * supply the backend-backed reader from its transactional projection.
33
+ */
34
+ export declare const resolveMemoryCurrentFromAggregates: (readAggregate: (key: string) => Promise<MemoryStoredAggregate | null>) => MemoryCurrentStateResolver;
35
+ /**
36
+ * Mandatory structural validation before projection: capture and admission
37
+ * aggregates must carry well-formed proofs, and capture completion units
38
+ * carry strictly zero appends. When a current-state resolver is supplied,
39
+ * K7 capture and K8 admission transitions are enforced statefully: a
40
+ * higher-version write that changes the original proof or outcome is
41
+ * refused before effects, and identical replay passes through.
42
+ */
43
+ export declare const validateMemoryEffects: (effects: AtomicUnit, resolveCurrent?: MemoryCurrentStateResolver) => Promise<void>;
44
+ export declare const createMemoryPostgresRegistration: () => Promise<MemoryPostgresRegistration>;
45
+ /**
46
+ * Postgres storage composition. FAILS CLOSED in this increment: the public
47
+ * raw factory installed no G1b stateful projection, so admitting any write
48
+ * lane would let a higher-version update replace a frozen first proof
49
+ * (the generic kernel accepts higher aggregate versions). The K7/K8
50
+ * transition core is enforced through `validateMemoryEffects` with a
51
+ * current-state resolver; the factory itself refuses until G1b wires a
52
+ * backend-backed resolver and transactional projection.
53
+ */
54
+ export declare const createMemoryPostgresStorage: (options: Omit<PostgresStorageOptions, 'moduleId' | 'assets' | 'descriptor' | 'projection' | 'validateEffects' | 'queries' | 'operations'>) => Promise<never>;
55
+ //# sourceMappingURL=postgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/engram-memory/postgres.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAQpD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC;IAC1D,QAAQ,CAAC,UAAU,EAAE,OAAO,iBAAiB,CAAC;IAC9C,QAAQ,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnF,QAAQ,CAAC,OAAO,EAAE,OAAO,iBAAiB,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,OAAO,qBAAqB,CAAC;CAC/C;AAyBD;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3E,uEAAuE;AACvE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/E;AAED;;;;;GAKG;AACH,eAAO,MAAM,kCAAkC,kBAC9B,CAAC,GAAG,EAAE,MAAM,KAAK,QAAQ,qBAAqB,GAAG,IAAI,CAAC,KACpE,0BAIF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YACvB,UAAU,mBACF,0BAA0B,KAC1C,QAAQ,IAAI,CAsCd,CAAC;AAEF,eAAO,MAAM,gCAAgC,QAAa,QAAQ,0BAA0B,CASxF,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,YAC7B,KACP,sBAAsB,EACtB,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,GAAG,iBAAiB,GAAG,SAAS,GAAG,YAAY,CACnG,KACA,QAAQ,KAAK,CAKf,CAAC"}
@@ -0,0 +1,115 @@
1
+ // engram-memory Postgres registration and storage (binding section 2.3).
2
+ // Mirrors the Comments architectural pattern: fixed module identity,
3
+ // descriptor, effects validator, queries, limits and trusted operations,
4
+ // then delegation to `createPostgresKernel`. No connection acquisition or
5
+ // migration execution in registration. A host cannot override mandatory
6
+ // validation, recovery or ownership through the storage factory.
7
+ import { loadPgAssets } from '../storage/postgres/migrations.js';
8
+ import { StorageInvalidCommandError, StorageUnavailableError } from '../storage/errors.js';
9
+ import { MEMORY_DESCRIPTOR } from './manifest.js';
10
+ import { MEMORY_PG_QUERIES } from './postgres-queries.js';
11
+ import { MEMORY_STORAGE_LIMITS } from './limits.js';
12
+ import { isMemoryAdmissionOutcome, isMemoryCaptureProof, validateAdmissionTransition, validateCaptureTransition, } from './validation.js';
13
+ const decodeUpdateValue = (value) => {
14
+ const candidate = value;
15
+ const text = candidate.format === 'base64' && typeof candidate.data === 'string'
16
+ ? Buffer.from(candidate.data, 'base64').toString('utf8')
17
+ : candidate.data;
18
+ if (typeof text !== 'string')
19
+ throw new StorageInvalidCommandError('memory aggregate update requires an encoded value');
20
+ try {
21
+ return JSON.parse(text);
22
+ }
23
+ catch {
24
+ throw new StorageInvalidCommandError('memory aggregate update requires JSON bytes');
25
+ }
26
+ };
27
+ const updateKind = (key) => {
28
+ try {
29
+ const parsed = JSON.parse(key);
30
+ return Array.isArray(parsed) && typeof parsed[0] === 'string' ? parsed[0] : null;
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ };
36
+ /**
37
+ * Build a current-state resolver from a kernel-style aggregate reader.
38
+ * Stored bytes decode through the same envelope path as proposed updates,
39
+ * so transition validators compare identical representations. G1b will
40
+ * supply the backend-backed reader from its transactional projection.
41
+ */
42
+ export const resolveMemoryCurrentFromAggregates = (readAggregate) => async (key) => {
43
+ const found = await readAggregate(key);
44
+ if (found === null || found === undefined)
45
+ return undefined;
46
+ return decodeUpdateValue(found.value);
47
+ };
48
+ /**
49
+ * Mandatory structural validation before projection: capture and admission
50
+ * aggregates must carry well-formed proofs, and capture completion units
51
+ * carry strictly zero appends. When a current-state resolver is supplied,
52
+ * K7 capture and K8 admission transitions are enforced statefully: a
53
+ * higher-version write that changes the original proof or outcome is
54
+ * refused before effects, and identical replay passes through.
55
+ */
56
+ export const validateMemoryEffects = async (effects, resolveCurrent) => {
57
+ let touchesCapture = false;
58
+ for (const update of effects.updates) {
59
+ const kind = updateKind(update.key);
60
+ if (kind === null)
61
+ throw new StorageInvalidCommandError('memory aggregate update requires a compound key');
62
+ const value = decodeUpdateValue(update.value);
63
+ if (kind === 'memory-capture-idempotency-v1') {
64
+ touchesCapture = true;
65
+ if (!isMemoryCaptureProof(value)) {
66
+ throw new StorageInvalidCommandError('memory capture update requires a capture proof value');
67
+ }
68
+ if (resolveCurrent !== undefined) {
69
+ const current = await resolveCurrent(update.key);
70
+ const transition = validateCaptureTransition(current ?? null, value);
71
+ if (!transition.ok) {
72
+ throw new StorageInvalidCommandError(`memory capture first proof is immutable: ${transition.errors.join('; ')}`);
73
+ }
74
+ }
75
+ }
76
+ else if (kind === 'memory-admission-outcome-v1') {
77
+ if (!isMemoryAdmissionOutcome(value)) {
78
+ throw new StorageInvalidCommandError('memory admission update requires an admission outcome value');
79
+ }
80
+ if (resolveCurrent !== undefined) {
81
+ const current = await resolveCurrent(update.key);
82
+ const transition = validateAdmissionTransition(current ?? null, value);
83
+ if (!transition.ok) {
84
+ throw new StorageInvalidCommandError(`memory admission first proof is immutable: ${transition.errors.join('; ')}`);
85
+ }
86
+ }
87
+ }
88
+ }
89
+ if (touchesCapture && effects.appends.length !== 0) {
90
+ throw new StorageInvalidCommandError('memory capture completion carries strictly zero appends');
91
+ }
92
+ };
93
+ export const createMemoryPostgresRegistration = async () => Object.freeze({
94
+ assets: await loadPgAssets(),
95
+ descriptor: MEMORY_DESCRIPTOR,
96
+ validateEffects: async (effects) => {
97
+ await validateMemoryEffects(effects);
98
+ },
99
+ queries: MEMORY_PG_QUERIES,
100
+ limits: MEMORY_STORAGE_LIMITS,
101
+ });
102
+ /**
103
+ * Postgres storage composition. FAILS CLOSED in this increment: the public
104
+ * raw factory installed no G1b stateful projection, so admitting any write
105
+ * lane would let a higher-version update replace a frozen first proof
106
+ * (the generic kernel accepts higher aggregate versions). The K7/K8
107
+ * transition core is enforced through `validateMemoryEffects` with a
108
+ * current-state resolver; the factory itself refuses until G1b wires a
109
+ * backend-backed resolver and transactional projection.
110
+ */
111
+ export const createMemoryPostgresStorage = async (options) => {
112
+ void options;
113
+ throw new StorageUnavailableError('memory Postgres composition requires the G1b stateful projection with backend reads');
114
+ };
115
+ //# sourceMappingURL=postgres.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/engram-memory/postgres.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qEAAqE;AACrE,yEAAyE;AACzE,0EAA0E;AAC1E,wEAAwE;AACxE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vC,CAAC;IACD,OAAO,EAAE,iBAAiB;IAC1B,MAAM,EAAE,qBAAqB;CAC9B,CAAC,CAAC;AAEL;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC9C,OAGC,EACe,EAAE;IAClB,KAAK,OAAO,CAAC;IACb,MAAM,IAAI,uBAAuB,CAC/B,qFAAqF,CACtF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type ValidationResult } from '../storage/contracts.js';
2
+ export interface MemoryCommitIdentity {
3
+ readonly eventId: string;
4
+ readonly intentHash: string;
5
+ }
6
+ export type MemoryReplayDecision = {
7
+ readonly kind: 'proceed';
8
+ } | {
9
+ readonly kind: 'reuse';
10
+ readonly eventId: string;
11
+ } | {
12
+ readonly kind: 'conflict';
13
+ readonly eventId: string;
14
+ };
15
+ /**
16
+ * Classify an apply intent against commits already issued in this scope.
17
+ * Same event with the same intent reuses the original result without a
18
+ * new event or cursor; the same event with a changed intent conflicts
19
+ * before any effect. Multiple `apply` contributions share one
20
+ * transaction and commit identity.
21
+ */
22
+ export declare const classifyCommitReplay: (committed: Readonly<Record<string, string>>, intent: MemoryCommitIdentity) => MemoryReplayDecision;
23
+ /** A conflicting intent must fail without writes, never overwrite. */
24
+ export declare const validateCommitReplay: (committed: Readonly<Record<string, string>>, intent: MemoryCommitIdentity) => ValidationResult;
25
+ //# sourceMappingURL=replay-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-policy.d.ts","sourceRoot":"","sources":["../../src/engram-memory/replay-policy.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAErF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,oBAAoB,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5D;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,cACpB,SAAS,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC,UACnC,oBAAoB,KAC3B,oBAQF,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,cACpB,SAAS,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC,UACnC,oBAAoB,KAC3B,gBAIF,CAAC"}