@capybara-hq/kernel 0.1.0-rc.67 → 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 (226) hide show
  1. package/bootstrap.json +9 -1
  2. package/dist/admin/admin.module.js +2 -0
  3. package/dist/admin/health.service.d.ts +11 -4
  4. package/dist/admin/health.service.js +33 -17
  5. package/dist/background/poll.job.js +2 -2
  6. package/dist/background/tasks.service.d.ts +5 -5
  7. package/dist/background/tasks.service.js +9 -8
  8. package/dist/catalog/credential-key.d.ts +10 -0
  9. package/dist/catalog/credential-key.js +28 -0
  10. package/dist/catalog/marketplaces.service.d.ts +1 -1
  11. package/dist/catalog/plugin-upgrade.js +1 -19
  12. package/dist/catalog/requests.service.js +1 -1
  13. package/dist/config/schema.d.ts +1 -1
  14. package/dist/config/schema.js +9 -9
  15. package/dist/conversations/conversations.controller.d.ts +8 -3
  16. package/dist/conversations/conversations.controller.js +8 -3
  17. package/dist/conversations/conversations.service.d.ts +33 -15
  18. package/dist/conversations/conversations.service.js +60 -10
  19. package/dist/conversations/events.d.ts +21 -41
  20. package/dist/conversations/events.js +57 -31
  21. package/dist/conversations/permission-profiles.controller.d.ts +6 -4
  22. package/dist/conversations/permission-profiles.service.d.ts +6 -4
  23. package/dist/ctx/create-ctx.d.ts +20 -1
  24. package/dist/ctx/create-ctx.js +77 -6
  25. package/dist/ctx/device-provider-check.d.ts +6 -2
  26. package/dist/ctx/device-provider-check.js +17 -2
  27. package/dist/db/kernel-schema.d.ts +10 -48
  28. package/dist/devices/access.d.ts +3 -4
  29. package/dist/devices/access.js +3 -4
  30. package/dist/devices/conversation-devices.d.ts +1 -3
  31. package/dist/devices/conversation-devices.js +2 -7
  32. package/dist/devices/device-projects.service.js +24 -29
  33. package/dist/devices/device-provider-selection.d.ts +5 -6
  34. package/dist/devices/device-provider-selection.js +8 -9
  35. package/dist/devices/devices.controller.d.ts +8 -21
  36. package/dist/devices/devices.controller.js +9 -34
  37. package/dist/devices/devices.module.js +6 -4
  38. package/dist/devices/devices.schemas.d.ts +1 -5
  39. package/dist/devices/devices.schemas.js +1 -5
  40. package/dist/devices/devices.service.d.ts +84 -147
  41. package/dist/devices/devices.service.js +134 -229
  42. package/dist/devices/dto.d.ts +5 -32
  43. package/dist/devices/dto.js +5 -37
  44. package/dist/devices/errors.d.ts +6 -5
  45. package/dist/devices/errors.js +7 -8
  46. package/dist/devices/project-rules.d.ts +9 -11
  47. package/dist/devices/project-rules.js +7 -7
  48. package/dist/devices/working-root.d.ts +3 -6
  49. package/dist/devices/working-root.js +3 -8
  50. package/dist/dial-in/access.d.ts +23 -0
  51. package/dist/dial-in/access.js +64 -0
  52. package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
  53. package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
  54. package/dist/dial-in/auth.module.d.ts +7 -0
  55. package/dist/dial-in/auth.module.js +27 -0
  56. package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
  57. package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
  58. package/dist/dial-in/dial-in.module.d.ts +9 -0
  59. package/dist/dial-in/dial-in.module.js +37 -0
  60. package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
  61. package/dist/{local-devices → dial-in}/dto.js +14 -2
  62. package/dist/dial-in/envelope.d.ts +95 -0
  63. package/dist/dial-in/envelope.js +89 -0
  64. package/dist/dial-in/gateway.d.ts +214 -0
  65. package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
  66. package/dist/dial-in/handlers.d.ts +47 -0
  67. package/dist/dial-in/handlers.js +84 -0
  68. package/dist/dial-in/machines.d.ts +155 -0
  69. package/dist/dial-in/machines.js +383 -0
  70. package/dist/dial-in/relay.d.ts +135 -0
  71. package/dist/dial-in/relay.js +444 -0
  72. package/dist/dial-in/relay.module.d.ts +7 -0
  73. package/dist/dial-in/relay.module.js +24 -0
  74. package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
  75. package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
  76. package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
  77. package/dist/{local-devices → dial-in}/targets.js +3 -48
  78. package/dist/errors.d.ts +8 -27
  79. package/dist/errors.js +8 -27
  80. package/dist/extensions/bootstrap.d.ts +5 -0
  81. package/dist/extensions/bootstrap.js +10 -1
  82. package/dist/extensions/extensions.module.js +6 -0
  83. package/dist/extensions/host.d.ts +6 -0
  84. package/dist/extensions/host.js +12 -2
  85. package/dist/extensions/permission-set.d.ts +15 -1
  86. package/dist/extensions/permission-set.js +11 -1
  87. package/dist/extensions/permission-view.d.ts +1 -1
  88. package/dist/extensions/permission-view.js +4 -1
  89. package/dist/http/api.module.js +4 -4
  90. package/dist/http/gateway-routes.d.ts +1 -1
  91. package/dist/http/gateway-routes.js +1 -1
  92. package/dist/http/meta.controller.js +1 -1
  93. package/dist/identity/settings.d.ts +1 -1
  94. package/dist/identity/settings.js +6 -8
  95. package/dist/infra/config/kernel-config.service.js +2 -2
  96. package/dist/infra/outbox/registry.d.ts +0 -14
  97. package/dist/infra/outbox/registry.js +0 -15
  98. package/dist/infra/throttler/named-throttlers.d.ts +1 -1
  99. package/dist/infra/throttler/named-throttlers.js +1 -1
  100. package/dist/kernel.module.js +0 -3
  101. package/dist/orgs/settings.service.js +5 -10
  102. package/dist/overrides.d.ts +0 -4
  103. package/dist/overrides.js +0 -2
  104. package/dist/platform/exclusions.js +5 -5
  105. package/dist/platform/ops/admin.ops.js +1 -1
  106. package/dist/platform/ops/conversations.ops.js +5 -2
  107. package/dist/platform/ops/devices.ops.js +11 -24
  108. package/dist/platform/ops/inbox.ops.js +1 -1
  109. package/dist/roles/gateway-role.d.ts +3 -3
  110. package/dist/roles/gateway-role.js +4 -4
  111. package/dist/roles/gateway.module.d.ts +1 -1
  112. package/dist/roles/gateway.module.js +5 -5
  113. package/dist/runtime/context/device-paths.d.ts +4 -1
  114. package/dist/runtime/context/permission-profile.js +5 -5
  115. package/dist/runtime/maintenance.d.ts +2 -5
  116. package/dist/runtime/maintenance.js +9 -19
  117. package/dist/runtime/project/knowledge.js +4 -5
  118. package/dist/runtime/project/knowledge.service.js +2 -1
  119. package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
  120. package/dist/sandbox/cloud-permission-snapshot.js +1 -3
  121. package/dist/sandbox/device-reports.d.ts +74 -14
  122. package/dist/sandbox/device-reports.js +190 -33
  123. package/dist/sandbox/device-reports.module.d.ts +7 -0
  124. package/dist/sandbox/device-reports.module.js +25 -0
  125. package/dist/sandbox/device-sandbox.d.ts +39 -41
  126. package/dist/sandbox/device-sandbox.js +44 -83
  127. package/dist/sandbox/kernel-read.d.ts +2 -2
  128. package/dist/sandbox/legacy-retirement.d.ts +11 -59
  129. package/dist/sandbox/legacy-retirement.js +34 -186
  130. package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
  131. package/dist/sandbox/legacy-retirement.module.js +2 -2
  132. package/dist/sandbox/managed-device-context.d.ts +16 -4
  133. package/dist/sandbox/managed-device-context.js +25 -8
  134. package/dist/sandbox/managed-device-context.module.js +4 -0
  135. package/dist/sandbox/modes.d.ts +3 -12
  136. package/dist/sandbox/modes.js +2 -14
  137. package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
  138. package/dist/{local-devices → sandbox}/network-grants.js +4 -49
  139. package/dist/sandbox/operation-authority-types.d.ts +2 -1
  140. package/dist/sandbox/operation-authority.d.ts +6 -20
  141. package/dist/sandbox/operation-authority.js +43 -104
  142. package/dist/sandbox/operation-authority.module.js +1 -1
  143. package/dist/sandbox/operation-intents.d.ts +4 -1
  144. package/dist/sandbox/operation-intents.js +11 -2
  145. package/dist/sandbox/operation-reconcile.job.js +2 -4
  146. package/dist/sandbox/permission-availability.d.ts +6 -7
  147. package/dist/sandbox/permission-availability.js +7 -10
  148. package/dist/sandbox/permission-call-grants.d.ts +2 -1
  149. package/dist/sandbox/permission-call-grants.js +1 -7
  150. package/dist/sandbox/permission-call-types.d.ts +4 -4
  151. package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
  152. package/dist/sandbox/permission-ceiling-writes.js +8 -35
  153. package/dist/sandbox/permission-config-publication.d.ts +9 -1
  154. package/dist/sandbox/permission-config-publication.js +29 -21
  155. package/dist/sandbox/permission-context-types.d.ts +17 -10
  156. package/dist/sandbox/permission-facts.d.ts +98 -95
  157. package/dist/sandbox/permission-facts.js +160 -314
  158. package/dist/sandbox/permission-instance-writes.d.ts +23 -37
  159. package/dist/sandbox/permission-instance-writes.js +44 -121
  160. package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
  161. package/dist/sandbox/permission-runtime-reports.js +105 -122
  162. package/dist/sandbox/providers.d.ts +26 -38
  163. package/dist/sandbox/providers.js +36 -18
  164. package/dist/sandbox/request-not-sent.d.ts +2 -13
  165. package/dist/sandbox/request-not-sent.js +2 -13
  166. package/dist/sandbox/review/permission-candidate.d.ts +13 -8
  167. package/dist/sandbox/review/permission-candidate.js +38 -48
  168. package/dist/sandbox/sandbox.module.js +7 -3
  169. package/dist/sandbox/sandbox.service.d.ts +49 -59
  170. package/dist/sandbox/sandbox.service.js +139 -259
  171. package/dist/schedules/fire.d.ts +15 -6
  172. package/dist/schedules/fire.js +27 -13
  173. package/dist/schedules/grant-rules.js +1 -1
  174. package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
  175. package/dist/schedules/scheduled-tasks.service.js +1 -4
  176. package/dist/schedules/schedules.module.js +5 -3
  177. package/dist/skills/invoke.d.ts +1 -1
  178. package/dist/skills/invoke.js +2 -3
  179. package/dist/tools/approvals.service.d.ts +8 -5
  180. package/dist/tools/approvals.service.js +5 -5
  181. package/dist/tools/builtins/sandbox/bash.js +1 -2
  182. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  183. package/dist/tools/builtins/sandbox/common.js +37 -38
  184. package/dist/tools/connectors.controller.d.ts +2 -0
  185. package/dist/tools/connectors.schemas.d.ts +2 -0
  186. package/dist/tools/credentials.d.ts +2 -0
  187. package/dist/tools/network-asks.d.ts +19 -22
  188. package/dist/tools/network-asks.js +15 -21
  189. package/dist/tools/oauth/authorization-params.d.ts +7 -0
  190. package/dist/tools/oauth/authorization-params.js +19 -0
  191. package/dist/tools/oauth/flow.js +7 -0
  192. package/dist/tools/oauth/tokens.js +2 -1
  193. package/dist/tools/pipeline.d.ts +6 -7
  194. package/dist/tools/pipeline.js +17 -21
  195. package/dist/tools/tools.module.js +3 -7
  196. package/package.json +3 -4
  197. package/src/migrations/0177_dial_in_contract.sql +32 -0
  198. package/dist/local-devices/device-auth.module.d.ts +0 -7
  199. package/dist/local-devices/device-auth.module.js +0 -25
  200. package/dist/local-devices/device-policy.service.d.ts +0 -213
  201. package/dist/local-devices/device-policy.service.js +0 -605
  202. package/dist/local-devices/instance-bindings.d.ts +0 -82
  203. package/dist/local-devices/instance-bindings.js +0 -307
  204. package/dist/local-devices/local-device-gateway.d.ts +0 -153
  205. package/dist/local-devices/local-device-provider.d.ts +0 -122
  206. package/dist/local-devices/local-device-provider.js +0 -326
  207. package/dist/local-devices/local-devices.module.d.ts +0 -31
  208. package/dist/local-devices/local-devices.module.js +0 -100
  209. package/dist/local-devices/machines.d.ts +0 -211
  210. package/dist/local-devices/machines.js +0 -766
  211. package/dist/local-devices/owner-report.d.ts +0 -81
  212. package/dist/local-devices/owner-report.js +0 -150
  213. package/dist/local-devices/owner-reports.d.ts +0 -48
  214. package/dist/local-devices/owner-reports.js +0 -208
  215. package/dist/local-devices/policy-op-jobs.d.ts +0 -15
  216. package/dist/local-devices/policy-op-jobs.js +0 -12
  217. package/dist/local-devices/policy-summary.d.ts +0 -102
  218. package/dist/local-devices/policy-summary.js +0 -155
  219. package/dist/local-devices/relay.d.ts +0 -166
  220. package/dist/local-devices/relay.js +0 -559
  221. package/dist/tools/device-op-resolver.d.ts +0 -34
  222. package/dist/tools/device-op-resolver.js +0 -120
  223. /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
  224. /package/dist/{local-devices → dial-in}/keys.js +0 -0
  225. /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
  226. /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
