@capybara-hq/kernel 0.1.0-rc.62 → 0.1.0-rc.64

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 (120) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/app.d.ts +2 -0
  3. package/dist/catalog/catalog.service.d.ts +13 -0
  4. package/dist/catalog/catalog.service.js +17 -8
  5. package/dist/catalog/git-source.d.ts +8 -0
  6. package/dist/catalog/git-source.js +14 -6
  7. package/dist/catalog/marketplaces.controller.d.ts +3 -2
  8. package/dist/catalog/marketplaces.controller.js +5 -2
  9. package/dist/catalog/marketplaces.schemas.d.ts +7 -0
  10. package/dist/catalog/marketplaces.schemas.js +13 -0
  11. package/dist/catalog/marketplaces.service.d.ts +65 -11
  12. package/dist/catalog/marketplaces.service.js +208 -30
  13. package/dist/catalog/org-catalog.schemas.d.ts +1 -1
  14. package/dist/catalog/org-catalog.schemas.js +1 -1
  15. package/dist/channels/actions.d.ts +2 -5
  16. package/dist/channels/actions.js +20 -8
  17. package/dist/channels/cards.d.ts +4 -3
  18. package/dist/channels/cards.js +6 -4
  19. package/dist/channels/outbound.js +3 -2
  20. package/dist/config/schema.d.ts +2 -0
  21. package/dist/config/schema.js +22 -2
  22. package/dist/conversations/approval-profile.d.ts +30 -0
  23. package/dist/conversations/approval-profile.js +62 -0
  24. package/dist/conversations/conversations.service.js +0 -2
  25. package/dist/conversations/events.d.ts +43 -0
  26. package/dist/conversations/events.js +52 -0
  27. package/dist/conversations/permission-profiles.controller.d.ts +3 -2
  28. package/dist/conversations/permission-profiles.service.d.ts +3 -2
  29. package/dist/conversations/permission-profiles.service.js +12 -8
  30. package/dist/db/kernel-schema.d.ts +8 -2
  31. package/dist/errors.d.ts +7 -0
  32. package/dist/errors.js +7 -0
  33. package/dist/extensions/bootstrap-defaults.d.ts +24 -0
  34. package/dist/extensions/bootstrap-defaults.js +78 -0
  35. package/dist/extensions/bootstrap-extra.d.ts +74 -0
  36. package/dist/extensions/bootstrap-extra.js +131 -0
  37. package/dist/extensions/bootstrap.d.ts +77 -13
  38. package/dist/extensions/bootstrap.js +282 -48
  39. package/dist/identity/initial-passwords.controller.d.ts +8 -6
  40. package/dist/identity/initial-passwords.controller.js +13 -7
  41. package/dist/identity/initial-passwords.d.ts +22 -13
  42. package/dist/identity/initial-passwords.js +25 -29
  43. package/dist/identity/settings.d.ts +10 -0
  44. package/dist/identity/settings.js +46 -0
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.js +3 -0
  47. package/dist/kernel.module.js +3 -0
  48. package/dist/lifecycle/kernel-lifecycle.d.ts +7 -1
  49. package/dist/lifecycle/kernel-lifecycle.js +69 -16
  50. package/dist/local-devices/relay.js +3 -1
  51. package/dist/models/images.js +5 -4
  52. package/dist/platform/connector-person-fields.js +2 -2
  53. package/dist/platform/exclusions.js +4 -4
  54. package/dist/platform/method.js +1 -1
  55. package/dist/platform/operation.d.ts +9 -7
  56. package/dist/platform/operation.js +1 -1
  57. package/dist/platform/ops/accounts.ops.d.ts +1 -1
  58. package/dist/platform/ops/accounts.ops.js +3 -3
  59. package/dist/platform/ops/channels.ops.d.ts +1 -1
  60. package/dist/platform/ops/channels.ops.js +2 -2
  61. package/dist/platform/ops/connectors.ops.d.ts +2 -2
  62. package/dist/platform/ops/connectors.ops.js +8 -8
  63. package/dist/platform/ops/extensions-admin.ops.d.ts +1 -1
  64. package/dist/platform/ops/extensions-admin.ops.js +3 -3
  65. package/dist/platform/ops/extensions.ops.d.ts +1 -1
  66. package/dist/platform/ops/extensions.ops.js +4 -4
  67. package/dist/platform/ops/marketplaces.ops.js +27 -4
  68. package/dist/platform/ops/org-plugins.ops.js +2 -2
  69. package/dist/platform/ops/orgs.ops.d.ts +1 -1
  70. package/dist/platform/ops/orgs.ops.js +3 -3
  71. package/dist/platform/ops/plugins.ops.d.ts +1 -1
  72. package/dist/platform/ops/plugins.ops.js +2 -2
  73. package/dist/platform/person-fields.d.ts +4 -3
  74. package/dist/platform/person-fields.js +6 -5
  75. package/dist/platform/sealed-inputs.d.ts +2 -2
  76. package/dist/platform/sealed-inputs.js +2 -2
  77. package/dist/platform/sealed-reveals.controller.d.ts +5 -8
  78. package/dist/platform/sealed-reveals.controller.js +8 -8
  79. package/dist/platform/sealed-reveals.d.ts +19 -17
  80. package/dist/platform/sealed-reveals.js +30 -33
  81. package/dist/runtime/context/build.js +3 -0
  82. package/dist/runtime/context/compaction.js +2 -0
  83. package/dist/runtime/waits.js +3 -2
  84. package/dist/sandbox/operation-authority.js +16 -15
  85. package/dist/sandbox/operation-intents.js +2 -2
  86. package/dist/sandbox/permission-availability.d.ts +49 -3
  87. package/dist/sandbox/permission-availability.js +61 -6
  88. package/dist/sandbox/permission-call-types.d.ts +3 -0
  89. package/dist/sandbox/permission-facts.d.ts +29 -1
  90. package/dist/sandbox/permission-facts.js +29 -6
  91. package/dist/sandbox/review/classifier.d.ts +72 -2
  92. package/dist/sandbox/review/classifier.js +113 -38
  93. package/dist/sandbox/review/index.d.ts +2 -2
  94. package/dist/sandbox/review/index.js +1 -1
  95. package/dist/sandbox/review/review.service.d.ts +1 -4
  96. package/dist/sandbox/review/review.service.js +4 -33
  97. package/dist/setup/setup-guides.service.js +1 -1
  98. package/dist/tools/approvals.service.d.ts +71 -16
  99. package/dist/tools/approvals.service.js +139 -13
  100. package/dist/tools/builtins/builtin-tools.d.ts +1 -1
  101. package/dist/tools/builtins/builtin-tools.js +12 -6
  102. package/dist/tools/builtins/platform.d.ts +15 -11
  103. package/dist/tools/builtins/platform.js +49 -39
  104. package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
  105. package/dist/tools/builtins/sandbox/bash.js +32 -14
  106. package/dist/tools/builtins/sandbox/common.d.ts +12 -3
  107. package/dist/tools/builtins/sandbox/common.js +29 -5
  108. package/dist/tools/connectors.schemas.d.ts +1 -1
  109. package/dist/tools/connectors.schemas.js +1 -1
  110. package/dist/tools/pipeline.d.ts +70 -10
  111. package/dist/tools/pipeline.js +356 -48
  112. package/dist/tools/policy.d.ts +4 -3
  113. package/dist/tools/policy.js +6 -6
  114. package/dist/tools/registry.d.ts +25 -9
  115. package/dist/tools/tool-review.d.ts +113 -0
  116. package/dist/tools/tool-review.js +303 -0
  117. package/dist/tools/tools.module.js +6 -0
  118. package/package.json +4 -4
  119. package/src/migrations/0174_marketplace_managed_username.sql +4 -0
  120. package/src/migrations/0175_secure_input_kind.sql +8 -0
