@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0f07274d438b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -4
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +15 -0
- package/dist/bridge/bridge-state-io.js +68 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.service.d.ts +29 -12
- package/dist/bridge/bridge.service.js +215 -380
- package/dist/bridge/bridge.types.d.ts +21 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +57 -13
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +20 -213
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +14 -1
- package/dist/cli/local-config.js +42 -2
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +13 -0
- package/dist/runtime/host-load-child-environment.js +35 -1
- package/dist/runtime/host-load-governor-config.d.ts +33 -3
- package/dist/runtime/host-load-governor-config.js +24 -3
- package/dist/runtime/host-load-governor.d.ts +91 -2
- package/dist/runtime/host-load-governor.js +217 -18
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -0
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +25 -1
- package/dist/runtime/host-load-sampler.js +38 -7
- package/dist/runtime/host-load-step-run.d.ts +37 -3
- package/dist/runtime/host-load-step-run.js +63 -7
- package/dist/runtime/host-load-test-slot.d.ts +3 -0
- package/dist/runtime/host-load-test-slot.js +26 -7
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +35 -5
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +4 -0
- package/dist/runtime/runner-settings.js +22 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +1 -2
- package/dist/sandbox/runtime.js +9 -19
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +54 -109
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +10 -5
- package/dist/session/managed-command-host-load.js +18 -14
- package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +2 -17
- package/dist/session/phase-completion.artifacts.js +65 -166
- package/dist/session/phase-completion.d.ts +27 -2
- package/dist/session/phase-completion.helpers.js +5 -53
- package/dist/session/phase-completion.js +15 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +14 -0
- package/dist/session/phase-completion.runtime.d.ts +8 -9
- package/dist/session/phase-completion.runtime.js +65 -196
- package/dist/session/phase-completion.schemas.js +12 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +9 -1
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.js +6 -5
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-process.js +13 -12
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +9 -4
- package/dist/session/pre-publication-validation.js +62 -65
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +41 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
- package/dist/session/provider-cli/provider-cli.service.js +59 -190
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +63 -22
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +8 -1
- package/dist/session/session.service.js +177 -239
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +9 -79
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +18 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +49 -5
- package/dist/worktree/worktree.service.js +223 -187
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { completionPhaseFromAlias } from "./phase-completion.phase-aliases.js";
|
|
2
3
|
import { artifactOwnerDirectory, isDebugCompletionPhase, normalizeDebugCompletionPhase, safePathSegment } from "./phase-completion.validation.js";
|
|
3
4
|
export { isDebugCompletionPhase } from "./phase-completion.validation.js";
|
|
4
5
|
export { readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.artifacts.js";
|
|
6
|
+
export { recordedPrReviewArtifactProblem } from "./phase-completion.pr-review.js";
|
|
5
7
|
export * from "./phase-completion.prompts.js";
|
|
6
8
|
export * from "./phase-completion.runtime.js";
|
|
9
|
+
export * from "./phase-completion.mcp-args.js";
|
|
7
10
|
export const toolServerName = "forge";
|
|
8
11
|
export const completionRedactionSecretsEnv = "FORGE_COMPLETION_REDACTION_SECRETS";
|
|
9
12
|
export const completionPhaseOrder = ["implementation", "self_review", "validation"];
|
|
@@ -209,42 +212,20 @@ export const phaseFiles = {
|
|
|
209
212
|
comment_repair: {
|
|
210
213
|
jsonFileName: "comment-repair.handoff.json",
|
|
211
214
|
reportFileName: "comment-repair.report.md"
|
|
215
|
+
},
|
|
216
|
+
pr_review: {
|
|
217
|
+
jsonFileName: "pr-review.result.json",
|
|
218
|
+
reportFileName: "pr-review.report.md"
|
|
212
219
|
}
|
|
213
220
|
};
|
|
221
|
+
/** Statuses `forge.complete_pr_review` accepts; each one ends the review lane. */
|
|
222
|
+
export const prReviewStatuses = ["reviewed", "stale_head", "blocked"];
|
|
214
223
|
export function completionPhaseFromDispatch(dispatch) {
|
|
215
224
|
return normalizeCompletionPhase(dispatch.cycleRun.phase || dispatch.execution.lane || dispatch.execution.role);
|
|
216
225
|
}
|
|
217
226
|
export function normalizeCompletionPhase(value) {
|
|
218
227
|
const normalized = (value ?? "").trim().toLowerCase().replace(/-/g, "_");
|
|
219
|
-
|
|
220
|
-
if (debugPhase) {
|
|
221
|
-
return debugPhase;
|
|
222
|
-
}
|
|
223
|
-
if (normalized === "self_review" || normalized === "selfreview" || normalized === "review") {
|
|
224
|
-
return "self_review";
|
|
225
|
-
}
|
|
226
|
-
if (normalized === "validate" || normalized === "validation") {
|
|
227
|
-
return "validation";
|
|
228
|
-
}
|
|
229
|
-
if (normalized === "qa" || normalized === "quality_assurance" || normalized === "qualityassurance") {
|
|
230
|
-
return "qa";
|
|
231
|
-
}
|
|
232
|
-
if (normalized === "architect" || normalized === "architect_plan" || normalized === "planning" || normalized === "plan") {
|
|
233
|
-
return "architect";
|
|
234
|
-
}
|
|
235
|
-
if (normalized === "draft" || normalized === "drafting" || normalized === "draft_work_order") {
|
|
236
|
-
return "draft";
|
|
237
|
-
}
|
|
238
|
-
if (normalized === "decompose" || normalized === "decomposition" || normalized === "work_order_decomposition" || normalized === "feature_decomposition") {
|
|
239
|
-
return "decompose";
|
|
240
|
-
}
|
|
241
|
-
if (normalized === "ci_repair" || normalized === "pr_checks" || normalized === "repair_pr_checks") {
|
|
242
|
-
return "ci_repair";
|
|
243
|
-
}
|
|
244
|
-
if (normalized === "comment_repair" || normalized === "pr_comments" || normalized === "repair_pr_comments") {
|
|
245
|
-
return "comment_repair";
|
|
246
|
-
}
|
|
247
|
-
return "implementation";
|
|
228
|
+
return normalizeDebugCompletionPhase(normalized) ?? completionPhaseFromAlias(normalized) ?? "implementation";
|
|
248
229
|
}
|
|
249
230
|
export function usesDevelopCycleCompletion(dispatch) {
|
|
250
231
|
const kind = dispatch.cycleRun.kind.trim().toLowerCase();
|
|
@@ -299,9 +280,11 @@ export function completionToolNamesForPhase(phase) {
|
|
|
299
280
|
? "complete_ci_repair"
|
|
300
281
|
: phase === "comment_repair"
|
|
301
282
|
? "complete_comment_repair"
|
|
302
|
-
: phase === "
|
|
303
|
-
? "
|
|
304
|
-
: "
|
|
283
|
+
: phase === "pr_review"
|
|
284
|
+
? "complete_pr_review"
|
|
285
|
+
: phase === "architect"
|
|
286
|
+
? "complete_architect_plan"
|
|
287
|
+
: "complete_qa";
|
|
305
288
|
return [`forge.${base}`, base];
|
|
306
289
|
}
|
|
307
290
|
export function completionToolNamesForQaGate(gate) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CompletionToolServerConfig } from "./phase-completion.js";
|
|
2
|
+
export declare function buildCompletionToolServerArgs(config: CompletionToolServerConfig): readonly string[];
|
|
3
|
+
export declare function parseCompletionMcpArgs(argv: readonly string[]): {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly config: CompletionToolServerConfig;
|
|
6
|
+
} | {
|
|
7
|
+
readonly ok: false;
|
|
8
|
+
readonly error: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
|
|
3
|
+
import { completionRedactionSecretsEnv, } from "./phase-completion.js";
|
|
4
|
+
import { isDebugCompletionPhase, isDevelopCompletionPhase, normalizedOwnerType, parseCompletionRedactionSecrets, parseStrictCompletionPhase, } from "./phase-completion.validation.js";
|
|
5
|
+
// The `forge-bridge mcp` command line: the arguments the Bridge launches its completion-tool server
|
|
6
|
+
// with, and the parsing that server applies to them.
|
|
7
|
+
export function buildCompletionToolServerArgs(config) {
|
|
8
|
+
const args = [
|
|
9
|
+
"mcp",
|
|
10
|
+
"--worktree",
|
|
11
|
+
path.resolve(config.worktreePath),
|
|
12
|
+
"--work-item-id",
|
|
13
|
+
config.workItemId,
|
|
14
|
+
"--phase",
|
|
15
|
+
config.phase,
|
|
16
|
+
"--produced-by",
|
|
17
|
+
config.producedBy ?? "forge-completion-tool"
|
|
18
|
+
];
|
|
19
|
+
if (config.ownerType || config.ownerId) {
|
|
20
|
+
args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
|
|
21
|
+
args.push("--owner-id", config.ownerId ?? config.workItemId);
|
|
22
|
+
}
|
|
23
|
+
if (config.developCycle) {
|
|
24
|
+
args.push("--develop-cycle");
|
|
25
|
+
}
|
|
26
|
+
if (config.qaCycle) {
|
|
27
|
+
args.push("--qa-cycle");
|
|
28
|
+
}
|
|
29
|
+
if (config.debugCycle) {
|
|
30
|
+
args.push("--debug-cycle");
|
|
31
|
+
}
|
|
32
|
+
if (config.architectCycle) {
|
|
33
|
+
args.push("--architect-cycle");
|
|
34
|
+
}
|
|
35
|
+
if (config.draftCycle) {
|
|
36
|
+
args.push("--draft-cycle");
|
|
37
|
+
}
|
|
38
|
+
if (config.decomposeCycle) {
|
|
39
|
+
args.push("--decompose-cycle");
|
|
40
|
+
}
|
|
41
|
+
if (config.managedToolsOnly) {
|
|
42
|
+
args.push("--managed-tools-only");
|
|
43
|
+
}
|
|
44
|
+
if (config.prReview?.headSha) {
|
|
45
|
+
args.push("--pr-review-head", config.prReview.headSha);
|
|
46
|
+
}
|
|
47
|
+
if (config.prReview?.baseSha) {
|
|
48
|
+
args.push("--pr-review-base", config.prReview.baseSha);
|
|
49
|
+
}
|
|
50
|
+
for (const threadId of config.prReview?.threadIds ?? []) {
|
|
51
|
+
args.push("--pr-review-thread", threadId);
|
|
52
|
+
}
|
|
53
|
+
return args;
|
|
54
|
+
}
|
|
55
|
+
const completionMcpFlags = {
|
|
56
|
+
"--develop-cycle": "developCycle",
|
|
57
|
+
"--qa-cycle": "qaCycle",
|
|
58
|
+
"--debug-cycle": "debugCycle",
|
|
59
|
+
"--architect-cycle": "architectCycle",
|
|
60
|
+
"--draft-cycle": "draftCycle",
|
|
61
|
+
"--decompose-cycle": "decomposeCycle",
|
|
62
|
+
"--managed-tools-only": "managedToolsOnly",
|
|
63
|
+
};
|
|
64
|
+
const completionMcpValues = {
|
|
65
|
+
"--worktree": "worktreePath",
|
|
66
|
+
"--work-item-id": "workItemId",
|
|
67
|
+
"--owner-id": "ownerId",
|
|
68
|
+
"--produced-by": "producedBy",
|
|
69
|
+
};
|
|
70
|
+
export function parseCompletionMcpArgs(argv) {
|
|
71
|
+
let phase = "implementation";
|
|
72
|
+
let ownerType;
|
|
73
|
+
const values = {};
|
|
74
|
+
const prReview = { threadIds: [] };
|
|
75
|
+
const flags = {
|
|
76
|
+
developCycle: false,
|
|
77
|
+
qaCycle: false,
|
|
78
|
+
debugCycle: false,
|
|
79
|
+
architectCycle: false,
|
|
80
|
+
draftCycle: false,
|
|
81
|
+
decomposeCycle: false,
|
|
82
|
+
managedToolsOnly: false,
|
|
83
|
+
};
|
|
84
|
+
for (let index = 1; index < argv.length; index += 1) {
|
|
85
|
+
const arg = argv[index];
|
|
86
|
+
if (Object.hasOwn(completionMcpFlags, arg)) {
|
|
87
|
+
flags[completionMcpFlags[arg]] = true;
|
|
88
|
+
}
|
|
89
|
+
else if (Object.hasOwn(completionMcpValues, arg)) {
|
|
90
|
+
values[completionMcpValues[arg]] = argv[++index];
|
|
91
|
+
}
|
|
92
|
+
else if (applyPrReviewArg(prReview, arg, () => argv[++index])) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
else if (arg === "--owner-type") {
|
|
96
|
+
ownerType = normalizedOwnerType(argv[++index]);
|
|
97
|
+
if (!ownerType) {
|
|
98
|
+
return { ok: false, error: "mcp --owner-type must be work_item or story." };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (arg === "--phase") {
|
|
102
|
+
const rawPhase = argv[++index];
|
|
103
|
+
const parsedPhase = parseStrictCompletionPhase(rawPhase);
|
|
104
|
+
if (!parsedPhase) {
|
|
105
|
+
return { ok: false, error: "mcp --phase must be one of: implementation, self-review, validation, qa, architect, draft, decompose, ci-repair, comment-repair, pr-review, debug-repro, debug-root-cause, debug-fix, debug-regression." };
|
|
106
|
+
}
|
|
107
|
+
phase = parsedPhase;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return { ok: false, error: `Unknown mcp argument: ${arg}` };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const { worktreePath, workItemId, ownerId, producedBy } = values;
|
|
114
|
+
if (!worktreePath?.trim() || !workItemId?.trim()) {
|
|
115
|
+
return { ok: false, error: "mcp requires --worktree and --work-item-id." };
|
|
116
|
+
}
|
|
117
|
+
const { managedToolsOnly, ...cycles } = flags;
|
|
118
|
+
const config = {
|
|
119
|
+
worktreePath: path.resolve(worktreePath),
|
|
120
|
+
workItemId,
|
|
121
|
+
ownerType,
|
|
122
|
+
ownerId,
|
|
123
|
+
phase,
|
|
124
|
+
producedBy,
|
|
125
|
+
redactionSecrets: redactionSecretsFromEnvironment(),
|
|
126
|
+
...cycles,
|
|
127
|
+
...(managedToolsOnly ? { managedToolsOnly } : {}),
|
|
128
|
+
...prReviewConfig(prReview)
|
|
129
|
+
};
|
|
130
|
+
const modeError = completionMcpModeError(config);
|
|
131
|
+
return modeError ? { ok: false, error: modeError } : { ok: true, config };
|
|
132
|
+
}
|
|
133
|
+
/** Applies one pr_review dispatch-context flag; false when the flag is not one of them. */
|
|
134
|
+
function applyPrReviewArg(state, arg, next) {
|
|
135
|
+
switch (arg) {
|
|
136
|
+
case "--pr-review-head":
|
|
137
|
+
state.headSha = next()?.trim() || undefined;
|
|
138
|
+
return true;
|
|
139
|
+
case "--pr-review-base":
|
|
140
|
+
state.baseSha = next()?.trim() || undefined;
|
|
141
|
+
return true;
|
|
142
|
+
case "--pr-review-thread": {
|
|
143
|
+
const threadId = next()?.trim();
|
|
144
|
+
if (threadId)
|
|
145
|
+
state.threadIds.push(threadId);
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function prReviewConfig(state) {
|
|
153
|
+
const { headSha, baseSha, threadIds } = state;
|
|
154
|
+
return headSha || baseSha || threadIds.length > 0
|
|
155
|
+
? { prReview: { headSha, baseSha, threadIds: threadIds.length > 0 ? threadIds : undefined } }
|
|
156
|
+
: {};
|
|
157
|
+
}
|
|
158
|
+
/** The secrets the server redacts from what it records: the Bridge's list and the attempt database capability. */
|
|
159
|
+
function redactionSecretsFromEnvironment() {
|
|
160
|
+
return [
|
|
161
|
+
...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
|
|
162
|
+
...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
/** Why the parsed cycle mode, phase and tool scope cannot run together, or null when they can. */
|
|
166
|
+
function completionMcpModeError(config) {
|
|
167
|
+
const { phase } = config;
|
|
168
|
+
const cycleModes = [config.developCycle, config.qaCycle, config.debugCycle, config.architectCycle, config.draftCycle, config.decomposeCycle]
|
|
169
|
+
.filter(Boolean).length;
|
|
170
|
+
if (cycleModes > 1) {
|
|
171
|
+
return "mcp accepts only one cycle mode.";
|
|
172
|
+
}
|
|
173
|
+
if (config.managedToolsOnly && cycleModes > 0) {
|
|
174
|
+
return "mcp --managed-tools-only serves no completion tools, so it accepts no cycle mode.";
|
|
175
|
+
}
|
|
176
|
+
if (config.developCycle && !isDevelopCompletionPhase(phase)) {
|
|
177
|
+
return "mcp --develop-cycle requires --phase implementation, self-review, or validation.";
|
|
178
|
+
}
|
|
179
|
+
if (config.qaCycle && phase !== "qa") {
|
|
180
|
+
return "mcp --qa-cycle requires --phase qa.";
|
|
181
|
+
}
|
|
182
|
+
if (config.debugCycle && !isDebugCompletionPhase(phase)) {
|
|
183
|
+
return "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression.";
|
|
184
|
+
}
|
|
185
|
+
if (config.architectCycle && phase !== "architect") {
|
|
186
|
+
return "mcp --architect-cycle requires --phase architect.";
|
|
187
|
+
}
|
|
188
|
+
if (config.draftCycle && phase !== "draft") {
|
|
189
|
+
return "mcp --draft-cycle requires --phase draft.";
|
|
190
|
+
}
|
|
191
|
+
if (config.decomposeCycle && phase !== "decompose") {
|
|
192
|
+
return "mcp --decompose-cycle requires --phase decompose.";
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CompletionPhase } from "./phase-completion.js";
|
|
2
|
+
/** Resolves an already-normalized (trimmed, lower-case, underscore) phase alias, or null. */
|
|
3
|
+
export declare function completionPhaseFromAlias(normalized: string): CompletionPhase | null;
|
|
4
|
+
/** Resolves a fixed single-gate completion tool name (with or without the forge. prefix), or null. */
|
|
5
|
+
export declare function singleGatePhaseFromToolName(toolName: string): CompletionPhase | null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Table-driven phase aliases and tool names. Debug phases are resolved separately because they
|
|
2
|
+
// have their own normalizer. Aliases are disjoint, so lookup order never changes a result.
|
|
3
|
+
const phaseAliases = [
|
|
4
|
+
["implementation", ["implementation", "implement", "develop"]],
|
|
5
|
+
["self_review", ["self_review", "selfreview", "review"]],
|
|
6
|
+
["validation", ["validate", "validation"]],
|
|
7
|
+
["qa", ["qa", "quality_assurance", "qualityassurance"]],
|
|
8
|
+
["architect", ["architect", "architect_plan", "planning", "plan"]],
|
|
9
|
+
["draft", ["draft", "drafting", "draft_work_order"]],
|
|
10
|
+
["decompose", ["decompose", "decomposition", "work_order_decomposition", "feature_decomposition"]],
|
|
11
|
+
["ci_repair", ["ci_repair", "pr_checks", "repair_pr_checks"]],
|
|
12
|
+
["comment_repair", ["comment_repair", "pr_comments", "repair_pr_comments"]],
|
|
13
|
+
["pr_review", ["pr_review", "prreview", "pull_request_review"]]
|
|
14
|
+
];
|
|
15
|
+
/** Resolves an already-normalized (trimmed, lower-case, underscore) phase alias, or null. */
|
|
16
|
+
export function completionPhaseFromAlias(normalized) {
|
|
17
|
+
for (const [phase, aliases] of phaseAliases) {
|
|
18
|
+
if (aliases.includes(normalized)) {
|
|
19
|
+
return phase;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const phaseToolNames = [
|
|
25
|
+
["implementation", "complete_implementation"],
|
|
26
|
+
["self_review", "complete_self_review"],
|
|
27
|
+
["validation", "complete_validation"],
|
|
28
|
+
["qa", "complete_qa"],
|
|
29
|
+
["architect", "complete_architect_plan"],
|
|
30
|
+
["ci_repair", "complete_ci_repair"],
|
|
31
|
+
["comment_repair", "complete_comment_repair"],
|
|
32
|
+
["pr_review", "complete_pr_review"]
|
|
33
|
+
];
|
|
34
|
+
/** Resolves a fixed single-gate completion tool name (with or without the forge. prefix), or null. */
|
|
35
|
+
export function singleGatePhaseFromToolName(toolName) {
|
|
36
|
+
const normalized = toolName.trim().toLowerCase();
|
|
37
|
+
for (const [phase, base] of phaseToolNames) {
|
|
38
|
+
if (normalized === `forge.${base}` || normalized === base) {
|
|
39
|
+
return phase;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prReviewToolInputSchema(): unknown;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { evidenceObjectSchema, objectToolSchema } from "./phase-completion.schema-parts.js";
|
|
2
|
+
export function prReviewToolInputSchema() {
|
|
3
|
+
const stringArray = { type: "array", items: { type: "string" } };
|
|
4
|
+
return objectToolSchema({
|
|
5
|
+
status: {
|
|
6
|
+
type: "string",
|
|
7
|
+
enum: ["reviewed", "stale_head", "blocked"],
|
|
8
|
+
description: "reviewed for a completed review. stale_head when `git rev-parse HEAD` differs from the dispatched head_sha (set head_sha to what you found). blocked, with a reason, when the diff cannot be read."
|
|
9
|
+
},
|
|
10
|
+
head_sha: { type: "string", description: "Full sha of the head you reviewed: the output of `git rev-parse HEAD`. Must be the dispatched head for status reviewed." },
|
|
11
|
+
base_sha: { type: "string", description: "The dispatched base sha you diffed against." },
|
|
12
|
+
review_effort: { type: "string", enum: ["lite", "standard", "deep"] },
|
|
13
|
+
verdict: { type: "string", enum: ["changes_recommended", "needs_closer_look", "approval_recommended"], description: "changes_recommended exactly when there is an open issue: a finding in this payload or a prior thread that is still_open or reintroduced." },
|
|
14
|
+
verdict_reason: { type: "string", description: "One sentence naming the open issues, or why approval is or is not recommended." },
|
|
15
|
+
summary: { type: "string", description: "A paragraph on what the pull request does." },
|
|
16
|
+
reason: { type: "string", description: "Required for status blocked: why the review could not be done." },
|
|
17
|
+
changes: { ...stringArray, description: "The main changes, as short bullets." },
|
|
18
|
+
files: {
|
|
19
|
+
type: "array",
|
|
20
|
+
description: "The reviewed files with a short description each.",
|
|
21
|
+
items: evidenceObjectSchema(["path", "description"], { path: { type: "string" }, description: { type: "string" } })
|
|
22
|
+
},
|
|
23
|
+
findings: {
|
|
24
|
+
type: "array",
|
|
25
|
+
description: "New inline comments only; may be empty. Every line must be on the new side of the pull request diff.",
|
|
26
|
+
items: evidenceObjectSchema(["path", "line", "side", "severity", "category", "title", "body"], {
|
|
27
|
+
path: { type: "string" },
|
|
28
|
+
line: { type: "integer", minimum: 1, description: "A line on the new side of the PR diff (a changed or context line inside a hunk)." },
|
|
29
|
+
start_line: { type: ["integer", "null"], minimum: 1, description: "First line of a multi-line range inside the same hunk, or null." },
|
|
30
|
+
side: { type: "string", enum: ["RIGHT"] },
|
|
31
|
+
severity: { type: "string", enum: ["high", "medium", "low"] },
|
|
32
|
+
category: { type: "string", enum: ["correctness", "security", "contract", "tests", "data", "docs"] },
|
|
33
|
+
title: { type: "string", description: "At most about 70 characters naming the defect." },
|
|
34
|
+
body: { type: "string", description: "The inline comment: defect, concrete scenario, evidence as path:line, and what to change." },
|
|
35
|
+
also_at: {
|
|
36
|
+
type: "array",
|
|
37
|
+
items: evidenceObjectSchema(["path", "line"], { path: { type: "string" }, line: { type: "integer", minimum: 1 } })
|
|
38
|
+
},
|
|
39
|
+
suggestion: { type: ["string", "null"] }
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
prior_threads: {
|
|
43
|
+
type: "array",
|
|
44
|
+
description: "Prior review threads from the dispatch, by thread_id. Still-open threads belong here, not in findings.",
|
|
45
|
+
items: evidenceObjectSchema(["thread_id", "status"], {
|
|
46
|
+
thread_id: { type: "string" },
|
|
47
|
+
status: { type: "string", enum: ["resolved_since_last_review", "still_open", "reintroduced"] }
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
tests_checked: {
|
|
51
|
+
type: "array",
|
|
52
|
+
description: "New or changed test assertions you traced to production code. produced_at \"not produced\" needs a matching tests finding.",
|
|
53
|
+
items: evidenceObjectSchema(["test", "assertion", "produced_at"], { test: { type: "string" }, assertion: { type: "string" }, produced_at: { type: "string" } })
|
|
54
|
+
},
|
|
55
|
+
security_review: {
|
|
56
|
+
type: "object",
|
|
57
|
+
additionalProperties: true,
|
|
58
|
+
description: "Required on every reviewed payload, including reviews with no findings.",
|
|
59
|
+
properties: {
|
|
60
|
+
status: { type: "string", enum: ["findings", "no_findings"], description: "findings exactly when some finding has category security." },
|
|
61
|
+
checked: stringArray,
|
|
62
|
+
keys_checked: {
|
|
63
|
+
type: "array",
|
|
64
|
+
items: evidenceObjectSchema(["key", "per_user_data", "includes_user"], { key: { type: "string" }, per_user_data: { type: "boolean" }, includes_user: { type: "boolean" } })
|
|
65
|
+
},
|
|
66
|
+
notes: { type: "string" }
|
|
67
|
+
},
|
|
68
|
+
required: ["status", "checked", "keys_checked", "notes"]
|
|
69
|
+
},
|
|
70
|
+
skipped_files: {
|
|
71
|
+
type: "array",
|
|
72
|
+
items: evidenceObjectSchema(["path", "reason"], { path: { type: "string" }, reason: { type: "string" } })
|
|
73
|
+
}
|
|
74
|
+
}, ["status"], "For status reviewed, include head_sha, base_sha, review_effort, verdict, verdict_reason, summary, changes, files, findings, security_review. For stale_head include head_sha. For blocked include reason. Forge rejects a head_sha that is not the checked-out head, non-RIGHT sides, lines off the diff, a verdict that contradicts the open issues, and unknown prior thread ids; fix the fields it names and call again.");
|
|
75
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PrReviewCompletionContext, PrReviewStatus } from "./phase-completion.js";
|
|
2
|
+
/** Per-finding limits; Forge's API applies the same ones (PrReviewArtifactValidator.MaximumFindingTextCharacters). */
|
|
3
|
+
export declare const prReviewMaximumFindingTextCharacters: number;
|
|
4
|
+
/**
|
|
5
|
+
* Shape and consistency rules for `forge.complete_pr_review`. Anything that needs the
|
|
6
|
+
* repository (the worktree head, the diff lines) is checked separately, after this passes.
|
|
7
|
+
*
|
|
8
|
+
* `stale_head` and `blocked` are terminal outcomes, not reviews: they need only enough
|
|
9
|
+
* evidence to explain themselves. A `reviewed` payload is held to the skill's full contract.
|
|
10
|
+
*/
|
|
11
|
+
export declare function validatePrReviewPayloadShape(payload: Record<string, unknown>, status: PrReviewStatus, context?: PrReviewCompletionContext | undefined): void;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { normalizedString, optionalString, requireArray, requireArrayRecord, requireEvidenceRecord, requireKnownStringRecord, requireNonEmptyStringArrayRecord, requireNonEmptyStringRecord, requireObject, requiredRecord } from "./phase-completion.helpers.js";
|
|
2
|
+
const prReviewVerdicts = new Set(["changes_recommended", "needs_closer_look", "approval_recommended"]);
|
|
3
|
+
const prReviewEfforts = new Set(["lite", "standard", "deep"]);
|
|
4
|
+
const prReviewSeverities = new Set(["high", "medium", "low"]);
|
|
5
|
+
const prReviewCategories = new Set(["correctness", "security", "contract", "tests", "data", "docs"]);
|
|
6
|
+
const prReviewThreadStatuses = new Set(["resolved_since_last_review", "still_open", "reintroduced"]);
|
|
7
|
+
const prReviewShaPattern = /^[0-9a-f]{7,64}$/iu;
|
|
8
|
+
/** Per-finding limits; Forge's API applies the same ones (PrReviewArtifactValidator.MaximumFindingTextCharacters). */
|
|
9
|
+
export const prReviewMaximumFindingTextCharacters = 8 * 1024;
|
|
10
|
+
/**
|
|
11
|
+
* Shape and consistency rules for `forge.complete_pr_review`. Anything that needs the
|
|
12
|
+
* repository (the worktree head, the diff lines) is checked separately, after this passes.
|
|
13
|
+
*
|
|
14
|
+
* `stale_head` and `blocked` are terminal outcomes, not reviews: they need only enough
|
|
15
|
+
* evidence to explain themselves. A `reviewed` payload is held to the skill's full contract.
|
|
16
|
+
*/
|
|
17
|
+
export function validatePrReviewPayloadShape(payload, status, context = undefined) {
|
|
18
|
+
if (status === "blocked") {
|
|
19
|
+
validateBlockedPrReview(payload);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const headSha = requirePrReviewHeadSha(payload);
|
|
23
|
+
const expectedHead = context?.headSha?.trim().toLowerCase();
|
|
24
|
+
if (status === "stale_head") {
|
|
25
|
+
if (expectedHead && headSha.toLowerCase() === expectedHead) {
|
|
26
|
+
throw new Error(`head_sha ${headSha} is the dispatched head, so the worktree is not stale. Review that commit and complete with status "reviewed", or set head_sha to the different commit you found.`);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (expectedHead && headSha.toLowerCase() !== expectedHead) {
|
|
31
|
+
throw new Error(`head_sha ${headSha} is not the head Forge dispatched (${context.headSha}). A review is bound to the dispatched head: review that commit, or complete with status "stale_head" and head_sha set to the commit you found if the worktree is on a different one.`);
|
|
32
|
+
}
|
|
33
|
+
validateReviewedPrReviewHeader(payload);
|
|
34
|
+
validatePrReviewChanges(payload);
|
|
35
|
+
validatePrReviewRecords(payload, "files", ["path", "description"]);
|
|
36
|
+
validatePrReviewRecords(payload, "skipped_files", ["path", "reason"], false);
|
|
37
|
+
validatePrReviewRecords(payload, "tests_checked", ["test", "assertion", "produced_at"], false);
|
|
38
|
+
requireArray(payload, "findings");
|
|
39
|
+
const findings = payload.findings;
|
|
40
|
+
for (const [index, finding] of findings.entries()) {
|
|
41
|
+
validatePrReviewFinding(finding, `findings[${index}]`);
|
|
42
|
+
}
|
|
43
|
+
const openThreads = validatePrReviewPriorThreads(payload, context);
|
|
44
|
+
validatePrReviewVerdictConsistency(payload, findings.length, openThreads);
|
|
45
|
+
validatePrReviewSecurity(payload, findings);
|
|
46
|
+
validatePrReviewTestsChecked(payload, findings);
|
|
47
|
+
}
|
|
48
|
+
function validateBlockedPrReview(payload) {
|
|
49
|
+
const hasReason = ["reason", "summary", "verdict_reason"].some((key) => optionalString(payload, key))
|
|
50
|
+
|| (Array.isArray(payload.blockers) && payload.blockers.length > 0);
|
|
51
|
+
if (!hasReason) {
|
|
52
|
+
throw new Error("A blocked pr_review needs a reason: set reason (or summary) to say why the diff could not be read.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function requirePrReviewHeadSha(payload) {
|
|
56
|
+
requireNonEmptyStringRecord(payload, "head_sha", "");
|
|
57
|
+
const headSha = optionalString(payload, "head_sha").trim();
|
|
58
|
+
if (!prReviewShaPattern.test(headSha)) {
|
|
59
|
+
throw new Error("head_sha must be a commit sha (7-64 hex characters); copy it from `git rev-parse HEAD`.");
|
|
60
|
+
}
|
|
61
|
+
return headSha;
|
|
62
|
+
}
|
|
63
|
+
function validateReviewedPrReviewHeader(payload) {
|
|
64
|
+
requireNonEmptyStringRecord(payload, "base_sha", "");
|
|
65
|
+
if (!prReviewShaPattern.test(optionalString(payload, "base_sha").trim())) {
|
|
66
|
+
throw new Error("base_sha must be a commit sha (7-64 hex characters).");
|
|
67
|
+
}
|
|
68
|
+
requireKnownStringRecord(payload, "review_effort", prReviewEfforts);
|
|
69
|
+
requireKnownStringRecord(payload, "verdict", prReviewVerdicts);
|
|
70
|
+
requireNonEmptyStringRecord(payload, "verdict_reason", "");
|
|
71
|
+
requireNonEmptyStringRecord(payload, "summary", "");
|
|
72
|
+
}
|
|
73
|
+
function validatePrReviewChanges(payload) {
|
|
74
|
+
requireArray(payload, "changes");
|
|
75
|
+
for (const [index, change] of payload.changes.entries()) {
|
|
76
|
+
if (typeof change !== "string" || change.trim().length === 0) {
|
|
77
|
+
throw new Error(`changes[${index}] must be a non-empty string.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Validates prior_threads and returns how many are still_open or reintroduced. */
|
|
82
|
+
function validatePrReviewPriorThreads(payload, context) {
|
|
83
|
+
const priorThreads = payload.prior_threads === undefined || payload.prior_threads === null ? [] : payload.prior_threads;
|
|
84
|
+
if (!Array.isArray(priorThreads)) {
|
|
85
|
+
throw new Error("prior_threads must be an array.");
|
|
86
|
+
}
|
|
87
|
+
const knownThreadIds = context?.threadIds && context.threadIds.length > 0 ? new Set(context.threadIds) : null;
|
|
88
|
+
const seenThreads = new Set();
|
|
89
|
+
let openThreads = 0;
|
|
90
|
+
for (const [index, thread] of priorThreads.entries()) {
|
|
91
|
+
requireEvidenceRecord(thread, `prior_threads[${index}]`);
|
|
92
|
+
const record = thread;
|
|
93
|
+
requireNonEmptyStringRecord(record, "thread_id", `prior_threads[${index}].`);
|
|
94
|
+
requireKnownStringRecord(record, "status", prReviewThreadStatuses, `prior_threads[${index}].`);
|
|
95
|
+
const threadId = optionalString(record, "thread_id");
|
|
96
|
+
if (knownThreadIds && !knownThreadIds.has(threadId)) {
|
|
97
|
+
throw new Error(`prior_threads[${index}].thread_id ${threadId} is not a thread in the dispatch. Use only thread ids from the dispatch's prior_threads (${[...knownThreadIds].slice(0, 10).join(", ")}${knownThreadIds.size > 10 ? ", ..." : ""}) and drop the entry if the thread is not one of them.`);
|
|
98
|
+
}
|
|
99
|
+
if (seenThreads.has(threadId)) {
|
|
100
|
+
throw new Error(`prior_threads[${index}] repeats thread ${threadId}; report each thread once.`);
|
|
101
|
+
}
|
|
102
|
+
seenThreads.add(threadId);
|
|
103
|
+
const threadStatus = normalizedString(optionalString(record, "status"));
|
|
104
|
+
if (threadStatus === "still_open" || threadStatus === "reintroduced")
|
|
105
|
+
openThreads += 1;
|
|
106
|
+
}
|
|
107
|
+
return openThreads;
|
|
108
|
+
}
|
|
109
|
+
function validatePrReviewVerdictConsistency(payload, findingCount, openThreads) {
|
|
110
|
+
const openIssues = findingCount + openThreads;
|
|
111
|
+
const verdict = normalizedString(optionalString(payload, "verdict"));
|
|
112
|
+
if (openIssues > 0 && verdict !== "changes_recommended") {
|
|
113
|
+
throw new Error(`verdict ${verdict} contradicts ${openIssues} open issue(s) (${findingCount} new finding(s), ${openThreads} still_open or reintroduced prior thread(s)). Set verdict to changes_recommended, or remove findings you cannot prove.`);
|
|
114
|
+
}
|
|
115
|
+
if (openIssues === 0 && verdict === "changes_recommended") {
|
|
116
|
+
throw new Error("verdict changes_recommended needs at least one open issue: a finding, or a prior thread that is still_open or reintroduced. Use approval_recommended, or needs_closer_look when you could not verify a risky surface.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function hasFindingCategory(findings, category) {
|
|
120
|
+
return findings.some((finding) => normalizedString(finding.category) === category);
|
|
121
|
+
}
|
|
122
|
+
function validatePrReviewSecurity(payload, findings) {
|
|
123
|
+
requireObject(payload, "security_review");
|
|
124
|
+
const security = requiredRecord(payload, "security_review");
|
|
125
|
+
requireKnownStringRecord(security, "status", new Set(["findings", "no_findings"]), "security_review.");
|
|
126
|
+
requireNonEmptyStringArrayRecord(security, "checked", "security_review.");
|
|
127
|
+
requireNonEmptyStringRecord(security, "notes", "security_review.");
|
|
128
|
+
requireArrayRecord(security, "keys_checked", "security_review.");
|
|
129
|
+
const hasSecurityFinding = hasFindingCategory(findings, "security");
|
|
130
|
+
const securityStatus = normalizedString(optionalString(security, "status"));
|
|
131
|
+
if (hasSecurityFinding && securityStatus !== "findings") {
|
|
132
|
+
throw new Error('security_review.status must be "findings" when any finding has category "security".');
|
|
133
|
+
}
|
|
134
|
+
if (!hasSecurityFinding && securityStatus === "findings") {
|
|
135
|
+
throw new Error('security_review.status is "findings" but no finding has category "security". Add the finding or set status to "no_findings".');
|
|
136
|
+
}
|
|
137
|
+
for (const [index, key] of security.keys_checked.entries()) {
|
|
138
|
+
requireEvidenceRecord(key, `security_review.keys_checked[${index}]`);
|
|
139
|
+
const record = key;
|
|
140
|
+
requireNonEmptyStringRecord(record, "key", `security_review.keys_checked[${index}].`);
|
|
141
|
+
if (typeof record.per_user_data !== "boolean" || typeof record.includes_user !== "boolean") {
|
|
142
|
+
throw new Error(`security_review.keys_checked[${index}] needs boolean per_user_data and includes_user.`);
|
|
143
|
+
}
|
|
144
|
+
if (record.per_user_data === true && record.includes_user === false && !hasSecurityFinding) {
|
|
145
|
+
throw new Error(`security_review.keys_checked[${index}] holds per-user data under a key without the user, which must have a matching security finding. Add the finding.`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function validatePrReviewTestsChecked(payload, findings) {
|
|
150
|
+
const hasTestsFinding = hasFindingCategory(findings, "tests");
|
|
151
|
+
for (const [index, entry] of (payload.tests_checked ?? []).entries()) {
|
|
152
|
+
const produced = normalizedString(optionalString(entry, "produced_at")).replace(/_/gu, " ");
|
|
153
|
+
if (produced === "not produced" && !hasTestsFinding) {
|
|
154
|
+
throw new Error(`tests_checked[${index}] was not produced by production code, so the test cannot pass; it must have a matching finding with category "tests". Add the finding.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function validatePrReviewRecords(payload, key, fields, required = true) {
|
|
159
|
+
if ((payload[key] === undefined || payload[key] === null) && !required)
|
|
160
|
+
return;
|
|
161
|
+
requireArray(payload, key);
|
|
162
|
+
for (const [index, entry] of payload[key].entries()) {
|
|
163
|
+
requireEvidenceRecord(entry, `${key}[${index}]`);
|
|
164
|
+
for (const field of fields) {
|
|
165
|
+
requireNonEmptyStringRecord(entry, field, `${key}[${index}].`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function validatePrReviewFinding(finding, label) {
|
|
170
|
+
requireEvidenceRecord(finding, label);
|
|
171
|
+
const record = finding;
|
|
172
|
+
for (const key of ["path", "title", "body"]) {
|
|
173
|
+
requireNonEmptyStringRecord(record, key, `${label}.`);
|
|
174
|
+
}
|
|
175
|
+
if (!Number.isInteger(record.line) || record.line < 1) {
|
|
176
|
+
throw new Error(`${label}.line must be a positive integer line number on the new side of the diff.`);
|
|
177
|
+
}
|
|
178
|
+
if (record.start_line !== undefined && record.start_line !== null) {
|
|
179
|
+
if (!Number.isInteger(record.start_line) || record.start_line < 1 || record.start_line >= record.line) {
|
|
180
|
+
throw new Error(`${label}.start_line must be null (single-line comment) or a positive integer strictly less than line.`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (record.side !== "RIGHT") {
|
|
184
|
+
throw new Error(`${label}.side must be "RIGHT": inline comments anchor on the new side of the diff. Re-anchor the comment at the changed line on the new side, and name any unchanged location in the body as path:line.`);
|
|
185
|
+
}
|
|
186
|
+
requireKnownStringRecord(record, "severity", prReviewSeverities, `${label}.`);
|
|
187
|
+
requireKnownStringRecord(record, "category", prReviewCategories, `${label}.`);
|
|
188
|
+
if (record.also_at !== undefined && record.also_at !== null) {
|
|
189
|
+
if (!Array.isArray(record.also_at))
|
|
190
|
+
throw new Error(`${label}.also_at must be an array.`);
|
|
191
|
+
for (const [index, place] of record.also_at.entries()) {
|
|
192
|
+
requireEvidenceRecord(place, `${label}.also_at[${index}]`);
|
|
193
|
+
requireNonEmptyStringRecord(place, "path", `${label}.also_at[${index}].`);
|
|
194
|
+
if (!Number.isInteger(place.line) || place.line < 1) {
|
|
195
|
+
throw new Error(`${label}.also_at[${index}].line must be a positive integer.`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (record.suggestion !== undefined && record.suggestion !== null && typeof record.suggestion !== "string") {
|
|
200
|
+
throw new Error(`${label}.suggestion must be null or a string.`);
|
|
201
|
+
}
|
|
202
|
+
requireFindingTextWithinCap(record, label);
|
|
203
|
+
}
|
|
204
|
+
/** Each finding's body and suggestion becomes one inline comment, which the review body's cap does not cover. */
|
|
205
|
+
function requireFindingTextWithinCap(record, label) {
|
|
206
|
+
for (const key of ["body", "suggestion"]) {
|
|
207
|
+
const value = record[key];
|
|
208
|
+
if (typeof value === "string" && value.length > prReviewMaximumFindingTextCharacters) {
|
|
209
|
+
throw new Error(`${label}.${key} is ${value.length} characters; an inline comment's ${key} may be at most ${prReviewMaximumFindingTextCharacters}. Shorten it to the input, the path and the wrong result.`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|