@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
@@ -1,5 +1,8 @@
1
+ import { PluginIcons } from "../extensions/plugin-icons.js";
1
2
  import { KernelDb } from "../infra/database/kernel-db.js";
2
3
  import { type Page } from "../infra/paging/paged-read.js";
4
+ import { type ConnectorSetup } from "../tools/connector-setup.js";
5
+ import { Credentials } from "../tools/credentials.js";
3
6
  import { AgentLookup, type AgentVisibility } from "./agent-lookup.js";
4
7
  import { type AgentDefinition } from "./definition.js";
5
8
  import type { AgentAvatarView } from "./profile.js";
@@ -56,7 +59,8 @@ export interface AdminAgentDetail extends AdminAgentRow {
56
59
  }[];
57
60
  /**
58
61
  * The org's live connectors it can use by name (tools default-on): every one but those whose
59
- * every tool it turns off. Never auth, credentials or a member's state.
62
+ * every tool it turns off, with their state and icon. Never auth, credentials or a member's
63
+ * state.
60
64
  */
61
65
  connectors: AdminAgentConnector[];
62
66
  }
@@ -65,6 +69,16 @@ export interface AdminAgentConnector {
65
69
  name: string;
66
70
  slug: string;
67
71
  status: "active" | "disabled";
72
+ /**
73
+ * Derived from key presence only, as on the org's connector routes: `needs_config` while the
74
+ * org input its auth needs (an OAuth client or an org credential) is absent.
75
+ */
76
+ setup: ConnectorSetup;
77
+ /**
78
+ * The icon it shows on the super admin's routes: its platform template's own icon, else its
79
+ * plugin's (`GET /api/v1/admin/catalog/...`), else null (a custom connector, or none).
80
+ */
81
+ icon: string | null;
68
82
  }
