@open-cr-agent/core 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +1 -1
  2. package/dist/{pipeline → agent}/budget.d.ts +0 -1
  3. package/dist/{pipeline → agent}/budget.js +0 -1
  4. package/dist/agent/json.d.ts +1 -0
  5. package/dist/agent/json.js +11 -0
  6. package/dist/{pipeline → agent}/pool.d.ts +0 -1
  7. package/dist/{pipeline → agent}/pool.js +2 -2
  8. package/dist/{pipeline/agents.d.ts → agent/settings.d.ts} +9 -5
  9. package/dist/{pipeline/agents.js → agent/settings.js} +14 -6
  10. package/dist/{pipeline → agent}/usage.d.ts +0 -1
  11. package/dist/{pipeline → agent}/usage.js +0 -1
  12. package/dist/anchor/anchor.d.ts +0 -1
  13. package/dist/anchor/anchor.js +0 -1
  14. package/dist/anchor/match.d.ts +0 -1
  15. package/dist/anchor/match.js +5 -5
  16. package/dist/anchor/relocate.d.ts +1 -3
  17. package/dist/anchor/relocate.js +2 -3
  18. package/dist/at.d.ts +1 -0
  19. package/dist/at.js +11 -0
  20. package/dist/bounded-file.d.ts +12 -0
  21. package/dist/bounded-file.js +47 -0
  22. package/dist/bundle/bundle.d.ts +2 -2
  23. package/dist/bundle/bundle.js +3 -3
  24. package/dist/bundle/grouping.d.ts +0 -2
  25. package/dist/bundle/grouping.js +0 -1
  26. package/dist/bundle/runtime-grouper.d.ts +4 -0
  27. package/dist/{pipeline/helpers.js → bundle/runtime-grouper.js} +4 -14
  28. package/dist/contracts.d.ts +16 -15
  29. package/dist/contracts.js +6 -2
  30. package/dist/diff/hunks.d.ts +0 -1
  31. package/dist/diff/hunks.js +3 -3
  32. package/dist/diff/parse.d.ts +0 -1
  33. package/dist/diff/parse.js +5 -5
  34. package/dist/diff/quoted-path.d.ts +0 -1
  35. package/dist/diff/quoted-path.js +16 -16
  36. package/dist/domain.d.ts +14 -3
  37. package/dist/domain.js +2 -3
  38. package/dist/errors.d.ts +3 -2
  39. package/dist/errors.js +12 -1
  40. package/dist/hash.d.ts +1 -0
  41. package/dist/hash.js +6 -0
  42. package/dist/index.d.ts +27 -13
  43. package/dist/index.js +16 -6
  44. package/dist/internal.d.ts +10 -13
  45. package/dist/internal.js +10 -13
  46. package/dist/judge/judge.d.ts +1 -3
  47. package/dist/judge/judge.js +9 -9
  48. package/dist/judge/prompt.d.ts +0 -1
  49. package/dist/judge/prompt.js +0 -1
  50. package/dist/judge/verdict.d.ts +0 -2
  51. package/dist/judge/verdict.js +1 -2
  52. package/dist/memory/memory.d.ts +0 -1
  53. package/dist/memory/memory.js +2 -3
  54. package/dist/net/proxied-fetch.d.ts +0 -1
  55. package/dist/net/proxied-fetch.js +2 -2
  56. package/dist/pipeline/assemble-report.d.ts +21 -0
  57. package/dist/pipeline/assemble-report.js +98 -0
  58. package/dist/pipeline/check-stage.d.ts +12 -0
  59. package/dist/pipeline/check-stage.js +69 -0
  60. package/dist/pipeline/context.d.ts +2 -2
  61. package/dist/pipeline/context.js +8 -5
  62. package/dist/pipeline/coverage.d.ts +1 -2
  63. package/dist/pipeline/coverage.js +38 -17
  64. package/dist/pipeline/execute-stage.d.ts +25 -0
  65. package/dist/pipeline/execute-stage.js +130 -0
  66. package/dist/pipeline/execute.d.ts +11 -6
  67. package/dist/pipeline/execute.js +147 -59
  68. package/dist/pipeline/filter-stage.d.ts +15 -0
  69. package/dist/pipeline/filter-stage.js +45 -0
  70. package/dist/pipeline/findings.d.ts +0 -1
  71. package/dist/pipeline/findings.js +3 -3
  72. package/dist/pipeline/imports.d.ts +1 -2
  73. package/dist/pipeline/imports.js +1 -2
  74. package/dist/pipeline/matrix.d.ts +1 -9
  75. package/dist/pipeline/matrix.js +0 -1
  76. package/dist/pipeline/options.d.ts +66 -0
  77. package/dist/pipeline/options.js +8 -0
  78. package/dist/pipeline/plan-output.d.ts +89 -0
  79. package/dist/pipeline/plan-output.js +108 -0
  80. package/dist/pipeline/plan.d.ts +3 -5
  81. package/dist/pipeline/plan.js +10 -6
  82. package/dist/pipeline/preview.d.ts +23 -10
  83. package/dist/pipeline/preview.js +25 -5
  84. package/dist/pipeline/provenance.d.ts +4 -28
  85. package/dist/pipeline/provenance.js +2 -3
  86. package/dist/pipeline/resume.d.ts +22 -0
  87. package/dist/pipeline/resume.js +24 -0
  88. package/dist/pipeline/run-id.d.ts +0 -1
  89. package/dist/pipeline/run-id.js +0 -1
  90. package/dist/pipeline/run.d.ts +2 -49
  91. package/dist/pipeline/run.js +18 -274
  92. package/dist/pipeline/task.d.ts +5 -10
  93. package/dist/pipeline/task.js +10 -8
  94. package/dist/plugin/builtin.d.ts +1 -1
  95. package/dist/plugin/builtin.js +12 -3
  96. package/dist/plugin/host.d.ts +0 -1
  97. package/dist/plugin/host.js +0 -1
  98. package/dist/plugin/registry.d.ts +5 -5
  99. package/dist/plugin/registry.js +3 -4
  100. package/dist/plugin/types.d.ts +3 -6
  101. package/dist/plugin/types.js +0 -1
  102. package/dist/{pipeline → report}/output-schema.d.ts +95 -63
  103. package/dist/{pipeline → report}/output-schema.js +64 -42
  104. package/dist/report/output.d.ts +7 -0
  105. package/dist/report/output.js +214 -0
  106. package/dist/report/provenance.d.ts +25 -0
  107. package/dist/report/provenance.js +1 -0
  108. package/dist/report/read.d.ts +2 -0
  109. package/dist/report/read.js +36 -0
  110. package/dist/{pipeline → report}/report.d.ts +27 -4
  111. package/dist/{pipeline → report}/report.js +11 -3
  112. package/dist/report/serialize.d.ts +2 -0
  113. package/dist/report/serialize.js +26 -0
  114. package/dist/rereview/presence.d.ts +0 -1
  115. package/dist/rereview/presence.js +1 -2
  116. package/dist/rereview/quote.d.ts +0 -1
  117. package/dist/rereview/quote.js +2 -3
  118. package/dist/rereview/reconcile.d.ts +1 -2
  119. package/dist/rereview/reconcile.js +0 -1
  120. package/dist/review/impact.d.ts +0 -3
  121. package/dist/review/impact.js +2 -3
  122. package/dist/review/plan-phase.d.ts +1 -3
  123. package/dist/review/plan-phase.js +2 -3
  124. package/dist/review/prompt-text.d.ts +1 -2
  125. package/dist/review/prompt-text.js +1 -2
  126. package/dist/review/prompt.d.ts +0 -4
  127. package/dist/review/prompt.js +3 -4
  128. package/dist/review/reviewer.d.ts +0 -1
  129. package/dist/review/reviewer.js +0 -1
  130. package/dist/review/reviewers/agents-md.d.ts +0 -1
  131. package/dist/review/reviewers/agents-md.js +0 -1
  132. package/dist/review/reviewers/correctness.d.ts +0 -1
  133. package/dist/review/reviewers/correctness.js +0 -1
  134. package/dist/review/reviewers/docs.d.ts +0 -1
  135. package/dist/review/reviewers/docs.js +0 -1
  136. package/dist/review/reviewers/performance.d.ts +0 -1
  137. package/dist/review/reviewers/performance.js +0 -1
  138. package/dist/review/reviewers/scopes.d.ts +0 -1
  139. package/dist/review/reviewers/scopes.js +0 -1
  140. package/dist/review/reviewers/security.d.ts +0 -1
  141. package/dist/review/reviewers/security.js +0 -1
  142. package/dist/review/tools.d.ts +0 -1
  143. package/dist/review/tools.js +0 -1
  144. package/dist/rules/builtin/general.d.ts +0 -1
  145. package/dist/rules/builtin/general.js +0 -1
  146. package/dist/rules/builtin/go.d.ts +0 -1
  147. package/dist/rules/builtin/go.js +0 -1
  148. package/dist/rules/builtin/index.d.ts +0 -5
  149. package/dist/rules/builtin/index.js +1 -3
  150. package/dist/rules/builtin/java.d.ts +0 -1
  151. package/dist/rules/builtin/java.js +0 -1
  152. package/dist/rules/builtin/performance.d.ts +0 -1
  153. package/dist/rules/builtin/performance.js +0 -1
  154. package/dist/rules/builtin/python.d.ts +0 -1
  155. package/dist/rules/builtin/python.js +0 -1
  156. package/dist/rules/builtin/security.d.ts +0 -1
  157. package/dist/rules/builtin/security.js +0 -1
  158. package/dist/rules/builtin/typescript.d.ts +0 -1
  159. package/dist/rules/builtin/typescript.js +0 -1
  160. package/dist/rules/languages.d.ts +0 -1
  161. package/dist/rules/languages.js +0 -1
  162. package/dist/rules/repo-rules.d.ts +0 -7
  163. package/dist/rules/repo-rules.js +3 -4
  164. package/dist/rules/resolve.d.ts +0 -1
  165. package/dist/rules/resolve.js +0 -1
  166. package/dist/rules/rule-set.d.ts +0 -1
  167. package/dist/rules/rule-set.js +0 -1
  168. package/dist/runtime/attempt.d.ts +15 -2
  169. package/dist/runtime/attempt.js +47 -1
  170. package/dist/runtime/chain-runner.d.ts +18 -0
  171. package/dist/runtime/chain-runner.js +62 -0
  172. package/dist/runtime/effort-capability.d.ts +13 -0
  173. package/dist/runtime/effort-capability.js +69 -0
  174. package/dist/runtime/failback.d.ts +0 -10
  175. package/dist/runtime/failback.js +52 -13
  176. package/dist/runtime/models.d.ts +1 -3
  177. package/dist/runtime/models.js +14 -13
  178. package/dist/runtime/quota.d.ts +1 -1
  179. package/dist/runtime/quota.js +3 -2
  180. package/dist/runtime/tools.d.ts +0 -17
  181. package/dist/runtime/tools.js +3 -4
  182. package/dist/sarif/candidates.d.ts +2 -2
  183. package/dist/sarif/candidates.js +0 -1
  184. package/dist/sarif/schema.d.ts +2 -3
  185. package/dist/sarif/schema.js +4 -5
  186. package/dist/select/patterns.d.ts +0 -1
  187. package/dist/select/patterns.js +0 -1
  188. package/dist/select/select.d.ts +1 -1
  189. package/dist/select/select.js +16 -3
  190. package/dist/session/jsonl.d.ts +4 -4
  191. package/dist/session/jsonl.js +14 -8
  192. package/dist/session/resume-read.d.ts +2 -0
  193. package/dist/session/resume-read.js +128 -0
  194. package/dist/session/seal.d.ts +5 -0
  195. package/dist/session/seal.js +24 -0
  196. package/dist/triage.d.ts +2 -3
  197. package/dist/triage.js +1 -2
  198. package/dist/vcs.d.ts +14 -0
  199. package/dist/vcs.js +1 -0
  200. package/dist/verify/prompt.d.ts +0 -7
  201. package/dist/verify/prompt.js +1 -2
  202. package/dist/verify/verify.d.ts +2 -4
  203. package/dist/verify/verify.js +4 -5
  204. package/package.json +1 -1
  205. package/dist/pipeline/helpers.d.ts +0 -7
  206. package/dist/pipeline/output.d.ts +0 -79
  207. package/dist/pipeline/output.js +0 -132
