chrometools-mcp 1.8.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,87 +0,0 @@
1
- /**
2
- * utils/project-detector.js
3
- *
4
- * Utilities for detecting the current project root directory.
5
- * Uses cascade strategy: env variables → Git root → cwd fallback
6
- */
7
-
8
- import { execSync } from 'child_process';
9
- import path from 'path';
10
-
11
- /**
12
- * Find Git repository root from a starting path
13
- * @param {string} startPath - Path to start searching from
14
- * @returns {string|null} - Git root path or null if not in a Git repository
15
- */
16
- function findGitRoot(startPath = process.cwd()) {
17
- try {
18
- const root = execSync('git rev-parse --show-toplevel', {
19
- cwd: startPath,
20
- encoding: 'utf-8',
21
- stdio: ['pipe', 'pipe', 'ignore'] // Suppress stderr
22
- }).trim();
23
-
24
- // Normalize path separators for Windows
25
- return path.normalize(root);
26
- } catch {
27
- // Not in a Git repository or git command not available
28
- return null;
29
- }
30
- }
31
-
32
- /**
33
- * Detect project root directory using cascade strategy
34
- *
35
- * Priority:
36
- * 1. CLAUDE_PROJECT_DIR environment variable
37
- * 2. PROJECT_DIR environment variable (custom)
38
- * 3. Git repository root
39
- * 4. Current working directory (fallback)
40
- *
41
- * @returns {string} - Detected project root path
42
- */
43
- export function detectProjectRoot() {
44
- // 1. Try CLAUDE_PROJECT_DIR (Claude Code specific)
45
- if (process.env.CLAUDE_PROJECT_DIR) {
46
- const claudeDir = path.normalize(process.env.CLAUDE_PROJECT_DIR);
47
- console.log('[chrometools-mcp] Project root from CLAUDE_PROJECT_DIR:', claudeDir);
48
- return claudeDir;
49
- }
50
-
51
- // 2. Try PROJECT_DIR (custom env variable)
52
- if (process.env.PROJECT_DIR) {
53
- const projectDir = path.normalize(process.env.PROJECT_DIR);
54
- console.log('[chrometools-mcp] Project root from PROJECT_DIR:', projectDir);
55
- return projectDir;
56
- }
57
-
58
- // 3. Try Git root
59
- const gitRoot = findGitRoot();
60
- if (gitRoot) {
61
- console.log('[chrometools-mcp] Project root from Git:', gitRoot);
62
- return gitRoot;
63
- }
64
-
65
- // 4. Fallback to current working directory
66
- const cwd = process.cwd();
67
- console.log('[chrometools-mcp] Project root fallback to cwd:', cwd);
68
- return cwd;
69
- }
70
-
71
- /**
72
- * Get scenarios directory path from base directory
73
- * @param {string} baseDir - Base directory
74
- * @returns {string} - Path to scenarios directory
75
- */
76
- export function getScenariosDir(baseDir) {
77
- return path.join(baseDir, 'scenarios');
78
- }
79
-
80
- /**
81
- * Get secrets directory path from base directory
82
- * @param {string} baseDir - Base directory
83
- * @returns {string} - Path to secrets directory
84
- */
85
- export function getSecretsDir(baseDir) {
86
- return path.join(baseDir, 'secrets');
87
- }