@effect-agent/pr-review 0.1.0-beta.29 → 0.1.0-beta.31
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.
- package/README.md +5 -3
- package/dist/index.d.mts +15 -10
- package/dist/index.mjs +19 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/review.ts +35 -3
package/README.md
CHANGED
|
@@ -4,12 +4,14 @@ A small, provider-neutral review agent.
|
|
|
4
4
|
|
|
5
5
|
The package accepts an already-collected diff, makes one model call with no
|
|
6
6
|
tools, validates the returned paths and line anchors, and returns a structured
|
|
7
|
-
report with
|
|
8
|
-
|
|
7
|
+
report with cached, uncached, cache-write, and output token usage plus, when
|
|
8
|
+
supplied by the host, an estimated cost. It knows nothing about GitHub,
|
|
9
|
+
webhooks, comments, providers, retries, or review history; those belong to the
|
|
10
|
+
host channel.
|
|
9
11
|
Each finding carries a severity and problem category so a host can render a
|
|
10
12
|
scannable review without another model call.
|
|
11
13
|
|
|
12
14
|
```ts
|
|
13
|
-
const reviewer = makeReviewer({ model, guidance });
|
|
15
|
+
const reviewer = makeReviewer({ model, guidance, estimateCostMicrousd });
|
|
14
16
|
const outcome = yield * reviewer.review(request);
|
|
15
17
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { AgentPolicy, IdGenerator, UsageBudgetLimits } from "effect-agent";
|
|
2
|
+
import { AgentPolicy, IdGenerator, RunCostEstimator, UsageBudgetLimits } from "effect-agent";
|
|
3
3
|
import { LanguageModel, Model, Toolkit } from "effect/unstable/ai";
|
|
4
4
|
//#region src/review.d.ts
|
|
5
5
|
declare const ReviewChange_base: Schema.Class<ReviewChange, Schema.Struct<{
|
|
@@ -21,14 +21,14 @@ declare class ReviewRequest extends ReviewRequest_base {}
|
|
|
21
21
|
declare const ReviewSeverity: Schema.Literals<readonly ["blocking", "important", "nit"]>;
|
|
22
22
|
type ReviewSeverity = typeof ReviewSeverity.Type;
|
|
23
23
|
/** A model-claimed problem kind used only to label findings for readers. */
|
|
24
|
-
declare const ReviewCategory: Schema.Literals<readonly ["correctness", "security", "concurrency", "performance", "resources", "error-handling", "testing", "maintainability", "style", "docs"]>;
|
|
24
|
+
declare const ReviewCategory: Schema.Literals<readonly ["correctness", "security", "concurrency", "performance", "resources", "reliability", "error-handling", "testing", "maintainability", "style", "docs"]>;
|
|
25
25
|
type ReviewCategory = typeof ReviewCategory.Type;
|
|
26
26
|
declare const ReviewFinding_base: Schema.Class<ReviewFinding, Schema.Struct<{
|
|
27
27
|
readonly path: Schema.NonEmptyString;
|
|
28
28
|
readonly line: Schema.optionalKey<Schema.Int>;
|
|
29
29
|
readonly severity: Schema.Literals<readonly ["blocking", "important", "nit"]>;
|
|
30
30
|
/** Presentation label only; it never changes review admission or failure policy. */
|
|
31
|
-
readonly category: Schema.Literals<readonly ["correctness", "security", "concurrency", "performance", "resources", "error-handling", "testing", "maintainability", "style", "docs"]>;
|
|
31
|
+
readonly category: Schema.Literals<readonly ["correctness", "security", "concurrency", "performance", "resources", "reliability", "error-handling", "testing", "maintainability", "style", "docs"]>;
|
|
32
32
|
readonly title: Schema.NonEmptyString;
|
|
33
33
|
readonly body: Schema.NonEmptyString;
|
|
34
34
|
}>, {}>;
|
|
@@ -42,7 +42,11 @@ declare const ReviewReport_base: Schema.Class<ReviewReport, Schema.Struct<{
|
|
|
42
42
|
declare class ReviewReport extends ReviewReport_base {}
|
|
43
43
|
declare const ReviewUsage_base: Schema.Class<ReviewUsage, Schema.Struct<{
|
|
44
44
|
readonly inputTokens: Schema.Natural;
|
|
45
|
+
readonly uncachedInputTokens: Schema.Natural;
|
|
46
|
+
readonly cachedInputTokens: Schema.Natural;
|
|
47
|
+
readonly cacheWriteInputTokens: Schema.Natural;
|
|
45
48
|
readonly outputTokens: Schema.Natural;
|
|
49
|
+
readonly estimatedCostMicrousd: Schema.optionalKey<Schema.Natural>;
|
|
46
50
|
}>, {}>;
|
|
47
51
|
declare class ReviewUsage extends ReviewUsage_base {}
|
|
48
52
|
declare const ReviewOutcome_base: Schema.Class<ReviewOutcome, Schema.Struct<{
|
|
@@ -64,34 +68,35 @@ declare const sanitizeReviewReport: (request: Pick<ReviewRequest, "changes">, re
|
|
|
64
68
|
interface ReviewerOptions<Provider, ModelProvides, ModelRequires> {
|
|
65
69
|
readonly model: Model.Model<Provider, LanguageModel.LanguageModel | ModelProvides, ModelRequires>;
|
|
66
70
|
readonly guidance?: string | undefined;
|
|
71
|
+
readonly estimateCostMicrousd?: RunCostEstimator | undefined;
|
|
67
72
|
}
|
|
68
73
|
/** Build a provider-neutral reviewer. The returned `review` performs exactly one Run. */
|
|
69
74
|
declare const makeReviewer: <Provider, ModelProvides, ModelRequires>(options: ReviewerOptions<Provider, ModelProvides, ModelRequires>) => {
|
|
70
|
-
readonly definition: import("effect-agent").Definition<typeof ReviewRequest, typeof ReviewReport, "Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it." | `Review the supplied pull-request diff once.
|
|
75
|
+
readonly definition: import("effect-agent").Definition<typeof ReviewRequest, typeof ReviewReport, "Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches." | `Review the supplied pull-request diff once.
|
|
71
76
|
|
|
72
77
|
Report only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.
|
|
73
78
|
|
|
74
|
-
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it.
|
|
79
|
+
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches.
|
|
75
80
|
|
|
76
81
|
Repository guidance:
|
|
77
82
|
${string}`, Toolkit.Toolkit<{}>, undefined>;
|
|
78
|
-
readonly binding: import("effect-agent").Binding<import("effect-agent").Definition<typeof ReviewRequest, typeof ReviewReport, "Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it." | `Review the supplied pull-request diff once.
|
|
83
|
+
readonly binding: import("effect-agent").Binding<import("effect-agent").Definition<typeof ReviewRequest, typeof ReviewReport, "Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches." | `Review the supplied pull-request diff once.
|
|
79
84
|
|
|
80
85
|
Report only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.
|
|
81
86
|
|
|
82
|
-
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it.
|
|
87
|
+
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches.
|
|
83
88
|
|
|
84
89
|
Repository guidance:
|
|
85
90
|
${string}`, Toolkit.Toolkit<{}>, undefined>, Model.Model<Provider, ModelProvides | LanguageModel.LanguageModel, ModelRequires>>;
|
|
86
|
-
readonly review: (request: ReviewRequest) => Effect.Effect<ReviewOutcome, import("effect-agent").AgentRuntimeFailure<import("effect-agent").RuntimeBinding<typeof ReviewRequest, typeof ReviewReport, "Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it." | `Review the supplied pull-request diff once.
|
|
91
|
+
readonly review: (request: ReviewRequest) => Effect.Effect<ReviewOutcome, import("effect-agent").AgentRuntimeFailure<import("effect-agent").RuntimeBinding<typeof ReviewRequest, typeof ReviewReport, "Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches." | `Review the supplied pull-request diff once.
|
|
87
92
|
|
|
88
93
|
Report only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.
|
|
89
94
|
|
|
90
|
-
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it.
|
|
95
|
+
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches.
|
|
91
96
|
|
|
92
97
|
Repository guidance:
|
|
93
98
|
${string}`, {}, Provider, ModelProvides, ModelRequires, never, never, undefined>, import("effect-agent").BudgetAdapterError | import("effect-agent").BudgetExceeded, never>, Exclude<Exclude<Exclude<ModelRequires, import("effect-agent").EngineProvidedToolServices>, IdGenerator>, import("effect/Scope").Scope>>;
|
|
94
99
|
};
|
|
95
100
|
//#endregion
|
|
96
|
-
export { ReviewCategory, ReviewChange, ReviewFinding, ReviewOutcome, ReviewReport, ReviewRequest, ReviewSeverity, ReviewUsage, ReviewerOptions, commentableLines, isCommentableLine, makeReviewer, reviewBudgetLimits, reviewPolicy, sanitizeReviewReport };
|
|
101
|
+
export { ReviewCategory, ReviewChange, ReviewFinding, ReviewOutcome, ReviewReport, ReviewRequest, ReviewSeverity, ReviewUsage, ReviewerOptions, type RunCostEstimator, commentableLines, isCommentableLine, makeReviewer, reviewBudgetLimits, reviewPolicy, sanitizeReviewReport };
|
|
97
102
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -30,6 +30,7 @@ const ReviewCategory = Schema.Literals([
|
|
|
30
30
|
"concurrency",
|
|
31
31
|
"performance",
|
|
32
32
|
"resources",
|
|
33
|
+
"reliability",
|
|
33
34
|
"error-handling",
|
|
34
35
|
"testing",
|
|
35
36
|
"maintainability",
|
|
@@ -51,10 +52,15 @@ var ReviewReport = class extends Schema.Class("@effect-agent/pr-review/ReviewRep
|
|
|
51
52
|
summary: Schema.NonEmptyString.check(Schema.isMaxLength(6e3)),
|
|
52
53
|
findings: Schema.Array(ReviewFinding).check(Schema.isMaxLength(12))
|
|
53
54
|
}) {};
|
|
54
|
-
|
|
55
|
+
const ReviewUsageFields = Schema.Struct({
|
|
55
56
|
inputTokens: Schema.Natural,
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
uncachedInputTokens: Schema.Natural,
|
|
58
|
+
cachedInputTokens: Schema.Natural,
|
|
59
|
+
cacheWriteInputTokens: Schema.Natural,
|
|
60
|
+
outputTokens: Schema.Natural,
|
|
61
|
+
estimatedCostMicrousd: Schema.optionalKey(Schema.Natural)
|
|
62
|
+
}).check(Schema.makeFilter((usage) => usage.inputTokens === usage.uncachedInputTokens + usage.cachedInputTokens + usage.cacheWriteInputTokens, { title: "Input token total equals uncached, cached, and cache-write components" }));
|
|
63
|
+
var ReviewUsage = class extends Schema.Class("@effect-agent/pr-review/ReviewUsage")(ReviewUsageFields) {};
|
|
58
64
|
var ReviewOutcome = class extends Schema.Class("@effect-agent/pr-review/ReviewOutcome")({
|
|
59
65
|
report: ReviewReport,
|
|
60
66
|
turns: Schema.Natural,
|
|
@@ -64,7 +70,7 @@ const BASE_INSTRUCTIONS = `Review the supplied pull-request diff once.
|
|
|
64
70
|
|
|
65
71
|
Report only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.
|
|
66
72
|
|
|
67
|
-
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it.`;
|
|
73
|
+
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches.`;
|
|
68
74
|
const reviewPolicy = AgentPolicy.make({
|
|
69
75
|
maxTurns: 1,
|
|
70
76
|
maxToolCalls: 1,
|
|
@@ -148,14 +154,21 @@ const makeReviewer = (options) => {
|
|
|
148
154
|
const binding = Agent.withModel(definition, options.model);
|
|
149
155
|
const review = (request) => Effect.gen(function* () {
|
|
150
156
|
const budget = yield* makeUsageBudget(reviewBudgetLimits);
|
|
151
|
-
const result = yield* AgentRuntime.run(binding, request, {
|
|
157
|
+
const result = yield* AgentRuntime.run(binding, request, {
|
|
158
|
+
budget: toRunBudgetHook(budget),
|
|
159
|
+
...options.estimateCostMicrousd === void 0 ? {} : { estimateCostMicrousd: options.estimateCostMicrousd }
|
|
160
|
+
});
|
|
152
161
|
const usage = yield* budget.snapshot;
|
|
153
162
|
return ReviewOutcome.make({
|
|
154
163
|
report: sanitizeReviewReport(request, result.output),
|
|
155
164
|
turns: result.turns,
|
|
156
165
|
usage: ReviewUsage.make({
|
|
157
166
|
inputTokens: usage.inputTokens,
|
|
158
|
-
|
|
167
|
+
uncachedInputTokens: Math.max(0, usage.inputTokens - usage.cacheReadInputTokens - usage.cacheWriteInputTokens),
|
|
168
|
+
cachedInputTokens: usage.cacheReadInputTokens,
|
|
169
|
+
cacheWriteInputTokens: usage.cacheWriteInputTokens,
|
|
170
|
+
outputTokens: usage.outputTokens,
|
|
171
|
+
...options.estimateCostMicrousd === void 0 ? {} : { estimatedCostMicrousd: usage.costMicrousd }
|
|
159
172
|
})
|
|
160
173
|
});
|
|
161
174
|
}).pipe(Effect.provide(IdGenerator.layer), Effect.scoped);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/review.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\nimport {\n Agent,\n AgentPolicy,\n AgentRuntime,\n IdGenerator,\n makeUsageBudget,\n toRunBudgetHook,\n UsageBudgetLimits,\n} from \"effect-agent\";\nimport { type LanguageModel, type Model, Toolkit } from \"effect/unstable/ai\";\n\nconst ReviewPath = Schema.NonEmptyString.check(Schema.isMaxLength(512));\nconst Revision = Schema.NonEmptyString.check(Schema.isMaxLength(128));\n\n/** One complete textual patch supplied by the host. */\nexport class ReviewChange extends Schema.Class<ReviewChange>(\n \"@effect-agent/pr-review/ReviewChange\",\n)({\n path: ReviewPath,\n patch: Schema.NonEmptyString.check(Schema.isMaxLength(80_000)),\n}) {}\n\n/** The provider-neutral input to one review pass. */\nexport class ReviewRequest extends Schema.Class<ReviewRequest>(\n \"@effect-agent/pr-review/ReviewRequest\",\n)({\n title: Schema.String.check(Schema.isMaxLength(1_000)),\n description: Schema.String.check(Schema.isMaxLength(20_000)),\n baseRevision: Revision,\n headRevision: Revision,\n changes: Schema.Array(ReviewChange).check(Schema.isMaxLength(100)),\n unreviewedPaths: Schema.Array(ReviewPath).check(Schema.isMaxLength(300)),\n}) {}\n\nexport const ReviewSeverity = Schema.Literals([\"blocking\", \"important\", \"nit\"]);\nexport type ReviewSeverity = typeof ReviewSeverity.Type;\n\n/** A model-claimed problem kind used only to label findings for readers. */\nexport const ReviewCategory = Schema.Literals([\n \"correctness\",\n \"security\",\n \"concurrency\",\n \"performance\",\n \"resources\",\n \"error-handling\",\n \"testing\",\n \"maintainability\",\n \"style\",\n \"docs\",\n]);\nexport type ReviewCategory = typeof ReviewCategory.Type;\n\n/** One actionable defect. `line` is a RIGHT-side line in the supplied patch. */\nexport class ReviewFinding extends Schema.Class<ReviewFinding>(\n \"@effect-agent/pr-review/ReviewFinding\",\n)({\n path: ReviewPath,\n line: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n severity: ReviewSeverity,\n /** Presentation label only; it never changes review admission or failure policy. */\n category: ReviewCategory,\n title: Schema.NonEmptyString.check(Schema.isMaxLength(200)),\n body: Schema.NonEmptyString.check(Schema.isMaxLength(2_000)),\n}) {}\n\n/** The only model-authored output. An empty findings array is a successful review. */\nexport class ReviewReport extends Schema.Class<ReviewReport>(\n \"@effect-agent/pr-review/ReviewReport\",\n)({\n summary: Schema.NonEmptyString.check(Schema.isMaxLength(6_000)),\n findings: Schema.Array(ReviewFinding).check(Schema.isMaxLength(12)),\n}) {}\n\nexport class ReviewUsage extends Schema.Class<ReviewUsage>(\"@effect-agent/pr-review/ReviewUsage\")({\n inputTokens: Schema.Natural,\n outputTokens: Schema.Natural,\n}) {}\n\nexport class ReviewOutcome extends Schema.Class<ReviewOutcome>(\n \"@effect-agent/pr-review/ReviewOutcome\",\n)({\n report: ReviewReport,\n turns: Schema.Natural,\n usage: ReviewUsage,\n}) {}\n\nconst BASE_INSTRUCTIONS = `Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it.`;\n\nexport const reviewPolicy = AgentPolicy.make({\n maxTurns: 1,\n maxToolCalls: 1,\n maxDuration: \"5 minutes\",\n toolConcurrency: 1,\n tokenBudget: 56_000,\n completionReserveTokens: 8_000,\n contextTokenLimit: 48_000,\n onExhaustion: \"fail\",\n});\n\nconst makeDefinition = (guidance?: string) =>\n Agent.define(\"pr-review\", {\n input: ReviewRequest,\n output: ReviewReport,\n instructions:\n guidance === undefined || guidance.trim().length === 0\n ? BASE_INSTRUCTIONS\n : `${BASE_INSTRUCTIONS}\\n\\nRepository guidance:\\n${guidance.trim()}`,\n toolkit: Toolkit.empty,\n policy: reviewPolicy,\n description: \"Review one supplied pull-request diff in a single model call.\",\n metadata: { deploymentClass: \"E\", surface: \"read-only\" },\n });\n\nexport const reviewBudgetLimits = UsageBudgetLimits.make({\n maxInputTokens: 48_000,\n maxOutputTokens: 8_000,\n maxToolCalls: 0,\n maxDurationMillis: 300_000,\n});\n\n/** Return every RIGHT-side line on which GitHub can place a diff comment. */\nexport const commentableLines = (patch: string): ReadonlySet<number> => {\n const lines = new Set<number>();\n let right: number | undefined;\n for (const text of patch.split(\"\\n\")) {\n const hunk = /^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@/.exec(text);\n if (hunk !== null) {\n right = Number(hunk[1]);\n continue;\n }\n if (right === undefined || text.startsWith(\"\\\\\")) continue;\n if (text.startsWith(\"-\")) continue;\n if (text.startsWith(\"+\") || text.startsWith(\" \")) {\n lines.add(right);\n right += 1;\n }\n }\n return lines;\n};\n\nexport const isCommentableLine = (patch: string, line: number): boolean =>\n commentableLines(patch).has(line);\n\n/**\n * Treat model output as untrusted: remove unknown paths, demote invalid line\n * anchors to top-level findings, and collapse exact duplicates.\n */\nexport const sanitizeReviewReport = (\n request: Pick<ReviewRequest, \"changes\">,\n report: ReviewReport,\n): ReviewReport => {\n const patches = new Map(request.changes.map((change) => [change.path, change.patch] as const));\n const seen = new Set<string>();\n const findings: Array<ReviewFinding> = [];\n for (const finding of report.findings) {\n const patch = patches.get(finding.path);\n if (patch === undefined) continue;\n const line =\n finding.line !== undefined && isCommentableLine(patch, finding.line)\n ? finding.line\n : undefined;\n const key = `${finding.path}\\u0000${String(line ?? \"\")}\\u0000${finding.title.trim().toLowerCase()}`;\n if (seen.has(key)) continue;\n seen.add(key);\n findings.push(\n ReviewFinding.make({\n path: finding.path,\n ...(line === undefined ? {} : { line }),\n severity: finding.severity,\n category: finding.category,\n title: finding.title,\n body: finding.body,\n }),\n );\n }\n return ReviewReport.make({ summary: report.summary, findings });\n};\n\nexport interface ReviewerOptions<Provider, ModelProvides, ModelRequires> {\n readonly model: Model.Model<Provider, LanguageModel.LanguageModel | ModelProvides, ModelRequires>;\n readonly guidance?: string | undefined;\n}\n\n/** Build a provider-neutral reviewer. The returned `review` performs exactly one Run. */\nexport const makeReviewer = <Provider, ModelProvides, ModelRequires>(\n options: ReviewerOptions<Provider, ModelProvides, ModelRequires>,\n) => {\n const definition = makeDefinition(options.guidance);\n const binding = Agent.withModel(definition, options.model);\n const review = (request: ReviewRequest) =>\n Effect.gen(function* () {\n const budget = yield* makeUsageBudget(reviewBudgetLimits);\n const result = yield* AgentRuntime.run(binding, request, {\n budget: toRunBudgetHook(budget),\n });\n const usage = yield* budget.snapshot;\n return ReviewOutcome.make({\n report: sanitizeReviewReport(request, result.output),\n turns: result.turns,\n usage: ReviewUsage.make({\n inputTokens: usage.inputTokens,\n outputTokens: usage.outputTokens,\n }),\n });\n }).pipe(Effect.provide(IdGenerator.layer), Effect.scoped);\n return { definition, binding, review } as const;\n};\n"],"mappings":";;;;AAYA,MAAM,aAAa,OAAO,eAAe,MAAM,OAAO,YAAY,GAAG,CAAC;AACtE,MAAM,WAAW,OAAO,eAAe,MAAM,OAAO,YAAY,GAAG,CAAC;;AAGpE,IAAa,eAAb,cAAkC,OAAO,MACvC,sCACF,CAAC,CAAC;CACA,MAAM;CACN,OAAO,OAAO,eAAe,MAAM,OAAO,YAAY,GAAM,CAAC;AAC/D,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,gBAAb,cAAmC,OAAO,MACxC,uCACF,CAAC,CAAC;CACA,OAAO,OAAO,OAAO,MAAM,OAAO,YAAY,GAAK,CAAC;CACpD,aAA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sources":["../src/review.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\nimport {\n Agent,\n AgentPolicy,\n AgentRuntime,\n IdGenerator,\n makeUsageBudget,\n type RunCostEstimator,\n toRunBudgetHook,\n UsageBudgetLimits,\n} from \"effect-agent\";\nimport { type LanguageModel, type Model, Toolkit } from \"effect/unstable/ai\";\n\nexport type { RunCostEstimator };\n\nconst ReviewPath = Schema.NonEmptyString.check(Schema.isMaxLength(512));\nconst Revision = Schema.NonEmptyString.check(Schema.isMaxLength(128));\n\n/** One complete textual patch supplied by the host. */\nexport class ReviewChange extends Schema.Class<ReviewChange>(\n \"@effect-agent/pr-review/ReviewChange\",\n)({\n path: ReviewPath,\n patch: Schema.NonEmptyString.check(Schema.isMaxLength(80_000)),\n}) {}\n\n/** The provider-neutral input to one review pass. */\nexport class ReviewRequest extends Schema.Class<ReviewRequest>(\n \"@effect-agent/pr-review/ReviewRequest\",\n)({\n title: Schema.String.check(Schema.isMaxLength(1_000)),\n description: Schema.String.check(Schema.isMaxLength(20_000)),\n baseRevision: Revision,\n headRevision: Revision,\n changes: Schema.Array(ReviewChange).check(Schema.isMaxLength(100)),\n unreviewedPaths: Schema.Array(ReviewPath).check(Schema.isMaxLength(300)),\n}) {}\n\nexport const ReviewSeverity = Schema.Literals([\"blocking\", \"important\", \"nit\"]);\nexport type ReviewSeverity = typeof ReviewSeverity.Type;\n\n/** A model-claimed problem kind used only to label findings for readers. */\nexport const ReviewCategory = Schema.Literals([\n \"correctness\",\n \"security\",\n \"concurrency\",\n \"performance\",\n \"resources\",\n \"reliability\",\n \"error-handling\",\n \"testing\",\n \"maintainability\",\n \"style\",\n \"docs\",\n]);\nexport type ReviewCategory = typeof ReviewCategory.Type;\n\n/** One actionable defect. `line` is a RIGHT-side line in the supplied patch. */\nexport class ReviewFinding extends Schema.Class<ReviewFinding>(\n \"@effect-agent/pr-review/ReviewFinding\",\n)({\n path: ReviewPath,\n line: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n severity: ReviewSeverity,\n /** Presentation label only; it never changes review admission or failure policy. */\n category: ReviewCategory,\n title: Schema.NonEmptyString.check(Schema.isMaxLength(200)),\n body: Schema.NonEmptyString.check(Schema.isMaxLength(2_000)),\n}) {}\n\n/** The only model-authored output. An empty findings array is a successful review. */\nexport class ReviewReport extends Schema.Class<ReviewReport>(\n \"@effect-agent/pr-review/ReviewReport\",\n)({\n summary: Schema.NonEmptyString.check(Schema.isMaxLength(6_000)),\n findings: Schema.Array(ReviewFinding).check(Schema.isMaxLength(12)),\n}) {}\n\nconst ReviewUsageFields = Schema.Struct({\n inputTokens: Schema.Natural,\n uncachedInputTokens: Schema.Natural,\n cachedInputTokens: Schema.Natural,\n cacheWriteInputTokens: Schema.Natural,\n outputTokens: Schema.Natural,\n estimatedCostMicrousd: Schema.optionalKey(Schema.Natural),\n}).check(\n Schema.makeFilter(\n (usage) =>\n usage.inputTokens ===\n usage.uncachedInputTokens + usage.cachedInputTokens + usage.cacheWriteInputTokens,\n { title: \"Input token total equals uncached, cached, and cache-write components\" },\n ),\n);\n\nexport class ReviewUsage extends Schema.Class<ReviewUsage>(\"@effect-agent/pr-review/ReviewUsage\")(\n ReviewUsageFields,\n) {}\n\nexport class ReviewOutcome extends Schema.Class<ReviewOutcome>(\n \"@effect-agent/pr-review/ReviewOutcome\",\n)({\n report: ReviewReport,\n turns: Schema.Natural,\n usage: ReviewUsage,\n}) {}\n\nconst BASE_INSTRUCTIONS = `Review the supplied pull-request diff once.\n\nReport only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.\n\nEvery finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches.`;\n\nexport const reviewPolicy = AgentPolicy.make({\n maxTurns: 1,\n maxToolCalls: 1,\n maxDuration: \"5 minutes\",\n toolConcurrency: 1,\n tokenBudget: 56_000,\n completionReserveTokens: 8_000,\n contextTokenLimit: 48_000,\n onExhaustion: \"fail\",\n});\n\nconst makeDefinition = (guidance?: string) =>\n Agent.define(\"pr-review\", {\n input: ReviewRequest,\n output: ReviewReport,\n instructions:\n guidance === undefined || guidance.trim().length === 0\n ? BASE_INSTRUCTIONS\n : `${BASE_INSTRUCTIONS}\\n\\nRepository guidance:\\n${guidance.trim()}`,\n toolkit: Toolkit.empty,\n policy: reviewPolicy,\n description: \"Review one supplied pull-request diff in a single model call.\",\n metadata: { deploymentClass: \"E\", surface: \"read-only\" },\n });\n\nexport const reviewBudgetLimits = UsageBudgetLimits.make({\n maxInputTokens: 48_000,\n maxOutputTokens: 8_000,\n maxToolCalls: 0,\n maxDurationMillis: 300_000,\n});\n\n/** Return every RIGHT-side line on which GitHub can place a diff comment. */\nexport const commentableLines = (patch: string): ReadonlySet<number> => {\n const lines = new Set<number>();\n let right: number | undefined;\n for (const text of patch.split(\"\\n\")) {\n const hunk = /^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@/.exec(text);\n if (hunk !== null) {\n right = Number(hunk[1]);\n continue;\n }\n if (right === undefined || text.startsWith(\"\\\\\")) continue;\n if (text.startsWith(\"-\")) continue;\n if (text.startsWith(\"+\") || text.startsWith(\" \")) {\n lines.add(right);\n right += 1;\n }\n }\n return lines;\n};\n\nexport const isCommentableLine = (patch: string, line: number): boolean =>\n commentableLines(patch).has(line);\n\n/**\n * Treat model output as untrusted: remove unknown paths, demote invalid line\n * anchors to top-level findings, and collapse exact duplicates.\n */\nexport const sanitizeReviewReport = (\n request: Pick<ReviewRequest, \"changes\">,\n report: ReviewReport,\n): ReviewReport => {\n const patches = new Map(request.changes.map((change) => [change.path, change.patch] as const));\n const seen = new Set<string>();\n const findings: Array<ReviewFinding> = [];\n for (const finding of report.findings) {\n const patch = patches.get(finding.path);\n if (patch === undefined) continue;\n const line =\n finding.line !== undefined && isCommentableLine(patch, finding.line)\n ? finding.line\n : undefined;\n const key = `${finding.path}\\u0000${String(line ?? \"\")}\\u0000${finding.title.trim().toLowerCase()}`;\n if (seen.has(key)) continue;\n seen.add(key);\n findings.push(\n ReviewFinding.make({\n path: finding.path,\n ...(line === undefined ? {} : { line }),\n severity: finding.severity,\n category: finding.category,\n title: finding.title,\n body: finding.body,\n }),\n );\n }\n return ReviewReport.make({ summary: report.summary, findings });\n};\n\nexport interface ReviewerOptions<Provider, ModelProvides, ModelRequires> {\n readonly model: Model.Model<Provider, LanguageModel.LanguageModel | ModelProvides, ModelRequires>;\n readonly guidance?: string | undefined;\n readonly estimateCostMicrousd?: RunCostEstimator | undefined;\n}\n\n/** Build a provider-neutral reviewer. The returned `review` performs exactly one Run. */\nexport const makeReviewer = <Provider, ModelProvides, ModelRequires>(\n options: ReviewerOptions<Provider, ModelProvides, ModelRequires>,\n) => {\n const definition = makeDefinition(options.guidance);\n const binding = Agent.withModel(definition, options.model);\n const review = (request: ReviewRequest) =>\n Effect.gen(function* () {\n const budget = yield* makeUsageBudget(reviewBudgetLimits);\n const result = yield* AgentRuntime.run(binding, request, {\n budget: toRunBudgetHook(budget),\n ...(options.estimateCostMicrousd === undefined\n ? {}\n : { estimateCostMicrousd: options.estimateCostMicrousd }),\n });\n const usage = yield* budget.snapshot;\n return ReviewOutcome.make({\n report: sanitizeReviewReport(request, result.output),\n turns: result.turns,\n usage: ReviewUsage.make({\n inputTokens: usage.inputTokens,\n uncachedInputTokens: Math.max(\n 0,\n usage.inputTokens - usage.cacheReadInputTokens - usage.cacheWriteInputTokens,\n ),\n cachedInputTokens: usage.cacheReadInputTokens,\n cacheWriteInputTokens: usage.cacheWriteInputTokens,\n outputTokens: usage.outputTokens,\n ...(options.estimateCostMicrousd === undefined\n ? {}\n : { estimatedCostMicrousd: usage.costMicrousd }),\n }),\n });\n }).pipe(Effect.provide(IdGenerator.layer), Effect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,CACH;CACF;CACA,OAAO,aAAa,KAAK;EAAE,SAAS,OAAO;EAAS;CAAS,CAAC;AAChE;;AASA,MAAa,gBACX,YACG;CACH,MAAM,aAAa,eAAe,QAAQ,QAAQ;CAClD,MAAM,UAAU,MAAM,UAAU,YAAY,QAAQ,KAAK;CACzD,MAAM,UAAU,YACd,OAAO,IAAI,aAAa;EACtB,MAAM,SAAS,OAAO,gBAAgB,kBAAkB;EACxD,MAAM,SAAS,OAAO,aAAa,IAAI,SAAS,SAAS;GACvD,QAAQ,gBAAgB,MAAM;GAC9B,GAAI,QAAQ,yBAAyB,KAAA,IACjC,CAAC,IACD,EAAE,sBAAsB,QAAQ,qBAAqB;EAC3D,CAAC;EACD,MAAM,QAAQ,OAAO,OAAO;EAC5B,OAAO,cAAc,KAAK;GACxB,QAAQ,qBAAqB,SAAS,OAAO,MAAM;GACnD,OAAO,OAAO;GACd,OAAO,YAAY,KAAK;IACtB,aAAa,MAAM;IACnB,qBAAqB,KAAK,IACxB,GACA,MAAM,cAAc,MAAM,uBAAuB,MAAM,qBACzD;IACA,mBAAmB,MAAM;IACzB,uBAAuB,MAAM;IAC7B,cAAc,MAAM;IACpB,GAAI,QAAQ,yBAAyB,KAAA,IACjC,CAAC,IACD,EAAE,uBAAuB,MAAM,aAAa;GAClD,CAAC;EACH,CAAC;CACH,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,YAAY,KAAK,GAAG,OAAO,MAAM;CAC1D,OAAO;EAAE;EAAY;EAAS;CAAO;AACvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-agent/pr-review",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.31",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"effect": "4.0.0-rc.110",
|
|
12
|
-
"effect-agent": "0.1.0-beta.
|
|
12
|
+
"effect-agent": "0.1.0-beta.31"
|
|
13
13
|
},
|
|
14
14
|
"description": "A provider-neutral, single-pass pull-request review agent.",
|
|
15
15
|
"license": "MIT",
|
package/src/review.ts
CHANGED
|
@@ -5,11 +5,14 @@ import {
|
|
|
5
5
|
AgentRuntime,
|
|
6
6
|
IdGenerator,
|
|
7
7
|
makeUsageBudget,
|
|
8
|
+
type RunCostEstimator,
|
|
8
9
|
toRunBudgetHook,
|
|
9
10
|
UsageBudgetLimits,
|
|
10
11
|
} from "effect-agent";
|
|
11
12
|
import { type LanguageModel, type Model, Toolkit } from "effect/unstable/ai";
|
|
12
13
|
|
|
14
|
+
export type { RunCostEstimator };
|
|
15
|
+
|
|
13
16
|
const ReviewPath = Schema.NonEmptyString.check(Schema.isMaxLength(512));
|
|
14
17
|
const Revision = Schema.NonEmptyString.check(Schema.isMaxLength(128));
|
|
15
18
|
|
|
@@ -43,6 +46,7 @@ export const ReviewCategory = Schema.Literals([
|
|
|
43
46
|
"concurrency",
|
|
44
47
|
"performance",
|
|
45
48
|
"resources",
|
|
49
|
+
"reliability",
|
|
46
50
|
"error-handling",
|
|
47
51
|
"testing",
|
|
48
52
|
"maintainability",
|
|
@@ -72,10 +76,25 @@ export class ReviewReport extends Schema.Class<ReviewReport>(
|
|
|
72
76
|
findings: Schema.Array(ReviewFinding).check(Schema.isMaxLength(12)),
|
|
73
77
|
}) {}
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
const ReviewUsageFields = Schema.Struct({
|
|
76
80
|
inputTokens: Schema.Natural,
|
|
81
|
+
uncachedInputTokens: Schema.Natural,
|
|
82
|
+
cachedInputTokens: Schema.Natural,
|
|
83
|
+
cacheWriteInputTokens: Schema.Natural,
|
|
77
84
|
outputTokens: Schema.Natural,
|
|
78
|
-
|
|
85
|
+
estimatedCostMicrousd: Schema.optionalKey(Schema.Natural),
|
|
86
|
+
}).check(
|
|
87
|
+
Schema.makeFilter(
|
|
88
|
+
(usage) =>
|
|
89
|
+
usage.inputTokens ===
|
|
90
|
+
usage.uncachedInputTokens + usage.cachedInputTokens + usage.cacheWriteInputTokens,
|
|
91
|
+
{ title: "Input token total equals uncached, cached, and cache-write components" },
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export class ReviewUsage extends Schema.Class<ReviewUsage>("@effect-agent/pr-review/ReviewUsage")(
|
|
96
|
+
ReviewUsageFields,
|
|
97
|
+
) {}
|
|
79
98
|
|
|
80
99
|
export class ReviewOutcome extends Schema.Class<ReviewOutcome>(
|
|
81
100
|
"@effect-agent/pr-review/ReviewOutcome",
|
|
@@ -89,7 +108,7 @@ const BASE_INSTRUCTIONS = `Review the supplied pull-request diff once.
|
|
|
89
108
|
|
|
90
109
|
Report only concrete correctness, security, reliability, or maintainability defects that the author should act on. Do not praise, restate the change, invent missing repository context, or ask for speculative cleanup. An empty findings array is valid.
|
|
91
110
|
|
|
92
|
-
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it.`;
|
|
111
|
+
Every finding must use an exact supplied path. Set line only to a RIGHT-side added or context line visible in that path's unified patch; otherwise omit line. Use blocking only for a defect that should prevent shipping. Classify each finding with the closest available category. Treat unreviewedPaths as unavailable scope and never imply that you inspected it. A changed file absent from changes may have been withheld by the host; never infer that it was not changed, and report only defects proven by the supplied patches.`;
|
|
93
112
|
|
|
94
113
|
export const reviewPolicy = AgentPolicy.make({
|
|
95
114
|
maxTurns: 1,
|
|
@@ -184,6 +203,7 @@ export const sanitizeReviewReport = (
|
|
|
184
203
|
export interface ReviewerOptions<Provider, ModelProvides, ModelRequires> {
|
|
185
204
|
readonly model: Model.Model<Provider, LanguageModel.LanguageModel | ModelProvides, ModelRequires>;
|
|
186
205
|
readonly guidance?: string | undefined;
|
|
206
|
+
readonly estimateCostMicrousd?: RunCostEstimator | undefined;
|
|
187
207
|
}
|
|
188
208
|
|
|
189
209
|
/** Build a provider-neutral reviewer. The returned `review` performs exactly one Run. */
|
|
@@ -197,6 +217,9 @@ export const makeReviewer = <Provider, ModelProvides, ModelRequires>(
|
|
|
197
217
|
const budget = yield* makeUsageBudget(reviewBudgetLimits);
|
|
198
218
|
const result = yield* AgentRuntime.run(binding, request, {
|
|
199
219
|
budget: toRunBudgetHook(budget),
|
|
220
|
+
...(options.estimateCostMicrousd === undefined
|
|
221
|
+
? {}
|
|
222
|
+
: { estimateCostMicrousd: options.estimateCostMicrousd }),
|
|
200
223
|
});
|
|
201
224
|
const usage = yield* budget.snapshot;
|
|
202
225
|
return ReviewOutcome.make({
|
|
@@ -204,7 +227,16 @@ export const makeReviewer = <Provider, ModelProvides, ModelRequires>(
|
|
|
204
227
|
turns: result.turns,
|
|
205
228
|
usage: ReviewUsage.make({
|
|
206
229
|
inputTokens: usage.inputTokens,
|
|
230
|
+
uncachedInputTokens: Math.max(
|
|
231
|
+
0,
|
|
232
|
+
usage.inputTokens - usage.cacheReadInputTokens - usage.cacheWriteInputTokens,
|
|
233
|
+
),
|
|
234
|
+
cachedInputTokens: usage.cacheReadInputTokens,
|
|
235
|
+
cacheWriteInputTokens: usage.cacheWriteInputTokens,
|
|
207
236
|
outputTokens: usage.outputTokens,
|
|
237
|
+
...(options.estimateCostMicrousd === undefined
|
|
238
|
+
? {}
|
|
239
|
+
: { estimatedCostMicrousd: usage.costMicrousd }),
|
|
208
240
|
}),
|
|
209
241
|
});
|
|
210
242
|
}).pipe(Effect.provide(IdGenerator.layer), Effect.scoped);
|