@@ -0,0 +1,15 @@
1
+ import type { PriorReview } from "../domain.js";
2
+ import { type RememberedEntry } from "../memory/memory.js";
3
+ import { type CoverageEntry } from "../report/report.js";
4
+ import { type Reconciled } from "../rereview/reconcile.js";
5
+ import type { ExecuteStage, StageContext } from "./execute-stage.js";
6
+ import { type SarifImport } from "./imports.js";
7
+ export interface FilterStage {
8
+ imported: SarifImport;
9
+ coverage: CoverageEntry[];
10
+ remembered: RememberedEntry[];
11
+ reconciled: Reconciled;
12
+ nothingReviewed: boolean;
13
+ warnings: string[];
14
+ }
15
+ export declare function filterStage(executed: ExecuteStage, prior: PriorReview | undefined, { options, plan, emit }: StageContext): Promise<FilterStage>;
@@ -0,0 +1,45 @@
1
+ import { applyMemory } from "../memory/memory.js";
2
+ import { coverageGaps } from "../report/report.js";
3
+ import { priorCodePresence } from "../rereview/presence.js";
4
+ import { reconcile } from "../rereview/reconcile.js";
5
+ import { coverageOf } from "./coverage.js";
6
+ import { dedupeFindings } from "./findings.js";
7
+ import { importSarif } from "./imports.js";
8
+ // Memory and the previous review filter first, so Verify and Judge are not
9
+ // paid for findings that will not be reported, and a person's dismissal
10
+ // keeps a finding out of the verdict whatever the models say.
11
+ export async function filterStage(executed, prior, { options, plan, emit }) {
12
+ const imported = options.sarif && options.sarif.length > 0
13
+ ? await importSarif(options.sarif, plan, emit)
14
+ : { findings: [], outcomes: [], warnings: [] };
15
+ const { results } = executed;
16
+ const found = dedupeFindings([...results.flatMap((r) => r.findings), ...imported.findings]);
17
+ const coverage = coverageOf(plan.decisions, results, plan.unchanged, executed.matrix.limited ?? [], executed.notStarted);
18
+ const remembered = applyMemory(found, plan.memory);
19
+ const reported = new Set(found.map((f) => f.fingerprint));
20
+ const priorReview = withoutRemembered(prior, plan.memory);
21
+ const reconciled = reconcile({
22
+ findings: remembered.kept,
23
+ reported,
24
+ prior: priorReview,
25
+ coverage,
26
+ stillPresent: await priorCodePresence(priorReview, reported, plan.context.readFile),
27
+ });
28
+ const { nothingReviewed } = coverageGaps({ coverage, tasks: results.map((r) => r.outcome) });
29
+ return {
30
+ imported,
31
+ coverage,
32
+ remembered: remembered.remembered,
33
+ reconciled,
34
+ nothingReviewed,
35
+ warnings: imported.warnings,
36
+ };
37
+ }
38
+ // An earlier finding the team has since accepted is no longer open.
39
+ function withoutRemembered(review, memory) {
40
+ if (!review)
41
+ return undefined;
42
+ const accepted = new Set(memory.map((e) => e.fingerprint));
43
+ // Everything else the earlier review carries (replies, tier, head) stays.
44
+ return { ...review, findings: review.findings.filter((f) => !accepted.has(f.fingerprint)) };
45
+ }
@@ -3,4 +3,3 @@ import type { Finding, FindingProvenance, ReportedFinding } from "../domain.js";
3
3
  export declare function fingerprint(category: string, file: string, existingCode: string): string;
