@kici-dev/orchestrator 0.2.0 → 0.3.0

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/dist/cli.js CHANGED
@@ -10,7 +10,7 @@ import { AgentPlatform, BaseColdStore, ChunkLru, addLogsToArchive, chunkObjectKe
10
10
  import crypto$1, { createDecipheriv, createHash, createHmac, createPublicKey, generateKeyPairSync, hkdfSync, randomBytes, randomUUID } from "node:crypto";
11
11
  import { createInterface } from "node:readline";
12
12
  import { sql } from "kysely";
13
- import { AccessLogSource, DEFAULT_APPROVAL_EXPIRY_HOURS, KICI_AGENT_ENV_PREFIX, KNOWN_ROLES, OrchestratorMode, PLATFORM_CONNECTED_MODES, PRIVILEGED_ROOT_LABEL, ScalerBackendType, ScalerEventType, TERMINAL_JOB_STATES, TERMINAL_RUN_STATES, WS_MAX_PAYLOAD_BYTES, accessLogWarmSqlCase, agentLabelOf, attestationVerifyStatusSchema, flattenActor, getAccessLogColdDays, getSecretAuditLogColdDays, matcherSatisfiedBy, minAccessLogWarmDays, minSecretAuditLogWarmDays, parseHostPropertyAssignments, scalerAgentLabels, scalerPlatformSchema, secretAuditLogWarmSqlCase, shouldRecordAccess, shouldRecordSecretResolve } from "@kici-dev/engine";
13
+ import { AccessLogSource, DEFAULT_APPROVAL_EXPIRY_HOURS, ExecutionJobStatus, KICI_AGENT_ENV_PREFIX, KNOWN_ROLES, OrchestratorMode, PLATFORM_CONNECTED_MODES, PRIVILEGED_ROOT_LABEL, ScalerBackendType, ScalerEventType, TERMINAL_JOB_STATES, TERMINAL_RUN_STATES, WS_MAX_PAYLOAD_BYTES, accessLogWarmSqlCase, agentLabelOf, attestationVerifyStatusSchema, flattenActor, getAccessLogColdDays, getSecretAuditLogColdDays, matcherSatisfiedBy, minAccessLogWarmDays, minSecretAuditLogWarmDays, parseHostPropertyAssignments, scalerAgentLabels, scalerPlatformSchema, secretAuditLogWarmSqlCase, shouldRecordAccess, shouldRecordSecretResolve } from "@kici-dev/engine";
14
14
  import { access, chmod, constants as constants$1, copyFile, link, mkdir, open, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
15
15
  import { parse, stringify } from "yaml";
16
16
  import { z } from "zod";
@@ -70,6 +70,46 @@ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
70
70
  * All methods are thin wrappers around fetch() that handle JSON serialization,
71
71
  * error formatting, and URL construction.
72
72
  */
73
+ /**
74
+ * `fetch` rejects with a bare `TypeError: fetch failed` when it cannot reach the
75
+ * host — it names neither the address dialled nor the knob that sets it. Printed
76
+ * through the CLI's `Error: ${message}` handler that becomes `Error: fetch
77
+ * failed`, which reads like a fault in the subcommand rather than a misaddressed
78
+ * client, and sends the operator debugging the wrong thing.
79
+ *
80
+ * The trap is sharpened by two details of this CLI. The base URL comes from
81
+ * `KICI_ADMIN_URL`, not the `KICI_ORCHESTRATOR_URL` an operator is likelier to
82
+ * have exported; and subcommands accepting `--database-url` fall back to direct
83
+ * DB access, so on a host with `KICI_DATABASE_URL` set they keep working while
84
+ * the HTTP-only ones fail — making it look like specific subcommands are broken.
85
+ *
86
+ * So: name the address, name the variable, and name the near-miss.
87
+ */
88
+ /**
89
+ * Best-effort one-line detail from a rejected `fetch`. Returns '' when nothing
90
+ * useful is available, so the caller can omit the parenthetical rather than
91
+ * print an empty one.
92
+ */
93
+ function firstCauseMessage(err) {
94
+ if (!(err instanceof Error)) return "";
95
+ const cause = err.cause;
96
+ if (!(cause instanceof Error)) return "";
97
+ if (cause.message) return cause.message;
98
+ const nested = cause.errors;
99
+ if (Array.isArray(nested)) {
100
+ for (const e of nested) if (e instanceof Error && e.message) return e.message;
101
+ }
102
+ return "";
103
+ }
104
+ async function fetchAdminApi(url, init, baseUrl) {
105
+ try {
106
+ return await fetch(url, init);
107
+ } catch (err) {
108
+ const detail = firstCauseMessage(err);
109
+ const cause = detail ? ` (${detail})` : "";
110
+ throw new Error(`cannot reach the orchestrator admin API at ${baseUrl}${cause}. Set KICI_ADMIN_URL to the orchestrator's HTTP address, or pass --base-url where the subcommand accepts it. Note KICI_ORCHESTRATOR_URL is NOT read by this CLI; if other subcommands appear to work, they are using the --database-url / KICI_DATABASE_URL direct-DB path rather than HTTP.`, { cause: err });
111
+ }
112
+ }
73
113
  var AdminApiClient = class {
74
114
  baseUrl;
75
115
  token;
@@ -81,16 +121,14 @@ var AdminApiClient = class {
81
121
  * Make an authenticated HTTP request to the admin API.
82
122
  */
83
123
  async request(method, path, body) {
84
- const url = `${this.baseUrl}${path}`;
85
- const headers = {
86
- Authorization: `Bearer ${this.token}`,
87
- "Content-Type": "application/json"
88
- };
89
- const res = await fetch(url, {
124
+ const res = await fetchAdminApi(`${this.baseUrl}${path}`, {
90
125
  method,
91
- headers,
126
+ headers: {
127
+ Authorization: `Bearer ${this.token}`,
128
+ "Content-Type": "application/json"
129
+ },
92
130
  body: body !== void 0 ? JSON.stringify(body) : void 0
93
- });
131
+ }, this.baseUrl);
94
132
  if (!res.ok) {
95
133
  const text = await res.text();
96
134
  let errorBody;
@@ -138,11 +176,10 @@ var AdminApiClient = class {
138
176
  * Public GET request returning raw response text.
139
177
  */
140
178
  async getText(path) {
141
- const url = `${this.baseUrl}${path}`;
142
- const res = await fetch(url, {
179
+ const res = await fetchAdminApi(`${this.baseUrl}${path}`, {
143
180
  method: "GET",
144
181
  headers: { Authorization: `Bearer ${this.token}` }
145
- });
182
+ }, this.baseUrl);
146
183
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
147
184
  return res.text();
148
185
  }
@@ -155,14 +192,14 @@ var AdminApiClient = class {
155
192
  * response is an octet-stream, so it is read as bytes rather than parsed JSON.
156
193
  */
157
194
  async downloadFleetBundle(body, outPath) {
158
- const res = await fetch(`${this.baseUrl}/admin/fleet-bundle`, {
195
+ const res = await fetchAdminApi(`${this.baseUrl}/admin/fleet-bundle`, {
159
196
  method: "POST",
160
197
  headers: {
161
198
  Authorization: `Bearer ${this.token}`,
162
199
  "Content-Type": "application/json"
163
200
  },
164
201
  body: JSON.stringify(body)
165
- });
202
+ }, this.baseUrl);
166
203
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
167
204
  const buf = Buffer.from(await res.arrayBuffer());
168
205
  fs$1.writeFileSync(outPath, buf);
@@ -1971,6 +2008,7 @@ var init_schema = __esmMin((() => {
1971
2008
  rosterTtlMs: z.coerce.number().default(18e5),
1972
2009
  queueMaxDepth: z.coerce.number().default(1e3),
1973
2010
  queueTimeoutMs: z.coerce.number().default(36e5),
2011
+ unroutableGraceMs: z.coerce.number().default(12e4),
1974
2012
  /**
1975
2013
  * Operator-facing backpressure warning threshold. See `configSchema` in
1976
2014
  * `packages/orchestrator/src/config.ts` for the user-facing prose.
@@ -2454,8 +2492,8 @@ server:
2454
2492
  //#endregion
2455
2493
  //#region src/db/migrations/001_initial.ts
2456
2494
  var _001_initial_exports = /* @__PURE__ */ __exportAll({
2457
- down: () => down$106,
2458
- up: () => up$106
2495
+ down: () => down$107,
2496
+ up: () => up$107
2459
2497
  });
2460
2498
  /**
2461
2499
  * Squashed initial migration -- creates the complete Orchestrator database schema.
@@ -3147,7 +3185,7 @@ const DDL_STATEMENTS = [
3147
3185
  `ALTER TABLE ONLY public.held_runs
3148
3186
  ADD CONSTRAINT held_runs_environment_id_fkey FOREIGN KEY (environment_id) REFERENCES public.environments(id);`
3149
3187
  ];
3150
- async function up$106(db) {
3188
+ async function up$107(db) {
3151
3189
  for (const stmt of DDL_STATEMENTS) await sql.raw(stmt).execute(db);
3152
3190
  await sql`
3153
3191
  INSERT INTO cluster_meta (key, value)
@@ -3169,7 +3207,7 @@ async function up$106(db) {
3169
3207
  * Rollback drops everything created above. Uses CASCADE on table drops to cut
3170
3208
  * through the FK graph without relying on exact topological order.
3171
3209
  */
3172
- async function down$106(db) {
3210
+ async function down$107(db) {
3173
3211
  for (const [trig, tbl] of [["source_secrets_change_trigger", "scoped_secrets"], ["sources_change_trigger", "sources"]]) await sql.raw(`DROP TRIGGER IF EXISTS ${trig} ON public.${tbl}`).execute(db);
3174
3212
  for (const table of [
3175
3213
  "workflow_registrations",
@@ -3216,8 +3254,8 @@ async function down$106(db) {
3216
3254
  //#endregion
3217
3255
  //#region src/db/migrations/002_config_versions_key_version.ts
3218
3256
  var _002_config_versions_key_version_exports = /* @__PURE__ */ __exportAll({
3219
- down: () => down$105,
3220
- up: () => up$105
3257
+ down: () => down$106,
3258
+ up: () => up$106
3221
3259
  });
3222
3260
  /**
3223
3261
  * Add key_version column to config_versions so that sensitive-field encryption
@@ -3231,13 +3269,13 @@ var _002_config_versions_key_version_exports = /* @__PURE__ */ __exportAll({
3231
3269
  * No index is needed: rotation does a full-table scan; reads are by
3232
3270
  * `version` primary key and never filter on `key_version`.
3233
3271
  */
3234
- async function up$105(db) {
3272
+ async function up$106(db) {
3235
3273
  await sql`
3236
3274
  ALTER TABLE public.config_versions
3237
3275
  ADD COLUMN key_version integer NOT NULL DEFAULT 1
3238
3276
  `.execute(db);
3239
3277
  }
3240
- async function down$105(db) {
3278
+ async function down$106(db) {
3241
3279
  await sql`
3242
3280
  ALTER TABLE public.config_versions
3243
3281
  DROP COLUMN key_version
@@ -3246,8 +3284,8 @@ async function down$105(db) {
3246
3284
  //#endregion
3247
3285
  //#region src/db/migrations/003_access_log.ts
3248
3286
  var _003_access_log_exports = /* @__PURE__ */ __exportAll({
3249
- down: () => down$104,
3250
- up: () => up$104
3287
+ down: () => down$105,
3288
+ up: () => up$105
3251
3289
  });
3252
3290
  /**
3253
3291
  * Access log: one row per read or orchestrator-admin mutation attributable
@@ -3271,7 +3309,7 @@ var _003_access_log_exports = /* @__PURE__ */ __exportAll({
3271
3309
  * Retention is TTL-based via expires_at; packages/orchestrator/src/queue/
3272
3310
  * cleanup.ts picks up the prune pass.
3273
3311
  */
3274
- async function up$104(db) {
3312
+ async function up$105(db) {
3275
3313
  await sql`
3276
3314
  CREATE TABLE public.access_log (
3277
3315
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
@@ -3309,28 +3347,28 @@ async function up$104(db) {
3309
3347
  ON public.access_log (actor_type, actor_id, created_at DESC)
3310
3348
  `.execute(db);
3311
3349
  }
3312
- async function down$104(db) {
3350
+ async function down$105(db) {
3313
3351
  await sql`DROP TABLE IF EXISTS public.access_log`.execute(db);
3314
3352
  }
3315
3353
  //#endregion
3316
3354
  //#region src/db/migrations/004_rename_bundle_to_source.ts
3317
3355
  var _004_rename_bundle_to_source_exports = /* @__PURE__ */ __exportAll({
3318
- down: () => down$103,
3319
- up: () => up$103
3356
+ down: () => down$104,
3357
+ up: () => up$104
3320
3358
  });
3321
- async function up$103(db) {
3359
+ async function up$104(db) {
3322
3360
  await db.schema.alterTable("dispatch_queue").renameColumn("bundle_url", "source_tar_url").execute();
3323
3361
  await db.schema.alterTable("dispatch_queue").renameColumn("bundle_hash", "source_tar_hash").execute();
3324
3362
  }
3325
- async function down$103(db) {
3363
+ async function down$104(db) {
3326
3364
  await db.schema.alterTable("dispatch_queue").renameColumn("source_tar_url", "bundle_url").execute();
3327
3365
  await db.schema.alterTable("dispatch_queue").renameColumn("source_tar_hash", "bundle_hash").execute();
3328
3366
  }
3329
3367
  //#endregion
3330
3368
  //#region src/db/migrations/005_cold_store_chunk_counter.ts
3331
3369
  var _005_cold_store_chunk_counter_exports = /* @__PURE__ */ __exportAll({
3332
- down: () => down$102,
3333
- up: () => up$102
3370
+ down: () => down$103,
3371
+ up: () => up$103
3334
3372
  });
3335
3373
  /**
3336
3374
  * Cold-store chunk counter table.
@@ -3347,7 +3385,7 @@ var _005_cold_store_chunk_counter_exports = /* @__PURE__ */ __exportAll({
3347
3385
  *
3348
3386
  * sections 5 and 8.
3349
3387
  */
3350
- async function up$102(db) {
3388
+ async function up$103(db) {
3351
3389
  await sql`
3352
3390
  CREATE TABLE public.cold_store_chunk_counts (
3353
3391
  db TEXT NOT NULL,
@@ -3365,14 +3403,14 @@ async function up$102(db) {
3365
3403
  ON public.cold_store_chunk_counts (db, table_name)
3366
3404
  `.execute(db);
3367
3405
  }
3368
- async function down$102(db) {
3406
+ async function down$103(db) {
3369
3407
  await sql`DROP TABLE IF EXISTS public.cold_store_chunk_counts`.execute(db);
3370
3408
  }
3371
3409
  //#endregion
3372
3410
  //#region src/db/migrations/006_runs_jobs_steps_archived_at.ts
3373
3411
  var _006_runs_jobs_steps_archived_at_exports = /* @__PURE__ */ __exportAll({
3374
- down: () => down$101,
3375
- up: () => up$101
3412
+ down: () => down$102,
3413
+ up: () => up$102
3376
3414
  });
3377
3415
  /**
3378
3416
  * `execution_runs` / `execution_jobs` / `execution_steps` cold-store
@@ -3408,7 +3446,7 @@ var _006_runs_jobs_steps_archived_at_exports = /* @__PURE__ */ __exportAll({
3408
3446
  * - `idx_execution_jobs_routing_key_created (routing_key, created_at)`
3409
3447
  * - `idx_execution_steps_routing_key_created (routing_key, created_at)`
3410
3448
  */
3411
- async function up$101(db) {
3449
+ async function up$102(db) {
3412
3450
  await sql`
3413
3451
  ALTER TABLE public.execution_runs
3414
3452
  ADD COLUMN archived_at TIMESTAMPTZ NULL,
@@ -3453,7 +3491,7 @@ async function up$101(db) {
3453
3491
  ON public.execution_steps (routing_key, created_at)
3454
3492
  `.execute(db);
3455
3493
  }
3456
- async function down$101(db) {
3494
+ async function down$102(db) {
3457
3495
  await sql`DROP INDEX IF EXISTS public.idx_execution_steps_routing_key_created`.execute(db);
3458
3496
  await sql`
3459
3497
  ALTER TABLE public.execution_steps
@@ -3478,8 +3516,8 @@ async function down$101(db) {
3478
3516
  //#endregion
3479
3517
  //#region src/db/migrations/007_audit_logs_archived_at.ts
3480
3518
  var _007_audit_logs_archived_at_exports = /* @__PURE__ */ __exportAll({
3481
- down: () => down$100,
3482
- up: () => up$100
3519
+ down: () => down$101,
3520
+ up: () => up$101
3483
3521
  });
3484
3522
  /**
3485
3523
  * `secret_audit_log` and `access_log` cold-store schema additions, plus
@@ -3519,7 +3557,7 @@ var _007_audit_logs_archived_at_exports = /* @__PURE__ */ __exportAll({
3519
3557
  * `down()` would not have meaningful retention bounds. Acceptable for
3520
3558
  * staging.
3521
3559
  */
3522
- async function up$100(db) {
3560
+ async function up$101(db) {
3523
3561
  await sql`
3524
3562
  ALTER TABLE public.secret_audit_log
3525
3563
  ADD COLUMN archived_at TIMESTAMPTZ NULL,
@@ -3540,7 +3578,7 @@ async function up$100(db) {
3540
3578
  DROP COLUMN IF EXISTS expires_at
3541
3579
  `.execute(db);
3542
3580
  }
3543
- async function down$100(db) {
3581
+ async function down$101(db) {
3544
3582
  await sql`
3545
3583
  ALTER TABLE public.access_log
3546
3584
  ADD COLUMN expires_at TIMESTAMPTZ NOT NULL DEFAULT (now() + INTERVAL '90 days')
@@ -3568,8 +3606,8 @@ async function down$100(db) {
3568
3606
  //#endregion
3569
3607
  //#region src/db/migrations/008_event_log_archived_at.ts
3570
3608
  var _008_event_log_archived_at_exports = /* @__PURE__ */ __exportAll({
3571
- down: () => down$99,
3572
- up: () => up$99
3609
+ down: () => down$100,
3610
+ up: () => up$100
3573
3611
  });
3574
3612
  /**
3575
3613
  * `event_log` cold-store schema additions plus removal of the
@@ -3607,7 +3645,7 @@ var _008_event_log_archived_at_exports = /* @__PURE__ */ __exportAll({
3607
3645
  * — best effort; rows inserted between `up()` and a hypothetical
3608
3646
  * `down()` would not have meaningful retention bounds.
3609
3647
  */
3610
- async function up$99(db) {
3648
+ async function up$100(db) {
3611
3649
  await sql`
3612
3650
  ALTER TABLE public.event_log
3613
3651
  ADD COLUMN archived_at TIMESTAMPTZ NULL,
@@ -3623,7 +3661,7 @@ async function up$99(db) {
3623
3661
  DROP COLUMN IF EXISTS expires_at
3624
3662
  `.execute(db);
3625
3663
  }
3626
- async function down$99(db) {
3664
+ async function down$100(db) {
3627
3665
  await sql`
3628
3666
  ALTER TABLE public.event_log
3629
3667
  ADD COLUMN expires_at TIMESTAMPTZ NOT NULL DEFAULT (now() + INTERVAL '30 days')
@@ -3642,8 +3680,8 @@ async function down$99(db) {
3642
3680
  //#endregion
3643
3681
  //#region src/db/migrations/009_access_log_trigram.ts
3644
3682
  var _009_access_log_trigram_exports = /* @__PURE__ */ __exportAll({
3645
- down: () => down$98,
3646
- up: () => up$98
3683
+ down: () => down$99,
3684
+ up: () => up$99
3647
3685
  });
3648
3686
  /**
3649
3687
  * Trigram (pg_trgm) index on access_log.error_message for the federated
@@ -3656,7 +3694,7 @@ var _009_access_log_trigram_exports = /* @__PURE__ */ __exportAll({
3656
3694
  * EXISTS` are both safe to re-run. No CONCURRENTLY because Kysely runs
3657
3695
  * migrations inside a transaction; the lock is brief on a sampled table.
3658
3696
  */
3659
- async function up$98(db) {
3697
+ async function up$99(db) {
3660
3698
  await sql`CREATE EXTENSION IF NOT EXISTS pg_trgm`.execute(db);
3661
3699
  await sql`
3662
3700
  CREATE INDEX IF NOT EXISTS access_log_error_message_trgm_idx
@@ -3665,14 +3703,14 @@ async function up$98(db) {
3665
3703
  WHERE error_message IS NOT NULL
3666
3704
  `.execute(db);
3667
3705
  }
3668
- async function down$98(db) {
3706
+ async function down$99(db) {
3669
3707
  await sql`DROP INDEX IF EXISTS public.access_log_error_message_trgm_idx`.execute(db);
3670
3708
  }
3671
3709
  //#endregion
3672
3710
  //#region src/db/migrations/010_cold_store_chunks.ts
3673
3711
  var _010_cold_store_chunks_exports = /* @__PURE__ */ __exportAll({
3674
- down: () => down$97,
3675
- up: () => up$97
3712
+ down: () => down$98,
3713
+ up: () => up$98
3676
3714
  });
3677
3715
  /**
3678
3716
  * Cold-store chunk index — Phase 2 (cold-store purge).
@@ -3704,7 +3742,7 @@ var _010_cold_store_chunks_exports = /* @__PURE__ */ __exportAll({
3704
3742
  * forever. Adapters that don't opt into per-bucket archival via
3705
3743
  * `coldTtlDays` don't insert here either.
3706
3744
  */
3707
- async function up$97(db) {
3745
+ async function up$98(db) {
3708
3746
  await sql`
3709
3747
  CREATE TABLE public.cold_store_chunks (
3710
3748
  db TEXT NOT NULL,
@@ -3731,14 +3769,14 @@ async function up$97(db) {
3731
3769
  ON public.cold_store_chunks (db, table_name, tenant_id, archived_at DESC)
3732
3770
  `.execute(db);
3733
3771
  }
3734
- async function down$97(db) {
3772
+ async function down$98(db) {
3735
3773
  await sql`DROP TABLE IF EXISTS public.cold_store_chunks`.execute(db);
3736
3774
  }
3737
3775
  //#endregion
3738
3776
  //#region src/db/migrations/011_drop_source_secrets_notify.ts
3739
3777
  var _011_drop_source_secrets_notify_exports = /* @__PURE__ */ __exportAll({
3740
- down: () => down$96,
3741
- up: () => up$96
3778
+ down: () => down$97,
3779
+ up: () => up$97
3742
3780
  });
3743
3781
  /**
3744
3782
  * Drop the `source_secrets_change_trigger` and the
@@ -3757,11 +3795,11 @@ var _011_drop_source_secrets_notify_exports = /* @__PURE__ */ __exportAll({
3757
3795
  * in `001_initial.ts`. They wake up no consumer until the `WebhookSecretManager`
3758
3796
  * is restored, so this migration is safe to roll back.
3759
3797
  */
3760
- async function up$96(db) {
3798
+ async function up$97(db) {
3761
3799
  await sql`DROP TRIGGER IF EXISTS source_secrets_change_trigger ON public.scoped_secrets`.execute(db);
3762
3800
  await sql`DROP FUNCTION IF EXISTS public.notify_source_secrets_change() CASCADE`.execute(db);
3763
3801
  }
3764
- async function down$96(db) {
3802
+ async function down$97(db) {
3765
3803
  await sql`
3766
3804
  CREATE OR REPLACE FUNCTION public.notify_source_secrets_change() RETURNS trigger
3767
3805
  LANGUAGE plpgsql
@@ -3800,8 +3838,8 @@ async function down$96(db) {
3800
3838
  //#endregion
3801
3839
  //#region src/db/migrations/012_peer_credentials_active_uniq.ts
3802
3840
  var _012_peer_credentials_active_uniq_exports = /* @__PURE__ */ __exportAll({
3803
- down: () => down$95,
3804
- up: () => up$95
3841
+ down: () => down$96,
3842
+ up: () => up$96
3805
3843
  });
3806
3844
  /**
3807
3845
  * Add a partial unique index on `peer_credentials (instance_id) WHERE
@@ -3827,7 +3865,7 @@ var _012_peer_credentials_active_uniq_exports = /* @__PURE__ */ __exportAll({
3827
3865
  * `down()` only drops the index; it does NOT undo the dedupe (there's no
3828
3866
  * safe way to recreate revoked rows, and the dedupe is monotonic).
3829
3867
  */
3830
- async function up$95(db) {
3868
+ async function up$96(db) {
3831
3869
  await sql`
3832
3870
  UPDATE public.peer_credentials
3833
3871
  SET revoked_at = NOW()
@@ -3845,14 +3883,14 @@ async function up$95(db) {
3845
3883
  WHERE revoked_at IS NULL
3846
3884
  `.execute(db);
3847
3885
  }
3848
- async function down$95(db) {
3886
+ async function down$96(db) {
3849
3887
  await sql`DROP INDEX IF EXISTS public.peer_credentials_active_uniq`.execute(db);
3850
3888
  }
3851
3889
  //#endregion
3852
3890
  //#region src/db/migrations/013_execution_log_bytes.ts
3853
3891
  var _013_execution_log_bytes_exports = /* @__PURE__ */ __exportAll({
3854
- down: () => down$94,
3855
- up: () => up$94
3892
+ down: () => down$95,
3893
+ up: () => up$95
3856
3894
  });
3857
3895
  /**
3858
3896
  * Add `log_bytes BIGINT NOT NULL DEFAULT 0` columns to `execution_runs` and
@@ -3871,7 +3909,7 @@ var _013_execution_log_bytes_exports = /* @__PURE__ */ __exportAll({
3871
3909
  *
3872
3910
  * Idempotent (`ADD COLUMN IF NOT EXISTS`).
3873
3911
  */
3874
- async function up$94(db) {
3912
+ async function up$95(db) {
3875
3913
  await sql`
3876
3914
  ALTER TABLE public.execution_runs
3877
3915
  ADD COLUMN IF NOT EXISTS log_bytes BIGINT NOT NULL DEFAULT 0
@@ -3881,15 +3919,15 @@ async function up$94(db) {
3881
3919
  ADD COLUMN IF NOT EXISTS log_bytes BIGINT NOT NULL DEFAULT 0
3882
3920
  `.execute(db);
3883
3921
  }
3884
- async function down$94(db) {
3922
+ async function down$95(db) {
3885
3923
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS log_bytes`.execute(db);
3886
3924
  await sql`ALTER TABLE public.execution_jobs DROP COLUMN IF EXISTS log_bytes`.execute(db);
3887
3925
  }
3888
3926
  //#endregion
3889
3927
  //#region src/db/migrations/014_kici_events_lease_retry.ts
3890
3928
  var _014_kici_events_lease_retry_exports = /* @__PURE__ */ __exportAll({
3891
- down: () => down$93,
3892
- up: () => up$93
3929
+ down: () => down$94,
3930
+ up: () => up$94
3893
3931
  });
3894
3932
  /**
3895
3933
  * Add lease + retry + DLQ columns to `kici_events` so the EventRouter can
@@ -3923,7 +3961,7 @@ var _014_kici_events_lease_retry_exports = /* @__PURE__ */ __exportAll({
3923
3961
  *
3924
3962
  * Idempotent (`ADD COLUMN IF NOT EXISTS` + `CREATE INDEX IF NOT EXISTS`).
3925
3963
  */
3926
- async function up$93(db) {
3964
+ async function up$94(db) {
3927
3965
  await sql`
3928
3966
  ALTER TABLE public.kici_events
3929
3967
  ADD COLUMN IF NOT EXISTS claimed_at TIMESTAMPTZ,
@@ -3954,7 +3992,7 @@ async function up$93(db) {
3954
3992
  WHERE dlq_at IS NOT NULL
3955
3993
  `.execute(db);
3956
3994
  }
3957
- async function down$93(db) {
3995
+ async function down$94(db) {
3958
3996
  await sql`DROP INDEX IF EXISTS public.idx_kici_events_dlq`.execute(db);
3959
3997
  await sql`DROP INDEX IF EXISTS public.idx_kici_events_lease_expired`.execute(db);
3960
3998
  await sql`DROP INDEX IF EXISTS public.idx_kici_events_retry_due`.execute(db);
@@ -3972,8 +4010,8 @@ async function down$93(db) {
3972
4010
  //#endregion
3973
4011
  //#region src/db/migrations/015_org_settings_customer_scoped.ts
3974
4012
  var _015_org_settings_customer_scoped_exports = /* @__PURE__ */ __exportAll({
3975
- down: () => down$92,
3976
- up: () => up$92
4013
+ down: () => down$93,
4014
+ up: () => up$93
3977
4015
  });
3978
4016
  /**
3979
4017
  * Org-scope `org_settings` and qualify each glob entry by source.
@@ -4001,7 +4039,7 @@ var _015_org_settings_customer_scoped_exports = /* @__PURE__ */ __exportAll({
4001
4039
  * Idempotent: a re-run on an already-migrated DB sees `customer_id` exists
4002
4040
  * and the list columns are already jsonb, so it is a no-op.
4003
4041
  */
4004
- async function up$92(db) {
4042
+ async function up$93(db) {
4005
4043
  if ((await sql`
4006
4044
  SELECT EXISTS (
4007
4045
  SELECT 1 FROM information_schema.columns
@@ -4126,7 +4164,7 @@ async function up$92(db) {
4126
4164
  await sql`DROP TABLE _org_settings_merged`.execute(db);
4127
4165
  await sql`DROP TABLE _org_settings_stage`.execute(db);
4128
4166
  }
4129
- async function down$92(db) {
4167
+ async function down$93(db) {
4130
4168
  if (!(await sql`
4131
4169
  SELECT EXISTS (
4132
4170
  SELECT 1 FROM information_schema.columns
@@ -4151,8 +4189,8 @@ async function down$92(db) {
4151
4189
  //#endregion
4152
4190
  //#region src/db/migrations/016_org_settings_allow_http_npm.ts
4153
4191
  var _016_org_settings_allow_http_npm_exports = /* @__PURE__ */ __exportAll({
4154
- down: () => down$91,
4155
- up: () => up$91
4192
+ down: () => down$92,
4193
+ up: () => up$92
4156
4194
  });
4157
4195
  /**
4158
4196
  * Add `org_settings.allow_http_npm_registries boolean NOT NULL DEFAULT false`.
@@ -4165,7 +4203,7 @@ var _016_org_settings_allow_http_npm_exports = /* @__PURE__ */ __exportAll({
4165
4203
  *
4166
4204
  * Idempotent: a re-run on a DB that already has the column is a no-op.
4167
4205
  */
4168
- async function up$91(db) {
4206
+ async function up$92(db) {
4169
4207
  if ((await sql`
4170
4208
  SELECT EXISTS (
4171
4209
  SELECT 1 FROM information_schema.columns
@@ -4179,7 +4217,7 @@ async function up$91(db) {
4179
4217
  ADD COLUMN allow_http_npm_registries boolean NOT NULL DEFAULT false
4180
4218
  `.execute(db);
4181
4219
  }
4182
- async function down$91(db) {
4220
+ async function down$92(db) {
4183
4221
  await sql`
4184
4222
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS allow_http_npm_registries
4185
4223
  `.execute(db);
@@ -4187,8 +4225,8 @@ async function down$91(db) {
4187
4225
  //#endregion
4188
4226
  //#region src/db/migrations/017_org_id_widen.ts
4189
4227
  var _017_org_id_widen_exports = /* @__PURE__ */ __exportAll({
4190
- down: () => down$90,
4191
- up: () => up$90
4228
+ down: () => down$91,
4229
+ up: () => up$91
4192
4230
  });
4193
4231
  /**
4194
4232
  * Widen every orchestrator-side `org_id varchar(12)` column to
@@ -4228,17 +4266,17 @@ const ORG_ID_TABLES$1 = [
4228
4266
  "held_runs",
4229
4267
  "scoped_secrets"
4230
4268
  ];
4231
- async function up$90(db) {
4269
+ async function up$91(db) {
4232
4270
  for (const table of ORG_ID_TABLES$1) await sql.raw(`ALTER TABLE public.${table} ALTER COLUMN org_id TYPE varchar(16)`).execute(db);
4233
4271
  }
4234
- async function down$90(db) {
4272
+ async function down$91(db) {
4235
4273
  for (const table of ORG_ID_TABLES$1) await sql.raw(`ALTER TABLE public.${table} ALTER COLUMN org_id TYPE varchar(12)`).execute(db);
4236
4274
  }
4237
4275
  //#endregion
4238
4276
  //#region src/db/migrations/018_org_id_prefix_backfill.ts
4239
4277
  var _018_org_id_prefix_backfill_exports = /* @__PURE__ */ __exportAll({
4240
- down: () => down$89,
4241
- up: () => up$89
4278
+ down: () => down$90,
4279
+ up: () => up$90
4242
4280
  });
4243
4281
  /**
4244
4282
  * Prefix every orchestrator-side tenant string with `org_` to align
@@ -4283,19 +4321,19 @@ const CUSTOMER_ID_TABLES = [
4283
4321
  "workflow_registrations",
4284
4322
  "org_settings"
4285
4323
  ];
4286
- async function up$89(db) {
4324
+ async function up$90(db) {
4287
4325
  for (const table of ORG_ID_TABLES) await sql.raw(`UPDATE public.${table} SET org_id = 'org_' || org_id WHERE org_id <> 'kici-admin' AND org_id NOT LIKE 'org\\_%' ESCAPE '\\'`).execute(db);
4288
4326
  for (const table of CUSTOMER_ID_TABLES) await sql.raw(`UPDATE public.${table} SET customer_id = 'org_' || customer_id WHERE customer_id <> 'kici-admin' AND customer_id NOT LIKE 'org\\_%' ESCAPE '\\'`).execute(db);
4289
4327
  }
4290
- async function down$89(db) {
4328
+ async function down$90(db) {
4291
4329
  for (const table of CUSTOMER_ID_TABLES) await sql.raw(`UPDATE public.${table} SET customer_id = substring(customer_id from 5) WHERE customer_id LIKE 'org\\_%' ESCAPE '\\'`).execute(db);
4292
4330
  for (const table of ORG_ID_TABLES) await sql.raw(`UPDATE public.${table} SET org_id = substring(org_id from 5) WHERE org_id LIKE 'org\\_%' ESCAPE '\\'`).execute(db);
4293
4331
  }
4294
4332
  //#endregion
4295
4333
  //#region src/db/migrations/019_generic_sources_change_notify.ts
4296
4334
  var _019_generic_sources_change_notify_exports = /* @__PURE__ */ __exportAll({
4297
- down: () => down$88,
4298
- up: () => up$88
4335
+ down: () => down$89,
4336
+ up: () => up$89
4299
4337
  });
4300
4338
  /**
4301
4339
  * Add a Postgres trigger on `generic_webhook_sources` that emits
@@ -4318,7 +4356,7 @@ var _019_generic_sources_change_notify_exports = /* @__PURE__ */ __exportAll({
4318
4356
  * (`notify_sources_change()` + `sources_change_trigger`, defined in
4319
4357
  * `001_initial.ts`).
4320
4358
  */
4321
- async function up$88(db) {
4359
+ async function up$89(db) {
4322
4360
  await sql`
4323
4361
  CREATE FUNCTION public.notify_generic_sources_change() RETURNS trigger
4324
4362
  LANGUAGE plpgsql
@@ -4339,15 +4377,15 @@ async function up$88(db) {
4339
4377
  FOR EACH ROW EXECUTE FUNCTION public.notify_generic_sources_change()
4340
4378
  `.execute(db);
4341
4379
  }
4342
- async function down$88(db) {
4380
+ async function down$89(db) {
4343
4381
  await sql`DROP TRIGGER IF EXISTS generic_sources_change_trigger ON public.generic_webhook_sources`.execute(db);
4344
4382
  await sql`DROP FUNCTION IF EXISTS public.notify_generic_sources_change()`.execute(db);
4345
4383
  }
4346
4384
  //#endregion
4347
4385
  //#region src/db/migrations/020_org_settings_dashboard_write_policy.ts
4348
4386
  var _020_org_settings_dashboard_write_policy_exports = /* @__PURE__ */ __exportAll({
4349
- down: () => down$87,
4350
- up: () => up$87
4387
+ down: () => down$88,
4388
+ up: () => up$88
4351
4389
  });
4352
4390
  /**
4353
4391
  * Add `org_settings.dashboard_write_policy jsonb NOT NULL DEFAULT '{}'`.
@@ -4362,7 +4400,7 @@ var _020_org_settings_dashboard_write_policy_exports = /* @__PURE__ */ __exportA
4362
4400
  *
4363
4401
  * Idempotent: a re-run on a DB that already has the column is a no-op.
4364
4402
  */
4365
- async function up$87(db) {
4403
+ async function up$88(db) {
4366
4404
  if ((await sql`
4367
4405
  SELECT EXISTS (
4368
4406
  SELECT 1 FROM information_schema.columns
@@ -4376,7 +4414,7 @@ async function up$87(db) {
4376
4414
  ADD COLUMN dashboard_write_policy jsonb NOT NULL DEFAULT '{}'::jsonb
4377
4415
  `.execute(db);
4378
4416
  }
4379
- async function down$87(db) {
4417
+ async function down$88(db) {
4380
4418
  await sql`
4381
4419
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS dashboard_write_policy
4382
4420
  `.execute(db);
@@ -4384,8 +4422,8 @@ async function down$87(db) {
4384
4422
  //#endregion
4385
4423
  //#region src/db/migrations/021_check_run_tracking.ts
4386
4424
  var _021_check_run_tracking_exports = /* @__PURE__ */ __exportAll({
4387
- down: () => down$86,
4388
- up: () => up$86
4425
+ down: () => down$87,
4426
+ up: () => up$87
4389
4427
  });
4390
4428
  /**
4391
4429
  * Add `check_run_tracking` table for HA-safe check-run state persistence.
@@ -4409,7 +4447,7 @@ var _021_check_run_tracking_exports = /* @__PURE__ */ __exportAll({
4409
4447
  *
4410
4448
  * Idempotent: a re-run on a DB that already has the table is a no-op.
4411
4449
  */
4412
- async function up$86(db) {
4450
+ async function up$87(db) {
4413
4451
  if ((await sql`
4414
4452
  SELECT EXISTS (
4415
4453
  SELECT 1 FROM information_schema.tables
@@ -4440,14 +4478,14 @@ async function up$86(db) {
4440
4478
  WHERE run_id IS NOT NULL
4441
4479
  `.execute(db);
4442
4480
  }
4443
- async function down$86(db) {
4481
+ async function down$87(db) {
4444
4482
  await sql`DROP TABLE IF EXISTS public.check_run_tracking`.execute(db);
4445
4483
  }
4446
4484
  //#endregion
4447
4485
  //#region src/db/migrations/022_scaler_manager_state.ts
4448
4486
  var _022_scaler_manager_state_exports = /* @__PURE__ */ __exportAll({
4449
- down: () => down$85,
4450
- up: () => up$85
4487
+ down: () => down$86,
4488
+ up: () => up$86
4451
4489
  });
4452
4490
  /**
4453
4491
  * Add three tables persisting `ScalerManager` per-coord state:
@@ -4474,7 +4512,7 @@ var _022_scaler_manager_state_exports = /* @__PURE__ */ __exportAll({
4474
4512
  * Idempotent: a re-run on a DB that already has any of these tables
4475
4513
  * leaves the existing one alone.
4476
4514
  */
4477
- async function up$85(db) {
4515
+ async function up$86(db) {
4478
4516
  const tableExists = async (name) => {
4479
4517
  return (await sql`
4480
4518
  SELECT EXISTS (
@@ -4524,7 +4562,7 @@ async function up$85(db) {
4524
4562
  `.execute(db);
4525
4563
  }
4526
4564
  }
4527
- async function down$85(db) {
4565
+ async function down$86(db) {
4528
4566
  await sql`DROP TABLE IF EXISTS public.scaler_reservations`.execute(db);
4529
4567
  await sql`DROP TABLE IF EXISTS public.scaler_agent_jobs`.execute(db);
4530
4568
  await sql`DROP TABLE IF EXISTS public.scaler_spawning_agents`.execute(db);
@@ -4532,8 +4570,8 @@ async function down$85(db) {
4532
4570
  //#endregion
4533
4571
  //#region src/db/migrations/023_dispatch_queue_recovery_deadline.ts
4534
4572
  var _023_dispatch_queue_recovery_deadline_exports = /* @__PURE__ */ __exportAll({
4535
- down: () => down$84,
4536
- up: () => up$84
4573
+ down: () => down$85,
4574
+ up: () => up$85
4537
4575
  });
4538
4576
  /**
4539
4577
  * Add `dispatch_queue.recovery_deadline TIMESTAMPTZ` and
@@ -4557,7 +4595,7 @@ var _023_dispatch_queue_recovery_deadline_exports = /* @__PURE__ */ __exportAll(
4557
4595
  * Idempotent: re-running on a DB that already has either column is a
4558
4596
  * no-op.
4559
4597
  */
4560
- async function up$84(db) {
4598
+ async function up$85(db) {
4561
4599
  const colExists = async (name) => {
4562
4600
  return (await sql`
4563
4601
  SELECT EXISTS (
@@ -4582,7 +4620,7 @@ async function up$84(db) {
4582
4620
  WHERE recovery_deadline IS NOT NULL
4583
4621
  `.execute(db);
4584
4622
  }
4585
- async function down$84(db) {
4623
+ async function down$85(db) {
4586
4624
  await sql`DROP INDEX IF EXISTS public.idx_dispatch_queue_recovery_deadline`.execute(db);
4587
4625
  await sql`
4588
4626
  ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS recovery_agent_id
@@ -4594,8 +4632,8 @@ async function down$84(db) {
4594
4632
  //#endregion
4595
4633
  //#region src/db/migrations/024_dispatch_queue_provisioning_error.ts
4596
4634
  var _024_dispatch_queue_provisioning_error_exports = /* @__PURE__ */ __exportAll({
4597
- down: () => down$83,
4598
- up: () => up$83
4635
+ down: () => down$84,
4636
+ up: () => up$84
4599
4637
  });
4600
4638
  /**
4601
4639
  * Add `dispatch_queue.last_provisioning_error TEXT` recording the most
@@ -4611,7 +4649,7 @@ var _024_dispatch_queue_provisioning_error_exports = /* @__PURE__ */ __exportAll
4611
4649
  *
4612
4650
  * Idempotent: re-running on a DB that already has the column is a no-op.
4613
4651
  */
4614
- async function up$83(db) {
4652
+ async function up$84(db) {
4615
4653
  const colExists = async (name) => {
4616
4654
  return (await sql`
4617
4655
  SELECT EXISTS (
@@ -4627,7 +4665,7 @@ async function up$83(db) {
4627
4665
  ADD COLUMN last_provisioning_error TEXT
4628
4666
  `.execute(db);
4629
4667
  }
4630
- async function down$83(db) {
4668
+ async function down$84(db) {
4631
4669
  await sql`
4632
4670
  ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS last_provisioning_error
4633
4671
  `.execute(db);
@@ -4635,8 +4673,8 @@ async function down$83(db) {
4635
4673
  //#endregion
4636
4674
  //#region src/db/migrations/025_init_failure.ts
4637
4675
  var _025_init_failure_exports = /* @__PURE__ */ __exportAll({
4638
- down: () => down$82,
4639
- up: () => up$82
4676
+ down: () => down$83,
4677
+ up: () => up$83
4640
4678
  });
4641
4679
  /**
4642
4680
  * Add `init_failure jsonb` columns to `execution_runs` and `execution_jobs`.
@@ -4650,7 +4688,7 @@ var _025_init_failure_exports = /* @__PURE__ */ __exportAll({
4650
4688
  * Idempotent: re-running on a DB that already has either column is a no-op
4651
4689
  * for that column.
4652
4690
  */
4653
- async function up$82(db) {
4691
+ async function up$83(db) {
4654
4692
  const colExists = async (table, name) => {
4655
4693
  return (await sql`
4656
4694
  SELECT EXISTS (
@@ -4670,7 +4708,7 @@ async function up$82(db) {
4670
4708
  ADD COLUMN init_failure JSONB DEFAULT NULL
4671
4709
  `.execute(db);
4672
4710
  }
4673
- async function down$82(db) {
4711
+ async function down$83(db) {
4674
4712
  await sql`
4675
4713
  ALTER TABLE public.execution_jobs DROP COLUMN IF EXISTS init_failure
4676
4714
  `.execute(db);
@@ -4681,8 +4719,8 @@ async function down$82(db) {
4681
4719
  //#endregion
4682
4720
  //#region src/db/migrations/026_event_log_lockfile_corrupt.ts
4683
4721
  var _026_event_log_lockfile_corrupt_exports = /* @__PURE__ */ __exportAll({
4684
- down: () => down$81,
4685
- up: () => up$81
4722
+ down: () => down$82,
4723
+ up: () => up$82
4686
4724
  });
4687
4725
  /**
4688
4726
  * Extend the event_log.status CHECK constraint with 'lockfile_corrupt' so the
@@ -4691,7 +4729,7 @@ var _026_event_log_lockfile_corrupt_exports = /* @__PURE__ */ __exportAll({
4691
4729
  *
4692
4730
  * Idempotent: the DROP ... IF EXISTS / re-ADD pair re-runs cleanly.
4693
4731
  */
4694
- async function up$81(db) {
4732
+ async function up$82(db) {
4695
4733
  await sql`ALTER TABLE event_log DROP CONSTRAINT IF EXISTS event_log_status_check`.execute(db);
4696
4734
  await sql`
4697
4735
  ALTER TABLE event_log ADD CONSTRAINT event_log_status_check
@@ -4701,7 +4739,7 @@ async function up$81(db) {
4701
4739
  ])))
4702
4740
  `.execute(db);
4703
4741
  }
4704
- async function down$81(db) {
4742
+ async function down$82(db) {
4705
4743
  await sql`ALTER TABLE event_log DROP CONSTRAINT IF EXISTS event_log_status_check`.execute(db);
4706
4744
  await sql`
4707
4745
  ALTER TABLE event_log ADD CONSTRAINT event_log_status_check
@@ -4714,8 +4752,8 @@ async function down$81(db) {
4714
4752
  //#endregion
4715
4753
  //#region src/db/migrations/027_workflow_timeout.ts
4716
4754
  var _027_workflow_timeout_exports = /* @__PURE__ */ __exportAll({
4717
- down: () => down$80,
4718
- up: () => up$80
4755
+ down: () => down$81,
4756
+ up: () => up$81
4719
4757
  });
4720
4758
  /**
4721
4759
  * Add `workflow_timeout_ms integer` to `execution_runs`.
@@ -4733,13 +4771,13 @@ var _027_workflow_timeout_exports = /* @__PURE__ */ __exportAll({
4733
4771
  *
4734
4772
  * Idempotent: re-running on a DB that already has the column is a no-op.
4735
4773
  */
4736
- async function up$80(db) {
4774
+ async function up$81(db) {
4737
4775
  await sql`
4738
4776
  ALTER TABLE public.execution_runs
4739
4777
  ADD COLUMN IF NOT EXISTS workflow_timeout_ms INTEGER DEFAULT NULL
4740
4778
  `.execute(db);
4741
4779
  }
4742
- async function down$80(db) {
4780
+ async function down$81(db) {
4743
4781
  await sql`
4744
4782
  ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS workflow_timeout_ms
4745
4783
  `.execute(db);
@@ -4747,8 +4785,8 @@ async function down$80(db) {
4747
4785
  //#endregion
4748
4786
  //#region src/db/migrations/028_org_settings_user_cache.ts
4749
4787
  var _028_org_settings_user_cache_exports = /* @__PURE__ */ __exportAll({
4750
- down: () => down$79,
4751
- up: () => up$79
4788
+ down: () => down$80,
4789
+ up: () => up$80
4752
4790
  });
4753
4791
  /**
4754
4792
  * Add `org_settings.user_cache_quota_bytes bigint` and
@@ -4767,7 +4805,7 @@ var _028_org_settings_user_cache_exports = /* @__PURE__ */ __exportAll({
4767
4805
  *
4768
4806
  * Idempotent: a re-run on a DB that already has either column skips it.
4769
4807
  */
4770
- async function columnExists$5(db, column) {
4808
+ async function columnExists$6(db, column) {
4771
4809
  return (await sql`
4772
4810
  SELECT EXISTS (
4773
4811
  SELECT 1 FROM information_schema.columns
@@ -4777,17 +4815,17 @@ async function columnExists$5(db, column) {
4777
4815
  ) AS exists
4778
4816
  `.execute(db)).rows[0]?.exists ?? false;
4779
4817
  }
4780
- async function up$79(db) {
4781
- if (!await columnExists$5(db, "user_cache_quota_bytes")) await sql`
4818
+ async function up$80(db) {
4819
+ if (!await columnExists$6(db, "user_cache_quota_bytes")) await sql`
4782
4820
  ALTER TABLE public.org_settings
4783
4821
  ADD COLUMN user_cache_quota_bytes bigint
4784
4822
  `.execute(db);
4785
- if (!await columnExists$5(db, "user_cache_ttl_ms")) await sql`
4823
+ if (!await columnExists$6(db, "user_cache_ttl_ms")) await sql`
4786
4824
  ALTER TABLE public.org_settings
4787
4825
  ADD COLUMN user_cache_ttl_ms bigint
4788
4826
  `.execute(db);
4789
4827
  }
4790
- async function down$79(db) {
4828
+ async function down$80(db) {
4791
4829
  await sql`
4792
4830
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS user_cache_quota_bytes
4793
4831
  `.execute(db);
@@ -4798,8 +4836,8 @@ async function down$79(db) {
4798
4836
  //#endregion
4799
4837
  //#region src/db/migrations/029_dispatch_queue_attempts.ts
4800
4838
  var _029_dispatch_queue_attempts_exports = /* @__PURE__ */ __exportAll({
4801
- down: () => down$78,
4802
- up: () => up$78
4839
+ down: () => down$79,
4840
+ up: () => up$79
4803
4841
  });
4804
4842
  /**
4805
4843
  * Add `dispatch_queue.dispatch_attempts INT NOT NULL DEFAULT 0`.
@@ -4813,7 +4851,7 @@ var _029_dispatch_queue_attempts_exports = /* @__PURE__ */ __exportAll({
4813
4851
  *
4814
4852
  * Idempotent: re-running on a DB that already has the column is a no-op.
4815
4853
  */
4816
- async function up$78(db) {
4854
+ async function up$79(db) {
4817
4855
  if (!((await sql`
4818
4856
  SELECT EXISTS (
4819
4857
  SELECT 1 FROM information_schema.columns
@@ -4826,7 +4864,7 @@ async function up$78(db) {
4826
4864
  ADD COLUMN dispatch_attempts INT NOT NULL DEFAULT 0
4827
4865
  `.execute(db);
4828
4866
  }
4829
- async function down$78(db) {
4867
+ async function down$79(db) {
4830
4868
  await sql`
4831
4869
  ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS dispatch_attempts
4832
4870
  `.execute(db);
@@ -4834,8 +4872,8 @@ async function down$78(db) {
4834
4872
  //#endregion
4835
4873
  //#region src/db/migrations/030_held_runs_env_set_null.ts
4836
4874
  var _030_held_runs_env_set_null_exports = /* @__PURE__ */ __exportAll({
4837
- down: () => down$77,
4838
- up: () => up$77
4875
+ down: () => down$78,
4876
+ up: () => up$78
4839
4877
  });
4840
4878
  /**
4841
4879
  * held_runs.environment_id becomes nullable with ON DELETE SET NULL so
@@ -4846,14 +4884,14 @@ var _030_held_runs_env_set_null_exports = /* @__PURE__ */ __exportAll({
4846
4884
  * Idempotent: dropping the NOT NULL and the constraint are both no-ops on a
4847
4885
  * re-run, and the constraint is re-created with the SET NULL action.
4848
4886
  */
4849
- async function up$77(db) {
4887
+ async function up$78(db) {
4850
4888
  await sql`ALTER TABLE public.held_runs ALTER COLUMN environment_id DROP NOT NULL`.execute(db);
4851
4889
  await sql`ALTER TABLE public.held_runs DROP CONSTRAINT IF EXISTS held_runs_environment_id_fkey`.execute(db);
4852
4890
  await sql`ALTER TABLE public.held_runs
4853
4891
  ADD CONSTRAINT held_runs_environment_id_fkey
4854
4892
  FOREIGN KEY (environment_id) REFERENCES public.environments(id) ON DELETE SET NULL`.execute(db);
4855
4893
  }
4856
- async function down$77(db) {
4894
+ async function down$78(db) {
4857
4895
  await sql`ALTER TABLE public.held_runs DROP CONSTRAINT IF EXISTS held_runs_environment_id_fkey`.execute(db);
4858
4896
  await sql`ALTER TABLE public.held_runs
4859
4897
  ADD CONSTRAINT held_runs_environment_id_fkey
@@ -4863,8 +4901,8 @@ async function down$77(db) {
4863
4901
  //#endregion
4864
4902
  //#region src/db/migrations/031_dispatch_queue_ack_deadline.ts
4865
4903
  var _031_dispatch_queue_ack_deadline_exports = /* @__PURE__ */ __exportAll({
4866
- down: () => down$76,
4867
- up: () => up$76
4904
+ down: () => down$77,
4905
+ up: () => up$77
4868
4906
  });
4869
4907
  /**
4870
4908
  * Add `dispatch_queue.ack_deadline TIMESTAMPTZ` and
@@ -4881,7 +4919,7 @@ var _031_dispatch_queue_ack_deadline_exports = /* @__PURE__ */ __exportAll({
4881
4919
  *
4882
4920
  * Idempotent: re-running on a DB that already has either column is a no-op.
4883
4921
  */
4884
- async function up$76(db) {
4922
+ async function up$77(db) {
4885
4923
  const colExists = async (name) => {
4886
4924
  return (await sql`
4887
4925
  SELECT EXISTS (
@@ -4906,7 +4944,7 @@ async function up$76(db) {
4906
4944
  WHERE ack_deadline IS NOT NULL
4907
4945
  `.execute(db);
4908
4946
  }
4909
- async function down$76(db) {
4947
+ async function down$77(db) {
4910
4948
  await sql`DROP INDEX IF EXISTS public.idx_dispatch_queue_ack_deadline`.execute(db);
4911
4949
  await sql`ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS ack_agent_id`.execute(db);
4912
4950
  await sql`ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS ack_deadline`.execute(db);
@@ -4914,8 +4952,8 @@ async function down$76(db) {
4914
4952
  //#endregion
4915
4953
  //#region src/db/migrations/032_org_settings_dispatch_ack_timeout.ts
4916
4954
  var _032_org_settings_dispatch_ack_timeout_exports = /* @__PURE__ */ __exportAll({
4917
- down: () => down$75,
4918
- up: () => up$75
4955
+ down: () => down$76,
4956
+ up: () => up$76
4919
4957
  });
4920
4958
  /**
4921
4959
  * Add `org_settings.dispatch_ack_timeout_ms BIGINT` (nullable).
@@ -4927,7 +4965,7 @@ var _032_org_settings_dispatch_ack_timeout_exports = /* @__PURE__ */ __exportAll
4927
4965
  *
4928
4966
  * Idempotent: a re-run on a DB that already has the column is a no-op.
4929
4967
  */
4930
- async function up$75(db) {
4968
+ async function up$76(db) {
4931
4969
  if ((await sql`
4932
4970
  SELECT EXISTS (
4933
4971
  SELECT 1 FROM information_schema.columns
@@ -4941,7 +4979,7 @@ async function up$75(db) {
4941
4979
  ADD COLUMN dispatch_ack_timeout_ms BIGINT
4942
4980
  `.execute(db);
4943
4981
  }
4944
- async function down$75(db) {
4982
+ async function down$76(db) {
4945
4983
  await sql`
4946
4984
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS dispatch_ack_timeout_ms
4947
4985
  `.execute(db);
@@ -4949,8 +4987,8 @@ async function down$75(db) {
4949
4987
  //#endregion
4950
4988
  //#region src/db/migrations/033_org_settings_approval.ts
4951
4989
  var _033_org_settings_approval_exports = /* @__PURE__ */ __exportAll({
4952
- down: () => down$74,
4953
- up: () => up$74
4990
+ down: () => down$75,
4991
+ up: () => up$75
4954
4992
  });
4955
4993
  /**
4956
4994
  * Add the two approval-policy columns to `org_settings`:
@@ -4967,7 +5005,7 @@ var _033_org_settings_approval_exports = /* @__PURE__ */ __exportAll({
4967
5005
  * and the orchestrator admin route. Idempotent: a re-run on a DB that already
4968
5006
  * has the columns is a no-op (each column is guarded independently).
4969
5007
  */
4970
- async function up$74(db) {
5008
+ async function up$75(db) {
4971
5009
  const colExists = async (column) => {
4972
5010
  return (await sql`
4973
5011
  SELECT EXISTS (
@@ -4987,7 +5025,7 @@ async function up$74(db) {
4987
5025
  ADD COLUMN allow_self_approval BOOLEAN NOT NULL DEFAULT true
4988
5026
  `.execute(db);
4989
5027
  }
4990
- async function down$74(db) {
5028
+ async function down$75(db) {
4991
5029
  await sql`
4992
5030
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS approval_expiry_seconds
4993
5031
  `.execute(db);
@@ -4998,8 +5036,8 @@ async function down$74(db) {
4998
5036
  //#endregion
4999
5037
  //#region src/db/migrations/034_held_runs_generalize.ts
5000
5038
  var _034_held_runs_generalize_exports = /* @__PURE__ */ __exportAll({
5001
- down: () => down$73,
5002
- up: () => up$73
5039
+ down: () => down$74,
5040
+ up: () => up$74
5003
5041
  });
5004
5042
  /**
5005
5043
  * Generalize `held_runs` from an environment-only hold into the unified
@@ -5021,7 +5059,7 @@ var _034_held_runs_generalize_exports = /* @__PURE__ */ __exportAll({
5021
5059
  * New `held_run_approvals` table: one row per approver decision, FK to
5022
5060
  * `held_runs.id` (uuid) with ON DELETE CASCADE.
5023
5061
  */
5024
- async function up$73(db) {
5062
+ async function up$74(db) {
5025
5063
  const colExists = async (column) => {
5026
5064
  return (await sql`
5027
5065
  SELECT EXISTS (
@@ -5054,7 +5092,7 @@ async function up$73(db) {
5054
5092
  ON public.held_run_approvals USING btree (held_run_id)
5055
5093
  `.execute(db);
5056
5094
  }
5057
- async function down$73(db) {
5095
+ async function down$74(db) {
5058
5096
  await sql`DROP TABLE IF EXISTS public.held_run_approvals`.execute(db);
5059
5097
  await sql`ALTER TABLE public.held_runs DROP COLUMN IF EXISTS approval_requirement`.execute(db);
5060
5098
  await sql`ALTER TABLE public.held_runs DROP COLUMN IF EXISTS trigger_source`.execute(db);
@@ -5064,8 +5102,8 @@ async function down$73(db) {
5064
5102
  //#endregion
5065
5103
  //#region src/db/migrations/035_pending_workflow_contexts.ts
5066
5104
  var _035_pending_workflow_contexts_exports = /* @__PURE__ */ __exportAll({
5067
- down: () => down$72,
5068
- up: () => up$72
5105
+ down: () => down$73,
5106
+ up: () => up$73
5069
5107
  });
5070
5108
  /**
5071
5109
  * Pending workflow dispatch context — backs resume of a workflow whose install
@@ -5074,7 +5112,7 @@ var _035_pending_workflow_contexts_exports = /* @__PURE__ */ __exportAll({
5074
5112
  * wait-timer expiry, concurrency slot free). The row is deleted once the resume
5075
5113
  * dispatch has been kicked off.
5076
5114
  */
5077
- async function up$72(db) {
5115
+ async function up$73(db) {
5078
5116
  await sql`
5079
5117
  CREATE TABLE IF NOT EXISTS public.pending_workflow_contexts (
5080
5118
  run_id text PRIMARY KEY,
@@ -5084,14 +5122,14 @@ async function up$72(db) {
5084
5122
  )
5085
5123
  `.execute(db);
5086
5124
  }
5087
- async function down$72(db) {
5125
+ async function down$73(db) {
5088
5126
  await sql`DROP TABLE IF EXISTS public.pending_workflow_contexts`.execute(db);
5089
5127
  }
5090
5128
  //#endregion
5091
5129
  //#region src/db/migrations/036_attestations.ts
5092
5130
  var _036_attestations_exports = /* @__PURE__ */ __exportAll({
5093
- down: () => down$71,
5094
- up: () => up$71
5131
+ down: () => down$72,
5132
+ up: () => up$72
5095
5133
  });
5096
5134
  /**
5097
5135
  * Add the `attestations` table for build-provenance bundles.
@@ -5104,7 +5142,7 @@ var _036_attestations_exports = /* @__PURE__ */ __exportAll({
5104
5142
  *
5105
5143
  * Idempotent: a re-run on a DB that already has the table is a no-op.
5106
5144
  */
5107
- async function up$71(db) {
5145
+ async function up$72(db) {
5108
5146
  if ((await sql`
5109
5147
  SELECT EXISTS (
5110
5148
  SELECT 1 FROM information_schema.tables
@@ -5130,14 +5168,14 @@ async function up$71(db) {
5130
5168
  ON public.attestations (run_id, job_id)
5131
5169
  `.execute(db);
5132
5170
  }
5133
- async function down$71(db) {
5171
+ async function down$72(db) {
5134
5172
  await sql`DROP TABLE IF EXISTS public.attestations`.execute(db);
5135
5173
  }
5136
5174
  //#endregion
5137
5175
  //#region src/db/migrations/037_generic_sources_provider_type_local.ts
5138
5176
  var _037_generic_sources_provider_type_local_exports = /* @__PURE__ */ __exportAll({
5139
- down: () => down$70,
5140
- up: () => up$70
5177
+ down: () => down$71,
5178
+ up: () => up$71
5141
5179
  });
5142
5180
  /**
5143
5181
  * Replace the `generic_webhook_sources.provider_type` CHECK constraint so it
@@ -5154,7 +5192,7 @@ var _037_generic_sources_provider_type_local_exports = /* @__PURE__ */ __exportA
5154
5192
  * Idempotent: the constraint is dropped IF EXISTS and recreated; the data
5155
5193
  * backfill is a plain UPDATE that is a no-op once no `'internal'` rows remain.
5156
5194
  */
5157
- async function up$70(db) {
5195
+ async function up$71(db) {
5158
5196
  await sql`
5159
5197
  ALTER TABLE public.generic_webhook_sources
5160
5198
  DROP CONSTRAINT IF EXISTS generic_webhook_sources_provider_type_check
@@ -5170,7 +5208,7 @@ async function up$70(db) {
5170
5208
  CHECK (provider_type = ANY (ARRAY['generic'::text, 'local'::text]))
5171
5209
  `.execute(db);
5172
5210
  }
5173
- async function down$70(db) {
5211
+ async function down$71(db) {
5174
5212
  await sql`
5175
5213
  ALTER TABLE public.generic_webhook_sources
5176
5214
  DROP CONSTRAINT IF EXISTS generic_webhook_sources_provider_type_check
@@ -5189,8 +5227,8 @@ async function down$70(db) {
5189
5227
  //#endregion
5190
5228
  //#region src/db/migrations/038_remote_sources.ts
5191
5229
  var _038_remote_sources_exports = /* @__PURE__ */ __exportAll({
5192
- down: () => down$69,
5193
- up: () => up$69
5230
+ down: () => down$70,
5231
+ up: () => up$70
5194
5232
  });
5195
5233
  /**
5196
5234
  * `remote_sources` anchors a Platform-relayed `kici run remote` to its real
@@ -5202,7 +5240,7 @@ var _038_remote_sources_exports = /* @__PURE__ */ __exportAll({
5202
5240
  *
5203
5241
  * Idempotent: a re-run on a DB that already has the table is a no-op.
5204
5242
  */
5205
- async function up$69(db) {
5243
+ async function up$70(db) {
5206
5244
  if ((await sql`
5207
5245
  SELECT EXISTS (
5208
5246
  SELECT 1 FROM information_schema.tables
@@ -5221,14 +5259,14 @@ async function up$69(db) {
5221
5259
  )
5222
5260
  `.execute(db);
5223
5261
  }
5224
- async function down$69(db) {
5262
+ async function down$70(db) {
5225
5263
  await sql`DROP TABLE IF EXISTS public.remote_sources`.execute(db);
5226
5264
  }
5227
5265
  //#endregion
5228
5266
  //#region src/db/migrations/039_host_roster.ts
5229
5267
  var _039_host_roster_exports = /* @__PURE__ */ __exportAll({
5230
- down: () => down$68,
5231
- up: () => up$68
5268
+ down: () => down$69,
5269
+ up: () => up$69
5232
5270
  });
5233
5271
  /**
5234
5272
  * `host_roster` is KiCI's declared inventory: one durable row per agent the
@@ -5245,7 +5283,7 @@ var _039_host_roster_exports = /* @__PURE__ */ __exportAll({
5245
5283
  *
5246
5284
  * Idempotent: a re-run on a DB that already has the table is a no-op.
5247
5285
  */
5248
- async function up$68(db) {
5286
+ async function up$69(db) {
5249
5287
  if ((await sql`
5250
5288
  SELECT EXISTS (
5251
5289
  SELECT 1 FROM information_schema.tables
@@ -5275,14 +5313,14 @@ async function up$68(db) {
5275
5313
  await sql`CREATE INDEX idx_host_roster_reap
5276
5314
  ON public.host_roster (lifecycle_class, last_seen)`.execute(db);
5277
5315
  }
5278
- async function down$68(db) {
5316
+ async function down$69(db) {
5279
5317
  await sql`DROP TABLE IF EXISTS public.host_roster`.execute(db);
5280
5318
  }
5281
5319
  //#endregion
5282
5320
  //#region src/db/migrations/040_runsonall_pin.ts
5283
5321
  var _040_runsonall_pin_exports = /* @__PURE__ */ __exportAll({
5284
- down: () => down$67,
5285
- up: () => up$67
5322
+ down: () => down$68,
5323
+ up: () => up$68
5286
5324
  });
5287
5325
  /**
5288
5326
  * Add the `runsOnAll` host fan-out columns:
@@ -5309,7 +5347,7 @@ async function colExists$12(db, table, name) {
5309
5347
  ) AS exists
5310
5348
  `.execute(db)).rows[0]?.exists ?? false;
5311
5349
  }
5312
- async function up$67(db) {
5350
+ async function up$68(db) {
5313
5351
  if (!await colExists$12(db, "dispatch_queue", "pinned_agent_id")) await sql`ALTER TABLE public.dispatch_queue ADD COLUMN pinned_agent_id TEXT`.execute(db);
5314
5352
  if (!await colExists$12(db, "execution_jobs", "base_job_name")) await sql`ALTER TABLE public.execution_jobs ADD COLUMN base_job_name TEXT`.execute(db);
5315
5353
  if (!await colExists$12(db, "execution_jobs", "variant_kind")) await sql`ALTER TABLE public.execution_jobs ADD COLUMN variant_kind TEXT`.execute(db);
@@ -5320,7 +5358,7 @@ async function up$67(db) {
5320
5358
  WHERE pinned_agent_id IS NOT NULL
5321
5359
  `.execute(db);
5322
5360
  }
5323
- async function down$67(db) {
5361
+ async function down$68(db) {
5324
5362
  await sql`DROP INDEX IF EXISTS public.idx_dispatch_queue_pinned_agent`.execute(db);
5325
5363
  await sql`ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS pinned_agent_id`.execute(db);
5326
5364
  await sql`ALTER TABLE public.execution_jobs DROP COLUMN IF EXISTS variant_label`.execute(db);
@@ -5330,8 +5368,8 @@ async function down$67(db) {
5330
5368
  //#endregion
5331
5369
  //#region src/db/migrations/041_wave_gated.ts
5332
5370
  var _041_wave_gated_exports = /* @__PURE__ */ __exportAll({
5333
- down: () => down$66,
5334
- up: () => up$66
5371
+ down: () => down$67,
5372
+ up: () => up$67
5335
5373
  });
5336
5374
  /**
5337
5375
  * Add the rolling fan-out wave-gate columns:
@@ -5361,7 +5399,7 @@ async function colExists$11(db, table, name) {
5361
5399
  ) AS exists
5362
5400
  `.execute(db)).rows[0]?.exists ?? false;
5363
5401
  }
5364
- async function up$66(db) {
5402
+ async function up$67(db) {
5365
5403
  if (!await colExists$11(db, "execution_jobs", "wave_gated")) await sql`ALTER TABLE public.execution_jobs ADD COLUMN wave_gated boolean NOT NULL DEFAULT false`.execute(db);
5366
5404
  if (!await colExists$11(db, "execution_jobs", "wave_max_parallel")) await sql`ALTER TABLE public.execution_jobs ADD COLUMN wave_max_parallel integer`.execute(db);
5367
5405
  if (!await colExists$11(db, "execution_jobs", "wave_fail_fast")) await sql`ALTER TABLE public.execution_jobs ADD COLUMN wave_fail_fast boolean`.execute(db);
@@ -5370,7 +5408,7 @@ async function up$66(db) {
5370
5408
  ON public.execution_jobs (run_id, base_job_name, wave_gated)
5371
5409
  `.execute(db);
5372
5410
  }
5373
- async function down$66(db) {
5411
+ async function down$67(db) {
5374
5412
  await sql`DROP INDEX IF EXISTS public.idx_execution_jobs_wave`.execute(db);
5375
5413
  await sql`ALTER TABLE public.execution_jobs DROP COLUMN IF EXISTS wave_fail_fast`.execute(db);
5376
5414
  await sql`ALTER TABLE public.execution_jobs DROP COLUMN IF EXISTS wave_max_parallel`.execute(db);
@@ -5379,8 +5417,8 @@ async function down$66(db) {
5379
5417
  //#endregion
5380
5418
  //#region src/db/migrations/042_dispatch_queue_patterns.ts
5381
5419
  var _042_dispatch_queue_patterns_exports = /* @__PURE__ */ __exportAll({
5382
- down: () => down$65,
5383
- up: () => up$65
5420
+ down: () => down$66,
5421
+ up: () => up$66
5384
5422
  });
5385
5423
  /**
5386
5424
  * Add pattern columns to dispatch_queue. Exact labels stay in runs_on_labels /
@@ -5406,19 +5444,19 @@ async function colExists$10(db, table, name) {
5406
5444
  ) AS exists
5407
5445
  `.execute(db)).rows[0]?.exists ?? false;
5408
5446
  }
5409
- async function up$65(db) {
5447
+ async function up$66(db) {
5410
5448
  if (!await colExists$10(db, "dispatch_queue", "runs_on_patterns")) await sql`ALTER TABLE public.dispatch_queue ADD COLUMN runs_on_patterns jsonb NOT NULL DEFAULT '[]'::jsonb`.execute(db);
5411
5449
  if (!await colExists$10(db, "dispatch_queue", "exclude_patterns")) await sql`ALTER TABLE public.dispatch_queue ADD COLUMN exclude_patterns jsonb NOT NULL DEFAULT '[]'::jsonb`.execute(db);
5412
5450
  }
5413
- async function down$65(db) {
5451
+ async function down$66(db) {
5414
5452
  await sql`ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS exclude_patterns`.execute(db);
5415
5453
  await sql`ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS runs_on_patterns`.execute(db);
5416
5454
  }
5417
5455
  //#endregion
5418
5456
  //#region src/db/migrations/043_rerouted_to_peer.ts
5419
5457
  var _043_rerouted_to_peer_exports = /* @__PURE__ */ __exportAll({
5420
- down: () => down$64,
5421
- up: () => up$64
5458
+ down: () => down$65,
5459
+ up: () => up$65
5422
5460
  });
5423
5461
  /**
5424
5462
  * Add a nullable `rerouted_to_peer text` marker to execution_jobs. Non-null
@@ -5439,17 +5477,17 @@ async function colExists$9(db, table, name) {
5439
5477
  ) AS exists
5440
5478
  `.execute(db)).rows[0]?.exists ?? false;
5441
5479
  }
5442
- async function up$64(db) {
5480
+ async function up$65(db) {
5443
5481
  if (!await colExists$9(db, "execution_jobs", "rerouted_to_peer")) await sql`ALTER TABLE public.execution_jobs ADD COLUMN rerouted_to_peer text`.execute(db);
5444
5482
  }
5445
- async function down$64(db) {
5483
+ async function down$65(db) {
5446
5484
  await sql`ALTER TABLE public.execution_jobs DROP COLUMN IF EXISTS rerouted_to_peer`.execute(db);
5447
5485
  }
5448
5486
  //#endregion
5449
5487
  //#region src/db/migrations/044_check_mode.ts
5450
5488
  var _044_check_mode_exports = /* @__PURE__ */ __exportAll({
5451
- down: () => down$63,
5452
- up: () => up$63
5489
+ down: () => down$64,
5490
+ up: () => up$64
5453
5491
  });
5454
5492
  /**
5455
5493
  * Add idempotent check-mode columns:
@@ -5476,13 +5514,13 @@ async function colExists$8(db, table, name) {
5476
5514
  ) AS exists
5477
5515
  `.execute(db)).rows[0]?.exists ?? false;
5478
5516
  }
5479
- async function up$63(db) {
5517
+ async function up$64(db) {
5480
5518
  if (!await colExists$8(db, "execution_runs", "check_mode")) await sql`ALTER TABLE public.execution_runs ADD COLUMN check_mode text`.execute(db);
5481
5519
  if (!await colExists$8(db, "execution_steps", "check_outcome")) await sql`ALTER TABLE public.execution_steps ADD COLUMN check_outcome text`.execute(db);
5482
5520
  if (!await colExists$8(db, "execution_steps", "drift_summary")) await sql`ALTER TABLE public.execution_steps ADD COLUMN drift_summary text`.execute(db);
5483
5521
  if (!await colExists$8(db, "execution_steps", "drift")) await sql`ALTER TABLE public.execution_steps ADD COLUMN drift jsonb`.execute(db);
5484
5522
  }
5485
- async function down$63(db) {
5523
+ async function down$64(db) {
5486
5524
  await sql`ALTER TABLE public.execution_steps DROP COLUMN IF EXISTS drift`.execute(db);
5487
5525
  await sql`ALTER TABLE public.execution_steps DROP COLUMN IF EXISTS drift_summary`.execute(db);
5488
5526
  await sql`ALTER TABLE public.execution_steps DROP COLUMN IF EXISTS check_outcome`.execute(db);
@@ -5491,8 +5529,8 @@ async function down$63(db) {
5491
5529
  //#endregion
5492
5530
  //#region src/db/migrations/045_host_properties.ts
5493
5531
  var _045_host_properties_exports = /* @__PURE__ */ __exportAll({
5494
- down: () => down$62,
5495
- up: () => up$62
5532
+ down: () => down$63,
5533
+ up: () => up$63
5496
5534
  });
5497
5535
  /**
5498
5536
  * Add the typed host-vars dimension to the host roster:
@@ -5506,18 +5544,18 @@ var _045_host_properties_exports = /* @__PURE__ */ __exportAll({
5506
5544
  * Idempotent (`ADD COLUMN IF NOT EXISTS`): re-running on a DB that already has
5507
5545
  * the column is a no-op. Staging data is preserved (additive column).
5508
5546
  */
5509
- async function up$62(db) {
5547
+ async function up$63(db) {
5510
5548
  await sql`ALTER TABLE public.host_roster
5511
5549
  ADD COLUMN IF NOT EXISTS host_properties jsonb NOT NULL DEFAULT '{}'::jsonb`.execute(db);
5512
5550
  }
5513
- async function down$62(db) {
5551
+ async function down$63(db) {
5514
5552
  await sql`ALTER TABLE public.host_roster DROP COLUMN IF EXISTS host_properties`.execute(db);
5515
5553
  }
5516
5554
  //#endregion
5517
5555
  //#region src/db/migrations/046_join_token_consumed_by_instance.ts
5518
5556
  var _046_join_token_consumed_by_instance_exports = /* @__PURE__ */ __exportAll({
5519
- down: () => down$61,
5520
- up: () => up$61
5557
+ down: () => down$62,
5558
+ up: () => up$62
5521
5559
  });
5522
5560
  /**
5523
5561
  * Record the joining peer's instanceId at first consumption of a join token:
@@ -5532,18 +5570,18 @@ var _046_join_token_consumed_by_instance_exports = /* @__PURE__ */ __exportAll({
5532
5570
  * Idempotent (`ADD COLUMN IF NOT EXISTS`): re-running on a DB that already has
5533
5571
  * the column is a no-op. Staging data is preserved (additive nullable column).
5534
5572
  */
5535
- async function up$61(db) {
5573
+ async function up$62(db) {
5536
5574
  await sql`ALTER TABLE public.join_tokens
5537
5575
  ADD COLUMN IF NOT EXISTS consumed_by_instance text`.execute(db);
5538
5576
  }
5539
- async function down$61(db) {
5577
+ async function down$62(db) {
5540
5578
  await sql`ALTER TABLE public.join_tokens DROP COLUMN IF EXISTS consumed_by_instance`.execute(db);
5541
5579
  }
5542
5580
  //#endregion
5543
5581
  //#region src/db/migrations/047_needs_run_on.ts
5544
5582
  var _047_needs_run_on_exports = /* @__PURE__ */ __exportAll({
5545
- down: () => down$60,
5546
- up: () => up$60
5583
+ down: () => down$61,
5584
+ up: () => up$61
5547
5585
  });
5548
5586
  /**
5549
5587
  * Migrate `execution_job_needs` from the binary `if_failed` policy to a
@@ -5579,7 +5617,7 @@ async function colExists$7(db, table, name) {
5579
5617
  `.execute(db)).rows[0]?.exists ?? false;
5580
5618
  }
5581
5619
  const SUCCESS_ONLY_DEFAULT = `'${SUCCESS_ONLY_JSON}'`;
5582
- async function up$60(db) {
5620
+ async function up$61(db) {
5583
5621
  if (!await colExists$7(db, "execution_job_needs", "run_on")) await sql`
5584
5622
  ALTER TABLE public.execution_job_needs
5585
5623
  ADD COLUMN run_on text NOT NULL DEFAULT ${sql.raw(SUCCESS_ONLY_DEFAULT)}
@@ -5598,7 +5636,7 @@ async function up$60(db) {
5598
5636
  await sql`ALTER TABLE public.execution_job_needs DROP COLUMN if_failed`.execute(db);
5599
5637
  }
5600
5638
  }
5601
- async function down$60(db) {
5639
+ async function down$61(db) {
5602
5640
  if (!await colExists$7(db, "execution_job_needs", "if_failed")) await sql`
5603
5641
  ALTER TABLE public.execution_job_needs
5604
5642
  ADD COLUMN if_failed text NOT NULL DEFAULT 'skip'
@@ -5614,8 +5652,8 @@ async function down$60(db) {
5614
5652
  //#endregion
5615
5653
  //#region src/db/migrations/048_host_reboot_pending.ts
5616
5654
  var _048_host_reboot_pending_exports = /* @__PURE__ */ __exportAll({
5617
- down: () => down$59,
5618
- up: () => up$59
5655
+ down: () => down$60,
5656
+ up: () => up$60
5619
5657
  });
5620
5658
  /**
5621
5659
  * Add `host_roster.reboot_pending_until timestamptz NULL` — the persisted
@@ -5632,18 +5670,18 @@ var _048_host_reboot_pending_exports = /* @__PURE__ */ __exportAll({
5632
5670
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive, so staging data is
5633
5671
  * preserved.
5634
5672
  */
5635
- async function up$59(db) {
5673
+ async function up$60(db) {
5636
5674
  await sql`ALTER TABLE public.host_roster
5637
5675
  ADD COLUMN IF NOT EXISTS reboot_pending_until timestamptz`.execute(db);
5638
5676
  }
5639
- async function down$59(db) {
5677
+ async function down$60(db) {
5640
5678
  await sql`ALTER TABLE public.host_roster DROP COLUMN IF EXISTS reboot_pending_until`.execute(db);
5641
5679
  }
5642
5680
  //#endregion
5643
5681
  //#region src/db/migrations/049_held_runs_payload.ts
5644
5682
  var _049_held_runs_payload_exports = /* @__PURE__ */ __exportAll({
5645
- down: () => down$58,
5646
- up: () => up$58
5683
+ down: () => down$59,
5684
+ up: () => up$59
5647
5685
  });
5648
5686
  /**
5649
5687
  * Add `held_runs.payload jsonb NULL` — the drift payload captured when a
@@ -5655,18 +5693,18 @@ var _049_held_runs_payload_exports = /* @__PURE__ */ __exportAll({
5655
5693
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive, so staging data is
5656
5694
  * preserved.
5657
5695
  */
5658
- async function up$58(db) {
5696
+ async function up$59(db) {
5659
5697
  await sql`ALTER TABLE public.held_runs
5660
5698
  ADD COLUMN IF NOT EXISTS payload jsonb`.execute(db);
5661
5699
  }
5662
- async function down$58(db) {
5700
+ async function down$59(db) {
5663
5701
  await sql`ALTER TABLE public.held_runs DROP COLUMN IF EXISTS payload`.execute(db);
5664
5702
  }
5665
5703
  //#endregion
5666
5704
  //#region src/db/migrations/050_sources_slug.ts
5667
5705
  var _050_sources_slug_exports = /* @__PURE__ */ __exportAll({
5668
- down: () => down$57,
5669
- up: () => up$57
5706
+ down: () => down$58,
5707
+ up: () => up$58
5670
5708
  });
5671
5709
  /**
5672
5710
  * Add `sources.slug TEXT NULL` — the GitHub App slug (the URL-safe identifier
@@ -5681,18 +5719,18 @@ var _050_sources_slug_exports = /* @__PURE__ */ __exportAll({
5681
5719
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive, so staging data is
5682
5720
  * preserved.
5683
5721
  */
5684
- async function up$57(db) {
5722
+ async function up$58(db) {
5685
5723
  await sql`ALTER TABLE public.sources
5686
5724
  ADD COLUMN IF NOT EXISTS slug text`.execute(db);
5687
5725
  }
5688
- async function down$57(db) {
5726
+ async function down$58(db) {
5689
5727
  await sql`ALTER TABLE public.sources DROP COLUMN IF EXISTS slug`.execute(db);
5690
5728
  }
5691
5729
  //#endregion
5692
5730
  //#region src/db/migrations/051_binding_host_pattern.ts
5693
5731
  var _051_binding_host_pattern_exports = /* @__PURE__ */ __exportAll({
5694
- down: () => down$56,
5695
- up: () => up$56
5732
+ down: () => down$57,
5733
+ up: () => up$57
5696
5734
  });
5697
5735
  /**
5698
5736
  * Add a per-host dimension to environment secret bindings:
@@ -5708,7 +5746,7 @@ var _051_binding_host_pattern_exports = /* @__PURE__ */ __exportAll({
5708
5746
  * Idempotent: re-running on a DB that already has the column / index is a no-op.
5709
5747
  * Additive — staging data is preserved.
5710
5748
  */
5711
- async function up$56(db) {
5749
+ async function up$57(db) {
5712
5750
  await sql`ALTER TABLE public.environment_bindings
5713
5751
  ADD COLUMN IF NOT EXISTS host_pattern text NOT NULL DEFAULT '**'`.execute(db);
5714
5752
  await sql`ALTER TABLE public.environment_bindings
@@ -5716,7 +5754,7 @@ async function up$56(db) {
5716
5754
  await sql`CREATE UNIQUE INDEX IF NOT EXISTS environment_bindings_env_scope_host_uniq
5717
5755
  ON public.environment_bindings (environment_id, scope_pattern, host_pattern)`.execute(db);
5718
5756
  }
5719
- async function down$56(db) {
5757
+ async function down$57(db) {
5720
5758
  await sql`DROP INDEX IF EXISTS public.environment_bindings_env_scope_host_uniq`.execute(db);
5721
5759
  await sql`ALTER TABLE public.environment_bindings
5722
5760
  DROP COLUMN IF EXISTS host_pattern`.execute(db);
@@ -5726,8 +5764,8 @@ async function down$56(db) {
5726
5764
  //#endregion
5727
5765
  //#region src/db/migrations/052_host_reach_metadata.ts
5728
5766
  var _052_host_reach_metadata_exports = /* @__PURE__ */ __exportAll({
5729
- down: () => down$55,
5730
- up: () => up$55
5767
+ down: () => down$56,
5768
+ up: () => up$56
5731
5769
  });
5732
5770
  /**
5733
5771
  * Add pre-agent reach metadata to the host roster so a declared host (no agent
@@ -5744,14 +5782,14 @@ var _052_host_reach_metadata_exports = /* @__PURE__ */ __exportAll({
5744
5782
  * behaves exactly as before. Idempotent (`ADD COLUMN IF NOT EXISTS`); additive,
5745
5783
  * so staging data is preserved.
5746
5784
  */
5747
- async function up$55(db) {
5785
+ async function up$56(db) {
5748
5786
  await sql`ALTER TABLE public.host_roster
5749
5787
  ADD COLUMN IF NOT EXISTS address text,
5750
5788
  ADD COLUMN IF NOT EXISTS ssh_user text,
5751
5789
  ADD COLUMN IF NOT EXISTS ssh_port integer,
5752
5790
  ADD COLUMN IF NOT EXISTS ssh_key_secret text`.execute(db);
5753
5791
  }
5754
- async function down$55(db) {
5792
+ async function down$56(db) {
5755
5793
  await sql`ALTER TABLE public.host_roster
5756
5794
  DROP COLUMN IF EXISTS address,
5757
5795
  DROP COLUMN IF EXISTS ssh_user,
@@ -5761,8 +5799,8 @@ async function down$55(db) {
5761
5799
  //#endregion
5762
5800
  //#region src/db/migrations/053_agent_token_single_use.ts
5763
5801
  var _053_agent_token_single_use_exports = /* @__PURE__ */ __exportAll({
5764
- down: () => down$54,
5765
- up: () => up$54
5802
+ down: () => down$55,
5803
+ up: () => up$55
5766
5804
  });
5767
5805
  /**
5768
5806
  * Add a single-use marker to agent tokens for the bootstrap (init-runner)
@@ -5777,19 +5815,19 @@ var _053_agent_token_single_use_exports = /* @__PURE__ */ __exportAll({
5777
5815
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive, so staging data is
5778
5816
  * preserved.
5779
5817
  */
5780
- async function up$54(db) {
5818
+ async function up$55(db) {
5781
5819
  await sql`ALTER TABLE public.agent_tokens
5782
5820
  ADD COLUMN IF NOT EXISTS consumed_at timestamptz`.execute(db);
5783
5821
  }
5784
- async function down$54(db) {
5822
+ async function down$55(db) {
5785
5823
  await sql`ALTER TABLE public.agent_tokens
5786
5824
  DROP COLUMN IF EXISTS consumed_at`.execute(db);
5787
5825
  }
5788
5826
  //#endregion
5789
5827
  //#region src/db/migrations/054_local_working_tree.ts
5790
5828
  var _054_local_working_tree_exports = /* @__PURE__ */ __exportAll({
5791
- down: () => down$53,
5792
- up: () => up$53
5829
+ down: () => down$54,
5830
+ up: () => up$54
5793
5831
  });
5794
5832
  /**
5795
5833
  * Mark runs that executed an uploaded local working tree (`kici run remote`):
@@ -5802,19 +5840,19 @@ var _054_local_working_tree_exports = /* @__PURE__ */ __exportAll({
5802
5840
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive with a default, so staging
5803
5841
  * data is preserved.
5804
5842
  */
5805
- async function up$53(db) {
5843
+ async function up$54(db) {
5806
5844
  await sql`ALTER TABLE public.execution_runs
5807
5845
  ADD COLUMN IF NOT EXISTS local_working_tree boolean NOT NULL DEFAULT false`.execute(db);
5808
5846
  }
5809
- async function down$53(db) {
5847
+ async function down$54(db) {
5810
5848
  await sql`ALTER TABLE public.execution_runs
5811
5849
  DROP COLUMN IF EXISTS local_working_tree`.execute(db);
5812
5850
  }
5813
5851
  //#endregion
5814
5852
  //#region src/db/migrations/055_agent_token_mandatory_labels.ts
5815
5853
  var _055_agent_token_mandatory_labels_exports = /* @__PURE__ */ __exportAll({
5816
- down: () => down$52,
5817
- up: () => up$52
5854
+ down: () => down$53,
5855
+ up: () => up$53
5818
5856
  });
5819
5857
  /**
5820
5858
  * Add a token-bound mandatory-label taint to agent tokens:
@@ -5830,19 +5868,19 @@ var _055_agent_token_mandatory_labels_exports = /* @__PURE__ */ __exportAll({
5830
5868
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive, so staging data is
5831
5869
  * preserved.
5832
5870
  */
5833
- async function up$52(db) {
5871
+ async function up$53(db) {
5834
5872
  await sql`ALTER TABLE public.agent_tokens
5835
5873
  ADD COLUMN IF NOT EXISTS mandatory_labels text`.execute(db);
5836
5874
  }
5837
- async function down$52(db) {
5875
+ async function down$53(db) {
5838
5876
  await sql`ALTER TABLE public.agent_tokens
5839
5877
  DROP COLUMN IF EXISTS mandatory_labels`.execute(db);
5840
5878
  }
5841
5879
  //#endregion
5842
5880
  //#region src/db/migrations/056_execution_jobs_environments.ts
5843
5881
  var _056_execution_jobs_environments_exports = /* @__PURE__ */ __exportAll({
5844
- down: () => down$51,
5845
- up: () => up$51
5882
+ down: () => down$52,
5883
+ up: () => up$52
5846
5884
  });
5847
5885
  /**
5848
5886
  * Add a per-job bound deployment-environment list to `execution_jobs`:
@@ -5857,19 +5895,19 @@ var _056_execution_jobs_environments_exports = /* @__PURE__ */ __exportAll({
5857
5895
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive, so staging data is
5858
5896
  * preserved.
5859
5897
  */
5860
- async function up$51(db) {
5898
+ async function up$52(db) {
5861
5899
  await sql`ALTER TABLE public.execution_jobs
5862
5900
  ADD COLUMN IF NOT EXISTS environments text`.execute(db);
5863
5901
  }
5864
- async function down$51(db) {
5902
+ async function down$52(db) {
5865
5903
  await sql`ALTER TABLE public.execution_jobs
5866
5904
  DROP COLUMN IF EXISTS environments`.execute(db);
5867
5905
  }
5868
5906
  //#endregion
5869
5907
  //#region src/db/migrations/057_step_concurrency.ts
5870
5908
  var _057_step_concurrency_exports = /* @__PURE__ */ __exportAll({
5871
- down: () => down$50,
5872
- up: () => up$50
5909
+ down: () => down$51,
5910
+ up: () => up$51
5873
5911
  });
5874
5912
  /**
5875
5913
  * Add parallel step-group concurrency columns to `execution_steps`:
@@ -5892,19 +5930,19 @@ async function colExists$6(db, table, name) {
5892
5930
  ) AS exists
5893
5931
  `.execute(db)).rows[0]?.exists ?? false;
5894
5932
  }
5895
- async function up$50(db) {
5933
+ async function up$51(db) {
5896
5934
  if (!await colExists$6(db, "execution_steps", "concurrency_kind")) await sql`ALTER TABLE public.execution_steps ADD COLUMN concurrency_kind text`.execute(db);
5897
5935
  if (!await colExists$6(db, "execution_steps", "group_id")) await sql`ALTER TABLE public.execution_steps ADD COLUMN group_id text`.execute(db);
5898
5936
  }
5899
- async function down$50(db) {
5937
+ async function down$51(db) {
5900
5938
  await sql`ALTER TABLE public.execution_steps DROP COLUMN IF EXISTS group_id`.execute(db);
5901
5939
  await sql`ALTER TABLE public.execution_steps DROP COLUMN IF EXISTS concurrency_kind`.execute(db);
5902
5940
  }
5903
5941
  //#endregion
5904
5942
  //#region src/db/migrations/058_access_log_agent_label.ts
5905
5943
  var _058_access_log_agent_label_exports = /* @__PURE__ */ __exportAll({
5906
- down: () => down$49,
5907
- up: () => up$49
5944
+ down: () => down$50,
5945
+ up: () => up$50
5908
5946
  });
5909
5947
  /**
5910
5948
  * Add `access_log.agent_label text` — the human-set name of the agent that
@@ -5924,17 +5962,17 @@ async function colExists$5(db, table, name) {
5924
5962
  ) AS exists
5925
5963
  `.execute(db)).rows[0]?.exists ?? false;
5926
5964
  }
5927
- async function up$49(db) {
5965
+ async function up$50(db) {
5928
5966
  if (!await colExists$5(db, "access_log", "agent_label")) await sql`ALTER TABLE public.access_log ADD COLUMN agent_label text`.execute(db);
5929
5967
  }
5930
- async function down$49(db) {
5968
+ async function down$50(db) {
5931
5969
  await sql`ALTER TABLE public.access_log DROP COLUMN IF EXISTS agent_label`.execute(db);
5932
5970
  }
5933
5971
  //#endregion
5934
5972
  //#region src/db/migrations/059_attestation_verdict.ts
5935
5973
  var _059_attestation_verdict_exports = /* @__PURE__ */ __exportAll({
5936
- down: () => down$48,
5937
- up: () => up$48
5974
+ down: () => down$49,
5975
+ up: () => up$49
5938
5976
  });
5939
5977
  /**
5940
5978
  * Add server-side verification verdict columns to `attestations`, plus the
@@ -5961,7 +5999,7 @@ async function colExists$4(db, table, name) {
5961
5999
  ) AS exists
5962
6000
  `.execute(db)).rows[0]?.exists ?? false;
5963
6001
  }
5964
- async function up$48(db) {
6002
+ async function up$49(db) {
5965
6003
  if (await colExists$4(db, "attestations", "verify_status")) return;
5966
6004
  await sql`
5967
6005
  ALTER TABLE public.attestations
@@ -5974,7 +6012,7 @@ async function up$48(db) {
5974
6012
  await sql`CREATE INDEX idx_attestations_verify_status ON public.attestations (verify_status)`.execute(db);
5975
6013
  await sql`CREATE INDEX idx_attestations_created_at ON public.attestations (created_at)`.execute(db);
5976
6014
  }
5977
- async function down$48(db) {
6015
+ async function down$49(db) {
5978
6016
  await sql`DROP INDEX IF EXISTS idx_attestations_created_at`.execute(db);
5979
6017
  await sql`DROP INDEX IF EXISTS idx_attestations_verify_status`.execute(db);
5980
6018
  await sql`DROP INDEX IF EXISTS idx_attestations_subject_name`.execute(db);
@@ -5989,8 +6027,8 @@ async function down$48(db) {
5989
6027
  //#endregion
5990
6028
  //#region src/db/migrations/060_run_trigger_actor.ts
5991
6029
  var _060_run_trigger_actor_exports = /* @__PURE__ */ __exportAll({
5992
- down: () => down$47,
5993
- up: () => up$47
6030
+ down: () => down$48,
6031
+ up: () => up$48
5994
6032
  });
5995
6033
  /**
5996
6034
  * Add the triggering-actor columns to `execution_runs`:
@@ -6018,12 +6056,12 @@ async function colExists$3(db, table, name) {
6018
6056
  ) AS exists
6019
6057
  `.execute(db)).rows[0]?.exists ?? false;
6020
6058
  }
6021
- async function up$47(db) {
6059
+ async function up$48(db) {
6022
6060
  if (!await colExists$3(db, "execution_runs", "trigger_actor_provider")) await sql`ALTER TABLE public.execution_runs ADD COLUMN trigger_actor_provider text`.execute(db);
6023
6061
  if (!await colExists$3(db, "execution_runs", "trigger_actor_username")) await sql`ALTER TABLE public.execution_runs ADD COLUMN trigger_actor_username text`.execute(db);
6024
6062
  if (!await colExists$3(db, "execution_runs", "trigger_actor_user_id")) await sql`ALTER TABLE public.execution_runs ADD COLUMN trigger_actor_user_id text`.execute(db);
6025
6063
  }
6026
- async function down$47(db) {
6064
+ async function down$48(db) {
6027
6065
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS trigger_actor_provider`.execute(db);
6028
6066
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS trigger_actor_username`.execute(db);
6029
6067
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS trigger_actor_user_id`.execute(db);
@@ -6031,8 +6069,8 @@ async function down$47(db) {
6031
6069
  //#endregion
6032
6070
  //#region src/db/migrations/061_execution_runs_environment_id.ts
6033
6071
  var _061_execution_runs_environment_id_exports = /* @__PURE__ */ __exportAll({
6034
- down: () => down$46,
6035
- up: () => up$46
6072
+ down: () => down$47,
6073
+ up: () => up$47
6036
6074
  });
6037
6075
  /**
6038
6076
  * Add `environment_id` to `execution_runs` so environment run-history can be
@@ -6068,7 +6106,7 @@ async function colExists$2(db, table, name) {
6068
6106
  ) AS exists
6069
6107
  `.execute(db)).rows[0]?.exists ?? false;
6070
6108
  }
6071
- async function up$46(db) {
6109
+ async function up$47(db) {
6072
6110
  if (!await colExists$2(db, "execution_runs", "environment_id")) await sql`
6073
6111
  ALTER TABLE public.execution_runs
6074
6112
  ADD COLUMN environment_id uuid
@@ -6090,15 +6128,15 @@ async function up$46(db) {
6090
6128
  WHERE e2.type = 'fixed' AND e2.name = er.environment) = 1
6091
6129
  `.execute(db);
6092
6130
  }
6093
- async function down$46(db) {
6131
+ async function down$47(db) {
6094
6132
  await sql`DROP INDEX IF EXISTS idx_execution_runs_environment_id`.execute(db);
6095
6133
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS environment_id`.execute(db);
6096
6134
  }
6097
6135
  //#endregion
6098
6136
  //#region src/db/migrations/062_execution_runs_agent_label.ts
6099
6137
  var _062_execution_runs_agent_label_exports = /* @__PURE__ */ __exportAll({
6100
- down: () => down$45,
6101
- up: () => up$45
6138
+ down: () => down$46,
6139
+ up: () => up$46
6102
6140
  });
6103
6141
  /**
6104
6142
  * Add the agent-provenance columns to `execution_runs`:
@@ -6123,19 +6161,19 @@ async function colExists$1(db, table, name) {
6123
6161
  ) AS exists
6124
6162
  `.execute(db)).rows[0]?.exists ?? false;
6125
6163
  }
6126
- async function up$45(db) {
6164
+ async function up$46(db) {
6127
6165
  if (!await colExists$1(db, "execution_runs", "triggered_by_agent_label")) await sql`ALTER TABLE public.execution_runs ADD COLUMN triggered_by_agent_label text`.execute(db);
6128
6166
  if (!await colExists$1(db, "execution_runs", "cancelled_by_agent_label")) await sql`ALTER TABLE public.execution_runs ADD COLUMN cancelled_by_agent_label text`.execute(db);
6129
6167
  }
6130
- async function down$45(db) {
6168
+ async function down$46(db) {
6131
6169
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS triggered_by_agent_label`.execute(db);
6132
6170
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS cancelled_by_agent_label`.execute(db);
6133
6171
  }
6134
6172
  //#endregion
6135
6173
  //#region src/db/migrations/063_access_log_agent_label_index.ts
6136
6174
  var _063_access_log_agent_label_index_exports = /* @__PURE__ */ __exportAll({
6137
- down: () => down$44,
6138
- up: () => up$44
6175
+ down: () => down$45,
6176
+ up: () => up$45
6139
6177
  });
6140
6178
  /**
6141
6179
  * Index `access_log.agent_label` (column added by migration 058) so the
@@ -6143,17 +6181,17 @@ var _063_access_log_agent_label_index_exports = /* @__PURE__ */ __exportAll({
6143
6181
  * the dashboard "agent name" filter) does an indexed exact-match lookup
6144
6182
  * instead of a scan. Idempotent.
6145
6183
  */
6146
- async function up$44(db) {
6184
+ async function up$45(db) {
6147
6185
  await sql`CREATE INDEX IF NOT EXISTS access_log_agent_label_idx ON public.access_log (agent_label)`.execute(db);
6148
6186
  }
6149
- async function down$44(db) {
6187
+ async function down$45(db) {
6150
6188
  await sql`DROP INDEX IF EXISTS access_log_agent_label_idx`.execute(db);
6151
6189
  }
6152
6190
  //#endregion
6153
6191
  //#region src/db/migrations/064_execution_jobs_skipped_environments.ts
6154
6192
  var _064_execution_jobs_skipped_environments_exports = /* @__PURE__ */ __exportAll({
6155
- down: () => down$43,
6156
- up: () => up$43
6193
+ down: () => down$44,
6194
+ up: () => up$44
6157
6195
  });
6158
6196
  /**
6159
6197
  * Add the test-run skipped-environment columns to `execution_jobs`:
@@ -6168,13 +6206,13 @@ var _064_execution_jobs_skipped_environments_exports = /* @__PURE__ */ __exportA
6168
6206
  * Idempotent (`ADD COLUMN IF NOT EXISTS`); additive, so staging data is
6169
6207
  * preserved.
6170
6208
  */
6171
- async function up$43(db) {
6209
+ async function up$44(db) {
6172
6210
  await sql`ALTER TABLE public.execution_jobs
6173
6211
  ADD COLUMN IF NOT EXISTS skipped_environments text`.execute(db);
6174
6212
  await sql`ALTER TABLE public.execution_jobs
6175
6213
  ADD COLUMN IF NOT EXISTS env_warning text`.execute(db);
6176
6214
  }
6177
- async function down$43(db) {
6215
+ async function down$44(db) {
6178
6216
  await sql`ALTER TABLE public.execution_jobs
6179
6217
  DROP COLUMN IF EXISTS skipped_environments`.execute(db);
6180
6218
  await sql`ALTER TABLE public.execution_jobs
@@ -6183,8 +6221,8 @@ async function down$43(db) {
6183
6221
  //#endregion
6184
6222
  //#region src/db/migrations/065_pending_attestations.ts
6185
6223
  var _065_pending_attestations_exports = /* @__PURE__ */ __exportAll({
6186
- down: () => down$42,
6187
- up: () => up$42
6224
+ down: () => down$43,
6225
+ up: () => up$43
6188
6226
  });
6189
6227
  /**
6190
6228
  * Add the `pending_attestations` deferred-attestation outbox and an idempotency
@@ -6204,7 +6242,7 @@ var _065_pending_attestations_exports = /* @__PURE__ */ __exportAll({
6204
6242
  *
6205
6243
  * Idempotent: guarded on table existence.
6206
6244
  */
6207
- async function up$42(db) {
6245
+ async function up$43(db) {
6208
6246
  if ((await sql`
6209
6247
  SELECT EXISTS (
6210
6248
  SELECT 1 FROM information_schema.tables
@@ -6243,15 +6281,15 @@ async function up$42(db) {
6243
6281
  ON public.attestations (run_id, job_id, subject_digest)
6244
6282
  `.execute(db);
6245
6283
  }
6246
- async function down$42(db) {
6284
+ async function down$43(db) {
6247
6285
  await sql`DROP INDEX IF EXISTS uq_attestations_run_job_subject`.execute(db);
6248
6286
  await sql`DROP TABLE IF EXISTS public.pending_attestations`.execute(db);
6249
6287
  }
6250
6288
  //#endregion
6251
6289
  //#region src/db/migrations/066_pending_attestations_rejected.ts
6252
6290
  var _066_pending_attestations_rejected_exports = /* @__PURE__ */ __exportAll({
6253
- down: () => down$41,
6254
- up: () => up$41
6291
+ down: () => down$42,
6292
+ up: () => up$42
6255
6293
  });
6256
6294
  /**
6257
6295
  * Add `rejected_at` to `pending_attestations`: the terminal-rejection marker for
@@ -6262,21 +6300,21 @@ var _066_pending_attestations_rejected_exports = /* @__PURE__ */ __exportAll({
6262
6300
  *
6263
6301
  * Idempotent: guarded on column existence.
6264
6302
  */
6265
- async function up$41(db) {
6266
- if (await columnExists$4(db, "pending_attestations", "rejected_at")) return;
6303
+ async function up$42(db) {
6304
+ if (await columnExists$5(db, "pending_attestations", "rejected_at")) return;
6267
6305
  await sql`
6268
6306
  ALTER TABLE public.pending_attestations
6269
6307
  ADD COLUMN rejected_at TIMESTAMPTZ
6270
6308
  `.execute(db);
6271
6309
  }
6272
- async function down$41(db) {
6273
- if (!await columnExists$4(db, "pending_attestations", "rejected_at")) return;
6310
+ async function down$42(db) {
6311
+ if (!await columnExists$5(db, "pending_attestations", "rejected_at")) return;
6274
6312
  await sql`
6275
6313
  ALTER TABLE public.pending_attestations
6276
6314
  DROP COLUMN rejected_at
6277
6315
  `.execute(db);
6278
6316
  }
6279
- async function columnExists$4(db, table, column) {
6317
+ async function columnExists$5(db, table, column) {
6280
6318
  return (await sql`
6281
6319
  SELECT EXISTS (
6282
6320
  SELECT 1 FROM information_schema.columns
@@ -6287,8 +6325,8 @@ async function columnExists$4(db, table, column) {
6287
6325
  //#endregion
6288
6326
  //#region src/db/migrations/067_environments_to_contexts.ts
6289
6327
  var _067_environments_to_contexts_exports = /* @__PURE__ */ __exportAll({
6290
- down: () => down$40,
6291
- up: () => up$40
6328
+ down: () => down$41,
6329
+ up: () => up$41
6292
6330
  });
6293
6331
  /**
6294
6332
  * Rename the named-policy object from "environment" to "context" across the
@@ -6322,7 +6360,7 @@ var _067_environments_to_contexts_exports = /* @__PURE__ */ __exportAll({
6322
6360
  * columns automatically (Postgres references them by identity, not name), so
6323
6361
  * only the one hand-named index above needs an explicit rename.
6324
6362
  */
6325
- async function up$40(db) {
6363
+ async function up$41(db) {
6326
6364
  await sql`ALTER TABLE public.environments RENAME TO contexts`.execute(db);
6327
6365
  await sql`ALTER TABLE public.environment_bindings RENAME TO context_bindings`.execute(db);
6328
6366
  await sql`ALTER TABLE public.environment_variables RENAME TO context_variables`.execute(db);
@@ -6341,7 +6379,7 @@ async function up$40(db) {
6341
6379
  await sql`ALTER TABLE public.held_runs ALTER COLUMN queue_type SET DEFAULT 'context'`.execute(db);
6342
6380
  await sql`ALTER TABLE public.held_runs ALTER COLUMN trigger_source SET DEFAULT 'context'`.execute(db);
6343
6381
  }
6344
- async function down$40(db) {
6382
+ async function down$41(db) {
6345
6383
  await sql`ALTER TABLE public.held_runs ALTER COLUMN trigger_source SET DEFAULT 'environment'`.execute(db);
6346
6384
  await sql`ALTER TABLE public.held_runs ALTER COLUMN queue_type SET DEFAULT 'environment'`.execute(db);
6347
6385
  await sql`UPDATE public.held_runs SET trigger_source = 'environment' WHERE trigger_source = 'context'`.execute(db);
@@ -6363,8 +6401,8 @@ async function down$40(db) {
6363
6401
  //#endregion
6364
6402
  //#region src/db/migrations/068_request_idempotency.ts
6365
6403
  var _068_request_idempotency_exports = /* @__PURE__ */ __exportAll({
6366
- down: () => down$39,
6367
- up: () => up$39
6404
+ down: () => down$40,
6405
+ up: () => up$40
6368
6406
  });
6369
6407
  /**
6370
6408
  * Add the `request_idempotency` claim table: a `request_id`-keyed record that
@@ -6379,12 +6417,12 @@ var _068_request_idempotency_exports = /* @__PURE__ */ __exportAll({
6379
6417
  *
6380
6418
  * Idempotent: guarded on table existence.
6381
6419
  */
6382
- async function up$39(db) {
6420
+ async function up$40(db) {
6383
6421
  if (await tableExists$3(db, "request_idempotency")) return;
6384
6422
  await db.schema.createTable("request_idempotency").addColumn("request_id", "text", (c) => c.primaryKey()).addColumn("new_run_id", "text", (c) => c.notNull()).addColumn("created_at", "timestamptz", (c) => c.notNull().defaultTo(sql`now()`)).execute();
6385
6423
  await db.schema.createIndex("idx_request_idempotency_created_at").on("request_idempotency").column("created_at").execute();
6386
6424
  }
6387
- async function down$39(db) {
6425
+ async function down$40(db) {
6388
6426
  await db.schema.dropTable("request_idempotency").ifExists().execute();
6389
6427
  }
6390
6428
  async function tableExists$3(db, table) {
@@ -6398,8 +6436,8 @@ async function tableExists$3(db, table) {
6398
6436
  //#endregion
6399
6437
  //#region src/db/migrations/069_reroute_tunables.ts
6400
6438
  var _069_reroute_tunables_exports = /* @__PURE__ */ __exportAll({
6401
- down: () => down$38,
6402
- up: () => up$38
6439
+ down: () => down$39,
6440
+ up: () => up$39
6403
6441
  });
6404
6442
  /**
6405
6443
  * Add the three reroute-tunable columns to `org_settings` (all nullable):
@@ -6418,12 +6456,12 @@ var _069_reroute_tunables_exports = /* @__PURE__ */ __exportAll({
6418
6456
  * Idempotent: each column add is guarded on column existence, so a re-run on a
6419
6457
  * DB that already has a column is a no-op for that column.
6420
6458
  */
6421
- async function up$38(db) {
6459
+ async function up$39(db) {
6422
6460
  await addColumnIfMissing(db, "reroute_spawn_window_ms", "BIGINT");
6423
6461
  await addColumnIfMissing(db, "reroute_ack_timeout_ms", "BIGINT");
6424
6462
  await addColumnIfMissing(db, "reroute_max_hops", "INTEGER");
6425
6463
  }
6426
- async function down$38(db) {
6464
+ async function down$39(db) {
6427
6465
  await sql`ALTER TABLE public.org_settings DROP COLUMN IF EXISTS reroute_spawn_window_ms`.execute(db);
6428
6466
  await sql`ALTER TABLE public.org_settings DROP COLUMN IF EXISTS reroute_ack_timeout_ms`.execute(db);
6429
6467
  await sql`ALTER TABLE public.org_settings DROP COLUMN IF EXISTS reroute_max_hops`.execute(db);
@@ -6442,8 +6480,8 @@ async function addColumnIfMissing(db, column, type) {
6442
6480
  //#endregion
6443
6481
  //#region src/db/migrations/070_execution_runs_failure_class.ts
6444
6482
  var _070_execution_runs_failure_class_exports = /* @__PURE__ */ __exportAll({
6445
- down: () => down$37,
6446
- up: () => up$37
6483
+ down: () => down$38,
6484
+ up: () => up$38
6447
6485
  });
6448
6486
  /**
6449
6487
  * Add `execution_runs.failure_class` — the reason a terminal run failed
@@ -6464,17 +6502,17 @@ async function colExists(db, table, name) {
6464
6502
  ) AS exists
6465
6503
  `.execute(db)).rows[0]?.exists ?? false;
6466
6504
  }
6467
- async function up$37(db) {
6505
+ async function up$38(db) {
6468
6506
  if (!await colExists(db, "execution_runs", "failure_class")) await sql`ALTER TABLE public.execution_runs ADD COLUMN failure_class text`.execute(db);
6469
6507
  }
6470
- async function down$37(db) {
6508
+ async function down$38(db) {
6471
6509
  await sql`ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS failure_class`.execute(db);
6472
6510
  }
6473
6511
  //#endregion
6474
6512
  //#region src/db/migrations/071_batch_accumulation.ts
6475
6513
  var _071_batch_accumulation_exports = /* @__PURE__ */ __exportAll({
6476
- down: () => down$36,
6477
- up: () => up$36
6514
+ down: () => down$37,
6515
+ up: () => up$37
6478
6516
  });
6479
6517
  /**
6480
6518
  * Add the batch-accumulation tables that back the `workflows_failed_batch`
@@ -6498,7 +6536,7 @@ var _071_batch_accumulation_exports = /* @__PURE__ */ __exportAll({
6498
6536
  *
6499
6537
  * Idempotent: guarded on table existence.
6500
6538
  */
6501
- async function up$36(db) {
6539
+ async function up$37(db) {
6502
6540
  if ((await sql`
6503
6541
  SELECT EXISTS (
6504
6542
  SELECT 1 FROM information_schema.tables
@@ -6543,15 +6581,15 @@ async function up$36(db) {
6543
6581
  ON public.batch_accumulation_items (window_id)
6544
6582
  `.execute(db);
6545
6583
  }
6546
- async function down$36(db) {
6584
+ async function down$37(db) {
6547
6585
  await sql`DROP TABLE IF EXISTS public.batch_accumulation_items`.execute(db);
6548
6586
  await sql`DROP TABLE IF EXISTS public.batch_accumulation_windows`.execute(db);
6549
6587
  }
6550
6588
  //#endregion
6551
6589
  //#region src/db/migrations/072_dispatch_queue_run_id_index.ts
6552
6590
  var _072_dispatch_queue_run_id_index_exports = /* @__PURE__ */ __exportAll({
6553
- down: () => down$35,
6554
- up: () => up$35
6591
+ down: () => down$36,
6592
+ up: () => up$36
6555
6593
  });
6556
6594
  /**
6557
6595
  * Add `idx_dispatch_queue_run_id` on `dispatch_queue (run_id)`.
@@ -6564,20 +6602,20 @@ var _072_dispatch_queue_run_id_index_exports = /* @__PURE__ */ __exportAll({
6564
6602
  *
6565
6603
  * Idempotent: `IF NOT EXISTS` makes a re-run a no-op.
6566
6604
  */
6567
- async function up$35(db) {
6605
+ async function up$36(db) {
6568
6606
  await sql`
6569
6607
  CREATE INDEX IF NOT EXISTS idx_dispatch_queue_run_id
6570
6608
  ON public.dispatch_queue (run_id)
6571
6609
  `.execute(db);
6572
6610
  }
6573
- async function down$35(db) {
6611
+ async function down$36(db) {
6574
6612
  await sql`DROP INDEX IF EXISTS public.idx_dispatch_queue_run_id`.execute(db);
6575
6613
  }
6576
6614
  //#endregion
6577
6615
  //#region src/db/migrations/073_org_settings_ingest_concurrency.ts
6578
6616
  var _073_org_settings_ingest_concurrency_exports = /* @__PURE__ */ __exportAll({
6579
- down: () => down$34,
6580
- up: () => up$34
6617
+ down: () => down$35,
6618
+ up: () => up$35
6581
6619
  });
6582
6620
  /**
6583
6621
  * Add `org_settings.ingest_max_concurrency BIGINT` (nullable).
@@ -6588,7 +6626,7 @@ var _073_org_settings_ingest_concurrency_exports = /* @__PURE__ */ __exportAll({
6588
6626
  *
6589
6627
  * Idempotent: a re-run on a DB that already has the column is a no-op.
6590
6628
  */
6591
- async function up$34(db) {
6629
+ async function up$35(db) {
6592
6630
  if ((await sql`
6593
6631
  SELECT EXISTS (
6594
6632
  SELECT 1 FROM information_schema.columns
@@ -6602,7 +6640,7 @@ async function up$34(db) {
6602
6640
  ADD COLUMN ingest_max_concurrency BIGINT
6603
6641
  `.execute(db);
6604
6642
  }
6605
- async function down$34(db) {
6643
+ async function down$35(db) {
6606
6644
  await sql`
6607
6645
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS ingest_max_concurrency
6608
6646
  `.execute(db);
@@ -6610,8 +6648,8 @@ async function down$34(db) {
6610
6648
  //#endregion
6611
6649
  //#region src/db/migrations/074_normalize_zero_concurrency_limit.ts
6612
6650
  var _074_normalize_zero_concurrency_limit_exports = /* @__PURE__ */ __exportAll({
6613
- down: () => down$33,
6614
- up: () => up$33
6651
+ down: () => down$34,
6652
+ up: () => up$34
6615
6653
  });
6616
6654
  /**
6617
6655
  * Normalize degenerate context concurrency limits. A `concurrency_limit` of 0
@@ -6622,15 +6660,15 @@ var _074_normalize_zero_concurrency_limit_exports = /* @__PURE__ */ __exportAll(
6622
6660
  * Idempotent; down() is a no-op (a normalized 0 cannot — and should not — be
6623
6661
  * restored).
6624
6662
  */
6625
- async function up$33(db) {
6663
+ async function up$34(db) {
6626
6664
  await sql`UPDATE public.contexts SET concurrency_limit = NULL WHERE concurrency_limit <= 0`.execute(db);
6627
6665
  }
6628
- async function down$33(_db) {}
6666
+ async function down$34(_db) {}
6629
6667
  //#endregion
6630
6668
  //#region src/db/migrations/075_ingest_overflow_buffer.ts
6631
6669
  var _075_ingest_overflow_buffer_exports = /* @__PURE__ */ __exportAll({
6632
- down: () => down$32,
6633
- up: () => up$32
6670
+ down: () => down$33,
6671
+ up: () => up$33
6634
6672
  });
6635
6673
  /**
6636
6674
  * Durable overflow buffer for shed webhook-ingest deliveries.
@@ -6644,7 +6682,7 @@ var _075_ingest_overflow_buffer_exports = /* @__PURE__ */ __exportAll({
6644
6682
  *
6645
6683
  * Idempotent: a re-run on a DB that already has the table is a no-op.
6646
6684
  */
6647
- async function up$32(db) {
6685
+ async function up$33(db) {
6648
6686
  if ((await sql`
6649
6687
  SELECT EXISTS (
6650
6688
  SELECT 1 FROM information_schema.tables
@@ -6677,14 +6715,14 @@ async function up$32(db) {
6677
6715
  ON public.ingest_overflow_buffer (delivery_id)
6678
6716
  `.execute(db);
6679
6717
  }
6680
- async function down$32(db) {
6718
+ async function down$33(db) {
6681
6719
  await sql`DROP TABLE IF EXISTS public.ingest_overflow_buffer`.execute(db);
6682
6720
  }
6683
6721
  //#endregion
6684
6722
  //#region src/db/migrations/076_artifacts.ts
6685
6723
  var _076_artifacts_exports = /* @__PURE__ */ __exportAll({
6686
- down: () => down$31,
6687
- up: () => up$31
6724
+ down: () => down$32,
6725
+ up: () => up$32
6688
6726
  });
6689
6727
  /**
6690
6728
  * Add the `artifacts` table for user-facing build artifacts and the per-org
@@ -6701,7 +6739,7 @@ var _076_artifacts_exports = /* @__PURE__ */ __exportAll({
6701
6739
  *
6702
6740
  * Idempotent: a re-run on a DB that already has the table / columns is a no-op.
6703
6741
  */
6704
- async function up$31(db) {
6742
+ async function up$32(db) {
6705
6743
  if (!(await sql`
6706
6744
  SELECT EXISTS (
6707
6745
  SELECT 1 FROM information_schema.tables
@@ -6737,7 +6775,7 @@ async function up$31(db) {
6737
6775
  ADD COLUMN IF NOT EXISTS artifact_ttl_ms BIGINT
6738
6776
  `.execute(db);
6739
6777
  }
6740
- async function down$31(db) {
6778
+ async function down$32(db) {
6741
6779
  await sql`DROP TABLE IF EXISTS public.artifacts`.execute(db);
6742
6780
  await sql`
6743
6781
  ALTER TABLE public.org_settings
@@ -6748,8 +6786,8 @@ async function down$31(db) {
6748
6786
  //#endregion
6749
6787
  //#region src/db/migrations/077_backup_runs.ts
6750
6788
  var _077_backup_runs_exports = /* @__PURE__ */ __exportAll({
6751
- down: () => down$30,
6752
- up: () => up$30
6789
+ down: () => down$31,
6790
+ up: () => up$31
6753
6791
  });
6754
6792
  /**
6755
6793
  * Add the `backup_runs` table: one row per successful `kici-admin db backup`,
@@ -6760,12 +6798,12 @@ var _077_backup_runs_exports = /* @__PURE__ */ __exportAll({
6760
6798
  *
6761
6799
  * Idempotent: guarded on table existence.
6762
6800
  */
6763
- async function up$30(db) {
6801
+ async function up$31(db) {
6764
6802
  if (await tableExists$2(db, "backup_runs")) return;
6765
6803
  await db.schema.createTable("backup_runs").addColumn("id", "bigserial", (c) => c.primaryKey()).addColumn("created_at", "timestamptz", (c) => c.notNull().defaultTo(sql`now()`)).addColumn("dump_path", "text", (c) => c.notNull()).addColumn("byte_size", "bigint", (c) => c.notNull()).addColumn("secret_key_version", "integer").addColumn("pg_server_version", "text", (c) => c.notNull()).addColumn("migrations_hash", "text", (c) => c.notNull()).addColumn("hostname", "text", (c) => c.notNull()).execute();
6766
6804
  await db.schema.createIndex("idx_backup_runs_created_at").on("backup_runs").column("created_at").execute();
6767
6805
  }
6768
- async function down$30(db) {
6806
+ async function down$31(db) {
6769
6807
  await db.schema.dropTable("backup_runs").ifExists().execute();
6770
6808
  }
6771
6809
  async function tableExists$2(db, table) {
@@ -6779,8 +6817,8 @@ async function tableExists$2(db, table) {
6779
6817
  //#endregion
6780
6818
  //#region src/db/migrations/078_org_settings_backup_staleness.ts
6781
6819
  var _078_org_settings_backup_staleness_exports = /* @__PURE__ */ __exportAll({
6782
- down: () => down$29,
6783
- up: () => up$29
6820
+ down: () => down$30,
6821
+ up: () => up$30
6784
6822
  });
6785
6823
  /**
6786
6824
  * Add the nullable `org_settings.backup_staleness_warn_hours INTEGER` column:
@@ -6790,7 +6828,7 @@ var _078_org_settings_backup_staleness_exports = /* @__PURE__ */ __exportAll({
6790
6828
  *
6791
6829
  * Idempotent: guarded on column existence.
6792
6830
  */
6793
- async function up$29(db) {
6831
+ async function up$30(db) {
6794
6832
  if ((await sql`
6795
6833
  SELECT EXISTS (
6796
6834
  SELECT 1 FROM information_schema.columns
@@ -6804,7 +6842,7 @@ async function up$29(db) {
6804
6842
  ADD COLUMN backup_staleness_warn_hours INTEGER
6805
6843
  `.execute(db);
6806
6844
  }
6807
- async function down$29(db) {
6845
+ async function down$30(db) {
6808
6846
  await sql`
6809
6847
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS backup_staleness_warn_hours
6810
6848
  `.execute(db);
@@ -6812,8 +6850,8 @@ async function down$29(db) {
6812
6850
  //#endregion
6813
6851
  //#region src/db/migrations/079_org_settings_scaler_spawn_timeout.ts
6814
6852
  var _079_org_settings_scaler_spawn_timeout_exports = /* @__PURE__ */ __exportAll({
6815
- down: () => down$28,
6816
- up: () => up$28
6853
+ down: () => down$29,
6854
+ up: () => up$29
6817
6855
  });
6818
6856
  /**
6819
6857
  * Add `org_settings.scaler_spawn_timeout_ms BIGINT` (nullable).
@@ -6825,7 +6863,7 @@ var _079_org_settings_scaler_spawn_timeout_exports = /* @__PURE__ */ __exportAll
6825
6863
  *
6826
6864
  * Idempotent: a re-run on a DB that already has the column is a no-op.
6827
6865
  */
6828
- async function up$28(db) {
6866
+ async function up$29(db) {
6829
6867
  if ((await sql`
6830
6868
  SELECT EXISTS (
6831
6869
  SELECT 1 FROM information_schema.columns
@@ -6839,7 +6877,7 @@ async function up$28(db) {
6839
6877
  ADD COLUMN scaler_spawn_timeout_ms BIGINT
6840
6878
  `.execute(db);
6841
6879
  }
6842
- async function down$28(db) {
6880
+ async function down$29(db) {
6843
6881
  await sql`
6844
6882
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS scaler_spawn_timeout_ms
6845
6883
  `.execute(db);
@@ -6847,8 +6885,8 @@ async function down$28(db) {
6847
6885
  //#endregion
6848
6886
  //#region src/db/migrations/080_cluster_settings.ts
6849
6887
  var _080_cluster_settings_exports = /* @__PURE__ */ __exportAll({
6850
- down: () => down$27,
6851
- up: () => up$27
6888
+ down: () => down$28,
6889
+ up: () => up$28
6852
6890
  });
6853
6891
  /**
6854
6892
  * Create `cluster_settings`: a single-row (id='default') table of fleet-wide
@@ -6863,7 +6901,7 @@ var _080_cluster_settings_exports = /* @__PURE__ */ __exportAll({
6863
6901
  *
6864
6902
  * Idempotent: a re-run on a DB that already has the table is a no-op.
6865
6903
  */
6866
- async function up$27(db) {
6904
+ async function up$28(db) {
6867
6905
  if ((await sql`
6868
6906
  SELECT EXISTS (
6869
6907
  SELECT 1 FROM information_schema.tables
@@ -6887,14 +6925,14 @@ async function up$27(db) {
6887
6925
  )
6888
6926
  `.execute(db);
6889
6927
  }
6890
- async function down$27(db) {
6928
+ async function down$28(db) {
6891
6929
  await sql`DROP TABLE IF EXISTS public.cluster_settings`.execute(db);
6892
6930
  }
6893
6931
  //#endregion
6894
6932
  //#region src/db/migrations/081_org_settings_queue_timeout.ts
6895
6933
  var _081_org_settings_queue_timeout_exports = /* @__PURE__ */ __exportAll({
6896
- down: () => down$26,
6897
- up: () => up$26
6934
+ down: () => down$27,
6935
+ up: () => up$27
6898
6936
  });
6899
6937
  /**
6900
6938
  * Add `org_settings.queue_timeout_ms BIGINT` (nullable).
@@ -6911,7 +6949,7 @@ var _081_org_settings_queue_timeout_exports = /* @__PURE__ */ __exportAll({
6911
6949
  *
6912
6950
  * Idempotent: a re-run on a DB that already has the column is a no-op.
6913
6951
  */
6914
- async function up$26(db) {
6952
+ async function up$27(db) {
6915
6953
  if ((await sql`
6916
6954
  SELECT EXISTS (
6917
6955
  SELECT 1 FROM information_schema.columns
@@ -6925,7 +6963,7 @@ async function up$26(db) {
6925
6963
  ADD COLUMN queue_timeout_ms BIGINT
6926
6964
  `.execute(db);
6927
6965
  }
6928
- async function down$26(db) {
6966
+ async function down$27(db) {
6929
6967
  await sql`
6930
6968
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS queue_timeout_ms
6931
6969
  `.execute(db);
@@ -6933,8 +6971,8 @@ async function down$26(db) {
6933
6971
  //#endregion
6934
6972
  //#region src/db/migrations/082_host_s3_reachable.ts
6935
6973
  var _082_host_s3_reachable_exports = /* @__PURE__ */ __exportAll({
6936
- down: () => down$25,
6937
- up: () => up$25
6974
+ down: () => down$26,
6975
+ up: () => up$26
6938
6976
  });
6939
6977
  /**
6940
6978
  * Add `host_roster.s3_reachable BOOLEAN` (nullable).
@@ -6948,7 +6986,7 @@ var _082_host_s3_reachable_exports = /* @__PURE__ */ __exportAll({
6948
6986
  *
6949
6987
  * Idempotent: a re-run on a DB that already has the column is a no-op.
6950
6988
  */
6951
- async function up$25(db) {
6989
+ async function up$26(db) {
6952
6990
  if ((await sql`
6953
6991
  SELECT EXISTS (
6954
6992
  SELECT 1 FROM information_schema.columns
@@ -6962,7 +7000,7 @@ async function up$25(db) {
6962
7000
  ADD COLUMN s3_reachable BOOLEAN
6963
7001
  `.execute(db);
6964
7002
  }
6965
- async function down$25(db) {
7003
+ async function down$26(db) {
6966
7004
  await sql`
6967
7005
  ALTER TABLE public.host_roster DROP COLUMN IF EXISTS s3_reachable
6968
7006
  `.execute(db);
@@ -6970,8 +7008,8 @@ async function down$25(db) {
6970
7008
  //#endregion
6971
7009
  //#region src/db/migrations/083_org_settings_artifact_caps.ts
6972
7010
  var _083_org_settings_artifact_caps_exports = /* @__PURE__ */ __exportAll({
6973
- down: () => down$24,
6974
- up: () => up$24
7011
+ down: () => down$25,
7012
+ up: () => up$25
6975
7013
  });
6976
7014
  /**
6977
7015
  * Add `org_settings.artifact_max_bytes` + `artifact_max_per_run` (both nullable
@@ -6987,7 +7025,7 @@ var _083_org_settings_artifact_caps_exports = /* @__PURE__ */ __exportAll({
6987
7025
  * Idempotent: guarded on column existence; a re-run on a DB that already has a
6988
7026
  * column is a no-op.
6989
7027
  */
6990
- async function up$24(db) {
7028
+ async function up$25(db) {
6991
7029
  for (const col of ["artifact_max_bytes", "artifact_max_per_run"]) {
6992
7030
  if ((await sql`
6993
7031
  SELECT EXISTS (
@@ -7000,15 +7038,15 @@ async function up$24(db) {
7000
7038
  await sql`ALTER TABLE public.org_settings ADD COLUMN ${sql.ref(col)} BIGINT`.execute(db);
7001
7039
  }
7002
7040
  }
7003
- async function down$24(db) {
7041
+ async function down$25(db) {
7004
7042
  await sql`ALTER TABLE public.org_settings DROP COLUMN IF EXISTS artifact_max_bytes`.execute(db);
7005
7043
  await sql`ALTER TABLE public.org_settings DROP COLUMN IF EXISTS artifact_max_per_run`.execute(db);
7006
7044
  }
7007
7045
  //#endregion
7008
7046
  //#region src/db/migrations/084_orchestrator_signing_keys.ts
7009
7047
  var _084_orchestrator_signing_keys_exports = /* @__PURE__ */ __exportAll({
7010
- down: () => down$23,
7011
- up: () => up$23
7048
+ down: () => down$24,
7049
+ up: () => up$24
7012
7050
  });
7013
7051
  /**
7014
7052
  * Add the `orchestrator_signing_keys` table: the cluster-scoped, long-lived
@@ -7026,12 +7064,12 @@ var _084_orchestrator_signing_keys_exports = /* @__PURE__ */ __exportAll({
7026
7064
  *
7027
7065
  * Idempotent: guarded on table existence.
7028
7066
  */
7029
- async function up$23(db) {
7067
+ async function up$24(db) {
7030
7068
  if (await tableExists$1(db, "orchestrator_signing_keys")) return;
7031
7069
  await db.schema.createTable("orchestrator_signing_keys").addColumn("kid", "text", (c) => c.primaryKey()).addColumn("public_jwk", "jsonb", (c) => c.notNull()).addColumn("encrypted_private_jwk", "text").addColumn("key_version", "integer", (c) => c.notNull().defaultTo(1)).addColumn("alg", "text", (c) => c.notNull()).addColumn("signer_kind", "text", (c) => c.notNull()).addColumn("key_ref", "text").addColumn("status", "text", (c) => c.notNull().defaultTo("active")).addColumn("revocation_reason", "text").addColumn("created_at", "timestamptz", (c) => c.notNull().defaultTo(sql`now()`)).addColumn("activated_at", "timestamptz").addColumn("retired_at", "timestamptz").addColumn("revoked_at", "timestamptz").execute();
7032
7070
  await db.schema.createIndex("idx_orch_signing_keys_status").on("orchestrator_signing_keys").column("status").execute();
7033
7071
  }
7034
- async function down$23(db) {
7072
+ async function down$24(db) {
7035
7073
  await db.schema.dropTable("orchestrator_signing_keys").ifExists().execute();
7036
7074
  }
7037
7075
  async function tableExists$1(db, table) {
@@ -7045,8 +7083,8 @@ async function tableExists$1(db, table) {
7045
7083
  //#endregion
7046
7084
  //#region src/db/migrations/085_cluster_settings_reroute_flap_grace_ms.ts
7047
7085
  var _085_cluster_settings_reroute_flap_grace_ms_exports = /* @__PURE__ */ __exportAll({
7048
- down: () => down$22,
7049
- up: () => up$22
7086
+ down: () => down$23,
7087
+ up: () => up$23
7050
7088
  });
7051
7089
  /**
7052
7090
  * Add `cluster_settings.reroute_flap_grace_ms` (nullable BIGINT).
@@ -7056,7 +7094,7 @@ var _085_cluster_settings_reroute_flap_grace_ms_exports = /* @__PURE__ */ __expo
7056
7094
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7057
7095
  * the column is a no-op.
7058
7096
  */
7059
- async function up$22(db) {
7097
+ async function up$23(db) {
7060
7098
  if ((await sql`
7061
7099
  SELECT EXISTS (
7062
7100
  SELECT 1 FROM information_schema.columns
@@ -7067,14 +7105,14 @@ async function up$22(db) {
7067
7105
  `.execute(db)).rows[0]?.exists) return;
7068
7106
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN reroute_flap_grace_ms BIGINT`.execute(db);
7069
7107
  }
7070
- async function down$22(db) {
7108
+ async function down$23(db) {
7071
7109
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS reroute_flap_grace_ms`.execute(db);
7072
7110
  }
7073
7111
  //#endregion
7074
7112
  //#region src/db/migrations/086_cluster_settings_max_fanout_hosts.ts
7075
7113
  var _086_cluster_settings_max_fanout_hosts_exports = /* @__PURE__ */ __exportAll({
7076
- down: () => down$21,
7077
- up: () => up$21
7114
+ down: () => down$22,
7115
+ up: () => up$22
7078
7116
  });
7079
7117
  /**
7080
7118
  * Add `cluster_settings.max_fanout_hosts` (nullable INTEGER).
@@ -7084,7 +7122,7 @@ var _086_cluster_settings_max_fanout_hosts_exports = /* @__PURE__ */ __exportAll
7084
7122
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7085
7123
  * the column is a no-op.
7086
7124
  */
7087
- async function up$21(db) {
7125
+ async function up$22(db) {
7088
7126
  if ((await sql`
7089
7127
  SELECT EXISTS (
7090
7128
  SELECT 1 FROM information_schema.columns
@@ -7095,14 +7133,14 @@ async function up$21(db) {
7095
7133
  `.execute(db)).rows[0]?.exists) return;
7096
7134
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN max_fanout_hosts INTEGER`.execute(db);
7097
7135
  }
7098
- async function down$21(db) {
7136
+ async function down$22(db) {
7099
7137
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS max_fanout_hosts`.execute(db);
7100
7138
  }
7101
7139
  //#endregion
7102
7140
  //#region src/db/migrations/087_cluster_settings_event_router_rate_limit.ts
7103
7141
  var _087_cluster_settings_event_router_rate_limit_exports = /* @__PURE__ */ __exportAll({
7104
- down: () => down$20,
7105
- up: () => up$20
7142
+ down: () => down$21,
7143
+ up: () => up$21
7106
7144
  });
7107
7145
  /**
7108
7146
  * Add `cluster_settings.event_router_rate_limit_per_workflow_per_minute` (nullable INTEGER).
@@ -7112,7 +7150,7 @@ var _087_cluster_settings_event_router_rate_limit_exports = /* @__PURE__ */ __ex
7112
7150
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7113
7151
  * the column is a no-op.
7114
7152
  */
7115
- async function up$20(db) {
7153
+ async function up$21(db) {
7116
7154
  if ((await sql`
7117
7155
  SELECT EXISTS (
7118
7156
  SELECT 1 FROM information_schema.columns
@@ -7123,14 +7161,14 @@ async function up$20(db) {
7123
7161
  `.execute(db)).rows[0]?.exists) return;
7124
7162
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN event_router_rate_limit_per_workflow_per_minute INTEGER`.execute(db);
7125
7163
  }
7126
- async function down$20(db) {
7164
+ async function down$21(db) {
7127
7165
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS event_router_rate_limit_per_workflow_per_minute`.execute(db);
7128
7166
  }
7129
7167
  //#endregion
7130
7168
  //#region src/db/migrations/088_cluster_settings_cache_max_tarball_bytes.ts
7131
7169
  var _088_cluster_settings_cache_max_tarball_bytes_exports = /* @__PURE__ */ __exportAll({
7132
- down: () => down$19,
7133
- up: () => up$19
7170
+ down: () => down$20,
7171
+ up: () => up$20
7134
7172
  });
7135
7173
  /**
7136
7174
  * Add `cluster_settings.cache_max_tarball_bytes` (nullable BIGINT).
@@ -7140,7 +7178,7 @@ var _088_cluster_settings_cache_max_tarball_bytes_exports = /* @__PURE__ */ __ex
7140
7178
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7141
7179
  * the column is a no-op.
7142
7180
  */
7143
- async function up$19(db) {
7181
+ async function up$20(db) {
7144
7182
  if ((await sql`
7145
7183
  SELECT EXISTS (
7146
7184
  SELECT 1 FROM information_schema.columns
@@ -7151,14 +7189,14 @@ async function up$19(db) {
7151
7189
  `.execute(db)).rows[0]?.exists) return;
7152
7190
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN cache_max_tarball_bytes BIGINT`.execute(db);
7153
7191
  }
7154
- async function down$19(db) {
7192
+ async function down$20(db) {
7155
7193
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS cache_max_tarball_bytes`.execute(db);
7156
7194
  }
7157
7195
  //#endregion
7158
7196
  //#region src/db/migrations/089_cluster_settings_cache_ttl_days.ts
7159
7197
  var _089_cluster_settings_cache_ttl_days_exports = /* @__PURE__ */ __exportAll({
7160
- down: () => down$18,
7161
- up: () => up$18
7198
+ down: () => down$19,
7199
+ up: () => up$19
7162
7200
  });
7163
7201
  /**
7164
7202
  * Add `cluster_settings.cache_ttl_days` (nullable INTEGER).
@@ -7168,7 +7206,7 @@ var _089_cluster_settings_cache_ttl_days_exports = /* @__PURE__ */ __exportAll({
7168
7206
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7169
7207
  * the column is a no-op.
7170
7208
  */
7171
- async function up$18(db) {
7209
+ async function up$19(db) {
7172
7210
  if ((await sql`
7173
7211
  SELECT EXISTS (
7174
7212
  SELECT 1 FROM information_schema.columns
@@ -7179,14 +7217,14 @@ async function up$18(db) {
7179
7217
  `.execute(db)).rows[0]?.exists) return;
7180
7218
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN cache_ttl_days INTEGER`.execute(db);
7181
7219
  }
7182
- async function down$18(db) {
7220
+ async function down$19(db) {
7183
7221
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS cache_ttl_days`.execute(db);
7184
7222
  }
7185
7223
  //#endregion
7186
7224
  //#region src/db/migrations/090_cluster_settings_concurrency_wait_timeout_ms.ts
7187
7225
  var _090_cluster_settings_concurrency_wait_timeout_ms_exports = /* @__PURE__ */ __exportAll({
7188
- down: () => down$17,
7189
- up: () => up$17
7226
+ down: () => down$18,
7227
+ up: () => up$18
7190
7228
  });
7191
7229
  /**
7192
7230
  * Add `cluster_settings.concurrency_wait_timeout_ms` (nullable BIGINT).
@@ -7196,7 +7234,7 @@ var _090_cluster_settings_concurrency_wait_timeout_ms_exports = /* @__PURE__ */
7196
7234
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7197
7235
  * the column is a no-op.
7198
7236
  */
7199
- async function up$17(db) {
7237
+ async function up$18(db) {
7200
7238
  if ((await sql`
7201
7239
  SELECT EXISTS (
7202
7240
  SELECT 1 FROM information_schema.columns
@@ -7207,14 +7245,14 @@ async function up$17(db) {
7207
7245
  `.execute(db)).rows[0]?.exists) return;
7208
7246
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN concurrency_wait_timeout_ms BIGINT`.execute(db);
7209
7247
  }
7210
- async function down$17(db) {
7248
+ async function down$18(db) {
7211
7249
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS concurrency_wait_timeout_ms`.execute(db);
7212
7250
  }
7213
7251
  //#endregion
7214
7252
  //#region src/db/migrations/091_cluster_settings_agent_token_ttl_ms.ts
7215
7253
  var _091_cluster_settings_agent_token_ttl_ms_exports = /* @__PURE__ */ __exportAll({
7216
- down: () => down$16,
7217
- up: () => up$16
7254
+ down: () => down$17,
7255
+ up: () => up$17
7218
7256
  });
7219
7257
  /**
7220
7258
  * Add `cluster_settings.agent_token_ttl_ms` (nullable BIGINT).
@@ -7224,7 +7262,7 @@ var _091_cluster_settings_agent_token_ttl_ms_exports = /* @__PURE__ */ __exportA
7224
7262
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7225
7263
  * the column is a no-op.
7226
7264
  */
7227
- async function up$16(db) {
7265
+ async function up$17(db) {
7228
7266
  if ((await sql`
7229
7267
  SELECT EXISTS (
7230
7268
  SELECT 1 FROM information_schema.columns
@@ -7235,14 +7273,14 @@ async function up$16(db) {
7235
7273
  `.execute(db)).rows[0]?.exists) return;
7236
7274
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN agent_token_ttl_ms BIGINT`.execute(db);
7237
7275
  }
7238
- async function down$16(db) {
7276
+ async function down$17(db) {
7239
7277
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS agent_token_ttl_ms`.execute(db);
7240
7278
  }
7241
7279
  //#endregion
7242
7280
  //#region src/db/migrations/092_cluster_settings_version.ts
7243
7281
  var _092_cluster_settings_version_exports = /* @__PURE__ */ __exportAll({
7244
- down: () => down$15,
7245
- up: () => up$15
7282
+ down: () => down$16,
7283
+ up: () => up$16
7246
7284
  });
7247
7285
  /**
7248
7286
  * Add `cluster_settings.version` (monotonic BIGINT, bumped on each settings
@@ -7256,7 +7294,7 @@ var _092_cluster_settings_version_exports = /* @__PURE__ */ __exportAll({
7256
7294
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7257
7295
  * the column is a no-op.
7258
7296
  */
7259
- async function up$15(db) {
7297
+ async function up$16(db) {
7260
7298
  if ((await sql`
7261
7299
  SELECT EXISTS (
7262
7300
  SELECT 1 FROM information_schema.columns
@@ -7267,14 +7305,14 @@ async function up$15(db) {
7267
7305
  `.execute(db)).rows[0]?.exists) return;
7268
7306
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN version BIGINT NOT NULL DEFAULT 0`.execute(db);
7269
7307
  }
7270
- async function down$15(db) {
7308
+ async function down$16(db) {
7271
7309
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS version`.execute(db);
7272
7310
  }
7273
7311
  //#endregion
7274
7312
  //#region src/db/migrations/093_org_settings_sandbox_allowlist.ts
7275
7313
  var _093_org_settings_sandbox_allowlist_exports = /* @__PURE__ */ __exportAll({
7276
- down: () => down$14,
7277
- up: () => up$14
7314
+ down: () => down$15,
7315
+ up: () => up$15
7278
7316
  });
7279
7317
  /**
7280
7318
  * Add the per-org container-sandbox escape-hatch allow-list to `org_settings`:
@@ -7292,7 +7330,7 @@ var _093_org_settings_sandbox_allowlist_exports = /* @__PURE__ */ __exportAll({
7292
7330
  *
7293
7331
  * Idempotent: a re-run on a DB that already has a column skips that column.
7294
7332
  */
7295
- async function columnExists$3(db, column) {
7333
+ async function columnExists$4(db, column) {
7296
7334
  return (await sql`
7297
7335
  SELECT EXISTS (
7298
7336
  SELECT 1 FROM information_schema.columns
@@ -7302,17 +7340,17 @@ async function columnExists$3(db, column) {
7302
7340
  ) AS exists
7303
7341
  `.execute(db)).rows[0]?.exists ?? false;
7304
7342
  }
7305
- async function up$14(db) {
7306
- if (!await columnExists$3(db, "sandbox_allowed_capabilities")) await sql`
7343
+ async function up$15(db) {
7344
+ if (!await columnExists$4(db, "sandbox_allowed_capabilities")) await sql`
7307
7345
  ALTER TABLE public.org_settings
7308
7346
  ADD COLUMN sandbox_allowed_capabilities TEXT[]
7309
7347
  `.execute(db);
7310
- if (!await columnExists$3(db, "sandbox_allow_host_network")) await sql`
7348
+ if (!await columnExists$4(db, "sandbox_allow_host_network")) await sql`
7311
7349
  ALTER TABLE public.org_settings
7312
7350
  ADD COLUMN sandbox_allow_host_network BOOLEAN
7313
7351
  `.execute(db);
7314
7352
  }
7315
- async function down$14(db) {
7353
+ async function down$15(db) {
7316
7354
  await sql`
7317
7355
  ALTER TABLE public.org_settings DROP COLUMN IF EXISTS sandbox_allowed_capabilities
7318
7356
  `.execute(db);
@@ -7323,8 +7361,8 @@ async function down$14(db) {
7323
7361
  //#endregion
7324
7362
  //#region src/db/migrations/094_dashboard_encryption_keys.ts
7325
7363
  var _094_dashboard_encryption_keys_exports = /* @__PURE__ */ __exportAll({
7326
- down: () => down$13,
7327
- up: () => up$13
7364
+ down: () => down$14,
7365
+ up: () => up$14
7328
7366
  });
7329
7367
  /**
7330
7368
  * Add the `dashboard_encryption_keys` table: the cluster-scoped, long-lived
@@ -7343,12 +7381,12 @@ var _094_dashboard_encryption_keys_exports = /* @__PURE__ */ __exportAll({
7343
7381
  *
7344
7382
  * Idempotent: guarded on table existence.
7345
7383
  */
7346
- async function up$13(db) {
7384
+ async function up$14(db) {
7347
7385
  if (await tableExists(db, "dashboard_encryption_keys")) return;
7348
7386
  await db.schema.createTable("dashboard_encryption_keys").addColumn("kid", "text", (c) => c.primaryKey()).addColumn("public_jwk", "jsonb", (c) => c.notNull()).addColumn("encrypted_private_key", "text", (c) => c.notNull()).addColumn("status", "text", (c) => c.notNull().defaultTo("active")).addColumn("revocation_reason", "text").addColumn("created_at", "timestamptz", (c) => c.notNull().defaultTo(sql`now()`)).addColumn("activated_at", "timestamptz").addColumn("revoked_at", "timestamptz").execute();
7349
7387
  await db.schema.createIndex("idx_dashboard_encryption_keys_status").on("dashboard_encryption_keys").column("status").execute();
7350
7388
  }
7351
- async function down$13(db) {
7389
+ async function down$14(db) {
7352
7390
  await db.schema.dropTable("dashboard_encryption_keys").ifExists().execute();
7353
7391
  }
7354
7392
  async function tableExists(db, table) {
@@ -7362,8 +7400,8 @@ async function tableExists(db, table) {
7362
7400
  //#endregion
7363
7401
  //#region src/db/migrations/095_dashboard_write_policy_tristate.ts
7364
7402
  var _095_dashboard_write_policy_tristate_exports = /* @__PURE__ */ __exportAll({
7365
- down: () => down$12,
7366
- up: () => up$12
7403
+ down: () => down$13,
7404
+ up: () => up$13
7367
7405
  });
7368
7406
  /**
7369
7407
  * Migrate stored `org_settings.dashboard_write_policy` JSONB from the legacy
@@ -7381,7 +7419,7 @@ var _095_dashboard_write_policy_tristate_exports = /* @__PURE__ */ __exportAll({
7381
7419
  * Pure SQL rewrite: for each row, rebuild the object keeping only non-`true`
7382
7420
  * entries and mapping `false` → `'disabled'`, leaving existing string values.
7383
7421
  */
7384
- async function up$12(db) {
7422
+ async function up$13(db) {
7385
7423
  await sql`
7386
7424
  UPDATE org_settings
7387
7425
  SET dashboard_write_policy = COALESCE(
@@ -7408,12 +7446,12 @@ async function up$12(db) {
7408
7446
  )
7409
7447
  `.execute(db);
7410
7448
  }
7411
- async function down$12() {}
7449
+ async function down$13() {}
7412
7450
  //#endregion
7413
7451
  //#region src/db/migrations/096_multi_schedule_cron_last_fired.ts
7414
7452
  var _096_multi_schedule_cron_last_fired_exports = /* @__PURE__ */ __exportAll({
7415
- down: () => down$11,
7416
- up: () => up$11
7453
+ down: () => down$12,
7454
+ up: () => up$12
7417
7455
  });
7418
7456
  /**
7419
7457
  * Track cron last-fired per (registration, schedule) instead of per
@@ -7428,7 +7466,7 @@ var _096_multi_schedule_cron_last_fired_exports = /* @__PURE__ */ __exportAll({
7428
7466
  *
7429
7467
  * Idempotent: re-running on an already-migrated DB skips each step.
7430
7468
  */
7431
- async function columnExists$2(db, column) {
7469
+ async function columnExists$3(db, column) {
7432
7470
  return (await sql`
7433
7471
  SELECT EXISTS (
7434
7472
  SELECT 1 FROM information_schema.columns
@@ -7448,8 +7486,8 @@ async function primaryKeyColumns(db) {
7448
7486
  ORDER BY a.attnum
7449
7487
  `.execute(db)).rows.map((row) => row.attname);
7450
7488
  }
7451
- async function up$11(db) {
7452
- if (!await columnExists$2(db, "schedule_key")) await sql`ALTER TABLE public.cron_last_fired ADD COLUMN schedule_key text`.execute(db);
7489
+ async function up$12(db) {
7490
+ if (!await columnExists$3(db, "schedule_key")) await sql`ALTER TABLE public.cron_last_fired ADD COLUMN schedule_key text`.execute(db);
7453
7491
  await sql`
7454
7492
  UPDATE public.cron_last_fired clf
7455
7493
  SET schedule_key = k.key
@@ -7475,7 +7513,7 @@ async function up$11(db) {
7475
7513
  `.execute(db);
7476
7514
  }
7477
7515
  }
7478
- async function down$11(db) {
7516
+ async function down$12(db) {
7479
7517
  await sql`
7480
7518
  DELETE FROM public.cron_last_fired a
7481
7519
  USING public.cron_last_fired b
@@ -7487,13 +7525,13 @@ async function down$11(db) {
7487
7525
  ALTER TABLE public.cron_last_fired
7488
7526
  ADD CONSTRAINT cron_last_fired_pkey PRIMARY KEY (registration_id)
7489
7527
  `.execute(db);
7490
- if (await columnExists$2(db, "schedule_key")) await sql`ALTER TABLE public.cron_last_fired DROP COLUMN schedule_key`.execute(db);
7528
+ if (await columnExists$3(db, "schedule_key")) await sql`ALTER TABLE public.cron_last_fired DROP COLUMN schedule_key`.execute(db);
7491
7529
  }
7492
7530
  //#endregion
7493
7531
  //#region src/db/migrations/097_execution_runs_pr_number.ts
7494
7532
  var _097_execution_runs_pr_number_exports = /* @__PURE__ */ __exportAll({
7495
- down: () => down$10,
7496
- up: () => up$10
7533
+ down: () => down$11,
7534
+ up: () => up$11
7497
7535
  });
7498
7536
  /**
7499
7537
  * Add `pr_number INTEGER NULL` to `execution_runs`.
@@ -7506,7 +7544,7 @@ var _097_execution_runs_pr_number_exports = /* @__PURE__ */ __exportAll({
7506
7544
  *
7507
7545
  * Idempotent: a re-run on a DB that already has the column is a no-op.
7508
7546
  */
7509
- async function columnExists$1(db, column) {
7547
+ async function columnExists$2(db, column) {
7510
7548
  return (await sql`
7511
7549
  SELECT EXISTS (
7512
7550
  SELECT 1 FROM information_schema.columns
@@ -7516,13 +7554,13 @@ async function columnExists$1(db, column) {
7516
7554
  ) AS exists
7517
7555
  `.execute(db)).rows[0]?.exists ?? false;
7518
7556
  }
7519
- async function up$10(db) {
7520
- if (!await columnExists$1(db, "pr_number")) await sql`
7557
+ async function up$11(db) {
7558
+ if (!await columnExists$2(db, "pr_number")) await sql`
7521
7559
  ALTER TABLE public.execution_runs
7522
7560
  ADD COLUMN pr_number INTEGER
7523
7561
  `.execute(db);
7524
7562
  }
7525
- async function down$10(db) {
7563
+ async function down$11(db) {
7526
7564
  await sql`
7527
7565
  ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS pr_number
7528
7566
  `.execute(db);
@@ -7530,8 +7568,8 @@ async function down$10(db) {
7530
7568
  //#endregion
7531
7569
  //#region src/db/migrations/098_execution_runs_customer_id.ts
7532
7570
  var _098_execution_runs_customer_id_exports = /* @__PURE__ */ __exportAll({
7533
- down: () => down$9,
7534
- up: () => up$9
7571
+ down: () => down$10,
7572
+ up: () => up$10
7535
7573
  });
7536
7574
  /**
7537
7575
  * Denormalize the owning org onto `execution_runs` so the concurrency-gate
@@ -7549,7 +7587,7 @@ var _098_execution_runs_customer_id_exports = /* @__PURE__ */ __exportAll({
7549
7587
  *
7550
7588
  * Idempotent: re-running skips the column when it already exists.
7551
7589
  */
7552
- async function columnExists(db, column) {
7590
+ async function columnExists$1(db, column) {
7553
7591
  return (await sql`
7554
7592
  SELECT EXISTS (
7555
7593
  SELECT 1 FROM information_schema.columns
@@ -7559,8 +7597,8 @@ async function columnExists(db, column) {
7559
7597
  ) AS exists
7560
7598
  `.execute(db)).rows[0]?.exists ?? false;
7561
7599
  }
7562
- async function up$9(db) {
7563
- if (!await columnExists(db, "customer_id")) {
7600
+ async function up$10(db) {
7601
+ if (!await columnExists$1(db, "customer_id")) {
7564
7602
  await sql`
7565
7603
  ALTER TABLE public.execution_runs
7566
7604
  ADD COLUMN customer_id TEXT NOT NULL DEFAULT '__default__'
@@ -7583,7 +7621,7 @@ async function up$9(db) {
7583
7621
  ON public.execution_runs (customer_id, context)
7584
7622
  `.execute(db);
7585
7623
  }
7586
- async function down$9(db) {
7624
+ async function down$10(db) {
7587
7625
  await sql`DROP INDEX IF EXISTS execution_runs_customer_id_context_idx`.execute(db);
7588
7626
  await sql`
7589
7627
  ALTER TABLE public.execution_runs DROP COLUMN IF EXISTS customer_id
@@ -7592,8 +7630,8 @@ async function down$9(db) {
7592
7630
  //#endregion
7593
7631
  //#region src/db/migrations/099_cluster_settings_dashboard_verified_issuer.ts
7594
7632
  var _099_cluster_settings_dashboard_verified_issuer_exports = /* @__PURE__ */ __exportAll({
7595
- down: () => down$8,
7596
- up: () => up$8
7633
+ down: () => down$9,
7634
+ up: () => up$9
7597
7635
  });
7598
7636
  /**
7599
7637
  * Add `cluster_settings.dashboard_verified_issuer` (nullable text).
@@ -7612,7 +7650,7 @@ var _099_cluster_settings_dashboard_verified_issuer_exports = /* @__PURE__ */ __
7612
7650
  * Idempotent: guarded on column existence; a re-run on a DB that already has the
7613
7651
  * column is a no-op.
7614
7652
  */
7615
- async function up$8(db) {
7653
+ async function up$9(db) {
7616
7654
  if ((await sql`
7617
7655
  SELECT EXISTS (
7618
7656
  SELECT 1 FROM information_schema.columns
@@ -7623,14 +7661,14 @@ async function up$8(db) {
7623
7661
  `.execute(db)).rows[0]?.exists) return;
7624
7662
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN dashboard_verified_issuer TEXT`.execute(db);
7625
7663
  }
7626
- async function down$8(db) {
7664
+ async function down$9(db) {
7627
7665
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS dashboard_verified_issuer`.execute(db);
7628
7666
  }
7629
7667
  //#endregion
7630
7668
  //#region src/db/migrations/100_held_runs_hold_type_vocabulary.ts
7631
7669
  var _100_held_runs_hold_type_vocabulary_exports = /* @__PURE__ */ __exportAll({
7632
- down: () => down$7,
7633
- up: () => up$7
7670
+ down: () => down$8,
7671
+ up: () => up$8
7634
7672
  });
7635
7673
  /**
7636
7674
  * Realign `held_runs.hold_type` onto the engine's `HoldType` vocabulary.
@@ -7649,7 +7687,7 @@ var _100_held_runs_hold_type_vocabulary_exports = /* @__PURE__ */ __exportAll({
7649
7687
  *
7650
7688
  * Idempotent: a second run matches no rows.
7651
7689
  */
7652
- async function up$7(db) {
7690
+ async function up$8(db) {
7653
7691
  await sql`UPDATE public.held_runs SET hold_type = 'reviewer' WHERE hold_type = 'approval'`.execute(db);
7654
7692
  await sql`UPDATE public.held_runs SET hold_type = 'timer' WHERE hold_type = 'wait_timer'`.execute(db);
7655
7693
  }
@@ -7663,15 +7701,15 @@ async function up$7(db) {
7663
7701
  * `wait_timer` alone, so leaving those rows spelled `timer` would strand them
7664
7702
  * in the expire-and-fail path.
7665
7703
  */
7666
- async function down$7(db) {
7704
+ async function down$8(db) {
7667
7705
  await sql`UPDATE public.held_runs SET hold_type = 'approval' WHERE hold_type = 'reviewer'`.execute(db);
7668
7706
  await sql`UPDATE public.held_runs SET hold_type = 'wait_timer' WHERE hold_type = 'timer'`.execute(db);
7669
7707
  }
7670
7708
  //#endregion
7671
7709
  //#region src/db/migrations/101_contexts_hold_expiry_drop_default.ts
7672
7710
  var _101_contexts_hold_expiry_drop_default_exports = /* @__PURE__ */ __exportAll({
7673
- down: () => down$6,
7674
- up: () => up$6
7711
+ down: () => down$7,
7712
+ up: () => up$7
7675
7713
  });
7676
7714
  /**
7677
7715
  * Give the context hold expiry a single default, and retire the stored zeroes.
@@ -7692,7 +7730,7 @@ var _101_contexts_hold_expiry_drop_default_exports = /* @__PURE__ */ __exportAll
7692
7730
  * Idempotent: dropping an absent default is a no-op and the UPDATE matches no
7693
7731
  * rows on a second run.
7694
7732
  */
7695
- async function up$6(db) {
7733
+ async function up$7(db) {
7696
7734
  await sql`ALTER TABLE public.contexts ALTER COLUMN hold_expiry_seconds DROP DEFAULT`.execute(db);
7697
7735
  await sql`UPDATE public.contexts SET hold_expiry_seconds = NULL WHERE hold_expiry_seconds = 0`.execute(db);
7698
7736
  }
@@ -7704,14 +7742,14 @@ async function up$6(db) {
7704
7742
  * back to `0` would resume cancelling every hold on its context — so a
7705
7743
  * rollback keeps them on the fallback rather than re-breaking them.
7706
7744
  */
7707
- async function down$6(db) {
7745
+ async function down$7(db) {
7708
7746
  await sql`ALTER TABLE public.contexts ALTER COLUMN hold_expiry_seconds SET DEFAULT 86400`.execute(db);
7709
7747
  }
7710
7748
  //#endregion
7711
7749
  //#region src/db/migrations/102_dispatch_queue_agent_id.ts
7712
7750
  var _102_dispatch_queue_agent_id_exports = /* @__PURE__ */ __exportAll({
7713
- down: () => down$5,
7714
- up: () => up$5
7751
+ down: () => down$6,
7752
+ up: () => up$6
7715
7753
  });
7716
7754
  /**
7717
7755
  * Add `dispatch_queue.agent_id` (nullable text).
@@ -7729,7 +7767,7 @@ var _102_dispatch_queue_agent_id_exports = /* @__PURE__ */ __exportAll({
7729
7767
  * Idempotent: guarded on column existence; a re-run on a DB that already has the
7730
7768
  * column is a no-op.
7731
7769
  */
7732
- async function up$5(db) {
7770
+ async function up$6(db) {
7733
7771
  if ((await sql`
7734
7772
  SELECT EXISTS (
7735
7773
  SELECT 1 FROM information_schema.columns
@@ -7740,14 +7778,14 @@ async function up$5(db) {
7740
7778
  `.execute(db)).rows[0]?.exists) return;
7741
7779
  await sql`ALTER TABLE public.dispatch_queue ADD COLUMN agent_id TEXT`.execute(db);
7742
7780
  }
7743
- async function down$5(db) {
7781
+ async function down$6(db) {
7744
7782
  await sql`ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS agent_id`.execute(db);
7745
7783
  }
7746
7784
  //#endregion
7747
7785
  //#region src/db/migrations/103_cluster_settings_ownership_db_check_timeout_ms.ts
7748
7786
  var _103_cluster_settings_ownership_db_check_timeout_ms_exports = /* @__PURE__ */ __exportAll({
7749
- down: () => down$4,
7750
- up: () => up$4
7787
+ down: () => down$5,
7788
+ up: () => up$5
7751
7789
  });
7752
7790
  /**
7753
7791
  * Add `cluster_settings.ownership_db_check_timeout_ms` (nullable bigint).
@@ -7765,7 +7803,7 @@ var _103_cluster_settings_ownership_db_check_timeout_ms_exports = /* @__PURE__ *
7765
7803
  * Idempotent: guarded on column existence; a re-run on a DB that already has the
7766
7804
  * column is a no-op.
7767
7805
  */
7768
- async function up$4(db) {
7806
+ async function up$5(db) {
7769
7807
  if ((await sql`
7770
7808
  SELECT EXISTS (
7771
7809
  SELECT 1 FROM information_schema.columns
@@ -7776,14 +7814,14 @@ async function up$4(db) {
7776
7814
  `.execute(db)).rows[0]?.exists) return;
7777
7815
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN ownership_db_check_timeout_ms BIGINT`.execute(db);
7778
7816
  }
7779
- async function down$4(db) {
7817
+ async function down$5(db) {
7780
7818
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS ownership_db_check_timeout_ms`.execute(db);
7781
7819
  }
7782
7820
  //#endregion
7783
7821
  //#region src/db/migrations/104_check_run_terminal_sent.ts
7784
7822
  var _104_check_run_terminal_sent_exports = /* @__PURE__ */ __exportAll({
7785
- down: () => down$3,
7786
- up: () => up$3
7823
+ down: () => down$4,
7824
+ up: () => up$4
7787
7825
  });
7788
7826
  /**
7789
7827
  * Add `check_run_tracking.terminal_sent_at` (nullable timestamptz).
@@ -7803,7 +7841,7 @@ var _104_check_run_terminal_sent_exports = /* @__PURE__ */ __exportAll({
7803
7841
  * Idempotent: guarded on column existence; a re-run on a DB that already has
7804
7842
  * the column is a no-op.
7805
7843
  */
7806
- async function up$3(db) {
7844
+ async function up$4(db) {
7807
7845
  if ((await sql`
7808
7846
  SELECT EXISTS (
7809
7847
  SELECT 1 FROM information_schema.columns
@@ -7814,14 +7852,14 @@ async function up$3(db) {
7814
7852
  `.execute(db)).rows[0]?.exists) return;
7815
7853
  await sql`ALTER TABLE public.check_run_tracking ADD COLUMN terminal_sent_at TIMESTAMPTZ`.execute(db);
7816
7854
  }
7817
- async function down$3(db) {
7855
+ async function down$4(db) {
7818
7856
  await sql`ALTER TABLE public.check_run_tracking DROP COLUMN IF EXISTS terminal_sent_at`.execute(db);
7819
7857
  }
7820
7858
  //#endregion
7821
7859
  //#region src/db/migrations/105_org_trust_policy.ts
7822
7860
  var _105_org_trust_policy_exports = /* @__PURE__ */ __exportAll({
7823
- down: () => down$2,
7824
- up: () => up$2
7861
+ down: () => down$3,
7862
+ up: () => up$3
7825
7863
  });
7826
7864
  /**
7827
7865
  * Create `org_trust_policy` — the orchestrator's cache of the Platform-owned org
@@ -7838,7 +7876,7 @@ var _105_org_trust_policy_exports = /* @__PURE__ */ __exportAll({
7838
7876
  *
7839
7877
  * Idempotent: guarded by IF NOT EXISTS, so a re-run is a no-op.
7840
7878
  */
7841
- async function up$2(db) {
7879
+ async function up$3(db) {
7842
7880
  await sql`
7843
7881
  CREATE TABLE IF NOT EXISTS public.org_trust_policy (
7844
7882
  customer_id TEXT PRIMARY KEY,
@@ -7851,14 +7889,14 @@ async function up$2(db) {
7851
7889
  )
7852
7890
  `.execute(db);
7853
7891
  }
7854
- async function down$2(db) {
7892
+ async function down$3(db) {
7855
7893
  await sql`DROP TABLE IF EXISTS public.org_trust_policy`.execute(db);
7856
7894
  }
7857
7895
  //#endregion
7858
7896
  //#region src/db/migrations/106_cluster_settings_check_run_tracking_ttl_days.ts
7859
7897
  var _106_cluster_settings_check_run_tracking_ttl_days_exports = /* @__PURE__ */ __exportAll({
7860
- down: () => down$1,
7861
- up: () => up$1
7898
+ down: () => down$2,
7899
+ up: () => up$2
7862
7900
  });
7863
7901
  /**
7864
7902
  * Add `cluster_settings.check_run_tracking_ttl_days` (nullable integer).
@@ -7874,7 +7912,7 @@ var _106_cluster_settings_check_run_tracking_ttl_days_exports = /* @__PURE__ */
7874
7912
  * Idempotent: guarded on column existence; a re-run on a database that already
7875
7913
  * has the column is a no-op.
7876
7914
  */
7877
- async function up$1(db) {
7915
+ async function up$2(db) {
7878
7916
  if ((await sql`
7879
7917
  SELECT EXISTS (
7880
7918
  SELECT 1 FROM information_schema.columns
@@ -7885,14 +7923,14 @@ async function up$1(db) {
7885
7923
  `.execute(db)).rows[0]?.exists) return;
7886
7924
  await sql`ALTER TABLE public.cluster_settings ADD COLUMN check_run_tracking_ttl_days INTEGER`.execute(db);
7887
7925
  }
7888
- async function down$1(db) {
7926
+ async function down$2(db) {
7889
7927
  await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS check_run_tracking_ttl_days`.execute(db);
7890
7928
  }
7891
7929
  //#endregion
7892
7930
  //#region src/db/migrations/107_check_run_tracking_updated_at_index.ts
7893
7931
  var _107_check_run_tracking_updated_at_index_exports = /* @__PURE__ */ __exportAll({
7894
- down: () => down,
7895
- up: () => up
7932
+ down: () => down$1,
7933
+ up: () => up$1
7896
7934
  });
7897
7935
  /**
7898
7936
  * Add `idx_check_run_tracking_updated_at` on `check_run_tracking (updated_at)`.
@@ -7913,16 +7951,61 @@ var _107_check_run_tracking_updated_at_index_exports = /* @__PURE__ */ __exportA
7913
7951
  *
7914
7952
  * Idempotent: `IF NOT EXISTS` makes a re-run a no-op.
7915
7953
  */
7916
- async function up(db) {
7954
+ async function up$1(db) {
7917
7955
  await sql`
7918
7956
  CREATE INDEX IF NOT EXISTS idx_check_run_tracking_updated_at
7919
7957
  ON public.check_run_tracking (updated_at)
7920
7958
  `.execute(db);
7921
7959
  }
7922
- async function down(db) {
7960
+ async function down$1(db) {
7923
7961
  await sql`DROP INDEX IF EXISTS public.idx_check_run_tracking_updated_at`.execute(db);
7924
7962
  }
7925
7963
  //#endregion
7964
+ //#region src/db/migrations/108_unroutable_fast_fail.ts
7965
+ var _108_unroutable_fast_fail_exports = /* @__PURE__ */ __exportAll({
7966
+ down: () => down,
7967
+ up: () => up
7968
+ });
7969
+ /**
7970
+ * Fast-fail support for jobs nothing in the fleet can run.
7971
+ *
7972
+ * Three additive, nullable columns:
7973
+ *
7974
+ * - `cluster_settings.unroutable_grace_ms` — how long a job may stay
7975
+ * continuously unroutable before it is terminalized. NULL means the
7976
+ * orchestrator's configured default applies; 0 disables fast-fail and leaves
7977
+ * the `queue_timeout_ms` backstop as the only path.
7978
+ * - `dispatch_queue.unroutable_since` — when the job first read unroutable.
7979
+ * Persisted rather than in-memory so a restart mid-grace resumes the same
7980
+ * clock instead of resetting it; an orchestrator that bounces every 90s must
7981
+ * not be able to keep a genuinely dead job alive forever. Cleared the moment
7982
+ * the job reads routable again.
7983
+ * - `execution_jobs.routing_reason` — the operator-facing reason, visible while
7984
+ * the job is still queued. Cleared on recovery.
7985
+ *
7986
+ * Idempotent: each column is guarded on existence, so a re-run is a no-op.
7987
+ */
7988
+ async function columnExists(db, table, column) {
7989
+ return (await sql`
7990
+ SELECT EXISTS (
7991
+ SELECT 1 FROM information_schema.columns
7992
+ WHERE table_schema = 'public'
7993
+ AND table_name = ${table}
7994
+ AND column_name = ${column}
7995
+ ) AS exists
7996
+ `.execute(db)).rows[0]?.exists === true;
7997
+ }
7998
+ async function up(db) {
7999
+ if (!await columnExists(db, "cluster_settings", "unroutable_grace_ms")) await sql`ALTER TABLE public.cluster_settings ADD COLUMN unroutable_grace_ms INTEGER`.execute(db);
8000
+ if (!await columnExists(db, "dispatch_queue", "unroutable_since")) await sql`ALTER TABLE public.dispatch_queue ADD COLUMN unroutable_since TIMESTAMPTZ`.execute(db);
8001
+ if (!await columnExists(db, "execution_jobs", "routing_reason")) await sql`ALTER TABLE public.execution_jobs ADD COLUMN routing_reason TEXT`.execute(db);
8002
+ }
8003
+ async function down(db) {
8004
+ await sql`ALTER TABLE public.execution_jobs DROP COLUMN IF EXISTS routing_reason`.execute(db);
8005
+ await sql`ALTER TABLE public.dispatch_queue DROP COLUMN IF EXISTS unroutable_since`.execute(db);
8006
+ await sql`ALTER TABLE public.cluster_settings DROP COLUMN IF EXISTS unroutable_grace_ms`.execute(db);
8007
+ }
8008
+ //#endregion
7926
8009
  //#region src/db/migration-provider.ts
7927
8010
  function createMigrationProvider() {
7928
8011
  return { async getMigrations() {
@@ -8033,7 +8116,8 @@ function createMigrationProvider() {
8033
8116
  "104_check_run_terminal_sent": _104_check_run_terminal_sent_exports,
8034
8117
  "105_org_trust_policy": _105_org_trust_policy_exports,
8035
8118
  "106_cluster_settings_check_run_tracking_ttl_days": _106_cluster_settings_check_run_tracking_ttl_days_exports,
8036
- "107_check_run_tracking_updated_at_index": _107_check_run_tracking_updated_at_index_exports
8119
+ "107_check_run_tracking_updated_at_index": _107_check_run_tracking_updated_at_index_exports,
8120
+ "108_unroutable_fast_fail": _108_unroutable_fast_fail_exports
8037
8121
  };
8038
8122
  } };
8039
8123
  }
@@ -11092,6 +11176,11 @@ function registerRunsCommands(program, getClient) {
11092
11176
  String(j.steps?.length ?? 0)
11093
11177
  ]);
11094
11178
  console.log(renderTable$2(jobHeaders, jobRows));
11179
+ const unroutableJobs = jobs.filter((j) => j.routingReason && (j.status === ExecutionJobStatus.enum.pending || j.status === ExecutionJobStatus.enum.queued));
11180
+ if (unroutableJobs.length > 0) {
11181
+ console.log("");
11182
+ for (const job of unroutableJobs) console.log(` ! ${job.jobName}: ${job.routingReason}`);
11183
+ }
11095
11184
  const jobsWithSteps = jobs.filter((j) => (j.steps?.length ?? 0) > 0);
11096
11185
  if (jobsWithSteps.length > 0) for (const job of jobsWithSteps) {
11097
11186
  console.log("");
@@ -11403,6 +11492,12 @@ const baseSchema = z.object({
11403
11492
  queueMaxDepth: z.coerce.number().default(1e3),
11404
11493
  queueTimeoutMs: z.coerce.number().default(36e5),
11405
11494
  /**
11495
+ * Grace a job may stay continuously unroutable (nothing in the fleet matches
11496
+ * its selectors) before it is terminalized. Cluster default; the live value
11497
+ * is the `unroutable_grace_ms` cluster setting. 0 = fast-fail disabled.
11498
+ */
11499
+ unroutableGraceMs: z.coerce.number().default(12e4),
11500
+ /**
11406
11501
  * Operator-facing backpressure warning threshold for the dispatch queue.
11407
11502
  * When pending-queue depth stays at or above this value for at least two
11408
11503
  * consecutive refresher ticks (~10s), the orchestrator emits a
@@ -11758,6 +11853,7 @@ const envDef = defineEnv({
11758
11853
  lockfileCacheMaxBytes: "KICI_LOCKFILE_CACHE_MAX_BYTES",
11759
11854
  queueMaxDepth: "KICI_QUEUE_MAX_DEPTH",
11760
11855
  queueTimeoutMs: "KICI_QUEUE_TIMEOUT_MS",
11856
+ unroutableGraceMs: "KICI_UNROUTABLE_GRACE_MS",
11761
11857
  queueBackpressureThreshold: "KICI_QUEUE_BACKPRESSURE_THRESHOLD",
11762
11858
  workerConcurrency: "KICI_WORKER_CONCURRENCY",
11763
11859
  concurrencyWaitTimeoutMs: "KICI_CONCURRENCY_WAIT_TIMEOUT_MS",
@@ -18306,7 +18402,7 @@ async function refreshAgentPackages(storage, version, opts, deps) {
18306
18402
  const ALL_PLATFORMS = AgentPlatform.options;
18307
18403
  /** The orchestrator's own version (single-version invariant) = the packaged agent version. */
18308
18404
  function resolveKiciVersion() {
18309
- return "0.2.0";
18405
+ return "0.3.0";
18310
18406
  }
18311
18407
  /** Parse the --platform value: default set | single | CSV | `all`. */
18312
18408
  function parsePlatforms(raw) {
@@ -20943,6 +21039,12 @@ const KNOBS$1 = [
20943
21039
  flag: "ownership-db-check-timeout-ms",
20944
21040
  min: 100,
20945
21041
  label: "Ownership DB check timeout (ms)"
21042
+ },
21043
+ {
21044
+ field: "unroutableGraceMs",
21045
+ flag: "unroutable-grace-ms",
21046
+ min: 0,
21047
+ label: "Unroutable fast-fail grace (ms)"
20946
21048
  }
20947
21049
  ];
20948
21050
  /** The cluster-global text knobs. */