@loucompanion/forge-bridge 0.1.4-dev.86fc5d1208e6 → 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 (269) hide show
  1. package/README.md +144 -3
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +132 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +10 -0
  5. package/dist/bridge/bridge-chat.types.js +16 -1
  6. package/dist/bridge/bridge-state-file.d.ts +161 -0
  7. package/dist/bridge/bridge-state-file.js +376 -0
  8. package/dist/bridge/bridge-state-io.d.ts +11 -0
  9. package/dist/bridge/bridge-state-io.js +50 -0
  10. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  11. package/dist/bridge/bridge-state-lock.js +102 -0
  12. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  13. package/dist/bridge/bridge-state-unpublished.js +111 -0
  14. package/dist/bridge/bridge.base.d.ts +9 -0
  15. package/dist/bridge/bridge.service.d.ts +101 -15
  16. package/dist/bridge/bridge.service.js +472 -345
  17. package/dist/bridge/bridge.types.d.ts +27 -0
  18. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  19. package/dist/bridge/dispatch-result-outbox.js +31 -6
  20. package/dist/bridge/in-flight-registry.d.ts +62 -0
  21. package/dist/bridge/in-flight-registry.js +207 -0
  22. package/dist/bridge/local-yield-flag.d.ts +6 -0
  23. package/dist/bridge/local-yield-flag.js +34 -0
  24. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  25. package/dist/bridge/readiness-result-outbox.js +20 -0
  26. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  27. package/dist/bridge/runner-host-capabilities.js +17 -0
  28. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  29. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  30. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  31. package/dist/bridge/test-postgres-capability.js +120 -0
  32. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  33. package/dist/cleanup/cleanup-wip.js +66 -0
  34. package/dist/cleanup/cleanup.service.d.ts +20 -1
  35. package/dist/cleanup/cleanup.service.js +150 -169
  36. package/dist/cleanup/cleanup.types.d.ts +6 -0
  37. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  38. package/dist/cleanup/forge-owned-paths.js +53 -0
  39. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  40. package/dist/cleanup/host-runtime-ledger.js +130 -0
  41. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  42. package/dist/cleanup/managed-branch-sweep.js +111 -0
  43. package/dist/cli/cli.help.js +74 -12
  44. package/dist/cli/cli.service.d.ts +19 -10
  45. package/dist/cli/cli.service.js +152 -187
  46. package/dist/cli/idle-status.d.ts +84 -0
  47. package/dist/cli/idle-status.js +181 -0
  48. package/dist/cli/local-config.d.ts +6 -0
  49. package/dist/cli/local-config.js +32 -4
  50. package/dist/cli/provider-cli-detection.d.ts +10 -0
  51. package/dist/cli/provider-cli-detection.js +160 -0
  52. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  53. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  54. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  55. package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
  56. package/dist/runtime/attempt-process-supervisor.d.ts +21 -0
  57. package/dist/runtime/attempt-process-supervisor.js +62 -6
  58. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  59. package/dist/runtime/docker-engine-probe.js +7 -0
  60. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  61. package/dist/runtime/dotnet-build-outputs.js +402 -0
  62. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  63. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  64. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  65. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  66. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  67. package/dist/runtime/host-database-capability-boundary.js +1 -0
  68. package/dist/runtime/host-facts.d.ts +36 -0
  69. package/dist/runtime/host-facts.js +95 -0
  70. package/dist/runtime/host-load-admission.d.ts +67 -0
  71. package/dist/runtime/host-load-admission.js +99 -0
  72. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  73. package/dist/runtime/host-load-child-environment.js +76 -0
  74. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  75. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  76. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  77. package/dist/runtime/host-load-governor-config.js +83 -0
  78. package/dist/runtime/host-load-governor.d.ts +186 -0
  79. package/dist/runtime/host-load-governor.js +632 -0
  80. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  81. package/dist/runtime/host-load-ledger-lock.js +187 -0
  82. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  83. package/dist/runtime/host-load-runtime-settings.js +80 -0
  84. package/dist/runtime/host-load-sampler.d.ts +156 -0
  85. package/dist/runtime/host-load-sampler.js +298 -0
  86. package/dist/runtime/host-load-step-class.d.ts +70 -0
  87. package/dist/runtime/host-load-step-class.js +161 -0
  88. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  89. package/dist/runtime/host-load-step-reaper.js +95 -0
  90. package/dist/runtime/host-load-step-run.d.ts +73 -0
  91. package/dist/runtime/host-load-step-run.js +102 -0
  92. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  93. package/dist/runtime/host-load-test-slot.js +81 -0
  94. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  95. package/dist/runtime/host-load-token-ledger.js +453 -0
  96. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  97. package/dist/runtime/host-load-windows-cpu.js +85 -0
  98. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  99. package/dist/runtime/host-pressure-stall.js +168 -0
  100. package/dist/runtime/host-runtime-contract.d.ts +16 -0
  101. package/dist/runtime/host-runtime-contract.js +35 -2
  102. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  103. package/dist/runtime/host-runtime-lease.js +343 -67
  104. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  105. package/dist/runtime/host-runtime-promotion.js +48 -0
  106. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  107. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  108. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  109. package/dist/runtime/host-runtime-requirements.js +117 -0
  110. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  111. package/dist/runtime/managed-command-teardown.js +596 -0
  112. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  113. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  114. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  115. package/dist/runtime/playwright-browser-cache.js +227 -0
  116. package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
  117. package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
  118. package/dist/runtime/runner-settings.d.ts +104 -0
  119. package/dist/runtime/runner-settings.js +236 -0
  120. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  121. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  122. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  123. package/dist/sandbox/host-capacity-broker.js +336 -0
  124. package/dist/sandbox/managed-branch.d.ts +13 -0
  125. package/dist/sandbox/managed-branch.js +90 -0
  126. package/dist/sandbox/provider-auth/codex.js +11 -11
  127. package/dist/sandbox/runtime.d.ts +10 -1
  128. package/dist/sandbox/runtime.js +47 -8
  129. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  130. package/dist/sandbox/sandbox-cgroups.js +42 -0
  131. package/dist/session/architect-waits.d.ts +2 -0
  132. package/dist/session/architect-waits.js +138 -0
  133. package/dist/session/managed-attempt-tools.d.ts +27 -7
  134. package/dist/session/managed-attempt-tools.js +406 -123
  135. package/dist/session/managed-build-coordinator.d.ts +17 -1
  136. package/dist/session/managed-build-coordinator.js +14 -1
  137. package/dist/session/managed-build-receipt.d.ts +5 -0
  138. package/dist/session/managed-build-receipt.js +8 -3
  139. package/dist/session/managed-command-host-load.d.ts +47 -0
  140. package/dist/session/managed-command-host-load.js +83 -0
  141. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  142. package/dist/session/mcp-argument-coercion.js +121 -0
  143. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  144. package/dist/session/phase-completion.artifacts.js +100 -26
  145. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  146. package/dist/session/phase-completion.command-validation.js +77 -0
  147. package/dist/session/phase-completion.d.ts +12 -0
  148. package/dist/session/phase-completion.helpers.js +13 -12
  149. package/dist/session/phase-completion.js +5 -0
  150. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  151. package/dist/session/phase-completion.mcp-args.js +156 -0
  152. package/dist/session/phase-completion.prompts.js +6 -1
  153. package/dist/session/phase-completion.runtime.d.ts +5 -11
  154. package/dist/session/phase-completion.runtime.js +111 -230
  155. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  156. package/dist/session/phase-completion.schema-parts.js +188 -0
  157. package/dist/session/phase-completion.schemas.d.ts +3 -3
  158. package/dist/session/phase-completion.schemas.js +208 -231
  159. package/dist/session/phase-completion.validation.d.ts +2 -3
  160. package/dist/session/phase-completion.validation.js +49 -93
  161. package/dist/session/pre-publication-host-load.d.ts +27 -0
  162. package/dist/session/pre-publication-host-load.js +111 -0
  163. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  164. package/dist/session/pre-publication-native-postgres.js +111 -0
  165. package/dist/session/pre-publication-pass.d.ts +61 -0
  166. package/dist/session/pre-publication-pass.js +148 -0
  167. package/dist/session/pre-publication-process.d.ts +23 -0
  168. package/dist/session/pre-publication-process.js +109 -0
  169. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  170. package/dist/session/pre-publication-skipped-tests.js +109 -0
  171. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  172. package/dist/session/pre-publication-step-execution.js +50 -0
  173. package/dist/session/pre-publication-validation.d.ts +37 -21
  174. package/dist/session/pre-publication-validation.js +228 -219
  175. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  176. package/dist/session/provider-cli/claude-background-work.js +181 -0
  177. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  178. package/dist/session/provider-cli/host-build-lock.js +30 -0
  179. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  180. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  181. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  182. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  183. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  184. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  185. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  186. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  187. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  188. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  189. package/dist/session/provider-cli/provider-cli.process.d.ts +46 -31
  190. package/dist/session/provider-cli/provider-cli.process.js +286 -403
  191. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  192. package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
  193. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  194. package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
  195. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  196. package/dist/session/provider-cli/provider-cli.service.js +207 -192
  197. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  198. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  199. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  200. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  201. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  202. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  203. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  204. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  205. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  206. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  207. package/dist/session/provider-cli/provider-output-state.js +15 -0
  208. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  209. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  210. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  211. package/dist/session/publishable-worktree-changes.js +193 -0
  212. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  213. package/dist/session/qa-sidecar-validation.js +28 -0
  214. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  215. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  216. package/dist/session/session-redaction.js +31 -181
  217. package/dist/session/session.base.d.ts +9 -1
  218. package/dist/session/session.service.d.ts +11 -2
  219. package/dist/session/session.service.js +189 -69
  220. package/dist/session/session.types.d.ts +3 -0
  221. package/dist/session/session.types.js +15 -3
  222. package/dist/session/sidecar-json-shape.d.ts +31 -0
  223. package/dist/session/sidecar-json-shape.js +217 -0
  224. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  225. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  226. package/dist/shared/fs/file-identity.d.ts +10 -0
  227. package/dist/shared/fs/file-identity.js +15 -0
  228. package/dist/shared/fs/replace-file.d.ts +7 -0
  229. package/dist/shared/fs/replace-file.js +33 -0
  230. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  231. package/dist/shared/process/host-process-recovery.js +23 -3
  232. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  233. package/dist/shared/process/host-process-supervisor.js +67 -15
  234. package/dist/shared/process/process-tree.d.ts +52 -0
  235. package/dist/shared/process/process-tree.js +144 -0
  236. package/dist/shared/process/process.d.ts +67 -0
  237. package/dist/shared/process/process.js +213 -11
  238. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  239. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  240. package/dist/shared/process/windows-launch.d.ts +18 -0
  241. package/dist/shared/process/windows-launch.js +68 -0
  242. package/dist/shared/provider-capabilities.js +14 -7
  243. package/dist/version.d.ts +1 -1
  244. package/dist/version.js +1 -1
  245. package/dist/worktree/dependency-warmer.d.ts +25 -0
  246. package/dist/worktree/dependency-warmer.js +120 -10
  247. package/dist/worktree/orphan-relink.d.ts +19 -0
  248. package/dist/worktree/orphan-relink.js +106 -0
  249. package/dist/worktree/wip-git.d.ts +33 -0
  250. package/dist/worktree/wip-git.js +122 -0
  251. package/dist/worktree/wip-refs.d.ts +62 -0
  252. package/dist/worktree/wip-refs.js +119 -0
  253. package/dist/worktree/wip-restore.d.ts +38 -0
  254. package/dist/worktree/wip-restore.js +190 -0
  255. package/dist/worktree/wip-snapshot.d.ts +50 -0
  256. package/dist/worktree/wip-snapshot.js +268 -0
  257. package/dist/worktree/worktree-inputs.d.ts +8 -0
  258. package/dist/worktree/worktree-inputs.js +134 -0
  259. package/dist/worktree/worktree-origin-sync.d.ts +34 -0
  260. package/dist/worktree/worktree-origin-sync.js +127 -0
  261. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  262. package/dist/worktree/worktree-wip-events.js +98 -0
  263. package/dist/worktree/worktree-wip.d.ts +50 -0
  264. package/dist/worktree/worktree-wip.js +185 -0
  265. package/dist/worktree/worktree.base.d.ts +7 -1
  266. package/dist/worktree/worktree.service.d.ts +36 -5
  267. package/dist/worktree/worktree.service.js +124 -155
  268. package/dist/worktree/worktree.types.d.ts +38 -0
  269. package/package.json +2 -2
