             lt))))))
 
 (defn write-to-agenda-file
-  [deets-by-file {:keys [preamble] :as cfg} now]
-  (let [today (.toLocalDate now)
-        {:keys [triage deadlines by-day past-log]} (synthesize-agenda deets-by-file today)
-        custom-prefix (:custom-prefix cfg (constantly nil))
-        format-todo (fn [{:keys [done todo priority-cookie header] :as item}]
+  [agenda cfg]
+  (let [format-todo (fn [{:keys [done todo priority-cookie header] :as item}]
                       (format "%s%s %s%s%s"
                               (cond-> (or done todo)
                                 (= "[#C]" priority-cookie)

                    by-file (into by-file
                                  (for [file all]
                                    [file (agenda-data-for-file file today)]))]
                (write-to-agenda-file by-file cfg now)
                (log/infof "Updated at %s with %d changed files in %dms"
                           (pr-str (java.util.Date.))
                           (count all)

(defn do-once
  [{:keys [directory] :as cfg} now]
  (let [by-file (all-agenda-data directory now)]
    (write-to-agenda-file (calculate-agenda by-file cfg now) cfg)))

(defn watch
  "cfg:

  :directory        the directory containing org files
  :agenda-file      the file the agenda will be written to
  :reset-all-file   a file which, when touched, causes *all* org files
                    to be reloaded
  :refresh-file     a file which, when touched, triggers a regeneration
                    of the agenda
  :callback         (optional) function of the agenda data that is called
                    each time the agenda changes"
  [{:keys [directory reset-all-file callback] :as cfg}]
  (let [q (LinkedBlockingQueue.)]
    (run! #(.add q %) (all-org-files directory))
    (let [do-refresh-all (fn []
