@loucompanion/forge-bridge 0.2.1-dev.4f11ffc822f9 → 0.2.1-dev.7171bf414613
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 +41 -3
- package/dist/bridge/bridge-state-io.d.ts +6 -2
- package/dist/bridge/bridge-state-io.js +22 -4
- package/dist/bridge/bridge.service.d.ts +10 -0
- package/dist/bridge/bridge.service.js +63 -101
- package/dist/bridge/bridge.types.d.ts +16 -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/runner-host-capabilities.js +14 -1
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.js +3 -3
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cli/cli.help.js +1 -1
- package/dist/cli/cli.service.js +11 -43
- package/dist/cli/local-config.d.ts +12 -1
- package/dist/cli/local-config.js +35 -1
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- 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 +89 -2
- package/dist/runtime/host-load-governor.js +217 -18
- 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-sampler.d.ts +17 -0
- package/dist/runtime/host-load-sampler.js +24 -0
- 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.js +6 -4
- package/dist/runtime/prepared-runtime-readiness.d.ts +12 -2
- package/dist/runtime/prepared-runtime-readiness.js +35 -11
- package/dist/sandbox/runtime.d.ts +1 -2
- package/dist/sandbox/runtime.js +8 -14
- 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.js +6 -29
- package/dist/session/managed-build-receipt.d.ts +3 -1
- package/dist/session/managed-build-receipt.js +5 -2
- 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 +63 -165
- package/dist/session/phase-completion.d.ts +25 -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.js +69 -2
- 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-threads.d.ts +34 -0
- package/dist/session/phase-completion.pr-review-threads.js +90 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +215 -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.js +9 -3
- 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 +45 -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-process.js +3 -2
- package/dist/session/pre-publication-validation.d.ts +2 -1
- package/dist/session/pre-publication-validation.js +31 -36
- 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/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 +11 -0
- package/dist/session/provider-cli/pr-review-prompt.js +132 -0
- package/dist/session/provider-cli/pre-publication-repair.js +8 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- 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.prompts.d.ts +10 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +123 -70
- 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 +7 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
- 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 +11 -17
- package/dist/session/provider-cli/provider-cli.service.js +33 -148
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- package/dist/session/sandbox-host-capacity-gate.js +29 -7
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- 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 +2 -1
- package/dist/session/session.service.js +57 -158
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +8 -78
- package/dist/session/session.types.pr-review.d.ts +59 -0
- package/dist/session/session.types.pr-review.js +53 -0
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +9 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/wip-git.d.ts +25 -0
- package/dist/worktree/wip-git.js +64 -4
- package/dist/worktree/wip-refs.d.ts +23 -0
- package/dist/worktree/wip-refs.js +52 -2
- package/dist/worktree/wip-restore.d.ts +13 -0
- package/dist/worktree/wip-restore.js +159 -25
- package/dist/worktree/wip-snapshot.d.ts +5 -2
- package/dist/worktree/wip-snapshot.js +15 -13
- package/dist/worktree/worktree-origin-sync.d.ts +1 -0
- package/dist/worktree/worktree-origin-sync.js +1 -0
- package/dist/worktree/worktree-wip-events.d.ts +2 -0
- package/dist/worktree/worktree-wip-events.js +53 -3
- package/dist/worktree/worktree-wip.d.ts +7 -0
- package/dist/worktree/worktree-wip.js +17 -2
- package/dist/worktree/worktree.service.d.ts +23 -1
- package/dist/worktree/worktree.service.js +122 -15
- package/dist/worktree/worktree.types.d.ts +16 -0
- package/package.json +1 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { RepositoryCoordinatorLock } from "../../sandbox/repository-lock.js";
|
|
4
3
|
import { GitClient } from "../../shared/git/git.js";
|
|
5
4
|
import { sandboxHostLoadGateFromEnvironment } from "../sandbox-host-capacity-gate.js";
|
|
6
5
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
7
|
-
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
8
6
|
import { completionPhaseFromDispatch, prepareCompletionToolRuntime, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion } from "../phase-completion.js";
|
|
9
7
|
import { ForgeFailureError } from "../session.types.js";
|
|
10
8
|
import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtifact, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitDecomposeGateArtifacts, emitDraftGateArtifacts, emitPhaseCompletionEvent, emitPhaseGateEvents, emitQaArtifactRecorded, emitQaStructuredEvents, enforceQaBrowserLaunchTargetGate, LiveArchitectArtifactEmitter, LiveCompletionArtifactEmitter, LiveQaArtifactEmitter, readCompletionArtifactsForRun, readQaCompletionArtifactBundle, waitForCompletionArtifact } from "./provider-cli.artifacts.js";
|
|
11
9
|
import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChangedFilePath, stagePublishableWorktreeChangeSet, } from "../publishable-worktree-changes.js";
|
|
12
10
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
13
|
-
import { buildArchitectPrompt, buildConflictResolvePrompt, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch, shouldPipePromptToStdin, usesManagedWindowsHost } from "./provider-cli.prompts.js";
|
|
14
|
-
import {
|
|
11
|
+
import { buildArchitectPrompt, buildConflictResolvePrompt, withReapplyConflictInstruction, withRemainingReapplyConflictInstruction, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch, shouldPipePromptToStdin, usesManagedWindowsHost } from "./provider-cli.prompts.js";
|
|
12
|
+
import { providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
15
13
|
import { admitUserConfigIsolatedProvider, emitProviderUsageEvent, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
16
|
-
import {
|
|
14
|
+
import { defaultPublicationCoordinator, ProviderToolActivityHeartbeat, providerCliExitFailure, } from "./provider-cli.service-support.js";
|
|
15
|
+
import { runPrReviewSession } from "./provider-cli.pr-review.js";
|
|
16
|
+
import { clip, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
17
17
|
import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
|
|
18
18
|
import { assertRepairHeadEpoch } from "./provider-cli.repair-epoch.js";
|
|
19
19
|
import { PrePublicationValidator } from "../pre-publication-validation.js";
|
|
@@ -160,6 +160,7 @@ export { parseClaudeMcpToolName } from "./provider-output-state.js";
|
|
|
160
160
|
export { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
161
161
|
export { buildProviderCliCommand, codexSandboxModeForPlatform, formatProviderCliCommand, formatProviderCliCommandForCheckpoint } from "./provider-cli.prompts.js";
|
|
162
162
|
export { buildProviderChildEnvironment, chooseWindowsCommandCandidate, resolveCodexNpmDirectLaunch, resolveClaudeNpmDirectLaunch, resolvePackageManagerDirectLaunch, resolveWindowsCommandFromPath, PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS, CodexModelsCacheRecoveringProcessRunner, CodexResumeRecoveringProcessRunner, isTransientCodexProviderNotFoundFailure, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
163
|
+
export { isProviderCapacityFailure, isProviderConfigurationFailure, isProviderContextWindowExhausted } from "./provider-cli.service-support.js";
|
|
163
164
|
export { buildWindowsLaunchCommand } from "../../shared/process/windows-launch.js";
|
|
164
165
|
async function pushWorktreeBranch(git, worktreePath, branchName, repoPath, coordinator, signal, emit, expectedRemoteHeadSha) {
|
|
165
166
|
return await coordinator.withLock(repoPath, async () => {
|
|
@@ -227,88 +228,6 @@ function isNonFastForwardPushError(err) {
|
|
|
227
228
|
function errorMessage(err) {
|
|
228
229
|
return err instanceof Error ? err.message : String(err);
|
|
229
230
|
}
|
|
230
|
-
function providerCliExitFailure(command, result) {
|
|
231
|
-
const output = [result.stderr.trim(), result.stdout.trim()]
|
|
232
|
-
.filter(value => value.length > 0)
|
|
233
|
-
.join("\n");
|
|
234
|
-
const detail = clipTail(output, 1200);
|
|
235
|
-
const suffix = detail ? `: ${detail}` : "";
|
|
236
|
-
if (isProviderConfigurationFailure(command, result)) {
|
|
237
|
-
return new ForgeFailureError("provider_configuration_invalid", `${command} rejected its model configuration; correct the configuration before retrying${suffix}`, "provider");
|
|
238
|
-
}
|
|
239
|
-
if (isTransientCodexProviderNotFoundFailure(command, result)) {
|
|
240
|
-
return new ForgeFailureError("provider_request_not_found", `${command} received a transient not-found response from its provider service${suffix}`, "provider");
|
|
241
|
-
}
|
|
242
|
-
if (isProviderCapacityFailure(result)) {
|
|
243
|
-
return new ForgeFailureError("provider_capacity_unavailable", `${command} was deferred because the selected provider model is temporarily at capacity${suffix}`, "provider");
|
|
244
|
-
}
|
|
245
|
-
if (isProviderContextWindowExhausted(command, result)) {
|
|
246
|
-
return new ForgeFailureError("provider_context_window_exhausted", `${command} exhausted the provider context window and must continue in a fresh session${suffix}`, "provider");
|
|
247
|
-
}
|
|
248
|
-
return new Error(`${command} exited ${result.exitCode}${suffix}`);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Capacity is trusted only when a nonzero provider process writes one of the
|
|
252
|
-
* narrow service-level messages to stderr. Stdout can contain arbitrary agent
|
|
253
|
-
* command output and account usage-limit messages remain ordinary failures.
|
|
254
|
-
*/
|
|
255
|
-
export function isProviderCapacityFailure(result) {
|
|
256
|
-
if (result.exitCode === 0)
|
|
257
|
-
return false;
|
|
258
|
-
const capacityMessages = new Set([
|
|
259
|
-
"the selected model is at capacity. please try again later.",
|
|
260
|
-
"the selected model is currently at capacity. please try again later.",
|
|
261
|
-
"the model is currently overloaded. please try again later.",
|
|
262
|
-
"the provider is currently overloaded. please try again later.",
|
|
263
|
-
]);
|
|
264
|
-
return result.stderr
|
|
265
|
-
.split(/\r?\n/u)
|
|
266
|
-
.map(line => line.trim().toLowerCase().replace(/^error:\s*/u, ""))
|
|
267
|
-
.some(line => capacityMessages.has(line));
|
|
268
|
-
}
|
|
269
|
-
/** Only a nonzero Codex service diagnostic can classify a configuration rejection.
|
|
270
|
-
* JSONL turn.failed is a provider envelope; item/tool output is not retry authority. */
|
|
271
|
-
export function isProviderConfigurationFailure(command, result) {
|
|
272
|
-
const names = [path.posix.parse(command).name, path.win32.parse(command).name];
|
|
273
|
-
if (result.exitCode === 0 || !names.some(name => name.toLowerCase() === "codex"))
|
|
274
|
-
return false;
|
|
275
|
-
const reasoningRejected = /Unsupported value: '[^'\r\n]+' is not supported with the '[^'\r\n]+' model\./u.test(result.stderr)
|
|
276
|
-
&& result.stderr.includes("reasoning.effort")
|
|
277
|
-
&& result.stderr.includes("invalid_request_error")
|
|
278
|
-
&& result.stderr.includes("unsupported_value");
|
|
279
|
-
if (reasoningRejected)
|
|
280
|
-
return true;
|
|
281
|
-
return [result.stderr, result.stdout].some(output => output.split(/\r?\n/u).some(line => {
|
|
282
|
-
try {
|
|
283
|
-
const event = JSON.parse(line);
|
|
284
|
-
if (event.type !== "turn.failed")
|
|
285
|
-
return false;
|
|
286
|
-
const error = event.error;
|
|
287
|
-
if (typeof error?.message !== "string")
|
|
288
|
-
return false;
|
|
289
|
-
const service = JSON.parse(error.message);
|
|
290
|
-
return service.type === "error" && service.status === 400
|
|
291
|
-
&& service.error?.type === "invalid_request_error"
|
|
292
|
-
&& typeof service.error.message === "string"
|
|
293
|
-
&& /^The '[^'\r\n]+' model is not supported when using Codex with a ChatGPT account\.$/u.test(service.error.message);
|
|
294
|
-
}
|
|
295
|
-
catch {
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
}));
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* A context limit is trusted only at the provider process boundary. The exact
|
|
302
|
-
* Codex message can be embedded in its JSONL stderr envelope, so substring
|
|
303
|
-
* matching is intentional but remains narrow and stderr-only.
|
|
304
|
-
*/
|
|
305
|
-
export function isProviderContextWindowExhausted(command, result) {
|
|
306
|
-
const executableNames = [path.posix.parse(command).name, path.win32.parse(command).name]
|
|
307
|
-
.map(name => name.toLowerCase());
|
|
308
|
-
if (result.exitCode === 0 || !executableNames.includes("codex"))
|
|
309
|
-
return false;
|
|
310
|
-
return result.stderr.toLowerCase().includes("codex ran out of room in the model's context window");
|
|
311
|
-
}
|
|
312
231
|
const defaultProviderToolHeartbeatIntervalMs = 60_000;
|
|
313
232
|
const defaultManagedVerificationProgressIntervalMs = 30_000;
|
|
314
233
|
function compareManagedVerificationSnapshots(left, right) {
|
|
@@ -452,58 +371,6 @@ function formatElapsed(milliseconds) {
|
|
|
452
371
|
const minutes = Math.floor(seconds / 60);
|
|
453
372
|
return minutes > 0 ? `${minutes}m ${seconds % 60}s` : `${seconds}s`;
|
|
454
373
|
}
|
|
455
|
-
class ProviderToolActivityHeartbeat {
|
|
456
|
-
outputState;
|
|
457
|
-
emit;
|
|
458
|
-
intervalMs;
|
|
459
|
-
timer = null;
|
|
460
|
-
/** Lets the provider runner hold its end-of-turn timers while a tool call is in flight. */
|
|
461
|
-
isToolCallInFlight = () => this.outputState.hasActiveToolCall;
|
|
462
|
-
/** Forgets tool calls a previous generation left open; called before every relaunch. */
|
|
463
|
-
startGeneration = () => this.outputState.resetActiveToolCalls();
|
|
464
|
-
constructor(outputState, emit, intervalMs) {
|
|
465
|
-
this.outputState = outputState;
|
|
466
|
-
this.emit = emit;
|
|
467
|
-
this.intervalMs = intervalMs;
|
|
468
|
-
// Each heartbeat watches one provider generation. Calls an earlier generation left
|
|
469
|
-
// open died with it; inheriting them would hold the new generation's timers forever.
|
|
470
|
-
this.outputState.resetActiveToolCalls();
|
|
471
|
-
}
|
|
472
|
-
async consume(line) {
|
|
473
|
-
const events = this.outputState.consume(line);
|
|
474
|
-
this.sync();
|
|
475
|
-
for (const event of events) {
|
|
476
|
-
await this.emit(event);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
stop() {
|
|
480
|
-
if (this.timer) {
|
|
481
|
-
clearInterval(this.timer);
|
|
482
|
-
this.timer = null;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
sync() {
|
|
486
|
-
if (!this.outputState.hasActiveToolCall) {
|
|
487
|
-
this.stop();
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
if (this.timer) {
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
this.timer = setInterval(() => {
|
|
494
|
-
if (!this.outputState.hasActiveToolCall) {
|
|
495
|
-
this.stop();
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
void this.emit({
|
|
499
|
-
role: "runner",
|
|
500
|
-
kind: "status",
|
|
501
|
-
content: "A supervised provider tool is still running.",
|
|
502
|
-
eventType: "provider_tool_heartbeat",
|
|
503
|
-
}).catch(() => undefined);
|
|
504
|
-
}, Math.max(1, this.intervalMs));
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
374
|
const fakeWorkerModel = "server-local-fake-worker";
|
|
508
375
|
export class RoutingProviderCliService {
|
|
509
376
|
realProvider;
|
|
@@ -532,6 +399,11 @@ export class RoutingProviderCliService {
|
|
|
532
399
|
? await this.deterministicProvider.runConflictResolve(context)
|
|
533
400
|
: await this.realProvider.runConflictResolve(context);
|
|
534
401
|
}
|
|
402
|
+
async runPrReview(context) {
|
|
403
|
+
return isFakeWorkerModel(context.dispatch.execution.model)
|
|
404
|
+
? await this.deterministicProvider.runPrReview(context)
|
|
405
|
+
: await this.realProvider.runPrReview(context);
|
|
406
|
+
}
|
|
535
407
|
async runQa(context) {
|
|
536
408
|
return isFakeWorkerModel(context.dispatch.execution.model)
|
|
537
409
|
? await this.deterministicProvider.runQa(context)
|
|
@@ -550,7 +422,7 @@ export class ProcessBackedProviderCliService {
|
|
|
550
422
|
publicationCoordinator;
|
|
551
423
|
prePublicationValidator;
|
|
552
424
|
prePublicationRepairTurns;
|
|
553
|
-
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator =
|
|
425
|
+
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = defaultPublicationCoordinator(),
|
|
554
426
|
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
555
427
|
// this default. A container cannot reach the host ledger, so when the host
|
|
556
428
|
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
@@ -758,11 +630,11 @@ export class ProcessBackedProviderCliService {
|
|
|
758
630
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
759
631
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" }) + "\n", "utf8");
|
|
760
632
|
const completionTools = await prepareCompletionToolRuntime({ dispatch, worktree, phase, runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment });
|
|
761
|
-
const implementationPrompt = debugCycle
|
|
633
|
+
const implementationPrompt = withReapplyConflictInstruction(debugCycle
|
|
762
634
|
? buildDebugCyclePrompt(dispatch, phase)
|
|
763
635
|
: developCycle
|
|
764
636
|
? buildDevelopCyclePrompt(dispatch, phase)
|
|
765
|
-
: buildImplementationPrompt(dispatch, phase);
|
|
637
|
+
: buildImplementationPrompt(dispatch, phase), context.reapplyConflicts, context.projectStartDeferred);
|
|
766
638
|
const providerPrompt = buildProviderCliPrompt(dispatch, implementationPrompt, context.runtimeEnvironment);
|
|
767
639
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
768
640
|
const command = buildProviderCliCommand(dispatch, {
|
|
@@ -1179,11 +1051,11 @@ export class ProcessBackedProviderCliService {
|
|
|
1179
1051
|
eventType: "completion_tools_configured",
|
|
1180
1052
|
});
|
|
1181
1053
|
}
|
|
1182
|
-
const repairPrompt = repairChecks
|
|
1054
|
+
const repairPrompt = withReapplyConflictInstruction(repairChecks
|
|
1183
1055
|
? buildPullRequestCheckRepairPrompt(dispatch, worktree.branchName)
|
|
1184
1056
|
: addressComments
|
|
1185
1057
|
? buildPullRequestCommentsPrompt(dispatch, worktree.branchName)
|
|
1186
|
-
: buildConflictResolvePrompt(dispatch, worktree.branchName);
|
|
1058
|
+
: buildConflictResolvePrompt(dispatch, worktree.branchName), context.reapplyConflicts, context.projectStartDeferred);
|
|
1187
1059
|
const providerPrompt = buildProviderCliPrompt(dispatch, repairPrompt, repairEnvironment);
|
|
1188
1060
|
const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
|
|
1189
1061
|
const command = buildProviderCliCommand(dispatch, {
|
|
@@ -1348,6 +1220,19 @@ export class ProcessBackedProviderCliService {
|
|
|
1348
1220
|
artifacts: repairArtifact ? [repairArtifact] : [],
|
|
1349
1221
|
};
|
|
1350
1222
|
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Review-only session for a pull request head. Never routed through implementation: the worktree
|
|
1225
|
+
* is detached at the dispatched head, the provider cannot change or publish anything, and the
|
|
1226
|
+
* review is handed to Forge only through the completion tool. No commit, push or GitHub call
|
|
1227
|
+
* is made here; a worktree that differs after the session fails with `guardrail_violation`.
|
|
1228
|
+
*/
|
|
1229
|
+
async runPrReview(context) {
|
|
1230
|
+
return await runPrReviewSession({
|
|
1231
|
+
git: this.git,
|
|
1232
|
+
processRunner: this.processRunner,
|
|
1233
|
+
providerToolHeartbeatIntervalMs: this.providerToolHeartbeatIntervalMs,
|
|
1234
|
+
}, admitUserConfigIsolatedProvider(context));
|
|
1235
|
+
}
|
|
1351
1236
|
async recoverMissingQaCompletion(options) {
|
|
1352
1237
|
const { context, outputState } = options;
|
|
1353
1238
|
const { dispatch, worktree } = context;
|
|
@@ -1368,7 +1253,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1368
1253
|
...dispatch,
|
|
1369
1254
|
session: { ...dispatch.session, resumeProviderThreadId: providerThreadId },
|
|
1370
1255
|
};
|
|
1371
|
-
const recoveryPrompt = [
|
|
1256
|
+
const recoveryPrompt = await withRemainingReapplyConflictInstruction([
|
|
1372
1257
|
"Your previous turn ended before Forge received the QA verdict, so the provider process exited.",
|
|
1373
1258
|
"Background watchers, monitors and notifications from that turn did not survive and will never report back.",
|
|
1374
1259
|
"Resume QA exactly where it stopped. Do not repeat gates you already recorded.",
|
|
@@ -1376,7 +1261,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1376
1261
|
"and block on long commands with forge.wait_managed_command, calling it again while command_continues is true.",
|
|
1377
1262
|
"Do not end your turn until you have called every remaining QA gate through forge.complete_qa_verdict.",
|
|
1378
1263
|
"If a gate cannot get evidence, record it as blocked with the reason instead of ending the turn.",
|
|
1379
|
-
].join(" ");
|
|
1264
|
+
].join(" "), context);
|
|
1380
1265
|
for (let turn = 1; turn <= maxQaCompletionRecoveryTurns; turn += 1) {
|
|
1381
1266
|
const providerPrompt = buildProviderCliPrompt(recoveryDispatch, recoveryPrompt, context.runtimeEnvironment);
|
|
1382
1267
|
const pipePromptToStdin = shouldPipePromptToStdin(recoveryDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(recoveryDispatch));
|
|
@@ -1477,7 +1362,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1477
1362
|
...dispatch,
|
|
1478
1363
|
session: { ...dispatch.session, resumeProviderThreadId: providerThreadId },
|
|
1479
1364
|
};
|
|
1480
|
-
const recoveryPrompt = [
|
|
1365
|
+
const recoveryPrompt = await withRemainingReapplyConflictInstruction([
|
|
1481
1366
|
"Forge did not receive the required forge.complete_comment_repair call from your previous turn, so the provider process exited.",
|
|
1482
1367
|
"Background watchers, monitors and notifications from that turn did not survive and will never report back,",
|
|
1483
1368
|
"and Forge stopped any managed command that process was still running; its receipt reports that.",
|
|
@@ -1487,7 +1372,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1487
1372
|
"and block on long commands with forge.wait_managed_command, calling it again while command_continues is true.",
|
|
1488
1373
|
"Do not end your turn until you have called forge.complete_comment_repair with an evidence-backed disposition for every actionable finding.",
|
|
1489
1374
|
"Do not commit or push; Forge owns publication after the completion gate succeeds.",
|
|
1490
|
-
].join(" ");
|
|
1375
|
+
].join(" "), context);
|
|
1491
1376
|
const providerPrompt = buildProviderCliPrompt(recoveryDispatch, recoveryPrompt, repairEnvironment);
|
|
1492
1377
|
const pipePromptToStdin = shouldPipePromptToStdin(recoveryDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(recoveryDispatch));
|
|
1493
1378
|
const completionTools = await prepareCompletionToolRuntime({
|
|
@@ -3,10 +3,11 @@ import type { WorktreeHandle } from "../../worktree/worktree.types.js";
|
|
|
3
3
|
import type { ProviderProcessRunner } from "./provider-cli.process.js";
|
|
4
4
|
/**
|
|
5
5
|
* Why the attempt's runtime stack restarted before a validation pass. The first cause that applies:
|
|
6
|
-
*
|
|
6
|
+
* its first start was deferred until a WIP re-apply's conflicts were resolved (it never ran); a
|
|
7
|
+
* previous restart did not complete; the workspace state could not be compared with the stack's
|
|
7
8
|
* (either reading was unavailable); or the workspace changed since the stack was launched.
|
|
8
9
|
*/
|
|
9
|
-
export type RuntimeRestartReason = "previous_restart_incomplete" | "fingerprint_unavailable" | "workspace_changed";
|
|
10
|
+
export type RuntimeRestartReason = "deferred_start" | "previous_restart_incomplete" | "fingerprint_unavailable" | "workspace_changed";
|
|
10
11
|
export interface RuntimeEnvironmentRefresh {
|
|
11
12
|
/** The restarted stack's runtime environment. */
|
|
12
13
|
readonly environment: Readonly<Record<string, string>>;
|
|
@@ -35,6 +36,10 @@ export interface ProviderCliRunContext {
|
|
|
35
36
|
* ports). A failed restart withholds them from the repair turn, since the stack is down.
|
|
36
37
|
*/
|
|
37
38
|
readonly runtimeStackEnvironmentKeys?: readonly string[];
|
|
39
|
+
/** Unresolved conflicts a WIP re-apply left in the worktree, which the prompt names (withReapplyConflictInstruction). */
|
|
40
|
+
readonly reapplyConflicts?: readonly string[];
|
|
41
|
+
/** True when the project stack's start waits for those conflicts to be resolved. */
|
|
42
|
+
readonly projectStartDeferred?: boolean;
|
|
38
43
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
39
44
|
}
|
|
40
45
|
export interface ProviderCliDraftContext {
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { constants as fsConstants } from "node:fs";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { HostCapacityTimeoutError, } from "../runtime/host-load-governor.js";
|
|
5
|
+
import { afterNotified, HostCapacityTimeoutError, waitChanged, } from "../runtime/host-load-governor.js";
|
|
6
6
|
import { defaultHostLoadGovernorConfig } from "../runtime/host-load-governor-config.js";
|
|
7
7
|
import { HostCapacityTokenFencedError } from "../runtime/host-load-token-ledger.js";
|
|
8
8
|
import { sandboxHostCapacityBrokerEnvironment, sandboxHostCapacityBrokerProtocol, sandboxHostCapacityLineType, sandboxHostCapacityMaxWaitEnvironment, sandboxHostCapacityResponseOwnerUid, sandboxHostCapacityResponseRoot, } from "../sandbox/host-capacity-broker.js";
|
|
@@ -39,25 +39,35 @@ export class SandboxBrokeredHostLoadGate {
|
|
|
39
39
|
this.pollMs = options.pollMs ?? 250;
|
|
40
40
|
this.replyOwnership = options.replyOwnership
|
|
41
41
|
?? posixReplyOwnership(options.trustedOwnerUid ?? sandboxHostCapacityResponseOwnerUid);
|
|
42
|
-
this.maxWaitMs = options.maxWaitMs ?? defaultHostLoadGovernorConfig.
|
|
42
|
+
this.maxWaitMs = options.maxWaitMs ?? defaultHostLoadGovernorConfig.maxTotalWaitMs + 2 * 60_000;
|
|
43
43
|
}
|
|
44
44
|
async acquire(request, options = {}) {
|
|
45
45
|
const requestId = randomUUID();
|
|
46
46
|
const responsePath = path.join(this.responseRoot, `${requestId}.json`);
|
|
47
47
|
const startedAtMs = monotonicNowMs();
|
|
48
48
|
this.send("acquire", requestId, request);
|
|
49
|
-
|
|
49
|
+
// The broker answers again when the wait changes (a new slot holder, say). Each changed wait is
|
|
50
|
+
// reported by the governor's rule, in order. The admission, failure or cancellation lands after the
|
|
51
|
+
// report in flight, and a report still queued by then is dropped as stale (as in the governor).
|
|
52
|
+
let reportedWait = null;
|
|
53
|
+
let reports = Promise.resolve();
|
|
54
|
+
let settled = false;
|
|
50
55
|
try {
|
|
51
56
|
while (true) {
|
|
52
57
|
if (options.signal?.aborted)
|
|
53
58
|
throw options.signal.reason ?? new Error("The host capacity wait was cancelled.");
|
|
54
59
|
const response = await readResponse(responsePath, requestId, this.replyOwnership);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
const wait = newWait(response, reportedWait);
|
|
61
|
+
if (wait) {
|
|
62
|
+
reportedWait = wait;
|
|
63
|
+
reports = reports.then(async () => { if (!settled)
|
|
64
|
+
await options.onWaiting?.(wait); }).catch(() => undefined);
|
|
58
65
|
}
|
|
59
|
-
if (response?.status === "admitted")
|
|
66
|
+
if (response?.status === "admitted") {
|
|
67
|
+
settled = true;
|
|
68
|
+
await afterNotified(reports);
|
|
60
69
|
return this.admission(requestId, responsePath, request, response);
|
|
70
|
+
}
|
|
61
71
|
if (response?.status === "failed" || response?.status === "fenced")
|
|
62
72
|
throw responseError(request, response);
|
|
63
73
|
if (monotonicNowMs() - startedAtMs > this.maxWaitMs) {
|
|
@@ -67,8 +77,10 @@ export class SandboxBrokeredHostLoadGate {
|
|
|
67
77
|
}
|
|
68
78
|
}
|
|
69
79
|
catch (error) {
|
|
80
|
+
settled = true;
|
|
70
81
|
this.send("release", requestId, request);
|
|
71
82
|
await fs.rm(responsePath, { force: true }).catch(() => undefined);
|
|
83
|
+
await afterNotified(reports);
|
|
72
84
|
throw error;
|
|
73
85
|
}
|
|
74
86
|
}
|
|
@@ -179,6 +191,16 @@ export function sandboxHostLoadGateFromEnvironment(environment = process.env) {
|
|
|
179
191
|
export function resetSandboxHostLoadGateForTesting() {
|
|
180
192
|
cachedGate = null;
|
|
181
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* A waiting answer whose wait changed since the one last reported, by the governor's rule
|
|
196
|
+
* (`waitChanged`: a new reason, or a slot wait's new holder or place), or null.
|
|
197
|
+
*/
|
|
198
|
+
function newWait(response, reported) {
|
|
199
|
+
if (response?.status !== "waiting")
|
|
200
|
+
return null;
|
|
201
|
+
const next = decision(false, response);
|
|
202
|
+
return waitChanged(reported, next) ? next : null;
|
|
203
|
+
}
|
|
182
204
|
function decision(admitted, response) {
|
|
183
205
|
return {
|
|
184
206
|
admitted,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LoadedHostRuntimeContract } from "../runtime/host-runtime-contract.js";
|
|
2
|
+
import { type HostRuntimeLeaseRuntime, type HostRuntimeLeaseStart } from "../runtime/host-runtime-lease.js";
|
|
3
|
+
import type { RuntimeRestartReason } from "./provider-cli/provider-cli.types.js";
|
|
4
|
+
import type { HostRuntimeReadinessProbeResult, RunOnceDispatchPacket, RunnerDispatchEvent } from "./session.types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Builds and launches the attempt's configured project from the prepared worktree and reports the
|
|
7
|
+
* verified port; or, while a WIP re-apply left unresolved conflicts that would fail its build,
|
|
8
|
+
* defers the start to pre-publication validation (deferredProjectStartEvent) so the agent runs first.
|
|
9
|
+
*/
|
|
10
|
+
export declare function startOrDeferConfiguredProject(hostRuntime: HostRuntimeLeaseRuntime, hostLease: HostRuntimeLeaseStart, dispatch: RunOnceDispatchPacket, reapplyConflicts: readonly string[] | undefined, signal: AbortSignal | undefined, emitLifecycle: (event: RunnerDispatchEvent) => Promise<void>): Promise<{
|
|
11
|
+
readonly hostLease: HostRuntimeLeaseStart;
|
|
12
|
+
readonly deferred: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function managedQaLaunchTarget(runtimeContract: LoadedHostRuntimeContract): HostRuntimeReadinessProbeResult["qaAppLaunchTarget"];
|
|
15
|
+
/** The host_runtime_restart_started checkpoint text for the first cause of a validation-time restart. */
|
|
16
|
+
export declare function runtimeRestartStartedMessage(reason: RuntimeRestartReason, changes: readonly string[]): string;
|
|
17
|
+
/**
|
|
18
|
+
* The dispatch with its managed Browser QA target's URL from the started stack. While the first start
|
|
19
|
+
* is deferred (startOrDeferConfiguredProject) the stack has no URL yet: the target keeps its port,
|
|
20
|
+
* and validation starts the stack once the agent has resolved the conflicts.
|
|
21
|
+
*/
|
|
22
|
+
export declare function withMaterializedManagedQaTarget(dispatch: RunOnceDispatchPacket, hostLease: HostRuntimeLeaseStart | null, projectStartDeferred?: boolean): RunOnceDispatchPacket;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { hostRuntimeEventResources } from "../runtime/host-runtime-lease.js";
|
|
2
|
+
import { configuredLaunchPortNames } from "../runtime/host-runtime-promotion.js";
|
|
3
|
+
import { deferredProjectStartEvent } from "../worktree/worktree.service.js";
|
|
4
|
+
// The attempt's configured project on a managed host: its first start (or its deferral while a WIP
|
|
5
|
+
// re-apply left unresolved conflicts), the checkpoint text for a validation-time restart, and the
|
|
6
|
+
// Browser QA target it serves.
|
|
7
|
+
/**
|
|
8
|
+
* Builds and launches the attempt's configured project from the prepared worktree and reports the
|
|
9
|
+
* verified port; or, while a WIP re-apply left unresolved conflicts that would fail its build,
|
|
10
|
+
* defers the start to pre-publication validation (deferredProjectStartEvent) so the agent runs first.
|
|
11
|
+
*/
|
|
12
|
+
export async function startOrDeferConfiguredProject(hostRuntime, hostLease, dispatch, reapplyConflicts, signal, emitLifecycle) {
|
|
13
|
+
// Only a managed runtime with a port to launch builds anything here (launchConfiguredProject returns
|
|
14
|
+
// at once for analysis_only or no launch config), so no other setup has a build to defer.
|
|
15
|
+
const deferred = (reapplyConflicts?.length ?? 0) > 0 && Boolean(hostRuntime.restartConfiguredProject)
|
|
16
|
+
&& hostLease.executionClass === "managed_runtime"
|
|
17
|
+
&& configuredLaunchPortNames(hostLease.runtimeContract).length > 0;
|
|
18
|
+
if (deferred) {
|
|
19
|
+
await emitLifecycle(deferredProjectStartEvent(reapplyConflicts));
|
|
20
|
+
return { hostLease, deferred };
|
|
21
|
+
}
|
|
22
|
+
const unconfiguredPortCount = hostLease.lease.resources.ports.length;
|
|
23
|
+
const started = await hostRuntime.startConfiguredProject(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken, signal, async (checkpoint) => {
|
|
24
|
+
await emitLifecycle({
|
|
25
|
+
role: "runner",
|
|
26
|
+
kind: "checkpoint",
|
|
27
|
+
content: checkpoint.message,
|
|
28
|
+
eventType: checkpoint.code,
|
|
29
|
+
data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
if (started.lease.resources.ports.length > unconfiguredPortCount) {
|
|
33
|
+
const assigned = started.lease.resources.ports.at(-1);
|
|
34
|
+
await emitLifecycle({
|
|
35
|
+
role: "runner",
|
|
36
|
+
kind: "checkpoint",
|
|
37
|
+
content: `Verified supervised project runtime ${assigned.name} on ${assigned.hostIp}:${assigned.hostPort}.`,
|
|
38
|
+
eventType: "host_runtime_project_ready",
|
|
39
|
+
data: JSON.stringify(hostRuntimeEventResources(started.lease, started.runtimeContract, started.executionClass)),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return { hostLease: started, deferred };
|
|
43
|
+
}
|
|
44
|
+
export function managedQaLaunchTarget(runtimeContract) {
|
|
45
|
+
const playwright = runtimeContract.contract.runtime.playwright;
|
|
46
|
+
if (!playwright)
|
|
47
|
+
return null;
|
|
48
|
+
const port = runtimeContract.contract.runtime.ports.find(candidate => candidate.name === playwright.baseUrlPort);
|
|
49
|
+
return port?.launch && port.baseUrlEnv && port.format
|
|
50
|
+
? { managedRuntimePort: port.name, routes: ["/"] }
|
|
51
|
+
: null;
|
|
52
|
+
}
|
|
53
|
+
/** The host_runtime_restart_started checkpoint text for the first cause of a validation-time restart. */
|
|
54
|
+
export function runtimeRestartStartedMessage(reason, changes) {
|
|
55
|
+
const current = "so validation runs against the current source.";
|
|
56
|
+
switch (reason) {
|
|
57
|
+
case "deferred_start":
|
|
58
|
+
return `Starting the attempt runtime stack, deferred until the restored work's re-apply conflicts were resolved, ${current}`;
|
|
59
|
+
case "workspace_changed":
|
|
60
|
+
return `The workspace changed since the attempt runtime stack was launched (${changes.join(", ")}); restarting it ${current}`;
|
|
61
|
+
case "previous_restart_incomplete":
|
|
62
|
+
return `The previous attempt runtime restart did not complete; restarting it again ${current}`
|
|
63
|
+
+ (changes.length > 0 ? ` The workspace also changed since launch (${changes.join(", ")}).` : "");
|
|
64
|
+
default:
|
|
65
|
+
return `The workspace state could not be compared with the attempt runtime stack; restarting it ${current}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The dispatch with its managed Browser QA target's URL from the started stack. While the first start
|
|
70
|
+
* is deferred (startOrDeferConfiguredProject) the stack has no URL yet: the target keeps its port,
|
|
71
|
+
* and validation starts the stack once the agent has resolved the conflicts.
|
|
72
|
+
*/
|
|
73
|
+
export function withMaterializedManagedQaTarget(dispatch, hostLease, projectStartDeferred = false) {
|
|
74
|
+
const target = dispatch.qaBrowser?.launchTarget;
|
|
75
|
+
const portName = target?.managed_runtime_port?.trim().toLowerCase();
|
|
76
|
+
if (!target || !portName)
|
|
77
|
+
return dispatch;
|
|
78
|
+
if (!hostLease) {
|
|
79
|
+
throw new Error("qa_managed_runtime_unavailable: Browser QA requires the verified managed host runtime selected during readiness.");
|
|
80
|
+
}
|
|
81
|
+
const normalizedName = portName.toUpperCase().replaceAll(/[^A-Z0-9]/gu, "_");
|
|
82
|
+
const url = hostLease.environment[`FORGE_${normalizedName}_URL`];
|
|
83
|
+
if (!url && projectStartDeferred)
|
|
84
|
+
return withQaTargetNote(dispatch, target, "Forge starts this port's stack at validation, after the conflicts from restored work are resolved; it has no URL before then.");
|
|
85
|
+
if (!url) {
|
|
86
|
+
throw new Error(`qa_managed_runtime_unavailable: verified runtime port '${portName}' was not launched for this attempt.`);
|
|
87
|
+
}
|
|
88
|
+
return withQaTargetNote(dispatch, { ...target, url: target.url ?? url, ready_url: target.ready_url ?? url }, "Forge launched and verified this URL inside the current fenced attempt.");
|
|
89
|
+
}
|
|
90
|
+
function withQaTargetNote(dispatch, target, note) {
|
|
91
|
+
return {
|
|
92
|
+
...dispatch,
|
|
93
|
+
qaBrowser: dispatch.qaBrowser ? {
|
|
94
|
+
...dispatch.qaBrowser,
|
|
95
|
+
launchTarget: { ...target, notes: [target.notes, note].filter(Boolean).join(" ") },
|
|
96
|
+
} : dispatch.qaBrowser,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function asObject(value: unknown, label: string): Record<string, unknown>;
|
|
2
|
+
export declare function requiredString(source: Record<string, unknown>, key: string): string;
|
|
3
|
+
export declare function optionalString(source: Record<string, unknown>, key: string): string | null;
|
|
4
|
+
export declare function requiredBoolean(source: Record<string, unknown>, key: string): boolean;
|
|
5
|
+
export declare function optionalBoolean(source: Record<string, unknown>, key: string): boolean | null;
|
|
6
|
+
export declare function optionalPositiveInteger(source: Record<string, unknown>, key: string): number | null;
|
|
7
|
+
export declare function optionalNonNegativeInteger(source: Record<string, unknown>, key: string): number | null;
|
|
8
|
+
export declare function requiredNumber(source: Record<string, unknown>, key: string): number;
|
|
9
|
+
export declare function boundedInteger(source: Record<string, unknown>, key: string, minimum: number, maximum: number): number;
|
|
10
|
+
export declare function optionalObjectArray(source: Record<string, unknown>, key: string): Record<string, unknown>[];
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export function asObject(value, label) {
|
|
2
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
3
|
+
throw new Error(`${label} must be an object.`);
|
|
4
|
+
}
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
export function requiredString(source, key) {
|
|
8
|
+
const value = source[key];
|
|
9
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
10
|
+
throw new Error(`${key} must be a non-empty string.`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function optionalString(source, key) {
|
|
15
|
+
const value = source[key];
|
|
16
|
+
if (value === undefined || value === null) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value !== "string") {
|
|
20
|
+
throw new Error(`${key} must be a string when provided.`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
export function requiredBoolean(source, key) {
|
|
25
|
+
const value = source[key];
|
|
26
|
+
if (typeof value !== "boolean") {
|
|
27
|
+
throw new Error(`${key} must be a boolean.`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
export function optionalBoolean(source, key) {
|
|
32
|
+
const value = source[key];
|
|
33
|
+
if (value === undefined || value === null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (typeof value !== "boolean") {
|
|
37
|
+
throw new Error(`${key} must be a boolean when provided.`);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
export function optionalPositiveInteger(source, key) {
|
|
42
|
+
const value = source[key];
|
|
43
|
+
if (value === undefined || value === null) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
47
|
+
throw new Error(`${key} must be a positive integer when provided.`);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
export function optionalNonNegativeInteger(source, key) {
|
|
52
|
+
const value = source[key];
|
|
53
|
+
if (value === undefined || value === null) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
57
|
+
throw new Error(`${key} must be a non-negative integer when provided.`);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
export function requiredNumber(source, key) {
|
|
62
|
+
const value = source[key];
|
|
63
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
64
|
+
throw new Error(`${key} must be a finite number.`);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
export function boundedInteger(source, key, minimum, maximum) {
|
|
69
|
+
const value = requiredNumber(source, key);
|
|
70
|
+
if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
|
|
71
|
+
throw new Error(`${key} must be an integer from ${minimum} through ${maximum}.`);
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
export function optionalObjectArray(source, key) {
|
|
76
|
+
const value = source[key];
|
|
77
|
+
if (value === undefined || value === null) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
if (!Array.isArray(value)) {
|
|
81
|
+
throw new Error(`${key} must be an array when provided.`);
|
|
82
|
+
}
|
|
83
|
+
return value.map((item, index) => asObject(item, `${key}[${index}]`));
|
|
84
|
+
}
|