Files
memex/notes/org-skill-ast-normalization.org

2.6 KiB

SKILL: AST Normalization Agent (Universal Literate Note)

Overview

The AST Normalization Agent maintains the structural integrity of the Org-mode Abstract Syntax Tree. It ensures all nodes adhere to strict metadata requirements and handles deterministic refactoring.

Phase A: Demand (PRD)

1. Purpose

Define automated structural enforcement and refactoring for the Org AST.

2. User Needs

  • Structural Enforcement: Mandatory unique IDs for all headlines.
  • Deterministic Preemption: Symbolic verification must override neural suggestions if errors exist.
  • Fidelity: Preservation of content during metadata normalization.

3. Success Criteria

TODO ID Injection

TODO Neural Preemption

TODO Subtree Refactoring Verification

Phase B: Blueprint (PROTOCOL)

1. Architectural Intent

Interfaces for AST inspection and transformation. Operates as a "Safety Gate" in the Consensus Loop.

2. Semantic Interfaces

(defun trigger-skill-ast-normalization (context)
  "Triggers on :user-command :organize-subtree.")

(defun verify-skill-ast-normalization (proposed-action context)
  "Symbolic check for missing IDs and mandatory properties.")

(defun find-headline-missing-id (ast)
  "Recursive scan of AST for headlines without IDs.")

Phase D: Build (Implementation)

Trigger Perception

(defun trigger-skill-ast-normalization (context)
  (let ((type (getf context :type))
        (payload (getf context :payload)))
    (and (eq type :EVENT)
         (eq (getf payload :sensor) :user-command)
         (eq (getf payload :command) :organize-subtree))))

Symbolic Verification (System 2)

(defun verify-skill-ast-normalization (proposed-action context)
  (let* ((ast (getf (getf context :payload) :ast))
         (missing-id (find-headline-missing-id ast)))
    (if missing-id
        `(:type :REQUEST :target :emacs
          :payload (:action :refactor-subtree 
                    :properties (("ID" . ,(org-id-new)))))
        proposed-action)))

Registration

(defskill :skill-ast-normalization
  :priority 100
  :trigger #'trigger-skill-ast-normalization
  :neuro #'neuro-skill-ast-normalization
  :symbolic #'verify-skill-ast-normalization)