@@ -9,6 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
+ import { accessibleTo } from "../conversations/access.js";
12
13
  import { platformSealedRevealAad as aadOf } from "../ctx/secrets.js";
13
14
  import { ApiError } from "../errors.js";
14
15
  import { audit } from "../identity/audit.js";
@@ -19,20 +20,19 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
19
20
  import { KEYRING } from "../infra/tokens.js";
20
21
  /**
21
22
  * How long a sealed invitation link waits for its reader, like a generated initial password: the
22
- * approving person reads it right after the call runs; one never read expires (revoke the
23
- * invitation and invite again).
23
+ * person the call was made for reads it right after the call runs; one never read expires
24
+ * (revoke the invitation and invite again).
24
25
  */
25
26
  export const SEALED_REVEAL_TTL_MS = 24 * 60 * 60 * 1000;
26
- /** The tool key of the approval an invitation link belongs to. */
27
- export const INVITE_TOOL_KEY = "Platform:orgs.invite";
28
27
  /** The web path of an invitation link (apps/web `invitePath`). */
29
28
  export const invitationPath = (token) => `/invite/${encodeURIComponent(token)}`;
30
29
  /**
31
- * Values a Platform call makes that only the person who approved the call may read (platform web
32
- * parity spec §7.2, plan ruling R10): the token of an invitation an org admin's agent created. The
33
- * token never reaches the model, the tool result, the event log, the audit or a log line: it is
34
- * sealed with the master keyring in the creation's transaction and read once, on the web, by the
35
- * person who approved the call, like the generated initial password (`InitialPasswords`).
30
+ * Values a Platform call makes that only the person the call was made for may read (platform web
31
+ * parity spec §7.2; read by call: profiles govern every approval, plan ruling R6): the token of an
32
+ * invitation an org admin's agent created. The token never reaches the model, the tool result, the
33
+ * event log, the audit or a log line: it is sealed with the master keyring in the creation's
34
+ * transaction and read once, on the web, by that person, like the generated initial password
35
+ * (`InitialPasswords`).
36
36
  */
