fix(ext,bot): Accept All WS regression + auto_approve dual-write — VSIX v0.4.5
This commit is contained in:
@@ -61,6 +61,100 @@ export function resetPendingState(): void {
|
||||
ctx.sawRunningAfterPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle diff_review Accept all / Reject all response.
|
||||
* Extracted so both WS onResponse (extension.ts) and processResponseFile can call it.
|
||||
*
|
||||
* This was previously only in processResponseFile (file-bridge path).
|
||||
* When WS was added (v0.4.x), the onResponse handler skipped this logic entirely,
|
||||
* causing Accept All to stop working — a regression.
|
||||
*/
|
||||
export async function handleDiffReviewResponse(data: {
|
||||
request_id: string;
|
||||
approved: boolean;
|
||||
button_index?: number;
|
||||
step_type?: string;
|
||||
}): Promise<boolean> {
|
||||
const btnIdx = data.button_index ?? -1;
|
||||
const isAccept = btnIdx === 0 || (btnIdx === -1 && data.approved);
|
||||
const cmd = isAccept
|
||||
? 'antigravity.prioritized.agentAcceptAllInFile'
|
||||
: 'antigravity.prioritized.agentRejectAllInFile';
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] → ${isAccept ? 'ACCEPT' : 'REJECT'} (btnIdx=${btnIdx}, rid=${data.request_id?.substring(0, 12)})`);
|
||||
|
||||
let diffReviewDone = false;
|
||||
let modifiedFiles: string[] = [];
|
||||
|
||||
// Load tracked step indices and modified files from memory cache or pending file
|
||||
const trackedSteps: number[] = [];
|
||||
const memMeta = ctx.diffReviewMetadata.get(data.request_id);
|
||||
if (memMeta) {
|
||||
trackedSteps.push(...memMeta.edit_step_indices);
|
||||
modifiedFiles = memMeta.modified_files;
|
||||
ctx.diffReviewMetadata.delete(data.request_id);
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] loaded from memory: steps=[${trackedSteps.join(',')}] files=${modifiedFiles.length}`);
|
||||
} else {
|
||||
try {
|
||||
const pf = path.join(ctx.bridgePath, 'pending', `${data.request_id}.json`);
|
||||
if (fs.existsSync(pf)) {
|
||||
const pd = JSON.parse(fs.readFileSync(pf, 'utf-8'));
|
||||
if (pd.edit_step_indices) trackedSteps.push(...pd.edit_step_indices);
|
||||
if (pd.modified_files) modifiedFiles = pd.modified_files;
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
// Strategy 1: VS Code command — open review panel + focus each file + accept/reject
|
||||
try {
|
||||
try {
|
||||
await vscode.commands.executeCommand('antigravity.openReviewChanges');
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] openReviewChanges OK`);
|
||||
await new Promise(r => setTimeout(r, 500));
|
||||
} catch { }
|
||||
|
||||
if (modifiedFiles.length > 0) {
|
||||
for (const fp of modifiedFiles) {
|
||||
try {
|
||||
const uri = vscode.Uri.file(fp);
|
||||
const doc = await vscode.workspace.openTextDocument(uri);
|
||||
await vscode.window.showTextDocument(doc, { preview: false });
|
||||
await new Promise(r => setTimeout(r, 300));
|
||||
await vscode.commands.executeCommand(cmd);
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] ✅ ${cmd} on ${fp.split(/[\\/]/).pop()} OK`);
|
||||
diffReviewDone = true;
|
||||
} catch (e: any) {
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] per-file error on ${fp}: ${e.message?.substring(0, 80)}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await vscode.commands.executeCommand(cmd);
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] ✅ ${cmd} executed (no file list)`);
|
||||
diffReviewDone = true;
|
||||
}
|
||||
} catch (cmdErr: any) {
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] Strategy 1 command error: ${cmdErr.message?.substring(0, 200)}`);
|
||||
}
|
||||
|
||||
// Strategy 2: individual hunk accept/reject
|
||||
if (!diffReviewDone) {
|
||||
try {
|
||||
const hunkCmd = isAccept
|
||||
? 'antigravity.prioritized.agentAcceptFocusedHunk'
|
||||
: 'antigravity.prioritized.agentRejectFocusedHunk';
|
||||
await vscode.commands.executeCommand(hunkCmd);
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] ✅ ${hunkCmd} fallback OK`);
|
||||
diffReviewDone = true;
|
||||
} catch (hunkErr: any) {
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] hunk fallback error: ${hunkErr.message?.substring(0, 100)}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!diffReviewDone) {
|
||||
ctx.logToFile(`[DIFF-REVIEW-WS] ❌ ALL strategies failed for rid=${data.request_id}`);
|
||||
}
|
||||
return diffReviewDone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a registration file for the Bot to discover session → project mapping.
|
||||
* Called automatically on first step event per session.
|
||||
|
||||
Reference in New Issue
Block a user