@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,236 @@
1
+ import { formatBytes } from "../shared/format/format-bytes.js";
2
+ import { parseHostLoadGovernorMode } from "./host-load-governor-config.js";
3
+ // Decision 0014 §3 "Precedence" and §6 "Bridge hub": the server pushes a runner
4
+ // settings document (`ApplySettings`) and is the source of truth. Host env vars
5
+ // are one-sided safety bounds only: a ceiling on capacity, a floor on reserves.
6
+ // The bridge reports the effective values, their sources and every env bound it
7
+ // saw back to the server (`SettingsApplied`), so a host bound is never silent.
8
+ // Nothing here is persisted to bridge.json (0014 agent constraint).
9
+ export const runnerSettingKeys = [
10
+ "maxConcurrentAttempts",
11
+ "cpuBudgetPercent",
12
+ "yieldCpuBudgetPercent",
13
+ "memoryReserveBytes",
14
+ "maxHeavySteps",
15
+ "yieldToForeground",
16
+ ];
17
+ export const defaultCpuBudgetPercent = 80;
18
+ export const defaultYieldCpuBudgetPercent = 50;
19
+ const MiB = 1024 ** 2;
20
+ const GiB = 1024 ** 3;
21
+ /** The server's ranges (contract); a value outside them is rejected, not clamped, so it is never silent. */
22
+ const serverRanges = {
23
+ maxConcurrentAttempts: { min: 1, max: 32 },
24
+ cpuBudgetPercent: { min: 10, max: 100 },
25
+ yieldCpuBudgetPercent: { min: 10, max: 100 },
26
+ memoryReserveBytes: { min: 512 * MiB, max: 128 * GiB },
27
+ maxHeavySteps: { min: 1, max: 64 },
28
+ };
29
+ /**
30
+ * Computes every effective value (decision 0014 precedence):
31
+ * - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
32
+ * - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
33
+ * - yield: server OR the local `forge-bridge yield on` flag.
34
+ * With no document at all (and the local flag off) the values equal today's env/default behaviour.
35
+ */
36
+ export function computeEffectiveRunnerSettings(document, environment, hostDefaults, localYield) {
37
+ const rejected = [];
38
+ const server = (key) => {
39
+ const value = document?.[key] ?? null;
40
+ if (value === null)
41
+ return null;
42
+ const range = serverRanges[key];
43
+ if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
44
+ rejected.push({ key, reason: `${String(value)} is not a whole number; the host default applies.`, kind: "invalid" });
45
+ return null;
46
+ }
47
+ if (value < range.min || value > range.max) {
48
+ rejected.push({ key, reason: `${value} is outside ${range.min}-${range.max}; the host default applies.`, kind: "invalid" });
49
+ return null;
50
+ }
51
+ return value;
52
+ };
53
+ const attemptsCeiling = integerEnv(environment, "FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", 1, 32);
54
+ const cpuCeilings = cpuBudgetCeilings(environment);
55
+ const reserveFloor = integerEnv(environment, "FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * MiB, 128 * GiB);
56
+ const heavyStepsCeiling = integerEnv(environment, "FORGE_HOST_MAX_HEAVY_STEPS", 1, 64);
57
+ const attempts = ceilingValue(server("maxConcurrentAttempts"), lowest(attemptsCeiling), hostDefaults.maxConcurrentAttempts);
58
+ const cpu = ceilingValue(server("cpuBudgetPercent"), lowest(...cpuCeilings), defaultCpuBudgetPercent);
59
+ // The yield budget's ceilings are the CPU budget's. Without a server value they
60
+ // cap its default rather than replace it: a host allowing 90% CPU must not raise
61
+ // the 50% yield default, which no env var sets today.
62
+ const serverYieldCpu = server("yieldCpuBudgetPercent");
63
+ const yieldCpu = ceilingValue(serverYieldCpu ?? defaultYieldCpuBudgetPercent, lowest(...cpuCeilings), defaultYieldCpuBudgetPercent);
64
+ const yieldCpuSource = serverYieldCpu === null && yieldCpu.source === "server" ? "default" : yieldCpu.source;
65
+ const reserve = floorValue(server("memoryReserveBytes"), reserveFloor?.value ?? null, hostDefaults.memoryReserveBytes);
66
+ const heavySteps = ceilingValue(server("maxHeavySteps"), lowest(heavyStepsCeiling), null);
67
+ const serverYield = document?.yieldToForeground === true;
68
+ const yielding = serverYield || localYield;
69
+ // The host's own switch wins the label: turning the server toggle off would not stop it.
70
+ const yieldSource = localYield ? "host_local" : serverYield ? "server" : "default";
71
+ const bounds = [];
72
+ const addCeilings = (key, set) => {
73
+ for (const bound of set)
74
+ if (bound)
75
+ bounds.push({ key, envVar: bound.envVar, value: bound.value, kind: "ceiling" });
76
+ };
77
+ addCeilings("maxConcurrentAttempts", [attemptsCeiling]);
78
+ addCeilings("cpuBudgetPercent", cpuCeilings);
79
+ addCeilings("yieldCpuBudgetPercent", cpuCeilings);
80
+ if (reserveFloor)
81
+ bounds.push({ key: "memoryReserveBytes", envVar: reserveFloor.envVar, value: reserveFloor.value, kind: "floor" });
82
+ addCeilings("maxHeavySteps", [heavyStepsCeiling]);
83
+ const values = {
84
+ maxConcurrentAttempts: attempts.value,
85
+ cpuBudgetPercent: cpu.value,
86
+ yieldCpuBudgetPercent: yieldCpu.value,
87
+ memoryReserveBytes: reserve.value,
88
+ maxHeavySteps: heavySteps.value,
89
+ yieldToForeground: yielding,
90
+ };
91
+ const budgetPercent = yielding ? Math.min(values.yieldCpuBudgetPercent, values.cpuBudgetPercent) : values.cpuBudgetPercent;
92
+ return {
93
+ report: {
94
+ version: null,
95
+ governor: parseHostLoadGovernorMode(environment.FORGE_HOST_LOAD_GOVERNOR),
96
+ values,
97
+ sources: {
98
+ maxConcurrentAttempts: attempts.source,
99
+ cpuBudgetPercent: cpu.source,
100
+ yieldCpuBudgetPercent: yieldCpuSource,
101
+ memoryReserveBytes: reserve.source,
102
+ maxHeavySteps: heavySteps.source,
103
+ yieldToForeground: yieldSource,
104
+ },
105
+ bounds,
106
+ rejected,
107
+ },
108
+ yielding,
109
+ governorCpuBudgetFraction: budgetPercent / 100,
110
+ };
111
+ }
112
+ /**
113
+ * Parses the `ApplySettings` argument. Returns null when it has no usable version
114
+ * (the bridge then ignores it); malformed values become null so the host default applies.
115
+ */
116
+ export function parseRunnerSettingsDocument(raw) {
117
+ if (!raw || typeof raw !== "object")
118
+ return null;
119
+ const record = raw;
120
+ const version = record.version;
121
+ if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 0)
122
+ return null;
123
+ const numeric = (key) => {
124
+ const value = record[key];
125
+ // Kept as-is (even out of range) so computeEffectiveRunnerSettings can report it as rejected.
126
+ return typeof value === "number" ? value : null;
127
+ };
128
+ return {
129
+ runnerId: typeof record.runnerId === "string" ? record.runnerId : null,
130
+ version,
131
+ maxConcurrentAttempts: numeric("maxConcurrentAttempts"),
132
+ cpuBudgetPercent: numeric("cpuBudgetPercent"),
133
+ yieldCpuBudgetPercent: numeric("yieldCpuBudgetPercent"),
134
+ memoryReserveBytes: numeric("memoryReserveBytes"),
135
+ maxHeavySteps: numeric("maxHeavySteps"),
136
+ yieldToForeground: record.yieldToForeground === true,
137
+ };
138
+ }
139
+ /**
140
+ * The report for what is actually in force after an apply in which the host
141
+ * failed to put some keys in force: each failed key keeps the value (and source)
142
+ * that was in force before, and its failure is reported as an `apply_failed`
143
+ * rejection, so the server never reads a desired value as applied.
144
+ */
145
+ export function runnerSettingsInForce(report, previous, failures) {
146
+ if (failures.length === 0)
147
+ return report;
148
+ const values = { ...report.values };
149
+ const sources = { ...report.sources };
150
+ for (const failure of failures) {
151
+ keepPrevious(values, previous.values, failure.key);
152
+ sources[failure.key] = previous.sources[failure.key];
153
+ }
154
+ return { ...report, values, sources, rejected: [...report.rejected, ...failures] };
155
+ }
156
+ function keepPrevious(target, previous, key) {
157
+ target[key] = previous[key];
158
+ }
159
+ /** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
160
+ export function sameRunnerSettingsReport(left, right) {
161
+ return JSON.stringify(left) === JSON.stringify(right);
162
+ }
163
+ function ceilingValue(server, ceiling, fallback) {
164
+ if (server !== null) {
165
+ return ceiling && ceiling.value < server
166
+ ? { value: ceiling.value, source: "host_env" }
167
+ : { value: server, source: "server" };
168
+ }
169
+ return ceiling ? { value: ceiling.value, source: "host_env" } : { value: fallback, source: "default" };
170
+ }
171
+ function floorValue(server, floor, fallback) {
172
+ if (server !== null) {
173
+ return floor !== null && floor > server
174
+ ? { value: floor, source: "host_env" }
175
+ : { value: server, source: "server" };
176
+ }
177
+ return floor !== null ? { value: floor, source: "host_env" } : { value: fallback, source: "default" };
178
+ }
179
+ function lowest(...bounds) {
180
+ let result = null;
181
+ for (const bound of bounds) {
182
+ if (bound && (result === null || bound.value < result.value))
183
+ result = bound;
184
+ }
185
+ return result;
186
+ }
187
+ /**
188
+ * Both CPU ceilings: the new FORGE_HOST_CPU_BUDGET_PERCENT (10–100) and the
189
+ * existing FORGE_HOST_LOAD_CPU_BUDGET_FRACTION (0.05–1, the governor's own
190
+ * parse), reported as a percent.
191
+ */
192
+ function cpuBudgetCeilings(environment) {
193
+ const percent = numberEnv(environment, "FORGE_HOST_CPU_BUDGET_PERCENT", 10, 100);
194
+ const fraction = numberEnv(environment, "FORGE_HOST_LOAD_CPU_BUDGET_FRACTION", 0.05, 1);
195
+ return [
196
+ percent,
197
+ fraction ? { envVar: fraction.envVar, value: Math.round(fraction.value * 10_000) / 100 } : null,
198
+ ];
199
+ }
200
+ /** Matches the lease manager's parse (parseInt, clamped); an unparsable value counts as unset. */
201
+ function integerEnv(environment, envVar, minimum, maximum) {
202
+ const raw = environment[envVar];
203
+ if (raw === undefined || raw.trim() === "")
204
+ return null;
205
+ const parsed = Number.parseInt(raw, 10);
206
+ return Number.isFinite(parsed) ? { envVar, value: Math.max(minimum, Math.min(maximum, parsed)) } : null;
207
+ }
208
+ /** Matches the governor config's parse (Number, clamped); an unparsable value counts as unset. */
209
+ function numberEnv(environment, envVar, minimum, maximum) {
210
+ const raw = environment[envVar];
211
+ if (raw === undefined || raw.trim() === "")
212
+ return null;
213
+ const parsed = Number(raw);
214
+ return Number.isFinite(parsed) ? { envVar, value: Math.min(maximum, Math.max(minimum, parsed)) } : null;
215
+ }
216
+ /** The offer refusal message while the runner yields to foreground work. */
217
+ export function runnerYieldingMessage(report) {
218
+ const where = report.sources.yieldToForeground === "host_local" ? "on this host (forge-bridge yield on)" : "in Forge";
219
+ return `runner_yielding: this runner is yielding to foreground work (turned on ${where}); it takes no new attempts until yield is off. Running attempts continue.`;
220
+ }
221
+ /** One line describing the effective settings, for the bridge log. */
222
+ export function describeRunnerSettings(report) {
223
+ const { values } = report;
224
+ const parts = [
225
+ `max attempts ${values.maxConcurrentAttempts}`,
226
+ `CPU budget ${values.cpuBudgetPercent}%`,
227
+ `yield budget ${values.yieldCpuBudgetPercent}%`,
228
+ `memory reserve ${formatBytes(values.memoryReserveBytes)}`,
229
+ `heavy steps ${values.maxHeavySteps ?? "budget only"}`,
230
+ `yield ${values.yieldToForeground ? "on" : "off"}`,
231
+ ];
232
+ const capped = report.bounds
233
+ .filter(bound => report.sources[bound.key] === "host_env")
234
+ .map(bound => `${bound.envVar}=${bound.value}`);
235
+ return `${parts.join(", ")}${capped.length > 0 ? `; host bounds in force: ${[...new Set(capped)].join(", ")}` : ""}`;
236
+ }
@@ -0,0 +1,67 @@
1
+ export declare const runtimeIsolationLeaseStates: readonly ["reserved", "starting", "active", "releasing", "released", "degraded"];
2
+ export type RuntimeIsolationLeaseState = typeof runtimeIsolationLeaseStates[number];
3
+ export type RuntimeIsolationMode = "docker" | "host";
4
+ export interface RuntimeIsolationPort {
5
+ readonly name: string;
6
+ readonly protocol: "tcp" | "udp";
7
+ readonly hostIp: "127.0.0.1" | "::1";
8
+ readonly hostPort: number;
9
+ readonly targetPort: number;
10
+ }
11
+ export interface RuntimeIsolationPath {
12
+ readonly path: string;
13
+ readonly role: string;
14
+ }
15
+ export interface RuntimeIsolationDockerResource {
16
+ readonly type: "container" | "network" | "volume";
17
+ readonly name: string;
18
+ readonly role: string;
19
+ readonly id?: string | null;
20
+ }
21
+ export interface RuntimeIsolationResources {
22
+ readonly memoryReservationBytes: number;
23
+ readonly cpuMillis: number;
24
+ readonly pids: number;
25
+ readonly ports: readonly RuntimeIsolationPort[];
26
+ readonly paths: readonly RuntimeIsolationPath[];
27
+ readonly processSupervisorId: string | null;
28
+ readonly dockerResources: readonly RuntimeIsolationDockerResource[];
29
+ readonly singletonKeys: readonly string[];
30
+ }
31
+ export interface RuntimeIsolationLease {
32
+ readonly schemaVersion: 1;
33
+ readonly leaseId: string;
34
+ readonly dispatchAttemptId: string;
35
+ readonly executionLeaseId: string;
36
+ readonly fencingToken: string;
37
+ readonly runnerId: string;
38
+ readonly runnerInstanceId: string;
39
+ readonly worktreeKey: string;
40
+ readonly worktreePath: string;
41
+ readonly mode: RuntimeIsolationMode;
42
+ readonly state: RuntimeIsolationLeaseState;
43
+ readonly createdAt: string;
44
+ readonly stateChangedAt: string;
45
+ readonly expiresAt: string;
46
+ readonly releasedAt: string | null;
47
+ readonly resources: RuntimeIsolationResources;
48
+ }
49
+ export interface RuntimeIsolationLeaseInput {
50
+ readonly leaseId: string;
51
+ readonly dispatchAttemptId: string;
52
+ readonly executionLeaseId: string;
53
+ readonly fencingToken: string;
54
+ readonly runnerId: string;
55
+ readonly runnerInstanceId: string;
56
+ readonly worktreeKey: string;
57
+ readonly worktreePath: string;
58
+ readonly mode: RuntimeIsolationMode;
59
+ readonly expiresAt: string;
60
+ readonly resources: RuntimeIsolationResources;
61
+ readonly createdAt?: string;
62
+ }
63
+ export declare function createRuntimeIsolationLease(input: RuntimeIsolationLeaseInput): RuntimeIsolationLease;
64
+ export declare function transitionRuntimeIsolationLease(lease: RuntimeIsolationLease, nextState: RuntimeIsolationLeaseState, occurredAt?: string): RuntimeIsolationLease;
65
+ export declare function renewRuntimeIsolationLease(lease: RuntimeIsolationLease, fencingToken: string, expiresAt: string): RuntimeIsolationLease | null;
66
+ export declare function withRuntimeIsolationResources(lease: RuntimeIsolationLease, resources: RuntimeIsolationResources): RuntimeIsolationLease;
67
+ export declare function validRuntimeIsolationLease(value: unknown): value is RuntimeIsolationLease;
@@ -0,0 +1,161 @@
1
+ export const runtimeIsolationLeaseStates = [
2
+ "reserved",
3
+ "starting",
4
+ "active",
5
+ "releasing",
6
+ "released",
7
+ "degraded",
8
+ ];
9
+ const allowedTransitions = {
10
+ reserved: new Set(["starting", "releasing", "degraded"]),
11
+ starting: new Set(["active", "releasing", "degraded"]),
12
+ active: new Set(["releasing", "degraded"]),
13
+ releasing: new Set(["released", "degraded"]),
14
+ released: new Set(),
15
+ degraded: new Set(["releasing"]),
16
+ };
17
+ export function createRuntimeIsolationLease(input) {
18
+ const createdAt = input.createdAt ?? new Date().toISOString();
19
+ const lease = {
20
+ schemaVersion: 1,
21
+ leaseId: input.leaseId,
22
+ dispatchAttemptId: input.dispatchAttemptId,
23
+ executionLeaseId: input.executionLeaseId,
24
+ fencingToken: input.fencingToken,
25
+ runnerId: input.runnerId,
26
+ runnerInstanceId: input.runnerInstanceId,
27
+ worktreeKey: input.worktreeKey,
28
+ worktreePath: input.worktreePath,
29
+ mode: input.mode,
30
+ state: "reserved",
31
+ createdAt,
32
+ stateChangedAt: createdAt,
33
+ expiresAt: input.expiresAt,
34
+ releasedAt: null,
35
+ resources: input.resources,
36
+ };
37
+ if (!validRuntimeIsolationLease(lease)) {
38
+ throw new Error("runtime_lease_invalid: lease identity, lifetime, or resources are invalid.");
39
+ }
40
+ return lease;
41
+ }
42
+ export function transitionRuntimeIsolationLease(lease, nextState, occurredAt = new Date().toISOString()) {
43
+ if (lease.state === nextState)
44
+ return lease;
45
+ if (!allowedTransitions[lease.state].has(nextState) || !validTimestamp(occurredAt)) {
46
+ throw new Error(`runtime_lease_transition_invalid: cannot transition ${lease.state} to ${nextState}.`);
47
+ }
48
+ const transitioned = {
49
+ ...lease,
50
+ state: nextState,
51
+ stateChangedAt: occurredAt,
52
+ releasedAt: nextState === "released" ? occurredAt : null,
53
+ };
54
+ if (!validRuntimeIsolationLease(transitioned)) {
55
+ throw new Error("runtime_lease_invalid: transitioned lease is invalid.");
56
+ }
57
+ return transitioned;
58
+ }
59
+ export function renewRuntimeIsolationLease(lease, fencingToken, expiresAt) {
60
+ if (lease.fencingToken !== fencingToken
61
+ || lease.state === "releasing"
62
+ || lease.state === "released"
63
+ || !validTimestamp(expiresAt))
64
+ return null;
65
+ const renewed = { ...lease, expiresAt };
66
+ return validRuntimeIsolationLease(renewed) ? renewed : null;
67
+ }
68
+ export function withRuntimeIsolationResources(lease, resources) {
69
+ if (lease.state === "released") {
70
+ throw new Error("runtime_lease_transition_invalid: released leases cannot acquire resources.");
71
+ }
72
+ const updated = { ...lease, resources };
73
+ if (!validRuntimeIsolationLease(updated)) {
74
+ throw new Error("runtime_lease_invalid: resources are invalid.");
75
+ }
76
+ return updated;
77
+ }
78
+ export function validRuntimeIsolationLease(value) {
79
+ if (!isRecord(value)
80
+ || value.schemaVersion !== 1
81
+ || !isUuid(value.leaseId)
82
+ || !isUuid(value.dispatchAttemptId)
83
+ || !isUuid(value.executionLeaseId)
84
+ || !isUuid(value.fencingToken)
85
+ || !isUuid(value.runnerId)
86
+ || !isUuid(value.runnerInstanceId)
87
+ || !boundedText(value.worktreeKey, 255)
88
+ || !boundedText(value.worktreePath, 4096)
89
+ || (value.mode !== "docker" && value.mode !== "host")
90
+ || !runtimeIsolationLeaseStates.includes(value.state)
91
+ || !validTimestamp(value.createdAt)
92
+ || !validTimestamp(value.stateChangedAt)
93
+ || !validTimestamp(value.expiresAt)
94
+ || Date.parse(value.stateChangedAt) < Date.parse(value.createdAt)
95
+ || Date.parse(value.expiresAt) < Date.parse(value.createdAt)
96
+ || (value.state === "released") !== validTimestamp(value.releasedAt)) {
97
+ return false;
98
+ }
99
+ if (value.releasedAt !== null && Date.parse(value.releasedAt) < Date.parse(value.createdAt))
100
+ return false;
101
+ return validResources(value.resources, value.mode);
102
+ }
103
+ function validResources(value, mode) {
104
+ if (!isRecord(value)
105
+ || !nonNegativeInteger(value.memoryReservationBytes)
106
+ || !nonNegativeInteger(value.cpuMillis)
107
+ || !nonNegativeInteger(value.pids)
108
+ || !Array.isArray(value.ports) || value.ports.length > 64
109
+ || !Array.isArray(value.paths) || value.paths.length > 64
110
+ || !Array.isArray(value.dockerResources) || value.dockerResources.length > 128
111
+ || !Array.isArray(value.singletonKeys) || value.singletonKeys.length > 64
112
+ || (value.processSupervisorId !== null && !boundedText(value.processSupervisorId, 255))) {
113
+ return false;
114
+ }
115
+ if (value.ports.some(port => !validPort(port))
116
+ || value.paths.some(entry => !isRecord(entry) || !boundedText(entry.path, 4096) || !boundedText(entry.role, 128))
117
+ || value.singletonKeys.some(key => !boundedText(key, 255))
118
+ || value.dockerResources.some(resource => !validDockerResource(resource))) {
119
+ return false;
120
+ }
121
+ return mode === "docker" || value.dockerResources.length === 0;
122
+ }
123
+ function validPort(value) {
124
+ return isRecord(value)
125
+ && boundedText(value.name, 128)
126
+ && (value.protocol === "tcp" || value.protocol === "udp")
127
+ && (value.hostIp === "127.0.0.1" || value.hostIp === "::1")
128
+ && validPortNumber(value.hostPort)
129
+ && validPortNumber(value.targetPort);
130
+ }
131
+ function validDockerResource(value) {
132
+ return isRecord(value)
133
+ && (value.type === "container" || value.type === "network" || value.type === "volume")
134
+ && boundedText(value.name, 255)
135
+ && boundedText(value.role, 128)
136
+ && (value.id === undefined || value.id === null || boundedText(value.id, 255));
137
+ }
138
+ function validPortNumber(value) {
139
+ return Number.isSafeInteger(value) && Number(value) >= 1 && Number(value) <= 65535;
140
+ }
141
+ function nonNegativeInteger(value) {
142
+ return Number.isSafeInteger(value) && Number(value) >= 0;
143
+ }
144
+ function validTimestamp(value) {
145
+ return typeof value === "string" && Number.isFinite(Date.parse(value));
146
+ }
147
+ function boundedText(value, maximumLength) {
148
+ return typeof value === "string"
149
+ && value.length > 0
150
+ && value.length <= maximumLength
151
+ && Array.from(value).every((character) => {
152
+ const codePoint = character.codePointAt(0) ?? 0;
153
+ return codePoint > 31 && codePoint !== 127;
154
+ });
155
+ }
156
+ function isUuid(value) {
157
+ return typeof value === "string" && /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/iu.test(value);
158
+ }
159
+ function isRecord(value) {
160
+ return typeof value === "object" && value !== null && !Array.isArray(value);
161
+ }
@@ -0,0 +1,17 @@
1
+ export declare const minimumWorkspaceEstimateBytes: number;
2
+ export declare const architectMinimumWorkspaceEstimateBytes: number;
3
+ export interface RepositoryWorkspaceFootprint {
4
+ readonly sourceBytes: number;
5
+ readonly hasNode: boolean;
6
+ readonly hasDotNet: boolean;
7
+ readonly hasBrowser: boolean;
8
+ readonly serviceCount: number;
9
+ }
10
+ export interface WorkspaceEstimateHints {
11
+ readonly role?: string | null;
12
+ readonly serviceCount?: number;
13
+ readonly browser?: boolean;
14
+ }
15
+ export declare function estimateWorkspaceBytesFromRepo(repoPath: string, hints?: WorkspaceEstimateHints): Promise<number>;
16
+ export declare function calculateWorkspaceBytes(footprint: RepositoryWorkspaceFootprint, role?: string | null): number;
17
+ export declare function measureRepositoryWorkspace(repoPath: string): Promise<RepositoryWorkspaceFootprint>;
@@ -0,0 +1,174 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import readline from "node:readline";
5
+ const GiB = 1024 ** 3;
6
+ const alignmentBytes = 512 * 1024 ** 2;
7
+ export const minimumWorkspaceEstimateBytes = 2 * GiB;
8
+ export const architectMinimumWorkspaceEstimateBytes = GiB;
9
+ const maximumBytes = 100 * GiB;
10
+ const footprintCacheLifetimeMs = 5 * 60_000;
11
+ const excludedDirectories = new Set([
12
+ ".git",
13
+ ".artifacts",
14
+ ".forge-worktrees",
15
+ ".local",
16
+ ".next",
17
+ ".nuget",
18
+ ".pnpm-store",
19
+ ".tmp",
20
+ ".turbo",
21
+ "artifacts",
22
+ "bin",
23
+ "build",
24
+ "coverage",
25
+ "dist",
26
+ "node_modules",
27
+ "obj",
28
+ "testresults",
29
+ ]);
30
+ const footprintCache = new Map();
31
+ export async function estimateWorkspaceBytesFromRepo(repoPath, hints = {}) {
32
+ const cacheKey = path.resolve(repoPath);
33
+ const cached = footprintCache.get(cacheKey);
34
+ const footprint = cached && Date.now() - cached.measuredAt < footprintCacheLifetimeMs
35
+ ? cached.footprint
36
+ : await measureRepositoryWorkspace(cacheKey);
37
+ if (!cached || cached.footprint !== footprint) {
38
+ footprintCache.set(cacheKey, { measuredAt: Date.now(), footprint });
39
+ }
40
+ return calculateWorkspaceBytes({
41
+ ...footprint,
42
+ hasBrowser: footprint.hasBrowser || hints.browser === true,
43
+ serviceCount: Math.max(footprint.serviceCount, Math.max(0, hints.serviceCount ?? 0)),
44
+ }, hints.role);
45
+ }
46
+ export function calculateWorkspaceBytes(footprint, role) {
47
+ const normalizedRole = role?.trim().toLowerCase() ?? "";
48
+ if (normalizedRole === "architect") {
49
+ // Architect owns a checkout and planning artifacts, not dependencies,
50
+ // build outputs, browser state, services, or application runtime output.
51
+ const estimate = architectMinimumWorkspaceEstimateBytes
52
+ + Math.max(0, footprint.sourceBytes) * 2;
53
+ return Math.min(maximumBytes, Math.max(architectMinimumWorkspaceEstimateBytes, alignUp(estimate, alignmentBytes)));
54
+ }
55
+ let estimate = 2 * GiB + Math.max(0, footprint.sourceBytes) * 3;
56
+ if (footprint.hasNode)
57
+ estimate += 3 * GiB;
58
+ if (footprint.hasDotNet)
59
+ estimate += 2 * GiB;
60
+ if (footprint.hasBrowser)
61
+ estimate += 1536 * 1024 ** 2;
62
+ estimate += Math.max(0, footprint.serviceCount) * GiB;
63
+ if (["qa", "ci_repair", "pr_fix"].includes(normalizedRole)) {
64
+ estimate += GiB;
65
+ }
66
+ return Math.min(maximumBytes, Math.max(minimumWorkspaceEstimateBytes, alignUp(estimate, alignmentBytes)));
67
+ }
68
+ export async function measureRepositoryWorkspace(repoPath) {
69
+ return await measureGitWorkspace(repoPath) ?? await measureFilesystemFallback(repoPath);
70
+ }
71
+ async function measureGitWorkspace(repoPath) {
72
+ let sourceBytes = 0;
73
+ let hasNode = false;
74
+ let hasDotNet = false;
75
+ let hasBrowser = false;
76
+ let serviceCount = 0;
77
+ const child = spawn("git", ["-c", "core.quotepath=false", "ls-files", "--cached", "--others", "--exclude-standard"], {
78
+ cwd: repoPath,
79
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
80
+ stdio: ["ignore", "pipe", "ignore"],
81
+ windowsHide: true,
82
+ });
83
+ const closed = new Promise((resolve) => {
84
+ child.once("close", resolve);
85
+ child.once("error", () => resolve(null));
86
+ });
87
+ try {
88
+ const lines = readline.createInterface({ input: child.stdout, crlfDelay: Infinity });
89
+ for await (const relativePath of lines) {
90
+ if (!relativePath.trim())
91
+ continue;
92
+ const file = await inspectWorkspaceFile(path.join(repoPath, relativePath));
93
+ if (!file)
94
+ continue;
95
+ sourceBytes += file.bytes;
96
+ hasNode ||= file.hasNode;
97
+ hasDotNet ||= file.hasDotNet;
98
+ hasBrowser ||= file.hasBrowser;
99
+ serviceCount = Math.max(serviceCount, file.serviceCount);
100
+ }
101
+ return await closed === 0 ? { sourceBytes, hasNode, hasDotNet, hasBrowser, serviceCount } : null;
102
+ }
103
+ catch {
104
+ child.kill();
105
+ await closed;
106
+ return null;
107
+ }
108
+ }
109
+ async function measureFilesystemFallback(repoPath) {
110
+ let sourceBytes = 0;
111
+ let hasNode = false;
112
+ let hasDotNet = false;
113
+ let hasBrowser = false;
114
+ let serviceCount = 0;
115
+ const pending = [path.resolve(repoPath)];
116
+ while (pending.length > 0) {
117
+ const current = pending.pop();
118
+ const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => []);
119
+ for (const entry of entries) {
120
+ const entryPath = path.join(current, entry.name);
121
+ if (entry.isDirectory()) {
122
+ if (!excludedDirectories.has(entry.name.toLowerCase()))
123
+ pending.push(entryPath);
124
+ continue;
125
+ }
126
+ if (!entry.isFile())
127
+ continue;
128
+ const file = await inspectWorkspaceFile(entryPath);
129
+ if (!file)
130
+ continue;
131
+ sourceBytes += file.bytes;
132
+ hasNode ||= file.hasNode;
133
+ hasDotNet ||= file.hasDotNet;
134
+ hasBrowser ||= file.hasBrowser;
135
+ serviceCount = Math.max(serviceCount, file.serviceCount);
136
+ }
137
+ }
138
+ return { sourceBytes, hasNode, hasDotNet, hasBrowser, serviceCount };
139
+ }
140
+ async function inspectWorkspaceFile(filePath) {
141
+ const stat = await fs.stat(filePath).catch(() => null);
142
+ if (!stat?.isFile())
143
+ return null;
144
+ const name = path.basename(filePath).toLowerCase();
145
+ const sandbox = name === "forge.sandbox.yml" || name === "forge.sandbox.yaml";
146
+ return {
147
+ bytes: stat.size,
148
+ hasNode: ["package.json", "pnpm-lock.yaml", "package-lock.json", "yarn.lock"].includes(name),
149
+ hasDotNet: name.endsWith(".sln") || name.endsWith(".csproj") || name.endsWith(".fsproj"),
150
+ hasBrowser: name.startsWith("playwright.config"),
151
+ serviceCount: sandbox
152
+ ? countSandboxServices(await fs.readFile(filePath, "utf8").catch(() => ""))
153
+ : 0,
154
+ };
155
+ }
156
+ function countSandboxServices(yaml) {
157
+ let inServices = false;
158
+ let count = 0;
159
+ for (const rawLine of yaml.split(/\r?\n/gu)) {
160
+ const line = rawLine.trim();
161
+ if (!line || line.startsWith("#"))
162
+ continue;
163
+ if (!/^\s/u.test(rawLine)) {
164
+ inServices = line.toLowerCase() === "services:";
165
+ continue;
166
+ }
167
+ if (inServices && line.startsWith("-"))
168
+ count += 1;
169
+ }
170
+ return count;
171
+ }
172
+ function alignUp(value, alignment) {
173
+ return Math.ceil(value / alignment) * alignment;
174
+ }
@@ -0,0 +1,4 @@
1
+ import type { CommandOptions, CommandResult, CommandRunner } from "./sandbox.types.js";
2
+ export declare class BoundedCommandRunner implements CommandRunner {
3
+ run(command: string, args: readonly string[], options?: CommandOptions): Promise<CommandResult>;
4
+ }