Skip to content

feat: mds watch command (file watcher with auto-recompile) #57

@dean0x

Description

@dean0x

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

  • mds watch <file> recompiles on save
  • Import dependencies are tracked and trigger recompilation
  • Errors are displayed without exiting watch mode
  • All mds build output options work with mds watch
  • Ctrl+C exits cleanly
  • --clear flag clears terminal between rebuilds
  • Debouncing prevents duplicate compilations

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliCLI commands and optionsenhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions