@open-cr-agent/core 0.17.0 → 0.19.0
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 +1 -1
- package/dist/agent/pool.d.ts +1 -0
- package/dist/agent/pool.js +21 -0
- package/dist/contracts.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +1 -0
- package/dist/judge/judge.d.ts +3 -1
- package/dist/judge/judge.js +8 -8
- package/dist/net/fetch-failure.d.ts +1 -0
- package/dist/net/fetch-failure.js +20 -0
- package/dist/pipeline/assemble-report.js +4 -0
- package/dist/pipeline/check-stage.d.ts +3 -2
- package/dist/pipeline/check-stage.js +12 -15
- package/dist/pipeline/early-check.d.ts +16 -0
- package/dist/pipeline/early-check.js +95 -0
- package/dist/pipeline/execute-stage.d.ts +4 -0
- package/dist/pipeline/execute-stage.js +21 -1
- package/dist/pipeline/filter-stage.js +1 -1
- package/dist/pipeline/findings.d.ts +1 -1
- package/dist/pipeline/findings.js +7 -3
- package/dist/pipeline/fix-finding.d.ts +39 -0
- package/dist/pipeline/fix-finding.js +113 -0
- package/dist/pipeline/options.d.ts +2 -0
- package/dist/pipeline/run.js +3 -2
- package/dist/pipeline/task-prompt.js +7 -1
- package/dist/pipeline/task.js +7 -0
- package/dist/plugin/types.d.ts +1 -0
- package/dist/report/inline.d.ts +37 -0
- package/dist/report/inline.js +67 -0
- package/dist/report/output-schema.d.ts +15 -0
- package/dist/report/output-schema.js +2 -0
- package/dist/report/output.js +7 -0
- package/dist/report/report.d.ts +8 -0
- package/dist/rereview/reconcile.d.ts +1 -0
- package/dist/rereview/reconcile.js +5 -1
- package/dist/review/prompt-text.d.ts +1 -1
- package/dist/review/prompt-text.js +1 -0
- package/dist/review/reviewers/agents-md.js +4 -1
- package/dist/review/reviewers/correctness.js +5 -2
- package/dist/review/reviewers/docs.js +5 -2
- package/dist/review/reviewers/performance.js +5 -2
- package/dist/review/reviewers/security.js +5 -2
- package/dist/review/reviewers/writing.d.ts +1 -0
- package/dist/review/reviewers/writing.js +8 -0
- package/dist/runtime/attempt.d.ts +1 -0
- package/dist/runtime/attempt.js +4 -1
- package/dist/runtime/failback.js +3 -2
- package/dist/runtime/text-tools.d.ts +16 -0
- package/dist/runtime/text-tools.js +60 -0
- package/dist/runtime/tools.js +5 -1
- package/dist/verify/early.d.ts +22 -0
- package/dist/verify/early.js +79 -0
- package/dist/verify/verify.d.ts +13 -0
- package/dist/verify/verify.js +77 -64
- package/package.json +3 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { oneShot } from "../agent/model-call.js";
|
|
2
|
+
import { roleCall } from "../agent/settings.js";
|
|
3
|
+
import { spendLimit } from "../agent/spend-limit.js";
|
|
4
|
+
import { matchInContent, matchInHunks } from "../anchor/match.js";
|
|
5
|
+
import { quoteSignature } from "../anchor/quote.js";
|
|
6
|
+
import { OcraError } from "../errors.js";
|
|
7
|
+
import { proposeFixes } from "../fix/propose.js";
|
|
8
|
+
import { MAX_FIX_SPAN_LINES } from "../fix/select.js";
|
|
9
|
+
import { reviewContext } from "./context.js";
|
|
10
|
+
const OUTCOME_OF = {
|
|
11
|
+
declined: "not_fixable",
|
|
12
|
+
no_parser: "not_fixable",
|
|
13
|
+
not_candidate: "not_fixable",
|
|
14
|
+
stale: "stale",
|
|
15
|
+
failed: "rejected",
|
|
16
|
+
unchanged: "rejected",
|
|
17
|
+
unsafe: "rejected",
|
|
18
|
+
too_large: "rejected",
|
|
19
|
+
syntax: "rejected",
|
|
20
|
+
};
|
|
21
|
+
// A checked fix for one stored finding (ADR-0077): the finding is anchored
|
|
22
|
+
// again at the head by the review's rules, and a fix is asked only for one
|
|
23
|
+
// the fix stage would ask for (fixCandidates), whether or not it had a fix.
|
|
24
|
+
export async function fixFinding(options) {
|
|
25
|
+
const { vcs, finding } = options;
|
|
26
|
+
if (!oneShot(options.runtime, () => { })) {
|
|
27
|
+
throw new OcraError("RUNTIME_START_FAILED", `the ${options.runtime.name} runtime makes no plain completions, which ocra fix needs`);
|
|
28
|
+
}
|
|
29
|
+
const { headSha } = await vcs.getChangeRequest();
|
|
30
|
+
if (options.expectedHead !== undefined && options.expectedHead !== headSha) {
|
|
31
|
+
return { headSha, outcome: "head_moved", warnings: [] };
|
|
32
|
+
}
|
|
33
|
+
const end = (reason, warnings = []) => ({
|
|
34
|
+
headSha,
|
|
35
|
+
outcome: OUTCOME_OF[reason],
|
|
36
|
+
reason,
|
|
37
|
+
warnings,
|
|
38
|
+
});
|
|
39
|
+
if (finding.lowConfidence)
|
|
40
|
+
return end("not_candidate");
|
|
41
|
+
const diffs = await vcs.getDiff();
|
|
42
|
+
const context = reviewContext(vcs, diffs);
|
|
43
|
+
let content;
|
|
44
|
+
try {
|
|
45
|
+
content = await context.readFile(finding.file);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// The access policy refuses it: no review read it, and no fix will.
|
|
49
|
+
return end("not_candidate");
|
|
50
|
+
}
|
|
51
|
+
if (content === undefined)
|
|
52
|
+
return end("stale");
|
|
53
|
+
const located = locate(finding, diffs, content);
|
|
54
|
+
if (typeof located === "string")
|
|
55
|
+
return end(located);
|
|
56
|
+
const lineRange = located.range;
|
|
57
|
+
const quote = quoteSignature(content, lineRange);
|
|
58
|
+
const candidate = {
|
|
59
|
+
id: finding.fingerprint,
|
|
60
|
+
fingerprint: finding.fingerprint,
|
|
61
|
+
reviewer: finding.reviewer,
|
|
62
|
+
category: finding.category,
|
|
63
|
+
severity: finding.severity,
|
|
64
|
+
file: finding.file,
|
|
65
|
+
existingCode: finding.existingCode ?? "",
|
|
66
|
+
title: finding.title,
|
|
67
|
+
body: finding.body,
|
|
68
|
+
...(finding.suggestion ? { suggestion: finding.suggestion } : {}),
|
|
69
|
+
evidence: [],
|
|
70
|
+
lineRange,
|
|
71
|
+
...(quote ? { quote } : {}),
|
|
72
|
+
provenance: { task: "fix" },
|
|
73
|
+
anchor: { method: "hunk", inDiff: true },
|
|
74
|
+
status: "new",
|
|
75
|
+
};
|
|
76
|
+
const limit = spendLimit(options.maxCostUsd);
|
|
77
|
+
const result = await proposeFixes([candidate], {
|
|
78
|
+
runtime: options.runtime,
|
|
79
|
+
syntax: options.syntax,
|
|
80
|
+
diffs,
|
|
81
|
+
context,
|
|
82
|
+
signal: options.signal,
|
|
83
|
+
concurrency: 1,
|
|
84
|
+
maxFixes: 1,
|
|
85
|
+
spendLimit: limit,
|
|
86
|
+
call: roleCall("fixer", options),
|
|
87
|
+
});
|
|
88
|
+
for (const usage of result.usage)
|
|
89
|
+
options.onUsage(usage);
|
|
90
|
+
const fix = result.findings[0]?.fix;
|
|
91
|
+
if (fix)
|
|
92
|
+
return { headSha, outcome: "proposed", fix, warnings: result.warnings };
|
|
93
|
+
return end(result.summary.rejected[0]?.reason ?? "failed", result.warnings);
|
|
94
|
+
}
|
|
95
|
+
// Where the finding's quote is at the head. Only a quote that fits one place
|
|
96
|
+
// in the change's hunks is a candidate, as anchoring by "hunk" is; a quote
|
|
97
|
+
// found nowhere in the file is stale, unless the stored text was altered.
|
|
98
|
+
function locate(finding, diffs, content) {
|
|
99
|
+
const code = finding.existingCode ?? "";
|
|
100
|
+
if (code.trim() === "")
|
|
101
|
+
return "not_candidate";
|
|
102
|
+
const own = diffs.find((d) => d.newPath === finding.file);
|
|
103
|
+
const inHunk = own ? matchInHunks(own, code) : undefined;
|
|
104
|
+
if (inHunk?.kind === "found") {
|
|
105
|
+
const { range } = inHunk;
|
|
106
|
+
return range.end - range.start < MAX_FIX_SPAN_LINES ? { range } : "not_candidate";
|
|
107
|
+
}
|
|
108
|
+
if (inHunk?.kind === "ambiguous")
|
|
109
|
+
return "not_candidate";
|
|
110
|
+
if (matchInContent(content, code).kind !== "none")
|
|
111
|
+
return "not_candidate";
|
|
112
|
+
return finding.altered ? "not_candidate" : "stale";
|
|
113
|
+
}
|
|
@@ -8,6 +8,7 @@ import type { ProjectDoc } from "../docs/project-docs.js";
|
|
|
8
8
|
import type { Learning } from "../knowledge/learning.js";
|
|
9
9
|
import type { MemoryEntry } from "../memory/memory.js";
|
|
10
10
|
import type { MergeCheck } from "../merge-checks/merge-check.js";
|
|
11
|
+
import type { InlinePolicy } from "../report/inline.js";
|
|
11
12
|
import type { ReviewEvent } from "../report/report.js";
|
|
12
13
|
import { type OptionalContext } from "../review/context-sources.js";
|
|
13
14
|
import type { ReviewerDefinition } from "../review/reviewer.js";
|
|
@@ -37,6 +38,7 @@ export interface ReviewOptions {
|
|
|
37
38
|
mergeChecks?: readonly MergeCheck[];
|
|
38
39
|
selection?: Partial<SelectionPolicy>;
|
|
39
40
|
limits?: ReviewLimits;
|
|
41
|
+
inline?: InlinePolicy;
|
|
40
42
|
stages?: ReviewStages;
|
|
41
43
|
mode?: ReviewMode;
|
|
42
44
|
identity?: RunIdentity;
|
package/dist/pipeline/run.js
CHANGED
|
@@ -13,7 +13,8 @@ import { newRunId } from "./run-id.js";
|
|
|
13
13
|
import { walkthroughStage } from "./walkthrough-stage.js";
|
|
14
14
|
// The library entry: plan (deterministic stages) → execute (one agent task
|
|
15
15
|
// per cell, beside the walkthrough and the pre-merge checks) → filter
|
|
16
|
-
// (memory, the previous review) → check (verify,
|
|
16
|
+
// (memory, the previous review) → check (verify, which starts while tasks
|
|
17
|
+
// still run, and judge) → fix → report. The `ocra`
|
|
17
18
|
// command is one caller. The manual's Embedding page says which options are
|
|
18
19
|
// a contract.
|
|
19
20
|
export function review(options) {
|
|
@@ -43,7 +44,7 @@ export async function reviewWithHooks(options) {
|
|
|
43
44
|
const mergeChecks = mergeChecksStage(context);
|
|
44
45
|
const executed = await executeStage(reviewers, context);
|
|
45
46
|
const filtered = await filterStage(executed, plan.prior.review, context);
|
|
46
|
-
const checked = await checkStage(filtered, context);
|
|
47
|
+
const checked = await checkStage(filtered, executed.early, context);
|
|
47
48
|
const fixed = await fixStage(checked, context);
|
|
48
49
|
const report = assembleReport({ runId, reviewers }, {
|
|
49
50
|
executed,
|
|
@@ -35,7 +35,7 @@ export function taskPrompt(cell, plan, { ultra, securityFiles, without, guidelin
|
|
|
35
35
|
};
|
|
36
36
|
const prompt = buildReviewPrompt(input);
|
|
37
37
|
const callers = (ultra || plan.tier === "full") && !without?.has("callers");
|
|
38
|
-
if (!ultra && !
|
|
38
|
+
if (!ultra && !plansFirst(cell))
|
|
39
39
|
return { input, prompt, callers };
|
|
40
40
|
return {
|
|
41
41
|
input,
|
|
@@ -55,6 +55,12 @@ function guidelinesInput(guidelines) {
|
|
|
55
55
|
...(guidelines.left.length > 0 ? { moreGuidelines: guidelines.left } : {}),
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
+
// A checklist orders a reviewer's steps inside one large bundle. A reviewer
|
|
59
|
+
// that takes the change as a whole is over the size on most changes, and
|
|
60
|
+
// its plan calls were a tenth of a review's bill for no finding more.
|
|
61
|
+
function plansFirst({ reviewer, bundle }) {
|
|
62
|
+
return (reviewer.scope?.span ?? "bundle") === "bundle" && isLargeBundle(bundle);
|
|
63
|
+
}
|
|
58
64
|
function isLargeBundle({ files }) {
|
|
59
65
|
const chars = files.reduce((sum, f) => sum + f.patch.length, 0);
|
|
60
66
|
return files.length >= PLAN_MIN_FILES || chars >= PLAN_MIN_PATCH_CHARS;
|
package/dist/pipeline/task.js
CHANGED
|
@@ -2,6 +2,7 @@ import { SpendLimitReached } from "../agent/spend-limit.js";
|
|
|
2
2
|
import { addUsage, emptyUsage } from "../agent/usage.js";
|
|
3
3
|
import { reportedFindingSchema } from "../domain.js";
|
|
4
4
|
import { errorMessage } from "../errors.js";
|
|
5
|
+
import { oneLine } from "../review/prompt-text.js";
|
|
5
6
|
export async function executeTask(runtime, spec, runSignal, callbacks) {
|
|
6
7
|
const timeout = AbortSignal.timeout(spec.timeoutMs);
|
|
7
8
|
const signal = AbortSignal.any([runSignal, timeout]);
|
|
@@ -116,6 +117,12 @@ function handle(event, result, callbacks) {
|
|
|
116
117
|
result.ended = event.ended;
|
|
117
118
|
if (event.wrapUp)
|
|
118
119
|
result.wrapUp = { findings: event.wrapUp.findings };
|
|
120
|
+
if (event.refusedFindings?.length) {
|
|
121
|
+
result.warnings.push(`${event.refusedFindings.length} finding(s) the reviewer reported were refused for their arguments and are missing (${event.refusedFindings
|
|
122
|
+
.slice(0, MAX_FINDINGS_PER_TASK)
|
|
123
|
+
.map((fields) => oneLine(fields).slice(0, 100))
|
|
124
|
+
.join("; ")})`);
|
|
125
|
+
}
|
|
119
126
|
return true;
|
|
120
127
|
case "error":
|
|
121
128
|
result.status = "failed";
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Finding, type Severity } from "../domain.js";
|
|
3
|
+
export declare const INLINE_HOLD_REASONS: readonly ["below_floor", "over_cap"];
|
|
4
|
+
export type InlineHoldReason = (typeof INLINE_HOLD_REASONS)[number];
|
|
5
|
+
export interface InlinePolicy {
|
|
6
|
+
minSeverity?: Severity;
|
|
7
|
+
maxComments?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface InlineSelection extends InlinePolicy {
|
|
10
|
+
held: {
|
|
11
|
+
fingerprint: string;
|
|
12
|
+
reason: InlineHoldReason;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
export declare const inlineSelectionSchema: z.ZodObject<{
|
|
16
|
+
minSeverity: z.ZodExactOptional<z.ZodEnum<{
|
|
17
|
+
critical: "critical";
|
|
18
|
+
suggestion: "suggestion";
|
|
19
|
+
warning: "warning";
|
|
20
|
+
}>>;
|
|
21
|
+
maxComments: z.ZodExactOptional<z.ZodInt>;
|
|
22
|
+
held: z.ZodArray<z.ZodObject<{
|
|
23
|
+
fingerprint: z.ZodString;
|
|
24
|
+
reason: z.ZodEnum<{
|
|
25
|
+
below_floor: "below_floor";
|
|
26
|
+
over_cap: "over_cap";
|
|
27
|
+
}>;
|
|
28
|
+
}, z.core.$strict>>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
/**
|
|
31
|
+
* The findings a policy holds back from inline comments: those below its
|
|
32
|
+
* floor, then those past its cap among the rest when ranked. The cap counts
|
|
33
|
+
* this review's findings, so one commented on in an earlier review and
|
|
34
|
+
* reported again takes a place without being posted twice. Undefined
|
|
35
|
+
* without a policy.
|
|
36
|
+
*/
|
|
37
|
+
export declare function selectInline(findings: readonly Finding[], policy: InlinePolicy): InlineSelection | undefined;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { severitySchema } from "../domain.js";
|
|
3
|
+
// Which findings a platform may post as inline comments (ADR-0076). A
|
|
4
|
+
// policy never removes a finding from the report or changes the verdict: a
|
|
5
|
+
// finding it holds back is listed in the summary instead.
|
|
6
|
+
export const INLINE_HOLD_REASONS = ["below_floor", "over_cap"];
|
|
7
|
+
export const inlineSelectionSchema = z.strictObject({
|
|
8
|
+
minSeverity: severitySchema.exactOptional(),
|
|
9
|
+
maxComments: z.int().nonnegative().exactOptional(),
|
|
10
|
+
held: z.array(z.strictObject({ fingerprint: z.string(), reason: z.enum(INLINE_HOLD_REASONS) })),
|
|
11
|
+
});
|
|
12
|
+
const SEVERITY_RANK = { critical: 0, warning: 1, suggestion: 2 };
|
|
13
|
+
const VERIFICATION_RANK = {
|
|
14
|
+
confirmed: 0,
|
|
15
|
+
uncertain: 1,
|
|
16
|
+
unchecked: 2,
|
|
17
|
+
};
|
|
18
|
+
// More severe first, then what Verify confirmed, then what the judge did not
|
|
19
|
+
// mark low confidence, then by place and fingerprint, so the order does not
|
|
20
|
+
// depend on the order tasks ended in.
|
|
21
|
+
function compareForInline(a, b) {
|
|
22
|
+
return (SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] ||
|
|
23
|
+
VERIFICATION_RANK[a.verification ?? "unchecked"] -
|
|
24
|
+
VERIFICATION_RANK[b.verification ?? "unchecked"] ||
|
|
25
|
+
Number(a.lowConfidence === true) - Number(b.lowConfidence === true) ||
|
|
26
|
+
compareText(a.file, b.file) ||
|
|
27
|
+
(a.lineRange?.start ?? 0) - (b.lineRange?.start ?? 0) ||
|
|
28
|
+
compareText(a.fingerprint, b.fingerprint));
|
|
29
|
+
}
|
|
30
|
+
function compareText(a, b) {
|
|
31
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
/** A finding a platform can comment on inline: anchored to lines in the diff. */
|
|
34
|
+
function postableInline(f) {
|
|
35
|
+
return f.lineRange !== undefined && f.anchor.inDiff;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The findings a policy holds back from inline comments: those below its
|
|
39
|
+
* floor, then those past its cap among the rest when ranked. The cap counts
|
|
40
|
+
* this review's findings, so one commented on in an earlier review and
|
|
41
|
+
* reported again takes a place without being posted twice. Undefined
|
|
42
|
+
* without a policy.
|
|
43
|
+
*/
|
|
44
|
+
export function selectInline(findings, policy) {
|
|
45
|
+
const { minSeverity, maxComments } = policy;
|
|
46
|
+
if (minSeverity === undefined && maxComments === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const ranked = findings.filter(postableInline).sort(compareForInline);
|
|
49
|
+
const held = [];
|
|
50
|
+
let kept = 0;
|
|
51
|
+
for (const f of ranked) {
|
|
52
|
+
if (minSeverity !== undefined && SEVERITY_RANK[f.severity] > SEVERITY_RANK[minSeverity]) {
|
|
53
|
+
held.push({ fingerprint: f.fingerprint, reason: "below_floor" });
|
|
54
|
+
}
|
|
55
|
+
else if (maxComments !== undefined && kept >= maxComments) {
|
|
56
|
+
held.push({ fingerprint: f.fingerprint, reason: "over_cap" });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
kept += 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
...(minSeverity !== undefined ? { minSeverity } : {}),
|
|
64
|
+
...(maxComments !== undefined ? { maxComments } : {}),
|
|
65
|
+
held,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -432,6 +432,21 @@ export declare const reportOutputSchema: z.ZodObject<{
|
|
|
432
432
|
total: "total";
|
|
433
433
|
}>>;
|
|
434
434
|
}, z.core.$strict>>;
|
|
435
|
+
inline: z.ZodExactOptional<z.ZodObject<{
|
|
436
|
+
minSeverity: z.ZodExactOptional<z.ZodEnum<{
|
|
437
|
+
critical: "critical";
|
|
438
|
+
suggestion: "suggestion";
|
|
439
|
+
warning: "warning";
|
|
440
|
+
}>>;
|
|
441
|
+
maxComments: z.ZodExactOptional<z.ZodInt>;
|
|
442
|
+
held: z.ZodArray<z.ZodObject<{
|
|
443
|
+
fingerprint: z.ZodString;
|
|
444
|
+
reason: z.ZodEnum<{
|
|
445
|
+
below_floor: "below_floor";
|
|
446
|
+
over_cap: "over_cap";
|
|
447
|
+
}>;
|
|
448
|
+
}, z.core.$strict>>;
|
|
449
|
+
}, z.core.$strict>>;
|
|
435
450
|
provenance: z.ZodExactOptional<z.ZodObject<{
|
|
436
451
|
ocraVersion: z.ZodString;
|
|
437
452
|
promptHash: z.ZodString;
|
|
@@ -8,6 +8,7 @@ import { memoryEntrySchema } from "../memory/memory.js";
|
|
|
8
8
|
import { MERGE_CHECK_OUTCOMES } from "../merge-checks/merge-check.js";
|
|
9
9
|
import { exclusionReasonSchema } from "../select/select.js";
|
|
10
10
|
import { TASK_TRACKERS } from "../task/linked-task.js";
|
|
11
|
+
import { inlineSelectionSchema } from "./inline.js";
|
|
11
12
|
import { taskStatusSchema } from "./report.js";
|
|
12
13
|
// The published shape of a review: `--format json` and a session's
|
|
13
14
|
// report.json. It is a contract with scripts and CI, so it carries a version
|
|
@@ -255,6 +256,7 @@ export const reportOutputSchema = z.strictObject({
|
|
|
255
256
|
spendLimit: z
|
|
256
257
|
.strictObject({ usd: z.number(), reached: z.enum(["review", "total"]).exactOptional() })
|
|
257
258
|
.exactOptional(),
|
|
259
|
+
inline: inlineSelectionSchema.exactOptional(),
|
|
258
260
|
provenance: provenanceSchema.exactOptional(),
|
|
259
261
|
usage: usageSchema,
|
|
260
262
|
warnings: z.array(z.string()),
|
package/dist/report/output.js
CHANGED
|
@@ -60,6 +60,13 @@ export function toReportOutput(report) {
|
|
|
60
60
|
output.anchoring = outputAnchoring(report.anchoring);
|
|
61
61
|
if (report.spendLimit)
|
|
62
62
|
output.spendLimit = outputSpendLimit(report.spendLimit);
|
|
63
|
+
if (report.inline) {
|
|
64
|
+
const { held, ...policy } = report.inline;
|
|
65
|
+
output.inline = {
|
|
66
|
+
...policy,
|
|
67
|
+
held: held.map(({ fingerprint, reason }) => ({ fingerprint, reason })),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
63
70
|
if (report.provenance)
|
|
64
71
|
output.provenance = outputProvenance(report.provenance);
|
|
65
72
|
if (report.rereview) {
|
package/dist/report/report.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { ExclusionReason } from "../select/select.js";
|
|
|
13
13
|
import type { LinkedTaskUse } from "../task/linked-task.js";
|
|
14
14
|
import type { RefutedFinding } from "../verify/verify.js";
|
|
15
15
|
import type { Walkthrough } from "../walkthrough/walkthrough.js";
|
|
16
|
+
import type { InlineSelection } from "./inline.js";
|
|
16
17
|
import type { RunProvenance } from "./provenance.js";
|
|
17
18
|
export type CoverageEntry = {
|
|
18
19
|
path: string;
|
|
@@ -117,6 +118,7 @@ export interface ReviewReport {
|
|
|
117
118
|
usd: number;
|
|
118
119
|
reached?: "review" | "total";
|
|
119
120
|
};
|
|
121
|
+
inline?: InlineSelection;
|
|
120
122
|
provenance?: RunProvenance;
|
|
121
123
|
usage: Usage;
|
|
122
124
|
warnings: string[];
|
|
@@ -183,6 +185,12 @@ export type ReviewEvent = {
|
|
|
183
185
|
} | {
|
|
184
186
|
type: "usage_reported";
|
|
185
187
|
usage: Usage;
|
|
188
|
+
} | {
|
|
189
|
+
type: "findings_verified";
|
|
190
|
+
file: string;
|
|
191
|
+
kept: Finding[];
|
|
192
|
+
refuted: string[];
|
|
193
|
+
settled: string[];
|
|
186
194
|
} | {
|
|
187
195
|
type: "verification_finished";
|
|
188
196
|
checked: number;
|
|
@@ -16,4 +16,5 @@ export interface Reconciled {
|
|
|
16
16
|
dismissed: PriorFinding[];
|
|
17
17
|
}
|
|
18
18
|
export declare function reconcile(input: ReconcileInput): Reconciled;
|
|
19
|
+
export declare function staysDismissed(finding: Pick<Finding, "severity">, old: PriorFinding): boolean;
|
|
19
20
|
export declare function stillOpen(reconciled: Reconciled): PriorFinding[];
|
|
@@ -32,7 +32,7 @@ export function reconcile(input) {
|
|
|
32
32
|
}
|
|
33
33
|
for (const finding of findings) {
|
|
34
34
|
const old = before.get(finding.fingerprint);
|
|
35
|
-
if (old
|
|
35
|
+
if (old && staysDismissed(finding, old)) {
|
|
36
36
|
result.dismissed.push(old);
|
|
37
37
|
continue;
|
|
38
38
|
}
|
|
@@ -44,6 +44,10 @@ export function reconcile(input) {
|
|
|
44
44
|
}
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
|
+
// A person's dismissal holds unless the finding came back more severe.
|
|
48
|
+
export function staysDismissed(finding, old) {
|
|
49
|
+
return !!old.dismissed && RANK[finding.severity] <= RANK[old.severity];
|
|
50
|
+
}
|
|
47
51
|
// Earlier findings that are neither fixed nor dismissed keep counting towards
|
|
48
52
|
// the verdict, so the same code reviewed twice cannot flip it by chance.
|
|
49
53
|
export function stillOpen(reconciled) {
|
|
@@ -2,7 +2,7 @@ declare const brand: unique symbol;
|
|
|
2
2
|
export type PromptText = string & {
|
|
3
3
|
readonly [brand]: "PromptText";
|
|
4
4
|
};
|
|
5
|
-
declare const SECTIONS: readonly ["change_request", "title", "description", "changed_files", "linked_tasks", "task", "body", "parent", "subtasks", "project_docs", "doc", "doc_index", "repository_guidelines", "review_rules", "accepted_findings", "team_learnings", "learning", "learning_index", "review_files", "file", "findings", "finding", "lines_to_replace", "diff", "file_excerpt", "related_code", "callers", "analyzer_results", "review_plan", "reply", "thread", "question", "merge_checks", "check"];
|
|
5
|
+
declare const SECTIONS: readonly ["change_request", "title", "description", "changed_files", "linked_tasks", "task", "body", "parent", "subtasks", "project_docs", "doc", "doc_index", "repository_guidelines", "review_rules", "accepted_findings", "team_learnings", "learning", "learning_index", "review_files", "file", "findings", "finding", "lines_to_replace", "diff", "file_excerpt", "related_code", "callers", "analyzer_results", "review_plan", "reply", "thread", "question", "merge_checks", "check", "tool_result"];
|
|
6
6
|
export type SectionName = (typeof SECTIONS)[number];
|
|
7
7
|
export declare function data(text: string): PromptText;
|
|
8
8
|
export declare function ocraText(text: string): PromptText;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { REVIEW_TOOLS as T } from "../tools.js";
|
|
2
2
|
import { TEST_FILES } from "./scopes.js";
|
|
3
|
+
import { FINDING_WRITING } from "./writing.js";
|
|
3
4
|
// Each reviewer's prompt is written and measured on its own; shared wording
|
|
4
5
|
// would tie one reviewer's evaluation to another's edits.
|
|
5
6
|
const SYSTEM_PROMPT = `You are the AGENTS.md reviewer in a multi-agent code review system. You review one bundle of changed files in a pull request and report where this change makes the repository's agent guidelines out of date. The guidelines are shown in <ocra_repository_guidelines>; other reviewers check that the code follows them.
|
|
@@ -27,11 +28,13 @@ Call ${T.reportFinding} once per outdated statement with:
|
|
|
27
28
|
- file: the path of a file in <ocra_review_files>.
|
|
28
29
|
- existingCode: one to five lines copied verbatim from the new version of that file, at the change that makes the guidelines wrong. Never invent or paraphrase code, never include diff markers, never give line numbers.
|
|
29
30
|
- severity: "warning" when an agent following the guidelines would now fail (a command or path that no longer exists); otherwise "suggestion". Never "critical".
|
|
30
|
-
- title:
|
|
31
|
+
- title: what the guidelines now get wrong.
|
|
31
32
|
- body: the statement in the guidelines, and what is true after this change.
|
|
32
33
|
- suggestion: an optional minimal update of the guidelines.
|
|
33
34
|
- evidence: the facts you verified with tools, such as "package.json renames the test script to test:unit; AGENTS.md still says npm test".
|
|
34
35
|
|
|
36
|
+
${FINDING_WRITING}
|
|
37
|
+
|
|
35
38
|
If a finding would not survive a skeptical senior engineer, do not report it. Reporting nothing is a valid outcome.
|
|
36
39
|
|
|
37
40
|
When every file has been reviewed, call ${T.taskDone}.`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CORRECTNESS_RULES } from "../../rules/builtin/index.js";
|
|
2
2
|
import { REVIEW_TOOLS as T } from "../tools.js";
|
|
3
|
+
import { FINDING_WRITING } from "./writing.js";
|
|
3
4
|
const SYSTEM_PROMPT = `You are the correctness reviewer in a multi-agent code review system. You review one bundle of changed files in a pull request and report defects that would make the changed code behave incorrectly.
|
|
4
5
|
|
|
5
6
|
## Trust boundary
|
|
@@ -30,11 +31,13 @@ Call ${T.reportFinding} once per confirmed issue with:
|
|
|
30
31
|
- file: the path of a file in <ocra_review_files>.
|
|
31
32
|
- existingCode: one to five lines copied verbatim from the new version of the file that pinpoint the defect. Never invent or paraphrase code, never include diff markers, never give line numbers.
|
|
32
33
|
- severity: "critical" for outages, data loss, security vulnerabilities or crashes on common paths; "warning" for incorrect behavior on realistic inputs or measurable regressions; "suggestion" only for low-risk correctness improvements worth a reviewer's time.
|
|
33
|
-
- title:
|
|
34
|
-
- body: why it is wrong, the input or state that triggers it, and its impact.
|
|
34
|
+
- title: the defect.
|
|
35
|
+
- body: why it is wrong, the input or state that triggers it, and its impact.
|
|
35
36
|
- suggestion: an optional minimal fix.
|
|
36
37
|
- evidence: the facts you verified with tools, such as "caller src/api.ts passes null when the header is missing".
|
|
37
38
|
|
|
39
|
+
${FINDING_WRITING}
|
|
40
|
+
|
|
38
41
|
If a finding would not survive a skeptical senior engineer, do not report it. Reporting nothing is a valid outcome.
|
|
39
42
|
|
|
40
43
|
When every file has been reviewed, call ${T.taskDone}.`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { REVIEW_TOOLS as T } from "../tools.js";
|
|
2
2
|
import { TEST_FILES } from "./scopes.js";
|
|
3
|
+
import { FINDING_WRITING } from "./writing.js";
|
|
3
4
|
// Each reviewer's prompt is written and measured on its own; shared wording
|
|
4
5
|
// would tie one reviewer's evaluation to another's edits.
|
|
5
6
|
const SYSTEM_PROMPT = `You are the documentation reviewer in a multi-agent code review system. You review one bundle of changed files in a pull request and report places where this change makes user-facing documentation wrong. Other reviewers cover correctness, security and performance.
|
|
@@ -29,11 +30,13 @@ Call ${T.reportFinding} once per contradiction with:
|
|
|
29
30
|
- file: the path of a file in <ocra_review_files>.
|
|
30
31
|
- existingCode: one to five lines copied verbatim from the new version of that file, at the change that makes the documentation wrong. Never invent or paraphrase code, never include diff markers, never give line numbers.
|
|
31
32
|
- severity: "warning" when users following the documentation would now fail (a removed flag, a renamed key, a changed default); "suggestion" for smaller mismatches. Never "critical".
|
|
32
|
-
- title:
|
|
33
|
-
- body: which document says what, and what the code does now.
|
|
33
|
+
- title: what the documentation now gets wrong.
|
|
34
|
+
- body: which document says what, and what the code does now.
|
|
34
35
|
- suggestion: an optional minimal correction of the document.
|
|
35
36
|
- evidence: the facts you verified with tools, such as "README.md line 42 documents --output-dir, which this change renamed to --out".
|
|
36
37
|
|
|
38
|
+
${FINDING_WRITING}
|
|
39
|
+
|
|
37
40
|
If a finding would not survive a skeptical senior engineer, do not report it. Reporting nothing is a valid outcome.
|
|
38
41
|
|
|
39
42
|
When every file has been reviewed, call ${T.taskDone}.`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PERFORMANCE_RULES } from "../../rules/builtin/index.js";
|
|
2
2
|
import { REVIEW_TOOLS as T } from "../tools.js";
|
|
3
3
|
import { DOCUMENTATION_FILES, TEST_FILES } from "./scopes.js";
|
|
4
|
+
import { FINDING_WRITING } from "./writing.js";
|
|
4
5
|
// Each reviewer's prompt is written and measured on its own; shared wording
|
|
5
6
|
// would tie one reviewer's evaluation to another's edits.
|
|
6
7
|
const SYSTEM_PROMPT = `You are the performance reviewer in a multi-agent code review system. You review one bundle of changed files in a pull request and report measurable performance regressions on paths that matter. Other reviewers cover correctness and security.
|
|
@@ -32,11 +33,13 @@ Call ${T.reportFinding} once per confirmed regression with:
|
|
|
32
33
|
- file: the path of a file in <ocra_review_files>.
|
|
33
34
|
- existingCode: one to five lines copied verbatim from the new version of the file that pinpoint the costly code. Never invent or paraphrase code, never include diff markers, never give line numbers.
|
|
34
35
|
- severity: "critical" for timeouts, memory exhaustion or outages on a common path with realistic data; "warning" for a measurable regression on a realistic path; "suggestion" only for a clear, low-risk win on a demonstrated hot path.
|
|
35
|
-
- title:
|
|
36
|
-
- body: what grows, with what input, on which path, and the expected impact.
|
|
36
|
+
- title: the regression.
|
|
37
|
+
- body: what grows, with what input, on which path, and the expected impact.
|
|
37
38
|
- suggestion: an optional minimal fix.
|
|
38
39
|
- evidence: the facts you verified with tools, such as "called once per row by exportAll in jobs/export.ts over the whole orders table".
|
|
39
40
|
|
|
41
|
+
${FINDING_WRITING}
|
|
42
|
+
|
|
40
43
|
If a finding would not survive a skeptical senior engineer, do not report it. Reporting nothing is a valid outcome.
|
|
41
44
|
|
|
42
45
|
When every file has been reviewed, call ${T.taskDone}.`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SECURITY_RULES } from "../../rules/builtin/index.js";
|
|
2
2
|
import { REVIEW_TOOLS as T } from "../tools.js";
|
|
3
3
|
import { DOCUMENTATION_FILES, TEST_FILES } from "./scopes.js";
|
|
4
|
+
import { FINDING_WRITING } from "./writing.js";
|
|
4
5
|
// Each reviewer's prompt is written and measured on its own; shared wording
|
|
5
6
|
// would tie one reviewer's evaluation to another's edits.
|
|
6
7
|
const SYSTEM_PROMPT = `You are the security reviewer in a multi-agent code review system. You review one bundle of changed files in a pull request and report vulnerabilities that the change introduces or makes reachable. Other reviewers cover general correctness and performance.
|
|
@@ -33,11 +34,13 @@ Call ${T.reportFinding} once per confirmed vulnerability with:
|
|
|
33
34
|
- file: the path of a file in <ocra_review_files>.
|
|
34
35
|
- existingCode: one to five lines copied verbatim from the new version of the file that pinpoint the vulnerable code. Never invent or paraphrase code, never include diff markers, never give line numbers.
|
|
35
36
|
- severity: "critical" when an unauthenticated or low-privilege attacker can execute code, bypass authentication or authorization, read or modify other users' data, or obtain secrets; "warning" when exploitation needs preconditions or the impact is limited; "suggestion" only for a specific, concrete hardening gap in the changed code.
|
|
36
|
-
- title:
|
|
37
|
-
- body: the attacker, the input they control, the path to the sink, and the impact.
|
|
37
|
+
- title: the vulnerability.
|
|
38
|
+
- body: the attacker, the input they control, the path to the sink, and the impact.
|
|
38
39
|
- suggestion: an optional minimal fix.
|
|
39
40
|
- evidence: the source-to-sink facts you verified with tools, such as "handler in routes/users.ts passes req.query.id straight to db.raw".
|
|
40
41
|
|
|
42
|
+
${FINDING_WRITING}
|
|
43
|
+
|
|
41
44
|
If a finding would not survive a skeptical security engineer, do not report it. Reporting nothing is a valid outcome.
|
|
42
45
|
|
|
43
46
|
When every file has been reviewed, call ${T.taskDone}.`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FINDING_WRITING = "Write for an engineer who reads the finding in the diff and has seconds for it:\n- title: at most 12 words, a plain statement of what is wrong, without a final period. Never open with \"This change\" or name the severity or the file.\n- body: at most three sentences. Open with what goes wrong, then the input or state that triggers it, then the impact. Do not repeat the title, retell the diff or list what you checked: that is evidence.\n- suggestion: one or two sentences naming the smallest change that fixes it, with the code inline when it fits on a line.\n- evidence: one fact per entry, each a single sentence.\n- Put identifiers, values and code in backticks. No headings, lists or tables.";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The one wording the built-in reviewers share: findings of all of them are
|
|
2
|
+
// read side by side in a diff, so they have one voice.
|
|
3
|
+
export const FINDING_WRITING = `Write for an engineer who reads the finding in the diff and has seconds for it:
|
|
4
|
+
- title: at most 12 words, a plain statement of what is wrong, without a final period. Never open with "This change" or name the severity or the file.
|
|
5
|
+
- body: at most three sentences. Open with what goes wrong, then the input or state that triggers it, then the impact. Do not repeat the title, retell the diff or list what you checked: that is evidence.
|
|
6
|
+
- suggestion: one or two sentences naming the smallest change that fixes it, with the code inline when it fits on a line.
|
|
7
|
+
- evidence: one fact per entry, each a single sentence.
|
|
8
|
+
- Put identifiers, values and code in backticks. No headings, lists or tables.`;
|
package/dist/runtime/attempt.js
CHANGED
|
@@ -36,7 +36,10 @@ export function attemptSummary(model, outcome) {
|
|
|
36
36
|
const unread = outcome.unreadMessages
|
|
37
37
|
? `, ${outcome.unreadMessages} session message(s) not read (their findings and usage are missing)`
|
|
38
38
|
: "";
|
|
39
|
-
|
|
39
|
+
const refused = outcome.refusedFindings?.length
|
|
40
|
+
? `, ${outcome.refusedFindings.length} finding(s) refused for their arguments and not sent again`
|
|
41
|
+
: "";
|
|
42
|
+
return `${model}: ${outcome.steps} step(s), ${toolSummary(outcome.toolCalls)}${resumed}${wrapUpSummary(outcome.wrappedUp)}, ${inputTokens} in / ${outputTokens} out / ${reasoningTokens} reasoning tokens, $${costUsd.toFixed(4)}${unread}${refused}`;
|
|
40
43
|
}
|
|
41
44
|
function wrapUpSummary(wrapUp) {
|
|
42
45
|
if (!wrapUp)
|
package/dist/runtime/failback.js
CHANGED
|
@@ -60,7 +60,7 @@ export async function* withFailback(options) {
|
|
|
60
60
|
// the run's limit: the pipeline decides what that stop means.
|
|
61
61
|
if (!outcome.error) {
|
|
62
62
|
health.recordSuccess(model);
|
|
63
|
-
yield doneEvent(taskId, ended, outcome
|
|
63
|
+
yield doneEvent(taskId, ended, outcome);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
// A cancelled attempt is neither finished nor the model's fault.
|
|
@@ -96,12 +96,13 @@ export async function* withFailback(options) {
|
|
|
96
96
|
...(quota ? { quota } : {}),
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
function doneEvent(taskId, ended, wrappedUp) {
|
|
99
|
+
function doneEvent(taskId, ended, { wrappedUp, refusedFindings }) {
|
|
100
100
|
return {
|
|
101
101
|
type: "done",
|
|
102
102
|
taskId,
|
|
103
103
|
...(ended === "step_cap" || ended === "stopped_early" ? { ended } : {}),
|
|
104
104
|
...(wrappedUp ? { wrapUp: { findings: wrappedUp.findings } } : {}),
|
|
105
|
+
...(refusedFindings?.length ? { refusedFindings } : {}),
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
108
|
function rateLimited(model, pauseMs) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ToolDefinition } from "../plugin/types.js";
|
|
2
|
+
import { type PromptText } from "../review/prompt-text.js";
|
|
3
|
+
export interface TextToolCall {
|
|
4
|
+
name: string;
|
|
5
|
+
input: unknown;
|
|
6
|
+
malformed?: true;
|
|
7
|
+
}
|
|
8
|
+
export declare function textToolInstructions(tools: readonly ToolDefinition[]): string;
|
|
9
|
+
export declare function parseTextToolCalls(answer: string): {
|
|
10
|
+
text: string;
|
|
11
|
+
calls: TextToolCall[];
|
|
12
|
+
};
|
|
13
|
+
export declare function textToolResults(outputs: readonly {
|
|
14
|
+
name: string;
|
|
15
|
+
output: string;
|
|
16
|
+
}[]): PromptText;
|