@sentropic/cluster-mesh 0.23.5 → 0.24.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 (149) hide show
  1. package/assets/storage/engram-memory/C6-FREEZE.md +63 -0
  2. package/assets/storage/engram-memory/contract-manifest.json +6 -4
  3. package/assets/storage/engram-memory/equivalence.json +1 -1
  4. package/assets/storage/engram-memory/neutral-asset-inventory.json +53 -0
  5. package/assets/storage/engram-memory/neutral-equivalence.json +44 -0
  6. package/assets/storage/postgres/007-consumed-counters.sql +17 -0
  7. package/assets/storage/postgres/008-instance-ownership.sql +35 -0
  8. package/assets/storage/postgres/engram-memory/001-projections.sql +14 -0
  9. package/assets/storage/postgres/engram-memory/002-host-ledger.sql +14 -0
  10. package/assets/storage/postgres/engram-memory/manifest.json +29 -0
  11. package/assets/storage/postgres/manifest.json +26 -0
  12. package/contracts/engram-memory-neutral-contract-v1.d.ts +367 -0
  13. package/dist/comments/postgres.d.ts +1 -0
  14. package/dist/comments/postgres.d.ts.map +1 -1
  15. package/dist/engram-memory/binding.d.ts +115 -0
  16. package/dist/engram-memory/binding.d.ts.map +1 -0
  17. package/dist/engram-memory/binding.js +239 -0
  18. package/dist/engram-memory/binding.js.map +1 -0
  19. package/dist/engram-memory/commit-result-recovery.d.ts +12 -0
  20. package/dist/engram-memory/commit-result-recovery.d.ts.map +1 -0
  21. package/dist/engram-memory/commit-result-recovery.js +14 -0
  22. package/dist/engram-memory/commit-result-recovery.js.map +1 -0
  23. package/dist/engram-memory/contract.d.ts +7 -1
  24. package/dist/engram-memory/contract.d.ts.map +1 -1
  25. package/dist/engram-memory/contract.js +7 -1
  26. package/dist/engram-memory/contract.js.map +1 -1
  27. package/dist/engram-memory/host-maintenance.d.ts +40 -0
  28. package/dist/engram-memory/host-maintenance.d.ts.map +1 -0
  29. package/dist/engram-memory/host-maintenance.js +44 -0
  30. package/dist/engram-memory/host-maintenance.js.map +1 -0
  31. package/dist/engram-memory/ledger.d.ts +75 -0
  32. package/dist/engram-memory/ledger.d.ts.map +1 -0
  33. package/dist/engram-memory/ledger.js +286 -0
  34. package/dist/engram-memory/ledger.js.map +1 -0
  35. package/dist/engram-memory/manifest.d.ts +1 -1
  36. package/dist/engram-memory/manifest.d.ts.map +1 -1
  37. package/dist/engram-memory/manifest.js +2 -1
  38. package/dist/engram-memory/manifest.js.map +1 -1
  39. package/dist/engram-memory/neutral-contract.d.ts +368 -0
  40. package/dist/engram-memory/neutral-contract.d.ts.map +1 -0
  41. package/dist/engram-memory/neutral-contract.js +39 -0
  42. package/dist/engram-memory/neutral-contract.js.map +1 -0
  43. package/dist/engram-memory/neutral-handle.d.ts +62 -0
  44. package/dist/engram-memory/neutral-handle.d.ts.map +1 -0
  45. package/dist/engram-memory/neutral-handle.js +131 -0
  46. package/dist/engram-memory/neutral-handle.js.map +1 -0
  47. package/dist/engram-memory/postgres-queries.d.ts +1 -1
  48. package/dist/engram-memory/postgres-queries.d.ts.map +1 -1
  49. package/dist/engram-memory/postgres-queries.js +111 -21
  50. package/dist/engram-memory/postgres-queries.js.map +1 -1
  51. package/dist/engram-memory/postgres.d.ts +51 -10
  52. package/dist/engram-memory/postgres.d.ts.map +1 -1
  53. package/dist/engram-memory/postgres.js +118 -17
  54. package/dist/engram-memory/postgres.js.map +1 -1
  55. package/dist/engram-memory/projection.d.ts +12 -0
  56. package/dist/engram-memory/projection.d.ts.map +1 -0
  57. package/dist/engram-memory/projection.js +123 -0
  58. package/dist/engram-memory/projection.js.map +1 -0
  59. package/dist/engram-memory/wire-adaptation.d.ts +61 -0
  60. package/dist/engram-memory/wire-adaptation.d.ts.map +1 -0
  61. package/dist/engram-memory/wire-adaptation.js +223 -0
  62. package/dist/engram-memory/wire-adaptation.js.map +1 -0
  63. package/dist/modules/catalog.js +1 -1
  64. package/dist/storage/atomic.d.ts +66 -1
  65. package/dist/storage/atomic.d.ts.map +1 -1
  66. package/dist/storage/atomic.js +173 -1
  67. package/dist/storage/atomic.js.map +1 -1
  68. package/dist/storage/backend.d.ts +3 -0
  69. package/dist/storage/backend.d.ts.map +1 -1
  70. package/dist/storage/backend.js +8 -0
  71. package/dist/storage/backend.js.map +1 -1
  72. package/dist/storage/contracts.d.ts +13 -0
  73. package/dist/storage/contracts.d.ts.map +1 -1
  74. package/dist/storage/contracts.js +12 -0
  75. package/dist/storage/contracts.js.map +1 -1
  76. package/dist/storage/instance-ownership.d.ts.map +1 -1
  77. package/dist/storage/instance-ownership.js +25 -7
  78. package/dist/storage/instance-ownership.js.map +1 -1
  79. package/dist/storage/postgres/codec.d.ts +1 -0
  80. package/dist/storage/postgres/codec.d.ts.map +1 -1
  81. package/dist/storage/postgres/codec.js +19 -0
  82. package/dist/storage/postgres/codec.js.map +1 -1
  83. package/dist/storage/postgres/commit-results.d.ts +6 -0
  84. package/dist/storage/postgres/commit-results.d.ts.map +1 -0
  85. package/dist/storage/postgres/commit-results.js +28 -0
  86. package/dist/storage/postgres/commit-results.js.map +1 -0
  87. package/dist/storage/postgres/core.d.ts +3 -1
  88. package/dist/storage/postgres/core.d.ts.map +1 -1
  89. package/dist/storage/postgres/core.js +99 -36
  90. package/dist/storage/postgres/core.js.map +1 -1
  91. package/dist/storage/postgres/effects.d.ts +1 -1
  92. package/dist/storage/postgres/effects.d.ts.map +1 -1
  93. package/dist/storage/postgres/effects.js +31 -6
  94. package/dist/storage/postgres/effects.js.map +1 -1
  95. package/dist/storage/postgres/errors.d.ts.map +1 -1
  96. package/dist/storage/postgres/errors.js +13 -0
  97. package/dist/storage/postgres/errors.js.map +1 -1
  98. package/dist/storage/postgres/index.d.ts +1 -0
  99. package/dist/storage/postgres/index.d.ts.map +1 -1
  100. package/dist/storage/postgres/index.js +1 -0
  101. package/dist/storage/postgres/index.js.map +1 -1
  102. package/dist/storage/postgres/instance-guard.d.ts +48 -0
  103. package/dist/storage/postgres/instance-guard.d.ts.map +1 -0
  104. package/dist/storage/postgres/instance-guard.js +147 -0
  105. package/dist/storage/postgres/instance-guard.js.map +1 -0
  106. package/dist/storage/postgres/instance-ownership.d.ts +22 -0
  107. package/dist/storage/postgres/instance-ownership.d.ts.map +1 -0
  108. package/dist/storage/postgres/instance-ownership.js +165 -0
  109. package/dist/storage/postgres/instance-ownership.js.map +1 -0
  110. package/dist/storage/postgres/journal.d.ts +24 -8
  111. package/dist/storage/postgres/journal.d.ts.map +1 -1
  112. package/dist/storage/postgres/journal.js +43 -32
  113. package/dist/storage/postgres/journal.js.map +1 -1
  114. package/dist/storage/postgres/migrations.d.ts +2 -1
  115. package/dist/storage/postgres/migrations.d.ts.map +1 -1
  116. package/dist/storage/postgres/migrations.js +14 -4
  117. package/dist/storage/postgres/migrations.js.map +1 -1
  118. package/dist/storage/postgres/ordinary-transactions.d.ts.map +1 -1
  119. package/dist/storage/postgres/ordinary-transactions.js +3 -2
  120. package/dist/storage/postgres/ordinary-transactions.js.map +1 -1
  121. package/dist/storage/postgres/profiles.d.ts +15 -8
  122. package/dist/storage/postgres/profiles.d.ts.map +1 -1
  123. package/dist/storage/postgres/protocol.d.ts +14 -0
  124. package/dist/storage/postgres/protocol.d.ts.map +1 -1
  125. package/dist/storage/postgres/protocol.js.map +1 -1
  126. package/dist/storage/postgres/queries.js +5 -5
  127. package/dist/storage/postgres/queries.js.map +1 -1
  128. package/dist/storage/postgres/readers.js +2 -2
  129. package/dist/storage/postgres/readers.js.map +1 -1
  130. package/dist/storage/postgres/roots.d.ts.map +1 -1
  131. package/dist/storage/postgres/roots.js +10 -6
  132. package/dist/storage/postgres/roots.js.map +1 -1
  133. package/dist/storage/postgres/scope.d.ts +17 -8
  134. package/dist/storage/postgres/scope.d.ts.map +1 -1
  135. package/dist/storage/postgres/scope.js +4 -0
  136. package/dist/storage/postgres/scope.js.map +1 -1
  137. package/dist/storage/postgres/snapshots.d.ts +2 -2
  138. package/dist/storage/postgres/snapshots.d.ts.map +1 -1
  139. package/dist/storage/postgres/snapshots.js +7 -4
  140. package/dist/storage/postgres/snapshots.js.map +1 -1
  141. package/dist/storage/postgres/transactions.d.ts +11 -0
  142. package/dist/storage/postgres/transactions.d.ts.map +1 -1
  143. package/dist/storage/postgres/transactions.js +21 -0
  144. package/dist/storage/postgres/transactions.js.map +1 -1
  145. package/dist/storage/u64.d.ts +18 -0
  146. package/dist/storage/u64.d.ts.map +1 -0
  147. package/dist/storage/u64.js +54 -0
  148. package/dist/storage/u64.js.map +1 -0
  149. package/package.json +3 -2
