@capybara-hq/kernel 0.1.0-rc.73 → 0.1.0-rc.75

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 (85) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/catalog/admin-catalog.schemas.d.ts +3 -1
  3. package/dist/catalog/admin-catalog.schemas.js +6 -2
  4. package/dist/catalog/marketplaces.service.d.ts +1 -1
  5. package/dist/catalog/org-catalog.schemas.d.ts +3 -1
  6. package/dist/catalog/org-catalog.schemas.js +3 -1
  7. package/dist/catalog/plugin-package.js +7 -5
  8. package/dist/catalog/reserved-names.js +3 -9
  9. package/dist/channels/actions.js +4 -0
  10. package/dist/channels/cards.d.ts +10 -7
  11. package/dist/channels/cards.js +23 -12
  12. package/dist/channels/phrases.d.ts +24 -2
  13. package/dist/channels/phrases.js +12 -2
  14. package/dist/ctx/secrets.d.ts +4 -2
  15. package/dist/ctx/secrets.js +19 -5
  16. package/dist/db/kernel-schema.d.ts +14 -0
  17. package/dist/devices/conversation-devices.d.ts +3 -2
  18. package/dist/devices/conversation-devices.js +9 -4
  19. package/dist/devices/device-projects.service.d.ts +22 -27
  20. package/dist/devices/device-projects.service.js +39 -44
  21. package/dist/devices/devices.controller.d.ts +3 -5
  22. package/dist/devices/devices.controller.js +4 -17
  23. package/dist/devices/devices.schemas.d.ts +1 -1
  24. package/dist/devices/devices.schemas.js +1 -1
  25. package/dist/devices/devices.service.d.ts +75 -52
  26. package/dist/devices/devices.service.js +166 -95
  27. package/dist/devices/project-rules.d.ts +6 -8
  28. package/dist/devices/project-rules.js +5 -11
  29. package/dist/dial-in/auth.service.js +1 -1
  30. package/dist/dial-in/machines.d.ts +4 -15
  31. package/dist/dial-in/machines.js +4 -59
  32. package/dist/errors.d.ts +8 -3
  33. package/dist/errors.js +8 -3
  34. package/dist/extensions/admin-ops.js +2 -1
  35. package/dist/extensions/bootstrap-extra.d.ts +11 -1
  36. package/dist/extensions/bootstrap-extra.js +21 -1
  37. package/dist/extensions/bootstrap-manifest.d.ts +14 -0
  38. package/dist/extensions/bootstrap-manifest.js +23 -0
  39. package/dist/extensions/bootstrap-packages.d.ts +87 -0
  40. package/dist/extensions/bootstrap-packages.js +263 -0
  41. package/dist/extensions/bootstrap.d.ts +27 -71
  42. package/dist/extensions/bootstrap.js +85 -329
  43. package/dist/extensions/guide-places.d.ts +9 -0
  44. package/dist/extensions/guide-places.js +32 -22
  45. package/dist/extensions/plugin-guides.d.ts +20 -2
  46. package/dist/extensions/plugin-guides.js +39 -14
  47. package/dist/http/meta.controller.d.ts +0 -1
  48. package/dist/http/meta.controller.js +2 -6
  49. package/dist/identity/sso-paths.d.ts +7 -0
  50. package/dist/identity/sso-paths.js +13 -0
  51. package/dist/identity/sso.js +3 -2
  52. package/dist/index.d.ts +3 -1
  53. package/dist/index.js +3 -1
  54. package/dist/lifecycle/kernel-lifecycle.js +2 -2
  55. package/dist/platform/exclusions.js +2 -7
  56. package/dist/platform/ops/devices.ops.js +11 -7
  57. package/dist/platform/ops/setup.ops.js +1 -1
  58. package/dist/runtime/project/knowledge.service.js +6 -5
  59. package/dist/sandbox/device-sandbox.d.ts +27 -2
  60. package/dist/sandbox/device-sandbox.js +42 -5
  61. package/dist/sandbox/modes.d.ts +16 -4
  62. package/dist/sandbox/modes.js +12 -0
  63. package/dist/sandbox/operation-authority.js +3 -1
  64. package/dist/sandbox/permission-authority-lock.d.ts +6 -0
  65. package/dist/sandbox/permission-authority-lock.js +14 -0
  66. package/dist/sandbox/permission-facts.d.ts +16 -2
  67. package/dist/sandbox/permission-facts.js +20 -5
  68. package/dist/sandbox/review/permission-candidate.d.ts +12 -7
  69. package/dist/sandbox/review/permission-candidate.js +28 -7
  70. package/dist/sandbox/sandbox.service.d.ts +18 -11
  71. package/dist/sandbox/sandbox.service.js +51 -24
  72. package/dist/setup/setup-guides.service.d.ts +3 -4
  73. package/dist/setup/setup-guides.service.js +2 -5
  74. package/dist/shares/sweep.job.d.ts +2 -0
  75. package/dist/shares/sweep.job.js +3 -1
  76. package/dist/tools/approvals.service.d.ts +31 -11
  77. package/dist/tools/approvals.service.js +55 -19
  78. package/dist/tools/builtins/sandbox/common.d.ts +2 -2
  79. package/dist/tools/builtins/sandbox/common.js +2 -2
  80. package/dist/tools/network-asks.d.ts +103 -20
  81. package/dist/tools/network-asks.js +133 -18
  82. package/dist/tools/pipeline.d.ts +5 -0
  83. package/dist/tools/pipeline.js +15 -8
  84. package/package.json +3 -3
  85. package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
@@ -1,4 +1,9 @@
1
1
  import { coversHost, orgEffectiveHosts } from "./modes.js";
2
+ /**
3
+ * Whether a ceiling's layer is the device's side (its provider, or the owner of the machine it
4
+ * runs on): it clamps the sandbox network, never what an org allows per call.
5
+ */
6
+ export const deviceSideLayer = (layer) => layer === "provider" || layer === "owner";
2
7
  /**
3
8
  * The hosts of `a` the list `b` covers and the hosts of `b` that `a` covers (wildcards included),
4
9
  * lowercased, deduplicated and sorted: never wider than either list.
@@ -43,9 +48,11 @@ export function effectiveDeviceSandbox(platform, org, device, provider) {
43
48
  ? "platform"
44
49
  : org.outsideSandbox === "off"
45
50
  ? "org"
46
- : !provider.outsideSandbox || instance
51
+ : instance
47
52
  ? "provider"
48
- : null;
53
+ : !provider.outsideSandbox
54
+ ? (provider.limitedBy?.outsideSandbox ?? "provider")
55
+ : null;
49
56
  // the network ceiling: platform, then org, then what the provider can enforce
50
57
  let ceiling;
51
58
  let networkLayer = null;
@@ -69,7 +76,7 @@ export function effectiveDeviceSandbox(platform, org, device, provider) {
69
76
  }
70
77
  else if (ceiling === "open" && !provider.network.openPublic) {
71
78
  ceiling = "allowlist";
72
- networkLayer = "provider";
79
+ networkLayer = provider.limitedBy?.openPublic ?? "provider";
73
80
  }
74
81
  // the device's choice, else the org default, else the platform default; then the ceiling
75
82
  const chosen = device.networkMode ?? org.deviceNetwork?.default ?? platform.settings.network.default;
@@ -116,6 +123,7 @@ export function providerLayerOf(support) {
116
123
  boundary: support.boundary,
117
124
  network: { ...support.network },
118
125
  outsideSandbox: support.outsideSandbox,
126
+ ...(support.limitedBy !== undefined && { limitedBy: { ...support.limitedBy } }),
119
127
  };
120
128
  return {
121
129
  boundary: "instance",
@@ -131,7 +139,7 @@ export function hostGrantCeiling(box, platform, org) {
131
139
  return { kind: "hosts", hosts: [] };
132
140
  // the platform's or org's allowlist ceiling is hard; a provider that cannot enforce the open
133
141
  // network clamps the sandbox network, not what an org allows per call
134
- const hard = box.networkCeiling === "allowlist" && box.layer?.network !== "provider";
142
+ const hard = box.networkCeiling === "allowlist" && !deviceSideLayer(box.layer?.network);
135
143
  return hard || platform.orgHosts === "within"
136
144
  ? { kind: "hosts", hosts: orgHostsOf(platform, org) }
137
145
  : {
@@ -169,11 +177,40 @@ export function hostGrantRefusal(host, box, platform, org) {
169
177
  return "network access is turned off for this device's sandbox";
170
178
  if (box.boundary === "instance" || box.perCallHosts === false)
171
179
  return `a host cannot be granted per call on this device; add ${host} to the device's network list`;
172
- return (box.networkCeiling === "allowlist" && box.layer?.network !== "provider") ||
180
+ return (box.networkCeiling === "allowlist" && !deviceSideLayer(box.layer?.network)) ||
173
181
  ceiling.kind === "any"
174
182
  ? `an organization admin adds ${host} to the organization's device network list`
175
183
  : `${host} is outside the platform's host list; a super admin adds the host`;
176
184
  }
185
+ /**
186
+ * Why `host` cannot be added to this device's own network list, naming who can make it possible,
187
+ * or null when it can. The device's list only narrows the org's effective hosts
188
+ * ({@link effectiveDeviceSandbox}, {@link orgHostsOf}), so a host is addable only when the network
189
+ * is not closed and either an org extra kept in those hosts covers it, or a kept platform entry
190
+ * covers it and no org exclusion (a pattern, as for a per-call grant) does. Exclusions drop
191
+ * platform entries only: never an extra, and nothing under `base: none`. Otherwise the refusal
192
+ * names the org admin (removing the exclusion, or adding the host when the org may extend the
193
+ * platform's list or the platform's list covers it), else the super admin.
194
+ */
195
+ export function deviceListAddRefusal(host, box, platform, org) {
196
+ if (box.networkMode === "none" || box.networkCeiling === "none" || platform.egress === "none")
197
+ return "network access is turned off for this device's sandbox";
198
+ const h = host.toLowerCase();
199
+ const covers = (list) => list.some((p) => coversHost(p.toLowerCase(), h));
200
+ const kept = orgHostsOf(platform, org);
201
+ const extras = new Set(org.deviceNetwork?.extraHosts ?? []);
202
+ if (covers(kept.filter((e) => extras.has(e))))
203
+ return null;
204
+ const fromPlatform = org.deviceNetwork?.base === "none" ? [] : kept.filter((e) => !extras.has(e));
205
+ const excluded = org.deviceNetwork?.base !== "none" && covers(org.deviceNetwork?.excludedHosts ?? []);
206
+ if (!excluded && covers(fromPlatform))
207
+ return null;
208
+ if (excluded && covers(platform.allowHosts))
209
+ return `the organization excludes ${host}; an organization admin removes the exclusion`;
210
+ return platform.orgHosts === "extend" || covers(platform.allowHosts)
211
+ ? `an organization admin adds ${host} to the organization's device network list`
212
+ : `${host} is outside the platform's host list; a super admin adds the host`;
213
+ }
177
214
  const MODE_RANK = { none: 0, allowlist: 1, open: 2 };
178
215
  /**
179
216
  * Whether `now` is within `consented` in every dimension: a narrowing keeps the consent, a widening
@@ -142,10 +142,14 @@ export interface DeviceLimits extends SandboxLimits {
142
142
  /** What a provider's create and update get of {@link DeviceLimits}: resources and the network. */
143
143
  export declare function providerLimits(limits: DeviceLimits): SandboxLimits;
144
144
  /**
145
- * What the kernel records of a cloud instance's limits (auto mode spec §4.2). Only the kind of its
146
- * network decides whether a running instance must change; `hosts` and resources reach instances
147
- * created afterwards. `mode` is recorded but never decides a change ({@link sameApplied},
148
- * {@link appliedWider}; only the one-time B1 reconciliation compares it, {@link sameAppliedExactly}):
145
+ * What the kernel records of a cloud instance's limits (auto mode spec §4.2). The kind of its
146
+ * network decides whether a running instance must change, and so do its hosts: a host the
147
+ * instance's list allows that the desired list does not ({@link appliedWider}, applied at once) or
148
+ * a desired host the instance's list does not cover ({@link appliedLacksHost}, a host added to the
149
+ * device's or the org's list, applied per the provider's `limitsApplyAt`: at the next use, or
150
+ * after a file reset). Resources reach instances created afterwards. `mode` is recorded but never
151
+ * decides a change ({@link sameApplied}, {@link appliedWider}; only the one-time B1 reconciliation
152
+ * compares it, {@link sameAppliedExactly}):
149
153
  * a cloud device has no outside of its sandbox and the mode never reaches a provider
150
154
  * ({@link providerLimits}), so a mode that follows the platform's or org's outside-sandbox setting
151
155
  * must not update every cloud instance when that setting is toggled (Docker would recreate it
@@ -171,6 +175,14 @@ export declare const sameAppliedExact: (a: AppliedLimits | null | undefined, b:
171
175
  * separately). The mode is not a dimension ({@link AppliedLimits}).
172
176
  */
173
177
  export declare function appliedWider(a: AppliedLimits | null | undefined, b: AppliedLimits): boolean;
178
+ /**
179
+ * Whether desired limits `b` allow a host that applied limits `a` do not cover, both allowlists
180
+ * (device-provider spec §6.3): a host added to the device's own list, or to the org's or the
181
+ * platform's, which the instance gets at its next use (or, with limits fixed at its file system,
182
+ * after a file reset). Unknown (null) is false here, as for {@link appliedWider}; a change of kind
183
+ * is {@link sameApplied}'s. The mode is not a dimension ({@link AppliedLimits}).
184
+ */
185
+ export declare function appliedLacksHost(a: AppliedLimits | null | undefined, b: AppliedLimits): boolean;
174
186
  /**
175
187
  * `device_instances.instance_limits` read leniently: `applied` is what the instance runs with
176
188
  * (null: unknown, e.g. an instance made before auto mode recorded tiers, which differs from every
@@ -171,6 +171,18 @@ export function appliedWider(a, b) {
171
171
  return true;
172
172
  return a.network.hosts.some((host) => !b.network.hosts.some((p) => coversHost(p, host)));
173
173
  }
174
+ /**
175
+ * Whether desired limits `b` allow a host that applied limits `a` do not cover, both allowlists
176
+ * (device-provider spec §6.3): a host added to the device's own list, or to the org's or the
177
+ * platform's, which the instance gets at its next use (or, with limits fixed at its file system,
178
+ * after a file reset). Unknown (null) is false here, as for {@link appliedWider}; a change of kind
179
+ * is {@link sameApplied}'s. The mode is not a dimension ({@link AppliedLimits}).
180
+ */
181
+ export function appliedLacksHost(a, b) {
182
+ if (a == null || a.network.kind !== "allowlist" || b.network.kind !== "allowlist")
183
+ return false;
184
+ return b.network.hosts.some((host) => !a.network.hosts.some((p) => coversHost(p, host)));
185
+ }
174
186
  const isMode = (v) => v === "auto" || v === "sandbox";
175
187
  function appliedFrom(v) {
176
188
  if (typeof v !== "object" || v === null)
@@ -495,6 +495,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
495
495
  layer: sandbox.layer.outsideSandbox,
496
496
  boundary: sandbox.boundary,
497
497
  description: base.description,
498
+ changeHint: base.changeHint,
498
499
  })
499
500
  : null;
500
501
  const vector = await this.epochs.readLocked(subject);
@@ -568,7 +569,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
568
569
  */
569
570
  async baseScopeLocked(input) {
570
571
  const { orgId, deviceId } = input;
571
- const { policy, sandbox, hostCeiling, hostRefusal, description } = await this.facts.readDevice(orgId, deviceId);
572
+ const { policy, sandbox, hostCeiling, hostRefusal, description, changeHint } = await this.facts.readDevice(orgId, deviceId);
572
573
  const { workingRoot, projectRoot } = await this.workingRootOf(input);
573
574
  const grant = input.runId
574
575
  ? await this.grants.forExec({ orgId, deviceId, runId: input.runId })
@@ -581,6 +582,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
581
582
  return {
582
583
  policy,
583
584
  description,
585
+ changeHint,
584
586
  workingRoot,
585
587
  projectRoot,
586
588
  grant,
@@ -36,3 +36,9 @@ export declare class PermissionAuthorityLock {
36
36
  }
37
37
  /** The current transaction holds this authority lock (exclusively when asked); else throws. */
38
38
  export declare function assertAuthorityHeld(kind: AuthorityLevel, id: string, exclusive?: boolean): void;
39
+ /**
40
+ * The current transaction holds every authority lock a write of `level` on `subject` takes
41
+ * ({@link PermissionAuthorityLock.acquire}): each level above `level` (shared or stronger) and
42
+ * `level` itself exclusively; else throws before the caller writes anything.
43
+ */
44
+ export declare function assertAuthorityWriteHeld(subject: AuthoritySubject, level: AuthorityLevel): void;
@@ -145,3 +145,17 @@ export function assertAuthorityHeld(kind, id, exclusive = false) {
145
145
  if (!held || (exclusive && held !== "exclusive"))
146
146
  throw new Error("The matching authority lock is required");
147
147
  }
148
+ /**
149
+ * The current transaction holds every authority lock a write of `level` on `subject` takes
150
+ * ({@link PermissionAuthorityLock.acquire}): each level above `level` (shared or stronger) and
151
+ * `level` itself exclusively; else throws before the caller writes anything.
152
+ */
153
+ export function assertAuthorityWriteHeld(subject, level) {
154
+ const entries = authorityEntries(subject);
155
+ const stop = entries.findIndex(([l]) => l === level);
156
+ if (stop < 0)
157
+ throw new Error("The changed authority level is missing");
158
+ entries.slice(0, stop + 1).forEach(([l, id], i) => {
159
+ assertAuthorityHeld(l, id, i === stop);
160
+ });
161
+ }
@@ -47,6 +47,8 @@ export declare class PermissionFacts {
47
47
  hostRefusal: (host: string) => string | null;
48
48
  /** The provider's description of the device (its stored report, English), or null. */
49
49
  description: string | null;
50
+ /** How to change the device's limits, in its provider's words (stored report, English). */
51
+ changeHint: string | null;
50
52
  }>;
51
53
  /**
52
54
  * The effective device sandbox (approval-only profiles design, "Settings model"): the platform,
@@ -80,9 +82,21 @@ export declare class PermissionFacts {
80
82
  /** The org's effective hosts: what a device's own host list may narrow, never add to. */
81
83
  orgHosts: string[];
82
84
  refusal: (host: string) => string | null;
85
+ /** Why a host cannot be added to the device's own network list ({@link deviceListAddRefusal}). */
86
+ listAddRefusal: (host: string) => string | null;
83
87
  description: string | null;
84
- /** Its provider enforces a sandbox allowlist (its support): a blocked host may be asked about. */
85
- allowlist: boolean;
88
+ /** How to change the device's limits, in its provider's words (English), or null. */
89
+ changeHint: string | null;
90
+ /**
91
+ * The device's network is an allowlist with a host list of its own: only then can a host
92
+ * join that list (`DevicesService.addNetworkHostsIn`); a device following its org's hosts
93
+ * already allows every host its list could name.
94
+ */
95
+ ownList: boolean;
96
+ /** The device's own host list (empty unless its network is an allowlist of its own). */
97
+ ownHosts: string[];
98
+ /** Where its provider applies new limits (`limitsApplyAt`; absent: at its instance). */
99
+ limitsApplyAt: "fileSystem" | "instance" | undefined;
86
100
  reach: {
87
101
  outsideSandbox: boolean;
88
102
  networkCeiling: "none" | import("./device-sandbox.js").DeviceNetworkMode;
@@ -21,7 +21,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
21
21
  import { KernelDb } from "../infra/database/kernel-db.js";
22
22
  import { readOrgSettings } from "../orgs/settings.service.js";
23
23
  import { storedReport, storedSupport } from "./device-reports.js";
24
- import { canonicalHostCeiling, effectiveDeviceSandbox, hostGrantCeiling, hostGrantRefusal, orgHostsOf, providerLayerOf, reachWithin, } from "./device-sandbox.js";
24
+ import { canonicalHostCeiling, deviceListAddRefusal, effectiveDeviceSandbox, hostGrantCeiling, hostGrantRefusal, orgHostsOf, providerLayerOf, reachWithin, } from "./device-sandbox.js";
25
25
  import { readDeviceSandboxSettings } from "./device-sandbox-settings.js";
26
26
  import { appliedOf, appliedWider, cloudChosenMode, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
27
27
  import { assertAuthorityHeld } from "./permission-authority-lock.js";
@@ -73,6 +73,8 @@ let PermissionFacts = class PermissionFacts {
73
73
  hostRefusal: sandbox.refusal,
74
74
  /** The provider's description of the device (its stored report, English), or null. */
75
75
  description: sandbox.description,
76
+ /** How to change the device's limits, in its provider's words (stored report, English). */
77
+ changeHint: sandbox.changeHint,
76
78
  };
77
79
  }
78
80
  /**
@@ -106,7 +108,7 @@ let PermissionFacts = class PermissionFacts {
106
108
  readOrgSettings(this.db.db, orgId),
107
109
  this.db
108
110
  .selectFrom("devices")
109
- .select(["network_mode", "network_hosts", "report"])
111
+ .select(["network_mode", "network_hosts", "report", "provider"])
110
112
  .where("id", "=", deviceId)
111
113
  .where("org_id", "=", orgId)
112
114
  .executeTakeFirst(),
@@ -131,6 +133,7 @@ let PermissionFacts = class PermissionFacts {
131
133
  ...(org.deviceNetwork !== undefined && { deviceNetwork: org.deviceNetwork }),
132
134
  };
133
135
  const box = effectiveDeviceSandbox(platform, orgLayer, device, providerLayerOf(support));
136
+ const report = storedReport(row?.report);
134
137
  const hostCeiling = hostGrantCeiling(box, platform, orgLayer);
135
138
  return {
136
139
  box,
@@ -138,9 +141,21 @@ let PermissionFacts = class PermissionFacts {
138
141
  /** The org's effective hosts: what a device's own host list may narrow, never add to. */
139
142
  orgHosts: orgHostsOf(platform, orgLayer),
140
143
  refusal: (host) => hostGrantRefusal(host, box, platform, orgLayer),
141
- description: storedReport(row?.report)?.description.en ?? null,
142
- /** Its provider enforces a sandbox allowlist (its support): a blocked host may be asked about. */
143
- allowlist: support !== null && support.unavailableReason === undefined && support.network.allowlist,
144
+ /** Why a host cannot be added to the device's own network list ({@link deviceListAddRefusal}). */
145
+ listAddRefusal: (host) => deviceListAddRefusal(host, box, platform, orgLayer),
146
+ description: report?.description.en ?? null,
147
+ /** How to change the device's limits, in its provider's words (English), or null. */
148
+ changeHint: report?.changeHint?.en ?? null,
149
+ /**
150
+ * The device's network is an allowlist with a host list of its own: only then can a host
151
+ * join that list (`DevicesService.addNetworkHostsIn`); a device following its org's hosts
152
+ * already allows every host its list could name.
153
+ */
154
+ ownList: device.networkMode === "allowlist" && device.networkHosts.length > 0,
155
+ /** The device's own host list (empty unless its network is an allowlist of its own). */
156
+ ownHosts: device.networkMode === "allowlist" ? [...device.networkHosts] : [],
157
+ /** Where its provider applies new limits (`limitsApplyAt`; absent: at its instance). */
158
+ limitsApplyAt: row ? this.providers.forDevice(row.provider)?.impl.limitsApplyAt : undefined,
144
159
  reach: {
145
160
  outsideSandbox: box.outsideSandbox,
146
161
  networkCeiling: box.networkCeiling,
@@ -36,27 +36,32 @@ export declare const ESCALATION_JUSTIFICATION_MISSING_TEXT = "This Bash call ask
36
36
  /** Why an escalation cannot be reviewed: an unattended run (no one can approve it). */
37
37
  export declare const ESCALATION_UNATTENDED_WHY = "this is an unattended run (a scheduled task) where no one can approve running outside the sandbox";
38
38
  /**
39
- * Why an escalation cannot be reviewed because a layer's outside-sandbox setting is off: one text
40
- * per layer that blocks it (`DeviceSandbox.layer.outsideSandbox`), each naming who lifts it and how.
39
+ * Why an escalation cannot be reviewed because the device's provider does not allow running
40
+ * outside its sandbox now, with the provider's own description of the device and how to change it
41
+ * (its report's `description` and `changeHint`).
41
42
  */
43
+ export declare const escalationDeviceOffWhy: (description: string | null, changeHint?: string | null) => string;
42
44
  /**
43
- * Why an escalation cannot be reviewed because the device's provider does not allow running
44
- * outside its sandbox now, with the provider's own description of the device (its report).
45
+ * Why an escalation cannot be reviewed because the owner of the machine the device runs on keeps
46
+ * running outside the sandbox off (the provider names that layer, support `limitedBy`), with the
47
+ * provider's description of the device and how to change it.
45
48
  */
46
- export declare const escalationDeviceOffWhy: (description: string | null) => string;
49
+ export declare const escalationOwnerOffWhy: (description: string | null, changeHint?: string | null) => string;
47
50
  export declare const ESCALATION_ORG_OFF_WHY = "running commands outside the sandbox is off in this organization; an organization admin can allow running outside the sandbox";
48
51
  export declare const ESCALATION_PLATFORM_OFF_WHY = "running commands outside the sandbox is off on this platform; a super admin can allow running outside the sandbox";
49
52
  export declare const ESCALATION_NO_OUTSIDE_WHY = "this device is an instance that is itself the sandbox, so this device has no outside of its sandbox to run a command in";
50
53
  /**
51
54
  * The refusal text of an escalation that a layer's outside-sandbox setting blocks, the same for
52
55
  * every provider: an instance-boundary provider has no outside at all, whichever layer is off;
53
- * otherwise the platform or the org names who lifts it, and a provider whose support does not
54
- * allow it now says so with its description of the device (`description`, its report's).
56
+ * otherwise the platform or the org names who lifts it, and the owner of the machine or a provider
57
+ * whose support does not allow it now says so with the device's report (`description`, and
58
+ * `changeHint`: how to change it, in the provider's words).
55
59
  */
56
60
  export declare const escalationCeilingWhy: (input: {
57
61
  layer: DeviceSandboxLayer | null;
58
62
  boundary: "operation" | "instance";
59
63
  description?: string | null;
64
+ changeHint?: string | null;
60
65
  }) => string;
61
66
  /** Why an escalation cannot be reviewed: the runtime cannot run a command outside its sandbox now. */
62
67
  export declare const escalationRuntimeWhy: (reason: string) => string;
@@ -80,22 +80,41 @@ export const ESCALATION_JUSTIFICATION_MISSING_TEXT = 'This Bash call asked to ru
80
80
  /** Why an escalation cannot be reviewed: an unattended run (no one can approve it). */
81
81
  export const ESCALATION_UNATTENDED_WHY = "this is an unattended run (a scheduled task) where no one can approve running outside the sandbox";
82
82
  /**
83
- * Why an escalation cannot be reviewed because a layer's outside-sandbox setting is off: one text
84
- * per layer that blocks it (`DeviceSandbox.layer.outsideSandbox`), each naming who lifts it and how.
83
+ * The device's own words appended to a refusal that cites its report: its description (what the
84
+ * device may do now) and its change hint (who changes that and how), each without a final period,
85
+ * as one parenthesis-free tail of a clause.
85
86
  */
87
+ function reportTail(description, changeHint) {
88
+ const clean = (t) => t.trim().replace(/\.$/, "");
89
+ const parts = [
90
+ ...(description ? [`: ${clean(description)}`] : []),
91
+ ...(changeHint
92
+ ? [` (to change this, as the device's provider says: ${clean(changeHint)})`]
93
+ : []),
94
+ ];
95
+ return parts.join("");
96
+ }
86
97
  /**
87
98
  * Why an escalation cannot be reviewed because the device's provider does not allow running
88
- * outside its sandbox now, with the provider's own description of the device (its report).
99
+ * outside its sandbox now, with the provider's own description of the device and how to change it
100
+ * (its report's `description` and `changeHint`).
101
+ */
102
+ export const escalationDeviceOffWhy = (description, changeHint = null) => `this device's provider does not allow running outside the sandbox now${reportTail(description, changeHint)}`;
103
+ /**
104
+ * Why an escalation cannot be reviewed because the owner of the machine the device runs on keeps
105
+ * running outside the sandbox off (the provider names that layer, support `limitedBy`), with the
106
+ * provider's description of the device and how to change it.
89
107
  */
90
- export const escalationDeviceOffWhy = (description) => `this device's provider does not allow running outside the sandbox now${description ? `: ${description.replace(/\.$/, "")}` : ""}`;
108
+ export const escalationOwnerOffWhy = (description, changeHint = null) => `the owner of the machine this device runs on does not allow running outside the sandbox on it now${reportTail(description, changeHint)}`;
91
109
  export const ESCALATION_ORG_OFF_WHY = "running commands outside the sandbox is off in this organization; an organization admin can allow running outside the sandbox";
92
110
  export const ESCALATION_PLATFORM_OFF_WHY = "running commands outside the sandbox is off on this platform; a super admin can allow running outside the sandbox";
93
111
  export const ESCALATION_NO_OUTSIDE_WHY = "this device is an instance that is itself the sandbox, so this device has no outside of its sandbox to run a command in";
94
112
  /**
95
113
  * The refusal text of an escalation that a layer's outside-sandbox setting blocks, the same for
96
114
  * every provider: an instance-boundary provider has no outside at all, whichever layer is off;
97
- * otherwise the platform or the org names who lifts it, and a provider whose support does not
98
- * allow it now says so with its description of the device (`description`, its report's).
115
+ * otherwise the platform or the org names who lifts it, and the owner of the machine or a provider
116
+ * whose support does not allow it now says so with the device's report (`description`, and
117
+ * `changeHint`: how to change it, in the provider's words).
99
118
  */
100
119
  export const escalationCeilingWhy = (input) => {
101
120
  if (input.boundary === "instance")
@@ -105,8 +124,10 @@ export const escalationCeilingWhy = (input) => {
105
124
  return ESCALATION_PLATFORM_OFF_WHY;
106
125
  case "org":
107
126
  return ESCALATION_ORG_OFF_WHY;
127
+ case "owner":
128
+ return escalationOwnerOffWhy(input.description ?? null, input.changeHint ?? null);
108
129
  default:
109
- return escalationDeviceOffWhy(input.description ?? null);
130
+ return escalationDeviceOffWhy(input.description ?? null, input.changeHint ?? null);
110
131
  }
111
132
  };
112
133
  /** Why an escalation cannot be reviewed: the runtime cannot run a command outside its sandbox now. */
@@ -26,7 +26,6 @@ import type { HeldDeviceContextEvidence } from "./permission-context-types.js";
26
26
  import { PermissionFacts } from "./permission-facts.js";
27
27
  import { DeviceProviders } from "./providers.js";
28
28
  import type { SandboxUseContext } from "./use-context.js";
29
- export { deviceNotFound } from "../devices/errors.js";
30
29
  export { SANDBOX_LOCK_PREFIX, SANDBOX_LOCK_TTL_MS, SandboxLockLostError, sandboxBusy, } from "./leases.js";
31
30
  export type { SandboxUseContext } from "./use-context.js";
32
31
  /** The third argument of the `withSandbox` callback. */
@@ -362,17 +361,23 @@ export declare class SandboxService {
362
361
  */
363
362
  ceilingLimits(orgId: string): Promise<SandboxLimits>;
364
363
  /**
365
- * Why a per-call host grant for each host is unavailable on the device, naming who can add it
366
- * (`hostGrantRefusal`; null: grantable): a network ask is made only for a grantable host, and
367
- * only on a device whose provider enforces an allowlist (`allowlist`, from its support).
364
+ * What a network ask may offer on the device (device-provider spec §6.3): why a per-call host
365
+ * grant is unavailable (`hostGrantRefusal`; null: grantable), why a host cannot join the
366
+ * device's own list (`deviceListAddRefusal`), whether it has a list of its own (`ownList`) and
367
+ * its hosts (`ownHosts`),
368
+ * where its provider applies new limits (`limitsApplyAt`) and its sandbox (`box.perCallHosts`:
369
+ * the provider's per-operation hosts).
368
370
  */
369
371
  hostRefusal(device: {
370
372
  orgId: string;
371
373
  deviceId: string;
372
374
  }): Promise<{
373
375
  refusal: (host: string) => string | null;
376
+ listAddRefusal: (host: string) => string | null;
374
377
  box: DeviceSandbox;
375
- allowlist: boolean;
378
+ ownList: boolean;
379
+ ownHosts: string[];
380
+ limitsApplyAt: "instance" | "fileSystem" | undefined;
376
381
  }>;
377
382
  /**
378
383
  * The limits state of a device's instance for its page (auto mode spec §4.2), read without a
@@ -397,12 +402,14 @@ export declare class SandboxService {
397
402
  private fsBound;
398
403
  /**
399
404
  * Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
400
- * cloud instance whose recorded network kind differs (never the mode alone), or whose recorded limits are more
401
- * permissive than `want` in any dimension (a host-only narrowing too, spec §124; a host-only
402
- * widening still reaches instances created afterwards), unless only a file reset could apply it
403
- * ({@link fsBound}). A provider bound to its file system still goes through the exclusive lease
404
- * once for a narrowing, so `applyLimits` records it as `unapplied` (the device is then unprobed
405
- * until the reset, never silently supported).
405
+ * cloud instance whose recorded network kind differs (never the mode alone), whose recorded
406
+ * limits are more permissive than `want` in any dimension (a host-only narrowing too, spec
407
+ * §124), or whose recorded allowlist lacks a host `want` allows (a host added to the device's or
408
+ * the org's list, device-provider spec §6.3; applied once, then recorded), unless only a file
409
+ * reset could apply it ({@link fsBound}). A provider bound to its file system still goes through
410
+ * the exclusive lease once for a narrowing, so `applyLimits` records it as `unapplied` (the
411
+ * device is then unprobed until the reset, never silently supported); an added host there only
412
+ * waits for the reset (`pendingFilesReset`).
406
413
  */
407
414
  private mustApply;
408
415
  /**
@@ -24,6 +24,12 @@ const failureKindOf = (error) => isDeviceRequestNotSent(error)
24
24
  : isSandboxScopeDeniedError(error)
25
25
  ? "denied"
26
26
  : "unsupported";
27
+ /**
28
+ * A provider found the instance gone before it sent the request (#643): a
29
+ * `DeviceRequestNotSentError` whose `cause` is a `SandboxGoneError`. Nothing ran, so the operation
30
+ * is a definite `not_sent` failure, and the instance is rebuilt like any gone one.
31
+ */
32
+ const goneBeforeSent = (error) => isDeviceRequestNotSent(error) && isSandboxGoneError(error.cause);
27
33
  /** The reservation fields a managed start's dispatch must match (its stable input). */
28
34
  const backgroundBinding = (args, instanceId) => ({
29
35
  taskId: args.taskId,
@@ -56,13 +62,12 @@ import { isKernelReadMethod, KernelReadNotAdmitted, KernelReadUnsupported, } fro
56
62
  import { SandboxLeases, SandboxLockLostError, sandboxBusy, } from "./leases.js";
57
63
  import { isKnownProvider, LegacyRetirementStore } from "./legacy-retirement.js";
58
64
  import { ManagedDeviceContextFailed } from "./managed-device-context.js";
59
- import { appliedOf, appliedWider, instanceLimitsJson, orgEffectiveHosts, providerLimits, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
65
+ import { appliedLacksHost, appliedOf, appliedWider, instanceLimitsJson, orgEffectiveHosts, providerLimits, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
60
66
  import { PermissionFacts } from "./permission-facts.js";
61
67
  import { reportOwed, supportOf } from "./permission-runtime-reports.js";
62
68
  import { DeviceProviders, servesDialIn } from "./providers.js";
63
69
  import { isDeviceRequestNotSent } from "./request-not-sent.js";
64
70
  import { SandboxProviderUnreachableError } from "./unreachable.js";
65
- export { deviceNotFound } from "../devices/errors.js";
66
71
  // Moved to leases.ts (phase C); re-exported for existing importers
67
72
  export { SANDBOX_LOCK_PREFIX, SANDBOX_LOCK_TTL_MS, SandboxLockLostError, sandboxBusy, } from "./leases.js";
68
73
  /** Margin (ms) of a holder record's TTL beyond the longest command: by then the in-sandbox limit has ended its commands. */
@@ -474,13 +479,23 @@ let SandboxService = class SandboxService {
474
479
  }, override);
475
480
  }
476
481
  /**
477
- * Why a per-call host grant for each host is unavailable on the device, naming who can add it
478
- * (`hostGrantRefusal`; null: grantable): a network ask is made only for a grantable host, and
479
- * only on a device whose provider enforces an allowlist (`allowlist`, from its support).
482
+ * What a network ask may offer on the device (device-provider spec §6.3): why a per-call host
483
+ * grant is unavailable (`hostGrantRefusal`; null: grantable), why a host cannot join the
484
+ * device's own list (`deviceListAddRefusal`), whether it has a list of its own (`ownList`) and
485
+ * its hosts (`ownHosts`),
486
+ * where its provider applies new limits (`limitsApplyAt`) and its sandbox (`box.perCallHosts`:
487
+ * the provider's per-operation hosts).
480
488
  */
481
489
  async hostRefusal(device) {
482
490
  const facts = await this.facts.deviceSandboxFacts(device.orgId, device.deviceId);
483
- return { refusal: facts.refusal, box: facts.box, allowlist: facts.allowlist };
491
+ return {
492
+ refusal: facts.refusal,
493
+ listAddRefusal: facts.listAddRefusal,
494
+ box: facts.box,
495
+ ownList: facts.ownList,
496
+ ownHosts: facts.ownHosts,
497
+ limitsApplyAt: facts.limitsApplyAt,
498
+ };
484
499
  }
485
500
  /**
486
501
  * The limits state of a device's instance for its page (auto mode spec §4.2), read without a
@@ -511,7 +526,12 @@ let SandboxService = class SandboxService {
511
526
  return { applied: null, effective, pendingNextUse: false, pendingFilesReset: false };
512
527
  }
513
528
  const rec = readInstanceLimits(row.instance_limits);
514
- const differs = row.provider === p.plugin && !sameApplied(rec.applied, effective);
529
+ // what mustApply applies at the next use: another kind, a host the instance allows that the
530
+ // desired list does not (a narrowing), or a desired host it lacks (a host added to a list)
531
+ const differs = row.provider === p.plugin &&
532
+ (!sameApplied(rec.applied, effective) ||
533
+ appliedWider(rec.applied, effective) ||
534
+ appliedLacksHost(rec.applied, effective));
515
535
  const fsBound = differs && row.fs_status === "ready" && this.fsBound(p, rec, effective);
516
536
  const hasInstance = row.handle !== null && (row.status === "running" || row.status === "suspended");
517
537
  return {
@@ -532,18 +552,20 @@ let SandboxService = class SandboxService {
532
552
  }
533
553
  /**
534
554
  * Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
535
- * cloud instance whose recorded network kind differs (never the mode alone), or whose recorded limits are more
536
- * permissive than `want` in any dimension (a host-only narrowing too, spec §124; a host-only
537
- * widening still reaches instances created afterwards), unless only a file reset could apply it
538
- * ({@link fsBound}). A provider bound to its file system still goes through the exclusive lease
539
- * once for a narrowing, so `applyLimits` records it as `unapplied` (the device is then unprobed
540
- * until the reset, never silently supported).
555
+ * cloud instance whose recorded network kind differs (never the mode alone), whose recorded
556
+ * limits are more permissive than `want` in any dimension (a host-only narrowing too, spec
557
+ * §124), or whose recorded allowlist lacks a host `want` allows (a host added to the device's or
558
+ * the org's list, device-provider spec §6.3; applied once, then recorded), unless only a file
559
+ * reset could apply it ({@link fsBound}). A provider bound to its file system still goes through
560
+ * the exclusive lease once for a narrowing, so `applyLimits` records it as `unapplied` (the
561
+ * device is then unprobed until the reset, never silently supported); an added host there only
562
+ * waits for the reset (`pendingFilesReset`).
541
563
  */
542
564
  mustApply(row, p, want) {
543
565
  const rec = readInstanceLimits(row.instance_limits);
544
566
  const target = appliedOf(want);
545
567
  const wider = appliedWider(rec.applied, target);
546
- if (sameApplied(rec.applied, target) && !wider)
568
+ if (sameApplied(rec.applied, target) && !wider && !appliedLacksHost(rec.applied, target))
547
569
  return false;
548
570
  if (!this.fsBound(p, rec, target))
549
571
  return true;
@@ -846,15 +868,20 @@ let SandboxService = class SandboxService {
846
868
  catch (err) {
847
869
  if (isFileSystemGoneError(err))
848
870
  throw await this.filesGone(env, p, e);
849
- if (isSandboxOperationOutcomeUnknownError(err) &&
850
- isSandboxGoneError(err.cause)) {
871
+ const notSentGone = goneBeforeSent(err);
872
+ if (notSentGone ||
873
+ (isSandboxOperationOutcomeUnknownError(err) &&
874
+ (isSandboxGoneError(err.cause) ||
875
+ goneBeforeSent(err.cause)))) {
851
876
  // gone after a durable dispatch: the outcome stays unknown and the call is never retried
852
- // under a new identity, but the gone instance is rebuilt on the kept files now, so the
853
- // holder's next call runs on it and is told of the restart (its seen record still names
854
- // the gone instance)
855
- this.log.info("sandbox instance is gone after a dispatched operation; recreating", {
856
- deviceId: env,
857
- });
877
+ // under a new identity. Gone before the request was sent (#643): the operation is
878
+ // recorded as not sent, and the call answers that nothing ran. Either way the gone
879
+ // instance is rebuilt on the kept files now, so the holder's next call (a retry
880
+ // included) runs on it and is told of the restart (its seen record still names the
881
+ // gone instance)
882
+ this.log.info(notSentGone
883
+ ? "sandbox instance is gone before an operation was sent; recreating"
884
+ : "sandbox instance is gone after a dispatched operation; recreating", { deviceId: env });
858
885
  const gone = { handle: e.handle, createdAt: e.createdAt };
859
886
  await this.leave(env, e);
860
887
  left = true;
@@ -2696,8 +2723,8 @@ let SandboxService = class SandboxService {
2696
2723
  destroyed_at: null,
2697
2724
  sweep_failed_at: null,
2698
2725
  });
2699
- // the device's effective limits apply at creation (a changed mode or network kind is applied
2700
- // on use, see applyLimits; other changes reach only instances created afterwards)
2726
+ // the device's effective limits apply at creation (a changed network kind or host list is
2727
+ // applied on use, see applyLimits; resources reach only instances created afterwards)
2701
2728
  const wanted = want;
2702
2729
  // the record says what is in force: a provider whose limits are fixed at its file system
2703
2730
  // records them with the file system, any other with the instance (spec §7.1)
@@ -34,8 +34,8 @@ export interface SetupGuideListEntry {
34
34
  plugin: string;
35
35
  guideId: string;
36
36
  place: SetupGuidePlace;
37
- /** The connector template of a `connector-template` guide; null for other places. */
38
- template: string | null;
37
+ /** The connector templates a `connector-template` guide covers; empty for other places. */
38
+ templates: string[];
39
39
  /** The section rendered: org admins get the admin guides, members their member sections. */
40
40
  audience: SetupGuideAudience;
41
41
  title: string;
@@ -85,8 +85,7 @@ export declare const setupWebPath: {
85
85
  template: (itemId: string) => string;
86
86
  };
87
87
  /**
88
- * The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines, shell
89
- * actions as `- [shell action <action>]` lines).
88
+ * The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines).
90
89
  */
91
90
  export declare function guideMarkdown(title: string, blocks: readonly SetupGuideBlock[]): string;
92
91
  /**