@kici-dev/orchestrator 0.0.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -6
  3. package/dist/__test-helpers__/mock-db.d.ts +103 -0
  4. package/dist/__test-helpers__/mock-ws.d.ts +13 -0
  5. package/dist/agent/dispatcher.d.ts +231 -0
  6. package/dist/agent/ownership-tracker.d.ts +46 -0
  7. package/dist/agent/registry.d.ts +255 -0
  8. package/dist/agent/token-store.d.ts +96 -0
  9. package/dist/app.d.ts +234 -0
  10. package/dist/audit/access-log.d.ts +92 -0
  11. package/dist/audit/sampling-rate-limiter.d.ts +41 -0
  12. package/dist/cache/build-coordinator.d.ts +42 -0
  13. package/dist/cache/dep-cache.d.ts +51 -0
  14. package/dist/cache/index.d.ts +16 -0
  15. package/dist/cache/pending-builds.d.ts +14 -0
  16. package/dist/cache/pending-dynamics.d.ts +15 -0
  17. package/dist/cache/pending-inits.d.ts +19 -0
  18. package/dist/cache/pending-tracker.d.ts +65 -0
  19. package/dist/cache/source-cache.d.ts +30 -0
  20. package/dist/cli/api-client.d.ts +411 -0
  21. package/dist/cli/commands/access-log.d.ts +30 -0
  22. package/dist/cli/commands/agent-service/index.d.ts +15 -0
  23. package/dist/cli/commands/agent-service/install.d.ts +9 -0
  24. package/dist/cli/commands/agent-service/logs.d.ts +9 -0
  25. package/dist/cli/commands/agent-service/restart.d.ts +8 -0
  26. package/dist/cli/commands/agent-service/start.d.ts +8 -0
  27. package/dist/cli/commands/agent-service/status.d.ts +10 -0
  28. package/dist/cli/commands/agent-service/stop.d.ts +8 -0
  29. package/dist/cli/commands/agent-service/uninstall.d.ts +9 -0
  30. package/dist/cli/commands/agent-service/upgrade.d.ts +11 -0
  31. package/dist/cli/commands/agent.d.ts +10 -0
  32. package/dist/cli/commands/api-key.d.ts +12 -0
  33. package/dist/cli/commands/audit.d.ts +9 -0
  34. package/dist/cli/commands/backend.d.ts +17 -0
  35. package/dist/cli/commands/cold-store-impl.d.ts +101 -0
  36. package/dist/cli/commands/cold-store.d.ts +30 -0
  37. package/dist/cli/commands/config.d.ts +16 -0
  38. package/dist/cli/commands/db.d.ts +19 -0
  39. package/dist/cli/commands/debug-bundle.d.ts +16 -0
  40. package/dist/cli/commands/diagnose.d.ts +15 -0
  41. package/dist/cli/commands/environment.d.ts +24 -0
  42. package/dist/cli/commands/event-dlq.d.ts +19 -0
  43. package/dist/cli/commands/event-log.d.ts +27 -0
  44. package/dist/cli/commands/event.d.ts +4 -0
  45. package/dist/cli/commands/execution.d.ts +17 -0
  46. package/dist/cli/commands/inspect-bundle.d.ts +16 -0
  47. package/dist/cli/commands/maintenance.d.ts +4 -0
  48. package/dist/cli/commands/orchestrator-service/index.d.ts +12 -0
  49. package/dist/cli/commands/orchestrator-service/install.d.ts +10 -0
  50. package/dist/cli/commands/orchestrator-service/logs.d.ts +10 -0
  51. package/dist/cli/commands/orchestrator-service/restart.d.ts +8 -0
  52. package/dist/cli/commands/orchestrator-service/start.d.ts +8 -0
  53. package/dist/cli/commands/orchestrator-service/status.d.ts +10 -0
  54. package/dist/cli/commands/orchestrator-service/stop.d.ts +8 -0
  55. package/dist/cli/commands/orchestrator-service/uninstall.d.ts +9 -0
  56. package/dist/cli/commands/orchestrator-service/upgrade.d.ts +12 -0
  57. package/dist/cli/commands/org-settings.d.ts +17 -0
  58. package/dist/cli/commands/peer.d.ts +13 -0
  59. package/dist/cli/commands/queue.d.ts +16 -0
  60. package/dist/cli/commands/registration.d.ts +18 -0
  61. package/dist/cli/commands/rotate.d.ts +9 -0
  62. package/dist/cli/commands/runs.d.ts +34 -0
  63. package/dist/cli/commands/secret.d.ts +12 -0
  64. package/dist/cli/commands/shared/db.d.ts +16 -0
  65. package/dist/cli/commands/shared/versioned-upgrade.d.ts +38 -0
  66. package/dist/cli/commands/source.d.ts +24 -0
  67. package/dist/cli/commands/token.d.ts +10 -0
  68. package/dist/cli/commands/workflow.d.ts +31 -0
  69. package/dist/cli/join.d.ts +14 -0
  70. package/dist/cli/kici-admin.d.ts +13 -0
  71. package/dist/cli/lazy-deps/cache.d.ts +17 -0
  72. package/dist/cli/lazy-deps/downloader.d.ts +33 -0
  73. package/dist/cli/lazy-deps/registry.d.ts +43 -0
  74. package/dist/cli/service/compose.d.ts +25 -0
  75. package/dist/cli/service/index.d.ts +24 -0
  76. package/dist/cli/service/launchd.d.ts +34 -0
  77. package/dist/cli/service/platform-detect.d.ts +59 -0
  78. package/dist/cli/service/systemd.d.ts +41 -0
  79. package/dist/cli/service/types.d.ts +91 -0
  80. package/dist/cli/service/windows.d.ts +20 -0
  81. package/dist/cli/wizard/agent-wizard.d.ts +24 -0
  82. package/dist/cli/wizard/orchestrator-wizard.d.ts +38 -0
  83. package/dist/cli/wizard/prompts.d.ts +23 -0
  84. package/dist/cli.js +11435 -0
  85. package/dist/cluster/cluster-identity.d.ts +59 -0
  86. package/dist/cluster/coordinator.d.ts +204 -0
  87. package/dist/cluster/health-api.d.ts +30 -0
  88. package/dist/cluster/index.d.ts +24 -0
  89. package/dist/cluster/join-client.d.ts +75 -0
  90. package/dist/cluster/join-handler.d.ts +58 -0
  91. package/dist/cluster/join-token.d.ts +94 -0
  92. package/dist/cluster/orphan-recovery.d.ts +67 -0
  93. package/dist/cluster/peer-client.d.ts +190 -0
  94. package/dist/cluster/peer-credentials.d.ts +108 -0
  95. package/dist/cluster/peer-crypto.d.ts +57 -0
  96. package/dist/cluster/peer-handler.d.ts +97 -0
  97. package/dist/cluster/peer-registry.d.ts +186 -0
  98. package/dist/cluster/raft-state.d.ts +36 -0
  99. package/dist/cluster/raft.d.ts +140 -0
  100. package/dist/cold-store/load-access-log-range.d.ts +73 -0
  101. package/dist/cold-store/load-event-log-range.d.ts +62 -0
  102. package/dist/cold-store/load-secret-audit-log-range.d.ts +38 -0
  103. package/dist/cold-store/orchestrator-cold-store.d.ts +58 -0
  104. package/dist/cold-store/tables/access-log.d.ts +80 -0
  105. package/dist/cold-store/tables/event-log.d.ts +70 -0
  106. package/dist/cold-store/tables/execution-jobs.d.ts +63 -0
  107. package/dist/cold-store/tables/execution-runs.d.ts +81 -0
  108. package/dist/cold-store/tables/execution-steps.d.ts +65 -0
  109. package/dist/cold-store/tables/secret-audit-log.d.ts +77 -0
  110. package/dist/concurrency/dispatch-next-queued.d.ts +63 -0
  111. package/dist/concurrency/group-tracker.d.ts +51 -0
  112. package/dist/concurrency/index.d.ts +3 -0
  113. package/dist/concurrency/queue-manager.d.ts +68 -0
  114. package/dist/concurrency/waiters.d.ts +58 -0
  115. package/dist/config/encryption.d.ts +82 -0
  116. package/dist/config/env-overlay.d.ts +45 -0
  117. package/dist/config/index.d.ts +16 -0
  118. package/dist/config/loader.d.ts +26 -0
  119. package/dist/config/reload.d.ts +113 -0
  120. package/dist/config/resolver.d.ts +47 -0
  121. package/dist/config/schema.d.ts +210 -0
  122. package/dist/config/shared-store.d.ts +142 -0
  123. package/dist/config/types.d.ts +218 -0
  124. package/dist/config.d.ts +249 -0
  125. package/dist/cron/cron-scheduler.d.ts +78 -0
  126. package/dist/cron/cron-store.d.ts +38 -0
  127. package/dist/dashboard/handler.d.ts +243 -0
  128. package/dist/db/client.d.ts +13 -0
  129. package/dist/db/migration-provider.d.ts +9 -0
  130. package/dist/db/migrations/001_initial.d.ts +8 -0
  131. package/dist/db/migrations/002_config_versions_key_version.d.ts +16 -0
  132. package/dist/db/migrations/003_access_log.d.ts +26 -0
  133. package/dist/db/migrations/004_rename_bundle_to_source.d.ts +19 -0
  134. package/dist/db/migrations/005_cold_store_chunk_counter.d.ts +19 -0
  135. package/dist/db/migrations/006_runs_jobs_steps_archived_at.d.ts +38 -0
  136. package/dist/db/migrations/007_audit_logs_archived_at.d.ts +42 -0
  137. package/dist/db/migrations/008_event_log_archived_at.d.ts +40 -0
  138. package/dist/db/migrations/009_access_log_trigram.d.ts +15 -0
  139. package/dist/db/migrations/010_cold_store_chunks.d.ts +34 -0
  140. package/dist/db/migrations/011_drop_source_secrets_notify.d.ts +21 -0
  141. package/dist/db/migrations/012_peer_credentials_active_uniq.d.ts +28 -0
  142. package/dist/db/migrations/013_execution_log_bytes.d.ts +21 -0
  143. package/dist/db/migrations/014_kici_events_lease_retry.d.ts +36 -0
  144. package/dist/db/migrations/015_org_settings_customer_scoped.d.ts +30 -0
  145. package/dist/db/migrations/016_org_settings_allow_http_npm.d.ts +15 -0
  146. package/dist/db/migrations/017_org_id_widen.d.ts +4 -0
  147. package/dist/db/migrations/018_org_id_prefix_backfill.d.ts +4 -0
  148. package/dist/db/migrator.d.ts +32 -0
  149. package/dist/db/types.d.ts +1266 -0
  150. package/dist/diagnostics/bundle-reader.d.ts +48 -0
  151. package/dist/diagnostics/bundle-writer.d.ts +57 -0
  152. package/dist/diagnostics/checks/agents.d.ts +10 -0
  153. package/dist/diagnostics/checks/certs.d.ts +9 -0
  154. package/dist/diagnostics/checks/config.d.ts +10 -0
  155. package/dist/diagnostics/checks/db.d.ts +9 -0
  156. package/dist/diagnostics/checks/disk.d.ts +9 -0
  157. package/dist/diagnostics/checks/index.d.ts +17 -0
  158. package/dist/diagnostics/checks/ws.d.ts +9 -0
  159. package/dist/diagnostics/index.d.ts +13 -0
  160. package/dist/diagnostics/runner.d.ts +23 -0
  161. package/dist/diagnostics/types.d.ts +38 -0
  162. package/dist/entry-helpers.d.ts +93 -0
  163. package/dist/environments/binding-store.d.ts +27 -0
  164. package/dist/environments/environment-store.d.ts +74 -0
  165. package/dist/environments/held-runs.d.ts +64 -0
  166. package/dist/environments/index.d.ts +10 -0
  167. package/dist/environments/protection/branch-gate.d.ts +5 -0
  168. package/dist/environments/protection/concurrency-gate.d.ts +7 -0
  169. package/dist/environments/protection/pipeline.d.ts +18 -0
  170. package/dist/environments/protection/reviewer-gate.d.ts +7 -0
  171. package/dist/environments/protection/trust-gate.d.ts +7 -0
  172. package/dist/environments/protection/wait-timer-gate.d.ts +7 -0
  173. package/dist/environments/variable-store.d.ts +39 -0
  174. package/dist/events/circuit-breaker.d.ts +33 -0
  175. package/dist/events/event-emitter.d.ts +55 -0
  176. package/dist/events/event-retry-scanner.d.ts +52 -0
  177. package/dist/events/event-router.d.ts +183 -0
  178. package/dist/events/event-store.d.ts +157 -0
  179. package/dist/events/trust-store.d.ts +54 -0
  180. package/dist/events/types.d.ts +61 -0
  181. package/dist/helpers/ip-extraction.d.ts +29 -0
  182. package/dist/helpers/rate-limiter.d.ts +23 -0
  183. package/dist/index.d.ts +7 -0
  184. package/dist/index.js +772 -0
  185. package/dist/lockfile-cache.d.ts +39 -0
  186. package/dist/metrics/agent-metrics-aggregator.d.ts +116 -0
  187. package/dist/metrics/metrics-reporter.d.ts +40 -0
  188. package/dist/metrics/prometheus.d.ts +261 -0
  189. package/dist/metrics/scheduled-jobs.d.ts +20 -0
  190. package/dist/orchestrator-core.d.ts +193 -0
  191. package/dist/pipeline/dispatch-matched-workflow.d.ts +102 -0
  192. package/dist/pipeline/inline-eval.d.ts +28 -0
  193. package/dist/pipeline/install-secrets-resolver.d.ts +73 -0
  194. package/dist/pipeline/manual-schedule.d.ts +21 -0
  195. package/dist/pipeline/needs-scheduler.d.ts +85 -0
  196. package/dist/pipeline/process-webhook.d.ts +38 -0
  197. package/dist/pipeline/processor.d.ts +326 -0
  198. package/dist/pipeline/rerun.d.ts +79 -0
  199. package/dist/pipeline/test-pipeline.d.ts +110 -0
  200. package/dist/provider-registry.d.ts +122 -0
  201. package/dist/providers/generic/index.d.ts +23 -0
  202. package/dist/providers/generic/normalizer.d.ts +112 -0
  203. package/dist/providers/generic/verification.d.ts +47 -0
  204. package/dist/providers/github/auth.d.ts +60 -0
  205. package/dist/providers/github/changed-files.d.ts +51 -0
  206. package/dist/providers/github/check-status-poster.d.ts +35 -0
  207. package/dist/providers/github/contributor-resolver.d.ts +30 -0
  208. package/dist/providers/github/index.d.ts +20 -0
  209. package/dist/providers/github/lock-file.d.ts +32 -0
  210. package/dist/providers/github/normalizer.d.ts +103 -0
  211. package/dist/providers/github/repo-url.d.ts +35 -0
  212. package/dist/providers/internal/index.d.ts +32 -0
  213. package/dist/providers/internal/lock-file-fetcher.d.ts +34 -0
  214. package/dist/providers/internal/normalizer.d.ts +89 -0
  215. package/dist/providers/internal/repo-url-builder.d.ts +42 -0
  216. package/dist/providers/universal-git/changed-files.d.ts +42 -0
  217. package/dist/providers/universal-git/clone-token.d.ts +83 -0
  218. package/dist/providers/universal-git/config.d.ts +192 -0
  219. package/dist/providers/universal-git/index.d.ts +55 -0
  220. package/dist/providers/universal-git/lock-file.d.ts +71 -0
  221. package/dist/providers/universal-git/normalizer.d.ts +90 -0
  222. package/dist/providers/universal-git/repo-url.d.ts +50 -0
  223. package/dist/providers/universal-git/ssh-auth.d.ts +94 -0
  224. package/dist/queue/bootstrap.d.ts +50 -0
  225. package/dist/queue/cleanup.d.ts +41 -0
  226. package/dist/queue/depth-refresher.d.ts +65 -0
  227. package/dist/queue/job-queue.d.ts +343 -0
  228. package/dist/queue/scheduled-job.d.ts +91 -0
  229. package/dist/registration/extractor.d.ts +44 -0
  230. package/dist/registration/registration-index.d.ts +162 -0
  231. package/dist/registration/registration-store.d.ts +111 -0
  232. package/dist/reporting/check-run-summary.d.ts +102 -0
  233. package/dist/reporting/commit-status.d.ts +382 -0
  234. package/dist/reporting/execution-tracker.d.ts +538 -0
  235. package/dist/reporting/fs-log-storage.d.ts +41 -0
  236. package/dist/reporting/log-pull-handler.d.ts +35 -0
  237. package/dist/reporting/log-storage.d.ts +70 -0
  238. package/dist/reporting/log-writer.d.ts +45 -0
  239. package/dist/reporting/s3-log-storage.d.ts +42 -0
  240. package/dist/reporting/step-log-buffer.d.ts +57 -0
  241. package/dist/routes/admin-access-log.d.ts +34 -0
  242. package/dist/routes/admin-backends.d.ts +28 -0
  243. package/dist/routes/admin-config.d.ts +57 -0
  244. package/dist/routes/admin-db.d.ts +20 -0
  245. package/dist/routes/admin-environments.d.ts +42 -0
  246. package/dist/routes/admin-errors.d.ts +4 -0
  247. package/dist/routes/admin-event-dlq.d.ts +39 -0
  248. package/dist/routes/admin-event-log.d.ts +42 -0
  249. package/dist/routes/admin-events.d.ts +46 -0
  250. package/dist/routes/admin-maintenance.d.ts +22 -0
  251. package/dist/routes/admin-org-settings.d.ts +29 -0
  252. package/dist/routes/admin-queue-execution.d.ts +27 -0
  253. package/dist/routes/admin-registrations.d.ts +37 -0
  254. package/dist/routes/admin-runs.d.ts +57 -0
  255. package/dist/routes/admin-scheduled-jobs.d.ts +36 -0
  256. package/dist/routes/admin-sources.d.ts +18 -0
  257. package/dist/routes/admin.d.ts +103 -0
  258. package/dist/routes/capabilities.d.ts +24 -0
  259. package/dist/routes/diagnostics.d.ts +16 -0
  260. package/dist/routes/health.d.ts +20 -0
  261. package/dist/routes/test-trigger.d.ts +41 -0
  262. package/dist/routes/uploads.d.ts +38 -0
  263. package/dist/routes/webhooks.d.ts +36 -0
  264. package/dist/scaler/bare-metal-backend.d.ts +107 -0
  265. package/dist/scaler/config.d.ts +303 -0
  266. package/dist/scaler/container-backend.d.ts +125 -0
  267. package/dist/scaler/file-tail.d.ts +23 -0
  268. package/dist/scaler/firecracker-api.d.ts +100 -0
  269. package/dist/scaler/firecracker-backend.d.ts +263 -0
  270. package/dist/scaler/index.d.ts +24 -0
  271. package/dist/scaler/ip-allocator.d.ts +177 -0
  272. package/dist/scaler/label-matcher.d.ts +73 -0
  273. package/dist/scaler/log-forwarder.d.ts +54 -0
  274. package/dist/scaler/machine-ledger.d.ts +160 -0
  275. package/dist/scaler/manager.d.ts +338 -0
  276. package/dist/scaler/nftables.d.ts +85 -0
  277. package/dist/scaler/types.d.ts +388 -0
  278. package/dist/scaler/warm-pool.d.ts +81 -0
  279. package/dist/secrets/audit-logger.d.ts +65 -0
  280. package/dist/secrets/backend-health.d.ts +60 -0
  281. package/dist/secrets/backend-registry.d.ts +68 -0
  282. package/dist/secrets/backend-sync.d.ts +40 -0
  283. package/dist/secrets/cleanup.d.ts +40 -0
  284. package/dist/secrets/config.d.ts +51 -0
  285. package/dist/secrets/crypto.d.ts +49 -0
  286. package/dist/secrets/ephemeral-keys.d.ts +49 -0
  287. package/dist/secrets/index.d.ts +17 -0
  288. package/dist/secrets/pg-secret-store.d.ts +105 -0
  289. package/dist/secrets/rbac.d.ts +47 -0
  290. package/dist/secrets/secret-output-store.d.ts +46 -0
  291. package/dist/secrets/secret-resolver.d.ts +137 -0
  292. package/dist/secrets/source-credentials.d.ts +61 -0
  293. package/dist/secrets/token-manager.d.ts +63 -0
  294. package/dist/secrets/vault-secret-store.d.ts +85 -0
  295. package/dist/security/comment-handler.d.ts +67 -0
  296. package/dist/security/contributor-cache.d.ts +75 -0
  297. package/dist/security/global-workflow-policy.d.ts +72 -0
  298. package/dist/security/lock-source.d.ts +34 -0
  299. package/dist/security/trust-resolver.d.ts +108 -0
  300. package/dist/security/workflow-diff.d.ts +26 -0
  301. package/dist/server.d.ts +17 -0
  302. package/dist/server.js +48055 -0
  303. package/dist/sources/index.d.ts +10 -0
  304. package/dist/sources/source-manager.d.ts +63 -0
  305. package/dist/sources/source-store.d.ts +79 -0
  306. package/dist/sources/source-validator.d.ts +16 -0
  307. package/dist/stale-detector/stale-run-detector.d.ts +109 -0
  308. package/dist/standalone.d.ts +20 -0
  309. package/dist/standalone.js +41546 -0
  310. package/dist/storage/blob-routes.d.ts +20 -0
  311. package/dist/storage/filesystem.d.ts +60 -0
  312. package/dist/storage/index.d.ts +20 -0
  313. package/dist/storage/s3.d.ts +68 -0
  314. package/dist/storage/sign-url.d.ts +45 -0
  315. package/dist/storage/types.d.ts +98 -0
  316. package/dist/webhook/dedup.d.ts +44 -0
  317. package/dist/webhook/event-log.d.ts +83 -0
  318. package/dist/webhook/generic-sources.d.ts +169 -0
  319. package/dist/webhook/handler.d.ts +23 -0
  320. package/dist/webhook/relay-buffer.d.ts +96 -0
  321. package/dist/webhook/verify-inbound.d.ts +78 -0
  322. package/dist/worker/in-memory-execution-tracker.d.ts +94 -0
  323. package/dist/worker/in-memory-job-queue.d.ts +74 -0
  324. package/dist/worker/static-agent-token-store.d.ts +58 -0
  325. package/dist/worker/worker-status.d.ts +36 -0
  326. package/dist/worker-core.d.ts +74 -0
  327. package/dist/ws/agent-api-registry.d.ts +49 -0
  328. package/dist/ws/agent-handler.d.ts +176 -0
  329. package/dist/ws/agent-heartbeat.d.ts +45 -0
  330. package/dist/ws/dashboard-backends-handler.d.ts +51 -0
  331. package/dist/ws/dashboard-diagnostics-handler.d.ts +56 -0
  332. package/dist/ws/dashboard-env-handler.d.ts +107 -0
  333. package/dist/ws/dashboard-global-workflows-handler.d.ts +72 -0
  334. package/dist/ws/dashboard-registrations-handler.d.ts +84 -0
  335. package/dist/ws/event-buffer.d.ts +16 -0
  336. package/dist/ws/observer-handler.d.ts +42 -0
  337. package/dist/ws/observer-registry.d.ts +88 -0
  338. package/dist/ws/platform-client.d.ts +270 -0
  339. package/dist/ws/server-options.d.ts +15 -0
  340. package/package.json +87 -7
  341. package/sbom.spdx.json +14370 -0
  342. package/index.js +0 -3
