@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,63 @@
1
+ import { type Kysely } from 'kysely';
2
+ import type { Database, AdminTokenRow } from '../db/types.js';
3
+ import type { Role } from './rbac.js';
4
+ /**
5
+ * Manages admin API tokens for the secrets management system.
6
+ *
7
+ * Tokens are 32-byte random hex strings (64 chars). Only the SHA-256
8
+ * hash is stored; the plaintext is returned once at generation time.
9
+ */
10
+ export declare class TokenManager {
11
+ private readonly db;
12
+ constructor(db: Kysely<Database>);
13
+ /**
14
+ * Generate a new admin API token.
15
+ *
16
+ * @param label - Human-readable label for this token.
17
+ * @param role - Role to assign (owner, admin, auditor).
18
+ * @param routingKey - Optional routing key scope (null = all).
19
+ * @returns The plaintext token (shown once) and the row ID.
20
+ */
21
+ generateToken(label: string, role: Role, routingKey?: string | null): Promise<{
22
+ token: string;
23
+ id: string;
24
+ }>;
25
+ /**
26
+ * Validate a plaintext token against stored hashes.
27
+ *
28
+ * @param token - The plaintext token to validate.
29
+ * @returns Token info if valid, null if invalid/expired/revoked.
30
+ */
31
+ validate(token: string): Promise<{
32
+ id: string;
33
+ role: Role;
34
+ routingKey: string | null;
35
+ label: string;
36
+ } | null>;
37
+ /**
38
+ * Revoke a token by ID.
39
+ */
40
+ revokeToken(tokenId: string): Promise<void>;
41
+ /**
42
+ * List all tokens (excluding hash for security).
43
+ *
44
+ * @param routingKey - Optional filter by routing key.
45
+ */
46
+ listTokens(routingKey?: string | null): Promise<Omit<AdminTokenRow, 'token_hash'>[]>;
47
+ /**
48
+ * Ensure a bootstrap admin token exists.
49
+ *
50
+ * If KICI_BOOTSTRAP_ADMIN_TOKEN env var (or envOverride) is set,
51
+ * use that as the plaintext, hash, and upsert with label='bootstrap', role='owner'.
52
+ *
53
+ * If no env var and no non-revoked tokens exist, generate a new owner
54
+ * token and return the plaintext for logging.
55
+ *
56
+ * If tokens already exist, return null (no bootstrap needed).
57
+ *
58
+ * @param envOverride - Override for KICI_BOOTSTRAP_ADMIN_TOKEN env var.
59
+ * @returns Plaintext token if generated/created, null if not needed.
60
+ */
61
+ ensureBootstrapToken(envOverride?: string): Promise<string | null>;
62
+ }
63
+ //# sourceMappingURL=token-manager.d.ts.map
@@ -0,0 +1,85 @@
1
+ import type { SecretStore } from '@kici-dev/engine';
2
+ import type { Logger } from '@kici-dev/shared';
3
+ /**
4
+ * Configuration for the Vault secret store backend.
5
+ */
6
+ export interface VaultConfig {
7
+ /** Vault server URL (e.g., 'http://vault:8200'). */
8
+ vaultUrl: string;
9
+ /** Authentication method. */
10
+ authMethod: 'approle' | 'token';
11
+ /** AppRole role ID (required for 'approle' auth). */
12
+ roleId?: string;
13
+ /** AppRole secret ID (required for 'approle' auth). */
14
+ secretId?: string;
15
+ /** Static Vault token (required for 'token' auth). */
16
+ token?: string;
17
+ /** Vault Enterprise namespace. */
18
+ namespace?: string;
19
+ /** KV v2 mount path (default: 'secret'). */
20
+ mountPath?: string;
21
+ /** Base path within mount (e.g., 'kici/secrets'). */
22
+ basePath: string;
23
+ }
24
+ /**
25
+ * HashiCorp Vault backend implementing SecretStore.
26
+ *
27
+ * Supports AppRole and token authentication. KV v2 CRUD operations
28
+ * map (orgId, scope) to Vault paths under the configured basePath.
29
+ */
30
+ export declare class VaultSecretStore implements SecretStore {
31
+ private readonly client;
32
+ private readonly config;
33
+ private readonly mountPath;
34
+ private readonly logger;
35
+ private authState;
36
+ constructor(config: VaultConfig, logger: Logger);
37
+ /**
38
+ * Log a Vault API request with structured context.
39
+ * Captures operation, path, status, and optionally error for diagnostics.
40
+ */
41
+ private logVaultRequest;
42
+ /**
43
+ * Authenticate with Vault and cache the token with TTL tracking.
44
+ */
45
+ private authenticate;
46
+ private getToken;
47
+ private withRetry;
48
+ /**
49
+ * Build the full Vault path for a scoped secret.
50
+ */
51
+ private secretPath;
52
+ /**
53
+ * Get all secrets for a scope as key-value pairs.
54
+ */
55
+ getSecrets(orgId: string, scope: string): Promise<Record<string, string>>;
56
+ /**
57
+ * Set (create or update) a secret in a scope.
58
+ */
59
+ setSecret(orgId: string, scope: string, key: string, value: string): Promise<void>;
60
+ /**
61
+ * Delete a secret key from a scope.
62
+ */
63
+ deleteSecret(orgId: string, scope: string, key: string): Promise<void>;
64
+ /**
65
+ * List all secret key names in a scope.
66
+ */
67
+ listKeys(orgId: string, scope: string): Promise<string[]>;
68
+ /**
69
+ * List all distinct scopes for an org.
70
+ * Vault KV v2 LIST only returns immediate children — directories end with '/'.
71
+ * We recurse into directories to discover leaf scopes (paths that hold actual secrets).
72
+ */
73
+ listScopes(orgId: string): Promise<string[]>;
74
+ /**
75
+ * Get all secrets for an org (for resolver).
76
+ * Lists scopes then reads each to collect all encrypted/plain values.
77
+ */
78
+ getAllSecrets(orgId: string): Promise<Array<{
79
+ scope: string;
80
+ key: string;
81
+ encryptedValue: string;
82
+ keyVersion: number;
83
+ }>>;
84
+ }
85
+ //# sourceMappingURL=vault-secret-store.d.ts.map
@@ -0,0 +1,67 @@
1
+ /**
2
+ * /kici approve and /kici reject comment command handler.
3
+ *
4
+ * Parses issue_comment webhook bodies for /kici commands and handles
5
+ * approval/rejection of security holds. Verifies commenter identity
6
+ * via the trust policy cache and checks ci_trust:write+ before acting.
7
+ */
8
+ import type { HeldRunStore } from '../environments/held-runs.js';
9
+ import { type IdentityLink, type PermissionLevel } from './trust-resolver.js';
10
+ import type { CheckStatusPoster as EngineCheckStatusPoster } from '@kici-dev/engine';
11
+ /** Parsed /kici command from a comment body. */
12
+ interface CommentCommand {
13
+ action: 'approve' | 'reject';
14
+ /** Optional: specific run to approve/reject. */
15
+ runId?: string;
16
+ }
17
+ /** Parameters for the approval comment handler. */
18
+ export interface HandleApprovalCommentParams {
19
+ commentBody: string;
20
+ commenterUsername: string;
21
+ /**
22
+ * Commenter immutable IDP-side numeric id from the webhook event. Used to
23
+ * match the identity link by id first, falling back to username during the
24
+ * backfill window (see trust-resolver.findIdentityLink).
25
+ */
26
+ commenterUserId?: string;
27
+ provider: string;
28
+ repoIdentifier: string;
29
+ prNumber: number;
30
+ orgId: string;
31
+ identityLinks: IdentityLink[];
32
+ orgMemberPermissions: Map<string, PermissionLevel>;
33
+ heldRunStore: HeldRunStore;
34
+ /** Check status poster for updating GitHub checks after approval/rejection. */
35
+ checkStatusPoster?: EngineCheckStatusPoster;
36
+ /** Commit SHA for the PR head (needed for check status updates). */
37
+ commitSha?: string;
38
+ credentials: unknown;
39
+ }
40
+ /** Result of handling a comment. */
41
+ interface HandleApprovalResult {
42
+ handled: boolean;
43
+ reason?: string;
44
+ }
45
+ /**
46
+ * Parse a comment body for /kici commands.
47
+ *
48
+ * Looks for `/kici approve` or `/kici reject` at the start of any line.
49
+ * Case-insensitive for the command word (approve/reject) but the /kici prefix is exact.
50
+ * Optional run ID follows the command.
51
+ *
52
+ * @returns Parsed command or null if no /kici command found.
53
+ */
54
+ export declare function parseKiciCommand(commentBody: string): CommentCommand | null;
55
+ /**
56
+ * Handle an approval comment from a PR.
57
+ *
58
+ * Flow:
59
+ * 1. Parse comment for /kici command
60
+ * 2. Look up commenter's identity link via trust policy cache
61
+ * 3. Check ci_trust level (must be write+)
62
+ * 4. Find held runs for the PR
63
+ * 5. Approve or reject held runs
64
+ */
65
+ export declare function handleApprovalComment(params: HandleApprovalCommentParams): Promise<HandleApprovalResult>;
66
+ export {};
67
+ //# sourceMappingURL=comment-handler.d.ts.map
@@ -0,0 +1,75 @@
1
+ /**
2
+ * LRU cache wrapper for ContributorResolver.
3
+ *
4
+ * Caches contributor permission lookups to prevent redundant API calls.
5
+ * Uses a 15-minute TTL and 10,000 max entries.
6
+ */
7
+ import type { ContributorResolver, ContributorInfo } from '@kici-dev/engine';
8
+ /**
9
+ * Caches ContributorResolver results in an LRU cache.
10
+ *
11
+ * Cache key format: `{provider}:{repoFullName}:{username}`
12
+ * TTL: 15 minutes (configurable for testing).
13
+ */
14
+ export declare class ContributorCache {
15
+ private readonly cache;
16
+ constructor(options?: {
17
+ ttlMs?: number;
18
+ maxEntries?: number;
19
+ });
20
+ /**
21
+ * Build the cache key from provider, repo, and username.
22
+ */
23
+ private buildKey;
24
+ /**
25
+ * Resolve contributor info, using cache when available.
26
+ *
27
+ * @param provider - Provider identifier (e.g. 'github')
28
+ * @param repoFullName - Full repo identifier (e.g. 'owner/repo')
29
+ * @param username - Contributor username
30
+ * @param resolver - ContributorResolver to call on cache miss
31
+ * @param credentials - Provider credentials for API calls
32
+ * @returns Cached or freshly resolved ContributorInfo
33
+ */
34
+ resolve(provider: string, repoFullName: string, username: string, resolver: ContributorResolver, credentials: unknown): Promise<ContributorInfo>;
35
+ /**
36
+ * Explicitly invalidate a cached entry.
37
+ *
38
+ * @returns 1 if an entry was present and deleted, 0 otherwise. Symmetric
39
+ * with the bulk invalidators so callers can accumulate a total.
40
+ */
41
+ invalidate(provider: string, repoFullName: string, username: string): number;
42
+ /**
43
+ * Invalidate every cached entry for a specific repository.
44
+ *
45
+ * Scans the LRU (bounded to `maxEntries`) and deletes entries whose key
46
+ * prefix matches `{provider}:{repoFullName}:`. Used when a webhook event
47
+ * signals a repo-wide permission change (e.g. GitHub `team.added_to_repository`
48
+ * / `team.removed_from_repository`) where every contributor's effective
49
+ * permission on that repo may have shifted.
50
+ *
51
+ * @returns Number of entries deleted.
52
+ */
53
+ invalidateByRepo(provider: string, repoFullName: string): number;
54
+ /**
55
+ * Invalidate every cached entry for a user across all repositories in an org.
56
+ *
57
+ * Scans the LRU and deletes entries whose key matches
58
+ * `{provider}:{orgLogin}/*:{username}`. Used when a webhook event signals
59
+ * that a user's membership in an org changed (e.g. GitHub `organization`,
60
+ * `membership` events), since any repo under that org could now return a
61
+ * different permission for the user.
62
+ *
63
+ * @returns Number of entries deleted.
64
+ */
65
+ invalidateByUserInOrg(provider: string, orgLogin: string, username: string): number;
66
+ /**
67
+ * Clear all cached entries. Useful for testing.
68
+ */
69
+ clear(): void;
70
+ /**
71
+ * Get the current number of cached entries.
72
+ */
73
+ get size(): number;
74
+ }
75
+ //# sourceMappingURL=contributor-cache.d.ts.map
@@ -0,0 +1,72 @@
1
+ import type { Kysely } from 'kysely';
2
+ import type { Database } from '../db/types.js';
3
+ interface GlobalWorkflowPermission {
4
+ allowed: boolean;
5
+ reason?: string;
6
+ }
7
+ /**
8
+ * Org-level permission enforcement for global workflows.
9
+ *
10
+ * Three independent axes (each stored as a jsonb array of
11
+ * `{routingKey?, pattern}` entries on `org_settings`):
12
+ *
13
+ * - Workflow-repo allow-list (`global_workflow_allowed_repos`): which repos
14
+ * may author global workflows. null/empty = any repo. Checked at
15
+ * registration-extraction time and at dispatch time against the
16
+ * REGISTRATION's repo (the repo that defined the workflow).
17
+ *
18
+ * - Source-repo deny-list (`global_workflow_denied_repos`): which repos
19
+ * must never have global workflows run against their events (e.g., forks,
20
+ * untrusted contrib repos). Checked at dispatch time against the EVENT's
21
+ * repo (the repo that emitted the webhook).
22
+ *
23
+ * - Elevated access (`global_workflow_elevated_repos`): which workflow-
24
+ * authoring repos can read source-repo secrets during execution.
25
+ *
26
+ * Each entry can optionally pin a `routingKey`, restricting the entry to
27
+ * one webhook source. An entry without a routing key applies to any source
28
+ * in the org. An entry whose routing key no longer matches any current
29
+ * source becomes a no-op (orphan, never matches) — by design, so deleting
30
+ * a source does not silently rebind its policy entries to an unrelated
31
+ * source.
32
+ */
33
+ export declare class GlobalWorkflowPolicy {
34
+ private readonly db;
35
+ constructor(db: Kysely<Database>);
36
+ /**
37
+ * Check whether a workflow-authoring repository is allowed to register or
38
+ * dispatch global workflows. The workflow's own routing key is matched
39
+ * against each entry's optional `routingKey` qualifier.
40
+ *
41
+ * Decision flow:
42
+ * 1. No org_settings row or globally disabled → not allowed (opt-in).
43
+ * 2. allowed list null/empty → any repo allowed.
44
+ * 3. Entry matches when its `routingKey` is absent OR equals
45
+ * `workflowRoutingKey`, AND its pattern matches the workflow repo.
46
+ * 4. Otherwise → not allowed.
47
+ */
48
+ isWorkflowRepoAllowed(workflowRoutingKey: string, workflowRepoIdentifier: string, customerId: string): Promise<GlobalWorkflowPermission>;
49
+ /**
50
+ * Check whether events from a source repository may trigger any global
51
+ * workflows. Each deny entry is matched against the EVENT's routing key
52
+ * (so a source-qualified deny only applies to that specific source).
53
+ *
54
+ * Decision flow:
55
+ * 1. No org_settings row or globally disabled → not allowed (opt-in).
56
+ * 2. denied list null/empty → allowed.
57
+ * 3. Any deny entry whose routing key (if set) equals the event's routing
58
+ * key AND whose pattern matches the source repo → not allowed.
59
+ */
60
+ isSourceRepoAllowed(eventRoutingKey: string, sourceRepoIdentifier: string, customerId: string): Promise<GlobalWorkflowPermission>;
61
+ /**
62
+ * Check whether a workflow-authoring repository has elevated access (i.e.,
63
+ * may read source-repo secrets during execution). The workflow's routing
64
+ * key is matched against each entry's optional `routingKey` qualifier.
65
+ *
66
+ * Returns false if no org_settings row or the elevated list is null/empty.
67
+ */
68
+ isElevatedAccessAllowed(workflowRoutingKey: string, repoIdentifier: string, customerId: string): Promise<boolean>;
69
+ private getSettings;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=global-workflow-policy.d.ts.map
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Lock-file branch selection for webhook processing.
3
+ *
4
+ * For pull-request events, the orchestrator must decide whether to fetch
5
+ * the workflow lock file from the PR head branch (the contributor's
6
+ * proposed change) or from the base branch (the protected target). Only
7
+ * trusted contributors get their HEAD lock evaluated; everyone else
8
+ * (unknown / known / undefined trust resolution) falls back to the base
9
+ * branch's lock so an untrusted contributor cannot inject triggers,
10
+ * jobs, or environment claims that the project's maintainers haven't
11
+ * vetted.
12
+ *
13
+ * The default for non-PR events is HEAD, because there is no untrusted
14
+ * "incoming" contribution to gate against — push events come directly
15
+ * from someone with write access.
16
+ */
17
+ import type { TrustTier } from '@kici-dev/engine';
18
+ /**
19
+ * Select which branch's lock file to fetch.
20
+ *
21
+ * Invariant (customer-isolation): for any pull-request event, an
22
+ * untrusted contributor (`tier === 'unknown' | 'known' | undefined`)
23
+ * MUST NOT have their HEAD lock file evaluated by the orchestrator.
24
+ * The base-branch lock — controlled by the project's trusted
25
+ * maintainers — is the source of truth for trigger evaluation,
26
+ * trust-tier-based environment access, and contributor-controlled
27
+ * fields that downstream secret resolution depends on.
28
+ *
29
+ * Only `tier === 'trusted'` (an identity-linked contributor with
30
+ * provider write+ permission AND ci_trust write+ permission, per
31
+ * `TrustResolver.resolveTrustTier`) can have their HEAD lock evaluated.
32
+ */
33
+ export declare function selectLockFileSource(isPREvent: boolean, tier: TrustTier | undefined): 'head' | 'base';
34
+ //# sourceMappingURL=lock-source.d.ts.map
@@ -0,0 +1,108 @@
1
+ /**
2
+ * TrustResolver -- combines identity links, RBAC ci_trust, and provider permissions
3
+ * into a trust tier decision.
4
+ *
5
+ * The TrustResolver is the core decision engine for CI security. It determines
6
+ * whether a contributor is trusted, known, or unknown based on:
7
+ * 1. Identity link lookup (provider username -> KiCI user ID)
8
+ * 2. ci_trust RBAC level for that user in the org
9
+ * 3. Provider API permission (via ContributorResolver + cache)
10
+ */
11
+ import type { ContributorPermission, ContributorResolver } from '@kici-dev/engine';
12
+ import type { TrustTier } from '@kici-dev/engine';
13
+ import type { ContributorCache } from './contributor-cache.js';
14
+ /**
15
+ * Match an identity link strictly by `(provider, providerUserId)`.
16
+ *
17
+ * Returns `null` whenever the numeric id is missing on either side or when no
18
+ * link's id matches the event's id. This is the strict end-state contract:
19
+ * username fallback is gone, mutable-username impersonation cannot grant
20
+ * trust, and a refused match is recorded under
21
+ * `kici_orch_trust_match_refused_no_id_total{reason}` so the rate of refusals
22
+ * stays observable.
23
+ *
24
+ * Pre-conditions for callers: Platform's reconcile job has filled
25
+ * `provider_user_id` for every row in `identity_links` (verified by the
26
+ * `kici_platform_identity_links_missing_provider_user_id` gauge being 0 for
27
+ * ≥4 cycles before this strict policy was deployed). See
28
+ * `.claude/plans/cryptic-jumping-narwhal.md` for the rollout journey.
29
+ */
30
+ export declare function findIdentityLink(identityLinks: IdentityLink[], provider: string, providerUsername: string, providerUserId: string | undefined): IdentityLink | null;
31
+ /** RBAC permission levels from the Platform permission system. */
32
+ export type PermissionLevel = 'none' | 'read' | 'write' | 'admin';
33
+ /** Identity link mapping a provider identity to a KiCI user. */
34
+ export interface IdentityLink {
35
+ userId: string;
36
+ provider: string;
37
+ providerUsername: string;
38
+ /**
39
+ * Immutable IDP-side numeric id (e.g. GitHub's `sender.id`).
40
+ * Nullable during the backfill window for legacy rows that
41
+ * predate Platform migration 009. Trust resolver matches on
42
+ * this field first; once backfill completes the strict policy
43
+ * refuses trust when this is null.
44
+ */
45
+ providerUserId?: string | null;
46
+ }
47
+ /** Parameters for trust tier resolution. */
48
+ interface TrustResolutionParams {
49
+ /** Sender username from the webhook event. */
50
+ providerUsername: string;
51
+ /**
52
+ * Sender immutable IDP-side numeric id from the webhook event (e.g.
53
+ * GitHub's `sender.id` coerced to string). Optional during the backfill
54
+ * window; the strict end-state refuses trust when this is missing.
55
+ */
56
+ providerUserId?: string;
57
+ /** Provider type (e.g. 'github'). */
58
+ provider: string;
59
+ /** Repository identifier (e.g. 'owner/repo'). */
60
+ repoIdentifier: string;
61
+ /** Whether the PR comes from a fork. */
62
+ isForkPR: boolean;
63
+ /** Organization ID this webhook routes to. */
64
+ orgId: string;
65
+ /** Cached identity links from Platform push. */
66
+ identityLinks: IdentityLink[];
67
+ /** ci_trust permission levels per user ID from Platform push. */
68
+ orgMemberPermissions: Map<string, PermissionLevel>;
69
+ /** Provider-specific contributor resolver. */
70
+ contributorResolver: ContributorResolver;
71
+ /** Credentials for provider API calls. */
72
+ credentials: unknown;
73
+ }
74
+ /** Result of trust tier resolution with full audit trail. */
75
+ export interface TrustResolution {
76
+ tier: TrustTier;
77
+ contributorUsername: string;
78
+ identityLinked: boolean;
79
+ userId?: string;
80
+ providerPermission: ContributorPermission;
81
+ ciTrustLevel?: PermissionLevel;
82
+ reason: string;
83
+ }
84
+ /**
85
+ * TrustResolver combines identity links, ci_trust RBAC, and provider permissions
86
+ * into a trust tier.
87
+ *
88
+ * Decision matrix:
89
+ * 1. Fork PR -> always unknown
90
+ * 2. No identity link -> provider API fallback (never trusted)
91
+ * - read+ -> known
92
+ * - none -> unknown
93
+ * 3. Identity linked -> combine ci_trust + provider permission:
94
+ * - provider write+ AND ci_trust write+ -> trusted
95
+ * - provider write+ AND ci_trust none/read -> known
96
+ * - provider read -> known
97
+ * - provider none -> unknown
98
+ */
99
+ export declare class TrustResolver {
100
+ private readonly contributorCache;
101
+ constructor(contributorCache: ContributorCache);
102
+ /**
103
+ * Resolve the trust tier for a contributor.
104
+ */
105
+ resolveTrustTier(params: TrustResolutionParams): Promise<TrustResolution>;
106
+ }
107
+ export {};
108
+ //# sourceMappingURL=trust-resolver.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Workflow modification detection.
3
+ *
4
+ * Compares base and head lock files to detect added, modified, or removed workflows.
5
+ * Used by the processor to flag workflow changes in PRs from non-trusted contributors.
6
+ */
7
+ import type { LockFile } from '@kici-dev/engine';
8
+ /** A single workflow modification detected between base and head lock files. */
9
+ export interface WorkflowModification {
10
+ workflowName: string;
11
+ changeType: 'added' | 'modified' | 'removed';
12
+ }
13
+ /**
14
+ * Detect workflow modifications between base and head lock files.
15
+ *
16
+ * Compares workflow names and configurations:
17
+ * - Added: in head but not base
18
+ * - Removed: in base but not head
19
+ * - Modified: in both but triggers, jobs, or steps differ
20
+ *
21
+ * @param baseLockFile - Lock file from the base branch (null for new repos)
22
+ * @param headLockFile - Lock file from the head commit (null means nothing to detect)
23
+ * @returns List of detected modifications
24
+ */
25
+ export declare function detectWorkflowModifications(baseLockFile: LockFile | null, headLockFile: LockFile | null): WorkflowModification[];
26
+ //# sourceMappingURL=workflow-diff.d.ts.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Platform-connected entry point for the customer orchestrator.
3
+ *
4
+ * Operates in 'platform' or 'hybrid' mode:
5
+ * - platform: receives webhooks ONLY via Platform WS relay
6
+ * - hybrid: receives webhooks via both WS relay and direct HTTP endpoint
7
+ *
8
+ * Both modes connect a PlatformClient to the Platform relay and run an agent WS server.
9
+ *
10
+ * Startup sequence follows packages/platform/src/server.ts pattern:
11
+ * config -> DB -> migrations -> provider registry -> dispatcher -> PlatformClient -> app -> HTTP -> heartbeat
12
+ *
13
+ * Graceful shutdown in reverse order:
14
+ * Platform client -> agent WS -> heartbeat -> HTTP -> DB
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=server.d.ts.map