feat(arch): implement 'Code as Thought' architecture and formalize PSF Consensus Loop

This commit is contained in:
2026-03-31 13:03:26 -04:00
parent 5a9129132e
commit 1712b1e4a9
114 changed files with 3652 additions and 2581 deletions

View File

@@ -0,0 +1,44 @@
import re
import os
def simulate_memex_audit(file_path):
if not os.path.exists(file_path):
return {"status": "error", "message": "File not found"}
errors = []
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
for i, line in enumerate(lines):
if re.match(r'^\*{3,10} ', line):
current_headline = line.strip()
found_created = False
in_properties = False
# Look ahead for PROPERTIES and CREATED
for j in range(i + 1, min(i + 20, len(lines))):
if ":PROPERTIES:" in lines[j]:
in_properties = True
if in_properties and ":CREATED:" in lines[j]:
found_created = True
break
if in_properties and ":END:" in lines[j]:
break
if re.match(r'^\*+ ', lines[j]): # Hit another headline
break
if not found_created:
errors.append(f"Missing :CREATED: for {current_headline} (Line {i+1})")
return {"status": "fail" if errors else "success", "file": file_path, "errors": errors}
if __name__ == "__main__":
inbox_files = [f for f in os.listdir('.') if f.startswith('inbox-') and f.endswith('.org')]
for f in inbox_files:
result = simulate_memex_audit(f)
print(f"--- Audit: {f} ---")
print(f"Status: {result['status'].upper()}")
print(f"Errors Found: {len(result['errors'])}")
if result['errors']:
print("First 3 errors:")
for e in result['errors'][:3]:
print(f" - {e}")

View File

@@ -0,0 +1,55 @@
;;; TDD Suite: org-skill-memex (Knowledge Management Standards)
;;; Status: RED (Initial Inception)
;;; Author: Tech-Analyst-Agent
;;; Created: [2026-03-31 Tue 12:50]
(defpackage :org-skill-memex-tests
(:use :cl :fiveam :org-skill-memex))
(in-package :org-skill-memex-tests)
(def-suite memex-integrity-suite
:description "Tests for metadata and structural integrity of the Memex.")
(in-suite memex-integrity-suite)
;;; --- 2.1 Metadata Integrity Audit Tests ---
(test audit-missing-created-property
"Ensure that entries missing the :CREATED: property are flagged."
(let ((test-file "/tmp/test-missing-created.org"))
(with-open-file (out test-file :direction :output :if-exists :supersede)
(format out "* TODO Entry without created property~% :PROPERTIES:~% :ID: 123~% :END:~%"))
(let ((result (memex-audit-metadata test-file)))
(is (member :missing-created (getf result :errors)))
(is (equal "Entry without created property" (getf (car (getf result :entries)) :title))))))
(test audit-misplaced-logbook
"Ensure that :LOGBOOK: drawers MUST come after :PROPERTIES:."
(let ((test-file "/tmp/test-bad-logbook.org"))
(with-open-file (out test-file :direction :output :if-exists :supersede)
(format out "* TODO Misplaced Logbook~% :LOGBOOK:~% - State \"DONE\" from \"TODO\" [2026-03-31]~% :END:~% :PROPERTIES:~% :CREATED: [2026-03-31]~% :END:~%"))
(let ((result (memex-audit-metadata test-file)))
(is (member :misplaced-logbook (getf result :errors))))))
;;; --- 2.2 GTD Task Promotion Tests ---
(test promote-sequential-task
"Ensure that completing a NEXT task promotes the next TODO in the same project."
(let ((project-id "test-project-promotion"))
;; Implementation of mock GTD state would go here
;; (is (equal "next-task-id" (memex-promote-next-task project-id)))
(skip "Mock GTD state machine required for promotion testing.")))
;;; --- 2.3 Agentic Distillation Tests ---
(test distill-concept-from-daily
"Ensure concepts are correctly extracted and backlinks added."
(let ((daily-file "/tmp/2026-03-31-test.org")
(concept "Lisp Sovereignty"))
(with-open-file (out daily-file :direction :output :if-exists :supersede)
(format out "* Lisp Sovereignty~% This is a timeless concept about control.~%"))
(let ((note-path (memex-distill-atomic-note daily-file concept)))
(is (cl-ppcre:scan "lisp_sovereignty.org" note-path))
(is (cl-ppcre:scan "Source: \\[\\[file:2026-03-31-test.org\\]\\]"
(uiop:read-file-string note-path))))))