@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
@@ -2,6 +2,7 @@ import type { BridgeServiceConfig } from "../bridge/bridge.types.js";
2
2
  import type { SessionEventSink } from "../session/session.base.js";
3
3
  import { type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
4
4
  import type { SandboxService, ValidatedSandboxContract } from "./sandbox.types.js";
5
+ import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
5
6
  import { type RuntimeIsolationLease } from "../runtime/runtime-isolation-lease.js";
6
7
  export interface SandboxRuntime {
7
8
  runOnce(dispatch: RunOnceDispatchPacket, sink: SessionEventSink, signal?: AbortSignal): Promise<RunOnceResultPacket>;
@@ -87,12 +88,18 @@ export type SandboxPublicationGrantRedeemer = (request: SandboxPublicationGrantR
87
88
  export declare class DockerSandboxRuntime implements SandboxRuntime {
88
89
  private readonly config;
89
90
  private readonly publicationGrantRedeemer?;
91
+ /** The host load governor; with it on, the sandbox's validation steps are brokered through it (decision 0013). */
92
+ private readonly hostLoadGate?;
90
93
  private readonly active;
91
94
  private readonly degraded;
92
95
  private readonly builds;
93
96
  private readonly verifiedCatalogImages;
94
97
  private buildTail;
95
- constructor(config: BridgeServiceConfig, publicationGrantRedeemer?: SandboxPublicationGrantRedeemer | undefined);
98
+ /** Shared with every sampler on the state root, so sandbox CPU is never external load. */
99
+ private readonly forgeCgroups;
100
+ constructor(config: BridgeServiceConfig, publicationGrantRedeemer?: SandboxPublicationGrantRedeemer | undefined,
101
+ /** The host load governor; with it on, the sandbox's validation steps are brokered through it (decision 0013). */
102
+ hostLoadGate?: HostLoadStepGate | undefined);
96
103
  runOnce(dispatch: RunOnceDispatchPacket, sink: SessionEventSink, signal?: AbortSignal): Promise<RunOnceResultPacket>;
97
104
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
98
105
  private pushLeaseUpdate;
@@ -133,6 +140,8 @@ export declare class DockerSandboxRuntime implements SandboxRuntime {
133
140
  private inspectImageMetadata;
134
141
  private startPeakMemorySampler;
135
142
  private docker;
143
+ /** The container's init process: stopping it stops every process in the sandbox. */
144
+ private containerInitProcess;
136
145
  private dockerArgs;
137
146
  }
138
147
  export declare function managedBranchUpdateExpectedValue(current: string, expectedInput: string, imported: string): string;
@@ -8,23 +8,37 @@ import { requireSandboxProcess, runSandboxProcess } from "./process.js";
8
8
  import { createLeaseUpdate } from "./lease-watchdog.js";
9
9
  import { evaluateSandboxImagePolicy, hasSandboxImagePolicyRecord, sandboxImagePolicyConfigurationDigest, verifySandboxImageSignature } from "./image-policy.js";
10
10
  import { SandboxEventBudget } from "./event-budget.js";
11
+ import { SandboxHostCapacityBroker, sandboxHostCapacityDeliveryExecArgs, withSandboxHostCapacityBroker, } from "./host-capacity-broker.js";
12
+ import { defaultHostLoadGovernorConfig } from "../runtime/host-load-governor-config.js";
13
+ import { captureHostProcessIdentity } from "../shared/process/host-process-supervisor.js";
14
+ import { FileForgeCgroupRegistry } from "../runtime/host-load-forge-cgroups.js";
15
+ import { trackSandboxCgroups } from "./sandbox-cgroups.js";
16
+ import { runtimeAdmissionPriority } from "../runtime/host-runtime-lease.js";
11
17
  import { RepositoryCoordinatorLock } from "./repository-lock.js";
12
18
  import { redactText } from "../shared/redaction/redaction.js";
13
19
  import { createRuntimeIsolationLease, renewRuntimeIsolationLease, transitionRuntimeIsolationLease, validRuntimeIsolationLease, withRuntimeIsolationResources, } from "../runtime/runtime-isolation-lease.js";
14
20
  import { sandboxProviderAuthAdapterFor, sandboxProviderAuthUnavailableMessage } from "./provider-auth/codex.js";
21
+ import { monotonicNowMs } from "../shared/time/monotonic.js";
15
22
  const managedLabel = "dev.forge.managed=true";
16
23
  const bridgeRuntimeDigestLabel = "dev.forge.bridge-runtime-digest";
17
24
  export class DockerSandboxRuntime {
18
25
  config;
19
26
  publicationGrantRedeemer;
27
+ hostLoadGate;
20
28
  active = new Map();
21
29
  degraded = new Set();
22
30
  builds = new Map();
23
31
  verifiedCatalogImages = new Set();
24
32
  buildTail = Promise.resolve();
25
- constructor(config, publicationGrantRedeemer) {
33
+ /** Shared with every sampler on the state root, so sandbox CPU is never external load. */
34
+ forgeCgroups;
35
+ constructor(config, publicationGrantRedeemer,
36
+ /** The host load governor; with it on, the sandbox's validation steps are brokered through it (decision 0013). */
37
+ hostLoadGate) {
26
38
  this.config = config;
27
39
  this.publicationGrantRedeemer = publicationGrantRedeemer;
40
+ this.hostLoadGate = hostLoadGate;
41
+ this.forgeCgroups = new FileForgeCgroupRegistry(config.sandboxStateRoot);
28
42
  }
29
43
  async runOnce(dispatch, sink, signal) {
30
44
  if (!dispatch.sandbox || dispatch.sandbox.executionMode !== "docker" || dispatch.sandbox.runtime !== "docker") {
@@ -152,7 +166,11 @@ export class DockerSandboxRuntime {
152
166
  await this.initializeEgressPolicy(builtImage.helperImageDigest, runtimeDispatch, resources, labels, runtimeSignal);
153
167
  const egressProxy = await this.startEgressProxy(runtimeDispatch, resources, labels, securityOptions, sink, runtimeSignal);
154
168
  const serviceContainers = await this.startServices(validated, runtimeDispatch.sandbox.executionPolicy, resources, labels, securityOptions, sink, runtimeSignal);
155
- const createArgs = workerCreateArgs(runtimeDispatch, validated, resources, labels, imageDigest, securityOptions);
169
+ const brokered = this.hostLoadGate?.enabled === true;
170
+ const workerArgs = workerCreateArgs(runtimeDispatch, validated, resources, labels, imageDigest, securityOptions);
171
+ const createArgs = brokered
172
+ ? withSandboxHostCapacityBroker(workerArgs, imageDigest, this.hostLoadGate.maxWaitMs ?? defaultHostLoadGovernorConfig.maxWaitMs)
173
+ : workerArgs;
156
174
  const createdContainer = await this.docker(createArgs, 60_000, runtimeSignal);
157
175
  const containerId = dockerObjectId(createdContainer.stdout, "container");
158
176
  await this.docker(["cp", prepared.bundlePath, `${containerId}:/control/input/repo.bundle`], 60_000, runtimeSignal);
@@ -182,6 +200,16 @@ export class DockerSandboxRuntime {
182
200
  runtimeLease: active.runtimeLease,
183
201
  }));
184
202
  const eventBudget = new SandboxEventBudget();
203
+ const hostCapacity = brokered
204
+ ? new SandboxHostCapacityBroker(this.hostLoadGate, runtimeDispatch.sandbox.dispatchAttemptId, runtimeAdmissionPriority(runtimeDispatch), async (response) => void await requireSandboxProcess({
205
+ command: this.config.dockerExecutable,
206
+ // As root, into the root-owned reply mount the sandbox user cannot write.
207
+ args: this.dockerArgs(sandboxHostCapacityDeliveryExecArgs(containerId)),
208
+ input: `${JSON.stringify(response)}\n`,
209
+ timeoutMs: 10_000,
210
+ maxOutputBytes: 16 * 1024,
211
+ }), { stepProcess: async () => await this.containerInitProcess(containerId) })
212
+ : null;
185
213
  const startPromise = runSandboxProcess({
186
214
  command: this.config.dockerExecutable,
187
215
  args: this.dockerArgs(["start", "--attach", "--interactive", containerId]),
@@ -197,6 +225,8 @@ export class DockerSandboxRuntime {
197
225
  signal: runtimeSignal,
198
226
  onStdoutLine: async (line) => {
199
227
  eventBudget.accept(line);
228
+ if (hostCapacity?.handleLine(line))
229
+ return;
200
230
  const streamedEvent = parseSandboxEventLine(line);
201
231
  if (streamedEvent) {
202
232
  if (streamedEvent.eventType === "provider_cli_started")
@@ -206,7 +236,14 @@ export class DockerSandboxRuntime {
206
236
  }
207
237
  });
208
238
  const memorySampler = this.startPeakMemorySampler(runtimeContainers);
239
+ // The sandbox's CPU is Forge's own work, not external load, for the governor.
240
+ const untrackCgroups = brokered
241
+ ? trackSandboxCgroups(this.forgeCgroups, runtimeDispatch.sandbox.dispatchAttemptId, runtimeContainers.map(container => container.id), async (ids) => (await this.docker(["inspect", "--format", "{{.State.Pid}}", ...ids], 10_000)).stdout)
242
+ : null;
209
243
  const start = await startPromise.finally(async () => {
244
+ // The worker exited: its queued and admitted host load tokens go back to the budget.
245
+ untrackCgroups?.();
246
+ await hostCapacity?.close();
210
247
  const telemetry = await memorySampler.stop();
211
248
  if (!telemetry)
212
249
  return;
@@ -554,10 +591,10 @@ export class DockerSandboxRuntime {
554
591
  const existing = this.builds.get(key);
555
592
  if (existing) {
556
593
  await sink.emit(event("sandbox_image_cache_miss", `Sandbox image ${key.slice(0, 12)} is being built by another dispatch.`, { cacheKey: key, singleflight: true }));
557
- const waitStartedAt = Date.now();
594
+ const waitStartedAt = monotonicNowMs();
558
595
  const built = await existing;
559
596
  await sink.emit(event("sandbox_build_singleflight_wait", `Waited for the existing sandbox image build ${key.slice(0, 12)}.`, {
560
- durationMs: Date.now() - waitStartedAt,
597
+ durationMs: Math.round(monotonicNowMs() - waitStartedAt),
561
598
  imageDigest: built.imageDigest
562
599
  }));
563
600
  return built;
@@ -889,8 +926,8 @@ export class DockerSandboxRuntime {
889
926
  await sink.emit(event("sandbox_image_signature_warning", `Image signature enforcement is not configured for adoption-mode image ${image}.`));
890
927
  }
891
928
  async waitForServiceHealthy(name, signal) {
892
- const deadline = Date.now() + 60_000;
893
- while (Date.now() < deadline) {
929
+ const deadline = monotonicNowMs() + 60_000;
930
+ while (monotonicNowMs() < deadline) {
894
931
  if (signal?.aborted)
895
932
  throw new Error(String(signal.reason ?? "sandbox service startup cancelled"));
896
933
  const status = (await this.docker(["container", "inspect", name, "--format", "{{.State.Health.Status}}"], 10_000, signal)).stdout.trim();
@@ -1104,6 +1141,13 @@ export class DockerSandboxRuntime {
1104
1141
  docker(args, timeoutMs, signal, maxOutputBytes = 1024 * 1024) {
1105
1142
  return requireSandboxProcess({ command: this.config.dockerExecutable, args: this.dockerArgs(args), timeoutMs, maxOutputBytes, signal });
1106
1143
  }
1144
+ /** The container's init process: stopping it stops every process in the sandbox. */
1145
+ async containerInitProcess(containerId) {
1146
+ const pid = Number((await this.docker(["inspect", "--format", "{{.State.Pid}}", containerId], 10_000)).stdout.trim());
1147
+ return Number.isSafeInteger(pid) && pid > 1
1148
+ ? { rootPid: pid, rootIdentity: captureHostProcessIdentity(pid), processGroup: false }
1149
+ : null;
1150
+ }
1107
1151
  dockerArgs(args) { return this.config.dockerContext ? ["--context", this.config.dockerContext, ...args] : [...args]; }
1108
1152
  }
1109
1153
  class HostGit {
@@ -0,0 +1,14 @@
1
+ import type { ForgeCgroupWriter } from "../runtime/host-load-forge-cgroups.js";
2
+ export type DockerInspectPids = (containerIds: readonly string[]) => Promise<string>;
3
+ /** Cgroup paths of the given containers' init processes; containers not yet running are skipped. */
4
+ export declare function sandboxContainerCgroupPaths(inspectPids: DockerInspectPids, containerIds: readonly string[], procRoot?: string): Promise<readonly string[]>;
5
+ /**
6
+ * Registers a sandbox's container cgroups once its containers are running,
7
+ * retrying briefly while the agent container starts. Returns a function that
8
+ * stops the retries and removes the registration.
9
+ */
10
+ export declare function trackSandboxCgroups(registry: ForgeCgroupWriter, owner: string, containerIds: readonly string[], inspectPids: DockerInspectPids, options?: {
11
+ readonly attempts?: number;
12
+ readonly intervalMs?: number;
13
+ readonly procRoot?: string;
14
+ }): () => void;
@@ -0,0 +1,42 @@
1
+ import fs from "node:fs/promises";
2
+ import { parseUnifiedCgroupPath } from "../runtime/host-pressure-stall.js";
3
+ /** Cgroup paths of the given containers' init processes; containers not yet running are skipped. */
4
+ export async function sandboxContainerCgroupPaths(inspectPids, containerIds, procRoot = "/proc") {
5
+ const output = await inspectPids(containerIds);
6
+ const paths = [];
7
+ for (const line of output.split(/\r?\n/u)) {
8
+ const pid = Number(line.trim());
9
+ if (!Number.isSafeInteger(pid) || pid <= 1)
10
+ continue;
11
+ const membership = await fs.readFile(`${procRoot}/${pid}/cgroup`, "utf8").catch(() => null);
12
+ const cgroupPath = membership ? parseUnifiedCgroupPath(membership) : null;
13
+ if (cgroupPath)
14
+ paths.push(cgroupPath);
15
+ }
16
+ return paths;
17
+ }
18
+ /**
19
+ * Registers a sandbox's container cgroups once its containers are running,
20
+ * retrying briefly while the agent container starts. Returns a function that
21
+ * stops the retries and removes the registration.
22
+ */
23
+ export function trackSandboxCgroups(registry, owner, containerIds, inspectPids, options = {}) {
24
+ let stopped = false;
25
+ void (async () => {
26
+ for (let attempt = 0; attempt < (options.attempts ?? 10) && !stopped; attempt += 1) {
27
+ await new Promise(resolve => setTimeout(resolve, options.intervalMs ?? 1_000));
28
+ if (stopped)
29
+ return;
30
+ const paths = await sandboxContainerCgroupPaths(inspectPids, containerIds, options.procRoot).catch(() => []);
31
+ if (stopped)
32
+ return;
33
+ registry.set(owner, paths);
34
+ if (paths.length >= containerIds.length)
35
+ return;
36
+ }
37
+ })();
38
+ return () => {
39
+ stopped = true;
40
+ registry.delete(owner);
41
+ };
42
+ }
@@ -1,6 +1,32 @@
1
1
  import { type NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
2
2
  export declare const managedAttemptToolNames: readonly ["forge.run_managed_command", "run_managed_command", "forge.start_managed_command", "start_managed_command", "forge.get_managed_command", "get_managed_command", "forge.wait_managed_command", "wait_managed_command", "forge.start_managed_verification", "start_managed_verification", "forge.reset_generated_outputs", "reset_generated_outputs"];
3
+ /**
4
+ * Stops every managed command this MCP server started, proves each process tree stopped,
5
+ * and writes their terminal receipts. Called when the provider closes the MCP connection
6
+ * or the server is signalled: once this server exits nothing could supervise them.
7
+ */
8
+ export declare function stopManagedCommandsForOwnerExit(): Promise<void>;
9
+ /** Test support: lets one test process act as a fresh MCP server after a simulated exit. */
10
+ export declare function resetManagedCommandOwnerShutdownForTesting(): void;
11
+ declare const ownerShutdownSignals: readonly ["SIGTERM", "SIGHUP", "SIGINT"];
12
+ export interface OwnerShutdownSignalTarget {
13
+ once(signal: (typeof ownerShutdownSignals)[number], listener: () => void): unknown;
14
+ removeListener(signal: (typeof ownerShutdownSignals)[number], listener: () => void): unknown;
15
+ }
16
+ /**
17
+ * Makes a termination signal stop this server's managed commands before it exits, so none
18
+ * outlives its only supervisor. Returns a function that removes the handlers.
19
+ */
20
+ export declare function installOwnerShutdownHandlers(target?: OwnerShutdownSignalTarget, exit?: (code: number) => void): () => void;
21
+ /**
22
+ * Runs an MCP server body, then stops every managed command it started before returning.
23
+ * The signal handlers stay installed until that stop completes: a signal during the body
24
+ * or the stop exits only after the same stop finishes, never by Node's default exit.
25
+ */
26
+ export declare function runWithOwnerShutdown<T>(body: () => Promise<T>, target?: OwnerShutdownSignalTarget, exit?: (code: number) => void): Promise<T>;
3
27
  export declare function isManagedAttemptTool(name: string): boolean;
28
+ /** The input schema a managed-attempt tool advertises; also the shape its arguments are coerced to. */
29
+ export declare function managedAttemptToolInputSchema(name: string): unknown;
4
30
  export declare function managedAttemptToolDefinition(name: string): unknown;
5
31
  export interface ManagedAttemptToolResult {
6
32
  readonly content: readonly {
@@ -26,3 +52,4 @@ export declare function playwrightProjectNamesFromConfigSource(source: string):
26
52
  */
27
53
  export declare function managedVerificationDatabaseEnvironment(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null): Promise<Readonly<Record<string, string>>>;
28
54
  export declare function isBuildProducingManagedCommand(command: string, args: readonly string[]): boolean;
55
+ export {};