@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0fedbc5c9ef7

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 (182) hide show
  1. package/README.md +89 -1
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
  5. package/dist/bridge/bridge-chat-provider-command.js +131 -26
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +11 -0
  11. package/dist/bridge/bridge-state-io.js +50 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.service.d.ts +19 -12
  17. package/dist/bridge/bridge.service.js +155 -282
  18. package/dist/bridge/bridge.types.d.ts +5 -0
  19. package/dist/bridge/in-flight-registry.d.ts +62 -0
  20. package/dist/bridge/in-flight-registry.js +207 -0
  21. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  22. package/dist/bridge/readiness-result-outbox.js +20 -0
  23. package/dist/bridge/runner-host-capabilities.js +14 -1
  24. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  25. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  26. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  27. package/dist/bridge/windows-bash-resolution.js +153 -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 +11 -1
  31. package/dist/cleanup/cleanup.service.js +80 -62
  32. package/dist/cleanup/cleanup.types.d.ts +2 -0
  33. package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
  34. package/dist/cleanup/host-runtime-ledger.js +30 -9
  35. package/dist/cli/cli.help.js +56 -12
  36. package/dist/cli/cli.service.d.ts +3 -10
  37. package/dist/cli/cli.service.js +10 -171
  38. package/dist/cli/idle-status.d.ts +84 -0
  39. package/dist/cli/idle-status.js +181 -0
  40. package/dist/cli/local-config.d.ts +2 -0
  41. package/dist/cli/local-config.js +7 -1
  42. package/dist/cli/provider-cli-detection.d.ts +10 -0
  43. package/dist/cli/provider-cli-detection.js +160 -0
  44. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  45. package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
  46. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  47. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  48. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  49. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  50. package/dist/runtime/attempt-process-supervisor.js +12 -6
  51. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  52. package/dist/runtime/docker-engine-probe.js +7 -0
  53. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  54. package/dist/runtime/dotnet-build-outputs.js +402 -0
  55. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  56. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  57. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  58. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  59. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  60. package/dist/runtime/host-listener-inspector.js +84 -3
  61. package/dist/runtime/host-load-admission.d.ts +5 -0
  62. package/dist/runtime/host-load-governor-config.d.ts +10 -1
  63. package/dist/runtime/host-load-governor-config.js +4 -1
  64. package/dist/runtime/host-load-governor.d.ts +10 -1
  65. package/dist/runtime/host-load-governor.js +33 -3
  66. package/dist/runtime/host-load-ledger-lock.js +6 -4
  67. package/dist/runtime/host-load-runtime-settings.js +4 -2
  68. package/dist/runtime/host-load-sampler.d.ts +8 -1
  69. package/dist/runtime/host-load-sampler.js +14 -7
  70. package/dist/runtime/host-load-test-slot.js +7 -0
  71. package/dist/runtime/host-runtime-contract.d.ts +12 -0
  72. package/dist/runtime/host-runtime-contract.js +29 -1
  73. package/dist/runtime/host-runtime-lease.d.ts +28 -3
  74. package/dist/runtime/host-runtime-lease.js +140 -296
  75. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  76. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  77. package/dist/runtime/host-runtime-promotion.d.ts +78 -2
  78. package/dist/runtime/host-runtime-promotion.js +307 -14
  79. package/dist/runtime/managed-command-teardown.js +5 -16
  80. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  81. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  82. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  83. package/dist/runtime/prepared-runtime-identity.js +130 -9
  84. package/dist/runtime/prepared-runtime-readiness.d.ts +13 -1
  85. package/dist/runtime/prepared-runtime-readiness.js +63 -16
  86. package/dist/runtime/runner-settings.d.ts +4 -0
  87. package/dist/runtime/runner-settings.js +22 -0
  88. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  89. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  90. package/dist/sandbox/host-capacity-broker.d.ts +3 -1
  91. package/dist/sandbox/host-capacity-broker.js +4 -2
  92. package/dist/sandbox/managed-branch.d.ts +13 -0
  93. package/dist/sandbox/managed-branch.js +90 -0
  94. package/dist/sandbox/provider-auth/codex.js +11 -11
  95. package/dist/sandbox/runtime.js +3 -7
  96. package/dist/session/managed-attempt-tools.d.ts +0 -7
  97. package/dist/session/managed-attempt-tools.js +50 -82
  98. package/dist/session/managed-build-coordinator.d.ts +16 -0
  99. package/dist/session/managed-build-coordinator.js +10 -0
  100. package/dist/session/managed-build-receipt.d.ts +5 -0
  101. package/dist/session/managed-build-receipt.js +8 -3
  102. package/dist/session/phase-completion.artifacts.js +2 -1
  103. package/dist/session/phase-completion.d.ts +8 -0
  104. package/dist/session/phase-completion.js +1 -0
  105. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  106. package/dist/session/phase-completion.mcp-args.js +156 -0
  107. package/dist/session/phase-completion.runtime.d.ts +0 -8
  108. package/dist/session/phase-completion.runtime.js +43 -197
  109. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  110. package/dist/session/pre-publication-native-postgres.js +111 -0
  111. package/dist/session/pre-publication-process.js +10 -10
  112. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  113. package/dist/session/pre-publication-step-execution.js +6 -5
  114. package/dist/session/pre-publication-validation.d.ts +7 -3
  115. package/dist/session/pre-publication-validation.js +32 -30
  116. package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
  117. package/dist/session/provider-cli/claude-background-work.js +4 -3
  118. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  119. package/dist/session/provider-cli/host-build-lock.js +30 -0
  120. package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
  121. package/dist/session/provider-cli/pre-publication-repair.js +33 -0
  122. package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
  123. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  124. package/dist/session/provider-cli/provider-cli.merge-integrity.js +28 -8
  125. package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
  126. package/dist/session/provider-cli/provider-cli.process.js +4 -94
  127. package/dist/session/provider-cli/provider-cli.prompts.d.ts +3 -0
  128. package/dist/session/provider-cli/provider-cli.prompts.js +27 -27
  129. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  130. package/dist/session/provider-cli/provider-cli.runtime.js +23 -2
  131. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  132. package/dist/session/provider-cli/provider-cli.service.js +27 -43
  133. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  134. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  135. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  136. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  137. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  138. package/dist/session/qa-sidecar-validation.js +28 -0
  139. package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
  140. package/dist/session/sandbox-host-capacity-gate.js +35 -16
  141. package/dist/session/session-redaction.js +31 -181
  142. package/dist/session/session.service.d.ts +6 -0
  143. package/dist/session/session.service.js +131 -88
  144. package/dist/session/session.types.d.ts +1 -0
  145. package/dist/session/session.types.js +3 -3
  146. package/dist/session/sidecar-json-shape.d.ts +31 -0
  147. package/dist/session/sidecar-json-shape.js +217 -0
  148. package/dist/shared/fs/file-identity.d.ts +10 -0
  149. package/dist/shared/fs/file-identity.js +15 -0
  150. package/dist/shared/fs/replace-file.d.ts +7 -0
  151. package/dist/shared/fs/replace-file.js +33 -0
  152. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  153. package/dist/shared/process/host-process-recovery.js +23 -3
  154. package/dist/shared/process/host-process-supervisor.d.ts +13 -1
  155. package/dist/shared/process/host-process-supervisor.js +66 -14
  156. package/dist/shared/provider-capabilities.js +9 -1
  157. package/dist/version.d.ts +1 -1
  158. package/dist/version.js +1 -1
  159. package/dist/worktree/orphan-relink.d.ts +19 -0
  160. package/dist/worktree/orphan-relink.js +106 -0
  161. package/dist/worktree/wip-git.d.ts +42 -0
  162. package/dist/worktree/wip-git.js +139 -0
  163. package/dist/worktree/wip-refs.d.ts +77 -0
  164. package/dist/worktree/wip-refs.js +146 -0
  165. package/dist/worktree/wip-restore.d.ts +46 -0
  166. package/dist/worktree/wip-restore.js +280 -0
  167. package/dist/worktree/wip-snapshot.d.ts +53 -0
  168. package/dist/worktree/wip-snapshot.js +270 -0
  169. package/dist/worktree/worktree-inputs.d.ts +8 -0
  170. package/dist/worktree/worktree-inputs.js +134 -0
  171. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  172. package/dist/worktree/worktree-origin-sync.js +128 -0
  173. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  174. package/dist/worktree/worktree-wip-events.js +115 -0
  175. package/dist/worktree/worktree-wip.d.ts +51 -0
  176. package/dist/worktree/worktree-wip.js +190 -0
  177. package/dist/worktree/worktree.base.d.ts +7 -1
  178. package/dist/worktree/worktree.service.d.ts +27 -5
  179. package/dist/worktree/worktree.service.js +112 -181
  180. package/dist/worktree/worktree.types.d.ts +35 -0
  181. package/package.json +1 -1
  182. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -0,0 +1,30 @@
