feat: GOD MODE+ v4.0 - main.py
Browse files
main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""
|
| 2 |
-
π GOD MODE+ Autonomous AI Operating System
|
| 3 |
-
Devin + Manus + Genspark Style
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
|
| 7 |
import asyncio
|
|
@@ -42,9 +42,14 @@ from agents.deploy_agent import DeployAgent
|
|
| 42 |
from agents.workflow_agent import WorkflowAgent
|
| 43 |
from agents.sandbox_agent import SandboxAgent
|
| 44 |
from agents.ui_agent import UIAgent
|
| 45 |
-
from agents.autonomous_agent import AutonomousAgent
|
| 46 |
from connectors.manager import ConnectorManager
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
# βββ Structured Logging ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 49 |
structlog.configure(
|
| 50 |
processors=[
|
|
@@ -65,11 +70,16 @@ task_engine = TaskEngine(ws_manager)
|
|
| 65 |
ai_router = AIRouter(ws_manager)
|
| 66 |
connector_manager = ConnectorManager()
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
# βββ Build God Agent Ecosystem ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 69 |
def build_orchestrator() -> GodAgentOrchestrator:
|
| 70 |
orchestrator = GodAgentOrchestrator(ws_manager=ws_manager, ai_router=ai_router)
|
| 71 |
-
|
| 72 |
-
# Register all specialized agents
|
| 73 |
orchestrator.register_agent("chat", ChatAgent(ws_manager, ai_router))
|
| 74 |
orchestrator.register_agent("planner", PlannerAgent(ws_manager, ai_router))
|
| 75 |
orchestrator.register_agent("coding", CodingAgent(ws_manager, ai_router))
|
|
@@ -80,35 +90,40 @@ def build_orchestrator() -> GodAgentOrchestrator:
|
|
| 80 |
orchestrator.register_agent("workflow", WorkflowAgent(ws_manager, ai_router))
|
| 81 |
orchestrator.register_agent("sandbox", SandboxAgent(ws_manager, ai_router))
|
| 82 |
orchestrator.register_agent("ui", UIAgent(ws_manager, ai_router))
|
| 83 |
-
orchestrator.register_agent("autonomous", AutonomousAgent(ws_manager, ai_router))
|
| 84 |
-
|
| 85 |
log.info("π€ God Agent Ecosystem initialized", agents=10)
|
| 86 |
return orchestrator
|
| 87 |
|
|
|
|
| 88 |
orchestrator = build_orchestrator()
|
| 89 |
|
| 90 |
|
| 91 |
@asynccontextmanager
|
| 92 |
async def lifespan(app: FastAPI):
|
| 93 |
-
"
|
| 94 |
-
log.info("
|
| 95 |
await init_db()
|
| 96 |
await task_engine.start()
|
| 97 |
asyncio.create_task(ws_manager.heartbeat_loop())
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
log.info("π€ Agents: Chat, Planner, Coding, Debug, Memory, Connector, Deploy, Workflow, Sandbox, UI")
|
|
|
|
| 100 |
log.info("π AI Router: OpenAI β Groq β Cerebras β OpenRouter β Anthropic")
|
| 101 |
yield
|
| 102 |
-
log.info("π Shutting down...")
|
| 103 |
await task_engine.stop()
|
| 104 |
log.info("β
Shutdown complete")
|
| 105 |
|
| 106 |
|
| 107 |
# βββ FastAPI App βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 108 |
app = FastAPI(
|
| 109 |
-
title="π€ GOD MODE+ AI Operating System",
|
| 110 |
-
description="
|
| 111 |
-
version="
|
| 112 |
lifespan=lifespan,
|
| 113 |
docs_url="/api/docs",
|
| 114 |
redoc_url="/api/redoc",
|
|
@@ -123,6 +138,10 @@ app.state.task_engine = task_engine
|
|
| 123 |
app.state.ai_router = ai_router
|
| 124 |
app.state.orchestrator = orchestrator
|
| 125 |
app.state.connector_manager = connector_manager
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
# βββ Middleware ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 128 |
app.add_middleware(
|
|
@@ -154,34 +173,8 @@ app.include_router(connectors.router, prefix="/api/v1/connectors", tag
|
|
| 154 |
app.include_router(agents_router.router, prefix="/api/v1/agents", tags=["agents"])
|
| 155 |
app.include_router(execution_router.router, prefix="/api/v1/exec", tags=["execution"])
|
| 156 |
|
| 157 |
-
# βββ WebSocket: autonomous execution stream ββββββββββββββββββββββββββββββββ
|
| 158 |
-
@app.websocket("/ws/exec/{session_id}")
|
| 159 |
-
async def ws_exec(websocket: WebSocket, session_id: str):
|
| 160 |
-
"""Live execution streaming for autonomous tasks."""
|
| 161 |
-
await ws_manager.connect(websocket, room=f"exec:{session_id}")
|
| 162 |
-
try:
|
| 163 |
-
while True:
|
| 164 |
-
data = await websocket.receive_text()
|
| 165 |
-
msg = json.loads(data)
|
| 166 |
-
if msg.get("type") == "ping":
|
| 167 |
-
await websocket.send_json({"type": "pong", "timestamp": time.time()})
|
| 168 |
-
elif msg.get("type") == "run":
|
| 169 |
-
from agents.autonomous_agent import AutonomousAgent
|
| 170 |
-
agent = AutonomousAgent(ws_manager=ws_manager, ai_router=ai_router)
|
| 171 |
-
asyncio.create_task(
|
| 172 |
-
agent.run(
|
| 173 |
-
msg.get("goal", ""),
|
| 174 |
-
context=msg.get("context", {}),
|
| 175 |
-
session_id=session_id,
|
| 176 |
-
task_id=session_id,
|
| 177 |
-
max_steps=msg.get("max_steps", 20),
|
| 178 |
-
)
|
| 179 |
-
)
|
| 180 |
-
except WebSocketDisconnect:
|
| 181 |
-
ws_manager.disconnect(websocket, room=f"exec:{session_id}")
|
| 182 |
-
|
| 183 |
|
| 184 |
-
# βββ WebSocket
|
| 185 |
@app.websocket("/ws/tasks/{task_id}")
|
| 186 |
async def ws_task(websocket: WebSocket, task_id: str):
|
| 187 |
await ws_manager.connect(websocket, room=f"task:{task_id}")
|
|
@@ -195,6 +188,7 @@ async def ws_task(websocket: WebSocket, task_id: str):
|
|
| 195 |
ws_manager.disconnect(websocket, room=f"task:{task_id}")
|
| 196 |
|
| 197 |
|
|
|
|
| 198 |
@app.websocket("/ws/logs")
|
| 199 |
async def ws_logs(websocket: WebSocket):
|
| 200 |
await ws_manager.connect(websocket, room="logs")
|
|
@@ -208,6 +202,7 @@ async def ws_logs(websocket: WebSocket):
|
|
| 208 |
ws_manager.disconnect(websocket, room="logs")
|
| 209 |
|
| 210 |
|
|
|
|
| 211 |
@app.websocket("/ws/chat/{session_id}")
|
| 212 |
async def ws_chat(websocket: WebSocket, session_id: str):
|
| 213 |
await ws_manager.connect(websocket, room=f"chat:{session_id}")
|
|
@@ -218,7 +213,6 @@ async def ws_chat(websocket: WebSocket, session_id: str):
|
|
| 218 |
if msg.get("type") == "ping":
|
| 219 |
await websocket.send_json({"type": "pong", "timestamp": time.time()})
|
| 220 |
elif msg.get("type") == "chat_message":
|
| 221 |
-
# Route through God Agent Orchestrator
|
| 222 |
asyncio.create_task(
|
| 223 |
orchestrator.orchestrate(
|
| 224 |
user_message=msg.get("content", ""),
|
|
@@ -227,7 +221,6 @@ async def ws_chat(websocket: WebSocket, session_id: str):
|
|
| 227 |
)
|
| 228 |
)
|
| 229 |
elif msg.get("type") == "task_message":
|
| 230 |
-
# Create autonomous task via task engine
|
| 231 |
from core.models import TaskCreateRequest
|
| 232 |
req = TaskCreateRequest(
|
| 233 |
goal=msg.get("content", ""),
|
|
@@ -238,6 +231,7 @@ async def ws_chat(websocket: WebSocket, session_id: str):
|
|
| 238 |
ws_manager.disconnect(websocket, room=f"chat:{session_id}")
|
| 239 |
|
| 240 |
|
|
|
|
| 241 |
@app.websocket("/ws/agent/status")
|
| 242 |
async def ws_agent_status(websocket: WebSocket):
|
| 243 |
await ws_manager.connect(websocket, room="agent_status")
|
|
@@ -256,40 +250,112 @@ async def ws_agent_status(websocket: WebSocket):
|
|
| 256 |
ws_manager.disconnect(websocket, room="agent_status")
|
| 257 |
|
| 258 |
|
|
|
|
| 259 |
@app.websocket("/ws/sandbox/{session_id}")
|
| 260 |
async def ws_sandbox(websocket: WebSocket, session_id: str):
|
| 261 |
-
"""Live sandbox terminal
|
| 262 |
await ws_manager.connect(websocket, room=f"sandbox:{session_id}")
|
| 263 |
-
sandbox = orchestrator.get_agent("sandbox")
|
| 264 |
try:
|
| 265 |
while True:
|
| 266 |
data = await websocket.receive_text()
|
| 267 |
msg = json.loads(data)
|
|
|
|
| 268 |
if msg.get("type") == "ping":
|
| 269 |
await websocket.send_json({"type": "pong", "timestamp": time.time()})
|
| 270 |
-
|
|
|
|
| 271 |
cmd = msg.get("command", "")
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
await websocket.send_json({
|
| 274 |
-
"type": "
|
| 275 |
"command": cmd,
|
| 276 |
-
"output": result,
|
|
|
|
|
|
|
|
|
|
| 277 |
"timestamp": time.time(),
|
| 278 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
except WebSocketDisconnect:
|
| 280 |
ws_manager.disconnect(websocket, room=f"sandbox:{session_id}")
|
| 281 |
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
# βββ Root ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 284 |
@app.get("/")
|
| 285 |
async def root():
|
| 286 |
cs = connector_manager.get_summary()
|
| 287 |
return {
|
| 288 |
"name": "π€ GOD MODE+ AI Operating System",
|
| 289 |
-
"version": "
|
| 290 |
"status": "operational",
|
| 291 |
-
"mode": "
|
|
|
|
| 292 |
"agents": orchestrator.get_status()["agents"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
"connectors": {
|
| 294 |
"connected": cs["connected"],
|
| 295 |
"total": cs["total"],
|
|
@@ -302,6 +368,7 @@ async def root():
|
|
| 302 |
"/ws/chat/{session_id}",
|
| 303 |
"/ws/agent/status",
|
| 304 |
"/ws/sandbox/{session_id}",
|
|
|
|
| 305 |
],
|
| 306 |
"phases_complete": [
|
| 307 |
"Phase 1: God Agent Orchestrator",
|
|
@@ -310,7 +377,12 @@ async def root():
|
|
| 310 |
"Phase 4: Autonomous Coding Engine",
|
| 311 |
"Phase 5: Memory System",
|
| 312 |
"Phase 6: Real-time Streaming",
|
| 313 |
-
"Phase 7: Workflow
|
|
|
|
| 314 |
"Phase 9: Multi-Model AI Router",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
],
|
| 316 |
}
|
|
|
|
| 1 |
"""
|
| 2 |
+
π GOD MODE+ Autonomous AI Operating System v4.0
|
| 3 |
+
REAL Execution-First Architecture β Devin + Manus + Genspark Style
|
| 4 |
+
Phase 4: Terminal Engine + FileSystem + GitHub + DAG + Self-Repair
|
| 5 |
"""
|
| 6 |
|
| 7 |
import asyncio
|
|
|
|
| 42 |
from agents.workflow_agent import WorkflowAgent
|
| 43 |
from agents.sandbox_agent import SandboxAgent
|
| 44 |
from agents.ui_agent import UIAgent
|
|
|
|
| 45 |
from connectors.manager import ConnectorManager
|
| 46 |
|
| 47 |
+
# βββ New Execution Tools βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 48 |
+
from tools.terminal_engine import TerminalEngine
|
| 49 |
+
from tools.filesystem import FileSystemTool
|
| 50 |
+
from tools.github_tool import GitHubTool
|
| 51 |
+
from tools.task_dag import DAGEngine
|
| 52 |
+
|
| 53 |
# βββ Structured Logging ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 54 |
structlog.configure(
|
| 55 |
processors=[
|
|
|
|
| 70 |
ai_router = AIRouter(ws_manager)
|
| 71 |
connector_manager = ConnectorManager()
|
| 72 |
|
| 73 |
+
# βββ Execution Tools βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 74 |
+
terminal_engine = TerminalEngine(ws_manager)
|
| 75 |
+
fs_tool = FileSystemTool()
|
| 76 |
+
github_tool = GitHubTool()
|
| 77 |
+
dag_engine = DAGEngine(ws_manager)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
# βββ Build God Agent Ecosystem ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 81 |
def build_orchestrator() -> GodAgentOrchestrator:
|
| 82 |
orchestrator = GodAgentOrchestrator(ws_manager=ws_manager, ai_router=ai_router)
|
|
|
|
|
|
|
| 83 |
orchestrator.register_agent("chat", ChatAgent(ws_manager, ai_router))
|
| 84 |
orchestrator.register_agent("planner", PlannerAgent(ws_manager, ai_router))
|
| 85 |
orchestrator.register_agent("coding", CodingAgent(ws_manager, ai_router))
|
|
|
|
| 90 |
orchestrator.register_agent("workflow", WorkflowAgent(ws_manager, ai_router))
|
| 91 |
orchestrator.register_agent("sandbox", SandboxAgent(ws_manager, ai_router))
|
| 92 |
orchestrator.register_agent("ui", UIAgent(ws_manager, ai_router))
|
|
|
|
|
|
|
| 93 |
log.info("π€ God Agent Ecosystem initialized", agents=10)
|
| 94 |
return orchestrator
|
| 95 |
|
| 96 |
+
|
| 97 |
orchestrator = build_orchestrator()
|
| 98 |
|
| 99 |
|
| 100 |
@asynccontextmanager
|
| 101 |
async def lifespan(app: FastAPI):
|
| 102 |
+
log.info("π Starting GOD MODE+ v4.0 AI Operating System...")
|
| 103 |
+
log.info("β‘ REAL Execution Engine: Terminal + FileSystem + GitHub + DAG")
|
| 104 |
await init_db()
|
| 105 |
await task_engine.start()
|
| 106 |
asyncio.create_task(ws_manager.heartbeat_loop())
|
| 107 |
+
|
| 108 |
+
# Ensure workspace exists
|
| 109 |
+
ws_dir = os.environ.get("WORKSPACE_DIR", "/tmp/god_workspace")
|
| 110 |
+
os.makedirs(ws_dir, exist_ok=True)
|
| 111 |
+
|
| 112 |
+
log.info("β
GOD MODE+ v4.0 Platform ready")
|
| 113 |
log.info("π€ Agents: Chat, Planner, Coding, Debug, Memory, Connector, Deploy, Workflow, Sandbox, UI")
|
| 114 |
+
log.info("π§ Tools: TerminalEngine, FileSystem, GitHub, DAG Engine, SelfRepair")
|
| 115 |
log.info("π AI Router: OpenAI β Groq β Cerebras β OpenRouter β Anthropic")
|
| 116 |
yield
|
| 117 |
+
log.info("π Shutting down GOD MODE+ v4.0...")
|
| 118 |
await task_engine.stop()
|
| 119 |
log.info("β
Shutdown complete")
|
| 120 |
|
| 121 |
|
| 122 |
# βββ FastAPI App βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 123 |
app = FastAPI(
|
| 124 |
+
title="π€ GOD MODE+ AI Operating System v4.0",
|
| 125 |
+
description="REAL Execution-First Autonomous AI Engineering Platform β Devin + Manus + Genspark",
|
| 126 |
+
version="4.0.0",
|
| 127 |
lifespan=lifespan,
|
| 128 |
docs_url="/api/docs",
|
| 129 |
redoc_url="/api/redoc",
|
|
|
|
| 138 |
app.state.ai_router = ai_router
|
| 139 |
app.state.orchestrator = orchestrator
|
| 140 |
app.state.connector_manager = connector_manager
|
| 141 |
+
app.state.terminal_engine = terminal_engine
|
| 142 |
+
app.state.fs_tool = fs_tool
|
| 143 |
+
app.state.github_tool = github_tool
|
| 144 |
+
app.state.dag_engine = dag_engine
|
| 145 |
|
| 146 |
# βββ Middleware ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 147 |
app.add_middleware(
|
|
|
|
| 173 |
app.include_router(agents_router.router, prefix="/api/v1/agents", tags=["agents"])
|
| 174 |
app.include_router(execution_router.router, prefix="/api/v1/exec", tags=["execution"])
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
+
# βββ WebSocket: Task Stream ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 178 |
@app.websocket("/ws/tasks/{task_id}")
|
| 179 |
async def ws_task(websocket: WebSocket, task_id: str):
|
| 180 |
await ws_manager.connect(websocket, room=f"task:{task_id}")
|
|
|
|
| 188 |
ws_manager.disconnect(websocket, room=f"task:{task_id}")
|
| 189 |
|
| 190 |
|
| 191 |
+
# βββ WebSocket: Logs ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 192 |
@app.websocket("/ws/logs")
|
| 193 |
async def ws_logs(websocket: WebSocket):
|
| 194 |
await ws_manager.connect(websocket, room="logs")
|
|
|
|
| 202 |
ws_manager.disconnect(websocket, room="logs")
|
| 203 |
|
| 204 |
|
| 205 |
+
# βββ WebSocket: Chat ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 206 |
@app.websocket("/ws/chat/{session_id}")
|
| 207 |
async def ws_chat(websocket: WebSocket, session_id: str):
|
| 208 |
await ws_manager.connect(websocket, room=f"chat:{session_id}")
|
|
|
|
| 213 |
if msg.get("type") == "ping":
|
| 214 |
await websocket.send_json({"type": "pong", "timestamp": time.time()})
|
| 215 |
elif msg.get("type") == "chat_message":
|
|
|
|
| 216 |
asyncio.create_task(
|
| 217 |
orchestrator.orchestrate(
|
| 218 |
user_message=msg.get("content", ""),
|
|
|
|
| 221 |
)
|
| 222 |
)
|
| 223 |
elif msg.get("type") == "task_message":
|
|
|
|
| 224 |
from core.models import TaskCreateRequest
|
| 225 |
req = TaskCreateRequest(
|
| 226 |
goal=msg.get("content", ""),
|
|
|
|
| 231 |
ws_manager.disconnect(websocket, room=f"chat:{session_id}")
|
| 232 |
|
| 233 |
|
| 234 |
+
# βββ WebSocket: Agent Status ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 235 |
@app.websocket("/ws/agent/status")
|
| 236 |
async def ws_agent_status(websocket: WebSocket):
|
| 237 |
await ws_manager.connect(websocket, room="agent_status")
|
|
|
|
| 250 |
ws_manager.disconnect(websocket, room="agent_status")
|
| 251 |
|
| 252 |
|
| 253 |
+
# βββ WebSocket: Sandbox Terminal ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 254 |
@app.websocket("/ws/sandbox/{session_id}")
|
| 255 |
async def ws_sandbox(websocket: WebSocket, session_id: str):
|
| 256 |
+
"""Live streaming sandbox terminal."""
|
| 257 |
await ws_manager.connect(websocket, room=f"sandbox:{session_id}")
|
|
|
|
| 258 |
try:
|
| 259 |
while True:
|
| 260 |
data = await websocket.receive_text()
|
| 261 |
msg = json.loads(data)
|
| 262 |
+
|
| 263 |
if msg.get("type") == "ping":
|
| 264 |
await websocket.send_json({"type": "pong", "timestamp": time.time()})
|
| 265 |
+
|
| 266 |
+
elif msg.get("type") == "execute":
|
| 267 |
cmd = msg.get("command", "")
|
| 268 |
+
task_id = msg.get("task_id", "")
|
| 269 |
+
|
| 270 |
+
async def stream_line(line: str):
|
| 271 |
+
try:
|
| 272 |
+
await websocket.send_json({
|
| 273 |
+
"type": "terminal_output",
|
| 274 |
+
"line": line,
|
| 275 |
+
"timestamp": time.time(),
|
| 276 |
+
})
|
| 277 |
+
except Exception:
|
| 278 |
+
pass
|
| 279 |
+
|
| 280 |
+
result = await terminal_engine.execute(
|
| 281 |
+
cmd,
|
| 282 |
+
session_id=session_id,
|
| 283 |
+
task_id=task_id,
|
| 284 |
+
stream_callback=stream_line,
|
| 285 |
+
)
|
| 286 |
await websocket.send_json({
|
| 287 |
+
"type": "terminal_result",
|
| 288 |
"command": cmd,
|
| 289 |
+
"output": result.get("output", ""),
|
| 290 |
+
"exit_code": result.get("exit_code", 0),
|
| 291 |
+
"success": result.get("success", False),
|
| 292 |
+
"duration": result.get("duration", 0),
|
| 293 |
"timestamp": time.time(),
|
| 294 |
})
|
| 295 |
+
|
| 296 |
+
elif msg.get("type") == "kill":
|
| 297 |
+
result = await terminal_engine.kill(session_id)
|
| 298 |
+
await websocket.send_json({"type": "kill_result", **result})
|
| 299 |
+
|
| 300 |
+
elif msg.get("type") == "write_file":
|
| 301 |
+
filename = msg.get("filename", "")
|
| 302 |
+
content = msg.get("content", "")
|
| 303 |
+
result = await fs_tool.write_file(filename, content)
|
| 304 |
+
await websocket.send_json({"type": "file_result", **result})
|
| 305 |
+
|
| 306 |
+
elif msg.get("type") == "read_file":
|
| 307 |
+
filename = msg.get("filename", "")
|
| 308 |
+
result = await fs_tool.read_file(filename)
|
| 309 |
+
await websocket.send_json({"type": "file_result", **result})
|
| 310 |
+
|
| 311 |
+
elif msg.get("type") == "list_files":
|
| 312 |
+
result = await fs_tool.list_dir(msg.get("path", ""))
|
| 313 |
+
await websocket.send_json({"type": "file_list", **result})
|
| 314 |
+
|
| 315 |
+
elif msg.get("type") == "tree":
|
| 316 |
+
result = await fs_tool.tree(msg.get("path", ""))
|
| 317 |
+
await websocket.send_json({"type": "tree_result", **result})
|
| 318 |
+
|
| 319 |
except WebSocketDisconnect:
|
| 320 |
ws_manager.disconnect(websocket, room=f"sandbox:{session_id}")
|
| 321 |
|
| 322 |
|
| 323 |
+
# βββ WebSocket: DAG Progress ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 324 |
+
@app.websocket("/ws/dag/{dag_id}")
|
| 325 |
+
async def ws_dag(websocket: WebSocket, dag_id: str):
|
| 326 |
+
"""Real-time DAG execution progress."""
|
| 327 |
+
await ws_manager.connect(websocket, room=f"dag:{dag_id}")
|
| 328 |
+
try:
|
| 329 |
+
while True:
|
| 330 |
+
data = await websocket.receive_text()
|
| 331 |
+
msg = json.loads(data)
|
| 332 |
+
if msg.get("type") == "ping":
|
| 333 |
+
await websocket.send_json({"type": "pong", "timestamp": time.time()})
|
| 334 |
+
elif msg.get("type") == "get_dag":
|
| 335 |
+
dag = dag_engine.get_dag(dag_id)
|
| 336 |
+
if dag:
|
| 337 |
+
await websocket.send_json({"type": "dag_state", "dag": dag.to_dict()})
|
| 338 |
+
except WebSocketDisconnect:
|
| 339 |
+
ws_manager.disconnect(websocket, room=f"dag:{dag_id}")
|
| 340 |
+
|
| 341 |
+
|
| 342 |
# βββ Root ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 343 |
@app.get("/")
|
| 344 |
async def root():
|
| 345 |
cs = connector_manager.get_summary()
|
| 346 |
return {
|
| 347 |
"name": "π€ GOD MODE+ AI Operating System",
|
| 348 |
+
"version": "4.0.0",
|
| 349 |
"status": "operational",
|
| 350 |
+
"mode": "god_mode_plus_v4",
|
| 351 |
+
"execution_engine": "REAL",
|
| 352 |
"agents": orchestrator.get_status()["agents"],
|
| 353 |
+
"tools": {
|
| 354 |
+
"terminal": "TerminalEngine (streaming, self-repair)",
|
| 355 |
+
"filesystem": "FileSystemTool (read/write/patch/search/tree)",
|
| 356 |
+
"github": "GitHubTool (clone/commit/push/pr/issues)",
|
| 357 |
+
"dag": "DAGEngine (parallel, dependency-aware)",
|
| 358 |
+
},
|
| 359 |
"connectors": {
|
| 360 |
"connected": cs["connected"],
|
| 361 |
"total": cs["total"],
|
|
|
|
| 368 |
"/ws/chat/{session_id}",
|
| 369 |
"/ws/agent/status",
|
| 370 |
"/ws/sandbox/{session_id}",
|
| 371 |
+
"/ws/dag/{dag_id}",
|
| 372 |
],
|
| 373 |
"phases_complete": [
|
| 374 |
"Phase 1: God Agent Orchestrator",
|
|
|
|
| 377 |
"Phase 4: Autonomous Coding Engine",
|
| 378 |
"Phase 5: Memory System",
|
| 379 |
"Phase 6: Real-time Streaming",
|
| 380 |
+
"Phase 7: Workflow Factory OS",
|
| 381 |
+
"Phase 8: Terminal Execution Engine",
|
| 382 |
"Phase 9: Multi-Model AI Router",
|
| 383 |
+
"Phase 10: FileSystem Control",
|
| 384 |
+
"Phase 11: GitHub Autonomy",
|
| 385 |
+
"Phase 12: Task DAG Engine",
|
| 386 |
+
"Phase 13: Self-Repair Loop",
|
| 387 |
],
|
| 388 |
}
|