This file provides guidelines and instructions for AI agents working on the Matter SDK codebase.
CHIP_ERROR as the standard return type for fallible operations. Prefer VerifyOrReturnError and ReturnErrorOnFailure macros for concise error checking and propagation.ChipLog* macros (e.g., ChipLogProgress, ChipLogError, ChipLogDetail) for logging. Ensure logs are appropriately categorized by module (e.g., AppServer, InteractionModel).When searching for files or code patterns, ignore the following directories unless explicitly asked to look there:
third_party/ (contains external dependencies)out/ (contains build artifacts)chip::Span from src/lib/support/Span.h to pointer + size groups. Pass Span by value rather than const reference (treat it as a string_view)"foo"_span (i.e. operator _span) for const char spans instead of fromCharString.std::optional to chip::OptionalStringBuilder from src/lib/support/StringBuilder.h to using snprintf for string formatting.Refer to docs/style/CODING_STYLE_GUIDE.md for full details.
<cstdint> for POD integer typesusing namespace in headers.{} bracketing for control flows, even if using one liners (e.g. for if, while, for and such)src/python_testing and src/app/tests/suites which verify expected failures should clearly indicate why the failure is expected. Include a summary of the relevant specification requirements if possible.Code-driven clusters are implementations in src/app/clusters that use DefaultServerCluster as a base class. When developing them:
ReadAttribute, WriteAttribute, and InvokeCommand are by API contract only called for existent paths. Do not add path validity checks — they increase code size and are redundant as long as Attributes or AcceptedCommands are correct.CodegenIntegration layer. CodegenIntegration.h/cpp is the documented bridge between generated configuration and code-driven cluster logic. Avoid types like EmberAfStatus or functions like emberAfContainsServer, emberAfReadAttribute, or emberAfWriteAttribute in core cluster code.app_config_dependent_sources.cmake/gni; all others belong in BUILD.gn. Ensure every file (especially headers) is listed in one of these — there should be no unreferenced files.Most commands require an activated environment.
You can run commands within the environment using scripts/run_in_build_env.sh: scripts/run_in_build_env.sh "command"
Alternatively, you can activate the environment in your shell: source scripts/activate.sh
List available targets: scripts/run_in_build_env.sh "./scripts/build/build_examples.py targets"
Generate Ninja files: scripts/run_in_build_env.sh "./scripts/build/build_examples.py --target linux-x64-tests-clang --quiet gen"
Build and run all tests: scripts/run_in_build_env.sh "./scripts/build/build_examples.py --target linux-x64-tests-clang --quiet build"
Run a specific test: scripts/run_in_build_env.sh "ninja -C out/linux-x64-tests-clang --quiet path/to/test:test_name.run"
Explicit example: scripts/run_in_build_env.sh "ninja -C out/linux-x64-tests-clang src/app/clusters/occupancy-sensor-server/tests:TestOccupancySensingCluster.run"
Compile and run can be separated (e.g. if running under some memory debugger or needing to set other options):
```bash scripts/run_in_build_env.sh "ninja -C out/linux-x64-tests-clang src/app/clusters/occupancy-sensor-server/tests:TestOccupancySensingCluster"` ./out/linux-x64-tests-clang/tests/TestOccupancySensingCluster ```
scripts/run_in_build_env.sh "./scripts/build/build_examples.py --target linux-x64-chip-tool-clang --quiet build"scripts/run_in_build_env.sh "./scripts/build/build_examples.py --target linux-x64-all-clusters-clang --quiet build"scripts/run_in_build_env.sh "./scripts/build/build_examples.py --target linux-x64-all-devices-clang --quiet build"