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