@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.0098fdb4e213
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.
- package/README.md +232 -5
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +13 -1
- package/dist/bridge/bridge.service.d.ts +169 -14
- package/dist/bridge/bridge.service.js +1868 -330
- package/dist/bridge/bridge.types.d.ts +73 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +25 -0
- package/dist/bridge/readiness-result-outbox.js +74 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +21 -1
- package/dist/cleanup/cleanup.service.js +185 -143
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +78 -16
- package/dist/cli/cli.service.d.ts +32 -15
- package/dist/cli/cli.service.js +206 -182
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +7 -0
- package/dist/cli/local-config.js +36 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +41 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +95 -0
- package/dist/runtime/docker-engine-probe.js +340 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +28 -1
- package/dist/runtime/host-runtime-contract.js +203 -57
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1427 -124
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
- package/dist/runtime/native-test-postgres-fallback.js +143 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/runtime-isolation-lease.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +183 -114
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +37 -1
- package/dist/session/managed-attempt-tools.js +822 -84
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +26 -0
- package/dist/session/managed-build-receipt.js +342 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +24 -0
- package/dist/session/phase-completion.artifacts.js +321 -45
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +23 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +19 -3
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -10
- package/dist/session/phase-completion.runtime.js +214 -224
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +91 -0
- package/dist/session/pre-publication-validation.js +670 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +85 -19
- package/dist/session/provider-cli/provider-cli.process.js +566 -283
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +211 -36
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +22 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +83 -4
- package/dist/session/provider-cli/provider-cli.service.d.ts +36 -5
- package/dist/session/provider-cli/provider-cli.service.js +818 -99
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.js +284 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +301 -58
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +26 -5
- package/dist/shared/process/host-process-supervisor.d.ts +16 -1
- package/dist/shared/process/host-process-supervisor.js +124 -23
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +69 -0
- package/dist/shared/process/process.js +223 -16
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +92 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +22 -2
- package/dist/worktree/worktree.service.js +302 -25
- package/dist/worktree/worktree.types.d.ts +36 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
|
|
4
|
-
import { asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch,
|
|
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";
|
|
5
6
|
import { completionPromptForDebugCycle, completionPromptForDecomposeCycle, completionPromptForDevelopCycle, completionPromptForDraftCycle, completionPromptForPhase, completionPromptForQaCycle, completionToolNextInstruction, completionToolNextInstructionForDebugGate, completionToolNextInstructionForDecomposeGate, completionToolNextInstructionForDraftGate, completionToolNextInstructionForQaGate, nextDebugPhaseAfter, nextPhaseAfter } from "./phase-completion.prompts.js";
|
|
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";
|
|
6
10
|
import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
|
|
11
|
+
import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
|
|
7
12
|
import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
|
|
8
|
-
import {
|
|
13
|
+
import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
|
|
14
|
+
import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
|
|
9
15
|
export async function prepareCompletionToolRuntime(options) {
|
|
10
16
|
const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
|
|
11
17
|
const worktreePath = path.resolve(options.worktree.worktreePath);
|
|
12
18
|
const workItemId = options.dispatch.workItem.id;
|
|
13
19
|
const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
|
|
14
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;
|
|
15
23
|
const mcpArgs = buildCompletionToolServerArgs({
|
|
16
24
|
worktreePath,
|
|
17
25
|
workItemId,
|
|
@@ -19,63 +27,35 @@ export async function prepareCompletionToolRuntime(options) {
|
|
|
19
27
|
ownerId,
|
|
20
28
|
phase,
|
|
21
29
|
producedBy: `${options.dispatch.execution.provider}-cli`,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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")
|
|
29
39
|
&& !isDecomposeDispatch(options.dispatch),
|
|
30
|
-
decomposeCycle: isDecomposeDispatch(options.dispatch)
|
|
40
|
+
decomposeCycle: cycles && isDecomposeDispatch(options.dispatch)
|
|
31
41
|
});
|
|
32
42
|
const runtime = {
|
|
33
43
|
serverName: toolServerName,
|
|
34
44
|
command: process.execPath,
|
|
35
45
|
args: [forgeBridgeCliBinPath(), ...mcpArgs],
|
|
36
|
-
env: completionToolRuntimeEnvironment(options.runtimeEnvironment),
|
|
46
|
+
env: completionToolRuntimeEnvironment(options.runtimeEnvironment, configuredNativeTestPostgresFallbackPath(), options.hostLoadEnvironment),
|
|
37
47
|
cleanup: async () => undefined
|
|
38
48
|
};
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
const provider = options.dispatch.execution.provider.trim().toLowerCase();
|
|
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);
|
|
41
54
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export function buildCompletionToolServerArgs(config) {
|
|
45
|
-
const args = [
|
|
46
|
-
"mcp",
|
|
47
|
-
"--worktree",
|
|
48
|
-
path.resolve(config.worktreePath),
|
|
49
|
-
"--work-item-id",
|
|
50
|
-
config.workItemId,
|
|
51
|
-
"--phase",
|
|
52
|
-
config.phase,
|
|
53
|
-
"--produced-by",
|
|
54
|
-
config.producedBy ?? "forge-completion-tool"
|
|
55
|
-
];
|
|
56
|
-
if (config.ownerType || config.ownerId) {
|
|
57
|
-
args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
|
|
58
|
-
args.push("--owner-id", config.ownerId ?? config.workItemId);
|
|
59
|
-
}
|
|
60
|
-
if (config.developCycle) {
|
|
61
|
-
args.push("--develop-cycle");
|
|
62
|
-
}
|
|
63
|
-
if (config.qaCycle) {
|
|
64
|
-
args.push("--qa-cycle");
|
|
65
|
-
}
|
|
66
|
-
if (config.debugCycle) {
|
|
67
|
-
args.push("--debug-cycle");
|
|
68
|
-
}
|
|
69
|
-
if (config.architectCycle) {
|
|
70
|
-
args.push("--architect-cycle");
|
|
71
|
-
}
|
|
72
|
-
if (config.draftCycle) {
|
|
73
|
-
args.push("--draft-cycle");
|
|
74
|
-
}
|
|
75
|
-
if (config.decomposeCycle) {
|
|
76
|
-
args.push("--decompose-cycle");
|
|
55
|
+
if (provider === "claude") {
|
|
56
|
+
return await prepareClaudeCompletionToolRuntime(runtime);
|
|
77
57
|
}
|
|
78
|
-
return
|
|
58
|
+
return runtime;
|
|
79
59
|
}
|
|
80
60
|
export function codexMcpConfigArgs(runtime) {
|
|
81
61
|
const prefix = `mcp_servers.${runtime.serverName}`;
|
|
@@ -101,6 +81,14 @@ export function cursorMcpServerConfig(runtime) {
|
|
|
101
81
|
env: runtime.env
|
|
102
82
|
};
|
|
103
83
|
}
|
|
84
|
+
export function claudeMcpServerConfig(runtime) {
|
|
85
|
+
return {
|
|
86
|
+
type: "stdio",
|
|
87
|
+
command: runtime.command,
|
|
88
|
+
args: [...runtime.args],
|
|
89
|
+
env: runtime.env
|
|
90
|
+
};
|
|
91
|
+
}
|
|
104
92
|
export function completionToolNamesForServer(config) {
|
|
105
93
|
return config.decomposeCycle
|
|
106
94
|
? decomposeCompletionGateOrder.flatMap((gate) => completionToolNamesForDecomposeGate(gate))
|
|
@@ -116,6 +104,10 @@ export function completionToolNamesForServer(config) {
|
|
|
116
104
|
? completionToolNamesForPhase("architect")
|
|
117
105
|
: completionToolNamesForPhase(config.phase);
|
|
118
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.";
|
|
119
111
|
export class CompletionToolServerSession {
|
|
120
112
|
config;
|
|
121
113
|
currentPhase;
|
|
@@ -129,36 +121,46 @@ export class CompletionToolServerSession {
|
|
|
129
121
|
this.currentPhase = config.phase;
|
|
130
122
|
}
|
|
131
123
|
get instructions() {
|
|
132
|
-
return this.config.
|
|
133
|
-
?
|
|
134
|
-
: this.config.
|
|
135
|
-
?
|
|
136
|
-
: this.config.
|
|
137
|
-
?
|
|
138
|
-
: this.config.
|
|
139
|
-
?
|
|
140
|
-
: this.config.
|
|
141
|
-
?
|
|
142
|
-
:
|
|
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));
|
|
143
137
|
}
|
|
144
138
|
toolDefinitions() {
|
|
145
|
-
const completionTools =
|
|
139
|
+
const completionTools = this.config.managedToolsOnly
|
|
140
|
+
? []
|
|
141
|
+
: completionToolNamesForServer(this.config).map(toolDefinition);
|
|
146
142
|
return managedAttemptToolsAvailable()
|
|
147
143
|
? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
|
|
148
144
|
: completionTools;
|
|
149
145
|
}
|
|
150
|
-
async callTool(toolName,
|
|
146
|
+
async callTool(toolName, rawInput) {
|
|
151
147
|
if (isManagedAttemptTool(toolName)) {
|
|
152
148
|
if (!managedAttemptToolsAvailable()) {
|
|
153
149
|
throw new Error("Forge managed-attempt tools require an active managed host runtime.");
|
|
154
150
|
}
|
|
155
|
-
const
|
|
151
|
+
const managedInput = coerceJsonStringArguments(rawInput, managedAttemptToolInputSchema(toolName));
|
|
152
|
+
const result = await callManagedAttemptTool(toolName, managedInput, this.config.worktreePath);
|
|
156
153
|
if (Array.isArray(result.structuredContent.command)) {
|
|
157
154
|
this.managedCommandReceipts.push(result.structuredContent);
|
|
158
155
|
}
|
|
159
156
|
return result;
|
|
160
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
|
+
}
|
|
161
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));
|
|
162
164
|
if (this.completed) {
|
|
163
165
|
throw new Error("Forge completion cycle is already complete; no more completion calls are accepted.");
|
|
164
166
|
}
|
|
@@ -185,9 +187,11 @@ export class CompletionToolServerSession {
|
|
|
185
187
|
? this.advanceAfterPass(completedPhase)
|
|
186
188
|
: completedPhase;
|
|
187
189
|
const nextInstruction = completionToolNextInstruction(completedPhase, status, nextPhase);
|
|
188
|
-
const reason =
|
|
189
|
-
?
|
|
190
|
-
:
|
|
190
|
+
const reason = completedPhase === "qa"
|
|
191
|
+
? `QA artifact recorded locally with status ${status}; API ingestion and acceptance are pending.`
|
|
192
|
+
: pass
|
|
193
|
+
? `${completedPhase} completion artifact accepted.`
|
|
194
|
+
: `${completedPhase} completion artifact recorded with status ${status}; rework is required before phase progression.`;
|
|
191
195
|
return {
|
|
192
196
|
content: [
|
|
193
197
|
{
|
|
@@ -197,6 +201,7 @@ export class CompletionToolServerSession {
|
|
|
197
201
|
],
|
|
198
202
|
structuredContent: {
|
|
199
203
|
...reference,
|
|
204
|
+
...acceptedArtifactReceipt(reference),
|
|
200
205
|
gate: {
|
|
201
206
|
phase: completedPhase,
|
|
202
207
|
status,
|
|
@@ -234,6 +239,7 @@ export class CompletionToolServerSession {
|
|
|
234
239
|
content: [{ type: "text", text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}` }],
|
|
235
240
|
structuredContent: {
|
|
236
241
|
...reference,
|
|
242
|
+
...acceptedArtifactReceipt(reference),
|
|
237
243
|
gate: { phase: "decompose", decomposeGate: completedGate, status, allowed: pass, reason },
|
|
238
244
|
nextPhase,
|
|
239
245
|
nextInstruction
|
|
@@ -251,14 +257,26 @@ export class CompletionToolServerSession {
|
|
|
251
257
|
const completedGate = this.currentDraftGate;
|
|
252
258
|
const reference = await writeDraftGateCompletionArtifact(this.config, completedGate, toolName, input);
|
|
253
259
|
const status = reference.status.trim().toLowerCase();
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
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);
|
|
257
266
|
return {
|
|
258
267
|
content: [{ type: "text", text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}` }],
|
|
259
268
|
structuredContent: {
|
|
260
269
|
...reference,
|
|
261
|
-
|
|
270
|
+
...acceptedArtifactReceipt(reference),
|
|
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
|
+
},
|
|
262
280
|
nextPhase,
|
|
263
281
|
nextInstruction
|
|
264
282
|
}
|
|
@@ -291,6 +309,7 @@ export class CompletionToolServerSession {
|
|
|
291
309
|
],
|
|
292
310
|
structuredContent: {
|
|
293
311
|
...reference,
|
|
312
|
+
...acceptedArtifactReceipt(reference),
|
|
294
313
|
gate: {
|
|
295
314
|
phase: completedGate,
|
|
296
315
|
status,
|
|
@@ -321,8 +340,8 @@ export class CompletionToolServerSession {
|
|
|
321
340
|
const nextInstruction = completionToolNextInstructionForQaGate(completedGate, status, nextGate);
|
|
322
341
|
const allowed = status !== "blocked";
|
|
323
342
|
const reason = nextGate
|
|
324
|
-
? `${completedGate} artifact accepted; continue to ${nextGate}.`
|
|
325
|
-
: `QA verdict artifact
|
|
343
|
+
? `${completedGate} artifact accepted locally; continue to ${nextGate}.`
|
|
344
|
+
: `QA verdict artifact recorded locally with status ${status}; API ingestion and acceptance are pending.`;
|
|
326
345
|
return {
|
|
327
346
|
content: [
|
|
328
347
|
{
|
|
@@ -332,6 +351,7 @@ export class CompletionToolServerSession {
|
|
|
332
351
|
],
|
|
333
352
|
structuredContent: {
|
|
334
353
|
...reference,
|
|
354
|
+
...acceptedArtifactReceipt(reference),
|
|
335
355
|
gate: {
|
|
336
356
|
phase: "qa",
|
|
337
357
|
qaGate: completedGate,
|
|
@@ -412,22 +432,51 @@ const completionToolRuntimeEnvironmentNames = [
|
|
|
412
432
|
"FORGE_RUNTIME_MODE",
|
|
413
433
|
"FORGE_RESOURCE_LEASE_ID",
|
|
414
434
|
"FORGE_DISPATCH_ATTEMPT_ID",
|
|
435
|
+
"FORGE_E2E_OWNERSHIP_MODE",
|
|
436
|
+
"FORGE_E2E_OWNERSHIP_TOKEN",
|
|
437
|
+
"FORGE_WORKTREE_PATH",
|
|
415
438
|
"FORGE_LOG_DIR",
|
|
439
|
+
"FORGE_CACHE_DIR",
|
|
416
440
|
"FORGE_TEST_OUTPUT_DIR",
|
|
441
|
+
"FORGE_ATTEMPT_DATABASE_SCHEMA",
|
|
442
|
+
"FORGE_ATTEMPT_DATABASE_READINESS_PATH",
|
|
443
|
+
"FORGE_ATTEMPT_DATABASE_CAPABILITY",
|
|
444
|
+
"FORGE_CI_REPAIR_READINESS_PATH",
|
|
445
|
+
"FORGE_CI_REPAIR_HANDOFF_PATH",
|
|
446
|
+
"FORGE_CI_REPAIR_PROVIDER_ONLY_SPECS",
|
|
447
|
+
"FORGE_PLAYWRIGHT_CONFIG",
|
|
448
|
+
"FORGE_API_URL",
|
|
449
|
+
"FORGE_WEB_URL",
|
|
450
|
+
"FORGE_E2E_API_URL",
|
|
451
|
+
"FORGE_E2E_WEB_URL",
|
|
452
|
+
"PLAYWRIGHT_BROWSERS_PATH",
|
|
417
453
|
"FORGE_TMPDIR",
|
|
454
|
+
"NPM_CONFIG_CACHE",
|
|
418
455
|
"TMPDIR",
|
|
419
456
|
"TMP",
|
|
420
457
|
"TEMP",
|
|
421
458
|
];
|
|
422
|
-
export function completionToolRuntimeEnvironment(runtimeEnvironment) {
|
|
423
|
-
if (!runtimeEnvironment)
|
|
424
|
-
return {};
|
|
459
|
+
export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestPostgresFallbackPath, hostLoadEnvironment) {
|
|
425
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;
|
|
426
465
|
for (const name of completionToolRuntimeEnvironmentNames) {
|
|
427
|
-
const value = runtimeEnvironment[name]?.trim();
|
|
466
|
+
const value = runtimeEnvironment?.[name]?.trim();
|
|
428
467
|
if (value)
|
|
429
468
|
env[name] = value;
|
|
430
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
|
+
}
|
|
475
|
+
// Managed verification reads the operator's native test cluster only through
|
|
476
|
+
// this explicit path; the file's `use` decides whether Docker comes first.
|
|
477
|
+
if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
|
|
478
|
+
env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
|
|
479
|
+
}
|
|
431
480
|
return env;
|
|
432
481
|
}
|
|
433
482
|
const minimumManagedSolutionTestTimeoutMs = 45 * 60 * 1000;
|
|
@@ -453,7 +502,8 @@ export function assertManagedQaRegressionEvidence(input, receipts) {
|
|
|
453
502
|
const managedCommandId = entry.managed_command_id;
|
|
454
503
|
if (typeof managedCommandId !== "string" || !managedCommandId.trim()) {
|
|
455
504
|
throw new Error(`qa_regression_managed_command_id_required: commands[${index}] runs the solution-wide Forge test. `
|
|
456
|
-
+ "Run it with forge.start_managed_command, continue independent work, call forge.wait_managed_command
|
|
505
|
+
+ "Run it with forge.start_managed_command, continue independent work, then call forge.wait_managed_command for a transport-safe receipt. "
|
|
506
|
+
+ "If command_continues=true, continue useful work or wait again after retry_after_ms. Include the terminal managed_command_id in this command evidence.");
|
|
457
507
|
}
|
|
458
508
|
const matchingReceipts = receipts.filter((receipt) => {
|
|
459
509
|
const tokens = receipt.command;
|
|
@@ -464,7 +514,8 @@ export function assertManagedQaRegressionEvidence(input, receipts) {
|
|
|
464
514
|
});
|
|
465
515
|
if (matchingReceipts.length === 0) {
|
|
466
516
|
throw new Error(`qa_regression_managed_command_required: commands[${index}] runs the solution-wide Forge test. `
|
|
467
|
-
+ "Run it with forge.start_managed_command, continue independent work, call forge.wait_managed_command
|
|
517
|
+
+ "Run it with forge.start_managed_command, continue independent work, then call forge.wait_managed_command for a transport-safe receipt. "
|
|
518
|
+
+ "If command_continues=true, continue useful work or wait again after retry_after_ms. Include its matching terminal managed_command_id; generic-shell timeout evidence is not accepted on a managed host.");
|
|
468
519
|
}
|
|
469
520
|
const terminalReceipts = matchingReceipts.filter((receipt) => typeof receipt.status === "string" && [
|
|
470
521
|
"pass",
|
|
@@ -475,7 +526,7 @@ export function assertManagedQaRegressionEvidence(input, receipts) {
|
|
|
475
526
|
].includes(receipt.status));
|
|
476
527
|
if (terminalReceipts.length === 0) {
|
|
477
528
|
throw new Error(`qa_regression_managed_command_in_progress: commands[${index}] has not produced a terminal managed receipt. `
|
|
478
|
-
+ "Call forge.wait_managed_command
|
|
529
|
+
+ "Call forge.wait_managed_command. If command_continues=true, continue useful work or wait again after retry_after_ms; resubmit this gate only after the receipt is terminal.");
|
|
479
530
|
}
|
|
480
531
|
const adequateReceipt = terminalReceipts.some((receipt) => {
|
|
481
532
|
if (receipt.timed_out !== true)
|
|
@@ -506,130 +557,29 @@ function managedAttemptToolsAvailable() {
|
|
|
506
557
|
}
|
|
507
558
|
export async function runCompletionMcpServer(config) {
|
|
508
559
|
const session = new CompletionToolServerSession(config);
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
buffer
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
await handleJsonRpcLine(session, trailing);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
export function parseCompletionMcpArgs(argv) {
|
|
529
|
-
let worktreePath = null;
|
|
530
|
-
let workItemId = null;
|
|
531
|
-
let phase = "implementation";
|
|
532
|
-
let ownerType;
|
|
533
|
-
let ownerId;
|
|
534
|
-
let producedBy;
|
|
535
|
-
let developCycle = false;
|
|
536
|
-
let qaCycle = false;
|
|
537
|
-
let debugCycle = false;
|
|
538
|
-
let architectCycle = false;
|
|
539
|
-
let draftCycle = false;
|
|
540
|
-
let decomposeCycle = false;
|
|
541
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
542
|
-
const arg = argv[index];
|
|
543
|
-
if (arg === "--worktree") {
|
|
544
|
-
worktreePath = argv[++index] ?? null;
|
|
545
|
-
}
|
|
546
|
-
else if (arg === "--work-item-id") {
|
|
547
|
-
workItemId = argv[++index] ?? null;
|
|
548
|
-
}
|
|
549
|
-
else if (arg === "--owner-type") {
|
|
550
|
-
ownerType = normalizedOwnerType(argv[++index]);
|
|
551
|
-
if (!ownerType) {
|
|
552
|
-
return { ok: false, error: "mcp --owner-type must be work_item or story." };
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
else if (arg === "--owner-id") {
|
|
556
|
-
ownerId = argv[++index] ?? undefined;
|
|
557
|
-
}
|
|
558
|
-
else if (arg === "--phase") {
|
|
559
|
-
const rawPhase = argv[++index];
|
|
560
|
-
const parsedPhase = parseStrictCompletionPhase(rawPhase);
|
|
561
|
-
if (!parsedPhase) {
|
|
562
|
-
return { ok: false, error: "mcp --phase must be one of: implementation, self-review, validation, qa, architect, draft, decompose, ci-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");
|
|
563
576
|
}
|
|
564
|
-
phase = parsedPhase;
|
|
565
577
|
}
|
|
566
|
-
|
|
567
|
-
|
|
578
|
+
const trailing = buffer.trim();
|
|
579
|
+
if (trailing.length > 0) {
|
|
580
|
+
await handleJsonRpcLine(session, trailing);
|
|
568
581
|
}
|
|
569
|
-
|
|
570
|
-
developCycle = true;
|
|
571
|
-
}
|
|
572
|
-
else if (arg === "--qa-cycle") {
|
|
573
|
-
qaCycle = true;
|
|
574
|
-
}
|
|
575
|
-
else if (arg === "--debug-cycle") {
|
|
576
|
-
debugCycle = true;
|
|
577
|
-
}
|
|
578
|
-
else if (arg === "--architect-cycle") {
|
|
579
|
-
architectCycle = true;
|
|
580
|
-
}
|
|
581
|
-
else if (arg === "--draft-cycle") {
|
|
582
|
-
draftCycle = true;
|
|
583
|
-
}
|
|
584
|
-
else if (arg === "--decompose-cycle") {
|
|
585
|
-
decomposeCycle = true;
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
return { ok: false, error: `Unknown mcp argument: ${arg}` };
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
if (!worktreePath?.trim() || !workItemId?.trim()) {
|
|
592
|
-
return { ok: false, error: "mcp requires --worktree and --work-item-id." };
|
|
593
|
-
}
|
|
594
|
-
if ([developCycle, qaCycle, debugCycle, architectCycle, draftCycle, decomposeCycle].filter(Boolean).length > 1) {
|
|
595
|
-
return { ok: false, error: "mcp accepts only one cycle mode." };
|
|
596
|
-
}
|
|
597
|
-
if (developCycle && !isDevelopCompletionPhase(phase)) {
|
|
598
|
-
return { ok: false, error: "mcp --develop-cycle requires --phase implementation, self-review, or validation." };
|
|
599
|
-
}
|
|
600
|
-
if (qaCycle && phase !== "qa") {
|
|
601
|
-
return { ok: false, error: "mcp --qa-cycle requires --phase qa." };
|
|
602
|
-
}
|
|
603
|
-
if (debugCycle && !isDebugCompletionPhase(phase)) {
|
|
604
|
-
return { ok: false, error: "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression." };
|
|
605
|
-
}
|
|
606
|
-
if (architectCycle && phase !== "architect") {
|
|
607
|
-
return { ok: false, error: "mcp --architect-cycle requires --phase architect." };
|
|
608
|
-
}
|
|
609
|
-
if (draftCycle && phase !== "draft") {
|
|
610
|
-
return { ok: false, error: "mcp --draft-cycle requires --phase draft." };
|
|
611
|
-
}
|
|
612
|
-
if (decomposeCycle && phase !== "decompose") {
|
|
613
|
-
return { ok: false, error: "mcp --decompose-cycle requires --phase decompose." };
|
|
614
|
-
}
|
|
615
|
-
return {
|
|
616
|
-
ok: true,
|
|
617
|
-
config: {
|
|
618
|
-
worktreePath: path.resolve(worktreePath),
|
|
619
|
-
workItemId,
|
|
620
|
-
ownerType,
|
|
621
|
-
ownerId,
|
|
622
|
-
phase,
|
|
623
|
-
producedBy,
|
|
624
|
-
redactionSecrets: parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
|
|
625
|
-
developCycle,
|
|
626
|
-
qaCycle,
|
|
627
|
-
debugCycle,
|
|
628
|
-
architectCycle,
|
|
629
|
-
draftCycle,
|
|
630
|
-
decomposeCycle
|
|
631
|
-
}
|
|
632
|
-
};
|
|
582
|
+
});
|
|
633
583
|
}
|
|
634
584
|
export function completionRedactionEnv(secrets) {
|
|
635
585
|
const filtered = secrets.filter((secret) => secret.length > 0);
|
|
@@ -637,30 +587,25 @@ export function completionRedactionEnv(secrets) {
|
|
|
637
587
|
? { [completionRedactionSecretsEnv]: JSON.stringify(filtered) }
|
|
638
588
|
: {};
|
|
639
589
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
mcpServers:
|
|
590
|
+
/**
|
|
591
|
+
* Claude Code takes MCP servers from `--mcp-config <file>`. The file lives in an attempt-owned
|
|
592
|
+
* temp directory (never the worktree) because its env block can carry redaction secrets, and
|
|
593
|
+
* passing the JSON inline would not survive Windows shim quoting.
|
|
594
|
+
*/
|
|
595
|
+
async function prepareClaudeCompletionToolRuntime(runtime) {
|
|
596
|
+
const configDir = await fs.mkdtemp(path.join(os.tmpdir(), "forge-claude-mcp-"));
|
|
597
|
+
const configPath = path.join(configDir, "mcp.json");
|
|
598
|
+
const config = {
|
|
599
|
+
mcpServers: {
|
|
600
|
+
[runtime.serverName]: claudeMcpServerConfig(runtime)
|
|
601
|
+
}
|
|
650
602
|
};
|
|
651
|
-
await fs.
|
|
652
|
-
await writeFileAtomic(configPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
603
|
+
await fs.writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
653
604
|
return {
|
|
654
605
|
...runtime,
|
|
655
|
-
|
|
606
|
+
claudeMcpConfigPath: configPath,
|
|
656
607
|
cleanup: async () => {
|
|
657
|
-
|
|
658
|
-
await writeFileAtomic(configPath, original.content);
|
|
659
|
-
}
|
|
660
|
-
else {
|
|
661
|
-
await fs.rm(configPath, { force: true });
|
|
662
|
-
await fs.rmdir(cursorDir).catch(() => undefined);
|
|
663
|
-
}
|
|
608
|
+
await fs.rm(configDir, { recursive: true, force: true });
|
|
664
609
|
}
|
|
665
610
|
};
|
|
666
611
|
}
|
|
@@ -718,14 +663,59 @@ async function handleJsonRpcRequest(session, method, params) {
|
|
|
718
663
|
const call = asRecord(params, "tools/call params");
|
|
719
664
|
const name = requiredString(call, "name");
|
|
720
665
|
const args = call.arguments ?? {};
|
|
721
|
-
|
|
666
|
+
try {
|
|
667
|
+
return await session.callTool(name, args);
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
if (isManagedAttemptTool(name))
|
|
671
|
+
throw error;
|
|
672
|
+
return completionToolRejectedResult(name, error, args);
|
|
673
|
+
}
|
|
722
674
|
}
|
|
723
675
|
throw new Error(`Unsupported MCP method: ${method}`);
|
|
724
676
|
}
|
|
725
|
-
function
|
|
677
|
+
export function completionToolRejectedResult(toolName, error, input) {
|
|
678
|
+
const issues = error instanceof CompletionPayloadValidationError
|
|
679
|
+
? [...error.issues]
|
|
680
|
+
: [errorMessage(error)];
|
|
681
|
+
if (input !== undefined && isEmptyToolInput(input)) {
|
|
682
|
+
issues.push(`${emptyToolInputHint} Keep long free text such as report_markdown short.`);
|
|
683
|
+
}
|
|
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.";
|
|
685
|
+
return {
|
|
686
|
+
content: [{
|
|
687
|
+
type: "text",
|
|
688
|
+
text: `Forge rejected ${toolName}. No artifact was written.\n${issues.map(issue => `- ${issue}`).join("\n")}\n${repairInstruction}`,
|
|
689
|
+
}],
|
|
690
|
+
structuredContent: {
|
|
691
|
+
status: "rejected",
|
|
692
|
+
tool_name: toolName,
|
|
693
|
+
artifact_written: false,
|
|
694
|
+
issues,
|
|
695
|
+
repair_instruction: repairInstruction,
|
|
696
|
+
},
|
|
697
|
+
isError: true,
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
function acceptedArtifactReceipt(reference) {
|
|
701
|
+
return {
|
|
702
|
+
artifact_written: true,
|
|
703
|
+
artifact_receipt: {
|
|
704
|
+
schema_version: 1,
|
|
705
|
+
path: reference.path,
|
|
706
|
+
report_path: reference.reportPath,
|
|
707
|
+
content_hash: reference.contentHash,
|
|
708
|
+
},
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
function toolDefinition(name) {
|
|
726
712
|
return {
|
|
727
713
|
name,
|
|
728
|
-
description: toolDescription(
|
|
729
|
-
inputSchema:
|
|
714
|
+
description: toolDescription(phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name), draftGateFromToolName(name)),
|
|
715
|
+
inputSchema: completionToolInputSchema(name)
|
|
730
716
|
};
|
|
731
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>;
|