dryymatt commited on
Commit
7e7eddc
·
verified ·
1 Parent(s): 70df0c3

Omni-Vibe: updated server.py — Pose swarm + Pinggy tunnel

Browse files
Files changed (1) hide show
  1. server.py +245 -60
server.py CHANGED
@@ -1,109 +1,285 @@
1
  """
2
- ╔══════════════════════════════════════════════════════════
3
- WIZARD-VIBE STUDIO — Tokenless Autonomy Protocol
4
- Ghost Deploy: HF Space Live URL
5
- Reflect-Select: Zero-tolerance perfection
6
- ╚══════════════════════════════════════════════════════════
7
  """
8
- import json, os, uuid, asyncio
 
9
  from pathlib import Path
10
  from aiohttp import web
11
- from core import state as st, sandbox_validate
12
- from ghost_deploy import ghost, CANONICAL_REPO
 
 
 
 
 
 
13
 
14
  PORT = int(os.environ.get("WIZARD_PORT", 8765))
15
  STATIC = Path(__file__).parent / "static"
 
 
 
 
 
16
 
17
- def _sse(ev, d): return f"event: {ev}\ndata: {json.dumps(d)}\n\n"
18
 
19
  async def stream_gen(sid, prompt):
20
- st.sessions[sid]["status"] = "streaming"
 
 
 
 
 
 
 
 
 
21
  st.sandbox[sid] = "building"
22
- yield _sse("phase", {"phase": "orchestrate"})
23
- plan = st.orchestrator.pose(prompt)
24
- yield _sse("plan", plan)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  yield _sse("phase", {"phase": "generate"})
26
- code = ""
27
- for chunk in st.orchestrator.generate(prompt):
28
- code += chunk; st.codes[sid] = code
29
- yield _sse("code", {"chunk": chunk, "partial": code})
30
- await asyncio.sleep(0.03)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  yield _sse("phase", {"phase": "heal"})
 
 
 
 
32
  healed, found, fixed = st.reflect.heal(code)
33
- st.codes[sid] = healed
34
- yield _sse("heal", {"found": found, "fixed": fixed})
35
- # Zero-tolerance: keep healing until perfect
36
- total_heals = fixed
37
  for i in range(15):
38
  result = sandbox_validate(healed)
39
- if result["success"]: break
40
- healed, _, _ = st.reflect.heal(healed, result["errors"])
41
- total_heals += 1; st.codes[sid] = healed
42
- await asyncio.sleep(0.02)
 
 
 
 
 
 
 
 
 
 
 
43
  yield _sse("phase", {"phase": "sandbox"})
44
  result = sandbox_validate(healed)
45
  if result["success"]:
46
- st.sandbox[sid] = "stable"; st.publish_ready[sid] = True
47
- yield _sse("sandbox", {"status": "stable", "errors": 0})
 
48
  else:
49
  st.sandbox[sid] = "error"
50
  yield _sse("sandbox", {"status": "error", "errors": result["errors"]})
51
- st.sessions[sid]["status"] = "complete"
52
- yield _sse("done", {"status": st.sandbox[sid]})
 
 
 
 
 
53
 
54
  async def handle_stream(req):
55
- sid = str(uuid.uuid4())[:8]; d = await req.json(); prompt = d.get("prompt","")
56
- st.sessions[sid] = {"id":sid,"prompt":prompt,"status":"init"}
57
- st.sandbox[sid]="building"; st.publish_ready[sid]=False
58
- resp = web.StreamResponse(status=200, headers={"Content-Type":"text/event-stream","Cache-Control":"no-cache","Connection":"keep-alive","X-Accel-Buffering":"no"})
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  await resp.prepare(req)
60
  try:
61
- async for ev in stream_gen(sid, prompt): await resp.write(ev.encode())
 
62
  await resp.write(b"event: close\ndata: {}\n\n")
63
  except Exception as e:
64
- await resp.write(f"event: error\ndata: {json.dumps({'error':str(e)})}\n\n".encode())
 
 
65
  return resp
66
 
 
67
  async def handle_publish(req):
68
- d = await req.json(); sid = d.get("session_id")
69
- vibe_name = d.get("vibe_name", f"vibe-{sid}")
 
 
70
  if not st.publish_ready.get(sid):
