pigweed
AGENTS.md561 starsChanged 16 days agoApache-2.0View on GitHub
Pigweed is a collection of embedded libraries, called "modules," that work together to enable faster and more robust development of embedded systems. It provides a comprehensive development environment, including a build system, testing frameworks, and tools for debugging and analysis. This section provides specific guidance for writing C++ code and tests in Pigweed. Pigweed places a strong emphasis on testing. Here are some key points to remember: - Framework: Tests are written using the pw_unit_test framework, which provides a GoogleTest-like…
- Commits and pushes
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 31,439 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 repository20 other files it gives its agents.
- pw_ghish/AGENTS.mdAGENTS.md
- pw_ide/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- BluetoothSkill
- Code ReviewSkill
- crankSkill
- docsSkill
- freshenSkill
- ghishSkill
- manual-cli-testSkill
- oncallSkill
- pw_async2Skill
- Pigweed Kernel TestingSkill
- C++ Pigweed RPC ServicesSkill
- respondSkill
- reviewSkill
- run-presubmit-checksSkill
- saleae-analyzerSkill
- Use Pigweed Toolchain ToolsSkill
- Multi-Agent Worktree & Bazel Cache ManagementSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
28 rules. About 0 are common, 8 are distinctive, and 20 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
20
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
File Location: Test files should be located in the same module as the code they are testing and have a _test.cc suffix.
- Very specific: line 24
Status and Result: Use PW_TEST_EXPECT_OK and PW_TEST_ASSERT_OK to test functions that return pw::Status or pw::Result.
- Distinctive: line 30
Test Naming: Test suites and test cases should be named clearly and descriptively.
- Very specific: line 40
C++ Standard: All C++ code must compile with -std=c++17.
- Very specific: line 44
Use C++-style headers (e.g., <cstdlib> instead of <stdlib.h>).
- Very specific: line 47
Use Pigweed's own libraries (e.g., pw::string, pw::sync, pw::function) instead of their std counterparts.
- Very specific: line 50
Prefer C++-style comments (//).
- Distinctive: line 53
Always use braces for loops and conditionals.
- Very specific: line 54
Prefer early exits with return and continue.
- Very specific: line 55
Do not use else after a return or continue.
- Very specific: line 57
Use pw::Status and pw::Result for recoverable errors.
- Very specific: line 58
Use PW_ASSERT and PW_CHECK for fatal errors.
- Very specific: line 59
Include Guards: Use #pragma once.
- Very specific: line 61
Use the pw_log module for logging.
- Very specific: line 65
Memory Allocation: No dynamic memory allocation in core Pigweed code.
- Very specific: line 67
All C++ code must be in the pw namespace.
- Very specific: line 71
Place the * or & next to the type (e.g., int* number).
- Distinctive: line 72
Prefer references over pointers when possible.
- Distinctive: line 74
Use macros only when they significantly improve the code.
- Very specific: line 78
Unused Variables: Leave function parameters unnamed or use the standard C++ attribute [[maybe_unused]].
- Very specific: line 93
Style: Follow the Pigweed Go style guide (docs/sphinx/style/go.rst) and pw_ghish/AGENTS.md.
- Very specific: line 95
Invariants: Use RunE on all Cobra commands, never silently swallow errors with return nil, classify all CLI flags (//ghish:flag), and keep …
- Very specific: line 107
Note: Always use bazelisk and not bazel to ensure the correct bazel version is in use.
- Distinctive: line 131
Start with the module name affected by the change, followed by a colon.
- Distinctive: line 132
Use the imperative mood (e.g., "Add feature" not "Added feature").
- Distinctive: line 133
Keep it under 72 characters.
- Distinctive: line 140
If you are tempted to write a long commit message, consider if the content is better written in the docs and referred to from the commit.
- Very specific: line 142
Use a Bug: or Fixed: line for bug fixes.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 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.
Files
Overview
Pigweed is a collection of embedded libraries, called "modules," that work together to enable faster and more robust development of embedded systems. It provides a comprehensive development environment, including a build system, testing frameworks, and tools for debugging and analysis.
C++ Development Guidance
This section provides specific guidance for writing C++ code and tests in Pigweed.
Testing
Pigweed places a strong emphasis on testing. Here are some key points to remember:
- Framework: Tests are written using the
pw_unit_testframework, which provides a GoogleTest-like API. You should be familiar with theTESTandTEST_Fmacros for defining test cases, and theEXPECT_*andASSERT_*macros for assertions. - File Location: Test files should be located in the same module as the code
they are testing and have a
_test.ccsuffix. - Status and Result: Use
PW_TEST_EXPECT_OKandPW_TEST_ASSERT_OKto test functions that returnpw::Statusorpw::Result. - Negative Compilation Tests: Pigweed uses negative compilation tests
(
PW_NC_TEST) to verify that code fails to compile under specific conditions. This is particularly useful for testing static assertions and template metaprogramming. - Test Naming: Test suites and test cases should be named clearly and descriptively. The test suite name often corresponds to the class or module being tested, and the test case name describes the specific behavior being tested.
C++ Style Guide (Condensed)
This is a condensed version of the Pigweed C++ style guide. For more details, refer to the full style guide.
- C++ Standard: All C++ code must compile with
-std=c++17. C++20 features can be used if the code remains C++17 compatible. - Formatting: Format code with
./pw format. - C and C++ Standard Libraries:
- Use C++-style headers (e.g.,
<cstdlib>instead of<stdlib.h>). - A limited subset of the C++ Standard Library is permitted. Dynamic memory allocation, streams, and exceptions are disallowed in core Pigweed modules.
- Use Pigweed's own libraries (e.g.,
pw::string,pw::sync,pw::function) instead of theirstdcounterparts.
- Use C++-style headers (e.g.,
- Comments:
- Prefer C++-style comments (
//). - Code in comments should be indented with two additional spaces.
- Prefer C++-style comments (
- Control Statements:
- Always use braces for loops and conditionals.
- Prefer early exits with
returnandcontinue. - Do not use
elseafter areturnorcontinue.
- Error Handling:
- Use
pw::Statusandpw::Resultfor recoverable errors. - Use
PW_ASSERTandPW_CHECKfor fatal errors.
- Use
- Include Guards: Use
#pragma once. - Logging:
- Use the
pw_logmodule for logging. - Log errors as soon as they are unambiguously determined to be errors.
- Log at the appropriate level (
PW_LOG_DEBUG,PW_LOG_INFO,PW_LOG_WARN,PW_LOG_ERROR,PW_LOG_CRITICAL).
- Use the
- Memory Allocation: No dynamic memory allocation in core Pigweed code.
- Naming:
- All C++ code must be in the
pwnamespace. - C symbols must be prefixed with the module name (e.g.,
pw_tokenizer_*). - Public macros must be prefixed with
PW_MY_MODULE_*.
- All C++ code must be in the
- Pointers and References:
- Place the
*or&next to the type (e.g.,int* number). - Prefer references over pointers when possible.
- Place the
- Preprocessor Macros:
- Use macros only when they significantly improve the code.
- Standalone statement macros must require a semicolon.
- Unsigned Integers: Permitted, but be careful when mixing with signed integers.
- Unused Variables: Leave function parameters unnamed or use the standard
C++ attribute
[[maybe_unused]].
Python Development Guidance
Python Style Guide (Condensed)
- Style: Pigweed follows PEP 8. Format code with
./pw format. - Python Versions: Upstream Pigweed code must support the officially supported Python versions.
- Generated Files: Python packages with generated files should extend their
import path in
__init__.py.
Go Development Guidance (pw_ghish)
- Style: Follow the Pigweed Go style guide (
docs/sphinx/style/go.rst) andpw_ghish/AGENTS.md. Format code with./pw format. - Invariants: Use
RunEon all Cobra commands, never silently swallow errors withreturn nil, classify all CLI flags (//ghish:flag), and keep CLI/config docs synchronized (bazelisk test //pw_ghish/...).
Project Conventions
Build System Interaction
Pigweed uses bazel and gn as its primary build systems. Here are some common
commands:
bazel(Build system):- Note: Always use
bazeliskand notbazelto ensure the correctbazelversion is in use. Note: Use--noshow_progress--noshow_loading_progressto reduce the amount of output produced and avoid polluting the context window. - Build a target:
bazelisk build --noshow_progress --noshow_loading_progress //path/to/module:target - Run a test:
bazelisk test --noshow_progress --noshow_loading_progress //path/to/module:target - Run all tests in a module:
bazelisk test --noshow_progress --noshow_loading_progress //path/to/module/...
- Note: Always use
gn(Meta-build system):- Generate build files:
gn gen out - Build all targets and run tests:
ninja -C out --quiet - Clean the build:
gn clean out
- Generate build files:
Commit Message Conventions
Pigweed follows a specific commit message format. A good commit message should be concise and descriptive.
Subject Line:
- Start with the module name affected by the change, followed by a colon.
- Use the imperative mood (e.g., "Add feature" not "Added feature").
- Keep it under 72 characters.
- Example:
pw_foo: Add support for bar feature
Body:
- Explain the "what" and "why" of the change, not the "how".
- Reference any relevant issue trackers.
- If you are tempted to write a long commit message, consider if the content is better written in the docs and referred to from the commit.
- Use a
Bug:orFixed:line for bug fixes. Example:
``` This change adds support for the bar feature to the
pw_foomodule. This is necessary because...Bug: b/123456789 ```
Change-Ids:
- Preserve
Change-Idfooters when editing, amending, squashing, or rebasing commits. Gerrit uses these to link git commits to Change Lists. If multiple commits are combined, ensure ONLY theChange-Idfrom the earliest commit in the series is retained in the final commit message.
- Preserve
Gerrit, CI, Buganizer Issues, and Worktrees (./gh)
Pigweed provides ./gh (//pw_ghish:gh-ish), which exposes Gerrit code
reviews (./gh pr), LUCI Buildbucket CI checks (./gh pr checks, ./gh run),
Google Issue Tracker / Buganizer (./gh issue), and multi-agent Git/Bazel
worktrees (./gh wt) using standard GitHub CLI (gh) syntax.
For full workflows and flag references, load the
ghish skill and
worktree skill. An explicit /review
loads the review skill, which dispatches
language reviewer subagents in parallel and falls back to its own inline audit
for files with no enabled reviewer (the reviewer subagents currently land
disabled).
Strict Rules for AI Agents
- Always use
./gh: Use./ghfor all Gerrit CLs, Buildbucket tryjobs, Buganizer issues, and worktree management. - NEVER use raw
git push: Always use./gh pr createto upload new changes and./gh pr push(or./gh push) to upload new patchsets to existing changes. - NEVER use raw
curl,gob-curl, or.gitcookiesscripts: Do not craft manual REST calls topigweed-review.googlesource.comorcr-buildbucket.appspot.com../ghhandles authentication automatically. - NEVER poll CI in a loop: To wait on tryjobs, run
./gh pr checks --watch --fail-fastas a background command and stop calling tools until notified. - NEVER clobber
Change-Idfooters: Never rungit commit --amend -mwithout the existingChange-Id:. Usegit commit --amend --no-editfor code-only amends,-t/-b/-F/--bug/--fixedon./gh pr pushor./gh pr createfor single-commit message edits, or surgical temp-file amends (git commit --amend --only -F <file>) during rebases.
Quick Command Reference
- Inspect a CL (
pwrev/1234, Gerrit URL, or active branch):- Metadata & review comments:
./gh pr view [<id>] --comments - Unified patch diff:
./gh pr diff [<id>] - Check out a CL locally:
./gh pr checkout <id>
- Metadata & review comments:
- Create, push, or edit a CL:
- Create new CL:
./gh pr create [--cq] [--draft] [-r <email>](accepts-t,-b,-F,--bug,--fixed) - Upload new patchset:
./gh pr push [--cq] [--stack](single-commit CLs also accept-t,-b,-F,--bug,--fixed) - Edit CL metadata (CQ, reviewers, topic, hashtags):
./gh pr edit [<id>] [--cq] [--add-reviewer <email>] [--topic <name>]
- Create new CL:
- Respond to or post review comments (stage inline replies first, then publish once):
- Stage inline reply & mark resolved (use
-F -to read multi-line body fromstdin):./gh pr comment [<id>] --path <file> --line <line> (-m "<msg>" | -F <file|->) --resolved - Batch-publish all staged replies in a single review:
./gh pr review [<id>] --publish(or./gh pr push --publish)
- Stage inline reply & mark resolved (use
- Inspect & rerun LUCI CI / Buildbucket checks:
- Check or watch status:
./gh pr checks [<id>] [--watch --fail-fast] - View failure logs in terminal:
./gh run view [<id>] --log-failed - View builder step tree:
./gh run view [<id>] -j <builder> - Rerun failed builders:
./gh run rerun [<id>] --failed(or-j <builder>)
- Check or watch status:
- Buganizer issues (
./gh issue):- Inspect or list issues:
./gh issue view [<id>] --comments,./gh issue list - File bug & add
Bug: b/<id>trailer toHEAD:./gh issue create -t "<title>" (-b "<body>" | -F <file|->) --amend
- Inspect or list issues:
- Warm Git/Bazel worktrees (
./gh wt):- Allocate or switch project slot:
./gh wt use <project> --json - View active & parked workstreams:
./gh wt list
- Allocate or switch project slot:
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
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.

