From 63b577ee46d64db61d5cdfd838c9262e8d394a4d Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 6 Apr 2026 20:38:20 +0100 Subject: [PATCH] fix: worker creates venv before execution, prompt enforces uv pip install --- src/prompts/step_execution.md | 3 ++- src/worker_runner.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/prompts/step_execution.md b/src/prompts/step_execution.md index ca8c6a6..fd9a1e6 100644 --- a/src/prompts/step_execution.md +++ b/src/prompts/step_execution.md @@ -27,6 +27,7 @@ ## 环境信息 - 工作目录是独立的项目工作区,Python venv 已预先激活(.venv/) -- 使用 `uv add <包名>` 或 `pip install <包名>` 安装依赖 +- 安装 Python 包**必须**使用 `uv pip install <包名>`(不要用裸 pip) +- 运行 Python 脚本直接用 `python3 xxx.py`(venv 已在 PATH 中) 请使用中文回复。 diff --git a/src/worker_runner.rs b/src/worker_runner.rs index 03cbd7d..5290561 100644 --- a/src/worker_runner.rs +++ b/src/worker_runner.rs @@ -150,7 +150,15 @@ async fn connect_and_run(server_url: &str, worker_name: &str, llm_config: &crate let llm = LlmClient::new(llm_config); let exec = LocalExecutor::new(None); let workdir = format!("workspaces/{}", project_id); - let instructions = String::new(); // TODO: load from template + let instructions = String::new(); + + // Ensure workspace has a venv + let _ = tokio::fs::create_dir_all(&workdir).await; + let venv_path = format!("{}/.venv", workdir); + if !std::path::Path::new(&venv_path).exists() { + tracing::info!("Setting up venv in {}", workdir); + let _ = exec.execute("uv venv .venv", &workdir).await; + } // update channel → serialize → WebSocket let (update_tx, mut update_rx) = mpsc::channel::(64);