@cotal-ai/core 0.16.0 → 0.17.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 (141) hide show
  1. package/dist/acls.d.ts +21 -0
  2. package/dist/acls.d.ts.map +1 -1
  3. package/dist/acls.js +44 -1
  4. package/dist/acls.js.map +1 -1
  5. package/dist/artifact.d.ts +45 -0
  6. package/dist/artifact.d.ts.map +1 -0
  7. package/dist/artifact.js +82 -0
  8. package/dist/artifact.js.map +1 -0
  9. package/dist/backup-config.d.ts +9 -2
  10. package/dist/backup-config.d.ts.map +1 -1
  11. package/dist/backup-config.js +6 -2
  12. package/dist/backup-config.js.map +1 -1
  13. package/dist/broker-tls.d.ts +70 -0
  14. package/dist/broker-tls.d.ts.map +1 -0
  15. package/dist/broker-tls.js +195 -0
  16. package/dist/broker-tls.js.map +1 -0
  17. package/dist/canonical.d.ts +14 -1
  18. package/dist/canonical.d.ts.map +1 -1
  19. package/dist/canonical.js +21 -1
  20. package/dist/canonical.js.map +1 -1
  21. package/dist/channels.js +4 -4
  22. package/dist/channels.js.map +1 -1
  23. package/dist/endpoint-action.d.ts +108 -3
  24. package/dist/endpoint-action.d.ts.map +1 -1
  25. package/dist/endpoint-action.js +209 -20
  26. package/dist/endpoint-action.js.map +1 -1
  27. package/dist/endpoint-binding.d.ts +138 -8
  28. package/dist/endpoint-binding.d.ts.map +1 -1
  29. package/dist/endpoint-binding.js +233 -26
  30. package/dist/endpoint-binding.js.map +1 -1
  31. package/dist/endpoint-contract-store.d.ts +24 -1
  32. package/dist/endpoint-contract-store.d.ts.map +1 -1
  33. package/dist/endpoint-contract-store.js +79 -27
  34. package/dist/endpoint-contract-store.js.map +1 -1
  35. package/dist/endpoint-envelope.d.ts +15 -37
  36. package/dist/endpoint-envelope.d.ts.map +1 -1
  37. package/dist/endpoint-envelope.js +93 -44
  38. package/dist/endpoint-envelope.js.map +1 -1
  39. package/dist/endpoint-error.d.ts +33 -0
  40. package/dist/endpoint-error.d.ts.map +1 -0
  41. package/dist/endpoint-error.js +34 -0
  42. package/dist/endpoint-error.js.map +1 -0
  43. package/dist/endpoint-grants.d.ts +48 -7
  44. package/dist/endpoint-grants.d.ts.map +1 -1
  45. package/dist/endpoint-grants.js +97 -9
  46. package/dist/endpoint-grants.js.map +1 -1
  47. package/dist/endpoint-invoke.d.ts +138 -0
  48. package/dist/endpoint-invoke.d.ts.map +1 -0
  49. package/dist/endpoint-invoke.js +340 -0
  50. package/dist/endpoint-invoke.js.map +1 -0
  51. package/dist/endpoint-records.d.ts.map +1 -1
  52. package/dist/endpoint-records.js +17 -0
  53. package/dist/endpoint-records.js.map +1 -1
  54. package/dist/endpoint-serve-kv.d.ts +97 -0
  55. package/dist/endpoint-serve-kv.d.ts.map +1 -0
  56. package/dist/endpoint-serve-kv.js +336 -0
  57. package/dist/endpoint-serve-kv.js.map +1 -0
  58. package/dist/endpoint-serve.d.ts.map +1 -1
  59. package/dist/endpoint-serve.js +21 -1
  60. package/dist/endpoint-serve.js.map +1 -1
  61. package/dist/endpoint-service.d.ts +1 -1
  62. package/dist/endpoint-service.d.ts.map +1 -1
  63. package/dist/endpoint-service.js +34 -10
  64. package/dist/endpoint-service.js.map +1 -1
  65. package/dist/endpoint-session-rail.d.ts +127 -0
  66. package/dist/endpoint-session-rail.d.ts.map +1 -0
  67. package/dist/endpoint-session-rail.js +325 -0
  68. package/dist/endpoint-session-rail.js.map +1 -0
  69. package/dist/endpoint-session.d.ts +1 -115
  70. package/dist/endpoint-session.d.ts.map +1 -1
  71. package/dist/endpoint-session.js +4 -316
  72. package/dist/endpoint-session.js.map +1 -1
  73. package/dist/endpoint-subjects.d.ts +10 -1
  74. package/dist/endpoint-subjects.d.ts.map +1 -1
  75. package/dist/endpoint-subjects.js +10 -1
  76. package/dist/endpoint-subjects.js.map +1 -1
  77. package/dist/endpoint-verbs.d.ts +1 -2
  78. package/dist/endpoint-verbs.d.ts.map +1 -1
  79. package/dist/endpoint-verbs.js +6 -6
  80. package/dist/endpoint-verbs.js.map +1 -1
  81. package/dist/endpoint.d.ts +136 -11
  82. package/dist/endpoint.d.ts.map +1 -1
  83. package/dist/endpoint.js +329 -24
  84. package/dist/endpoint.js.map +1 -1
  85. package/dist/identity.d.ts +19 -0
  86. package/dist/identity.d.ts.map +1 -1
  87. package/dist/identity.js +12 -0
  88. package/dist/identity.js.map +1 -1
  89. package/dist/index.d.ts +8 -0
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +8 -0
  92. package/dist/index.js.map +1 -1
  93. package/dist/kv-scan.d.ts +8 -0
  94. package/dist/kv-scan.d.ts.map +1 -1
  95. package/dist/kv-scan.js +8 -0
  96. package/dist/kv-scan.js.map +1 -1
  97. package/dist/lease.d.ts +12 -5
  98. package/dist/lease.d.ts.map +1 -1
  99. package/dist/lease.js.map +1 -1
  100. package/dist/lifecycle-saga.d.ts +174 -0
  101. package/dist/lifecycle-saga.d.ts.map +1 -0
  102. package/dist/lifecycle-saga.js +418 -0
  103. package/dist/lifecycle-saga.js.map +1 -0
  104. package/dist/lifecycle-state.d.ts +202 -0
  105. package/dist/lifecycle-state.d.ts.map +1 -0
  106. package/dist/lifecycle-state.js +347 -0
  107. package/dist/lifecycle-state.js.map +1 -0
  108. package/dist/parts.d.ts +13 -0
  109. package/dist/parts.d.ts.map +1 -0
  110. package/dist/parts.js +17 -0
  111. package/dist/parts.js.map +1 -0
  112. package/dist/provision.d.ts +106 -9
  113. package/dist/provision.d.ts.map +1 -1
  114. package/dist/provision.js +506 -110
  115. package/dist/provision.js.map +1 -1
  116. package/dist/schema-profile.d.ts +3 -2
  117. package/dist/schema-profile.d.ts.map +1 -1
  118. package/dist/schema-profile.js +242 -18
  119. package/dist/schema-profile.js.map +1 -1
  120. package/dist/session-browser.d.ts +15 -0
  121. package/dist/session-browser.d.ts.map +1 -0
  122. package/dist/session-browser.js +14 -0
  123. package/dist/session-browser.js.map +1 -0
  124. package/dist/session-terminal-frames.d.ts +36 -0
  125. package/dist/session-terminal-frames.d.ts.map +1 -0
  126. package/dist/session-terminal-frames.js +149 -0
  127. package/dist/session-terminal-frames.js.map +1 -0
  128. package/dist/spaces.d.ts.map +1 -1
  129. package/dist/spaces.js +6 -1
  130. package/dist/spaces.js.map +1 -1
  131. package/dist/streams.d.ts +53 -1
  132. package/dist/streams.d.ts.map +1 -1
  133. package/dist/streams.js +135 -8
  134. package/dist/streams.js.map +1 -1
  135. package/dist/subjects.d.ts +32 -26
  136. package/dist/subjects.d.ts.map +1 -1
  137. package/dist/subjects.js +38 -25
  138. package/dist/subjects.js.map +1 -1
  139. package/dist/types.d.ts +27 -1
  140. package/dist/types.d.ts.map +1 -1
  141. package/package.json +6 -1
