|
|
|
|
|
""" |
|
|
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 |
|
|
|
|
|
|
|
|
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(): |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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()) |
|
|
|