@effect-agent/pr-review 0.1.0-beta.8 → 0.1.0-beta.80
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/NOTICE +26 -0
- package/README.md +170 -158
- package/dist/Review.d.mts +295 -0
- package/dist/Review.mjs +704 -0
- package/dist/Review.mjs.map +1 -0
- package/dist/ReviewRepository-Wd_4qCaO.d.mts +71 -0
- package/dist/ReviewRepository.d.mts +2 -0
- package/dist/ReviewRepository.mjs +15 -0
- package/dist/ReviewRepository.mjs.map +1 -0
- package/dist/index.d.mts +3 -716
- package/dist/index.mjs +3 -66
- package/dist/repository-BzSG74vX.mjs +101 -0
- package/dist/repository-BzSG74vX.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +1 -54
- package/src/Review.ts +1058 -0
- package/src/ReviewRepository.ts +9 -0
- package/src/index.ts +2 -20
- package/src/internal/repository.ts +156 -0
- package/dist/action.d.mts +0 -185
- package/dist/action.mjs +0 -406
- package/dist/action.mjs.map +0 -1
- package/dist/cli.d.mts +0 -1
- package/dist/cli.mjs +0 -102
- package/dist/cli.mjs.map +0 -1
- package/dist/fan-out-BBEATQwc.d.mts +0 -997
- package/dist/github-BZNzmxao.mjs +0 -1372
- package/dist/github-BZNzmxao.mjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/providers-J6BKHyHe.mjs +0 -986
- package/dist/providers-J6BKHyHe.mjs.map +0 -1
- package/dist/testing.d.mts +0 -131
- package/dist/testing.mjs +0 -228
- package/dist/testing.mjs.map +0 -1
- package/src/action.ts +0 -666
- package/src/cli.ts +0 -213
- package/src/internal/action-entry.ts +0 -41
- package/src/internal/coverage.ts +0 -245
- package/src/internal/diff.ts +0 -134
- package/src/internal/effort.ts +0 -86
- package/src/internal/factory.ts +0 -374
- package/src/internal/fan-out-scripted.ts +0 -164
- package/src/internal/fan-out.ts +0 -450
- package/src/internal/fingerprint.ts +0 -74
- package/src/internal/fixtures.ts +0 -127
- package/src/internal/github-env.ts +0 -128
- package/src/internal/github.ts +0 -531
- package/src/internal/ignore.ts +0 -88
- package/src/internal/profiles.ts +0 -79
- package/src/internal/providers.ts +0 -91
- package/src/internal/render.ts +0 -428
- package/src/internal/review-agent.ts +0 -385
- package/src/internal/review-state.ts +0 -488
- package/src/internal/review-units.ts +0 -167
- package/src/internal/run.ts +0 -397
- package/src/internal/scripted.ts +0 -108
- package/src/internal/source.ts +0 -110
- package/src/testing.ts +0 -8
package/src/action.ts
DELETED
|
@@ -1,666 +0,0 @@
|
|
|
1
|
-
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
2
|
-
import { Config, Console, Effect, FileSystem, Layer, Option, Redacted, Schema } from "effect";
|
|
3
|
-
import { BudgetExceeded, UsageBudgetLimits } from "effect-agent";
|
|
4
|
-
|
|
5
|
-
import { InvalidEffortInput, parseEffortPosition, type EffortPosition } from "./internal/effort.ts";
|
|
6
|
-
import { PrReview, type RunReviewOptions } from "./internal/factory.ts";
|
|
7
|
-
import { readGitHubEvent, resolveReviewTarget, gitHubReviewLayers } from "./internal/github-env.ts";
|
|
8
|
-
import { PriorReviews } from "./internal/github.ts";
|
|
9
|
-
import {
|
|
10
|
-
anthropicClientLayer,
|
|
11
|
-
DEFAULT_PROVIDER,
|
|
12
|
-
describeReviewModel,
|
|
13
|
-
makeAnthropicReviewModel,
|
|
14
|
-
makeOpenAiReviewModel,
|
|
15
|
-
openAiClientLayer,
|
|
16
|
-
type ReviewProvider,
|
|
17
|
-
} from "./internal/providers.ts";
|
|
18
|
-
import {
|
|
19
|
-
ReviewExecutionContext,
|
|
20
|
-
ReviewHeadComparison,
|
|
21
|
-
ReviewStateAuthenticator,
|
|
22
|
-
type ReviewMode,
|
|
23
|
-
type ReviewState,
|
|
24
|
-
selectReviewRange,
|
|
25
|
-
selectedPullRequestSourceLayer,
|
|
26
|
-
unavailableReviewStateAuthenticatorLayer,
|
|
27
|
-
webCryptoReviewStateAuthenticatorLayer,
|
|
28
|
-
} from "./internal/review-state.ts";
|
|
29
|
-
import { fanOutReviewBudgetLimits, reviewBudgetLimits } from "./internal/run.ts";
|
|
30
|
-
import type { ReviewRunOutcome } from "./internal/run.ts";
|
|
31
|
-
import { normalizeRepoRelativePath, PullRequestSource } from "./internal/source.ts";
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// The GitHub Actions entrypoint (deployment class E: one bounded ephemeral
|
|
35
|
-
// run, no exactly-once posting). Bounded continuity state travels in GitHub
|
|
36
|
-
// review bodies and is validated before reuse. Inputs arrive as
|
|
37
|
-
// PR_REVIEW_* environment variables set by the action manifest; the target
|
|
38
|
-
// pull request comes from the standard Actions event environment. A non-PR
|
|
39
|
-
// or draft event is a typed skip — green job, nothing posted. Publication
|
|
40
|
-
// happens only after the run settles, so a failed or truncated run posts
|
|
41
|
-
// nothing.
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
/** Deprecated compatibility input; host-derived conclusions are unconditional. */
|
|
45
|
-
export const FailOnPolicy = Schema.Literals(["never", "request-changes"]);
|
|
46
|
-
export type FailOnPolicy = typeof FailOnPolicy.Type;
|
|
47
|
-
|
|
48
|
-
export const ReviewCheckConclusion = Schema.Literals(["success", "blocking", "incomplete"]);
|
|
49
|
-
export type ReviewCheckConclusion = typeof ReviewCheckConclusion.Type;
|
|
50
|
-
|
|
51
|
-
/** The host-derived blocking or incomplete conclusion failed the check. */
|
|
52
|
-
export class ReviewGateFailed extends Schema.TaggedError<ReviewGateFailed>()("ReviewGateFailed", {
|
|
53
|
-
conclusion: Schema.Literals(["blocking", "incomplete"]),
|
|
54
|
-
reasons: Schema.Array(Schema.NonEmptyString.check(Schema.isMaxLength(1_000))).check(
|
|
55
|
-
Schema.isMinLength(1),
|
|
56
|
-
),
|
|
57
|
-
}) {
|
|
58
|
-
override get message() {
|
|
59
|
-
return `Review check concluded '${this.conclusion}': ${this.reasons.join("; ")}`;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** A configured max-duration that cannot bound a run; configuration faults fail loudly. */
|
|
64
|
-
export class InvalidMaxDurationInput extends Schema.TaggedError<InvalidMaxDurationInput>()(
|
|
65
|
-
"InvalidMaxDurationInput",
|
|
66
|
-
{
|
|
67
|
-
minutes: Schema.Int,
|
|
68
|
-
},
|
|
69
|
-
) {
|
|
70
|
-
override get message() {
|
|
71
|
-
return `Invalid max-duration-minutes '${this.minutes}': expected a positive number of minutes.`;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Everything the packaged action reads from its environment. */
|
|
76
|
-
export interface ResolvedActionInputs {
|
|
77
|
-
readonly provider: ReviewProvider;
|
|
78
|
-
readonly model: string | undefined;
|
|
79
|
-
readonly effort: EffortPosition | undefined;
|
|
80
|
-
readonly post: boolean;
|
|
81
|
-
readonly applyVerdict: boolean;
|
|
82
|
-
readonly fanOut: boolean;
|
|
83
|
-
readonly guidance: string | undefined;
|
|
84
|
-
readonly guidanceFile: string | undefined;
|
|
85
|
-
readonly ignore: ReadonlyArray<string>;
|
|
86
|
-
readonly maxFindings: number | undefined;
|
|
87
|
-
readonly maxDurationMinutes: number | undefined;
|
|
88
|
-
readonly reviewMode: ReviewMode;
|
|
89
|
-
/** Deprecated compatibility input; conclusions are always conservative. */
|
|
90
|
-
readonly failOn: FailOnPolicy;
|
|
91
|
-
readonly skipUnchanged: boolean;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Read the PR_REVIEW_* input surface (all optional, all defaulted). */
|
|
95
|
-
export const resolveActionInputs = Effect.fn("resolveActionInputs")(function* () {
|
|
96
|
-
const provider = yield* Config.literals(["openai", "anthropic"], "PR_REVIEW_PROVIDER").pipe(
|
|
97
|
-
Config.withDefault<ReviewProvider>(DEFAULT_PROVIDER),
|
|
98
|
-
);
|
|
99
|
-
const model = yield* Config.option(Config.nonEmptyString("PR_REVIEW_MODEL"));
|
|
100
|
-
const effortRaw = yield* Config.option(Config.nonEmptyString("PR_REVIEW_EFFORT"));
|
|
101
|
-
let effort: EffortPosition | undefined;
|
|
102
|
-
if (Option.isSome(effortRaw)) {
|
|
103
|
-
effort = parseEffortPosition(effortRaw.value);
|
|
104
|
-
if (effort === undefined) {
|
|
105
|
-
return yield* InvalidEffortInput.make({ input: effortRaw.value });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const maxDurationMinutes = Option.getOrUndefined(
|
|
109
|
-
yield* Config.option(Config.int("PR_REVIEW_MAX_DURATION_MINUTES")),
|
|
110
|
-
);
|
|
111
|
-
if (maxDurationMinutes !== undefined && maxDurationMinutes <= 0) {
|
|
112
|
-
return yield* InvalidMaxDurationInput.make({ minutes: maxDurationMinutes });
|
|
113
|
-
}
|
|
114
|
-
const post = yield* Config.boolean("PR_REVIEW_POST").pipe(Config.withDefault(true));
|
|
115
|
-
const applyVerdict = yield* Config.boolean("PR_REVIEW_APPLY_VERDICT").pipe(
|
|
116
|
-
Config.withDefault(false),
|
|
117
|
-
);
|
|
118
|
-
const fanOut = yield* Config.boolean("PR_REVIEW_FAN_OUT").pipe(Config.withDefault(false));
|
|
119
|
-
const guidance = yield* Config.option(Config.nonEmptyString("PR_REVIEW_GUIDANCE"));
|
|
120
|
-
const guidanceFile = yield* Config.option(Config.nonEmptyString("PR_REVIEW_GUIDANCE_FILE"));
|
|
121
|
-
const ignoreRaw = yield* Config.string("PR_REVIEW_IGNORE").pipe(Config.withDefault(""));
|
|
122
|
-
const maxFindings = yield* Config.option(Config.int("PR_REVIEW_MAX_FINDINGS"));
|
|
123
|
-
const reviewMode = yield* Config.literals(["incremental", "final"], "PR_REVIEW_MODE").pipe(
|
|
124
|
-
Config.withDefault<ReviewMode>("incremental"),
|
|
125
|
-
);
|
|
126
|
-
const failOn = yield* Config.literals(["never", "request-changes"], "PR_REVIEW_FAIL_ON").pipe(
|
|
127
|
-
Config.withDefault<FailOnPolicy>("never"),
|
|
128
|
-
);
|
|
129
|
-
const skipUnchanged = yield* Config.boolean("PR_REVIEW_SKIP_UNCHANGED").pipe(
|
|
130
|
-
Config.withDefault(true),
|
|
131
|
-
);
|
|
132
|
-
return {
|
|
133
|
-
provider,
|
|
134
|
-
model: Option.getOrUndefined(model),
|
|
135
|
-
effort,
|
|
136
|
-
post,
|
|
137
|
-
applyVerdict,
|
|
138
|
-
fanOut,
|
|
139
|
-
guidance: Option.getOrUndefined(guidance),
|
|
140
|
-
guidanceFile: Option.getOrUndefined(guidanceFile),
|
|
141
|
-
ignore: ignoreRaw
|
|
142
|
-
.split(",")
|
|
143
|
-
.map((pattern) => pattern.trim())
|
|
144
|
-
.filter((pattern) => pattern.length > 0),
|
|
145
|
-
maxFindings: Option.getOrUndefined(maxFindings),
|
|
146
|
-
maxDurationMinutes,
|
|
147
|
-
reviewMode,
|
|
148
|
-
failOn,
|
|
149
|
-
skipUnchanged,
|
|
150
|
-
} satisfies ResolvedActionInputs;
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
/** A guidance file larger than this is refused, never silently truncated. */
|
|
154
|
-
export const MAX_GUIDANCE_FILE_CHARS = 20_000;
|
|
155
|
-
|
|
156
|
-
/** A configured guidance file could not be used; configuration faults fail loudly. */
|
|
157
|
-
export class GuidanceFileUnreadable extends Schema.TaggedError<GuidanceFileUnreadable>()(
|
|
158
|
-
"GuidanceFileUnreadable",
|
|
159
|
-
{
|
|
160
|
-
path: Schema.String,
|
|
161
|
-
reason: Schema.String,
|
|
162
|
-
},
|
|
163
|
-
) {
|
|
164
|
-
override get message() {
|
|
165
|
-
return `Cannot use guidance file '${this.path}': ${this.reason}`;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Resolve the effective review guidance: the committed guidance file (a
|
|
171
|
-
* repository-owned review profile) first, with any inline guidance appended.
|
|
172
|
-
* A configured-but-unreadable file fails typed — a review silently running
|
|
173
|
-
* without its profile would be worse than a red job.
|
|
174
|
-
*/
|
|
175
|
-
export const resolveGuidance = Effect.fn("resolveGuidance")(function* (inputs: {
|
|
176
|
-
readonly guidance: string | undefined;
|
|
177
|
-
readonly guidanceFile: string | undefined;
|
|
178
|
-
}) {
|
|
179
|
-
const filePath = inputs.guidanceFile;
|
|
180
|
-
if (filePath === undefined) return inputs.guidance;
|
|
181
|
-
// The profile path is operator configuration, but it stays fail-closed
|
|
182
|
-
// like every other path in this package: workspace-relative only, and the
|
|
183
|
-
// size bound is checked before the file is read into memory.
|
|
184
|
-
const relative = yield* normalizeRepoRelativePath(filePath).pipe(
|
|
185
|
-
Effect.mapError((violation) =>
|
|
186
|
-
GuidanceFileUnreadable.make({ path: filePath, reason: violation.reason }),
|
|
187
|
-
),
|
|
188
|
-
);
|
|
189
|
-
const fs = yield* FileSystem.FileSystem;
|
|
190
|
-
const unreadable = (error: { readonly _tag: string; readonly message: string }) =>
|
|
191
|
-
GuidanceFileUnreadable.make({
|
|
192
|
-
path: relative,
|
|
193
|
-
reason: `${error._tag}: ${error.message}`.slice(0, 2_048),
|
|
194
|
-
});
|
|
195
|
-
const stat = yield* fs.stat(relative).pipe(Effect.mapError(unreadable));
|
|
196
|
-
const oversized = GuidanceFileUnreadable.make({
|
|
197
|
-
path: relative,
|
|
198
|
-
reason: `File is larger than the ${MAX_GUIDANCE_FILE_CHARS}-character guidance bound.`,
|
|
199
|
-
});
|
|
200
|
-
if (stat.size > BigInt(MAX_GUIDANCE_FILE_CHARS) * 4n) {
|
|
201
|
-
return yield* oversized;
|
|
202
|
-
}
|
|
203
|
-
const content = yield* fs.readFileString(relative).pipe(Effect.mapError(unreadable));
|
|
204
|
-
if (content.length > MAX_GUIDANCE_FILE_CHARS) {
|
|
205
|
-
return yield* oversized;
|
|
206
|
-
}
|
|
207
|
-
const combined = [content.trim(), inputs.guidance ?? ""]
|
|
208
|
-
.filter((part) => part.length > 0)
|
|
209
|
-
.join("\n");
|
|
210
|
-
return combined.length > 0 ? combined : undefined;
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
/** One step-output line; values must be single-line by construction. */
|
|
214
|
-
const outputLine = (name: string, value: string): string =>
|
|
215
|
-
`${name}=${value.replaceAll("\n", " ").slice(0, 1_000)}\n`;
|
|
216
|
-
|
|
217
|
-
/** Append step outputs to GITHUB_OUTPUT when present (no-op locally). */
|
|
218
|
-
export const writeActionOutputs = Effect.fn("writeActionOutputs")(function* (
|
|
219
|
-
entries: ReadonlyArray<readonly [name: string, value: string]>,
|
|
220
|
-
) {
|
|
221
|
-
const outputPath = yield* Config.string("GITHUB_OUTPUT").pipe(Config.withDefault(""));
|
|
222
|
-
if (outputPath === "") return;
|
|
223
|
-
const fs = yield* FileSystem.FileSystem;
|
|
224
|
-
yield* fs.writeFileString(
|
|
225
|
-
outputPath,
|
|
226
|
-
entries.map(([name, value]) => outputLine(name, value)).join(""),
|
|
227
|
-
{
|
|
228
|
-
flag: "a",
|
|
229
|
-
},
|
|
230
|
-
);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
/** Append markdown to the GITHUB_STEP_SUMMARY report when present (no-op locally). */
|
|
234
|
-
export const writeStepSummary = Effect.fn("writeStepSummary")(function* (
|
|
235
|
-
lines: ReadonlyArray<string>,
|
|
236
|
-
) {
|
|
237
|
-
const summaryPath = yield* Config.string("GITHUB_STEP_SUMMARY").pipe(Config.withDefault(""));
|
|
238
|
-
if (summaryPath === "") return;
|
|
239
|
-
const fs = yield* FileSystem.FileSystem;
|
|
240
|
-
yield* fs.writeFileString(summaryPath, `${lines.join("\n")}\n`, { flag: "a" });
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
const outcomeOutputs = (
|
|
244
|
-
outcome: ReviewRunOutcome,
|
|
245
|
-
conclusion: ReviewCheckConclusion,
|
|
246
|
-
): ReadonlyArray<readonly [string, string]> => [
|
|
247
|
-
["skipped", "false"],
|
|
248
|
-
["conclusion", conclusion],
|
|
249
|
-
["verdict", outcome.review.verdict],
|
|
250
|
-
["coverage", outcome.coverage.status],
|
|
251
|
-
["review-mode", outcome.reviewMode ?? "full"],
|
|
252
|
-
["review-reason", outcome.reviewReason ?? "direct full review"],
|
|
253
|
-
["inline-comments", String(outcome.plan.comments.length)],
|
|
254
|
-
["demoted-findings", String(outcome.plan.demoted.length)],
|
|
255
|
-
["concerns", String(outcome.review.concerns?.length ?? 0)],
|
|
256
|
-
...(outcome.usage === undefined
|
|
257
|
-
? []
|
|
258
|
-
: ([
|
|
259
|
-
["input-tokens", String(outcome.usage.inputTokens)],
|
|
260
|
-
["output-tokens", String(outcome.usage.outputTokens)],
|
|
261
|
-
] as const)),
|
|
262
|
-
["review-url", outcome.published?.url ?? ""],
|
|
263
|
-
];
|
|
264
|
-
|
|
265
|
-
const outcomeSummary = (
|
|
266
|
-
outcome: ReviewRunOutcome,
|
|
267
|
-
modelLabel: string | undefined,
|
|
268
|
-
conclusion: ReviewCheckConclusion,
|
|
269
|
-
): ReadonlyArray<string> => [
|
|
270
|
-
"### Pull-request review",
|
|
271
|
-
`- Check conclusion: **${conclusion}**`,
|
|
272
|
-
`- Verdict: **${outcome.review.verdict}**`,
|
|
273
|
-
`- Coverage: **${outcome.coverage.status}** · scope: ${outcome.reviewMode ?? "full"}`,
|
|
274
|
-
`- Inline comments: ${outcome.plan.comments.length} · demoted findings: ${outcome.plan.demoted.length} · concerns: ${outcome.review.concerns?.length ?? 0}`,
|
|
275
|
-
...(modelLabel === undefined ? [] : [`- Model: \`${modelLabel}\``]),
|
|
276
|
-
...(outcome.usage === undefined
|
|
277
|
-
? []
|
|
278
|
-
: [
|
|
279
|
-
`- Tokens: ${outcome.usage.inputTokens} in / ${outcome.usage.outputTokens} out${
|
|
280
|
-
outcome.usageScope === "coordinator" ? " (coordinator)" : ""
|
|
281
|
-
}`,
|
|
282
|
-
]),
|
|
283
|
-
...(outcome.published === undefined
|
|
284
|
-
? ["- Dry run: nothing posted"]
|
|
285
|
-
: [`- Posted: ${outcome.published.url}`]),
|
|
286
|
-
];
|
|
287
|
-
|
|
288
|
-
/** The result of one action invocation: a typed skip or a settled review. */
|
|
289
|
-
export type ReviewActionResult =
|
|
290
|
-
| { readonly _tag: "Skipped"; readonly reason: string }
|
|
291
|
-
| { readonly _tag: "Completed"; readonly outcome: ReviewRunOutcome };
|
|
292
|
-
|
|
293
|
-
const skip = (reason: string) =>
|
|
294
|
-
Effect.gen(function* () {
|
|
295
|
-
yield* Console.log(`Skipping review: ${reason}`);
|
|
296
|
-
yield* writeActionOutputs([
|
|
297
|
-
["skipped", "true"],
|
|
298
|
-
["skip-reason", reason],
|
|
299
|
-
]);
|
|
300
|
-
yield* writeStepSummary(["### Pull-request review skipped", `- Reason: ${reason}`]);
|
|
301
|
-
return { _tag: "Skipped", reason } satisfies ReviewActionResult;
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
/** The Actions run URL for the review footer, or undefined outside Actions. */
|
|
305
|
-
const resolveRunUrl = Effect.fn("resolveRunUrl")(function* () {
|
|
306
|
-
const runId = yield* Config.string("GITHUB_RUN_ID").pipe(Config.withDefault(""));
|
|
307
|
-
const repository = yield* Config.string("GITHUB_REPOSITORY").pipe(Config.withDefault(""));
|
|
308
|
-
if (runId === "" || repository === "") return undefined;
|
|
309
|
-
const server = yield* Config.string("GITHUB_SERVER_URL").pipe(
|
|
310
|
-
Config.withDefault("https://github.com"),
|
|
311
|
-
);
|
|
312
|
-
return `${server}/${repository}/actions/runs/${runId}`;
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
/** The reviewer surface the action harness drives. `PrReview.make` and
|
|
316
|
-
* `PrReview.makeFanOut` provide the state-selection effects; the legacy
|
|
317
|
-
* fingerprint field remains for source compatibility with custom harnesses. */
|
|
318
|
-
export interface HarnessedReviewer<E, R, FingerprintE, FingerprintR> {
|
|
319
|
-
readonly run: (runOptions?: RunReviewOptions) => Effect.Effect<ReviewRunOutcome, E, R>;
|
|
320
|
-
readonly fingerprint?: Effect.Effect<string, FingerprintE, FingerprintR> | undefined;
|
|
321
|
-
readonly profileFingerprint?: Effect.Effect<string, FingerprintE, FingerprintR> | undefined;
|
|
322
|
-
readonly snapshot?:
|
|
323
|
-
| Effect.Effect<
|
|
324
|
-
{
|
|
325
|
-
readonly metadata: import("./internal/source.ts").PullRequestMetadata;
|
|
326
|
-
readonly files: ReadonlyArray<import("./internal/diff.ts").ChangedFile>;
|
|
327
|
-
},
|
|
328
|
-
FingerprintE,
|
|
329
|
-
FingerprintR
|
|
330
|
-
>
|
|
331
|
-
| undefined;
|
|
332
|
-
readonly filterFiles?:
|
|
333
|
-
| ((
|
|
334
|
-
files: ReadonlyArray<import("./internal/diff.ts").ChangedFile>,
|
|
335
|
-
) => ReadonlyArray<import("./internal/diff.ts").ChangedFile>)
|
|
336
|
-
| undefined;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
const blockingReasons = (input: {
|
|
340
|
-
readonly findings: ReadonlyArray<{ readonly severity: string; readonly title: string }>;
|
|
341
|
-
readonly concerns: ReadonlyArray<{ readonly severity: string; readonly title: string }>;
|
|
342
|
-
}): ReadonlyArray<string> => [
|
|
343
|
-
...input.findings
|
|
344
|
-
.filter((finding) => finding.severity === "blocking")
|
|
345
|
-
.map((finding) => `blocking finding: ${finding.title}`),
|
|
346
|
-
...input.concerns
|
|
347
|
-
.filter((concern) => concern.severity === "blocking")
|
|
348
|
-
.map((concern) => `blocking concern: ${concern.title}`),
|
|
349
|
-
];
|
|
350
|
-
|
|
351
|
-
/** Host-derived check conclusion; model verdict prose cannot weaken it. */
|
|
352
|
-
export const concludeReviewOutcome = (
|
|
353
|
-
outcome: ReviewRunOutcome,
|
|
354
|
-
): {
|
|
355
|
-
readonly conclusion: ReviewCheckConclusion;
|
|
356
|
-
readonly reasons: ReadonlyArray<string>;
|
|
357
|
-
} => {
|
|
358
|
-
if (outcome.coverage.status === "incomplete") {
|
|
359
|
-
return { conclusion: "incomplete", reasons: outcome.coverage.reasons };
|
|
360
|
-
}
|
|
361
|
-
const reasons = blockingReasons({
|
|
362
|
-
findings: outcome.activeFindings,
|
|
363
|
-
concerns: outcome.activeConcerns,
|
|
364
|
-
});
|
|
365
|
-
return reasons.length > 0
|
|
366
|
-
? { conclusion: "blocking", reasons }
|
|
367
|
-
: { conclusion: "success", reasons };
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
const concludeReviewState = (state: ReviewState) => {
|
|
371
|
-
const reasons = blockingReasons({
|
|
372
|
-
findings: state.unresolvedFindings,
|
|
373
|
-
concerns: state.unresolvedConcerns,
|
|
374
|
-
});
|
|
375
|
-
return reasons.length > 0
|
|
376
|
-
? ({ conclusion: "blocking", reasons } as const)
|
|
377
|
-
: ({ conclusion: "success", reasons: [] } as const);
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Harness one already-built reviewer inside the Actions environment: resolve
|
|
382
|
-
* the target from the event, provide the GitHub source/publisher/prior
|
|
383
|
-
* reviews, validate/select bounded continuity scope, write step outputs, and apply
|
|
384
|
-
* the host-derived coverage/blocker gate. Draft and non-PR skips are values;
|
|
385
|
-
* an unchanged reviewed head preserves and enforces its stored conclusion. The reviewer's
|
|
386
|
-
* remaining requirements — its model client, any extra tool handlers — stay
|
|
387
|
-
* visible in `R` for the caller.
|
|
388
|
-
*/
|
|
389
|
-
export const runReviewAction = <E, R, FingerprintE = never, FingerprintR = never>(
|
|
390
|
-
reviewer: HarnessedReviewer<E, R, FingerprintE, FingerprintR>,
|
|
391
|
-
options: {
|
|
392
|
-
readonly post?: boolean | undefined;
|
|
393
|
-
readonly failOn?: FailOnPolicy | undefined;
|
|
394
|
-
/** Skip model execution when the current head already has complete stored coverage. */
|
|
395
|
-
readonly skipUnchanged?: boolean | undefined;
|
|
396
|
-
/** Incremental by default; `final` deliberately re-reviews the full PR diff. */
|
|
397
|
-
readonly reviewMode?: ReviewMode | undefined;
|
|
398
|
-
/** Model binding descriptor for the Actions step summary. */
|
|
399
|
-
readonly modelLabel?: string | undefined;
|
|
400
|
-
/** Explicit test/custom-host history override; GitHub owns the default adapter. */
|
|
401
|
-
readonly priorReviews?: PriorReviews["Service"] | undefined;
|
|
402
|
-
} = {},
|
|
403
|
-
) =>
|
|
404
|
-
Effect.gen(function* () {
|
|
405
|
-
const event = yield* readGitHubEvent();
|
|
406
|
-
if (Option.isSome(event)) {
|
|
407
|
-
if (event.value.pull_request === undefined) {
|
|
408
|
-
return yield* skip("the triggering event carries no pull request");
|
|
409
|
-
}
|
|
410
|
-
if (event.value.pull_request.draft === true) {
|
|
411
|
-
return yield* skip("the pull request is a draft");
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
const target = yield* resolveReviewTarget({});
|
|
415
|
-
// One layer build for state selection AND the run, so both observe
|
|
416
|
-
// the same cached pull-request snapshot.
|
|
417
|
-
return yield* Effect.gen(function* () {
|
|
418
|
-
let selection: ReturnType<typeof selectReviewRange> | undefined;
|
|
419
|
-
if (reviewer.profileFingerprint !== undefined) {
|
|
420
|
-
const source = yield* PullRequestSource;
|
|
421
|
-
const [snapshot, profileFingerprint] = yield* Effect.all([
|
|
422
|
-
reviewer.snapshot ?? Effect.all({ metadata: source.metadata, files: source.anchorFiles }),
|
|
423
|
-
reviewer.profileFingerprint,
|
|
424
|
-
]);
|
|
425
|
-
const { metadata, files: fullFiles } = snapshot;
|
|
426
|
-
const history = options.priorReviews ?? (yield* PriorReviews);
|
|
427
|
-
const stateAuthenticator = yield* ReviewStateAuthenticator;
|
|
428
|
-
const recovered =
|
|
429
|
-
stateAuthenticator.status === "unavailable"
|
|
430
|
-
? {
|
|
431
|
-
state: undefined,
|
|
432
|
-
failure:
|
|
433
|
-
stateAuthenticator.unavailableReason ??
|
|
434
|
-
"an authenticated review-state secret is not configured",
|
|
435
|
-
}
|
|
436
|
-
: yield* history.latestState.pipe(
|
|
437
|
-
Effect.match({
|
|
438
|
-
onFailure: (failure) => ({ state: undefined, failure: failure.reason }),
|
|
439
|
-
onSuccess: (state) => ({
|
|
440
|
-
state: Option.getOrUndefined(state),
|
|
441
|
-
failure: undefined,
|
|
442
|
-
}),
|
|
443
|
-
}),
|
|
444
|
-
);
|
|
445
|
-
let comparison: ReviewHeadComparison | undefined;
|
|
446
|
-
let baseComparison: ReviewHeadComparison | undefined;
|
|
447
|
-
if (
|
|
448
|
-
(options.reviewMode ?? "incremental") === "incremental" &&
|
|
449
|
-
recovered.state !== undefined
|
|
450
|
-
) {
|
|
451
|
-
if (recovered.state.reviewedHeadSha === metadata.headSha) {
|
|
452
|
-
comparison = ReviewHeadComparison.make({
|
|
453
|
-
status: "identical",
|
|
454
|
-
baseSha: metadata.headSha,
|
|
455
|
-
headSha: metadata.headSha,
|
|
456
|
-
mergeBaseSha: metadata.headSha,
|
|
457
|
-
files: [],
|
|
458
|
-
truncated: false,
|
|
459
|
-
});
|
|
460
|
-
} else {
|
|
461
|
-
comparison = yield* history
|
|
462
|
-
.compareHeads(recovered.state.reviewedHeadSha, metadata.headSha)
|
|
463
|
-
.pipe(Effect.orElseSucceed(() => undefined));
|
|
464
|
-
if (comparison !== undefined && reviewer.filterFiles !== undefined) {
|
|
465
|
-
comparison = ReviewHeadComparison.make({
|
|
466
|
-
...comparison,
|
|
467
|
-
files: reviewer.filterFiles(comparison.files),
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
if (metadata.baseSha !== undefined && recovered.state.baseSha !== metadata.baseSha) {
|
|
472
|
-
baseComparison = yield* history
|
|
473
|
-
.compareHeads(recovered.state.baseSha, metadata.baseSha)
|
|
474
|
-
.pipe(Effect.orElseSucceed(() => undefined));
|
|
475
|
-
if (baseComparison !== undefined && reviewer.filterFiles !== undefined) {
|
|
476
|
-
baseComparison = ReviewHeadComparison.make({
|
|
477
|
-
...baseComparison,
|
|
478
|
-
files: reviewer.filterFiles(baseComparison.files),
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
selection = {
|
|
484
|
-
...selectReviewRange({
|
|
485
|
-
requestedMode: options.reviewMode ?? "incremental",
|
|
486
|
-
current: metadata,
|
|
487
|
-
fullFiles,
|
|
488
|
-
profileFingerprint,
|
|
489
|
-
priorState: recovered.state,
|
|
490
|
-
comparison,
|
|
491
|
-
baseComparison,
|
|
492
|
-
lookupFailure: recovered.failure,
|
|
493
|
-
}),
|
|
494
|
-
stateAuthenticator,
|
|
495
|
-
};
|
|
496
|
-
if (
|
|
497
|
-
options.skipUnchanged !== false &&
|
|
498
|
-
selection.mode === "incremental" &&
|
|
499
|
-
selection.files.length === 0 &&
|
|
500
|
-
selection.priorState !== undefined
|
|
501
|
-
) {
|
|
502
|
-
const result = concludeReviewState(selection.priorState);
|
|
503
|
-
const reason = "no changed review scope since the last successfully reviewed head";
|
|
504
|
-
yield* Console.log(
|
|
505
|
-
`Skipping review of ${target.repository}#${target.number}: ${reason}.`,
|
|
506
|
-
);
|
|
507
|
-
yield* writeActionOutputs([
|
|
508
|
-
["skipped", "true"],
|
|
509
|
-
["skip-reason", reason],
|
|
510
|
-
["conclusion", result.conclusion],
|
|
511
|
-
["coverage", "complete"],
|
|
512
|
-
["review-mode", "incremental"],
|
|
513
|
-
]);
|
|
514
|
-
yield* writeStepSummary([
|
|
515
|
-
"### Pull-request review skipped",
|
|
516
|
-
`- Reason: ${reason}`,
|
|
517
|
-
`- Preserved check conclusion: **${result.conclusion}**`,
|
|
518
|
-
]);
|
|
519
|
-
if (result.conclusion === "blocking") {
|
|
520
|
-
return yield* ReviewGateFailed.make({
|
|
521
|
-
conclusion: "blocking",
|
|
522
|
-
reasons: result.reasons,
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
return { _tag: "Skipped", reason } satisfies ReviewActionResult;
|
|
526
|
-
}
|
|
527
|
-
} else if (options.skipUnchanged !== false && reviewer.fingerprint !== undefined) {
|
|
528
|
-
// Preserve the pre-state custom harness contract explicitly. The
|
|
529
|
-
// packaged reviewer always takes the authenticated state path above.
|
|
530
|
-
const current = yield* reviewer.fingerprint;
|
|
531
|
-
const history = options.priorReviews ?? (yield* PriorReviews);
|
|
532
|
-
const latest = yield* history.latestFingerprint.pipe(
|
|
533
|
-
Effect.orElseSucceed(() => Option.none<string>()),
|
|
534
|
-
);
|
|
535
|
-
if (Option.isSome(latest) && latest.value === current) {
|
|
536
|
-
const reason = "changeset unchanged since the last review";
|
|
537
|
-
yield* Console.log(
|
|
538
|
-
`Skipping review of ${target.repository}#${target.number}: ${reason}.`,
|
|
539
|
-
);
|
|
540
|
-
yield* writeActionOutputs([
|
|
541
|
-
["skipped", "true"],
|
|
542
|
-
["skip-reason", reason],
|
|
543
|
-
["fingerprint", current],
|
|
544
|
-
["conclusion", "success"],
|
|
545
|
-
["coverage", "complete"],
|
|
546
|
-
]);
|
|
547
|
-
yield* writeStepSummary(["### Pull-request review skipped", `- Reason: ${reason}`]);
|
|
548
|
-
return { _tag: "Skipped", reason } satisfies ReviewActionResult;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
yield* Console.log(
|
|
552
|
-
`Reviewing ${target.repository}#${target.number} (${options.post === false ? "dry run" : "posting"})...`,
|
|
553
|
-
);
|
|
554
|
-
const runUrl = yield* resolveRunUrl();
|
|
555
|
-
const reviewEffect = reviewer.run({ post: options.post ?? true, runUrl });
|
|
556
|
-
const outcome = yield* selection === undefined
|
|
557
|
-
? reviewEffect
|
|
558
|
-
: reviewEffect.pipe(
|
|
559
|
-
Effect.provide(selectedPullRequestSourceLayer(selection)),
|
|
560
|
-
Effect.provideService(ReviewExecutionContext, selection),
|
|
561
|
-
);
|
|
562
|
-
yield* Console.log(
|
|
563
|
-
`Review finished in ${outcome.turns} turn(s): verdict ${outcome.review.verdict}, ` +
|
|
564
|
-
`${outcome.plan.comments.length} inline comment(s), ${outcome.plan.demoted.length} demoted finding(s).`,
|
|
565
|
-
);
|
|
566
|
-
if (outcome.published !== undefined) {
|
|
567
|
-
yield* Console.log(`Posted ${outcome.published.event} review: ${outcome.published.url}`);
|
|
568
|
-
}
|
|
569
|
-
const check = concludeReviewOutcome(outcome);
|
|
570
|
-
yield* writeActionOutputs(outcomeOutputs(outcome, check.conclusion));
|
|
571
|
-
yield* writeStepSummary(outcomeSummary(outcome, options.modelLabel, check.conclusion));
|
|
572
|
-
if (check.conclusion !== "success") {
|
|
573
|
-
return yield* ReviewGateFailed.make({
|
|
574
|
-
conclusion: check.conclusion,
|
|
575
|
-
reasons: check.reasons,
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
return { _tag: "Completed", outcome } satisfies ReviewActionResult;
|
|
579
|
-
}).pipe(Effect.provide(gitHubReviewLayers(target)));
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* The packaged, environment-driven action program: inputs from PR_REVIEW_*,
|
|
584
|
-
* reviewer built from the packaged factory, provider client from the
|
|
585
|
-
* matching credential environment variable.
|
|
586
|
-
*/
|
|
587
|
-
export const reviewActionProgram = Effect.gen(function* () {
|
|
588
|
-
const inputs = yield* resolveActionInputs();
|
|
589
|
-
const stateSecret = Option.map(
|
|
590
|
-
yield* Config.option(Config.nonEmptyString("PR_REVIEW_STATE_SECRET")),
|
|
591
|
-
Redacted.make,
|
|
592
|
-
);
|
|
593
|
-
const stateAuthenticatorLayer = Option.match(stateSecret, {
|
|
594
|
-
onNone: () =>
|
|
595
|
-
unavailableReviewStateAuthenticatorLayer(
|
|
596
|
-
"an authenticated review-state secret is not configured",
|
|
597
|
-
),
|
|
598
|
-
onSome: webCryptoReviewStateAuthenticatorLayer,
|
|
599
|
-
});
|
|
600
|
-
const guidance = yield* resolveGuidance(inputs);
|
|
601
|
-
const modelLabel = describeReviewModel(inputs.provider, inputs.model, inputs.effort);
|
|
602
|
-
const defaults = inputs.fanOut ? fanOutReviewBudgetLimits : reviewBudgetLimits;
|
|
603
|
-
const budget =
|
|
604
|
-
inputs.maxDurationMinutes === undefined
|
|
605
|
-
? defaults
|
|
606
|
-
: UsageBudgetLimits.make({
|
|
607
|
-
...defaults,
|
|
608
|
-
maxDurationMillis: inputs.maxDurationMinutes * 60_000,
|
|
609
|
-
});
|
|
610
|
-
const shared = {
|
|
611
|
-
guidance,
|
|
612
|
-
ignore: inputs.ignore,
|
|
613
|
-
maxFindings: inputs.maxFindings,
|
|
614
|
-
applyVerdict: inputs.applyVerdict,
|
|
615
|
-
modelLabel,
|
|
616
|
-
budget,
|
|
617
|
-
};
|
|
618
|
-
const harness = {
|
|
619
|
-
post: inputs.post,
|
|
620
|
-
failOn: inputs.failOn,
|
|
621
|
-
skipUnchanged: inputs.skipUnchanged,
|
|
622
|
-
reviewMode: inputs.reviewMode,
|
|
623
|
-
modelLabel,
|
|
624
|
-
};
|
|
625
|
-
if (inputs.provider === "anthropic") {
|
|
626
|
-
const model = makeAnthropicReviewModel(inputs.model, inputs.effort);
|
|
627
|
-
const reviewer = inputs.fanOut
|
|
628
|
-
? PrReview.makeFanOut({ ...shared, model })
|
|
629
|
-
: PrReview.make({ ...shared, model });
|
|
630
|
-
return yield* runReviewAction(reviewer, harness).pipe(
|
|
631
|
-
Effect.provide(Layer.merge(stateAuthenticatorLayer, anthropicClientLayer)),
|
|
632
|
-
);
|
|
633
|
-
}
|
|
634
|
-
const model = makeOpenAiReviewModel(inputs.model, inputs.effort);
|
|
635
|
-
const reviewer = inputs.fanOut
|
|
636
|
-
? PrReview.makeFanOut({ ...shared, model })
|
|
637
|
-
: PrReview.make({ ...shared, model });
|
|
638
|
-
return yield* runReviewAction(reviewer, harness).pipe(
|
|
639
|
-
Effect.provide(Layer.merge(stateAuthenticatorLayer, openAiClientLayer)),
|
|
640
|
-
);
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
/** Run the packaged action program on Node; the bundled action entrypoint. */
|
|
644
|
-
export const main = (): void =>
|
|
645
|
-
NodeRuntime.runMain(
|
|
646
|
-
reviewActionProgram.pipe(
|
|
647
|
-
Effect.tapError((error) =>
|
|
648
|
-
Console.error(
|
|
649
|
-
Schema.is(BudgetExceeded)(error)
|
|
650
|
-
? `Budget exceeded: ${error.limit} observed ${error.observedValue}, limit ${error.limitValue}.`
|
|
651
|
-
: String(error),
|
|
652
|
-
),
|
|
653
|
-
),
|
|
654
|
-
Effect.scoped,
|
|
655
|
-
Effect.provide(NodeServices.layer),
|
|
656
|
-
),
|
|
657
|
-
{ disableErrorReporting: true },
|
|
658
|
-
);
|
|
659
|
-
|
|
660
|
-
/** The packaged GitHub Actions surface. */
|
|
661
|
-
export const PrReviewAction = {
|
|
662
|
-
inputs: resolveActionInputs,
|
|
663
|
-
run: runReviewAction,
|
|
664
|
-
program: reviewActionProgram,
|
|
665
|
-
main,
|
|
666
|
-
} as const;
|