1"""ll-auto: Process all backlog issues sequentially in priority order."""

2

3 from __future__ import annotations

4

5 import argparse

6 import os

7 import sys

8 from pathlib import Path

9

10 from little_loops.cli.output import configure_output

11 from little_loops.cli_args import (

12 add_common_auto_args,

13 add_skip_learning_gate_arg,

14 parse_issue_ids,

15 parse_issue_ids_ordered,

16 parse_issue_types,

17 parse_labels,

18 parse_priorities,

19)

20 from little_loops.config import BRConfig

21 from little_loops.issue_manager import AutoManager

22 from little_loops.session_store import DEFAULT_DB_PATH, cli_event_context

23

24

25 def main_auto() -> int:

26 """Entry point for ll-auto command.

27

28 Process all backlog issues sequentially in priority order.

29

30 Returns:

31 Exit code (0 = success)

32 """

33 with cli_event_context(DEFAULT_DB_PATH, "ll-auto", sys.argv[1:]):

34 parser = argparse.ArgumentParser(

35 description="Process all backlog issues sequentially in priority order",

36 formatter_class=argparse.RawDescriptionHelpFormatter,

37 epilog="""

38 Examples:

39 %(prog)s # Process all issues in priority order

40 %(prog)s --max-issues 5 # Process at most 5 issues

41 %(prog)s --resume # Resume from previous state

42 %(prog)s --dry-run # Preview what would be processed

43 %(prog)s --category bugs # Only process bugs

44 %(prog)s --only BUG-001,BUG-002 # Process only specific issues

45 %(prog)s --skip BUG-003 # Skip specific issues

46 %(prog)s --type BUG # Process only bugs

47 %(prog)s --type BUG,ENH # Process bugs and enhancements

48 %(prog)s --priority P1,P2 # Only process P1 and P2 issues

49""",

50 )

51

52 # Add common arguments from shared module

53 add_common_auto_args(parser)

54 add_skip_learning_gate_arg(parser)

55

56 # Add tool-specific arguments

57 parser.add_argument(

58 "--category",

59 "-c",

60 type=str,

61 default=None,

62 help="Filter to specific category (bugs, features, enhancements)",

63 )

64 parser.add_argument(

65 "--verbose",

66 "-v",

67 action="store_true",

68 help="Enable verbose output (default when --quiet is not set)",

69 )

70

71 args = parser.parse_args()

72

73 project_root = args.config or Path.cwd()

74 config = BRConfig(project_root)

75 configure_output(config.cli)

76

77 if args.idle_timeout is not None:

78 config.automation.idle_timeout_seconds = args.idle_timeout

79

80 if args.handoff_threshold is not None:

81 if not (1 <= args.handoff_threshold <= 100):

82 parser.error("--handoff-threshold must be between 1 and 100")

83 os.environ["LL_HANDOFF_THRESHOLD"] = str(args.handoff_threshold)

84

85 if args.context_limit is not None:

86 if args.context_limit < 50000:

87 parser.error("--context-limit must be at least 50000")

88 os.environ["LL_CONTEXT_LIMIT"] = str(args.context_limit)

89

90 # Parse issue ID filters

91 only_ids = parse_issue_ids_ordered(args.only)

92 skip_ids = parse_issue_ids(args.skip)

93 type_prefixes = parse_issue_types(args.type)

94 priority_filter = parse_priorities(args.priority)

95 label_filter = parse_labels(args.label)

96

97 manager = AutoManager(

98 config=config,

99 dry_run=args.dry_run,

100 max_issues=args.max_issues,

101 resume=args.resume,

102 category=args.category,

103 only_ids=only_ids,

104 skip_ids=skip_ids,

105 type_prefixes=type_prefixes,

106 priority_filter=priority_filter,

107 label_filter=label_filter,

108 verbose=args.verbose or not args.quiet,

109 preview_full=args.verbose,

110 skip_learning_gate=args.skip_learning_gate,

111 )

112

113 return manager.run()