@loucompanion/forge-bridge 0.1.4-dev.bfa11ebe98c6 → 0.1.4-dev.c03d3c89ec4a

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 (174) hide show
  1. package/README.md +45 -3
  2. package/dist/bridge/bridge.base.d.ts +9 -0
  3. package/dist/bridge/bridge.service.d.ts +84 -2
  4. package/dist/bridge/bridge.service.js +358 -12
  5. package/dist/bridge/bridge.types.d.ts +22 -0
  6. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  7. package/dist/bridge/dispatch-result-outbox.js +31 -6
  8. package/dist/bridge/local-yield-flag.d.ts +6 -0
  9. package/dist/bridge/local-yield-flag.js +34 -0
  10. package/dist/bridge/runner-host-capabilities.d.ts +2 -0
  11. package/dist/bridge/runner-host-capabilities.js +4 -0
  12. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  13. package/dist/bridge/test-postgres-capability.js +120 -0
  14. package/dist/cleanup/cleanup.service.d.ts +9 -0
  15. package/dist/cleanup/cleanup.service.js +72 -109
  16. package/dist/cleanup/cleanup.types.d.ts +4 -0
  17. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  18. package/dist/cleanup/forge-owned-paths.js +53 -0
  19. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  20. package/dist/cleanup/host-runtime-ledger.js +109 -0
  21. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  22. package/dist/cleanup/managed-branch-sweep.js +111 -0
  23. package/dist/cli/cli.help.js +20 -2
  24. package/dist/cli/cli.service.d.ts +16 -0
  25. package/dist/cli/cli.service.js +142 -16
  26. package/dist/cli/local-config.d.ts +4 -0
  27. package/dist/cli/local-config.js +26 -4
  28. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  29. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  30. package/dist/runtime/attempt-database-broker.js +390 -0
  31. package/dist/runtime/attempt-process-supervisor.d.ts +24 -0
  32. package/dist/runtime/attempt-process-supervisor.js +77 -3
  33. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  34. package/dist/runtime/host-database-capability-boundary.js +1 -0
  35. package/dist/runtime/host-diagnostics.js +4 -3
  36. package/dist/runtime/host-facts.d.ts +35 -0
  37. package/dist/runtime/host-facts.js +95 -0
  38. package/dist/runtime/host-load-admission.d.ts +60 -0
  39. package/dist/runtime/host-load-admission.js +99 -0
  40. package/dist/runtime/host-load-child-environment.d.ts +22 -0
  41. package/dist/runtime/host-load-child-environment.js +67 -0
  42. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  43. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  44. package/dist/runtime/host-load-governor-config.d.ts +43 -0
  45. package/dist/runtime/host-load-governor-config.js +76 -0
  46. package/dist/runtime/host-load-governor.d.ts +174 -0
  47. package/dist/runtime/host-load-governor.js +541 -0
  48. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  49. package/dist/runtime/host-load-ledger-lock.js +185 -0
  50. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  51. package/dist/runtime/host-load-runtime-settings.js +78 -0
  52. package/dist/runtime/host-load-sampler.d.ts +126 -0
  53. package/dist/runtime/host-load-sampler.js +232 -0
  54. package/dist/runtime/host-load-step-class.d.ts +68 -0
  55. package/dist/runtime/host-load-step-class.js +106 -0
  56. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  57. package/dist/runtime/host-load-step-reaper.js +95 -0
  58. package/dist/runtime/host-load-step-run.d.ts +73 -0
  59. package/dist/runtime/host-load-step-run.js +102 -0
  60. package/dist/runtime/host-load-token-ledger.d.ts +174 -0
  61. package/dist/runtime/host-load-token-ledger.js +421 -0
  62. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  63. package/dist/runtime/host-pressure-stall.js +168 -0
  64. package/dist/runtime/host-runtime-contract.d.ts +4 -0
  65. package/dist/runtime/host-runtime-contract.js +75 -11
  66. package/dist/runtime/host-runtime-lease.d.ts +76 -4
  67. package/dist/runtime/host-runtime-lease.js +386 -32
  68. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  69. package/dist/runtime/host-runtime-promotion.js +48 -0
  70. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  71. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  72. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  73. package/dist/runtime/host-runtime-requirements.js +117 -0
  74. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  75. package/dist/runtime/managed-command-teardown.js +607 -0
  76. package/dist/runtime/node-host-runtime-adapter.js +5 -4
  77. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  78. package/dist/runtime/playwright-browser-cache.js +227 -0
  79. package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
  80. package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
  81. package/dist/runtime/runner-settings.d.ts +100 -0
  82. package/dist/runtime/runner-settings.js +214 -0
  83. package/dist/sandbox/host-capacity-broker.d.ts +107 -0
  84. package/dist/sandbox/host-capacity-broker.js +315 -0
  85. package/dist/sandbox/repository-lock.js +3 -2
  86. package/dist/sandbox/runtime.d.ts +10 -1
  87. package/dist/sandbox/runtime.js +50 -6
  88. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  89. package/dist/sandbox/sandbox-cgroups.js +42 -0
  90. package/dist/session/managed-attempt-tools.d.ts +27 -0
  91. package/dist/session/managed-attempt-tools.js +366 -45
  92. package/dist/session/managed-build-coordinator.d.ts +1 -1
  93. package/dist/session/managed-build-coordinator.js +8 -4
  94. package/dist/session/managed-command-host-load.d.ts +45 -0
  95. package/dist/session/managed-command-host-load.js +82 -0
  96. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  97. package/dist/session/mcp-argument-coercion.js +121 -0
  98. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  99. package/dist/session/phase-completion.artifacts.js +98 -25
  100. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  101. package/dist/session/phase-completion.command-validation.js +77 -0
  102. package/dist/session/phase-completion.d.ts +4 -0
  103. package/dist/session/phase-completion.helpers.js +13 -12
  104. package/dist/session/phase-completion.js +4 -0
  105. package/dist/session/phase-completion.prompts.js +6 -1
  106. package/dist/session/phase-completion.runtime.d.ts +5 -3
  107. package/dist/session/phase-completion.runtime.js +78 -36
  108. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  109. package/dist/session/phase-completion.schema-parts.js +188 -0
  110. package/dist/session/phase-completion.schemas.d.ts +3 -3
  111. package/dist/session/phase-completion.schemas.js +206 -221
  112. package/dist/session/phase-completion.validation.d.ts +2 -3
  113. package/dist/session/phase-completion.validation.js +46 -92
  114. package/dist/session/pre-publication-host-load.d.ts +27 -0
  115. package/dist/session/pre-publication-host-load.js +111 -0
  116. package/dist/session/pre-publication-pass.d.ts +60 -0
  117. package/dist/session/pre-publication-pass.js +145 -0
  118. package/dist/session/pre-publication-process.d.ts +23 -0
  119. package/dist/session/pre-publication-process.js +109 -0
  120. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  121. package/dist/session/pre-publication-skipped-tests.js +109 -0
  122. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  123. package/dist/session/pre-publication-step-execution.js +49 -0
  124. package/dist/session/pre-publication-validation.d.ts +30 -20
  125. package/dist/session/pre-publication-validation.js +178 -193
  126. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  127. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  128. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  129. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  130. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  131. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  132. package/dist/session/provider-cli/provider-cli.process.d.ts +37 -1
  133. package/dist/session/provider-cli/provider-cli.process.js +299 -25
  134. package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
  135. package/dist/session/provider-cli/provider-cli.prompts.js +62 -9
  136. package/dist/session/provider-cli/provider-cli.runtime.d.ts +6 -0
  137. package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
  138. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  139. package/dist/session/provider-cli/provider-cli.service.js +200 -162
  140. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  141. package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
  142. package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
  143. package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
  144. package/dist/session/provider-cli/provider-output-state.js +9 -0
  145. package/dist/session/provider-cli/provider-usage.d.ts +2 -1
  146. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  147. package/dist/session/publishable-worktree-changes.js +193 -0
  148. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  149. package/dist/session/sandbox-host-capacity-gate.js +229 -0
  150. package/dist/session/session.base.d.ts +9 -1
  151. package/dist/session/session.service.d.ts +9 -2
  152. package/dist/session/session.service.js +120 -5
  153. package/dist/session/session.types.d.ts +3 -0
  154. package/dist/session/session.types.js +15 -3
  155. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  156. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  157. package/dist/shared/process/host-process-recovery.js +3 -2
  158. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  159. package/dist/shared/process/host-process-supervisor.js +6 -5
  160. package/dist/shared/process/process-tree.d.ts +52 -0
  161. package/dist/shared/process/process-tree.js +144 -0
  162. package/dist/shared/process/process.d.ts +67 -0
  163. package/dist/shared/process/process.js +213 -11
  164. package/dist/shared/provider-capabilities.js +5 -6
  165. package/dist/shared/time/monotonic.d.ts +1 -0
  166. package/dist/shared/time/monotonic.js +8 -0
  167. package/dist/version.d.ts +1 -1
  168. package/dist/version.js +1 -1
  169. package/dist/worktree/dependency-warmer.d.ts +25 -0
  170. package/dist/worktree/dependency-warmer.js +120 -10
  171. package/dist/worktree/worktree.service.d.ts +10 -1
  172. package/dist/worktree/worktree.service.js +42 -2
  173. package/dist/worktree/worktree.types.d.ts +7 -0
  174. package/package.json +2 -2
