@loucompanion/forge-bridge 0.1.4-dev.8901ba056f68 → 0.1.4-dev.894bcbd53d64

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 (225) hide show
  1. package/README.md +142 -1
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +132 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +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 +87 -14
  16. package/dist/bridge/bridge.service.js +394 -338
  17. package/dist/bridge/bridge.types.d.ts +16 -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 +3 -0
  25. package/dist/bridge/runner-host-capabilities.js +13 -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/cleanup/cleanup-wip.d.ts +12 -0
  29. package/dist/cleanup/cleanup-wip.js +66 -0
  30. package/dist/cleanup/cleanup.service.d.ts +20 -1
  31. package/dist/cleanup/cleanup.service.js +150 -169
  32. package/dist/cleanup/cleanup.types.d.ts +6 -0
  33. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  34. package/dist/cleanup/forge-owned-paths.js +53 -0
  35. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  36. package/dist/cleanup/host-runtime-ledger.js +130 -0
  37. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  38. package/dist/cleanup/managed-branch-sweep.js +111 -0
  39. package/dist/cli/cli.help.js +74 -12
  40. package/dist/cli/cli.service.d.ts +19 -10
  41. package/dist/cli/cli.service.js +149 -186
  42. package/dist/cli/idle-status.d.ts +84 -0
  43. package/dist/cli/idle-status.js +181 -0
  44. package/dist/cli/local-config.d.ts +6 -0
  45. package/dist/cli/local-config.js +32 -4
  46. package/dist/cli/provider-cli-detection.d.ts +10 -0
  47. package/dist/cli/provider-cli-detection.js +160 -0
  48. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  49. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  50. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  51. package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
  52. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  53. package/dist/runtime/attempt-process-supervisor.js +12 -6
  54. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  55. package/dist/runtime/docker-engine-probe.js +7 -0
  56. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  57. package/dist/runtime/dotnet-build-outputs.js +402 -0
  58. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  59. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  60. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  61. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  62. package/dist/runtime/host-facts.d.ts +2 -1
  63. package/dist/runtime/host-load-admission.d.ts +18 -3
  64. package/dist/runtime/host-load-admission.js +19 -4
  65. package/dist/runtime/host-load-child-environment.d.ts +11 -6
  66. package/dist/runtime/host-load-child-environment.js +22 -11
  67. package/dist/runtime/host-load-governor-config.d.ts +19 -1
  68. package/dist/runtime/host-load-governor-config.js +37 -0
  69. package/dist/runtime/host-load-governor.d.ts +14 -0
  70. package/dist/runtime/host-load-governor.js +139 -26
  71. package/dist/runtime/host-load-ledger-lock.js +6 -4
  72. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  73. package/dist/runtime/host-load-runtime-settings.js +80 -0
  74. package/dist/runtime/host-load-sampler.d.ts +34 -4
  75. package/dist/runtime/host-load-sampler.js +73 -7
  76. package/dist/runtime/host-load-step-class.d.ts +3 -1
  77. package/dist/runtime/host-load-step-class.js +60 -5
  78. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  79. package/dist/runtime/host-load-test-slot.js +81 -0
  80. package/dist/runtime/host-load-token-ledger.d.ts +26 -0
  81. package/dist/runtime/host-load-token-ledger.js +93 -61
  82. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  83. package/dist/runtime/host-load-windows-cpu.js +85 -0
  84. package/dist/runtime/host-runtime-contract.d.ts +12 -0
  85. package/dist/runtime/host-runtime-contract.js +29 -1
  86. package/dist/runtime/host-runtime-lease.d.ts +59 -3
  87. package/dist/runtime/host-runtime-lease.js +212 -61
  88. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  89. package/dist/runtime/host-runtime-promotion.js +36 -0
  90. package/dist/runtime/managed-command-teardown.js +5 -16
  91. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  92. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  93. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  94. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  95. package/dist/runtime/runner-settings.d.ts +104 -0
  96. package/dist/runtime/runner-settings.js +236 -0
  97. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  98. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  99. package/dist/sandbox/host-capacity-broker.d.ts +10 -2
  100. package/dist/sandbox/host-capacity-broker.js +27 -6
  101. package/dist/sandbox/managed-branch.d.ts +13 -0
  102. package/dist/sandbox/managed-branch.js +90 -0
  103. package/dist/sandbox/provider-auth/codex.js +11 -11
  104. package/dist/sandbox/runtime.js +2 -6
  105. package/dist/session/architect-waits.d.ts +2 -0
  106. package/dist/session/architect-waits.js +138 -0
  107. package/dist/session/managed-attempt-tools.d.ts +2 -7
  108. package/dist/session/managed-attempt-tools.js +94 -104
  109. package/dist/session/managed-build-coordinator.d.ts +16 -0
  110. package/dist/session/managed-build-coordinator.js +10 -0
  111. package/dist/session/managed-build-receipt.d.ts +5 -0
  112. package/dist/session/managed-build-receipt.js +8 -3
  113. package/dist/session/managed-command-host-load.d.ts +2 -0
  114. package/dist/session/managed-command-host-load.js +2 -1
  115. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  116. package/dist/session/mcp-argument-coercion.js +121 -0
  117. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  118. package/dist/session/phase-completion.artifacts.js +96 -26
  119. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  120. package/dist/session/phase-completion.command-validation.js +77 -0
  121. package/dist/session/phase-completion.d.ts +10 -0
  122. package/dist/session/phase-completion.helpers.js +13 -12
  123. package/dist/session/phase-completion.js +5 -0
  124. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  125. package/dist/session/phase-completion.mcp-args.js +156 -0
  126. package/dist/session/phase-completion.prompts.js +6 -1
  127. package/dist/session/phase-completion.runtime.d.ts +4 -10
  128. package/dist/session/phase-completion.runtime.js +77 -209
  129. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  130. package/dist/session/phase-completion.schema-parts.js +188 -0
  131. package/dist/session/phase-completion.schemas.d.ts +3 -3
  132. package/dist/session/phase-completion.schemas.js +208 -231
  133. package/dist/session/phase-completion.validation.d.ts +2 -3
  134. package/dist/session/phase-completion.validation.js +49 -93
  135. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  136. package/dist/session/pre-publication-native-postgres.js +111 -0
  137. package/dist/session/pre-publication-pass.d.ts +61 -0
  138. package/dist/session/pre-publication-pass.js +148 -0
  139. package/dist/session/pre-publication-process.js +10 -10
  140. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  141. package/dist/session/pre-publication-step-execution.js +6 -5
  142. package/dist/session/pre-publication-validation.d.ts +30 -14
  143. package/dist/session/pre-publication-validation.js +207 -134
  144. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  145. package/dist/session/provider-cli/claude-background-work.js +181 -0
  146. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  147. package/dist/session/provider-cli/host-build-lock.js +30 -0
  148. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  149. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  150. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  151. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  152. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  153. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  154. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  155. package/dist/session/provider-cli/provider-cli.process.js +39 -430
  156. package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
  157. package/dist/session/provider-cli/provider-cli.prompts.js +72 -32
  158. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  159. package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
  160. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  161. package/dist/session/provider-cli/provider-cli.service.js +78 -171
  162. package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
  163. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  164. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  165. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  166. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  167. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  168. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  169. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  170. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  171. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  172. package/dist/session/provider-cli/provider-output-state.js +6 -0
  173. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  174. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  175. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  176. package/dist/session/qa-sidecar-validation.js +28 -0
  177. package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
  178. package/dist/session/sandbox-host-capacity-gate.js +42 -14
  179. package/dist/session/session-redaction.js +31 -181
  180. package/dist/session/session.base.d.ts +6 -1
  181. package/dist/session/session.service.d.ts +9 -2
  182. package/dist/session/session.service.js +169 -66
  183. package/dist/session/session.types.js +4 -4
  184. package/dist/session/sidecar-json-shape.d.ts +31 -0
  185. package/dist/session/sidecar-json-shape.js +217 -0
  186. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  187. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  188. package/dist/shared/fs/file-identity.d.ts +10 -0
  189. package/dist/shared/fs/file-identity.js +15 -0
  190. package/dist/shared/fs/replace-file.d.ts +7 -0
  191. package/dist/shared/fs/replace-file.js +33 -0
  192. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  193. package/dist/shared/process/host-process-recovery.js +23 -3
  194. package/dist/shared/process/host-process-supervisor.d.ts +13 -1
  195. package/dist/shared/process/host-process-supervisor.js +66 -14
  196. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  197. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  198. package/dist/shared/process/windows-launch.d.ts +18 -0
  199. package/dist/shared/process/windows-launch.js +68 -0
  200. package/dist/shared/provider-capabilities.js +14 -7
  201. package/dist/version.d.ts +1 -1
  202. package/dist/version.js +1 -1
  203. package/dist/worktree/orphan-relink.d.ts +19 -0
  204. package/dist/worktree/orphan-relink.js +106 -0
  205. package/dist/worktree/wip-git.d.ts +33 -0
  206. package/dist/worktree/wip-git.js +122 -0
  207. package/dist/worktree/wip-refs.d.ts +62 -0
  208. package/dist/worktree/wip-refs.js +119 -0
  209. package/dist/worktree/wip-restore.d.ts +38 -0
  210. package/dist/worktree/wip-restore.js +190 -0
  211. package/dist/worktree/wip-snapshot.d.ts +50 -0
  212. package/dist/worktree/wip-snapshot.js +268 -0
  213. package/dist/worktree/worktree-inputs.d.ts +8 -0
  214. package/dist/worktree/worktree-inputs.js +134 -0
  215. package/dist/worktree/worktree-origin-sync.d.ts +34 -0
  216. package/dist/worktree/worktree-origin-sync.js +127 -0
  217. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  218. package/dist/worktree/worktree-wip-events.js +98 -0
  219. package/dist/worktree/worktree-wip.d.ts +50 -0
  220. package/dist/worktree/worktree-wip.js +185 -0
  221. package/dist/worktree/worktree.base.d.ts +7 -1
  222. package/dist/worktree/worktree.service.d.ts +31 -5
  223. package/dist/worktree/worktree.service.js +120 -163
  224. package/dist/worktree/worktree.types.d.ts +31 -0
  225. package/package.json +2 -2
