@capybara-hq/kernel 0.1.0-rc.125 → 0.1.0-rc.126

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 (38) hide show
  1. package/dist/catalog/catalog.module.js +0 -3
  2. package/dist/catalog/org-catalog.service.d.ts +0 -2
  3. package/dist/catalog/org-catalog.service.js +0 -4
  4. package/dist/catalog/org-extension.controller.d.ts +5 -9
  5. package/dist/catalog/org-extension.controller.js +22 -22
  6. package/dist/catalog/org-extension.schemas.d.ts +0 -1
  7. package/dist/catalog/org-extension.schemas.js +0 -2
  8. package/dist/catalog/plugin-install.d.ts +4 -1
  9. package/dist/catalog/plugin-install.js +4 -1
  10. package/dist/conversations/events.d.ts +10 -154
  11. package/dist/conversations/events.js +8 -83
  12. package/dist/devices/conversation-devices.d.ts +1 -2
  13. package/dist/devices/devices.service.d.ts +8 -1
  14. package/dist/devices/devices.service.js +1 -1
  15. package/dist/errors.d.ts +5 -0
  16. package/dist/errors.js +5 -0
  17. package/dist/evals/recorded-permission-context.js +1 -3
  18. package/dist/evals/recorded-tools.d.ts +3 -4
  19. package/dist/evals/recorded-tools.js +6 -7
  20. package/dist/extensions/org-config.d.ts +35 -8
  21. package/dist/extensions/org-config.js +61 -14
  22. package/dist/extensions/plugin-items.d.ts +16 -0
  23. package/dist/extensions/plugin-items.js +35 -0
  24. package/dist/platform/operation.d.ts +0 -2
  25. package/dist/platform/ops/extensions.ops.d.ts +4 -6
  26. package/dist/platform/ops/extensions.ops.js +17 -34
  27. package/dist/runtime/context/build.d.ts +1 -1
  28. package/dist/runtime/context/build.js +1 -10
  29. package/dist/runtime/context/device-paths.d.ts +5 -82
  30. package/dist/runtime/context/device-paths.js +3 -174
  31. package/dist/runtime/context/permission-profile.d.ts +3 -13
  32. package/dist/runtime/context/permission-profile.js +9 -26
  33. package/dist/runtime/permission-context.service.js +3 -4
  34. package/dist/runtime/run-worker.js +6 -5
  35. package/package.json +1 -1
  36. package/src/migrations/0210_normalize_conversation_history.sql +1012 -0
  37. package/dist/catalog/org-extension-switch.d.ts +0 -41
  38. package/dist/catalog/org-extension-switch.js +0 -123
@@ -18,7 +18,6 @@ import { CatalogImportModule } from "./catalog-import.module.js";
18
18
  import { CatalogScopeService } from "./catalog-scope.service.js";
19
19
  import { ComponentScopeService } from "./component-scope.service.js";
20
20
  import { OrgCatalogService } from "./org-catalog.service.js";
21
- import { OrgExtensionSwitch } from "./org-extension-switch.js";
22
21
  import { OrgPluginUploads } from "./org-plugin-uploads.js";
23
22
  import { OwnedItems } from "./owned-items.js";
24
23
  import { PlatformImportUpdate } from "./platform-import-update.js";
@@ -70,7 +69,6 @@ CatalogModule = __decorate([
70
69
  PluginInstaller,
71
70
  PlatformPluginUpdater,
72
71
  OrgCatalogService,
73
- OrgExtensionSwitch,
74
72
  PluginScopeSync,
75
73
  CatalogScopeService,
76
74
  ComponentScopeService,
@@ -88,7 +86,6 @@ CatalogModule = __decorate([
88
86
  PluginInstaller,
89
87
  PlatformPluginUpdater,
90
88
  OrgCatalogService,
91
- OrgExtensionSwitch,
92
89
  PluginScopeSync,
93
90
  CatalogScopeService,
94
91
  ComponentScopeService,
@@ -91,8 +91,6 @@ export declare class OrgCatalogService {
91
91
  install(orgId: string, actor: string, itemId: string, body: OrgInstallInput, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<OrgInstallResult>;
92
92
  /** The item when the org may see it (scope), else `catalog.item_not_found`. */
93
93
  private visibleItem;
94
- /** Whether the org has a live install of the item (switching it on then installs nothing). */
95
- hasLiveInstall(orgId: string, itemId: string): Promise<boolean>;
96
94
  /** The org's live plugin install of the item, if any. */
97
95
  private liveInstall;
98
96
  /**
@@ -479,10 +479,6 @@ let OrgCatalogService = class OrgCatalogService {
479
479
  }
480
480
  return item;
481
481
  }
482
- /** Whether the org has a live install of the item (switching it on then installs nothing). */
483
- async hasLiveInstall(orgId, itemId) {
484
- return (await this.liveInstall(orgId, itemId)) !== undefined;
485
- }
486
482
  /** The org's live plugin install of the item, if any. */
487
483
  liveInstall(orgId, itemId) {
488
484
  return this.db
@@ -11,8 +11,6 @@ import { type OrgToolSwitch, OrgToolSwitches, type OrgToolSwitchResult } from ".
11
11
  import { AppearanceApplyBody } from "./appearance.schemas.js";
12
12
  import { type AppearanceResult, AppearanceService } from "./appearance.service.js";
13
13
  import { OrgExtensionParams as ExtensionParams, OrgOverridesPut as OverridesPut, OrgOverridesTake as OverridesTake, OrgExtensionPut as PutBody, OrgExtensionToolParams as ToolParams, OrgToolSwitchPut as ToolSwitchPut } from "./org-extension.schemas.js";
14
- import { OrgExtensionSwitch } from "./org-extension-switch.js";
15
- import type { UninstallPreview } from "./plugin-install.js";
16
14
  /**
17
15
  * One extension of the org list: the org view plus the plugin's display name, the URL of its
18
16
  * plugin's icon on the org's catalog route (null without one or when the org may not see the
@@ -42,11 +40,10 @@ export type OrgExtensionMemberItem = Omit<OrgExtensionItem, "permissions" | "sug
42
40
  export declare class OrgExtensionConfigsController {
43
41
  private readonly configs;
44
42
  private readonly displayNames;
45
- private readonly extSwitch;
46
43
  private readonly icons;
47
44
  private readonly appearance;
48
45
  private readonly clientBuilds;
49
- constructor(configs: OrgExtensionConfigs, displayNames: ExtensionDisplayNames, extSwitch: OrgExtensionSwitch, icons: PluginIcons, appearance: AppearanceService, clientBuilds: ClientBuilds);
46
+ constructor(configs: OrgExtensionConfigs, displayNames: ExtensionDisplayNames, icons: PluginIcons, appearance: AppearanceService, clientBuilds: ClientBuilds);
50
47
  /**
51
48
  * The org's extensions (also the channel plugin options: those providing `channel@1`). Members
52
49
  * get the projection {@link OrgExtensionMemberItem}; admins the full view.
@@ -55,14 +52,13 @@ export declare class OrgExtensionConfigsController {
55
52
  extensions: OrgExtensionItem[] | OrgExtensionMemberItem[];
56
53
  }>;
57
54
  /**
58
- * Writes enablement; see {@link OrgExtensionSwitch.put} for how `enabled` follows
59
- * the extension's plugin (off answers `{ preview, confirm }` until `confirm` carries the hash).
55
+ * Writes enablement ({@link OrgExtensionConfigs.put}): the extension only, never its plugin
56
+ * (extension switch spec 2026-12-02 §3.1). Its plugin stays installed when it goes off; switching
57
+ * on an extension whose plugin is not installed in the org -> 409
58
+ * `extension.plugin_not_installed`. Audited with `reason: "org_switch"`.
60
59
  */
61
60
  put(principal: Principal, org: OrgContext, extension: string, body: z.infer<typeof PutBody>): Promise<{
62
61
  extension: OrgExtensionItem;
63
- } | {
64
- preview: UninstallPreview;
65
- confirm: string;
66
62
  }>;
67
63
  /**
68
64
  * 应用此插件的外观 (client extensions spec §6.5), for a plugin whose extension is on in the org:
@@ -22,7 +22,8 @@ import { OrgToolSwitches, } from "../tools/org-tool-switches.js";
22
22
  import { AppearanceApplyBody } from "./appearance.schemas.js";
23
23
  import { AppearanceService } from "./appearance.service.js";
24
24
  import { OrgExtensionParams as ExtensionParams, OrgOverridesPut as OverridesPut, OrgOverridesTake as OverridesTake, OrgExtensionPut as PutBody, OrgExtensionToolParams as ToolParams, OrgToolSwitchPut as ToolSwitchPut, } from "./org-extension.schemas.js";
25
- import { OrgExtensionSwitch } from "./org-extension-switch.js";
25
+ /** The audit detail of a switch made on the org's Extensions or Models page. */
26
+ const ORG_SWITCH = { reason: "org_switch" };
26
27
  class OrgExtensionPutBody extends createZodDto(PutBody, "OrgExtensionPutBody") {
27
28
  }
28
29
  class OrgToolSwitchPutBody extends createZodDto(ToolSwitchPut, "OrgToolSwitchPutBody") {
@@ -44,14 +45,12 @@ class OrgOverridesTakeBody extends createZodDto(OverridesTake, "OrgOverridesTake
44
45
  let OrgExtensionConfigsController = class OrgExtensionConfigsController {
45
46
  configs;
46
47
  displayNames;
47
- extSwitch;
48
48
  icons;
49
49
  appearance;
50
50
  clientBuilds;
51
- constructor(configs, displayNames, extSwitch, icons, appearance, clientBuilds) {
51
+ constructor(configs, displayNames, icons, appearance, clientBuilds) {
52
52
  this.configs = configs;
53
53
  this.displayNames = displayNames;
54
- this.extSwitch = extSwitch;
55
54
  this.icons = icons;
56
55
  this.appearance = appearance;
57
56
  this.clientBuilds = clientBuilds;
@@ -85,28 +84,30 @@ let OrgExtensionConfigsController = class OrgExtensionConfigsController {
85
84
  };
86
85
  }
87
86
  /**
88
- * Writes enablement; see {@link OrgExtensionSwitch.put} for how `enabled` follows
89
- * the extension's plugin (off answers `{ preview, confirm }` until `confirm` carries the hash).
87
+ * Writes enablement ({@link OrgExtensionConfigs.put}): the extension only, never its plugin
88
+ * (extension switch spec 2026-12-02 §3.1). Its plugin stays installed when it goes off; switching
89
+ * on an extension whose plugin is not installed in the org -> 409
90
+ * `extension.plugin_not_installed`. Audited with `reason: "org_switch"`.
90
91
  */
91
92
  async put(principal, org, extension, body) {
92
93
  const p = requireUser(principal);
93
- const r = await this.extSwitch.put(org.orgId, p.account.id, extension, body, patTokenId(p));
94
- if (r.kind === "preview")
95
- return { preview: r.preview, confirm: r.confirm };
94
+ const view = await this.configs.put(org.orgId, extension, body, p.account.id, patTokenId(p), {
95
+ auditDetail: ORG_SWITCH,
96
+ });
96
97
  const [displayName, icons, suggestions, clients] = await Promise.all([
97
- this.displayNames.get(r.view.plugin),
98
- this.icons.many([r.view.plugin], orgIconScope(org)),
99
- this.appearance.suggestions([r.view.plugin]),
100
- this.clientBuilds.installedSummaries([r.view.plugin]),
98
+ this.displayNames.get(view.plugin),
99
+ this.icons.many([view.plugin], orgIconScope(org)),
100
+ this.appearance.suggestions([view.plugin]),
101
+ this.clientBuilds.installedSummaries([view.plugin]),
101
102
  ]);
102
103
  return {
103
104
  extension: {
104
- ...r.view,
105
+ ...view,
105
106
  displayName,
106
- icon: icons.get(r.view.plugin) ?? null,
107
- provides: providesOf(r.view),
108
- suggestedAppearance: suggestions.get(r.view.plugin) ?? null,
109
- client: clients.get(r.view.plugin) ?? null,
107
+ icon: icons.get(view.plugin) ?? null,
108
+ provides: providesOf(view),
109
+ suggestedAppearance: suggestions.get(view.plugin) ?? null,
110
+ client: clients.get(view.plugin) ?? null,
110
111
  },
111
112
  };
112
113
  }
@@ -150,10 +151,9 @@ OrgExtensionConfigsController = __decorate([
150
151
  Controller("api/v1/orgs/:orgId/extensions"),
151
152
  __param(0, Inject(OrgExtensionConfigs)),
152
153
  __param(1, Inject(ExtensionDisplayNames)),
153
- __param(2, Inject(OrgExtensionSwitch)),
154
- __param(3, Inject(PluginIcons)),
155
- __param(4, Inject(AppearanceService)),
156
- __param(5, Inject(ClientBuilds))
154
+ __param(2, Inject(PluginIcons)),
155
+ __param(3, Inject(AppearanceService)),
156
+ __param(4, Inject(ClientBuilds))
157
157
  ], OrgExtensionConfigsController);
158
158
  export { OrgExtensionConfigsController };
159
159
  /**
@@ -16,7 +16,6 @@ export declare const OrgToolSwitchPut: z.ZodObject<{
16
16
  export declare const OrgExtensionPut: z.ZodObject<{
17
17
  enabled: z.ZodOptional<z.ZodBoolean>;
18
18
  force: z.ZodOptional<z.ZodBoolean>;
19
- confirm: z.ZodOptional<z.ZodString>;
20
19
  }, z.core.$strict>;
21
20
  /**
22
21
  * One key of a secret record of the org's copy. `value` is a secret (`secret()` meta): a Platform
@@ -17,8 +17,6 @@ export const OrgExtensionPut = z
17
17
  .object({
18
18
  enabled: z.boolean().optional(),
19
19
  force: z.boolean().optional(),
20
- /** The hash of the plugin uninstall preview, to confirm switching the extension's plugin off. */
21
- confirm: z.string().optional(),
22
20
  })
23
21
  .strict();
24
22
  /**
@@ -406,7 +406,10 @@ export declare class PluginInstaller {
406
406
  * transaction (`put` joins it): "enabled before" is decided under the org row lock (already
407
407
  * enabled: `put` writes nothing, the config is untouched, the component is recorded as not
408
408
  * created), and the ledger row is written before the COMMIT, so no concurrent uninstall fits
409
- * between enabling and recording. Used by the install and the upgrade.
409
+ * between enabling and recording. Used only by a fresh install (and a dependency the install or a
410
+ * platform update adds): a platform update of an installed plugin and switching an installed
411
+ * plugin on again never call it, so an extension the org switched off stays off (extension switch
412
+ * spec 2026-12-02 §3.2).
410
413
  */
411
414
  enableExtension(orgId: string, name: string, input: OrgExtensionInput, actor: string | null, actorTokenId: string | undefined, opts: Pick<OrgExtensionPutOptions, "viaItem" | "approvedBy">, record: (c: Component) => Promise<void>): Promise<void>;
412
415
  private createInstallRow;
@@ -797,7 +797,10 @@ let PluginInstaller = class PluginInstaller {
797
797
  * transaction (`put` joins it): "enabled before" is decided under the org row lock (already
798
798
  * enabled: `put` writes nothing, the config is untouched, the component is recorded as not
799
799
  * created), and the ledger row is written before the COMMIT, so no concurrent uninstall fits
800
- * between enabling and recording. Used by the install and the upgrade.
800
+ * between enabling and recording. Used only by a fresh install (and a dependency the install or a
801
+ * platform update adds): a platform update of an installed plugin and switching an installed
802
+ * plugin on again never call it, so an extension the org switched off stays off (extension switch
803
+ * spec 2026-12-02 §3.2).
801
804
  */
802
805
  async enableExtension(orgId, name, input, actor, actorTokenId, opts, record) {
803
806
  const ifDisabled = { skipped: false };
@@ -138,107 +138,6 @@ export declare const PermissionContextV2Schema: z.ZodObject<{
138
138
  }, z.core.$strict>>;
139
139
  }, z.core.$strict>;
140
140
  export type PermissionContextV2 = z.infer<typeof PermissionContextV2Schema>;
141
- /**
142
- * Reads a recorded payload as version 2. Stored v1 rows exist on deployments and the log is never
143
- * rewritten: a v1 payload (`version: 1`, never a `sandbox` key) reads as v2 with `sandbox: null`,
144
- * which v2 accepts under exactly v1's rules. A payload recorded before device providers reported
145
- * their boundary (a `location` of `local` / `cloud`, read roots in a scoped filesystem) reads with
146
- * the boundary that location had (`operation` / `instance`) and without its read roots. Anything
147
- * else is left for the v2 schema to judge.
148
- */
149
- export declare function upconvertPermissionContext(payload: unknown): unknown;
150
- /** A recorded `permission_context` payload as every reader parses it (v1 up-converted). */
151
- export declare const RecordedPermissionContextSchema: z.ZodPreprocess<z.ZodObject<{
152
- version: z.ZodLiteral<2>;
153
- rootConversationId: z.ZodString;
154
- profileRevision: z.ZodNullable<z.ZodNumber>;
155
- selectedProfile: z.ZodNullable<z.ZodCustom<PermissionProfile, PermissionProfile>>;
156
- effectiveProfile: z.ZodNullable<z.ZodCustom<PermissionProfile, PermissionProfile>>;
157
- execution: z.ZodEnum<{
158
- interactive: "interactive";
159
- scheduled: "scheduled";
160
- }>;
161
- inherited: z.ZodBoolean;
162
- deviceId: z.ZodNullable<z.ZodString>;
163
- scopeRevision: z.ZodNullable<z.ZodString>;
164
- authorityRevision: z.ZodNullable<z.ZodString>;
165
- availability: z.ZodDiscriminatedUnion<[z.ZodObject<{
166
- state: z.ZodLiteral<"supported">;
167
- }, z.core.$strict>, z.ZodObject<{
168
- state: z.ZodEnum<{
169
- unprobed: "unprobed";
170
- unsupported: "unsupported";
171
- }>;
172
- reason: z.ZodString;
173
- }, z.core.$strict>, z.ZodObject<{
174
- state: z.ZodLiteral<"unavailable">;
175
- cause: z.ZodEnum<{
176
- "actor-device-access": "actor-device-access";
177
- "no-device": "no-device";
178
- }>;
179
- reason: z.ZodString;
180
- }, z.core.$strict>], "state">;
181
- scope: z.ZodNullable<z.ZodObject<{
182
- boundary: z.ZodEnum<{
183
- instance: "instance";
184
- operation: "operation";
185
- }>;
186
- workingRoot: z.ZodString;
187
- filesystem: z.ZodDiscriminatedUnion<[z.ZodObject<{
188
- kind: z.ZodLiteral<"device">;
189
- }, z.core.$strict>, z.ZodObject<{
190
- kind: z.ZodLiteral<"scoped">;
191
- writeDirectories: z.ZodArray<z.ZodString>;
192
- }, z.core.$strict>], "kind">;
193
- network: z.ZodDiscriminatedUnion<[z.ZodObject<{
194
- kind: z.ZodLiteral<"none">;
195
- }, z.core.$strict>, z.ZodObject<{
196
- kind: z.ZodLiteral<"environment">;
197
- }, z.core.$strict>, z.ZodObject<{
198
- kind: z.ZodLiteral<"allowlist">;
199
- hosts: z.ZodArray<z.ZodString>;
200
- }, z.core.$strict>, z.ZodObject<{
201
- kind: z.ZodLiteral<"open-public">;
202
- }, z.core.$strict>], "kind">;
203
- outerNetwork: z.ZodDiscriminatedUnion<[z.ZodObject<{
204
- kind: z.ZodLiteral<"host-environment">;
205
- }, z.core.$strict>, z.ZodObject<{
206
- kind: z.ZodLiteral<"none">;
207
- }, z.core.$strict>, z.ZodObject<{
208
- kind: z.ZodLiteral<"open-public">;
209
- }, z.core.$strict>, z.ZodObject<{
210
- kind: z.ZodLiteral<"allowlist">;
211
- hosts: z.ZodArray<z.ZodString>;
212
- }, z.core.$strict>], "kind">;
213
- }, z.core.$strict>>;
214
- sandbox: z.ZodNullable<z.ZodObject<{
215
- boundary: z.ZodEnum<{
216
- instance: "instance";
217
- operation: "operation";
218
- }>;
219
- workingRoot: z.ZodString;
220
- network: z.ZodObject<{
221
- kind: z.ZodEnum<{
222
- allowlist: "allowlist";
223
- none: "none";
224
- "open-public": "open-public";
225
- }>;
226
- hostsCount: z.ZodNumber;
227
- }, z.core.$strict>;
228
- outsideSandbox: z.ZodBoolean;
229
- outerNetwork: z.ZodDiscriminatedUnion<[z.ZodObject<{
230
- kind: z.ZodLiteral<"host-environment">;
231
- }, z.core.$strict>, z.ZodObject<{
232
- kind: z.ZodLiteral<"none">;
233
- }, z.core.$strict>, z.ZodObject<{
234
- kind: z.ZodLiteral<"open-public">;
235
- }, z.core.$strict>, z.ZodObject<{
236
- kind: z.ZodLiteral<"allowlist">;
237
- hosts: z.ZodArray<z.ZodString>;
238
- }, z.core.$strict>], "kind">;
239
- perCallHosts: z.ZodOptional<z.ZodBoolean>;
240
- }, z.core.$strict>>;
241
- }, z.core.$strict>, unknown>;
242
141
  export declare const ManagedDevicePathsV1Schema: z.ZodObject<{
243
142
  permissionContextVersion: z.ZodLiteral<1>;
244
143
  deviceId: z.ZodString;
@@ -294,10 +193,10 @@ export declare const COMMAND_ASK_MAX_CHARS: number;
294
193
  * `commandHash` is the SHA-256 of the command text the approval holds in full, so an audit can
295
194
  * match a record to what ran.
296
195
  */
297
- export declare const PermissionExpansionSchema: z.ZodPreprocess<z.ZodObject<{
196
+ export declare const PermissionExpansionSchema: z.ZodObject<{
298
197
  writeDirectories: z.ZodArray<z.ZodString>;
299
198
  hosts: z.ZodArray<z.ZodString>;
300
- }, z.core.$strict>, unknown>;
199
+ }, z.core.$strict>;
301
200
  export declare const PermissionCallBindingSchema: z.ZodObject<{
302
201
  orgId: z.ZodString;
303
202
  rootConversationId: z.ZodString;
@@ -372,10 +271,10 @@ export declare const ReviewRecordSchema: z.ZodObject<{
372
271
  }, z.core.$strict>;
373
272
  /** The display-only `approval_requested.command` facts of a `command` ask (auto mode spec §5.4). */
374
273
  export declare const CommandAskSchema: z.ZodObject<{
375
- permissionScope: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
274
+ permissionScope: z.ZodOptional<z.ZodObject<{
376
275
  writeDirectories: z.ZodArray<z.ZodString>;
377
276
  hosts: z.ZodArray<z.ZodString>;
378
- }, z.core.$strict>, unknown>>;
277
+ }, z.core.$strict>>;
379
278
  targetPath: z.ZodOptional<z.ZodString>;
380
279
  candidateHash: z.ZodOptional<z.ZodString>;
381
280
  escalation: z.ZodOptional<z.ZodObject<{
@@ -839,10 +738,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
839
738
  scopeRevision: z.ZodString;
840
739
  authorityRevision: z.ZodString;
841
740
  }, z.core.$strict>;
842
- permissionScope: z.ZodPreprocess<z.ZodObject<{
741
+ permissionScope: z.ZodObject<{
843
742
  writeDirectories: z.ZodArray<z.ZodString>;
844
743
  hosts: z.ZodArray<z.ZodString>;
845
- }, z.core.$strict>, unknown>;
744
+ }, z.core.$strict>;
846
745
  targetPath: z.ZodOptional<z.ZodString>;
847
746
  scopeKind: z.ZodEnum<{
848
747
  "directories-and-hosts": "directories-and-hosts";
@@ -1404,7 +1303,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1404
1303
  }, z.core.$strip>;
1405
1304
  }, z.core.$strip>, z.ZodObject<{
1406
1305
  type: z.ZodLiteral<"device_paths">;
1407
- payload: z.ZodUnion<readonly [z.ZodObject<{
1306
+ payload: z.ZodObject<{
1408
1307
  permissionContextVersion: z.ZodLiteral<1>;
1409
1308
  deviceId: z.ZodString;
1410
1309
  roots: z.ZodObject<{
@@ -1413,50 +1312,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1413
1312
  tmp: z.ZodString;
1414
1313
  }, z.core.$strict>;
1415
1314
  workingRoot: z.ZodString;
1416
- }, z.core.$strict>, z.ZodObject<{
1417
- permissionContextVersion: z.ZodOptional<z.ZodNever>;
1418
- roots: z.ZodObject<{
1419
- workspace: z.ZodString;
1420
- skills: z.ZodString;
1421
- tmp: z.ZodString;
1422
- }, z.core.$strip>;
1423
- tier: z.ZodOptional<z.ZodEnum<{
1424
- dev: "dev";
1425
- open: "open";
1426
- strict: "strict";
1427
- }>>;
1428
- isolation: z.ZodOptional<z.ZodEnum<{
1429
- none: "none";
1430
- sandbox: "sandbox";
1431
- }>>;
1432
- network: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"none">, z.ZodObject<{
1433
- kind: z.ZodEnum<{
1434
- allowlist: "allowlist";
1435
- "open-public": "open-public";
1436
- }>;
1437
- hosts: z.ZodArray<z.ZodString>;
1438
- }, z.core.$strip>]>>;
1439
- localhost: z.ZodOptional<z.ZodEnum<{
1440
- off: "off";
1441
- "off-proxy-detected": "off-proxy-detected";
1442
- on: "on";
1443
- }>>;
1444
- unixSockets: z.ZodOptional<z.ZodEnum<{
1445
- "all-masked": "all-masked";
1446
- off: "off";
1447
- roots: "roots";
1448
- }>>;
1449
- unattended: z.ZodOptional<z.ZodLiteral<true>>;
1450
- mode: z.ZodOptional<z.ZodEnum<{
1451
- auto: "auto";
1452
- sandbox: "sandbox";
1453
- }>>;
1454
- allowedMode: z.ZodOptional<z.ZodEnum<{
1455
- auto: "auto";
1456
- sandbox: "sandbox";
1457
- }>>;
1458
- local: z.ZodOptional<z.ZodBoolean>;
1459
- }, z.core.$strip>]>;
1315
+ }, z.core.$strict>;
1460
1316
  }, z.core.$strip>, z.ZodObject<{
1461
1317
  type: z.ZodLiteral<"project_root">;
1462
1318
  payload: z.ZodObject<{
@@ -1681,10 +1537,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1681
1537
  refs: z.ZodArray<z.ZodString>;
1682
1538
  }, z.core.$strip>>;
1683
1539
  command: z.ZodOptional<z.ZodObject<{
1684
- permissionScope: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
1540
+ permissionScope: z.ZodOptional<z.ZodObject<{
1685
1541
  writeDirectories: z.ZodArray<z.ZodString>;
1686
1542
  hosts: z.ZodArray<z.ZodString>;
1687
- }, z.core.$strict>, unknown>>;
1543
+ }, z.core.$strict>>;
1688
1544
  targetPath: z.ZodOptional<z.ZodString>;
1689
1545
  candidateHash: z.ZodOptional<z.ZodString>;
1690
1546
  escalation: z.ZodOptional<z.ZodObject<{
@@ -199,8 +199,8 @@ export const PermissionContextV2Schema = z
199
199
  return;
200
200
  // every profile records a scoped sandbox under a block (the producer always writes one); a
201
201
  // device filesystem or environment networking is never a sandboxed context's. Only a stored
202
- // version 1 context, read as version 2 without a block, records Full access as exactly device
203
- // + environment: that form stays readable because the log is never rewritten
202
+ // Full access context without a sandbox block records device filesystem and environment
203
+ // networking. Migration 0210 preserves that form as a v2 event with a null block.
204
204
  if (p.effectiveProfile === "full-access" && p.sandbox === null) {
205
205
  if (s.filesystem.kind !== "device" || s.network.kind !== "environment")
206
206
  reject("Full access without a sandbox requires device filesystem and environment networking");
@@ -243,41 +243,6 @@ export const PermissionContextV2Schema = z
243
243
  }
244
244
  }
245
245
  });
246
- /**
247
- * Reads a recorded payload as version 2. Stored v1 rows exist on deployments and the log is never
248
- * rewritten: a v1 payload (`version: 1`, never a `sandbox` key) reads as v2 with `sandbox: null`,
249
- * which v2 accepts under exactly v1's rules. A payload recorded before device providers reported
250
- * their boundary (a `location` of `local` / `cloud`, read roots in a scoped filesystem) reads with
251
- * the boundary that location had (`operation` / `instance`) and without its read roots. Anything
252
- * else is left for the v2 schema to judge.
253
- */
254
- export function upconvertPermissionContext(payload) {
255
- if (typeof payload !== "object" || payload === null || Array.isArray(payload))
256
- return payload;
257
- let p = payload;
258
- if (p.version === 1 && !Object.hasOwn(p, "sandbox"))
259
- p = { ...p, version: 2, sandbox: null };
260
- const boundaryOf = (location) => location === "local" ? "operation" : location === "cloud" ? "instance" : location;
261
- const scope = p.scope;
262
- if (scope && typeof scope === "object" && Object.hasOwn(scope, "location")) {
263
- const { location, ...rest } = scope;
264
- const fs = rest.filesystem;
265
- let filesystem = fs;
266
- if (fs && typeof fs === "object" && Object.hasOwn(fs, "readDirectories")) {
267
- const { readDirectories: _reads, ...kept } = fs;
268
- filesystem = kept;
269
- }
270
- p = { ...p, scope: { boundary: boundaryOf(location), ...rest, filesystem } };
271
- }
272
- const box = p.sandbox;
273
- if (box && typeof box === "object" && Object.hasOwn(box, "location")) {
274
- const { location: _location, ...kept } = box;
275
- p = { ...p, sandbox: kept };
276
- }
277
- return p;
278
- }
279
- /** A recorded `permission_context` payload as every reader parses it (v1 up-converted). */
280
- export const RecordedPermissionContextSchema = z.preprocess(upconvertPermissionContext, PermissionContextV2Schema);
281
246
  /** Order-independent identity of an outer network value (host lists are already sorted). */
282
247
  function canonicalOuter(value) {
283
248
  return JSON.stringify([value.kind, value.hosts ?? null]);
@@ -383,20 +348,12 @@ export const COMMAND_ASK_MAX_CHARS = 32 * 1024;
383
348
  * `commandHash` is the SHA-256 of the command text the approval holds in full, so an audit can
384
349
  * match a record to what ran.
385
350
  */
386
- export const PermissionExpansionSchema = z.preprocess(
387
- // a scope recorded before read roots left the kernel (reads are the device provider's rule)
388
- // carried `readDirectories`: read without it, as nothing grants a read any more
389
- (value) => {
390
- if (typeof value !== "object" || value === null || !Object.hasOwn(value, "readDirectories"))
391
- return value;
392
- const { readDirectories: _reads, ...rest } = value;
393
- return rest;
394
- }, z
351
+ export const PermissionExpansionSchema = z
395
352
  .object({
396
353
  writeDirectories: z.array(z.string().max(4096)).max(64),
397
354
  hosts: z.array(z.string().max(253)).max(100),
398
355
  })
399
- .strict());
356
+ .strict();
400
357
  export const PermissionCallBindingSchema = z
401
358
  .object({
402
359
  orgId: z.string(),
@@ -1321,43 +1278,11 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1321
1278
  */
1322
1279
  ev("tools_changed", z.object({ step: count, added: z.array(z.string()), removed: z.array(z.string()) })),
1323
1280
  /**
1324
- * The directories of the instance a sandbox tool call entered and the device's sandbox level
1325
- * (environments spec §13.1; sandbox dev tiers spec §11.5: `tier`, `isolation`, and when they
1326
- * apply `network: "none"`, a local device's `localhost` / `unixSockets` and `unattended`; all
1327
- * absent on events recorded before tiers). Written on a conversation's first sandbox call and whenever
1328
- * they change, before that call's result. **Model-visible**: rendered at its position as a
1329
- * system message (`devicePathsText`); a summary covering it is followed by the latest one again.
1281
+ * The directories of the device entered by a sandbox call. Written before the call's result
1282
+ * when the paths change. **Model-visible**: rendered at its position as a system message and
1283
+ * restored after a summary that covers it.
1330
1284
  */
1331
- ev("device_paths", z.union([
1332
- ManagedDevicePathsV1Schema,
1333
- z.object({
1334
- permissionContextVersion: z.never().optional(),
1335
- roots: z.object({
1336
- workspace: z.string().min(1).max(4096),
1337
- skills: z.string().min(1).max(4096),
1338
- tmp: z.string().min(1).max(4096),
1339
- }),
1340
- tier: z.enum(["strict", "dev", "open"]).optional(),
1341
- isolation: z.enum(["sandbox", "none"]).optional(),
1342
- /** The current network (`none` on events recorded before auto mode). */
1343
- network: z
1344
- .union([
1345
- z.literal("none"),
1346
- z.object({
1347
- kind: z.enum(["open-public", "allowlist"]),
1348
- hosts: z.array(z.string()),
1349
- }),
1350
- ])
1351
- .optional(),
1352
- localhost: z.enum(["on", "off-proxy-detected", "off"]).optional(),
1353
- unixSockets: z.enum(["roots", "all-masked", "off"]).optional(),
1354
- unattended: z.literal(true).optional(),
1355
- /** Auto mode: the mode and its ceiling, and whether the device is a connected machine. */
1356
- mode: z.enum(["auto", "sandbox"]).optional(),
1357
- allowedMode: z.enum(["auto", "sandbox"]).optional(),
1358
- local: z.boolean().optional(),
1359
- }),
1360
- ])),
1285
+ ev("device_paths", ManagedDevicePathsV1Schema),
1361
1286
  /**
1362
1287
  * The project a bound conversation's run read at its start (project root spec §4.4): the
1363
1288
  * project's name and root, its `AGENTS.md` text, and per skill its name, description and digest;
@@ -1,13 +1,12 @@
1
1
  import { ApiError } from "../errors.js";
2
2
  import { KernelDb } from "../infra/database/kernel-db.js";
3
3
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
- import type { DeviceModeLevel } from "../runtime/context/device-paths.js";
5
4
  import type { SandboxMode } from "../sandbox/modes.js";
6
5
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
7
6
  import { PermissionFacts, type WorkingFacts } from "../sandbox/permission-facts.js";
8
7
  import { DeviceAccess } from "./access.js";
9
8
  import { DeviceProviderSelection } from "./device-provider-selection.js";
10
- import { DevicesService } from "./devices.service.js";
9
+ import { type DeviceModeLevel, DevicesService } from "./devices.service.js";
11
10
  import { type WorkingProject } from "./working-root.js";
12
11
  export type { WorkingFacts } from "../sandbox/permission-facts.js";
13
12
  /** `details[0].reason` of the error an anonymous IM conversation's sandbox call gets. */
@@ -13,10 +13,10 @@ import { KernelDb } from "../infra/database/kernel-db.js";
13
13
  import { TransactionHost } from "../infra/database/transaction-host.js";
14
14
  import { OutboxService } from "../infra/outbox/outbox.service.js";
15
15
  import type { OrgRole } from "../orgs/roles.js";
16
- import type { DeviceModeLevel } from "../runtime/context/device-paths.js";
17
16
  import { DeviceReports } from "../sandbox/device-reports.js";
18
17
  import type { DeviceSandbox, DeviceSandboxLayer, HostGrantCeiling } from "../sandbox/device-sandbox.js";
19
18
  import { SandboxJobs } from "../sandbox/jobs.js";
19
+ import { type DeviceNetwork, type SandboxMode } from "../sandbox/modes.js";
20
20
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
21
21
  import { PermissionFacts } from "../sandbox/permission-facts.js";
22
22
  import { DeviceProviders } from "../sandbox/providers.js";
@@ -24,6 +24,13 @@ import { SandboxService } from "../sandbox/sandbox.service.js";
24
24
  import { DeviceAccess } from "./access.js";
25
25
  import { DeviceProviderSelection } from "./device-provider-selection.js";
26
26
  /** A device as its owner sees it (`GET /orgs/:orgId/devices`). */
27
+ /** The effective mode and network of a device, with its provider's boundary. */
28
+ export interface DeviceModeLevel {
29
+ mode: SandboxMode;
30
+ allowedMode: SandboxMode;
31
+ network: DeviceNetwork;
32
+ local: boolean;
33
+ }
27
34
  export interface DeviceView {
28
35
  id: string;
29
36
  /** null for the default device (shown as the localized "Personal"). */
@@ -29,7 +29,7 @@ import { DeviceReports } from "../sandbox/device-reports.js";
29
29
  import { deviceSideLayer, hostGrantable } from "../sandbox/device-sandbox.js";
30
30
  import { oweDeviceDestroy, SandboxJobs } from "../sandbox/jobs.js";
31
31
  import { revokeLoopbackGrantsOfDevice } from "../sandbox/loopback-grant-records.js";
32
- import { coversHost } from "../sandbox/modes.js";
32
+ import { coversHost, } from "../sandbox/modes.js";
33
33
  import { assertAuthorityWriteHeld } from "../sandbox/permission-authority-lock.js";
34
34
  import { hostsNarrowed, needsOpenNetwork, PermissionCeilingWrites, } from "../sandbox/permission-ceiling-writes.js";
35
35
  import { ownNetwork, PermissionFacts } from "../sandbox/permission-facts.js";
package/dist/errors.d.ts CHANGED
@@ -141,6 +141,11 @@ export declare const ERROR_CODES: {
141
141
  readonly "extension.package_too_large": 413;
142
142
  readonly "extension.config_declared": 409;
143
143
  readonly "extension.required": 409;
144
+ /**
145
+ * Switching on an extension whose plugin is not installed in the org (details
146
+ * `[{ itemId, plugin }]`): the plugin's switch on the Plugins page installs it first.
147
+ */
148
+ readonly "extension.plugin_not_installed": 409;
144
149
  readonly "extension.name_conflict": 409;
145
150
  readonly "extension.approval_stale": 409;
146
151
  readonly "extension.not_pending": 409;
package/dist/errors.js CHANGED
@@ -141,6 +141,11 @@ export const ERROR_CODES = {
141
141
  "extension.package_too_large": 413,
142
142
  "extension.config_declared": 409,
143
143
  "extension.required": 409,
144
+ /**
145
+ * Switching on an extension whose plugin is not installed in the org (details
146
+ * `[{ itemId, plugin }]`): the plugin's switch on the Plugins page installs it first.
147
+ */
148
+ "extension.plugin_not_installed": 409,
144
149
  "extension.name_conflict": 409,
145
150
  "extension.approval_stale": 409,
146
151
  "extension.not_pending": 409,