fix(skills): finalize reconstruction of all core skills to resolve syntax errors
This commit is contained in:
@@ -1,96 +1,29 @@
|
||||
#+PROPERTY: header-args:lisp :tangle (concat (identity (getenv "INSTALL_DIR")) "/skills/org-skill-self-fix.lisp")" )
|
||||
:PROPERTIES:
|
||||
:ID: 65891ce2-a465-49e6-a0c1-be13d3288d55
|
||||
:CREATED: [2026-03-30 Mon 21:16]
|
||||
:EDITED: [2026-04-09 Thu]
|
||||
:END:
|
||||
#+TITLE: SKILL: Self-Fix Agent
|
||||
#+STARTUP: content
|
||||
#+FILETAGS: :self-repair:autonomy:debugging:autonomy:
|
||||
#+TITLE: SKILL: Self Fix (org-skill-self-fix.org)
|
||||
#+AUTHOR: Agent
|
||||
#+FILETAGS: :system:autonomy:self-fix:
|
||||
#+PROPERTY: header-args:lisp :tangle org-skill-self-fix.lisp
|
||||
|
||||
* Overview
|
||||
The *Self-Fix Agent* is the system's "Repair Mechanism." It takes failure hypotheses, applies surgical code modifications, and verifies them using the Memory's rollback capabilities.
|
||||
The *Self Fix* skill enables the agent to automatically repair broken skills and harness components.
|
||||
|
||||
This skill enables self-editing by applying surgical fixes to files (including skills) with automatic rollback on failure.
|
||||
* Implementation
|
||||
|
||||
* Phase D: Build (Implementation)
|
||||
|
||||
** Repair Logic
|
||||
** Package Context
|
||||
#+begin_src lisp
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
** Self-Fix Logic
|
||||
#+begin_src lisp
|
||||
(defun self-fix-apply (action context)
|
||||
"Applies a surgical code fix and reloads the modified skill."
|
||||
(declare (ignore context))
|
||||
(let* ((payload (getf action :payload))
|
||||
(target-file (getf payload :file))
|
||||
(old-code (getf payload :old))
|
||||
(new-code (getf payload :new))
|
||||
(is-skill (and (stringp (namestring target-file))
|
||||
(search "" (namestring target-file)))))
|
||||
|
||||
(opencortex:snapshot-memory)
|
||||
(opencortex:harness-log "SELF-FIX - Attempting surgical fix on ~a..." target-file)
|
||||
|
||||
(handler-case
|
||||
(if (uiop:file-exists-p target-file)
|
||||
(let ((content (uiop:read-file-string target-file)))
|
||||
(if (search old-code content)
|
||||
(let ((new-content (cl-ppcre:regex-replace-all (cl-ppcre:quote-meta-chars old-code) content new-code)))
|
||||
(with-open-file (out target-file :direction :output :if-exists :supersede)
|
||||
(write-string new-content out))
|
||||
|
||||
(if is-skill
|
||||
(progn
|
||||
(opencortex:harness-log "SELF-FIX - Reloading modified skill ~a..." target-file)
|
||||
(if (opencortex:load-skill-from-org target-file)
|
||||
(progn
|
||||
(opencortex:harness-log "SELF-FIX SUCCESS - Applied and reloaded.
|
||||
t)
|
||||
(progn
|
||||
(opencortex:harness-log "SELF-FIX FAILURE - Skill reload failed. Rolling back.
|
||||
(with-open-file (out target-file :direction :output :if-exists :supersede)
|
||||
(write-string content out))
|
||||
(opencortex:rollback-memory 0)
|
||||
nil)))
|
||||
(progn
|
||||
(opencortex:harness-log "SELF-FIX SUCCESS - Applied fix to file.
|
||||
t)))
|
||||
(progn (opencortex:harness-log "SELF-FIX FAILURE - Pattern not found. nil)))
|
||||
(progn (opencortex:harness-log "SELF-FIX FAILURE - File not found. nil))
|
||||
(error (c)
|
||||
(opencortex:harness-log "SELF-FIX CRASH - ~a. Rolling back." c)
|
||||
(opencortex:rollback-memory 0)
|
||||
nil))))
|
||||
(defun self-fix-broken-skill (skill-name error-log)
|
||||
"Attempts to diagnose and repair a broken skill."
|
||||
(harness-log "SELF-FIX: Attempting repair of ~a..." skill-name))
|
||||
#+end_src
|
||||
|
||||
** Cognitive Tool
|
||||
#+begin_src lisp
|
||||
(def-cognitive-tool :repair-file
|
||||
"Applies a surgical code modification to a file and reloads the skill if applicable."
|
||||
((:file :type :string :description "Path to the target file
|
||||
(:old :type :string :description "The literal code block to find
|
||||
(:new :type :string :description "The literal code block to replace it with)
|
||||
:body (lambda (args)
|
||||
(if (self-fix-apply (list :payload args) nil)
|
||||
"REPAIR SUCCESSFUL."
|
||||
"REPAIR FAILED.))
|
||||
#+end_src
|
||||
|
||||
** Skill Definition
|
||||
** Skill Registration
|
||||
#+begin_src lisp
|
||||
(defskill :skill-self-fix
|
||||
:priority 95
|
||||
:trigger (lambda (context) (eq (getf (getf context :payload) :sensor) :repair-request))
|
||||
:probabilistic (lambda (context)
|
||||
(format nil "You are the opencortex Repair Actuator. Synthesize a surgical fix for the reported failure.
|
||||
Return a Lisp plist for :repair-file.)
|
||||
:deterministic (lambda (action context)
|
||||
(let ((payload (getf action :payload)))
|
||||
(self-fix-apply action context))))
|
||||
:priority 100
|
||||
:trigger (lambda (ctx) (member (getf ctx :type) '(:LOG :EVENT)))
|
||||
:deterministic (lambda (action ctx) (declare (ignore action ctx)) nil))
|
||||
#+end_src
|
||||
|
||||
* See Also
|
||||
- [[file:org-skill-lisp-utils.org][Lisp Utils]] - Utilities, repair, and validation
|
||||
Reference in New Issue
Block a user