@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,3 +1,5 @@
|
|
|
1
|
+
// forge-bridge run-once's review placement guard (pr-review-placement.ts).
|
|
2
|
+
export { runOnceWithReviewPlacement } from "./pr-review-placement.js";
|
|
1
3
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "./session-redaction.js";
|
|
2
4
|
import { randomUUID } from "node:crypto";
|
|
3
5
|
import { RoutingProviderCliService } from "./provider-cli/provider-cli.service.js";
|
|
@@ -6,8 +8,8 @@ import { emitWorktreePreparedEvents, GitWorktreeService, sessionWipOutcome, sett
|
|
|
6
8
|
import { SandboxWorkspaceService } from "../sandbox/workspace.service.js";
|
|
7
9
|
import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, hostRuntimeStackEnvironmentKeys, runtimeAdmissionPriority, } from "../runtime/host-runtime-lease.js";
|
|
8
10
|
import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "../runtime/host-runtime-promotion.js";
|
|
9
|
-
import { managedQaLaunchTarget,
|
|
10
|
-
import {
|
|
11
|
+
import { managedQaLaunchTarget, startOrDeferConfiguredProject, withMaterializedManagedQaTarget, } from "./session-host-project.js";
|
|
12
|
+
import { createConfiguredRuntimeRefresh, readWorkspaceRuntimeFingerprint, } from "./session.runtime-refresh.js";
|
|
11
13
|
const minimumReadinessProbeStartupBudgetMs = 150_000;
|
|
12
14
|
export class BridgeSessionService {
|
|
13
15
|
worktrees;
|
|
@@ -251,6 +253,8 @@ export class BridgeSessionService {
|
|
|
251
253
|
warmPathOverrides: dispatch.warmPathOverrides,
|
|
252
254
|
applicationRuntimeRequired: dispatch.runtimeIntent.applicationRuntimeRequired,
|
|
253
255
|
preserveExistingState: Boolean(dispatch.session.resumedFromSessionId),
|
|
256
|
+
// A review reads the exact pull request head, detached; it never works on a lease branch.
|
|
257
|
+
detachedHeadSha: prReviewHeadSha(dispatch),
|
|
254
258
|
sessionId: dispatch.session.id,
|
|
255
259
|
...preparedAttemptOwner(dispatch),
|
|
256
260
|
signal,
|
|
@@ -319,91 +323,20 @@ export class BridgeSessionService {
|
|
|
319
323
|
}
|
|
320
324
|
// The stack was built and launched from this workspace state. Pre-publication
|
|
321
325
|
// validation restarts it when the provider has changed the source since.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
.catch(() => null);
|
|
333
|
-
// Set while the stack may not match the workspace: a failed restart is retried on the next pass.
|
|
334
|
-
let restartPending = false;
|
|
335
|
-
// Set until the deferred first start (re-apply conflicts) succeeds: the stack has never run.
|
|
336
|
-
let startDeferred = projectStartDeferred;
|
|
337
|
-
refreshRuntimeEnvironment = async (refreshSignal) => {
|
|
338
|
-
// A late violation stopped the stack: fail this validation pass rather than run it against closed ports.
|
|
339
|
-
this.throwIfAbortedOrIsolationViolated(undefined, dispatch, hostLease);
|
|
340
|
-
const current = await this.workspaceFingerprint(worktreePath).catch(() => null);
|
|
341
|
-
if (!restartPending && !startDeferred && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
|
|
342
|
-
return null;
|
|
343
|
-
// Every cause that applies is reported; `reason` is the first of them. Changes are named
|
|
344
|
-
// only when both states were read: an unreadable baseline is not a workspace change.
|
|
345
|
-
const comparable = launchFingerprint !== null && current !== null;
|
|
346
|
-
const changes = comparable ? workspaceRuntimeFingerprintChanges(launchFingerprint, current) : [];
|
|
347
|
-
const causes = [
|
|
348
|
-
...(startDeferred ? ["deferred_start"] : []),
|
|
349
|
-
...(restartPending ? ["previous_restart_incomplete"] : []),
|
|
350
|
-
...(comparable ? [] : ["fingerprint_unavailable"]),
|
|
351
|
-
...(changes.length > 0 ? ["workspace_changed"] : []),
|
|
352
|
-
];
|
|
353
|
-
const reason = causes[0] ?? "workspace_changed";
|
|
354
|
-
await emitLifecycle({
|
|
355
|
-
role: "runner",
|
|
356
|
-
kind: "checkpoint",
|
|
357
|
-
content: runtimeRestartStartedMessage(reason, changes),
|
|
358
|
-
eventType: "host_runtime_restart_started",
|
|
359
|
-
data: JSON.stringify({
|
|
360
|
-
reason,
|
|
361
|
-
causes,
|
|
362
|
-
changes,
|
|
363
|
-
head_sha: current?.headSha ?? null,
|
|
364
|
-
merge_in_progress: Boolean(current?.mergeHead),
|
|
365
|
-
}),
|
|
366
|
-
});
|
|
367
|
-
restartPending = true;
|
|
368
|
-
let restarted;
|
|
369
|
-
try {
|
|
370
|
-
restarted = await restartConfiguredProject(dispatchAttemptId, fencingToken, refreshSignal ?? signal, async (checkpoint) => {
|
|
371
|
-
await emitLifecycle({
|
|
372
|
-
role: "runner",
|
|
373
|
-
kind: "checkpoint",
|
|
374
|
-
content: checkpoint.message,
|
|
375
|
-
eventType: checkpoint.code,
|
|
376
|
-
data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
catch (error) {
|
|
381
|
-
await emitLifecycle({
|
|
382
|
-
role: "runner",
|
|
383
|
-
kind: "error",
|
|
384
|
-
content: `Restarting the attempt runtime stack failed: ${failureMessage(error)}`,
|
|
385
|
-
eventType: "host_runtime_restart_failed",
|
|
386
|
-
data: JSON.stringify({ reason, causes, changes }),
|
|
387
|
-
}).catch(() => undefined);
|
|
388
|
-
throw error;
|
|
389
|
-
}
|
|
326
|
+
const refreshRuntimeEnvironment = await createConfiguredRuntimeRefresh({
|
|
327
|
+
hostLease,
|
|
328
|
+
dispatch,
|
|
329
|
+
hostRuntime: this.hostRuntime,
|
|
330
|
+
worktreePath: worktree.worktreePath,
|
|
331
|
+
readFingerprint: this.workspaceFingerprint,
|
|
332
|
+
emitLifecycle,
|
|
333
|
+
signal,
|
|
334
|
+
assertRunning: () => this.throwIfAbortedOrIsolationViolated(undefined, dispatch, hostLease),
|
|
335
|
+
onRestarted: restarted => {
|
|
390
336
|
hostLease = restarted;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
launchFingerprint = await this.workspaceFingerprint(worktreePath).catch(() => current);
|
|
395
|
-
restartPending = false;
|
|
396
|
-
startDeferred = false;
|
|
397
|
-
await emitLifecycle({
|
|
398
|
-
role: "runner",
|
|
399
|
-
kind: "checkpoint",
|
|
400
|
-
content: `Restarted the supervised project runtime on ${restarted.lease.resources.ports.map(port => `${port.name} ${port.hostIp}:${port.hostPort}`).join(", ") || "no ports"}.`,
|
|
401
|
-
eventType: "host_runtime_restarted",
|
|
402
|
-
data: JSON.stringify(hostRuntimeEventResources(restarted.lease, restarted.runtimeContract, restarted.executionClass)),
|
|
403
|
-
});
|
|
404
|
-
return { environment: restarted.environment, reason, changes };
|
|
405
|
-
};
|
|
406
|
-
}
|
|
337
|
+
},
|
|
338
|
+
startDeferred: projectStartDeferred
|
|
339
|
+
});
|
|
407
340
|
providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease, projectStartDeferred);
|
|
408
341
|
const providerEnvironment = {
|
|
409
342
|
runtimeEnvironment: hostLease?.environment,
|
|
@@ -444,6 +377,7 @@ export class BridgeSessionService {
|
|
|
444
377
|
const isArchitect = role === "architect" || lane === "architect" || cycleKind === "architect";
|
|
445
378
|
const isCiRepair = role === "ci_repair" || lane === "ci_repair" || cycleKind === "pr_checks";
|
|
446
379
|
const isConflictResolve = role === "conflict_resolve" || lane === "conflict_resolve";
|
|
380
|
+
const isPrReview = role === "pr_review" || lane === "pr_review" || cycleKind === "pr_review";
|
|
447
381
|
const context = {
|
|
448
382
|
dispatch: providerDispatch,
|
|
449
383
|
worktree,
|
|
@@ -461,15 +395,17 @@ export class BridgeSessionService {
|
|
|
461
395
|
};
|
|
462
396
|
let run;
|
|
463
397
|
try {
|
|
464
|
-
run =
|
|
465
|
-
? await this.providerCli.
|
|
466
|
-
:
|
|
467
|
-
? await this.providerCli.
|
|
468
|
-
:
|
|
469
|
-
? await this.providerCli.
|
|
470
|
-
:
|
|
471
|
-
? await this.providerCli.
|
|
472
|
-
:
|
|
398
|
+
run = isPrReview
|
|
399
|
+
? await this.providerCli.runPrReview(context)
|
|
400
|
+
: isQa
|
|
401
|
+
? await this.providerCli.runQa(context)
|
|
402
|
+
: isArchitect
|
|
403
|
+
? await this.providerCli.runArchitect(context)
|
|
404
|
+
: isCiRepair
|
|
405
|
+
? await this.providerCli.runCiRepair(context)
|
|
406
|
+
: isConflictResolve
|
|
407
|
+
? await this.providerCli.runConflictResolve(context)
|
|
408
|
+
: await this.providerCli.runImplementation(context);
|
|
473
409
|
}
|
|
474
410
|
catch (error) {
|
|
475
411
|
const message = failureMessage(error);
|
|
@@ -590,6 +526,15 @@ export class BridgeSessionService {
|
|
|
590
526
|
}
|
|
591
527
|
}
|
|
592
528
|
}
|
|
529
|
+
function prReviewHeadSha(dispatch) {
|
|
530
|
+
const lane = dispatch.execution.lane.trim().toLowerCase();
|
|
531
|
+
const role = dispatch.execution.role.trim().toLowerCase();
|
|
532
|
+
const kind = dispatch.cycleRun.kind.trim().toLowerCase();
|
|
533
|
+
if (role !== "pr_review" && lane !== "pr_review" && kind !== "pr_review") {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
return (dispatch.prReview?.headSha || dispatch.pullRequest?.headSha || "").trim() || null;
|
|
537
|
+
}
|
|
593
538
|
function failureMessage(error) {
|
|
594
539
|
return error instanceof Error ? error.message : String(error);
|
|
595
540
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { HostRuntimeRequirements } from "../runtime/host-runtime-requirements.js";
|
|
2
|
+
import { type DispatchPrReviewContext } from "./session.types.pr-review.js";
|
|
3
|
+
export type { DispatchPrReviewContext, DispatchPrReviewPriorReview, DispatchPrReviewThread, DispatchPrReviewThreadComment } from "./session.types.pr-review.js";
|
|
2
4
|
export interface RunOnceDispatchPacket {
|
|
3
5
|
readonly schemaVersion: 1 | 2;
|
|
4
6
|
readonly userId: string;
|
|
@@ -13,6 +15,8 @@ export interface RunOnceDispatchPacket {
|
|
|
13
15
|
readonly sandbox?: DispatchSandboxContext | null;
|
|
14
16
|
readonly wipAttempt?: number | null;
|
|
15
17
|
readonly pullRequest?: DispatchPullRequestContext | null;
|
|
18
|
+
/** Review-only context for the pr_review lane: the head to review and the Story spec text. */
|
|
19
|
+
readonly prReview?: DispatchPrReviewContext | null;
|
|
16
20
|
readonly apiKeySecretGrant?: ApiKeySecretGrant | null;
|
|
17
21
|
readonly apiKeySecretGrantHandle?: ApiKeySecretGrantHandle | null;
|
|
18
22
|
readonly artifacts: readonly DispatchResolvedArtifact[];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
3
|
+
import { asObject, requiredString, optionalString, requiredBoolean, optionalBoolean, optionalPositiveInteger, optionalNonNegativeInteger, requiredNumber, boundedInteger } from "./session.parse-helpers.js";
|
|
4
|
+
import { parsePrReview } from "./session.types.pr-review.js";
|
|
3
5
|
export class ForgeFailureError extends Error {
|
|
4
6
|
failureCode;
|
|
5
7
|
failureSource;
|
|
@@ -30,6 +32,7 @@ export function parseRunOnceDispatchPacket(value) {
|
|
|
30
32
|
sandbox: parseSandbox(packet.sandbox, schemaVersion),
|
|
31
33
|
wipAttempt: optionalNonNegativeInteger(packet, "wipAttempt"),
|
|
32
34
|
pullRequest: parsePullRequest(packet.pullRequest),
|
|
35
|
+
prReview: parsePrReview(packet.prReview),
|
|
33
36
|
apiKeySecretGrant: parseApiKeySecretGrant(packet.apiKeySecretGrant),
|
|
34
37
|
apiKeySecretGrantHandle: parseApiKeySecretGrantHandle(packet.apiKeySecretGrantHandle),
|
|
35
38
|
artifacts: parseArtifacts(packet.artifacts),
|
|
@@ -539,6 +542,9 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
539
542
|
if (stableFailureFamilyCodes.has(code) && (code.startsWith("teardown") || code.startsWith("reaper"))) {
|
|
540
543
|
return facts(code, "transport", "teardown", source, "retryable", "retry_with_policy");
|
|
541
544
|
}
|
|
545
|
+
if (["pr_review.unsandboxed_host", "pr_review.sandbox_unavailable"].includes(code)) {
|
|
546
|
+
return facts(code, "domain", "offer", source, "non_retryable", "fix_environment");
|
|
547
|
+
}
|
|
542
548
|
if (["invalid_dispatch"].includes(code)) {
|
|
543
549
|
return facts(code, "domain", "offer", source, "non_retryable", "fix_input");
|
|
544
550
|
}
|
|
@@ -552,10 +558,7 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
552
558
|
].includes(code)) {
|
|
553
559
|
return facts(code, "domain", "prepare", source, "non_retryable", "reauthenticate");
|
|
554
560
|
}
|
|
555
|
-
if (
|
|
556
|
-
return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
|
|
557
|
-
}
|
|
558
|
-
if (code === "sandbox_wall_timeout") {
|
|
561
|
+
if (["sandbox_idle_timeout", "sandbox_wall_timeout"].includes(code)) {
|
|
559
562
|
return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
|
|
560
563
|
}
|
|
561
564
|
if (["sandbox_oom_killed", "sandbox_pid_exhausted", "sandbox_file_descriptor_exhausted", "sandbox_storage_exhausted"].includes(code)) {
|
|
@@ -1322,76 +1325,3 @@ function parsePriorPhaseArtifacts(value) {
|
|
|
1322
1325
|
};
|
|
1323
1326
|
});
|
|
1324
1327
|
}
|
|
1325
|
-
function asObject(value, label) {
|
|
1326
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1327
|
-
throw new Error(`${label} must be an object.`);
|
|
1328
|
-
}
|
|
1329
|
-
return value;
|
|
1330
|
-
}
|
|
1331
|
-
function requiredString(source, key) {
|
|
1332
|
-
const value = source[key];
|
|
1333
|
-
if (typeof value !== "string" || value.trim().length === 0) {
|
|
1334
|
-
throw new Error(`${key} must be a non-empty string.`);
|
|
1335
|
-
}
|
|
1336
|
-
return value;
|
|
1337
|
-
}
|
|
1338
|
-
function optionalString(source, key) {
|
|
1339
|
-
const value = source[key];
|
|
1340
|
-
if (value === undefined || value === null) {
|
|
1341
|
-
return null;
|
|
1342
|
-
}
|
|
1343
|
-
if (typeof value !== "string") {
|
|
1344
|
-
throw new Error(`${key} must be a string when provided.`);
|
|
1345
|
-
}
|
|
1346
|
-
return value;
|
|
1347
|
-
}
|
|
1348
|
-
function requiredBoolean(source, key) {
|
|
1349
|
-
const value = source[key];
|
|
1350
|
-
if (typeof value !== "boolean") {
|
|
1351
|
-
throw new Error(`${key} must be a boolean.`);
|
|
1352
|
-
}
|
|
1353
|
-
return value;
|
|
1354
|
-
}
|
|
1355
|
-
function optionalBoolean(source, key) {
|
|
1356
|
-
const value = source[key];
|
|
1357
|
-
if (value === undefined || value === null) {
|
|
1358
|
-
return null;
|
|
1359
|
-
}
|
|
1360
|
-
if (typeof value !== "boolean") {
|
|
1361
|
-
throw new Error(`${key} must be a boolean when provided.`);
|
|
1362
|
-
}
|
|
1363
|
-
return value;
|
|
1364
|
-
}
|
|
1365
|
-
function optionalPositiveInteger(source, key) {
|
|
1366
|
-
const value = source[key];
|
|
1367
|
-
if (value === undefined || value === null) {
|
|
1368
|
-
return null;
|
|
1369
|
-
}
|
|
1370
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
1371
|
-
throw new Error(`${key} must be a positive integer when provided.`);
|
|
1372
|
-
}
|
|
1373
|
-
return value;
|
|
1374
|
-
}
|
|
1375
|
-
function optionalNonNegativeInteger(source, key) {
|
|
1376
|
-
const value = source[key];
|
|
1377
|
-
if (value === undefined || value === null)
|
|
1378
|
-
return null;
|
|
1379
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
1380
|
-
throw new Error(`${key} must be a non-negative integer when provided.`);
|
|
1381
|
-
}
|
|
1382
|
-
return value;
|
|
1383
|
-
}
|
|
1384
|
-
function requiredNumber(source, key) {
|
|
1385
|
-
const value = source[key];
|
|
1386
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1387
|
-
throw new Error(`${key} must be a finite number.`);
|
|
1388
|
-
}
|
|
1389
|
-
return value;
|
|
1390
|
-
}
|
|
1391
|
-
function boundedInteger(source, key, minimum, maximum) {
|
|
1392
|
-
const value = requiredNumber(source, key);
|
|
1393
|
-
if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
|
|
1394
|
-
throw new Error(`${key} must be an integer from ${minimum} through ${maximum}.`);
|
|
1395
|
-
}
|
|
1396
|
-
return value;
|
|
1397
|
-
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface DispatchPrReviewContext {
|
|
2
|
+
/** The pull request head commit the worktree is checked out at, detached. */
|
|
3
|
+
readonly headSha: string;
|
|
4
|
+
/** The commit the review diffs against: the merge base of the base branch tip and the head, once the bridge resolved it. */
|
|
5
|
+
readonly baseSha: string;
|
|
6
|
+
/** The base branch tip the provider reported, when the bridge replaced it with the merge base. */
|
|
7
|
+
readonly baseTipSha?: string;
|
|
8
|
+
readonly reviewKind: string;
|
|
9
|
+
/** The approved Story spec text, written verbatim to the Story's spec.md. */
|
|
10
|
+
readonly storySpec: string;
|
|
11
|
+
readonly pullRequestNumber: number;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
/** The pull request description. Author-controlled text: treat it as untrusted. */
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly baseBranch: string;
|
|
16
|
+
readonly storyWorkItemId: string | null;
|
|
17
|
+
readonly storySpecPath: string | null;
|
|
18
|
+
readonly priorReviews: readonly DispatchPrReviewPriorReview[];
|
|
19
|
+
readonly priorThreads: readonly DispatchPrReviewThread[];
|
|
20
|
+
}
|
|
21
|
+
export interface DispatchPrReviewPriorReview {
|
|
22
|
+
readonly cycleRunId: string;
|
|
23
|
+
readonly sessionId: string;
|
|
24
|
+
readonly headSha: string;
|
|
25
|
+
readonly status: string;
|
|
26
|
+
readonly completedAt: string | null;
|
|
27
|
+
}
|
|
28
|
+
export interface DispatchPrReviewThread {
|
|
29
|
+
readonly threadId: string;
|
|
30
|
+
readonly path: string | null;
|
|
31
|
+
readonly line: number | null;
|
|
32
|
+
readonly startLine: number | null;
|
|
33
|
+
readonly side: string | null;
|
|
34
|
+
/** The head the thread was raised on. */
|
|
35
|
+
readonly reviewedHeadSha: string | null;
|
|
36
|
+
readonly isResolved: boolean;
|
|
37
|
+
readonly isOutdated: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The status the latest posted Forge review that reported the thread gave it (resolved_since_last_review,
|
|
40
|
+
* still_open or reintroduced); null when no posted Forge review reported it, such as one the last review raised.
|
|
41
|
+
*/
|
|
42
|
+
readonly previousReviewStatus?: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Forge set this, not the reviewer: the thread's first comment is a finding an earlier Forge review posted from the
|
|
45
|
+
* account Forge posts with. Only such a thread holds a new finding at its lines back as a repeat; a thread a person,
|
|
46
|
+
* Copilot or another bot raised does not.
|
|
47
|
+
*/
|
|
48
|
+
readonly raisedByForge?: boolean;
|
|
49
|
+
readonly comments: readonly DispatchPrReviewThreadComment[];
|
|
50
|
+
}
|
|
51
|
+
export interface DispatchPrReviewThreadComment {
|
|
52
|
+
readonly id: string;
|
|
53
|
+
readonly author: string | null;
|
|
54
|
+
/** Comment text. Author-controlled: treat it as untrusted. */
|
|
55
|
+
readonly body: string;
|
|
56
|
+
readonly url: string | null;
|
|
57
|
+
readonly createdAt: string | null;
|
|
58
|
+
}
|
|
59
|
+
export declare function parsePrReview(value: unknown): DispatchPrReviewContext | null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { asObject, optionalBoolean, optionalNonNegativeInteger, optionalObjectArray, optionalString, requiredString } from "./session.parse-helpers.js";
|
|
2
|
+
export function parsePrReview(value) {
|
|
3
|
+
if (value === undefined || value === null) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const prReview = asObject(value, "prReview");
|
|
7
|
+
return {
|
|
8
|
+
headSha: requiredString(prReview, "headSha"),
|
|
9
|
+
baseSha: optionalString(prReview, "baseSha") ?? "",
|
|
10
|
+
...(optionalString(prReview, "baseTipSha") ? { baseTipSha: optionalString(prReview, "baseTipSha") } : {}),
|
|
11
|
+
reviewKind: optionalString(prReview, "reviewKind") ?? "initial",
|
|
12
|
+
storySpec: optionalString(prReview, "storySpec") ?? "",
|
|
13
|
+
pullRequestNumber: optionalNonNegativeInteger(prReview, "pullRequestNumber") ?? 0,
|
|
14
|
+
title: optionalString(prReview, "title") ?? "",
|
|
15
|
+
description: optionalString(prReview, "description") ?? "",
|
|
16
|
+
baseBranch: optionalString(prReview, "baseBranch") ?? "",
|
|
17
|
+
storyWorkItemId: optionalString(prReview, "storyWorkItemId"),
|
|
18
|
+
storySpecPath: optionalString(prReview, "storySpecPath"),
|
|
19
|
+
priorReviews: optionalObjectArray(prReview, "priorReviews").map(parsePrReviewPriorReview),
|
|
20
|
+
priorThreads: optionalObjectArray(prReview, "priorThreads").map(parsePrReviewThread)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function parsePrReviewPriorReview(review) {
|
|
24
|
+
return {
|
|
25
|
+
cycleRunId: optionalString(review, "cycleRunId") ?? "",
|
|
26
|
+
sessionId: optionalString(review, "sessionId") ?? "",
|
|
27
|
+
headSha: requiredString(review, "headSha"),
|
|
28
|
+
status: optionalString(review, "status") ?? "",
|
|
29
|
+
completedAt: optionalString(review, "completedAt")
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function parsePrReviewThread(thread) {
|
|
33
|
+
return {
|
|
34
|
+
// The server serializes the id as threadId; id is accepted for the review-finding shape.
|
|
35
|
+
threadId: optionalString(thread, "threadId") || requiredString(thread, "id"),
|
|
36
|
+
path: optionalString(thread, "path"),
|
|
37
|
+
line: optionalNonNegativeInteger(thread, "line"),
|
|
38
|
+
startLine: optionalNonNegativeInteger(thread, "startLine"),
|
|
39
|
+
side: optionalString(thread, "side"),
|
|
40
|
+
reviewedHeadSha: optionalString(thread, "reviewedHeadSha"),
|
|
41
|
+
isResolved: optionalBoolean(thread, "isResolved") ?? false,
|
|
42
|
+
isOutdated: optionalBoolean(thread, "isOutdated") ?? false,
|
|
43
|
+
previousReviewStatus: optionalString(thread, "previousReviewStatus"),
|
|
44
|
+
raisedByForge: optionalBoolean(thread, "raisedByForge") ?? false,
|
|
45
|
+
comments: optionalObjectArray(thread, "comments").map((comment) => ({
|
|
46
|
+
id: optionalString(comment, "id") ?? "",
|
|
47
|
+
author: optionalString(comment, "author"),
|
|
48
|
+
body: optionalString(comment, "body") ?? "",
|
|
49
|
+
url: optionalString(comment, "url"),
|
|
50
|
+
createdAt: optionalString(comment, "createdAt")
|
|
51
|
+
}))
|
|
52
|
+
};
|
|
53
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.2.1-dev.
|
|
1
|
+
export declare const forgeBridgeVersion = "0.2.1-dev.7171bf414613";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.2.1-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.2.1-dev.7171bf414613";
|
|
@@ -32,6 +32,7 @@ const ARCHITECT_OPERATIONAL_HOOKS = new Set([
|
|
|
32
32
|
"architect-complete",
|
|
33
33
|
"architect-revise"
|
|
34
34
|
]);
|
|
35
|
+
const PR_REVIEW_OPERATIONAL_SKILLS = new Set(["pr-review"]);
|
|
35
36
|
const DRAFT_OPERATIONAL_SKILLS = new Set([
|
|
36
37
|
"draft-intent",
|
|
37
38
|
"draft-repo-context",
|
|
@@ -74,6 +75,9 @@ export function filterArtifactsForLane(artifacts, lane, phase) {
|
|
|
74
75
|
if (normalizedLane === "architect") {
|
|
75
76
|
return artifacts.filter((artifact) => shouldInjectArchitectArtifact(artifact, commandSlug));
|
|
76
77
|
}
|
|
78
|
+
if (normalizedLane === "pr_review" || normalizedLane === "pr-review") {
|
|
79
|
+
return artifacts.filter((artifact) => shouldInjectPrReviewArtifact(artifact, commandSlug));
|
|
80
|
+
}
|
|
77
81
|
if (normalizedLane === "draft") {
|
|
78
82
|
return artifacts.filter((artifact) => shouldInjectDraftArtifact(artifact, commandSlug, phase));
|
|
79
83
|
}
|
|
@@ -112,6 +116,9 @@ export function resolveCommandSlug(lane, phase) {
|
|
|
112
116
|
return "debug-prompt";
|
|
113
117
|
}
|
|
114
118
|
const normalizedPhase = phase.trim().toLowerCase().replace(/-/g, "_");
|
|
119
|
+
if (normalizedLane === "pr_review" || normalizedLane === "pr-review") {
|
|
120
|
+
return "pr-review-prompt";
|
|
121
|
+
}
|
|
115
122
|
if (normalizedPhase === "rework") {
|
|
116
123
|
return "rework-prompt";
|
|
117
124
|
}
|
|
@@ -122,6 +129,9 @@ export function resolveCommandSlug(lane, phase) {
|
|
|
122
129
|
return "architect-prompt";
|
|
123
130
|
case "qa":
|
|
124
131
|
return "qa-prompt";
|
|
132
|
+
case "pr_review":
|
|
133
|
+
case "pr-review":
|
|
134
|
+
return "pr-review-prompt";
|
|
125
135
|
default:
|
|
126
136
|
return "dev-prompt";
|
|
127
137
|
}
|
|
@@ -191,6 +201,20 @@ function shouldInjectArchitectArtifact(artifact, commandSlug) {
|
|
|
191
201
|
return false;
|
|
192
202
|
}
|
|
193
203
|
}
|
|
204
|
+
function shouldInjectPrReviewArtifact(artifact, commandSlug) {
|
|
205
|
+
if (artifact.scope.trim().toLowerCase() !== "operational") {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
const slug = artifact.slug.trim().toLowerCase();
|
|
209
|
+
switch (normalizedArtifactKind(artifact.kind)) {
|
|
210
|
+
case "command":
|
|
211
|
+
return slug === commandSlug;
|
|
212
|
+
case "skill":
|
|
213
|
+
return PR_REVIEW_OPERATIONAL_SKILLS.has(slug);
|
|
214
|
+
default:
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
194
218
|
function shouldInjectDraftArtifact(artifact, commandSlug, phase) {
|
|
195
219
|
if (artifact.scope.trim().toLowerCase() !== "operational") {
|
|
196
220
|
return false;
|
|
@@ -23,6 +23,23 @@ export declare class GitWorktreeService implements WorktreeService {
|
|
|
23
23
|
/** The bridge log: prepare records its start point and what it did to a reused worktree. */
|
|
24
24
|
log?: BridgeLog);
|
|
25
25
|
prepare(request: WorktreePrepareRequest): Promise<WorktreeHandle>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates the lease's worktree. A review's is detached at the review head: no lease branch is
|
|
28
|
+
* created and no WIP is restored. Any other is on the lease branch with the story's WIP restored.
|
|
29
|
+
*/
|
|
30
|
+
private createWorktree;
|
|
31
|
+
/**
|
|
32
|
+
* Readies a surviving worktree. A review reads one exact commit, so whatever state a prior attempt
|
|
33
|
+
* left behind is discarded. Any other must still be on the lease branch; it is refreshed for this
|
|
34
|
+
* pass and given the story's WIP.
|
|
35
|
+
*/
|
|
36
|
+
private reuseWorktree;
|
|
37
|
+
/**
|
|
38
|
+
* Finds the review head in the repository, fetching it when the local clone has not seen it
|
|
39
|
+
* yet, and returns the full commit id.
|
|
40
|
+
*/
|
|
41
|
+
private resolveReviewHead;
|
|
42
|
+
private assertDetachedAtHead;
|
|
26
43
|
private warmDependencies;
|
|
27
44
|
/** Restores the story's saved WIP (still under the repository lock, before the provider starts). */
|
|
28
45
|
private withRestoredWip;
|
|
@@ -38,6 +55,11 @@ export declare class GitWorktreeService implements WorktreeService {
|
|
|
38
55
|
private registeredManagedWorktreePath;
|
|
39
56
|
private repoCreationCoordinationPath;
|
|
40
57
|
release(handle: WorktreeHandle): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Removes a review worktree without saving anything from it (see settleWip). A failed removal leaves
|
|
60
|
+
* the folder for the next prepare of that head, which resets and cleans it, or for stale cleanup.
|
|
61
|
+
*/
|
|
62
|
+
private removeReviewWorktree;
|
|
41
63
|
private restoreOrphanedWorktree;
|
|
42
64
|
private resolveRepoPath;
|
|
43
65
|
private managedRepoPath;
|