From 1825ed3bcff2684266a08772cdbe97f997a9c905 Mon Sep 17 00:00:00 2001 From: catlog22 Date: Sat, 3 Jan 2026 22:41:34 +0800 Subject: [PATCH] feat: update CodexLens route to spawn watcher using Python and add getVenvPythonPath export --- ccw/src/core/routes/codexlens-routes.ts | 14 +++++++------- ccw/src/tools/codex-lens.ts | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ccw/src/core/routes/codexlens-routes.ts b/ccw/src/core/routes/codexlens-routes.ts index 21ff717d..dd1b2f01 100644 --- a/ccw/src/core/routes/codexlens-routes.ts +++ b/ccw/src/core/routes/codexlens-routes.ts @@ -20,7 +20,8 @@ import { detectGpuSupport, uninstallCodexLens, cancelIndexing, - isIndexingInProgress + isIndexingInProgress, + getVenvPythonPath } from '../../tools/codex-lens.js'; import type { ProgressInfo, GpuMode } from '../../tools/codex-lens.js'; import { loadLiteLLMApiConfig } from '../../config/litellm-api-config-manager.js'; @@ -1356,12 +1357,11 @@ export async function handleCodexLensRoutes(ctx: RouteContext): Promise return { success: false, error: 'CodexLens not installed', status: 400 }; } - // Spawn watch process (no shell: true for security) - // Use process.platform to determine if we need .cmd extension on Windows - const isWindows = process.platform === 'win32'; - const codexlensCmd = isWindows ? 'codexlens.exe' : 'codexlens'; - const args = ['watch', targetPath, '--debounce', String(debounce_ms)]; - watcherProcess = spawn(codexlensCmd, args, { + // Spawn watch process using Python (no shell: true for security) + // CodexLens is a Python package, must run via python -m codexlens + const pythonPath = getVenvPythonPath(); + const args = ['-m', 'codexlens', 'watch', targetPath, '--debounce', String(debounce_ms)]; + watcherProcess = spawn(pythonPath, args, { cwd: targetPath, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env } diff --git a/ccw/src/tools/codex-lens.ts b/ccw/src/tools/codex-lens.ts index 14eba046..d66b74f1 100644 --- a/ccw/src/tools/codex-lens.ts +++ b/ccw/src/tools/codex-lens.ts @@ -1446,6 +1446,12 @@ export { cancelIndexing, isIndexingInProgress, }; + +// Export Python path for direct spawn usage (e.g., watcher) +export function getVenvPythonPath(): string { + return VENV_PYTHON; +} + export type { GpuMode, PythonEnvInfo }; // Backward-compatible export for tests