Skip to content

modly-cli: start the API with the same setup as the desktop app - #391

Merged
lightningpixel merged 2 commits into
lightningpixel:devfrom
ahgsql:fix/cli-serve-api-desktop-env
Oct 31, 2026
Merged

lightningpixel merged 2 commits into
lightningpixel:devfrom
ahgsql:fix/cli-serve-api-desktop-env

Conversation

@ahgsql

@ahgsql ahgsql commented Oct 30, 2026

Copy link
Copy Markdown

I wanted to run the backend without the desktop app and used agent.py dev ensure-server --start. It started the wrong Python.

My Modly dependencies live on another drive (dependenciesDir in settings.json points to F:\Modly\dependencies). _default_python never looked there, so it fell back to sys.executable, which is my system Python without any of the backend packages:

before: "cmd": ["C:\\Python314\\python.exe", "-m", "uvicorn", ...]
after:  "cmd": ["F:\\Modly\\dependencies\\venv\\Scripts\\python.exe", "-m", "uvicorn", ...]

Changes:

  • _default_python checks dependenciesDir/venv from settings.json before the old fallbacks (settings are now loaded before the Python is resolved).
  • The started backend gets the same env vars the Electron bridge sets: PYTHONIOENCODING=utf-8, MODLY_LLM_DIR from agentDir, and MODLY_NODE_EXECUTABLE pointing at Modly.exe when the CLI runs against an installed app. Values already in the environment are left alone.

Added two tests for this. The whole test_agent.py passes (34 tests), and I checked it for real: ensure-server --start --detach --api-dir <installed app>/resources/api brings the API up and /model/all answers.

ahgsql and others added 2 commits October 30, 2026 23:29
`dev serve-api` / `dev ensure-server --start` ignored dependenciesDir from
settings.json. If the dependencies live on another drive (mine are on F:),
the venv isn't found and it falls back to whatever Python runs the CLI,
which doesn't have the backend deps.

It now checks dependenciesDir first, and passes the env vars the Electron
bridge sets: PYTHONIOENCODING=utf-8, MODLY_LLM_DIR (agentDir) and
MODLY_NODE_EXECUTABLE (Modly.exe) for the installed app.

Added two tests; the existing ones still pass.
… the desktop bridge

The started API inherited PYTHONHOME, PYTHONPATH, VIRTUAL_ENV, CONDA_PREFIX
and the PIP_* variables of whatever shell ran the CLI. From a conda env or
an activated venv, these point Modly's venv interpreter at foreign
site-packages, or keep it from starting at all. They are now removed, the
same list Electron's cleanPythonEnv() strips.

_default_python also tried the api's dev .venv before the app's venv,
the reverse of the PythonBridge. The app's venv (dependenciesDir, then the
default dependencies folder) now comes first, the dev .venv second.
@lightningpixel
lightningpixel merged commit c34655a into lightningpixel:dev Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants