(in-package :opencortex.skills.org-skill-architect)

(defun architect-actuate (action context)
  (declare (ignore context))
  (let* ((payload (getf action :payload))
         ;; Support both (getf action :payload) and direct top-level keys
         (note-path (or (getf payload :path) (getf action :path)))
         (blueprint-content (or (getf payload :content) (getf action :content))))
    
    (if (and note-path blueprint-content)
        (progn
          (opencortex:kernel-log "ARCHITECT - Appending PROTOCOL to ~a" note-path)
          (with-open-file (out note-path :direction :output :if-exists :append)
            (format out "~%* Phase B: Blueprint (PROTOCOL)~%:PROPERTIES:~%:STATUS: SIGNED~%:END:~%~%~a" 
                    blueprint-content))
          (format nil "SUCCESS - Architect established PROTOCOL in ~a" note-path))
        (progn
          (opencortex:kernel-log "ARCHITECT FAILURE - Missing path or content in action: ~a" action)
          nil))))
