Files
memex/system/skills/org-skill-task-integrity.org

5.4 KiB

SKILL: Task Integrity Agent (GTD Guardian)

Overview

The Task Integrity Agent is the "Guardian" of the GTD system within the Memex. It ensures that all task transitions adhere to the semantic rules of org-gtd v4.0, preventing logical inconsistencies in the user's workload and maintaining the structural health of the task hierarchy.

The Integrity Mandate

  1. Semantic Enforcement: Tasks must move through valid states (Active vs. Resolved) based on their hierarchical context.
  2. Dependency Awareness: A parent task MUST NOT be closed if it still contains active children or unfulfilled dependencies.
  3. Proactive Assistance: The agent provides "peripheral vision" by suggesting the next logical action based on recent momentum and active projects.
  4. Fidelity: Automated refactoring must preserve all task metadata (IDs, properties) during state transitions.

Symbolic Implementation (The Logic)

The implementation focuses on the deterministic verification of task states and their relationships.

Architectural Intent: Buffer Perception

Triggers on any buffer update, ensuring that the integrity logic is engaged whenever the user modifies their tasks.

(defun trigger-skill-task-integrity (context)
  (let ((type (getf context :type))
        (payload (getf context :payload)))
    (and (eq type :EVENT)
         (eq (getf payload :sensor) :buffer-update))))

Architectural Intent: Neuro-Cognitive EA Support

The neural layer acts as an Executive Assistant, analyzing the user's recent "wins" and active projects to suggest the most impactful next step, providing momentum in the face of a large backlog.

(defun neuro-skill-task-integrity (context)
  "Generate a System 1 prompt by gathering relevant facts from the Object Store."
  (let ((recent-wins (org-agent:context-get-recent-completed-tasks))
        (projects (org-agent:context-get-active-projects)))
    ;; We construct a rich, human-readable prompt that describes the user's
    ;; current reality, momentum, and the latest event.
    (format nil "
      You are the user's Executive Assistant managing their Org-mode GTD system.      
      CURRENT MOMENTUM (Recently DONE) - ~a
      ACTIVE PROJECTS - ~a
      
      NEW EVENT - ~a
      
      Suggest the next logical Org-mode action.
      Provide concise, high-fidelity suggestions in Lisp plist format.
      You MUST include :target :emacs in your top-level plist if you intend to execute an action.
    " recent-wins projects context)))

Architectural Intent: Symbolic State Mapping

This utility maps raw Org-mode keywords to their semantic categories within the PSF/GTD framework, enabling high-level reasoning about "active" vs "resolved" work.

(defun semantic-state-category (state)
  "Map a keyword state to its org-gtd v4.0 semantic category."
  (let ((s (string-upcase (or state ""))))
    (cond
     ((member s '("TODO" "NEXT" "WAIT") :test #'string=) :active)
     ((member s '("DONE" "CNCL" "CANCELED") :test #'string=) :resolved)
     (t :unknown))))

Architectural Intent: Hierarchical Dependency Check

Ensures that the "Knuth-Sovereign" principle is upheld: no node can be considered complete if its constituents are still in flux.

(defun has-active-children-p (parent-id)
  "Recursively check if a node has any children in an :active semantic state."
  (let ((parent (org-agent:lookup-object parent-id)))
    (when parent
      (cl:some (lambda (child-id)
                 (let* ((child (org-agent:lookup-object child-id))
                        (state (getf (org-agent:org-object-attributes child) :TODO-STATE)))
                   (or (eq (semantic-state-category state) :active)
                       (has-active-children-p child-id))))
               (org-agent:org-object-children parent)))))

Architectural Intent: Symbolic Gatekeeping (System 2)

The ultimate authority on task state. It inspects proposed neural actions and blocks any attempt to close a task that has active children, effectively enforcing the system's logical integrity.

(defun verify-skill-task-integrity (proposed-action context)
  "The System 2 gatekeeper for task consistency. 
   Ensures parent tasks cannot be closed if children are still active."
  (let* ((payload (getf proposed-action :payload))
         (action (getf payload :action))
         (target-id (getf payload :target-id))
         (props (getf payload :properties))
         (new-state (cdr (assoc :TODO-STATE props))))
    
    ;; If the proposal attempts to transition a node to a :resolved state
    (if (and (eq action :refactor-subtree)
             target-id
             (eq (semantic-state-category new-state) :resolved))
        
        ;; Verify that all hierarchical dependencies are met
        (if (has-active-children-p target-id)
            (progn
              (format t "System 2 [skill-task-integrity] - BLOCKED transition of ~a to ~a. Active children remain.~%" target-id new-state)
              nil) ; Return NIL to block the illegal state change
            proposed-action)
        
        ;; Allow all other actions (e.g., TODO -> NEXT, or simple property updates)
        proposed-action)))

Registration

(defskill :skill-task-integrity
  :priority 50
  :trigger #'trigger-skill-task-integrity
  :neuro #'neuro-skill-task-integrity
  :symbolic #'verify-skill-task-integrity)