@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
package/dist/tools/pipeline.js
CHANGED
|
@@ -22,7 +22,7 @@ import { audit } from "../identity/audit.js";
|
|
|
22
22
|
import { sha256Hex } from "../identity/hash.js";
|
|
23
23
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
24
24
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
25
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
25
|
+
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
26
26
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
27
27
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
28
28
|
import { DevicePolicyService } from "../local-devices/device-policy.service.js";
|
|
@@ -31,12 +31,18 @@ import { UNKNOWN_RESULT_TEXT } from "../runtime/context/pairing.js";
|
|
|
31
31
|
import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookScope, } from "../runtime/hook-calls.js";
|
|
32
32
|
import { subagentWaitingIdemKey } from "../runtime/loop.js";
|
|
33
33
|
import { assistantIdemKey, MAX_STEP_MODEL_CALLS, modelCallIdemKey } from "../runtime/model-call.js";
|
|
34
|
+
import { currentExecutionClaim } from "../runtime/run-execution.js";
|
|
34
35
|
import { rootSurfaceOf } from "../runtime/subagents/child.js";
|
|
35
36
|
import { SubagentMessages } from "../runtime/subagents/messages.js";
|
|
36
37
|
import { pairStoppedForks } from "../runtime/subagents/skill-fork.js";
|
|
37
38
|
import { SubagentsService } from "../runtime/subagents/subagents.service.js";
|
|
38
39
|
import { orgHostOutsideCeiling } from "../sandbox/modes.js";
|
|
40
|
+
import { SandboxOperationAuthority } from "../sandbox/operation-authority.js";
|
|
41
|
+
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
42
|
+
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
43
|
+
import { permissionScopeHash } from "../sandbox/permission-facts.js";
|
|
39
44
|
import { isSessionGrantableRule, } from "../sandbox/review/index.js";
|
|
45
|
+
import { buildPermissionCandidate } from "../sandbox/review/permission-candidate.js";
|
|
40
46
|
import { CommandReviewService } from "../sandbox/review/review.service.js";
|
|
41
47
|
import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRunOf, } from "../schedules/unattended.js";
|
|
42
48
|
import { skillLoadOfferedIn } from "../skills/catalog.js";
|
|
@@ -45,6 +51,7 @@ import { Breaker, breakerOpenMessage } from "./breaker.js";
|
|
|
45
51
|
import { SEND_MESSAGE, SUBAGENT_HANDBACK, TOOL_SEARCH } from "./builtin-names.js";
|
|
46
52
|
import { AGENT_TOOL, AgentToolInput } from "./builtins/agent.js";
|
|
47
53
|
import { HandbackInput } from "./builtins/handback.js";
|
|
54
|
+
import { generateImagePaths } from "./builtins/image/paths.js";
|
|
48
55
|
import { DEVICE_CODE_PATTERN, deviceCodeIdemKey, GITHUB_DEVICE_LOGIN_URL, } from "./builtins/sandbox/device-code.js";
|
|
49
56
|
import { SendMessageInput } from "./builtins/send-message.js";
|
|
50
57
|
import { isAlwaysLoaded, notLoadedText } from "./builtins/tool-search.js";
|
|
@@ -157,12 +164,32 @@ const personalMissingText = (connectorName) => `The user has not connected ${con
|
|
|
157
164
|
const orgMissingText = (connectorName) => `${connectorName} has no organization credential configured; ask an organization admin to set it up.`;
|
|
158
165
|
/** Optional provider: the pipeline's {@link ToolPipelineHooks} (tests). */
|
|
159
166
|
export const TOOL_PIPELINE_HOOKS = Symbol("TOOL_PIPELINE_HOOKS");
|
|
167
|
+
/** Review usage and hooks retain the same tree ancestry on both review routes. */
|
|
168
|
+
function reviewParentOf(parent) {
|
|
169
|
+
return parent === undefined
|
|
170
|
+
? {}
|
|
171
|
+
: {
|
|
172
|
+
parentRunId: parent.runId,
|
|
173
|
+
...(parent.budgetRunId !== undefined && { budgetRunId: parent.budgetRunId }),
|
|
174
|
+
parent: {
|
|
175
|
+
conversationId: parent.conversationId,
|
|
176
|
+
runId: parent.runId,
|
|
177
|
+
callId: parent.callId,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
160
181
|
/**
|
|
161
182
|
* The tools the command review covers (auto mode spec §5.1): the shell and the file tools whose
|
|
162
|
-
* writes may leave the workspace
|
|
163
|
-
* `
|
|
183
|
+
* writes may leave the workspace, and `GenerateImage` when it writes its images into the device
|
|
184
|
+
* (`file_path`; image generation spec §5.3, reviewed as a `Write`). Any other tool call is not
|
|
185
|
+
* reviewed (the review service answers `allow` for it too; the pipeline skips the facts read).
|
|
164
186
|
*/
|
|
165
|
-
const REVIEWED_TOOL_KEYS = new Set(["Bash", "Write", "Edit"]);
|
|
187
|
+
const REVIEWED_TOOL_KEYS = new Set(["Bash", "Write", "Edit", "GenerateImage"]);
|
|
188
|
+
/** Whether the review covers this call ({@link REVIEWED_TOOL_KEYS}; `GenerateImage` with a path). */
|
|
189
|
+
const isReviewedCall = (toolKey, input) => REVIEWED_TOOL_KEYS.has(toolKey) &&
|
|
190
|
+
(toolKey !== "GenerateImage" || generateImagePaths(input).length > 0);
|
|
191
|
+
/** The paths a reviewed write writes: `file_path`, or every path of a `GenerateImage` call. */
|
|
192
|
+
const writePathsOf = (toolKey, input) => toolKey === "GenerateImage" ? generateImagePaths(input) : [textField(input, "file_path")];
|
|
166
193
|
/** Whether the review holds a shell command or a file write, for the texts and the ask's detail. */
|
|
167
194
|
const reviewKindOf = (toolKey) => toolKey === "Bash" ? "command" : "write";
|
|
168
195
|
/**
|
|
@@ -315,6 +342,9 @@ const inputWait = (q) => ({
|
|
|
315
342
|
let ToolPipeline = class ToolPipeline {
|
|
316
343
|
config;
|
|
317
344
|
txHost;
|
|
345
|
+
permissionAuthority;
|
|
346
|
+
permissionGrants;
|
|
347
|
+
permissionLocks;
|
|
318
348
|
decide;
|
|
319
349
|
deps;
|
|
320
350
|
constructor(kdb, eventLog,
|
|
@@ -327,9 +357,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
327
357
|
/** The command review (auto mode spec §5.4); absent in hand-built pipelines. */
|
|
328
358
|
review,
|
|
329
359
|
/** The reviewed call's device facts; absent in hand-built pipelines. */
|
|
330
|
-
devices) {
|
|
360
|
+
devices, permissionAuthority, permissionGrants, permissionLocks) {
|
|
331
361
|
this.config = config;
|
|
332
362
|
this.txHost = txHost;
|
|
363
|
+
this.permissionAuthority = permissionAuthority;
|
|
364
|
+
this.permissionGrants = permissionGrants;
|
|
365
|
+
this.permissionLocks = permissionLocks;
|
|
333
366
|
this.deps = {
|
|
334
367
|
get db() {
|
|
335
368
|
return kdb.db;
|
|
@@ -668,7 +701,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
668
701
|
return fail(reviewed.content, outKey);
|
|
669
702
|
}
|
|
670
703
|
review = reviewed.review;
|
|
671
|
-
const
|
|
704
|
+
const reviewedRoots = { workingRoot: reviewed.workingRoot, against: reviewed.reviewedAgainst };
|
|
672
705
|
if (reviewed.commandAsk !== undefined)
|
|
673
706
|
authorization = approvalAuthorization(reviewed.commandAsk);
|
|
674
707
|
// tool.preExecute after policy and approval, before tool_call_started (F10)
|
|
@@ -801,11 +834,24 @@ let ToolPipeline = class ToolPipeline {
|
|
|
801
834
|
type: "tool_call_started",
|
|
802
835
|
runId: ctx.runId,
|
|
803
836
|
idemKey: idem.started(ctx.runId, call.id, attempt),
|
|
804
|
-
payload: {
|
|
837
|
+
payload: {
|
|
838
|
+
step: ctx.step,
|
|
839
|
+
callId: call.id,
|
|
840
|
+
toolKey: tool.key,
|
|
841
|
+
specHash: tool.specHash,
|
|
842
|
+
...(this.operationScoped(tool)
|
|
843
|
+
? {
|
|
844
|
+
permissionInput: {
|
|
845
|
+
callInputHash: permissionScopeHash(call.input),
|
|
846
|
+
resolvedInputHash: permissionScopeHash(input),
|
|
847
|
+
},
|
|
848
|
+
}
|
|
849
|
+
: {}),
|
|
850
|
+
},
|
|
805
851
|
},
|
|
806
852
|
]);
|
|
807
853
|
const t0 = Date.now();
|
|
808
|
-
let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools,
|
|
854
|
+
let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools, reviewedRoots);
|
|
809
855
|
const durationMs = Date.now() - t0;
|
|
810
856
|
await this.deps.hooks?.afterExecute?.(ctx.runId, call.id);
|
|
811
857
|
// scheduled tasks spec §7, `fail` mode: no one answers an input request or connects an app
|
|
@@ -953,15 +999,20 @@ let ToolPipeline = class ToolPipeline {
|
|
|
953
999
|
* asked is the whole truth on a resume: the call is never reviewed twice.
|
|
954
1000
|
*/
|
|
955
1001
|
async reviewCall(ctx, call, tool, input) {
|
|
1002
|
+
if (this.operationScoped(tool)) {
|
|
1003
|
+
const scoped = await this.reviewPermissionCall(ctx, call, tool, input);
|
|
1004
|
+
if (scoped)
|
|
1005
|
+
return scoped;
|
|
1006
|
+
}
|
|
956
1007
|
const review = this.deps.review;
|
|
957
1008
|
const devices = this.deps.devices;
|
|
958
1009
|
if (review === undefined || devices === undefined)
|
|
959
1010
|
return { kind: "continue" };
|
|
960
|
-
if (!
|
|
1011
|
+
if (!isReviewedCall(tool.key, input))
|
|
961
1012
|
return { kind: "continue" };
|
|
962
1013
|
const asked = await this.deps.approvals.commandForCall(ctx.runId, call.id);
|
|
963
1014
|
const rootConversationId = ctx.parent?.rootConversationId ?? ctx.conversationId;
|
|
964
|
-
if (asked !== null) {
|
|
1015
|
+
if (asked !== null && asked.status !== "superseded") {
|
|
965
1016
|
const settled = this.settledCommandAsk(asked, tool.key);
|
|
966
1017
|
// an approved call runs in the root it was reviewed against only while the device still runs
|
|
967
1018
|
// in the mode recorded with the ask; otherwise the tool decides its working root afresh. A
|
|
@@ -972,6 +1023,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
972
1023
|
if (now === null ||
|
|
973
1024
|
now.mode !== asked.command?.mode ||
|
|
974
1025
|
carriedRoot({ workspace: now.workspace, workingRoot: settled.workingRoot }) === undefined) {
|
|
1026
|
+
// the root the person approved stays the one judged (B-18): only the carried root goes
|
|
975
1027
|
return { ...settled, workingRoot: undefined };
|
|
976
1028
|
}
|
|
977
1029
|
}
|
|
@@ -1012,21 +1064,18 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1012
1064
|
step: ctx.step,
|
|
1013
1065
|
callId: call.id,
|
|
1014
1066
|
signal: ctx.signal,
|
|
1015
|
-
...(ctx.parent
|
|
1016
|
-
parentRunId: ctx.parent.runId,
|
|
1017
|
-
...(ctx.parent.budgetRunId !== undefined && { budgetRunId: ctx.parent.budgetRunId }),
|
|
1018
|
-
parent: {
|
|
1019
|
-
conversationId: ctx.parent.conversationId,
|
|
1020
|
-
runId: ctx.parent.runId,
|
|
1021
|
-
callId: ctx.parent.callId,
|
|
1022
|
-
},
|
|
1023
|
-
}),
|
|
1067
|
+
...reviewParentOf(ctx.parent),
|
|
1024
1068
|
agentId: ctx.agentId,
|
|
1025
1069
|
agentVersion: ctx.agentVersion,
|
|
1026
1070
|
...(ctx.conversationKind !== undefined && { conversationKind: ctx.conversationKind }),
|
|
1027
1071
|
});
|
|
1028
1072
|
if (verdict.decision === "allow") {
|
|
1029
|
-
return {
|
|
1073
|
+
return {
|
|
1074
|
+
kind: "continue",
|
|
1075
|
+
review: allowRecord(verdict),
|
|
1076
|
+
workingRoot: carriedRoot(facts),
|
|
1077
|
+
reviewedAgainst: facts.workingRoot,
|
|
1078
|
+
};
|
|
1030
1079
|
}
|
|
1031
1080
|
if (verdict.decision === "deny") {
|
|
1032
1081
|
return {
|
|
@@ -1053,10 +1102,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1053
1102
|
// the whole command the approval covers (the event keeps a clamped copy for display)
|
|
1054
1103
|
command,
|
|
1055
1104
|
// a relative path as it will be written: resolved against the working root
|
|
1105
|
+
// (every path a GenerateImage call writes, comma-separated)
|
|
1056
1106
|
...(kind === "write" && {
|
|
1057
|
-
path: clipText(
|
|
1058
|
-
?
|
|
1059
|
-
|
|
1107
|
+
path: clipText(writePathsOf(tool.key, input)
|
|
1108
|
+
.map((p) => facts.workingRoot === undefined ? p : pathAgainstWorkingRoot(p, facts.workingRoot))
|
|
1109
|
+
.join(", "), 4096),
|
|
1060
1110
|
}),
|
|
1061
1111
|
rule: verdict.rule,
|
|
1062
1112
|
reason: clipText(verdict.reason, COMMAND_ASK_TEXT_MAX_CHARS),
|
|
@@ -1094,6 +1144,215 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1094
1144
|
}
|
|
1095
1145
|
return { kind: "wait", wait: approvalWait(ask) };
|
|
1096
1146
|
}
|
|
1147
|
+
operationScoped(tool) {
|
|
1148
|
+
return tool.source.kind === "builtin" && this.deps.permissionOperations?.has(tool.key) === true;
|
|
1149
|
+
}
|
|
1150
|
+
/** This branch is unreachable for production legacy handlers until the caller cutover. */
|
|
1151
|
+
async reviewPermissionCall(ctx, call, tool, input) {
|
|
1152
|
+
if (!this.permissionAuthority ||
|
|
1153
|
+
!this.permissionGrants ||
|
|
1154
|
+
!this.permissionLocks ||
|
|
1155
|
+
!this.deps.devices ||
|
|
1156
|
+
!this.deps.review)
|
|
1157
|
+
return null;
|
|
1158
|
+
const permissionLocks = this.permissionLocks;
|
|
1159
|
+
const previous = await this.deps.approvals.commandForCall(ctx.runId, call.id);
|
|
1160
|
+
// A settled refusal belongs to this call, not to a replaceable permission revision.
|
|
1161
|
+
if (previous && !["pending", "approved", "superseded"].includes(previous.status))
|
|
1162
|
+
return this.settledCommandAsk(previous, tool.key);
|
|
1163
|
+
const device = await this.deps.devices.reviewFacts(ctx.orgId, ctx.parent?.rootConversationId ?? ctx.conversationId, ctx.conversationId);
|
|
1164
|
+
if (!device)
|
|
1165
|
+
return null;
|
|
1166
|
+
const use = {
|
|
1167
|
+
orgId: ctx.orgId,
|
|
1168
|
+
deviceId: device.deviceId,
|
|
1169
|
+
holderConversationId: ctx.conversationId,
|
|
1170
|
+
actor: { accountId: ctx.accountId, conversationId: ctx.conversationId, runId: ctx.runId },
|
|
1171
|
+
};
|
|
1172
|
+
const facts = await this.permissionAuthority.previewCall(use, { runId: ctx.runId, callId: call.id }, ctx.signal);
|
|
1173
|
+
if (facts.availability.state !== "supported" || facts.unattended)
|
|
1174
|
+
return null;
|
|
1175
|
+
if (tool.key === "Bash" && textField(input, "command").length > COMMAND_ASK_MAX_CHARS)
|
|
1176
|
+
return {
|
|
1177
|
+
kind: "result",
|
|
1178
|
+
content: commandTooLongText(textField(input, "command").length),
|
|
1179
|
+
review: denyRecord("rule", null, "The command exceeds the review limit"),
|
|
1180
|
+
};
|
|
1181
|
+
const built = facts.profile === "full-access"
|
|
1182
|
+
? { kind: "in-scope" }
|
|
1183
|
+
: buildPermissionCandidate({
|
|
1184
|
+
toolKey: tool.key,
|
|
1185
|
+
specHash: tool.specHash,
|
|
1186
|
+
rawInput: call.input,
|
|
1187
|
+
validatedInput: input,
|
|
1188
|
+
}, facts);
|
|
1189
|
+
if (built.kind === "unsupported")
|
|
1190
|
+
return {
|
|
1191
|
+
kind: "result",
|
|
1192
|
+
content: built.message,
|
|
1193
|
+
review: denyRecord("rule", null, built.message),
|
|
1194
|
+
};
|
|
1195
|
+
const candidate = built.kind === "proposal" ? built.candidate : undefined;
|
|
1196
|
+
if (previous &&
|
|
1197
|
+
previous.status !== "superseded" &&
|
|
1198
|
+
candidate &&
|
|
1199
|
+
previous.command?.permissionCandidate?.candidateHash === candidate.candidateHash) {
|
|
1200
|
+
if (previous.status !== "approved")
|
|
1201
|
+
return this.settledCommandAsk(previous, tool.key);
|
|
1202
|
+
const grant = await withTransactionFencePrelude(() => permissionLocks.acquire({
|
|
1203
|
+
orgId: facts.orgId,
|
|
1204
|
+
deviceId: facts.deviceId,
|
|
1205
|
+
rootConversationId: facts.rootConversationId,
|
|
1206
|
+
}, { kind: "admit" }), () => this.findPermissionGrant(candidate));
|
|
1207
|
+
if (grant)
|
|
1208
|
+
return this.settledCommandAsk(previous, tool.key);
|
|
1209
|
+
}
|
|
1210
|
+
if (candidate) {
|
|
1211
|
+
const existingGrant = await withTransactionFencePrelude(() => permissionLocks.acquire({
|
|
1212
|
+
orgId: facts.orgId,
|
|
1213
|
+
deviceId: facts.deviceId,
|
|
1214
|
+
rootConversationId: facts.rootConversationId,
|
|
1215
|
+
}, { kind: "admit" }), () => this.findPermissionGrant(candidate));
|
|
1216
|
+
if (existingGrant) {
|
|
1217
|
+
if (permissionScopeHash(existingGrant.expansion) !==
|
|
1218
|
+
permissionScopeHash(candidate.permissionScope))
|
|
1219
|
+
return {
|
|
1220
|
+
kind: "result",
|
|
1221
|
+
content: "This call already has different permission evidence; submit a new call with the intended directory scope.",
|
|
1222
|
+
review: denyRecord("rule", null, "Conflicting permission evidence"),
|
|
1223
|
+
};
|
|
1224
|
+
return {
|
|
1225
|
+
kind: "continue",
|
|
1226
|
+
workingRoot: carriedRoot(device),
|
|
1227
|
+
reviewedAgainst: facts.workingRoot,
|
|
1228
|
+
review: {
|
|
1229
|
+
decision: "allow",
|
|
1230
|
+
by: "classifier",
|
|
1231
|
+
rule: null,
|
|
1232
|
+
reason: "The exact current call already has approved permission evidence.",
|
|
1233
|
+
profile: facts.profile,
|
|
1234
|
+
profileRevision: facts.profileRevision,
|
|
1235
|
+
scopeRevision: facts.scopeRevision,
|
|
1236
|
+
decisionSource: "review-model",
|
|
1237
|
+
},
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
const verdict = await this.deps.review.review({
|
|
1242
|
+
orgId: ctx.orgId,
|
|
1243
|
+
conversationId: facts.rootConversationId,
|
|
1244
|
+
runId: ctx.runId,
|
|
1245
|
+
accountId: ctx.accountId,
|
|
1246
|
+
toolKey: tool.key,
|
|
1247
|
+
input,
|
|
1248
|
+
mode: device.mode,
|
|
1249
|
+
workspace: facts.workingRoot,
|
|
1250
|
+
home: device.home,
|
|
1251
|
+
deviceHome: device.deviceHome,
|
|
1252
|
+
attended: true,
|
|
1253
|
+
step: ctx.step,
|
|
1254
|
+
callId: call.id,
|
|
1255
|
+
signal: ctx.signal,
|
|
1256
|
+
...reviewParentOf(ctx.parent),
|
|
1257
|
+
agentId: ctx.agentId,
|
|
1258
|
+
agentVersion: ctx.agentVersion,
|
|
1259
|
+
...(ctx.conversationKind ? { conversationKind: ctx.conversationKind } : {}),
|
|
1260
|
+
permissionProfile: facts.profile,
|
|
1261
|
+
...(candidate ? { permissionCandidate: candidate } : {}),
|
|
1262
|
+
});
|
|
1263
|
+
if (candidate && facts.profile === "approve-for-me") {
|
|
1264
|
+
await withTransactionFencePrelude(() => permissionLocks.acquire({
|
|
1265
|
+
orgId: facts.orgId,
|
|
1266
|
+
deviceId: facts.deviceId,
|
|
1267
|
+
rootConversationId: facts.rootConversationId,
|
|
1268
|
+
}, { kind: "admit" }), () => this.recordPermissionReview(candidate, verdict));
|
|
1269
|
+
}
|
|
1270
|
+
const provenance = {
|
|
1271
|
+
profile: facts.profile,
|
|
1272
|
+
profileRevision: facts.profileRevision,
|
|
1273
|
+
scopeRevision: facts.scopeRevision,
|
|
1274
|
+
};
|
|
1275
|
+
if (verdict.decision === "deny")
|
|
1276
|
+
return {
|
|
1277
|
+
kind: "result",
|
|
1278
|
+
content: commandDeniedText(verdict.reason, reviewKindOf(tool.key)),
|
|
1279
|
+
review: { ...denyRecord(verdict.by, verdict.rule, verdict.reason), ...provenance },
|
|
1280
|
+
};
|
|
1281
|
+
if (verdict.decision === "allow")
|
|
1282
|
+
return {
|
|
1283
|
+
kind: "continue",
|
|
1284
|
+
workingRoot: carriedRoot(device),
|
|
1285
|
+
reviewedAgainst: facts.workingRoot,
|
|
1286
|
+
review: {
|
|
1287
|
+
...allowRecord(verdict),
|
|
1288
|
+
...provenance,
|
|
1289
|
+
decisionSource: facts.profile === "full-access" ? "full-access" : candidate ? "review-model" : "scope",
|
|
1290
|
+
},
|
|
1291
|
+
};
|
|
1292
|
+
if (!candidate)
|
|
1293
|
+
return {
|
|
1294
|
+
kind: "result",
|
|
1295
|
+
content: "Current permission review could not decide; retry with an explicit bounded directory or host.",
|
|
1296
|
+
review: denyRecord(verdict.by, verdict.rule, verdict.reason),
|
|
1297
|
+
};
|
|
1298
|
+
const ask = await this.deps.approvals.requestCommand({
|
|
1299
|
+
orgId: ctx.orgId,
|
|
1300
|
+
conversationId: ctx.conversationId,
|
|
1301
|
+
runId: ctx.runId,
|
|
1302
|
+
step: ctx.step,
|
|
1303
|
+
callId: call.id,
|
|
1304
|
+
requestedFor: ctx.accountId,
|
|
1305
|
+
scopes: ["once"],
|
|
1306
|
+
detail: {
|
|
1307
|
+
deviceId: device.deviceId,
|
|
1308
|
+
deviceName: device.deviceName,
|
|
1309
|
+
mode: device.mode,
|
|
1310
|
+
kind: reviewKindOf(tool.key),
|
|
1311
|
+
command: tool.key === "Bash" ? textField(input, "command") : tool.key,
|
|
1312
|
+
rule: verdict.rule,
|
|
1313
|
+
reason: verdict.reason,
|
|
1314
|
+
workingRoot: facts.workingRoot,
|
|
1315
|
+
permissionCandidate: candidate,
|
|
1316
|
+
permissionScope: candidate.permissionScope,
|
|
1317
|
+
candidateHash: candidate.candidateHash,
|
|
1318
|
+
...(candidate.targetPath
|
|
1319
|
+
? { targetPath: candidate.targetPath, path: candidate.targetPath }
|
|
1320
|
+
: {}),
|
|
1321
|
+
},
|
|
1322
|
+
});
|
|
1323
|
+
return { kind: "wait", wait: approvalWait(ask) };
|
|
1324
|
+
}
|
|
1325
|
+
findPermissionGrant(candidate) {
|
|
1326
|
+
if (!this.permissionGrants)
|
|
1327
|
+
throw new Error("Permission grants are unavailable");
|
|
1328
|
+
return this.permissionGrants.findForAdmission(candidate.binding);
|
|
1329
|
+
}
|
|
1330
|
+
async recordPermissionReview(candidate, verdict) {
|
|
1331
|
+
if (!this.permissionGrants)
|
|
1332
|
+
throw new Error("Permission grants are unavailable");
|
|
1333
|
+
await this.permissionGrants.assertCurrent(candidate.binding);
|
|
1334
|
+
const events = await this.deps.eventLog.appendIn(candidate.binding.conversationId, [
|
|
1335
|
+
{
|
|
1336
|
+
type: "permission_reviewed",
|
|
1337
|
+
runId: candidate.binding.runId,
|
|
1338
|
+
payload: {
|
|
1339
|
+
...candidate,
|
|
1340
|
+
outcome: verdict.decision,
|
|
1341
|
+
reason: verdict.reason,
|
|
1342
|
+
decisionSource: "review-model",
|
|
1343
|
+
},
|
|
1344
|
+
},
|
|
1345
|
+
]);
|
|
1346
|
+
const event = events[0];
|
|
1347
|
+
if (!event)
|
|
1348
|
+
throw new Error("The review event was not recorded");
|
|
1349
|
+
if (verdict.decision === "allow")
|
|
1350
|
+
await this.permissionGrants.issueLocked(candidate, {
|
|
1351
|
+
source: "review-model",
|
|
1352
|
+
reviewEventSeq: event.seq,
|
|
1353
|
+
decidedBy: null,
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1097
1356
|
/** The outcome of a call whose `command` approval was already asked (a resume). */
|
|
1098
1357
|
settledCommandAsk(ask, toolKey) {
|
|
1099
1358
|
const kind = reviewKindOf(toolKey);
|
|
@@ -1106,6 +1365,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1106
1365
|
commandAsk: ask,
|
|
1107
1366
|
review: this.personAllowRecord(ask),
|
|
1108
1367
|
workingRoot: ask.command?.workingRoot,
|
|
1368
|
+
reviewedAgainst: ask.command?.workingRoot,
|
|
1109
1369
|
};
|
|
1110
1370
|
}
|
|
1111
1371
|
if (ask.status === "denied") {
|
|
@@ -1124,7 +1384,16 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1124
1384
|
* command the SHA-256 of the text the ask holds in full, so an audit can match record and text.
|
|
1125
1385
|
*/
|
|
1126
1386
|
personAllowRecord(ask) {
|
|
1387
|
+
const binding = ask.command?.permissionCandidate?.binding;
|
|
1127
1388
|
return {
|
|
1389
|
+
...(binding
|
|
1390
|
+
? {
|
|
1391
|
+
profile: binding.profile,
|
|
1392
|
+
profileRevision: binding.profileRevision,
|
|
1393
|
+
scopeRevision: binding.scopeRevision,
|
|
1394
|
+
decisionSource: "human",
|
|
1395
|
+
}
|
|
1396
|
+
: {}),
|
|
1128
1397
|
decision: "allow",
|
|
1129
1398
|
by: "person",
|
|
1130
1399
|
rule: ask.command?.rule ?? null,
|
|
@@ -1317,7 +1586,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1317
1586
|
* 带 `tools.timeoutMs` 超时与 run 的中止信号(合并后传给处理函数 / 连接器,不响应信号的也按时结束)。
|
|
1318
1587
|
* 熔断只作用于连接器工具(键为组织 × 连接器)。
|
|
1319
1588
|
*/
|
|
1320
|
-
async execute(tool, input, ctx, callId, resume, stepTools,
|
|
1589
|
+
async execute(tool, input, ctx, callId, resume, stepTools, reviewed) {
|
|
1590
|
+
const reviewedWorkingRoot = reviewed?.workingRoot;
|
|
1591
|
+
const reviewedAgainstRoot = reviewed?.against;
|
|
1321
1592
|
if (tool.source.kind === "connector") {
|
|
1322
1593
|
return this.executeConnector(tool, tool.source, input, ctx, resume);
|
|
1323
1594
|
}
|
|
@@ -1337,12 +1608,18 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1337
1608
|
ownerAccountId: ctx.ownerAccountId,
|
|
1338
1609
|
role: ctx.role,
|
|
1339
1610
|
...(tool.source.kind === "builtin" && stepTools !== undefined && { tools: stepTools }),
|
|
1340
|
-
...(tool.source.kind === "builtin" && {
|
|
1611
|
+
...(tool.source.kind === "builtin" && {
|
|
1612
|
+
runId: ctx.runId,
|
|
1613
|
+
executionClaim: currentExecutionClaim(),
|
|
1614
|
+
}),
|
|
1341
1615
|
...(tool.source.kind === "builtin" &&
|
|
1342
1616
|
ctx.deadline !== undefined && { runDeadline: ctx.deadline }),
|
|
1343
1617
|
// a reviewed call runs in the working root its review judged (project root spec §4.3)
|
|
1344
1618
|
...(tool.source.kind === "builtin" &&
|
|
1345
1619
|
reviewedWorkingRoot !== undefined && { reviewedWorkingRoot }),
|
|
1620
|
+
// and the root it was judged against, workspace included (B-18, the managed route)
|
|
1621
|
+
...(tool.source.kind === "builtin" &&
|
|
1622
|
+
reviewedAgainstRoot !== undefined && { reviewedAgainstRoot }),
|
|
1346
1623
|
// a sub-agent works in its root conversation's sandbox (spec §10.1, at every depth)
|
|
1347
1624
|
...(tool.source.kind === "builtin" &&
|
|
1348
1625
|
ctx.parent !== undefined && { sandboxConversationId: ctx.parent.rootConversationId }),
|
|
@@ -1758,6 +2035,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1758
2035
|
__decorate([
|
|
1759
2036
|
Transactional({ propagation: "mandatory" })
|
|
1760
2037
|
], ToolPipeline.prototype, "stopOpenAgentCalls", null);
|
|
2038
|
+
__decorate([
|
|
2039
|
+
Transactional()
|
|
2040
|
+
], ToolPipeline.prototype, "findPermissionGrant", null);
|
|
2041
|
+
__decorate([
|
|
2042
|
+
Transactional()
|
|
2043
|
+
], ToolPipeline.prototype, "recordPermissionReview", null);
|
|
1761
2044
|
__decorate([
|
|
1762
2045
|
Transactional()
|
|
1763
2046
|
], ToolPipeline.prototype, "writeResultIn", null);
|
|
@@ -1789,6 +2072,12 @@ ToolPipeline = __decorate([
|
|
|
1789
2072
|
__param(20, Optional()),
|
|
1790
2073
|
__param(20, Inject(CommandReviewService)),
|
|
1791
2074
|
__param(21, Optional()),
|
|
1792
|
-
__param(21, Inject(ConversationDevices))
|
|
2075
|
+
__param(21, Inject(ConversationDevices)),
|
|
2076
|
+
__param(22, Optional()),
|
|
2077
|
+
__param(22, Inject(SandboxOperationAuthority)),
|
|
2078
|
+
__param(23, Optional()),
|
|
2079
|
+
__param(23, Inject(PermissionCallGrants)),
|
|
2080
|
+
__param(24, Optional()),
|
|
2081
|
+
__param(24, Inject(PermissionAuthorityLock))
|
|
1793
2082
|
], ToolPipeline);
|
|
1794
2083
|
export { ToolPipeline };
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
8
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
9
9
|
import type { OrgRole } from "../orgs/roles.js";
|
|
10
10
|
import type { ConversationKindForHooks } from "../runtime/hook-calls.js";
|
|
11
|
+
import type { ExecutionClaim } from "../runtime/run-execution.js";
|
|
11
12
|
import { BuiltinTools } from "./builtins/builtin-tools.js";
|
|
12
13
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
13
14
|
export { BUILTIN_TOOL_NAMES } from "./builtin-names.js";
|
|
@@ -34,6 +35,8 @@ export interface ToolRefIssue {
|
|
|
34
35
|
* (`ToolSearch` 据此搜索)。插件处理函数收到的仍是 `ToolCallContext`。
|
|
35
36
|
*/
|
|
36
37
|
export interface BuiltinCallContext extends ToolCallContext {
|
|
38
|
+
/** Server execution identity only; operation admission revalidates current PG ownership. */
|
|
39
|
+
executionClaim?: Readonly<ExecutionClaim> | undefined;
|
|
37
40
|
tools?: readonly ResolvedTool[];
|
|
38
41
|
/** 本次运行 id(内置工具写自己的事件时用,如沙箱 deliver 的 `artifact_created`)。 */
|
|
39
42
|
runId?: string;
|
|
@@ -56,6 +59,12 @@ export interface BuiltinCallContext extends ToolCallContext {
|
|
|
56
59
|
* was reviewed. Absent for a call the review does not cover.
|
|
57
60
|
*/
|
|
58
61
|
reviewedWorkingRoot?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The root the command review judged the call against, the workspace included (B-18): on the
|
|
64
|
+
* managed route a held device context naming another root refuses the call as stale before it
|
|
65
|
+
* runs. Absent for a call the review does not cover.
|
|
66
|
+
*/
|
|
67
|
+
reviewedAgainstRoot?: string;
|
|
59
68
|
/** The parent run of a sub-agent's run (absent for a top-level run). */
|
|
60
69
|
parentRunId?: string;
|
|
61
70
|
/**
|
|
@@ -17,9 +17,14 @@ import { ModelsModule } from "../models/models.module.js";
|
|
|
17
17
|
import { OrgLockModule } from "../orgs/org-lock.js";
|
|
18
18
|
import { PlatformModule } from "../platform/platform.module.js";
|
|
19
19
|
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
20
|
+
import { ProvidersModule } from "../runtime/providers.js";
|
|
20
21
|
import { RunJobsModule } from "../runtime/run-jobs.js";
|
|
21
22
|
import { StepLogModule } from "../runtime/step-log.js";
|
|
22
23
|
import { SubagentsModule } from "../runtime/subagents/subagents.service.js";
|
|
24
|
+
import { ManagedDeviceContextModule } from "../sandbox/managed-device-context.module.js";
|
|
25
|
+
import { OperationAuthorityModule } from "../sandbox/operation-authority.module.js";
|
|
26
|
+
import { PermissionAuthorityModule } from "../sandbox/permission-authority.module.js";
|
|
27
|
+
import { PermissionCallGrantsModule } from "../sandbox/permission-call-grants.module.js";
|
|
23
28
|
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
24
29
|
import { ScheduledTaskStoreModule } from "../schedules/store.module.js";
|
|
25
30
|
import { SkillsModule } from "../skills/skills.module.js";
|
|
@@ -40,6 +45,7 @@ import { ConversationToolInfo, OrgExtensionTools } from "./info.js";
|
|
|
40
45
|
import { OAuthFlow } from "./oauth/flow.js";
|
|
41
46
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
42
47
|
import { ToolOutputs } from "./outputs.js";
|
|
48
|
+
import { PermissionApprovalJobs } from "./permission-approval-jobs.js";
|
|
43
49
|
import { ToolPipeline } from "./pipeline.js";
|
|
44
50
|
import { QuestionsService } from "./questions.service.js";
|
|
45
51
|
import { ToolRegistry } from "./registry.js";
|
|
@@ -56,6 +62,9 @@ let ToolsModule = class ToolsModule {
|
|
|
56
62
|
ToolsModule = __decorate([
|
|
57
63
|
Module({
|
|
58
64
|
imports: [
|
|
65
|
+
PermissionCallGrantsModule,
|
|
66
|
+
PermissionAuthorityModule,
|
|
67
|
+
OperationAuthorityModule,
|
|
59
68
|
EventLogModule,
|
|
60
69
|
AttachmentsModule,
|
|
61
70
|
ExtensionsModule,
|
|
@@ -66,6 +75,8 @@ ToolsModule = __decorate([
|
|
|
66
75
|
SubagentsModule,
|
|
67
76
|
// the builtin sandbox and skill tools run in the conversation's device
|
|
68
77
|
SandboxModule,
|
|
78
|
+
// the managed sandbox route's device context writer (passed only once activated)
|
|
79
|
+
ManagedDeviceContextModule,
|
|
69
80
|
DevicesModule,
|
|
70
81
|
// 「这台设备一直允许」 changes the device's local policy (network asks)
|
|
71
82
|
LocalDevicesModule,
|
|
@@ -75,6 +86,8 @@ ToolsModule = __decorate([
|
|
|
75
86
|
ConversationAccessModule,
|
|
76
87
|
// the WebFetch extraction call: its purpose and step writes (its usage report owed with them)
|
|
77
88
|
ModelsModule,
|
|
89
|
+
// `GenerateImage`'s availability resolves the image purpose's model in the org
|
|
90
|
+
ProvidersModule,
|
|
78
91
|
StepLogModule,
|
|
79
92
|
// a decision resumes its waiting run in the decision's transaction (`RunResume`)
|
|
80
93
|
RunJobsModule,
|
|
@@ -87,6 +100,7 @@ ToolsModule = __decorate([
|
|
|
87
100
|
CredentialsModule,
|
|
88
101
|
],
|
|
89
102
|
providers: [
|
|
103
|
+
PermissionApprovalJobs,
|
|
90
104
|
ToolOutputs,
|
|
91
105
|
BuiltinTools,
|
|
92
106
|
// `ScheduleUpdate`'s write in one transaction (scheduled tasks spec §11)
|
|
@@ -112,6 +126,7 @@ ToolsModule = __decorate([
|
|
|
112
126
|
DeviceOpResolver,
|
|
113
127
|
],
|
|
114
128
|
exports: [
|
|
129
|
+
PermissionApprovalJobs,
|
|
115
130
|
ScheduleToolsPort,
|
|
116
131
|
CredentialsModule,
|
|
117
132
|
ToolOutputs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.43",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"yaml": "^2.9.1",
|
|
66
66
|
"yauzl": "3.4.0",
|
|
67
67
|
"zod": "^4.6.7",
|
|
68
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
68
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.32"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -74,7 +74,8 @@
|
|
|
74
74
|
"@types/ws": "^8.18.2",
|
|
75
75
|
"@types/yauzl": "3.4.0",
|
|
76
76
|
"ws": "^8.22.0",
|
|
77
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
77
|
+
"@capybara-hq/testing": "0.1.0-rc.25",
|
|
78
|
+
"@capybara-hq/device": "0.1.0-rc.14"
|
|
78
79
|
},
|
|
79
80
|
"scripts": {
|
|
80
81
|
"build": "tsc -b"
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- Preserve existing independent device/org ceilings; profiles grant no device authority.
|
|
2
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS permission_profile text NOT NULL DEFAULT 'approve-for-me' CHECK (permission_profile IN ('request-approval', 'approve-for-me', 'full-access'));
|
|
3
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS permission_revision integer NOT NULL DEFAULT 0;
|
|
4
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS permission_consent jsonb;
|