@cotal-ai/auth 0.12.0 → 0.13.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 (95) hide show
  1. package/dist/admission-mediator.d.ts +319 -0
  2. package/dist/admission-mediator.d.ts.map +1 -0
  3. package/dist/admission-mediator.js +1033 -0
  4. package/dist/admission-mediator.js.map +1 -0
  5. package/dist/auth-admin.d.ts +29 -0
  6. package/dist/auth-admin.d.ts.map +1 -0
  7. package/dist/auth-admin.js +224 -0
  8. package/dist/auth-admin.js.map +1 -0
  9. package/dist/authority-client.d.ts +215 -0
  10. package/dist/authority-client.d.ts.map +1 -0
  11. package/dist/authority-client.js +346 -0
  12. package/dist/authority-client.js.map +1 -0
  13. package/dist/barrier-evict.d.ts +16 -0
  14. package/dist/barrier-evict.d.ts.map +1 -0
  15. package/dist/barrier-evict.js +100 -0
  16. package/dist/barrier-evict.js.map +1 -0
  17. package/dist/connect-reader.d.ts +72 -0
  18. package/dist/connect-reader.d.ts.map +1 -0
  19. package/dist/connect-reader.js +154 -0
  20. package/dist/connect-reader.js.map +1 -0
  21. package/dist/continuity.d.ts.map +1 -1
  22. package/dist/continuity.js +3 -0
  23. package/dist/continuity.js.map +1 -1
  24. package/dist/credential-ledger.d.ts +343 -0
  25. package/dist/credential-ledger.d.ts.map +1 -0
  26. package/dist/credential-ledger.js +732 -0
  27. package/dist/credential-ledger.js.map +1 -0
  28. package/dist/drain-repair.d.ts +95 -0
  29. package/dist/drain-repair.d.ts.map +1 -0
  30. package/dist/drain-repair.js +305 -0
  31. package/dist/drain-repair.js.map +1 -0
  32. package/dist/idp.d.ts +19 -0
  33. package/dist/idp.d.ts.map +1 -1
  34. package/dist/idp.js +17 -0
  35. package/dist/idp.js.map +1 -1
  36. package/dist/index.d.ts +5 -2
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +29 -2
  39. package/dist/index.js.map +1 -1
  40. package/dist/issuer.d.ts +8 -0
  41. package/dist/issuer.d.ts.map +1 -1
  42. package/dist/issuer.js +4 -2
  43. package/dist/issuer.js.map +1 -1
  44. package/dist/ledger-scanner.d.ts +98 -0
  45. package/dist/ledger-scanner.d.ts.map +1 -0
  46. package/dist/ledger-scanner.js +352 -0
  47. package/dist/ledger-scanner.js.map +1 -0
  48. package/dist/ledger.d.ts +7 -0
  49. package/dist/ledger.d.ts.map +1 -1
  50. package/dist/ledger.js +53 -5
  51. package/dist/ledger.js.map +1 -1
  52. package/dist/lifecycle-registry.d.ts +397 -0
  53. package/dist/lifecycle-registry.d.ts.map +1 -0
  54. package/dist/lifecycle-registry.js +819 -0
  55. package/dist/lifecycle-registry.js.map +1 -0
  56. package/dist/permissions.d.ts +5 -1
  57. package/dist/permissions.d.ts.map +1 -1
  58. package/dist/permissions.js +29 -6
  59. package/dist/permissions.js.map +1 -1
  60. package/dist/plane-claim.d.ts +83 -0
  61. package/dist/plane-claim.d.ts.map +1 -0
  62. package/dist/plane-claim.js +290 -0
  63. package/dist/plane-claim.js.map +1 -0
  64. package/dist/provider.d.ts.map +1 -1
  65. package/dist/provider.js +2 -1
  66. package/dist/provider.js.map +1 -1
  67. package/dist/records-scanner.d.ts +78 -0
  68. package/dist/records-scanner.d.ts.map +1 -0
  69. package/dist/records-scanner.js +320 -0
  70. package/dist/records-scanner.js.map +1 -0
  71. package/dist/retirement-barrier.d.ts +217 -0
  72. package/dist/retirement-barrier.d.ts.map +1 -0
  73. package/dist/retirement-barrier.js +624 -0
  74. package/dist/retirement-barrier.js.map +1 -0
  75. package/dist/retirement-cleaner.d.ts +54 -0
  76. package/dist/retirement-cleaner.d.ts.map +1 -0
  77. package/dist/retirement-cleaner.js +158 -0
  78. package/dist/retirement-cleaner.js.map +1 -0
  79. package/dist/root-credential.d.ts +26 -0
  80. package/dist/root-credential.d.ts.map +1 -0
  81. package/dist/root-credential.js +116 -0
  82. package/dist/root-credential.js.map +1 -0
  83. package/dist/service.d.ts +60 -0
  84. package/dist/service.d.ts.map +1 -1
  85. package/dist/service.js +317 -10
  86. package/dist/service.js.map +1 -1
  87. package/dist/session-ledger.d.ts +224 -0
  88. package/dist/session-ledger.d.ts.map +1 -0
  89. package/dist/session-ledger.js +713 -0
  90. package/dist/session-ledger.js.map +1 -0
  91. package/dist/token.d.ts +17 -0
  92. package/dist/token.d.ts.map +1 -1
  93. package/dist/token.js +30 -2
  94. package/dist/token.js.map +1 -1
  95. package/package.json +5 -3
