Summary
Add an mds watch command that monitors .mds files for changes and automatically recompiles on save. Essential for iterative prompt development workflows.
Motivation
Prompt engineering is an iterative process — edit template, compile, review output, repeat. Currently users must manually run mds build after every edit. A watch mode removes this friction and enables a live-preview workflow when combined with a Markdown viewer.
Proposed CLI
mds watch template.mds # Watch single file + its imports
mds watch template.mds -o output.md # Auto-recompile to specific output
mds watch . # Watch all .mds files in directory
mds watch template.mds --vars vars.json # With runtime variables
mds watch template.mds --set name=Alice # With --set overrides
mds watch template.mds --clear # Clear terminal before each rebuild
Design Considerations
- Dependency tracking: When
a.mds imports b.mds, changes to b.mds should trigger recompilation of a.mds. The CompileOutput.dependencies field already provides the import graph.
- Debouncing: File writes often produce multiple filesystem events — debounce with a ~100ms window
- Error display: On compilation error, print the diagnostic to stderr but keep watching (don't exit). On next successful compile, clear the error.
- Performance: For single-file watch, use OS-native file watching (inotify/kqueue/ReadDirectoryChanges). For directory watch, use recursive watching with
.mds extension filter.
- Signal handling: Ctrl+C exits cleanly
- Rust crate:
notify is the standard cross-platform file watcher
- Output format: Reuse all
mds build output resolution logic (stdout, -o, --out-dir)
- mds.json integration:
watch respects build.output_dir from project config
Acceptance Criteria
Summary
Add an
mds watchcommand that monitors.mdsfiles for changes and automatically recompiles on save. Essential for iterative prompt development workflows.Motivation
Prompt engineering is an iterative process — edit template, compile, review output, repeat. Currently users must manually run
mds buildafter every edit. A watch mode removes this friction and enables a live-preview workflow when combined with a Markdown viewer.Proposed CLI
Design Considerations
a.mdsimportsb.mds, changes tob.mdsshould trigger recompilation ofa.mds. TheCompileOutput.dependenciesfield already provides the import graph..mdsextension filter.notifyis the standard cross-platform file watchermds buildoutput resolution logic (stdout,-o,--out-dir)watchrespectsbuild.output_dirfrom project configAcceptance Criteria
mds watch <file>recompiles on savemds buildoutput options work withmds watch--clearflag clears terminal between rebuilds