@capybara-hq/kernel 0.1.0-rc.144 → 0.1.0-rc.146

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 (51) hide show
  1. package/dist/agents/admin-agents.d.ts +20 -3
  2. package/dist/agents/admin-agents.js +38 -7
  3. package/dist/catalog/marketplace-fetch.d.ts +2 -0
  4. package/dist/catalog/marketplace-fetch.js +7 -2
  5. package/dist/catalog/marketplaces.service.d.ts +1 -1
  6. package/dist/catalog/provenance.d.ts +69 -0
  7. package/dist/catalog/provenance.js +108 -0
  8. package/dist/ctx/create-ctx.d.ts +16 -0
  9. package/dist/ctx/create-ctx.js +269 -34
  10. package/dist/errors.d.ts +1 -1
  11. package/dist/errors.js +2 -2
  12. package/dist/extensions/execution-realm.d.ts +96 -0
  13. package/dist/extensions/execution-realm.js +141 -0
  14. package/dist/extensions/extensions.module.js +3 -0
  15. package/dist/extensions/grant-epoch.d.ts +4 -2
  16. package/dist/extensions/grant-epoch.js +4 -2
  17. package/dist/extensions/host.d.ts +26 -3
  18. package/dist/extensions/host.js +135 -10
  19. package/dist/extensions/instance.d.ts +2 -0
  20. package/dist/extensions/instance.js +1 -0
  21. package/dist/extensions/isolated/admission.d.ts +6 -0
  22. package/dist/extensions/isolated/admission.js +17 -0
  23. package/dist/extensions/isolated/tier.d.ts +14 -0
  24. package/dist/extensions/isolated/tier.js +27 -0
  25. package/dist/extensions/ledger.d.ts +5 -0
  26. package/dist/extensions/ledger.js +16 -0
  27. package/dist/extensions/permission-view.d.ts +2 -2
  28. package/dist/extensions/publisher-proof.job.d.ts +39 -0
  29. package/dist/extensions/publisher-proof.job.js +160 -0
  30. package/dist/extensions/registry.d.ts +6 -0
  31. package/dist/extensions/registry.js +8 -0
  32. package/dist/extensions/review-hash.d.ts +114 -0
  33. package/dist/extensions/review-hash.js +145 -0
  34. package/dist/extensions/revision-grants.d.ts +10 -0
  35. package/dist/extensions/revocation-leases.d.ts +273 -0
  36. package/dist/extensions/revocation-leases.js +533 -0
  37. package/dist/extensions/revocation.d.ts +78 -0
  38. package/dist/extensions/revocation.js +202 -0
  39. package/dist/index.d.ts +6 -2
  40. package/dist/index.js +6 -2
  41. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  42. package/dist/lifecycle/kernel-lifecycle.js +24 -18
  43. package/dist/overrides.d.ts +5 -1
  44. package/dist/overrides.js +2 -0
  45. package/dist/packages/official-publisher.d.ts +44 -0
  46. package/dist/packages/official-publisher.js +147 -48
  47. package/dist/packages/provenance.d.ts +6 -0
  48. package/dist/packages/provenance.js +26 -9
  49. package/dist/platform/ops/admin-items.ops.js +1 -1
  50. package/dist/roles/worker.module.js +3 -0
  51. package/package.json +2 -2
