@open-cr-agent/core 0.7.0 → 0.10.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 (122) 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 +10 -5
  4. package/dist/agent/settings.js +22 -8
  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/chat/answer.d.ts +10 -0
  12. package/dist/chat/answer.js +26 -0
  13. package/dist/chat/prompt.d.ts +22 -0
  14. package/dist/chat/prompt.js +65 -0
  15. package/dist/contracts.d.ts +27 -0
  16. package/dist/contracts.js +10 -0
  17. package/dist/domain.d.ts +7 -0
  18. package/dist/domain.js +2 -0
  19. package/dist/index.d.ts +10 -7
  20. package/dist/index.js +4 -4
  21. package/dist/internal.d.ts +8 -3
  22. package/dist/internal.js +8 -3
  23. package/dist/judge/judge.d.ts +1 -1
  24. package/dist/judge/judge.js +10 -13
  25. package/dist/judge/prompt.d.ts +1 -1
  26. package/dist/judge/prompt.js +10 -1
  27. package/dist/judge/verdict.d.ts +2 -1
  28. package/dist/judge/verdict.js +4 -2
  29. package/dist/knowledge/learning.d.ts +21 -0
  30. package/dist/knowledge/learning.js +1 -0
  31. package/dist/knowledge/paths.d.ts +1 -0
  32. package/dist/knowledge/paths.js +18 -0
  33. package/dist/knowledge/select.d.ts +15 -0
  34. package/dist/knowledge/select.js +116 -0
  35. package/dist/knowledge/terms.d.ts +21 -0
  36. package/dist/knowledge/terms.js +153 -0
  37. package/dist/learn/draft.d.ts +21 -0
  38. package/dist/learn/draft.js +126 -0
  39. package/dist/{pipeline → matrix}/matrix.d.ts +1 -2
  40. package/dist/{pipeline → matrix}/matrix.js +1 -1
  41. package/dist/pipeline/answer.d.ts +16 -0
  42. package/dist/pipeline/answer.js +29 -0
  43. package/dist/pipeline/assemble-report.d.ts +2 -6
  44. package/dist/pipeline/assemble-report.js +38 -22
  45. package/dist/pipeline/check-stage.js +31 -11
  46. package/dist/pipeline/context.d.ts +2 -1
  47. package/dist/pipeline/context.js +19 -3
  48. package/dist/pipeline/coverage.d.ts +1 -1
  49. package/dist/pipeline/execute-stage.d.ts +5 -5
  50. package/dist/pipeline/execute-stage.js +27 -30
  51. package/dist/pipeline/execute.d.ts +12 -7
  52. package/dist/pipeline/execute.js +40 -55
  53. package/dist/pipeline/filter-stage.js +2 -0
  54. package/dist/pipeline/imports.js +2 -16
  55. package/dist/pipeline/learnings.d.ts +7 -0
  56. package/dist/pipeline/learnings.js +20 -0
  57. package/dist/pipeline/options.d.ts +22 -1
  58. package/dist/pipeline/options.js +32 -0
  59. package/dist/pipeline/plan-output.d.ts +7 -0
  60. package/dist/pipeline/plan-output.js +9 -1
  61. package/dist/pipeline/plan.d.ts +14 -8
  62. package/dist/pipeline/plan.js +60 -8
  63. package/dist/pipeline/preview.d.ts +5 -4
  64. package/dist/pipeline/preview.js +20 -27
  65. package/dist/pipeline/run.js +23 -47
  66. package/dist/pipeline/task-prompt.d.ts +17 -0
  67. package/dist/pipeline/task-prompt.js +44 -0
  68. package/dist/pipeline/task.d.ts +3 -0
  69. package/dist/pipeline/task.js +3 -1
  70. package/dist/pipeline/walkthrough-stage.d.ts +9 -0
  71. package/dist/pipeline/walkthrough-stage.js +20 -0
  72. package/dist/report/output-schema.d.ts +39 -0
  73. package/dist/report/output-schema.js +31 -2
  74. package/dist/report/output.js +33 -0
  75. package/dist/report/report.d.ts +34 -2
  76. package/dist/report/report.js +29 -0
  77. package/dist/review/impact.d.ts +21 -4
  78. package/dist/review/impact.js +186 -28
  79. package/dist/review/plan-phase.d.ts +1 -1
  80. package/dist/review/plan-phase.js +13 -12
  81. package/dist/review/prompt-text.d.ts +1 -1
  82. package/dist/review/prompt-text.js +84 -20
  83. package/dist/review/prompt.d.ts +6 -0
  84. package/dist/review/prompt.js +57 -2
  85. package/dist/review/tools.d.ts +1 -0
  86. package/dist/review/tools.js +1 -0
  87. package/dist/runtime/attempt.d.ts +12 -0
  88. package/dist/runtime/attempt.js +21 -1
  89. package/dist/runtime/chain-runner.d.ts +2 -2
  90. package/dist/runtime/failback.d.ts +2 -2
  91. package/dist/runtime/failback.js +29 -12
  92. package/dist/runtime/tools.js +11 -0
  93. package/dist/runtime/wrap-up.d.ts +6 -0
  94. package/dist/runtime/wrap-up.js +27 -0
  95. package/dist/sarif/candidates.d.ts +3 -2
  96. package/dist/sarif/candidates.js +2 -0
  97. package/dist/sarif/evidence.d.ts +42 -0
  98. package/dist/sarif/evidence.js +142 -0
  99. package/dist/sarif/schema.d.ts +18 -0
  100. package/dist/sarif/schema.js +8 -0
  101. package/dist/select/patterns.d.ts +1 -0
  102. package/dist/select/patterns.js +46 -0
  103. package/dist/select/select.d.ts +1 -0
  104. package/dist/select/select.js +18 -1
  105. package/dist/session/resume-read.js +3 -0
  106. package/dist/session/seal.js +5 -0
  107. package/dist/vcs.d.ts +22 -0
  108. package/dist/verify/prompt.d.ts +6 -2
  109. package/dist/verify/prompt.js +13 -4
  110. package/dist/verify/related.d.ts +3 -0
  111. package/dist/verify/related.js +88 -0
  112. package/dist/verify/verify.d.ts +3 -3
  113. package/dist/verify/verify.js +27 -19
  114. package/dist/walkthrough/diagram.d.ts +1 -0
  115. package/dist/walkthrough/diagram.js +49 -0
  116. package/dist/walkthrough/prompt.d.ts +19 -0
  117. package/dist/walkthrough/prompt.js +62 -0
  118. package/dist/walkthrough/walkthrough.d.ts +27 -0
  119. package/dist/walkthrough/walkthrough.js +71 -0
  120. package/package.json +3 -3
  121. package/dist/agent/budget.d.ts +0 -12
  122. package/dist/agent/budget.js +0 -27
@@ -1,53 +1,44 @@
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 { securityReviewed } from "../sarif/evidence.js";
6
+ import { runSettings } from "./options.js";
9
7
  import { planReview } from "./plan.js";
8
+ import { taskPrompt } from "./task-prompt.js";
10
9
  // Everything a review would do before its first model call, for free: which
11
10
  // files, which tasks, and how large each first prompt is.
12
11
  export async function previewReview(options) {
13
- const plan = await planReview(options, () => { }, new AbortController().signal);
12
+ const settings = runSettings(options);
13
+ const plan = await planReview({ ...options, full: settings.full }, () => { }, new AbortController().signal);
14
14
  const reviewers = options.reviewers ?? [correctnessReviewer];
15
15
  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 } : {}),
16
+ ultra: settings.ultra,
17
+ ...(settings.maxTasks !== undefined ? { maxTasks: settings.maxTasks } : {}),
18
18
  hasGuidelines: Boolean(plan.guidelines?.trim()),
19
19
  });
20
20
  const { cells } = planned;
21
21
  const plannedBundles = new Set();
22
+ const securityFiles = securityReviewed(cells);
22
23
  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);
24
+ const prepared = taskPrompt(cell, plan, { ultra: settings.ultra, securityFiles });
34
25
  const task = {
35
26
  taskId: cell.taskId,
36
27
  reviewer: cell.reviewer.id,
37
28
  bundle: cell.bundle.label,
38
- files,
39
- promptTokens: tokens(prompt),
29
+ files: cell.bundle.files.map((f) => f.newPath),
30
+ promptTokens: tokens(prepared.prompt),
40
31
  };