4
4
  export declare function toFinding(reported: ReportedFinding, reviewer: string, provenance: FindingProvenance, anchor: Anchor, content?: string): Finding;
5
5
  export declare function dedupeFindings(findings: readonly Finding[]): Finding[];
6
- //# sourceMappingURL=findings.d.ts.map
@@ -1,10 +1,11 @@
1
- import { createHash, randomUUID } from "node:crypto";
1
+ import { randomUUID } from "node:crypto";
2
2
  import { normalizeSnippet } from "../anchor/match.js";
3
+ import { shortHash } from "../hash.js";
3
4
  import { quoteSignature } from "../rereview/quote.js";
4
5
  const SEVERITY_RANK = { suggestion: 0, warning: 1, critical: 2 };
5
6
  export function fingerprint(category, file, existingCode) {
6
7
  const key = [category, file, ...normalizeSnippet(existingCode)].join("\n");
7
- return createHash("sha256").update(key).digest("hex").slice(0, 16);
8
+ return shortHash(key);
8
9
  }
9
10
  // content is the anchored file at head, when the anchor found lines in it.
10
11
  export function toFinding(reported, reviewer, provenance, anchor, content) {
@@ -42,4 +43,3 @@ export function dedupeFindings(findings) {
42
43
  }
43
44
  return [...byFingerprint.values()];
44
45
  }
45
- //# sourceMappingURL=findings.js.map
@@ -1,7 +1,7 @@
1
1
  import type { Finding } from "../domain.js";
2
+ import type { ReviewEvent, TaskOutcome } from "../report/report.js";
2
3
  import type { SarifLog } from "../sarif/schema.js";
3
4
  import type { ReviewPlan } from "./plan.js";