@@ -1,20 +1,25 @@
1
1
  import fs from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
5
4
  import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
6
- import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, isDevelopCompletionPhase, normalizedOwnerType, parseCompletionRedactionSecrets, parseOptionalJsonObject, parseStrictCompletionPhase, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeFileAtomic, writeJsonRpc } from "./phase-completion.validation.js";
5
+ import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, normalizedOwnerType, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeJsonRpc } from "./phase-completion.validation.js";
7
6
  import { completionPromptForDebugCycle, completionPromptForDecomposeCycle, completionPromptForDevelopCycle, completionPromptForDraftCycle, completionPromptForPhase, completionPromptForQaCycle, completionToolNextInstruction, completionToolNextInstructionForDebugGate, completionToolNextInstructionForDecomposeGate, completionToolNextInstructionForDraftGate, completionToolNextInstructionForQaGate, nextDebugPhaseAfter, nextPhaseAfter } from "./phase-completion.prompts.js";
8
7
  import { configuredNativeTestPostgresFallbackPath, nativeTestPostgresFallbackConfigEnvironment, } from "../runtime/native-test-postgres-fallback.js";
8
+ import { isHostLoadChildEnvironmentName } from "../runtime/host-load-child-environment.js";
9
+ import { isProviderUserConfigIsolated, providerUserConfigIsolationUnsupported } from "./provider-cli/provider-user-config-isolation.js";
9
10
  import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
