@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +3 -3
- package/dist/admin/admin.schemas.d.ts +6 -0
- package/dist/admin/org-network.service.d.ts +3 -1
- package/dist/admin/org-network.service.js +10 -2
- package/dist/app.d.ts +4 -0
- package/dist/app.js +2 -0
- package/dist/background/finish.d.ts +9 -1
- package/dist/background/finish.js +57 -4
- package/dist/background/launch.d.ts +23 -0
- package/dist/background/launch.js +55 -1
- package/dist/background/managed-output.d.ts +110 -0
- package/dist/background/managed-output.js +219 -0
- package/dist/background/managed.d.ts +52 -0
- package/dist/background/managed.js +128 -0
- package/dist/background/poll.job.d.ts +35 -1
- package/dist/background/poll.job.js +174 -9
- package/dist/background/render.js +1 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
- package/dist/background/retire-legacy-tasks.job.js +149 -0
- package/dist/background/session.d.ts +15 -5
- package/dist/background/session.js +22 -6
- package/dist/background/stop.d.ts +35 -5
- package/dist/background/stop.js +94 -8
- package/dist/background/store.d.ts +110 -3
- package/dist/background/store.js +205 -3
- package/dist/background/tasks.service.d.ts +18 -1
- package/dist/background/tasks.service.js +99 -9
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.js +1 -1
- package/dist/channels/inbound.js +2 -0
- package/dist/channels/phrases.d.ts +4 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/config/load.d.ts +18 -0
- package/dist/config/load.js +39 -1
- package/dist/config/permission-migration.d.ts +26 -0
- package/dist/config/permission-migration.js +64 -0
- package/dist/config/schema.d.ts +4 -1
- package/dist/config/schema.js +41 -10
- package/dist/conversations/conversations.controller.d.ts +1 -1
- package/dist/conversations/conversations.controller.js +1 -1
- package/dist/conversations/conversations.module.js +12 -0
- package/dist/conversations/conversations.service.d.ts +11 -2
- package/dist/conversations/conversations.service.js +97 -27
- package/dist/conversations/event-log.d.ts +1 -1
- package/dist/conversations/event-log.js +10 -2
- package/dist/conversations/events.d.ts +307 -4
- package/dist/conversations/events.js +286 -32
- package/dist/conversations/permission-profile-store.d.ts +50 -0
- package/dist/conversations/permission-profile-store.js +67 -0
- package/dist/conversations/permission-profile-store.module.d.ts +2 -0
- package/dist/conversations/permission-profile-store.module.js +19 -0
- package/dist/conversations/permission-profiles.controller.d.ts +84 -0
- package/dist/conversations/permission-profiles.controller.js +105 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
- package/dist/conversations/permission-profiles.schemas.js +23 -0
- package/dist/conversations/permission-profiles.service.d.ts +56 -0
- package/dist/conversations/permission-profiles.service.js +179 -0
- package/dist/ctx/create-ctx.d.ts +12 -5
- package/dist/ctx/create-ctx.js +21 -5
- package/dist/db/kernel-schema.d.ts +248 -3
- package/dist/devices/access.js +1 -1
- package/dist/devices/access.module.d.ts +2 -0
- package/dist/devices/access.module.js +19 -0
- package/dist/devices/conversation-devices.d.ts +8 -29
- package/dist/devices/conversation-devices.js +37 -73
- package/dist/devices/device-projects.service.d.ts +26 -28
- package/dist/devices/device-projects.service.js +123 -127
- package/dist/devices/devices.controller.js +3 -1
- package/dist/devices/devices.module.js +11 -9
- package/dist/devices/devices.service.d.ts +116 -8
- package/dist/devices/devices.service.js +252 -20
- package/dist/devices/dto.d.ts +16 -0
- package/dist/devices/dto.js +34 -6
- package/dist/devices/errors.d.ts +8 -0
- package/dist/devices/errors.js +10 -0
- package/dist/devices/project-rules.d.ts +44 -0
- package/dist/devices/project-rules.js +27 -0
- package/dist/devices/working-root.d.ts +6 -0
- package/dist/devices/working-root.js +12 -1
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +31 -0
- package/dist/evals/reconstruct.d.ts +19 -2
- package/dist/evals/reconstruct.js +40 -2
- package/dist/evals/recorded-permission-context.d.ts +77 -0
- package/dist/evals/recorded-permission-context.js +151 -0
- package/dist/evals/recorded-tools.d.ts +10 -1
- package/dist/evals/recorded-tools.js +27 -3
- package/dist/evals/run-replay.d.ts +8 -2
- package/dist/evals/run-replay.js +18 -2
- package/dist/evals/trajectory.d.ts +1 -1
- package/dist/evals/worker.d.ts +10 -1
- package/dist/evals/worker.js +23 -14
- package/dist/extensions/host.d.ts +4 -1
- package/dist/extensions/host.js +10 -6
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +14 -1
- package/dist/identity/accounts.js +61 -5
- package/dist/identity/identity.module.js +2 -0
- package/dist/identity/settings.d.ts +28 -12
- package/dist/identity/settings.js +89 -33
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
- package/dist/infra/cli/kernel-cli.module.js +5 -2
- package/dist/infra/cli/permission-cutover.d.ts +59 -0
- package/dist/infra/cli/permission-cutover.js +107 -0
- package/dist/infra/config/kernel-config.service.d.ts +2 -2
- package/dist/infra/config/kernel-config.service.js +35 -11
- package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
- package/dist/infra/database/startup-activation-transaction.js +242 -0
- package/dist/infra/database/transaction-host.d.ts +47 -0
- package/dist/infra/database/transaction-host.js +119 -0
- package/dist/infra/database/xact-lock.d.ts +1 -0
- package/dist/infra/database/xact-lock.js +6 -0
- package/dist/infra/outbox/registry.d.ts +39 -0
- package/dist/infra/outbox/registry.js +18 -0
- package/dist/kernel.module.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +55 -28
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +35 -5
- package/dist/local-devices/device-policy.service.js +188 -13
- package/dist/local-devices/instance-bindings.d.ts +82 -0
- package/dist/local-devices/instance-bindings.js +304 -0
- package/dist/local-devices/keys.d.ts +5 -0
- package/dist/local-devices/keys.js +5 -0
- package/dist/local-devices/local-device-gateway.d.ts +19 -4
- package/dist/local-devices/local-device-gateway.js +185 -17
- package/dist/local-devices/local-device-provider.d.ts +42 -7
- package/dist/local-devices/local-device-provider.js +185 -10
- package/dist/local-devices/local-devices.module.d.ts +17 -2
- package/dist/local-devices/local-devices.module.js +49 -8
- package/dist/local-devices/machines.d.ts +35 -12
- package/dist/local-devices/machines.js +203 -8
- package/dist/local-devices/network-grants.js +3 -3
- package/dist/local-devices/network-grants.module.d.ts +2 -0
- package/dist/local-devices/network-grants.module.js +14 -0
- package/dist/local-devices/owner-report.d.ts +79 -0
- package/dist/local-devices/owner-report.js +155 -0
- package/dist/local-devices/owner-reports.d.ts +48 -0
- package/dist/local-devices/owner-reports.js +190 -0
- package/dist/local-devices/policy-summary.d.ts +24 -1
- package/dist/local-devices/policy-summary.js +48 -0
- package/dist/local-devices/relay.d.ts +82 -6
- package/dist/local-devices/relay.js +187 -16
- package/dist/local-devices/targets.d.ts +16 -1
- package/dist/local-devices/targets.js +35 -2
- package/dist/models/image-usable.d.ts +22 -0
- package/dist/models/image-usable.js +29 -0
- package/dist/models/images.d.ts +125 -0
- package/dist/models/images.js +440 -0
- package/dist/models/models.module.d.ts +3 -2
- package/dist/models/models.module.js +16 -5
- package/dist/models/org-models.schemas.js +1 -0
- package/dist/models/purposes.controller.d.ts +7 -0
- package/dist/models/purposes.controller.js +9 -0
- package/dist/models/purposes.d.ts +28 -3
- package/dist/models/purposes.js +40 -13
- package/dist/orgs/cloud-network-setting.d.ts +33 -0
- package/dist/orgs/cloud-network-setting.js +47 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +8 -2
- package/dist/orgs/org-lock.d.ts +10 -4
- package/dist/orgs/org-lock.js +10 -4
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +8 -2
- package/dist/orgs/settings.controller.d.ts +4 -1
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +48 -56
- package/dist/orgs/settings.service.js +144 -101
- package/dist/overrides.d.ts +6 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin.ops.js +14 -11
- package/dist/platform/ops/agent-skills.ops.js +2 -0
- package/dist/platform/ops/devices.ops.js +10 -2
- package/dist/platform/ops/models.ops.js +10 -0
- package/dist/platform/ops/org-settings.ops.js +6 -6
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker.module.js +4 -0
- package/dist/runtime/context/build.d.ts +3 -1
- package/dist/runtime/context/build.js +19 -3
- package/dist/runtime/context/compaction.js +5 -0
- package/dist/runtime/context/device-paths.d.ts +9 -2
- package/dist/runtime/context/device-paths.js +20 -0
- package/dist/runtime/context/permission-profile.d.ts +46 -0
- package/dist/runtime/context/permission-profile.js +194 -0
- package/dist/runtime/hook-calls.d.ts +11 -1
- package/dist/runtime/hook-calls.js +24 -1
- package/dist/runtime/maintenance.d.ts +7 -1
- package/dist/runtime/maintenance.js +43 -15
- package/dist/runtime/model-call.d.ts +32 -0
- package/dist/runtime/model-call.js +67 -0
- package/dist/runtime/permission-context-errors.d.ts +39 -0
- package/dist/runtime/permission-context-errors.js +67 -0
- package/dist/runtime/permission-context.service.d.ts +60 -0
- package/dist/runtime/permission-context.service.js +286 -0
- package/dist/runtime/project/knowledge.d.ts +7 -2
- package/dist/runtime/project/knowledge.js +5 -2
- package/dist/runtime/project/knowledge.service.d.ts +17 -2
- package/dist/runtime/project/knowledge.service.js +76 -12
- package/dist/runtime/providers.d.ts +9 -5
- package/dist/runtime/providers.js +22 -3
- package/dist/runtime/run-execution.d.ts +4 -1
- package/dist/runtime/run-execution.js +14 -5
- package/dist/runtime/run-steps.d.ts +11 -3
- package/dist/runtime/run-steps.js +27 -4
- package/dist/runtime/runtime.module.js +11 -0
- package/dist/runtime/usage-report.d.ts +10 -6
- package/dist/runtime/usage-report.js +31 -11
- package/dist/sandbox/attachments-path.d.ts +15 -0
- package/dist/sandbox/attachments-path.js +15 -0
- package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
- package/dist/sandbox/cloud-permission-snapshot.js +407 -0
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
- package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
- package/dist/sandbox/held-operations.d.ts +39 -0
- package/dist/sandbox/held-operations.js +119 -0
- package/dist/sandbox/jobs.d.ts +14 -3
- package/dist/sandbox/jobs.js +20 -2
- package/dist/sandbox/kernel-read.d.ts +55 -0
- package/dist/sandbox/kernel-read.js +57 -0
- package/dist/sandbox/legacy-retirement.d.ts +336 -0
- package/dist/sandbox/legacy-retirement.js +1063 -0
- package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
- package/dist/sandbox/legacy-retirement.module.js +25 -0
- package/dist/sandbox/managed-device-context.d.ts +94 -0
- package/dist/sandbox/managed-device-context.js +308 -0
- package/dist/sandbox/managed-device-context.module.d.ts +6 -0
- package/dist/sandbox/managed-device-context.module.js +33 -0
- package/dist/sandbox/modes.d.ts +56 -8
- package/dist/sandbox/modes.js +92 -8
- package/dist/sandbox/operation-authority-types.d.ts +8 -0
- package/dist/sandbox/operation-authority-types.js +32 -0
- package/dist/sandbox/operation-authority.d.ts +145 -0
- package/dist/sandbox/operation-authority.js +783 -0
- package/dist/sandbox/operation-authority.module.d.ts +2 -0
- package/dist/sandbox/operation-authority.module.js +29 -0
- package/dist/sandbox/operation-intents.d.ts +206 -0
- package/dist/sandbox/operation-intents.js +1252 -0
- package/dist/sandbox/operation-intents.module.d.ts +2 -0
- package/dist/sandbox/operation-intents.module.js +21 -0
- package/dist/sandbox/operation-payloads.d.ts +33 -0
- package/dist/sandbox/operation-payloads.js +332 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
- package/dist/sandbox/operation-reconcile.job.js +247 -0
- package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
- package/dist/sandbox/permission-authority-epochs.js +83 -0
- package/dist/sandbox/permission-authority-lock.d.ts +38 -0
- package/dist/sandbox/permission-authority-lock.js +147 -0
- package/dist/sandbox/permission-authority.module.d.ts +9 -0
- package/dist/sandbox/permission-authority.module.js +55 -0
- package/dist/sandbox/permission-availability.d.ts +18 -0
- package/dist/sandbox/permission-availability.js +19 -0
- package/dist/sandbox/permission-call-grants.d.ts +34 -0
- package/dist/sandbox/permission-call-grants.js +349 -0
- package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
- package/dist/sandbox/permission-call-grants.module.js +21 -0
- package/dist/sandbox/permission-call-types.d.ts +82 -0
- package/dist/sandbox/permission-call-types.js +1 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
- package/dist/sandbox/permission-ceiling-writes.js +223 -0
- package/dist/sandbox/permission-config-publication.d.ts +76 -0
- package/dist/sandbox/permission-config-publication.js +339 -0
- package/dist/sandbox/permission-context-types.d.ts +64 -0
- package/dist/sandbox/permission-context-types.js +24 -0
- package/dist/sandbox/permission-facts.d.ts +206 -0
- package/dist/sandbox/permission-facts.js +627 -0
- package/dist/sandbox/permission-facts.module.d.ts +2 -0
- package/dist/sandbox/permission-facts.module.js +20 -0
- package/dist/sandbox/permission-instance-writes.d.ts +90 -0
- package/dist/sandbox/permission-instance-writes.js +305 -0
- package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
- package/dist/sandbox/permission-runtime-reports.js +354 -0
- package/dist/sandbox/permission-transitions.d.ts +31 -0
- package/dist/sandbox/permission-transitions.js +155 -0
- package/dist/sandbox/platform-full-access.d.ts +128 -0
- package/dist/sandbox/platform-full-access.js +210 -0
- package/dist/sandbox/providers.d.ts +22 -0
- package/dist/sandbox/providers.js +10 -2
- package/dist/sandbox/providers.module.d.ts +2 -0
- package/dist/sandbox/providers.module.js +19 -0
- package/dist/sandbox/request-not-sent.d.ts +13 -0
- package/dist/sandbox/request-not-sent.js +13 -0
- package/dist/sandbox/review/classifier.d.ts +2 -0
- package/dist/sandbox/review/classifier.js +8 -0
- package/dist/sandbox/review/permission-candidate.d.ts +12 -0
- package/dist/sandbox/review/permission-candidate.js +145 -0
- package/dist/sandbox/review/review.service.d.ts +5 -2
- package/dist/sandbox/review/review.service.js +60 -15
- package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
- package/dist/sandbox/sandbox-file-reader.js +51 -7
- package/dist/sandbox/sandbox.module.js +26 -6
- package/dist/sandbox/sandbox.service.d.ts +230 -34
- package/dist/sandbox/sandbox.service.js +1368 -199
- package/dist/sandbox/unreachable.js +17 -3
- package/dist/sandbox/use-context.d.ts +17 -0
- package/dist/sandbox/use-context.js +1 -0
- package/dist/skills/invoke.d.ts +27 -4
- package/dist/skills/invoke.js +72 -7
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.schemas.d.ts +1 -0
- package/dist/tools/approvals.schemas.js +3 -1
- package/dist/tools/approvals.service.d.ts +23 -10
- package/dist/tools/approvals.service.js +104 -26
- package/dist/tools/builtin-names.d.ts +3 -1
- package/dist/tools/builtin-names.js +5 -1
- package/dist/tools/builtins/artifacts.d.ts +43 -0
- package/dist/tools/builtins/artifacts.js +67 -0
- package/dist/tools/builtins/builtin-tools.d.ts +20 -2
- package/dist/tools/builtins/builtin-tools.js +61 -10
- package/dist/tools/builtins/image/generate.d.ts +59 -0
- package/dist/tools/builtins/image/generate.js +535 -0
- package/dist/tools/builtins/image/index.d.ts +2 -0
- package/dist/tools/builtins/image/index.js +2 -0
- package/dist/tools/builtins/image/paths.d.ts +12 -0
- package/dist/tools/builtins/image/paths.js +26 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
- package/dist/tools/builtins/sandbox/bash.js +201 -5
- package/dist/tools/builtins/sandbox/common.d.ts +92 -20
- package/dist/tools/builtins/sandbox/common.js +201 -17
- package/dist/tools/builtins/sandbox/deliver.js +9 -51
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +2 -2
- package/dist/tools/builtins/sandbox/task-list.js +7 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +172 -0
- package/dist/tools/builtins/sandbox/task-stop.js +25 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.js +9 -6
- package/dist/tools/device-op-resolver.d.ts +1 -1
- package/dist/tools/device-op-resolver.js +13 -3
- package/dist/tools/permission-approval-jobs.d.ts +18 -0
- package/dist/tools/permission-approval-jobs.js +92 -0
- package/dist/tools/pipeline.d.ts +17 -2
- package/dist/tools/pipeline.js +315 -26
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +15 -0
- package/package.json +4 -3
- package/src/migrations/0146_permission_authority_epochs.sql +6 -0
- package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
- package/src/migrations/0148_first_message_request_hash.sql +2 -0
- package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
- package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
- package/src/migrations/0151_starting_execution_grants.sql +8 -0
- package/src/migrations/0152_background_launch_identity.sql +66 -0
- package/src/migrations/0153_background_cancel_requester.sql +13 -0
- package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
- package/src/migrations/0155_device_instance_generations.sql +30 -0
- package/src/migrations/0156_device_owner_report.sql +7 -0
- package/src/migrations/0157_legacy_retirement.sql +116 -0
- package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
- package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
- package/src/migrations/0160_model_usage_image_kind.sql +10 -0
- package/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -14,10 +14,11 @@ import { applyPlatformAttributionPatch, PLATFORM_ATTRIBUTION_FIELDS, PLATFORM_AT
|
|
|
14
14
|
import { ApiError } from "../errors.js";
|
|
15
15
|
import { KernelConfigService } from "../infra/config/kernel-config.service.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 { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
20
|
-
import {
|
|
20
|
+
import { localMachineRoots, needsWiderDeviceCeiling, PermissionCeilingWrites, } from "../sandbox/permission-ceiling-writes.js";
|
|
21
|
+
import { applyDevicesFullAccessPatch, DEVICES_AUTO_MODE_PATCH, DEVICES_FULL_ACCESS_DEFAULT, DEVICES_FULL_ACCESS_PATCH, DEVICES_FULL_ACCESS_SETTING, fullAccessPatchOfLegacy, LEGACY_DEVICES_AUTO_MODE_SETTING, legacyAutoModeView, legacyDevicesAutoModeStored, readDevicesFullAccess, readStoredDevicesFullAccess, } from "../sandbox/platform-full-access.js";
|
|
21
22
|
import { assertPlatformDefaultEligible, lockThemeShared } from "../themes/theme-state.js";
|
|
22
23
|
import { mergeArrangement, UiArrangementPatchSchema, UiArrangementSchema, } from "../ui/arrangement.js";
|
|
23
24
|
import { audit } from "./audit.js";
|
|
@@ -211,7 +212,7 @@ export const DEPLOYMENT_SETTINGS = z.object({
|
|
|
211
212
|
compaction: COMPACTION_SETTINGS.prefault({}),
|
|
212
213
|
});
|
|
213
214
|
const DEFAULTS = DEPLOYMENT_SETTINGS.parse({});
|
|
214
|
-
const autoModeWidenRefused = () => new ApiError("deployment.auto_mode_not_allowed", "
|
|
215
|
+
const autoModeWidenRefused = () => new ApiError("deployment.auto_mode_not_allowed", "Allowing Full permission at the platform level (devicesFullAccess) needs a super admin in the admin console; an API token or the Platform tool may only turn it off.");
|
|
215
216
|
/**
|
|
216
217
|
* 设置的修改(PUT /api/v1/admin/settings 的 body):只改给出的键。
|
|
217
218
|
* `runConcurrencyOverrides` 按组织合并:值为正整数 → 设置该组织的上限;值为 null → 删除该组织的覆盖
|
|
@@ -258,11 +259,16 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
|
|
|
258
259
|
})
|
|
259
260
|
.optional(),
|
|
260
261
|
/**
|
|
261
|
-
* The platform's
|
|
262
|
-
*
|
|
262
|
+
* The platform's Full permission switch (B1): `permission` replaced, null clears it (back to
|
|
263
|
+
* the default, allowed). A value set in the startup config is read-only (409
|
|
263
264
|
* `deployment.setting_readonly`); an API token or the Platform tool may only turn it off (400
|
|
264
265
|
* `deployment.auto_mode_not_allowed`).
|
|
265
266
|
*/
|
|
267
|
+
devicesFullAccess: DEVICES_FULL_ACCESS_PATCH.optional(),
|
|
268
|
+
/**
|
|
269
|
+
* The old name of `devicesFullAccess` (`{ mode }`), still accepted with the same values; never
|
|
270
|
+
* together with it.
|
|
271
|
+
*/
|
|
266
272
|
devicesAutoMode: DEVICES_AUTO_MODE_PATCH.optional(),
|
|
267
273
|
/**
|
|
268
274
|
* The platform's attribution defaults for agent-created git commits and pull requests (spec
|
|
@@ -436,6 +442,23 @@ function mergeByOrg(current, patch) {
|
|
|
436
442
|
}
|
|
437
443
|
return merged;
|
|
438
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* A patch with the old `devicesAutoMode` moved to `devicesFullAccess`; both together is a
|
|
447
|
+
* validation error (never pick one silently).
|
|
448
|
+
*/
|
|
449
|
+
export function normalizeDeploymentSettingsPatch(patch) {
|
|
450
|
+
if (patch.devicesAutoMode === undefined)
|
|
451
|
+
return patch;
|
|
452
|
+
if (patch.devicesFullAccess !== undefined)
|
|
453
|
+
throw new ApiError("validation_failed", "Invalid deployment settings", [
|
|
454
|
+
{
|
|
455
|
+
path: "devicesAutoMode",
|
|
456
|
+
message: "give devicesFullAccess only: devicesAutoMode is its old name",
|
|
457
|
+
},
|
|
458
|
+
]);
|
|
459
|
+
const { devicesAutoMode, ...rest } = patch;
|
|
460
|
+
return { ...rest, devicesFullAccess: fullAccessPatchOfLegacy(devicesAutoMode) };
|
|
461
|
+
}
|
|
439
462
|
/** Deployment settings: one row per key, defaults for missing keys. */
|
|
440
463
|
let SettingsService = class SettingsService {
|
|
441
464
|
db;
|
|
@@ -443,25 +466,28 @@ let SettingsService = class SettingsService {
|
|
|
443
466
|
adminLock;
|
|
444
467
|
log;
|
|
445
468
|
config;
|
|
469
|
+
ceilings;
|
|
446
470
|
constructor(db, txHost, adminLock, log,
|
|
447
|
-
/** The startup config's `devices.
|
|
448
|
-
config) {
|
|
471
|
+
/** The startup config's `devices.fullAccess`, which wins over the stored choice. */
|
|
472
|
+
config, ceilings) {
|
|
449
473
|
this.db = db;
|
|
450
474
|
this.txHost = txHost;
|
|
451
475
|
this.adminLock = adminLock;
|
|
452
476
|
this.log = log;
|
|
453
477
|
this.config = config;
|
|
478
|
+
this.ceilings = ceilings;
|
|
454
479
|
}
|
|
455
|
-
/** The settings with the platform's
|
|
480
|
+
/** The settings with the platform's Full switch and attribution defaults in effect. */
|
|
456
481
|
async view() {
|
|
457
|
-
const [settings,
|
|
482
|
+
const [settings, devicesFullAccess, attribution] = await Promise.all([
|
|
458
483
|
this.get(),
|
|
459
|
-
|
|
484
|
+
readDevicesFullAccess(this.db.db, this.config, this.log),
|
|
460
485
|
readStoredPlatformAttribution(this.db.db, this.log),
|
|
461
486
|
]);
|
|
462
487
|
return {
|
|
463
488
|
...settings,
|
|
464
|
-
|
|
489
|
+
devicesFullAccess,
|
|
490
|
+
devicesAutoMode: legacyAutoModeView(devicesFullAccess),
|
|
465
491
|
attribution: this.attributionView(attribution),
|
|
466
492
|
};
|
|
467
493
|
}
|
|
@@ -474,20 +500,20 @@ let SettingsService = class SettingsService {
|
|
|
474
500
|
return { ...resolvePlatformAttribution(config, stored), sources };
|
|
475
501
|
}
|
|
476
502
|
/**
|
|
477
|
-
* The refusals of a `
|
|
503
|
+
* The refusals of a `devicesFullAccess` change: a value set in the startup config
|
|
478
504
|
* (`deployment.setting_readonly`) and, with `onlyNarrows` (an API token, the Platform tool),
|
|
479
|
-
*
|
|
480
|
-
*
|
|
505
|
+
* allowing Full where it is off (`deployment.auto_mode_not_allowed`). Returns the next stored
|
|
506
|
+
* choice and the effective switch before it.
|
|
481
507
|
*/
|
|
482
|
-
async
|
|
483
|
-
const source = this.config.fieldSource("devices.
|
|
508
|
+
async checkDevicesFullAccess(patch, opts = {}) {
|
|
509
|
+
const source = this.config.fieldSource("devices.fullAccess");
|
|
484
510
|
if (source !== undefined) {
|
|
485
|
-
throw new ApiError("deployment.setting_readonly", "The platform's
|
|
511
|
+
throw new ApiError("deployment.setting_readonly", "The platform's Full permission switch is set in the startup config (file, Nacos or environment) and is read-only here", [{ path: "devicesFullAccess.permission", source }]);
|
|
486
512
|
}
|
|
487
|
-
const before = await
|
|
488
|
-
const next =
|
|
489
|
-
const after = next.
|
|
490
|
-
if (opts.onlyNarrows && before.
|
|
513
|
+
const before = await readDevicesFullAccess(this.db.db, this.config, this.log);
|
|
514
|
+
const next = applyDevicesFullAccessPatch(await readStoredDevicesFullAccess(this.db.db, this.log), patch);
|
|
515
|
+
const after = next.permission ?? DEVICES_FULL_ACCESS_DEFAULT;
|
|
516
|
+
if (opts.onlyNarrows && before.permission === "off" && after === DEVICES_FULL_ACCESS_DEFAULT) {
|
|
491
517
|
throw autoModeWidenRefused();
|
|
492
518
|
}
|
|
493
519
|
return { next, before };
|
|
@@ -535,7 +561,7 @@ let SettingsService = class SettingsService {
|
|
|
535
561
|
}
|
|
536
562
|
/**
|
|
537
563
|
* Updates settings under the super admin lock, re-checking the actor (else `forbidden`).
|
|
538
|
-
* `onlyNarrows` (an API token, the Platform tool): `
|
|
564
|
+
* `onlyNarrows` (an API token, the Platform tool): `devicesFullAccess` may only turn Full off.
|
|
539
565
|
*/
|
|
540
566
|
async update(patch, actorAccountId, actorTokenId,
|
|
541
567
|
/** Merged into the audit detail (the Platform tool's `via: "agent"`). */
|
|
@@ -544,11 +570,21 @@ let SettingsService = class SettingsService {
|
|
|
544
570
|
if (!check.success) {
|
|
545
571
|
throw new ApiError("validation_failed", "Invalid deployment settings", check.error.issues.map((i) => ({ path: i.path.join("."), message: i.message })));
|
|
546
572
|
}
|
|
547
|
-
|
|
573
|
+
const normalized = normalizeDeploymentSettingsPatch(check.data);
|
|
574
|
+
// the super admin lock, then (for a Full switch change) the platform permission authority
|
|
575
|
+
// lock: the ordered prelude, so inside a run's fence (the Platform tool's
|
|
576
|
+
// `admin.update-settings`) they precede the conversation rows; the patch decides the lock
|
|
577
|
+
await withOrderedLocks(() => this.lockFor(normalized, actorAccountId), () => this.write(normalized, actorAccountId, actorTokenId, auditDetail, opts));
|
|
548
578
|
return this.view();
|
|
549
579
|
}
|
|
550
|
-
async
|
|
580
|
+
async lockFor(patch, actorAccountId) {
|
|
551
581
|
await this.adminLock.lockAndAuthorize(actorAccountId);
|
|
582
|
+
if (patch.devicesFullAccess !== undefined)
|
|
583
|
+
await this.ceilings.lock({}, "platform");
|
|
584
|
+
}
|
|
585
|
+
async write(patch, actorAccountId, actorTokenId, auditDetail, opts) {
|
|
586
|
+
// held since the prelude (`lockFor`); naming them again re-checks the actor
|
|
587
|
+
await this.lockFor(patch, actorAccountId);
|
|
552
588
|
// The super admin lock serializes every settings write: the current overrides are read
|
|
553
589
|
// and merged under it, so no concurrent change is lost
|
|
554
590
|
const next = {};
|
|
@@ -616,14 +652,30 @@ let SettingsService = class SettingsService {
|
|
|
616
652
|
next.subagentLimitOverrides = mergeByOrg(current.subagentLimitOverrides, subagentPatch);
|
|
617
653
|
}
|
|
618
654
|
}
|
|
619
|
-
// the platform's
|
|
620
|
-
//
|
|
621
|
-
let
|
|
655
|
+
// the platform's Full switch: checked against the stored choice under the lock; the stored
|
|
656
|
+
// shape keeps `permission` optional, so clearing it (null) writes `{}` back to the default
|
|
657
|
+
let fullAccessChange;
|
|
622
658
|
const writes = Object.entries(next);
|
|
623
|
-
if (patch.
|
|
624
|
-
const r = await this.
|
|
625
|
-
|
|
626
|
-
|
|
659
|
+
if (patch.devicesFullAccess !== undefined) {
|
|
660
|
+
const r = await this.checkDevicesFullAccess(patch.devicesFullAccess, opts);
|
|
661
|
+
fullAccessChange = {
|
|
662
|
+
before: r.before,
|
|
663
|
+
after: r.next.permission ?? DEVICES_FULL_ACCESS_DEFAULT,
|
|
664
|
+
};
|
|
665
|
+
writes.push([DEVICES_FULL_ACCESS_SETTING, r.next]);
|
|
666
|
+
// until 8.6: an unconverted (or re-written by an old replica) old key is kept in step, so
|
|
667
|
+
// neither side reads a value the super admin did not choose
|
|
668
|
+
if (await legacyDevicesAutoModeStored(this.db.db))
|
|
669
|
+
writes.push([
|
|
670
|
+
LEGACY_DEVICES_AUTO_MODE_SETTING,
|
|
671
|
+
r.next.permission === undefined ? {} : { mode: r.next.permission },
|
|
672
|
+
]);
|
|
673
|
+
if (fullAccessChange.before.permission !== fullAccessChange.after) {
|
|
674
|
+
const machineRoots = fullAccessChange.after === "off" ? await localMachineRoots(this.db.db) : null;
|
|
675
|
+
await this.ceilings.publishLocked({}, "platform", machineRoots === null
|
|
676
|
+
? false
|
|
677
|
+
: (scope, row) => needsWiderDeviceCeiling(scope, machineRoots.get(row.device_id)), true);
|
|
678
|
+
}
|
|
627
679
|
}
|
|
628
680
|
// the platform's attribution defaults: a field set in the startup config is read-only
|
|
629
681
|
if (patch.attribution !== undefined) {
|
|
@@ -647,12 +699,15 @@ let SettingsService = class SettingsService {
|
|
|
647
699
|
action: "deployment.settings.updated",
|
|
648
700
|
detail: {
|
|
649
701
|
...patch,
|
|
650
|
-
...(
|
|
702
|
+
...(fullAccessChange !== undefined && { devicesFullAccessEffective: fullAccessChange }),
|
|
651
703
|
...auditDetail,
|
|
652
704
|
},
|
|
653
705
|
});
|
|
654
706
|
}
|
|
655
707
|
};
|
|
708
|
+
__decorate([
|
|
709
|
+
Transactional({ propagation: "mandatory" })
|
|
710
|
+
], SettingsService.prototype, "lockFor", null);
|
|
656
711
|
__decorate([
|
|
657
712
|
Transactional()
|
|
658
713
|
], SettingsService.prototype, "write", null);
|
|
@@ -662,6 +717,7 @@ SettingsService = __decorate([
|
|
|
662
717
|
__param(1, Inject(TransactionHost)),
|
|
663
718
|
__param(2, Inject(SuperAdminLock)),
|
|
664
719
|
__param(3, Inject(KERNEL_LOGGER)),
|
|
665
|
-
__param(4, Inject(KernelConfigService))
|
|
720
|
+
__param(4, Inject(KernelConfigService)),
|
|
721
|
+
__param(5, Inject(PermissionCeilingWrites))
|
|
666
722
|
], SettingsService);
|
|
667
723
|
export { SettingsService };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { type ConfigField, changedPaths, configFields, secretValues } from "./co
|
|
|
11
11
|
export { fileSource } from "./config/file-source.js";
|
|
12
12
|
export { ConfigError, type ConfigSource, loadConfig, loadConfigWithSources, resolveConfig, selectConfigSource, } from "./config/load.js";
|
|
13
13
|
export { createNacosSource, type NacosSourceOptions } from "./config/nacos-source.js";
|
|
14
|
+
export { legacyPermissionEnvRenames, migratePermissionConfigText, type PermissionConfigMigration, type PermissionEnvRename, } from "./config/permission-migration.js";
|
|
14
15
|
export { type FieldMeta, type KernelConfig, KernelConfigSchema, MARKETPLACE_OFFICIAL_URL_DEFAULT, meta, PACKAGES_MAX_BYTES_DEFAULT, } from "./config/schema.js";
|
|
15
16
|
export { type ConfigSourceKind, configSourceKind, extensionConfigSources, } from "./config/sources.js";
|
|
16
17
|
export type { ConversationEvent } from "./conversations/events.js";
|
|
@@ -55,6 +56,7 @@ export { type IssuedSession, REFRESH_RACE_GRACE_MS, SessionService, } from "./id
|
|
|
55
56
|
export { DEPLOYMENT_SETTINGS, type DeploymentSettings, SettingsService, } from "./identity/settings.js";
|
|
56
57
|
export { type KernelCliOptions, openKernelCli, openKernelCliOverPool, } from "./infra/cli/kernel-cli.module.js";
|
|
57
58
|
export { rewrapMasterKeys } from "./infra/cli/master-key-rewrap.js";
|
|
59
|
+
export { type CutoverReplica, type PermissionCutoverReport, permissionCutoverFreeze, permissionCutoverReport, permissionCutoverSnapshot, } from "./infra/cli/permission-cutover.js";
|
|
58
60
|
export { onProcessFault } from "./infra/health/process-fault.js";
|
|
59
61
|
export { GUARD_CIRCUIT_LIMIT, GUARD_CIRCUIT_WINDOW_MS, installProcessGuards, type ProcessGuardDeps, } from "./infra/lifecycle/process-guards.js";
|
|
60
62
|
export { handleShutdownSignals, type ShutdownSignalHandle, type ShutdownSignalOptions, } from "./infra/lifecycle/shutdown-signals.js";
|
|
@@ -74,7 +76,11 @@ export type { AgentLoop, LoopContext, LoopOutcome } from "./runtime/loop.js";
|
|
|
74
76
|
export { MAINTENANCE_QUEUE_NAME } from "./runtime/maintenance-queue.js";
|
|
75
77
|
export { type OrphanCandidate, queuedRunsWithoutJob } from "./runtime/run-orphan-check.job.js";
|
|
76
78
|
export { runJobId } from "./runtime/run-queue.js";
|
|
79
|
+
export type { CloudSnapshotProgress, CloudSnapshotResult, CloudSnapshotRun, } from "./sandbox/cloud-permission-snapshot.js";
|
|
77
80
|
export { SANDBOX_DESTROY_JOB, SANDBOX_SUSPEND_JOB, } from "./sandbox/jobs.js";
|
|
81
|
+
export { CutoverBarrierError, type LegacyFreezeResult, LegacyFreezeUnsettledError, type LegacyRetirementReport, } from "./sandbox/legacy-retirement.js";
|
|
82
|
+
export { PermissionAuthorityModule } from "./sandbox/permission-authority.module.js";
|
|
83
|
+
export { PermissionConfigPublication } from "./sandbox/permission-config-publication.js";
|
|
78
84
|
export { SANDBOX_LOCK_TTL_MS, SandboxService, type SandboxUseInfo, } from "./sandbox/sandbox.service.js";
|
|
79
85
|
export { MAX_STORAGE_KEY_BYTES, StorageKeyError, } from "./storage/prefix.js";
|
|
80
86
|
export { PrefixedStorage, StorageService, type StorageSource, } from "./storage/storage.service.js";
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { changedPaths, configFields, secretValues } from "./config/fields.js";
|
|
|
11
11
|
export { fileSource } from "./config/file-source.js";
|
|
12
12
|
export { ConfigError, loadConfig, loadConfigWithSources, resolveConfig, selectConfigSource, } from "./config/load.js";
|
|
13
13
|
export { createNacosSource } from "./config/nacos-source.js";
|
|
14
|
+
export { legacyPermissionEnvRenames, migratePermissionConfigText, } from "./config/permission-migration.js";
|
|
14
15
|
export { KernelConfigSchema, MARKETPLACE_OFFICIAL_URL_DEFAULT, meta, PACKAGES_MAX_BYTES_DEFAULT, } from "./config/schema.js";
|
|
15
16
|
export { configSourceKind, extensionConfigSources, } from "./config/sources.js";
|
|
16
17
|
export { createBus, createBusSubscriber } from "./ctx/bus.js";
|
|
@@ -53,6 +54,7 @@ export { REFRESH_RACE_GRACE_MS, SessionService, } from "./identity/sessions.js";
|
|
|
53
54
|
export { DEPLOYMENT_SETTINGS, SettingsService, } from "./identity/settings.js";
|
|
54
55
|
export { openKernelCli, openKernelCliOverPool, } from "./infra/cli/kernel-cli.module.js";
|
|
55
56
|
export { rewrapMasterKeys } from "./infra/cli/master-key-rewrap.js";
|
|
57
|
+
export { permissionCutoverFreeze, permissionCutoverReport, permissionCutoverSnapshot, } from "./infra/cli/permission-cutover.js";
|
|
56
58
|
export { onProcessFault } from "./infra/health/process-fault.js";
|
|
57
59
|
export { GUARD_CIRCUIT_LIMIT, GUARD_CIRCUIT_WINDOW_MS, installProcessGuards, } from "./infra/lifecycle/process-guards.js";
|
|
58
60
|
export { handleShutdownSignals, } from "./infra/lifecycle/shutdown-signals.js";
|
|
@@ -73,6 +75,9 @@ export { MAINTENANCE_QUEUE_NAME } from "./runtime/maintenance-queue.js";
|
|
|
73
75
|
export { queuedRunsWithoutJob } from "./runtime/run-orphan-check.job.js";
|
|
74
76
|
export { runJobId } from "./runtime/run-queue.js";
|
|
75
77
|
export { SANDBOX_DESTROY_JOB, SANDBOX_SUSPEND_JOB, } from "./sandbox/jobs.js";
|
|
78
|
+
export { CutoverBarrierError, LegacyFreezeUnsettledError, } from "./sandbox/legacy-retirement.js";
|
|
79
|
+
export { PermissionAuthorityModule } from "./sandbox/permission-authority.module.js";
|
|
80
|
+
export { PermissionConfigPublication } from "./sandbox/permission-config-publication.js";
|
|
76
81
|
export { SANDBOX_LOCK_TTL_MS, SandboxService, } from "./sandbox/sandbox.service.js";
|
|
77
82
|
export { MAX_STORAGE_KEY_BYTES, StorageKeyError, } from "./storage/prefix.js";
|
|
78
83
|
export { PrefixedStorage, StorageService, } from "./storage/storage.service.js";
|
|
@@ -43,8 +43,8 @@ export declare class KernelCliModule {
|
|
|
43
43
|
/**
|
|
44
44
|
* A context over a pool the caller owns, for code that has a pool and no config
|
|
45
45
|
* (`@capybara-hq/testing`'s `createLocalAccount`): the logger, the database handles over `pool`
|
|
46
|
-
* (never closed by the context), in-process events and the given modules. No config,
|
|
47
|
-
* no Redis: only modules that need nothing more fit.
|
|
46
|
+
* (never closed by the context), the outbox, in-process events and the given modules. No config,
|
|
47
|
+
* no keyring, no Redis: only modules that need nothing more fit.
|
|
48
48
|
*/
|
|
49
49
|
static overPool(pool: Kysely<any>, opts: {
|
|
50
50
|
logger: KernelLogger;
|
|
@@ -132,8 +132,8 @@ let KernelCliModule = KernelCliModule_1 = class KernelCliModule {
|
|
|
132
132
|
/**
|
|
133
133
|
* A context over a pool the caller owns, for code that has a pool and no config
|
|
134
134
|
* (`@capybara-hq/testing`'s `createLocalAccount`): the logger, the database handles over `pool`
|
|
135
|
-
* (never closed by the context), in-process events and the given modules. No config,
|
|
136
|
-
* no Redis: only modules that need nothing more fit.
|
|
135
|
+
* (never closed by the context), the outbox, in-process events and the given modules. No config,
|
|
136
|
+
* no keyring, no Redis: only modules that need nothing more fit.
|
|
137
137
|
*/
|
|
138
138
|
static overPool(
|
|
139
139
|
// biome-ignore lint/suspicious/noExplicitAny: the pool carries no schema types
|
|
@@ -144,6 +144,9 @@ let KernelCliModule = KernelCliModule_1 = class KernelCliModule {
|
|
|
144
144
|
imports: [
|
|
145
145
|
LoggingModule.forLogger(opts.logger),
|
|
146
146
|
DatabaseModule.borrowing(pool),
|
|
147
|
+
// owed work the modules' writes carry (an account status change revokes permission
|
|
148
|
+
// authority through the outbox): rows in PG, delivered by a worker's relay
|
|
149
|
+
OutboxModule,
|
|
147
150
|
KernelEventsModule,
|
|
148
151
|
...opts.modules,
|
|
149
152
|
],
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { KernelConfig } from "../../config/schema.js";
|
|
2
|
+
import type { KernelLogger } from "../../log.js";
|
|
3
|
+
import { type CloudSnapshotProgress, type CloudSnapshotRun } from "../../sandbox/cloud-permission-snapshot.js";
|
|
4
|
+
import { type LegacyFreezeResult, type LegacyRetirementReport } from "../../sandbox/legacy-retirement.js";
|
|
5
|
+
/**
|
|
6
|
+
* The operator surface of the permission runtime cutover (B-10, B-26): `capybara permissions
|
|
7
|
+
* cutover report | freeze | snapshot`. The report and the freeze use PostgreSQL only (the report
|
|
8
|
+
* reads replica presence from Redis when it answers, and says so when it does not); the snapshot
|
|
9
|
+
* needs Redis, because each device is snapshotted under its lifecycle lease.
|
|
10
|
+
*/
|
|
11
|
+
/** A live replica as the report shows it. */
|
|
12
|
+
export interface CutoverReplica {
|
|
13
|
+
id: string;
|
|
14
|
+
version: string;
|
|
15
|
+
roles: string[];
|
|
16
|
+
startedAt: string;
|
|
17
|
+
/** Runs this CLI's kernel version. */
|
|
18
|
+
sameVersion: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** `capybara permissions cutover report`. */
|
|
21
|
+
export interface PermissionCutoverReport {
|
|
22
|
+
kernelVersion: string;
|
|
23
|
+
/** This CLI's permission configuration is the published one (the snapshot needs it). */
|
|
24
|
+
configCurrent: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The live replicas by presence (Redis), null when Redis did not answer. A replica on another
|
|
27
|
+
* version may run code without the freeze (unfenced): stop old replicas before the freeze.
|
|
28
|
+
*/
|
|
29
|
+
replicas: CutoverReplica[] | null;
|
|
30
|
+
retirement: LegacyRetirementReport;
|
|
31
|
+
snapshot: CloudSnapshotProgress;
|
|
32
|
+
}
|
|
33
|
+
/** The report (no writes). `presence: false` skips the replica presence read. */
|
|
34
|
+
export declare function permissionCutoverReport(config: KernelConfig, opts: {
|
|
35
|
+
logger: KernelLogger;
|
|
36
|
+
presence?: boolean;
|
|
37
|
+
}): Promise<PermissionCutoverReport>;
|
|
38
|
+
/**
|
|
39
|
+
* Publishes the legacy-launch freeze and enumerates until stable before returning
|
|
40
|
+
* ({@link LegacyRetirementStore.freeze}; idempotent, never undone), then reads the report.
|
|
41
|
+
* Throws `LegacyFreezeUnsettledError` when the enumeration did not settle.
|
|
42
|
+
*/
|
|
43
|
+
export declare function permissionCutoverFreeze(config: KernelConfig, opts: {
|
|
44
|
+
logger: KernelLogger;
|
|
45
|
+
by: string;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
freeze: LegacyFreezeResult;
|
|
48
|
+
report: PermissionCutoverReport;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Runs the cloud snapshot driver ({@link CloudPermissionSnapshots.snapshotAll}) in a context with
|
|
52
|
+
* the CLI's Redis (the lifecycle leases). Throws `CutoverBarrierError` before the freeze, and the
|
|
53
|
+
* scope denial when this CLI's permission configuration is not the published one.
|
|
54
|
+
*/
|
|
55
|
+
export declare function permissionCutoverSnapshot(config: KernelConfig, opts: {
|
|
56
|
+
logger: KernelLogger;
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
leaseWaitMs?: number;
|
|
59
|
+
}): Promise<CloudSnapshotRun>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import { CloudPermissionSnapshots, readCloudSnapshotProgress, } from "../../sandbox/cloud-permission-snapshot.js";
|
|
3
|
+
import { CloudPermissionSnapshotsModule } from "../../sandbox/cloud-permission-snapshot.module.js";
|
|
4
|
+
import { LegacyRetirementStore, } from "../../sandbox/legacy-retirement.js";
|
|
5
|
+
import { LegacyRetirementModule } from "../../sandbox/legacy-retirement.module.js";
|
|
6
|
+
import { PermissionAuthorityModule } from "../../sandbox/permission-authority.module.js";
|
|
7
|
+
import { PermissionConfigPublication } from "../../sandbox/permission-config-publication.js";
|
|
8
|
+
import { KERNEL_VERSION } from "../../version.js";
|
|
9
|
+
import { KernelDb } from "../database/kernel-db.js";
|
|
10
|
+
import { PRESENCE_DEFAULT_INTERVAL_MS, readLiveReplicas } from "../presence/replica-presence.js";
|
|
11
|
+
import { openKernelCli } from "./kernel-cli.module.js";
|
|
12
|
+
/** How long the report waits for Redis before it reports replicas as unknown. */
|
|
13
|
+
const PRESENCE_CONNECT_TIMEOUT_MS = 2_000;
|
|
14
|
+
/** The live replicas, or null when Redis does not answer (the report never fails on it). */
|
|
15
|
+
async function liveReplicas(url) {
|
|
16
|
+
const redis = new Redis(url, {
|
|
17
|
+
lazyConnect: true,
|
|
18
|
+
connectTimeout: PRESENCE_CONNECT_TIMEOUT_MS,
|
|
19
|
+
maxRetriesPerRequest: 0,
|
|
20
|
+
retryStrategy: () => null,
|
|
21
|
+
});
|
|
22
|
+
redis.on("error", () => { });
|
|
23
|
+
try {
|
|
24
|
+
await redis.connect();
|
|
25
|
+
const live = await readLiveReplicas(redis, PRESENCE_DEFAULT_INTERVAL_MS * 3);
|
|
26
|
+
return live.map((r) => ({
|
|
27
|
+
id: r.id,
|
|
28
|
+
version: r.version,
|
|
29
|
+
roles: r.roles,
|
|
30
|
+
startedAt: r.startedAt,
|
|
31
|
+
sameVersion: r.version === KERNEL_VERSION,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
redis.disconnect();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Opens the PostgreSQL-only context of the report and the freeze, runs `fn` and closes it. */
|
|
42
|
+
async function withPgContext(config, logger, fn) {
|
|
43
|
+
const app = await openKernelCli(config, {
|
|
44
|
+
logger,
|
|
45
|
+
modules: [LegacyRetirementModule, PermissionAuthorityModule],
|
|
46
|
+
redis: false,
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
return await fn(app);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
await app.close().catch((err) => {
|
|
53
|
+
logger.debug("permissions cutover: closing the CLI context failed", { err });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function readReport(app, replicas) {
|
|
58
|
+
const configCurrent = await app
|
|
59
|
+
.get(PermissionConfigPublication)
|
|
60
|
+
.assertCurrent()
|
|
61
|
+
.then(() => true, () => false);
|
|
62
|
+
return {
|
|
63
|
+
kernelVersion: KERNEL_VERSION,
|
|
64
|
+
configCurrent,
|
|
65
|
+
replicas,
|
|
66
|
+
retirement: await app.get(LegacyRetirementStore).report(),
|
|
67
|
+
snapshot: await readCloudSnapshotProgress(app.get(KernelDb)),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** The report (no writes). `presence: false` skips the replica presence read. */
|
|
71
|
+
export async function permissionCutoverReport(config, opts) {
|
|
72
|
+
const replicas = opts.presence === false ? null : await liveReplicas(config.redis.url);
|
|
73
|
+
return withPgContext(config, opts.logger, (app) => readReport(app, replicas));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Publishes the legacy-launch freeze and enumerates until stable before returning
|
|
77
|
+
* ({@link LegacyRetirementStore.freeze}; idempotent, never undone), then reads the report.
|
|
78
|
+
* Throws `LegacyFreezeUnsettledError` when the enumeration did not settle.
|
|
79
|
+
*/
|
|
80
|
+
export async function permissionCutoverFreeze(config, opts) {
|
|
81
|
+
return withPgContext(config, opts.logger, async (app) => {
|
|
82
|
+
const freeze = await app.get(LegacyRetirementStore).freeze(opts.by);
|
|
83
|
+
return { freeze, report: await readReport(app, null) };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Runs the cloud snapshot driver ({@link CloudPermissionSnapshots.snapshotAll}) in a context with
|
|
88
|
+
* the CLI's Redis (the lifecycle leases). Throws `CutoverBarrierError` before the freeze, and the
|
|
89
|
+
* scope denial when this CLI's permission configuration is not the published one.
|
|
90
|
+
*/
|
|
91
|
+
export async function permissionCutoverSnapshot(config, opts) {
|
|
92
|
+
const app = await openKernelCli(config, {
|
|
93
|
+
logger: opts.logger,
|
|
94
|
+
modules: [CloudPermissionSnapshotsModule],
|
|
95
|
+
});
|
|
96
|
+
try {
|
|
97
|
+
return await app.get(CloudPermissionSnapshots).snapshotAll({
|
|
98
|
+
...(opts.signal !== undefined && { signal: opts.signal }),
|
|
99
|
+
...(opts.leaseWaitMs !== undefined && { leaseWaitMs: opts.leaseWaitMs }),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
await app.close().catch((err) => {
|
|
104
|
+
opts.logger.debug("permissions cutover: closing the CLI context failed", { err });
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -19,7 +19,7 @@ export declare class KernelConfigService {
|
|
|
19
19
|
* Where the current value of a field without a schema default comes from: `env` when an
|
|
20
20
|
* environment variable sets it, else the config source (`file` / `nacos`) when it is set at all;
|
|
21
21
|
* undefined when nothing sets it (a layer below the startup config decides, e.g. the deployment
|
|
22
|
-
* settings for `devices.
|
|
22
|
+
* settings for `devices.fullAccess`). Such fields are read-only in the admin console.
|
|
23
23
|
*/
|
|
24
24
|
fieldSource(path: string): "env" | "file" | "nacos" | undefined;
|
|
25
25
|
/** Subscribes to applied changes (hot fields only); returns the unsubscribe function. */
|
|
@@ -28,5 +28,5 @@ export declare class KernelConfigService {
|
|
|
28
28
|
* Hot reload: re-validates the raw config; only hot fields are applied, other changes warn and
|
|
29
29
|
* list the keys needing a restart; a validation failure keeps the current config.
|
|
30
30
|
*/
|
|
31
|
-
apply(raw: unknown): void
|
|
31
|
+
apply(raw: unknown, publish?: (before: KernelConfig, next: KernelConfig) => Promise<void>): Promise<void>;
|
|
32
32
|
}
|
|
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { envOverrides } from "../../config/env.js";
|
|
12
12
|
import { changedPaths, configFields, getPath, secretValues, setPath } from "../../config/fields.js";
|
|
13
|
-
import { resolveConfig } from "../../config/load.js";
|
|
13
|
+
import { resolveConfig, translateLegacyPermissionKeys } from "../../config/load.js";
|
|
14
14
|
import { KernelConfigSchema } from "../../config/schema.js";
|
|
15
15
|
import { configSourceKind } from "../../config/sources.js";
|
|
16
16
|
import { KERNEL_CONFIG_INPUT, KERNEL_LOGGER } from "../tokens.js";
|
|
@@ -35,13 +35,17 @@ const HOT_APPLIERS = {
|
|
|
35
35
|
// The provider registry reads the list time limit at every listModels call.
|
|
36
36
|
"models.listTimeoutMs": () => { },
|
|
37
37
|
"models.embedTimeoutMs": () => { },
|
|
38
|
+
// ModelImages reads the image limits at every prepare and run.
|
|
39
|
+
"models.imageTimeoutMs": () => { },
|
|
40
|
+
"models.imageMaxPerCall": () => { },
|
|
41
|
+
"models.imagePromptMaxChars": () => { },
|
|
38
42
|
// SandboxService reads the shared-lease cap at every acquisition.
|
|
39
43
|
"sandbox.maxConcurrentCommands": () => { },
|
|
40
44
|
// The command-review service reads the classifier's bounds at every classifier call.
|
|
41
45
|
"sandbox.review.timeoutMs": () => { },
|
|
42
46
|
"sandbox.review.messageTokens": () => { },
|
|
43
|
-
// The devices service reads the platform's
|
|
44
|
-
"devices.
|
|
47
|
+
// The devices service reads the platform's Full switch at every device use and settings read.
|
|
48
|
+
"devices.fullAccess": () => { },
|
|
45
49
|
// The devices service reads the personal limit at every create.
|
|
46
50
|
"devices.maxPersonal": () => { },
|
|
47
51
|
// The local device relay reads the reconnect grace at every disconnect and token response.
|
|
@@ -97,14 +101,15 @@ let KernelConfigService = class KernelConfigService {
|
|
|
97
101
|
* Where the current value of a field without a schema default comes from: `env` when an
|
|
98
102
|
* environment variable sets it, else the config source (`file` / `nacos`) when it is set at all;
|
|
99
103
|
* undefined when nothing sets it (a layer below the startup config decides, e.g. the deployment
|
|
100
|
-
* settings for `devices.
|
|
104
|
+
* settings for `devices.fullAccess`). Such fields are read-only in the admin console.
|
|
101
105
|
*/
|
|
102
106
|
fieldSource(path) {
|
|
103
107
|
if (getPath(this.current, path) === undefined)
|
|
104
108
|
return undefined;
|
|
105
109
|
let fromEnv = false;
|
|
106
110
|
try {
|
|
107
|
-
fromEnv =
|
|
111
|
+
fromEnv =
|
|
112
|
+
getPath(translateLegacyPermissionKeys(envOverrides(this.env), "env"), path) !== undefined;
|
|
108
113
|
}
|
|
109
114
|
catch {
|
|
110
115
|
// conflicting variables fail the start; a later change here only loses the label
|
|
@@ -122,7 +127,7 @@ let KernelConfigService = class KernelConfigService {
|
|
|
122
127
|
* Hot reload: re-validates the raw config; only hot fields are applied, other changes warn and
|
|
123
128
|
* list the keys needing a restart; a validation failure keeps the current config.
|
|
124
129
|
*/
|
|
125
|
-
apply(raw) {
|
|
130
|
+
async apply(raw, publish) {
|
|
126
131
|
const log = this.log;
|
|
127
132
|
let next;
|
|
128
133
|
try {
|
|
@@ -141,15 +146,34 @@ let KernelConfigService = class KernelConfigService {
|
|
|
141
146
|
const updated = structuredClone(this.current);
|
|
142
147
|
const applied = [];
|
|
143
148
|
for (const p of hot) {
|
|
149
|
+
setPath(updated, p, getPath(next, p));
|
|
150
|
+
applied.push(p);
|
|
151
|
+
}
|
|
152
|
+
if (applied.includes("devices.fullAccess")) {
|
|
153
|
+
if (!publish) {
|
|
154
|
+
log.error("permission config reload rejected: durable publication is required");
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
await publish(this.current, updated);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
log.error("permission config publication failed; keeping current config", {
|
|
162
|
+
error: errMsg(error),
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const p of [...applied]) {
|
|
144
168
|
try {
|
|
145
|
-
HOT_APPLIERS[p]({ log }, getPath(
|
|
146
|
-
setPath(updated, p, getPath(next, p));
|
|
147
|
-
applied.push(p);
|
|
169
|
+
HOT_APPLIERS[p]({ log }, getPath(updated, p));
|
|
148
170
|
}
|
|
149
|
-
catch (
|
|
171
|
+
catch (error) {
|
|
172
|
+
setPath(updated, p, getPath(this.current, p));
|
|
173
|
+
applied.splice(applied.indexOf(p), 1);
|
|
150
174
|
log.error("config reload: cannot apply field; keeping current value", {
|
|
151
175
|
key: p,
|
|
152
|
-
error: errMsg(
|
|
176
|
+
error: errMsg(error),
|
|
153
177
|
});
|
|
154
178
|
}
|
|
155
179
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Transaction } from "kysely";
|
|
2
|
+
export interface StartupActivationOptions {
|
|
3
|
+
connectionString: string;
|
|
4
|
+
connectTimeoutMs?: number;
|
|
5
|
+
signal: AbortSignal;
|
|
6
|
+
remainingMs: () => number;
|
|
7
|
+
/**
|
|
8
|
+
* Test seam: the owned session's `idle_in_transaction_session_timeout` instead of
|
|
9
|
+
* {@link STARTUP_IDLE_IN_TRANSACTION_TIMEOUT_MS} (tests shorten it to prove the bound fails
|
|
10
|
+
* closed). Not an operator setting.
|
|
11
|
+
*/
|
|
12
|
+
idleInTransactionTimeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Server-side bound on one statement of the owned startup session. */
|
|
15
|
+
export declare const STARTUP_STATEMENT_TIMEOUT_MS = 500;
|
|
16
|
+
/** Server-side bound on one lock wait of the owned startup session. */
|
|
17
|
+
export declare const STARTUP_LOCK_TIMEOUT_MS = 500;
|
|
18
|
+
/**
|
|
19
|
+
* Server-side bound on the gap between two statements of the owned startup transaction. A client
|
|
20
|
+
* pause (OS scheduling, GC, CPU throttling) counts against it, so it is longer than the statement
|
|
21
|
+
* and lock bounds; it still bounds how long a stalled process can hold the platform permission
|
|
22
|
+
* lock (activation design spec, "Timeouts precede all SQL").
|
|
23
|
+
*/
|
|
24
|
+
export declare const STARTUP_IDLE_IN_TRANSACTION_TIMEOUT_MS = 5000;
|
|
25
|
+
/** Deliberately safe diagnostics: driver errors may contain connection or statement inputs. */
|
|
26
|
+
export declare class StartupActivationError extends Error {
|
|
27
|
+
readonly outcome: "aborted" | "rolled-back" | "uncertain";
|
|
28
|
+
constructor(outcome: "aborted" | "rolled-back" | "uncertain");
|
|
29
|
+
}
|
|
30
|
+
interface StartupGuard {
|
|
31
|
+
check(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function startupActivationGuard(): StartupGuard | undefined;
|
|
34
|
+
/** A one-use owned session. Neither this pool nor its client can reach the shared pool. */
|
|
35
|
+
export declare function runOwnedStartupActivation<T>(fn: (trx: Transaction<any>) => Promise<T>, options: StartupActivationOptions): Promise<T>;
|
|
36
|
+
export {};
|