Re: AGENTS.md

Jean Louis <[email protected]> Fri, 07 Aug 2026 21:12:46 +0300
Newsgroups gmane.emacs.devel
Organization GNU Support
Message-ID <[email protected]>
On 2026-08-07 09:19, Dr. Arne Babenhauserheide wrote:
> Eli Zaretskii <[email protected]> writes:
> 
>> Again, we created it to help users making innocent mistakes, using
>> whatever LLM-based agents, both proprietary and free.
> 
> Do the emacs modes that drive LLMs support AGENTS.md?
> 
> With the decision of Emacs core to embrace AGENTS.md, it may be good if
> they did, too.

This type of package would implement a function that can be used by 
other packages:

llm-memory-user-files ⇒ 
(("/home/data1/protected/Programming/emacs-lisp/" . "MEMORY.txt"))

(llm-project-memory "/home/data1/protected/Programming/emacs-lisp/") ⇒ 
"# Emacs Lisp Agent Guidelines

When working with Emacs Lisp code in this project, use the `emacs-elisp` 
MCP tools to discover, document, and explore functions.

## Available MCP Tools

| Tool | Purpose |
|------|---------|
| `search_functions` | Search for functions by name pattern |
| `get_documentation` | Get documentation for any function or variable |
| `list_functions_by_prefix` | List all functions starting with a prefix 
|
| `rcd_elisp_function_definition` | Get the full source definition of a 
function |

etc. etc.

;;; llm-memory.el --- Project memory for LLMs -*- lexical-binding: t; 
-*-

(defgroup llm-memory nil
   "Project-specific LLM memory."
   :group 'applications)

(defcustom llm-memory-enabled t
   "Enable project memory."
   :type 'boolean)

(defcustom llm-memory-filenames '("MEMORY.md" ".llm-memory" 
"LLM_MEMORY.md")
   "Memory filenames to check in order."
   :type '(repeat string))

(defcustom llm-memory-user-files nil
   "Alist (DIR . FILENAME) for custom per-project memory files."
   :type '(alist :key-type string :value-type string))

(defcustom llm-memory-cache t
   "Cache memory contents."
   :type 'boolean)

(defvar llm-memory--cache (make-hash-table :test 'equal))

(defun llm-memory--find (dir)
   "Find memory file in DIR."
   (unless (file-directory-p dir)
     (error "Not a directory: %s" dir))
   (let ((truename (file-truename dir)))
     (or (and-let* ((pair (assoc truename llm-memory-user-files))
                    (file (cdr pair))
                    (path (expand-file-name file dir))
                    ((file-readable-p path)))
           path)
         (cl-some (lambda (f)
                    (let ((path (expand-file-name f dir)))
                      (when (file-readable-p path) path)))
                  llm-memory-filenames))))

(defun llm-project-memory (dir)
   "Return memory content for DIR or nil."
   (unless (and llm-memory-enabled (file-directory-p dir))
     (cl-return-from llm-project-memory nil))
   (let ((key (file-truename dir)))
     (or (when llm-memory-cache (gethash key llm-memory--cache))
         (and-let* ((file (llm-memory--find dir))
                    (content (with-temp-buffer
                               (insert-file-contents file)
                               (buffer-string))))
           (when llm-memory-cache
             (puthash key content llm-memory--cache))
           content))))

;;;###autoload
(defun llm-memory-dired-record (file)
   "Record FILE as memory for the current dired directory.
Interactively, use the file at point in dired."
   (interactive
    (let ((file (dired-get-filename nil 'no-error)))
      (unless file
        (user-error "No file at point"))
      (list file)))
   (unless (file-exists-p file)
     (user-error "File does not exist: %s" file))
   (let* ((dir (if (derived-mode-p 'dired-mode)
                   default-directory
                 (user-error "Not in dired mode")))
          (truename (file-truename dir))
          (basename (file-name-nondirectory file)))
     (setq llm-memory-user-files
           (cons (cons truename basename)
                 (cl-remove-if (lambda (pair)
                                 (string= (car pair) truename))
                               llm-memory-user-files)))
     (when llm-memory-cache
       (remhash truename llm-memory--cache))
     (message "Recorded %s as memory for %s" basename dir)))

(provide 'llm-memory)

That would be the Emacs way, to assign some file as memory to the 
project, no matter how you call the file.

Then you can change or apply different file without fiddling. You can 
also turn it off as not to spend too much money on the SaaS LLM.

-- 
Jean Louis