|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | import shutil |
| 5 | +from pathlib import Path |
5 | 6 | from typing import List |
6 | 7 |
|
7 | 8 | from pydantic import Field, field_validator |
|
11 | 12 | def find_claude_binary() -> str: |
12 | 13 | """Find Claude binary path automatically.""" |
13 | 14 | # First check environment variable |
14 | | - if "CLAUDE_BINARY_PATH" in os.environ: |
15 | | - claude_path = os.environ["CLAUDE_BINARY_PATH"] |
16 | | - if os.path.exists(claude_path): |
17 | | - return claude_path |
| 15 | + env_path = os.environ.get("CLAUDE_BINARY_PATH") |
| 16 | + if env_path: |
| 17 | + path = Path(env_path) |
| 18 | + if path.exists(): |
| 19 | + return str(path) |
18 | 20 |
|
19 | | - # Try to find claude in PATH - this should work for npm global installs |
| 21 | + # Try to find claude in PATH |
20 | 22 | claude_path = shutil.which("claude") |
21 | 23 | if claude_path: |
22 | 24 | return claude_path |
23 | 25 |
|
24 | | - # Import npm environment if needed |
25 | | - try: |
26 | | - import subprocess |
27 | | - |
28 | | - # Try to get npm global bin path |
29 | | - result = subprocess.run(["npm", "bin", "-g"], capture_output=True, text=True) |
30 | | - if result.returncode == 0: |
31 | | - npm_bin_path = result.stdout.strip() |
32 | | - claude_npm_path = os.path.join(npm_bin_path, "claude") |
33 | | - if os.path.exists(claude_npm_path): |
34 | | - return claude_npm_path |
35 | | - except Exception: |
36 | | - pass |
37 | | - |
38 | | - # Fallback to common npm/nvm locations |
39 | | - import glob |
40 | | - |
41 | | - common_patterns = [ |
42 | | - "/usr/local/bin/claude", |
43 | | - "/usr/local/share/nvm/versions/node/*/bin/claude", |
44 | | - "~/.nvm/versions/node/*/bin/claude", |
45 | | - ] |
46 | | - |
47 | | - for pattern in common_patterns: |
48 | | - expanded_pattern = os.path.expanduser(pattern) |
49 | | - matches = glob.glob(expanded_pattern) |
50 | | - if matches: |
51 | | - # Return the most recent version |
52 | | - return sorted(matches)[-1] |
53 | | - |
54 | 26 | return "claude" # Final fallback |
55 | 27 |
|
56 | 28 |
|
57 | 29 | def default_project_root() -> str: |
58 | 30 | """Default project root under the current working directory.""" |
59 | | - return os.path.join(os.getcwd(), "claude_projects") |
| 31 | + return str(Path.cwd() / "claude_projects") |
60 | 32 |
|
61 | 33 |
|
62 | 34 | def default_session_map_path() -> str: |
63 | 35 | """Default path for CLI-to-API session mapping.""" |
64 | | - return os.path.join(os.getcwd(), "claude_sessions", "session_map.json") |
| 36 | + return str(Path.cwd() / "claude_sessions" / "session_map.json") |
65 | 37 |
|
66 | 38 |
|
67 | 39 | def default_log_file_path() -> str: |
68 | 40 | """Default path for application logs.""" |
69 | | - return os.path.join(os.getcwd(), "dist", "logs", "claude-code-api.log") |
| 41 | + return str(Path.cwd() / "dist" / "logs" / "claude-code-api.log") |
70 | 42 |
|
71 | 43 |
|
72 | 44 | def _is_shell_script_line(line: str) -> bool: |
|
0 commit comments