Coverage for little_loops / cli / parallel.py: 0%
57 statements
« prev ^ index » next coverage.py v7.12.0, created at 2026-03-14 23:20 -0500
« prev ^ index » next coverage.py v7.12.0, created at 2026-03-14 23:20 -0500
1"""ll-parallel: Process issues concurrently using isolated git worktrees."""
3from __future__ import annotations
5import argparse
6import subprocess
7from pathlib import Path
9from little_loops.cli.output import configure_output
10from little_loops.cli_args import (
11 add_dry_run_arg,
12 add_idle_timeout_arg,
13 add_max_issues_arg,
14 add_only_arg,
15 add_quiet_arg,
16 add_resume_arg,
17 add_skip_arg,
18 add_timeout_arg,
19 add_type_arg,
20 parse_issue_ids,
21 parse_issue_types,
22)
23from little_loops.config import BRConfig
24from little_loops.logger import Logger
27def main_parallel() -> int:
28 """Entry point for ll-parallel command.
30 Process issues concurrently using isolated git worktrees.
32 Returns:
33 Exit code (0 = success)
34 """
35 parser = argparse.ArgumentParser(
36 description="Process issues concurrently using isolated git worktrees",
37 formatter_class=argparse.RawDescriptionHelpFormatter,
38 epilog="""
39Examples:
40 %(prog)s # Process with default workers
41 %(prog)s --workers 3 # Use 3 parallel workers
42 %(prog)s --dry-run # Preview what would be processed
43 %(prog)s --priority P1,P2 # Only process P1 and P2 issues
44 %(prog)s --cleanup # Clean up worktrees and exit
45 %(prog)s --stream-output # Stream Claude CLI output in real-time
46 %(prog)s --only BUG-001,BUG-002 # Process only specific issues
47 %(prog)s --skip BUG-003 # Skip specific issues
48 %(prog)s --type BUG # Process only bugs
49 %(prog)s --type BUG,ENH # Process bugs and enhancements
50""",
51 )
53 # Parallel-specific arguments (--workers, not --max-workers)
54 parser.add_argument(
55 "--workers",
56 "-w",
57 type=int,
58 default=None,
59 help="Number of parallel workers (default: from config or 2)",
60 )
61 parser.add_argument(
62 "--priority",
63 "-p",
64 type=str,
65 default=None,
66 help="Comma-separated priorities to process (default: all)",
67 )
68 parser.add_argument(
69 "--worktree-base",
70 type=Path,
71 default=None,
72 help="Base directory for git worktrees",
73 )
74 parser.add_argument(
75 "--cleanup",
76 "-c",
77 action="store_true",
78 help="Clean up all worktrees and exit",
79 )
80 parser.add_argument(
81 "--merge-pending",
82 action="store_true",
83 help="Attempt to merge pending work from previous interrupted runs",
84 )
85 parser.add_argument(
86 "--clean-start",
87 action="store_true",
88 help="Remove all worktrees and start fresh (skip pending work check)",
89 )
90 parser.add_argument(
91 "--ignore-pending",
92 action="store_true",
93 help="Report pending work but continue without merging",
94 )
95 parser.add_argument(
96 "--stream-output",
97 action="store_true",
98 help="Stream Claude CLI subprocess output to console",
99 )
100 parser.add_argument(
101 "--show-model",
102 action="store_true",
103 help="Make API call to verify and display model on worktree setup",
104 )
105 parser.add_argument(
106 "--overlap-detection",
107 action="store_true",
108 help="Enable pre-flight overlap detection to reduce merge conflicts (ENH-143)",
109 )
110 parser.add_argument(
111 "--warn-only",
112 action="store_true",
113 help="With --overlap-detection, warn about overlaps instead of serializing",
114 )
116 # Add common arguments from shared module
117 add_dry_run_arg(parser)
118 add_resume_arg(parser)
119 add_timeout_arg(parser)
120 add_idle_timeout_arg(parser)
121 add_quiet_arg(parser)
122 add_only_arg(parser)
123 add_skip_arg(parser)
124 add_type_arg(parser)
126 # Add max-issues and config individually (different help text needed)
127 add_max_issues_arg(parser)
128 parser.add_argument(
129 "--config",
130 type=Path,
131 default=None,
132 help="Path to project root",
133 )
135 args = parser.parse_args()
137 project_root = args.config or Path.cwd()
138 config = BRConfig(project_root)
139 configure_output(config.cli)
141 logger = Logger(verbose=not args.quiet)
143 # Handle cleanup mode
144 if args.cleanup:
145 from little_loops.parallel import WorkerPool
147 parallel_config = config.create_parallel_config()
148 pool = WorkerPool(parallel_config, config, logger, project_root)
149 pool.cleanup_all_worktrees()
150 logger.success("Cleanup complete")
151 return 0
153 # Build priority filter
154 priority_filter = (
155 [p.strip().upper() for p in args.priority.split(",")] if args.priority else None
156 )
158 # Parse issue ID filters
159 only_ids = parse_issue_ids(args.only)
160 skip_ids = parse_issue_ids(args.skip)
161 type_prefixes = parse_issue_types(args.type)
163 # Detect current branch for rebase/merge operations (BUG-439)
164 _branch_result = subprocess.run(
165 ["git", "rev-parse", "--abbrev-ref", "HEAD"],
166 capture_output=True,
167 text=True,
168 cwd=project_root,
169 )
170 _base_branch = _branch_result.stdout.strip() if _branch_result.returncode == 0 else "main"
172 # Create parallel config with CLI overrides
173 parallel_config = config.create_parallel_config(
174 max_workers=args.workers,
175 priority_filter=priority_filter,
176 max_issues=args.max_issues,
177 dry_run=args.dry_run,
178 timeout_seconds=args.timeout,
179 idle_timeout_per_issue=args.idle_timeout,
180 stream_output=args.stream_output if args.stream_output else None,
181 show_model=args.show_model if args.show_model else None,
182 only_ids=only_ids,
183 skip_ids=skip_ids,
184 type_prefixes=type_prefixes,
185 merge_pending=args.merge_pending,
186 clean_start=args.clean_start,
187 ignore_pending=args.ignore_pending,
188 overlap_detection=args.overlap_detection,
189 serialize_overlapping=not args.warn_only,
190 base_branch=_base_branch,
191 )
193 # Delete state file if not resuming
194 if not args.resume:
195 state_file = config.get_parallel_state_file()
196 if state_file.exists():
197 state_file.unlink()
199 # Create and run orchestrator
200 from little_loops.parallel import ParallelOrchestrator
202 orchestrator = ParallelOrchestrator(
203 parallel_config=parallel_config,
204 br_config=config,
205 repo_path=project_root,
206 verbose=not args.quiet,
207 )
209 return orchestrator.run()