Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:777genius Agent teams ai ReviewDecisionStore

From Leeroopedia
Knowledge Sources
Domains Code_Review, Persistence
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for persisting and loading file-level and hunk-level code review decisions with optimistic concurrency, snapshot validation, and idempotency, provided by the Agent Teams application.

Description

The ReviewDecisionStore class reads and writes review decisions to JSON files on disk. It supports loading decisions by scope (task or agent), saving decisions with revision-based optimistic concurrency, validating snapshots for integrity, and protecting against path traversal via scope token validation.

Key behaviors:

  • Scope validation: `assertSafeScope()` validates team names and scope keys against regex patterns, and scope tokens for length and null-byte safety.
  • Snapshot validation: `assertValidSnapshot()` validates hunk decisions, file decisions, context hashes, action history, and redo history, plus checks for disjoint action IDs between undo and redo.
  • Optimistic concurrency: `save()` accepts `expectedRevision`; if the current revision on disk doesn't match, the save is rejected.
  • Idempotency: `save()` accepts `mutationId`; a duplicate mutation with the same ID is detected and skipped.
  • Atomic writes: Uses `atomicWrite` helpers to prevent corruption during write.

Usage

  • Load decisions: Call `load()` with team name, scope key ('task-' or 'agent-' prefixed), and scope token (sha256 hash).
  • Save decisions: Call `save()` with decisions, scope token, optional expected revision for optimistic concurrency, and optional mutation ID for idempotency.
  • Validate before save: Call `assertValidSnapshot()` to validate decision structure before persistence.

Code Reference

Source Location

  • Repository: agent-teams
  • File: src/main/services/team/ReviewDecisionStore.ts

Signature

export class ReviewDecisionStore {
  assertValidSnapshot(data: {
    hunkDecisions: Record<string, HunkDecision>;
    fileDecisions: Record<string, HunkDecision>;
    hunkContextHashesByFile?: Record<string, Record<number, string>>;
    reviewActionHistory?: ReviewUndoAction[];
    reviewRedoHistory?: ReviewRedoAction[];
  }): void;

  async load(
    teamName: string,
    scopeKey: string,
    scopeToken: string
  ): Promise<ReviewDecisionsData | null>;

  async save(
    teamName: string,
    scopeKey: string,
    data: {
      scopeToken: string;
      hunkDecisions: Record<string, HunkDecision>;
      fileDecisions: Record<string, HunkDecision>;
      hunkContextHashesByFile?: Record<string, Record<number, string>>;
      reviewActionHistory?: ReviewUndoAction[];
      reviewRedoHistory?: ReviewRedoAction[];
      expectedRevision?: number;
      mutationId?: string;
    }
  ): Promise<number>;
}

Import

import { ReviewDecisionStore } from '@main/services/team/ReviewDecisionStore';

I/O Contract

Inputs

Name Type Required Description
teamName string Yes Team name (validated against TEAM_NAME_PATTERN)
scopeKey string Yes Scope key ('task-' or 'agent-' prefixed, validated against SCOPE_KEY_PATTERN)
scopeToken string Yes sha256 hash scope token for security
data.hunkDecisions Record<string, HunkDecision> Yes Hunk-level accept/reject decisions
data.fileDecisions Record<string, HunkDecision> Yes File-level accept/reject decisions
data.expectedRevision number No Optimistic concurrency: expected current revision
data.mutationId string No Idempotency key for safe retries

Outputs

Name Type Description
return (load) null> Stored decisions or null if not found
return (save) Promise<number> New revision number after persisted write
ReviewDecisionsData.hunkDecisions Record<string, HunkDecision> Stored hunk decisions
ReviewDecisionsData.fileDecisions Record<string, HunkDecision> Stored file decisions
ReviewDecisionsData.reviewActionHistory ReviewUndoAction[] Undo history

Usage Examples

Loading Review Decisions

import { ReviewDecisionStore } from '@main/services/team/ReviewDecisionStore';
import { createHash } from 'crypto';

const store = new ReviewDecisionStore();
const scopeToken = createHash('sha256').update('task-123').digest('hex');

// Load existing decisions for a task scope
const decisions = await store.load('my-team', 'task-123', scopeToken);
if (decisions) {
  console.log(`Loaded ${Object.keys(decisions.hunkDecisions).length} hunk decisions`);
}

Saving Decisions with Optimistic Concurrency

// Save with optimistic concurrency: if the revision on disk
// has changed since we loaded, the save is rejected
const newRevision = await store.save('my-team', 'task-123', {
  scopeToken: scopeToken,
  hunkDecisions: { 'src/auth.ts:hunk-1': 'accept', 'src/auth.ts:hunk-2': 'reject' },
  fileDecisions: { 'src/auth.ts': 'partial' },
  hunkContextHashesByFile: { 'src/auth.ts': { 0: 'hash-abc', 1: 'hash-def' } },
  expectedRevision: decisions?.revision ?? 0,  // Optimistic concurrency
  mutationId: 'mutation-456',  // Idempotency key
});

console.log(`Saved as revision ${newRevision}`);

Validating Before Save

// Validate snapshot integrity before saving
store.assertValidSnapshot({
  hunkDecisions: { 'hunk-1': 'accept' },
  fileDecisions: { 'file.ts': 'accept' },
  hunkContextHashesByFile: { 'file.ts': { 0: 'hash-abc' } },
  reviewActionHistory: [],
  reviewRedoHistory: [],
});
// Throws if any field is invalid

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment