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

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.
package/bootstrap.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "e5cc914a56d4c1dbb1383ba1729fcac8233dfd16"
6
+ "commit": "0b6d898d9481190adc74d5554dd53e78382b1e31"
7
7
  },
8
8
  "plugins": [
9
9
  {
@@ -98,8 +98,8 @@
98
98
  "name": "device-local",
99
99
  "source": "npm",
100
100
  "npm": "@capybara-hq/plugin-device-local",
101
- "version": "0.1.0-rc.17",
102
- "integrity": "sha512-1cO8hRNz5mlArA+QxXkwr39Aluza0njOIyZidtI8wmX61eEuCxEiPv5W/+dBuUCatshwhjCGG+E0rB2udjliLA==",
101
+ "version": "0.1.0-rc.18",
102
+ "integrity": "sha512-i+0Ixm83k967TXjDh7EcgpwQSwKBMtHE1owhLfgg06zMzhkkrfAqE4YdegdRj0hFWf79rAYQwN95pYoMGLZBdw==",
103
103
  "required": false,
104
104
  "scope": "all"
105
105
  },
@@ -13,6 +13,12 @@ import { OnboardingChecklist, type OnboardingStatus } from "./onboarding-checkli
13
13
  export interface OrgFixableProvider {
14
14
  provider: string;
15
15
  reason: "not_enabled" | "needs_config";
16
+ /**
17
+ * The provider waits for the org's own config (an API key the platform left empty), whether or
18
+ * not it is on: false means the platform configured a connection the org only switches on. The
19
+ * setup home says "the platform provides models" only then (#1226).
20
+ */
21
+ needsOrgConfig: boolean;
16
22
  }
17
23
  /**
18
24
  * A model provider that is on in the org with a valid config but gives an agent no model to pick
@@ -126,7 +126,7 @@ function orgFixableOf(views) {
126
126
  continue;
127
127
  const reason = fixOf(v);
128
128
  if (reason !== null)
129
- out.push({ provider: v.plugin, reason });
129
+ out.push({ provider: v.plugin, reason, needsOrgConfig: v.needsConfig });
130
130
  }
131
131
  return out;
132
132
  }
@@ -242,10 +242,13 @@ export type ItemConfirmations = ReadonlyMap<string, {
242
242
  }>;
243
243
  /**
244
244
  * Per item id: is its extension waiting for a person's confirmation (pending) and the permission
245
- * digest to confirm. Pending when the extension is not installed on the deployment, when the
246
- * installed version's permission set is not covered by the stored snapshot, or (a builtin item)
247
- * when the snapshot is the bootstrap step's, never confirmed by a person. Items whose latest
248
- * version has no extension are never pending.
245
+ * digest to confirm. Pending when the extension is not installed on the deployment, or when the
246
+ * installed version's permission set is not covered by the stored snapshot. A snapshot the
247
+ * bootstrap step wrote is consent like any other: the super admin's bootstrap manifests pin that
248
+ * version, so it covers exactly the pinned version's permissions (audited
249
+ * `extension.permissions_approved`, source `bootstrap`), and a version off the pin asking for more
250
+ * is pending as for any install (core#1226). Items whose latest version has no extension are never
251
+ * pending.
249
252
  */
250
253
  export declare function itemConfirmations(admin: ExtensionAdmin, items: {
251
254
  id: string;
@@ -511,10 +511,13 @@ export function ownerOnlyFacts(owner) {
511
511
  const NO_FACTS = ownerOnlyFacts(PLATFORM_OWNER);
512
512
  /**
513
513
  * Per item id: is its extension waiting for a person's confirmation (pending) and the permission
514
- * digest to confirm. Pending when the extension is not installed on the deployment, when the
515
- * installed version's permission set is not covered by the stored snapshot, or (a builtin item)
516
- * when the snapshot is the bootstrap step's, never confirmed by a person. Items whose latest
517
- * version has no extension are never pending.
514
+ * digest to confirm. Pending when the extension is not installed on the deployment, or when the
515
+ * installed version's permission set is not covered by the stored snapshot. A snapshot the
516
+ * bootstrap step wrote is consent like any other: the super admin's bootstrap manifests pin that
517
+ * version, so it covers exactly the pinned version's permissions (audited
518
+ * `extension.permissions_approved`, source `bootstrap`), and a version off the pin asking for more
519
+ * is pending as for any install (core#1226). Items whose latest version has no extension are never
520
+ * pending.
518
521
  */
519
522
  export async function itemConfirmations(admin, items, versions) {
520
523
  const out = new Map();
@@ -537,9 +540,7 @@ export async function itemConfirmations(admin, items, versions) {
537
540
  out.set(item.id, { pending: true, permissionsHash: await admin.packageReviewHash(sha) });
538
541
  continue;
539
542
  }
540
- const pending = v.snapshot === null ||
541
- blockingKeys(v.added).length > 0 ||
542
- (item.builtin && v.snapshot.source === "bootstrap");
543
+ const pending = v.snapshot === null || blockingKeys(v.added).length > 0;
543
544
  out.set(item.id, {
544
545
  pending,
545
546
  permissionsHash: pending && v.error === undefined ? v.reviewHash : null,
@@ -109,8 +109,9 @@ export declare class CatalogScopeService {
109
109
  * permission set with snapshot source `web` (`permissionsHash` is the item view's, the extension
110
110
  * review digest; a changed set -> 409 `extension.approval_stale`); an extension that was never
111
111
  * deployed (no install record) is installed and enabled first (the package is in the package
112
- * store from the import). Nothing waiting (a covered snapshot a person approved already, an item
113
- * without an extension) -> 409 `extension.not_pending`. The item's scope sync is owed by the
112
+ * store from the import). Nothing waiting (a covered snapshot, whether a person approved it or
113
+ * the bootstrap step wrote it for the pinned version; an item without an extension) -> 409
114
+ * `extension.not_pending`. The item's scope sync is owed by the
114
115
  * approval of an enabled extension, or by the enable.
115
116
  */
116
117
  confirmPermissions(actor: string, itemId: string, permissionsHash: string, opts?: ActorOpts): Promise<CatalogItemView>;
@@ -120,8 +120,9 @@ let CatalogScopeService = class CatalogScopeService {
120
120
  * permission set with snapshot source `web` (`permissionsHash` is the item view's, the extension
121
121
  * review digest; a changed set -> 409 `extension.approval_stale`); an extension that was never
122
122
  * deployed (no install record) is installed and enabled first (the package is in the package
123
- * store from the import). Nothing waiting (a covered snapshot a person approved already, an item
124
- * without an extension) -> 409 `extension.not_pending`. The item's scope sync is owed by the
123
+ * store from the import). Nothing waiting (a covered snapshot, whether a person approved it or
124
+ * the bootstrap step wrote it for the pinned version; an item without an extension) -> 409
125
+ * `extension.not_pending`. The item's scope sync is owed by the
125
126
  * approval of an enabled extension, or by the enable.
126
127
  */
127
128
  async confirmPermissions(actor, itemId, permissionsHash, opts = {}) {
@@ -129,7 +130,7 @@ let CatalogScopeService = class CatalogScopeService {
129
130
  throw notFound();
130
131
  const item = await this.db
131
132
  .selectFrom("catalog_items")
132
- .select(["id", "name", "latest_version", "builtin", "owner_org_id", "scope"])
133
+ .select(["id", "name", "latest_version", "owner_org_id", "scope"])
133
134
  .where("id", "=", itemId)
134
135
  .where("deleted_at", "is", null)
135
136
  .executeTakeFirst();
@@ -168,7 +169,7 @@ let CatalogScopeService = class CatalogScopeService {
168
169
  // A disabled install is what an earlier confirm that stopped before the enable left behind
169
170
  const disabled = current.desired?.state === "disabled";
170
171
  try {
171
- await this.extensions.approve(actor, item.name, { sha256: current.sha256, reviewHash: permissionsHash }, { ...opts, confirmBootstrap: item.builtin });
172
+ await this.extensions.approve(actor, item.name, { sha256: current.sha256, reviewHash: permissionsHash }, opts);
172
173
  }
173
174
  catch (e) {
174
175
  // Already approved but not enabled yet: carry on to the enable; else nothing to confirm
@@ -3,7 +3,6 @@ import type { ColumnType, Generated, Kysely } from "kysely";
3
3
  import type { ModelRef } from "../agents/definition.js";
4
4
  import type { AutomationChat, AutomationEventMarker, AutomationMode, AutomationOrigin, AutomationPauseReason, AutomationPrincipal, AutomationStatus, AutomationTrigger, AutomationUnattendedAsk, ScheduleMarker, TaskRunSkipReason, TaskRunStatus } from "../automations/types.js";
5
5
  import type { AccountAvatar } from "../identity/account-avatar.js";
6
- import type { DeviceNetwork } from "../sandbox/modes.js";
7
6
  import type { StartingExecutionGrants } from "../sandbox/operation-authority-types.js";
8
7
  import type { AuthorityEpochVector } from "../sandbox/permission-authority-epochs.js";
9
8
  import type { PermissionEscalation, PermissionExpansion, PermissionGrantSource, PermissionScopeKind } from "../sandbox/permission-call-types.js";
@@ -958,13 +957,13 @@ export interface AttachmentsTable {
958
957
  pages: number | null;
959
958
  created_at: Ts;
960
959
  expires_at: TsNullable;
961
- /** 0024:上传用途(技能包不能绑定到消息)。 */
962
- purpose: ColumnType<AttachmentPurpose, AttachmentPurpose | undefined, AttachmentPurpose>;
960
+ /** Attachment purposes are explicit on insert. */
961
+ purpose: AttachmentPurpose;
963
962
  /** 0068: the agent whose profile uses this avatar upload (set once, when it is saved). */
964
963
  agent_id: ColumnType<string | null, string | null | undefined, string | null>;
965
964
  }
966
965
  /**
967
- * What an attachment row is for: a chat attachment, a skill package zip, an agent avatar image, or
966
+ * What an attachment row is for: a skill package zip, an agent avatar image, or
968
967
  * (0163) an image the builtin Read stored with the calling conversation.
969
968
  */
970
969
  export type AttachmentPurpose = "skill-package" | "agent-avatar" | "read";
@@ -1074,11 +1073,6 @@ export interface BackgroundTasksTable {
1074
1073
  trigger_account_id: string;
1075
1074
  description: string;
1076
1075
  command: string;
1077
- /**
1078
- * A legacy row's session id (0071); NULL on every managed row. Never written after insert: no
1079
- * launch records a SID any more (permission activation W5-P2), so updates are refused by type.
1080
- */
1081
- sid: ColumnType<string | null, string | null | undefined, never>;
1082
1076
  output_path: string;
1083
1077
  status: ColumnType<"running" | "completed" | "failed" | "stopped" | "timed_out" | "lost", string | undefined, string>;
1084
1078
  lost_reason: ColumnType<string | null, string | null | undefined, string | null>;
@@ -1088,14 +1082,13 @@ export interface BackgroundTasksTable {
1088
1082
  deadline_at: Date | string;
1089
1083
  /** NULL while the launch is reserved but not started (0071). */
1090
1084
  sandbox_created_at: Date | string | null;
1091
- kill_pending: ColumnType<boolean, boolean | undefined, boolean>;
1092
1085
  read_offset: ColumnType<string, number | string | undefined, number | string>;
1093
1086
  /** Set while a stop is under way (0072); the poller skips such a task. */
1094
1087
  stopping_at: ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
1095
1088
  /** 0088, renamed in 0105: the device the task runs in. */
1096
1089
  device_id: ColumnType<string | null, string | null | undefined, string | null>;
1097
- /** 0152: the durable launch state of a managed task; `legacy` for SID rows. */
1098
- launch_state: ColumnType<BackgroundLaunchState, BackgroundLaunchState | undefined, BackgroundLaunchState>;
1090
+ /** 0152: the durable launch state of a managed task. */
1091
+ launch_state: BackgroundLaunchState;
1099
1092
  operation_id: NullableText;
1100
1093
  input_digest: NullableText;
1101
1094
  run_execution_id: NullableText;
@@ -1120,42 +1113,9 @@ export interface BackgroundTasksTable {
1120
1113
  cancel_failure: ColumnType<"unreachable" | "failed" | null, "unreachable" | "failed" | null | undefined, "unreachable" | "failed" | null>;
1121
1114
  /** 0184: that failure's message, clipped. */
1122
1115
  cancel_failure_detail: NullableText;
1123
- /** 0157: the exact incarnation a legacy dispatch was admitted for; null on historical rows. */
1124
- legacy_dispatch_provider: NullableText;
1125
- legacy_dispatch_generation: NullableText;
1126
- /** 0157: whether a legacy launch may have dispatched its command (see the migration). */
1127
- legacy_dispatch: ColumnType<"unknown" | "reserved" | "dispatched", "unknown" | "reserved" | "dispatched" | undefined, "unknown" | "reserved" | "dispatched">;
1128
- }
1129
- /** 0152: see the migration for the meaning of each state. */
1130
- export type BackgroundLaunchState = "legacy" | "pending" | "dispatched" | "acknowledged" | "cancel-pending" | "terminal";
1131
- /** 0023_sandboxes.sql: the legacy per-conversation sandbox; kept only for the cleanup job (0088). */
1132
- export interface LegacySandboxesTable {
1133
- conversation_id: string;
1134
- org_id: string;
1135
- provider: string;
1136
- /** 提供方的 `SandboxHandle`;creating 时为 NULL。 */
1137
- handle: ColumnType<{
1138
- id: string;
1139
- [k: string]: unknown;
1140
- } | null, string | null | undefined, string | null>;
1141
- status: "creating" | "running" | "suspended" | "destroyed";
1142
- last_used_at: Ts;
1143
- running_since: TsNullable;
1144
- created_at: Ts;
1145
- suspended_at: TsNullable;
1146
- destroyed_at: TsNullable;
1147
- /** 防护号:锁内的每次 status / handle 写入都按它比较并加一。 */
1148
- generation: ColumnType<number, number | undefined, number>;
1149
- /** 曾经成功创建过实例(只会置 true)。 */
1150
- had_instance: ColumnType<boolean, boolean | undefined, boolean>;
1151
- /** 换提供方时留下的旧实例。 */
1152
- prev_provider: string | null;
1153
- prev_handle: ColumnType<{
1154
- id: string;
1155
- [k: string]: unknown;
1156
- } | null, string | null | undefined, string | null>;
1157
- sweep_failed_at: TsNullable;
1158
1116
  }
1117
+ /** 0152: see the migration for the meaning of each managed launch state. */
1118
+ export type BackgroundLaunchState = "pending" | "dispatched" | "acknowledged" | "cancel-pending" | "terminal";
1159
1119
  type InstanceHandle = ColumnType<{
1160
1120
  id: string;
1161
1121
  [k: string]: unknown;
@@ -1176,14 +1136,6 @@ export interface DevicesTable {
1176
1136
  demoted_from_provider: ColumnType<string | null, string | null | undefined, string | null>;
1177
1137
  /** 0131: a cloud device's narrowing switch (`sandbox`); null follows the platform and the org. */
1178
1138
  mode: ColumnType<"sandbox" | null, "sandbox" | null | undefined, "sandbox" | null>;
1179
- /** 0154: a cloud device's owner Full ceiling (B1 snapshot); null: not snapshotted yet. */
1180
- owner_full_access: ColumnType<boolean | null, boolean | null | undefined, boolean | null>;
1181
- /** 0154: a cloud device's outer network (B1 snapshot); null: not snapshotted yet. */
1182
- outer_network: ColumnType<DeviceNetwork | null, string | null | undefined, string | null>;
1183
- /** 0154: the provenance of the B1 snapshot. */
1184
- permission_migration: ColumnType<unknown, string | null | undefined, string | null>;
1185
- /** 0154: the applied limits must be established before any operation is admitted. */
1186
- permission_reconcile_required: ColumnType<boolean, boolean | undefined, boolean>;
1187
1139
  /** 0165: a cloud device's sandbox network choice; null follows the org, `none` is closed. */
1188
1140
  network_mode: ColumnType<"open" | "allowlist" | "none" | null, "open" | "allowlist" | "none" | null | undefined, "open" | "allowlist" | "none" | null>;
1189
1141
  /** 0165: a cloud device's allowlist hosts (a JSON array), used while the mode is `allowlist`. */
@@ -1937,50 +1889,6 @@ export interface DeviceGenerationHighWaterTable {
1937
1889
  high_water_ms: ColumnType<string, string | number, string | number>;
1938
1890
  updated_at: Ts;
1939
1891
  }
1940
- export interface LegacyLaunchFreezeTable {
1941
- id: "platform";
1942
- frozen_at: Generated<Date>;
1943
- frozen_by: string;
1944
- /** Migration 0158: when the freeze's enumeration last completed stable; null before. */
1945
- enumerated_at: TsNullable;
1946
- }
1947
- export interface DeviceRetirementObligationsTable {
1948
- id: Generated<string>;
1949
- device_id: string;
1950
- org_id: string;
1951
- provider: string;
1952
- instance_generation: string;
1953
- state: ColumnType<"open" | "quarantined" | "resolved" | "abandoned", "open" | "quarantined" | "resolved" | "abandoned" | undefined, "open" | "quarantined" | "resolved" | "abandoned">;
1954
- /** When the obligation was abandoned with its deleted device (never evidence). */
1955
- abandoned_at: TsNullable;
1956
- /** `exact-cancelled`: every member was a revoked start cancelled by its exact ref (B-22). */
1957
- resolution: ColumnType<"provider-destroyed" | "host-rebooted" | "exact-cancelled" | null, "provider-destroyed" | "host-rebooted" | "exact-cancelled" | null | undefined, "provider-destroyed" | "host-rebooted" | "exact-cancelled" | null>;
1958
- /** A local incarnation: the machine and its boot identity when recorded (null: none). */
1959
- boot_machine_id: ColumnType<string | null, string | null | undefined, string | null>;
1960
- boot_id: ColumnType<string | null, string | null | undefined, string | null>;
1961
- reason: ColumnType<string | null, string | null | undefined, string | null>;
1962
- attempts: ColumnType<number, number | undefined, number>;
1963
- last_attempt_at: TsNullable;
1964
- last_error: ColumnType<string | null, string | null | undefined, string | null>;
1965
- created_at: Generated<Date>;
1966
- resolved_at: TsNullable;
1967
- }
1968
- export interface DeviceRetirementMembersTable {
1969
- obligation_id: string;
1970
- kind: "legacy-task" | "revoked-start";
1971
- ref_id: string;
1972
- settled: ColumnType<boolean, boolean | undefined, boolean>;
1973
- created_at: Generated<Date>;
1974
- }
1975
- /** 0204: the exact local provider identity of a committed kernel incarnation. */
1976
- export interface DeviceInstanceRetirementIdentitiesTable {
1977
- org_id: string;
1978
- device_id: string;
1979
- provider: string;
1980
- instance_generation: string;
1981
- provider_generation: string;
1982
- attested_at: TsNullable;
1983
- }
1984
1892
  export interface DeviceInstanceDestructionsTable {
1985
1893
  confirmed: Generated<boolean>;
1986
1894
  device_id: string;
@@ -2007,15 +1915,8 @@ export interface KernelDatabase {
2007
1915
  device_permission_reports: DevicePermissionReportsTable;
2008
1916
  /** Migration 0155: per-device generation high-water mark; outlives instance rows. */
2009
1917
  device_generation_high_water: DeviceGenerationHighWaterTable;
2010
- /** Migration 0157: the durable legacy-launch freeze (one row, never removed). */
2011
- legacy_launch_freeze: LegacyLaunchFreezeTable;
2012
- /** Migration 0157: the physical no-reuse obligation of one old instance incarnation. */
2013
- device_retirement_obligations: DeviceRetirementObligationsTable;
2014
- /** Migration 0157: what put a retirement obligation there. */
2015
- device_retirement_members: DeviceRetirementMembersTable;
2016
1918
  /** Migration 0157: provider-confirmed destruction of a cloud instance incarnation. */
2017
1919
  device_instance_destructions: DeviceInstanceDestructionsTable;
2018
- device_instance_retirement_identities: DeviceInstanceRetirementIdentitiesTable;
2019
1920
  sandbox_operation_intents: SandboxOperationIntentsTable;
2020
1921
  sandbox_operation_payload_chunks: SandboxOperationPayloadChunksTable;
2021
1922
  permission_config_publication: PermissionConfigPublicationTable;
@@ -2072,7 +1973,6 @@ export interface KernelDatabase {
2072
1973
  org_anonymous_accounts: OrgAnonymousAccountsTable;
2073
1974
  directory_exclusions: DirectoryExclusionsTable;
2074
1975
  attachments: AttachmentsTable;
2075
- sandboxes: LegacySandboxesTable;
2076
1976
  devices: DevicesTable;
2077
1977
  device_instances: DeviceInstancesTable;
2078
1978
  device_defaults: DeviceDefaultsTable;
@@ -108,12 +108,10 @@ export declare class ExtensionAdmin {
108
108
  * recomputed now -> `extension.approval_stale`; a config-declared extension's `sha256` must be
109
109
  * null (otherwise `validation_failed`);
110
110
  * - the snapshot already covers the current permission set (nothing to approve, F-N) ->
111
- * `extension.not_pending`, except with `confirmBootstrap` when the snapshot is the bootstrap
112
- * step's (the catalog's confirm re-writes it with source web).
111
+ * `extension.not_pending` (a snapshot the bootstrap step wrote included: the pin is consent).
113
112
  */
114
113
  approve(actor: string, name: string, body: ApproveBody, opts?: {
115
114
  actorTokenId?: string;
116
- confirmBootstrap?: boolean;
117
115
  }): Promise<AdminExtensionView>;
118
116
  private writeApproval;
119
117
  /** 配置声明 → 安装记录(与配置声明重名的安装记录不生效,不单列)。`only` 给出时只取这一个。 */
@@ -166,8 +166,7 @@ let ExtensionAdmin = class ExtensionAdmin {
166
166
  * recomputed now -> `extension.approval_stale`; a config-declared extension's `sha256` must be
167
167
  * null (otherwise `validation_failed`);
168
168
  * - the snapshot already covers the current permission set (nothing to approve, F-N) ->
169
- * `extension.not_pending`, except with `confirmBootstrap` when the snapshot is the bootstrap
170
- * step's (the catalog's confirm re-writes it with source web).
169
+ * `extension.not_pending` (a snapshot the bootstrap step wrote included: the pin is consent).
171
170
  */
172
171
  async approve(actor, name, body, opts = {}) {
173
172
  const s = (await this.subjects(name))[0];
@@ -182,7 +181,7 @@ let ExtensionAdmin = class ExtensionAdmin {
182
181
  throw stale();
183
182
  if (body.reviewHash !== reviewHash(s.set, s.warnings))
184
183
  throw stale();
185
- await this.writeApproval(actor, name, s, opts.actorTokenId, stale, opts.confirmBootstrap === true);
184
+ await this.writeApproval(actor, name, s, opts.actorTokenId, stale);
186
185
  try {
187
186
  await this.bus.publish(PLUGINS_CHANGED_TOPIC, { plugin: name });
188
187
  }
@@ -198,7 +197,7 @@ let ExtensionAdmin = class ExtensionAdmin {
198
197
  }
199
198
  return this.get(name);
200
199
  }
201
- async writeApproval(actor, name, s, actorTokenId, stale, confirmBootstrap) {
200
+ async writeApproval(actor, name, s, actorTokenId, stale) {
202
201
  const db = this.db;
203
202
  await this.adminLock.lockAndAuthorize(actor);
204
203
  await this.approveLock.lock(name);
@@ -218,7 +217,7 @@ let ExtensionAdmin = class ExtensionAdmin {
218
217
  }
219
218
  const snapRow = await db
220
219
  .selectFrom("extension_permission_snapshots")
221
- .select(["version", "permissions", "source"])
220
+ .select(["version", "permissions"])
222
221
  .where("plugin", "=", name)
223
222
  .forUpdate()
224
223
  .executeTakeFirst();
@@ -226,9 +225,7 @@ let ExtensionAdmin = class ExtensionAdmin {
226
225
  version: snapRow.version,
227
226
  permissions: snapRow.permissions,
228
227
  };
229
- // `confirmBootstrap` (the catalog's confirm): a snapshot the bootstrap step wrote was never
230
- // confirmed by a person, so a covered one is still taken over
231
- if (snapshotCovers(snap, s.set) && !(confirmBootstrap && snapRow?.source === "bootstrap")) {
228
+ if (snapshotCovers(snap, s.set)) {
232
229
  throw new ApiError("extension.not_pending", `Extension ${name} ${s.version} has no new permissions awaiting approval`);
233
230
  }
234
231
  const { added, removed } = diffPermissions(snap?.permissions, s.set);
@@ -780,7 +780,7 @@ let AgentsOperations = class AgentsOperations {
780
780
  }),
781
781
  defineOperation({
782
782
  id: "agents.readiness",
783
- description: "Whether the org can run agents: modelProvider is ready when the org has a chat model an agent can pick (the list agents.create chooses from); no_models when model providers are on but none gives one (unusableProviders names each provider and its reason: list_failed with errorKind, e.g. auth for a rejected key, or no_chat_models; orgCanFix says whether an org admin can fix it on Settings > Models, else only the super admin can on the admin Models page); org_fixable when no provider is on but an org admin can make one available on Settings > Models (orgFixableProviders names each provider and its reason: not_enabled, switch it on; needs_config, fill the org's config); none when only the super admin can help; how many agents you can see, and the optional setup steps visible to your role. checklistDismissed is your own preference in this org.",
783
+ description: "Whether the org can run agents: modelProvider is ready when the org has a chat model an agent can pick (the list agents.create chooses from); no_models when model providers are on but none gives one (unusableProviders names each provider and its reason: list_failed with errorKind, e.g. auth for a rejected key, or no_chat_models; orgCanFix says whether an org admin can fix it on Settings > Models, else only the super admin can on the admin Models page); org_fixable when no provider is on but an org admin can make one available on Settings > Models (orgFixableProviders names each provider and its reason: not_enabled, switch it on; needs_config, fill the org's config; needsOrgConfig says whether it also needs the org's own config, such as an API key the platform left empty); none when only the super admin can help; how many agents you can see, and the optional setup steps visible to your role. checklistDismissed is your own preference in this org.",
784
784
  input: z.object({}).strict(),
785
785
  example: {},
786
786
  authz: { orgAction: "org.read" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.126",
3
+ "version": "0.1.0-rc.128",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,154 @@
1
+ -- Contract the storage left behind by the pre-release reader and writer removals.
2
+ -- 0208 already converted permission settings and 0210 verified any history export receipt.
3
+
4
+ -- These are the two tables whose metadata is about to be contracted.
5
+ LOCK TABLE attachments, file_shares IN ACCESS EXCLUSIVE MODE;
6
+
7
+ -- capybara:allow-destructive Block the contract if the earlier copy did not carry forward still-live file or share metadata.
8
+ DO $$
9
+ BEGIN
10
+ IF EXISTS (
11
+ SELECT FROM attachments a
12
+ WHERE a.purpose = 'chat' AND a.status IN ('ready', 'pending')
13
+ AND (a.expires_at IS NULL OR a.expires_at > now() OR a.conversation_id IS NOT NULL)
14
+ AND NOT EXISTS (
15
+ SELECT FROM files f
16
+ WHERE f.id = a.id AND f.org_id = a.org_id AND f.account_id = a.account_id
17
+ AND (f.status = 'deleted' OR (a.status = 'pending' AND f.staging_key = a.object_key)
18
+ OR (f.blob_id IS NOT NULL AND (a.conversation_id IS NULL OR EXISTS (
19
+ SELECT FROM conversation_files cf
20
+ WHERE cf.conversation_id = a.conversation_id AND cf.file_id = f.id
21
+ AND cf.org_id = a.org_id
22
+ ))))
23
+ )
24
+ ) THEN
25
+ RAISE EXCEPTION '0211 has live chat attachments without migrated library metadata. Follow the pre-release cleanup release notes.';
26
+ END IF;
27
+
28
+ IF EXISTS (
29
+ SELECT FROM file_shares
30
+ WHERE object_key IS NOT NULL AND blob_id IS NULL AND revoked_at IS NULL
31
+ AND (expires_at IS NULL OR expires_at > now())
32
+ ) THEN
33
+ RAISE EXCEPTION '0211 has live shares without a migrated blob. Follow the pre-release cleanup release notes.';
34
+ END IF;
35
+ END
36
+ $$;
37
+
38
+ -- capybara:allow-destructive Only the retired SID launcher wrote these tasks. Managed reservations keep their exact execution state.
39
+ DELETE FROM background_tasks WHERE launch_state = 'legacy';
40
+
41
+ -- capybara:allow-destructive Remove SID-only fields and checks whose writers were removed before the contract.
42
+ ALTER TABLE background_tasks
43
+ DROP COLUMN IF EXISTS sid,
44
+ DROP COLUMN IF EXISTS kill_pending,
45
+ DROP COLUMN IF EXISTS legacy_dispatch,
46
+ DROP COLUMN IF EXISTS legacy_dispatch_provider,
47
+ DROP COLUMN IF EXISTS legacy_dispatch_generation,
48
+ ALTER COLUMN launch_state DROP DEFAULT,
49
+ DROP CONSTRAINT IF EXISTS background_tasks_launch_state_check,
50
+ DROP CONSTRAINT IF EXISTS background_tasks_managed_reservation_check,
51
+ DROP CONSTRAINT IF EXISTS background_tasks_managed_dispatch_check;
52
+
53
+ ALTER TABLE background_tasks
54
+ ADD CONSTRAINT background_tasks_launch_state_check
55
+ CHECK (launch_state IN ('pending', 'dispatched', 'acknowledged', 'cancel-pending', 'terminal')),
56
+ ADD CONSTRAINT background_tasks_managed_reservation_check
57
+ CHECK (operation_id IS NOT NULL AND working_root IS NOT NULL AND retain_until IS NOT NULL
58
+ AND left(output_path, 1) = '/'),
59
+ ADD CONSTRAINT background_tasks_managed_dispatch_check
60
+ CHECK (launch_state IN ('pending', 'terminal')
61
+ OR (input_digest IS NOT NULL AND run_execution_id IS NOT NULL AND task_tag IS NOT NULL
62
+ AND instance_id IS NOT NULL AND instance_provider IS NOT NULL
63
+ AND instance_provider_version IS NOT NULL AND instance_generation IS NOT NULL
64
+ AND profile_revision IS NOT NULL AND ceiling_revision IS NOT NULL));
65
+
66
+ -- capybara:allow-destructive Replace the managed-call partial index with the same uniqueness over all remaining tasks.
67
+ DROP INDEX IF EXISTS background_tasks_managed_call_idx;
68
+ CREATE UNIQUE INDEX IF NOT EXISTS background_tasks_managed_call_idx ON background_tasks (run_id, call_id);
69
+
70
+ -- capybara:allow-destructive 0208 carried forward the inherited network restrictions. The report-driven runtime has no snapshot readers.
71
+ ALTER TABLE devices
72
+ DROP COLUMN IF EXISTS owner_full_access,
73
+ DROP COLUMN IF EXISTS outer_network,
74
+ DROP COLUMN IF EXISTS permission_migration,
75
+ DROP COLUMN IF EXISTS permission_reconcile_required;
76
+
77
+ -- capybara:allow-destructive Obsolete per-conversation sandbox records. The device instances and their storage remain.
78
+ DROP TABLE IF EXISTS sandboxes;
79
+ -- capybara:allow-destructive The legacy launch freeze has no writers or readers after retirement removal.
80
+ DROP TABLE IF EXISTS legacy_launch_freeze;
81
+ -- capybara:allow-destructive Retire obsolete proof membership and its trigger before dropping the referenced obligations.
82
+ DROP TABLE IF EXISTS device_retirement_members;
83
+ -- capybara:allow-destructive The proof trigger belonged only to the removed retirement members.
84
+ DROP FUNCTION IF EXISTS reopen_local_retirement_proof();
85
+ -- capybara:allow-destructive The old retirement ledger no longer owns cleanup. Keep device_instance_destructions for live reconciliation.
86
+ DROP TABLE IF EXISTS device_retirement_obligations;
87
+ -- capybara:allow-destructive Remove exact identities used only by the retired local proof flow.
88
+ DROP TABLE IF EXISTS device_instance_retirement_identities;
89
+ -- capybara:allow-destructive This generation scan index served the removed retirement enumerator only.
90
+ DROP INDEX IF EXISTS sandbox_operation_intents_owed_background_revoke_idx;
91
+
92
+ -- capybara:allow-destructive Only the retired permission tier syntax used this prefix.
93
+ DELETE FROM automation_grants WHERE tool_key LIKE 'tier:%';
94
+
95
+ -- capybara:allow-destructive Effective extension config now uses scoped secret storage instead of the retired plugin-config credentials.
96
+ DELETE FROM secrets
97
+ WHERE namespace = 'kernel' AND org_id <> '_deployment' AND key LIKE 'plugin-config:%';
98
+
99
+ -- capybara:allow-destructive Delete obsolete markers and retired permission keys whose current restrictions were migrated by 0208.
100
+ DELETE FROM deployment_settings WHERE key IN (
101
+ 'fileLibraryCopySettled', 'templateConnectorsReconciled', 'devicesAutoMode', 'devicesFullAccess'
102
+ );
103
+
104
+ -- capybara:allow-destructive Remove retired permission keys already converted by 0208, leaving current and unrelated settings untouched.
105
+ UPDATE orgs SET settings = settings - ARRAY['autoMode', 'fullAccess', 'cloudNetwork']
106
+ WHERE jsonb_typeof(settings) = 'object' AND settings ?| ARRAY['autoMode', 'fullAccess', 'cloudNetwork'];
107
+
108
+ -- capybara:allow-destructive These jobs belonged to the removed backfill and share-object paths.
109
+ DELETE FROM outbox
110
+ WHERE queue = 'cap-kernel-maintenance' AND job_name IN ('file-library-backfill', 'share-object-delete');
111
+
112
+ CREATE TEMP TABLE IF NOT EXISTS retired_trigger_dispatches ON COMMIT DROP AS
113
+ SELECT id, data ->> 'eventId' AS event_id
114
+ FROM outbox
115
+ WHERE queue = 'cap-kernel-maintenance' AND job_name = 'trigger-dispatch'
116
+ AND job_id ~ '^trigger-dispatch-[0-9a-f-]{36}-sweep-[0-9]+$'
117
+ AND starts_with(job_id, 'trigger-dispatch-' || (data ->> 'eventId') || '-sweep-');
118
+
119
+ -- A sweep dispatch could be the only job owed for a still-pending event. Transfer it to the
120
+ -- current dispatcher with a deterministic fresh id, distinct from any old BullMQ job.
121
+ INSERT INTO outbox (queue, job_name, job_id, data, org_id)
122
+ SELECT 'cap-kernel-maintenance', 'trigger-dispatch', 'trigger-dispatch-' || e.id || '-0211',
123
+ jsonb_build_object('eventId', e.id, 'orgId', e.org_id), e.org_id
124
+ FROM trigger_events e
125
+ WHERE e.state = 'pending' AND e.audience IS NOT NULL
126
+ AND EXISTS (SELECT FROM retired_trigger_dispatches d WHERE d.event_id = e.id)
127
+ AND NOT EXISTS (
128
+ SELECT FROM outbox current_dispatch
129
+ WHERE current_dispatch.queue = 'cap-kernel-maintenance'
130
+ AND current_dispatch.job_name = 'trigger-dispatch' AND current_dispatch.dead_at IS NULL
131
+ AND current_dispatch.job_id = 'trigger-dispatch-' || e.id
132
+ )
133
+ ON CONFLICT (queue, job_id) WHERE dead_at IS NULL DO NOTHING;
134
+
135
+ -- capybara:allow-destructive Remove only the retired directed-trigger recovery jobs after preserving pending delivery.
136
+ DELETE FROM outbox WHERE id IN (SELECT id FROM retired_trigger_dispatches);
137
+
138
+ -- capybara:allow-destructive The earlier copy migrated chat attachment metadata to the file library. Leave blob and storage objects alone.
139
+ DELETE FROM attachments WHERE purpose = 'chat';
140
+
141
+ -- capybara:allow-destructive Replace the attachment default and check with the current explicit purposes.
142
+ ALTER TABLE attachments ALTER COLUMN purpose DROP DEFAULT,
143
+ DROP CONSTRAINT IF EXISTS attachments_purpose_check;
144
+ ALTER TABLE attachments ADD CONSTRAINT attachments_purpose_check
145
+ CHECK (purpose IN ('skill-package', 'agent-avatar', 'read'));
146
+
147
+ -- capybara:allow-destructive The one-off file library copy has run and its runtime callers are gone.
148
+ DROP FUNCTION IF EXISTS file_library_copy(timestamptz);
149
+ -- capybara:allow-destructive Shares resolve their snapshot through blob_id after the file library cutover.
150
+ ALTER TABLE file_shares DROP COLUMN IF EXISTS object_key;
151
+ -- capybara:allow-destructive The removed org config reader has been replaced by the current storage paths.
152
+ ALTER TABLE extension_org_configs DROP COLUMN IF EXISTS config;
153
+ -- capybara:allow-destructive 0210 has consumed the one-time export receipt. The verified manifests and transcripts stay outside PostgreSQL.
154
+ DROP TABLE IF EXISTS capybara._history_export_0210;