FerrellSyntheticIntelligence commited on
Commit
890a66a
·
verified ·
1 Parent(s): adb0efd

Upload ide/server.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. ide/server.py +84 -0
ide/server.py CHANGED
@@ -12,6 +12,8 @@ from rabbit import WhiteRabbit
12
  from android_compiler_fixed import AndroidCompiler
13
  from mesh_repo import MeshRepo, _set_node_id
14
  from fsi_sandbox import ExecutionSandbox
 
 
15
 
16
  HOST = "0.0.0.0"
17
  PORT = 8080
@@ -39,6 +41,8 @@ class APIHandler(SimpleHTTPRequestHandler):
39
  rabbit = None
40
  android = None
41
  mesh_repo = None
 
 
42
  _start_time = time.time()
43
 
44
  def __init__(self, *args, **kwargs):
@@ -65,6 +69,8 @@ class APIHandler(SimpleHTTPRequestHandler):
65
 
66
  def do_GET(self):
67
  path = urlparse(self.path).path
 
 
68
  handlers = {
69
  "/api/status": self._handle_status,
70
  "/api/stats": self._handle_stats,
@@ -75,6 +81,8 @@ class APIHandler(SimpleHTTPRequestHandler):
75
  "/api/mesh/discover": self._handle_mesh_discover,
76
  "/api/android/env": self._handle_android_env,
77
  "/api/mesh/repo/search": self._handle_mesh_repo_search,
 
 
78
  }
79
  handler = handlers.get(path)
80
  if handler:
@@ -85,6 +93,8 @@ class APIHandler(SimpleHTTPRequestHandler):
85
  def do_POST(self):
86
  path = urlparse(self.path).path
87
  body = self._read_body()
 
 
88
  handlers = {
89
  "/api/command": self._handle_command,
90
  "/api/build": self._handle_build,
@@ -111,6 +121,8 @@ class APIHandler(SimpleHTTPRequestHandler):
111
  "/api/super/generate": self._handle_super_generate,
112
  "/api/super/run": self._handle_super_run,
113
  "/api/super/status": self._handle_super_status,
 
 
114
  }
115
  handler = handlers.get(path)
116
  if handler:
@@ -132,6 +144,19 @@ class APIHandler(SimpleHTTPRequestHandler):
132
  try:
133
  from chimera.engine import ChimeraEngine
134
  APIHandler.chimera = ChimeraEngine()
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  except Exception as e:
136
  return str(e)
137
  return None
@@ -305,6 +330,8 @@ class APIHandler(SimpleHTTPRequestHandler):
305
  " super use <id> — Select foreground variant (checks bg solutions on error)",
306
  " super run <id> — Run foreground + 4 background variants simultaneously",
307
  " super status — Show all variant statuses",
 
 
308
  " clear — Clear terminal",
309
  " woogity woogity — ???",
310
  ]
@@ -503,6 +530,29 @@ class APIHandler(SimpleHTTPRequestHandler):
503
  output.append(f" [{v['id']}] {icon} {v['approach']:14s} → {v.get('status', 'pending')} ({v.get('loc', 0)} LOC)")
504
  td = ci.superimposition.collect_training_data()
505
  output.append(f"[SUPER] Training data: {len(td)} entries ready")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
  elif lower.startswith("test"):
507
  target = rest or "all"
508
  output.append(f"[TEST] Running test suite: {target}")
@@ -976,6 +1026,40 @@ class APIHandler(SimpleHTTPRequestHandler):
976
  "log_path": SUPERIMPOSITION_LOG if 'SUPERIMPOSITION_LOG' in dir() else "/tmp/fsi_felon/superimposition_log.json",
977
  })
978
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979
  def _handle_mesh_related(self, body):
980
  text = body.get("text", "").lower()
981
  if not text or len(text) < 10:
 
12
  from android_compiler_fixed import AndroidCompiler
13
  from mesh_repo import MeshRepo, _set_node_id
14
  from fsi_sandbox import ExecutionSandbox
15
+ from fsi_shadow import ShadowMode
16
+ from fsi_selfplay import SelfPlay
17
 
18
  HOST = "0.0.0.0"
19
  PORT = 8080
 
41
  rabbit = None
42
  android = None
43
  mesh_repo = None
44
+ shadow = None
45
+ selfplay = None
46
  _start_time = time.time()
47
 
48
  def __init__(self, *args, **kwargs):
 
69
 
70
  def do_GET(self):
71
  path = urlparse(self.path).path
72
+ if APIHandler.shadow:
73
+ APIHandler.shadow.register_input()
74
  handlers = {
75
  "/api/status": self._handle_status,
76
  "/api/stats": self._handle_stats,
 
81
  "/api/mesh/discover": self._handle_mesh_discover,
82
  "/api/android/env": self._handle_android_env,
83
  "/api/mesh/repo/search": self._handle_mesh_repo_search,
84
+ "/api/shadow/status": self._handle_shadow_status,
85
+ "/api/selfplay/status": self._handle_selfplay_status,
86
  }
87
  handler = handlers.get(path)
88
  if handler:
 
93
  def do_POST(self):
94
  path = urlparse(self.path).path
95
  body = self._read_body()
96
+ if APIHandler.shadow:
97
+ APIHandler.shadow.register_input()
98
  handlers = {
99
  "/api/command": self._handle_command,
100
  "/api/build": self._handle_build,
 
121
  "/api/super/generate": self._handle_super_generate,
122
  "/api/super/run": self._handle_super_run,
123
  "/api/super/status": self._handle_super_status,
124
+ "/api/shadow/run": self._handle_shadow_run,
125
+ "/api/selfplay/run": self._handle_selfplay_run,
126
  }