@@ -0,0 +1,273 @@
1
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
+ import { type GrantEpochView } from "./isolated/authorization.js";
3
+ import { type ExecutionRealm, type RevisionGrant, type RevisionGrantState } from "./revision-grants.js";
4
+ /**
5
+ * Revocation on a serving replica (extension permission model spec 2026-12-04, "Revocation, audit
6
+ * and people"; plan task 1.3e). The write side is {@link ExtensionRevocations} in `revocation.ts`;
7
+ * this file holds what the host and `ctx` need without depending on the Nest service: the key
8
+ * classes, the serving surface of a grant, and the replica-local permission leases.
9
+ *
10
+ * A lease belongs to one extension instance (one loaded generation of one package revision). It
11
+ * caches the revision's grant state, valid only at the grant epoch it was confirmed at and while
12
+ * that epoch is fresh: every committed grant change advances the epoch (the grant tables' triggers
13
+ * of migration 0235, on the 0234 epoch),
14
+ * so a replica that missed the fan-out hint still revalidates within the 5 s bound. Revalidations
15
+ * are coalesced, and a read started before a change can only confirm the epoch it started at.
16
+ *
17
+ * Shadow mode until plan task 1.5a (the plan's rollout fence): the revocation is written, audited and
18
+ * advances the epoch, and every lease computes its decision within the bound and reports it (logs,
19
+ * {@link RevisionLeases.statesOf}, the Partially revoked view), but nothing is refused, aborted,
20
+ * withdrawn or unloaded on account of it, and no call waits on a lease read: the legacy approval
21
+ * path keeps governing. Task 1.5a sets {@link REVOCATION_ENFORCED} and removes the shadow branch.
22
+ * When enforcing, a revision with no grant never refuses, and one with a grant fails closed while
23
+ * its state cannot be confirmed.
24
+ */
25
+ /** The rollout fence: false until plan task 1.5a turns enforcement on and deletes this switch. */
26
+ export declare const REVOCATION_ENFORCED: boolean;
27
+ /**
28
+ * The kernel test seam that enforces revocation before task 1.5a (a kernel test's
29
+ * `KernelAppOptions.overrides`, value `true`), so the dual-replica tests exercise the enforcing
30
+ * branches. Task 1.5a removes it with {@link REVOCATION_ENFORCED}.
31
+ */
32
+ export declare const REVOCATION_ENFORCEMENT: unique symbol;
33
+ /**
34
+ * A revision whose grant no longer lets it run where it would (whole grant revoked, or server full
35
+ * access revoked while the remaining grant still needs it, or no isolated form): it waits for a new
36
+ * review instead of failing (enforcing only).
37
+ */
38
+ export declare class RevocationPendingError extends Error {
39
+ constructor(message: string);
40
+ }
41
+ /** What revoking one key does (the spec's revocation table). */
42
+ export type KeyClass =
43
+ /** A registration (route, tool, provider, hook, view, setup check): withdrawn. */
44
+ {
45
+ kind: "registration";
46
+ }
47
+ /** A `ctx` resource or operation: refused with `ExtensionPermissionError`, handles closed. */
48
+ | {
49
+ kind: "capability";
50
+ }
51
+ /** `execution.full-access:<realm>`: the privileged generation is unloaded. */
52
+ | {
53
+ kind: "full_access";
54
+ realm: ExecutionRealm;
55
+ }
56
+ /**
57
+ * A key no running surface can withdraw on its own (network, config, tables, embeds,
58
+ * dependencies, client code, raw egress, migration warnings): only a whole-grant revocation,
59
+ * which unloads the revision, takes it away, so {@link revocableKeys} refuses it alone.
60
+ */
61
+ | {
62
+ kind: "unenforced";
63
+ };
64
+ export declare function classifyKey(key: string): KeyClass;
65
+ /** The keys a partial revocation cannot honour on its own (revoke the whole grant instead). */
66
+ export declare function unrevocableKeys(keys: readonly string[]): string[];
67
+ /** The grant fields revocation reads. */
68
+ export type GrantSurface = Pick<RevisionGrant, "keys" | "disabledKeys" | "retiredKeys" | "realms" | "retiredForcing" | "state" | "generation">;
69
+ /**
70
+ * What a full-access realm whose key no longer serves becomes: `isolated` when the remaining grant
71
+ * fits the sandbox, otherwise `pending_approval`. The remaining grant fits when none of the realm's
72
+ * forcing keys still applies: each was retired, or is a permission key that no longer serves (a
73
+ * host reason such as `host.no-isolation` is never a grant key, so it keeps the realm pending).
74
+ */
75
+ export declare function realmAfterRevocation(grant: GrantSurface, realm: ExecutionRealm): "isolated" | "pending_approval";
76
+ /**
77
+ * A revision grant as the inventory shows it: the withdrawn keys by class and the remaining
78
+ * serving surface (**Partially revoked** when some, not all, keys are withdrawn).
79
+ */
80
+ export interface RevocationView {
81
+ state: RevisionGrantState;
82
+ generation: number;
83
+ /** Keys revoked or retired (every key once the grant is revoked). */
84
+ withdrawn: string[];
85
+ /** Keys still serving. */
86
+ serving: string[];
87
+ registrations: string[];
88
+ capabilities: string[];
89
+ fullAccess: {
90
+ realm: ExecutionRealm;
91
+ next: "isolated" | "pending_approval";
92
+ }[];
93
+ }
94
+ export declare function revocationView(grant: GrantSurface): RevocationView;
95
+ /** A revision's grant state as one lease caches it. */
96
+ export interface LeaseState {
97
+ status: "no_grant" | RevisionGrantState;
98
+ generation?: number;
99
+ /** Grant keys that no longer serve: revoked or retired, every key once the grant is revoked. */
100
+ refused: ReadonlySet<string>;
101
+ /** Realms the grant reviewed whose full access no longer serves. */
102
+ realmsRevoked: readonly ExecutionRealm[];
103
+ }
104
+ export declare const NO_GRANT: LeaseState;
105
+ /**
106
+ * The lease state of a revision's newest grant generation. A retired grant is not a revocation
107
+ * (its revision was superseded; admission of a superseded revision belongs to the enforcing
108
+ * cutover), so it refuses nothing here.
109
+ */
110
+ export declare function leaseStateOf(grant: GrantSurface | undefined): LeaseState;
111
+ /**
112
+ * The newest grant generation of each revision stored under the given package sha256s (the
113
+ * package's sha512 names the revision): one query for all of them. A package without a recorded
114
+ * digest or a review has no entry. Grants and packages are deployment rows (no org_id), read
115
+ * outside any org scope.
116
+ */
117
+ export declare function readGrantSurfacesBySha256(db: KernelSchemaDb, sha256s: readonly string[]): Promise<Map<string, GrantSurface>>;
118
+ /** The newest grant generation of the revision stored under one package sha256, or undefined. */
119
+ export declare function readGrantSurfaceBySha256(db: KernelSchemaDb, sha256: string): Promise<GrantSurface | undefined>;
120
+ /** Newly refused keys of a lease, after a revalidation that saw them (enforcing only). */
121
+ export type LeaseRefusalListener = (keys: string[], state: LeaseState) => void;
122
+ export interface LeaseOptions {
123
+ plugin: string;
124
+ /** The package of the instance; null (a config-declared extension): no lease. */
125
+ sha256: string | null;
126
+ /** The instance runs in the kernel process (full access for the server realm, today's trusted tier). */
127
+ inProcess: boolean;
128
+ }
129
+ /**
130
+ * The enforcing decision for one key under a confirmed lease state: refused when the grant no
131
+ * longer serves it, when the whole grant is revoked, or when an in-process generation lost its
132
+ * server full access. Keys the grant never reviewed are not revocation's to refuse.
133
+ */
134
+ export declare function leaseAllows(state: LeaseState, key: string, inProcess: boolean): boolean;
135
+ /** One revalidation's read: the epoch captured before it, and the state (undefined: it failed). */
136
+ interface LeaseRead {
137
+ epoch: string | undefined;
138
+ checkedAt: number;
139
+ state: (sha256: string) => LeaseState | undefined;
140
+ }
141
+ /**
142
+ * The revision authority of one extension instance. {@link check} answers synchronously while the
143
+ * state is confirmed at the fresh epoch, and otherwise after one coalesced revalidation.
144
+ */
145
+ export declare class PermissionLease {
146
+ private readonly owner;
147
+ readonly plugin: string;
148
+ readonly sha256: string;
149
+ readonly inProcess: boolean;
150
+ private state;
151
+ /** The epoch the state was confirmed at; undefined while unconfirmed. */
152
+ private epoch;
153
+ private checkedAt;
154
+ /** The last revalidation failed (no epoch or no grant read): what is known is not confirmed. */
155
+ private readFailed;
156
+ private pending;
157
+ private readonly controllers;
158
+ /** Aborted when the whole lease is fenced: closes every handle that relied on it. */
159
+ private fenced;
160
+ private readonly listeners;
161
+ /** Keys whose computed refusal was already reported in shadow mode. */
162
+ private readonly reported;
163
+ closed: boolean;
164
+ constructor(owner: RevisionLeases, plugin: string, sha256: string, inProcess: boolean);
165
+ /** Whether this replica enforces revocation (false until plan task 1.5a). */
166
+ get enforced(): boolean;
167
+ /**
168
+ * Whether `key` may be used now. In shadow mode always true and never waiting: a stale lease
169
+ * refreshes in the background, and a computed refusal is reported once per key. When enforcing:
170
+ * {@link wouldAllow} after one coalesced revalidation when the state is not confirmed.
171
+ */
172
+ check(key: string): boolean | Promise<boolean>;
173
+ /**
174
+ * The computed decision from what is known: {@link leaseAllows} under the last state, and a
175
+ * refusal when the last read failed and the revision has a grant or was never confirmed (fail
176
+ * closed; a revision confirmed without a grant has nothing to revoke).
177
+ */
178
+ wouldAllow(key: string): boolean;
179
+ /** The keys refused by the last confirmed state. */
180
+ refusedKeys(): string[];
181
+ /** The last confirmed state, if any. */
182
+ current(): LeaseState | undefined;
183
+ /**
184
+ * Aborted when `key` is refused or the lease is fenced (enforcing only): the handles that relied
185
+ * on it close. A key restored by a new grant gets a fresh signal.
186
+ */
187
+ signal(key: string): AbortSignal;
188
+ onRefused(listener: LeaseRefusalListener): () => void;
189
+ close(): void;
190
+ /** Drops the confirmation (a hint or a fence): the next check reads the grant again. */
191
+ invalidate(): void;
192
+ /**
193
+ * The settle deadline or an epoch outage: a lease with a grant that is not confirmed at the
194
+ * current epoch is unconfirmed; when enforcing it also closes its handles, and the next check
195
+ * revalidates (failing closed if it cannot).
196
+ */
197
+ fenceIfStale(epoch: string | undefined): void;
198
+ /** Revalidates alone, or with a read shared by every lease of a fence or epoch change. */
199
+ revalidate(shared?: Promise<LeaseRead>): Promise<LeaseState | undefined>;
200
+ private valid;
201
+ private apply;
202
+ }
203
+ export interface RevisionLeasesOptions {
204
+ epochs: GrantEpochView;
205
+ /** The lease states of the revisions stored under package sha256s (one query for all). */
206
+ read: (sha256s: readonly string[]) => Promise<Map<string, LeaseState>>;
207
+ /**
208
+ * An in-process generation lost its server full access, or the whole grant was revoked
209
+ * (enforcing only): converge, so the generation is unloaded (and restarted isolated when the
210
+ * remaining grant fits).
211
+ */
212
+ onUnload: (plugin: string) => void;
213
+ /**
214
+ * A new grant serves withdrawn keys again (enforcing only): reload the instance, since withdrawn
215
+ * registrations come back only with a new setup.
216
+ */
217
+ onRestored: (plugin: string) => void;
218
+ onFault?: (plugin: string, err: unknown) => void;
219
+ /** A decision computed but not enforced (shadow mode): what enforcement would do. */
220
+ onShadow?: (plugin: string, decision: ShadowRevocation) => void;
221
+ /**
222
+ * Enforce the decisions; defaults to {@link REVOCATION_ENFORCED}. Only the tests of the
223
+ * enforcing branch pass true; task 1.5a removes this option with the shadow branch.
224
+ */
225
+ enforce?: boolean;
226
+ now?: () => number;
227
+ }
228
+ /** What a lease would enforce, reported while revocation is computed only. */
229
+ export type ShadowRevocation = {
230
+ refusedCall: string;
231
+ } | {
232
+ refused: string[];
233
+ lostServerFullAccess: boolean;
234
+ revoked: boolean;
235
+ state: LeaseState;
236
+ };
237
+ /** The leases of every instance on this replica (one per instance with a package). */
238
+ export declare class RevisionLeases {
239
+ private readonly options;
240
+ private readonly leases;
241
+ readonly epochs: GrantEpochView;
242
+ readonly now: () => number;
243
+ readonly enforced: boolean;
244
+ /** Callbacks run in the context the leases were built in, never a caller's org scope. */
245
+ private readonly inOwnContext;
246
+ constructor(options: RevisionLeasesOptions);
247
+ /** Opens the lease of an instance and starts confirming it; undefined without a package. */
248
+ open({ plugin, sha256, inProcess }: LeaseOptions): PermissionLease | undefined;
249
+ /** The confirmed states of a plugin's leases on this replica (the computed decisions). */
250
+ statesOf(plugin: string): LeaseState[];
251
+ /** The local fence after a commit, or a fan-out hint: revalidate the plugin's leases now. */
252
+ fence(plugin?: string): Promise<void>;
253
+ /** The grant epoch advanced: every lease may be stale; revalidate them all with one read. */
254
+ epochChanged(): Promise<void>;
255
+ /** The settle deadline after an epoch change: close what was not confirmed at the new epoch. */
256
+ fenceStale(): void;
257
+ /** No epoch read succeeded for the whole bound: close every lease that has a grant. */
258
+ fenceAll(): void;
259
+ /** One lease's read (its first confirmation, or a check that found it stale). */
260
+ readOne(sha256: string): Promise<LeaseRead>;
261
+ forget(lease: PermissionLease): void;
262
+ mustUnload(lease: PermissionLease): void;
263
+ restored(lease: PermissionLease): void;
264
+ shadow(lease: PermissionLease, decision: ShadowRevocation): void;
265
+ fault(lease: PermissionLease, err: unknown): void;
266
+ private revalidateAll;
267
+ /**
268
+ * The epoch is captured before the grants are read: a revocation committed after the read's
269
+ * snapshot advances the epoch past this value, so the result never outlives it.
270
+ */
271
+ private readStates;
272
+ }
273
+ export {};