1
+ import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
2
+ import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
3
+ import { type NativeTestPostgresFallback, type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
4
+ import type { RunnerDispatchEvent } from "./session.types.js";
5
+ /**
6
+ * A provisioned native test cluster whose file prefers it serves this check's shared
7
+ * test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
8
+ * first). Docker is still probed, never recovered, so the fixtures know whether
9
+ * pinned-engine tests can start their own containers. An unreadable file leaves the
10
+ * check on Docker.
11
+ */
12
+ export declare function preferredNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null, dockerEngineProbe: DockerEngineProbe | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>, startEphemeral?: typeof startEphemeralTestPostgresGrant): Promise<NativeTestPostgresGrant | undefined>;
13
+ /** Whether this check already has its isolated PostgreSQL without Docker. */
14
+ export declare function isolatedPostgresProvided(checkId: string, environment?: Readonly<Record<string, string>>, postgresAdminConnection?: NativeTestPostgresGrant): boolean;
15
+ /**
16
+ * The grant, when it makes its check Docker-free. A native_preferred grant still lets
17
+ * pinned-engine tests start Docker containers, so a Docker loss during its check stays
18
+ * retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
19
+ */
20
+ export declare function dockerFreeGrant(grant: NativeTestPostgresGrant | undefined): NativeTestPostgresGrant | undefined;
21
+ /**
22
+ * Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
23
+ * is left disowned for the next start's reap and does not change the check's own result.
24
+ */
25
+ export declare function releaseCheckPostgres(checkId: string, grant: NativeTestPostgresGrant | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>): Promise<void>;
26
+ /** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
27
+ export declare function dockerUnavailableNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null): NativeTestPostgresGrant | null;
28
+ export type { NativeTestPostgresFallback, NativeTestPostgresGrant };
29
+ /** Starts a check's ephemeral cluster; injectable so tests need no PostgreSQL install. */
30
+ export type StartEphemeralTestPostgresGrant = typeof startEphemeralTestPostgresGrant;
@@ -0,0 +1,111 @@
1
+ import path from "node:path";
2
+ import { attemptDatabaseCapabilityEnvironment } from "../runtime/attempt-database-broker.js";
3
+ import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
4
+ import { nativeTestPostgresFallbackDatabaseMode, nativeTestPostgresGrant, } from "../runtime/native-test-postgres-fallback.js";
5
+ import { validationEvent } from "./pre-publication-pass.js";
6
+ import { supportsNativeTestPostgresFallback } from "./pre-publication-step-execution.js";
7
+ // Which PostgreSQL a pre-publication check's isolated_postgres prerequisite is met by,
8
+ // before the validator falls back to waiting for Docker.
9
+ /**
10
+ * A provisioned native test cluster whose file prefers it serves this check's shared
11
+ * test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
12
+ * first). Docker is still probed, never recovered, so the fixtures know whether
13
+ * pinned-engine tests can start their own containers. An unreadable file leaves the
14
+ * check on Docker.
15
+ */
16
+ export async function preferredNativeTestPostgres(checkId, requiredPrerequisite, readCluster, dockerEngineProbe, emit, startEphemeral = startEphemeralTestPostgresGrant) {
17
+ if (requiredPrerequisite !== "isolated_postgres" || !supportsNativeTestPostgresFallback(checkId))
18
+ return undefined;
19
+ let configured;
20
+ try {
21
+ configured = readCluster();
22
+ }
23
+ catch (error) {
24
+ await emit?.(validationEvent("prepublication_prerequisite_native_invalid", checkId, `The native PostgreSQL test cluster configuration was refused, so '${checkId}' uses Docker: ${error instanceof Error ? error.message : String(error)}`));
25
+ return undefined;
26
+ }
27
+ if (configured?.use === "ephemeral") {
28
+ return await ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral);
29
+ }
30
+ if (configured?.use !== "preferred")
31
+ return undefined;
32
+ const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
33
+ const grant = nativeTestPostgresGrant(configured, dockerAvailable);
34
+ if (!grant)
35
+ return undefined;
36
+ await emit?.(validationEvent("prepublication_prerequisite_native_preferred", checkId, `Pre-publication check '${checkId}' is using the dedicated native PostgreSQL test cluster at ${grant.endpoint} with per-run owned databases${dockerAvailable
37
+ ? "; tests that need a pinned engine container still start one in Docker."
38
+ : ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
39
+ return grant;
40
+ }
41
+ /**
42
+ * A throwaway cluster of the check's own, whose superuser it holds (owner policy 2026-11-17).
43
+ * If it cannot start, the check falls back to Docker, and to the provisioned cluster only while
44
+ * Docker is down.
45
+ */
46
+ async function ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral) {
47
+ const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
48
+ let grant;
49
+ try {
50
+ grant = await startEphemeral(configured, dockerAvailable);
51
+ }
52
+ catch (error) {
53
+ await emit?.(validationEvent("prepublication_prerequisite_ephemeral_unavailable", checkId, `An ephemeral PostgreSQL test cluster could not start for '${checkId}', so it uses Docker: ${error instanceof Error ? error.message : String(error)}`));
54
+ return undefined;
55
+ }
56
+ try {
57
+ await emit?.(validationEvent("prepublication_prerequisite_native_ephemeral", checkId, `Pre-publication check '${checkId}' is using its own ephemeral PostgreSQL test cluster at ${grant.endpoint}, deleted when the check ends${dockerAvailable
58
+ ? "; tests that need a pinned engine container still start one in Docker."
59
+ : ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
60
+ }
61
+ catch (error) {
62
+ // The caller releases only a grant it receives, so a failed emit releases it here.
63
+ await grant.release?.().catch(() => undefined);
64
+ throw error;
65
+ }
66
+ return grant;
67
+ }
68
+ function environmentValue(environment, name) {
69
+ return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
70
+ ? environment?.[name]?.trim() ?? ""
71
+ : process.env[name]?.trim() ?? "";
72
+ }
73
+ /** Whether this check already has its isolated PostgreSQL without Docker. */
74
+ export function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
75
+ if (checkId === "playwright-e2e") {
76
+ const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
77
+ return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
78
+ || /^[0-9a-f-]{36}$/iu.test(attemptId))
79
+ && /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
80
+ && path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
81
+ // The attempt owns a database only once the Bridge's broker has issued it one.
82
+ && environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
83
+ }
84
+ return Boolean(postgresAdminConnection);
85
+ }
86
+ /**
87
+ * The grant, when it makes its check Docker-free. A native_preferred grant still lets
88
+ * pinned-engine tests start Docker containers, so a Docker loss during its check stays
89
+ * retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
90
+ */
91
+ export function dockerFreeGrant(grant) {
92
+ return grant?.mode === nativeTestPostgresFallbackDatabaseMode ? grant : undefined;
93
+ }
94
+ /**
95
+ * Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
96
+ * is left disowned for the next start's reap and does not change the check's own result.
97
+ */
98
+ export async function releaseCheckPostgres(checkId, grant, emit) {
99
+ try {
100
+ await grant?.release?.();
101
+ }
102
+ catch (error) {
103
+ await emit?.(validationEvent("prepublication_ephemeral_release_failed", checkId, `The ephemeral PostgreSQL test cluster for '${checkId}' could not be released and will be reaped later: ${error instanceof Error ? error.message : String(error)}`)).catch(() => undefined);
104
+ }
105
+ }
106
+ /** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
107
+ export function dockerUnavailableNativeTestPostgres(checkId, requiredPrerequisite, readCluster) {
108
+ return requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(checkId)
109
+ ? nativeTestPostgresGrant(readCluster(), false)
110
+ : null;
111
+ }
@@ -4,23 +4,26 @@ import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminE
4
4
  import { withoutHostLoadGovernorVariables } from "../runtime/host-load-child-environment.js";
5
5
  import { isSubPath } from "../shared/path/path.js";
6
6
  import { NodeProcessRunner, ProcessTreeTerminationError } from "../shared/process/process.js";
7
+ import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
7
8
  /** Output kept per stream for one validation step (the tail). */
