name: file-editing
description: Navigate a small codebase and make a targeted edit
prompt: |
  The User struct in user.rs is missing a display_name() method.
  Add a method that returns the full name formatted as "first_name last_name".

tags:
  - file-editing
  - code-navigation

setup:
  Cargo.toml: |
    [package]
    name = "user-service"
    version = "0.1.0"
    edition = "2021"

    [workspace]

  src/main.rs: |
    mod models;
    mod utils;

    use models::user::User;

    fn main() {
        let user = User::new("Alice", "Smith", "alice@example.com");
        println!("Created user: {}", user.email());
    }

  src/models/mod.rs: |
    pub mod user;

  src/models/user.rs: |
    pub struct User {
        first_name: String,
        last_name: String,
        email: String,
    }

    impl User {
        pub fn new(first_name: &str, last_name: &str, email: &str) -> Self {
            Self {
                first_name: first_name.to_string(),
                last_name: last_name.to_string(),
                email: email.to_string(),
            }
        }

        pub fn email(&self) -> &str {
            &self.email
        }

        pub fn first_name(&self) -> &str {
            &self.first_name
        }

        pub fn last_name(&self) -> &str {
            &self.last_name
        }
    }

  src/utils/mod.rs: |
    pub mod formatting;

  src/utils/formatting.rs: |
    pub fn capitalize(s: &str) -> String {
        let mut chars = s.chars();
        match chars.next() {
            None => String::new(),
            Some(c) => c.to_uppercase().collect::<String>() + chars.as_str(),
        }
    }

validate:
  # The edit was made to the correct file
  - type: file_exists
    path: src/models/user.rs
    name: user.rs exists
  # Method was added
  - type: file_matches
    path: src/models/user.rs
    regex: "fn\\s+display_name"
    name: display_name() added
  # Method returns a String or &str
  - type: file_matches
    path: src/models/user.rs
    regex: "display_name.*->.*String|display_name.*->.*str"
    name: has return type
  # Original code preserved
  - type: file_contains
    path: src/models/user.rs
    pattern: "pub fn email"
    name: email() preserved
  - type: file_contains
    path: src/models/user.rs
    pattern: "pub fn first_name"
    name: first_name() preserved
  # Other files untouched
  - type: file_exists
    path: src/main.rs
    name: main.rs exists
  - type: file_contains
    path: src/main.rs
    pattern: "mod models"
    name: main.rs unchanged
  # Code compiles
  - type: command_succeeds
    command: "cargo build"
    name: cargo build
