@open-cr-agent/core 0.6.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.
Files changed (204) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/budget.d.ts +0 -1
  3. package/dist/agent/budget.js +0 -1
  4. package/dist/agent/json.d.ts +0 -1
  5. package/dist/agent/json.js +0 -1
  6. package/dist/agent/pool.d.ts +0 -1
  7. package/dist/agent/pool.js +0 -1
  8. package/dist/agent/settings.d.ts +0 -1
  9. package/dist/agent/settings.js +0 -1
  10. package/dist/agent/usage.d.ts +0 -1
  11. package/dist/agent/usage.js +0 -1
  12. package/dist/anchor/anchor.d.ts +0 -1
  13. package/dist/anchor/anchor.js +0 -1
  14. package/dist/anchor/match.d.ts +0 -1
  15. package/dist/anchor/match.js +0 -1
  16. package/dist/anchor/relocate.d.ts +0 -1
  17. package/dist/anchor/relocate.js +0 -1
  18. package/dist/at.d.ts +0 -1
  19. package/dist/at.js +0 -1
  20. package/dist/bounded-file.d.ts +12 -0
  21. package/dist/bounded-file.js +47 -0
  22. package/dist/bundle/bundle.d.ts +0 -1
  23. package/dist/bundle/bundle.js +0 -1
  24. package/dist/bundle/grouping.d.ts +0 -1
  25. package/dist/bundle/grouping.js +0 -1
  26. package/dist/bundle/runtime-grouper.d.ts +0 -1
  27. package/dist/bundle/runtime-grouper.js +0 -1
  28. package/dist/contracts.d.ts +10 -1
  29. package/dist/contracts.js +4 -1
  30. package/dist/diff/hunks.d.ts +0 -1
  31. package/dist/diff/hunks.js +0 -1
  32. package/dist/diff/parse.d.ts +0 -1
  33. package/dist/diff/parse.js +0 -1
  34. package/dist/diff/quoted-path.d.ts +0 -1
  35. package/dist/diff/quoted-path.js +0 -1
  36. package/dist/domain.d.ts +4 -1
  37. package/dist/domain.js +0 -1
  38. package/dist/errors.d.ts +0 -1
  39. package/dist/errors.js +0 -1
  40. package/dist/hash.d.ts +0 -1
  41. package/dist/hash.js +0 -1
  42. package/dist/index.d.ts +5 -5
  43. package/dist/index.js +2 -3
  44. package/dist/internal.d.ts +3 -3
  45. package/dist/internal.js +2 -2
  46. package/dist/judge/judge.d.ts +0 -1
  47. package/dist/judge/judge.js +0 -1
  48. package/dist/judge/prompt.d.ts +0 -1
  49. package/dist/judge/prompt.js +0 -1
  50. package/dist/judge/verdict.d.ts +0 -1
  51. package/dist/judge/verdict.js +0 -1
  52. package/dist/memory/memory.d.ts +0 -1
  53. package/dist/memory/memory.js +0 -1
  54. package/dist/net/proxied-fetch.d.ts +0 -1
  55. package/dist/net/proxied-fetch.js +0 -1
  56. package/dist/pipeline/assemble-report.d.ts +0 -1
  57. package/dist/pipeline/assemble-report.js +0 -1
  58. package/dist/pipeline/check-stage.d.ts +0 -1
  59. package/dist/pipeline/check-stage.js +0 -1
  60. package/dist/pipeline/context.d.ts +0 -1
  61. package/dist/pipeline/context.js +8 -5
  62. package/dist/pipeline/coverage.d.ts +0 -1
  63. package/dist/pipeline/coverage.js +37 -17
  64. package/dist/pipeline/execute-stage.d.ts +0 -1
  65. package/dist/pipeline/execute-stage.js +29 -3
  66. package/dist/pipeline/execute.d.ts +9 -2
  67. package/dist/pipeline/execute.js +90 -9
  68. package/dist/pipeline/filter-stage.d.ts +0 -1
  69. package/dist/pipeline/filter-stage.js +0 -1
  70. package/dist/pipeline/findings.d.ts +0 -1
  71. package/dist/pipeline/findings.js +0 -1
  72. package/dist/pipeline/imports.d.ts +0 -1
  73. package/dist/pipeline/imports.js +0 -1
  74. package/dist/pipeline/matrix.d.ts +0 -1
  75. package/dist/pipeline/matrix.js +0 -1
  76. package/dist/pipeline/options.d.ts +2 -1
  77. package/dist/pipeline/options.js +0 -1
  78. package/dist/pipeline/plan-output.d.ts +0 -1
  79. package/dist/pipeline/plan-output.js +0 -1
  80. package/dist/pipeline/plan.d.ts +1 -2
  81. package/dist/pipeline/plan.js +6 -2
  82. package/dist/pipeline/preview.d.ts +0 -1
  83. package/dist/pipeline/preview.js +0 -1
  84. package/dist/pipeline/provenance.d.ts +0 -1
  85. package/dist/pipeline/provenance.js +0 -1
  86. package/dist/pipeline/resume.d.ts +22 -0
  87. package/dist/pipeline/resume.js +24 -0
  88. package/dist/pipeline/run-id.d.ts +0 -1
  89. package/dist/pipeline/run-id.js +0 -1
  90. package/dist/pipeline/run.d.ts +0 -1
  91. package/dist/pipeline/run.js +0 -1
  92. package/dist/pipeline/task.d.ts +5 -8
  93. package/dist/pipeline/task.js +8 -6
  94. package/dist/plugin/builtin.d.ts +1 -1
  95. package/dist/plugin/builtin.js +12 -3
  96. package/dist/plugin/host.d.ts +0 -1
  97. package/dist/plugin/host.js +0 -1
  98. package/dist/plugin/registry.d.ts +0 -1
  99. package/dist/plugin/registry.js +0 -1
  100. package/dist/plugin/types.d.ts +0 -1
  101. package/dist/plugin/types.js +0 -1
  102. package/dist/report/output-schema.d.ts +39 -1
  103. package/dist/report/output-schema.js +10 -3
  104. package/dist/report/output.d.ts +0 -1
  105. package/dist/report/output.js +7 -4
  106. package/dist/report/provenance.d.ts +0 -1
  107. package/dist/report/provenance.js +0 -1
  108. package/dist/report/read.d.ts +0 -1
  109. package/dist/report/read.js +5 -3
  110. package/dist/report/report.d.ts +26 -3
  111. package/dist/report/report.js +11 -3
  112. package/dist/report/serialize.d.ts +0 -1
  113. package/dist/report/serialize.js +0 -1
  114. package/dist/rereview/presence.d.ts +0 -1
  115. package/dist/rereview/presence.js +0 -1
  116. package/dist/rereview/quote.d.ts +0 -1
  117. package/dist/rereview/quote.js +0 -1
  118. package/dist/rereview/reconcile.d.ts +0 -1
  119. package/dist/rereview/reconcile.js +0 -1
  120. package/dist/review/impact.d.ts +0 -1
  121. package/dist/review/impact.js +0 -1
  122. package/dist/review/plan-phase.d.ts +0 -1
  123. package/dist/review/plan-phase.js +0 -1
  124. package/dist/review/prompt-text.d.ts +0 -1
  125. package/dist/review/prompt-text.js +0 -1
  126. package/dist/review/prompt.d.ts +0 -1
  127. package/dist/review/prompt.js +0 -1
  128. package/dist/review/reviewer.d.ts +0 -1
  129. package/dist/review/reviewer.js +0 -1
  130. package/dist/review/reviewers/agents-md.d.ts +0 -1
  131. package/dist/review/reviewers/agents-md.js +0 -1
  132. package/dist/review/reviewers/correctness.d.ts +0 -1
  133. package/dist/review/reviewers/correctness.js +0 -1
  134. package/dist/review/reviewers/docs.d.ts +0 -1
  135. package/dist/review/reviewers/docs.js +0 -1
  136. package/dist/review/reviewers/performance.d.ts +0 -1
  137. package/dist/review/reviewers/performance.js +0 -1
  138. package/dist/review/reviewers/scopes.d.ts +0 -1
  139. package/dist/review/reviewers/scopes.js +0 -1
  140. package/dist/review/reviewers/security.d.ts +0 -1
  141. package/dist/review/reviewers/security.js +0 -1
  142. package/dist/review/tools.d.ts +0 -1
  143. package/dist/review/tools.js +0 -1
  144. package/dist/rules/builtin/general.d.ts +0 -1
  145. package/dist/rules/builtin/general.js +0 -1
  146. package/dist/rules/builtin/go.d.ts +0 -1
  147. package/dist/rules/builtin/go.js +0 -1
  148. package/dist/rules/builtin/index.d.ts +0 -1
  149. package/dist/rules/builtin/index.js +0 -1
  150. package/dist/rules/builtin/java.d.ts +0 -1
  151. package/dist/rules/builtin/java.js +0 -1
  152. package/dist/rules/builtin/performance.d.ts +0 -1
  153. package/dist/rules/builtin/performance.js +0 -1
  154. package/dist/rules/builtin/python.d.ts +0 -1
  155. package/dist/rules/builtin/python.js +0 -1
  156. package/dist/rules/builtin/security.d.ts +0 -1
  157. package/dist/rules/builtin/security.js +0 -1
  158. package/dist/rules/builtin/typescript.d.ts +0 -1
  159. package/dist/rules/builtin/typescript.js +0 -1
  160. package/dist/rules/languages.d.ts +0 -1
  161. package/dist/rules/languages.js +0 -1
  162. package/dist/rules/repo-rules.d.ts +0 -1
  163. package/dist/rules/repo-rules.js +0 -1
  164. package/dist/rules/resolve.d.ts +0 -1
  165. package/dist/rules/resolve.js +0 -1
  166. package/dist/rules/rule-set.d.ts +0 -1
  167. package/dist/rules/rule-set.js +0 -1
  168. package/dist/runtime/attempt.d.ts +15 -2
  169. package/dist/runtime/attempt.js +47 -1
  170. package/dist/runtime/chain-runner.d.ts +0 -1
  171. package/dist/runtime/chain-runner.js +0 -1
  172. package/dist/runtime/effort-capability.d.ts +0 -1
  173. package/dist/runtime/effort-capability.js +0 -1
  174. package/dist/runtime/failback.d.ts +0 -1
  175. package/dist/runtime/failback.js +38 -9
  176. package/dist/runtime/models.d.ts +0 -1
  177. package/dist/runtime/models.js +14 -13
  178. package/dist/runtime/quota.d.ts +1 -1
  179. package/dist/runtime/quota.js +3 -2
  180. package/dist/runtime/tools.d.ts +0 -1
  181. package/dist/runtime/tools.js +0 -1
  182. package/dist/sarif/candidates.d.ts +0 -1
  183. package/dist/sarif/candidates.js +0 -1
  184. package/dist/sarif/schema.d.ts +0 -1
  185. package/dist/sarif/schema.js +0 -1
  186. package/dist/select/patterns.d.ts +0 -1
  187. package/dist/select/patterns.js +0 -1
  188. package/dist/select/select.d.ts +1 -1
  189. package/dist/select/select.js +16 -3
  190. package/dist/session/jsonl.d.ts +2 -2
  191. package/dist/session/jsonl.js +9 -4
  192. package/dist/session/resume-read.d.ts +2 -0
  193. package/dist/session/resume-read.js +128 -0
  194. package/dist/session/seal.d.ts +5 -0
  195. package/dist/session/seal.js +24 -0
  196. package/dist/triage.d.ts +0 -1
  197. package/dist/triage.js +0 -1
  198. package/dist/vcs.d.ts +0 -1
  199. package/dist/vcs.js +0 -1
  200. package/dist/verify/prompt.d.ts +0 -1
  201. package/dist/verify/prompt.js +0 -1
  202. package/dist/verify/verify.d.ts +0 -1
  203. package/dist/verify/verify.js +0 -1
  204. package/package.json +1 -1
@@ -1,37 +1,41 @@
1
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"];
2
6
  export function coverageOf(decisions, results, unchanged, limited, notStarted) {
3
7
  // A file is reviewed when every reviewer assigned to it finished at least
4
- // one of its tasks: under --ultra one completed sample is enough. A
5
- // reviewer whose task failed makes the file "failed"; one whose task never
6
- // started (the task or spend limit, a cancelled run) makes it "unreviewed".
7
- const done = new Map();
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();
8
13
  const ran = new Set();
9
14
  const key = (reviewer, file) => `${reviewer}\0${file}`;
10
15
  for (const { outcome } of results) {
11
16
  const started = !notStarted.has(outcome.taskId);
17
+ const reached = outcome.status !== "completed" ? "none" : (outcome.ended ?? "done");
12
18
  for (const file of outcome.files) {
13
19
  const k = key(outcome.reviewer, file);
14
20
  if (started)
15
21
  ran.add(k);
16
- done.set(k, done.get(k) === true || outcome.status === "completed");
22
+ progress.set(k, better(progress.get(k) ?? "none", reached));
17
23
  }
18
24
  }
19
25
  for (const cell of limited) {
20
26
  for (const f of cell.bundle.files) {
21
27
  const k = key(cell.reviewer.id, f.newPath);
22
- if (!done.has(k))
23
- done.set(k, false);
28
+ if (!progress.has(k))
29
+ progress.set(k, "none");
24
30
  }
25
31
  }
26
32
  const status = new Map();
27
- for (const [k, completed] of done) {
28
- const file = at(k.split("\0"), 1);
29
- const now = completed ? "reviewed" : ran.has(k) ? "failed" : "unreviewed";
30
- const before = status.get(file);
31
- // failed outranks unreviewed, which outranks reviewed.
32
- if (!before || now === "failed" || (now === "unreviewed" && before === "reviewed")) {
33
- status.set(file, now);
34
- }
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);
35
39
  }
