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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/catalog/admin-catalog.schemas.d.ts +3 -1
  3. package/dist/catalog/admin-catalog.schemas.js +6 -2
  4. package/dist/catalog/marketplaces.service.d.ts +1 -1
  5. package/dist/catalog/org-catalog.schemas.d.ts +3 -1
  6. package/dist/catalog/org-catalog.schemas.js +3 -1
  7. package/dist/catalog/plugin-package.js +7 -5
  8. package/dist/catalog/reserved-names.js +3 -9
  9. package/dist/channels/actions.js +4 -0
  10. package/dist/channels/cards.d.ts +10 -7
  11. package/dist/channels/cards.js +23 -12
  12. package/dist/channels/phrases.d.ts +24 -2
  13. package/dist/channels/phrases.js +12 -2
  14. package/dist/ctx/secrets.d.ts +4 -2
  15. package/dist/ctx/secrets.js +19 -5
  16. package/dist/db/kernel-schema.d.ts +14 -0
  17. package/dist/devices/conversation-devices.d.ts +3 -2
  18. package/dist/devices/conversation-devices.js +9 -4
  19. package/dist/devices/device-projects.service.d.ts +22 -27
  20. package/dist/devices/device-projects.service.js +39 -44
  21. package/dist/devices/devices.controller.d.ts +3 -5
  22. package/dist/devices/devices.controller.js +4 -17
  23. package/dist/devices/devices.schemas.d.ts +1 -1
  24. package/dist/devices/devices.schemas.js +1 -1
  25. package/dist/devices/devices.service.d.ts +75 -52
  26. package/dist/devices/devices.service.js +166 -95
  27. package/dist/devices/project-rules.d.ts +6 -8
  28. package/dist/devices/project-rules.js +5 -11
  29. package/dist/dial-in/auth.service.js +1 -1
  30. package/dist/dial-in/machines.d.ts +4 -15
  31. package/dist/dial-in/machines.js +4 -59
  32. package/dist/errors.d.ts +8 -3
  33. package/dist/errors.js +8 -3
  34. package/dist/extensions/admin-ops.js +2 -1
  35. package/dist/extensions/bootstrap-extra.d.ts +11 -1
  36. package/dist/extensions/bootstrap-extra.js +21 -1
  37. package/dist/extensions/bootstrap-manifest.d.ts +14 -0
  38. package/dist/extensions/bootstrap-manifest.js +23 -0
  39. package/dist/extensions/bootstrap-packages.d.ts +87 -0
  40. package/dist/extensions/bootstrap-packages.js +263 -0
  41. package/dist/extensions/bootstrap.d.ts +27 -71
  42. package/dist/extensions/bootstrap.js +85 -329
  43. package/dist/extensions/guide-places.d.ts +9 -0
  44. package/dist/extensions/guide-places.js +32 -22
  45. package/dist/extensions/plugin-guides.d.ts +20 -2
  46. package/dist/extensions/plugin-guides.js +39 -14
  47. package/dist/http/meta.controller.d.ts +0 -1
  48. package/dist/http/meta.controller.js +2 -6
  49. package/dist/identity/sso-paths.d.ts +7 -0
  50. package/dist/identity/sso-paths.js +13 -0
  51. package/dist/identity/sso.js +3 -2
  52. package/dist/index.d.ts +3 -1
  53. package/dist/index.js +3 -1
  54. package/dist/lifecycle/kernel-lifecycle.js +2 -2
  55. package/dist/platform/exclusions.js +2 -7
  56. package/dist/platform/ops/devices.ops.js +11 -7
  57. package/dist/platform/ops/setup.ops.js +1 -1
  58. package/dist/runtime/project/knowledge.service.js +6 -5
  59. package/dist/sandbox/device-sandbox.d.ts +27 -2
  60. package/dist/sandbox/device-sandbox.js +42 -5
  61. package/dist/sandbox/modes.d.ts +16 -4
  62. package/dist/sandbox/modes.js +12 -0
  63. package/dist/sandbox/operation-authority.js +3 -1
  64. package/dist/sandbox/permission-authority-lock.d.ts +6 -0
  65. package/dist/sandbox/permission-authority-lock.js +14 -0
  66. package/dist/sandbox/permission-facts.d.ts +16 -2
  67. package/dist/sandbox/permission-facts.js +20 -5
  68. package/dist/sandbox/review/permission-candidate.d.ts +12 -7
  69. package/dist/sandbox/review/permission-candidate.js +28 -7
  70. package/dist/sandbox/sandbox.service.d.ts +18 -11
  71. package/dist/sandbox/sandbox.service.js +51 -24
  72. package/dist/setup/setup-guides.service.d.ts +3 -4
  73. package/dist/setup/setup-guides.service.js +2 -5
  74. package/dist/shares/sweep.job.d.ts +2 -0
  75. package/dist/shares/sweep.job.js +3 -1
  76. package/dist/tools/approvals.service.d.ts +31 -11
  77. package/dist/tools/approvals.service.js +55 -19
  78. package/dist/tools/builtins/sandbox/common.d.ts +2 -2
  79. package/dist/tools/builtins/sandbox/common.js +2 -2
  80. package/dist/tools/network-asks.d.ts +103 -20
  81. package/dist/tools/network-asks.js +133 -18
  82. package/dist/tools/pipeline.d.ts +5 -0
  83. package/dist/tools/pipeline.js +15 -8
  84. package/package.json +3 -3
  85. package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
@@ -1,4 +1,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,39 @@ 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 "add
361
+ * to this device's list" (`via`: where it was decided). In a caller's transaction (the approval
362
+ * decision's) it joins it and requires the authority locks of that prelude already held there
363
+ * (platform and org shared, the device exclusive: {@link lockNetworkAddSubject} in the caller's
364
+ * ordered prelude; else it throws before locking or writing anything; the membership and device
365
+ * rows are locked again in the body); with no transaction it takes that prelude itself
366
+ * ({@link withOrderedLocks}). It takes no distributed lock. The write is a network change like `PATCH`
367
+ * ({@link networkLocked}: audited `device.network_changed` from → to, listed as a recent change,
368
+ * the device epoch bumped and the instance marked for its next use). Refuses with
369
+ * `device.network_not_allowed`, writing nothing, unless the stored network is `allowlist` with a
370
+ * host list of its own (a device following its org's hosts already allows every host its list
371
+ * could name) and every host may join that list (`deviceListAddRefusal`); its detail `reason`
372
+ * says which (`network_closed`, `follows_org`, `host_not_addable`), for the decision's copy.
373
+ * Hosts its list already covers change nothing; own hosts the org's hosts no longer cover (in
374
+ * effect nowhere) leave the list with the addition.
375
+ */
376
+ addNetworkHostsIn(orgId: string, accountId: string, deviceId: string, hosts: string[], via: "web" | "im"): Promise<void>;
377
+ /** {@link addNetworkHostsIn} under the locks of its prelude (naming them again re-checks). */
378
+ private addNetworkHostsLocked;
352
379
  /**
353
380
  * The level a sandbox call in the device runs at now, for the model (legacy `device_paths`, auto
354
381
  * mode spec §4.2), the same for every provider: the kernel-internal tier (`SandboxMode`) with
@@ -375,11 +402,6 @@ export declare class DevicesService {
375
402
  /** The prelude of {@link remove}: the membership, the device row, the device's write lock. */
376
403
  private lockRemovalSubject;
377
404
  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
405
  /**
384
406
  * Starts one of the person's devices over with empty files (after
385
407
  * `device.files_lost`): records the request (audit), then, after the commit, enqueues the
@@ -396,8 +418,9 @@ export declare class DevicesService {
396
418
  * The person's default device in the org: the live one if any, whatever its provider's state
397
419
  * (a default whose provider is off stays the default, unavailable, never demoted or replaced),
398
420
  * 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.
421
+ * ({@link DeviceProviderSelection.defaultFor}), else null: no default provider on in the org, or
422
+ * a dial-in one (a machine must sign in to make its device, so nothing is created for the person;
423
+ * spec §6.4). An existing one is read without locking.
401
424
  *
402
425
  * Creating one first takes the person's membership row (`FOR SHARE`, after the org row), so an
403
426
  * offboarding that removes them cannot leave a live default behind; not a member (any more) →
@@ -427,8 +450,8 @@ export declare class DevicesService {
427
450
  /** Whether `provider` (a device's `devices.provider`) serves its devices over dial-in. */
428
451
  private isDialIn;
429
452
  /**
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.
453
+ * The last {@link RECENT_POLICY_CHANGES} setting changes of each device in the org (its
454
+ * `device.network_changed` audit rows), newest first, with the deciding account's display name.
432
455
  */
433
456
  private recentChanges;
434
457
  /**
@@ -443,14 +466,14 @@ export declare class DevicesService {
443
466
  private assertNameFree;
444
467
  }
445
468
  /**
446
- * Whether a cloud device's stored network setting widens from `a` to `b`, whatever the network in
469
+ * Whether a device's stored network setting widens from `a` to `b`, whatever the network in
447
470
  * effect now (a stored widening takes effect when a ceiling opens later): a wider mode, where
448
471
  * following the org (null) counts as wider than any explicit mode; or an explicit host list
449
472
  * replaced by none of its own (follow the org's hosts) or gaining a host.
450
473
  */
451
474
  export declare function storedNetworkWidens(a: DeviceNetworkSetting, b: DeviceNetworkSetting): boolean;
452
475
  /**
453
- * What a cloud device's new network takes from admitted or started work (`next`: its sandbox
476
+ * What a device's new network takes from admitted or started work (`next`: its sandbox
454
477
  * after the change): open-network work once it is no longer open, and allowlist work naming a host
455
478
  * its new hosts no longer cover, unless an independent grant the new per-call ceiling still allows
456
479
  * holds it (`hostsNarrowed`).