@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.
Files changed (113) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/admin/admin.schemas.d.ts +14 -0
  3. package/dist/automations/automations.service.js +15 -21
  4. package/dist/automations/effective-settings.d.ts +3 -9
  5. package/dist/automations/effective-settings.js +3 -5
  6. package/dist/automations/fire.js +0 -11
  7. package/dist/automations/grant-rules.d.ts +7 -10
  8. package/dist/automations/grant-rules.js +9 -18
  9. package/dist/automations/unattended.d.ts +1 -4
  10. package/dist/automations/unattended.js +0 -2
  11. package/dist/catalog/org-extension.controller.d.ts +1 -20
  12. package/dist/catalog/org-extension.controller.js +1 -48
  13. package/dist/catalog/org-extension.schemas.d.ts +1 -9
  14. package/dist/catalog/org-extension.schemas.js +1 -17
  15. package/dist/config/schema.d.ts +12 -0
  16. package/dist/config/schema.js +16 -0
  17. package/dist/conversations/approval-profile.d.ts +8 -1
  18. package/dist/conversations/approval-profile.js +20 -0
  19. package/dist/conversations/conversations.service.d.ts +1 -1
  20. package/dist/conversations/conversations.service.js +8 -3
  21. package/dist/conversations/events.d.ts +25 -1
  22. package/dist/conversations/events.js +7 -2
  23. package/dist/conversations/permission-profiles.controller.d.ts +4 -0
  24. package/dist/conversations/permission-profiles.schemas.d.ts +5 -0
  25. package/dist/conversations/permission-profiles.schemas.js +8 -0
  26. package/dist/conversations/permission-profiles.service.d.ts +8 -1
  27. package/dist/conversations/permission-profiles.service.js +13 -1
  28. package/dist/db/kernel-schema.d.ts +21 -0
  29. package/dist/device-access/device-access.service.d.ts +4 -1
  30. package/dist/device-access/device-access.service.js +26 -7
  31. package/dist/device-access/viewer.d.ts +3 -1
  32. package/dist/device-access/viewer.js +18 -9
  33. package/dist/errors.d.ts +6 -0
  34. package/dist/errors.js +6 -0
  35. package/dist/git/gateway.d.ts +8 -1
  36. package/dist/git/gateway.js +68 -11
  37. package/dist/git/git.module.d.ts +2 -3
  38. package/dist/git/git.module.js +4 -4
  39. package/dist/http/api.module.js +3 -3
  40. package/dist/identity/settings.d.ts +20 -5
  41. package/dist/identity/settings.js +52 -9
  42. package/dist/infra/config/kernel-config.service.js +4 -0
  43. package/dist/orgs/orgs.module.js +12 -1
  44. package/dist/orgs/orgs.schemas.js +3 -0
  45. package/dist/orgs/security-settings.service.d.ts +94 -0
  46. package/dist/orgs/security-settings.service.js +223 -0
  47. package/dist/orgs/settings.controller.d.ts +33 -0
  48. package/dist/orgs/settings.controller.js +41 -1
  49. package/dist/orgs/settings.service.d.ts +48 -63
  50. package/dist/orgs/settings.service.js +86 -103
  51. package/dist/platform/exclusions.js +1 -1
  52. package/dist/platform/operation.js +4 -0
  53. package/dist/platform/ops/admin.ops.js +18 -4
  54. package/dist/platform/ops/connectors.ops.js +2 -2
  55. package/dist/platform/ops/extensions.ops.d.ts +1 -3
  56. package/dist/platform/ops/extensions.ops.js +4 -131
  57. package/dist/platform/ops/org-settings.ops.d.ts +3 -1
  58. package/dist/platform/ops/org-settings.ops.js +76 -3
  59. package/dist/platform/ops/orgs.ops.js +2 -0
  60. package/dist/runtime/context/permission-profile.js +6 -0
  61. package/dist/runtime/subagents/dispatch.d.ts +3 -0
  62. package/dist/runtime/subagents/dispatch.js +2 -1
  63. package/dist/runtime/subagents/messages.d.ts +3 -1
  64. package/dist/runtime/subagents/messages.js +9 -6
  65. package/dist/sandbox/device-sandbox-settings.d.ts +55 -1
  66. package/dist/sandbox/device-sandbox-settings.js +64 -1
  67. package/dist/sandbox/device-sandbox.d.ts +9 -1
  68. package/dist/sandbox/device-sandbox.js +17 -2
  69. package/dist/sandbox/device-services.d.ts +26 -3
  70. package/dist/sandbox/device-services.js +95 -16
  71. package/dist/sandbox/loopback-grant-records.d.ts +3 -2
  72. package/dist/sandbox/loopback-grant-records.js +32 -5
  73. package/dist/sandbox/operation-authority.d.ts +3 -2
  74. package/dist/sandbox/operation-authority.js +21 -1
  75. package/dist/sandbox/operation-intents.js +5 -1
  76. package/dist/sandbox/permission-call-types.d.ts +2 -1
  77. package/dist/sandbox/permission-ceiling-writes.d.ts +14 -5
  78. package/dist/sandbox/permission-ceiling-writes.js +122 -13
  79. package/dist/sandbox/permission-config-publication.d.ts +10 -0
  80. package/dist/sandbox/permission-config-publication.js +27 -5
  81. package/dist/sandbox/permission-facts.d.ts +21 -2
  82. package/dist/sandbox/permission-facts.js +101 -9
  83. package/dist/sandbox/permission-transitions.d.ts +1 -1
  84. package/dist/sandbox/sandbox.service.d.ts +2 -2
  85. package/dist/sandbox/sandbox.service.js +7 -3
  86. package/dist/tools/admin-connectors.js +2 -2
  87. package/dist/tools/approvals.service.d.ts +7 -2
  88. package/dist/tools/approvals.service.js +39 -7
  89. package/dist/tools/builtin-names.d.ts +0 -6
  90. package/dist/tools/builtin-names.js +0 -11
  91. package/dist/tools/builtins/sandbox/index.d.ts +3 -5
  92. package/dist/tools/builtins/sandbox/index.js +3 -5
  93. package/dist/tools/connector-account-policies.js +7 -4
  94. package/dist/tools/connectors.controller.d.ts +0 -6
  95. package/dist/tools/connectors.schemas.d.ts +1 -8
  96. package/dist/tools/connectors.schemas.js +1 -4
  97. package/dist/tools/connectors.service.d.ts +3 -7
  98. package/dist/tools/connectors.service.js +29 -44
  99. package/dist/tools/drift.js +12 -4
  100. package/dist/tools/git-push-policy.d.ts +1 -4
  101. package/dist/tools/git-push-policy.js +4 -5
  102. package/dist/tools/org-tool-policies.d.ts +24 -0
  103. package/dist/tools/org-tool-policies.js +113 -0
  104. package/dist/tools/org-tool-switches.d.ts +5 -70
  105. package/dist/tools/org-tool-switches.js +13 -141
  106. package/dist/tools/pipeline.d.ts +11 -5
  107. package/dist/tools/pipeline.js +173 -38
  108. package/dist/tools/policy.d.ts +3 -7
  109. package/dist/tools/policy.js +29 -48
  110. package/dist/tools/registry.d.ts +5 -0
  111. package/dist/tools/registry.js +44 -13
  112. package/package.json +1 -1
  113. package/src/migrations/0212_org_security_policy.sql +234 -0
