Files
memex/notes/org-skill-self-fix.org

2.6 KiB

SKILL: Self-Fix Agent (Universal Literate Note)

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)

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

(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\")")))

Registration

(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)))