@capybara-hq/kernel 0.1.0-rc.72 → 0.1.0-rc.74

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 (81) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/catalog/admin-catalog.schemas.d.ts +3 -1
  3. package/dist/catalog/admin-catalog.schemas.js +6 -2
  4. package/dist/catalog/marketplaces.service.d.ts +1 -1
  5. package/dist/catalog/org-catalog.schemas.d.ts +3 -1
  6. package/dist/catalog/org-catalog.schemas.js +3 -1
  7. package/dist/catalog/plugin-package.js +7 -5
  8. package/dist/catalog/reserved-names.js +3 -9
  9. package/dist/channels/actions.js +4 -0
  10. package/dist/channels/cards.d.ts +10 -7
  11. package/dist/channels/cards.js +23 -12
  12. package/dist/channels/phrases.d.ts +24 -2
  13. package/dist/channels/phrases.js +12 -2
  14. package/dist/ctx/secrets.d.ts +4 -2
  15. package/dist/ctx/secrets.js +19 -5
  16. package/dist/db/kernel-schema.d.ts +14 -0
  17. package/dist/devices/conversation-devices.d.ts +3 -2
  18. package/dist/devices/conversation-devices.js +9 -4
  19. package/dist/devices/device-projects.service.d.ts +22 -27
  20. package/dist/devices/device-projects.service.js +36 -41
  21. package/dist/devices/devices.controller.d.ts +3 -5
  22. package/dist/devices/devices.controller.js +4 -17
  23. package/dist/devices/devices.schemas.d.ts +1 -1
  24. package/dist/devices/devices.schemas.js +1 -1
  25. package/dist/devices/devices.service.d.ts +72 -52
  26. package/dist/devices/devices.service.js +158 -93
  27. package/dist/devices/project-rules.d.ts +6 -8
  28. package/dist/devices/project-rules.js +5 -11
  29. package/dist/dial-in/auth.controller.d.ts +1 -1
  30. package/dist/dial-in/auth.controller.js +1 -1
  31. package/dist/dial-in/auth.service.d.ts +4 -0
  32. package/dist/dial-in/auth.service.js +16 -2
  33. package/dist/dial-in/machines.d.ts +5 -4
  34. package/dist/dial-in/machines.js +5 -4
  35. package/dist/errors.d.ts +8 -3
  36. package/dist/errors.js +8 -3
  37. package/dist/extensions/admin-ops.js +2 -1
  38. package/dist/extensions/bootstrap-extra.d.ts +11 -1
  39. package/dist/extensions/bootstrap-extra.js +21 -1
  40. package/dist/extensions/bootstrap-manifest.d.ts +14 -0
  41. package/dist/extensions/bootstrap-manifest.js +23 -0
  42. package/dist/extensions/bootstrap-packages.d.ts +87 -0
  43. package/dist/extensions/bootstrap-packages.js +263 -0
  44. package/dist/extensions/bootstrap.d.ts +27 -71
  45. package/dist/extensions/bootstrap.js +85 -329
  46. package/dist/extensions/guide-places.d.ts +9 -0
  47. package/dist/extensions/guide-places.js +32 -22
  48. package/dist/extensions/permission-set.d.ts +1 -1
  49. package/dist/extensions/permission-set.js +1 -1
  50. package/dist/extensions/plugin-guides.d.ts +20 -2
  51. package/dist/extensions/plugin-guides.js +39 -14
  52. package/dist/identity/sso-paths.d.ts +7 -0
  53. package/dist/identity/sso-paths.js +13 -0
  54. package/dist/identity/sso.js +3 -2
  55. package/dist/index.d.ts +3 -1
  56. package/dist/index.js +3 -1
  57. package/dist/lifecycle/kernel-lifecycle.js +2 -2
  58. package/dist/platform/exclusions.js +2 -7
  59. package/dist/platform/ops/devices.ops.js +11 -7
  60. package/dist/platform/ops/setup.ops.js +1 -1
  61. package/dist/runtime/project/knowledge.service.js +6 -5
  62. package/dist/sandbox/device-sandbox.d.ts +11 -0
  63. package/dist/sandbox/device-sandbox.js +29 -0
  64. package/dist/sandbox/modes.d.ts +16 -4
  65. package/dist/sandbox/modes.js +12 -0
  66. package/dist/sandbox/permission-facts.d.ts +12 -2
  67. package/dist/sandbox/permission-facts.js +14 -4
  68. package/dist/sandbox/sandbox.service.d.ts +18 -11
  69. package/dist/sandbox/sandbox.service.js +51 -24
  70. package/dist/setup/setup-guides.service.d.ts +2 -2
  71. package/dist/setup/setup-guides.service.js +1 -1
  72. package/dist/tools/approvals.service.d.ts +31 -11
  73. package/dist/tools/approvals.service.js +55 -19
  74. package/dist/tools/builtins/sandbox/common.d.ts +2 -2
  75. package/dist/tools/builtins/sandbox/common.js +2 -2
  76. package/dist/tools/network-asks.d.ts +103 -20
  77. package/dist/tools/network-asks.js +133 -18
  78. package/dist/tools/pipeline.d.ts +5 -0
  79. package/dist/tools/pipeline.js +15 -8
  80. package/package.json +3 -3
  81. package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
@@ -1,4 +1,4 @@
1
- import type { DeviceReport, LocalizedName, SandboxBrowseScope, SandboxLimits, SandboxOperationScope } from "@capybara-hq/plugin-sdk";
1
+ import { type DeviceReport, type LocalizedName, type SandboxBrowseScope, type SandboxLimits, type SandboxOperationScope } from "@capybara-hq/plugin-sdk";
2
2
  import { type Selectable } from "kysely";
3
3
  import type { SandboxOperationIntentsTable } from "../db/kernel-schema.js";
4
4
  import { DialInHandlers } from "../dial-in/handlers.js";
@@ -6,11 +6,13 @@ import { DialInMachines } from "../dial-in/machines.js";
6
6
  import { DialInRelay } from "../dial-in/relay.js";
7
7
  import { ApiError } from "../errors.js";
8
8
  import { ExtensionDisplayNames } from "../extensions/display-name.js";
9
+ import { PluginGuides, type SetupGuideRef } from "../extensions/plugin-guides.js";
9
10
  import { type PersonRef } from "../identity/account-avatar.js";
10
11
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
11
12
  import { KernelDb } from "../infra/database/kernel-db.js";
12
13
  import { TransactionHost } from "../infra/database/transaction-host.js";
13
14
  import { OutboxService } from "../infra/outbox/outbox.service.js";
15
+ import type { OrgRole } from "../orgs/roles.js";
14
16
  import type { DeviceModeLevel } from "../runtime/context/device-paths.js";
15
17
  import { DeviceReports } from "../sandbox/device-reports.js";
16
18
  import type { DeviceSandbox, DeviceSandboxLayer, HostGrantCeiling } from "../sandbox/device-sandbox.js";
@@ -30,6 +32,11 @@ export interface DeviceView {
30
32
  ownerKind: "personal";
31
33
  /** The provider it is bound to for life (`devices.provider`). */
32
34
  provider: string | null;
35
+ /**
36
+ * The provider's extension display name (`ExtensionDisplayNames`), also while the provider is
37
+ * off or not loaded when the name is known; null otherwise.
38
+ */
39
+ providerDisplayName: LocalizedName | null;
33
40
  /**
34
41
  * Its provider serves its devices over the dial-in channel (a machine signs in to the device);
35
42
  * false while the provider is not loaded here.
@@ -106,52 +113,26 @@ export interface DeviceSandboxView {
106
113
  /** How many recent setting changes a device view lists. */
107
114
  export declare const RECENT_POLICY_CHANGES = 10;
108
115
  /**
109
- * One setting change of a device, as its owner sees it on the device page:
110
- * - `policy` (`device.policy_changed`): hosts removed from a local machine's allowlist by the
111
- * platform (`web`, `im`), or added or removed on the machine by its owner (`device`,
112
- * `capybara-device policy ...`); one sent whose answer never came (`device.policy_unknown`) or
113
- * that failed (`device.policy_failed`) too;
114
- * - `ceiling` (`device.owner_ceiling_changed`): a machine's owner ceiling changed, narrowed from the
115
- * device page (`web`) or on the machine (`device`);
116
- * - `network` (`device.network_changed`): a cloud device's sandbox network changed on its device
117
- * page (`web`), through an API token (`token`), or by an agent's Platform tool call (`agent`).
116
+ * One setting change of a device, as its owner sees it on the device page: its sandbox network
117
+ * changed (`device.network_changed`), whatever its provider.
118
118
  */
119
119
  export interface DeviceSettingChangeView {
120
120
  at: string;
121
- kind: "policy" | "ceiling" | "network";
122
- /** Hosts added to / removed from the local allowlist (`policy` only; else empty). */
123
- add: string[];
124
- remove: string[];
125
- /** The owner ceiling change (`ceiling` only; else null). `from` is null when the row does not say. */
126
- ceiling: {
127
- from: DeviceCeilingFacts | null;
128
- to: DeviceCeilingFacts;
129
- } | null;
130
- /** The cloud network change (`network` only; else null). */
121
+ kind: "network";
131
122
  network: {
132
123
  from: DeviceNetworkSetting;
133
124
  to: DeviceNetworkSetting;
134
- } | null;
125
+ };
135
126
  /** The deciding account (null when the account is gone). */
136
127
  by: PersonRef | null;
137
128
  /**
138
- * `device`: made or reported on the machine itself; `token`: through an API token; `agent`: an
139
- * agent's Platform tool call.
129
+ * Where it was decided: `web` on the device page or a network approval there, `im` a network
130
+ * approval on an IM card, `token` through an API token, `agent` an agent's Platform tool call.
140
131
  */
141
- via: "web" | "im" | "device" | "token" | "agent";
142
- /**
143
- * What became of a `policy` change sent to the machine: `applied` (also every change made or
144
- * reported on the machine, and every other row); `unknown`, its answer never came, `failed`, the
145
- * machine refused it, never received it or stopped while applying it.
146
- */
147
- outcome: "applied" | "unknown" | "failed";
148
- }
149
- /** One side of a {@link DeviceSettingChangeView.ceiling} change. */
150
- export interface DeviceCeilingFacts {
151
- outsideSandbox: boolean;
152
- restrictedProjectReach?: "workspace" | "os-user";
153
- network?: "open" | "allowlist";
132
+ via: DeviceNetworkChangeVia;
154
133
  }
134
+ /** Where a device's network change was decided ({@link DeviceSettingChangeView.via}). */
135
+ export type DeviceNetworkChangeVia = "web" | "im" | "token" | "agent";
155
136
  /** A device's stored network setting: `mode` null follows its org. */
156
137
  export interface DeviceNetworkSetting {
157
138
  mode: "open" | "allowlist" | "none" | null;
@@ -194,6 +175,15 @@ export interface DeviceProviderOption {
194
175
  plugin: string;
195
176
  /** The extension's display name; null when it has none. */
196
177
  displayName: LocalizedName | null;
178
+ /** The catalog item's description (`{ en, zh? }`); null when the item has none. */
179
+ description: {
180
+ en: string;
181
+ zh?: string;
182
+ } | null;
183
+ /** The provider declares `permissions.dialIn`: its devices are made by the machine signing in. */
184
+ dialIn: boolean;
185
+ /** Its device-connection setup guide, when the org's catalog shows it; null otherwise. */
186
+ guide: SetupGuideRef | null;
197
187
  }
198
188
  /** A device sign-in names a provider that is no dial-in provider on in the org (403). */
199
189
  export declare const dialInProviderUnavailable: (provider: string) => ApiError;
@@ -227,24 +217,31 @@ export declare class DevicesService {
227
217
  private readonly reports;
228
218
  /** The dial-in providers on in an org (a device signed in from a machine). */
229
219
  private readonly dialIn;
220
+ /** The providers' device-connection guides. */
221
+ private readonly guides;
230
222
  constructor(db: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get" | "fieldSource">, selection: Pick<DeviceProviderSelection, "onInOrg" | "isOnInOrg" | "defaultFor">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "limitsState">, sandboxJobs: Pick<SandboxJobs, "resetFiles">,
231
223
  /** Owes a deleted device's destruction in the delete's transaction. */
232
224
  outbox: Pick<OutboxService, "add">, access: Pick<DeviceAccess, "usable">,
233
225
  /** Whether a dial-in device's machine is connected now. */
234
226
  relay: Pick<DialInRelay, "online">,
235
227
  /** Each device's provider (whether it serves its devices over the dial-in channel). */
236
- providers: Pick<DeviceProviders, "forDevice">, machines: Pick<DialInMachines, "revoke" | "revokeActive">, ceilings: PermissionCeilingWrites, facts: Pick<PermissionFacts, "deviceSandbox" | "deviceSandboxFacts">, displayNames: Pick<ExtensionDisplayNames, "many">,
228
+ providers: Pick<DeviceProviders, "forDevice">, machines: Pick<DialInMachines, "revokeActive">, ceilings: PermissionCeilingWrites, facts: Pick<PermissionFacts, "deviceSandbox" | "deviceSandboxFacts">, displayNames: Pick<ExtensionDisplayNames, "many">,
237
229
  /** Each device's stored provider report (read only; never asks the provider). */
238
230
  reports: Pick<DeviceReports, "read">,
239
231
  /** The dial-in providers on in an org (a device signed in from a machine). */
240
- dialIn: Pick<DialInHandlers, "onInOrg">);
232
+ dialIn: Pick<DialInHandlers, "onInOrg">,
233
+ /** The providers' device-connection guides. */
234
+ guides: Pick<PluginGuides, "deviceGuides">);
241
235
  /**
242
236
  * The person's live devices in the org, the default first, then by creation, with the device
243
237
  * providers on in the org and its default one. With a default provider serving the org the
244
238
  * default device is created first if missing (its first need, spec §4.2 item 7; an existing one
245
- * is only read, whatever its provider's state).
239
+ * is only read, whatever its provider's state). `role` is the caller's role in the org: it
240
+ * decides which setup guides the org's catalog shows them (none without it).
246
241
  */
247
- list(orgId: string, accountId: string): Promise<DeviceList>;
242
+ list(orgId: string, accountId: string, role?: OrgRole): Promise<DeviceList>;
243
+ /** The latest catalog descriptions of `names` (one query); an item without one is absent. */
244
+ private catalogDescriptions;
248
245
  /** One of the person's live devices; anyone else's (or a missing one) → `not_found`. */
249
246
  get(orgId: string, accountId: string, id: string): Promise<DeviceView>;
250
247
  /**
@@ -346,9 +343,36 @@ export declare class DevicesService {
346
343
  * transaction: a narrowing bumps the device epoch and revokes the admitted or started work it
347
344
  * takes ({@link networkNarrowingRevokes}; the revocations are owed through the outbox) and keeps
348
345
  * Full consent; a widening resets Full consent with a `permission_profile_changed` event.
349
- * Audited `device.network_changed` (`via`: `web`, `token` for an API token, or the agent's).
346
+ * Audited `device.network_changed` (`via`: `opts.via` (a network approval's), else `web`,
347
+ * `token` for an API token, or the agent's in `auditDetail`).
350
348
  */
351
349
  private networkLocked;
350
+ /**
351
+ * The ordered prelude of {@link addNetworkHostsIn} in a caller's transaction: the person's
352
+ * membership, the device row and the device's permission write lock (authority levels platform,
353
+ * org shared, device exclusive). A caller that adds hosts inside its own transaction (a network
354
+ * approval's decision) runs this in its own `withOrderedLocks` prelude, after its org row and
355
+ * before any conversation, approval or run row, the place of the authority locks in the global
356
+ * lock order; refuses `device.not_found` for anyone else's or a deleted device.
357
+ */
358
+ lockNetworkAddSubject(orgId: string, accountId: string, deviceId: string): Promise<void>;
359
+ /**
360
+ * Adds `hosts` to one of the person's devices' own network list: a network approval decided
361
+ * "add to this device's list" (`via`: where it was decided). In a caller's transaction (the
362
+ * approval decision's) it joins it and requires the device's permission write lock already held
363
+ * there ({@link lockNetworkAddSubject} in the caller's ordered prelude; else it throws before
364
+ * writing); with no transaction it takes that prelude itself ({@link withOrderedLocks}). It
365
+ * takes no distributed lock. The write is a network change like `PATCH` ({@link networkLocked}:
366
+ * audited `device.network_changed` from → to, listed as a recent change, the device epoch bumped
367
+ * and the instance marked for its next use). Refuses with `device.network_not_allowed`, writing
368
+ * nothing, unless the stored network is `allowlist` with a host list of its own (a device
369
+ * following its org's hosts already allows every host its list could name) and every host may
370
+ * join that list (`deviceListAddRefusal`). Hosts its list already covers change nothing; own
371
+ * hosts the org's hosts no longer cover (in effect nowhere) leave the list with the addition.
372
+ */
373
+ addNetworkHostsIn(orgId: string, accountId: string, deviceId: string, hosts: string[], via: "web" | "im"): Promise<void>;
374
+ /** {@link addNetworkHostsIn} under the locks of its prelude (naming them again re-checks). */
375
+ private addNetworkHostsLocked;
352
376
  /**
353
377
  * The level a sandbox call in the device runs at now, for the model (legacy `device_paths`, auto
354
378
  * mode spec §4.2), the same for every provider: the kernel-internal tier (`SandboxMode`) with
@@ -375,11 +399,6 @@ export declare class DevicesService {
375
399
  /** The prelude of {@link remove}: the membership, the device row, the device's write lock. */
376
400
  private lockRemovalSubject;
377
401
  private removeIn;
378
- /**
379
- * Disconnects the machine of one of the person's own dial-in devices (it must sign in
380
- * again); see {@link DialInMachines.revoke}.
381
- */
382
- revokeMachine(orgId: string, accountId: string, id: string, actorTokenId?: string): Promise<void>;
383
402
  /**
384
403
  * Starts one of the person's devices over with empty files (after
385
404
  * `device.files_lost`): records the request (audit), then, after the commit, enqueues the
@@ -396,8 +415,9 @@ export declare class DevicesService {
396
415
  * The person's default device in the org: the live one if any, whatever its provider's state
397
416
  * (a default whose provider is off stays the default, unavailable, never demoted or replaced),
398
417
  * else a new default (named by the UI, `name` NULL) bound to the org's default provider
399
- * ({@link DeviceProviderSelection.defaultFor}), else null (no default provider on in the org).
400
- * An existing one is read without locking.
418
+ * ({@link DeviceProviderSelection.defaultFor}), else null: no default provider on in the org, or
419
+ * a dial-in one (a machine must sign in to make its device, so nothing is created for the person;
420
+ * spec §6.4). An existing one is read without locking.
401
421
  *
402
422
  * Creating one first takes the person's membership row (`FOR SHARE`, after the org row), so an
403
423
  * offboarding that removes them cannot leave a live default behind; not a member (any more) →
@@ -427,8 +447,8 @@ export declare class DevicesService {
427
447
  /** Whether `provider` (a device's `devices.provider`) serves its devices over dial-in. */
428
448
  private isDialIn;
429
449
  /**
430
- * The last {@link RECENT_POLICY_CHANGES} setting changes of each device in the org (audit rows
431
- * {@link SETTING_CHANGE_ACTIONS}), newest first, with the deciding account's display name.
450
+ * The last {@link RECENT_POLICY_CHANGES} setting changes of each device in the org (its
451
+ * `device.network_changed` audit rows), newest first, with the deciding account's display name.
432
452
  */
433
453
  private recentChanges;
434
454
  /**
@@ -443,14 +463,14 @@ export declare class DevicesService {
443
463
  private assertNameFree;
444
464
  }
445
465
  /**
446
- * Whether a cloud device's stored network setting widens from `a` to `b`, whatever the network in
466
+ * Whether a device's stored network setting widens from `a` to `b`, whatever the network in
447
467
  * effect now (a stored widening takes effect when a ceiling opens later): a wider mode, where
448
468
  * following the org (null) counts as wider than any explicit mode; or an explicit host list
449
469
  * replaced by none of its own (follow the org's hosts) or gaining a host.
450
470
  */
451
471
  export declare function storedNetworkWidens(a: DeviceNetworkSetting, b: DeviceNetworkSetting): boolean;
452
472
  /**
453
- * What a cloud device's new network takes from admitted or started work (`next`: its sandbox
473
+ * What a device's new network takes from admitted or started work (`next`: its sandbox
454
474
  * after the change): open-network work once it is no longer open, and allowlist work naming a host
455
475
  * its new hosts no longer cover, unless an independent grant the new per-call ceiling still allows
456
476
  * holds it (`hostsNarrowed`).