36
40
  return decisions.map((d) => {
37
41
  const path = d.diff.newPath;
@@ -39,7 +43,23 @@ export function coverageOf(decisions, results, unchanged, limited, notStarted) {
39
43
  return { path, status: "excluded", reason: d.reason };
40
44
  if (unchanged.has(path))
41
45
  return { path, status: "unchanged" };
42
- return { path, status: status.get(path) ?? "unreviewed" };
46
+ return status.get(path) ?? { path, status: "unreviewed" };
43
47
  });
44
48
  }
45
- //# sourceMappingURL=coverage.js.map
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
+ }
@@ -23,4 +23,3 @@ export interface ExecuteStage {
23
23
  reviewLimitReached(): boolean;
24
24
  }
25
25
  export declare function executeStage(reviewers: readonly ReviewerDefinition[], context: StageContext): Promise<ExecuteStage>;
26
- //# sourceMappingURL=execute-stage.d.ts.map
@@ -3,9 +3,10 @@ import { mapWithConcurrency } from "../agent/pool.js";
3
3
  import { roleCall } from "../agent/settings.js";
4
4
  import { emptyUsage } from "../agent/usage.js";
5
5
  import { runtimeRelocator } from "../anchor/relocate.js";
6
- import { runJob } from "./execute.js";
6
+ import { jobKey, reuseJob, runJob } from "./execute.js";
7
7
  import { DEFAULT_MAX_TASKS, planTasks } from "./matrix.js";