127
  handler = handlers.get(path)
128
  if handler:
 
144
  try:
145
  from chimera.engine import ChimeraEngine
146
  APIHandler.chimera = ChimeraEngine()
147
+ self._ensure_shadow()
148
+ except Exception as e:
149
+ return str(e)
150
+ return None
151
+
152
+ def _ensure_shadow(self):
153
+ if APIHandler.shadow is None:
154
+ try:
155
+ sandbox = ExecutionSandbox()
156
+ sp = SelfPlay(chimera=APIHandler.chimera, sandbox=sandbox)
157
+ APIHandler.selfplay = sp
158
+ APIHandler.shadow = ShadowMode(chimera=APIHandler.chimera, sandbox=sandbox, selfplay=sp)
159
+ APIHandler.shadow.start()
160
  except Exception as e:
161
  return str(e)
162
  return None
 
330
  " super use <id> — Select foreground variant (checks bg solutions on error)",
331
  " super run <id> — Run foreground + 4 background variants simultaneously",
332
  " super status — Show all variant statuses",
333
+ " shadow status — Shadow mode status",
334
+ " selfplay run [n] — Run self-play (default 10 rounds)",
335
  " clear — Clear terminal",
336
  " woogity woogity — ???",
337
  ]
 
530
  output.append(f" [{v['id']}] {icon} {v['approach']:14s} → {v.get('status', 'pending')} ({v.get('loc', 0)} LOC)")
531
  td = ci.superimposition.collect_training_data()
532
  output.append(f"[SUPER] Training data: {len(td)} entries ready")
533
+ elif lower == "shadow status" or lower.startswith("shadow "):
534
+ err = self._ensure_shadow()
535
+ if err or not APIHandler.shadow:
536
+ output.append(f"[SHADOW] Error: {err or 'shadow not loaded'}")
537
+ else:
538
+ s = APIHandler.shadow.get_status()
539
+ output.append(f"[SHADOW] Active: {s['active']} | Idle: {s['idle_secs']}s | Running: {s['running']}")
540
+ output.append(f"[SHADOW] Training data: {s['training_dir']} bytes | Log: {s['log_size']} bytes")
541
+ if s['active']:
542
+ output.append(f"[SHADOW] Session elapsed: {s['session_elapsed']}s")
543
+ elif lower.startswith("selfplay"):
544
+ err = self._ensure_shadow()
545
+ if err or not APIHandler.selfplay:
546
+ output.append(f"[SELFPLAY] Error: {err or 'selfplay not loaded'}")
547
+ else:
548
+ parts = cmd.split()
549
+ rounds = 10
550
+ if len(parts) >= 2 and parts[-1].isdigit():
551
+ rounds = int(parts[-1])
552
+ output.append(f"[SELFPLAY] Running {rounds} rounds...")
553
+ summary = APIHandler.selfplay.run_session(rounds=rounds)
554
+ output.append(f"[SELFPLAY] Builder: {summary['builder_total']} pts | Breaker: {summary['breaker_total']} pts")
555
+ output.append(f"[SELFPLAY] Winner: {summary['winner']} | Flaws: {summary['total_flaws']} | Fixes: {summary['total_fixes']}")
556
  elif lower.startswith("test"):
557
  target = rest or "all"
558
  output.append(f"[TEST] Running test suite: {target}")
 
1026
  "log_path": SUPERIMPOSITION_LOG if 'SUPERIMPOSITION_LOG' in dir() else "/tmp/fsi_felon/superimposition_log.json",
1027
  })
1028
 
1029
+ # ── Shadow Mode Handlers ──
1030
+ def _handle_shadow_status(self):
1031
+ err = self._ensure_shadow()
1032
+ if err or not APIHandler.shadow:
1033
+ self._send_json({"error": "Shadow not ready"})
1034
+ return
1035
+ self._send_json(APIHandler.shadow.get_status())
1036
+
1037
+ def _handle_shadow_run(self, body):
1038
+ err = self._ensure_shadow()
1039
+ if err or not APIHandler.shadow:
1040
+ self._send_json({"error": "Shadow not ready"})
1041
+ return
1042
+ shadow = APIHandler.shadow
1043
+ shadow.last_input = time.time() - 310 # Force idle
1044
+ self._send_json({"status": "shadow_triggered", "message": "Shadow mode will activate on next cycle"})
1045
+
1046
+ # ── Self-Play Mode Handlers ──
1047
+ def _handle_selfplay_status(self):
1048
+ err = self._ensure_shadow()
1049
+ if err or not APIHandler.selfplay:
1050
+ self._send_json({"error": "SelfPlay not ready"})
1051
+ return
1052
+ self._send_json(APIHandler.selfplay.get_status())
1053
+
1054
+ def _handle_selfplay_run(self, body):
1055
+ err = self._ensure_shadow()
1056
+ if err or not APIHandler.selfplay:
1057
+ self._send_json({"error": "SelfPlay not ready"})
1058
+ return
1059
+ rounds = body.get("rounds", 10)
1060
+ summary = APIHandler.selfplay.run_session(rounds=rounds)
1061
+ self._send_json(summary)
1062
+
1063
  def _handle_mesh_related(self, body):
1064
  text = body.get("text", "").lower()
1065
  if not text or len(text) < 10: