@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b

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 (329) hide show
  1. package/README.md +183 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
  5. package/dist/bridge/bridge-chat-provider-command.js +230 -0
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.base.d.ts +9 -0
  17. package/dist/bridge/bridge.service.d.ts +102 -14
  18. package/dist/bridge/bridge.service.js +499 -471
  19. package/dist/bridge/bridge.types.d.ts +37 -0
  20. package/dist/bridge/bridge.types.js +2 -1
  21. package/dist/bridge/default-session-service.d.ts +13 -0
  22. package/dist/bridge/default-session-service.js +22 -0
  23. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  24. package/dist/bridge/dispatch-offer-policy.js +58 -0
  25. package/dist/bridge/in-flight-registry.d.ts +62 -0
  26. package/dist/bridge/in-flight-registry.js +207 -0
  27. package/dist/bridge/local-yield-flag.d.ts +6 -0
  28. package/dist/bridge/local-yield-flag.js +34 -0
  29. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  30. package/dist/bridge/readiness-result-outbox.js +20 -0
  31. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  32. package/dist/bridge/runner-host-capabilities.js +31 -1
  33. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  34. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  35. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  36. package/dist/bridge/test-postgres-capability.js +120 -0
  37. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  38. package/dist/bridge/windows-bash-resolution.js +153 -0
  39. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  40. package/dist/cleanup/cleanup-wip.js +66 -0
  41. package/dist/cleanup/cleanup.service.d.ts +20 -1
  42. package/dist/cleanup/cleanup.service.js +150 -169
  43. package/dist/cleanup/cleanup.types.d.ts +6 -0
  44. package/dist/cleanup/forge-owned-paths.d.ts +11 -0
  45. package/dist/cleanup/forge-owned-paths.js +62 -0
  46. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  47. package/dist/cleanup/host-runtime-ledger.js +130 -0
  48. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  49. package/dist/cleanup/managed-branch-sweep.js +111 -0
  50. package/dist/cli/cli.help.js +75 -13
  51. package/dist/cli/cli.service.d.ts +19 -10
  52. package/dist/cli/cli.service.js +161 -228
  53. package/dist/cli/idle-status.d.ts +84 -0
  54. package/dist/cli/idle-status.js +181 -0
  55. package/dist/cli/local-config.d.ts +18 -1
  56. package/dist/cli/local-config.js +67 -5
  57. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  58. package/dist/cli/provider-cli-advertising.js +88 -0
  59. package/dist/cli/provider-cli-detection.d.ts +10 -0
  60. package/dist/cli/provider-cli-detection.js +160 -0
  61. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  62. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  63. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  64. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  65. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  66. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  67. package/dist/runtime/attempt-process-supervisor.js +12 -6
  68. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  69. package/dist/runtime/docker-engine-probe.js +7 -0
  70. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  71. package/dist/runtime/dotnet-build-outputs.js +402 -0
  72. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  73. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  74. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  75. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  76. package/dist/runtime/host-facts.d.ts +2 -1
  77. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  78. package/dist/runtime/host-listener-inspector.js +84 -3
  79. package/dist/runtime/host-load-admission.d.ts +72 -0
  80. package/dist/runtime/host-load-admission.js +99 -0
  81. package/dist/runtime/host-load-capacity.d.ts +198 -0
  82. package/dist/runtime/host-load-capacity.js +353 -0
  83. package/dist/runtime/host-load-child-environment.d.ts +40 -0
  84. package/dist/runtime/host-load-child-environment.js +110 -0
  85. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  86. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  87. package/dist/runtime/host-load-governor-config.d.ts +82 -0
  88. package/dist/runtime/host-load-governor-config.js +104 -0
  89. package/dist/runtime/host-load-governor.d.ts +273 -0
  90. package/dist/runtime/host-load-governor.js +831 -0
  91. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  92. package/dist/runtime/host-load-ledger-lock.js +187 -0
  93. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  94. package/dist/runtime/host-load-live-test-slots.js +193 -0
  95. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  96. package/dist/runtime/host-load-runtime-settings.js +80 -0
  97. package/dist/runtime/host-load-sampler.d.ts +92 -2
  98. package/dist/runtime/host-load-sampler.js +166 -8
  99. package/dist/runtime/host-load-step-class.d.ts +70 -0
  100. package/dist/runtime/host-load-step-class.js +161 -0
  101. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  102. package/dist/runtime/host-load-step-reaper.js +95 -0
  103. package/dist/runtime/host-load-step-run.d.ts +107 -0
  104. package/dist/runtime/host-load-step-run.js +158 -0
  105. package/dist/runtime/host-load-test-slot.d.ts +46 -0
  106. package/dist/runtime/host-load-test-slot.js +100 -0
  107. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  108. package/dist/runtime/host-load-token-ledger.js +453 -0
  109. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  110. package/dist/runtime/host-load-windows-cpu.js +85 -0
  111. package/dist/runtime/host-pressure-stall.d.ts +21 -1
  112. package/dist/runtime/host-pressure-stall.js +48 -1
  113. package/dist/runtime/host-runtime-contract.d.ts +15 -0
  114. package/dist/runtime/host-runtime-contract.js +39 -6
  115. package/dist/runtime/host-runtime-lease.d.ts +101 -6
  116. package/dist/runtime/host-runtime-lease.js +408 -294
  117. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  118. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  119. package/dist/runtime/host-runtime-promotion.d.ts +101 -2
  120. package/dist/runtime/host-runtime-promotion.js +355 -14
  121. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  122. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  123. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  124. package/dist/runtime/host-runtime-requirements.js +117 -0
  125. package/dist/runtime/managed-command-teardown.js +5 -16
  126. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  127. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  128. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  129. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  130. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  131. package/dist/runtime/prepared-runtime-identity.js +130 -9
  132. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  133. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  134. package/dist/runtime/runner-settings.d.ts +104 -0
  135. package/dist/runtime/runner-settings.js +236 -0
  136. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  137. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  138. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  139. package/dist/sandbox/host-capacity-broker.js +336 -0
  140. package/dist/sandbox/managed-branch.d.ts +13 -0
  141. package/dist/sandbox/managed-branch.js +90 -0
  142. package/dist/sandbox/provider-auth/codex.js +11 -11
  143. package/dist/sandbox/runtime.d.ts +11 -3
  144. package/dist/sandbox/runtime.js +53 -20
  145. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  146. package/dist/sandbox/sandbox-cgroups.js +42 -0
  147. package/dist/sandbox/sandbox-input.d.ts +22 -0
  148. package/dist/sandbox/sandbox-input.js +49 -0
  149. package/dist/sandbox/workspace.service.js +15 -2
  150. package/dist/session/architect-waits.d.ts +2 -0
  151. package/dist/session/architect-waits.js +138 -0
  152. package/dist/session/managed-attempt-tools.d.ts +2 -7
  153. package/dist/session/managed-attempt-tools.js +204 -141
  154. package/dist/session/managed-build-coordinator.d.ts +16 -0
  155. package/dist/session/managed-build-coordinator.js +10 -0
  156. package/dist/session/managed-build-receipt.d.ts +7 -0
  157. package/dist/session/managed-build-receipt.js +11 -3
  158. package/dist/session/managed-command-environment.d.ts +8 -0
  159. package/dist/session/managed-command-environment.js +28 -0
  160. package/dist/session/managed-command-host-load.d.ts +52 -0
  161. package/dist/session/managed-command-host-load.js +87 -0
  162. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  163. package/dist/session/mcp-argument-coercion.js +121 -0
  164. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  165. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  166. package/dist/session/phase-completion.artifacts.d.ts +9 -17
  167. package/dist/session/phase-completion.artifacts.js +158 -190
  168. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  169. package/dist/session/phase-completion.command-validation.js +77 -0
  170. package/dist/session/phase-completion.d.ts +31 -2
  171. package/dist/session/phase-completion.helpers.js +18 -65
  172. package/dist/session/phase-completion.js +19 -32
  173. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  174. package/dist/session/phase-completion.mcp-args.js +195 -0
  175. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  176. package/dist/session/phase-completion.phase-aliases.js +43 -0
  177. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  178. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  179. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  180. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  181. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  182. package/dist/session/phase-completion.pr-review.js +294 -0
  183. package/dist/session/phase-completion.prompts.d.ts +1 -1
  184. package/dist/session/phase-completion.prompts.js +20 -1
  185. package/dist/session/phase-completion.runtime.d.ts +13 -12
  186. package/dist/session/phase-completion.runtime.js +113 -214
  187. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  188. package/dist/session/phase-completion.schema-parts.js +188 -0
  189. package/dist/session/phase-completion.schemas.d.ts +3 -3
  190. package/dist/session/phase-completion.schemas.js +219 -232
  191. package/dist/session/phase-completion.validation.d.ts +3 -3
  192. package/dist/session/phase-completion.validation.js +58 -94
  193. package/dist/session/pr-review-diff-base.d.ts +18 -0
  194. package/dist/session/pr-review-diff-base.js +44 -0
  195. package/dist/session/pr-review-placement.d.ts +50 -0
  196. package/dist/session/pr-review-placement.js +91 -0
  197. package/dist/session/pre-publication-change-set.d.ts +62 -0
  198. package/dist/session/pre-publication-change-set.js +166 -0
  199. package/dist/session/pre-publication-host-load.d.ts +27 -0
  200. package/dist/session/pre-publication-host-load.js +112 -0
  201. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  202. package/dist/session/pre-publication-native-postgres.js +111 -0
  203. package/dist/session/pre-publication-pass.d.ts +61 -0
  204. package/dist/session/pre-publication-pass.js +148 -0
  205. package/dist/session/pre-publication-process.d.ts +3 -0
  206. package/dist/session/pre-publication-process.js +32 -19
  207. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  208. package/dist/session/pre-publication-step-execution.js +50 -0
  209. package/dist/session/pre-publication-validation.d.ts +39 -22
  210. package/dist/session/pre-publication-validation.js +241 -207
  211. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  212. package/dist/session/provider-cli/claude-background-work.js +181 -0
  213. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  214. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  215. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  216. package/dist/session/provider-cli/host-build-lock.js +30 -0
  217. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  218. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  219. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  220. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  221. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  222. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  223. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  224. package/dist/session/provider-cli/pre-publication-repair.js +281 -0
  225. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  226. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  227. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  228. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  229. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  230. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  231. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  232. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  233. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  234. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  235. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  236. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  237. package/dist/session/provider-cli/provider-cli.process.js +41 -432
  238. package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
  239. package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
  240. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  241. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  242. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  243. package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
  244. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  245. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  246. package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
  247. package/dist/session/provider-cli/provider-cli.service.js +127 -317
  248. package/dist/session/provider-cli/provider-cli.types.d.ts +35 -0
  249. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  250. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  251. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  252. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  253. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  254. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  255. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  256. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  257. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  258. package/dist/session/provider-cli/provider-output-state.js +6 -0
  259. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  260. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  261. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  262. package/dist/session/qa-sidecar-validation.js +28 -0
  263. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  264. package/dist/session/sandbox-host-capacity-gate.js +279 -0
  265. package/dist/session/session-host-project.d.ts +22 -0
  266. package/dist/session/session-host-project.js +98 -0
  267. package/dist/session/session-redaction.js +31 -181
  268. package/dist/session/session.base.d.ts +9 -1
  269. package/dist/session/session.parse-helpers.d.ts +10 -0
  270. package/dist/session/session.parse-helpers.js +84 -0
  271. package/dist/session/session.runtime-refresh.d.ts +46 -0
  272. package/dist/session/session.runtime-refresh.js +116 -0
  273. package/dist/session/session.service.d.ts +16 -2
  274. package/dist/session/session.service.js +208 -155
  275. package/dist/session/session.types.d.ts +8 -0
  276. package/dist/session/session.types.js +13 -83
  277. package/dist/session/session.types.pr-review.d.ts +48 -0
  278. package/dist/session/session.types.pr-review.js +51 -0
  279. package/dist/session/sidecar-json-shape.d.ts +31 -0
  280. package/dist/session/sidecar-json-shape.js +217 -0
  281. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  282. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  283. package/dist/shared/fs/file-identity.d.ts +10 -0
  284. package/dist/shared/fs/file-identity.js +15 -0
  285. package/dist/shared/fs/replace-file.d.ts +7 -0
  286. package/dist/shared/fs/replace-file.js +33 -0
  287. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  288. package/dist/shared/process/host-process-recovery.js +23 -3
  289. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  290. package/dist/shared/process/host-process-supervisor.js +67 -15
  291. package/dist/shared/process/process-tree.d.ts +52 -0
  292. package/dist/shared/process/process-tree.js +144 -0
  293. package/dist/shared/process/process.d.ts +67 -0
  294. package/dist/shared/process/process.js +213 -11
  295. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  296. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  297. package/dist/shared/process/windows-launch.d.ts +18 -0
  298. package/dist/shared/process/windows-launch.js +68 -0
  299. package/dist/shared/provider-capabilities.d.ts +2 -0
  300. package/dist/shared/provider-capabilities.js +23 -7
  301. package/dist/version.d.ts +1 -1
  302. package/dist/version.js +1 -1
  303. package/dist/worktree/artifact-injector.js +24 -0
  304. package/dist/worktree/dependency-warmer.d.ts +25 -0
  305. package/dist/worktree/dependency-warmer.js +46 -10
  306. package/dist/worktree/orphan-relink.d.ts +19 -0
  307. package/dist/worktree/orphan-relink.js +106 -0
  308. package/dist/worktree/wip-git.d.ts +58 -0
  309. package/dist/worktree/wip-git.js +182 -0
  310. package/dist/worktree/wip-refs.d.ts +85 -0
  311. package/dist/worktree/wip-refs.js +169 -0
  312. package/dist/worktree/wip-restore.d.ts +51 -0
  313. package/dist/worktree/wip-restore.js +324 -0
  314. package/dist/worktree/wip-snapshot.d.ts +53 -0
  315. package/dist/worktree/wip-snapshot.js +270 -0
  316. package/dist/worktree/worktree-inputs.d.ts +8 -0
  317. package/dist/worktree/worktree-inputs.js +134 -0
  318. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  319. package/dist/worktree/worktree-origin-sync.js +128 -0
  320. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  321. package/dist/worktree/worktree-wip-events.js +148 -0
  322. package/dist/worktree/worktree-wip.d.ts +57 -0
  323. package/dist/worktree/worktree-wip.js +200 -0
  324. package/dist/worktree/worktree.base.d.ts +7 -1
  325. package/dist/worktree/worktree.service.d.ts +58 -5
  326. package/dist/worktree/worktree.service.js +237 -161
  327. package/dist/worktree/worktree.types.d.ts +54 -0
  328. package/package.json +2 -2
  329. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -0,0 +1,40 @@
