| """ |
| Litehat Universal Engine โ Main Entry Point |
| Summon the Wizard. Manifest your dream. |
| |
| Usage: |
| python -m litehat summon --dream "build me a social network for gardeners" |
| python -m litehat manifest --dream "create a real-time multiplayer game" |
| python -m litehat heal --app my-app |
| python -m litehat deploy --app my-app --env production |
| """ |
|
|
| import sys |
| import asyncio |
| import argparse |
|
|
| from .wizard import WizardGrimoire |
| from .mcp_terminal import MCPTerminal |
| from .kuberns_bridge import KubernsBridge, DeploymentConfig |
| from .self_healing import SelfHealingEngine, ContinuousMonitor |
|
|
|
|
| BANNER = """ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ โ |
| โ ๐งโโ๏ธ LITEHAT โ The Sovereign Universal Maker โ |
| โ โ |
| โ "I don't just write code. I launch reality." โ |
| โ โ |
| โ โก Holographic Brain | ๐ฎ Wizard Interface โ |
| โ ๐ฅ๏ธ MCP Terminal | โ๏ธ Kuberns Deployer โ |
| โ ๐ Self-Healing | ๐ Eternal Chronicle โ |
| โ โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| """ |
|
|
|
|
| def create_parser() -> argparse.ArgumentParser: |
| parser = argparse.ArgumentParser( |
| description="๐งโโ๏ธ Litehat โ The Sovereign Universal Maker", |
| formatter_class=argparse.RawDescriptionHelpFormatter, |
| epilog=""" |
| Examples: |
| python -m litehat summon --dream "build me a todo app with AI features" |
| python -m litehat deploy --app my-app --domain myapp.litehat.app |
| python -m litehat heal --app my-app |
| python -m litehat monitor --apps my-app,other-app |
| """, |
| ) |
|
|
| subparsers = parser.add_subparsers(dest="command", help="Commands") |
|
|
| |
| summon_parser = subparsers.add_parser("summon", help="Summon the Wizard with a dream") |
| summon_parser.add_argument("--dream", "-d", type=str, required=True, |
| help="Your dream โ what to build") |
| summon_parser.add_argument("--project", "-p", type=str, default=".", |
| help="Project directory") |
| summon_parser.add_argument("--stack", "-s", type=str, default="auto", |
| help="Tech stack (auto-detected if not specified)") |
|
|
| |
| manifest_parser = subparsers.add_parser("manifest", help="Manifest a dream end-to-end") |
| manifest_parser.add_argument("--dream", "-d", type=str, required=True, |
| help="Your dream") |
| manifest_parser.add_argument("--deploy", action="store_true", default=True, |
| help="Deploy after building (default: true)") |
| manifest_parser.add_argument("--domain", type=str, default=None, |
| help="Custom domain for deployment") |
|
|
| |
| deploy_parser = subparsers.add_parser("deploy", help="Deploy an application") |
| deploy_parser.add_argument("--app", "-a", type=str, required=True, |
| help="Application name") |
| deploy_parser.add_argument("--domain", type=str, default=None, |
| help="Custom domain") |
| deploy_parser.add_argument("--port", type=int, default=3000, |
| help="Application port") |
| deploy_parser.add_argument("--env", type=str, default="production", |
| help="Environment (production/staging)") |
|
|
| |
| heal_parser = subparsers.add_parser("heal", help="Self-heal an application") |
| heal_parser.add_argument("--app", "-a", type=str, required=True, |
| help="Application name") |
|
|
| |
| monitor_parser = subparsers.add_parser("monitor", help="Continuous monitoring") |
| monitor_parser.add_argument("--apps", type=str, required=True, |
| help="Comma-separated app names to monitor") |
|
|
| |
| terminal_parser = subparsers.add_parser("terminal", help="Open MCP terminal") |
| terminal_parser.add_argument("--command", "-c", type=str, default=None, |
| help="Execute a command directly") |
|
|
| |
| init_parser = subparsers.add_parser("init", help="Initialize a Litehat project") |
| init_parser.add_argument("--name", "-n", type=str, required=True, |
| help="Project name") |
|
|
| return parser |
|
|
|
|
| async def handle_summon(args): |
| """Handle the summon command.""" |
| print(BANNER) |
| wizard = WizardGrimoire() |
| report = await wizard.manifest_dream(args.dream) |
| return report |
|
|
|
|
| async def handle_manifest(args): |
| """Handle the manifest command โ full build + deploy pipeline.""" |
| print(BANNER) |
| wizard = WizardGrimoire() |
|
|
| if args.domain: |
| wizard.domain = args.domain |
|
|
| report = await wizard.manifest_dream(args.dream) |
| return report |
|
|
|
|
| def handle_deploy(args): |
| """Handle the deploy command.""" |
| bridge = KubernsBridge() |
|
|
| config = DeploymentConfig( |
| app_name=args.app, |
| image=f"{args.app}:latest", |
| port=args.port, |
| domain=args.domain, |
| ) |
|
|
| status = bridge.deploy(config) |
|
|
| if status.deployed: |
| print(f"\nโ
{args.app} is live at: {status.url}") |
| else: |
| print(f"\nโ Deployment failed: {status.last_error}") |
| |
| print("๐ Initiating self-healing...") |
| healer = SelfHealingEngine() |
| event = healer.detect_failure(args.app, status.last_error or "", 503) |
| if event: |
| healer.heal(event) |
|
|
| return status |
|
|
|
|
| def handle_heal(args): |
| """Handle the heal command.""" |
| healer = SelfHealingEngine() |
| health_report = healer.get_health_report() |
|
|
| print(f"๐ Self-Healing Report for {args.app}") |
| print(f" Total failures: {health_report['total_failures']}") |
| print(f" Healed: {health_report['healed']}") |
| print(f" Heal rate: {health_report['heal_rate']:.0%}") |
|
|
| return health_report |
|
|
|
|
| async def handle_monitor(args): |
| """Handle the monitor command.""" |
| app_names = [a.strip() for a in args.apps.split(",")] |
|
|
| healer = SelfHealingEngine() |
| monitor = ContinuousMonitor(healer) |
|
|
| for app in app_names: |
| monitor.register_app(app, f"https://{app}.litehat.app/health") |
| print(f"๐๏ธ Monitoring {app}...") |
|
|
| print("๐งโโ๏ธ The Wizard watches over your apps...") |
| await monitor.monitor_loop() |
|
|
|
|
| def handle_terminal(args): |
| """Handle the terminal command.""" |
| terminal = MCPTerminal() |
|
|
| if args.command: |
| result = terminal.execute(args.command) |
| print(f"$ {args.command}") |
| if result.stdout: |
| print(result.stdout) |
| if result.stderr: |
| print(f"ERROR: {result.stderr}") |
| print(f"Exit: {result.exit_code} | Time: {result.elapsed_ms:.0f}ms") |
| else: |
| print("MCP Terminal ready. Use --command to execute.") |
| print(f"Workspace: {terminal.workspace_root}") |
|
|
|
|
| def handle_init(args): |
| """Handle the init command.""" |
| terminal = MCPTerminal() |
|
|
| print(f"๐ฎ Initializing Litehat project: {args.name}") |
|
|
| |
| terminal.write_file(f"{args.name}/README.md", f"# {args.name}\n\nBuilt with Litehat ๐งโโ๏ธ\n") |
| terminal.write_file(f"{args.name}/.litehat/config.json", |
| '{"version": "1.0", "created_by": "Litehat Universal Engine"}') |
| terminal.write_file(f"{args.name}/.github/workflows/deploy.yml", |
| f"# Auto-generated by Litehat\n# CI/CD for {args.name}\n") |
|
|
| print(f"โ
Project {args.name} initialized!") |
| print(f" Run: cd {args.name} && python -m litehat summon --dream 'your dream'") |
|
|
|
|
| async def main(): |
| """Main entry point.""" |
| parser = create_parser() |
| args = parser.parse_args() |
|
|
| if not args.command: |
| parser.print_help() |
| print("\n๐งโโ๏ธ The Wizard awaits your command...") |
| return 1 |
|
|
| handlers = { |
| "summon": handle_summon, |
| "manifest": handle_manifest, |
| "deploy": handle_deploy, |
| "heal": handle_heal, |
| "monitor": handle_monitor, |
| "terminal": handle_terminal, |
| "init": handle_init, |
| } |
|
|
| handler = handlers.get(args.command) |
| if handler: |
| if asyncio.iscoroutinefunction(handler): |
| await handler(args) |
| else: |
| handler(args) |
|
|
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(asyncio.run(main())) |
|
|