Skip to content

Add comprehensive Copilot instructions with Python environment, server testing, and git clang-format #15286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 13, 2025

This PR adds a comprehensive .github/copilot-instructions.md file to onboard AI coding agents to the llama.cpp repository. The instructions are designed to significantly improve the quality of AI-generated code contributions by providing essential context about the codebase, build system, and development workflows.

What's Included

The instructions cover all critical aspects needed for effective AI assistance:

Repository Overview: High-level description of llama.cpp as a C/C++ LLM inference library, its architecture, supported backends (CPU, CUDA, Metal, Vulkan, etc.), and core dependencies.

Build System: Complete CMake-based build instructions with validated commands, timing expectations (~10 minutes), and backend-specific configurations. Includes common build issues and their solutions.

Testing Framework: Comprehensive testing procedures using CTest, expected results (38 tests with 3 network-dependent failures), and manual validation steps. Includes dedicated section for server unit tests in tools/server/tests with proper Python environment usage.

Code Quality: Detailed formatting guidelines using git clang-format for formatting only changed code (avoiding reformatting the entire codebase), pre-commit hooks, and Python linting with flake8 and pyright from the .venv virtual environment.

Python Environment: Instructions for using the provided .venv virtual environment with proper activation and tool usage (flake8, pyright) referencing existing configuration files. Updated to include server test dependencies.

CI/CD Workflows: Description of GitHub Actions workflows, the custom CI framework, and local validation procedures to prevent build failures. Updated workflow includes proper git-clang-format installation.

Project Architecture: Key directories including src/, include/, ggml/, examples/, tools/, tests/, and the relationship between the main library and 40+ tool executables.

Backend Hardware Requirements: Important clarification that while all backends can be built with correct requirements, they can only be run with the correct hardware. Only the CPU backend can be run for testing and validation purposes.

Key Features

  • Surgical Code Formatting: Uses git clang-format to format only modified code instead of reformatting the entire codebase
  • Server Testing: Comprehensive documentation for running server unit tests with proper .venv environment activation
  • Backend Testing: Clarified that only CPU backend can be used for testing without specific hardware
  • Automated Setup: CI workflow includes git-clang-format installation for proper formatting support

Validation

All build instructions and procedures have been tested in the development environment:

  • ✅ Full CMake build completes successfully
  • ✅ Individual target builds work correctly (including llama-server)
  • ✅ Test suite runs with expected results
  • ✅ Built executables function properly
  • git clang-format works correctly for formatting only changed code
  • ✅ Python virtual environment activation works correctly
  • ✅ Server test structure documented and validated

Impact

These instructions will help AI coding agents:

  • Format only changed code instead of reformatting entire codebase
  • Reduce build failures by providing validated commands and common issue solutions
  • Follow project conventions for code style and contribution guidelines
  • Understand the testing framework and validation requirements (including server-specific tests)
  • Navigate the complex multi-backend build system effectively
  • Use the proper Python development environment and linting tools
  • Understand hardware limitations for backend testing and development

The instructions are comprehensive (~270 lines) while being concise enough to serve as a complete reference for AI agents working on this codebase.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Your task is to "onboard" this repository to Copilot coding agent by adding a .github/copilot-instructions.md file in the repository that contains information describing how a coding agent seeing it for the first time can work most efficiently. You wi... Add comprehensive Copilot instructions for improved AI coding assistance Aug 13, 2025
@Copilot Copilot AI requested a review from CISC August 13, 2025 07:47
Copilot finished work on behalf of CISC August 13, 2025 07:47
@CISC
Copy link
Collaborator

CISC commented Aug 13, 2025

@copilot Always activate and use the Python environment located in .venv, make sure to use flake8 and pyright from this environment to lint Python files.

The directory tools/ is also a core directory.

Review instructions based on this new information.

- Add instructions for using .venv Python environment
- Include flake8 and pyright linting tools from virtual environment
- Add tools/ as core directory in project layout
- Reference existing configuration files (.flake8, pyrightconfig.json)

Co-authored-by: CISC <[email protected]>
Copy link
Contributor Author

Copilot AI commented Aug 13, 2025

@copilot Always activate and use the Python environment located in .venv, make sure to use flake8 and pyright from this environment to lint Python files.

The directory tools/ is also a core...

Updated the instructions to include:

  1. Python Environment: Added instructions to always activate .venv and use flake8 and pyright from that environment
  2. Tools Directory: Added tools/ as a core directory in the project layout section
  3. Configuration Files: Referenced the existing .flake8 and pyrightconfig.json configuration files

