@capybara-hq/kernel 0.1.0-rc.40 → 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 +10 -1
- 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
|
@@ -2,9 +2,12 @@ import { ApiError } from "../errors.js";
|
|
|
2
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
3
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
4
|
import type { SandboxMode } from "../sandbox/modes.js";
|
|
5
|
-
import {
|
|
5
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
6
|
+
import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
6
7
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
7
8
|
import { DeviceAccess } from "./access.js";
|
|
9
|
+
import { type DeviceProjectScope } from "./project-rules.js";
|
|
10
|
+
export { type DeviceProjectScope, readModeOf, withinMode } from "./project-rules.js";
|
|
8
11
|
/** The most projects one device keeps (project root §4.1). */
|
|
9
12
|
export declare const MAX_DEVICE_PROJECTS = 100;
|
|
10
13
|
/** A project as the web and the Platform tool see it. */
|
|
@@ -45,27 +48,6 @@ export interface DeviceProjectCandidates {
|
|
|
45
48
|
base: string | null;
|
|
46
49
|
supported: boolean;
|
|
47
50
|
}
|
|
48
|
-
/** What a project's scope is read from: the device's mode now and the bases it gives. */
|
|
49
|
-
export interface DeviceProjectScope {
|
|
50
|
-
source: "cloud" | "local";
|
|
51
|
-
mode: SandboxMode;
|
|
52
|
-
/** The workspace root as last known (a machine's hello, a cloud instance's handle). */
|
|
53
|
-
workspace: string;
|
|
54
|
-
/** The owner's home a local machine reported; null when unknown (and for a cloud device). */
|
|
55
|
-
home: string | null;
|
|
56
|
-
supported: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* A machine whose own policy is auto mode while the organization allows only sandbox mode: exec
|
|
59
|
-
* refuses it (`device.auto_mode_not_allowed`), and the kernel reads nothing on it unasked.
|
|
60
|
-
*/
|
|
61
|
-
widerThanAllowed: boolean;
|
|
62
|
-
}
|
|
63
|
-
type Scope = DeviceProjectScope;
|
|
64
|
-
/**
|
|
65
|
-
* `path` lies inside what the scope's mode may read (sandbox mode and cloud: the workspace, as the
|
|
66
|
-
* held instance reports it when given).
|
|
67
|
-
*/
|
|
68
|
-
export declare const withinMode: (s: Scope, path: string, workspace?: string) => boolean;
|
|
69
51
|
/**
|
|
70
52
|
* A device's projects (project root design §4.1, §4.2, §6): kept in `device_projects`, keyed by the
|
|
71
53
|
* device's id, written only here. Only the device's owner reads or changes them (anyone else gets
|
|
@@ -79,10 +61,15 @@ export declare const withinMode: (s: Scope, path: string, workspace?: string) =>
|
|
|
79
61
|
export declare class DeviceProjectsService {
|
|
80
62
|
private readonly db;
|
|
81
63
|
readonly txHost: TransactionHost;
|
|
82
|
-
private readonly providers;
|
|
83
64
|
private readonly sandbox;
|
|
84
65
|
private readonly access;
|
|
85
|
-
|
|
66
|
+
private readonly facts;
|
|
67
|
+
private readonly ceilings;
|
|
68
|
+
/** The paired activation gate: once on, every device read is an owner browse. */
|
|
69
|
+
private readonly activation?;
|
|
70
|
+
constructor(db: KernelDb, txHost: TransactionHost, sandbox: Pick<SandboxService, "withSandbox" | "withBrowse" | "ensureRunningForOwner">, access: Pick<DeviceAccess, "usable">, facts: Pick<PermissionFacts, "resolveProjectForBinding" | "projectMatches" | "projectScope">, ceilings: PermissionCeilingWrites,
|
|
71
|
+
/** The paired activation gate: once on, every device read is an owner browse. */
|
|
72
|
+
activation?: boolean | undefined);
|
|
86
73
|
/** The projects the device's current mode can read; see {@link DeviceProjectList}. */
|
|
87
74
|
list(orgId: string, accountId: string, deviceId: string): Promise<DeviceProjectList>;
|
|
88
75
|
/**
|
|
@@ -110,10 +97,18 @@ export declare class DeviceProjectsService {
|
|
|
110
97
|
path: string;
|
|
111
98
|
name?: string;
|
|
112
99
|
}, actorTokenId?: string, auditDetail?: Record<string, unknown>, signal?: AbortSignal): Promise<DeviceProjectView>;
|
|
100
|
+
/**
|
|
101
|
+
* The owner's live device row, then its permission authority lock: the ordered prelude of the
|
|
102
|
+
* project writes (`withOrderedLocks`), so inside a run's fence (the Platform tool's
|
|
103
|
+
* `devices.add-project` / `devices.remove-project`) they follow the org row and precede the
|
|
104
|
+
* conversation rows. The writes name both again (already held: a re-check).
|
|
105
|
+
*/
|
|
106
|
+
private lockSubject;
|
|
113
107
|
/** The insert of {@link add}: the owner's live device locked, the count and the name checked. */
|
|
114
108
|
private insert;
|
|
115
109
|
/** Removes a project of the owner's device; removing one that is not there succeeds. */
|
|
116
110
|
remove(orgId: string, accountId: string, deviceId: string, name: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<void>;
|
|
111
|
+
private removeIn;
|
|
117
112
|
/**
|
|
118
113
|
* The project a new conversation of `accountId` binds to (project root §4.3): one of the
|
|
119
114
|
* owner's device's projects that its current mode can read. Refused with `device.not_found`
|
|
@@ -145,9 +140,13 @@ export declare class DeviceProjectsService {
|
|
|
145
140
|
*/
|
|
146
141
|
private scope;
|
|
147
142
|
/**
|
|
148
|
-
* Runs `fn` on the device
|
|
149
|
-
*
|
|
150
|
-
*
|
|
143
|
+
* Runs `fn` on the device with a {@link ProjectReader}. While the activation gate is off:
|
|
144
|
+
* `SandboxService.withSandbox` (its instance made or resumed as for a tool call) with the
|
|
145
|
+
* workspace root its instance reports. Once it is on: the device started for its owner
|
|
146
|
+
* (`SandboxService.ensureRunningForOwner`), then the owner browse (`SandboxService.withBrowse`,
|
|
147
|
+
* as the device's owner, on the instance that runs) with the last known workspace; an instance
|
|
148
|
+
* that stopped in between is `device.not_running`. Kernel refusals (offline, files lost, busy,
|
|
149
|
+
* unavailable) stay as they are; anything else becomes a readable
|
|
151
150
|
* `device.projects_unavailable`, never a 500.
|
|
152
151
|
*/
|
|
153
152
|
private onDevice;
|
|
@@ -159,4 +158,3 @@ export declare class DeviceProjectsService {
|
|
|
159
158
|
* person's project skill invocation).
|
|
160
159
|
*/
|
|
161
160
|
export declare const providerUnreachable: () => ApiError;
|
|
162
|
-
export {};
|
|
@@ -8,53 +8,60 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { posix } from "node:path";
|
|
11
|
-
import {
|
|
12
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
+
import { DeviceProtocolError, isDeviceProjectName, isFileSystemGoneError, isSandboxGoneError, isSandboxScopeDeniedError, MAX_DEVICE_SCAN_RESULTS, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
12
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { ApiError } from "../errors.js";
|
|
15
15
|
import { audit } from "../identity/audit.js";
|
|
16
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
17
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
17
|
+
import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
|
|
18
18
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
19
19
|
import { projectsUnsupported } from "../local-devices/local-device-provider.js";
|
|
20
|
-
import { deviceFeaturesOf, localModeOf } from "../local-devices/policy-summary.js";
|
|
21
20
|
import { POLICY_REFUSAL_PREFIX } from "../local-devices/relay.js";
|
|
22
|
-
import {
|
|
21
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
22
|
+
import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../sandbox/permission-context-types.js";
|
|
23
|
+
import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
23
24
|
import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
|
|
24
25
|
import { SandboxProviderUnreachableError } from "../sandbox/unreachable.js";
|
|
25
26
|
import { DeviceAccess } from "./access.js";
|
|
27
|
+
import { baseOf, clipped, homeUnknown, nameInvalid, nameTaken, outsideMode, readModeOf, tooBroad, withinMode, } from "./project-rules.js";
|
|
26
28
|
// a path above the owner's home is never stored as a project: the working root would fall back for
|
|
27
29
|
// it anyway (project root §4.3), so both use the one rule; the home itself may be one
|
|
28
30
|
import { aboveHome } from "./working-root.js";
|
|
31
|
+
export { readModeOf, withinMode } from "./project-rules.js";
|
|
29
32
|
/** The most projects one device keeps (project root §4.1). */
|
|
30
33
|
export const MAX_DEVICE_PROJECTS = 100;
|
|
31
34
|
/**
|
|
32
35
|
* The holder name the projects service enters a device's sandbox under (`SandboxService`
|
|
33
|
-
* `withSandbox`): it only lists directories, never runs a
|
|
36
|
+
* `withSandbox`) while the activation gate is off: it only lists directories, never runs a
|
|
37
|
+
* command, so no conversation holds it. Once the gate is on the owner browse route has no holder.
|
|
34
38
|
*/
|
|
35
39
|
const PROJECTS_HOLDER = "device-projects";
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
40
|
+
/** The raw route's reader over a held provider (gate off): the protocol 2 calls, unchanged. */
|
|
41
|
+
function heldReader(scope, h, p, workspace) {
|
|
42
|
+
const list = p.list;
|
|
43
|
+
const scan = p.scan;
|
|
44
|
+
return {
|
|
45
|
+
workspace,
|
|
46
|
+
browse: false,
|
|
47
|
+
...(list !== undefined && {
|
|
48
|
+
list: (path, limit, signal) => list.call(p, h, path, { limit, limits: { mode: readModeOf(scope) }, signal }),
|
|
49
|
+
}),
|
|
50
|
+
...(scan !== undefined && {
|
|
51
|
+
scan: (base, signal) => scan.call(p, h, base, { limits: { mode: readModeOf(scope) }, signal }),
|
|
52
|
+
}),
|
|
53
|
+
stat: (path, signal) => p.stat(h, path, signal),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The owner browse route's reader (gate on): the browse scope's stat / list / scan only. */
|
|
57
|
+
function browseReader(b, workspace) {
|
|
58
|
+
return {
|
|
59
|
+
workspace,
|
|
60
|
+
browse: true,
|
|
61
|
+
list: (path, limit, signal) => b.list(path, { limit, signal }),
|
|
62
|
+
scan: (base, signal) => b.scan(base, { signal }),
|
|
63
|
+
stat: (path, signal) => b.stat(path, signal),
|
|
64
|
+
};
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
60
67
|
* A device's projects (project root design §4.1, §4.2, §6): kept in `device_projects`, keyed by the
|
|
@@ -69,15 +76,21 @@ function clipped(s, max = 200) {
|
|
|
69
76
|
let DeviceProjectsService = class DeviceProjectsService {
|
|
70
77
|
db;
|
|
71
78
|
txHost;
|
|
72
|
-
providers;
|
|
73
79
|
sandbox;
|
|
74
80
|
access;
|
|
75
|
-
|
|
81
|
+
facts;
|
|
82
|
+
ceilings;
|
|
83
|
+
activation;
|
|
84
|
+
constructor(db, txHost, sandbox, access, facts, ceilings,
|
|
85
|
+
/** The paired activation gate: once on, every device read is an owner browse. */
|
|
86
|
+
activation) {
|
|
76
87
|
this.db = db;
|
|
77
88
|
this.txHost = txHost;
|
|
78
|
-
this.providers = providers;
|
|
79
89
|
this.sandbox = sandbox;
|
|
80
90
|
this.access = access;
|
|
91
|
+
this.facts = facts;
|
|
92
|
+
this.ceilings = ceilings;
|
|
93
|
+
this.activation = activation;
|
|
81
94
|
}
|
|
82
95
|
/** The projects the device's current mode can read; see {@link DeviceProjectList}. */
|
|
83
96
|
async list(orgId, accountId, deviceId) {
|
|
@@ -114,14 +127,15 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
114
127
|
}
|
|
115
128
|
if (baseOf(scope) === null)
|
|
116
129
|
throw homeUnknown();
|
|
117
|
-
return this.onDevice(orgId, accountId, deviceId, signal, async (
|
|
130
|
+
return this.onDevice(orgId, accountId, deviceId, scope, signal, async (r, sig) => {
|
|
131
|
+
const workspace = r.workspace;
|
|
118
132
|
const base = baseOf(scope, workspace);
|
|
119
|
-
const scan =
|
|
133
|
+
const scan = r.scan;
|
|
120
134
|
if (scan === undefined)
|
|
121
135
|
throw projectsUnsupported(false);
|
|
122
136
|
let found;
|
|
123
137
|
try {
|
|
124
|
-
found = await scan
|
|
138
|
+
found = await scan(base, sig);
|
|
125
139
|
}
|
|
126
140
|
catch (e) {
|
|
127
141
|
// the base is the device's own workspace or home: a refusal there is not the person's path
|
|
@@ -190,34 +204,41 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
190
204
|
if (withinMode(scope, path) && aboveHome(path, scope.home))
|
|
191
205
|
throw tooBroad(path);
|
|
192
206
|
}
|
|
193
|
-
const resolved = await this.onDevice(orgId, accountId, deviceId, signal, async (
|
|
194
|
-
const path = resolve(scope, workspace, input.path);
|
|
207
|
+
const resolved = await this.onDevice(orgId, accountId, deviceId, scope, signal, async (r, sig) => {
|
|
208
|
+
const path = resolve(scope, r.workspace, input.path);
|
|
195
209
|
const name = input.name ?? posix.basename(path);
|
|
196
210
|
if (!isDeviceProjectName(name))
|
|
197
211
|
throw nameInvalid(name);
|
|
198
|
-
const list =
|
|
212
|
+
const list = r.list;
|
|
199
213
|
if (list === undefined)
|
|
200
214
|
throw projectsUnsupported(false);
|
|
201
215
|
let answer;
|
|
202
216
|
try {
|
|
203
|
-
answer = await list
|
|
204
|
-
limit: 1,
|
|
205
|
-
limits: { mode: scope.mode },
|
|
206
|
-
signal: sig,
|
|
207
|
-
});
|
|
217
|
+
answer = await list(path, 1, sig);
|
|
208
218
|
}
|
|
209
219
|
catch (e) {
|
|
210
|
-
throw await listFailure(e,
|
|
220
|
+
throw await listFailure(e, r, path, scope.mode, sig);
|
|
211
221
|
}
|
|
212
222
|
if (answer === null)
|
|
213
223
|
throw pathMissing(path);
|
|
214
224
|
return { path, name };
|
|
215
225
|
});
|
|
216
|
-
return this.insert(orgId, accountId, deviceId, resolved, actorTokenId, auditDetail);
|
|
226
|
+
return withOrderedLocks(() => this.lockSubject(orgId, accountId, deviceId), () => this.insert(orgId, accountId, deviceId, resolved, actorTokenId, auditDetail));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The owner's live device row, then its permission authority lock: the ordered prelude of the
|
|
230
|
+
* project writes (`withOrderedLocks`), so inside a run's fence (the Platform tool's
|
|
231
|
+
* `devices.add-project` / `devices.remove-project`) they follow the org row and precede the
|
|
232
|
+
* conversation rows. The writes name both again (already held: a re-check).
|
|
233
|
+
*/
|
|
234
|
+
async lockSubject(orgId, accountId, deviceId) {
|
|
235
|
+
await this.lockOwn(orgId, accountId, deviceId);
|
|
236
|
+
await this.ceilings.lock({ orgId, deviceId }, "device");
|
|
217
237
|
}
|
|
218
238
|
/** The insert of {@link add}: the owner's live device locked, the count and the name checked. */
|
|
219
239
|
async insert(orgId, accountId, deviceId, p, actorTokenId, auditDetail) {
|
|
220
240
|
await this.lockOwn(orgId, accountId, deviceId);
|
|
241
|
+
await this.ceilings.lock({ orgId, deviceId }, "device");
|
|
221
242
|
const count = await this.db
|
|
222
243
|
.selectFrom("device_projects")
|
|
223
244
|
.select(sql `count(*)::int`.as("n"))
|
|
@@ -233,6 +254,7 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
233
254
|
.executeTakeFirst();
|
|
234
255
|
if (row === undefined)
|
|
235
256
|
throw nameTaken(p.name);
|
|
257
|
+
await this.ceilings.publishLocked({ orgId, deviceId }, "device", false);
|
|
236
258
|
await audit(this.db.db, {
|
|
237
259
|
actorAccountId: accountId,
|
|
238
260
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -245,7 +267,11 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
245
267
|
}
|
|
246
268
|
/** Removes a project of the owner's device; removing one that is not there succeeds. */
|
|
247
269
|
async remove(orgId, accountId, deviceId, name, actorTokenId, auditDetail) {
|
|
270
|
+
await withOrderedLocks(() => this.lockSubject(orgId, accountId, deviceId), () => this.removeIn(orgId, accountId, deviceId, name, actorTokenId, auditDetail));
|
|
271
|
+
}
|
|
272
|
+
async removeIn(orgId, accountId, deviceId, name, actorTokenId, auditDetail) {
|
|
248
273
|
await this.lockOwn(orgId, accountId, deviceId);
|
|
274
|
+
await this.ceilings.lock({ orgId, deviceId }, "device");
|
|
249
275
|
const gone = await this.db
|
|
250
276
|
.deleteFrom("device_projects")
|
|
251
277
|
.where("device_id", "=", deviceId)
|
|
@@ -254,6 +280,26 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
254
280
|
.executeTakeFirst();
|
|
255
281
|
if (gone === undefined)
|
|
256
282
|
return;
|
|
283
|
+
const roots = await this.db
|
|
284
|
+
.selectFrom("conversations")
|
|
285
|
+
.select("id")
|
|
286
|
+
.where("device_id", "=", deviceId)
|
|
287
|
+
.where("project_name", "=", name)
|
|
288
|
+
.where("project_path", "=", gone.path)
|
|
289
|
+
.execute();
|
|
290
|
+
const affected = new Set(roots.map((r) => r.id));
|
|
291
|
+
await this.ceilings.publishLocked({ orgId, deviceId }, "device", (_scope, row) => row.root_conversation_id !== null && affected.has(row.root_conversation_id));
|
|
292
|
+
if (affected.size)
|
|
293
|
+
await this.db
|
|
294
|
+
.updateTable("conversations")
|
|
295
|
+
.set((eb) => ({
|
|
296
|
+
permission_profile: "approve-for-me",
|
|
297
|
+
permission_consent: null,
|
|
298
|
+
permission_revision: eb("permission_revision", "+", 1),
|
|
299
|
+
}))
|
|
300
|
+
.where("id", "in", [...affected])
|
|
301
|
+
.where("permission_profile", "=", "full-access")
|
|
302
|
+
.execute();
|
|
257
303
|
await audit(this.db.db, {
|
|
258
304
|
actorAccountId: accountId,
|
|
259
305
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -271,24 +317,7 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
271
317
|
* not asked: it enforces its mode on every access anyway.
|
|
272
318
|
*/
|
|
273
319
|
async resolveForBinding(orgId, deviceId, accountId, name) {
|
|
274
|
-
|
|
275
|
-
if (!scope.supported)
|
|
276
|
-
throw projectsUnsupported(scope.source === "local");
|
|
277
|
-
const row = await this.db
|
|
278
|
-
.selectFrom("device_projects")
|
|
279
|
-
.select(["name", "path"])
|
|
280
|
-
.where("device_id", "=", deviceId)
|
|
281
|
-
.where("name", "=", name)
|
|
282
|
-
.executeTakeFirst();
|
|
283
|
-
if (row === undefined)
|
|
284
|
-
throw projectNotFound(name);
|
|
285
|
-
if (!withinMode(scope, row.path))
|
|
286
|
-
throw outsideMode(row.path, scope.mode);
|
|
287
|
-
// a home reported after the project was added can put it above the home: the working root
|
|
288
|
-
// would fall back for it, so it is not bound (the add rule, project root §4.3)
|
|
289
|
-
if (aboveHome(row.path, scope.home))
|
|
290
|
-
throw tooBroad(row.path);
|
|
291
|
-
return { name: row.name, path: row.path };
|
|
320
|
+
return this.facts.resolveProjectForBinding(orgId, deviceId, accountId, name);
|
|
292
321
|
}
|
|
293
322
|
/**
|
|
294
323
|
* Whether the device still keeps the project `name` at `path` (project root §4.3): a binding is
|
|
@@ -296,14 +325,7 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
296
325
|
* longer serves the conversations bound to it. Reads only.
|
|
297
326
|
*/
|
|
298
327
|
async keeps(deviceId, name, path) {
|
|
299
|
-
|
|
300
|
-
.selectFrom("device_projects")
|
|
301
|
-
.select("name")
|
|
302
|
-
.where("device_id", "=", deviceId)
|
|
303
|
-
.where("name", "=", name)
|
|
304
|
-
.where("path", "=", path)
|
|
305
|
-
.executeTakeFirst();
|
|
306
|
-
return row !== undefined;
|
|
328
|
+
return this.facts.projectMatches(deviceId, name, path);
|
|
307
329
|
}
|
|
308
330
|
/**
|
|
309
331
|
* The owner's live device's scope now ({@link scope}), for a run start's read of its bound
|
|
@@ -320,66 +342,31 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
320
342
|
* offers projects. Anyone else's device (or a missing one) → `device.not_found`.
|
|
321
343
|
*/
|
|
322
344
|
async scope(orgId, accountId, deviceId) {
|
|
323
|
-
|
|
324
|
-
.selectFrom("devices as e")
|
|
325
|
-
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
326
|
-
.leftJoin("device_instances as i", "i.device_id", "e.id")
|
|
327
|
-
.select([
|
|
328
|
-
"e.source",
|
|
329
|
-
"e.provider",
|
|
330
|
-
"m.features",
|
|
331
|
-
"m.local_policy",
|
|
332
|
-
"m.home",
|
|
333
|
-
sql `m.roots->>'workspace'`.as("machine_workspace"),
|
|
334
|
-
"i.handle",
|
|
335
|
-
])
|
|
336
|
-
.where("e.id", "=", deviceId)
|
|
337
|
-
.where("e.org_id", "=", orgId)
|
|
338
|
-
.where("e.owner_kind", "=", "personal")
|
|
339
|
-
.where("e.owner_account_id", "=", accountId)
|
|
340
|
-
.where("e.deleted_at", "is", null)
|
|
341
|
-
.executeTakeFirst();
|
|
342
|
-
if (row === undefined)
|
|
343
|
-
throw deviceNotFound();
|
|
344
|
-
// `devicePolicy`, not `modeLevel` as the command review reads: a cloud device with a pending
|
|
345
|
-
// files reset is scoped by the narrower mode it will run at, never the wider one its instance
|
|
346
|
-
// still has, on purpose (projects are offered for what the device will read; no effect today)
|
|
347
|
-
const { mode, allowedMode } = await this.sandbox.devicePolicy({ orgId, deviceId });
|
|
348
|
-
if (row.source === "local") {
|
|
349
|
-
return {
|
|
350
|
-
source: "local",
|
|
351
|
-
mode,
|
|
352
|
-
widerThanAllowed: allowedMode === "sandbox" && localModeOf(row.features, row.local_policy) === "auto",
|
|
353
|
-
workspace: row.machine_workspace ?? DEFAULT_SANDBOX_ROOTS.workspace,
|
|
354
|
-
home: row.home,
|
|
355
|
-
supported: deviceFeaturesOf(row.features).includes("projects"),
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
const impl = providerForDevice(this.providers, row.provider)?.impl;
|
|
359
|
-
const handle = row.handle;
|
|
360
|
-
return {
|
|
361
|
-
source: "cloud",
|
|
362
|
-
mode,
|
|
363
|
-
widerThanAllowed: false,
|
|
364
|
-
workspace: handle === null ? DEFAULT_SANDBOX_ROOTS.workspace : rootsOf(handle).workspace,
|
|
365
|
-
home: null,
|
|
366
|
-
supported: typeof impl?.list === "function" && typeof impl.scan === "function",
|
|
367
|
-
};
|
|
345
|
+
return this.facts.projectScope(orgId, accountId, deviceId);
|
|
368
346
|
}
|
|
369
347
|
/**
|
|
370
|
-
* Runs `fn` on the device
|
|
371
|
-
*
|
|
372
|
-
*
|
|
348
|
+
* Runs `fn` on the device with a {@link ProjectReader}. While the activation gate is off:
|
|
349
|
+
* `SandboxService.withSandbox` (its instance made or resumed as for a tool call) with the
|
|
350
|
+
* workspace root its instance reports. Once it is on: the device started for its owner
|
|
351
|
+
* (`SandboxService.ensureRunningForOwner`), then the owner browse (`SandboxService.withBrowse`,
|
|
352
|
+
* as the device's owner, on the instance that runs) with the last known workspace; an instance
|
|
353
|
+
* that stopped in between is `device.not_running`. Kernel refusals (offline, files lost, busy,
|
|
354
|
+
* unavailable) stay as they are; anything else becomes a readable
|
|
373
355
|
* `device.projects_unavailable`, never a 500.
|
|
374
356
|
*/
|
|
375
|
-
async onDevice(orgId, accountId, deviceId, signal, fn) {
|
|
357
|
+
async onDevice(orgId, accountId, deviceId, scope, signal, fn) {
|
|
376
358
|
try {
|
|
359
|
+
if (permissionContextActive(this.activation)) {
|
|
360
|
+
// a stopped device is started for its owner first, as the raw route's use did
|
|
361
|
+
await this.sandbox.ensureRunningForOwner({ orgId, deviceId, accountId }, signal);
|
|
362
|
+
return await this.sandbox.withBrowse({ orgId, deviceId, accountId }, (b, sig) => fn(browseReader(b, scope.workspace), sig), signal);
|
|
363
|
+
}
|
|
377
364
|
return await this.sandbox.withSandbox({
|
|
378
365
|
orgId,
|
|
379
366
|
deviceId,
|
|
380
367
|
holderConversationId: PROJECTS_HOLDER,
|
|
381
368
|
actor: { accountId, conversationId: PROJECTS_HOLDER },
|
|
382
|
-
}, (h, p, info, sig) => fn(h, p, info.roots.workspace, sig), signal);
|
|
369
|
+
}, (h, p, info, sig) => fn(heldReader(scope, h, p, info.roots.workspace), sig), signal);
|
|
383
370
|
}
|
|
384
371
|
catch (e) {
|
|
385
372
|
if (e instanceof ApiError)
|
|
@@ -405,19 +392,25 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
405
392
|
throw deviceNotFound();
|
|
406
393
|
}
|
|
407
394
|
};
|
|
395
|
+
__decorate([
|
|
396
|
+
Transactional({ propagation: "mandatory" })
|
|
397
|
+
], DeviceProjectsService.prototype, "lockSubject", null);
|
|
408
398
|
__decorate([
|
|
409
399
|
Transactional()
|
|
410
400
|
], DeviceProjectsService.prototype, "insert", null);
|
|
411
401
|
__decorate([
|
|
412
402
|
Transactional()
|
|
413
|
-
], DeviceProjectsService.prototype, "
|
|
403
|
+
], DeviceProjectsService.prototype, "removeIn", null);
|
|
414
404
|
DeviceProjectsService = __decorate([
|
|
415
405
|
Injectable(),
|
|
416
406
|
__param(0, Inject(KernelDb)),
|
|
417
407
|
__param(1, Inject(TransactionHost)),
|
|
418
|
-
__param(2, Inject(
|
|
419
|
-
__param(3, Inject(
|
|
420
|
-
__param(4, Inject(
|
|
408
|
+
__param(2, Inject(SandboxService)),
|
|
409
|
+
__param(3, Inject(DeviceAccess)),
|
|
410
|
+
__param(4, Inject(PermissionFacts)),
|
|
411
|
+
__param(5, Inject(PermissionCeilingWrites)),
|
|
412
|
+
__param(6, Optional()),
|
|
413
|
+
__param(6, Inject(PERMISSION_CONTEXT_ACTIVATION))
|
|
421
414
|
], DeviceProjectsService);
|
|
422
415
|
export { DeviceProjectsService };
|
|
423
416
|
/**
|
|
@@ -480,17 +473,19 @@ const pathMissing = (path) => new ApiError("device.project_path_missing", `${cli
|
|
|
480
473
|
* missing path `device.project_path_missing`, and a `stat` that fails too means the device could
|
|
481
474
|
* not be asked (503 `device.projects_unavailable`).
|
|
482
475
|
*/
|
|
483
|
-
async function listFailure(e,
|
|
476
|
+
async function listFailure(e, r, path, mode, signal) {
|
|
484
477
|
const passed = passThrough(e);
|
|
485
478
|
if (passed !== undefined)
|
|
486
479
|
return passed;
|
|
487
480
|
const why = e instanceof ToolError ? ` (${clipped(e.message)})` : "";
|
|
488
|
-
|
|
481
|
+
// the owner browse scope refusing the path is the device refusing it (gate on only)
|
|
482
|
+
if ((e instanceof ToolError && e.message.startsWith(POLICY_REFUSAL_PREFIX)) ||
|
|
483
|
+
(r.browse && isSandboxScopeDeniedError(e))) {
|
|
489
484
|
return new ApiError("device.project_outside_mode", `The device refused ${clipped(path)} in ${mode} mode${why}`);
|
|
490
485
|
}
|
|
491
486
|
let st;
|
|
492
487
|
try {
|
|
493
|
-
st = await
|
|
488
|
+
st = await r.stat(path, signal);
|
|
494
489
|
}
|
|
495
490
|
catch (e2) {
|
|
496
491
|
return passThrough(e2) ?? unavailable(e);
|
|
@@ -501,3 +496,4 @@ async function listFailure(e, p, h, path, mode, signal) {
|
|
|
501
496
|
? `${clipped(path)} is a directory the device cannot read${why}`
|
|
502
497
|
: `${clipped(path)} is a file, not a directory`);
|
|
503
498
|
}
|
|
499
|
+
const relativeTo = (base, path) => path === base ? "" : posix.relative(base, path);
|
|
@@ -72,13 +72,15 @@ let DevicesController = class DevicesController {
|
|
|
72
72
|
const tokenId = patTokenId(p);
|
|
73
73
|
// a person changes their device's mode in a web session, narrowing or widening (auto mode
|
|
74
74
|
// spec §4.3, hardening D2): never an API token
|
|
75
|
-
if (body.mode !== undefined && tokenId !== undefined) {
|
|
75
|
+
if ((body.mode !== undefined || body.ownerCeiling !== undefined) && tokenId !== undefined) {
|
|
76
76
|
throw new ApiError("device.mode_requires_session", "A device's mode is changed by its owner on the device page, not with an API token");
|
|
77
77
|
}
|
|
78
78
|
return {
|
|
79
79
|
device: await this.devices.update(org.orgId, p.account.id, params.id, {
|
|
80
80
|
...(body.name !== undefined && { name: body.name }),
|
|
81
81
|
...(body.mode !== undefined && { mode: body.mode }),
|
|
82
|
+
...(body.ownerCeiling !== undefined && { ownerCeiling: body.ownerCeiling }),
|
|
83
|
+
...(body.confirmWidening === true && { confirmWidening: true }),
|
|
82
84
|
}, tokenId),
|
|
83
85
|
};
|
|
84
86
|
}
|
|
@@ -7,9 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
8
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
9
9
|
import { LocalDevicesModule } from "../local-devices/local-devices.module.js";
|
|
10
|
+
import { PermissionFactsModule } from "../sandbox/permission-facts.module.js";
|
|
10
11
|
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
11
12
|
import { SandboxFileReader } from "../sandbox/sandbox-file-reader.js";
|
|
12
13
|
import { DeviceAccess } from "./access.js";
|
|
14
|
+
import { DeviceAccessModule } from "./access.module.js";
|
|
13
15
|
import { ConversationDevices } from "./conversation-devices.js";
|
|
14
16
|
import { DeviceProjectsService } from "./device-projects.service.js";
|
|
15
17
|
import { DevicesService } from "./devices.service.js";
|
|
@@ -25,18 +27,18 @@ DevicesModule = __decorate([
|
|
|
25
27
|
Module({
|
|
26
28
|
// ExtensionsModule: the provider display names of demoted defaults; LocalDevicesModule: deleting
|
|
27
29
|
// a local device revokes its machine
|
|
28
|
-
imports: [
|
|
30
|
+
imports: [
|
|
31
|
+
SandboxModule,
|
|
32
|
+
ExtensionsModule,
|
|
33
|
+
LocalDevicesModule,
|
|
34
|
+
DeviceAccessModule,
|
|
35
|
+
PermissionFactsModule,
|
|
36
|
+
],
|
|
29
37
|
// SandboxFileReader lives here, not in SandboxModule: it needs ConversationDevices, and this
|
|
30
38
|
// module already imports SandboxModule (the other way would be a module cycle)
|
|
31
|
-
providers: [
|
|
32
|
-
DeviceAccess,
|
|
33
|
-
DevicesService,
|
|
34
|
-
ConversationDevices,
|
|
35
|
-
SandboxFileReader,
|
|
36
|
-
DeviceProjectsService,
|
|
37
|
-
],
|
|
39
|
+
providers: [DevicesService, ConversationDevices, SandboxFileReader, DeviceProjectsService],
|
|
38
40
|
exports: [
|
|
39
|
-
|
|
41
|
+
DeviceAccessModule,
|
|
40
42
|
DevicesService,
|
|
41
43
|
ConversationDevices,
|
|
42
44
|
SandboxFileReader,
|