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