Implementation:777genius Agent teams ai changeReviewSlice
| Knowledge Sources | |
|---|---|
| Domains | Code_Review, State_Management |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for managing reactive code review state in a Zustand store slice, provided by the Agent Teams application.
Description
The createChangeReviewSlice function creates a Zustand state slice that holds all code review state for the application. It tracks the active change set, file-level and hunk-level decisions, file contents with loading flags, hunk context hashes, content version numbers, and file invalidation logic for handling path aliases.
Key state fields:
- activeChangeSet: The current change set being reviewed (files, warnings, confidence).
- fileDecisions / hunkDecisions: Accept/reject decisions per file and per hunk.
- fileContents / fileContentsLoading: Loaded file content with loading state per file.
- hunkContextHashesByFile: Context hashes that identify specific code regions for decision matching.
- fileContentVersionByPath: Version counter per file path; bumped when content is invalidated.
The slice includes a `buildResolvedFileInvalidation` helper that clears cached content, chunk counts, loading flags, and context hashes across all path aliases when a file's diff changes.
Usage
- UI subscription: React components subscribe to the slice for reactive rendering of review state.
- File content invalidation: When a file's diff changes, call the invalidation logic to clear stale decisions.
- Decision tracking: The store is the single source of truth for what the user has accepted or rejected before applying.
Code Reference
Source Location
- Repository: agent-teams
- File: src/renderer/store/slices/changeReviewSlice.ts
Signature
import type { StateCreator } from 'zustand';
export const createChangeReviewSlice: StateCreator<
AppState,
[],
[],
ChangeReviewSlice
> = (set, get) => {
// State includes:
// - activeChangeSet: TaskChangeSetV2 | null
// - fileDecisions: Record<string, HunkDecision>
// - hunkDecisions: Record<string, HunkDecision>
// - fileContents: Record<string, FileChangeWithContent>
// - fileContentsLoading: Record<string, boolean>
// - hunkContextHashesByFile: Record<string, Record<number, string>>
// - fileContentVersionByPath: Record<string, number>
// - fileChunkCounts: Record<string, number>
// Actions: setActiveChangeSet, setFileDecision, setHunkDecision,
// loadFileContent, invalidateFile, clearDecisions, etc.
return { /* slice implementation */ };
};
Import
import { createChangeReviewSlice } from '@renderer/store/slices/changeReviewSlice';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| set | (partial) => void | Yes | Zustand state setter |
| get | () => AppState | Yes | Zustand state accessor |
Outputs
| Name | Type | Description |
|---|---|---|
| return | ChangeReviewSlice | Zustand slice with state and actions for code review |
| ChangeReviewSlice.activeChangeSet | null | Currently reviewed change set |
| ChangeReviewSlice.fileDecisions | Record<string, HunkDecision> | File-level accept/reject decisions |
| ChangeReviewSlice.hunkDecisions | Record<string, HunkDecision> | Hunk-level accept/reject decisions |
Usage Examples
Creating the Store with the Slice
import { create } from 'zustand';
import { createChangeReviewSlice } from '@renderer/store/slices/changeReviewSlice';
const useStore = create<AppState>((...args) => ({
...createChangeReviewSlice(...args),
// ... other slices
}));
// In a React component:
function ReviewPanel({ teamName, taskId }) {
const activeChangeSet = useStore((s) => s.activeChangeSet);
const fileDecisions = useStore((s) => s.fileDecisions);
return (
<div>
{activeChangeSet?.files.map((file) => (
<FileReview
key={file.filePath}
file={file}
decision={fileDecisions[file.filePath]}
/>
))}
</div>
);
}
Setting File and Hunk Decisions
const setFileDecision = useStore((s) => s.setFileDecision);
const setHunkDecision = useStore((s) => s.setHunkDecision);
// Accept an entire file
setFileDecision('src/auth/login.ts', 'accept');
// Reject a specific hunk
setHunkDecision('src/auth/login.ts', 'hunk-3', 'reject');