4
- import type { ReviewEvent, TaskOutcome } from "./report.js";
5
5
  export interface SarifImport {
6
6
  findings: Finding[];
7
7
  outcomes: TaskOutcome[];
@@ -9,4 +9,3 @@ export interface SarifImport {
9
9
  }
10
10
  export declare const MAX_IMPORTED_PER_RUN = 200;
11
11
  export declare function importSarif(logs: readonly SarifLog[], plan: Pick<ReviewPlan, "selected" | "context">, emit: (event: ReviewEvent) => void): Promise<SarifImport>;
12
- //# sourceMappingURL=imports.d.ts.map
@@ -1,8 +1,8 @@
1
+ import { emptyUsage } from "../agent/usage.js";
1
2
  import { anchorFinding } from "../anchor/anchor.js";
2
3
  import { sarifCandidates } from "../sarif/candidates.js";
3
4
  import { toFinding } from "./findings.js";
4
5
  import { boundFinding } from "./task.js";
5
- import { emptyUsage } from "./usage.js";
6
6
  // A hostile log could carry thousands of results on the change.
7
7
  export const MAX_IMPORTED_PER_RUN = 200;
8
8
  export async function importSarif(logs, plan, emit) {
@@ -123,4 +123,3 @@ function importWarnings(tool, c) {
123
123
  return [];
124
124
  return [`${tool}: imported ${c.imported} result(s); left out ${left.join(", ")}`];
125
125
  }
126
- //# sourceMappingURL=imports.js.map
@@ -1,16 +1,9 @@
1
1
  import { z } from "zod";
2
+ import type { ReviewerOverrides } from "../agent/settings.js";
2
3
  import type { Bundle } from "../bundle/bundle.js";
3
- import type { Effort } from "../contracts.js";
4
4
  import type { RiskTier } from "../domain.js";
5
5
  import type { ReviewerDefinition } from "../review/reviewer.js";
6
6
  export declare const RISK_TIERS: readonly RiskTier[];
7
- export interface ReviewerOverride {
8
- enabled?: boolean | undefined;
9
- minTier?: RiskTier | undefined;
10
- effort?: Effort | undefined;
11
- models?: readonly string[] | undefined;
12
- }
13
- export type ReviewerOverrides = Readonly<Record<string, ReviewerOverride>>;
14
7
  export interface MatrixCell {
15
8
  taskId: string;
16
9
  reviewer: ReviewerDefinition;
@@ -46,4 +39,3 @@ export interface TaskOptions {
46
39
  }
47
40
  export declare function planTasks(bundles: readonly Bundle[], reviewers: readonly ReviewerDefinition[], tier: RiskTier, overrides?: ReviewerOverrides, options?: TaskOptions): ReviewMatrix;
48
41
  export declare function rank(tier: RiskTier): number;
49
- //# sourceMappingURL=matrix.d.ts.map
@@ -98,4 +98,3 @@ function ignoreMatcher(reviewer) {
98
98
  const globs = reviewer.scope?.ignore ?? [];
99
99
  return globs.length === 0 ? () => false : picomatch([...globs], { dot: true, nocase: true });
100
100
  }
101
- //# sourceMappingURL=matrix.js.map
@@ -0,0 +1,66 @@
1
+ import type { ReviewerOverrides, RoleSettings, TierEfforts } from "../agent/settings.js";
2
+ import type { AnchorContext } from "../anchor/anchor.js";
3
+ import type { BundlePolicy } from "../bundle/bundle.js";
4
+ import type { FileGrouper } from "../bundle/grouping.js";
5
+ import type { AgentRuntime, ModelChains } from "../contracts.js";
6
+ import type { MemoryEntry } from "../memory/memory.js";
7
+ import type { ReviewEvent } from "../report/report.js";
8
+ import type { ReviewerDefinition } from "../review/reviewer.js";
9
+ import type { SourcedRule } from "../rules/repo-rules.js";
10
+ import type { SarifLog } from "../sarif/schema.js";
11
+ import type { SelectionPolicy } from "../select/select.js";
12
+ import type { VcsAdapter } from "../vcs.js";
13
+ import type { ProvenanceInput } from "./provenance.js";
14
+ import type { ResumedRun } from "./resume.js";
15
+ export interface ReviewOptions {
16
+ vcs: VcsAdapter;
17
+ runtime: AgentRuntime;
18
+ reviewers?: readonly ReviewerDefinition[];
19
+ reviewerOverrides?: ReviewerOverrides;
20
+ effort?: TierEfforts;
21
+ roles?: RoleSettings;
22
+ models?: ModelChains;
23
+ rules?: readonly SourcedRule[];
24
+ readTrusted?: (path: string) => Promise<string | undefined>;
25
+ accountMemory?: readonly MemoryEntry[];
26
+ selection?: Partial<SelectionPolicy>;
27
+ limits?: ReviewLimits;
28
+ stages?: ReviewStages;
29
+ mode?: ReviewMode;
30
+ identity?: RunIdentity;
31
+ resume?: ResumedRun;
32
+ sarif?: readonly SarifLog[];
33
+ signal?: AbortSignal;
34
+ onEvent?: (event: ReviewEvent) => void;
35
+ }
36
+ export interface ReviewLimits {
37
+ concurrency?: number;
38
+ taskTimeoutMs?: number;
39
+ runTimeoutMs?: number;
40
+ maxCostUsd?: number;
41
+ maxTasks?: number;
42
+ }
43
+ export interface ReviewStages {
44
+ verify?: boolean;
45
+ judge?: boolean;
46
+ }
47
+ export interface ReviewMode {
48
+ full?: boolean;
49
+ ultra?: boolean;
50
+ }
51
+ export interface RunIdentity {
52
+ runId?: string;
53
+ provenance?: ProvenanceInput;
54
+ }
55
+ export interface ReviewHooks {
56
+ bundling?: BundlePolicy;
57
+ grouper?: FileGrouper;
58
+ relocate?: AnchorContext["relocate"] | false;
59
+ abortGraceMs?: number;
60
+ }
61
+ export declare const REVIEW_DEFAULTS: {
62
+ readonly concurrency: 4;
63
+ readonly taskTimeoutMs: number;
64
+ readonly runTimeoutMs: number;
65
+ };
66
+ export declare const MAX_TIMER_MS: number;
@@ -0,0 +1,8 @@
1
+ export const REVIEW_DEFAULTS = {
2
+ concurrency: 4,
3
+ taskTimeoutMs: 10 * 60_000,
4
+ runTimeoutMs: 25 * 60_000,
5
+ };
6
+ // Timers fire at once past 2^31 - 1 ms (about 24.8 days); a longer timeout
7
+ // means no practical limit, so it is cut to the longest one a timer keeps.
8
+ export const MAX_TIMER_MS = 2 ** 31 - 1;
@@ -0,0 +1,89 @@
1
+ import { z } from "zod";
2
+ import type { ReviewPreview } from "./preview.js";
3
+ export declare const PLAN_VERSION = 1;
4
+ export declare const planOutputSchema: z.ZodObject<{
5
+ version: z.ZodLiteral<1>;
6
+ changeRequest: z.ZodObject<{
7
+ id: z.ZodString;
8
+ title: z.ZodString;
9
+ description: z.ZodString;
10
+ baseSha: z.ZodString;
11
+ headSha: z.ZodString;
12
+ override: z.ZodExactOptional<z.ZodObject<{
13
+ by: z.ZodString;
14
+ reason: z.ZodString;
15
+ }, z.core.$strict>>;
16
+ }, z.core.$strict>;
17
+ tier: z.ZodEnum<{
18
+ full: "full";
19
+ lite: "lite";
20
+ trivial: "trivial";
21
+ }>;
22
+ selected: z.ZodArray<z.ZodString>;
23
+ excluded: z.ZodArray<z.ZodObject<{
24
+ path: z.ZodString;
25
+ reason: z.ZodEnum<{
26
+ binary: "binary";
27
+ deleted: "deleted";
28
+ extension: "extension";
29
+ generated: "generated";
30
+ secret: "secret";
31
+ too_large: "too_large";
32
+ user_exclude: "user_exclude";
33
+ }>;
34
+ }, z.core.$strict>>;
35
+ bundles: z.ZodArray<z.ZodObject<{
36
+ label: z.ZodString;
37
+ files: z.ZodArray<z.ZodString>;
38
+ }, z.core.$strict>>;
39
+ groupingSkipped: z.ZodBoolean;
40
+ tasks: z.ZodArray<z.ZodObject<{
41
+ taskId: z.ZodString;
42
+ reviewer: z.ZodString;
43
+ bundle: z.ZodString;
44
+ files: z.ZodArray<z.ZodString>;
45
+ promptTokens: z.ZodInt;
46
+ effort: z.ZodExactOptional<z.ZodEnum<{
47
+ high: "high";
48
+ low: "low";
49
+ medium: "medium";
50
+ minimal: "minimal";
51
+ none: "none";
52
+ }>>;
53
+ models: z.ZodExactOptional<z.ZodArray<z.ZodString>>;
54
+ planPromptTokens: z.ZodExactOptional<z.ZodInt>;
55
+ inputCost: z.ZodExactOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
56
+ model: z.ZodString;
57
+ status: z.ZodLiteral<"priced">;
58
+ usd: z.ZodNumber;
59
+ }, z.core.$strict>, z.ZodObject<{
60
+ model: z.ZodString;
61
+ status: z.ZodLiteral<"unpriced">;
62
+ }, z.core.$strict>, z.ZodObject<{
63
+ model: z.ZodString;
64
+ status: z.ZodLiteral<"unknown">;
65
+ }, z.core.$strict>], "status">>;
66
+ }, z.core.$strict>>;
67
+ skipped: z.ZodArray<z.ZodObject<{
68
+ reviewer: z.ZodString;
69
+ bundle: z.ZodString;
70
+ reason: z.ZodEnum<{
71
+ below_tier: "below_tier";
72
+ disabled: "disabled";
73
+ no_guidelines: "no_guidelines";
74
+ no_matching_files: "no_matching_files";
75
+ task_limit: "task_limit";
76
+ }>;
77
+ }, z.core.$strict>>;
78
+ promptTokens: z.ZodInt;
79
+ planCalls: z.ZodInt;
80
+ inputCost: z.ZodExactOptional<z.ZodObject<{
81
+ usd: z.ZodNumber;
82
+ priced: z.ZodInt;
83
+ unpriced: z.ZodInt;
84
+ unknown: z.ZodInt;
85
+ }, z.core.$strict>>;
86
+ warnings: z.ZodArray<z.ZodString>;
87
+ }, z.core.$strict>;
88
+ export type PlanOutput = z.output<typeof planOutputSchema>;
89
+ export declare function toPlanOutput(preview: ReviewPreview): PlanOutput;
@@ -0,0 +1,108 @@
1
+ import { z } from "zod";
2
+ import { EFFORT_LEVELS } from "../agent/settings.js";
3
+ import { riskTierSchema } from "../domain.js";
4
+ import { changeRequestSchema, skippedCellSchema } from "../report/output-schema.js";
5
+ import { exclusionReasonSchema } from "../select/select.js";
6
+ // The published shape of `ocra review --plan --format json` without what
7
+ // the CLI adds (where each setting came from), versioned like the report: a
8
+ // version only gains optional fields. The type is derived from the schema,
9
+ // and the CLI publishes the JSON Schema of the whole output.
10
+ export const PLAN_VERSION = 1;
11
+ const inputCostSchema = z.discriminatedUnion("status", [
12
+ z.strictObject({ model: z.string(), status: z.literal("priced"), usd: z.number() }),
13
+ z.strictObject({ model: z.string(), status: z.literal("unpriced") }),
14
+ z.strictObject({ model: z.string(), status: z.literal("unknown") }),
15
+ ]);
16
+ const planTaskSchema = z.strictObject({
17
+ taskId: z.string(),
18
+ reviewer: z.string(),
19
+ bundle: z.string(),
20
+ files: z.array(z.string()),
21
+ promptTokens: z.int().nonnegative(),
22
+ effort: z.enum(EFFORT_LEVELS).exactOptional(),
23
+ models: z.array(z.string()).exactOptional(),
24
+ planPromptTokens: z.int().nonnegative().exactOptional(),
25
+ inputCost: inputCostSchema.exactOptional(),
26
+ });
27
+ export const planOutputSchema = z.strictObject({
28
+ version: z.literal(PLAN_VERSION),
29
+ changeRequest: changeRequestSchema,
30
+ tier: riskTierSchema,
31
+ selected: z.array(z.string()),
32
+ excluded: z.array(z.strictObject({ path: z.string(), reason: exclusionReasonSchema })),
33
+ bundles: z.array(z.strictObject({ label: z.string(), files: z.array(z.string()) })),
34
+ groupingSkipped: z.boolean(),
35
+ tasks: z.array(planTaskSchema),
36
+ skipped: z.array(skippedCellSchema),
37
+ promptTokens: z.int().nonnegative(),
38
+ // Added in version 1 without a bump: a new field older readers ignore.
39
+ planCalls: z.int().nonnegative(),
40
+ // Added in version 1 without a bump, like planCalls.
41
+ inputCost: z
42
+ .strictObject({
43
+ usd: z.number(),
44
+ priced: z.int().nonnegative(),
45
+ unpriced: z.int().nonnegative(),
46
+ unknown: z.int().nonnegative(),
47
+ })
48
+ .exactOptional(),
49
+ warnings: z.array(z.string()),
50
+ });
51
+ export function toPlanOutput(preview) {
52
+ const { changeRequest: c, inputCost } = preview;
53
+ return {
54
+ version: PLAN_VERSION,
55
+ changeRequest: {
56
+ id: c.id,
57
+ title: c.title,
58
+ description: c.description,
59
+ baseSha: c.baseSha,
60
+ headSha: c.headSha,
61
+ ...(c.override ? { override: { by: c.override.by, reason: c.override.reason } } : {}),
62
+ },
63
+ tier: preview.tier,
64
+ selected: [...preview.selected],
65
+ excluded: preview.excluded.map((e) => ({ path: e.path, reason: e.reason })),
66
+ bundles: preview.bundles.map((b) => ({ label: b.label, files: [...b.files] })),
67
+ groupingSkipped: preview.groupingSkipped,
68
+ tasks: preview.tasks.map(planTask),
69
+ skipped: preview.skipped.map((s) => ({
70
+ reviewer: s.reviewer,
71
+ bundle: s.bundle,
72
+ reason: s.reason,
73
+ })),
74
+ promptTokens: preview.promptTokens,
75
+ planCalls: preview.planCalls,
76
+ ...(inputCost
77
+ ? {
78
+ inputCost: {
79
+ usd: inputCost.usd,
80
+ priced: inputCost.priced,
81
+ unpriced: inputCost.unpriced,
82
+ unknown: inputCost.unknown,
83
+ },
84
+ }
85
+ : {}),
86
+ warnings: [...preview.warnings],
87
+ };
88
+ }
89
+ function planTask(t) {
90
+ const cost = t.inputCost;
91
+ return {
92
+ taskId: t.taskId,
93
+ reviewer: t.reviewer,
94
+ bundle: t.bundle,
95
+ files: [...t.files],
96
+ promptTokens: t.promptTokens,
97
+ ...(t.effort === undefined ? {} : { effort: t.effort }),
98
+ ...(t.models ? { models: [...t.models] } : {}),
99
+ ...(t.planPromptTokens === undefined ? {} : { planPromptTokens: t.planPromptTokens }),
100
+ ...(cost
101
+ ? {
102
+ inputCost: cost.status === "priced"
103
+ ? { model: cost.model, status: cost.status, usd: cost.usd }
104
+ : { model: cost.model, status: cost.status },
105
+ }
106
+ : {}),
107
+ };
108
+ }
@@ -2,11 +2,10 @@ import { type Bundle } from "../bundle/bundle.js";
2
2
  import type { AgentRuntime, ReviewContext, Usage } from "../contracts.js";
3
3
  import type { ChangeRequest, FileDiff, RiskTier } from "../domain.js";
4
4
  import { type RememberedEntry } from "../memory/memory.js";
5
+ import type { ReviewEvent } from "../report/report.js";
5
6
  import { type SourcedRule } from "../rules/repo-rules.js";
6
7
  import { type FileDecision } from "../select/select.js";
7
- import type { ReviewEvent } from "./report.js";
8
- import type { ReviewHooks, ReviewOptions } from "./run.js";
9
- export declare const GUIDELINES_PATH = "AGENTS.md";
8
+ import type { ReviewHooks, ReviewOptions } from "./options.js";
10
9
  export interface ReviewPlan {
11
10
  changeRequest: ChangeRequest;
12
11
  decisions: FileDecision[];
@@ -25,11 +24,10 @@ export interface ReviewPlan {
25
24
  usage: Usage[];
26
25
  warnings: string[];
27
26
  }
28
- export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "selection" | "bundling" | "grouper" | "effort" | "roles"> & {
27
+ export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "selection" | "bundling" | "grouper" | "effort" | "roles" | "resume"> & {
29
28
  runId?: string;
30
29
  runtime?: AgentRuntime;
31
30
  reviewOnly?: ReadonlySet<string>;
32
31
  priorTier?: RiskTier;
33
32
  };
34
33
  export declare function planReview(options: PlanOptions, emit: (event: ReviewEvent) => void, signal: AbortSignal): Promise<ReviewPlan>;
35
- //# sourceMappingURL=plan.d.ts.map
@@ -1,21 +1,22 @@
1
+ import { roleCall } from "../agent/settings.js";
1
2
  import { bundleFiles, defaultBundlePolicy } from "../bundle/bundle.js";
3
+ import { runtimeGrouper } from "../bundle/runtime-grouper.js";
2
4
  import { MEMORY_PATH, mergeMemory, parseMemory } from "../memory/memory.js";
3
5
  import { parseRepoRules, REPO_RULES_PATH, } from "../rules/repo-rules.js";
4
6
  import { defaultSelectionPolicy, selectFiles } from "../select/select.js";
5
7
  import { triage } from "../triage.js";
6
- import { roleCall } from "./agents.js";
7
8
  import { reviewContext } from "./context.js";
8
- import { runtimeGrouper } from "./helpers.js";
9
9
  import { rank } from "./matrix.js";
10
+ import { resumedBundles } from "./resume.js";
10
11
  import { newRunId } from "./run-id.js";
11
- export const GUIDELINES_PATH = "AGENTS.md";
12
+ const GUIDELINES_PATH = "AGENTS.md";
12
13
  export async function planReview(options, emit, signal) {
13
14
  const { vcs } = options;
14
15
  const readTrusted = options.readTrusted ?? ((path) => vcs.readFile(path));
15
16
  const changeRequest = await vcs.getChangeRequest();
16
17
  emit({ type: "run_started", runId: options.runId ?? newRunId(), changeRequest });
17
18
  const diffs = await vcs.getDiff();
18
- const decisions = selectFiles(diffs, options.selection ?? defaultSelectionPolicy);
19
+ const decisions = selectFiles(diffs, { ...defaultSelectionPolicy, ...options.selection });
19
20
  const selected = decisions.filter((d) => d.selected).map((d) => d.diff);
20
21
  const tier = triage(selected);
21
22
  emit({
@@ -42,11 +43,15 @@ export async function planReview(options, emit, signal) {
42
43
  ? selected.filter((d) => only.has(d.newPath) || only.has(d.oldPath))
43
44
  : selected;
44
45
  const unchanged = new Set(selected.filter((d) => !inScope.includes(d)).map((d) => d.newPath));
45
- const bundled = await bundleFiles(inScope, options.bundling ?? defaultBundlePolicy, grouper);
46
+ const resumed = options.resume && resumedBundles(options.resume, inScope);
47
+ const bundled = resumed
48
+ ? { bundles: resumed, strategy: "resumed", warnings: [] }
49
+ : await bundleFiles(inScope, options.bundling ?? defaultBundlePolicy, grouper);
46
50
  emit({
47
51
  type: "files_bundled",
48
52
  strategy: bundled.strategy,
49
53
  bundles: bundled.bundles.length,
54
+ groups: bundled.bundles.map((b) => ({ label: b.label, files: b.files.map((f) => f.newPath) })),
50
55
  warnings: bundled.warnings,
51
56
  });
52
57
  return {
@@ -72,4 +77,3 @@ async function loadRepoRules(read) {
72
77
  const text = await read(REPO_RULES_PATH);
73
78
  return text === undefined ? [] : parseRepoRules(text);
74
79
  }
75
- //# sourceMappingURL=plan.js.map
@@ -1,9 +1,8 @@
1
1
  import type { Effort } from "../contracts.js";
2
2
  import type { ChangeRequest, RiskTier } from "../domain.js";
3
- import type { ModelChains } from "../plugin/types.js";
4
- import type { ReviewerDefinition } from "../review/reviewer.js";
5
3
  import type { FileDecision } from "../select/select.js";
6
- import { type ReviewerOverrides, type SkippedCell } from "./matrix.js";
4
+ import { type SkippedCell } from "./matrix.js";
5
+ import type { ReviewOptions } from "./options.js";
7
6
  import { type PlanOptions } from "./plan.js";
8
7
  export interface PreviewTask {
9
8
  taskId: string;
@@ -14,7 +13,19 @@ export interface PreviewTask {
14
13
  planPromptTokens?: number;
15
14
  effort?: Effort;
16
15
  models?: string[];
16
+ inputCost?: InputCost;
17
17
  }
18
+ type InputCost = {
19
+ model: string;
20
+ status: "priced";
21
+ usd: number;
22
+ } | {
23
+ model: string;
24
+ status: "unpriced";
25
+ } | {
26
+ model: string;
27
+ status: "unknown";
28
+ };
18
29
  export interface ReviewPreview {
19
30
  changeRequest: ChangeRequest;
20
31
  tier: RiskTier;
@@ -34,14 +45,16 @@ export interface ReviewPreview {
34
45
  skipped: SkippedCell[];
35
46
  promptTokens: number;
36
47
  planCalls: number;
48
+ inputCost?: {
49
+ usd: number;
50
+ priced: number;
51
+ unpriced: number;
52
+ unknown: number;
53
+ };
37
54
  warnings: string[];
38
55
  }
39
- export type PreviewOptions = Omit<PlanOptions, "runtime"> & {
40
- reviewers?: readonly ReviewerDefinition[];
41
- reviewerOverrides?: ReviewerOverrides;
42
- ultra?: boolean;
43
- maxTasks?: number;
44
- models?: ModelChains;
56
+ export type PreviewOptions = Omit<PlanOptions, "runtime"> & Omit<ReviewOptions, "vcs" | "runtime"> & {
57
+ inputPrice?: (model: string) => number | undefined;
45
58
  };
46
59
  export declare function previewReview(options: PreviewOptions): Promise<ReviewPreview>;
47
- //# sourceMappingURL=preview.d.ts.map
60
+ export {};
@@ -1,9 +1,9 @@
1
+ import { reviewerCall } from "../agent/settings.js";
1
2
  import { defaultBundlePolicy } from "../bundle/bundle.js";
2
3
  import { memoryFor } from "../memory/memory.js";
3
4
  import { buildReviewPrompt } from "../review/prompt.js";
4
5
  import { correctnessReviewer } from "../review/reviewers/correctness.js";
5
6
  import { resolveRules } from "../rules/resolve.js";
6
- import { reviewerCall } from "./agents.js";
7
7
  import { isLargeBundle } from "./execute.js";
8
8
  import { planTasks } from "./matrix.js";
9
9
  import { planReview } from "./plan.js";
@@ -13,8 +13,8 @@ export async function previewReview(options) {
13
13
  const plan = await planReview(options, () => { }, 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.ultra === true,
17
- ...(options.maxTasks !== undefined ? { maxTasks: options.maxTasks } : {}),
16
+ ultra: options.mode?.ultra === true,
17
+ ...(options.limits?.maxTasks !== undefined ? { maxTasks: options.limits?.maxTasks } : {}),
18
18
  hasGuidelines: Boolean(plan.guidelines?.trim()),
19
19
  });
20
20
  const { cells } = planned;
@@ -45,10 +45,14 @@ export async function previewReview(options) {
45
45
  if (models?.length)
46
46
  task.models = [...models];
47
47
  const key = `${cell.reviewer.id}\0${cell.bundle.label}`;
48
- if ((options.ultra || isLargeBundle(cell.bundle.files)) && !plannedBundles.has(key)) {
48
+ if ((options.mode?.ultra || isLargeBundle(cell.bundle.files)) && !plannedBundles.has(key)) {
49
49
  plannedBundles.add(key);
50
50
  task.planPromptTokens = tokens(buildReviewPrompt({ ...input, forPlanning: true }));
51
51
  }
52
+ const first = task.models?.[0];
53
+ if (first !== undefined && options.inputPrice) {
54
+ task.inputCost = inputCost(first, options.inputPrice(first), task.promptTokens + (task.planPromptTokens ?? 0));
55
+ }
52
56
  return task;
53
57
  });
54
58
  const policy = options.bundling ?? defaultBundlePolicy;
@@ -63,6 +67,7 @@ export async function previewReview(options) {
63
67
  skipped: planned.skipped,
64
68
  promptTokens: tasks.reduce((sum, t) => sum + t.promptTokens + (t.planPromptTokens ?? 0), 0),
65
69
  planCalls: tasks.filter((t) => t.planPromptTokens !== undefined).length,
70
+ ...(tasks.some((t) => t.inputCost) ? { inputCost: totalInputCost(tasks) } : {}),
66
71
  warnings: [
67
72
  ...plan.warnings,
68
73
  ...(planned.limited?.length
@@ -73,8 +78,23 @@ export async function previewReview(options) {
73
78
  ],
74
79
  };
75
80
  }
81
+ function inputCost(model, price, promptTokens) {
82
+ if (price === undefined)
83
+ return { model, status: "unknown" };
84
+ if (price === 0)
85
+ return { model, status: "unpriced" };
86
+ return { model, status: "priced", usd: (promptTokens * price) / 1_000_000 };
87
+ }
88
+ function totalInputCost(tasks) {
89
+ const total = { usd: 0, priced: 0, unpriced: 0, unknown: 0 };
90
+ for (const { inputCost } of tasks) {
91
+ if (inputCost?.status === "priced")
92
+ total.usd += inputCost.usd;
93
+ total[inputCost?.status ?? "unknown"] += 1;
94
+ }
95
+ return total;
96
+ }
76
97
  // Four characters per token: an estimate, not a tokenizer.
77
98
  function tokens(prompt) {
78
99
  return Math.ceil((prompt.system.length + prompt.user.length) / 4);
79
100
  }
80
- //# sourceMappingURL=preview.js.map
@@ -1,31 +1,8 @@
1
- import type { AgentRuntime, AppliedSampling, Effort, ModelTier, Sampling } from "../contracts.js";
1
+ import type { ResolvedAgent, ReviewerOverrides } from "../agent/settings.js";
2
+ import type { AgentRuntime, AppliedSampling, Sampling } from "../contracts.js";
3
+ import type { AgentProvenance, RunProvenance } from "../report/provenance.js";
2
4
  import type { ReviewerDefinition } from "../review/reviewer.js";
3
- import type { RuleSource, SourcedRule } from "../rules/repo-rules.js";
4
- import type { ResolvedAgent } from "./agents.js";
5
- import type { ReviewerOverrides } from "./matrix.js";
6
- export interface RunProvenance {
7
- ocraVersion: string;
8
- promptHash: string;
9
- configHash: string;
10
- sampling: AppliedSampling;
11
- agents?: Record<string, AgentProvenance>;
12
- rules?: RuleProvenance[];
13
- accountSettings?: {
14
- version: string | null;
15
- };
16
- }
17
- export interface RuleProvenance {
18
- path: string[];
19
- rule: string;
20
- source?: RuleSource;
21
- }
22
- export interface AgentProvenance {
23
- tier: ModelTier;
24
- models?: string[];
25
- effort?: Effort;
26
- applied?: boolean;
27
- notApplied?: (keyof Sampling)[];
28
- }
5
+ import type { SourcedRule } from "../rules/repo-rules.js";
29
6
  export interface ProvenanceInput {
30
7
  ocraVersion: string;
31
8
  configHash: string;
@@ -41,4 +18,3 @@ export declare function appliedSampling(runtime: {
41
18
  }, requested?: Sampling): AppliedSampling;
42
19
  export declare function agentProvenance(agents: readonly ResolvedAgent[], runtime: Pick<AgentRuntime, "appliedTo">): Record<string, AgentProvenance>;
43
20
  export declare function runProvenance(input: ProvenanceInput, runtime: Pick<AgentRuntime, "sampling" | "appliedTo">, reviewers: readonly ReviewerDefinition[], agents: readonly ResolvedAgent[], overrides?: ReviewerOverrides, rules?: readonly SourcedRule[]): RunProvenance;
44
- //# sourceMappingURL=provenance.d.ts.map