@open-cr-agent/core 0.7.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 (101) hide show
  1. package/dist/agent/model-call.d.ts +13 -0
  2. package/dist/agent/model-call.js +22 -0
  3. package/dist/agent/settings.d.ts +9 -4
  4. package/dist/agent/settings.js +20 -7
  5. package/dist/agent/spend-limit.d.ts +18 -0
  6. package/dist/agent/spend-limit.js +53 -0
  7. package/dist/anchor/relocate.d.ts +1 -1
  8. package/dist/anchor/relocate.js +8 -14
  9. package/dist/bundle/runtime-grouper.d.ts +1 -1
  10. package/dist/bundle/runtime-grouper.js +8 -14
  11. package/dist/contracts.d.ts +27 -0
  12. package/dist/contracts.js +10 -0
  13. package/dist/domain.d.ts +7 -0
  14. package/dist/domain.js +2 -0
  15. package/dist/index.d.ts +8 -6
  16. package/dist/index.js +4 -4
  17. package/dist/internal.d.ts +7 -3
  18. package/dist/internal.js +7 -3
  19. package/dist/judge/judge.d.ts +1 -1
  20. package/dist/judge/judge.js +10 -13
  21. package/dist/judge/prompt.d.ts +1 -1
  22. package/dist/judge/prompt.js +10 -1
  23. package/dist/judge/verdict.d.ts +2 -1
  24. package/dist/judge/verdict.js +4 -2
  25. package/dist/knowledge/learning.d.ts +21 -0
  26. package/dist/knowledge/learning.js +1 -0
  27. package/dist/knowledge/select.d.ts +15 -0
  28. package/dist/knowledge/select.js +175 -0
  29. package/dist/learn/draft.d.ts +21 -0
  30. package/dist/learn/draft.js +123 -0
  31. package/dist/{pipeline → matrix}/matrix.d.ts +1 -2
  32. package/dist/{pipeline → matrix}/matrix.js +1 -1
  33. package/dist/pipeline/assemble-report.d.ts +0 -6
  34. package/dist/pipeline/assemble-report.js +33 -20
  35. package/dist/pipeline/check-stage.js +31 -11
  36. package/dist/pipeline/context.d.ts +2 -1
  37. package/dist/pipeline/context.js +19 -3
  38. package/dist/pipeline/coverage.d.ts +1 -1
  39. package/dist/pipeline/execute-stage.d.ts +5 -5
  40. package/dist/pipeline/execute-stage.js +21 -26
  41. package/dist/pipeline/execute.d.ts +4 -5
  42. package/dist/pipeline/execute.js +35 -51
  43. package/dist/pipeline/filter-stage.js +2 -0
  44. package/dist/pipeline/imports.js +2 -16
  45. package/dist/pipeline/options.d.ts +20 -1
  46. package/dist/pipeline/options.js +31 -0
  47. package/dist/pipeline/plan-output.d.ts +7 -0
  48. package/dist/pipeline/plan-output.js +9 -1
  49. package/dist/pipeline/plan.d.ts +14 -8
  50. package/dist/pipeline/plan.js +58 -8
  51. package/dist/pipeline/preview.d.ts +5 -4
  52. package/dist/pipeline/preview.js +18 -27
  53. package/dist/pipeline/run.js +18 -44
  54. package/dist/pipeline/task-prompt.d.ts +13 -0
  55. package/dist/pipeline/task-prompt.js +43 -0
  56. package/dist/pipeline/task.d.ts +3 -0
  57. package/dist/pipeline/task.js +3 -1
  58. package/dist/report/output-schema.d.ts +30 -0
  59. package/dist/report/output-schema.js +24 -2
  60. package/dist/report/output.js +24 -0
  61. package/dist/report/report.d.ts +32 -2
  62. package/dist/report/report.js +29 -0
  63. package/dist/review/impact.d.ts +20 -4
  64. package/dist/review/impact.js +153 -28
  65. package/dist/review/plan-phase.d.ts +1 -1
  66. package/dist/review/plan-phase.js +13 -12
  67. package/dist/review/prompt-text.d.ts +1 -1
  68. package/dist/review/prompt-text.js +82 -20
  69. package/dist/review/prompt.d.ts +6 -0
  70. package/dist/review/prompt.js +57 -2
  71. package/dist/review/tools.d.ts +1 -0
  72. package/dist/review/tools.js +1 -0
  73. package/dist/runtime/attempt.d.ts +12 -0
  74. package/dist/runtime/attempt.js +21 -1
  75. package/dist/runtime/chain-runner.d.ts +2 -2
  76. package/dist/runtime/failback.d.ts +2 -2
  77. package/dist/runtime/failback.js +29 -12
  78. package/dist/runtime/tools.js +11 -0
  79. package/dist/runtime/wrap-up.d.ts +6 -0
  80. package/dist/runtime/wrap-up.js +27 -0
  81. package/dist/sarif/candidates.d.ts +3 -2
  82. package/dist/sarif/candidates.js +2 -0
  83. package/dist/sarif/evidence.d.ts +35 -0
  84. package/dist/sarif/evidence.js +128 -0
  85. package/dist/sarif/schema.d.ts +18 -0
  86. package/dist/sarif/schema.js +8 -0
  87. package/dist/select/patterns.d.ts +1 -0
  88. package/dist/select/patterns.js +46 -0
  89. package/dist/select/select.d.ts +1 -0
  90. package/dist/select/select.js +18 -1
  91. package/dist/session/resume-read.js +3 -0
  92. package/dist/session/seal.js +5 -0
  93. package/dist/verify/prompt.d.ts +6 -2
  94. package/dist/verify/prompt.js +13 -4
  95. package/dist/verify/related.d.ts +3 -0
  96. package/dist/verify/related.js +88 -0
  97. package/dist/verify/verify.d.ts +3 -3
  98. package/dist/verify/verify.js +27 -19
  99. package/package.json +3 -3
  100. package/dist/agent/budget.d.ts +0 -12
  101. package/dist/agent/budget.js +0 -27
@@ -1,20 +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";
10
13
  import { resumedBundles } from "./resume.js";
11
14
  import { newRunId } from "./run-id.js";
12
15
  const GUIDELINES_PATH = "AGENTS.md";
13
16
  export async function planReview(options, emit, signal) {
14
17
  const { vcs } = options;
15
18
  const readTrusted = options.readTrusted ?? ((path) => vcs.readFile(path));
19
+ const prior = await loadPriorReview(vcs);
20
+ const scope = reviewScope(prior.review, options.full === true);
16
21
  const changeRequest = await vcs.getChangeRequest();
17
22
  emit({ type: "run_started", runId: options.runId ?? newRunId(), changeRequest });
23
+ emit({ type: "stage_started", stage: "select" });
18
24
  const diffs = await vcs.getDiff();
19
25
  const decisions = selectFiles(diffs, { ...defaultSelectionPolicy, ...options.selection });
20
26
  const selected = decisions.filter((d) => d.selected).map((d) => d.diff);
@@ -35,14 +41,18 @@ export async function planReview(options, emit, signal) {
35
41
  (options.runtime
36
42
  ? runtimeGrouper(options.runtime, signal, (u) => usage.push(u), roleCall("helper", options))
37
43
  : undefined);
38
- const widened = options.reviewOnly && options.priorTier && rank(tier) > rank(options.priorTier)
39
- ? { 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 }
40
49
  : undefined;
41
- const only = widened ? undefined : options.reviewOnly;
50
+ const only = widened ? undefined : scope.only;
42
51
  const inScope = only
43
52
  ? selected.filter((d) => only.has(d.newPath) || only.has(d.oldPath))
44
53
  : selected;
45
54
  const unchanged = new Set(selected.filter((d) => !inScope.includes(d)).map((d) => d.newPath));
55
+ emit({ type: "stage_started", stage: "bundle" });
46
56
  const resumed = options.resume && resumedBundles(options.resume, inScope);
47
57
  const bundled = resumed
48
58
  ? { bundles: resumed, strategy: "resumed", warnings: [] }
@@ -54,6 +64,8 @@ export async function planReview(options, emit, signal) {
54
64
  groups: bundled.bundles.map((b) => ({ label: b.label, files: b.files.map((f) => f.newPath) })),
55
65
  warnings: bundled.warnings,
56
66
  });
67
+ const binaryText = binaryTextWarning(decisions);
68
+ const evidence = analyzerEvidence(options.sarifEvidence ?? [], bundled.bundles);
57
69
  return {
58
70
  changeRequest,
59
71
  decisions,
@@ -61,19 +73,57 @@ export async function planReview(options, emit, signal) {
61
73
  tier,
62
74
  bundles: bundled.bundles,
63
75
  unchanged,
64
- ...(widened ? { widened } : {}),
65
- 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),
66
88
  guidelines,
67
89
  repoRules: [
68
90
  ...(options.rules ?? []),
69
91
  ...fileRules.map((rule) => ({ ...rule, source: "repository" })),
70
92
  ],
71
93
  memory: mergeMemory(memoryText === undefined ? [] : parseMemory(memoryText), options.accountMemory ?? []),
94
+ learnings: learningSelector(options.learnings ?? []),
95
+ evidence,
72
96
  usage,
73
- warnings: bundled.warnings,
97
+ warnings: [...(binaryText ? [binaryText] : []), ...bundled.warnings, ...evidence.warnings],
74
98
  };
75
99
  }