@@ -1,81 +0,0 @@
1
- import { type DeviceOwnerCeiling, type SandboxBrowseScope, type SandboxOperationScope } from "@capybara-hq/plugin-sdk";
2
- /** How far restricted (non-Full) operations and project browsing may reach on a machine. */
3
- export type RestrictedProjectReach = "workspace" | "os-user";
4
- /** Which message carried a report (audit and diagnostics only). */
5
- export type OwnerReportVia = "hello" | "policy" | "policy-result" | "bind";
6
- /**
7
- * The authenticated owner report kept on a machine row (`device_machines.owner_report`, B2): the
8
- * strict report, the connection and time it arrived, and a block set by an out-of-order report.
9
- */
10
- export interface StoredOwnerReport {
11
- report: DeviceOwnerCeiling;
12
- connectionId: string | null;
13
- observedAt: string;
14
- via: OwnerReportVia;
15
- /** A later report arrived stale or conflicting: no new authority until a valid current one. */
16
- blocked?: {
17
- reason: "stale" | "conflict";
18
- sequence: number;
19
- at: string;
20
- };
21
- }
22
- /** The stored report in `v`, or null (absent or malformed: never trusted). */
23
- export declare function storedOwnerReportOf(v: unknown): StoredOwnerReport | null;
24
- /**
25
- * What a newly arrived report means against the stored one: a higher sequence is recorded; the
26
- * same sequence, revision and bytes is idempotent; a lower sequence is stale; the same sequence
27
- * with other bytes is a protocol conflict.
28
- */
29
- export declare function decideOwnerReport(stored: StoredOwnerReport | null, incoming: DeviceOwnerCeiling): "record" | "same" | "stale" | "conflict";
30
- /**
31
- * The owner facts the kernel decides with (B2), never inferred wider than reported:
32
- * - `report`: an authenticated version 3 report (protocol 4);
33
- * - `blocked`: a stale or conflicting report arrived: fail closed, admission refused;
34
- * - `missing`: nothing readable (no report, or one of an older protocol): fail closed.
35
- *
36
- * The facts carry the report's fields under its own names: `outsideSandbox`, `network` and
37
- * `allowedDomains` (the owner's sandbox allowlist, a ceiling while its network is `allowlist`).
38
- */
39
- export interface OwnerFacts {
40
- state: "report" | "blocked" | "missing";
41
- /** The owner allows running outside the sandbox (an escalated call). */
42
- outsideSandbox: boolean;
43
- restrictedProjectReach: RestrictedProjectReach;
44
- /** The owner's sandbox allowlist: the machine's host ceiling while its network is `allowlist`. */
45
- allowedDomains: string[];
46
- /** The owner's sandbox network (`allowlist` when failing closed). */
47
- network: "open" | "allowlist";
48
- revision: string | null;
49
- sequence: number | null;
50
- observedAt: string | null;
51
- }
52
- /** The facts of a stored report alone (a successful record). */
53
- export declare function ownerFactsOfReport(stored: StoredOwnerReport): OwnerFacts;
54
- /** A machine row's owner facts: its authenticated report, else missing (fail closed). */
55
- export declare function ownerFactsOf(row: {
56
- owner_report?: unknown;
57
- }): OwnerFacts;
58
- /**
59
- * The owner writer's selector (B2): what an owner-ceiling change takes from a running admission.
60
- * Full work loses only to Full being removed; broad browsing (`/`) and restricted roots outside
61
- * the machine's own roots lose only to the reach narrowing to the workspace; a restricted
62
- * execution loses a host only when no independent grant keeps it. A restricted-only change never
63
- * touches Full work, and a Full-only change never touches restricted work.
64
- */
65
- export declare function ownerReportRevokes(next: OwnerFacts, scope: SandboxOperationScope | SandboxBrowseScope, method: string, grantedHosts: readonly string[], machineRoots: readonly string[]): boolean;
66
- /**
67
- * A restricted operation scope reaching outside the machine's own roots (a selected project beyond
68
- * the workspace): what narrowing the reach to the workspace takes away (B2). The owner writer and
69
- * the platform/org Full-off writers share it.
70
- */
71
- export declare function outsideMachineRoots(scope: SandboxOperationScope | SandboxBrowseScope, machineRoots: readonly string[] | undefined): boolean;
72
- /** The machine's reported roots as a list (workspace, tmp, skills ...), or none. */
73
- export declare function machineRootList(roots: unknown): string[];
74
- /**
75
- * A machine's owner outside-sandbox permission in the kernel-internal tier encoding (`SandboxMode`
76
- * in `sandbox/modes.ts`; never re-encodes reach): `auto` only for an authenticated report that
77
- * allows running outside the sandbox; a blocked, missing or older report fails closed.
78
- */
79
- export declare function ownerModeOf(row: {
80
- owner_report?: unknown;
81
- }): "auto" | "sandbox";
@@ -1,150 +0,0 @@
1
- import { parseOwnerCeilingReport, } from "@capybara-hq/plugin-sdk";
2
- import { coversHost } from "../sandbox/modes.js";
3
- import { isExecutionMethod, isFullExecutionScope } from "../sandbox/operation-authority-types.js";
4
- /** The stored report in `v`, or null (absent or malformed: never trusted). */
5
- export function storedOwnerReportOf(v) {
6
- if (typeof v !== "object" || v === null || Array.isArray(v))
7
- return null;
8
- const o = v;
9
- let report;
10
- try {
11
- report = parseOwnerCeilingReport(o.report);
12
- }
13
- catch {
14
- return null;
15
- }
16
- if (typeof o.observedAt !== "string")
17
- return null;
18
- if (o.connectionId !== null && typeof o.connectionId !== "string")
19
- return null;
20
- if (!["hello", "policy", "policy-result", "bind"].includes(String(o.via)))
21
- return null;
22
- const b = o.blocked;
23
- return {
24
- report,
25
- connectionId: o.connectionId,
26
- observedAt: o.observedAt,
27
- via: o.via,
28
- ...(b &&
29
- (b.reason === "stale" || b.reason === "conflict") &&
30
- typeof b.sequence === "number" &&
31
- typeof b.at === "string" && {
32
- blocked: { reason: b.reason, sequence: b.sequence, at: b.at },
33
- }),
34
- };
35
- }
36
- /**
37
- * What a newly arrived report means against the stored one: a higher sequence is recorded; the
38
- * same sequence, revision and bytes is idempotent; a lower sequence is stale; the same sequence
39
- * with other bytes is a protocol conflict.
40
- */
41
- export function decideOwnerReport(stored, incoming) {
42
- if (stored === null)
43
- return "record";
44
- const prev = stored.report;
45
- if (incoming.sequence > prev.sequence)
46
- return "record";
47
- if (incoming.sequence < prev.sequence)
48
- return "stale";
49
- return JSON.stringify(canonicalReport(incoming)) === JSON.stringify(canonicalReport(prev))
50
- ? "same"
51
- : "conflict";
52
- }
53
- const canonicalReport = (r) => ({
54
- version: r.version,
55
- revision: r.revision,
56
- sequence: r.sequence,
57
- outsideSandbox: r.outsideSandbox,
58
- network: r.network,
59
- allowedDomains: [...r.allowedDomains],
60
- restrictedProjectReach: r.restrictedProjectReach,
61
- });
62
- const FAIL_CLOSED = {
63
- outsideSandbox: false,
64
- restrictedProjectReach: "workspace",
65
- allowedDomains: [],
66
- network: "allowlist",
67
- };
68
- /** The facts of a stored report alone (a successful record). */
69
- export function ownerFactsOfReport(stored) {
70
- if (stored.blocked)
71
- return {
72
- state: "blocked",
73
- ...FAIL_CLOSED,
74
- revision: stored.report.revision,
75
- sequence: stored.report.sequence,
76
- observedAt: stored.observedAt,
77
- };
78
- return {
79
- state: "report",
80
- outsideSandbox: stored.report.outsideSandbox,
81
- restrictedProjectReach: stored.report.restrictedProjectReach,
82
- allowedDomains: [...stored.report.allowedDomains],
83
- network: stored.report.network,
84
- revision: stored.report.revision,
85
- sequence: stored.report.sequence,
86
- observedAt: stored.observedAt,
87
- };
88
- }
89
- /** A machine row's owner facts: its authenticated report, else missing (fail closed). */
90
- export function ownerFactsOf(row) {
91
- const stored = storedOwnerReportOf(row.owner_report);
92
- if (stored !== null)
93
- return ownerFactsOfReport(stored);
94
- return { state: "missing", ...FAIL_CLOSED, revision: null, sequence: null, observedAt: null };
95
- }
96
- /** True when `path` lies in one of `roots` (absolute, normalized). */
97
- const within = (path, root) => root === "/" || path === root || path.startsWith(`${root}/`);
98
- /**
99
- * The owner writer's selector (B2): what an owner-ceiling change takes from a running admission.
100
- * Full work loses only to Full being removed; broad browsing (`/`) and restricted roots outside
101
- * the machine's own roots lose only to the reach narrowing to the workspace; a restricted
102
- * execution loses a host only when no independent grant keeps it. A restricted-only change never
103
- * touches Full work, and a Full-only change never touches restricted work.
104
- */
105
- export function ownerReportRevokes(next, scope, method, grantedHosts, machineRoots) {
106
- if (next.state === "blocked" || next.state === "missing")
107
- return true;
108
- const inMachine = (root) => machineRoots.some((r) => within(root, r));
109
- if (!("profile" in scope))
110
- return (next.restrictedProjectReach === "workspace" && scope.readRoots.some((r) => !inMachine(r)));
111
- if (isFullExecutionScope(scope))
112
- return !next.outsideSandbox;
113
- if (next.restrictedProjectReach === "workspace" && outsideMachineRoots(scope, machineRoots))
114
- return true;
115
- if (!isExecutionMethod(method))
116
- return false;
117
- // the open public network goes when the owner narrows the sandbox network to the allowlist
118
- if (scope.network.kind === "open-public")
119
- return next.network === "allowlist";
120
- // the owner's list bounds hosts only while its network is the allowlist
121
- if (scope.network.kind !== "allowlist" || next.network !== "allowlist")
122
- return false;
123
- return scope.network.hosts.some((host) => !next.allowedDomains.some((pattern) => coversHost(pattern, host)) &&
124
- !grantedHosts.includes(host));
125
- }
126
- /**
127
- * A restricted operation scope reaching outside the machine's own roots (a selected project beyond
128
- * the workspace): what narrowing the reach to the workspace takes away (B2). The owner writer and
129
- * the platform/org Full-off writers share it.
130
- */
131
- export function outsideMachineRoots(scope, machineRoots) {
132
- if (machineRoots === undefined || !("profile" in scope) || scope.filesystem.kind !== "scoped")
133
- return false;
134
- const { projectRoot, writeRoots } = scope.filesystem;
135
- return [...(projectRoot === null ? [] : [projectRoot]), ...writeRoots].some((r) => !machineRoots.some((m) => within(r, m)));
136
- }
137
- /** The machine's reported roots as a list (workspace, tmp, skills ...), or none. */
138
- export function machineRootList(roots) {
139
- if (typeof roots !== "object" || roots === null)
140
- return [];
141
- return Object.values(roots).filter((r) => typeof r === "string" && r.startsWith("/"));
142
- }
143
- /**
144
- * A machine's owner outside-sandbox permission in the kernel-internal tier encoding (`SandboxMode`
145
- * in `sandbox/modes.ts`; never re-encodes reach): `auto` only for an authenticated report that
146
- * allows running outside the sandbox; a blocked, missing or older report fails closed.
147
- */
148
- export function ownerModeOf(row) {
149
- return ownerFactsOf(row).outsideSandbox ? "auto" : "sandbox";
150
- }
@@ -1,48 +0,0 @@
1
- import { KernelDb } from "../infra/database/kernel-db.js";
2
- import { TransactionHost } from "../infra/database/transaction-host.js";
3
- import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
4
- import { type OwnerReportVia } from "./owner-report.js";
5
- /** What became of an arrived owner report. */
6
- export type OwnerReportOutcome = "recorded" | "same" | "stale" | "conflict" | "revoked";
7
- /**
8
- * The single writer of authenticated owner reports (permission runtime cutover B2). Every carrier
9
- * (v3 hello, `policy` frame, policy answer or applied status, bind answer) enters here under the
10
- * device authority writer, for the machine the authenticated connection belongs to: a caller never
11
- * names another device. A higher sequence is recorded and publishes the changed effective facts
12
- * through the common ceiling writer: Full consent resets only when the owner's Full permission
13
- * (or the machine's roots) actually changed; restricted-only changes revoke only the restricted
14
- * work they narrow. The same report again only refreshes when it was seen; a stale or conflicting
15
- * one blocks new authority until a valid current report arrives.
16
- */
17
- export declare class OwnerReports {
18
- private readonly db;
19
- readonly txHost: TransactionHost;
20
- private readonly ceilings;
21
- constructor(db: KernelDb, txHost: TransactionHost, ceilings: PermissionCeilingWrites);
22
- /** {@link recordLocked} in its own transaction, taking the device authority writer. */
23
- record(machineId: string, report: unknown, meta: {
24
- connectionId: string | null;
25
- via: OwnerReportVia;
26
- }): Promise<OwnerReportOutcome>;
27
- /**
28
- * Records one report for `machineId` (the caller holds the device authority writer and has
29
- * validated the connection). `rootsChanged`: the same message also changed the machine's roots,
30
- * which already resets Full consent and revokes everything (folded into one publication).
31
- */
32
- recordLocked(machineId: string, raw: unknown, meta: {
33
- connectionId: string | null;
34
- via: OwnerReportVia;
35
- rootsChanged?: boolean;
36
- /**
37
- * The platform op whose answer carries this report: the change is audited as its source
38
- * made it (the person, via the web or an approval), once, instead of as the machine's own.
39
- */
40
- explainedBy?: {
41
- accountId: string;
42
- via: string;
43
- opId: string;
44
- actorTokenId?: string;
45
- };
46
- }): Promise<OwnerReportOutcome>;
47
- private write;
48
- }
@@ -1,208 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __param = (this && this.__param) || function (paramIndex, decorator) {
8
- return function (target, key) { decorator(target, key, paramIndex); }
9
- };
10
- import { parseOwnerCeilingReport } from "@capybara-hq/plugin-sdk";
11
- import { Inject, Injectable } from "@nestjs/common";
12
- import { audit } from "../identity/audit.js";
13
- import { KernelDb } from "../infra/database/kernel-db.js";
14
- import { TransactionHost } from "../infra/database/transaction-host.js";
15
- import { Transactional } from "../infra/database/transactional.decorator.js";
16
- import { coversHost } from "../sandbox/modes.js";
17
- import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
18
- import { decideOwnerReport, machineRootList, ownerFactsOf, ownerFactsOfReport, ownerReportRevokes, storedOwnerReportOf, } from "./owner-report.js";
19
- import { opExplainsOwnerChange, pendingPolicyOpsOf } from "./policy-summary.js";
20
- /**
21
- * The single writer of authenticated owner reports (permission runtime cutover B2). Every carrier
22
- * (v3 hello, `policy` frame, policy answer or applied status, bind answer) enters here under the
23
- * device authority writer, for the machine the authenticated connection belongs to: a caller never
24
- * names another device. A higher sequence is recorded and publishes the changed effective facts
25
- * through the common ceiling writer: Full consent resets only when the owner's Full permission
26
- * (or the machine's roots) actually changed; restricted-only changes revoke only the restricted
27
- * work they narrow. The same report again only refreshes when it was seen; a stale or conflicting
28
- * one blocks new authority until a valid current report arrives.
29
- */
30
- let OwnerReports = class OwnerReports {
31
- db;
32
- txHost;
33
- ceilings;
34
- constructor(db, txHost, ceilings) {
35
- this.db = db;
36
- this.txHost = txHost;
37
- this.ceilings = ceilings;
38
- }
39
- /** {@link recordLocked} in its own transaction, taking the device authority writer. */
40
- async record(machineId, report, meta) {
41
- const subject = await this.db
42
- .selectFrom("device_machines")
43
- .select(["org_id", "device_id"])
44
- .where("id", "=", machineId)
45
- .where("revoked_at", "is", null)
46
- .executeTakeFirst();
47
- if (!subject)
48
- return "revoked";
49
- await this.ceilings.lock({ orgId: subject.org_id, deviceId: subject.device_id }, "device");
50
- return this.recordLocked(machineId, report, meta);
51
- }
52
- /**
53
- * Records one report for `machineId` (the caller holds the device authority writer and has
54
- * validated the connection). `rootsChanged`: the same message also changed the machine's roots,
55
- * which already resets Full consent and revokes everything (folded into one publication).
56
- */
57
- async recordLocked(machineId, raw, meta) {
58
- const report = parseOwnerCeilingReport(raw);
59
- const row = await this.db
60
- .selectFrom("device_machines")
61
- .select([
62
- "org_id",
63
- "device_id",
64
- "account_id",
65
- "owner_report",
66
- "local_policy",
67
- "roots",
68
- "pending_policy_ops",
69
- ])
70
- .where("id", "=", machineId)
71
- .where("revoked_at", "is", null)
72
- .forUpdate()
73
- .executeTakeFirst();
74
- if (!row)
75
- return "revoked";
76
- const subject = { orgId: row.org_id, deviceId: row.device_id };
77
- const stored = storedOwnerReportOf(row.owner_report);
78
- const decision = decideOwnerReport(stored, report);
79
- const now = new Date().toISOString();
80
- if (decision === "stale" && meta.via !== "hello") {
81
- // a policy frame, answer, status or bind answer committed after a newer report (carriers
82
- // commit in lock order, not issue order) carries no newer authority: ignored, never blocks
83
- if (meta.rootsChanged)
84
- await this.ceilings.publishLocked(subject, "device", true, true);
85
- return "stale";
86
- }
87
- if (decision === "stale" || decision === "conflict") {
88
- // a hello (it opens the current connection) regressing the sequence, or the same sequence
89
- // with other bytes: never replaces the authority, blocks new admissions until a valid report
90
- await this.write(machineId, {
91
- ...stored,
92
- blocked: { reason: decision, sequence: report.sequence, at: now },
93
- });
94
- if (meta.rootsChanged)
95
- await this.ceilings.publishLocked(subject, "device", true, true);
96
- return decision;
97
- }
98
- if (decision === "same") {
99
- const { blocked: _cleared, ...kept } = stored;
100
- await this.write(machineId, { ...kept, connectionId: meta.connectionId, observedAt: now });
101
- if (meta.rootsChanged)
102
- await this.ceilings.publishLocked(subject, "device", true, true);
103
- return "same";
104
- }
105
- // the facts the authority last held: a block only fails admission closed, it is not a change
106
- // of Full or reach (unblocking with the same facts resets nothing and audits nothing)
107
- const before = stored === null
108
- ? ownerFactsOf(row)
109
- : ownerFactsOfReport({
110
- report: stored.report,
111
- connectionId: stored.connectionId,
112
- observedAt: stored.observedAt,
113
- via: stored.via,
114
- });
115
- const next = {
116
- report,
117
- connectionId: meta.connectionId,
118
- observedAt: now,
119
- via: meta.via,
120
- };
121
- const after = ownerFactsOfReport(next);
122
- await this.write(machineId, next);
123
- const fullChanged = before.outsideSandbox !== after.outsideSandbox;
124
- const reachChanged = before.restrictedProjectReach !== after.restrictedProjectReach;
125
- const domainsChanged = JSON.stringify([...before.allowedDomains].sort()) !==
126
- JSON.stringify([...after.allowedDomains].sort());
127
- // the owner's sandbox network: narrowing it to the allowlist takes open-network work
128
- const networkChanged = before.network !== after.network;
129
- // only a widening resets Full consent (Full access would auto-approve more): running outside
130
- // allowed again, the open network, the os-user reach, or a host added to an allowlist the
131
- // owner keeps; a narrowing keeps what the consent covered. A machine's first report is no
132
- // network widening (the missing state's allowlist is only failing closed)
133
- const reported = before.state !== "missing";
134
- const widened = (!before.outsideSandbox && after.outsideSandbox) ||
135
- (before.restrictedProjectReach === "workspace" &&
136
- after.restrictedProjectReach === "os-user") ||
137
- (reported && before.network === "allowlist" && after.network === "open") ||
138
- (reported &&
139
- after.network === "allowlist" &&
140
- after.allowedDomains.some((h) => !before.allowedDomains.some((p) => coversHost(p, h))));
141
- const roots = machineRootList(row.roots);
142
- // a new revision with the same visible facts is no new authority: nothing is published
143
- if (fullChanged || reachChanged || domainsChanged || networkChanged || meta.rootsChanged)
144
- await this.ceilings.publishLocked(subject, "device", (scope, intent) => meta.rootsChanged === true ||
145
- ownerReportRevokes(after, scope, intent.method, intent.granted_hosts, roots), widened || meta.rootsChanged === true);
146
- // the op whose change this is: its answer names it, else (the machine's own report of it, a
147
- // policy frame or a reconnect hello, landing first) a live pending op of the platform's that
148
- // asked for exactly this narrowing; the answer then finds the same report and audits nothing
149
- const nowMs = Date.now();
150
- const pending = meta.explainedBy === undefined
151
- ? pendingPolicyOpsOf(row.pending_policy_ops).find((op) => op.until > nowMs && opExplainsOwnerChange(op, before, after))
152
- : undefined;
153
- const by = meta.explainedBy ??
154
- (pending && {
155
- accountId: pending.source.accountId,
156
- via: pending.source.via,
157
- opId: pending.id,
158
- ...(pending.actorTokenId !== undefined && { actorTokenId: pending.actorTokenId }),
159
- });
160
- if (before.state !== "missing" && (fullChanged || reachChanged || networkChanged))
161
- await audit(this.db.db, {
162
- actorAccountId: by?.accountId ?? row.account_id,
163
- ...(by?.actorTokenId !== undefined && { actorTokenId: by.actorTokenId }),
164
- orgId: row.org_id,
165
- action: "device.owner_ceiling_changed",
166
- target: row.device_id,
167
- detail: {
168
- // the network appears when it changed (the rows of other changes keep their shape)
169
- from: {
170
- outsideSandbox: before.outsideSandbox,
171
- restrictedProjectReach: before.restrictedProjectReach,
172
- ...(networkChanged && { network: before.network }),
173
- },
174
- to: {
175
- outsideSandbox: after.outsideSandbox,
176
- restrictedProjectReach: after.restrictedProjectReach,
177
- ...(networkChanged && { network: after.network }),
178
- },
179
- sequence: report.sequence,
180
- by: by?.accountId ?? row.account_id,
181
- via: by?.via ?? "device",
182
- ...(by !== undefined && { opId: by.opId }),
183
- machineId,
184
- },
185
- });
186
- return "recorded";
187
- }
188
- async write(machineId, value) {
189
- await this.db
190
- .updateTable("device_machines")
191
- .set({ owner_report: JSON.stringify(value) })
192
- .where("id", "=", machineId)
193
- .execute();
194
- }
195
- };
196
- __decorate([
197
- Transactional()
198
- ], OwnerReports.prototype, "record", null);
199
- __decorate([
200
- Transactional({ propagation: "mandatory" })
201
- ], OwnerReports.prototype, "recordLocked", null);
202
- OwnerReports = __decorate([
203
- Injectable(),
204
- __param(0, Inject(KernelDb)),
205
- __param(1, Inject(TransactionHost)),
206
- __param(2, Inject(PermissionCeilingWrites))
207
- ], OwnerReports);
208
- export { OwnerReports };
@@ -1,15 +0,0 @@
1
- /**
2
- * Settles a device policy op whose outcome was not recorded (transactional outbox spec §7): owed
3
- * by the op's intent transaction for when the op can no longer reach the machine, and by a hello
4
- * that reported its outcome. Consumed by `DeviceOpResolver` on the maintenance queue.
5
- */
6
- export declare const DEVICE_OP_RESOLVE_JOB = "device-op-resolve";
7
- /** The `device-op-resolve` job's data. */
8
- export interface DeviceOpResolveData {
9
- machineId: string;
10
- opId: string;
11
- }
12
- /** The job id of the resolve job owed with an op's intent. */
13
- export declare const deviceOpResolveJobId: (opId: string) => string;
14
- /** The job id of the resolve job owed by a hello that reported the op's outcome. */
15
- export declare const deviceOpReportedJobId: (opId: string) => string;
@@ -1,12 +0,0 @@
1
- // The device policy op jobs' names and ids: a leaf module (no service imports), read by the
2
- // producers (DevicePolicyService, MachinesService) and the maintenance processor.
3
- /**
4
- * Settles a device policy op whose outcome was not recorded (transactional outbox spec §7): owed
5
- * by the op's intent transaction for when the op can no longer reach the machine, and by a hello
6
- * that reported its outcome. Consumed by `DeviceOpResolver` on the maintenance queue.
7
- */
8
- export const DEVICE_OP_RESOLVE_JOB = "device-op-resolve";
9
- /** The job id of the resolve job owed with an op's intent. */
10
- export const deviceOpResolveJobId = (opId) => `device-op-resolve-${opId}`;
11
- /** The job id of the resolve job owed by a hello that reported the op's outcome. */
12
- export const deviceOpReportedJobId = (opId) => `device-op-reported-${opId}`;
@@ -1,102 +0,0 @@
1
- import type { DeviceFeature, DeviceLocalPolicySummary, SandboxBrowseScope, SandboxOperationScope } from "@capybara-hq/plugin-sdk";
2
- /**
3
- * The known features in `v` (a hello's `features` or the stored column), in a fixed order and
4
- * deduped; anything else (unknown names, a non-array) is dropped.
5
- */
6
- export declare function deviceFeaturesOf(v: unknown): DeviceFeature[];
7
- /**
8
- * `v` as a local policy summary (auto mode spec §4.1), or null when it is absent or not a valid
9
- * one. The device is the authority on its policy: the kernel only keeps what it last said, for the
10
- * device page and the `device_paths` event, never to decide what a command may reach.
11
- */
12
- export declare function localPolicyOf(v: unknown): DeviceLocalPolicySummary | null;
13
- /**
14
- * What changed between two local policy summaries, in the owner's terms (the device page's change
15
- * list): hosts added to and removed from the allowlist. The owner ceiling's changes come from the
16
- * owner report.
17
- */
18
- export interface LocalPolicyDiff {
19
- add: string[];
20
- remove: string[];
21
- }
22
- /** The {@link LocalPolicyDiff} from `prev` to `next`; null when nothing the owner sets changed. */
23
- export declare function localPolicyDiff(prev: DeviceLocalPolicySummary, next: DeviceLocalPolicySummary): LocalPolicyDiff | null;
24
- /** Who asked for a `policy` op: the deciding account and where. */
25
- export interface PolicyOpSource {
26
- accountId: string;
27
- via: "web" | "im";
28
- }
29
- /** What the machine reported of an op after its answer was lost (its hello's `recentOps`). */
30
- export interface ReportedPolicyOp {
31
- /**
32
- * `absent`: not in the hello's outcomes although the op can no longer reach the machine;
33
- * `interrupted`: logged `started` only, and its change is not in the policy the hello reports
34
- * (one whose change is there is `applied`).
35
- */
36
- outcome: "applied" | "refused" | "absent" | "interrupted";
37
- }
38
- /**
39
- * The intent of a `policy` op the platform sends to a machine (transactional outbox spec §7), kept
40
- * on the machine's row (`pending_policy_ops`) from before the op is sent until its outcome is
41
- * recorded: the change asked for, who asked, and until when (epoch ms) a summary the machine
42
- * reports by itself may still be that op's. `sent`: on its way or in flight, the
43
- * `device-op-resolve` job owed for `resolveAt`; `unknown`: no answer came, and only the machine's
44
- * next hello (`recentOps`) or a later `policyStatus` can tell what became of it.
45
- */
46
- export interface PendingPolicyOp {
47
- id: string;
48
- /** Hosts to remove; the platform never adds one (the owner does, on the machine). */
49
- remove: string[];
50
- /**
51
- * The owner-ceiling narrowing the op asked the machine for: only `false` / `allowlist` /
52
- * `workspace` (the platform never widens). It explains the machine's own owner report of the
53
- * change.
54
- */
55
- ownerCeiling?: {
56
- outsideSandbox?: false;
57
- network?: "allowlist";
58
- restrictedProjectReach?: "workspace";
59
- };
60
- source: PolicyOpSource;
61
- actorTokenId?: string;
62
- status: "sent" | "unknown";
63
- /** When the intent was written (epoch ms). */
64
- sentAt: number;
65
- /** From when the op can no longer reach the machine (epoch ms): the resolve job's `runAt`. */
66
- resolveAt: number;
67
- until: number;
68
- /** Set by a hello that reported the op's outcome (or its absence) before the op was resolved. */
69
- reported?: ReportedPolicyOp;
70
- }
71
- /** The pending ops stored on a machine row (malformed entries dropped). */
72
- export declare function pendingPolicyOpsOf(v: unknown): PendingPolicyOp[];
73
- /**
74
- * Whether the change of `op` is in `policy`: its hosts removed. Tells an op the machine logged only
75
- * as `started` (it stopped between the log and the answer) that was written from one that was not.
76
- */
77
- export declare function opVisibleIn(op: PendingPolicyOp, policy: DeviceLocalPolicySummary): boolean;
78
- /** The owner facts an op's narrowing is compared on (`network` absent: not compared). */
79
- export interface OwnerChangeFacts {
80
- outsideSandbox: boolean;
81
- restrictedProjectReach: "workspace" | "os-user";
82
- network?: "open" | "allowlist";
83
- }
84
- /**
85
- * Whether a v3 owner report's change from `before` to `after` is what the platform's `op` asked
86
- * for (the machine's own report of it, arriving before the op's answer): something changed, and
87
- * every changed fact is a narrowing the op carried, to the value it asked for. A widening is never
88
- * an op's.
89
- */
90
- export declare function opExplainsOwnerChange(op: PendingPolicyOp, before: OwnerChangeFacts, after: OwnerChangeFacts): boolean;
91
- /**
92
- * Whether `diff` is what the platform's `op` did (its answer, or the machine's own report of it
93
- * before the answer was recorded): hosts within the op's. The device page then lists the change
94
- * once, as the platform's.
95
- */
96
- export declare function opExplains(op: PendingPolicyOp, diff: LocalPolicyDiff): boolean;
97
- /**
98
- * Revoke only authority removed from a starting grant; explicit additions are not owner baseline.
99
- * The summary carries the sandbox allowlist only: the owner ceiling (outside the sandbox, the
100
- * reach) is revoked by the owner report's writer (`ownerReportRevokes`).
101
- */
102
- export declare function ownerPolicyRevokes(next: DeviceLocalPolicySummary | null, scope: SandboxOperationScope | SandboxBrowseScope, method: string, grantedHosts: readonly string[]): boolean;