@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
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# @open-cr-agent/core
|
|
2
2
|
|
|
3
|
-
The domain types, pipeline stages and plugin contract of [Open-CR-Agent](https://github.com/
|
|
3
|
+
The domain types, pipeline stages and plugin contract of [Open-CR-Agent](https://github.com/ocrahq/Open-CR-Agent), the multi-agent code reviewer; see the [plugin guide](https://ocracloud.com/en/docs/plugins). Most users want [`@open-cr-agent/cli`](https://www.npmjs.com/package/@open-cr-agent/cli) (the `ocra` command) and the [manual](https://ocracloud.com). All packages share one version. Apache-2.0.
|
package/dist/agent/pool.d.ts
CHANGED
package/dist/agent/pool.js
CHANGED
|
@@ -11,3 +11,24 @@ export async function mapWithConcurrency(items, limit, worker) {
|
|
|
11
11
|
await Promise.all(runners);
|
|
12
12
|
return results;
|
|
13
13
|
}
|
|
14
|
+
// Runs jobs as they are added, at most `limit` at a time, in the order added.
|
|
15
|
+
export function limiter(limit) {
|
|
16
|
+
let running = 0;
|
|
17
|
+
const waiting = [];
|
|
18
|
+
return async (job) => {
|
|
19
|
+
if (running >= Math.max(limit, 1))
|
|
20
|
+
await new Promise((start) => waiting.push(start));
|
|
21
|
+
else
|
|
22
|
+
running += 1;
|
|
23
|
+
try {
|
|
24
|
+
return await job();
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
const next = waiting.shift();
|
|
28
|
+
if (next)
|
|
29
|
+
next();
|
|
30
|
+
else
|
|
31
|
+
running -= 1;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
package/dist/contracts.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type { Learning, LearningSource, LearningUse } from "./knowledge/learning
|
|
|
15
15
|
export type { SkippedCell, SkipReason } from "./matrix/matrix.js";
|
|
16
16
|
export type { MemoryEntry, MemorySource, RememberedEntry } from "./memory/memory.js";
|
|
17
17
|
export { MERGE_CHECK_OUTCOMES, type MergeCheck, type MergeCheckOutcome, type MergeCheckResult, } from "./merge-checks/merge-check.js";
|
|
18
|
+
export { fetchFailure } from "./net/fetch-failure.js";
|
|
18
19
|
export { type ProxyEnv, proxiedFetch } from "./net/proxied-fetch.js";
|
|
19
20
|
export { AccessDeniedError } from "./pipeline/context.js";
|
|
20
21
|
export type { ReviewLimits, ReviewMode, ReviewOptions, ReviewStages, RunIdentity, } from "./pipeline/options.js";
|
|
@@ -25,6 +26,7 @@ export { agentsMdReviewerPlugin, correctnessReviewerPlugin, docsReviewerPlugin,
|
|
|
25
26
|
export { type PluginHostOptions, startPlugins } from "./plugin/host.js";
|
|
26
27
|
export { PluginError, PluginRegistry } from "./plugin/registry.js";
|
|
27
28
|
export type { BootstrapContext, ConfigureContext, CustomProvider, Env, ModelPrice, OcraPlugin, PluginSummary, PostConfigureContext, RuntimeFactory, RuntimeOptions, ToolDefinition, VcsFactory, } from "./plugin/types.js";
|
|
29
|
+
export { INLINE_HOLD_REASONS, type InlineHoldReason, type InlinePolicy, type InlineSelection, } from "./report/inline.js";
|
|
28
30
|
export { type OutputFinding, type OutputPriorFinding, type ReportOutput, toReportOutput, } from "./report/output.js";
|
|
29
31
|
export { REPORT_VERSION, reportJsonSchema, reportOutputSchema } from "./report/output-schema.js";
|
|
30
32
|
export type { AgentProvenance, RuleProvenance, RunProvenance } from "./report/provenance.js";
|
|
@@ -41,6 +43,7 @@ export { type EffortCapability, type EffortParameter, effortCapability, thinking
|
|
|
41
43
|
export type { RateLimits } from "./runtime/failback.js";
|
|
42
44
|
export { type ModelRef, parseModel } from "./runtime/models.js";
|
|
43
45
|
export { MAX_QUOTA_WAIT_MS, parseQuotaError, type QuotaError } from "./runtime/quota.js";
|
|
46
|
+
export { parseTextToolCalls, type TextToolCall, textToolInstructions, textToolResults, } from "./runtime/text-tools.js";
|
|
44
47
|
export { reviewTools } from "./runtime/tools.js";
|
|
45
48
|
export type { AnalyzerEvidenceUse } from "./sarif/evidence.js";
|
|
46
49
|
export { parseSarifLog, SarifError, type SarifLog } from "./sarif/schema.js";
|
package/dist/index.js
CHANGED
|
@@ -12,12 +12,14 @@ export { PROJECT_DOC_LIMITS, } from "./docs/project-docs.js";
|
|
|
12
12
|
export { CompletionError, errorMessage, isOcraError, OCRA_ERROR_CODES, OcraError, } from "./errors.js";
|
|
13
13
|
export { FIX_REJECTIONS } from "./fix/check.js";
|
|
14
14
|
export { MERGE_CHECK_OUTCOMES, } from "./merge-checks/merge-check.js";
|
|
15
|
+
export { fetchFailure } from "./net/fetch-failure.js";
|
|
15
16
|
export { proxiedFetch } from "./net/proxied-fetch.js";
|
|
16
17
|
export { AccessDeniedError } from "./pipeline/context.js";
|
|
17
18
|
export { review } from "./pipeline/run.js";
|
|
18
19
|
export { agentsMdReviewerPlugin, correctnessReviewerPlugin, docsReviewerPlugin, performanceReviewerPlugin, securityReviewerPlugin, sessionJsonlPlugin, } from "./plugin/builtin.js";
|
|
19
20
|
export { startPlugins } from "./plugin/host.js";
|
|
20
21
|
export { PluginError, PluginRegistry } from "./plugin/registry.js";
|
|
22
|
+
export { INLINE_HOLD_REASONS, } from "./report/inline.js";
|
|
21
23
|
export { toReportOutput, } from "./report/output.js";
|
|
22
24
|
export { REPORT_VERSION, reportJsonSchema, reportOutputSchema } from "./report/output-schema.js";
|
|
23
25
|
export { coverageGaps, isBlocking, isIncompleteReview, isUnfinished, REVIEW_STAGES, } from "./report/report.js";
|
|
@@ -28,6 +30,7 @@ export { ChainRunner } from "./runtime/chain-runner.js";
|
|
|
28
30
|
export { effortCapability, thinkingBudget, } from "./runtime/effort-capability.js";
|
|
29
31
|
export { parseModel } from "./runtime/models.js";
|
|
30
32
|
export { MAX_QUOTA_WAIT_MS, parseQuotaError } from "./runtime/quota.js";
|
|
33
|
+
export { parseTextToolCalls, textToolInstructions, textToolResults, } from "./runtime/text-tools.js";
|
|
31
34
|
export { reviewTools } from "./runtime/tools.js";
|
|
32
35
|
export { parseSarifLog, SarifError } from "./sarif/schema.js";
|
|
33
36
|
export { LINKED_TASK_LIMITS, TASK_TRACKERS, } from "./task/linked-task.js";
|
package/dist/internal.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { type DraftLearning, type LearningDraft, type LearningEvidence, learning
|
|
|
11
11
|
export { MEMORY_PATH, memoryEntrySchema, parseMemory, serializeMemory, } from "./memory/memory.js";
|
|
12
12
|
export { answerMention } from "./pipeline/answer.js";
|
|
13
13
|
export { reviewContext } from "./pipeline/context.js";
|
|
14
|
+
export { type FixedFinding, fixFinding, type StoredFinding, } from "./pipeline/fix-finding.js";
|
|
14
15
|
export { type Generated, generateChanges } from "./pipeline/generate.js";
|
|
15
16
|
export { MAX_TIMER_MS, REVIEW_DEFAULTS } from "./pipeline/options.js";
|
|
16
17
|
export { PLAN_VERSION, planOutputSchema, toPlanOutput, } from "./pipeline/plan-output.js";
|
package/dist/internal.js
CHANGED
|
@@ -13,6 +13,7 @@ export { learningDrafter, } from "./learn/draft.js";
|
|
|
13
13
|
export { MEMORY_PATH, memoryEntrySchema, parseMemory, serializeMemory, } from "./memory/memory.js";
|
|
14
14
|
export { answerMention } from "./pipeline/answer.js";
|
|
15
15
|
export { reviewContext } from "./pipeline/context.js";
|
|
16
|
+
export { fixFinding, } from "./pipeline/fix-finding.js";
|
|
16
17
|
export { generateChanges } from "./pipeline/generate.js";
|
|
17
18
|
export { MAX_TIMER_MS, REVIEW_DEFAULTS } from "./pipeline/options.js";
|
|
18
19
|
export { PLAN_VERSION, planOutputSchema, toPlanOutput, } from "./pipeline/plan-output.js";
|
package/dist/judge/judge.d.ts
CHANGED
|
@@ -37,9 +37,11 @@ export interface JudgeOptions {
|
|
|
37
37
|
call?: AgentCallSettings | undefined;
|
|
38
38
|
keepDropped?: boolean;
|
|
39
39
|
carried?: readonly PriorFinding[];
|
|
40
|
+
settled?: ReadonlySet<string>;
|
|
40
41
|
}
|
|
41
42
|
export declare function judgeFindings(findings: readonly Finding[], options: JudgeOptions): Promise<JudgeResult>;
|
|
42
|
-
export declare function
|
|
43
|
+
export declare function protectedFinding(f: Finding): boolean;
|
|
44
|
+
export declare function applyDecisions(findings: readonly Finding[], response: JudgeResponse, settled?: ReadonlySet<string>): {
|
|
43
45
|
findings: Finding[];
|
|
44
46
|
decisions: JudgeDecisions;
|
|
45
47
|
warnings: string[];
|
package/dist/judge/judge.js
CHANGED
|
@@ -37,7 +37,7 @@ export async function judgeFindings(findings, options) {
|
|
|
37
37
|
catch (error) {
|
|
38
38
|
return fallback([`judge failed, reporting findings unjudged: ${errorMessage(error)}`], usage);
|
|
39
39
|
}
|
|
40
|
-
const judged = applyDecisions(findings, response);
|
|
40
|
+
const judged = applyDecisions(findings, response, options.settled);
|
|
41
41
|
if (options.keepDropped) {
|
|
42
42
|
const dropped = new Set(judged.decisions.dropped.map((d) => d.fingerprint));
|
|
43
43
|
judged.findings.push(...findings
|
|
@@ -57,24 +57,24 @@ export async function judgeFindings(findings, options) {
|
|
|
57
57
|
// A critical finding the verifier confirmed is never dropped and never
|
|
58
58
|
// downgraded: the judge reads text the change's author controls, and either
|
|
59
59
|
// would take a blocking finding out of the verdict.
|
|
60
|
-
function protectedFinding(f) {
|
|
60
|
+
export function protectedFinding(f) {
|
|
61
61
|
return f.severity === "critical" && f.verification === "confirmed";
|
|
62
62
|
}
|
|
63
63
|
// Indexes come from a model: out-of-range, repeated or conflicting ones are
|
|
64
64
|
// ignored rather than trusted.
|
|
65
|
-
export function applyDecisions(findings, response) {
|
|
65
|
+
export function applyDecisions(findings, response, settled = new Set()) {
|
|
66
66
|
const valid = (i) => Number.isInteger(i) && i >= 0 && i < findings.length;
|
|
67
67
|
const decisions = { merged: [], dropped: [], recalibrated: [] };
|
|
68
68
|
const warnings = [];
|
|
69
69
|
const removed = new Set();
|
|
70
70
|
const isProtected = (i) => protectedFinding(at(findings, i));
|
|
71
|
+
const isSettled = (i) => settled.has(at(findings, i).id);
|
|
71
72
|
for (const group of response.duplicates) {
|
|
72
73
|
const members = [...new Set(group.filter(valid))].filter((i) => !removed.has(i));
|
|
73
|
-
// Merging keeps one member
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const [keep, ...rest] = members;
|
|
74
|
+
// Merging keeps one member: a settled one, else a protected one, so
|
|
75
|
+
// neither is merged away. Other settled members stay as they are.
|
|
76
|
+
const keep = members.find(isSettled) ?? members.find(isProtected) ?? members[0];
|
|
77
|
+
const rest = members.filter((i) => i !== keep && !isSettled(i));
|
|
78
78
|
if (keep === undefined || rest.length === 0)
|
|
79
79
|
continue;
|
|
80
80
|
for (const i of rest)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fetchFailure(error: unknown): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { errnoCode, errorMessage } from "../errors.js";
|
|
2
|
+
const UNTRUSTED_CERTIFICATE = /SELF_SIGNED|UNABLE_TO_(VERIFY|GET_ISSUER)/;
|
|
3
|
+
// fetch says only "fetch failed"; its causes name the network or TLS error.
|
|
4
|
+
// A server whose certificate authority Node does not trust (a company's own)
|
|
5
|
+
// is fixed on this machine, so the message says how.
|
|
6
|
+
export function fetchFailure(error) {
|
|
7
|
+
// Each without its full stop, so the causes read as one sentence.
|
|
8
|
+
const said = (e) => errorMessage(e).replace(/\.$/, "");
|
|
9
|
+
const messages = [said(error)];
|
|
10
|
+
let untrusted = false;
|
|
11
|
+
let cause = error instanceof Error ? error.cause : undefined;
|
|
12
|
+
while (cause instanceof Error) {
|
|
13
|
+
const message = said(cause);
|
|
14
|
+
if (message && !messages.includes(message))
|
|
15
|
+
messages.push(message);
|
|
16
|
+
untrusted ||= UNTRUSTED_CERTIFICATE.test(errnoCode(cause) ?? "");
|
|
17
|
+
cause = cause.cause;
|
|
18
|
+
}
|
|
19
|
+
return `${messages.join(": ")}${untrusted ? " (trust the server's certificate authority with NODE_EXTRA_CA_CERTS)" : ""}`;
|
|
20
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { effortWarnings, resolveAgents } from "../agent/settings.js";
|
|
2
2
|
import { addUsage, emptyUsage, unpricedCalls } from "../agent/usage.js";
|
|
3
3
|
import { projectDocUses } from "../docs/project-docs.js";
|
|
4
|
+
import { selectInline } from "../report/inline.js";
|
|
4
5
|
import { nothingReviewedSummary, summarizeAnchoring } from "../report/report.js";
|
|
5
6
|
import { evidenceUses } from "../sarif/evidence.js";
|
|
6
7
|
import { runProvenance } from "./provenance.js";
|
|
@@ -19,6 +20,9 @@ export function assembleReport(run, stages, context) {
|
|
|
19
20
|
const limit = spendLimit.status();
|
|
20
21
|
if (limit)
|
|
21
22
|
report.spendLimit = limit;
|
|
23
|
+
const inline = options.inline && selectInline(report.findings, options.inline);
|
|
24
|
+
if (inline)
|
|
25
|
+
report.inline = inline;
|
|
22
26
|
report.anchoring = summarizeAnchoring(report.findings, executed.relocations.length);
|
|
23
27
|
const agents = resolveAgents(run.reviewers, options);
|
|
24
28
|
report.warnings.push(...effortWarnings(agents, options.runtime));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Usage } from "../contracts.js";
|
|
2
2
|
import { type JudgeResult } from "../judge/judge.js";
|
|
3
3
|
import { type VerificationResult } from "../verify/verify.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { EarlyCheck } from "./early-check.js";
|
|
5
|
+
import { type StageContext } from "./execute-stage.js";
|
|
5
6
|
import type { FilterStage } from "./filter-stage.js";
|
|
6
7
|
export interface CheckStage {
|
|
7
8
|
verification: VerificationResult;
|
|
@@ -9,4 +10,4 @@ export interface CheckStage {
|
|
|
9
10
|
usage: Usage[];
|
|
10
11
|
warnings: string[];
|
|
11
12
|
}
|
|
12
|
-
export declare function checkStage(filtered: FilterStage, context: StageContext): Promise<CheckStage>;
|
|
13
|
+
export declare function checkStage(filtered: FilterStage, early: EarlyCheck | undefined, context: StageContext): Promise<CheckStage>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { roleCall } from "../agent/settings.js";
|
|
2
2
|
import { judgeFindings } from "../judge/judge.js";
|
|
3
3
|
import { stillOpen } from "../rereview/reconcile.js";
|
|
4
|
-
import {
|
|
4
|
+
import { verifyRemaining } from "../verify/early.js";
|
|
5
|
+
import { markUnchecked } from "../verify/verify.js";
|
|
6
|
+
import { verifyOptions } from "./execute-stage.js";
|
|
5
7
|
// Verify fact-checks the findings, then the judge merges, filters and
|
|
6
8
|
// recalibrates them and gives the verdict.
|
|
7
|
-
export async function checkStage(filtered, context) {
|
|
9
|
+
export async function checkStage(filtered, early, context) {
|
|
8
10
|
context.emit({ type: "stage_started", stage: "verify" });
|
|
9
|
-
const
|
|
11
|
+
const checked = await early?.result();
|
|
12
|
+
const verification = hidePreExisting(await verify(filtered, checked?.verification, context), context.settings);
|
|
10
13
|
context.emit({ type: "stage_started", stage: "judge" });
|
|
11
|
-
const judged = await judge(verification, filtered, context);
|
|
14
|
+
const judged = await judge(verification, filtered, checked?.settled, context);
|
|
12
15
|
for (const usage of judged.usage)
|
|
13
16
|
context.spendLimit.charge(usage);
|
|
14
17
|
return {
|
|
@@ -18,7 +21,8 @@ export async function checkStage(filtered, context) {
|
|
|
18
21
|
warnings: [...verification.warnings, ...judged.warnings],
|
|
19
22
|
};
|
|
20
23
|
}
|
|
21
|
-
async function verify({ reconciled },
|
|
24
|
+
async function verify({ reconciled }, early, context) {
|
|
25
|
+
const { settings, emit } = context;
|
|
22
26
|
if (!settings.verify) {
|
|
23
27
|
return {
|
|
24
28
|
checked: 0,
|
|
@@ -29,15 +33,7 @@ async function verify({ reconciled }, { options, settings, plan, spendLimit, sig
|
|
|
29
33
|
warnings: [],
|
|
30
34
|
};
|
|
31
35
|
}
|
|
32
|
-
const verification = await
|
|
33
|
-
runtime: options.runtime,
|
|
34
|
-
diffs: plan.selected,
|
|
35
|
-
context: plan.context,
|
|
36
|
-
signal,
|
|
37
|
-
concurrency: settings.concurrency,
|
|
38
|
-
spendLimit,
|
|
39
|
-
call: roleCall("verifier", options),
|
|
40
|
-
});
|
|
36
|
+
const verification = await verifyRemaining(reconciled.findings, early, verifyOptions(context));
|
|
41
37
|
if (verification.checked > 0) {
|
|
42
38
|
emit({
|
|
43
39
|
type: "verification_finished",
|
|
@@ -63,7 +59,7 @@ function hidePreExisting(verification, settings) {
|
|
|
63
59
|
],
|
|
64
60
|
};
|
|
65
61
|
}
|
|
66
|
-
async function judge(verification, { reconciled, nothingReviewed }, { options, settings, plan, spendLimit, signal, emit }) {
|
|
62
|
+
async function judge(verification, { reconciled, nothingReviewed }, settled, { options, settings, plan, spendLimit, signal, emit }) {
|
|
67
63
|
const wanted = settings.judge && verification.kept.length > 0;
|
|
68
64
|
const affordable = spendLimit.mayCall();
|
|
69
65
|
const judged = await judgeFindings(verification.kept, {
|
|
@@ -75,6 +71,7 @@ async function judge(verification, { reconciled, nothingReviewed }, { options, s
|
|
|
75
71
|
enabled: wanted && affordable,
|
|
76
72
|
keepDropped: settings.ultra,
|
|
77
73
|
carried: stillOpen(reconciled),
|
|
74
|
+
...(settled ? { settled } : {}),
|
|
78
75
|
});
|
|
79
76
|
if (wanted && !affordable) {
|
|
80
77
|
judged.warnings.push(`spend limit of $${settings.maxCostUsd} reached: findings were not judged`);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Finding } from "../domain.js";
|
|
2
|
+
import type { MatrixCell } from "../matrix/matrix.js";
|
|
3
|
+
import { type EarlyVerification } from "../verify/early.js";
|
|
4
|
+
import type { VerifyOptions } from "../verify/verify.js";
|
|
5
|
+
import type { StageContext } from "./execute-stage.js";
|
|
6
|
+
interface EarlyResult {
|
|
7
|
+
verification: EarlyVerification;
|
|
8
|
+
settled: ReadonlySet<string>;
|
|
9
|
+
}
|
|
10
|
+
export interface EarlyCheck {
|
|
11
|
+
readonly submitted: ReadonlySet<string>;
|
|
12
|
+
taskEnded(cell: MatrixCell, findings: readonly Finding[]): void;
|
|
13
|
+
result(): Promise<EarlyResult>;
|
|
14
|
+
}
|
|
15
|
+
export declare function earlyCheck(cells: readonly MatrixCell[], verify: VerifyOptions, { settings, plan, emit }: StageContext): EarlyCheck | undefined;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { protectedFinding } from "../judge/judge.js";
|
|
2
|
+
import { staysDismissed } from "../rereview/reconcile.js";
|
|
3
|
+
import { earlyVerifier } from "../verify/early.js";
|
|
4
|
+
import { dedupeFindings } from "./findings.js";
|
|
5
|
+
// Undefined when the run does not verify.
|
|
6
|
+
export function earlyCheck(cells, verify, { settings, plan, emit }) {
|
|
7
|
+
if (!settings.verify)
|
|
8
|
+
return undefined;
|
|
9
|
+
const settled = new Set();
|
|
10
|
+
const verifier = earlyVerifier(verify, (file, verified) => {
|
|
11
|
+
const now = settle(verified, settings.showPreExisting);
|
|
12
|
+
for (const f of now)
|
|
13
|
+
settled.add(f.id);
|
|
14
|
+
emit({
|
|
15
|
+
type: "findings_verified",
|
|
16
|
+
file,
|
|
17
|
+
kept: verified.kept,
|
|
18
|
+
refuted: verified.refuted.map((r) => r.finding.id),
|
|
19
|
+
settled: now.map((f) => f.id),
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
if (!verifier)
|
|
23
|
+
return undefined;
|
|
24
|
+
const reportable = keptByPeople(plan.prior.review, plan.memory);
|
|
25
|
+
const order = new Map(cells.map((cell, index) => [cell.taskId, index]));
|
|
26
|
+
const open = openTasks(cells);
|
|
27
|
+
const found = new Map();
|
|
28
|
+
return {
|
|
29
|
+
submitted: verifier.submitted,
|
|
30
|
+
taskEnded(cell, findings) {
|
|
31
|
+
const at = order.get(cell.taskId) ?? cells.length;
|
|
32
|
+
for (const finding of findings) {
|
|
33
|
+
// A file checked already keeps its answer: a finding that names it
|
|
34
|
+
// later waits for Verify.
|
|
35
|
+
if (open.has(finding.file)) {
|
|
36
|
+
found.set(finding.file, [...(found.get(finding.file) ?? []), { at, finding }]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const { newPath } of cell.bundle.files) {
|
|
40
|
+
const tasks = open.get(newPath);
|
|
41
|
+
tasks?.delete(cell.taskId);
|
|
42
|
+
if (tasks?.size !== 0)
|
|
43
|
+
continue;
|
|
44
|
+
open.delete(newPath);
|
|
45
|
+
// In the tasks' order, as Verify would see them.
|
|
46
|
+
const group = dedupeFindings((found.get(newPath) ?? []).sort((a, b) => a.at - b.at).map((f) => f.finding)).filter(reportable);
|
|
47
|
+
if (group.length > 0)
|
|
48
|
+
verifier.verify(newPath, group);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
result: async () => ({ verification: await verifier.result(), settled }),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// The tasks still to end, by file they review.
|
|
55
|
+
function openTasks(cells) {
|
|
56
|
+
const open = new Map();
|
|
57
|
+
for (const cell of cells) {
|
|
58
|
+
for (const { newPath } of cell.bundle.files) {
|
|
59
|
+
open.set(newPath, (open.get(newPath) ?? new Set()).add(cell.taskId));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return open;
|
|
63
|
+
}
|
|
64
|
+
// What memory and a person's dismissal leave of the findings (filter-stage.ts
|
|
65
|
+
// applies both to the whole run); neither is worth a verifier call.
|
|
66
|
+
function keptByPeople(prior, memory) {
|
|
67
|
+
const accepted = new Set(memory.map((e) => e.fingerprint));
|
|
68
|
+
const before = new Map(prior?.findings.map((f) => [f.fingerprint, f]));
|
|
69
|
+
return (finding) => {
|
|
70
|
+
if (accepted.has(finding.fingerprint))
|
|
71
|
+
return false;
|
|
72
|
+
const old = before.get(finding.fingerprint);
|
|
73
|
+
return !(old && staysDismissed(finding, old));
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// The judge can neither drop nor downgrade a confirmed critical finding, but
|
|
77
|
+
// it may merge two that say the same thing; of findings on overlapping lines
|
|
78
|
+
// only the first is settled, and the others wait for it.
|
|
79
|
+
function settle(verified, showPreExisting) {
|
|
80
|
+
const settled = [];
|
|
81
|
+
for (const finding of verified.kept) {
|
|
82
|
+
if (!protectedFinding(finding))
|
|
83
|
+
continue;
|
|
84
|
+
if (finding.preExisting && !showPreExisting)
|
|
85
|
+
continue;
|
|
86
|
+
if (!settled.some((other) => overlap(other, finding)))
|
|
87
|
+
settled.push(finding);
|
|
88
|
+
}
|
|
89
|
+
return settled;
|
|
90
|
+
}
|
|
91
|
+
function overlap(a, b) {
|
|
92
|
+
if (!a.lineRange || !b.lineRange)
|
|
93
|
+
return true;
|
|
94
|
+
return a.lineRange.start <= b.lineRange.end && b.lineRange.start <= a.lineRange.end;
|
|
95
|
+
}
|
|
@@ -3,6 +3,8 @@ import type { Usage } from "../contracts.js";
|
|
|
3
3
|
import { type ReviewMatrix } from "../matrix/matrix.js";
|
|
4
4
|
import type { ReviewEvent } from "../report/report.js";
|
|
5
5
|
import type { ReviewerDefinition } from "../review/reviewer.js";
|
|
6
|
+
import type { VerifyOptions } from "../verify/verify.js";
|
|
7
|
+
import { type EarlyCheck } from "./early-check.js";
|
|
6
8
|
import { type JobResult } from "./execute.js";
|
|
7
9
|
import { type ReviewHooks, type ReviewOptions, type RunSettings } from "./options.js";
|
|
8
10
|
import type { ReviewPlan } from "./plan.js";
|
|
@@ -21,5 +23,7 @@ export interface ExecuteStage {
|
|
|
21
23
|
relocations: readonly Usage[];
|
|
22
24
|
usage(): Usage[];
|
|
23
25
|
warnings: string[];
|
|
26
|
+
early?: EarlyCheck;
|
|
24
27
|
}
|
|
25
28
|
export declare function executeStage(reviewers: readonly ReviewerDefinition[], context: StageContext): Promise<ExecuteStage>;
|
|
29
|
+
export declare function verifyOptions({ options, settings, plan, spendLimit, signal, }: StageContext): VerifyOptions;
|
|
@@ -4,6 +4,7 @@ import { emptyUsage } from "../agent/usage.js";
|
|
|
4
4
|
import { runtimeRelocator } from "../anchor/relocate.js";
|
|
5
5
|
import { DEFAULT_MAX_TASKS, planTasks, } from "../matrix/matrix.js";
|
|
6
6
|
import { securityReviewed } from "../sarif/evidence.js";
|
|
7
|
+
import { earlyCheck } from "./early-check.js";
|
|
7
8
|
import { prepareJob, reuseJob, runJob } from "./execute.js";
|
|
8
9
|
import { guidelinesShown, } from "./options.js";
|
|
9
10
|
import { reusePool } from "./resume.js";
|
|
@@ -33,7 +34,7 @@ export async function executeStage(reviewers, context) {
|
|
|
33
34
|
execute.reuse = { pool, runId: resume.runId };
|
|
34
35
|
const notStarted = new Set();
|
|
35
36
|
let unaffordable = 0;
|
|
36
|
-
const
|
|
37
|
+
const runCell = async (cell) => {
|
|
37
38
|
// Once the run is cancelled or timed out, remaining cells are not started.
|
|
38
39
|
if (context.signal.aborted) {
|
|
39
40
|
notStarted.add(cell.taskId);
|
|
@@ -49,6 +50,12 @@ export async function executeStage(reviewers, context) {
|
|
|
49
50
|
return skipCell(cell, `spend limit of $${settings.maxCostUsd} reached`, emit);
|
|
50
51
|
}
|
|
51
52
|
return runJob(cell, plan, execute, prepared);
|
|
53
|
+
};
|
|
54
|
+
const early = earlyCheck(matrix.cells, verifyOptions(context), context);
|
|
55
|
+
const results = await mapWithConcurrency(matrix.cells, settings.concurrency, async (cell) => {
|
|
56
|
+
const result = await runCell(cell);
|
|
57
|
+
early?.taskEnded(cell, result.findings);
|
|
58
|
+
return result;
|
|
52
59
|
});
|
|
53
60
|
if (unaffordable > 0) {
|
|
54
61
|
warnings.push(`spend limit of $${settings.maxCostUsd} reached: ${unaffordable} review task(s) did not start; their files are reported as not reviewed`);
|
|
@@ -63,6 +70,19 @@ export async function executeStage(reviewers, context) {
|
|
|
63
70
|
relocations,
|
|
64
71
|
usage: () => [...results.map((r) => r.usage), ...relocations],
|
|
65
72
|
warnings,
|
|
73
|
+
...(early ? { early } : {}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// One for the calls made while tasks run and the ones Verify makes after.
|
|
77
|
+
export function verifyOptions({ options, settings, plan, spendLimit, signal, }) {
|
|
78
|
+
return {
|
|
79
|
+
runtime: options.runtime,
|
|
80
|
+
diffs: plan.selected,
|
|
81
|
+
context: plan.context,
|
|
82
|
+
signal,
|
|
83
|
+
concurrency: settings.concurrency,
|
|
84
|
+
spendLimit,
|
|
85
|
+
call: roleCall("verifier", options),
|
|
66
86
|
};
|
|
67
87
|
}
|
|
68
88
|
function executeOptions({ options, settings, spendLimit, signal, emit }, relocations) {
|
|
@@ -14,7 +14,7 @@ export async function filterStage(executed, prior, { options, plan, emit }) {
|
|
|
14
14
|
? await importSarif(options.sarif, plan, emit)
|
|
15
15
|
: { findings: [], outcomes: [], warnings: [] };
|
|
16
16
|
const { results } = executed;
|
|
17
|
-
const found = dedupeFindings([...results.flatMap((r) => r.findings), ...imported.findings]);
|
|
17
|
+
const found = dedupeFindings([...results.flatMap((r) => r.findings), ...imported.findings], executed.early?.submitted);
|
|
18
18
|
const coverage = coverageOf(plan.decisions, results, plan.unchanged, executed.matrix.limited ?? [], executed.notStarted);
|
|
19
19
|
emit({ type: "coverage_settled", coverage });
|
|
20
20
|
const remembered = applyMemory(found, plan.memory);
|
|
@@ -2,4 +2,4 @@ import type { Anchor } from "../anchor/anchor.js";
|
|
|
2
2
|
import type { Finding, FindingProvenance, ReportedFinding } from "../domain.js";
|
|
3
3
|
export declare function fingerprint(category: string, file: string, existingCode: string): string;
|
|
4
4
|
export declare function toFinding(reported: ReportedFinding, reviewer: string, provenance: FindingProvenance, anchor: Anchor, content?: string): Finding;
|
|
5
|
-
export declare function dedupeFindings(findings: readonly Finding[]): Finding[];
|
|
5
|
+
export declare function dedupeFindings(findings: readonly Finding[], checked?: ReadonlySet<string>): Finding[];
|
|
@@ -32,12 +32,16 @@ export function toFinding(reported, reviewer, provenance, anchor, content) {
|
|
|
32
32
|
return finding;
|
|
33
33
|
}
|
|
34
34
|
// The most severe copy wins whole: its title and explanation describe the
|
|
35
|
-
// severity it carries.
|
|
36
|
-
|
|
35
|
+
// severity it carries. Among equally severe copies the one verification
|
|
36
|
+
// already has (`checked`, by id) wins, so it is not checked twice.
|
|
37
|
+
export function dedupeFindings(findings, checked = new Set()) {
|
|
37
38
|
const byFingerprint = new Map();
|
|
38
39
|
for (const finding of findings) {
|
|
39
40
|
const existing = byFingerprint.get(finding.fingerprint);
|
|
40
|
-
|
|
41
|
+
const rank = existing && SEVERITY_RANK[finding.severity] - SEVERITY_RANK[existing.severity];
|
|
42
|
+
if (rank === undefined ||
|
|
43
|
+
rank > 0 ||
|
|
44
|
+
(rank === 0 && checked.has(finding.id) && !checked.has(existing?.id ?? ""))) {
|
|
41
45
|
byFingerprint.set(finding.fingerprint, finding);
|
|
42
46
|
}
|
|
43
47
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AgentRuntime, SyntaxChecker, Usage } from "../contracts.js";
|
|
2
|
+
import type { FindingFix, Severity } from "../domain.js";
|
|
3
|
+
import type { FixRejection } from "../fix/check.js";
|
|
4
|
+
import type { VcsAdapter } from "../vcs.js";
|
|
5
|
+
import type { ReviewOptions } from "./options.js";
|
|
6
|
+
export interface StoredFinding {
|
|
7
|
+
fingerprint: string;
|
|
8
|
+
reviewer: string;
|
|
9
|
+
severity: Severity;
|
|
10
|
+
category: string;
|
|
11
|
+
file: string;
|
|
12
|
+
title: string;
|
|
13
|
+
body: string;
|
|
14
|
+
suggestion?: string;
|
|
15
|
+
existingCode?: string;
|
|
16
|
+
lowConfidence?: boolean;
|
|
17
|
+
altered?: boolean;
|
|
18
|
+
}
|
|
19
|
+
type FixFindingOutcome = "proposed" | "rejected" | "not_fixable" | "stale" | "head_moved";
|
|
20
|
+
type FixFindingReason = FixRejection | "not_candidate";
|
|
21
|
+
export interface FixedFinding {
|
|
22
|
+
headSha: string;
|
|
23
|
+
outcome: FixFindingOutcome;
|
|
24
|
+
fix?: FindingFix;
|
|
25
|
+
reason?: FixFindingReason;
|
|
26
|
+
warnings: string[];
|
|
27
|
+
}
|
|
28
|
+
interface FixFindingOptions extends Pick<ReviewOptions, "effort" | "roles"> {
|
|
29
|
+
finding: StoredFinding;
|
|
30
|
+
vcs: VcsAdapter;
|
|
31
|
+
runtime: AgentRuntime;
|
|
32
|
+
syntax: SyntaxChecker;
|
|
33
|
+
expectedHead?: string;
|
|
34
|
+
maxCostUsd?: number;
|
|
35
|
+
signal: AbortSignal;
|
|
36
|
+
onUsage: (usage: Usage) => void;
|
|
37
|
+
}
|
|
38
|
+
export declare function fixFinding(options: FixFindingOptions): Promise<FixedFinding>;
|
|
39
|
+
export {};
|