File size: 2,506 Bytes
b89d2c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
HARMONIC STACK CLI
Ghost in the Machine Labs

Simple command-line interface to the Harmonic Stack.
Auto-detects hardware and configures appropriately.

Usage:
  python3 run_stack.py                    # Interactive mode
  python3 run_stack.py "your question"    # Single query
  python3 run_stack.py --profile gaming   # Force profile
  python3 run_stack.py --status           # Show status only
"""

import asyncio
import sys
import json

from harmonic_stack import create_stack, HarmonicStack
from hardware_profiles import list_profiles


async def interactive_mode(stack: HarmonicStack):
    """Run interactive REPL."""
    print("\nHarmonic Stack Interactive Mode")
    print("Type 'quit' to exit, 'status' for stack status")
    print("-" * 40)
    
    while True:
        try:
            query = input("\n> ").strip()
        except (EOFError, KeyboardInterrupt):
            print("\nGoodbye.")
            break
        
        if not query:
            continue
        
        if query.lower() == "quit":
            print("Goodbye.")
            break
        
        if query.lower() == "status":
            print(json.dumps(stack.status(), indent=2))
            continue
        
        # Process query
        result = await stack.process(query)
        print(f"\n[{result['route']}] ({result['elapsed_ms']}ms)")
        print(result['response'])


async def single_query(stack: HarmonicStack, query: str):
    """Process single query and exit."""
    result = await stack.process(query)
    print(result['response'])


async def main():
    # Parse args
    args = sys.argv[1:]
    profile = None
    query = None
    status_only = False
    
    i = 0
    while i < len(args):
        if args[i] == "--profile" and i + 1 < len(args):
            profile = args[i + 1]
            i += 2
        elif args[i] == "--status":
            status_only = True
            i += 1
        elif args[i] == "--list":
            print("\nAvailable profiles:")
            list_profiles()
            return
        elif args[i] == "--help":
            print(__doc__)
            return
        else:
            query = args[i]
            i += 1
    
    # Create stack
    stack = await create_stack(profile)
    
    if status_only:
        print(json.dumps(stack.status(), indent=2))
        return
    
    if query:
        await single_query(stack, query)
    else:
        await interactive_mode(stack)


if __name__ == "__main__":
    asyncio.run(main())