Implementation:777genius Agent teams ai ReviewApplierService applyReviewDecisions
| Knowledge Sources | |
|---|---|
| Domains | Code_Review, Version_Control |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for applying file-level and hunk-level review decisions (accept/reject) to a worktree with three-way merge conflict detection and disk transition tracking, provided by the Agent Teams application.
Description
The ReviewApplierService.applyReviewDecisions() method takes a batch of review decisions and applies them to the filesystem. For each file, it uses the file content snapshots and hunk-level decisions to compute the final content. When a file has changed since the decision was made, a three-way merge resolves conflicts.
Key behaviors:
- Mutation context: Uses `AsyncLocalStorage` (`reviewApplyMutationContext`) to carry hooks, observed preimages, and planned transitions across the async call chain.
- Replay evidence validation: `assertReviewReplayEvidence()` validates that file contents and disk transitions are consistent before application.
- Rename recovery: Detects file renames from the change ledger and validates them against the review evidence before applying.
- Disk transition tracking: Each file's transition (create, modify, delete, move) is recorded in `context.plannedTransitions` for replay and recovery.
- Checkpoint hook: If no errors occur and disk transitions exist, `checkpointDiskTransitions` hook is called to persist the transition record.
Usage
- Applying review decisions: Call after the user has made all accept/reject decisions and wants to apply them to the filesystem.
- Replay after crash: Pass `initialDiskTransitions` to resume an interrupted application.
Code Reference
Source Location
- Repository: agent-teams
- File: src/main/services/team/ReviewApplierService.ts
Signature
export interface ApplyReviewRequest {
decisions: Array<{
filePath: string;
fileDecision: HunkDecision;
hunkDecisions: Record<string, HunkDecision>;
}>;
}
export interface ReviewApplyMutationHooks {
checkpointDiskTransitions?: (transitions: DiskTransition[]) => Promise<void>;
initialDiskTransitions?: DiskTransition[];
}
export class ReviewApplierService {
async applyReviewDecisions(
request: ApplyReviewRequest,
fileContents?: Map<string, FileChangeWithContent>,
hooks?: ReviewApplyMutationHooks
): Promise<ApplyReviewResult>;
}
Import
import { ReviewApplierService } from '@main/services/team/ReviewApplierService';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request.decisions | Array | Yes | Decisions with filePath, fileDecision, hunkDecisions |
| fileContents | Map<string, FileChangeWithContent> | No (default empty) | File content with snippets for merge |
| hooks.checkpointDiskTransitions | (transitions) => Promise<void> | No | Called after successful application to persist transitions |
| hooks.initialDiskTransitions | DiskTransition[] | No | Transitions from a previous interrupted application for replay |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Promise<ApplyReviewResult> | Application result with counts and errors |
| ApplyReviewResult.applied | number | Number of files successfully applied |
| ApplyReviewResult.skipped | number | Number of files skipped (e.g., no changes needed) |
| ApplyReviewResult.conflicts | number | Number of files with merge conflicts |
| ApplyReviewResult.errors | Array | Per-file errors |
| ApplyReviewResult.diskTransitions | DiskTransition[] | Recorded disk state changes |
Usage Examples
Applying Review Decisions
import { ReviewApplierService } from '@main/services/team/ReviewApplierService';
const service = new ReviewApplierService();
const result = await service.applyReviewDecisions(
{
decisions: [
{
filePath: 'src/auth/login.ts',
fileDecision: 'partial',
hunkDecisions: {
'hunk-0': 'accept',
'hunk-1': 'reject',
'hunk-2': 'accept',
},
},
],
},
fileContentsMap // Map<string, FileChangeWithContent> from ChangeExtractorService
);
console.log(`Applied: ${result.applied}, Conflicts: ${result.conflicts}`);
if (result.errors.length > 0) {
console.error('Errors:', result.errors);
}
With Checkpoint Hook
const result = await service.applyReviewDecisions(
request,
fileContentsMap,
{
checkpointDiskTransitions: async (transitions) => {
// Persist disk transitions for crash recovery
await fs.writeFile(
transitionLogPath,
JSON.stringify(transitions, null, 2)
);
},
}
);
Replay After Crash
// Resume an interrupted application using stored transitions
const savedTransitions = JSON.parse(
await fs.readFile(transitionLogPath, 'utf-8')
);
const result = await service.applyReviewDecisions(
request,
fileContentsMap,
{
initialDiskTransitions: savedTransitions,
checkpointDiskTransitions: async (transitions) => {
await fs.writeFile(transitionLogPath, JSON.stringify(transitions));
},
}
);
Related Pages
Implements Principle
Requires Environment
- Environment:777genius_Agent_teams_ai_Electron_Main_Process
- Environment:777genius_Agent_teams_ai_Git_Worktrees