37
37
  let SealedReveals = class SealedReveals {
38
38
  db;
@@ -68,37 +68,34 @@ let SealedReveals = class SealedReveals {
68
68
  .execute();
69
69
  }
70
70
  /**
71
- * The link of the invitation an approved `orgs.invite` call created, read once by the person who
72
- * approved it (`approvalId` in `orgId`, decided by `accountId`), then deleted. Anything else (not
73
- * that person, not approved, not run yet, read already, expired, the invitation no longer
74
- * pending) is `invitation.link_unavailable`, saying nothing about which. Audits the read
75
- * (without the token). The URL is absolute under `http.publicUrl`, else the web path.
71
+ * The link of the invitation an `orgs.invite` call created (`call` in `orgId`), read once by its
72
+ * recipient `accountId` while the call's conversation is still accessible to them, then deleted
73
+ * (plan ruling R6: read by call, whether the call ran under an approval or automatically).
74
+ * Anything else (not the recipient, the conversation not accessible, not run yet, read already,
75
+ * expired, the invitation no longer pending) is `invitation.link_unavailable`, saying nothing
76
+ * about which. Audits the read (without the token). The URL is absolute under
77
+ * `http.publicUrl`, else the web path.
76
78
  */
77
- async reveal(orgId, approvalId, accountId) {
78
- const unavailable = () => new ApiError("invitation.link_unavailable", "No invitation link to show: it was shown already, has expired, the invitation is no longer pending, or it was not created by a call you approved");
79
- const approval = await this.db
80
- .selectFrom("approvals")
81
- .select(["conversation_id", "run_id", "call_id", "tool_key", "status", "decided_by"])
82
- .where("id", "=", approvalId)
83
- .where("org_id", "=", orgId)
84
- .executeTakeFirst();
85
- if (approval === undefined ||
86
- approval.tool_key !== INVITE_TOOL_KEY ||
87
- approval.status !== "approved" ||
88
- approval.decided_by !== accountId) {
89
- throw unavailable();
90
- }
91
- // exactly the row of this approval's call, for a still pending invitation: deleted as read
79
+ async reveal(orgId, call, accountId) {
80
+ const unavailable = () => new ApiError("invitation.link_unavailable", "No invitation link to show: it was shown already, has expired, the invitation is no longer pending, or it was not created by a call made for you");
81
+ // exactly the row of this call, for its recipient in a conversation they can still see and
82
+ // a still pending invitation: deleted as read
92
83
  const row = await this.db
93
84
  .deleteFrom("platform_sealed_reveals")
94
85
  .where("kind", "=", "invitation_link")
95
86
  .where("org_id", "=", orgId)
96
- .where("conversation_id", "=", approval.conversation_id)
97
- .where("run_id", "=", approval.run_id)
98
- .where("call_id", "=", approval.call_id)
87
+ .where("conversation_id", "=", call.conversationId)
88
+ .where("run_id", "=", call.runId)
89
+ .where("call_id", "=", call.callId)
99
90
  .where("recipient_account_id", "=", accountId)
100
91
  .where("expires_at", ">", sql `now()`)
101
92
  .where((eb) => eb.exists(eb
93
+ .selectFrom("conversations")
94
+ .select("conversations.id")
95
+ .whereRef("conversations.id", "=", "platform_sealed_reveals.conversation_id")
96
+ .where("conversations.org_id", "=", orgId)
97
+ .where(accessibleTo(accountId))))
98
+ .where((eb) => eb.exists(eb
102
99
  .selectFrom("invitations")
103
100
  .select("invitations.id")
104
101
  .whereRef("invitations.id", "=", "platform_sealed_reveals.id")
@@ -123,7 +120,7 @@ let SealedReveals = class SealedReveals {
123
120
  orgId,
124
121
  action: "org.invitation.link_shown",
125
122
  target: row.id,
126
- detail: { approvalId },
123
+ detail: { conversationId: call.conversationId, runId: call.runId, callId: call.callId },
127
124
  });
128
125
  const base = this.config.get().http.publicUrl?.replace(/\/+$/, "") ?? "";
129
126
  return { url: `${base}${invitationPath(token)}` };
@@ -999,6 +999,9 @@ export function buildModelRequest(input) {
999
999
  // its recorded permission_context, the review only through the tool result
1000
1000
  case "permission_profile_changed":
1001
1001
  case "permission_reviewed":
1002
+ // an automatic decision of a person's ask is display and audit only; the model sees the
1003
+ // call's tool result
1004
+ case "tool_ask_decided":
1002
1005
  break;
1003
1006
  default: {
1004
1007
  const unrendered = e;
@@ -363,6 +363,8 @@ function transcriptLine(e) {
363
363
  case "permission_context":
364
364
  case "permission_profile_changed":
365
365
  case "permission_reviewed":
366
+ // an automatic decision of a person's ask is display and audit only
367
+ case "tool_ask_decided":
366
368
  return null;
367
369
  default: {
368
370
  const unrendered = e;
@@ -353,8 +353,9 @@ let Waits = class Waits {
353
353
  }
354
354
  : {
355
355
  toolKey: a.tool_key,
356
- // a tool ask whose card refused a person's value as leaked says so (§4.5)
357
- text: withLeakedOnCard(APPROVAL_CANCELLED_TEXT, a.kind === "tool"
356
+ // a tool ask or secure input whose card refused a person's value as leaked says
357
+ // so (§4.5)
358
+ text: withLeakedOnCard(APPROVAL_CANCELLED_TEXT, a.kind === "tool" || a.kind === "secure_input"
358
359
  ? a.detail?.leakedFields
359
360
  : undefined),
360
361
  });
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { randomUUID } from "node:crypto";
11
- import { instanceSupported, parseSandboxBrowseScope, parseSandboxOperationScope, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
11
+ import { instanceSupported, parseSandboxBrowseScope, parseSandboxOperationScope, } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
13
  import { sql } from "kysely";
14
14
  import { ACTOR_DEVICE_ACCESS_REASON, ACTOR_NOT_DEVICE_OWNER_REASON, PermissionContextV2Schema, permissionCodePointCompare, } from "../conversations/events.js";
@@ -25,12 +25,14 @@ import { coversHost, projectReachOf } from "./modes.js";
25
25
  import { EscalationGrantMissingError, isExecutionMethod, parseStartingExecutionGrants, } from "./operation-authority-types.js";
26
26
  import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
27
27
  import { assertAuthorityHeld, PermissionAuthorityLock } from "./permission-authority-lock.js";
28
+ import { PermissionAdmissionUnavailable, runtimeReportVerdict, } from "./permission-availability.js";
28
29
  import { PermissionCallGrants } from "./permission-call-grants.js";
29
30
  import { PermissionConfigPublication } from "./permission-config-publication.js";
30
31
  import { PermissionContextSubjectChanged, } from "./permission-context-types.js";
31
32
  import { hostsWithinOuter, PermissionFacts, permissionScopeHash } from "./permission-facts.js";
32
33
  import { ESCALATION_UNATTENDED_WHY, escalationCeilingWhy, escalationRuntimeWhy, normalizePermissionExpansion, runtimeWriteRootRefusal, withinDirectory, } from "./review/permission-candidate.js";
33
34
  const UNPROVED_ENVIRONMENT = "The device's installed environment is not verified yet; it is checked when the device starts";
35
+ const RUNTIME_CAUSE = { kind: "runtime" };
34
36
  /**
35
37
  * The one verdict over a device's runtime report and its applied environment (B1, B-16): the
36
38
  * recorded permission context withholds its scope exactly when this returns a verdict, and
@@ -42,21 +44,20 @@ const UNPROVED_ENVIRONMENT = "The device's installed environment is not verified
42
44
  */
43
45
  function withheldScope(input) {
44
46
  const { availability, applied } = input;
45
- if (availability.state !== "supported")
46
- return { state: availability.state, reason: availability.reason };
47
+ if (availability.state === "unprobed")
48
+ return { state: "unprobed", reason: availability.reason };
49
+ if (availability.state === "unsupported")
50
+ return {
51
+ state: "unsupported",
52
+ reason: availability.reason,
53
+ cause: availability.cause ?? RUNTIME_CAUSE,
54
+ };
47
55
  if (applied === null ||
48
56
  applied.location !== input.location ||
49
57
  (input.projectPath === null && input.workingRoot !== applied.roots.workspace))
50
58
  return { state: "unprobed", reason: UNPROVED_ENVIRONMENT };
51
- // a local machine's sandbox is per operation; only a cloud provider's instance is the sandbox
52
- if (availability.report.boundary === "instance" && input.location === "local")
53
- return { state: "unsupported", reason: "A local device cannot report an instance boundary" };
54
- if (availability.report.restricted === null && !instanceSupported(availability.report))
55
- return {
56
- state: "unsupported",
57
- reason: availability.report.unavailableReason ?? "This device's runtime cannot enforce its sandbox",
58
- };
59
- return null;
59
+ const verdict = runtimeReportVerdict(availability.report, input.location);
60
+ return verdict === null ? null : { state: "unsupported", reason: verdict, cause: RUNTIME_CAUSE };
60
61
  }
61
62
  /**
62
63
  * The profile every kernel read is sent with: a restricted one, so the runtime enforces its single
@@ -423,10 +424,10 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
423
424
  throw new ApiError("forbidden", "Unknown sandbox operation");
424
425
  // the recorded context withholds its scope for exactly these states (B-16)
425
426
  if (f.admissionRefusal) {
426
- // a runtime that cannot enforce the profile is the typed pre-effect refusal: the model gets
427
- // the actionable unsupported text, never the generic "may not have completed" one
427
+ // a device that cannot run scoped work is the typed pre-effect refusal: the model gets the
428
+ // kernel's text for its cause, never the generic "may not have completed" one
428
429
  if (f.availability.state === "unsupported")
429
- throw new SandboxPermissionUnsupportedError(f.admissionRefusal);
430
+ throw new PermissionAdmissionUnavailable(f.availability.cause ?? RUNTIME_CAUSE, f.admissionRefusal);
430
431
  throw new ApiError("forbidden", f.admissionRefusal);
431
432
  }
432
433
  const operationId = randomUUID();
@@ -61,9 +61,9 @@ export function launchRefusedText(kind) {
61
61
  case "denied":
62
62
  return "the command or its output file is outside what this conversation may use on the device; choose a working directory this conversation may write to";
63
63
  case "unsupported":
64
- return "this device cannot run background tasks with this conversation's permissions; ask the user to choose another permission profile or device";
64
+ return "the device refused it because it cannot enforce its sandbox limits; ask the device's owner to update capybara-device (or a super admin to update the device's sandbox plugin), or continue without the device";
65
65
  default:
66
- return "the device refused the start; check that the device is connected and its permission profile allows background tasks, then retry the call";
66
+ return "the device refused the start; check that the device is connected, then retry the call";
67
67
  }
68
68
  }
69
69
  export function operationResult(value) {
@@ -1,4 +1,28 @@
1
- import type { SandboxPermissionSupport, SandboxProvider } from "@capybara-hq/plugin-sdk";
1
+ import { type SandboxPermissionSupport, SandboxPermissionUnsupportedError, type SandboxProvider } from "@capybara-hq/plugin-sdk";
2
+ /**
3
+ * Why a device cannot run permission-scoped work, for people and for the kernel-rendered admission
4
+ * text (ruling R9): an outdated sandbox provider plugin, or a runtime that cannot enforce the
5
+ * sandbox. The recorded `permission_context` keeps only `{ state, reason }`.
6
+ */
7
+ export type PermissionAvailabilityCause = {
8
+ kind: "provider-outdated";
9
+ plugin: string;
10
+ version: string;
11
+ } | {
12
+ kind: "runtime";
13
+ };
14
+ /**
15
+ * Admission's refusal of device work on a device that cannot run permission-scoped operations:
16
+ * nothing was sent. It extends {@link SandboxPermissionUnsupportedError} (and keeps its name), so
17
+ * every check that treats that error as a definite refusal treats this one the same way; the
18
+ * model's text is rendered from `cause` (`admissionUnavailableText`), never from the message,
19
+ * which is the availability reason (a provider may write it). Exported to tools from
20
+ * `tools/builtins/sandbox/common.ts`.
21
+ */
22
+ export declare class PermissionAdmissionUnavailable extends SandboxPermissionUnsupportedError {
23
+ readonly cause: PermissionAvailabilityCause;
24
+ constructor(cause: PermissionAvailabilityCause, reason: string);
25
+ }
2
26
  /** Read models never provision or probe. Runtime activation will persist provenance-bound reports. */
3
27
  export type PermissionAvailability = {
4
28
  state: "supported";
@@ -6,6 +30,7 @@ export type PermissionAvailability = {
6
30
  } | {
7
31
  state: "unsupported";
8
32
  reason: string;
33
+ cause?: PermissionAvailabilityCause;
9
34
  } | {
10
35
  state: "unprobed";
11
36
  reason: string;
@@ -13,6 +38,27 @@ export type PermissionAvailability = {
13
38
  export declare const unprobedPermissionAvailability: () => PermissionAvailability;
14
39
  /** Method presence is only an unknown runtime candidate, never evidence of enforcement support.
15
40
  * No capability probe or lifecycle operation runs here, even for an empty or suspended device.
16
- * Task 6 records provenance-bound runtime reports before user execution can be admitted.
41
+ * Task 6 records provenance-bound runtime reports before user execution can be admitted. A
42
+ * provider without the permission-scoped methods is an outdated plugin, named with its version
43
+ * (ruling R9).
44
+ */
45
+ export declare function permissionAvailabilityFor(provider: {
46
+ impl: SandboxProvider;
47
+ plugin: string;
48
+ version?: string;
49
+ } | undefined): PermissionAvailability;
50
+ /**
51
+ * Why a recorded runtime report cannot run permission-scoped work on a device at `location`, or
52
+ * null when it can: the one rule admission's withheld scope and the people's view both apply
53
+ * (the "one verdict" rule, B-16). A local machine's sandbox is per operation (only a cloud
54
+ * provider's instance is the sandbox); a runtime without a restricted mode and without an instance
55
+ * boundary only runs outside its sandbox.
56
+ */
57
+ export declare function runtimeReportVerdict(report: SandboxPermissionSupport, location: "local" | "cloud"): string | null;
58
+ /**
59
+ * The availability of device work as people see it (the HTTP views): a supported report that
60
+ * {@link runtimeReportVerdict} refuses reads `unsupported` with the runtime cause, as admission
61
+ * refuses it. Kernel readers keep the raw availability (its report decides the provider layer and
62
+ * the kernel read route).
17
63
  */
18
- export declare function permissionAvailabilityFor(provider: SandboxProvider | undefined): PermissionAvailability;
64
+ export declare function deviceWorkAvailability(availability: PermissionAvailability, location: "local" | "cloud"): PermissionAvailability;
@@ -1,19 +1,74 @@
1
+ import { instanceSupported, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
2
+ /**
3
+ * Admission's refusal of device work on a device that cannot run permission-scoped operations:
4
+ * nothing was sent. It extends {@link SandboxPermissionUnsupportedError} (and keeps its name), so
5
+ * every check that treats that error as a definite refusal treats this one the same way; the
6
+ * model's text is rendered from `cause` (`admissionUnavailableText`), never from the message,
7
+ * which is the availability reason (a provider may write it). Exported to tools from
8
+ * `tools/builtins/sandbox/common.ts`.
9
+ */
10
+ export class PermissionAdmissionUnavailable extends SandboxPermissionUnsupportedError {
11
+ cause;
12
+ constructor(cause, reason) {
13
+ super(reason);
14
+ this.cause = cause;
15
+ }
16
+ }
1
17
  export const unprobedPermissionAvailability = () => ({
2
18
  state: "unprobed",
3
19
  reason: "Checked when this device starts",
4
20
  });
5
21
  /** Method presence is only an unknown runtime candidate, never evidence of enforcement support.
6
22
  * No capability probe or lifecycle operation runs here, even for an empty or suspended device.
7
- * Task 6 records provenance-bound runtime reports before user execution can be admitted.
23
+ * Task 6 records provenance-bound runtime reports before user execution can be admitted. A
24
+ * provider without the permission-scoped methods is an outdated plugin, named with its version
25
+ * (ruling R9).
8
26
  */
9
27
  export function permissionAvailabilityFor(provider) {
10
- if (!provider ||
11
- typeof provider.operation !== "function" ||
12
- typeof provider.permissionSupport !== "function" ||
13
- typeof provider.revokeOperation !== "function")
28
+ if (!provider)
29
+ return {
30
+ state: "unsupported",
31
+ reason: "This device's sandbox provider is not available",
32
+ cause: { kind: "runtime" },
33
+ };
34
+ const { impl, plugin } = provider;
35
+ if (typeof impl.operation !== "function" ||
36
+ typeof impl.permissionSupport !== "function" ||
37
+ typeof impl.revokeOperation !== "function") {
38
+ const version = provider.version ?? "unknown version";
14
39
  return {
15
40
  state: "unsupported",
16
- reason: "This provider does not implement permission-scoped operations; update its plugin or device program",
41
+ reason: `This device's sandbox plugin (${plugin} ${version}) does not implement permission-scoped operations; a super admin updates it`,
42
+ cause: { kind: "provider-outdated", plugin, version },
17
43
  };
44
+ }
18
45
  return unprobedPermissionAvailability();
19
46
  }
47
+ /**
48
+ * Why a recorded runtime report cannot run permission-scoped work on a device at `location`, or
49
+ * null when it can: the one rule admission's withheld scope and the people's view both apply
50
+ * (the "one verdict" rule, B-16). A local machine's sandbox is per operation (only a cloud
51
+ * provider's instance is the sandbox); a runtime without a restricted mode and without an instance
52
+ * boundary only runs outside its sandbox.
53
+ */
54
+ export function runtimeReportVerdict(report, location) {
55
+ if (report.boundary === "instance" && location === "local")
56
+ return "A local device cannot report an instance boundary";
57
+ if (report.restricted === null && !instanceSupported(report))
58
+ return report.unavailableReason ?? "This device's runtime cannot enforce its sandbox";
59
+ return null;
60
+ }
61
+ /**
62
+ * The availability of device work as people see it (the HTTP views): a supported report that
63
+ * {@link runtimeReportVerdict} refuses reads `unsupported` with the runtime cause, as admission
64
+ * refuses it. Kernel readers keep the raw availability (its report decides the provider layer and
65
+ * the kernel read route).
66
+ */
67
+ export function deviceWorkAvailability(availability, location) {
68
+ if (availability.state !== "supported")
69
+ return availability;
70
+ const reason = runtimeReportVerdict(availability.report, location);
71
+ return reason === null
72
+ ? availability
73
+ : { state: "unsupported", reason, cause: { kind: "runtime" } };
74
+ }
@@ -1,6 +1,7 @@
1
1
  import type { PermissionProfile } from "@capybara-hq/plugin-sdk";
2
2
  import type { HostGrantCeiling } from "./device-sandbox.js";
3
3
  import type { EffectiveDevicePolicy } from "./modes.js";
4
+ import type { PermissionAvailabilityCause } from "./permission-availability.js";
4
5
  import type { AppliedOuterNetwork } from "./permission-context-types.js";
5
6
  export type PermissionCallRef = {
6
7
  runId: string;
@@ -109,9 +110,11 @@ export type PermissionReviewSnapshot = Readonly<Omit<PermissionCallBinding, "too
109
110
  broadProjectReach: boolean;
110
111
  unattended: boolean;
111
112
  fullConsent: boolean;
113
+ /** An `unsupported` state carries its cause (R9), from which admission renders the text. */
112
114
  availability: {
113
115
  state: string;
114
116
  reason?: string;
117
+ cause?: PermissionAvailabilityCause;
115
118
  };
116
119
  /**
117
120
  * The reason admission refuses this device (B-16): the recorded permission context withholds
@@ -185,10 +185,15 @@ export declare class PermissionFacts {
185
185
  hostCeiling: HostGrantCeiling;
186
186
  };
187
187
  availability: PermissionAvailability;
188
+ location: "cloud" | "local";
188
189
  sandbox: DeviceSandbox;
189
190
  outsideSandboxCeiling: boolean;
190
191
  broadProjectReach: boolean;
191
192
  }>;
193
+ /**
194
+ * The preview people see before choosing a profile: availability is the device-work verdict
195
+ * ({@link deviceWorkAvailability}). Kernel callers only use it as a check.
196
+ */
192
197
  preview(orgId: string, accountId: string, deviceId: string, project?: string): Promise<{
193
198
  deviceId: string;
194
199
  project: string | null;
@@ -201,10 +206,11 @@ export declare class PermissionFacts {
201
206
  restrictedProjectReach: "os-user" | "workspace";
202
207
  hostCeiling: HostGrantCeiling;
203
208
  };
204
- availability: PermissionAvailability;
209
+ location: "cloud" | "local";
205
210
  sandbox: DeviceSandbox;
206
211
  outsideSandboxCeiling: boolean;
207
212
  broadProjectReach: boolean;
213
+ availability: PermissionAvailability;
208
214
  }>;
209
215
  view(orgId: string, accountId: string, row: PermissionRoot): Promise<{
210
216
  profile: PermissionProfile;
@@ -222,6 +228,27 @@ export declare class PermissionFacts {
222
228
  sandbox: DeviceSandbox | null;
223
229
  startingWorkNotice: string;
224
230
  }>;
231
+ /**
232
+ * {@link view} as people see it (`GET …/permissions`): availability is the device-work verdict
233
+ * admission applies ({@link deviceWorkAvailability}), so a device whose runtime cannot enforce
234
+ * its sandbox reads `unsupported` with the runtime cause. Kernel readers use {@link view}.
235
+ */
236
+ peopleView(orgId: string, accountId: string, row: PermissionRoot): Promise<{
237
+ availability: PermissionAvailability;
238
+ profile: PermissionProfile;
239
+ revision: number;
240
+ rootConversationId: string;
241
+ deviceId: string | null;
242
+ consentScope: {
243
+ deviceId: string;
244
+ scopeRevision: string;
245
+ } | null;
246
+ scopeRevision: string | null;
247
+ outsideSandboxCeiling: boolean;
248
+ broadProjectReach: boolean;
249
+ sandbox: DeviceSandbox | null;
250
+ startingWorkNotice: string;
251
+ }>;
225
252
  /**
226
253
  * {@link view} plus how the actor reached the root's device: none selected, usable, refused for
227
254
  * this actor (`device.not_found`: not its device), or its provider is not the current one. The
@@ -229,6 +256,7 @@ export declare class PermissionFacts {
229
256
  */
230
257
  viewWithAccess(orgId: string, accountId: string, row: PermissionRoot): Promise<{
231
258
  access: "actor-device-access" | "device" | "no-device" | "provider-unavailable";
259
+ location: "cloud" | "local" | null;
232
260
  view: {
233
261
  profile: PermissionProfile;
234
262
  revision: number;
@@ -26,7 +26,7 @@ import { canonicalHostCeiling, effectiveDeviceSandbox, hostGrantCeiling, hostGra
26
26
  import { readDeviceSandboxSettings } from "./device-sandbox-settings.js";
27
27
  import { appliedOf, appliedWider, cloudChosenMode, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
28
28
  import { assertAuthorityHeld } from "./permission-authority-lock.js";
29
- import { permissionAvailabilityFor, } from "./permission-availability.js";
29
+ import { deviceWorkAvailability, permissionAvailabilityFor, } from "./permission-availability.js";
30
30
  import { readCurrentReport, readRuntimeReport, sameRuntimeIdentity, } from "./permission-runtime-reports.js";
31
31
  import { providerForDevice, SandboxProviders } from "./providers.js";
32
32
  import { homeOf } from "./review/rules.js";
@@ -303,7 +303,7 @@ let PermissionFacts = class PermissionFacts {
303
303
  .where("org_id", "=", orgId)
304
304
  .executeTakeFirst();
305
305
  const provider = device ? providerForDevice(this.providers, device.provider) : undefined;
306
- let availability = permissionAvailabilityFor(provider?.impl);
306
+ let availability = permissionAvailabilityFor(provider);
307
307
  if (availability.state === "unprobed" && provider) {
308
308
  const machine = provider.plugin === "@local"
309
309
  ? await this.db
@@ -314,6 +314,9 @@ let PermissionFacts = class PermissionFacts {
314
314
  .executeTakeFirst()
315
315
  : undefined;
316
316
  availability = await readRuntimeReport(this.db.db, deviceId, provider.plugin, machine?.program_version ?? provider.version);
317
+ // a recorded runtime report that cannot enforce the sandbox is the runtime's cause
318
+ if (availability.state === "unsupported")
319
+ availability = { ...availability, cause: { kind: "runtime" } };
317
320
  }
318
321
  return availability;
319
322
  }
@@ -535,6 +538,7 @@ let PermissionFacts = class PermissionFacts {
535
538
  consentIdentity,
536
539
  consentReach,
537
540
  availability,
541
+ location: source === "local" ? "local" : "cloud",
538
542
  sandbox,
539
543
  outsideSandboxCeiling: sandbox.outsideSandbox,
540
544
  // B2: broad restricted reach (directories outside the working root) is the owner's reach
@@ -546,16 +550,32 @@ let PermissionFacts = class PermissionFacts {
546
550
  : policy.mode === "auto" && policy.allowedMode === "auto"),
547
551
  };
548
552
  }
553
+ /**
554
+ * The preview people see before choosing a profile: availability is the device-work verdict
555
+ * ({@link deviceWorkAvailability}). Kernel callers only use it as a check.
556
+ */
549
557
  async preview(orgId, accountId, deviceId, project) {
550
558
  await this.devices.usable(orgId, accountId, deviceId);
551
559
  const binding = project === undefined
552
560
  ? null
553
561
  : await this.resolveProjectForBinding(orgId, deviceId, accountId, project);
554
- return this.scope(orgId, deviceId, binding?.path ?? null, project ?? null);
562
+ const scope = await this.scope(orgId, deviceId, binding?.path ?? null, project ?? null);
563
+ return { ...scope, availability: deviceWorkAvailability(scope.availability, scope.location) };
555
564
  }
556
565
  async view(orgId, accountId, row) {
557
566
  return (await this.viewWithAccess(orgId, accountId, row)).view;
558
567
  }
568
+ /**
569
+ * {@link view} as people see it (`GET …/permissions`): availability is the device-work verdict
570
+ * admission applies ({@link deviceWorkAvailability}), so a device whose runtime cannot enforce
571
+ * its sandbox reads `unsupported` with the runtime cause. Kernel readers use {@link view}.
572
+ */
573
+ async peopleView(orgId, accountId, row) {
574
+ const { view, location } = await this.viewWithAccess(orgId, accountId, row);
575
+ return location === null
576
+ ? view
577
+ : { ...view, availability: deviceWorkAvailability(view.availability, location) };
578
+ }
559
579
  /**
560
580
  * {@link view} plus how the actor reached the root's device: none selected, usable, refused for
561
581
  * this actor (`device.not_found`: not its device), or its provider is not the current one. The
@@ -580,14 +600,17 @@ let PermissionFacts = class PermissionFacts {
580
600
  }
581
601
  }
582
602
  const consent = row.permission_consent;
603
+ // Auto holds whatever the device supports (device tools refuse at admission instead) and
604
+ // without a device (no consent row, ruling R8); with a device it needs that device to be
605
+ // reachable and its consent to still cover the device's ceilings
583
606
  const profile = row.permission_profile === "full-access" &&
584
- (!preview ||
585
- preview.availability.state === "unsupported" ||
586
- !consentHolds(consent, row.device_id, preview))
607
+ row.device_id !== null &&
608
+ (!preview || !consentHolds(consent, row.device_id, preview))
587
609
  ? "approve-for-me"
588
610
  : row.permission_profile;
589
611
  return {
590
612
  access,
613
+ location: preview?.location ?? null,
591
614
  view: {
592
615
  profile,
593
616
  revision: row.permission_revision,