71
- return web.json_response({"success":False,"error":"Sandbox not stable — perfection required"}, status=400)
72
- code = st.codes.get(sid,"")
73
- if not code: return web.json_response({"success":False,"error":"No code"}, status=400)
74
- description = d.get("description", st.sessions.get(sid,{}).get("prompt",""))
75
- result = await ghost.publish(code, vibe_name, description[:200] if description else "")
 
 
 
 
 
 
 
76
  if result.get("success"):
77
  st.sessions[sid]["published"] = True
78
- st.sessions[sid]["deploy_url"] = result.get("url")
 
 
79
  return web.json_response(result)
80
 
 
81
  async def handle_health(req):
82
- return web.json_response({"status":"alive","engine":"Wizard-Vibe Studio — Ghost Deploy","protocol":"tokenless","registry":CANONICAL_REPO,"hf_token":bool(os.environ.get("HF_TOKEN"))})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  async def handle_agent(req):
85
- return web.json_response(ghost.generate_agent_card("wizard-vibe-studio","Tokenless Ghost Deploy — HF Spaces + A2A native.","https://dryymatt-wizard-vibe-studio-v2.hf.space"))
 
 
 
 
 
86
 
87
  async def handle_preview(req):
88
- sid = req.query.get("session_id","")
89
- return web.Response(text=st.codes.get(sid,"<!-- No code -->"), content_type="text/html")
 
 
 
 
90
 
91
  async def handle_status(req):
92
- sid = req.query.get("session_id","")
93
  if sid in st.sessions:
94
  s = st.sessions[sid]
95
- return web.json_response({"status":s["status"],"sandbox":st.sandbox.get(sid),"ready":st.publish_ready.get(sid),"deploy_url":s.get("deploy_url")})
96
- return web.json_response({"sessions":len(st.sessions)})
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  async def handle_vibes(req):
99
  vibes = await ghost.list_vibes()
100
- return web.json_response({"vibes":vibes,"count":len(vibes),"registry":CANONICAL_REPO})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  async def handle_static(req):
103
- path = req.match_info.get("path","index.html"); fp = STATIC/path
104
- if not fp.exists(): return web.Response(text="Not found", status=404)
105
- ct = {".html":"text/html",".css":"text/css",".js":"application/javascript"}
106
- return web.Response(text=fp.read_text(), content_type=ct.get(fp.suffix,"text/plain"))
 
 
 
107
 
108
  def create_app():
109
  app = web.Application()
@@ -113,15 +289,24 @@ def create_app():
113
  app.router.add_get("/api/preview", handle_preview)
114
  app.router.add_get("/api/health", handle_health)
115
  app.router.add_get("/api/vibes", handle_vibes)
 
 
116
  app.router.add_get("/.well-known/agent.json", handle_agent)
117
  app.router.add_get("/", handle_static)
118
  app.router.add_get("/{path:.*}", handle_static)
119
  return app
120
 
 
121
  def main():
122
- print(f"🧙‍♂️ Wizard-Vibe Studio — Ghost Deploy Protocol")
123
- print(f" Registry: {CANONICAL_REPO}")
124
- print(f" Zero-tolerance sandbox perfection")
 
 
 
 
125
  web.run_app(create_app(), host="0.0.0.0", port=PORT)
126
 
127
- if __name__ == "__main__": main()
 
 
 
1
  """
2
+ ╔══════════════════════════════════════════════════════╗
3
+ OMNI-VIBE STUDIO — Specialized Swarm Server
4
+ Pose Architect · Pose Painter · Pose Auditor
5
+ LiteRT · Sub-Second · Shadow-Hosting
6
+ ╚══════════════════════════════════════════════════════╝
7
  """
8
+
9
+ import json, os, uuid, asyncio, time
10
  from pathlib import Path
11
  from aiohttp import web
12
+
13
+ # Import the Omni-Vibe core — backward-compatible API
14
+ from core import (
15
+ state as st, sandbox_validate,
16
+ Orchestrator, OmniVibeEngine, ReflectSelect,
17
+ PoseArchitect, PosePainter, PoseAuditor,
18
+ )
19
+ from ghost_deploy import ghost, CANONICAL_REPO, PinggyTunnel
20
 
21
  PORT = int(os.environ.get("WIZARD_PORT", 8765))
22
  STATIC = Path(__file__).parent / "static"
23
+ WIZARD_HAT_COLOR = "steady-gold" # The Athanor is active
24
+
25
+
26
+ def _sse(ev, d):
27
+ return f"event: {ev}\ndata: {json.dumps(d)}\n\n"
28
 
 
29
 
30
  async def stream_gen(sid, prompt):
31
+ """
32
+ Omni-Vibe streaming pipeline:
33
+ 1. POSE — all three agents analyze in parallel
34
+ 2. GENERATE — Pose Architect + Pose Painter produce code
35
+ 3. AUDIT — Pose Auditor verifies step-by-step
36
+ 4. HEAL — Reflect-Select loop until perfection
37
+ 5. DEPLOY — Ghost Deploy to HF Spaces + Pinggy tunnel
38
+ """
39
+ session = st.sessions[sid]
40
+ session["status"] = "streaming"
41
  st.sandbox[sid] = "building"
42
+
43
+ # Phase 1: Pose
44
+ yield _sse("phase", {"phase": "pose", "hat": WIZARD_HAT_COLOR})
45
+ await asyncio.sleep(0.05)
46
+
47
+ pose_plan = st.engine.pose(prompt)
48
+ yield _sse("pose", {
49
+ "architect": {
50
+ "stack": pose_plan["architect"]["stack"],
51
+ "features": pose_plan["architect"]["features"],
52
+ "files": pose_plan["architect"]["files_needed"],
53
+ },
54
+ "painter": pose_plan["painter"],
55
+ "auditor": pose_plan["auditor"],
56
+ })
57
+
58
+ # Phase 2: Generate
59
  yield _sse("phase", {"phase": "generate"})
