@loucompanion/forge-bridge 0.1.4-dev.d2d83bc81b6a → 0.1.4-dev.deb7f72e7930

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 (253) hide show
  1. package/README.md +144 -3
  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 +10 -0
  5. package/dist/bridge/bridge-chat.types.js +16 -1
  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 +9 -0
  15. package/dist/bridge/bridge.service.d.ts +92 -15
  16. package/dist/bridge/bridge.service.js +432 -342
  17. package/dist/bridge/bridge.types.d.ts +27 -0
  18. package/dist/bridge/in-flight-registry.d.ts +62 -0
  19. package/dist/bridge/in-flight-registry.js +207 -0
  20. package/dist/bridge/local-yield-flag.d.ts +6 -0
  21. package/dist/bridge/local-yield-flag.js +34 -0
  22. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  23. package/dist/bridge/readiness-result-outbox.js +20 -0
  24. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  25. package/dist/bridge/runner-host-capabilities.js +17 -0
  26. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  27. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  28. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  29. package/dist/bridge/test-postgres-capability.js +120 -0
  30. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  31. package/dist/cleanup/cleanup-wip.js +66 -0
  32. package/dist/cleanup/cleanup.service.d.ts +20 -1
  33. package/dist/cleanup/cleanup.service.js +150 -169
  34. package/dist/cleanup/cleanup.types.d.ts +6 -0
  35. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  36. package/dist/cleanup/forge-owned-paths.js +53 -0
  37. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  38. package/dist/cleanup/host-runtime-ledger.js +130 -0
  39. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  40. package/dist/cleanup/managed-branch-sweep.js +111 -0
  41. package/dist/cli/cli.help.js +74 -12
  42. package/dist/cli/cli.service.d.ts +19 -10
  43. package/dist/cli/cli.service.js +152 -187
  44. package/dist/cli/idle-status.d.ts +84 -0
  45. package/dist/cli/idle-status.js +181 -0
  46. package/dist/cli/local-config.d.ts +6 -0
  47. package/dist/cli/local-config.js +32 -4
  48. package/dist/cli/provider-cli-detection.d.ts +10 -0
  49. package/dist/cli/provider-cli-detection.js +160 -0
  50. package/dist/runtime/aspnet-runtime-prebuild.d.ts +5 -0
  51. package/dist/runtime/aspnet-runtime-prebuild.js +140 -7
  52. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  53. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  54. package/dist/runtime/docker-engine-probe.js +7 -0
  55. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  56. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  57. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  58. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  59. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  60. package/dist/runtime/host-database-capability-boundary.js +1 -0
  61. package/dist/runtime/host-facts.d.ts +36 -0
  62. package/dist/runtime/host-facts.js +95 -0
  63. package/dist/runtime/host-load-admission.d.ts +67 -0
  64. package/dist/runtime/host-load-admission.js +99 -0
  65. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  66. package/dist/runtime/host-load-child-environment.js +76 -0
  67. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  68. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  69. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  70. package/dist/runtime/host-load-governor-config.js +83 -0
  71. package/dist/runtime/host-load-governor.d.ts +186 -0
  72. package/dist/runtime/host-load-governor.js +632 -0
  73. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  74. package/dist/runtime/host-load-ledger-lock.js +187 -0
  75. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  76. package/dist/runtime/host-load-runtime-settings.js +80 -0
  77. package/dist/runtime/host-load-sampler.d.ts +156 -0
  78. package/dist/runtime/host-load-sampler.js +298 -0
  79. package/dist/runtime/host-load-step-class.d.ts +70 -0
  80. package/dist/runtime/host-load-step-class.js +161 -0
  81. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  82. package/dist/runtime/host-load-step-reaper.js +95 -0
  83. package/dist/runtime/host-load-step-run.d.ts +73 -0
  84. package/dist/runtime/host-load-step-run.js +102 -0
  85. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  86. package/dist/runtime/host-load-test-slot.js +81 -0
  87. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  88. package/dist/runtime/host-load-token-ledger.js +453 -0
  89. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  90. package/dist/runtime/host-load-windows-cpu.js +85 -0
  91. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  92. package/dist/runtime/host-pressure-stall.js +168 -0
  93. package/dist/runtime/host-runtime-contract.d.ts +16 -0
  94. package/dist/runtime/host-runtime-contract.js +35 -2
  95. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  96. package/dist/runtime/host-runtime-lease.js +285 -55
  97. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  98. package/dist/runtime/host-runtime-promotion.js +48 -0
  99. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  100. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  101. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  102. package/dist/runtime/host-runtime-requirements.js +117 -0
  103. package/dist/runtime/managed-command-teardown.js +5 -16
  104. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  105. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  106. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  107. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  108. package/dist/runtime/runner-settings.d.ts +104 -0
  109. package/dist/runtime/runner-settings.js +236 -0
  110. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  111. package/dist/sandbox/host-capacity-broker.js +336 -0
  112. package/dist/sandbox/managed-branch.d.ts +13 -0
  113. package/dist/sandbox/managed-branch.js +36 -0
  114. package/dist/sandbox/provider-auth/codex.js +11 -11
  115. package/dist/sandbox/runtime.d.ts +10 -1
  116. package/dist/sandbox/runtime.js +47 -8
  117. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  118. package/dist/sandbox/sandbox-cgroups.js +42 -0
  119. package/dist/session/architect-waits.d.ts +2 -0
  120. package/dist/session/architect-waits.js +138 -0
  121. package/dist/session/managed-attempt-tools.d.ts +2 -7
  122. package/dist/session/managed-attempt-tools.js +202 -116
  123. package/dist/session/managed-build-receipt.d.ts +5 -0
  124. package/dist/session/managed-build-receipt.js +8 -3
  125. package/dist/session/managed-command-host-load.d.ts +47 -0
  126. package/dist/session/managed-command-host-load.js +83 -0
  127. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  128. package/dist/session/mcp-argument-coercion.js +121 -0
  129. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  130. package/dist/session/phase-completion.artifacts.js +100 -26
  131. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  132. package/dist/session/phase-completion.command-validation.js +77 -0
  133. package/dist/session/phase-completion.d.ts +12 -0
  134. package/dist/session/phase-completion.helpers.js +13 -12
  135. package/dist/session/phase-completion.js +5 -0
  136. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  137. package/dist/session/phase-completion.mcp-args.js +156 -0
  138. package/dist/session/phase-completion.prompts.js +6 -1
  139. package/dist/session/phase-completion.runtime.d.ts +5 -11
  140. package/dist/session/phase-completion.runtime.js +91 -215
  141. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  142. package/dist/session/phase-completion.schema-parts.js +188 -0
  143. package/dist/session/phase-completion.schemas.d.ts +3 -3
  144. package/dist/session/phase-completion.schemas.js +208 -231
  145. package/dist/session/phase-completion.validation.d.ts +2 -3
  146. package/dist/session/phase-completion.validation.js +49 -93
  147. package/dist/session/pre-publication-host-load.d.ts +27 -0
  148. package/dist/session/pre-publication-host-load.js +111 -0
  149. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  150. package/dist/session/pre-publication-native-postgres.js +111 -0
  151. package/dist/session/pre-publication-pass.d.ts +61 -0
  152. package/dist/session/pre-publication-pass.js +148 -0
  153. package/dist/session/pre-publication-process.d.ts +3 -0
  154. package/dist/session/pre-publication-process.js +33 -20
  155. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  156. package/dist/session/pre-publication-skipped-tests.js +109 -0
  157. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  158. package/dist/session/pre-publication-step-execution.js +50 -0
  159. package/dist/session/pre-publication-validation.d.ts +37 -21
  160. package/dist/session/pre-publication-validation.js +224 -166
  161. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  162. package/dist/session/provider-cli/claude-background-work.js +181 -0
  163. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  164. package/dist/session/provider-cli/host-build-lock.js +30 -0
  165. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  166. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  167. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  168. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  169. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  170. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  171. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  172. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  173. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  174. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  175. package/dist/session/provider-cli/provider-cli.process.d.ts +41 -31
  176. package/dist/session/provider-cli/provider-cli.process.js +139 -438
  177. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  178. package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
  179. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  180. package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
  181. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  182. package/dist/session/provider-cli/provider-cli.service.js +200 -189
  183. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  184. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  185. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  186. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  187. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  188. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  189. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  190. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  191. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  192. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  193. package/dist/session/provider-cli/provider-output-state.js +15 -0
  194. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  195. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  196. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  197. package/dist/session/publishable-worktree-changes.js +193 -0
  198. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  199. package/dist/session/qa-sidecar-validation.js +28 -0
  200. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  201. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  202. package/dist/session/session-redaction.js +31 -181
  203. package/dist/session/session.base.d.ts +9 -1
  204. package/dist/session/session.service.d.ts +11 -2
  205. package/dist/session/session.service.js +182 -61
  206. package/dist/session/session.types.d.ts +3 -0
  207. package/dist/session/session.types.js +15 -3
  208. package/dist/session/sidecar-json-shape.d.ts +31 -0
  209. package/dist/session/sidecar-json-shape.js +217 -0
  210. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  211. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  212. package/dist/shared/fs/file-identity.d.ts +10 -0
  213. package/dist/shared/fs/file-identity.js +15 -0
  214. package/dist/shared/fs/replace-file.d.ts +7 -0
  215. package/dist/shared/fs/replace-file.js +33 -0
  216. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  217. package/dist/shared/process/host-process-recovery.js +23 -3
  218. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  219. package/dist/shared/process/host-process-supervisor.js +67 -15
  220. package/dist/shared/process/process-tree.d.ts +52 -0
  221. package/dist/shared/process/process-tree.js +144 -0
  222. package/dist/shared/process/process.d.ts +67 -0
  223. package/dist/shared/process/process.js +213 -11
  224. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  225. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  226. package/dist/shared/process/windows-launch.d.ts +18 -0
  227. package/dist/shared/process/windows-launch.js +68 -0
  228. package/dist/shared/provider-capabilities.js +14 -7
  229. package/dist/version.d.ts +1 -1
  230. package/dist/version.js +1 -1
  231. package/dist/worktree/dependency-warmer.d.ts +25 -0
  232. package/dist/worktree/dependency-warmer.js +46 -10
  233. package/dist/worktree/wip-git.d.ts +33 -0
  234. package/dist/worktree/wip-git.js +122 -0
  235. package/dist/worktree/wip-refs.d.ts +62 -0
  236. package/dist/worktree/wip-refs.js +119 -0
  237. package/dist/worktree/wip-restore.d.ts +38 -0
  238. package/dist/worktree/wip-restore.js +190 -0
  239. package/dist/worktree/wip-snapshot.d.ts +50 -0
  240. package/dist/worktree/wip-snapshot.js +268 -0
  241. package/dist/worktree/worktree-inputs.d.ts +8 -0
  242. package/dist/worktree/worktree-inputs.js +134 -0
  243. package/dist/worktree/worktree-origin-sync.d.ts +34 -0
  244. package/dist/worktree/worktree-origin-sync.js +127 -0
  245. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  246. package/dist/worktree/worktree-wip-events.js +98 -0
  247. package/dist/worktree/worktree-wip.d.ts +49 -0
  248. package/dist/worktree/worktree-wip.js +182 -0
  249. package/dist/worktree/worktree.base.d.ts +7 -1
  250. package/dist/worktree/worktree.service.d.ts +36 -5
  251. package/dist/worktree/worktree.service.js +120 -155
  252. package/dist/worktree/worktree.types.d.ts +38 -0
  253. package/package.json +2 -2