@@ -0,0 +1,397 @@
1
+ /**
2
+ * The D13 lifecycle registry, slice (1)+(2a) (SPEC §13.1, as amended): the sealed storage
3
+ * authority for lifecycle identity — the space-global UID reservation, the three-state alias
4
+ * head (`active | retiring | retired`), the activation saga over both stores, the leader-served
5
+ * mapping reader that backs the `readProcessEpoch` seam D11 (restart supervision, status
6
+ * commit) and D7 (session redemption) inject, and the issuance-gate CAS PRIMITIVES
7
+ * (create/observe/freeze/op-pinned reopen/retire) for the agent gate family `gate.<lifecycleUid>`.
8
+ *
9
+ * DELIBERATELY NOT HERE (the later gated slices, §13.1 barrier order):
10
+ * - the (3) normative credential ledger and the (2b) takeover barrier live in the SIBLING
11
+ * module `credential-ledger.ts` (the same authority over the same stores, reached through
12
+ * {@link registryStores}); this module keeps only the barrier's module-internal epoch seam
13
+ * ({@link advanceEpochWithinTakeover} — there is still NO public epoch advance);
14
+ * - no head retirement: `active → retiring → retired` is a finalization step of the
15
+ * RETIREMENT barrier (a later slice), and exposing it without the completed barrier would
16
+ * recreate the half-fence D13 exists to remove;
17
+ * - no reachable production activation wiring and no credential release (the head is written
18
+ * WITHOUT `currentCredentialId` until production issuance mints under the reopened gate).
19
+ *
20
+ * SURFACE: the activation saga and the gate primitives are PACKAGE-INTERNAL (not exported from
21
+ * the package index) until the (3) ledger slice completes them into real operations; "no
22
+ * production callsite" is not the same as no reachable API, so the API is not reachable. The
23
+ * executor seam is the sealed registry itself: it is constructed only over the minting
24
+ * authority's own authenticated connection, so holding a gate's `opId` string grants nothing
25
+ * to a caller that cannot open the registry (the opId is an identifier, §13.1).
26
+ *
27
+ * The model (§13.1):
28
+ * - the UID is entropy, never order: before anything else the minting authority WINS the
29
+ * create-only, never-deleted, SPACE-GLOBAL reservation `uid.<lifecycleUid>`; a create
30
+ * conflict burns the candidate (the alias head alone cannot reject the same UID under a
31
+ * different alias), and a DEL/PURGE marker is corruption, never reusable absence;
32
+ * - the head is a SINGLE unsplit key and `mappingRevision` IS its STORE revision (one leader
33
+ * read returns `{ mapping, revision }`; the value carries no revision field);
34
+ * - `active` is the ONLY current state: every currency seam (the epoch reader here) yields no
35
+ * current mapping and no current epoch for `retiring` AND `retired` alike;
36
+ * - activation is a CROSS-BUCKET SAGA with a durable op intent, in the normative order:
37
+ * reserve UID → create the gate `frozen` carrying the activation op (unmintable from
38
+ * birth) → CAS the alias head → reopen the gate LAST; a head-CAS loser terminalizes its own
39
+ * orphan gate and its UID stays burned; a crash resumes the SAME op ({@link resumeActivation}),
40
+ * never minting a second UID for one activation;
41
+ * - the head and the reservation are NEVER-DELETED: a reader treats only TRUE ABSENCE as
42
+ * virgin, and a deletion marker refuses LOUDLY as corruption;
43
+ * - a `frozen` gate MUST carry its durable operation intent `{ opId, kind }`: a resumer
44
+ * advances only the SAME `opId` (the opId is an identifier, never a bearer capability — the
45
+ * op-pinned CAS plus the caller's own authenticated authority is what advances the gate),
46
+ * and a stranger can neither reopen nor terminalize another operation's freeze.
47
+ */
48
+ import { type JetStreamClient, type JetStreamManager } from "@nats-io/jetstream";
49
+ import { type KV } from "@nats-io/kv";
50
+ import type { NatsConnection } from "@nats-io/transport-node";
51
+ import { type WorkPoolContext } from "@cotal-ai/core";
52
+ import { type AuthLedgerScanner } from "./ledger-scanner.js";
53
+ import { type RecordsScanner } from "./records-scanner.js";
54
+ /** The minting authority's sealed registry over the space's PRIMARY records + auth stores. */
55
+ export interface LifecycleRegistry {
56
+ readonly space: string;
57
+ }
58
+ /** The read-only sealed mapping reader (the confined reader profile holds ONLY the records
59
+ * leader read; it cannot write a head or touch the auth store). */
60
+ export interface LifecycleMappingReader {
61
+ readonly space: string;
62
+ }
63
+ /** The bucket-config fields the shape proofs inspect (wire names, per the JetStream API).
64
+ * PACKAGE-INTERNAL (with {@link assertAuthorityStreamShape}) for the sibling trusted-path
65
+ * modules; never re-exported from the package index. */
66
+ export interface AuthorityStreamCfg {
67
+ allow_direct?: boolean;
68
+ retention?: string;
69
+ max_age?: number;
70
+ max_msgs?: number;
71
+ max_bytes?: number;
72
+ mirror?: unknown;
73
+ sources?: unknown;
74
+ subjects?: unknown;
75
+ storage?: string;
76
+ }
77
+ /** Prove an authority store's stream shape at bind (SPEC 13.12): PRIMARY (never a
78
+ * mirror/sourced copy), LIMITS retention (an Interest/WorkQueue stream deletes a message once
79
+ * consumers have interest/ack it — an authority row would silently vanish after a barrier's
80
+ * point-in-time enumeration reads it), and NO silent-eviction limit — no age retention and no
81
+ * finite global message/byte cap (under DiscardOld a finite global limit evicts a PRIOR
82
+ * authority key's latest row the moment an unrelated key is written). A store that cannot be
83
+ * proved never serves. (A per-subject cap is NOT a vector: NATS keeps at least the latest value
84
+ * per subject for any cap ≥ 1, and 0/-1 mean unlimited, so no setting drops a key's own row.) */
85
+ export declare function assertAuthorityStreamShape(cfg: AuthorityStreamCfg, bucket: string): void;
86
+ /** Open the minting authority's sealed lifecycle registry: binds the space's primary records
87
+ * bucket AND its auth bucket. BOTH are shape-proved at bind (SPEC 13.12): primary, un-aged,
88
+ * no finite global eviction cap; the auth store additionally leader-only `allow_direct=false`. */
89
+ export declare function openLifecycleRegistry(nc: NatsConnection, space: string, scanner?: AuthLedgerScanner, recordsScanner?: RecordsScanner): Promise<LifecycleRegistry>;
90
+ /** Open the sealed read-only mapping reader. Its scoped credential holds EXACTLY the records
91
+ * leader read (`STREAM.MSG.GET`) plus the records `STREAM.INFO` for the bind-time shape proof
92
+ * (SPEC 13.9/13.12): a reader that cannot prove it is bound to the primary, non-evicting
93
+ * records store refuses to serve authority reads (it could otherwise leader-read a MIRROR's
94
+ * leader and call that the mapping). */
95
+ export declare function openLifecycleMappingReader(nc: NatsConnection, space: string): Promise<LifecycleMappingReader>;
96
+ /** The `lifecycle.<owner>.<actor>` head value (§13.1, amended). One incarnation of an alias.
97
+ * `mappingRevision` is NOT here: it is the head key's STORE revision (§13.1), returned beside
98
+ * the mapping by the leader read. `currentCredentialId` stays ABSENT until the (3) normative
99
+ * ledger mints under the reopened gate (an active head naming a released credential before the
100
+ * ledger exists would be exactly the unledgered mint §13.1 forbids). */
101
+ export interface LifecycleMapping {
102
+ owner: string;
103
+ actor: string;
104
+ /** The never-reused, space-globally reserved lifecycle UID of THIS incarnation. */
105
+ lifecycleUid: string;
106
+ /** The minting/supervising authority. */
107
+ managerInstance: string;
108
+ /** The fenced process epoch (§13.1: live authority binds it; advanced only by the takeover
109
+ * barrier, which this slice does not expose). */
110
+ processEpoch: number;
111
+ /** `active` is the ONLY current state. `retiring` = the terminal barrier's op-bound
112
+ * containment phase (non-current, NOT replaceable). `retired` = terminal AND asserts the
113
+ * completed barrier (only then may activation replace the alias, with a fresh UID). */
114
+ state: "active" | "retiring" | "retired";
115
+ /** The public credential fingerprint + authority epoch — absent until the ledger slice. */
116
+ currentCredentialId?: string;
117
+ /** The opId of the takeover operation that LAST advanced this epoch (SPEC 13.1: the epoch
118
+ * advance and its op stamp are ONE CAS, so a completion is bound to exactly one operation).
119
+ * A resuming barrier confirms the completed head carries ITS opId; a LOSING concurrent
120
+ * takeover finds a foreign opId and refuses, never claiming the winner's completion. Absent
121
+ * at initial activation (epoch 1), present from the first takeover. */
122
+ lastTakeoverOpId?: string;
123
+ /** REQUIRED at `retiring` (the retirement operation's durable intent); absent otherwise. */
124
+ op?: {
125
+ opId: string;
126
+ kind: "retirement";
127
+ };
128
+ }
129
+ /** PACKAGE-INTERNAL accessor for the trusted auth path's sibling modules (the credential
130
+ * ledger + issuance barrier, which are the SAME authority over the SAME stores). Deliberately
131
+ * never re-exported from the package index: a sealed registry stays the only door. */
132
+ export declare function registryStores(reg: LifecycleRegistry): {
133
+ space: string;
134
+ recordsKv: KV;
135
+ authKv: KV;
136
+ jsm: JetStreamManager;
137
+ js: JetStreamClient;
138
+ work: WorkPoolContext;
139
+ };
140
+ /** PACKAGE-INTERNAL: the barrier's CLOSED enumeration seam (SPEC 13.9). Returns the sealed
141
+ * auth-ledger scanner or throws — a registry constructed WITHOUT one (the mint writer) never
142
+ * enumerates, so asking it to is a composition bug, not a silent degrade. Exposes only the closed
143
+ * scan ops; the raw scanner/connection/credential stay inside {@link openAuthLedgerScanner}. */
144
+ export declare function registryScanner(reg: LifecycleRegistry): AuthLedgerScanner;
145
+ /** PACKAGE-INTERNAL: the retirement barrier's CLOSED obligation-enumeration seam (SPEC 13.9,
146
+ * site 3). Returns the sealed records scanner or throws — a registry constructed WITHOUT one never
147
+ * drains obligations, so asking it to is a composition bug, not a silent degrade. Exposes only the
148
+ * closed scan op; the raw scanner/connection/credential stay inside {@link openRecordsScanner}. */
149
+ export declare function registryRecordsScanner(reg: LifecycleRegistry): RecordsScanner;
150
+ /** PACKAGE-INTERNAL: the barrier's candidate read of an alias head (the credential-ledger
151
+ * takeover barrier captures its `fromEpoch` coordinate from it, and its epoch CAS re-reads
152
+ * through {@link advanceEpochWithinTakeover}). Same never-deleted discipline as every head
153
+ * read; never re-exported from the package index. */
154
+ export declare function readLifecycleHeadForOperation(reg: LifecycleRegistry, owner: string, actor: string): Promise<{
155
+ mapping: LifecycleMapping;
156
+ revision: number;
157
+ } | undefined>;
158
+ /** The takeover barrier's epoch-advance head CAS (SPEC 13.1: NO public epoch advance exists;
159
+ * this is a finalization step of the takeover barrier, module-internal for the credential
160
+ * ledger's barrier only, and idempotent for the barrier's crash-resume). Advances the epoch by
161
+ * exactly one, revision-pinned, only while the head is ACTIVE at the SAME uid. */
162
+ export declare function advanceEpochWithinTakeover(reg: LifecycleRegistry, args: {
163
+ owner: string;
164
+ actor: string;
165
+ lifecycleUid: string;
166
+ fromEpoch: number;
167
+ opId: string;
168
+ }): Promise<"advanced" | "already-advanced">;
169
+ /**
170
+ * The issuance path's head CAS stamping the incarnation's ROOT credential (SPEC 13.1: the head's
171
+ * `currentCredentialId` is what the connect arm's root-path equality check reads, so a superseded
172
+ * root issuance is denied even while its old row still reads active). The mint protocol's
173
+ * RELEASE-LAST final step: the active `cred.` row is durable and its gate finalize has won BEFORE
174
+ * this runs, and the bearer bytes release only after it.
175
+ *
176
+ * ABSENT → value ONLY (idempotent for the SAME value): a head that already names a DIFFERENT root
177
+ * credential REFUSES — flipping `currentCredentialId` without the full family revoke would leave
178
+ * the old root's descendants connectable under the leaf check, so root ROTATION is exclusively a
179
+ * barrier's job (takeover/retirement), never this seam's. Revision-pinned; ACTIVE at the SAME uid
180
+ * only; a foreign head movement between the caller's read and this CAS loses fail-closed.
181
+ */
182
+ export declare function setCurrentRootCredential(reg: LifecycleRegistry, args: {
183
+ owner: string;
184
+ actor: string;
185
+ lifecycleUid: string;
186
+ credentialId: string;
187
+ }): Promise<void>;
188
+ /** The retirement barrier's head CONTAINMENT CAS (SPEC 13.1: `active → retiring`, bound to the
189
+ * retirement operation's durable intent — from this point every currency seam yields no current
190
+ * mapping and no current epoch, and the alias is NOT replaceable). PACKAGE-INTERNAL for the
191
+ * barrier only (no public retire seam exists); idempotent for the barrier's crash-resume. */
192
+ export declare function beginHeadRetirementWithinBarrier(reg: LifecycleRegistry, args: {
193
+ owner: string;
194
+ actor: string;
195
+ lifecycleUid: string;
196
+ opId: string;
197
+ }): Promise<"retiring" | "already-retiring">;
198
+ /** The retirement barrier's TERMINAL head CAS (`retiring → retired`, op-pinned) — the barrier's
199
+ * LAST step (SPEC 13.1: `retired` ASSERTS completed cleanup, which is what makes the alias
200
+ * replaceable). The op intent is dropped (it belongs to `retiring` only); idempotence at
201
+ * `retired` is decided by the CALLER against the gate's terminal op (the retired head itself
202
+ * carries no retirement stamp). PACKAGE-INTERNAL for the barrier only. */
203
+ export declare function completeHeadRetirementWithinBarrier(reg: LifecycleRegistry, args: {
204
+ owner: string;
205
+ actor: string;
206
+ lifecycleUid: string;
207
+ opId: string;
208
+ }): Promise<"retired" | "already-retired">;
209
+ /** PACKAGE-INTERNAL: read a UID reservation's audit `{ owner, actor }` (the minting authority
210
+ * recorded it at {@link tryReserveUid}). The credential ledger uses it to BIND a mint's
211
+ * `holderPrincipal` to the reserved identity, so a trusted caller cannot ledger a row that
212
+ * names a foreign principal for the barrier to evict. A DEL/PURGE marker refuses loudly. */
213
+ export declare function readUidReservation(reg: LifecycleRegistry, lifecycleUid: string): Promise<{
214
+ owner: string;
215
+ actor: string;
216
+ } | undefined>;
217
+ /** Try to reserve ONE explicit candidate UID (test/provisioning-internal; production paths use
218
+ * {@link reserveLifecycleUid}). Create-only: `"won"` reserves it forever; `"burned"` means the
219
+ * candidate already exists OR carries a deletion marker — either way it is unusable, per the
220
+ * never-reuse rule. NOT exported from the package index: an explicit candidate is only for
221
+ * probes and migration tooling, never a caller-chosen identity. */
222
+ export declare function tryReserveUid(reg: LifecycleRegistry, lifecycleUid: string, audit: {
223
+ owner: string;
224
+ actor: string;
225
+ mintedBy: string;
226
+ }): Promise<"won" | "burned">;
227
+ /** Reserve a fresh lifecycle UID space-globally (§13.1): mint a CSPRNG candidate, win its
228
+ * create-only reservation, and on a collision burn the candidate and draw another. At ≥128
229
+ * bits a collision is effectively adversarial, so a handful of retries is a correctness
230
+ * formality, not a capacity plan; exhausting them refuses loudly. */
231
+ export declare function reserveLifecycleUid(reg: LifecycleRegistry, audit: {
232
+ owner: string;
233
+ actor: string;
234
+ mintedBy: string;
235
+ }): Promise<string>;
236
+ /** The agent-family issuance gate row (§13.1, amended): `frozen` MUST carry the durable op
237
+ * intent; the embedded uid MUST agree with the key. (The disjoint ENDPOINT family
238
+ * `epgate.<endpoint>.<instanceId>` and the full barrier land with the (3)/(2b) ledger slices.) */
239
+ export interface EpGateRow {
240
+ lifecycleUid: string;
241
+ state: "open" | "frozen" | "retired";
242
+ /** Mint generation: born 0 under the activation freeze, first mintable generation is 1 (the
243
+ * activation's reopen), and every barrier reopen advances it. */
244
+ generation: number;
245
+ /** REQUIRED at `frozen` (which operation owns this freeze and may advance it) AND at
246
+ * `retired` (the terminalizing op, audit + same-op idempotence); absent at `open`.
247
+ * `successor` is a per-kind summary token (SPEC 13.1): only `takeover`/`registration`
248
+ * may carry one (their authoritative successor artifacts live under `stage.<opId>.`);
249
+ * `activation`/`retirement` never do. */
250
+ op?: {
251
+ opId: string;
252
+ kind: "activation" | "takeover" | "registration" | "retirement";
253
+ successor?: string;
254
+ };
255
+ }
256
+ /** Observe the gate (the candidate read feeding a revision-pinned CAS; the auth store is
257
+ * leader-only by shape, `allow_direct=false`). A DEL/PURGE marker refuses loudly. */
258
+ export declare function observeGate(reg: LifecycleRegistry, lifecycleUid: string): Promise<{
259
+ row: EpGateRow;
260
+ revision: number;
261
+ } | undefined>;
262
+ /** Create the gate FROZEN under its operation's durable intent (create-only: conflicts on an
263
+ * existing gate or a deletion marker). A gate is BORN only under an ACTIVATION intent (SPEC
264
+ * 13.1 per-kind transition sets: takeover/registration/retirement freeze an EXISTING open
265
+ * gate), and only for a UID whose space-global reservation was already WON: a gate over an
266
+ * unreserved UID would mint outside the never-reuse fence. Born unmintable at generation 0:
267
+ * no credential can be released until the operation's own reopen (§13.1 activation saga). */
268
+ export declare function createGateFrozen(reg: LifecycleRegistry, args: {
269
+ lifecycleUid: string;
270
+ op: {
271
+ opId: string;
272
+ kind: "activation";
273
+ };
274
+ }): Promise<{
275
+ row: EpGateRow;
276
+ revision: number;
277
+ }>;
278
+ /** CAS the gate `open → frozen` carrying the freezing operation's durable intent, at the
279
+ * observed revision. The bar of every barrier: a staged mint's own finalize CAS loses. */
280
+ export declare function freezeGate(reg: LifecycleRegistry, args: {
281
+ lifecycleUid: string;
282
+ revision: number;
283
+ op: {
284
+ opId: string;
285
+ kind: "takeover" | "registration" | "retirement";
286
+ successor?: string;
287
+ };
288
+ }): Promise<{
289
+ row: EpGateRow;
290
+ revision: number;
291
+ }>;
292
+ /** CAS the gate `frozen → open` at the NEXT generation — op-pinned: only the freeze's own
293
+ * operation (the same `opId`) reopens, as its barrier's final step; a stranger or a stale
294
+ * reconciler refuses before the CAS is even attempted. Per-kind (SPEC 13.1): a reopen
295
+ * belongs to activation, takeover, and a registration abort — NEVER retirement (a
296
+ * retirement freeze never reopens; its only exit is the terminal). */
297
+ export declare function reopenGate(reg: LifecycleRegistry, args: {
298
+ lifecycleUid: string;
299
+ revision: number;
300
+ opId: string;
301
+ }): Promise<{
302
+ row: EpGateRow;
303
+ revision: number;
304
+ }>;
305
+ /** CAS the gate `frozen → retired` (terminal; never reopened) — op-pinned like the reopen. The
306
+ * activation saga uses it to terminalize a head-CAS loser's orphan gate; the retirement
307
+ * barrier uses it as its own gate terminalization step. Per-kind (SPEC 13.1): only an
308
+ * ACTIVATION orphan or a RETIREMENT terminalizes — a takeover/registration freeze aborts by
309
+ * reopening, never by the terminal. Idempotence at `retired` is SAME-OP idempotence: a
310
+ * stranger's retry on a terminal gate refuses, it does not "succeed". */
311
+ export declare function retireGate(reg: LifecycleRegistry, args: {
312
+ lifecycleUid: string;
313
+ revision: number;
314
+ opId: string;
315
+ }): Promise<{
316
+ row: EpGateRow;
317
+ revision: number;
318
+ }>;
319
+ /**
320
+ * Activate the alias `(owner, actor)`: the full §13.1 initial-activation saga. Refuses an
321
+ * `active` head (`already-exists`: a takeover advances the epoch through its barrier, never a
322
+ * new incarnation) and a `retiring` head (`failed-precondition`: a retiring alias is NOT
323
+ * replaceable until its barrier completes). A virgin alias activates by create-only head CAS; a
324
+ * `retired` predecessor is replaced by revision-pinned CAS with a FRESH reserved UID. The
325
+ * head-CAS loser terminalizes its own orphan gate (its UID stays burned forever) and rethrows
326
+ * the `conflict`. Returns the new mapping, its store revision (= `mappingRevision`), and the
327
+ * saga's `opId` (the durable intent a crashed caller resumes with, {@link resumeActivation}).
328
+ *
329
+ * NOT wired to any production spawn path in this slice; the ledger slice adds credential
330
+ * minting under the reopened gate before this becomes reachable.
331
+ */
332
+ export declare function activateLifecycle(reg: LifecycleRegistry, args: {
333
+ owner: string;
334
+ actor: string;
335
+ managerInstance: string;
336
+ }): Promise<{
337
+ mapping: LifecycleMapping;
338
+ revision: number;
339
+ opId: string;
340
+ }>;
341
+ /**
342
+ * Activate the alias `(owner, actor)` AT THE CALLER'S uid — the production ISSUANCE activation
343
+ * (SPEC 13.1). The grant row already minted the incarnation's uid and every bearer's
344
+ * lifecycle-equality is bound to it, so a fresh reservation ({@link activateLifecycle}) would
345
+ * strand the grant. Same saga order (reserve → gate frozen → head CAS → reopen LAST) with
346
+ * ADOPT-instead-of-burn resume semantics: a reservation or frozen ACTIVATION gate already carried
347
+ * by OUR alias at this uid is a prior attempt's durable progress and is adopted — burning the
348
+ * grant's uid would permanently brick the grant — and a CAS loss to a SIBLING (same alias, same
349
+ * uid) converges on the winner's state instead of refusing.
350
+ *
351
+ * Returns with the head ACTIVE at `lifecycleUid` and the issuance gate OPEN. Refuses loudly: an
352
+ * active head at a DIFFERENT uid (`already-exists` — retiring a live predecessor is the takeover
353
+ * barrier's job, which production issuance does not run in R1), a retiring head, a reservation
354
+ * held by a FOREIGN alias, a foreign-operation freeze, and a terminally retired gate.
355
+ */
356
+ export declare function activateLifecycleAtUid(reg: LifecycleRegistry, args: {
357
+ owner: string;
358
+ actor: string;
359
+ lifecycleUid: string;
360
+ managerInstance: string;
361
+ }): Promise<void>;
362
+ /**
363
+ * Resume a crashed activation saga from its durable coordinates (`{alias, lifecycleUid, opId}`,
364
+ * the intent the minting authority persists before step 1 and the gate carries from step 2).
365
+ * Reads the durable state and finishes the SAME operation deterministically:
366
+ * - head active at OUR uid → finish step 4 (reopen the gate) if it is still frozen by us;
367
+ * - head absent / retired / owned by another uid → our head CAS never won (or never ran):
368
+ * terminalize our orphan gate; the uid stays burned.
369
+ * Idempotent; never advances another operation's freeze (the op-pinned CAS refuses). Returns
370
+ * what it did.
371
+ */
372
+ export declare function resumeActivation(reg: LifecycleRegistry, args: {
373
+ owner: string;
374
+ actor: string;
375
+ lifecycleUid: string;
376
+ opId: string;
377
+ }): Promise<"completed" | "terminalized" | "already-settled">;
378
+ /**
379
+ * The LEADER-SERVED mapping read (§13.1: `mappingRevision` IS the returned store revision; the
380
+ * records bucket allows Direct Get for non-fencing reads, but an authority read of the head is
381
+ * leader-served `STREAM.MSG.GET`, never a follower get). Returns the mapping REGARDLESS of
382
+ * state — currency is the CALLER's rule, and the epoch seam below applies it. A DEL/PURGE
383
+ * marker refuses loudly.
384
+ */
385
+ export declare function readLifecycleMappingLeader(rd: LifecycleMappingReader, owner: string, actor: string): Promise<{
386
+ mapping: LifecycleMapping;
387
+ revision: number;
388
+ } | undefined>;
389
+ /**
390
+ * The `readProcessEpoch` PRODUCTION SEAM the D11/D7 paths inject: the CURRENT incarnation's
391
+ * fenced epoch, leader-served — and current means `state: "active"` ONLY (§13.1, amended):
392
+ * `retiring` and `retired` alike yield `undefined`, so a superseded process's status write, a
393
+ * containment-phase mint, or a leaked session grant all fail the epoch fence. Bind it as
394
+ * `readProcessEpoch: () => lifecycleProcessEpochReader(reader, owner, actor)`.
395
+ */
396
+ export declare function lifecycleProcessEpochReader(rd: LifecycleMappingReader, owner: string, actor: string): Promise<number | undefined>;
397
+ //# sourceMappingURL=lifecycle-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle-registry.d.ts","sourceRoot":"","sources":["../src/lifecycle-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,EAA+B,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAO,KAAK,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAaL,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAsB,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