@capybara-hq/kernel 0.1.0-rc.49 → 0.1.0-rc.50

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.
Files changed (128) hide show
  1. package/dist/admin/admin.schemas.d.ts +0 -6
  2. package/dist/background/launch.d.ts +7 -61
  3. package/dist/background/launch.js +8 -133
  4. package/dist/background/poll.job.d.ts +19 -23
  5. package/dist/background/poll.job.js +30 -66
  6. package/dist/background/render.d.ts +9 -0
  7. package/dist/background/render.js +19 -0
  8. package/dist/background/session.d.ts +3 -66
  9. package/dist/background/session.js +3 -114
  10. package/dist/background/stop.d.ts +26 -33
  11. package/dist/background/stop.js +59 -90
  12. package/dist/background/store.d.ts +26 -60
  13. package/dist/background/store.js +23 -108
  14. package/dist/background/tasks.service.d.ts +9 -29
  15. package/dist/background/tasks.service.js +18 -115
  16. package/dist/catalog/marketplaces.service.d.ts +1 -1
  17. package/dist/channels/cards.d.ts +3 -0
  18. package/dist/channels/cards.js +29 -2
  19. package/dist/channels/phrases.d.ts +35 -0
  20. package/dist/channels/phrases.js +32 -0
  21. package/dist/config/load.d.ts +3 -10
  22. package/dist/config/load.js +26 -21
  23. package/dist/config/schema.js +3 -3
  24. package/dist/conversations/events.d.ts +45 -2
  25. package/dist/conversations/events.js +44 -4
  26. package/dist/db/kernel-schema.d.ts +9 -4
  27. package/dist/devices/devices.service.js +1 -1
  28. package/dist/devices/errors.d.ts +5 -0
  29. package/dist/devices/errors.js +5 -0
  30. package/dist/devices/project-rules.d.ts +2 -2
  31. package/dist/errors.d.ts +9 -11
  32. package/dist/errors.js +9 -11
  33. package/dist/identity/settings.d.ts +4 -17
  34. package/dist/identity/settings.js +9 -32
  35. package/dist/infra/config/kernel-config.service.js +2 -9
  36. package/dist/infra/outbox/registry.d.ts +13 -0
  37. package/dist/infra/outbox/registry.js +8 -0
  38. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  39. package/dist/local-devices/device-auth.controller.js +1 -1
  40. package/dist/local-devices/device-auth.d.ts +4 -3
  41. package/dist/local-devices/device-auth.js +1 -1
  42. package/dist/local-devices/device-policy.service.d.ts +6 -6
  43. package/dist/local-devices/device-routes.d.ts +4 -2
  44. package/dist/local-devices/device-routes.js +7 -6
  45. package/dist/local-devices/instance-bindings.d.ts +4 -4
  46. package/dist/local-devices/instance-bindings.js +2 -2
  47. package/dist/local-devices/local-device-gateway.d.ts +12 -12
  48. package/dist/local-devices/local-device-gateway.js +94 -129
  49. package/dist/local-devices/local-device-provider.d.ts +19 -87
  50. package/dist/local-devices/local-device-provider.js +43 -158
  51. package/dist/local-devices/local-devices.module.d.ts +4 -5
  52. package/dist/local-devices/local-devices.module.js +6 -9
  53. package/dist/local-devices/machines.d.ts +6 -6
  54. package/dist/local-devices/machines.js +4 -4
  55. package/dist/local-devices/owner-report.d.ts +3 -3
  56. package/dist/local-devices/owner-report.js +4 -4
  57. package/dist/local-devices/owner-reports.js +2 -2
  58. package/dist/local-devices/policy-summary.js +2 -2
  59. package/dist/local-devices/relay.d.ts +12 -25
  60. package/dist/local-devices/relay.js +17 -31
  61. package/dist/orgs/settings.controller.d.ts +1 -4
  62. package/dist/orgs/settings.controller.js +3 -3
  63. package/dist/orgs/settings.service.d.ts +7 -21
  64. package/dist/orgs/settings.service.js +16 -40
  65. package/dist/overrides.d.ts +3 -3
  66. package/dist/platform/ops/admin.ops.js +6 -8
  67. package/dist/platform/ops/org-settings.ops.js +4 -4
  68. package/dist/platform/ops/orgs.ops.js +0 -1
  69. package/dist/runtime/maintenance.d.ts +1 -1
  70. package/dist/runtime/maintenance.js +7 -1
  71. package/dist/runtime/run-steps.js +2 -2
  72. package/dist/sandbox/held-operations.d.ts +7 -0
  73. package/dist/sandbox/held-operations.js +25 -1
  74. package/dist/sandbox/leases.d.ts +6 -3
  75. package/dist/sandbox/leases.js +16 -10
  76. package/dist/sandbox/legacy-retirement.d.ts +0 -19
  77. package/dist/sandbox/legacy-retirement.js +6 -37
  78. package/dist/sandbox/managed-device-context.d.ts +12 -0
  79. package/dist/sandbox/managed-device-context.js +49 -1
  80. package/dist/sandbox/modes.d.ts +9 -8
  81. package/dist/sandbox/modes.js +4 -15
  82. package/dist/sandbox/operation-authority-types.d.ts +18 -1
  83. package/dist/sandbox/operation-authority-types.js +20 -1
  84. package/dist/sandbox/operation-authority.d.ts +14 -0
  85. package/dist/sandbox/operation-authority.js +120 -18
  86. package/dist/sandbox/operation-intents.d.ts +43 -0
  87. package/dist/sandbox/operation-intents.js +107 -4
  88. package/dist/sandbox/operation-reconcile.job.d.ts +12 -1
  89. package/dist/sandbox/operation-reconcile.job.js +53 -6
  90. package/dist/sandbox/permission-call-grants.d.ts +4 -0
  91. package/dist/sandbox/permission-call-grants.js +32 -3
  92. package/dist/sandbox/permission-call-types.d.ts +27 -2
  93. package/dist/sandbox/permission-ceiling-writes.js +2 -1
  94. package/dist/sandbox/permission-context-types.d.ts +2 -2
  95. package/dist/sandbox/permission-context-types.js +2 -2
  96. package/dist/sandbox/permission-facts.js +10 -2
  97. package/dist/sandbox/platform-full-access.d.ts +8 -26
  98. package/dist/sandbox/platform-full-access.js +8 -20
  99. package/dist/sandbox/review/classifier.d.ts +2 -2
  100. package/dist/sandbox/review/classifier.js +18 -5
  101. package/dist/sandbox/review/permission-candidate.d.ts +59 -3
  102. package/dist/sandbox/review/permission-candidate.js +192 -25
  103. package/dist/sandbox/review/review.service.d.ts +18 -0
  104. package/dist/sandbox/review/review.service.js +158 -12
  105. package/dist/sandbox/sandbox.service.d.ts +71 -47
  106. package/dist/sandbox/sandbox.service.js +234 -133
  107. package/dist/tools/approvals.service.d.ts +6 -1
  108. package/dist/tools/approvals.service.js +10 -0
  109. package/dist/tools/builtins/builtin-tools.d.ts +1 -4
  110. package/dist/tools/builtins/builtin-tools.js +13 -18
  111. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  112. package/dist/tools/builtins/sandbox/bash.js +92 -270
  113. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  114. package/dist/tools/builtins/sandbox/common.js +55 -19
  115. package/dist/tools/builtins/sandbox/device-owner.d.ts +13 -0
  116. package/dist/tools/builtins/sandbox/device-owner.js +14 -0
  117. package/dist/tools/builtins/sandbox/task-list.js +2 -2
  118. package/dist/tools/builtins/sandbox/task-output.d.ts +14 -57
  119. package/dist/tools/builtins/sandbox/task-output.js +88 -210
  120. package/dist/tools/builtins/sandbox/task-stop.d.ts +2 -2
  121. package/dist/tools/builtins/sandbox/task-stop.js +15 -26
  122. package/dist/tools/pipeline.d.ts +31 -2
  123. package/dist/tools/pipeline.js +273 -43
  124. package/dist/tools/registry.d.ts +7 -0
  125. package/package.json +4 -4
  126. package/src/migrations/0162_permission_call_escalation.sql +9 -0
  127. package/dist/background/status.d.ts +0 -35
  128. package/dist/background/status.js +0 -57
@@ -6,7 +6,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
6
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
7
7
  import type { KernelLogger } from "../log.js";
8
8
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
9
- import { type DevicesAutoModeView, type DevicesFullAccessPatch, type DevicesFullAccessStored, type DevicesFullAccessView } from "../sandbox/platform-full-access.js";
9
+ import { type DevicesFullAccessPatch, type DevicesFullAccessStored, type DevicesFullAccessView } from "../sandbox/platform-full-access.js";
10
10
  import { type ExternalSharingView, type ShareMaxExpiryView } from "../shares/settings.js";
11
11
  import { type UiArrangement } from "../ui/arrangement.js";
12
12
  import { SuperAdminLock } from "./super-admin.js";
@@ -163,15 +163,13 @@ export declare const DEPLOYMENT_SETTINGS: z.ZodObject<{
163
163
  }, z.core.$strip>;
164
164
  export type DeploymentSettings = z.infer<typeof DEPLOYMENT_SETTINGS>;
165
165
  /**
166
- * What `GET /api/v1/admin/settings` answers: the stored settings, the platform's auto-mode switch
167
- * as it is in effect with where it comes from (`env` / `file` / `nacos`: the startup config,
166
+ * What `GET /api/v1/admin/settings` answers: the stored settings, the platform's Full permission
167
+ * switch as it is in effect with where it comes from (`env` / `file` / `nacos`: the startup config,
168
168
  * read-only here; `db`: chosen in the admin console; `default`), and the platform's effective
169
169
  * attribution defaults with their sources the same way.
170
170
  */
171
171
  export type DeploymentSettingsView = DeploymentSettings & {
172
172
  devicesFullAccess: DevicesFullAccessView;
173
- /** The same switch under its old public name, until the old public readers are removed. */
174
- devicesAutoMode: DevicesAutoModeView;
175
173
  attribution: PlatformAttributionView;
176
174
  /** The platform's external sharing switch in effect and where it comes from. */
177
175
  externalSharing: ExternalSharingView;
@@ -235,12 +233,6 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
235
233
  off: "off";
236
234
  }>>;
237
235
  }, z.core.$strict>>;
238
- devicesAutoMode: z.ZodOptional<z.ZodObject<{
239
- mode: z.ZodNullable<z.ZodEnum<{
240
- allowed: "allowed";
241
- off: "off";
242
- }>>;
243
- }, z.core.$strict>>;
244
236
  attribution: z.ZodOptional<z.ZodObject<{
245
237
  commit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
246
238
  pr: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -314,11 +306,6 @@ export declare function readUiArrangement(db: KernelSchemaDb): Promise<UiArrange
314
306
  * {@link parseClientExtensions} (missing or invalid -> everything on; invalid also warns on `log`).
315
307
  */
316
308
  export declare function readClientExtensions(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">): Promise<ClientExtensionsKillSwitch>;
317
- /**
318
- * A patch with the old `devicesAutoMode` moved to `devicesFullAccess`; both together is a
319
- * validation error (never pick one silently).
320
- */
321
- export declare function normalizeDeploymentSettingsPatch(patch: DeploymentSettingsPatch): DeploymentSettingsPatch;
322
309
  /** Deployment settings: one row per key, defaults for missing keys. */
323
310
  export declare class SettingsService {
324
311
  private readonly db;
@@ -337,7 +324,7 @@ export declare class SettingsService {
337
324
  /**
338
325
  * The refusals of a `devicesFullAccess` change: a value set in the startup config
339
326
  * (`deployment.setting_readonly`) and, with `onlyNarrows` (an API token, the Platform tool),
340
- * allowing Full where it is off (`deployment.auto_mode_not_allowed`). Returns the next stored
327
+ * allowing Full where it is off (`deployment.full_access_not_allowed`). Returns the next stored
341
328
  * choice and the effective switch before it.
342
329
  */
343
330
  checkDevicesFullAccess(patch: DevicesFullAccessPatch, opts?: {
@@ -18,7 +18,7 @@ import { TransactionHost, withOrderedLocks } from "../infra/database/transaction
18
18
  import { Transactional } from "../infra/database/transactional.decorator.js";
19
19
  import { KERNEL_LOGGER } from "../infra/tokens.js";
20
20
  import { localMachineRoots, needsWiderDeviceCeiling, PermissionCeilingWrites, } from "../sandbox/permission-ceiling-writes.js";
21
- import { applyDevicesFullAccessPatch, DEVICES_AUTO_MODE_PATCH, DEVICES_FULL_ACCESS_DEFAULT, DEVICES_FULL_ACCESS_PATCH, DEVICES_FULL_ACCESS_SETTING, fullAccessPatchOfLegacy, LEGACY_DEVICES_AUTO_MODE_SETTING, legacyAutoModeView, legacyDevicesAutoModeStored, readDevicesFullAccess, readStoredDevicesFullAccess, } from "../sandbox/platform-full-access.js";
21
+ import { applyDevicesFullAccessPatch, DEVICES_FULL_ACCESS_DEFAULT, DEVICES_FULL_ACCESS_PATCH, DEVICES_FULL_ACCESS_SETTING, LEGACY_DEVICES_AUTO_MODE_SETTING, legacyDevicesAutoModeStored, readDevicesFullAccess, readStoredDevicesFullAccess, } from "../sandbox/platform-full-access.js";
22
22
  import { EXTERNAL_SHARING_SETTING, ExternalSharingValue, HTML_CDN_ALLOWLIST_DEFAULT, HtmlCdnAllowlistSchema, readExternalSharing, readHtmlCdnAllowlist, readShareMaxExpiry, SHARE_MAX_EXPIRY_DEFAULT, SHARE_MAX_EXPIRY_SETTING, ShareMaxExpiryDays, } from "../shares/settings.js";
23
23
  import { assertPlatformDefaultEligible, lockThemeShared } from "../themes/theme-state.js";
24
24
  import { mergeArrangement, UiArrangementPatchSchema, UiArrangementSchema, } from "../ui/arrangement.js";
@@ -218,7 +218,7 @@ export const DEPLOYMENT_SETTINGS = z.object({
218
218
  htmlRenderCdnAllowlist: HtmlCdnAllowlistSchema.default(() => [...HTML_CDN_ALLOWLIST_DEFAULT]),
219
219
  });
220
220
  const DEFAULTS = DEPLOYMENT_SETTINGS.parse({});
221
- const autoModeWidenRefused = () => new ApiError("deployment.auto_mode_not_allowed", "Allowing Full permission at the platform level (devicesFullAccess) needs a super admin in the admin console; an API token or the Platform tool may only turn it off.");
221
+ const fullAccessWidenRefused = () => new ApiError("deployment.full_access_not_allowed", "Allowing Full permission at the platform level (devicesFullAccess) needs a super admin in the admin console; an API token or the Platform tool may only turn it off.");
222
222
  /** The `deployment_settings` key of the platform's prompt suggestions switch (`"on" | "off"`). */
223
223
  export const PROMPT_SUGGESTIONS_SETTING = "promptSuggestions";
224
224
  const PromptSuggestionsValue = z.enum(["on", "off"]);
@@ -293,14 +293,9 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
293
293
  * The platform's Full permission switch (B1): `permission` replaced, null clears it (back to
294
294
  * the default, allowed). A value set in the startup config is read-only (409
295
295
  * `deployment.setting_readonly`); an API token or the Platform tool may only turn it off (400
296
- * `deployment.auto_mode_not_allowed`).
296
+ * `deployment.full_access_not_allowed`).
297
297
  */
298
298
  devicesFullAccess: DEVICES_FULL_ACCESS_PATCH.optional(),
299
- /**
300
- * The old name of `devicesFullAccess` (`{ mode }`), still accepted with the same values; never
301
- * together with it.
302
- */
303
- devicesAutoMode: DEVICES_AUTO_MODE_PATCH.optional(),
304
299
  /**
305
300
  * The platform's attribution defaults for agent-created git commits and pull requests (spec
306
301
  * 2026-11-14-agent-attribution): each given field replaces the stored one, null clears it
@@ -492,23 +487,6 @@ function mergeByOrg(current, patch) {
492
487
  }
493
488
  return merged;
494
489
  }
495
- /**
496
- * A patch with the old `devicesAutoMode` moved to `devicesFullAccess`; both together is a
497
- * validation error (never pick one silently).
498
- */
499
- export function normalizeDeploymentSettingsPatch(patch) {
500
- if (patch.devicesAutoMode === undefined)
501
- return patch;
502
- if (patch.devicesFullAccess !== undefined)
503
- throw new ApiError("validation_failed", "Invalid deployment settings", [
504
- {
505
- path: "devicesAutoMode",
506
- message: "pass devicesFullAccess only, not together with devicesAutoMode",
507
- },
508
- ]);
509
- const { devicesAutoMode, ...rest } = patch;
510
- return { ...rest, devicesFullAccess: fullAccessPatchOfLegacy(devicesAutoMode) };
511
- }
512
490
  /** Deployment settings: one row per key, defaults for missing keys. */
513
491
  let SettingsService = class SettingsService {
514
492
  db;
@@ -540,7 +518,6 @@ let SettingsService = class SettingsService {
540
518
  return {
541
519
  ...settings,
542
520
  devicesFullAccess,
543
- devicesAutoMode: legacyAutoModeView(devicesFullAccess),
544
521
  attribution: this.attributionView(attribution),
545
522
  externalSharing,
546
523
  shareMaxExpiryDays,
@@ -558,7 +535,7 @@ let SettingsService = class SettingsService {
558
535
  /**
559
536
  * The refusals of a `devicesFullAccess` change: a value set in the startup config
560
537
  * (`deployment.setting_readonly`) and, with `onlyNarrows` (an API token, the Platform tool),
561
- * allowing Full where it is off (`deployment.auto_mode_not_allowed`). Returns the next stored
538
+ * allowing Full where it is off (`deployment.full_access_not_allowed`). Returns the next stored
562
539
  * choice and the effective switch before it.
563
540
  */
564
541
  async checkDevicesFullAccess(patch, opts = {}) {
@@ -570,7 +547,7 @@ let SettingsService = class SettingsService {
570
547
  const next = applyDevicesFullAccessPatch(await readStoredDevicesFullAccess(this.db.db, this.log), patch);
571
548
  const after = next.permission ?? DEVICES_FULL_ACCESS_DEFAULT;
572
549
  if (opts.onlyNarrows && before.permission === "off" && after === DEVICES_FULL_ACCESS_DEFAULT) {
573
- throw autoModeWidenRefused();
550
+ throw fullAccessWidenRefused();
574
551
  }
575
552
  return { next, before };
576
553
  }
@@ -664,11 +641,11 @@ let SettingsService = class SettingsService {
664
641
  if (!check.success) {
665
642
  throw new ApiError("validation_failed", "Invalid deployment settings", check.error.issues.map((i) => ({ path: i.path.join("."), message: i.message })));
666
643
  }
667
- const normalized = normalizeDeploymentSettingsPatch(check.data);
644
+ const valid = check.data;
668
645
  // the super admin lock, then (for a Full switch change) the platform permission authority
669
646
  // lock: the ordered prelude, so inside a run's fence (the Platform tool's
670
647
  // `admin.update-settings`) they precede the conversation rows; the patch decides the lock
671
- await withOrderedLocks(() => this.lockFor(normalized, actorAccountId), () => this.write(normalized, actorAccountId, actorTokenId, auditDetail, opts));
648
+ await withOrderedLocks(() => this.lockFor(valid, actorAccountId), () => this.write(valid, actorAccountId, actorTokenId, auditDetail, opts));
672
649
  return this.view();
673
650
  }
674
651
  async lockFor(patch, actorAccountId) {
@@ -760,8 +737,8 @@ let SettingsService = class SettingsService {
760
737
  after: r.next.permission ?? DEVICES_FULL_ACCESS_DEFAULT,
761
738
  };
762
739
  writes.push([DEVICES_FULL_ACCESS_SETTING, r.next]);
763
- // until 8.6: an unconverted (or re-written by an old replica) old key is kept in step, so
764
- // neither side reads a value the super admin did not choose
740
+ // an old key the publication conversion has not reached yet (a mismatch window before
741
+ // activation) is kept in step, so the narrowed read shows the value the super admin chose
765
742
  if (await legacyDevicesAutoModeStored(this.db.db))
766
743
  writes.push([
767
744
  LEGACY_DEVICES_AUTO_MODE_SETTING,
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { envOverrides } from "../../config/env.js";
12
12
  import { changedPaths, configFields, getPath, secretValues, setPath } from "../../config/fields.js";
13
- import { resolveConfig, translateLegacyPermissionKeys } from "../../config/load.js";
13
+ import { resolveConfig } from "../../config/load.js";
14
14
  import { KernelConfigSchema } from "../../config/schema.js";
15
15
  import { configSourceKind } from "../../config/sources.js";
16
16
  import { KERNEL_CONFIG_INPUT, KERNEL_LOGGER } from "../tokens.js";
@@ -109,14 +109,7 @@ let KernelConfigService = class KernelConfigService {
109
109
  fieldSource(path) {
110
110
  if (getPath(this.current, path) === undefined)
111
111
  return undefined;
112
- let fromEnv = false;
113
- try {
114
- fromEnv =
115
- getPath(translateLegacyPermissionKeys(envOverrides(this.env), "env"), path) !== undefined;
116
- }
117
- catch {
118
- // conflicting variables fail the start; a later change here only loses the label
119
- }
112
+ const fromEnv = getPath(envOverrides(this.env), path) !== undefined;
120
113
  return fromEnv ? "env" : configSourceKind(this.env);
121
114
  }
122
115
  /** Subscribes to applied changes (hot fields only); returns the unsubscribe function. */
@@ -71,6 +71,19 @@ export declare const OUTBOX_JOBS: {
71
71
  readonly removeOnComplete: true;
72
72
  };
73
73
  };
74
+ readonly "sandbox-holder-revoke": {
75
+ readonly queue: "cap-kernel-maintenance";
76
+ readonly idempotent: "revokes only the holder's intents still admitted, dispatching or started-or-unknown; a revoked one is left as it is";
77
+ readonly processedIn: "packages/kernel/src/runtime/maintenance.ts";
78
+ readonly opts: {
79
+ readonly attempts: 10;
80
+ readonly backoff: {
81
+ readonly type: "exponential";
82
+ readonly delay: 5000;
83
+ };
84
+ readonly removeOnComplete: true;
85
+ };
86
+ };
74
87
  readonly run: {
75
88
  readonly queue: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs"];
76
89
  readonly idempotent: "the run worker starts only a run in `queued` state for this job's runId; a finished run's job only repeats the idempotent post-run ensureRun, a waiting run's does nothing";
@@ -47,6 +47,14 @@ export const OUTBOX_JOBS = {
47
47
  processedIn: "packages/kernel/src/runtime/maintenance.ts",
48
48
  opts: { attempts: 10, backoff: { type: "exponential", delay: 5000 }, removeOnComplete: true },
49
49
  },
50
+ // `sandbox/operation-intents.ts` HOLDER_REVOKE: owed before a crashed sandbox holder's record is
51
+ // forgotten, under `sandbox-holder-revoke-<deviceId>-<token>`
52
+ "sandbox-holder-revoke": {
53
+ queue: "cap-kernel-maintenance",
54
+ idempotent: "revokes only the holder's intents still admitted, dispatching or started-or-unknown; a revoked one is left as it is",
55
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
56
+ opts: { attempts: 10, backoff: { type: "exponential", delay: 5000 }, removeOnComplete: true },
57
+ },
50
58
  // `runtime/run-jobs.ts` RUN_JOB: one name on both run queues (a sub-agent's runs go to the
51
59
  // sub-agent queue), under the job ids `runJobId` builds and, for a waiting run's resume
52
60
  // (`RunResume.resumeIn`), `resumeJobId`
@@ -12,7 +12,7 @@ import { type DeviceAuthorizeBody, type DeviceConfirmBody, type DeviceTokenBody,
12
12
  * - `POST /authorize { name, os, arch, programVersion }` → `{ deviceCode, userCode,
13
13
  * verificationUri, verificationUriComplete, interval, expiresIn }` (`device-authorize-ip`);
14
14
  * - `POST /token { deviceCode }` → `{ credential, orgId, deviceId, connectUrl,
15
- * reconnectGraceSeconds, maxFrameBytes }` once, else `device_sign_in.authorization_pending` / `device_sign_in.slow_down` /
15
+ * reconnectGraceSeconds, maxFrameBytes, fullAccess }` once, else `device_sign_in.authorization_pending` / `device_sign_in.slow_down` /
16
16
  * `device_sign_in.denied` / `device_sign_in.expired` (`device-token-ip`).
17
17
  *
18
18
  * The person's routes need a web session (the confirmation page `/device`); each try of a user
@@ -24,7 +24,7 @@ const CODE_THROTTLER = ["device-code-account"];
24
24
  * - `POST /authorize { name, os, arch, programVersion }` → `{ deviceCode, userCode,
25
25
  * verificationUri, verificationUriComplete, interval, expiresIn }` (`device-authorize-ip`);
26
26
  * - `POST /token { deviceCode }` → `{ credential, orgId, deviceId, connectUrl,
27
- * reconnectGraceSeconds, maxFrameBytes }` once, else `device_sign_in.authorization_pending` / `device_sign_in.slow_down` /
27
+ * reconnectGraceSeconds, maxFrameBytes, fullAccess }` once, else `device_sign_in.authorization_pending` / `device_sign_in.slow_down` /
28
28
  * `device_sign_in.denied` / `device_sign_in.expired` (`device-token-ip`).
29
29
  *
30
30
  * The person's routes need a web session (the confirmation page `/device`); each try of a user
@@ -44,10 +44,11 @@ export interface DeviceGrant extends Grant {
44
44
  /** `devices.local.maxFrameBytes`: the program never sends a larger frame (ruling R26). */
45
45
  maxFrameBytes: number;
46
46
  /**
47
- * Whether the organization allows auto mode now: `off` turns a local device's default to sandbox
48
- * mode and makes `login` say why (auto mode spec §4.1). Absent on older kernels counts as allowed.
47
+ * Whether the platform and the organization allow Full access now (`devices.fullAccess` and the
48
+ * org's `fullAccess`): `off` makes `login` say that the org does not allow Full access, even
49
+ * when the machine's owner ceiling does.
49
50
  */
50
- autoMode: "allowed" | "off";
51
+ fullAccess: "allowed" | "off";
51
52
  }
52
53
  /** A user code as typed → `XXXX-XXXX`, or null when it cannot be one. */
53
54
  export declare function normalizeUserCode(input: string): string | null;
@@ -192,7 +192,7 @@ let DeviceAuthService = class DeviceAuthService {
192
192
  connectUrl,
193
193
  reconnectGraceSeconds: local.reconnectGraceSeconds,
194
194
  maxFrameBytes: local.maxFrameBytes,
195
- autoMode: allowedDeviceMode(deployment.fullAccess, settings.fullAccess) === "auto"
195
+ fullAccess: allowedDeviceMode(deployment.fullAccess, settings.fullAccess) === "auto"
196
196
  ? "allowed"
197
197
  : "off",
198
198
  };
@@ -1,4 +1,4 @@
1
- import { type DeviceFeature, type DeviceLocalPolicySummary, type DevicePolicyArgs, type DevicePolicyArgsV3, type DevicePolicyStatus } from "@capybara-hq/plugin-sdk";
1
+ import { type DeviceFeature, type DeviceLocalPolicySummary, type DevicePolicyArgs, type LegacyDevicePolicyArgs, type LegacyDevicePolicyStatus } from "@capybara-hq/plugin-sdk";
2
2
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
3
3
  import { KernelDb } from "../infra/database/kernel-db.js";
4
4
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -13,7 +13,7 @@ export declare const POLICY_DEADLINE_MS = 30000;
13
13
  /** How long an op left `unknown` waits for the machine's hello to report it (from its intent). */
14
14
  export declare const UNKNOWN_OP_MS: number;
15
15
  /** A policy change as callers ask for it: the op id and the source are added here. */
16
- type PolicyChange = Omit<DevicePolicyArgsV3, "source" | "opId">;
16
+ type PolicyChange = Omit<DevicePolicyArgs, "source" | "opId">;
17
17
  /**
18
18
  * Test seam (`KernelOverride`): called by {@link DevicePolicyService.send} right after the `policy`
19
19
  * op's call returned, before its outcome is recorded (by `apply` or a network ask's decision);
@@ -39,7 +39,7 @@ export interface PolicyIntent {
39
39
  deviceId: string;
40
40
  machineId: string;
41
41
  opId: string;
42
- args: DevicePolicyArgsV3;
42
+ args: DevicePolicyArgs;
43
43
  /**
44
44
  * The staged (protocol 3) connection the op goes to, when the device's machine is connected
45
45
  * over one: the op is sent as a v3 `policy` request fenced to it (not sent at all once it
@@ -73,7 +73,7 @@ export type PolicyOpResult = {
73
73
  outcome: "unknown";
74
74
  };
75
75
  /** What a machine says of an op id ({@link DevicePolicyService.outcomeOf}). */
76
- export type PolicyOpStatus = (DevicePolicyStatus & {
76
+ export type PolicyOpStatus = (LegacyDevicePolicyStatus & {
77
77
  ownerCeiling?: unknown;
78
78
  connectionId?: string | null;
79
79
  }) | {
@@ -119,7 +119,7 @@ export declare class DevicePolicyService {
119
119
  orgId: string;
120
120
  deviceId: string;
121
121
  change: PolicyChange;
122
- source: DevicePolicyArgs["source"];
122
+ source: LegacyDevicePolicyArgs["source"];
123
123
  actorTokenId?: string;
124
124
  }): Promise<PolicyChangeOutcome>;
125
125
  /**
@@ -132,7 +132,7 @@ export declare class DevicePolicyService {
132
132
  orgId: string;
133
133
  deviceId: string;
134
134
  change: PolicyChange;
135
- source: DevicePolicyArgs["source"];
135
+ source: LegacyDevicePolicyArgs["source"];
136
136
  actorTokenId?: string;
137
137
  }): Promise<{
138
138
  intent: PolicyIntent;
@@ -8,7 +8,8 @@ export declare const DEVICE_PROTOCOL_HEADER = "x-capybara-device-protocol";
8
8
  /** What the route needs from the gateway (`LocalDeviceGateway`). */
9
9
  export interface DeviceRoutesGateway {
10
10
  authenticate(credential: string): Promise<MachineIdentity | null>;
11
- accept(socket: WebSocket, identity: MachineIdentity, credential: string): void;
11
+ /** Serves the upgraded socket (re-checks the credential with the socket paused). */
12
+ accept(socket: WebSocket, credential: string): Promise<void>;
12
13
  }
13
14
  export interface DeviceRoutesOptions {
14
15
  gateway: DeviceRoutesGateway;
@@ -24,7 +25,8 @@ export declare function isWebSocketUpgrade(req: FastifyRequest): boolean;
24
25
  * Registers `GET /device/connect` (the gateway role only) in its own encapsulated scope with
25
26
  * `@fastify/websocket`: a raw Fastify route outside Nest, so neither the API's `AuthGuard` nor its
26
27
  * CSRF check applies; the route checks the machine credential itself, before the upgrade (401
27
- * `device.credential_invalid`), then the protocol header (426 `device.program_outdated`).
28
+ * `device.credential_invalid`), then the protocol header (426 `device.program_outdated`): only
29
+ * {@link DEVICE_PROTOCOL_VERSION} (3) is served; a protocol 2 program must update.
28
30
  * Must be called before Nest `app.init()`, on the root instance.
29
31
  *
30
32
  * `@fastify/websocket` sends every upgrade request of the server through the Fastify router; the
@@ -36,7 +36,8 @@ function bearer(req) {
36
36
  * Registers `GET /device/connect` (the gateway role only) in its own encapsulated scope with
37
37
  * `@fastify/websocket`: a raw Fastify route outside Nest, so neither the API's `AuthGuard` nor its
38
38
  * CSRF check applies; the route checks the machine credential itself, before the upgrade (401
39
- * `device.credential_invalid`), then the protocol header (426 `device.program_outdated`).
39
+ * `device.credential_invalid`), then the protocol header (426 `device.program_outdated`): only
40
+ * {@link DEVICE_PROTOCOL_VERSION} (3) is served; a protocol 2 program must update.
40
41
  * Must be called before Nest `app.init()`, on the root instance.
41
42
  *
42
43
  * `@fastify/websocket` sends every upgrade request of the server through the Fastify router; the
@@ -59,7 +60,7 @@ export async function registerDeviceConnectRoute(fastify, opts) {
59
60
  });
60
61
  await fastify.register(async (scope) => {
61
62
  await scope.register(websocket, { options: { maxPayload: opts.maxFrameBytes } });
62
- const identities = new WeakMap();
63
+ const credentials = new WeakMap();
63
64
  scope.get(DEVICE_CONNECT_ROUTE, {
64
65
  websocket: true,
65
66
  preValidation: async (req, reply) => {
@@ -76,15 +77,15 @@ export async function registerDeviceConnectRoute(fastify, opts) {
76
77
  .send(errorBody("device.program_outdated", `This kernel speaks device protocol ${DEVICE_PROTOCOL_VERSION}. ` +
77
78
  "Update capybara-device."));
78
79
  }
79
- identities.set(req, { identity, cred });
80
+ credentials.set(req, cred);
80
81
  },
81
82
  }, (socket, req) => {
82
- const found = identities.get(req);
83
- if (!found) {
83
+ const cred = credentials.get(req);
84
+ if (cred === undefined) {
84
85
  socket.close(4400, "not authenticated");
85
86
  return;
86
87
  }
87
- opts.gateway.accept(socket, found.identity, found.cred);
88
+ void opts.gateway.accept(socket, cred);
88
89
  });
89
90
  });
90
91
  }
@@ -1,4 +1,4 @@
1
- import { type BindInstanceRequestV3, type BindInstanceResultV3, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
1
+ import { type BindInstanceRequest, type BindInstanceResult, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
2
2
  import { KernelDb } from "../infra/database/kernel-db.js";
3
3
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
4
  import { LegacyRetirementStore } from "../sandbox/legacy-retirement.js";
@@ -10,7 +10,7 @@ import { LocalDeviceRelay } from "./relay.js";
10
10
  /** The committed binding of a local instance generation, as the coordinator sends it. */
11
11
  export interface CommittedBinding {
12
12
  orgId: string;
13
- request: BindInstanceRequestV3;
13
+ request: BindInstanceRequest;
14
14
  status: "awaiting-device" | "installed";
15
15
  /** The machine the binding was committed for (null: none was active). */
16
16
  machineId: string | null;
@@ -63,7 +63,7 @@ export declare class LocalInstanceBindings implements SandboxInstanceBinder {
63
63
  * Sends the committed binding and installs the verified answer. The caller holds the device's
64
64
  * lifecycle lease; no transaction is open across the RPC.
65
65
  */
66
- bind(deviceId: string, signal: AbortSignal): Promise<BindInstanceResultV3 | null>;
66
+ bind(deviceId: string, signal: AbortSignal): Promise<BindInstanceResult | null>;
67
67
  /**
68
68
  * Moves a still awaiting binding to the active machine: its previous becomes the last binding
69
69
  * committed for that machine. Under the device writer, against the exact generation and id.
@@ -76,7 +76,7 @@ export declare class LocalInstanceBindings implements SandboxInstanceBinder {
76
76
  * fingerprint than the previous installed generation resets Full consent; the first verified
77
77
  * proof of an unprobed device does not (its semantic scope was what the person consented to).
78
78
  */
79
- install(deviceId: string, machineId: string, committed: CommittedBinding, answer: BindInstanceResultV3,
79
+ install(deviceId: string, machineId: string, committed: CommittedBinding, answer: BindInstanceResult,
80
80
  /** The authenticated connection the answer came on (recorded with its owner report). */
81
81
  connectionId?: string | null): Promise<void>;
82
82
  }
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { DeviceProtocolError, parseOperationResultV3, } from "@capybara-hq/plugin-sdk";
10
+ import { DeviceProtocolError, parseOperationResult, } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -152,7 +152,7 @@ let LocalInstanceBindings = class LocalInstanceBindings {
152
152
  committed = again;
153
153
  }
154
154
  const connection = await this.relay.connection(deviceId);
155
- const answer = parseOperationResultV3("bindInstance", await this.relay.callV3(deviceId, "bindInstance", { ...committed.request }, {
155
+ const answer = parseOperationResult("bindInstance", await this.relay.callV3(deviceId, "bindInstance", { ...committed.request }, {
156
156
  deadlineMs: OP_DEADLINE_MS,
157
157
  signal,
158
158
  connection,
@@ -1,4 +1,4 @@
1
- import { type DeviceFrameV3, type ExtensionContext } from "@capybara-hq/plugin-sdk";
1
+ import { type ExtensionContext } from "@capybara-hq/plugin-sdk";
2
2
  import type { WebSocket } from "@fastify/websocket";
3
3
  import type { Redis } from "ioredis";
4
4
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
@@ -42,7 +42,6 @@ declare class DeviceConnection {
42
42
  private readonly socket;
43
43
  readonly identity: MachineIdentity;
44
44
  private readonly credential;
45
- private readonly staged;
46
45
  readonly token: `${string}-${string}-${string}-${string}-${string}`;
47
46
  state: State;
48
47
  private lease;
@@ -58,9 +57,9 @@ declare class DeviceConnection {
58
57
  private released;
59
58
  /** The hello's record, then each policy frame's, one after another (never rejects). */
60
59
  private recorded;
61
- constructor(gw: LocalDeviceGateway, socket: WebSocket, identity: MachineIdentity, credential: string, staged?: boolean);
60
+ constructor(gw: LocalDeviceGateway, socket: WebSocket, identity: MachineIdentity, credential: string);
62
61
  /**
63
- * The id a staged connection fences requests and results with (sent to the machine in `ready`).
62
+ * The id a connection fences requests and results with (sent to the machine in `ready`).
64
63
  * Random and separate from the lease token, which stays internal to the kernel.
65
64
  */
66
65
  readonly connectionId: `${string}-${string}-${string}-${string}-${string}`;
@@ -114,7 +113,7 @@ declare class DeviceConnection {
114
113
  * sockets are this process's own; everything other replicas need is in Redis.
115
114
  */
116
115
  export declare class LocalDeviceGateway {
117
- readonly machines: Pick<MachinesService, "authenticate" | "recordHello" | "recordPolicy" | "recordHelloV3" | "recordPolicyV3" | "touch">;
116
+ readonly machines: Pick<MachinesService, "authenticate" | "recordHelloV3" | "recordPolicyV3" | "touch">;
118
117
  readonly locks: Pick<LockService, "hold">;
119
118
  readonly bus: ExtensionContext["bus"];
120
119
  readonly redis: Redis;
@@ -125,16 +124,19 @@ export declare class LocalDeviceGateway {
125
124
  private stopping;
126
125
  /** How often connections are pinged ({@link PING_INTERVAL_MS}; a test seam). */
127
126
  pingIntervalMs: number;
128
- constructor(machines: Pick<MachinesService, "authenticate" | "recordHello" | "recordPolicy" | "recordHelloV3" | "recordPolicyV3" | "touch">, locks: Pick<LockService, "hold">, bus: ExtensionContext["bus"], redis: Redis, config: KernelConfigService, log: Pick<KernelLogger, "info" | "warn">);
127
+ constructor(machines: Pick<MachinesService, "authenticate" | "recordHelloV3" | "recordPolicyV3" | "touch">, locks: Pick<LockService, "hold">, bus: ExtensionContext["bus"], redis: Redis, config: KernelConfigService, log: Pick<KernelLogger, "info" | "warn">);
129
128
  graceMs(): number;
130
129
  leaseTtlMs(): number;
131
130
  maxFrameBytes(): number;
132
131
  /** Who a `Bearer` machine credential stands for, or null (checked before the upgrade). */
133
132
  authenticate(credential: string): Promise<MachineIdentity | null>;
134
- /** Serves one upgraded socket of an authenticated machine until it closes. */
135
- accept(socket: WebSocket, identity: MachineIdentity, credential: string): void;
136
- /** Dormant authenticated seam; the production HTTP route never calls this until full cutover. */
137
- acceptStaged(socket: WebSocket, credential: string): Promise<void>;
133
+ /**
134
+ * Serves one upgraded socket of a machine until it closes (protocol 3 only: the route refused any
135
+ * other header with 426, and a hello that is not protocol 3 closes 4400). The credential is
136
+ * checked again here, with the socket paused, so a credential revoked since the upgrade check
137
+ * never gets a connection.
138
+ */
139
+ accept(socket: WebSocket, credential: string): Promise<void>;
138
140
  /**
139
141
  * How many devices this process holds the connection of (replica presence reports it): only
140
142
  * sockets past the hello that hold their device's lease, so a socket still claiming or being
@@ -146,6 +148,4 @@ export declare class LocalDeviceGateway {
146
148
  /** Closes every connection (1001) and hands their leases back. */
147
149
  stop(): Promise<void>;
148
150
  }
149
- /** Staged validation only; active connection acceptance above remains protocol 2. */
150
- export declare function validateDeviceOperationFrameV3(raw: string, from: "device" | "kernel"): DeviceFrameV3;
151
151
  export {};