8
8
  import { MAX_TIMER_MS, REVIEW_DEFAULTS } from "./options.js";
9
+ import { reusePool } from "./resume.js";
9
10
  // One agent task per (bundle, reviewer) cell of the matrix, within the task
10
11
  // limit, the run's signal and the review share of the spend limit.
11
12
  export async function executeStage(reviewers, context) {
@@ -24,6 +25,10 @@ export async function executeStage(reviewers, context) {
24
25
  const relocations = [];
25
26
  const spendLimit = new AbortController();
26
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 };
27
32
  const notStarted = new Set();
28
33
  let unaffordable = 0;
29
34
  const results = await mapWithConcurrency(matrix.cells, options.limits?.concurrency ?? REVIEW_DEFAULTS.concurrency, async (cell) => {
@@ -32,16 +37,22 @@ export async function executeStage(reviewers, context) {
32
37
  notStarted.add(cell.taskId);
33
38
  return skipCell(cell, "run cancelled before this task started", emit);
34
39
  }
40
+ const key = jobKey(cell, plan, execute);
41
+ const reused = await reuseJob(cell, plan, execute, key);
42
+ if (reused)
43
+ return reused;
35
44
  if (context.budget.reviewExhausted()) {
36
45
  notStarted.add(cell.taskId);
37
46
  unaffordable += 1;
38
47
  return skipCell(cell, `spend limit of $${options.limits?.maxCostUsd} reached`, emit);
39
48
  }
40
- return runJob(cell, plan, execute);
49
+ return runJob(cell, plan, execute, key);
41
50
  });
42
51
  if (unaffordable > 0) {
43
52
  warnings.push(`spend limit of $${options.limits?.maxCostUsd} reached: ${unaffordable} review task(s) did not start; their files are reported as not reviewed`);
44
53
  }
54
+ if (resume)
55
+ warnings.push(...resumeWarnings(resume.runId, pool.unused()));
45
56
  warnings.push(...results.flatMap((r) => r.warnings));
46
57
  return {
47
58
  matrix,
@@ -68,6 +79,7 @@ function executeOptions({ options, budget, signal, emit }, relocations, spendLim
68
79
  ultra: options.mode?.ultra === true,
69
80
  plans: new Map(),
70
81
  agents: options,
82
+ keyInputs: keyInputs(options),
71
83
  emit,
72
84
  // Tasks report spend while they run, so the one that uses up the review
73
85
  // share stops every task still running, not only the ones not yet started.
@@ -80,6 +92,21 @@ function executeOptions({ options, budget, signal, emit }, relocations, spendLim
80
92
  signal: AbortSignal.any([signal, spendLimit.signal]),
81
93
  };
82
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
+ }
83
110
  function relocatorOf(options, signal, onUsage) {
84
111
  if (options.relocate === false)
85
112
  return undefined;
@@ -101,4 +128,3 @@ function skipCell(cell, reason, emit) {
101
128
  emit({ type: "task_finished", outcome });
102
129
  return { outcome, findings: [], usage: emptyUsage(), warnings: [] };
103
130
  }
104
- //# sourceMappingURL=execute-stage.js.map
@@ -6,6 +6,7 @@ import type { ReviewEvent, TaskOutcome } from "../report/report.js";
6
6
  import { planBundle } from "../review/plan-phase.js";
7
7
  import type { MatrixCell } from "./matrix.js";
8
8
  import type { ReviewPlan } from "./plan.js";
9
+ import type { ReusePool } from "./resume.js";
9
10
  export interface JobResult {
10
11
  outcome: TaskOutcome;
11
12
  findings: Finding[];
@@ -23,11 +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
34
  export declare function isLargeBundle(files: readonly {
29
35
  patch: string;
30
36
  }[]): boolean;
31
- export declare function runJob(job: MatrixCell, plan: ReviewPlan, options: ExecuteOptions): Promise<JobResult>;
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>;
32
40
  export {};
33
- //# sourceMappingURL=execute.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { reviewerCall } from "../agent/settings.js";
2
- import { addUsage } from "../agent/usage.js";
2
+ import { addUsage, emptyUsage } from "../agent/usage.js";
3
3
  import { anchorFinding } from "../anchor/anchor.js";
4
4
  import { memoryFor } from "../memory/memory.js";
5
5
  import { findCallers } from "../review/impact.js";
@@ -7,6 +7,7 @@ import { planBundle } from "../review/plan-phase.js";
7
7
  import { buildReviewPrompt } from "../review/prompt.js";
8
8
  import { resolveRules } from "../rules/resolve.js";
9
9
  import { toFinding } from "./findings.js";
10
+ import { stableHash } from "./provenance.js";
10
11
  import { executeTask } from "./task.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.
@@ -16,12 +17,19 @@ 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
30
  const call = reviewerCall(job.reviewer, options.agents ?? {});
24
- const prepared = await preparePrompt(job, plan, options, call);
31
+ const input = promptInput(job, plan);
32
+ const prepared = await preparePrompt(job, plan, options, call, input);
25
33
  emit({
26
34
  type: "task_started",
27
35
  taskId: job.taskId,
@@ -40,7 +48,12 @@ export async function runJob(job, plan, options) {
40
48
  context: plan.context,
41
49
  timeoutMs: options.taskTimeoutMs,
42
50
  }, options.signal, {
43
- onProgress: (message) => emit({ type: "task_progress", taskId: job.taskId, message }),
51
+ onProgress: (message, attempt) => emit({
52
+ type: "task_progress",
53
+ taskId: job.taskId,
54
+ message,
55
+ ...(attempt ? { attempt } : {}),
56
+ }),
44
57
  onUsage: options.onUsage,
45
58
  category: job.reviewer.category,
46
59
  abortGraceMs: options.abortGraceMs,
@@ -60,14 +73,19 @@ export async function runJob(job, plan, options) {
60
73
  };
61
74
  if (result.error !== undefined)
62
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
+ }
63
82
  emit({ type: "task_finished", outcome });
64
83
  return { outcome, findings: anchored.findings, usage, warnings };
65
84
  }
66
- // The review prompt, with a plan phase and, under --ultra, the callers of
67
- // changed symbols.
68
- async function preparePrompt(job, plan, options, call) {
85
+ // The task's review prompt before a plan phase or callers are added.
86
+ function promptInput(job, plan) {
69
87
  const files = job.bundle.files.map((f) => f.newPath);
70
- const input = {
88
+ return {
71
89
  reviewer: job.reviewer,
72
90
  changeRequest: plan.changeRequest,
73
91
  changedFiles: plan.selected,
@@ -76,6 +94,63 @@ async function preparePrompt(job, plan, options, call) {
76
94
  guidelines: plan.guidelines,
77
95
  accepted: memoryFor(files, plan.memory),
78
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) {
79
154
  if (!options.ultra && !isLargeBundle(job.bundle.files)) {
80
155
  return { prompt: buildReviewPrompt(input), usage: [], warnings: [] };
81
156
  }
@@ -120,6 +195,13 @@ async function anchorFindings(job, plan, options, reportedFindings) {
120
195
  warnings.push(`${job.taskId}: ${anchor.warning}`);
121
196
  if (!bundleFiles.has(anchor.file)) {
122
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
+ });
123
205
  continue;
124
206
  }
125
207
  const content = anchor.lineRange
@@ -135,4 +217,3 @@ async function anchorFindings(job, plan, options, reportedFindings) {
135
217
  }
136
218
  return { findings, warnings };
137
219
  }
138
- //# sourceMappingURL=execute.js.map
@@ -13,4 +13,3 @@ export interface FilterStage {
13
13
  warnings: string[];
14
14
  }
15
15
  export declare function filterStage(executed: ExecuteStage, prior: PriorReview | undefined, { options, plan, emit }: StageContext): Promise<FilterStage>;
16
- //# sourceMappingURL=filter-stage.d.ts.map
@@ -43,4 +43,3 @@ function withoutRemembered(review, memory) {
43
43
  // Everything else the earlier review carries (replies, tier, head) stays.
44
44
  return { ...review, findings: review.findings.filter((f) => !accepted.has(f.fingerprint)) };
45
45
  }
46
- //# sourceMappingURL=filter-stage.js.map
@@ -3,4 +3,3 @@ 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
5
  export declare function dedupeFindings(findings: readonly Finding[]): Finding[];
6
- //# sourceMappingURL=findings.d.ts.map
@@ -43,4 +43,3 @@ export function dedupeFindings(findings) {
43
43
  }
44
44
  return [...byFingerprint.values()];
45
45
  }
46
- //# sourceMappingURL=findings.js.map
@@ -9,4 +9,3 @@ export interface SarifImport {
9
9
  }
10
10
  export declare const MAX_IMPORTED_PER_RUN = 200;
11
11
  export declare function importSarif(logs: readonly SarifLog[], plan: Pick<ReviewPlan, "selected" | "context">, emit: (event: ReviewEvent) => void): Promise<SarifImport>;
12
- //# sourceMappingURL=imports.d.ts.map
@@ -123,4 +123,3 @@ function importWarnings(tool, c) {
123
123
  return [];
124
124
  return [`${tool}: imported ${c.imported} result(s); left out ${left.join(", ")}`];
125
125
  }
126
- //# sourceMappingURL=imports.js.map
@@ -39,4 +39,3 @@ export interface TaskOptions {
39
39
  }
40
40
  export declare function planTasks(bundles: readonly Bundle[], reviewers: readonly ReviewerDefinition[], tier: RiskTier, overrides?: ReviewerOverrides, options?: TaskOptions): ReviewMatrix;
41
41
  export declare function rank(tier: RiskTier): number;
42
- //# sourceMappingURL=matrix.d.ts.map
@@ -98,4 +98,3 @@ function ignoreMatcher(reviewer) {
98
98
  const globs = reviewer.scope?.ignore ?? [];
99
99
  return globs.length === 0 ? () => false : picomatch([...globs], { dot: true, nocase: true });
100
100
  }
101
- //# sourceMappingURL=matrix.js.map
@@ -11,6 +11,7 @@ import type { SarifLog } from "../sarif/schema.js";
11
11
  import type { SelectionPolicy } from "../select/select.js";
12
12
  import type { VcsAdapter } from "../vcs.js";
13
13
  import type { ProvenanceInput } from "./provenance.js";
14
+ import type { ResumedRun } from "./resume.js";
14
15
  export interface ReviewOptions {
15
16
  vcs: VcsAdapter;
16
17
  runtime: AgentRuntime;
@@ -27,6 +28,7 @@ export interface ReviewOptions {
27
28
  stages?: ReviewStages;
28
29
  mode?: ReviewMode;
29
30
  identity?: RunIdentity;
31
+ resume?: ResumedRun;
30
32
  sarif?: readonly SarifLog[];
31
33
  signal?: AbortSignal;
32
34
  onEvent?: (event: ReviewEvent) => void;
@@ -62,4 +64,3 @@ export declare const REVIEW_DEFAULTS: {
62
64
  readonly runTimeoutMs: number;
63
65
  };
64
66
  export declare const MAX_TIMER_MS: number;
65
- //# sourceMappingURL=options.d.ts.map
@@ -6,4 +6,3 @@ export const REVIEW_DEFAULTS = {
6
6
  // Timers fire at once past 2^31 - 1 ms (about 24.8 days); a longer timeout
7
7
  // means no practical limit, so it is cut to the longest one a timer keeps.
8
8
  export const MAX_TIMER_MS = 2 ** 31 - 1;
9
- //# sourceMappingURL=options.js.map
@@ -87,4 +87,3 @@ export declare const planOutputSchema: z.ZodObject<{
87
87
  }, z.core.$strict>;
88
88
  export type PlanOutput = z.output<typeof planOutputSchema>;
89
89
  export declare function toPlanOutput(preview: ReviewPreview): PlanOutput;
90
- //# sourceMappingURL=plan-output.d.ts.map
@@ -106,4 +106,3 @@ function planTask(t) {
106
106
  : {}),
107
107
  };
108
108
  }
109
- //# sourceMappingURL=plan-output.js.map
@@ -24,11 +24,10 @@ export interface ReviewPlan {
24
24
  usage: Usage[];
25
25
  warnings: string[];
26
26
  }
27
- export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "selection" | "bundling" | "grouper" | "effort" | "roles"> & {
27
+ export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "selection" | "bundling" | "grouper" | "effort" | "roles" | "resume"> & {
28
28
  runId?: string;
29
29
  runtime?: AgentRuntime;
30
30
  reviewOnly?: ReadonlySet<string>;
31
31
  priorTier?: RiskTier;
32
32
  };
33
33
  export declare function planReview(options: PlanOptions, emit: (event: ReviewEvent) => void, signal: AbortSignal): Promise<ReviewPlan>;
34
- //# sourceMappingURL=plan.d.ts.map
@@ -7,6 +7,7 @@ import { defaultSelectionPolicy, selectFiles } from "../select/select.js";
7
7
  import { triage } from "../triage.js";
8
8
  import { reviewContext } from "./context.js";
9
9
  import { rank } from "./matrix.js";
10
+ import { resumedBundles } from "./resume.js";
10
11
  import { newRunId } from "./run-id.js";
11
12
  const GUIDELINES_PATH = "AGENTS.md";
12
13
  export async function planReview(options, emit, signal) {
@@ -42,11 +43,15 @@ export async function planReview(options, emit, signal) {
42
43
  ? selected.filter((d) => only.has(d.newPath) || only.has(d.oldPath))
43
44
  : selected;
44
45
  const unchanged = new Set(selected.filter((d) => !inScope.includes(d)).map((d) => d.newPath));
45
- const bundled = await bundleFiles(inScope, options.bundling ?? defaultBundlePolicy, grouper);
46
+ const resumed = options.resume && resumedBundles(options.resume, inScope);
47
+ const bundled = resumed
48
+ ? { bundles: resumed, strategy: "resumed", warnings: [] }
49
+ : await bundleFiles(inScope, options.bundling ?? defaultBundlePolicy, grouper);
46
50
  emit({
47
51
  type: "files_bundled",
48
52
  strategy: bundled.strategy,
49
53
  bundles: bundled.bundles.length,
54
+ groups: bundled.bundles.map((b) => ({ label: b.label, files: b.files.map((f) => f.newPath) })),
50
55
  warnings: bundled.warnings,
51
56
  });
52
57
  return {
@@ -72,4 +77,3 @@ async function loadRepoRules(read) {
72
77
  const text = await read(REPO_RULES_PATH);
73
78
  return text === undefined ? [] : parseRepoRules(text);
74
79
  }
75
- //# sourceMappingURL=plan.js.map
@@ -58,4 +58,3 @@ export type PreviewOptions = Omit<PlanOptions, "runtime"> & Omit<ReviewOptions,
58
58
  };
59
59
  export declare function previewReview(options: PreviewOptions): Promise<ReviewPreview>;
60
60
  export {};
61
- //# sourceMappingURL=preview.d.ts.map
@@ -98,4 +98,3 @@ function totalInputCost(tasks) {
98
98
  function tokens(prompt) {
99
99
  return Math.ceil((prompt.system.length + prompt.user.length) / 4);
100
100
  }
101
- //# sourceMappingURL=preview.js.map
@@ -18,4 +18,3 @@ export declare function appliedSampling(runtime: {
18
18
  }, requested?: Sampling): AppliedSampling;
19
19
  export declare function agentProvenance(agents: readonly ResolvedAgent[], runtime: Pick<AgentRuntime, "appliedTo">): Record<string, AgentProvenance>;
20
20
  export declare function runProvenance(input: ProvenanceInput, runtime: Pick<AgentRuntime, "sampling" | "appliedTo">, reviewers: readonly ReviewerDefinition[], agents: readonly ResolvedAgent[], overrides?: ReviewerOverrides, rules?: readonly SourcedRule[]): RunProvenance;
21
- //# sourceMappingURL=provenance.d.ts.map
@@ -99,4 +99,3 @@ function ruleProvenance({ path, rule, source }) {
99
99
  ...(source ? { source } : {}),
100
100
  };
101
101
  }
102
- //# sourceMappingURL=provenance.js.map
@@ -0,0 +1,22 @@
1
+ import type { Bundle } from "../bundle/bundle.js";
2
+ import type { FileDiff, TaskFinding } from "../domain.js";
3
+ import type { TaskOutcome } from "../report/report.js";
4
+ export interface ResumedRun {
5
+ runId: string;
6
+ bundles: readonly {
7
+ label: string;
8
+ files: readonly string[];
9
+ }[];
10
+ tasks: readonly ResumedTask[];
11
+ }
12
+ export interface ResumedTask {
13
+ key: string;
14
+ outcome: TaskOutcome;
15
+ findings: readonly TaskFinding[];
16
+ }
17
+ export declare function resumedBundles(run: ResumedRun, inScope: readonly FileDiff[]): Bundle[] | undefined;
18
+ export interface ReusePool {
19
+ take(key: string): ResumedTask | undefined;
20
+ unused(): number;
21
+ }
22
+ export declare function reusePool(run: ResumedRun | undefined): ReusePool;
@@ -0,0 +1,24 @@
1
+ // The earlier run's bundles, when they hold exactly the files in scope;
2
+ // otherwise undefined and the files are bundled again.
3
+ export function resumedBundles(run, inScope) {
4
+ const byPath = new Map(inScope.map((d) => [d.newPath, d]));
5
+ const listed = run.bundles.flatMap((b) => b.files);
6
+ if (listed.length !== byPath.size || new Set(listed).size !== listed.length)
7
+ return undefined;
8
+ if (!listed.every((path) => byPath.has(path)))
9
+ return undefined;
10
+ return run.bundles.map((b) => ({
11
+ label: b.label,
12
+ files: b.files.map((path) => byPath.get(path)),
13
+ }));
14
+ }
15
+ export function reusePool(run) {
16
+ const byKey = new Map();
17
+ for (const task of run?.tasks ?? []) {
18
+ byKey.set(task.key, [...(byKey.get(task.key) ?? []), task]);
19
+ }
20
+ return {
21
+ take: (key) => byKey.get(key)?.shift(),
22
+ unused: () => [...byKey.values()].reduce((n, tasks) => n + tasks.length, 0),
23
+ };
24
+ }
@@ -1,2 +1 @@
1
1
  export declare function newRunId(now?: Date): string;
2
- //# sourceMappingURL=run-id.d.ts.map
@@ -10,4 +10,3 @@ export function newRunId(now = new Date()) {
10
10
  .replace(/\.\d+Z$/, "Z");
11
11
  return `${stamp}-${randomBytes(3).toString("hex")}`;
12
12
  }
13
- //# sourceMappingURL=run-id.js.map
@@ -2,4 +2,3 @@ import type { ReviewReport } from "../report/report.js";
2
2
  import { type ReviewHooks, type ReviewOptions } from "./options.js";
3
3
  export declare function review(options: ReviewOptions): Promise<ReviewReport>;
4
4
  export declare function reviewWithHooks(options: ReviewOptions & ReviewHooks): Promise<ReviewReport>;
5
- //# sourceMappingURL=run.d.ts.map
@@ -68,4 +68,3 @@ async function loadPriorReview(vcs) {
68
68
  return { warning: `could not load the previous review: ${errorMessage(error)}` };
69
69
  }
70
70
  }
71
- //# sourceMappingURL=run.js.map
@@ -1,23 +1,20 @@
1
- import type { AgentRuntime, AgentTaskSpec, Usage } from "../contracts.js";
2
- import { type ReportedFinding } from "../domain.js";
1
+ import type { AgentRuntime, AgentTaskSpec, AttemptRecord, IncompleteEnding, Usage } from "../contracts.js";
2
+ import { type ReportedFinding, type TaskFinding } from "../domain.js";
3
3
  import type { TaskStatus } from "../report/report.js";
4
- export interface TaskFinding {
5
- reported: ReportedFinding;
6
- model?: string;
7
- }
8
4
  export interface TaskResult {
9
5
  status: TaskStatus;
10
6
  error?: string;
7
+ ended?: IncompleteEnding;
11
8
  findings: TaskFinding[];
12
9
  usage: Usage;
13
10
  warnings: string[];
14
11
  }
15
12
  export interface TaskCallbacks {
16
- onProgress(message: string): void;
13
+ onProgress(message: string, attempt?: AttemptRecord): void;
17
14
  onUsage?: ((usage: Usage) => void) | undefined;
18
15
  category: string;
19
16
  abortGraceMs?: number | undefined;
20
17
  }
21
18
  export declare function executeTask(runtime: AgentRuntime, spec: AgentTaskSpec, runSignal: AbortSignal, callbacks: TaskCallbacks): Promise<TaskResult>;
19
+ export declare const MAX_FINDINGS_PER_TASK = 50;
22
20
  export declare function boundFinding(f: ReportedFinding): ReportedFinding;
23
- //# sourceMappingURL=task.d.ts.map