76
100
  async function loadRepoRules(read) {
77
101
  const text = await read(REPO_RULES_PATH);
78
102
  return text === undefined ? [] : parseRepoRules(text);
79
103
  }
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,7 +54,7 @@ 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>;
@@ -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
  ? [
@@ -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,55 +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
- }
@@ -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
+ }
@@ -8,6 +8,9 @@ export interface TaskResult {
8
8
  findings: TaskFinding[];
9
9
  usage: Usage;
10
10
  warnings: string[];
11
+ wrapUp?: {
12
+ findings: number;
13
+ };
11
14
  }
12
15
  export interface TaskCallbacks {
13
16
  onProgress(message: string, attempt?: AttemptRecord): void;
@@ -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";
@@ -114,6 +114,8 @@ function handle(event, result, callbacks) {
114
114
  case "done":
115
115
  if (event.ended)
116
116
  result.ended = event.ended;
117
+ if (event.wrapUp)
118
+ result.wrapUp = { findings: event.wrapUp.findings };
117
119
  return true;
118
120
  case "error":
119
121
  result.status = "failed";
@@ -37,6 +37,9 @@ export declare const taskOutcomeSchema: z.ZodObject<{
37
37
  costUsd: z.ZodNumber;
38
38
  }, z.core.$strict>;
39
39
  reusedFrom: z.ZodExactOptional<z.ZodString>;
40
+ wrapUp: z.ZodExactOptional<z.ZodObject<{
41
+ findings: z.ZodInt;
42
+ }, z.core.$strict>>;
40
43
  }, z.core.$strict>;
41
44
  export declare const skippedCellSchema: z.ZodObject<{
42
45
  reviewer: z.ZodString;
@@ -49,6 +52,13 @@ export declare const skippedCellSchema: z.ZodObject<{
49
52
  task_limit: "task_limit";
50
53
  }>;
51
54
  }, z.core.$strict>;
55
+ export declare const scopeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
56
+ mode: z.ZodLiteral<"incremental">;
57
+ since: z.ZodString;
58
+ }, z.core.$strict>, z.ZodObject<{
59
+ mode: z.ZodLiteral<"full">;
60
+ reason: z.ZodString;
61
+ }, z.core.$strict>], "mode">;
52
62
  export declare const reportOutputSchema: z.ZodObject<{
53
63
  version: z.ZodLiteral<1>;
54
64
  runId: z.ZodExactOptional<z.ZodString>;
@@ -145,6 +155,7 @@ export declare const reportOutputSchema: z.ZodObject<{
145
155
  evidence: z.ZodArray<z.ZodString>;
146
156
  code: z.ZodString;
147
157
  lowConfidence: z.ZodExactOptional<z.ZodLiteral<true>>;
158
+ preExisting: z.ZodExactOptional<z.ZodLiteral<true>>;
148
159
  provenance: z.ZodExactOptional<z.ZodObject<{
149
160
  task: z.ZodString;
150
161
  model: z.ZodExactOptional<z.ZodString>;
@@ -168,6 +179,22 @@ export declare const reportOutputSchema: z.ZodObject<{
168
179
  repository: "repository";
169
180
  }>>;
170
181
  }, z.core.$strip>>;
182
+ learnings: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
183
+ id: z.ZodString;
184
+ title: z.ZodString;
185
+ critical: z.ZodBoolean;
186
+ source: z.ZodExactOptional<z.ZodObject<{
187
+ kind: z.ZodString;
188
+ ref: z.ZodExactOptional<z.ZodString>;
189
+ }, z.core.$strict>>;
190
+ bundles: z.ZodArray<z.ZodString>;
191
+ }, z.core.$strict>>>;
192
+ analyzerEvidence: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
193
+ tool: z.ZodString;
194
+ version: z.ZodExactOptional<z.ZodString>;
195
+ results: z.ZodInt;
196
+ bundles: z.ZodArray<z.ZodString>;
197
+ }, z.core.$strict>>>;
171
198
  judgement: z.ZodExactOptional<z.ZodObject<{
172
199
  merged: z.ZodArray<z.ZodObject<{
173
200
  kept: z.ZodString;
@@ -302,6 +329,9 @@ export declare const reportOutputSchema: z.ZodObject<{
302
329
  costUsd: z.ZodNumber;
303
330
  }, z.core.$strict>;
304
331
  reusedFrom: z.ZodExactOptional<z.ZodString>;
332
+ wrapUp: z.ZodExactOptional<z.ZodObject<{
333
+ findings: z.ZodInt;
334
+ }, z.core.$strict>>;
305
335
  }, z.core.$strict>>;
306
336
  skipped: z.ZodArray<z.ZodObject<{
307
337
  reviewer: z.ZodString;
@@ -2,8 +2,8 @@ import { z } from "zod";
2
2
  import { EFFORT_LEVELS } from "../agent/settings.js";
3
3
  import { INCOMPLETE_ENDINGS, MODEL_TIERS } from "../contracts.js";
4
4
  import { anchorMethodSchema, riskTierSchema, severitySchema, verdictSchema, verificationSchema, } from "../domain.js";
5
+ import { skipReasonSchema } from "../matrix/matrix.js";
5
6
  import { memoryEntrySchema } from "../memory/memory.js";
6
- import { skipReasonSchema } from "../pipeline/matrix.js";
7
7
  import { exclusionReasonSchema } from "../select/select.js";
8
8
  import { taskStatusSchema } from "./report.js";
9
9
  // The published shape of a review: `--format json` and a session's
@@ -73,6 +73,7 @@ const outputFindingSchema = z.strictObject({
73
73
  evidence: z.array(z.string()),
74
74
  code: z.string(),
75
75
  lowConfidence: z.literal(true).exactOptional(),
76
+ preExisting: z.literal(true).exactOptional(),
76
77
  provenance: z
77
78
  .strictObject({ task: z.string(), model: z.string().exactOptional() })
78
79
  .exactOptional(),
@@ -119,6 +120,8 @@ export const taskOutcomeSchema = z.strictObject({
119
120
  usage: usageSchema,
120
121
  // Taken from this earlier run (--resume): usage is what that run paid.
121
122
  reusedFrom: z.string().exactOptional(),
123
+ // The agent ended without task_done and was given the wrap-up turn.
124
+ wrapUp: z.strictObject({ findings: z.int().nonnegative() }).exactOptional(),
122
125
  });
123
126
  export const skippedCellSchema = z.strictObject({
124
127
  reviewer: z.string(),
@@ -130,7 +133,7 @@ const anchoringSummarySchema = z.strictObject({
130
133
  ambiguous: z.int().nonnegative(),
131
134
  relocationCalls: z.int().nonnegative(),
132
135
  });
133
- const scopeSchema = z.discriminatedUnion("mode", [
136
+ export const scopeSchema = z.discriminatedUnion("mode", [
134
137
  z.strictObject({ mode: z.literal("incremental"), since: z.string() }),
135
138
  z.strictObject({ mode: z.literal("full"), reason: z.string() }),
136
139
  ]);
@@ -175,6 +178,25 @@ export const reportOutputSchema = z.strictObject({
175
178
  unverifiedCriticals: z.int().nonnegative(),
176
179
  refuted: z.array(refutedFindingSchema),
177
180
  remembered: z.array(memoryEntrySchema.extend({ source: z.enum(["repository", "account"]).exactOptional() })),
181
+ learnings: z
182
+ .array(z.strictObject({
183
+ id: z.string(),
184
+ title: z.string(),
185
+ critical: z.boolean(),
186
+ source: z
187
+ .strictObject({ kind: z.string(), ref: z.string().exactOptional() })
188
+ .exactOptional(),
189
+ bundles: z.array(z.string()),
190
+ }))
191
+ .exactOptional(),
192
+ analyzerEvidence: z
193
+ .array(z.strictObject({
194
+ tool: z.string(),
195
+ version: z.string().exactOptional(),
196
+ results: z.int().nonnegative(),
197
+ bundles: z.array(z.string()),
198
+ }))
199
+ .exactOptional(),
178
200
  judgement: judgeDecisionsSchema.exactOptional(),
179
201
  rereview: z
180
202
  .strictObject({
@@ -20,6 +20,16 @@ export function toReportOutput(report) {
20
20
  };
21
21
  if (report.scope)
22
22
  output.scope = outputScope(report.scope);
23
+ if (report.learnings)
24
+ output.learnings = report.learnings.map(outputLearning);
25
+ if (report.analyzerEvidence) {
26
+ output.analyzerEvidence = report.analyzerEvidence.map((e) => ({
27
+ tool: e.tool,
28
+ ...(e.version ? { version: e.version } : {}),
29
+ results: e.results,
30
+ bundles: [...e.bundles],
31
+ }));
32
+ }
23
33
  if (report.judgement)
24
34
  output.judgement = outputJudgement(report.judgement);
25
35
  if (report.anchoring)
@@ -40,6 +50,17 @@ export function toReportOutput(report) {
40
50
  }
41
51
  return output;
42
52
  }
53
+ function outputLearning(l) {
54
+ return {
55
+ id: l.id,
56
+ title: l.title,
57
+ critical: l.critical,
58
+ ...(l.source
59
+ ? { source: { kind: l.source.kind, ...(l.source.ref ? { ref: l.source.ref } : {}) } }
60
+ : {}),
61
+ bundles: [...l.bundles],
62
+ };
63
+ }
43
64
  function outputChangeRequest(c) {
44
65
  return {
45
66
  id: c.id,
@@ -85,6 +106,8 @@ function outputFinding(f) {
85
106
  }
86
107
  if (f.lowConfidence)
87
108
  output.lowConfidence = true;
109
+ if (f.preExisting)
110
+ output.preExisting = true;
88
111
  output.provenance =
89
112
  f.provenance.model === undefined
90
113
  ? { task: f.provenance.task }
@@ -117,6 +140,7 @@ function outputTask(t) {
117
140
  ...(t.error === undefined ? {} : { error: t.error }),
118
141
  ...(t.ended === undefined ? {} : { ended: t.ended }),
119
142
  ...(t.reusedFrom === undefined ? {} : { reusedFrom: t.reusedFrom }),
143
+ ...(t.wrapUp === undefined ? {} : { wrapUp: { findings: t.wrapUp.findings } }),
120
144
  };
121
145
  }
122
146
  function outputSkipped(s) {