1
+ import { type HostCapacitySpec } from "./host-load-capacity.js";
2
+ import { HostLoadGovernor } from "./host-load-governor.js";
3
+ export declare const hostLoadGovernorEnvironment = "FORGE_HOST_LOAD_GOVERNOR";
4
+ export declare const hostLoadStateRootEnvironment = "FORGE_HOST_LOAD_STATE_ROOT";
5
+ export declare const hostLoadTestSlotsEnvironment = "FORGE_HOST_LOAD_TEST_SLOTS";
6
+ /** True for the variables that carry the governor into a child process. */
7
+ /**
8
+ * A process environment with every host load governor variable removed
9
+ * (FORGE_HOST_LOAD_*, any case) and the governor turned off explicitly. A governed
10
+ * step's own processes must never join the host ledger, or broker control, that
11
+ * their step's token is held in; since the host test slot is on by default
12
+ * (decision 0018), removing the variables alone would not keep a nested Forge
13
+ * process out.
14
+ */
15
+ export declare function withoutHostLoadGovernorVariables<T extends Readonly<Record<string, string | undefined>>>(environment: T): T;
16
+ export declare function isHostLoadChildEnvironmentName(name: string): boolean;
17
+ /**
18
+ * The variables a child needs to share this bridge's ledger: the budget flag and
19
+ * the host test slot count as this bridge resolved them, the state root, the
20
+ * operator's FORGE_HOST_LOAD_* tuning and the bridge's cgroup unit. Empty with
21
+ * the governor off, so the child stays ungoverned.
22
+ */
23
+ export declare function hostLoadChildEnvironment(stateRoot: string, environment?: Readonly<Record<string, string | undefined>>): Readonly<Record<string, string>>;
24
+ export declare const testMaxParallelClassesEnvironment = "FORGE_TEST_MAX_PARALLEL_CLASSES";
25
+ /**
26
+ * A governed step's environment plus FORGE_TEST_MAX_PARALLEL_CLASSES sized for one host test
27
+ * slot's share of the machine, when the host runs more than one heavy step at once: two .NET
28
+ * suites must not each size their test-class parallelism for the whole host. A value the step
29
+ * or the operator set is kept, and with one slot nothing is added (the framework's own default
30
+ * already fits). The share uses the configured slot count, not the live one: a suite keeps the
31
+ * parallelism it started with, and a busy host is no reason to give it more.
32
+ *
33
+ * @param governorEnvironment where the slot count is read (the bridge's or MCP server's own).
34
+ */
35
+ export declare function withHostTestParallelism<T extends Readonly<Record<string, string | undefined>>>(environment: T, governorEnvironment?: Readonly<Record<string, string | undefined>>, host?: HostCapacitySpec | null): T;
36
+ /**
37
+ * The governor a child process uses, from the variables above. Undefined when
38
+ * the governor is off or no state root was handed over: the child is ungoverned.
39
+ */
40
+ export declare function hostLoadGovernorFromChildEnvironment(environment?: Readonly<Record<string, string | undefined>>): HostLoadGovernor | undefined;
@@ -0,0 +1,110 @@
1
+ import path from "node:path";
2
+ import { detectHostCapacitySpec, testParallelClassesPerSlot } from "./host-load-capacity.js";
3
+ import { HostLoadGovernor } from "./host-load-governor.js";
4
+ import { hostLoadGovernorEnabled, loadHostLoadGovernorConfig } from "./host-load-governor-config.js";
5
+ import { FileForgeCgroupRegistry } from "./host-load-forge-cgroups.js";
6
+ import { HostLoadSampler } from "./host-load-sampler.js";
7
+ // How a process the bridge starts (the completion MCP server, which runs
8
+ // managed commands) joins the bridge's host load governor (decision 0013).
9
+ // The ledger is file-backed, so the child builds its own governor on the
10
+ // bridge's state root and every token counts against one host budget.
11
+ export const hostLoadGovernorEnvironment = "FORGE_HOST_LOAD_GOVERNOR";
12
+ export const hostLoadStateRootEnvironment = "FORGE_HOST_LOAD_STATE_ROOT";
13
+ export const hostLoadTestSlotsEnvironment = "FORGE_HOST_LOAD_TEST_SLOTS";
14
+ const cgroupUnitEnvironment = "FORGE_BRIDGE_CGROUP_UNIT";
15
+ /** True for the variables that carry the governor into a child process. */
16
+ /**
17
+ * A process environment with every host load governor variable removed
18
+ * (FORGE_HOST_LOAD_*, any case) and the governor turned off explicitly. A governed
19
+ * step's own processes must never join the host ledger, or broker control, that
20
+ * their step's token is held in; since the host test slot is on by default
21
+ * (decision 0018), removing the variables alone would not keep a nested Forge
22
+ * process out.
23
+ */
24
+ export function withoutHostLoadGovernorVariables(environment) {
25
+ const kept = {};
26
+ for (const [name, value] of Object.entries(environment)) {
27
+ if (!name.toUpperCase().startsWith("FORGE_HOST_LOAD_"))
28
+ kept[name] = value;
29
+ }
30
+ kept[hostLoadGovernorEnvironment] = "off";
31
+ kept[hostLoadTestSlotsEnvironment] = "0";
32
+ return kept;
33
+ }
34
+ // Decision 0014 operator ceilings the child's governor applies itself (host-load-governor-config.ts).
35
+ const hostCeilingEnvironmentNames = new Set(["FORGE_HOST_CPU_BUDGET_PERCENT", "FORGE_HOST_MAX_HEAVY_STEPS"]);
36
+ export function isHostLoadChildEnvironmentName(name) {
37
+ return name.startsWith("FORGE_HOST_LOAD_") || name === cgroupUnitEnvironment || hostCeilingEnvironmentNames.has(name);
38
+ }
39
+ /**
40
+ * The variables a child needs to share this bridge's ledger: the budget flag and
41
+ * the host test slot count as this bridge resolved them, the state root, the
42
+ * operator's FORGE_HOST_LOAD_* tuning and the bridge's cgroup unit. Empty with
43
+ * the governor off, so the child stays ungoverned.
44
+ */
45
+ export function hostLoadChildEnvironment(stateRoot, environment = process.env) {
46
+ const config = loadHostLoadGovernorConfig(environment);
47
+ if (!hostLoadGovernorEnabled(config))
48
+ return {};
49
+ const forwarded = {};
50
+ for (const [name, value] of Object.entries(environment)) {
51
+ if (typeof value === "string" && value.trim() && isHostLoadChildEnvironmentName(name))
52
+ forwarded[name] = value;
53
+ }
54
+ forwarded[hostLoadGovernorEnvironment] = config.mode;
55
+ // The operator's count is handed over as resolved. An auto-sized count is not: the child
56
+ // sizes the same host itself and keeps it labelled auto, with live adjustment of its own.
57
+ if (config.testSlotsSource === "auto")
58
+ delete forwarded[hostLoadTestSlotsEnvironment];
59
+ else
60
+ forwarded[hostLoadTestSlotsEnvironment] = String(config.testSlots);
61
+ forwarded[hostLoadStateRootEnvironment] = path.resolve(stateRoot);
62
+ return forwarded;
63
+ }
64
+ export const testMaxParallelClassesEnvironment = "FORGE_TEST_MAX_PARALLEL_CLASSES";
65
+ // hostRuntimeTestPostgresAdminEnvironment (host-runtime-contract.ts): set when the step's tests use
66
+ // the native PostgreSQL fallback, whose classes cost more memory each.
67
+ const testPostgresAdminEnvironment = "FORGE_TEST_POSTGRES_ADMIN_CONNECTION_STRING";
68
+ /**
69
+ * A governed step's environment plus FORGE_TEST_MAX_PARALLEL_CLASSES sized for one host test
70
+ * slot's share of the machine, when the host runs more than one heavy step at once: two .NET
71
+ * suites must not each size their test-class parallelism for the whole host. A value the step
72
+ * or the operator set is kept, and with one slot nothing is added (the framework's own default
73
+ * already fits). The share uses the configured slot count, not the live one: a suite keeps the
74
+ * parallelism it started with, and a busy host is no reason to give it more.
75
+ *
76
+ * @param governorEnvironment where the slot count is read (the bridge's or MCP server's own).
77
+ */
78
+ export function withHostTestParallelism(environment, governorEnvironment = process.env, host = detectHostCapacitySpec()) {
79
+ if (namedValue(environment, testMaxParallelClassesEnvironment) !== undefined || !host)
80
+ return environment;
81
+ const config = loadHostLoadGovernorConfig(governorEnvironment, host);
82
+ // The step's own environment decides: prePublicationChildEnvironment strips the admin connection
83
+ // from a step that runs in container mode, even when the governor's process has one.
84
+ const native = namedValue(environment, testPostgresAdminEnvironment) !== undefined;
85
+ const classes = config.testSlots > 1 ? testParallelClassesPerSlot(host, config.testSlots, native) : null;
86
+ return classes === null ? environment : { ...environment, [testMaxParallelClassesEnvironment]: String(classes) };
87
+ }
88
+ /** A non-empty variable, matched without case (Windows environment names are case-insensitive). */
89
+ function namedValue(environment, wanted) {
90
+ return Object.entries(environment).find(([name, value]) => name.toUpperCase() === wanted && Boolean(value?.trim()))?.[1];
91
+ }
92
+ /**
93
+ * The governor a child process uses, from the variables above. Undefined when
94
+ * the governor is off or no state root was handed over: the child is ungoverned.
95
+ */
96
+ export function hostLoadGovernorFromChildEnvironment(environment = process.env) {
97
+ const config = loadHostLoadGovernorConfig(environment);
98
+ const stateRoot = environment[hostLoadStateRootEnvironment]?.trim();
99
+ if (!hostLoadGovernorEnabled(config) || !stateRoot || !path.isAbsolute(stateRoot))
100
+ return undefined;
101
+ return new HostLoadGovernor({
102
+ stateRoot,
103
+ config,
104
+ load: new HostLoadSampler({
105
+ cgroupUnit: environment[cgroupUnitEnvironment]?.trim() || null,
106
+ // The bridge registers its Docker sandboxes here: their CPU is Forge's own here too.
107
+ forgeCgroups: new FileForgeCgroupRegistry(stateRoot),
108
+ }),
109
+ });
110
+ }
@@ -0,0 +1,49 @@
1
+ import { type HostEnvironment } from "./host-facts.js";
2
+ /** Where a sampler learns which cgroups hold Forge's own Docker sandbox work. */
3
+ export interface ForgeCgroupSource {
4
+ paths(): readonly string[] | Promise<readonly string[]>;
5
+ }
6
+ /** Where the sandbox runtime records the cgroups of the containers it launched. */
7
+ export interface ForgeCgroupWriter {
8
+ set(owner: string, cgroupPaths: readonly string[]): void;
9
+ delete(owner: string): void;
10
+ }
11
+ /** Cgroups of Docker sandbox containers this bridge launched (paths below the cgroup root). */
12
+ export declare class ForgeCgroupRegistry implements ForgeCgroupSource, ForgeCgroupWriter {
13
+ private readonly entries;
14
+ set(owner: string, cgroupPaths: readonly string[]): void;
15
+ delete(owner: string): void;
16
+ paths(): readonly string[];
17
+ }
18
+ /**
19
+ * The registry shared by every process on the governor's state root: the
20
+ * bridge's sandbox runtime writes it, and both the bridge's and the MCP
21
+ * servers' samplers read it, so all of them count sandbox CPU as Forge's own.
22
+ */
23
+ export declare class FileForgeCgroupRegistry implements ForgeCgroupSource, ForgeCgroupWriter {
24
+ private readonly filePath;
25
+ private readonly registered;
26
+ private writing;
27
+ constructor(stateRoot: string);
28
+ set(owner: string, cgroupPaths: readonly string[]): void;
29
+ delete(owner: string): void;
30
+ paths(): Promise<readonly string[]>;
31
+ /** Settles once every registration so far is on disk (tests). */
32
+ flushed(): Promise<void>;
33
+ private persist;
34
+ }
35
+ /** CPU cores used by a changing set of cgroups, from `cpu.stat usage_usec` deltas. */
36
+ export declare class ForgeCgroupCpuMeter {
37
+ private readonly environment;
38
+ private marks;
39
+ constructor(environment: HostEnvironment);
40
+ /** Cores used since the previous call; a cgroup seen for the first time contributes from the next window. */
41
+ coresInUse(cgroupPaths: readonly string[], atMs: number): Promise<number>;
42
+ }
43
+ /**
44
+ * Free memory under the tightest `memory.max` from the cgroup up to and
45
+ * including the root (`memory.max − memory.current`), or null when no limit is
46
+ * set on the path. Inside a container the root is the container's own cgroup,
47
+ * whose `memory.max` is the container limit.
48
+ */
49
+ export declare function readCgroupMemoryHeadroomBytes(environment: HostEnvironment, cgroupPath: string): Promise<number | null>;
@@ -0,0 +1,140 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { readOptional } from "./host-facts.js";
5
+ import { parseCgroupCpuUsageUsec, parseNonNegativeInteger } from "./host-pressure-stall.js";
6
+ /** Cgroups of Docker sandbox containers this bridge launched (paths below the cgroup root). */
7
+ export class ForgeCgroupRegistry {
8
+ entries = new Map();
9
+ set(owner, cgroupPaths) {
10
+ if (cgroupPaths.length === 0)
11
+ this.entries.delete(owner);
12
+ else
13
+ this.entries.set(owner, [...cgroupPaths]);
14
+ }
15
+ delete(owner) {
16
+ this.entries.delete(owner);
17
+ }
18
+ paths() {
19
+ return [...new Set([...this.entries.values()].flat())];
20
+ }
21
+ }
22
+ /**
23
+ * The registry shared by every process on the governor's state root: the
24
+ * bridge's sandbox runtime writes it, and both the bridge's and the MCP
25
+ * servers' samplers read it, so all of them count sandbox CPU as Forge's own.
26
+ */
27
+ export class FileForgeCgroupRegistry {
28
+ filePath;
29
+ registered = new ForgeCgroupRegistry();
30
+ writing = Promise.resolve();
31
+ constructor(stateRoot) {
32
+ this.filePath = path.join(stateRoot, "host-load-governor", "forge-cgroups.v1.json");
33
+ }
34
+ set(owner, cgroupPaths) {
35
+ this.registered.set(owner, cgroupPaths);
36
+ this.persist();
37
+ }
38
+ delete(owner) {
39
+ this.registered.delete(owner);
40
+ this.persist();
41
+ }
42
+ paths() {
43
+ return fs.readFile(this.filePath, "utf8")
44
+ .then(content => {
45
+ const parsed = JSON.parse(content);
46
+ return Array.isArray(parsed.paths)
47
+ ? parsed.paths.filter((entry) => typeof entry === "string").slice(0, 256)
48
+ : [];
49
+ })
50
+ .catch(() => []);
51
+ }
52
+ /** Settles once every registration so far is on disk (tests). */
53
+ async flushed() {
54
+ await this.writing;
55
+ }
56
+ persist() {
57
+ const snapshot = JSON.stringify({ schemaVersion: 1, paths: this.registered.paths() });
58
+ this.writing = this.writing.then(async () => {
59
+ await fs.mkdir(path.dirname(this.filePath), { recursive: true, mode: 0o700 });
60
+ const temporary = `${this.filePath}.${process.pid}.${randomUUID()}.tmp`;
61
+ await fs.writeFile(temporary, snapshot, { mode: 0o600 });
62
+ await fs.rename(temporary, this.filePath);
63
+ }).catch(() => undefined);
64
+ }
65
+ }
66
+ /** CPU cores used by a changing set of cgroups, from `cpu.stat usage_usec` deltas. */
67
+ export class ForgeCgroupCpuMeter {
68
+ environment;
69
+ marks = new Map();
70
+ constructor(environment) {
71
+ this.environment = environment;
72
+ }
73
+ /** Cores used since the previous call; a cgroup seen for the first time contributes from the next window. */
74
+ async coresInUse(cgroupPaths, atMs) {
75
+ const next = new Map();
76
+ let cores = 0;
77
+ for (const cgroupPath of cgroupPaths) {
78
+ const directory = cgroupDirectory(this.environment, cgroupPath);
79
+ if (!directory)
80
+ continue;
81
+ const content = await readOptional(this.environment, path.posix.join(directory, "cpu.stat"));
82
+ const usageUsec = content ? parseCgroupCpuUsageUsec(content) : null;
83
+ if (usageUsec === null)
84
+ continue;
85
+ next.set(cgroupPath, { usageUsec, atMs });
86
+ const previous = this.marks.get(cgroupPath);
87
+ const elapsedUsec = previous ? (atMs - previous.atMs) * 1_000 : 0;
88
+ if (previous && elapsedUsec > 0 && usageUsec >= previous.usageUsec) {
89
+ cores += (usageUsec - previous.usageUsec) / elapsedUsec;
90
+ }
91
+ }
92
+ this.marks = next;
93
+ return cores;
94
+ }
95
+ }
96
+ /**
97
+ * Free memory under the tightest `memory.max` from the cgroup up to and
98
+ * including the root (`memory.max − memory.current`), or null when no limit is
99
+ * set on the path. Inside a container the root is the container's own cgroup,
100
+ * whose `memory.max` is the container limit.
101
+ */
102
+ export async function readCgroupMemoryHeadroomBytes(environment, cgroupPath) {
103
+ let tightest = null;
104
+ for (const current of cgroupPathAndAncestors(cgroupPath)) {
105
+ const directory = cgroupDirectory(environment, current);
106
+ if (!directory)
107
+ return null;
108
+ const [maximum, used] = await Promise.all([
109
+ readOptional(environment, path.posix.join(directory, "memory.max")),
110
+ readOptional(environment, path.posix.join(directory, "memory.current")),
111
+ ]);
112
+ const limit = maximum ? parseNonNegativeInteger(maximum) : null;
113
+ const usage = used ? parseNonNegativeInteger(used) : null;
114
+ if (limit === null || usage === null)
115
+ continue;
116
+ const headroom = Math.max(0, limit - usage);
117
+ tightest = tightest === null ? headroom : Math.min(tightest, headroom);
118
+ }
119
+ return tightest;
120
+ }
121
+ /** `/a/b/c`, `/a/b`, `/a`, `/`; nothing for a relative or traversing path. */
122
+ function cgroupPathAndAncestors(cgroupPath) {
123
+ if (!cgroupPath.startsWith("/") || cgroupPath.split("/").includes(".."))
124
+ return [];
125
+ const paths = [];
126
+ for (let current = path.posix.normalize(cgroupPath);; current = path.posix.dirname(current)) {
127
+ paths.push(current);
128
+ if (current === "/")
129
+ return paths;
130
+ }
131
+ }
132
+ function cgroupDirectory(environment, cgroupPath) {
133
+ if (!cgroupPath.startsWith("/") || cgroupPath.split("/").includes(".."))
134
+ return null;
135
+ const root = environment.cgroupRoot.replace(/\/+$/u, "");
136
+ if (cgroupPath === "/")
137
+ return root;
138
+ const directory = path.posix.join(root, cgroupPath);
139
+ return directory.startsWith(`${root}/`) ? directory : null;
140
+ }
@@ -0,0 +1,82 @@
1
+ import { type HostCapacitySpec, type HostTestSlotsSource } from "./host-load-capacity.js";
2
+ export type HostLoadGovernorMode = "on" | "off";
3
+ export interface HostLoadGovernorConfig {
4
+ /** FORGE_HOST_LOAD_GOVERNOR: the CPU and memory budget. Off by default; `off` is the operator override. */
5
+ readonly mode: HostLoadGovernorMode;
6
+ /**
7
+ * FORGE_HOST_LOAD_TEST_SLOTS (decision 0018): how many heavy steps (builds, test runs,
8
+ * Playwright, the runtime build) run at once on the host, whatever the budget says.
9
+ * Unset, it is sized from the host's CPUs and memory (1 to 4); an explicit value is the
10
+ * operator's override. 0 turns the slot off, and with the budget off too the governor is off.
11
+ */
12
+ readonly testSlots: number;
13
+ /** Where testSlots came from, and how it was chosen (for logs and wait messages). Absent: a fixed count. */
14
+ readonly testSlotsSource?: HostTestSlotsSource;
15
+ readonly testSlotsDetail?: string;
16
+ /** The host the slots were sized for; live adjustment reads it too. */
17
+ readonly hostCapacity?: HostCapacitySpec | null;
18
+ /**
19
+ * Lower the slot count while other work on the host needs the machine, and raise it again
20
+ * slowly (host-load-capacity.ts). loadHostLoadGovernorConfig turns it on unless
21
+ * FORGE_HOST_LOAD_LIVE_SLOTS=off; absent means off.
22
+ */
23
+ readonly liveTestSlots?: boolean;
24
+ /** Share of logical CPUs Forge may reserve for heavy steps. */
25
+ readonly cpuBudgetFraction: number;
26
+ /** Memory kept free for the rest of the host, taken off MemAvailable. */
27
+ readonly memoryReserveBytes: number;
28
+ /** Host CPU PSI `some avg10` (percent) at or above which a sample counts as pressured. */
29
+ readonly cpuPressureThreshold: number;
30
+ /** Consecutive pressured samples that stop new admissions (backpressure). */
31
+ readonly backpressureSamples: number;
32
+ /** Host memory PSI `full avg10` (percent) above which admission is a hard stop. */
33
+ readonly memoryFullThreshold: number;
34
+ /**
35
+ * FORGE_HOST_LOAD_MAX_WAIT_MS: the longest a step waits while its queue is stalled before a retryable
36
+ * host_capacity_timeout. Time spent behind holders of the host test slot that are all healthy (owner
37
+ * alive, lease renewed, not retained) does not count: their steps are making progress.
38
+ */
39
+ readonly maxWaitMs: number;
40
+ /**
41
+ * FORGE_HOST_LOAD_MAX_TOTAL_WAIT_MS: the longest a step may queue in all, healthy holders or not; the
42
+ * backstop for a holder that is alive but never finishes. Never below maxWaitMs.
43
+ */
44
+ readonly maxTotalWaitMs: number;
45
+ /** Steps allowed at once when PSI is unavailable (the per-host semaphore fallback). */
46
+ readonly fallbackSlots: number;
47
+ /** After this long at the head of the queue, later waiters may no longer overtake it. */
48
+ readonly antiStarvationMs: number;
49
+ /** Token lease; the owner renews well before it expires. */
50
+ readonly leaseMs: number;
51
+ /** How often waiters are re-evaluated against fresh samples and the shared ledger. */
52
+ readonly recheckIntervalMs: number;
53
+ /** A load sample older than this is treated as missing PSI. */
54
+ readonly sampleStaleMs: number;
55
+ /** The sampler's interval; a longer gap between samples resets the pressure streak. */
56
+ readonly sampleIntervalMs: number;
57
+ /** Without a dedicated cgroup, a step this old is assumed to use its reserved memory. */
58
+ readonly memoryRampMs: number;
59
+ /**
60
+ * Decision 0014 operator ceilings, applied by every governor itself so they hold even
61
+ * without the bridge's runtime settings file (before its first write, after a failed
62
+ * write, or a file that can't be read): the lower of FORGE_HOST_CPU_BUDGET_PERCENT (as a
63
+ * fraction) and an explicitly set FORGE_HOST_LOAD_CPU_BUDGET_FRACTION, and
64
+ * FORGE_HOST_MAX_HEAVY_STEPS. Null when unset.
65
+ */
66
+ readonly cpuBudgetCeilingFraction?: number | null;
67
+ readonly maxHeavyStepsCeiling?: number | null;
68
+ }
69
+ /**
70
+ * The fixed count in defaultHostLoadGovernorConfig, which is not sized for any host: a running
71
+ * governor's config comes from loadHostLoadGovernorConfig, which sizes the slots from the host.
72
+ */
73
+ export declare const defaultHostTestSlots = 1;
74
+ export declare const defaultHostLoadGovernorConfig: HostLoadGovernorConfig;
75
+ export declare function parseHostLoadGovernorMode(value: string | undefined): HostLoadGovernorMode;
76
+ /** The governor admits steps when either rule is on: the host test slot or the budget. */
77
+ export declare function hostLoadGovernorEnabled(config: Pick<HostLoadGovernorConfig, "mode" | "testSlots">): boolean;
78
+ /**
79
+ * @param host the host the test slots are sized for, detected from this machine by default.
80
+ * Null means it could not be read: an unset FORGE_HOST_LOAD_TEST_SLOTS then means 1.
81
+ */
82
+ export declare function loadHostLoadGovernorConfig(environment?: Readonly<Record<string, string | undefined>>, host?: HostCapacitySpec | null): HostLoadGovernorConfig;
@@ -0,0 +1,104 @@
1
+ import { detectHostCapacitySpec, resolveHostTestSlots, } from "./host-load-capacity.js";
2
+ import { defaultHostLoadSampleIntervalMs } from "./host-load-sampler.js";
3
+ /**
4
+ * The fixed count in defaultHostLoadGovernorConfig, which is not sized for any host: a running
5
+ * governor's config comes from loadHostLoadGovernorConfig, which sizes the slots from the host.
6
+ */
7
+ export const defaultHostTestSlots = 1;
8
+ export const defaultHostLoadGovernorConfig = {
9
+ mode: "off",
10
+ testSlots: defaultHostTestSlots,
11
+ cpuBudgetFraction: 0.8,
12
+ memoryReserveBytes: 1024 ** 3,
13
+ cpuPressureThreshold: 50,
14
+ backpressureSamples: 2,
15
+ memoryFullThreshold: 5,
16
+ maxWaitMs: 30 * 60_000,
17
+ maxTotalWaitMs: 4 * 60 * 60_000,
18
+ fallbackSlots: 1,
19
+ antiStarvationMs: 2 * 60_000,
20
+ leaseMs: 2 * 60_000,
21
+ recheckIntervalMs: 1_000,
22
+ sampleStaleMs: 30_000,
23
+ sampleIntervalMs: defaultHostLoadSampleIntervalMs,
24
+ memoryRampMs: 60_000,
25
+ };
26
+ export function parseHostLoadGovernorMode(value) {
27
+ const normalized = value?.trim().toLowerCase() ?? "";
28
+ return normalized === "on" || normalized === "true" || normalized === "1" ? "on" : "off";
29
+ }
30
+ /** The governor admits steps when either rule is on: the host test slot or the budget. */
31
+ export function hostLoadGovernorEnabled(config) {
32
+ return config.mode === "on" || config.testSlots > 0;
33
+ }
34
+ /**
35
+ * @param host the host the test slots are sized for, detected from this machine by default.
36
+ * Null means it could not be read: an unset FORGE_HOST_LOAD_TEST_SLOTS then means 1.
37
+ */
38
+ export function loadHostLoadGovernorConfig(environment = process.env, host = detectHostCapacitySpec()) {
39
+ const defaults = defaultHostLoadGovernorConfig;
40
+ const maxWaitMs = bounded(environment.FORGE_HOST_LOAD_MAX_WAIT_MS, defaults.maxWaitMs, 1_000, 24 * 60 * 60_000);
41
+ const testSlots = resolveHostTestSlots(environment.FORGE_HOST_LOAD_TEST_SLOTS, host);
42
+ return {
43
+ mode: parseHostLoadGovernorMode(environment.FORGE_HOST_LOAD_GOVERNOR),
44
+ testSlots: testSlots.slots,
45
+ testSlotsSource: testSlots.source,
46
+ testSlotsDetail: testSlots.detail,
47
+ hostCapacity: host,
48
+ liveTestSlots: !isOff(environment.FORGE_HOST_LOAD_LIVE_SLOTS),
49
+ cpuBudgetFraction: bounded(environment.FORGE_HOST_LOAD_CPU_BUDGET_FRACTION, defaults.cpuBudgetFraction, 0.05, 1),
50
+ memoryReserveBytes: bounded(environment.FORGE_HOST_LOAD_MEMORY_RESERVE_BYTES, defaults.memoryReserveBytes, 0, 1024 ** 4),
51
+ cpuPressureThreshold: bounded(environment.FORGE_HOST_LOAD_CPU_PRESSURE_THRESHOLD, defaults.cpuPressureThreshold, 1, 100),
52
+ backpressureSamples: Math.round(bounded(environment.FORGE_HOST_LOAD_BACKPRESSURE_SAMPLES, defaults.backpressureSamples, 1, 60)),
53
+ memoryFullThreshold: bounded(environment.FORGE_HOST_LOAD_MEMORY_FULL_THRESHOLD, defaults.memoryFullThreshold, 0, 100),
54
+ maxWaitMs,
55
+ maxTotalWaitMs: Math.max(maxWaitMs, bounded(environment.FORGE_HOST_LOAD_MAX_TOTAL_WAIT_MS, defaults.maxTotalWaitMs, 1_000, 24 * 60 * 60_000)),
56
+ fallbackSlots: Math.round(bounded(environment.FORGE_HOST_LOAD_FALLBACK_SLOTS, defaults.fallbackSlots, 1, 64)),
57
+ antiStarvationMs: defaults.antiStarvationMs,
58
+ leaseMs: defaults.leaseMs,
59
+ recheckIntervalMs: defaults.recheckIntervalMs,
60
+ sampleStaleMs: defaults.sampleStaleMs,
61
+ sampleIntervalMs: defaults.sampleIntervalMs,
62
+ memoryRampMs: defaults.memoryRampMs,
63
+ cpuBudgetCeilingFraction: lowestFraction(optionalCpuPercentFraction(environment.FORGE_HOST_CPU_BUDGET_PERCENT), optionalFraction(environment.FORGE_HOST_LOAD_CPU_BUDGET_FRACTION)),
64
+ maxHeavyStepsCeiling: optionalHeavySteps(environment.FORGE_HOST_MAX_HEAVY_STEPS),
65
+ };
66
+ }
67
+ /** Matches runner-settings' parse of FORGE_HOST_CPU_BUDGET_PERCENT (Number, 10-100); unparsable is unset. */
68
+ function optionalCpuPercentFraction(raw) {
69
+ if (raw === undefined || raw.trim() === "")
70
+ return null;
71
+ const value = Number(raw);
72
+ return Number.isFinite(value) ? Math.min(100, Math.max(10, value)) / 100 : null;
73
+ }
74
+ /** An explicitly set FORGE_HOST_LOAD_CPU_BUDGET_FRACTION is a ceiling too (runner-settings' cpuBudgetCeilings). */
75
+ function optionalFraction(raw) {
76
+ if (raw === undefined || raw.trim() === "")
77
+ return null;
78
+ const value = Number(raw);
79
+ return Number.isFinite(value) ? Math.min(1, Math.max(0.05, value)) : null;
80
+ }
81
+ function lowestFraction(a, b) {
82
+ if (a === null)
83
+ return b;
84
+ if (b === null)
85
+ return a;
86
+ return Math.min(a, b);
87
+ }
88
+ /** Matches runner-settings' parse of FORGE_HOST_MAX_HEAVY_STEPS (parseInt, 1-64); unparsable is unset. */
89
+ function optionalHeavySteps(raw) {
90
+ if (raw === undefined || raw.trim() === "")
91
+ return null;
92
+ const value = Number.parseInt(raw, 10);
93
+ return Number.isFinite(value) ? Math.min(64, Math.max(1, value)) : null;
94
+ }
95
+ function isOff(raw) {
96
+ const normalized = raw?.trim().toLowerCase() ?? "";
97
+ return normalized === "off" || normalized === "false" || normalized === "0";
98
+ }
99
+ function bounded(raw, fallback, minimum, maximum) {
100
+ if (raw === undefined || raw.trim() === "")
101
+ return fallback;
102
+ const value = Number(raw);
103
+ return Number.isFinite(value) ? Math.min(maximum, Math.max(minimum, value)) : fallback;
104
+ }