@capybara-hq/kernel 0.1.0-rc.143 → 0.1.0-rc.145
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 +30 -11
- package/dist/agents/admin-agents.js +51 -16
- 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/marketplace-fetch.d.ts +2 -0
- package/dist/catalog/marketplace-fetch.js +7 -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/errors.d.ts +1 -1
- package/dist/errors.js +2 -2
- 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 +30 -10
- package/dist/extensions/host.js +162 -43
- 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/isolated/tier.d.ts +14 -0
- package/dist/extensions/isolated/tier.js +27 -0
- 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/publisher-proof.job.d.ts +39 -0
- package/dist/extensions/publisher-proof.job.js +160 -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/packages/official-publisher.d.ts +5 -0
- package/dist/packages/official-publisher.js +24 -3
- package/dist/packages/provenance.d.ts +6 -0
- package/dist/packages/provenance.js +26 -9
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/accounts.ops.js +7 -16
- package/dist/platform/ops/admin-items.ops.js +8 -8
- 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 +6 -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,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ExtensionManifest, type ExtensionPermissions, type HttpAccess, type PermissionPurpose } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
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";
|
|
2
3
|
/** 一个配置字段:点路径(根即叶子时为空串)与是否密钥。 */
|
|
3
4
|
export interface PermissionConfigField {
|
|
4
5
|
path: string;
|
|
@@ -18,9 +19,15 @@ export interface PermissionSet {
|
|
|
18
19
|
};
|
|
19
20
|
/** 插件迁移里 `CREATE TABLE` 的表名(插件自己 schema 下的不带前缀)。 */
|
|
20
21
|
tables: string[];
|
|
22
|
+
purposes?: Record<string, PermissionPurpose>;
|
|
21
23
|
permissions: {
|
|
22
24
|
secrets: boolean;
|
|
23
25
|
storage: boolean;
|
|
26
|
+
kv?: true;
|
|
27
|
+
lock?: true;
|
|
28
|
+
bus?: true;
|
|
29
|
+
queue?: true;
|
|
30
|
+
outbox?: true;
|
|
24
31
|
http: {
|
|
25
32
|
method: string;
|
|
26
33
|
path: string;
|
|
@@ -55,6 +62,8 @@ export interface PermissionSet {
|
|
|
55
62
|
views: string[];
|
|
56
63
|
embeds: string[];
|
|
57
64
|
components: string[];
|
|
65
|
+
queries?: string[];
|
|
66
|
+
actions?: string[];
|
|
58
67
|
};
|
|
59
68
|
/**
|
|
60
69
|
* Setup check ids (`permissions.setupChecks`, setup guides v2 §10.2): recorded and shown at
|
|
@@ -117,8 +126,6 @@ export interface PermissionSet {
|
|
|
117
126
|
*/
|
|
118
127
|
warningsDigest?: string;
|
|
119
128
|
}
|
|
120
|
-
/** 迁移警告摘要的权限键前缀(`migration.warnings:<摘要>`)。 */
|
|
121
|
-
export declare const WARNINGS_KEY_PREFIX = "migration.warnings:";
|
|
122
129
|
/**
|
|
123
130
|
* 解析 SQL 中 `CREATE [TEMP|UNLOGGED] TABLE [IF NOT EXISTS] [schema.]name` 的表名(按出现顺序,不去重);
|
|
124
131
|
* 其他语句忽略。schema 等于 `ownSchema` 时去掉前缀(与不带前缀等价),其他 schema 保留 `schema.name`。
|
|
@@ -151,83 +158,12 @@ export declare function buildPermissionSet(input: {
|
|
|
151
158
|
tables: readonly string[];
|
|
152
159
|
permissions?: ExtensionPermissions | undefined;
|
|
153
160
|
warningsDigest?: string | undefined;
|
|
161
|
+
purposes?: ReadonlyMap<string, PermissionPurpose>;
|
|
154
162
|
}): PermissionSet;
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
* `permissions.http.<access>:<METHOD> <path>` (`permissions.http.public:POST /events`),
|
|
159
|
-
* `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud`,
|
|
160
|
-
* `permissions.dialin:capybara-device/6`, `permissions.deviceaccess:browser`,
|
|
161
|
-
* `permissions.deviceaccess.loopbackports`,
|
|
162
|
-
* `permissions.triggers:item.created`, `permissions.inbox`.
|
|
163
|
-
* Tolerates old snapshots missing fields (read as empty), so format changes never throw.
|
|
164
|
-
*/
|
|
163
|
+
/** Legacy approval cannot authorize a privileged execution realm. */
|
|
164
|
+
export declare const FULL_ACCESS_UNSUPPORTED = "permissions.fullAccess is not yet supported by extension approval";
|
|
165
|
+
/** Expand the kernel snapshot's declarations using the SDK's canonical catalog. */
|
|
165
166
|
export declare function permissionKeys(set: PermissionSet): string[];
|
|
166
|
-
/**
|
|
167
|
-
* Key prefix of a policy hook mount (manifest `permissions.policyHooks`): needs approval like any hook.
|
|
168
|
-
* Lower-case letters and dots only, as catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
169
|
-
*/
|
|
170
|
-
export declare const POLICY_HOOK_KEY_PREFIX = "permissions.hooks.policy:";
|
|
171
|
-
/**
|
|
172
|
-
* Permission key of client code (`permissions.client`): sensitive and blocking. The key, not the
|
|
173
|
-
* bundle's bytes, is reviewed: an upgrade that only changes the bundle adds no key.
|
|
174
|
-
*/
|
|
175
|
-
export declare const CLIENT_KEY = "permissions.client";
|
|
176
|
-
/**
|
|
177
|
-
* Key prefix of a dial-in protocol (`permissions.dialIn`): blocking. Lower-case letters and dots
|
|
178
|
-
* before the colon, as catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
179
|
-
*/
|
|
180
|
-
export declare const DIAL_IN_KEY_PREFIX = "permissions.dialin:";
|
|
181
|
-
/**
|
|
182
|
-
* Key prefix of a device service (`permissions.deviceAccess.services`): sensitive and blocking, so
|
|
183
|
-
* an upgrade adding a service waits for approval. Lower-case letters and dots before the colon, as
|
|
184
|
-
* catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
185
|
-
*/
|
|
186
|
-
export declare const DEVICE_ACCESS_KEY_PREFIX = "permissions.deviceaccess:";
|
|
187
|
-
/**
|
|
188
|
-
* Permission key of loopback port grants (`permissions.deviceAccess.loopbackPorts: true`, browser
|
|
189
|
-
* loopback port grants design): sensitive and blocking, so an approved extension never gains it on
|
|
190
|
-
* upgrade without approval again. Recorded only when declared.
|
|
191
|
-
*/
|
|
192
|
-
export declare const DEVICE_LOOPBACK_PORTS_KEY = "permissions.deviceaccess.loopbackports";
|
|
193
|
-
/**
|
|
194
|
-
* Key prefix of a host service (`permissions.deviceAccess.hostServices`): the service runs on the
|
|
195
|
-
* owner's machine outside the sandbox; sensitive and blocking like any device service key.
|
|
196
|
-
*/
|
|
197
|
-
export declare const DEVICE_HOST_KEY_PREFIX = "permissions.deviceaccess.host:";
|
|
198
|
-
/** Blocking permission for profile decisions on non-loopback site actions. */
|
|
199
|
-
export declare const DEVICE_SITE_ACCESS_KEY = "permissions.deviceaccess.siteaccess";
|
|
200
|
-
/**
|
|
201
|
-
* Key prefix of an event type the extension emits (`permissions.triggers.emit`): blocking, not
|
|
202
|
-
* sensitive (an event only reaches automations an org built on it, collaboration spec §4.2).
|
|
203
|
-
* Lower-case letters and dots before the colon, as catalog permission keys require
|
|
204
|
-
* (`PERMISSION_KEY_RE`).
|
|
205
|
-
*/
|
|
206
|
-
export declare const TRIGGERS_KEY_PREFIX = "permissions.triggers:";
|
|
207
|
-
/**
|
|
208
|
-
* Permission key of personal inbox items (`permissions.inbox`): blocking, not sensitive (an item
|
|
209
|
-
* reaches only members of orgs that enabled the extension, links only to its own pages, and its
|
|
210
|
-
* buttons call its UI actions as the person who clicks).
|
|
211
|
-
*/
|
|
212
|
-
export declare const INBOX_KEY = "permissions.inbox";
|
|
213
|
-
/**
|
|
214
|
-
* Permission keys of the read-only org facts: blocking, not sensitive (`ctx.agents` lists the
|
|
215
|
-
* agents a member may use, `ctx.conversations` the metadata of the extension's own subjects'
|
|
216
|
-
* conversations, `ctx.people` the members' names and avatars: no content, no email).
|
|
217
|
-
*/
|
|
218
|
-
export declare const AGENTS_KEY = "permissions.agents";
|
|
219
|
-
export declare const CONVERSATIONS_KEY = "permissions.conversations";
|
|
220
|
-
export declare const PEOPLE_KEY = "permissions.people";
|
|
221
|
-
/** Key prefix of a client component (`ui.component:<id>`): sensitive and blocking. */
|
|
222
|
-
export declare const UI_COMPONENT_KEY_PREFIX = "ui.component:";
|
|
223
|
-
/** 渲染 schema 视图的权限键前缀:记入快照但不卡加载(见 {@link blockingKeys})。 */
|
|
224
|
-
export declare const UI_VIEW_KEY_PREFIX = "ui.view:";
|
|
225
|
-
/**
|
|
226
|
-
* Key prefix of a setup check id (`permissions.setupChecks`): recorded but never blocking
|
|
227
|
-
* ({@link blockingKeys}). Lower-case letters and dots before the colon, as catalog permission keys
|
|
228
|
-
* require (`PERMISSION_KEY_RE` of the marketplace format).
|
|
229
|
-
*/
|
|
230
|
-
export declare const SETUP_CHECK_KEY_PREFIX = "setup.check:";
|
|
231
167
|
/**
|
|
232
168
|
* 新增项里需要批准(卡加载)的部分:除 `ui.view:*` 与 `setup.check:*` 之外的全部。视图只是把插件已有的数据交给
|
|
233
169
|
* 内核组件来画,不给插件新能力(spec §4.1);setup checks get only data the extension already gets
|
|
@@ -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
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
3
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
5
|
+
import type { KernelLogger } from "../log.js";
|
|
6
|
+
export declare const PUBLISHER_PROOF_RECHECK_JOB = "extension-publisher-proof-recheck";
|
|
7
|
+
/**
|
|
8
|
+
* A definite failure (no provenance, another signer, digest or name) is not fetched again before
|
|
9
|
+
* this long: the registry's answer rarely changes. A transient one (network, timeout, 5xx) is
|
|
10
|
+
* retried on the next tick.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PUBLISHER_PROOF_RETRY_MS: number;
|
|
13
|
+
/**
|
|
14
|
+
* Records the publisher proof of installed official-marketplace revisions imported before the
|
|
15
|
+
* kernel recorded one (kernel rc.165 made it an admission condition). Admission itself never
|
|
16
|
+
* fetches: this worker job (`@LockedInterval`, once per tick across replicas, run at start) fetches
|
|
17
|
+
* the npm publish and workflow attestations of exactly `name@version`, verifies them with the same
|
|
18
|
+
* code an import uses against the bundled trust root and the recorded integrity, and writes the
|
|
19
|
+
* proof into the revision's `source_detail` in one conditional statement (only while still
|
|
20
|
+
* missing, so a concurrent upgrade or a second run changes nothing). Every replica then admits the
|
|
21
|
+
* revision on its next convergence. A revision that cannot be verified (no attestations, other
|
|
22
|
+
* signer, other digest) keeps being refused with the "publisher proof missing" reason; the failure
|
|
23
|
+
* is recorded and retried after {@link PUBLISHER_PROOF_RETRY_MS}, a network or registry hiccup on
|
|
24
|
+
* the next tick. Under the super admin's pin-only choice nothing is fetched.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PublisherProofRecheckJob {
|
|
27
|
+
private readonly kdb;
|
|
28
|
+
private readonly bus;
|
|
29
|
+
readonly config: KernelConfigService;
|
|
30
|
+
readonly lockService: LockService;
|
|
31
|
+
readonly log: KernelLogger;
|
|
32
|
+
constructor(kdb: KernelDb, bus: Pick<ExtensionContext["bus"], "publish">, config: KernelConfigService, lockService: LockService, log: KernelLogger);
|
|
33
|
+
recheck(stop?: AbortSignal): Promise<void>;
|
|
34
|
+
/** One pass (the locked tick runs it); returns how many proofs it recorded and how many failed. */
|
|
35
|
+
run(stop?: AbortSignal): Promise<{
|
|
36
|
+
recorded: number;
|
|
37
|
+
failed: number;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
+
import { sql } from "kysely";
|
|
12
|
+
import { publisherCheckTransient, requireMarketplacePublisher, } from "../catalog/marketplace-fetch.js";
|
|
13
|
+
import { OFFICIAL_MARKETPLACE_ID, officialPublisherProofMode, } from "../catalog/publisher-policy.js";
|
|
14
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
15
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
16
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
17
|
+
import { LockedInterval } from "../infra/schedule/locked-interval.js";
|
|
18
|
+
import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
|
|
19
|
+
import { PLUGINS_RECONCILE_TOPIC } from "./lifecycle-topics.js";
|
|
20
|
+
export const PUBLISHER_PROOF_RECHECK_JOB = "extension-publisher-proof-recheck";
|
|
21
|
+
const PUBLISHER_PROOF_RECHECK_PERIOD_MS = 15 * 60_000;
|
|
22
|
+
/**
|
|
23
|
+
* A definite failure (no provenance, another signer, digest or name) is not fetched again before
|
|
24
|
+
* this long: the registry's answer rarely changes. A transient one (network, timeout, 5xx) is
|
|
25
|
+
* retried on the next tick.
|
|
26
|
+
*/
|
|
27
|
+
export const PUBLISHER_PROOF_RETRY_MS = 6 * 60 * 60_000;
|
|
28
|
+
/** Revisions checked per tick (each is one bounded attestation fetch). */
|
|
29
|
+
const PUBLISHER_PROOF_BATCH = 20;
|
|
30
|
+
/**
|
|
31
|
+
* Records the publisher proof of installed official-marketplace revisions imported before the
|
|
32
|
+
* kernel recorded one (kernel rc.165 made it an admission condition). Admission itself never
|
|
33
|
+
* fetches: this worker job (`@LockedInterval`, once per tick across replicas, run at start) fetches
|
|
34
|
+
* the npm publish and workflow attestations of exactly `name@version`, verifies them with the same
|
|
35
|
+
* code an import uses against the bundled trust root and the recorded integrity, and writes the
|
|
36
|
+
* proof into the revision's `source_detail` in one conditional statement (only while still
|
|
37
|
+
* missing, so a concurrent upgrade or a second run changes nothing). Every replica then admits the
|
|
38
|
+
* revision on its next convergence. A revision that cannot be verified (no attestations, other
|
|
39
|
+
* signer, other digest) keeps being refused with the "publisher proof missing" reason; the failure
|
|
40
|
+
* is recorded and retried after {@link PUBLISHER_PROOF_RETRY_MS}, a network or registry hiccup on
|
|
41
|
+
* the next tick. Under the super admin's pin-only choice nothing is fetched.
|
|
42
|
+
*/
|
|
43
|
+
let PublisherProofRecheckJob = class PublisherProofRecheckJob {
|
|
44
|
+
kdb;
|
|
45
|
+
bus;
|
|
46
|
+
config;
|
|
47
|
+
lockService;
|
|
48
|
+
log;
|
|
49
|
+
constructor(kdb, bus, config, lockService, log) {
|
|
50
|
+
this.kdb = kdb;
|
|
51
|
+
this.bus = bus;
|
|
52
|
+
this.config = config;
|
|
53
|
+
this.lockService = lockService;
|
|
54
|
+
this.log = log;
|
|
55
|
+
}
|
|
56
|
+
async recheck(stop) {
|
|
57
|
+
await this.run(stop);
|
|
58
|
+
}
|
|
59
|
+
/** One pass (the locked tick runs it); returns how many proofs it recorded and how many failed. */
|
|
60
|
+
async run(stop) {
|
|
61
|
+
const db = this.kdb.db;
|
|
62
|
+
if ((await officialPublisherProofMode(db)) === "pin-only")
|
|
63
|
+
return { recorded: 0, failed: 0 };
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
const rows = await db
|
|
66
|
+
.selectFrom("extension_installs")
|
|
67
|
+
.innerJoin("catalog_items", "catalog_items.id", "extension_installs.catalog_item_id")
|
|
68
|
+
.innerJoin("catalog_item_versions as revision", (join) => join
|
|
69
|
+
.onRef("revision.item_id", "=", "catalog_items.id")
|
|
70
|
+
.onRef("revision.extension_sha256", "=", "extension_installs.sha256")
|
|
71
|
+
.onRef("revision.version", "=", "extension_installs.version"))
|
|
72
|
+
.select([
|
|
73
|
+
"revision.item_id",
|
|
74
|
+
"revision.version",
|
|
75
|
+
"revision.integrity",
|
|
76
|
+
"catalog_items.package_name",
|
|
77
|
+
])
|
|
78
|
+
.where("extension_installs.source", "=", "catalog")
|
|
79
|
+
.where("catalog_items.marketplace_id", "=", OFFICIAL_MARKETPLACE_ID)
|
|
80
|
+
.where("revision.source", "=", "marketplace")
|
|
81
|
+
.where("revision.integrity", "is not", null)
|
|
82
|
+
.where("catalog_items.package_name", "is not", null)
|
|
83
|
+
.where(sql `NOT (coalesce(revision.source_detail, '{}'::jsonb) ? 'publisherProof')`)
|
|
84
|
+
.where(sql `coalesce(revision.source_detail -> 'publisherProofCheck' ->> 'retryAt', '') <= ${new Date(now).toISOString()}`)
|
|
85
|
+
.orderBy("revision.item_id")
|
|
86
|
+
.limit(PUBLISHER_PROOF_BATCH)
|
|
87
|
+
.execute();
|
|
88
|
+
let recorded = 0;
|
|
89
|
+
let failed = 0;
|
|
90
|
+
for (const row of rows) {
|
|
91
|
+
if (stop?.aborted)
|
|
92
|
+
break;
|
|
93
|
+
const revision = {
|
|
94
|
+
name: row.package_name,
|
|
95
|
+
version: row.version,
|
|
96
|
+
integrity: row.integrity,
|
|
97
|
+
};
|
|
98
|
+
let detail;
|
|
99
|
+
try {
|
|
100
|
+
detail = {
|
|
101
|
+
publisherProof: await requireMarketplacePublisher(this.config.get(), revision, stop),
|
|
102
|
+
};
|
|
103
|
+
recorded += 1;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
if (stop?.aborted)
|
|
107
|
+
break;
|
|
108
|
+
failed += 1;
|
|
109
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
110
|
+
const transient = publisherCheckTransient(err);
|
|
111
|
+
this.log.warn("cannot verify the official publisher of an installed revision", {
|
|
112
|
+
plugin: revision.name,
|
|
113
|
+
version: revision.version,
|
|
114
|
+
reason,
|
|
115
|
+
transient,
|
|
116
|
+
});
|
|
117
|
+
const failedAt = Date.now();
|
|
118
|
+
detail = {
|
|
119
|
+
publisherProofCheck: {
|
|
120
|
+
failedAt: new Date(failedAt).toISOString(),
|
|
121
|
+
reason,
|
|
122
|
+
transient,
|
|
123
|
+
retryAt: new Date(transient ? failedAt : failedAt + PUBLISHER_PROOF_RETRY_MS).toISOString(),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// One conditional statement is its own transaction: nothing else is written with it, and the
|
|
128
|
+
// condition keeps a proof an upgrade or another pass recorded meanwhile.
|
|
129
|
+
await db
|
|
130
|
+
.updateTable("catalog_item_versions")
|
|
131
|
+
.set({
|
|
132
|
+
source_detail: sql `(coalesce(source_detail, '{}'::jsonb) - 'publisherProofCheck') || ${JSON.stringify(detail)}::jsonb`,
|
|
133
|
+
})
|
|
134
|
+
.where("item_id", "=", row.item_id)
|
|
135
|
+
.where("version", "=", row.version)
|
|
136
|
+
.where("integrity", "=", revision.integrity)
|
|
137
|
+
.where(sql `NOT (coalesce(source_detail, '{}'::jsonb) ? 'publisherProof')`)
|
|
138
|
+
.execute();
|
|
139
|
+
}
|
|
140
|
+
if (recorded > 0) {
|
|
141
|
+
this.log.info("recorded official publisher proofs of installed revisions", { recorded });
|
|
142
|
+
await this.bus.publish(PLUGINS_RECONCILE_TOPIC, {});
|
|
143
|
+
}
|
|
144
|
+
return { recorded, failed };
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
__decorate([
|
|
148
|
+
LockedInterval(PUBLISHER_PROOF_RECHECK_JOB, () => PUBLISHER_PROOF_RECHECK_PERIOD_MS, {
|
|
149
|
+
runOnStart: true,
|
|
150
|
+
})
|
|
151
|
+
], PublisherProofRecheckJob.prototype, "recheck", null);
|
|
152
|
+
PublisherProofRecheckJob = __decorate([
|
|
153
|
+
Injectable(),
|
|
154
|
+
__param(0, Inject(KernelDb)),
|
|
155
|
+
__param(1, Inject(KERNEL_BUS)),
|
|
156
|
+
__param(2, Inject(KernelConfigService)),
|
|
157
|
+
__param(3, Inject(LockService)),
|
|
158
|
+
__param(4, Inject(KERNEL_LOGGER))
|
|
159
|
+
], PublisherProofRecheckJob);
|
|
160
|
+
export { PublisherProofRecheckJob };
|
|
@@ -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[];
|