{"record":{"id":"22f50b045d94ff52","repo":"nikivdev/code","slug":"ai-not-found-in-path","errorCode":null,"errorMessage":"ai not found in PATH","messagePattern":"ai not found in PATH","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":475,"sourceCode":"    let agent_name =\n        env::var(\"FLOW_FIX_COMMIT_AGENT\").unwrap_or_else(|_| \"fix-f-commit\".to_string());\n    let handoff_enabled = agent_name.trim().to_lowercase() != \"off\";\n    let ai_available = which::which(\"ai\").is_ok();\n    if !handoff_enabled && !ai_available {\n        return Ok(false);\n    }\n\n    git_run(&[\"add\", \".\"])?;\n    ensure_no_internal_staged(repo_root)?;\n    ensure_no_unwanted_staged(repo_root)?;\n    gitignore_policy::enforce_staged_policy(repo_root)?;\n\n    Ok(!scan_diff_for_secrets(repo_root).is_empty())\n}\n\nfn run_fix_f_commit_ai(repo_root: &Path, task: &str) -> Result<()> {\n    if which::which(\"ai\").is_err() {\n        bail!(\"ai not found in PATH\");\n    }\n\n    let status = Command::new(\"ai\")\n        .args([\"--prompt\", task])\n        .current_dir(repo_root)\n        .stdin(Stdio::inherit())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .context(\"failed to run ai\")?;\n\n    if !status.success() {\n        bail!(\"ai auto-fix failed\");\n    }\n\n    Ok(())\n}\n","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L457-L493","documentation":"This error is raised by `run_fix_f_commit_ai` when the external `ai` CLI executable cannot be located on PATH via `which::which(\"ai\")`. The library depends on this external tool to perform AI-assisted secret redaction and aborts the fix flow early with a clear message rather than failing mid-execution.","triggerScenarios":"`warn_secrets_in_diff` selects the AI fix path (interactive TTY, FLOW_FIX_COMMIT_AGENT enabled) and calls `run_fix_f_commit_ai`, but the `ai` binary is not installed or not on the PATH of the current process.","commonSituations":"AI CLI never installed; installed in a user-local bin dir (e.g. ~/.local/bin, ~/.cargo/bin) missing from PATH; running the commit tool from an IDE terminal, cron, or CI where PATH differs from the interactive shell; the tool named differently after a version change.","solutions":["Install the `ai` CLI (e.g. via your package manager or its official installer).","Ensure its install directory is on PATH: `export PATH=\"$HOME/.local/bin:$PATH\"` and verify with `which ai`.","If you do not want AI fixing, set `FLOW_FIX_COMMIT_AGENT=off` and fix the findings manually instead.","Run the commit flow from a shell where `which ai` succeeds."],"exampleFix":"// before: command not found\n// $ flow commit ...\n// Error: ai not found in PATH\n// after\nexport PATH=\"$HOME/.local/bin:$PATH\"\nwhich ai  # /home/user/.local/bin/ai","handlingStrategy":"fallback","validationCode":"// check availability before entering the AI fix path\nif which::which(\"ai\").is_err() {\n    eprintln!(\"ai CLI missing; fix findings manually or install it\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"match run_fix_f_commit_ai(repo_root, task) {\n    Err(e) if e.to_string().contains(\"ai not found in PATH\") => {\n        // fallback: remediate manually instead of the AI path\n        eprintln!(\"falling back to manual redaction of findings\");\n    }\n    Err(e) => return Err(e),\n    Ok(_) => {}\n}","preventionTips":["Install the ai CLI and verify with `which ai` before scripted commits","Add its install dir (~/.local/bin, ~/.cargo/bin) to PATH in shell profiles and CI","Use FLOW_FIX_COMMIT_AGENT=off as a supported fallback when the CLI is unavailable","Prefer explicit `git add <file>` in automation to avoid entering the interactive fix path"],"tags":["environment","cli","path","dependency"],"backgroundTag":"command-not-found-on-path","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}