|
27 | 27 | */ |
28 | 28 |
|
29 | 29 | const { execSync } = require("child_process"); |
| 30 | +const fs = require("fs"); |
30 | 31 | const path = require("path"); |
31 | 32 | const { createEditorMcpServer } = require("./mcp-editor-tools"); |
32 | 33 |
|
| 34 | +const isWindows = process.platform === "win32"; |
| 35 | + |
33 | 36 | const CONNECTOR_ID = "ph_ai_claude"; |
34 | 37 |
|
35 | 38 | const CLARIFICATION_HINT = |
@@ -71,9 +74,45 @@ async function getQueryFn() { |
71 | 74 | } |
72 | 75 |
|
73 | 76 | /** |
74 | | - * Find the user's globally installed Claude CLI, skipping node_modules copies. |
| 77 | + * Find the user's globally installed Claude CLI on Windows. |
75 | 78 | */ |
76 | | -function findGlobalClaudeCli() { |
| 79 | +function _findGlobalClaudeCliWin() { |
| 80 | + const userHome = process.env.USERPROFILE || process.env.HOME || ""; |
| 81 | + const locations = [ |
| 82 | + path.join(userHome, ".local", "bin", "claude.exe"), |
| 83 | + path.join(process.env.APPDATA || "", "npm", "claude.cmd"), |
| 84 | + path.join(process.env.LOCALAPPDATA || "", "Programs", "claude", "claude.exe") |
| 85 | + ]; |
| 86 | + |
| 87 | + // Try 'where claude' first to find claude in PATH |
| 88 | + try { |
| 89 | + const allPaths = execSync("where claude", { encoding: "utf8" }) |
| 90 | + .trim() |
| 91 | + .split("\r\n") |
| 92 | + .filter(p => p && !p.includes("node_modules")); |
| 93 | + if (allPaths.length > 0) { |
| 94 | + console.log("[Phoenix AI] Found global Claude CLI at:", allPaths[0]); |
| 95 | + return allPaths[0]; |
| 96 | + } |
| 97 | + } catch { |
| 98 | + // where failed, try manual locations |
| 99 | + } |
| 100 | + |
| 101 | + // Check common Windows locations |
| 102 | + for (const loc of locations) { |
| 103 | + if (loc && fs.existsSync(loc)) { |
| 104 | + console.log("[Phoenix AI] Found global Claude CLI at:", loc); |
| 105 | + return loc; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + return null; |
| 110 | +} |
| 111 | + |
| 112 | +/** |
| 113 | + * Find the user's globally installed Claude CLI on macOS/Linux. |
| 114 | + */ |
| 115 | +function _findGlobalClaudeCliLinuxMac() { |
77 | 116 | const locations = [ |
78 | 117 | "/usr/local/bin/claude", |
79 | 118 | "/usr/bin/claude", |
@@ -108,10 +147,20 @@ function findGlobalClaudeCli() { |
108 | 147 | } |
109 | 148 | } |
110 | 149 |
|
111 | | - console.log("[Phoenix AI] Global Claude CLI not found"); |
112 | 150 | return null; |
113 | 151 | } |
114 | 152 |
|
| 153 | +/** |
| 154 | + * Find the user's globally installed Claude CLI, skipping node_modules copies. |
| 155 | + */ |
| 156 | +function findGlobalClaudeCli() { |
| 157 | + const claudePath = isWindows ? _findGlobalClaudeCliWin() : _findGlobalClaudeCliLinuxMac(); |
| 158 | + if (!claudePath) { |
| 159 | + console.log("[Phoenix AI] Global Claude CLI not found"); |
| 160 | + } |
| 161 | + return claudePath; |
| 162 | +} |
| 163 | + |
115 | 164 | /** |
116 | 165 | * Check whether Claude CLI is available. |
117 | 166 | * Called from browser via execPeer("checkAvailability"). |
|
0 commit comments