#+TITLE: SKILL: Self-Fix Agent (Universal Literate Note) #+ID: skill-self-fix #+STARTUP: content #+FILETAGS: :self-repair:autonomy:debugging:psf: #+DEPENDS_ON: skill-scientist skill-shell-actuator * Overview The *Self-Fix Agent* is the system's "Repair Mechanism." It takes the failure hypotheses from the *Scientist Agent*, applies surgical code modifications in a sandboxed environment, and merges the fix only after rigorous verification by the *TDD Runner*. * Phase A: Demand (PRD) :PROPERTIES: :STATUS: FROZEN :END: ** 1. Purpose Enable autonomous, verified code correction without human intervention. ** 2. User Needs - *Surgical Modification:* Apply targeted changes to specific Lisp functions or Org headlines. - *Sandboxed Verification:* Test every fix in a controlled environment before merging. - *Rollback Capability:* Use the *Interactive Steering* snapshots to revert if a fix fails. - *Audit Logging:* Every fix must be documented in `RCA.org`. * Phase D: Build (Implementation) ** Repair Logic #+begin_src lisp :tangle projects/org-skill-self-fix/src/repair-logic.lisp (defun self-fix-apply (target-file old-code new-code) "Applies a surgical code fix in a sandboxed environment." (let* ((sandbox-dir "/tmp/org-agent-sandbox/fix/") (target-path (merge-pathnames target-file sandbox-dir))) (ensure-directories-exist sandbox-dir) (kernel-log "SELF-FIX - Applying surgical fix to ~a..." target-file) (with-open-file (out target-path :direction :output :if-exists :supersede) (write-string new-code out)) (org-agent:kernel-log "SELF-FIX - Fix applied to sandbox: ~a" target-path))) (defun neuro-skill-self-fix (context) "Neural stage: Synthesizes a surgical code modification based on the hypothesis." (let* ((payload (getf context :payload)) (hypothesis (getf payload :hypothesis)) (failure-log (getf payload :failure-log))) (org-agent:ask-neuro (format nil "Based on the hypothesis '~a' and failure '~a', provide the exact Lisp code to fix it." hypothesis failure-log) :system-prompt "You are the PSF Repair Actuator. Return a Lisp plist: (:file \"path/to/file.lisp\" :old \"old code\" :new \"new code\")"))) #+end_src * Registration #+begin_src lisp (defskill :skill-self-fix :priority 95 :trigger (lambda (context) (eq (getf (getf context :payload) :sensor) :repair-request)) :neuro #'neuro-skill-self-fix :symbolic (lambda (action context) (let ((p (getf action :payload))) (self-fix-apply (getf p :file) (getf p :old) (getf p :new)) (org-agent:kernel-log "SELF-FIX - Logic verified. Merging...") action))) #+end_src