@@ -4,23 +4,51 @@ import path from "node:path";
4
4
  import { isAlias, parseDocument, visit } from "yaml";
5
5
  import { readCanonicalSourceFile } from "./canonical-source-file.js";
6
6
  import { isGeneratedOutputDirectoryName } from "./generated-output-reset.js";
7
+ import { parseHostRuntimeRequirements } from "./host-runtime-requirements.js";
7
8
  export const hostRuntimeContractPath = ".forge/forge.runtime.yml";
8
9
  export const hostRuntimeTestPostgresAdminEnvironment = "FORGE_TEST_POSTGRES_ADMIN_CONNECTION_STRING";
9
10
  export const hostRuntimeLegacyTestPostgresEnvironment = "FORGE_TEST_POSTGRES_CONNECTION_STRING";
11
+ // Optional superuser login for operator-run .NET fixtures. Never reaches attempt, validation or provider processes.
12
+ export const hostRuntimeTestPostgresProvisionerEnvironment = "FORGE_TEST_POSTGRES_PROVISIONER_CONNECTION_STRING";
10
13
  const maximumContractBytes = 64 * 1024;
11
14
  const maximumDepth = 12;
15
+ // Every discovery scan stops after this many directory entries. A monorepo needs a few
16
+ // thousand; the bound only keeps a pathological tree from stalling attempt preparation.
17
+ const maximumDiscoveryEntries = 20_000;
18
+ /**
19
+ * A discovery scan reached its entry budget before seeing the whole tree, so what it did not
20
+ * find may still exist. Discovery must not treat that as absence: a partial runtime (for
21
+ * example a web app without its API) would send the attempt's traffic to the wrong server.
22
+ */
23
+ class IncompleteRuntimeDiscoveryError extends Error {
24
+ }
25
+ // Dependency, build and editor folders never hold an application entrypoint, and counting
26
+ // them would exhaust the budget and serialize a repository for no reason.
12
27
  const ignoredDiscoveryDirectories = new Set([
13
28
  ".forge",
14
29
  ".forge-designer",
15
30
  ".git",
31
+ ".gradle",
32
+ ".idea",
16
33
  ".local",
34
+ ".next",
35
+ ".pnpm",
36
+ ".turbo",
37
+ ".venv",
38
+ ".vs",
39
+ ".vscode",
40
+ ".yarn",
17
41
  "bin",
42
+ "build",
18
43
  "coverage",
19
44
  "dist",
20
45
  "node_modules",
21
46
  "obj",
47
+ "target",
48
+ "vendor",
49
+ "venv",
22
50
  ]);
23
- const topLevelKeys = new Set(["schemaVersion", "runtime"]);
51
+ const topLevelKeys = new Set(["schemaVersion", "runtime", "requires", "costHints"]);
24
52
  const runtimeKeys = new Set(["hostConcurrency", "ports", "playwright", "browserProfile", "singletonResources"]);
25
53
  const portKeys = new Set(["adapter", "launch", "env", "baseUrlEnv", "format"]);
26
54
  const launchKeys = new Set(["command", "args", "workingDirectory", "environment"]);
@@ -47,10 +75,19 @@ export async function loadHostRuntimeContract(worktreePath, snapshot, directoryS
47
75
  }
48
76
  async function discoverHostRuntimeContract(worktreePath, snapshot, directorySnapshot) {
49
77
  const root = path.resolve(worktreePath);
50
- const [nodeDiscovery, aspNetDiscovery] = await Promise.all([
51
- discoverNodeRuntimes(root, snapshot, directorySnapshot),
52
- discoverAspNetRuntimes(root, snapshot, directorySnapshot),
53
- ]);
78
+ let nodeDiscovery;
79
+ let aspNetDiscovery;
80
+ try {
81
+ [nodeDiscovery, aspNetDiscovery] = await Promise.all([
82
+ discoverNodeRuntimes(root, snapshot, directorySnapshot),
83
+ discoverAspNetRuntimes(root, snapshot, directorySnapshot),
84
+ ]);
85
+ }
86
+ catch (error) {
87
+ if (error instanceof IncompleteRuntimeDiscoveryError)
88
+ return incompleteRuntimeDiscovery();
89
+ throw error;
90
+ }
54
91
  if (nodeDiscovery.ambiguous || aspNetDiscovery.ambiguous) {
55
92
  return ambiguousRuntimeDiscovery();
56
93
  }
@@ -102,7 +139,7 @@ async function discoverHostRuntimeContract(worktreePath, snapshot, directorySnap
102
139
  async function discoverNodeRuntimes(root, snapshot, directorySnapshot) {
103
140
  const manifests = [...new Set([
104
141
  path.join(root, "package.json"),
105
- ...await findFiles(root, file => path.basename(file).toLowerCase() === "package.json", 4, 500, directorySnapshot),
142
+ ...await findFiles(root, file => path.basename(file).toLowerCase() === "package.json", 4, maximumDiscoveryEntries, directorySnapshot),
106
143
  ])];
107
144
  const candidates = (await Promise.all(manifests.map(async (manifestPath) => await discoverNodeRuntime(root, manifestPath, snapshot, directorySnapshot)))).filter((candidate) => candidate !== null);
108
145
  return { candidates: candidates.length === 1 ? candidates : [], ambiguous: candidates.length > 1 };
@@ -138,7 +175,7 @@ async function discoverNodeRuntime(root, manifestPath, snapshot, directorySnapsh
138
175
  ...["playwright.config.ts", "playwright.config.js", "playwright.config.mjs", "playwright.config.cjs"]
139
176
  .flatMap(file => [file, `e2e/${file}`, `tests/e2e/${file}`])
140
177
  .map(async (candidate) => await optionalFileExists(path.join(root, candidate), snapshot) ? path.join(root, candidate) : null),
141
- findFiles(root, file => /^playwright\.config\.(?:ts|js|mjs|cjs)$/iu.test(path.basename(file)), 4, 2_000, directorySnapshot),
178
+ findFiles(root, file => /^playwright\.config\.(?:ts|js|mjs|cjs)$/iu.test(path.basename(file)), 4, maximumDiscoveryEntries, directorySnapshot),
142
179
  ])).flat().filter((value) => value !== null))]
