Principle:777genius Agent teams ai Review Application
| Knowledge Sources | |
|---|---|
| Domains | Code_Review, Version_Control |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Pattern for applying file-level and hunk-level review decisions (accept/reject) to a worktree with three-way merge conflict detection and disk transition tracking.
Description
Review Application takes a set of accepted and rejected file/hunk decisions and applies them to the filesystem. For each file, accepted hunks are written to disk while rejected hunks are left in their pre-change state. When the file has been modified since the decision was made, a three-way merge is attempted; if the merge produces conflicts, the file is marked as conflicted.
Key aspects:
- Batch application: All decisions in a request are applied in a single pass, with per-file results aggregated into an `ApplyReviewResult`.
- Three-way merge: When a file has changed since the decision's content snapshot, a three-way text merge resolves conflicts between the original, modified, and current content.
- Disk transition tracking: Each file's disk transition (create, modify, delete, move) is recorded for replay and recovery.
- Mutation context: An `AsyncLocalStorage` context carries hooks, observed preimages, and planned transitions across the async call chain.
- Rename recovery: File renames detected from the change ledger are validated against the review evidence before application.
Usage
Use this principle when applying review decisions to a filesystem where files may have changed between decision and application. Applicable to any diff-based review system that must handle concurrent edits safely.
Theoretical Basis
The application follows a batch apply with three-way merge pattern:
# Abstract algorithm (NOT real implementation)
async def apply_review_decisions(request, file_contents, hooks):
context = MutationContext(hooks=hooks, planned_transitions={})
for decision in request.decisions:
content = file_contents.get(decision.filePath)
if decision.fileDecision == "accept":
merged = apply_accepted_hunks(content, decision.hunkDecisions)
else:
merged = apply_rejected_hunks(content, decision.hunkDecisions)
if file_changed_since_snapshot(decision.filePath):
merged, has_conflicts = three_way_merge(
base=content.original,
ours=merged,
theirs=current_disk_content
)
await atomic_write(decision.filePath, merged)
context.planned_transitions[decision.filePath] = disk_transition
return ApplyReviewResult(
applied=applied_count,
skipped=skipped_count,
conflicts=conflict_count,
errors=errors
)