Files
memex/notes/skill-cron.org

87 lines
3.2 KiB
Org Mode

#+TITLE - Cron Scheduler Skill
#+AUTHOR - org-agent
#+SKILL_NAME - skill-cron
This skill hooks into the background heartbeat to provide autonomous temporal action, like checking for missed deadlines.
* Trigger
Triggers on every background heartbeat pulse.
#+begin_src lisp
(defun trigger-skill-cron (context)
(let ((type (getf context :type))
(payload (getf context :payload)))
(and (eq type :EVENT)
(eq (getf payload :sensor) :heartbeat))))
#+end_src
* Symbolic Pre-Processing & Neuro Prompt
System 2 parses deadlines and only wakes up the LLM if a task is actually
overdue according to the current universal time.
#+begin_src lisp
(defun parse-org-timestamp (ts-str)
"Extract year, month, and day from an Org timestamp (e.g. <2026-03-24 Tue>)
and return its universal-time representation."
(let ((match (nth-value 1 (cl-ppcre:scan-to-strings "<(\\d{4})-(\\d{2})-(\\d{2}).*>" ts-str))))
(if match
(encode-universal-time 0 0 0
(parse-integer (aref match 2))
(parse-integer (aref match 1))
(parse-integer (aref match 0)))
nil)))
(defun neuro-skill-cron (context)
"Checks for deadlines and only wakes the LLM if action is needed."
(let* ((all-tasks (org-agent:context-query-store :todo-state "TODO" :type :HEADLINE))
(now (get-universal-time))
(overdue-tasks nil))
(dolist (task all-tasks)
(let* ((attrs (org-agent:org-object-attributes task))
(deadline-str (getf attrs :DEADLINE))
(title (getf attrs :TITLE)))
(when deadline-str
(let ((deadline-time (parse-org-timestamp deadline-str)))
;; Only consider it overdue if the deadline has actually passed
(when (and deadline-time (<= deadline-time now))
(push (format nil "[~a] Was due - ~a" title deadline-str) overdue-tasks))))))
(if overdue-tasks
(let* ((all-delivery (mapcar (lambda (task)
(getf (org-agent:org-object-attributes task) :DELIVERY))
all-tasks))
;; Check if any overdue task specifically requested external delivery
(target (if (cl:some (lambda (d) (not (null d))) all-delivery) :delivery :emacs)))
(format nil "
You are the user's Executive Assistant.
The heartbeat monitor just woke you up.
The following tasks are officially OVERDUE:
~a
Draft a very short, polite alert message to the user warning them about these deadlines.
Return a Lisp plist - (:target ~a :action :message :text \"your alert\")
If target is :delivery, make the message extra concise for a phone notification.
" overdue-tasks (if (eq target :delivery) ":delivery" ":emacs")))
nil)))
#+end_src
* Symbolic Verification
Standard pass-through.
#+begin_src lisp
(defun verify-skill-cron (proposed-action context)
proposed-action)
#+end_src
* Registration
#+begin_src lisp
(defskill :skill-cron
:priority 60
:trigger #'trigger-skill-cron
:neuro #'neuro-skill-cron
:symbolic #'verify-skill-cron)
#+end_src