Skip to main content

find_bean_file

Function find_bean_file 

Source
pub fn find_bean_file(beans_dir: &Path, id: &str) -> Result<PathBuf>
Expand description

Find a bean file by ID, supporting both new and legacy naming conventions.

Searches for bean files in this order:

  1. New format: {id}-{slug}.md (e.g., “1-my-task.md”, “11.1-refactor-parser.md”)
  2. Legacy format: {id}.yaml (e.g., “1.yaml”, “11.1.yaml”)

Returns the full path if found.

§Examples

  • find_bean_file(beans_dir, "1").beans/1-my-task.md or .beans/1.yaml
  • find_bean_file(beans_dir, "11.1").beans/11.1-refactor-parser.md or .beans/11.1.yaml

§Arguments

  • beans_dir - Path to the .beans/ directory
  • id - The bean ID to find (e.g., “1”, “11.1”, “3.2.1”)

§Errors

  • If the ID is invalid (empty, contains path traversal, etc.)
  • If no bean file is found for the given ID
  • If glob pattern matching fails