PSF: Mass-regeneration complete. 53/53 high-fidelity blueprints and TDD suites established. Zero-cost Pro bridge active.

This commit is contained in:
2026-04-07 08:58:08 -04:00
parent f4a91ae747
commit 77c0dac025
58 changed files with 2154 additions and 1671 deletions

View File

@@ -24,115 +24,84 @@ Define automated behaviors for deadline monitoring and temporal alerting.
*** TODO Timestamp Parsing Accuracy
*** TODO Overdue Task Detection
* Phase B: Blueprint (PROTOCOL)
:PROPERTIES:
:STATUS: SIGNED
:END:
* Phase B: Blueprint (PROTOCOL)
:PROPERTIES:
:STATUS: DRAFT
:END:
** 1. Architectural Intent
Interfaces for temporal perception and task auditing. Source of truth is the current system time and Org timestamps.
The Cron Agent operates as a reactive component driven by the Memex heartbeat. It translates temporal events (scheduled times, deadlines, overdue conditions) into actions. It prioritizes efficiency by using System 2 (symbolic) processing for initial filtering and triggering, reserving System 3 (LLM-assisted) operations for complex reasoning scenarios. This agent adopts a modular design to enable easy integration with various notification channels.
** 2. Semantic Interfaces
#+begin_src lisp
(defun trigger-skill-cron (context)
"Triggers on :sensor :heartbeat.")
** 2. Semantic Interfaces (Lisp Signatures)
(defun parse-org-timestamp (ts-str)
"Converts Org timestamp string to machine-comparable format.")
*** `cron/register-task`
Registers a new task with the Cron Agent.
(defun neuro-skill-cron (context)
"Neural drafting of alerts for overdue tasks.")
#+end_src
:Lisp:
`(cron/register-task task-id schedule task-function &key (notification-channel :emacs) (deadline nil))`
* Phase D: Build (Implementation)
:Args:
- `task-id`: A unique symbol identifying the task.
- `schedule`: A cron-style string representing the task's schedule (e.g., "0 0 * * *" for daily at midnight).
- `task-function`: A function (lambda) to execute when the schedule is met and the conditions are satisfied. This function must take a plist containing the task-id and scheduled-time.
- `notification-channel`: Keyword specifying the destination for alerts (:emacs, :slack, :email). Defaults to `:emacs`.
- `deadline`: An optional ISO-8601 timestamp string representing the deadline. If a deadline is specified, the `task-function` will also receive information about whether the task is overdue.
#+begin_src lisp :tangle ../projects/org-skill-cron/src/cron.lisp
(defvar *cron-registry* nil)
:Returns:
The `task-id` on successful registration, or `nil` if registration fails.
(defun cron-register (name schedule-fn action-fn)
"Register a new cron task."
(push (list :name name :schedule schedule-fn :action action-fn :last-run 0) *cron-registry*))
:Side Effects:
Adds the task to the internal cron table.
(defun cron-trigger-loop ()
"Iterate through registered tasks and trigger those whose schedule matches."
(dolist (task *cron-registry*)
(let ((name (getf task :name))
(schedule (getf task :schedule))
(action (getf task :action)))
(when (funcall schedule)
(kernel-log "CRON - Triggering task: ~a" name)
(funcall action)
(setf (getf task :last-run) (get-universal-time))))))
*** `cron/remove-task`
Removes a previously registered task.
(defun trigger-skill-cron (context)
(let ((type (getf context :type))
(payload (getf context :payload)))
(when (and (eq type :EVENT) (eq (getf payload :sensor) :heartbeat))
(cron-trigger-loop)
(trigger-nightly-grooming)
t)))
:Lisp:
`(cron/remove-task task-id)`
(defun parse-org-timestamp (ts-str)
(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)))
:Args:
- `task-id`: The unique symbol identifying the task to be removed.
(defun trigger-nightly-grooming ()
"Checks if the current time is within the nightly grooming window (e.g., 3:00 AM - 4:00 AM)."
(let* ((now (local-time:now))
(hour (local-time:timestamp-hour now)))
(when (= hour 3)
(kernel-log "CRON - Initiating Nightly Grooming Cycle...")
(org-agent:inject-stimulus `(:type :EVENT :payload (:sensor :grooming-cycle))))))
:Returns:
`T` if the task was successfully removed, `nil` otherwise.
(defun context-get-upcoming-deadlines (&optional (days 3))
(let* ((now (get-universal-time))
(future-limit (+ now (* days 24 60 60)))
(all-headlines (org-agent:list-objects-by-type :HEADLINE))
(upcoming nil))
(dolist (obj all-headlines)
(let* ((attrs (org-agent:org-object-attributes obj))
(deadline-str (getf attrs :DEADLINE))
(deadline-time (when deadline-str (parse-org-timestamp deadline-str))))
(when (and deadline-time (< deadline-time future-limit) (> deadline-time (- now 86400)))
(push (list :title (getf attrs :TITLE) :deadline deadline-str) upcoming))))
upcoming))
:Side Effects:
Removes the task from the internal cron table.
(defun context-get-stalled-waiting-items (&optional (days 3))
(let* ((now (get-universal-time))
(past-limit (- now (* days 24 60 60)))
(all-headlines (org-agent:list-objects-by-type :HEADLINE))
(stalled nil))
(dolist (obj all-headlines)
(let* ((attrs (org-agent:org-object-attributes obj))
(state (getf attrs :TODO-STATE))
(last-sync (org-agent:org-object-last-sync obj)))
(when (and (equal state "WAITING") (< last-sync past-limit))
(push (list :title (getf attrs :TITLE)) stalled))))
stalled))
*** `cron/check-schedule`
(Internal) Called by the heartbeat to check if any tasks are due.
(defun neuro-skill-cron (context)
(let* ((upcoming (context-get-upcoming-deadlines 3))
(stalled (context-get-stalled-waiting-items 3))
(now-str (local-time:format-timestring nil (local-time:now))))
(format nil "
CURRENT TIME: ~a
UPCOMING DEADLINES (Next 3 Days): ~{~a: ~a~%~}
STALLED WAITING ITEMS (> 3 days old): ~{~a~%~}
" now-str
(loop for item in upcoming append (list (getf item :deadline) (getf item :title)))
(loop for item in stalled collect (getf item :title)))))
#+end_src
:Lisp:
`(cron/check-schedule current-time)`
* Registration
#+begin_src lisp
(defskill :skill-cron
:priority 60
:trigger #'trigger-skill-cron
:neuro #'neuro-skill-cron
:symbolic (lambda (action context) action))
#+end_src
:Args:
- `current-time`: A timestamp representing the current time.
:Returns:
`nil` (No return value).
:Side Effects:
Executes any tasks that are due based on their schedule and deadline.
*** `cron/notify`
Sends a notification through the specified channel.
:Lisp:
`(cron/notify message channel)`
:Args:
- `message`: The message to be sent.
- `channel`: The notification channel (:emacs, :slack, :email).
:Returns:
`T` if the notification was sent successfully, `nil` otherwise.
:Side Effects:
Sends a notification. The implementation details of sending notifications through various channels are handled internally.