@effect-agent/pr-review 0.1.0-beta.22 → 0.1.0-beta.23
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 +63 -46
- package/dist/action.d.mts +11 -11
- package/dist/action.mjs +33 -25
- package/dist/action.mjs.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/{fan-out-n-00ppWr.d.mts → fan-out-BJBTAYuh.d.mts} +260 -305
- package/dist/{github-BgtP7Rdv.mjs → github-BbwYzNrC.mjs} +560 -244
- package/dist/github-BbwYzNrC.mjs.map +1 -0
- package/dist/index.d.mts +71 -115
- package/dist/index.mjs +11 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{providers-BguZK4B_.mjs → providers-NyP-4rS6.mjs} +162 -583
- package/dist/providers-NyP-4rS6.mjs.map +1 -0
- package/dist/testing.d.mts +4 -15
- package/dist/testing.mjs +12 -41
- package/dist/testing.mjs.map +1 -1
- package/package.json +2 -2
- package/src/action.ts +40 -34
- package/src/internal/action-entry.ts +0 -1
- package/src/internal/coverage.ts +147 -548
- package/src/internal/factory.ts +29 -50
- package/src/internal/fan-out-scripted.ts +26 -80
- package/src/internal/fan-out.ts +532 -437
- package/src/internal/profiles.ts +8 -8
- package/src/internal/render.ts +34 -45
- package/src/internal/retirement.ts +3 -1
- package/src/internal/review-state.ts +43 -19
- package/src/internal/review-units.ts +25 -0
- package/src/internal/run.ts +211 -174
- package/src/internal/source.ts +1 -1
- package/dist/github-BgtP7Rdv.mjs.map +0 -1
- package/dist/providers-BguZK4B_.mjs.map +0 -1
package/src/internal/fan-out.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Effect,
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
2
|
import {
|
|
3
3
|
Agent,
|
|
4
4
|
AgentPolicy,
|
|
5
|
-
|
|
6
|
-
SubagentPolicy,
|
|
7
|
-
SubagentRuntime,
|
|
8
|
-
ToolExecutionClass,
|
|
5
|
+
AgentRuntime,
|
|
9
6
|
ToolResultBounds,
|
|
7
|
+
type BudgetAdapterError,
|
|
8
|
+
type BudgetExceeded,
|
|
9
|
+
type RunBudgetHook,
|
|
10
10
|
type RuntimeBinding,
|
|
11
11
|
} from "effect-agent";
|
|
12
|
-
import {
|
|
12
|
+
import { Toolkit } from "effect/unstable/ai";
|
|
13
13
|
|
|
14
14
|
import { anchorViolation } from "./anchors.ts";
|
|
15
|
-
import {
|
|
15
|
+
import { boundedListReason, FailedReviewPass, ReviewAssurance } from "./coverage.ts";
|
|
16
|
+
import { ChangedFileStatus, ChangedPath, type ChangedFile } from "./diff.ts";
|
|
16
17
|
import {
|
|
17
|
-
clampMaxFindings,
|
|
18
18
|
CodeReview,
|
|
19
19
|
fileReviewEvidenceChunks,
|
|
20
20
|
MAX_PATCH_CHARS,
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
REVIEW_TOOL_RESULT_MAX_BYTES,
|
|
23
23
|
ReviewConcern,
|
|
24
24
|
ReviewFinding,
|
|
25
|
-
ReviewMission,
|
|
26
25
|
WalkthroughEntry,
|
|
27
26
|
} from "./review-agent.ts";
|
|
28
27
|
import {
|
|
@@ -31,23 +30,31 @@ import {
|
|
|
31
30
|
MAX_UNIT_FILES,
|
|
32
31
|
findingAnchorInUnitEvidence,
|
|
33
32
|
planReviewUnits,
|
|
33
|
+
rankAndDedupeConcerns,
|
|
34
|
+
rankAndDedupeFindings,
|
|
34
35
|
ReviewEvidenceShardId,
|
|
35
36
|
ReviewPassId,
|
|
36
37
|
ReviewRiskCategory,
|
|
37
38
|
ReviewUnitId,
|
|
38
|
-
|
|
39
|
+
type ReviewDiscoveryPass,
|
|
40
|
+
type ReviewUnit,
|
|
41
|
+
type ReviewUnitPlan,
|
|
39
42
|
} from "./review-units.ts";
|
|
40
|
-
import { PullRequestSource, PullRequestSourceFailure } from "./source.ts";
|
|
41
43
|
|
|
42
44
|
// ---------------------------------------------------------------------------
|
|
43
45
|
// The assured fan-out reviewer is a bounded, deterministic three-stage
|
|
44
|
-
// pipeline
|
|
46
|
+
// pipeline scheduled ENTIRELY by host code:
|
|
45
47
|
//
|
|
46
48
|
// host plan -> independent discovery passes -> independent verification
|
|
47
49
|
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
50
|
+
// `planReviewUnits` is a pure function, so dispatch is plain Effect structured
|
|
51
|
+
// concurrency over its exact work list — there is no coordinator model, no
|
|
52
|
+
// delegation tool, and therefore no prompt-compliance failure mode. A pass
|
|
53
|
+
// that fails (child fault, malformed output) is retried once; a pass that
|
|
54
|
+
// still fails is recorded and its unit's paths are carried forward as
|
|
55
|
+
// retryable unreviewed scope instead of freezing the run's continuity
|
|
56
|
+
// baseline. A finding whose anchor is invalid is discarded and counted —
|
|
57
|
+
// never a reason to reject the whole pass.
|
|
51
58
|
// ---------------------------------------------------------------------------
|
|
52
59
|
|
|
53
60
|
/** One discovery pass returns at most this many anchored candidates. */
|
|
@@ -59,9 +66,16 @@ export const MAX_CHILD_CONCERNS = 3;
|
|
|
59
66
|
/** Every unit receives independent general and specialist discovery passes. */
|
|
60
67
|
export const MAX_UNIT_CANDIDATES = (MAX_CHILD_FINDINGS + MAX_CHILD_CONCERNS) * 2;
|
|
61
68
|
|
|
62
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* General + specialist discovery for every unit, then one verifier per unit.
|
|
71
|
+
* The one-retry budget doubles the worst-case child Run count, but the
|
|
72
|
+
* schedule itself never exceeds this bound.
|
|
73
|
+
*/
|
|
63
74
|
export const MAX_REVIEW_CHILDREN = MAX_REVIEW_UNITS * 3;
|
|
64
75
|
|
|
76
|
+
/** Bounded structured concurrency across units; passes inside a unit are sequential. */
|
|
77
|
+
export const REVIEW_UNIT_CONCURRENCY = 4;
|
|
78
|
+
|
|
65
79
|
/** Structural minimum for a child that exposes no tools. */
|
|
66
80
|
export const MAX_FILE_REVIEW_TOOL_CALLS = 1;
|
|
67
81
|
|
|
@@ -128,8 +142,8 @@ export class CandidateAssessment extends Schema.Class<CandidateAssessment>(
|
|
|
128
142
|
|
|
129
143
|
/**
|
|
130
144
|
* Exact suggestion settlement shape: a carried suggestion must be settled and
|
|
131
|
-
* nothing else may be.
|
|
132
|
-
* and
|
|
145
|
+
* nothing else may be. A verification report that violates it is treated as a
|
|
146
|
+
* misbehaving pass and retried within the pass budget.
|
|
133
147
|
*/
|
|
134
148
|
export const assessmentSettlesSuggestionExactly = (
|
|
135
149
|
assessment: CandidateAssessment,
|
|
@@ -181,21 +195,6 @@ const EvidenceShardIds = Schema.Array(ReviewEvidenceShardId)
|
|
|
181
195
|
.check(Schema.isMinLength(1))
|
|
182
196
|
.check(Schema.isMaxLength(MAX_UNIT_EVIDENCE_SHARDS));
|
|
183
197
|
|
|
184
|
-
/** Strict-object coordinator request for either discovery or verification. */
|
|
185
|
-
export class FileReviewRequest extends Schema.Class<FileReviewRequest>(
|
|
186
|
-
"@effect-agent/pr-review/FileReviewRequest",
|
|
187
|
-
)({
|
|
188
|
-
phase: ReviewWorkPhase,
|
|
189
|
-
workId: ReviewPassId,
|
|
190
|
-
unitId: ReviewUnitId,
|
|
191
|
-
paths: UnitPaths,
|
|
192
|
-
evidenceShardIds: EvidenceShardIds,
|
|
193
|
-
perspective: ReviewWorkPerspective,
|
|
194
|
-
riskCategories: RiskCategories,
|
|
195
|
-
/** Empty for discovery; the exact discovered set for unit verification. */
|
|
196
|
-
candidates: Candidates,
|
|
197
|
-
}) {}
|
|
198
|
-
|
|
199
198
|
/** One complete host-selected evidence shard supplied to a review child. */
|
|
200
199
|
export class FileReviewEvidence extends Schema.Class<FileReviewEvidence>(
|
|
201
200
|
"@effect-agent/pr-review/FileReviewEvidence",
|
|
@@ -220,6 +219,7 @@ export class FileReviewBrief extends Schema.Class<FileReviewBrief>(
|
|
|
220
219
|
evidenceShardIds: EvidenceShardIds,
|
|
221
220
|
perspective: ReviewWorkPerspective,
|
|
222
221
|
riskCategories: RiskCategories,
|
|
222
|
+
/** Empty for discovery; the exact discovered set for unit verification. */
|
|
223
223
|
candidates: Candidates,
|
|
224
224
|
evidence: Schema.Array(FileReviewEvidence)
|
|
225
225
|
.check(Schema.isMinLength(1))
|
|
@@ -239,36 +239,20 @@ export class FileReviewReport extends Schema.Class<FileReviewReport>(
|
|
|
239
239
|
assessments: Schema.Array(CandidateAssessment).check(Schema.isMaxLength(MAX_UNIT_CANDIDATES)),
|
|
240
240
|
}) {}
|
|
241
241
|
|
|
242
|
-
/**
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
fileSummaries: Schema.Array(WalkthroughEntry).check(Schema.isMaxLength(MAX_UNIT_FILES)),
|
|
251
|
-
assessments: Schema.Array(CandidateAssessment).check(Schema.isMaxLength(MAX_UNIT_CANDIDATES)),
|
|
252
|
-
}) {}
|
|
253
|
-
|
|
254
|
-
export class FileReviewUnitFailed extends Schema.TaggedError<FileReviewUnitFailed>()(
|
|
255
|
-
"FileReviewUnitFailed",
|
|
256
|
-
{
|
|
257
|
-
childErrorTag: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
|
|
258
|
-
message: Schema.String.check(Schema.isMaxLength(400)),
|
|
259
|
-
},
|
|
260
|
-
) {}
|
|
261
|
-
|
|
262
|
-
export class FileReviewWorkRejected extends Schema.TaggedError<FileReviewWorkRejected>()(
|
|
263
|
-
"FileReviewWorkRejected",
|
|
242
|
+
/**
|
|
243
|
+
* A structurally valid child report that does not answer the scheduled pass:
|
|
244
|
+
* wrong identity, phase-inapplicable fields, or an inexact assessment set.
|
|
245
|
+
* Retried once like any other pass fault, because it is model misbehavior,
|
|
246
|
+
* not evidence about the code under review.
|
|
247
|
+
*/
|
|
248
|
+
export class ReviewPassMisbehaved extends Schema.TaggedError<ReviewPassMisbehaved>()(
|
|
249
|
+
"ReviewPassMisbehaved",
|
|
264
250
|
{
|
|
265
251
|
workId: ReviewPassId,
|
|
266
252
|
reason: Schema.NonEmptyString.check(Schema.isMaxLength(600)),
|
|
267
253
|
},
|
|
268
254
|
) {}
|
|
269
255
|
|
|
270
|
-
export const FileReviewFailure = Schema.Union([FileReviewUnitFailed, FileReviewWorkRejected]);
|
|
271
|
-
|
|
272
256
|
export interface FanOutInstructionOptions {
|
|
273
257
|
readonly guidance?: string | ReadonlyArray<string> | undefined;
|
|
274
258
|
}
|
|
@@ -327,9 +311,6 @@ export const fileReviewerInstructions = makeFileReviewerInstructions();
|
|
|
327
311
|
|
|
328
312
|
export const FileReviewToolkit = Toolkit.empty;
|
|
329
313
|
|
|
330
|
-
/** Compatibility export: the evidence-only child has no handler requirements. */
|
|
331
|
-
export const FileReviewToolkitLayer = Layer.empty;
|
|
332
|
-
|
|
333
314
|
export const defaultFileReviewerPolicy = AgentPolicy.make({
|
|
334
315
|
maxTurns: 6,
|
|
335
316
|
maxToolCalls: MAX_FILE_REVIEW_TOOL_CALLS,
|
|
@@ -344,121 +325,74 @@ export const defaultFileReviewerPolicy = AgentPolicy.make({
|
|
|
344
325
|
onExhaustion: "fail",
|
|
345
326
|
});
|
|
346
327
|
|
|
347
|
-
export const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
readonly _tag: string;
|
|
358
|
-
readonly message?: string;
|
|
359
|
-
}): FileReviewUnitFailed =>
|
|
360
|
-
FileReviewUnitFailed.make({
|
|
361
|
-
childErrorTag: failure._tag,
|
|
362
|
-
message: (failure.message ?? "").slice(0, 400),
|
|
328
|
+
export const makeFileReviewerDefinition = (options: FanOutInstructionOptions = {}) =>
|
|
329
|
+
Agent.define("pr-review-worker", {
|
|
330
|
+
input: FileReviewBrief,
|
|
331
|
+
output: FileReviewReport,
|
|
332
|
+
instructions: makeFileReviewerInstructions(options),
|
|
333
|
+
toolkit: FileReviewToolkit,
|
|
334
|
+
policy: defaultFileReviewerPolicy,
|
|
335
|
+
description:
|
|
336
|
+
"Perform one bounded discovery or independent candidate-verification pass over host-supplied pull-request evidence.",
|
|
337
|
+
metadata: { deploymentClass: "E", surface: "read-only", stage: "discovery-verification" },
|
|
363
338
|
});
|
|
364
339
|
|
|
365
|
-
const
|
|
366
|
-
left.length === right.length && left.every((value, index) => value === right[index]);
|
|
340
|
+
export const FileReviewer = makeFileReviewerDefinition();
|
|
367
341
|
|
|
368
|
-
|
|
369
|
-
|
|
342
|
+
/** The exact child binding shape the host pipeline schedules. */
|
|
343
|
+
export type FileReviewerBinding<Provider, ModelProvides, ModelRequires> = RuntimeBinding<
|
|
344
|
+
typeof FileReviewBrief,
|
|
345
|
+
typeof FileReviewReport,
|
|
346
|
+
ReturnType<typeof makeFileReviewerInstructions>,
|
|
347
|
+
Toolkit.Tools<typeof FileReviewToolkit>,
|
|
348
|
+
Provider,
|
|
349
|
+
ModelProvides,
|
|
350
|
+
ModelRequires
|
|
351
|
+
>;
|
|
370
352
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const source = yield* PullRequestSource;
|
|
375
|
-
const mapSourceFailure = (failure: PullRequestSourceFailure) =>
|
|
376
|
-
rejectWork(
|
|
377
|
-
request.workId,
|
|
378
|
-
`pull-request source ${failure.operation} failed: ${failure.reason}`.slice(0, 600),
|
|
379
|
-
);
|
|
380
|
-
const files = yield* source.changedFiles.pipe(Effect.mapError(mapSourceFailure));
|
|
381
|
-
const metadata = yield* source.metadata.pipe(Effect.mapError(mapSourceFailure));
|
|
382
|
-
const plan = planReviewUnits(files, { totalChangedFiles: metadata.totalChangedFiles });
|
|
383
|
-
const unit = plan.units.find((candidate) => candidate.unitId === request.unitId);
|
|
384
|
-
if (
|
|
385
|
-
unit === undefined ||
|
|
386
|
-
!sameStrings(request.paths, unit.paths) ||
|
|
387
|
-
!sameStrings(
|
|
388
|
-
request.evidenceShardIds,
|
|
389
|
-
unit.evidenceShards.map((shard) => shard.shardId),
|
|
390
|
-
)
|
|
391
|
-
) {
|
|
392
|
-
return yield* rejectWork(request.workId, "request does not match a host-planned unit");
|
|
393
|
-
}
|
|
353
|
+
// ---------------------------------------------------------------------------
|
|
354
|
+
// Host pipeline.
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
394
356
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
) {
|
|
415
|
-
return yield* rejectWork(
|
|
416
|
-
request.workId,
|
|
417
|
-
"verification request does not match the host-planned unit",
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
const candidateIds = new Set<string>();
|
|
421
|
-
const candidateSubjects = new Set<string>();
|
|
422
|
-
const allowed = new Set(unit.paths);
|
|
423
|
-
for (const candidate of request.candidates) {
|
|
424
|
-
const subjectKey = reviewCandidateSubjectKey(candidate);
|
|
425
|
-
if (
|
|
426
|
-
candidateIds.has(candidate.candidateId) ||
|
|
427
|
-
candidateSubjects.has(subjectKey) ||
|
|
428
|
-
candidate.unitId !== unit.unitId ||
|
|
429
|
-
candidate.evidencePaths.some((path) => !allowed.has(path)) ||
|
|
430
|
-
(candidate._tag === "FindingCandidate" && !allowed.has(candidate.finding.path))
|
|
431
|
-
) {
|
|
432
|
-
return yield* rejectWork(
|
|
433
|
-
request.workId,
|
|
434
|
-
"verification candidates are duplicated or outside the planned unit",
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
candidateIds.add(candidate.candidateId);
|
|
438
|
-
candidateSubjects.add(subjectKey);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
357
|
+
/** Everything one settled fan-out pipeline run produced, before publication. */
|
|
358
|
+
export interface FanOutPipelineOutcome {
|
|
359
|
+
readonly review: CodeReview;
|
|
360
|
+
readonly assurance: ReviewAssurance;
|
|
361
|
+
readonly plan: ReviewUnitPlan;
|
|
362
|
+
/** Paths of units with an unsettled pass — retryable scope for the next run. */
|
|
363
|
+
readonly unreviewedPaths: ReadonlyArray<string>;
|
|
364
|
+
/** Total settled child turns across every scheduled pass. */
|
|
365
|
+
readonly turns: number;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface FanOutPipelineInput {
|
|
369
|
+
readonly files: ReadonlyArray<ChangedFile>;
|
|
370
|
+
readonly anchorFiles: ReadonlyArray<ChangedFile>;
|
|
371
|
+
readonly totalChangedFiles: number;
|
|
372
|
+
readonly maxFindings?: number | undefined;
|
|
373
|
+
/** Shared run budget observed by every child pass. */
|
|
374
|
+
readonly budget?: RunBudgetHook<BudgetExceeded | BudgetAdapterError> | undefined;
|
|
375
|
+
}
|
|
441
376
|
|
|
377
|
+
const candidateOrdinal = (index: number): string => String(index + 1).padStart(3, "0");
|
|
378
|
+
|
|
379
|
+
/** Rebuild one unit's complete evidence from the same snapshot the plan used. */
|
|
380
|
+
const unitEvidence = (
|
|
381
|
+
unit: ReviewUnit,
|
|
382
|
+
files: ReadonlyArray<ChangedFile>,
|
|
383
|
+
): Effect.Effect<ReadonlyArray<FileReviewEvidence>> =>
|
|
384
|
+
Effect.gen(function* () {
|
|
442
385
|
const byPath = new Map(files.map((file) => [file.path, file] as const));
|
|
443
386
|
const evidence: Array<FileReviewEvidence> = [];
|
|
444
387
|
for (const shard of unit.evidenceShards) {
|
|
445
388
|
const file = byPath.get(shard.path);
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const chunk = chunks[shard.ordinal - 1];
|
|
454
|
-
if (
|
|
455
|
-
chunk === undefined ||
|
|
456
|
-
chunks.length !== shard.total ||
|
|
457
|
-
chunk.annotatedPatch.length !== shard.evidenceChars
|
|
458
|
-
) {
|
|
459
|
-
return yield* rejectWork(
|
|
460
|
-
request.workId,
|
|
461
|
-
`planned evidence shard no longer matches source: ${shard.shardId}`,
|
|
389
|
+
const chunk =
|
|
390
|
+
file === undefined ? undefined : fileReviewEvidenceChunks(file)[shard.ordinal - 1];
|
|
391
|
+
if (file === undefined || chunk === undefined) {
|
|
392
|
+
// The plan and this evidence derive from the same immutable snapshot
|
|
393
|
+
// via the same pure function; a mismatch is a host defect, not input.
|
|
394
|
+
return yield* Effect.die(
|
|
395
|
+
new Error(`planned evidence shard has no source: ${shard.shardId} (${shard.path})`),
|
|
462
396
|
);
|
|
463
397
|
}
|
|
464
398
|
evidence.push(
|
|
@@ -473,303 +407,464 @@ const prepareReviewBrief = (request: FileReviewRequest) =>
|
|
|
473
407
|
}),
|
|
474
408
|
);
|
|
475
409
|
}
|
|
476
|
-
return
|
|
410
|
+
return evidence;
|
|
477
411
|
});
|
|
478
412
|
|
|
479
|
-
|
|
413
|
+
interface SettledPass {
|
|
414
|
+
readonly report: FileReviewReport;
|
|
415
|
+
readonly turns: number;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
type PassOutcome =
|
|
419
|
+
| ({ readonly _tag: "settled" } & SettledPass)
|
|
420
|
+
| { readonly _tag: "failed"; readonly errorTag: string };
|
|
480
421
|
|
|
481
|
-
const
|
|
422
|
+
const misbehaved = (workId: string, reason: string) =>
|
|
423
|
+
ReviewPassMisbehaved.make({ workId, reason: reason.slice(0, 600) });
|
|
424
|
+
|
|
425
|
+
/** Validate that a verification report assesses exactly the scheduled candidates. */
|
|
426
|
+
const validateVerificationReport = (
|
|
427
|
+
brief: FileReviewBrief,
|
|
482
428
|
report: FileReviewReport,
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
if (context.budgetExhausted) {
|
|
487
|
-
return Effect.fail(
|
|
488
|
-
rejectWork(report.workId, "review work exhausted its budget before exact settlement"),
|
|
489
|
-
);
|
|
429
|
+
): ReviewPassMisbehaved | undefined => {
|
|
430
|
+
if (report.findings.length > 0 || report.concerns.length > 0 || report.fileSummaries.length > 0) {
|
|
431
|
+
return misbehaved(brief.workId, "verification output contained discovery-only fields");
|
|
490
432
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
433
|
+
const expectedById = new Map(
|
|
434
|
+
brief.candidates.map((candidate) => [candidate.candidateId, candidate] as const),
|
|
435
|
+
);
|
|
436
|
+
const assessedIds = new Set<string>();
|
|
437
|
+
for (const assessment of report.assessments) {
|
|
438
|
+
const candidate = expectedById.get(assessment.candidateId);
|
|
439
|
+
if (candidate === undefined || assessedIds.has(assessment.candidateId)) {
|
|
440
|
+
return misbehaved(brief.workId, "verification output did not assess the exact candidate set");
|
|
441
|
+
}
|
|
442
|
+
if (!assessmentSettlesSuggestionExactly(assessment, candidate)) {
|
|
443
|
+
return misbehaved(
|
|
444
|
+
brief.workId,
|
|
445
|
+
"verification output did not settle suggestion publication exactly",
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
assessedIds.add(assessment.candidateId);
|
|
499
449
|
}
|
|
500
|
-
if (
|
|
450
|
+
if (assessedIds.size !== expectedById.size) {
|
|
451
|
+
return misbehaved(brief.workId, "verification output did not assess the exact candidate set");
|
|
452
|
+
}
|
|
453
|
+
return undefined;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Run one scheduled pass: execute the child, decode its report, and enforce
|
|
458
|
+
* the pass contract. Any typed fault — child failure, malformed or misdirected
|
|
459
|
+
* output — is retried once; budget exhaustion is terminal because a retry
|
|
460
|
+
* would fail the same way. The settled outcome is a value either way, so one
|
|
461
|
+
* flaky pass can never fail the whole pipeline.
|
|
462
|
+
*/
|
|
463
|
+
const runReviewPass = <Provider, ModelProvides, ModelRequires>(
|
|
464
|
+
binding: FileReviewerBinding<Provider, ModelProvides, ModelRequires>,
|
|
465
|
+
brief: FileReviewBrief,
|
|
466
|
+
budget: RunBudgetHook<BudgetExceeded | BudgetAdapterError> | undefined,
|
|
467
|
+
) =>
|
|
468
|
+
Effect.gen(function* () {
|
|
469
|
+
const result = yield* AgentRuntime.run(binding, brief, {
|
|
470
|
+
...(budget === undefined ? {} : { budget }),
|
|
471
|
+
estimateCostMicrousd: () => Effect.succeed(500),
|
|
472
|
+
});
|
|
473
|
+
const report = yield* Schema.decodeUnknownEffect(FileReviewReport)(result.output).pipe(
|
|
474
|
+
Effect.mapError((error) =>
|
|
475
|
+
misbehaved(brief.workId, `child report failed to decode: ${error.message}`),
|
|
476
|
+
),
|
|
477
|
+
);
|
|
501
478
|
if (
|
|
502
|
-
report.
|
|
503
|
-
report.
|
|
504
|
-
report.
|
|
479
|
+
report.phase !== brief.phase ||
|
|
480
|
+
report.workId !== brief.workId ||
|
|
481
|
+
report.unitId !== brief.unitId
|
|
505
482
|
) {
|
|
506
|
-
return
|
|
507
|
-
|
|
483
|
+
return yield* misbehaved(
|
|
484
|
+
brief.workId,
|
|
485
|
+
"child report identity does not match the scheduled pass",
|
|
508
486
|
);
|
|
509
487
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
488
|
+
if (brief.phase === "verification") {
|
|
489
|
+
const violation = validateVerificationReport(brief, report);
|
|
490
|
+
if (violation !== undefined) return yield* violation;
|
|
491
|
+
} else if (report.assessments.length > 0) {
|
|
492
|
+
return yield* misbehaved(
|
|
493
|
+
brief.workId,
|
|
494
|
+
"discovery output contained verification-only assessments",
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
return { report, turns: result.turns } satisfies SettledPass;
|
|
498
|
+
}).pipe(
|
|
499
|
+
Effect.scoped,
|
|
500
|
+
Effect.retry({ times: 1, while: (error) => error._tag !== "BudgetExceeded" }),
|
|
501
|
+
Effect.map((settled): PassOutcome => ({ _tag: "settled", ...settled })),
|
|
502
|
+
Effect.catch((error) =>
|
|
503
|
+
Effect.succeed<PassOutcome>({ _tag: "failed", errorTag: String(error._tag).slice(0, 256) }),
|
|
504
|
+
),
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
interface DiscoveryHarvest {
|
|
508
|
+
readonly candidates: ReadonlyArray<ReviewCandidate>;
|
|
509
|
+
readonly fileSummaries: ReadonlyArray<WalkthroughEntry>;
|
|
510
|
+
readonly discarded: number;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Keep only findings anchored inside the pass's exact assigned evidence and
|
|
515
|
+
* concerns bound to unit paths. Everything else is discarded and counted —
|
|
516
|
+
* an invalid anchor invalidates one claim, never the pass that produced it.
|
|
517
|
+
*/
|
|
518
|
+
const harvestDiscovery = (
|
|
519
|
+
pass: ReviewDiscoveryPass,
|
|
520
|
+
unit: ReviewUnit,
|
|
521
|
+
files: ReadonlyArray<ChangedFile>,
|
|
522
|
+
anchorFiles: ReadonlyArray<ChangedFile>,
|
|
523
|
+
report: FileReviewReport,
|
|
524
|
+
): DiscoveryHarvest => {
|
|
525
|
+
const allowed = new Set(pass.paths);
|
|
526
|
+
let discarded = 0;
|
|
527
|
+
const keptFindings: Array<ReviewFinding> = [];
|
|
528
|
+
for (const finding of report.findings) {
|
|
529
|
+
if (
|
|
530
|
+
!allowed.has(finding.path) ||
|
|
531
|
+
anchorViolation(finding, anchorFiles) !== undefined ||
|
|
532
|
+
!findingAnchorInUnitEvidence(finding, unit, files)
|
|
533
|
+
) {
|
|
534
|
+
discarded += 1;
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
keptFindings.push(finding);
|
|
538
|
+
}
|
|
539
|
+
const keptConcerns: Array<DiscoveredConcern> = [];
|
|
540
|
+
for (const candidate of report.concerns) {
|
|
541
|
+
if (candidate.evidencePaths.some((path) => !allowed.has(path))) {
|
|
542
|
+
discarded += 1;
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
keptConcerns.push(candidate);
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
candidates: [
|
|
549
|
+
...keptFindings.map((finding, index) =>
|
|
550
|
+
FindingCandidate.make({
|
|
551
|
+
candidateId: `${pass.passId}:finding:${candidateOrdinal(index)}`,
|
|
552
|
+
workId: pass.passId,
|
|
553
|
+
unitId: pass.unitId,
|
|
554
|
+
finding,
|
|
555
|
+
evidencePaths: [finding.path],
|
|
556
|
+
}),
|
|
557
|
+
),
|
|
558
|
+
...keptConcerns.map((candidate, index) =>
|
|
559
|
+
ConcernCandidate.make({
|
|
560
|
+
candidateId: `${pass.passId}:concern:${candidateOrdinal(index)}`,
|
|
561
|
+
workId: pass.passId,
|
|
562
|
+
unitId: pass.unitId,
|
|
563
|
+
concern: candidate.concern,
|
|
564
|
+
evidencePaths: candidate.evidencePaths,
|
|
565
|
+
}),
|
|
566
|
+
),
|
|
567
|
+
],
|
|
568
|
+
fileSummaries: report.fileSummaries.filter((entry) => allowed.has(entry.path)),
|
|
569
|
+
discarded,
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
interface UnitReviewOutcome {
|
|
574
|
+
readonly failedPasses: ReadonlyArray<FailedReviewPass>;
|
|
575
|
+
readonly discoveredCandidates: number;
|
|
576
|
+
readonly confirmed: ReadonlyArray<{
|
|
577
|
+
readonly assessment: CandidateAssessment;
|
|
578
|
+
readonly candidate: ReviewCandidate;
|
|
579
|
+
}>;
|
|
580
|
+
readonly rejectedCandidates: number;
|
|
581
|
+
readonly unsettledCandidates: number;
|
|
582
|
+
readonly discardedFindings: number;
|
|
583
|
+
readonly walkthrough: ReadonlyArray<WalkthroughEntry>;
|
|
584
|
+
readonly turns: number;
|
|
585
|
+
readonly completedGeneralPasses: number;
|
|
586
|
+
readonly completedSpecialistPasses: number;
|
|
587
|
+
readonly requiredVerificationPasses: number;
|
|
588
|
+
readonly completedVerificationPasses: number;
|
|
589
|
+
readonly unreviewedPaths: ReadonlyArray<string>;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const reviewUnit = <Provider, ModelProvides, ModelRequires>(
|
|
593
|
+
binding: FileReviewerBinding<Provider, ModelProvides, ModelRequires>,
|
|
594
|
+
unit: ReviewUnit,
|
|
595
|
+
passes: ReadonlyArray<ReviewDiscoveryPass>,
|
|
596
|
+
input: FanOutPipelineInput,
|
|
597
|
+
) =>
|
|
598
|
+
Effect.gen(function* () {
|
|
599
|
+
const evidence = yield* unitEvidence(unit, input.files);
|
|
600
|
+
const failedPasses: Array<FailedReviewPass> = [];
|
|
601
|
+
const candidates: Array<ReviewCandidate> = [];
|
|
602
|
+
const subjects = new Set<string>();
|
|
603
|
+
const walkthrough: Array<WalkthroughEntry> = [];
|
|
604
|
+
let discardedFindings = 0;
|
|
605
|
+
let turns = 0;
|
|
606
|
+
let completedGeneralPasses = 0;
|
|
607
|
+
let completedSpecialistPasses = 0;
|
|
608
|
+
for (const pass of passes) {
|
|
609
|
+
const stage = pass.perspective === "risk-specialist" ? "specialist" : "discovery";
|
|
610
|
+
const brief = FileReviewBrief.make({
|
|
611
|
+
phase: "discovery",
|
|
612
|
+
workId: pass.passId,
|
|
613
|
+
unitId: pass.unitId,
|
|
614
|
+
paths: pass.paths,
|
|
615
|
+
evidenceShardIds: pass.evidenceShardIds,
|
|
616
|
+
perspective: pass.perspective,
|
|
617
|
+
riskCategories: pass.riskCategories,
|
|
618
|
+
candidates: [],
|
|
619
|
+
evidence,
|
|
620
|
+
});
|
|
621
|
+
const outcome = yield* runReviewPass(binding, brief, input.budget);
|
|
622
|
+
if (outcome._tag === "failed") {
|
|
623
|
+
failedPasses.push(
|
|
624
|
+
FailedReviewPass.make({ workId: pass.passId, stage, errorTag: outcome.errorTag }),
|
|
519
625
|
);
|
|
626
|
+
continue;
|
|
520
627
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
628
|
+
turns += outcome.turns;
|
|
629
|
+
if (stage === "specialist") {
|
|
630
|
+
completedSpecialistPasses += 1;
|
|
631
|
+
} else {
|
|
632
|
+
completedGeneralPasses += 1;
|
|
633
|
+
}
|
|
634
|
+
const harvest = harvestDiscovery(pass, unit, input.files, input.anchorFiles, outcome.report);
|
|
635
|
+
discardedFindings += harvest.discarded;
|
|
636
|
+
if (pass.perspective === "general") walkthrough.push(...harvest.fileSummaries);
|
|
637
|
+
for (const candidate of harvest.candidates) {
|
|
638
|
+
const subject = reviewCandidateSubjectKey(candidate);
|
|
639
|
+
if (subjects.has(subject)) continue;
|
|
640
|
+
subjects.add(subject);
|
|
641
|
+
candidates.push(candidate);
|
|
528
642
|
}
|
|
529
|
-
assessedIds.add(assessment.candidateId);
|
|
530
643
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
644
|
+
const confirmed: Array<{
|
|
645
|
+
readonly assessment: CandidateAssessment;
|
|
646
|
+
readonly candidate: ReviewCandidate;
|
|
647
|
+
}> = [];
|
|
648
|
+
let rejectedCandidates = 0;
|
|
649
|
+
let unsettledCandidates = 0;
|
|
650
|
+
let completedVerificationPasses = 0;
|
|
651
|
+
const requiredVerificationPasses = candidates.length > 0 ? 1 : 0;
|
|
652
|
+
if (candidates.length > 0) {
|
|
653
|
+
const workId = `${unit.unitId}-verification`;
|
|
654
|
+
const brief = FileReviewBrief.make({
|
|
655
|
+
phase: "verification",
|
|
656
|
+
workId,
|
|
657
|
+
unitId: unit.unitId,
|
|
658
|
+
paths: unit.paths,
|
|
659
|
+
evidenceShardIds: unit.evidenceShards.map((shard) => shard.shardId),
|
|
660
|
+
perspective: "candidate-verification",
|
|
661
|
+
riskCategories: unit.riskCategories,
|
|
662
|
+
candidates,
|
|
663
|
+
evidence,
|
|
664
|
+
});
|
|
665
|
+
const outcome = yield* runReviewPass(binding, brief, input.budget);
|
|
666
|
+
if (outcome._tag === "failed") {
|
|
667
|
+
unsettledCandidates = candidates.length;
|
|
668
|
+
failedPasses.push(
|
|
669
|
+
FailedReviewPass.make({ workId, stage: "verification", errorTag: outcome.errorTag }),
|
|
670
|
+
);
|
|
671
|
+
} else {
|
|
672
|
+
turns += outcome.turns;
|
|
673
|
+
completedVerificationPasses = 1;
|
|
674
|
+
const byId = new Map(candidates.map((candidate) => [candidate.candidateId, candidate]));
|
|
675
|
+
for (const assessment of outcome.report.assessments) {
|
|
676
|
+
const candidate = byId.get(assessment.candidateId);
|
|
677
|
+
if (candidate === undefined) continue;
|
|
678
|
+
if (assessment.disposition === "confirmed") {
|
|
679
|
+
confirmed.push({ assessment, candidate });
|
|
680
|
+
} else {
|
|
681
|
+
rejectedCandidates += 1;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
535
685
|
}
|
|
536
|
-
return
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
686
|
+
return {
|
|
687
|
+
failedPasses,
|
|
688
|
+
discoveredCandidates: candidates.length,
|
|
689
|
+
confirmed,
|
|
690
|
+
rejectedCandidates,
|
|
691
|
+
unsettledCandidates,
|
|
692
|
+
discardedFindings,
|
|
693
|
+
walkthrough,
|
|
694
|
+
turns,
|
|
695
|
+
completedGeneralPasses,
|
|
696
|
+
completedSpecialistPasses,
|
|
697
|
+
requiredVerificationPasses,
|
|
698
|
+
completedVerificationPasses,
|
|
699
|
+
unreviewedPaths: failedPasses.length > 0 ? unit.paths : [],
|
|
700
|
+
} satisfies UnitReviewOutcome;
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
const countNoun = (count: number, noun: string): string =>
|
|
704
|
+
`${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
705
|
+
|
|
706
|
+
const composeSummary = (plan: ReviewUnitPlan, assurance: ReviewAssurance): string => {
|
|
707
|
+
const requiredDiscovery =
|
|
708
|
+
assurance.requiredGeneralDiscoveryPasses + assurance.requiredSpecialistPasses;
|
|
709
|
+
const completedDiscovery =
|
|
710
|
+
assurance.completedGeneralDiscoveryPasses + assurance.completedSpecialistPasses;
|
|
711
|
+
const parts = [
|
|
712
|
+
`Reviewed ${countNoun(plan.totalFiles, "changed file")} across ${countNoun(plan.units.length, "bounded unit")}: ${completedDiscovery}/${requiredDiscovery} discovery and ${assurance.completedVerificationPasses}/${assurance.requiredVerificationPasses} verification pass(es) settled; ${assurance.confirmedCandidates} of ${countNoun(assurance.discoveredCandidates, "discovered candidate")} confirmed by independent verification.`,
|
|
713
|
+
];
|
|
714
|
+
if (assurance.failedPasses.length > 0) {
|
|
715
|
+
parts.push(
|
|
716
|
+
`${countNoun(assurance.failedPasses.length, "pass")} did not settle; the affected paths are carried forward and retried on the next run. This is a reviewer-side gap, not a code defect.`,
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
if (assurance.discardedInvalidFindings > 0) {
|
|
720
|
+
parts.push(
|
|
721
|
+
`${countNoun(assurance.discardedInvalidFindings, "candidate")} discarded for anchors or paths outside the assigned evidence.`,
|
|
545
722
|
);
|
|
546
723
|
}
|
|
547
|
-
if (
|
|
548
|
-
|
|
549
|
-
|
|
724
|
+
if (plan.undiffablePaths.length > 0) {
|
|
725
|
+
parts.push(
|
|
726
|
+
`${countNoun(plan.undiffablePaths.length, "path")} had no reviewable textual evidence and keep input coverage incomplete; exclude such paths with ignore globs when that is intended.`,
|
|
550
727
|
);
|
|
551
728
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
report.concerns.some((candidate) =>
|
|
556
|
-
candidate.evidencePaths.some((path) => !allowed.has(path)),
|
|
557
|
-
) ||
|
|
558
|
-
report.fileSummaries.some((entry) => !allowed.has(entry.path))
|
|
559
|
-
) {
|
|
560
|
-
return Effect.fail(
|
|
561
|
-
rejectWork(report.workId, "discovery output referenced evidence outside the scheduled unit"),
|
|
729
|
+
if (plan.unassignedPaths.length > 0 || plan.unassignedEvidenceShardCount > 0) {
|
|
730
|
+
parts.push(
|
|
731
|
+
"The changeset exceeded the bounded fan-out capacity; unassigned scope is reported under input coverage.",
|
|
562
732
|
);
|
|
563
733
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
734
|
+
parts.push(
|
|
735
|
+
"No configured pipeline can prove absence of defects; this describes settled work only.",
|
|
736
|
+
);
|
|
737
|
+
return parts.join(" ").slice(0, 4_000);
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Run the complete host-scheduled fan-out pipeline over one selected
|
|
742
|
+
* changeset snapshot: plan, independent discovery, exact verification, and a
|
|
743
|
+
* deterministic host-composed CodeReview from verifier-confirmed candidates
|
|
744
|
+
* only. The verdict is derived from confirmed severities, never model prose.
|
|
745
|
+
*/
|
|
746
|
+
export const runFanOutReview = <Provider, ModelProvides, ModelRequires>(
|
|
747
|
+
binding: FileReviewerBinding<Provider, ModelProvides, ModelRequires>,
|
|
748
|
+
input: FanOutPipelineInput,
|
|
749
|
+
) =>
|
|
750
|
+
Effect.gen(function* () {
|
|
751
|
+
const plan = planReviewUnits(input.files, { totalChangedFiles: input.totalChangedFiles });
|
|
752
|
+
const passesByUnit = new Map<string, Array<ReviewDiscoveryPass>>();
|
|
753
|
+
for (const pass of plan.discoveryPasses) {
|
|
754
|
+
const passes = passesByUnit.get(pass.unitId) ?? [];
|
|
755
|
+
passes.push(pass);
|
|
756
|
+
passesByUnit.set(pass.unitId, passes);
|
|
757
|
+
}
|
|
758
|
+
const outcomes = yield* Effect.forEach(
|
|
759
|
+
plan.units,
|
|
760
|
+
(unit) => reviewUnit(binding, unit, passesByUnit.get(unit.unitId) ?? [], input),
|
|
761
|
+
{ concurrency: REVIEW_UNIT_CONCURRENCY },
|
|
762
|
+
);
|
|
763
|
+
const failedPasses = outcomes.flatMap((outcome) => outcome.failedPasses);
|
|
764
|
+
const unsettledCandidates = outcomes.reduce(
|
|
765
|
+
(total, outcome) => total + outcome.unsettledCandidates,
|
|
766
|
+
0,
|
|
767
|
+
);
|
|
768
|
+
const reasons: Array<string> = [];
|
|
769
|
+
if (failedPasses.length > 0) {
|
|
770
|
+
reasons.push(
|
|
771
|
+
boundedListReason(
|
|
772
|
+
"configured review passes did not settle",
|
|
773
|
+
failedPasses.map((pass) => `${pass.workId} (${pass.errorTag})`),
|
|
774
|
+
),
|
|
570
775
|
);
|
|
571
|
-
const files = yield* source.changedFiles.pipe(Effect.mapError(mapSourceFailure));
|
|
572
|
-
const metadata = yield* source.metadata.pipe(Effect.mapError(mapSourceFailure));
|
|
573
|
-
const anchorFiles = yield* source.anchorFiles.pipe(Effect.mapError(mapSourceFailure));
|
|
574
|
-
const unit = planReviewUnits(files, {
|
|
575
|
-
totalChangedFiles: metadata.totalChangedFiles,
|
|
576
|
-
}).units.find((candidate) => candidate.unitId === request.unitId);
|
|
577
|
-
if (unit === undefined) {
|
|
578
|
-
return yield* rejectWork(request.workId, "scheduled review unit is no longer available");
|
|
579
776
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
request.workId,
|
|
585
|
-
`discovery finding has no valid anchor in its assigned evidence: ${violation ?? finding.path}`,
|
|
586
|
-
);
|
|
587
|
-
}
|
|
777
|
+
if (unsettledCandidates > 0) {
|
|
778
|
+
reasons.push(
|
|
779
|
+
`${unsettledCandidates} discovered candidate(s) did not receive exact verification`,
|
|
780
|
+
);
|
|
588
781
|
}
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
782
|
+
const requiredSpecialistPasses = plan.discoveryPasses.filter(
|
|
783
|
+
(pass) => pass.perspective === "risk-specialist",
|
|
784
|
+
).length;
|
|
785
|
+
const confirmed = outcomes.flatMap((outcome) => outcome.confirmed);
|
|
786
|
+
const assurance = ReviewAssurance.make({
|
|
787
|
+
status: reasons.length === 0 ? "settled" : "incomplete",
|
|
788
|
+
requiredGeneralDiscoveryPasses: plan.discoveryPasses.length - requiredSpecialistPasses,
|
|
789
|
+
completedGeneralDiscoveryPasses: outcomes.reduce(
|
|
790
|
+
(total, outcome) => total + outcome.completedGeneralPasses,
|
|
791
|
+
0,
|
|
792
|
+
),
|
|
793
|
+
requiredSpecialistPasses,
|
|
794
|
+
completedSpecialistPasses: outcomes.reduce(
|
|
795
|
+
(total, outcome) => total + outcome.completedSpecialistPasses,
|
|
796
|
+
0,
|
|
797
|
+
),
|
|
798
|
+
requiredVerificationPasses: outcomes.reduce(
|
|
799
|
+
(total, outcome) => total + outcome.requiredVerificationPasses,
|
|
800
|
+
0,
|
|
801
|
+
),
|
|
802
|
+
completedVerificationPasses: outcomes.reduce(
|
|
803
|
+
(total, outcome) => total + outcome.completedVerificationPasses,
|
|
804
|
+
0,
|
|
805
|
+
),
|
|
806
|
+
discoveredCandidates: outcomes.reduce(
|
|
807
|
+
(total, outcome) => total + outcome.discoveredCandidates,
|
|
808
|
+
0,
|
|
809
|
+
),
|
|
810
|
+
confirmedCandidates: confirmed.length,
|
|
811
|
+
rejectedCandidates: outcomes.reduce(
|
|
812
|
+
(total, outcome) => total + outcome.rejectedCandidates,
|
|
813
|
+
0,
|
|
814
|
+
),
|
|
815
|
+
unsettledCandidates,
|
|
816
|
+
discardedInvalidFindings: outcomes.reduce(
|
|
817
|
+
(total, outcome) => total + outcome.discardedFindings,
|
|
818
|
+
0,
|
|
819
|
+
),
|
|
820
|
+
failedPasses,
|
|
821
|
+
reasons,
|
|
822
|
+
});
|
|
823
|
+
const findings = rankAndDedupeFindings(
|
|
824
|
+
confirmed.flatMap(({ assessment, candidate }) =>
|
|
825
|
+
candidate._tag === "FindingCandidate"
|
|
826
|
+
? [confirmedFindingForPublication(assessment, candidate)]
|
|
827
|
+
: [],
|
|
828
|
+
),
|
|
597
829
|
);
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
unitId: request.unitId,
|
|
603
|
-
concern: candidate.concern,
|
|
604
|
-
evidencePaths: candidate.evidencePaths,
|
|
605
|
-
}),
|
|
830
|
+
const concerns = rankAndDedupeConcerns(
|
|
831
|
+
confirmed.flatMap(({ candidate }) =>
|
|
832
|
+
candidate._tag === "ConcernCandidate" ? [candidate.concern] : [],
|
|
833
|
+
),
|
|
606
834
|
);
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
835
|
+
const walkthrough = outcomes.flatMap((outcome) => outcome.walkthrough);
|
|
836
|
+
const blocking =
|
|
837
|
+
findings.some((finding) => finding.severity === "blocking") ||
|
|
838
|
+
concerns.some((concern) => concern.severity === "blocking");
|
|
839
|
+
const review = CodeReview.make({
|
|
840
|
+
summary: composeSummary(plan, assurance),
|
|
841
|
+
verdict: blocking
|
|
842
|
+
? "request-changes"
|
|
843
|
+
: findings.length > 0 || concerns.length > 0
|
|
844
|
+
? "comment"
|
|
845
|
+
: "approve",
|
|
846
|
+
findings,
|
|
847
|
+
...(concerns.length === 0 ? {} : { concerns }),
|
|
848
|
+
...(walkthrough.length === 0 ? {} : { walkthrough }),
|
|
614
849
|
});
|
|
850
|
+
return {
|
|
851
|
+
review,
|
|
852
|
+
assurance,
|
|
853
|
+
plan,
|
|
854
|
+
// Everything not fully reviewed this run and still part of the pull
|
|
855
|
+
// request carries forward, so the baseline can advance without ever
|
|
856
|
+
// moving unreviewed scope behind a green check: failed units retry,
|
|
857
|
+
// whole overflow files review in later installments, and partial or
|
|
858
|
+
// undiffable files keep the check fail-closed until they are reviewed,
|
|
859
|
+
// removed, or explicitly ignored.
|
|
860
|
+
unreviewedPaths: [
|
|
861
|
+
...new Set([
|
|
862
|
+
...outcomes.flatMap((outcome) => outcome.unreviewedPaths),
|
|
863
|
+
...plan.unassignedPaths,
|
|
864
|
+
...plan.partialEvidencePaths,
|
|
865
|
+
...plan.undiffablePaths,
|
|
866
|
+
]),
|
|
867
|
+
].sort(),
|
|
868
|
+
turns: outcomes.reduce((total, outcome) => total + outcome.turns, 0),
|
|
869
|
+
} satisfies FanOutPipelineOutcome;
|
|
615
870
|
});
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
const delegationDescription =
|
|
619
|
-
"Run exactly one host-planned discovery or candidate-verification child. Copy every plan field and candidate verbatim; never retry failed work.";
|
|
620
|
-
|
|
621
|
-
const makeFileReviewDelegation = (child: ReturnType<typeof makeFileReviewerDefinition>) =>
|
|
622
|
-
Subagent.define("delegate_file_review", {
|
|
623
|
-
description: delegationDescription,
|
|
624
|
-
target: child,
|
|
625
|
-
parameters: FileReviewRequest,
|
|
626
|
-
success: FileReviewUnitResult,
|
|
627
|
-
failure: FileReviewFailure,
|
|
628
|
-
failureMode: "return",
|
|
629
|
-
prepareInput: prepareReviewBrief,
|
|
630
|
-
projectResult: projectReviewResult,
|
|
631
|
-
policy: fileReviewPolicy,
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
export class ListReviewUnitsQuery extends Schema.Class<ListReviewUnitsQuery>(
|
|
635
|
-
"@effect-agent/pr-review/ListReviewUnitsQuery",
|
|
636
|
-
)({
|
|
637
|
-
scope: Schema.Literal("all"),
|
|
638
|
-
}) {}
|
|
639
|
-
|
|
640
|
-
export const ListReviewUnits = Tool.make("list_review_units", {
|
|
641
|
-
description:
|
|
642
|
-
"List deterministic bounded review units, explicit risk categories, every required discovery pass, and paths the pipeline cannot cover.",
|
|
643
|
-
parameters: ListReviewUnitsQuery,
|
|
644
|
-
success: ReviewUnitPlan,
|
|
645
|
-
failure: PullRequestSourceFailure,
|
|
646
|
-
failureMode: "error",
|
|
647
|
-
dependencies: [PullRequestSource],
|
|
648
|
-
}).annotate(ToolExecutionClass, "readonly");
|
|
649
|
-
|
|
650
|
-
export const FanOutCoordinatorToolkit = Toolkit.make(ListReviewUnits);
|
|
651
|
-
|
|
652
|
-
export const FanOutCoordinatorToolkitLayer = FanOutCoordinatorToolkit.toLayer({
|
|
653
|
-
list_review_units: () =>
|
|
654
|
-
Effect.gen(function* () {
|
|
655
|
-
const source = yield* PullRequestSource;
|
|
656
|
-
const files = yield* source.changedFiles;
|
|
657
|
-
const metadata = yield* source.metadata;
|
|
658
|
-
return planReviewUnits(files, { totalChangedFiles: metadata.totalChangedFiles });
|
|
659
|
-
}),
|
|
660
|
-
});
|
|
661
|
-
|
|
662
|
-
export const makeFanOutReviewInstructions =
|
|
663
|
-
(options: FanOutInstructionOptions & { readonly maxFindings?: number | undefined } = {}) =>
|
|
664
|
-
(mission: ReviewMission): string => {
|
|
665
|
-
const maxFindings = clampMaxFindings(options.maxFindings);
|
|
666
|
-
return [
|
|
667
|
-
`You coordinate the bounded multi-pass review of pull request #${mission.number} ("${mission.title}") in ${mission.repository}.`,
|
|
668
|
-
mission.body.length > 0 ? `Author description:\n${mission.body}` : "No author description.",
|
|
669
|
-
...staticGuidanceLines(options.guidance),
|
|
670
|
-
"1. Call list_review_units exactly once.",
|
|
671
|
-
'2. For EVERY discoveryPass, call delegate_file_review exactly once with phase "discovery", workId=passId, and the pass unitId/paths/evidenceShardIds/perspective/riskCategories verbatim; candidates must be []. Prefer one bounded parallel batch. Never retry.',
|
|
672
|
-
'3. Group candidates returned by all successful discovery passes by unit. Deterministically deduplicate byte-identical finding or concern payloads, retaining the first candidate in discoveryPass plan order. For every unit with at least one retained candidate, call delegate_file_review exactly once with phase "verification", workId "<unitId>-verification", perspective "candidate-verification", the unit paths/evidenceShardIds/riskCategories, and EVERY retained candidate copied byte-for-byte. Prefer one bounded parallel batch. Never retry.',
|
|
673
|
-
"4. Verification is authoritative: rejected candidates must not be reported. The host independently reconstructs publishable findings from exact confirmed assessments, so do not select, rewrite, downgrade, or invent findings.",
|
|
674
|
-
`5. Return ONLY CodeReview JSON. Write a concise summary of completed and failed stages. Set findings=[] and concerns=[]; the host injects exact confirmed candidates. Copy factual fileSummaries into walkthrough without invention. The host publication cap is ${maxFindings}.`,
|
|
675
|
-
"No configured pipeline can prove absence of defects. Describe settled work, never an exhaustive or defect-free review.",
|
|
676
|
-
].join("\n");
|
|
677
|
-
};
|
|
678
|
-
|
|
679
|
-
export const fanOutReviewInstructions = makeFanOutReviewInstructions();
|
|
680
|
-
|
|
681
|
-
export const defaultFanOutPolicy = AgentPolicy.make({
|
|
682
|
-
maxTurns: 7,
|
|
683
|
-
maxToolCalls: 1 + MAX_REVIEW_CHILDREN,
|
|
684
|
-
maxDuration: "20 minutes",
|
|
685
|
-
toolConcurrency: 4,
|
|
686
|
-
repeatedFailureLimit: 3,
|
|
687
|
-
tokenBudget: 400_000,
|
|
688
|
-
contextTokenLimit: 150_000,
|
|
689
|
-
// Coordinator exhaustion cannot become an assured result; exact stage
|
|
690
|
-
// settlement, not this final prose, determines assurance.
|
|
691
|
-
onExhaustion: "final-answer",
|
|
692
|
-
});
|
|
693
|
-
|
|
694
|
-
export interface FanOutReviewSuite {
|
|
695
|
-
readonly child: ReturnType<typeof makeFileReviewerDefinition>;
|
|
696
|
-
readonly parent: ReturnType<typeof makeFanOutReviewerDefinition>;
|
|
697
|
-
readonly delegation: ReturnType<typeof makeFileReviewDelegation>;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
const makeFileReviewerDefinition = (options: FanOutInstructionOptions = {}) =>
|
|
701
|
-
Agent.define("pr-review-worker", {
|
|
702
|
-
input: FileReviewBrief,
|
|
703
|
-
output: FileReviewReport,
|
|
704
|
-
instructions: makeFileReviewerInstructions(options),
|
|
705
|
-
toolkit: FileReviewToolkit,
|
|
706
|
-
policy: defaultFileReviewerPolicy,
|
|
707
|
-
description:
|
|
708
|
-
"Perform one bounded discovery or independent candidate-verification pass over host-supplied pull-request evidence.",
|
|
709
|
-
metadata: { deploymentClass: "E", surface: "read-only", stage: "discovery-verification" },
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
const delegationToolFor = (delegation: ReturnType<typeof makeFileReviewDelegation>) =>
|
|
713
|
-
delegation.tool.annotate(ToolExecutionClass, "readonly");
|
|
714
|
-
|
|
715
|
-
const makeFanOutReviewerDefinition = (
|
|
716
|
-
options: FanOutInstructionOptions & { readonly maxFindings?: number | undefined },
|
|
717
|
-
delegation: ReturnType<typeof makeFileReviewDelegation>,
|
|
718
|
-
) =>
|
|
719
|
-
Agent.define("pr-fanout-reviewer", {
|
|
720
|
-
input: ReviewMission,
|
|
721
|
-
output: CodeReview,
|
|
722
|
-
instructions: makeFanOutReviewInstructions(options),
|
|
723
|
-
toolkit: Toolkit.make(ListReviewUnits, delegationToolFor(delegation)),
|
|
724
|
-
policy: defaultFanOutPolicy,
|
|
725
|
-
description:
|
|
726
|
-
"Coordinate deterministic general/specialist discovery and independent candidate verification over bounded review units.",
|
|
727
|
-
metadata: {
|
|
728
|
-
deploymentClass: "E",
|
|
729
|
-
surface: "read-only",
|
|
730
|
-
delegation: "S1-attached",
|
|
731
|
-
assurance: "multi-pass",
|
|
732
|
-
},
|
|
733
|
-
});
|
|
734
|
-
|
|
735
|
-
export interface FanOutSuiteOptions extends FanOutInstructionOptions {
|
|
736
|
-
readonly maxFindings?: number | undefined;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
export const makeFanOutReviewSuite = (options: FanOutSuiteOptions = {}): FanOutReviewSuite => {
|
|
740
|
-
const child = makeFileReviewerDefinition({ guidance: options.guidance });
|
|
741
|
-
const delegation = makeFileReviewDelegation(child);
|
|
742
|
-
return {
|
|
743
|
-
child,
|
|
744
|
-
parent: makeFanOutReviewerDefinition(options, delegation),
|
|
745
|
-
delegation,
|
|
746
|
-
};
|
|
747
|
-
};
|
|
748
|
-
|
|
749
|
-
const defaultSuite = makeFanOutReviewSuite();
|
|
750
|
-
|
|
751
|
-
export const FileReviewer = defaultSuite.child;
|
|
752
|
-
export const FanOutReviewer = defaultSuite.parent;
|
|
753
|
-
export const fileReviewDelegation = defaultSuite.delegation;
|
|
754
|
-
export const DelegateFileReview = delegationToolFor(fileReviewDelegation);
|
|
755
|
-
export const FanOutReviewToolkit = FanOutReviewer.toolkit;
|
|
756
|
-
export const FileReviewDelegationFailure = fileReviewDelegation.containedFailure;
|
|
757
|
-
|
|
758
|
-
export const fanOutHandlersLayerFor =
|
|
759
|
-
(delegation: ReturnType<typeof makeFileReviewDelegation>) =>
|
|
760
|
-
<Provider, ModelProvides, ModelRequires>(
|
|
761
|
-
childBinding: RuntimeBinding<
|
|
762
|
-
typeof FileReviewBrief,
|
|
763
|
-
typeof FileReviewReport,
|
|
764
|
-
ReturnType<typeof makeFileReviewerInstructions>,
|
|
765
|
-
Toolkit.Tools<typeof FileReviewToolkit>,
|
|
766
|
-
Provider,
|
|
767
|
-
ModelProvides,
|
|
768
|
-
ModelRequires
|
|
769
|
-
>,
|
|
770
|
-
) =>
|
|
771
|
-
SubagentRuntime.layer(delegation, childBinding, {
|
|
772
|
-
mapChildFailure: mapFileReviewChildFailure,
|
|
773
|
-
});
|
|
774
|
-
|
|
775
|
-
export const fanOutHandlersLayer = fanOutHandlersLayerFor(fileReviewDelegation);
|