RDS777 commited on
Commit
1646601
·
verified ·
1 Parent(s): e408261

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -3
app.py CHANGED
@@ -713,6 +713,26 @@ class Sandbox:
713
  finally:
714
  Path(temp_path).unlink(missing_ok=True)
715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
716
 
717
  sandbox = Sandbox()
718
 
@@ -1022,12 +1042,20 @@ function sendTask(){
1022
  ws.send(JSON.stringify({action:'agent', task:t}));
1023
  }
1024
  function clearChat(){ document.getElementById('chat').innerHTML = ''; }
1025
- function qTest(){ sendDirect('Run all tests and report failures'); }
1026
- function qFix(){ sendDirect('Scan for bugs and fix them'); }
 
 
 
 
1027
  function qExp(){
1028
  if (!curFile){ addMsg('e','Open a file first'); return; }
1029
- sendDirect('Explain '+curFile);
 
1030
  }
 
 
 
1031
  function sendDirect(t){ addMsg('u',t); ws.send(JSON.stringify({action:'agent', task:t})); }
1032
  function runTelemetry(){
1033
  if (!curFile){ alert('No file open'); return; }
@@ -1176,6 +1204,42 @@ async def websocket_endpoint(websocket: WebSocket):
1176
  elif action == "agent":
1177
  result = await agent.run_task(session_id, msg.get("task", ""), websocket)
1178
  await websocket.send_json({"type": "agent_result", "data": result})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1179
  elif action == "telemetry_run":
1180
  code = file_mgr.read(msg.get("path")).get("content", "")
1181
  result = await telemetry.run_with_trace(code)
 
713
  finally:
714
  Path(temp_path).unlink(missing_ok=True)
715
 
716
+ async def run_command(self, args: list, timeout=30):
717
+ """Execute une commande arbitraire (liste d'arguments, pas de shell=True)
718
+ dans le workspace. Utilise par les actions rapides deterministes
719
+ (Tests, Fix) qui n'ont pas besoin de passer par la decision du LLM."""
720
+ try:
721
+ proc = await asyncio.create_subprocess_exec(
722
+ *args,
723
+ stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
724
+ cwd=str(Config.WORKSPACE_ROOT))
725
+ try:
726
+ stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)
727
+ return {"success": proc.returncode == 0, "returncode": proc.returncode,
728
+ "stdout": stdout.decode('utf-8', errors='replace'),
729
+ "stderr": stderr.decode('utf-8', errors='replace')}
730
+ except asyncio.TimeoutError:
731
+ proc.kill()
732
+ return {"success": False, "error": "Timeout", "stdout": "", "stderr": ""}
733
+ except Exception as e:
734
+ return {"success": False, "error": str(e), "stdout": "", "stderr": ""}
735
+
736
 
737
  sandbox = Sandbox()
738
 
 
1042
  ws.send(JSON.stringify({action:'agent', task:t}));
1043
  }
1044
  function clearChat(){ document.getElementById('chat').innerHTML = ''; }
1045
+ // Les boutons rapides (Tests/Fix/Explain) sont des actions deterministes :
1046
+ // on sait deja quoi executer, donc on ne passe pas par la boucle agentique
1047
+ // (qui laisse le LLM decider quel outil appeler). Cela evite les esquives
1048
+ // que peut produire un petit modele face a une decision d'outil.
1049
+ function qTest(){ addMsg('u','Run all tests and report failures'); ws.send(JSON.stringify({action:'quick_test'})); }
1050
+ function qFix(){ addMsg('u','Scan for bugs and fix them'); ws.send(JSON.stringify({action:'quick_fix'})); }
1051
  function qExp(){
1052
  if (!curFile){ addMsg('e','Open a file first'); return; }
1053
+ addMsg('u','Explain '+curFile);
1054
+ ws.send(JSON.stringify({action:'quick_explain', path:curFile}));
1055
  }
1056
+ // La zone de texte libre ("Describe what to build...") reste sur le
1057
+ // pipeline agentique complet : c'est la seule ou un vrai raisonnement
1058
+ // multi-etapes (choix d'outil inclus) est necessaire.
1059
  function sendDirect(t){ addMsg('u',t); ws.send(JSON.stringify({action:'agent', task:t})); }
1060
  function runTelemetry(){
1061
  if (!curFile){ alert('No file open'); return; }
 
1204
  elif action == "agent":
1205
  result = await agent.run_task(session_id, msg.get("task", ""), websocket)
1206
  await websocket.send_json({"type": "agent_result", "data": result})
1207
+ elif action == "quick_test":
1208
+ # Action deterministe : on sait deja quelle commande executer,
1209
+ # inutile de laisser un petit modele "decider" d'appeler un
1210
+ # outil — on l'execute directement et on ne sollicite le LLM
1211
+ # que pour resumer un resultat deja connu (pas de JSON a
1212
+ # produire, donc pas de risque d'esquive).
1213
+ result = await sandbox.run_command([sys.executable, "-m", "pytest", "-q"])
1214
+ summary = await inference.generate([
1215
+ {"role": "system", "content": "You are a coding assistant. Summarize this pytest output concisely in plain text for a developer: how many passed/failed, and the key error if any. No JSON, no tool calls."},
1216
+ {"role": "user", "content": f"stdout:\n{result.get('stdout','')}\n\nstderr:\n{result.get('stderr','')}"},
1217
+ ], max_tokens=300, do_sample=False)
1218
+ await websocket.send_json({"type": "agent_result", "data": {"success": True, "result": summary, "raw": result}})
1219
+ elif action == "quick_fix":
1220
+ result = await sandbox.run_command([sys.executable, "-m", "flake8", "."])
1221
+ if result.get("stdout", "").strip() == "" and result.get("returncode") == 0:
1222
+ summary = "Aucun probleme detecte par flake8."
1223
+ else:
1224
+ summary = await inference.generate([
1225
+ {"role": "system", "content": "You are a coding assistant. Given this flake8 output, list the issues found and suggest concise fixes in plain text. No JSON, no tool calls."},
1226
+ {"role": "user", "content": result.get("stdout", "") or result.get("stderr", "")},
1227
+ ], max_tokens=400, do_sample=False)
1228
+ await websocket.send_json({"type": "agent_result", "data": {"success": True, "result": summary, "raw": result}})
1229
+ elif action == "quick_explain":
1230
+ path = msg.get("path", "")
1231
+ if not path:
1232
+ await websocket.send_json({"type": "agent_result", "data": {"success": False, "result": "Aucun fichier ouvert."}})
1233
+ else:
1234
+ file_result = file_mgr.read(path)
1235
+ if not file_result.get("success"):
1236
+ await websocket.send_json({"type": "agent_result", "data": {"success": False, "result": file_result.get("error", "Fichier introuvable.")}})
1237
+ else:
1238
+ summary = await inference.generate([
1239
+ {"role": "system", "content": "You are a coding assistant. Explain the given file's purpose, structure and possible improvements, concisely, in plain text. No JSON, no tool calls."},
1240
+ {"role": "user", "content": f"File: {path}\n\n{file_result.get('content','')}"},
1241
+ ], max_tokens=400, do_sample=False)
1242
+ await websocket.send_json({"type": "agent_result", "data": {"success": True, "result": summary}})
1243
  elif action == "telemetry_run":
1244
  code = file_mgr.read(msg.get("path")).get("content", "")
1245
  result = await telemetry.run_with_trace(code)