// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617use crate::Logger;18use anyhow::{Error, anyhow};19use std::fs::OpenOptions;20use std::io::Write;21use std::path::Path;2223const RULES_CONTENT: &str = include_str!("resources/rules.md");2425/// Writes the Selenium LLM rules file to the given path, creating parent directories as needed.26///27/// # Arguments28/// * `path` - Destination file path (e.g. `rules/selenium.md`)29/// * `log` - Logger instance30///31/// # Errors32/// Returns an error if the file already exists or cannot be written.33pub fn write_rules_file(path: &Path, log: &Logger) -> Result<(), Error> {34log.debug(format!("Creating rules file at: {}", path.display()));35if path.exists() {36return Err(anyhow!(37"The file {} already exists. Please remove it or choose a different location.",38path.display()39));40}41if let Some(parent) = path.parent() {42if !parent.exists() {43log.debug(format!("Creating directory: {}", parent.display()));44std::fs::create_dir_all(parent)?;45}46}47let mut file = OpenOptions::new().write(true).create_new(true).open(path)?;48file.write_all(RULES_CONTENT.as_bytes())?;49Ok(())50}515253