@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.42
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 +1 -1
- package/dist/config/schema.js +11 -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 +304 -4
- package/dist/conversations/events.js +279 -29
- 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/db/kernel-schema.d.ts +238 -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/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 +31 -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/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/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/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/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/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 +129 -0
- package/dist/sandbox/review/review.service.d.ts +4 -1
- package/dist/sandbox/review/review.service.js +19 -5
- 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/builtins/builtin-tools.d.ts +16 -2
- package/dist/tools/builtins/builtin-tools.js +38 -10
- 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 +2 -2
- 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 +300 -19
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +12 -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/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -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 };
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SandboxBrowse, type SandboxPreparation, type SandboxPreparationScope } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { type HeldProvider } from "./held-operations.js";
|
|
3
|
+
import { SandboxOperationAuthority } from "./operation-authority.js";
|
|
4
|
+
import { type OperationInvocation, SandboxOperationIntents } from "./operation-intents.js";
|
|
5
|
+
import { PermissionInstanceWrites } from "./permission-instance-writes.js";
|
|
6
|
+
export type { HeldProvider } from "./held-operations.js";
|
|
7
|
+
import { type ExecResult, type SandboxHandle, type SandboxLimits, type SandboxProvider, type SandboxRoots } from "@capybara-hq/plugin-sdk";
|
|
2
8
|
import type { Redis } from "ioredis";
|
|
3
9
|
import { type Selectable } from "kysely";
|
|
4
10
|
import { BackgroundTaskStore } from "../background/store.js";
|
|
@@ -8,10 +14,18 @@ import { ApiError } from "../errors.js";
|
|
|
8
14
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
9
15
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
10
16
|
import type { KernelLogger } from "../log.js";
|
|
17
|
+
import { CloudPermissionSnapshots, type CloudSnapshotOutcome } from "./cloud-permission-snapshot.js";
|
|
18
|
+
import { type KernelReadInvocation } from "./kernel-read.js";
|
|
11
19
|
import { SandboxLeases, type SandboxPathLease } from "./leases.js";
|
|
20
|
+
import { LegacyRetirementStore } from "./legacy-retirement.js";
|
|
12
21
|
import { type AppliedLimits, type EffectiveDevicePolicy } from "./modes.js";
|
|
22
|
+
import type { HeldDeviceContextEvidence } from "./permission-context-types.js";
|
|
23
|
+
import { PermissionFacts } from "./permission-facts.js";
|
|
13
24
|
import { SandboxProviders } from "./providers.js";
|
|
25
|
+
import type { SandboxUseContext } from "./use-context.js";
|
|
26
|
+
export { deviceNotFound } from "../devices/errors.js";
|
|
14
27
|
export { SANDBOX_LOCK_PREFIX, SANDBOX_LOCK_TTL_MS, SandboxLockLostError, sandboxBusy, } from "./leases.js";
|
|
28
|
+
export type { SandboxUseContext } from "./use-context.js";
|
|
15
29
|
/** The third argument of the `withSandbox` callback. */
|
|
16
30
|
export interface SandboxUseInfo {
|
|
17
31
|
/** This call created the instance (first use, or a rebuild). */
|
|
@@ -32,22 +46,13 @@ export interface SandboxUseInfo {
|
|
|
32
46
|
* them (environments spec §13.1; a connected machine's real paths).
|
|
33
47
|
*/
|
|
34
48
|
roots: SandboxRoots;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/** Passed with every `exec` (audit and attribution). */
|
|
43
|
-
actor: SandboxActor;
|
|
44
|
-
/**
|
|
45
|
-
* A use that tells the model nothing (the run-start read of a bound project): it does not mark
|
|
46
|
-
* the holder as having seen the instance, so the holder's next ordinary use still learns that
|
|
47
|
-
* the instance started, restarted or had its files reset ({@link SandboxUseInfo}); what this use
|
|
48
|
-
* itself caused (a creation, a rebuild) is kept for that next use.
|
|
49
|
-
*/
|
|
50
|
-
silent?: true;
|
|
49
|
+
/**
|
|
50
|
+
* Kernel-private: what this managed entry holds for the device's model-facing context (the
|
|
51
|
+
* entered provider, the held instance id and generation, its installed binding, its roots and the
|
|
52
|
+
* base working root), present only when the invocation asked for it and the held instance has
|
|
53
|
+
* an installed binding. Never an SDK field, never read from model or tool input.
|
|
54
|
+
*/
|
|
55
|
+
contextEvidence?: HeldDeviceContextEvidence;
|
|
51
56
|
}
|
|
52
57
|
export type { SandboxProviderEntry } from "./providers.js";
|
|
53
58
|
type Row = Selectable<DeviceInstancesTable>;
|
|
@@ -65,9 +70,6 @@ interface Instance {
|
|
|
65
70
|
* The provider {@link SandboxService.withSandbox} passes to its callback: every `exec` carries the
|
|
66
71
|
* holder's tag and the caller's actor, so the callback passes neither.
|
|
67
72
|
*/
|
|
68
|
-
export type HeldProvider = Omit<SandboxProvider, "exec"> & {
|
|
69
|
-
exec(h: SandboxHandle, args: Omit<ExecArgs, "tag" | "actor">): Promise<ExecResult>;
|
|
70
|
-
};
|
|
71
73
|
/**
|
|
72
74
|
* The provider {@link SandboxService.ifRunning} passes to its callback: every `exec` carries the
|
|
73
75
|
* holder's tag; the caller names the actor.
|
|
@@ -105,8 +107,6 @@ export interface DeviceLimitsState {
|
|
|
105
107
|
}
|
|
106
108
|
/** The provider-side name of a device's file system and instance. */
|
|
107
109
|
export declare const deviceResourceName: (deviceId: string) => string;
|
|
108
|
-
/** The device is missing, deleted, or not in the caller's org (404; ids cannot be probed). */
|
|
109
|
-
export declare const deviceNotFound: () => ApiError;
|
|
110
110
|
/**
|
|
111
111
|
* The device's file system is gone at the provider (409); never replaced silently. On a
|
|
112
112
|
* connected machine (`local`, details `[{ source: "local" }]`) the directory is the machine
|
|
@@ -151,6 +151,38 @@ export declare function sandboxConfigWarnings(cfg: Pick<KernelConfig, "runtime"
|
|
|
151
151
|
}[];
|
|
152
152
|
/** No sandbox provider (503). */
|
|
153
153
|
export declare const sandboxUnavailable: () => ApiError;
|
|
154
|
+
/**
|
|
155
|
+
* An owner browse found no running instance of the device (409): the picker starts the device
|
|
156
|
+
* for its owner first ({@link SandboxService.ensureRunningForOwner}), so this is an instance that
|
|
157
|
+
* stopped in between (idle suspension) or one that could not be started; retrying starts it.
|
|
158
|
+
*/
|
|
159
|
+
export declare const deviceNotRunning: () => ApiError;
|
|
160
|
+
/**
|
|
161
|
+
* The device's old instance incarnation may still run legacy work that was never retired (503):
|
|
162
|
+
* the device stays unavailable until the provider confirms that incarnation destroyed, or for
|
|
163
|
+
* good when it is quarantined (permission runtime cutover 8.5). Never a retirement claim.
|
|
164
|
+
*/
|
|
165
|
+
export declare class RetirementPendingError extends ApiError {
|
|
166
|
+
name: string;
|
|
167
|
+
}
|
|
168
|
+
export declare const retirementPending: () => ApiError;
|
|
169
|
+
/**
|
|
170
|
+
* A local machine's old instance may still run legacy work, and a later boot of that machine is
|
|
171
|
+
* the evidence that ends it (503, 8.5): the person restarts the computer.
|
|
172
|
+
*/
|
|
173
|
+
export declare const restartRequired: () => ApiError;
|
|
174
|
+
/**
|
|
175
|
+
* A cloud device's earlier instance may still run legacy work and no evidence the kernel can get
|
|
176
|
+
* will ever cover it (an incarnation replaced without a recorded confirmed destruction, or an
|
|
177
|
+
* unknown one it cannot clear) (503, 8.5): the owner deletes the device and creates it again.
|
|
178
|
+
*/
|
|
179
|
+
export declare const recreateRequired: () => ApiError;
|
|
180
|
+
/**
|
|
181
|
+
* A local machine's old instance may still run legacy work, and the computer never reported a
|
|
182
|
+
* boot identity, so not even a restart can prove it ended (503, 8.5): the owner replaces the
|
|
183
|
+
* device. A deleted device's obligations never block a new one.
|
|
184
|
+
*/
|
|
185
|
+
export declare const replaceRequired: () => ApiError;
|
|
154
186
|
/**
|
|
155
187
|
* The kernel's sandbox service over the `sandbox@2` provider, keyed by **device** (spec
|
|
156
188
|
* 2026-11-07-environments-design §4.2, §5.1): one file system kept until the device is
|
|
@@ -210,6 +242,15 @@ export declare const sandboxUnavailable: () => ApiError;
|
|
|
210
242
|
* {@link availableFor} is false and uses throw `sandbox.unavailable` (503). No in-process state:
|
|
211
243
|
* replicas share it through PG and Redis.
|
|
212
244
|
*/
|
|
245
|
+
/** Available only to kernel staging callbacks, never to a held user-operation callback. */
|
|
246
|
+
export interface SandboxStaging {
|
|
247
|
+
prepare<T>(purpose: SandboxPreparationScope["purpose"], roots: readonly string[], fn: (p: SandboxPreparation, signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
248
|
+
}
|
|
249
|
+
export type OperationSessionInvocation = Omit<OperationInvocation, "ordinal"> & {
|
|
250
|
+
/** Read the held {@link SandboxUseInfo.contextEvidence} once after entry (managed route). */
|
|
251
|
+
contextEvidence?: true;
|
|
252
|
+
beforeUser?: (staging: SandboxStaging, info: SandboxUseInfo, signal: AbortSignal) => Promise<void>;
|
|
253
|
+
};
|
|
213
254
|
export declare class SandboxService {
|
|
214
255
|
private readonly db;
|
|
215
256
|
/** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
|
|
@@ -221,13 +262,25 @@ export declare class SandboxService {
|
|
|
221
262
|
private readonly log;
|
|
222
263
|
/** Background tasks lost while their process may live on (killed after a resume). */
|
|
223
264
|
private readonly background;
|
|
265
|
+
private readonly facts;
|
|
266
|
+
private readonly operationIntents;
|
|
267
|
+
private readonly authority;
|
|
268
|
+
private readonly instanceWrites;
|
|
269
|
+
/** The retirement obligations every lifecycle acquisition is gated on (8.5). */
|
|
270
|
+
private readonly retirement;
|
|
271
|
+
/** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
|
|
272
|
+
private readonly snapshots;
|
|
224
273
|
constructor(db: KernelDb,
|
|
225
274
|
/** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
|
|
226
|
-
redis: Pick<Redis, "set" | "getdel">, leases: SandboxLeases,
|
|
275
|
+
redis: Pick<Redis, "get" | "set" | "getdel">, leases: SandboxLeases,
|
|
227
276
|
/** The providers (read at every call: providers are ready after the extension load). */
|
|
228
277
|
providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">,
|
|
229
278
|
/** Background tasks lost while their process may live on (killed after a resume). */
|
|
230
|
-
background: Pick<BackgroundTaskStore, "pendingKills" | "clearKill"
|
|
279
|
+
background: Pick<BackgroundTaskStore, "pendingKills" | "clearKill">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
|
|
280
|
+
/** The retirement obligations every lifecycle acquisition is gated on (8.5). */
|
|
281
|
+
retirement: Pick<LegacyRetirementStore, "unresolved" | "hasUnresolved" | "settleRebooted" | "scanUntilStable" | "frozen" | "frozenAt" | "quarantine" | "noteFailure" | "resolveDestroyed" | "resolveCancelled" | "membersOf" | "recordDestruction" | "destructionRecorded">,
|
|
282
|
+
/** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
|
|
283
|
+
snapshots: Pick<CloudPermissionSnapshots, "reconcileHeld">);
|
|
231
284
|
/** Poll interval while waiting for a lease (the leases' own). */
|
|
232
285
|
private get pollMs();
|
|
233
286
|
/**
|
|
@@ -257,13 +310,6 @@ export declare class SandboxService {
|
|
|
257
310
|
orgId: string;
|
|
258
311
|
deviceId?: string;
|
|
259
312
|
}): Promise<EffectiveDevicePolicy>;
|
|
260
|
-
/**
|
|
261
|
-
* The mode a device chose: a local device's derived one (`localModeOf`, which never returns null
|
|
262
|
-
* — a machine with no summary or no mode feature is sandbox); a cloud device's narrowing switch
|
|
263
|
-
* (`devices.mode`, `sandbox` only), or null for a cloud device that follows the platform and the
|
|
264
|
-
* org.
|
|
265
|
-
*/
|
|
266
|
-
private deviceChosenMode;
|
|
267
313
|
/** The device's source (`local` for a connected machine, else `cloud`); cloud when unknown. */
|
|
268
314
|
private deviceSource;
|
|
269
315
|
/**
|
|
@@ -311,8 +357,13 @@ export declare class SandboxService {
|
|
|
311
357
|
private fsBound;
|
|
312
358
|
/**
|
|
313
359
|
* Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
|
|
314
|
-
* cloud instance whose recorded mode or network kind differs,
|
|
315
|
-
*
|
|
360
|
+
* cloud instance whose recorded mode or network kind differs, or whose recorded limits are more
|
|
361
|
+
* permissive than `want` in any dimension (a host-only narrowing too, spec §124; a host-only
|
|
362
|
+
* widening still reaches instances created afterwards), unless only a file reset could apply it
|
|
363
|
+
* ({@link fsBound}). A provider bound to its file system still goes through the exclusive lease
|
|
364
|
+
* once for a narrowing, so `applyLimits` records it as `unapplied` (the device is then unprobed
|
|
365
|
+
* until the reset, never silently supported). `want` null: a local device (the mode travels
|
|
366
|
+
* with each command).
|
|
316
367
|
*/
|
|
317
368
|
private mustApply;
|
|
318
369
|
/**
|
|
@@ -331,6 +382,7 @@ export declare class SandboxService {
|
|
|
331
382
|
*/
|
|
332
383
|
currentInstance(deviceId: string): Promise<{
|
|
333
384
|
createdAt: Date;
|
|
385
|
+
provider: string | null;
|
|
334
386
|
} | null>;
|
|
335
387
|
/**
|
|
336
388
|
* Runs `fn` on the device's instance only while it runs the instance created at
|
|
@@ -344,9 +396,21 @@ export declare class SandboxService {
|
|
|
344
396
|
* to `fn` aborts with `signal` or when the lease is lost. Errors of `fn` (`SandboxGoneError`
|
|
345
397
|
* too) are thrown as they are.
|
|
346
398
|
*/
|
|
347
|
-
ifRunning<T>(deviceId: string,
|
|
399
|
+
ifRunning<T>(deviceId: string,
|
|
400
|
+
/**
|
|
401
|
+
* `exactRef`: an exact-ref managed drain (status, stop, the revoke worker), allowed on an
|
|
402
|
+
* incarnation under a retirement obligation; every other caller (legacy SID polls, stops and
|
|
403
|
+
* reads, staged browse) is refused there with a {@link RetirementPendingError} (8.5).
|
|
404
|
+
*/
|
|
405
|
+
instance: {
|
|
348
406
|
createdAt: Date;
|
|
407
|
+
exactRef?: boolean;
|
|
349
408
|
}, fn: (p: TaggedProvider, h: SandboxHandle, signal: AbortSignal) => Promise<T>, signal?: AbortSignal): Promise<IfRunningResult<T>>;
|
|
409
|
+
/**
|
|
410
|
+
* {@link ifRunning}; `use` (staged owner browse) also refuses a device carrying the B1
|
|
411
|
+
* reconcile marker under the shared lease, before any provider call (B-11).
|
|
412
|
+
*/
|
|
413
|
+
private ifRunningAs;
|
|
350
414
|
/**
|
|
351
415
|
* A short lease on one path of the device around the kernel's own read-modify-write of
|
|
352
416
|
* that file (spec §10.4); waits up to 30 s, then throws `SandboxPathBusyError`. Its `signal`
|
|
@@ -370,7 +434,42 @@ export declare class SandboxService {
|
|
|
370
434
|
* - When `ctx.holderConversationId` last used another instance (another holder rebuilt it
|
|
371
435
|
* meanwhile), `info.restarted` is true, so it learns its processes are gone (final review m5).
|
|
372
436
|
*/
|
|
437
|
+
/** Trusted staging only. The callback receives no exec, browsing or lifecycle methods. */
|
|
438
|
+
withPreparation<T>(ctx: SandboxUseContext, purpose: SandboxPreparationScope["purpose"], roots: readonly string[], fn: (p: SandboxPreparation, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
439
|
+
private prepareFor;
|
|
440
|
+
/** Owner browse scopes never manufacture a conversation or Full consent. */
|
|
441
|
+
withBrowse<T>(ctx: {
|
|
442
|
+
orgId: string;
|
|
443
|
+
deviceId: string;
|
|
444
|
+
accountId: string;
|
|
445
|
+
}, fn: (p: SandboxBrowse, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
446
|
+
/**
|
|
447
|
+
* Makes the device's instance run for its owner (permission activation L2, Hook 3), before an
|
|
448
|
+
* owner browse ({@link withBrowse}) of a device that may be stopped: the owner, membership and
|
|
449
|
+
* browsing ceiling checks of the browse first (`resolveBrowse`), then the lifecycle `enter` a
|
|
450
|
+
* use takes (the exclusive lease creates or resumes the instance through the retirement gate,
|
|
451
|
+
* the B-11 reconcile marker, the B-8 binding, `maxRunningSandboxes` and fencing), and the lease
|
|
452
|
+
* is left at once. No conversation holds it and nothing runs in it; what the start caused is
|
|
453
|
+
* not marked seen, so each conversation's next use still learns of it.
|
|
454
|
+
*/
|
|
455
|
+
ensureRunningForOwner(ctx: {
|
|
456
|
+
orgId: string;
|
|
457
|
+
deviceId: string;
|
|
458
|
+
accountId: string;
|
|
459
|
+
}, signal: AbortSignal): Promise<void>;
|
|
460
|
+
/**
|
|
461
|
+
* A run start's kernel read of the bound project (permission activation L2, Hook 1): the use
|
|
462
|
+
* a tool call's would be (the instance made or resumed, the read silent for the holder), whose
|
|
463
|
+
* provider stats, reads and lists only, each call a kernel read admitted and claimed on its own
|
|
464
|
+
* (`SandboxOperationIntents.admitKernelRead`: the run's current claim with its run still
|
|
465
|
+
* `queued`, a random operation id, the profile scope narrowed to the root, its `AGENTS.md` and
|
|
466
|
+
* its `.agents/skills`). Any other method is refused before admission. Only
|
|
467
|
+
* `ProjectKnowledgeService` calls this: no tool context, Platform operation or route has it.
|
|
468
|
+
*/
|
|
469
|
+
withKernelRead<T>(ctx: SandboxUseContext, read: KernelReadInvocation, fn: (h: SandboxHandle, p: HeldProvider, info: SandboxUseInfo, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
470
|
+
withOperations<T>(ctx: SandboxUseContext, invocation: OperationSessionInvocation, fn: (h: SandboxHandle, p: HeldProvider, info: SandboxUseInfo, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
373
471
|
withSandbox<T>(ctx: SandboxUseContext, fn: (h: SandboxHandle, p: HeldProvider, info: SandboxUseInfo, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
472
|
+
private withSandboxUse;
|
|
374
473
|
/**
|
|
375
474
|
* The limits a cloud device's instance must run with for this use (auto mode spec §4.2), read
|
|
376
475
|
* fresh; null for a local device (its machine gets the mode and network with each command).
|
|
@@ -405,6 +504,22 @@ export declare class SandboxService {
|
|
|
405
504
|
private seenBy;
|
|
406
505
|
/** Runs `fn` as the holder `e`: its tag and the caller's actor on every exec, its lease's signal. */
|
|
407
506
|
private runAs;
|
|
507
|
+
/**
|
|
508
|
+
* The held provider of a kernel read ({@link withKernelRead}): every call admitted and claimed
|
|
509
|
+
* as its own kernel read, then dispatched inline under the held lease, as an owner browse's
|
|
510
|
+
* call is ({@link withBrowse}). Exec, writes and scans are refused before any admission.
|
|
511
|
+
*/
|
|
512
|
+
private kernelReadProvider;
|
|
513
|
+
/**
|
|
514
|
+
* The held evidence of a managed entry (B3), read once under the shared lease the holder already
|
|
515
|
+
* has: the entered provider, the held handle's id and its generation (the row's `created_at`
|
|
516
|
+
* milliseconds), the installed binding of exactly that generation and provider, the handle's
|
|
517
|
+
* roots and the base working root admission resolves. Undefined without an installed binding or
|
|
518
|
+
* with a project binding that no longer matches: the managed writer then refuses the call. The
|
|
519
|
+
* writer validates every field again under the authority locks.
|
|
520
|
+
*/
|
|
521
|
+
private heldContextEvidence;
|
|
522
|
+
private readHeldContextEvidence;
|
|
408
523
|
/**
|
|
409
524
|
* Becomes a holder: loops until it has a shared lease on a running instance, or `sandbox.busy`.
|
|
410
525
|
* An instance recorded `running` (with the current provider, not the `gone` instance) is used
|
|
@@ -414,6 +529,32 @@ export declare class SandboxService {
|
|
|
414
529
|
* during the wait is never used with the old, wider limits.
|
|
415
530
|
*/
|
|
416
531
|
private enter;
|
|
532
|
+
/**
|
|
533
|
+
* Whether this device's instances record cloud evidence (B-15): a cloud device whose provider
|
|
534
|
+
* (with a known version) reads its own permission support. A local device attests through its
|
|
535
|
+
* installed binding instead.
|
|
536
|
+
*/
|
|
537
|
+
private recordsCloudSupport;
|
|
538
|
+
/**
|
|
539
|
+
* The provider's permission support of the held instance `handle`, read under the caller's
|
|
540
|
+
* lifecycle lease within {@link PERMISSION_SUPPORT_TIMEOUT_MS}; undefined when it cannot be
|
|
541
|
+
* read in time or is not a version 1 report. Never throws: missing evidence keeps the device
|
|
542
|
+
* unprobed, it never fails the lifecycle step. A failure is logged once per instance generation
|
|
543
|
+
* (`warnOnce`: a Redis marker shared by the replicas; without it, every failure is logged).
|
|
544
|
+
*/
|
|
545
|
+
private cloudSupport;
|
|
546
|
+
/**
|
|
547
|
+
* Under a lifecycle lease on the running instance `e`: records its cloud evidence again when
|
|
548
|
+
* `force` (a resume) or when the recorded one is stale (another provider version, handle,
|
|
549
|
+
* generation or applied limits; `cloudReportOwed`). The record is written only while the row
|
|
550
|
+
* still holds the probed instance with the limits read before the probe, so a holder whose
|
|
551
|
+
* lease was lost never overwrites newer evidence. A forced read that fails clears the recorded
|
|
552
|
+
* identity (a resumed instance is unprobed until a read succeeds); any other failure leaves the
|
|
553
|
+
* evidence as it was. Never throws.
|
|
554
|
+
*/
|
|
555
|
+
private refreshCloudSupport;
|
|
556
|
+
/** No binder (protocol 2), or the current generation's binding is installed (B-8). */
|
|
557
|
+
private bound;
|
|
417
558
|
private clearIntent;
|
|
418
559
|
private readRow;
|
|
419
560
|
/** The instance row belongs to another org: reported as not found, so ids cannot be probed. */
|
|
@@ -480,6 +621,61 @@ export declare class SandboxService {
|
|
|
480
621
|
* creates a new one. Nothing to do without a row. Throws `sandbox.unavailable` without a provider.
|
|
481
622
|
*/
|
|
482
623
|
resetFileSystem(deviceId: string): Promise<void>;
|
|
624
|
+
/**
|
|
625
|
+
* The worker's retirement of a device's old incarnations (8.5, `RetireLegacyTasksJob`): one try
|
|
626
|
+
* at the exclusive lifecycle lease, then the same gate as every acquisition. `busy`: a holder
|
|
627
|
+
* has the device (the inline gate runs on its next lifecycle acquisition anyway); `unavailable`:
|
|
628
|
+
* an obligation stays (quarantined, or a destroy that failed); `clear`: none left.
|
|
629
|
+
*/
|
|
630
|
+
retireLegacy(deviceId: string,
|
|
631
|
+
/** The worker's signal (its stop, a lost run lock): ends a destroy in flight. */
|
|
632
|
+
signal?: AbortSignal): Promise<"clear" | "unavailable" | "busy">;
|
|
633
|
+
/**
|
|
634
|
+
* The lifecycle reconcile of a cloud device carrying `permission_reconcile_required` (B-12),
|
|
635
|
+
* under one try at its exclusive lifecycle lease (`busy`: a holder has it). The snapshot
|
|
636
|
+
* writer's reconcile runs first ({@link CloudPermissionSnapshots.reconcileHeld}: it narrows the
|
|
637
|
+
* authority to what the instance is known to run, and may clear the marker by itself). A device
|
|
638
|
+
* with an unresolved retirement obligation stops there: its incarnation is the retirement
|
|
639
|
+
* gate's alone (never resumed here). When the
|
|
640
|
+
* marker stays on a live instance whose provider can `update`, the provider applies the
|
|
641
|
+
* reconcile target, which is never wider than the instance in any dimension, so this only
|
|
642
|
+
* narrows; a suspended instance is resumed for it (its leftover commands killed, nobody else
|
|
643
|
+
* holds it) and suspended again, as its row still says. `updated` records the target as
|
|
644
|
+
* applied (fenced) and the reconcile runs again, which clears the marker. No `update`, a
|
|
645
|
+
* `recreate` answer, a gone instance or a failure leave the marker and its file reset action.
|
|
646
|
+
*/
|
|
647
|
+
reconcileLimits(deviceId: string, signal?: AbortSignal): Promise<CloudSnapshotOutcome | "busy">;
|
|
648
|
+
/**
|
|
649
|
+
* The worker's sweep of {@link reconcileLimits} (`sandbox-reconcile-limits`): up to `limit`
|
|
650
|
+
* live cloud devices of the loaded cloud provider carrying the marker on a live instance, in
|
|
651
|
+
* id order from a shared keyset cursor that wraps around (no starvation), each tried at most
|
|
652
|
+
* once per {@link RECONCILE_RETRY_SECONDS} across replicas (a Redis marker).
|
|
653
|
+
* Nothing without a cloud provider that can `update`. Returns how many it reconciled.
|
|
654
|
+
*/
|
|
655
|
+
reconcileMarked(limit?: number): Promise<number>;
|
|
656
|
+
/**
|
|
657
|
+
* The retirement gate (permission runtime cutover 8.5), under the exclusive lifecycle lease and
|
|
658
|
+
* before the instance is used, resumed, rebuilt, switched to another provider, bound or
|
|
659
|
+
* downgraded to shared use: every unresolved obligation of the device is settled here or the
|
|
660
|
+
* device is unavailable ({@link retirementPending}).
|
|
661
|
+
* - The obligation names the **current** incarnation (provider and exact generation): a cloud
|
|
662
|
+
* one is destroyed whole by its provider (never resumed, never `killAll`ed, the file system
|
|
663
|
+
* kept), the confirmed destruction is recorded and the row reads `destroyed`, so the use
|
|
664
|
+
* creates a fresh instance; a failed destroy keeps the obligation. A kernel-internal (local)
|
|
665
|
+
* one is quarantined: its destroy is a no-op and a restart proves nothing.
|
|
666
|
+
* - B-22: a **suspended** current cloud incarnation whose members are all revoked managed starts
|
|
667
|
+
* is not destroyed whole (its other tasks would be lost): each revoked ref gets its exact stop
|
|
668
|
+
* (persisted while suspended), the instance is resumed, each stop is confirmed (`stopped` or
|
|
669
|
+
* `already-exited`), and the obligation resolves as `exact-cancelled`. Any failure is noted on
|
|
670
|
+
* the obligation and falls back to the whole-instance destroy above. `resumed` given (a use):
|
|
671
|
+
* the resumed instance is left running for it (`resumed.resumed` set); otherwise (the worker),
|
|
672
|
+
* or when the device stays refused, it is suspended again, as its row still says.
|
|
673
|
+
* - It names an incarnation that is **not current** (replaced, a reused handle with another
|
|
674
|
+
* generation, unknown): resolved only by a recorded provider-confirmed destruction of exactly
|
|
675
|
+
* it, else quarantined. A newer generation is never evidence.
|
|
676
|
+
* Returns the row as it is afterwards.
|
|
677
|
+
*/
|
|
678
|
+
private retireIncarnations;
|
|
483
679
|
/**
|
|
484
680
|
* Under the exclusive lease (before the downgrade), on an instance just resumed from
|
|
485
681
|
* `suspended`: kills every command left in it (`killAll`), crashed holders' (`dead`, already
|