@capybara-hq/kernel 0.1.0-rc.143 → 0.1.0-rc.144
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.
- package/dist/admin/admin-agents.controller.d.ts +3 -5
- package/dist/admin/admin-agents.controller.js +1 -1
- package/dist/admin/admin-connectors.controller.d.ts +3 -5
- package/dist/admin/admin-connectors.controller.js +1 -1
- package/dist/admin/admin-items.schemas.d.ts +6 -6
- package/dist/admin/admin-items.schemas.js +5 -9
- package/dist/admin/admin.controller.d.ts +18 -12
- package/dist/admin/admin.controller.js +29 -15
- package/dist/admin/admin.schemas.d.ts +12 -3
- package/dist/admin/admin.schemas.js +17 -6
- package/dist/agents/admin-agents.d.ts +10 -8
- package/dist/agents/admin-agents.js +13 -9
- package/dist/automations/automations.controller.d.ts +9 -5
- package/dist/automations/automations.controller.js +21 -4
- package/dist/automations/automations.schemas.d.ts +19 -0
- package/dist/automations/automations.schemas.js +9 -0
- package/dist/automations/automations.service.d.ts +25 -8
- package/dist/automations/automations.service.js +40 -34
- package/dist/automations/store.d.ts +17 -0
- package/dist/automations/store.js +35 -0
- package/dist/catalog/admin-catalog.controller.d.ts +64 -2
- package/dist/catalog/admin-catalog.controller.js +17 -0
- package/dist/catalog/cli.js +2 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-package.js +2 -1
- package/dist/client/client-access.service.js +29 -1
- package/dist/config/schema.d.ts +9 -0
- package/dist/config/schema.js +26 -0
- package/dist/ctx/create-ctx.d.ts +2 -19
- package/dist/ctx/create-ctx.js +3 -93
- package/dist/ctx/durable-relay.d.ts +2 -5
- package/dist/ctx/durable-relay.js +56 -29
- package/dist/db/extension-handoff-schema.js +5 -0
- package/dist/db/kernel-schema.d.ts +74 -0
- package/dist/erasure/account-batches.js +2 -0
- package/dist/erasure/account-residual.js +1 -0
- package/dist/erasure/org-catalog.js +8 -3
- package/dist/erasure/org-rules.js +1 -0
- package/dist/evals/evals.schemas.d.ts +15 -5
- package/dist/evals/evals.schemas.js +17 -10
- package/dist/evals/runs.controller.d.ts +4 -12
- package/dist/evals/runs.controller.js +14 -11
- package/dist/evals/runs.service.d.ts +29 -25
- package/dist/evals/runs.service.js +73 -61
- package/dist/evals/trajectory.controller.d.ts +10 -6
- package/dist/evals/trajectory.controller.js +11 -4
- package/dist/evals/trajectory.service.d.ts +17 -9
- package/dist/evals/trajectory.service.js +52 -35
- package/dist/extensions/admin-ops.js +4 -3
- package/dist/extensions/blobs.d.ts +2 -0
- package/dist/extensions/blobs.js +11 -0
- package/dist/extensions/enabled.d.ts +5 -0
- package/dist/extensions/grant-epoch.d.ts +108 -0
- package/dist/extensions/grant-epoch.js +214 -0
- package/dist/extensions/host.d.ts +29 -9
- package/dist/extensions/host.js +148 -42
- package/dist/extensions/instance.d.ts +3 -3
- package/dist/extensions/instance.js +1 -1
- package/dist/extensions/isolated/authorization.d.ts +54 -2
- package/dist/extensions/isolated/authorization.js +148 -35
- package/dist/extensions/isolated/child-session.js +0 -1
- package/dist/extensions/isolated/revision.js +1 -1
- package/dist/extensions/package-digest.job.d.ts +34 -0
- package/dist/extensions/package-digest.job.js +121 -0
- package/dist/extensions/package.js +10 -6
- package/dist/extensions/permission-set.d.ts +14 -78
- package/dist/extensions/permission-set.js +17 -143
- package/dist/extensions/permission-view.d.ts +13 -1
- package/dist/extensions/permission-view.js +20 -0
- package/dist/extensions/registry.js +4 -1
- package/dist/extensions/resolve.d.ts +7 -8
- package/dist/extensions/resolve.js +7 -8
- package/dist/extensions/revision-approvals.d.ts +167 -0
- package/dist/extensions/revision-approvals.js +353 -0
- package/dist/extensions/revision-grants.d.ts +197 -0
- package/dist/extensions/revision-grants.js +584 -0
- package/dist/extensions/state.module.js +12 -1
- package/dist/identity/accounts.d.ts +10 -4
- package/dist/identity/accounts.js +18 -5
- package/dist/infra/database/extension-effect-key-lock.js +7 -0
- package/dist/infra/paging/paged-read.d.ts +34 -4
- package/dist/infra/paging/paged-read.js +38 -1
- package/dist/orgs/invitations.controller.d.ts +4 -7
- package/dist/orgs/invitations.controller.js +8 -5
- package/dist/orgs/invitations.service.d.ts +17 -3
- package/dist/orgs/invitations.service.js +35 -13
- package/dist/orgs/members.service.d.ts +35 -0
- package/dist/orgs/members.service.js +52 -3
- package/dist/orgs/orgs.controller.d.ts +11 -4
- package/dist/orgs/orgs.controller.js +25 -5
- package/dist/orgs/orgs.schemas.d.ts +14 -0
- package/dist/orgs/orgs.schemas.js +19 -2
- package/dist/orgs/orgs.service.d.ts +21 -1
- package/dist/orgs/orgs.service.js +40 -1
- package/dist/orgs/security-settings.service.d.ts +14 -6
- package/dist/orgs/security-settings.service.js +18 -13
- package/dist/orgs/settings.controller.d.ts +7 -4
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/accounts.ops.js +7 -16
- package/dist/platform/ops/admin-items.ops.js +7 -7
- package/dist/platform/ops/automations.ops.js +6 -4
- package/dist/platform/ops/evals.ops.js +30 -15
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +44 -27
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/step-log.d.ts +1 -1
- package/dist/runtime/step-log.js +5 -4
- package/dist/setup/kernel-checks.d.ts +3 -3
- package/dist/setup/kernel-checks.js +4 -4
- package/dist/setup/setup-check-registry.d.ts +16 -5
- package/dist/setup/setup-check-registry.js +11 -3
- package/dist/setup/setup-checks.service.d.ts +1 -2
- package/dist/setup/setup-checks.service.js +7 -6
- package/dist/tools/admin-connectors.d.ts +10 -8
- package/dist/tools/admin-connectors.js +12 -10
- package/dist/tools/builtins/automations.d.ts +1 -1
- package/dist/tools/builtins/automations.js +1 -1
- package/package.json +3 -3
- package/src/migrations/0234_extension_grant_epoch.sql +141 -0
- package/src/migrations/0235_extension_revision_grants.sql +166 -0
- package/src/migrations/0236_paged_table_idx.sql +33 -0
- package/src/migrations/0237_extension_handoff_health.sql +18 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import { resolve as resolvePath } from "node:path";
|
|
3
|
+
import { permissionKeys as catalogPermissionKeys, SETUP_CHECK_KEY_PREFIX, staticManifestOf, staticPermissionDeclarations, UI_VIEW_KEY_PREFIX, } from "@capybara-hq/plugin-sdk";
|
|
3
4
|
import { configFields } from "../config/fields.js";
|
|
4
5
|
import { pluginSchemaName } from "../ctx/create-ctx.js";
|
|
5
6
|
import { MIGRATION_FILE_RE } from "../db/migrator.js";
|
|
6
|
-
|
|
7
|
-
export const WARNINGS_KEY_PREFIX = "migration.warnings:";
|
|
7
|
+
export { AGENTS_KEY, CLIENT_KEY, CONVERSATIONS_KEY, DEVICE_ACCESS_KEY_PREFIX, DEVICE_HOST_KEY_PREFIX, DEVICE_LOOPBACK_PORTS_KEY, DEVICE_SITE_ACCESS_KEY, DIAL_IN_KEY_PREFIX, INBOX_KEY, PEOPLE_KEY, POLICY_HOOK_KEY_PREFIX, SETUP_CHECK_KEY_PREFIX, TRIGGERS_KEY_PREFIX, UI_COMPONENT_KEY_PREFIX, UI_VIEW_KEY_PREFIX, WARNINGS_KEY_PREFIX, } from "@capybara-hq/plugin-sdk";
|
|
8
8
|
const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
9
9
|
const sortedUnique = (xs) => [...new Set(xs ?? [])].sort(cmp);
|
|
10
10
|
const IDENT = '(?:"(?:[^"]|"")+"|[A-Za-z_][A-Za-z0-9_$]*)';
|
|
@@ -72,6 +72,7 @@ export async function computePermissionSet(manifest, pluginDir) {
|
|
|
72
72
|
},
|
|
73
73
|
tables,
|
|
74
74
|
permissions: manifest.permissions,
|
|
75
|
+
purposes: staticPermissionDeclarations(staticManifestOf(manifest)).purposes,
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
/**
|
|
@@ -80,6 +81,8 @@ export async function computePermissionSet(manifest, pluginDir) {
|
|
|
80
81
|
*/
|
|
81
82
|
export function buildPermissionSet(input) {
|
|
82
83
|
const p = input.permissions ?? {};
|
|
84
|
+
if (p.fullAccess !== undefined)
|
|
85
|
+
throw new Error(FULL_ACCESS_UNSUPPORTED);
|
|
83
86
|
const byPath = (a, b) => cmp(a.path, b.path);
|
|
84
87
|
return {
|
|
85
88
|
provides: sortedUnique(input.provides),
|
|
@@ -89,9 +92,15 @@ export function buildPermissionSet(input) {
|
|
|
89
92
|
deployment: [...input.config.deployment].sort(byPath),
|
|
90
93
|
},
|
|
91
94
|
tables: sortedUnique(input.tables),
|
|
95
|
+
...(input.purposes?.size && { purposes: Object.fromEntries(input.purposes) }),
|
|
92
96
|
permissions: {
|
|
93
97
|
secrets: p.secrets === true,
|
|
94
98
|
storage: p.storage === true,
|
|
99
|
+
...(p.kv && { kv: true }),
|
|
100
|
+
...(p.lock && { lock: true }),
|
|
101
|
+
...(p.bus && { bus: true }),
|
|
102
|
+
...(p.queue && { queue: true }),
|
|
103
|
+
...(p.outbox && { outbox: true }),
|
|
95
104
|
http: (p.http ?? [])
|
|
96
105
|
.map((r) => ({ method: r.method, path: r.path, access: r.access }))
|
|
97
106
|
.sort((a, b) => cmp(`${a.method} ${a.path}`, `${b.method} ${b.path}`)),
|
|
@@ -110,6 +119,8 @@ export function buildPermissionSet(input) {
|
|
|
110
119
|
views: sortedUnique(p.ui?.views),
|
|
111
120
|
embeds: sortedUnique(p.ui?.embeds),
|
|
112
121
|
components: sortedUnique(p.ui?.components),
|
|
122
|
+
...(p.ui?.queries?.length && { queries: sortedUnique(p.ui.queries) }),
|
|
123
|
+
...(p.ui?.actions?.length && { actions: sortedUnique(p.ui.actions) }),
|
|
113
124
|
},
|
|
114
125
|
// only when declared: sets (and snapshots) of plugins without setup checks stay as they were
|
|
115
126
|
...(p.setupChecks && p.setupChecks.length > 0
|
|
@@ -141,149 +152,12 @@ export function buildPermissionSet(input) {
|
|
|
141
152
|
...(input.warningsDigest ? { warningsDigest: input.warningsDigest } : {}),
|
|
142
153
|
};
|
|
143
154
|
}
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
* `permissions.http.<access>:<METHOD> <path>` (`permissions.http.public:POST /events`),
|
|
148
|
-
* `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud`,
|
|
149
|
-
* `permissions.dialin:capybara-device/6`, `permissions.deviceaccess:browser`,
|
|
150
|
-
* `permissions.deviceaccess.loopbackports`,
|
|
151
|
-
* `permissions.triggers:item.created`, `permissions.inbox`.
|
|
152
|
-
* Tolerates old snapshots missing fields (read as empty), so format changes never throw.
|
|
153
|
-
*/
|
|
155
|
+
/** Legacy approval cannot authorize a privileged execution realm. */
|
|
156
|
+
export const FULL_ACCESS_UNSUPPORTED = "permissions.fullAccess is not yet supported by extension approval";
|
|
157
|
+
/** Expand the kernel snapshot's declarations using the SDK's canonical catalog. */
|
|
154
158
|
export function permissionKeys(set) {
|
|
155
|
-
|
|
156
|
-
const p = (s.permissions ?? {});
|
|
157
|
-
const keys = [];
|
|
158
|
-
for (const r of s.provides ?? [])
|
|
159
|
-
keys.push(`provides:${r}`);
|
|
160
|
-
for (const r of s.requires ?? [])
|
|
161
|
-
keys.push(`requires:${r}`);
|
|
162
|
-
for (const r of s.optional ?? [])
|
|
163
|
-
keys.push(`optional:${r}`);
|
|
164
|
-
for (const f of s.config?.deployment ?? []) {
|
|
165
|
-
keys.push(`config.deployment${f.secret ? ".secret" : ""}:${f.path || "<root>"}`);
|
|
166
|
-
}
|
|
167
|
-
for (const t of s.tables ?? [])
|
|
168
|
-
keys.push(`table:${t}`);
|
|
169
|
-
if (p.secrets)
|
|
170
|
-
keys.push("permissions.secrets");
|
|
171
|
-
if (p.storage)
|
|
172
|
-
keys.push("permissions.storage");
|
|
173
|
-
for (const r of p.http ?? []) {
|
|
174
|
-
// a snapshot from before route access has no `access`: its key matches no current key, so the
|
|
175
|
-
// extension waits for re-approval
|
|
176
|
-
keys.push(`permissions.http${r.access ? `.${r.access}` : ""}:${r.method} ${r.path}`);
|
|
177
|
-
}
|
|
178
|
-
for (const t of p.tools ?? [])
|
|
179
|
-
keys.push(`permissions.tools:${t}`);
|
|
180
|
-
for (const h of p.hooks ?? [])
|
|
181
|
-
keys.push(`permissions.hooks:${h}`);
|
|
182
|
-
for (const h of p.policyHooks ?? [])
|
|
183
|
-
keys.push(`${POLICY_HOOK_KEY_PREFIX}${h}`);
|
|
184
|
-
for (const m of p.models ?? [])
|
|
185
|
-
keys.push(`permissions.models:${m.purpose} (${m.kind})`);
|
|
186
|
-
for (const d of p.network ?? [])
|
|
187
|
-
keys.push(`permissions.network:${d}`);
|
|
188
|
-
if (p.client)
|
|
189
|
-
keys.push(CLIENT_KEY);
|
|
190
|
-
for (const v of p.ui?.views ?? [])
|
|
191
|
-
keys.push(`${UI_VIEW_KEY_PREFIX}${v}`);
|
|
192
|
-
for (const e of p.ui?.embeds ?? [])
|
|
193
|
-
keys.push(`ui.embed:${e}`);
|
|
194
|
-
for (const c of p.ui?.components ?? [])
|
|
195
|
-
keys.push(`${UI_COMPONENT_KEY_PREFIX}${c}`);
|
|
196
|
-
for (const c of p.setupChecks ?? [])
|
|
197
|
-
keys.push(`${SETUP_CHECK_KEY_PREFIX}${c}`);
|
|
198
|
-
if (p.dialIn?.protocol)
|
|
199
|
-
keys.push(`${DIAL_IN_KEY_PREFIX}${p.dialIn.protocol}`);
|
|
200
|
-
for (const svc of p.deviceAccess?.services ?? [])
|
|
201
|
-
keys.push(`${DEVICE_ACCESS_KEY_PREFIX}${svc}`);
|
|
202
|
-
if (p.deviceAccess?.loopbackPorts === true)
|
|
203
|
-
keys.push(DEVICE_LOOPBACK_PORTS_KEY);
|
|
204
|
-
if (p.deviceAccess?.siteAccess === true)
|
|
205
|
-
keys.push(DEVICE_SITE_ACCESS_KEY);
|
|
206
|
-
for (const svc of p.deviceAccess?.hostServices ?? [])
|
|
207
|
-
keys.push(`${DEVICE_HOST_KEY_PREFIX}${svc}`);
|
|
208
|
-
for (const t of p.triggers?.emit ?? [])
|
|
209
|
-
keys.push(`${TRIGGERS_KEY_PREFIX}${t}`);
|
|
210
|
-
if (p.inbox === true)
|
|
211
|
-
keys.push(INBOX_KEY);
|
|
212
|
-
if (p.agents?.read === true)
|
|
213
|
-
keys.push(AGENTS_KEY);
|
|
214
|
-
if (p.conversations?.subjects === true)
|
|
215
|
-
keys.push(CONVERSATIONS_KEY);
|
|
216
|
-
if (p.people?.read === true)
|
|
217
|
-
keys.push(PEOPLE_KEY);
|
|
218
|
-
if (s.warningsDigest)
|
|
219
|
-
keys.push(`${WARNINGS_KEY_PREFIX}${s.warningsDigest}`);
|
|
220
|
-
return sortedUnique(keys);
|
|
159
|
+
return catalogPermissionKeys(set);
|
|
221
160
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Key prefix of a policy hook mount (manifest `permissions.policyHooks`): needs approval like any hook.
|
|
224
|
-
* Lower-case letters and dots only, as catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
225
|
-
*/
|
|
226
|
-
export const POLICY_HOOK_KEY_PREFIX = "permissions.hooks.policy:";
|
|
227
|
-
/**
|
|
228
|
-
* Permission key of client code (`permissions.client`): sensitive and blocking. The key, not the
|
|
229
|
-
* bundle's bytes, is reviewed: an upgrade that only changes the bundle adds no key.
|
|
230
|
-
*/
|
|
231
|
-
export const CLIENT_KEY = "permissions.client";
|
|
232
|
-
/**
|
|
233
|
-
* Key prefix of a dial-in protocol (`permissions.dialIn`): blocking. Lower-case letters and dots
|
|
234
|
-
* before the colon, as catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
235
|
-
*/
|
|
236
|
-
export const DIAL_IN_KEY_PREFIX = "permissions.dialin:";
|
|
237
|
-
/**
|
|
238
|
-
* Key prefix of a device service (`permissions.deviceAccess.services`): sensitive and blocking, so
|
|
239
|
-
* an upgrade adding a service waits for approval. Lower-case letters and dots before the colon, as
|
|
240
|
-
* catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
241
|
-
*/
|
|
242
|
-
export const DEVICE_ACCESS_KEY_PREFIX = "permissions.deviceaccess:";
|
|
243
|
-
/**
|
|
244
|
-
* Permission key of loopback port grants (`permissions.deviceAccess.loopbackPorts: true`, browser
|
|
245
|
-
* loopback port grants design): sensitive and blocking, so an approved extension never gains it on
|
|
246
|
-
* upgrade without approval again. Recorded only when declared.
|
|
247
|
-
*/
|
|
248
|
-
export const DEVICE_LOOPBACK_PORTS_KEY = "permissions.deviceaccess.loopbackports";
|
|
249
|
-
/**
|
|
250
|
-
* Key prefix of a host service (`permissions.deviceAccess.hostServices`): the service runs on the
|
|
251
|
-
* owner's machine outside the sandbox; sensitive and blocking like any device service key.
|
|
252
|
-
*/
|
|
253
|
-
export const DEVICE_HOST_KEY_PREFIX = "permissions.deviceaccess.host:";
|
|
254
|
-
/** Blocking permission for profile decisions on non-loopback site actions. */
|
|
255
|
-
export const DEVICE_SITE_ACCESS_KEY = "permissions.deviceaccess.siteaccess";
|
|
256
|
-
/**
|
|
257
|
-
* Key prefix of an event type the extension emits (`permissions.triggers.emit`): blocking, not
|
|
258
|
-
* sensitive (an event only reaches automations an org built on it, collaboration spec §4.2).
|
|
259
|
-
* Lower-case letters and dots before the colon, as catalog permission keys require
|
|
260
|
-
* (`PERMISSION_KEY_RE`).
|
|
261
|
-
*/
|
|
262
|
-
export const TRIGGERS_KEY_PREFIX = "permissions.triggers:";
|
|
263
|
-
/**
|
|
264
|
-
* Permission key of personal inbox items (`permissions.inbox`): blocking, not sensitive (an item
|
|
265
|
-
* reaches only members of orgs that enabled the extension, links only to its own pages, and its
|
|
266
|
-
* buttons call its UI actions as the person who clicks).
|
|
267
|
-
*/
|
|
268
|
-
export const INBOX_KEY = "permissions.inbox";
|
|
269
|
-
/**
|
|
270
|
-
* Permission keys of the read-only org facts: blocking, not sensitive (`ctx.agents` lists the
|
|
271
|
-
* agents a member may use, `ctx.conversations` the metadata of the extension's own subjects'
|
|
272
|
-
* conversations, `ctx.people` the members' names and avatars: no content, no email).
|
|
273
|
-
*/
|
|
274
|
-
export const AGENTS_KEY = "permissions.agents";
|
|
275
|
-
export const CONVERSATIONS_KEY = "permissions.conversations";
|
|
276
|
-
export const PEOPLE_KEY = "permissions.people";
|
|
277
|
-
/** Key prefix of a client component (`ui.component:<id>`): sensitive and blocking. */
|
|
278
|
-
export const UI_COMPONENT_KEY_PREFIX = "ui.component:";
|
|
279
|
-
/** 渲染 schema 视图的权限键前缀:记入快照但不卡加载(见 {@link blockingKeys})。 */
|
|
280
|
-
export const UI_VIEW_KEY_PREFIX = "ui.view:";
|
|
281
|
-
/**
|
|
282
|
-
* Key prefix of a setup check id (`permissions.setupChecks`): recorded but never blocking
|
|
283
|
-
* ({@link blockingKeys}). Lower-case letters and dots before the colon, as catalog permission keys
|
|
284
|
-
* require (`PERMISSION_KEY_RE` of the marketplace format).
|
|
285
|
-
*/
|
|
286
|
-
export const SETUP_CHECK_KEY_PREFIX = "setup.check:";
|
|
287
161
|
/**
|
|
288
162
|
* 新增项里需要批准(卡加载)的部分:除 `ui.view:*` 与 `setup.check:*` 之外的全部。视图只是把插件已有的数据交给
|
|
289
163
|
* 内核组件来画,不给插件新能力(spec §4.1);setup checks get only data the extension already gets
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedName, type UiDropReason } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { PluginScope } from "../catalog/scope.js";
|
|
3
3
|
import type { ReportBodyInput } from "../client/client.schemas.js";
|
|
4
4
|
import { type PermissionSet } from "./permission-set.js";
|
|
5
5
|
import type { ExtensionSource } from "./sources.js";
|
|
6
|
+
/** Review data contains plain purpose text. Renderers escape it as text on output. */
|
|
7
|
+
export declare function reviewPermissionRows(set: PermissionSet): {
|
|
8
|
+
rows: {
|
|
9
|
+
key: string;
|
|
10
|
+
family: "config.deployment" | "config.deployment.secret" | "execution.full-access" | "execution.provider.unsupported" | "host.no-isolation" | "migration.warnings" | "optional" | "optional.custodian" | "permissions.agents" | "permissions.bus" | "permissions.client" | "permissions.conversations" | "permissions.deviceaccess" | "permissions.deviceaccess.host" | "permissions.deviceaccess.loopbackports" | "permissions.deviceaccess.siteaccess" | "permissions.dialin" | "permissions.fullaccess.rawegress" | "permissions.hooks.observe" | "permissions.hooks.policy" | "permissions.hooks.sensitive" | "permissions.http" | "permissions.inbox" | "permissions.kv" | "permissions.lock" | "permissions.models" | "permissions.network" | "permissions.outbox" | "permissions.people" | "permissions.queue" | "permissions.secrets" | "permissions.storage" | "permissions.tools" | "permissions.triggers" | "provides" | "provides.standard" | "requires" | "requires.custodian" | "setup.check" | "table" | "ui.action" | "ui.component" | "ui.embed" | "ui.query" | "ui.view";
|
|
11
|
+
risk: "custodian" | "fullAccess" | "informational" | "sensitive" | "standard";
|
|
12
|
+
reason: "Accepts connections from devices that use this protocol." | "Calls the model mapped to this declared purpose." | "Can deny the protected action at this mount." | "Can request a grant for a device loopback port." | "Can request approved actions on websites from the person's device." | "Contains migration statements that require review." | "Coordinates work using locks in the extension namespace." | "Creates a table in the extension database schema." | "Depends on a provider that handles a protected resource." | "Emits durable events of this type." | "Handles this named action for its extension UI." | "Handles this named query for its extension UI." | "Implements a kernel capability and sees the resource it serves." | "Implements this kernel capability." | "Makes network requests outside the kernel egress broker." | "Observes bounded metadata at this mount." | "Observes model or tool data at this mount." | "Orders startup after this extension point when present." | "Posts to the inbox of members of enabled orgs." | "Publishes and receives events in the extension namespace." | "Reads and writes keys in the extension namespace." | "Reads metadata for conversations about its own subjects." | "Reads or stores secrets in its approved namespace." | "Reads or writes objects in its scoped storage prefix." | "Reads the names and avatars of org members." | "Reads which agents a member can use." | "Receives requests and data for this route and audience." | "Receives this field from effective configuration." | "Renders this named component in the app." | "Renders this named view through the kernel." | "Requires this extension point at startup." | "Runs this named tool with its input and scoped call context." | "Runs this read-only setup check." | "Runs this service outside the device sandbox." | "Runs with the privileges of the approved execution realm." | "Runs without a host isolation supervisor." | "Schedules work in the extension namespace." | "Sends requests and data to this destination." | "Serves an embedded page for this view." | "Stages durable effects in the extension namespace." | "Supplies client code for the app." | "This provider contract does not yet have an isolated execution form." | "Uses this confidential configuration field." | "Uses this service on a person's device.";
|
|
13
|
+
purpose: import("@capybara-hq/plugin-sdk").PermissionPurpose | undefined;
|
|
14
|
+
}[];
|
|
15
|
+
errors: string[];
|
|
16
|
+
warnings: string[];
|
|
17
|
+
};
|
|
6
18
|
/**
|
|
7
19
|
* Review digest: the first 16 hex digits of `sha256(permissionKeys(set).join("\n"))`; with migration
|
|
8
20
|
* warnings their digest (kind, file, line and statement) is folded in, without warnings it equals the
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { lintPermissionPurposes, permissionCatalogMatches, } from "@capybara-hq/plugin-sdk";
|
|
2
3
|
import { pluginSchemaName } from "../ctx/create-ctx.js";
|
|
3
4
|
import { EXTENSION_RLS_PREDICATE } from "../db/extension-rls-predicate.js";
|
|
4
5
|
import { isDestructiveSql, splitSqlStatements } from "../db/sql-statements.js";
|
|
5
6
|
import { AGENTS_KEY, CLIENT_KEY, CONVERSATIONS_KEY, DEVICE_ACCESS_KEY_PREFIX, DEVICE_HOST_KEY_PREFIX, DEVICE_LOOPBACK_PORTS_KEY, DEVICE_SITE_ACCESS_KEY, DIAL_IN_KEY_PREFIX, INBOX_KEY, PEOPLE_KEY, permissionKeys, TRIGGERS_KEY_PREFIX, UI_COMPONENT_KEY_PREFIX, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
|
|
7
|
+
/** Review data contains plain purpose text. Renderers escape it as text on output. */
|
|
8
|
+
export function reviewPermissionRows(set) {
|
|
9
|
+
const { purposes, errors, warnings } = lintPermissionPurposes(set, new Map(Object.entries(set.purposes ?? {})));
|
|
10
|
+
const rows = permissionKeys(set).flatMap((key) => {
|
|
11
|
+
const [entry, ...otherMatches] = permissionCatalogMatches(key);
|
|
12
|
+
if (!entry || otherMatches.length > 0)
|
|
13
|
+
return [];
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
key,
|
|
17
|
+
family: entry.family,
|
|
18
|
+
risk: entry.risk,
|
|
19
|
+
reason: entry.reason,
|
|
20
|
+
purpose: purposes.get(key),
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
});
|
|
24
|
+
return { rows, errors, warnings };
|
|
25
|
+
}
|
|
6
26
|
/**
|
|
7
27
|
* Review digest: the first 16 hex digits of `sha256(permissionKeys(set).join("\n"))`; with migration
|
|
8
28
|
* warnings their digest (kind, file, line and statement) is folded in, without warnings it equals the
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
|
|
7
|
+
import { EXTENSION_POINTS, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
|
|
8
8
|
import { Injectable, Module } from "@nestjs/common";
|
|
9
9
|
import { trackCalls } from "./inflight.js";
|
|
10
10
|
/** 内核消费的提供方能力:调用计入提供方实例的在途计数(撤销 / 升级时排空,C17)。 */
|
|
@@ -80,6 +80,9 @@ let ExtensionRegistry = class ExtensionRegistry {
|
|
|
80
80
|
* 实时取自注册表:调用方不要缓存实现对象(插件撤销 / 升级后旧实现不再有效)。
|
|
81
81
|
*/
|
|
82
82
|
list(extensionPointName) {
|
|
83
|
+
if (!Object.hasOwn(EXTENSION_POINTS, extensionPointName)) {
|
|
84
|
+
throw new Error(`unknown extension point: ${extensionPointName}`);
|
|
85
|
+
}
|
|
83
86
|
const out = [];
|
|
84
87
|
const tracked = TRACKED_EXTENSION_POINTS[extensionPointName];
|
|
85
88
|
for (const i of this.instances.values()) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExtensionManifest } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type ExtensionManifest, type PermissionDeclaration } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
/**
|
|
3
3
|
* Code of the {@link ExtensionResolveError} for a single-provider extension point that more than
|
|
4
4
|
* one extension provides: nothing is missing, the extensions conflict (replica reason `conflict`).
|
|
@@ -20,8 +20,7 @@ export declare function parseProviderConflict(detail: string | null): {
|
|
|
20
20
|
unprovided?: true;
|
|
21
21
|
} | null;
|
|
22
22
|
/**
|
|
23
|
-
* The single-provider extension points
|
|
24
|
-
* `config-source`; `EXTENSION_POINT_CARDINALITY`) among `provides`, sorted (the lock order).
|
|
23
|
+
* The single-provider extension points among `provides`, sorted in lock order.
|
|
25
24
|
*/
|
|
26
25
|
export declare function singlePointsOf(provides: readonly string[]): string[];
|
|
27
26
|
/**
|
|
@@ -35,7 +34,7 @@ export declare function electSingleProviders(desired: readonly {
|
|
|
35
34
|
name: string;
|
|
36
35
|
section: {
|
|
37
36
|
manifest: {
|
|
38
|
-
provides: readonly string[];
|
|
37
|
+
provides: readonly PermissionDeclaration<string>[];
|
|
39
38
|
};
|
|
40
39
|
};
|
|
41
40
|
}[]): {
|
|
@@ -54,9 +53,9 @@ export declare class ExtensionResolveError extends Error {
|
|
|
54
53
|
code?: string | undefined);
|
|
55
54
|
}
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
56
|
+
* Validate SDK ranges, dependencies, single-provider cardinality and cycles, then preserve input
|
|
57
|
+
* order within each dependency level. An absent required provider is an error. An optional provider
|
|
58
|
+
* participates in ordering and cycle detection when present. Storage permission implies ordering
|
|
59
|
+
* after the object-store provider. The approval gate marks missing storage providers pending.
|
|
61
60
|
*/
|
|
62
61
|
export declare function resolveExtensions(manifests: ExtensionManifest[], sdkVersion: string): ExtensionManifest[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EXTENSION_POINT_CARDINALITY, EXTENSION_POINTS, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { EXTENSION_POINT_CARDINALITY, EXTENSION_POINTS, extensionPointRefs, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import semver from "semver";
|
|
3
3
|
/**
|
|
4
4
|
* Code of the {@link ExtensionResolveError} for a single-provider extension point that more than
|
|
@@ -32,8 +32,7 @@ export function parseProviderConflict(detail) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* The single-provider extension points
|
|
36
|
-
* `config-source`; `EXTENSION_POINT_CARDINALITY`) among `provides`, sorted (the lock order).
|
|
35
|
+
* The single-provider extension points among `provides`, sorted in lock order.
|
|
37
36
|
*/
|
|
38
37
|
export function singlePointsOf(provides) {
|
|
39
38
|
return [
|
|
@@ -58,7 +57,7 @@ export function electSingleProviders(desired) {
|
|
|
58
57
|
const owners = new Map();
|
|
59
58
|
const losers = new Map();
|
|
60
59
|
for (const d of desired) {
|
|
61
|
-
const points = singlePointsOf(d.section.manifest.provides);
|
|
60
|
+
const points = singlePointsOf(extensionPointRefs(d.section.manifest.provides));
|
|
62
61
|
const lost = points.find((p) => owners.has(p));
|
|
63
62
|
if (lost !== undefined) {
|
|
64
63
|
losers.set(d.name, { extensionPoint: lost, winner: owners.get(lost) });
|
|
@@ -81,10 +80,10 @@ export class ExtensionResolveError extends Error {
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
83
|
+
* Validate SDK ranges, dependencies, single-provider cardinality and cycles, then preserve input
|
|
84
|
+
* order within each dependency level. An absent required provider is an error. An optional provider
|
|
85
|
+
* participates in ordering and cycle detection when present. Storage permission implies ordering
|
|
86
|
+
* after the object-store provider. The approval gate marks missing storage providers pending.
|
|
88
87
|
*/
|
|
89
88
|
export function resolveExtensions(manifests, sdkVersion) {
|
|
90
89
|
const seen = new Set();
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
2
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
|
+
import { ExtensionApprovals } from "./approvals.js";
|
|
5
|
+
import { ExtensionBlobs } from "./blobs.js";
|
|
6
|
+
import { type PermissionSet } from "./permission-set.js";
|
|
7
|
+
import { ExtensionRevisionGrants, type NewRevisionGrant, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
|
|
8
|
+
/**
|
|
9
|
+
* Revision approvals in shadow mode (extension permission model plan task 1.2b; the rollout fence
|
|
10
|
+
* "shadow mode until 1.5a"). Every installed revision is resolved against its own revision grant,
|
|
11
|
+
* never against the grant of an older or newer version (no `isOlder`): a rollback rechecks the
|
|
12
|
+
* selected revision's own grant. The result sits next to the legacy snapshot decision, which keeps
|
|
13
|
+
* governing admission: nothing here refuses a start, load or call.
|
|
14
|
+
*
|
|
15
|
+
* No grant is minted from a legacy snapshot approval: that consent never showed purposes, realms or
|
|
16
|
+
* the full-access warning. First grants come from the review (plan task 1.3a) and the bootstrap
|
|
17
|
+
* approval (1.3c); until then every revision resolves to `missing_grant`.
|
|
18
|
+
*/
|
|
19
|
+
/** How the enforcing path (plan task 1.5a) would treat one installed revision. */
|
|
20
|
+
export type ShadowGrantStatus =
|
|
21
|
+
/** Its own live grant covers every current key. */
|
|
22
|
+
"granted"
|
|
23
|
+
/** Its own live grant does not serve some current keys; the rest would serve. */
|
|
24
|
+
| "partially_revoked"
|
|
25
|
+
/** No live grant of its own; it waits for review. */
|
|
26
|
+
| "missing_grant"
|
|
27
|
+
/** No live grant, and the manifest lacks bilingual purposes: Republish with purposes. */
|
|
28
|
+
| "missing_purposes"
|
|
29
|
+
/** The package sha512 is not recorded yet (the backfill job fills it); no grant can match. */
|
|
30
|
+
| "unknown_digest"
|
|
31
|
+
/** The stored package could not be read (storage unavailable, too large, refused). */
|
|
32
|
+
| "unreadable";
|
|
33
|
+
/** What the legacy snapshot path, which governs admission until 1.5a, decides. */
|
|
34
|
+
export type LegacyDecision = "approved" | "pending";
|
|
35
|
+
export interface ShadowRevisionDecision {
|
|
36
|
+
revision: {
|
|
37
|
+
plugin: string;
|
|
38
|
+
version: string;
|
|
39
|
+
sha512: string | null;
|
|
40
|
+
};
|
|
41
|
+
status: ShadowGrantStatus;
|
|
42
|
+
/** The generation of the live grant it resolved to. */
|
|
43
|
+
generation?: number;
|
|
44
|
+
/** Current keys its grant revoked or retired. */
|
|
45
|
+
refusedKeys: string[];
|
|
46
|
+
/** Current keys its grant never had (a key set that changed since the review). */
|
|
47
|
+
ungrantedKeys: string[];
|
|
48
|
+
/** Keys without a bilingual purpose. */
|
|
49
|
+
missingPurposes: string[];
|
|
50
|
+
/** Why the approved revision's grant does not carry over as continuity, when there is one. */
|
|
51
|
+
continuity?: string;
|
|
52
|
+
/** A required bootstrap install (the start gate). */
|
|
53
|
+
required: boolean;
|
|
54
|
+
/** Whether the enforcing path would register and serve it ("register only after the grant"). */
|
|
55
|
+
wouldServe: boolean;
|
|
56
|
+
/** The legacy snapshot decision, which governs today. */
|
|
57
|
+
legacy: LegacyDecision;
|
|
58
|
+
/** The legacy and the enforcing decision differ: what the cutover would change. */
|
|
59
|
+
diverges: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface ShadowStartGate {
|
|
62
|
+
/** Required installs the enforcing start gate would refuse. */
|
|
63
|
+
missingRequired: ShadowRevisionDecision[];
|
|
64
|
+
/** Every other install that would not serve (they would wait as pending). */
|
|
65
|
+
pending: ShadowRevisionDecision[];
|
|
66
|
+
/** Installs whose legacy and enforcing decisions differ: what the cutover would change. */
|
|
67
|
+
diverging: ShadowRevisionDecision[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The kernel-written purpose of a migration warnings digest key. The key carries the digest, so a
|
|
71
|
+
* revision whose risky migration statements changed has a key its predecessor's grant lacks, and
|
|
72
|
+
* continuity refuses it: the change goes to review.
|
|
73
|
+
*/
|
|
74
|
+
export declare function warningsPurpose(key: string): PurposeRow;
|
|
75
|
+
/**
|
|
76
|
+
* The reviewed purpose rows of a permission set, and the keys that lack one. A migration warnings
|
|
77
|
+
* digest key gets the kernel-written row of {@link warningsPurpose}: authors cannot write one, and
|
|
78
|
+
* the grant must still bind the digest.
|
|
79
|
+
*/
|
|
80
|
+
export declare function purposeRowsOf(set: PermissionSet): {
|
|
81
|
+
rows: PurposeRow[];
|
|
82
|
+
missing: string[];
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The legacy decision for a revision's set against its snapshot, by `planApprovals`' approval rule:
|
|
86
|
+
* no snapshot or a new blocking key waits, unless `extensionPermissions.autoApprove` is on. Its
|
|
87
|
+
* dependency rule (an install whose required providers are all pending waits too) is not mirrored:
|
|
88
|
+
* the shadow report compares approval, not load order.
|
|
89
|
+
*/
|
|
90
|
+
export declare function legacyDecision(set: PermissionSet, snapshot: {
|
|
91
|
+
permissions: PermissionSet;
|
|
92
|
+
} | undefined, autoApprove?: boolean): LegacyDecision;
|
|
93
|
+
/**
|
|
94
|
+
* The shadow decision for one installed revision: resolved against its own live grant. `approved`
|
|
95
|
+
* is the live grant of the install's approved revision when that is another revision; it only
|
|
96
|
+
* explains whether continuity could carry over (the publisher evidence is not known here, so it
|
|
97
|
+
* never grants by itself).
|
|
98
|
+
*/
|
|
99
|
+
export declare function resolveRevisionGrant(input: {
|
|
100
|
+
revision: {
|
|
101
|
+
plugin: string;
|
|
102
|
+
version: string;
|
|
103
|
+
sha512: string | null;
|
|
104
|
+
};
|
|
105
|
+
set: PermissionSet;
|
|
106
|
+
required: boolean;
|
|
107
|
+
own: RevisionGrant | undefined;
|
|
108
|
+
approved: RevisionGrant | undefined;
|
|
109
|
+
legacy: LegacyDecision;
|
|
110
|
+
}): ShadowRevisionDecision;
|
|
111
|
+
/** What a reviewed promotion carries besides the revision: its verified publisher evidence. */
|
|
112
|
+
export interface PromotionEvidence {
|
|
113
|
+
publisher: NewRevisionGrant["publisher"];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* An upgrade may continue the approved revision's grant; a rollback never does: it is served
|
|
117
|
+
* only under the selected revision's own grant.
|
|
118
|
+
*/
|
|
119
|
+
export type PromotionKind = "upgrade" | "rollback";
|
|
120
|
+
export type PromotionOutcome = {
|
|
121
|
+
status: "promoted";
|
|
122
|
+
grant: RevisionGrant;
|
|
123
|
+
continued: boolean;
|
|
124
|
+
} | {
|
|
125
|
+
status: "pending";
|
|
126
|
+
reason: string;
|
|
127
|
+
};
|
|
128
|
+
/** The installed revisions' shadow decisions, and promotion with continuity. */
|
|
129
|
+
export declare class ExtensionRevisionApprovals {
|
|
130
|
+
private readonly kdb;
|
|
131
|
+
readonly txHost: TransactionHost;
|
|
132
|
+
private readonly grants;
|
|
133
|
+
private readonly approvals;
|
|
134
|
+
private readonly blobs;
|
|
135
|
+
private readonly config;
|
|
136
|
+
/** Permission sets by package sha256: content-addressed, so a cached set never goes stale. */
|
|
137
|
+
private readonly sets;
|
|
138
|
+
constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionApprovals, "all">, blobs: Pick<ExtensionBlobs, "get">, config: KernelConfigService);
|
|
139
|
+
/**
|
|
140
|
+
* The shadow decision of every install record. A package that cannot be read is reported as
|
|
141
|
+
* `unreadable` and never hides the others.
|
|
142
|
+
*/
|
|
143
|
+
decisions(): Promise<ShadowRevisionDecision[]>;
|
|
144
|
+
/** The facts the enforcing start gate would act on; computed and reported, never refused. */
|
|
145
|
+
startGate(): Promise<ShadowStartGate>;
|
|
146
|
+
/**
|
|
147
|
+
* Makes a revision the approved one of its install. A revision with its own live grant is
|
|
148
|
+
* promoted under it (an upgrade or a rollback). An upgrade without one continues the install's
|
|
149
|
+
* approved revision when that has a live grant and the candidate is a continuation of it (the
|
|
150
|
+
* store's rules): the continuity grant is recorded in the same transaction before the promotion.
|
|
151
|
+
* Anything else leaves the revision as the install's candidate, pending review, with the reason;
|
|
152
|
+
* it never throws for a refusal. A continuation carries no full-access realm (narrower, so safe):
|
|
153
|
+
* realms and the `extension.full_access_continued` audit come with plan tasks 1.2e and 1.3a.
|
|
154
|
+
*
|
|
155
|
+
* The package is read before the transaction: no object storage call holds a connection.
|
|
156
|
+
*/
|
|
157
|
+
promote(candidate: RevisionIdentity, evidence: PromotionEvidence, kind?: PromotionKind): Promise<PromotionOutcome>;
|
|
158
|
+
private promoteIn;
|
|
159
|
+
/** The stored package of a revision, or undefined while its sha512 is not recorded. */
|
|
160
|
+
private sha256Of;
|
|
161
|
+
private setOf;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The review hash of a continuity grant: the kernel reviewed it against its source, so the hash
|
|
165
|
+
* binds the candidate, its purpose rows and the exact source generation.
|
|
166
|
+
*/
|
|
167
|
+
export declare function continuityReviewHash(source: RevisionGrant, candidate: RevisionIdentity, rows: readonly PurposeRow[]): string;
|