143
180
  .map(config => portableRelativePath(root, config));
144
181
  const playwright = playwrightConfigs.length === 1
@@ -183,7 +220,9 @@ async function discoverNodeRuntime(root, manifestPath, snapshot, directorySnapsh
183
220
  };
184
221
  }
185
222
  async function discoverAspNetRuntimes(root, snapshot, directorySnapshot) {
186
- const projects = await findFiles(root, file => file.toLowerCase().endsWith(".csproj"), 3, 200, directorySnapshot);
223
+ // Deep enough for nested solutions (src/<area>/<Project>/<Project>.csproj); the entry budget,
224
+ // not the depth, bounds the scan, and a scan that exceeds it is reported as incomplete.
225
+ const projects = await findFiles(root, file => file.toLowerCase().endsWith(".csproj"), 6, maximumDiscoveryEntries, directorySnapshot);
187
226
  const webProjects = [];
188
227
  for (const projectPath of projects) {
189
228
  const source = await readBoundedOptionalFile(projectPath, 512 * 1024, snapshot);
@@ -277,6 +316,17 @@ function combineBrowserAndApiRuntime(browser, api) {
277
316
  }),
278
317
  };
279
318
  }
319
+ function incompleteRuntimeDiscovery() {
320
+ return {
321
+ contract: defaultHostRuntimeContract(),
322
+ source: "default",
323
+ discovery: {
324
+ status: "ambiguous",
325
+ reasonCode: "runtime_discovery_incomplete",
326
+ summary: "Forge could not scan the whole repository within its discovery budget, so host application runs remain serialized.",
327
+ },
328
+ };
329
+ }
280
330
  function ambiguousRuntimeDiscovery() {
281
331
  return {
282
332
  contract: defaultHostRuntimeContract(),
@@ -339,7 +389,13 @@ async function discoverAspNetLaunchProfile(root, projectRelativePath, snapshot)
339
389
  return { name: null, source, environment: {} };
340
390
  }
341
391
  }
