@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,596 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { readCanonicalSourceFile } from "./canonical-source-file.js";
5
+ import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
6
+ import { replaceFile } from "../shared/fs/replace-file.js";
7
+ import { ExactHostProcessRecovery } from "../shared/process/host-process-recovery.js";
8
+ import { captureHostProcessIdentity, } from "../shared/process/host-process-supervisor.js";
9
+ import { monotonicNowMs } from "../shared/time/monotonic.js";
10
+ const terminalStatuses = new Set(["pass", "fail", "timed_out", "timeout_termination_failed", "runner_error"]);
11
+ const commandIdPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
12
+ const managedCommandFilePattern = /^([0-9a-f-]{36})(?:\.receipt)?\.json$/u;
13
+ const maximumMetadataBytes = 64 * 1024;
14
+ const maximumReceiptBytes = 16 * 1024 * 1024;
15
+ const maximumCapturedCharacters = 200_000;
16
+ const defaultGraceMs = 2_000;
17
+ const receiptReadAttempts = 5;
18
+ const receiptReadRetryMs = 25;
19
+ const invalidMetadata = Symbol("invalid managed-command metadata");
20
+ let procRoot = "/proc";
21
+ /** Test support: points the Linux process inventory at another directory (null restores /proc). */
22
+ export function setManagedCommandProcRootForTesting(root) {
23
+ procRoot = root ?? "/proc";
24
+ }
25
+ /**
26
+ * Stops managed commands that an attempt's MCP servers started and proves their process
27
+ * trees are gone. Managed commands run in their own process group (Unix) or Job Object
28
+ * (Windows), outside the provider tree that the attempt supervisor stops, so stopping the
29
+ * provider alone leaves them running. Each command's durable receipt is given a terminal
30
+ * status when its owner can no longer write one.
31
+ *
32
+ * Every signal is fenced: the recorded root must still carry the recorded birth identity
33
+ * and, on Linux, this command's supervisor and attempt identity in its environment. A
34
+ * tree that cannot be proven to be the command's own fails the teardown instead of being
35
+ * reported stopped.
36
+ */
37
+ export async function terminateAttemptManagedCommands(scope, options) {
38
+ const store = await recordStore(scope);
39
+ const names = await store.list();
40
+ if (!names)
41
+ return [];
42
+ const commandIds = new Set();
43
+ for (const name of names) {
44
+ const commandId = managedCommandFilePattern.exec(name)?.[1];
45
+ if (commandId && commandIdPattern.test(commandId))
46
+ commandIds.add(commandId);
47
+ }
48
+ const outcomes = [];
49
+ const failures = [];
50
+ for (const commandId of [...commandIds].sort()) {
51
+ try {
52
+ outcomes.push(await teardownManagedCommand(store, commandId, scope, options));
53
+ }
54
+ catch (error) {
55
+ failures.push(error);
56
+ }
57
+ }
58
+ if (failures.length > 0) {
59
+ throw new AggregateError(failures, `managed_command_teardown_failed: ${failures.map(failure => failure instanceof Error ? failure.message : String(failure)).join("; ")}`);
60
+ }
61
+ return outcomes;
62
+ }
63
+ async function teardownManagedCommand(store, commandId, scope, options, ownerWaited = false) {
64
+ const platform = options.platform ?? process.platform;
65
+ const graceMs = options.graceMs ?? defaultGraceMs;
66
+ const receiptName = `${commandId}.receipt.json`;
67
+ const receipt = await readReceipt(store, receiptName);
68
+ const receiptTerminal = receipt !== null && terminalStatuses.has(String(receipt.status));
69
+ const metadata = await readMetadata(store, commandId, scope);
70
+ if (metadata === invalidMetadata) {
71
+ // An unreadable, partial, or foreign record for a command that has finished (or never
72
+ // wrote a receipt) leaves nothing to stop. One that claims a running command does: its
73
+ // tree cannot be identified, so the teardown fails closed.
74
+ if (receipt === null || receiptTerminal) {
75
+ return { commandId, outcome: "absent", receiptFinalized: false };
76
+ }
77
+ throw new Error(`managed_command_teardown_unverifiable: ownership metadata for ${commandId} is unreadable or does not belong to this attempt while its receipt is ${String(receipt.status)}.`);
78
+ }
79
+ // Receipt first. The owner writes pass, fail, timed_out, or a runner_error only after
80
+ // its runner proved the command's tree stopped, so such a command is never signalled,
81
+ // even while its root is still finishing its own exit. Only a terminal receipt that says
82
+ // its tree was not proven stopped (a failed timeout termination, or
83
+ // process_tree_terminated: false) still needs the recorded tree stopped.
84
+ if (receipt !== null && receiptTerminal && !terminalReceiptLeavesTree(receipt)) {
85
+ return { commandId, outcome: "already_terminal", receiptFinalized: false };
86
+ }
87
+ const owner = processOwner(receipt, metadata);
88
+ if (options.onlyOrphaned && (owner === null || ownerAlive(owner, platform))) {
89
+ // Without a recorded owner the command cannot be proven orphaned; attempt teardown stops it.
90
+ return { commandId, outcome: "owner_alive", receiptFinalized: false };
91
+ }
92
+ let outcome;
93
+ if (metadata) {
94
+ await assertNotBridgeProcess(metadata.rootPid, platform);
95
+ outcome = platform === "win32"
96
+ ? await terminateWindowsManagedCommand(metadata, graceMs)
97
+ : await terminateUnixManagedProcessGroup(metadata, scope, graceMs, platform);
98
+ }
99
+ else {
100
+ if (receipt === null || receiptTerminal) {
101
+ return { commandId, outcome: receiptTerminal ? "already_terminal" : "absent", receiptFinalized: false };
102
+ }
103
+ // Queued, or launching: no process is recorded yet. A live owner could still launch
104
+ // it after Forge finalized its receipt, so give a shutting-down owner time to stop (or
105
+ // to record the process), and refuse to report the command stopped otherwise.
106
+ if (owner && ownerAlive(owner, platform)) {
107
+ if (!ownerWaited) {
108
+ await waitUntil(() => !ownerAlive(owner, platform), graceMs);
109
+ return await teardownManagedCommand(store, commandId, scope, options, true);
110
+ }
111
+ throw new Error(`managed_command_teardown_unverifiable: managed command ${commandId} has no recorded process and its owner ${owner.pid} is still alive and could launch it.`);
112
+ }
113
+ // The runner spawns the command before its spawn handler records it, so an owner that
114
+ // died in between leaves an unrecorded process. The owner marks the receipt before it
115
+ // spawns; only a command it never started to launch is safe without a process search.
116
+ outcome = receipt.launch_requested === false
117
+ ? "no_process_record"
118
+ : await stopUnrecordedLaunch(commandId, scope, graceMs, platform);
119
+ }
120
+ // The owner may have written its own terminal receipt while its process stopped. A
121
+ // terminal receipt that did not prove its tree stopped keeps its result.
122
+ const current = await readReceipt(store, receiptName) ?? receipt;
123
+ if (current && terminalStatuses.has(String(current.status))) {
124
+ return { commandId, outcome: outcome === "absent" ? "already_terminal" : outcome, receiptFinalized: false };
125
+ }
126
+ await persistReceipt(path.join(store.directory, receiptName), terminalReceipt(commandId, current, options.reason, outcome));
127
+ return { commandId, outcome, receiptFinalized: true };
128
+ }
129
+ function terminalReceiptLeavesTree(receipt) {
130
+ return receipt.status === "timeout_termination_failed" || receipt.process_tree_terminated === false;
131
+ }
132
+ async function terminateWindowsManagedCommand(metadata, graceMs) {
133
+ const outcome = await new ExactHostProcessRecovery("win32", graceMs).recover(metadata);
134
+ if (outcome === "unverifiable") {
135
+ throw new Error(`managed_command_teardown_unverifiable: managed command root ${metadata.rootPid} is alive but its identity cannot be verified.`);
136
+ }
137
+ return outcome;
138
+ }
139
+ async function terminateUnixManagedProcessGroup(metadata, scope, graceMs, platform) {
140
+ const processGroupId = metadata.rootPid;
141
+ if (platform !== "linux") {
142
+ // Other Unix platforms expose no process birth identity or group inventory that Forge
143
+ // can verify, and the bridge's own process group cannot be ruled out. Forge never
144
+ // signals there: a tree that may still be running fails the teardown.
145
+ if (!processExists(processGroupId) && !processGroupExists(processGroupId))
146
+ return "absent";
147
+ throw new Error(`managed_command_teardown_unverifiable: Forge can prove managed command process trees only on Linux and Windows; ${platform} process group ${processGroupId} may still be running.`);
148
+ }
149
+ const initial = await verifyLinuxTree(metadata, scope);
150
+ if (initial === "gone")
151
+ return "absent";
152
+ if (initial === "pid_reused")
153
+ return "pid_reused";
154
+ signalProcessGroup(processGroupId, "SIGTERM");
155
+ await waitForProcessGroupExit(processGroupId, graceMs);
156
+ // Members can exit and their PIDs be reissued during the grace period. Re-prove that
157
+ // the group is still this command's before escalating.
158
+ if (processGroupExists(processGroupId) && await verifyLinuxTree(metadata, scope) === "ours") {
159
+ signalProcessGroup(processGroupId, "SIGKILL");
160
+ await waitForProcessGroupExit(processGroupId, graceMs);
161
+ }
162
+ if (processGroupExists(processGroupId)) {
163
+ // An exited member stays in its group until its parent reaps it; it no longer runs.
164
+ const members = await linuxProcessGroupMembers(processGroupId);
165
+ if (members === null || members.some(member => !member.zombie)) {
166
+ throw new Error(`managed_command_teardown_failed: managed command process group ${processGroupId} did not stop${members === null ? ", or its members could not be listed" : ""}.`);
167
+ }
168
+ }
169
+ return "terminated";
170
+ }
171
+ /**
172
+ * Proves whether the recorded group is this command's tree. Every claim rests on a birth
173
+ * identity, a complete /proc inventory of the group, and this command's identity markers
174
+ * in a member's environment; anything less is unverifiable and the caller fails closed.
175
+ */
176
+ async function verifyLinuxTree(metadata, scope) {
177
+ const processGroupId = metadata.rootPid;
178
+ const markers = identityMarkers(metadata, scope);
179
+ if (processExists(processGroupId) && !await linuxProcessIsZombie(processGroupId)) {
180
+ const identity = captureHostProcessIdentity(processGroupId, "linux");
181
+ if (!metadata.rootIdentity || !identity) {
182
+ throw new Error(`managed_command_teardown_unverifiable: managed command root ${processGroupId} is alive but its identity cannot be verified.`);
183
+ }
184
+ if (identity !== metadata.rootIdentity) {
185
+ // POSIX does not reissue a PID that is still a process-group ID, so the recorded
186
+ // group should be empty. Check rather than assume: a member carrying this command's
187
+ // identity contradicts that and fails closed.
188
+ if (await linuxProcessGroupHasMarkedMember(processGroupId, markers)) {
189
+ throw new Error(`managed_command_teardown_unverifiable: managed command root ${processGroupId} was reissued while members of its former group may still be running.`);
190
+ }
191
+ return "pid_reused";
192
+ }
193
+ if (!await linuxProcessCarriesMarkers(processGroupId, markers)) {
194
+ throw new Error(`managed_command_teardown_unverifiable: process ${processGroupId} does not carry managed command ${metadata.supervisorId}'s attempt identity.`);
195
+ }
196
+ return "ours";
197
+ }
198
+ if (!processGroupExists(processGroupId))
199
+ return "gone";
200
+ // The leader exited but members remain in its group. Only a running member that still
201
+ // carries this command's identity proves the group is the command's own.
202
+ const members = await linuxProcessGroupMembers(processGroupId);
203
+ if (members !== null) {
204
+ const running = members.filter(member => !member.zombie);
205
+ if (running.length === 0)
206
+ return "gone";
207
+ for (const member of running) {
208
+ if (await linuxProcessCarriesMarkers(member.pid, markers))
209
+ return "ours";
210
+ }
211
+ }
212
+ throw new Error(`managed_command_teardown_unverifiable: managed command root ${processGroupId} exited but its process group is still alive and cannot be proven to be the command's own${members === null ? " (its members could not be listed)" : ""}.`);
213
+ }
214
+ async function linuxProcessGroupHasMarkedMember(processGroupId, markers) {
215
+ const members = await linuxProcessGroupMembers(processGroupId);
216
+ if (members === null) {
217
+ throw new Error(`managed_command_teardown_unverifiable: the members of process group ${processGroupId} could not be listed.`);
218
+ }
219
+ for (const member of members) {
220
+ if (!member.zombie && await linuxProcessCarriesMarkers(member.pid, markers))
221
+ return true;
222
+ }
223
+ return false;
224
+ }
225
+ /**
226
+ * Handles a command whose launch was requested but never recorded. On Linux it stops every
227
+ * process that still carries the command's supervisor and attempt identity, but that is
228
+ * never proof the whole tree is gone: a descendant can drop those markers from its
229
+ * environment or start its own session. Without a recorded root and group to verify, the
230
+ * teardown always fails closed and the lease stays degraded for an operator.
231
+ */
232
+ async function stopUnrecordedLaunch(commandId, scope, graceMs, platform) {
233
+ const unverifiable = `managed_command_teardown_unverifiable: managed command ${commandId} may have been launched without a process record, so Forge cannot prove its process tree stopped`;
234
+ if (platform !== "linux")
235
+ throw new Error(`${unverifiable}.`);
236
+ const markers = [
237
+ `FORGE_PROCESS_SUPERVISOR_ID=managed-${commandId.replaceAll("-", "")}`,
238
+ `FORGE_DISPATCH_ATTEMPT_ID=${scope.dispatchAttemptId}`,
239
+ ];
240
+ const ownPid = process.pid;
241
+ const find = async () => {
242
+ const found = await linuxProcessesCarryingMarkers(markers);
243
+ if (found === null) {
244
+ throw new Error(`${unverifiable}, and the process inventory could not be read to stop what it can find.`);
245
+ }
246
+ return found.filter(candidate => candidate.pid !== ownPid);
247
+ };
248
+ let found = await find();
249
+ for (const signal of ["SIGTERM", "SIGKILL"]) {
250
+ if (found.length === 0)
251
+ break;
252
+ for (const candidate of found) {
253
+ // Re-check the birth identity so a reissued PID is never signalled.
254
+ if (captureHostProcessIdentity(candidate.pid, "linux") !== candidate.identity)
255
+ continue;
256
+ try {
257
+ process.kill(candidate.pid, signal);
258
+ }
259
+ catch (error) {
260
+ if (error.code !== "ESRCH")
261
+ throw error;
262
+ }
263
+ }
264
+ const deadline = monotonicNowMs() + graceMs;
265
+ do {
266
+ await delay(25);
267
+ found = await find();
268
+ } while (found.length > 0 && monotonicNowMs() < deadline);
269
+ }
270
+ throw new Error(found.length === 0
271
+ ? `${unverifiable}; it stopped every process still carrying the command's identity.`
272
+ : `${unverifiable}, and its marked processes did not stop: ${found.map(candidate => candidate.pid).join(", ")}.`);
273
+ }
274
+ function identityMarkers(metadata, scope) {
275
+ return [
276
+ `FORGE_PROCESS_SUPERVISOR_ID=${metadata.supervisorId}`,
277
+ `FORGE_DISPATCH_ATTEMPT_ID=${scope.dispatchAttemptId}`,
278
+ ];
279
+ }
280
+ /** Every platform refuses the bridge's own PID; Linux, the only Unix that signals, also its group. */
281
+ async function assertNotBridgeProcess(processGroupId, platform) {
282
+ if (processGroupId === process.pid
283
+ || (platform === "linux" && processGroupId === await linuxProcessGroupOf("self"))) {
284
+ throw new Error(`managed_command_teardown_invalid: managed command root ${processGroupId} names the bridge's own process or process group.`);
285
+ }
286
+ }
287
+ function terminalReceipt(commandId, receipt, reason, outcome) {
288
+ const now = Date.now();
289
+ const startedAt = Date.parse(String(receipt?.started_at ?? ""));
290
+ const message = reason === "owner_exited"
291
+ ? `managed_command_owner_exited: Forge stopped managed command ${commandId} because the provider process that started it exited before the command finished. Its result is unknown; start it again if it is still needed.`
292
+ : `managed_command_attempt_teardown: Forge stopped managed command ${commandId} because its dispatch attempt ended before the command finished.`;
293
+ const priorStderr = typeof receipt?.stderr === "string" ? receipt.stderr : "";
294
+ const stderr = `${priorStderr}${message}\n`;
295
+ const outputRevision = typeof receipt?.output_revision === "number" ? receipt.output_revision : 0;
296
+ return {
297
+ ...(receipt ?? {}),
298
+ command_id: commandId,
299
+ status: "runner_error",
300
+ timed_out: false,
301
+ exit_code: null,
302
+ elapsed_ms: Number.isFinite(startedAt)
303
+ ? Math.max(0, now - startedAt)
304
+ : typeof receipt?.elapsed_ms === "number" ? receipt.elapsed_ms : null,
305
+ stdout: typeof receipt?.stdout === "string" ? receipt.stdout : "",
306
+ stderr: stderr.length <= maximumCapturedCharacters ? stderr : stderr.slice(-maximumCapturedCharacters),
307
+ output_revision: outputRevision + 1,
308
+ last_output_at: new Date(now).toISOString(),
309
+ last_output_stream: "stderr",
310
+ // Proof comes only from the recorded process tree. A command with no recorded process
311
+ // may still have been spawned in its last moments, so nothing is claimed for it.
312
+ process_tree_terminated: outcome === "terminated" || outcome === "absent" || outcome === "pid_reused",
313
+ process_tree_outcome: outcome,
314
+ termination_reason: reason,
315
+ terminated_by: "forge_bridge",
316
+ terminated_at: new Date(now).toISOString(),
317
+ };
318
+ }
319
+ function processOwner(receipt, metadata) {
320
+ if (typeof receipt?.owner_pid === "number" && Number.isSafeInteger(receipt.owner_pid) && receipt.owner_pid > 0) {
321
+ return {
322
+ pid: receipt.owner_pid,
323
+ identity: typeof receipt.owner_identity === "string" ? receipt.owner_identity : null,
324
+ };
325
+ }
326
+ return metadata ? { pid: metadata.bridgePid, identity: null } : null;
327
+ }
328
+ function ownerAlive(owner, platform) {
329
+ if (!processExists(owner.pid))
330
+ return false;
331
+ // A recorded birth identity tells a reissued PID from the owner itself.
332
+ return owner.identity === null || captureHostProcessIdentity(owner.pid, platform) === owner.identity;
333
+ }
334
+ async function readMetadata(store, commandId, scope) {
335
+ let bytes;
336
+ try {
337
+ bytes = await store.read(`${commandId}.json`, maximumMetadataBytes);
338
+ }
339
+ catch {
340
+ return invalidMetadata;
341
+ }
342
+ if (bytes === null)
343
+ return null;
344
+ try {
345
+ const value = JSON.parse(bytes.toString("utf8"));
346
+ return validManagedCommandMetadata(value, commandId, scope) ? value : invalidMetadata;
347
+ }
348
+ catch {
349
+ return invalidMetadata;
350
+ }
351
+ }
352
+ async function readReceipt(store, name) {
353
+ // The owner replaces its receipt atomically while it runs; a read can observe a swap.
354
+ for (let attempt = 1; attempt <= receiptReadAttempts; attempt += 1) {
355
+ try {
356
+ const bytes = await store.read(name, maximumReceiptBytes);
357
+ if (bytes === null)
358
+ return null;
359
+ const value = JSON.parse(bytes.toString("utf8"));
360
+ return typeof value === "object" && value !== null && !Array.isArray(value)
361
+ ? value
362
+ : null;
363
+ }
364
+ catch {
365
+ if (attempt < receiptReadAttempts)
366
+ await delay(receiptReadRetryMs);
367
+ }
368
+ }
369
+ return null;
370
+ }
371
+ function validManagedCommandMetadata(value, commandId, scope) {
372
+ if (typeof value !== "object" || value === null)
373
+ return false;
374
+ const metadata = value;
375
+ return metadata.schemaVersion === 1
376
+ && metadata.supervisorId === `managed-${commandId.replaceAll("-", "")}`
377
+ && (metadata.strategy === "windows_job_object" || metadata.strategy === "unix_process_group")
378
+ && Number.isSafeInteger(metadata.rootPid)
379
+ && metadata.rootPid > 1
380
+ && (metadata.rootIdentity == null
381
+ || (typeof metadata.rootIdentity === "string" && metadata.rootIdentity.length <= 256))
382
+ && metadata.dispatchAttemptId === scope.dispatchAttemptId
383
+ && metadata.runtimeLeaseId === scope.runtimeLeaseId
384
+ && Number.isSafeInteger(metadata.bridgePid)
385
+ && metadata.bridgePid > 0;
386
+ }
387
+ async function recordStore(scope) {
388
+ // The attempt's log root holds every managed command's ownership record and is created
389
+ // with the attempt (the supervisor's ledger lives there too). If it is gone, the records
390
+ // that would show a running command are gone with it, so that is not an empty store.
391
+ const logDirectory = await fs.realpath(scope.logDirectory).catch((error) => {
392
+ throw new Error(`managed_command_teardown_unverifiable: the attempt log directory ${scope.logDirectory} is unavailable (${error.code ?? String(error)}), so its managed commands cannot be accounted for.`, { cause: error });
393
+ });
394
+ const directory = path.join(logDirectory, "managed-commands");
395
+ const readFile = async (name, maximumBytes, identity) => {
396
+ try {
397
+ return await readCanonicalSourceFile(path.join(directory, name), maximumBytes, identity);
398
+ }
399
+ catch (error) {
400
+ if (error.code === "ENOENT")
401
+ return null;
402
+ throw error;
403
+ }
404
+ };
405
+ if (scope.pinnedLogDirectory) {
406
+ const pinnedLogs = scope.pinnedLogDirectory;
407
+ let identities;
408
+ const pinnedEntries = async () => {
409
+ if (identities !== undefined)
410
+ return identities;
411
+ const logs = await readPinnedSourceDirectory(logDirectory, pinnedLogs);
412
+ const entry = logs.find(candidate => candidate.name === "managed-commands");
413
+ if (!entry)
414
+ return identities = null;
415
+ if (entry.kind !== "directory") {
416
+ throw new Error("managed_command_teardown_invalid: the managed-command ownership path is not an ordinary directory.");
417
+ }
418
+ const files = await readPinnedSourceDirectory(directory, entry.identity);
419
+ return identities = new Map(files.filter(file => file.kind === "file").map(file => [file.name, file.identity]));
420
+ };
421
+ return {
422
+ directory,
423
+ list: async () => {
424
+ const entries = await pinnedEntries();
425
+ return entries ? [...entries.keys()] : null;
426
+ },
427
+ read: async (name, maximumBytes) => {
428
+ const identity = (await pinnedEntries())?.get(name);
429
+ // A receipt the owner replaced after enumeration has a new identity; read it fresh.
430
+ if (!identity)
431
+ return await readFile(name, maximumBytes);
432
+ try {
433
+ return await readFile(name, maximumBytes, identity);
434
+ }
435
+ catch (error) {
436
+ if (!name.endsWith(".receipt.json"))
437
+ throw error;
438
+ return await readFile(name, maximumBytes);
439
+ }
440
+ },
441
+ };
442
+ }
443
+ return {
444
+ directory,
445
+ list: async () => {
446
+ const stat = await fs.lstat(directory).catch(error => {
447
+ if (error.code === "ENOENT")
448
+ return null;
449
+ throw error;
450
+ });
451
+ if (!stat)
452
+ return null;
453
+ if (!stat.isDirectory()) {
454
+ throw new Error("managed_command_teardown_invalid: the managed-command ownership path is not an ordinary directory.");
455
+ }
456
+ return await fs.readdir(directory);
457
+ },
458
+ read: async (name, maximumBytes) => await readFile(name, maximumBytes),
459
+ };
460
+ }
461
+ async function persistReceipt(receiptPath, receipt) {
462
+ const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
463
+ try {
464
+ await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" });
465
+ // Windows refuses to replace a file another process briefly holds open.
466
+ await replaceFile(temporaryPath, receiptPath);
467
+ }
468
+ finally {
469
+ await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
470
+ }
471
+ }
472
+ function processExists(pid) {
473
+ if (!Number.isSafeInteger(pid) || pid <= 0)
474
+ return false;
475
+ try {
476
+ process.kill(pid, 0);
477
+ return true;
478
+ }
479
+ catch (error) {
480
+ return error.code === "EPERM";
481
+ }
482
+ }
483
+ function processGroupExists(processGroupId) {
484
+ try {
485
+ process.kill(-processGroupId, 0);
486
+ return true;
487
+ }
488
+ catch (error) {
489
+ const code = error.code;
490
+ if (code === "ESRCH")
491
+ return false;
492
+ if (code === "EPERM")
493
+ return true;
494
+ throw error;
495
+ }
496
+ }
497
+ function signalProcessGroup(processGroupId, signal) {
498
+ try {
499
+ process.kill(-processGroupId, signal);
500
+ }
501
+ catch (error) {
502
+ if (error.code !== "ESRCH")
503
+ throw error;
504
+ }
505
+ }
506
+ async function waitForProcessGroupExit(processGroupId, timeoutMs) {
507
+ await waitUntil(() => !processGroupExists(processGroupId), timeoutMs);
508
+ }
509
+ async function waitUntil(predicate, timeoutMs) {
510
+ const deadline = monotonicNowMs() + timeoutMs;
511
+ while (monotonicNowMs() < deadline && !predicate())
512
+ await delay(25);
513
+ }
514
+ async function delay(ms) {
515
+ await new Promise(resolve => setTimeout(resolve, ms));
516
+ }
517
+ /** Fields after the parenthesized command name of /proc/<pid>/stat: state, ppid, pgrp, ... */
518
+ async function linuxStatFields(pid) {
519
+ try {
520
+ const stat = await fs.readFile(`${procRoot}/${pid}/stat`, "utf8");
521
+ return stat.slice(stat.lastIndexOf(")") + 2).trim().split(/\s+/u);
522
+ }
523
+ catch {
524
+ return null;
525
+ }
526
+ }
527
+ async function linuxProcessGroupOf(pid) {
528
+ const pgrp = Number((await linuxStatFields(pid))?.[2]);
529
+ return Number.isSafeInteger(pgrp) ? pgrp : null;
530
+ }
531
+ async function linuxProcessIsZombie(pid) {
532
+ const state = (await linuxStatFields(pid))?.[0];
533
+ return state === "Z" || state === "X";
534
+ }
535
+ async function linuxProcessCarriesMarkers(pid, markers) {
536
+ try {
537
+ const environment = new Set((await fs.readFile(`${procRoot}/${pid}/environ`, "utf8")).split("\0"));
538
+ return markers.every(marker => environment.has(marker));
539
+ }
540
+ catch {
541
+ // The process exited while it was inspected, or its environment is not readable.
542
+ return false;
543
+ }
544
+ }
545
+ /** /proc entries, or null when the process inventory cannot be listed. */
546
+ async function linuxProcessIds() {
547
+ try {
548
+ return (await fs.readdir(procRoot)).filter(entry => /^\d+$/u.test(entry)).map(Number);
549
+ }
550
+ catch {
551
+ return null;
552
+ }
553
+ }
554
+ /**
555
+ * The running and exited members of a process group, or null when the inventory is
556
+ * incomplete: /proc cannot be listed, or a member's stat cannot be read for a reason other
557
+ * than that process having exited.
558
+ */
559
+ async function linuxProcessGroupMembers(processGroupId) {
560
+ const pids = await linuxProcessIds();
561
+ if (pids === null)
562
+ return null;
563
+ const members = [];
564
+ for (const pid of pids) {
565
+ let stat;
566
+ try {
567
+ stat = await fs.readFile(`${procRoot}/${pid}/stat`, "utf8");
568
+ }
569
+ catch (error) {
570
+ const code = error.code;
571
+ if (code === "ENOENT" || code === "ESRCH")
572
+ continue;
573
+ return null;
574
+ }
575
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).trim().split(/\s+/u);
576
+ if (Number(fields[2]) !== processGroupId)
577
+ continue;
578
+ members.push({ pid, zombie: fields[0] === "Z" || fields[0] === "X" });
579
+ }
580
+ return members;
581
+ }
582
+ /** Running processes whose environment carries every marker, or null when /proc cannot be listed. */
583
+ async function linuxProcessesCarryingMarkers(markers) {
584
+ const pids = await linuxProcessIds();
585
+ if (pids === null)
586
+ return null;
587
+ const found = [];
588
+ for (const pid of pids) {
589
+ if (await linuxProcessIsZombie(pid) || !await linuxProcessCarriesMarkers(pid, markers))
590
+ continue;
591
+ const identity = captureHostProcessIdentity(pid, "linux");
592
+ if (identity)
593
+ found.push({ pid, identity });
594
+ }
595
+ return found;
596
+ }
@@ -0,0 +1,70 @@
1
+ export declare const memoryAdmissionPolicyVersion = "memory-admission-v2";
2
+ export declare const memoryAdmissionEquation = "max(0, min(stabilized_available - reserve - pending_commitment, total - reserve - committed))";
3
+ export interface MemoryAdmissionDiagnostics {
4
+ readonly policyVersion: string;
5
+ readonly sampledAt: string;
6
+ readonly totalMemoryBytes: number;
7
+ readonly rawAvailableMemoryBytes: number;
8
+ readonly stabilizedAvailableMemoryBytes: number;
9
+ readonly reclaimableMemoryBytes: number | null;
10
+ readonly reclaimableMemorySource: "not_sampled_separately";
11
+ readonly controlPlaneMemoryBytes: number;
12
+ readonly reserveMemoryBytes: number;
13
+ readonly committedMemoryBytes: number;
14
+ readonly pendingCommitmentMemoryBytes: number;
15
+ readonly availableForAdmissionBytes: number;
16
+ readonly requestedMemoryBytes: number | null;
17
+ readonly shortfallMemoryBytes: number | null;
18
+ readonly decision: "snapshot" | "admitted" | "denied";
19
+ readonly equation: string;
20
+ }
21
+ export interface MemoryAdmissionInputs {
22
+ readonly sampledAt: string;
23
+ readonly totalMemoryBytes: number;
24
+ readonly rawAvailableMemoryBytes: number;
25
+ readonly stabilizedAvailableMemoryBytes: number;
26
+ readonly controlPlaneMemoryBytes: number;
27
+ readonly reserveMemoryBytes: number;
28
+ /** Every committed Forge request, including pending requests. */
29
+ readonly committedMemoryBytes: number;
30
+ /** Commitments not yet reflected in the OS available-memory sample. */
31
+ readonly pendingCommitmentMemoryBytes: number;
32
+ readonly requestedMemoryBytes?: number | null;
33
+ }
34
+ /**
35
+ * One memory admission equation for Docker and managed-host capacity. The raw
36
+ * OS/daemon sample already reflects resident active children, so only pending
37
+ * commitments are charged against sampled headroom. Ambient host use must not
38
+ * also be folded into committedMemoryBytes: it is already reflected in the OS
39
+ * sample, and doing both permanently double-charges long-lived host processes.
40
+ * The total-memory ceiling independently caps Forge's own reservations.
41
+ */
42
+ export declare function buildMemoryAdmissionDiagnostics(inputs: MemoryAdmissionInputs): MemoryAdmissionDiagnostics;
43
+ export interface AdaptiveMemoryReserveOptions {
44
+ readonly explicitBytes?: number | null;
45
+ readonly floorBytes?: number | null;
46
+ readonly ceilingBytes?: number | null;
47
+ readonly percent?: number | null;
48
+ }
49
+ /**
50
+ * Derives a host safety reserve from the capacity domain it protects. An
51
+ * explicit operator value remains authoritative; otherwise the reserve scales
52
+ * with the sampled total inside conservative floors and ceilings.
53
+ */
54
+ export declare function resolveAdaptiveMemoryReserveBytes(totalMemoryBytes: number, options?: AdaptiveMemoryReserveOptions): number;
55
+ /**
56
+ * Applies pressure immediately while requiring durable recovery samples before
57
+ * increasing advertised capacity. This prevents one GC/cache sample from
58
+ * waking queued work and then immediately withdrawing the same capacity.
59
+ */
60
+ export declare class RecoveryStabilizedMemory {
61
+ private readonly requiredRecoverySamples;
62
+ private readonly minimumRecoverySampleIntervalMs;
63
+ private stableBytes;
64
+ private recoveryFloorBytes;
65
+ private recoverySamples;
66
+ private lastRecoverySampleAt;
67
+ constructor(requiredRecoverySamples?: number, minimumRecoverySampleIntervalMs?: number);
68
+ observe(rawAvailableBytes: number, sampledAt?: number): number;
69
+ private resetRecovery;
70
+ }