package/bootstrap.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "0b6d898d9481190adc74d5554dd53e78382b1e31"
6
+ "commit": "28d1cfdacc69af3ed2020622d973c681e9f7fc10"
7
7
  },
8
8
  "plugins": [
9
9
  {
@@ -98,8 +98,8 @@
98
98
  "name": "device-local",
99
99
  "source": "npm",
100
100
  "npm": "@capybara-hq/plugin-device-local",
101
- "version": "0.1.0-rc.18",
102
- "integrity": "sha512-i+0Ixm83k967TXjDh7EcgpwQSwKBMtHE1owhLfgg06zMzhkkrfAqE4YdegdRj0hFWf79rAYQwN95pYoMGLZBdw==",
101
+ "version": "0.1.0-rc.19",
102
+ "integrity": "sha512-2v2iT3YWZJs42PYXSDZQ9lrU7vALnb7aYRHlYLvWw+kFmrDb51ZlyXKWPjgi1WhzUTk3Zcp5f2WNcnbjiTm97Q==",
103
103
  "required": false,
104
104
  "scope": "all"
105
105
  },
@@ -74,6 +74,20 @@ export declare const DeploymentSettingsBody: z.ZodObject<{
74
74
  open: "open";
75
75
  }>>>;
76
76
  }, z.core.$strict>>;
77
+ devicesAllowedProfiles: z.ZodOptional<z.ZodObject<{
78
+ value: z.ZodNullable<z.ZodPipe<z.ZodArray<z.ZodEnum<{
79
+ "approve-for-me": "approve-for-me";
80
+ "full-access": "full-access";
81
+ "request-approval": "request-approval";
82
+ }>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>;
83
+ }, z.core.$strict>>;
84
+ devicesProjectReach: z.ZodOptional<z.ZodObject<{
85
+ ceiling: z.ZodNullable<z.ZodEnum<{
86
+ machine: "machine";
87
+ paths: "paths";
88
+ workspace: "workspace";
89
+ }>>;
90
+ }, z.core.$strict>>;
77
91
  devicesDefaultProvider: z.ZodOptional<z.ZodObject<{
78
92
  provider: z.ZodNullable<z.ZodString>;
79
93
  }, z.core.$strict>>;
@@ -28,12 +28,12 @@ import { OutboxService } from "../infra/outbox/outbox.service.js";
28
28
  import { KERNEL_LOGGER } from "../infra/tokens.js";
29
29
  import { OrgLock } from "../orgs/org-lock.js";
30
30
  import { can, roleAtLeast } from "../orgs/roles.js";
31
- import { FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR } from "../orgs/settings.service.js";
32
31
  import { ProviderRegistry } from "../runtime/providers.js";
33
32
  import { orgHostOutsideCeiling } from "../sandbox/modes.js";
34
33
  import { orgAllows } from "../sandbox/network-grants.js";
35
34
  import { SandboxService } from "../sandbox/sandbox.service.js";
36
35
  import { isTimeZone } from "../time-zone.js";
36
+ import { readOrgGitPushDenials, readOrgToolPolicies, readOrgToolPolicy, } from "../tools/org-tool-policies.js";
37
37
  import { ToolRegistry } from "../tools/registry.js";
38
38
  import { assembleCalendar, CALENDAR_LIMITS, CALENDAR_RANGE_DAYS, CALENDAR_TASK_RANGE_DAYS, calendarRunReadLimit, } from "./calendar.js";
39
39
  import { readAutomationSettings } from "./effective-settings.js";
@@ -158,7 +158,7 @@ let AutomationsService = class AutomationsService {
158
158
  };
159
159
  await this.checkPick(orgId, accountId, agent, target.mode, pick);
160
160
  const expiresAt = expiryOf(input.expiresAt ?? null, trigger, now, settings);
161
- const grants = await this.resolveGrants(orgId, role, agent, settings, input.grants ?? [], await this.taskDeviceOf(orgId, { ...target, deviceId: pick.deviceId }), source);
161
+ const grants = await this.resolveGrants(orgId, role, agent, input.grants ?? [], await this.taskDeviceOf(orgId, { ...target, deviceId: pick.deviceId }), source);
162
162
  const id = randomUUID();
163
163
  const jitter = jitterForGap(id, gap);
