@effect-agent/pr-review 0.1.0-beta.31 → 0.1.0-beta.32
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/dist/index.mjs +8 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/review.ts +11 -11
package/dist/index.mjs
CHANGED
|
@@ -79,7 +79,8 @@ const reviewPolicy = AgentPolicy.make({
|
|
|
79
79
|
tokenBudget: 56e3,
|
|
80
80
|
completionReserveTokens: 8e3,
|
|
81
81
|
contextTokenLimit: 48e3,
|
|
82
|
-
onExhaustion: "fail"
|
|
82
|
+
onExhaustion: "fail",
|
|
83
|
+
runStatus: "off"
|
|
83
84
|
});
|
|
84
85
|
const makeDefinition = (guidance) => Agent.define("pr-review", {
|
|
85
86
|
input: ReviewRequest,
|
|
@@ -131,17 +132,18 @@ const sanitizeReviewReport = (request, report) => {
|
|
|
131
132
|
const patch = patches.get(finding.path);
|
|
132
133
|
if (patch === void 0) continue;
|
|
133
134
|
const line = finding.line !== void 0 && isCommentableLine(patch, finding.line) ? finding.line : void 0;
|
|
134
|
-
const
|
|
135
|
-
if (seen.has(key)) continue;
|
|
136
|
-
seen.add(key);
|
|
137
|
-
findings.push(ReviewFinding.make({
|
|
135
|
+
const sanitized = ReviewFinding.make({
|
|
138
136
|
path: finding.path,
|
|
139
137
|
...line === void 0 ? {} : { line },
|
|
140
138
|
severity: finding.severity,
|
|
141
139
|
category: finding.category,
|
|
142
140
|
title: finding.title,
|
|
143
141
|
body: finding.body
|
|
144
|
-
})
|
|
142
|
+
});
|
|
143
|
+
const key = JSON.stringify(sanitized);
|
|
144
|
+
if (seen.has(key)) continue;
|
|
145
|
+
seen.add(key);
|
|
146
|
+
findings.push(sanitized);
|
|
145
147
|
}
|
|
146
148
|
return ReviewReport.make({
|
|
147
149
|
summary: report.summary,
|
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 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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ChB,CAAC,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"}
|
|
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 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 runStatus: \"off\",\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 sanitized = 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 const key = JSON.stringify(sanitized);\n if (seen.has(key)) continue;\n seen.add(key);\n findings.push(sanitized);\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.scoped);\n return { definition, binding, review } as const;\n};\n"],"mappings":";;;;AAeA,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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;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.32",
|
|
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.32"
|
|
13
13
|
},
|
|
14
14
|
"description": "A provider-neutral, single-pass pull-request review agent.",
|
|
15
15
|
"license": "MIT",
|
package/src/review.ts
CHANGED
|
@@ -119,6 +119,7 @@ export const reviewPolicy = AgentPolicy.make({
|
|
|
119
119
|
completionReserveTokens: 8_000,
|
|
120
120
|
contextTokenLimit: 48_000,
|
|
121
121
|
onExhaustion: "fail",
|
|
122
|
+
runStatus: "off",
|
|
122
123
|
});
|
|
123
124
|
|
|
124
125
|
const makeDefinition = (guidance?: string) =>
|
|
@@ -183,19 +184,18 @@ export const sanitizeReviewReport = (
|
|
|
183
184
|
finding.line !== undefined && isCommentableLine(patch, finding.line)
|
|
184
185
|
? finding.line
|
|
185
186
|
: undefined;
|
|
186
|
-
const
|
|
187
|
+
const sanitized = ReviewFinding.make({
|
|
188
|
+
path: finding.path,
|
|
189
|
+
...(line === undefined ? {} : { line }),
|
|
190
|
+
severity: finding.severity,
|
|
191
|
+
category: finding.category,
|
|
192
|
+
title: finding.title,
|
|
193
|
+
body: finding.body,
|
|
194
|
+
});
|
|
195
|
+
const key = JSON.stringify(sanitized);
|
|
187
196
|
if (seen.has(key)) continue;
|
|
188
197
|
seen.add(key);
|
|
189
|
-
findings.push(
|
|
190
|
-
ReviewFinding.make({
|
|
191
|
-
path: finding.path,
|
|
192
|
-
...(line === undefined ? {} : { line }),
|
|
193
|
-
severity: finding.severity,
|
|
194
|
-
category: finding.category,
|
|
195
|
-
title: finding.title,
|
|
196
|
-
body: finding.body,
|
|
197
|
-
}),
|
|
198
|
-
);
|
|
198
|
+
findings.push(sanitized);
|
|
199
199
|
}
|
|
200
200
|
return ReviewReport.make({ summary: report.summary, findings });
|
|
201
201
|
};
|