@open-cr-agent/core 0.6.0 → 0.9.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 (222) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/json.d.ts +0 -1
  3. package/dist/agent/json.js +0 -1
  4. package/dist/agent/model-call.d.ts +13 -0
  5. package/dist/agent/model-call.js +22 -0
  6. package/dist/agent/pool.d.ts +0 -1
  7. package/dist/agent/pool.js +0 -1
  8. package/dist/agent/settings.d.ts +9 -5
  9. package/dist/agent/settings.js +20 -8
  10. package/dist/agent/spend-limit.d.ts +18 -0
  11. package/dist/agent/spend-limit.js +53 -0
  12. package/dist/agent/usage.d.ts +0 -1
  13. package/dist/agent/usage.js +0 -1
  14. package/dist/anchor/anchor.d.ts +0 -1
  15. package/dist/anchor/anchor.js +0 -1
  16. package/dist/anchor/match.d.ts +0 -1
  17. package/dist/anchor/match.js +0 -1
  18. package/dist/anchor/relocate.d.ts +1 -2
  19. package/dist/anchor/relocate.js +8 -15
  20. package/dist/at.d.ts +0 -1
  21. package/dist/at.js +0 -1
  22. package/dist/bounded-file.d.ts +12 -0
  23. package/dist/bounded-file.js +47 -0
  24. package/dist/bundle/bundle.d.ts +0 -1
  25. package/dist/bundle/bundle.js +0 -1
  26. package/dist/bundle/grouping.d.ts +0 -1
  27. package/dist/bundle/grouping.js +0 -1
  28. package/dist/bundle/runtime-grouper.d.ts +1 -2
  29. package/dist/bundle/runtime-grouper.js +8 -15
  30. package/dist/contracts.d.ts +37 -1
  31. package/dist/contracts.js +14 -1
  32. package/dist/diff/hunks.d.ts +0 -1
  33. package/dist/diff/hunks.js +0 -1
  34. package/dist/diff/parse.d.ts +0 -1
  35. package/dist/diff/parse.js +0 -1
  36. package/dist/diff/quoted-path.d.ts +0 -1
  37. package/dist/diff/quoted-path.js +0 -1
  38. package/dist/domain.d.ts +11 -1
  39. package/dist/domain.js +2 -1
  40. package/dist/errors.d.ts +0 -1
  41. package/dist/errors.js +0 -1
  42. package/dist/hash.d.ts +0 -1
  43. package/dist/hash.js +0 -1
  44. package/dist/index.d.ts +10 -8
  45. package/dist/index.js +4 -5
  46. package/dist/internal.d.ts +10 -6
  47. package/dist/internal.js +9 -5
  48. package/dist/judge/judge.d.ts +1 -2
  49. package/dist/judge/judge.js +10 -14
  50. package/dist/judge/prompt.d.ts +1 -2
  51. package/dist/judge/prompt.js +10 -2
  52. package/dist/judge/verdict.d.ts +2 -2
  53. package/dist/judge/verdict.js +4 -3
  54. package/dist/knowledge/learning.d.ts +21 -0
  55. package/dist/knowledge/learning.js +1 -0
  56. package/dist/knowledge/select.d.ts +15 -0
  57. package/dist/knowledge/select.js +175 -0
  58. package/dist/learn/draft.d.ts +21 -0
  59. package/dist/learn/draft.js +123 -0
  60. package/dist/{pipeline → matrix}/matrix.d.ts +1 -3
  61. package/dist/{pipeline → matrix}/matrix.js +1 -2
  62. package/dist/memory/memory.d.ts +0 -1
  63. package/dist/memory/memory.js +0 -1
  64. package/dist/net/proxied-fetch.d.ts +0 -1
  65. package/dist/net/proxied-fetch.js +0 -1
  66. package/dist/pipeline/assemble-report.d.ts +0 -7
  67. package/dist/pipeline/assemble-report.js +33 -21
  68. package/dist/pipeline/check-stage.d.ts +0 -1
  69. package/dist/pipeline/check-stage.js +31 -12
  70. package/dist/pipeline/context.d.ts +2 -2
  71. package/dist/pipeline/context.js +26 -7
  72. package/dist/pipeline/coverage.d.ts +1 -2
  73. package/dist/pipeline/coverage.js +37 -17
  74. package/dist/pipeline/execute-stage.d.ts +5 -6
  75. package/dist/pipeline/execute-stage.js +50 -29
  76. package/dist/pipeline/execute.d.ts +13 -7
  77. package/dist/pipeline/execute.js +108 -43
  78. package/dist/pipeline/filter-stage.d.ts +0 -1
  79. package/dist/pipeline/filter-stage.js +2 -1
  80. package/dist/pipeline/findings.d.ts +0 -1
  81. package/dist/pipeline/findings.js +0 -1
  82. package/dist/pipeline/imports.d.ts +0 -1
  83. package/dist/pipeline/imports.js +2 -17
  84. package/dist/pipeline/options.d.ts +22 -2
  85. package/dist/pipeline/options.js +31 -1
  86. package/dist/pipeline/plan-output.d.ts +7 -1
  87. package/dist/pipeline/plan-output.js +9 -2
  88. package/dist/pipeline/plan.d.ts +14 -9
  89. package/dist/pipeline/plan.js +64 -10
  90. package/dist/pipeline/preview.d.ts +5 -5
  91. package/dist/pipeline/preview.js +18 -28
  92. package/dist/pipeline/provenance.d.ts +0 -1
  93. package/dist/pipeline/provenance.js +0 -1
  94. package/dist/pipeline/resume.d.ts +22 -0
  95. package/dist/pipeline/resume.js +24 -0
  96. package/dist/pipeline/run-id.d.ts +0 -1
  97. package/dist/pipeline/run-id.js +0 -1
  98. package/dist/pipeline/run.d.ts +0 -1
  99. package/dist/pipeline/run.js +18 -45
  100. package/dist/pipeline/task-prompt.d.ts +13 -0
  101. package/dist/pipeline/task-prompt.js +43 -0
  102. package/dist/pipeline/task.d.ts +8 -8
  103. package/dist/pipeline/task.js +11 -7
  104. package/dist/plugin/builtin.d.ts +1 -1
  105. package/dist/plugin/builtin.js +12 -3
  106. package/dist/plugin/host.d.ts +0 -1
  107. package/dist/plugin/host.js +0 -1
  108. package/dist/plugin/registry.d.ts +0 -1
  109. package/dist/plugin/registry.js +0 -1
  110. package/dist/plugin/types.d.ts +0 -1
  111. package/dist/plugin/types.js +0 -1
  112. package/dist/report/output-schema.d.ts +69 -1
  113. package/dist/report/output-schema.js +34 -5
  114. package/dist/report/output.d.ts +0 -1
  115. package/dist/report/output.js +31 -4
  116. package/dist/report/provenance.d.ts +0 -1
  117. package/dist/report/provenance.js +0 -1
  118. package/dist/report/read.d.ts +0 -1
  119. package/dist/report/read.js +5 -3
  120. package/dist/report/report.d.ts +57 -4
  121. package/dist/report/report.js +40 -3
  122. package/dist/report/serialize.d.ts +0 -1
  123. package/dist/report/serialize.js +0 -1
  124. package/dist/rereview/presence.d.ts +0 -1
  125. package/dist/rereview/presence.js +0 -1
  126. package/dist/rereview/quote.d.ts +0 -1
  127. package/dist/rereview/quote.js +0 -1
  128. package/dist/rereview/reconcile.d.ts +0 -1
  129. package/dist/rereview/reconcile.js +0 -1
  130. package/dist/review/impact.d.ts +20 -5
  131. package/dist/review/impact.js +153 -29
  132. package/dist/review/plan-phase.d.ts +1 -2
  133. package/dist/review/plan-phase.js +13 -13
  134. package/dist/review/prompt-text.d.ts +1 -2
  135. package/dist/review/prompt-text.js +82 -21
  136. package/dist/review/prompt.d.ts +6 -1
  137. package/dist/review/prompt.js +57 -3
  138. package/dist/review/reviewer.d.ts +0 -1
  139. package/dist/review/reviewer.js +0 -1
  140. package/dist/review/reviewers/agents-md.d.ts +0 -1
  141. package/dist/review/reviewers/agents-md.js +0 -1
  142. package/dist/review/reviewers/correctness.d.ts +0 -1
  143. package/dist/review/reviewers/correctness.js +0 -1
  144. package/dist/review/reviewers/docs.d.ts +0 -1
  145. package/dist/review/reviewers/docs.js +0 -1
  146. package/dist/review/reviewers/performance.d.ts +0 -1
  147. package/dist/review/reviewers/performance.js +0 -1
  148. package/dist/review/reviewers/scopes.d.ts +0 -1
  149. package/dist/review/reviewers/scopes.js +0 -1
  150. package/dist/review/reviewers/security.d.ts +0 -1
  151. package/dist/review/reviewers/security.js +0 -1
  152. package/dist/review/tools.d.ts +1 -1
  153. package/dist/review/tools.js +1 -1
  154. package/dist/rules/builtin/general.d.ts +0 -1
  155. package/dist/rules/builtin/general.js +0 -1
  156. package/dist/rules/builtin/go.d.ts +0 -1
  157. package/dist/rules/builtin/go.js +0 -1
  158. package/dist/rules/builtin/index.d.ts +0 -1
  159. package/dist/rules/builtin/index.js +0 -1
  160. package/dist/rules/builtin/java.d.ts +0 -1
  161. package/dist/rules/builtin/java.js +0 -1
  162. package/dist/rules/builtin/performance.d.ts +0 -1
  163. package/dist/rules/builtin/performance.js +0 -1
  164. package/dist/rules/builtin/python.d.ts +0 -1
  165. package/dist/rules/builtin/python.js +0 -1
  166. package/dist/rules/builtin/security.d.ts +0 -1
  167. package/dist/rules/builtin/security.js +0 -1
  168. package/dist/rules/builtin/typescript.d.ts +0 -1
  169. package/dist/rules/builtin/typescript.js +0 -1
  170. package/dist/rules/languages.d.ts +0 -1
  171. package/dist/rules/languages.js +0 -1
  172. package/dist/rules/repo-rules.d.ts +0 -1
  173. package/dist/rules/repo-rules.js +0 -1
  174. package/dist/rules/resolve.d.ts +0 -1
  175. package/dist/rules/resolve.js +0 -1
  176. package/dist/rules/rule-set.d.ts +0 -1
  177. package/dist/rules/rule-set.js +0 -1
  178. package/dist/runtime/attempt.d.ts +27 -2
  179. package/dist/runtime/attempt.js +68 -2
  180. package/dist/runtime/chain-runner.d.ts +2 -3
  181. package/dist/runtime/chain-runner.js +0 -1
  182. package/dist/runtime/effort-capability.d.ts +0 -1
  183. package/dist/runtime/effort-capability.js +0 -1
  184. package/dist/runtime/failback.d.ts +2 -3
  185. package/dist/runtime/failback.js +61 -15
  186. package/dist/runtime/models.d.ts +0 -1
  187. package/dist/runtime/models.js +14 -13
  188. package/dist/runtime/quota.d.ts +1 -1
  189. package/dist/runtime/quota.js +3 -2
  190. package/dist/runtime/tools.d.ts +0 -1
  191. package/dist/runtime/tools.js +11 -1
  192. package/dist/runtime/wrap-up.d.ts +6 -0
  193. package/dist/runtime/wrap-up.js +27 -0
  194. package/dist/sarif/candidates.d.ts +3 -3
  195. package/dist/sarif/candidates.js +2 -1
  196. package/dist/sarif/evidence.d.ts +35 -0
  197. package/dist/sarif/evidence.js +128 -0
  198. package/dist/sarif/schema.d.ts +18 -1
  199. package/dist/sarif/schema.js +8 -1
  200. package/dist/select/patterns.d.ts +1 -1
  201. package/dist/select/patterns.js +46 -1
  202. package/dist/select/select.d.ts +2 -1
  203. package/dist/select/select.js +34 -4
  204. package/dist/session/jsonl.d.ts +2 -2
  205. package/dist/session/jsonl.js +9 -4
  206. package/dist/session/resume-read.d.ts +2 -0
  207. package/dist/session/resume-read.js +131 -0
  208. package/dist/session/seal.d.ts +5 -0
  209. package/dist/session/seal.js +29 -0
  210. package/dist/triage.d.ts +0 -1
  211. package/dist/triage.js +0 -1
  212. package/dist/vcs.d.ts +0 -1
  213. package/dist/vcs.js +0 -1
  214. package/dist/verify/prompt.d.ts +6 -3
  215. package/dist/verify/prompt.js +13 -5
  216. package/dist/verify/related.d.ts +3 -0
  217. package/dist/verify/related.js +88 -0
  218. package/dist/verify/verify.d.ts +3 -4
  219. package/dist/verify/verify.js +27 -20
  220. package/package.json +3 -3
  221. package/dist/agent/budget.d.ts +0 -13
  222. package/dist/agent/budget.js +0 -28
@@ -1,9 +1,11 @@
1
1
  import { type Bundle } from "../bundle/bundle.js";
2
2
  import type { AgentRuntime, ReviewContext, Usage } from "../contracts.js";
3
- import type { ChangeRequest, FileDiff, RiskTier } from "../domain.js";
3
+ import type { ChangeRequest, FileDiff, PriorReview, RiskTier } from "../domain.js";
4
+ import { type SelectLearnings } from "../knowledge/select.js";
4
5
  import { type RememberedEntry } from "../memory/memory.js";
5
- import type { ReviewEvent } from "../report/report.js";
6
+ import type { ReviewEvent, ReviewReport } from "../report/report.js";
6
7
  import { type SourcedRule } from "../rules/repo-rules.js";
8
+ import { type AnalyzerEvidence } from "../sarif/evidence.js";
7
9
  import { type FileDecision } from "../select/select.js";
8
10
  import type { ReviewHooks, ReviewOptions } from "./options.js";
9
11
  export interface ReviewPlan {
@@ -13,22 +15,25 @@ export interface ReviewPlan {
13
15
  tier: RiskTier;
14
16
  bundles: Bundle[];
15
17
  unchanged: ReadonlySet<string>;
16
- widened?: {
17
- from: RiskTier;
18
- to: RiskTier;
18
+ prior: {
19
+ review?: PriorReview;
20
+ warning?: string;
19
21
  };
22
+ scope?: ReviewScope;
20
23
  context: ReviewContext;
21
24
  guidelines: string | undefined;
22
25
  repoRules: SourcedRule[];
23
26
  memory: RememberedEntry[];
27
+ learnings: SelectLearnings;
28
+ evidence: AnalyzerEvidence;
24
29
  usage: Usage[];
25
30
  warnings: string[];
26
31
  }
27
- export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "selection" | "bundling" | "grouper" | "effort" | "roles"> & {
32
+ export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "learnings" | "sarifEvidence" | "selection" | "bundling" | "grouper" | "effort" | "roles" | "resume"> & {
28
33
  runId?: string;
29
34
  runtime?: AgentRuntime;
30
- reviewOnly?: ReadonlySet<string>;
31
- priorTier?: RiskTier;
35
+ full?: boolean;
32
36
  };
37
+ type ReviewScope = NonNullable<ReviewReport["scope"]>;
33
38
  export declare function planReview(options: PlanOptions, emit: (event: ReviewEvent) => void, signal: AbortSignal): Promise<ReviewPlan>;
34
- //# sourceMappingURL=plan.d.ts.map
39
+ export {};
@@ -1,19 +1,26 @@
1
1
  import { roleCall } from "../agent/settings.js";
2
2
  import { bundleFiles, defaultBundlePolicy } from "../bundle/bundle.js";
3
3
  import { runtimeGrouper } from "../bundle/runtime-grouper.js";
4
+ import { errorMessage } from "../errors.js";
5
+ import { learningSelector } from "../knowledge/select.js";
6
+ import { rank } from "../matrix/matrix.js";
4
7
  import { MEMORY_PATH, mergeMemory, parseMemory } from "../memory/memory.js";
5
8
  import { parseRepoRules, REPO_RULES_PATH, } from "../rules/repo-rules.js";
6
- import { defaultSelectionPolicy, selectFiles } from "../select/select.js";
9
+ import { analyzerEvidence } from "../sarif/evidence.js";
10
+ import { binaryTextWarning, defaultSelectionPolicy, selectFiles, } from "../select/select.js";
7
11
  import { triage } from "../triage.js";
8
12
  import { reviewContext } from "./context.js";
9
- import { rank } from "./matrix.js";
13
+ import { resumedBundles } from "./resume.js";
10
14
  import { newRunId } from "./run-id.js";
11
15
  const GUIDELINES_PATH = "AGENTS.md";
12
16
  export async function planReview(options, emit, signal) {
13
17
  const { vcs } = options;
14
18
  const readTrusted = options.readTrusted ?? ((path) => vcs.readFile(path));
19
+ const prior = await loadPriorReview(vcs);
20
+ const scope = reviewScope(prior.review, options.full === true);
15
21
  const changeRequest = await vcs.getChangeRequest();
16
22
  emit({ type: "run_started", runId: options.runId ?? newRunId(), changeRequest });
23
+ emit({ type: "stage_started", stage: "select" });
17
24
  const diffs = await vcs.getDiff();
18
25
  const decisions = selectFiles(diffs, { ...defaultSelectionPolicy, ...options.selection });
19
26
  const selected = decisions.filter((d) => d.selected).map((d) => d.diff);
@@ -34,21 +41,31 @@ export async function planReview(options, emit, signal) {
34
41
  (options.runtime
35
42
  ? runtimeGrouper(options.runtime, signal, (u) => usage.push(u), roleCall("helper", options))
36
43
  : undefined);
37
- const widened = options.reviewOnly && options.priorTier && rank(tier) > rank(options.priorTier)
38
- ? { from: options.priorTier, to: tier }
44
+ // The rest of the change still sets the risk tier; a tier above the prior
45
+ // review's adds reviewers, so everything is reviewed again.
46
+ const priorTier = prior.review?.tier;
47
+ const widened = scope.only && priorTier && rank(tier) > rank(priorTier)
48
+ ? { from: priorTier, to: tier }
39
49
  : undefined;
40
- const only = widened ? undefined : options.reviewOnly;
50
+ const only = widened ? undefined : scope.only;
41
51
  const inScope = only
42
52
  ? selected.filter((d) => only.has(d.newPath) || only.has(d.oldPath))
43
53
  : selected;
44
54
  const unchanged = new Set(selected.filter((d) => !inScope.includes(d)).map((d) => d.newPath));
45
- const bundled = await bundleFiles(inScope, options.bundling ?? defaultBundlePolicy, grouper);
55
+ emit({ type: "stage_started", stage: "bundle" });
56
+ const resumed = options.resume && resumedBundles(options.resume, inScope);
57
+ const bundled = resumed
58
+ ? { bundles: resumed, strategy: "resumed", warnings: [] }
59
+ : await bundleFiles(inScope, options.bundling ?? defaultBundlePolicy, grouper);
46
60
  emit({
47
61
  type: "files_bundled",
48
62
  strategy: bundled.strategy,
49
63
  bundles: bundled.bundles.length,
64
+ groups: bundled.bundles.map((b) => ({ label: b.label, files: b.files.map((f) => f.newPath) })),
50
65
  warnings: bundled.warnings,
51
66
  });
67
+ const binaryText = binaryTextWarning(decisions);
68
+ const evidence = analyzerEvidence(options.sarifEvidence ?? [], bundled.bundles);
52
69
  return {
53
70
  changeRequest,
54
71
  decisions,
@@ -56,20 +73,57 @@ export async function planReview(options, emit, signal) {
56
73
  tier,
57
74
  bundles: bundled.bundles,
58
75
  unchanged,
59
- ...(widened ? { widened } : {}),
60
- context: reviewContext(vcs, diffs),
76
+ prior,
77
+ ...(widened
78
+ ? {
79
+ scope: {
80
+ mode: "full",
81
+ reason: `the risk tier rose from ${widened.from} to ${widened.to}, which adds reviewers`,
82
+ },
83
+ }
84
+ : scope.note
85
+ ? { scope: scope.note }
86
+ : {}),
87
+ context: reviewContext(vcs, diffs, options.learnings),
61
88
  guidelines,
62
89
  repoRules: [
63
90
  ...(options.rules ?? []),
64
91
  ...fileRules.map((rule) => ({ ...rule, source: "repository" })),
65
92
  ],
66
93
  memory: mergeMemory(memoryText === undefined ? [] : parseMemory(memoryText), options.accountMemory ?? []),
94
+ learnings: learningSelector(options.learnings ?? []),
95
+ evidence,
67
96
  usage,
68
- warnings: bundled.warnings,
97
+ warnings: [...(binaryText ? [binaryText] : []), ...bundled.warnings, ...evidence.warnings],
69
98
  };
70
99
  }
71
100
  async function loadRepoRules(read) {
72
101
  const text = await read(REPO_RULES_PATH);
73
102
  return text === undefined ? [] : parseRepoRules(text);
74
103
  }
75
- //# sourceMappingURL=plan.js.map
104
+ // Review only what changed since the prior review when the platform can
105
+ // tell; otherwise everything, with the reason in the report.
106
+ function reviewScope(review, full) {
107
+ if (!review)
108
+ return {};
109
+ if (full)
110
+ return { note: { mode: "full", reason: "a full review was requested" } };
111
+ if (review.changedSince) {
112
+ return {
113
+ only: new Set(review.changedSince.files),
114
+ note: { mode: "incremental", since: review.changedSince.head },
115
+ };
116
+ }
117
+ const reason = review.fullReviewReason ?? "the platform cannot tell what changed since";
118
+ return { note: { mode: "full", reason } };
119
+ }
120
+ // A missing prior review only costs the comparison, never the review.
121
+ async function loadPriorReview(vcs) {
122
+ try {
123
+ const review = await vcs.getPriorReview();
124
+ return review ? { review } : {};
125
+ }
126
+ catch (error) {
127
+ return { warning: `could not load the previous review: ${errorMessage(error)}` };
128
+ }
129
+ }
@@ -1,9 +1,9 @@
1
1
  import type { Effort } from "../contracts.js";
2
2
  import type { ChangeRequest, RiskTier } from "../domain.js";
3
+ import { type SkippedCell } from "../matrix/matrix.js";
3
4
  import type { FileDecision } from "../select/select.js";
4
- import { type SkippedCell } from "./matrix.js";
5
- import type { ReviewOptions } from "./options.js";
6
- import { type PlanOptions } from "./plan.js";
5
+ import { type ReviewOptions } from "./options.js";
6
+ import { type PlanOptions, type ReviewPlan } from "./plan.js";
7
7
  export interface PreviewTask {
8
8
  taskId: string;
9
9
  reviewer: string;
@@ -29,6 +29,7 @@ type InputCost = {
29
29
  export interface ReviewPreview {
30
30
  changeRequest: ChangeRequest;
31
31
  tier: RiskTier;
32
+ scope?: NonNullable<ReviewPlan["scope"]>;
32
33
  selected: string[];
33
34
  excluded: {
34
35
  path: string;
@@ -53,9 +54,8 @@ export interface ReviewPreview {
53
54
  };
54
55
  warnings: string[];
55
56
  }
56
- export type PreviewOptions = Omit<PlanOptions, "runtime"> & Omit<ReviewOptions, "vcs" | "runtime"> & {
57
+ export type PreviewOptions = Omit<PlanOptions, "runtime" | "full"> & Omit<ReviewOptions, "vcs" | "runtime" | "full"> & {
57
58
  inputPrice?: (model: string) => number | undefined;
58
59
  };
59
60
  export declare function previewReview(options: PreviewOptions): Promise<ReviewPreview>;
60
61
  export {};
61
- //# sourceMappingURL=preview.d.ts.map
@@ -1,53 +1,42 @@
1
- import { reviewerCall } from "../agent/settings.js";
1
+ import { chainOf, reviewerCall } from "../agent/settings.js";
2
2
  import { defaultBundlePolicy } from "../bundle/bundle.js";
3
- import { memoryFor } from "../memory/memory.js";
4
- import { buildReviewPrompt } from "../review/prompt.js";
3
+ import { planTasks } from "../matrix/matrix.js";
5
4
  import { correctnessReviewer } from "../review/reviewers/correctness.js";
6
- import { resolveRules } from "../rules/resolve.js";
7
- import { isLargeBundle } from "./execute.js";
8
- import { planTasks } from "./matrix.js";
5
+ import { runSettings } from "./options.js";
9
6
  import { planReview } from "./plan.js";
7
+ import { taskPrompt } from "./task-prompt.js";
10
8
  // Everything a review would do before its first model call, for free: which
11
9
  // files, which tasks, and how large each first prompt is.
12
10
  export async function previewReview(options) {
13
- const plan = await planReview(options, () => { }, new AbortController().signal);
11
+ const settings = runSettings(options);
12
+ const plan = await planReview({ ...options, full: settings.full }, () => { }, new AbortController().signal);
14
13
  const reviewers = options.reviewers ?? [correctnessReviewer];
15
14
  const planned = planTasks(plan.bundles, reviewers, plan.tier, options.reviewerOverrides, {
16
- ultra: options.mode?.ultra === true,
17
- ...(options.limits?.maxTasks !== undefined ? { maxTasks: options.limits?.maxTasks } : {}),
15
+ ultra: settings.ultra,
16
+ ...(settings.maxTasks !== undefined ? { maxTasks: settings.maxTasks } : {}),
18
17
  hasGuidelines: Boolean(plan.guidelines?.trim()),
19
18
  });
20
19
  const { cells } = planned;
21
20
  const plannedBundles = new Set();
22
21
  const tasks = cells.map((cell) => {
23
- const files = cell.bundle.files.map((f) => f.newPath);
24
- const input = {
25
- reviewer: cell.reviewer,
26
- changeRequest: plan.changeRequest,
27
- changedFiles: plan.selected,
28
- bundle: cell.bundle.files,
29
- rules: resolveRules(files, plan.repoRules, cell.reviewer.rules),
30
- guidelines: plan.guidelines,
31
- accepted: memoryFor(files, plan.memory),
32
- };
33
- const prompt = buildReviewPrompt(input);
22
+ const prepared = taskPrompt(cell, plan, settings.ultra);
34
23
  const task = {
35
24
  taskId: cell.taskId,
36
25
  reviewer: cell.reviewer.id,
37
26
  bundle: cell.bundle.label,
38
- files,
39
- promptTokens: tokens(prompt),
27
+ files: cell.bundle.files.map((f) => f.newPath),
28
+ promptTokens: tokens(prepared.prompt),
40
29
  };
41
30
  const call = reviewerCall(cell.reviewer, options);
42
31
  if (call.effort !== undefined)
43
32
  task.effort = call.effort;
44
- const models = call.models ?? options.models?.[cell.reviewer.modelTier];
33
+ const models = chainOf(call, cell.reviewer.modelTier, options);
45
34
  if (models?.length)
46
35
  task.models = [...models];
47
- const key = `${cell.reviewer.id}\0${cell.bundle.label}`;
48
- if ((options.mode?.ultra || isLargeBundle(cell.bundle.files)) && !plannedBundles.has(key)) {
49
- plannedBundles.add(key);
50
- task.planPromptTokens = tokens(buildReviewPrompt({ ...input, forPlanning: true }));
36
+ const { planCall } = prepared;
37
+ if (planCall && !plannedBundles.has(planCall.key)) {
38
+ plannedBundles.add(planCall.key);
39
+ task.planPromptTokens = tokens(planCall.prompt());
51
40
  }
52
41
  const first = task.models?.[0];
53
42
  if (first !== undefined && options.inputPrice) {
@@ -59,6 +48,7 @@ export async function previewReview(options) {
59
48
  return {
60
49
  changeRequest: plan.changeRequest,
61
50
  tier: plan.tier,
51
+ ...(plan.scope ? { scope: plan.scope } : {}),
62
52
  selected: plan.selected.map((d) => d.newPath),
63
53
  excluded: plan.decisions.flatMap((d) => d.selected ? [] : [{ path: d.diff.newPath, reason: d.reason }]),
64
54
  bundles: plan.bundles.map((b) => ({ label: b.label, files: b.files.map((f) => f.newPath) })),
@@ -69,6 +59,7 @@ export async function previewReview(options) {
69
59
  planCalls: tasks.filter((t) => t.planPromptTokens !== undefined).length,
70
60
  ...(tasks.some((t) => t.inputCost) ? { inputCost: totalInputCost(tasks) } : {}),
71
61
  warnings: [
62
+ ...(plan.prior.warning ? [plan.prior.warning] : []),
72
63
  ...plan.warnings,
73
64
  ...(planned.limited?.length
74
65
  ? [
@@ -98,4 +89,3 @@ function totalInputCost(tasks) {
98
89
  function tokens(prompt) {
99
90
  return Math.ceil((prompt.system.length + prompt.user.length) / 4);
100
91
  }
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
@@ -1,11 +1,11 @@
1
- import { spendTracker } from "../agent/budget.js";
2
- import { errorMessage, OcraError } from "../errors.js";
1
+ import { spendLimit } from "../agent/spend-limit.js";
2
+ import { OcraError } from "../errors.js";
3
3
  import { correctnessReviewer } from "../review/reviewers/correctness.js";
4
4
  import { assembleReport } from "./assemble-report.js";
5
5
  import { checkStage } from "./check-stage.js";
6
6
  import { executeStage } from "./execute-stage.js";
7
7
  import { filterStage } from "./filter-stage.js";
8
- import { MAX_TIMER_MS, REVIEW_DEFAULTS } from "./options.js";
8
+ import { runSettings } from "./options.js";
9
9
  import { planReview } from "./plan.js";
10
10
  import { newRunId } from "./run-id.js";
11
11
  // The library entry: plan (deterministic stages) → execute (one agent task
@@ -16,56 +16,29 @@ export function review(options) {
16
16
  return reviewWithHooks(options);
17
17
  }
18
18
  export async function reviewWithHooks(options) {
19
+ const settings = runSettings(options);
19
20
  const emit = options.onEvent ?? (() => { });
20
- const timeout = AbortSignal.timeout(Math.min(options.limits?.runTimeoutMs ?? REVIEW_DEFAULTS.runTimeoutMs, MAX_TIMER_MS));
21
+ const timeout = AbortSignal.timeout(settings.runTimeoutMs);
21
22
  const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
22
23
  const reviewers = options.reviewers ?? [correctnessReviewer];
23
24
  if (reviewers.length === 0)
24
25
  throw new OcraError("CONFIG_INVALID", "No reviewer is registered");
25
26
  const runId = options.identity?.runId ?? newRunId();
26
- const prior = await loadPriorReview(options.vcs);
27
- const scope = reviewScope(prior.review, options.mode?.full === true);
28
- const plan = await planReview(scope.only
29
- ? {
30
- ...options,
31
- runId,
32
- reviewOnly: scope.only,
33
- ...(prior.review?.tier ? { priorTier: prior.review.tier } : {}),
34
- }
35
- : { ...options, runId }, emit, signal);
36
- const budget = spendTracker(options.limits?.maxCostUsd, plan.usage);
37
- const context = { options, plan, budget, signal, emit };
27
+ const plan = await planReview({ ...options, runId, full: settings.full }, emit, signal);
28
+ for (const usage of plan.usage)
29
+ emit({ type: "usage_reported", usage });
30
+ const context = {
31
+ options,
32
+ settings,
33
+ plan,
34
+ spendLimit: spendLimit(settings.maxCostUsd, plan.usage, (usage) => emit({ type: "usage_reported", usage })),
35
+ signal,
36
+ emit,
37
+ };
38
38
  const executed = await executeStage(reviewers, context);
39
- const filtered = await filterStage(executed, prior.review, context);
39
+ const filtered = await filterStage(executed, plan.prior.review, context);
40
40
  const checked = await checkStage(filtered, context);
41
- const report = assembleReport({ runId, reviewers, prior, scopeNote: scope.note }, { executed, filtered, checked }, context);
41
+ const report = assembleReport({ runId, reviewers }, { executed, filtered, checked }, context);
42
42
  emit({ type: "run_finished", report });
43
43
  return report;
44
44
  }
45
- // Review only what changed since the earlier review when the platform can
46
- // tell; otherwise everything, with the reason in the report.
47
- function reviewScope(review, full) {
48
- if (!review)
49
- return {};
50
- if (full)
51
- return { note: { mode: "full", reason: "a full review was requested" } };
52
- if (review.changedSince) {
53
- return {
54
- only: new Set(review.changedSince.files),
55
- note: { mode: "incremental", since: review.changedSince.head },
56
- };
57
- }
58
- const reason = review.fullReviewReason ?? "the platform cannot tell what changed since";
59
- return { note: { mode: "full", reason } };
60
- }
61
- // A missing earlier review only costs the comparison, never the review.
62
- async function loadPriorReview(vcs) {
63
- try {
64
- const review = await vcs.getPriorReview();
65
- return review ? { review } : {};
66
- }
67
- catch (error) {
68
- return { warning: `could not load the previous review: ${errorMessage(error)}` };
69
- }
70
- }
71
- //# sourceMappingURL=run.js.map
@@ -0,0 +1,13 @@
1
+ import type { MatrixCell } from "../matrix/matrix.js";
2
+ import { type ReviewPrompt, type ReviewPromptInput } from "../review/prompt.js";
3
+ import type { ReviewPlan } from "./plan.js";
4
+ export interface TaskPrompt {
5
+ input: ReviewPromptInput;
6
+ prompt: ReviewPrompt;
7
+ callers: boolean;
8
+ planCall?: {
9
+ key: string;
10
+ prompt: () => ReviewPrompt;
11
+ };
12
+ }
13
+ export declare function taskPrompt(cell: MatrixCell, plan: ReviewPlan, ultra: boolean): TaskPrompt;
@@ -0,0 +1,43 @@
1
+ import { memoryFor } from "../memory/memory.js";
2
+ import { buildReviewPrompt } from "../review/prompt.js";
3
+ import { resolveRules } from "../rules/resolve.js";
4
+ // In default mode only bundles large enough that a reviewer's 30 steps may
5
+ // not cover them get a plan phase; --ultra plans every task.
6
+ const PLAN_MIN_FILES = 5;
7
+ const PLAN_MIN_PATCH_CHARS = 40_000;
8
+ // What one task of the matrix sends: the run builds its prompt from this and
9
+ // --plan previews it, so the preview cannot drift from the run.
10
+ export function taskPrompt(cell, plan, ultra) {
11
+ const files = cell.bundle.files.map((f) => f.newPath);
12
+ const learnings = plan.learnings(cell.bundle.files);
13
+ const analyzerResults = plan.evidence.forBundle(cell.bundle);
14
+ const input = {
15
+ reviewer: cell.reviewer,
16
+ changeRequest: plan.changeRequest,
17
+ changedFiles: plan.selected,
18
+ bundle: cell.bundle.files,
19
+ rules: resolveRules(files, plan.repoRules, cell.reviewer.rules),
20
+ guidelines: plan.guidelines,
21
+ accepted: memoryFor(files, plan.memory),
22
+ learnings: learnings.selected,
23
+ moreLearnings: learnings.left,
24
+ ...(analyzerResults.length > 0 ? { analyzerResults } : {}),
25
+ };
26
+ const prompt = buildReviewPrompt(input);
27
+ const callers = ultra || plan.tier === "full";
28
+ if (!ultra && !isLargeBundle(cell.bundle))
29
+ return { input, prompt, callers };
30
+ return {
31
+ input,
32
+ prompt,
33
+ callers,
34
+ planCall: {
35
+ key: `${cell.reviewer.id}\0${cell.bundle.label}`,
36
+ prompt: () => buildReviewPrompt({ ...input, forPlanning: true }),
37
+ },
38
+ };
39
+ }
40
+ function isLargeBundle({ files }) {
41
+ const chars = files.reduce((sum, f) => sum + f.patch.length, 0);
42
+ return files.length >= PLAN_MIN_FILES || chars >= PLAN_MIN_PATCH_CHARS;
43
+ }
@@ -1,23 +1,23 @@
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[];
11
+ wrapUp?: {
12
+ findings: number;
13
+ };
14
14
  }
15
15
  export interface TaskCallbacks {
16
- onProgress(message: string): void;
16
+ onProgress(message: string, attempt?: AttemptRecord): void;
17
17
  onUsage?: ((usage: Usage) => void) | undefined;
18
18
  category: string;
19
19
  abortGraceMs?: number | undefined;
20
20
  }
21
21
  export declare function executeTask(runtime: AgentRuntime, spec: AgentTaskSpec, runSignal: AbortSignal, callbacks: TaskCallbacks): Promise<TaskResult>;
22
+ export declare const MAX_FINDINGS_PER_TASK = 50;
22
23
  export declare function boundFinding(f: ReportedFinding): ReportedFinding;
23
- //# sourceMappingURL=task.d.ts.map
@@ -1,4 +1,4 @@
1
- import { SpendLimitReached } from "../agent/budget.js";
1
+ import { SpendLimitReached } from "../agent/spend-limit.js";
2
2
  import { addUsage, emptyUsage } from "../agent/usage.js";
3
3
  import { reportedFindingSchema } from "../domain.js";
4
4
  import { errorMessage } from "../errors.js";
@@ -39,8 +39,8 @@ export async function executeTask(runtime, spec, runSignal, callbacks) {
39
39
  const ending = iterator
40
40
  ? await collectAfterAbort(iterator, pending, result, callbacks)
41
41
  : undefined;
42
- // The task's last usage report crossed the limit, and it finished
43
- // anyway: its review is complete.
42
+ // The spend limit stopped the run, often through the task's own last
43
+ // usage report, after the task had finished: its review is complete.
44
44
  if (ending === "done" && runSignal.reason instanceof SpendLimitReached) {
45
45
  result.status = "completed";
46
46
  delete result.error;
@@ -68,8 +68,9 @@ async function collectAfterAbort(iterator, pending, result, callbacks) {
68
68
  if (event.done)
69
69
  return undefined;
70
70
  const { value } = event;
71
- if (value.type === "usage" || value.type === "finding")
71
+ if (value.type === "usage" || value.type === "finding" || value.type === "done") {
72
72
  handle(value, result, callbacks);
73
+ }
73
74
  if (value.type === "done" || value.type === "error")
74
75
  return value.type;
75
76
  next = iterator.next();
@@ -84,7 +85,7 @@ async function collectAfterAbort(iterator, pending, result, callbacks) {
84
85
  function handle(event, result, callbacks) {
85
86
  switch (event.type) {
86
87
  case "progress":
87
- callbacks.onProgress(event.message);
88
+ callbacks.onProgress(event.message, event.attempt);
88
89
  return false;
89
90
  case "finding": {
90
91
  const parsed = reportedFindingSchema.safeParse(withReviewerCategory(event.finding, callbacks.category));
@@ -111,6 +112,10 @@ function handle(event, result, callbacks) {
111
112
  return false;
112
113
  }
113
114
  case "done":
115
+ if (event.ended)
116
+ result.ended = event.ended;
117
+ if (event.wrapUp)
118
+ result.wrapUp = { findings: event.wrapUp.findings };
114
119
  return true;
115
120
  case "error":
116
121
  result.status = "failed";
@@ -120,7 +125,7 @@ function handle(event, result, callbacks) {
120
125
  }
121
126
  // A reviewer steered by the change could flood the pull request with
122
127
  // comments or pad them without end; both are bounded.
123
- const MAX_FINDINGS_PER_TASK = 50;
128
+ export const MAX_FINDINGS_PER_TASK = 50;
124
129
  const MAX_TITLE = 300;
125
130
  const MAX_TEXT = 4_000;
126
131
  const MAX_EVIDENCE = 10;
@@ -159,4 +164,3 @@ function untilAborted(promise, signal) {
159
164
  });
160
165
  });
161
166
  }
162
- //# sourceMappingURL=task.js.map
@@ -8,7 +8,7 @@ export declare const agentsMdReviewerPlugin: OcraPlugin;
8
8
  declare const sessionSettings: z.ZodObject<{
9
9
  dir: z.ZodString;
10
10
  id: z.ZodString;
11
+ sealKey: z.ZodExactOptional<z.ZodString>;
11
12
  }, z.core.$strict>;
12
13
  export declare const sessionJsonlPlugin: OcraPlugin<z.infer<typeof sessionSettings>>;
13
14
  export {};
14
- //# sourceMappingURL=builtin.d.ts.map