π§ββοΈ Ghost Deploy: server.py
Browse files
server.py
CHANGED
|
@@ -1,18 +1,15 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 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
|
| 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,
|
| 62 |
-
st.sandbox[sid]
|
| 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")
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
code = st.codes.get(sid,"")
|
| 76 |
-
if not code: return web.json_response({"error":"No code"}, status=400)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
return web.json_response(
|
| 83 |
|
| 84 |
async def handle_health(req):
|
| 85 |
-
return web.json_response({"status":"alive","engine":"Wizard-Vibe Studio","
|
| 86 |
|
| 87 |
async def handle_agent(req):
|
| 88 |
-
return web.json_response(
|
| 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:
|
|
|
|
|
|
|
| 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
|
| 119 |
-
print(f"
|
| 120 |
-
print(f"
|
| 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()
|