@@ -0,0 +1,388 @@
1
+ /**
2
+ * Core type definitions for the agent auto-scaler module.
3
+ *
4
+ * Provides the foundational types that all scaler backends, the ScalerManager,
5
+ * and the configuration layer depend on.
6
+ */
7
+ import type { ResourceRequest, ResourceSpec, ScalerBackendType } from '@kici-dev/engine';
8
+ export type { ResourceRequest, ResourceSpec } from '@kici-dev/engine';
9
+ /**
10
+ * Resource limits for spawned agents.
11
+ *
12
+ * Alias of `ResourceSpec` from `@kici-dev/engine`. Single source of truth for
13
+ * the (cpus, memory) pair used by both scaler config and per-job resource
14
+ * declarations. Memory uses container-style suffixes (e.g., "2g", "512m").
15
+ * CPUs use fractional cores (e.g., 1.5 = 1.5 cores).
16
+ */
17
+ export type ResourceLimits = ResourceSpec;
18
+ /**
19
+ * Aggregate cap on summed `requests` for a group of agents (per-scaler,
20
+ * per-orchestrator, or per-machine pool). Memory is pre-parsed to bytes at
21
+ * config-load so the scaler doesn't re-parse on every spawn check.
22
+ */
23
+ export interface ResourceCap {
24
+ /** Maximum total CPU (sum of `requests.cpus`) across all active agents in the group. */
25
+ maxCpu?: number;
26
+ /** Maximum total memory in bytes (sum of `requests.memory`) across all active agents in the group. */
27
+ maxMemoryBytes?: number;
28
+ }
29
+ /**
30
+ * Definition of a named machine pool. Multiple orchestrators on the same host
31
+ * can share a pool by referencing it by name; the file-backed ledger
32
+ * (`machine-ledger.ts`) coordinates reservation accounting across processes.
33
+ */
34
+ export interface MachinePoolConfig {
35
+ name: string;
36
+ cap: ResourceCap;
37
+ }
38
+ /**
39
+ * Pre-resolved kernel-side limits passed to `ScalerBackend.spawn()`.
40
+ *
41
+ * Memory is in bytes (already parsed) so the backend doesn't re-run the
42
+ * memory-string parser on every spawn. Either field may be zero or omitted
43
+ * to mean "no limit on this dimension"; the backend falls back to its
44
+ * label-set or default limits when both are zero.
45
+ */
46
+ export interface EffectiveLimits {
47
+ cpus?: number;
48
+ memBytes?: number;
49
+ }
50
+ /**
51
+ * Network policy controlling RFC1918 and internet access for agents in this label set.
52
+ */
53
+ export interface NetworkPolicy {
54
+ /** CIDR ranges allowed as exceptions to the default RFC1918 block */
55
+ allowlist?: string[];
56
+ /** Block all outbound traffic except allowlisted ranges */
57
+ denyAll?: boolean;
58
+ }
59
+ /**
60
+ * Configuration for a single label-set mapping within a scaler backend.
61
+ * Maps an exact set of labels to the agent provisioning details.
62
+ */
63
+ export interface LabelSetConfig {
64
+ /** Exact label set (sorted for deterministic comparison) */
65
+ labels: string[];
66
+ /** Container image (Docker backend) */
67
+ image?: string;
68
+ /** Image pull policy: Always (default), IfNotPresent, or Never */
69
+ imagePullPolicy?: 'Always' | 'IfNotPresent' | 'Never';
70
+ /** Path to agent binary (bare-metal backend) */
71
+ binaryPath?: string;
72
+ /**
73
+ * Per-label-set resource request and limit (override scaler defaults).
74
+ * After config-load normalization the internal representation is always nested:
75
+ * `{ requests?: { cpus, memory }, limits?: { cpus, memory } }`.
76
+ * The legacy flat shorthand (`{ cpus, memory }`) is accepted at config-load
77
+ * and treated as `limits` (with `requests` auto-mirrored).
78
+ */
79
+ resources?: ResourceRequest;
80
+ /**
81
+ * Mount container runtime socket into container.
82
+ * WARNING: Enabling gives CI jobs FULL ROOT ACCESS to the host container runtime.
83
+ * Only enable for fully trusted workloads on isolated infrastructure.
84
+ * @default false
85
+ */
86
+ containerSocket?: boolean;
87
+ /** Additional bind-mount volumes for spawned containers (e.g. ["/host/path:/container/path:ro"]) */
88
+ volumes?: string[];
89
+ /** Additional environment variables passed to spawned agents */
90
+ env?: Record<string, string>;
91
+ /** Network isolation policy for agents in this label set */
92
+ networkPolicy?: NetworkPolicy;
93
+ /** Backpressure mode for agent log streaming: 'pause' (default) or 'drop'.
94
+ * When set, injected as KICI_BACKPRESSURE_MODE into spawned agent environment. */
95
+ backpressureMode?: 'pause' | 'drop';
96
+ /** Path to ext4 rootfs image (Firecracker backend, required per label-set) */
97
+ rootfsPath?: string;
98
+ /** Override scaler-level kernel path for this label set */
99
+ kernelPath?: string;
100
+ /** Override scaler-level vCPU count for this label set */
101
+ vcpuCount?: number;
102
+ /** Override scaler-level memory in MiB for this label set */
103
+ memSizeMib?: number;
104
+ /** Size in MiB for the per-VM overlay drive (Firecracker CoW mode) @default 2048 */
105
+ overlayDriveSizeMib?: number;
106
+ }
107
+ /**
108
+ * Represents a single spawned agent instance tracked by the scaler.
109
+ * Separate from the AgentRegistry which only knows about registered (WS-connected) agents.
110
+ */
111
+ export interface ManagedAgent {
112
+ /** Unique ID for this managed agent instance (scaler-internal tracking) */
113
+ id: string;
114
+ /** The label set this agent was spawned for */
115
+ labelSet: string[];
116
+ /** Backend-specific identifier (container ID or PID) */
117
+ backendRef: string;
118
+ /** When this agent was spawned (epoch ms) */
119
+ spawnedAt: number;
120
+ /** Current lifecycle state */
121
+ state: 'spawning' | 'running' | 'destroying';
122
+ /** The agentId the spawned agent registered with via WS (set after registration) */
123
+ registeredAgentId?: string;
124
+ }
125
+ /**
126
+ * Result of a scaling decision.
127
+ * Discriminated union on 'action' for exhaustive pattern matching.
128
+ */
129
+ export type ScaleResult = {
130
+ action: 'spawning';
131
+ backendType: string;
132
+ } | {
133
+ action: 'at-capacity';
134
+ } | {
135
+ action: 'no-backend';
136
+ labels: string[];
137
+ } | {
138
+ action: 'failed';
139
+ error: string;
140
+ };
141
+ /**
142
+ * Result of a configuration validation or reload operation.
143
+ */
144
+ export type ValidationResult = {
145
+ valid: true;
146
+ } | {
147
+ valid: false;
148
+ errors: string[];
149
+ };
150
+ /**
151
+ * Common interface for all scaler backends.
152
+ * Each backend manages a specific pool of agents for specific label sets.
153
+ * Designed to be pluggable -- Docker, bare-metal, and future K8s/VM backends
154
+ * all implement this interface.
155
+ */
156
+ export interface ScalerBackend {
157
+ /** Backend type identifier */
158
+ readonly type: ScalerBackendType;
159
+ /** Log source identifier for ELK app.logsSource field. Set by each backend. */
160
+ readonly logsSource?: string;
161
+ /** Label sets this backend can provision */
162
+ readonly labelSets: LabelSetConfig[];
163
+ /** Per-backend maximum agents */
164
+ readonly maxAgents: number;
165
+ /** Current count of agents managed by this backend (including spawning) */
166
+ getActiveCount(): number;
167
+ /**
168
+ * Spawn an agent for the given label set.
169
+ * @param labelSet - The exact label set to spawn for
170
+ * @param agentId - Pre-generated agent ID for WS registration correlation
171
+ * @param orchestratorUrl - URL for the agent to connect back to
172
+ * @param onEvent - Lifecycle event callback
173
+ * @param effectiveLimits - Resolved kernel-side limits (`{ cpus, memBytes }`)
174
+ * for this spawn. Computed by ScalerManager from the job/label-set/scaler
175
+ * default chain. When omitted (or both fields zero), the backend falls
176
+ * back to its label-set / default limits the same way it always has.
177
+ * @returns The managed agent tracking object
178
+ * @throws If the label set is not supported by this backend
179
+ */
180
+ spawn(labelSet: string[], agentId: string, orchestratorUrl: string, onEvent?: ScalerEventCallback, effectiveLimits?: EffectiveLimits): Promise<ManagedAgent>;
181
+ /**
182
+ * Destroy a specific managed agent.
183
+ * Docker: docker rm -f; Bare-metal: SIGTERM -> SIGKILL
184
+ */
185
+ destroy(managedId: string): Promise<void>;
186
+ /**
187
+ * Get the LogCapture for a managed agent (optional -- container and bare-metal backends
188
+ * support stdout capture. Firecracker handles log forwarding internally via file tailing
189
+ * (serial console + VMM logs) and does not return a LogCapture here).
190
+ */
191
+ getLogCapture?(managedId: string): LogCapture | undefined;
192
+ /** Shutdown all agents managed by this backend (called during graceful shutdown) */
193
+ shutdownAll(): Promise<void>;
194
+ /**
195
+ * Return scaler-specific configuration metadata for a managed agent.
196
+ * Used by the orchestrator to enrich job.context before forwarding to Platform.
197
+ */
198
+ getScalerContext?(agentId: string): Record<string, unknown> | undefined;
199
+ /**
200
+ * Reload configuration (called on SIGHUP).
201
+ * Returns validation errors if new config is invalid.
202
+ */
203
+ reload(labelSets: LabelSetConfig[]): ValidationResult;
204
+ }
205
+ /**
206
+ * Parsed and validated scaler configuration from YAML.
207
+ * Loaded at startup and reloaded on SIGHUP.
208
+ */
209
+ /**
210
+ * Firecracker network configuration.
211
+ * Defines the CIDR pool, bridge name, and gateway for VM networking.
212
+ * Global across all Firecracker scalers on the orchestrator.
213
+ */
214
+ export interface FirecrackerNetworkConfig {
215
+ /** CIDR range for VM IP allocation @default '10.0.0.0/24' */
216
+ cidr?: string;
217
+ /** Host bridge interface name @default 'kici-br0' */
218
+ bridgeName?: string;
219
+ /** Gateway IP address (assigned to bridge) @default '10.0.0.1' */
220
+ gateway?: string;
221
+ /** Subnet mask for guest networking @default '255.255.255.0' */
222
+ netmask?: string;
223
+ }
224
+ /**
225
+ * Parsed and validated scaler configuration from YAML.
226
+ * Loaded at startup and reloaded on SIGHUP.
227
+ */
228
+ export interface ScalerConfig {
229
+ /** Config format version (currently always 1) */
230
+ version: 1;
231
+ /** Global maximum agents across all backends */
232
+ globalMaxAgents: number;
233
+ /** Global defaults applied to all label sets */
234
+ defaults?: {
235
+ /**
236
+ * Default resource request and limit applied when neither the job nor the
237
+ * label-set declares resources. Internal representation is always nested.
238
+ */
239
+ resources?: ResourceRequest;
240
+ };
241
+ /**
242
+ * Cap on the total summed `requests` across every agent this orchestrator
243
+ * has active (across all scalers). Counterpart to `globalMaxAgents` for
244
+ * resource-based pressure.
245
+ */
246
+ globalResourceCap?: ResourceCap;
247
+ /**
248
+ * Optional named machine pools shared by scaler entries on the same host.
249
+ * Each entry's cap is enforced via the file-backed ledger so multiple
250
+ * orchestrator processes on one machine cannot collectively oversubscribe.
251
+ */
252
+ machinePools?: MachinePoolConfig[];
253
+ /** Individual scaler backend configurations */
254
+ scalers: ScalerEntry[];
255
+ /** Global Firecracker network configuration (shared across all Firecracker scalers) */
256
+ firecracker?: FirecrackerNetworkConfig;
257
+ }
258
+ /**
259
+ * Configuration for a single scaler backend entry.
260
+ */
261
+ export interface ScalerEntry {
262
+ /** Human-readable name for this scaler */
263
+ name: string;
264
+ /** Backend type */
265
+ type: Exclude<ScalerBackendType, 'kubernetes'>;
266
+ /** Maximum concurrent agents for this scaler */
267
+ maxAgents: number;
268
+ /** Label-set to image/binary mappings */
269
+ labelSets: LabelSetConfig[];
270
+ /** Container runtime host (e.g. 'tcp://192.168.1.10:2376'). Works for both Docker and Podman remote. */
271
+ host?: string;
272
+ /** Explicit container runtime socket path. Overrides auto-detection. Use for non-standard socket locations. */
273
+ socketPath?: string;
274
+ /** Container runtime type. 'auto' probes known socket paths. Default: 'auto' */
275
+ runtime?: 'docker' | 'podman' | 'auto';
276
+ /** Orchestrator URL for spawned agents to connect back to */
277
+ orchestratorUrl?: string;
278
+ /** Extra host:IP mappings injected into spawned containers (e.g. ["verdaccio.local:host-gateway"]) */
279
+ extraHosts?: string[];
280
+ /** Disable nftables-based network isolation for container backend (default: true). Set to false when nft is unavailable. */
281
+ networkIsolation?: boolean;
282
+ /** Warm pool configuration */
283
+ warmPool?: WarmPoolConfig;
284
+ /**
285
+ * Labels a job MUST declare in `runsOn` to be allowed on this scaler.
286
+ * Mirrors the Kubernetes "taints" concept: a generic job that does not
287
+ * include every mandatory label is blocked from this scaler entirely,
288
+ * even when its other labels are a subset of one of the scaler's
289
+ * `labelSets`. Default: `[]` (no gating).
290
+ */
291
+ mandatoryLabels?: string[];
292
+ /**
293
+ * Agent roles this scaler handles. scaler-entry level, not per-label-set.
294
+ * - undefined (not set): handles all job types including build and init (backward compat,)
295
+ * - []: execution jobs only, no build/init
296
+ * - ['builder']: handles build jobs + execution
297
+ * - ['init-runner']: handles init jobs + execution
298
+ * - ['builder', 'init-runner']: handles both internal job types + execution
299
+ * - ['all']: same as undefined
300
+ */
301
+ roles?: string[];
302
+ /**
303
+ * Cap on summed `requests` (cpus + memory) across active agents in this
304
+ * scaler. Stacks with `maxAgents`; both must allow the spawn.
305
+ */
306
+ resourceCap?: ResourceCap;
307
+ /**
308
+ * Reference to a named machine pool defined at top level. Scalers that
309
+ * reference the same pool name on the same host share a file-backed ledger
310
+ * so multiple orchestrators can't collectively exceed the pool cap.
311
+ */
312
+ machinePool?: string;
313
+ /**
314
+ * Bare-metal opt-in: when true, wrap the spawned binary in a transient
315
+ * `systemd-run --user --scope` with `MemoryMax` and `CPUQuota` derived from
316
+ * the resolved `limits`. Requires user-mode systemd with cgroup-v2 delegate.
317
+ */
318
+ enforceCgroups?: boolean;
319
+ /** Path to the Firecracker binary (Firecracker backend, required) */
320
+ firecrackerPath?: string;
321
+ /** Path to the jailer binary (Firecracker backend, required) */
322
+ jailerPath?: string;
323
+ /** Default kernel path for all label sets (Firecracker backend, required) */
324
+ kernelPath?: string;
325
+ /** Jailer chroot base directory @default '/srv/jailer' */
326
+ chrootBaseDir?: string;
327
+ /** Jailer uid (Firecracker backend, required) */
328
+ uid?: number;
329
+ /** Jailer gid (Firecracker backend, required) */
330
+ gid?: number;
331
+ /** Default vCPU count for VMs @default 2 */
332
+ vcpuCount?: number;
333
+ /** Default memory in MiB for VMs @default 512 */
334
+ memSizeMib?: number;
335
+ /**
336
+ * Wrap privileged commands (`ip`, `chown`) with `sudo -n` when the
337
+ * orchestrator runs as a non-root user (e.g. user-mode systemd on edge
338
+ * worker nodes). Operators must have NOPASSWD sudoers entries for those
339
+ * binaries. Default false.
340
+ */
341
+ requireSudo?: boolean;
342
+ }
343
+ /**
344
+ * Warm pool configuration for pre-provisioned idle agents.
345
+ */
346
+ export interface WarmPoolConfig {
347
+ /** Whether the warm pool is enabled */
348
+ enabled: boolean;
349
+ /** Number of idle agents to maintain */
350
+ size: number;
351
+ /** Seconds before an idle warm-pool agent is destroyed
352
+ * @default 300
353
+ */
354
+ idleTimeoutSeconds: number;
355
+ }
356
+ /**
357
+ * Standardized scaler lifecycle event types emitted by all backends.
358
+ * These are stored in the event_log table for timeline rendering.
359
+ */
360
+ type ScalerEventType = 'scaler.provisioning' | 'scaler.network' | 'scaler.ready' | 'scaler.failed' | 'agent.connecting';
361
+ /**
362
+ * A single scaler lifecycle event.
363
+ * Each backend emits these at key provisioning milestones.
364
+ */
365
+ export interface ScalerEvent {
366
+ agentId: string;
367
+ eventType: ScalerEventType;
368
+ /** Backend-specific detail text (e.g. "pulling image nginx:latest", "booting microVM") */
369
+ detail: string;
370
+ timestampMs: number;
371
+ }
372
+ /**
373
+ * Callback type for scaler event emission.
374
+ * Passed from ScalerManager to each backend during spawn().
375
+ */
376
+ export type ScalerEventCallback = (event: ScalerEvent) => void;
377
+ /**
378
+ * Interface for capturing agent log output from scaler backends.
379
+ * Each backend implements this to expose the spawned agent's stdout/stderr
380
+ * as an async iterable of individual log lines.
381
+ */
382
+ export interface LogCapture {
383
+ /** Async iterable yielding individual log lines from the agent process. */
384
+ lines(): AsyncIterable<string>;
385
+ /** Stop capturing and destroy underlying streams. Safe to call multiple times. */
386
+ close(): void;
387
+ }
388
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Warm pool manager for pre-provisioned idle agents.
3
+ *
4
+ * Tracks idle agents per label set, handles idle timeout expiry,
5
+ * and triggers replenishment when a warm agent is consumed.
6
+ * Uses callback pattern to avoid circular dependencies with ScalerManager.
7
+ */
8
+ export interface WarmPoolCallbacks {
9
+ /** Request the ScalerManager to spawn a new agent for the given label set */
10
+ onSpawnRequest: (labelSet: string[], backendName: string) => Promise<void>;
11
+ /** Request the ScalerManager to destroy an idle agent */
12
+ onDestroyRequest: (managedId: string, backendName: string) => Promise<void>;
13
+ }
14
+ export declare class WarmPoolManager {
15
+ private readonly callbacks;
16
+ /** Pools of idle agents keyed by normalized label set string */
17
+ private readonly pools;
18
+ /** Configuration per normalized label set */
19
+ private readonly configs;
20
+ /** Periodic idle check interval */
21
+ private idleCheckInterval;
22
+ constructor(callbacks: WarmPoolCallbacks);
23
+ /**
24
+ * Configure the warm pool for a label set.
25
+ * Called during ScalerManager initialization based on YAML config.
26
+ */
27
+ configure(normalizedLabels: string, backendName: string, config: {
28
+ size: number;
29
+ idleTimeoutSeconds: number;
30
+ labels: string[];
31
+ }): void;
32
+ /**
33
+ * Add an agent to the warm pool.
34
+ * Called when a freshly spawned warm pool agent has registered but has no job.
35
+ */
36
+ addIdleAgent(normalizedLabels: string, managedId: string, backendName: string): void;
37
+ /**
38
+ * Consume an agent from the warm pool for the given label set.
39
+ * Returns the managedId (FIFO order) or null if pool is empty.
40
+ * After consuming, schedules replenishment on next tick.
41
+ */
42
+ consumeAgent(normalizedLabels: string): string | null;
43
+ /**
44
+ * Check if pool is below configured size and request spawns for the deficit.
45
+ */
46
+ replenish(normalizedLabels: string): void;
47
+ /**
48
+ * Start periodic idle check (every 30 seconds).
49
+ * Destroys agents that have been idle past their timeout.
50
+ */
51
+ start(): void;
52
+ /**
53
+ * Stop the periodic idle check interval.
54
+ */
55
+ stop(): void;
56
+ /**
57
+ * Return current warm pool count for a label set.
58
+ */
59
+ getPoolSize(normalizedLabels: string): number;
60
+ /**
61
+ * Return total warm agents across all pools.
62
+ */
63
+ getTotalPoolSize(): number;
64
+ /**
65
+ * Update configs. Drain excess agents from pools that shrunk.
66
+ * Does NOT remove agents from pools whose config was removed --
67
+ * let idle timeout handle that gracefully.
68
+ */
69
+ reload(newConfigs: Map<string, {
70
+ backendName: string;
71
+ size: number;
72
+ idleTimeoutSeconds: number;
73
+ labels: string[];
74
+ }>): void;
75
+ /**
76
+ * Check for idle agents past their timeout and destroy them.
77
+ * Exposed for testing.
78
+ */
79
+ checkIdleTimeouts(): void;
80
+ }
81
+ //# sourceMappingURL=warm-pool.d.ts.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Audit logger for secrets management operations.
3
+ *
4
+ * Records all secret access/denial events to the secret_audit_log table
5
+ * for compliance and security monitoring.
6
+ *
7
+ * Phase D: query() supports cold-store read-through via the optional
8
+ * `coldStore` constructor argument and an `includeArchived` query
9
+ * filter. Hot-only behavior is unchanged when neither is supplied.
10
+ */
11
+ import type { Kysely } from 'kysely';
12
+ import type { ColdStore } from '@kici-dev/shared';
13
+ import type { Database, SecretAuditLogRow } from '../db/types.js';
14
+ import { type AuditEntry } from '@kici-dev/engine';
15
+ /**
16
+ * Audit logger that writes secret operation events to PostgreSQL.
17
+ */
18
+ export declare class AuditLogger {
19
+ private readonly db;
20
+ private coldStore;
21
+ constructor(db: Kysely<Database>, coldStore?: ColdStore);
22
+ /**
23
+ * Late-binding setter so the orchestrator-core wiring can build the
24
+ * AuditLogger before the cold-store singleton (which depends on env
25
+ * + S3 client init) and attach it later.
26
+ */
27
+ setColdStore(coldStore: ColdStore | null): void;
28
+ /**
29
+ * Log a secret operation event.
30
+ *
31
+ * `resolve` / `resolve_named` allowed entries are sampled at 1% (per the
32
+ * engine's `shouldRecordSecretResolve` helper) since they're written
33
+ * once per JOB-step secret resolution and dwarf every other action's
34
+ * volume. Denied resolves and every other action (`setSecret`,
35
+ * `deleteSecret`, `rotateKey`, `secret-outputs.reveal`) bypass the
36
+ * sampler — they are transactional with the mutation and must always
37
+ * land.
38
+ *
39
+ * @param entry - The audit entry to record.
40
+ */
41
+ log(entry: AuditEntry): Promise<void>;
42
+ /**
43
+ * Query audit log entries with optional filters.
44
+ *
45
+ * @param opts - Query filters and pagination.
46
+ * @returns Matching audit log rows ordered by timestamp descending.
47
+ */
48
+ query(opts: {
49
+ contextName?: string;
50
+ routingKey?: string;
51
+ action?: string;
52
+ from?: Date;
53
+ to?: Date;
54
+ limit?: number;
55
+ offset?: number;
56
+ /**
57
+ * Phase D opt-in. When true, falls through to cold-store via
58
+ * `loadSecretAuditLogRange` for any portion of the requested
59
+ * window past the warm cutoff. Default false preserves the
60
+ * original semantics.
61
+ */
62
+ includeArchived?: boolean;
63
+ }): Promise<SecretAuditLogRow[]>;
64
+ }
65
+ //# sourceMappingURL=audit-logger.d.ts.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Backend health checker for multi-source secret management.
3
+ *
4
+ * Probes PG and Vault backends for connectivity and reports health status.
5
+ * Used on orchestrator startup and periodically to detect degraded backends.
6
+ */
7
+ import type { BackendHealthStatus, AddBackendParams } from '@kici-dev/engine';
8
+ import type { Logger } from '@kici-dev/shared';
9
+ import type { BackendRegistry } from './backend-registry.js';
10
+ /** PG probe function type — injectable for testing. */
11
+ export type PgProbe = (connectionString?: string) => Promise<void>;
12
+ /**
13
+ * Probes secret backends for connectivity and tracks health status.
14
+ */
15
+ export declare class BackendHealthChecker {
16
+ private readonly registry;
17
+ private readonly logger;
18
+ private intervalHandle;
19
+ private readonly pgProbe;
20
+ constructor(registry: BackendRegistry, logger: Logger, pgProbe?: PgProbe);
21
+ /**
22
+ * Check health of a single backend by name.
23
+ * Updates the registry with the result.
24
+ */
25
+ checkHealth(name: string): Promise<BackendHealthStatus>;
26
+ /**
27
+ * Check health of all enabled backends in parallel.
28
+ */
29
+ checkAllBackends(): Promise<Map<string, BackendHealthStatus>>;
30
+ /**
31
+ * Start periodic health checks at the given interval.
32
+ */
33
+ startPeriodicCheck(intervalMs?: number): void;
34
+ /**
35
+ * Stop periodic health checks.
36
+ */
37
+ stopPeriodicCheck(): void;
38
+ /**
39
+ * Test connectivity to a backend without persisting it.
40
+ * Creates an ephemeral connection and probes it.
41
+ */
42
+ testConnection(params: AddBackendParams): Promise<{
43
+ ok: boolean;
44
+ error?: string;
45
+ latencyMs: number;
46
+ }>;
47
+ /**
48
+ * Probe a backend by type and return its health status.
49
+ */
50
+ private probeBackend;
51
+ /**
52
+ * Probe a PG backend by running SELECT 1.
53
+ */
54
+ private probePg;
55
+ /**
56
+ * Probe a Vault backend by checking /v1/sys/health.
57
+ */
58
+ private probeVault;
59
+ }
60
+ //# sourceMappingURL=backend-health.d.ts.map
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Backend registry for multi-source secret management.
3
+ *
4
+ * Manages the secret_backends table: CRUD operations, config encryption,
5
+ * and factory methods to create SecretStore instances from registered backends.
6
+ */
7
+ import { type Kysely } from 'kysely';
8
+ import type { BackendDescriptor, BackendType, BackendHealthStatus, AddBackendParams, SecretStore } from '@kici-dev/engine';
9
+ import type { Logger } from '@kici-dev/shared';
10
+ import type { AuditLogger } from './audit-logger.js';
11
+ /**
12
+ * Registry for secret backends.
13
+ *
14
+ * Encrypts backend config at rest using AES-256-GCM with the backend name
15
+ * as AAD to prevent cross-backend config swaps.
16
+ */
17
+ export declare class BackendRegistry {
18
+ private readonly db;
19
+ private readonly masterKey;
20
+ private readonly logger?;
21
+ constructor(db: Kysely<any>, masterKey: Buffer, logger?: Logger | undefined);
22
+ /**
23
+ * Register a new backend. Encrypts config and stores in DB.
24
+ */
25
+ addBackend(params: AddBackendParams): Promise<BackendDescriptor>;
26
+ /**
27
+ * Ensure the default `pg` backend row exists. The initial migration seeds
28
+ * this row with `config_encrypted = ''` (sentinel, never decrypted), but the
29
+ * row can be lost to operator error, a buggy purge, or manual cleanup.
30
+ * Idempotent — safe to call on every startup. Self-heals DBs where the row
31
+ * was deleted so the admin API and `listBackends()` always expose `pg`.
32
+ */
33
+ ensureDefaultPgBackend(): Promise<void>;
34
+ /**
35
+ * Remove a backend by name. Returns true if a row was deleted.
36
+ */
37
+ removeBackend(name: string): Promise<boolean>;
38
+ /**
39
+ * List all registered backends (metadata only, no credentials).
40
+ */
41
+ listBackends(): Promise<BackendDescriptor[]>;
42
+ /**
43
+ * Get a single backend by name, or null if not found.
44
+ */
45
+ getBackend(name: string): Promise<BackendDescriptor | null>;
46
+ /**
47
+ * Get backend config (decrypted). Internal use only.
48
+ */
49
+ getBackendConfig(name: string): Promise<Record<string, unknown> | null>;
50
+ /**
51
+ * Create SecretStore instances for all enabled backends.
52
+ * Returns a map of backend name to SecretStore.
53
+ */
54
+ loadAllStores(auditLogger: AuditLogger): Promise<Map<string, SecretStore>>;
55
+ /**
56
+ * Create a SecretStore for a given backend type and config.
57
+ */
58
+ createStoreForBackend(backendType: BackendType, config: Record<string, unknown>, auditLogger: AuditLogger): SecretStore | null;
59
+ /**
60
+ * Update health status for a backend.
61
+ */
62
+ updateHealthStatus(name: string, status: BackendHealthStatus, error?: string): Promise<void>;
63
+ /**
64
+ * Update sync status for a backend.
65
+ */
66
+ updateSyncStatus(name: string, scopeCount: number, error?: string): Promise<void>;
67
+ }
68
+ //# sourceMappingURL=backend-registry.d.ts.map