8
9
  export const prePublicationOutputLimitChars = 4 * 1024 * 1024;
9
10
  export class ProcessPrePublicationCommandRunner {
10
11
  async run(command, args, cwd, signal, environment) {
11
12
  try {
12
13
  const launch = await pnpmDirectoryLaunch(command, args, cwd);
13
- const windowsBatch = process.platform === "win32" && (command === "npm" || command === "pnpm");
14
- const executable = windowsBatch ? (process.env.ComSpec ?? "cmd.exe") : command;
15
- const commandArgs = windowsBatch
16
- ? ["/d", "/s", "/c", [`${command}.cmd`, ...launch.args].map(quoteWindowsCommandArgument).join(" ")]
17
- : [...launch.args];
14
+ // npm and pnpm are batch files on Windows, run through cmd.exe. Its command line is
15
+ // passed verbatim: Node's own quoting escapes inner quotes as \", which cmd.exe does
16
+ // not read, so a quoted argument reached the package manager with its quotes.
17
+ const windowsBatch = process.platform === "win32" && (command === "npm" || command === "pnpm")
18
+ ? buildWindowsCmdLaunch(`${command}.cmd`, launch.args)
19
+ : null;
18
20
  // A process group the runner stops as a whole, settling only once it is gone:
19
21
  // a validation step's host capacity is never returned while its test hosts,
20
22
  // build nodes or browser workers still run.
21
23
  const result = await new NodeProcessRunner().run({
22
- command: executable,
23
- args: commandArgs,
24
+ command: windowsBatch?.command ?? command,
25
+ args: windowsBatch?.args ?? [...launch.args],
26
+ windowsVerbatimArguments: windowsBatch !== null,
24
27
  cwd: launch.cwd,
25
28
  env: prePublicationChildEnvironment(environment),
26
29
  rawOutput: true,
@@ -48,9 +51,6 @@ export class ProcessPrePublicationCommandRunner {
48
51
  }
49
52
  }
50
53
  }
51
- function quoteWindowsCommandArgument(value) {
52
- return /^[A-Za-z0-9_./:@=-]+$/u.test(value) ? value : `"${value.replaceAll('"', '""')}"`;
53
- }
54
54
  export function prePublicationChildEnvironment(environment) {
55
55
  const child = {};
56
56
  const privilegedNames = new Set([
@@ -1,3 +1,4 @@
1
+ import { type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
1
2
  import type { PrePublicationExecutionContext } from "./pre-publication-validation.js";
2
3
  export interface ValidationStep {
3
4
  readonly command: string;
@@ -8,4 +9,4 @@ export interface ValidationStep {
8
9
  }
9
10
  export declare function managedAttemptInvocation(checkId: string, step: ValidationStep, environment?: Readonly<Record<string, string>>): Pick<ValidationStep, "command" | "args">;
10
11
  export declare function supportsNativeTestPostgresFallback(checkId: string): boolean;
11
- export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?: string): PrePublicationExecutionContext | undefined;
12
+ export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?: NativeTestPostgresGrant): PrePublicationExecutionContext | undefined;
@@ -29,21 +29,22 @@ export function supportsNativeTestPostgresFallback(checkId) {
29
29
  return nativeFallbackCheckIds.has(checkId);
30
30
  }
31
31
  export function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
32
- // The connection only exists when Docker is unavailable and the operator
33
- // provisioned a dedicated native test cluster. Only the runner-authored
34
- // .NET test tiers and the suite-identity check receive it; build, client,
35
- // Bridge, and E2E steps never do.
32
+ // The grant only exists when the operator provisioned a dedicated native test
33
+ // cluster, and only the runner-authored .NET test tiers and the suite-identity
34
+ // check receive it; build, client, Bridge, and E2E steps never do.
36
35
  if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
37
36
  return execution;
38
37
  const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
39
38
  .some(script => argument.replaceAll("\\", "/").endsWith(script)));
40
39
  if (checkId !== "owned-suite-registration" && !runsDotnetTier)
41
40
  return execution;
41
+ // Re-validate the connection before it reaches attempt code.
42
+ parseNativeTestPostgresFallback(postgresAdminConnection.connectionString);
42
43
  return {
43
44
  ...execution,
44
45
  environment: {
45
46
  ...execution?.environment,
46
- ...nativeTestPostgresFallbackEnvironment(parseNativeTestPostgresFallback(postgresAdminConnection)),
47
+ ...nativeTestPostgresFallbackEnvironment(postgresAdminConnection),
47
48
  },
48
49
  };
49
50
  }
@@ -1,7 +1,7 @@
1
1
  import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
2
- import type { NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
3
2
  import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
4
3
  import { type PrePublicationHostLoadOwner } from "./pre-publication-host-load.js";
4
+ import { type NativeTestPostgresFallback, type StartEphemeralTestPostgresGrant } from "./pre-publication-native-postgres.js";
5
5
  import { type ValidationStep } from "./pre-publication-step-execution.js";
6
6
  import { PrePublicationValidationError, type PrePublicationCheckFailure } from "./pre-publication-pass.js";
7
7
  import type { ProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
@@ -56,7 +56,8 @@ export declare class PrePublicationValidator {
56
56
  private readonly dockerEngineProbe?;
57
57
  private readonly nativeTestPostgresFallback;
58
58
  private readonly hostLoad?;
59
- constructor(commands?: PrePublicationCommandRunner, dockerEngineProbe?: DockerEngineProbe | undefined, nativeTestPostgresFallback?: () => NativeTestPostgresFallback | null, hostLoad?: HostLoadStepGate | undefined);
59
+ private readonly startEphemeral?;
60
+ constructor(commands?: PrePublicationCommandRunner, dockerEngineProbe?: DockerEngineProbe | undefined, nativeTestPostgresFallback?: () => NativeTestPostgresFallback | null, hostLoad?: HostLoadStepGate | undefined, startEphemeral?: StartEphemeralTestPostgresGrant | undefined);
60
61
  /**
61
62
  * Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
62
63
  * can still meaningfully run keeps going, and the pass then throws all of its failures as one
@@ -66,13 +67,16 @@ export declare class PrePublicationValidator {
66
67
  private runChecks;
67
68
  /** Runs one check's steps in order; the first failed step ends the check, since later steps use its output. */
68
69
  private runCheck;
70
+ private runCheckSteps;
69
71
  /** Runs a step, confirming once a failure that matches a known transient pattern. */
70
72
  private runConfirmedStep;
71
73
  private runCheckedStep;
72
74
  private confirmStep;
73
75
  private confirmInfrastructure;
74
- /** Returns the native fallback connection when this check must use it instead of Docker. */
76
+ /** Returns the native cluster grant when this check uses it instead of Docker. */
75
77
  private ensurePrerequisite;
78
+ /** Waits for Docker; returns the native cluster grant when Docker stays down and a cluster is provisioned. */
79
+ private ensureDockerPrerequisite;
76
80
  private throwIfPrerequisiteWasLost;
77
81
  private checkTestOnlyExports;
78
82
  private changedPaths;
@@ -4,7 +4,8 @@ import path from "node:path";
4
4
  import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
5
5
  import { assertHostDatabaseCapabilityBoundary } from "../runtime/host-database-capability-boundary.js";
6
6
  import { runHostGovernedValidationStep } from "./pre-publication-host-load.js";
7
- import { managedAttemptInvocation, supportsNativeTestPostgresFallback, validationExecutionForStep, } from "./pre-publication-step-execution.js";
7
+ import { dockerFreeGrant, dockerUnavailableNativeTestPostgres, isolatedPostgresProvided, preferredNativeTestPostgres, releaseCheckPostgres, } from "./pre-publication-native-postgres.js";
8
+ import { managedAttemptInvocation, validationExecutionForStep, } from "./pre-publication-step-execution.js";
8
9
  import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
9
10
  import { redactText } from "../shared/redaction/redaction.js";
10
11
  import { PrePublicationPass, PrePublicationValidationError, SkippedTestTally, skippedCheckEvent, validationEvent, } from "./pre-publication-pass.js";
@@ -100,11 +101,13 @@ export class PrePublicationValidator {
100
101
  dockerEngineProbe;
101
102
  nativeTestPostgresFallback;
102
103
  hostLoad;
103
- constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad) {
104
+ startEphemeral;
105
+ constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad, startEphemeral) {
104
106
  this.commands = commands;
105
107
  this.dockerEngineProbe = dockerEngineProbe;
106
108
  this.nativeTestPostgresFallback = nativeTestPostgresFallback;
107
109
  this.hostLoad = hostLoad;
110
+ this.startEphemeral = startEphemeral;
108
111
  }
109
112
  /**
110
113
  * Runs one pre-publication pass. A failed check does not end the pass: every remaining check that
@@ -189,8 +192,16 @@ export class PrePublicationValidator {
189
192
  if (check.requiredCapability && !run.capabilities.has(check.requiredCapability)) {
190
193
  throw new ForgeFailureError("prepublication_capability_unavailable", `prepublication_capability_unavailable: ${check.id} requires ${check.requiredCapability}; publication is holding until a capable runner is available.`, "bridge");
191
194
  }
192
- const postgresAdminConnection = await this.ensurePrerequisite(check, run.execution?.environment, run.postgresAdminConnection, run.emit) ?? run.postgresAdminConnection;
193
- const stepRun = { ...run, check, postgresAdminConnection };
195
+ const granted = await this.ensurePrerequisite(check, run.execution?.environment, run.postgresAdminConnection, run.emit);
196
+ try {
197
+ return await this.runCheckSteps({ ...run, check, postgresAdminConnection: granted ?? run.postgresAdminConnection });
198
+ }
199
+ finally {
200
+ await releaseCheckPostgres(check.id, granted, run.emit);
201
+ }
202
+ }
203
+ async runCheckSteps(stepRun) {
204
+ const { check, ...run } = stepRun;
194
205
  await run.emit?.(validationEvent("prepublication_validation_started", check.id, `Running pre-publication CI parity check '${check.id}'.`));
195
206
  const skipped = new SkippedTestTally(run.worktreePath, run.execution?.environment);
196
207
  for (const step of check.steps) {
@@ -206,7 +217,11 @@ export class PrePublicationValidator {
206
217
  }
207
218
  await skipped.add(result.args, stepStartedMs);
208
219
  }
209
- await run.emit?.(skipped.passedEvent(check.id, validationExactSecrets(run.execution?.environment)));
220
+ // The check's own grant reaches only its steps' derived environments, so name its secrets too.
221
+ await run.emit?.(skipped.passedEvent(check.id, [
222
+ ...validationExactSecrets(run.execution?.environment),
223
+ ...attemptDatabaseCapabilitySecrets(run.postgresAdminConnection?.connectionString),
224
+ ]));
210
225
  return null;
211
226
  }
212
227
  /** Runs a step, confirming once a failure that matches a known transient pattern. */
@@ -255,7 +270,7 @@ export class PrePublicationValidator {
255
270
  await run.emit?.(validationEvent("prepublication_infrastructure_failed", checkId, `Pre-publication infrastructure for '${checkId}' remained unavailable${detail ? `: ${detail}` : "."}`));
256
271
  throw new PrePublicationInfrastructureError(checkId, result.exitCode, result.command, result.args, detail);
257
272
  }
258
- /** Returns the native fallback connection when this check must use it instead of Docker. */
273
+ /** Returns the native cluster grant when this check uses it instead of Docker. */
259
274
  async ensurePrerequisite(check, environment, postgresAdminConnection, emit) {
260
275
  if (check.requiredPrerequisite === "isolated_postgres"
261
276
  && isolatedPostgresProvided(check.id, environment, postgresAdminConnection)) {
@@ -264,6 +279,11 @@ export class PrePublicationValidator {
264
279
  : `Pre-publication check '${check.id}' is using the configured loopback PostgreSQL test server with per-run owned databases. No Docker daemon is required.`));
265
280
  return undefined;
266
281
  }
282
+ return await preferredNativeTestPostgres(check.id, check.requiredPrerequisite, this.nativeTestPostgresFallback, this.dockerEngineProbe, emit, this.startEphemeral)
283
+ ?? await this.ensureDockerPrerequisite(check, emit);
284
+ }
285
+ /** Waits for Docker; returns the native cluster grant when Docker stays down and a cluster is provisioned. */
286
+ async ensureDockerPrerequisite(check, emit) {
267
287
  if (check.requiredPrerequisite === undefined || !this.dockerEngineProbe)
268
288
  return undefined;
269
289
  const current = this.dockerEngineProbe.current();
@@ -275,12 +295,10 @@ export class PrePublicationValidator {
275
295
  const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
276
296
  if (!snapshot.available) {
277
297
  const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
278
- const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check.id)
279
- ? this.nativeTestPostgresFallback()
280
- : null;
298
+ const fallback = dockerUnavailableNativeTestPostgres(check.id, check.requiredPrerequisite, this.nativeTestPostgresFallback);
281
299
  if (fallback) {
282
300
  await emit?.(validationEvent("prepublication_prerequisite_native_fallback", check.id, `${detail}. Pre-publication check '${check.id}' is using the dedicated native PostgreSQL test cluster at ${fallback.endpoint} with per-run owned databases.`));
283
- return fallback.connectionString;
301
+ return fallback;
284
302
  }
285
303
  await emit?.(validationEvent("prepublication_prerequisite_unavailable", check.id, `Pre-publication check '${check.id}' is waiting for Docker infrastructure recovery: ${detail}`));
286
304
  throw new PrePublicationInfrastructureError(check.id, 75, "docker", ["info"], detail);
@@ -292,7 +310,7 @@ export class PrePublicationValidator {
292
310
  if (result.exitCode === 0
293
311
  || check.requiredPrerequisite === undefined
294
312
  || (check.requiredPrerequisite === "isolated_postgres"
295
- && isolatedPostgresProvided(check.id, environment, postgresAdminConnection))
313
+ && isolatedPostgresProvided(check.id, environment, dockerFreeGrant(postgresAdminConnection)))
296
314
  || !this.dockerEngineProbe)
297
315
  return;
298
316
  const snapshot = await this.dockerEngineProbe.refresh(true);
@@ -435,27 +453,11 @@ export class PrePublicationValidator {
435
453
  }
436
454
  }
437
455
  }
438
- function environmentValue(environment, name) {
439
- return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
440
- ? environment?.[name]?.trim() ?? ""
441
- : process.env[name]?.trim() ?? "";
442
- }
443
- function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
444
- if (checkId === "playwright-e2e") {
445
- const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
446
- return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
447
- || /^[0-9a-f-]{36}$/iu.test(attemptId))
448
- && /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
449
- && path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
450
- // The attempt owns a database only once the Bridge's broker has issued it one.
451
- && environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
452
- }
453
- return Boolean(postgresAdminConnection);
454
- }
455
456
  function validationExactSecrets(environment) {
456
457
  return [
457
- environment?.[hostRuntimeTestPostgresAdminEnvironment]?.trim() ?? "",
458
- environment?.[hostRuntimeLegacyTestPostgresEnvironment]?.trim() ?? "",
458
+ // The connection strings and their passwords: a test may print either.
459
+ ...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeTestPostgresAdminEnvironment]),
460
+ ...attemptDatabaseCapabilitySecrets(environment?.[hostRuntimeLegacyTestPostgresEnvironment]),
459
461
  environment?.[hostRuntimeTestPostgresProvisionerEnvironment]?.trim() ?? "",
460
462
  ...attemptDatabaseCapabilitySecrets(environment?.[attemptDatabaseCapabilityEnvironment]),
461
463
  ].filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
@@ -19,9 +19,10 @@ export declare const claudeHeadlessEnvironment: Readonly<Record<string, string>>
19
19
  export declare const claudeHeadlessDisallowedTools: readonly string[];
20
20
  /**
21
21
  * The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
22
- * again as flag settings, which outrank a user's or repository's settings `env` block.
22
+ * again as flag settings, which outrank a user's or repository's settings `env` block. Other flag
23
+ * settings (`provider-user-config-isolation.ts`) share the one `--settings` value.
23
24
  */
24
- export declare function claudeHeadlessToolArgs(): readonly string[];
25
+ export declare function claudeHeadlessToolArgs(additionalSettings?: Readonly<Record<string, unknown>>): readonly string[];
25
26
  /**
26
27
  * The provider ended its turn while background work it started (a background subagent or
27
28
  * shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
@@ -40,12 +40,13 @@ export const claudeHeadlessDisallowedTools = Object.freeze([
40
40
  ]);
41
41
  /**
42
42
  * The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
43
- * again as flag settings, which outrank a user's or repository's settings `env` block.
43
+ * again as flag settings, which outrank a user's or repository's settings `env` block. Other flag
44
+ * settings (`provider-user-config-isolation.ts`) share the one `--settings` value.
44
45
  */
45
- export function claudeHeadlessToolArgs() {
46
+ export function claudeHeadlessToolArgs(additionalSettings = {}) {
46
47
  return [
47
48
  "--disallowedTools", claudeHeadlessDisallowedTools.join(","),
48
- "--settings", JSON.stringify({ env: claudeHeadlessEnvironment }),
49
+ "--settings", JSON.stringify({ ...additionalSettings, env: claudeHeadlessEnvironment }),
49
50
  ];
50
51
  }
51
52
  /**
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A runner host can allow only one local .NET build or test at a time across everything that runs
3
+ * on it: Forge agents, the owner's own sessions and their tools. Parallel builds there exhaust
4
+ * memory and break each other's shared test output. The host's owner names the lock wrapper in the
5
+ * bridge's own environment; Forge passes it to every host-mode agent turn and Bridge Chat turn and
6
+ * tells the agent to run its .NET builds and tests through it. The rule reaches agents only from Forge, never from a
7
+ * user-level instruction file (provider-user-config-isolation.ts).
8
+ */
9
+ export declare const hostDotnetBuildLockVariable = "FORGE_HOST_DOTNET_BUILD_LOCK";
10
+ /** The host's .NET build lock wrapper, when the bridge's environment names one. */
11
+ export declare function hostDotnetBuildLock(environment?: NodeJS.ProcessEnv): string | null;
12
+ export declare function hostDotnetBuildLockEnvironment(environment?: NodeJS.ProcessEnv): Readonly<Record<string, string>>;
13
+ /**
14
+ * The runtime-context instruction for a host that names a .NET build lock, or an empty string.
15
+ * Session turns also hear that the commands Forge runs for them are scheduled by Forge; Bridge
16
+ * Chat turns have no Forge tools.
17
+ */
18
+ export declare function hostDotnetBuildLockInstruction(environment?: NodeJS.ProcessEnv, turn?: "session" | "chat"): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A runner host can allow only one local .NET build or test at a time across everything that runs
3
+ * on it: Forge agents, the owner's own sessions and their tools. Parallel builds there exhaust
4
+ * memory and break each other's shared test output. The host's owner names the lock wrapper in the
5
+ * bridge's own environment; Forge passes it to every host-mode agent turn and Bridge Chat turn and
6
+ * tells the agent to run its .NET builds and tests through it. The rule reaches agents only from Forge, never from a
7
+ * user-level instruction file (provider-user-config-isolation.ts).
8
+ */
9
+ export const hostDotnetBuildLockVariable = "FORGE_HOST_DOTNET_BUILD_LOCK";
10
+ /** The host's .NET build lock wrapper, when the bridge's environment names one. */
11
+ export function hostDotnetBuildLock(environment = process.env) {
12
+ return environment[hostDotnetBuildLockVariable]?.trim() || null;
13
+ }
14
+ export function hostDotnetBuildLockEnvironment(environment = process.env) {
15
+ const lock = hostDotnetBuildLock(environment);
16
+ return lock ? { [hostDotnetBuildLockVariable]: lock } : {};
17
+ }
18
+ /**
19
+ * The runtime-context instruction for a host that names a .NET build lock, or an empty string.
20
+ * Session turns also hear that the commands Forge runs for them are scheduled by Forge; Bridge
21
+ * Chat turns have no Forge tools.
22
+ */
23
+ export function hostDotnetBuildLockInstruction(environment = process.env, turn = "session") {
24
+ if (!hostDotnetBuildLock(environment))
25
+ return "";
26
+ const forgeScheduled = turn === "session"
27
+ ? " Commands Forge runs for you (`forge.start_managed_verification`, pre-publication checks) are scheduled by Forge."
28
+ : "";
29
+ return `\n- This host runs one local .NET build or test at a time. Run every \`dotnet build\` and \`dotnet test\` you start yourself through the host lock in \`${hostDotnetBuildLockVariable}\`, for example \`"$${hostDotnetBuildLockVariable}" dotnet test <project> --filter <tests>\`. It waits while another build or test holds the lock and exits 75 if the wait times out; wait and retry rather than running without it.${forgeScheduled}`;
30
+ }
@@ -1,5 +1,8 @@
1
1
  import { PrePublicationValidationError, type PrePublicationProfile, type PrePublicationValidator } from "../pre-publication-validation.js";
2
+ import { prepareCompletionToolRuntime } from "../phase-completion.js";
3
+ import { type RunOnceDispatchPacket } from "../session.types.js";
2
4
  import type { ProviderProcessRunner } from "./provider-cli.process.js";
5
+ import { buildProviderCliCommand } from "./provider-cli.prompts.js";
3
6
  import type { ProviderCliRunContext } from "./provider-cli.types.js";
4
7
  import { type ProviderOutputState } from "./provider-output-state.js";
5
8
  /**
@@ -37,4 +40,17 @@ export interface PrePublicationRepairDependencies {
37
40
  readonly runRepairTurn: (turn: PrePublicationRepairTurn) => Promise<void>;
38
41
  }
39
42
  export declare function validatePrePublicationWithRepair(options: PrePublicationRepairOptions, dependencies: PrePublicationRepairDependencies): Promise<void>;
43
+ /**
44
+ * The resumed command for one pre-publication repair turn. The main turn's Forge MCP server was
45
+ * cleaned up when that turn exited, so the repair turn gets its own: the managed-attempt tools its
46
+ * prompt directs long checks to, without the completion tools whose artifacts are already recorded.
47
+ * The caller owns the returned runtime and cleans it up when the turn exits.
48
+ */
49
+ export declare function prepareRepairTurnLaunch(context: ProviderCliRunContext, turn: PrePublicationRepairTurn): Promise<{
50
+ readonly repairDispatch: RunOnceDispatchPacket;
51
+ readonly providerPrompt: string;
52
+ readonly pipePromptToStdin: boolean;
53
+ readonly completionTools: Awaited<ReturnType<typeof prepareCompletionToolRuntime>>;
54
+ readonly command: ReturnType<typeof buildProviderCliCommand>;
55
+ }>;
40
56
  export declare function buildPrePublicationRepairPrompt(error: PrePublicationValidationError, repairTurn: number, maxRepairTurns: number, repairScope: "implementation" | "pull_request"): string;
@@ -2,7 +2,9 @@ import { HostPortCollisionError } from "../../runtime/host-port-broker.js";
2
2
  import { runtimeAdmissionPriority } from "../../runtime/host-runtime-lease.js";
3
3
  import { runtimeRestartCheckId } from "../pre-publication-pass.js";
4
4
  import { PrePublicationValidationError, } from "../pre-publication-validation.js";
5
+ import { prepareCompletionToolRuntime } from "../phase-completion.js";
5
6
  import { ForgeFailureError } from "../session.types.js";
7
+ import { buildProviderCliCommand, buildProviderCliPrompt, shouldPipePromptToStdin, usesManagedWindowsHost, } from "./provider-cli.prompts.js";
6
8
  import { prePublicationValidationEnv, providerProcessEnv } from "./provider-cli.runtime.js";
7
9
  import { clip } from "./provider-output-state.js";
8
10
  // Pre-publication validation with bounded in-place repair: each pass restarts the attempt's runtime
@@ -88,6 +90,37 @@ export async function validatePrePublicationWithRepair(options, dependencies) {
88
90
  });
89
91
  }
90
92
  }
93
+ /**
94
+ * The resumed command for one pre-publication repair turn. The main turn's Forge MCP server was
95
+ * cleaned up when that turn exited, so the repair turn gets its own: the managed-attempt tools its
96
+ * prompt directs long checks to, without the completion tools whose artifacts are already recorded.
97
+ * The caller owns the returned runtime and cleans it up when the turn exits.
98
+ */
99
+ export async function prepareRepairTurnLaunch(context, turn) {
100
+ const { dispatch, worktree } = context;
101
+ const { prompt: focusedPrompt, repairEnvironment } = turn;
102
+ const repairDispatch = {
103
+ ...dispatch,
104
+ session: { ...dispatch.session, resumeProviderThreadId: turn.providerThreadId },
105
+ };
106
+ const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
107
+ const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
108
+ const completionTools = await prepareCompletionToolRuntime({
109
+ dispatch: repairDispatch,
110
+ worktree,
111
+ runtimeEnvironment: repairEnvironment,
112
+ hostLoadEnvironment: context.hostLoadEnvironment,
113
+ managedToolsOnly: true,
114
+ });
115
+ const command = buildProviderCliCommand(repairDispatch, {
116
+ worktreePath: worktree.worktreePath,
117
+ prompt: focusedPrompt,
118
+ promptFromStdin: pipePromptToStdin,
119
+ completionTools,
120
+ runtimeEnvironment: repairEnvironment,
121
+ });
122
+ return { repairDispatch, providerPrompt, pipePromptToStdin, completionTools, command };
123
+ }
91
124
  /** Restarts the runtime stack if needed, then validates; returns every failure of the pass, or null. */
92
125
  async function runValidationPass(options, dependencies, environments, repairTurn) {
93
126
  const { context, validationProfile, preparedHeadSha } = options;
@@ -2,6 +2,9 @@ import os from "node:os";
2
2
  import { normalizeWindowsProviderEnvironment, windowsAllowedProviderParentEnvNames } from "./provider-cli.windows-environment.js";
3
3
  // The environment a provider child process starts with: an allowlist of the Bridge's own
4
4
  // variables, the request's values, the Windows defaults, then the .NET build-server settings.
5
+ // CLAUDE_CONFIG_DIR is not passed: it would point Claude Code at a user configuration directory
6
+ // of the host's choosing (provider-user-config-isolation.ts). Claude signs in from the provider
7
+ // home's default `.claude` directory under HOME or USERPROFILE, or with a Forge-granted API key.
5
8
  const allowedProviderParentEnvNames = [
6
9
  "PATH",
7
10
  "HOME",
@@ -9,8 +12,7 @@ const allowedProviderParentEnvNames = [
9
12
  "TMPDIR",
10
13
  "TEMP",
11
14
  "TMP",
12
- "LANG",
13
- "CLAUDE_CONFIG_DIR"
15
+ "LANG"
14
16
  ];
15
17
  export function buildProviderChildEnvironment(requestEnv, options = {}) {
16
18
  const parentEnv = options.parentEnv ?? process.env;
@@ -57,17 +57,20 @@ export declare class MergeResolutionUnresolvedConflictError extends ForgeFailure
57
57
  export declare function isMergeInProgress(git: GitRunner, worktreePath: string): Promise<boolean>;
58
58
  export declare function readInProgressMerge(git: GitRunner, worktreePath: string): Promise<InProgressMerge | null>;
59
59
  /**
60
- * Fails before `git add -A` can silently resolve a conflict:
60
+ * Fails before `git add -A` can silently resolve a conflict, during a merge or whenever the index
61
+ * holds unmerged paths without one (a WIP snapshot re-applied across a branch move that conflicted,
62
+ * see wip-restore.ts):
61
63
  * - a modify/delete conflict, by keeping whatever is on disk;
62
64
  * - a binary (or other marker-less) conflict, by staging whichever side is on disk;
63
65
  * - a content conflict, by staging its conflict markers. This includes markers
64
66
  * the provider already staged, which clears the unmerged stages, so every path
65
- * both sides changed is checked too.
67
+ * both sides of the merge changed is checked too, or without a merge every path
68
+ * the worktree's WIP re-apply conflict record lists.
66
69
  * A text conflict the agent resolved in the working tree without `git add` is
67
70
  * still unmerged here and is accepted once its markers are gone.
68
71
  */
69
72
  export declare function assertNoUnresolvedMergeConflicts(git: GitRunner, worktreePath: string): Promise<void>;
70
- export declare function readUnresolvedMergeConflicts(git: GitRunner, worktreePath: string, merge: InProgressMerge): Promise<readonly UnresolvedMergeConflict[]>;
73
+ export declare function readUnresolvedMergeConflicts(git: GitRunner, worktreePath: string, merge: InProgressMerge | null): Promise<readonly UnresolvedMergeConflict[]>;
71
74
  /**
72
75
  * Staging excludes some worktree changes (Forge runtime output) by unstaging them
73
76
  * back to HEAD. During a merge HEAD is the story side, so an excluded path the merge