feat(arch): implement 'Code as Thought' architecture and formalize PSF Consensus Loop
This commit is contained in:
52
projects/org-skill-scribe/src/scribe-engine.lisp
Normal file
52
projects/org-skill-scribe/src/scribe-engine.lisp
Normal file
@@ -0,0 +1,52 @@
|
||||
;;;; scribe-engine.lisp --- Knowledge distillation and mandate auditing logic.
|
||||
;;;; This file is TANGLED from org-skill-scribe.org. DO NOT EDIT MANUALLY.
|
||||
|
||||
(defpackage :org-skill-scribe
|
||||
(:use :cl :uiop :cl-ppcre :local-time)
|
||||
(:export #:scribe-scan-for-knowledge-gaps
|
||||
#:scribe-distill-concept
|
||||
#:scribe-audit-foundry-mandate
|
||||
#:scribe-update-state))
|
||||
|
||||
(in-package :org-skill-scribe)
|
||||
|
||||
(defun scribe-scan-for-knowledge-gaps ()
|
||||
"Uses 'git diff' to identify new daily captures using Lisp-native state."
|
||||
(let* ((state-file (or (uiop:getenv "SCRIBE_STATE") "scribe-state.lisp"))
|
||||
(state (if (uiop:file-exists-p state-file)
|
||||
(with-open-file (in state-file) (read in))
|
||||
'((:last-commit . "HEAD~1"))))
|
||||
(last-hash (cdr (assoc :last-commit state))))
|
||||
(uiop:run-program (list "git" "diff" "--name-only" last-hash "HEAD" "--" (or (uiop:getenv "MEMEX_DAILY") "daily/"))
|
||||
:output :lines)))
|
||||
|
||||
(defun scribe-update-state (new-hash)
|
||||
"Serializes the new state alist to disk."
|
||||
(let ((state-file (or (uiop:getenv "SCRIBE_STATE") "scribe-state.lisp")))
|
||||
(with-open-file (out state-file :direction :output :if-exists :supersede)
|
||||
(print `((:last-commit . ,new-hash)
|
||||
(:last-run . ,(local-time:format-timestring nil (local-time:now))))
|
||||
out))))
|
||||
|
||||
(defun scribe-distill-concept (daily-path concept-meta)
|
||||
"Creates an atomic note with snake_case filename and Source: backlink."
|
||||
(let* ((title (getf concept-meta :title))
|
||||
(content (getf concept-meta :content))
|
||||
(source (getf concept-meta :source))
|
||||
(filename (format nil "~a.org" (cl-ppcre:regex-replace-all " " (string-downcase title) "_")))
|
||||
(target-path (format nil "~a/~a" (or (uiop:getenv "MEMEX_NOTES") "notes") filename)))
|
||||
|
||||
(with-open-file (out target-path :direction :output :if-exists :supersede)
|
||||
(format out "#+TITLE: ~a~%#+ID: ~a~%~%Source: [[file:~a]]~%~%~a"
|
||||
title (uiop:read-file-string "/proc/sys/kernel/random/uuid") source content))
|
||||
target-path))
|
||||
|
||||
(defun scribe-audit-foundry-mandate (project-name)
|
||||
"Audits a project for PRD, PROTOCOL, and Literate src/ structure."
|
||||
(let ((project-dir (format nil "~a/~a/" (or (uiop:getenv "PROJECTS_DIR") "projects") project-name))
|
||||
(violations '()))
|
||||
(unless (uiop:file-exists-p (format nil "~aPRD.org" project-dir))
|
||||
(push :missing-prd violations))
|
||||
(unless (uiop:file-exists-p (format nil "~aPROTOCOL.org" project-dir))
|
||||
(push :missing-protocol violations))
|
||||
violations))
|
||||
Reference in New Issue
Block a user