dryymatt commited on
Commit
5fdaf66
Β·
verified Β·
1 Parent(s): 69700af

πŸ§™β€β™‚οΈ Ghost Deploy: server.py

Browse files
Files changed (1) hide show
  1. server.py +42 -38
server.py CHANGED
@@ -1,18 +1,15 @@
1
  """
2
- Wizard-Vibe Studio β€” Server Entry Point
3
- ========================================
4
- M523zappin/Wizard-Vibe-Studio
5
- github.com/M523zappin/Wizard-Vibe-Studio
6
-
7
- Imports engine from core.py, bridge from github_bridge.py.
8
  """
9
-
10
  import json, os, uuid, asyncio
11
  from pathlib import Path
12
  from aiohttp import web
13
-
14
- from core import Orchestrator, ReflectSelect, sandbox_validate, state as st
15
- from github_bridge import bridge, TARGET_GITHUB, TARGET_URL, CANONICAL_HF
16
 
17
  PORT = int(os.environ.get("WIZARD_PORT", 8765))
18
  STATIC = Path(__file__).parent / "static"
@@ -35,31 +32,29 @@ async def stream_gen(sid, prompt):
35
  healed, found, fixed = st.reflect.heal(code)
36
  st.codes[sid] = healed
37
  yield _sse("heal", {"found": found, "fixed": fixed})
 
 
 
 
 
 
 
 
38
  yield _sse("phase", {"phase": "sandbox"})
39
-
40
  result = sandbox_validate(healed)
41
  if result["success"]:
42
  st.sandbox[sid] = "stable"; st.publish_ready[sid] = True
43
- yield _sse("sandbox", {"status": "stable"})
44
  else:
45
  st.sandbox[sid] = "error"
46
  yield _sse("sandbox", {"status": "error", "errors": result["errors"]})
47
- for i in range(3):
48
- healed, _, _ = st.reflect.heal(healed, result["errors"])
49
- st.codes[sid] = healed
50
- result = sandbox_validate(healed)
51
- if result["success"]:
52
- st.sandbox[sid] = "stable"; st.publish_ready[sid] = True
53
- yield _sse("sandbox", {"status": "stable", "heals": i+1})
54
- break
55
- yield _sse("heal_attempt", {"attempt": i+1})
56
  st.sessions[sid]["status"] = "complete"
57
  yield _sse("done", {"status": st.sandbox[sid]})
58
 
59
  async def handle_stream(req):
60
  sid = str(uuid.uuid4())[:8]; d = await req.json(); prompt = d.get("prompt","")
61
- st.sessions[sid] = {"id":sid, "prompt":prompt, "status":"init"}
62
- st.sandbox[sid] = "building"; st.publish_ready[sid] = False
63
  resp = web.StreamResponse(status=200, headers={"Content-Type":"text/event-stream","Cache-Control":"no-cache","Connection":"keep-alive","X-Accel-Buffering":"no"})
64
  await resp.prepare(req)
65
  try:
@@ -70,22 +65,24 @@ async def handle_stream(req):
70
  return resp
71
 
72
  async def handle_publish(req):
73
- d = await req.json(); sid = d.get("session_id"); repo = d.get("repo_name",f"wizard-vibe-{sid}")
74
- if not st.publish_ready.get(sid): return web.json_response({"error":"Sandbox not stable"}, status=400)
 
 
75
  code = st.codes.get(sid,"")
76
- if not code: return web.json_response({"error":"No code"}, status=400)
77
- agent = bridge.generate_agent_card(repo, d.get("description",""), TARGET_URL)
78
- files = {"index.html": code, ".well-known/agent.json": json.dumps(agent,indent=2),
79
- "README.md": f"# {repo}\n\nBuilt with Wizard-Vibe Studio\n\n**GitHub**: {TARGET_URL}\n**HF**: https://huggingface.co/{CANONICAL_HF}\n"}
80
- result = await bridge.publish(repo, files, d.get("description",""))
81
- st.sessions[sid]["published"] = True
82
- return web.json_response({"success":True, **result, "agent":agent})
83
 
84
  async def handle_health(req):
85
- return web.json_response({"status":"alive","engine":"Wizard-Vibe Studio","sandbox_first":True,"target":TARGET_GITHUB,"github_token":bool(os.environ.get("GITHUB_TOKEN")),"hf_token":bool(os.environ.get("HF_TOKEN"))})
86
 
87
  async def handle_agent(req):
88
- return web.json_response(bridge.generate_agent_card("wizard-vibe-studio","Wizard-Vibe Studio β€” sandbox-first autonomous creator with Reflect-Select self-healing and GitHub bridge.",TARGET_URL))
89
 
90
  async def handle_preview(req):
91
  sid = req.query.get("session_id","")
@@ -93,9 +90,15 @@ async def handle_preview(req):
93
 
94
  async def handle_status(req):
95
  sid = req.query.get("session_id","")
96
- if sid in st.sessions: return web.json_response({"status":st.sessions[sid]["status"],"sandbox":st.sandbox.get(sid),"ready":st.publish_ready.get(sid)})
 
 
97
  return web.json_response({"sessions":len(st.sessions)})
98
 
 
 
 
 
99
  async def handle_static(req):
100
  path = req.match_info.get("path","index.html"); fp = STATIC/path
101
  if not fp.exists(): return web.Response(text="Not found", status=404)
@@ -109,15 +112,16 @@ def create_app():
109
  app.router.add_get("/api/status", handle_status)
110
  app.router.add_get("/api/preview", handle_preview)
111
  app.router.add_get("/api/health", handle_health)
 
112
  app.router.add_get("/.well-known/agent.json", handle_agent)
113
  app.router.add_get("/", handle_static)
114
  app.router.add_get("/{path:.*}", handle_static)
115
  return app
116
 
117
  def main():
118
- print(f"πŸ§™β€β™‚οΈ Wizard-Vibe Studio β†’ {TARGET_GITHUB}")
119
- print(f" Canonical HF: {CANONICAL_HF}")
120
- print(f" Access: {'GITHUB_TOKEN' if os.environ.get('GITHUB_TOKEN') else 'HF Hub bridge'}")
121
  web.run_app(create_app(), host="0.0.0.0", port=PORT)
122
 
123
  if __name__ == "__main__": main()
 
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"
 
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:
 
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","")
 
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)
 
112
  app.router.add_get("/api/status", handle_status)
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()