@@ -0,0 +1,17 @@
1
+ import type { HostRuntimeRequirements } from "./host-runtime-requirements.js";
2
+ /** What this bridge host offers, for the accept-time requirements recheck (decision 0013). */
3
+ export interface HostRequirementFacts {
4
+ readonly logicalThreads: number;
5
+ readonly totalMemoryBytes: number;
6
+ readonly availableToolchains: readonly string[];
7
+ readonly dockerAvailable: boolean;
8
+ readonly browserLaunch: boolean;
9
+ readonly testPostgresSuperuser: boolean | null;
10
+ }
11
+ export type HostRequirementsCheck = (requires: HostRuntimeRequirements | null | undefined) => readonly string[];
12
+ /**
13
+ * Reasons this host fails a host-mode attempt's declared requirements. The API filters on
14
+ * stored requirements; this recheck closes the gap when they were not reported yet or the
15
+ * attempt's contract differs from the probed one. Mirrors the API's wording.
16
+ */
17
+ export declare function unmetHostRuntimeRequirements(requires: HostRuntimeRequirements | null | undefined, facts: HostRequirementFacts): readonly string[];
@@ -0,0 +1,29 @@
1
+ const gib = 1024 * 1024 * 1024;
2
+ /**
3
+ * Reasons this host fails a host-mode attempt's declared requirements. The API filters on
4
+ * stored requirements; this recheck closes the gap when they were not reported yet or the
5
+ * attempt's contract differs from the probed one. Mirrors the API's wording.
6
+ */
7
+ export function unmetHostRuntimeRequirements(requires, facts) {
8
+ if (!requires)
9
+ return [];
10
+ const unmet = [];
11
+ if (requires.minThreads !== null && facts.logicalThreads < requires.minThreads) {
12
+ unmet.push(`needs ≥ ${requires.minThreads} threads; this host has ${facts.logicalThreads}`);
13
+ }
14
+ if (requires.minMemoryGiB !== null && facts.totalMemoryBytes / gib < requires.minMemoryGiB) {
15
+ unmet.push(`needs ≥ ${requires.minMemoryGiB} GiB; this host has ${(Math.floor(facts.totalMemoryBytes / gib * 100) / 100)}`);
16
+ }
17
+ const available = new Set(facts.availableToolchains.map(name => name.toLowerCase()));
18
+ const missing = requires.toolchains.filter(name => !available.has(name));
19
+ if (missing.length > 0)
20
+ unmet.push(`needs ${missing.join(", ")}; this host does not have ${missing.length === 1 ? "it" : "them"}`);
21
+ if (requires.docker && !facts.dockerAvailable)
22
+ unmet.push("needs Docker; this host does not have it");
23
+ if (requires.testPostgres?.superuser && !facts.dockerAvailable && facts.testPostgresSuperuser !== true) {
24
+ unmet.push("needs Docker or a superuser test database; this host has neither");
25
+ }
26
+ if (requires.playwright && !facts.browserLaunch)
27
+ unmet.push("needs Playwright browsers; this host cannot launch them");
28
+ return unmet;
29
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Project host requirements declared in `.forge/forge.runtime.yml` (decision 0013 §3).
3
+ *
4
+ * The bridge parses them with the runtime contract and reports them, with the contract
5
+ * fingerprint, in its readiness payload. The API stores them per fingerprint and uses them
6
+ * as hard placement filters. A contract without a `requires` section has no requirements.
7
+ */
8
+ export interface HostRuntimePlaywrightRequirement {
9
+ /** Pinned Playwright revision. Recorded; enforced once bridges probe browser revisions. */
10
+ readonly revision: string | null;
11
+ }
12
+ export interface HostRuntimeTestPostgresRequirement {
13
+ readonly extensions: readonly string[];
14
+ /** Suites need a superuser role (or Docker-backed Testcontainers). */
15
+ readonly superuser: boolean;
16
+ }
17
+ export interface HostRuntimeCostHint {
18
+ readonly cores: number | null;
19
+ readonly memoryGiB: number | null;
20
+ }
21
+ export interface HostRuntimeRequirements {
22
+ readonly minThreads: number | null;
23
+ readonly minMemoryGiB: number | null;
24
+ readonly toolchains: readonly string[];
25
+ /** Suites need a Docker engine (for example Testcontainers). */
26
+ readonly docker: boolean;
27
+ readonly playwright: HostRuntimePlaywrightRequirement | null;
28
+ readonly testPostgres: HostRuntimeTestPostgresRequirement | null;
29
+ /** Accepted and reported, not yet used for placement. */
30
+ readonly costHints: Readonly<Record<string, HostRuntimeCostHint>>;
31
+ }
32
+ /**
33
+ * Validates the optional top-level `requires` and `costHints` sections. Returns null when
34
+ * neither section is present, so contracts written before decision 0013 keep their meaning.
35
+ */
36
+ export declare function parseHostRuntimeRequirements(requires: unknown, costHints: unknown): HostRuntimeRequirements | null;
@@ -0,0 +1,117 @@
1
+ const requiresKeys = new Set(["minThreads", "minMemoryGiB", "toolchains", "docker", "playwright", "testPostgres"]);
2
+ const playwrightKeys = new Set(["revision"]);
3
+ const testPostgresKeys = new Set(["extensions", "superuser"]);
4
+ const costHintKeys = new Set(["cores", "memoryGiB"]);
5
+ const toolchainPattern = /^[a-z][a-z0-9_.-]{0,63}$/u;
6
+ const extensionPattern = /^[a-z][a-z0-9_]{0,62}$/u;
7
+ const stepClassPattern = /^[a-z][a-z0-9_.:-]{0,127}$/u;
8
+ const revisionPattern = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/u;
9
+ /**
10
+ * Validates the optional top-level `requires` and `costHints` sections. Returns null when
11
+ * neither section is present, so contracts written before decision 0013 keep their meaning.
12
+ */
13
+ export function parseHostRuntimeRequirements(requires, costHints) {
14
+ if (isAbsent(requires) && isAbsent(costHints))
15
+ return null;
16
+ const section = isAbsent(requires) ? {} : object(requires, "requires");
17
+ rejectUnknownKeys(section, requiresKeys, "requires");
18
+ return {
19
+ minThreads: optionalNumber(section.minThreads, "requires.minThreads", 1, 1024, true),
20
+ minMemoryGiB: optionalNumber(section.minMemoryGiB, "requires.minMemoryGiB", 0.125, 4096, false),
21
+ toolchains: nameList(section.toolchains, "requires.toolchains", toolchainPattern, 32),
22
+ docker: optionalBoolean(section.docker, "requires.docker"),
23
+ playwright: parsePlaywright(section.playwright),
24
+ testPostgres: parseTestPostgres(section.testPostgres),
25
+ costHints: parseCostHints(costHints),
26
+ };
27
+ }
28
+ function parsePlaywright(value) {
29
+ if (isAbsent(value) || value === false)
30
+ return null;
31
+ if (value === true)
32
+ return { revision: null };
33
+ const playwright = object(value, "requires.playwright");
34
+ rejectUnknownKeys(playwright, playwrightKeys, "requires.playwright");
35
+ if (isAbsent(playwright.revision))
36
+ return { revision: null };
37
+ if (typeof playwright.revision !== "string" || !revisionPattern.test(playwright.revision.trim())) {
38
+ throw invalid("requires.playwright.revision must be a version or revision string.");
39
+ }
40
+ return { revision: playwright.revision.trim() };
41
+ }
42
+ function parseTestPostgres(value) {
43
+ if (isAbsent(value))
44
+ return null;
45
+ const testPostgres = object(value, "requires.testPostgres");
46
+ rejectUnknownKeys(testPostgres, testPostgresKeys, "requires.testPostgres");
47
+ return {
48
+ extensions: nameList(testPostgres.extensions, "requires.testPostgres.extensions", extensionPattern, 16),
49
+ superuser: optionalBoolean(testPostgres.superuser, "requires.testPostgres.superuser"),
50
+ };
51
+ }
52
+ function parseCostHints(value) {
53
+ if (isAbsent(value))
54
+ return {};
55
+ const hints = object(value, "costHints");
56
+ const entries = Object.entries(hints);
57
+ if (entries.length > 32)
58
+ throw invalid("costHints may declare at most 32 step classes.");
59
+ const parsed = {};
60
+ for (const [stepClass, hint] of entries.sort(([left], [right]) => left.localeCompare(right))) {
61
+ if (!stepClassPattern.test(stepClass))
62
+ throw invalid(`costHints step class '${stepClass}' is invalid.`);
63
+ const entry = object(hint, `costHints.${stepClass}`);
64
+ rejectUnknownKeys(entry, costHintKeys, `costHints.${stepClass}`);
65
+ parsed[stepClass] = {
66
+ cores: optionalNumber(entry.cores, `costHints.${stepClass}.cores`, 0.01, 1024, false),
67
+ memoryGiB: optionalNumber(entry.memoryGiB, `costHints.${stepClass}.memoryGiB`, 0.01, 4096, false),
68
+ };
69
+ }
70
+ return parsed;
71
+ }
72
+ function optionalNumber(value, label, minimum, maximum, integer) {
73
+ if (isAbsent(value))
74
+ return null;
75
+ if (typeof value !== "number" || !Number.isFinite(value) || value < minimum || value > maximum
76
+ || (integer && !Number.isSafeInteger(value))) {
77
+ throw invalid(`${label} must be ${integer ? "an integer" : "a number"} between ${minimum} and ${maximum}.`);
78
+ }
79
+ return value;
80
+ }
81
+ function nameList(value, label, pattern, maximum) {
82
+ if (isAbsent(value))
83
+ return [];
84
+ if (!Array.isArray(value) || value.length > maximum) {
85
+ throw invalid(`${label} must be a list with at most ${maximum} entries.`);
86
+ }
87
+ const names = value.map((entry, index) => {
88
+ const name = typeof entry === "string" ? entry.trim().toLowerCase() : "";
89
+ if (!pattern.test(name))
90
+ throw invalid(`${label}[${index}] is invalid.`);
91
+ return name;
92
+ });
93
+ return [...new Set(names)].sort((left, right) => left.localeCompare(right));
94
+ }
95
+ function optionalBoolean(value, label) {
96
+ if (isAbsent(value))
97
+ return false;
98
+ if (typeof value !== "boolean")
99
+ throw invalid(`${label} must be true or false.`);
100
+ return value;
101
+ }
102
+ function isAbsent(value) {
103
+ return value === undefined || value === null;
104
+ }
105
+ function object(value, label) {
106
+ if (!value || typeof value !== "object" || Array.isArray(value))
107
+ throw invalid(`${label} must be an object.`);
108
+ return value;
109
+ }
110
+ function rejectUnknownKeys(value, allowed, label) {
111
+ const unknown = Object.keys(value).find(key => !allowed.has(key));
112
+ if (unknown)
113
+ throw invalid(`unknown ${label} key '${unknown}'.`);
114
+ }
115
+ function invalid(message) {
116
+ return new Error(`runtime_contract_invalid: ${message}`);
117
+ }
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { readCanonicalSourceFile } from "./canonical-source-file.js";
5
5
  import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
6
+ import { replaceFile } from "../shared/fs/replace-file.js";
6
7
  import { ExactHostProcessRecovery } from "../shared/process/host-process-recovery.js";
7
8
  import { captureHostProcessIdentity, } from "../shared/process/host-process-supervisor.js";
8
9
  import { monotonicNowMs } from "../shared/time/monotonic.js";
@@ -14,8 +15,7 @@ const maximumReceiptBytes = 16 * 1024 * 1024;
14
15
  const maximumCapturedCharacters = 200_000;
15
16
  const defaultGraceMs = 2_000;
16
17
  const receiptReadAttempts = 5;
17
- const receiptReplaceAttempts = 40;
18
- const receiptReplaceRetryMs = 25;
18
+ const receiptReadRetryMs = 25;
19
19
  const invalidMetadata = Symbol("invalid managed-command metadata");
20
20
  let procRoot = "/proc";
21
21
  /** Test support: points the Linux process inventory at another directory (null restores /proc). */
@@ -363,7 +363,7 @@ async function readReceipt(store, name) {
363
363
  }
364
364
  catch {
365
365
  if (attempt < receiptReadAttempts)
366
- await delay(receiptReplaceRetryMs);
366
+ await delay(receiptReadRetryMs);
367
367
  }
368
368
  }
