@loucompanion/forge-bridge 0.2.1-dev.573a8a5fa582 → 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 +38 -2
- 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 +62 -92
- package/dist/bridge/bridge.types.d.ts +6 -0
- 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/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 +3 -3
- package/dist/cli/local-config.d.ts +2 -0
- package/dist/cli/local-config.js +3 -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 +23 -2
- package/dist/runtime/host-load-governor-config.js +20 -2
- package/dist/runtime/host-load-governor.d.ts +81 -1
- package/dist/runtime/host-load-governor.js +184 -15
- 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 +19 -7
- package/dist/sandbox/runtime.d.ts +1 -2
- package/dist/sandbox/runtime.js +7 -13
- 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 +7 -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.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 -13
- package/dist/session/provider-cli/provider-cli.prompts.js +123 -107
- 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 +24 -139
- package/dist/session/sandbox-host-capacity-gate.js +28 -6
- 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 +40 -95
- package/dist/session/session.types.d.ts +4 -0
- package/dist/session/session.types.js +7 -77
- package/dist/session/session.types.pr-review.d.ts +59 -0
- package/dist/session/session.types.pr-review.js +53 -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/worktree.service.d.ts +22 -0
- package/dist/worktree/worktree.service.js +116 -12
- package/dist/worktree/worktree.types.d.ts +7 -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
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";
|
|
14
|
-
import {
|
|
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
|
|
@@ -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;
|
|
@@ -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";
|
|
@@ -46,18 +46,28 @@ export class SandboxBrokeredHostLoadGate {
|
|
|
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,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
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { RuntimeEnvironmentRefresh } from "./provider-cli/provider-cli.types.js";
|
|
2
|
+
import type { RunOnceDispatchPacket, RunnerDispatchEvent } from "./session.types.js";
|
|
3
|
+
import type { HostRuntimeLeaseRuntime, HostRuntimeLeaseStart } from "../runtime/host-runtime-lease.js";
|
|
4
|
+
import { readWorkspaceRuntimeFingerprint, type WorkspaceRuntimeFingerprintReader } from "./workspace-runtime-fingerprint.js";
|
|
5
|
+
export { readWorkspaceRuntimeFingerprint, type WorkspaceRuntimeFingerprintReader };
|
|
6
|
+
export interface RuntimeEnvironmentRefreshInput {
|
|
7
|
+
readonly worktreePath: string;
|
|
8
|
+
readonly dispatchAttemptId: string;
|
|
9
|
+
readonly fencingToken: string;
|
|
10
|
+
readonly restartConfiguredProject: NonNullable<HostRuntimeLeaseRuntime["restartConfiguredProject"]>;
|
|
11
|
+
readonly readFingerprint: WorkspaceRuntimeFingerprintReader;
|
|
12
|
+
readonly emitLifecycle: (event: RunnerDispatchEvent) => Promise<void>;
|
|
13
|
+
readonly signal?: AbortSignal;
|
|
14
|
+
/** Throws when the attempt was aborted or a late isolation violation stopped its stack. */
|
|
15
|
+
readonly assertRunning?: () => void;
|
|
16
|
+
/** Called with the restarted lease so the caller keeps serving the current stack. */
|
|
17
|
+
readonly onRestarted: (restarted: HostRuntimeLeaseStart) => void;
|
|
18
|
+
/**
|
|
19
|
+
* True while the first start of the stack is deferred (re-apply conflicts): the stack has never run,
|
|
20
|
+
* so the first pass starts it. Cleared after a successful restart.
|
|
21
|
+
*/
|
|
22
|
+
readonly startDeferred?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds the pre-publication hook that restarts the attempt runtime stack when the provider has
|
|
26
|
+
* changed the workspace since the stack was launched. The stack was built and launched from the
|
|
27
|
+
* workspace state read here.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createRuntimeEnvironmentRefresh(input: RuntimeEnvironmentRefreshInput): Promise<(refreshSignal?: AbortSignal) => Promise<RuntimeEnvironmentRefresh | null>>;
|
|
30
|
+
export interface ConfiguredRuntimeRefreshInput {
|
|
31
|
+
readonly hostLease: HostRuntimeLeaseStart | null;
|
|
32
|
+
readonly dispatch: RunOnceDispatchPacket;
|
|
33
|
+
readonly hostRuntime: HostRuntimeLeaseRuntime | undefined;
|
|
34
|
+
readonly worktreePath: string;
|
|
35
|
+
readonly readFingerprint: WorkspaceRuntimeFingerprintReader;
|
|
36
|
+
readonly emitLifecycle: (event: RunnerDispatchEvent) => Promise<void>;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
readonly assertRunning?: () => void;
|
|
39
|
+
readonly onRestarted: (restarted: HostRuntimeLeaseStart) => void;
|
|
40
|
+
readonly startDeferred?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The refresh hook for a managed runtime lease with configured launch ports, or undefined when the
|
|
44
|
+
* attempt has no restartable project stack.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createConfiguredRuntimeRefresh(input: ConfiguredRuntimeRefreshInput): Promise<((refreshSignal?: AbortSignal) => Promise<RuntimeEnvironmentRefresh | null>) | undefined>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { configuredLaunchPortNames } from "../runtime/host-runtime-promotion.js";
|
|
2
|
+
import { hostRuntimeEventResources } from "../runtime/host-runtime-lease.js";
|
|
3
|
+
import { runtimeRestartStartedMessage } from "./session-host-project.js";
|
|
4
|
+
import { readWorkspaceRuntimeFingerprint, sameWorkspaceRuntimeFingerprint, workspaceRuntimeFingerprintChanges, } from "./workspace-runtime-fingerprint.js";
|
|
5
|
+
// Re-exported so the session service reaches the workspace fingerprint reader through this module.
|
|
6
|
+
export { readWorkspaceRuntimeFingerprint };
|
|
7
|
+
function failureMessage(error) {
|
|
8
|
+
return error instanceof Error ? error.message : String(error);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds the pre-publication hook that restarts the attempt runtime stack when the provider has
|
|
12
|
+
* changed the workspace since the stack was launched. The stack was built and launched from the
|
|
13
|
+
* workspace state read here.
|
|
14
|
+
*/
|
|
15
|
+
export async function createRuntimeEnvironmentRefresh(input) {
|
|
16
|
+
const { worktreePath, dispatchAttemptId, fencingToken, restartConfiguredProject, readFingerprint, emitLifecycle, signal, assertRunning, onRestarted } = input;
|
|
17
|
+
let launchFingerprint = await readFingerprint(worktreePath)
|
|
18
|
+
.catch(() => null);
|
|
19
|
+
// Set while the stack may not match the workspace: a failed restart is retried on the next pass.
|
|
20
|
+
let restartPending = false;
|
|
21
|
+
// Set until the deferred first start (re-apply conflicts) succeeds: the stack has never run.
|
|
22
|
+
let startDeferred = input.startDeferred ?? false;
|
|
23
|
+
return async (refreshSignal) => {
|
|
24
|
+
// A late violation stopped the stack: fail this validation pass rather than run it against closed ports.
|
|
25
|
+
assertRunning?.();
|
|
26
|
+
const current = await readFingerprint(worktreePath).catch(() => null);
|
|
27
|
+
if (!restartPending && !startDeferred && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
|
|
28
|
+
return null;
|
|
29
|
+
// Every cause that applies is reported; `reason` is the first of them. Changes are named
|
|
30
|
+
// only when both states were read: an unreadable baseline is not a workspace change.
|
|
31
|
+
const comparable = launchFingerprint !== null && current !== null;
|
|
32
|
+
const changes = comparable ? workspaceRuntimeFingerprintChanges(launchFingerprint, current) : [];
|
|
33
|
+
const causes = [
|
|
34
|
+
...(startDeferred ? ["deferred_start"] : []),
|
|
35
|
+
...(restartPending ? ["previous_restart_incomplete"] : []),
|
|
36
|
+
...(comparable ? [] : ["fingerprint_unavailable"]),
|
|
37
|
+
...(changes.length > 0 ? ["workspace_changed"] : []),
|
|
38
|
+
];
|
|
39
|
+
const reason = causes[0] ?? "workspace_changed";
|
|
40
|
+
await emitLifecycle({
|
|
41
|
+
role: "runner",
|
|
42
|
+
kind: "checkpoint",
|
|
43
|
+
content: runtimeRestartStartedMessage(reason, changes),
|
|
44
|
+
eventType: "host_runtime_restart_started",
|
|
45
|
+
data: JSON.stringify({
|
|
46
|
+
reason,
|
|
47
|
+
causes,
|
|
48
|
+
changes,
|
|
49
|
+
head_sha: current?.headSha ?? null,
|
|
50
|
+
merge_in_progress: Boolean(current?.mergeHead),
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
restartPending = true;
|
|
54
|
+
let restarted;
|
|
55
|
+
try {
|
|
56
|
+
restarted = await restartConfiguredProject(dispatchAttemptId, fencingToken, refreshSignal ?? signal, async (checkpoint) => {
|
|
57
|
+
await emitLifecycle({
|
|
58
|
+
role: "runner",
|
|
59
|
+
kind: "checkpoint",
|
|
60
|
+
content: checkpoint.message,
|
|
61
|
+
eventType: checkpoint.code,
|
|
62
|
+
data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
await emitLifecycle({
|
|
68
|
+
role: "runner",
|
|
69
|
+
kind: "error",
|
|
70
|
+
content: `Restarting the attempt runtime stack failed: ${failureMessage(error)}`,
|
|
71
|
+
eventType: "host_runtime_restart_failed",
|
|
72
|
+
data: JSON.stringify({ reason, causes, changes }),
|
|
73
|
+
}).catch(() => undefined);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
onRestarted(restarted);
|
|
77
|
+
// The restarted stack serves the workspace as it is now. Read that state again rather than
|
|
78
|
+
// keep the pre-restart reading, which is null when it could not be collected; a null
|
|
79
|
+
// baseline never matches, so every later pass would restart and rotate ports again.
|
|
80
|
+
launchFingerprint = await readFingerprint(worktreePath).catch(() => current);
|
|
81
|
+
restartPending = false;
|
|
82
|
+
startDeferred = false;
|
|
83
|
+
await emitLifecycle({
|
|
84
|
+
role: "runner",
|
|
85
|
+
kind: "checkpoint",
|
|
86
|
+
content: `Restarted the supervised project runtime on ${restarted.lease.resources.ports.map(port => `${port.name} ${port.hostIp}:${port.hostPort}`).join(", ") || "no ports"}.`,
|
|
87
|
+
eventType: "host_runtime_restarted",
|
|
88
|
+
data: JSON.stringify(hostRuntimeEventResources(restarted.lease, restarted.runtimeContract, restarted.executionClass)),
|
|
89
|
+
});
|
|
90
|
+
return { environment: restarted.environment, reason, changes };
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The refresh hook for a managed runtime lease with configured launch ports, or undefined when the
|
|
95
|
+
* attempt has no restartable project stack.
|
|
96
|
+
*/
|
|
97
|
+
export async function createConfiguredRuntimeRefresh(input) {
|
|
98
|
+
const { hostLease, dispatch, hostRuntime } = input;
|
|
99
|
+
if (!hostLease || !dispatch.sandbox || !hostRuntime?.restartConfiguredProject
|
|
100
|
+
|| hostLease.executionClass !== "managed_runtime"
|
|
101
|
+
|| configuredLaunchPortNames(hostLease.runtimeContract).length === 0) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
return await createRuntimeEnvironmentRefresh({
|
|
105
|
+
worktreePath: input.worktreePath,
|
|
106
|
+
dispatchAttemptId: dispatch.sandbox.dispatchAttemptId,
|
|
107
|
+
fencingToken: dispatch.lease.fencingToken,
|
|
108
|
+
restartConfiguredProject: hostRuntime.restartConfiguredProject.bind(hostRuntime),
|
|
109
|
+
readFingerprint: input.readFingerprint,
|
|
110
|
+
emitLifecycle: input.emitLifecycle,
|
|
111
|
+
signal: input.signal,
|
|
112
|
+
assertRunning: input.assertRunning,
|
|
113
|
+
onRestarted: input.onRestarted,
|
|
114
|
+
startDeferred: input.startDeferred
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { runOnceWithReviewPlacement } from "./pr-review-placement.js";
|
|
1
2
|
import type { HostRequirementsCheck } from "../runtime/host-runtime-requirements-check.js";
|
|
2
3
|
import type { ProviderCliService } from "./provider-cli/provider-cli.base.js";
|
|
3
4
|
import type { SessionEventSink, SessionService } from "./session.base.js";
|
|
@@ -5,7 +6,7 @@ import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult,
|
|
|
5
6
|
import type { WorktreeService } from "../worktree/worktree.base.js";
|
|
6
7
|
import { type HostCapacityLimits, type HostRuntimeCapacitySnapshot, type HostRuntimeLeaseRuntime, type HostRuntimeReapOptions, type HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
|
|
7
8
|
import type { RunnerHostDefaults } from "../runtime/runner-settings.js";
|
|
8
|
-
import { type WorkspaceRuntimeFingerprintReader } from "./
|
|
9
|
+
import { type WorkspaceRuntimeFingerprintReader } from "./session.runtime-refresh.js";
|
|
9
10
|
export declare class BridgeSessionService implements SessionService {
|
|
10
11
|
private readonly worktrees;
|
|
11
12
|
private readonly providerCli;
|