@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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
3
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
4
|
+
import { type OwnerReportVia } from "./owner-report.js";
|
|
5
|
+
/** What became of an arrived owner report. */
|
|
6
|
+
export type OwnerReportOutcome = "recorded" | "same" | "stale" | "conflict" | "revoked";
|
|
7
|
+
/**
|
|
8
|
+
* The single writer of authenticated owner reports (permission runtime cutover B2). Every carrier
|
|
9
|
+
* (v3 hello, `policy` frame, policy answer or applied status, bind answer) enters here under the
|
|
10
|
+
* device authority writer, for the machine the authenticated connection belongs to: a caller never
|
|
11
|
+
* names another device. A higher sequence is recorded and publishes the changed effective facts
|
|
12
|
+
* through the common ceiling writer: Full consent resets only when the owner's Full permission
|
|
13
|
+
* (or the machine's roots) actually changed; restricted-only changes revoke only the restricted
|
|
14
|
+
* work they narrow. The same report again only refreshes when it was seen; a stale or conflicting
|
|
15
|
+
* one blocks new authority until a valid current report arrives.
|
|
16
|
+
*/
|
|
17
|
+
export declare class OwnerReports {
|
|
18
|
+
private readonly db;
|
|
19
|
+
readonly txHost: TransactionHost;
|
|
20
|
+
private readonly ceilings;
|
|
21
|
+
constructor(db: KernelDb, txHost: TransactionHost, ceilings: PermissionCeilingWrites);
|
|
22
|
+
/** {@link recordLocked} in its own transaction, taking the device authority writer. */
|
|
23
|
+
record(machineId: string, report: unknown, meta: {
|
|
24
|
+
connectionId: string | null;
|
|
25
|
+
via: OwnerReportVia;
|
|
26
|
+
}): Promise<OwnerReportOutcome>;
|
|
27
|
+
/**
|
|
28
|
+
* Records one report for `machineId` (the caller holds the device authority writer and has
|
|
29
|
+
* validated the connection). `rootsChanged`: the same message also changed the machine's roots,
|
|
30
|
+
* which already resets Full consent and revokes everything (folded into one publication).
|
|
31
|
+
*/
|
|
32
|
+
recordLocked(machineId: string, raw: unknown, meta: {
|
|
33
|
+
connectionId: string | null;
|
|
34
|
+
via: OwnerReportVia;
|
|
35
|
+
rootsChanged?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The platform op whose answer carries this report: the change is audited as its source
|
|
38
|
+
* made it (the person, via the web or an approval), once, instead of as the machine's own.
|
|
39
|
+
*/
|
|
40
|
+
explainedBy?: {
|
|
41
|
+
accountId: string;
|
|
42
|
+
via: string;
|
|
43
|
+
opId: string;
|
|
44
|
+
actorTokenId?: string;
|
|
45
|
+
};
|
|
46
|
+
}): Promise<OwnerReportOutcome>;
|
|
47
|
+
private write;
|
|
48
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { parseOwnerCeilingReportV3 } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
+
import { audit } from "../identity/audit.js";
|
|
13
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
15
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
16
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
17
|
+
import { decideOwnerReport, machineRootList, ownerFactsOf, ownerFactsOfReport, ownerReportRevokes, storedOwnerReportOf, } from "./owner-report.js";
|
|
18
|
+
import { opExplainsOwnerChange, pendingPolicyOpsOf } from "./policy-summary.js";
|
|
19
|
+
/**
|
|
20
|
+
* The single writer of authenticated owner reports (permission runtime cutover B2). Every carrier
|
|
21
|
+
* (v3 hello, `policy` frame, policy answer or applied status, bind answer) enters here under the
|
|
22
|
+
* device authority writer, for the machine the authenticated connection belongs to: a caller never
|
|
23
|
+
* names another device. A higher sequence is recorded and publishes the changed effective facts
|
|
24
|
+
* through the common ceiling writer: Full consent resets only when the owner's Full permission
|
|
25
|
+
* (or the machine's roots) actually changed; restricted-only changes revoke only the restricted
|
|
26
|
+
* work they narrow. The same report again only refreshes when it was seen; a stale or conflicting
|
|
27
|
+
* one blocks new authority until a valid current report arrives.
|
|
28
|
+
*/
|
|
29
|
+
let OwnerReports = class OwnerReports {
|
|
30
|
+
db;
|
|
31
|
+
txHost;
|
|
32
|
+
ceilings;
|
|
33
|
+
constructor(db, txHost, ceilings) {
|
|
34
|
+
this.db = db;
|
|
35
|
+
this.txHost = txHost;
|
|
36
|
+
this.ceilings = ceilings;
|
|
37
|
+
}
|
|
38
|
+
/** {@link recordLocked} in its own transaction, taking the device authority writer. */
|
|
39
|
+
async record(machineId, report, meta) {
|
|
40
|
+
const subject = await this.db
|
|
41
|
+
.selectFrom("device_machines")
|
|
42
|
+
.select(["org_id", "device_id"])
|
|
43
|
+
.where("id", "=", machineId)
|
|
44
|
+
.where("revoked_at", "is", null)
|
|
45
|
+
.executeTakeFirst();
|
|
46
|
+
if (!subject)
|
|
47
|
+
return "revoked";
|
|
48
|
+
await this.ceilings.lock({ orgId: subject.org_id, deviceId: subject.device_id }, "device");
|
|
49
|
+
return this.recordLocked(machineId, report, meta);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Records one report for `machineId` (the caller holds the device authority writer and has
|
|
53
|
+
* validated the connection). `rootsChanged`: the same message also changed the machine's roots,
|
|
54
|
+
* which already resets Full consent and revokes everything (folded into one publication).
|
|
55
|
+
*/
|
|
56
|
+
async recordLocked(machineId, raw, meta) {
|
|
57
|
+
const report = parseOwnerCeilingReportV3(raw);
|
|
58
|
+
const row = await this.db
|
|
59
|
+
.selectFrom("device_machines")
|
|
60
|
+
.select([
|
|
61
|
+
"org_id",
|
|
62
|
+
"device_id",
|
|
63
|
+
"account_id",
|
|
64
|
+
"owner_report",
|
|
65
|
+
"local_policy",
|
|
66
|
+
"roots",
|
|
67
|
+
"pending_policy_ops",
|
|
68
|
+
])
|
|
69
|
+
.where("id", "=", machineId)
|
|
70
|
+
.where("revoked_at", "is", null)
|
|
71
|
+
.forUpdate()
|
|
72
|
+
.executeTakeFirst();
|
|
73
|
+
if (!row)
|
|
74
|
+
return "revoked";
|
|
75
|
+
const subject = { orgId: row.org_id, deviceId: row.device_id };
|
|
76
|
+
const stored = storedOwnerReportOf(row.owner_report);
|
|
77
|
+
const decision = decideOwnerReport(stored, report);
|
|
78
|
+
const now = new Date().toISOString();
|
|
79
|
+
if (decision === "stale" && meta.via !== "hello") {
|
|
80
|
+
// a policy frame, answer, status or bind answer committed after a newer report (carriers
|
|
81
|
+
// commit in lock order, not issue order) carries no newer authority: ignored, never blocks
|
|
82
|
+
if (meta.rootsChanged)
|
|
83
|
+
await this.ceilings.publishLocked(subject, "device", true, true);
|
|
84
|
+
return "stale";
|
|
85
|
+
}
|
|
86
|
+
if (decision === "stale" || decision === "conflict") {
|
|
87
|
+
// a hello (it opens the current connection) regressing the sequence, or the same sequence
|
|
88
|
+
// with other bytes: never replaces the authority, blocks new admissions until a valid report
|
|
89
|
+
await this.write(machineId, {
|
|
90
|
+
...stored,
|
|
91
|
+
blocked: { reason: decision, sequence: report.sequence, at: now },
|
|
92
|
+
});
|
|
93
|
+
if (meta.rootsChanged)
|
|
94
|
+
await this.ceilings.publishLocked(subject, "device", true, true);
|
|
95
|
+
return decision;
|
|
96
|
+
}
|
|
97
|
+
if (decision === "same") {
|
|
98
|
+
const { blocked: _cleared, ...kept } = stored;
|
|
99
|
+
await this.write(machineId, { ...kept, connectionId: meta.connectionId, observedAt: now });
|
|
100
|
+
if (meta.rootsChanged)
|
|
101
|
+
await this.ceilings.publishLocked(subject, "device", true, true);
|
|
102
|
+
return "same";
|
|
103
|
+
}
|
|
104
|
+
// the facts the authority last held: a block only fails admission closed, it is not a change
|
|
105
|
+
// of Full or reach (unblocking with the same facts resets nothing and audits nothing)
|
|
106
|
+
const before = stored === null
|
|
107
|
+
? ownerFactsOf(row)
|
|
108
|
+
: ownerFactsOfReport({
|
|
109
|
+
report: stored.report,
|
|
110
|
+
connectionId: stored.connectionId,
|
|
111
|
+
observedAt: stored.observedAt,
|
|
112
|
+
via: stored.via,
|
|
113
|
+
});
|
|
114
|
+
const next = {
|
|
115
|
+
report,
|
|
116
|
+
connectionId: meta.connectionId,
|
|
117
|
+
observedAt: now,
|
|
118
|
+
via: meta.via,
|
|
119
|
+
};
|
|
120
|
+
const after = ownerFactsOfReport(next);
|
|
121
|
+
await this.write(machineId, next);
|
|
122
|
+
const fullChanged = before.fullAccess !== after.fullAccess;
|
|
123
|
+
const reachChanged = before.restrictedProjectReach !== after.restrictedProjectReach;
|
|
124
|
+
const domainsChanged = JSON.stringify([...before.restrictedAllowedDomains].sort()) !==
|
|
125
|
+
JSON.stringify([...after.restrictedAllowedDomains].sort());
|
|
126
|
+
const roots = machineRootList(row.roots);
|
|
127
|
+
// a new revision with the same visible facts is no new authority: nothing is published
|
|
128
|
+
if (fullChanged || reachChanged || domainsChanged || meta.rootsChanged)
|
|
129
|
+
await this.ceilings.publishLocked(subject, "device", (scope, intent) => meta.rootsChanged === true ||
|
|
130
|
+
ownerReportRevokes(after, scope, intent.method, intent.granted_hosts, roots), fullChanged || meta.rootsChanged === true);
|
|
131
|
+
// the op whose change this is: its answer names it, else (the machine's own report of it, a
|
|
132
|
+
// policy frame or a reconnect hello, landing first) a live pending op of the platform's that
|
|
133
|
+
// asked for exactly this narrowing; the answer then finds the same report and audits nothing
|
|
134
|
+
const nowMs = Date.now();
|
|
135
|
+
const pending = meta.explainedBy === undefined
|
|
136
|
+
? pendingPolicyOpsOf(row.pending_policy_ops).find((op) => op.until > nowMs && opExplainsOwnerChange(op, before, after))
|
|
137
|
+
: undefined;
|
|
138
|
+
const by = meta.explainedBy ??
|
|
139
|
+
(pending && {
|
|
140
|
+
accountId: pending.source.accountId,
|
|
141
|
+
via: pending.source.via,
|
|
142
|
+
opId: pending.id,
|
|
143
|
+
...(pending.actorTokenId !== undefined && { actorTokenId: pending.actorTokenId }),
|
|
144
|
+
});
|
|
145
|
+
if (before.state !== "missing" && (fullChanged || reachChanged))
|
|
146
|
+
await audit(this.db.db, {
|
|
147
|
+
actorAccountId: by?.accountId ?? row.account_id,
|
|
148
|
+
...(by?.actorTokenId !== undefined && { actorTokenId: by.actorTokenId }),
|
|
149
|
+
orgId: row.org_id,
|
|
150
|
+
action: "device.owner_ceiling_changed",
|
|
151
|
+
target: row.device_id,
|
|
152
|
+
detail: {
|
|
153
|
+
from: {
|
|
154
|
+
fullAccess: before.fullAccess,
|
|
155
|
+
restrictedProjectReach: before.restrictedProjectReach,
|
|
156
|
+
},
|
|
157
|
+
to: {
|
|
158
|
+
fullAccess: after.fullAccess,
|
|
159
|
+
restrictedProjectReach: after.restrictedProjectReach,
|
|
160
|
+
},
|
|
161
|
+
sequence: report.sequence,
|
|
162
|
+
by: by?.accountId ?? row.account_id,
|
|
163
|
+
via: by?.via ?? "device",
|
|
164
|
+
...(by !== undefined && { opId: by.opId }),
|
|
165
|
+
machineId,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
return "recorded";
|
|
169
|
+
}
|
|
170
|
+
async write(machineId, value) {
|
|
171
|
+
await this.db
|
|
172
|
+
.updateTable("device_machines")
|
|
173
|
+
.set({ owner_report: JSON.stringify(value) })
|
|
174
|
+
.where("id", "=", machineId)
|
|
175
|
+
.execute();
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
__decorate([
|
|
179
|
+
Transactional()
|
|
180
|
+
], OwnerReports.prototype, "record", null);
|
|
181
|
+
__decorate([
|
|
182
|
+
Transactional({ propagation: "mandatory" })
|
|
183
|
+
], OwnerReports.prototype, "recordLocked", null);
|
|
184
|
+
OwnerReports = __decorate([
|
|
185
|
+
Injectable(),
|
|
186
|
+
__param(0, Inject(KernelDb)),
|
|
187
|
+
__param(1, Inject(TransactionHost)),
|
|
188
|
+
__param(2, Inject(PermissionCeilingWrites))
|
|
189
|
+
], OwnerReports);
|
|
190
|
+
export { OwnerReports };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeviceFeature, DeviceLocalPolicySummary } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import type { DeviceFeature, DeviceLocalPolicySummary, SandboxBrowseScope, SandboxOperationScope } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { SandboxMode } from "../sandbox/modes.js";
|
|
3
3
|
/**
|
|
4
4
|
* The known features in `v` (a hello's `features` or the stored column), in a fixed order and
|
|
@@ -71,6 +71,14 @@ export interface PendingPolicyOp {
|
|
|
71
71
|
remove: string[];
|
|
72
72
|
/** Present when the op turned the sandbox back on (the only mode the platform may set). */
|
|
73
73
|
mode?: "sandbox";
|
|
74
|
+
/**
|
|
75
|
+
* The owner-ceiling narrowing the op asked a staged (v3) machine for: only `false` / `workspace`
|
|
76
|
+
* (the platform never widens). It explains the machine's own owner report of the change.
|
|
77
|
+
*/
|
|
78
|
+
ownerCeiling?: {
|
|
79
|
+
fullAccess?: false;
|
|
80
|
+
restrictedProjectReach?: "workspace";
|
|
81
|
+
};
|
|
74
82
|
source: PolicyOpSource;
|
|
75
83
|
actorTokenId?: string;
|
|
76
84
|
status: "sent" | "unknown";
|
|
@@ -90,9 +98,24 @@ export declare function pendingPolicyOpsOf(v: unknown): PendingPolicyOp[];
|
|
|
90
98
|
* written from one that was not.
|
|
91
99
|
*/
|
|
92
100
|
export declare function opVisibleIn(op: PendingPolicyOp, policy: DeviceLocalPolicySummary): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether a v3 owner report's change from `before` to `after` is what the platform's `op` asked
|
|
103
|
+
* for (the machine's own report of it, arriving before the op's answer): something changed, and
|
|
104
|
+
* every changed fact is a narrowing the op carried, to the value it asked for. A widening is never
|
|
105
|
+
* an op's.
|
|
106
|
+
*/
|
|
107
|
+
export declare function opExplainsOwnerChange(op: PendingPolicyOp, before: {
|
|
108
|
+
fullAccess: boolean;
|
|
109
|
+
restrictedProjectReach: "workspace" | "os-user";
|
|
110
|
+
}, after: {
|
|
111
|
+
fullAccess: boolean;
|
|
112
|
+
restrictedProjectReach: "workspace" | "os-user";
|
|
113
|
+
}): boolean;
|
|
93
114
|
/**
|
|
94
115
|
* Whether `diff` is what the platform's `op` did (its answer, or the machine's own report of it
|
|
95
116
|
* before the answer was recorded): hosts within the op's, and the mode the op set. The device page
|
|
96
117
|
* then lists the change once, as the platform's.
|
|
97
118
|
*/
|
|
98
119
|
export declare function opExplains(op: PendingPolicyOp, diff: LocalPolicyDiff): boolean;
|
|
120
|
+
/** Revoke only authority removed from a starting grant; explicit additions are not owner baseline. */
|
|
121
|
+
export declare function ownerPolicyRevokes(next: DeviceLocalPolicySummary | null, scope: SandboxOperationScope | SandboxBrowseScope, method: string, grantedHosts: readonly string[]): boolean;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { coversHost } from "../sandbox/modes.js";
|
|
2
|
+
import { isExecutionMethod } from "../sandbox/operation-authority-types.js";
|
|
1
3
|
const KNOWN_FEATURES = [
|
|
2
4
|
"networkReport",
|
|
3
5
|
"policyOp",
|
|
@@ -109,6 +111,7 @@ export function pendingPolicyOpsOf(v) {
|
|
|
109
111
|
add: hosts(o.add),
|
|
110
112
|
remove: hosts(o.remove),
|
|
111
113
|
...(o.mode === "sandbox" && { mode: "sandbox" }),
|
|
114
|
+
...ownerNarrowingOf(o.ownerCeiling),
|
|
112
115
|
source: {
|
|
113
116
|
accountId: src.accountId,
|
|
114
117
|
via: src.via,
|
|
@@ -136,6 +139,38 @@ export function opVisibleIn(op, policy) {
|
|
|
136
139
|
return false;
|
|
137
140
|
return op.mode === undefined || policy.mode === op.mode;
|
|
138
141
|
}
|
|
142
|
+
/** A stored op's owner narrowing: kept only while it narrows (anything wider is dropped). */
|
|
143
|
+
function ownerNarrowingOf(v) {
|
|
144
|
+
if (typeof v !== "object" || v === null)
|
|
145
|
+
return {};
|
|
146
|
+
const o = v;
|
|
147
|
+
const narrowing = {
|
|
148
|
+
...(o.fullAccess === false && { fullAccess: false }),
|
|
149
|
+
...(o.restrictedProjectReach === "workspace" && {
|
|
150
|
+
restrictedProjectReach: "workspace",
|
|
151
|
+
}),
|
|
152
|
+
};
|
|
153
|
+
return Object.keys(narrowing).length > 0 ? { ownerCeiling: narrowing } : {};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether a v3 owner report's change from `before` to `after` is what the platform's `op` asked
|
|
157
|
+
* for (the machine's own report of it, arriving before the op's answer): something changed, and
|
|
158
|
+
* every changed fact is a narrowing the op carried, to the value it asked for. A widening is never
|
|
159
|
+
* an op's.
|
|
160
|
+
*/
|
|
161
|
+
export function opExplainsOwnerChange(op, before, after) {
|
|
162
|
+
const fullChanged = before.fullAccess !== after.fullAccess;
|
|
163
|
+
const reachChanged = before.restrictedProjectReach !== after.restrictedProjectReach;
|
|
164
|
+
if (!fullChanged && !reachChanged)
|
|
165
|
+
return false;
|
|
166
|
+
if (fullChanged && (op.ownerCeiling?.fullAccess !== false || after.fullAccess))
|
|
167
|
+
return false;
|
|
168
|
+
if (reachChanged &&
|
|
169
|
+
(op.ownerCeiling?.restrictedProjectReach !== "workspace" ||
|
|
170
|
+
after.restrictedProjectReach !== "workspace"))
|
|
171
|
+
return false;
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
139
174
|
/**
|
|
140
175
|
* Whether `diff` is what the platform's `op` did (its answer, or the machine's own report of it
|
|
141
176
|
* before the answer was recorded): hosts within the op's, and the mode the op set. The device page
|
|
@@ -150,3 +185,16 @@ export function opExplains(op, diff) {
|
|
|
150
185
|
return false;
|
|
151
186
|
return true;
|
|
152
187
|
}
|
|
188
|
+
/** Revoke only authority removed from a starting grant; explicit additions are not owner baseline. */
|
|
189
|
+
export function ownerPolicyRevokes(next, scope, method, grantedHosts) {
|
|
190
|
+
if (!next)
|
|
191
|
+
return true;
|
|
192
|
+
if (!("profile" in scope))
|
|
193
|
+
return next.mode !== "auto" && scope.readRoots.includes("/");
|
|
194
|
+
if (scope.profile === "full-access")
|
|
195
|
+
return next.mode !== "auto";
|
|
196
|
+
if (!isExecutionMethod(method) || scope.network.kind !== "allowlist")
|
|
197
|
+
return false;
|
|
198
|
+
return scope.network.hosts.some((host) => !next.allowedDomains.some((pattern) => coversHost(pattern, host)) &&
|
|
199
|
+
!grantedHosts.includes(host));
|
|
200
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { type DeviceOp, type DeviceOpResults, type ExtensionContext } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type DeviceOp, type DeviceOperationV3, type DeviceOpResults, DeviceProtocolError, type DeviceStopArgs, type ExtensionContext } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
3
|
import { ApiError } from "../errors.js";
|
|
4
4
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
5
5
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
6
6
|
import type { KernelLogger } from "../log.js";
|
|
7
|
+
import { DeviceRequestNotSentError, isDeviceRequestNotSent } from "../sandbox/request-not-sent.js";
|
|
7
8
|
import { DeviceTargets } from "./targets.js";
|
|
8
9
|
/** The device's connected machine is not connected (no replica holds its lease). */
|
|
9
10
|
export declare const deviceOffline: () => ApiError;
|
|
@@ -16,6 +17,22 @@ export declare const machineRevoked: () => ApiError;
|
|
|
16
17
|
export declare const POLICY_REFUSAL_PREFIX = "Refused by the machine's local policy: ";
|
|
17
18
|
/** The text a machine's `error` result reaches the model with (ruling R28). */
|
|
18
19
|
export declare const ON_MACHINE_PREFIX = "On the connected machine: ";
|
|
20
|
+
/**
|
|
21
|
+
* The text of a staged (protocol 3) request refused because the machine's connection changed.
|
|
22
|
+
* Only an output read has an offset to retry from; every other operation is simply retried.
|
|
23
|
+
*/
|
|
24
|
+
export declare const connectionChangedMessage: (op: string) => string;
|
|
25
|
+
export { DeviceRequestNotSentError, isDeviceRequestNotSent };
|
|
26
|
+
/**
|
|
27
|
+
* The kernel-internal field of a queued `stop` naming the machine it is for (stripped by the holder
|
|
28
|
+
* before the frame goes out; a frame for another machine is dropped).
|
|
29
|
+
*/
|
|
30
|
+
export declare const STOP_MACHINE: "machineId";
|
|
31
|
+
/**
|
|
32
|
+
* Whether the deployment speaks the staged device protocol: the single gate is the SDK's protocol
|
|
33
|
+
* constant (flipped to 3 at the paired activation). Until then the active wire stays protocol 2.
|
|
34
|
+
*/
|
|
35
|
+
export declare const stagedDeviceProtocolActive: () => boolean;
|
|
19
36
|
/** The longest one lease check of a waiting caller may take before it counts as "unknown". */
|
|
20
37
|
export declare const LEASE_CHECK_TIMEOUT_MS = 2000;
|
|
21
38
|
/** How often a waiting caller checks that a replica still holds the machine's connection. */
|
|
@@ -25,11 +42,33 @@ export declare const HOLDER_POLL_MS = 5000;
|
|
|
25
42
|
* untaken request on the list (an expired one would look taken and get a needless cancel).
|
|
26
43
|
*/
|
|
27
44
|
export declare const LIST_TTL_MARGIN_MS = 30000;
|
|
45
|
+
/**
|
|
46
|
+
* The kernel-internal fields the gateway adds to what it stores for a staged result, next to the
|
|
47
|
+
* device's frame: the connection it arrived on, that connection's capacity and, only on the
|
|
48
|
+
* gateway's own refusal of a request queued for another connection, {@link GATEWAY_NOT_SENT}. The
|
|
49
|
+
* device's frame is parsed strictly (unknown keys refused), so a device can never set them.
|
|
50
|
+
*/
|
|
51
|
+
export declare const GATEWAY_NOT_SENT: "notSent";
|
|
52
|
+
/**
|
|
53
|
+
* A staged request refused because it was not sent, outside the operations held under an operation
|
|
54
|
+
* identity (a policy control, a status read): a protocol error that also says nothing ran, so a
|
|
55
|
+
* caller can record it as never received instead of unknown ({@link wasDeviceRequestNotSent}).
|
|
56
|
+
*/
|
|
57
|
+
export declare class DeviceRequestNotSentProtocolError extends DeviceProtocolError {
|
|
58
|
+
readonly notSent: true;
|
|
59
|
+
}
|
|
60
|
+
/** Any staged request the kernel knows was never sent to the machine (held or not). */
|
|
61
|
+
export declare const wasDeviceRequestNotSent: (e: unknown) => boolean;
|
|
28
62
|
export interface DeviceCallOptions {
|
|
29
63
|
/** How long the machine may take for the operation (sent to it as `deadlineMs`). */
|
|
30
64
|
deadlineMs: number;
|
|
31
65
|
/** The caller's signal: aborting gives the request up and rejects. */
|
|
32
66
|
signal: AbortSignal;
|
|
67
|
+
/** Internal authenticated lease/capacity fence; never part of caller operation arguments. */
|
|
68
|
+
connection?: {
|
|
69
|
+
connectionId: string;
|
|
70
|
+
maxFrameBytes: number;
|
|
71
|
+
};
|
|
33
72
|
}
|
|
34
73
|
/**
|
|
35
74
|
* The caller side of the device relay (environments spec §13.4). A request goes onto the
|
|
@@ -60,14 +99,43 @@ export declare class LocalDeviceRelay {
|
|
|
60
99
|
private readonly config;
|
|
61
100
|
private readonly log;
|
|
62
101
|
private readonly targets;
|
|
63
|
-
constructor(redis: Redis, bus: ExtensionContext["bus"], locks: Pick<LockService, "holderOf">, config: Pick<KernelConfigService, "get">, log: Pick<KernelLogger, "warn">, targets: Pick<DeviceTargets, "state">);
|
|
102
|
+
constructor(redis: Redis, bus: ExtensionContext["bus"], locks: Pick<LockService, "holderOf">, config: Pick<KernelConfigService, "get">, log: Pick<KernelLogger, "warn">, targets: Pick<DeviceTargets, "state" | "transport">);
|
|
64
103
|
/** Whether a gateway replica holds the machine's connection now. */
|
|
65
104
|
holderLive(deviceId: string): Promise<boolean>;
|
|
66
105
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
106
|
+
* Whether the protocol gate is open ({@link stagedDeviceProtocolActive}; a test seam opens it
|
|
107
|
+
* for one relay instance, the deployment never does).
|
|
108
|
+
*/
|
|
109
|
+
stagedProtocolActive: () => boolean;
|
|
110
|
+
/**
|
|
111
|
+
* The negotiated transport of the device's connection when the platform's own controls (policy
|
|
112
|
+
* ops) must speak protocol 3 to it, else null (protocol 2). With the gate closed every
|
|
113
|
+
* connection is protocol 2: nothing is looked up (no lease or transport read per op). With it
|
|
114
|
+
* open every connection is staged, so this is {@link connection} (a missing or unready one
|
|
115
|
+
* throws its typed error).
|
|
116
|
+
*/
|
|
117
|
+
stagedTransport(deviceId: string): Promise<{
|
|
118
|
+
connectionId: string;
|
|
119
|
+
maxFrameBytes: number;
|
|
120
|
+
} | null>;
|
|
121
|
+
/**
|
|
122
|
+
* The negotiated transport of the machine's current connection, for a staged call. Liveness is
|
|
123
|
+
* checked first (ruling R27): no holder throws `device.not_found` for a deleted device,
|
|
124
|
+
* `device.forbidden` for a revoked machine and `device.offline` otherwise.
|
|
69
125
|
*/
|
|
70
|
-
|
|
126
|
+
connection(deviceId: string): Promise<{
|
|
127
|
+
connectionId: string;
|
|
128
|
+
maxFrameBytes: number;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Queues `stop` for the machine without waiting for an answer (ruling R14). The caller checks
|
|
132
|
+
* {@link holderLive} first; the frame waits on the list for the grace like any request. It is
|
|
133
|
+
* fenced to the machine `machineId` ({@link STOP_MACHINE}): a holder hands it only to that
|
|
134
|
+
* machine's connection (on a staged connection as a protocol 3 `stop`, across a socket blip
|
|
135
|
+
* too), never to a newer machine of the device. Only `stop` is ever queued this way: a broad
|
|
136
|
+
* kill (`killAll` / `killTagged`) has no frame on protocol 3.
|
|
137
|
+
*/
|
|
138
|
+
send(deviceId: string, op: "stop", args: DeviceStopArgs, deadlineMs: number, machineId: string): Promise<void>;
|
|
71
139
|
/**
|
|
72
140
|
* Runs `op` on the device's machine and returns its validated result. Throws
|
|
73
141
|
* `device.offline` when no replica holds the machine at send time or when the wait ran
|
|
@@ -79,6 +147,9 @@ export declare class LocalDeviceRelay {
|
|
|
79
147
|
* abort reason is thrown.
|
|
80
148
|
*/
|
|
81
149
|
call<Op extends DeviceOp>(deviceId: string, op: Op, args: unknown, opts: DeviceCallOptions): Promise<DeviceOpResults[Op]>;
|
|
150
|
+
/** Development staging: the active gateway continues rejecting protocol 3 until coordinated cutover. */
|
|
151
|
+
callV3(deviceId: string, op: DeviceOperationV3, args: Record<string, unknown>, opts: DeviceCallOptions): Promise<unknown>;
|
|
152
|
+
private callWithCodec;
|
|
82
153
|
/** {@link holderLive}, or undefined when it takes longer than {@link LEASE_CHECK_TIMEOUT_MS}. */
|
|
83
154
|
private leaseCheck;
|
|
84
155
|
/**
|
|
@@ -96,7 +167,12 @@ export declare class LocalDeviceRelay {
|
|
|
96
167
|
private giveUp;
|
|
97
168
|
/** Runs a side step whose failure must not replace the call's outcome: logged, swallowed. */
|
|
98
169
|
private quietly;
|
|
99
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* A stored / published `res` frame for request `id`, or the protocol error it carries. A staged
|
|
172
|
+
* frame carries the tag of the connection it arrived on (added by the gateway); a fenced
|
|
173
|
+
* operation ({@link connectionFenced}) accepts only its request's connection, any other staged
|
|
174
|
+
* operation a well-formed tag, and the frame is parsed against that connection's capacity.
|
|
175
|
+
*/
|
|
100
176
|
private parseRes;
|
|
101
177
|
private resultOf;
|
|
102
178
|
}
|