()
| 45 | * project root itself; we warn once to stderr so the misconfiguration is seen. |
| 46 | */ |
| 47 | export function codeGraphDirName(): string { |
| 48 | const raw = process.env.CODEGRAPH_DIR?.trim(); |
| 49 | if (!raw) return DEFAULT_CODEGRAPH_DIR; |
| 50 | const invalid = |
| 51 | raw === '.' || |
| 52 | raw.includes('..') || |
| 53 | raw.includes('/') || |
| 54 | raw.includes('\\') || |
| 55 | path.isAbsolute(raw); |
| 56 | if (invalid) { |
| 57 | if (!warnedBadDirName) { |
| 58 | warnedBadDirName = true; |
| 59 | // stderr only — stdout is the MCP protocol channel. |
| 60 | console.warn( |
| 61 | `[codegraph] Ignoring invalid CODEGRAPH_DIR="${raw}" — it must be a plain ` + |
| 62 | `directory name (no path separators, no "..", not absolute). Using "${DEFAULT_CODEGRAPH_DIR}".` |
| 63 | ); |
| 64 | } |
| 65 | return DEFAULT_CODEGRAPH_DIR; |
| 66 | } |
| 67 | return raw; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * CodeGraph directory name — a load-time snapshot of {@link codeGraphDirName}. |
no test coverage detected