392
+ // A project's "forge-attempt" profile configures its API for managed attempts. The
393
+ // attempt's pre-publication checks then run against the same settings the project's own
394
+ // e2e suite uses, instead of the developer's "http" profile.
395
+ const attemptLaunchProfileName = "forge-attempt";
342
396
  function aspNetProfilePriority(name) {
397
+ if (name.toLowerCase() === attemptLaunchProfileName)
398
+ return -1;
343
399
  if (name.toLowerCase() === "http")
344
400
  return 0;
345
401
  if (name.toLowerCase() === "https")
@@ -373,7 +429,7 @@ async function findFiles(root, accepts, maximumDepth, maximumEntries, snapshot)
373
429
  const results = [];
374
430
  let examined = 0;
375
431
  const directories = [{ directory: root, depth: 0 }];
376
- while (directories.length > 0 && examined < maximumEntries) {
432
+ while (directories.length > 0) {
377
433
  const current = directories.shift();
378
434
  if (current.depth > maximumDepth)
379
435
  continue;
@@ -383,14 +439,20 @@ async function findFiles(root, accepts, maximumDepth, maximumEntries, snapshot)
383
439
  name: entry.name,
384
440
  isDirectory: entry.isDirectory(),
385
441
  isFile: entry.isFile(),
386
- }))).catch(() => []);
442
+ }))).catch((error) => {
443
+ // A directory removed since it was listed holds nothing; one that cannot be read
444
+ // (permissions, open-file limits) may hold the entrypoint discovery is looking for.
445
+ if (isFileNotFound(error))
446
+ return [];
447
+ throw new IncompleteRuntimeDiscoveryError();
448
+ });
387
449
  const orderedEntries = [...entries].sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
