{"record":{"id":"e501d44e0ebff0ee","repo":"JuliusBrussee/caveman","slug":"kilo-config-root-resolves-to-an-empty-path","errorCode":null,"errorMessage":"Kilo config root resolves to an empty path","messagePattern":"Kilo config root resolves to an empty path","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":11161,"sourceCode":"\n// Kilo 7.5.6's native config writer targets KILO_CONFIG_DIR when present. That\n// directory is also loaded after KILO_CONFIG, so it must win for effective MCP\n// ownership. Explicit KILO_CONFIG wins only without a custom config directory;\n// xdg-basedir is the final fallback.\nfunction kiloConfigLocation(): KiloConfigLocation {\n  const configuredDirectory = process.env.KILO_CONFIG_DIR;\n  if (configuredDirectory) {\n    return kiloConfigInDirectory(kiloPathFromEnv(configuredDirectory, \"KILO_CONFIG_DIR\"), \"KILO_CONFIG_DIR\");\n  }\n  const explicit = process.env.KILO_CONFIG;\n  if (explicit) {\n    const path = kiloPathFromEnv(explicit, \"KILO_CONFIG\");\n    return { path, jsonc: extname(path).toLowerCase() === \".jsonc\", source: \"KILO_CONFIG\" };\n  }\n  // Pinned Kilo strips accidental newlines from xdg-basedir output before use.\n  const configuredRoot = process.env.XDG_CONFIG_HOME || join(homedir(), \".config\");\n  const cleanedRoot = configuredRoot.replace(/[\\r\\n]+/g, \"\");\n  if (!cleanedRoot) throw new Error(\"Kilo config root resolves to an empty path\");\n  const root = normalize(isAbsolute(cleanedRoot) ? cleanedRoot : resolve(cleanedRoot));\n  return kiloConfigInDirectory(join(root, \"kilo\"), \"XDG_CONFIG_HOME\");\n}\n\nfunction kiloConfigPath(): string {\n  return kiloConfigLocation().path;\n}\n\nfunction kiloMcpEntry(mcp: { command: string; args: string[] }): Record<string, unknown> {\n  return {\n    type: \"local\",\n    command: [mcp.command, ...mcp.args],\n    enabled: true,\n  };\n}\n\nfunction kiloMcpEntryMatches(value: unknown, mcp: { command: string; args: string[] }): boolean {\n  if (!value || typeof value !== \"object\" || Array.isArray(value)) return false;","sourceCodeStart":11143,"sourceCodeEnd":11179,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L11143-L11179","documentation":"When KILO_CONFIG is unset, the CLI derives Kilo's config root from XDG_CONFIG_HOME (or ~/.config), mimicking pinned Kilo behavior of stripping accidental newlines from xdg-basedir output. If, after stripping CR/LF, the root is an empty string, it throws rather than resolving against a meaningless path.","triggerScenarios":"Running a Kilo-related command with XDG_CONFIG_HOME exported as only whitespace/newline characters (e.g. `XDG_CONFIG_HOME=$'\\n'`), or an env source that produced an empty-after-cleanup value, while KILO_CONFIG is unset.","commonSituations":"CI pipelines exporting XDG_CONFIG_HOME from a template variable left empty; shell rc files setting XDG_CONFIG_HOME=\"\" or with accidental line continuations; direnv files with broken interpolation.","solutions":["Unset XDG_CONFIG_HOME so the CLI falls back to ~/.config: `unset XDG_CONFIG_HOME`","Set it to a real absolute directory: `export XDG_CONFIG_HOME=\"$HOME/.config\"`","Fix the rc/CI file that emits a newline-only value"],"exampleFix":"// before\nexport XDG_CONFIG_HOME=\"\"\ncaveman kilo ...\n// after\nunset XDG_CONFIG_HOME   # or:\nexport XDG_CONFIG_HOME=\"$HOME/.config\"","handlingStrategy":"validation","validationCode":"const xdg = process.env.XDG_CONFIG_HOME?.replace(/[\\r\\n]+/g, \"\");\nif (xdg !== undefined && !xdg) throw new Error(\"XDG_CONFIG_HOME is empty/newline-only; unset it or set a real path\");","typeGuard":"function isValidXdgRoot(v: string | undefined): boolean {\n  const cleaned = v?.replace(/[\\r\\n]+/g, \"\") ?? \"\";\n  return cleaned === \"\" || isAbsolute(cleaned);\n}","tryCatchPattern":"try {\n  await kiloCommand();\n} catch (e) {\n  if ((e as Error).message.includes(\"config root resolves to an empty path\")) {\n    delete process.env.XDG_CONFIG_HOME; // fall back to ~/.config, retry\n    await kiloCommand();\n  } else throw e;\n}","preventionTips":["Either unset XDG_CONFIG_HOME or set it to an absolute directory — never empty","Guard CI/templated exports: skip the export when the template value is blank","Audit shell rc/direnv files for broken interpolations into XDG variables"],"tags":["env-var","xdg","config"],"backgroundTag":"invalid-env-var-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}