60
+ await asyncio.sleep(0.05)
61
+
62
+ t0 = time.time()
63
+ code, schema = st.engine.generate(prompt)
64
+ elapsed = (time.time() - t0) * 1000
65
+
66
+ # Stream in chunks for live UI
67
+ chunk_size = max(1, len(code) // 30)
68
+ for i in range(0, len(code), chunk_size):
69
+ chunk = code[i:i + chunk_size]
70
+ yield _sse("code", {
71
+ "chunk": chunk,
72
+ "partial": code[:i + chunk_size],
73
+ "progress": min(100, int((i + chunk_size) / len(code) * 100)),
74
+ })
75
+ await asyncio.sleep(0.015)
76
+
77
+ st.codes[sid] = code
78
+ st.sessions[sid]["schema"] = schema
79
+ yield _sse("generated", {
80
+ "chars": len(code),
81
+ "elapsed_ms": round(elapsed, 1),
82
+ "schema": {k: v for k, v in schema.items() if k != "files_needed"},
83
+ })
84
+
85
+ # Phase 3: Audit
86
+ yield _sse("phase", {"phase": "audit"})
87
+ await asyncio.sleep(0.05)
88
+
89
+ findings = st.engine.auditor.audit(code, schema)
90
+ yield _sse("audit", {
91
+ "findings": len(findings),
92
+ "errors": sum(1 for f in findings if f.severity == "ERROR"),
93
+ "warnings": sum(1 for f in findings if f.severity == "WARN"),
94
+ "details": [{"line": f.line, "severity": f.severity, "message": f.message}
95
+ for f in findings[:5]],
96
+ })
97
+
98
+ # Phase 4: Heal (Reflect-Select)
99
  yield _sse("phase", {"phase": "heal"})
100
+
101
+ code, auto_fixes = st.engine.auditor.heal_findings(code, findings)
102
+ st.codes[sid] = code
103
+
104
  healed, found, fixed = st.reflect.heal(code)
105
+ total_heals = fixed + auto_fixes
106
+
 
 
107
  for i in range(15):
108
  result = sandbox_validate(healed)
109
+ if result["success"]:
110
+ break
111
+ healed, _, extra = st.reflect.heal(healed, result["errors"])
112
+ total_heals += extra
113
+ st.codes[sid] = healed
114
+ await asyncio.sleep(0.01)
115
+
116
+ yield _sse("heal", {
117
+ "auto_fixes": auto_fixes,
118
+ "reflect_fixes": fixed,
119
+ "total_heals": total_heals,
120
+ "loop_iterations": i + 1,
121
+ })
122
+
123
+ # Phase 5: Sandbox Validation
124
  yield _sse("phase", {"phase": "sandbox"})
125
  result = sandbox_validate(healed)
126
  if result["success"]:
127
+ st.sandbox[sid] = "stable"
128
+ st.publish_ready[sid] = True
129
+ yield _sse("sandbox", {"status": "stable", "errors": 0, "hat": "steady-gold"})
130
  else:
131
  st.sandbox[sid] = "error"
132
  yield _sse("sandbox", {"status": "error", "errors": result["errors"]})
133
+
134
+ session["status"] = "complete"
135
+ yield _sse("done", {
136
+ "status": st.sandbox[sid],
137
+ "hat": "steady-gold" if st.sandbox[sid] == "stable" else "red-glow",
138
+ })
139
+
140
 
141
  async def handle_stream(req):
142
+ sid = str(uuid.uuid4())[:8]
143
+ d = await req.json()
144
+ prompt = d.get("prompt", "")
145
+
146
+ st.sessions[sid] = {"id": sid, "prompt": prompt, "status": "init"}
147
+ st.sandbox[sid] = "building"
148
+ st.publish_ready[sid] = False
149
+
150
+ resp = web.StreamResponse(
151
+ status=200,
152
+ headers={
153
+ "Content-Type": "text/event-stream",
154
+ "Cache-Control": "no-cache",
155
+ "Connection": "keep-alive",
156
+ "X-Accel-Buffering": "no",
157
+ },
158
+ )
159
  await resp.prepare(req)
160
  try:
161
+ async for ev in stream_gen(sid, prompt):
162
+ await resp.write(ev.encode())
163
  await resp.write(b"event: close\ndata: {}\n\n")
164
  except Exception as e:
165
+ await resp.write(
166
+ f"event: error\ndata: {json.dumps({'error': str(e)})}\n\n".encode()
167
+ )
168
  return resp
169
 
170
+
171
  async def handle_publish(req):
172
+ d = await req.json()
173
+ sid = d.get("session_id")
174
+ vibe_name = d.get("vibe_name", f"omni-vibe-{sid}")
175
+
176
  if not st.publish_ready.get(sid):
177
+ return web.json_response(
178
+ {"success": False, "error": "Sandbox not stable — Pose Auditor requires perfection."},
179
+ status=400,
180
+ )
181
+
182
+ code = st.codes.get(sid, "")
183
+ if not code:
184
+ return web.json_response({"success": False, "error": "No code generated"}, status=400)
185
+
186
+ description = d.get("description", st.sessions.get(sid, {}).get("prompt", ""))
187
+ result = await ghost.publish(code, vibe_name, description[:200] if description else "", port=PORT)
188
+
189
  if result.get("success"):
190
  st.sessions[sid]["published"] = True
191
+ st.sessions[sid]["deploy_url"] = result.get("space_url")
192
+ st.sessions[sid]["tunnel_url"] = result.get("tunnel_url")
193
+
194
  return web.json_response(result)
195
 
196
+
197
  async def handle_health(req):
198
+ return web.json_response({
199
+ "status": "alive",
200
+ "engine": "Omni-Vibe Studio — Specialized Swarm",
201
+ "protocol": "omni-vibe / tokenless / shadow-hosting",
202
+ "registry": CANONICAL_REPO,
203
+ "lifert": True,
204
+ "poses": {
205
+ "architect": "full-stack + zero-DB + Google OAuth",
206
+ "painter": "Liquid Glass design system",
207
+ "auditor": "step-by-step verification",
208
+ },
209
+ "hat": WIZARD_HAT_COLOR,
210
+ "hf_token": bool(os.environ.get("HF_TOKEN")),
211
+ })
212
+
213
 
214
  async def handle_agent(req):
215
+ return web.json_response(ghost.generate_agent_card(
216
+ "omni-vibe-studio",
217
+ "Omni-Vibe Studio — Specialized AI Swarm. Pose Architect designs full-stack schemas with zero-config DB and Google OAuth. Pose Painter enforces Liquid Glass design. Pose Auditor verifies step-by-step. LiteRT engine for sub-second latency.",
218
+ "https://dryymatt-wizard-vibe-studio-v2.hf.space",
219
+ ))
220
+
221
 
222
  async def handle_preview(req):
223
+ sid = req.query.get("session_id", "")
224
+ return web.Response(
225
+ text=st.codes.get(sid, "<!-- Omni-Vibe — no code -->"),
226
+ content_type="text/html",
227
+ )
228
+
229
 
230
  async def handle_status(req):
231
+ sid = req.query.get("session_id", "")
232
  if sid in st.sessions:
233
  s = st.sessions[sid]
234
+ return web.json_response({
235
+ "status": s["status"],
236
+ "sandbox": st.sandbox.get(sid),
237
+ "ready": st.publish_ready.get(sid),
238
+ "deploy_url": s.get("deploy_url"),
239
+ "tunnel_url": s.get("tunnel_url"),
240
+ "hat": "steady-gold" if st.publish_ready.get(sid) else "cyan-blink",
241
+ })
242
+ return web.json_response({
243
+ "sessions": len(st.sessions),
244
+ "engine": "omni-vibe",
245
+ "hat": WIZARD_HAT_COLOR,
246
+ })
247
+
248
 
249
  async def handle_vibes(req):
250
  vibes = await ghost.list_vibes()
251
+ return web.json_response({
252
+ "vibes": vibes,
253
+ "count": len(vibes),
254
+ "registry": CANONICAL_REPO,
255
+ })
256
+
257
+
258
+ async def handle_tunnel(req):
259
+ """Bring up an ephemeral Pinggy/Cloudflare tunnel for instant preview."""
260
+ try:
261
+ url = await ghost.tunnel.up(PORT, timeout=10.0)
262
+ return web.json_response({"success": bool(url), "url": url})
263
+ except Exception as e:
264
+ return web.json_response({"success": False, "error": str(e)}, status=500)
265
+
266
+
267
+ async def handle_schema(req):
268
+ """Get the full-stack schema for the current session."""
269
+ sid = req.query.get("session_id", "")
270
+ s = st.sessions.get(sid, {})
271
+ schema = s.get("schema", {})
272
+ return web.json_response(schema)
273
+
274
 
275
  async def handle_static(req):
276
+ path = req.match_info.get("path", "index.html")
277
+ fp = STATIC / path
278
+ if not fp.exists():
279
+ return web.Response(text="Not found", status=404)
280
+ ct = {".html": "text/html", ".css": "text/css", ".js": "application/javascript"}
281
+ return web.Response(text=fp.read_text(), content_type=ct.get(fp.suffix, "text/plain"))
282
+
283
 
284
  def create_app():
285
  app = web.Application()
 
289
  app.router.add_get("/api/preview", handle_preview)
290
  app.router.add_get("/api/health", handle_health)
291
  app.router.add_get("/api/vibes", handle_vibes)
292
+ app.router.add_get("/api/tunnel", handle_tunnel)
293
+ app.router.add_get("/api/schema", handle_schema)
294
  app.router.add_get("/.well-known/agent.json", handle_agent)
295
  app.router.add_get("/", handle_static)
296
  app.router.add_get("/{path:.*}", handle_static)
297
  return app
298
 
299
+
300
  def main():
301
+ print(f"🧙‍♂️ Omni-Vibe Studio — Specialized Swarm")
302
+ print(f" Pose Architect : full-stack + zero-DB + Google OAuth")
303
+ print(f" Pose Painter : Liquid Glass design system")
304
+ print(f" Pose Auditor : step-by-step verification")
305
+ print(f" Athanor : LiteRT engine, sub-second latency")
306
+ print(f" Registry : {CANONICAL_REPO}")
307
+ print(f" Hat : {WIZARD_HAT_COLOR}")
308
  web.run_app(create_app(), host="0.0.0.0", port=PORT)
309
 
310
+
311
+ if __name__ == "__main__":
312
+ main()