@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0f07274d438b
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 +128 -4
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- 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 +15 -0
- package/dist/bridge/bridge-state-io.js +68 -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.service.d.ts +29 -12
- package/dist/bridge/bridge.service.js +215 -380
- package/dist/bridge/bridge.types.d.ts +21 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -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 +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +57 -13
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +20 -213
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +14 -1
- package/dist/cli/local-config.js +42 -2
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- 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 +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -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/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +13 -0
- package/dist/runtime/host-load-child-environment.js +35 -1
- package/dist/runtime/host-load-governor-config.d.ts +33 -3
- package/dist/runtime/host-load-governor-config.js +24 -3
- package/dist/runtime/host-load-governor.d.ts +91 -2
- package/dist/runtime/host-load-governor.js +217 -18
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -0
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +25 -1
- package/dist/runtime/host-load-sampler.js +38 -7
- package/dist/runtime/host-load-step-run.d.ts +37 -3
- package/dist/runtime/host-load-step-run.js +63 -7
- package/dist/runtime/host-load-test-slot.d.ts +3 -0
- package/dist/runtime/host-load-test-slot.js +26 -7
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +35 -5
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +4 -0
- package/dist/runtime/runner-settings.js +22 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +1 -2
- package/dist/sandbox/runtime.js +9 -19
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +54 -109
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +10 -5
- package/dist/session/managed-command-host-load.js +18 -14
- package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +2 -17
- package/dist/session/phase-completion.artifacts.js +65 -166
- package/dist/session/phase-completion.d.ts +27 -2
- package/dist/session/phase-completion.helpers.js +5 -53
- package/dist/session/phase-completion.js +15 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +14 -0
- package/dist/session/phase-completion.runtime.d.ts +8 -9
- package/dist/session/phase-completion.runtime.js +65 -196
- package/dist/session/phase-completion.schemas.js +12 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +9 -1
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.js +6 -5
- 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-process.js +13 -12
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +9 -4
- package/dist/session/pre-publication-validation.js +62 -65
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -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/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +41 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
- package/dist/session/provider-cli/provider-cli.service.js +59 -190
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- 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-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -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 +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +63 -22
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +8 -1
- package/dist/session/session.service.js +177 -239
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +9 -79
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -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/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +18 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +49 -5
- package/dist/worktree/worktree.service.js +223 -187
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -1,15 +1,16 @@
|
|
|
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,
|
|
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";
|
|
9
8
|
import { isHostLoadChildEnvironmentName } from "../runtime/host-load-child-environment.js";
|
|
9
|
+
import { isProviderUserConfigIsolated, providerUserConfigIsolationUnsupported } from "./provider-cli/provider-user-config-isolation.js";
|
|
10
10
|
import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
|
|
11
11
|
import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
|
|
12
12
|
import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
|
|
13
|
+
import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
|
|
13
14
|
import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
|
|
14
15
|
export async function prepareCompletionToolRuntime(options) {
|
|
15
16
|
const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
|
|
@@ -17,6 +18,8 @@ export async function prepareCompletionToolRuntime(options) {
|
|
|
17
18
|
const workItemId = options.dispatch.workItem.id;
|
|
18
19
|
const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
|
|
19
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;
|
|
20
23
|
const mcpArgs = buildCompletionToolServerArgs({
|
|
21
24
|
worktreePath,
|
|
22
25
|
workItemId,
|
|
@@ -24,15 +27,18 @@ export async function prepareCompletionToolRuntime(options) {
|
|
|
24
27
|
ownerId,
|
|
25
28
|
phase,
|
|
26
29
|
producedBy: `${options.dispatch.execution.provider}-cli`,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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")
|
|
34
39
|
&& !isDecomposeDispatch(options.dispatch),
|
|
35
|
-
decomposeCycle: isDecomposeDispatch(options.dispatch)
|
|
40
|
+
decomposeCycle: cycles && isDecomposeDispatch(options.dispatch),
|
|
41
|
+
prReview: phase === "pr_review" ? prReviewContextFromDispatch(options.dispatch) : undefined
|
|
36
42
|
});
|
|
37
43
|
const runtime = {
|
|
38
44
|
serverName: toolServerName,
|
|
@@ -42,49 +48,32 @@ export async function prepareCompletionToolRuntime(options) {
|
|
|
42
48
|
cleanup: async () => undefined
|
|
43
49
|
};
|
|
44
50
|
const provider = options.dispatch.execution.provider.trim().toLowerCase();
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
// Provider phases refuse these at entry (admitUserConfigIsolatedProvider, provider-cli.runtime.ts);
|
|
52
|
+
// this guards any other caller before the Claude MCP config is written.
|
|
53
|
+
if (!isProviderUserConfigIsolated(provider)) {
|
|
54
|
+
throw providerUserConfigIsolationUnsupported(options.dispatch.execution.provider);
|
|
47
55
|
}
|
|
48
56
|
if (provider === "claude") {
|
|
49
57
|
return await prepareClaudeCompletionToolRuntime(runtime);
|
|
50
58
|
}
|
|
51
59
|
return runtime;
|
|
52
60
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"--produced-by",
|
|
63
|
-
config.producedBy ?? "forge-completion-tool"
|
|
64
|
-
];
|
|
65
|
-
if (config.ownerType || config.ownerId) {
|
|
66
|
-
args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
|
|
67
|
-
args.push("--owner-id", config.ownerId ?? config.workItemId);
|
|
68
|
-
}
|
|
69
|
-
if (config.developCycle) {
|
|
70
|
-
args.push("--develop-cycle");
|
|
71
|
-
}
|
|
72
|
-
if (config.qaCycle) {
|
|
73
|
-
args.push("--qa-cycle");
|
|
74
|
-
}
|
|
75
|
-
if (config.debugCycle) {
|
|
76
|
-
args.push("--debug-cycle");
|
|
77
|
-
}
|
|
78
|
-
if (config.architectCycle) {
|
|
79
|
-
args.push("--architect-cycle");
|
|
80
|
-
}
|
|
81
|
-
if (config.draftCycle) {
|
|
82
|
-
args.push("--draft-cycle");
|
|
83
|
-
}
|
|
84
|
-
if (config.decomposeCycle) {
|
|
85
|
-
args.push("--decompose-cycle");
|
|
61
|
+
/**
|
|
62
|
+
* The pull-request facts the pr_review completion tool holds a review to: the admitted head
|
|
63
|
+
* (prReview.headSha, never the live pull request head) and the prior review threads the
|
|
64
|
+
* dispatch lists, and the dispatched base commit the payload's base_sha must resolve to.
|
|
65
|
+
*/
|
|
66
|
+
export function prReviewContextFromDispatch(dispatch) {
|
|
67
|
+
const prReview = dispatch.prReview;
|
|
68
|
+
if (!prReview) {
|
|
69
|
+
return undefined;
|
|
86
70
|
}
|
|
87
|
-
|
|
71
|
+
const threadIds = prReview.priorThreads.map((thread) => thread.threadId);
|
|
72
|
+
return {
|
|
73
|
+
headSha: prReview.headSha.trim() || undefined,
|
|
74
|
+
baseSha: prReview.baseSha.trim() || undefined,
|
|
75
|
+
threadIds: threadIds.length > 0 ? threadIds : undefined
|
|
76
|
+
};
|
|
88
77
|
}
|
|
89
78
|
export function codexMcpConfigArgs(runtime) {
|
|
90
79
|
const prefix = `mcp_servers.${runtime.serverName}`;
|
|
@@ -133,6 +122,10 @@ export function completionToolNamesForServer(config) {
|
|
|
133
122
|
? completionToolNamesForPhase("architect")
|
|
134
123
|
: completionToolNamesForPhase(config.phase);
|
|
135
124
|
}
|
|
125
|
+
const managedToolsOnlyInstructions = "Forge serves only its managed-attempt tools in this turn: "
|
|
126
|
+
+ "forge.start_managed_verification, forge.start_managed_command, forge.wait_managed_command, forge.get_managed_command, "
|
|
127
|
+
+ "forge.run_managed_command and forge.reset_generated_outputs. No completion tool is available; the phase's completion "
|
|
128
|
+
+ "artifacts are already recorded and must stay as they are.";
|
|
136
129
|
export class CompletionToolServerSession {
|
|
137
130
|
config;
|
|
138
131
|
currentPhase;
|
|
@@ -146,20 +139,24 @@ export class CompletionToolServerSession {
|
|
|
146
139
|
this.currentPhase = config.phase;
|
|
147
140
|
}
|
|
148
141
|
get instructions() {
|
|
149
|
-
return this.config.
|
|
150
|
-
?
|
|
151
|
-
: this.config.
|
|
152
|
-
?
|
|
153
|
-
: this.config.
|
|
154
|
-
?
|
|
155
|
-
: this.config.
|
|
156
|
-
?
|
|
157
|
-
: this.config.
|
|
158
|
-
?
|
|
159
|
-
:
|
|
142
|
+
return this.config.managedToolsOnly
|
|
143
|
+
? managedToolsOnlyInstructions
|
|
144
|
+
: this.config.decomposeCycle
|
|
145
|
+
? completionPromptForDecomposeCycle(this.currentDecomposeGate)
|
|
146
|
+
: this.config.draftCycle
|
|
147
|
+
? completionPromptForDraftCycle(this.currentDraftGate)
|
|
148
|
+
: this.config.debugCycle
|
|
149
|
+
? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
|
|
150
|
+
: this.config.qaCycle
|
|
151
|
+
? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
|
|
152
|
+
: this.config.developCycle
|
|
153
|
+
? completionPromptForDevelopCycle(this.currentPhase)
|
|
154
|
+
: completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
|
|
160
155
|
}
|
|
161
156
|
toolDefinitions() {
|
|
162
|
-
const completionTools =
|
|
157
|
+
const completionTools = this.config.managedToolsOnly
|
|
158
|
+
? []
|
|
159
|
+
: completionToolNamesForServer(this.config).map(toolDefinition);
|
|
163
160
|
return managedAttemptToolsAvailable()
|
|
164
161
|
? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
|
|
165
162
|
: completionTools;
|
|
@@ -176,6 +173,9 @@ export class CompletionToolServerSession {
|
|
|
176
173
|
}
|
|
177
174
|
return result;
|
|
178
175
|
}
|
|
176
|
+
if (this.config.managedToolsOnly) {
|
|
177
|
+
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.`);
|
|
178
|
+
}
|
|
179
179
|
const requestedPhase = phaseFromToolName(toolName);
|
|
180
180
|
// Clients sometimes send a declared array/object argument as its JSON text.
|
|
181
181
|
const input = coerceJsonStringArguments(rawInput, completionToolInputSchema(toolName));
|
|
@@ -200,7 +200,8 @@ export class CompletionToolServerSession {
|
|
|
200
200
|
const completedPhase = this.currentPhase;
|
|
201
201
|
const reference = await writeCompletionArtifact({ ...this.config, phase: completedPhase }, toolName, input);
|
|
202
202
|
const status = reference.status.trim().toLowerCase();
|
|
203
|
-
|
|
203
|
+
// pr_review accepts reviewed, stale_head and blocked; each ends the lane, and an invalid payload throws above.
|
|
204
|
+
const pass = completedPhase === "pr_review" || status === "pass";
|
|
204
205
|
const nextPhase = pass
|
|
205
206
|
? this.advanceAfterPass(completedPhase)
|
|
206
207
|
: completedPhase;
|
|
@@ -383,6 +384,10 @@ export class CompletionToolServerSession {
|
|
|
383
384
|
};
|
|
384
385
|
}
|
|
385
386
|
advanceAfterPass(phase) {
|
|
387
|
+
if (phase === "pr_review") {
|
|
388
|
+
this.completed = true;
|
|
389
|
+
return "pr_review_complete";
|
|
390
|
+
}
|
|
386
391
|
if (phase === "qa") {
|
|
387
392
|
this.completed = true;
|
|
388
393
|
return "sign_off_ready";
|
|
@@ -491,7 +496,7 @@ export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestP
|
|
|
491
496
|
env[name] = value.trim();
|
|
492
497
|
}
|
|
493
498
|
// Managed verification reads the operator's native test cluster only through
|
|
494
|
-
// this explicit path
|
|
499
|
+
// this explicit path; the file's `use` decides whether Docker comes first.
|
|
495
500
|
if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
|
|
496
501
|
env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
|
|
497
502
|
}
|
|
@@ -599,148 +604,12 @@ export async function runCompletionMcpServer(config) {
|
|
|
599
604
|
}
|
|
600
605
|
});
|
|
601
606
|
}
|
|
602
|
-
export function parseCompletionMcpArgs(argv) {
|
|
603
|
-
let worktreePath = null;
|
|
604
|
-
let workItemId = null;
|
|
605
|
-
let phase = "implementation";
|
|
606
|
-
let ownerType;
|
|
607
|
-
let ownerId;
|
|
608
|
-
let producedBy;
|
|
609
|
-
let developCycle = false;
|
|
610
|
-
let qaCycle = false;
|
|
611
|
-
let debugCycle = false;
|
|
612
|
-
let architectCycle = false;
|
|
613
|
-
let draftCycle = false;
|
|
614
|
-
let decomposeCycle = false;
|
|
615
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
616
|
-
const arg = argv[index];
|
|
617
|
-
if (arg === "--worktree") {
|
|
618
|
-
worktreePath = argv[++index] ?? null;
|
|
619
|
-
}
|
|
620
|
-
else if (arg === "--work-item-id") {
|
|
621
|
-
workItemId = argv[++index] ?? null;
|
|
622
|
-
}
|
|
623
|
-
else if (arg === "--owner-type") {
|
|
624
|
-
ownerType = normalizedOwnerType(argv[++index]);
|
|
625
|
-
if (!ownerType) {
|
|
626
|
-
return { ok: false, error: "mcp --owner-type must be work_item or story." };
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
else if (arg === "--owner-id") {
|
|
630
|
-
ownerId = argv[++index] ?? undefined;
|
|
631
|
-
}
|
|
632
|
-
else if (arg === "--phase") {
|
|
633
|
-
const rawPhase = argv[++index];
|
|
634
|
-
const parsedPhase = parseStrictCompletionPhase(rawPhase);
|
|
635
|
-
if (!parsedPhase) {
|
|
636
|
-
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." };
|
|
637
|
-
}
|
|
638
|
-
phase = parsedPhase;
|
|
639
|
-
}
|
|
640
|
-
else if (arg === "--produced-by") {
|
|
641
|
-
producedBy = argv[++index] ?? undefined;
|
|
642
|
-
}
|
|
643
|
-
else if (arg === "--develop-cycle") {
|
|
644
|
-
developCycle = true;
|
|
645
|
-
}
|
|
646
|
-
else if (arg === "--qa-cycle") {
|
|
647
|
-
qaCycle = true;
|
|
648
|
-
}
|
|
649
|
-
else if (arg === "--debug-cycle") {
|
|
650
|
-
debugCycle = true;
|
|
651
|
-
}
|
|
652
|
-
else if (arg === "--architect-cycle") {
|
|
653
|
-
architectCycle = true;
|
|
654
|
-
}
|
|
655
|
-
else if (arg === "--draft-cycle") {
|
|
656
|
-
draftCycle = true;
|
|
657
|
-
}
|
|
658
|
-
else if (arg === "--decompose-cycle") {
|
|
659
|
-
decomposeCycle = true;
|
|
660
|
-
}
|
|
661
|
-
else {
|
|
662
|
-
return { ok: false, error: `Unknown mcp argument: ${arg}` };
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
if (!worktreePath?.trim() || !workItemId?.trim()) {
|
|
666
|
-
return { ok: false, error: "mcp requires --worktree and --work-item-id." };
|
|
667
|
-
}
|
|
668
|
-
if ([developCycle, qaCycle, debugCycle, architectCycle, draftCycle, decomposeCycle].filter(Boolean).length > 1) {
|
|
669
|
-
return { ok: false, error: "mcp accepts only one cycle mode." };
|
|
670
|
-
}
|
|
671
|
-
if (developCycle && !isDevelopCompletionPhase(phase)) {
|
|
672
|
-
return { ok: false, error: "mcp --develop-cycle requires --phase implementation, self-review, or validation." };
|
|
673
|
-
}
|
|
674
|
-
if (qaCycle && phase !== "qa") {
|
|
675
|
-
return { ok: false, error: "mcp --qa-cycle requires --phase qa." };
|
|
676
|
-
}
|
|
677
|
-
if (debugCycle && !isDebugCompletionPhase(phase)) {
|
|
678
|
-
return { ok: false, error: "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression." };
|
|
679
|
-
}
|
|
680
|
-
if (architectCycle && phase !== "architect") {
|
|
681
|
-
return { ok: false, error: "mcp --architect-cycle requires --phase architect." };
|
|
682
|
-
}
|
|
683
|
-
if (draftCycle && phase !== "draft") {
|
|
684
|
-
return { ok: false, error: "mcp --draft-cycle requires --phase draft." };
|
|
685
|
-
}
|
|
686
|
-
if (decomposeCycle && phase !== "decompose") {
|
|
687
|
-
return { ok: false, error: "mcp --decompose-cycle requires --phase decompose." };
|
|
688
|
-
}
|
|
689
|
-
return {
|
|
690
|
-
ok: true,
|
|
691
|
-
config: {
|
|
692
|
-
worktreePath: path.resolve(worktreePath),
|
|
693
|
-
workItemId,
|
|
694
|
-
ownerType,
|
|
695
|
-
ownerId,
|
|
696
|
-
phase,
|
|
697
|
-
producedBy,
|
|
698
|
-
redactionSecrets: [
|
|
699
|
-
...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
|
|
700
|
-
...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
|
|
701
|
-
],
|
|
702
|
-
developCycle,
|
|
703
|
-
qaCycle,
|
|
704
|
-
debugCycle,
|
|
705
|
-
architectCycle,
|
|
706
|
-
draftCycle,
|
|
707
|
-
decomposeCycle
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
607
|
export function completionRedactionEnv(secrets) {
|
|
712
608
|
const filtered = secrets.filter((secret) => secret.length > 0);
|
|
713
609
|
return filtered.length > 0
|
|
714
610
|
? { [completionRedactionSecretsEnv]: JSON.stringify(filtered) }
|
|
715
611
|
: {};
|
|
716
612
|
}
|
|
717
|
-
async function prepareCursorCompletionToolRuntime(worktreePath, runtime) {
|
|
718
|
-
const cursorDir = path.join(worktreePath, ".cursor");
|
|
719
|
-
const configPath = path.join(cursorDir, "mcp.json");
|
|
720
|
-
const original = await fs.readFile(configPath, "utf8").then((content) => ({ existed: true, content }), () => ({ existed: false, content: "" }));
|
|
721
|
-
const existing = original.existed ? parseOptionalJsonObject(original.content, configPath) : {};
|
|
722
|
-
const servers = asMutableRecord(existing.mcpServers);
|
|
723
|
-
servers[runtime.serverName] = cursorMcpServerConfig(runtime);
|
|
724
|
-
const next = {
|
|
725
|
-
...existing,
|
|
726
|
-
mcpServers: servers
|
|
727
|
-
};
|
|
728
|
-
await fs.mkdir(cursorDir, { recursive: true });
|
|
729
|
-
await writeFileAtomic(configPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
730
|
-
return {
|
|
731
|
-
...runtime,
|
|
732
|
-
cursorMcpConfigPath: configPath,
|
|
733
|
-
cleanup: async () => {
|
|
734
|
-
if (original.existed) {
|
|
735
|
-
await writeFileAtomic(configPath, original.content);
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
738
|
-
await fs.rm(configPath, { force: true });
|
|
739
|
-
await fs.rmdir(cursorDir).catch(() => undefined);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
613
|
/**
|
|
745
614
|
* Claude Code takes MCP servers from `--mcp-config <file>`. The file lives in an attempt-owned
|
|
746
615
|
* temp directory (never the worktree) because its env block can carry redaction secrets, and
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { decomposeGateFileNames, decomposeStatuses, draftStatuses, isDebugCompletionPhase, phaseFiles, qaBlockerReasons, qaGateFileNames } from "./phase-completion.js";
|
|
2
2
|
import { browserCheckSchema, qaSidecarsSchema, qaEvidenceWrapperSchema, qaGateEvidenceWrapperSchema, findingEvidenceSchema, objectToolSchema, evidenceObjectSchema, qaScopeSchema, commandEvidenceSchema, resolvedFindingSchema, acceptanceCriteriaSchema, reviewSectionSchema, reviewSectionProperties } from "./phase-completion.schema-parts.js";
|
|
3
|
+
import { prReviewToolInputSchema } from "./phase-completion.pr-review-schema.js";
|
|
3
4
|
import { architectNonPassProperties } from "./architect-waits.js";
|
|
4
5
|
export function toolDescription(phase, qaGate = null, decomposeGate = null, draftGate = null) {
|
|
5
6
|
if (qaGate) {
|
|
@@ -30,6 +31,9 @@ export function toolDescription(phase, qaGate = null, decomposeGate = null, draf
|
|
|
30
31
|
if (phase === "comment_repair") {
|
|
31
32
|
return "Complete Forge pull-request comment repair by recording one evidence-backed disposition for every actionable finding in the dispatch snapshot.";
|
|
32
33
|
}
|
|
34
|
+
if (phase === "pr_review") {
|
|
35
|
+
return "Complete Forge pull-request review by recording one comment-only review bound to the reviewed head: a verdict, overview, security summary, and inline comments anchored on new-side diff lines. Forge posts it afterwards; this tool does not publish. Use stale_head when the worktree is not at the dispatched head and blocked when the diff cannot be read.";
|
|
36
|
+
}
|
|
33
37
|
if (phase === "self_review") {
|
|
34
38
|
return "Complete Forge self-review by writing self-review.report.json with diff review, findings, security, edge-case, design, deterministic-comparison, fixes, and remaining-risk evidence.";
|
|
35
39
|
}
|
|
@@ -41,8 +45,8 @@ export function toolDescription(phase, qaGate = null, decomposeGate = null, draf
|
|
|
41
45
|
}
|
|
42
46
|
return "Complete Forge validation by writing validation.verdict.json with command, build/test/lint/design, drift, acceptance-criteria, and ready-for-dev-test evidence.";
|
|
43
47
|
}
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
function baseToolProperties() {
|
|
49
|
+
return {
|
|
46
50
|
status: {
|
|
47
51
|
type: "string",
|
|
48
52
|
enum: ["pass", "needs_rework", "fail", "failed"],
|
|
@@ -60,6 +64,9 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
|
|
|
60
64
|
})
|
|
61
65
|
}
|
|
62
66
|
};
|
|
67
|
+
}
|
|
68
|
+
export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draftGate = null) {
|
|
69
|
+
const baseProperties = baseToolProperties();
|
|
63
70
|
if (qaGate && qaGate !== "qa_verdict") {
|
|
64
71
|
return qaGateToolInputSchema(qaGate);
|
|
65
72
|
}
|
|
@@ -204,6 +211,9 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
|
|
|
204
211
|
}
|
|
205
212
|
}, ["status", "summary", "repair_head_sha", "repair_issue_key", "dispositions", "changed_files", "validation"], "Use status pass after every actionable finding has an evidence-backed disposition. Rejected and needs_decision are legitimate outcomes and must not be disguised as code changes.");
|
|
206
213
|
}
|
|
214
|
+
if (phase === "pr_review") {
|
|
215
|
+
return prReviewToolInputSchema();
|
|
216
|
+
}
|
|
207
217
|
if (phase === "implementation") {
|
|
208
218
|
return objectToolSchema({
|
|
209
219
|
...baseProperties,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CompletionPhase, type DebugCompletionPhase, type QaCompletionGate } from "./phase-completion.js";
|
|
2
2
|
export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
|
|
3
|
+
export { validatePrReviewPayloadShape } from "./phase-completion.pr-review-validation.js";
|
|
3
4
|
export declare const qaEvidenceGates: ReadonlySet<QaCompletionGate>;
|
|
4
5
|
export declare function normalizeCompletionStatus(value: string, phase?: CompletionPhase): string;
|
|
5
6
|
export declare function normalizeQaGateStatus(value: string): string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces } from "./phase-completion.js";
|
|
1
|
+
import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces, prReviewStatuses } from "./phase-completion.js";
|
|
2
2
|
import { structuredTypeHint } from "./mcp-argument-coercion.js";
|
|
3
3
|
import { validateArchitectWaits } from "./architect-waits.js";
|
|
4
4
|
import { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
|
|
5
5
|
export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
|
|
6
|
+
export { validatePrReviewPayloadShape } from "./phase-completion.pr-review-validation.js";
|
|
6
7
|
export const qaEvidenceGates = new Set(["qa_regression", "qa_api", "qa_manual_web", "qa_bug_repro"]);
|
|
7
8
|
export function normalizeCompletionStatus(value, phase) {
|
|
8
9
|
const normalized = value.trim().toLowerCase().replace(/-/g, "_");
|
|
@@ -13,6 +14,13 @@ export function normalizeCompletionStatus(value, phase) {
|
|
|
13
14
|
}
|
|
14
15
|
return canonical;
|
|
15
16
|
}
|
|
17
|
+
if (phase === "pr_review") {
|
|
18
|
+
const canonical = normalized === "stalehead" ? "stale_head" : normalized;
|
|
19
|
+
if (!prReviewStatuses.includes(canonical)) {
|
|
20
|
+
throw new Error(`pr_review status must be one of ${prReviewStatuses.join(", ")}.`);
|
|
21
|
+
}
|
|
22
|
+
return canonical;
|
|
23
|
+
}
|
|
16
24
|
if (phase === "architect") {
|
|
17
25
|
const canonical = normalized === "needsrevision" ? "needs_revision" : normalized;
|
|
18
26
|
if (canonical !== "pass" && canonical !== "needs_revision" && canonical !== "blocked") {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RunOnceDispatchPacket } from "./session.types.js";
|
|
2
|
+
/** Runs git in the review's repository: resolves with stdout, rejects when git fails. */
|
|
3
|
+
export type ReviewDiffBaseGit = (args: readonly string[]) => Promise<string>;
|
|
4
|
+
/**
|
|
5
|
+
* The commit a Forge PR review diffs against: the merge base of the dispatched base and the head, the
|
|
6
|
+
* same `base...head` diff the pull request shows. The provider's base (GitHub's `base.sha`) is the base
|
|
7
|
+
* branch tip at the pull request's last sync, which is not an ancestor of the head once the base moves
|
|
8
|
+
* on and the branch has not merged it; a Docker sandbox imports only the head's ancestry, so that tip
|
|
9
|
+
* is not there, but the merge base always is. Resolved with the bridge's own git, fetching the base by
|
|
10
|
+
* its SHA when the checkout lacks it and falling back to the base branch on origin when the base commit
|
|
11
|
+
* is gone. Null when the dispatch is not a review or no base can be found: the dispatch is then unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveReviewDiffBase(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "prReview" | "pullRequest">, git: ReviewDiffBaseGit): Promise<string | null>;
|
|
14
|
+
/**
|
|
15
|
+
* The dispatch with its review base set to the diff base, keeping the base tip it replaced, so the prompt,
|
|
16
|
+
* the completion tool's anchor check and the recorded review all use one commit that is in the worktree.
|
|
17
|
+
*/
|
|
18
|
+
export declare function withReviewDiffBase(dispatch: RunOnceDispatchPacket, diffBase: string | null): RunOnceDispatchPacket;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { prReviewDispatchHeadSha } from "./pr-review-placement.js";
|
|
2
|
+
const fullObjectId = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u;
|
|
3
|
+
/**
|
|
4
|
+
* The commit a Forge PR review diffs against: the merge base of the dispatched base and the head, the
|
|
5
|
+
* same `base...head` diff the pull request shows. The provider's base (GitHub's `base.sha`) is the base
|
|
6
|
+
* branch tip at the pull request's last sync, which is not an ancestor of the head once the base moves
|
|
7
|
+
* on and the branch has not merged it; a Docker sandbox imports only the head's ancestry, so that tip
|
|
8
|
+
* is not there, but the merge base always is. Resolved with the bridge's own git, fetching the base by
|
|
9
|
+
* its SHA when the checkout lacks it and falling back to the base branch on origin when the base commit
|
|
10
|
+
* is gone. Null when the dispatch is not a review or no base can be found: the dispatch is then unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export async function resolveReviewDiffBase(dispatch, git) {
|
|
13
|
+
const headSha = prReviewDispatchHeadSha(dispatch);
|
|
14
|
+
const baseSha = (dispatch.prReview?.baseSha ?? "").trim().toLowerCase();
|
|
15
|
+
if (!headSha || !baseSha) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const commit = async (rev) => {
|
|
19
|
+
const sha = (await git(["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]).catch(() => "")).trim().toLowerCase();
|
|
20
|
+
return fullObjectId.test(sha) ? sha : null;
|
|
21
|
+
};
|
|
22
|
+
let base = await commit(baseSha);
|
|
23
|
+
if (!base) {
|
|
24
|
+
await git(["fetch", "--no-tags", "--no-write-fetch-head", "origin", baseSha]).catch(() => undefined);
|
|
25
|
+
const baseBranch = (dispatch.prReview?.baseBranch || dispatch.cycleRun.baseBranch || "").trim();
|
|
26
|
+
base = await commit(baseSha) ?? (baseBranch ? await commit(`refs/remotes/origin/${baseBranch}`) : null);
|
|
27
|
+
}
|
|
28
|
+
if (!base) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const mergeBase = (await git(["merge-base", base, headSha]).catch(() => "")).trim().toLowerCase();
|
|
32
|
+
return fullObjectId.test(mergeBase) ? mergeBase : null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The dispatch with its review base set to the diff base, keeping the base tip it replaced, so the prompt,
|
|
36
|
+
* the completion tool's anchor check and the recorded review all use one commit that is in the worktree.
|
|
37
|
+
*/
|
|
38
|
+
export function withReviewDiffBase(dispatch, diffBase) {
|
|
39
|
+
const prReview = dispatch.prReview;
|
|
40
|
+
if (!diffBase || !prReview || prReview.baseSha.trim().toLowerCase() === diffBase) {
|
|
41
|
+
return dispatch;
|
|
42
|
+
}
|
|
43
|
+
return { ...dispatch, prReview: { ...prReview, baseSha: diffBase, baseTipSha: prReview.baseTipSha || prReview.baseSha } };
|
|
44
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type RunnerDispatchEvent, type RunOnceDispatchPacket, type RunOnceResultPacket } from "./session.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where a Forge PR review may run. A review reads pull request code an author controls, and the only
|
|
4
|
+
* operating-system isolation this bridge enforces is its Docker sandbox: a container with no git
|
|
5
|
+
* credential, no remote and no host home directory. On a plain host the provider runs as the
|
|
6
|
+
* bridge's user, beside that user's git credentials and provider sign-in, and the review guardrails
|
|
7
|
+
* (credential-free git environment, tool deny rules, command shims, the post-run ref and remote-head
|
|
8
|
+
* checks) are defence in depth, not a boundary. So a review placed on the host is refused before any
|
|
9
|
+
* provider starts unless the runner's owner opted in with `allowUnsandboxedPrReview: true` in
|
|
10
|
+
* bridge.json, accepting that risk.
|
|
11
|
+
*/
|
|
12
|
+
export declare const prReviewUnsandboxedHostCode = "pr_review.unsandboxed_host";
|
|
13
|
+
/**
|
|
14
|
+
* A review placed in this bridge's Docker sandbox for a project whose sandbox contract it cannot read or build:
|
|
15
|
+
* refused before any provider starts, and never retried on this runner (a capacity wait would only expire).
|
|
16
|
+
*/
|
|
17
|
+
export declare const prReviewSandboxUnavailableCode = "pr_review.sandbox_unavailable";
|
|
18
|
+
/** The execution facility a runner advertises when its owner opted in to host-placed reviews. */
|
|
19
|
+
export declare const prReviewUnsandboxedHostFacility = "pr_review_unsandboxed_host";
|
|
20
|
+
/** The warning a host-placed review carries when the runner's owner opted in. */
|
|
21
|
+
export declare const prReviewUnsandboxedHostWarningEvent = "pr_review_unsandboxed_host_warning";
|
|
22
|
+
/** A dispatch for the review-only pr_review session, by role, lane or cycle kind. */
|
|
23
|
+
export declare function isPrReviewDispatch(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun">): boolean;
|
|
24
|
+
/** The pull request head a review dispatch reads, lowercased, or null for any other dispatch. */
|
|
25
|
+
export declare function prReviewDispatchHeadSha(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "prReview" | "pullRequest">): string | null;
|
|
26
|
+
/** Why this bridge refuses the dispatch, or null: a review placed outside Docker without the opt-in. */
|
|
27
|
+
export declare function prReviewPlacementRefusal(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): string | null;
|
|
28
|
+
/** The warning for a review that runs on the host because the runner's owner opted in, or null. */
|
|
29
|
+
export declare function prReviewUnsandboxedHostWarning(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): string | null;
|
|
30
|
+
/** The terminal failure for a refused review (see {@link prReviewPlacementRefusal}), or null. */
|
|
31
|
+
export declare function prReviewPlacementRefusalResult(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): RunOnceResultPacket | null;
|
|
32
|
+
/**
|
|
33
|
+
* Set by the server-local runner on a run-once whose Forge PR review it admitted on its host (in its container
|
|
34
|
+
* sandbox, or because the runner opted in to host reviews). Nothing else sets it.
|
|
35
|
+
*/
|
|
36
|
+
export declare const prReviewHostAdmittedEnv = "FORGE_PR_REVIEW_HOST_ADMITTED";
|
|
37
|
+
/**
|
|
38
|
+
* forge-bridge run-once (which the server-local runner launches): a Forge PR review placed outside Docker runs
|
|
39
|
+
* only when the server-local runner admitted it on this host; any other is refused before a provider starts.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runOnceWithReviewPlacement(dispatch: RunOnceDispatchPacket, run: (dispatch: RunOnceDispatchPacket) => Promise<RunOnceResultPacket>, env?: NodeJS.ProcessEnv): Promise<RunOnceResultPacket>;
|
|
42
|
+
/** The execution facilities that tell Forge this runner's owner opted in to host-placed reviews. */
|
|
43
|
+
export declare function prReviewExecutionFacilities(allowUnsandboxedPrReview: boolean | undefined): readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* Runs the dispatch; a review that runs on the host by the owner's opt-in is logged, announced as a
|
|
46
|
+
* session event and reported in the result summary as a warning.
|
|
47
|
+
*/
|
|
48
|
+
export declare function runWithUnsandboxedReviewWarning(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined, sink: {
|
|
49
|
+
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
50
|
+
}, log: (message: string) => void, run: () => Promise<RunOnceResultPacket>): Promise<RunOnceResultPacket>;
|