@capybara-hq/kernel 0.1.0-rc.145 → 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 (37) hide show
  1. package/dist/catalog/marketplaces.service.d.ts +1 -1
  2. package/dist/catalog/provenance.d.ts +69 -0
  3. package/dist/catalog/provenance.js +108 -0
  4. package/dist/ctx/create-ctx.d.ts +16 -0
  5. package/dist/ctx/create-ctx.js +269 -34
  6. package/dist/extensions/execution-realm.d.ts +96 -0
  7. package/dist/extensions/execution-realm.js +141 -0
  8. package/dist/extensions/extensions.module.js +3 -0
  9. package/dist/extensions/grant-epoch.d.ts +4 -2
  10. package/dist/extensions/grant-epoch.js +4 -2
  11. package/dist/extensions/host.d.ts +25 -2
  12. package/dist/extensions/host.js +120 -8
  13. package/dist/extensions/instance.d.ts +2 -0
  14. package/dist/extensions/instance.js +1 -0
  15. package/dist/extensions/isolated/admission.d.ts +6 -0
  16. package/dist/extensions/isolated/admission.js +17 -0
  17. package/dist/extensions/ledger.d.ts +5 -0
  18. package/dist/extensions/ledger.js +16 -0
  19. package/dist/extensions/permission-view.d.ts +2 -2
  20. package/dist/extensions/registry.d.ts +6 -0
  21. package/dist/extensions/registry.js +8 -0
  22. package/dist/extensions/review-hash.d.ts +114 -0
  23. package/dist/extensions/review-hash.js +145 -0
  24. package/dist/extensions/revision-grants.d.ts +10 -0
  25. package/dist/extensions/revocation-leases.d.ts +273 -0
  26. package/dist/extensions/revocation-leases.js +533 -0
  27. package/dist/extensions/revocation.d.ts +78 -0
  28. package/dist/extensions/revocation.js +202 -0
  29. package/dist/index.d.ts +6 -2
  30. package/dist/index.js +6 -2
  31. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  32. package/dist/lifecycle/kernel-lifecycle.js +24 -18
  33. package/dist/overrides.d.ts +5 -1
  34. package/dist/overrides.js +2 -0
  35. package/dist/packages/official-publisher.d.ts +39 -0
  36. package/dist/packages/official-publisher.js +125 -47
  37. package/package.json +2 -2
@@ -209,7 +209,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
209
209
  /** The host versions (an entry's `minKernel` is judged against them). */
210
210
  export declare const HOST_VERSIONS: {
211
211
  readonly kernel: string;
212
- readonly sdk: "0.1.0-rc.102";
212
+ readonly sdk: "0.1.0-rc.103";
213
213
  };
214
214
  /** Whether this deployment satisfies the entry's `minKernel`. */
215
215
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -0,0 +1,69 @@
1
+ import type { NewRevisionGrant, PublisherIdentity } from "../extensions/revision-grants.js";
2
+ import { type PublisherCertificate, type VerifiedPublisher } from "../packages/official-publisher.js";
3
+ /**
4
+ * Publisher evidence for review and continuity (extension permission model spec, "Review, updates
5
+ * and provenance" step 5; plan task 1.2e). Pure. The signatures are verified by
6
+ * `packages/official-publisher.ts` (`verifyPublisher`, any GitHub Actions publisher;
7
+ * `verifyOfficialPublisher`, the official repository); here the signed identity is normalized
8
+ * and the evidence of one revision is classified:
9
+ * - `verified`: both attestations verified; the normalized identity is recorded on the grant and
10
+ * continuity requires it unchanged;
11
+ * - `pin_only`: the official marketplace under the `pin-only` policy, an exact digest without
12
+ * attestation: valid integrity, no verified-publisher continuity;
13
+ * - `none`: no or unverifiable attestation outside the official marketplace;
14
+ * - refused: a byte-integrity mismatch always, and an official marketplace revision without proof
15
+ * under the default `require` policy.
16
+ * Publisher identity confers no permission: it only lets an approved grant continue.
17
+ */
18
+ export type PublisherEvidence = NewRevisionGrant["publisher"];
19
+ /**
20
+ * The ref class continuity compares: a branch exactly, every release tag as one class (a publisher
21
+ * releasing from tags signs each release with a new tag ref). Other refs are kept exactly.
22
+ */
23
+ export declare function refClass(ref: string): string;
24
+ /**
25
+ * The normalized identity of a signing certificate: the issuer and repository URLs canonical, the
26
+ * identity rebuilt from the normalized repository and workflow (so case or `.git` variants of one
27
+ * repository compare equal), the stable repository and owner ids, and the ref class. The exact ref
28
+ * and commit are evidence to display, not identity.
29
+ */
30
+ export declare function normalizePublisherIdentity(certificate: PublisherCertificate): PublisherIdentity;
31
+ /** Two verified identities name the same publisher (exact after normalization). */
32
+ export declare function samePublisher(a: PublisherIdentity, b: PublisherIdentity): boolean;
33
+ /** What the review shows about a verified signature besides the identity: the exact build. */
34
+ export interface SignatureDisplay {
35
+ ref: string;
36
+ commit: string;
37
+ }
38
+ export type PublisherEvidenceOutcome = {
39
+ outcome: "accepted";
40
+ publisher: PublisherEvidence;
41
+ evidenceDigest?: string;
42
+ signature?: SignatureDisplay;
43
+ /** A verified signature that is not the identity this source requires, shown, not anchored. */
44
+ foreignIdentity?: PublisherIdentity;
45
+ } | {
46
+ outcome: "refused";
47
+ reason: string;
48
+ };
49
+ /**
50
+ * The publisher evidence of one revision:
51
+ * - `integrity`: whether the bytes matched the recorded digest; a mismatch always refuses;
52
+ * - `attestation`: the verification result, or `undefined` when no attestation was read (offline,
53
+ * or the registry has none);
54
+ * - `official`: the revision comes from the built-in official marketplace, with its
55
+ * `officialPublisherProof` policy.
56
+ */
57
+ export declare function classifyPublisherEvidence(input: {
58
+ integrity: "match" | "mismatch";
59
+ attestation?: {
60
+ ok: true;
61
+ verified: VerifiedPublisher;
62
+ } | {
63
+ ok: false;
64
+ reason: string;
65
+ };
66
+ official?: {
67
+ policy: "require" | "pin-only";
68
+ };
69
+ }): PublisherEvidenceOutcome;
@@ -0,0 +1,108 @@
1
+ import { officialPublisherProblem, } from "../packages/official-publisher.js";
2
+ import { canonicalJson } from "../tools/canonical-json.js";
3
+ /** `https://Host/Path/` → `https://host/Path` without a trailing slash; other strings trimmed. */
4
+ function normalizeUrl(value) {
5
+ const trimmed = value.trim().replace(/\/+$/, "");
6
+ try {
7
+ const url = new URL(trimmed);
8
+ return `${url.protocol}//${url.host.toLowerCase()}${url.pathname.replace(/\/+$/, "")}`;
9
+ }
10
+ catch {
11
+ return trimmed;
12
+ }
13
+ }
14
+ /**
15
+ * A repository URL: `git+`, `.git` and a trailing slash dropped; on GitHub the owner and name are
16
+ * lowercased (GitHub treats them case-insensitively).
17
+ */
18
+ function normalizeRepository(value) {
19
+ const url = normalizeUrl(value
20
+ .trim()
21
+ .replace(/^git\+/, "")
22
+ .replace(/\.git$/, ""));
23
+ return url.startsWith("https://github.com/") ? url.toLowerCase() : url;
24
+ }
25
+ /** A workflow path relative to the repository root. */
26
+ const normalizeWorkflow = (value) => value.trim().replace(/^(?:\.\/|\/)+/, "");
27
+ /**
28
+ * The ref class continuity compares: a branch exactly, every release tag as one class (a publisher
29
+ * releasing from tags signs each release with a new tag ref). Other refs are kept exactly.
30
+ */
31
+ export function refClass(ref) {
32
+ const trimmed = ref.trim();
33
+ return trimmed.startsWith("refs/tags/") ? "refs/tags/*" : trimmed;
34
+ }
35
+ /**
36
+ * The normalized identity of a signing certificate: the issuer and repository URLs canonical, the
37
+ * identity rebuilt from the normalized repository and workflow (so case or `.git` variants of one
38
+ * repository compare equal), the stable repository and owner ids, and the ref class. The exact ref
39
+ * and commit are evidence to display, not identity.
40
+ */
41
+ export function normalizePublisherIdentity(certificate) {
42
+ const repository = normalizeRepository(certificate.repository);
43
+ const workflow = normalizeWorkflow(certificate.workflow);
44
+ return {
45
+ issuer: normalizeUrl(certificate.issuer),
46
+ identity: `${repository}/${workflow}`,
47
+ repository,
48
+ repositoryId: certificate.repositoryId.trim(),
49
+ ownerId: certificate.ownerId.trim(),
50
+ workflow,
51
+ refClass: refClass(certificate.ref),
52
+ };
53
+ }
54
+ /** Two verified identities name the same publisher (exact after normalization). */
55
+ export function samePublisher(a, b) {
56
+ return canonicalJson(a) === canonicalJson(b);
57
+ }
58
+ /**
59
+ * The publisher evidence of one revision:
60
+ * - `integrity`: whether the bytes matched the recorded digest; a mismatch always refuses;
61
+ * - `attestation`: the verification result, or `undefined` when no attestation was read (offline,
62
+ * or the registry has none);
63
+ * - `official`: the revision comes from the built-in official marketplace, with its
64
+ * `officialPublisherProof` policy.
65
+ */
66
+ export function classifyPublisherEvidence(input) {
67
+ if (input.integrity === "mismatch") {
68
+ return { outcome: "refused", reason: "the package bytes do not match the recorded digest" };
69
+ }
70
+ if (input.attestation?.ok) {
71
+ const { certificate, evidenceDigest } = input.attestation.verified;
72
+ const identity = normalizePublisherIdentity(certificate);
73
+ const problem = input.official
74
+ ? officialPublisherProblem(input.attestation.verified)
75
+ : undefined;
76
+ if (input.official && problem !== undefined) {
77
+ // an official revision signed by anyone else never anchors continuity
78
+ if (input.official.policy === "require") {
79
+ return {
80
+ outcome: "refused",
81
+ reason: `an official marketplace revision needs official proof: ${problem}`,
82
+ };
83
+ }
84
+ return {
85
+ outcome: "accepted",
86
+ publisher: { evidence: "pin_only" },
87
+ foreignIdentity: identity,
88
+ };
89
+ }
90
+ return {
91
+ outcome: "accepted",
92
+ publisher: { evidence: "verified", identity },
93
+ evidenceDigest,
94
+ signature: { ref: certificate.ref, commit: certificate.commit },
95
+ };
96
+ }
97
+ if (input.official?.policy === "require") {
98
+ const why = input.attestation ? `: ${input.attestation.reason}` : "";
99
+ return {
100
+ outcome: "refused",
101
+ reason: `an official marketplace revision needs verified publisher proof${why}`,
102
+ };
103
+ }
104
+ if (input.official?.policy === "pin-only") {
105
+ return { outcome: "accepted", publisher: { evidence: "pin_only" } };
106
+ }
107
+ return { outcome: "accepted", publisher: { evidence: "none" } };
108
+ }
@@ -9,6 +9,7 @@ import type { ServiceEventHandler, ServiceEventsBackend } from "../device-access
9
9
  import type { DialInAccess } from "../dial-in/access.js";
10
10
  import { type RegisteredHook } from "../extensions/hooks.js";
11
11
  import { RegistrationLedger } from "../extensions/ledger.js";
12
+ import type { LeaseOptions, PermissionLease } from "../extensions/revocation-leases.js";
12
13
  import type { InboxItemsService } from "../inbox/inbox-items.service.js";
13
14
  import type { LockService } from "../infra/lock/lock.service.js";
14
15
  import type { ModelEmbeddings } from "../models/embeddings.js";
@@ -114,6 +115,19 @@ export interface KernelDeps {
114
115
  * (`streamExternalText` drops its hint).
115
116
  */
116
117
  externalConversations?: () => ExternalConversationsBackend | undefined;
118
+ /**
119
+ * The replica's permission leases (`RevisionLeases`, plan task 1.3e): an instance loaded from a
120
+ * package holds one, and `ctx` refuses the keys its revision grant no longer serves. Absent (a
121
+ * ctx built alone in a test, the CLI): nothing is refused for a revocation.
122
+ */
123
+ leases?: {
124
+ open(opts: LeaseOptions): PermissionLease | undefined;
125
+ };
126
+ /**
127
+ * Called after revoked registrations were withdrawn: derived tables (routes) rebuild and the
128
+ * registry's change listeners refresh.
129
+ */
130
+ registrationsChanged?: (plugin: string) => void;
117
131
  runWorkers: boolean;
118
132
  /** 内核 logger(`debug` 可选:插件 Logger 没有它,测试可不给)。 */
119
133
  log: Logger & {
@@ -276,4 +290,6 @@ export declare function createExtensionContext(deps: KernelDeps, manifest: Exten
276
290
  identity?: {
277
291
  sha256: string | null;
278
292
  db?: Kysely<any>;
293
+ /** The instance runs in the kernel process (default); false for an isolated instance. */
294
+ inProcess?: boolean;
279
295
  }): KernelExtensionContext;