@capybara-hq/kernel 0.1.0-rc.128 → 0.1.0-rc.129
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/admin/admin.schemas.d.ts +14 -0
- package/dist/automations/automations.service.js +15 -21
- package/dist/automations/effective-settings.d.ts +3 -9
- package/dist/automations/effective-settings.js +3 -5
- package/dist/automations/fire.js +0 -11
- package/dist/automations/grant-rules.d.ts +7 -10
- package/dist/automations/grant-rules.js +9 -18
- package/dist/automations/unattended.d.ts +1 -4
- package/dist/automations/unattended.js +0 -2
- package/dist/catalog/org-extension.controller.d.ts +1 -20
- package/dist/catalog/org-extension.controller.js +1 -48
- package/dist/catalog/org-extension.schemas.d.ts +1 -9
- package/dist/catalog/org-extension.schemas.js +1 -17
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +16 -0
- package/dist/conversations/approval-profile.d.ts +8 -1
- package/dist/conversations/approval-profile.js +20 -0
- package/dist/conversations/conversations.service.d.ts +1 -1
- package/dist/conversations/conversations.service.js +8 -3
- package/dist/conversations/events.d.ts +25 -1
- package/dist/conversations/events.js +7 -2
- package/dist/conversations/permission-profiles.controller.d.ts +4 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +5 -0
- package/dist/conversations/permission-profiles.schemas.js +8 -0
- package/dist/conversations/permission-profiles.service.d.ts +8 -1
- package/dist/conversations/permission-profiles.service.js +13 -1
- package/dist/db/kernel-schema.d.ts +21 -0
- package/dist/device-access/device-access.service.d.ts +4 -1
- package/dist/device-access/device-access.service.js +26 -7
- package/dist/device-access/viewer.d.ts +3 -1
- package/dist/device-access/viewer.js +18 -9
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +6 -0
- package/dist/git/gateway.d.ts +8 -1
- package/dist/git/gateway.js +68 -11
- package/dist/git/git.module.d.ts +2 -3
- package/dist/git/git.module.js +4 -4
- package/dist/http/api.module.js +3 -3
- package/dist/identity/settings.d.ts +20 -5
- package/dist/identity/settings.js +52 -9
- package/dist/infra/config/kernel-config.service.js +4 -0
- package/dist/orgs/orgs.module.js +12 -1
- package/dist/orgs/orgs.schemas.js +3 -0
- package/dist/orgs/security-settings.service.d.ts +94 -0
- package/dist/orgs/security-settings.service.js +223 -0
- package/dist/orgs/settings.controller.d.ts +33 -0
- package/dist/orgs/settings.controller.js +41 -1
- package/dist/orgs/settings.service.d.ts +48 -63
- package/dist/orgs/settings.service.js +86 -103
- package/dist/platform/exclusions.js +1 -1
- package/dist/platform/operation.js +4 -0
- package/dist/platform/ops/admin.ops.js +18 -4
- package/dist/platform/ops/connectors.ops.js +2 -2
- package/dist/platform/ops/extensions.ops.d.ts +1 -3
- package/dist/platform/ops/extensions.ops.js +4 -131
- package/dist/platform/ops/org-settings.ops.d.ts +3 -1
- package/dist/platform/ops/org-settings.ops.js +76 -3
- package/dist/platform/ops/orgs.ops.js +2 -0
- package/dist/runtime/context/permission-profile.js +6 -0
- package/dist/runtime/subagents/dispatch.d.ts +3 -0
- package/dist/runtime/subagents/dispatch.js +2 -1
- package/dist/runtime/subagents/messages.d.ts +3 -1
- package/dist/runtime/subagents/messages.js +9 -6
- package/dist/sandbox/device-sandbox-settings.d.ts +55 -1
- package/dist/sandbox/device-sandbox-settings.js +64 -1
- package/dist/sandbox/device-sandbox.d.ts +9 -1
- package/dist/sandbox/device-sandbox.js +17 -2
- package/dist/sandbox/device-services.d.ts +26 -3
- package/dist/sandbox/device-services.js +95 -16
- package/dist/sandbox/loopback-grant-records.d.ts +3 -2
- package/dist/sandbox/loopback-grant-records.js +32 -5
- package/dist/sandbox/operation-authority.d.ts +3 -2
- package/dist/sandbox/operation-authority.js +21 -1
- package/dist/sandbox/operation-intents.js +5 -1
- package/dist/sandbox/permission-call-types.d.ts +2 -1
- package/dist/sandbox/permission-ceiling-writes.d.ts +14 -5
- package/dist/sandbox/permission-ceiling-writes.js +122 -13
- package/dist/sandbox/permission-config-publication.d.ts +10 -0
- package/dist/sandbox/permission-config-publication.js +27 -5
- package/dist/sandbox/permission-facts.d.ts +21 -2
- package/dist/sandbox/permission-facts.js +101 -9
- package/dist/sandbox/permission-transitions.d.ts +1 -1
- package/dist/sandbox/sandbox.service.d.ts +2 -2
- package/dist/sandbox/sandbox.service.js +7 -3
- package/dist/tools/admin-connectors.js +2 -2
- package/dist/tools/approvals.service.d.ts +7 -2
- package/dist/tools/approvals.service.js +39 -7
- package/dist/tools/builtin-names.d.ts +0 -6
- package/dist/tools/builtin-names.js +0 -11
- package/dist/tools/builtins/sandbox/index.d.ts +3 -5
- package/dist/tools/builtins/sandbox/index.js +3 -5
- package/dist/tools/connector-account-policies.js +7 -4
- package/dist/tools/connectors.controller.d.ts +0 -6
- package/dist/tools/connectors.schemas.d.ts +1 -8
- package/dist/tools/connectors.schemas.js +1 -4
- package/dist/tools/connectors.service.d.ts +3 -7
- package/dist/tools/connectors.service.js +29 -44
- package/dist/tools/drift.js +12 -4
- package/dist/tools/git-push-policy.d.ts +1 -4
- package/dist/tools/git-push-policy.js +4 -5
- package/dist/tools/org-tool-policies.d.ts +24 -0
- package/dist/tools/org-tool-policies.js +113 -0
- package/dist/tools/org-tool-switches.d.ts +5 -70
- package/dist/tools/org-tool-switches.js +13 -141
- package/dist/tools/pipeline.d.ts +11 -5
- package/dist/tools/pipeline.js +173 -38
- package/dist/tools/policy.d.ts +3 -7
- package/dist/tools/policy.js +29 -48
- package/dist/tools/registry.d.ts +5 -0
- package/dist/tools/registry.js +44 -13
- package/package.json +1 -1
- package/src/migrations/0212_org_security_policy.sql +234 -0
|
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { EXTENSION_POINTS, parseExtensionPoint } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { z } from "zod";
|
|
13
|
-
import { OrgExtensionParams, OrgExtensionPut,
|
|
13
|
+
import { OrgExtensionParams, OrgExtensionPut, OrgOverridesPut, OrgOverridesTake, } from "../../catalog/org-extension.schemas.js";
|
|
14
14
|
import { ApiError } from "../../errors.js";
|
|
15
15
|
import { ExtensionDisplayNames } from "../../extensions/display-name.js";
|
|
16
16
|
import { listedInOrg, OrgExtensionConfigs, pluginNotInstalledError, providesOf, } from "../../extensions/org-config.js";
|
|
@@ -19,7 +19,6 @@ import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
|
|
|
19
19
|
import { ExtensionPointDefaultBody, ExtensionPointParams, } from "../../extensions/point-defaults.schemas.js";
|
|
20
20
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
21
21
|
import { can } from "../../orgs/roles.js";
|
|
22
|
-
import { OrgToolSwitches } from "../../tools/org-tool-switches.js";
|
|
23
22
|
import { resolveNext } from "../errors.js";
|
|
24
23
|
import { defineOperation } from "../operation.js";
|
|
25
24
|
import { personFieldParams, secretFieldsOf } from "../person-fields.js";
|
|
@@ -32,8 +31,6 @@ import { localized, named, orElse } from "./summary.js";
|
|
|
32
31
|
import { roleFor, unavailableFields } from "./unavailable.js";
|
|
33
32
|
const NoInput = z.object({}).strict();
|
|
34
33
|
const Extension = OrgExtensionParams.shape.extension;
|
|
35
|
-
const Tool = OrgExtensionToolParams.shape.tool;
|
|
36
|
-
const SwitchConfirm = OrgToolSwitchPut.shape.confirm.unwrap();
|
|
37
34
|
const Force = OrgExtensionPut.shape.force;
|
|
38
35
|
/** The next step of an extension that needs its org config. */
|
|
39
36
|
const NEEDS_ORG_CONFIG = {
|
|
@@ -90,15 +87,13 @@ let ExtensionsOperations = class ExtensionsOperations {
|
|
|
90
87
|
configs;
|
|
91
88
|
displayNames;
|
|
92
89
|
kdb;
|
|
93
|
-
switches;
|
|
94
90
|
pointDefaults;
|
|
95
91
|
overrides;
|
|
96
|
-
constructor(registry, configs, displayNames, kdb,
|
|
92
|
+
constructor(registry, configs, displayNames, kdb, pointDefaults, overrides) {
|
|
97
93
|
this.registry = registry;
|
|
98
94
|
this.configs = configs;
|
|
99
95
|
this.displayNames = displayNames;
|
|
100
96
|
this.kdb = kdb;
|
|
101
|
-
this.switches = switches;
|
|
102
97
|
this.pointDefaults = pointDefaults;
|
|
103
98
|
this.overrides = overrides;
|
|
104
99
|
}
|
|
@@ -256,127 +251,6 @@ let ExtensionsOperations = class ExtensionsOperations {
|
|
|
256
251
|
};
|
|
257
252
|
},
|
|
258
253
|
}),
|
|
259
|
-
defineOperation({
|
|
260
|
-
id: "extensions.tools",
|
|
261
|
-
description: "List the tools an extension registers, each with this org's switch (on unless an org admin turned it off).",
|
|
262
|
-
input: z.object({ extension: Extension }).strict(),
|
|
263
|
-
example: { extension: "todo" },
|
|
264
|
-
authz: { orgAction: "org.extensions.read" },
|
|
265
|
-
mirrors: ["GET /api/v1/orgs/:orgId/extensions/:extension/tools"],
|
|
266
|
-
confirm: "read",
|
|
267
|
-
errors: [
|
|
268
|
-
{
|
|
269
|
-
code: "extension.not_found",
|
|
270
|
-
next: "The extension is not running or not visible to this org; check the name with extensions.list.",
|
|
271
|
-
},
|
|
272
|
-
],
|
|
273
|
-
run: async (input, ctx) => ({
|
|
274
|
-
tools: await this.switches.list(ctx.orgId, input.extension),
|
|
275
|
-
}),
|
|
276
|
-
}),
|
|
277
|
-
defineOperation({
|
|
278
|
-
id: "extensions.tool-disable-preview",
|
|
279
|
-
description: "Preview turning one extension tool off in this org (org admins): the org's agents that have it (every agent that does not turn it off), and the confirm value extensions.set-tool-enabled needs. Show the preview to the person before turning it off.",
|
|
280
|
-
input: z.object({ extension: Extension, tool: Tool }).strict(),
|
|
281
|
-
example: { extension: "todo", tool: "add_item" },
|
|
282
|
-
// the web previews through the switch route itself (no confirm); writes nothing here
|
|
283
|
-
authz: { orgAction: "org.extensions.manage" },
|
|
284
|
-
mirrors: [],
|
|
285
|
-
confirm: "read",
|
|
286
|
-
errors: [
|
|
287
|
-
{
|
|
288
|
-
code: "extension.not_found",
|
|
289
|
-
next: "The extension is not running or not visible to this org; check the name with extensions.list.",
|
|
290
|
-
},
|
|
291
|
-
{ code: "extension.tool_not_found", next: "Check the tool names with extensions.tools." },
|
|
292
|
-
],
|
|
293
|
-
run: async (input, ctx) => {
|
|
294
|
-
const p = await this.switches.previewOff(ctx.orgId, input.extension, input.tool);
|
|
295
|
-
return p === null
|
|
296
|
-
? { preview: null, next: "The tool is off in this org already." }
|
|
297
|
-
: { affectedAgents: p.affectedAgents, confirm: p.confirm };
|
|
298
|
-
},
|
|
299
|
-
}),
|
|
300
|
-
defineOperation({
|
|
301
|
-
id: "extensions.set-tool-enabled",
|
|
302
|
-
description: "Turn one extension tool on or off in this org (org admins). Turning on applies at once; turning off needs confirm: the value extensions.tool-disable-preview returned with the preview the person saw.",
|
|
303
|
-
input: z.discriminatedUnion("enabled", [
|
|
304
|
-
z.object({ extension: Extension, tool: Tool, enabled: z.literal(true) }).strict(),
|
|
305
|
-
z
|
|
306
|
-
.object({
|
|
307
|
-
extension: Extension,
|
|
308
|
-
tool: Tool,
|
|
309
|
-
enabled: z.literal(false),
|
|
310
|
-
confirm: SwitchConfirm,
|
|
311
|
-
})
|
|
312
|
-
.strict(),
|
|
313
|
-
]),
|
|
314
|
-
example: { extension: "todo", tool: "add_item", enabled: true },
|
|
315
|
-
authz: { orgAction: "org.extensions.manage" },
|
|
316
|
-
mirrors: ["PUT /api/v1/orgs/:orgId/extensions/:extension/tools/:tool"],
|
|
317
|
-
confirm: "org",
|
|
318
|
-
errors: [
|
|
319
|
-
{
|
|
320
|
-
code: "extension.not_found",
|
|
321
|
-
next: "The extension is not running or not visible to this org; check the name with extensions.list.",
|
|
322
|
-
},
|
|
323
|
-
{ code: "extension.tool_not_found", next: "Check the tool names with extensions.tools." },
|
|
324
|
-
{
|
|
325
|
-
code: "plugin.switch_stale",
|
|
326
|
-
next: "What turning it off affects changed: call extensions.tool-disable-preview again, show it, and call again with the new confirm value.",
|
|
327
|
-
},
|
|
328
|
-
],
|
|
329
|
-
precheck: async (i, ctx) => {
|
|
330
|
-
if (i.enabled) {
|
|
331
|
-
let tools = [];
|
|
332
|
-
const r = await precheckBy(async () => {
|
|
333
|
-
tools = await this.switches.list(ctx.orgId, i.extension);
|
|
334
|
-
});
|
|
335
|
-
if (!r.ok)
|
|
336
|
-
return r;
|
|
337
|
-
return tools.some((t) => t.tool === i.tool)
|
|
338
|
-
? { ok: true }
|
|
339
|
-
: {
|
|
340
|
-
ok: false,
|
|
341
|
-
code: "extension.tool_not_found",
|
|
342
|
-
message: `Extension ${i.extension} does not register a tool named ${i.tool}`,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
let confirm = null;
|
|
346
|
-
const r = await precheckBy(async () => {
|
|
347
|
-
confirm =
|
|
348
|
-
(await this.switches.previewOff(ctx.orgId, i.extension, i.tool))?.confirm ?? null;
|
|
349
|
-
});
|
|
350
|
-
if (!r.ok)
|
|
351
|
-
return r;
|
|
352
|
-
return confirm === null || confirm === i.confirm
|
|
353
|
-
? { ok: true }
|
|
354
|
-
: {
|
|
355
|
-
ok: false,
|
|
356
|
-
code: "plugin.switch_stale",
|
|
357
|
-
message: "What turning this tool off affects has changed since the preview",
|
|
358
|
-
};
|
|
359
|
-
},
|
|
360
|
-
summary: async (i, ctx) => {
|
|
361
|
-
const x = await this.nameOf(i.extension);
|
|
362
|
-
if (i.enabled) {
|
|
363
|
-
return {
|
|
364
|
-
zh: `在本组织开启扩展「${x.zh}」的工具 ${named(i.tool)}`,
|
|
365
|
-
en: `Turn on tool ${named(i.tool)} of extension "${x.en}" in the org`,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
const p = await this.switches.previewOff(ctx.orgId, i.extension, i.tool);
|
|
369
|
-
const n = p?.affectedAgents.length ?? 0;
|
|
370
|
-
return {
|
|
371
|
-
zh: `在本组织关闭扩展「${x.zh}」的工具 ${named(i.tool)}:${n} 个智能体选用了它`,
|
|
372
|
-
en: `Turn off tool ${named(i.tool)} of extension "${x.en}" in the org: ${n} agents selected it`,
|
|
373
|
-
};
|
|
374
|
-
},
|
|
375
|
-
run: async (input, ctx) => this.switches.set(ctx.orgId, input.extension, input.tool, input.enabled, {
|
|
376
|
-
accountId: ctx.actorAccountId,
|
|
377
|
-
auditDetail: viaAgent("extensions.set-tool-enabled", ctx),
|
|
378
|
-
}, input.enabled ? undefined : input.confirm),
|
|
379
|
-
}),
|
|
380
254
|
defineOperation({
|
|
381
255
|
id: "extensions.org-config",
|
|
382
256
|
description: "Read an extension's config in this org (org admins): configurable (it has fields the org can override) and needsConfig (its config for this org is not valid); deploymentCopy is the org's side of the platform's deployment config: following the platform or a copy, the overridable fields (platform values, the copy's values, secrets as set or not, never a value) and whether the effective config is valid. deploymentCopy is null when the extension does not run on the platform.",
|
|
@@ -646,8 +520,7 @@ ExtensionsOperations = __decorate([
|
|
|
646
520
|
__param(1, Inject(OrgExtensionConfigs)),
|
|
647
521
|
__param(2, Inject(ExtensionDisplayNames)),
|
|
648
522
|
__param(3, Inject(KernelDb)),
|
|
649
|
-
__param(4, Inject(
|
|
650
|
-
__param(5, Inject(
|
|
651
|
-
__param(6, Inject(OrgOverrides))
|
|
523
|
+
__param(4, Inject(ExtensionPointDefaults)),
|
|
524
|
+
__param(5, Inject(OrgOverrides))
|
|
652
525
|
], ExtensionsOperations);
|
|
653
526
|
export { ExtensionsOperations };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
2
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
3
|
+
import { OrgSecuritySettingsService } from "../../orgs/security-settings.service.js";
|
|
3
4
|
import { OrgSettingsService } from "../../orgs/settings.service.js";
|
|
4
5
|
import { ThemesService } from "../../themes/themes.service.js";
|
|
5
6
|
import { PlatformOperations } from "../registry.js";
|
|
@@ -15,6 +16,7 @@ export declare class OrgSettingsOperations implements OnModuleInit {
|
|
|
15
16
|
private readonly settings;
|
|
16
17
|
private readonly themes;
|
|
17
18
|
private readonly db;
|
|
18
|
-
|
|
19
|
+
private readonly security;
|
|
20
|
+
constructor(registry: PlatformOperations, settings: OrgSettingsService, themes: ThemesService, db: KernelDb, security: OrgSecuritySettingsService);
|
|
19
21
|
onModuleInit(): void;
|
|
20
22
|
}
|
|
@@ -9,7 +9,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
+
import { ApiError } from "../../errors.js";
|
|
12
13
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
14
|
+
import { OrgSecurityPatchSchema, OrgSecurityQuerySchema, OrgSecuritySettingsService, } from "../../orgs/security-settings.service.js";
|
|
13
15
|
import { OrgSettingsPatchSchema, OrgSettingsService } from "../../orgs/settings.service.js";
|
|
14
16
|
import { ThemesService } from "../../themes/themes.service.js";
|
|
15
17
|
import { defineOperation } from "../operation.js";
|
|
@@ -33,17 +35,87 @@ let OrgSettingsOperations = class OrgSettingsOperations {
|
|
|
33
35
|
settings;
|
|
34
36
|
themes;
|
|
35
37
|
db;
|
|
36
|
-
|
|
38
|
+
security;
|
|
39
|
+
constructor(registry, settings, themes, db, security) {
|
|
37
40
|
this.registry = registry;
|
|
38
41
|
this.settings = settings;
|
|
39
42
|
this.themes = themes;
|
|
40
43
|
this.db = db;
|
|
44
|
+
this.security = security;
|
|
41
45
|
}
|
|
42
46
|
onModuleInit() {
|
|
43
47
|
this.registry.register([
|
|
48
|
+
defineOperation({
|
|
49
|
+
id: "org-security.get",
|
|
50
|
+
description: "Read organization security ceilings and a page of canonical tool policies. Pass nextCursor as cursor to continue.",
|
|
51
|
+
input: OrgSecurityQuerySchema,
|
|
52
|
+
example: { limit: 50 },
|
|
53
|
+
authz: { orgAction: "org.update" },
|
|
54
|
+
mirrors: ["GET /api/v1/orgs/:orgId/settings/security"],
|
|
55
|
+
confirm: "read",
|
|
56
|
+
run: (input, ctx) => this.security.view(ctx.orgId, input),
|
|
57
|
+
}),
|
|
58
|
+
defineOperation({
|
|
59
|
+
id: "org-security.update",
|
|
60
|
+
description: "Narrow organization tool policy, unattended Git push denials, allowed permission profiles or project reach. Use the revision from org-security.get. Widen in the organization security settings on the web.",
|
|
61
|
+
input: OrgSecurityPatchSchema,
|
|
62
|
+
example: {
|
|
63
|
+
expectedRevision: "0".repeat(64),
|
|
64
|
+
tools: [{ toolKey: "Bash", policy: "ask", unattendedPolicy: "deny" }],
|
|
65
|
+
},
|
|
66
|
+
authz: { orgAction: "org.update" },
|
|
67
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/settings/security"],
|
|
68
|
+
confirm: "org",
|
|
69
|
+
summary: (input) => {
|
|
70
|
+
const count = (input.tools?.length ?? 0) + (input.gitPush?.length ?? 0);
|
|
71
|
+
return {
|
|
72
|
+
en: `Update organization security settings (${count} tool and Git rules)`,
|
|
73
|
+
zh: `修改组织安全设置(${count} 条工具及 Git 规则)`,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
errors: [
|
|
77
|
+
{
|
|
78
|
+
code: "org.security_revision_conflict",
|
|
79
|
+
next: "Run org-security.get again to get the latest revision.",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
code: "org.security_widening_not_allowed",
|
|
83
|
+
next: "Ask an organization admin to open /settings/security on the web.",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
code: "org.security_confirmation_required",
|
|
87
|
+
next: "Ask an organization admin to review the affected agents at /settings/security on the web.",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
run: async (input, ctx) => {
|
|
91
|
+
try {
|
|
92
|
+
return {
|
|
93
|
+
applied: true,
|
|
94
|
+
...(await this.security.update(ctx.orgId, input, ctx.actorAccountId, {
|
|
95
|
+
onlyNarrows: true,
|
|
96
|
+
auditDetail: viaAgent("org-security.update", ctx),
|
|
97
|
+
})),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof ApiError &&
|
|
102
|
+
(error.code === "org.security_widening_not_allowed" ||
|
|
103
|
+
error.code === "org.security_confirmation_required"))
|
|
104
|
+
return { applied: false, code: error.code, message: error.message };
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
handoff: (_input, result) => result?.applied === false
|
|
109
|
+
? {
|
|
110
|
+
kind: "handoff",
|
|
111
|
+
title: { en: "Review organization security", zh: "检查组织安全设置" },
|
|
112
|
+
target: { type: "link", url: "/settings/security" },
|
|
113
|
+
}
|
|
114
|
+
: null,
|
|
115
|
+
}),
|
|
44
116
|
defineOperation({
|
|
45
117
|
id: "org-settings.get",
|
|
46
|
-
description: "Read this org's settings: toolSearch, locale,
|
|
118
|
+
description: "Read this org's settings: toolSearch, locale, allowedProfiles and projectReach (edit these with org-security.update), platformTool (on, read-only or off), outsideSandbox (allowed or off: whether the org's devices may be granted running a call outside their sandbox; absent follows the deployment, and the org may never exceed it), deviceNetwork (the org's device sandbox network: default, the network a device gets when its owner chooses none, and ceiling, the widest a device may choose, each open or allowlist and absent following the platform; base platform or none; extraHosts the org adds; excludedHosts platform hosts it drops; open means any public host, while loopback, private and cloud metadata addresses stay closed), wakeOnBackgroundTask (absent means it follows the deployment), theme (the org's default theme id, null or absent following the platform, and personal: allowed or locked), navigation (pluginPages: per plugin page contribution key <extension>/<contribution>, the section primary or more an org admin chose; at most 3 primary; absent means every page follows its own suggestion), uiArrangement (per list slot, the extension contributions the org hides and their order; per single slot, the contribution that replaces the built-in as use, null for the built-in; a slot not listed follows the platform), the deployment's outside-sandbox switch (outsideSandbox) and device network (deviceNetwork: its default and ceiling, its allowlist, orgHosts: extend lets the org go beyond the allowlist, within makes it the hosts' ceiling, and off for the platform kill switch), effectiveNetwork (the mode and hosts the org's devices really get), externalSharing (on or off, absent meaning off: whether members may share conversation files through public links; the deployment's externalSharing must be allow too) with the deployment's externalSharing and shareMaxExpiryDays, promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) with the deployment's promptSuggestions, the sandbox cpu / memory limits in effect, and fileLibraryBytes (the org-wide storage total for org admins).",
|
|
47
119
|
input: z.object({}).strict(),
|
|
48
120
|
example: {},
|
|
49
121
|
authz: { orgAction: "org.read" },
|
|
@@ -151,6 +223,7 @@ OrgSettingsOperations = __decorate([
|
|
|
151
223
|
__param(0, Inject(PlatformOperations)),
|
|
152
224
|
__param(1, Inject(OrgSettingsService)),
|
|
153
225
|
__param(2, Inject(ThemesService)),
|
|
154
|
-
__param(3, Inject(KernelDb))
|
|
226
|
+
__param(3, Inject(KernelDb)),
|
|
227
|
+
__param(4, Inject(OrgSecuritySettingsService))
|
|
155
228
|
], OrgSettingsOperations);
|
|
156
229
|
export { OrgSettingsOperations };
|
|
@@ -144,12 +144,18 @@ export function permissionContextText(payload) {
|
|
|
144
144
|
`Permission context for new operations: ${p.availability.state === "supported" && p.effectiveProfile !== null ? labels[p.effectiveProfile] : "unavailable"}.`,
|
|
145
145
|
"This context supersedes earlier device-mode descriptions for new operations.",
|
|
146
146
|
];
|
|
147
|
+
if (p.allowedProfiles)
|
|
148
|
+
lines.push(`Permission profiles available in this organization: ${p.allowedProfiles.map((profile) => labels[profile]).join(", ")}.`);
|
|
147
149
|
if (s !== null) {
|
|
148
150
|
if (box !== null)
|
|
149
151
|
lines.push(box.boundary === "instance"
|
|
150
152
|
? "Sandbox: the same under every profile; the provisioned device instance is the sandbox, its whole filesystem is in scope and its outer network applies."
|
|
151
153
|
: "Sandbox: the same under every profile; new commands run in the device's OS sandbox, limited to the directories and network below.");
|
|
152
154
|
lines.push(`Working directory: ${permissionQuote(s.workingRoot)}.`);
|
|
155
|
+
if (box?.projectReach !== undefined)
|
|
156
|
+
lines.push(box.projectReach === "workspace"
|
|
157
|
+
? "Project reach is capped at the device workspace."
|
|
158
|
+
: "Project reach is capped at the device owner's approved paths.");
|
|
153
159
|
if (s.filesystem.kind === "scoped") {
|
|
154
160
|
lines.push("Readable files: set by this device's provider, not by the permission profile.", `Writable directories: ${arrayText(s.filesystem.writeDirectories)}.`);
|
|
155
161
|
}
|
|
@@ -33,12 +33,15 @@ export interface DispatchDeps {
|
|
|
33
33
|
*/
|
|
34
34
|
commitDispatch: (a: DispatchArgs, plan: DispatchPlan, child: ChildWriter) => Promise<DispatchCommit | null>;
|
|
35
35
|
}
|
|
36
|
+
/** Apply the tool admission fence to the one transaction that writes this dispatch. */
|
|
37
|
+
export type DispatchAdmission = <T>(commit: () => Promise<T>) => Promise<T>;
|
|
36
38
|
/** One dispatch's call. */
|
|
37
39
|
export interface DispatchArgs {
|
|
38
40
|
ctx: ToolStepContext;
|
|
39
41
|
callId: string;
|
|
40
42
|
input: AgentToolInputT;
|
|
41
43
|
forSkill?: SkillForkDispatch;
|
|
44
|
+
admit?: DispatchAdmission;
|
|
42
45
|
/**
|
|
43
46
|
* The `Agent` call's own record (not for a fork invocation): the logged key its `tool_result`
|
|
44
47
|
* keeps (the rc `agent` for a call logged before the rename), the `tool.called` audit's
|
|
@@ -493,7 +493,8 @@ export async function commit(d, a, plan,
|
|
|
493
493
|
/** Writes the child's events; `checked` is the org agent version the in-lock gates passed. */
|
|
494
494
|
child) {
|
|
495
495
|
const { ctx } = a;
|
|
496
|
-
const
|
|
496
|
+
const write = () => d.commitDispatch(a, plan, child);
|
|
497
|
+
const out = await (a.admit === undefined ? write() : a.admit(write));
|
|
497
498
|
if (out === null)
|
|
498
499
|
return null;
|
|
499
500
|
if (out.kind === "existing") {
|
|
@@ -6,6 +6,7 @@ import type { KernelLogger } from "../../log.js";
|
|
|
6
6
|
import type { ToolStepContext } from "../../tools/pipeline.js";
|
|
7
7
|
import { RunJobs } from "../run-jobs.js";
|
|
8
8
|
import { SubagentDeliveries } from "./deliveries.js";
|
|
9
|
+
import { type DispatchAdmission } from "./dispatch.js";
|
|
9
10
|
/** The message tools' test seams (`SUBAGENT_MESSAGES_HOOKS`; the kernel never provides them). */
|
|
10
11
|
export interface SubagentMessagesHooks {
|
|
11
12
|
/**
|
|
@@ -73,13 +74,14 @@ export declare class SubagentMessages {
|
|
|
73
74
|
/** The pipeline's record of why the call was allowed (the `tool.called` audit of a restart). */
|
|
74
75
|
opts?: {
|
|
75
76
|
authorization?: Record<string, unknown>;
|
|
77
|
+
admit?: DispatchAdmission;
|
|
76
78
|
}): Promise<MessageOutcome>;
|
|
77
79
|
/**
|
|
78
80
|
* A sub-agent's note (`SendMessage` to `"parent"`) or report (`SubagentHandback`) to its parent
|
|
79
81
|
* (agent map spec §4.3, §5.2): one `subagent_delivery` of this run in the parent's log,
|
|
80
82
|
* idempotent by the call; an active parent run absorbs it, an idle parent is woken.
|
|
81
83
|
*/
|
|
82
|
-
toParent(ctx: ToolStepContext, kind: "note" | "report", text: string, callId: string): Promise<MessageOutcome>;
|
|
84
|
+
toParent(ctx: ToolStepContext, kind: "note" | "report", text: string, callId: string, admit?: DispatchAdmission): Promise<MessageOutcome>;
|
|
83
85
|
/**
|
|
84
86
|
* Appends the message to a sub-agent whose run is active, under its row lock (a run's terminal
|
|
85
87
|
* write takes the same lock, so the run is still active when the message lands). Null when no
|
|
@@ -100,7 +100,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
100
100
|
/** The pipeline's record of why the call was allowed (the `tool.called` audit of a restart). */
|
|
101
101
|
opts = {}) {
|
|
102
102
|
if (childId === PARENT_TARGET && ctx.parent !== undefined) {
|
|
103
|
-
return this.toParent(ctx, "note", text, callId);
|
|
103
|
+
return this.toParent(ctx, "note", text, callId, opts.admit);
|
|
104
104
|
}
|
|
105
105
|
const child = await this.db
|
|
106
106
|
.selectFrom("conversations")
|
|
@@ -149,7 +149,8 @@ let SubagentMessages = class SubagentMessages {
|
|
|
149
149
|
const active = prior === undefined && (await this.activeRunOf(child.id)) !== undefined;
|
|
150
150
|
await this.hooks?.afterStatusRead?.(child.id);
|
|
151
151
|
if (active) {
|
|
152
|
-
const
|
|
152
|
+
const write = () => this.appendToRunning(ctx, callId, child.id, text, narrowFollowUp(frozen, current));
|
|
153
|
+
const seq = await (opts.admit === undefined ? write() : opts.admit(write));
|
|
153
154
|
if (seq !== null) {
|
|
154
155
|
await this.eventLog.notify(child.id, seq);
|
|
155
156
|
return { content: sentToRunningText(target), isError: false };
|
|
@@ -165,7 +166,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
165
166
|
resumed: true,
|
|
166
167
|
model: started.payload.definition.model,
|
|
167
168
|
tierFallback: false,
|
|
168
|
-
}, frozen);
|
|
169
|
+
}, frozen, opts.admit);
|
|
169
170
|
if (out === "active")
|
|
170
171
|
continue;
|
|
171
172
|
return out;
|
|
@@ -177,7 +178,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
177
178
|
* (agent map spec §4.3, §5.2): one `subagent_delivery` of this run in the parent's log,
|
|
178
179
|
* idempotent by the call; an active parent run absorbs it, an idle parent is woken.
|
|
179
180
|
*/
|
|
180
|
-
async toParent(ctx, kind, text, callId) {
|
|
181
|
+
async toParent(ctx, kind, text, callId, admit) {
|
|
181
182
|
if (ctx.parent === undefined)
|
|
182
183
|
return refused(HANDBACK_NOT_A_CHILD_TEXT);
|
|
183
184
|
const row = await deliveryRowOfChildRun(this.db, ctx.runId);
|
|
@@ -186,7 +187,8 @@ let SubagentMessages = class SubagentMessages {
|
|
|
186
187
|
// a fork invocation's parent run waits for the final reply (phase D, agent map spec §5.4)
|
|
187
188
|
if (row.forSkill === true)
|
|
188
189
|
return refused(HANDBACK_FORK_TEXT);
|
|
189
|
-
|
|
190
|
+
const write = () => this.deliveries.deliverIn(row, { kind, text }, { idemKey: toParentIdemKey(ctx.runId, callId) });
|
|
191
|
+
await (admit === undefined ? write() : admit(write));
|
|
190
192
|
return {
|
|
191
193
|
content: kind === "report" ? HANDBACK_RESULT_TEXT : SENT_TO_PARENT_TEXT,
|
|
192
194
|
isError: false,
|
|
@@ -217,11 +219,12 @@ let SubagentMessages = class SubagentMessages {
|
|
|
217
219
|
* is locked only after no active run was found, and again checked under the lock. `"active"`
|
|
218
220
|
* when a run is active after all (the caller appends to it instead).
|
|
219
221
|
*/
|
|
220
|
-
async restart(ctx, callId, text, target, authorization, plan, frozen) {
|
|
222
|
+
async restart(ctx, callId, text, target, authorization, plan, frozen, admit) {
|
|
221
223
|
const a = {
|
|
222
224
|
ctx,
|
|
223
225
|
callId,
|
|
224
226
|
input: { description: target.description || target.id, prompt: text },
|
|
227
|
+
...(admit !== undefined && { admit }),
|
|
225
228
|
call: {
|
|
226
229
|
toolKey: SEND_MESSAGE,
|
|
227
230
|
authorization: authorization ?? { policy: "allow" },
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type DeviceProjectReach, type PermissionProfile } from "@capybara-hq/plugin-sdk";
|
|
1
2
|
import { z } from "zod";
|
|
3
|
+
import { AllowedProfilesSchema } from "../conversations/permission-profiles.schemas.js";
|
|
2
4
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
5
|
import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
4
6
|
import type { KernelLogger } from "../log.js";
|
|
@@ -13,6 +15,29 @@ import type { DeviceNetworkMode, DeviceSandboxSettings } from "./device-sandbox.
|
|
|
13
15
|
* admin console. An invalid stored value reads narrower with a warning (fail closed): `off`, and
|
|
14
16
|
* the allowlist.
|
|
15
17
|
*/
|
|
18
|
+
export { AllowedProfilesSchema };
|
|
19
|
+
export declare const ProjectReachSchema: z.ZodEnum<{
|
|
20
|
+
machine: "machine";
|
|
21
|
+
paths: "paths";
|
|
22
|
+
workspace: "workspace";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const DEVICES_ALLOWED_PROFILES_SETTING = "devicesAllowedProfiles";
|
|
25
|
+
export declare const DEVICES_PROJECT_REACH_SETTING = "devicesProjectReach";
|
|
26
|
+
export declare const DEFAULT_ALLOWED_PROFILES: ("approve-for-me" | "full-access" | "request-approval")[];
|
|
27
|
+
export declare const DEVICES_ALLOWED_PROFILES_PATCH: z.ZodObject<{
|
|
28
|
+
value: z.ZodNullable<z.ZodPipe<z.ZodArray<z.ZodEnum<{
|
|
29
|
+
"approve-for-me": "approve-for-me";
|
|
30
|
+
"full-access": "full-access";
|
|
31
|
+
"request-approval": "request-approval";
|
|
32
|
+
}>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>;
|
|
33
|
+
}, z.core.$strict>;
|
|
34
|
+
export declare const DEVICES_PROJECT_REACH_PATCH: z.ZodObject<{
|
|
35
|
+
ceiling: z.ZodNullable<z.ZodEnum<{
|
|
36
|
+
machine: "machine";
|
|
37
|
+
paths: "paths";
|
|
38
|
+
workspace: "workspace";
|
|
39
|
+
}>>;
|
|
40
|
+
}, z.core.$strict>;
|
|
16
41
|
export type OutsideSandboxPermission = "allowed" | "off";
|
|
17
42
|
/** The `deployment_settings` key of the super admin's outside-sandbox choice. */
|
|
18
43
|
export declare const DEVICES_OUTSIDE_SANDBOX_SETTING = "devicesOutsideSandbox";
|
|
@@ -44,6 +69,8 @@ export type DevicesNetworkStored = z.infer<typeof DevicesNetworkStoredSchema>;
|
|
|
44
69
|
export interface StoredDeviceSandbox {
|
|
45
70
|
outsideSandbox: DevicesOutsideSandboxStored;
|
|
46
71
|
network: DevicesNetworkStored;
|
|
72
|
+
allowedProfiles?: PermissionProfile[] | undefined;
|
|
73
|
+
projectReach?: DeviceProjectReach | undefined;
|
|
47
74
|
}
|
|
48
75
|
/**
|
|
49
76
|
* A change of the stored outside-sandbox choice (`PUT /api/v1/admin/settings`
|
|
@@ -88,19 +115,35 @@ export interface DevicesNetworkView {
|
|
|
88
115
|
ceiling: DeviceSandboxSource;
|
|
89
116
|
};
|
|
90
117
|
}
|
|
118
|
+
export interface AllowedProfilesView {
|
|
119
|
+
value: PermissionProfile[];
|
|
120
|
+
source: DeviceSandboxSource;
|
|
121
|
+
}
|
|
122
|
+
export interface ProjectReachView {
|
|
123
|
+
ceiling: DeviceProjectReach;
|
|
124
|
+
source: {
|
|
125
|
+
ceiling: DeviceSandboxSource;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
91
128
|
export interface DeviceSandboxSettingsView {
|
|
92
129
|
outsideSandbox: DevicesOutsideSandboxView;
|
|
93
130
|
network: DevicesNetworkView;
|
|
131
|
+
allowedProfiles: AllowedProfilesView;
|
|
132
|
+
projectReach: ProjectReachView;
|
|
94
133
|
}
|
|
95
134
|
/** The startup config's values and where each comes from (undefined: not set there). */
|
|
96
135
|
export interface ConfiguredDeviceSandbox {
|
|
97
136
|
outsideSandbox?: OutsideSandboxPermission | undefined;
|
|
98
137
|
networkDefault?: DeviceNetworkMode | undefined;
|
|
99
138
|
networkCeiling?: DeviceNetworkMode | undefined;
|
|
139
|
+
allowedProfiles?: PermissionProfile[] | undefined;
|
|
140
|
+
projectReach?: DeviceProjectReach | undefined;
|
|
100
141
|
sources: {
|
|
101
142
|
outsideSandbox?: ConfigSource | undefined;
|
|
102
143
|
networkDefault?: ConfigSource | undefined;
|
|
103
144
|
networkCeiling?: ConfigSource | undefined;
|
|
145
|
+
allowedProfiles?: ConfigSource | undefined;
|
|
146
|
+
projectReach?: ConfigSource | undefined;
|
|
104
147
|
};
|
|
105
148
|
}
|
|
106
149
|
/**
|
|
@@ -138,6 +181,16 @@ export declare function readDeviceSandboxSettingsView(db: KernelSchemaDb, config
|
|
|
138
181
|
/** The platform's effective device sandbox settings (the layer `effectiveDeviceSandbox` takes). */
|
|
139
182
|
export declare function readDeviceSandboxSettings(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">, log?: Pick<KernelLogger, "warn">): Promise<DeviceSandboxSettings>;
|
|
140
183
|
export declare const OrgDeviceSandboxStoredSchema: z.ZodObject<{
|
|
184
|
+
allowedProfiles: z.ZodCatch<z.ZodOptional<z.ZodPipe<z.ZodArray<z.ZodEnum<{
|
|
185
|
+
"approve-for-me": "approve-for-me";
|
|
186
|
+
"full-access": "full-access";
|
|
187
|
+
"request-approval": "request-approval";
|
|
188
|
+
}>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>>;
|
|
189
|
+
projectReach: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
|
|
190
|
+
machine: "machine";
|
|
191
|
+
paths: "paths";
|
|
192
|
+
workspace: "workspace";
|
|
193
|
+
}>>>;
|
|
141
194
|
outsideSandbox: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
|
|
142
195
|
allowed: "allowed";
|
|
143
196
|
off: "off";
|
|
@@ -173,4 +226,5 @@ export declare const OrgDeviceSandboxStoredSchema: z.ZodObject<{
|
|
|
173
226
|
}, z.core.$strip>;
|
|
174
227
|
/** Read the org's current choices. A missing choice follows the platform. */
|
|
175
228
|
export declare function orgDeviceSandboxOf(raw: unknown): z.infer<typeof OrgDeviceSandboxStoredSchema>;
|
|
176
|
-
export
|
|
229
|
+
export declare function effectiveAllowedProfiles(platform: readonly PermissionProfile[], org: readonly PermissionProfile[] | undefined): PermissionProfile[];
|
|
230
|
+
export declare function effectiveProjectReach(platform: DeviceProjectReach, org: DeviceProjectReach | undefined): DeviceProjectReach;
|