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

79 lines
2.6 KiB
Org Mode

#+TITLE: SKILL: AST Normalization Agent (Universal Literate Note)
#+ID: skill-ast-normalization
#+STARTUP: content
#+FILETAGS: :ast:normalization:integrity:psf:
* 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)
:PROPERTIES:
:STATUS: FROZEN
:END:
** 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)
:PROPERTIES:
:STATUS: SIGNED
:END:
** 1. Architectural Intent
Interfaces for AST inspection and transformation. Operates as a "Safety Gate" in the Consensus Loop.
** 2. Semantic Interfaces
#+begin_src lisp
(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.")
#+end_src
* Phase D: Build (Implementation)
** Trigger Perception
#+begin_src lisp :tangle projects/org-skill-ast-normalization/src/normalization-logic.lisp
(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))))
#+end_src
** Symbolic Verification (System 2)
#+begin_src lisp :tangle projects/org-skill-ast-normalization/src/normalization-logic.lisp
(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)))
#+end_src
* Registration
#+begin_src lisp
(defskill :skill-ast-normalization
:priority 100
:trigger #'trigger-skill-ast-normalization
:neuro #'neuro-skill-ast-normalization
:symbolic #'verify-skill-ast-normalization)
#+end_src