41
32
  const call = reviewerCall(cell.reviewer, options);
42
33
  if (call.effort !== undefined)
43
34
  task.effort = call.effort;
44
- const models = call.models ?? options.models?.[cell.reviewer.modelTier];
35
+ const models = chainOf(call, cell.reviewer.modelTier, options);
45
36
  if (models?.length)
46
37
  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 }));
38
+ const { planCall } = prepared;
39
+ if (planCall && !plannedBundles.has(planCall.key)) {
40
+ plannedBundles.add(planCall.key);
41
+ task.planPromptTokens = tokens(planCall.prompt());
51
42
  }
52
43
  const first = task.models?.[0];
53
44
  if (first !== undefined && options.inputPrice) {
@@ -59,6 +50,7 @@ export async function previewReview(options) {
59
50
  return {
60
51
  changeRequest: plan.changeRequest,
61
52
  tier: plan.tier,
53
+ ...(plan.scope ? { scope: plan.scope } : {}),
62
54
  selected: plan.selected.map((d) => d.newPath),
63
55
  excluded: plan.decisions.flatMap((d) => d.selected ? [] : [{ path: d.diff.newPath, reason: d.reason }]),
64
56
  bundles: plan.bundles.map((b) => ({ label: b.label, files: b.files.map((f) => f.newPath) })),
@@ -69,6 +61,7 @@ export async function previewReview(options) {
69
61
  planCalls: tasks.filter((t) => t.planPromptTokens !== undefined).length,
70
62
  ...(tasks.some((t) => t.inputCost) ? { inputCost: totalInputCost(tasks) } : {}),
71
63
  warnings: [
64
+ ...(plan.prior.warning ? [plan.prior.warning] : []),
72
65
  ...plan.warnings,
73
66
  ...(planned.limited?.length
74
67
  ? [
@@ -1,70 +1,46 @@
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
+ import { walkthroughStage } from "./walkthrough-stage.js";
11
12
  // The library entry: plan (deterministic stages) → execute (one agent task
12
- // per cell) → filter (memory, the previous review) → check (verify, judge)
13
- // → report. The `ocra` command is one caller. The manual's Embedding page
14
- // says which options are a contract.
13
+ // per cell, beside the walkthrough) → filter (memory, the previous review)
14
+ // → check (verify, judge) → report. The `ocra` command is one caller. The
15
+ // manual's Embedding page says which options are a contract.
15
16
  export function review(options) {
16
17
  return reviewWithHooks(options);
17
18
  }
18
19
  export async function reviewWithHooks(options) {
20
+ const settings = runSettings(options);
19
21
  const emit = options.onEvent ?? (() => { });
20
- const timeout = AbortSignal.timeout(Math.min(options.limits?.runTimeoutMs ?? REVIEW_DEFAULTS.runTimeoutMs, MAX_TIMER_MS));
22
+ const timeout = AbortSignal.timeout(settings.runTimeoutMs);
21
23
  const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
22
24
  const reviewers = options.reviewers ?? [correctnessReviewer];
23
25
  if (reviewers.length === 0)
24
26
  throw new OcraError("CONFIG_INVALID", "No reviewer is registered");
25
27
  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 };
28
+ const plan = await planReview({ ...options, runId, full: settings.full }, emit, signal);
29
+ for (const usage of plan.usage)
30
+ emit({ type: "usage_reported", usage });
31
+ const context = {
32
+ options,
33
+ settings,
34
+ plan,
35
+ spendLimit: spendLimit(settings.maxCostUsd, plan.usage, (usage) => emit({ type: "usage_reported", usage })),
36
+ signal,
37
+ emit,
38
+ };
39
+ const walkthrough = walkthroughStage(context);
38
40
  const executed = await executeStage(reviewers, context);
39
- const filtered = await filterStage(executed, prior.review, context);
41
+ const filtered = await filterStage(executed, plan.prior.review, context);
40
42
  const checked = await checkStage(filtered, context);
41
- const report = assembleReport({ runId, reviewers, prior, scopeNote: scope.note }, { executed, filtered, checked }, context);
43
+ const report = assembleReport({ runId, reviewers }, { executed, filtered, checked, walkthrough: await walkthrough }, context);
42
44
  emit({ type: "run_finished", report });
43
45
  return report;
44
46
  }
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,17 @@
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 interface TaskSettings {
14
+ ultra: boolean;
15
+ securityFiles: ReadonlySet<string>;
16
+ }
17
+ export declare function taskPrompt(cell: MatrixCell, plan: ReviewPlan, { ultra, securityFiles }: TaskSettings): TaskPrompt;
@@ -0,0 +1,44 @@
1
+ import { memoryFor } from "../memory/memory.js";
2
+ import { buildReviewPrompt } from "../review/prompt.js";
3
+ import { resolveRules } from "../rules/resolve.js";
4
+ import { evidenceForReviewer } from "../sarif/evidence.js";
5
+ // In default mode only bundles large enough that a reviewer's 30 steps may
6
+ // not cover them get a plan phase; --ultra plans every task.
7
+ const PLAN_MIN_FILES = 5;
8
+ const PLAN_MIN_PATCH_CHARS = 40_000;
9
+ // What one task of the matrix sends: the run builds its prompt from this and
10
+ // --plan previews it, so the preview cannot drift from the run.
11
+ export function taskPrompt(cell, plan, { ultra, securityFiles }) {
12
+ const files = cell.bundle.files.map((f) => f.newPath);
13
+ const learnings = plan.learnings(cell.bundle.files);
14
+ const analyzerResults = evidenceForReviewer(plan.evidence.forBundle(cell.bundle), cell.reviewer.category, securityFiles);
15
+ const input = {
16
+ reviewer: cell.reviewer,
17
+ changeRequest: plan.changeRequest,
18
+ changedFiles: plan.selected,
19
+ bundle: cell.bundle.files,
20
+ rules: resolveRules(files, plan.repoRules, cell.reviewer.rules),
21
+ guidelines: plan.guidelines,
22
+ accepted: memoryFor(files, plan.memory),
23
+ learnings: learnings.selected,
24
+ moreLearnings: learnings.left,
25
+ ...(analyzerResults.length > 0 ? { analyzerResults } : {}),
26
+ };
27
+ const prompt = buildReviewPrompt(input);
28
+ const callers = ultra || plan.tier === "full";
29
+ if (!ultra && !isLargeBundle(cell.bundle))
30
+ return { input, prompt, callers };
31
+ return {
32
+ input,
33
+ prompt,
34
+ callers,
35
+ planCall: {
36
+ key: `${cell.reviewer.id}\0${cell.bundle.label}`,
37
+ prompt: () => buildReviewPrompt({ ...input, forPlanning: true }),
38
+ },
39
+ };
40
+ }
41
+ function isLargeBundle({ files }) {
42
+ const chars = files.reduce((sum, f) => sum + f.patch.length, 0);
43
+ return files.length >= PLAN_MIN_FILES || chars >= PLAN_MIN_PATCH_CHARS;
44
+ }
@@ -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";
@@ -0,0 +1,9 @@
1
+ import type { Usage } from "../contracts.js";
2
+ import { type Walkthrough } from "../walkthrough/walkthrough.js";
3
+ import type { StageContext } from "./execute-stage.js";
4
+ export interface WalkthroughStage {
5
+ walkthrough?: Walkthrough;
6
+ usage: Usage[];
7
+ warnings: string[];
8
+ }
9
+ export declare function walkthroughStage({ options, settings, plan, spendLimit, signal, }: StageContext): Promise<WalkthroughStage>;
@@ -0,0 +1,20 @@
1
+ import { roleCall } from "../agent/settings.js";
2
+ import { writeWalkthrough } from "../walkthrough/walkthrough.js";
3
+ // Runs beside the review tasks: it reads only the plan, and never rejects.
4
+ export async function walkthroughStage({ options, settings, plan, spendLimit, signal, }) {
5
+ if (!settings.walkthrough || !spendLimit.mayCall())
6
+ return { usage: [], warnings: [] };
7
+ const usage = [];
8
+ const result = await writeWalkthrough({
9
+ runtime: options.runtime,
10
+ changeRequest: plan.changeRequest,
11
+ files: plan.selected,
12
+ signal,
13
+ onUsage: (u) => {
14
+ usage.push(u);
15
+ spendLimit.charge(u);
16
+ },
17
+ call: roleCall("writer", options),
18
+ });
19
+ return { ...result, usage };
20
+ }
@@ -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;
@@ -194,6 +221,15 @@ export declare const reportOutputSchema: z.ZodObject<{
194
221
  reason: z.ZodString;
195
222
  }, z.core.$strict>>;
196
223
  }, z.core.$strict>>;
224
+ walkthrough: z.ZodExactOptional<z.ZodObject<{
225
+ overview: z.ZodString;
226
+ groups: z.ZodArray<z.ZodObject<{
227
+ title: z.ZodString;
228
+ files: z.ZodArray<z.ZodString>;
229
+ note: z.ZodString;
230
+ }, z.core.$strict>>;
231
+ diagram: z.ZodExactOptional<z.ZodString>;
232
+ }, z.core.$strict>>;
197
233
  rereview: z.ZodExactOptional<z.ZodObject<{
198
234
  fixed: z.ZodArray<z.ZodObject<{
199
235
  fingerprint: z.ZodString;
@@ -302,6 +338,9 @@ export declare const reportOutputSchema: z.ZodObject<{
302
338
  costUsd: z.ZodNumber;
303
339
  }, z.core.$strict>;
304
340
  reusedFrom: z.ZodExactOptional<z.ZodString>;
341
+ wrapUp: z.ZodExactOptional<z.ZodObject<{
342
+ findings: z.ZodInt;
343
+ }, z.core.$strict>>;
305
344
  }, z.core.$strict>>;
306
345
  skipped: z.ZodArray<z.ZodObject<{
307
346
  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,7 +178,33 @@ 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(),
201
+ walkthrough: z
202
+ .strictObject({
203
+ overview: z.string(),
204
+ groups: z.array(z.strictObject({ title: z.string(), files: z.array(z.string()), note: z.string() })),
205
+ diagram: z.string().exactOptional(),
206
+ })
207
+ .exactOptional(),
179
208
  rereview: z
180
209
  .strictObject({
181
210
  fixed: priorList,
@@ -20,8 +20,20 @@ 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);
35
+ if (report.walkthrough)
36
+ output.walkthrough = outputWalkthrough(report.walkthrough);
25
37
  if (report.anchoring)
26
38
  output.anchoring = outputAnchoring(report.anchoring);
27
39
  if (report.spendLimit)
@@ -40,6 +52,24 @@ export function toReportOutput(report) {
40
52
  }
41
53
  return output;
42
54
  }
55
+ function outputWalkthrough(w) {
56
+ return {
57
+ overview: w.overview,
58
+ groups: w.groups.map((g) => ({ title: g.title, files: [...g.files], note: g.note })),
59
+ ...(w.diagram ? { diagram: w.diagram } : {}),
60
+ };
61
+ }
62
+ function outputLearning(l) {
63
+ return {
64
+ id: l.id,
65
+ title: l.title,
66
+ critical: l.critical,
67
+ ...(l.source
68
+ ? { source: { kind: l.source.kind, ...(l.source.ref ? { ref: l.source.ref } : {}) } }
69
+ : {}),
70
+ bundles: [...l.bundles],
71
+ };
72
+ }
43
73
  function outputChangeRequest(c) {
44
74
  return {
45
75
  id: c.id,
@@ -85,6 +115,8 @@ function outputFinding(f) {
85
115
  }
86
116
  if (f.lowConfidence)
87
117
  output.lowConfidence = true;
118
+ if (f.preExisting)
119
+ output.preExisting = true;
88
120
  output.provenance =
89
121
  f.provenance.model === undefined
90
122
  ? { task: f.provenance.task }
@@ -117,6 +149,7 @@ function outputTask(t) {
117
149
  ...(t.error === undefined ? {} : { error: t.error }),
118
150
  ...(t.ended === undefined ? {} : { ended: t.ended }),
119
151
  ...(t.reusedFrom === undefined ? {} : { reusedFrom: t.reusedFrom }),
152
+ ...(t.wrapUp === undefined ? {} : { wrapUp: { findings: t.wrapUp.findings } }),
120
153
  };
121
154
  }
122
155
  function outputSkipped(s) {
@@ -2,10 +2,13 @@ import { z } from "zod";
2
2
  import type { AttemptRecord, IncompleteEnding, Usage } from "../contracts.js";
3
3
  import type { AnchorMethod, ChangeRequest, Finding, PriorFinding, RiskTier, TaskFinding, Verdict } from "../domain.js";
4
4
  import type { JudgeDecisions } from "../judge/judge.js";
5
+ import type { LearningUse } from "../knowledge/learning.js";
6
+ import type { SkippedCell } from "../matrix/matrix.js";
5
7
  import type { RememberedEntry } from "../memory/memory.js";
6
- import type { SkippedCell } from "../pipeline/matrix.js";
8
+ import type { AnalyzerEvidenceUse } from "../sarif/evidence.js";
7
9
  import type { ExclusionReason } from "../select/select.js";
8
10
  import type { RefutedFinding } from "../verify/verify.js";
11
+ import type { Walkthrough } from "../walkthrough/walkthrough.js";
9
12
  import type { RunProvenance } from "./provenance.js";
10
13
  export type CoverageEntry = {
11
14
  path: string;
@@ -28,6 +31,18 @@ export declare function coverageGaps(run: {
28
31
  nothingReviewed: boolean;
29
32
  incomplete: Record<IncompleteEnding, number>;
30
33
  };
34
+ export declare function isIncompleteReview(run: {
35
+ coverage: readonly CoverageEntry[];
36
+ unverifiedCriticals: number;
37
+ }): boolean;
38
+ export declare function isBlocking(run: {
39
+ verdict: Verdict;
40
+ changeRequest: Pick<ChangeRequest, "override">;
41
+ }): boolean;
42
+ export declare function unconfirmedCriticals(run: {
43
+ verdict: Verdict;
44
+ findings: readonly Pick<Finding, "severity" | "verification" | "lowConfidence">[];
45
+ }): number;
31
46
  export declare const taskStatusSchema: z.ZodEnum<{
32
47
  cancelled: "cancelled";
33
48
  completed: "completed";
@@ -47,6 +62,9 @@ export interface TaskOutcome {
47
62
  durationMs: number;
48
63
  usage: Usage;
49
64
  reusedFrom?: string;
65
+ wrapUp?: {
66
+ findings: number;
67
+ };
50
68
  }
51
69
  export interface ReviewReport {
52
70
  runId: string;
@@ -65,7 +83,10 @@ export interface ReviewReport {
65
83
  unverifiedCriticals: number;
66
84
  refuted: RefutedFinding[];
67
85
  remembered: RememberedEntry[];
86
+ learnings?: LearningUse[];
87
+ analyzerEvidence?: AnalyzerEvidenceUse[];
68
88
  judgement?: JudgeDecisions;
89
+ walkthrough?: Walkthrough;
69
90
  scope?: {
70
91
  mode: "incremental";
71
92
  since: string;
@@ -89,10 +110,15 @@ export interface ReviewReport {
89
110
  usage: Usage;
90
111
  warnings: string[];
91
112
  }
113
+ export declare const REVIEW_STAGES: readonly ["select", "bundle", "plan", "review", "filter", "verify", "judge"];
114
+ export type ReviewStage = (typeof REVIEW_STAGES)[number];
92
115
  export type ReviewEvent = {
93
116
  type: "run_started";
94
117
  runId: string;
95
118
  changeRequest: ChangeRequest;
119
+ } | {
120
+ type: "stage_started";
121
+ stage: ReviewStage;
96
122
  } | {
97
123
  type: "files_selected";
98
124
  selected: number;
@@ -129,7 +155,7 @@ export type ReviewEvent = {
129
155
  } | {
130
156
  type: "finding_dropped";
131
157
  taskId: string;
132
- reason: "outside_bundle";
158
+ reason: "outside_review";
133
159
  file: string;
134
160
  title: string;
135
161
  } | {
@@ -140,6 +166,12 @@ export type ReviewEvent = {
140
166
  } | {
141
167
  type: "task_finished";
142
168
  outcome: TaskOutcome;
169
+ } | {
170
+ type: "coverage_settled";
171
+ coverage: CoverageEntry[];
172
+ } | {
173
+ type: "usage_reported";
174
+ usage: Usage;
143
175
  } | {
144
176
  type: "verification_finished";
145
177
  checked: number;
@@ -21,7 +21,36 @@ export function coverageGaps(run) {
21
21
  run.tasks.some((t) => t.status === "completed");
22
22
  return { notReviewed, nothingReviewed: notReviewed > 0 && !reviewed, incomplete };
23
23
  }
24
+ // An incomplete review: it left an unfinished file or a critical finding
25
+ // Verify could not check, so its result must never be read as a pass. The
26
+ // exit code (3), SARIF, the pull request summary, the ocra Cloud upload and
27
+ // `ocra metrics` all read it from here.
28
+ export function isIncompleteReview(run) {
29
+ return run.coverage.some(isUnfinished) || run.unverifiedCriticals > 0;
30
+ }
31
+ // A verdict that fails the run and requests changes: significant concerns
32
+ // that no one entitled to has overridden for this head commit.
33
+ export function isBlocking(run) {
34
+ return run.verdict === "significant_concerns" && run.changeRequest.override === undefined;
35
+ }
36
+ // Critical findings that only cap the verdict at minor issues: none is
37
+ // confirmed, so none blocks. Zero while a confirmed one blocks, and
38
+ // low-confidence findings do not count toward the verdict at all.
39
+ export function unconfirmedCriticals(run) {
40
+ if (run.verdict === "significant_concerns")
41
+ return 0;
42
+ return run.findings.filter((f) => f.severity === "critical" && f.verification !== "confirmed" && !f.lowConfidence).length;
43
+ }
24
44
  export const taskStatusSchema = z.enum(["completed", "failed", "timed_out", "cancelled"]);
45
+ export const REVIEW_STAGES = [
46
+ "select",
47
+ "bundle",
48
+ "plan",
49
+ "review",
50
+ "filter",
51
+ "verify",
52
+ "judge",
53
+ ];
25
54
  export function summarizeAnchoring(findings, relocationCalls) {
26
55
  const byMethod = {
27
56
  hunk: 0,