@kici-dev/orchestrator 0.0.0 → 0.1.1

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 -6
  341. package/sbom.spdx.json +14370 -0
  342. package/index.js +0 -3
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Registry tracking active WebSocket observers per execution run.
3
+ *
4
+ * Multiple CLI clients can subscribe to observe the same run.
5
+ * The registry handles:
6
+ * - Per-run observer sets with subscribe/unsubscribe
7
+ * - Broadcast of messages (log, step, status, complete) to all observers
8
+ * - Message buffering with monotonic sequence numbers for reconnection backfill
9
+ * - Automatic cleanup of closed/errored connections during broadcast
10
+ * - TTL-based buffer cleanup after run completion
11
+ */
12
+ import type { WsLike } from '@kici-dev/engine';
13
+ export type ObserverWsLike = WsLike;
14
+ export declare class ObserverRegistry {
15
+ /** Per-run observer sets. */
16
+ private readonly observers;
17
+ /** Per-run message buffers for reconnection backfill. */
18
+ private readonly buffers;
19
+ /** Monotonic sequence counter per run. */
20
+ private readonly sequenceCounters;
21
+ /** Scheduled buffer cleanup timers (for cancellation on new subscribe). */
22
+ private readonly cleanupTimers;
23
+ /**
24
+ * Subscribe an observer to a run.
25
+ *
26
+ * If `lastSeenSequence` is provided, buffered messages with sequence > lastSeenSequence
27
+ * are replayed to the observer immediately.
28
+ */
29
+ subscribe(runId: string, ws: ObserverWsLike, lastSeenSequence?: number): void;
30
+ /**
31
+ * Unsubscribe an observer from a run.
32
+ *
33
+ * If the observer set becomes empty, the buffer is kept alive
34
+ * for potential reconnection (TTL-based cleanup happens later).
35
+ */
36
+ unsubscribe(runId: string, ws: ObserverWsLike): void;
37
+ /**
38
+ * Broadcast a message object to all observers of a run.
39
+ *
40
+ * The message is serialized once, sent to all observers, and added to the
41
+ * run's buffer with a monotonic sequence number. Closed/errored connections
42
+ * are removed during broadcast.
43
+ */
44
+ broadcast(runId: string, message: object): void;
45
+ /**
46
+ * Convenience: broadcast a log chunk message.
47
+ */
48
+ broadcastLog(runId: string, jobId: string, jobName: string, stepIndex: number, stepName: string, lines: string[]): void;
49
+ /**
50
+ * Convenience: broadcast a step lifecycle event.
51
+ */
52
+ broadcastStep(runId: string, jobId: string, jobName: string, stepName: string, state: string, durationMs?: number): void;
53
+ /**
54
+ * Convenience: broadcast a run status change.
55
+ */
56
+ broadcastStatus(runId: string, status: string, jobName?: string): void;
57
+ /**
58
+ * Convenience: broadcast run completion with summary.
59
+ *
60
+ * After broadcasting, schedules buffer cleanup after COMPLETION_BUFFER_TTL_MS
61
+ * to allow brief reconnection windows.
62
+ */
63
+ broadcastComplete(runId: string, status: string, summary: object): void;
64
+ /**
65
+ * Get the number of active observers for a run.
66
+ */
67
+ getObserverCount(runId: string): number;
68
+ /**
69
+ * Check if a run has any active observers.
70
+ */
71
+ hasObservers(runId: string): boolean;
72
+ /**
73
+ * Remove all buffers for completed runs.
74
+ * Call periodically or on shutdown to reclaim memory.
75
+ */
76
+ cleanup(): void;
77
+ /**
78
+ * Get the current sequence number for a run (for testing).
79
+ */
80
+ getCurrentSequence(runId: string): number;
81
+ /**
82
+ * Get the buffer size for a run (for testing).
83
+ */
84
+ getBufferSize(runId: string): number;
85
+ private nextSequence;
86
+ private addToBuffer;
87
+ }
88
+ //# sourceMappingURL=observer-registry.d.ts.map
@@ -0,0 +1,270 @@
1
+ import { type OrchestratorToPlatformMessage, type WebhookRelay, type WebhookRelayResult, type TrustPolicyUpdate, type StaleCheckrunCleanup, type DashboardRunDetailRequest, type DashboardStepLogsRequest, type DashboardOrchLogsRequest, type RunRerunRequest, type ManualScheduleRequest, type RunCancelRequest, type DashboardPayloadRequest, type DashboardPlatformToOrchMessage, type DashboardDiagnosticsRequest, type DashboardScalerCapacityRequest, type DashboardScalerAgentsRequest, type JoinRequest, type JoinResponse, type OrchCapabilities, type OrchRole } from '@kici-dev/engine';
2
+ import { RelayBufferRegistry, type RelayStartMeta } from '../webhook/relay-buffer.js';
3
+ /**
4
+ * Verification + processing outcome returned by the chunked relay path's
5
+ * `onVerifyInbound` callback. Mirrors the shape exported by
6
+ * `webhook/verify-inbound.ts` so wiring is a single hand-off without an
7
+ * adapter layer.
8
+ */
9
+ export interface InboundVerifyOutcome {
10
+ result: WebhookRelayResult;
11
+ reason?: string;
12
+ }
13
+ export type ConnectionState = 'disconnected' | 'connecting' | 'authenticating' | 'authenticated';
14
+ /**
15
+ * A webhook source that this orchestrator manages.
16
+ * Sent to Platform after auth.success so the Platform knows which
17
+ * routing keys this orchestrator handles.
18
+ *
19
+ * Note: webhookSecret is no longer included. Secrets are pushed separately
20
+ * via source.secrets after loading from PgSecretStore.
21
+ *
22
+ * Single source of truth lives in `../entry-helpers.ts`. Re-exported here
23
+ * so existing imports of `ProviderSource` from `./platform-client.js` keep
24
+ * working without churn.
25
+ */
26
+ export type { ProviderSource } from '../entry-helpers.js';
27
+ import type { ProviderSource } from '../entry-helpers.js';
28
+ export interface PlatformClientOptions {
29
+ /** WebSocket URL of the Platform relay. */
30
+ url: string;
31
+ /** API key for authentication. */
32
+ token: string;
33
+ /** Callback invoked when a webhook relay is received from Platform. */
34
+ onWebhookRelay: (relay: WebhookRelay) => Promise<void>;
35
+ /** Provider sources to register after authentication. */
36
+ providerSources?: ProviderSource[];
37
+ /** Orchestrator cluster instance ID (sent in source.register for peer correlation). */
38
+ instanceId?: string;
39
+ /** Reachable address for peer-to-peer connections (from KICI_CLUSTER_ADDRESS env var). Null if not configured. */
40
+ address?: string | null;
41
+ /** Orchestrator version string (e.g. "0.0.1"). Sent in source.register for diagnostics. */
42
+ version?: string;
43
+ /** Orchestrator config mode. Sent in source.register for diagnostics. */
44
+ mode?: string;
45
+ /** Scaler backends configured (e.g. ["container", "firecracker"]). Sent in source.register for diagnostics. */
46
+ scalerBackends?: string[];
47
+ /** Whether this orchestrator has S3 log storage configured. Sent in source.register for pool validation. */
48
+ s3LogAccess?: boolean;
49
+ /** Queue timeout in ms. Sent in source.register for Platform safety-net GC. */
50
+ queueTimeoutMs?: number;
51
+ /** Heartbeat interval in ms. Default: 30000 (30s). */
52
+ heartbeatIntervalMs?: number;
53
+ /** Maximum reconnect delay in ms. Default: 60000 (60s). */
54
+ maxReconnectDelayMs?: number;
55
+ /** Maximum event buffer size. Default: 10000. */
56
+ maxBufferSize?: number;
57
+ /** Optional callback for log pull requests from Platform. */
58
+ onLogPullRequest?: (msg: {
59
+ messageId: string;
60
+ executionId: string;
61
+ jobName?: string;
62
+ stepIndex?: number;
63
+ cursor?: number;
64
+ limit?: number;
65
+ }) => void;
66
+ /** Optional callback for peer discovery (from Platform matchmaker). */
67
+ onPeerDiscover?: (peer: {
68
+ connectionId: string;
69
+ instanceId?: string;
70
+ address: string | null;
71
+ routingKeys: string[];
72
+ orchRole?: OrchRole;
73
+ }) => void;
74
+ /** Optional callback invoked after successful authentication and source registration. */
75
+ onAuthenticated?: () => void;
76
+ /** Optional callback for dashboard run detail requests from Platform. */
77
+ onDashboardRunDetail?: (msg: DashboardRunDetailRequest) => void;
78
+ /** Optional callback for dashboard step logs requests from Platform. */
79
+ onDashboardStepLogs?: (msg: DashboardStepLogsRequest) => void;
80
+ /** Optional callback for run re-run requests from Platform (dashboard action). */
81
+ onRunRerun?: (msg: RunRerunRequest) => void;
82
+ /** Optional callback for manual schedule trigger requests from Platform (dashboard action). */
83
+ onManualSchedule?: (msg: ManualScheduleRequest) => void;
84
+ /** Optional callback for run cancel requests from Platform (dashboard action). */
85
+ onRunCancel?: (msg: RunCancelRequest) => void;
86
+ /** Optional callback for dashboard payload requests from Platform. */
87
+ onDashboardPayload?: (msg: DashboardPayloadRequest) => void;
88
+ /** Optional callback for dashboard orchestration logs requests from Platform. */
89
+ onDashboardOrchLogs?: (msg: DashboardOrchLogsRequest) => void;
90
+ /** Optional callback for dashboard environment/held-run messages from Platform. */
91
+ onDashboardEnvMessage?: (msg: DashboardPlatformToOrchMessage) => void;
92
+ /** Optional callback for dashboard diagnostics requests from Platform. */
93
+ onDashboardDiagnostics?: (msg: DashboardDiagnosticsRequest) => void;
94
+ /** Optional callback for dashboard scaler capacity requests from Platform. */
95
+ onDashboardScalerCapacity?: (msg: DashboardScalerCapacityRequest) => void;
96
+ /** Optional callback for dashboard scaler agents requests from Platform. */
97
+ onDashboardScalerAgents?: (msg: DashboardScalerAgentsRequest) => void;
98
+ /** Optional callback for trust policy updates pushed from Platform. */
99
+ onTrustPolicyUpdate?: (msg: TrustPolicyUpdate) => void;
100
+ /** Optional callback for stale check run cleanup requests from Platform. */
101
+ onStaleCheckrunCleanup?: (msg: StaleCheckrunCleanup) => void;
102
+ /** Optional callback for join requests relayed via Platform. */
103
+ onJoinRequest?: (msg: JoinRequest) => Promise<JoinResponse>;
104
+ /** Custom orchestrator capabilities to merge with ORCH_CAPABILITIES in auth.request. */
105
+ orchCapabilities?: Partial<OrchCapabilities>;
106
+ /**
107
+ * Verify a reassembled inbound webhook from the chunked relay path.
108
+ *
109
+ * Wired to `verifyInboundWebhook(deps, ...)` in production. Required when
110
+ * Platform sends `webhook.relay.start`/`webhook.relay.chunk` (chunked path);
111
+ * if absent, the orchestrator ACKs `rejected_misconfigured` because it
112
+ * cannot perform the trust check the new design requires.
113
+ */
114
+ onVerifyInbound?: (meta: RelayStartMeta, body: Buffer) => Promise<InboundVerifyOutcome> | InboundVerifyOutcome;
115
+ /**
116
+ * Optional injected reassembly registry. Tests pass a registry with a short
117
+ * TTL; production constructs a default one per PlatformClient.
118
+ */
119
+ relayBuffer?: RelayBufferRegistry;
120
+ }
121
+ /**
122
+ * WebSocket client that connects the orchestrator to the Platform relay.
123
+ *
124
+ * Handles:
125
+ * - Authentication handshake (auth.request -> auth.success/failure)
126
+ * - Periodic heartbeat messages to keep the connection alive
127
+ * - Auto-reconnect with exponential backoff (1s initial, 1.5x, jitter, 60s max)
128
+ * - Webhook relay reception and ACK responses
129
+ * - Event buffering during disconnection with flush on reconnect
130
+ */
131
+ export declare class PlatformClient {
132
+ private ws;
133
+ private _state;
134
+ private readonly eventBuffer;
135
+ private heartbeatTimer;
136
+ private reconnectTimer;
137
+ private reconnectAttempts;
138
+ private intentionalDisconnect;
139
+ private readonly url;
140
+ private readonly token;
141
+ private readonly onWebhookRelay;
142
+ private providerSources;
143
+ private readonly instanceId?;
144
+ private readonly address?;
145
+ private readonly version?;
146
+ private readonly mode?;
147
+ private readonly scalerBackends?;
148
+ private readonly s3LogAccess?;
149
+ private readonly queueTimeoutMs?;
150
+ private readonly heartbeatIntervalMs;
151
+ private readonly maxReconnectDelayMs;
152
+ private readonly onLogPullRequest?;
153
+ private readonly onPeerDiscover?;
154
+ private readonly onAuthenticated?;
155
+ private readonly onDashboardRunDetail?;
156
+ private readonly onDashboardStepLogs?;
157
+ private readonly onRunRerun?;
158
+ private readonly onManualSchedule?;
159
+ private readonly onRunCancel?;
160
+ private readonly onDashboardPayload?;
161
+ private readonly onDashboardOrchLogs?;
162
+ private readonly onDashboardEnvMessage?;
163
+ private readonly onDashboardDiagnostics?;
164
+ private readonly onDashboardScalerCapacity?;
165
+ private readonly onDashboardScalerAgents?;
166
+ private readonly onTrustPolicyUpdate?;
167
+ private readonly onStaleCheckrunCleanup?;
168
+ private readonly onJoinRequest?;
169
+ private readonly orchCapabilities;
170
+ private readonly onVerifyInbound?;
171
+ private readonly relayBuffer;
172
+ /**
173
+ * Public alias of the orchestrator's owning org as supplied by
174
+ * Platform on `auth.success`. Used by the check-run emitter to build
175
+ * outbound `details_url`s that hide the canonical `org_<12-char>` id.
176
+ * `undefined` when the orchestrator runs against a Platform that
177
+ * predates the alias plumbing, or before the first successful auth.
178
+ */
179
+ private _orgPublicAlias?;
180
+ /**
181
+ * Returns the cached public alias of the orchestrator's owning org,
182
+ * or `undefined` if Platform has not supplied one yet. Read by
183
+ * `commit-status.ts` when building `details_url`.
184
+ */
185
+ getOrgPublicAlias(): string | undefined;
186
+ constructor(options: PlatformClientOptions);
187
+ /** Current connection state. */
188
+ get state(): ConnectionState;
189
+ /** Number of messages currently buffered. */
190
+ getBufferedCount(): number;
191
+ /**
192
+ * Complete a chunked webhook relay: verify, process if accepted, ACK.
193
+ *
194
+ * Called from the `webhook.relay.chunk` handler once `relayBuffer.chunk(...)`
195
+ * returns `{ status: 'completed' }`. This sequence is intentionally single-pass
196
+ * and inside `requestContext.run` so trace propagation works end-to-end.
197
+ */
198
+ private completeChunkedRelay;
199
+ /**
200
+ * Initiate connection to the Platform relay.
201
+ * Starts the connect -> authenticate -> ready lifecycle.
202
+ */
203
+ connect(): void;
204
+ /**
205
+ * Gracefully disconnect from Platform. Does not trigger reconnection.
206
+ */
207
+ disconnect(): void;
208
+ /**
209
+ * Send a message to Platform. If authenticated, sends immediately.
210
+ * If not authenticated, buffers the message for later delivery.
211
+ */
212
+ send(message: OrchestratorToPlatformMessage): void;
213
+ /**
214
+ * Send a raw message directly on the WebSocket, bypassing typed validation.
215
+ * Used for log pull response messages (log.response) which are
216
+ * NOT in the OrchestratorToPlatformMessage union (they are in the separate log pull schema).
217
+ */
218
+ sendRaw(data: unknown): void;
219
+ /**
220
+ * Register a new source at runtime (e.g., after config reload adds a new GitHub app).
221
+ * Separate from the post-auth registration which sends all sources at once.
222
+ */
223
+ sendSourceRegister(source: ProviderSource): void;
224
+ /**
225
+ * Deregister sources at runtime (e.g., after config reload removes a GitHub app).
226
+ * Tells Platform to stop routing webhooks for these routing keys to this orchestrator.
227
+ */
228
+ sendSourceDeregister(source: {
229
+ routingKey: string;
230
+ }): void;
231
+ /**
232
+ * Diff current provider sources with new ones and send register/deregister as needed.
233
+ * Convenience method for config reload that atomically updates routing.
234
+ */
235
+ updateSources(newSources: ProviderSource[]): void;
236
+ getReconnectDelay(): number;
237
+ private doConnect;
238
+ private handleMessage;
239
+ /**
240
+ * Try the two non-mainline schemas (log-pull, cluster join.request) when
241
+ * the primary `platformToOrchestratorMessageSchema` failed to parse. Falls
242
+ * back to a structured warning if neither schema matches.
243
+ */
244
+ private handleNonStandardMessage;
245
+ /**
246
+ * Dispatch a parsed platform message to the appropriate per-area
247
+ * handler. Each `case` either inlines a tiny dispatch (for one-line
248
+ * forwards to a callback) or delegates to a private method when the
249
+ * branch carries non-trivial logic.
250
+ */
251
+ private dispatchPlatformMessage;
252
+ private handleAuthSuccess;
253
+ private handleAuthFailure;
254
+ private handleWebhookRelayStart;
255
+ private handleWebhookRelayChunk;
256
+ private handleSourceRegisterAck;
257
+ private handlePeerDiscover;
258
+ private handlePeerUpdate;
259
+ /**
260
+ * Send a message directly on the WebSocket without buffering.
261
+ * Used for ACK responses that must go immediately.
262
+ */
263
+ private sendDirect;
264
+ private flushBuffer;
265
+ private startHeartbeat;
266
+ private stopHeartbeat;
267
+ private scheduleReconnect;
268
+ private cancelReconnect;
269
+ }
270
+ //# sourceMappingURL=platform-client.d.ts.map
@@ -0,0 +1,15 @@
1
+ import type { WebSocketServer } from 'ws';
2
+ /**
3
+ * Applies the security-relevant options to a `ws` `WebSocketServer` instance.
4
+ *
5
+ * Single source of truth for the orchestrator's agent-WS server config. Lives
6
+ * here so it is unit-testable independently of the heavy `createApp` dependency
7
+ * graph.
8
+ *
9
+ * The (`permessage-deflate` compression bombs) invariant lives here: any
10
+ * field added to defend against compression-bomb DoS — `maxPayload`,
11
+ * `serverNoContextTakeover`, etc. — MUST be set inside this helper so the
12
+ * neighbouring test file can assert it.
13
+ */
14
+ export declare function configureSecureWsServer(wss: WebSocketServer): void;
15
+ //# sourceMappingURL=server-options.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kici-dev/orchestrator",
3
- "version": "0.0.0",
3
+ "version": "0.1.1",
4
4
  "description": "Customer-deployable orchestrator for the KiCI CI/CD stack. Receives webhook events (direct or via Platform relay), matches triggers against the lock file, and dispatches jobs to connected agents.",
