@open-cr-agent/core 0.5.0 → 0.7.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/{pipeline → agent}/budget.d.ts +0 -1
- package/dist/{pipeline → agent}/budget.js +0 -1
- package/dist/agent/json.d.ts +1 -0
- package/dist/agent/json.js +11 -0
- package/dist/{pipeline → agent}/pool.d.ts +0 -1
- package/dist/{pipeline → agent}/pool.js +2 -2
- package/dist/{pipeline/agents.d.ts → agent/settings.d.ts} +9 -5
- package/dist/{pipeline/agents.js → agent/settings.js} +14 -6
- package/dist/{pipeline → agent}/usage.d.ts +0 -1
- package/dist/{pipeline → agent}/usage.js +0 -1
- package/dist/anchor/anchor.d.ts +0 -1
- package/dist/anchor/anchor.js +0 -1
- package/dist/anchor/match.d.ts +0 -1
- package/dist/anchor/match.js +5 -5
- package/dist/anchor/relocate.d.ts +1 -3
- package/dist/anchor/relocate.js +2 -3
- package/dist/at.d.ts +1 -0
- package/dist/at.js +11 -0
- package/dist/bounded-file.d.ts +12 -0
- package/dist/bounded-file.js +47 -0
- package/dist/bundle/bundle.d.ts +2 -2
- package/dist/bundle/bundle.js +3 -3
- package/dist/bundle/grouping.d.ts +0 -2
- package/dist/bundle/grouping.js +0 -1
- package/dist/bundle/runtime-grouper.d.ts +4 -0
- package/dist/{pipeline/helpers.js → bundle/runtime-grouper.js} +4 -14
- package/dist/contracts.d.ts +16 -15
- package/dist/contracts.js +6 -2
- package/dist/diff/hunks.d.ts +0 -1
- package/dist/diff/hunks.js +3 -3
- package/dist/diff/parse.d.ts +0 -1
- package/dist/diff/parse.js +5 -5
- package/dist/diff/quoted-path.d.ts +0 -1
- package/dist/diff/quoted-path.js +16 -16
- package/dist/domain.d.ts +14 -3
- package/dist/domain.js +2 -3
- package/dist/errors.d.ts +3 -2
- package/dist/errors.js +12 -1
- package/dist/hash.d.ts +1 -0
- package/dist/hash.js +6 -0
- package/dist/index.d.ts +27 -13
- package/dist/index.js +16 -6
- package/dist/internal.d.ts +10 -13
- package/dist/internal.js +10 -13
- package/dist/judge/judge.d.ts +1 -3
- package/dist/judge/judge.js +9 -9
- package/dist/judge/prompt.d.ts +0 -1
- package/dist/judge/prompt.js +0 -1
- package/dist/judge/verdict.d.ts +0 -2
- package/dist/judge/verdict.js +1 -2
- package/dist/memory/memory.d.ts +0 -1
- package/dist/memory/memory.js +2 -3
- package/dist/net/proxied-fetch.d.ts +0 -1
- package/dist/net/proxied-fetch.js +2 -2
- package/dist/pipeline/assemble-report.d.ts +21 -0
- package/dist/pipeline/assemble-report.js +98 -0
- package/dist/pipeline/check-stage.d.ts +12 -0
- package/dist/pipeline/check-stage.js +69 -0
- package/dist/pipeline/context.d.ts +2 -2
- package/dist/pipeline/context.js +8 -5
- package/dist/pipeline/coverage.d.ts +1 -2
- package/dist/pipeline/coverage.js +38 -17
- package/dist/pipeline/execute-stage.d.ts +25 -0
- package/dist/pipeline/execute-stage.js +130 -0
- package/dist/pipeline/execute.d.ts +11 -6
- package/dist/pipeline/execute.js +147 -59
- package/dist/pipeline/filter-stage.d.ts +15 -0
- package/dist/pipeline/filter-stage.js +45 -0
- package/dist/pipeline/findings.d.ts +0 -1
- package/dist/pipeline/findings.js +3 -3
- package/dist/pipeline/imports.d.ts +1 -2
- package/dist/pipeline/imports.js +1 -2
- package/dist/pipeline/matrix.d.ts +1 -9
- package/dist/pipeline/matrix.js +0 -1
- package/dist/pipeline/options.d.ts +66 -0
- package/dist/pipeline/options.js +8 -0
- package/dist/pipeline/plan-output.d.ts +89 -0
- package/dist/pipeline/plan-output.js +108 -0
- package/dist/pipeline/plan.d.ts +3 -5
- package/dist/pipeline/plan.js +10 -6
- package/dist/pipeline/preview.d.ts +23 -10
- package/dist/pipeline/preview.js +25 -5
- package/dist/pipeline/provenance.d.ts +4 -28
- package/dist/pipeline/provenance.js +2 -3
- package/dist/pipeline/resume.d.ts +22 -0
- package/dist/pipeline/resume.js +24 -0
- package/dist/pipeline/run-id.d.ts +0 -1
- package/dist/pipeline/run-id.js +0 -1
- package/dist/pipeline/run.d.ts +2 -49
- package/dist/pipeline/run.js +18 -274
- package/dist/pipeline/task.d.ts +5 -10
- package/dist/pipeline/task.js +10 -8
- package/dist/plugin/builtin.d.ts +1 -1
- package/dist/plugin/builtin.js +12 -3
- package/dist/plugin/host.d.ts +0 -1
- package/dist/plugin/host.js +0 -1
- package/dist/plugin/registry.d.ts +5 -5
- package/dist/plugin/registry.js +3 -4
- package/dist/plugin/types.d.ts +3 -6
- package/dist/plugin/types.js +0 -1
- package/dist/{pipeline → report}/output-schema.d.ts +95 -63
- package/dist/{pipeline → report}/output-schema.js +64 -42
- package/dist/report/output.d.ts +7 -0
- package/dist/report/output.js +214 -0
- package/dist/report/provenance.d.ts +25 -0
- package/dist/report/provenance.js +1 -0
- package/dist/report/read.d.ts +2 -0
- package/dist/report/read.js +36 -0
- package/dist/{pipeline → report}/report.d.ts +27 -4
- package/dist/{pipeline → report}/report.js +11 -3
- package/dist/report/serialize.d.ts +2 -0
- package/dist/report/serialize.js +26 -0
- package/dist/rereview/presence.d.ts +0 -1
- package/dist/rereview/presence.js +1 -2
- package/dist/rereview/quote.d.ts +0 -1
- package/dist/rereview/quote.js +2 -3
- package/dist/rereview/reconcile.d.ts +1 -2
- package/dist/rereview/reconcile.js +0 -1
- package/dist/review/impact.d.ts +0 -3
- package/dist/review/impact.js +2 -3
- package/dist/review/plan-phase.d.ts +1 -3
- package/dist/review/plan-phase.js +2 -3
- package/dist/review/prompt-text.d.ts +1 -2
- package/dist/review/prompt-text.js +1 -2
- package/dist/review/prompt.d.ts +0 -4
- package/dist/review/prompt.js +3 -4
- package/dist/review/reviewer.d.ts +0 -1
- package/dist/review/reviewer.js +0 -1
- package/dist/review/reviewers/agents-md.d.ts +0 -1
- package/dist/review/reviewers/agents-md.js +0 -1
- package/dist/review/reviewers/correctness.d.ts +0 -1
- package/dist/review/reviewers/correctness.js +0 -1
- package/dist/review/reviewers/docs.d.ts +0 -1
- package/dist/review/reviewers/docs.js +0 -1
- package/dist/review/reviewers/performance.d.ts +0 -1
- package/dist/review/reviewers/performance.js +0 -1
- package/dist/review/reviewers/scopes.d.ts +0 -1
- package/dist/review/reviewers/scopes.js +0 -1
- package/dist/review/reviewers/security.d.ts +0 -1
- package/dist/review/reviewers/security.js +0 -1
- package/dist/review/tools.d.ts +0 -1
- package/dist/review/tools.js +0 -1
- package/dist/rules/builtin/general.d.ts +0 -1
- package/dist/rules/builtin/general.js +0 -1
- package/dist/rules/builtin/go.d.ts +0 -1
- package/dist/rules/builtin/go.js +0 -1
- package/dist/rules/builtin/index.d.ts +0 -5
- package/dist/rules/builtin/index.js +1 -3
- package/dist/rules/builtin/java.d.ts +0 -1
- package/dist/rules/builtin/java.js +0 -1
- package/dist/rules/builtin/performance.d.ts +0 -1
- package/dist/rules/builtin/performance.js +0 -1
- package/dist/rules/builtin/python.d.ts +0 -1
- package/dist/rules/builtin/python.js +0 -1
- package/dist/rules/builtin/security.d.ts +0 -1
- package/dist/rules/builtin/security.js +0 -1
- package/dist/rules/builtin/typescript.d.ts +0 -1
- package/dist/rules/builtin/typescript.js +0 -1
- package/dist/rules/languages.d.ts +0 -1
- package/dist/rules/languages.js +0 -1
- package/dist/rules/repo-rules.d.ts +0 -7
- package/dist/rules/repo-rules.js +3 -4
- package/dist/rules/resolve.d.ts +0 -1
- package/dist/rules/resolve.js +0 -1
- package/dist/rules/rule-set.d.ts +0 -1
- package/dist/rules/rule-set.js +0 -1
- package/dist/runtime/attempt.d.ts +15 -2
- package/dist/runtime/attempt.js +47 -1
- package/dist/runtime/chain-runner.d.ts +18 -0
- package/dist/runtime/chain-runner.js +62 -0
- package/dist/runtime/effort-capability.d.ts +13 -0
- package/dist/runtime/effort-capability.js +69 -0
- package/dist/runtime/failback.d.ts +0 -10
- package/dist/runtime/failback.js +52 -13
- package/dist/runtime/models.d.ts +1 -3
- package/dist/runtime/models.js +14 -13
- package/dist/runtime/quota.d.ts +1 -1
- package/dist/runtime/quota.js +3 -2
- package/dist/runtime/tools.d.ts +0 -17
- package/dist/runtime/tools.js +3 -4
- package/dist/sarif/candidates.d.ts +2 -2
- package/dist/sarif/candidates.js +0 -1
- package/dist/sarif/schema.d.ts +2 -3
- package/dist/sarif/schema.js +4 -5
- package/dist/select/patterns.d.ts +0 -1
- package/dist/select/patterns.js +0 -1
- package/dist/select/select.d.ts +1 -1
- package/dist/select/select.js +16 -3
- package/dist/session/jsonl.d.ts +4 -4
- package/dist/session/jsonl.js +14 -8
- package/dist/session/resume-read.d.ts +2 -0
- package/dist/session/resume-read.js +128 -0
- package/dist/session/seal.d.ts +5 -0
- package/dist/session/seal.js +24 -0
- package/dist/triage.d.ts +2 -3
- package/dist/triage.js +1 -2
- package/dist/vcs.d.ts +14 -0
- package/dist/vcs.js +1 -0
- package/dist/verify/prompt.d.ts +0 -7
- package/dist/verify/prompt.js +1 -2
- package/dist/verify/verify.d.ts +2 -4
- package/dist/verify/verify.js +4 -5
- package/package.json +1 -1
- package/dist/pipeline/helpers.d.ts +0 -7
- package/dist/pipeline/output.d.ts +0 -79
- package/dist/pipeline/output.js +0 -132
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { roleCall } from "../agent/settings.js";
|
|
2
|
+
import { judgeFindings } from "../judge/judge.js";
|
|
3
|
+
import { stillOpen } from "../rereview/reconcile.js";
|
|
4
|
+
import { markUnchecked, verifyFindings } from "../verify/verify.js";
|
|
5
|
+
import { REVIEW_DEFAULTS } from "./options.js";
|
|
6
|
+
// Verify fact-checks the findings, then the judge merges, filters and
|
|
7
|
+
// recalibrates them and gives the verdict.
|
|
8
|
+
export async function checkStage(filtered, context) {
|
|
9
|
+
const verification = await verify(filtered, context);
|
|
10
|
+
const judged = await judge(verification, filtered, context);
|
|
11
|
+
return {
|
|
12
|
+
verification,
|
|
13
|
+
judged,
|
|
14
|
+
usage: [...verification.usage, ...judged.usage],
|
|
15
|
+
warnings: [...verification.warnings, ...judged.warnings],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async function verify({ reconciled }, { options, plan, budget, signal, emit }) {
|
|
19
|
+
if (options.stages?.verify === false) {
|
|
20
|
+
return {
|
|
21
|
+
checked: 0,
|
|
22
|
+
kept: markUnchecked(reconciled.findings),
|
|
23
|
+
refuted: [],
|
|
24
|
+
missed: [],
|
|
25
|
+
usage: [],
|
|
26
|
+
warnings: [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const verification = await verifyFindings(reconciled.findings, {
|
|
30
|
+
runtime: options.runtime,
|
|
31
|
+
diffs: plan.selected,
|
|
32
|
+
context: plan.context,
|
|
33
|
+
signal,
|
|
34
|
+
concurrency: options.limits?.concurrency ?? REVIEW_DEFAULTS.concurrency,
|
|
35
|
+
budget,
|
|
36
|
+
call: roleCall("verifier", options),
|
|
37
|
+
});
|
|
38
|
+
if (verification.checked > 0) {
|
|
39
|
+
emit({
|
|
40
|
+
type: "verification_finished",
|
|
41
|
+
checked: verification.checked,
|
|
42
|
+
refuted: verification.refuted,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return verification;
|
|
46
|
+
}
|
|
47
|
+
async function judge(verification, { reconciled, nothingReviewed }, { options, plan, budget, signal, emit }) {
|
|
48
|
+
const wanted = options.stages?.judge !== false && verification.kept.length > 0;
|
|
49
|
+
const affordable = !budget.exhausted();
|
|
50
|
+
const judged = await judgeFindings(verification.kept, {
|
|
51
|
+
runtime: options.runtime,
|
|
52
|
+
changeRequest: plan.changeRequest,
|
|
53
|
+
tier: plan.tier,
|
|
54
|
+
signal,
|
|
55
|
+
call: roleCall("judge", options),
|
|
56
|
+
enabled: wanted && affordable,
|
|
57
|
+
keepDropped: options.mode?.ultra === true,
|
|
58
|
+
carried: stillOpen(reconciled),
|
|
59
|
+
});
|
|
60
|
+
if (wanted && !affordable) {
|
|
61
|
+
judged.warnings.push(`spend limit of $${options.limits?.maxCostUsd} reached: findings were not judged`);
|
|
62
|
+
}
|
|
63
|
+
if (!nothingReviewed) {
|
|
64
|
+
emit(judged.decisions
|
|
65
|
+
? { type: "judge_finished", verdict: judged.verdict, judgement: judged.decisions }
|
|
66
|
+
: { type: "judge_finished", verdict: judged.verdict });
|
|
67
|
+
}
|
|
68
|
+
return judged;
|
|
69
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ReviewContext
|
|
1
|
+
import type { ReviewContext } from "../contracts.js";
|
|
2
2
|
import type { FileDiff } from "../domain.js";
|
|
3
3
|
import { OcraError } from "../errors.js";
|
|
4
|
+
import type { VcsAdapter } from "../vcs.js";
|
|
4
5
|
export declare class AccessDeniedError extends OcraError {
|
|
5
6
|
constructor(message: string);
|
|
6
7
|
}
|
|
7
8
|
export declare function reviewContext(vcs: VcsAdapter, diffs: readonly FileDiff[]): ReviewContext;
|
|
8
|
-
//# sourceMappingURL=context.d.ts.map
|
package/dist/pipeline/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
2
|
import { OcraError } from "../errors.js";
|
|
3
|
-
import { isSecretPath } from "../select/select.js";
|
|
3
|
+
import { foldPath, isSecretPath } from "../select/select.js";
|
|
4
4
|
export class AccessDeniedError extends OcraError {
|
|
5
5
|
constructor(message) {
|
|
6
6
|
super("ACCESS_DENIED", message);
|
|
@@ -18,10 +18,12 @@ export function reviewContext(vcs, diffs) {
|
|
|
18
18
|
const searches = new Map();
|
|
19
19
|
// A file renamed away from a secret name still holds the secret, and
|
|
20
20
|
// selection already excludes it from review for that reason.
|
|
21
|
-
const renamedSecrets = new Set(diffs
|
|
21
|
+
const renamedSecrets = new Set(diffs
|
|
22
|
+
.filter((d) => d.newPath !== d.oldPath && isSecretPath(d.oldPath))
|
|
23
|
+
.map((d) => foldPath(d.newPath)));
|
|
22
24
|
const isReadable = (path) => {
|
|
23
25
|
const normalized = normalize(path);
|
|
24
|
-
return normalized !== undefined && isAllowed(normalized) && !renamedSecrets.has(normalized);
|
|
26
|
+
return (normalized !== undefined && isAllowed(normalized) && !renamedSecrets.has(foldPath(normalized)));
|
|
25
27
|
};
|
|
26
28
|
const allowedPath = (path) => {
|
|
27
29
|
const normalized = normalize(path);
|
|
@@ -59,8 +61,10 @@ export function reviewContext(vcs, diffs) {
|
|
|
59
61
|
},
|
|
60
62
|
};
|
|
61
63
|
}
|
|
64
|
+
// Names are compared folded: a case-insensitive file system opens a file
|
|
65
|
+
// under every spelling that folds to its name.
|
|
62
66
|
function isAllowed(normalized) {
|
|
63
|
-
const segments = normalized
|
|
67
|
+
const segments = foldPath(normalized).split("/");
|
|
64
68
|
return !segments.includes(".git") && !isSecretPath(normalized);
|
|
65
69
|
}
|
|
66
70
|
function normalize(path) {
|
|
@@ -73,4 +77,3 @@ function normalize(path) {
|
|
|
73
77
|
return undefined;
|
|
74
78
|
return unified.replace(/^\.\//, "");
|
|
75
79
|
}
|
|
76
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import type { CoverageEntry } from "../report/report.js";
|
|
1
2
|
import type { FileDecision } from "../select/select.js";
|
|
2
3
|
import type { JobResult } from "./execute.js";
|
|
3
4
|
import type { MatrixCell } from "./matrix.js";
|
|
4
|
-
import type { CoverageEntry } from "./report.js";
|
|
5
5
|
export declare function coverageOf(decisions: readonly FileDecision[], results: readonly JobResult[], unchanged: ReadonlySet<string>, limited: readonly MatrixCell[], notStarted: ReadonlySet<string>): CoverageEntry[];
|
|
6
|
-
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -1,36 +1,41 @@
|
|
|
1
|
+
import { at } from "../at.js";
|
|
2
|
+
// How far one reviewer got with a file, best first: under --ultra one sample
|
|
3
|
+
// that called the done tool is enough. Ranked by how actionable it is, a cut-
|
|
4
|
+
// off at the step cap above a stop with steps left.
|
|
5
|
+
const PROGRESS = ["done", "step_cap", "stopped_early", "none"];
|
|
1
6
|
export function coverageOf(decisions, results, unchanged, limited, notStarted) {
|
|
2
7
|
// A file is reviewed when every reviewer assigned to it finished at least
|
|
3
|
-
// one of its tasks
|
|
4
|
-
//
|
|
5
|
-
// started (the task or spend limit, a cancelled run)
|
|
6
|
-
|
|
8
|
+
// one of its tasks with the done tool. One whose tasks finished without it
|
|
9
|
+
// makes the file "incomplete"; one whose task failed makes it "failed"; one
|
|
10
|
+
// whose task never started (the task or spend limit, a cancelled run)
|
|
11
|
+
// makes it "unreviewed".
|
|
12
|
+
const progress = new Map();
|
|
7
13
|
const ran = new Set();
|
|
8
14
|
const key = (reviewer, file) => `${reviewer}\0${file}`;
|
|
9
15
|
for (const { outcome } of results) {
|
|
10
16
|
const started = !notStarted.has(outcome.taskId);
|
|
17
|
+
const reached = outcome.status !== "completed" ? "none" : (outcome.ended ?? "done");
|
|
11
18
|
for (const file of outcome.files) {
|
|
12
19
|
const k = key(outcome.reviewer, file);
|
|
13
20
|
if (started)
|
|
14
21
|
ran.add(k);
|
|
15
|
-
|
|
22
|
+
progress.set(k, better(progress.get(k) ?? "none", reached));
|
|
16
23
|
}
|
|
17
24
|
}
|
|
18
25
|
for (const cell of limited) {
|
|
19
26
|
for (const f of cell.bundle.files) {
|
|
20
27
|
const k = key(cell.reviewer.id, f.newPath);
|
|
21
|
-
if (!
|
|
22
|
-
|
|
28
|
+
if (!progress.has(k))
|
|
29
|
+
progress.set(k, "none");
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
const status = new Map();
|
|
26
|
-
for (const [k,
|
|
27
|
-
const
|
|
28
|
-
const now =
|
|
29
|
-
const before = status.get(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
status.set(file, now);
|
|
33
|
-
}
|
|
33
|
+
for (const [k, reached] of progress) {
|
|
34
|
+
const path = at(k.split("\0"), 1);
|
|
35
|
+
const now = fileStatus(path, reached, ran.has(k));
|
|
36
|
+
const before = status.get(path);
|
|
37
|
+
if (!before || RANK[now.status] > RANK[before.status])
|
|
38
|
+
status.set(path, now);
|
|
34
39
|
}
|
|
35
40
|
return decisions.map((d) => {
|
|
36
41
|
const path = d.diff.newPath;
|
|
@@ -38,7 +43,23 @@ export function coverageOf(decisions, results, unchanged, limited, notStarted) {
|
|
|
38
43
|
return { path, status: "excluded", reason: d.reason };
|
|
39
44
|
if (unchanged.has(path))
|
|
40
45
|
return { path, status: "unchanged" };
|
|
41
|
-
return
|
|
46
|
+
return status.get(path) ?? { path, status: "unreviewed" };
|
|
42
47
|
});
|
|
43
48
|
}
|
|
44
|
-
|
|
49
|
+
// A file takes its worst reviewer's status.
|
|
50
|
+
const RANK = {
|
|
51
|
+
reviewed: 0,
|
|
52
|
+
unreviewed: 1,
|
|
53
|
+
incomplete: 2,
|
|
54
|
+
failed: 3,
|
|
55
|
+
};
|
|
56
|
+
function better(a, b) {
|
|
57
|
+
return PROGRESS.indexOf(a) <= PROGRESS.indexOf(b) ? a : b;
|
|
58
|
+
}
|
|
59
|
+
function fileStatus(path, reached, ran) {
|
|
60
|
+
if (reached === "done")
|
|
61
|
+
return { path, status: "reviewed" };
|
|
62
|
+
if (reached === "none")
|
|
63
|
+
return { path, status: ran ? "failed" : "unreviewed" };
|
|
64
|
+
return { path, status: "incomplete", ended: reached };
|
|
65
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type SpendTracker } from "../agent/budget.js";
|
|
2
|
+
import type { Usage } from "../contracts.js";
|
|
3
|
+
import type { ReviewEvent } from "../report/report.js";
|
|
4
|
+
import type { ReviewerDefinition } from "../review/reviewer.js";
|
|
5
|
+
import { type JobResult } from "./execute.js";
|
|
6
|
+
import { type ReviewMatrix } from "./matrix.js";
|
|
7
|
+
import { type ReviewHooks, type ReviewOptions } from "./options.js";
|
|
8
|
+
import type { ReviewPlan } from "./plan.js";
|
|
9
|
+
export interface StageContext {
|
|
10
|
+
options: ReviewOptions & ReviewHooks;
|
|
11
|
+
plan: ReviewPlan;
|
|
12
|
+
budget: SpendTracker;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
emit: (event: ReviewEvent) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface ExecuteStage {
|
|
17
|
+
matrix: ReviewMatrix;
|
|
18
|
+
results: JobResult[];
|
|
19
|
+
notStarted: ReadonlySet<string>;
|
|
20
|
+
relocations: readonly Usage[];
|
|
21
|
+
usage(): Usage[];
|
|
22
|
+
warnings: string[];
|
|
23
|
+
reviewLimitReached(): boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function executeStage(reviewers: readonly ReviewerDefinition[], context: StageContext): Promise<ExecuteStage>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { SpendLimitReached } from "../agent/budget.js";
|
|
2
|
+
import { mapWithConcurrency } from "../agent/pool.js";
|
|
3
|
+
import { roleCall } from "../agent/settings.js";
|
|
4
|
+
import { emptyUsage } from "../agent/usage.js";
|
|
5
|
+
import { runtimeRelocator } from "../anchor/relocate.js";
|
|
6
|
+
import { jobKey, reuseJob, runJob } from "./execute.js";
|
|
7
|
+
import { DEFAULT_MAX_TASKS, planTasks } from "./matrix.js";
|
|
8
|
+
import { MAX_TIMER_MS, REVIEW_DEFAULTS } from "./options.js";
|
|
9
|
+
import { reusePool } from "./resume.js";
|
|
10
|
+
// One agent task per (bundle, reviewer) cell of the matrix, within the task
|
|
11
|
+
// limit, the run's signal and the review share of the spend limit.
|
|
12
|
+
export async function executeStage(reviewers, context) {
|
|
13
|
+
const { options, plan, emit } = context;
|
|
14
|
+
const matrix = planTasks(plan.bundles, reviewers, plan.tier, options.reviewerOverrides, {
|
|
15
|
+
ultra: options.mode?.ultra === true,
|
|
16
|
+
...(options.limits?.maxTasks !== undefined ? { maxTasks: options.limits?.maxTasks } : {}),
|
|
17
|
+
hasGuidelines: Boolean(plan.guidelines?.trim()),
|
|
18
|
+
});
|
|
19
|
+
const warnings = [];
|
|
20
|
+
const limited = matrix.skipped.filter((s) => s.reason === "task_limit").length;
|
|
21
|
+
if (limited > 0) {
|
|
22
|
+
warnings.push(`task limit of ${options.limits?.maxTasks ?? DEFAULT_MAX_TASKS} reached: ${limited} review task(s) skipped; their files are reported as not reviewed`);
|
|
23
|
+
}
|
|
24
|
+
emit({ type: "matrix_planned", tasks: matrix.cells.length, skipped: matrix.skipped });
|
|
25
|
+
const relocations = [];
|
|
26
|
+
const spendLimit = new AbortController();
|
|
27
|
+
const execute = executeOptions(context, relocations, spendLimit);
|
|
28
|
+
const resume = options.resume;
|
|
29
|
+
const pool = reusePool(resume);
|
|
30
|
+
if (resume)
|
|
31
|
+
execute.reuse = { pool, runId: resume.runId };
|
|
32
|
+
const notStarted = new Set();
|
|
33
|
+
let unaffordable = 0;
|
|
34
|
+
const results = await mapWithConcurrency(matrix.cells, options.limits?.concurrency ?? REVIEW_DEFAULTS.concurrency, async (cell) => {
|
|
35
|
+
// Once the run is cancelled or timed out, remaining cells are not started.
|
|
36
|
+
if (context.signal.aborted) {
|
|
37
|
+
notStarted.add(cell.taskId);
|
|
38
|
+
return skipCell(cell, "run cancelled before this task started", emit);
|
|
39
|
+
}
|
|
40
|
+
const key = jobKey(cell, plan, execute);
|
|
41
|
+
const reused = await reuseJob(cell, plan, execute, key);
|
|
42
|
+
if (reused)
|
|
43
|
+
return reused;
|
|
44
|
+
if (context.budget.reviewExhausted()) {
|
|
45
|
+
notStarted.add(cell.taskId);
|
|
46
|
+
unaffordable += 1;
|
|
47
|
+
return skipCell(cell, `spend limit of $${options.limits?.maxCostUsd} reached`, emit);
|
|
48
|
+
}
|
|
49
|
+
return runJob(cell, plan, execute, key);
|
|
50
|
+
});
|
|
51
|
+
if (unaffordable > 0) {
|
|
52
|
+
warnings.push(`spend limit of $${options.limits?.maxCostUsd} reached: ${unaffordable} review task(s) did not start; their files are reported as not reviewed`);
|
|
53
|
+
}
|
|
54
|
+
if (resume)
|
|
55
|
+
warnings.push(...resumeWarnings(resume.runId, pool.unused()));
|
|
56
|
+
warnings.push(...results.flatMap((r) => r.warnings));
|
|
57
|
+
return {
|
|
58
|
+
matrix,
|
|
59
|
+
results,
|
|
60
|
+
notStarted,
|
|
61
|
+
relocations,
|
|
62
|
+
usage: () => [...results.map((r) => r.usage), ...relocations],
|
|
63
|
+
warnings,
|
|
64
|
+
reviewLimitReached: () => spendLimit.signal.aborted || unaffordable > 0,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function executeOptions({ options, budget, signal, emit }, relocations, spendLimit) {
|
|
68
|
+
const relocator = relocatorOf(options, signal, (u) => {
|
|
69
|
+
relocations.push(u);
|
|
70
|
+
budget.add(u);
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
runtime: options.runtime,
|
|
74
|
+
taskTimeoutMs: Math.min(options.limits?.taskTimeoutMs ?? REVIEW_DEFAULTS.taskTimeoutMs, MAX_TIMER_MS),
|
|
75
|
+
abortGraceMs: options.abortGraceMs,
|
|
76
|
+
// Past the spend limit a quote that does not match stays file-level.
|
|
77
|
+
relocate: relocator &&
|
|
78
|
+
(async (request) => (budget.exhausted() ? undefined : relocator(request))),
|
|
79
|
+
ultra: options.mode?.ultra === true,
|
|
80
|
+
plans: new Map(),
|
|
81
|
+
agents: options,
|
|
82
|
+
keyInputs: keyInputs(options),
|
|
83
|
+
emit,
|
|
84
|
+
// Tasks report spend while they run, so the one that uses up the review
|
|
85
|
+
// share stops every task still running, not only the ones not yet started.
|
|
86
|
+
onUsage: (usage) => {
|
|
87
|
+
budget.add(usage);
|
|
88
|
+
if (budget.reviewExhausted() && !spendLimit.signal.aborted) {
|
|
89
|
+
spendLimit.abort(new SpendLimitReached(options.limits?.maxCostUsd ?? 0));
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
signal: AbortSignal.any([signal, spendLimit.signal]),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// The caller's build and sampling: an earlier run made with another ocra or
|
|
96
|
+
// other sampling settings answered a different question.
|
|
97
|
+
function keyInputs({ identity }) {
|
|
98
|
+
const provenance = identity?.provenance;
|
|
99
|
+
return provenance && { ocraVersion: provenance.ocraVersion, sampling: provenance.sampling };
|
|
100
|
+
}
|
|
101
|
+
// Reused tasks are named in report.tasks (reusedFrom); only what could not be
|
|
102
|
+
// reused is worth a warning.
|
|
103
|
+
function resumeWarnings(runId, unused) {
|
|
104
|
+
if (unused === 0)
|
|
105
|
+
return [];
|
|
106
|
+
return [
|
|
107
|
+
`resumed run ${runId}: ${unused} completed task(s) not reused, their inputs changed (commits, configuration, prompts or ocra version)`,
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
function relocatorOf(options, signal, onUsage) {
|
|
111
|
+
if (options.relocate === false)
|
|
112
|
+
return undefined;
|
|
113
|
+
return (options.relocate ??
|
|
114
|
+
runtimeRelocator(options.runtime, signal, onUsage, roleCall("helper", options)));
|
|
115
|
+
}
|
|
116
|
+
function skipCell(cell, reason, emit) {
|
|
117
|
+
const outcome = {
|
|
118
|
+
taskId: cell.taskId,
|
|
119
|
+
reviewer: cell.reviewer.id,
|
|
120
|
+
bundle: cell.bundle.label,
|
|
121
|
+
files: cell.bundle.files.map((f) => f.newPath),
|
|
122
|
+
status: "cancelled",
|
|
123
|
+
error: reason,
|
|
124
|
+
findings: 0,
|
|
125
|
+
durationMs: 0,
|
|
126
|
+
usage: emptyUsage(),
|
|
127
|
+
};
|
|
128
|
+
emit({ type: "task_finished", outcome });
|
|
129
|
+
return { outcome, findings: [], usage: emptyUsage(), warnings: [] };
|
|
130
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { type AgentSettings } from "../agent/settings.js";
|
|
1
2
|
import { type AnchorContext } from "../anchor/anchor.js";
|
|
2
3
|
import type { AgentRuntime, Usage } from "../contracts.js";
|
|
3
4
|
import type { Finding } from "../domain.js";
|
|
5
|
+
import type { ReviewEvent, TaskOutcome } from "../report/report.js";
|
|
4
6
|
import { planBundle } from "../review/plan-phase.js";
|
|
5
|
-
import { type AgentSettings } from "./agents.js";
|
|
6
7
|
import type { MatrixCell } from "./matrix.js";
|
|
7
8
|
import type { ReviewPlan } from "./plan.js";
|
|
8
|
-
import type {
|
|
9
|
+
import type { ReusePool } from "./resume.js";
|
|
9
10
|
export interface JobResult {
|
|
10
11
|
outcome: TaskOutcome;
|
|
11
12
|
findings: Finding[];
|
|
@@ -23,13 +24,17 @@ export interface ExecuteOptions {
|
|
|
23
24
|
onUsage?: ((usage: Usage) => void) | undefined;
|
|
24
25
|
signal: AbortSignal;
|
|
25
26
|
agents?: AgentSettings;
|
|
27
|
+
reuse?: {
|
|
28
|
+
pool: ReusePool;
|
|
29
|
+
runId: string;
|
|
30
|
+
};
|
|
31
|
+
keyInputs?: unknown;
|
|
26
32
|
}
|
|
27
33
|
type PlannedBundle = Awaited<ReturnType<typeof planBundle>>;
|
|
28
|
-
export declare const PLAN_MIN_FILES = 5;
|
|
29
|
-
export declare const PLAN_MIN_PATCH_CHARS = 40000;
|
|
30
34
|
export declare function isLargeBundle(files: readonly {
|
|
31
35
|
patch: string;
|
|
32
36
|
}[]): boolean;
|
|
33
|
-
export declare function
|
|
37
|
+
export declare function jobKey(job: MatrixCell, plan: ReviewPlan, options: ExecuteOptions): string;
|
|
38
|
+
export declare function runJob(job: MatrixCell, plan: ReviewPlan, options: ExecuteOptions, key: string): Promise<JobResult>;
|
|
39
|
+
export declare function reuseJob(job: MatrixCell, plan: ReviewPlan, options: ExecuteOptions, key: string): Promise<JobResult | undefined>;
|
|
34
40
|
export {};
|
|
35
|
-
//# sourceMappingURL=execute.d.ts.map
|
package/dist/pipeline/execute.js
CHANGED
|
@@ -1,57 +1,35 @@
|
|
|
1
|
+
import { reviewerCall } from "../agent/settings.js";
|
|
2
|
+
import { addUsage, emptyUsage } from "../agent/usage.js";
|
|
1
3
|
import { anchorFinding } from "../anchor/anchor.js";
|
|
2
4
|
import { memoryFor } from "../memory/memory.js";
|
|
3
5
|
import { findCallers } from "../review/impact.js";
|
|
4
6
|
import { planBundle } from "../review/plan-phase.js";
|
|
5
7
|
import { buildReviewPrompt } from "../review/prompt.js";
|
|
6
8
|
import { resolveRules } from "../rules/resolve.js";
|
|
7
|
-
import { reviewerCall } from "./agents.js";
|
|
8
9
|
import { toFinding } from "./findings.js";
|
|
10
|
+
import { stableHash } from "./provenance.js";
|
|
9
11
|
import { executeTask } from "./task.js";
|
|
10
|
-
import { addUsage } from "./usage.js";
|
|
11
12
|
// In default mode only bundles large enough that a reviewer's 30 steps may
|
|
12
13
|
// not cover them get a plan phase; --ultra plans every task.
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const PLAN_MIN_FILES = 5;
|
|
15
|
+
const PLAN_MIN_PATCH_CHARS = 40_000;
|
|
15
16
|
export function isLargeBundle(files) {
|
|
16
17
|
const chars = files.reduce((sum, f) => sum + f.patch.length, 0);
|
|
17
18
|
return files.length >= PLAN_MIN_FILES || chars >= PLAN_MIN_PATCH_CHARS;
|
|
18
19
|
}
|
|
20
|
+
// The key of a cell's inputs (taskKey), under which its answer is reported
|
|
21
|
+
// and an earlier run's answer is reused.
|
|
22
|
+
export function jobKey(job, plan, options) {
|
|
23
|
+
const call = reviewerCall(job.reviewer, options.agents ?? {});
|
|
24
|
+
return taskKey(job, plan, buildReviewPrompt(promptInput(job, plan)), call, options);
|
|
25
|
+
}
|
|
19
26
|
// Runs one (bundle, reviewer) cell and anchors what it reports.
|
|
20
|
-
export async function runJob(job, plan, options) {
|
|
27
|
+
export async function runJob(job, plan, options, key) {
|
|
21
28
|
const { emit } = options;
|
|
22
29
|
const files = job.bundle.files.map((f) => f.newPath);
|
|
23
|
-
const input = {
|
|
24
|
-
reviewer: job.reviewer,
|
|
25
|
-
changeRequest: plan.changeRequest,
|
|
26
|
-
changedFiles: plan.selected,
|
|
27
|
-
bundle: job.bundle.files,
|
|
28
|
-
rules: resolveRules(files, plan.repoRules, job.reviewer.rules),
|
|
29
|
-
guidelines: plan.guidelines,
|
|
30
|
-
accepted: memoryFor(files, plan.memory),
|
|
31
|
-
};
|
|
32
30
|
const call = reviewerCall(job.reviewer, options.agents ?? {});
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
let prompt = buildReviewPrompt(input);
|
|
36
|
-
if (options.ultra || isLargeBundle(job.bundle.files)) {
|
|
37
|
-
const callers = options.ultra ? await findCallers(job.bundle.files, plan.context) : [];
|
|
38
|
-
const key = `${job.reviewer.id}\0${job.bundle.label}`;
|
|
39
|
-
const shared = options.plans?.get(key);
|
|
40
|
-
const planning = shared ??
|
|
41
|
-
planBundle(options.runtime, job.reviewer, buildReviewPrompt({ ...input, forPlanning: true }), options.signal, call);
|
|
42
|
-
if (!shared)
|
|
43
|
-
options.plans?.set(key, planning);
|
|
44
|
-
const planned = await planning;
|
|
45
|
-
// The sample that made the call pays for it and reports its warning.
|
|
46
|
-
if (!shared) {
|
|
47
|
-
extraUsage.push(...planned.usage);
|
|
48
|
-
for (const usage of planned.usage)
|
|
49
|
-
options.onUsage?.(usage);
|
|
50
|
-
if (planned.warning)
|
|
51
|
-
extraWarnings.push(planned.warning);
|
|
52
|
-
}
|
|
53
|
-
prompt = buildReviewPrompt({ ...input, callers, plan: planned.plan });
|
|
54
|
-
}
|
|
31
|
+
const input = promptInput(job, plan);
|
|
32
|
+
const prepared = await preparePrompt(job, plan, options, call, input);
|
|
55
33
|
emit({
|
|
56
34
|
type: "task_started",
|
|
57
35
|
taskId: job.taskId,
|
|
@@ -65,17 +43,135 @@ export async function runJob(job, plan, options) {
|
|
|
65
43
|
reviewer: job.reviewer.id,
|
|
66
44
|
modelTier: job.reviewer.modelTier,
|
|
67
45
|
...call,
|
|
68
|
-
systemPrompt: prompt.system,
|
|
69
|
-
userPrompt: prompt.user,
|
|
46
|
+
systemPrompt: prepared.prompt.system,
|
|
47
|
+
userPrompt: prepared.prompt.user,
|
|
70
48
|
context: plan.context,
|
|
71
49
|
timeoutMs: options.taskTimeoutMs,
|
|
72
50
|
}, options.signal, {
|
|
73
|
-
onProgress: (message) => emit({
|
|
51
|
+
onProgress: (message, attempt) => emit({
|
|
52
|
+
type: "task_progress",
|
|
53
|
+
taskId: job.taskId,
|
|
54
|
+
message,
|
|
55
|
+
...(attempt ? { attempt } : {}),
|
|
56
|
+
}),
|
|
74
57
|
onUsage: options.onUsage,
|
|
75
58
|
category: job.reviewer.category,
|
|
76
59
|
abortGraceMs: options.abortGraceMs,
|
|
77
60
|
});
|
|
78
|
-
const
|
|
61
|
+
const anchored = await anchorFindings(job, plan, options, result.findings);
|
|
62
|
+
const warnings = [...prepared.warnings, ...result.warnings, ...anchored.warnings];
|
|
63
|
+
const usage = prepared.usage.reduce(addUsage, result.usage);
|
|
64
|
+
const outcome = {
|
|
65
|
+
taskId: job.taskId,
|
|
66
|
+
reviewer: job.reviewer.id,
|
|
67
|
+
bundle: job.bundle.label,
|
|
68
|
+
files,
|
|
69
|
+
status: result.status,
|
|
70
|
+
findings: anchored.findings.length,
|
|
71
|
+
durationMs: Date.now() - started,
|
|
72
|
+
usage,
|
|
73
|
+
};
|
|
74
|
+
if (result.error !== undefined)
|
|
75
|
+
outcome.error = result.error;
|
|
76
|
+
if (result.ended !== undefined)
|
|
77
|
+
outcome.ended = result.ended;
|
|
78
|
+
// A task cut off before it finished (ADR-0030) is reviewed again, not reused.
|
|
79
|
+
if (result.status === "completed" && result.ended === undefined) {
|
|
80
|
+
emit({ type: "task_reported", taskId: job.taskId, key, findings: result.findings });
|
|
81
|
+
}
|
|
82
|
+
emit({ type: "task_finished", outcome });
|
|
83
|
+
return { outcome, findings: anchored.findings, usage, warnings };
|
|
84
|
+
}
|
|
85
|
+
// The task's review prompt before a plan phase or callers are added.
|
|
86
|
+
function promptInput(job, plan) {
|
|
87
|
+
const files = job.bundle.files.map((f) => f.newPath);
|
|
88
|
+
return {
|
|
89
|
+
reviewer: job.reviewer,
|
|
90
|
+
changeRequest: plan.changeRequest,
|
|
91
|
+
changedFiles: plan.selected,
|
|
92
|
+
bundle: job.bundle.files,
|
|
93
|
+
rules: resolveRules(files, plan.repoRules, job.reviewer.rules),
|
|
94
|
+
guidelines: plan.guidelines,
|
|
95
|
+
accepted: memoryFor(files, plan.memory),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Everything a task's answer depends on, so an earlier answer is reused only
|
|
99
|
+
// for the same question: the prompt (instructions, change, bundle, rules,
|
|
100
|
+
// guidelines, memory), the commits (the code around the change, which the
|
|
101
|
+
// reviewer reads but the prompt does not hold), the model chain and effort,
|
|
102
|
+
// --ultra (which adds a plan phase and callers, both derived from the same
|
|
103
|
+
// inputs), and the caller's build and sampling.
|
|
104
|
+
function taskKey(job, plan, prompt, call, options) {
|
|
105
|
+
const { baseSha, headSha } = plan.changeRequest;
|
|
106
|
+
return stableHash({
|
|
107
|
+
prompt: { system: prompt.system, user: prompt.user },
|
|
108
|
+
commits: { base: baseSha, head: headSha },
|
|
109
|
+
tier: job.reviewer.modelTier,
|
|
110
|
+
chain: call.models ?? options.agents?.models?.[job.reviewer.modelTier],
|
|
111
|
+
effort: call.effort,
|
|
112
|
+
ultra: options.ultra === true,
|
|
113
|
+
inputs: options.keyInputs,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// A cell an earlier run already answered, when the reuse pool holds an answer
|
|
117
|
+
// under its key: the reported findings are anchored again (the change is the
|
|
118
|
+
// same, so they land where they did) and it costs nothing, so the stage takes
|
|
119
|
+
// it before the spend limit; its outcome says where it came from. Undefined
|
|
120
|
+
// when the cell has to run.
|
|
121
|
+
export async function reuseJob(job, plan, options, key) {
|
|
122
|
+
const earlier = options.reuse?.pool.take(key);
|
|
123
|
+
if (!earlier || !options.reuse)
|
|
124
|
+
return undefined;
|
|
125
|
+
const { runId } = options.reuse;
|
|
126
|
+
const { emit } = options;
|
|
127
|
+
const files = job.bundle.files.map((f) => f.newPath);
|
|
128
|
+
emit({
|
|
129
|
+
type: "task_started",
|
|
130
|
+
taskId: job.taskId,
|
|
131
|
+
reviewer: job.reviewer.id,
|
|
132
|
+
bundle: job.bundle.label,
|
|
133
|
+
files,
|
|
134
|
+
});
|
|
135
|
+
const anchored = await anchorFindings(job, plan, options, earlier.findings);
|
|
136
|
+
emit({ type: "task_reported", taskId: job.taskId, key, findings: [...earlier.findings] });
|
|
137
|
+
const { error: _error, ...prior } = earlier.outcome;
|
|
138
|
+
const outcome = {
|
|
139
|
+
...prior,
|
|
140
|
+
taskId: job.taskId,
|
|
141
|
+
reviewer: job.reviewer.id,
|
|
142
|
+
bundle: job.bundle.label,
|
|
143
|
+
files,
|
|
144
|
+
status: "completed",
|
|
145
|
+
findings: anchored.findings.length,
|
|
146
|
+
reusedFrom: earlier.outcome.reusedFrom ?? runId,
|
|
147
|
+
};
|
|
148
|
+
emit({ type: "task_finished", outcome });
|
|
149
|
+
return { outcome, findings: anchored.findings, usage: emptyUsage(), warnings: anchored.warnings };
|
|
150
|
+
}
|
|
151
|
+
// The review prompt, with a plan phase and, under --ultra, the callers of
|
|
152
|
+
// changed symbols.
|
|
153
|
+
async function preparePrompt(job, plan, options, call, input) {
|
|
154
|
+
if (!options.ultra && !isLargeBundle(job.bundle.files)) {
|
|
155
|
+
return { prompt: buildReviewPrompt(input), usage: [], warnings: [] };
|
|
156
|
+
}
|
|
157
|
+
const callers = options.ultra ? await findCallers(job.bundle.files, plan.context) : [];
|
|
158
|
+
const key = `${job.reviewer.id}\0${job.bundle.label}`;
|
|
159
|
+
const shared = options.plans?.get(key);
|
|
160
|
+
const planning = shared ??
|
|
161
|
+
planBundle(options.runtime, job.reviewer, buildReviewPrompt({ ...input, forPlanning: true }), options.signal, call);
|
|
162
|
+
if (!shared)
|
|
163
|
+
options.plans?.set(key, planning);
|
|
164
|
+
const planned = await planning;
|
|
165
|
+
const prompt = buildReviewPrompt({ ...input, callers, plan: planned.plan });
|
|
166
|
+
// The sample that made the call pays for it and reports its warning.
|
|
167
|
+
if (shared)
|
|
168
|
+
return { prompt, usage: [], warnings: [] };
|
|
169
|
+
for (const usage of planned.usage)
|
|
170
|
+
options.onUsage?.(usage);
|
|
171
|
+
return { prompt, usage: [...planned.usage], warnings: planned.warning ? [planned.warning] : [] };
|
|
172
|
+
}
|
|
173
|
+
async function anchorFindings(job, plan, options, reportedFindings) {
|
|
174
|
+
const warnings = [];
|
|
79
175
|
const findings = [];
|
|
80
176
|
const anchorContext = {
|
|
81
177
|
diffs: plan.selected,
|
|
@@ -86,9 +182,9 @@ export async function runJob(job, plan, options) {
|
|
|
86
182
|
// A finding on a file outside the bundle belongs to the task that reviews
|
|
87
183
|
// that file; keeping it would report the same issue once per bundle that
|
|
88
184
|
// happened to read the file.
|
|
89
|
-
const bundleFiles = new Set(files);
|
|
185
|
+
const bundleFiles = new Set(job.bundle.files.map((f) => f.newPath));
|
|
90
186
|
let outside = 0;
|
|
91
|
-
for (const { reported, model } of
|
|
187
|
+
for (const { reported, model } of reportedFindings) {
|
|
92
188
|
// Relocating a quote on a file outside the bundle would pay for an
|
|
93
189
|
// answer the next check throws away.
|
|
94
190
|
const context = bundleFiles.has(reported.file)
|
|
@@ -99,6 +195,13 @@ export async function runJob(job, plan, options) {
|
|
|
99
195
|
warnings.push(`${job.taskId}: ${anchor.warning}`);
|
|
100
196
|
if (!bundleFiles.has(anchor.file)) {
|
|
101
197
|
outside += 1;
|
|
198
|
+
options.emit({
|
|
199
|
+
type: "finding_dropped",
|
|
200
|
+
taskId: job.taskId,
|
|
201
|
+
reason: "outside_bundle",
|
|
202
|
+
file: anchor.file,
|
|
203
|
+
title: reported.title,
|
|
204
|
+
});
|
|
102
205
|
continue;
|
|
103
206
|
}
|
|
104
207
|
const content = anchor.lineRange
|
|
@@ -107,25 +210,10 @@ export async function runJob(job, plan, options) {
|
|
|
107
210
|
const provenance = model === undefined ? { task: job.taskId } : { task: job.taskId, model };
|
|
108
211
|
const finding = toFinding(reported, job.reviewer.id, provenance, anchor, content);
|
|
109
212
|
findings.push(finding);
|
|
110
|
-
emit({ type: "finding", taskId: job.taskId, finding });
|
|
213
|
+
options.emit({ type: "finding", taskId: job.taskId, finding });
|
|
111
214
|
}
|
|
112
215
|
if (outside > 0) {
|
|
113
216
|
warnings.push(`${job.taskId}: dropped ${outside} finding(s) on files outside its bundle`);
|
|
114
217
|
}
|
|
115
|
-
|
|
116
|
-
const outcome = {
|
|
117
|
-
taskId: job.taskId,
|
|
118
|
-
reviewer: job.reviewer.id,
|
|
119
|
-
bundle: job.bundle.label,
|
|
120
|
-
files,
|
|
121
|
-
status: result.status,
|
|
122
|
-
findings: findings.length,
|
|
123
|
-
durationMs: Date.now() - started,
|
|
124
|
-
usage,
|
|
125
|
-
};
|
|
126
|
-
if (result.error !== undefined)
|
|
127
|
-
outcome.error = result.error;
|
|
128
|
-
emit({ type: "task_finished", outcome });
|
|
129
|
-
return { outcome, findings, usage, warnings };
|
|
218
|
+
return { findings, warnings };
|
|
130
219
|
}
|
|
131
|
-
//# sourceMappingURL=execute.js.map
|