Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | 2x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x | import type { Octokit } from '@octokit/rest';
import { z } from 'zod';
import type { ExistingComment } from '../../output/dedup.js';
import {
buildFileListSection,
buildJsonOutputSection,
buildTaggedSection,
joinPromptSections,
} from '../../sdk/prompt-sections.js';
import { getRuntime, type AuxiliaryTool, type RuntimeName } from '../../sdk/runtimes/index.js';
import { emptyUsage } from '../../sdk/usage.js';
import { FixJudgeVerdictSchema } from './types.js';
import type { FixJudgeResult } from './types.js';
import { fetchFileContent, fetchFileLines } from './github.js';
export interface FixJudgeInput {
comment: ExistingComment;
skillName?: string;
changedFiles: string[];
codeBeforeFix: string;
codeAfterFix?: string;
commitMessages?: string[];
}
export interface FixJudgeContext {
octokit: Octokit;
owner: string;
repo: string;
baseSha: string;
headSha: string;
patches: Map<string, string>;
}
export interface FixJudgeRuntimeOptions {
runtime?: RuntimeName;
model?: string;
maxRetries?: number;
}
const TOOL_DEFINITIONS: AuxiliaryTool[] = [
{
name: 'get_file_diff',
description: 'Get the unified diff showing what changed in a file between the two commits.',
inputSchema: {
type: 'object' as const,
properties: {
path: { type: 'string', description: 'File path to get diff for' },
},
required: ['path'],
},
},
{
name: 'get_file_at_commit',
description:
'Get file content at a specific commit. Use "before" for pre-fix state, "after" for post-fix state. Optionally specify line range.',
inputSchema: {
type: 'object' as const,
properties: {
path: { type: 'string', description: 'File path to fetch' },
commit: { type: 'string', enum: ['before', 'after'], description: 'before = pre-fix, after = post-fix' },
startLine: { type: 'number', description: 'Start line (1-indexed, inclusive)' },
endLine: { type: 'number', description: 'End line (1-indexed, inclusive)' },
},
required: ['path', 'commit'],
},
},
];
function buildPrompt(input: FixJudgeInput): string {
const { comment, changedFiles, codeBeforeFix, codeAfterFix, commitMessages } = input;
const afterCodeSection = codeAfterFix
? buildTaggedSection('after_code', codeAfterFix)
: undefined;
const commitMessagesSection =
commitMessages && commitMessages.length > 0
? buildTaggedSection('developer_intent', [
...commitMessages.map((msg, i) => `${i + 1}. ${msg.split('\n')[0]}`),
'',
'Use these to help understand what the developer was trying to do. A commit mentioning "fix" or the issue topic suggests intent to address it.',
])
: undefined;
const investigationStrategy = codeAfterFix
? `Compare the BEFORE and AFTER code above to determine if the issue was fixed.
Use tools only if you need additional context:
- \`get_file_diff(path)\` - See unified diff of changes to a file
- \`get_file_at_commit(path, "before"|"after", startLine?, endLine?)\` - Read more file content if needed`
: `Use tools to determine if the issue was fixed:
1. **Start with get_file_diff** on the issue's file (if changed) to see what was modified
2. **Use get_file_at_commit with "after"** to see the current state at the issue location
3. **Check related files** if the fix might involve changes elsewhere (imports, shared utilities, etc.)
Tools:
- \`get_file_diff(path)\` - See unified diff of changes to a file
- \`get_file_at_commit(path, "before"|"after", startLine?, endLine?)\` - Read file content at either commit`;
return joinPromptSections([
`<task>
Judge whether a code change fixed a reported issue.
</task>`,
`<key_question>
Does the reported issue still exist in the code after this commit?
</key_question>`,
`<verdict_definitions>
Choose ONE verdict based on these criteria:
resolved - The issue NO LONGER EXISTS. Evidence:
- The problematic code was corrected (directly or via equivalent fix)
- The code was refactored in a way that eliminates the issue by design
- The problematic code was intentionally removed (file deleted, function removed, dead code cleaned up)
attempted_failed - A fix was CLEARLY ATTEMPTED but the issue PERSISTS. Evidence:
- Changes DIRECTLY modify the reported file at or near the issue location
- AND the changes appear specifically intended to address THIS issue
- BUT the core issue remains (wrong fix, incomplete fix, edge cases missed)
- Use this ONLY when there's clear evidence of intent to fix THIS specific issue
- Do NOT use for general refactoring, unrelated bug fixes, or changes to other files
- When in doubt between attempted_failed and not_attempted, prefer not_attempted
not_attempted - The issue was NOT ADDRESSED. Evidence:
- No changes to the problematic code or its logic
- Changes are unrelated (different feature, different bug, unrelated refactor)
- The reported code is identical or functionally unchanged
- Changes are in other files with no clear connection to the reported issue
</verdict_definitions>`,
buildTaggedSection('reported_issue', [
`<title>${comment.title}</title>`,
`<file>${comment.path}</file>`,
`<line>${comment.line}</line>`,
'<description>',
comment.description,
'</description>',
]),
buildTaggedSection('before_code', codeBeforeFix),
afterCodeSection,
buildFileListSection('changed_files', changedFiles),
commitMessagesSection,
buildTaggedSection('investigation_strategy', investigationStrategy),
buildJsonOutputSection(`{"status": "resolved|attempted_failed|not_attempted", "reasoning": "One sentence explaining your verdict"}
Put your one-sentence explanation in the "reasoning" field.`),
]);
}
const GetFileDiffInput = z.object({
path: z.string(),
});
const GetFileAtCommitInput = z.object({
path: z.string(),
commit: z.enum(['before', 'after']),
startLine: z.number().optional(),
endLine: z.number().optional(),
});
function createToolExecutor(ctx: FixJudgeContext): (name: string, input: Record<string, unknown>) => Promise<string> {
return async (name: string, input: Record<string, unknown>): Promise<string> => {
if (name === 'get_file_diff') {
const parsed = GetFileDiffInput.safeParse(input);
if (!parsed.success) {
return `Invalid input: ${parsed.error.message}`;
}
const patch = ctx.patches.get(parsed.data.path);
return patch ?? 'No changes found for this file';
}
if (name === 'get_file_at_commit') {
const parsed = GetFileAtCommitInput.safeParse(input);
if (!parsed.success) {
return `Invalid input: ${parsed.error.message}`;
}
const { path, commit, startLine, endLine } = parsed.data;
const sha = commit === 'before' ? ctx.baseSha : ctx.headSha;
try {
if (startLine !== undefined && endLine !== undefined) {
return await fetchFileLines(ctx.octokit, ctx.owner, ctx.repo, path, sha, startLine, endLine);
}
const content = await fetchFileContent(ctx.octokit, ctx.owner, ctx.repo, path, sha);
const lines = content.split('\n');
if (lines.length > 100) {
const numbered = lines.slice(0, 100).map((line, i) => `${i + 1}: ${line}`);
return `${numbered.join('\n')}\n\n[... ${lines.length - 100} more lines truncated]`;
}
return lines.map((line, i) => `${i + 1}: ${line}`).join('\n');
} catch (error) {
return `Error fetching file: ${error instanceof Error ? error.message : String(error)}`;
}
}
return `Unknown tool: ${name}`;
};
}
/**
* Evaluate whether a code change fixed a reported issue.
* Uses Haiku with tool use to explore the changes.
*/
export async function evaluateFix(
input: FixJudgeInput,
context: FixJudgeContext,
apiKey: string,
runtimeOptionsOrMaxRetries?: number | FixJudgeRuntimeOptions
): Promise<FixJudgeResult> {
const runtimeOptions: FixJudgeRuntimeOptions =
runtimeOptionsOrMaxRetries !== null && typeof runtimeOptionsOrMaxRetries === 'object'
? runtimeOptionsOrMaxRetries
: runtimeOptionsOrMaxRetries == null
? {}
: { maxRetries: runtimeOptionsOrMaxRetries };
const fallback: FixJudgeResult = {
verdict: { status: 'not_attempted', reasoning: 'Evaluation failed' },
usage: emptyUsage(),
usedFallback: true,
};
const prompt = buildPrompt(input);
const executeTool = createToolExecutor(context);
const result = await getRuntime(runtimeOptions.runtime).runAuxiliary({
task: 'fix_evaluation',
agentName: input.skillName,
apiKey,
prompt,
schema: FixJudgeVerdictSchema,
tools: TOOL_DEFINITIONS,
executeTool,
model: runtimeOptions.model,
maxIterations: 5,
maxRetries: runtimeOptions.maxRetries,
});
Eif (result.success) {
return { verdict: result.data, usage: result.usage, usedFallback: false };
}
return { ...fallback, usage: result.usage };
}
|