File size: 4,430 Bytes
77a06d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
"""
CLI Runner for DReamMachine
Quick command-line interface for running dream rounds
"""

import os
import argparse
import logging
from orchestrator import DreamOrchestrator

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s'
)


def main():
    parser = argparse.ArgumentParser(
        description='DReamMachine - LLM Brainstorm System CLI',
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Examples:
  # Run a single dream round
  python run_cli.py --single

  # Run with specific life stage
  python run_cli.py --single --stage mid_26_50

  # Run batch mode with 5 rounds
  python run_cli.py --batch 5

  # Run batch with custom interval
  python run_cli.py --batch 10 --interval 60

  # Run scheduled mode (until max runtime)
  python run_cli.py --scheduled
        """
    )

    parser.add_argument(
        '--single',
        action='store_true',
        help='Run a single dream round'
    )

    parser.add_argument(
        '--batch',
        type=int,
        metavar='N',
        help='Run N dream rounds in batch mode'
    )

    parser.add_argument(
        '--scheduled',
        action='store_true',
        help='Run in scheduled mode (continuous until max runtime)'
    )

    parser.add_argument(
        '--stage',
        choices=['init_1_25', 'mid_26_50', 'late_51_75', 'final_76_100'],
        default='init_1_25',
        help='Life stage to run (default: init_1_25)'
    )

    parser.add_argument(
        '--interval',
        type=int,
        default=10,
        metavar='SECONDS',
        help='Seconds to sleep between batch rounds (default: 10)'
    )

    parser.add_argument(
        '--config',
        default='config.yaml',
        help='Path to configuration file (default: config.yaml)'
    )

    parser.add_argument(
        '--token',
        help='HuggingFace API token (overrides HF_TOKEN env var)'
    )

    args = parser.parse_args()

    # Get HuggingFace token
    hf_token = args.token or os.getenv('HF_TOKEN')
    if not hf_token:
        print("Error: HuggingFace token required. Set HF_TOKEN environment variable or use --token")
        return 1

    # Initialize orchestrator
    print(f"Initializing DReamMachine with config: {args.config}")
    orchestrator = DreamOrchestrator(config_path=args.config, hf_token=hf_token)

    # Run based on mode
    if args.single:
        print(f"\nRunning single dream round (stage: {args.stage})")
        result = orchestrator.run_dream_round(stage=args.stage)

        print("\n" + "=" * 80)
        print("RESULTS")
        print("=" * 80)
        print(f"Session ID: {result.get('session_id')}")
        print(f"Originality: {result['curator_scorecard'].get('originality')}/10")
        print(f"Feasibility: {result['curator_scorecard'].get('feasibility')}/10")
        print(f"Global Impact: {result['curator_scorecard'].get('global_impact')}/10")
        print(f"Reforge Flag: {result['curator_scorecard'].get('reforge_flag')}")
        print(f"\nNext Action: {result['next_action'].get('type')}")
        print(f"Reason: {result['next_action'].get('reason')}")
        print("=" * 80)

    elif args.batch:
        print(f"\nRunning batch mode: {args.batch} rounds (interval: {args.interval}s)")
        results = orchestrator.run_batch_mode(
            num_rounds=args.batch,
            sleep_between=args.interval
        )

        print("\n" + "=" * 80)
        print("BATCH RESULTS")
        print("=" * 80)
        print(f"Total rounds: {len(results)}")
        reforge_count = sum(1 for r in results if r.get('curator_scorecard', {}).get('reforge_flag'))
        print(f"Reforge-eligible: {reforge_count}")

        if results:
            avg_orig = sum(r.get('curator_scorecard', {}).get('originality', 0) for r in results) / len(results)
            avg_feas = sum(r.get('curator_scorecard', {}).get('feasibility', 0) for r in results) / len(results)
            print(f"\nAverage Originality: {avg_orig:.1f}/10")
            print(f"Average Feasibility: {avg_feas:.1f}/10")

        print("=" * 80)

    elif args.scheduled:
        print("\nRunning in scheduled mode (continuous until max runtime)")
        orchestrator.run_scheduled_mode()

    else:
        parser.print_help()
        return 1

    print("\n✓ Complete!")
    return 0


if __name__ == '__main__':
    exit(main())