@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 0.1.4-dev.0098fdb4e213

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 (381) hide show
  1. package/README.md +306 -1
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +132 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +121 -0
  5. package/dist/bridge/bridge-chat.types.js +416 -0
  6. package/dist/bridge/bridge-state-file.d.ts +161 -0
  7. package/dist/bridge/bridge-state-file.js +376 -0
  8. package/dist/bridge/bridge-state-io.d.ts +11 -0
  9. package/dist/bridge/bridge-state-io.js +50 -0
  10. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  11. package/dist/bridge/bridge-state-lock.js +102 -0
  12. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  13. package/dist/bridge/bridge-state-unpublished.js +111 -0
  14. package/dist/bridge/bridge.base.d.ts +18 -1
  15. package/dist/bridge/bridge.service.d.ts +216 -4
  16. package/dist/bridge/bridge.service.js +2574 -90
  17. package/dist/bridge/bridge.types.d.ts +245 -2
  18. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  19. package/dist/bridge/dispatch-result-outbox.js +87 -0
  20. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  21. package/dist/bridge/dispatch-result-worker.js +122 -0
  22. package/dist/bridge/in-flight-registry.d.ts +62 -0
  23. package/dist/bridge/in-flight-registry.js +207 -0
  24. package/dist/bridge/internals.d.ts +2 -0
  25. package/dist/bridge/internals.js +1 -0
  26. package/dist/bridge/local-yield-flag.d.ts +6 -0
  27. package/dist/bridge/local-yield-flag.js +34 -0
  28. package/dist/bridge/readiness-result-outbox.d.ts +25 -0
  29. package/dist/bridge/readiness-result-outbox.js +74 -0
  30. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  31. package/dist/bridge/readiness-result-worker.js +121 -0
  32. package/dist/bridge/runner-host-capabilities.d.ts +20 -0
  33. package/dist/bridge/runner-host-capabilities.js +110 -0
  34. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  35. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  36. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  37. package/dist/bridge/test-postgres-capability.js +120 -0
  38. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  39. package/dist/cleanup/cleanup-wip.js +66 -0
  40. package/dist/cleanup/cleanup.service.d.ts +33 -2
  41. package/dist/cleanup/cleanup.service.js +477 -3
  42. package/dist/cleanup/cleanup.types.d.ts +16 -0
  43. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  44. package/dist/cleanup/forge-owned-paths.js +53 -0
  45. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  46. package/dist/cleanup/host-runtime-ledger.js +130 -0
  47. package/dist/cleanup/index.d.ts +1 -1
  48. package/dist/cleanup/index.js +1 -1
  49. package/dist/cleanup/internals.d.ts +2 -2
  50. package/dist/cleanup/internals.js +1 -1
  51. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  52. package/dist/cleanup/managed-branch-sweep.js +111 -0
  53. package/dist/cli/cli.help.d.ts +2 -0
  54. package/dist/cli/cli.help.js +279 -0
  55. package/dist/cli/cli.service.d.ts +69 -12
  56. package/dist/cli/cli.service.js +557 -382
  57. package/dist/cli/idle-status.d.ts +84 -0
  58. package/dist/cli/idle-status.js +181 -0
  59. package/dist/cli/local-config.d.ts +13 -0
  60. package/dist/cli/local-config.js +82 -6
  61. package/dist/cli/provider-cli-detection.d.ts +10 -0
  62. package/dist/cli/provider-cli-detection.js +160 -0
  63. package/dist/runtime/aspnet-runtime-prebuild.d.ts +41 -0
  64. package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
  65. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  66. package/dist/runtime/attempt-database-broker.js +390 -0
  67. package/dist/runtime/attempt-node-runtime-launcher.d.ts +18 -0
  68. package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
  69. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  70. package/dist/runtime/attempt-path-operation.js +94 -0
  71. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  72. package/dist/runtime/attempt-private-directory.js +54 -0
  73. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  74. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  75. package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
  76. package/dist/runtime/attempt-process-supervisor.js +471 -0
  77. package/dist/runtime/canonical-source-file.d.ts +3 -0
  78. package/dist/runtime/canonical-source-file.js +54 -0
  79. package/dist/runtime/docker-engine-probe.d.ts +95 -0
  80. package/dist/runtime/docker-engine-probe.js +340 -0
  81. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  82. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  83. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  84. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  85. package/dist/runtime/generated-output-reset.d.ts +20 -0
  86. package/dist/runtime/generated-output-reset.js +157 -0
  87. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  88. package/dist/runtime/host-database-capability-boundary.js +63 -0
  89. package/dist/runtime/host-diagnostics.d.ts +11 -0
  90. package/dist/runtime/host-diagnostics.js +192 -0
  91. package/dist/runtime/host-execution-root.d.ts +4 -0
  92. package/dist/runtime/host-execution-root.js +39 -0
  93. package/dist/runtime/host-facts.d.ts +36 -0
  94. package/dist/runtime/host-facts.js +95 -0
  95. package/dist/runtime/host-listener-inspector.d.ts +51 -0
  96. package/dist/runtime/host-listener-inspector.js +385 -0
  97. package/dist/runtime/host-load-admission.d.ts +67 -0
  98. package/dist/runtime/host-load-admission.js +99 -0
  99. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  100. package/dist/runtime/host-load-child-environment.js +76 -0
  101. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  102. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  103. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  104. package/dist/runtime/host-load-governor-config.js +83 -0
  105. package/dist/runtime/host-load-governor.d.ts +186 -0
  106. package/dist/runtime/host-load-governor.js +632 -0
  107. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  108. package/dist/runtime/host-load-ledger-lock.js +187 -0
  109. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  110. package/dist/runtime/host-load-runtime-settings.js +80 -0
  111. package/dist/runtime/host-load-sampler.d.ts +156 -0
  112. package/dist/runtime/host-load-sampler.js +298 -0
  113. package/dist/runtime/host-load-step-class.d.ts +70 -0
  114. package/dist/runtime/host-load-step-class.js +161 -0
  115. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  116. package/dist/runtime/host-load-step-reaper.js +95 -0
  117. package/dist/runtime/host-load-step-run.d.ts +73 -0
  118. package/dist/runtime/host-load-step-run.js +102 -0
  119. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  120. package/dist/runtime/host-load-test-slot.js +81 -0
  121. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  122. package/dist/runtime/host-load-token-ledger.js +453 -0
  123. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  124. package/dist/runtime/host-load-windows-cpu.js +85 -0
  125. package/dist/runtime/host-port-broker.d.ts +76 -0
  126. package/dist/runtime/host-port-broker.js +333 -0
  127. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  128. package/dist/runtime/host-pressure-stall.js +168 -0
  129. package/dist/runtime/host-runtime-contract.d.ts +74 -0
  130. package/dist/runtime/host-runtime-contract.js +846 -0
  131. package/dist/runtime/host-runtime-lease.d.ts +287 -0
  132. package/dist/runtime/host-runtime-lease.js +2763 -0
  133. package/dist/runtime/host-runtime-promotion.d.ts +55 -0
  134. package/dist/runtime/host-runtime-promotion.js +254 -0
  135. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  136. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  137. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  138. package/dist/runtime/host-runtime-requirements.js +117 -0
  139. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  140. package/dist/runtime/managed-command-teardown.js +596 -0
  141. package/dist/runtime/memory-capacity.d.ts +70 -0
  142. package/dist/runtime/memory-capacity.js +123 -0
  143. package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
  144. package/dist/runtime/native-test-postgres-fallback.js +143 -0
  145. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  146. package/dist/runtime/node-host-runtime-adapter.js +286 -0
  147. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  148. package/dist/runtime/pinned-directory-process.js +61 -0
  149. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  150. package/dist/runtime/pinned-source-directory.js +94 -0
  151. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  152. package/dist/runtime/playwright-browser-cache.js +227 -0
  153. package/dist/runtime/playwright-host-runtime-adapter.d.ts +39 -0
  154. package/dist/runtime/playwright-host-runtime-adapter.js +274 -0
  155. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  156. package/dist/runtime/prepared-runtime-identity.js +218 -0
  157. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  158. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  159. package/dist/runtime/runner-settings.d.ts +104 -0
  160. package/dist/runtime/runner-settings.js +236 -0
  161. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  162. package/dist/runtime/runtime-isolation-lease.js +161 -0
  163. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  164. package/dist/runtime/workspace-resource-estimator.js +174 -0
  165. package/dist/sandbox/command-runner.d.ts +4 -0
  166. package/dist/sandbox/command-runner.js +47 -0
  167. package/dist/sandbox/contract.d.ts +5 -0
  168. package/dist/sandbox/contract.js +276 -0
  169. package/dist/sandbox/event-budget.d.ts +11 -0
  170. package/dist/sandbox/event-budget.js +27 -0
  171. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  172. package/dist/sandbox/host-capacity-broker.js +336 -0
  173. package/dist/sandbox/image-policy.d.ts +35 -0
  174. package/dist/sandbox/image-policy.js +247 -0
  175. package/dist/sandbox/index.d.ts +5 -0
  176. package/dist/sandbox/index.js +5 -0
  177. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  178. package/dist/sandbox/lease-watchdog.js +67 -0
  179. package/dist/sandbox/managed-branch.d.ts +13 -0
  180. package/dist/sandbox/managed-branch.js +36 -0
  181. package/dist/sandbox/preflight.d.ts +84 -0
  182. package/dist/sandbox/preflight.js +521 -0
  183. package/dist/sandbox/process.d.ts +20 -0
  184. package/dist/sandbox/process.js +209 -0
  185. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  186. package/dist/sandbox/provider-auth/codex.js +212 -0
  187. package/dist/sandbox/repository-lock.d.ts +6 -0
  188. package/dist/sandbox/repository-lock.js +129 -0
  189. package/dist/sandbox/runtime.d.ts +311 -0
  190. package/dist/sandbox/runtime.js +2407 -0
  191. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  192. package/dist/sandbox/sandbox-cgroups.js +42 -0
  193. package/dist/sandbox/sandbox.types.d.ts +93 -0
  194. package/dist/sandbox/sandbox.types.js +1 -0
  195. package/dist/sandbox/smoke.d.ts +76 -0
  196. package/dist/sandbox/smoke.js +380 -0
  197. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  198. package/dist/sandbox/worker-supervisor.js +36 -0
  199. package/dist/sandbox/worker.d.ts +1 -0
  200. package/dist/sandbox/worker.js +225 -0
  201. package/dist/sandbox/workspace.service.d.ts +13 -0
  202. package/dist/sandbox/workspace.service.js +74 -0
  203. package/dist/session/architect-waits.d.ts +2 -0
  204. package/dist/session/architect-waits.js +138 -0
  205. package/dist/session/managed-attempt-tools.d.ts +48 -0
  206. package/dist/session/managed-attempt-tools.js +1299 -0
  207. package/dist/session/managed-build-coordinator.d.ts +5 -0
  208. package/dist/session/managed-build-coordinator.js +109 -0
  209. package/dist/session/managed-build-receipt.d.ts +26 -0
  210. package/dist/session/managed-build-receipt.js +342 -0
  211. package/dist/session/managed-command-host-load.d.ts +47 -0
  212. package/dist/session/managed-command-host-load.js +83 -0
  213. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  214. package/dist/session/managed-verification-timeouts.js +17 -0
  215. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  216. package/dist/session/mcp-argument-coercion.js +121 -0
  217. package/dist/session/phase-completion.artifacts.d.ts +34 -0
  218. package/dist/session/phase-completion.artifacts.js +903 -0
  219. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  220. package/dist/session/phase-completion.command-validation.js +77 -0
  221. package/dist/session/phase-completion.d.ts +65 -42
  222. package/dist/session/phase-completion.helpers.d.ts +117 -0
  223. package/dist/session/phase-completion.helpers.js +708 -0
  224. package/dist/session/phase-completion.js +130 -3007
  225. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  226. package/dist/session/phase-completion.mcp-args.js +156 -0
  227. package/dist/session/phase-completion.prompts.d.ts +14 -0
  228. package/dist/session/phase-completion.prompts.js +238 -0
  229. package/dist/session/phase-completion.runtime.d.ts +43 -0
  230. package/dist/session/phase-completion.runtime.js +721 -0
  231. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  232. package/dist/session/phase-completion.schema-parts.js +188 -0
  233. package/dist/session/phase-completion.schemas.d.ts +3 -0
  234. package/dist/session/phase-completion.schemas.js +836 -0
  235. package/dist/session/phase-completion.validation.d.ts +37 -0
  236. package/dist/session/phase-completion.validation.js +874 -0
  237. package/dist/session/pre-publication-host-load.d.ts +27 -0
  238. package/dist/session/pre-publication-host-load.js +111 -0
  239. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  240. package/dist/session/pre-publication-native-postgres.js +111 -0
  241. package/dist/session/pre-publication-pass.d.ts +61 -0
  242. package/dist/session/pre-publication-pass.js +148 -0
  243. package/dist/session/pre-publication-process.d.ts +23 -0
  244. package/dist/session/pre-publication-process.js +109 -0
  245. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  246. package/dist/session/pre-publication-skipped-tests.js +109 -0
  247. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  248. package/dist/session/pre-publication-step-execution.js +50 -0
  249. package/dist/session/pre-publication-validation.d.ts +91 -0
  250. package/dist/session/pre-publication-validation.js +670 -0
  251. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  252. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  253. package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
  254. package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
  255. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  256. package/dist/session/provider-cli/claude-background-work.js +181 -0
  257. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  258. package/dist/session/provider-cli/host-build-lock.js +30 -0
  259. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  260. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  261. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +96 -0
  262. package/dist/session/provider-cli/provider-cli.artifacts.js +818 -0
  263. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  264. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  265. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  266. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  267. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  268. package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
  269. package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
  270. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
  271. package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
  272. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  273. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  274. package/dist/session/provider-cli/provider-cli.process.d.ts +114 -0
  275. package/dist/session/provider-cli/provider-cli.process.js +757 -0
  276. package/dist/session/provider-cli/provider-cli.prompts.d.ts +62 -0
  277. package/dist/session/provider-cli/provider-cli.prompts.js +770 -0
  278. package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
  279. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
  280. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  281. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  282. package/dist/session/provider-cli/provider-cli.runtime.d.ts +30 -0
  283. package/dist/session/provider-cli/provider-cli.runtime.js +120 -0
  284. package/dist/session/provider-cli/provider-cli.service.d.ts +53 -53
  285. package/dist/session/provider-cli/provider-cli.service.js +1299 -2523
  286. package/dist/session/provider-cli/provider-cli.types.d.ts +38 -0
  287. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  288. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  289. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  290. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  291. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  292. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  293. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  294. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  295. package/dist/session/provider-cli/provider-output-state.d.ts +40 -0
  296. package/dist/session/provider-cli/provider-output-state.js +832 -0
  297. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  298. package/dist/session/provider-cli/provider-usage.js +28 -5
  299. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  300. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  301. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  302. package/dist/session/publishable-worktree-changes.js +193 -0
  303. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  304. package/dist/session/qa-sidecar-validation.js +28 -0
  305. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  306. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  307. package/dist/session/session-redaction.d.ts +3 -0
  308. package/dist/session/session-redaction.js +298 -0
  309. package/dist/session/session.base.d.ts +14 -1
  310. package/dist/session/session.service.d.ts +17 -2
  311. package/dist/session/session.service.js +708 -60
  312. package/dist/session/session.types.d.ts +327 -3
  313. package/dist/session/session.types.js +951 -10
  314. package/dist/session/sidecar-json-shape.d.ts +31 -0
  315. package/dist/session/sidecar-json-shape.js +217 -0
  316. package/dist/session/unreferenced-exports.d.ts +12 -0
  317. package/dist/session/unreferenced-exports.js +59 -0
  318. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  319. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  320. package/dist/shared/format/format-bytes.d.ts +1 -0
  321. package/dist/shared/format/format-bytes.js +9 -0
  322. package/dist/shared/fs/file-identity.d.ts +10 -0
  323. package/dist/shared/fs/file-identity.js +15 -0
  324. package/dist/shared/fs/replace-file.d.ts +7 -0
  325. package/dist/shared/fs/replace-file.js +33 -0
  326. package/dist/shared/git/git.js +2 -1
  327. package/dist/shared/path/path.d.ts +1 -0
  328. package/dist/shared/path/path.js +21 -1
  329. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  330. package/dist/shared/process/dotnet-toolchain.js +307 -0
  331. package/dist/shared/process/host-process-recovery.d.ts +23 -0
  332. package/dist/shared/process/host-process-recovery.js +99 -0
  333. package/dist/shared/process/host-process-supervisor.d.ts +72 -0
  334. package/dist/shared/process/host-process-supervisor.js +383 -0
  335. package/dist/shared/process/process-tree.d.ts +52 -0
  336. package/dist/shared/process/process-tree.js +144 -0
  337. package/dist/shared/process/process.d.ts +70 -0
  338. package/dist/shared/process/process.js +224 -16
  339. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  340. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  341. package/dist/shared/process/windows-launch.d.ts +26 -0
  342. package/dist/shared/process/windows-launch.js +109 -0
  343. package/dist/shared/provider-capabilities.d.ts +4 -0
  344. package/dist/shared/provider-capabilities.js +95 -0
  345. package/dist/shared/redaction/redaction.d.ts +1 -0
  346. package/dist/shared/redaction/redaction.js +47 -4
  347. package/dist/shared/time/monotonic.d.ts +1 -0
  348. package/dist/shared/time/monotonic.js +8 -0
  349. package/dist/version.d.ts +1 -1
  350. package/dist/version.js +1 -1
  351. package/dist/worktree/artifact-injector.d.ts +3 -2
  352. package/dist/worktree/artifact-injector.js +82 -10
  353. package/dist/worktree/dependency-warmer.d.ts +78 -1
  354. package/dist/worktree/dependency-warmer.js +731 -13
  355. package/dist/worktree/index.d.ts +2 -1
  356. package/dist/worktree/index.js +1 -0
  357. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  358. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  359. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  360. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  361. package/dist/worktree/wip-git.d.ts +33 -0
  362. package/dist/worktree/wip-git.js +122 -0
  363. package/dist/worktree/wip-refs.d.ts +62 -0
  364. package/dist/worktree/wip-refs.js +119 -0
  365. package/dist/worktree/wip-restore.d.ts +38 -0
  366. package/dist/worktree/wip-restore.js +190 -0
  367. package/dist/worktree/wip-snapshot.d.ts +50 -0
  368. package/dist/worktree/wip-snapshot.js +268 -0
  369. package/dist/worktree/worktree-paths.d.ts +4 -0
  370. package/dist/worktree/worktree-paths.js +30 -0
  371. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  372. package/dist/worktree/worktree-wip-events.js +98 -0
  373. package/dist/worktree/worktree-wip.d.ts +49 -0
  374. package/dist/worktree/worktree-wip.js +182 -0
  375. package/dist/worktree/worktree.base.d.ts +10 -1
  376. package/dist/worktree/worktree.service.d.ts +30 -4
  377. package/dist/worktree/worktree.service.js +379 -54
  378. package/dist/worktree/worktree.types.d.ts +38 -1
  379. package/package.json +12 -7
  380. package/runtime/windows-job-supervisor.ps1 +722 -0
  381. package/runtime/windows-listener-owner.ps1 +33 -0
@@ -0,0 +1,385 @@
1
+ import { execFile } from "node:child_process";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ const windowsListenerOwnerPath = fileURLToPath(new URL("../../runtime/windows-listener-owner.ps1", import.meta.url));
6
+ const windowsNetstatArgs = ["-ano", "-p", "TCP"];
7
+ const windowsNetstatAttempts = 3;
8
+ const windowsAncestryAttempts = 2;
9
+ const windowsNetstatRetryDelayMs = 250;
10
+ const inspectionCommandTimeoutMs = 15_000;
11
+ /** Proves that a loopback listener belongs to one exact supervised child. */
12
+ export class HostListenerInspector {
13
+ commands;
14
+ platform;
15
+ retryDelayMs;
16
+ constructor(commands = new ExecFileInspectionCommandRunner(), platform = process.platform, retryDelayMs = windowsNetstatRetryDelayMs) {
17
+ this.commands = commands;
18
+ this.platform = platform;
19
+ this.retryDelayMs = retryDelayMs;
20
+ }
21
+ async inspect(child, reservation, owner) {
22
+ if (reservation.hostIp !== "127.0.0.1" || reservation.protocol !== "tcp") {
23
+ throw new Error("host_listener_inspection_invalid: only TCP IPv4 loopback listeners are supported.");
24
+ }
25
+ const metadata = await loadMetadata(child.metadataPath);
26
+ if (!metadata)
27
+ return "unbound";
28
+ if (!matchesOwner(metadata, child, owner))
29
+ return "foreign";
30
+ if (this.platform === "win32") {
31
+ return await this.inspectWindows(metadata.rootPid, reservation.hostPort);
32
+ }
33
+ return await this.inspectUnix(metadata.rootPid, reservation.hostPort);
34
+ }
35
+ /** Returns loopback TCP ports opened by one exact supervised child process tree. */
36
+ async inspectOwnedLoopbackListeners(child, owner) {
37
+ const metadata = await loadMetadata(child.metadataPath);
38
+ if (!metadata || !matchesOwner(metadata, child, owner)) {
39
+ throw new Error("host_listener_inspection_invalid: supervised provider ownership metadata is unavailable.");
40
+ }
41
+ return this.platform === "win32"
42
+ ? await this.inspectAllWindows(metadata.rootPid)
43
+ : await this.inspectAllUnix(metadata.rootPid);
44
+ }
45
+ /** Snapshots loopback TCP ports that predate a supervised child launch. */
46
+ async inspectLoopbackListeners() {
47
+ if (this.platform === "win32") {
48
+ const netstat = await this.runWindowsNetstat();
49
+ return uniqueSorted(parseWindowsLoopbackListeners(netstat.stdout).map(listener => listener.port));
50
+ }
51
+ const lsof = await this.commands.run("lsof", [
52
+ "-nP",
53
+ "-a",
54
+ "-iTCP@127.0.0.1",
55
+ "-sTCP:LISTEN",
56
+ "-Fpn",
57
+ ]);
58
+ if (lsof.exitCode === 0 || lsof.exitCode === 1) {
59
+ return uniqueSorted(parseLsofLoopbackListeners(lsof.stdout).map(listener => listener.port));
60
+ }
61
+ if (lsof.errorCode !== "ENOENT")
62
+ throw commandError("lsof", lsof);
63
+ const ss = await this.commands.run("ss", ["-H", "-ltnp"]);
64
+ if (ss.exitCode !== 0)
65
+ throw commandError("ss", ss);
66
+ return uniqueSorted(parseSsLoopbackListeners(ss.stdout).map(listener => listener.port));
67
+ }
68
+ async inspectWindows(rootPid, port) {
69
+ const netstat = await this.runWindowsNetstat();
70
+ const listenerPids = parseWindowsListenerPids(netstat.stdout, port);
71
+ if (listenerPids.length === 0)
72
+ return "unbound";
73
+ const values = await this.runWindowsAncestry(rootPid, listenerPids);
74
+ return values.every(value => value) ? "owned" : "foreign";
75
+ }
76
+ async inspectAllWindows(rootPid) {
77
+ const netstat = await this.runWindowsNetstat();
78
+ const listeners = parseWindowsLoopbackListeners(netstat.stdout);
79
+ if (listeners.length === 0)
80
+ return [];
81
+ const pids = [...new Set(listeners.map(listener => listener.pid))];
82
+ const values = await this.runWindowsAncestry(rootPid, pids);
83
+ const ownedPids = new Set(pids.filter((_pid, index) => values[index] === true));
84
+ return uniqueSorted(listeners.filter(listener => ownedPids.has(listener.pid)).map(listener => listener.port));
85
+ }
86
+ async runWindowsAncestry(rootPid, listenerPids) {
87
+ let lastResult = null;
88
+ let lastParseError;
89
+ for (let attempt = 1; attempt <= windowsAncestryAttempts; attempt += 1) {
90
+ const result = await this.commands.run(windowsPowerShellPath(), [
91
+ "-NoLogo",
92
+ "-NoProfile",
93
+ "-NonInteractive",
94
+ "-ExecutionPolicy",
95
+ "Bypass",
96
+ "-File",
97
+ windowsListenerOwnerPath,
98
+ "-RootProcessId",
99
+ String(rootPid),
100
+ "-ListenerProcessIds",
101
+ listenerPids.join(","),
102
+ ]);
103
+ lastResult = result;
104
+ if (result.exitCode !== 0) {
105
+ if (!isTransientWindowsInspectionFailure(result) || attempt === windowsAncestryAttempts) {
106
+ throw commandError("Windows process ancestry", result);
107
+ }
108
+ }
109
+ else {
110
+ try {
111
+ const parsed = JSON.parse(result.stdout.trim());
112
+ const values = Array.isArray(parsed) ? parsed : [parsed];
113
+ if (values.length !== listenerPids.length || values.some(value => typeof value !== "boolean")) {
114
+ throw new Error("Windows ancestry output was incomplete.");
115
+ }
116
+ return values;
117
+ }
118
+ catch (error) {
119
+ lastParseError = error;
120
+ if (attempt === windowsAncestryAttempts) {
121
+ throw new Error(`host_diagnostics_temporary_unavailable: Windows process ancestry returned invalid output after ${attempt} attempts.`, { cause: error });
122
+ }
123
+ }
124
+ }
125
+ await wait(this.retryDelayMs);
126
+ }
127
+ if (lastResult)
128
+ throw commandError("Windows process ancestry", lastResult);
129
+ throw new Error("host_diagnostics_temporary_unavailable: Windows process ancestry produced no result.", {
130
+ cause: lastParseError,
131
+ });
132
+ }
133
+ async runWindowsNetstat() {
134
+ let lastResult = null;
135
+ for (let attempt = 1; attempt <= windowsNetstatAttempts; attempt += 1) {
136
+ const result = await this.commands.run("netstat.exe", windowsNetstatArgs);
137
+ if (result.exitCode === 0)
138
+ return result;
139
+ lastResult = result;
140
+ if (!isTransientWindowsNetstatFailure(result) || attempt === windowsNetstatAttempts)
141
+ break;
142
+ await wait(this.retryDelayMs);
143
+ }
144
+ throw commandError("netstat", lastResult);
145
+ }
146
+ async inspectUnix(rootPid, port) {
147
+ let listenerPids = null;
148
+ const lsof = await this.commands.run("lsof", [
149
+ "-nP",
150
+ "-a",
151
+ `-iTCP@127.0.0.1:${port}`,
152
+ "-sTCP:LISTEN",
153
+ "-Fp",
154
+ ]);
155
+ if (lsof.exitCode === 0 || lsof.exitCode === 1) {
156
+ listenerPids = parseLsofPids(lsof.stdout);
157
+ }
158
+ else if (lsof.errorCode !== "ENOENT") {
159
+ throw commandError("lsof", lsof);
160
+ }
161
+ if (listenerPids === null) {
162
+ const ss = await this.commands.run("ss", ["-H", "-ltnp", "sport", "=", `:${port}`]);
163
+ if (ss.exitCode !== 0)
164
+ throw commandError("ss", ss);
165
+ listenerPids = parseSsPids(ss.stdout, port);
166
+ }
167
+ if (listenerPids.length === 0)
168
+ return "unbound";
169
+ const processGroups = await this.commands.run("ps", [
170
+ "-o",
171
+ "pid=,pgid=",
172
+ "-p",
173
+ listenerPids.join(","),
174
+ ]);
175
+ if (processGroups.exitCode !== 0)
176
+ throw commandError("ps", processGroups);
177
+ const groups = parseProcessGroups(processGroups.stdout);
178
+ return listenerPids.every(pid => groups.get(pid) === rootPid) ? "owned" : "foreign";
179
+ }
180
+ async inspectAllUnix(rootPid) {
181
+ const lsof = await this.commands.run("lsof", [
182
+ "-nP",
183
+ "-a",
184
+ "-iTCP@127.0.0.1",
185
+ "-sTCP:LISTEN",
186
+ "-Fpn",
187
+ ]);
188
+ let listeners;
189
+ if (lsof.exitCode === 0 || lsof.exitCode === 1) {
190
+ listeners = parseLsofLoopbackListeners(lsof.stdout);
191
+ }
192
+ else if (lsof.errorCode === "ENOENT") {
193
+ const ss = await this.commands.run("ss", ["-H", "-ltnp"]);
194
+ if (ss.exitCode !== 0)
195
+ throw commandError("ss", ss);
196
+ listeners = parseSsLoopbackListeners(ss.stdout);
197
+ }
198
+ else {
199
+ throw commandError("lsof", lsof);
200
+ }
201
+ if (listeners.length === 0)
202
+ return [];
203
+ const pids = [...new Set(listeners.map(listener => listener.pid))];
204
+ const processGroups = await this.commands.run("ps", ["-o", "pid=,pgid=", "-p", pids.join(",")]);
205
+ if (processGroups.exitCode !== 0)
206
+ throw commandError("ps", processGroups);
207
+ const groups = parseProcessGroups(processGroups.stdout);
208
+ return uniqueSorted(listeners
209
+ .filter(listener => groups.get(listener.pid) === rootPid)
210
+ .map(listener => listener.port));
211
+ }
212
+ }
213
+ export function parseWindowsLoopbackListeners(output) {
214
+ return uniqueListeners(output.split(/\r?\n/u).flatMap(line => {
215
+ const fields = line.trim().split(/\s+/u);
216
+ if (fields.length < 5 || fields[0]?.toUpperCase() !== "TCP" || fields[3]?.toUpperCase() !== "LISTENING")
217
+ return [];
218
+ const endpoint = parseIpv4LoopbackEndpoint(fields[1]);
219
+ const pids = validPid(fields[4]);
220
+ return endpoint && pids.length === 1 ? [{ pid: pids[0], port: endpoint }] : [];
221
+ }));
222
+ }
223
+ export function parseLsofLoopbackListeners(output) {
224
+ const listeners = [];
225
+ let pid = null;
226
+ for (const line of output.split(/\r?\n/u)) {
227
+ if (line.startsWith("p"))
228
+ pid = validPid(line.slice(1))[0] ?? null;
229
+ if (!line.startsWith("n") || pid === null)
230
+ continue;
231
+ const port = parseIpv4LoopbackEndpoint(line.slice(1));
232
+ if (port !== null)
233
+ listeners.push({ pid, port });
234
+ }
235
+ return uniqueListeners(listeners);
236
+ }
237
+ export function parseSsLoopbackListeners(output) {
238
+ return uniqueListeners(output.split(/\r?\n/u).flatMap(line => {
239
+ const endpoint = line.match(/127\.0\.0\.1:(\d+)/u)?.[1];
240
+ const port = endpoint ? Number.parseInt(endpoint, 10) : 0;
241
+ if (!Number.isSafeInteger(port) || port < 1 || port > 65535)
242
+ return [];
243
+ return [...line.matchAll(/pid=(\d+)/gu)].flatMap(match => {
244
+ const pid = validPid(match[1])[0];
245
+ return pid ? [{ pid, port }] : [];
246
+ });
247
+ }));
248
+ }
249
+ export class ExecFileInspectionCommandRunner {
250
+ run(command, args) {
251
+ return new Promise(resolve => {
252
+ const executable = process.platform === "win32" && command.toLowerCase() === "netstat.exe"
253
+ ? windowsSystemExecutable("netstat.exe")
254
+ : command;
255
+ execFile(executable, args, {
256
+ windowsHide: true,
257
+ timeout: inspectionCommandTimeoutMs,
258
+ maxBuffer: 4 * 1024 * 1024,
259
+ }, (error, stdout, stderr) => {
260
+ const processError = error;
261
+ const timedOut = Boolean(processError?.killed && processError.signal === "SIGTERM" && processError.code == null);
262
+ resolve({
263
+ exitCode: typeof processError?.code === "number" ? processError.code : error ? 1 : 0,
264
+ stdout: String(stdout),
265
+ stderr: String(stderr),
266
+ ...(typeof processError?.code === "string" ? { errorCode: processError.code } : {}),
267
+ ...(timedOut ? { timedOut: true } : {}),
268
+ ...(processError?.signal ? { signal: processError.signal } : {}),
269
+ });
270
+ });
271
+ });
272
+ }
273
+ }
274
+ export function parseWindowsListenerPids(output, port) {
275
+ const suffix = `:${port}`;
276
+ const pids = output.split(/\r?\n/u).flatMap(line => {
277
+ const fields = line.trim().split(/\s+/u);
278
+ if (fields.length < 5 || fields[0]?.toUpperCase() !== "TCP" || fields[3]?.toUpperCase() !== "LISTENING")
279
+ return [];
280
+ if (fields[1] !== `127.0.0.1${suffix}`)
281
+ return [];
282
+ return validPid(fields[4]);
283
+ });
284
+ return uniqueSorted(pids);
285
+ }
286
+ export function parseLsofPids(output) {
287
+ return uniqueSorted(output.split(/\r?\n/u).flatMap(line => line.startsWith("p") ? validPid(line.slice(1)) : []));
288
+ }
289
+ export function parseSsPids(output, port) {
290
+ return uniqueSorted(output.split(/\r?\n/u).flatMap(line => {
291
+ if (!line.includes(`127.0.0.1:${port}`))
292
+ return [];
293
+ return [...line.matchAll(/pid=(\d+)/gu)].flatMap(match => validPid(match[1]));
294
+ }));
295
+ }
296
+ export function parseProcessGroups(output) {
297
+ const groups = new Map();
298
+ for (const line of output.split(/\r?\n/u)) {
299
+ const fields = line.trim().split(/\s+/u);
300
+ const pid = validPid(fields[0]);
301
+ const group = validPid(fields[1]);
302
+ if (pid.length === 1 && group.length === 1)
303
+ groups.set(pid[0], group[0]);
304
+ }
305
+ return groups;
306
+ }
307
+ async function loadMetadata(metadataPath) {
308
+ try {
309
+ const parsed = JSON.parse(await fs.readFile(metadataPath, "utf8"));
310
+ if (parsed.schemaVersion !== 1 || !Number.isSafeInteger(parsed.rootPid) || parsed.rootPid <= 0) {
311
+ throw new Error("host_listener_inspection_invalid: process supervisor metadata is invalid.");
312
+ }
313
+ return parsed;
314
+ }
315
+ catch (error) {
316
+ if (error.code === "ENOENT")
317
+ return null;
318
+ throw error;
319
+ }
320
+ }
321
+ function matchesOwner(metadata, child, owner) {
322
+ return metadata.supervisorId === child.processSupervisorId
323
+ && metadata.runtimeLeaseId === owner.executionLeaseId
324
+ && metadata.dispatchAttemptId === owner.dispatchAttemptId
325
+ && metadata.fencingToken === owner.fencingToken;
326
+ }
327
+ function validPid(value) {
328
+ if (!value || !/^\d+$/u.test(value))
329
+ return [];
330
+ const pid = Number.parseInt(value, 10);
331
+ return Number.isSafeInteger(pid) && pid > 0 ? [pid] : [];
332
+ }
333
+ function uniqueSorted(values) {
334
+ return [...new Set(values)].sort((left, right) => left - right);
335
+ }
336
+ function parseIpv4LoopbackEndpoint(value) {
337
+ const match = value?.match(/^127\.0\.0\.1:(\d+)$/u);
338
+ if (!match)
339
+ return null;
340
+ const port = Number.parseInt(match[1], 10);
341
+ return Number.isSafeInteger(port) && port >= 1 && port <= 65535 ? port : null;
342
+ }
343
+ function uniqueListeners(values) {
344
+ const seen = new Set();
345
+ return values.filter(value => {
346
+ const key = `${value.pid}:${value.port}`;
347
+ if (seen.has(key))
348
+ return false;
349
+ seen.add(key);
350
+ return true;
351
+ }).sort((left, right) => left.port - right.port || left.pid - right.pid);
352
+ }
353
+ function commandError(label, result) {
354
+ const detail = result.stderr.replaceAll(/[\r\n\t]+/gu, " ").trim().slice(0, 512);
355
+ const code = result.errorCode ? ` (${result.errorCode})` : "";
356
+ if (result.timedOut) {
357
+ return new Error(`host_diagnostics_temporary_unavailable: ${label} timed out after ${inspectionCommandTimeoutMs} ms${result.signal ? ` (${result.signal})` : ""}.`);
358
+ }
359
+ if (isTransientWindowsNetstatFailure(result)) {
360
+ return new Error(`host_diagnostics_temporary_unavailable: ${label} repeatedly exited ${result.exitCode} without diagnostics.`);
361
+ }
362
+ return new Error(`host_listener_inspection_failed: ${label} exited ${result.exitCode}${code}${detail ? `: ${detail}` : ""}.`);
363
+ }
364
+ function isTransientWindowsNetstatFailure(result) {
365
+ return isTransientWindowsInspectionFailure(result);
366
+ }
367
+ function isTransientWindowsInspectionFailure(result) {
368
+ return result.timedOut === true
369
+ || (result.exitCode === 1
370
+ && !result.errorCode
371
+ && !result.stdout.trim()
372
+ && !result.stderr.trim());
373
+ }
374
+ function wait(milliseconds) {
375
+ return milliseconds > 0
376
+ ? new Promise(resolve => setTimeout(resolve, milliseconds))
377
+ : Promise.resolve();
378
+ }
379
+ function windowsPowerShellPath() {
380
+ return path.win32.join(path.dirname(windowsSystemExecutable("netstat.exe")), "WindowsPowerShell", "v1.0", "powershell.exe");
381
+ }
382
+ function windowsSystemExecutable(name) {
383
+ const systemRoot = process.env.SystemRoot?.trim() || "C:\\Windows";
384
+ return path.win32.join(systemRoot, "System32", name);
385
+ }
@@ -0,0 +1,67 @@
1
+ import type { HostLoadGovernorConfig } from "./host-load-governor-config.js";
2
+ import type { HostLoadStepCost } from "./host-load-step-class.js";
3
+ /** Measured host load the admission rule reads. Null means PSI is unavailable or stale. */
4
+ export interface HostLoadSignals {
5
+ /**
6
+ * Host-wide CPU PSI `some avg10`, used as is (never split per cgroup). On Windows,
7
+ * the estimate from host CPU use in the same shape (decision 0021).
8
+ */
9
+ readonly cpuSomeAvg10: number;
10
+ /** Consecutive samples, ending with the latest, at or above the CPU pressure threshold. */
11
+ readonly cpuPressuredSamples: number;
12
+ /** Host-wide memory PSI `full avg10`; a hard stop above its threshold. */
13
+ readonly memoryFullAvg10: number | null;
14
+ readonly memoryAvailableBytes: number | null;
15
+ /**
16
+ * Host CPU from /proc/stat minus the bridge's dedicated cgroup over the same
17
+ * window. Null when the bridge's cgroup is not dedicated: Forge's own work is
18
+ * then counted only through reserved cost and the host PSI gate.
19
+ */
20
+ readonly externalCpuCores: number | null;
21
+ }
22
+ export type HostLoadAdmissionReason = "admitted" | "admitted_alone" | "admitted_fallback" | "cpu_budget" | "memory_budget" | "cpu_pressure" | "memory_pressure" | "fallback_slots"
23
+ /** Decision 0014: the host already runs the owner's maximum number of heavy steps. */
24
+ | "heavy_step_limit"
25
+ /** A corrupt ledger was quarantined; admissions wait one lease while owners restore their reservations. */
26
+ | "ledger_recovering"
27
+ /** Decision 0018: the host test slot is free and this step is next in the host queue. */
28
+ | "admitted_test_slot"
29
+ /** Decision 0018: the host test slot is taken, or steps ahead in the host queue take it first. */
30
+ | "host_test_slot";
31
+ export interface HostLoadAdmissionInput {
32
+ readonly request: HostLoadStepCost;
33
+ /** Reserved cost of every live token on this host (all processes). */
34
+ readonly running: readonly HostLoadStepCost[];
35
+ /**
36
+ * Memory the running steps already use. MemAvailable already excludes it, so
37
+ * it is added back to the budget (capped at their reservations) instead of
38
+ * being counted twice.
39
+ */
40
+ readonly runningMemoryBytes?: number;
41
+ readonly logicalCpus: number;
42
+ readonly signals: HostLoadSignals | null;
43
+ readonly config: Pick<HostLoadGovernorConfig, "cpuBudgetFraction" | "memoryReserveBytes" | "cpuPressureThreshold" | "backpressureSamples" | "memoryFullThreshold" | "fallbackSlots">;
44
+ /**
45
+ * Decision 0014 "Max concurrent heavy steps": a host-wide count limit on top of
46
+ * the budget. Null or absent means the budget alone decides.
47
+ */
48
+ readonly maxHeavySteps?: number | null;
49
+ }
50
+ export interface HostLoadAdmissionDecision {
51
+ readonly admitted: boolean;
52
+ readonly reason: HostLoadAdmissionReason;
53
+ readonly cpuBudgetCores: number | null;
54
+ readonly memoryBudgetBytes: number | null;
55
+ readonly reservedCpuCores: number;
56
+ readonly reservedMemoryBytes: number;
57
+ readonly detail: string;
58
+ }
59
+ /**
60
+ * Decision 0013 admission rule. A step is admitted when the reserved cost of
61
+ * running steps plus its own cost fits the budget and host pressure is under
62
+ * the backpressure threshold. Memory `full` pressure is a hard stop. A step
63
+ * too large for the budget on its own runs only when nothing else does. An
64
+ * optional count limit (decision 0014) caps how many heavy steps run at once.
65
+ * Without PSI, a simple per-host semaphore applies instead.
66
+ */
67
+ export declare function decideHostLoadAdmission(input: HostLoadAdmissionInput): HostLoadAdmissionDecision;
@@ -0,0 +1,99 @@
1
+ const epsilon = 1e-9;
2
+ /**
3
+ * Decision 0013 admission rule. A step is admitted when the reserved cost of
4
+ * running steps plus its own cost fits the budget and host pressure is under
5
+ * the backpressure threshold. Memory `full` pressure is a hard stop. A step
6
+ * too large for the budget on its own runs only when nothing else does. An
7
+ * optional count limit (decision 0014) caps how many heavy steps run at once.
8
+ * Without PSI, a simple per-host semaphore applies instead.
9
+ */
10
+ export function decideHostLoadAdmission(input) {
11
+ const { request, running, signals, config } = input;
12
+ const reservedCpuCores = running.reduce((sum, cost) => sum + cost.cpuCores, 0);
13
+ const reservedMemoryBytes = running.reduce((sum, cost) => sum + cost.memoryBytes, 0);
14
+ const base = { reservedCpuCores, reservedMemoryBytes };
15
+ const maxHeavySteps = input.maxHeavySteps ?? null;
16
+ if (!signals) {
17
+ // The count limit narrows the semaphore: min(fallback slots, max heavy steps).
18
+ const limited = maxHeavySteps !== null && maxHeavySteps < config.fallbackSlots;
19
+ const slots = limited ? maxHeavySteps : config.fallbackSlots;
20
+ const admitted = running.length < slots;
21
+ return {
22
+ ...base,
23
+ admitted,
24
+ reason: admitted ? "admitted_fallback" : limited ? "heavy_step_limit" : "fallback_slots",
25
+ cpuBudgetCores: null,
26
+ memoryBudgetBytes: null,
27
+ detail: admitted
28
+ ? "Host pressure data is unavailable; admitted under the per-host step semaphore."
29
+ : limited
30
+ ? `Host pressure data is unavailable; ${running.length} of ${slots} heavy step(s) allowed at once are running (max heavy steps).`
31
+ : `Host pressure data is unavailable; ${running.length} of ${config.fallbackSlots} heavy step slot(s) are in use.`,
32
+ };
33
+ }
34
+ const cpuBudgetCores = Math.max(0, input.logicalCpus * config.cpuBudgetFraction - (signals.externalCpuCores ?? 0));
35
+ const usedByRunning = Math.min(reservedMemoryBytes, Math.max(0, input.runningMemoryBytes ?? 0));
36
+ const memoryBudgetBytes = signals.memoryAvailableBytes === null
37
+ ? null
38
+ : Math.max(0, signals.memoryAvailableBytes + usedByRunning - config.memoryReserveBytes);
39
+ const budget = { ...base, cpuBudgetCores, memoryBudgetBytes };
40
+ if (signals.memoryFullAvg10 !== null && signals.memoryFullAvg10 > config.memoryFullThreshold) {
41
+ return {
42
+ ...budget,
43
+ admitted: false,
44
+ reason: "memory_pressure",
45
+ detail: `Host memory pressure (full avg10 ${signals.memoryFullAvg10}%) is above ${config.memoryFullThreshold}%; no heavy step may start.`,
46
+ };
47
+ }
48
+ if (signals.cpuPressuredSamples >= config.backpressureSamples) {
49
+ return {
50
+ ...budget,
51
+ admitted: false,
52
+ reason: "cpu_pressure",
53
+ detail: `Host CPU pressure (some avg10 ${signals.cpuSomeAvg10}%) has been at or above ${config.cpuPressureThreshold}% for ${signals.cpuPressuredSamples} sample(s).`,
54
+ };
55
+ }
56
+ if (maxHeavySteps !== null && running.length >= maxHeavySteps) {
57
+ return {
58
+ ...budget,
59
+ admitted: false,
60
+ reason: "heavy_step_limit",
61
+ detail: `${running.length} heavy step(s) are running and the host allows at most ${maxHeavySteps} at once.`,
62
+ };
63
+ }
64
+ if (running.length === 0) {
65
+ const oversize = request.cpuCores > cpuBudgetCores + epsilon
66
+ || (memoryBudgetBytes !== null && request.memoryBytes > memoryBudgetBytes + epsilon);
67
+ return {
68
+ ...budget,
69
+ admitted: true,
70
+ reason: oversize ? "admitted_alone" : "admitted",
71
+ detail: oversize
72
+ ? "The step exceeds the host budget on its own and runs alone because nothing else is running."
73
+ : "The step fits the host budget.",
74
+ };
75
+ }
76
+ if (reservedCpuCores + request.cpuCores > cpuBudgetCores + epsilon) {
77
+ return {
78
+ ...budget,
79
+ admitted: false,
80
+ reason: "cpu_budget",
81
+ detail: `Reserved ${round(reservedCpuCores)} + requested ${round(request.cpuCores)} cores exceed the ${round(cpuBudgetCores)}-core budget${signals.externalCpuCores ? ` (${round(signals.externalCpuCores)} cores of external load)` : ""}.`,
82
+ };
83
+ }
84
+ if (memoryBudgetBytes !== null && reservedMemoryBytes + request.memoryBytes > memoryBudgetBytes + epsilon) {
85
+ return {
86
+ ...budget,
87
+ admitted: false,
88
+ reason: "memory_budget",
89
+ detail: `Reserved ${gib(reservedMemoryBytes)} + requested ${gib(request.memoryBytes)} GiB exceed the ${gib(memoryBudgetBytes)} GiB memory budget.`,
90
+ };
91
+ }
92
+ return { ...budget, admitted: true, reason: "admitted", detail: "The step fits the host budget." };
93
+ }
94
+ function round(value) {
95
+ return Math.round(value * 100) / 100;
96
+ }
97
+ function gib(bytes) {
98
+ return round(bytes / 1024 ** 3);
99
+ }
@@ -0,0 +1,27 @@
1
+ import { HostLoadGovernor } from "./host-load-governor.js";
2
+ export declare const hostLoadGovernorEnvironment = "FORGE_HOST_LOAD_GOVERNOR";
3
+ export declare const hostLoadStateRootEnvironment = "FORGE_HOST_LOAD_STATE_ROOT";
4
+ export declare const hostLoadTestSlotsEnvironment = "FORGE_HOST_LOAD_TEST_SLOTS";
5
+ /** True for the variables that carry the governor into a child process. */
6
+ /**
7
+ * A process environment with every host load governor variable removed
8
+ * (FORGE_HOST_LOAD_*, any case) and the governor turned off explicitly. A governed
9
+ * step's own processes must never join the host ledger, or broker control, that
10
+ * their step's token is held in; since the host test slot is on by default
11
+ * (decision 0018), removing the variables alone would not keep a nested Forge
12
+ * process out.
13
+ */
14
+ export declare function withoutHostLoadGovernorVariables<T extends Readonly<Record<string, string | undefined>>>(environment: T): T;
15
+ export declare function isHostLoadChildEnvironmentName(name: string): boolean;
16
+ /**
17
+ * The variables a child needs to share this bridge's ledger: the budget flag and
18
+ * the host test slot count as this bridge resolved them, the state root, the
19
+ * operator's FORGE_HOST_LOAD_* tuning and the bridge's cgroup unit. Empty with
20
+ * the governor off, so the child stays ungoverned.
21
+ */
22
+ export declare function hostLoadChildEnvironment(stateRoot: string, environment?: Readonly<Record<string, string | undefined>>): Readonly<Record<string, string>>;
23
+ /**
24
+ * The governor a child process uses, from the variables above. Undefined when
25
+ * the governor is off or no state root was handed over: the child is ungoverned.
26
+ */
27
+ export declare function hostLoadGovernorFromChildEnvironment(environment?: Readonly<Record<string, string | undefined>>): HostLoadGovernor | undefined;
@@ -0,0 +1,76 @@
1
+ import path from "node:path";
2
+ import { HostLoadGovernor } from "./host-load-governor.js";
3
+ import { hostLoadGovernorEnabled, loadHostLoadGovernorConfig } from "./host-load-governor-config.js";
4
+ import { FileForgeCgroupRegistry } from "./host-load-forge-cgroups.js";
5
+ import { HostLoadSampler } from "./host-load-sampler.js";
6
+ // How a process the bridge starts (the completion MCP server, which runs
7
+ // managed commands) joins the bridge's host load governor (decision 0013).
8
+ // The ledger is file-backed, so the child builds its own governor on the
9
+ // bridge's state root and every token counts against one host budget.
10
+ export const hostLoadGovernorEnvironment = "FORGE_HOST_LOAD_GOVERNOR";
11
+ export const hostLoadStateRootEnvironment = "FORGE_HOST_LOAD_STATE_ROOT";
12
+ export const hostLoadTestSlotsEnvironment = "FORGE_HOST_LOAD_TEST_SLOTS";
13
+ const cgroupUnitEnvironment = "FORGE_BRIDGE_CGROUP_UNIT";
14
+ /** True for the variables that carry the governor into a child process. */
15
+ /**
16
+ * A process environment with every host load governor variable removed
17
+ * (FORGE_HOST_LOAD_*, any case) and the governor turned off explicitly. A governed
18
+ * step's own processes must never join the host ledger, or broker control, that
19
+ * their step's token is held in; since the host test slot is on by default
20
+ * (decision 0018), removing the variables alone would not keep a nested Forge
21
+ * process out.
22
+ */
23
+ export function withoutHostLoadGovernorVariables(environment) {
24
+ const kept = {};
25
+ for (const [name, value] of Object.entries(environment)) {
26
+ if (!name.toUpperCase().startsWith("FORGE_HOST_LOAD_"))
27
+ kept[name] = value;
28
+ }
29
+ kept[hostLoadGovernorEnvironment] = "off";
30
+ kept[hostLoadTestSlotsEnvironment] = "0";
31
+ return kept;
32
+ }
33
+ // Decision 0014 operator ceilings the child's governor applies itself (host-load-governor-config.ts).
34
+ const hostCeilingEnvironmentNames = new Set(["FORGE_HOST_CPU_BUDGET_PERCENT", "FORGE_HOST_MAX_HEAVY_STEPS"]);
35
+ export function isHostLoadChildEnvironmentName(name) {
36
+ return name.startsWith("FORGE_HOST_LOAD_") || name === cgroupUnitEnvironment || hostCeilingEnvironmentNames.has(name);
37
+ }
38
+ /**
39
+ * The variables a child needs to share this bridge's ledger: the budget flag and
40
+ * the host test slot count as this bridge resolved them, the state root, the
41
+ * operator's FORGE_HOST_LOAD_* tuning and the bridge's cgroup unit. Empty with
42
+ * the governor off, so the child stays ungoverned.
43
+ */
44
+ export function hostLoadChildEnvironment(stateRoot, environment = process.env) {
45
+ const config = loadHostLoadGovernorConfig(environment);
46
+ if (!hostLoadGovernorEnabled(config))
47
+ return {};
48
+ const forwarded = {};
49
+ for (const [name, value] of Object.entries(environment)) {
50
+ if (typeof value === "string" && value.trim() && isHostLoadChildEnvironmentName(name))
51
+ forwarded[name] = value;
52
+ }
53
+ forwarded[hostLoadGovernorEnvironment] = config.mode;
54
+ forwarded[hostLoadTestSlotsEnvironment] = String(config.testSlots);
55
+ forwarded[hostLoadStateRootEnvironment] = path.resolve(stateRoot);
56
+ return forwarded;
57
+ }
58
+ /**
59
+ * The governor a child process uses, from the variables above. Undefined when
60
+ * the governor is off or no state root was handed over: the child is ungoverned.
61
+ */
62
+ export function hostLoadGovernorFromChildEnvironment(environment = process.env) {
63
+ const config = loadHostLoadGovernorConfig(environment);
64
+ const stateRoot = environment[hostLoadStateRootEnvironment]?.trim();
65
+ if (!hostLoadGovernorEnabled(config) || !stateRoot || !path.isAbsolute(stateRoot))
66
+ return undefined;
67
+ return new HostLoadGovernor({
68
+ stateRoot,
69
+ config,
70
+ load: new HostLoadSampler({
71
+ cgroupUnit: environment[cgroupUnitEnvironment]?.trim() || null,
72
+ // The bridge registers its Docker sandboxes here: their CPU is Forge's own here too.
73
+ forgeCgroups: new FileForgeCgroupRegistry(stateRoot),
74
+ }),
75
+ });
76
+ }