@kici-dev/orchestrator 0.1.27 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/dist/__test-helpers__/mock-db.d.ts +2 -0
  2. package/dist/agent/dispatcher.d.ts +52 -2
  3. package/dist/agent/host-roster-reaper.d.ts +1 -2
  4. package/dist/agent/host-roster.d.ts +34 -0
  5. package/dist/agent/ownership-refusal.d.ts +12 -0
  6. package/dist/agent/ownership-tracker.d.ts +64 -16
  7. package/dist/agent/token-store.d.ts +13 -0
  8. package/dist/agent-packaging/availability.d.ts +27 -0
  9. package/dist/agent-packaging/build-package.d.ts +16 -0
  10. package/dist/agent-packaging/download.d.ts +30 -0
  11. package/dist/agent-packaging/index.d.ts +9 -0
  12. package/dist/agent-packaging/install-closure.d.ts +30 -0
  13. package/dist/agent-packaging/node-binary.d.ts +26 -0
  14. package/dist/agent-packaging/refresh.d.ts +50 -0
  15. package/dist/agent-packaging/store.d.ts +15 -0
  16. package/dist/agent-packaging/upload.d.ts +24 -0
  17. package/dist/app-on-error.d.ts +29 -0
  18. package/dist/app.d.ts +56 -4
  19. package/dist/artifacts/artifact-store.d.ts +233 -0
  20. package/dist/artifacts/failure-messages.d.ts +46 -0
  21. package/dist/audit/access-log.d.ts +18 -1
  22. package/dist/cache/dep-cache.d.ts +15 -0
  23. package/dist/cache/user-cache.d.ts +37 -0
  24. package/dist/cancel/cancel-run.d.ts +10 -3
  25. package/dist/cancel/dashboard-cancel-handler.d.ts +19 -0
  26. package/dist/cli/api-client.d.ts +22 -1
  27. package/dist/cli/commands/agent-package.d.ts +34 -0
  28. package/dist/cli/commands/check-run.d.ts +26 -0
  29. package/dist/cli/commands/cluster-settings.d.ts +55 -0
  30. package/dist/cli/commands/dashboard-encryption-key.d.ts +3 -0
  31. package/dist/cli/commands/db-backup.d.ts +71 -0
  32. package/dist/cli/commands/orchestrator-service/drain.d.ts +31 -0
  33. package/dist/cli/commands/orchestrator-service/index.d.ts +7 -4
  34. package/dist/cli/commands/orchestrator-service/install-env.d.ts +58 -0
  35. package/dist/cli/commands/secret.d.ts +45 -1
  36. package/dist/cli/commands/shared/admin-cli-access-log.d.ts +46 -0
  37. package/dist/cli/commands/shared/versioned-upgrade.d.ts +65 -2
  38. package/dist/cli/commands/signing-key.d.ts +3 -0
  39. package/dist/cli/commands/source.d.ts +12 -0
  40. package/dist/cli/commands/token.d.ts +9 -0
  41. package/dist/cli/commands/trust-policy.d.ts +48 -0
  42. package/dist/cli/join.d.ts +1 -1
  43. package/dist/cli/service/index.d.ts +2 -2
  44. package/dist/cli/service/instance/manifest.d.ts +17 -0
  45. package/dist/cli/service/instance/resolve.d.ts +11 -0
  46. package/dist/cli/wizard/orchestrator-wizard.d.ts +39 -11
  47. package/dist/cli.js +9818 -3408
  48. package/dist/cluster/cluster-settings-reader.d.ts +78 -0
  49. package/dist/cluster/coordinator.d.ts +81 -9
  50. package/dist/cluster/join-client.d.ts +1 -1
  51. package/dist/cluster/leader-gated-scheduler.d.ts +50 -0
  52. package/dist/cluster/orphan-recovery.d.ts +14 -0
  53. package/dist/cluster/peer-client.d.ts +12 -2
  54. package/dist/cluster/peer-handler.d.ts +15 -4
  55. package/dist/cluster/peer-registry.d.ts +12 -0
  56. package/dist/cluster/verified-issuer-poller.d.ts +11 -0
  57. package/dist/cluster/verified-issuer.d.ts +63 -0
  58. package/dist/cold-store/tables/access-log.d.ts +1 -1
  59. package/dist/cold-store/tables/event-log.d.ts +1 -1
  60. package/dist/cold-store/tables/execution-jobs.d.ts +1 -1
  61. package/dist/cold-store/tables/execution-runs.d.ts +1 -1
  62. package/dist/cold-store/tables/execution-steps.d.ts +1 -1
  63. package/dist/cold-store/tables/secret-audit-log.d.ts +1 -1
  64. package/dist/config/loader.d.ts +1 -1
  65. package/dist/config/resolver.d.ts +2 -1
  66. package/dist/config/schema.d.ts +8 -6
  67. package/dist/config/types.d.ts +3 -2
  68. package/dist/config.d.ts +363 -53
  69. package/dist/contexts/context-store.d.ts +21 -8
  70. package/dist/contexts/glob-specificity.d.ts +30 -0
  71. package/dist/contexts/held-runs.d.ts +51 -19
  72. package/dist/contexts/protection/aggregate.d.ts +2 -2
  73. package/dist/contexts/protection/concurrency-gate.d.ts +0 -3
  74. package/dist/contexts/protection/reviewer-gate.d.ts +0 -3
  75. package/dist/contexts/protection/satisfiability.d.ts +1 -1
  76. package/dist/contexts/protection/trust-gate.d.ts +0 -3
  77. package/dist/contexts/protection/wait-timer-gate.d.ts +0 -3
  78. package/dist/cron/cron-scheduler.d.ts +24 -4
  79. package/dist/cron/cron-store.d.ts +21 -7
  80. package/dist/dashboard/attestation-filters.d.ts +92 -74
  81. package/dist/dashboard/handler.d.ts +35 -1
  82. package/dist/db/migration-test-harness.d.ts +41 -0
  83. package/dist/db/migrations/069_reroute_tunables.d.ts +21 -0
  84. package/dist/db/migrations/070_execution_runs_failure_class.d.ts +4 -0
  85. package/dist/db/migrations/071_batch_accumulation.d.ts +26 -0
  86. package/dist/db/migrations/072_dispatch_queue_run_id_index.d.ts +15 -0
  87. package/dist/db/migrations/073_org_settings_ingest_concurrency.d.ts +13 -0
  88. package/dist/db/migrations/074_normalize_zero_concurrency_limit.d.ts +13 -0
  89. package/dist/db/migrations/075_ingest_overflow_buffer.d.ts +16 -0
  90. package/dist/db/migrations/076_artifacts.d.ts +19 -0
  91. package/dist/db/migrations/077_backup_runs.d.ts +13 -0
  92. package/dist/db/migrations/078_org_settings_backup_staleness.d.ts +12 -0
  93. package/dist/db/migrations/079_org_settings_scaler_spawn_timeout.d.ts +14 -0
  94. package/dist/db/migrations/080_cluster_settings.d.ts +17 -0
  95. package/dist/db/migrations/081_org_settings_queue_timeout.d.ts +19 -0
  96. package/dist/db/migrations/082_host_s3_reachable.d.ts +16 -0
  97. package/dist/db/migrations/083_org_settings_artifact_caps.d.ts +18 -0
  98. package/dist/db/migrations/084_orchestrator_signing_keys.d.ts +20 -0
  99. package/dist/db/migrations/085_cluster_settings_reroute_flap_grace_ms.d.ts +12 -0
  100. package/dist/db/migrations/086_cluster_settings_max_fanout_hosts.d.ts +12 -0
  101. package/dist/db/migrations/087_cluster_settings_event_router_rate_limit.d.ts +12 -0
  102. package/dist/db/migrations/088_cluster_settings_cache_max_tarball_bytes.d.ts +12 -0
  103. package/dist/db/migrations/089_cluster_settings_cache_ttl_days.d.ts +12 -0
  104. package/dist/db/migrations/090_cluster_settings_concurrency_wait_timeout_ms.d.ts +12 -0
  105. package/dist/db/migrations/091_cluster_settings_agent_token_ttl_ms.d.ts +12 -0
  106. package/dist/db/migrations/092_cluster_settings_version.d.ts +16 -0
  107. package/dist/db/migrations/093_org_settings_sandbox_allowlist.d.ts +4 -0
  108. package/dist/db/migrations/094_dashboard_encryption_keys.d.ts +21 -0
  109. package/dist/db/migrations/095_dashboard_write_policy_tristate.d.ts +20 -0
  110. package/dist/db/migrations/096_multi_schedule_cron_last_fired.d.ts +4 -0
  111. package/dist/db/migrations/097_execution_runs_pr_number.d.ts +4 -0
  112. package/dist/db/migrations/098_execution_runs_customer_id.d.ts +4 -0
  113. package/dist/db/migrations/099_cluster_settings_dashboard_verified_issuer.d.ts +21 -0
  114. package/dist/db/migrations/100_held_runs_hold_type_vocabulary.d.ts +31 -0
  115. package/dist/db/migrations/101_contexts_hold_expiry_drop_default.d.ts +31 -0
  116. package/dist/db/migrations/102_dispatch_queue_agent_id.d.ts +20 -0
  117. package/dist/db/migrations/103_cluster_settings_ownership_db_check_timeout_ms.d.ts +20 -0
  118. package/dist/db/migrations/104_check_run_terminal_sent.d.ts +22 -0
  119. package/dist/db/migrations/105_org_trust_policy.d.ts +19 -0
  120. package/dist/db/migrations/106_cluster_settings_check_run_tracking_ttl_days.d.ts +18 -0
  121. package/dist/db/migrations/107_check_run_tracking_updated_at_index.d.ts +23 -0
  122. package/dist/db/repos/dashboard-encryption-keys-repo.d.ts +48 -0
  123. package/dist/db/repos/signing-keys-repo.d.ts +34 -0
  124. package/dist/db/types.d.ts +421 -7
  125. package/dist/deployment/deployment-identity.d.ts +87 -2
  126. package/dist/diagnostics/checks/backup.d.ts +18 -0
  127. package/dist/diagnostics/checks/index.d.ts +2 -1
  128. package/dist/diagnostics/fleet-collector.d.ts +1 -1
  129. package/dist/drain/drain-controller.d.ts +52 -0
  130. package/dist/events/batch-accumulator.d.ts +63 -0
  131. package/dist/events/circuit-breaker.d.ts +9 -3
  132. package/dist/events/event-emitter.d.ts +31 -0
  133. package/dist/events/event-retry-scanner.d.ts +12 -2
  134. package/dist/events/event-router.d.ts +29 -0
  135. package/dist/firecracker/host-network.d.ts +2 -0
  136. package/dist/firecracker/net-interfaces.d.ts +14 -0
  137. package/dist/github-app-name-refresher/github-app-name-refresher.d.ts +18 -8
  138. package/dist/index.d.ts +2 -0
  139. package/dist/index.js +604 -16
  140. package/dist/lockfile-cache.d.ts +4 -0
  141. package/dist/lockfile-validate.d.ts +16 -9
  142. package/dist/metrics/prometheus.d.ts +112 -15
  143. package/dist/oidc/aws-kms-signer.d.ts +37 -0
  144. package/dist/oidc/command-signer.d.ts +23 -0
  145. package/dist/oidc/db-signer.d.ts +48 -0
  146. package/dist/oidc/id-token-claims.d.ts +22 -9
  147. package/dist/oidc/jwt.d.ts +5 -2
  148. package/dist/oidc/local-dev-signer.d.ts +1 -1
  149. package/dist/oidc/oidc-mint-registration.d.ts +27 -11
  150. package/dist/oidc/orchestrator-mint.d.ts +97 -0
  151. package/dist/oidc/orchestrator-signer-factory.d.ts +33 -0
  152. package/dist/oidc/reconcile-signing-key.d.ts +21 -0
  153. package/dist/oidc/signer.d.ts +25 -0
  154. package/dist/oidc/signing-key-status.d.ts +23 -0
  155. package/dist/orchestrator-core.d.ts +42 -2
  156. package/dist/pipeline/decorating-secret-resolver.d.ts +3 -2
  157. package/dist/pipeline/dispatch-matched-workflow.d.ts +41 -0
  158. package/dist/pipeline/install-secrets-resolver.d.ts +12 -1
  159. package/dist/pipeline/manual-schedule.d.ts +20 -13
  160. package/dist/pipeline/pending-workflow-context.d.ts +1 -1
  161. package/dist/pipeline/process-webhook.d.ts +57 -2
  162. package/dist/pipeline/processor.d.ts +44 -8
  163. package/dist/pipeline/rerun.d.ts +12 -13
  164. package/dist/pipeline/resolve-sandbox-grant.d.ts +28 -0
  165. package/dist/pipeline/route-or-dispatch-jobs.d.ts +71 -0
  166. package/dist/pipeline/sandbox-allowlist-reader.d.ts +33 -0
  167. package/dist/policy/dashboard-write-policy.d.ts +9 -4
  168. package/dist/provenance/backfill-run.d.ts +1 -0
  169. package/dist/provenance/trust-root.d.ts +13 -0
  170. package/dist/providers/generic/normalizer.d.ts +1 -1
  171. package/dist/providers/github/auth.d.ts +1 -1
  172. package/dist/providers/github/changed-files.d.ts +14 -6
  173. package/dist/providers/github/check-status-poster.d.ts +19 -3
  174. package/dist/providers/github/contributor-resolver.d.ts +1 -1
  175. package/dist/providers/github/lock-file.d.ts +1 -1
  176. package/dist/providers/github/normalizer.d.ts +1 -1
  177. package/dist/providers/github/repo-url.d.ts +1 -1
  178. package/dist/providers/local/lock-file-fetcher.d.ts +1 -1
  179. package/dist/providers/local/normalizer.d.ts +1 -1
  180. package/dist/providers/local/repo-url-builder.d.ts +1 -1
  181. package/dist/providers/universal-git/changed-files.d.ts +8 -7
  182. package/dist/providers/universal-git/clone-token.d.ts +1 -1
  183. package/dist/providers/universal-git/config.d.ts +4 -4
  184. package/dist/providers/universal-git/index.d.ts +5 -1
  185. package/dist/providers/universal-git/lock-file.d.ts +6 -1
  186. package/dist/providers/universal-git/normalizer.d.ts +1 -1
  187. package/dist/providers/universal-git/repo-url.d.ts +1 -1
  188. package/dist/queue/cleanup.d.ts +69 -8
  189. package/dist/queue/job-queue.d.ts +94 -14
  190. package/dist/queue/scheduled-job.d.ts +2 -2
  191. package/dist/registration/registration-index.d.ts +1 -1
  192. package/dist/reporting/agent-failure-category.d.ts +4 -1
  193. package/dist/reporting/check-run-reporter.d.ts +34 -14
  194. package/dist/reporting/check-run-tracking-store.d.ts +70 -8
  195. package/dist/reporting/execution-tracker.d.ts +156 -10
  196. package/dist/reporting/fs-log-storage.d.ts +31 -2
  197. package/dist/reporting/job-check-run-completion.d.ts +50 -0
  198. package/dist/reporting/log-chunk-sink.d.ts +47 -0
  199. package/dist/reporting/log-retention.d.ts +16 -0
  200. package/dist/reporting/log-storage.d.ts +64 -4
  201. package/dist/reporting/log-writer.d.ts +22 -7
  202. package/dist/reporting/peer-log-normalize.d.ts +14 -0
  203. package/dist/reporting/run-aggregator.d.ts +32 -32
  204. package/dist/reporting/s3-log-storage.d.ts +102 -8
  205. package/dist/routes/admin-auth.d.ts +90 -0
  206. package/dist/routes/admin-cluster-settings.d.ts +31 -0
  207. package/dist/routes/admin-events.d.ts +3 -0
  208. package/dist/routes/admin-orchestrator-drain.d.ts +35 -0
  209. package/dist/routes/admin-runs.d.ts +9 -0
  210. package/dist/routes/admin-sources.d.ts +7 -0
  211. package/dist/routes/admin-trust-policy.d.ts +49 -0
  212. package/dist/routes/admin.d.ts +15 -1
  213. package/dist/routes/github-webhook.d.ts +9 -3
  214. package/dist/routes/provenance-oidc.d.ts +38 -0
  215. package/dist/routes/verify-attestation.d.ts +21 -0
  216. package/dist/scaler/bare-metal-backend.d.ts +9 -2
  217. package/dist/scaler/config.d.ts +25 -4
  218. package/dist/scaler/container-backend.d.ts +9 -1
  219. package/dist/scaler/firecracker-backend.d.ts +29 -2
  220. package/dist/scaler/index.d.ts +1 -1
  221. package/dist/scaler/manager.d.ts +166 -8
  222. package/dist/scaler/pending-scale-sweeper.d.ts +35 -0
  223. package/dist/scaler/types.d.ts +75 -6
  224. package/dist/secrets/backend-registry.d.ts +32 -1
  225. package/dist/secrets/dashboard-encryption-key.d.ts +48 -0
  226. package/dist/secrets/ephemeral-keys.d.ts +16 -0
  227. package/dist/secrets/pg-secret-store.d.ts +10 -0
  228. package/dist/secrets/rbac.d.ts +5 -1
  229. package/dist/secrets/routing-key-scope.d.ts +6 -0
  230. package/dist/secrets/scope-routing.d.ts +126 -0
  231. package/dist/secrets/secret-resolver.d.ts +1 -14
  232. package/dist/secrets/token-manager.d.ts +5 -1
  233. package/dist/security/contributor-cache.d.ts +9 -1
  234. package/dist/security/trust-policy-gate.d.ts +117 -0
  235. package/dist/security/trust-policy-store.d.ts +78 -0
  236. package/dist/server.js +35769 -25052
  237. package/dist/sources/source-manager.d.ts +24 -0
  238. package/dist/stale-detector/stale-run-detector.d.ts +7 -0
  239. package/dist/standalone.js +34831 -25317
  240. package/dist/storage/filesystem.d.ts +17 -0
  241. package/dist/storage/key-discriminator.d.ts +20 -0
  242. package/dist/storage/s3.d.ts +2 -0
  243. package/dist/storage/types.d.ts +16 -0
  244. package/dist/webhook/dedup.d.ts +9 -1
  245. package/dist/webhook/event-log.d.ts +13 -2
  246. package/dist/webhook/generic-sources-listener.d.ts +4 -0
  247. package/dist/webhook/ingest-admission.d.ts +140 -0
  248. package/dist/webhook/ingest-overflow-buffer.d.ts +27 -0
  249. package/dist/webhook/ingest-overflow-replayer.d.ts +49 -0
  250. package/dist/webhook/ingest-overflow-types.d.ts +73 -0
  251. package/dist/webhook/loop-lag-source.d.ts +40 -0
  252. package/dist/webhook/observed-relay-guard.d.ts +40 -0
  253. package/dist/webhook/org-ingest-cap-reader.d.ts +24 -0
  254. package/dist/webhook/register-source-bundle.d.ts +3 -0
  255. package/dist/webhook/relay-reinject.d.ts +43 -0
  256. package/dist/worker/in-memory-job-queue.d.ts +8 -3
  257. package/dist/worker-core.d.ts +10 -0
  258. package/dist/ws/agent-api-registry.d.ts +20 -0
  259. package/dist/ws/agent-handler.d.ts +63 -7
  260. package/dist/ws/bringup-api.d.ts +99 -0
  261. package/dist/ws/dashboard-context-handler.d.ts +28 -10
  262. package/dist/ws/dashboard-run-state-handler.d.ts +31 -0
  263. package/dist/ws/failure-messages.d.ts +29 -0
  264. package/dist/ws/oidc-token-relay.d.ts +9 -0
  265. package/dist/ws/ownership-gate.d.ts +22 -0
  266. package/dist/ws/platform-client.d.ts +96 -1
  267. package/dist/ws/replay-chunker.d.ts +37 -0
  268. package/installer-image-digests.json +3 -3
  269. package/package.json +22 -21
  270. package/sbom.spdx.json +1240 -1788