11
+ import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
10
12
  import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
11
- import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolNames, } from "./managed-attempt-tools.js";
13
+ import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
14
+ import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
12
15
  export async function prepareCompletionToolRuntime(options) {
13
16
  const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
14
17
  const worktreePath = path.resolve(options.worktree.worktreePath);
15
18
  const workItemId = options.dispatch.workItem.id;
16
19
  const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
17
20
  const ownerId = options.dispatch.cycleRun.ownerId ?? workItemId;
21
+ // A managed-tools-only server records no completion artifact, so it takes no cycle mode.
22
+ const cycles = !options.managedToolsOnly;
18
23
  const mcpArgs = buildCompletionToolServerArgs({
19
24
  worktreePath,
20
25
  workItemId,
@@ -22,68 +27,36 @@ export async function prepareCompletionToolRuntime(options) {
22
27
  ownerId,
23
28
  phase,
24
29
  producedBy: `${options.dispatch.execution.provider}-cli`,
25
- developCycle: usesDevelopCycleCompletion(options.dispatch),
26
- qaCycle: usesQaCycleCompletion(options.dispatch),
27
- debugCycle: usesDebugCycleCompletion(options.dispatch),
28
- architectCycle: usesArchitectCycleCompletion(options.dispatch),
29
- draftCycle: (phase === "draft"
30
- || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
31
- || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
30
+ managedToolsOnly: options.managedToolsOnly,
31
+ developCycle: cycles && usesDevelopCycleCompletion(options.dispatch),
32
+ qaCycle: cycles && usesQaCycleCompletion(options.dispatch),
33
+ debugCycle: cycles && usesDebugCycleCompletion(options.dispatch),
34
+ architectCycle: cycles && usesArchitectCycleCompletion(options.dispatch),
35
+ draftCycle: cycles
36
+ && (phase === "draft"
37
+ || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
38
+ || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
32
39
  && !isDecomposeDispatch(options.dispatch),
33
- decomposeCycle: isDecomposeDispatch(options.dispatch)
40
+ decomposeCycle: cycles && isDecomposeDispatch(options.dispatch)
34
41
  });
35
42
  const runtime = {
36
43
  serverName: toolServerName,
37
44
  command: process.execPath,
38
45
  args: [forgeBridgeCliBinPath(), ...mcpArgs],
39
- env: completionToolRuntimeEnvironment(options.runtimeEnvironment, configuredNativeTestPostgresFallbackPath()),
46
+ env: completionToolRuntimeEnvironment(options.runtimeEnvironment, configuredNativeTestPostgresFallbackPath(), options.hostLoadEnvironment),
40
47
  cleanup: async () => undefined
41
48
  };
42
49
  const provider = options.dispatch.execution.provider.trim().toLowerCase();
43
- if (provider === "cursor") {
44
- return await prepareCursorCompletionToolRuntime(worktreePath, runtime);
50
+ // Provider phases refuse these at entry (admitUserConfigIsolatedProvider, provider-cli.runtime.ts);
51
+ // this guards any other caller before the Claude MCP config is written.
52
+ if (!isProviderUserConfigIsolated(provider)) {
53
+ throw providerUserConfigIsolationUnsupported(options.dispatch.execution.provider);
45
54
  }
46
55
  if (provider === "claude") {
47
56
  return await prepareClaudeCompletionToolRuntime(runtime);
48
57
  }
49
58
  return runtime;
50
59
  }
51
- export function buildCompletionToolServerArgs(config) {
52
- const args = [
53
- "mcp",
54
- "--worktree",
55
- path.resolve(config.worktreePath),
56
- "--work-item-id",
57
- config.workItemId,
58
- "--phase",
59
- config.phase,
60
- "--produced-by",
61
- config.producedBy ?? "forge-completion-tool"
62
- ];
63
- if (config.ownerType || config.ownerId) {
64
- args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
65
- args.push("--owner-id", config.ownerId ?? config.workItemId);
66
- }
67
- if (config.developCycle) {
68
- args.push("--develop-cycle");
69
- }
70
- if (config.qaCycle) {
71
- args.push("--qa-cycle");
72
- }
73
- if (config.debugCycle) {
74
- args.push("--debug-cycle");
75
- }
76
- if (config.architectCycle) {
77
- args.push("--architect-cycle");
78
- }
79
- if (config.draftCycle) {
80
- args.push("--draft-cycle");
81
- }
82
- if (config.decomposeCycle) {
83
- args.push("--decompose-cycle");
84
- }
85
- return args;
86
- }
87
60
  export function codexMcpConfigArgs(runtime) {
88
61
  const prefix = `mcp_servers.${runtime.serverName}`;
89
62
  const args = [
@@ -131,6 +104,10 @@ export function completionToolNamesForServer(config) {
131
104
  ? completionToolNamesForPhase("architect")
132
105
  : completionToolNamesForPhase(config.phase);
133
106
  }
107
+ const managedToolsOnlyInstructions = "Forge serves only its managed-attempt tools in this turn: "
108
+ + "forge.start_managed_verification, forge.start_managed_command, forge.wait_managed_command, forge.get_managed_command, "
109
+ + "forge.run_managed_command and forge.reset_generated_outputs. No completion tool is available; the phase's completion "
110
+ + "artifacts are already recorded and must stay as they are.";
134
111
  export class CompletionToolServerSession {
135
112
  config;
136
113
  currentPhase;
@@ -144,36 +121,46 @@ export class CompletionToolServerSession {
144
121
  this.currentPhase = config.phase;
145
122
  }
146
123
  get instructions() {
147
- return this.config.decomposeCycle
148
- ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
149
- : this.config.draftCycle
150
- ? completionPromptForDraftCycle(this.currentDraftGate)
151
- : this.config.debugCycle
152
- ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
153
- : this.config.qaCycle
154
- ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
155
- : this.config.developCycle
156
- ? completionPromptForDevelopCycle(this.currentPhase)
157
- : completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
124
+ return this.config.managedToolsOnly
125
+ ? managedToolsOnlyInstructions
126
+ : this.config.decomposeCycle
127
+ ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
128
+ : this.config.draftCycle
129
+ ? completionPromptForDraftCycle(this.currentDraftGate)
130
+ : this.config.debugCycle
131
+ ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
132
+ : this.config.qaCycle
133
+ ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
134
+ : this.config.developCycle
135
+ ? completionPromptForDevelopCycle(this.currentPhase)
136
+ : completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
158
137
  }
159
138
  toolDefinitions() {
160
- const completionTools = completionToolNamesForServer(this.config).map((name) => toolDefinition(name, phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name)));
139
+ const completionTools = this.config.managedToolsOnly
140
+ ? []
141
+ : completionToolNamesForServer(this.config).map(toolDefinition);
161
142
  return managedAttemptToolsAvailable()
162
143
  ? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
163
144
  : completionTools;
164
145
  }
165
- async callTool(toolName, input) {
146
+ async callTool(toolName, rawInput) {
166
147
  if (isManagedAttemptTool(toolName)) {
167
148
  if (!managedAttemptToolsAvailable()) {
168
149
  throw new Error("Forge managed-attempt tools require an active managed host runtime.");
169
150
  }
170
- const result = await callManagedAttemptTool(toolName, input, this.config.worktreePath);
151
+ const managedInput = coerceJsonStringArguments(rawInput, managedAttemptToolInputSchema(toolName));
152
+ const result = await callManagedAttemptTool(toolName, managedInput, this.config.worktreePath);
171
153
  if (Array.isArray(result.structuredContent.command)) {
172
154
  this.managedCommandReceipts.push(result.structuredContent);
173
155
  }
174
156
  return result;
175
157
  }
158
+ if (this.config.managedToolsOnly) {
159
+ throw new Error(`${toolName} is not available in this turn: Forge serves only its managed-attempt tools during a pre-publication repair turn, and the phase's completion artifacts are already recorded. Fix the failing checks and stop; Bridge reruns validation.`);
160
+ }
176
161
  const requestedPhase = phaseFromToolName(toolName);
162
+ // Clients sometimes send a declared array/object argument as its JSON text.
163
+ const input = coerceJsonStringArguments(rawInput, completionToolInputSchema(toolName));
177
164
  if (this.completed) {
178
165
  throw new Error("Forge completion cycle is already complete; no more completion calls are accepted.");
179
166
  }
@@ -270,15 +257,26 @@ export class CompletionToolServerSession {
270
257
  const completedGate = this.currentDraftGate;
271
258
  const reference = await writeDraftGateCompletionArtifact(this.config, completedGate, toolName, input);
272
259
  const status = reference.status.trim().toLowerCase();
273
- const nextGate = this.advanceAfterDraftGate(completedGate);
274
- const nextPhase = nextGate ? "draft" : "sign_off_ready";
275
- const nextInstruction = completionToolNextInstructionForDraftGate(completedGate, status, nextGate);
260
+ // Only a pass completes a Draft gate; needs_revision, needs_rework, and blocked keep the same
261
+ // gate selected so it is retried, never skipped.
262
+ const pass = status === "pass";
263
+ const nextGate = pass ? this.advanceAfterDraftGate(completedGate) : completedGate;
264
+ const nextPhase = pass ? (nextGate ? "draft" : "sign_off_ready") : "draft";
265
+ const nextInstruction = completionToolNextInstructionForDraftGate(completedGate, status, pass ? nextGate : null);
276
266
  return {
277
267
  content: [{ type: "text", text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}` }],
278
268
  structuredContent: {
279
269
  ...reference,
280
270
  ...acceptedArtifactReceipt(reference),
281
- gate: { phase: "draft", draftGate: completedGate, status, allowed: status !== "blocked", reason: nextGate ? `${completedGate} artifact accepted; continue to ${nextGate}.` : `Draft proposal artifact accepted with status ${status}.` },
271
+ gate: {
272
+ phase: "draft",
273
+ draftGate: completedGate,
274
+ status,
275
+ allowed: pass,
276
+ reason: !pass
277
+ ? `${completedGate} artifact recorded with status ${status}; rework is required before continuing.`
278
+ : nextGate ? `${completedGate} artifact accepted; continue to ${nextGate}.` : `Draft proposal artifact accepted with status ${status}.`
279
+ },
282
280
  nextPhase,
283
281
  nextInstruction
284
282
  }
@@ -458,18 +456,25 @@ const completionToolRuntimeEnvironmentNames = [
458
456
  "TMP",
459
457
  "TEMP",
460
458
  ];
461
- export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestPostgresFallbackPath) {
462
- if (!runtimeEnvironment)
463
- return {};
459
+ export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestPostgresFallbackPath, hostLoadEnvironment) {
464
460
  const env = {};
461
+ // Without a runtime environment the server gets nothing from it, but it still
462
+ // joins the host ledger when the bridge handed it the governor's variables.
463
+ if (!runtimeEnvironment && !hostLoadEnvironment)
464
+ return env;
465
465
  for (const name of completionToolRuntimeEnvironmentNames) {
466
- const value = runtimeEnvironment[name]?.trim();
466
+ const value = runtimeEnvironment?.[name]?.trim();
467
467
  if (value)
468
468
  env[name] = value;
469
469
  }
470
+ // The host load governor's flag, state root and tuning: managed commands join its ledger.
471
+ for (const [name, value] of Object.entries(hostLoadEnvironment ?? {})) {
472
+ if (isHostLoadChildEnvironmentName(name) && value.trim())
473
+ env[name] = value.trim();
474
+ }
470
475
  // Managed verification reads the operator's native test cluster only through
471
- // this explicit path, and only while Docker is unavailable.
472
- if (nativeTestPostgresFallbackPath) {
476
+ // this explicit path; the file's `use` decides whether Docker comes first.
477
+ if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
473
478
  env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
474
479
  }
475
480
  return env;
@@ -552,133 +557,29 @@ function managedAttemptToolsAvailable() {
552
557
  }
553
558
  export async function runCompletionMcpServer(config) {
554
559
  const session = new CompletionToolServerSession(config);
555
- process.stdin.setEncoding("utf8");
556
- let buffer = "";
557
- for await (const chunk of process.stdin) {
558
- buffer += chunk;
559
- let newlineIndex = buffer.indexOf("\n");
560
- while (newlineIndex >= 0) {
561
- const rawLine = buffer.slice(0, newlineIndex).trim();
562
- buffer = buffer.slice(newlineIndex + 1);
563
- if (rawLine.length > 0) {
564
- await handleJsonRpcLine(session, rawLine);
565
- }
566
- newlineIndex = buffer.indexOf("\n");
567
- }
568
- }
569
- const trailing = buffer.trim();
570
- if (trailing.length > 0) {
571
- await handleJsonRpcLine(session, trailing);
572
- }
573
- }
574
- export function parseCompletionMcpArgs(argv) {
575
- let worktreePath = null;
576
- let workItemId = null;
577
- let phase = "implementation";
578
- let ownerType;
579
- let ownerId;
580
- let producedBy;
581
- let developCycle = false;
582
- let qaCycle = false;
583
- let debugCycle = false;
584
- let architectCycle = false;
585
- let draftCycle = false;
586
- let decomposeCycle = false;
587
- for (let index = 1; index < argv.length; index += 1) {
588
- const arg = argv[index];
589
- if (arg === "--worktree") {
590
- worktreePath = argv[++index] ?? null;
591
- }
592
- else if (arg === "--work-item-id") {
593
- workItemId = argv[++index] ?? null;
594
- }
595
- else if (arg === "--owner-type") {
596
- ownerType = normalizedOwnerType(argv[++index]);
597
- if (!ownerType) {
598
- return { ok: false, error: "mcp --owner-type must be work_item or story." };
599
- }
600
- }
601
- else if (arg === "--owner-id") {
602
- ownerId = argv[++index] ?? undefined;
603
- }
604
- else if (arg === "--phase") {
605
- const rawPhase = argv[++index];
606
- const parsedPhase = parseStrictCompletionPhase(rawPhase);
607
- if (!parsedPhase) {
608
- return { ok: false, error: "mcp --phase must be one of: implementation, self-review, validation, qa, architect, draft, decompose, ci-repair, comment-repair, debug-repro, debug-root-cause, debug-fix, debug-regression." };
560
+ // This server is the only supervisor of the managed commands it starts, and they run in
561
+ // their own process groups. When the provider closes the connection or stops this server,
562
+ // stop them first so none outlives its supervisor and receipt writer.
563
+ await runWithOwnerShutdown(async () => {
564
+ process.stdin.setEncoding("utf8");
565
+ let buffer = "";
566
+ for await (const chunk of process.stdin) {
567
+ buffer += chunk;
568
+ let newlineIndex = buffer.indexOf("\n");
569
+ while (newlineIndex >= 0) {
570
+ const rawLine = buffer.slice(0, newlineIndex).trim();
571
+ buffer = buffer.slice(newlineIndex + 1);
572
+ if (rawLine.length > 0) {
573
+ await handleJsonRpcLine(session, rawLine);
574
+ }
575
+ newlineIndex = buffer.indexOf("\n");
609
576
  }
610
- phase = parsedPhase;
611
- }
612
- else if (arg === "--produced-by") {
613
- producedBy = argv[++index] ?? undefined;
614
- }
615
- else if (arg === "--develop-cycle") {
616
- developCycle = true;
617
577
  }
618
- else if (arg === "--qa-cycle") {
619
- qaCycle = true;
578
+ const trailing = buffer.trim();
579
+ if (trailing.length > 0) {
580
+ await handleJsonRpcLine(session, trailing);
620
581
  }
621
- else if (arg === "--debug-cycle") {
622
- debugCycle = true;
623
- }
624
- else if (arg === "--architect-cycle") {
625
- architectCycle = true;
626
- }
627
- else if (arg === "--draft-cycle") {
628
- draftCycle = true;
629
- }
630
- else if (arg === "--decompose-cycle") {
631
- decomposeCycle = true;
632
- }
633
- else {
634
- return { ok: false, error: `Unknown mcp argument: ${arg}` };
635
- }
636
- }
637
- if (!worktreePath?.trim() || !workItemId?.trim()) {
638
- return { ok: false, error: "mcp requires --worktree and --work-item-id." };
639
- }
640
- if ([developCycle, qaCycle, debugCycle, architectCycle, draftCycle, decomposeCycle].filter(Boolean).length > 1) {
641
- return { ok: false, error: "mcp accepts only one cycle mode." };
642
- }
643
- if (developCycle && !isDevelopCompletionPhase(phase)) {
644
- return { ok: false, error: "mcp --develop-cycle requires --phase implementation, self-review, or validation." };
645
- }
646
- if (qaCycle && phase !== "qa") {
647
- return { ok: false, error: "mcp --qa-cycle requires --phase qa." };
648
- }
649
- if (debugCycle && !isDebugCompletionPhase(phase)) {
650
- return { ok: false, error: "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression." };
651
- }
652
- if (architectCycle && phase !== "architect") {
653
- return { ok: false, error: "mcp --architect-cycle requires --phase architect." };
654
- }
655
- if (draftCycle && phase !== "draft") {
656
- return { ok: false, error: "mcp --draft-cycle requires --phase draft." };
657
- }
658
- if (decomposeCycle && phase !== "decompose") {
659
- return { ok: false, error: "mcp --decompose-cycle requires --phase decompose." };
660
- }
661
- return {
662
- ok: true,
663
- config: {
664
- worktreePath: path.resolve(worktreePath),
665
- workItemId,
666
- ownerType,
667
- ownerId,
668
- phase,
669
- producedBy,
670
- redactionSecrets: [
671
- ...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
672
- ...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
673
- ],
674
- developCycle,
675
- qaCycle,
676
- debugCycle,
677
- architectCycle,
678
- draftCycle,
679
- decomposeCycle
680
- }
681
- };
582
+ });
682
583
  }
683
584
  export function completionRedactionEnv(secrets) {
684
585
  const filtered = secrets.filter((secret) => secret.length > 0);
@@ -686,33 +587,6 @@ export function completionRedactionEnv(secrets) {
686
587
  ? { [completionRedactionSecretsEnv]: JSON.stringify(filtered) }
687
588
  : {};
688
589
  }
689
- async function prepareCursorCompletionToolRuntime(worktreePath, runtime) {
690
- const cursorDir = path.join(worktreePath, ".cursor");
691
- const configPath = path.join(cursorDir, "mcp.json");
692
- const original = await fs.readFile(configPath, "utf8").then((content) => ({ existed: true, content }), () => ({ existed: false, content: "" }));
693
- const existing = original.existed ? parseOptionalJsonObject(original.content, configPath) : {};
694
- const servers = asMutableRecord(existing.mcpServers);
695
- servers[runtime.serverName] = cursorMcpServerConfig(runtime);
696
- const next = {
697
- ...existing,
698
- mcpServers: servers
699
- };
700
- await fs.mkdir(cursorDir, { recursive: true });
701
- await writeFileAtomic(configPath, `${JSON.stringify(next, null, 2)}\n`);
702
- return {
703
- ...runtime,
704
- cursorMcpConfigPath: configPath,
705
- cleanup: async () => {
706
- if (original.existed) {
707
- await writeFileAtomic(configPath, original.content);
708
- }
709
- else {
710
- await fs.rm(configPath, { force: true });
711
- await fs.rmdir(cursorDir).catch(() => undefined);
712
- }
713
- }
714
- };
715
- }
716
590
  /**
717
591
  * Claude Code takes MCP servers from `--mcp-config <file>`. The file lives in an attempt-owned
718
592
  * temp directory (never the worktree) because its env block can carry redaction secrets, and
@@ -795,15 +669,18 @@ async function handleJsonRpcRequest(session, method, params) {
795
669
  catch (error) {
796
670
  if (isManagedAttemptTool(name))
797
671
  throw error;
798
- return completionToolRejectedResult(name, error);
672
+ return completionToolRejectedResult(name, error, args);
799
673
  }
800
674
  }
801
675
  throw new Error(`Unsupported MCP method: ${method}`);
802
676
  }
803
- export function completionToolRejectedResult(toolName, error) {
677
+ export function completionToolRejectedResult(toolName, error, input) {
804
678
  const issues = error instanceof CompletionPayloadValidationError
805
679
  ? [...error.issues]
806
680
  : [errorMessage(error)];
681
+ if (input !== undefined && isEmptyToolInput(input)) {
682
+ issues.push(`${emptyToolInputHint} Keep long free text such as report_markdown short.`);
683
+ }
807
684
  const repairInstruction = "Repair every listed issue and resubmit this same gate once. Do not inspect the artifact path: rejected calls never write or replace completion artifacts.";
808
685
  return {
809
686
  content: [{
@@ -831,10 +708,14 @@ function acceptedArtifactReceipt(reference) {
831
708
  },
832
709
  };
833
710
  }
834
- function toolDefinition(name, phase, qaGate = null, decomposeGate = null) {
711
+ function toolDefinition(name) {
835
712
  return {
836
713
  name,
837
- description: toolDescription(phase, qaGate, decomposeGate),
838
- inputSchema: toolInputSchema(phase, qaGate, decomposeGate)
714
+ description: toolDescription(phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name), draftGateFromToolName(name)),
715
+ inputSchema: completionToolInputSchema(name)
839
716
  };
840
717
  }
718
+ /** The input schema a completion tool advertises; also the shape its arguments are coerced to. */
719
+ export function completionToolInputSchema(name) {
720
+ return toolInputSchema(phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name), draftGateFromToolName(name));
721
+ }
@@ -0,0 +1,19 @@
1
+ export declare function browserCheckSchema(required: readonly string[]): unknown;
2
+ export declare function qaSidecarsSchema(): unknown;
3
+ export declare function qaEvidenceWrapperSchema(): unknown;
4
+ /** QA evidence gates read only sidecars from the nested wrapper; the other evidence fields go at the top level. */
5
+ export declare function qaGateEvidenceWrapperSchema(): unknown;
6
+ export declare function findingEvidenceSchema(rule: string): unknown;
7
+ export declare function objectToolSchema(properties: Record<string, unknown>, required: readonly string[], description: string): unknown;
8
+ export declare function evidenceObjectSchema(required: readonly string[], properties: Record<string, unknown>): unknown;
9
+ export declare function qaScopeSchema(description: string): unknown;
10
+ export declare function commandEvidenceSchema(): unknown;
11
+ export declare function resolvedFindingSchema(): unknown;
12
+ export declare function acceptanceCriteriaSchema(): unknown;
13
+ export declare function reviewSectionSchema(): {
14
+ readonly type: "object";
15
+ readonly description: string;
16
+ readonly additionalProperties: true;
17
+ readonly properties: Record<string, unknown>;
18
+ };
19
+ export declare function reviewSectionProperties(): Record<string, unknown>;