@@ -0,0 +1,202 @@
1
+ /** The `lifecycle.<owner>.<actor>` head value (§13.1, amended). One incarnation of an alias.
2
+ * `mappingRevision` is NOT here: it is the head key's STORE revision (§13.1), returned beside
3
+ * the mapping by the leader read. `currentCredentialId` stays ABSENT until the (3) normative
4
+ * ledger mints under the reopened gate (an active head naming a released credential before the
5
+ * ledger exists would be exactly the unledgered mint §13.1 forbids). */
6
+ export interface LifecycleMapping {
7
+ owner: string;
8
+ actor: string;
9
+ /** The never-reused, space-globally reserved lifecycle UID of THIS incarnation. */
10
+ lifecycleUid: string;
11
+ /** The minting/supervising authority. */
12
+ managerInstance: string;
13
+ /** The fenced process epoch (§13.1: live authority binds it; advanced only by the takeover
14
+ * barrier). */
15
+ processEpoch: number;
16
+ /** `active` is the ONLY current state. `retiring` = the terminal barrier's op-bound
17
+ * containment phase (non-current, NOT replaceable). `retired` = terminal AND asserts the
18
+ * completed barrier (only then may activation replace the alias, with a fresh UID). */
19
+ state: "active" | "retiring" | "retired";
20
+ /** The public credential fingerprint + authority epoch — absent until the ledger slice. */
21
+ currentCredentialId?: string;
22
+ /** The opId of the takeover operation that LAST advanced this epoch (SPEC 13.1: the epoch
23
+ * advance and its op stamp are ONE CAS, so a completion is bound to exactly one operation).
24
+ * A resuming barrier confirms the completed head carries ITS opId; a LOSING concurrent
25
+ * takeover finds a foreign opId and refuses, never claiming the winner's completion. Absent
26
+ * at initial activation (epoch 1), present from the first takeover. */
27
+ lastTakeoverOpId?: string;
28
+ /** REQUIRED at `retiring` (the retirement operation's durable intent); absent otherwise. */
29
+ op?: {
30
+ opId: string;
31
+ kind: "retirement";
32
+ };
33
+ }
34
+ export declare const LIFECYCLE_HEAD_STATES: ReadonlySet<string>;
35
+ /** The head key `lifecycle.<owner>.<actor>` (§13.7: one atomic unsplit key). */
36
+ export declare function lifecycleHeadKey(owner: string, actor: string): string;
37
+ /** The space-global reservation key `uid.<lifecycleUid>` (§13.7: create-only, never-deleted). */
38
+ export declare function uidReservationKey(lifecycleUid: string): string;
39
+ /** Validate a head value at the consuming boundary — CLOSED schema (nested `op` included), and
40
+ * the embedded owner/actor MUST agree with the key so a key-mismatched row never authorizes. */
41
+ export declare function parseLifecycleHead(raw: Uint8Array, key: string, owner: string, actor: string): LifecycleMapping;
42
+ /** The agent-family issuance gate row (§13.1, amended): `frozen` MUST carry the durable op
43
+ * intent; the embedded uid MUST agree with the key. (The disjoint ENDPOINT family
44
+ * `epgate.<endpoint>.<instanceId>` is separate.) */
45
+ export interface EpGateRow {
46
+ lifecycleUid: string;
47
+ state: "open" | "frozen" | "retired";
48
+ /** Mint generation: born 0 under the activation freeze, first mintable generation is 1 (the
49
+ * activation's reopen), and every barrier reopen advances it. */
50
+ generation: number;
51
+ /** REQUIRED at `frozen` (which operation owns this freeze and may advance it) AND at
52
+ * `retired` (the terminalizing op, audit + same-op idempotence); absent at `open`.
53
+ * `successor` is a per-kind summary token (SPEC 13.1): only `takeover`/`registration`
54
+ * may carry one (their authoritative successor artifacts live under `stage.<opId>.`);
55
+ * `activation`/`retirement` never do. */
56
+ op?: {
57
+ opId: string;
58
+ kind: "activation" | "takeover" | "registration" | "retirement";
59
+ successor?: string;
60
+ };
61
+ }
62
+ export declare const ISSUANCE_GATE_STATES: ReadonlySet<string>;
63
+ export declare const ISSUANCE_GATE_OP_KINDS: ReadonlySet<string>;
64
+ /** The gate key `gate.<lifecycleUid>` (§13.7). */
65
+ export declare function issuanceGateKey(lifecycleUid: string): string;
66
+ /** Validate a gate row at the consuming boundary — CLOSED schema; key/uid agreement; the
67
+ * per-kind STATE x KIND transition invariants (§13.1). */
68
+ export declare function parseIssuanceGate(raw: Uint8Array, key: string, lifecycleUid: string): EpGateRow;
69
+ export declare function assertKeySegment(v: unknown, what: string): string;
70
+ /** A credential id: one or more KV-safe segments (dots allowed BETWEEN segments — the session
71
+ * families use `<sessionId>.c` / `<sessionId>.s` — but never wildcards or empty segments). */
72
+ export declare function assertCredentialIdTail(v: unknown, what: string): string;
73
+ /** A holder principal `<owner>.<actor>` with a REAL owner (derived `u_…` or the dev owner) —
74
+ * eviction is BY PRINCIPAL, so a row that cannot name an evictable principal never ledgers. */
75
+ export declare function assertHolderPrincipal(v: unknown, what: string): string;
76
+ export declare const SOURCE_ROOT = "root";
77
+ /** Validate ONE sourceChain member — `root`, `handle.<issuerKeyId>.<id>`, or
78
+ * `session.<sessionId>` (SPEC 13.1) — and return its parsed shape. */
79
+ export declare function parseSourceMember(member: unknown): {
80
+ kind: "root";
81
+ } | {
82
+ kind: "handle";
83
+ issuerKeyId: string;
84
+ id: string;
85
+ } | {
86
+ kind: "session";
87
+ sessionId: string;
88
+ };
89
+ export declare function assertSourceChain(v: unknown, what: string): string[];
90
+ /** The agent-family ledger key `cred.<lifecycleUid>.<credentialId>`. */
91
+ export declare function credRowKey(lifecycleUid: string, credentialId: string): string;
92
+ /** The endpoint-family ledger key `epcred.<endpoint>.<instanceId>.<credentialId>` (disjoint by
93
+ * explicit prefix, never arity, SPEC 13.1). */
94
+ export declare function epcredRowKey(endpoint: string, instanceId: string, credentialId: string): string;
95
+ /** The endpoint-family ledger KEY PREFIX `epcred.<endpoint>.<instanceId>` (no credentialId tail) —
96
+ * the exact family a barrier enumerates and a key-pinned executor grant scopes to (`…​.>`). Built
97
+ * from the core tokenizers so a grant never spells the prefix by hand (guard-the-core). */
98
+ export declare function epcredFamilyPrefix(endpoint: string, instanceId: string): string;
99
+ /** The ENDPOINT-instance issuance gate row (§13.1: a DISJOINT family from the agent
100
+ * `gate.<lifecycleUid>`, distinguished by explicit PREFIX and never token arity; it carries the
101
+ * endpoint fence coordinates of §13.5/§13.7). Closed schema; `frozen`/`retired` are op-bound
102
+ * exactly like the agent family. Lifted to core (guarded-core: ONE encoder shared by the auth
103
+ * session ledger and the manager's endpoint-serve wiring; a second dialect is the dual-encoder
104
+ * drift this module bans). */
105
+ export interface EndpointGateRow {
106
+ state: "open" | "frozen" | "retired";
107
+ generation: number;
108
+ processEpoch: number;
109
+ registrationRevision: number;
110
+ nameAuthorityRevision: number;
111
+ /** The serving instance's CONNZ-attributable connection principal (`<owner>.<actor>` dot-form)
112
+ * — the eviction target when the endpoint is taken over or a serving credential is revoked
113
+ * (§13.1: eviction is BY PRINCIPAL). Recorded at endpoint registration; the serving ledger
114
+ * rows (`epcred.`) copy it as their `holderPrincipal`, so the endpoint KEY identity
115
+ * (`endpoint`) and the evictable principal stay disjoint. */
116
+ principal: string;
117
+ op?: {
118
+ opId: string;
119
+ kind: "activation" | "takeover" | "registration" | "retirement";
120
+ successor?: string;
121
+ };
122
+ }
123
+ /** The endpoint gate key `epgate.<endpoint>.<instanceId>` (an instanceId is unique ONLY within
124
+ * `(space, endpoint)`, so the key is endpoint-qualified — equal instanceIds under two endpoints
125
+ * never collide on the gate or the credential family, §13.1/§13.6). */
126
+ export declare function epgateKey(endpoint: string, instanceId: string): string;
127
+ /** Validate an endpoint gate row at the consuming boundary — CLOSED schema; a real owner-grammar
128
+ * serving principal; the per-kind STATE x KIND + successor invariants (§13.1). Byte-for-byte the
129
+ * parser the auth session ledger carried (fact H3 lift), now shared. */
130
+ export declare function parseEndpointGate(raw: Uint8Array, key: string): EndpointGateRow;
131
+ /** The §13.1 credential-ledger row, closed. `lifecycleUid` is the HOLDER's KEY identity
132
+ * component: the managed agent's lifecycle UID in the `cred.` family, the endpoint instance's
133
+ * `instanceId` in the `epcred.` family (SPEC 13.1: `instanceId` is to an endpoint what
134
+ * `lifecycleUid` is to a managed agent). `endpoint` is present ONLY in the `epcred.` family
135
+ * (it forms the key there and is absent in `cred.`), so the KEY identity is never conflated
136
+ * with the eviction target. `holderPrincipal` is who the barrier KICKs: ALWAYS a CONNZ-
137
+ * attributable `<owner>.<actor>` dot-form (the caller principal in the `cred.` family; the
138
+ * serving instance's own connection principal in the `epcred.` family, recorded from the
139
+ * endpoint gate), NEVER the endpoint name (which CONNZ cannot attribute). */
140
+ export interface CredentialLedgerRow {
141
+ credentialId: string;
142
+ holderPrincipal: string;
143
+ lifecycleUid: string;
144
+ /** The endpoint NAME whose token forms the `epcred.` key; present iff this is an endpoint-
145
+ * family row, absent in the `cred.` family (which the lifecycleUid keys). */
146
+ endpoint?: string;
147
+ /** The FULL verified lineage at mint: `root` | `handle.<issuerKeyId>.<id>`… |
148
+ * `session.<sessionId>` (SPEC 13.1 — for a handle redemption EVERY handle in the presented
149
+ * chain, never only the leaf). */
150
+ sourceChain: string[];
151
+ /** Monotonic: `active → revoked` only; a revoked row is never deleted. */
152
+ state: "active" | "revoked";
153
+ exp: number;
154
+ }
155
+ /** Parse + validate a ledger row at its consuming boundary — closed schema, and the embedded
156
+ * identity MUST rebuild the row's own key, so a key-mismatched or family-swapped poison row
157
+ * never authorizes (SPEC 13.1/13.3). */
158
+ export declare function parseLedgerRow(raw: Uint8Array, key: string): CredentialLedgerRow;
159
+ /** Phases of one static managed slot: the F3 outer spawn intent (`provisioning`, persisted
160
+ * BEFORE head activation), the owned slot (`active`), the terminal in flight (`terminalizing`),
161
+ * and the completed terminal (`retired` — the row is never deleted; a same-alias successor
162
+ * CASes over it). */
163
+ export declare const STATIC_SLOT_PHASES: ReadonlySet<string>;
164
+ export type StaticSlotPhase = "provisioning" | "active" | "terminalizing" | "retired";
165
+ /** The static manager's durable alias -> (owner, actor, lifecycleUid) slot mapping (Unit B,
166
+ * the F5-bind split-coordinates design): the ALIAS is routing/display, protected by this
167
+ * name-keyed row plus the uid reservation and the manager's freeSlot hold; the AUTHORITY
168
+ * coordinate is the incarnation-unique wire `actor` (the nkey) recorded here as DATA. The row
169
+ * lives in the records store — the same durability domain as the head — and survives manager
170
+ * restart (the boot sweep re-drives any non-retired phase). `credentialIds` is the incarnation's
171
+ * full mint set (root + renewals): the terminal's B1 revoke enumerates from HERE (recorded
172
+ * BEFORE each mint), never from a store listing. */
173
+ export interface StaticManagedSlotRow {
174
+ owner: string;
175
+ /** The manager-visible agent name (routing identity; never sufficient authority, SPEC 13.1). */
176
+ alias: string;
177
+ /** The incarnation-unique wire principal actor (the connection nkey) — the authority coordinate. */
178
+ actor: string;
179
+ lifecycleUid: string;
180
+ phase: StaticSlotPhase;
181
+ /** Every credentialId minted for this incarnation, recorded BEFORE its mint (crash-safe:
182
+ * a cred never exists without its id recorded here and its ledger row appended first). */
183
+ credentialIds: string[];
184
+ /** The minting/supervising authority (the manager's own per-PROCESS incarnation uid — audit only). */
185
+ managerInstance: string;
186
+ /** The owning LOGICAL manager instance id (P2 item 3 slice 3b-2): stable across manager restart, so
187
+ * the boot reconcile filters to rows THIS logical instance owns and never sweep-terminalizes a
188
+ * SIBLING manager's rows (multi-manager-per-space). Optional for backward-compat: a legacy row
189
+ * (written before 3b-2, no owner recorded) predates multi-manager, so a reconciling manager treats
190
+ * it as its own (the single-manager past). An orphaned sibling row is claimed only by an explicit
191
+ * operator CAS takeover (ruling 1), never auto-adopted. */
192
+ ownerInstanceId?: string;
193
+ }
194
+ /** The slot key prefix in the records store. Core-owned so permission builders and the manager
195
+ * share ONE encoder (a second literal is the drift class this module bans). */
196
+ export declare const STATIC_SLOT_PREFIX = "mgrslot";
197
+ /** The slot key `mgrslot.<owner>.<alias>`. */
198
+ export declare function staticSlotKey(owner: string, alias: string): string;
199
+ /** Validate a slot row at the consuming boundary — CLOSED schema, and the embedded identity
200
+ * MUST rebuild the row's own key, so a key-mismatched row never drives a resume or terminal. */
201
+ export declare function parseStaticSlotRow(raw: Uint8Array, key: string): StaticManagedSlotRow;
202
+ //# sourceMappingURL=lifecycle-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle-state.d.ts","sourceRoot":"","sources":["../src/lifecycle-state.ts"],"names":[],"mappings":"AAuBA;;;;yEAIyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,YAAY,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,eAAe,EAAE,MAAM,CAAC;IACxB;oBACgB;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB;;4FAEwF;IACxF,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;IACzC,2FAA2F;IAC3F,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;4EAIwE;IACxE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4FAA4F;IAC5F,EAAE,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE,CAAC;CAC3C;AAED,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,CAA8C,CAAC;AAErG,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;iGACiG;AACjG,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CA0C/G;AAID;;qDAEqD;AACrD,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,KA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AAC;IACrB;kFAC8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;uCAEmC;IACnC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,0EAA0E;IAC1E,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;yCAEyC;AACzC,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,mBAAmB,CA8ChF;AAID;;;sBAGsB;AACtB,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAmE,CAAC;AACvH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,QAAQ,GAAG,eAAe,GAAG,SAAS,CAAC;AAEtF;;;;;;;qDAOqD;AACrD,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,gGAAgG;IAChG,KAAK,EAAE,MAAM,CAAC;IACd,oGAAoG;IACpG,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,eAAe,CAAC;IACvB;+FAC2F;IAC3F,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,sGAAsG;IACtG,eAAe,EAAE,MAAM,CAAC;IACxB;;;;;gEAK4D;IAC5D,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;gFACgF;AAChF,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C,8CAA8C;AAC9C,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;iGACiG;AACjG,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAuBrF"}
@@ -0,0 +1,347 @@
1
+ /**
2
+ * The §13.1 lifecycle STATE grammar: the wire-normative key shapes, closed value schemas, and
3
+ * state sets for the lifecycle alias head (`lifecycle.<owner>.<actor>`), the space-global UID
4
+ * reservation (`uid.<lifecycleUid>`), and the agent-family issuance gate (`gate.<lifecycleUid>`).
5
+ *
6
+ * This module is GRAMMAR ONLY, shared by every lifecycle executor (the user-mesh auth service
7
+ * and the manager's static lifecycle adapter): key construction, parse-at-the-consuming-boundary
8
+ * validation, and the state constants. The CAS SEQUENCING that produces these rows (activation
9
+ * saga, head retirement, gate transitions) and the barrier ORCHESTRATION (revoke/evict/ledger)
10
+ * live with their executors; a second copy of either is the dual-encoder drift this module
11
+ * exists to prevent.
12
+ */
13
+ import { EpEnvelopeError } from "./endpoint-envelope.js";
14
+ import { LIFECYCLE_HEAD, UID_RESERVATION, recordAtomicKey } from "./endpoint-records.js";
15
+ import { assertLifecycleToken, endpointToken } from "./endpoint-subjects.js";
16
+ import { parsePrincipalKey, isPrincipalOwnerToken } from "./subjects.js";
17
+ const dec = new TextDecoder();
18
+ const isRec = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
19
+ const uint = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
20
+ export const LIFECYCLE_HEAD_STATES = new Set(["active", "retiring", "retired"]);
21
+ /** The head key `lifecycle.<owner>.<actor>` (§13.7: one atomic unsplit key). */
22
+ export function lifecycleHeadKey(owner, actor) {
23
+ return recordAtomicKey(LIFECYCLE_HEAD, [owner, actor]);
24
+ }
25
+ /** The space-global reservation key `uid.<lifecycleUid>` (§13.7: create-only, never-deleted). */
26
+ export function uidReservationKey(lifecycleUid) {
27
+ return recordAtomicKey(UID_RESERVATION, [lifecycleUid]);
28
+ }
29
+ /** Validate a head value at the consuming boundary — CLOSED schema (nested `op` included), and
30
+ * the embedded owner/actor MUST agree with the key so a key-mismatched row never authorizes. */
31
+ export function parseLifecycleHead(raw, key, owner, actor) {
32
+ let o;
33
+ try {
34
+ o = JSON.parse(dec.decode(raw));
35
+ }
36
+ catch {
37
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} is not JSON; garbled trusted-path state never authorizes (SPEC 13.1)`);
38
+ }
39
+ if (!isRec(o))
40
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} is not an object`);
41
+ const allowed = new Set(["owner", "actor", "lifecycleUid", "managerInstance", "processEpoch", "state", "currentCredentialId", "lastTakeoverOpId", "op"]);
42
+ for (const k of Object.keys(o))
43
+ if (!allowed.has(k))
44
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} carries the unknown field "${k}" (closed schema, SPEC 13.1)`);
45
+ if (o.owner !== owner || o.actor !== actor ||
46
+ typeof o.lifecycleUid !== "string" || typeof o.managerInstance !== "string" || o.managerInstance.length === 0 ||
47
+ !uint(o.processEpoch) || o.processEpoch < 1 || typeof o.state !== "string" || !LIFECYCLE_HEAD_STATES.has(o.state) ||
48
+ (o.currentCredentialId !== undefined && (typeof o.currentCredentialId !== "string" || o.currentCredentialId.length === 0)) ||
49
+ (o.lastTakeoverOpId !== undefined && typeof o.lastTakeoverOpId !== "string"))
50
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} does not validate (owner/actor/uid/epoch/state); a garbled or key-mismatched head never authorizes (SPEC 13.1/13.3)`);
51
+ try {
52
+ assertLifecycleToken(o.lifecycleUid);
53
+ if (o.lastTakeoverOpId !== undefined)
54
+ assertLifecycleToken(o.lastTakeoverOpId);
55
+ }
56
+ catch {
57
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} carries a malformed lifecycleUid/lastTakeoverOpId (SPEC 13.1)`);
58
+ }
59
+ // The retirement op intent: REQUIRED at `retiring`, forbidden elsewhere; itself closed.
60
+ if (o.state === "retiring") {
61
+ if (!isRec(o.op))
62
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} is retiring without its durable op intent (SPEC 13.1: retiring is op-bound)`);
63
+ }
64
+ else if (o.op !== undefined) {
65
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} carries an op intent in state "${o.state}" (SPEC 13.1: only retiring is op-bound)`);
66
+ }
67
+ if (o.op !== undefined) {
68
+ const op = o.op;
69
+ for (const k of Object.keys(op))
70
+ if (k !== "opId" && k !== "kind")
71
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} op intent carries the unknown field "${k}" (closed schema)`);
72
+ if (typeof op.opId !== "string" || op.kind !== "retirement")
73
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} op intent does not validate (SPEC 13.1)`);
74
+ try {
75
+ assertLifecycleToken(op.opId);
76
+ }
77
+ catch {
78
+ throw new EpEnvelopeError("internal", `the lifecycle head ${key} op intent carries a malformed opId (SPEC 13.1)`);
79
+ }
80
+ }
81
+ return o;
82
+ }
83
+ export const ISSUANCE_GATE_STATES = new Set(["open", "frozen", "retired"]);
84
+ export const ISSUANCE_GATE_OP_KINDS = new Set(["activation", "takeover", "registration", "retirement"]);
85
+ /** The gate key `gate.<lifecycleUid>` (§13.7). */
86
+ export function issuanceGateKey(lifecycleUid) {
87
+ return `gate.${assertLifecycleToken(lifecycleUid)}`;
88
+ }
89
+ /** Validate a gate row at the consuming boundary — CLOSED schema; key/uid agreement; the
90
+ * per-kind STATE x KIND transition invariants (§13.1). */
91
+ export function parseIssuanceGate(raw, key, lifecycleUid) {
92
+ let o;
93
+ try {
94
+ o = JSON.parse(dec.decode(raw));
95
+ }
96
+ catch {
97
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} is not JSON; garbled trusted-path state never authorizes (SPEC 13.1)`);
98
+ }
99
+ if (!isRec(o))
100
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} is not an object`);
101
+ for (const k of Object.keys(o))
102
+ if (k !== "lifecycleUid" && k !== "state" && k !== "generation" && k !== "op")
103
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} carries the unknown field "${k}" (closed schema, SPEC 13.1)`);
104
+ if (o.lifecycleUid !== lifecycleUid || typeof o.state !== "string" || !ISSUANCE_GATE_STATES.has(o.state) || !uint(o.generation))
105
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} does not validate (uid/state/generation); a garbled or key-mismatched gate never authorizes (SPEC 13.1)`);
106
+ if ((o.state === "frozen" || o.state === "retired") && !isRec(o.op))
107
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} is ${o.state} without its durable op intent (SPEC 13.1: a frozen gate is op-bound, and a retired gate retains its terminalizing op)`);
108
+ if (o.state === "open" && o.op !== undefined)
109
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} is open but carries an op intent (SPEC 13.1: open gates are not op-bound)`);
110
+ if (o.op !== undefined) {
111
+ const op = o.op;
112
+ for (const k of Object.keys(op))
113
+ if (k !== "opId" && k !== "kind" && k !== "successor")
114
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} op intent carries the unknown field "${k}" (closed schema)`);
115
+ if (typeof op.opId !== "string" || typeof op.kind !== "string" || !ISSUANCE_GATE_OP_KINDS.has(op.kind))
116
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} op intent does not validate (SPEC 13.1)`);
117
+ // STATE x KIND invariant (SPEC 13.1 per-kind transition sets): only an activation orphan or
118
+ // a retirement produces a `retired` gate, so a persisted `retired` gate carrying a
119
+ // takeover/registration kind is IMPOSSIBLE state — refuse it at parse, never let the terminal
120
+ // idempotence path return it as a settled success (fail-closed on corruption, not open).
121
+ if (o.state === "retired" && op.kind !== "activation" && op.kind !== "retirement")
122
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} is retired under a ${op.kind} op; only an activation orphan or a retirement terminalizes (SPEC 13.1); impossible persisted state, refused`);
123
+ if (op.successor !== undefined && (typeof op.successor !== "string" || op.successor.length === 0 || (op.kind !== "takeover" && op.kind !== "registration")))
124
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} op intent carries an invalid successor (SPEC 13.1: only takeover/registration stage successors, and the summary is a non-empty token)`);
125
+ try {
126
+ assertLifecycleToken(op.opId);
127
+ }
128
+ catch {
129
+ throw new EpEnvelopeError("internal", `the issuance gate ${key} op intent carries a malformed opId (SPEC 13.1)`);
130
+ }
131
+ }
132
+ return o;
133
+ }
134
+ // ---- the credential-ledger row grammar (auth store, `cred.` / `epcred.` families) -----------
135
+ /** One KV key segment: no dots (a segment separator), no wildcards, KV-safe. */
136
+ const KEY_SEGMENT = /^[A-Za-z0-9_-]+$/;
137
+ export function assertKeySegment(v, what) {
138
+ if (typeof v !== "string" || !KEY_SEGMENT.test(v))
139
+ throw new EpEnvelopeError("failed-precondition", `${what} ${JSON.stringify(v)} is not a KV-safe key segment (SPEC 13.1)`);
140
+ return v;
141
+ }
142
+ /** A credential id: one or more KV-safe segments (dots allowed BETWEEN segments — the session
143
+ * families use `<sessionId>.c` / `<sessionId>.s` — but never wildcards or empty segments). */
144
+ export function assertCredentialIdTail(v, what) {
145
+ if (typeof v !== "string" || v.length === 0 || v.length > 256 || !v.split(".").every((s) => KEY_SEGMENT.test(s)))
146
+ throw new EpEnvelopeError("failed-precondition", `${what} ${JSON.stringify(v)} is not a bounded dotted credential id (SPEC 13.1)`);
147
+ return v;
148
+ }
149
+ /** A holder principal `<owner>.<actor>` with a REAL owner (derived `u_…` or the dev owner) —
150
+ * eviction is BY PRINCIPAL, so a row that cannot name an evictable principal never ledgers. */
151
+ export function assertHolderPrincipal(v, what) {
152
+ const p = typeof v === "string" ? parsePrincipalKey(v) : null;
153
+ if (!p || !isPrincipalOwnerToken(p.owner))
154
+ throw new EpEnvelopeError("failed-precondition", `${what} ${JSON.stringify(v)} is not a principal dot-form the barrier can evict (SPEC 13.1)`);
155
+ return v;
156
+ }
157
+ export const SOURCE_ROOT = "root";
158
+ /** Validate ONE sourceChain member — `root`, `handle.<issuerKeyId>.<id>`, or
159
+ * `session.<sessionId>` (SPEC 13.1) — and return its parsed shape. */
160
+ export function parseSourceMember(member) {
161
+ if (member === SOURCE_ROOT)
162
+ return { kind: "root" };
163
+ if (typeof member === "string" && member.startsWith("handle.")) {
164
+ const rest = member.slice("handle.".length).split(".");
165
+ if (rest.length === 2 && KEY_SEGMENT.test(rest[0]) && KEY_SEGMENT.test(rest[1]))
166
+ return { kind: "handle", issuerKeyId: rest[0], id: rest[1] };
167
+ }
168
+ if (typeof member === "string" && member.startsWith("session.")) {
169
+ const sid = member.slice("session.".length);
170
+ if (KEY_SEGMENT.test(sid))
171
+ return { kind: "session", sessionId: sid };
172
+ }
173
+ throw new EpEnvelopeError("failed-precondition", `sourceChain member ${JSON.stringify(member)} is not root | handle.<issuerKeyId>.<id> | session.<sessionId> (SPEC 13.1)`);
174
+ }
175
+ export function assertSourceChain(v, what) {
176
+ if (!Array.isArray(v) || v.length === 0)
177
+ throw new EpEnvelopeError("failed-precondition", `${what} must be a non-empty sourceChain (SPEC 13.1: the FULL verified lineage, never absent)`);
178
+ for (const m of v)
179
+ parseSourceMember(m);
180
+ return v;
181
+ }
182
+ /** The agent-family ledger key `cred.<lifecycleUid>.<credentialId>`. */
183
+ export function credRowKey(lifecycleUid, credentialId) {
184
+ return `cred.${assertLifecycleToken(lifecycleUid)}.${assertCredentialIdTail(credentialId, "credentialId")}`;
185
+ }
186
+ /** The endpoint-family ledger key `epcred.<endpoint>.<instanceId>.<credentialId>` (disjoint by
187
+ * explicit prefix, never arity, SPEC 13.1). */
188
+ export function epcredRowKey(endpoint, instanceId, credentialId) {
189
+ return `epcred.${endpointToken(endpoint)}.${assertLifecycleToken(instanceId, "instanceId")}.${assertCredentialIdTail(credentialId, "credentialId")}`;
190
+ }
191
+ /** The endpoint-family ledger KEY PREFIX `epcred.<endpoint>.<instanceId>` (no credentialId tail) —
192
+ * the exact family a barrier enumerates and a key-pinned executor grant scopes to (`…​.>`). Built
193
+ * from the core tokenizers so a grant never spells the prefix by hand (guard-the-core). */
194
+ export function epcredFamilyPrefix(endpoint, instanceId) {
195
+ return `epcred.${endpointToken(endpoint)}.${assertLifecycleToken(instanceId, "instanceId")}`;
196
+ }
197
+ /** The endpoint gate key `epgate.<endpoint>.<instanceId>` (an instanceId is unique ONLY within
198
+ * `(space, endpoint)`, so the key is endpoint-qualified — equal instanceIds under two endpoints
199
+ * never collide on the gate or the credential family, §13.1/§13.6). */
200
+ export function epgateKey(endpoint, instanceId) {
201
+ return `epgate.${endpointToken(endpoint)}.${assertLifecycleToken(instanceId, "instanceId")}`;
202
+ }
203
+ /** Validate an endpoint gate row at the consuming boundary — CLOSED schema; a real owner-grammar
204
+ * serving principal; the per-kind STATE x KIND + successor invariants (§13.1). Byte-for-byte the
205
+ * parser the auth session ledger carried (fact H3 lift), now shared. */
206
+ export function parseEndpointGate(raw, key) {
207
+ let o;
208
+ try {
209
+ o = JSON.parse(dec.decode(raw));
210
+ }
211
+ catch {
212
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} is not JSON (SPEC 13.1)`);
213
+ }
214
+ if (!isRec(o))
215
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} is not an object`);
216
+ const allowed = new Set(["state", "generation", "processEpoch", "registrationRevision", "nameAuthorityRevision", "principal", "op"]);
217
+ for (const k of Object.keys(o))
218
+ if (!allowed.has(k))
219
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} carries the unknown field "${k}" (closed schema, SPEC 13.1)`);
220
+ if (!["open", "frozen", "retired"].includes(o.state) || !uint(o.generation) || !uint(o.processEpoch) || !uint(o.registrationRevision) || !uint(o.nameAuthorityRevision))
221
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} does not validate (SPEC 13.1)`);
222
+ const principal = typeof o.principal === "string" ? parsePrincipalKey(o.principal) : null;
223
+ if (principal === null || !isPrincipalOwnerToken(principal.owner))
224
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} does not carry a CONNZ-attributable serving principal (owner-grammar owner.actor, SPEC 13.1)`);
225
+ if ((o.state === "frozen" || o.state === "retired") && !isRec(o.op))
226
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} is ${o.state} without its durable op intent (SPEC 13.1)`);
227
+ if (o.state === "open" && o.op !== undefined)
228
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} is open but carries an op intent (SPEC 13.1)`);
229
+ if (o.op !== undefined) {
230
+ const op = o.op;
231
+ for (const k of Object.keys(op))
232
+ if (k !== "opId" && k !== "kind" && k !== "successor")
233
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} op intent carries the unknown field "${k}" (closed schema)`);
234
+ if (typeof op.opId !== "string" || !["activation", "takeover", "registration", "retirement"].includes(op.kind))
235
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} op intent does not validate (SPEC 13.1)`);
236
+ if (o.state === "retired" && op.kind !== "activation" && op.kind !== "retirement")
237
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} is retired under a ${op.kind} op; only an activation orphan or a retirement terminalizes (SPEC 13.1); impossible persisted state, refused`);
238
+ if (op.successor !== undefined && (typeof op.successor !== "string" || op.successor.length === 0 || (op.kind !== "takeover" && op.kind !== "registration")))
239
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} op intent carries an invalid successor (SPEC 13.1: only takeover/registration stage successors, and the summary is a non-empty token)`);
240
+ try {
241
+ assertLifecycleToken(op.opId);
242
+ }
243
+ catch {
244
+ throw new EpEnvelopeError("internal", `the endpoint gate ${key} op intent carries a malformed opId (SPEC 13.1)`);
245
+ }
246
+ }
247
+ return o;
248
+ }
249
+ /** Parse + validate a ledger row at its consuming boundary — closed schema, and the embedded
250
+ * identity MUST rebuild the row's own key, so a key-mismatched or family-swapped poison row
251
+ * never authorizes (SPEC 13.1/13.3). */
252
+ export function parseLedgerRow(raw, key) {
253
+ let o;
254
+ try {
255
+ o = JSON.parse(dec.decode(raw));
256
+ }
257
+ catch {
258
+ throw new EpEnvelopeError("internal", `the credential-ledger row ${key} is not JSON; garbled trusted-path state never authorizes (SPEC 13.1)`);
259
+ }
260
+ if (!isRec(o))
261
+ throw new EpEnvelopeError("internal", `the credential-ledger row ${key} is not an object`);
262
+ const allowed = new Set(["credentialId", "holderPrincipal", "lifecycleUid", "endpoint", "sourceChain", "state", "exp"]);
263
+ for (const k of Object.keys(o))
264
+ if (!allowed.has(k))
265
+ throw new EpEnvelopeError("internal", `the credential-ledger row ${key} carries the unknown field "${k}" (closed schema, SPEC 13.1)`);
266
+ if (typeof o.credentialId !== "string" || typeof o.holderPrincipal !== "string" || typeof o.lifecycleUid !== "string" ||
267
+ (o.state !== "active" && o.state !== "revoked") || !uint(o.exp))
268
+ throw new EpEnvelopeError("internal", `the credential-ledger row ${key} does not validate (id/holder/uid/state/exp); a garbled row never authorizes (SPEC 13.1)`);
269
+ try {
270
+ assertSourceChain(o.sourceChain, `row ${key} sourceChain`);
271
+ assertCredentialIdTail(o.credentialId, `row ${key} credentialId`);
272
+ // holderPrincipal is ALWAYS a CONNZ-attributable principal, in BOTH families (the barrier
273
+ // KICKs it; the endpoint name is NOT attributable and never sits here).
274
+ assertHolderPrincipal(o.holderPrincipal, `row ${key} holderPrincipal`);
275
+ }
276
+ catch (e) {
277
+ throw new EpEnvelopeError("internal", `the credential-ledger row ${key} carries a malformed lineage/id/holder: ${e.message}`);
278
+ }
279
+ // KEY BINDING, per family: the row's own identity must rebuild its key exactly. The endpoint
280
+ // family keys on its own `endpoint` field (NOT holderPrincipal), so the key identity and the
281
+ // eviction target stay disjoint.
282
+ let expected;
283
+ if (key.startsWith("cred.")) {
284
+ if (o.endpoint !== undefined)
285
+ throw new EpEnvelopeError("internal", `the agent-family row ${key} carries an endpoint field (that belongs to the epcred family, SPEC 13.1)`);
286
+ expected = credRowKey(o.lifecycleUid, o.credentialId);
287
+ }
288
+ else if (key.startsWith("epcred.")) {
289
+ if (typeof o.endpoint !== "string" || o.endpoint.length === 0)
290
+ throw new EpEnvelopeError("internal", `the endpoint-family row ${key} is missing its endpoint field (it forms the key, SPEC 13.1)`);
291
+ try {
292
+ expected = epcredRowKey(o.endpoint, o.lifecycleUid, o.credentialId);
293
+ }
294
+ catch (e) {
295
+ throw new EpEnvelopeError("internal", `the credential-ledger row ${key} does not validate for the endpoint family: ${e.message}`);
296
+ }
297
+ }
298
+ else {
299
+ throw new EpEnvelopeError("internal", `the credential-ledger row key ${key} is under neither ledger family prefix (SPEC 13.1)`);
300
+ }
301
+ if (expected !== key)
302
+ throw new EpEnvelopeError("internal", `the credential-ledger row at ${key} embeds an identity that rebuilds ${expected}; a key-mismatched row never authorizes (SPEC 13.1)`);
303
+ return o;
304
+ }
305
+ // ---- the static manager's durable slot mapping (records store) ------------------------------
306
+ /** Phases of one static managed slot: the F3 outer spawn intent (`provisioning`, persisted
307
+ * BEFORE head activation), the owned slot (`active`), the terminal in flight (`terminalizing`),
308
+ * and the completed terminal (`retired` — the row is never deleted; a same-alias successor
309
+ * CASes over it). */
310
+ export const STATIC_SLOT_PHASES = new Set(["provisioning", "active", "terminalizing", "retired"]);
311
+ /** The slot key prefix in the records store. Core-owned so permission builders and the manager
312
+ * share ONE encoder (a second literal is the drift class this module bans). */
313
+ export const STATIC_SLOT_PREFIX = "mgrslot";
314
+ /** The slot key `mgrslot.<owner>.<alias>`. */
315
+ export function staticSlotKey(owner, alias) {
316
+ return `${STATIC_SLOT_PREFIX}.${assertKeySegment(owner, "slot owner")}.${assertKeySegment(alias, "slot alias")}`;
317
+ }
318
+ /** Validate a slot row at the consuming boundary — CLOSED schema, and the embedded identity
319
+ * MUST rebuild the row's own key, so a key-mismatched row never drives a resume or terminal. */
320
+ export function parseStaticSlotRow(raw, key) {
321
+ let o;
322
+ try {
323
+ o = JSON.parse(dec.decode(raw));
324
+ }
325
+ catch {
326
+ throw new EpEnvelopeError("internal", `the static slot row ${key} is not JSON; garbled trusted-path state never drives supervision (SPEC 13.1)`);
327
+ }
328
+ if (!isRec(o))
329
+ throw new EpEnvelopeError("internal", `the static slot row ${key} is not an object`);
330
+ const allowed = new Set(["owner", "alias", "actor", "lifecycleUid", "phase", "credentialIds", "managerInstance", "ownerInstanceId"]);
331
+ for (const k of Object.keys(o))
332
+ if (!allowed.has(k))
333
+ throw new EpEnvelopeError("internal", `the static slot row ${key} carries the unknown field "${k}" (closed schema)`);
334
+ if (typeof o.owner !== "string" || typeof o.alias !== "string" || typeof o.actor !== "string" ||
335
+ typeof o.lifecycleUid !== "string" || typeof o.managerInstance !== "string" || o.managerInstance.length === 0 ||
336
+ typeof o.phase !== "string" || !STATIC_SLOT_PHASES.has(o.phase) ||
337
+ (o.ownerInstanceId !== undefined && (typeof o.ownerInstanceId !== "string" || o.ownerInstanceId.length === 0)) ||
338
+ !Array.isArray(o.credentialIds) || !o.credentialIds.every((c) => typeof c === "string" && c.length > 0))
339
+ throw new EpEnvelopeError("internal", `the static slot row ${key} does not validate (owner/alias/actor/uid/phase/credentialIds/managerInstance/ownerInstanceId)`);
340
+ assertLifecycleToken(o.lifecycleUid);
341
+ for (const c of o.credentialIds)
342
+ assertCredentialIdTail(c, `slot row ${key} credentialId`);
343
+ if (staticSlotKey(o.owner, o.alias) !== key)
344
+ throw new EpEnvelopeError("internal", `the static slot row at ${key} embeds an identity that rebuilds ${staticSlotKey(o.owner, o.alias)}; a key-mismatched row never drives supervision`);
345
+ return o;
346
+ }
347
+ //# sourceMappingURL=lifecycle-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle-state.js","sourceRoot":"","sources":["../src/lifecycle-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEzE,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC9B,MAAM,KAAK,GAAG,CAAC,CAAU,EAAgC,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACrH,MAAM,IAAI,GAAG,CAAC,CAAU,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa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text a human or a model reads.
3
+ *
4
+ * This exists because the expression it replaces was copied verbatim into three surfaces (the
5
+ * connector inbox, `cotal join`, and the mesh view), and adding the `artifact` core kind broke all
6
+ * three the same way: an artifact part has no `data` field, so the old `JSON.stringify(p.data)`
7
+ * fallback rendered it as the literal string "undefined". One renderer means a new core part kind
8
+ * is legible everywhere at once, or nowhere — never in two surfaces out of three.
9
+ */
10
+ import type { Part } from "./types.js";
11
+ /** A message's parts as one flat string, space-joined. */
12
+ export declare function partsToText(parts: readonly Part[]): string;
13
+ //# sourceMappingURL=parts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../src/parts.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAavC,0DAA0D;AAC1D,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,CAE1D"}
package/dist/parts.js ADDED
@@ -0,0 +1,17 @@
1
+ /** One part as display text. An unknown extension kind still falls back to its `data`, which is
2
+ * the pre-existing behaviour and deliberately unchanged: extensions are opaque here. */
3
+ function partText(p) {
4
+ if (p.kind === "text")
5
+ return p.text;
6
+ // The digest is verbose, and it is not optional: it is the only handle a reader can act on to
7
+ // actually fetch the bytes. Name and size come from the publisher, so they are shown as the
8
+ // claims they are, not as facts the reader should size a buffer from.
9
+ if (p.kind === "artifact")
10
+ return `[artifact ${p.name} (${p.mediaType}, ${p.size} bytes) ${p.digest}]`;
11
+ return JSON.stringify(p.data);
12
+ }
13
+ /** A message's parts as one flat string, space-joined. */
14
+ export function partsToText(parts) {
15
+ return parts.map(partText).join(" ");
16
+ }
17
+ //# sourceMappingURL=parts.js.map