1"""ll-generate-schemas: Generate JSON Schema files for all LLEvent types."""

2

3 from __future__ import annotations

4

5 import argparse

6 import sys

7 from pathlib import Path

8

9 from little_loops.cli.output import configure_output, use_color_enabled

10 from little_loops.logger import Logger

11 from little_loops.session_store import DEFAULT_DB_PATH, cli_event_context

12

13

14 def main_generate_schemas() -> int:

15 """Entry point for ll-generate-schemas command.

16

17 Generate JSON Schema (draft-07) files for all 22 LLEvent types and write them

18 to docs/reference/schemas/ (or a custom output directory).

19

20 Returns:

21 Exit code (0 = success, 1 = error)

22 """

23 with cli_event_context(DEFAULT_DB_PATH, "ll-generate-schemas", sys.argv[1:]):

24 from little_loops.generate_schemas import generate_schemas

25

26 parser = argparse.ArgumentParser(

27 prog="ll-generate-schemas",

28 description="Generate JSON Schema files for all LLEvent types",

29 formatter_class=argparse.RawDescriptionHelpFormatter,

30 epilog="""

31 Examples:

32 %(prog)s # Write to docs/reference/schemas/

33 %(prog)s --output path/to/schemas/ # Custom output directory

34

35 Exit codes:

36 0 - Schemas generated successfully

37 1 - Error occurred

38""",

39 )

40

41 parser.add_argument(

42 "-o",

43 "--output",

44 type=Path,

45 default=None,

46 help="Output directory (default: docs/reference/schemas/ relative to cwd)",

47 )

48

49 args = parser.parse_args()

50

51 configure_output()

52 logger = Logger(use_color=use_color_enabled())

53

54 output_dir = args.output or Path.cwd() / "docs" / "reference" / "schemas"

55

56 try:

57 paths = generate_schemas(output_dir)

58 logger.success(f"Generated {len(paths)} schema(s) in {output_dir}/")

59 return 0

60 except Exception as exc:

61 logger.error(str(exc))

62 return 1