agentleFS
tninjatninja/ai-code-interface.el/AGENTS.md

ai-code-interface.el

AGENTS.md305 starsChanged 24 days agoApache-2.0View on GitHub

- Treat new byte-compilation warnings as regressions when touching Emacs Lisp code. - Prefer reproducible batch verification first, ideally emacs -Q with the necessary load-path and dependencies configured for the target file. - If batch compilation fails to load required files or packages, treat that as a verification failure to resolve or report, not as a clean pass. - If emacs -Q cannot be made to work cleanly, compile files individually through emacsclient as a fallback to match the active…

  • Installs packages
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

19 rules. About 0 are common, 6 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat new byte-compilation warnings as regressions when touching Emacs Lisp code.

    line 12
  2. Very specific:

    Prefer reproducible batch verification first, ideally emacs -Q with the necessary load-path and dependencies configured for the target file.

    line 13
  3. Distinctive:

    If batch compilation fails to load required files or packages, treat that as a verification failure to resolve or report, not as a clean …

    line 15
  4. Very specific:

    If emacs -Q cannot be made to work cleanly, compile files individually through emacsclient as a fallback to match the active Emacs session …

    line 17
  5. Very specific:

    ai-code-discussion.el: Ask questions, explain code functionality

    line 89
  6. Distinctive:

    AI CLI Session: Start, resume, switch, select backend, upgrade, open config, apply prompt on file

    line 102
  7. Distinctive:

    All context-aware actions automatically include:

    line 107
  8. Very specific:

    All files use lexical-binding: t

    line 143
  9. Very specific:

    Use defcustom for user-configurable variables with :group 'ai-code

    line 155
  10. Very specific:

    Use ;;;###autoload cookies for interactive commands that should be available when the package is loaded

    line 156
  11. Very specific:

    Use declare-function only for functions defined in other files or loaded later.

    line 157
  12. Very specific:

    Do not add declare-function entries for functions defined later in the same file.

    line 158
  13. Very specific:

    Use cl-labels for local helper functions

    line 162
  14. Distinctive:

    When adding a new backend:

    line 166
  15. Very specific:

    Create ai-code-<backend-name>.el following the pattern of existing backends

    line 167
  16. Very specific:

    Add backend definition to ai-code-backends in ai-code-backends.el

    line 169
  17. Distinctive:

    Update README.org with backend setup instructions

    line 170
  18. Very specific:

    Use ert-deftest for test definitions

    line 174
  19. Very specific:

    Use with-temp-buffer for buffer-related tests

    line 176

≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

This file provides guidance to coding agents working with code in this repository.

Common Development Commands

Byte Compilation

emacs -batch -f batch-byte-compile *.el
  • Treat new byte-compilation warnings as regressions when touching Emacs Lisp code.
  • Prefer reproducible batch verification first, ideally emacs -Q with the necessary load-path and dependencies configured for the target file.
  • If batch compilation fails to load required files or packages, treat that as a verification failure to resolve or report, not as a clean pass.
  • If emacs -Q cannot be made to work cleanly, compile files individually through emacsclient as a fallback to match the active Emacs session more closely.
  • For documentation hygiene on touched files, also run M-x checkdoc (or batch checkdoc-file) before wrapping up changes.

Running Tests

# Run a specific test file
emacs -batch -L . -l ert -l test/test_ai-code-change.el -f ert-run-tests-batch-and-exit

# Run all tests
emacs -batch -L . -l ert --eval "(mapc #'load-file (file-expand-wildcards \"test/test_*.el\"))" -f ert-run-tests-batch-and-exit

CI Testing

The project uses melpazoid for CI checks. The workflow is defined in .github/workflows/melpazoid.yml.

High-Level Architecture

Core Design Philosophy

This is a unified interface package for AI-assisted software development that abstracts over multiple AI coding CLI backends (Claude Code, Gemini CLI, OpenAI Codex, Pi, GitHub Copilot CLI, Opencode, Kilo, Grok CLI, Cursor CLI, CodeBuddy Code CLI, Kiro CLI). The package provides a consistent user experience across different AI tools while maintaining context-aware code actions and agile development workflows.

Backend System Architecture

The backend system is pluggable and defined in ai-code-backends.el. Each backend is registered as a property list in ai-code-backends:

(ai-code-backends
  '((claude-code
     :label "Claude Code"
     :require ai-code-claude-code
     :start   ai-code-claude-code
     :switch  ai-code-claude-code-switch-to-buffer
     :send    ai-code-claude-code-send-command
     :resume  ai-code-claude-code-resume
     :config  "~/.claude.json"
     :upgrade "npm install -g @anthropic-ai/claude-code@latest"
     :cli     "claude")
    ;; ... other backends
    ))

Backend switching is handled via ai-code-set-backend, which:

  1. Loads the backend's requirement (e.g., ai-code-claude-code)
  2. Sets up function aliases for common operations
  3. Updates the UI to reflect the current backend

Backend implementations fall into two categories:

  1. Native backends (in this repo): Implemented in files like ai-code-codex-cli.el, ai-code-pi.el, ai-code-github-copilot-cli.el, ai-code-gemini-cli.el, ai-code-codebuddy-cli.el, etc.
  2. External backends: Packages like claude-code-ide.el and claude-code.el that provide backend functions

Terminal Infrastructure

ai-code-backends-infra.el provides a unified abstraction over terminal emulators:

  • Default: vterm (libvterm-based)
  • Alternative: eat (Embraced as Terminal)
  • Configuration via ai-code-backends-infra-terminal-backend

Key infrastructure features:

  • Session management (multiple concurrent AI sessions)
  • Window management (side windows, focus control)
  • Performance optimizations (anti-flicker, reflow glitch prevention)
  • Input handling (@-completion, clipboard integration)

Module Organization

The codebase is organized into focused modules:

  • ai-code.el: Main entry point, defines the transient menu (C-c a) and top-level commands
  • ai-code-backends.el: Backend registration and selection system
  • ai-code-backends-infra.el: Terminal abstraction (vterm/eat) and session management
  • ai-code-change.el: Code manipulation operations (change code, implement TODOs, explain code)
  • ai-code-discussion.el: Ask questions, explain code functionality
  • ai-code-agile.el: Refactoring techniques catalog and TDD cycle workflow
  • ai-code-git.el: Git integration (diff review, recent files, branch operations)
  • ai-code-file.el: File operations (copy paths, recent files, sed-based prompt application)
  • ai-code-prompt-mode.el: Prompt file management (.ai.code.prompt.org), @-completion, yasnippet integration
  • ai-code-input.el: User input handling, context gathering, completion utilities
  • ai-code-notifications.el: Desktop notifications for AI session completion
  • Backend implementations: ai-code-codex-cli.el, ai-code-pi.el, ai-code-github-copilot-cli.el, ai-code-gemini-cli.el, ai-code-codebuddy-cli.el, ai-code-opencode.el, ai-code-kilo.el, ai-code-grok-cli.el, ai-code-cursor-cli.el, ai-code-kiro-cli.el, ai-code-claude-code.el

Transient Menu System

The main entry point is ai-code-menu (bound to C-c a), which uses the transient package to create an interactive menu with four sections:

  1. AI CLI Session: Start, resume, switch, select backend, upgrade, open config, apply prompt on file
  2. AI Code Actions With Context: Code change, implement TODO, ask question, explain, send command, add context, create task file
  3. AI Agile Development With Harness: Refactor, TDD cycle, pull/review diff, run file, build project, open prompt file, insert function
  4. Other Tools: Init project, debug exception, fix Flycheck errors, copy file name, toggle dedicated, open recent file, debug MCP, take notes, toggle notifications

All context-aware actions automatically include:

  • Current file path
  • Visible buffers (context files)
  • Function or region at point
  • Stored repo context (ai-code--repo-context-info)
  • Optional clipboard context (with C-u prefix)

Context Engineering System

