PSF: Stabilizing workspace after crash. Valid kernel/skill fixes.
This commit is contained in:
@@ -24,16 +24,38 @@ Enable autonomous, verified code correction without human intervention.
|
||||
* 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)))
|
||||
#+begin_src lisp :tangle ../projects/org-skill-self-fix/src/repair-logic.lisp
|
||||
(defun self-fix-replace-all (string part replacement)
|
||||
(with-output-to-string (out)
|
||||
(loop with part-length = (length part)
|
||||
for old-pos = 0 then (+ pos part-length)
|
||||
for pos = (search part string :start2 old-pos)
|
||||
do (write-string string out :start old-pos :end (or pos (length string)))
|
||||
when pos do (write-string replacement out)
|
||||
while pos)))
|
||||
|
||||
(defun self-fix-apply (action context)
|
||||
"Applies a surgical code fix directly to the target file."
|
||||
(declare (ignore context))
|
||||
(let* ((payload (getf action :payload))
|
||||
(target-file (getf payload :file))
|
||||
(old-code (getf payload :old))
|
||||
(new-code (getf payload :new)))
|
||||
(org-agent:kernel-log "SELF-FIX - Attempting surgical fix on ~a..." target-file)
|
||||
(if (uiop:file-exists-p target-file)
|
||||
(let ((content (uiop:read-file-string target-file)))
|
||||
(if (search old-code content)
|
||||
(let ((new-content (self-fix-replace-all content old-code new-code)))
|
||||
(with-open-file (out target-file :direction :output :if-exists :supersede)
|
||||
(write-string new-content out))
|
||||
(org-agent:kernel-log "SELF-FIX SUCCESS - Applied fix to ~a" target-file)
|
||||
t)
|
||||
(progn
|
||||
(org-agent:kernel-log "SELF-FIX FAILURE - Could not find old code in ~a" target-file)
|
||||
nil)))
|
||||
(progn
|
||||
(org-agent:kernel-log "SELF-FIX FAILURE - File not found: ~a" target-file)
|
||||
nil))))
|
||||
|
||||
(defun neuro-skill-self-fix (context)
|
||||
"Neural stage: Synthesizes a surgical code modification based on the hypothesis."
|
||||
@@ -41,8 +63,10 @@ Enable autonomous, verified code correction without human intervention.
|
||||
(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\")")))
|
||||
(format nil "Based on the hypothesis '~a' and failure '~a', provide the exact Lisp code to fix it.
|
||||
Return a Lisp plist: (:target :self-fix :action :apply :file \"path/to/file.lisp\" :old \"old code\" :new \"new code\")"
|
||||
hypothesis failure-log)
|
||||
:system-prompt "You are the PSF Repair Actuator. You MUST return ONLY a Lisp plist.")))
|
||||
#+end_src
|
||||
|
||||
* Registration
|
||||
@@ -51,9 +75,5 @@ Enable autonomous, verified code correction without human intervention.
|
||||
: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)))
|
||||
:symbolic #'self-fix-apply)
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user