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