69
83
  export interface AdminAgentListQuery {
70
84
  orgId?: string | undefined;
@@ -83,7 +97,9 @@ export interface AdminAgentListQuery {
83
97
  export declare class AdminAgents {
84
98
  private readonly db;
85
99
  private readonly lookup;
86
- constructor(db: KernelDb, lookup: AgentLookup);
100
+ private readonly credentials;
101
+ private readonly icons;
102
+ constructor(db: KernelDb, lookup: AgentLookup, credentials: Pick<Credentials, "orgInputs">, icons: Pick<PluginIcons, "ofTemplatesOrItems">);
87
103
  /**
88
104
  * One page of every live org's live agents, filtered, newest first (`created_at`, then id), by
89
105
  * page number without a snapshot (table pagination spec §2.3: agents are edited in place).
@@ -100,7 +116,8 @@ export declare class AdminAgents {
100
116
  private skillsOff;
101
117
  /**
102
118
  * The org's live connectors by name, minus those the agent turns off as a whole: `tools: "all"`,
103
- * or a list naming every tool the connector has (a connector without tools stays listed).
119
+ * or a list naming every tool the connector has (a connector without tools stays listed). Each
120
+ * with its derived setup state and its icon on the admin routes (one lookup each for all).
104
121
  */
105
122
  private connectorsOf;
106
123
  /** The list columns of live agents in live orgs. */
@@ -11,10 +11,13 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { escapeLike } from "../conversations/conversations.service.js";
13
13
  import { ApiError } from "../errors.js";
14
+ import { PluginIcons } from "../extensions/plugin-icons.js";
14
15
  import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
15
16
  import { KernelDb } from "../infra/database/kernel-db.js";
16
17
  import { assertReadablePage, cappedCount, PAGED_TOTAL_CAP, pageOf, pageOffset, } from "../infra/paging/paged-read.js";
17
18
  import { agentSkills, builtinSkillIds, builtinSkillPlugins, linkedCopyIds, skillIdsOf, usableSkillVersions, } from "../skills/usable.js";
19
+ import { connectorSetups } from "../tools/connector-setup.js";
20
+ import { Credentials } from "../tools/credentials.js";
18
21
  import { AgentLookup } from "./agent-lookup.js";
19
22
  import { avatarView } from "./avatar-view.js";
20
23
  import { skillDisabled, } from "./definition.js";
@@ -27,9 +30,13 @@ const notFound = () => new ApiError("agent.not_found", "Agent not found");
27
30
  let AdminAgents = class AdminAgents {
28
31
  db;
29
32
  lookup;
30
- constructor(db, lookup) {
33
+ credentials;
34
+ icons;
35
+ constructor(db, lookup, credentials, icons) {
31
36
  this.db = db;
32
37
  this.lookup = lookup;
38
+ this.credentials = credentials;
39
+ this.icons = icons;
33
40
  }
34
41
  /**
35
42
  * One page of every live org's live agents, filtered, newest first (`created_at`, then id), by
@@ -147,12 +154,21 @@ let AdminAgents = class AdminAgents {
147
154
  }
148
155
  /**
149
156
  * The org's live connectors by name, minus those the agent turns off as a whole: `tools: "all"`,
150
- * or a list naming every tool the connector has (a connector without tools stays listed).
157
+ * or a list naming every tool the connector has (a connector without tools stays listed). Each
158
+ * with its derived setup state and its icon on the admin routes (one lookup each for all).
151
159
  */
152
160
  async connectorsOf(orgId, disabled) {
153
161
  const rows = await this.db
154
162
  .selectFrom("connectors as c")
155
- .select(["c.id", "c.name", "c.slug", "c.status"])
163
+ .select([
164
+ "c.id",
165
+ "c.name",
166
+ "c.slug",
167
+ "c.status",
168
+ "c.auth",
169
+ "c.platform_template_id",
170
+ "c.catalog_item_id",
171
+ ])
156
172
  .select(sql `coalesce((SELECT array_agg(t.name) FROM capybara.connector_tools t
157
173
  WHERE t.connector_id = c.id), '{}')`.as("tools"))
158
174
  .where("c.org_id", "=", orgId)
@@ -178,9 +194,22 @@ let AdminAgents = class AdminAgents {
178
194
  return true;
179
195
  return tools.length > 0 && tools.every((t) => off.has(t));
180
196
  };
181
- return rows
182
- .filter((r) => !allOff(r.id, r.tools))
183
- .map((r) => ({ id: r.id, name: r.name, slug: r.slug, status: r.status }));
197
+ const listed = rows.filter((r) => !allOff(r.id, r.tools));
198
+ const [setups, icons] = await Promise.all([
199
+ connectorSetups(this.credentials, orgId, listed.map((r) => ({ id: r.id, auth: r.auth }))),
200
+ this.icons.ofTemplatesOrItems(listed.map((r) => ({
201
+ templateId: r.platform_template_id ?? null,
202
+ itemId: r.catalog_item_id ?? null,
203
+ })), { kind: "admin" }),
204
+ ]);
205
+ return listed.map((r, i) => ({
206
+ id: r.id,
207
+ name: r.name,
208
+ slug: r.slug,
209
+ status: r.status,
210
+ setup: setups.get(r.id) ?? "needs_config",
211
+ icon: icons[i] ?? null,
212
+ }));
184
213
  }
185
214
  /** The list columns of live agents in live orgs. */
186
215
  rows() {
@@ -214,7 +243,9 @@ let AdminAgents = class AdminAgents {
214
243
  AdminAgents = __decorate([
215
244
  Injectable(),
216
245
  __param(0, Inject(KernelDb)),
217
- __param(1, Inject(AgentLookup))
246
+ __param(1, Inject(AgentLookup)),
247
+ __param(2, Inject(Credentials)),
248
+ __param(3, Inject(PluginIcons))
218
249
  ], AdminAgents);
219
250
  export { AdminAgents };
220
251
  function toRow(r, skillsOff) {
@@ -3,6 +3,8 @@ import type { KernelConfig } from "../config/schema.js";
3
3
  import { type LookupFn, NetDeniedError, type NetPolicy } from "../net/public-address.js";
4
4
  import { type OfficialNpmRevision, type OfficialPublisherProof } from "../packages/official-publisher.js";
5
5
  export declare function requireMarketplacePublisher(config: Pick<KernelConfig, "packages" | "marketplaces" | "net">, revision: OfficialNpmRevision, signal?: AbortSignal): Promise<OfficialPublisherProof>;
6
+ /** Whether a {@link requireMarketplacePublisher} failure was a network or registry hiccup. */
7
+ export declare function publisherCheckTransient(error: unknown): boolean;
6
8
  /**
7
9
  * Fetching a marketplace manifest `marketplace.json` (C26, spec §5.2) and a marketplace's archive
8
10
  * sources. The URLs come from a super admin or the config, but responses are always hostile
@@ -4,7 +4,7 @@ import { ApiError } from "../errors.js";
4
4
  import { NetDeniedError } from "../net/public-address.js";
5
5
  import { describeFetchError, safeFetch } from "../net/safe-fetch.js";
6
6
  import { isLoopback, readCapped } from "../packages/npm.js";
7
- import { fetchOfficialPublisher, } from "../packages/official-publisher.js";
7
+ import { fetchOfficialPublisher, OfficialPublisherError, } from "../packages/official-publisher.js";
8
8
  export async function requireMarketplacePublisher(config, revision, signal) {
9
9
  try {
10
10
  return await fetchOfficialPublisher({
@@ -16,9 +16,14 @@ export async function requireMarketplacePublisher(config, revision, signal) {
16
16
  }
17
17
  catch (error) {
18
18
  const reason = error instanceof Error ? error.message : String(error);
19
- throw new ApiError("marketplace.publisher_unverified", `Cannot verify the official publisher for ${revision.name}@${revision.version}: ${reason}`);
19
+ throw new ApiError("marketplace.publisher_unverified", `Cannot verify the official publisher for ${revision.name}@${revision.version}: ${reason}`, undefined, { cause: error });
20
20
  }
21
21
  }
22
+ /** Whether a {@link requireMarketplacePublisher} failure was a network or registry hiccup. */
23
+ export function publisherCheckTransient(error) {
24
+ const cause = error instanceof Error ? error.cause : undefined;
25
+ return cause instanceof OfficialPublisherError && cause.transient;
26
+ }
22
27
  /**
23
28
  * The API error for a refused download, or undefined when the refusal is not one of the two
24
29
  * marketplace codes (an invalid URL or a DNS failure is an ordinary fetch failure).
@@ -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;