369
369
  return null;
@@ -462,19 +462,8 @@ async function persistReceipt(receiptPath, receipt) {
462
462
  const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
463
463
  try {
464
464
  await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" });
465
- for (let attempt = 1;; attempt += 1) {
466
- try {
467
- await fs.rename(temporaryPath, receiptPath);
468
- return;
469
- }
470
- catch (error) {
471
- const code = error.code;
472
- // Windows refuses to replace a file another process briefly holds open.
473
- if (attempt >= receiptReplaceAttempts || (code !== "EPERM" && code !== "EBUSY" && code !== "EACCES"))
474
- throw error;
475
- await delay(receiptReplaceRetryMs);
476
- }
477
- }
465
+ // Windows refuses to replace a file another process briefly holds open.
466
+ await replaceFile(temporaryPath, receiptPath);
478
467
  }
479
468
  finally {
480
469
  await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
@@ -2,15 +2,51 @@ export declare const nativeTestPostgresFallbackConfigEnvironment = "FORGE_NATIVE
2
2
  export declare const nativeTestPostgresFallbackFileName = "native-test-postgres.json";
3
3
  export declare const nativeTestPostgresFallbackDatabaseMode = "native_fallback";
4
4
  /**
5
- * A dedicated, operator-provisioned PostgreSQL cluster that runner-authored .NET
6
- * test tiers may use only while the Docker engine is unavailable. The cluster
7
- * must hold nothing but disposable test databases, so its capability carries no
8
- * more authority than the attempt-private container it replaces.
5
+ * The cluster serves the shared test server while Docker is up, so tests that need a
6
+ * pinned engine container still start one. Owner policy (2026-11-16): native PostgreSQL
7
+ * first, which keeps test databases out of the Docker VM and saves RAM.
8
+ */
9
+ export declare const nativeTestPostgresPreferredDatabaseMode = "native_preferred";
10
+ export type NativeTestPostgresDatabaseMode = typeof nativeTestPostgresFallbackDatabaseMode | typeof nativeTestPostgresPreferredDatabaseMode;
11
+ /**
12
+ * What runner-authored .NET test tiers get: `preferred` (the default) the provisioned
13
+ * cluster whenever it is configured; `docker_unavailable` that cluster only after a
14
+ * Docker probe fails; `ephemeral` a throwaway cluster of their own for each check, whose
15
+ * bootstrap superuser they hold (owner policy 2026-11-17). The provisioned cluster still
16
+ * hosts the attempt database broker in every mode.
17
+ */
18
+ export type NativeTestPostgresUse = "preferred" | "docker_unavailable" | "ephemeral";
19
+ /**
20
+ * A dedicated, operator-provisioned PostgreSQL cluster for runner-authored .NET
21
+ * test tiers, preferred over Docker unless its file says `docker_unavailable`.
22
+ * The cluster must hold nothing but disposable test databases, so its capability
23
+ * carries no more authority than the attempt-private container it replaces.
9
24
  */
10
25
  export interface NativeTestPostgresFallback {
11
26
  readonly connectionString: string;
12
27
  readonly endpoint: string;
28
+ readonly use: NativeTestPostgresUse;
29
+ /** The PostgreSQL bin directory an ephemeral cluster runs from; defaults to the one beside psql. */
30
+ readonly postgresBin?: string;
13
31
  }
32
+ /** The cluster as handed to one test process, with the mode its fixtures run in. */
33
+ export interface NativeTestPostgresGrant {
34
+ readonly connectionString: string;
35
+ readonly endpoint: string;
36
+ readonly mode: NativeTestPostgresDatabaseMode;
37
+ /** Set when the grant is a throwaway cluster of its own; the server reports it as `forge.ephemeral_cluster`. */
38
+ readonly ephemeralClusterId?: string;
39
+ /** Stops and deletes an ephemeral cluster once its check has finished. */
40
+ readonly release?: () => Promise<void>;
41
+ }
42
+ /**
43
+ * The provisioned cluster's grant for a check that can use it, or null to use Docker. A
44
+ * preferred cluster is granted whether or not Docker is up; the mode says which, because
45
+ * only the fallback mode excludes Docker for pinned-engine tests. An `ephemeral` host
46
+ * normally gets its own cluster instead (ephemeral-test-postgres-grant.ts); if that cannot
47
+ * start, the provisioned cluster serves only while Docker is down, as for `docker_unavailable`.
48
+ */
49
+ export declare function nativeTestPostgresGrant(fallback: NativeTestPostgresFallback | null, dockerAvailable: boolean): NativeTestPostgresGrant | null;
14
50
  export declare class NativeTestPostgresFallbackError extends Error {
15
51
  readonly code = "native_test_postgres_fallback_invalid";
16
52
  constructor(detail: string);
@@ -20,6 +56,14 @@ export declare function resolveNativeTestPostgresFallbackPath(): string;
20
56
  export declare function configuredNativeTestPostgresFallbackPath(): string | null;
21
57
  /** Returns null when no fallback is configured; throws when one is configured unsafely. */
22
58
  export declare function readNativeTestPostgresFallback(configPath?: string): NativeTestPostgresFallback | null;
23
- export declare function parseNativeTestPostgresFallback(connectionString: string): NativeTestPostgresFallback;
24
- /** Environment for one runner-authored .NET test process using the fallback. */
25
- export declare function nativeTestPostgresFallbackEnvironment(fallback: NativeTestPostgresFallback): Readonly<Record<string, string>>;
59
+ export declare function parseNativeTestPostgresFallback(connectionString: string, use?: NativeTestPostgresUse): NativeTestPostgresFallback;
60
+ /** Environment for one runner-authored .NET test process using the cluster. */
61
+ export declare function nativeTestPostgresFallbackEnvironment(grant: Pick<NativeTestPostgresGrant, "connectionString" | "mode" | "ephemeralClusterId">): Readonly<Record<string, string>>;
62
+ /**
63
+ * Runner-authored verification uses the operator-provisioned native test cluster,
64
+ * which holds no real data, whenever its file prefers it (the default); Docker then
65
+ * only starts pinned-engine containers. A `docker_unavailable` cluster is used only
66
+ * when the Docker engine is unavailable; otherwise the attempt-owned Testcontainers
67
+ * database serves.
68
+ */
69
+ export declare function managedVerificationDatabaseEnvironment(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null): Promise<Readonly<Record<string, string>>>;
@@ -1,12 +1,37 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { resolveLocalConfigPath } from "../cli/local-config.js";
4
+ import { DockerEngineProbe } from "./docker-engine-probe.js";
5
+ import { ephemeralTestPostgresClusterEnvironment } from "./ephemeral-test-postgres.js";
4
6
  import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, } from "./host-runtime-contract.js";
5
7
  export const nativeTestPostgresFallbackConfigEnvironment = "FORGE_NATIVE_TEST_POSTGRES_CONFIG";
6
8
  export const nativeTestPostgresFallbackFileName = "native-test-postgres.json";
7
9
  export const nativeTestPostgresFallbackDatabaseMode = "native_fallback";
10
+ /**
11
+ * The cluster serves the shared test server while Docker is up, so tests that need a
12
+ * pinned engine container still start one. Owner policy (2026-11-16): native PostgreSQL
13
+ * first, which keeps test databases out of the Docker VM and saves RAM.
14
+ */
15
+ export const nativeTestPostgresPreferredDatabaseMode = "native_preferred";
16
+ const nativeTestPostgresUses = ["preferred", "docker_unavailable", "ephemeral"];
8
17
  const defaultPostgresPort = 5432;
9
18
  const loopbackHosts = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
19
+ /**
20
+ * The provisioned cluster's grant for a check that can use it, or null to use Docker. A
21
+ * preferred cluster is granted whether or not Docker is up; the mode says which, because
22
+ * only the fallback mode excludes Docker for pinned-engine tests. An `ephemeral` host
23
+ * normally gets its own cluster instead (ephemeral-test-postgres-grant.ts); if that cannot
24
+ * start, the provisioned cluster serves only while Docker is down, as for `docker_unavailable`.
25
+ */
26
+ export function nativeTestPostgresGrant(fallback, dockerAvailable) {
27
+ if (!fallback || (dockerAvailable && fallback.use !== "preferred"))
28
+ return null;
29
+ return {
30
+ connectionString: fallback.connectionString,
31
+ endpoint: fallback.endpoint,
32
+ mode: dockerAvailable ? nativeTestPostgresPreferredDatabaseMode : nativeTestPostgresFallbackDatabaseMode,
33
+ };
34
+ }
10
35
  export class NativeTestPostgresFallbackError extends Error {
11
36
  code = "native_test_postgres_fallback_invalid";
12
37
  constructor(detail) {
@@ -46,9 +71,17 @@ export function readNativeTestPostgresFallback(configPath = resolveNativeTestPos
46
71
  if (document.schemaVersion !== 1 || typeof document.connectionString !== "string") {
47
72
  throw new NativeTestPostgresFallbackError(`${configPath} must contain schemaVersion 1 and a connectionString.`);
48
73
  }
49
- return parseNativeTestPostgresFallback(document.connectionString);
74
+ if (document.use !== undefined && !nativeTestPostgresUses.includes(document.use)) {
75
+ throw new NativeTestPostgresFallbackError(`${configPath} 'use' must be 'preferred', 'docker_unavailable' or 'ephemeral'.`);
76
+ }
77
+ if (document.postgresBin !== undefined
78
+ && (typeof document.postgresBin !== "string" || !path.isAbsolute(document.postgresBin))) {
79
+ throw new NativeTestPostgresFallbackError(`${configPath} 'postgresBin' must be an absolute path.`);
80
+ }
81
+ const fallback = parseNativeTestPostgresFallback(document.connectionString, document.use ?? "preferred");
82
+ return typeof document.postgresBin === "string" ? { ...fallback, postgresBin: document.postgresBin } : fallback;
50
83
  }
51
- export function parseNativeTestPostgresFallback(connectionString) {
84
+ export function parseNativeTestPostgresFallback(connectionString, use = "preferred") {
52
85
  const fields = new Map();
53
86
  for (const segment of connectionString.split(";")) {
54
87
  const separator = segment.indexOf("=");
@@ -79,13 +112,32 @@ export function parseNativeTestPostgresFallback(connectionString) {
79
112
  if (!(fields.get("username") ?? fields.get("userid") ?? fields.get("user"))) {
80
113
  throw new NativeTestPostgresFallbackError("the fallback must name a dedicated test role.");
81
114
  }
82
- return { connectionString: connectionString.trim(), endpoint: `${host}:${port}` };
115
+ return { connectionString: connectionString.trim(), endpoint: `${host}:${port}`, use };
83
116
  }
84
- /** Environment for one runner-authored .NET test process using the fallback. */
85
- export function nativeTestPostgresFallbackEnvironment(fallback) {
117
+ /** Environment for one runner-authored .NET test process using the cluster. */
118
+ export function nativeTestPostgresFallbackEnvironment(grant) {
86
119
  return {
87
- [hostRuntimeTestPostgresAdminEnvironment]: fallback.connectionString,
88
- [hostRuntimeLegacyTestPostgresEnvironment]: fallback.connectionString,
89
- FORGE_MANAGED_VERIFICATION_DATABASE_MODE: nativeTestPostgresFallbackDatabaseMode,
120
+ [hostRuntimeTestPostgresAdminEnvironment]: grant.connectionString,
121
+ [hostRuntimeLegacyTestPostgresEnvironment]: grant.connectionString,
122
+ FORGE_MANAGED_VERIFICATION_DATABASE_MODE: grant.mode,
123
+ // The fixtures accept a superuser login only on the cluster that reports this id.
124
+ ...(grant.ephemeralClusterId ? { [ephemeralTestPostgresClusterEnvironment]: grant.ephemeralClusterId } : {}),
90
125
  };
91
126
  }
127
+ /**
128
+ * Runner-authored verification uses the operator-provisioned native test cluster,
129
+ * which holds no real data, whenever its file prefers it (the default); Docker then
130
+ * only starts pinned-engine containers. A `docker_unavailable` cluster is used only
131
+ * when the Docker engine is unavailable; otherwise the attempt-owned Testcontainers
132
+ * database serves.
133
+ */
134
+ export async function managedVerificationDatabaseEnvironment(dockerAvailable = async () => (await new DockerEngineProbe().probeWithoutRecovery()).available, readFallback = () => {
135
+ const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
136
+ return configPath ? readNativeTestPostgresFallback(configPath) : null;
137
+ }) {
138
+ const fallback = readFallback();
139
+ if (!fallback)
140
+ return {};
141
+ const grant = nativeTestPostgresGrant(fallback, await dockerAvailable());
142
+ return grant ? nativeTestPostgresFallbackEnvironment(grant) : {};
143
+ }
@@ -28,5 +28,12 @@ export declare class PlaywrightHostRuntimeAdapter {
28
28
  */
29
29
  assertBrowserCacheReady(config: HostRuntimePlaywrightConfig, worktreePath: string): Promise<void>;
30
30
  private readyBrowserCache;
31
+ /**
32
+ * Removes the generated config, which names the base URL of the stack it was prepared for. A
33
+ * stopped stack's config must not survive: its port may be reassigned to another attempt, and a
34
+ * provider that remembers the config's path would otherwise run Playwright against that port.
35
+ * The next `prepare` writes a fresh one.
36
+ */
37
+ discardOverlay(temporaryDirectory: string): Promise<void>;
31
38
  prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
32
39
  }
@@ -35,6 +35,17 @@ export class PlaywrightHostRuntimeAdapter {
35
35
  }
36
36
  return { cache: resolution.cache, installCommand };
37
37
  }
38
+ /**
39
+ * Removes the generated config, which names the base URL of the stack it was prepared for. A
40
+ * stopped stack's config must not survive: its port may be reassigned to another attempt, and a
41
+ * provider that remembers the config's path would otherwise run Playwright against that port.
42
+ * The next `prepare` writes a fresh one.
43
+ */
44
+ async discardOverlay(temporaryDirectory) {
45
+ if (!await assertCanonicalDirectory(temporaryDirectory, true))
46
+ return;
47
+ await fs.rm(path.join(path.resolve(temporaryDirectory), playwrightOverlayFileName), { force: true });
48
+ }
38
49
  async prepare(config, context) {
39
50
  const { realWorktree, realSource } = await projectConfigLocation(config, context.worktreePath);
40
51
  const sourceConfig = path.resolve(path.resolve(context.worktreePath), config.config);
@@ -62,7 +73,7 @@ export class PlaywrightHostRuntimeAdapter {
62
73
  if (!/^[0-9a-f]{32}$/u.test(context.ownershipToken)) {
63
74
  throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
64
75
  }
65
- const overlayPath = path.join(temporaryDirectory, "forge.playwright.config.mjs");
76
+ const overlayPath = path.join(temporaryDirectory, playwrightOverlayFileName);
66
77
  const { cache: readyCache, installCommand: browserInstallCommand } = await this.readyBrowserCache(context.worktreePath, realWorktree, path.dirname(realSource));
67
78
  const browserCache = readyCache
68
79
  ? { path: readyCache, ready: true }
@@ -135,6 +146,7 @@ async function ensureAttemptWritableDirectories(targets, realWorktree) {
135
146
  for (const target of resolvedTargets)
136
147
  await createPrivateCanonicalDirectory(target);
137
148
  }
149
+ const playwrightOverlayFileName = "forge.playwright.config.mjs";
138
150
  async function writeAttemptOverlay(target, content) {
139
151
  const parent = path.dirname(target);
140
152
  const identity = await assertCanonicalDirectory(parent);
@@ -0,0 +1,104 @@
1
+ import { type HostLoadGovernorMode } from "./host-load-governor-config.js";
2
+ export declare const runnerSettingKeys: readonly ["maxConcurrentAttempts", "cpuBudgetPercent", "yieldCpuBudgetPercent", "memoryReserveBytes", "maxHeavySteps", "yieldToForeground"];
3
+ export type RunnerSettingKey = typeof runnerSettingKeys[number];
4
+ /** The `ApplySettings` hub message. Null numeric fields mean "no server value": keep today's env/default behaviour. */
5
+ export interface RunnerSettingsDocument {
6
+ readonly runnerId: string | null;
7
+ readonly version: number;
8
+ readonly maxConcurrentAttempts: number | null;
9
+ readonly cpuBudgetPercent: number | null;
10
+ readonly yieldCpuBudgetPercent: number | null;
11
+ readonly memoryReserveBytes: number | null;
12
+ readonly maxHeavySteps: number | null;
13
+ readonly yieldToForeground: boolean;
14
+ }
15
+ export interface RunnerSettingsValues {
16
+ readonly maxConcurrentAttempts: number;
17
+ readonly cpuBudgetPercent: number;
18
+ readonly yieldCpuBudgetPercent: number;
19
+ readonly memoryReserveBytes: number;
20
+ /** Null: the governor's budget alone limits heavy steps (no count limit). */
21
+ readonly maxHeavySteps: number | null;
22
+ readonly yieldToForeground: boolean;
23
+ }
24
+ /**
25
+ * Where an effective value came from: the server's value as is, the bridge default,
26
+ * an env var that capped/floored the server value or supplied it, or the host's
27
+ * `forge-bridge yield on` flag.
28
+ */
29
+ export type RunnerSettingSource = "server" | "default" | "host_env" | "host_local";
30
+ export interface RunnerSettingBound {
31
+ readonly key: RunnerSettingKey;
32
+ readonly envVar: string;
33
+ readonly value: number;
34
+ readonly kind: "ceiling" | "floor";
35
+ }
36
+ /**
37
+ * Why a key was rejected. `invalid`: the server value is outside the contract, so
38
+ * the host default applies (version skew; it never holds placement). `apply_failed`:
39
+ * the host could not put the value in force, so the previous value stays in force
40
+ * and the server holds placement until a later apply succeeds. Clamping by an env
41
+ * bound is neither: it is a `bound` and a `host_env` source.
42
+ */
43
+ export type RunnerSettingRejectionKind = "invalid" | "apply_failed";
44
+ export interface RunnerSettingRejection {
45
+ readonly key: RunnerSettingKey;
46
+ readonly reason: string;
47
+ readonly kind: RunnerSettingRejectionKind;
48
+ }
49
+ /** The `SettingsApplied` report; also carried in the capabilities `settings` block (schema 8). */
50
+ export interface RunnerSettingsReport {
51
+ /** The applied document version, or null before any ApplySettings was applied. */
52
+ readonly version: number | null;
53
+ /** FORGE_HOST_LOAD_GOVERNOR: CPU budget, yield budget and heavy steps only take effect when on. */
54
+ readonly governor: HostLoadGovernorMode;
55
+ readonly values: RunnerSettingsValues;
56
+ readonly sources: Readonly<Record<RunnerSettingKey, RunnerSettingSource>>;
57
+ readonly bounds: readonly RunnerSettingBound[];
58
+ readonly rejected: readonly RunnerSettingRejection[];
59
+ }
60
+ /** Today's bridge defaults for the keys whose default depends on the host. */
61
+ export interface RunnerHostDefaults {
62
+ /** floor(threads / 2) capped at 8 (at least 1). */
63
+ readonly maxConcurrentAttempts: number;
64
+ /** The adaptive reserve: 12.5% of RAM within 1–4 GiB, before FORGE_HOST_MEMORY_RESERVE_BYTES. */
65
+ readonly memoryReserveBytes: number;
66
+ }
67
+ export interface EffectiveRunnerSettings {
68
+ readonly report: RunnerSettingsReport;
69
+ /** Effective yield (server OR local flag). */
70
+ readonly yielding: boolean;
71
+ /**
72
+ * The governor CPU budget in force, as a fraction of logical CPUs: the CPU budget,
73
+ * or min(yield budget, CPU budget) while yielding.
74
+ */
75
+ readonly governorCpuBudgetFraction: number;
76
+ }
77
+ export declare const defaultCpuBudgetPercent = 80;
78
+ export declare const defaultYieldCpuBudgetPercent = 50;
79
+ /**
80
+ * Computes every effective value (decision 0014 precedence):
81
+ * - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
82
+ * - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
83
+ * - yield: server OR the local `forge-bridge yield on` flag.
84
+ * With no document at all (and the local flag off) the values equal today's env/default behaviour.
85
+ */
86
+ export declare function computeEffectiveRunnerSettings(document: RunnerSettingsDocument | null, environment: Readonly<Record<string, string | undefined>>, hostDefaults: RunnerHostDefaults, localYield: boolean): EffectiveRunnerSettings;
87
+ /**
88
+ * Parses the `ApplySettings` argument. Returns null when it has no usable version
89
+ * (the bridge then ignores it); malformed values become null so the host default applies.
90
+ */
91
+ export declare function parseRunnerSettingsDocument(raw: unknown): RunnerSettingsDocument | null;
92
+ /**
93
+ * The report for what is actually in force after an apply in which the host
94
+ * failed to put some keys in force: each failed key keeps the value (and source)
95
+ * that was in force before, and its failure is reported as an `apply_failed`
96
+ * rejection, so the server never reads a desired value as applied.
97
+ */
98
+ export declare function runnerSettingsInForce(report: RunnerSettingsReport, previous: RunnerSettingsReport, failures: readonly RunnerSettingRejection[]): RunnerSettingsReport;
99
+ /** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
100
+ export declare function sameRunnerSettingsReport(left: RunnerSettingsReport, right: RunnerSettingsReport): boolean;
101
+ /** The offer refusal message while the runner yields to foreground work. */
102
+ export declare function runnerYieldingMessage(report: RunnerSettingsReport): string;
103
+ /** One line describing the effective settings, for the bridge log. */
104
+ export declare function describeRunnerSettings(report: RunnerSettingsReport): string;