A command is useless without knowing what to act upon. This lesson elevates your local AI script by giving it context from your project's file system. You'll learn how to find all relevant files and empower the AI to intelligently select the correct one based on your prompt.
The core technique involves using the globby package to scan for files and then feeding that list into a Zod enum. This constrains the AI's choices to a valid set of files, allowing it to accurately determine which file you're referring to in a natural language command.
Workflow demonstrated in this lesson:
- Install and import the 
globbylibrary to find files based on a pattern (e.g., all.jsonfiles). - Add a 
filePathfield to your Zod schema. - Define the 
filePathasz.enum(files), wherefilesis the array of file paths returned byglobby. - Pass a natural language prompt like "Summarize our typescript config" to the script.
 - Observe how the AI correctly identifies 
tsconfig.jsonfrom the list of available JSON files and returns it as structured data. 
This lesson is a crucial step toward building powerful, context-aware tools that can intelligently interact with your project's files based on simple, human-readable commands.
