Lesson

Providing File System Context to Local AI Scripts with Globby and Zod Enums

Access
Included
Transcript
Needs source

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 globby library to find files based on a pattern (e.g., all .json files).
  • Add a filePath field to your Zod schema.
  • Define the filePath as z.enum(files), where files is the array of file paths returned by globby.
  • Pass a natural language prompt like "Summarize our typescript config" to the script.
  • Observe how the AI correctly identifies tsconfig.json from 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.