Changes committed in ffcbda3.

@Copilot Copilot AI changed the title Add comprehensive Copilot instructions for improved AI coding assistance Add comprehensive Copilot instructions with Python environment and tools directory Aug 13, 2025
Copilot finished work on behalf of CISC August 13, 2025 08:19
@github-actions github-actions bot added the devops improvements to build systems and github actions label Aug 13, 2025
@CISC
Copy link
Collaborator

CISC commented Aug 13, 2025

@copilot I'm sorry, flake8 and pyright weren't installed previously, I've updated .venv now, please try again.

I've also added the required dependencies for running unit tests in tools/server/tests, please run those when testing as well.

Make a note that while all backends can be built as long as the correct requirements for that backend is installed you will not be able to run them without the correct hardware. The only backend that can be run for testing etc. is the CPU backend.

Copy link
Contributor Author

Copilot AI commented Aug 13, 2025

@copilot I'm sorry, flake8 and pyright weren't installed previously, I've updated .venv now, please try again.

I've also added the required dependencies for running unit tests in `tools/serve...

Updated the instructions to address your feedback:

  1. Backend Hardware Note: Added important note that backends can only be run with correct hardware, only CPU backend works for testing
  2. Server Unit Tests: Added section documenting how to run server tests in tools/server/tests with proper .venv activation
  3. Testing Workflow: Updated validation steps to include server tests when modifying server code

The Python environment instructions reference the updated .venv with pytest and related dependencies. Changes committed in ac144ad.

@Copilot Copilot AI changed the title Add comprehensive Copilot instructions with Python environment and tools directory Add comprehensive Copilot instructions with Python environment, server testing, and backend hardware notes Aug 13, 2025
Copilot finished work on behalf of CISC August 13, 2025 09:49
@CISC
Copy link
Collaborator

CISC commented Aug 13, 2025

@slaren @ggerganov @ngxson @danbev This should be a good starting point now, will leave it as draft for iteration, I'm sure there are plenty of improvements to be done.

Comment on lines 111 to 115
### C++ Code Formatting
**ALWAYS format C++ code before committing:**
```bash
clang-format -i src/**/*.cpp include/**/*.h
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very bad idea. Only new code should be formatted, which AFAIK requires clangd.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, true, any suggestions on how to make that work? If too complicated, perhaps just remove this step.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea, I know that editors often use clangd to implement the "format selection" option, not clang-format directly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot It would be better to use git clang-format instead to ensure only new code is formatted, can you test and update the instructions accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the instructions to use git clang-format --binary clang-format-16 instead of formatting all files. This ensures only changed code is formatted, avoiding reformatting the entire codebase. Tested and working in eb2cd93.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I use git diff -U0 --no-color --relative upstream/master | clang-format-diff, it only formats the diff. However, it will format every object the PR touches, so for example if you add a new arch, it will re-format that entire array

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I've updated dependencies so that git-clang-format should be installed now, remove --binary clang-format-16 and test that git clang-format still works.

If git clang-format doesn't work because git-clang-format is still missing update the Dependencies step in workflows/copilot-setup-steps.yml to download and install the version of git-clang-format that corresponds to the latest installed version of clang-format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the --binary clang-format-16 flag from the instructions and updated the CI workflow to properly install git-clang-format. Tested that git clang-format works correctly. Changes committed in 743e041.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very weird that git-clang-format is not included, but just downloading 18.x release should be good enough I guess.

@Copilot Copilot AI changed the title Add comprehensive Copilot instructions with Python environment, server testing, and backend hardware notes Add comprehensive Copilot instructions with Python environment, server testing, and git clang-format Aug 13, 2025
@Copilot Copilot AI requested a review from CISC August 13, 2025 12:09
Copilot finished work on behalf of CISC August 13, 2025 12:09
@0cc4m
Copy link
Collaborator

0cc4m commented Aug 13, 2025

What is the implication of this file?

@CISC
Copy link
Collaborator

CISC commented Aug 13, 2025

What is the implication of this file?

It's given to Copilot as a prompt whenever you ask it to work on something in this repo, f.ex. assigning an issue to it.

Copilot finished work on behalf of CISC August 13, 2025 13:26
@CISC
Copy link
Collaborator

CISC commented Aug 13, 2025

It's also possible to add separate instructions that apply to given files, see https://docs.github.com/en/copilot/how-tos/configure-custom-instructions/add-repository-instructions#using-one-or-more-instructionsmd-files-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devops improvements to build systems and github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants