@capybara-hq/kernel 0.1.0-rc.68 → 0.1.0-rc.69

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 (215) hide show
  1. package/dist/admin/admin.module.js +2 -0
  2. package/dist/admin/health.service.d.ts +11 -4
  3. package/dist/admin/health.service.js +33 -17
  4. package/dist/background/poll.job.js +2 -2
  5. package/dist/background/tasks.service.d.ts +5 -5
  6. package/dist/background/tasks.service.js +9 -8
  7. package/dist/catalog/marketplaces.service.d.ts +1 -1
  8. package/dist/catalog/requests.service.js +1 -1
  9. package/dist/config/schema.d.ts +1 -1
  10. package/dist/config/schema.js +9 -9
  11. package/dist/conversations/conversations.controller.d.ts +8 -3
  12. package/dist/conversations/conversations.controller.js +8 -3
  13. package/dist/conversations/conversations.service.d.ts +33 -15
  14. package/dist/conversations/conversations.service.js +60 -10
  15. package/dist/conversations/events.d.ts +21 -41
  16. package/dist/conversations/events.js +57 -31
  17. package/dist/conversations/permission-profiles.controller.d.ts +6 -4
  18. package/dist/conversations/permission-profiles.service.d.ts +6 -4
  19. package/dist/ctx/create-ctx.d.ts +20 -1
  20. package/dist/ctx/create-ctx.js +77 -6
  21. package/dist/ctx/device-provider-check.d.ts +6 -2
  22. package/dist/ctx/device-provider-check.js +17 -2
  23. package/dist/db/kernel-schema.d.ts +10 -48
  24. package/dist/devices/access.d.ts +3 -4
  25. package/dist/devices/access.js +3 -4
  26. package/dist/devices/conversation-devices.d.ts +1 -3
  27. package/dist/devices/conversation-devices.js +2 -7
  28. package/dist/devices/device-projects.service.js +24 -29
  29. package/dist/devices/device-provider-selection.d.ts +5 -6
  30. package/dist/devices/device-provider-selection.js +8 -9
  31. package/dist/devices/devices.controller.d.ts +8 -21
  32. package/dist/devices/devices.controller.js +9 -34
  33. package/dist/devices/devices.module.js +6 -4
  34. package/dist/devices/devices.schemas.d.ts +1 -5
  35. package/dist/devices/devices.schemas.js +1 -5
  36. package/dist/devices/devices.service.d.ts +84 -147
  37. package/dist/devices/devices.service.js +134 -229
  38. package/dist/devices/dto.d.ts +5 -32
  39. package/dist/devices/dto.js +5 -37
  40. package/dist/devices/errors.d.ts +6 -5
  41. package/dist/devices/errors.js +7 -8
  42. package/dist/devices/project-rules.d.ts +9 -11
  43. package/dist/devices/project-rules.js +7 -7
  44. package/dist/devices/working-root.d.ts +3 -6
  45. package/dist/devices/working-root.js +3 -8
  46. package/dist/dial-in/access.d.ts +23 -0
  47. package/dist/dial-in/access.js +64 -0
  48. package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
  49. package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
  50. package/dist/dial-in/auth.module.d.ts +7 -0
  51. package/dist/dial-in/auth.module.js +27 -0
  52. package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
  53. package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
  54. package/dist/dial-in/dial-in.module.d.ts +9 -0
  55. package/dist/dial-in/dial-in.module.js +37 -0
  56. package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
  57. package/dist/{local-devices → dial-in}/dto.js +14 -2
  58. package/dist/dial-in/envelope.d.ts +95 -0
  59. package/dist/dial-in/envelope.js +89 -0
  60. package/dist/dial-in/gateway.d.ts +214 -0
  61. package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
  62. package/dist/dial-in/handlers.d.ts +47 -0
  63. package/dist/dial-in/handlers.js +84 -0
  64. package/dist/dial-in/machines.d.ts +155 -0
  65. package/dist/dial-in/machines.js +383 -0
  66. package/dist/dial-in/relay.d.ts +135 -0
  67. package/dist/dial-in/relay.js +444 -0
  68. package/dist/dial-in/relay.module.d.ts +7 -0
  69. package/dist/dial-in/relay.module.js +24 -0
  70. package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
  71. package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
  72. package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
  73. package/dist/{local-devices → dial-in}/targets.js +3 -48
  74. package/dist/errors.d.ts +8 -27
  75. package/dist/errors.js +8 -27
  76. package/dist/extensions/bootstrap.d.ts +5 -0
  77. package/dist/extensions/bootstrap.js +10 -1
  78. package/dist/extensions/extensions.module.js +6 -0
  79. package/dist/extensions/host.d.ts +6 -0
  80. package/dist/extensions/host.js +12 -2
  81. package/dist/extensions/permission-set.d.ts +15 -1
  82. package/dist/extensions/permission-set.js +11 -1
  83. package/dist/extensions/permission-view.d.ts +1 -1
  84. package/dist/extensions/permission-view.js +4 -1
  85. package/dist/http/api.module.js +4 -4
  86. package/dist/http/gateway-routes.d.ts +1 -1
  87. package/dist/http/gateway-routes.js +1 -1
  88. package/dist/http/meta.controller.js +1 -1
  89. package/dist/identity/settings.d.ts +1 -1
  90. package/dist/identity/settings.js +6 -8
  91. package/dist/infra/config/kernel-config.service.js +2 -2
  92. package/dist/infra/outbox/registry.d.ts +0 -14
  93. package/dist/infra/outbox/registry.js +0 -15
  94. package/dist/infra/throttler/named-throttlers.d.ts +1 -1
  95. package/dist/infra/throttler/named-throttlers.js +1 -1
  96. package/dist/kernel.module.js +0 -3
  97. package/dist/orgs/settings.service.js +5 -10
  98. package/dist/overrides.d.ts +0 -4
  99. package/dist/overrides.js +0 -2
  100. package/dist/platform/exclusions.js +5 -5
  101. package/dist/platform/ops/admin.ops.js +1 -1
  102. package/dist/platform/ops/conversations.ops.js +5 -2
  103. package/dist/platform/ops/devices.ops.js +11 -24
  104. package/dist/platform/ops/inbox.ops.js +1 -1
  105. package/dist/roles/gateway-role.d.ts +3 -3
  106. package/dist/roles/gateway-role.js +4 -4
  107. package/dist/roles/gateway.module.d.ts +1 -1
  108. package/dist/roles/gateway.module.js +5 -5
  109. package/dist/runtime/context/device-paths.d.ts +4 -1
  110. package/dist/runtime/context/permission-profile.js +5 -5
  111. package/dist/runtime/maintenance.d.ts +2 -5
  112. package/dist/runtime/maintenance.js +9 -19
  113. package/dist/runtime/project/knowledge.js +4 -5
  114. package/dist/runtime/project/knowledge.service.js +2 -1
  115. package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
  116. package/dist/sandbox/cloud-permission-snapshot.js +1 -3
  117. package/dist/sandbox/device-reports.d.ts +74 -14
  118. package/dist/sandbox/device-reports.js +190 -33
  119. package/dist/sandbox/device-reports.module.d.ts +7 -0
  120. package/dist/sandbox/device-reports.module.js +25 -0
  121. package/dist/sandbox/device-sandbox.d.ts +39 -41
  122. package/dist/sandbox/device-sandbox.js +44 -83
  123. package/dist/sandbox/kernel-read.d.ts +2 -2
  124. package/dist/sandbox/legacy-retirement.d.ts +11 -59
  125. package/dist/sandbox/legacy-retirement.js +34 -186
  126. package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
  127. package/dist/sandbox/legacy-retirement.module.js +2 -2
  128. package/dist/sandbox/managed-device-context.d.ts +16 -4
  129. package/dist/sandbox/managed-device-context.js +25 -8
  130. package/dist/sandbox/managed-device-context.module.js +4 -0
  131. package/dist/sandbox/modes.d.ts +3 -12
  132. package/dist/sandbox/modes.js +2 -14
  133. package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
  134. package/dist/{local-devices → sandbox}/network-grants.js +4 -49
  135. package/dist/sandbox/operation-authority-types.d.ts +2 -1
  136. package/dist/sandbox/operation-authority.d.ts +6 -20
  137. package/dist/sandbox/operation-authority.js +43 -104
  138. package/dist/sandbox/operation-authority.module.js +1 -1
  139. package/dist/sandbox/operation-intents.d.ts +4 -1
  140. package/dist/sandbox/operation-intents.js +11 -2
  141. package/dist/sandbox/operation-reconcile.job.js +2 -4
  142. package/dist/sandbox/permission-availability.d.ts +6 -7
  143. package/dist/sandbox/permission-availability.js +7 -10
  144. package/dist/sandbox/permission-call-grants.d.ts +2 -1
  145. package/dist/sandbox/permission-call-grants.js +1 -7
  146. package/dist/sandbox/permission-call-types.d.ts +4 -4
  147. package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
  148. package/dist/sandbox/permission-ceiling-writes.js +8 -35
  149. package/dist/sandbox/permission-config-publication.d.ts +9 -1
  150. package/dist/sandbox/permission-config-publication.js +29 -21
  151. package/dist/sandbox/permission-context-types.d.ts +17 -10
  152. package/dist/sandbox/permission-facts.d.ts +98 -95
  153. package/dist/sandbox/permission-facts.js +160 -314
  154. package/dist/sandbox/permission-instance-writes.d.ts +23 -37
  155. package/dist/sandbox/permission-instance-writes.js +44 -121
  156. package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
  157. package/dist/sandbox/permission-runtime-reports.js +105 -122
  158. package/dist/sandbox/providers.d.ts +26 -38
  159. package/dist/sandbox/providers.js +36 -18
  160. package/dist/sandbox/request-not-sent.d.ts +2 -13
  161. package/dist/sandbox/request-not-sent.js +2 -13
  162. package/dist/sandbox/review/permission-candidate.d.ts +13 -8
  163. package/dist/sandbox/review/permission-candidate.js +38 -48
  164. package/dist/sandbox/sandbox.module.js +7 -3
  165. package/dist/sandbox/sandbox.service.d.ts +49 -59
  166. package/dist/sandbox/sandbox.service.js +139 -259
  167. package/dist/schedules/fire.d.ts +15 -6
  168. package/dist/schedules/fire.js +27 -13
  169. package/dist/schedules/grant-rules.js +1 -1
  170. package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
  171. package/dist/schedules/scheduled-tasks.service.js +1 -4
  172. package/dist/schedules/schedules.module.js +5 -3
  173. package/dist/skills/invoke.d.ts +1 -1
  174. package/dist/skills/invoke.js +2 -3
  175. package/dist/tools/approvals.service.d.ts +8 -5
  176. package/dist/tools/approvals.service.js +5 -5
  177. package/dist/tools/builtins/sandbox/bash.js +1 -2
  178. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  179. package/dist/tools/builtins/sandbox/common.js +37 -38
  180. package/dist/tools/network-asks.d.ts +19 -22
  181. package/dist/tools/network-asks.js +15 -21
  182. package/dist/tools/pipeline.d.ts +6 -7
  183. package/dist/tools/pipeline.js +17 -21
  184. package/dist/tools/tools.module.js +3 -7
  185. package/package.json +3 -4
  186. package/src/migrations/0177_dial_in_contract.sql +32 -0
  187. package/dist/local-devices/device-auth.module.d.ts +0 -7
  188. package/dist/local-devices/device-auth.module.js +0 -25
  189. package/dist/local-devices/device-policy.service.d.ts +0 -213
  190. package/dist/local-devices/device-policy.service.js +0 -605
  191. package/dist/local-devices/instance-bindings.d.ts +0 -82
  192. package/dist/local-devices/instance-bindings.js +0 -307
  193. package/dist/local-devices/local-device-gateway.d.ts +0 -153
  194. package/dist/local-devices/local-device-provider.d.ts +0 -122
  195. package/dist/local-devices/local-device-provider.js +0 -326
  196. package/dist/local-devices/local-devices.module.d.ts +0 -31
  197. package/dist/local-devices/local-devices.module.js +0 -100
  198. package/dist/local-devices/machines.d.ts +0 -211
  199. package/dist/local-devices/machines.js +0 -766
  200. package/dist/local-devices/owner-report.d.ts +0 -81
  201. package/dist/local-devices/owner-report.js +0 -150
  202. package/dist/local-devices/owner-reports.d.ts +0 -48
  203. package/dist/local-devices/owner-reports.js +0 -208
  204. package/dist/local-devices/policy-op-jobs.d.ts +0 -15
  205. package/dist/local-devices/policy-op-jobs.js +0 -12
  206. package/dist/local-devices/policy-summary.d.ts +0 -102
  207. package/dist/local-devices/policy-summary.js +0 -155
  208. package/dist/local-devices/relay.d.ts +0 -166
  209. package/dist/local-devices/relay.js +0 -559
  210. package/dist/tools/device-op-resolver.d.ts +0 -34
  211. package/dist/tools/device-op-resolver.js +0 -120
  212. /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
  213. /package/dist/{local-devices → dial-in}/keys.js +0 -0
  214. /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
  215. /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
@@ -1,155 +0,0 @@
1
- import { coversHost } from "../sandbox/modes.js";
2
- import { isExecutionMethod, isFullExecutionScope } from "../sandbox/operation-authority-types.js";
3
- const KNOWN_FEATURES = [
4
- "networkReport",
5
- "policyOp",
6
- "policyOpId",
7
- "projects",
8
- ];
9
- /**
10
- * The known features in `v` (a hello's `features` or the stored column), in a fixed order and
11
- * deduped; anything else (unknown names, a non-array) is dropped.
12
- */
13
- export function deviceFeaturesOf(v) {
14
- if (!Array.isArray(v))
15
- return [];
16
- return KNOWN_FEATURES.filter((f) => v.includes(f));
17
- }
18
- /**
19
- * `v` as a local policy summary (auto mode spec §4.1), or null when it is absent or not a valid
20
- * one. The device is the authority on its policy: the kernel only keeps what it last said, for the
21
- * device page and the `device_paths` event, never to decide what a command may reach.
22
- */
23
- export function localPolicyOf(v) {
24
- if (typeof v !== "object" || v === null || Array.isArray(v))
25
- return null;
26
- const o = v;
27
- if (!Array.isArray(o.allowedDomains))
28
- return null;
29
- if (!o.allowedDomains.every((d) => typeof d === "string"))
30
- return null;
31
- return { allowedDomains: [...o.allowedDomains] };
32
- }
33
- /** The {@link LocalPolicyDiff} from `prev` to `next`; null when nothing the owner sets changed. */
34
- export function localPolicyDiff(prev, next) {
35
- const before = new Set(prev.allowedDomains);
36
- const after = new Set(next.allowedDomains);
37
- const d = {
38
- add: [...after].filter((h) => !before.has(h)).sort(),
39
- remove: [...before].filter((h) => !after.has(h)).sort(),
40
- };
41
- return d.add.length > 0 || d.remove.length > 0 ? d : null;
42
- }
43
- /** The pending ops stored on a machine row (malformed entries dropped). */
44
- export function pendingPolicyOpsOf(v) {
45
- if (!Array.isArray(v))
46
- return [];
47
- const hosts = (x) => Array.isArray(x) ? x.filter((h) => typeof h === "string") : [];
48
- const out = [];
49
- for (const e of v) {
50
- if (typeof e !== "object" || e === null)
51
- continue;
52
- const o = e;
53
- if (typeof o.id !== "string" || typeof o.until !== "number")
54
- continue;
55
- if (typeof o.sentAt !== "number" || typeof o.resolveAt !== "number")
56
- continue;
57
- if (o.status !== "sent" && o.status !== "unknown")
58
- continue;
59
- const src = o.source;
60
- if (typeof src !== "object" || src === null || typeof src.accountId !== "string")
61
- continue;
62
- if (src.via !== "web" && src.via !== "im")
63
- continue;
64
- const rep = o.reported;
65
- const outcome = typeof rep === "object" && rep !== null ? rep.outcome : undefined;
66
- const reported = outcome === "applied" ||
67
- outcome === "refused" ||
68
- outcome === "absent" ||
69
- outcome === "interrupted"
70
- ? { outcome }
71
- : undefined;
72
- out.push({
73
- id: o.id,
74
- remove: hosts(o.remove),
75
- ...ownerNarrowingOf(o.ownerCeiling),
76
- source: { accountId: src.accountId, via: src.via },
77
- ...(typeof o.actorTokenId === "string" && { actorTokenId: o.actorTokenId }),
78
- status: o.status,
79
- sentAt: o.sentAt,
80
- resolveAt: o.resolveAt,
81
- until: o.until,
82
- ...(reported !== undefined && { reported }),
83
- });
84
- }
85
- return out;
86
- }
87
- /**
88
- * Whether the change of `op` is in `policy`: its hosts removed. Tells an op the machine logged only
89
- * as `started` (it stopped between the log and the answer) that was written from one that was not.
90
- */
91
- export function opVisibleIn(op, policy) {
92
- return !op.remove.some((h) => policy.allowedDomains.includes(h));
93
- }
94
- /** A stored op's owner narrowing: kept only while it narrows (anything wider is dropped). */
95
- function ownerNarrowingOf(v) {
96
- if (typeof v !== "object" || v === null)
97
- return {};
98
- const o = v;
99
- const narrowing = {
100
- ...(o.outsideSandbox === false && { outsideSandbox: false }),
101
- ...(o.network === "allowlist" && { network: "allowlist" }),
102
- ...(o.restrictedProjectReach === "workspace" && {
103
- restrictedProjectReach: "workspace",
104
- }),
105
- };
106
- return Object.keys(narrowing).length > 0 ? { ownerCeiling: narrowing } : {};
107
- }
108
- /**
109
- * Whether a v3 owner report's change from `before` to `after` is what the platform's `op` asked
110
- * for (the machine's own report of it, arriving before the op's answer): something changed, and
111
- * every changed fact is a narrowing the op carried, to the value it asked for. A widening is never
112
- * an op's.
113
- */
114
- export function opExplainsOwnerChange(op, before, after) {
115
- const outsideChanged = before.outsideSandbox !== after.outsideSandbox;
116
- const reachChanged = before.restrictedProjectReach !== after.restrictedProjectReach;
117
- const networkChanged = (before.network ?? after.network) !== (after.network ?? before.network);
118
- if (!outsideChanged && !reachChanged && !networkChanged)
119
- return false;
120
- if (outsideChanged && (op.ownerCeiling?.outsideSandbox !== false || after.outsideSandbox))
121
- return false;
122
- if (networkChanged && (op.ownerCeiling?.network !== "allowlist" || after.network !== "allowlist"))
123
- return false;
124
- if (reachChanged &&
125
- (op.ownerCeiling?.restrictedProjectReach !== "workspace" ||
126
- after.restrictedProjectReach !== "workspace"))
127
- return false;
128
- return true;
129
- }
130
- /**
131
- * Whether `diff` is what the platform's `op` did (its answer, or the machine's own report of it
132
- * before the answer was recorded): hosts within the op's. The device page then lists the change
133
- * once, as the platform's.
134
- */
135
- export function opExplains(op, diff) {
136
- // the platform never adds a host: a diff with an addition is the owner's own
137
- if (diff.add.length > 0)
138
- return false;
139
- return diff.remove.every((h) => op.remove.includes(h));
140
- }
141
- /**
142
- * Revoke only authority removed from a starting grant; explicit additions are not owner baseline.
143
- * The summary carries the sandbox allowlist only: the owner ceiling (outside the sandbox, the
144
- * reach) is revoked by the owner report's writer (`ownerReportRevokes`).
145
- */
146
- export function ownerPolicyRevokes(next, scope, method, grantedHosts) {
147
- if (!next)
148
- return true;
149
- if (!("profile" in scope) || isFullExecutionScope(scope))
150
- return false;
151
- if (!isExecutionMethod(method) || scope.network.kind !== "allowlist")
152
- return false;
153
- return scope.network.hosts.some((host) => !next.allowedDomains.some((pattern) => coversHost(pattern, host)) &&
154
- !grantedHosts.includes(host));
155
- }
@@ -1,166 +0,0 @@
1
- import { type DeviceOp, type DeviceOperation, type DeviceOpResults, DeviceProtocolError, type DeviceStopArgs, type ExtensionContext } from "@capybara-hq/plugin-sdk";
2
- import type { Redis } from "ioredis";
3
- import { ApiError } from "../errors.js";
4
- import { KernelConfigService } from "../infra/config/kernel-config.service.js";
5
- import { LockService } from "../infra/lock/lock.service.js";
6
- import type { KernelLogger } from "../log.js";
7
- import { DeviceRequestNotSentError, isDeviceRequestNotSent } from "../sandbox/request-not-sent.js";
8
- import { type DeviceConnectionInfo, DeviceTargets } from "./targets.js";
9
- /** The device's connected machine is not connected (no replica holds its lease). */
10
- export declare const deviceOffline: () => ApiError;
11
- export { machineRevoked } from "../devices/errors.js";
12
- /** The text a machine's `policy` refusal reaches the model with. */
13
- export declare const POLICY_REFUSAL_PREFIX = "Refused by the machine's local policy: ";
14
- /** The text a machine's `error` result reaches the model with (ruling R28). */
15
- export declare const ON_MACHINE_PREFIX = "On the connected machine: ";
16
- /**
17
- * The text of a staged (protocol 4) request refused because the machine's connection changed.
18
- * Only an output read has an offset to retry from; every other operation is simply retried.
19
- */
20
- export declare const connectionChangedMessage: (op: string) => string;
21
- export { DeviceRequestNotSentError, isDeviceRequestNotSent };
22
- /**
23
- * The kernel-internal field of a queued `stop` naming the machine it is for (stripped by the holder
24
- * before the frame goes out; a frame for another machine is dropped).
25
- */
26
- export declare const STOP_MACHINE: "machineId";
27
- /** The longest one lease check of a waiting caller may take before it counts as "unknown". */
28
- export declare const LEASE_CHECK_TIMEOUT_MS = 2000;
29
- /** How often a waiting caller checks that a replica still holds the machine's connection. */
30
- export declare const HOLDER_POLL_MS = 5000;
31
- /**
32
- * How much longer than the caller's wait a queued request lives: giving up must still find an
33
- * untaken request on the list (an expired one would look taken and get a needless cancel).
34
- */
35
- export declare const LIST_TTL_MARGIN_MS = 30000;
36
- /**
37
- * The kernel-internal fields the gateway adds to what it stores for a staged result, next to the
38
- * device's frame: the connection it arrived on, that connection's capacity and, only on the
39
- * gateway's own refusal of a request queued for another connection, {@link GATEWAY_NOT_SENT}. The
40
- * device's frame is parsed strictly (unknown keys refused), so a device can never set them.
41
- */
42
- export declare const GATEWAY_NOT_SENT: "notSent";
43
- /**
44
- * A staged request refused because it was not sent, outside the operations held under an operation
45
- * identity (a policy control, a status read): a protocol error that also says nothing ran, so a
46
- * caller can record it as never received instead of unknown ({@link wasDeviceRequestNotSent}).
47
- */
48
- export declare class DeviceRequestNotSentProtocolError extends DeviceProtocolError {
49
- readonly notSent: true;
50
- }
51
- /** Any staged request the kernel knows was never sent to the machine (held or not). */
52
- export declare const wasDeviceRequestNotSent: (e: unknown) => boolean;
53
- export interface DeviceCallOptions {
54
- /** How long the machine may take for the operation (sent to it as `deadlineMs`). */
55
- deadlineMs: number;
56
- /** The caller's signal: aborting gives the request up and rejects. */
57
- signal: AbortSignal;
58
- /** Internal authenticated lease/capacity fence; never part of caller operation arguments. */
59
- connection?: {
60
- connectionId: string;
61
- maxFrameBytes: number;
62
- };
63
- }
64
- /**
65
- * The caller side of the device relay (environments spec §13.4). A request goes onto the
66
- * device's Redis list (`capk:device-req:<deviceId>`) and is announced on
67
- * `device.req.<deviceId>`; whichever gateway replica holds the machine's lease drains the
68
- * list and forwards the frames to the machine.
69
- *
70
- * **The holder's half of the wire** (Task 6 follows it): items on the list are `KernelReq` or
71
- * `KernelCancel` frames as JSON text, to be parsed with `parseLegacyDeviceFrame(item, "kernel")`; the
72
- * nudge's payload is `{ id }`. For each `res` frame the machine sends, the holder writes the frame
73
- * (the JSON text as validated by `parseLegacyDeviceFrame(…, "device")`) under
74
- * `capk:device-res:<requestId>` with a TTL and publishes the same frame object on
75
- * `device.res.<requestId>`.
76
- *
77
- * The caller subscribes to its result topic before pushing and reads the result key once after,
78
- * and once more before giving up (the run-abort pattern; a publish lost while the subscriber
79
- * reconnects is still found). It waits within its own call for at most `deadlineMs` plus
80
- * `devices.local.reconnectGraceSeconds`; when the lease disappears meanwhile (checked every
81
- * {@link HOLDER_POLL_MS}) the wait ends at most one grace later, and when the machine is connected
82
- * again as another run of its program (`programRunId`) it ends at that poll with
83
- * {@link DeviceProgramRestartedError}: the old run's kept results died with it. A result produced
84
- * while the machine was disconnected arrives after it reconnects. Giving up (grace, abort, a bad result)
85
- * removes the request from the list, or queues a `cancel` when the machine already took it
86
- * (ruling R15). Nothing is kept in process memory beyond the call.
87
- */
88
- export declare class LocalDeviceRelay {
89
- private readonly redis;
90
- private readonly bus;
91
- private readonly locks;
92
- private readonly config;
93
- private readonly log;
94
- private readonly targets;
95
- constructor(redis: Redis, bus: ExtensionContext["bus"], locks: Pick<LockService, "holderOf">, config: Pick<KernelConfigService, "get">, log: Pick<KernelLogger, "warn">, targets: Pick<DeviceTargets, "state" | "current">);
96
- /** Whether a gateway replica holds the machine's connection now. */
97
- holderLive(deviceId: string): Promise<boolean>;
98
- /**
99
- * The negotiated transport of the device's connection for the platform's own controls (policy
100
- * ops): every connection speaks protocol 4, so this is {@link connection} (a missing or unready
101
- * one throws its typed error).
102
- */
103
- stagedTransport(deviceId: string): Promise<{
104
- connectionId: string;
105
- maxFrameBytes: number;
106
- } | null>;
107
- /**
108
- * The negotiated transport of the machine's current connection, for a staged call. Liveness is
109
- * checked first (ruling R27): no holder throws `device.not_found` for a deleted device,
110
- * `device.forbidden` for a revoked machine and `device.offline` otherwise. It carries the program
111
- * run the connection's hello named (`programRunId`, when reported): kernel-internal evidence a
112
- * staged call keeps, never put into a frame. Every staged call reads its connection here.
113
- */
114
- connection(deviceId: string): Promise<DeviceConnectionInfo>;
115
- /**
116
- * Queues `stop` for the machine without waiting for an answer (ruling R14). The caller checks
117
- * {@link holderLive} first; the frame waits on the list for the grace like any request. It is
118
- * fenced to the machine `machineId` ({@link STOP_MACHINE}): a holder hands it only to that
119
- * machine's connection (on a staged connection as a protocol 4 `stop`, across a socket blip
120
- * too), never to a newer machine of the device. Only `stop` is ever queued this way: a broad
121
- * kill (`killAll` / `killTagged`) has no frame on protocol 4.
122
- */
123
- send(deviceId: string, op: "stop", args: DeviceStopArgs, deadlineMs: number, machineId: string): Promise<void>;
124
- /**
125
- * Runs `op` on the device's machine and returns its validated result. Throws
126
- * `device.offline` when no replica holds the machine at send time or when the wait ran
127
- * out, but `device.forbidden` ({@link machineRevoked}) when the machine was revoked and
128
- * `device.not_found` when the device was deleted (checked whenever the connection is
129
- * missing, ruling R27); the machine's failures map to `SandboxGoneError` (`gone`),
130
- * `FileSystemGoneError` (`fs_gone`) or a `ToolError` (`policy`, and `error` prefixed
131
- * {@link ON_MACHINE_PREFIX}); an invalid answer throws a `DeviceProtocolError`. On abort the
132
- * abort reason is thrown.
133
- */
134
- call<Op extends DeviceOp>(deviceId: string, op: Op, args: unknown, opts: DeviceCallOptions): Promise<DeviceOpResults[Op]>;
135
- /**
136
- * Runs a protocol 4 operation on the device's machine over its current staged connection and
137
- * returns its validated result; the request is checked against the protocol 4 codec first.
138
- */
139
- callV3(deviceId: string, op: DeviceOperation, args: Record<string, unknown>, opts: DeviceCallOptions): Promise<unknown>;
140
- private callWithCodec;
141
- /** {@link holderLive}, or undefined when it takes longer than {@link LEASE_CHECK_TIMEOUT_MS}. */
142
- private leaseCheck;
143
- /**
144
- * The device's state ({@link DeviceTargets}), or undefined when it cannot be read within
145
- * {@link LEASE_CHECK_TIMEOUT_MS} (a failure only logs: the caller keeps its other rules).
146
- */
147
- private targetState;
148
- /** The error of a state that never comes back; undefined for `active` or unknown. */
149
- private goneError;
150
- private graceMs;
151
- private push;
152
- /** Announces new frames to the holder; a lost nudge is picked up on the holder's next drain. */
153
- private nudge;
154
- /** Removes the request from the list, or queues a cancel when the machine took it (R15). */
155
- private giveUp;
156
- /** Runs a side step whose failure must not replace the call's outcome: logged, swallowed. */
157
- private quietly;
158
- /**
159
- * A stored / published `res` frame for request `id`, or the protocol error it carries. A staged
160
- * frame carries the tag of the connection it arrived on (added by the gateway); a fenced
161
- * operation ({@link connectionFenced}) accepts only its request's connection, any other staged
162
- * operation a well-formed tag, and the frame is parsed against that connection's capacity.
163
- */
164
- private parseRes;
165
- private resultOf;
166
- }