diff --git a/packages/agent-core/script/build.ts b/packages/agent-core/script/build.ts index 77b4ef4716..8d2c9273dd 100755 --- a/packages/agent-core/script/build.ts +++ b/packages/agent-core/script/build.ts @@ -27,6 +27,30 @@ async function ensureZeeDependencies() { await $`pnpm install --prod --ignore-scripts`.cwd(zeeRoot) } +function resolveStanleyRuntime(): string | undefined { + const configured = process.env.STANLEY_PYTHON_RUNTIME + if (configured && fs.existsSync(configured)) return configured + const pyenvRoot = process.env.PYENV_ROOT + const pyenvVersion = process.env.PYENV_VERSION + if (pyenvRoot && pyenvVersion) { + const candidate = path.join(pyenvRoot, "versions", pyenvVersion) + if (fs.existsSync(candidate)) return candidate + } + return undefined +} + +function ensureStanleyRuntime() { + const runtimeRoot = resolveStanleyRuntime() + if (!runtimeRoot) return + const destRoot = path.join(stanleyRoot, ".python-runtime") + if (fs.existsSync(destRoot)) return + console.log("bundling stanley python runtime") + fs.cpSync(runtimeRoot, destRoot, { + recursive: true, + dereference: true, + }) +} + function getStanleyRequirementsFile(): string | undefined { const locked = path.join(stanleyRoot, "requirements-lock.txt") if (fs.existsSync(locked)) return locked @@ -75,7 +99,7 @@ async function ensureStanleyDependencies() { .then((v) => v.trim()) const [major, minor] = pythonVersion.split(".").map((v) => Number(v)) const supportsOpenbb = Number.isFinite(major) && Number.isFinite(minor) ? major < 3 || (major === 3 && minor < 14) : true - const deps = supportsOpenbb ? ["openbb==4.6.0", "yfinance==0.2.50"] : ["yfinance==0.2.50"] + const deps = supportsOpenbb ? ["openbb==4.6.0", "yfinance==0.2.66"] : ["yfinance==0.2.66"] if (!fs.existsSync(constraintsPath)) { fs.writeFileSync(constraintsPath, deps.join("\n")) @@ -239,6 +263,7 @@ if (fs.existsSync(zeeRoot)) { } if (fs.existsSync(stanleyRoot)) { await ensureStanleyDependencies() + ensureStanleyRuntime() } for (const item of targets) { diff --git a/src/domain/stanley/tools.ts b/src/domain/stanley/tools.ts index 62cbdcb8c2..bbf0b377af 100644 --- a/src/domain/stanley/tools.ts +++ b/src/domain/stanley/tools.ts @@ -31,9 +31,19 @@ function resolvePersonaRepo(name: string): string { function resolveStanleyCli(): { python: string; cliPath: string; pythonPath?: string } { const repo = process.env.STANLEY_REPO || resolvePersonaRepo("stanley"); const pythonPath = process.env.STANLEY_PYTHONPATH || (existsSync(join(repo, ".python")) ? join(repo, ".python") : undefined); + const runtimePython = join(repo, ".python-runtime", "bin", "python3"); + const runtimePythonAlt = join(repo, ".python-runtime", "bin", "python3.13"); + const bundledPython = existsSync(runtimePython) + ? runtimePython + : existsSync(runtimePythonAlt) + ? runtimePythonAlt + : undefined; const cliPath = process.env.STANLEY_CLI || join(repo, "scripts", "stanley_cli.py"); const venvPython = join(repo, ".venv", "bin", "python"); - const python = process.env.STANLEY_PYTHON || (pythonPath ? "python3" : existsSync(venvPython) ? venvPython : "python3"); + const python = + process.env.STANLEY_PYTHON || + bundledPython || + (pythonPath ? "python3" : existsSync(venvPython) ? venvPython : "python3"); return { python, cliPath, pythonPath }; } diff --git a/src/mcp/servers/portfolio.ts b/src/mcp/servers/portfolio.ts index 5341f01184..70a3a1444f 100644 --- a/src/mcp/servers/portfolio.ts +++ b/src/mcp/servers/portfolio.ts @@ -36,9 +36,19 @@ function resolvePersonaRepo(name: string): string { function resolveStanleyCli(): { python: string; cliPath: string; pythonPath?: string } { const repo = process.env.STANLEY_REPO || resolvePersonaRepo("stanley"); const pythonPath = process.env.STANLEY_PYTHONPATH || (existsSync(join(repo, ".python")) ? join(repo, ".python") : undefined); + const runtimePython = join(repo, ".python-runtime", "bin", "python3"); + const runtimePythonAlt = join(repo, ".python-runtime", "bin", "python3.13"); + const bundledPython = existsSync(runtimePython) + ? runtimePython + : existsSync(runtimePythonAlt) + ? runtimePythonAlt + : undefined; const cliPath = process.env.STANLEY_CLI || join(repo, "scripts", "stanley_cli.py"); const venvPython = join(repo, ".venv", "bin", "python"); - const python = process.env.STANLEY_PYTHON || (pythonPath ? "python3" : existsSync(venvPython) ? venvPython : "python3"); + const python = + process.env.STANLEY_PYTHON || + bundledPython || + (pythonPath ? "python3" : existsSync(venvPython) ? venvPython : "python3"); return { python, cliPath, pythonPath }; }