@@ -40,6 +40,7 @@ import { StepLogBuffer } from './reporting/step-log-buffer.js';
40
40
  import { ObserverRegistry } from './ws/observer-registry.js';
41
41
  import { ScalerManager } from './scaler/index.js';
42
42
  import type { ScalerConfig } from './scaler/index.js';
43
+ import type { WorkerClusterSettings } from '@kici-dev/engine';
43
44
  /**
44
45
  * Subsystems available in worker mode.
45
46
  * Subset of OrchestratorSubsystems with in-memory replacements.
@@ -61,6 +62,15 @@ interface WorkerSubsystems {
61
62
  scalerManager: ScalerManager | null;
62
63
  scalerConfig: ScalerConfig | null;
63
64
  }
65
+ /**
66
+ * Resolve the ephemeral agent-token TTL a worker-spawned agent should use:
67
+ * the fleet-wide `agent_token_ttl_ms` pulled from the leader when a snapshot has
68
+ * landed, otherwise the boot-time config default. This is the single seam the
69
+ * worker's three scaler backends read at spawn.
70
+ */
71
+ export declare function resolveWorkerAgentTokenTtlMs(pushed: {
72
+ settings: WorkerClusterSettings;
73
+ } | null, fallback: number): number;
64
74
  /**
65
75
  * Bootstrap the orchestrator in worker mode.
66
76
  *
@@ -15,6 +15,26 @@
15
15
  export type ApiRole = 'read' | 'write';
16
16
  /** Handler function for an API method. */
17
17
  export type ApiHandler = (agentId: string, params: Record<string, unknown>) => Promise<unknown>;
18
+ /**
19
+ * The caller named a method the registry does not know.
20
+ *
21
+ * A deliberate, bounded rejection: its message names only the method the caller
22
+ * itself sent, so the agent WS handler may forward it verbatim to the workflow
23
+ * author instead of replacing it with a safe fixed string.
24
+ */
25
+ export declare class UnknownApiMethodError extends Error {
26
+ constructor(method: string);
27
+ }
28
+ /**
29
+ * The caller is not authorized for the role the requested method requires.
30
+ *
31
+ * A deliberate, bounded rejection: its message names only the caller's own
32
+ * method and roles, so the agent WS handler may forward it verbatim to the
33
+ * workflow author instead of replacing it with a safe fixed string.
34
+ */
35
+ export declare class ApiRoleDeniedError extends Error {
36
+ constructor(method: string, requiredRole: ApiRole, allowedRoles: ApiRole[]);
37
+ }
18
38
  /**
19
39
  * Registry for agent private API methods.
20
40
  *
@@ -16,22 +16,24 @@
16
16
  * When agentAuthMode === 'none', the auth phase is skipped (legacy behavior).
17
17
  */
18
18
  import type { WSEvents } from 'hono/ws';
19
+ import { LogStream } from '@kici-dev/engine';
19
20
  import type { RateLimiterConfig, AttestationVerifyStatus } from '@kici-dev/engine';
20
21
  import type { ProvenanceTrustRoot } from '../provenance/trust-root.js';
21
22
  import type { AgentRegistry } from '../agent/registry.js';
22
23
  import type { Dispatcher } from '../agent/dispatcher.js';
23
- import type { AgentTokenStore } from '../agent/token-store.js';
24
+ import { type AgentTokenStore } from '../agent/token-store.js';
24
25
  import type { OwnershipTracker } from '../agent/ownership-tracker.js';
25
26
  import type { SourceCache } from '../cache/source-cache.js';
26
27
  import type { DepCache } from '../cache/dep-cache.js';
27
28
  import type { UserCache } from '../cache/user-cache.js';
29
+ import { type ArtifactStore } from '../artifacts/artifact-store.js';
28
30
  import type { DispatchCacheRefTracker } from '../cache/dispatch-cache-ref-tracker.js';
29
31
  import type { PendingBuildTracker } from '../cache/pending-builds.js';
30
32
  import type { PendingInitTracker } from '../cache/pending-inits.js';
31
33
  import type { PendingDynamicTracker } from '../cache/pending-dynamics.js';
32
34
  import type { CacheStorage } from '../storage/types.js';
33
35
  import type { AgentMetricsAggregator } from '../metrics/agent-metrics-aggregator.js';
34
- import type { AgentApiRegistry } from './agent-api-registry.js';
36
+ import { type AgentApiRegistry } from './agent-api-registry.js';
35
37
  import type { FleetAgentCollector } from './fleet-agent-collector.js';
36
38
  /**
37
39
  * Run the three token-bound authorization gates against a wire-supplied
@@ -39,8 +41,9 @@ import type { FleetAgentCollector } from './fleet-agent-collector.js';
39
41
  * (Phase 2 / `pendingRegistration`) and on every subsequent re-register
40
42
  * arriving on the same registered WS — every code path that mutates the
41
43
  * registry's `agentId → entry` mapping for an authenticated WS MUST run
42
- * them, otherwise the §5.3 / §5.1 invariants only hold for the very first
43
- * register and a re-register can silently overwrite the authority.
44
+ * them, otherwise the token-scope and identity-binding invariants only
45
+ * hold for the very first register and a re-register can silently
46
+ * overwrite the authority.
44
47
  *
45
48
  * Gates:
46
49
  * 1. Token-scope subset — wire labels MUST be a subset of
@@ -59,7 +62,7 @@ import type { FleetAgentCollector } from './fleet-agent-collector.js';
59
62
  * case the caller MUST stop processing.
60
63
  */
61
64
  /**
62
- * WebSocket close reasons are capped at 123 UTF-8 bytes (RFC 6455 §5.5.1).
65
+ * WebSocket close reasons are capped at 123 UTF-8 bytes (RFC 6455, section 5.5.1).
63
66
  * A reason longer than that makes `ws.close()` throw a RangeError, which —
64
67
  * thrown from an async message handler — surfaces as an unhandled rejection
65
68
  * and skips the close entirely. Truncate on a byte boundary and drop any
@@ -88,6 +91,8 @@ export interface AgentWsHandlerDeps {
88
91
  stepIndex: number;
89
92
  lines: string[];
90
93
  timestamp: number;
94
+ /** Absent when the agent does not report a stream; read as `stdout`. */
95
+ stream?: LogStream;
91
96
  }) => void;
92
97
  /** Optional callback when agent sends step status updates. */
93
98
  onStepStatus?: (agentId: string, msg: {
@@ -141,7 +146,17 @@ export interface AgentWsHandlerDeps {
141
146
  }) => void;
142
147
  /** Optional callback when agent acknowledges config (for MMDS clearing in Firecracker). */
143
148
  onConfigAck?: (agentId: string) => void;
144
- /** Optional callback when agent emits a custom event via ctx.emit(). */
149
+ /**
150
+ * Optional callback when agent emits a custom event via ctx.emit().
151
+ *
152
+ * A returned `error` is relayed to the agent verbatim, and the agent runs
153
+ * untrusted workflow code that persists it into the author's step logs — so
154
+ * an implementation may only return author-facing wording (an unknown job
155
+ * context). Raw exception text belongs in the implementation's own
156
+ * `logger.*`, with {@link AgentWsInternalFailure.eventEmitFailed} returned in
157
+ * its place; a thrown exception is already replaced with the same string
158
+ * here.
159
+ */
145
160
  onEventEmit?: (agentId: string, msg: {
146
161
  jobId: string;
147
162
  requestId: string;
@@ -185,6 +200,12 @@ export interface AgentWsHandlerDeps {
185
200
  * which org/repo/scope that job resolves to.
186
201
  */
187
202
  dispatchCacheRefs?: DispatchCacheRefTracker;
203
+ /**
204
+ * User-facing artifact store for serving `artifacts.*` upload/download
205
+ * requests from the sandbox. The org (`customer_id`) + runId are resolved
206
+ * server-side from the job's dispatch ref, NEVER from the wire body.
207
+ */
208
+ artifactStore?: ArtifactStore;
188
209
  /** Cache storage for setting metadata after upload completion. */
189
210
  cacheStorage?: CacheStorage;
190
211
  /**
@@ -253,7 +274,15 @@ export interface AgentWsHandlerDeps {
253
274
  }>) => Promise<void>;
254
275
  /** Agent metrics aggregator for receiving pushed metrics. */
255
276
  agentMetricsAggregator?: AgentMetricsAggregator;
256
- /** Optional callback when agent reports a job belongs to a concurrency group. */
277
+ /**
278
+ * Optional callback when agent reports a job belongs to a concurrency group.
279
+ *
280
+ * A returned `reason` is relayed to the agent verbatim as the
281
+ * `job.concurrency.ack` reason, and the agent runs untrusted workflow code
282
+ * that persists it into the author's step logs — so an implementation may
283
+ * only return author-facing wording (the group the job queued behind). Raw
284
+ * exception text belongs in the implementation's own `logger.*`.
285
+ */
257
286
  onConcurrencyReport?: (agentId: string, msg: {
258
287
  runId: string;
259
288
  jobId: string;
@@ -271,6 +300,13 @@ export interface AgentWsHandlerDeps {
271
300
  * resolution back to the originating agent as a `step.approval-resolved`
272
301
  * message. The `agentId` lets the server drop the pending resolver when the
273
302
  * agent disconnects.
303
+ *
304
+ * The resolved `reason` is relayed to the agent verbatim, and the agent runs
305
+ * untrusted workflow code that persists it into the author's step logs — so
306
+ * an implementation may only resolve with author-facing wording (an
307
+ * approver's decline note, an invalid per-gate timeout). Raw exception text
308
+ * belongs in the implementation's own `logger.*`; a rejected promise is
309
+ * already replaced with {@link AgentWsInternalFailure.approvalFailed} here.
274
310
  */
275
311
  onStepApproval?: (agentId: string, msg: {
276
312
  runId: string;
@@ -309,5 +345,25 @@ export interface AgentWsHandlerDeps {
309
345
  */
310
346
  fleetAgentCollector?: FleetAgentCollector;
311
347
  }
348
+ /**
349
+ * FAST PATH: Manual type guard for log.chunk messages.
350
+ *
351
+ * Skips Zod safeParse() on authenticated connections for this high-frequency message type.
352
+ *
353
+ * SYNC INVARIANT: This manual validator MUST match the Zod schema
354
+ * `agentLogChunkSchema` in packages/engine/src/protocol/messages/orchestrator-agent.ts.
355
+ * If you change the schema, update this validator in the same commit.
356
+ * See CLAUDE.md rule: "Zod fast-path sync invariant".
357
+ */
358
+ export declare function isValidLogChunk(raw: unknown): raw is {
359
+ type: 'log.chunk';
360
+ messageId: string;
361
+ runId: string;
362
+ jobId: string;
363
+ stepIndex: number;
364
+ lines: string[];
365
+ timestamp: number;
366
+ stream?: LogStream;
367
+ };
312
368
  export declare function createAgentWsHandler(deps: AgentWsHandlerDeps): WSEvents;
313
369
  //# sourceMappingURL=agent-handler.d.ts.map
@@ -1,3 +1,5 @@
1
+ import { AgentDeliveryMode, AgentPlatform } from '@kici-dev/shared';
2
+ import { type AgentPackageDownloadStorage } from '../agent-packaging/download.js';
1
3
  import { type HostRosterStore } from '../agent/host-roster.js';
2
4
  import type { AgentRegistry } from '../agent/registry.js';
3
5
  import type { AgentTokenStore } from '../agent/token-store.js';
@@ -21,6 +23,15 @@ export interface BringupApiDeps {
21
23
  resolveOrgId: () => string;
22
24
  /** Resolve the orchestrator WS URL the init-runner should dial. */
23
25
  resolveOrchestratorUrl: () => string;
26
+ /** Resolve the orchestrator's own version — the payload version to stage on bring-up. */
27
+ resolveVersion: () => string;
28
+ /**
29
+ * The cache-bucket agent-package store, present only when S3 cache storage is
30
+ * configured. Backs the `s3-direct` delivery mode: the handler mints a
31
+ * box-routable presigned download URL for a probed platform. Absent ⇒ every
32
+ * bring-up falls back to `ssh-push` and the presign RPC is refused.
33
+ */
34
+ agentPackages?: AgentPackageDownloadStorage;
24
35
  }
25
36
  /**
26
37
  * Reach the calling agent connects to + the resolved private key. Returned to
@@ -44,6 +55,15 @@ export interface EnsureInitRunnerResult {
44
55
  orchestratorUrl?: string;
45
56
  /** The init-runner label set the bootstrap token is bound to. */
46
57
  labels?: string[];
58
+ /** The orchestrator's own version — the self-contained payload version to stage. */
59
+ version?: string;
60
+ /**
61
+ * Per-host delivery mode the agent uses to stage the payload: `s3-direct` when
62
+ * the host is declared object-storage-reachable AND a cache store is
63
+ * configured, else `ssh-push`. The agent probes the platform then requests the
64
+ * presigned URL via `kici.presignAgentPackage` for the `s3-direct` case.
65
+ */
66
+ deliveryMode?: AgentDeliveryMode;
47
67
  }
48
68
  /** Result the agent receives for a `preBootSend` call. */
49
69
  export interface PreBootSendResult {
@@ -66,6 +86,85 @@ export declare class CapabilityDeniedError extends Error {
66
86
  * agent needs to drop + start the init-runner over SSH.
67
87
  */
68
88
  export declare function createEnsureInitRunnerHandler(deps: BringupApiDeps): (callingAgentId: string, params: Record<string, unknown>) => Promise<EnsureInitRunnerResult>;
89
+ /** Result the agent receives for a `presignAgentPackage` call. */
90
+ export interface PresignAgentPackageResult {
91
+ url: string;
92
+ /** The expected sha256 (hex), or null when the producer wrote no sidecar. */
93
+ sha256: string | null;
94
+ }
95
+ /**
96
+ * Build the `kici.presignAgentPackage` handler — the follow-up RPC the ops agent
97
+ * calls AFTER it probes the target platform (so the presign is keyed by the real
98
+ * platform). Same capability gate + access-log as the bring-up. Mints a
99
+ * box-routable presigned GET URL for the version-keyed payload from the
100
+ * orchestrator's own cache bucket; no standing S3 credential leaves the
101
+ * orchestrator. A missing payload object throws loudly (never a silent stale
102
+ * stage). Used by BOTH delivery paths: for `s3-direct` the URL goes to the box;
103
+ * for `ssh-push` the ops agent fetches it and streams the bytes onward.
104
+ */
105
+ export declare function createPresignAgentPackageHandler(deps: BringupApiDeps): (callingAgentId: string, params: Record<string, unknown>) => Promise<PresignAgentPackageResult>;
106
+ /** How the ops agent drains + restarts a re-staged host + where its install lives. */
107
+ export interface AgentRestartSpec {
108
+ stop: string;
109
+ start: string;
110
+ installDir?: string;
111
+ }
112
+ /**
113
+ * Map a roster row's os/arch tokens to an {@link AgentPlatform}, or null when the
114
+ * host's platform is unknown / unsupported (so availability falls back to the
115
+ * whole bootstrap set). Accepts both `uname` (`x86_64`/`aarch64`) and Node
116
+ * (`x64`/`arm64`) arch spellings.
117
+ */
118
+ export declare function archToAgentPlatform(platform: string | null, arch: string | null): AgentPlatform | null;
119
+ /**
120
+ * Derive the drain/restart spec from a host's declared properties. Explicit
121
+ * stop/start commands win; otherwise a declared systemd service name maps to
122
+ * `systemctl --user stop|start <svc>`. Returns null when neither is declared —
123
+ * the orchestrator then cannot re-stage the host (it does not know how to
124
+ * restart it) and the caller refuses loudly.
125
+ */
126
+ export declare function resolveRestartSpec(properties: Record<string, unknown>): AgentRestartSpec | null;
127
+ /** Result the check-step receives for a `kici.agentVersionStatus` read. */
128
+ export interface AgentVersionStatusResult {
129
+ /** The orchestrator's own version — the convergence target. */
130
+ targetVersion: string;
131
+ /** The version last staged onto the host, or null when never staged. */
132
+ stagedVersion: string | null;
133
+ /** True only when the target's payload objects exist for the host's platform. */
134
+ available: boolean;
135
+ }
136
+ /**
137
+ * Build the `kici.agentVersionStatus` read handler — the availability-gate probe
138
+ * the convergence check-step calls. Returns the target version, the host's
139
+ * recorded staged version, and whether the target's payloads are available for
140
+ * the host's platform (the whole bootstrap set when the platform is unknown). No
141
+ * SSH, no token — a pure read, but same capability gate + audit as the bring-up.
142
+ */
143
+ export declare function createAgentVersionStatusHandler(deps: BringupApiDeps): (callingAgentId: string, params: Record<string, unknown>) => Promise<AgentVersionStatusResult>;
144
+ /** Material the ops agent receives for a `kici.restageAgent` call. */
145
+ export interface RestageAgentResult {
146
+ /** How to SSH to the target host. */
147
+ reach: BringupReach;
148
+ /** The resolved bring-up private key (custodied by the ops agent). */
149
+ privateKey: string;
150
+ /** The target version to converge onto (the orchestrator's own). */
151
+ version: string;
152
+ /** Per-host delivery mode (`s3-direct` when reachable + a store is configured). */
153
+ deliveryMode: AgentDeliveryMode;
154
+ /** How the ops agent drains + restarts the host after the install swap. */
155
+ restart: AgentRestartSpec;
156
+ }
157
+ /**
158
+ * Build the `kici.restageAgent` handler — the availability-gated, external-actor
159
+ * re-stage authorization. Gates on the caller's `ssh-transport` capability,
160
+ * REFUSES loudly when the target version's payloads are unavailable for the
161
+ * host's platform (belt-and-suspenders over the check-step gate — never a
162
+ * skew), resolves the host reach + SSH key + restart spec, records the staged
163
+ * version, audits, and returns the material the ops agent needs to swap + restart
164
+ * the target's agent over SSH. Mints NO token: the re-staged permanent agent
165
+ * reconnects on its own persistent credential (no self-update-handoff).
166
+ */
167
+ export declare function createRestageAgentHandler(deps: BringupApiDeps): (callingAgentId: string, params: Record<string, unknown>) => Promise<RestageAgentResult>;
69
168
  /**
70
169
  * Build the `kici.preBootSend` handler. Gates on the caller's capability,
71
170
  * resolves the pre-boot input secret (e.g. a LUKS passphrase), audits, and
@@ -19,16 +19,15 @@ import type { VariableStore } from '../contexts/variable-store.js';
19
19
  import type { BindingStore } from '../contexts/binding-store.js';
20
20
  import type { Database } from '../db/types.js';
21
21
  import type { AccessLogWriter } from '../audit/access-log.js';
22
- /** Secret store interface (subset of PgSecretStore methods used here). */
23
- interface SecretStoreForDashboard {
24
- listScopes(orgId: string): Promise<string[]>;
25
- listKeys(orgId: string, scope: string): Promise<string[]>;
26
- setSecret(orgId: string, scope: string, key: string, value: string): Promise<void>;
27
- deleteSecret(orgId: string, scope: string, key: string): Promise<void>;
28
- createScope?(orgId: string, scope: string): Promise<void>;
29
- renameScope?(orgId: string, oldScope: string, newScope: string): Promise<void>;
30
- deleteScope?(orgId: string, scope: string): Promise<void>;
31
- }
22
+ import { type ScopedSecretStore } from '../secrets/scope-routing.js';
23
+ import type { ResolvedDashboardEncryptionKey } from '../secrets/dashboard-encryption-key.js';
24
+ /**
25
+ * Secret store interface (subset of PgSecretStore methods used here).
26
+ *
27
+ * Alias of the shared `ScopedSecretStore` so the WS plane and the HTTP admin
28
+ * plane route scopes against one contract.
29
+ */
30
+ type SecretStoreForDashboard = ScopedSecretStore;
32
31
  export interface DashboardContextHandlerDeps {
33
32
  /** Organization ID for all operations. */
34
33
  orgId: string;
@@ -54,6 +53,15 @@ export interface DashboardContextHandlerDeps {
54
53
  * handlers fall back to the direct status flip.
55
54
  */
56
55
  approvals?: ApprovalHandlerDeps;
56
+ /**
57
+ * Dashboard-encryption key resolver. Present when KICI_SECRET_KEY is
58
+ * configured. Under the `encrypted` posture the secret/variable set handlers
59
+ * decrypt the browser-sealed envelope with the resolved private key. Absent ⇒
60
+ * `encrypted` writes fail closed (`encryption_unavailable`).
61
+ */
62
+ dashboardEncryption?: {
63
+ resolve: () => Promise<ResolvedDashboardEncryptionKey | null>;
64
+ };
57
65
  }
58
66
  /** Dependencies enabling the resolver-backed approve/reject + resume path. */
59
67
  export interface ApprovalHandlerDeps {
@@ -92,6 +100,16 @@ export declare class DashboardContextHandler {
92
100
  * sends a structured `operation_disabled` envelope back to Platform.
93
101
  */
94
102
  private enforcePolicy;
103
+ /**
104
+ * Resolve the plaintext value for a secret/variable set under the write
105
+ * policy. When the client sends a `sealed` envelope, decrypt it with the
106
+ * orchestrator's X25519 key (honored regardless of posture — the client chose
107
+ * to seal, so never expose that plaintext through the Platform). Otherwise,
108
+ * under the `encrypted` posture a plaintext `value` is refused (fail-closed);
109
+ * under `permissive` the plaintext `value` is used. Returns the plaintext or a
110
+ * structured error code the caller records + sends back.
111
+ */
112
+ private resolveWriteValue;
95
113
  /**
96
114
  * Write an access_log row for a handler invocation. Uses the handler's
97
115
  * bound orgId + routingKey, the msg.actor principal, and the handler-
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Orchestrator-side handler for the `dashboard.run.state` system reconciliation
3
+ * read.
4
+ *
5
+ * The Platform's `RunMirrorReconciler` issues this request for a run that is
6
+ * stuck non-terminal in the Platform mirror to recover a terminal frame that was
7
+ * dropped on a live Platform↔orchestrator connection. It projects the current
8
+ * `execution_runs` + `execution_jobs` state for one run into the same
9
+ * `StateReplayRun` shape the reconnect `state.replay` push carries, so the
10
+ * Platform can drive it through the shared `upsertRunMirror` helper.
11
+ *
12
+ * Unlike the user-plane `dashboard.run.detail` read, this handler does NOT write
13
+ * an `access_log` row: it is a system reconciliation read (a `system` actor),
14
+ * not a user data access. The handler is pure (deps passed as arguments) so the
15
+ * WS wiring in `server.ts` stays a thin adapter and the logic is unit-testable
16
+ * without a live Platform connection.
17
+ */
18
+ import type { Kysely } from 'kysely';
19
+ import type { Database } from '../db/types.js';
20
+ import { type DashboardRunStateRequest, type DashboardRunStateResponse } from '@kici-dev/engine';
21
+ export interface RunStateHandlerDeps {
22
+ db: Kysely<Database>;
23
+ }
24
+ /**
25
+ * Build the `StateReplayRun` projection for one run, or `null` when the
26
+ * orchestrator has no such run. Mirrors the DB-backed branch of
27
+ * `ExecutionTracker.getReplayDataWithDb` (jobs = id/name/status;
28
+ * `jobCount = jobs.length`; `triggerEvent`/`commitMessage` omitted — no columns).
29
+ */
30
+ export declare function handleRunState(deps: RunStateHandlerDeps, req: DashboardRunStateRequest): Promise<DashboardRunStateResponse>;
31
+ //# sourceMappingURL=dashboard-run-state-handler.d.ts.map
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Safe, fixed messages the orchestrator sends to the agent (and through it to
3
+ * the workflow author) when an agent-WS request fails for an internal reason.
4
+ *
5
+ * These are presentation strings, not a wire vocabulary: the protocol carries
6
+ * them in the free-text `reason` field of `step.approval-resolved` and in the
7
+ * free-text `error` field of `event.emit.response` / `agent.api.response`, so an
8
+ * orchestrator is free to reword them without any agent-side change. They live
9
+ * in one module — rather than inline at each send site — so the handler, its
10
+ * tests and the `onEventEmit` callback in `app.ts` cannot drift apart.
11
+ *
12
+ * Raw exception text is never one of these. Exceptions stay in the
13
+ * orchestrator's own logs; the author sees only "this is an orchestrator
14
+ * problem", never a database endpoint, a constraint name or a stack frame.
15
+ *
16
+ * Author-actionable failures do not come through here at all — they ride the
17
+ * callback's return value with its own safe wording (an unknown job context, an
18
+ * approval bridge's timeout reason), which stays specific enough to debug a bad
19
+ * workflow without operator log access.
20
+ */
21
+ export declare const AgentWsInternalFailure: Readonly<{
22
+ /** The step-approval bridge rejected instead of resolving the hold. */
23
+ readonly approvalFailed: 'the orchestrator hit an internal error while resolving this approval';
24
+ /** The event router threw while emitting the agent's event. */
25
+ readonly eventEmitFailed: 'the orchestrator hit an internal error while emitting this event';
26
+ /** An agent private-API handler threw for a reason other than its two deliberate rejections. */
27
+ readonly agentApiFailed: 'the orchestrator hit an internal error while handling this API request';
28
+ }>;
29
+ //# sourceMappingURL=failure-messages.d.ts.map
@@ -1,6 +1,15 @@
1
1
  /**
2
2
  * Provenance ID-token relay (orchestrator side).
3
3
  *
4
+ * @deprecated The Platform-rooted identity mint is hard-deprecated in favor of
5
+ * orchestrator-owned signing (`oidc/orchestrator-mint.ts`). This relay is
6
+ * registered ONLY when the orchestrator has NO provenance signer configured
7
+ * (`selectOidcMintRegistration` prefers the orchestrator-owned mint whenever
8
+ * `KICI_ORCHESTRATOR_PROVENANCE_ISSUER` is set). It is kept wire-compatible for
9
+ * the mixed-version rollout window; the `oidc.mint.*` RPC shim is removed at
10
+ * v1.0. Existing Platform-signed bundles keep verifying forever (the Platform
11
+ * JWKS stays published). See docs/user/deprecations.md.
12
+ *
4
13
  * Backs the `oidc.token.request` agent.api method: an agent asks for a
5
14
  * short-lived OIDC ID token for a job it is running; the orchestrator verifies
6
15
  * the agent owns that job, resolves its runId from its own dispatch state, and
@@ -0,0 +1,22 @@
1
+ import type { OwnershipTracker } from '../agent/ownership-tracker.js';
2
+ /** Whether a job-scoped agent frame may be handled. */
3
+ export type OwnershipDecision = 'accept' | 'reject';
4
+ /**
5
+ * Resolve whether `agentId` may act on `jobId`, in the two steps every
6
+ * job-scoped agent frame shares.
7
+ *
8
+ * 1. No tracker configured — ownership enforcement is off; accept.
9
+ * 2. The synchronous in-memory check hits — accept without touching the
10
+ * database. This is the hot path: the owning coordinator answers from its
11
+ * own `agentJobs` map.
12
+ * 3. Otherwise resolve asynchronously. `checkOwnership` returning false is
13
+ * "not decided yet", not "refused", whenever a database fallback is
14
+ * configured — so the caller must never treat step 2 as the verdict.
15
+ *
16
+ * A `reject` is final: the caller replies with the shared refusal wording (or,
17
+ * where the message has no reply, drops the frame). What it must never do is
18
+ * drop a frame that this function has not yet ruled on — an agent awaiting an
19
+ * acknowledgment would hang until its own deadline expired.
20
+ */
21
+ export declare function gateOwnership(tracker: OwnershipTracker | undefined, agentId: string, jobId: string, messageType: string): Promise<OwnershipDecision>;
22
+ //# sourceMappingURL=ownership-gate.d.ts.map