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

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
@@ -1,5 +1,6 @@
1
1
  import { type HostEnvironment, type HostFacts } from "./host-facts.js";
2
2
  import { type PressureStallResource } from "./host-pressure-stall.js";
3
+ import { type ForgeCgroupSource } from "./host-load-forge-cgroups.js";
3
4
  export interface HostSystemPressure {
4
5
  readonly cpu: PressureStallResource | null;
5
6
  readonly memory: PressureStallResource | null;
@@ -17,16 +18,34 @@ export interface HostOwnCgroupLoad {
17
18
  /** All memory charged to the unit (`memory.current`), including page cache. */
18
19
  readonly memoryChargedBytes: number | null;
19
20
  }
21
+ /**
22
+ * Where `systemPressure` comes from: Linux PSI, or (decision 0021) an estimate
23
+ * of CPU `some` pressure from whole-host CPU use on Windows, which has no PSI.
24
+ */
25
+ export type HostLoadPressureSource = "psi" | "windows_estimate";
20
26
  /** Live host load. Reported in every heartbeat but never a material capability signal. */
21
27
  export interface HostLoadSnapshot {
22
28
  readonly sampledAt: string;
29
+ /**
30
+ * True when `systemPressure` carries a CPU pressure signal the governor gates on.
31
+ * The wire name predates decision 0021: on Windows the signal is an estimate
32
+ * (see `pressureSource`), and the static host fact `psiAvailable` stays false.
33
+ */
23
34
  readonly psiAvailable: boolean;
35
+ /** Null exactly when `psiAvailable` is false. */
36
+ readonly pressureSource: HostLoadPressureSource | null;
24
37
  readonly systemPressure: HostSystemPressure | null;
25
38
  /** True only when the bridge runs in a cgroup of its own (see isDedicatedBridgeUnit). */
26
39
  readonly ownCgroupDedicated: boolean;
27
40
  /** Reported only for a dedicated unit; never a shared terminal/session/app scope. */
28
41
  readonly ownCgroup: HostOwnCgroupLoad | null;
29
42
  readonly memoryAvailableBytes: number | null;
43
+ /**
44
+ * Busy share (0-100) of all logical CPUs over the last sampling window: /proc/stat deltas
45
+ * on Linux, os.cpus() deltas on Windows. Null on the first sample, after a break in
46
+ * readings, and on other platforms. For display only; the governor gates on pressure.
47
+ */
48
+ readonly hostCpuPercent: number | null;
30
49
  }
31
50
  /** What the bridge service needs: static facts plus the latest cached load sample. */
32
51
  export interface HostLoadSource {
@@ -34,6 +53,46 @@ export interface HostLoadSource {
34
53
  stop(): void;
35
54
  facts(): HostFacts | null;
36
55
  current(): HostLoadSnapshot | null;
56
+ /**
57
+ * Recent samples, oldest first, ending with `current()`. The governor reads its
58
+ * pressure streak from them, so samples taken while no step waited still count.
59
+ */
60
+ recent(): readonly HostLoadSnapshot[];
61
+ }
62
+ /**
63
+ * Host CPU time split into the bridge's own share and everything else, over one
64
+ * sampling window (decision 0013). Kept in the bridge for the host load governor;
65
+ * it is not part of the heartbeat payload.
66
+ */
67
+ export interface HostCpuAttribution {
68
+ readonly sampledAt: string;
69
+ /** Busy cores on the whole host, from /proc/stat deltas (os.cpus() deltas on Windows). */
70
+ readonly hostCoresInUse: number;
71
+ /** Cores used by the bridge's dedicated cgroup; null when the cgroup is not dedicated. */
72
+ readonly ownCoresInUse: number | null;
73
+ /** hostCoresInUse minus ownCoresInUse; null unless the own share is known. */
74
+ readonly externalCoresInUse: number | null;
75
+ }
76
+ /** The governor's view: the load sample plus the CPU attribution from the same window. */
77
+ export interface HostLoadGovernorSource extends Pick<HostLoadSource, "start" | "facts" | "current" | "recent"> {
78
+ cpuAttribution?(): HostCpuAttribution | null;
79
+ /**
80
+ * The CPU attribution of each sample in recent(), oldest first, matched by sampledAt. It
81
+ * counts the Docker sandbox cgroups as Forge's own, which the snapshots' ownCgroup does not.
82
+ */
83
+ recentCpuAttributions?(): readonly HostCpuAttribution[];
84
+ /**
85
+ * When a sample in recent() was taken on the sampler's monotonic clock (ms), matched by
86
+ * sampledAt; null for one it does not know. Readings are ordered and timed by it, so a
87
+ * wall-clock step (NTP, resume) cannot reorder them.
88
+ */
89
+ sampleMonotonicMs?(sampledAt: string): number | null;
90
+ /**
91
+ * Free memory under the tightest cgroup `memory.max` on the bridge's path
92
+ * (null when none is set), from the latest sample. The governor budgets
93
+ * against the smaller of this and MemAvailable (decision 0013).
94
+ */
95
+ cgroupMemoryHeadroomBytes?(): number | null;
37
96
  }
38
97
  export interface HostLoadSamplerOptions {
39
98
  readonly environment?: HostEnvironment;
@@ -44,12 +103,15 @@ export interface HostLoadSamplerOptions {
44
103
  readonly monotonicNow?: () => number;
45
104
  /** Systemd unit the operator dedicates to the bridge (FORGE_BRIDGE_CGROUP_UNIT). */
46
105
  readonly cgroupUnit?: string | null;
106
+ /** Docker sandbox cgroups whose CPU time is Forge's own, not external load. */
107
+ readonly forgeCgroups?: ForgeCgroupSource;
47
108
  }
48
109
  export declare const defaultHostLoadSampleIntervalMs = 5000;
49
110
  /**
50
111
  * Samples Linux PSI and the bridge's own cgroup on an interval and caches the
51
- * latest snapshot. Every read is async and failure-tolerant: a host without PSI
52
- * (non-Linux, old kernel, `psi=0`) reports `psiAvailable: false` and no pressure.
112
+ * latest snapshot. Every read is async and failure-tolerant: a Linux host without
113
+ * PSI (old kernel, `psi=0`) or another non-Windows host reports `psiAvailable: false`
114
+ * and no pressure. Windows reports a CPU pressure estimate instead (decision 0021).
53
115
  */
54
116
  export declare class HostLoadSampler implements HostLoadSource {
55
117
  private readonly environment;
@@ -63,10 +125,27 @@ export declare class HostLoadSampler implements HostLoadSource {
63
125
  private inFlight;
64
126
  private hostFacts;
65
127
  private latest;
128
+ private readonly history;
129
+ private readonly attributionHistory;
130
+ /** Each kept sample's monotonic time, by sampledAt (insertion order is sample order). */
131
+ private readonly monotonicStamps;
132
+ private readMonotonicMs;
66
133
  private cpuMark;
134
+ private hostCpuMark;
135
+ private latestCpuAttribution;
136
+ private latestMemoryHeadroom;
137
+ private windowsCpuMark;
138
+ private readonly windowsCpuPressure;
139
+ private readonly forgeCgroups;
140
+ private readonly sandboxCpu;
67
141
  constructor(options?: HostLoadSamplerOptions);
68
142
  facts(): HostFacts | null;
69
143
  current(): HostLoadSnapshot | null;
144
+ cpuAttribution(): HostCpuAttribution | null;
145
+ cgroupMemoryHeadroomBytes(): number | null;
146
+ recent(): readonly HostLoadSnapshot[];
147
+ recentCpuAttributions(): readonly HostCpuAttribution[];
148
+ sampleMonotonicMs(sampledAt: string): number | null;
70
149
  /** Detects static facts once, takes a first sample, then samples on the interval. Idempotent. */
71
150
  start(): Promise<void>;
72
151
  stop(): void;
@@ -74,9 +153,20 @@ export declare class HostLoadSampler implements HostLoadSource {
74
153
  sample(): Promise<HostLoadSnapshot>;
75
154
  private startOnce;
76
155
  private readSnapshot;
156
+ /**
157
+ * Decision 0021: Windows has no PSI or cgroups. CPU pressure is estimated from
158
+ * whole-host CPU use between samples, and memory is available physical memory.
159
+ * The bridge's own share is not attributed, so external load stays unknown and
160
+ * Forge's work counts through reserved cost and the pressure gate (as on a Linux
161
+ * host whose bridge has no dedicated cgroup).
162
+ */
163
+ private readWindowsSnapshot;
164
+ private readCgroupMemoryHeadroom;
77
165
  private readSystemPressure;
78
166
  private readOwnCgroup;
79
167
  private coresInUse;
168
+ /** Busy share (0-1) of all logical CPUs since the last /proc/stat reading. */
169
+ private readHostCpuUse;
80
170
  private readMemoryAvailable;
81
171
  private fallbackFreeMemory;
82
172
  private readPressure;
@@ -1,11 +1,16 @@
1
1
  import path from "node:path";
2
2
  import { defaultHostEnvironment, detectHostFacts, readOptional, } from "./host-facts.js";
3
- import { cgroupLeafName, isDedicatedBridgeUnit, parseCgroupCpuUsageUsec, parseCgroupMemoryAnonBytes, parseMemAvailableBytes, parseNonNegativeInteger, parsePressureStall, parseUnifiedCgroupPath, } from "./host-pressure-stall.js";
3
+ import { cgroupLeafName, isDedicatedBridgeUnit, parseCgroupCpuUsageUsec, parseCgroupMemoryAnonBytes, parseMemAvailableBytes, parseNonNegativeInteger, parsePressureStall, parseProcStatCpuTotals, parseUnifiedCgroupMembership, parseUnifiedCgroupPath, } from "./host-pressure-stall.js";
4
+ import { ForgeCgroupCpuMeter, readCgroupMemoryHeadroomBytes, } from "./host-load-forge-cgroups.js";
5
+ import { cpuTimeTotals, cpuUtilisation, WindowsCpuPressureEstimator, } from "./host-load-windows-cpu.js";
4
6
  export const defaultHostLoadSampleIntervalMs = 5_000;
7
+ /** Samples kept for the governor's pressure streak (FORGE_HOST_LOAD_BACKPRESSURE_SAMPLES is at most 60). */
8
+ const retainedSampleCount = 64;
5
9
  /**
6
10
  * Samples Linux PSI and the bridge's own cgroup on an interval and caches the
7
- * latest snapshot. Every read is async and failure-tolerant: a host without PSI
8
- * (non-Linux, old kernel, `psi=0`) reports `psiAvailable: false` and no pressure.
11
+ * latest snapshot. Every read is async and failure-tolerant: a Linux host without
12
+ * PSI (old kernel, `psi=0`) or another non-Windows host reports `psiAvailable: false`
13
+ * and no pressure. Windows reports a CPU pressure estimate instead (decision 0021).
9
14
  */
10
15
  export class HostLoadSampler {
11
16
  environment;
@@ -19,7 +24,19 @@ export class HostLoadSampler {
19
24
  inFlight = null;
20
25
  hostFacts = null;
21
26
  latest = null;
27
+ history = [];
28
+ attributionHistory = [];
29
+ /** Each kept sample's monotonic time, by sampledAt (insertion order is sample order). */
30
+ monotonicStamps = new Map();
31
+ readMonotonicMs = 0;
22
32
  cpuMark = null;
33
+ hostCpuMark = null;
34
+ latestCpuAttribution = null;
35
+ latestMemoryHeadroom = null;
36
+ windowsCpuMark = null;
37
+ windowsCpuPressure = new WindowsCpuPressureEstimator();
38
+ forgeCgroups;
39
+ sandboxCpu;
23
40
  constructor(options = {}) {
24
41
  this.environment = options.environment ?? defaultHostEnvironment();
25
42
  this.intervalMs = options.intervalMs !== undefined && Number.isFinite(options.intervalMs) && options.intervalMs > 0
@@ -30,6 +47,8 @@ export class HostLoadSampler {
30
47
  this.cgroupUnit = options.cgroupUnit !== undefined
31
48
  ? options.cgroupUnit
32
49
  : process.env.FORGE_BRIDGE_CGROUP_UNIT?.trim() || null;
50
+ this.forgeCgroups = options.forgeCgroups ?? null;
51
+ this.sandboxCpu = new ForgeCgroupCpuMeter(this.environment);
33
52
  }
34
53
  facts() {
35
54
  return this.hostFacts;
@@ -37,6 +56,21 @@ export class HostLoadSampler {
37
56
  current() {
38
57
  return this.latest;
39
58
  }
59
+ cpuAttribution() {
60
+ return this.latestCpuAttribution;
61
+ }
62
+ cgroupMemoryHeadroomBytes() {
63
+ return this.latestMemoryHeadroom;
64
+ }
65
+ recent() {
66
+ return [...this.history];
67
+ }
68
+ recentCpuAttributions() {
69
+ return [...this.attributionHistory];
70
+ }
71
+ sampleMonotonicMs(sampledAt) {
72
+ return this.monotonicStamps.get(sampledAt) ?? null;
73
+ }
40
74
  /** Detects static facts once, takes a first sample, then samples on the interval. Idempotent. */
41
75
  start() {
42
76
  if (this.timer)
@@ -57,7 +91,26 @@ export class HostLoadSampler {
57
91
  sample() {
58
92
  this.inFlight ??= this.readSnapshot()
59
93
  .then(snapshot => {
94
+ // A Windows reading that did not advance the CPU window returns the last snapshot.
95
+ if (snapshot === this.latest)
96
+ return snapshot;
60
97
  this.latest = snapshot;
98
+ this.history.push(snapshot);
99
+ if (this.history.length > retainedSampleCount)
100
+ this.history.splice(0, this.history.length - retainedSampleCount);
101
+ this.monotonicStamps.set(snapshot.sampledAt, this.readMonotonicMs);
102
+ for (const stamp of this.monotonicStamps.keys()) {
103
+ if (this.monotonicStamps.size <= retainedSampleCount)
104
+ break;
105
+ this.monotonicStamps.delete(stamp);
106
+ }
107
+ const attribution = this.latestCpuAttribution;
108
+ if (attribution?.sampledAt === snapshot.sampledAt) {
109
+ this.attributionHistory.push(attribution);
110
+ if (this.attributionHistory.length > retainedSampleCount) {
111
+ this.attributionHistory.splice(0, this.attributionHistory.length - retainedSampleCount);
112
+ }
113
+ }
61
114
  return snapshot;
62
115
  })
63
116
  .finally(() => {
@@ -81,19 +134,78 @@ export class HostLoadSampler {
81
134
  async readSnapshot() {
82
135
  const sampledAtMs = this.now();
83
136
  const monotonicMs = this.monotonicNow();
137
+ this.readMonotonicMs = monotonicMs;
138
+ if (this.environment.platform === "win32")
139
+ return this.readWindowsSnapshot(sampledAtMs, monotonicMs);
84
140
  const linux = this.environment.platform === "linux";
85
- const [systemPressure, ownCgroup, memoryAvailableBytes] = linux
86
- ? await Promise.all([this.readSystemPressure(), this.readOwnCgroup(monotonicMs), this.readMemoryAvailable()])
87
- : [null, null, this.fallbackFreeMemory()];
141
+ const [systemPressure, ownCgroup, memoryAvailableBytes, hostCpu, cgroupMemoryHeadroomBytes, sandboxCores] = linux
142
+ ? await Promise.all([
143
+ this.readSystemPressure(),
144
+ this.readOwnCgroup(monotonicMs),
145
+ this.readMemoryAvailable(),
146
+ this.readHostCpuUse(),
147
+ this.readCgroupMemoryHeadroom(),
148
+ Promise.resolve(this.forgeCgroups?.paths() ?? [])
149
+ .then(paths => this.sandboxCpu.coresInUse(paths, monotonicMs)).catch(() => 0),
150
+ ])
151
+ : [null, null, this.fallbackFreeMemory(), null, null, 0];
152
+ const sampledAt = new Date(sampledAtMs).toISOString();
153
+ // Docker sandbox CPU is Forge's own work, already counted through reserved cost.
154
+ const ownCores = ownCgroup?.cpuCoresInUse ?? null;
155
+ this.latestMemoryHeadroom = cgroupMemoryHeadroomBytes;
156
+ this.latestCpuAttribution = hostCpuAttribution(sampledAt, hostCpu === null ? null : roundCores(hostCpu.utilisation * hostCpu.cpuCount), ownCores === null ? null : ownCores + sandboxCores);
88
157
  return {
89
- sampledAt: new Date(sampledAtMs).toISOString(),
158
+ sampledAt,
90
159
  psiAvailable: systemPressure !== null,
160
+ pressureSource: systemPressure !== null ? "psi" : null,
91
161
  systemPressure,
92
162
  ownCgroupDedicated: ownCgroup !== null,
93
163
  ownCgroup,
94
164
  memoryAvailableBytes,
165
+ hostCpuPercent: hostCpu === null ? null : hostCpuPercent(hostCpu.utilisation),
95
166
  };
96
167
  }
168
+ /**
169
+ * Decision 0021: Windows has no PSI or cgroups. CPU pressure is estimated from
170
+ * whole-host CPU use between samples, and memory is available physical memory.
171
+ * The bridge's own share is not attributed, so external load stays unknown and
172
+ * Forge's work counts through reserved cost and the pressure gate (as on a Linux
173
+ * host whose bridge has no dedicated cgroup).
174
+ */
175
+ readWindowsSnapshot(sampledAtMs, monotonicMs) {
176
+ let totals;
177
+ try {
178
+ totals = cpuTimeTotals(this.environment.cpus());
179
+ }
180
+ catch {
181
+ totals = null;
182
+ }
183
+ const previous = this.windowsCpuMark;
184
+ const sampledAt = new Date(sampledAtMs).toISOString();
185
+ if (this.latest && totals && previous && previous.totals.cpuCount === totals.cpuCount
186
+ && monotonicMs - previous.atMs < minimumWindowsCpuWindowMs) {
187
+ // Too soon after the last reading (start() right after a sample) for a stable delta:
188
+ // the window stays open and the last snapshot is returned as is. sample() does not
189
+ // record it again, so it never counts as another sample in the pressure streak.
190
+ return this.latest;
191
+ }
192
+ this.windowsCpuMark = totals ? { totals, atMs: monotonicMs } : null;
193
+ const elapsedMs = previous ? monotonicMs - previous.atMs : 0;
194
+ const utilisation = previous && elapsedMs > 0 ? cpuUtilisation(previous.totals, totals) : null;
195
+ // The first sample, or a break in readings (no times, a CPU count change, a counter
196
+ // reset), reports no pressure and restarts the averages from the next window.
197
+ if (utilisation === null)
198
+ this.windowsCpuPressure.reset();
199
+ const cpu = utilisation === null ? null : this.windowsCpuPressure.update(utilisation, elapsedMs);
200
+ this.latestMemoryHeadroom = null;
201
+ this.latestCpuAttribution = hostCpuAttribution(sampledAt, utilisation !== null && totals ? roundCores(utilisation * totals.cpuCount) : null, null);
202
+ return windowsSnapshot(sampledAt, cpu, this.fallbackFreeMemory(), utilisation === null ? null : hostCpuPercent(utilisation));
203
+ }
204
+ async readCgroupMemoryHeadroom() {
205
+ const membership = await readOptional(this.environment, path.posix.join(this.environment.procRoot, "self", "cgroup"));
206
+ const cgroupPath = membership ? parseUnifiedCgroupMembership(membership) : null;
207
+ return cgroupPath ? await readCgroupMemoryHeadroomBytes(this.environment, cgroupPath).catch(() => null) : null;
208
+ }
97
209
  async readSystemPressure() {
98
210
  const pressureRoot = path.posix.join(this.environment.procRoot, "pressure");
99
211
  const [cpu, memory, io] = await Promise.all(["cpu", "memory", "io"].map(resource => this.readPressure(path.posix.join(pressureRoot, resource))));
@@ -142,7 +254,21 @@ export class HostLoadSampler {
142
254
  // A restarted unit resets its counter; elapsed time comes from a monotonic clock.
143
255
  if (elapsedUsec <= 0 || usedUsec < 0)
144
256
  return null;
145
- return Math.round((usedUsec / elapsedUsec) * 100) / 100;
257
+ return roundCores(usedUsec / elapsedUsec);
258
+ }
259
+ /** Busy share (0-1) of all logical CPUs since the last /proc/stat reading. */
260
+ async readHostCpuUse() {
261
+ const content = await readOptional(this.environment, path.posix.join(this.environment.procRoot, "stat"));
262
+ const totals = content ? parseProcStatCpuTotals(content) : null;
263
+ const previous = this.hostCpuMark;
264
+ this.hostCpuMark = totals;
265
+ if (!totals || !previous || previous.cpuCount !== totals.cpuCount)
266
+ return null;
267
+ const totalDelta = totals.totalTicks - previous.totalTicks;
268
+ const busyDelta = totals.busyTicks - previous.busyTicks;
269
+ if (totalDelta <= 0 || busyDelta < 0)
270
+ return null;
271
+ return { utilisation: Math.min(1, busyDelta / totalDelta), cpuCount: totals.cpuCount };
146
272
  }
147
273
  async readMemoryAvailable() {
148
274
  const meminfo = await readOptional(this.environment, path.posix.join(this.environment.procRoot, "meminfo"));
@@ -162,3 +288,35 @@ export class HostLoadSampler {
162
288
  return content ? parsePressureStall(content) : null;
163
289
  }
164
290
  }
291
+ /** Windows CPU deltas shorter than this are too noisy to fold into the pressure estimate. */
292
+ const minimumWindowsCpuWindowMs = 250;
293
+ function windowsSnapshot(sampledAt, cpu, memoryAvailableBytes, cpuPercent) {
294
+ return {
295
+ sampledAt,
296
+ psiAvailable: cpu !== null,
297
+ pressureSource: cpu !== null ? "windows_estimate" : null,
298
+ systemPressure: cpu ? { cpu, memory: null, io: null } : null,
299
+ ownCgroupDedicated: false,
300
+ ownCgroup: null,
301
+ memoryAvailableBytes,
302
+ hostCpuPercent: cpuPercent,
303
+ };
304
+ }
305
+ function roundCores(value) {
306
+ return Math.round(value * 100) / 100;
307
+ }
308
+ /** A 0-1 busy share as a percentage with two decimals. */
309
+ function hostCpuPercent(utilisation) {
310
+ return Math.round(Math.min(1, Math.max(0, utilisation)) * 10_000) / 100;
311
+ }
312
+ function hostCpuAttribution(sampledAt, hostCoresInUse, ownCoresInUse) {
313
+ if (hostCoresInUse === null)
314
+ return null;
315
+ return {
316
+ sampledAt,
317
+ hostCoresInUse,
318
+ ownCoresInUse,
319
+ // Own usage only exists for a dedicated cgroup; a shared scope never yields external load.
320
+ externalCoresInUse: ownCoresInUse === null ? null : roundCores(Math.max(0, hostCoresInUse - ownCoresInUse)),
321
+ };
322
+ }
@@ -0,0 +1,70 @@
1
+ export interface HostLoadStepCost {
2
+ /** Cores the step is expected to keep busy. */
3
+ readonly cpuCores: number;
4
+ /** Peak resident memory the step is expected to need. */
5
+ readonly memoryBytes: number;
6
+ }
7
+ export interface HostLoadStepClassification {
8
+ readonly stepClass: string;
9
+ readonly cost: HostLoadStepCost;
10
+ }
11
+ export declare const defaultHostLoadStepCosts: {
12
+ readonly dotnetTier: {
13
+ readonly cpuCores: 2;
14
+ readonly memoryBytes: number;
15
+ };
16
+ readonly vitest: {
17
+ readonly cpuCores: 1;
18
+ readonly memoryBytes: number;
19
+ };
20
+ readonly playwright: {
21
+ readonly cpuCores: 2;
22
+ readonly memoryBytes: number;
23
+ };
24
+ readonly generic: {
25
+ readonly cpuCores: 1;
26
+ readonly memoryBytes: number;
27
+ };
28
+ /** A `dotnet build` (or test with its build) started as a managed command. */
29
+ readonly managedBuild: {
30
+ readonly cpuCores: 2;
31
+ readonly memoryBytes: number;
32
+ };
33
+ readonly aspnetPrebuild: {
34
+ readonly cpuCores: 2;
35
+ readonly memoryBytes: number;
36
+ };
37
+ /** Dependency installs are mostly network and disk bound, so they cost less than a build. */
38
+ readonly dependencyInstall: {
39
+ readonly cpuCores: 0.5;
40
+ readonly memoryBytes: number;
41
+ };
42
+ };
43
+ export declare const aspNetPrebuildStepClass: HostLoadStepClassification;
44
+ export declare const dependencyInstallStepClass: HostLoadStepClassification;
45
+ /**
46
+ * Maps a pre-publication validation step to its class: `dotnet.tier.<tier>`,
47
+ * `vitest.<suite>`, `playwright.e2e`, or `generic` for everything else.
48
+ */
49
+ export declare function classifyValidationStep(checkId: string, command: string, args: readonly string[]): HostLoadStepClassification;
50
+ export interface ManagedCommandStepInput {
51
+ readonly command: string;
52
+ readonly args: readonly string[];
53
+ /** The runner-authored verification profile, when the command is one. */
54
+ readonly verificationProfile?: string;
55
+ /** Whether the command builds (see isBuildProducingManagedCommand). */
56
+ readonly buildProducing: boolean;
57
+ }
58
+ /**
59
+ * Maps a managed command to its class: `managed.<profile>` for verification
60
+ * profiles (a .NET tier's cost per parallel shard), `managed.playwright`,
61
+ * `managed.build` for build-producing commands, `managed.test` for a test run
62
+ * that reuses an earlier build, and `managed.command` otherwise. Only
63
+ * `managed.command` skips the host test slot (decision 0018).
64
+ */
65
+ export declare function classifyManagedCommand(input: ManagedCommandStepInput): HostLoadStepClassification;
66
+ /**
67
+ * The default cost of a step class, for a step whose cost the requester does
68
+ * not get to choose (a Docker sandbox asking the host bridge for admission).
69
+ */
70
+ export declare function hostLoadStepCostForClass(stepClass: string): HostLoadStepCost;
@@ -0,0 +1,161 @@
1
+ import path from "node:path";
2
+ const gib = 1024 ** 3;
3
+ export const defaultHostLoadStepCosts = {
4
+ dotnetTier: { cpuCores: 2, memoryBytes: 3 * gib },
5
+ vitest: { cpuCores: 1, memoryBytes: 1.5 * gib },
6
+ playwright: { cpuCores: 2, memoryBytes: 2 * gib },
7
+ generic: { cpuCores: 1, memoryBytes: 1 * gib },
8
+ /** A `dotnet build` (or test with its build) started as a managed command. */
9
+ managedBuild: { cpuCores: 2, memoryBytes: 2 * gib },
10
+ aspnetPrebuild: { cpuCores: 2, memoryBytes: 2 * gib },
11
+ /** Dependency installs are mostly network and disk bound, so they cost less than a build. */
12
+ dependencyInstall: { cpuCores: 0.5, memoryBytes: 0.75 * gib },
13
+ };
14
+ export const aspNetPrebuildStepClass = {
15
+ stepClass: "aspnet.prebuild",
16
+ cost: defaultHostLoadStepCosts.aspnetPrebuild,
17
+ };
18
+ export const dependencyInstallStepClass = {
19
+ stepClass: "deps.install",
20
+ cost: defaultHostLoadStepCosts.dependencyInstall,
21
+ };
22
+ const dotnetTierScripts = ["scripts/run-dotnet-test-tier.ps1", "scripts/run-dotnet-test-tier-set.ps1"];
23
+ const affectedDotnetScript = "scripts/run-affected-dotnet-tests.mjs";
24
+ const vitestSuites = new Set(["client", "bridge"]);
25
+ /**
26
+ * Maps a pre-publication validation step to its class: `dotnet.tier.<tier>`,
27
+ * `vitest.<suite>`, `playwright.e2e`, or `generic` for everything else.
28
+ */
29
+ export function classifyValidationStep(checkId, command, args) {
30
+ const normalized = args.map(argument => argument.replaceAll("\\", "/"));
31
+ if (checkId === "playwright-e2e") {
32
+ return { stepClass: "playwright.e2e", cost: defaultHostLoadStepCosts.playwright };
33
+ }
34
+ if (normalized.some(argument => dotnetTierScripts.some(script => argument.endsWith(script)))) {
35
+ return { stepClass: `dotnet.tier.${stepClassSegment(tierArgument(normalized))}`, cost: defaultHostLoadStepCosts.dotnetTier };
36
+ }
37
+ if (normalized.some(argument => argument.endsWith(affectedDotnetScript))) {
38
+ return { stepClass: "dotnet.tier.affected", cost: defaultHostLoadStepCosts.dotnetTier };
39
+ }
40
+ if (vitestSuites.has(checkId) && isTestScript(command, normalized)) {
41
+ return { stepClass: `vitest.${checkId}`, cost: defaultHostLoadStepCosts.vitest };
42
+ }
43
+ return { stepClass: "generic", cost: defaultHostLoadStepCosts.generic };
44
+ }
45
+ function tierArgument(args) {
46
+ const index = args.findIndex(argument => /^-(tier|tiers)$/iu.test(argument));
47
+ return index >= 0 ? args[index + 1] ?? "unknown" : "unknown";
48
+ }
49
+ function isTestScript(command, args) {
50
+ if (!["npm", "pnpm", "npx", "vitest"].includes(command))
51
+ return false;
52
+ const last = args.at(-1);
53
+ return last === "test" || command === "vitest" || args.includes("vitest");
54
+ }
55
+ function stepClassSegment(value) {
56
+ const segment = value.trim().toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "");
57
+ return segment || "unknown";
58
+ }
59
+ /**
60
+ * Maps a managed command to its class: `managed.<profile>` for verification
61
+ * profiles (a .NET tier's cost per parallel shard), `managed.playwright`,
62
+ * `managed.build` for build-producing commands, `managed.test` for a test run
63
+ * that reuses an earlier build, and `managed.command` otherwise. Only
64
+ * `managed.command` skips the host test slot (decision 0018).
65
+ */
66
+ export function classifyManagedCommand(input) {
67
+ if (input.verificationProfile) {
68
+ const parallelism = maxParallelismArgument(input.args);
69
+ const tier = defaultHostLoadStepCosts.dotnetTier;
70
+ return {
71
+ stepClass: `managed.${stepClassSegment(input.verificationProfile)}`,
72
+ cost: {
73
+ cpuCores: tier.cpuCores * parallelism,
74
+ memoryBytes: tier.memoryBytes + (parallelism - 1) * 1.5 * gib,
75
+ },
76
+ };
77
+ }
78
+ const invocation = [input.command, ...input.args].map(argument => argument.toLowerCase().replaceAll("\\", "/"));
79
+ const programs = programsRun(invocation);
80
+ if (programs.some(program => path.posix.basename(program).includes("playwright"))) {
81
+ return { stepClass: "managed.playwright", cost: defaultHostLoadStepCosts.playwright };
82
+ }
83
+ if (input.buildProducing)
84
+ return { stepClass: "managed.build", cost: defaultHostLoadStepCosts.managedBuild };
85
+ if (isTestRun(invocation, programs))
86
+ return { stepClass: "managed.test", cost: defaultHostLoadStepCosts.dotnetTier };
87
+ return { stepClass: "managed.command", cost: defaultHostLoadStepCosts.generic };
88
+ }
89
+ const testRunScripts = [...dotnetTierScripts, affectedDotnetScript].map(script => script.toLowerCase());
90
+ const packageManagers = new Set(["npm", "pnpm", "yarn", "npx"]);
91
+ const scriptHosts = new Set(["node", "pwsh", "powershell", "bash", "sh", "tsx"]);
92
+ const programName = (argument) => path.posix.basename(argument).replace(/\.(exe|cmd)$/u, "");
93
+ // Package-manager options that take a value (`pnpm --dir tests/e2e`, `npm --prefix x`), in
94
+ // lower case like the invocation, so `-c` and `-f` are pnpm's `-C` and `-F`.
95
+ const packageManagerValueOptions = new Set(["--dir", "-c", "--prefix", "--filter", "-f", "--workspace", "--cwd", "--config"]);
96
+ /** The operands of an invocation, without options and, for a package manager, the values its options take. */
97
+ function operandsOf(command, args) {
98
+ const operands = [];
99
+ for (let index = 0; index < args.length; index += 1) {
100
+ const argument = args[index];
101
+ if (!argument.startsWith("-"))
102
+ operands.push(argument);
103
+ else if (packageManagers.has(command) && packageManagerValueOptions.has(argument))
104
+ index += 1;
105
+ }
106
+ return operands;
107
+ }
108
+ /**
109
+ * The programs an invocation runs: the executable and, for a script host or a
110
+ * package manager's exec, the script or tool it starts. Arguments after that
111
+ * (a search pattern, a file to read) never classify the command, so
112
+ * `rg vitest src` or `cat playwright.config.ts` stays a plain command.
113
+ */
114
+ function programsRun(invocation) {
115
+ const command = programName(invocation[0] ?? "");
116
+ const operands = operandsOf(command, invocation.slice(1));
117
+ if (scriptHosts.has(command))
118
+ return [command, ...operands.slice(0, 1)];
119
+ if (command === "npx")
120
+ return [command, ...operands.slice(0, 1)];
121
+ if (packageManagers.has(command) && ["exec", "dlx"].includes(operands[0] ?? ""))
122
+ return [command, ...operands.slice(1, 2)];
123
+ // `pnpm vitest`, `yarn playwright test`: these run a package's binary by name.
124
+ if (command === "pnpm" || command === "yarn")
125
+ return [command, ...operands.slice(0, 1)];
126
+ return [command];
127
+ }
128
+ /** `dotnet test`, the tier and affected scripts, Vitest, or a package manager's test script. */
129
+ function isTestRun(invocation, programs) {
130
+ const command = programs[0] ?? "";
131
+ const operands = operandsOf(command, invocation.slice(1));
132
+ if (command === "dotnet" && operands[0] === "test")
133
+ return true;
134
+ if (programs.some(program => testRunScripts.some(script => program.endsWith(script))))
135
+ return true;
136
+ if (programs.some(program => programName(program) === "vitest"))
137
+ return true;
138
+ return packageManagers.has(command) && (operands[0] === "test" || (operands[0] === "run" && operands[1] === "test"));
139
+ }
140
+ /**
141
+ * The default cost of a step class, for a step whose cost the requester does
142
+ * not get to choose (a Docker sandbox asking the host bridge for admission).
143
+ */
144
+ export function hostLoadStepCostForClass(stepClass) {
145
+ if (stepClass.startsWith("dotnet.tier."))
146
+ return defaultHostLoadStepCosts.dotnetTier;
147
+ if (stepClass.startsWith("vitest."))
148
+ return defaultHostLoadStepCosts.vitest;
149
+ if (stepClass === "playwright.e2e")
150
+ return defaultHostLoadStepCosts.playwright;
151
+ if (stepClass === aspNetPrebuildStepClass.stepClass)
152
+ return defaultHostLoadStepCosts.aspnetPrebuild;
153
+ if (stepClass === dependencyInstallStepClass.stepClass)
154
+ return defaultHostLoadStepCosts.dependencyInstall;
155
+ return defaultHostLoadStepCosts.generic;
156
+ }
157
+ function maxParallelismArgument(args) {
158
+ const index = args.findIndex(argument => argument.toLowerCase() === "-maxparallelism");
159
+ const value = index >= 0 ? Number(args[index + 1]) : 1;
160
+ return Number.isSafeInteger(value) && value >= 1 ? Math.min(value, 32) : 1;
161
+ }
@@ -0,0 +1,27 @@
1
+ import { type WindowsProcessTable } from "../shared/process/process-tree.js";
2
+ /** The process tree a governed step runs in, recorded on its token once it launches. */
3
+ export interface HostLoadStepProcess {
4
+ readonly rootPid: number;
5
+ /** OS birth marker of the root, so a reused pid is never signalled. Null where unsupported. */
6
+ readonly rootIdentity: string | null;
7
+ /** The root leads its own process group (Unix): the whole group is stopped and checked. */
8
+ readonly processGroup: boolean;
9
+ }
10
+ /** Stops a step's process tree; resolves true only when no member is left. */
11
+ export type HostLoadStepTerminator = (step: HostLoadStepProcess) => Promise<boolean>;
12
+ /**
13
+ * Stops the recorded tree with SIGTERM, then SIGKILL, and confirms it is gone.
14
+ * A root that cannot be identified (no birth marker) is never signalled and
15
+ * counts as not confirmed, so its token keeps its reserved cost.
16
+ */
17
+ export declare const terminateHostLoadStepProcess: HostLoadStepTerminator;
18
+ /**
19
+ * Windows has no process groups and does not reparent orphans. A root with a
20
+ * recorded birth marker is stopped together with every descendant created
21
+ * after it (found through parent ids, even if the root already exited), and
22
+ * the reservation is reused only once none is left. Without a birth marker the
23
+ * root cannot be told from a reused pid, so it is never signalled and only its
24
+ * absence counts.
25
+ */
26
+ export declare function windowsStepTerminator(table: WindowsProcessTable, waitMs?: number): HostLoadStepTerminator;
27
+ export declare function validHostLoadStepProcess(value: unknown): value is HostLoadStepProcess;