Context engineering is a core concept - the package provides tools to automatically assemble precise context blocks:

  1. Automatic file context: ai-code--get-context-files-string includes visible buffers
  2. Function/region scoping: Most actions capture which-function result or active region
  3. Manual context curation: ai-code-context-action (C-c a @) stores file paths, function anchors, or region ranges in ai-code--repo-context-info
  4. @-completion: Type @ to open file completion list, inserts relative paths with @ prefix
  5. Prompt suffix: ai-code-prompt-suffix appends persistent constraints to all prompts

Refactoring Techniques Catalog

ai-code-agile.el contains a comprehensive catalog of refactoring techniques following Martin Fowler's book. Each technique has:

  • :name - Display name
  • :scopes - Where it applies (region/global)
  • :description - The prompt template sent to AI
  • :parameters (optional) - Interactive parameters with placeholders, prompts, and default value functions

TDD Workflow

The Test Driven Development cycle (ai-code-tdd-cycle) integrates with test frameworks:

  • Python: python-pytest
  • JavaScript/TypeScript: jest

The workflow guides through writing tests, running them, implementing code, and refactoring.

Code Style and Conventions

File Structure

  • All files use lexical-binding: t
  • Header includes Author, Version (for main file), Package-Requires, SPDX-License-Identifier: Apache-2.0
  • Commentary section describes the module's purpose
  • Code section follows

Naming Conventions

  • Public functions: ai-code-function-name
  • Private functions: ai-code--function-name (double dash)
  • Custom variables: ai-code-variable-name
  • Backends: Use kebab-case symbols like claude-code, github-copilot-cli

Function Definitions

  • Use defcustom for user-configurable variables with :group 'ai-code
  • Use ;;;###autoload cookies for interactive commands that should be available when the package is loaded
  • Use declare-function only for functions defined in other files or loaded later.
  • Do not add declare-function entries for functions defined later in the same file; that can trigger duplicate-definition byte-compilation warnings.
  • For dynamically bound external variables referenced from optional packages, add explicit defvar declarations instead of leaving them free.
  • Use cl-labels for local helper functions
  • Prefix arguments (C-u) are used to modify behavior (e.g., append clipboard context, force full paths)

Backend Integration Pattern

When adding a new backend:

  1. Create ai-code-<backend-name>.el following the pattern of existing backends
  2. Implement required functions: ai-code-<backend>-start, ai-code-<backend>-switch-to-buffer, ai-code-<backend>-send-command, ai-code-<backend>-resume (optional)
  3. Add backend definition to ai-code-backends in ai-code-backends.el
  4. Update README.org with backend setup instructions

Testing Conventions

  • Test files: test_ai-code-<module>.el
  • Use ert-deftest for test definitions
  • Test names: test-module--function-name-scenario
  • Use with-temp-buffer for buffer-related tests
  • Mock functions with cl-letf when needed
  • Mock which-function for function context testing

File Organization Context

  • .ai.code.files/: Created automatically in project root, contains .ai.code.prompt.org for prompt history
  • snippets/ai-code-prompt-mode/: Yasnippet templates for common prompts
  • examples/: Example projects demonstrating usage (Battleship, Connect4)
  • test/: ERT test files

Integration Points

Magit Integration

  • ai-code-magit-setup-transients adds AI commands to Magit popups
  • Functions use magit-toplevel to find git root
  • Diff review integrates with Magit's diff generation

External Package Integrations

  • gptel: Optional, used for AI-generated headlines in prompt file
  • helm: Optional, for enhanced completion
  • yasnippet: Optional, for prompt templates
  • flycheck: Optional, for ai-code-flycheck-fix-errors-in-scope
  • projectile: Optional, for project root detection in ai-code-init-project

External AI CLI Requirements

Each backend requires the corresponding CLI to be installed and available on PATH:

  • Claude Code: claude
  • Gemini CLI: gemini
  • OpenAI Codex: codex
  • Pi: pi
  • GitHub Copilot CLI: copilot
  • Opencode: opencode
  • Kilo: kilo
  • Grok CLI: grok
  • Goose CLI: goose
  • Cursor CLI: cursor
  • Kiro CLI: kiro
  • CodeBuddy Code CLI: codebuddy

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.