@@ -0,0 +1,239 @@
1
+ // engram-memory public host assembly (lot E7). The host composition owns
2
+ // the PG driver/pool lifecycle and a distinct host-issued maintain grant;
3
+ // Engram receives the neutral binding only (exactly ['read','write']).
4
+ // Assembly validates both authorities up front with typed refusals and
5
+ // returns a frozen binding. Neither the maintain grant nor any maintenance
6
+ // port escapes through the neutral memory handle. Storage opening stays
7
+ // refused until G1b wires the backend-backed resolver; this seam carries
8
+ // authority only.
9
+ import { randomUUID } from 'node:crypto';
10
+ import { validateScopeGrant } from '../storage/authority.js';
11
+ import { StorageDeniedError } from '../storage/errors.js';
12
+ import { validateStorageScope } from '../storage/contracts.js';
13
+ import { checkMemoryPostgresDriver } from './postgres.js';
14
+ /** The only operations Engram's neutral memory handle ever carries. */
15
+ export const MEMORY_HANDLE_OPERATIONS = ['read', 'write'];
16
+ /**
17
+ * Liveness of a maintain grant: it must carry the maintain operation and,
18
+ * for lease lifetimes, must not be expired. Revocation is checked against
19
+ * the live grants table by the G1b backend at use time; until then the
20
+ * fail-closed ports refuse everything anyway.
21
+ */
22
+ export const assertMaintainGrantLive = (grant, nowIso = new Date().toISOString()) => {
23
+ const candidate = grant;
24
+ if (typeof candidate !== 'object' || candidate === null || !Array.isArray(candidate.operations)) {
25
+ throw new StorageDeniedError('host binding requires a grant carrying the maintain operation');
26
+ }
27
+ if (!candidate.operations.includes('maintain')) {
28
+ throw new StorageDeniedError('host binding requires a grant carrying the maintain operation');
29
+ }
30
+ const lifetime = candidate.lifetime;
31
+ if (typeof lifetime === 'object' && lifetime !== null && lifetime.kind === 'lease') {
32
+ // Kernel lease semantics (contracts.ts): numeric Date.parse comparison,
33
+ // never lexicographic — offsets and precisions compare correctly.
34
+ const expiry = typeof lifetime.expiresAt === 'string' ? Date.parse(lifetime.expiresAt) : NaN;
35
+ if (!Number.isFinite(expiry) || expiry <= Date.parse(nowIso)) {
36
+ throw new StorageDeniedError('host maintain grant lease has expired');
37
+ }
38
+ }
39
+ };
40
+ const isExactMaintain = (grant) => Array.isArray(grant.operations) &&
41
+ grant.operations.length === 2 &&
42
+ grant.operations[0] === 'read' &&
43
+ grant.operations[1] === 'maintain';
44
+ /**
45
+ * Assemble the host binding: checked PG provider, a host-issued grant with
46
+ * exactly the `['read', 'maintain']` runner operations (a combined
47
+ * read/write/maintain grant is refused — it would leak maintain authority
48
+ * into the write path), and the derived neutral grant (exactly read/write)
49
+ * for the same scope. The two grants are separate objects; Engram receives
50
+ * only the neutral one.
51
+ */
52
+ export const assembleMemoryHostBinding = (input) => {
53
+ const provider = checkMemoryPostgresDriver(input?.driver);
54
+ const valid = validateScopeGrant(input?.maintainGrant, { expectedModuleId: 'engram-memory' });
55
+ if (!valid.ok)
56
+ throw new StorageDeniedError('host binding requires a valid maintain grant');
57
+ const grant = input.maintainGrant;
58
+ assertMaintainGrantLive(grant);
59
+ if (!isExactMaintain(grant)) {
60
+ throw new StorageDeniedError('host maintain grant must carry exactly the maintain operation');
61
+ }
62
+ if (typeof input?.invocationId !== 'string' || input.invocationId.length === 0) {
63
+ throw new StorageDeniedError('host binding requires a host invocation identity');
64
+ }
65
+ if (typeof input?.storeId !== 'string' || input.storeId.length === 0) {
66
+ throw new StorageDeniedError('host binding requires the served store identity');
67
+ }
68
+ const neutral = Object.freeze({
69
+ token: `memory-neutral-${grant.scope.tenantId}-${grant.scope.workspaceId}-${input.invocationId}`,
70
+ moduleId: grant.moduleId,
71
+ scope: grant.scope,
72
+ principalId: grant.principalId,
73
+ operations: MEMORY_HANDLE_OPERATIONS,
74
+ issuer: grant.issuer,
75
+ authorityRevision: grant.authorityRevision,
76
+ policyRevision: grant.policyRevision,
77
+ moduleAuthority: null,
78
+ lifetime: Object.freeze({ kind: 'invocation', invocationId: input.invocationId }),
79
+ });
80
+ return Object.freeze({
81
+ provider,
82
+ maintainGrant: grant,
83
+ memoryGrant: neutral,
84
+ memoryOperations: MEMORY_HANDLE_OPERATIONS,
85
+ storeId: input.storeId,
86
+ });
87
+ };
88
+ /**
89
+ * Verify the binding against the kernel's authoritative grants table by
90
+ * binding the maintain grant: a revoked or never-issued grant is refused
91
+ * by the store itself, not by a local copy. An optional expected scope
92
+ * pins the binding to one scope — a foreign scope is refused even with a
93
+ * live grant. The binder is the kernel's `bind` (check-only, no issue).
94
+ */
95
+ export const verifyHostBinding = async (binder, binding, scope, storeId) => {
96
+ if (typeof binding !== 'object' || binding === null) {
97
+ throw new StorageDeniedError('host binding verification requires an assembled binding');
98
+ }
99
+ assertMaintainGrantLive(binding.maintainGrant);
100
+ if (storeId !== undefined && storeId !== binding.storeId) {
101
+ throw new StorageDeniedError('host binding store does not match the served store');
102
+ }
103
+ if (scope !== undefined) {
104
+ if (scope.tenantId !== binding.maintainGrant.scope.tenantId ||
105
+ scope.workspaceId !== binding.maintainGrant.scope.workspaceId) {
106
+ throw new StorageDeniedError('host binding scope does not match the maintain grant scope');
107
+ }
108
+ }
109
+ await binder.bind(binding.maintainGrant);
110
+ };
111
+ /**
112
+ * Issue the explicit host-controlled continuation grant for a retained
113
+ * candidate. The ledger must already hold the candidate (refusing on an
114
+ * empty or unknown ledger is correct until rehydration); the grant scope
115
+ * always comes from the retained record, so a foreign scope can never be
116
+ * minted; the attestation must carry a fresh invocation identity with host
117
+ * authn. Copied fields never grant: reusing the retained or an
118
+ * already-recorded invocation is refused by the ledger. The grant carries
119
+ * only the neutral operations with the new invocation lifetime, bound to
120
+ * the retained candidate and scope.
121
+ */
122
+ export const issueContinuationGrant = async (ledger, binding, candidateId, attestation, authority) => {
123
+ const retained = await ledger.read(candidateId);
124
+ if (!retained)
125
+ throw new StorageDeniedError('no retained authority for this candidate');
126
+ if (retained.state === 'terminal') {
127
+ throw new StorageDeniedError('completed candidates cannot continue');
128
+ }
129
+ checkBindingScope(binding, retained, 'continuation');
130
+ if (typeof attestation !== 'object' ||
131
+ attestation === null ||
132
+ typeof attestation.invocationId !== 'string' ||
133
+ attestation.invocationId.length === 0 ||
134
+ typeof attestation.issuedAt !== 'string' ||
135
+ attestation.issuedAt.length === 0 ||
136
+ typeof attestation.hostPrincipal !== 'string' ||
137
+ attestation.hostPrincipal.length === 0) {
138
+ throw new StorageDeniedError('continuation requires fresh host authentication');
139
+ }
140
+ if (attestation.hostPrincipal !== retained.hostPrincipal) {
141
+ throw new StorageDeniedError('continuation requires the original host principal');
142
+ }
143
+ if (binding.maintainGrant.principalId !== retained.hostPrincipal) {
144
+ throw new StorageDeniedError('continuation binding serves a different host principal');
145
+ }
146
+ // Revocation is checked against the grants table before any effect: a
147
+ // revoked maintain grant cannot mint a continuation.
148
+ await authority.bind(binding.maintainGrant);
149
+ const updated = await ledger.recordContinuation(candidateId, attestation.invocationId);
150
+ const grant = Object.freeze({
151
+ token: `memory-continuation-${randomUUID()}`,
152
+ moduleId: 'engram-memory',
153
+ scope: updated.scope,
154
+ principalId: attestation.hostPrincipal,
155
+ operations: MEMORY_HANDLE_OPERATIONS,
156
+ issuer: binding.maintainGrant.issuer,
157
+ authorityRevision: binding.maintainGrant.authorityRevision,
158
+ policyRevision: binding.maintainGrant.policyRevision,
159
+ moduleAuthority: null,
160
+ lifetime: Object.freeze({ kind: 'invocation', invocationId: attestation.invocationId }),
161
+ });
162
+ return {
163
+ candidateId: updated.candidateId,
164
+ storeId: updated.storeId,
165
+ grant,
166
+ };
167
+ };
168
+ /** Spent or never-tracked candidate: the host ledger holds no entry. */
169
+ export class MemoryMaintenanceNotFoundError extends Error {
170
+ code = 'NOT_FOUND';
171
+ constructor(candidateId) {
172
+ super(`NOT_FOUND: no host ledger entry for memory candidate '${candidateId}'`);
173
+ this.name = 'MemoryMaintenanceNotFoundError';
174
+ }
175
+ }
176
+ const checkBindingScope = (binding, retained, what) => {
177
+ if (retained.scope.tenantId !== binding.maintainGrant.scope.tenantId ||
178
+ retained.scope.workspaceId !== binding.maintainGrant.scope.workspaceId) {
179
+ throw new StorageDeniedError(`${what} scope does not match the maintain grant scope`);
180
+ }
181
+ if (retained.storeId !== binding.storeId) {
182
+ throw new StorageDeniedError(`${what} store does not match the served store`);
183
+ }
184
+ };
185
+ /**
186
+ * Reattach a host maintenance session to a retained candidate. An unknown
187
+ * candidate — never tracked, or drained after its invocation was spent —
188
+ * surfaces NOT_FOUND (never a refusal and never a fresh reservation). A
189
+ * foreign scope is refused; an expired maintain grant cannot reattach.
190
+ */
191
+ export const reattachMemoryMaintenance = async (binding, ledger, candidateId, authority) => {
192
+ if (typeof binding !== 'object' || binding === null) {
193
+ throw new StorageDeniedError('memory reattach requires an assembled binding');
194
+ }
195
+ const retained = await ledger.read(candidateId);
196
+ if (!retained)
197
+ throw new MemoryMaintenanceNotFoundError(candidateId);
198
+ checkBindingScope(binding, retained, 'reattach');
199
+ assertMaintainGrantLive(binding.maintainGrant);
200
+ // A revoked maintain grant cannot reattach, even to a retained candidate.
201
+ await authority.bind(binding.maintainGrant);
202
+ return binding.maintainGrant;
203
+ };
204
+ /**
205
+ * Proof-only recovery through the host binding (E8 answer 4): the caller
206
+ * must hold a live maintain grant for the retained scope — a foreign
207
+ * scope is refused even with a live grant. Unknown or drained candidates
208
+ * are refused; use reattach to distinguish the spent (NOT_FOUND) case.
209
+ * By construction this path cannot write.
210
+ */
211
+ export const proveForRecoveryAuthorized = async (ledger, binding, candidateId, scope, authority) => {
212
+ if (typeof binding !== 'object' || binding === null) {
213
+ throw new StorageDeniedError('authorized recovery requires an assembled binding');
214
+ }
215
+ assertMaintainGrantLive(binding.maintainGrant);
216
+ const retained = await ledger.read(candidateId);
217
+ if (!retained)
218
+ throw new StorageDeniedError('no retained evidence for this candidate');
219
+ checkBindingScope(binding, retained, 'recovery');
220
+ // Proof-only, but not revocation-free: a revoked grant proves nothing.
221
+ await authority.bind(binding.maintainGrant);
222
+ if (scope !== undefined) {
223
+ if (!validateStorageScope(scope).ok)
224
+ throw new StorageDeniedError('recovery scope must be valid');
225
+ if (scope.tenantId !== retained.scope.tenantId || scope.workspaceId !== retained.scope.workspaceId) {
226
+ throw new StorageDeniedError('recovery scope does not match the retained evidence');
227
+ }
228
+ }
229
+ return Object.freeze({
230
+ candidateId: retained.candidateId,
231
+ storeId: retained.storeId,
232
+ scope: retained.scope,
233
+ envelopeDigest: retained.envelopeDigest,
234
+ state: retained.state,
235
+ receipt: retained.receipt,
236
+ cursor: retained.cursor,
237
+ });
238
+ };
239
+ //# sourceMappingURL=binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.js","sourceRoot":"","sources":["../../src/engram-memory/binding.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,0EAA0E;AAC1E,uEAAuE;AACvE,uEAAuE;AACvE,2EAA2E;AAC3E,wEAAwE;AACxE,yEAAyE;AACzE,kBAAkB;AAElB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAmB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAqB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAqC,MAAM,eAAe,CAAC;AAG7F,uEAAuE;AACvE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAc,EAAE,SAAiB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAQ,EAAE;IACzG,MAAM,SAAS,GAAG,KAAwD,CAAC;IAC3E,IAAI,OAAO,SAAS,KAAK,QAAQ,I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,CAAC;IAC/C,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAChD,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,kBAAkB,CAAC,yCAAyC,CAAC,CAAC;IACvF,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACjD,uEAAuE;IACvE,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,EAAE;YAAE,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;QAClG,IAAI,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,WAAW,KAAK,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;YACnG,MAAM,IAAI,kBAAkB,CAAC,qDAAqD,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,cAAc,EAAE,QAAQ,CAAC,cAAc;QACvC,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { EncodedValue, WriterFence } from '../storage/contracts.js';
2
+ import type { NeutralBoundScope } from './neutral-contract.js';
3
+ /** A bound backend owns scope/grant checks and validates this fence in its lookup transaction. */
4
+ export interface MemoryCommitResultSource {
5
+ readCommitResult(commitIdentity: string, fence: WriterFence): Promise<EncodedValue | null>;
6
+ }
7
+ /**
8
+ * E7 supplies its current host-owned fence. This identity-only reader does
9
+ * not classify retry intents: the adapter does that before effects (§5.3).
10
+ */
11
+ export declare const createMemoryCommitResultRecovery: (source: MemoryCommitResultSource, currentFence: () => Promise<WriterFence>) => NonNullable<NeutralBoundScope['readCommitResult']>;
12
+ //# sourceMappingURL=commit-result-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-result-recovery.d.ts","sourceRoot":"","sources":["../../src/engram-memory/commit-result-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,kGAAkG;AAClG,MAAM,WAAW,wBAAwB;IACvC,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;CAC5F;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,WACnC,wBAAwB,gBAClB,MAAM,QAAQ,WAAW,CAAC,KACvC,YAAY,iBAAiB,CAAC,kBAAkB,CAAC,CAKnD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { StorageUnavailableError } from '../storage/errors.js';
2
+ /**
3
+ * E7 supplies its current host-owned fence. This identity-only reader does
4
+ * not classify retry intents: the adapter does that before effects (§5.3).
5
+ */
6
+ export const createMemoryCommitResultRecovery = (source, currentFence) => async (commitIdentity) => {
7
+ const result = await source.readCommitResult(commitIdentity, await currentFence());
8
+ if (result === null)
9
+ return null;
10
+ if (result.format !== 'utf8')
11
+ throw new StorageUnavailableError('memory original result must be UTF-8');
12
+ return { format: result.format, data: result.data };
13
+ };
14
+ //# sourceMappingURL=commit-result-recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-result-recovery.js","sourceRoot":"","sources":["../../src/engram-memory/commit-result-recovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAO/D;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,MAAgC,EAChC,YAAwC,EACY,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE;IAChF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,MAAM,YAAY,EAAE,CAAC,CAAC;IACnF,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM;QAAE,MAAM,IAAI,uBAAuB,CAAC,sCAAsC,CAAC,CAAC;IACxG,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AACtD,CAAC,CAAC"}
@@ -4,10 +4,16 @@ export { canonicalizeMemoryJcs, normalizeMemoryCanonicalJson, memoryRecordKey, m
4
4
  export { MEMORY_SINGLE_EVENT_LIMITS, MEMORY_CAPTURE_COMPLETION_LIMITS, MEMORY_MAINTENANCE_LIMITS, MEMORY_IMPORT_LIMITS, MEMORY_STORAGE_LIMITS, requireMemoryStorageLimits, } from './limits.js';
5
5
  export { validateCaptureTransition, validateAdmissionTransition, isMemoryCaptureProof, isMemoryAdmissionOutcome, type MemoryCaptureProof, type MemoryAdmissionOutcome, } from './validation.js';
6
6
  export { classifyCommitReplay, validateCommitReplay, type MemoryCommitIdentity, type MemoryReplayDecision, } from './replay-policy.js';
7
- export { createMemoryPostgresRegistration, createMemoryPostgresStorage, resolveMemoryCurrentFromAggregates, validateMemoryEffects, type MemoryCurrentStateResolver, type MemoryPostgresRegistration, type MemoryStoredAggregate, } from './postgres.js';
7
+ export { createMemoryCommitResultRecovery, type MemoryCommitResultSource } from './commit-result-recovery.js';
8
+ export { createMemoryPostgresRegistration, createMemoryPostgresStorage, checkMemoryPostgresDriver, verifyMemoryPostgresProvider, resolveMemoryCurrentFromAggregates, validateMemoryEffects, type MemoryCurrentStateResolver, type MemoryPostgresRegistration, type MemoryPostgresDriverProvider, type MemoryStoredAggregate, } from './postgres.js';
8
9
  export { MEMORY_PG_QUERIES, memoryPgQuery, isMemoryQueryName, validateMemoryPageInput, validateMemoryRecordByIdInput, validateMemorySnapshotInput, type MemoryQueryName, } from './postgres-queries.js';
9
10
  export { createMemorySqliteRegistration, createMemorySqliteStorage, checkMemorySqliteDriver, MemoryHostDriverRequiredError, MEMORY_SQLITE_ENGINE_FLOOR, MEMORY_SQLITE_QUALIFICATION, type MemorySqliteDriverProvider, type MemorySqliteDriverIdentity, type MemorySqliteQualification, type MemorySqliteRegistration, type MemorySqliteStorageOptions, } from './sqlite.js';
10
11
  export { MEMORY_SQLITE_QUERIES, memorySqliteQuery, MEMORY_SQLITE_QUERY_NAMES, } from './sqlite-queries.js';
12
+ export { MEMORY_HANDLE_OPERATIONS, assembleMemoryHostBinding, assertMaintainGrantLive, verifyHostBinding, issueContinuationGrant, reattachMemoryMaintenance, proveForRecoveryAuthorized, MemoryMaintenanceNotFoundError, type MemoryAuthorityCheck, type MemoryMaintainGrant, type MemoryNeutralGrant, type MemoryHostBinding, type MemoryHostBindingInput, type MemoryContinuation, type MemoryContinuationAttestation, } from './binding.js';
13
+ export { openMemoryMaintenance, type MemoryMaintenancePorts, type MemoryMaintenanceRunner, } from './host-maintenance.js';
14
+ export { createMemoryHostLedger, createMemoryHostLedgerAsync, openMemoryPostgresHostLedger, proveForRecovery, type HostLedgerEntry, type HostLedgerState, type HostRecoveryProof, type MemoryAuthorityLedger, type MemoryHostLedger, type MemoryPostgresHostLedger, } from './ledger.js';
15
+ export { captureProofToKernel, captureProofToWire, createMemoryNeutralTransaction, isMemoryCaptureKey, isMemoryOutcomeKey, journalBytesWithIntentHash, memoryCommitIndexKey, memoryNeutralFailure, neutralQueryResult, neutralUnitToPg, stripJournalIntentHash, translateMemoryAggregateRead, translateMemoryUpdateWrite, type MemoryKernelTransactionPort, } from './wire-adaptation.js';
16
+ export { createMemoryNeutralHandle, type CreateMemoryNeutralHandleInput, type MemoryNeutralBoundPort, type MemoryNeutralHandleAssembly, type MemoryNeutralHostDriver, type MemoryNeutralHostSession, type MemoryNeutralKernelPort, } from './neutral-handle.js';
11
17
  /** Reserved trusted-service options for the memory module. No service is required in G1a. */
12
18
  export interface MemoryServiceOptions {
13
19
  readonly services?: Record<string, never>;
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/engram-memory/contract.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,SAAS,EACT,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,GAC3B,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,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,EAC1B,KAAK,2BAA2B,GACjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,yBAAyB,EACzB,KAAK,8BAA8B,EACnC,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,GAC7B,MAAM,qBAAqB,CAAC;AAE7B,6FAA6F;AAC7F,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC3C"}
@@ -9,8 +9,14 @@ export { canonicalizeMemoryJcs, normalizeMemoryCanonicalJson, memoryRecordKey, m
9
9
  export { MEMORY_SINGLE_EVENT_LIMITS, MEMORY_CAPTURE_COMPLETION_LIMITS, MEMORY_MAINTENANCE_LIMITS, MEMORY_IMPORT_LIMITS, MEMORY_STORAGE_LIMITS, requireMemoryStorageLimits, } from './limits.js';
10
10
  export { validateCaptureTransition, validateAdmissionTransition, isMemoryCaptureProof, isMemoryAdmissionOutcome, } from './validation.js';
11
11
  export { classifyCommitReplay, validateCommitReplay, } from './replay-policy.js';
12
- export { createMemoryPostgresRegistration, createMemoryPostgresStorage, resolveMemoryCurrentFromAggregates, validateMemoryEffects, } from './postgres.js';
12
+ export { createMemoryCommitResultRecovery } from './commit-result-recovery.js';
13
+ export { createMemoryPostgresRegistration, createMemoryPostgresStorage, checkMemoryPostgresDriver, verifyMemoryPostgresProvider, resolveMemoryCurrentFromAggregates, validateMemoryEffects, } from './postgres.js';
13
14
  export { MEMORY_PG_QUERIES, memoryPgQuery, isMemoryQueryName, validateMemoryPageInput, validateMemoryRecordByIdInput, validateMemorySnapshotInput, } from './postgres-queries.js';
14
15
  export { createMemorySqliteRegistration, createMemorySqliteStorage, checkMemorySqliteDriver, MemoryHostDriverRequiredError, MEMORY_SQLITE_ENGINE_FLOOR, MEMORY_SQLITE_QUALIFICATION, } from './sqlite.js';
15
16
  export { MEMORY_SQLITE_QUERIES, memorySqliteQuery, MEMORY_SQLITE_QUERY_NAMES, } from './sqlite-queries.js';
17
+ export { MEMORY_HANDLE_OPERATIONS, assembleMemoryHostBinding, assertMaintainGrantLive, verifyHostBinding, issueContinuationGrant, reattachMemoryMaintenance, proveForRecoveryAuthorized, MemoryMaintenanceNotFoundError, } from './binding.js';
18
+ export { openMemoryMaintenance, } from './host-maintenance.js';
19
+ export { createMemoryHostLedger, createMemoryHostLedgerAsync, openMemoryPostgresHostLedger, proveForRecovery, } from './ledger.js';
20
+ export { captureProofToKernel, captureProofToWire, createMemoryNeutralTransaction, isMemoryCaptureKey, isMemoryOutcomeKey, journalBytesWithIntentHash, memoryCommitIndexKey, memoryNeutralFailure, neutralQueryResult, neutralUnitToPg, stripJournalIntentHash, translateMemoryAggregateRead, translateMemoryUpdateWrite, } from './wire-adaptation.js';
21
+ export { createMemoryNeutralHandle, } from './neutral-handle.js';
16
22
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/engram-memory/contract.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAC1E,wEAAwE;AACxE,sCAAsC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAE1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,SAAS,EACT,wBAAwB,GAGzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,oBAAoB,EACpB,wBAAwB,GAGzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GAGrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,gCAAgC,EAChC,2BAA2B,EAC3B,kCAAkC,EAClC,qBAAqB,GAItB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,uBAAuB,EACvB,6BAA6B,EAC7B,2BAA2B,GAE5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,EAC1B,2BAA2B,GAM5B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/engram-memory/contract.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAC1E,wEAAwE;AACxE,sCAAsC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EA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AE5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,EAC1B,2BAA2B,GAM5B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,8BAA8B,GAQ/B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,GAGtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,4BAA4B,EAC5B,gBAAgB,GAOjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,8BAA8B,EAC9B,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,GAE3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,yBAAyB,GAO1B,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { ScopeGrant } from '../storage/authority.js';
2
+ import type { PgPosition } from '../storage/postgres/journal.js';
3
+ import type { JournalFence } from '../storage/staged-core.js';
4
+ import { type MemoryHostBinding } from './binding.js';
5
+ /** Kernel calls behind the ports, already bound to the maintain grant. */
6
+ export interface MemoryMaintenanceRunner {
7
+ readonly grant: ScopeGrant<unknown>;
8
+ readonly currentFence: () => Promise<JournalFence>;
9
+ readonly checkpoint: (consumer: string, expected: PgPosition, next: PgPosition, fence: JournalFence) => Promise<void>;
10
+ readonly poison: (consumer: string, event: string, reason: string) => Promise<void>;
11
+ readonly retry: (consumer: string, expected: string | null, fence: JournalFence) => Promise<void>;
12
+ readonly resync: (consumer: string, fence: JournalFence) => Promise<{
13
+ snapshotRoot: string;
14
+ journalSeq: string;
15
+ }>;
16
+ readonly snapshot: (token: string, after: number, limit: number) => Promise<{
17
+ rows: readonly unknown[];
18
+ }>;
19
+ }
20
+ export interface MemoryMaintenancePorts {
21
+ readonly checkFence: (fence: JournalFence) => Promise<JournalFence>;
22
+ readonly checkpoint: (consumer: string, expected: PgPosition, next: PgPosition, fence: JournalFence) => Promise<void>;
23
+ readonly poison: (consumer: string, event: string, reason: string) => Promise<void>;
24
+ readonly retry: (consumer: string, expected: string | null, fence: JournalFence) => Promise<void>;
25
+ readonly resync: (consumer: string, fence: JournalFence) => Promise<{
26
+ snapshotRoot: string;
27
+ journalSeq: string;
28
+ }>;
29
+ readonly snapshot: (token: string, after: number, limit: number) => Promise<{
30
+ rows: readonly unknown[];
31
+ }>;
32
+ }
33
+ /**
34
+ * Open the host-only maintenance ports. The binding is re-validated
35
+ * (checked provider plus live maintain grant) and the runner must carry
36
+ * the binding's exact grant object — an ad-hoc runner, or one bound to
37
+ * the neutral handle, cannot open ports.
38
+ */
39
+ export declare const openMemoryMaintenance: (binding: MemoryHostBinding, runner: MemoryMaintenanceRunner) => MemoryMaintenancePorts;
40
+ //# sourceMappingURL=host-maintenance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-maintenance.d.ts","sourceRoot":"","sources":["../../src/engram-memory/host-maintenance.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAG/E,0EAA0E;AAC1E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,UA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CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,QAAQ,CAAC,KAAK,EAAE,CACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,EAAE,YAAY,KAChB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,YAAY,KAChB,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3D,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,KACV,OAAO,CAAC;QAAE,IAAI,EAAE,SAAS,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;CAC5C;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,YACvB,iBAAiB,UAClB,uBAAuB,KAC9B,sBA6BF,CAAC"}
@@ -0,0 +1,44 @@
1
+ // Host-only maintenance ports (lot E7). The host composition opens these
2
+ // from an assembled binding plus a runner bound to the binding's maintain
3
+ // grant: the ports delegate fence/checkpoint/poison/retry/resync/snapshot
4
+ // to the kernel, which enforces the maintain authority on every call. A
5
+ // runner bound to any other grant (including the neutral handle) is
6
+ // refused by grant identity — the ports never run on another authority.
7
+ import { StorageDeniedError } from '../storage/errors.js';
8
+ import { assertMaintainGrantLive } from './binding.js';
9
+ import { checkMemoryPostgresDriver } from './postgres.js';
10
+ /**
11
+ * Open the host-only maintenance ports. The binding is re-validated
12
+ * (checked provider plus live maintain grant) and the runner must carry
13
+ * the binding's exact grant object — an ad-hoc runner, or one bound to
14
+ * the neutral handle, cannot open ports.
15
+ */
16
+ export const openMemoryMaintenance = (binding, runner) => {
17
+ if (typeof binding !== 'object' || binding === null) {
18
+ throw new StorageDeniedError('memory maintenance requires an assembled binding');
19
+ }
20
+ checkMemoryPostgresDriver(binding.provider);
21
+ assertMaintainGrantLive(binding.maintainGrant);
22
+ if (typeof runner !== 'object' || runner === null || runner.grant !== binding.maintainGrant) {
23
+ throw new StorageDeniedError('memory maintenance requires a runner bound to this binding');
24
+ }
25
+ const ports = {
26
+ checkFence: async (fence) => {
27
+ const current = await runner.currentFence();
28
+ if (current.fenceId !== fence.fenceId ||
29
+ current.epoch !== fence.epoch ||
30
+ current.incarnation !== fence.incarnation ||
31
+ current.ownerId !== fence.ownerId) {
32
+ throw new StorageDeniedError('maintenance fence is not current');
33
+ }
34
+ return current;
35
+ },
36
+ checkpoint: (consumer, expected, next, fence) => runner.checkpoint(consumer, expected, next, fence),
37
+ poison: (consumer, event, reason) => runner.poison(consumer, event, reason),
38
+ retry: (consumer, expected, fence) => runner.retry(consumer, expected, fence),
39
+ resync: (consumer, fence) => runner.resync(consumer, fence),
40
+ snapshot: (token, after, limit) => runner.snapshot(token, after, limit),
41
+ };
42
+ return Object.freeze(ports);
43
+ };
44
+ //# sourceMappingURL=host-maintenance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-maintenance.js","sourceRoot":"","sources":["../../src/engram-memory/host-maintenance.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,0EAA0E;AAC1E,0EAA0E;AAC1E,wEAAwE;AACxE,oEAAoE;AACpE,wEAAwE;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,uBAAuB,EAA0B,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAsD1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,OAA0B,EAC1B,MAA+B,EACP,EAAE;IAC1B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAA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AK,CAAC;QAC7E,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC;QAC3D,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;KACxE,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type StorageScope } from '../storage/contracts.js';
2
+ import { type InjectedPgDriver } from '../storage/postgres/protocol.js';
3
+ export type HostLedgerState = 'reserved' | 'terminal' | 'ambiguous';
4
+ export interface HostLedgerEntry {
5
+ readonly candidateId: string;
6
+ readonly storeId: string;
7
+ readonly scope: StorageScope;
8
+ readonly invocationId: string;
9
+ readonly hostPrincipal: string;
10
+ readonly continuationIds: readonly string[];
11
+ readonly envelopeDigest: string;
12
+ readonly state: HostLedgerState;
13
+ readonly receipt: unknown;
14
+ readonly cursor: string | null;
15
+ }
16
+ export interface MemoryHostLedger {
17
+ readonly record: (entry: HostLedgerEntry) => HostLedgerEntry;
18
+ readonly read: (candidateId: string) => HostLedgerEntry | null;
19
+ readonly recordContinuation: (candidateId: string, invocationId: string) => HostLedgerEntry;
20
+ readonly markTerminal: (candidateId: string, receipt: unknown, cursor: string | null) => HostLedgerEntry;
21
+ /**
22
+ * Drop every entry of a spent invocation (terminal candidates whose
23
+ * continuation window closed). A later reattach for a drained candidate
24
+ * surfaces NOT_FOUND; proof-only recovery is impossible once drained.
25
+ */
26
+ readonly drainInvocation: (invocationId: string) => number;
27
+ readonly snapshot: () => readonly HostLedgerEntry[];
28
+ readonly restore: (entries: readonly HostLedgerEntry[]) => void;
29
+ }
30
+ /** Read-only recovery evidence: envelope binding, state, receipt and cursor. */
31
+ export interface HostRecoveryProof {
32
+ readonly candidateId: string;
33
+ readonly storeId: string;
34
+ readonly scope: StorageScope;
35
+ readonly envelopeDigest: string;
36
+ readonly state: HostLedgerState;
37
+ readonly receipt: unknown;
38
+ readonly cursor: string | null;
39
+ }
40
+ /**
41
+ * Proof-only recovery (E8 answer 4): return the retained evidence for
42
+ * admission-outcome recovery and journal-replay decisions without applying
43
+ * any effect. Unknown candidates and foreign scopes are refused; an empty
44
+ * ledger refuses. By construction this path cannot write.
45
+ */
46
+ export declare const proveForRecovery: (ledger: MemoryHostLedger, candidateId: string, scope?: StorageScope) => HostRecoveryProof;
47
+ /** In-memory ledger for composition and tests; the durable PG backing lands with the ledger asset. */
48
+ export declare const createMemoryHostLedger: () => MemoryHostLedger;
49
+ /**
50
+ * PG-backed host ledger (P1-5, asset `002-host-ledger.sql`). Same
51
+ * first-write-wins semantics as the in-memory ledger, persisted per row in
52
+ * `memory_host_ledger`. The table is applied by the migration owner (E2
53
+ * wires the 002 asset into the manifest); opening against a schema without
54
+ * the table is refused. Rehydration across a real reopen is a fresh handle
55
+ * over the same schema — `snapshot()` feeds the in-memory authority seam.
56
+ */
57
+ export interface MemoryPostgresHostLedger {
58
+ readonly record: (entry: HostLedgerEntry) => Promise<HostLedgerEntry>;
59
+ readonly read: (candidateId: string) => Promise<HostLedgerEntry | null>;
60
+ readonly recordContinuation: (candidateId: string, invocationId: string) => Promise<HostLedgerEntry>;
61
+ readonly markTerminal: (candidateId: string, receipt: unknown, cursor: string | null) => Promise<HostLedgerEntry>;
62
+ readonly drainInvocation: (invocationId: string) => Promise<number>;
63
+ readonly snapshot: () => Promise<readonly HostLedgerEntry[]>;
64
+ }
65
+ /**
66
+ * Authority ledger port: the async surface the host authority functions
67
+ * run on (r2 P1-E). The PG ledger implements it durably; the in-memory
68
+ * adapter below implements it for composition and tests. Single-threaded
69
+ * memory updates are inherently atomic; PG updates guard in the statement.
70
+ */
71
+ export type MemoryAuthorityLedger = MemoryPostgresHostLedger;
72
+ /** In-memory implementation of the authority ledger port (composition/tests). */
73
+ export declare const createMemoryHostLedgerAsync: () => MemoryAuthorityLedger;
74
+ export declare const openMemoryPostgresHostLedger: (pool: InjectedPgDriver, schema: string) => Promise<MemoryPostgresHostLedger>;
75
+ //# sourceMappingURL=ledger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/engram-memory/ledger.ts"],"names":[],"mappings":"AASA,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAqB,KAAK,gBAAgB,EAAkB,MAAM,iCAAiC,CAAC;AAE3G,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,eAAe,CAAC;IAC7D,QAAQ,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,eAAe,GAAG,IAAI,CAAC;IAC/D,QAAQ,CAAC,kBAAkB,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,eAAe,CAAC;IAC5F,QAAQ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