dryymatt commited on
Commit
3762b57
ยท
verified ยท
1 Parent(s): 20d4393

Upload litehat/__main__.py

Browse files
Files changed (1) hide show
  1. litehat/__main__.py +244 -0
litehat/__main__.py ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Litehat Universal Engine โ€” Main Entry Point
3
+ Summon the Wizard. Manifest your dream.
4
+
5
+ Usage:
6
+ python -m litehat summon --dream "build me a social network for gardeners"
7
+ python -m litehat manifest --dream "create a real-time multiplayer game"
8
+ python -m litehat heal --app my-app
9
+ python -m litehat deploy --app my-app --env production
10
+ """
11
+
12
+ import sys
13
+ import asyncio
14
+ import argparse
15
+
16
+ from .wizard import WizardGrimoire
17
+ from .mcp_terminal import MCPTerminal
18
+ from .kuberns_bridge import KubernsBridge, DeploymentConfig
19
+ from .self_healing import SelfHealingEngine, ContinuousMonitor
20
+
21
+
22
+ BANNER = """
23
+ โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
24
+ โ•‘ โ•‘
25
+ โ•‘ ๐Ÿง™โ€โ™‚๏ธ LITEHAT โ€” The Sovereign Universal Maker โ•‘
26
+ โ•‘ โ•‘
27
+ โ•‘ "I don't just write code. I launch reality." โ•‘
28
+ โ•‘ โ•‘
29
+ โ•‘ โšก Holographic Brain | ๐Ÿ”ฎ Wizard Interface โ•‘
30
+ โ•‘ ๐Ÿ–ฅ๏ธ MCP Terminal | โ˜๏ธ Kuberns Deployer โ•‘
31
+ โ•‘ ๐Ÿ’Š Self-Healing | ๐Ÿ“œ Eternal Chronicle โ•‘
32
+ โ•‘ โ•‘
33
+ โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
34
+ """
35
+
36
+
37
+ def create_parser() -> argparse.ArgumentParser:
38
+ parser = argparse.ArgumentParser(
39
+ description="๐Ÿง™โ€โ™‚๏ธ Litehat โ€” The Sovereign Universal Maker",
40
+ formatter_class=argparse.RawDescriptionHelpFormatter,
41
+ epilog="""
42
+ Examples:
43
+ python -m litehat summon --dream "build me a todo app with AI features"
44
+ python -m litehat deploy --app my-app --domain myapp.litehat.app
45
+ python -m litehat heal --app my-app
46
+ python -m litehat monitor --apps my-app,other-app
47
+ """,
48
+ )
49
+
50
+ subparsers = parser.add_subparsers(dest="command", help="Commands")
51
+
52
+ # Summon: Start a new project
53
+ summon_parser = subparsers.add_parser("summon", help="Summon the Wizard with a dream")
54
+ summon_parser.add_argument("--dream", "-d", type=str, required=True,
55
+ help="Your dream โ€” what to build")
56
+ summon_parser.add_argument("--project", "-p", type=str, default=".",
57
+ help="Project directory")
58
+ summon_parser.add_argument("--stack", "-s", type=str, default="auto",
59
+ help="Tech stack (auto-detected if not specified)")
60
+
61
+ # Manifest: Full build + deploy pipeline
62
+ manifest_parser = subparsers.add_parser("manifest", help="Manifest a dream end-to-end")
63
+ manifest_parser.add_argument("--dream", "-d", type=str, required=True,
64
+ help="Your dream")
65
+ manifest_parser.add_argument("--deploy", action="store_true", default=True,
66
+ help="Deploy after building (default: true)")
67
+ manifest_parser.add_argument("--domain", type=str, default=None,
68
+ help="Custom domain for deployment")
69
+
70
+ # Deploy: Deploy an existing project
71
+ deploy_parser = subparsers.add_parser("deploy", help="Deploy an application")
72
+ deploy_parser.add_argument("--app", "-a", type=str, required=True,
73
+ help="Application name")
74
+ deploy_parser.add_argument("--domain", type=str, default=None,
75
+ help="Custom domain")
76
+ deploy_parser.add_argument("--port", type=int, default=3000,
77
+ help="Application port")
78
+ deploy_parser.add_argument("--env", type=str, default="production",
79
+ help="Environment (production/staging)")
80
+
81
+ # Heal: Self-healing for a deployed app
82
+ heal_parser = subparsers.add_parser("heal", help="Self-heal an application")
83
+ heal_parser.add_argument("--app", "-a", type=str, required=True,
84
+ help="Application name")
85
+
86
+ # Monitor: Continuous monitoring
87
+ monitor_parser = subparsers.add_parser("monitor", help="Continuous monitoring")
88
+ monitor_parser.add_argument("--apps", type=str, required=True,
89
+ help="Comma-separated app names to monitor")
90
+
91
+ # Terminal: Direct MCP terminal access
92
+ terminal_parser = subparsers.add_parser("terminal", help="Open MCP terminal")
93
+ terminal_parser.add_argument("--command", "-c", type=str, default=None,
94
+ help="Execute a command directly")
95
+
96
+ # Init: Initialize a new Litehat project
97
+ init_parser = subparsers.add_parser("init", help="Initialize a Litehat project")
98
+ init_parser.add_argument("--name", "-n", type=str, required=True,
99
+ help="Project name")
100
+
101
+ return parser
102
+
103
+
104
+ async def handle_summon(args):
105
+ """Handle the summon command."""
106
+ print(BANNER)
107
+ wizard = WizardGrimoire()
108
+ report = await wizard.manifest_dream(args.dream)
109
+ return report
110
+
111
+
112
+ async def handle_manifest(args):
113
+ """Handle the manifest command โ€” full build + deploy pipeline."""
114
+ print(BANNER)
115
+ wizard = WizardGrimoire()
116
+
117
+ if args.domain:
118
+ wizard.domain = args.domain
119
+
120
+ report = await wizard.manifest_dream(args.dream)
121
+ return report
122
+
123
+
124
+ def handle_deploy(args):
125
+ """Handle the deploy command."""
126
+ bridge = KubernsBridge()
127
+
128
+ config = DeploymentConfig(
129
+ app_name=args.app,
130
+ image=f"{args.app}:latest",
131
+ port=args.port,
132
+ domain=args.domain,
133
+ )
134
+
135
+ status = bridge.deploy(config)
136
+
137
+ if status.deployed:
138
+ print(f"\nโœ… {args.app} is live at: {status.url}")
139
+ else:
140
+ print(f"\nโŒ Deployment failed: {status.last_error}")
141
+ # Auto-heal
142
+ print("๐Ÿ’Š Initiating self-healing...")
143
+ healer = SelfHealingEngine()
144
+ event = healer.detect_failure(args.app, status.last_error or "", 503)
145
+ if event:
146
+ healer.heal(event)
147
+
148
+ return status
149
+
150
+
151
+ def handle_heal(args):
152
+ """Handle the heal command."""
153
+ healer = SelfHealingEngine()
154
+ health_report = healer.get_health_report()
155
+
156
+ print(f"๐Ÿ’Š Self-Healing Report for {args.app}")
157
+ print(f" Total failures: {health_report['total_failures']}")
158
+ print(f" Healed: {health_report['healed']}")
159
+ print(f" Heal rate: {health_report['heal_rate']:.0%}")
160
+
161
+ return health_report
162
+
163
+
164
+ async def handle_monitor(args):
165
+ """Handle the monitor command."""
166
+ app_names = [a.strip() for a in args.apps.split(",")]
167
+
168
+ healer = SelfHealingEngine()
169
+ monitor = ContinuousMonitor(healer)
170
+
171
+ for app in app_names:
172
+ monitor.register_app(app, f"https://{app}.litehat.app/health")
173
+ print(f"๐Ÿ‘๏ธ Monitoring {app}...")
174
+
175
+ print("๐Ÿง™โ€โ™‚๏ธ The Wizard watches over your apps...")
176
+ await monitor.monitor_loop()
177
+
178
+
179
+ def handle_terminal(args):
180
+ """Handle the terminal command."""
181
+ terminal = MCPTerminal()
182
+
183
+ if args.command:
184
+ result = terminal.execute(args.command)
185
+ print(f"$ {args.command}")
186
+ if result.stdout:
187
+ print(result.stdout)
188
+ if result.stderr:
189
+ print(f"ERROR: {result.stderr}")
190
+ print(f"Exit: {result.exit_code} | Time: {result.elapsed_ms:.0f}ms")
191
+ else:
192
+ print("MCP Terminal ready. Use --command to execute.")
193
+ print(f"Workspace: {terminal.workspace_root}")
194
+
195
+
196
+ def handle_init(args):
197
+ """Handle the init command."""
198
+ terminal = MCPTerminal()
199
+
200
+ print(f"๐Ÿ”ฎ Initializing Litehat project: {args.name}")
201
+
202
+ # Create project structure
203
+ terminal.write_file(f"{args.name}/README.md", f"# {args.name}\n\nBuilt with Litehat ๐Ÿง™โ€โ™‚๏ธ\n")
204
+ terminal.write_file(f"{args.name}/.litehat/config.json",
205
+ '{"version": "1.0", "created_by": "Litehat Universal Engine"}')
206
+ terminal.write_file(f"{args.name}/.github/workflows/deploy.yml",
207
+ f"# Auto-generated by Litehat\n# CI/CD for {args.name}\n")
208
+
209
+ print(f"โœ… Project {args.name} initialized!")
210
+ print(f" Run: cd {args.name} && python -m litehat summon --dream 'your dream'")
211
+
212
+
213
+ async def main():
214
+ """Main entry point."""
215
+ parser = create_parser()
216
+ args = parser.parse_args()
217
+
218
+ if not args.command:
219
+ parser.print_help()
220
+ print("\n๐Ÿง™โ€โ™‚๏ธ The Wizard awaits your command...")
221
+ return 1
222
+
223
+ handlers = {
224
+ "summon": handle_summon,
225
+ "manifest": handle_manifest,
226
+ "deploy": handle_deploy,
227
+ "heal": handle_heal,
228
+ "monitor": handle_monitor,
229
+ "terminal": handle_terminal,
230
+ "init": handle_init,
231
+ }
232
+
233
+ handler = handlers.get(args.command)
234
+ if handler:
235
+ if asyncio.iscoroutinefunction(handler):
236
+ await handler(args)
237
+ else:
238
+ handler(args)
239
+
240
+ return 0
241
+
242
+
243
+ if __name__ == "__main__":
244
+ sys.exit(asyncio.run(main()))