5
5
  "keywords": [
6
6
  "kici",
@@ -9,17 +9,98 @@
9
9
  "ci-cd",
10
10
  "typescript",
11
11
  "workflows",
12
- "devops"
12
+ "devops",
13
+ "orchestrator",
14
+ "webhook",
15
+ "self-hosted"
13
16
  ],
14
17
  "homepage": "https://kici.dev",
15
18
  "author": {
16
19
  "name": "KiCI",
17
20
  "email": "hello@kici.dev"
18
21
  },
19
- "license": "Apache-2.0",
20
- "main": "index.js",
22
+ "license": "AGPL-3.0-only",
23
+ "engines": {
24
+ "node": ">=24"
25
+ },
26
+ "type": "module",
27
+ "files": [
28
+ "dist",
29
+ "!dist/**/*.map",
30
+ "sbom.spdx.json"
31
+ ],
21
32
  "publishConfig": {
22
- "access": "public",
23
- "registry": "https://registry.npmjs.org/"
33
+ "registry": "https://registry.npmjs.org/",
34
+ "access": "public"
35
+ },
36
+ "main": "dist/index.js",
37
+ "types": "dist/index.d.ts",
38
+ "bin": {
39
+ "kici-admin": "./dist/cli.js"
40
+ },
41
+ "exports": {
42
+ ".": {
43
+ "import": "./dist/index.js",
44
+ "types": "./dist/index.d.ts"
45
+ },
46
+ "./cli": "./dist/cli.js"
47
+ },
48
+ "build": {
49
+ "entries": {
50
+ "server.js": "src/server.ts",
51
+ "standalone.js": "src/standalone.ts",
52
+ "cli.js": "src/cli/kici-admin.ts",
53
+ "index.js": "src/index.ts"
54
+ }
55
+ },
56
+ "scripts": {
57
+ "build": "node ../../scripts/build-service.mjs && tsc --emitDeclarationOnly",
58
+ "typecheck": "tsc --noEmit",
59
+ "test": "vitest run",
60
+ "db:migrate": "kysely migrate:latest",
61
+ "prepublishOnly": "npx tsx ../../hack/generate-sbom.ts --package packages/orchestrator --name @kici-dev/orchestrator"
62
+ },
63
+ "dependencies": {
64
+ "@aws-sdk/client-s3": "^3.1038.0",
65
+ "@aws-sdk/lib-storage": "^3.1038.0",
66
+ "@aws-sdk/s3-request-presigner": "^3.1038.0",
67
+ "@hono/node-server": "^2.0.0",
68
+ "@hono/node-ws": "^1.3.0",
69
+ "@inquirer/prompts": "^8.4.2",
70
+ "@kici-dev/engine": "workspace:*",
71
+ "@kici-dev/shared": "workspace:*",
72
+ "@octokit/auth-app": "^8.2.0",
73
+ "@octokit/rest": "^22.0.1",
74
+ "archiver": "^7.0.1",
75
+ "commander": "^14.0.3",
76
+ "croner": "^10.0.1",
77
+ "dockerode": "^5.0.0",
78
+ "hashi-vault-js": "^0.5.1",
79
+ "hono": "^4.12.18",
80
+ "jsonpath-plus": "^10.4.0",
81
+ "jszip": "^3.10.1",
82
+ "kysely": "^0.29.0",
83
+ "lru-cache": "^11.3.5",
84
+ "nanoid": "^5.1.9",
85
+ "pg": "^8.20.0",
86
+ "picomatch": "^4.0.4",
87
+ "strip-ansi": "^7.2.0",
88
+ "tar": "^7.5.13",
89
+ "ws": "^8.20.0",
90
+ "yaml": "^2.8.3",
91
+ "zod": "^4.3.6"
92
+ },
93
+ "kici": {
94
+ "metrics": {
95
+ "mode": "scrape",
96
+ "port": 10143,
97
+ "path": "/metrics",
98
+ "jobName": "kici-orchestrator"
99
+ }
100
+ },
101
+ "devDependencies": {
102
+ "@types/archiver": "^7.0.0",
103
+ "@types/dockerode": "^4.0.1",
104
+ "kysely-ctl": "^0.21.0"
24
105
  }
25
106
  }