@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.43
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 +6 -0
- package/dist/admin/org-network.service.d.ts +3 -1
- package/dist/admin/org-network.service.js +10 -2
- package/dist/app.d.ts +4 -0
- package/dist/app.js +2 -0
- package/dist/background/finish.d.ts +9 -1
- package/dist/background/finish.js +57 -4
- package/dist/background/launch.d.ts +23 -0
- package/dist/background/launch.js +55 -1
- package/dist/background/managed-output.d.ts +110 -0
- package/dist/background/managed-output.js +219 -0
- package/dist/background/managed.d.ts +52 -0
- package/dist/background/managed.js +128 -0
- package/dist/background/poll.job.d.ts +35 -1
- package/dist/background/poll.job.js +174 -9
- package/dist/background/render.js +1 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
- package/dist/background/retire-legacy-tasks.job.js +149 -0
- package/dist/background/session.d.ts +15 -5
- package/dist/background/session.js +22 -6
- package/dist/background/stop.d.ts +35 -5
- package/dist/background/stop.js +94 -8
- package/dist/background/store.d.ts +110 -3
- package/dist/background/store.js +205 -3
- package/dist/background/tasks.service.d.ts +18 -1
- package/dist/background/tasks.service.js +99 -9
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.js +1 -1
- package/dist/channels/inbound.js +2 -0
- package/dist/channels/phrases.d.ts +4 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/config/load.d.ts +18 -0
- package/dist/config/load.js +39 -1
- package/dist/config/permission-migration.d.ts +26 -0
- package/dist/config/permission-migration.js +64 -0
- package/dist/config/schema.d.ts +4 -1
- package/dist/config/schema.js +41 -10
- package/dist/conversations/conversations.controller.d.ts +1 -1
- package/dist/conversations/conversations.controller.js +1 -1
- package/dist/conversations/conversations.module.js +12 -0
- package/dist/conversations/conversations.service.d.ts +11 -2
- package/dist/conversations/conversations.service.js +97 -27
- package/dist/conversations/event-log.d.ts +1 -1
- package/dist/conversations/event-log.js +10 -2
- package/dist/conversations/events.d.ts +307 -4
- package/dist/conversations/events.js +286 -32
- package/dist/conversations/permission-profile-store.d.ts +50 -0
- package/dist/conversations/permission-profile-store.js +67 -0
- package/dist/conversations/permission-profile-store.module.d.ts +2 -0
- package/dist/conversations/permission-profile-store.module.js +19 -0
- package/dist/conversations/permission-profiles.controller.d.ts +84 -0
- package/dist/conversations/permission-profiles.controller.js +105 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
- package/dist/conversations/permission-profiles.schemas.js +23 -0
- package/dist/conversations/permission-profiles.service.d.ts +56 -0
- package/dist/conversations/permission-profiles.service.js +179 -0
- package/dist/ctx/create-ctx.d.ts +12 -5
- package/dist/ctx/create-ctx.js +21 -5
- package/dist/db/kernel-schema.d.ts +248 -3
- package/dist/devices/access.js +1 -1
- package/dist/devices/access.module.d.ts +2 -0
- package/dist/devices/access.module.js +19 -0
- package/dist/devices/conversation-devices.d.ts +8 -29
- package/dist/devices/conversation-devices.js +37 -73
- package/dist/devices/device-projects.service.d.ts +26 -28
- package/dist/devices/device-projects.service.js +123 -127
- package/dist/devices/devices.controller.js +3 -1
- package/dist/devices/devices.module.js +11 -9
- package/dist/devices/devices.service.d.ts +116 -8
- package/dist/devices/devices.service.js +252 -20
- package/dist/devices/dto.d.ts +16 -0
- package/dist/devices/dto.js +34 -6
- package/dist/devices/errors.d.ts +8 -0
- package/dist/devices/errors.js +10 -0
- package/dist/devices/project-rules.d.ts +44 -0
- package/dist/devices/project-rules.js +27 -0
- package/dist/devices/working-root.d.ts +6 -0
- package/dist/devices/working-root.js +12 -1
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +31 -0
- package/dist/evals/reconstruct.d.ts +19 -2
- package/dist/evals/reconstruct.js +40 -2
- package/dist/evals/recorded-permission-context.d.ts +77 -0
- package/dist/evals/recorded-permission-context.js +151 -0
- package/dist/evals/recorded-tools.d.ts +10 -1
- package/dist/evals/recorded-tools.js +27 -3
- package/dist/evals/run-replay.d.ts +8 -2
- package/dist/evals/run-replay.js +18 -2
- package/dist/evals/trajectory.d.ts +1 -1
- package/dist/evals/worker.d.ts +10 -1
- package/dist/evals/worker.js +23 -14
- package/dist/extensions/host.d.ts +4 -1
- package/dist/extensions/host.js +10 -6
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +14 -1
- package/dist/identity/accounts.js +61 -5
- package/dist/identity/identity.module.js +2 -0
- package/dist/identity/settings.d.ts +28 -12
- package/dist/identity/settings.js +89 -33
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
- package/dist/infra/cli/kernel-cli.module.js +5 -2
- package/dist/infra/cli/permission-cutover.d.ts +59 -0
- package/dist/infra/cli/permission-cutover.js +107 -0
- package/dist/infra/config/kernel-config.service.d.ts +2 -2
- package/dist/infra/config/kernel-config.service.js +35 -11
- package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
- package/dist/infra/database/startup-activation-transaction.js +242 -0
- package/dist/infra/database/transaction-host.d.ts +47 -0
- package/dist/infra/database/transaction-host.js +119 -0
- package/dist/infra/database/xact-lock.d.ts +1 -0
- package/dist/infra/database/xact-lock.js +6 -0
- package/dist/infra/outbox/registry.d.ts +39 -0
- package/dist/infra/outbox/registry.js +18 -0
- package/dist/kernel.module.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +55 -28
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +35 -5
- package/dist/local-devices/device-policy.service.js +188 -13
- package/dist/local-devices/instance-bindings.d.ts +82 -0
- package/dist/local-devices/instance-bindings.js +304 -0
- package/dist/local-devices/keys.d.ts +5 -0
- package/dist/local-devices/keys.js +5 -0
- package/dist/local-devices/local-device-gateway.d.ts +19 -4
- package/dist/local-devices/local-device-gateway.js +185 -17
- package/dist/local-devices/local-device-provider.d.ts +42 -7
- package/dist/local-devices/local-device-provider.js +185 -10
- package/dist/local-devices/local-devices.module.d.ts +17 -2
- package/dist/local-devices/local-devices.module.js +49 -8
- package/dist/local-devices/machines.d.ts +35 -12
- package/dist/local-devices/machines.js +203 -8
- package/dist/local-devices/network-grants.js +3 -3
- package/dist/local-devices/network-grants.module.d.ts +2 -0
- package/dist/local-devices/network-grants.module.js +14 -0
- package/dist/local-devices/owner-report.d.ts +79 -0
- package/dist/local-devices/owner-report.js +155 -0
- package/dist/local-devices/owner-reports.d.ts +48 -0
- package/dist/local-devices/owner-reports.js +190 -0
- package/dist/local-devices/policy-summary.d.ts +24 -1
- package/dist/local-devices/policy-summary.js +48 -0
- package/dist/local-devices/relay.d.ts +82 -6
- package/dist/local-devices/relay.js +187 -16
- package/dist/local-devices/targets.d.ts +16 -1
- package/dist/local-devices/targets.js +35 -2
- package/dist/models/image-usable.d.ts +22 -0
- package/dist/models/image-usable.js +29 -0
- package/dist/models/images.d.ts +125 -0
- package/dist/models/images.js +440 -0
- package/dist/models/models.module.d.ts +3 -2
- package/dist/models/models.module.js +16 -5
- package/dist/models/org-models.schemas.js +1 -0
- package/dist/models/purposes.controller.d.ts +7 -0
- package/dist/models/purposes.controller.js +9 -0
- package/dist/models/purposes.d.ts +28 -3
- package/dist/models/purposes.js +40 -13
- package/dist/orgs/cloud-network-setting.d.ts +33 -0
- package/dist/orgs/cloud-network-setting.js +47 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +8 -2
- package/dist/orgs/org-lock.d.ts +10 -4
- package/dist/orgs/org-lock.js +10 -4
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +8 -2
- package/dist/orgs/settings.controller.d.ts +4 -1
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +48 -56
- package/dist/orgs/settings.service.js +144 -101
- package/dist/overrides.d.ts +6 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin.ops.js +14 -11
- package/dist/platform/ops/agent-skills.ops.js +2 -0
- package/dist/platform/ops/devices.ops.js +10 -2
- package/dist/platform/ops/models.ops.js +10 -0
- package/dist/platform/ops/org-settings.ops.js +6 -6
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker.module.js +4 -0
- package/dist/runtime/context/build.d.ts +3 -1
- package/dist/runtime/context/build.js +19 -3
- package/dist/runtime/context/compaction.js +5 -0
- package/dist/runtime/context/device-paths.d.ts +9 -2
- package/dist/runtime/context/device-paths.js +20 -0
- package/dist/runtime/context/permission-profile.d.ts +46 -0
- package/dist/runtime/context/permission-profile.js +194 -0
- package/dist/runtime/hook-calls.d.ts +11 -1
- package/dist/runtime/hook-calls.js +24 -1
- package/dist/runtime/maintenance.d.ts +7 -1
- package/dist/runtime/maintenance.js +43 -15
- package/dist/runtime/model-call.d.ts +32 -0
- package/dist/runtime/model-call.js +67 -0
- package/dist/runtime/permission-context-errors.d.ts +39 -0
- package/dist/runtime/permission-context-errors.js +67 -0
- package/dist/runtime/permission-context.service.d.ts +60 -0
- package/dist/runtime/permission-context.service.js +286 -0
- package/dist/runtime/project/knowledge.d.ts +7 -2
- package/dist/runtime/project/knowledge.js +5 -2
- package/dist/runtime/project/knowledge.service.d.ts +17 -2
- package/dist/runtime/project/knowledge.service.js +76 -12
- package/dist/runtime/providers.d.ts +9 -5
- package/dist/runtime/providers.js +22 -3
- package/dist/runtime/run-execution.d.ts +4 -1
- package/dist/runtime/run-execution.js +14 -5
- package/dist/runtime/run-steps.d.ts +11 -3
- package/dist/runtime/run-steps.js +27 -4
- package/dist/runtime/runtime.module.js +11 -0
- package/dist/runtime/usage-report.d.ts +10 -6
- package/dist/runtime/usage-report.js +31 -11
- package/dist/sandbox/attachments-path.d.ts +15 -0
- package/dist/sandbox/attachments-path.js +15 -0
- package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
- package/dist/sandbox/cloud-permission-snapshot.js +407 -0
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
- package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
- package/dist/sandbox/held-operations.d.ts +39 -0
- package/dist/sandbox/held-operations.js +119 -0
- package/dist/sandbox/jobs.d.ts +14 -3
- package/dist/sandbox/jobs.js +20 -2
- package/dist/sandbox/kernel-read.d.ts +55 -0
- package/dist/sandbox/kernel-read.js +57 -0
- package/dist/sandbox/legacy-retirement.d.ts +336 -0
- package/dist/sandbox/legacy-retirement.js +1063 -0
- package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
- package/dist/sandbox/legacy-retirement.module.js +25 -0
- package/dist/sandbox/managed-device-context.d.ts +94 -0
- package/dist/sandbox/managed-device-context.js +308 -0
- package/dist/sandbox/managed-device-context.module.d.ts +6 -0
- package/dist/sandbox/managed-device-context.module.js +33 -0
- package/dist/sandbox/modes.d.ts +56 -8
- package/dist/sandbox/modes.js +92 -8
- package/dist/sandbox/operation-authority-types.d.ts +8 -0
- package/dist/sandbox/operation-authority-types.js +32 -0
- package/dist/sandbox/operation-authority.d.ts +145 -0
- package/dist/sandbox/operation-authority.js +783 -0
- package/dist/sandbox/operation-authority.module.d.ts +2 -0
- package/dist/sandbox/operation-authority.module.js +29 -0
- package/dist/sandbox/operation-intents.d.ts +206 -0
- package/dist/sandbox/operation-intents.js +1252 -0
- package/dist/sandbox/operation-intents.module.d.ts +2 -0
- package/dist/sandbox/operation-intents.module.js +21 -0
- package/dist/sandbox/operation-payloads.d.ts +33 -0
- package/dist/sandbox/operation-payloads.js +332 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
- package/dist/sandbox/operation-reconcile.job.js +247 -0
- package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
- package/dist/sandbox/permission-authority-epochs.js +83 -0
- package/dist/sandbox/permission-authority-lock.d.ts +38 -0
- package/dist/sandbox/permission-authority-lock.js +147 -0
- package/dist/sandbox/permission-authority.module.d.ts +9 -0
- package/dist/sandbox/permission-authority.module.js +55 -0
- package/dist/sandbox/permission-availability.d.ts +18 -0
- package/dist/sandbox/permission-availability.js +19 -0
- package/dist/sandbox/permission-call-grants.d.ts +34 -0
- package/dist/sandbox/permission-call-grants.js +349 -0
- package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
- package/dist/sandbox/permission-call-grants.module.js +21 -0
- package/dist/sandbox/permission-call-types.d.ts +82 -0
- package/dist/sandbox/permission-call-types.js +1 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
- package/dist/sandbox/permission-ceiling-writes.js +223 -0
- package/dist/sandbox/permission-config-publication.d.ts +76 -0
- package/dist/sandbox/permission-config-publication.js +339 -0
- package/dist/sandbox/permission-context-types.d.ts +64 -0
- package/dist/sandbox/permission-context-types.js +24 -0
- package/dist/sandbox/permission-facts.d.ts +206 -0
- package/dist/sandbox/permission-facts.js +627 -0
- package/dist/sandbox/permission-facts.module.d.ts +2 -0
- package/dist/sandbox/permission-facts.module.js +20 -0
- package/dist/sandbox/permission-instance-writes.d.ts +90 -0
- package/dist/sandbox/permission-instance-writes.js +305 -0
- package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
- package/dist/sandbox/permission-runtime-reports.js +354 -0
- package/dist/sandbox/permission-transitions.d.ts +31 -0
- package/dist/sandbox/permission-transitions.js +155 -0
- package/dist/sandbox/platform-full-access.d.ts +128 -0
- package/dist/sandbox/platform-full-access.js +210 -0
- package/dist/sandbox/providers.d.ts +22 -0
- package/dist/sandbox/providers.js +10 -2
- package/dist/sandbox/providers.module.d.ts +2 -0
- package/dist/sandbox/providers.module.js +19 -0
- package/dist/sandbox/request-not-sent.d.ts +13 -0
- package/dist/sandbox/request-not-sent.js +13 -0
- package/dist/sandbox/review/classifier.d.ts +2 -0
- package/dist/sandbox/review/classifier.js +8 -0
- package/dist/sandbox/review/permission-candidate.d.ts +12 -0
- package/dist/sandbox/review/permission-candidate.js +145 -0
- package/dist/sandbox/review/review.service.d.ts +5 -2
- package/dist/sandbox/review/review.service.js +60 -15
- package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
- package/dist/sandbox/sandbox-file-reader.js +51 -7
- package/dist/sandbox/sandbox.module.js +26 -6
- package/dist/sandbox/sandbox.service.d.ts +230 -34
- package/dist/sandbox/sandbox.service.js +1368 -199
- package/dist/sandbox/unreachable.js +17 -3
- package/dist/sandbox/use-context.d.ts +17 -0
- package/dist/sandbox/use-context.js +1 -0
- package/dist/skills/invoke.d.ts +27 -4
- package/dist/skills/invoke.js +72 -7
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.schemas.d.ts +1 -0
- package/dist/tools/approvals.schemas.js +3 -1
- package/dist/tools/approvals.service.d.ts +23 -10
- package/dist/tools/approvals.service.js +104 -26
- package/dist/tools/builtin-names.d.ts +3 -1
- package/dist/tools/builtin-names.js +5 -1
- package/dist/tools/builtins/artifacts.d.ts +43 -0
- package/dist/tools/builtins/artifacts.js +67 -0
- package/dist/tools/builtins/builtin-tools.d.ts +20 -2
- package/dist/tools/builtins/builtin-tools.js +61 -10
- package/dist/tools/builtins/image/generate.d.ts +59 -0
- package/dist/tools/builtins/image/generate.js +535 -0
- package/dist/tools/builtins/image/index.d.ts +2 -0
- package/dist/tools/builtins/image/index.js +2 -0
- package/dist/tools/builtins/image/paths.d.ts +12 -0
- package/dist/tools/builtins/image/paths.js +26 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
- package/dist/tools/builtins/sandbox/bash.js +201 -5
- package/dist/tools/builtins/sandbox/common.d.ts +92 -20
- package/dist/tools/builtins/sandbox/common.js +201 -17
- package/dist/tools/builtins/sandbox/deliver.js +9 -51
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +2 -2
- package/dist/tools/builtins/sandbox/task-list.js +7 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +172 -0
- package/dist/tools/builtins/sandbox/task-stop.js +25 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.js +9 -6
- package/dist/tools/device-op-resolver.d.ts +1 -1
- package/dist/tools/device-op-resolver.js +13 -3
- package/dist/tools/permission-approval-jobs.d.ts +18 -0
- package/dist/tools/permission-approval-jobs.js +92 -0
- package/dist/tools/pipeline.d.ts +17 -2
- package/dist/tools/pipeline.js +315 -26
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +15 -0
- package/package.json +4 -3
- package/src/migrations/0146_permission_authority_epochs.sql +6 -0
- package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
- package/src/migrations/0148_first_message_request_hash.sql +2 -0
- package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
- package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
- package/src/migrations/0151_starting_execution_grants.sql +8 -0
- package/src/migrations/0152_background_launch_identity.sql +66 -0
- package/src/migrations/0153_background_cancel_requester.sql +13 -0
- package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
- package/src/migrations/0155_device_instance_generations.sql +30 -0
- package/src/migrations/0156_device_owner_report.sql +7 -0
- package/src/migrations/0157_legacy_retirement.sql +116 -0
- package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
- package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
- package/src/migrations/0160_model_usage_image_kind.sql +10 -0
- package/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -15,6 +15,7 @@ import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
|
15
15
|
import { KERNEL_LOGGER } from "../../infra/tokens.js";
|
|
16
16
|
import { ModelPurposesService } from "../../models/purposes.js";
|
|
17
17
|
import { StepLog } from "../../runtime/step-log.js";
|
|
18
|
+
import { generateImagePaths } from "../../tools/builtins/image/paths.js";
|
|
18
19
|
import { boundMessages, newReviewTag, REVIEW_ASK_REASON, REVIEW_PURPOSE, runClassifier, } from "./classifier.js";
|
|
19
20
|
import { reviewRules, reviewWrite, writtenPaths } from "./rules.js";
|
|
20
21
|
import { applySessionGrants, isSessionGrantableRule, } from "./types.js";
|
|
@@ -29,8 +30,14 @@ export const REVIEW_REASONS = {
|
|
|
29
30
|
/** The person allowed this rule class for the conversation. */
|
|
30
31
|
sessionGrant: "Allowed for the rest of this conversation by an earlier approval.",
|
|
31
32
|
};
|
|
32
|
-
/**
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* The tools the review covers: the shell, and the file tools whose writes may leave the workspace
|
|
35
|
+
* (`GenerateImage` writes its images into the device at `file_path`, reviewed as a `Write`; a call
|
|
36
|
+
* without `file_path` writes nothing there and is not reviewed).
|
|
37
|
+
*/
|
|
38
|
+
const REVIEWED_TOOLS = new Set(["Bash", "Write", "Edit", "GenerateImage"]);
|
|
39
|
+
/** The reviewed tools that write a file at `file_path` (the rest run a shell command). */
|
|
40
|
+
const WRITE_TOOLS = new Set(["Write", "Edit", "GenerateImage"]);
|
|
34
41
|
/** How many of a conversation tree's latest assistant messages the review reads for its writes. */
|
|
35
42
|
const WRITTEN_EVENTS_READ = 200;
|
|
36
43
|
/** How many of the root conversation's latest person messages are read before bounding the text. */
|
|
@@ -94,17 +101,24 @@ let CommandReviewService = class CommandReviewService {
|
|
|
94
101
|
async decide(input) {
|
|
95
102
|
// not a reviewed tool, a sandbox-mode write (the tools stay root-confined), or no device: the
|
|
96
103
|
// tool call proceeds and fails on its own if it cannot
|
|
97
|
-
if (!REVIEWED_TOOLS.has(input.toolKey)) {
|
|
104
|
+
if (!REVIEWED_TOOLS.has(input.toolKey) && !input.permissionProfile) {
|
|
98
105
|
return allow(REVIEW_REASONS.notReviewed, null);
|
|
99
106
|
}
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
// a path call: the file writes, and a `Read` under a permission profile (its path is judged)
|
|
108
|
+
const isWrite = WRITE_TOOLS.has(input.toolKey) ||
|
|
109
|
+
(input.toolKey === "Read" && input.permissionProfile !== undefined);
|
|
110
|
+
// every path the call names (a GenerateImage call without file_path writes none)
|
|
111
|
+
const paths = isWrite ? writePathsOf(input.toolKey, input.input) : [];
|
|
112
|
+
if (isWrite && paths.length === 0)
|
|
113
|
+
return allow(REVIEW_REASONS.notReviewed, null);
|
|
114
|
+
if (input.mode === "sandbox" && isWrite && !input.permissionProfile) {
|
|
102
115
|
return allow(REVIEW_REASONS.sandboxWrite, null);
|
|
103
116
|
}
|
|
104
117
|
const workspace = input.workspace;
|
|
105
118
|
if (workspace === undefined)
|
|
106
119
|
return allow(REVIEW_REASONS.noDevice, null);
|
|
107
|
-
|
|
120
|
+
// the classifier reads every path a write call writes, one per line
|
|
121
|
+
const target = isWrite ? paths.join("\n") : commandOf(input.input);
|
|
108
122
|
if (target === null) {
|
|
109
123
|
// argument validation runs before this stage; a shape the tool itself will refuse
|
|
110
124
|
return allow(REVIEW_REASONS.notReviewed, null);
|
|
@@ -123,7 +137,7 @@ let CommandReviewService = class CommandReviewService {
|
|
|
123
137
|
};
|
|
124
138
|
// running a file this conversation wrote is not a development command (hardening spec R1)
|
|
125
139
|
const result = isWrite
|
|
126
|
-
?
|
|
140
|
+
? reviewWrites(paths, facts)
|
|
127
141
|
: reviewRules(target, {
|
|
128
142
|
...facts,
|
|
129
143
|
written: await this.writtenInTree(await rootOf(), facts),
|
|
@@ -137,10 +151,21 @@ let CommandReviewService = class CommandReviewService {
|
|
|
137
151
|
rule: hit?.id ?? null,
|
|
138
152
|
};
|
|
139
153
|
}
|
|
140
|
-
if (
|
|
154
|
+
if (input.permissionProfile === "full-access")
|
|
155
|
+
return allow("Current Full access covers discretionary review.", null);
|
|
156
|
+
if (input.permissionProfile && !input.permissionCandidate)
|
|
157
|
+
return allow("The enforced operation scope covers this call without expansion.", null);
|
|
158
|
+
if (input.permissionProfile === "request-approval")
|
|
159
|
+
return {
|
|
160
|
+
decision: "ask",
|
|
161
|
+
by: "rule",
|
|
162
|
+
rule: null,
|
|
163
|
+
reason: "Approve the exact proposed directory and host access for this call. File-only grants are not supported: directory approval covers its descendants; otherwise choose an in-project path.",
|
|
164
|
+
};
|
|
165
|
+
if (result.outcome === "allow" && !input.permissionCandidate) {
|
|
141
166
|
return allow(hit?.reason ?? "The command review allows this command.", hit?.id ?? null);
|
|
142
167
|
}
|
|
143
|
-
if (result.outcome === "ask") {
|
|
168
|
+
if (result.outcome === "ask" && !input.permissionCandidate) {
|
|
144
169
|
// a session grant covers its own class only, and only while the person is there to have
|
|
145
170
|
// given it (hardening spec R4, R6): every ask hit granted and nothing unsure left
|
|
146
171
|
const granted = input.attended ? await this.grantedRules(await rootOf()) : new Set();
|
|
@@ -203,6 +228,7 @@ let CommandReviewService = class CommandReviewService {
|
|
|
203
228
|
ruleHits: result.hits,
|
|
204
229
|
personMessages: await this.personMessages(await rootOf()),
|
|
205
230
|
tag: newReviewTag(),
|
|
231
|
+
...(input.permissionCandidate ? { permissionCandidate: input.permissionCandidate } : {}),
|
|
206
232
|
},
|
|
207
233
|
beforeSend: input.beforeSend,
|
|
208
234
|
});
|
|
@@ -291,8 +317,10 @@ let CommandReviewService = class CommandReviewService {
|
|
|
291
317
|
const written = new Set();
|
|
292
318
|
for (const row of rows) {
|
|
293
319
|
for (const call of toolCallsOf(row.payload)) {
|
|
294
|
-
if ((call.name
|
|
295
|
-
|
|
320
|
+
if (WRITE_TOOLS.has(call.name)) {
|
|
321
|
+
for (const path of writePathsOf(call.name, call.input)) {
|
|
322
|
+
written.add(path.startsWith("/") ? path : `${facts.workspace}/${path}`);
|
|
323
|
+
}
|
|
296
324
|
}
|
|
297
325
|
else if (call.name === "Bash" && typeof call.command === "string") {
|
|
298
326
|
for (const path of writtenPaths(call.command, facts))
|
|
@@ -342,7 +370,7 @@ function toolCallsOf(payload) {
|
|
|
342
370
|
if (block.type !== "tool_call" || typeof block.name !== "string")
|
|
343
371
|
return [];
|
|
344
372
|
const input = (block.input ?? {});
|
|
345
|
-
return [{ name: block.name,
|
|
373
|
+
return [{ name: block.name, input: block.input, command: input.command }];
|
|
346
374
|
});
|
|
347
375
|
}
|
|
348
376
|
/** The text blocks of a `user_message` payload (its images, documents and attachments are skipped). */
|
|
@@ -365,8 +393,25 @@ function commandOf(input) {
|
|
|
365
393
|
const command = input?.command;
|
|
366
394
|
return typeof command === "string" ? command : null;
|
|
367
395
|
}
|
|
368
|
-
/**
|
|
369
|
-
|
|
396
|
+
/**
|
|
397
|
+
* The paths a validated write call writes: `Write` / `Edit`'s `file_path`, every path of a
|
|
398
|
+
* `GenerateImage` call ({@link generateImagePaths}: none without `file_path`, the suffixed paths
|
|
399
|
+
* of several images). Empty when there is none (the file tools refuse such an input).
|
|
400
|
+
*/
|
|
401
|
+
function writePathsOf(toolKey, input) {
|
|
402
|
+
if (toolKey === "GenerateImage")
|
|
403
|
+
return generateImagePaths(input);
|
|
370
404
|
const path = input?.file_path;
|
|
371
|
-
return typeof path === "string" ? path :
|
|
405
|
+
return typeof path === "string" ? [path] : [];
|
|
406
|
+
}
|
|
407
|
+
const OUTCOME_RANK = { allow: 0, unsure: 1, ask: 2, deny: 3 };
|
|
408
|
+
/**
|
|
409
|
+
* The review of a call that writes several paths: each path reviewed as a `Write`, the worst
|
|
410
|
+
* outcome deciding (deny, then ask, then unsure) over all their hits, so the call is allowed only
|
|
411
|
+
* when every path is and a session grant settles it only when it covers every path's asks.
|
|
412
|
+
*/
|
|
413
|
+
function reviewWrites(paths, facts) {
|
|
414
|
+
const results = paths.map((p) => reviewWrite(p, facts));
|
|
415
|
+
const outcome = results.reduce((worst, r) => (OUTCOME_RANK[r.outcome] > OUTCOME_RANK[worst] ? r.outcome : worst), "allow");
|
|
416
|
+
return { outcome, hits: results.flatMap((r) => r.hits) };
|
|
372
417
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
2
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
3
|
import type { KernelLogger } from "../log.js";
|
|
4
|
+
import type { OperationInvocation } from "./operation-intents.js";
|
|
4
5
|
import { SandboxService } from "./sandbox.service.js";
|
|
5
6
|
/** What {@link SandboxFileReader.read} reads. */
|
|
6
7
|
export interface SandboxFileReadInput {
|
|
@@ -14,6 +15,11 @@ export interface SandboxFileReadInput {
|
|
|
14
15
|
/** The largest file accepted, in bytes. */
|
|
15
16
|
maxBytes: number;
|
|
16
17
|
signal: AbortSignal;
|
|
18
|
+
/**
|
|
19
|
+
* The tool call the read serves (the `Platform` call): once the activation gate is on, the read
|
|
20
|
+
* is a managed operation of that call under the run's current execution claim.
|
|
21
|
+
*/
|
|
22
|
+
callId?: string;
|
|
17
23
|
}
|
|
18
24
|
/**
|
|
19
25
|
* Reads one file from a conversation's sandbox for the kernel (skill authoring spec: a package
|
|
@@ -21,6 +27,10 @@ export interface SandboxFileReadInput {
|
|
|
21
27
|
* `Deliver` tool, with the same path checks, in the device of the conversation's tree (holder =
|
|
22
28
|
* the root conversation); no attachment sync and no `device_paths` record.
|
|
23
29
|
*
|
|
30
|
+
* Once the activation gate is on, {@link read} never takes the raw use: it is a managed operation
|
|
31
|
+
* of the serving tool call (`input.callId`) under the run's current execution claim, and without
|
|
32
|
+
* them nothing is entered (permission activation W3-L).
|
|
33
|
+
*
|
|
24
34
|
* Throws `ApiError` 422 `sandbox.file_invalid_path` / `sandbox.file_not_found` /
|
|
25
35
|
* `sandbox.file_is_directory` / `sandbox.file_too_large`; provider and device failures go through
|
|
26
36
|
* `mapSandboxError` (an actionable `ToolError`).
|
|
@@ -30,6 +40,13 @@ export declare class SandboxFileReader {
|
|
|
30
40
|
private readonly devices;
|
|
31
41
|
private readonly sandbox;
|
|
32
42
|
private readonly log;
|
|
33
|
-
|
|
43
|
+
/** The paired activation gate: once on, every read is a managed operation. */
|
|
44
|
+
private readonly activation?;
|
|
45
|
+
constructor(db: KernelDb, devices: Pick<ConversationDevices, "forTool">, sandbox: Pick<SandboxService, "withSandbox"> & Partial<Pick<SandboxService, "withOperations">>, log: Pick<KernelLogger, "warn">,
|
|
46
|
+
/** The paired activation gate: once on, every read is a managed operation. */
|
|
47
|
+
activation?: boolean | undefined);
|
|
34
48
|
read(input: SandboxFileReadInput): Promise<Uint8Array>;
|
|
49
|
+
/** Dormant caller adapter; the invoking tool supplies its actual current server execution identity. */
|
|
50
|
+
readOperation(input: SandboxFileReadInput, invocation: Omit<OperationInvocation, "ordinal">): Promise<Uint8Array>;
|
|
51
|
+
private readWith;
|
|
35
52
|
}
|
|
@@ -7,21 +7,29 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
11
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
10
|
+
import { SandboxScopeDeniedError, ToolError } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
12
|
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
14
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
15
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
16
|
+
import { currentExecutionClaim } from "../runtime/run-execution.js";
|
|
16
17
|
import { rootConversationOf } from "../runtime/subagents/child.js";
|
|
17
18
|
import { checkPath, checkPathShape, clip, mapSandboxError, } from "../tools/builtins/sandbox/common.js";
|
|
19
|
+
import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "./permission-context-types.js";
|
|
18
20
|
import { SandboxService } from "./sandbox.service.js";
|
|
21
|
+
/** How long one gate-on read may wait for admission (as a builtin tool call's operations). */
|
|
22
|
+
const READ_OPERATION_DEADLINE_MS = 30_000;
|
|
19
23
|
/**
|
|
20
24
|
* Reads one file from a conversation's sandbox for the kernel (skill authoring spec: a package
|
|
21
25
|
* the agent built is registered from its sandbox). The same stat -> readFile sequence as the
|
|
22
26
|
* `Deliver` tool, with the same path checks, in the device of the conversation's tree (holder =
|
|
23
27
|
* the root conversation); no attachment sync and no `device_paths` record.
|
|
24
28
|
*
|
|
29
|
+
* Once the activation gate is on, {@link read} never takes the raw use: it is a managed operation
|
|
30
|
+
* of the serving tool call (`input.callId`) under the run's current execution claim, and without
|
|
31
|
+
* them nothing is entered (permission activation W3-L).
|
|
32
|
+
*
|
|
25
33
|
* Throws `ApiError` 422 `sandbox.file_invalid_path` / `sandbox.file_not_found` /
|
|
26
34
|
* `sandbox.file_is_directory` / `sandbox.file_too_large`; provider and device failures go through
|
|
27
35
|
* `mapSandboxError` (an actionable `ToolError`).
|
|
@@ -31,24 +39,58 @@ let SandboxFileReader = class SandboxFileReader {
|
|
|
31
39
|
devices;
|
|
32
40
|
sandbox;
|
|
33
41
|
log;
|
|
34
|
-
|
|
42
|
+
activation;
|
|
43
|
+
constructor(db, devices, sandbox, log,
|
|
44
|
+
/** The paired activation gate: once on, every read is a managed operation. */
|
|
45
|
+
activation) {
|
|
35
46
|
this.db = db;
|
|
36
47
|
this.devices = devices;
|
|
37
48
|
this.sandbox = sandbox;
|
|
38
49
|
this.log = log;
|
|
50
|
+
this.activation = activation;
|
|
39
51
|
}
|
|
40
52
|
async read(input) {
|
|
53
|
+
if (!permissionContextActive(this.activation))
|
|
54
|
+
return this.readWith(input);
|
|
55
|
+
// the run this read serves: its current execution claim and the tool call, else nothing runs
|
|
56
|
+
const claim = currentExecutionClaim();
|
|
57
|
+
if (!claim || input.callId === undefined || claim.conversationId !== input.conversationId) {
|
|
58
|
+
invalidPathAsApiError(() => checkPathShape(input.path));
|
|
59
|
+
throw mapSandboxError(new SandboxScopeDeniedError("The read has no current server execution claim"), this.log);
|
|
60
|
+
}
|
|
61
|
+
return this.readWith(input, {
|
|
62
|
+
claim,
|
|
63
|
+
callId: input.callId,
|
|
64
|
+
deadlineMs: Date.now() + READ_OPERATION_DEADLINE_MS,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Dormant caller adapter; the invoking tool supplies its actual current server execution identity. */
|
|
68
|
+
async readOperation(input, invocation) {
|
|
69
|
+
return this.readWith(input, invocation);
|
|
70
|
+
}
|
|
71
|
+
async readWith(input, invocation) {
|
|
41
72
|
const { orgId, path: given, maxBytes: max } = input;
|
|
42
73
|
// the shape is checked before the sandbox is entered (nothing starts for a bad path)
|
|
43
74
|
invalidPathAsApiError(() => checkPathShape(given));
|
|
44
75
|
try {
|
|
45
76
|
const root = await rootConversationOf(this.db.db, input.conversationId);
|
|
46
77
|
const deviceId = await this.devices.forTool(orgId, root);
|
|
47
|
-
|
|
78
|
+
const enter = invocation
|
|
79
|
+
? (ctx, fn, signal) => {
|
|
80
|
+
if (!this.sandbox.withOperations)
|
|
81
|
+
throw new SandboxScopeDeniedError("Operation admission is unavailable");
|
|
82
|
+
return this.sandbox.withOperations(ctx, invocation, fn, signal);
|
|
83
|
+
}
|
|
84
|
+
: this.sandbox.withSandbox.bind(this.sandbox);
|
|
85
|
+
return await enter({
|
|
48
86
|
orgId,
|
|
49
87
|
deviceId,
|
|
50
|
-
holderConversationId: root,
|
|
51
|
-
actor: {
|
|
88
|
+
holderConversationId: invocation ? input.conversationId : root,
|
|
89
|
+
actor: {
|
|
90
|
+
accountId: input.actorAccountId,
|
|
91
|
+
conversationId: input.conversationId,
|
|
92
|
+
...(invocation && { runId: invocation.claim.runId }),
|
|
93
|
+
},
|
|
52
94
|
}, async (h, p, info, signal) => {
|
|
53
95
|
const path = invalidPathAsApiError(() => checkPath(given, info.roots));
|
|
54
96
|
const st = await p.stat(h, path, signal);
|
|
@@ -79,7 +121,9 @@ SandboxFileReader = __decorate([
|
|
|
79
121
|
__param(0, Inject(KernelDb)),
|
|
80
122
|
__param(1, Inject(ConversationDevices)),
|
|
81
123
|
__param(2, Inject(SandboxService)),
|
|
82
|
-
__param(3, Inject(KERNEL_LOGGER))
|
|
124
|
+
__param(3, Inject(KERNEL_LOGGER)),
|
|
125
|
+
__param(4, Optional()),
|
|
126
|
+
__param(4, Inject(PERMISSION_CONTEXT_ACTIVATION))
|
|
83
127
|
], SandboxFileReader);
|
|
84
128
|
export { SandboxFileReader };
|
|
85
129
|
/** Runs a path check of the sandbox tools, turning its `ToolError` into `sandbox.file_invalid_path`. */
|
|
@@ -8,14 +8,18 @@ import { Module } from "@nestjs/common";
|
|
|
8
8
|
import { BackgroundStoreModule } from "../background/store.module.js";
|
|
9
9
|
import { EventLogModule } from "../conversations/event-log.js";
|
|
10
10
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
11
|
-
import { ExtensionRegistryModule } from "../extensions/registry.js";
|
|
12
11
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
13
12
|
import { ModelsModule } from "../models/models.module.js";
|
|
14
13
|
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
15
14
|
import { StepLogModule } from "../runtime/step-log.js";
|
|
15
|
+
import { CloudPermissionSnapshotsModule } from "./cloud-permission-snapshot.module.js";
|
|
16
16
|
import { SandboxJobs } from "./jobs.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { LegacyRetirementModule } from "./legacy-retirement.module.js";
|
|
18
|
+
import { OperationAuthorityModule } from "./operation-authority.module.js";
|
|
19
|
+
import { OperationIntentsModule } from "./operation-intents.module.js";
|
|
20
|
+
import { PermissionAuthorityModule } from "./permission-authority.module.js";
|
|
21
|
+
import { PermissionFactsModule } from "./permission-facts.module.js";
|
|
22
|
+
import { SandboxProviderRegistryModule } from "./providers.module.js";
|
|
19
23
|
import { CommandReviewService } from "./review/review.service.js";
|
|
20
24
|
import { SandboxService } from "./sandbox.service.js";
|
|
21
25
|
/**
|
|
@@ -30,8 +34,14 @@ let SandboxModule = class SandboxModule {
|
|
|
30
34
|
SandboxModule = __decorate([
|
|
31
35
|
Module({
|
|
32
36
|
imports: [
|
|
33
|
-
|
|
37
|
+
SandboxProviderRegistryModule,
|
|
38
|
+
PermissionAuthorityModule,
|
|
39
|
+
PermissionFactsModule,
|
|
40
|
+
OperationIntentsModule,
|
|
41
|
+
OperationAuthorityModule,
|
|
34
42
|
BackgroundStoreModule,
|
|
43
|
+
LegacyRetirementModule,
|
|
44
|
+
CloudPermissionSnapshotsModule,
|
|
35
45
|
// the command review's classifier: the `review` purpose, its hooks, usage and audit writes
|
|
36
46
|
ModelsModule,
|
|
37
47
|
ExtensionsModule,
|
|
@@ -39,8 +49,18 @@ SandboxModule = __decorate([
|
|
|
39
49
|
StepLogModule,
|
|
40
50
|
QueueModule.registerQueue(MAINTENANCE_QUEUE_NAME),
|
|
41
51
|
],
|
|
42
|
-
providers: [
|
|
43
|
-
exports: [
|
|
52
|
+
providers: [SandboxService, SandboxJobs, CommandReviewService],
|
|
53
|
+
exports: [
|
|
54
|
+
SandboxProviderRegistryModule,
|
|
55
|
+
LegacyRetirementModule,
|
|
56
|
+
PermissionAuthorityModule,
|
|
57
|
+
SandboxService,
|
|
58
|
+
OperationIntentsModule,
|
|
59
|
+
OperationAuthorityModule,
|
|
60
|
+
SandboxJobs,
|
|
61
|
+
CommandReviewService,
|
|
62
|
+
CloudPermissionSnapshotsModule,
|
|
63
|
+
],
|
|
44
64
|
})
|
|
45
65
|
], SandboxModule);
|
|
46
66
|
export { SandboxModule };
|