Files
memex/system/skills/org-skill-project-foundry.org

7.0 KiB

SKILL: Project Foundry Agent (Workspace Scaffolding)

Overview

The Project Foundry Agent is responsible for the physical instantiation of new projects within the Memex workspace. It automates the boilerplate tasks of directory creation, version control initialization, and GTD integration, ensuring that every new project adheres to the high-integrity mandates of the Personal Software Foundry (PSF).

The Foundry Mandate

  1. Structural Consistency: Every project must follow the standard PSF directory layout (`src/`, `tests/`, `docs/`).
  2. Literate Programming: Scaffolding must include base Org-mode files (`README.org`, `PRD.org`, `PROTOCOL.org`) to encourage architectural documentation from day one.
  3. Traceability: New projects must be automatically linked to the user's GTD system with a predefined set of initialization tasks.
  4. Safety: The Foundry must prevent overwriting existing projects and ensure all system calls are properly logged.

Symbolic Implementation (The Logic)

The implementation focuses on the deterministic orchestration of the filesystem and the Git CLI.

Architectural Intent: Delegation Trigger

The Foundry is a specialized utility that is only invoked when the Router explicitly delegates a project creation task to it.

(defun trigger-skill-project-foundry (context)
  (let ((type (getf context :type))
        (payload (getf context :payload)))
    (and (eq type :EVENT)
         (eq (getf payload :sensor) :delegation)
         (eq (getf payload :target-skill) :foundry))))

Architectural Intent: Workspace Scaffolding

This function performs the "heavy lifting" of project creation. it manages directory structures, initializes Git, drafts initial Literate Programming documents, and appends the project to the user's GTD file with a strict dependency chain (PRD -> PROTOCOL -> Implementation).

(defun scaffold-project (name type)
  "Physically creates the PSF project structure on disk and links it to GTD.
Follows the mandates defined in [[file:personal_software_foundry.org][Personal Software Foundry]]."
  (let* ((projects-dir (org-agent::get-env "PROJECTS_DIR" "/app/5_projects/"))
         (project-dir (format nil "~a/~a/" projects-dir name))
         (memex-dir (org-agent::get-env "MEMEX_DIR" "/app/"))
         (gtd-file (format nil "~a/gtd.org" (string-right-trim "/" memex-dir)))
         (timestamp (get-universal-time)))
    
    (if (uiop:directory-exists-p project-dir)
        (format nil "ERROR - Project ~a already exists." name)
        (progn
          (kernel-log "FOUNDRY - Scaffolding ~a project: ~a" type name)
          
          ;; 1. Create PSF Directory Structure
          (ensure-directories-exist project-dir)
          (ensure-directories-exist (format nil "~asrc/" project-dir))
          (ensure-directories-exist (format nil "~atests/" project-dir))
          (ensure-directories-exist (format nil "~adocs/" project-dir))
          
          ;; 2. Initialize Git (via shell delegation)
          (org-agent:inject-stimulus 
           `(:type :EVENT :payload (:action :run-command :target :shell :cmd ,(format nil "git init ~a" project-dir))))
          
          ;; 3. Create Boilerplate PSF Files (Literate Programming Mandate)
          
          ;; README.org
          (with-open-file (out (format nil "~aREADME.org" project-dir) :direction :output :if-exists :supersede)
            (format out "#+TITLE: ~a~%#+AUTHOR: User~%#+DATE: ~a~%~%* Vision~%Automatically scaffolded ~a project.~%~%* Structure~%- [[file:PRD.org][Requirements (PRD)]]~%- [[file:PROTOCOL.org][Interfaces (PROTOCOL)]]~%- [[file:src/][Implementation (src)]]~%- [[file:tests/][Verification (tests)]]~%" name timestamp type))
          
          ;; PRD.org
          (with-open-file (out (format nil "~aPRD.org" project-dir) :direction :output :if-exists :supersede)
            (format out "#+TITLE: PRD: ~a~%#+STATUS: DRAFT~%~%* 1. Purpose~%Define the 'Why' and 'What' for ~a.~%~%* 2. User Needs~%- ~%~%* 3. Success Criteria~%- ~%" name name))
          
          ;; PROTOCOL.org
          (with-open-file (out (format nil "~aPROTOCOL.org" project-dir) :direction :output :if-exists :supersede)
            (format out "#+TITLE: PROTOCOL: ~a~%#+STATUS: DRAFT~%~%* 1. Architectural Intent~%How ~a is structured.~%~%* 2. Interfaces~%#+begin_src lisp~%;; Define core signatures here~%#+end_src~%" name name))
          
          ;; 4. Link to GTD.org (org-gtd v4.0 / PSF / org-edna Integration)
          (with-open-file (out gtd-file :direction :output :if-exists :append)
            (format out "~%** NEXT ~a~%  :PROPERTIES:~%  :PROJECT-PATH: $PROJECTS_DIR/~a~%  :PSF-STATE: A: DEMAND~%  :ID: proj-~a~%  :TRIGGER: next-sibling!~%  :END:~%  Drafted by Project Foundry following PSF Mandates.~%~%*** TODO Draft PRD for ~a~%    :PROPERTIES:~%    :ID: task-prd-~a~%    :TRIGGER: next-sibling!~%    :END:~%*** TODO Draft PROTOCOL for ~a~%    :PROPERTIES:~%    :ID: task-proto-~a~%    :BLOCKER: previous-sibling!~%    :TRIGGER: next-sibling!~%    :END:~%*** TODO Implement and Test ~a~%    :PROPERTIES:~%    :ID: task-impl-~a~%    :BLOCKER: previous-sibling!~%    :END:~%" 
                    name name timestamp name timestamp name timestamp name timestamp))
          
          (format nil "SUCCESS - PSF Project ~a scaffolded with full SDLC structure." name)))))

Architectural Intent: Neuro-Cognitive Extraction

When the Foundry is delegated a task, the neural layer is responsible for extracting the project name and type from the natural language query, translating intent into the symbolic parameters needed for scaffolding.

(defun neuro-skill-project-foundry (context)
  (let* ((payload (getf context :payload))
         (query (getf payload :query)))
    (format nil "
      You are the PSF Project Foundry. 
      Your mandate is to scaffold a high-integrity, Literate Programming project structure.
      The user wants to start a new project - '~a'
      
      Extract the PROJECT NAME and the PROJECT TYPE.
      The Foundry will create: README.org, PRD.org, PROTOCOL.org, src/, tests/, and docs/.
      
      Return a Lisp plist - (:target :foundry :action :scaffold :name \"extracted-name\" :type \"extracted-type\")
    " query)))

Architectural Intent: Symbolic Actuation

Ensures that the neural proposal is valid and then executes the physical scaffolding, returning a status message to the user via Emacs.

(defun verify-skill-project-foundry (proposed-action context)
  (let* ((payload (getf proposed-action :payload))
         (action (getf proposed-action :action))
         (name (getf payload :name))
         (type (getf payload :type)))
    
    (if (eq action :scaffold)
        (let ((result (scaffold-project name type)))
          `(:target :emacs :action :message :text ,result))
        nil)))

Registration

(defskill :skill-project-foundry
  :priority 80
  :trigger #'trigger-skill-project-foundry
  :neuro #'neuro-skill-project-foundry
  :symbolic #'verify-skill-project-foundry)