164
164
  const task = await this.store.insertTask(t, {
@@ -226,7 +226,7 @@ let AutomationsService = class AutomationsService {
226
226
  // too (refused, so the creator sees which), and takes the new agent's definition; network
227
227
  // and git and sandbox tier grants belong to no tool and stay as they are
228
228
  const held = (await this.store.listGrants(t, task.id)).filter((g) => !isNonToolGrantKey(g.toolKey));
229
- const regranted = await this.resolveGrants(orgId, role, agent, settings, held.map((g) => ({
229
+ const regranted = await this.resolveGrants(orgId, role, agent, held.map((g) => ({
230
230
  toolKey: g.toolKey,
231
231
  ...(g.connectorId !== null && { connectorId: g.connectorId }),
232
232
  })), null);
@@ -665,7 +665,8 @@ let AutomationsService = class AutomationsService {
665
665
  async grantableTools(orgId, accountId, agentId) {
666
666
  const role = await this.liveRole(orgId, accountId);
667
667
  const agent = await this.agents.get(orgId, agentId, accountId);
668
- const settings = await readAutomationSettings(this.db.db, this.config, orgId);
668
+ const policies = await readOrgToolPolicies(this.db.db, orgId);
669
+ const byKey = new Map(policies.map((r) => [r.toolKey, r]));
669
670
  const d = agent.definition;
670
671
  const { tools } = await this.tools.forAgent(orgId, {
671
672
  disabledTools: d.disabledTools ?? [],
@@ -674,12 +675,11 @@ let AutomationsService = class AutomationsService {
674
675
  // no conversation at hand: a web one's tools; a run elsewhere still refuses by spec.sources
675
676
  source: "web",
676
677
  });
677
- const ctx = {
678
- role,
679
- forbiddenTools: settings.forbiddenTools,
680
- };
681
678
  return tools.map((tool) => {
682
- const why = grantRefusalOf(tool.key, tool, ctx);
679
+ const row = byKey.get(tool.key);
680
+ const pair = [row?.policy, row?.unattendedPolicy];
681
+ const orgPolicy = pair.includes("deny") ? "deny" : pair.includes("ask") ? "ask" : "allow";
682
+ const why = grantRefusalOf(tool.key, tool, { role, orgPolicy });
683
683
  return {
684
684
  key: tool.key,
685
685
  title: tool.spec.title ?? null,
@@ -725,9 +725,8 @@ let AutomationsService = class AutomationsService {
725
725
  const { role } = await this.orgLock.lockAndAuthorize(orgId, accountId, "automations.use");
726
726
  const t = this.db.db;
727
727
  const task = await this.lockOwn(orgId, accountId, role, id);
728
- const settings = await readAutomationSettings(t, this.config, orgId);
729
728
  const agent = await this.agents.get(orgId, task.agentId, accountId);
730
- const resolved = await this.resolveGrants(orgId, role, agent, settings, grants, await this.taskDeviceOf(orgId, task), source);
729
+ const resolved = await this.resolveGrants(orgId, role, agent, grants, await this.taskDeviceOf(orgId, task), source);
731
730
  for (const g of resolved)
732
731
  await this.store.addGrant(t, task.id, g);
733
732
  await audit(t, {
@@ -1180,13 +1179,9 @@ let AutomationsService = class AutomationsService {
1180
1179
  * lower-cased) is refused by {@link gitGrantRefusal} and stored with `spec_hash` `git` and no
1181
1180
  * connector, also only when `source.fromSession`. Duplicates keep the last.
1182
1181
  */
1183
- async resolveGrants(orgId, role, agent, settings, grants, _deviceId, source = {}) {
1182
+ async resolveGrants(orgId, role, agent, grants, _deviceId, source = {}) {
1184
1183
  if (grants.length === 0)
1185
1184
  return [];
1186
- // fail closed: no grant can be checked against a list that cannot be read
1187
- if (settings.forbiddenToolsUnreadable) {
1188
- throw grantNotAllowed(FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR);
1189
- }
1190
1185
  const out = new Map();
1191
1186
  const network = grants.filter((g) => isNetworkGrantKey(g.toolKey));
1192
1187
  if (network.length > 0) {
@@ -1210,12 +1205,13 @@ let AutomationsService = class AutomationsService {
1210
1205
  // a push is the creator's decision, never an agent's or a token's (as network domains)
1211
1206
  if (source.fromSession !== true)
1212
1207
  throw grantNotAllowed(GIT_GRANT_NEEDS_PERSON);
1208
+ const gitDenials = await readOrgGitPushDenials(this.db.db, orgId);
1213
1209
  for (const g of git) {
1214
1210
  if (g.connectorId !== undefined) {
1215
1211
  throw grantNotAllowed(`${g.toolKey} is a git push and comes from no connector`);
1216
1212
  }
1217
1213
  const toolKey = normalizeGitGrantKey(g.toolKey);
1218
- const why = gitGrantRefusal(toolKey, { forbiddenTools: settings.forbiddenTools });
1214
+ const why = gitGrantRefusal(toolKey, { gitDenials });
1219
1215
  if (why !== null)
1220
1216
  throw grantNotAllowed(why.message);
1221
1217
  out.set(toolKey, { toolKey, specHash: GIT_GRANT_SPEC_HASH, connectorId: null });
@@ -1234,10 +1230,8 @@ let AutomationsService = class AutomationsService {
1234
1230
  });
1235
1231
  for (const g of toolGrants) {
1236
1232
  const tool = tools.find((x) => x.key === g.toolKey);
1237
- const why = grantRefusal(g.toolKey, tool, {
1238
- role,
1239
- forbiddenTools: settings.forbiddenTools,
1240
- });
1233
+ const policy = await readOrgToolPolicy(this.db.db, orgId, tool?.key ?? g.toolKey, g.toolKey, true);
1234
+ const why = grantRefusal(g.toolKey, tool, { role, orgPolicy: policy.policy });
1241
1235
  if (why !== null || !tool)
1242
1236
  throw grantNotAllowed(why ?? `${g.toolKey} cannot be approved`);
1243
1237
  const connectorId = tool.source.kind === "connector" ? tool.source.connectorId : null;
@@ -11,18 +11,12 @@ export interface AutomationBounds {
11
11
  coalesceSecondsCap: number;
12
12
  maxEventRunsPerSubjectPerHourCap: number;
13
13
  }
14
- /**
15
- * The org's automation settings after clamping to the platform bounds. `forbiddenToolsUnreadable`:
16
- * the stored list cannot be read (`invalidStoredForbiddenTools`); `forbiddenTools` is then `[]`
17
- * and unattended runs of the org must fail instead of running with nothing forbidden.
18
- */
19
- export type EffectiveAutomationSettings = AutomationsSettings & {
20
- forbiddenToolsUnreadable: boolean;
21
- };
14
+ /** The org's automation settings after clamping to the platform bounds. */
15
+ export type EffectiveAutomationSettings = AutomationsSettings;
22
16
  /**
23
17
  * An org value outside the platform bounds is clamped: the interval up, the counts, the event
24
18
  * chain depth and the coalescing window down.
25
19
  */
26
- export declare function effectiveAutomationSettings(org: AutomationsSettings, bounds: AutomationBounds, forbiddenToolsUnreadable?: boolean): EffectiveAutomationSettings;
20
+ export declare function effectiveAutomationSettings(org: AutomationsSettings, bounds: AutomationBounds): EffectiveAutomationSettings;
27
21
  /** Read the org's effective settings live (PG and the current kernel config). */
28
22
  export declare function readAutomationSettings(db: KernelSchemaDb, config: Pick<KernelConfigService, "get">, orgId: string): Promise<EffectiveAutomationSettings>;
@@ -1,14 +1,12 @@
1
- import { invalidStoredForbiddenTools, parseOrgSettings, readStoredOrgSettings, } from "../orgs/settings.service.js";
1
+ import { parseOrgSettings, readStoredOrgSettings, } from "../orgs/settings.service.js";
2
2
  /**
3
3
  * An org value outside the platform bounds is clamped: the interval up, the counts, the event
4
4
  * chain depth and the coalescing window down.
5
5
  */
6
- export function effectiveAutomationSettings(org, bounds, forbiddenToolsUnreadable = false) {
6
+ export function effectiveAutomationSettings(org, bounds) {
7
7
  return {
8
8
  ...org,
9
- forbiddenTools: [...org.forbiddenTools],
10
9
  eventSourcesOff: [...org.eventSourcesOff],
11
- forbiddenToolsUnreadable,
12
10
  minIntervalMinutes: Math.max(org.minIntervalMinutes, bounds.minIntervalFloorMinutes),
13
11
  maxTasksPerMember: Math.min(org.maxTasksPerMember, bounds.maxTasksPerMemberCap),
14
12
  maxTasksPerOrg: Math.min(org.maxTasksPerOrg, bounds.maxTasksPerOrgCap),
@@ -21,5 +19,5 @@ export function effectiveAutomationSettings(org, bounds, forbiddenToolsUnreadabl
21
19
  /** Read the org's effective settings live (PG and the current kernel config). */
22
20
  export async function readAutomationSettings(db, config, orgId) {
23
21
  const raw = await readStoredOrgSettings(db, orgId);
24
- return effectiveAutomationSettings(parseOrgSettings(raw).automations, config.get().automations, invalidStoredForbiddenTools(raw));
22
+ return effectiveAutomationSettings(parseOrgSettings(raw).automations, config.get().automations);
25
23
  }
@@ -29,7 +29,6 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
29
29
  import { OutboxService } from "../infra/outbox/outbox.service.js";
30
30
  import { KERNEL_LOGGER } from "../infra/tokens.js";
31
31
  import { OrgLock, OrgLockModule } from "../orgs/org-lock.js";
32
- import { FORBIDDEN_TOOLS_UNREADABLE_ERROR } from "../orgs/settings.service.js";
33
32
  import { AUTOMATION_EVENT_HEAD, AUTOMATION_EVENT_TAIL } from "../runtime/context/run-context.js";
34
33
  import { RuntimeModule } from "../runtime/runtime.module.js";
35
34
  import { DeviceProviders, servesDialIn } from "../sandbox/providers.js";
@@ -285,16 +284,6 @@ let AutomationFirer = class AutomationFirer {
285
284
  }
286
285
  if (!resumed && !settings.enabled)
287
286
  return skip("org_disabled");
288
- // an unattended run must not run with nothing forbidden (a trial run is attended)
289
- if (!resumed && !run.trial && settings.forbiddenToolsUnreadable) {
290
- this.log.warn("automation run failed: the org's forbidden tool list is unreadable", {
291
- orgId,
292
- taskId: task.id,
293
- taskRunId: run.id,
294
- });
295
- await this.tracker.failStartIn(run.id, FORBIDDEN_TOOLS_UNREADABLE_ERROR);
296
- return null;
297
- }
298
287
  if (!resumed && !(await this.creatorActive(orgId, task.accountId))) {
299
288
  return skip("creator_inactive");
300
289
  }
@@ -9,11 +9,12 @@ import type { ResolvedTool } from "../tools/registry.js";
9
9
  /** Who asks for a grant and where: the inputs of {@link grantRefusalOf}. */
10
10
  export interface GrantContext {
11
11
  role: OrgRole;
12
- forbiddenTools: readonly string[];
12
+ orgPolicy?: "allow" | "ask" | "deny";
13
+ gitDenials?: readonly string[];
13
14
  }
14
15
  /**
15
16
  * Why a tool can't be a task's grant, as a code the UI words: `forbidden` (the org's
16
- * `forbiddenTools`), `not_grantable` (by design: a Platform call that changes the agent's
17
+ * tool ceiling), `not_grantable` (by design: a Platform call that changes the agent's
17
18
  * skills, or any other per-call key such as `Platform:<operation>`), `not_available` (not one of the agent's tools now), `needs_role` (a
18
19
  * `requiredRole` above the creator's), `fixed_ask` (always asks a person). A network grant
19
20
  * (`network:<host>`, {@link networkGrantRefusal}) adds `needs_admin` (outside the org's network
@@ -85,20 +86,16 @@ export declare const isGitGrantKey: (key: string) => boolean;
85
86
  export declare const gitPushGrantKey: (repo?: string) => string;
86
87
  /**
87
88
  * Why a git push grant key cannot be one of a task's grants, or null when it can: the org forbids
88
- * it (`forbiddenTools` lists the key or `git:push`) or the repository is not `<owner>/<repo>`
89
+ * it (the repository or every repository is denied) or the repository is not `<owner>/<repo>`
89
90
  * (`not_grantable`). The key is compared as given (callers normalize it with
90
91
  * {@link normalizeGitGrantKey} first).
91
92
  */
92
- export declare function gitGrantRefusal(key: string, ctx: Pick<GrantContext, "forbiddenTools">): {
93
+ export declare function gitGrantRefusal(key: string, ctx: Pick<GrantContext, "gitDenials">): {
93
94
  code: GrantRefusalCode;
94
95
  message: string;
95
96
  } | null;
96
- /**
97
- * Whether the org's `forbiddenTools` forbid the git push grant `key` (normalized): it lists
98
- * `git:push` or the key, each entry compared normalized (`git:push:Acme/App` forbids
99
- * `git:push:acme/app`).
100
- */
101
- export declare function gitPushForbidden(forbiddenTools: readonly string[], key: string): boolean;
97
+ /** Whether the normalized repository target is denied by the organization's Git policy. */
98
+ export declare function gitPushForbidden(targets: readonly string[], key: string): boolean;
102
99
  /**
103
100
  * A git push grant key as stored: the repository normalized ({@link normalizeGitRepo}); the key
104
101
  * unchanged when its repository is not of the shape (then {@link gitGrantRefusal} refuses it).
@@ -16,8 +16,7 @@ export function grantRefusalOf(toolKey, tool, ctx) {
16
16
  // a git push grant belongs to no tool (sandbox git credentials spec §7)
17
17
  if (isGitGrantKey(toolKey))
18
18
  return gitGrantRefusal(toolKey, ctx);
19
- if (ctx.forbiddenTools.includes(toolKey) ||
20
- (tool !== undefined && ctx.forbiddenTools.includes(tool.key))) {
19
+ if (ctx.orgPolicy === "deny") {
21
20
  return {
22
21
  code: "forbidden",
23
22
  message: `The organization does not allow ${toolKey} in scheduled runs`,
@@ -44,7 +43,7 @@ export function grantRefusalOf(toolKey, tool, ctx) {
44
43
  message: `${toolKey} needs the ${tool.requiredRole} role to approve; you cannot approve it for the task`,
45
44
  };
46
45
  }
47
- if (isFixedAsk(tool)) {
46
+ if (ctx.orgPolicy === "ask" || isFixedAsk(tool)) {
48
47
  return {
49
48
  code: "fixed_ask",
50
49
  message: `${toolKey} always asks a person and cannot be approved in advance`,
@@ -120,12 +119,12 @@ export const isGitGrantKey = (key) => key === GIT_PUSH_GRANT || key.startsWith(G
120
119
  export const gitPushGrantKey = (repo) => repo === undefined ? GIT_PUSH_GRANT : `${GIT_PUSH_REPO_GRANT_PREFIX}${repo}`;
121
120
  /**
122
121
  * Why a git push grant key cannot be one of a task's grants, or null when it can: the org forbids
123
- * it (`forbiddenTools` lists the key or `git:push`) or the repository is not `<owner>/<repo>`
122
+ * it (the repository or every repository is denied) or the repository is not `<owner>/<repo>`
124
123
  * (`not_grantable`). The key is compared as given (callers normalize it with
125
124
  * {@link normalizeGitGrantKey} first).
126
125
  */
127
126
  export function gitGrantRefusal(key, ctx) {
128
- if (gitPushForbidden(ctx.forbiddenTools, key)) {
127
+ if (gitPushForbidden(ctx.gitDenials ?? [], key)) {
129
128
  return {
130
129
  code: "forbidden",
131
130
  message: `The organization does not allow ${key} in scheduled runs`,
@@ -142,19 +141,11 @@ export function gitGrantRefusal(key, ctx) {
142
141
  }
143
142
  return null;
144
143
  }
145
- /**
146
- * Whether the org's `forbiddenTools` forbid the git push grant `key` (normalized): it lists
147
- * `git:push` or the key, each entry compared normalized (`git:push:Acme/App` forbids
148
- * `git:push:acme/app`).
149
- */
150
- export function gitPushForbidden(forbiddenTools, key) {
151
- return forbiddenTools.some((entry) => {
152
- const lowered = entry.trim().toLowerCase();
153
- if (!isGitGrantKey(lowered))
154
- return false;
155
- const e = normalizeGitGrantKey(lowered);
156
- return e === GIT_PUSH_GRANT || e === key;
157
- });
144
+ /** Whether the normalized repository target is denied by the organization's Git policy. */
145
+ export function gitPushForbidden(targets, key) {
146
+ return (targets.includes("*") ||
147
+ (key.startsWith(GIT_PUSH_REPO_GRANT_PREFIX) &&
148
+ targets.includes(key.slice(GIT_PUSH_REPO_GRANT_PREFIX.length))));
158
149
  }
159
150
  /**
160
151
  * A git push grant key as stored: the repository normalized ({@link normalizeGitRepo}); the key
@@ -59,16 +59,13 @@ export declare const networkGrantKey: (host: string) => string;
59
59
  /**
60
60
  * What the tool policy knows of the automation run a kernel run serves (`PolicyContext`): the
61
61
  * task (its grants), the task run (its `missing_grants`), whether it is a trial run (attended), and
62
- * the org's `unattendedAsk` and `forbiddenTools`, read live.
62
+ * the org’s unattended approval mode, read live.
63
63
  */
64
64
  export interface UnattendedRun {
65
65
  taskId: string;
66
66
  taskRunId: string;
67
67
  trial: boolean;
68
68
  unattendedAsk: "fail" | "wait";
69
- forbiddenTools: string[];
70
- /** The org's stored `forbiddenTools` cannot be read: every tool call of the run is refused. */
71
- forbiddenToolsUnreadable?: boolean;
72
69
  }
73
70
  /** An unattended run that is not a trial run: the §7 rules apply. */
74
71
  export declare const unattendedRules: (u: UnattendedRun | null | undefined) => u is UnattendedRun;
@@ -180,8 +180,6 @@ export async function unattendedRunOf(db, config, orgId, runId) {
180
180
  return {
181
181
  ...run,
182
182
  unattendedAsk: own?.unattended_ask ?? s.unattendedAsk,
183
- forbiddenTools: s.forbiddenTools,
184
- forbiddenToolsUnreadable: s.forbiddenToolsUnreadable,
185
183
  };
186
184
  }
187
185
  /**
@@ -7,10 +7,9 @@ import { OrgOverrides, type OrgOverrideView } from "../extensions/org-overrides.
7
7
  import { PluginIcons } from "../extensions/plugin-icons.js";
8
8
  import { type Principal } from "../identity/principal.js";
9
9
  import { type OrgContext } from "../orgs/org.guard.js";
10
- import { type OrgToolSwitch, OrgToolSwitches, type OrgToolSwitchResult } from "../tools/org-tool-switches.js";
11
10
  import { AppearanceApplyBody } from "./appearance.schemas.js";
12
11
  import { type AppearanceResult, AppearanceService } from "./appearance.service.js";
13
- import { OrgExtensionParams as ExtensionParams, OrgOverridesPut as OverridesPut, OrgOverridesTake as OverridesTake, OrgExtensionPut as PutBody, OrgExtensionToolParams as ToolParams, OrgToolSwitchPut as ToolSwitchPut } from "./org-extension.schemas.js";
12
+ import { OrgExtensionParams as ExtensionParams, OrgOverridesPut as OverridesPut, OrgOverridesTake as OverridesTake, OrgExtensionPut as PutBody } from "./org-extension.schemas.js";
14
13
  /**
15
14
  * One extension of the org list: the org view plus the plugin's display name, the URL of its
16
15
  * plugin's icon on the org's catalog route (null without one or when the org may not see the
@@ -89,21 +88,3 @@ export declare class OrgExtensionOverridesController {
89
88
  /** Takes the platform's current values of non-secret overridable fields into the copy. */
90
89
  take(principal: Principal, org: OrgContext, { extension }: z.infer<typeof ExtensionParams>, body: z.infer<typeof OverridesTake>): Promise<OrgOverrideView>;
91
90
  }
92
- /**
93
- * The org's switches of an extension's single tools (layering spec A §7): members read them, org
94
- * admins turn a tool off (previewed with the agents that selected it, PCM §5 rule 8) or on.
95
- */
96
- export declare class OrgExtensionToolSwitchesController {
97
- private readonly switches;
98
- constructor(switches: OrgToolSwitches);
99
- /** Every tool the extension registers, with its switch (on unless the org turned it off). */
100
- list(org: OrgContext, { extension }: z.infer<typeof ExtensionParams>): Promise<{
101
- tools: OrgToolSwitch[];
102
- }>;
103
- /**
104
- * Switches one tool: on applies at once; off answers `{ applied: false, affectedAgents, confirm }`
105
- * until `confirm` carries the hash (a changed preview -> 409 `plugin.switch_stale`). A tool the
106
- * extension does not register -> 404 `extension.tool_not_found`.
107
- */
108
- set(principal: Principal, org: OrgContext, { extension, tool }: z.infer<typeof ToolParams>, body: z.infer<typeof ToolSwitchPut>): Promise<OrgToolSwitchResult>;
109
- }
@@ -18,20 +18,15 @@ import { createZodDto } from "../infra/validation/create-zod-dto.js";
18
18
  import { ZBody, ZParam } from "../infra/validation/zod-params.js";
19
19
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
20
20
  import { roleAtLeast } from "../orgs/roles.js";
21
- import { OrgToolSwitches, } from "../tools/org-tool-switches.js";
22
21
  import { AppearanceApplyBody } from "./appearance.schemas.js";
23
22
  import { AppearanceService } from "./appearance.service.js";
24
- import { OrgExtensionParams as ExtensionParams, OrgOverridesPut as OverridesPut, OrgOverridesTake as OverridesTake, OrgExtensionPut as PutBody, OrgExtensionToolParams as ToolParams, OrgToolSwitchPut as ToolSwitchPut, } from "./org-extension.schemas.js";
23
+ import { OrgExtensionParams as ExtensionParams, OrgOverridesPut as OverridesPut, OrgOverridesTake as OverridesTake, OrgExtensionPut as PutBody, } from "./org-extension.schemas.js";
25
24
  /** The audit detail of a switch made on the org's Extensions or Models page. */
26
25
  const ORG_SWITCH = { reason: "org_switch" };
27
26
  class OrgExtensionPutBody extends createZodDto(PutBody, "OrgExtensionPutBody") {
28
27
  }
29
- class OrgToolSwitchPutBody extends createZodDto(ToolSwitchPut, "OrgToolSwitchPutBody") {
30
- }
31
28
  class OrgExtensionParamsDto extends createZodDto(ExtensionParams, "OrgExtensionParams") {
32
29
  }
33
- class OrgExtensionToolParamsDto extends createZodDto(ToolParams, "OrgExtensionToolParams") {
34
- }
35
30
  class OrgAppearanceApplyBody extends createZodDto(AppearanceApplyBody, "OrgAppearanceApplyBody") {
36
31
  }
37
32
  class OrgOverridesPutBody extends createZodDto(OverridesPut, "OrgOverridesPutBody") {
@@ -232,45 +227,3 @@ OrgExtensionOverridesController = __decorate([
232
227
  __param(0, Inject(OrgOverrides))
233
228
  ], OrgExtensionOverridesController);
234
229
  export { OrgExtensionOverridesController };
235
- /**
236
- * The org's switches of an extension's single tools (layering spec A §7): members read them, org
237
- * admins turn a tool off (previewed with the agents that selected it, PCM §5 rule 8) or on.
238
- */
239
- let OrgExtensionToolSwitchesController = class OrgExtensionToolSwitchesController {
240
- switches;
241
- constructor(switches) {
242
- this.switches = switches;
243
- }
244
- /** Every tool the extension registers, with its switch (on unless the org turned it off). */
245
- async list(org, { extension }) {
246
- return { tools: await this.switches.list(org.orgId, extension) };
247
- }
248
- /**
249
- * Switches one tool: on applies at once; off answers `{ applied: false, affectedAgents, confirm }`
250
- * until `confirm` carries the hash (a changed preview -> 409 `plugin.switch_stale`). A tool the
251
- * extension does not register -> 404 `extension.tool_not_found`.
252
- */
253
- set(principal, org, { extension, tool }, body) {
254
- const p = requireUser(principal);
255
- return this.switches.set(org.orgId, extension, tool, body.enabled, { accountId: p.account.id, tokenId: patTokenId(p) }, body.confirm);
256
- }
257
- };
258
- __decorate([
259
- Get(),
260
- OrgAction("org.extensions.read"),
261
- __param(0, CurrentOrg()),
262
- __param(1, ZParam(OrgExtensionParamsDto))
263
- ], OrgExtensionToolSwitchesController.prototype, "list", null);
264
- __decorate([
265
- Put(":tool"),
266
- OrgAction("org.extensions.manage"),
267
- __param(0, CurrentPrincipal()),
268
- __param(1, CurrentOrg()),
269
- __param(2, ZParam(OrgExtensionToolParamsDto)),
270
- __param(3, ZBody(OrgToolSwitchPutBody))
271
- ], OrgExtensionToolSwitchesController.prototype, "set", null);
272
- OrgExtensionToolSwitchesController = __decorate([
273
- Controller("api/v1/orgs/:orgId/extensions/:extension/tools"),
274
- __param(0, Inject(OrgToolSwitches))
275
- ], OrgExtensionToolSwitchesController);
276
- export { OrgExtensionToolSwitchesController };
@@ -1,17 +1,9 @@
1
1
  import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
- /** Route parameters of the overrides and tool switch routes (decision R20). */
3
+ /** Route parameters of the overrides and enablement routes (decision R20). */
4
4
  export declare const OrgExtensionParams: z.ZodObject<{
5
5
  extension: z.ZodString;
6
6
  }, z.core.$strip>;
7
- export declare const OrgExtensionToolParams: z.ZodObject<{
8
- extension: z.ZodString;
9
- tool: z.ZodString;
10
- }, z.core.$strip>;
11
- export declare const OrgToolSwitchPut: z.ZodObject<{
12
- enabled: z.ZodBoolean;
13
- confirm: z.ZodOptional<z.ZodString>;
14
- }, z.core.$strict>;
15
7
  /** `PUT /orgs/:orgId/extensions/:extension`: enablement (an org's config is its copy: `…/overrides`). */
16
8
  export declare const OrgExtensionPut: z.ZodObject<{
17
9
  enabled: z.ZodOptional<z.ZodBoolean>;
@@ -1,17 +1,7 @@
1
1
  import { secret } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
- /** Route parameters of the overrides and tool switch routes (decision R20). */
3
+ /** Route parameters of the overrides and enablement routes (decision R20). */
4
4
  export const OrgExtensionParams = z.object({ extension: z.string().min(1).max(64) });
5
- export const OrgExtensionToolParams = OrgExtensionParams.extend({
6
- tool: z.string().min(1).max(64),
7
- });
8
- export const OrgToolSwitchPut = z
9
- .object({
10
- enabled: z.boolean(),
11
- /** The hash of the switch-off preview, to confirm turning the tool off. */
12
- confirm: z.string().min(1).max(128).optional(),
13
- })
14
- .strict();
15
5
  /** `PUT /orgs/:orgId/extensions/:extension`: enablement (an org's config is its copy: `…/overrides`). */
16
6
  export const OrgExtensionPut = z
17
7
  .object({
@@ -54,12 +44,6 @@ export const OrgOverridesTake = z
54
44
  .strict();
55
45
  export const ORG_EXTENSION_ROUTES = [
56
46
  { route: "GET /api/v1/orgs/:orgId/extensions" },
57
- { route: "GET /api/v1/orgs/:orgId/extensions/:extension/tools", params: OrgExtensionParams },
58
- {
59
- route: "PUT /api/v1/orgs/:orgId/extensions/:extension/tools/:tool",
60
- params: OrgExtensionToolParams,
61
- body: OrgToolSwitchPut,
62
- },
63
47
  {
64
48
  route: "PUT /api/v1/orgs/:orgId/extensions/:extension",
65
49
  params: OrgExtensionParams,
@@ -313,6 +313,18 @@ export declare const KernelConfigSchema: z.ZodObject<{
313
313
  open: "open";
314
314
  }>>;
315
315
  }, z.core.$strict>>;
316
+ allowedProfiles: z.ZodOptional<z.ZodPipe<z.ZodArray<z.ZodEnum<{
317
+ "approve-for-me": "approve-for-me";
318
+ "full-access": "full-access";
319
+ "request-approval": "request-approval";
320
+ }>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>;
321
+ projectReach: z.ZodPrefault<z.ZodObject<{
322
+ ceiling: z.ZodOptional<z.ZodEnum<{
323
+ machine: "machine";
324
+ paths: "paths";
325
+ workspace: "workspace";
326
+ }>>;
327
+ }, z.core.$strict>>;
316
328
  maxPersonal: z.ZodDefault<z.ZodNumber>;
317
329
  dialIn: z.ZodPrefault<z.ZodObject<{
318
330
  reconnectGraceSeconds: z.ZodDefault<z.ZodNumber>;
@@ -1,6 +1,7 @@
1
1
  import { isIP } from "node:net";
2
2
  import { CATALOG_ITEM_NAME_RE, DOCUMENT_MEDIA_TYPES, EXTENSION_NAME_RE, IMAGE_MEDIA_TYPES, TOOL_TIMEOUT_MAX_MS, validateAllowHost, } from "@capybara-hq/plugin-sdk";
3
3
  import { z } from "zod";
4
+ import { AllowedProfilesSchema } from "../conversations/permission-profiles.schemas.js";
4
5
  import { LOG_FORMATS, LOG_LEVELS } from "../log.js";
5
6
  import { noProxyEntryProblem, proxyUrlProblem } from "../net/proxy.js";
6
7
  import { privateHostEntryProblem } from "../net/public-address.js";
@@ -1773,6 +1774,21 @@ export const KernelConfigSchema = z.strictObject({
1773
1774
  })),
1774
1775
  })
1775
1776
  .prefault({}),
1777
+ allowedProfiles: AllowedProfilesSchema.optional().meta(meta({
1778
+ hot: true,
1779
+ description: "Permission profiles members may choose; Request approval is always available. Set here, it is read-only in the admin console",
1780
+ })),
1781
+ projectReach: z
1782
+ .strictObject({
1783
+ ceiling: z
1784
+ .enum(["workspace", "paths", "machine"])
1785
+ .optional()
1786
+ .meta(meta({
1787
+ hot: true,
1788
+ description: "The maximum project reach of a device, from workspace to owner-approved paths to the machine. Set here, it is read-only in the admin console",
1789
+ })),
1790
+ })
1791
+ .prefault({}),
1776
1792
  maxPersonal: z
1777
1793
  .number()
1778
1794
  .int()
@@ -17,7 +17,14 @@ export interface ApprovalProfile {
17
17
  export declare class ConversationApprovalProfile {
18
18
  private readonly db;
19
19
  private readonly facts;
20
- constructor(db: KernelDb, facts: Pick<PermissionFacts, "viewWithAccess">);
20
+ constructor(db: KernelDb, facts: Pick<PermissionFacts, "viewWithAccess" | "allowedProfiles">);
21
+ /** Whether an unstarted call can still use a recorded automatic allow. */
22
+ canAdmitRecorded(input: {
23
+ orgId: string;
24
+ rootConversationId: string;
25
+ profile: PermissionProfile;
26
+ revision: number;
27
+ }): Promise<boolean>;
21
28
  /** The root's effective profile for an ask addressed to `requestedFor`; null: the profile does not apply (R1). */
22
29
  resolve(input: {
23
30
  orgId: string;
@@ -8,6 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { Inject, Injectable, Module } from "@nestjs/common";
11
+ import { sql } from "kysely";
11
12
  import { KernelDb } from "../infra/database/kernel-db.js";
12
13
  import { PermissionFacts } from "../sandbox/permission-facts.js";
13
14
  import { PermissionFactsModule } from "../sandbox/permission-facts.module.js";
@@ -26,6 +27,25 @@ let ConversationApprovalProfile = class ConversationApprovalProfile {
26
27
  this.db = db;
27
28
  this.facts = facts;
28
29
  }
30
+ /** Whether an unstarted call can still use a recorded automatic allow. */
31
+ async canAdmitRecorded(input) {
32
+ if (!(await this.facts.allowedProfiles(input.orgId)).includes(input.profile))
33
+ return false;
34
+ const reset = await this.db.db
35
+ .selectFrom("conversation_events as e")
36
+ .innerJoin("conversations as c", "c.id", "e.conversation_id")
37
+ .select("e.seq")
38
+ .where("c.org_id", "=", input.orgId)
39
+ .where("c.id", "=", input.rootConversationId)
40
+ .where("c.permission_revision", ">", input.revision)
41
+ .where("e.type", "=", "permission_profile_changed")
42
+ .where(sql `payload->>'reason' in ('platform-profile-ceiling', 'org-profile-ceiling')`)
43
+ .where(sql `payload->>'oldProfile' = ${input.profile}`)
44
+ .where(sql `(payload->>'revision')::integer > ${input.revision}`)
45
+ .limit(1)
46
+ .executeTakeFirst();
47
+ return reset === undefined;
48
+ }
29
49
  /** The root's effective profile for an ask addressed to `requestedFor`; null: the profile does not apply (R1). */
30
50
  async resolve(input) {
31
51
  const row = await this.db.db
@@ -426,7 +426,7 @@ export declare class ConversationsService {
426
426
  private readonly outbox;
427
427
  /** The agent's tools for a message naming connectors or resources (inline tokens §3.4). */
428
428
  private readonly mentions;
429
- constructor(permissions: Pick<PermissionProfilesService, "initialize" | "lockInitial">, db: KernelDb, eventLog: EventLog, agents: Pick<AgentLookup, "get">, access: Pick<ConversationAccess, "isAccessible">,
429
+ constructor(permissions: Pick<PermissionProfilesService, "initialize" | "lockInitial" | "defaultProfile">, db: KernelDb, eventLog: EventLog, agents: Pick<AgentLookup, "get">, access: Pick<ConversationAccess, "isAccessible">,
430
430
  /** Starts and stops the conversation's runs. */
431
431
  runs: RunControl,
432
432
  /** Resolves a switched-to model and its declared parameters (UI refresh B). */