388
450
  for (const entry of orderedEntries) {
389
451
  if (entry.isDirectory
390
452
  && (ignoredDiscoveryDirectories.has(entry.name.toLowerCase()) || isGeneratedOutputDirectoryName(entry.name)))
391
453
  continue;
392
454
  if (examined++ >= maximumEntries)
393
- break;
455
+ throw new IncompleteRuntimeDiscoveryError();
394
456
  const target = path.join(current.directory, entry.name);
395
457
  if (entry.isDirectory)
396
458
  directories.push({ directory: target, depth: current.depth + 1 });
@@ -488,6 +550,7 @@ export function validateHostRuntimeContract(source) {
488
550
  throw new Error("runtime_contract_invalid: runtime.browserProfile must be isolated.");
489
551
  }
490
552
  const ports = parsePorts(runtime.ports);
553
+ const requires = parseHostRuntimeRequirements(root.requires, root.costHints);
491
554
  return {
492
555
  schemaVersion: 1,
493
556
  runtime: {
@@ -497,6 +560,7 @@ export function validateHostRuntimeContract(source) {
497
560
  browserProfile,
498
561
  singletonResources: parseSingletonResources(runtime.singletonResources),
499
562
  },
563
+ ...(requires ? { requires } : {}),
500
564
  };
501
565
  }
502
566
  function parsePlaywright(value, ports) {
@@ -1,4 +1,5 @@
1
- import type { RunOnceDispatchPacket } from "../session/session.types.js";
1
+ import type { HostRequirementsCheck } from "./host-runtime-requirements-check.js";
2
+ import { type RunOnceDispatchPacket } from "../session/session.types.js";
2
3
  import { type ProviderProcessRunner } from "../session/provider-cli/provider-cli.process.js";
3
4
  import { type RuntimeIsolationLease } from "./runtime-isolation-lease.js";
4
5
  import { type LoadedHostRuntimeContract } from "./host-runtime-contract.js";
@@ -6,11 +7,15 @@ import { HostPortBroker } from "./host-port-broker.js";
6
7
  import { NodeHostRuntimeAdapter, type NodeRuntimeAdapterLaunch, type NodeRuntimeCommand, type NodeRuntimeCommandLauncher } from "./node-host-runtime-adapter.js";
7
8
  import type { AttemptProcessTreeMemoryTelemetry } from "./attempt-process-supervisor.js";
8
9
  import { AttemptProcessSupervisorRegistry } from "./attempt-process-supervisor-registry.js";
10
+ import { type AttemptDatabaseBroker } from "./attempt-database-broker.js";
9
11
  import { HostListenerInspector } from "./host-listener-inspector.js";
10
12
  import { type MemoryAdmissionDiagnostics } from "./memory-capacity.js";
11
13
  import { PlaywrightHostRuntimeAdapter } from "./playwright-host-runtime-adapter.js";
12
14
  import { HostParallelPromotionStore } from "./host-runtime-promotion.js";
13
15
  import { type HostProcessRecovery } from "../shared/process/host-process-recovery.js";
16
+ import { HostLoadGovernor } from "./host-load-governor.js";
17
+ import { type HostLoadGovernorSource } from "./host-load-sampler.js";
18
+ import type { RunnerHostDefaults } from "./runner-settings.js";
14
19
  export interface HostRuntimeLeaseStart {
15
20
  readonly lease: RuntimeIsolationLease;
16
21
  readonly environment: Readonly<Record<string, string>>;
@@ -24,7 +29,7 @@ export interface HostRuntimeAdmissionCheckpoint {
24
29
  }
25
30
  export type HostRuntimeAdmissionCheckpointHandler = (checkpoint: HostRuntimeAdmissionCheckpoint) => void | Promise<void>;
26
31
  export interface HostRuntimeProjectCheckpoint {
27
- readonly code: "host_runtime_build_started" | "host_runtime_build_cached" | "host_runtime_build_completed";
32
+ readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned" | "host_runtime_contract_readmitted";
28
33
  readonly message: string;
29
34
  readonly data?: Readonly<Record<string, unknown>>;
30
35
  }
@@ -91,10 +96,21 @@ export interface HostNodeRuntimeLaunch<T> extends NodeRuntimeAdapterLaunch<T> {
91
96
  readonly runtimeLease: RuntimeIsolationLease;
92
97
  }
93
98
  export interface HostRuntimeLeaseRuntime {
99
+ setRequirementsCheck?(check: HostRequirementsCheck | null): void;
100
+ /** Decision 0014: today's max attempts and memory reserve defaults, before env bounds. */
101
+ capacityLimitDefaults?(): RunnerHostDefaults;
102
+ /** Decision 0014: the effective max attempts and memory reserve, from the next attempt admission. */
103
+ applyCapacityLimits?(limits: HostCapacityLimits): void;
94
104
  acquirePreparation?(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
95
105
  acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
96
106
  start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
97
107
  startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
108
+ /**
109
+ * Stops the attempt's configured project processes, releases their ports, and
110
+ * starts them again (rebuilding when sources changed) so the stack serves the
111
+ * current workspace. Returns the environment with the newly assigned URLs.
112
+ */
113
+ restartConfiguredProject?(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
98
114
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
99
115
  providerProcessRunner?(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
100
116
  providerMemoryTelemetry?(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
@@ -103,7 +119,10 @@ export interface HostRuntimeLeaseRuntime {
103
119
  hasForegroundDemand?(): boolean;
104
120
  reap?(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
105
121
  snapshot?(): HostRuntimeCapacitySnapshot;
122
+ /** Variables that let the completion MCP server share this host's load governor. */
123
+ hostLoadChildEnvironment?(): Readonly<Record<string, string>>;
106
124
  }
125
+ export type HostRuntimeAdmissionPriority = "foreground" | "background";
107
126
  export interface HostCapacityResourceSample {
108
127
  readonly totalMemoryBytes: number;
109
128
  readonly availableMemoryBytes: number;
@@ -119,6 +138,7 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
119
138
  private readonly playwrightAdapter;
120
139
  private readonly processRecovery;
121
140
  private readonly capacityResourceSample?;
141
+ private readonly databaseBroker;
122
142
  private readonly preparedReadiness;
123
143
  private readonly active;
124
144
  private readonly pendingRenewals;
@@ -138,10 +158,26 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
138
158
  private workspaceAvailableBytes;
139
159
  private readonly portBroker;
140
160
  private readonly nodeAdapter;
141
- private readonly capacityConfiguration;
161
+ /** Rebuilt by applyCapacityLimits (decision 0014); every admission reads the current one. */
162
+ private capacityConfiguration;
142
163
  private readonly memoryAvailability;
143
164
  private readonly executionRoot;
144
- constructor(stateRoot: string, portBroker?: HostPortBroker, nodeAdapter?: NodeHostRuntimeAdapter, processSupervisors?: AttemptProcessSupervisorRegistry, processRunner?: ProviderProcessRunner, listenerInspector?: HostListenerInspector, promotionStore?: HostParallelPromotionStore, playwrightAdapter?: PlaywrightHostRuntimeAdapter, processRecovery?: HostProcessRecovery, capacityResourceSample?: HostCapacityResourceSample | undefined, executionRoot?: string);
165
+ /** Host-wide admission for heavy steps (decision 0013); inert unless FORGE_HOST_LOAD_GOVERNOR=on. */
166
+ readonly hostLoadGovernor: HostLoadGovernor;
167
+ private requirementsCheck;
168
+ /** Installs the decision 0013 accept-time requirements recheck for host attempts. */
169
+ setRequirementsCheck(check: HostRequirementsCheck | null): void;
170
+ constructor(stateRoot: string, portBroker?: HostPortBroker, nodeAdapter?: NodeHostRuntimeAdapter, processSupervisors?: AttemptProcessSupervisorRegistry, processRunner?: ProviderProcessRunner, listenerInspector?: HostListenerInspector, promotionStore?: HostParallelPromotionStore, playwrightAdapter?: PlaywrightHostRuntimeAdapter, processRecovery?: HostProcessRecovery, capacityResourceSample?: HostCapacityResourceSample | undefined, executionRoot?: string, databaseBroker?: AttemptDatabaseBroker | null, hostLoad?: HostLoadGovernorSource | null);
171
+ /** Today's defaults for the limits the server can push, before any env bound (decision 0014). */
172
+ capacityLimitDefaults(): RunnerHostDefaults;
173
+ /**
174
+ * Decision 0014: the bridge's effective max attempts and memory reserve. They
175
+ * apply from the next attempt admission; admitted attempts keep their
176
+ * reservations and are never preempted, even when the new limit is lower than
177
+ * what already runs. The idle reserve follows the reserve as at startup.
178
+ */
179
+ applyCapacityLimits(limits: HostCapacityLimits): void;
180
+ hostLoadChildEnvironment(): Readonly<Record<string, string>>;
145
181
  reap(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
146
182
  snapshot(): HostRuntimeCapacitySnapshot;
147
183
  hasForegroundDemand(): boolean;
@@ -163,6 +199,24 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
163
199
  start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
164
200
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
165
201
  startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
202
+ /**
203
+ * Launches the configured project. Only the first launch, from the admitted commit's clean
204
+ * source, may record parallel-safety proof: a restart serves the workspace after the provider
205
+ * edited it, and a proof observed there would be stored under the admitted commit and could
206
+ * move this or a later attempt at that commit into shared admission for source it never ran.
207
+ */
208
+ private launchConfiguredProject;
209
+ /**
210
+ * Relaunches the configured project so it serves the current workspace. Every
211
+ * configured process stops (the API port changes, so the dev server's proxy target
212
+ * must change with it), its port reservation is released and dropped from the
213
+ * persisted lease, and the regular start path runs again, including the ASP.NET
214
+ * prebuild, whose receipt rebuilds only when the sources changed.
215
+ */
216
+ restartConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
217
+ private runConfiguredProjectRestart;
218
+ /** Stops configured project processes in reverse launch order and releases their ports. */
219
+ private stopConfiguredProject;
166
220
  providerProcessRunner(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
167
221
  private markCapacityReservationRunning;
168
222
  providerMemoryTelemetry(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
@@ -213,3 +267,21 @@ export declare class HostRuntimeCapacityRequestImpossibleError extends Error {
213
267
  }
214
268
  export declare function hostRuntimeEventResources(lease: RuntimeIsolationLease, runtimeContract?: LoadedHostRuntimeContract, executionClass?: HostRuntimeExecutionClass): Record<string, unknown>;
215
269
  export declare function hostRuntimeSingletonKeys(dispatch: RunOnceDispatchPacket): readonly string[];
270
+ /**
271
+ * Every environment key `hostRuntimeEnvironment` and the Playwright overlay derive from the
272
+ * configured project's assigned ports. They name a live stack, so they are withheld while the
273
+ * stack is down: after its ports are released another attempt may be assigned them.
274
+ */
275
+ export declare function hostRuntimeStackEnvironmentKeys(runtimeContract: LoadedHostRuntimeContract): readonly string[];
276
+ export declare function runtimeAdmissionPriority(dispatch: RunOnceDispatchPacket): HostRuntimeAdmissionPriority;
277
+ /** The pushed attempt limits (decision 0014), already resolved against host env bounds. */
278
+ export interface HostCapacityLimits {
279
+ readonly maxConcurrentAttempts: number;
280
+ readonly memoryReserveBytes: number;
281
+ }
282
+ /**
283
+ * Today's max attempts and adaptive memory reserve for this host, before
284
+ * FORGE_HOST_MAX_CONCURRENT_ATTEMPTS and FORGE_HOST_MEMORY_RESERVE_BYTES
285
+ * (decision 0014 treats those as bounds on the server's values).
286
+ */
287
+ export declare function hostCapacityLimitDefaults(capacityResourceSample?: HostCapacityResourceSample): RunnerHostDefaults;