@@ -0,0 +1,34 @@
1
+ import type os from "node:os";
2
+ import type { PressureStallResource } from "./host-pressure-stall.js";
3
+ /** Host CPU time summed over every logical CPU, in milliseconds, from os.cpus(). */
4
+ export interface CpuTimeTotals {
5
+ readonly busyMs: number;
6
+ readonly totalMs: number;
7
+ readonly cpuCount: number;
8
+ }
9
+ export type CpuTimesSource = readonly Partial<Pick<os.CpuInfo, "times">>[];
10
+ /**
11
+ * Host CPU use at which the estimate starts to report pressure. Waits for a CPU
12
+ * are rare below it on a many-core host. 0.6 puts the default backpressure
13
+ * threshold (50%) at 80% host CPU use, the default CPU budget.
14
+ */
15
+ export declare const windowsCpuPressureKnee = 0.6;
16
+ /** Busy is user + nice + sys + irq; idle is not busy. Null when any CPU lacks its times. */
17
+ export declare function cpuTimeTotals(cpus: CpuTimesSource): CpuTimeTotals | null;
18
+ /** Busy share of all logical CPUs (0-1) between two readings; null across a CPU count change or a counter reset. */
19
+ export declare function cpuUtilisation(previous: CpuTimeTotals | null, current: CpuTimeTotals | null): number | null;
20
+ /** Estimated share of wall time (percent) some runnable thread waited for a CPU, for one window. */
21
+ export declare function estimatedCpuStallPercent(utilisation: number): number;
22
+ /**
23
+ * Keeps 10/60/300-second exponentially decaying averages of the estimate, the
24
+ * way the kernel keeps PSI averages, so the governor's threshold and pressure
25
+ * streak read it exactly like PSI. The first window seeds every average, so a
26
+ * host already busy when the bridge starts reports pressure at once.
27
+ */
28
+ export declare class WindowsCpuPressureEstimator {
29
+ private averages;
30
+ /** Folds in one window of host CPU use lasting `elapsedMs`. */
31
+ update(utilisation: number, elapsedMs: number): PressureStallResource;
32
+ current(): PressureStallResource | null;
33
+ reset(): void;
34
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Host CPU use at which the estimate starts to report pressure. Waits for a CPU
3
+ * are rare below it on a many-core host. 0.6 puts the default backpressure
4
+ * threshold (50%) at 80% host CPU use, the default CPU budget.
5
+ */
6
+ export const windowsCpuPressureKnee = 0.6;
7
+ /** Busy is user + nice + sys + irq; idle is not busy. Null when any CPU lacks its times. */
8
+ export function cpuTimeTotals(cpus) {
9
+ if (cpus.length === 0)
10
+ return null;
11
+ let busyMs = 0;
12
+ let idleMs = 0;
13
+ for (const cpu of cpus) {
14
+ const times = cpu.times;
15
+ if (!times)
16
+ return null;
17
+ const values = [times.user, times.nice, times.sys, times.irq, times.idle];
18
+ if (!values.every(value => Number.isFinite(value) && value >= 0))
19
+ return null;
20
+ busyMs += times.user + times.nice + times.sys + times.irq;
21
+ idleMs += times.idle;
22
+ }
23
+ return { busyMs, totalMs: busyMs + idleMs, cpuCount: cpus.length };
24
+ }
25
+ /** Busy share of all logical CPUs (0-1) between two readings; null across a CPU count change or a counter reset. */
26
+ export function cpuUtilisation(previous, current) {
27
+ if (!previous || !current || previous.cpuCount !== current.cpuCount)
28
+ return null;
29
+ const totalDelta = current.totalMs - previous.totalMs;
30
+ const busyDelta = current.busyMs - previous.busyMs;
31
+ if (totalDelta <= 0 || busyDelta < 0)
32
+ return null;
33
+ return Math.min(1, busyDelta / totalDelta);
34
+ }
35
+ /** Estimated share of wall time (percent) some runnable thread waited for a CPU, for one window. */
36
+ export function estimatedCpuStallPercent(utilisation) {
37
+ const share = (utilisation - windowsCpuPressureKnee) / (1 - windowsCpuPressureKnee);
38
+ return Math.min(1, Math.max(0, share)) * 100;
39
+ }
40
+ const averageWindowsSeconds = { avg10: 10, avg60: 60, avg300: 300 };
41
+ /**
42
+ * Keeps 10/60/300-second exponentially decaying averages of the estimate, the
43
+ * way the kernel keeps PSI averages, so the governor's threshold and pressure
44
+ * streak read it exactly like PSI. The first window seeds every average, so a
45
+ * host already busy when the bridge starts reports pressure at once.
46
+ */
47
+ export class WindowsCpuPressureEstimator {
48
+ averages = null;
49
+ /** Folds in one window of host CPU use lasting `elapsedMs`. */
50
+ update(utilisation, elapsedMs) {
51
+ const stall = estimatedCpuStallPercent(utilisation);
52
+ const previous = this.averages;
53
+ this.averages = previous === null
54
+ ? { avg10: stall, avg60: stall, avg300: stall }
55
+ : {
56
+ avg10: decay(previous.avg10, stall, elapsedMs, averageWindowsSeconds.avg10),
57
+ avg60: decay(previous.avg60, stall, elapsedMs, averageWindowsSeconds.avg60),
58
+ avg300: decay(previous.avg300, stall, elapsedMs, averageWindowsSeconds.avg300),
59
+ };
60
+ return this.current();
61
+ }
62
+ current() {
63
+ if (!this.averages)
64
+ return null;
65
+ return {
66
+ some: {
67
+ avg10: roundPercent(this.averages.avg10),
68
+ avg60: roundPercent(this.averages.avg60),
69
+ avg300: roundPercent(this.averages.avg300),
70
+ },
71
+ // `full` (every runnable thread stalled) is not meaningful for CPU and is not estimated.
72
+ full: null,
73
+ };
74
+ }
75
+ reset() {
76
+ this.averages = null;
77
+ }
78
+ }
79
+ function decay(previous, sample, elapsedMs, windowSeconds) {
80
+ const weight = Math.exp(-Math.max(0, elapsedMs) / (windowSeconds * 1_000));
81
+ return sample + (previous - sample) * weight;
82
+ }
83
+ function roundPercent(value) {
84
+ return Math.round(value * 100) / 100;
85
+ }
@@ -57,6 +57,18 @@ export interface HostRuntimeDirectoryEntry {
57
57
  /** Returns one identity-bound directory inventory for runtime discovery. */
58
58
  export type HostRuntimeDirectorySnapshot = (target: string) => Promise<readonly HostRuntimeDirectoryEntry[]>;
59
59
  export declare function loadHostRuntimeContract(worktreePath: string, snapshot?: HostRuntimeSourceSnapshot, directorySnapshot?: HostRuntimeDirectorySnapshot): Promise<LoadedHostRuntimeContract>;
60
+ /** A managed attempt's own API master key: 32 random bytes, base64-encoded, as Security:MasterKey expects. */
61
+ export declare function newAttemptApiMasterKey(): string;
62
+ /**
63
+ * The environment a managed attempt's ASP.NET API launches with. When neither the launch profile
64
+ * nor the runtime contract configures Security__MasterKey or Security__MasterKeyFile, the API gets
65
+ * the attempt's own key. Otherwise ASP.NET Development falls back to the host user's dotnet
66
+ * user-secrets: the host's own key where they exist, and a failed secret write wherever they do not.
67
+ * The caller keeps one key for the attempt's whole life, so a restart against the same attempt
68
+ * database can still decrypt what was stored before it. The key is a secret: it is for the API
69
+ * process only, never for the environment handed to checks or providers.
70
+ */
71
+ export declare function withAttemptApiMasterKey(port: HostRuntimePortConfig, environment: Readonly<Record<string, string>>, attemptMasterKey: string): Readonly<Record<string, string>>;
60
72
  export declare function defaultHostRuntimeContract(): HostRuntimeContract;
61
73
  export declare function validateHostRuntimeContract(source: string): HostRuntimeContract;
62
74
  export declare function hostPortEnvironment(config: HostRuntimePortConfig, hostIp: "127.0.0.1", hostPort: number): Readonly<Record<string, string>>;
@@ -1,4 +1,4 @@
1
- import { createHash } from "node:crypto";
1
+ import { createHash, randomBytes } from "node:crypto";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { isAlias, parseDocument, visit } from "yaml";
@@ -425,6 +425,34 @@ function safeAspNetLaunchEnvironment(name, value) {
425
425
  "TMPDIR",
426
426
  ]).has(normalized);
427
427
  }
428
+ // The settings an ASP.NET API reads its secret-store master key from (Security:MasterKey wins).
429
+ const aspNetMasterKeySettings = ["security__masterkey", "security__masterkeyfile"];
430
+ /** A managed attempt's own API master key: 32 random bytes, base64-encoded, as Security:MasterKey expects. */
431
+ export function newAttemptApiMasterKey() {
432
+ return randomBytes(32).toString("base64");
433
+ }
434
+ /**
435
+ * The environment a managed attempt's ASP.NET API launches with. When neither the launch profile
436
+ * nor the runtime contract configures Security__MasterKey or Security__MasterKeyFile, the API gets
437
+ * the attempt's own key. Otherwise ASP.NET Development falls back to the host user's dotnet
438
+ * user-secrets: the host's own key where they exist, and a failed secret write wherever they do not.
439
+ * The caller keeps one key for the attempt's whole life, so a restart against the same attempt
440
+ * database can still decrypt what was stored before it. The key is a secret: it is for the API
441
+ * process only, never for the environment handed to checks or providers.
442
+ */
443
+ export function withAttemptApiMasterKey(port, environment, attemptMasterKey) {
444
+ if (port.adapter !== "aspnetcore")
445
+ return environment;
446
+ const masterKeySetting = (name) => aspNetMasterKeySettings.includes(name.toLowerCase());
447
+ if (Object.entries(environment).some(([name, value]) => masterKeySetting(name) && value.trim().length > 0)) {
448
+ return environment;
449
+ }
450
+ // A blank setting configures nothing; drop it so the attempt's key is the only one.
451
+ return {
452
+ ...Object.fromEntries(Object.entries(environment).filter(([name]) => !masterKeySetting(name))),
453
+ Security__MasterKey: attemptMasterKey,
454
+ };
455
+ }
428
456
  async function findFiles(root, accepts, maximumDepth, maximumEntries, snapshot) {
429
457
  const results = [];
430
458
  let examined = 0;
@@ -15,6 +15,7 @@ import { HostParallelPromotionStore } from "./host-runtime-promotion.js";
15
15
  import { type HostProcessRecovery } from "../shared/process/host-process-recovery.js";
16
16
  import { HostLoadGovernor } from "./host-load-governor.js";
17
17
  import { type HostLoadGovernorSource } from "./host-load-sampler.js";
18
+ import type { RunnerHostDefaults } from "./runner-settings.js";
18
19
  export interface HostRuntimeLeaseStart {
19
20
  readonly lease: RuntimeIsolationLease;
20
21
  readonly environment: Readonly<Record<string, string>>;
@@ -28,7 +29,7 @@ export interface HostRuntimeAdmissionCheckpoint {
28
29
  }
29
30
  export type HostRuntimeAdmissionCheckpointHandler = (checkpoint: HostRuntimeAdmissionCheckpoint) => void | Promise<void>;
30
31
  export interface HostRuntimeProjectCheckpoint {
31
- 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";
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";
32
33
  readonly message: string;
33
34
  readonly data?: Readonly<Record<string, unknown>>;
34
35
  }
@@ -96,10 +97,20 @@ export interface HostNodeRuntimeLaunch<T> extends NodeRuntimeAdapterLaunch<T> {
96
97
  }
97
98
  export interface HostRuntimeLeaseRuntime {
98
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;
99
104
  acquirePreparation?(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
100
105
  acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
101
106
  start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
102
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>;
103
114
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
104
115
  providerProcessRunner?(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
105
116
  providerMemoryTelemetry?(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
@@ -147,15 +158,25 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
147
158
  private workspaceAvailableBytes;
148
159
  private readonly portBroker;
149
160
  private readonly nodeAdapter;
150
- private readonly capacityConfiguration;
161
+ /** Rebuilt by applyCapacityLimits (decision 0014); every admission reads the current one. */
162
+ private capacityConfiguration;
151
163
  private readonly memoryAvailability;
152
164
  private readonly executionRoot;
153
- /** Host-wide admission for heavy steps (decision 0013); inert unless FORGE_HOST_LOAD_GOVERNOR=on. */
165
+ /** Host-wide admission for heavy steps (decisions 0013, 0018): the host test slot, and the budget when on. */
154
166
  readonly hostLoadGovernor: HostLoadGovernor;
155
167
  private requirementsCheck;
156
168
  /** Installs the decision 0013 accept-time requirements recheck for host attempts. */
157
169
  setRequirementsCheck(check: HostRequirementsCheck | null): void;
158
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;
159
180
  hostLoadChildEnvironment(): Readonly<Record<string, string>>;
160
181
  reap(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
161
182
  snapshot(): HostRuntimeCapacitySnapshot;
@@ -178,6 +199,24 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
178
199
  start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
179
200
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
180
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;
181
220
  providerProcessRunner(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
182
221
  private markCapacityReservationRunning;
183
222
  providerMemoryTelemetry(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
@@ -228,4 +267,21 @@ export declare class HostRuntimeCapacityRequestImpossibleError extends Error {
228
267
  }
229
268
  export declare function hostRuntimeEventResources(lease: RuntimeIsolationLease, runtimeContract?: LoadedHostRuntimeContract, executionClass?: HostRuntimeExecutionClass): Record<string, unknown>;
230
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[];
231
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;