Hardcoding command logic and prompts directly into your script makes it rigid and difficult to extend. This lesson demonstrates a more flexible and powerful pattern: defining your script's commands as individual Markdown files in a dedicated directory.
This approach allows you to easily add, remove, or modify commands without touching the core script logic. You'll learn how to dynamically load these command files, present them as options to the AI, and inject the corresponding instructions into your prompt, creating a truly modular and extensible tool.
Workflow demonstrated in this lesson:
- Create a 
commandsdirectory to house your command definitions (e.g.,summarize.md,translate.md). - In each file, write the specific prompt or instructions for that command.
 - Use 
globbyto discover all available command files at runtime. - Create a 
commandMapthat maps the filename (e.g., "summarize") to its file content. - Update the Zod schema to use an 
enumof the dynamically discovered command names. - Dynamically construct the final text generation prompt by injecting the instructions from the user-selected command file.
 - Add a 
profile.mdfile to demonstrate how the script can act on user-created content with the new file-based commands. 
By the end of this lesson, your script will be architected for easy expansion, allowing you to build a robust library of custom commands simply by adding new text files.
