@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS permission_call_grants (
|
|
2
|
+
id uuid PRIMARY KEY,
|
|
3
|
+
org_id text NOT NULL REFERENCES orgs(id),
|
|
4
|
+
root_conversation_id text NOT NULL REFERENCES conversations(id),
|
|
5
|
+
conversation_id text NOT NULL REFERENCES conversations(id),
|
|
6
|
+
device_id text NOT NULL REFERENCES devices(id),
|
|
7
|
+
account_id text NOT NULL REFERENCES accounts(id),
|
|
8
|
+
run_id text NOT NULL REFERENCES runs(id),
|
|
9
|
+
call_id text NOT NULL,
|
|
10
|
+
tool_key text NOT NULL,
|
|
11
|
+
spec_hash text NOT NULL,
|
|
12
|
+
call_input_hash text NOT NULL,
|
|
13
|
+
resolved_input_hash text NOT NULL,
|
|
14
|
+
profile text NOT NULL CHECK (profile IN ('request-approval', 'approve-for-me', 'full-access')),
|
|
15
|
+
profile_revision integer NOT NULL,
|
|
16
|
+
scope_revision text NOT NULL,
|
|
17
|
+
authority_revision text NOT NULL,
|
|
18
|
+
binding_hash text NOT NULL UNIQUE,
|
|
19
|
+
expansion jsonb NOT NULL,
|
|
20
|
+
expansion_hash text NOT NULL,
|
|
21
|
+
candidate_hash text NOT NULL,
|
|
22
|
+
target_path text,
|
|
23
|
+
scope_kind text NOT NULL CHECK (scope_kind = 'directories-and-hosts'),
|
|
24
|
+
source text NOT NULL CHECK (source IN ('human', 'review-model')),
|
|
25
|
+
approval_id text UNIQUE REFERENCES approvals(id),
|
|
26
|
+
review_event_seq integer,
|
|
27
|
+
decided_by text REFERENCES accounts(id),
|
|
28
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
29
|
+
CHECK ((source = 'human' AND approval_id IS NOT NULL AND decided_by IS NOT NULL AND review_event_seq IS NULL)
|
|
30
|
+
OR (source = 'review-model' AND approval_id IS NULL AND decided_by IS NULL AND review_event_seq IS NOT NULL))
|
|
31
|
+
);
|
|
32
|
+
ALTER TABLE sandbox_operation_intents ADD COLUMN IF NOT EXISTS permission_grant_id uuid REFERENCES permission_call_grants(id);
|
|
33
|
+
ALTER TABLE approvals ADD COLUMN IF NOT EXISTS superseded_revision integer;
|
|
34
|
+
ALTER TABLE approvals ADD COLUMN IF NOT EXISTS superseded_reason text;
|
|
35
|
+
ALTER TABLE approvals DROP CONSTRAINT IF EXISTS approvals_status_check;
|
|
36
|
+
ALTER TABLE approvals ADD CONSTRAINT approvals_status_check CHECK (status IN ('pending', 'approved', 'denied', 'expired', 'cancelled', 'skipped', 'superseded'));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Preserve exact starting grants for consumed retries; null historical rows remain unavailable.
|
|
2
|
+
ALTER TABLE sandbox_operation_intents ADD COLUMN IF NOT EXISTS execution_grants jsonb;
|
|
3
|
+
ALTER TABLE sandbox_operation_intents DROP CONSTRAINT IF EXISTS sandbox_operation_intents_method_check;
|
|
4
|
+
ALTER TABLE sandbox_operation_intents ADD CONSTRAINT sandbox_operation_intents_method_check
|
|
5
|
+
CHECK (method IN ('exec','backgroundStart','readFile','writeFile','stat','list','scan'));
|
|
6
|
+
ALTER TABLE sandbox_operation_intents DROP CONSTRAINT IF EXISTS sandbox_operation_intents_execution_grants_check;
|
|
7
|
+
ALTER TABLE sandbox_operation_intents ADD CONSTRAINT sandbox_operation_intents_execution_grants_check
|
|
8
|
+
CHECK (execution_grants IS NULL OR (method IN ('exec','backgroundStart') AND jsonb_typeof(execution_grants) = 'object'));
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
-- Durable launch identity for managed background tasks (permission runtime cutover phase 8.2).
|
|
2
|
+
-- An acknowledged backgroundStart keeps its intent as live running authority
|
|
3
|
+
-- ('background-running') with the exact typed execution reference; foreground completion never
|
|
4
|
+
-- retires it. Legacy SID rows keep launch_state 'legacy' and are never converted.
|
|
5
|
+
ALTER TABLE sandbox_operation_intents ADD COLUMN IF NOT EXISTS execution_ref jsonb;
|
|
6
|
+
ALTER TABLE sandbox_operation_intents DROP CONSTRAINT IF EXISTS sandbox_operation_intents_state_check;
|
|
7
|
+
ALTER TABLE sandbox_operation_intents ADD CONSTRAINT sandbox_operation_intents_state_check
|
|
8
|
+
CHECK (state IN ('pending','admitted','dispatching','started-or-unknown','background-running','completed','revoked'));
|
|
9
|
+
ALTER TABLE sandbox_operation_intents DROP CONSTRAINT IF EXISTS sandbox_operation_intents_execution_ref_check;
|
|
10
|
+
ALTER TABLE sandbox_operation_intents ADD CONSTRAINT sandbox_operation_intents_execution_ref_check
|
|
11
|
+
CHECK (
|
|
12
|
+
(execution_ref IS NULL OR (method = 'backgroundStart' AND jsonb_typeof(execution_ref) = 'object'))
|
|
13
|
+
AND (state <> 'background-running' OR (method = 'backgroundStart' AND execution_ref IS NOT NULL))
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- The launch reservation of a managed task, persisted before dispatch. pending: pre-effect;
|
|
17
|
+
-- dispatched: dispatched or consumed with an unknown outcome (a null ref is no proof of no
|
|
18
|
+
-- launch); acknowledged: exact ref recorded; cancel-pending: cancellation owed for a launched or
|
|
19
|
+
-- possibly launched task; terminal: settled.
|
|
20
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS launch_state text NOT NULL DEFAULT 'legacy';
|
|
21
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS operation_id text;
|
|
22
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS input_digest text;
|
|
23
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS run_execution_id text;
|
|
24
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS task_tag text;
|
|
25
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS instance_id text;
|
|
26
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS instance_provider text;
|
|
27
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS instance_provider_version text;
|
|
28
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS instance_generation text;
|
|
29
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS profile_revision integer;
|
|
30
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS ceiling_revision text;
|
|
31
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS permission_grant_id text;
|
|
32
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS network_authority jsonb;
|
|
33
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS working_root text;
|
|
34
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS retain_until timestamptz;
|
|
35
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS execution_ref jsonb;
|
|
36
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS cancel_requested_at timestamptz;
|
|
37
|
+
ALTER TABLE background_tasks DROP CONSTRAINT IF EXISTS background_tasks_launch_state_check;
|
|
38
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_launch_state_check
|
|
39
|
+
CHECK (launch_state IN ('legacy','pending','dispatched','acknowledged','cancel-pending','terminal'));
|
|
40
|
+
ALTER TABLE background_tasks DROP CONSTRAINT IF EXISTS background_tasks_managed_reservation_check;
|
|
41
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_managed_reservation_check
|
|
42
|
+
CHECK (
|
|
43
|
+
launch_state = 'legacy'
|
|
44
|
+
OR (operation_id IS NOT NULL AND working_root IS NOT NULL AND retain_until IS NOT NULL
|
|
45
|
+
AND left(output_path, 1) = '/')
|
|
46
|
+
);
|
|
47
|
+
ALTER TABLE background_tasks DROP CONSTRAINT IF EXISTS background_tasks_managed_dispatch_check;
|
|
48
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_managed_dispatch_check
|
|
49
|
+
CHECK (
|
|
50
|
+
launch_state IN ('legacy','pending','terminal')
|
|
51
|
+
OR (input_digest IS NOT NULL AND run_execution_id IS NOT NULL AND task_tag IS NOT NULL
|
|
52
|
+
AND instance_id IS NOT NULL AND instance_provider IS NOT NULL
|
|
53
|
+
AND instance_provider_version IS NOT NULL AND instance_generation IS NOT NULL
|
|
54
|
+
AND profile_revision IS NOT NULL AND ceiling_revision IS NOT NULL)
|
|
55
|
+
);
|
|
56
|
+
ALTER TABLE background_tasks DROP CONSTRAINT IF EXISTS background_tasks_execution_ref_check;
|
|
57
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_execution_ref_check
|
|
58
|
+
CHECK (
|
|
59
|
+
(execution_ref IS NULL OR (launch_state IN ('acknowledged','cancel-pending','terminal')
|
|
60
|
+
AND jsonb_typeof(execution_ref) = 'object'))
|
|
61
|
+
AND (launch_state <> 'acknowledged' OR execution_ref IS NOT NULL)
|
|
62
|
+
);
|
|
63
|
+
CREATE UNIQUE INDEX IF NOT EXISTS background_tasks_operation_idx
|
|
64
|
+
ON background_tasks (operation_id) WHERE operation_id IS NOT NULL;
|
|
65
|
+
CREATE UNIQUE INDEX IF NOT EXISTS background_tasks_managed_call_idx
|
|
66
|
+
ON background_tasks (run_id, call_id) WHERE launch_state <> 'legacy';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- Who asked for a managed task's cancellation (permission runtime cutover phase 8.3). A stop that
|
|
2
|
+
-- cannot settle at once (no exact ref yet, or the provider persisted a pending cancellation) is
|
|
3
|
+
-- finished later by another path; that finish must keep the requester's wake rule: a person's,
|
|
4
|
+
-- a deletion's or an ended sub-agent's stop never wakes the conversation, a tool's or a revocation's
|
|
5
|
+
-- may. NULL: no stop asked (a revocation's cancellation, or none).
|
|
6
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS cancel_requested_by text;
|
|
7
|
+
ALTER TABLE background_tasks DROP CONSTRAINT IF EXISTS background_tasks_cancel_requested_by_check;
|
|
8
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_cancel_requested_by_check
|
|
9
|
+
CHECK (cancel_requested_by IS NULL
|
|
10
|
+
OR cancel_requested_by IN ('tool','person','conversation_deleted','subagent_end'));
|
|
11
|
+
-- When an exact stop of the task was last attempted: owed cancellations are applied least
|
|
12
|
+
-- recently attempted first, so one that keeps failing never holds the head of the queue.
|
|
13
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS cancel_attempted_at timestamptz;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- The cloud per-device authority of permission runtime cutover B1 (expand only). A cloud
|
|
2
|
+
-- device's owner ceiling (`owner_full_access`) and its outer network (`outer_network`, `{ kind:
|
|
3
|
+
-- "open-public" | "allowlist", hosts }`) are a snapshot of the old effective auto-mode authority,
|
|
4
|
+
-- written once per device by the snapshot writer under the device's exclusive lifecycle lease;
|
|
5
|
+
-- NULL: not snapshotted yet (the old `mode` choice still applies). `permission_migration` records
|
|
6
|
+
-- the provenance (the old effective policy and what was known of the instance). A device whose
|
|
7
|
+
-- applied limits were unknown, stale, wider or pending a reset carries
|
|
8
|
+
-- `permission_reconcile_required`: no operation is admitted until a lifecycle action establishes
|
|
9
|
+
-- the exact limits.
|
|
10
|
+
ALTER TABLE devices ADD COLUMN IF NOT EXISTS owner_full_access boolean;
|
|
11
|
+
ALTER TABLE devices ADD COLUMN IF NOT EXISTS outer_network jsonb;
|
|
12
|
+
ALTER TABLE devices ADD COLUMN IF NOT EXISTS permission_migration jsonb;
|
|
13
|
+
ALTER TABLE devices ADD COLUMN IF NOT EXISTS permission_reconcile_required boolean NOT NULL
|
|
14
|
+
DEFAULT false;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Instance generation identity (permission runtime cutover B4). A device instance's generation is
|
|
2
|
+
-- the exact epoch millisecond of device_instances.created_at; operation refs, journals and spools
|
|
3
|
+
-- carry it. The high-water mark lives apart from device_instances (no foreign key to it or to
|
|
4
|
+
-- devices), so a deleted, reset or rebuilt instance row, a database clock that moved back, or two
|
|
5
|
+
-- creates within one millisecond can never hand out a generation already used for the device.
|
|
6
|
+
CREATE TABLE IF NOT EXISTS device_generation_high_water (
|
|
7
|
+
device_id uuid PRIMARY KEY,
|
|
8
|
+
high_water_ms bigint NOT NULL CHECK (high_water_ms >= 0),
|
|
9
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- The post-commit binding of a local instance generation: committed with the instance row as
|
|
13
|
+
-- 'awaiting-device'; 'installed' only after the authenticated device's bindInstance answer was
|
|
14
|
+
-- verified. A record outlives its instance row (no foreign key), so an old generation and its
|
|
15
|
+
-- binding id are never reused or adopted by a replacement.
|
|
16
|
+
CREATE TABLE IF NOT EXISTS device_instance_bindings (
|
|
17
|
+
device_id uuid NOT NULL,
|
|
18
|
+
instance_generation text NOT NULL CHECK (instance_generation ~ '^[0-9]{1,16}$'),
|
|
19
|
+
binding_id uuid NOT NULL UNIQUE,
|
|
20
|
+
provider text NOT NULL,
|
|
21
|
+
previous_generation text CHECK (previous_generation IS NULL
|
|
22
|
+
OR previous_generation ~ '^[0-9]{1,16}$'),
|
|
23
|
+
status text NOT NULL CHECK (status IN ('awaiting-device', 'installed')),
|
|
24
|
+
machine_id uuid,
|
|
25
|
+
-- the verified runtime identity the device answered with; a later report must match it
|
|
26
|
+
runtime_identity jsonb,
|
|
27
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
28
|
+
installed_at timestamptz,
|
|
29
|
+
PRIMARY KEY (device_id, instance_generation)
|
|
30
|
+
);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- The authenticated owner report of a local machine (permission runtime cutover B2): the strict
|
|
2
|
+
-- `{version: 2, revision, sequence, fullAccess, restrictedProjectReach, restrictedAllowedDomains}`
|
|
3
|
+
-- its program issued, with the connection it arrived on, when, and through which message; a
|
|
4
|
+
-- report that arrived out of order (a lower sequence, or the same sequence with other bytes)
|
|
5
|
+
-- marks it `blocked` (no new authority until a valid current report). Per machine row: a new
|
|
6
|
+
-- machine credential never adopts an old machine's sequence. NULL: no report yet (protocol 2).
|
|
7
|
+
ALTER TABLE device_machines ADD COLUMN IF NOT EXISTS owner_report jsonb;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
-- Legacy retirement and the fail-closed reuse barrier (permission runtime cutover phase 8.5).
|
|
2
|
+
|
|
3
|
+
-- The durable legacy-launch freeze: one row, written once under the platform authority writer
|
|
4
|
+
-- (the exclusive platform permission lock). A legacy SID launch checks it under the shared
|
|
5
|
+
-- platform lock immediately before its dispatch, so once the row is committed no replica running
|
|
6
|
+
-- this code can start another legacy task. It is never removed.
|
|
7
|
+
CREATE TABLE IF NOT EXISTS legacy_launch_freeze (
|
|
8
|
+
id text PRIMARY KEY CHECK (id = 'platform'),
|
|
9
|
+
frozen_at timestamptz NOT NULL DEFAULT now(),
|
|
10
|
+
frozen_by text NOT NULL CHECK (length(frozen_by) BETWEEN 1 AND 200)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
-- Whether a legacy launch may have dispatched its command. 'unknown': a row written by a replica
|
|
14
|
+
-- without this marker (every row before this migration, and any row of an old replica): it may
|
|
15
|
+
-- have dispatched. 'reserved': reserved by this code and not admitted for dispatch (yet).
|
|
16
|
+
-- 'dispatched': admitted by the freeze check; its command may run. The default stays 'unknown',
|
|
17
|
+
-- so a row inserted by an old, unfenced replica never reads as never dispatched.
|
|
18
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS legacy_dispatch text NOT NULL DEFAULT 'unknown';
|
|
19
|
+
ALTER TABLE background_tasks DROP CONSTRAINT IF EXISTS background_tasks_legacy_dispatch_check;
|
|
20
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_legacy_dispatch_check
|
|
21
|
+
CHECK (legacy_dispatch IN ('unknown', 'reserved', 'dispatched'));
|
|
22
|
+
-- The exact incarnation a dispatch was admitted for (provider and generation, read under the
|
|
23
|
+
-- launch's shared lease): a reservation that never got its sid still names where it may run. NULL
|
|
24
|
+
-- on historical rows: their incarnation is `unknown`, never guessed from the current instance.
|
|
25
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS legacy_dispatch_provider text;
|
|
26
|
+
ALTER TABLE background_tasks ADD COLUMN IF NOT EXISTS legacy_dispatch_generation text;
|
|
27
|
+
ALTER TABLE background_tasks DROP CONSTRAINT IF EXISTS background_tasks_legacy_dispatch_generation_check;
|
|
28
|
+
ALTER TABLE background_tasks ADD CONSTRAINT background_tasks_legacy_dispatch_generation_check
|
|
29
|
+
CHECK (legacy_dispatch_generation IS NULL OR legacy_dispatch_generation ~ '^[0-9]{1,16}$');
|
|
30
|
+
|
|
31
|
+
-- The physical no-reuse obligation of one old instance incarnation: the device, its provider and
|
|
32
|
+
-- the exact instance generation (the epoch millisecond of device_instances.created_at; 'unknown'
|
|
33
|
+
-- when a possibly dispatched legacy launch names no instance). No foreign key: it outlives the
|
|
34
|
+
-- task rows, the instance row and output retention. 'open': not yet retired; 'quarantined': no
|
|
35
|
+
-- trusted way to establish termination exists (a local machine, a replaced or unknown
|
|
36
|
+
-- incarnation without recorded destruction): the device stays unavailable; 'resolved': the
|
|
37
|
+
-- provider confirmed the incarnation destroyed. A quarantined device is not retired.
|
|
38
|
+
-- 'abandoned': the device was deleted while the obligation was unresolved; no device can reuse the
|
|
39
|
+
-- incarnation (device ids are never reused), but it is no evidence that its processes ended.
|
|
40
|
+
CREATE TABLE IF NOT EXISTS device_retirement_obligations (
|
|
41
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
42
|
+
device_id text NOT NULL,
|
|
43
|
+
org_id text NOT NULL,
|
|
44
|
+
provider text NOT NULL CHECK (length(provider) BETWEEN 1 AND 200),
|
|
45
|
+
instance_generation text NOT NULL
|
|
46
|
+
CHECK (instance_generation = 'unknown' OR instance_generation ~ '^[0-9]{1,16}$'),
|
|
47
|
+
state text NOT NULL DEFAULT 'open'
|
|
48
|
+
CHECK (state IN ('open', 'quarantined', 'resolved', 'abandoned')),
|
|
49
|
+
resolution text CHECK (resolution IS NULL OR resolution IN ('provider-destroyed', 'host-rebooted')),
|
|
50
|
+
-- a local incarnation: the machine and its OS boot identity current when the obligation was
|
|
51
|
+
-- recorded; NULL boot_id (none reported) never resolves by itself
|
|
52
|
+
boot_machine_id uuid,
|
|
53
|
+
boot_id text,
|
|
54
|
+
reason text,
|
|
55
|
+
attempts integer NOT NULL DEFAULT 0 CHECK (attempts >= 0),
|
|
56
|
+
last_attempt_at timestamptz,
|
|
57
|
+
last_error text,
|
|
58
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
59
|
+
resolved_at timestamptz,
|
|
60
|
+
abandoned_at timestamptz,
|
|
61
|
+
CHECK ((state = 'abandoned') = (abandoned_at IS NOT NULL)),
|
|
62
|
+
CHECK ((state = 'resolved') = (resolution IS NOT NULL AND resolved_at IS NOT NULL)),
|
|
63
|
+
UNIQUE (device_id, provider, instance_generation)
|
|
64
|
+
);
|
|
65
|
+
CREATE INDEX IF NOT EXISTS device_retirement_obligations_unresolved_idx
|
|
66
|
+
ON device_retirement_obligations (device_id) WHERE state IN ('open', 'quarantined');
|
|
67
|
+
|
|
68
|
+
-- What put an obligation there: a legacy task row (by task id) or a revoked managed background
|
|
69
|
+
-- start whose recorded generation no longer runs (by operation id). Kept apart from the task and
|
|
70
|
+
-- intent rows; `settled`: the member's own record was settled after the obligation resolved
|
|
71
|
+
-- (the intent's revocation acknowledged, the task's owed cancellation settled).
|
|
72
|
+
CREATE TABLE IF NOT EXISTS device_retirement_members (
|
|
73
|
+
obligation_id uuid NOT NULL REFERENCES device_retirement_obligations(id) ON DELETE RESTRICT,
|
|
74
|
+
kind text NOT NULL CHECK (kind IN ('legacy-task', 'revoked-start')),
|
|
75
|
+
ref_id text NOT NULL,
|
|
76
|
+
settled boolean NOT NULL DEFAULT false,
|
|
77
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
78
|
+
PRIMARY KEY (kind, ref_id, obligation_id)
|
|
79
|
+
);
|
|
80
|
+
CREATE INDEX IF NOT EXISTS device_retirement_members_obligation_idx
|
|
81
|
+
ON device_retirement_members (obligation_id);
|
|
82
|
+
|
|
83
|
+
-- Provider-confirmed destruction of a cloud instance incarnation, recorded by the kernel's own
|
|
84
|
+
-- whole-instance destroy when the provider's destroy resolved. A local destroy is a no-op and is
|
|
85
|
+
-- never recorded. No foreign key: it outlives the instance row.
|
|
86
|
+
CREATE TABLE IF NOT EXISTS device_instance_destructions (
|
|
87
|
+
device_id text NOT NULL,
|
|
88
|
+
provider text NOT NULL,
|
|
89
|
+
instance_generation text NOT NULL CHECK (instance_generation ~ '^[0-9]{1,16}$'),
|
|
90
|
+
destroyed_at timestamptz NOT NULL DEFAULT now(),
|
|
91
|
+
PRIMARY KEY (device_id, provider, instance_generation)
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
-- The worker's enumeration runs every tick: only the rows it may select are indexed.
|
|
95
|
+
CREATE INDEX IF NOT EXISTS background_tasks_legacy_retirement_idx
|
|
96
|
+
ON background_tasks (device_id)
|
|
97
|
+
WHERE launch_state = 'legacy' AND device_id IS NOT NULL
|
|
98
|
+
AND (status = 'running' OR kill_pending OR sid IS NULL);
|
|
99
|
+
CREATE INDEX IF NOT EXISTS sandbox_operation_intents_owed_background_revoke_idx
|
|
100
|
+
ON sandbox_operation_intents (device_id)
|
|
101
|
+
WHERE method = 'backgroundStart' AND state = 'revoked' AND NOT revoke_acknowledged
|
|
102
|
+
AND execution_ref IS NOT NULL;
|
|
103
|
+
|
|
104
|
+
-- The OS boot identities a machine reported in its authenticated hellos, in the order first seen.
|
|
105
|
+
-- A later boot of the same machine proves the host restarted since an earlier one, so no process of
|
|
106
|
+
-- the earlier boot can exist (a local legacy obligation resolves). A boot reported again after a
|
|
107
|
+
-- later one (a stale or replayed report) is ignored. Kept with the machine row.
|
|
108
|
+
CREATE TABLE IF NOT EXISTS device_machine_boots (
|
|
109
|
+
machine_id uuid NOT NULL REFERENCES device_machines(id) ON DELETE CASCADE,
|
|
110
|
+
boot_id text NOT NULL CHECK (boot_id ~ '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$'),
|
|
111
|
+
seq bigserial NOT NULL,
|
|
112
|
+
first_seen_at timestamptz NOT NULL DEFAULT now(),
|
|
113
|
+
PRIMARY KEY (machine_id, boot_id)
|
|
114
|
+
);
|
|
115
|
+
-- the machine's current boot: the latest first seen
|
|
116
|
+
ALTER TABLE device_machines ADD COLUMN IF NOT EXISTS boot_id text;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- When the legacy-launch freeze's own enumeration last completed with a stable pass (permission
|
|
2
|
+
-- runtime cutover B-26). NULL: the freeze was published but its enumeration never finished (a
|
|
3
|
+
-- crash, or an old unfenced replica kept writing legacy rows); the cloud snapshot driver refuses
|
|
4
|
+
-- until `capybara permissions cutover freeze` is run again and settles.
|
|
5
|
+
ALTER TABLE legacy_launch_freeze ADD COLUMN IF NOT EXISTS enumerated_at timestamptz;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- A retirement obligation whose members are all revoked managed starts on a suspended cloud
|
|
2
|
+
-- incarnation resolves without destroying that incarnation once its provider confirms the exact
|
|
3
|
+
-- cancellation of every revoked ref after a resume (permission activation B-22): the resolution
|
|
4
|
+
-- `exact-cancelled`. Widens the allowed values only; every existing row stays valid.
|
|
5
|
+
ALTER TABLE device_retirement_obligations
|
|
6
|
+
DROP CONSTRAINT IF EXISTS device_retirement_obligations_resolution_check;
|
|
7
|
+
ALTER TABLE device_retirement_obligations
|
|
8
|
+
ADD CONSTRAINT device_retirement_obligations_resolution_check
|
|
9
|
+
CHECK (resolution IS NULL OR resolution IN ('provider-destroyed', 'host-rebooted', 'exact-cancelled'));
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
|
-
import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
4
|
-
import type { KernelLogger } from "../log.js";
|
|
5
|
-
/**
|
|
6
|
-
* The platform's auto-mode switch (auto mode spec §4.3, P-D9): whether a device may run in auto
|
|
7
|
-
* mode. It is both a startup config field (`devices.autoMode`) and a deployment setting
|
|
8
|
-
* ({@link DEVICES_AUTO_MODE_SETTING}), read live at every use: environment > config file / Nacos >
|
|
9
|
-
* the super admin's choice in the admin console > {@link DEVICES_AUTO_MODE_DEFAULT}. A field set in
|
|
10
|
-
* the startup config is read-only in the admin console. An invalid stored value reads as `off` with
|
|
11
|
-
* a warning (fail closed): a mode nobody could set must never widen a device.
|
|
12
|
-
*/
|
|
13
|
-
export type DevicesAutoMode = "allowed" | "off";
|
|
14
|
-
/** The `deployment_settings` key of the super admin's choice. */
|
|
15
|
-
export declare const DEVICES_AUTO_MODE_SETTING = "devicesAutoMode";
|
|
16
|
-
/** What a deployment with neither the startup config nor the stored choice says: auto allowed. */
|
|
17
|
-
export declare const DEVICES_AUTO_MODE_DEFAULT: DevicesAutoMode;
|
|
18
|
-
/** The stored choice: `mode` absent follows the default. */
|
|
19
|
-
export declare const DevicesAutoModeStoredSchema: z.ZodObject<{
|
|
20
|
-
mode: z.ZodOptional<z.ZodEnum<{
|
|
21
|
-
allowed: "allowed";
|
|
22
|
-
off: "off";
|
|
23
|
-
}>>;
|
|
24
|
-
}, z.core.$strict>;
|
|
25
|
-
export type DevicesAutoModeStored = z.infer<typeof DevicesAutoModeStoredSchema>;
|
|
26
|
-
/**
|
|
27
|
-
* A change of the stored choice (`PUT /api/v1/admin/settings` `devicesAutoMode`): `mode: null`
|
|
28
|
-
* clears it, back to {@link DEVICES_AUTO_MODE_DEFAULT}.
|
|
29
|
-
*/
|
|
30
|
-
export declare const DEVICES_AUTO_MODE_PATCH: z.ZodObject<{
|
|
31
|
-
mode: z.ZodNullable<z.ZodEnum<{
|
|
32
|
-
allowed: "allowed";
|
|
33
|
-
off: "off";
|
|
34
|
-
}>>;
|
|
35
|
-
}, z.core.$strict>;
|
|
36
|
-
export type DevicesAutoModePatch = z.infer<typeof DEVICES_AUTO_MODE_PATCH>;
|
|
37
|
-
/** Where the effective switch comes from. */
|
|
38
|
-
export type DevicesAutoModeSource = "env" | "file" | "nacos" | "db" | "default";
|
|
39
|
-
/** The admin console's view: the effective mode and where it comes from. */
|
|
40
|
-
export interface DevicesAutoModeView {
|
|
41
|
-
mode: DevicesAutoMode;
|
|
42
|
-
source: DevicesAutoModeSource;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Parses the stored choice: missing -> `{}`; invalid -> `{ mode: "off" }` with a warning, narrower,
|
|
46
|
-
* never wider (the safe direction: auto mode off means sandbox mode).
|
|
47
|
-
*/
|
|
48
|
-
export declare function parseStoredDevicesAutoMode(value: unknown, log?: Pick<KernelLogger, "warn">): DevicesAutoModeStored;
|
|
49
|
-
/** The stored choice with `patch` applied (`mode: null` clears it). */
|
|
50
|
-
export declare function applyDevicesAutoModePatch(_stored: DevicesAutoModeStored, patch: DevicesAutoModePatch): DevicesAutoModeStored;
|
|
51
|
-
/**
|
|
52
|
-
* The effective switch and its source, pure (the reader below adds the database read). The startup
|
|
53
|
-
* config field is optional and has no schema default, so `configMode !== undefined` means the
|
|
54
|
-
* config source (environment, file or Nacos) sets it: it wins over the stored choice.
|
|
55
|
-
*/
|
|
56
|
-
export declare function resolveDevicesAutoMode(configMode: DevicesAutoMode | undefined, configSource: Exclude<DevicesAutoModeSource, "db" | "default"> | undefined, stored: DevicesAutoModeStored): DevicesAutoModeView;
|
|
57
|
-
/** The stored choice, read live (in the caller's transaction when there is one). */
|
|
58
|
-
export declare function readStoredDevicesAutoMode(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">): Promise<DevicesAutoModeStored>;
|
|
59
|
-
/**
|
|
60
|
-
* The platform's effective auto-mode switch, read live from PG at every use (so a change applies on
|
|
61
|
-
* every replica at once): see {@link resolveDevicesAutoMode}.
|
|
62
|
-
*/
|
|
63
|
-
export declare function readDevicesAutoMode(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">, log?: Pick<KernelLogger, "warn">): Promise<DevicesAutoModeView>;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/** The `deployment_settings` key of the super admin's choice. */
|
|
3
|
-
export const DEVICES_AUTO_MODE_SETTING = "devicesAutoMode";
|
|
4
|
-
/** What a deployment with neither the startup config nor the stored choice says: auto allowed. */
|
|
5
|
-
export const DEVICES_AUTO_MODE_DEFAULT = "allowed";
|
|
6
|
-
/** The stored choice: `mode` absent follows the default. */
|
|
7
|
-
export const DevicesAutoModeStoredSchema = z
|
|
8
|
-
.object({ mode: z.enum(["allowed", "off"]).optional() })
|
|
9
|
-
.strict();
|
|
10
|
-
/**
|
|
11
|
-
* A change of the stored choice (`PUT /api/v1/admin/settings` `devicesAutoMode`): `mode: null`
|
|
12
|
-
* clears it, back to {@link DEVICES_AUTO_MODE_DEFAULT}.
|
|
13
|
-
*/
|
|
14
|
-
export const DEVICES_AUTO_MODE_PATCH = z
|
|
15
|
-
.object({ mode: z.enum(["allowed", "off"]).nullable() })
|
|
16
|
-
.strict();
|
|
17
|
-
/**
|
|
18
|
-
* Parses the stored choice: missing -> `{}`; invalid -> `{ mode: "off" }` with a warning, narrower,
|
|
19
|
-
* never wider (the safe direction: auto mode off means sandbox mode).
|
|
20
|
-
*/
|
|
21
|
-
export function parseStoredDevicesAutoMode(value, log) {
|
|
22
|
-
if (value === undefined)
|
|
23
|
-
return {};
|
|
24
|
-
const parsed = DevicesAutoModeStoredSchema.safeParse(value);
|
|
25
|
-
if (parsed.success)
|
|
26
|
-
return parsed.data;
|
|
27
|
-
log?.warn("invalid deployment setting; it reads as mode off", { key: DEVICES_AUTO_MODE_SETTING });
|
|
28
|
-
return { mode: "off" };
|
|
29
|
-
}
|
|
30
|
-
/** The stored choice with `patch` applied (`mode: null` clears it). */
|
|
31
|
-
export function applyDevicesAutoModePatch(_stored, patch) {
|
|
32
|
-
return patch.mode === null ? {} : { mode: patch.mode };
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The effective switch and its source, pure (the reader below adds the database read). The startup
|
|
36
|
-
* config field is optional and has no schema default, so `configMode !== undefined` means the
|
|
37
|
-
* config source (environment, file or Nacos) sets it: it wins over the stored choice.
|
|
38
|
-
*/
|
|
39
|
-
export function resolveDevicesAutoMode(configMode, configSource, stored) {
|
|
40
|
-
if (configMode !== undefined && configSource !== undefined) {
|
|
41
|
-
return { mode: configMode, source: configSource };
|
|
42
|
-
}
|
|
43
|
-
if (stored.mode !== undefined)
|
|
44
|
-
return { mode: stored.mode, source: "db" };
|
|
45
|
-
return { mode: DEVICES_AUTO_MODE_DEFAULT, source: "default" };
|
|
46
|
-
}
|
|
47
|
-
/** The stored choice, read live (in the caller's transaction when there is one). */
|
|
48
|
-
export async function readStoredDevicesAutoMode(db, log) {
|
|
49
|
-
const row = await db
|
|
50
|
-
.selectFrom("deployment_settings")
|
|
51
|
-
.select("value")
|
|
52
|
-
.where("key", "=", DEVICES_AUTO_MODE_SETTING)
|
|
53
|
-
.executeTakeFirst();
|
|
54
|
-
return parseStoredDevicesAutoMode(row?.value, log);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The platform's effective auto-mode switch, read live from PG at every use (so a change applies on
|
|
58
|
-
* every replica at once): see {@link resolveDevicesAutoMode}.
|
|
59
|
-
*/
|
|
60
|
-
export async function readDevicesAutoMode(db, config, log) {
|
|
61
|
-
const stored = await readStoredDevicesAutoMode(db, log);
|
|
62
|
-
return resolveDevicesAutoMode(config.get().devices.autoMode, config.fieldSource("devices.autoMode"), stored);
|
|
63
|
-
}
|