@capybara-hq/kernel 0.1.0-rc.62 → 0.1.0-rc.64
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/bootstrap.json +3 -3
- package/dist/app.d.ts +2 -0
- package/dist/catalog/catalog.service.d.ts +13 -0
- package/dist/catalog/catalog.service.js +17 -8
- package/dist/catalog/git-source.d.ts +8 -0
- package/dist/catalog/git-source.js +14 -6
- package/dist/catalog/marketplaces.controller.d.ts +3 -2
- package/dist/catalog/marketplaces.controller.js +5 -2
- package/dist/catalog/marketplaces.schemas.d.ts +7 -0
- package/dist/catalog/marketplaces.schemas.js +13 -0
- package/dist/catalog/marketplaces.service.d.ts +65 -11
- package/dist/catalog/marketplaces.service.js +208 -30
- package/dist/catalog/org-catalog.schemas.d.ts +1 -1
- package/dist/catalog/org-catalog.schemas.js +1 -1
- package/dist/channels/actions.d.ts +2 -5
- package/dist/channels/actions.js +20 -8
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +6 -4
- package/dist/channels/outbound.js +3 -2
- package/dist/config/schema.d.ts +2 -0
- package/dist/config/schema.js +22 -2
- package/dist/conversations/approval-profile.d.ts +30 -0
- package/dist/conversations/approval-profile.js +62 -0
- package/dist/conversations/conversations.service.js +0 -2
- package/dist/conversations/events.d.ts +43 -0
- package/dist/conversations/events.js +52 -0
- package/dist/conversations/permission-profiles.controller.d.ts +3 -2
- package/dist/conversations/permission-profiles.service.d.ts +3 -2
- package/dist/conversations/permission-profiles.service.js +12 -8
- package/dist/db/kernel-schema.d.ts +8 -2
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +7 -0
- package/dist/extensions/bootstrap-defaults.d.ts +24 -0
- package/dist/extensions/bootstrap-defaults.js +78 -0
- package/dist/extensions/bootstrap-extra.d.ts +74 -0
- package/dist/extensions/bootstrap-extra.js +131 -0
- package/dist/extensions/bootstrap.d.ts +77 -13
- package/dist/extensions/bootstrap.js +282 -48
- package/dist/identity/initial-passwords.controller.d.ts +8 -6
- package/dist/identity/initial-passwords.controller.js +13 -7
- package/dist/identity/initial-passwords.d.ts +22 -13
- package/dist/identity/initial-passwords.js +25 -29
- package/dist/identity/settings.d.ts +10 -0
- package/dist/identity/settings.js +46 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/kernel.module.js +3 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +7 -1
- package/dist/lifecycle/kernel-lifecycle.js +69 -16
- package/dist/local-devices/relay.js +3 -1
- package/dist/models/images.js +5 -4
- package/dist/platform/connector-person-fields.js +2 -2
- package/dist/platform/exclusions.js +4 -4
- package/dist/platform/method.js +1 -1
- package/dist/platform/operation.d.ts +9 -7
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/accounts.ops.d.ts +1 -1
- package/dist/platform/ops/accounts.ops.js +3 -3
- package/dist/platform/ops/channels.ops.d.ts +1 -1
- package/dist/platform/ops/channels.ops.js +2 -2
- package/dist/platform/ops/connectors.ops.d.ts +2 -2
- package/dist/platform/ops/connectors.ops.js +8 -8
- package/dist/platform/ops/extensions-admin.ops.d.ts +1 -1
- package/dist/platform/ops/extensions-admin.ops.js +3 -3
- package/dist/platform/ops/extensions.ops.d.ts +1 -1
- package/dist/platform/ops/extensions.ops.js +4 -4
- package/dist/platform/ops/marketplaces.ops.js +27 -4
- package/dist/platform/ops/org-plugins.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.d.ts +1 -1
- package/dist/platform/ops/orgs.ops.js +3 -3
- package/dist/platform/ops/plugins.ops.d.ts +1 -1
- package/dist/platform/ops/plugins.ops.js +2 -2
- package/dist/platform/person-fields.d.ts +4 -3
- package/dist/platform/person-fields.js +6 -5
- package/dist/platform/sealed-inputs.d.ts +2 -2
- package/dist/platform/sealed-inputs.js +2 -2
- package/dist/platform/sealed-reveals.controller.d.ts +5 -8
- package/dist/platform/sealed-reveals.controller.js +8 -8
- package/dist/platform/sealed-reveals.d.ts +19 -17
- package/dist/platform/sealed-reveals.js +30 -33
- package/dist/runtime/context/build.js +3 -0
- package/dist/runtime/context/compaction.js +2 -0
- package/dist/runtime/waits.js +3 -2
- package/dist/sandbox/operation-authority.js +16 -15
- package/dist/sandbox/operation-intents.js +2 -2
- package/dist/sandbox/permission-availability.d.ts +49 -3
- package/dist/sandbox/permission-availability.js +61 -6
- package/dist/sandbox/permission-call-types.d.ts +3 -0
- package/dist/sandbox/permission-facts.d.ts +29 -1
- package/dist/sandbox/permission-facts.js +29 -6
- package/dist/sandbox/review/classifier.d.ts +72 -2
- package/dist/sandbox/review/classifier.js +113 -38
- package/dist/sandbox/review/index.d.ts +2 -2
- package/dist/sandbox/review/index.js +1 -1
- package/dist/sandbox/review/review.service.d.ts +1 -4
- package/dist/sandbox/review/review.service.js +4 -33
- package/dist/setup/setup-guides.service.js +1 -1
- package/dist/tools/approvals.service.d.ts +71 -16
- package/dist/tools/approvals.service.js +139 -13
- package/dist/tools/builtins/builtin-tools.d.ts +1 -1
- package/dist/tools/builtins/builtin-tools.js +12 -6
- package/dist/tools/builtins/platform.d.ts +15 -11
- package/dist/tools/builtins/platform.js +49 -39
- package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
- package/dist/tools/builtins/sandbox/bash.js +32 -14
- package/dist/tools/builtins/sandbox/common.d.ts +12 -3
- package/dist/tools/builtins/sandbox/common.js +29 -5
- package/dist/tools/connectors.schemas.d.ts +1 -1
- package/dist/tools/connectors.schemas.js +1 -1
- package/dist/tools/pipeline.d.ts +70 -10
- package/dist/tools/pipeline.js +356 -48
- package/dist/tools/policy.d.ts +4 -3
- package/dist/tools/policy.js +6 -6
- package/dist/tools/registry.d.ts +25 -9
- package/dist/tools/tool-review.d.ts +113 -0
- package/dist/tools/tool-review.js +303 -0
- package/dist/tools/tools.module.js +6 -0
- package/package.json +4 -4
- package/src/migrations/0174_marketplace_managed_username.sql +4 -0
- package/src/migrations/0175_secure_input_kind.sql +8 -0
|
@@ -11,14 +11,17 @@ import { createHash } from "node:crypto";
|
|
|
11
11
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
|
-
import { parseBootstrapManifest, SDK_VERSION, } from "@capybara-hq/plugin-sdk";
|
|
14
|
+
import { PLUGIN_MANIFEST_FILE, parseBootstrapManifest, SDK_VERSION, } from "@capybara-hq/plugin-sdk";
|
|
15
15
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
16
16
|
import { sql } from "kysely";
|
|
17
17
|
import semver from "semver";
|
|
18
|
-
import {
|
|
18
|
+
import { marketplaceGitSource, repoOwner } from "../catalog/catalog.service.js";
|
|
19
|
+
import { GitSourceError, normalGitPath, readGitTreeAndOids } from "../catalog/git-source.js";
|
|
20
|
+
import { marketplaceNetPolicy, marketplaceUrlProblem } from "../catalog/marketplace-fetch.js";
|
|
21
|
+
import { CONFIG_MARKETPLACE_PREFIX, marketplaceForm } from "../catalog/marketplaces.service.js";
|
|
19
22
|
import { otherNameOwner } from "../catalog/ownership.js";
|
|
20
|
-
import { catalogPackageError } from "../catalog/plugin-import.js";
|
|
21
|
-
import { PluginPackageError, readPluginPackage } from "../catalog/plugin-package.js";
|
|
23
|
+
import { catalogPackageError, } from "../catalog/plugin-import.js";
|
|
24
|
+
import { PluginPackageError, readPluginFiles, readPluginPackage, } from "../catalog/plugin-package.js";
|
|
22
25
|
import { ApiError } from "../errors.js";
|
|
23
26
|
import { audit } from "../identity/audit.js";
|
|
24
27
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -28,8 +31,10 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
28
31
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
29
32
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
30
33
|
import { fetchNpmPackage, IntegrityMismatchError, NpmFetchError, PackageTooLargeError, } from "../packages/npm.js";
|
|
34
|
+
import { PackageTgzError, packPackageTgz, unpackPackageTgz } from "../packages/tgz.js";
|
|
31
35
|
import { ExtensionAdminOps } from "./admin-ops.js";
|
|
32
36
|
import { writeSnapshot } from "./approvals.js";
|
|
37
|
+
import { BootstrapExtraMismatchError, hasExtraManifestTraces, } from "./bootstrap-extra.js";
|
|
33
38
|
import { ExtensionInstalls } from "./installs.js";
|
|
34
39
|
import { PluginApproveLock } from "./locks.js";
|
|
35
40
|
import { ExtensionPackageError, permissionSetOfPackage, readExtensionPackage } from "./package.js";
|
|
@@ -46,8 +51,11 @@ import { ExtensionRegistry } from "./registry.js";
|
|
|
46
51
|
* ({@link resolveBootstrapPackages}): a `*.tgz` file of the optional offline directory whose
|
|
47
52
|
* sha512 equals the entry's `integrity` (the file name does not matter), else the npm download
|
|
48
53
|
* of a `source: "npm"` entry (`packages.npmRegistry` / `npmToken` / `maxBytes`, verified against
|
|
49
|
-
* the pin only)
|
|
50
|
-
*
|
|
54
|
+
* the pin only), or the git read of a `source: "git"` entry of the extra manifest (its tree at the
|
|
55
|
+
* pinned commit, packed with `packPackageTgz` and verified against the pin before anything reads
|
|
56
|
+
* it; see {@link resolveBootstrapPackages}). A workspace entry without a matching file is
|
|
57
|
+
* `bootstrap.missing_file`, a failed download `bootstrap.download_failed` (a failed git read
|
|
58
|
+
* `bootstrap.git_read_failed`), a package that differs from the pin
|
|
51
59
|
* `bootstrap.integrity_mismatch` (all name the plugin), and then nothing is written. Downloading
|
|
52
60
|
* inside the lock means a fleet starting together downloads once.
|
|
53
61
|
* - The whole run holds the Redis lock `lock:bootstrap` (`LockService`, decision R5 of the Nest
|
|
@@ -69,7 +77,10 @@ import { ExtensionRegistry } from "./registry.js";
|
|
|
69
77
|
* declarative one imported again when its catalog item is gone).
|
|
70
78
|
* - Per entry, by the installed state of its extension:
|
|
71
79
|
* - not installed (and new, or required): imported into the catalog (source `bootstrap`, ref
|
|
72
|
-
* `bootstrap:<name>@<version>`, like a marketplace import
|
|
80
|
+
* `bootstrap:<name>@<version>`, like a marketplace import; a git entry is recorded as the
|
|
81
|
+
* managed marketplace `config:<marketplace>` it names, with the git location an admin import of
|
|
82
|
+
* that marketplace's `path` entry records, so later imports from it are the same source),
|
|
83
|
+
* installed, approved (snapshot
|
|
73
84
|
* source `bootstrap`, audited `extension.permissions_approved` with `source: "bootstrap"`)
|
|
74
85
|
* and enabled -> `installed`;
|
|
75
86
|
* - installed from `bootstrap` at a lower version: upgraded the same way (core's release vouched
|
|
@@ -143,12 +154,35 @@ export async function readBootstrapManifest(file = BOOTSTRAP_MANIFEST_FILE) {
|
|
|
143
154
|
return parsed;
|
|
144
155
|
}
|
|
145
156
|
const integrityOf = (bytes) => `sha512-${createHash("sha512").update(bytes).digest("base64")}`;
|
|
157
|
+
/**
|
|
158
|
+
* The marketplace a git entry names, its URL expanded as the managed row's (`config:<name>`) is and
|
|
159
|
+
* checked as an admin-added one is (`bootstrap.extra_invalid` otherwise).
|
|
160
|
+
*/
|
|
161
|
+
export function bootstrapGitMarketplace(manifest, e, config) {
|
|
162
|
+
const m = manifest.extra?.marketplaces.find((x) => x.name === e.marketplace);
|
|
163
|
+
const invalid = (why) => new ApiError("bootstrap.extra_invalid", `Bootstrap plugin ${e.name} ${e.version}: marketplace ${e.marketplace} ${why}`);
|
|
164
|
+
if (m === undefined)
|
|
165
|
+
throw invalid("is not declared in the extra bootstrap manifest");
|
|
166
|
+
const { form, url } = marketplaceForm(m.url);
|
|
167
|
+
if (form !== "git")
|
|
168
|
+
throw invalid("is not a git repository");
|
|
169
|
+
const problem = marketplaceUrlProblem(url, config.marketplaces.allowInsecureLoopback);
|
|
170
|
+
if (problem !== null)
|
|
171
|
+
throw invalid(`has an unusable url: ${problem}`);
|
|
172
|
+
return { ...m, url };
|
|
173
|
+
}
|
|
174
|
+
/** The managed marketplace's id of an extra-manifest marketplace (the row the kernel start creates). */
|
|
175
|
+
const managedMarketplaceId = (name) => `${CONFIG_MARKETPLACE_PREFIX}${name}`;
|
|
146
176
|
/**
|
|
147
177
|
* Obtains every entry's tgz, checked against its pinned sha512: from the offline directory when a
|
|
148
178
|
* file there has that sha512, else (a `source: "npm"` entry) downloaded from the npm registry and
|
|
149
|
-
* verified against the pin (the packument's `dist.integrity` is not consulted)
|
|
150
|
-
*
|
|
151
|
-
*
|
|
179
|
+
* verified against the pin (the packument's `dist.integrity` is not consulted), else (a
|
|
180
|
+
* `source: "git"` entry) its marketplace's tree at the pinned commit, the files under `path`
|
|
181
|
+
* re-rooted and packed with `packPackageTgz` (the pin is defined on that pack), refused unless the
|
|
182
|
+
* pack's sha512 is the pin: nothing of an unverified tree is read, translated or imported. The
|
|
183
|
+
* marketplace's token and username go only to its URL's origin. Throws an {@link ApiError} naming
|
|
184
|
+
* the plugin for the first entry it cannot obtain (`bootstrap.missing_file`,
|
|
185
|
+
* `bootstrap.download_failed`, `bootstrap.git_read_failed`, `bootstrap.integrity_mismatch`), except
|
|
152
186
|
* for the `soft` entries (recorded in `failed`, left out of the result).
|
|
153
187
|
*/
|
|
154
188
|
export async function resolveBootstrapPackages(manifest, o) {
|
|
@@ -176,6 +210,8 @@ export async function resolveBootstrapPackages(manifest, o) {
|
|
|
176
210
|
const found = offline.get(e.integrity);
|
|
177
211
|
if (found !== undefined)
|
|
178
212
|
return found;
|
|
213
|
+
if (e.source === "git")
|
|
214
|
+
return obtainGit(e);
|
|
179
215
|
if (e.source === "workspace") {
|
|
180
216
|
throw new ApiError("bootstrap.missing_file", `Bootstrap plugin ${e.name} ${e.version}: no file in ${where} has its pinned sha512 (${e.integrity.slice(0, 19)}…), and a workspace entry cannot be downloaded; put its package tgz (pnpm pack-plugin ${e.path}) in that directory`);
|
|
181
217
|
}
|
|
@@ -204,7 +240,60 @@ export async function resolveBootstrapPackages(manifest, o) {
|
|
|
204
240
|
throw new ApiError("bootstrap.download_failed", `Bootstrap plugin ${e.name} ${e.version}: cannot download ${e.npm}@${e.version} from ${registry} (${reason}); ${offlineHint}, or set packages.npmRegistry to a reachable mirror`);
|
|
205
241
|
}
|
|
206
242
|
}
|
|
243
|
+
async function obtainGit(e) {
|
|
244
|
+
const m = bootstrapGitMarketplace(manifest, e, o.config);
|
|
245
|
+
const u = new URL(m.url);
|
|
246
|
+
const at = `${e.path} at ${e.commit.slice(0, 12)} of marketplace ${m.name} (${u.origin}${u.pathname})`;
|
|
247
|
+
const cred = (o.gitCredentials ?? defaultGitCredentials)(m.name);
|
|
248
|
+
const token = cred.token !== undefined && cred.token !== "" ? cred.token : undefined;
|
|
249
|
+
const dir = normalGitPath(e.path);
|
|
250
|
+
let read;
|
|
251
|
+
try {
|
|
252
|
+
read = await readGitTreeAndOids({ url: m.url, commit: e.commit, path: e.path }, {
|
|
253
|
+
net: marketplaceNetPolicy(o.config),
|
|
254
|
+
maxBytes,
|
|
255
|
+
signal,
|
|
256
|
+
...(token !== undefined && {
|
|
257
|
+
token,
|
|
258
|
+
tokenOrigin: u.origin,
|
|
259
|
+
...(cred.username !== undefined && cred.username !== "" && { username: cred.username }),
|
|
260
|
+
}),
|
|
261
|
+
trees: () => [dir],
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
if (signal.aborted)
|
|
266
|
+
throw err;
|
|
267
|
+
// git-source messages never carry the token; redacted all the same, it is a credential
|
|
268
|
+
const reason = errMsg(err);
|
|
269
|
+
const redacted = token !== undefined ? reason.replaceAll(token, "***") : reason;
|
|
270
|
+
// A bootstrap entry pins a commit by its sha: a ref tip is not what it can change to
|
|
271
|
+
const message = err instanceof GitSourceError && err.refusedCommit !== undefined
|
|
272
|
+
? `the host refused to send commit ${err.refusedCommit} by its sha. The commit must be fetchable by its sha (GitHub: always; GitLab, Gitea and other hosts: only when fetching unadvertised commits is allowed, e.g. git's uploadpack.allowReachableSHA1InWant or the host's equivalent), or pin the commit of a tag and keep the tag, or put its pack (capybara-plugin bootstrap --write --out <dir>) in the offline directory, ${where}`
|
|
273
|
+
: `${redacted}; to install offline, put its pack (capybara-plugin bootstrap --write) in ${where}`;
|
|
274
|
+
throw new ApiError("bootstrap.git_read_failed", `Bootstrap plugin ${e.name} ${e.version}: cannot read ${at}: ${message}`);
|
|
275
|
+
}
|
|
276
|
+
const pack = await packPackageTgz(read.files);
|
|
277
|
+
const actual = integrityOf(pack);
|
|
278
|
+
if (actual !== e.integrity) {
|
|
279
|
+
throw new ApiError("bootstrap.integrity_mismatch", `Bootstrap plugin ${e.name} ${e.version}: ${at} packs to another sha512 than its pin (expected ${e.integrity.slice(0, 19)}…, got ${actual.slice(0, 19)}…); refusing to install anything`);
|
|
280
|
+
}
|
|
281
|
+
const tree = read.trees.get(dir);
|
|
282
|
+
if (tree !== undefined)
|
|
283
|
+
o.gitTrees?.set(e.name, tree);
|
|
284
|
+
return pack;
|
|
285
|
+
}
|
|
286
|
+
function defaultGitCredentials(name) {
|
|
287
|
+
const tokens = o.config.marketplaces.tokens;
|
|
288
|
+
const username = manifest.extra?.marketplaces.find((x) => x.name === name)?.username;
|
|
289
|
+
return {
|
|
290
|
+
...(Object.hasOwn(tokens, name) && { token: tokens[name] }),
|
|
291
|
+
...(username !== undefined && { username }),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
207
294
|
}
|
|
295
|
+
/** The message of a thrown value. */
|
|
296
|
+
export const errMsg = (e) => (e instanceof Error ? e.message : String(e));
|
|
208
297
|
/** The registry's origin, for messages (never its credentials or path). */
|
|
209
298
|
function registryOrigin(registry) {
|
|
210
299
|
try {
|
|
@@ -306,12 +395,39 @@ let BootstrapService = class BootstrapService {
|
|
|
306
395
|
.executeTakeFirst();
|
|
307
396
|
return row !== undefined;
|
|
308
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* What an extra manifest left ({@link ExtraManifestTraces}): the config-managed marketplaces
|
|
400
|
+
* (`managed = 'config'`) and the entries the last completed run flagged `extra`. A process
|
|
401
|
+
* without an extra manifest that finds any is configured differently from the ones that wrote
|
|
402
|
+
* them (rulings R14, R17). An entry a built-in manifest dropped is never flagged, so it is no
|
|
403
|
+
* trace.
|
|
404
|
+
*/
|
|
405
|
+
async extraManifestTraces() {
|
|
406
|
+
const rows = await this.db
|
|
407
|
+
.selectFrom("marketplaces")
|
|
408
|
+
.select("name")
|
|
409
|
+
.where("managed", "=", "config")
|
|
410
|
+
.orderBy("name")
|
|
411
|
+
.execute();
|
|
412
|
+
const last = await this.lastRunResults();
|
|
413
|
+
return {
|
|
414
|
+
marketplaces: rows.map((r) => r.name),
|
|
415
|
+
plugins: (last ?? [])
|
|
416
|
+
.filter((r) => r.extra === true)
|
|
417
|
+
.map((r) => r.name)
|
|
418
|
+
.sort(),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
309
421
|
/**
|
|
310
422
|
* Runs the bootstrap step (see the file header); when it is already done for this manifest
|
|
311
423
|
* (also when another replica finished it while this one waited for the lock) returns the
|
|
312
424
|
* recorded result without doing anything. `carry`: the results of an earlier, failed run in the
|
|
313
425
|
* same start ({@link BootstrapFailedError.results}); an entry it installed, upgraded or imported
|
|
314
|
-
* keeps that action instead of `kept` in this run's record.
|
|
426
|
+
* keeps that action instead of `kept` in this run's record. A manifest without an extra manifest
|
|
427
|
+
* while an extra manifest left traces ({@link extraManifestTraces}) throws
|
|
428
|
+
* {@link BootstrapExtraMismatchError}, checked under the lock before anything is obtained or
|
|
429
|
+
* written (ruling R16): the caller's own check may have run before another replica's sync
|
|
430
|
+
* committed. Every result of an entry from the extra manifest is flagged `extra` (R17).
|
|
315
431
|
*/
|
|
316
432
|
async run(o) {
|
|
317
433
|
const manifestSha256 = bootstrapManifestSha256(o.manifest);
|
|
@@ -332,6 +448,12 @@ let BootstrapService = class BootstrapService {
|
|
|
332
448
|
const done = await recorded();
|
|
333
449
|
if (done)
|
|
334
450
|
return done;
|
|
451
|
+
if (o.manifest.extra === undefined) {
|
|
452
|
+
const traces = await this.extraManifestTraces();
|
|
453
|
+
if (hasExtraManifestTraces(traces))
|
|
454
|
+
throw new BootstrapExtraMismatchError(traces);
|
|
455
|
+
}
|
|
456
|
+
const fromExtra = new Set(o.manifest.extra?.plugins);
|
|
335
457
|
const deferBuiltin = o.deferBuiltin === true;
|
|
336
458
|
const isDeferred = (e) => deferBuiltin && e.builtin === true;
|
|
337
459
|
// Every package is obtained and checked before the first write (a deferred entry's by the
|
|
@@ -340,6 +462,7 @@ let BootstrapService = class BootstrapService {
|
|
|
340
462
|
const files = new Map();
|
|
341
463
|
const fetchFailed = new Map();
|
|
342
464
|
const toObtain = [];
|
|
465
|
+
const gitTrees = new Map();
|
|
343
466
|
for (const e of o.manifest.plugins) {
|
|
344
467
|
if (isDeferred(e))
|
|
345
468
|
continue;
|
|
@@ -354,7 +477,11 @@ let BootstrapService = class BootstrapService {
|
|
|
354
477
|
config: this.config(),
|
|
355
478
|
signal,
|
|
356
479
|
log: this.log,
|
|
357
|
-
...(!deferBuiltin && {
|
|
480
|
+
...(!deferBuiltin && {
|
|
481
|
+
soft: (e) => !e.required,
|
|
482
|
+
failed: fetchFailed,
|
|
483
|
+
}),
|
|
484
|
+
gitTrees,
|
|
358
485
|
});
|
|
359
486
|
for (const [name, bytes] of obtained)
|
|
360
487
|
files.set(name, bytes);
|
|
@@ -373,8 +500,12 @@ let BootstrapService = class BootstrapService {
|
|
|
373
500
|
const fetchErr = fetchFailed.get(e.name);
|
|
374
501
|
if (fetchErr !== undefined)
|
|
375
502
|
throw fetchErr;
|
|
376
|
-
const r = await this.entry(e, files.get(e.name), handled, o.imports
|
|
377
|
-
|
|
503
|
+
const r = await this.entry(e, files.get(e.name), handled, o.imports, {
|
|
504
|
+
manifest: o.manifest,
|
|
505
|
+
tree: gitTrees.get(e.name),
|
|
506
|
+
});
|
|
507
|
+
const c = carried(r, o.carry);
|
|
508
|
+
results.push(fromExtra.has(e.name) ? { ...c, extra: true } : c);
|
|
378
509
|
}
|
|
379
510
|
catch (err) {
|
|
380
511
|
this.log.error("bootstrap: a plugin could not be installed", {
|
|
@@ -457,41 +588,89 @@ let BootstrapService = class BootstrapService {
|
|
|
457
588
|
await handle.release();
|
|
458
589
|
}
|
|
459
590
|
}
|
|
460
|
-
/** The
|
|
461
|
-
async
|
|
591
|
+
/** The results of the last completed run (undefined before any run completed). */
|
|
592
|
+
async lastRunResults() {
|
|
462
593
|
const row = await this.db
|
|
463
594
|
.selectFrom("bootstrap_runs")
|
|
464
595
|
.select("results")
|
|
465
596
|
.orderBy("completed_at", "desc")
|
|
466
597
|
.limit(1)
|
|
467
598
|
.executeTakeFirst();
|
|
468
|
-
|
|
599
|
+
return row?.results;
|
|
600
|
+
}
|
|
601
|
+
/** The entry names the last completed run handled (undefined before any run completed). */
|
|
602
|
+
async lastRunNames() {
|
|
603
|
+
const results = await this.lastRunResults();
|
|
604
|
+
if (!results)
|
|
469
605
|
return undefined;
|
|
470
|
-
return new Set(
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
606
|
+
return new Set(results.filter((r) => r.action !== "required_cleared").map((r) => r.name));
|
|
607
|
+
}
|
|
608
|
+
async entry(e, bytes, handled, imports,
|
|
609
|
+
/** For a git entry: the manifest (its marketplaces) and the tree oid when read from git now. */
|
|
610
|
+
at) {
|
|
611
|
+
let plugin;
|
|
612
|
+
let source;
|
|
613
|
+
let git;
|
|
614
|
+
if (e.source === "git") {
|
|
615
|
+
const m = bootstrapGitMarketplace(at.manifest, e, this.config());
|
|
616
|
+
git = { files: await this.unpackGit(e, bytes), publisher: repoOwner(m.url) };
|
|
617
|
+
plugin = this.gitPlugin(e, git.files);
|
|
618
|
+
// The source an admin import of the managed marketplace's `path` entry records (same
|
|
619
|
+
// arguments), so its later versions add to this item
|
|
620
|
+
const where = marketplaceGitSource({
|
|
621
|
+
url: m.url,
|
|
622
|
+
commit: e.commit,
|
|
623
|
+
path: e.path,
|
|
624
|
+
...(m.ref !== undefined && { ref: m.ref }),
|
|
625
|
+
}, { commit: e.commit, tree: at.tree }, false);
|
|
626
|
+
const marketplaceId = managedMarketplaceId(m.name);
|
|
627
|
+
// The managed row is created by the kernel start before its bootstrap step; `capybara
|
|
628
|
+
// bootstrap` may run before any start, when the item cannot name it yet (a foreign key).
|
|
629
|
+
// The git location alone makes it the same source; an import from the marketplace names it
|
|
630
|
+
const managed = await this.db
|
|
631
|
+
.selectFrom("marketplaces")
|
|
632
|
+
.select("id")
|
|
633
|
+
.where("id", "=", marketplaceId)
|
|
634
|
+
.executeTakeFirst();
|
|
635
|
+
source = {
|
|
636
|
+
kind: "bootstrap",
|
|
637
|
+
ref: `${marketplaceId}:${where.ref}`,
|
|
638
|
+
integrity: e.integrity,
|
|
639
|
+
...(managed !== undefined && { marketplaceId }),
|
|
640
|
+
detail: where.detail,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
const pkg = await readPluginPackage(bytes, {
|
|
645
|
+
maxBytes: this.config().packages.maxBytes,
|
|
646
|
+
hostSdkVersion: SDK_VERSION,
|
|
647
|
+
}).catch((err) => {
|
|
648
|
+
throw err instanceof PluginPackageError ? catalogPackageError(err) : err;
|
|
649
|
+
});
|
|
650
|
+
plugin = {
|
|
651
|
+
name: pkg.manifest.name,
|
|
652
|
+
version: pkg.manifest.version,
|
|
653
|
+
extension: pkg.manifest.extension !== undefined,
|
|
654
|
+
};
|
|
655
|
+
source = {
|
|
656
|
+
kind: "bootstrap",
|
|
657
|
+
ref: `bootstrap:${e.name}@${e.version}`,
|
|
658
|
+
integrity: e.integrity,
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
if (plugin.name !== e.name || plugin.version !== e.version) {
|
|
662
|
+
throw new ApiError("catalog.invalid_manifest", `The package for bootstrap entry ${e.name} ${e.version} contains plugin ${plugin.name} ${plugin.version}`);
|
|
483
663
|
}
|
|
484
|
-
const ref = `bootstrap:${e.name}@${e.version}`;
|
|
485
664
|
// Not new to the manifest: an optional entry left out on purpose stays out (Ruling 5)
|
|
486
665
|
const isNew = handled === undefined || !handled.has(e.name);
|
|
487
666
|
// Required and builtin entries are builtin in the catalog and put back when missing
|
|
488
667
|
const builtin = e.required || e.builtin === true;
|
|
489
|
-
if (!
|
|
668
|
+
if (!plugin.extension) {
|
|
490
669
|
await this.markBuiltin(e.name, builtin);
|
|
491
670
|
if (!isNew && !(builtin && !(await this.hasLiveItem(e.name)))) {
|
|
492
671
|
return { name: e.name, action: "kept", version: e.version };
|
|
493
672
|
}
|
|
494
|
-
const imported = await this.importOnly(e, bytes,
|
|
673
|
+
const imported = await this.importOnly(e, bytes, source, imports, git);
|
|
495
674
|
await this.markBuiltin(e.name, builtin);
|
|
496
675
|
return { name: e.name, action: imported ? "imported" : "kept", version: e.version };
|
|
497
676
|
}
|
|
@@ -513,12 +692,12 @@ let BootstrapService = class BootstrapService {
|
|
|
513
692
|
let result;
|
|
514
693
|
let leftDisabled;
|
|
515
694
|
if (!row) {
|
|
516
|
-
leftDisabled = await this.deploy(e, bytes,
|
|
695
|
+
leftDisabled = await this.deploy(e, bytes, source, true, imports, git);
|
|
517
696
|
result = { name: e.name, action: "installed", version: e.version };
|
|
518
697
|
}
|
|
519
698
|
else if (row.source === "bootstrap" && isLower(row.version, e.version)) {
|
|
520
699
|
// The desired state the admin chose is kept; a required plugin is enabled below anyway
|
|
521
|
-
leftDisabled = await this.deploy(e, bytes,
|
|
700
|
+
leftDisabled = await this.deploy(e, bytes, source, row.desired_state === "enabled", imports, git);
|
|
522
701
|
result = { name: e.name, action: "upgraded", version: e.version };
|
|
523
702
|
}
|
|
524
703
|
else {
|
|
@@ -591,14 +770,69 @@ let BootstrapService = class BootstrapService {
|
|
|
591
770
|
.where("builtin", "=", true)
|
|
592
771
|
.execute();
|
|
593
772
|
}
|
|
594
|
-
/**
|
|
595
|
-
|
|
773
|
+
/**
|
|
774
|
+
* The files of a git entry's verified pack (exactly the tree read at its commit). A tree the tgz
|
|
775
|
+
* rules refuse is `catalog.invalid_manifest`.
|
|
776
|
+
*/
|
|
777
|
+
async unpackGit(e, bytes) {
|
|
596
778
|
try {
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
779
|
+
const unpacked = await unpackPackageTgz(bytes, {
|
|
780
|
+
maxBytes: this.config().packages.maxBytes,
|
|
781
|
+
});
|
|
782
|
+
return new Map(unpacked.map((f) => [f.path, f.data]));
|
|
783
|
+
}
|
|
784
|
+
catch (err) {
|
|
785
|
+
if (!(err instanceof PackageTgzError))
|
|
786
|
+
throw err;
|
|
787
|
+
throw new ApiError("catalog.invalid_manifest", `The tree of bootstrap entry ${e.name} ${e.version}: ${err.issues.join("; ")}`);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Name, version and extension of a git entry's tree: from its `plugin.json`; a tree without one
|
|
792
|
+
* (a Claude Code or skills-only plugin, never an extension) is named by the entry, which its
|
|
793
|
+
* import's review is checked against ({@link prepareGitEntry}).
|
|
794
|
+
*/
|
|
795
|
+
gitPlugin(e, files) {
|
|
796
|
+
if (!files.has(PLUGIN_MANIFEST_FILE)) {
|
|
797
|
+
return { name: e.name, version: e.version, extension: false };
|
|
798
|
+
}
|
|
799
|
+
try {
|
|
800
|
+
const { manifest } = readPluginFiles(files, {
|
|
801
|
+
hostSdkVersion: SDK_VERSION,
|
|
802
|
+
requirePackageJson: false,
|
|
601
803
|
});
|
|
804
|
+
return {
|
|
805
|
+
name: manifest.name,
|
|
806
|
+
version: manifest.version,
|
|
807
|
+
extension: manifest.extension !== undefined,
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
catch (err) {
|
|
811
|
+
throw err instanceof PluginPackageError ? catalogPackageError(err) : err;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/** Stages a git entry from its files as an admin git import would (translation included). */
|
|
815
|
+
async prepareGitEntry(e, git, source, imports) {
|
|
816
|
+
const staged = await imports.prepareGit(null, git.files, source, {
|
|
817
|
+
fallback: {
|
|
818
|
+
name: e.name,
|
|
819
|
+
version: e.version,
|
|
820
|
+
publisher: git.publisher,
|
|
821
|
+
entryVersion: e.version,
|
|
822
|
+
},
|
|
823
|
+
});
|
|
824
|
+
const { name, version, pluginVersion } = staged.review;
|
|
825
|
+
if (name !== e.name || (pluginVersion ?? version) !== e.version) {
|
|
826
|
+
throw new ApiError("catalog.invalid_manifest", `The tree of bootstrap entry ${e.name} ${e.version} is plugin ${name} ${pluginVersion ?? version}`);
|
|
827
|
+
}
|
|
828
|
+
return staged;
|
|
829
|
+
}
|
|
830
|
+
/** A declarative plugin: catalog only. Returns false when that version is already imported. */
|
|
831
|
+
async importOnly(e, bytes, source, imports, git) {
|
|
832
|
+
try {
|
|
833
|
+
const { stagingId, review } = git !== undefined
|
|
834
|
+
? await this.prepareGitEntry(e, git, source, imports)
|
|
835
|
+
: await imports.prepare(null, bytes, source);
|
|
602
836
|
await imports.confirm(null, stagingId, { reviewHash: review.reviewHash });
|
|
603
837
|
return true;
|
|
604
838
|
}
|
|
@@ -613,18 +847,18 @@ let BootstrapService = class BootstrapService {
|
|
|
613
847
|
* the catalog already has this version (an earlier run stopped after importing, or the same
|
|
614
848
|
* package came from a marketplace), the extension is deployed from the package store instead.
|
|
615
849
|
*/
|
|
616
|
-
async deploy(e, bytes,
|
|
850
|
+
async deploy(e, bytes, source, enable, imports, git) {
|
|
617
851
|
let staged;
|
|
618
852
|
try {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
853
|
+
// A git plugin with an extension is packed again from these files: the verified bytes
|
|
854
|
+
staged =
|
|
855
|
+
git !== undefined
|
|
856
|
+
? await this.prepareGitEntry(e, git, source, imports)
|
|
857
|
+
: await imports.prepare(null, bytes, source);
|
|
624
858
|
}
|
|
625
859
|
catch (err) {
|
|
626
860
|
if (err instanceof ApiError && err.code === "catalog.version_exists") {
|
|
627
|
-
return this.deployFromStore(e, bytes, ref, enable);
|
|
861
|
+
return this.deployFromStore(e, bytes, source.ref, enable);
|
|
628
862
|
}
|
|
629
863
|
throw err;
|
|
630
864
|
}
|
|
@@ -2,21 +2,23 @@ import { z } from "zod";
|
|
|
2
2
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
3
3
|
import { InitialPasswords } from "./initial-passwords.js";
|
|
4
4
|
import { type Principal } from "./principal.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/** The tool call a once-shown value was made by. */
|
|
6
|
+
export declare const RevealCallParams: z.ZodObject<{
|
|
7
|
+
conversationId: z.ZodString;
|
|
8
|
+
runId: z.ZodString;
|
|
9
|
+
callId: z.ZodString;
|
|
7
10
|
}, z.core.$strip>;
|
|
8
11
|
/**
|
|
9
12
|
* The generated initial password of an account the super admin's agent created (Platform tool
|
|
10
|
-
* spec §14.5 item 2): shown once, on the web, to the person
|
|
11
|
-
* call. A POST because reading consumes it.
|
|
13
|
+
* spec §14.5 item 2): shown once, on the web, to the person the `accounts.create` call was made
|
|
14
|
+
* for, keyed by the call (plan ruling R6). A POST because reading consumes it.
|
|
12
15
|
*/
|
|
13
16
|
export declare class InitialPasswordsController {
|
|
14
17
|
private readonly passwords;
|
|
15
18
|
constructor(passwords: InitialPasswords);
|
|
16
|
-
reveal(principal: Principal, org: OrgContext, params: z.infer<typeof
|
|
19
|
+
reveal(principal: Principal, org: OrgContext, params: z.infer<typeof RevealCallParams>): Promise<{
|
|
17
20
|
accountId: string;
|
|
18
21
|
login: string | null;
|
|
19
22
|
password: string;
|
|
20
23
|
}>;
|
|
21
24
|
}
|
|
22
|
-
export {};
|
|
@@ -14,13 +14,18 @@ import { ZParam } from "../infra/validation/zod-params.js";
|
|
|
14
14
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
15
15
|
import { InitialPasswords } from "./initial-passwords.js";
|
|
16
16
|
import { CurrentPrincipal, requireUser, SessionOnly, SuperAdmin, } from "./principal.js";
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/** The tool call a once-shown value was made by. */
|
|
18
|
+
export const RevealCallParams = z.object({
|
|
19
|
+
conversationId: z.string().min(1).max(100),
|
|
20
|
+
runId: z.string().min(1).max(100),
|
|
21
|
+
callId: z.string().min(1).max(200),
|
|
22
|
+
});
|
|
23
|
+
class RevealCallParamsDto extends createZodDto(RevealCallParams, "InitialPasswordParams") {
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* The generated initial password of an account the super admin's agent created (Platform tool
|
|
22
|
-
* spec §14.5 item 2): shown once, on the web, to the person
|
|
23
|
-
* call. A POST because reading consumes it.
|
|
27
|
+
* spec §14.5 item 2): shown once, on the web, to the person the `accounts.create` call was made
|
|
28
|
+
* for, keyed by the call (plan ruling R6). A POST because reading consumes it.
|
|
24
29
|
*/
|
|
25
30
|
let InitialPasswordsController = class InitialPasswordsController {
|
|
26
31
|
passwords;
|
|
@@ -29,7 +34,8 @@ let InitialPasswordsController = class InitialPasswordsController {
|
|
|
29
34
|
}
|
|
30
35
|
async reveal(principal, org, params) {
|
|
31
36
|
const p = requireUser(principal);
|
|
32
|
-
|
|
37
|
+
const { conversationId, runId, callId } = params;
|
|
38
|
+
return this.passwords.reveal(org.orgId, { conversationId, runId, callId }, p.account.id);
|
|
33
39
|
}
|
|
34
40
|
};
|
|
35
41
|
__decorate([
|
|
@@ -40,10 +46,10 @@ __decorate([
|
|
|
40
46
|
SessionOnly(),
|
|
41
47
|
__param(0, CurrentPrincipal()),
|
|
42
48
|
__param(1, CurrentOrg()),
|
|
43
|
-
__param(2, ZParam(
|
|
49
|
+
__param(2, ZParam(RevealCallParamsDto))
|
|
44
50
|
], InitialPasswordsController.prototype, "reveal", null);
|
|
45
51
|
InitialPasswordsController = __decorate([
|
|
46
|
-
Controller("api/v1/orgs/:orgId/
|
|
52
|
+
Controller("api/v1/orgs/:orgId/conversations/:conversationId/runs/:runId/calls/:callId/initial-password"),
|
|
47
53
|
__param(0, Inject(InitialPasswords))
|
|
48
54
|
], InitialPasswordsController);
|
|
49
55
|
export { InitialPasswordsController };
|
|
@@ -4,28 +4,36 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
4
4
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
5
5
|
import { type Account, AccountsService } from "./accounts.js";
|
|
6
6
|
/**
|
|
7
|
-
* How long a generated password waits for its reader. The
|
|
8
|
-
* the call runs; one that is never read expires (the account can still be disabled
|
|
7
|
+
* How long a generated password waits for its reader. The person the call was made for reads it
|
|
8
|
+
* right after the call runs; one that is never read expires (the account can still be disabled
|
|
9
|
+
* and recreated).
|
|
9
10
|
*/
|
|
10
11
|
export declare const INITIAL_PASSWORD_TTL_MS: number;
|
|
11
|
-
/** The tool key of the approval a generated password belongs to. */
|
|
12
|
-
export declare const CREATE_ACCOUNT_TOOL_KEY = "Platform:accounts.create";
|
|
13
12
|
/** A one-time initial password, cryptographically random. */
|
|
14
13
|
export declare function generateInitialPassword(): string;
|
|
15
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* The tool call a once-shown value (an initial password, an invitation link) was made by: a call
|
|
16
|
+
* id is unique only within its run.
|
|
17
|
+
*/
|
|
18
|
+
export interface RevealCall {
|
|
19
|
+
conversationId: string;
|
|
20
|
+
runId: string;
|
|
21
|
+
callId: string;
|
|
22
|
+
}
|
|
23
|
+
/** Where a generated password is delivered: the tool call and the person it was made for. */
|
|
16
24
|
export interface InitialPasswordDelivery {
|
|
17
25
|
conversationId: string;
|
|
18
26
|
/** The run of the call: a call id is unique only within its run. */
|
|
19
27
|
runId: string;
|
|
20
28
|
callId: string;
|
|
21
|
-
/** The account that may read it: the
|
|
29
|
+
/** The account that may read it: the person the call was made for (the run's own person). */
|
|
22
30
|
recipientAccountId: string;
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
25
33
|
* Accounts created with a kernel-generated one-time password (Platform tool spec §14.5 item 2).
|
|
26
34
|
* The password never leaves the kernel except through {@link reveal}: it is not returned to the
|
|
27
35
|
* caller, not written to the audit, the event log or the logs. It is sealed with the master keyring
|
|
28
|
-
* in the creation's transaction and read once, on the web, by the person
|
|
36
|
+
* in the creation's transaction and read once, on the web, by the person the call was made for.
|
|
29
37
|
*/
|
|
30
38
|
export declare class InitialPasswords {
|
|
31
39
|
private readonly db;
|
|
@@ -45,13 +53,14 @@ export declare class InitialPasswords {
|
|
|
45
53
|
/** Stores the sealed password in the creation's transaction (the hourly job drops expired ones). */
|
|
46
54
|
private seal;
|
|
47
55
|
/**
|
|
48
|
-
* The password created by an
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* the
|
|
56
|
+
* The password created by an `accounts.create` call (`call` in `orgId`), read once by its
|
|
57
|
+
* recipient `accountId` while the call's conversation is still accessible to them, then deleted
|
|
58
|
+
* (plan ruling R6: read by call, whether the call ran under an approval or automatically).
|
|
59
|
+
* Anything else (not the recipient, the conversation not accessible, not run yet, read already,
|
|
60
|
+
* expired) is `account.initial_password_unavailable`, saying nothing about which. Audits the read
|
|
61
|
+
* (without the password).
|
|
53
62
|
*/
|
|
54
|
-
reveal(orgId: string,
|
|
63
|
+
reveal(orgId: string, call: RevealCall, accountId: string): Promise<{
|
|
55
64
|
accountId: string;
|
|
56
65
|
login: string | null;
|
|
57
66
|
password: string;
|