Perfect! Now I have a comprehensive understanding. Let me create a detailed summary report.
Summary: Investigation Batch Construction in Desloppify
I've thoroughly analyzed the desloppify codebase to understand how investigation_batches are constructed, configured, and used. Here are my findings:
1. Main Batch Construction Function
Location: /Users/user_c042661f/Documents/desloppify/desloppify/intelligence/review/prepare_batches.py
Primary Function: build_investigation_batches() (lines 491-516)
- Takes a
HolisticContext (or dict), language object, optional repo_root, and max_files_per_batch
- Returns a list of pre-built batch dictionaries
- The function calls 9 specialized batch builder functions, each creating one predefined batch
2. The 9 Predefined Batches
Each batch is built by a dedicated function and has a fixed name, set of dimensions, and seed files:
| Batch # | Function | Name | Dimensions |
|---|
| 1 | _batch_arch_coupling() | "Architecture & Coupling" | cross_module_architecture, high_level_elegance |
| 2 | _batch_conventions_errors() | "Conventions & Errors" | convention_outlier, error_consistency, mid_level_elegance |
| 3 | _batch_abstractions_deps() | "Abstractions & Dependencies" | abstraction_fitness, dependency_health, mid_level_elegance, low_level_elegance |
| 4 | _batch_testing_api() | "Testing & API" | test_strategy, api_surface_coherence, mid_level_elegance |
| 5 | _batch_authorization() | "Authorization" | authorization_consistency, mid_level_elegance |
| 6 | _batch_ai_debt_migrations() | "AI Debt & Migrations" | ai_generated_debt, incomplete_migration, low_level_elegance |
| 7 | _batch_package_organization() | "Package Organization" | package_organization, high_level_elegance |
| 8 | _batch_state_design() | "State & Design Integrity" | initialization_coupling, design_coherence |
| 9 | _batch_governance_contracts() | "Governance & Contracts" | cross_module_architecture, high_level_elegance, test_strategy, package_organization |
3. Batch Data Structure
Each batch is a dictionary with this schema (lines 148-154 show example):
python
{
"name": str, # Human-readable batch name
"dimensions": list[str], # Which dimensions this batch evaluates
"files_to_read": list[str], # Seed files to start review from
"why": str, # Rationale explaining why these files + dimensions
# Optional fields (added later):
"concern_signals": list[dict], # Mechanical detector concerns (from batch_concerns())
"historical_issue_focus": dict, # Previous issues scoped to batch dimensions
}
4. How Dimensions Are Assigned to Batches
Static Assignment:
- Dimensions are hardcoded in each
_batch_*() function (e.g., lines 150, 195, 273-278, 291, 317, 341-345, 392, 424, 441-445)
- No configuration controls which dimensions per batch
Multi-Dimensional Batches:
- Batches 2, 3, 4, 5, 6, and 9 have 3-4 dimensions each
- Batch 1, 7: 2 dimensions
- Batch 8: 2 dimensions
- Total coverage: 17 unique dimensions across 9 batches (with overlap/multi-mention)
5. Configuration for Dimensions Per Batch
Max Files Per Batch Configuration:
- Parameter
max_files_per_batch (optional, int or None) passed to build_investigation_batches()
- Passed through to each
_batch_*() function's max_files parameter
- Controls file count limit per batch, not dimension count
- When None: unlimited (lines 496, 502-514)
No Existing Configuration for Dimensions Per Batch:
- The number of dimensions per batch is hardcoded and not configurable
- Cannot adjust how many dimensions are assigned to each batch through configuration
6. Dimension Filtering Function
Location: filter_batches_to_dimensions() (lines 519-564)
- Purpose: Filters batches to only include user-selected dimensions
- Input: Full batch list + requested dimensions list
- Process:
- For each batch, keeps only dimensions in the selection set (line 537)
- Tracks which dimensions are "covered" by batches
- If selected dimensions aren't covered, creates a "Cross-cutting Sweep" fallback batch (lines 543-563)
- Fallback uses representative files from existing batches (line 552)
Not Used for Building: This is for filtering/post-processing, not for initial batch construction.
7. Batch Assignment Pipeline
The full pipeline in prepare_holistic_review_payload() (lines 328-432 in prepare_holistic_flow.py):
- Build base batches (line 369):
build_investigation_batches() → 9 batches with fixed dimensions
- Append concern batch (line 376): Optional mechanical concern signals batch
- Filter to active dimensions (line 384):
filter_batches_to_dimensions() removes inactive dimensions
- Append full sweep (line 393): Optional fallback batch covering all files
- Filter to file scope (line 400): Remove out-of-scope files from batches
- Attach issue history (line 427): Add historical context per batch (filtered by batch dimensions)
8. Existing Batch Concerns (Optional 10th Batch)
Function: batch_concerns() (lines 567-651 in prepare_batches.py)
- Generates a batch from mechanical detector signals
- Default dimensions:
design_coherence, initialization_coupling
- Scoping: If active dimensions don't overlap with defaults, maps to all active dimensions (lines 586-591)
- Max files: Uses
max_files_per_batch parameter (line 265)
9. Issue Budget Per Batch
Location: feedback_contract.py and prompt_sections.py
Function: max_batch_issues_for_dimension_count() (lines 16-19 in feedback_contract.py)
- Calculates max issues allowed per batch based on dimension count
- Formula:
max(DEFAULT_MAX_BATCH_ISSUES, dimension_count)
DEFAULT_MAX_BATCH_ISSUES = 10 (line 12)
- Example: A batch with 3 dimensions allows 10 issues (max of 10 and 3)
Usage in Prompts:
- In
build_batch_context() (lines 39-47 in prompt_sections.py), the issues cap is calculated from dimension count
- This controls how many issues the reviewer should report for each batch
10. Batch Usage in Review Execution
Files That Consume Batches:
/Users/user_c042661f/Documents/desloppify/desloppify/app/commands/review/batch/execution.py - runs batches in parallel
/Users/user_c042661f/Documents/desloppify/desloppify/app/commands/review/batch/scope.py - validates and scopes batches
/Users/user_c042661f/Documents/desloppify/desloppify/app/commands/review/prompt_sections.py - builds prompt context from batch
Key Field Access:
batch["dimensions"] - retrieved for dimension-scoped review filtering
batch["files_to_read"] - seed files for reviewer to start from
batch["why"] - rationale shown to reviewer
batch["concern_signals"] - mechanical detector hypotheses
batch["historical_issue_focus"] - previous issues matching batch dimensions
11. Key Files Reference
| File | Purpose |
|---|
prepare_batches.py | Batch builders, dimension filtering |
prepare_holistic_flow.py | Orchestration pipeline |
prepare.py | Public API (prepare_holistic_review()) |
prompt_sections.py | Batch prompt context building |
feedback_contract.py | Issue budget calculation |
_prepare/helpers.py | Full-sweep batch appending |
_prepare/issue_history.py | Per-batch historical issue focus |
batch/scope.py | Batch validation and scoping |
batch/execution.py | Parallel execution framework |
Summary of Key Findings
- Batch-Dimension Mapping: 9 pre-built batches with hardcoded dimensions — no configuration exists to control which dimensions go to which batch
- Files Per Batch: Configurable via
max_files_per_batch parameter, but dimensions are fixed
- Dimension Count Per Batch: Ranges from 2-4 dimensions per batch with significant overlap
- No Existing Configuration: To change which dimensions are evaluated in which batch, you'd need to modify the hardcoded
_batch_*() functions themselves
- Issue Budget: Calculated from dimension count (max of 10 or dimension count per batch), not configurable separately