(ns user (:require [clojure.tools.namespace.repl :as repl] [clojure.tools.logging :as log] [mount.core :as mount] [hawk.core :as hawk])) ;; Only reload spiceflow namespaces (repl/set-refresh-dirs "src") (defonce watcher (atom nil)) (defn start "Start the application." [] (require 'spiceflow.core) ((resolve 'spiceflow.core/-main))) (defn stop "Stop the application." [] (mount/stop)) (defn reset "Stop, reload all changed namespaces, and restart." [] (stop) (repl/refresh :after 'user/start)) (defn reload "Reload all changed namespaces without restarting." [] (repl/refresh)) (defn reload-all "Force reload all app namespaces." [] (stop) (repl/refresh-all :after 'user/start)) (defn- clj-file? [_ {:keys [file]}] (and file (.endsWith (.getName file) ".clj"))) (defn- on-file-change [_ _] (log/info "File change detected, reloading namespaces...") (log/info "Reloading workspaces...") (try (reset) (log/info "Reload complete") (catch Exception e (log/error e "Reload failed")))) (defn watch "Start watching src directory for changes and auto-reload." [] (when @watcher (hawk/stop! @watcher)) (reset! watcher (hawk/watch! [{:paths ["src"] :filter clj-file? :handler on-file-change}])) (log/info "File watcher started - will auto-reload on .clj changes")) (defn unwatch "Stop the file watcher." [] (when @watcher (hawk/stop! @watcher) (reset! watcher nil) (log/info "File watcher stopped"))) (defn go "Start the app and enable auto-reload on file changes." [] (start) (watch) :ready)